From 2d6b6fda1e1b3782e62f583388015cc601c7a564 Mon Sep 17 00:00:00 2001 From: Santiago Carmuega Date: Mon, 15 Apr 2024 21:53:33 -0300 Subject: [PATCH] chore(applying): prepare pparams for folding logic (#438) --- pallas-applying/src/utils/environment.rs | 244 +++++------------------ pallas-applying/tests/byron.rs | 10 + pallas-applying/tests/shelley_ma.rs | 17 ++ 3 files changed, 80 insertions(+), 191 deletions(-) diff --git a/pallas-applying/src/utils/environment.rs b/pallas-applying/src/utils/environment.rs index 246bb1b..39d7b0e 100644 --- a/pallas-applying/src/utils/environment.rs +++ b/pallas-applying/src/utils/environment.rs @@ -1,277 +1,139 @@ //! Types used for representing the environment required for validation in each //! era. -use pallas_codec::minicbor::{self, Decode, Encode}; use pallas_primitives::{ alonzo::{ - Coin, CostMdls, Epoch, ExUnitPrices, ExUnits, Nonce, ProtocolVersion, RationalNumber, - UnitInterval, + Coin, CostMdls, ExUnitPrices, ExUnits, Nonce, ProtocolVersion, RationalNumber, UnitInterval, }, babbage::CostMdls as BabbageCostMdls, }; -#[derive(Debug, Clone, Encode, Decode)] +#[derive(Debug, Clone)] #[non_exhaustive] pub enum MultiEraProtocolParameters { - #[n(0)] - Byron(#[n(1)] ByronProtParams), - - #[n(2)] - Shelley(#[n(3)] ShelleyProtParams), - - #[n(4)] - Alonzo(#[n(5)] AlonzoProtParams), - - #[n(6)] - Babbage(#[n(7)] BabbageProtParams), + Byron(ByronProtParams), + Shelley(ShelleyProtParams), + Alonzo(AlonzoProtParams), + Babbage(BabbageProtParams), } -#[derive(Debug, Clone, Encode, Decode)] +impl MultiEraProtocolParameters { + pub fn protocol_version(&self) -> usize { + match self { + MultiEraProtocolParameters::Byron(ByronProtParams { + block_version: (x, ..), + .. + }) => *x as usize, + MultiEraProtocolParameters::Shelley(ShelleyProtParams { + protocol_version: (x, ..), + .. + }) => *x as usize, + MultiEraProtocolParameters::Alonzo(AlonzoProtParams { + protocol_version: (x, ..), + .. + }) => *x as usize, + MultiEraProtocolParameters::Babbage(BabbageProtParams { + protocol_version: (x, ..), + .. + }) => *x as usize, + } + } +} + +#[derive(Debug, Clone)] pub struct ByronProtParams { - #[n(0)] + pub block_version: (u16, u16, u8), pub script_version: u16, - - #[n(1)] pub slot_duration: u64, - - #[n(2)] pub max_block_size: u64, - - #[n(3)] pub max_header_size: u64, - - #[n(4)] pub max_tx_size: u64, - - #[n(5)] pub max_proposal_size: u64, - - #[n(6)] pub mpc_thd: u64, - - #[n(7)] pub heavy_del_thd: u64, - - #[n(8)] pub update_vote_thd: u64, - - #[n(9)] pub update_proposal_thd: u64, - - #[n(10)] pub update_implicit: u64, - - #[n(11)] pub soft_fork_rule: (u64, u64, u64), - - #[n(12)] pub summand: u64, - - #[n(13)] pub multiplier: u64, - - #[n(14)] pub unlock_stake_epoch: u64, } -#[derive(Debug, Clone, Encode, Decode)] +#[derive(Debug, Clone)] pub struct ShelleyProtParams { - #[n(0)] pub minfee_a: u32, - - #[n(1)] pub minfee_b: u32, - - #[n(2)] pub max_block_body_size: u32, - - #[n(3)] pub max_transaction_size: u32, - - #[n(4)] pub max_block_header_size: u32, - - #[n(5)] pub key_deposit: Coin, - - #[n(6)] pub pool_deposit: Coin, - - #[n(7)] - pub maximum_epoch: Epoch, - - #[n(8)] pub desired_number_of_stake_pools: u32, - - #[n(9)] - pub pool_pledge_influence: RationalNumber, - - #[n(10)] - pub expansion_rate: UnitInterval, - - #[n(11)] - pub treasury_growth_rate: UnitInterval, - - #[n(12)] - pub decentralization_constant: UnitInterval, - - #[n(13)] - pub extra_entropy: Nonce, - - #[n(14)] pub protocol_version: ProtocolVersion, - - #[n(15)] pub min_utxo_value: Coin, + pub min_pool_cost: Coin, + pub expansion_rate: UnitInterval, + pub treasury_growth_rate: UnitInterval, + pub maximum_epoch: u32, + pub pool_pledge_influence: RationalNumber, + pub decentralization_constant: UnitInterval, + pub extra_entropy: Nonce, } -#[derive(Debug, Clone, Encode, Decode)] +#[derive(Debug, Clone)] pub struct AlonzoProtParams { - #[n(0)] pub minfee_a: u32, - - #[n(1)] pub minfee_b: u32, - - #[n(2)] pub max_block_body_size: u32, - - #[n(3)] pub max_transaction_size: u32, - - #[n(4)] pub max_block_header_size: u32, - - #[n(5)] pub key_deposit: Coin, - - #[n(6)] pub pool_deposit: Coin, - - #[n(7)] - pub maximum_epoch: Epoch, - - #[n(8)] pub desired_number_of_stake_pools: u32, - - #[n(9)] - pub pool_pledge_influence: RationalNumber, - - #[n(10)] - pub expansion_rate: UnitInterval, - - #[n(11)] - pub treasury_growth_rate: UnitInterval, - - #[n(12)] - pub decentralization_constant: UnitInterval, - - #[n(13)] - pub extra_entropy: Nonce, - - #[n(14)] pub protocol_version: ProtocolVersion, - - #[n(15)] pub min_pool_cost: Coin, - - #[n(16)] pub ada_per_utxo_byte: Coin, - - #[n(17)] pub cost_models_for_script_languages: CostMdls, - - #[n(18)] pub execution_costs: ExUnitPrices, - - #[n(19)] pub max_tx_ex_units: ExUnits, - - #[n(20)] pub max_block_ex_units: ExUnits, - - #[n(21)] pub max_value_size: u32, - - #[n(22)] pub collateral_percentage: u32, - - #[n(24)] pub max_collateral_inputs: u32, + pub expansion_rate: UnitInterval, + pub treasury_growth_rate: UnitInterval, + pub maximum_epoch: u32, + pub pool_pledge_influence: RationalNumber, + pub decentralization_constant: UnitInterval, + pub extra_entropy: Nonce, } -#[derive(Debug, Clone, Encode, Decode)] +#[derive(Debug, Clone)] pub struct BabbageProtParams { - #[n(0)] pub minfee_a: u32, - - #[n(1)] pub minfee_b: u32, - - #[n(2)] pub max_block_body_size: u32, - - #[n(3)] pub max_transaction_size: u32, - - #[n(4)] pub max_block_header_size: u32, - - #[n(5)] pub key_deposit: Coin, - - #[n(6)] pub pool_deposit: Coin, - - #[n(7)] - pub maximum_epoch: Epoch, - - #[n(8)] pub desired_number_of_stake_pools: u32, - - #[n(9)] - pub pool_pledge_influence: RationalNumber, - - #[n(10)] - pub expansion_rate: UnitInterval, - - #[n(11)] - pub treasury_growth_rate: UnitInterval, - - #[n(12)] - pub decentralization_constant: UnitInterval, - - #[n(13)] - pub extra_entropy: Nonce, - - #[n(14)] pub protocol_version: ProtocolVersion, - - #[n(15)] pub min_pool_cost: Coin, - - #[n(16)] pub ada_per_utxo_byte: Coin, - - #[n(17)] pub cost_models_for_script_languages: BabbageCostMdls, - - #[n(18)] pub execution_costs: ExUnitPrices, - - #[n(19)] pub max_tx_ex_units: ExUnits, - - #[n(20)] pub max_block_ex_units: ExUnits, - - #[n(21)] pub max_value_size: u32, - - #[n(22)] pub collateral_percentage: u32, - - #[n(24)] pub max_collateral_inputs: u32, + pub expansion_rate: UnitInterval, + pub treasury_growth_rate: UnitInterval, + pub maximum_epoch: u32, + pub pool_pledge_influence: RationalNumber, + pub decentralization_constant: UnitInterval, + pub extra_entropy: Nonce, } #[derive(Debug)] diff --git a/pallas-applying/tests/byron.rs b/pallas-applying/tests/byron.rs index fdcc205..782170e 100644 --- a/pallas-applying/tests/byron.rs +++ b/pallas-applying/tests/byron.rs @@ -39,6 +39,7 @@ mod byron_tests { ); let env: Environment = Environment { prot_params: MultiEraProtocolParameters::Byron(ByronProtParams { + block_version: (1, 0, 0), script_version: 0, slot_duration: 20000, max_block_size: 2000000, @@ -81,6 +82,7 @@ mod byron_tests { ); let env: Environment = Environment { prot_params: MultiEraProtocolParameters::Byron(ByronProtParams { + block_version: (1, 0, 0), script_version: 0, slot_duration: 20000, max_block_size: 2000000, @@ -131,6 +133,7 @@ mod byron_tests { let metx: MultiEraTx = MultiEraTx::from_byron(&mtxp); let env: Environment = Environment { prot_params: MultiEraProtocolParameters::Byron(ByronProtParams { + block_version: (1, 0, 0), script_version: 0, slot_duration: 20000, max_block_size: 2000000, @@ -184,6 +187,7 @@ mod byron_tests { ); let env: Environment = Environment { prot_params: MultiEraProtocolParameters::Byron(ByronProtParams { + block_version: (1, 0, 0), script_version: 0, slot_duration: 20000, max_block_size: 2000000, @@ -222,6 +226,7 @@ mod byron_tests { let utxos: UTxOs = UTxOs::new(); let env: Environment = Environment { prot_params: MultiEraProtocolParameters::Byron(ByronProtParams { + block_version: (1, 0, 0), script_version: 0, slot_duration: 20000, max_block_size: 2000000, @@ -281,6 +286,7 @@ mod byron_tests { ); let env: Environment = Environment { prot_params: MultiEraProtocolParameters::Byron(ByronProtParams { + block_version: (1, 0, 0), script_version: 0, slot_duration: 20000, max_block_size: 2000000, @@ -325,6 +331,7 @@ mod byron_tests { ); let env: Environment = Environment { prot_params: MultiEraProtocolParameters::Byron(ByronProtParams { + block_version: (1, 0, 0), script_version: 0, slot_duration: 20000, max_block_size: 2000000, @@ -369,6 +376,7 @@ mod byron_tests { ); let env: Environment = Environment { prot_params: MultiEraProtocolParameters::Byron(ByronProtParams { + block_version: (1, 0, 0), script_version: 0, slot_duration: 20000, max_block_size: 2000000, @@ -421,6 +429,7 @@ mod byron_tests { ); let env: Environment = Environment { prot_params: MultiEraProtocolParameters::Byron(ByronProtParams { + block_version: (1, 0, 0), script_version: 0, slot_duration: 20000, max_block_size: 2000000, @@ -482,6 +491,7 @@ mod byron_tests { ); let env: Environment = Environment { prot_params: MultiEraProtocolParameters::Byron(ByronProtParams { + block_version: (1, 0, 0), script_version: 0, slot_duration: 20000, max_block_size: 2000000, diff --git a/pallas-applying/tests/shelley_ma.rs b/pallas-applying/tests/shelley_ma.rs index a4ea1b9..baaf793 100644 --- a/pallas-applying/tests/shelley_ma.rs +++ b/pallas-applying/tests/shelley_ma.rs @@ -77,6 +77,7 @@ mod shelley_ma_tests { }, protocol_version: (0, 2), min_utxo_value: 1000000, + min_pool_cost: 340000000, }), prot_magic: 764824073, block_slot: 5281340, @@ -139,6 +140,7 @@ mod shelley_ma_tests { }, protocol_version: (0, 2), min_utxo_value: 1000000, + min_pool_cost: 340000000, }), prot_magic: 764824073, block_slot: 17584925, @@ -201,6 +203,7 @@ mod shelley_ma_tests { }, protocol_version: (0, 2), min_utxo_value: 1000000, + min_pool_cost: 340000000, }), prot_magic: 764824073, block_slot: 5860488, @@ -263,6 +266,7 @@ mod shelley_ma_tests { }, protocol_version: (0, 2), min_utxo_value: 1000000, + min_pool_cost: 340000000, }), prot_magic: 764824073, block_slot: 24381863, @@ -334,6 +338,7 @@ mod shelley_ma_tests { }, protocol_version: (0, 2), min_utxo_value: 1000000, + min_pool_cost: 340000000, }), prot_magic: 764824073, block_slot: 5281340, @@ -391,6 +396,7 @@ mod shelley_ma_tests { }, protocol_version: (0, 2), min_utxo_value: 1000000, + min_pool_cost: 340000000, }), prot_magic: 764824073, block_slot: 5281340, @@ -464,6 +470,7 @@ mod shelley_ma_tests { }, protocol_version: (0, 2), min_utxo_value: 1000000, + min_pool_cost: 340000000, }), prot_magic: 764824073, block_slot: 5281340, @@ -528,6 +535,7 @@ mod shelley_ma_tests { }, protocol_version: (0, 2), min_utxo_value: 1000000, + min_pool_cost: 340000000, }), prot_magic: 764824073, block_slot: 9999999, @@ -592,6 +600,7 @@ mod shelley_ma_tests { }, protocol_version: (0, 2), min_utxo_value: 1000000, + min_pool_cost: 340000000, }), prot_magic: 764824073, block_slot: 5281340, @@ -657,6 +666,7 @@ mod shelley_ma_tests { }, protocol_version: (0, 2), min_utxo_value: 10000000000000, + min_pool_cost: 340000000, }), prot_magic: 764824073, block_slot: 5281340, @@ -731,6 +741,7 @@ mod shelley_ma_tests { }, protocol_version: (0, 2), min_utxo_value: 1000000, + min_pool_cost: 340000000, }), prot_magic: 764824073, block_slot: 5281340, @@ -795,6 +806,7 @@ mod shelley_ma_tests { }, protocol_version: (0, 2), min_utxo_value: 1000000, + min_pool_cost: 340000000, }), prot_magic: 764824073, block_slot: 5281340, @@ -882,6 +894,7 @@ mod shelley_ma_tests { }, protocol_version: (0, 2), min_utxo_value: 1000000, + min_pool_cost: 340000000, }), prot_magic: 764824073, block_slot: 5281340, @@ -957,6 +970,7 @@ mod shelley_ma_tests { }, protocol_version: (0, 2), min_utxo_value: 1000000, + min_pool_cost: 340000000, }), prot_magic: 764824073, block_slot: 5860488, @@ -1025,6 +1039,7 @@ mod shelley_ma_tests { }, protocol_version: (0, 2), min_utxo_value: 1000000, + min_pool_cost: 340000000, }), prot_magic: 764824073, block_slot: 5281340, @@ -1106,6 +1121,7 @@ mod shelley_ma_tests { }, protocol_version: (0, 2), min_utxo_value: 1000000, + min_pool_cost: 340000000, }), prot_magic: 764824073, block_slot: 5281340, @@ -1182,6 +1198,7 @@ mod shelley_ma_tests { }, protocol_version: (0, 2), min_utxo_value: 1000000, + min_pool_cost: 340000000, }), prot_magic: 764824073, block_slot: 5281340,