Skip to content

Commit cc30301

Browse files
holimankaralabe
authored andcommitted
debug: convert uint64-blocknumber into rpc.Blocknumber (#13862)
* debug: Converted uint64-blocknumber into rpc.Blocknumber * api/debug: Fix pending block issues in DumpBlock
1 parent 49437a0 commit cc30301

1 file changed

Lines changed: 29 additions & 6 deletions

File tree

‎eth/api.go‎

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040
"github.com/ethereum/go-ethereum/miner"
4141
"github.com/ethereum/go-ethereum/params"
4242
"github.com/ethereum/go-ethereum/rlp"
43+
"github.com/ethereum/go-ethereum/rpc"
4344
)
4445

4546
const defaultTraceTimeout = 5 * time.Second
@@ -293,10 +294,22 @@ func NewPublicDebugAPI(eth *Ethereum) *PublicDebugAPI {
293294
}
294295

295296
// DumpBlock retrieves the entire state of the database at a given block.
296-
func (api *PublicDebugAPI) DumpBlock(number uint64) (state.Dump, error) {
297-
block := api.eth.BlockChain().GetBlockByNumber(number)
297+
func (api *PublicDebugAPI) DumpBlock(blockNr rpc.BlockNumber) (state.Dump, error) {
298+
if blockNr == rpc.PendingBlockNumber {
299+
// If we're dumping the pending state, we need to request
300+
// both the pending block as well as the pending state from
301+
// the miner and operate on those
302+
_, stateDb := api.eth.miner.Pending()
303+
return stateDb.RawDump(), nil
304+
}
305+
var block *types.Block
306+
if blockNr == rpc.LatestBlockNumber {
307+
block = api.eth.blockchain.CurrentBlock()
308+
} else {
309+
block = api.eth.blockchain.GetBlockByNumber(uint64(blockNr))
310+
}
298311
if block == nil {
299-
return state.Dump{}, fmt.Errorf("block #%d not found", number)
312+
return state.Dump{}, fmt.Errorf("block #%d not found", blockNr)
300313
}
301314
stateDb, err := api.eth.BlockChain().StateAt(block.Root())
302315
if err != nil {
@@ -361,11 +374,21 @@ func (api *PrivateDebugAPI) TraceBlockFromFile(file string, config *vm.LogConfig
361374
}
362375

363376
// TraceBlockByNumber processes the block by canonical block number.
364-
func (api *PrivateDebugAPI) TraceBlockByNumber(number uint64, config *vm.LogConfig) BlockTraceResult {
377+
func (api *PrivateDebugAPI) TraceBlockByNumber(blockNr rpc.BlockNumber, config *vm.LogConfig) BlockTraceResult {
365378
// Fetch the block that we aim to reprocess
366-
block := api.eth.BlockChain().GetBlockByNumber(number)
379+
var block *types.Block
380+
switch blockNr {
381+
case rpc.PendingBlockNumber:
382+
// Pending block is only known by the miner
383+
block = api.eth.miner.PendingBlock()
384+
case rpc.LatestBlockNumber:
385+
block = api.eth.blockchain.CurrentBlock()
386+
default:
387+
block = api.eth.blockchain.GetBlockByNumber(uint64(blockNr))
388+
}
389+
367390
if block == nil {
368-
return BlockTraceResult{Error: fmt.Sprintf("block #%d not found", number)}
391+
return BlockTraceResult{Error: fmt.Sprintf("block #%d not found", blockNr)}
369392
}
370393

371394
validated, logs, err := api.traceBlock(block, config)

0 commit comments

Comments
 (0)