api/debug: Fix pending block issues in DumpBlock

This commit is contained in:
Martin Holst Swende 2017-04-05 17:23:16 +02:00
parent 1840ad48b6
commit 6018907243

View file

@ -283,16 +283,17 @@ func NewPublicDebugAPI(eth *Ethereum) *PublicDebugAPI {
// DumpBlock retrieves the entire state of the database at a given block. // DumpBlock retrieves the entire state of the database at a given block.
func (api *PublicDebugAPI) DumpBlock(blockNr rpc.BlockNumber) (state.Dump, error) { func (api *PublicDebugAPI) DumpBlock(blockNr rpc.BlockNumber) (state.Dump, error) {
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
// the miner and operate on those
_, stateDb := api.eth.miner.Pending()
return stateDb.RawDump(), nil
}
var block *types.Block var block *types.Block
if blockNr == rpc.LatestBlockNumber {
switch blockNr {
case rpc.PendingBlockNumber:
// Pending block is only known by the miner
block = api.eth.miner.PendingBlock()
case rpc.LatestBlockNumber:
block = api.eth.blockchain.CurrentBlock() block = api.eth.blockchain.CurrentBlock()
default: } else {
block = api.eth.blockchain.GetBlockByNumber(uint64(blockNr)) block = api.eth.blockchain.GetBlockByNumber(uint64(blockNr))
} }
if block == nil { if block == nil {
@ -362,9 +363,8 @@ func (api *PrivateDebugAPI) TraceBlockFromFile(file string, config *vm.LogConfig
// TraceBlockByNumber processes the block by canonical block number. // TraceBlockByNumber processes the block by canonical block number.
func (api *PrivateDebugAPI) TraceBlockByNumber(blockNr rpc.BlockNumber, config *vm.LogConfig) BlockTraceResult { func (api *PrivateDebugAPI) TraceBlockByNumber(blockNr rpc.BlockNumber, config *vm.LogConfig) BlockTraceResult {
var block *types.Block
// Fetch the block that we aim to reprocess // Fetch the block that we aim to reprocess
var block *types.Block
switch blockNr { switch blockNr {
case rpc.PendingBlockNumber: case rpc.PendingBlockNumber:
// Pending block is only known by the miner // Pending block is only known by the miner