Skip to content

Commit 53016c1

Browse files
committed
eth, rpc: make trace configs optional
1 parent bbc77f4 commit 53016c1

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

eth/api.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,7 +1594,7 @@ type BlockTraceResult struct {
15941594

15951595
// TraceBlock processes the given block's RLP but does not import the block in to
15961596
// the chain.
1597-
func (api *PrivateDebugAPI) TraceBlock(blockRlp []byte, config vm.Config) BlockTraceResult {
1597+
func (api *PrivateDebugAPI) TraceBlock(blockRlp []byte, config *vm.Config) BlockTraceResult {
15981598
var block types.Block
15991599
err := rlp.Decode(bytes.NewReader(blockRlp), &block)
16001600
if err != nil {
@@ -1611,7 +1611,7 @@ func (api *PrivateDebugAPI) TraceBlock(blockRlp []byte, config vm.Config) BlockT
16111611

16121612
// TraceBlockFromFile loads the block's RLP from the given file name and attempts to
16131613
// process it but does not import the block in to the chain.
1614-
func (api *PrivateDebugAPI) TraceBlockFromFile(file string, config vm.Config) BlockTraceResult {
1614+
func (api *PrivateDebugAPI) TraceBlockFromFile(file string, config *vm.Config) BlockTraceResult {
16151615
blockRlp, err := ioutil.ReadFile(file)
16161616
if err != nil {
16171617
return BlockTraceResult{Error: fmt.Sprintf("could not read file: %v", err)}
@@ -1620,7 +1620,7 @@ func (api *PrivateDebugAPI) TraceBlockFromFile(file string, config vm.Config) Bl
16201620
}
16211621

16221622
// TraceProcessBlock processes the block by canonical block number.
1623-
func (api *PrivateDebugAPI) TraceBlockByNumber(number uint64, config vm.Config) BlockTraceResult {
1623+
func (api *PrivateDebugAPI) TraceBlockByNumber(number uint64, config *vm.Config) BlockTraceResult {
16241624
// Fetch the block that we aim to reprocess
16251625
block := api.eth.BlockChain().GetBlockByNumber(number)
16261626
if block == nil {
@@ -1636,7 +1636,7 @@ func (api *PrivateDebugAPI) TraceBlockByNumber(number uint64, config vm.Config)
16361636
}
16371637

16381638
// TraceBlockByHash processes the block by hash.
1639-
func (api *PrivateDebugAPI) TraceBlockByHash(hash common.Hash, config vm.Config) BlockTraceResult {
1639+
func (api *PrivateDebugAPI) TraceBlockByHash(hash common.Hash, config *vm.Config) BlockTraceResult {
16401640
// Fetch the block that we aim to reprocess
16411641
block := api.eth.BlockChain().GetBlock(hash)
16421642
if block == nil {
@@ -1664,14 +1664,17 @@ func (t *TraceCollector) AddStructLog(slog vm.StructLog) {
16641664
}
16651665

16661666
// traceBlock processes the given block but does not save the state.
1667-
func (api *PrivateDebugAPI) traceBlock(block *types.Block, config vm.Config) (bool, []vm.StructLog, error) {
1667+
func (api *PrivateDebugAPI) traceBlock(block *types.Block, config *vm.Config) (bool, []vm.StructLog, error) {
16681668
// Validate and reprocess the block
16691669
var (
16701670
blockchain = api.eth.BlockChain()
16711671
validator = blockchain.Validator()
16721672
processor = blockchain.Processor()
16731673
collector = &TraceCollector{}
16741674
)
1675+
if config == nil {
1676+
config = new(vm.Config)
1677+
}
16751678
config.Debug = true // make sure debug is set.
16761679
config.Logger.Collector = collector
16771680

@@ -1683,7 +1686,7 @@ func (api *PrivateDebugAPI) traceBlock(block *types.Block, config vm.Config) (bo
16831686
return false, collector.traces, err
16841687
}
16851688

1686-
receipts, _, usedGas, err := processor.Process(block, statedb, config)
1689+
receipts, _, usedGas, err := processor.Process(block, statedb, *config)
16871690
if err != nil {
16881691
return false, collector.traces, err
16891692
}
@@ -1771,7 +1774,10 @@ func formatError(err error) string {
17711774

17721775
// TraceTransaction returns the structured logs created during the execution of EVM
17731776
// and returns them as a JSON object.
1774-
func (s *PrivateDebugAPI) TraceTransaction(txHash common.Hash, logger vm.LogConfig) (*ExecutionResult, error) {
1777+
func (s *PrivateDebugAPI) TraceTransaction(txHash common.Hash, logger *vm.LogConfig) (*ExecutionResult, error) {
1778+
if logger == nil {
1779+
logger = new(vm.LogConfig)
1780+
}
17751781
// Retrieve the tx from the chain and the containing block
17761782
tx, blockHash, _, txIndex := core.GetTransaction(s.eth.ChainDb(), txHash)
17771783
if tx == nil {
@@ -1815,7 +1821,7 @@ func (s *PrivateDebugAPI) TraceTransaction(txHash common.Hash, logger vm.LogConf
18151821
continue
18161822
}
18171823
// Otherwise trace the transaction and return
1818-
vmenv := core.NewEnv(stateDb, s.config, s.eth.BlockChain(), msg, parent.Header(), vm.Config{Debug: true, Logger: logger})
1824+
vmenv := core.NewEnv(stateDb, s.config, s.eth.BlockChain(), msg, parent.Header(), vm.Config{Debug: true, Logger: *logger})
18191825
ret, gas, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(tx.Gas()))
18201826
if err != nil {
18211827
return nil, fmt.Errorf("tracing failed: %v", err)

rpc/javascript.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,22 +268,22 @@ web3._extend({
268268
new web3._extend.Method({
269269
name: 'traceBlock',
270270
call: 'debug_traceBlock',
271-
params: 2
271+
params: 1
272272
}),
273273
new web3._extend.Method({
274274
name: 'traceBlockByFile',
275275
call: 'debug_traceBlockByFile',
276-
params: 2
276+
params: 1
277277
}),
278278
new web3._extend.Method({
279279
name: 'traceBlockByNumber',
280280
call: 'debug_traceBlockByNumber',
281-
params: 2
281+
params: 1
282282
}),
283283
new web3._extend.Method({
284284
name: 'traceBlockByHash',
285285
call: 'debug_traceBlockByHash',
286-
params: 2
286+
params: 1
287287
}),
288288
new web3._extend.Method({
289289
name: 'seedHash',
@@ -390,7 +390,7 @@ web3._extend({
390390
new web3._extend.Method({
391391
name: 'traceTransaction',
392392
call: 'debug_traceTransaction',
393-
params: 2
393+
params: 1
394394
})
395395
],
396396
properties: []

0 commit comments

Comments
 (0)