bee icon indicating copy to clipboard operation
bee copied to clipboard

Peer might be connected before pseudosettle protocol would be added, leading to accounting block

Open metacertain opened this issue 2 years ago • 0 comments

⚠️ Support requests in an issue-format will be closed immediately. For support, go to Swarm's Discord.

Context

Accounting operations are only possible with explicitly connected peers. To signal that a peer is connected or disconnected, accounting connected/disconnected methods set a state for a peer. These method calls are propagated from PseudoSettle Protocol when it performs ConnectIn/Out DisconnectIn/Out calls from libp2p.

The problem is, in the early phase of node bootup, there might be a time race in between connections being established, and the actual protocols being initialized. This might lead to a scenario where connections already exist before pseudosettle protocol is added, and the connectin/connectout calls from libp2p might have not happened for the peer, leaving the connected state false, and not being able to make or serve requests to the peer in other protocols.

Summary

In order to avoid connected peers who are not connected according to accounting, either we need to make sure that a protocol added after the connection is already established gets the connectIn/Out method called retroactively, or, making sure that the protocol calling the accounting connected methods is the first one to be added (hive?), without which establishing connection is not possible, or, making sure that connections are not started or accepted until all the protocols are added in node.go

Expected behavior

P2p connections always match the range of accountingPeers with connected true

Actual behavior

Under specific circumstances (kademlia triggering connection attempts before further protocols are added, not triggering protocol init functions later on when the actual protocols are added)

Steps to reproduce

Verification of issue is required

Possible solution

Retroactive connectin/connectout, or Calling accounting connected from hive, or prohibiting incoming outgoing connections until all protocols are added in node.go

metacertain avatar Aug 10 '22 13:08 metacertain