From 6bc3c4bbdd413e63d614acf638538b6e9a733b29 Mon Sep 17 00:00:00 2001 From: Eugene Gostkin Date: Wed, 26 Apr 2023 18:15:15 +0200 Subject: [PATCH] Config improvements (#7) * Config improvements * Fmt fix --- Cargo.toml | 4 +- configs/run_benchmark.yml | 20 +++++++- examples/run_benchmark.rs | 98 ++++++++++++++++++++++++++++----------- 3 files changed, 91 insertions(+), 31 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1454095..4ddd1dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,8 +7,8 @@ edition = "2021" [dependencies] entity = { git = "https://github.com/dcSpark/carp.git", rev = "75bf44f6aad4fb53afdaab39956e66c2b3a09922" } -dcspark-core = { git = "https://github.com/dcSpark/dcspark-core.git", rev = "d5550993296340e7385f6035cc80d56e8398b3f7" } -utxo-selection = { git = "https://github.com/dcSpark/dcspark-core.git", rev = "d5550993296340e7385f6035cc80d56e8398b3f7" } +dcspark-core = { git = "https://github.com/dcSpark/dcspark-core.git", rev = "33d9c950d0f1a3abe4e08f3fafee60b1317877a6" } +utxo-selection = { git = "https://github.com/dcSpark/dcspark-core.git", rev = "33d9c950d0f1a3abe4e08f3fafee60b1317877a6" } anyhow = "1.0.53" itertools = "0.10.5" diff --git a/configs/run_benchmark.yml b/configs/run_benchmark.yml index 6e6ce6b..b9886cb 100644 --- a/configs/run_benchmark.yml +++ b/configs/run_benchmark.yml @@ -18,10 +18,28 @@ fee_estimator: type: thermostat network: mainnet plan_path: "events/milkomeda_events/multisig.script" + coins_per_utxo_byte: "4310" + #fee_estimator: # type: cml_estimator # magic: "mainnet.cardano-evm.c1" -# plan_path: "events/milkomeda_events/multisig.script" +# config: +# type: native_script +# plan: "events/milkomeda_events/multisig.script" +# parameters: +# coefficient: "44" +# constant: "155381" +# pool_deposit: "500000000" +# key_deposit: "2000000" +# max_value_size: 5000 +# max_tx_size: 16384 +# coins_per_utxo_byte: "4310" +# ex_unit_mem_price_numerator: "577" +# ex_unit_mem_price_denominator: "10000" +# ex_unit_step_price_numerator: "721" +# ex_unit_step_price_denominator: "10000000" +# collateral_percentage: 150 +# max_collateral_inputs: 3 mapper: type: cml_mapper diff --git a/examples/run_benchmark.rs b/examples/run_benchmark.rs index 27c1f8e..4983fec 100644 --- a/examples/run_benchmark.rs +++ b/examples/run_benchmark.rs @@ -82,13 +82,33 @@ pub enum FeeEstimatorConfig { Thermostat { network: NetworkInfo, plan_path: PathBuf, + coins_per_utxo_byte: BigNum, }, CmlEstimator { config: CardanoCmlEstimatorConfig, + parameters: CardanoNetworkParameters, magic: Option, }, } +#[derive(Debug, Clone, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct CardanoNetworkParameters { + coefficient: BigNum, + constant: BigNum, + pool_deposit: BigNum, + key_deposit: BigNum, + max_value_size: u32, + max_tx_size: u32, + coins_per_utxo_byte: BigNum, + ex_unit_mem_price_numerator: BigNum, + ex_unit_mem_price_denominator: BigNum, + ex_unit_step_price_numerator: BigNum, + ex_unit_step_price_denominator: BigNum, + collateral_percentage: u32, + max_collateral_inputs: u32, +} + #[derive(Debug, Clone, Deserialize)] #[serde(tag = "type", rename_all = "snake_case")] #[serde(deny_unknown_fields)] @@ -191,53 +211,70 @@ pub fn parse_estimator_creator< change_algo: ChangeAlgo, ) -> anyhow::Result<()> { match main_config.fee_estimator.clone() { - FeeEstimatorConfig::Thermostat { network, plan_path } => { + FeeEstimatorConfig::Thermostat { + network, + plan_path, + coins_per_utxo_byte, + } => { let plan = MultisigPlan::load(plan_path)?; parse_mapper(main_config, algo, change_algo, || { - Ok(ThermostatFeeEstimator::new(network.clone(), &plan)) + Ok(ThermostatFeeEstimator::new( + network.clone(), + &plan, + coins_per_utxo_byte, + )) }) } - FeeEstimatorConfig::CmlEstimator { config, magic } => { - let credentials = match config { + FeeEstimatorConfig::CmlEstimator { + config, + parameters, + magic, + } => { + let (credentials, require_calculation) = match config { CardanoCmlEstimatorConfig::PlutusScript { .. } => { todo!("not implemented") } - CardanoCmlEstimatorConfig::PaymentKey => CardanoPaymentCredentials::PaymentKey, + CardanoCmlEstimatorConfig::PaymentKey => { + (CardanoPaymentCredentials::PaymentKey, false) + } CardanoCmlEstimatorConfig::NativeScript { plan } => { let plan = MultisigPlan::load(plan)?; - CardanoPaymentCredentials::NativeScript { - native_script: plan.to_script().get(0), - witness_info: NativeScriptWitnessInfo::num_signatures(plan.quorum as usize), - } + ( + CardanoPaymentCredentials::NativeScript { + native_script: plan.to_script().get(0), + witness_info: NativeScriptWitnessInfo::num_signatures( + plan.quorum as usize, + ), + }, + false, + ) } }; parse_mapper(main_config, algo, change_algo, || { - // TODO: make this configurable - let coefficient = BigNum::from_str("44").unwrap(); - let constant = BigNum::from_str("155381").unwrap(); - let linear_fee = LinearFee::new(&coefficient, &constant); - let pool_deposit = BigNum::from_str("500000000").unwrap(); - let key_deposit = BigNum::from_str("2000000").unwrap(); - let max_value_size = 5000; - let max_tx_size = 16384; - let coins_per_utxo_byte = BigNum::from_str("4310").unwrap(); + let linear_fee = LinearFee::new(¶meters.coefficient, ¶meters.constant); let mut builder = cardano_multiplatform_lib::builders::tx_builder::TransactionBuilder::new( &TransactionBuilderConfigBuilder::new() .fee_algo(&linear_fee) - .pool_deposit(&pool_deposit) - .key_deposit(&key_deposit) - .max_value_size(max_value_size) - .max_tx_size(max_tx_size) - .coins_per_utxo_byte(&coins_per_utxo_byte) + .pool_deposit(¶meters.pool_deposit) + .key_deposit(¶meters.key_deposit) + .max_value_size(parameters.max_value_size) + .max_tx_size(parameters.max_tx_size) + .coins_per_utxo_byte(¶meters.coins_per_utxo_byte) .ex_unit_prices(&ExUnitPrices::new( - &UnitInterval::new(&BigNum::zero(), &BigNum::zero()), - &UnitInterval::new(&BigNum::zero(), &BigNum::zero()), + &UnitInterval::new( + ¶meters.ex_unit_mem_price_numerator, + ¶meters.ex_unit_mem_price_denominator, + ), + &UnitInterval::new( + ¶meters.ex_unit_step_price_numerator, + ¶meters.ex_unit_step_price_denominator, + ), )) - .collateral_percentage(0) - .max_collateral_inputs(0) + .collateral_percentage(parameters.collateral_percentage) + .max_collateral_inputs(parameters.max_collateral_inputs) .build() .map_err(|err| anyhow!("can't build tx builder: {}", err))?, ); @@ -260,7 +297,12 @@ pub fn parse_estimator_creator< builder.set_auxiliary_data(&auxiliary_data); } - CmlFeeEstimator::new(builder, credentials.clone(), true) + CmlFeeEstimator::new( + builder, + credentials.clone(), + require_calculation, + parameters.coins_per_utxo_byte, + ) }) } }