From 7b84762b5a766c0c097088fee0ea50bf61c193f2 Mon Sep 17 00:00:00 2001 From: Dmitry Murzin Date: Thu, 12 Sep 2024 10:53:56 +0300 Subject: [PATCH] fix: Fix `iroha_genesis` compilation without `transparent_api` feature (#5056) Signed-off-by: Dmitry Murzin --- crates/iroha/tests/integration/pagination.rs | 2 +- .../tests/integration/status_response.rs | 2 +- crates/iroha_data_model/src/parameter.rs | 35 ++++++++++++++++++ crates/iroha_genesis/src/lib.rs | 36 +------------------ 4 files changed, 38 insertions(+), 37 deletions(-) diff --git a/crates/iroha/tests/integration/pagination.rs b/crates/iroha/tests/integration/pagination.rs index 97415ca55ed..1c0e81ae97e 100644 --- a/crates/iroha/tests/integration/pagination.rs +++ b/crates/iroha/tests/integration/pagination.rs @@ -26,7 +26,7 @@ fn limits_should_work() -> Result<()> { #[test] fn reported_length_should_be_accurate() -> Result<()> { - let (_rt, _peer, client) = ::new().with_port(11_170).start_with_runtime(); + let (_rt, _peer, client) = ::new().with_port(11_200).start_with_runtime(); wait_for_genesis_committed(&vec![client.clone()], 0); register_assets(&client)?; diff --git a/crates/iroha/tests/integration/status_response.rs b/crates/iroha/tests/integration/status_response.rs index 5b59691cbf3..17b6c9dd734 100644 --- a/crates/iroha/tests/integration/status_response.rs +++ b/crates/iroha/tests/integration/status_response.rs @@ -14,7 +14,7 @@ fn status_eq_excluding_uptime_and_queue(lhs: &Status, rhs: &Status) -> bool { #[test] fn json_and_scale_statuses_equality() -> Result<()> { - let (_rt, network, client) = Network::start_test_with_runtime(2, Some(11_200)); + let (_rt, network, client) = Network::start_test_with_runtime(2, Some(11_280)); wait_for_genesis_committed(&network.clients(), 0); let json_status_zero = get_status_json(&client).unwrap(); diff --git a/crates/iroha_data_model/src/parameter.rs b/crates/iroha_data_model/src/parameter.rs index 66e1fd4f9b3..ec60939a2b2 100644 --- a/crates/iroha_data_model/src/parameter.rs +++ b/crates/iroha_data_model/src/parameter.rs @@ -458,6 +458,41 @@ impl Parameters { ) .chain(self.custom.values().cloned().map(Parameter::Custom)) } + + /// Set `parameter` value to corresponding parameter in `self` + pub fn set_parameter(&mut self, parameter: Parameter) { + macro_rules! apply_parameter { + ($($container:ident($param:ident.$field:ident) => $single:ident::$variant:ident),* $(,)?) => { + match parameter { + $( + Parameter::$container($single::$variant(next)) => { + self.$param.$field = next; + } + )* + Parameter::Custom(next) => { + self.custom.insert(next.id.clone(), next); + } + } + }; + } + + apply_parameter!( + Sumeragi(sumeragi.max_clock_drift_ms) => SumeragiParameter::MaxClockDriftMs, + Sumeragi(sumeragi.block_time_ms) => SumeragiParameter::BlockTimeMs, + Sumeragi(sumeragi.commit_time_ms) => SumeragiParameter::CommitTimeMs, + + Block(block.max_transactions) => BlockParameter::MaxTransactions, + + Transaction(transaction.max_instructions) => TransactionParameter::MaxInstructions, + Transaction(transaction.smart_contract_size) => TransactionParameter::SmartContractSize, + + SmartContract(smart_contract.fuel) => SmartContractParameter::Fuel, + SmartContract(smart_contract.memory) => SmartContractParameter::Memory, + + Executor(executor.fuel) => SmartContractParameter::Fuel, + Executor(executor.memory) => SmartContractParameter::Memory, + ); + } } impl SumeragiParameters { diff --git a/crates/iroha_genesis/src/lib.rs b/crates/iroha_genesis/src/lib.rs index db891b3dee3..1bd448168a5 100644 --- a/crates/iroha_genesis/src/lib.rs +++ b/crates/iroha_genesis/src/lib.rs @@ -334,45 +334,11 @@ fn convert_parameters(parameters: Vec) -> Option { } let mut result = Parameters::default(); for parameter in parameters { - apply_parameter(&mut result, parameter); + result.set_parameter(parameter); } Some(result) } -fn apply_parameter(parameters: &mut Parameters, parameter: Parameter) { - macro_rules! apply_parameter { - ($($container:ident($param:ident.$field:ident) => $single:ident::$variant:ident),* $(,)?) => { - match parameter { - $( - Parameter::$container(iroha_data_model::parameter::$single::$variant(next)) => { - parameters.$param.$field = next; - } - )* - Parameter::Custom(next) => { - parameters.custom.insert(next.id.clone(), next); - } - } - }; - } - - apply_parameter!( - Sumeragi(sumeragi.max_clock_drift_ms) => SumeragiParameter::MaxClockDriftMs, - Sumeragi(sumeragi.block_time_ms) => SumeragiParameter::BlockTimeMs, - Sumeragi(sumeragi.commit_time_ms) => SumeragiParameter::CommitTimeMs, - - Block(block.max_transactions) => BlockParameter::MaxTransactions, - - Transaction(transaction.max_instructions) => TransactionParameter::MaxInstructions, - Transaction(transaction.smart_contract_size) => TransactionParameter::SmartContractSize, - - SmartContract(smart_contract.fuel) => SmartContractParameter::Fuel, - SmartContract(smart_contract.memory) => SmartContractParameter::Memory, - - Executor(executor.fuel) => SmartContractParameter::Fuel, - Executor(executor.memory) => SmartContractParameter::Memory, - ); -} - impl Encode for ExecutorPath { fn encode(&self) -> Vec { self.0