Skip to content

Commit

Permalink
fix: testcases, add: block broadcasting mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
anshalshukla committed Aug 30, 2024
1 parent 3c48fca commit c0ff6db
Show file tree
Hide file tree
Showing 18 changed files with 635 additions and 217 deletions.
118 changes: 0 additions & 118 deletions consensus/merger.go

This file was deleted.

2 changes: 1 addition & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
bc.stateCache = state.NewDatabaseWithNodeDB(bc.db, bc.triedb)
bc.validator = NewBlockValidator(chainConfig, bc)
bc.prefetcher = newStatePrefetcher(chainConfig, bc.hc)
bc.processor = NewStateProcessor(chainConfig, bc.hc)
bc.processor = NewStateProcessor(chainConfig, bc, bc.hc)

bc.genesisBlock = bc.GetBlockByNumber(0)
if bc.genesisBlock == nil {
Expand Down
15 changes: 7 additions & 8 deletions core/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2189,7 +2189,6 @@ func testSideImport(t *testing.T, numCanonBlocksInSidechain, blocksBetweenCommon
chainConfig := *params.TestChainConfig

var (
merger = consensus.NewMerger(rawdb.NewMemoryDatabase())
engine = beacon.New(ethash.NewFaker())
key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
addr = crypto.PubkeyToAddress(key.PublicKey)
Expand All @@ -2212,15 +2211,15 @@ func testSideImport(t *testing.T, numCanonBlocksInSidechain, blocksBetweenCommon
defer chain.Stop()

// Activate the transition since genesis if required
if mergePoint == 0 {
mergeBlock = 0
// if mergePoint == 0 {
// mergeBlock = 0

merger.ReachTTD()
merger.FinalizePoS()
// merger.ReachTTD()
// merger.FinalizePoS()

// Set the terminal total difficulty in the config
gspec.Config.TerminalTotalDifficulty = big.NewInt(0)
}
// // Set the terminal total difficulty in the config
// gspec.Config.TerminalTotalDifficulty = big.NewInt(0)
// }
genDb, blocks, _ := GenerateChainWithGenesis(gspec, engine, 2*state.TriesInMemory, func(i int, gen *BlockGen) {
tx, err := types.SignTx(types.NewTransaction(nonce, common.HexToAddress("deadbeef"), big.NewInt(100), 21000, big.NewInt(int64(i+1)*params.GWei), nil), signer, key)
if err != nil {
Expand Down
12 changes: 7 additions & 5 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ import (
// StateProcessor implements Processor.
type StateProcessor struct {
config *params.ChainConfig // Chain configuration options
chain *HeaderChain // Canonical header chain
bc *BlockChain // Canonical header chain
hc *HeaderChain
}

// NewStateProcessor initialises a new StateProcessor.
func NewStateProcessor(config *params.ChainConfig, chain *HeaderChain) *StateProcessor {
func NewStateProcessor(config *params.ChainConfig, bc *BlockChain, hc *HeaderChain) *StateProcessor {
return &StateProcessor{
config: config,
chain: chain,
bc: bc,
hc: hc,
}
}

Expand Down Expand Up @@ -75,7 +77,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
context vm.BlockContext
signer = types.MakeSigner(p.config, header.Number, header.Time)
)
context = NewEVMBlockContext(header, p.chain, nil)
context = NewEVMBlockContext(header, p.hc, nil)
vmenv := vm.NewEVM(context, vm.TxContext{}, statedb, p.config, cfg)
if beaconRoot := block.BeaconRoot(); beaconRoot != nil {
ProcessBeaconBlockRoot(*beaconRoot, vmenv, statedb)
Expand Down Expand Up @@ -115,7 +117,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
withdrawals = nil
}
// Finalize the block, applying any consensus engine specific extras (e.g. block rewards)
p.chain.engine.Finalize(p.chain, header, statedb, block.Body())
p.hc.engine.Finalize(p.bc, header, statedb, block.Body())

return receipts, allLogs, *usedGas, nil
}
Expand Down
4 changes: 2 additions & 2 deletions core/stateless.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ func ExecuteStateless(config *params.ChainConfig, witness *stateless.Witness) (c
return common.Hash{}, common.Hash{}, err
}
// Create a blockchain that is idle, but can be used to access headers through
chain := &HeaderChain{
headerChain := &HeaderChain{
config: config,
chainDb: memdb,
headerCache: lru.NewCache[common.Hash, *types.Header](256),
engine: beacon.New(ethash.NewFaker()),
}
processor := NewStateProcessor(config, chain)
processor := NewStateProcessor(config, nil, headerChain)
validator := NewBlockValidator(config, nil) // No chain, we only validate the state, not the block

// Run the stateless blocks processing and self-validate certain fields
Expand Down
4 changes: 0 additions & 4 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,6 @@ func (b *EthAPIBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumbe
}

if number == rpc.SafeBlockNumber {
if !b.eth.Merger().TDDReached() {
return nil, errors.New("'safe' tag not supported on pre-merge network")
}

header := b.eth.blockchain.CurrentSafeBlock()

return b.eth.blockchain.GetBlock(header.Hash(), header.Number.Uint64()), nil
Expand Down
3 changes: 1 addition & 2 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ type Ethereum struct {
handler *handler
ethDialCandidates enode.Iterator
snapDialCandidates enode.Iterator
merger *consensus.Merger

// DB interfaces
chainDb ethdb.Database // Block chain database
Expand Down Expand Up @@ -583,7 +582,6 @@ func (s *Ethereum) Synced() bool { return s.handler.synced
func (s *Ethereum) SetSynced() { s.handler.enableSyncedFeatures() }
func (s *Ethereum) ArchiveMode() bool { return s.config.NoPruning }
func (s *Ethereum) BloomIndexer() *core.ChainIndexer { return s.bloomIndexer }
func (s *Ethereum) Merger() *consensus.Merger { return s.merger }

// SetAuthorized sets the authorized bool variable
// denoting that consensus has been authorized while creation
Expand Down Expand Up @@ -842,6 +840,7 @@ func (s *Ethereum) Stop() error {
close(s.closeCh)

s.txPool.Close()
s.miner.Close()
s.blockchain.Stop()

// Clean shutdown marker as the last thing before closing db
Expand Down
Loading

0 comments on commit c0ff6db

Please sign in to comment.