mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 13:16:42 +00:00
passing stExample suite
This commit is contained in:
parent
ef9b48603f
commit
04195f7311
3 changed files with 35 additions and 13 deletions
|
|
@ -26,6 +26,9 @@ type BlockAccessListTracer struct {
|
||||||
accessList *bal.ConstructionBlockAccessList
|
accessList *bal.ConstructionBlockAccessList
|
||||||
balIdx uint16
|
balIdx uint16
|
||||||
accessListBuilder *bal.AccessListBuilder
|
accessListBuilder *bal.AccessListBuilder
|
||||||
|
|
||||||
|
idxMutations *bal.StateDiff
|
||||||
|
idxReads bal.StateAccesses
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBlockAccessListTracer returns an BlockAccessListTracer and a set of hooks
|
// NewBlockAccessListTracer returns an BlockAccessListTracer and a set of hooks
|
||||||
|
|
@ -33,6 +36,7 @@ func NewBlockAccessListTracer(startIdx int) (*BlockAccessListTracer, *tracing.Ho
|
||||||
balTracer := &BlockAccessListTracer{
|
balTracer := &BlockAccessListTracer{
|
||||||
accessList: bal.NewConstructionBlockAccessList(),
|
accessList: bal.NewConstructionBlockAccessList(),
|
||||||
balIdx: uint16(startIdx),
|
balIdx: uint16(startIdx),
|
||||||
|
accessListBuilder: bal.NewAccessListBuilder(),
|
||||||
}
|
}
|
||||||
hooks := &tracing.Hooks{
|
hooks := &tracing.Hooks{
|
||||||
OnTxEnd: balTracer.TxEndHook,
|
OnTxEnd: balTracer.TxEndHook,
|
||||||
|
|
@ -57,25 +61,28 @@ 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.FinaliseIdxChanges()
|
|
||||||
a.accessList.Apply(a.balIdx, diff, reads)
|
|
||||||
a.accessListBuilder = new(bal.AccessListBuilder)
|
|
||||||
return a.accessList
|
return a.accessList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *BlockAccessListTracer) Finalise() {
|
||||||
|
a.idxMutations, a.idxReads = a.accessListBuilder.FinaliseIdxChanges()
|
||||||
|
a.accessList.Apply(a.balIdx, a.idxMutations, a.idxReads)
|
||||||
|
a.accessListBuilder = new(bal.AccessListBuilder)
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: I don't like that AccessList and this do slightly different things,
|
// 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)
|
// and that they mutate the access list builder (not apparent in the naming of the methods)
|
||||||
//
|
//
|
||||||
// ^ idea: add Finalize() which returns the diff/accesses, also accumulating them in the BAL.
|
// ^ idea: add Finalize() which returns the diff/accesses, also accumulating them in the BAL.
|
||||||
// AccessList just returns the constructed BAL.
|
// AccessList just returns the constructed BAL.
|
||||||
func (a *BlockAccessListTracer) IdxChanges() (*bal.StateDiff, bal.StateAccesses) {
|
func (a *BlockAccessListTracer) IdxChanges() (*bal.StateDiff, bal.StateAccesses) {
|
||||||
return a.accessListBuilder.FinaliseIdxChanges()
|
return a.idxMutations, a.idxReads
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *BlockAccessListTracer) TxEndHook(receipt *types.Receipt, err error) {
|
func (a *BlockAccessListTracer) TxEndHook(receipt *types.Receipt, err error) {
|
||||||
diff, reads := a.accessListBuilder.FinaliseIdxChanges()
|
a.idxMutations, a.idxReads = a.accessListBuilder.FinaliseIdxChanges()
|
||||||
a.accessList.Apply(a.balIdx, diff, reads)
|
a.accessList.Apply(a.balIdx, a.idxMutations, a.idxReads)
|
||||||
a.accessListBuilder = new(bal.AccessListBuilder)
|
a.accessListBuilder = bal.NewAccessListBuilder()
|
||||||
a.balIdx++
|
a.balIdx++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -83,7 +90,7 @@ func (a *BlockAccessListTracer) TxStartHook(vm *tracing.VMContext, tx *types.Tra
|
||||||
if a.balIdx == 0 {
|
if a.balIdx == 0 {
|
||||||
diff, reads := a.accessListBuilder.FinaliseIdxChanges()
|
diff, reads := a.accessListBuilder.FinaliseIdxChanges()
|
||||||
a.accessList.Apply(0, diff, reads)
|
a.accessList.Apply(0, diff, reads)
|
||||||
a.accessListBuilder = new(bal.AccessListBuilder)
|
a.accessListBuilder = bal.NewAccessListBuilder()
|
||||||
a.balIdx++
|
a.balIdx++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -124,6 +124,7 @@ func (p *ParallelStateProcessor) prepareExecResult(block *types.Block, allStateR
|
||||||
p.chain.engine.Finalize(p.chain, header, tracingStateDB, block.Body())
|
p.chain.engine.Finalize(p.chain, header, tracingStateDB, block.Body())
|
||||||
// invoke FinaliseIdxChanges 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)
|
||||||
|
balTracer.Finalise()
|
||||||
diff, stateReads := balTracer.IdxChanges()
|
diff, stateReads := balTracer.IdxChanges()
|
||||||
allStateReads.Merge(stateReads)
|
allStateReads.Merge(stateReads)
|
||||||
|
|
||||||
|
|
@ -292,7 +293,6 @@ func (p *ParallelStateProcessor) execTx(block *types.Block, tx *types.Transactio
|
||||||
// Process performs EVM execution and state root computation for a block which is known
|
// Process performs EVM execution and state root computation for a block which is known
|
||||||
// to contain an access list.
|
// to contain an access list.
|
||||||
func (p *ParallelStateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg vm.Config) (*ProcessResultWithMetrics, error) {
|
func (p *ParallelStateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg vm.Config) (*ProcessResultWithMetrics, error) {
|
||||||
fmt.Printf("process block with bal\n%s\n", block.Body().AccessList.String())
|
|
||||||
var (
|
var (
|
||||||
header = block.Header()
|
header = block.Header()
|
||||||
resCh = make(chan *ProcessResultWithMetrics)
|
resCh = make(chan *ProcessResultWithMetrics)
|
||||||
|
|
@ -332,6 +332,9 @@ func (p *ParallelStateProcessor) Process(block *types.Block, statedb *state.Stat
|
||||||
ProcessParentBlockHash(block.ParentHash(), evm)
|
ProcessParentBlockHash(block.ParentHash(), evm)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: weird that I have to manually call finalize here
|
||||||
|
balTracer.Finalise()
|
||||||
|
|
||||||
diff, stateReads := balTracer.IdxChanges()
|
diff, stateReads := balTracer.IdxChanges()
|
||||||
if err := statedb.BlockAccessList().ValidateStateDiff(0, diff); err != nil {
|
if err := statedb.BlockAccessList().ValidateStateDiff(0, diff); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -65,12 +65,21 @@ type AccessListBuilder struct {
|
||||||
accessesStack []map[common.Address]*constructionAccountAccess
|
accessesStack []map[common.Address]*constructionAccountAccess
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewAccessListBuilder() *AccessListBuilder {
|
||||||
|
return &AccessListBuilder{
|
||||||
|
make(map[common.Address]*AccountState),
|
||||||
|
[]map[common.Address]*constructionAccountAccess{
|
||||||
|
make(map[common.Address]*constructionAccountAccess),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c *AccessListBuilder) StorageRead(addr common.Address, key common.Hash) {
|
func (c *AccessListBuilder) StorageRead(addr common.Address, key common.Hash) {
|
||||||
panic("not implemented")
|
//panic("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *AccessListBuilder) AccountRead(addr common.Address) {
|
func (c *AccessListBuilder) AccountRead(addr common.Address) {
|
||||||
panic("not implemented")
|
//panic("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *AccessListBuilder) StorageWrite(address common.Address, key, prevVal, newVal common.Hash) {
|
func (c *AccessListBuilder) StorageWrite(address common.Address, key, prevVal, newVal common.Hash) {
|
||||||
|
|
@ -232,6 +241,9 @@ func (c *ConstructionBlockAccessList) Apply(idx uint16, diff *StateDiff, accesse
|
||||||
acctChanges.StorageWrites = make(map[common.Hash]map[uint16]common.Hash)
|
acctChanges.StorageWrites = make(map[common.Hash]map[uint16]common.Hash)
|
||||||
}
|
}
|
||||||
for key, val := range stateDiff.StorageWrites {
|
for key, val := range stateDiff.StorageWrites {
|
||||||
|
if _, ok := acctChanges.StorageWrites[key]; !ok {
|
||||||
|
acctChanges.StorageWrites[key] = make(map[uint16]common.Hash)
|
||||||
|
}
|
||||||
acctChanges.StorageWrites[key][idx] = val
|
acctChanges.StorageWrites[key][idx] = val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue