Skip to content

p2p: add Router prototype#5831

Merged
mergify[bot] merged 4 commits intomasterfrom
erik/p2p-router
Jan 8, 2021
Merged

p2p: add Router prototype#5831
mergify[bot] merged 4 commits intomasterfrom
erik/p2p-router

Conversation

@erikgrinaker
Copy link
Contributor

@erikgrinaker erikgrinaker commented Dec 23, 2020

Early but functional prototype of the new p2p.Router, see its GoDoc comment for details on how it works. Expect much of this logic to change and improve as we evolve the new P2P stack.

There is a simple test that sets up an in-memory network of four routers with reactors and passes messages between them, but otherwise no exhaustive tests since this is very much a work-in-progress.

@erikgrinaker erikgrinaker added the C:p2p Component: P2P pkg label Dec 23, 2020
@erikgrinaker erikgrinaker self-assigned this Dec 23, 2020
@codecov
Copy link

codecov bot commented Dec 23, 2020

Codecov Report

Merging #5831 (6a9f000) into master (66ba12d) will increase coverage by 0.05%.
The diff coverage is 62.73%.

@@            Coverage Diff             @@
##           master    #5831      +/-   ##
==========================================
+ Coverage   59.91%   59.96%   +0.05%     
==========================================
  Files         267      269       +2     
  Lines       24094    24495     +401     
==========================================
+ Hits        14435    14688     +253     
- Misses       8124     8226     +102     
- Partials     1535     1581      +46     
Impacted Files Coverage Δ
cmd/tendermint/commands/light.go 16.55% <0.00%> (-0.12%) ⬇️
statesync/stateprovider.go 0.00% <0.00%> (ø)
p2p/peer.go 53.12% <53.60%> (+2.73%) ⬆️
store/store.go 56.01% <55.55%> (-7.02%) ⬇️
p2p/transport.go 46.15% <57.14%> (+18.15%) ⬆️
light/store/db/db.go 58.27% <63.15%> (-0.59%) ⬇️
p2p/router.go 68.88% <68.88%> (ø)
p2p/channel.go 100.00% <100.00%> (+6.25%) ⬆️
p2p/queue.go 100.00% <100.00%> (ø)
libs/events/events.go 92.94% <0.00%> (-5.89%) ⬇️
... and 18 more

Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Providing a preliminary review -- looks great! Looking at the Router implementation now.

Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performed another review (solely the router) and it looks great -- easy to follow for the most part. I think it is just a tad bit confusing where/who closes queues (i.e. it seems we close and/or remove from map in both acceptPeers and routeChannel).

Overall, LGTM.

return nil
}

// Claim claims a peer. The caller has exclusive ownership of the peer, and must
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, multiple processes can have access to a storePeer, correct? The caller can pass that object around if it wanted to, but my guess is we don't really need to worry about that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that's up to the caller -- it owns it and can do whatever it wants with it. But the store will not give it to any other callers until it has been returned.

case queue.enqueue() <- Envelope{channel: ChannelID(chID), From: peerID, Message: msg}:
r.logger.Debug("received message", "peer", peerID, "message", msg)
case <-queue.closed():
r.logger.Error("channel closed, dropping message", "peer", peerID, "channel", chID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
r.logger.Error("channel closed, dropping message", "peer", peerID, "channel", chID)
r.logger.Error("channel closed; dropping message", "peer", peerID, "channel", chID)

@erikgrinaker erikgrinaker force-pushed the erik/p2p-nodeid branch 2 times, most recently from 57f2058 to dc6b31d Compare January 4, 2021 10:08
Base automatically changed from erik/p2p-nodeid to master January 4, 2021 10:25
Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@erikgrinaker erikgrinaker added the S:automerge Automatically merge PR when requirements pass label Jan 8, 2021
@erikgrinaker
Copy link
Contributor Author

TFTR @alexanderbez!

@mergify mergify bot merged commit c61cd3f into master Jan 8, 2021
@mergify mergify bot deleted the erik/p2p-router branch January 8, 2021 15:32
ctx := context.Background()

for _, address := range peer.Addresses {
resolveCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the timeout be configurable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, eventually. This is just a prototype, we'll be adding/integrating configurability later.

err := <-resultsCh
_ = conn.Close()
sendQueue.close()
if e := <-resultsCh; err == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

golang.org/x/sync/errgroup ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, wasn't aware of errgroup. However, in this case we're using conn.Close() and sendQueue.close() to signal termination of the other goroutines after one of them returns, unlike errgroup which relies to context for signaling. I think introducing contexts in addition to connections and queues here just complicates things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C:p2p Component: P2P pkg S:automerge Automatically merge PR when requirements pass

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants