Skip to content

Commit

Permalink
attempt 2 at fixing ban-on-tx-now-in-block
Browse files Browse the repository at this point in the history
  • Loading branch information
BrannonKing committed Oct 14, 2021
1 parent 4dd8db9 commit e75554b
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1346,10 +1348,12 @@ func (sp *serverPeer) OnNotFound(p *peer.Peer, msg *wire.MsgNotFound) {
// 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")
reason := fmt.Sprintf("%d %v not found on %s", numTxns, txStr, sp)
if sp.addBanScore(0, 25, reason) {
return // if they fail us four times in one minute, they're gone -- hitting them at new-block should be rare
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
}
}
}

Expand Down

0 comments on commit e75554b

Please sign in to comment.