From 682235849b5df653c4108f2a4099ee39b8cde6b6 Mon Sep 17 00:00:00 2001 From: David Date: Sat, 29 Mar 2025 16:33:03 +0800 Subject: [PATCH] chore(eth): always use the latest block number for pending state in RPC calls (#410) * feat: improve RPC * feat: more * feat: check flag --- eth/api_backend.go | 4 ++++ eth/api_debug.go | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/eth/api_backend.go b/eth/api_backend.go index 75b039dbe1..e582e25c63 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -187,6 +187,10 @@ func (b *EthAPIBackend) Pending() (*types.Block, types.Receipts, *state.StateDB) } func (b *EthAPIBackend) StateAndHeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*state.StateDB, *types.Header, error) { + // CHANGE(taiko): always use the latest block number for pending state. + if b.ChainConfig().Taiko && number == rpc.PendingBlockNumber { + number = rpc.LatestBlockNumber + } // Pending state is only known by the miner if number == rpc.PendingBlockNumber { block, _, state := b.eth.miner.Pending() diff --git a/eth/api_debug.go b/eth/api_debug.go index d5e4dda140..4ab3781742 100644 --- a/eth/api_debug.go +++ b/eth/api_debug.go @@ -52,6 +52,10 @@ func (api *DebugAPI) DumpBlock(blockNr rpc.BlockNumber) (state.Dump, error) { OnlyWithAddresses: true, Max: AccountRangeMaxResults, // Sanity limit over RPC } + // CHANGE(taiko): always use the latest block number for pending state. + if api.eth.blockchain.Config().Taiko && blockNr == rpc.PendingBlockNumber { + blockNr = rpc.LatestBlockNumber + } if blockNr == rpc.PendingBlockNumber { // If we're dumping the pending state, we need to request // both the pending block as well as the pending state from @@ -138,6 +142,10 @@ func (api *DebugAPI) AccountRange(blockNrOrHash rpc.BlockNumberOrHash, start hex var err error if number, ok := blockNrOrHash.Number(); ok { + // CHANGE(taiko): always use the latest block number for pending state. + if api.eth.blockchain.Config().Taiko && number == rpc.PendingBlockNumber { + number = rpc.LatestBlockNumber + } if number == rpc.PendingBlockNumber { // If we're dumping the pending state, we need to request // both the pending block as well as the pending state from