Skip to content

Commit

Permalink
Finalize state after each call in callMany (#6381)
Browse files Browse the repository at this point in the history
In `debug_traceCallMany` and `eth_callMany` the `IntraBlockState` is not
being finalized after each replayed transaction and after each call.
This can cause several problems:

- False gas consumption calculation. Specifically in `SSTORE` dynamic
gas calculation being affected by "warm" and "cold" storage slots, and
by "original" value comparison.
- Ability to call contracts that were `SELFDESTRUCT`ed in the replayed
transactions or during previous calls, as the self-destruction has not
been finalized.

see #6373 as an example.

This pull request adds a call to `FinalizeTx` after each `ApplyMessage`
and `TraceTx`
  • Loading branch information
ArielTM authored Dec 21, 2022
1 parent 0986342 commit 870b5ba
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/rpcdaemon/commands/eth_callMany.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ func (api *APIImpl) CallMany(ctx context.Context, bundles []Bundle, simulateCont
if err != nil {
return nil, err
}

_ = st.FinalizeTx(rules, state.NewNoopWriter())

// If the timer caused an abort, return an appropriate error message
if evm.Cancelled() {
return nil, fmt.Errorf("execution aborted (timeout = %v)", timeout)
Expand Down Expand Up @@ -274,6 +277,9 @@ func (api *APIImpl) CallMany(ctx context.Context, bundles []Bundle, simulateCont
if err != nil {
return nil, err
}

_ = st.FinalizeTx(rules, state.NewNoopWriter())

// If the timer caused an abort, return an appropriate error message
if evm.Cancelled() {
return nil, fmt.Errorf("execution aborted (timeout = %v)", timeout)
Expand Down
3 changes: 3 additions & 0 deletions cmd/rpcdaemon/commands/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ func (api *PrivateDebugAPIImpl) TraceCallMany(ctx context.Context, bundles []Bun
stream.WriteNil()
return err
}
_ = st.FinalizeTx(rules, state.NewNoopWriter())

}

Expand Down Expand Up @@ -440,6 +441,8 @@ func (api *PrivateDebugAPIImpl) TraceCallMany(ctx context.Context, bundles []Bun
return err
}

_ = ibs.FinalizeTx(rules, state.NewNoopWriter())

if txn_index < len(bundle.Transactions)-1 {
stream.WriteMore()
}
Expand Down

0 comments on commit 870b5ba

Please sign in to comment.