Automatic peer dialing in bootstrap module after address resolution. #901
ankur12-1610
started this conversation in
General
Replies: 2 comments 1 reply
-
@sumanjeet0012 is it apt to have a separate issue for updating the code of bootstrap example for logging connected peers? |
Beta Was this translation helpful? Give feedback.
0 replies
-
@ankur12-1610 The primary purpose of logging connected peers in the bootstrap example is to determine the time taken for bootstrapping and to identify which bootstrap nodes are successfully connected. Since the PR has already been merged, there is no need to address this now. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Related PR: #849
This PR adds Automatic peer dialing in bootstrap module after address resolution.
What was wrong?
Issue #798
Currently, the Bootstrap module in py-libp2p only resolves the multiaddrs of bootstrap peers and adds them to the peerstore. This enhancement proposes that, after resolving the addresses, the module should also attempt to connect (dial) to these peers automatically. This aligns with the intended purpose of bootstrapping in decentralized P2P networks, where nodes should proactively establish connectivity with known peers upon startup.
How was it fixed?
trio nursery
concurrent address processingKey Benefits
trio.open_nursery
enables simultaneous connection attempts, leading to a significant reduction in bootstrap timetrio.move_on_after
function ensures that connection attempts are canceled if they exceed a set timeoutImplementation details
In order to test it properly first change
examples/bootstrap/bootstrap.py
:by replacing
to
this helps you log the connected peers.
Now the core of the PR lies in using
trio.open_nursery
when calling_process_bootstrap_addr
.In essence, nursery.start_soon() transforms what would be a slow, sequential bootstrap process into a fast, parallel, and safe concurrent operation with proper error handling and resource management. This has significantly made the bootstrap process faster.
The core function which handles connection logic -
py-libp2p/libp2p/discovery/bootstrap/bootstrap.py
Line 191 in a8a71b0
Connection timeout feature is implemented using
trio.move_on_after
-py-libp2p/libp2p/discovery/bootstrap/bootstrap.py
Line 219 in a8a71b0
Discussion Points
Future work could include adding a backoff logic to handle repeated connection failures, similar to the approach used in go-libp2p. This would further improve the resilience of the bootstrapping process.
Learning
Gaining a solid understanding of trio was a significant learning curve, and this wouldn't have been possible without the insightful reviews from @sumanjeet0012.
Please share your thoughts on the same and feel free to contribute.
Beta Was this translation helpful? Give feedback.
All reactions