-
Notifications
You must be signed in to change notification settings - Fork 5
Implement PeerNetworkInterface #339
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
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
7390aad
feat: implementation of PeerNetworkInterface
SupernaviX 2281311
fix: blockfetch uses slots
SupernaviX 2d1c5b1
feat: test PeerNetworkInterface in omnibus
SupernaviX 41ee5de
fix: gracefully handle dropped connections
SupernaviX e085283
fix: handle rollbacks when switching chains
SupernaviX ece87d3
feat: integrate upstream cache
SupernaviX 4647b72
fix: handle cache errors more gracefully
SupernaviX dabb272
feat: extract chain logic to separate helper
SupernaviX 6159534
fix: gracefully handle disconnection during in-flight block reqs
SupernaviX a91d460
fix: correctly implement and test chain switching
SupernaviX 21f7e67
docs: docs
SupernaviX bf8a3b7
Merge branch 'main' into sg/peer-network-interface
SupernaviX 03ec421
fix: credit where credit is due
SupernaviX f9b1a4e
fix: finish a sentence
SupernaviX b0c5fc7
fix: run fmt on whole project
SupernaviX 1b85707
fix: gracefully handle connecting to lagging-behind peer
SupernaviX 89bf544
Merge branch 'main' into sg/peer-network-interface
SupernaviX 41d802a
fix: fix cargo-shear issues
SupernaviX 3c87d61
fix: make stake-delta-filter create cache as needed
SupernaviX 212ca55
fix: address copilot comments
SupernaviX 30ebc8d
fix: correctly handle disconnect from only peer
SupernaviX File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # Acropolis upstream chain fetcher module | ||
|
|
||
| [package] | ||
| name = "acropolis_module_peer_network_interface" | ||
| version = "0.2.0" | ||
| edition = "2024" | ||
| authors = ["Simon Gellis <simon@sundae.fi>"] | ||
| description = "Multiplexed chain fetcher Caryatid module for Acropolis" | ||
| license = "Apache-2.0" | ||
|
|
||
| [dependencies] | ||
| acropolis_common = { path = "../../common" } | ||
|
|
||
| caryatid_sdk = { workspace = true } | ||
|
|
||
| anyhow = { workspace = true } | ||
| config = { workspace = true } | ||
| pallas = { workspace = true } | ||
| serde = { workspace = true, features = ["rc"] } | ||
| tokio = { workspace = true } | ||
| tracing = { workspace = true } | ||
|
|
||
| [lib] | ||
| path = "src/peer_network_interface.rs" |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Architecture | ||
|
|
||
| This module uses an event-queue-based architecture. A `NetworkManager` is responsible for creating a set of `PeerConnection`s and sending commands to them. Each `PeerConnection` maintains a connection to a single peer; it responds to commands from the `NetworkManager`, and emits events to an event queue. The `NetworkManager` reads from that queue to decide which chain to follow. When blocks from the preferred chain have been fetched, it publishes those blocks to the message bus. | ||
|
|
||
| This module requests the body for every block announced by any chain, from the first chain which announced it. When it has the body for the next block announced, it will publish it to the message bus. | ||
|
|
||
| ```mermaid | ||
| graph LR | ||
| EQ[Event Queue]-->NM[NetworkManager] | ||
| subgraph Peers | ||
| P1[PeerConnection 1] | ||
| P2[PeerConnection 2] | ||
| P3[PeerConnection 3] | ||
| end | ||
| NM -->|RequestBlock</br>FindIntersect| P1 & P2 & P3 | ||
| Peers -->|ChainSync<br/>BlockFetched<br/>Disconnect|EQ | ||
| NM -->|BlockAvailable| MB[Message Bus] | ||
| ``` |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Peer network interface module | ||
|
|
||
| The peer network interface module uses the ChainSync and BlockFetch protocols to fetch blocks from one of several upstream sources. It chooses one peer to treat as the "preferred" chain to follow, but will gracefully switch which peer it follows during network issues. | ||
|
|
||
| It can either run independently, from the origin or current tip, or | ||
| be triggered by a Mithril snapshot event (the default) where it starts from | ||
| where the snapshot left off, and follows the chain from there. | ||
|
|
||
| Rollbacks are handled by signalling in the block data - it is downstream | ||
| subscribers' responsibility to deal with the effects of this. | ||
|
|
||
| ## Configuration | ||
|
|
||
| See [./config.default.toml](./config.default.toml) for the available configuration options and their default values. | ||
|
|
||
| ## Messages | ||
|
|
||
| This module publishes "raw block messages" to the configured `block-topic`. Each message includes the raw bytes composing the header and body of a block. The module follows the head of one chain at any given time, though that chain may switch during runtime. If that chain reports a rollback (or if this module switches to a different chain), the next message it emits will be the new head of the chain and have the status `RolledBack`. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # The topic to publish blocks on | ||
| block-topic = "cardano.block.available" | ||
| # The topic to wait for when sync-point is "snapshot" | ||
| snapshot-completion-topic = "cardano.snapshot.complete" | ||
| # The topic to wait for when listening for genesis values from another module | ||
| genesis-completion-topic = "cardano.sequence.bootstrapped" | ||
|
|
||
| # Upstream node connections | ||
| node-addresses = [ | ||
| "backbone.cardano.iog.io:3001", | ||
| "backbone.mainnet.cardanofoundation.org:3001", | ||
| "backbone.mainnet.emurgornd.com:3001", | ||
| ] | ||
| # The network magic for the chain to connect to | ||
| magic-number = 764824073 | ||
|
|
||
| # The initial point to start syncing from. Options: | ||
| # - "origin": sync from the very start of the chain | ||
| # - "tip": sync from the very end of the chain | ||
| # - "cache": replay messages from a local filesystem cache, then sync from the point right after that cache. | ||
| # - "snapshot": wait for another module to restore from a snapshot, then sync from the point right after that snapshot. | ||
| sync-point = "snapshot" | ||
| # The cache dir to use when sync-point is "cache" | ||
| cache-dir = "upstream-cache" | ||
Oops, something went wrong.
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.
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.
I was wondering about this topic. Does this mark the completion of a Mithril snapshot? For a future PR, I plan to deconflict this name from a snapshot boot completion.
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.
At the moment, it marks the completion of a mithril snapshot. But for this, we want a topic which marks the completion of any snapshot. If sync-point is "snapshot", we're
So whether it's a mithril snapshot or the boot snapshot, we just want to know when it's done