Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sequencer to report correct block height #1527

Merged
merged 2 commits into from
Dec 3, 2024
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
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
Loading