From 0744e8ebc0367d5e8c35c02880ada3a0515117b4 Mon Sep 17 00:00:00 2001 From: Ori Newman Date: Mon, 15 Jun 2020 16:08:25 +0300 Subject: [PATCH] [NOD-1042] Ignore very high orphans (#761) * [NOD-530] Remove coinbase inputs and add blue score to payload * [NOD-1042] Ignore very high orphans * [NOD-1042] Add ban score to an orphan with malformed blue score * [NOD-1042] Fix log --- netsync/manager.go | 19 +++++++++++++++++++ peer/banscores.go | 7 ++++--- 2 files changed, 23 insertions(+), 3 deletions(-) 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