fix(network): adjust PoolDistr & ProtocolParam structs used for state queries (#551)

Signed-off-by: Pedro Sánchez Terraf <sterraf@users.noreply.github.com>
This commit is contained in:
Pedro Sánchez Terraf 2024-12-14 16:32:12 -03:00 committed by GitHub
parent 227b5781a9
commit 9747be3095
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 33 additions and 35 deletions

View file

@ -14,7 +14,6 @@ use pallas::{
crypto::hash::Hash, crypto::hash::Hash,
}; };
use tracing::info; use tracing::info;
use hex::FromHex;
async fn do_localstate_query(client: &mut NodeClient) { async fn do_localstate_query(client: &mut NodeClient) {
let client = client.statequery(); let client = client.statequery();
@ -114,8 +113,8 @@ async fn do_localstate_query(client: &mut NodeClient) {
async fn do_chainsync(client: &mut NodeClient) { async fn do_chainsync(client: &mut NodeClient) {
let known_points = vec![Point::Specific( let known_points = vec![Point::Specific(
43847831u64, 77110778u64,
hex::decode("15b9eeee849dd6386d3770b0745e0450190f7560e5159b1b3ab13b14b2684a45").unwrap(), hex::decode("18e6eeaa592c42113280ba47a0829355e6bed1c9ce67cce4be502d6031d0679a").unwrap(),
)]; )];
let (point, _) = client let (point, _) = client

View file

@ -111,6 +111,7 @@ pub type PositiveInterval = RationalNumber;
pub type ProtocolVersionMajor = u64; pub type ProtocolVersionMajor = u64;
pub type ProtocolVersionMinor = u64; pub type ProtocolVersionMinor = u64;
pub type ProtocolVersion = (ProtocolVersionMajor, ProtocolVersionMinor);
pub type CostModel = Vec<i64>; pub type CostModel = Vec<i64>;
@ -169,26 +170,24 @@ pub struct ProtocolParam {
#[n(11)] #[n(11)]
pub treasury_growth_rate: Option<UnitInterval>, pub treasury_growth_rate: Option<UnitInterval>,
#[n(12)] #[n(12)]
pub protocol_version_major: Option<ProtocolVersionMajor>, pub protocol_version: Option<ProtocolVersion>,
#[n(13)] #[n(13)]
pub protocol_version_minor: Option<ProtocolVersionMinor>,
#[n(14)]
pub min_pool_cost: Option<Coin>, pub min_pool_cost: Option<Coin>,
#[n(15)] #[n(14)]
pub ada_per_utxo_byte: Option<Coin>, pub ada_per_utxo_byte: Option<Coin>,
#[n(16)] #[n(15)]
pub cost_models_for_script_languages: Option<CostMdls>, pub cost_models_for_script_languages: Option<CostMdls>,
#[n(17)] #[n(16)]
pub execution_costs: Option<ExUnitPrices>, pub execution_costs: Option<ExUnitPrices>,
#[n(18)] #[n(17)]
pub max_tx_ex_units: Option<ExUnits>, pub max_tx_ex_units: Option<ExUnits>,
#[n(19)] #[n(18)]
pub max_block_ex_units: Option<ExUnits>, pub max_block_ex_units: Option<ExUnits>,
#[n(20)] #[n(19)]
pub max_value_size: Option<u32>, pub max_value_size: Option<u32>,
#[n(21)] #[n(20)]
pub collateral_percentage: Option<u32>, pub collateral_percentage: Option<u32>,
#[n(22)] #[n(21)]
pub max_collateral_inputs: Option<u32>, pub max_collateral_inputs: Option<u32>,
} }
@ -201,19 +200,21 @@ pub struct StakeDistribution {
#[derive(Debug, Encode, Decode, PartialEq, Clone)] #[derive(Debug, Encode, Decode, PartialEq, Clone)]
pub struct Pool { pub struct Pool {
#[n(0)] #[n(0)]
pub stakes: Fraction, pub stakes: RationalNumber,
#[n(1)] #[n(1)]
pub hashes: Bytes, 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)] #[derive(Debug, Encode, Decode, PartialEq, Clone)]
pub struct Fraction { pub struct Fraction {
#[n(0)] #[n(0)]
pub num: u64, pub num: u64,
#[n(1)] #[n(1)]
pub dem: u64, pub den: u64,
} }
pub type Addr = Bytes; pub type Addr = Bytes;
@ -356,7 +357,7 @@ pub struct Stakes {
} }
#[derive(Debug, Encode, Decode, PartialEq)] #[derive(Debug, Encode, Decode, PartialEq)]
pub struct Genesis { pub struct GenesisConfig {
#[n(0)] #[n(0)]
pub system_start: SystemStart, pub system_start: SystemStart,
@ -509,7 +510,7 @@ pub async fn get_cbor(
pub async fn get_genesis_config( pub async fn get_genesis_config(
client: &mut Client, client: &mut Client,
era: u16, era: u16,
) -> Result<Vec<Genesis>, ClientError> { ) -> Result<Vec<GenesisConfig>, ClientError> {
let query = BlockQuery::GetGenesisConfig; let query = BlockQuery::GetGenesisConfig;
let query = LedgerQuery::BlockQuery(era, query); let query = LedgerQuery::BlockQuery(era, query);
let query = Request::LedgerQuery(query); let query = Request::LedgerQuery(query);

View file

@ -19,8 +19,8 @@ use pallas_network::{
}, },
}; };
use pallas_network::miniprotocols::localstate::queries_v16::{ use pallas_network::miniprotocols::localstate::queries_v16::{
self, Addr, Addrs, ChainBlockNumber, Fraction, Genesis, Snapshots, Stakes, self, Addr, Addrs, ChainBlockNumber, Fraction, GenesisConfig, Snapshots, Stakes,
SystemStart, UnitInterval, Value, StakeAddr, SystemStart, UnitInterval, Value, StakeAddr, RationalNumber,
}; };
use hex::FromHex; 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); assert_eq!(*server.statequery().state(), localstate::State::Querying);
let fraction = Fraction { num: 10, dem: 20 }; let rational = RationalNumber { numerator: 10, denominator: 20 };
let pool = queries_v16::Pool { let pool = localstate::queries_v16::Pool {
stakes: fraction.clone(), stakes: rational.clone(),
hashes: b"pool1qv4qgv62s3ha74p0643nexee9zvcdydcyahqqnavhj90zheuykz" hashes: b"pool1qv4qgv62s3ha74p0643nexee9zvcdydcyahqqnavhj90zheuykz"
.to_vec() .to_vec()
.into(), .into(),
@ -671,8 +671,7 @@ pub async fn local_state_query_server_and_client_happy_path() {
numerator: 3, numerator: 3,
denominator: 1000000, denominator: 1000000,
}), }),
protocol_version_major: Some(5), protocol_version: Some((5,0)),
protocol_version_minor: Some(0),
min_pool_cost: Some(AnyUInt::U32(340000000)), min_pool_cost: Some(AnyUInt::U32(340000000)),
ada_per_utxo_byte: Some(AnyUInt::U16(44)), ada_per_utxo_byte: Some(AnyUInt::U16(44)),
cost_models_for_script_languages: None, 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); assert_eq!(*server.statequery().state(), localstate::State::Querying);
let genesis = vec![Genesis { let genesis = vec![GenesisConfig {
system_start: SystemStart { system_start: SystemStart {
year: 2021, year: 2021,
day_of_year: 150, day_of_year: 150,
@ -759,7 +758,7 @@ pub async fn local_state_query_server_and_client_happy_path() {
}, },
network_magic: 42, network_magic: 42,
network_id: 42, network_id: 42,
active_slots_coefficient: Fraction { num: 6, dem: 10 }, active_slots_coefficient: Fraction { num: 6, den: 10 },
security_param: 2160, security_param: 2160,
epoch_length: 432000, epoch_length: 432000,
slots_per_kes_period: 129600, slots_per_kes_period: 129600,
@ -910,9 +909,9 @@ pub async fn local_state_query_server_and_client_happy_path() {
.into_decode() .into_decode()
.unwrap(); .unwrap();
let fraction = Fraction { num: 10, dem: 20 }; let rational = RationalNumber { numerator: 10, denominator: 20 };
let pool = queries_v16::Pool { let pool = localstate::queries_v16::Pool {
stakes: fraction.clone(), stakes: rational.clone(),
hashes: b"pool1qv4qgv62s3ha74p0643nexee9zvcdydcyahqqnavhj90zheuykz" hashes: b"pool1qv4qgv62s3ha74p0643nexee9zvcdydcyahqqnavhj90zheuykz"
.to_vec() .to_vec()
.into(), .into(),
@ -1024,8 +1023,7 @@ pub async fn local_state_query_server_and_client_happy_path() {
numerator: 3, numerator: 3,
denominator: 1000000, denominator: 1000000,
}), }),
protocol_version_major: Some(5), protocol_version: Some((5,0)),
protocol_version_minor: Some(0),
min_pool_cost: Some(AnyUInt::U32(340000000)), min_pool_cost: Some(AnyUInt::U32(340000000)),
ada_per_utxo_byte: Some(AnyUInt::U16(44)), ada_per_utxo_byte: Some(AnyUInt::U16(44)),
cost_models_for_script_languages: None, 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(); client.statequery().send_query(request).await.unwrap();
let result: Vec<Genesis> = client let result: Vec<GenesisConfig> = client
.statequery() .statequery()
.recv_while_querying() .recv_while_querying()
.await .await
@ -1095,7 +1093,7 @@ pub async fn local_state_query_server_and_client_happy_path() {
.into_decode() .into_decode()
.unwrap(); .unwrap();
let genesis = vec![Genesis { let genesis = vec![GenesisConfig {
system_start: SystemStart { system_start: SystemStart {
year: 2021, year: 2021,
day_of_year: 150, day_of_year: 150,
@ -1103,7 +1101,7 @@ pub async fn local_state_query_server_and_client_happy_path() {
}, },
network_magic: 42, network_magic: 42,
network_id: 42, network_id: 42,
active_slots_coefficient: Fraction { num: 6, dem: 10 }, active_slots_coefficient: Fraction { num: 6, den: 10 },
security_param: 2160, security_param: 2160,
epoch_length: 432000, epoch_length: 432000,
slots_per_kes_period: 129600, slots_per_kes_period: 129600,