Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion eth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
!(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)))
}

Expand Down
4 changes: 4 additions & 0 deletions eth/handler_eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion eth/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down