[lbry] don't ban peers on tx-not-in-block behavior

This commit is contained in:
Brannon King 2021-10-14 17:43:23 -04:00 committed by Roy Lee
parent 939eeca0cf
commit d9dc3463d0

View file

@ -389,11 +389,13 @@ func (sp *serverPeer) addBanScore(persistent, transient uint32, reason string) b
} }
score := sp.banScore.Increase(persistent, transient) score := sp.banScore.Increase(persistent, transient)
if score > warnThreshold { if score > warnThreshold {
peerLog.Warnf("Misbehaving peer %s: %s -- ban score increased to %d", peerLog.Warnf("Misbehaving peer %s: %s -- ban score increased to %d", sp, reason, score)
sp, reason, score)
if score > cfg.BanThreshold { if score > cfg.BanThreshold {
peerLog.Warnf("Misbehaving peer %s -- banning and disconnecting", if sp.server.ConnectedCount() <= 1 {
sp) peerLog.Warnf("Refusing to ban peer %s as it is the only peer", sp)
return false
}
peerLog.Warnf("Misbehaving peer %s -- banning and disconnecting", sp)
sp.server.BanPeer(sp) sp.server.BanPeer(sp)
sp.Disconnect() sp.Disconnect()
return true return true
@ -1330,24 +1332,28 @@ 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 {
txStr := pickNoun(uint64(numTxns), "transaction", "transactions") // This is an expected situation if transactions in the mempool make it into a block before
reason := fmt.Sprintf("%d %v not found", numBlocks, txStr) // this node knows about said block. We don't want to ban them for that alone
if sp.addBanScore(0, 10*numTxns, reason) { peerLog.Debugf("%d transactions not found on %s", numTxns, sp)
return if numBlocks+numTxns < wire.MaxInvPerMsg { // if our message is full then it is likely followed by another one that isn't
txStr := pickNoun(uint64(numTxns), "transaction", "transactions")
reason := fmt.Sprintf("%d %v not found on %s", numTxns, txStr, sp)
if sp.addBanScore(0, 20, reason) {
return // if they fail us five times in one minute, they're gone -- hitting them at new-block should be rare
}
} }
} }
@ -2727,6 +2733,7 @@ func newServer(listenAddrs, agentBlacklist, agentWhitelist []string,
claimTrieCfg := claimtrieconfig.DefaultConfig claimTrieCfg := claimtrieconfig.DefaultConfig
claimTrieCfg.DataDir = cfg.DataDir claimTrieCfg.DataDir = cfg.DataDir
claimTrieCfg.Interrupt = interrupt
var ct *claimtrie.ClaimTrie var ct *claimtrie.ClaimTrie