Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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()})
Expand Down Expand Up @@ -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()
Expand All @@ -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)))
}
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions core/blockchain_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 18 additions & 0 deletions core/rawdb/accessors_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions core/rawdb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions core/rawdb/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading