aboutsummaryrefslogtreecommitdiffstats
path: root/eth
diff options
context:
space:
mode:
authorMartin Holst Swende <martin@swende.se>2017-04-05 23:49:54 +0800
committerPéter Szilágyi <peterke@gmail.com>2017-04-05 23:49:54 +0800
commitcc303017c3f145441e583b5bb10ee3070b44cc50 (patch)
treea0c5618ca3e355fa3d98506513e86f07d1faa1cb /eth
parent49437a02c981199c62048fae00c6b80976f6e6b9 (diff)
downloadgo-tangerine-cc303017c3f145441e583b5bb10ee3070b44cc50.tar
go-tangerine-cc303017c3f145441e583b5bb10ee3070b44cc50.tar.gz
go-tangerine-cc303017c3f145441e583b5bb10ee3070b44cc50.tar.bz2
go-tangerine-cc303017c3f145441e583b5bb10ee3070b44cc50.tar.lz
go-tangerine-cc303017c3f145441e583b5bb10ee3070b44cc50.tar.xz
go-tangerine-cc303017c3f145441e583b5bb10ee3070b44cc50.tar.zst
go-tangerine-cc303017c3f145441e583b5bb10ee3070b44cc50.zip
debug: convert uint64-blocknumber into rpc.Blocknumber (#13862)
* debug: Converted uint64-blocknumber into rpc.Blocknumber * api/debug: Fix pending block issues in DumpBlock
Diffstat (limited to 'eth')
-rw-r--r--eth/api.go35
1 files changed, 29 insertions, 6 deletions
diff --git a/eth/api.go b/eth/api.go
index 58ae27df2..041ccd397 100644
--- a/eth/api.go
+++ b/eth/api.go
@@ -40,6 +40,7 @@ import (
"github.com/ethereum/go-ethereum/miner"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
+ "github.com/ethereum/go-ethereum/rpc"
)
const defaultTraceTimeout = 5 * time.Second
@@ -293,10 +294,22 @@ func NewPublicDebugAPI(eth *Ethereum) *PublicDebugAPI {
}
// DumpBlock retrieves the entire state of the database at a given block.
-func (api *PublicDebugAPI) DumpBlock(number uint64) (state.Dump, error) {
- block := api.eth.BlockChain().GetBlockByNumber(number)
+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
+ if blockNr == rpc.LatestBlockNumber {
+ block = api.eth.blockchain.CurrentBlock()
+ } else {
+ block = api.eth.blockchain.GetBlockByNumber(uint64(blockNr))
+ }
if block == nil {
- return state.Dump{}, fmt.Errorf("block #%d not found", number)
+ return state.Dump{}, fmt.Errorf("block #%d not found", blockNr)
}
stateDb, err := api.eth.BlockChain().StateAt(block.Root())
if err != nil {
@@ -361,11 +374,21 @@ func (api *PrivateDebugAPI) TraceBlockFromFile(file string, config *vm.LogConfig
}
// TraceBlockByNumber processes the block by canonical block number.
-func (api *PrivateDebugAPI) TraceBlockByNumber(number uint64, config *vm.LogConfig) BlockTraceResult {
+func (api *PrivateDebugAPI) TraceBlockByNumber(blockNr rpc.BlockNumber, config *vm.LogConfig) BlockTraceResult {
// Fetch the block that we aim to reprocess
- block := api.eth.BlockChain().GetBlockByNumber(number)
+ var block *types.Block
+ 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()
+ default:
+ block = api.eth.blockchain.GetBlockByNumber(uint64(blockNr))
+ }
+
if block == nil {
- return BlockTraceResult{Error: fmt.Sprintf("block #%d not found", number)}
+ return BlockTraceResult{Error: fmt.Sprintf("block #%d not found", blockNr)}
}
validated, logs, err := api.traceBlock(block, config)