From a04bcc47f15bc8da53de3beb82e3bad4995a7f97 Mon Sep 17 00:00:00 2001 From: allformless <213398294+allformless@users.noreply.github.com> Date: Mon, 24 Nov 2025 16:24:35 +0800 Subject: [PATCH 1/3] eth: fix stuck when starting up a new network --- eth/handler.go | 3 ++- eth/handler_eth.go | 4 ++++ eth/sync.go | 6 +++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/eth/handler.go b/eth/handler.go index 6f2bb7cdde..ffcc6e7f6f 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -833,7 +833,8 @@ func (h *handler) BroadcastBlock(block *types.Block, propagate bool) { // Step 1: Select target peers for initial broadcast. limit := totalPeers - if !h.directBroadcast { + if !h.directBroadcast && + block.NumberU64() != 1 { // Populate TD from every receiver on startup to establish proper sync. limit = int(math.Sqrt(float64(totalPeers))) } diff --git a/eth/handler_eth.go b/eth/handler_eth.go index 0099fb0873..d96b3b849c 100644 --- a/eth/handler_eth.go +++ b/eth/handler_eth.go @@ -165,6 +165,10 @@ func (h *ethHandler) handleBlockBroadcast(peer *eth.Peer, packet *eth.NewBlockPa trueHead = block.ParentHash() trueTD = new(big.Int).Sub(td, block.Difficulty()) ) + if block.NumberU64() == 1 { // this enable sync with the right peer when starting up a new network + trueHead = block.Hash() + trueTD = td + } // Update the peer's total difficulty if better than the previous if _, td := peer.Head(); trueTD.Cmp(td) > 0 { peer.SetHead(trueHead, trueTD) diff --git a/eth/sync.go b/eth/sync.go index 9c608f374c..cf66a324d4 100644 --- a/eth/sync.go +++ b/eth/sync.go @@ -260,7 +260,11 @@ func (h *handler) doSync(op *chainSyncOp) error { // degenerate connectivity, but it should be healthy for the mainnet too to // more reliably update peers or the local TD state. if block := h.chain.GetBlock(head.Hash(), head.Number.Uint64()); block != nil { - h.BroadcastBlock(block, false) + if head.Number.Uint64() == 1 { // Update TD from all receivers during network initialization. + h.BroadcastBlock(block, true) + } else { + h.BroadcastBlock(block, false) + } } } return nil From d8291098560a4c4815dc962c31a962af70dbbda9 Mon Sep 17 00:00:00 2001 From: allformless <213398294+allformless@users.noreply.github.com> Date: Tue, 25 Nov 2025 19:01:47 +0800 Subject: [PATCH 2/3] eth: fix UT --- eth/handler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eth/handler.go b/eth/handler.go index ffcc6e7f6f..7156592223 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -834,7 +834,7 @@ func (h *handler) BroadcastBlock(block *types.Block, propagate bool) { // Step 1: Select target peers for initial broadcast. limit := totalPeers if !h.directBroadcast && - block.NumberU64() != 1 { // Populate TD from every receiver on startup to establish proper sync. + (h.networkID == 1 || block.NumberU64() != 1) { // Populate TD from every receiver on startup to establish proper sync. limit = int(math.Sqrt(float64(totalPeers))) } From 20b631338bb3efafb8e5de1108e2cb894479791d Mon Sep 17 00:00:00 2001 From: allformless <213398294+allformless@users.noreply.github.com> Date: Tue, 25 Nov 2025 19:50:26 +0800 Subject: [PATCH 3/3] eth: improve fixing UT --- eth/handler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eth/handler.go b/eth/handler.go index 7156592223..bb63d64bfa 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -834,7 +834,7 @@ func (h *handler) BroadcastBlock(block *types.Block, propagate bool) { // Step 1: Select target peers for initial broadcast. limit := totalPeers if !h.directBroadcast && - (h.networkID == 1 || block.NumberU64() != 1) { // Populate TD from every receiver on startup to establish proper sync. + !(h.networkID == 714 /*RialtoChainConfig.ChainID*/ && block.NumberU64() == 1) { // Populate TD from every receiver on startup to establish proper sync. limit = int(math.Sqrt(float64(totalPeers))) }