Fix gossipsub incoming graft backoff (#616)

* Fix gossipsub incoming graft backoff

* Improve debug messages

* clamp to 24h
This commit is contained in:
Tanguy Cizain 2021-09-01 08:41:11 +02:00 committed by GitHub
parent cb94baf9c4
commit 8ea90037e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 7 deletions

View File

@ -89,7 +89,7 @@ proc handleGraft*(g: GossipSub,
# It is an error to GRAFT on a explicit peer # It is an error to GRAFT on a explicit peer
if peer.peerId in g.parameters.directPeers: if peer.peerId in g.parameters.directPeers:
# receiving a graft from a direct peer should yield a more prominent warning (protocol violation) # receiving a graft from a direct peer should yield a more prominent warning (protocol violation)
warn "attempt to graft an explicit peer, peering agreements should be reciprocal", warn "an explicit peer attempted to graft us, peering agreements should be reciprocal",
peer, topic peer, topic
# and such an attempt should be logged and rejected with a PRUNE # and such an attempt should be logged and rejected with a PRUNE
prunes.add(ControlPrune( prunes.add(ControlPrune(
@ -105,10 +105,14 @@ proc handleGraft*(g: GossipSub,
continue continue
# Check backingOff
# Ignore BackoffSlackTime here, since this only for outbound activity
# and subtract a second time to avoid race conditions
# (peers may wait to graft us as the exact instant they're allowed to)
if g.backingOff if g.backingOff
.getOrDefault(topic) .getOrDefault(topic)
.getOrDefault(peer.peerId) > Moment.now(): .getOrDefault(peer.peerId) - (BackoffSlackTime * 2).seconds > Moment.now():
debug "attempt to graft a backingOff peer", peer, topic debug "a backingOff peer attempted to graft us", peer, topic
# and such an attempt should be logged and rejected with a PRUNE # and such an attempt should be logged and rejected with a PRUNE
prunes.add(ControlPrune( prunes.add(ControlPrune(
topicID: topic, topicID: topic,
@ -162,13 +166,11 @@ proc handlePrune*(g: GossipSub, peer: PubSubPeer, prunes: seq[ControlPrune]) {.r
# add peer backoff # add peer backoff
if prune.backoff > 0: if prune.backoff > 0:
let let
# avoid overflows and follow params # avoid overflows and clamp to reasonable value
# worst case if the remote thinks we are wrong we get penalized
# but we won't end up with ghost peers
backoffSeconds = clamp( backoffSeconds = clamp(
prune.backoff + BackoffSlackTime, prune.backoff + BackoffSlackTime,
0'u64, 0'u64,
g.parameters.pruneBackoff.seconds.uint64 + BackoffSlackTime 1.days.seconds.uint64
) )
backoff = Moment.fromNow(backoffSeconds.int64.seconds) backoff = Moment.fromNow(backoffSeconds.int64.seconds)
current = g.backingOff.getOrDefault(topic).getOrDefault(peer.peerId) current = g.backingOff.getOrDefault(topic).getOrDefault(peer.peerId)