Skip to content

Commit

Permalink
sequencer to report correct block height (#1527)
Browse files Browse the repository at this point in the history
  • Loading branch information
hexoscott authored Dec 3, 2024
1 parent 84d960d commit 9be5df2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
8 changes: 7 additions & 1 deletion turbo/jsonrpc/eth_block_zkevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
Expand Down
26 changes: 15 additions & 11 deletions turbo/rpchelper/rpc_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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)
}
Expand All @@ -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
Expand Down

0 comments on commit 9be5df2

Please sign in to comment.