From 21cfaf1216b420171b4d0e1d9694a090b955422c Mon Sep 17 00:00:00 2001 From: Scott Fairclough Date: Mon, 2 Dec 2024 15:24:10 +0000 Subject: [PATCH] sequencer to report correct block height --- turbo/jsonrpc/eth_block_zkevm.go | 8 +++++++- turbo/rpchelper/rpc_block.go | 26 +++++++++++++++----------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/turbo/jsonrpc/eth_block_zkevm.go b/turbo/jsonrpc/eth_block_zkevm.go index 6f82477f685..3bf04c81dd8 100644 --- a/turbo/jsonrpc/eth_block_zkevm.go +++ b/turbo/jsonrpc/eth_block_zkevm.go @@ -26,6 +26,7 @@ import ( "github.com/ledgerwatch/erigon/turbo/rpchelper" "github.com/ledgerwatch/erigon/turbo/transactions" "github.com/ledgerwatch/erigon/zk/hermez_db" + "github.com/ledgerwatch/erigon/zk/sequencer" ) func (api *APIImpl) CallBundle(ctx context.Context, txHashes []common.Hash, stateBlockNumberOrHash rpc.BlockNumberOrHash, timeoutMilliSecondsPtr *int64) (map[string]interface{}, error) { @@ -217,7 +218,12 @@ func (api *APIImpl) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber defer tx.Rollback() // get latest finished block - finishedBlock, err := stages.GetStageProgress(tx, stages.Finish) + var finishedBlock uint64 + if sequencer.IsSequencer() { + finishedBlock, err = stages.GetStageProgress(tx, stages.Execution) + } else { + finishedBlock, err = stages.GetStageProgress(tx, stages.Finish) + } if err != nil { return nil, err } diff --git a/turbo/rpchelper/rpc_block.go b/turbo/rpchelper/rpc_block.go index b5da8148c29..5835209835c 100644 --- a/turbo/rpchelper/rpc_block.go +++ b/turbo/rpchelper/rpc_block.go @@ -10,6 +10,7 @@ import ( "github.com/ledgerwatch/erigon/eth/stagedsync/stages" "github.com/ledgerwatch/erigon/rpc" "github.com/ledgerwatch/erigon/zk/hermez_db" + "github.com/ledgerwatch/erigon/zk/sequencer" ) var UnknownBlockError = &rpc.CustomError{ @@ -18,15 +19,13 @@ var UnknownBlockError = &rpc.CustomError{ } func GetLatestFinishedBlockNumber(tx kv.Tx) (uint64, error) { - forkchoiceHeadHash := rawdb.ReadForkchoiceHead(tx) - if forkchoiceHeadHash != (libcommon.Hash{}) { - forkchoiceHeadNum := rawdb.ReadHeaderNumber(tx, forkchoiceHeadHash) - if forkchoiceHeadNum != nil { - return *forkchoiceHeadNum, nil - } + var blockNum uint64 + var err error + if sequencer.IsSequencer() { + blockNum, err = stages.GetStageProgress(tx, stages.Execution) + } else { + blockNum, err = stages.GetStageProgress(tx, stages.Finish) } - - blockNum, err := stages.GetStageProgress(tx, stages.Finish) if err != nil { return 0, fmt.Errorf("getting latest block number: %w", err) } @@ -48,14 +47,19 @@ func GetFinalizedBlockNumber(tx kv.Tx) (uint64, error) { return 0, err } - finishedBlockNumber, err := stages.GetStageProgress(tx, stages.Finish) + var highestBlockNumber uint64 + if sequencer.IsSequencer() { + highestBlockNumber, err = stages.GetStageProgress(tx, stages.Execution) + } else { + highestBlockNumber, err = stages.GetStageProgress(tx, stages.Finish) + } if err != nil { return 0, fmt.Errorf("getting latest finished block number: %w", err) } blockNumber := highestVerifiedBlock - if finishedBlockNumber < blockNumber { - blockNumber = finishedBlockNumber + if highestBlockNumber < blockNumber { + blockNumber = highestBlockNumber } return blockNumber, nil