From e0b4a396f71eaad0fe1c0012c5e41048839f5b4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Wed, 16 Oct 2024 23:03:34 +0300 Subject: [PATCH] core/exex: exposed last finalized block on chain interface too --- core/exex/exex/adapter_chain.go | 9 +++++++++ core/exex/interface_chain.go | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/core/exex/exex/adapter_chain.go b/core/exex/exex/adapter_chain.go index 5b1005cf06..ce5eff068f 100644 --- a/core/exex/exex/adapter_chain.go +++ b/core/exex/exex/adapter_chain.go @@ -30,6 +30,7 @@ import ( // rather it's a dynamic cast to break cross-package dependencies. type gethChain interface { CurrentBlock() *types.Header + CurrentFinalBlock() *types.Header GetHeaderByNumber(number uint64) *types.Header GetBlockByNumber(number uint64) *types.Block StateAt(root common.Hash) (*state.StateDB, error) @@ -54,6 +55,14 @@ func (a *chainAdapter) Head() *types.Header { 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 // chain. Headers on side-chains are not exposed by the Chain interface. func (a *chainAdapter) Header(number uint64) *types.Header { diff --git a/core/exex/interface_chain.go b/core/exex/interface_chain.go index b855c654a3..93e25a8b7e 100644 --- a/core/exex/interface_chain.go +++ b/core/exex/interface_chain.go @@ -29,6 +29,11 @@ type Chain interface { // Head retrieves the current head block's header from the canonical chain. 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 // chain. Headers on side-chains are not exposed by the Chain interface. Header(number uint64) *types.Header