all: core rework for the merge transition (#23761)
* all: work for eth1/2 transtition * consensus/beacon, eth: change beacon difficulty to 0 * eth: updates * all: add terminalBlockDifficulty config, fix rebasing issues * eth: implemented merge interop spec * internal/ethapi: update to v1.0.0.alpha.2 This commit updates the code to the new spec, moving payloadId into it's own object. It also fixes an issue with finalizing an empty blockhash. It also properly sets the basefee * all: sync polishes, other fixes + refactors * core, eth: correct semantics for LeavePoW, EnterPoS * core: fixed rebasing artifacts * core: light: performance improvements * core: use keyed field (f) * core: eth: fix compilation issues + tests * eth/catalyst: dbetter error codes * all: move Merger to consensus/, remove reliance on it in bc * all: renamed EnterPoS and LeavePoW to ReachTDD and FinalizePoS * core: make mergelogs a function * core: use InsertChain instead of InsertBlock * les: drop merger from lightchain object * consensus: add merger * core: recoverAncestors in catalyst mode * core: fix nitpick * all: removed merger from beacon, use TTD, nitpicks * consensus: eth: add docstring, removed unnecessary code duplication * consensus/beacon: better comment * all: easy to fix nitpicks by karalabe * consensus/beacon: verify known headers to be sure * core: comments * core: eth: don't drop peers who advertise blocks, nitpicks * core: never add beacon blocks to the future queue * core: fixed nitpicks * consensus/beacon: simplify IsTTDReached check * consensus/beacon: correct IsTTDReached check Co-authored-by: rjl493456442 <garyrong0905@gmail.com> Co-authored-by: Péter Szilágyi <peterke@gmail.com>
This commit is contained in:
committed by
GitHub
parent
519cf98b69
commit
3038e480f5
@ -63,6 +63,7 @@ type LightEthereum struct {
|
||||
serverPool *vfc.ServerPool
|
||||
serverPoolIterator enode.Iterator
|
||||
pruner *pruner
|
||||
merger *consensus.Merger
|
||||
|
||||
bloomRequests chan chan *bloombits.Retrieval // Channel receiving bloom data retrieval requests
|
||||
bloomIndexer *core.ChainIndexer // Bloom indexer operating during block imports
|
||||
@ -88,13 +89,14 @@ func New(stack *node.Node, config *ethconfig.Config) (*LightEthereum, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chainConfig, genesisHash, genesisErr := core.SetupGenesisBlockWithOverride(chainDb, config.Genesis, config.OverrideArrowGlacier)
|
||||
chainConfig, genesisHash, genesisErr := core.SetupGenesisBlockWithOverride(chainDb, config.Genesis, config.OverrideArrowGlacier, config.OverrideTerminalTotalDifficulty)
|
||||
if _, isCompat := genesisErr.(*params.ConfigCompatError); genesisErr != nil && !isCompat {
|
||||
return nil, genesisErr
|
||||
}
|
||||
log.Info("Initialised chain configuration", "config", chainConfig)
|
||||
|
||||
peers := newServerPeerSet()
|
||||
merger := consensus.NewMerger(chainDb)
|
||||
leth := &LightEthereum{
|
||||
lesCommons: lesCommons{
|
||||
genesis: genesisHash,
|
||||
@ -109,6 +111,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*LightEthereum, error) {
|
||||
eventMux: stack.EventMux(),
|
||||
reqDist: newRequestDistributor(peers, &mclock.System{}),
|
||||
accountManager: stack.AccountManager(),
|
||||
merger: merger,
|
||||
engine: ethconfig.CreateConsensusEngine(stack, chainConfig, &config.Ethash, nil, false, chainDb),
|
||||
bloomRequests: make(chan chan *bloombits.Retrieval),
|
||||
bloomIndexer: core.NewBloomIndexer(chainDb, params.BloomBitsBlocksClient, params.HelperTrieConfirmations),
|
||||
@ -332,6 +335,7 @@ func (s *LightEthereum) Engine() consensus.Engine { return s.engine }
|
||||
func (s *LightEthereum) LesVersion() int { return int(ClientProtocolVersions[0]) }
|
||||
func (s *LightEthereum) Downloader() *downloader.Downloader { return s.handler.downloader }
|
||||
func (s *LightEthereum) EventMux() *event.TypeMux { return s.eventMux }
|
||||
func (s *LightEthereum) Merger() *consensus.Merger { return s.merger }
|
||||
|
||||
// Protocols returns all the currently configured network protocols to start.
|
||||
func (s *LightEthereum) Protocols() []p2p.Protocol {
|
||||
|
@ -143,11 +143,13 @@ func (h *clientHandler) handle(p *serverPeer, noInitAnnounce bool) error {
|
||||
connectionTimer.Update(time.Duration(mclock.Now() - connectedAt))
|
||||
serverConnectionGauge.Update(int64(h.backend.peers.len()))
|
||||
}()
|
||||
// It's mainly used in testing which requires discarding initial
|
||||
// signal to prevent syncing.
|
||||
if !noInitAnnounce {
|
||||
|
||||
// Discard all the announces after the transition
|
||||
// Also discarding initial signal to prevent syncing during testing.
|
||||
if !(noInitAnnounce || h.backend.merger.TDDReached()) {
|
||||
h.fetcher.announce(p, &announceData{Hash: p.headInfo.Hash, Number: p.headInfo.Number, Td: p.headInfo.Td})
|
||||
}
|
||||
|
||||
// Mark the peer starts to be served.
|
||||
atomic.StoreUint32(&p.serving, 1)
|
||||
defer atomic.StoreUint32(&p.serving, 0)
|
||||
@ -212,7 +214,11 @@ func (h *clientHandler) handleMsg(p *serverPeer) error {
|
||||
|
||||
// Update peer head information first and then notify the announcement
|
||||
p.updateHead(req.Hash, req.Number, req.Td)
|
||||
h.fetcher.announce(p, &req)
|
||||
|
||||
// Discard all the announces after the transition
|
||||
if !h.backend.merger.TDDReached() {
|
||||
h.fetcher.announce(p, &req)
|
||||
}
|
||||
}
|
||||
case msg.Code == BlockHeadersMsg:
|
||||
p.Log().Trace("Received block header response message")
|
||||
|
@ -71,8 +71,8 @@ type fetcherPeer struct {
|
||||
// These following two fields can track the latest announces
|
||||
// from the peer with limited size for caching. We hold the
|
||||
// assumption that all enqueued announces are td-monotonic.
|
||||
announces map[common.Hash]*announce // Announcement map
|
||||
announcesList []common.Hash // FIFO announces list
|
||||
announces map[common.Hash]*announce // Announcement map
|
||||
fifo []common.Hash // FIFO announces list
|
||||
}
|
||||
|
||||
// addAnno enqueues an new trusted announcement. If the queued announces overflow,
|
||||
@ -87,15 +87,15 @@ func (fp *fetcherPeer) addAnno(anno *announce) {
|
||||
return
|
||||
}
|
||||
fp.announces[hash] = anno
|
||||
fp.announcesList = append(fp.announcesList, hash)
|
||||
fp.fifo = append(fp.fifo, hash)
|
||||
|
||||
// Evict oldest if the announces are oversized.
|
||||
if len(fp.announcesList)-cachedAnnosThreshold > 0 {
|
||||
for i := 0; i < len(fp.announcesList)-cachedAnnosThreshold; i++ {
|
||||
delete(fp.announces, fp.announcesList[i])
|
||||
if len(fp.fifo)-cachedAnnosThreshold > 0 {
|
||||
for i := 0; i < len(fp.fifo)-cachedAnnosThreshold; i++ {
|
||||
delete(fp.announces, fp.fifo[i])
|
||||
}
|
||||
copy(fp.announcesList, fp.announcesList[len(fp.announcesList)-cachedAnnosThreshold:])
|
||||
fp.announcesList = fp.announcesList[:cachedAnnosThreshold]
|
||||
copy(fp.fifo, fp.fifo[len(fp.fifo)-cachedAnnosThreshold:])
|
||||
fp.fifo = fp.fifo[:cachedAnnosThreshold]
|
||||
}
|
||||
}
|
||||
|
||||
@ -106,8 +106,8 @@ func (fp *fetcherPeer) forwardAnno(td *big.Int) []*announce {
|
||||
cutset int
|
||||
evicted []*announce
|
||||
)
|
||||
for ; cutset < len(fp.announcesList); cutset++ {
|
||||
anno := fp.announces[fp.announcesList[cutset]]
|
||||
for ; cutset < len(fp.fifo); cutset++ {
|
||||
anno := fp.announces[fp.fifo[cutset]]
|
||||
if anno == nil {
|
||||
continue // In theory it should never ever happen
|
||||
}
|
||||
@ -118,8 +118,8 @@ func (fp *fetcherPeer) forwardAnno(td *big.Int) []*announce {
|
||||
delete(fp.announces, anno.data.Hash)
|
||||
}
|
||||
if cutset > 0 {
|
||||
copy(fp.announcesList, fp.announcesList[cutset:])
|
||||
fp.announcesList = fp.announcesList[:len(fp.announcesList)-cutset]
|
||||
copy(fp.fifo, fp.fifo[cutset:])
|
||||
fp.fifo = fp.fifo[:len(fp.fifo)-cutset]
|
||||
}
|
||||
return evicted
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/mclock"
|
||||
"github.com/ethereum/go-ethereum/consensus"
|
||||
"github.com/ethereum/go-ethereum/consensus/ethash"
|
||||
"github.com/ethereum/go-ethereum/contracts/checkpointoracle/contract"
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
@ -239,6 +240,7 @@ func newTestClientHandler(backend *backends.SimulatedBackend, odr *LesOdr, index
|
||||
engine: engine,
|
||||
blockchain: chain,
|
||||
eventMux: evmux,
|
||||
merger: consensus.NewMerger(rawdb.NewMemoryDatabase()),
|
||||
}
|
||||
client.handler = newClientHandler(ulcServers, ulcFraction, nil, client)
|
||||
|
||||
|
Reference in New Issue
Block a user