chore(eth): always use the latest block number for pending state in RPC calls (#410)

* feat: improve RPC

* feat: more

* feat: check flag
This commit is contained in:
David 2025-03-29 16:33:03 +08:00 committed by GitHub
parent 9e6edc51db
commit 682235849b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 0 deletions

View file

@ -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) { 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 // Pending state is only known by the miner
if number == rpc.PendingBlockNumber { if number == rpc.PendingBlockNumber {
block, _, state := b.eth.miner.Pending() block, _, state := b.eth.miner.Pending()

View file

@ -52,6 +52,10 @@ func (api *DebugAPI) DumpBlock(blockNr rpc.BlockNumber) (state.Dump, error) {
OnlyWithAddresses: true, OnlyWithAddresses: true,
Max: AccountRangeMaxResults, // Sanity limit over RPC 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 blockNr == rpc.PendingBlockNumber {
// If we're dumping the pending state, we need to request // If we're dumping the pending state, we need to request
// both the pending block as well as the pending state from // 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 var err error
if number, ok := blockNrOrHash.Number(); ok { 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 number == rpc.PendingBlockNumber {
// If we're dumping the pending state, we need to request // If we're dumping the pending state, we need to request
// both the pending block as well as the pending state from // both the pending block as well as the pending state from