eth: fix tx looper startup and shutdown

This commit is contained in:
Péter Szilágyi 2024-03-05 11:11:24 +02:00
parent b443c3c215
commit c04c1c44fb

View file

@ -182,20 +182,7 @@ func newHandler(config *handlerConfig) (*handler, error) {
}
// Construct the downloader (long sync)
h.downloader = downloader.New(config.Database, h.eventMux, h.chain, nil, h.removePeer, h.enableSyncedFeatures)
if ttd := h.chain.Config().TerminalTotalDifficulty; ttd != nil {
if h.chain.Config().TerminalTotalDifficultyPassed {
log.Info("Chain post-merge, sync via beacon client")
} else {
head := h.chain.CurrentBlock()
if td := h.chain.GetTd(head.Hash(), head.Number.Uint64()); td.Cmp(ttd) >= 0 {
log.Info("Chain post-TTD, sync via beacon client")
} else {
log.Warn("Chain pre-merge, sync via PoW (ensure beacon client is ready)")
}
}
} else if h.chain.Config().TerminalTotalDifficultyPassed {
log.Error("Chain configured post-merge, but without TTD. Are you debugging sync?")
}
fetchTx := func(peer string, hashes []common.Hash) error {
p := h.peers.peer(peer)
if p == nil {
@ -442,6 +429,9 @@ func (h *handler) Start(maxPeers int) {
h.txsSub = h.txpool.SubscribeTransactions(h.txsCh, false)
go h.txBroadcastLoop()
// start sync handlers
h.txFetcher.Start()
// start peer handler tracker
h.wg.Add(1)
go h.protoTracker()
@ -449,6 +439,8 @@ func (h *handler) Start(maxPeers int) {
func (h *handler) Stop() {
h.txsSub.Unsubscribe() // quits txBroadcastLoop
h.txFetcher.Stop()
h.downloader.Terminate()
// Quit chainSync and txsync64.
// After this is done, no new peers will be accepted.