From 9747be309542e6a09e67a0a2d1da3c9cb5320a73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20S=C3=A1nchez=20Terraf?= Date: Sat, 14 Dec 2024 16:32:12 -0300 Subject: [PATCH] fix(network): adjust PoolDistr & ProtocolParam structs used for state queries (#551) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pedro Sánchez Terraf --- examples/n2c-miniprotocols/src/main.rs | 5 ++- .../localstate/queries_v16/mod.rs | 31 +++++++++--------- pallas-network/tests/protocols.rs | 32 +++++++++---------- 3 files changed, 33 insertions(+), 35 deletions(-) diff --git a/examples/n2c-miniprotocols/src/main.rs b/examples/n2c-miniprotocols/src/main.rs index 5fe5509e..9867f6e2 100644 --- a/examples/n2c-miniprotocols/src/main.rs +++ b/examples/n2c-miniprotocols/src/main.rs @@ -14,7 +14,6 @@ use pallas::{ crypto::hash::Hash, }; use tracing::info; -use hex::FromHex; async fn do_localstate_query(client: &mut NodeClient) { let client = client.statequery(); @@ -114,8 +113,8 @@ async fn do_localstate_query(client: &mut NodeClient) { async fn do_chainsync(client: &mut NodeClient) { let known_points = vec![Point::Specific( - 43847831u64, - hex::decode("15b9eeee849dd6386d3770b0745e0450190f7560e5159b1b3ab13b14b2684a45").unwrap(), + 77110778u64, + hex::decode("18e6eeaa592c42113280ba47a0829355e6bed1c9ce67cce4be502d6031d0679a").unwrap(), )]; let (point, _) = client diff --git a/pallas-network/src/miniprotocols/localstate/queries_v16/mod.rs b/pallas-network/src/miniprotocols/localstate/queries_v16/mod.rs index 6653d3ab..8a277799 100644 --- a/pallas-network/src/miniprotocols/localstate/queries_v16/mod.rs +++ b/pallas-network/src/miniprotocols/localstate/queries_v16/mod.rs @@ -111,6 +111,7 @@ pub type PositiveInterval = RationalNumber; pub type ProtocolVersionMajor = u64; pub type ProtocolVersionMinor = u64; +pub type ProtocolVersion = (ProtocolVersionMajor, ProtocolVersionMinor); pub type CostModel = Vec; @@ -169,26 +170,24 @@ pub struct ProtocolParam { #[n(11)] pub treasury_growth_rate: Option, #[n(12)] - pub protocol_version_major: Option, + pub protocol_version: Option, #[n(13)] - pub protocol_version_minor: Option, - #[n(14)] pub min_pool_cost: Option, - #[n(15)] + #[n(14)] pub ada_per_utxo_byte: Option, - #[n(16)] + #[n(15)] pub cost_models_for_script_languages: Option, - #[n(17)] + #[n(16)] pub execution_costs: Option, - #[n(18)] + #[n(17)] pub max_tx_ex_units: Option, - #[n(19)] + #[n(18)] pub max_block_ex_units: Option, - #[n(20)] + #[n(19)] pub max_value_size: Option, - #[n(21)] + #[n(20)] pub collateral_percentage: Option, - #[n(22)] + #[n(21)] pub max_collateral_inputs: Option, } @@ -201,19 +200,21 @@ pub struct StakeDistribution { #[derive(Debug, Encode, Decode, PartialEq, Clone)] pub struct Pool { #[n(0)] - pub stakes: Fraction, + pub stakes: RationalNumber, #[n(1)] pub hashes: Bytes, } +/// Type used at [GenesisConfig], which is a fraction that is CBOR-encoded +/// as an untagged array. #[derive(Debug, Encode, Decode, PartialEq, Clone)] pub struct Fraction { #[n(0)] pub num: u64, #[n(1)] - pub dem: u64, + pub den: u64, } pub type Addr = Bytes; @@ -356,7 +357,7 @@ pub struct Stakes { } #[derive(Debug, Encode, Decode, PartialEq)] -pub struct Genesis { +pub struct GenesisConfig { #[n(0)] pub system_start: SystemStart, @@ -509,7 +510,7 @@ pub async fn get_cbor( pub async fn get_genesis_config( client: &mut Client, era: u16, -) -> Result, ClientError> { +) -> Result, ClientError> { let query = BlockQuery::GetGenesisConfig; let query = LedgerQuery::BlockQuery(era, query); let query = Request::LedgerQuery(query); diff --git a/pallas-network/tests/protocols.rs b/pallas-network/tests/protocols.rs index e5ed0dc3..32e6987f 100644 --- a/pallas-network/tests/protocols.rs +++ b/pallas-network/tests/protocols.rs @@ -19,8 +19,8 @@ use pallas_network::{ }, }; use pallas_network::miniprotocols::localstate::queries_v16::{ - self, Addr, Addrs, ChainBlockNumber, Fraction, Genesis, Snapshots, Stakes, - SystemStart, UnitInterval, Value, StakeAddr, + self, Addr, Addrs, ChainBlockNumber, Fraction, GenesisConfig, Snapshots, Stakes, + SystemStart, UnitInterval, Value, StakeAddr, RationalNumber, }; use hex::FromHex; @@ -551,9 +551,9 @@ pub async fn local_state_query_server_and_client_happy_path() { ); assert_eq!(*server.statequery().state(), localstate::State::Querying); - let fraction = Fraction { num: 10, dem: 20 }; - let pool = queries_v16::Pool { - stakes: fraction.clone(), + let rational = RationalNumber { numerator: 10, denominator: 20 }; + let pool = localstate::queries_v16::Pool { + stakes: rational.clone(), hashes: b"pool1qv4qgv62s3ha74p0643nexee9zvcdydcyahqqnavhj90zheuykz" .to_vec() .into(), @@ -671,8 +671,7 @@ pub async fn local_state_query_server_and_client_happy_path() { numerator: 3, denominator: 1000000, }), - protocol_version_major: Some(5), - protocol_version_minor: Some(0), + protocol_version: Some((5,0)), min_pool_cost: Some(AnyUInt::U32(340000000)), ada_per_utxo_byte: Some(AnyUInt::U16(44)), cost_models_for_script_languages: None, @@ -751,7 +750,7 @@ pub async fn local_state_query_server_and_client_happy_path() { assert_eq!(*server.statequery().state(), localstate::State::Querying); - let genesis = vec![Genesis { + let genesis = vec![GenesisConfig { system_start: SystemStart { year: 2021, day_of_year: 150, @@ -759,7 +758,7 @@ pub async fn local_state_query_server_and_client_happy_path() { }, network_magic: 42, network_id: 42, - active_slots_coefficient: Fraction { num: 6, dem: 10 }, + active_slots_coefficient: Fraction { num: 6, den: 10 }, security_param: 2160, epoch_length: 432000, slots_per_kes_period: 129600, @@ -910,9 +909,9 @@ pub async fn local_state_query_server_and_client_happy_path() { .into_decode() .unwrap(); - let fraction = Fraction { num: 10, dem: 20 }; - let pool = queries_v16::Pool { - stakes: fraction.clone(), + let rational = RationalNumber { numerator: 10, denominator: 20 }; + let pool = localstate::queries_v16::Pool { + stakes: rational.clone(), hashes: b"pool1qv4qgv62s3ha74p0643nexee9zvcdydcyahqqnavhj90zheuykz" .to_vec() .into(), @@ -1024,8 +1023,7 @@ pub async fn local_state_query_server_and_client_happy_path() { numerator: 3, denominator: 1000000, }), - protocol_version_major: Some(5), - protocol_version_minor: Some(0), + protocol_version: Some((5,0)), min_pool_cost: Some(AnyUInt::U32(340000000)), ada_per_utxo_byte: Some(AnyUInt::U16(44)), cost_models_for_script_languages: None, @@ -1087,7 +1085,7 @@ pub async fn local_state_query_server_and_client_happy_path() { client.statequery().send_query(request).await.unwrap(); - let result: Vec = client + let result: Vec = client .statequery() .recv_while_querying() .await @@ -1095,7 +1093,7 @@ pub async fn local_state_query_server_and_client_happy_path() { .into_decode() .unwrap(); - let genesis = vec![Genesis { + let genesis = vec![GenesisConfig { system_start: SystemStart { year: 2021, day_of_year: 150, @@ -1103,7 +1101,7 @@ pub async fn local_state_query_server_and_client_happy_path() { }, network_magic: 42, network_id: 42, - active_slots_coefficient: Fraction { num: 6, dem: 10 }, + active_slots_coefficient: Fraction { num: 6, den: 10 }, security_param: 2160, epoch_length: 432000, slots_per_kes_period: 129600,