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

@ -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<i64>;
@ -169,26 +170,24 @@ pub struct ProtocolParam {
#[n(11)]
pub treasury_growth_rate: Option<UnitInterval>,
#[n(12)]
pub protocol_version_major: Option<ProtocolVersionMajor>,
pub protocol_version: Option<ProtocolVersion>,
#[n(13)]
pub protocol_version_minor: Option<ProtocolVersionMinor>,
#[n(14)]
pub min_pool_cost: Option<Coin>,
#[n(15)]
#[n(14)]
pub ada_per_utxo_byte: Option<Coin>,
#[n(16)]
#[n(15)]
pub cost_models_for_script_languages: Option<CostMdls>,
#[n(17)]
#[n(16)]
pub execution_costs: Option<ExUnitPrices>,
#[n(18)]
#[n(17)]
pub max_tx_ex_units: Option<ExUnits>,
#[n(19)]
#[n(18)]
pub max_block_ex_units: Option<ExUnits>,
#[n(20)]
#[n(19)]
pub max_value_size: Option<u32>,
#[n(21)]
#[n(20)]
pub collateral_percentage: Option<u32>,
#[n(22)]
#[n(21)]
pub max_collateral_inputs: Option<u32>,
}
@ -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<Vec<Genesis>, ClientError> {
) -> Result<Vec<GenesisConfig>, ClientError> {
let query = BlockQuery::GetGenesisConfig;
let query = LedgerQuery::BlockQuery(era, query);
let query = Request::LedgerQuery(query);

View file

@ -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<Genesis> = client
let result: Vec<GenesisConfig> = 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,