Skip to content
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

[Networking] Refactoring Networking Layer for Improved Structure and Maintainability AND Eliminating Redundant Middleware Component #4664

Merged
merged 116 commits into from
Sep 6, 2023

Conversation

yhassanzadeh13
Copy link
Contributor

@yhassanzadeh13 yhassanzadeh13 commented Aug 29, 2023

Background:

This PR aims to address the issues raised in GH issue https://github.com/dapperlabs/flow-go/issues/6851, which highlights inefficiencies in the Flow blockchain's networking layer. The current three-layered architecture has led to complexities, making the system difficult to maintain and debug.

Changes:

  • Removed the Middleware layer.
  • Reorganized the code into two distinct layers: Network Interface and Libp2p Node.
  • Moved the relevant logic from Middleware to Network component.

Specifically, the Middleware.go implementation has been removed. Instead, its functionality has been revamped and refactored into an interface integrated directly within the Network.go. Now, our Network.go file embodies three distinct interfaces—Network, Adapter, and Middleware—each serving different components.

  1. Network Interface: Provides functionalities exposed to the Flow protocol layer (i.e., engines). This includes registering channels and services like BlobService and PingService.

  2. Adapter Interface: Serves as the networking layer for individual conduits, allowing them to send various types of messages, such as unicast, multicast, and publish.

  3. Middleware Interface: Offers functionalities to lower-level networking components like libp2p, including channel subscriptions and updating addresses for authorized participants.

We acknowledge that the naming conventions for these interfaces may need to be revised. While we welcome suggestions for better names, we have retained the current names to facilitate a more streamlined PR review process for this first round.

Your feedback on the naming or the structural changes themselves would be greatly appreciated.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 6, 2023

FVM Benchstat comparison

This branch with compared with the base branch onflow:master commit 104ca4f

The command (for i in {1..7}; do go test ./fvm ./engine/execution/computation --bench . --tags relic -shuffle=on --benchmem --run ^$; done) was used.

Collapsed results for better readability

old.txtnew.txt
time/opdelta
ComputeBlock/16/cols/128/txes/1/max-concurrency-25.50s ± 0%5.48s ± 0%~(p=1.000 n=1+1)
ComputeBlock/16/cols/128/txes/2/max-concurrency-25.82s ± 0%5.80s ± 0%~(p=1.000 n=1+1)
 
us/txdelta
ComputeBlock/16/cols/128/txes/1/max-concurrency-22.69k ± 0%2.68k ± 0%~(p=1.000 n=1+1)
ComputeBlock/16/cols/128/txes/2/max-concurrency-22.84k ± 0%2.83k ± 0%~(p=1.000 n=1+1)
 
alloc/opdelta
ComputeBlock/16/cols/128/txes/1/max-concurrency-21.66GB ± 0%1.66GB ± 0%~(p=1.000 n=1+1)
ComputeBlock/16/cols/128/txes/2/max-concurrency-21.70GB ± 0%1.69GB ± 0%~(p=1.000 n=1+1)
 
allocs/opdelta
ComputeBlock/16/cols/128/txes/1/max-concurrency-221.9M ± 0%21.9M ± 0%~(p=1.000 n=1+1)
ComputeBlock/16/cols/128/txes/2/max-concurrency-222.6M ± 0%22.6M ± 0%~(p=1.000 n=1+1)
 

…e-part-2' into yahya/6851-refactoring-middleware-part-2
Middleware network.Middleware
Network network.Network
EngineRegistry network.EngineRegistry
UnderlayNetwork network.Underlay
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
UnderlayNetwork network.Underlay
NetworkUnderlay network.Underlay

I think its fine to call struct fields with the Network* prefix, UnderlayNetwork sounds like it is an actual network rather than a component in a network. Lets use NetworkUnderlay in these instances.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AddPeer(ctx context.Context, peerInfo peer.AddrInfo) error
// ConnectToPeerAddrInfo connects to the peer with the given peer address information.
// This method is used to connect to a peer that is not in the peer store.
ConnectToPeerAddrInfo(ctx context.Context, peerInfo peer.AddrInfo) error
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
ConnectToPeerAddrInfo(ctx context.Context, peerInfo peer.AddrInfo) error
ConnectToPeer(ctx context.Context, peerInfo peer.AddrInfo) error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mw network.Middleware
mu sync.RWMutex
engines map[channels.Channel]network.MessageProcessor
middleware network.Underlay // the Underlay interface of the network layer
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
middleware network.Underlay // the Underlay interface of the network layer
networkUnderlay network.Underlay // the Underlay interface of the network layer

Do we still need to use "middleware" at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@kc1116 kc1116 left a comment

Choose a reason for hiding this comment

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

Great work 🚀

@yhassanzadeh13 yhassanzadeh13 added this pull request to the merge queue Sep 6, 2023
Merged via the queue into master with commit 698d641 Sep 6, 2023
37 checks passed
@yhassanzadeh13 yhassanzadeh13 deleted the yahya/6851-refactoring-middleware-part-2 branch September 6, 2023 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants