Skip to content

Commit e75554b

Browse files
committed
attempt 2 at fixing ban-on-tx-now-in-block
1 parent 4dd8db9 commit e75554b

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

server.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -389,11 +389,13 @@ func (sp *serverPeer) addBanScore(persistent, transient uint32, reason string) b
389389
}
390390
score := sp.banScore.Increase(persistent, transient)
391391
if score > warnThreshold {
392-
peerLog.Warnf("Misbehaving peer %s: %s -- ban score increased to %d",
393-
sp, reason, score)
392+
peerLog.Warnf("Misbehaving peer %s: %s -- ban score increased to %d", sp, reason, score)
394393
if score > cfg.BanThreshold {
395-
peerLog.Warnf("Misbehaving peer %s -- banning and disconnecting",
396-
sp)
394+
if sp.server.ConnectedCount() <= 1 {
395+
peerLog.Warnf("Refusing to ban peer %s as it is the only peer", sp)
396+
return false
397+
}
398+
peerLog.Warnf("Misbehaving peer %s -- banning and disconnecting", sp)
397399
sp.server.BanPeer(sp)
398400
sp.Disconnect()
399401
return true
@@ -1346,10 +1348,12 @@ func (sp *serverPeer) OnNotFound(p *peer.Peer, msg *wire.MsgNotFound) {
13461348
// This is an expected situation if transactions in the mempool make it into a block before
13471349
// this node knows about said block. We don't want to ban them for that alone
13481350
peerLog.Debugf("%d transactions not found on %s", numTxns, sp)
1349-
txStr := pickNoun(uint64(numTxns), "transaction", "transactions")
1350-
reason := fmt.Sprintf("%d %v not found on %s", numTxns, txStr, sp)
1351-
if sp.addBanScore(0, 25, reason) {
1352-
return // if they fail us four times in one minute, they're gone -- hitting them at new-block should be rare
1351+
if numBlocks+numTxns < wire.MaxInvPerMsg { // if our message is full then it is likely followed by another one that isn't
1352+
txStr := pickNoun(uint64(numTxns), "transaction", "transactions")
1353+
reason := fmt.Sprintf("%d %v not found on %s", numTxns, txStr, sp)
1354+
if sp.addBanScore(0, 20, reason) {
1355+
return // if they fail us five times in one minute, they're gone -- hitting them at new-block should be rare
1356+
}
13531357
}
13541358
}
13551359

0 commit comments

Comments
 (0)