Skip to content

Commit

Permalink
Check block transaction context errors
Browse files Browse the repository at this point in the history
  • Loading branch information
matejmode authored and wsodsong committed May 21, 2024
1 parent 9d62e27 commit ed55b54
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
5 changes: 4 additions & 1 deletion executor/extension/primer/primer.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ func (p *stateDbPrimer[T]) prime(stateDb state.StateDB) error {
return fmt.Errorf("cannot generate update-set; %w", err)
}
if hasPrimed {
p.ctx.SuicideAccounts(stateDb, deletedAccounts)
err = p.ctx.SuicideAccounts(stateDb, deletedAccounts)
if err != nil {
return err
}
}
if err = p.ctx.PrimeStateDB(substatecontext.NewWorldState(update), stateDb); err != nil {
return fmt.Errorf("cannot prime state-db; %w", err)
Expand Down
22 changes: 17 additions & 5 deletions utils/prime_ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,17 @@ func (pc *PrimeContext) PrimeStateDBRandom(ws txcontext.WorldState, db state.Sta
}

// SuicideAccounts clears storage of all input accounts.
func (pc *PrimeContext) SuicideAccounts(db state.StateDB, accounts []common.Address) {
func (pc *PrimeContext) SuicideAccounts(db state.StateDB, accounts []common.Address) error {
count := 0
db.BeginSyncPeriod(0)
db.BeginBlock(pc.block)
db.BeginTransaction(0)
err := db.BeginBlock(pc.block)
if err != nil {
return fmt.Errorf("DeleteDestroyedAccounts BeginBlock: %w", err)
}
err = db.BeginTransaction(0)
if err != nil {
return fmt.Errorf("DeleteDestroyedAccounts BeginTransaction: %w", err)
}
for _, addr := range accounts {
if db.Exist(addr) {
db.Suicide(addr)
Expand All @@ -244,8 +250,14 @@ func (pc *PrimeContext) SuicideAccounts(db state.StateDB, accounts []common.Addr
pc.exist[addr] = false
}
}
db.EndTransaction()
db.EndBlock()
err = db.EndTransaction()
if err != nil {
return fmt.Errorf("DeleteDestroyedAccounts EndTransaction: %w", err)
}
err = db.EndBlock()
if err != nil {
return fmt.Errorf("DeleteDestroyedAccounts EndBlock: %w", err)
}
db.EndSyncPeriod()
pc.block++
pc.log.Infof("\t\t %v suicided accounts were removed from statedb (before priming).", count)
Expand Down
20 changes: 16 additions & 4 deletions utils/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,26 @@ func DeleteDestroyedAccountsFromStateDB(db state.StateDB, cfg *Config, target ui
return nil
}
db.BeginSyncPeriod(0)
db.BeginBlock(target)
db.BeginTransaction(0)
err = db.BeginBlock(target)
if err != nil {
return fmt.Errorf("DeleteDestroyedAccounts BeginBlock: %w", err)
}
err = db.BeginTransaction(0)
if err != nil {
return fmt.Errorf("DeleteDestroyedAccounts BeginTransaction: %w", err)
}
for _, addr := range accounts {
db.Suicide(addr)
log.Debugf("Perform suicide on %v", addr)
}
db.EndTransaction()
db.EndBlock()
err = db.EndTransaction()
if err != nil {
return fmt.Errorf("DeleteDestroyedAccounts EndTransaction: %w", err)
}
err = db.EndBlock()
if err != nil {
return fmt.Errorf("DeleteDestroyedAccounts EndBlock: %w", err)
}
db.EndSyncPeriod()
return nil
}

0 comments on commit ed55b54

Please sign in to comment.