core/exex: exposed last finalized block on chain interface too

This commit is contained in:
Péter Szilágyi 2024-10-16 23:03:34 +03:00
parent 062209fff8
commit e0b4a396f7
2 changed files with 14 additions and 0 deletions

View file

@ -30,6 +30,7 @@ import (
// rather it's a dynamic cast to break cross-package dependencies. // rather it's a dynamic cast to break cross-package dependencies.
type gethChain interface { type gethChain interface {
CurrentBlock() *types.Header CurrentBlock() *types.Header
CurrentFinalBlock() *types.Header
GetHeaderByNumber(number uint64) *types.Header GetHeaderByNumber(number uint64) *types.Header
GetBlockByNumber(number uint64) *types.Block GetBlockByNumber(number uint64) *types.Block
StateAt(root common.Hash) (*state.StateDB, error) StateAt(root common.Hash) (*state.StateDB, error)
@ -54,6 +55,14 @@ func (a *chainAdapter) Head() *types.Header {
return types.CopyHeader(a.chain.CurrentBlock()) return types.CopyHeader(a.chain.CurrentBlock())
} }
// Final retrieves the last finalized block from the chain. If no finality
// is known yet (not synced, not past merge, etc.) or Geth crashed and is
// recovering, the returns header will be nil.
func (a *chainAdapter) Final() *types.Header {
// Headers have public fields, copy to prevent modification
return types.CopyHeader(a.chain.CurrentFinalBlock())
}
// Header retrieves a block header with the given number from the canonical // Header retrieves a block header with the given number from the canonical
// chain. Headers on side-chains are not exposed by the Chain interface. // chain. Headers on side-chains are not exposed by the Chain interface.
func (a *chainAdapter) Header(number uint64) *types.Header { func (a *chainAdapter) Header(number uint64) *types.Header {

View file

@ -29,6 +29,11 @@ type Chain interface {
// Head retrieves the current head block's header from the canonical chain. // Head retrieves the current head block's header from the canonical chain.
Head() *types.Header Head() *types.Header
// Final retrieves the last finalized block from the chain. If no finality
// is known yet (not synced, not past merge, etc.) or Geth crashed and is
// recovering, the returns header will be nil.
Final() *types.Header
// Header retrieves a block header with the given number from the canonical // Header retrieves a block header with the given number from the canonical
// chain. Headers on side-chains are not exposed by the Chain interface. // chain. Headers on side-chains are not exposed by the Chain interface.
Header(number uint64) *types.Header Header(number uint64) *types.Header