[P2P] Integrate background router#732
Merged
bryanchriswhite merged 70 commits intomainfrom Jul 11, 2023
Merged
Conversation
7f58195 to
ab81389
Compare
20 tasks
ab81389 to
b01996d
Compare
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## refactor/unicast-router #732 +/- ##
===========================================================
+ Coverage 31.78% 32.23% +0.45%
===========================================================
Files 106 87 -19
Lines 8996 6099 -2897
===========================================================
- Hits 2859 1966 -893
+ Misses 5795 3861 -1934
+ Partials 342 272 -70
☔ View full report in Codecov by Sentry. |
b01996d to
a8206ec
Compare
This was referenced Jun 8, 2023
a8206ec to
744cb2b
Compare
30e94a6 to
fe24824
Compare
744cb2b to
d564ade
Compare
20 tasks
86d739c to
53e81e5
Compare
ca0b962 to
f80e6e9
Compare
This comment was marked as off-topic.
This comment was marked as off-topic.
20 tasks
Olshansk
reviewed
Jul 5, 2023
p2p/README.md
Outdated
|
|
||
| | Sender | Receiver | Router | Example Usage | | ||
| |----------------|----------------|-----------------|------------------------------------------------------| | ||
| | Staked Actor | Staked Actor | Raintree only | Consensus (state sync) messages (to validators only) | |
Collaborator
There was a problem hiding this comment.
As noted in the P2P knowledge transfer (#438) ticket, for hotstuff consensus, we don't use RainTree for messages propagation between staked actors (e.g. state sync) but for consensus, it's a star pattern (i.e. direct)
bryanchriswhite
commented
Jul 6, 2023
Olshansk
requested changes
Jul 6, 2023
p2p/README.md
Outdated
|
|
||
| | Sender | Receiver | Router | Example Usage | | ||
| |----------------|----------------|-----------------|------------------------------------------------------| | ||
| | Staked Actor | Staked Actor | Raintree only | Consensus (state sync) messages (to validators only) | |
Collaborator
There was a problem hiding this comment.
How about this:
Sender | Receiver | Router | Example Usage |
|----------------|----------------|-----------------|------------------------------------------------------|
| Staked Actor | Staked Actor | No router | Consensus (hotstuff) messages (to validators only) |
| Staked Actor | Staked Actor | Raintree only | Consensus (state sync) messages (to validators only) |
| Unstaked Actor | Staked Actor | Background only | Consensus (state sync) messages (to validators only) |
| Unstaked Actor | Unstaked Actor | Background only | Consensus (state sync) & Debug (CLI) messages |
d2dc98a to
b76efdf
Compare
* pokt/main: [Utility] Update E2E feature path template doc (#870) [IBC] Add nil check on proof for membership and non-membership proof creation (#877) Added git diff state to devlog10 Devlog 10 (#872) [Documentation] Add IBC Module introduction as an example (#853) [Persistence][Bug] Fix Actor Schema Assignment for ValidatorActor in GetActor (#857) QOL: add bash completion for p1 to localnet client (#865)
11 tasks
Olshansk
approved these changes
Jul 11, 2023
| { | ||
| name: "empty PocketEnvelope", | ||
| msgBz: mustMarshal(t, &typesP2P.BackgroundMessage{ | ||
| // NB: `Data` is normally a serialized `PocketEnvelope`. |
Collaborator
There was a problem hiding this comment.
Appreciate the comments 🙌
| t, receiverPeer, | ||
| receiverHost, | ||
| func(data []byte) error { | ||
| receivedChan <- data |
bryanchriswhite
commented
Jul 11, 2023
bryanchriswhite
added a commit
that referenced
this pull request
Jul 11, 2023
* pokt/main: [P2P] Integrate background router (#732) Update main README.md [Bug] Fix CI linter errors (#885) [Tooling] Block `IN_THIS_*` comments from passing CI (#889) [Utility] Update E2E feature path template doc (#870) [IBC] Add nil check on proof for membership and non-membership proof creation (#877) Added git diff state to devlog10 Devlog 10 (#872)
bryanchriswhite
added a commit
that referenced
this pull request
Jul 12, 2023
## Description Because `0` is the zero (default) value for `uint64`, if it is valid to be used as a nonce, it becomes difficult to distinguish the scenario where sender did not set a nonce from one where they explicitly set it to `0`. I'm not confident whether the ability to make this distinction matters now or has the potential to later but was following a feeling. <!-- reviewpad:summarize:start --> ### Summary generated by Reviewpad on 11 Jul 23 11:56 UTC This pull request includes the following changes: - In the `p2p/module.go` file, the `handlePocketEnvelope` function now checks if `poktEnvelope.Nonce` is zero and returns an error if it is. The error message includes the hex-encoded nonce value. - In the `p2p/module_test.go` file, new test cases have been added to test the handling of an invalid nonce. - In the `p2p/types/errors.go` file, a new error variable `ErrInvalidNonce` has been added to represent an invalid nonce value. - In the `shared/crypto/rand.go` file, a check has been added to ensure that the generated nonce value is not zero. If it is zero, the function recursively calls itself to generate a new nonce. <!-- reviewpad:summarize:end --> ## Issue N/A; observation made while working on #732. ## Type of change Please mark the relevant option(s): - [ ] New feature, functionality or library - [x] Bug fix - [ ] Code health or cleanup - [ ] Major breaking change - [ ] Documentation - [ ] Other <!-- add details here if it a different type of change --> ## List of changes - Adds `ErrInvalidNonce` P2P error type - Ensures the P2P message handler rejects the zero value `Nonce` (`uint64(0)`) is invalid - Ensures the `GetNonce` function never returns the zero value ## Testing - [ ] `make develop_test`; if any code changes were made - [ ] `make test_e2e` on [k8s LocalNet](https://github.com/pokt-network/pocket/blob/main/build/localnet/README.md); if any code changes were made - [ ] `e2e-devnet-test` passes tests on [DevNet](https://pocketnetwork.notion.site/How-to-DevNet-ff1598f27efe44c09f34e2aa0051f0dd); if any code was changed - [ ] [Docker Compose LocalNet](https://github.com/pokt-network/pocket/blob/main/docs/development/README.md); if any major functionality was changed or introduced - [ ] [k8s LocalNet](https://github.com/pokt-network/pocket/blob/main/build/localnet/README.md); if any infrastructure or configuration changes were made ## Required Checklist - [ ] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have added, or updated, [`godoc` format comments](https://go.dev/blog/godoc) on touched members (see: [tip.golang.org/doc/comment](https://tip.golang.org/doc/comment)) - [ ] I have tested my changes using the available tooling - [ ] I have updated the corresponding CHANGELOG ### If Applicable Checklist - [ ] I have updated the corresponding README(s); local and/or global - [x] I have added tests that prove my fix is effective or that my feature works - [ ] I have added, or updated, [mermaid.js](https://mermaid-js.github.io) diagrams in the corresponding README(s) - [ ] I have added, or updated, documentation and [mermaid.js](https://mermaid-js.github.io) diagrams in `shared/docs/*` if I updated `shared/*`README(s)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@Reviewer
This PR may be more digestible / reviewable on a commit-by-commit basis. Commits are organized logically and any given line is only modified in a single commit, with few exceptions*.
*(In the interest of preserving the git-time-continuum 👮🚨, this applies in batches of commits between comments or reviews by humans, only once "in review")
Description
Before
While
backgroundRouterexists and implements theRouterinterface, it had yet to be connected to anything. Additionally, it was not able to handle incoming unicast messages.classDiagram class p2pModule { -router Router -handlePocketEnvelope([]byte) error } class P2PModule { <<interface>> GetAddress() (Address, error) HandleEvent(*anypb.Any) error Send([]byte, Address) error Broadcast([]byte) error } p2pModule --|> P2PModule class RainTreeRouter { UnicastRouter -handler MessageHandler +Broadcast([]byte) error -handleRainTreeMsg([]byte) error } class BackgroundRouter { UnicastRouter -handler MessageHandler +Broadcast([]byte) error -handleBackgroundMsg([]byte) error -readSubscription(subscription *pubsub.Subscription) } class UnicastRouter { -messageHandler MessageHandler -peerHandler PeerHandler +Send([]byte, Address) error -handleStream(libp2pNetwork.Stream) -readStream(libp2pNetwork.Stream) } RainTreeRouter --* UnicastRouter : (embedded) p2pModule --o "1" Router p2pModule ..* RainTreeRouter : (`router`) class Router { <<interface>> +Send([]byte, Address) error +Broadcast([]byte) error } BackgroundRouter --|> Router RainTreeRouter --|> RouterAfter
backgroundRouterembedsUnicastRouterand is integrated intop2pModulesuch that it is considered when callingP2PModule#Send()andP2PModule#Broadcast().classDiagram class p2pModule { -stakedActorRouter Router -unstakedActorRouter Router -handlePocketEnvelope([]byte) error } class P2PModule { <<interface>> GetAddress() (Address, error) HandleEvent(*anypb.Any) error Send([]byte, Address) error Broadcast([]byte) error } p2pModule --|> P2PModule class RainTreeRouter { UnicastRouter -handler MessageHandler +Broadcast([]byte) error -handleRainTreeMsg([]byte) error } class BackgroundRouter { UnicastRouter -handler MessageHandler +Broadcast([]byte) error -handleBackgroundMsg([]byte) error -readSubscription(subscription *pubsub.Subscription) } class UnicastRouter { -messageHandler MessageHandler -peerHandler PeerHandler +Send([]byte, Address) error -handleStream(libp2pNetwork.Stream) -readStream(libp2pNetwork.Stream) } RainTreeRouter --* UnicastRouter : (embedded) BackgroundRouter --* UnicastRouter : (embedded) p2pModule --o "2" Router p2pModule ..* RainTreeRouter : (`stakedActorRouter`) p2pModule ..* BackgroundRouter : (`unstakedActorRouter`) class Router { <<interface>> +Send([]byte, Address) error +Broadcast([]byte) error } BackgroundRouter --|> Router RainTreeRouter --|> RouterIssue
Dependencies
Type of change
Please mark the relevant option(s):
List of changes
Router#Close()interface methodPocketEnvelopenonce generation toPackMessage()Handlerto router configsRouterinterface changesRouterinterface changesTesting
make develop_test; if any code changes were madeRequired Checklist
godocformat comments on touched members (see: tip.golang.org/doc/comment)If Applicable Checklist
shared/docs/*if I updatedshared/*README(s)