[lbry] server: don't ban peers on tx-not-in-block behavior
This commit is contained in:
parent
93481d7f3a
commit
44dd82a9f5
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)
|
||||
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
|
||||
|
@ -1328,24 +1330,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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue