Skip to content

Commit

Permalink
bugfix: Set the MaxStaleBroadcastDist based on Hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
gameofpointers committed Sep 29, 2023
1 parent 010594c commit e7f6f96
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions eth/fetcher/block_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ const (
)

const (
maxUncleDist = 100 // Maximum allowed backward distance from the chain head
maxQueueDist = 32 // Maximum allowed distance from the chain head to queue
hashLimit = 256 // Maximum number of unique blocks or headers a peer may have announced
blockLimit = 64 // Maximum number of unique blocks a peer may have delivered
MaxStaleBroadcastDist = 3500 // Drop peers who broadcast new blocks that are more than 3500 blocks stale
maxUncleDist = 100 // Maximum allowed backward distance from the chain head
maxQueueDist = 32 // Maximum allowed distance from the chain head to queue
hashLimit = 256 // Maximum number of unique blocks or headers a peer may have announced
blockLimit = 64 // Maximum number of unique blocks a peer may have delivered
PrimeMaxStaleBroadcastDist = 63 // Drop peers who broadcast new blocks that are more than 63 blocks stale in Prime
RegionMaxStaleBroadcastDist = 500 // Drop peers who broadcast new blocks that are more than 500 blocks stale in Region
ZoneMaxStaleBroadcastDist = 3500 // Drop peers who broadcast new blocks that are more than 3500 blocks stale in Zone
)

var (
Expand Down Expand Up @@ -698,7 +700,17 @@ func (f *BlockFetcher) ImportBlocks(peer string, block *types.Block, relay bool)
// If this is a newly mined block from a much lower height, drop the peer. Peers should not mine blocks until they are in sync with the network.
currentNum := f.chainHeight()
bcastNum := block.NumberU64()
if relay && currentNum > MaxStaleBroadcastDist && currentNum > bcastNum+MaxStaleBroadcastDist {
nodeCtx := common.NodeLocation.Context()
var maxStaleBroadcastDist uint64
switch nodeCtx {
case common.ZONE_CTX:
maxStaleBroadcastDist = ZoneMaxStaleBroadcastDist
case common.REGION_CTX:
maxStaleBroadcastDist = RegionMaxStaleBroadcastDist
case common.PRIME_CTX:
maxStaleBroadcastDist = PrimeMaxStaleBroadcastDist
}
if relay && currentNum > maxStaleBroadcastDist && currentNum > bcastNum+maxStaleBroadcastDist {
// The broadcast blocks is stale. Drop the peer.
log.Warn("Peer is mining while not synced, dropping peer", "Id", peer)
f.dropPeer(peer)
Expand Down

0 comments on commit e7f6f96

Please sign in to comment.