diff --git a/core/blockchain.go b/core/blockchain.go index 6567b64980..513c73690d 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -238,6 +238,8 @@ type BlockChain struct { currentFinalBlock atomic.Pointer[types.Header] // Latest (consensus) finalized block currentSafeBlock atomic.Pointer[types.Header] // Latest (consensus) safe block + currentBaseCelestiaHeight atomic.Uint64 // Latest finalized block height on Celestia + bodyCache *lru.Cache[common.Hash, *types.Body] bodyRLPCache *lru.Cache[common.Hash, rlp.RawValue] receiptsCache *lru.Cache[common.Hash, []*types.Receipt] @@ -323,6 +325,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis bc.currentBlock.Store(bc.genesisBlock.Header()) bc.currentFinalBlock.Store(bc.genesisBlock.Header()) bc.currentSafeBlock.Store(bc.genesisBlock.Header()) + bc.currentBaseCelestiaHeight.Store(bc.Config().AstriaCelestiaInitialHeight) // Update chain info data metrics chainInfoGauge.Update(metrics.GaugeInfoValue{"chain_id": bc.chainConfig.ChainID.String()}) @@ -539,6 +542,11 @@ func (bc *BlockChain) loadLastState() error { headSafeBlockGauge.Update(int64(block.NumberU64())) } } + + if height := rawdb.ReadBaseCelestiaHeight(bc.db); height != 0 { + bc.currentBaseCelestiaHeight.Store(height) + } + // Issue a status log for the user var ( currentSnapBlock = bc.CurrentSnapBlock() @@ -547,6 +555,7 @@ func (bc *BlockChain) loadLastState() error { headerTd = bc.GetTd(headHeader.Hash(), headHeader.Number.Uint64()) blockTd = bc.GetTd(headBlock.Hash(), headBlock.NumberU64()) ) + log.Info("Loaded celestia base height", "height", bc.currentBaseCelestiaHeight.Load()) if headHeader.Hash() != headBlock.Hash() { log.Info("Loaded most recent local header", "number", headHeader.Number, "hash", headHeader.Hash(), "td", headerTd, "age", common.PrettyAge(time.Unix(int64(headHeader.Time), 0))) } @@ -620,6 +629,13 @@ func (bc *BlockChain) SetFinalized(header *types.Header) { } } +// SetCelestiaFinalized sets the finalized block and the lowest Celestia height to find next finalized at. +func (bc *BlockChain) SetCelestiaFinalized(header *types.Header, celHeight uint64) { + rawdb.WriteBaseCelestiaHeight(bc.db, celHeight) + bc.currentBaseCelestiaHeight.Store(celHeight) + bc.SetFinalized(header) +} + // SetSafe sets the safe block. func (bc *BlockChain) SetSafe(header *types.Header) { bc.currentSafeBlock.Store(header) diff --git a/core/blockchain_reader.go b/core/blockchain_reader.go index 466a86c144..fe1986f724 100644 --- a/core/blockchain_reader.go +++ b/core/blockchain_reader.go @@ -62,6 +62,12 @@ func (bc *BlockChain) CurrentSafeBlock() *types.Header { return bc.currentSafeBlock.Load() } +// CurrentBaseCelestiaHeight retrieves the current base celestia height of the +// canonical chain. The height is retrieved from the blockchain's internal cache. +func (bc *BlockChain) CurrentBaseCelestiaHeight() uint64 { + return bc.currentBaseCelestiaHeight.Load() +} + // HasHeader checks if a block header is present in the database or not, caching // it if present. func (bc *BlockChain) HasHeader(hash common.Hash, number uint64) bool { diff --git a/core/rawdb/accessors_chain.go b/core/rawdb/accessors_chain.go index d9a89fe90c..e54f4964b6 100644 --- a/core/rawdb/accessors_chain.go +++ b/core/rawdb/accessors_chain.go @@ -233,6 +233,24 @@ func WriteFinalizedBlockHash(db ethdb.KeyValueWriter, hash common.Hash) { } } +// ReadFinalizedCelestiaBlockHeight retrieves the height of the finalized block. +func ReadBaseCelestiaHeight(db ethdb.KeyValueReader) uint64 { + data, _ := db.Get(headBaseCelestiaHeightKey) + if len(data) != 8 { + return 0 + } + number := binary.BigEndian.Uint64(data) + return number +} + +// WriteFinalizedCelestiaBlockHeight stores the height of the finalized block. +func WriteBaseCelestiaHeight(db ethdb.KeyValueWriter, height uint64) { + byteHeight := encodeBlockNumber(height) + if err := db.Put(headBaseCelestiaHeightKey, byteHeight); err != nil { + log.Crit("Failed to store base celestia height", "err", err) + } +} + // ReadLastPivotNumber retrieves the number of the last pivot block. If the node // full synced, the last pivot will always be nil. func ReadLastPivotNumber(db ethdb.KeyValueReader) *uint64 { diff --git a/core/rawdb/database.go b/core/rawdb/database.go index 1d7b7d1ca8..27159747a0 100644 --- a/core/rawdb/database.go +++ b/core/rawdb/database.go @@ -557,6 +557,7 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error { snapshotGeneratorKey, snapshotRecoveryKey, txIndexTailKey, fastTxLookupLimitKey, uncleanShutdownKey, badBlockKey, transitionStatusKey, skeletonSyncStatusKey, persistentStateIDKey, trieJournalKey, snapshotSyncStatusKey, snapSyncStatusFlagKey, + headBaseCelestiaHeightKey, } { if bytes.Equal(key, meta) { metadata.Add(size) diff --git a/core/rawdb/schema.go b/core/rawdb/schema.go index 8e82459e82..493c3cdff2 100644 --- a/core/rawdb/schema.go +++ b/core/rawdb/schema.go @@ -43,6 +43,9 @@ var ( // headFinalizedBlockKey tracks the latest known finalized block hash. headFinalizedBlockKey = []byte("LastFinalized") + // headBaseCelestiaHeightKey tracks the lowest celestia height from which to attempt derivation. + headBaseCelestiaHeightKey = []byte("LastBaseCelestiaHeight") + // persistentStateIDKey tracks the id of latest stored state(for path-based only). persistentStateIDKey = []byte("LastStateID") diff --git a/go.mod b/go.mod index afc8a314ef..d625f81230 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,10 @@ module github.com/ethereum/go-ethereum go 1.21 require ( - buf.build/gen/go/astria/execution-apis/grpc/go v1.3.0-20240515213934-11def93fe8c2.3 - buf.build/gen/go/astria/execution-apis/protocolbuffers/go v1.34.1-20240515213934-11def93fe8c2.1 - buf.build/gen/go/astria/primitives/protocolbuffers/go v1.34.1-20240515213932-4cda3260523c.1 + buf.build/gen/go/astria/execution-apis/grpc/go v1.3.0-20240601032207-1bcb86793146.3 + buf.build/gen/go/astria/execution-apis/protocolbuffers/go v1.34.1-20240601032207-1bcb86793146.1 + buf.build/gen/go/astria/primitives/protocolbuffers/go v1.34.1-20240529204957-2697e2110d78.1 + buf.build/gen/go/astria/sequencerblock-apis/protocolbuffers/go v1.34.1-20240529204957-1b3cb2034833.1 github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.2.0 github.com/Microsoft/go-winio v0.6.1 github.com/VictoriaMetrics/fastcache v1.12.1 @@ -80,7 +81,6 @@ require ( ) require ( - buf.build/gen/go/astria/sequencerblock-apis/protocolbuffers/go v1.34.1-20240515213933-356887db1177.1 // indirect github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.0 // indirect github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 // indirect github.com/DataDog/zstd v1.4.5 // indirect diff --git a/go.sum b/go.sum index 7203cf8428..0846f6b457 100644 --- a/go.sum +++ b/go.sum @@ -1,32 +1,18 @@ -buf.build/gen/go/astria/execution-apis/grpc/go v1.3.0-20240423053323-ccf38db75f2f.2 h1:hZ3iCorHPftvC8mtOq59JgsXVrzQa7DGVWhhReLfDUU= -buf.build/gen/go/astria/execution-apis/grpc/go v1.3.0-20240423053323-ccf38db75f2f.2/go.mod h1:xHHYSn2PRQE8P9sUfLoH4sDV1dPZzx7knBWLpc4r1ws= -buf.build/gen/go/astria/execution-apis/grpc/go v1.3.0-20240515213934-11def93fe8c2.3 h1:nRWDbArZH6mR5gqI3tfmBaJkzjO6S2ok71oXY5AM1L4= -buf.build/gen/go/astria/execution-apis/grpc/go v1.3.0-20240515213934-11def93fe8c2.3/go.mod h1:DNVdk7hzJuZxzyb9NOXdxCRHS1yvOAOYoqBD50ui8J4= -buf.build/gen/go/astria/execution-apis/protocolbuffers/go v1.28.1-20240423053323-ccf38db75f2f.4/go.mod h1:L45ZB/W7SxQDHLrKTdGT40ytkcnntNJcF/VyiAK3psE= -buf.build/gen/go/astria/execution-apis/protocolbuffers/go v1.33.0-20240423053323-ccf38db75f2f.1 h1:OB4HbEo2YRJc3L7TNSvou07id25Xg8WmuIHmx7FnnfA= -buf.build/gen/go/astria/execution-apis/protocolbuffers/go v1.33.0-20240423053323-ccf38db75f2f.1/go.mod h1:LbzJDzXgLEtOzJmPbh6SbBC0RyK1UxkfETur2p06VHU= -buf.build/gen/go/astria/execution-apis/protocolbuffers/go v1.34.0-20240515213934-11def93fe8c2.1 h1:43rSytfZc2FXAftAEJNdTjSwUHmKRQrCWQoQqxZoYV4= -buf.build/gen/go/astria/execution-apis/protocolbuffers/go v1.34.0-20240515213934-11def93fe8c2.1/go.mod h1:J0CN4rMt/4lTtzxxaFi27MloSWAPuLMH0gdbYTbUSvU= -buf.build/gen/go/astria/execution-apis/protocolbuffers/go v1.34.1-20240515213934-11def93fe8c2.1 h1:KR9+5n3PIJtaJgWNWZqDFM32eRxPu0170jYPhFShvXM= -buf.build/gen/go/astria/execution-apis/protocolbuffers/go v1.34.1-20240515213934-11def93fe8c2.1/go.mod h1:zkwJy8yFAIGVEWb3EnNkdfxdOdOCfHbRnwKVJt/2QCc= -buf.build/gen/go/astria/primitives/grpc/go v1.3.0-20240422195039-812e347acd6b.2/go.mod h1:5NfjRl1Y2qnN62OOMBNhKDFJKsZAvrYyJJdcoS438Aw= -buf.build/gen/go/astria/primitives/grpc/go v1.3.0-20240515213932-4cda3260523c.3/go.mod h1:lxd5WYe9GI6LNl4GuQuYwD+WuMSpiK3uvmJ059mrZiA= -buf.build/gen/go/astria/primitives/protocolbuffers/go v1.28.1-20240422195039-812e347acd6b.4/go.mod h1:Db3JxaJwPkhOVCUnIS785SD7TEI4NPB4LvWpvlWr02E= -buf.build/gen/go/astria/primitives/protocolbuffers/go v1.33.0-20240422195039-812e347acd6b.1 h1:ANEC8IuONtxy0go3DZqyXonzPGQ8kxDe3EOJNoqRol8= -buf.build/gen/go/astria/primitives/protocolbuffers/go v1.33.0-20240422195039-812e347acd6b.1/go.mod h1:1VK/IapDxiDL/a+arAHdzNuaTSeC6suYHRK8AxJQrUw= -buf.build/gen/go/astria/primitives/protocolbuffers/go v1.34.0-20240515213932-4cda3260523c.1 h1:q++mmOYZdc4M1tDd2sBZRXKkxwvJwThQamx0ooST2TQ= -buf.build/gen/go/astria/primitives/protocolbuffers/go v1.34.0-20240515213932-4cda3260523c.1/go.mod h1:t7VCP+ORGGLNXUOwi6T6h99GntTUT7bWzK6BQa/uTbA= -buf.build/gen/go/astria/primitives/protocolbuffers/go v1.34.1-20240515213932-4cda3260523c.1 h1:5Re2cZfcPO/zN0qYgEx6fd52AaIPiYs+9Sh2O0KdXZw= -buf.build/gen/go/astria/primitives/protocolbuffers/go v1.34.1-20240515213932-4cda3260523c.1/go.mod h1:pkz/GfhAgZSnDxyZ5bmGUzk6iQNAvyW72pYPkqb7Pbk= -buf.build/gen/go/astria/sequencerblock-apis/grpc/go v1.3.0-20240423053322-44396ca8658a.2/go.mod h1:YdVN+ZAuYsnCS8PH/TNFApM+3Z+rc0lQ63tHKri1KTE= -buf.build/gen/go/astria/sequencerblock-apis/grpc/go v1.3.0-20240515213933-356887db1177.3/go.mod h1:uvo/YYlSVCDfyvEWkJtlldJk+jvEAOl+LZ+pYUCV7no= -buf.build/gen/go/astria/sequencerblock-apis/protocolbuffers/go v1.28.1-20240423053322-44396ca8658a.4/go.mod h1:Zn4mqAF/djuebKMIqCoYo5aQtZuuUlZ32u9AsbJPNVY= -buf.build/gen/go/astria/sequencerblock-apis/protocolbuffers/go v1.33.0-20240423053322-44396ca8658a.1 h1:ybwQ3f4wa6hjSYFD6vEw7xfkuPNTJm9IVefs7LwF8uw= -buf.build/gen/go/astria/sequencerblock-apis/protocolbuffers/go v1.33.0-20240423053322-44396ca8658a.1/go.mod h1:avEoXDW7L9QoMYCDJFVqBm5D/qyZ4BMg31Zi/SFQR6U= -buf.build/gen/go/astria/sequencerblock-apis/protocolbuffers/go v1.34.0-20240515213933-356887db1177.1 h1:GXOy6eQ+ZTooCVYiB9SW1SW8+NgbwvlKXq9XLHNHfp0= -buf.build/gen/go/astria/sequencerblock-apis/protocolbuffers/go v1.34.0-20240515213933-356887db1177.1/go.mod h1:8ON6fUbHVGV+/+fSvv+IqorHJaysvtu010nOVAmHzh0= -buf.build/gen/go/astria/sequencerblock-apis/protocolbuffers/go v1.34.1-20240515213933-356887db1177.1 h1:0clANtcO3Q3jsdQMHV7f3zMPi5tppgjmSudm+jzToNs= -buf.build/gen/go/astria/sequencerblock-apis/protocolbuffers/go v1.34.1-20240515213933-356887db1177.1/go.mod h1:c3/mEqzDWf4TyURXs/QgYsU45D98RUAV5HIr6W57Dh8= +buf.build/gen/go/astria/execution-apis/grpc/go v1.3.0-20240601032207-1bcb86793146.3 h1:i8MoIU0AqTo/iydebYlwmjrWGDPQW6lFUoiQ45E6Pa4= +buf.build/gen/go/astria/execution-apis/grpc/go v1.3.0-20240601032207-1bcb86793146.3/go.mod h1:X2jDNjqmRIVdmErR9o6wCtN9Cy/e3CdACHeKE9JVnIg= +buf.build/gen/go/astria/execution-apis/protocolbuffers/go v1.34.0-20240601032207-1bcb86793146.1/go.mod h1:/LCeHy9fO3MXiOwoY9dQoTeIfS8UkBv9MC75gYsdLHw= +buf.build/gen/go/astria/execution-apis/protocolbuffers/go v1.34.1-20240601032207-1bcb86793146.1 h1:bLwaKvLfG/XsyXRrlp0bIZAXv5GEBj/DewSsGhy5Ftw= +buf.build/gen/go/astria/execution-apis/protocolbuffers/go v1.34.1-20240601032207-1bcb86793146.1/go.mod h1:dwuQzc8dbNWLqUHa7GwcsvDLe1eOHQifwlDlXOxeUWM= +buf.build/gen/go/astria/primitives/grpc/go v1.3.0-20240528191859-2caf2e8901b3.3/go.mod h1:cy3v1yVidgYadPTyxoYcmI2ttaANZ4cK1eMltUT3Y8w= +buf.build/gen/go/astria/primitives/protocolbuffers/go v1.34.0-20240528191859-2caf2e8901b3.1/go.mod h1:t7VCP+ORGGLNXUOwi6T6h99GntTUT7bWzK6BQa/uTbA= +buf.build/gen/go/astria/primitives/protocolbuffers/go v1.34.1-20240528191859-2caf2e8901b3.1/go.mod h1:pkz/GfhAgZSnDxyZ5bmGUzk6iQNAvyW72pYPkqb7Pbk= +buf.build/gen/go/astria/primitives/protocolbuffers/go v1.34.1-20240529204957-2697e2110d78.1 h1:FP1NQSG3SYFFFr4qRVIqD/VD51ipMzJ2XsnD6Qgc82w= +buf.build/gen/go/astria/primitives/protocolbuffers/go v1.34.1-20240529204957-2697e2110d78.1/go.mod h1:pkz/GfhAgZSnDxyZ5bmGUzk6iQNAvyW72pYPkqb7Pbk= +buf.build/gen/go/astria/sequencerblock-apis/grpc/go v1.3.0-20240528191859-66d6f20a25a2.3/go.mod h1:nj0oXqy+Fx2X7duXc0n1keHiUxbmOHAzRUrP6nYILBo= +buf.build/gen/go/astria/sequencerblock-apis/protocolbuffers/go v1.34.0-20240528191859-66d6f20a25a2.1/go.mod h1:qSoo/Wv1fQM3moFi8Auky4VF/Sh+QonAGSFPghPxjOc= +buf.build/gen/go/astria/sequencerblock-apis/protocolbuffers/go v1.34.1-20240528191859-66d6f20a25a2.1/go.mod h1:ho1LGPi0iGEw8pn0dEv5+f2/J7HwUvWhitx9jNl+lu8= +buf.build/gen/go/astria/sequencerblock-apis/protocolbuffers/go v1.34.1-20240529204957-1b3cb2034833.1 h1:TEGVCwN4J+dtp3MIyaDmbe04bRVRdKhcsWmCeAQ0aDw= +buf.build/gen/go/astria/sequencerblock-apis/protocolbuffers/go v1.34.1-20240529204957-1b3cb2034833.1/go.mod h1:Mty3/6h+D/YsYpSXjdj0BRy6HbMXbpovLw2Acnez714= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= @@ -1510,8 +1496,8 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-pkcs11 v0.2.0/go.mod h1:6eQoGcuNJpa7jnd5pMGdkSaQpNDYvPlXWMcjXXThLlY= github.com/google/go-pkcs11 v0.2.1-0.20230907215043-c6f79328ddf9/go.mod h1:6eQoGcuNJpa7jnd5pMGdkSaQpNDYvPlXWMcjXXThLlY= @@ -1550,7 +1536,6 @@ github.com/google/s2a-go v0.1.4/go.mod h1:Ej+mSEMGRnqRzjc7VtF+jdBwYG5fuJfiZ8ELkj github.com/google/s2a-go v0.1.7/go.mod h1:50CgR4k1jNlWBu4UfS4AcfhVe1r6pdZPygJ3R8F0Qdw= github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= @@ -1804,8 +1789,6 @@ github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1: github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.2.1-0.20210607210712-147c58e9608a h1:CmF68hwI0XsOQ5UwlBopMi2Ow4Pbg32akc4KIVCOm+Y= -github.com/prometheus/client_model v0.2.1-0.20210607210712-147c58e9608a/go.mod h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w= github.com/prometheus/client_model v0.3.0/go.mod h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w= github.com/prometheus/client_model v0.4.0 h1:5lQXD3cAg1OXBf4Wq03gTrXHeaV0TQvGfUooCfx1yqY= github.com/prometheus/client_model v0.4.0/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU= @@ -1952,7 +1935,6 @@ golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45 golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= -golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA= golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g= @@ -2092,7 +2074,6 @@ golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ= golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= golang.org/x/net v0.16.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= -golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg= golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ= @@ -2147,7 +2128,6 @@ golang.org/x/sync v0.0.0-20220819030929-7fc1605a5dde/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE= @@ -2262,7 +2242,6 @@ golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= @@ -2302,7 +2281,6 @@ golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= -golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= @@ -2593,7 +2571,6 @@ google.golang.org/genproto v0.0.0-20221201164419-0e50fba7f41c/go.mod h1:rZS5c/ZV google.golang.org/genproto v0.0.0-20221201204527-e3fa12d562f3/go.mod h1:rZS5c/ZVYMaOGBfO68GWtjOw/eLaZM1X6iVtgjZ+EWg= google.golang.org/genproto v0.0.0-20221202195650-67e5cbc046fd/go.mod h1:cTsE614GARnxrLsqKREzmNYJACSWWpAWdNMwnD7c2BE= google.golang.org/genproto v0.0.0-20221227171554-f9683d7f8bef/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM= -google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f h1:BWUVssLB0HVOSY78gIdvk1dTVYtT1y8SBWtPYuTJ/6w= google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM= google.golang.org/genproto v0.0.0-20230112194545-e10362b5ecf9/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM= google.golang.org/genproto v0.0.0-20230113154510-dbe35b8444a5/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM= @@ -2711,7 +2688,6 @@ google.golang.org/grpc v1.50.1/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCD google.golang.org/grpc v1.51.0/go.mod h1:wgNDFcnuBGmxLKI/qn4T+m5BtEBYXJPvibbUPsAIPww= google.golang.org/grpc v1.52.0/go.mod h1:pu6fVzoFb+NBYNAvQL08ic+lvB2IojljRYuun5vorUY= google.golang.org/grpc v1.52.3/go.mod h1:pu6fVzoFb+NBYNAvQL08ic+lvB2IojljRYuun5vorUY= -google.golang.org/grpc v1.53.0 h1:LAv2ds7cmFV/XTS3XG1NneeENYrXGmorPxsBbptIjNc= google.golang.org/grpc v1.53.0/go.mod h1:OnIrk0ipVdj4N5d9IUoFUx72/VlD7+jUsHwZgwSMQpw= google.golang.org/grpc v1.54.0/go.mod h1:PUSEXI6iWghWaB6lXM4knEgpJNu2qUcKfDtNci3EC2g= google.golang.org/grpc v1.55.0/go.mod h1:iYEXKGkEBhg1PjZQvoYEVPTDkHo1/bjTnfwTeGONTY8= @@ -2742,9 +2718,6 @@ google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw google.golang.org/protobuf v1.29.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= -google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= -google.golang.org/protobuf v1.34.0 h1:Qo/qEd2RZPCf2nKuorzksSknv0d3ERwp1vFG38gSmH4= google.golang.org/protobuf v1.34.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= diff --git a/grpc/execution/server.go b/grpc/execution/server.go index 3394572186..cf49270048 100644 --- a/grpc/execution/server.go +++ b/grpc/execution/server.go @@ -155,7 +155,6 @@ func (s *ExecutionServiceServerV1Alpha2) GetGenesisInfo(ctx context.Context, req res := &astriaPb.GenesisInfo{ RollupId: rollupId[:], SequencerGenesisBlockHeight: s.bc.Config().AstriaSequencerInitialHeight, - CelestiaBaseBlockHeight: s.bc.Config().AstriaCelestiaInitialHeight, CelestiaBlockVariance: s.bc.Config().AstriaCelestiaHeightVariance, } @@ -316,12 +315,15 @@ func (s *ExecutionServiceServerV1Alpha2) GetCommitmentState(ctx context.Context, return nil, status.Error(codes.Internal, "could not locate firm block") } + celestiaBlock := s.bc.CurrentBaseCelestiaHeight() + res := &astriaPb.CommitmentState{ - Soft: softBlock, - Firm: firmBlock, + Soft: softBlock, + Firm: firmBlock, + BaseCelestiaHeight: celestiaBlock, } - log.Info("GetCommitmentState completed", "soft_height", res.Soft.Number, "firm_height", res.Firm.Number) + log.Info("GetCommitmentState completed", "soft_height", res.Soft.Number, "firm_height", res.Firm.Number, "base_celestia_height", res.BaseCelestiaHeight) getCommitmentStateSuccessCount.Inc(1) s.getCommitmentStateCalled = true return res, nil @@ -342,6 +344,11 @@ func (s *ExecutionServiceServerV1Alpha2) UpdateCommitmentState(ctx context.Conte return nil, status.Error(codes.PermissionDenied, "Cannot update commitment state until GetGenesisInfo && GetCommitmentState methods are called") } + if s.bc.CurrentBaseCelestiaHeight() > req.CommitmentState.BaseCelestiaHeight { + errStr := fmt.Sprintf("Base Celestia height cannot be decreased, current_base_celestia_height: %d, new_base_celestia_height: %d", s.bc.CurrentBaseCelestiaHeight(), req.CommitmentState.BaseCelestiaHeight) + return nil, status.Error(codes.InvalidArgument, errStr) + } + softEthHash := common.BytesToHash(req.CommitmentState.Soft.Hash) firmEthHash := common.BytesToHash(req.CommitmentState.Firm.Hash) @@ -388,7 +395,7 @@ func (s *ExecutionServiceServerV1Alpha2) UpdateCommitmentState(ctx context.Conte } currentFirm := s.bc.CurrentFinalBlock().Hash() if currentFirm != firmEthHash { - s.bc.SetFinalized(firmBlock.Header()) + s.bc.SetCelestiaFinalized(firmBlock.Header(), req.CommitmentState.BaseCelestiaHeight) } log.Info("UpdateCommitmentState completed", "soft_height", softBlock.NumberU64(), "firm_height", firmBlock.NumberU64()) diff --git a/grpc/execution/server_test.go b/grpc/execution/server_test.go index 7af30fc4e3..e33fd6c1e0 100644 --- a/grpc/execution/server_test.go +++ b/grpc/execution/server_test.go @@ -29,7 +29,6 @@ func TestExecutionService_GetGenesisInfo(t *testing.T) { require.True(t, bytes.Equal(genesisInfo.RollupId, hashedRollupId[:]), "RollupId is not correct") require.Equal(t, genesisInfo.GetSequencerGenesisBlockHeight(), ethservice.BlockChain().Config().AstriaSequencerInitialHeight, "SequencerInitialHeight is not correct") - require.Equal(t, genesisInfo.GetCelestiaBaseBlockHeight(), ethservice.BlockChain().Config().AstriaCelestiaInitialHeight, "CelestiaInitialHeight is not correct") require.Equal(t, genesisInfo.GetCelestiaBlockVariance(), ethservice.BlockChain().Config().AstriaCelestiaHeightVariance, "CelestiaHeightVariance is not correct") require.True(t, serviceV1Alpha1.genesisInfoCalled, "GetGenesisInfo should be called") } @@ -55,6 +54,7 @@ func TestExecutionServiceServerV1Alpha2_GetCommitmentState(t *testing.T) { require.True(t, bytes.Equal(commitmentState.Firm.Hash, firmBlock.Hash().Bytes()), "Firm Block Hashes do not match") require.True(t, bytes.Equal(commitmentState.Firm.ParentBlockHash, firmBlock.ParentHash.Bytes()), "Firm Block Parent Hash do not match") require.Equal(t, uint64(commitmentState.Firm.Number), firmBlock.Number.Uint64(), "Firm Block Number do not match") + require.Equal(t, commitmentState.BaseCelestiaHeight, ethservice.BlockChain().Config().AstriaCelestiaInitialHeight, "BaseCelestiaHeight is not correct") require.True(t, serviceV1Alpha1.getCommitmentStateCalled, "GetCommitmentState should be called") } @@ -430,12 +430,14 @@ func TestExecutionServiceServerV1Alpha2_ExecuteBlockAndUpdateCommitment(t *testi Number: executeBlockRes.Number, Timestamp: executeBlockRes.Timestamp, }, + BaseCelestiaHeight: commitmentState.BaseCelestiaHeight + 1, }, } updateCommitmentStateRes, err := serviceV1Alpha1.UpdateCommitmentState(context.Background(), updateCommitmentStateReq) require.Nil(t, err, "UpdateCommitmentState failed") require.NotNil(t, updateCommitmentStateRes, "UpdateCommitmentState response should not be nil") + require.Equal(t, updateCommitmentStateRes, updateCommitmentStateReq.CommitmentState, "CommitmentState response should match request") // get the soft and firm block softBlock := ethservice.BlockChain().CurrentSafeBlock() @@ -452,6 +454,9 @@ func TestExecutionServiceServerV1Alpha2_ExecuteBlockAndUpdateCommitment(t *testi require.True(t, bytes.Equal(firmBlock.ParentHash.Bytes(), updateCommitmentStateRes.Firm.ParentBlockHash), "Firm Block Parent Hash do not match") require.Equal(t, firmBlock.Number.Uint64(), uint64(updateCommitmentStateRes.Firm.Number), "Firm Block Number do not match") + celestiaBaseHeight := ethservice.BlockChain().CurrentBaseCelestiaHeight() + require.Equal(t, celestiaBaseHeight, updateCommitmentStateRes.BaseCelestiaHeight, "BaseCelestiaHeight should be updated in db") + // check the difference in balances after deposit tx stateDb, err = ethservice.BlockChain().State() require.Nil(t, err, "Failed to get state db") diff --git a/params/config.go b/params/config.go index fd8924bfe5..09cb045e9a 100644 --- a/params/config.go +++ b/params/config.go @@ -343,8 +343,8 @@ type ChainConfig struct { AstriaExtraDataOverride hexutil.Bytes `json:"astriaExtraDataOverride,omitempty"` AstriaRollupName string `json:"astriaRollupName"` AstriaSequencerInitialHeight uint32 `json:"astriaSequencerInitialHeight"` - AstriaCelestiaInitialHeight uint32 `json:"astriaCelestiaInitialHeight"` - AstriaCelestiaHeightVariance uint32 `json:"astriaCelestiaHeightVariance,omitempty"` + AstriaCelestiaInitialHeight uint64 `json:"astriaCelestiaInitialHeight"` + AstriaCelestiaHeightVariance uint64 `json:"astriaCelestiaHeightVariance,omitempty"` AstriaBridgeAddressConfigs []AstriaBridgeAddressConfig `json:"astriaBridgeAddresses,omitempty"` AstriaFeeCollectors map[uint32]common.Address `json:"astriaFeeCollectors"` AstriaEIP1559Params *AstriaEIP1559Params `json:"astriaEIP1559Params,omitempty"`