Skip to content

Commit

Permalink
Fix debug tracer error message (#2345)
Browse files Browse the repository at this point in the history
  • Loading branch information
tclemos committed Oct 11, 2023
1 parent 8cef48f commit 1dc3fe1
Show file tree
Hide file tree
Showing 9 changed files with 523 additions and 3 deletions.
10 changes: 9 additions & 1 deletion pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,15 @@ func (p *Pool) preExecuteTx(ctx context.Context, tx types.Transaction) (preExecu
// TODO: Add effectivePercentage = 0xFF to the request (factor of 1) when gRPC message is updated
processBatchResponse, err := p.state.PreProcessTransaction(ctx, &tx, nil)
if err != nil {
return response, err
isOOC := executor.IsROMOutOfCountersError(executor.RomErrorCode(err))
isOOG := errors.Is(err, runtime.ErrOutOfGas)
if !isOOC && !isOOG {
return response, err
} else {
response.isOOC = isOOC
response.isOOG = isOOG
return response, nil
}
}

if processBatchResponse.Responses != nil && len(processBatchResponse.Responses) > 0 {
Expand Down
8 changes: 6 additions & 2 deletions state/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ func (s *State) DebugTransaction(ctx context.Context, transactionHash common.Has
StateRoot: response.StateRoot.Bytes(),
StructLogs: response.ExecutionTrace,
ExecutorTrace: response.CallTrace,
Err: response.RomError,
}

// if is the default trace, return the result
Expand Down Expand Up @@ -430,7 +431,7 @@ func (s *State) DebugTransaction(ctx context.Context, transactionHash common.Has
fakeDB := &FakeDB{State: s, stateRoot: batch.StateRoot.Bytes()}
evm := fakevm.NewFakeEVM(fakevm.BlockContext{BlockNumber: big.NewInt(1)}, fakevm.TxContext{GasPrice: gasPrice}, fakeDB, params.TestChainConfig, fakevm.Config{Debug: true, Tracer: customTracer})

traceResult, err := s.buildTrace(evm, result.ExecutorTrace, customTracer)
traceResult, err := s.buildTrace(evm, result, customTracer)
if err != nil {
log.Errorf("debug transaction: failed parse the trace using the tracer: %v", err)
return nil, fmt.Errorf("failed parse the trace using the tracer: %v", err)
Expand All @@ -442,7 +443,8 @@ func (s *State) DebugTransaction(ctx context.Context, transactionHash common.Has
}

// ParseTheTraceUsingTheTracer parses the given trace with the given tracer.
func (s *State) buildTrace(evm *fakevm.FakeEVM, trace instrumentation.ExecutorTrace, tracer tracers.Tracer) (json.RawMessage, error) {
func (s *State) buildTrace(evm *fakevm.FakeEVM, result *runtime.ExecutionResult, tracer tracers.Tracer) (json.RawMessage, error) {
trace := result.ExecutorTrace
tracer.CaptureTxStart(trace.Context.Gas)
contextGas := trace.Context.Gas - trace.Context.GasUsed
if len(trace.Steps) > 0 {
Expand Down Expand Up @@ -577,6 +579,8 @@ func (s *State) buildTrace(evm *fakevm.FakeEVM, trace instrumentation.ExecutorTr
var err error
if reverted {
err = fakevm.ErrExecutionReverted
} else if result.Err != nil {
err = result.Err
}
tracer.CaptureEnd(trace.Context.Output, trace.Context.GasUsed, err)
restGas := trace.Context.Gas - trace.Context.GasUsed
Expand Down
14 changes: 14 additions & 0 deletions test/contracts/auto/ConstructorMap.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.7.0 <0.9.0;

contract ConstructorMap {
mapping(uint => uint) public numbers;

constructor() {
uint i = 0;
for (i = 0; i < 100; i++) {
numbers[i] = i;
}
}
}
11 changes: 11 additions & 0 deletions test/contracts/auto/FFFFFFFF.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.7.0 <0.9.0;

contract FFFFFFFF {
constructor() {
assembly {
return(0, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
}
}
}
234 changes: 234 additions & 0 deletions test/contracts/bin/ConstructorMap/ConstructorMap.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1dc3fe1

Please sign in to comment.