[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)
if score > warnThreshold {
peerLog.Warnf("Misbehaving peer %s: %s -- ban score increased to %d",
sp, reason, score)
peerLog.Warnf("Misbehaving peer %s: %s -- ban score increased to %d", sp, reason, score)
if score > cfg.BanThreshold {
peerLog.Warnf("Misbehaving peer %s -- banning and disconnecting",
sp)
if sp.server.ConnectedCount() <= 1 {
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.Disconnect()
return true
@ -1330,24 +1332,28 @@ func (sp *serverPeer) OnNotFound(p *peer.Peer, msg *wire.MsgNotFound) {
case wire.InvTypeWitnessTx:
numTxns++
default:
peerLog.Debugf("Invalid inv type '%d' in notfound message from %s",
inv.Type, sp)
peerLog.Infof("Invalid inv type '%d' in NotFound message from %s. Disconnecting...", inv.Type, sp)
sp.Disconnect()
return
}
}
if numBlocks > 0 {
blockStr := pickNoun(uint64(numBlocks), "block", "blocks")
reason := fmt.Sprintf("%d %v not found", numBlocks, blockStr)
if sp.addBanScore(20*numBlocks, 0, reason) {
return
reason := fmt.Sprintf("%d %v not found on %s", numBlocks, blockStr, sp)
if sp.addBanScore(20, 0, reason) {
return // once they fail to return us five block requests they're gone for good
}
}
if numTxns > 0 {
txStr := pickNoun(uint64(numTxns), "transaction", "transactions")
reason := fmt.Sprintf("%d %v not found", numBlocks, txStr)
if sp.addBanScore(0, 10*numTxns, reason) {
return
// 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)
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.DataDir = cfg.DataDir
claimTrieCfg.Interrupt = interrupt
var ct *claimtrie.ClaimTrie