Workaround the gossipsub table race condition (#486)
This commit is contained in:
parent
b52dab9fd7
commit
18d69a5c41
|
@ -33,6 +33,18 @@ method subscribeTopic*(f: FloodSub,
|
||||||
topic: string,
|
topic: string,
|
||||||
subscribe: bool,
|
subscribe: bool,
|
||||||
peer: PubsubPeer) {.gcsafe.} =
|
peer: PubsubPeer) {.gcsafe.} =
|
||||||
|
logScope:
|
||||||
|
peer
|
||||||
|
topic
|
||||||
|
|
||||||
|
# this is a workaround for a race condition
|
||||||
|
# that can happen if we disconnect the peer very early
|
||||||
|
# in the future we might use this as a test case
|
||||||
|
# and eventually remove this workaround
|
||||||
|
if subscribe and peer.peerId notin f.peers:
|
||||||
|
trace "ignoring unknown peer"
|
||||||
|
return
|
||||||
|
|
||||||
procCall PubSub(f).subscribeTopic(topic, subscribe, peer)
|
procCall PubSub(f).subscribeTopic(topic, subscribe, peer)
|
||||||
|
|
||||||
if topic notin f.floodsub:
|
if topic notin f.floodsub:
|
||||||
|
|
|
@ -909,17 +909,25 @@ method subscribeTopic*(g: GossipSub,
|
||||||
topic: string,
|
topic: string,
|
||||||
subscribe: bool,
|
subscribe: bool,
|
||||||
peer: PubSubPeer) {.gcsafe.} =
|
peer: PubSubPeer) {.gcsafe.} =
|
||||||
# Skip floodsub - we don't want it to add the peer to `g.floodsub`
|
|
||||||
procCall PubSub(g).subscribeTopic(topic, subscribe, peer)
|
|
||||||
|
|
||||||
logScope:
|
logScope:
|
||||||
peer
|
peer
|
||||||
topic
|
topic
|
||||||
|
|
||||||
g.onNewPeer(peer)
|
# this is a workaround for a race condition
|
||||||
|
# that can happen if we disconnect the peer very early
|
||||||
|
# in the future we might use this as a test case
|
||||||
|
# and eventually remove this workaround
|
||||||
|
if subscribe and peer.peerId notin g.peers:
|
||||||
|
trace "ignoring unknown peer"
|
||||||
|
return
|
||||||
|
|
||||||
|
# Skip floodsub - we don't want it to add the peer to `g.floodsub`
|
||||||
|
procCall PubSub(g).subscribeTopic(topic, subscribe, peer)
|
||||||
|
|
||||||
if subscribe:
|
if subscribe:
|
||||||
trace "peer subscribed to topic"
|
trace "peer subscribed to topic"
|
||||||
|
# populate scoring structs and such
|
||||||
|
g.onNewPeer(peer)
|
||||||
# subscribe remote peer to the topic
|
# subscribe remote peer to the topic
|
||||||
discard g.gossipsub.addPeer(topic, peer)
|
discard g.gossipsub.addPeer(topic, peer)
|
||||||
if peer.peerId in g.parameters.directPeers:
|
if peer.peerId in g.parameters.directPeers:
|
||||||
|
|
Loading…
Reference in New Issue