mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 05:06:43 +00:00
checkpoint commit
This commit is contained in:
parent
0ab9b2a213
commit
a91005076d
5 changed files with 26 additions and 17 deletions
|
|
@ -57,14 +57,20 @@ func NewBlockAccessListTracer(startIdx int) (*BlockAccessListTracer, *tracing.Ho
|
||||||
// It is assumed that this is only called after all the block state changes
|
// It is assumed that this is only called after all the block state changes
|
||||||
// have been executed and the block has been finalized.
|
// have been executed and the block has been finalized.
|
||||||
func (a *BlockAccessListTracer) AccessList() *bal.ConstructionBlockAccessList {
|
func (a *BlockAccessListTracer) AccessList() *bal.ConstructionBlockAccessList {
|
||||||
diff, reads := a.accessListBuilder.Finalise()
|
diff, reads := a.accessListBuilder.FinaliseIdxChanges()
|
||||||
a.accessList.Apply(a.balIdx, diff, reads)
|
a.accessList.Apply(a.balIdx, diff, reads)
|
||||||
a.accessListBuilder = new(bal.AccessListBuilder)
|
a.accessListBuilder = new(bal.AccessListBuilder)
|
||||||
return a.accessList
|
return a.accessList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: I don't like that AccessList and this do slightly different things,
|
||||||
|
// and that they mutate the access list builder (not apparent in the naming of the methods)
|
||||||
|
func (a *BlockAccessListTracer) IdxChanges() (*bal.StateDiff, bal.StateAccesses) {
|
||||||
|
return a.accessListBuilder.FinaliseIdxChanges()
|
||||||
|
}
|
||||||
|
|
||||||
func (a *BlockAccessListTracer) TxEndHook(receipt *types.Receipt, err error) {
|
func (a *BlockAccessListTracer) TxEndHook(receipt *types.Receipt, err error) {
|
||||||
diff, reads := a.accessListBuilder.Finalise()
|
diff, reads := a.accessListBuilder.FinaliseIdxChanges()
|
||||||
a.accessList.Apply(a.balIdx, diff, reads)
|
a.accessList.Apply(a.balIdx, diff, reads)
|
||||||
a.accessListBuilder = new(bal.AccessListBuilder)
|
a.accessListBuilder = new(bal.AccessListBuilder)
|
||||||
a.balIdx++
|
a.balIdx++
|
||||||
|
|
@ -72,7 +78,7 @@ func (a *BlockAccessListTracer) TxEndHook(receipt *types.Receipt, err error) {
|
||||||
|
|
||||||
func (a *BlockAccessListTracer) TxStartHook(vm *tracing.VMContext, tx *types.Transaction, from common.Address) {
|
func (a *BlockAccessListTracer) TxStartHook(vm *tracing.VMContext, tx *types.Transaction, from common.Address) {
|
||||||
if a.balIdx == 0 {
|
if a.balIdx == 0 {
|
||||||
diff, reads := a.accessListBuilder.Finalise()
|
diff, reads := a.accessListBuilder.FinaliseIdxChanges()
|
||||||
a.accessList.Apply(0, diff, reads)
|
a.accessList.Apply(0, diff, reads)
|
||||||
a.accessListBuilder = new(bal.AccessListBuilder)
|
a.accessListBuilder = new(bal.AccessListBuilder)
|
||||||
a.balIdx++
|
a.balIdx++
|
||||||
|
|
|
||||||
|
|
@ -122,12 +122,13 @@ func (p *ParallelStateProcessor) prepareExecResult(block *types.Block, allStateR
|
||||||
|
|
||||||
// Finalize the block, applying any consensus engine specific extras (e.g. block rewards)
|
// Finalize the block, applying any consensus engine specific extras (e.g. block rewards)
|
||||||
p.chain.engine.Finalize(p.chain, header, tracingStateDB, block.Body())
|
p.chain.engine.Finalize(p.chain, header, tracingStateDB, block.Body())
|
||||||
// invoke Finalise so that withdrawals are accounted for in the state diff
|
// invoke FinaliseIdxChanges so that withdrawals are accounted for in the state diff
|
||||||
postTxState.Finalise(true)
|
postTxState.Finalise(true)
|
||||||
allStateReads.Merge(balTracer.AccessList().StateAccesses())
|
diff, stateReads := balTracer.IdxChanges()
|
||||||
|
allStateReads.Merge(stateReads)
|
||||||
|
|
||||||
balIdx := len(block.Transactions()) + 1
|
balIdx := len(block.Transactions()) + 1
|
||||||
if err := postTxState.BlockAccessList().ValidateStateDiff(balIdx, balTracer.AccessList().DiffAt(balIdx)); err != nil {
|
if err := postTxState.BlockAccessList().ValidateStateDiff(balIdx, diff); err != nil {
|
||||||
return &ProcessResultWithMetrics{
|
return &ProcessResultWithMetrics{
|
||||||
ProcessResult: &ProcessResult{Error: err},
|
ProcessResult: &ProcessResult{Error: err},
|
||||||
}
|
}
|
||||||
|
|
@ -158,7 +159,7 @@ type txExecResult struct {
|
||||||
receipt *types.Receipt
|
receipt *types.Receipt
|
||||||
err error // non-EVM error which would render the block invalid
|
err error // non-EVM error which would render the block invalid
|
||||||
|
|
||||||
accessList *bal.ConstructionBlockAccessList
|
stateReads bal.StateAccesses
|
||||||
}
|
}
|
||||||
|
|
||||||
// resultHandler polls until all transactions have finished executing and the
|
// resultHandler polls until all transactions have finished executing and the
|
||||||
|
|
@ -187,7 +188,7 @@ func (p *ParallelStateProcessor) resultHandler(block *types.Block, preTxStateRea
|
||||||
execErr = err
|
execErr = err
|
||||||
} else {
|
} else {
|
||||||
receipts = append(receipts, res.receipt)
|
receipts = append(receipts, res.receipt)
|
||||||
allReads.Merge(res.accessList.StateAccesses())
|
allReads.Merge(res.stateReads)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -276,14 +277,15 @@ func (p *ParallelStateProcessor) execTx(block *types.Block, tx *types.Transactio
|
||||||
return &txExecResult{err: err}
|
return &txExecResult{err: err}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := db.BlockAccessList().ValidateStateDiff(txIdx+1, balTracer.AccessList().DiffAt(txIdx+1)); err != nil {
|
diff, accesses := balTracer.IdxChanges()
|
||||||
|
if err := db.BlockAccessList().ValidateStateDiff(txIdx+1, diff); err != nil {
|
||||||
return &txExecResult{err: err}
|
return &txExecResult{err: err}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &txExecResult{
|
return &txExecResult{
|
||||||
idx: txIdx,
|
idx: txIdx,
|
||||||
receipt: receipt,
|
receipt: receipt,
|
||||||
accessList: balTracer.AccessList(),
|
stateReads: accesses,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -330,7 +332,8 @@ func (p *ParallelStateProcessor) Process(block *types.Block, statedb *state.Stat
|
||||||
ProcessParentBlockHash(block.ParentHash(), evm)
|
ProcessParentBlockHash(block.ParentHash(), evm)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := statedb.BlockAccessList().ValidateStateDiff(0, balTracer.AccessList().DiffAt(0)); err != nil {
|
diff, stateReads := balTracer.IdxChanges()
|
||||||
|
if err := statedb.BlockAccessList().ValidateStateDiff(0, diff); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -345,7 +348,7 @@ func (p *ParallelStateProcessor) Process(block *types.Block, statedb *state.Stat
|
||||||
// TODO: figure out how to funnel the state reads from the bal tracer through to the post-block-exec state/slot read
|
// TODO: figure out how to funnel the state reads from the bal tracer through to the post-block-exec state/slot read
|
||||||
// validation
|
// validation
|
||||||
tExecStart = time.Now()
|
tExecStart = time.Now()
|
||||||
go p.resultHandler(block, balTracer.AccessList().StateAccesses(), postTxState, tExecStart, txResCh, rootCalcResultCh, resCh)
|
go p.resultHandler(block, stateReads, postTxState, tExecStart, txResCh, rootCalcResultCh, resCh)
|
||||||
var workers errgroup.Group
|
var workers errgroup.Group
|
||||||
startingState := statedb.Copy()
|
startingState := statedb.Copy()
|
||||||
for i, tx := range block.Transactions() {
|
for i, tx := range block.Transactions() {
|
||||||
|
|
|
||||||
|
|
@ -879,7 +879,7 @@ func (s *StateDB) Finalise(deleteEmptyObjects bool) {
|
||||||
// It is called in between transactions to get the root hash that
|
// It is called in between transactions to get the root hash that
|
||||||
// goes into transaction receipts.
|
// goes into transaction receipts.
|
||||||
func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash {
|
func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash {
|
||||||
// Finalise all the dirty storage states and write them into the tries
|
// FinaliseIdxChanges all the dirty storage states and write them into the tries
|
||||||
s.Finalise(deleteEmptyObjects)
|
s.Finalise(deleteEmptyObjects)
|
||||||
|
|
||||||
// Initialize the trie if it's not constructed yet. If the prefetch
|
// Initialize the trie if it's not constructed yet. If the prefetch
|
||||||
|
|
|
||||||
|
|
@ -191,7 +191,7 @@ func TestCopy(t *testing.T) {
|
||||||
ccopyObj.AddBalance(uint256.NewInt(4 * uint64(i)))
|
ccopyObj.AddBalance(uint256.NewInt(4 * uint64(i)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finalise the changes on all concurrently
|
// FinaliseIdxChanges the changes on all concurrently
|
||||||
finalise := func(wg *sync.WaitGroup, db *StateDB) {
|
finalise := func(wg *sync.WaitGroup, db *StateDB) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
db.Finalise(true)
|
db.Finalise(true)
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@ func (c *AccessListBuilder) ExitScope(reverted bool) {
|
||||||
c.accessesStack = c.accessesStack[:len(c.accessesStack)-1]
|
c.accessesStack = c.accessesStack[:len(c.accessesStack)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AccessListBuilder) Finalise() (*StateDiff, StateAccesses) {
|
func (a *AccessListBuilder) FinaliseIdxChanges() (*StateDiff, StateAccesses) {
|
||||||
diff := &StateDiff{make(map[common.Address]*AccountState)}
|
diff := &StateDiff{make(map[common.Address]*AccountState)}
|
||||||
stateAccesses := make(StateAccesses)
|
stateAccesses := make(StateAccesses)
|
||||||
|
|
||||||
|
|
@ -512,9 +512,9 @@ func (c *ConstructionBlockAccessList) BalanceChange(address common.Address, old,
|
||||||
c.Accounts[address].BalanceChange(old, new)
|
c.Accounts[address].BalanceChange(old, new)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ConstructionBlockAccessList) Finalise() {
|
func (c *ConstructionBlockAccessList) FinaliseIdxChanges() {
|
||||||
for _, account := range c.Accounts {
|
for _, account := range c.Accounts {
|
||||||
account.Finalise()
|
account.FinaliseIdxChanges()
|
||||||
}
|
}
|
||||||
c.curIdx++
|
c.curIdx++
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue