Skip to content

Commit

Permalink
core/blockchain: add evm hook to blockchain object
Browse files Browse the repository at this point in the history
  • Loading branch information
minh-bq committed Nov 20, 2023
1 parent a63b17c commit 4370f97
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
13 changes: 11 additions & 2 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ type BlockChain struct {
shouldPreserve func(*types.Block) bool // Function used to determine whether should preserve the given block.
shouldStoreInternalTxs bool
enableAdditionalChainEvent bool
evmHook vm.EVMHook
}

// NewBlockChain returns a fully initialised block chain using information
Expand Down Expand Up @@ -427,6 +428,14 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
return bc, nil
}

func (bc *BlockChain) SetHook(evmHook vm.EVMHook) {
bc.evmHook = evmHook
}

func (bc *BlockChain) GetHook() vm.EVMHook {
return bc.evmHook
}

func (bc *BlockChain) loadLatestDirtyAccounts() {
dirtyStateAccounts := rawdb.ReadDirtyAccounts(bc.db)
for _, data := range dirtyStateAccounts {
Expand Down Expand Up @@ -1515,9 +1524,9 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.

if status == CanonStatTy {
if bc.enableAdditionalChainEvent {
bc.sendNewBlockEvent(block, receipts, true, true)
bc.sendNewBlockEvent(block, receipts, true, true)
} else {
bc.sendNewBlockEvent(block, receipts, false, false)
bc.sendNewBlockEvent(block, receipts, false, false)
}
if len(logs) > 0 {
bc.logsFeed.Send(logs)
Expand Down
5 changes: 5 additions & 0 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
)

Expand Down Expand Up @@ -74,6 +75,10 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg

blockContext := NewEVMBlockContext(header, p.bc, nil, publishEvents...)
vmenv := vm.NewEVM(blockContext, vm.TxContext{}, statedb, p.config, cfg)
if evmHook := p.bc.GetHook(); evmHook != nil {
log.Debug("set hook function for testnet")
vmenv.SetHook(evmHook)
}

txNum := len(block.Transactions())
commonTxs := make([]*types.Transaction, 0, txNum)
Expand Down

0 comments on commit 4370f97

Please sign in to comment.