Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement stateDiff tracer, compatible with OpenEthereum #345

Merged
merged 43 commits into from
Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
870c32c
eth: extract traceChain from the PrivateDebugAPI
ziogaschr Jan 21, 2021
8e92da0
eth: add initial draft API for `trace_filter`
ziogaschr Jan 21, 2021
cf41363
eth: add `trace_call`
ziogaschr Jan 21, 2021
043fbb6
eth: tracer_call to allow handling other tracers
ziogaschr Jan 26, 2021
dcf1526
eth/tracers: add draft state_diff JS tracer
ziogaschr Jan 26, 2021
54d6a42
eth: add trace_callMany
ziogaschr Feb 4, 2021
c55a07b
eth: add block context for trace_call
ziogaschr Feb 4, 2021
e838bd0
core/vm, eth/tracers: add EVM param in CaptureEnd
ziogaschr Feb 9, 2021
05b9d09
🍬 cleanup
ziogaschr Feb 9, 2021
b4211dc
eth/tracers: add JS context for statedb.Empty
ziogaschr Feb 9, 2021
189c4b7
eth/tracers: work on state_diff tracer
ziogaschr Feb 9, 2021
a7c0cfa
eth/tracers: add support for init method call on supported JS tracers
ziogaschr Feb 26, 2021
7a2d341
eth/tracers: work on balance calculations
ziogaschr Feb 26, 2021
94d7861
eth: trace_call to run on top of the provided block (with txs) on reexec
ziogaschr Mar 11, 2021
2744d8b
eth, eth/tracers: cleanup/verify state_diff logic
ziogaschr Mar 11, 2021
a3fc184
eth, eth/tracers: try complex code cleaning for state_diff by adding …
ziogaschr Mar 12, 2021
ad4ab68
eth, eth/tracers: fix trace_callMany for state_diff; will deduplicate…
ziogaschr Mar 16, 2021
4baa4a0
eth/tracers: add state_diff JS tracer tests
ziogaschr Mar 17, 2021
a461bd7
eth/tracers: update prestate tracer to use the new CapturePreEVM/init…
ziogaschr Mar 17, 2021
608a52e
eth/tracers: remove debug logs from state_diff
ziogaschr Mar 17, 2021
ca31c22
eth/tracers: add stateDiff test for internall call OOG
ziogaschr Mar 17, 2021
28298a0
eth/tracers: refactor the test runner for state_diff
ziogaschr Mar 17, 2021
748b5e1
Merge branch 'master' into feat/trace-state-diff
ziogaschr Mar 17, 2021
89b3cce
eth, eth/tracers: fixes
ziogaschr Mar 17, 2021
b9ec8b3
eth, eth/tracers, ethclient: cleanup, comments, semi-fix test
ziogaschr Mar 17, 2021
ae3ca5c
eth/tracers: add stateDiff test for a slow tx
ziogaschr Mar 17, 2021
a4a73d0
ethclient: fix discovery test by removing subscription based “trace_f…
ziogaschr Mar 17, 2021
7d77e8f
eth: allow Parity Ad-hoc tracers to be nested for full compatiblity w…
ziogaschr Mar 29, 2021
4b6dce0
eth: fix typo
ziogaschr Mar 29, 2021
b60a6e3
docs: add trace module overview
ziogaschr Mar 29, 2021
3582231
eth: Allow `trace_*` methods to use all the available JS tracers
ziogaschr Mar 30, 2021
a5d00e0
eth: extract condition-to-decorate out of decoration fn
meowsbits Mar 30, 2021
bbc4a7b
core/vm, eth/tracers: add `CapturePreEVM` to the `Tracer` interface
ziogaschr Mar 31, 2021
53eaf17
core/vm: revert prettyfication commit
ziogaschr Mar 31, 2021
16fb0ec
eth/tracers: rename `isEmpty` to `empty` for db wrapper
ziogaschr Mar 31, 2021
2e486f6
docs: add more on trace-overview docs
ziogaschr Mar 31, 2021
1071749
docs: add stateDiff output docs on trace-overview
ziogaschr Mar 31, 2021
e0b8ae0
internal/web3ext: add better inputFormatters for console’s web3 `trac…
ziogaschr Mar 31, 2021
84bf302
eth: refactor the parity decorate function for clarity
ziogaschr Mar 31, 2021
795a79d
eth: apply `decorateResponse` on nested txs for callMany
ziogaschr Apr 1, 2021
f553df4
eth/tracers: remove commented out code (dead code)
ziogaschr Apr 1, 2021
523cafe
eth/tracers: remove unneeded code (commented out)
ziogaschr Apr 1, 2021
9894118
Fix typos in comments
ziogaschr Apr 1, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (st *StateTransition) to() common.Address {

func (st *StateTransition) buyGas() error {
mgval := new(big.Int).Mul(new(big.Int).SetUint64(st.msg.Gas()), st.gasPrice)
if st.state.GetBalance(st.msg.From()).Cmp(mgval) < 0 {
if !st.evm.CanTransfer(st.state, st.msg.From(), mgval) {
return ErrInsufficientFunds
}
if err := st.gp.SubGas(st.msg.Gas()); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
// Calling a non existing account, don't do anything, but ping the tracer
if evm.vmConfig.Debug && evm.depth == 0 {
evm.vmConfig.Tracer.CaptureStart(caller.Address(), addr, false, input, gas, value)
evm.vmConfig.Tracer.CaptureEnd(ret, 0, 0, nil)
evm.vmConfig.Tracer.CaptureEnd(evm, ret, 0, 0, nil)
}
return nil, gas, nil
}
Expand All @@ -211,7 +211,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
if evm.vmConfig.Debug && evm.depth == 0 {
evm.vmConfig.Tracer.CaptureStart(caller.Address(), addr, false, input, gas, value)
defer func(startGas uint64, startTime time.Time) { // Lazy evaluation of the parameters
evm.vmConfig.Tracer.CaptureEnd(ret, startGas-gas, time.Since(startTime), err)
evm.vmConfig.Tracer.CaptureEnd(evm, ret, startGas-gas, time.Since(startTime), err)
}(gas, time.Now())
}

Expand Down Expand Up @@ -468,7 +468,7 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
err = ErrMaxCodeSizeExceeded
}
if evm.vmConfig.Debug && evm.depth == 0 {
evm.vmConfig.Tracer.CaptureEnd(ret, gas-contract.Gas, time.Since(start), err)
evm.vmConfig.Tracer.CaptureEnd(evm, ret, gas-contract.Gas, time.Since(start), err)
}
return ret, address, contract.Gas, err

Expand Down
3 changes: 1 addition & 2 deletions core/vm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,7 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
// consume the gas and return an error if not enough gas is available.
// cost is explicitly set so that the capture state defer method can get the proper cost
if operation.dynamicGas != nil {
var dynamicCost uint64
dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize)
dynamicCost, err := operation.dynamicGas(in.evm, contract, stack, mem, memorySize)
cost += dynamicCost // total cost, for debug tracing
if err != nil || !contract.UseGas(dynamicCost) {
return nil, ErrOutOfGas
Expand Down
6 changes: 3 additions & 3 deletions core/vm/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ type Tracer interface {
CaptureStart(from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) error
CaptureState(env *EVM, pc uint64, op OpCode, gas, cost uint64, memory *Memory, stack *Stack, rStack *ReturnStack, rData []byte, contract *Contract, depth int, err error) error
CaptureFault(env *EVM, pc uint64, op OpCode, gas, cost uint64, memory *Memory, stack *Stack, rStack *ReturnStack, contract *Contract, depth int, err error) error
CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error) error
CaptureEnd(env *EVM, output []byte, gasUsed uint64, t time.Duration, err error) error
}

// StructLogger is an EVM state logger and implements Tracer.
Expand Down Expand Up @@ -216,7 +216,7 @@ func (l *StructLogger) CaptureFault(env *EVM, pc uint64, op OpCode, gas, cost ui
}

// CaptureEnd is called after the call finishes to finalize the tracing.
func (l *StructLogger) CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error) error {
func (l *StructLogger) CaptureEnd(env *EVM, output []byte, gasUsed uint64, t time.Duration, err error) error {
l.output = output
l.err = err
if l.cfg.Debug {
Expand Down Expand Up @@ -358,7 +358,7 @@ func (t *mdLogger) CaptureFault(env *EVM, pc uint64, op OpCode, gas, cost uint64
return nil
}

func (t *mdLogger) CaptureEnd(output []byte, gasUsed uint64, tm time.Duration, err error) error {
func (t *mdLogger) CaptureEnd(env *EVM, output []byte, gasUsed uint64, tm time.Duration, err error) error {
fmt.Fprintf(t.out, "\nOutput: `0x%x`\nConsumed gas: `%d`\nError: `%v`\n",
output, gasUsed, err)
return nil
Expand Down
2 changes: 1 addition & 1 deletion core/vm/logger_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (l *JSONLogger) CaptureFault(env *EVM, pc uint64, op OpCode, gas, cost uint
}

// CaptureEnd is triggered at end of execution.
func (l *JSONLogger) CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error) error {
func (l *JSONLogger) CaptureEnd(env *EVM, output []byte, gasUsed uint64, t time.Duration, err error) error {
type endLog struct {
Output string `json:"output"`
GasUsed math.HexOrDecimal64 `json:"gasUsed"`
Expand Down
2 changes: 1 addition & 1 deletion core/vm/runtime/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ func (s *stepCounter) CaptureFault(env *vm.EVM, pc uint64, op vm.OpCode, gas, co
return nil
}

func (s *stepCounter) CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error) error {
func (s *stepCounter) CaptureEnd(env *vm.EVM, output []byte, gasUsed uint64, t time.Duration, err error) error {
return nil
}

Expand Down
Loading