[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
This commit is contained in:
Ori Newman 2020-06-15 16:08:25 +03:00 committed by GitHub
parent d4c9fdf6ac
commit 0744e8ebc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 3 deletions

View File

@ -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 {

View File

@ -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