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
6 changes: 5 additions & 1 deletion eth/handler_eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ func (h *ethHandler) handleBlockBroadcast(peer *eth.Peer, packet *eth.NewBlockPa
log.Debug("handleBlockBroadcast", "peer", peer.ID(), "block", block.Number(), "hash", block.Hash())
h.blockFetcher.Enqueue(peer.ID(), block)
stats := h.chain.GetBlockStats(block.Hash())
blockFirstReceived := false
if stats.RecvNewBlockTime.Load() == 0 {
blockFirstReceived = true
stats.RecvNewBlockTime.Store(time.Now().UnixMilli())
addr := peer.RemoteAddr()
if addr != nil {
Expand All @@ -166,7 +168,9 @@ func (h *ethHandler) handleBlockBroadcast(peer *eth.Peer, packet *eth.NewBlockPa
// Update the peer's total difficulty if better than the previous
if _, td := peer.Head(); trueTD.Cmp(td) > 0 {
peer.SetHead(trueHead, trueTD)
h.chainSync.handlePeerEvent()
if blockFirstReceived {
h.chainSync.handlePeerEvent()
}
}
return nil
}
8 changes: 4 additions & 4 deletions eth/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ type chainSyncOp struct {
func newChainSyncer(handler *handler) *chainSyncer {
return &chainSyncer{
handler: handler,
peerEventCh: make(chan struct{}),
peerEventCh: make(chan struct{}, 10),
}
}

Expand Down Expand Up @@ -186,9 +186,9 @@ func (cs *chainSyncer) nextSyncOp() *chainSyncOp {
} else if op.td.Cmp(new(big.Int).Add(ourTD, common.Big2)) <= 0 { // common.Big2: difficulty of an in-turn block
// On BSC, blocks are produced much faster than on Ethereum.
// If the node is only slightly behind (e.g., 1 block), syncing is unnecessary.
// It's likely still processing broadcasted blocks or block hash announcements.
// In most cases, the node will catch up within 3 seconds.
time.Sleep(3 * time.Second)
// It's likely still processing broadcasted blocks(such as including a big tx) or block hash announcements.
// In most cases, the node will catch up within 2 seconds.
time.Sleep(2 * time.Second)

// Re-check local head to see if it has caught up
if _, latestTD := cs.modeAndLocalHead(); ourTD.Cmp(latestTD) < 0 {
Expand Down