mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-05 11:33:47 +00:00
doc: add more doc to commitStateAfterApply for tracing in miner (#452)
* WIP * add more * improve * fix typos
This commit is contained in:
parent
b428fa1339
commit
2a1788f7f3
1 changed files with 11 additions and 4 deletions
|
|
@ -760,11 +760,13 @@ func (w *worker) makeCurrent(parent *types.Block, header *types.Header) error {
|
|||
return err
|
||||
}
|
||||
|
||||
commitAfterApply := false // don't commit during tracing for circuit capacity checker, otherwise we cannot revert
|
||||
// don't commit the state during tracing for circuit capacity checker, otherwise we cannot revert.
|
||||
// and even if we don't commit the state, the `refund` value will still be correct, as explained in `CommitTransaction`
|
||||
commitStateAfterApply := false
|
||||
traceEnv, err := core.CreateTraceEnv(w.chainConfig, w.chain, w.engine, state, parent,
|
||||
// new block with a placeholder tx, for traceEnv's ExecutionResults length & TxStorageTraces length
|
||||
types.NewBlockWithHeader(header).WithBody([]*types.Transaction{types.NewTx(&types.LegacyTx{})}, nil),
|
||||
commitAfterApply)
|
||||
commitStateAfterApply)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -873,8 +875,13 @@ func (w *worker) commitTransaction(tx *types.Transaction, coinbase common.Addres
|
|||
"txhash", tx.Hash(),
|
||||
)
|
||||
|
||||
// has to check circuit capacity before `core.ApplyTransaction`,
|
||||
// because if the tx can be successfully executed but circuit capacity overflows, it will be inconvenient to revert
|
||||
// 1. we have to check circuit capacity before `core.ApplyTransaction`,
|
||||
// because if the tx can be successfully executed but circuit capacity overflows, it will be inconvenient to revert.
|
||||
// 2. even if we don't commit to the state during the tracing (which means `clearJournalAndRefund` is not called during the tracing),
|
||||
// the `refund` value will still be correct, because:
|
||||
// 2.1 when starting handling the first tx, `state.refund` is 0 by default,
|
||||
// 2.2 after tracing, the state is either committed in `core.ApplyTransaction`, or reverted, so the `state.refund` can be cleared,
|
||||
// 2.3 when starting handling the following txs, `state.refund` comes as 0
|
||||
traces, err := w.current.traceEnv.GetBlockTrace(
|
||||
types.NewBlockWithHeader(w.current.header).WithBody([]*types.Transaction{tx}, nil),
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue