From e09f67ce7f2785f62546df092ce68b3c7f91d945 Mon Sep 17 00:00:00 2001 From: Alexsander Falcucci Date: Sat, 11 May 2024 02:10:20 +0200 Subject: [PATCH 1/4] feat: update source urls and add new chain point functions - update the source url of the pallas-addresses package - update the source url of the pallas-codec package - update the source url of the pallas-hardano package - update the source url of the pallas-network package - update the source url of the pallas-primitives package - update the source url of the pallas-traverse package - update the source url of the pallas-crypto package - modify the `do_get_chain_block_no` function to async and handle errors - add a new `get_chain_point` function to fetch chain point information - implement the `get_current_chain_point` function for pallas - add a new `get_current_chain_point` test function --- Cargo.lock | 23 ++---- mithril-common/Cargo.toml | 28 +++++-- .../src/chain_observer/pallas_observer.rs | 79 +++++++++++++++++-- 3 files changed, 102 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 989f525cf76..5384cc6c183 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4293,24 +4293,22 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "pallas-addresses" version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9148574f9e1b25d67d11c9680bd267e927128d287d6d4de394695ed57388f28f" +source = "git+https://github.com/txpipe/pallas.git?branch=main#e1504a24632c2337aae1f86a40ed700f26a9ad67" dependencies = [ "base58", "bech32 0.9.1", "crc", + "cryptoxide", "hex", "pallas-codec", "pallas-crypto", - "sha3", "thiserror", ] [[package]] name = "pallas-codec" version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "357301a71c685b3c586defca1aaea59da46fb397c1b960c8487277adf0c346a1" +source = "git+https://github.com/txpipe/pallas.git?branch=main#e1504a24632c2337aae1f86a40ed700f26a9ad67" dependencies = [ "hex", "minicbor", @@ -4321,8 +4319,7 @@ dependencies = [ [[package]] name = "pallas-crypto" version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a1adbeb46418fd6b1ca00db9d81253f131c7555864f4e6712c7f562063c316" +source = "git+https://github.com/txpipe/pallas.git?branch=main#e1504a24632c2337aae1f86a40ed700f26a9ad67" dependencies = [ "cryptoxide", "hex", @@ -4335,8 +4332,7 @@ dependencies = [ [[package]] name = "pallas-hardano" version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92836a18dd8411d5a6cfeb472b9d454b00e61dbcb466a41f0cc3a666b94726ea" +source = "git+https://github.com/txpipe/pallas.git?branch=main#e1504a24632c2337aae1f86a40ed700f26a9ad67" dependencies = [ "binary-layout", "pallas-network", @@ -4349,8 +4345,7 @@ dependencies = [ [[package]] name = "pallas-network" version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8397eb2e3c89cf17aa998725fcd6f8acb4bd3fa3802a1d96618dbe7d8145c1b" +source = "git+https://github.com/txpipe/pallas.git?branch=main#e1504a24632c2337aae1f86a40ed700f26a9ad67" dependencies = [ "byteorder", "hex", @@ -4367,8 +4362,7 @@ dependencies = [ [[package]] name = "pallas-primitives" version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95666399b6ae09fdf93cf405e032d1c950909daf0fe8954b43c895653359a194" +source = "git+https://github.com/txpipe/pallas.git?branch=main#e1504a24632c2337aae1f86a40ed700f26a9ad67" dependencies = [ "base58", "bech32 0.9.1", @@ -4383,8 +4377,7 @@ dependencies = [ [[package]] name = "pallas-traverse" version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfd9057640b61de89bf3176aeee20145192df644d09dd6672dcc85824901f11e" +source = "git+https://github.com/txpipe/pallas.git?branch=main#e1504a24632c2337aae1f86a40ed700f26a9ad67" dependencies = [ "hex", "pallas-addresses", diff --git a/mithril-common/Cargo.toml b/mithril-common/Cargo.toml index 4b21c726d1d..2715eab37f4 100644 --- a/mithril-common/Cargo.toml +++ b/mithril-common/Cargo.toml @@ -48,12 +48,24 @@ kes-summed-ed25519 = { version = "0.2.1", features = [ "sk_clone_enabled", ] } nom = "7.1.3" -pallas-addresses = { version = "0.25.0", optional = true } -pallas-codec = { version = "0.25.0", optional = true } -pallas-hardano = { version = "0.25.0", optional = true } -pallas-network = { version = "0.25.0", optional = true } -pallas-primitives = { version = "0.25.0", optional = true } -pallas-traverse = { version = "0.25.0", optional = true } +# pallas-addresses = { version = "0.25.0", optional = true } +pallas-addresses = { git = "https://github.com/txpipe/pallas.git", branch = "main", optional = true } +# pallas-addresses = { path = "/Users/falcucci/txpipe/pallas/pallas-addresses", optional = true } +# pallas-codec = { version = "0.25.0", optional = true } +pallas-codec = { git = "https://github.com/txpipe/pallas.git", branch = "main", optional = true } +# pallas-codec = { path = "/Users/falcucci/txpipe/pallas/pallas-codec", optional = true } +# pallas-hardano = { version = "0.25.0", optional = true } +pallas-hardano = { git = "https://github.com/txpipe/pallas.git", branch = "main", optional = true } +# pallas-hardano = { path = "/Users/falcucci/txpipe/pallas/pallas-hardano", optional = true } +# pallas-network = { version = "0.25.0", optional = true } +pallas-network = { git = "https://github.com/txpipe/pallas.git", branch = "main", optional = true } +# pallas-network = { path = "/Users/falcucci/txpipe/pallas/pallas-network", optional = true } +# pallas-primitives = { version = "0.25.0", optional = true } +pallas-primitives = { git = "https://github.com/txpipe/pallas.git", branch = "main", optional = true } +# pallas-primitives = { path = "/Users/falcucci/txpipe/pallas/pallas-primitives", optional = true } +# pallas-traverse = { version = "0.25.0", optional = true } +pallas-traverse = { git = "https://github.com/txpipe/pallas.git", branch = "main", optional = true } +# pallas-traverse = { path = "/Users/falcucci/txpipe/pallas/pallas-traverse", optional = true } rand_chacha = "0.3.1" rand_core = "0.6.4" rayon = "1.8.1" @@ -93,7 +105,9 @@ wasm-bindgen = "0.2.90" [dev-dependencies] criterion = { version = "0.5.1", features = ["html_reports", "async_tokio"] } mockall = "0.12.1" -pallas-crypto = "0.25.0" +# pallas-crypto = "0.25.0" +pallas-crypto = { git = "https://github.com/txpipe/pallas.git", branch = "main" } +# pallas-crypto = { path = "/Users/falcucci/txpipe/pallas/pallas-crypto" } rand_core = { version = "0.6.4", features = ["getrandom"] } reqwest = { version = "0.12.0", features = ["json"] } slog-async = "2.8.0" diff --git a/mithril-common/src/chain_observer/pallas_observer.rs b/mithril-common/src/chain_observer/pallas_observer.rs index 8779f01f83d..2df10fd95a9 100644 --- a/mithril-common/src/chain_observer/pallas_observer.rs +++ b/mithril-common/src/chain_observer/pallas_observer.rs @@ -7,8 +7,8 @@ use pallas_network::{ miniprotocols::{ localstate::{ queries_v16::{ - self, Addr, Addrs, Genesis, PostAlonsoTransactionOutput, StakeSnapshot, Stakes, - TransactionOutput, UTxOByAddress, + self, Addr, Addrs, ChainBlockNumber, Genesis, PostAlonsoTransactionOutput, + StakeSnapshot, Stakes, TransactionOutput, UTxOByAddress, }, Client, }, @@ -279,6 +279,16 @@ impl PallasChainObserver { Ok(chain_point) } + /// Fetches the current chain point using the provided `NodeClient`. + async fn do_get_chain_block_no(&self, statequery: &mut Client) -> StdResult { + let chain_block_number = queries_v16::get_chain_block_no(statequery) + .await + .map_err(|err| anyhow!(err)) + .with_context(|| "PallasChainObserver failed to get chain block number")?; + + Ok(chain_block_number) + } + /// Fetches the current era using the provided `statequery` client. async fn do_get_current_era_state_query(&self, statequery: &mut Client) -> StdResult { let era = queries_v16::get_current_era(statequery) @@ -303,6 +313,30 @@ impl PallasChainObserver { Ok(genesis_config) } + /// Fetches the current chain point using the provided `NodeClient`. + async fn get_chain_point(&self, statequery: &mut Client) -> StdResult { + statequery + .acquire(None) + .await + .map_err(|err| anyhow!(err)) + .with_context(|| "PallasChainObserver failed to acquire statequery")?; + + let chain_point = self.do_get_chain_point_state_query(statequery).await?; + + let header_hash = match chain_point { + Point::Origin => None, + Point::Specific(_at_slot, ref hash) => Some(hex::encode(hash)), + }; + + let chain_block_number = self.do_get_chain_block_no(statequery).await?; + + Ok(ChainPoint { + slot_number: chain_point.slot_or_default(), + block_hash: header_hash.unwrap_or_default(), + block_number: chain_block_number.block_number as u64, + }) + } + /// Fetches chain point and genesis config through the local statequery. /// The KES period is calculated afterwards. async fn get_kes_period( @@ -385,8 +419,15 @@ impl ChainObserver for PallasChainObserver { } async fn get_current_chain_point(&self) -> Result, ChainObserverError> { - // TODO: Implement get_current_chain_point with pallas - todo!("Implement get_current_chain_point") + let mut client = self.get_client().await?; + + let chain_point = self.get_chain_point(client.statequery()).await?; + + self.post_process_statequery(&mut client).await?; + + client.abort().await; + + Ok(Some(chain_point)) } async fn get_current_datums( @@ -444,8 +485,8 @@ mod tests { use pallas_network::miniprotocols::{ localstate::{ queries_v16::{ - BlockQuery, Fraction, Genesis, HardForkQuery, LedgerQuery, Request, Snapshots, - StakeSnapshot, SystemStart, Value, + BlockQuery, ChainBlockNumber, Fraction, Genesis, HardForkQuery, LedgerQuery, + Request, Snapshots, StakeSnapshot, SystemStart, Value, }, ClientQueryRequest, }, @@ -581,6 +622,10 @@ mod tests { Request::GetChainPoint => { AnyCbor::from_encode(Point::Specific(52851885, vec![1, 2, 3])) } + Request::GetChainBlockNo => AnyCbor::from_encode(ChainBlockNumber { + slot_timeline: 1, + block_number: 52851885, + }), Request::LedgerQuery(LedgerQuery::HardForkQuery(HardForkQuery::GetCurrentEra)) => { AnyCbor::from_encode(4) } @@ -816,4 +861,26 @@ mod tests { let era = client_res.expect("Client failed"); assert_eq!(era, 4); } + + #[tokio::test] + async fn get_current_chain_point() { + let socket_path = create_temp_dir("get_current_chain_point").join("node.socket"); + let server = setup_server(socket_path.clone(), 2).await; + let client = tokio::spawn(async move { + let observer = + PallasChainObserver::new(socket_path.as_path(), CardanoNetwork::TestNet(10)); + observer.get_current_chain_point().await.unwrap() + }); + + let (_, client_res) = tokio::join!(server, client); + let chain_point = client_res.expect("Client failed"); + assert_eq!( + chain_point, + Some(ChainPoint { + slot_number: 52851885, + block_hash: "010203".to_string(), + block_number: 52851885 + }) + ); + } } From b969fd2ea153c8fde14997aafdbbfc18f194ff95 Mon Sep 17 00:00:00 2001 From: Alexsander Falcucci Date: Sun, 12 May 2024 18:31:50 +0200 Subject: [PATCH 2/4] chore: update dependencies and reorganize feature flags - remove unnecessary commented out paths for dependencies - update versions of dependencies - reorganize feature flags for the `criterion` dependency --- mithril-common/Cargo.toml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/mithril-common/Cargo.toml b/mithril-common/Cargo.toml index 2715eab37f4..6861d76c134 100644 --- a/mithril-common/Cargo.toml +++ b/mithril-common/Cargo.toml @@ -50,22 +50,16 @@ kes-summed-ed25519 = { version = "0.2.1", features = [ nom = "7.1.3" # pallas-addresses = { version = "0.25.0", optional = true } pallas-addresses = { git = "https://github.com/txpipe/pallas.git", branch = "main", optional = true } -# pallas-addresses = { path = "/Users/falcucci/txpipe/pallas/pallas-addresses", optional = true } # pallas-codec = { version = "0.25.0", optional = true } pallas-codec = { git = "https://github.com/txpipe/pallas.git", branch = "main", optional = true } -# pallas-codec = { path = "/Users/falcucci/txpipe/pallas/pallas-codec", optional = true } # pallas-hardano = { version = "0.25.0", optional = true } pallas-hardano = { git = "https://github.com/txpipe/pallas.git", branch = "main", optional = true } -# pallas-hardano = { path = "/Users/falcucci/txpipe/pallas/pallas-hardano", optional = true } # pallas-network = { version = "0.25.0", optional = true } pallas-network = { git = "https://github.com/txpipe/pallas.git", branch = "main", optional = true } -# pallas-network = { path = "/Users/falcucci/txpipe/pallas/pallas-network", optional = true } # pallas-primitives = { version = "0.25.0", optional = true } pallas-primitives = { git = "https://github.com/txpipe/pallas.git", branch = "main", optional = true } -# pallas-primitives = { path = "/Users/falcucci/txpipe/pallas/pallas-primitives", optional = true } # pallas-traverse = { version = "0.25.0", optional = true } pallas-traverse = { git = "https://github.com/txpipe/pallas.git", branch = "main", optional = true } -# pallas-traverse = { path = "/Users/falcucci/txpipe/pallas/pallas-traverse", optional = true } rand_chacha = "0.3.1" rand_core = "0.6.4" rayon = "1.8.1" @@ -107,7 +101,6 @@ criterion = { version = "0.5.1", features = ["html_reports", "async_tokio"] } mockall = "0.12.1" # pallas-crypto = "0.25.0" pallas-crypto = { git = "https://github.com/txpipe/pallas.git", branch = "main" } -# pallas-crypto = { path = "/Users/falcucci/txpipe/pallas/pallas-crypto" } rand_core = { version = "0.6.4", features = ["getrandom"] } reqwest = { version = "0.12.0", features = ["json"] } slog-async = "2.8.0" From 9fc125e51a9af01f645e0fe5d8e3a1800d57bf7e Mon Sep 17 00:00:00 2001 From: Alexsander Falcucci Date: Tue, 21 May 2024 14:30:33 +0200 Subject: [PATCH 3/4] chore: update package versions and dependencies - update package versions in `cargo.lock` from `0.25.0` to `0.26.0` - change package sources in `cargo.lock` to use `crates.io-index` - update package versions in `cargo.toml` in `mithril-common` directory from `0.25.0` to `0.26.0` - add new dependencies with updated versions in `cargo.toml` in `mithril-common` directory --- Cargo.lock | 35 +++++++++++++++++++++-------------- mithril-common/Cargo.toml | 21 +++++++-------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5384cc6c183..b630e323b82 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4292,8 +4292,9 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "pallas-addresses" -version = "0.25.0" -source = "git+https://github.com/txpipe/pallas.git?branch=main#e1504a24632c2337aae1f86a40ed700f26a9ad67" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6987484713dc3114caaff5973ecfd411712f5906371b46e393611d9c9e7b15" dependencies = [ "base58", "bech32 0.9.1", @@ -4307,8 +4308,9 @@ dependencies = [ [[package]] name = "pallas-codec" -version = "0.25.0" -source = "git+https://github.com/txpipe/pallas.git?branch=main#e1504a24632c2337aae1f86a40ed700f26a9ad67" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aff3e0b3c3c1c2dabf6ae09e21ac174bce54bd2ba40b1d1bef297729ac7140e3" dependencies = [ "hex", "minicbor", @@ -4318,8 +4320,9 @@ dependencies = [ [[package]] name = "pallas-crypto" -version = "0.25.0" -source = "git+https://github.com/txpipe/pallas.git?branch=main#e1504a24632c2337aae1f86a40ed700f26a9ad67" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d7b3c6395d54baf25fec9c3ae1b3853e69a2a3ba2ef8e54e98c43b4181646d5" dependencies = [ "cryptoxide", "hex", @@ -4331,8 +4334,9 @@ dependencies = [ [[package]] name = "pallas-hardano" -version = "0.25.0" -source = "git+https://github.com/txpipe/pallas.git?branch=main#e1504a24632c2337aae1f86a40ed700f26a9ad67" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41a0cdce342f7e3ba68c8d6e359c0c9981dfa770c61952b98d338dd5a76ae8ad" dependencies = [ "binary-layout", "pallas-network", @@ -4344,8 +4348,9 @@ dependencies = [ [[package]] name = "pallas-network" -version = "0.25.0" -source = "git+https://github.com/txpipe/pallas.git?branch=main#e1504a24632c2337aae1f86a40ed700f26a9ad67" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca856c83cda9de083b1473db46e6ef8e91bcf485168cbb1315511b4a22d93fd0" dependencies = [ "byteorder", "hex", @@ -4361,8 +4366,9 @@ dependencies = [ [[package]] name = "pallas-primitives" -version = "0.25.0" -source = "git+https://github.com/txpipe/pallas.git?branch=main#e1504a24632c2337aae1f86a40ed700f26a9ad67" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4165af123578001c57be4dbceef9895e7eabd8062b80018411d5895be87645ac" dependencies = [ "base58", "bech32 0.9.1", @@ -4376,8 +4382,9 @@ dependencies = [ [[package]] name = "pallas-traverse" -version = "0.25.0" -source = "git+https://github.com/txpipe/pallas.git?branch=main#e1504a24632c2337aae1f86a40ed700f26a9ad67" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caac6868d44b49b29dc6e6d4c7b4e5c7d6e177dea0833bece478c2f87333c032" dependencies = [ "hex", "pallas-addresses", diff --git a/mithril-common/Cargo.toml b/mithril-common/Cargo.toml index 6861d76c134..9996942154a 100644 --- a/mithril-common/Cargo.toml +++ b/mithril-common/Cargo.toml @@ -48,18 +48,12 @@ kes-summed-ed25519 = { version = "0.2.1", features = [ "sk_clone_enabled", ] } nom = "7.1.3" -# pallas-addresses = { version = "0.25.0", optional = true } -pallas-addresses = { git = "https://github.com/txpipe/pallas.git", branch = "main", optional = true } -# pallas-codec = { version = "0.25.0", optional = true } -pallas-codec = { git = "https://github.com/txpipe/pallas.git", branch = "main", optional = true } -# pallas-hardano = { version = "0.25.0", optional = true } -pallas-hardano = { git = "https://github.com/txpipe/pallas.git", branch = "main", optional = true } -# pallas-network = { version = "0.25.0", optional = true } -pallas-network = { git = "https://github.com/txpipe/pallas.git", branch = "main", optional = true } -# pallas-primitives = { version = "0.25.0", optional = true } -pallas-primitives = { git = "https://github.com/txpipe/pallas.git", branch = "main", optional = true } -# pallas-traverse = { version = "0.25.0", optional = true } -pallas-traverse = { git = "https://github.com/txpipe/pallas.git", branch = "main", optional = true } +pallas-addresses = { version = "0.26.0", optional = true } +pallas-codec = { version = "0.26.0", optional = true } +pallas-hardano = { version = "0.26.0", optional = true } +pallas-network = { version = "0.26.0", optional = true } +pallas-primitives = { version = "0.26.0", optional = true } +pallas-traverse = { version = "0.26.0", optional = true } rand_chacha = "0.3.1" rand_core = "0.6.4" rayon = "1.8.1" @@ -99,8 +93,7 @@ wasm-bindgen = "0.2.90" [dev-dependencies] criterion = { version = "0.5.1", features = ["html_reports", "async_tokio"] } mockall = "0.12.1" -# pallas-crypto = "0.25.0" -pallas-crypto = { git = "https://github.com/txpipe/pallas.git", branch = "main" } +pallas-crypto = "0.26.0" rand_core = { version = "0.6.4", features = ["getrandom"] } reqwest = { version = "0.12.0", features = ["json"] } slog-async = "2.8.0" From 68735e652a0c3d87935ac92dbc78e930f387e465 Mon Sep 17 00:00:00 2001 From: Alexsander Falcucci Date: Tue, 21 May 2024 15:06:20 +0200 Subject: [PATCH 4/4] chore: update dependencies to latest versions - update version of `mithril-common` from 0.4.4 to 0.4.5 in `cargo.lock` and `mithril-common/cargo.toml` --- Cargo.lock | 2 +- mithril-common/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 291372f26a1..328c1ba0215 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3607,7 +3607,7 @@ dependencies = [ [[package]] name = "mithril-common" -version = "0.4.4" +version = "0.4.5" dependencies = [ "anyhow", "async-trait", diff --git a/mithril-common/Cargo.toml b/mithril-common/Cargo.toml index 9996942154a..1146b01e117 100644 --- a/mithril-common/Cargo.toml +++ b/mithril-common/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-common" -version = "0.4.4" +version = "0.4.5" description = "Common types, interfaces, and utilities for Mithril nodes." authors = { workspace = true } edition = { workspace = true }