-
Notifications
You must be signed in to change notification settings - Fork 375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: clean up p2p
& implement missing peering functionality
#2852
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2852 +/- ##
==========================================
- Coverage 63.79% 63.69% -0.11%
==========================================
Files 549 578 +29
Lines 78819 80176 +1357
==========================================
+ Hits 50281 51065 +784
- Misses 25146 25724 +578
+ Partials 3392 3387 -5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
seed
peers) supportp2p
& implement bootnode (seed
peers) support
@@ -36,10 +26,10 @@ type P2PConfig struct { | |||
UPNP bool `json:"upnp" toml:"upnp" comment:"UPNP port forwarding"` | |||
|
|||
// Maximum number of inbound peers | |||
MaxNumInboundPeers int `json:"max_num_inbound_peers" toml:"max_num_inbound_peers" comment:"Maximum number of inbound peers"` | |||
MaxNumInboundPeers uint64 `json:"max_num_inbound_peers" toml:"max_num_inbound_peers" comment:"Maximum number of inbound peers"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsigned may be better than signed if we don't need to use patterns like -1
. However, since we're constrained by the OS limits, a size of 64 may be excessive.
p2p
& implement bootnode (seed
peers) supportp2p
& implement missing peering functionality
There is a leftover issue with this PR that I'm currently investigating, which is a hanging test somewhere in TM2. I will resolve this before opening the PR for reviews 🙏 |
Description
Closes #2308
There is a lot happening in this PR, so don't be discouraged by the files changed.
I'll outline the way the PR should be reviewed, and give you pointers along the way.
What this PR set out to do
This PR initially set out to implement peer discovery in the TM2
p2p
module -- that's it, basically.The change was meant to be minimal, and not involve larger changes.
After spending more time than I'd like to admit in the
p2p
codebase, I've come to a couple of realizations:p2p
package are sketchy to say the least, and not convincing at all that we were covering actual functionality we needed to cover.All of these are temporarily fine, and not blocking us.
But the pattern was there -- to add peer discovery, it would require continuing the same pattern of code gymnastics present in the
p2p
module for the last 5+ years.I took this opportunity, ahead of the mainnet launch, to fill out a few checkboxes:
PHILOSOPHY.md
.test4
andtest5
.I wanted to implement all of this, without breaking any existing TM2 functionality that relies on the
p2p
module, or introducing additional complexities.What this PR actually accomplished
I'm proud to say that this PR brings more than a few bells and whistles to the table, in terms of TM2 improvements:
Switch
andTransport
implementations. No more gazillion redundant checks, or expensive lookups, or convoluted APIs.For the sake of not making groundbreaking changes ahead of mainnet, I didn't touch a few things, and this will be evident from the code:
conn
package, or how the multiplex connections are established and maintained (or the STS implementation) -- this would be too much, and require an exponential amount of time to get right.Peer
abstraction is still the same, and TM2 modules interact with the peers in the same way as before (directly, asReactor
s). I've outlined the issues with this in the README, so check it out.In retrospect, I should've limited the scope of this PR by a lot. At the time I was at the mid-way point, I committed fully to leaving this module in a better state than I found it in, rather than leave additional tech debt for future cleanup.
The other primary goal of this PR is to scope out changes needed to upgrade the networking layer implementation into utilizing a stack like libp2p. I am happy to say that we have 0 limitations in terms of p2p functionality to make the switch. We're just bound by time. This upgrade is scheduled for after the mainnet MVP launch 🤞
How do I review this PR?
There is no point in looking at the older implementation, and trying to figure out the changes from there.
There are just too many, and it can get overwhelming quickly.
Instead, as the first step -- read the new
p2p
README. It outlines how thep2p
module works on a core level, and highlights current challenges.After the README, open the
p2p
package intm2/pkg/p2p
, and start looking at the implementation from there. Leave comments on things that are unclear, or can be improved. I'll try to answer and give as much context as I can.Contributors' checklist...
BREAKING CHANGE: xxx
message was included in the description