[lbry] server: don't ban peers on tx-not-in-block behavior
This commit is contained in:
parent
57bca30a00
commit
dfc7a4423c
1 changed files with 19 additions and 13 deletions
32
server.go
32
server.go
|
@ -387,11 +387,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
|
||||||
|
@ -1328,24 +1330,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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue