-
Notifications
You must be signed in to change notification settings - Fork 5
feat: Add dynamic sync mode to peer_network_interface #394
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
15 commits
Select commit
Hold shift + click to select a range
237e8d2
feat: add SyncCommand channel to peer network interface
whankinsiv d85e915
refactor: await inital sync command before initializing network manager
whankinsiv 64a302f
feat: minimal indexer process and module
whankinsiv 65125b3
fix: move handle_sync_command logic inside on_sync_cmd
whankinsiv c1ae681
fix: comments
whankinsiv e385823
fix: cargo shear
whankinsiv 9668f14
fix: cargo shear (again)
whankinsiv 76cd5fb
refactor: rename SyncCommand to ChainSyncCommand
whankinsiv d9110c1
refactor: route sync commands through NetworkManager event queue
whankinsiv 3dfdb78
refactor: use strongly-typed config pattern
whankinsiv 7574bc2
Merge remote-tracking branch 'origin/main' into whankinsiv/peer-netwo…
whankinsiv 26809f0
fix: clippy
whankinsiv 6e12ea6
fix: shear
whankinsiv 6038416
test: add test that blocks coming in post-rollback are ignored
SupernaviX 725a021
fix: shear
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| use crate::{BlockHash, Slot}; | ||
|
|
||
| #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] | ||
| pub enum ChainSyncCommand { | ||
| FindIntersect { slot: Slot, hash: BlockHash }, | ||
| } |
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 |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| pub mod chain_sync; | ||
| pub mod transactions; |
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,22 @@ | ||
| # Acropolis indexer module | ||
|
|
||
| [package] | ||
| name = "acropolis_module_indexer" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
| authors = ["William Hankins <william@sundae.fi>"] | ||
| description = "Core indexer logic" | ||
| license = "Apache-2.0" | ||
|
|
||
| [dependencies] | ||
| acropolis_common = { path = "../../common" } | ||
|
|
||
| caryatid_sdk = { workspace = true } | ||
|
|
||
| anyhow = { workspace = true } | ||
| config = { workspace = true } | ||
| serde = { workspace = true, features = ["rc"] } | ||
| tracing = { workspace = true } | ||
|
|
||
| [lib] | ||
| path = "src/indexer.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,2 @@ | ||
| # The topic to publish sync commands on | ||
| sync-command-topic = "cardano.sync.command" |
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,21 @@ | ||
| use anyhow::Result; | ||
| use config::Config; | ||
|
|
||
| #[derive(serde::Deserialize)] | ||
| #[serde(rename_all = "kebab-case")] | ||
| pub struct IndexerConfig { | ||
| pub sync_command_topic: String, | ||
| } | ||
|
|
||
| impl IndexerConfig { | ||
| pub fn try_load(config: &Config) -> Result<Self> { | ||
| let full_config = Config::builder() | ||
| .add_source(config::File::from_str( | ||
| include_str!("../config.default.toml"), | ||
| config::FileFormat::Toml, | ||
| )) | ||
| .add_source(config.clone()) | ||
| .build()?; | ||
| Ok(full_config.try_deserialize()?) | ||
| } | ||
| } |
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,67 @@ | ||
| //! Acropolis indexer module for Caryatid | ||
| mod configuration; | ||
|
|
||
| use acropolis_common::{ | ||
| commands::chain_sync::ChainSyncCommand, | ||
| hash::Hash, | ||
| messages::{Command, Message}, | ||
| }; | ||
| use anyhow::Result; | ||
| use caryatid_sdk::{module, Context}; | ||
| use config::Config; | ||
| use std::{str::FromStr, sync::Arc}; | ||
| use tracing::info; | ||
|
|
||
| use crate::configuration::IndexerConfig; | ||
|
|
||
| /// Indexer module | ||
| #[module( | ||
| message_type(Message), | ||
| name = "indexer", | ||
| description = "Core indexer module for indexer process" | ||
| )] | ||
| pub struct Indexer; | ||
|
|
||
| impl Indexer { | ||
| /// Async initialisation | ||
| pub async fn init(&self, context: Arc<Context<Message>>, config: Arc<Config>) -> Result<()> { | ||
| let cfg = IndexerConfig::try_load(&config)?; | ||
| info!( | ||
| "Creating sync command publisher on '{}'", | ||
| cfg.sync_command_topic | ||
| ); | ||
|
|
||
| let ctx = context.clone(); | ||
|
|
||
| // This is a placeholder to test dynamic sync | ||
| context.run(async move { | ||
| let example = ChainSyncCommand::FindIntersect { | ||
| slot: 4492799, | ||
| hash: Hash::from_str( | ||
| "f8084c61b6a238acec985b59310b6ecec49c0ab8352249afd7268da5cff2a457", | ||
| ) | ||
| .expect("Valid hash"), | ||
| }; | ||
|
|
||
| // Initial sync message (This will be read from config for first sync and from DB on subsequent runs) | ||
| ctx.message_bus | ||
| .publish( | ||
| &cfg.sync_command_topic, | ||
| Arc::new(Message::Command(Command::ChainSync(example.clone()))), | ||
| ) | ||
| .await | ||
| .unwrap(); | ||
|
|
||
| // Simulate a later sync command to reset sync point to where we started | ||
|
|
||
| ctx.message_bus | ||
| .publish( | ||
| &cfg.sync_command_topic, | ||
| Arc::new(Message::Command(Command::ChainSync(example))), | ||
| ) | ||
| .await | ||
| .unwrap(); | ||
| }); | ||
| Ok(()) | ||
| } | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.