core: add blockchain back to state processor for bor consensus

This commit is contained in:
Manav Darji 2025-03-26 12:10:15 +05:30
parent 88147109be
commit adb53876db
No known key found for this signature in database
GPG key ID: A426F0124435F36E
3 changed files with 12 additions and 8 deletions

View file

@ -363,7 +363,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
bc.statedb = state.NewDatabase(bc.triedb, nil) bc.statedb = state.NewDatabase(bc.triedb, nil)
bc.validator = NewBlockValidator(chainConfig, bc) bc.validator = NewBlockValidator(chainConfig, bc)
bc.prefetcher = newStatePrefetcher(chainConfig, bc.hc) bc.prefetcher = newStatePrefetcher(chainConfig, bc.hc)
bc.processor = NewStateProcessor(chainConfig, bc.hc) bc.processor = NewStateProcessor(chainConfig, bc.hc, bc)
bc.genesisBlock = bc.GetBlockByNumber(0) bc.genesisBlock = bc.GetBlockByNumber(0)
if bc.genesisBlock == nil { if bc.genesisBlock == nil {

View file

@ -37,15 +37,17 @@ import (
// //
// StateProcessor implements Processor. // StateProcessor implements Processor.
type StateProcessor struct { type StateProcessor struct {
config *params.ChainConfig // Chain configuration options config *params.ChainConfig // Chain configuration options
chain *HeaderChain // Canonical header chain chain *HeaderChain // Canonical header chain
blockchain *BlockChain
} }
// NewStateProcessor initialises a new StateProcessor. // NewStateProcessor initialises a new StateProcessor.
func NewStateProcessor(config *params.ChainConfig, chain *HeaderChain) *StateProcessor { func NewStateProcessor(config *params.ChainConfig, chain *HeaderChain, blockchain *BlockChain) *StateProcessor {
return &StateProcessor{ return &StateProcessor{
config: config, config: config,
chain: chain, chain: chain,
blockchain: blockchain,
} }
} }
@ -133,7 +135,9 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
} }
// 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()) // Note that we specifically need `Blockchain` for `ChainHeaderReader` interface as it's
// typecasted in bor consensus for setting state-sync events.
p.chain.engine.Finalize(p.blockchain, header, tracingStateDB, block.Body())
return &ProcessResult{ return &ProcessResult{
Receipts: receipts, Receipts: receipts,

View file

@ -64,7 +64,7 @@ func ExecuteStateless(config *params.ChainConfig, block *types.Block, witness *s
headerCache: lru.NewCache[common.Hash, *types.Header](256), headerCache: lru.NewCache[common.Hash, *types.Header](256),
engine: beacon.New(ethash.NewFaker()), engine: beacon.New(ethash.NewFaker()),
} }
processor := NewStateProcessor(config, headerChain) processor := NewStateProcessor(config, headerChain, nil)
validator := NewBlockValidator(config, nil) // No chain, we only validate the state, not the block validator := NewBlockValidator(config, nil) // No chain, we only validate the state, not the block
// Run the stateless blocks processing and self-validate certain fields // Run the stateless blocks processing and self-validate certain fields