Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize gen-deleted-accounts #1085

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
34 changes: 22 additions & 12 deletions executor/transaction_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package executor

//go:generate mockgen -source transaction_processor.go -destination transaction_processor_mocks.go -package executor

import (
"errors"
"fmt"
Expand All @@ -36,11 +38,11 @@ import (

// MakeLiveDbTxProcessor creates a executor.Processor which processes transaction into LIVE StateDb.
func MakeLiveDbTxProcessor(cfg *utils.Config) *LiveDbTxProcessor {
return &LiveDbTxProcessor{MakeTxProcessor(cfg)}
return &LiveDbTxProcessor{makeTxProcessor(cfg)}
}

type LiveDbTxProcessor struct {
*TxProcessor
*txProcessor
}

// Process transaction inside state into given LIVE StateDb
Expand All @@ -62,11 +64,11 @@ func (p *LiveDbTxProcessor) Process(state State[txcontext.TxContext], ctx *Conte

// MakeArchiveDbTxProcessor creates a executor.Processor which processes transaction into ARCHIVE StateDb.
func MakeArchiveDbTxProcessor(cfg *utils.Config) *ArchiveDbTxProcessor {
return &ArchiveDbTxProcessor{MakeTxProcessor(cfg)}
return &ArchiveDbTxProcessor{makeTxProcessor(cfg)}
}

type ArchiveDbTxProcessor struct {
*TxProcessor
*txProcessor
}

// Process transaction inside state into given ARCHIVE StateDb
Expand All @@ -86,15 +88,23 @@ func (p *ArchiveDbTxProcessor) Process(state State[txcontext.TxContext], ctx *Co
return err
}

type TxProcessor struct {
type TxProcessor interface {
ProcessTransaction(db state.VmStateDB, block int, tx int, st txcontext.TxContext) (txcontext.Result, error)
}

type txProcessor struct {
cfg *utils.Config
numErrors *atomic.Int32 // transactions can be processed in parallel, so this needs to be thread safe
vmCfg vm.Config
chainCfg *params.ChainConfig
log logger.Logger
}

func MakeTxProcessor(cfg *utils.Config) *TxProcessor {
func MakeTxProcessor(cfg *utils.Config) TxProcessor {
return makeTxProcessor(cfg)
}

func makeTxProcessor(cfg *utils.Config) *txProcessor {
var vmCfg vm.Config
switch cfg.ChainID {
case utils.EthereumChainID:
Expand All @@ -111,16 +121,16 @@ func MakeTxProcessor(cfg *utils.Config) *TxProcessor {
vmCfg.Tracer = nil
vmCfg.Debug = false

return &TxProcessor{
return &txProcessor{
cfg: cfg,
numErrors: new(atomic.Int32),
vmCfg: vmCfg,
chainCfg: utils.GetChainConfig(cfg.ChainID),
log: logger.NewLogger(cfg.LogLevel, "TxProcessor"),
log: logger.NewLogger(cfg.LogLevel, "txProcessor"),
}
}

func (s *TxProcessor) isErrFatal() bool {
func (s *txProcessor) isErrFatal() bool {
if !s.cfg.ContinueOnFailure {
return true
}
Expand All @@ -138,15 +148,15 @@ func (s *TxProcessor) isErrFatal() bool {
return true
}

func (s *TxProcessor) ProcessTransaction(db state.VmStateDB, block int, tx int, st txcontext.TxContext) (txcontext.Result, error) {
func (s *txProcessor) ProcessTransaction(db state.VmStateDB, block int, tx int, st txcontext.TxContext) (txcontext.Result, error) {
if tx >= utils.PseudoTx {
return s.processPseudoTx(st.GetOutputState(), db), nil
}
return s.processRegularTx(db, block, tx, st)
}

// processRegularTx executes VM on a chosen storage system.
func (s *TxProcessor) processRegularTx(db state.VmStateDB, block int, tx int, st txcontext.TxContext) (res transactionResult, finalError error) {
func (s *txProcessor) processRegularTx(db state.VmStateDB, block int, tx int, st txcontext.TxContext) (res transactionResult, finalError error) {
var (
gasPool = new(evmcore.GasPool)
txHash = common.HexToHash(fmt.Sprintf("0x%016d%016d", block, tx))
Expand Down Expand Up @@ -190,7 +200,7 @@ func (s *TxProcessor) processRegularTx(db state.VmStateDB, block int, tx int, st

// processPseudoTx processes pseudo transactions in Lachesis by applying the change in db state.
// The pseudo transactions includes Lachesis SFC, lachesis genesis and lachesis-opera transition.
func (s *TxProcessor) processPseudoTx(ws txcontext.WorldState, db state.VmStateDB) txcontext.Result {
func (s *txProcessor) processPseudoTx(ws txcontext.WorldState, db state.VmStateDB) txcontext.Result {
ws.ForEachAccount(func(addr common.Address, acc txcontext.Account) {
db.SubBalance(addr, db.GetBalance(addr))
db.AddBalance(addr, acc.GetBalance())
Expand Down
56 changes: 56 additions & 0 deletions executor/transaction_processor_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions state/proxy/deletion.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ type DeletionProxy struct {
}

// NewDeletionProxy creates a new StateDB proxy.
func NewDeletionProxy(db state.StateDB, ch chan ContractLiveliness, logLevel string) *DeletionProxy {
func NewDeletionProxy(db state.StateDB, ch chan ContractLiveliness, log logger.Logger) *DeletionProxy {
r := new(DeletionProxy)
r.db = db
r.ch = ch
r.log = logger.NewLogger(logLevel, "Proxy Deletion")
r.log = log
return r
}

Expand Down
Loading