diff --git a/netsync/manager.go b/netsync/manager.go index 977f8cfb4..55481a888 100644 --- a/netsync/manager.go +++ b/netsync/manager.go @@ -532,6 +532,25 @@ func (sm *SyncManager) handleBlockMsg(bmsg *blockMsg) { } if isOrphan { + blueScore, err := bmsg.block.BlueScore() + if err != nil { + log.Errorf("Received an orphan block %s with malformed blue score from %s. Disconnecting...", + blockHash, peer) + peer.AddBanScoreAndPushRejectMsg(wire.CmdBlock, wire.RejectInvalid, blockHash, + peerpkg.BanScoreMalformedBlueScoreInOrphan, 0, + fmt.Sprintf("Received an orphan block %s with malformed blue score", blockHash)) + return + } + + const maxOrphanBlueScoreDiff = 10000 + selectedTipBlueScore := sm.dag.SelectedTipBlueScore() + if blueScore > selectedTipBlueScore+maxOrphanBlueScoreDiff { + log.Infof("Orphan block %s has blue score %d and the selected tip blue score is "+ + "%d. Ignoring orphans with a blue score difference from the selected tip greater than %d", + blockHash, blueScore, selectedTipBlueScore, maxOrphanBlueScoreDiff) + return + } + // Request the parents for the orphan block from the peer that sent it. missingAncestors, err := sm.dag.GetOrphanMissingAncestorHashes(blockHash) if err != nil { diff --git a/peer/banscores.go b/peer/banscores.go index d5a7dc1d8..f4529c19a 100644 --- a/peer/banscores.go +++ b/peer/banscores.go @@ -2,9 +2,10 @@ package peer // Ban scores for misbehaving nodes const ( - BanScoreUnrequestedBlock = 100 - BanScoreInvalidBlock = 100 - BanScoreInvalidInvBlock = 100 + BanScoreUnrequestedBlock = 100 + BanScoreInvalidBlock = 100 + BanScoreInvalidInvBlock = 100 + BanScoreMalformedBlueScoreInOrphan = 100 BanScoreUnrequestedSelectedTip = 20 BanScoreUnrequestedTx = 20