fixed unnecessary peer disconnect

This commit is contained in:
Brannon King 2021-09-24 10:58:55 -04:00
parent 3910319e80
commit 52f41459d5

View file

@ -1330,24 +1330,26 @@ func (sp *serverPeer) OnNotFound(p *peer.Peer, msg *wire.MsgNotFound) {
case wire.InvTypeWitnessTx: case wire.InvTypeWitnessTx:
numTxns++ numTxns++
default: default:
peerLog.Debugf("Invalid inv type '%d' in notfound message from %s", peerLog.Infof("Invalid inv type '%d' in NotFound message from %s. Disconnecting...", inv.Type, sp)
inv.Type, sp)
sp.Disconnect() sp.Disconnect()
return return
} }
} }
if numBlocks > 0 { if numBlocks > 0 {
blockStr := pickNoun(uint64(numBlocks), "block", "blocks") blockStr := pickNoun(uint64(numBlocks), "block", "blocks")
reason := fmt.Sprintf("%d %v not found", numBlocks, blockStr) reason := fmt.Sprintf("%d %v not found on %s", numBlocks, blockStr, sp)
if sp.addBanScore(20*numBlocks, 0, reason) { if sp.addBanScore(20, 0, reason) {
return return // once they fail to return us five block requests they're gone for good
} }
} }
if numTxns > 0 { if numTxns > 0 {
// This is an expected situation if transactions in the mempool make it into a block before
// this node knows about said block. We don't want to ban them for that alone
peerLog.Debugf("%d transactions not found on %s", numTxns, sp)
txStr := pickNoun(uint64(numTxns), "transaction", "transactions") txStr := pickNoun(uint64(numTxns), "transaction", "transactions")
reason := fmt.Sprintf("%d %v not found", numBlocks, txStr) reason := fmt.Sprintf("%d %v not found on %s", numTxns, txStr, sp)
if sp.addBanScore(0, 10*numTxns, reason) { if sp.addBanScore(0, 25, reason) {
return return // if they fail us four times in one minute, they're gone -- hitting them at new-block should be rare
} }
} }