From 42347250e94a318e873346305ed5bf69dc9ddd97 Mon Sep 17 00:00:00 2001 From: 0x009922 <43530070+0x009922@users.noreply.github.com> Date: Thu, 30 May 2024 11:50:20 +0900 Subject: [PATCH] refactor!: revert `_ms` and `_bytes` suffixes in config Signed-off-by: 0x009922 <43530070+0x009922@users.noreply.github.com> --- cli/src/samples.rs | 2 +- client/src/config.rs | 4 +- client/src/config/user.rs | 10 ++-- config/base/src/util.rs | 21 ++++----- config/src/parameters/actual.rs | 3 +- config/src/parameters/defaults.rs | 9 ++-- config/src/parameters/user.rs | 70 ++++++++++++++-------------- config/tests/fixtures.rs | 2 +- config/tests/fixtures/full.toml | 21 +++++---- configs/client.template.toml | 4 +- configs/peer.template.toml | 21 +++++---- core/src/snapshot.rs | 2 +- tools/kagami/src/genesis/generate.rs | 4 +- 13 files changed, 89 insertions(+), 84 deletions(-) diff --git a/cli/src/samples.rs b/cli/src/samples.rs index 8c5a2ba1698..24313644aa8 100644 --- a/cli/src/samples.rs +++ b/cli/src/samples.rs @@ -68,7 +68,7 @@ pub fn get_config_toml( .write("private_key", ExposedPrivateKey(private_key)) .write(["sumeragi", "trusted_peers"], peers) .write(["network", "address"], DEFAULT_P2P_ADDR) - .write(["network", "block_gossip_period"], 500) + .write(["network", "block_gossip_period_ms"], 500) .write(["network", "block_gossip_max_size"], 1) .write(["torii", "address"], DEFAULT_TORII_ADDR) .write(["chain_wide", "max_transactions_in_block"], 2) diff --git a/client/src/config.rs b/client/src/config.rs index 316434da4a2..5e22e207e64 100644 --- a/client/src/config.rs +++ b/client/src/config.rs @@ -121,8 +121,8 @@ mod tests { private_key = "802640CCF31D85E3B32A4BEA59987CE0C78E3B8E2DB93881468AB2435FE45D5C9DCD53CE7FA46C9DCE7EA4B125E2E36BDB63EA33073E7590AC92816AE1E861B7048B03" [transaction] - time_to_live = 100_000 - status_timeout = 100_000 + time_to_live_ms = 100_000 + status_timeout_ms = 100_000 nonce = false } } diff --git a/client/src/config/user.rs b/client/src/config/user.rs index 7ea7b1f066c..14aa85c4a35 100644 --- a/client/src/config/user.rs +++ b/client/src/config/user.rs @@ -3,7 +3,7 @@ use error_stack::{Report, ResultExt}; use iroha_config_base::{ attach::ConfigValueAndOrigin, - util::{Emitter, EmitterResultExt, HumanDuration}, + util::{DurationMs, Emitter, EmitterResultExt}, ReadConfig, WithOrigin, }; use iroha_crypto::{KeyPair, PrivateKey, PublicKey}; @@ -55,8 +55,8 @@ impl Root { }, transaction: Transaction { - time_to_live: tx_ttl, - status_timeout: tx_timeout, + time_to_live_ms: tx_ttl, + status_timeout_ms: tx_timeout, nonce: tx_add_nonce, }, } = self; @@ -122,9 +122,9 @@ pub struct Account { #[allow(missing_docs)] pub struct Transaction { #[config(default = "super::DEFAULT_TRANSACTION_TIME_TO_LIVE.into()")] - pub time_to_live: WithOrigin, + pub time_to_live_ms: WithOrigin, #[config(default = "super::DEFAULT_TRANSACTION_STATUS_TIMEOUT.into()")] - pub status_timeout: WithOrigin, + pub status_timeout_ms: WithOrigin, #[config(default = "super::DEFAULT_TRANSACTION_NONCE")] pub nonce: bool, } diff --git a/config/base/src/util.rs b/config/base/src/util.rs index 33d82985c55..956b8245eae 100644 --- a/config/base/src/util.rs +++ b/config/base/src/util.rs @@ -7,38 +7,37 @@ use drop_bomb::DropBomb; use error_stack::Report; use serde::{Deserialize, Serialize}; -/// [`Duration`], but can parse a human-readable string. -/// TODO: currently deserializes just as [`Duration`] +/// (De-)serialize [`Duration`] as a number of milliseconds #[serde_with::serde_as] #[derive(Debug, Copy, Clone, Deserialize, Serialize, Ord, PartialOrd, Eq, PartialEq, Display)] #[display(fmt = "{_0:?}")] -pub struct HumanDuration(#[serde_as(as = "serde_with::DurationMilliSeconds")] pub Duration); +pub struct DurationMs(#[serde_as(as = "serde_with::DurationMilliSeconds")] pub Duration); -impl HumanDuration { +impl DurationMs { /// Get the [`Duration`] pub fn get(self) -> Duration { self.0 } } -impl From for HumanDuration { +impl From for DurationMs { fn from(value: Duration) -> Self { Self(value) } } -/// Representation of number of bytes, parseable from a human-readable string. +/// A number of bytes #[derive(Debug, Copy, Clone, Deserialize, Serialize)] -pub struct HumanBytes(pub T); +pub struct Bytes(pub T); -impl HumanBytes { +impl Bytes { /// Get the number of bytes pub fn get(self) -> T { self.0 } } -impl From for HumanBytes { +impl From for Bytes { fn from(value: T) -> Self { Self(value) } @@ -238,10 +237,10 @@ mod tests { } #[test] - fn deserialize_human_duration() { + fn deserialize_duration_ms() { #[derive(Deserialize)] struct Test { - value: HumanDuration, + value: DurationMs, } let Test { value } = toml::toml! { diff --git a/config/src/parameters/actual.rs b/config/src/parameters/actual.rs index 893a77592ab..e10f6136a11 100644 --- a/config/src/parameters/actual.rs +++ b/config/src/parameters/actual.rs @@ -232,7 +232,6 @@ impl Default for ChainWide { #[derive(Debug, Clone, Copy, Serialize, Deserialize)] pub struct WasmRuntime { pub fuel_limit: u64, - // TODO: wrap into a `Bytes` newtype pub max_memory_bytes: u32, } @@ -240,7 +239,7 @@ impl Default for WasmRuntime { fn default() -> Self { Self { fuel_limit: defaults::chain_wide::WASM_FUEL_LIMIT, - max_memory_bytes: defaults::chain_wide::WASM_MAX_MEMORY_BYTES, + max_memory_bytes: defaults::chain_wide::WASM_MAX_MEMORY.get(), } } } diff --git a/config/src/parameters/defaults.rs b/config/src/parameters/defaults.rs index 59f86625c8c..a9da81e7851 100644 --- a/config/src/parameters/defaults.rs +++ b/config/src/parameters/defaults.rs @@ -46,14 +46,15 @@ pub mod snapshot { } pub mod chain_wide { + use iroha_config_base::util::Bytes; + use super::*; pub const MAX_TXS: NonZeroU32 = nonzero!(2_u32.pow(9)); pub const BLOCK_TIME: Duration = Duration::from_secs(2); pub const COMMIT_TIME: Duration = Duration::from_secs(4); pub const WASM_FUEL_LIMIT: u64 = 55_000_000; - // TODO: wrap into a `Bytes` newtype - pub const WASM_MAX_MEMORY_BYTES: u32 = 500 * 2_u32.pow(20); + pub const WASM_MAX_MEMORY: Bytes = Bytes(500 * 2_u32.pow(20)); /// Default estimation of consensus duration. pub const CONSENSUS_ESTIMATION: Duration = @@ -82,7 +83,9 @@ pub mod chain_wide { pub mod torii { use std::time::Duration; - pub const MAX_CONTENT_LENGTH: u64 = 2_u64.pow(20) * 16; + use iroha_config_base::util::Bytes; + + pub const MAX_CONTENT_LENGTH: Bytes = Bytes(2_u64.pow(20) * 16); pub const QUERY_IDLE_TIME: Duration = Duration::from_secs(30); } diff --git a/config/src/parameters/user.rs b/config/src/parameters/user.rs index 1d04ebb0fd3..fcfd5abe4cb 100644 --- a/config/src/parameters/user.rs +++ b/config/src/parameters/user.rs @@ -21,7 +21,7 @@ use error_stack::{Result, ResultExt}; use iroha_config_base::{ attach::ConfigValueAndOrigin, env::FromEnvStr, - util::{Emitter, EmitterResultExt, HumanBytes, HumanDuration}, + util::{Bytes, DurationMs, Emitter, EmitterResultExt}, ReadConfig, WithOrigin, }; use iroha_crypto::{PrivateKey, PublicKey}; @@ -275,14 +275,14 @@ pub struct Network { #[config(default = "defaults::network::BLOCK_GOSSIP_MAX_SIZE")] pub block_gossip_max_size: NonZeroU32, #[config(default = "defaults::network::BLOCK_GOSSIP_PERIOD.into()")] - pub block_gossip_period: HumanDuration, + pub block_gossip_period_ms: DurationMs, #[config(default = "defaults::network::TRANSACTION_GOSSIP_MAX_SIZE")] pub transaction_gossip_max_size: NonZeroU32, #[config(default = "defaults::network::TRANSACTION_GOSSIP_PERIOD.into()")] - pub transaction_gossip_period: HumanDuration, + pub transaction_gossip_period_ms: DurationMs, /// Duration of time after which connection with peer is terminated if peer is idle #[config(default = "defaults::network::IDLE_TIMEOUT.into()")] - pub idle_timeout: HumanDuration, + pub idle_timeout_ms: DurationMs, } impl Network { @@ -296,10 +296,10 @@ impl Network { let Self { address, block_gossip_max_size, - block_gossip_period, + block_gossip_period_ms: block_gossip_period, transaction_gossip_max_size, - transaction_gossip_period, - idle_timeout, + transaction_gossip_period_ms: transaction_gossip_period, + idle_timeout_ms: idle_timeout, } = self; ( @@ -330,10 +330,10 @@ pub struct Queue { pub capacity_per_user: NonZeroUsize, /// The transaction will be dropped after this time if it is still in the queue. #[config(default = "defaults::queue::TRANSACTION_TIME_TO_LIVE.into()")] - pub transaction_time_to_live: HumanDuration, + pub transaction_time_to_live_ms: DurationMs, /// The threshold to determine if a transaction has been tampered to have a future timestamp. #[config(default = "defaults::queue::FUTURE_THRESHOLD.into()")] - pub future_threshold: HumanDuration, + pub future_threshold_ms: DurationMs, } impl Queue { @@ -341,8 +341,8 @@ impl Queue { let Self { capacity, capacity_per_user, - transaction_time_to_live, - future_threshold, + transaction_time_to_live_ms: transaction_time_to_live, + future_threshold_ms: future_threshold, } = self; actual::Queue { capacity, @@ -374,17 +374,17 @@ pub struct Telemetry { name: String, url: Url, #[serde(default)] - min_retry_period: TelemetryMinRetryPeriod, + min_retry_period_ms: TelemetryMinRetryPeriod, #[serde(default)] max_retry_delay_exponent: TelemetryMaxRetryDelayExponent, } #[derive(Deserialize, Debug, Copy, Clone)] -struct TelemetryMinRetryPeriod(HumanDuration); +struct TelemetryMinRetryPeriod(DurationMs); impl Default for TelemetryMinRetryPeriod { fn default() -> Self { - Self(HumanDuration(defaults::telemetry::MIN_RETRY_PERIOD)) + Self(DurationMs(defaults::telemetry::MIN_RETRY_PERIOD)) } } @@ -402,7 +402,7 @@ impl From for actual::Telemetry { Telemetry { name, url, - min_retry_period: TelemetryMinRetryPeriod(HumanDuration(min_retry_period)), + min_retry_period_ms: TelemetryMinRetryPeriod(DurationMs(min_retry_period)), max_retry_delay_exponent: TelemetryMaxRetryDelayExponent(max_retry_delay_exponent), }: Telemetry, ) -> Self { @@ -425,7 +425,7 @@ pub struct Snapshot { #[config(default, env = "SNAPSHOT_MODE")] pub mode: SnapshotMode, #[config(default = "defaults::snapshot::CREATE_EVERY.into()")] - pub create_every: HumanDuration, + pub create_every_ms: DurationMs, #[config( default = "PathBuf::from(defaults::snapshot::STORE_DIR)", env = "SNAPSHOT_STORE_DIR" @@ -439,9 +439,9 @@ pub struct ChainWide { #[config(default = "defaults::chain_wide::MAX_TXS")] pub max_transactions_in_block: NonZeroU32, #[config(default = "defaults::chain_wide::BLOCK_TIME.into()")] - pub block_time: HumanDuration, + pub block_time_ms: DurationMs, #[config(default = "defaults::chain_wide::COMMIT_TIME.into()")] - pub commit_time: HumanDuration, + pub commit_time_ms: DurationMs, #[config(default = "defaults::chain_wide::TRANSACTION_LIMITS")] pub transaction_limits: TransactionLimits, #[config(default = "defaults::chain_wide::METADATA_LIMITS")] @@ -458,20 +458,20 @@ pub struct ChainWide { pub ident_length_limits: LengthLimits, #[config(default = "defaults::chain_wide::WASM_FUEL_LIMIT")] pub executor_fuel_limit: u64, - #[config(default = "defaults::chain_wide::WASM_MAX_MEMORY_BYTES")] - pub executor_max_memory: u32, + #[config(default = "defaults::chain_wide::WASM_MAX_MEMORY")] + pub executor_max_memory_bytes: Bytes, #[config(default = "defaults::chain_wide::WASM_FUEL_LIMIT")] pub wasm_fuel_limit: u64, - #[config(default = "defaults::chain_wide::WASM_MAX_MEMORY_BYTES")] - pub wasm_max_memory: u32, + #[config(default = "defaults::chain_wide::WASM_MAX_MEMORY")] + pub wasm_max_memory_bytes: Bytes, } impl ChainWide { fn parse(self) -> actual::ChainWide { let Self { max_transactions_in_block, - block_time, - commit_time, + block_time_ms: DurationMs(block_time), + commit_time_ms: DurationMs(commit_time), transaction_limits, asset_metadata_limits, trigger_metadata_limits, @@ -480,15 +480,15 @@ impl ChainWide { domain_metadata_limits, ident_length_limits, executor_fuel_limit, - executor_max_memory, + executor_max_memory_bytes, wasm_fuel_limit, - wasm_max_memory, + wasm_max_memory_bytes, } = self; actual::ChainWide { max_transactions_in_block, - block_time: block_time.get(), - commit_time: commit_time.get(), + block_time, + commit_time, transaction_limits, asset_metadata_limits, trigger_metadata_limits, @@ -498,11 +498,11 @@ impl ChainWide { ident_length_limits, executor_runtime: actual::WasmRuntime { fuel_limit: executor_fuel_limit, - max_memory_bytes: executor_max_memory, + max_memory_bytes: executor_max_memory_bytes.get(), }, wasm_runtime: actual::WasmRuntime { fuel_limit: wasm_fuel_limit, - max_memory_bytes: wasm_max_memory, + max_memory_bytes: wasm_max_memory_bytes.get(), }, } } @@ -512,21 +512,21 @@ impl ChainWide { pub struct Torii { #[config(env = "API_ADDRESS")] pub address: WithOrigin, - #[config(default = "defaults::torii::MAX_CONTENT_LENGTH.into()")] - pub max_content_length: HumanBytes, + #[config(default = "defaults::torii::MAX_CONTENT_LENGTH")] + pub max_content_length_bytes: Bytes, #[config(default = "defaults::torii::QUERY_IDLE_TIME.into()")] - pub query_idle_time: HumanDuration, + pub query_idle_time_ms: DurationMs, } impl Torii { fn parse(self) -> (actual::Torii, actual::LiveQueryStore) { let torii = actual::Torii { address: self.address, - max_content_len_bytes: self.max_content_length.get(), + max_content_len_bytes: self.max_content_length_bytes.get(), }; let query = actual::LiveQueryStore { - idle_time: self.query_idle_time.get(), + idle_time: self.query_idle_time_ms.get(), }; (torii, query) diff --git a/config/tests/fixtures.rs b/config/tests/fixtures.rs index 2a455e59f5c..2d2daf8489c 100644 --- a/config/tests/fixtures.rs +++ b/config/tests/fixtures.rs @@ -181,7 +181,7 @@ fn minimal_config_snapshot() { }, snapshot: Snapshot { mode: ReadWrite, - create_every: HumanDuration( + create_every_ms: DurationMs( 60s, ), store_dir: WithOrigin { diff --git a/config/tests/fixtures/full.toml b/config/tests/fixtures/full.toml index 59f6a1c0ab5..c35067f2243 100644 --- a/config/tests/fixtures/full.toml +++ b/config/tests/fixtures/full.toml @@ -10,15 +10,16 @@ signed_file = "genesis.signed.scale" [network] address = "localhost:3840" -block_gossip_period = 10_000 +block_gossip_period_ms = 10_000 block_gossip_max_size = 4 -transaction_gossip_period = 1_000 +transaction_gossip_period_ms = 1_000 transaction_gossip_max_size = 500 +idle_timeout_ms = 10_000 [torii] address = "localhost:5000" -max_content_length = 16 -query_idle_time = 30_000 +max_content_length_bytes = 16_000 +query_idle_time_ms = 30_000 [kura] init_mode = "strict" @@ -41,18 +42,18 @@ format = "compact" [queue] capacity = 65536 capacity_per_user = 65536 -transaction_time_to_live = 100 -future_threshold = 50 +transaction_time_to_live_ms = 100 +future_threshold_ms = 50 [snapshot] mode = "read_write" -create_every = 60_000 +create_every_ms = 60_000 store_dir = "./storage/snapshot" [telemetry] name = "test" url = "http://test.com" -min_retry_period = 5_000 +min_retry_period_ms = 5_000 max_retry_delay_exponent = 4 [dev_telemetry] @@ -60,8 +61,8 @@ out_file = "./dev_telemetry.json" [chain_wide] max_transactions_in_block = 512 -block_time = 2_000 -commit_time = 4_000 +block_time_ms = 2_000 +commit_time_ms = 4_000 transaction_limits = { max_instruction_number = 4096, max_wasm_size_bytes = 4194304 } asset_metadata_limits = { capacity = 1048576, max_entry_len = 4096 } asset_definition_metadata_limits = { capacity = 1048576, max_entry_len = 4096 } diff --git a/configs/client.template.toml b/configs/client.template.toml index 858a4c1df8e..a5000db4027 100644 --- a/configs/client.template.toml +++ b/configs/client.template.toml @@ -13,7 +13,7 @@ # private_key = [transaction] -# time_to_live = "100s" -# status_timeout = "100s" +# time_to_live_ms = 100_000 +# status_timeout_ms = 100_000 ## Nonce is TODO describe what it is # nonce = false diff --git a/configs/peer.template.toml b/configs/peer.template.toml index a1eb2e9b0ef..09ace99c821 100644 --- a/configs/peer.template.toml +++ b/configs/peer.template.toml @@ -2,8 +2,11 @@ ## You can use another TOML file to extend from. ## For a single file extension: + # extends = "./base.toml" + ## Or, for a chain of extensions: + # extends = ["base-1.toml", "base-2.toml"] # chain_id = @@ -16,16 +19,16 @@ [network] # address = -# block_gossip_period = "10s" +# block_gossip_period_ms = 10_000 # block_gossip_max_size = 4 -# transaction_gossip_period = "1s" +# transaction_gossip_period_ms = 1_000 # transaction_gossip_max_size = 500 -# idle_timeout = "60s" +# idle_timeout_ms = 60_000 [torii] # address = -# max_content_length = "16mb" -# query_idle_time = "30s" +# max_content_length = 16_000_000 +# query_idle_time_ms = 30_000 [kura] # init_mode = "strict" @@ -44,18 +47,18 @@ [queue] # capacity = 65536 # capacity_per_user = 65536 -# transaction_time_to_live = "1day" -# future_threshold = "1s" +# transaction_time_to_live_ms = 86_400_000 # 1 day +# future_threshold_ms = 1_000 [snapshot] # mode = "read_write" -# create_every = "1min" +# create_every_ms = 60_000 # store_dir = "./storage/snapshot" [telemetry] # name = # url = -# min_retry_period = "1s" +# min_retry_period_ms = 1_000 # max_retry_delay_exponent = 4 [dev_telemetry] diff --git a/core/src/snapshot.rs b/core/src/snapshot.rs index 572d0810c9b..129739c413d 100644 --- a/core/src/snapshot.rs +++ b/core/src/snapshot.rs @@ -119,7 +119,7 @@ impl SnapshotMaker { let latest_block_hash = state.view().latest_block_hash(); Some(Self { state, - create_every: config.create_every.get(), + create_every: config.create_every_ms.get(), store_dir: config.store_dir.clone(), latest_block_hash, }) diff --git a/tools/kagami/src/genesis/generate.rs b/tools/kagami/src/genesis/generate.rs index 3c842b9c929..be0804fa88a 100644 --- a/tools/kagami/src/genesis/generate.rs +++ b/tools/kagami/src/genesis/generate.rs @@ -191,7 +191,7 @@ pub fn generate_default( )? .add_parameter( EXECUTOR_MAX_MEMORY, - Numeric::new(chain_wide_defaults::WASM_MAX_MEMORY_BYTES.into(), 0), + Numeric::new(chain_wide_defaults::WASM_MAX_MEMORY.get().into(), 0), )? .add_parameter( WASM_FUEL_LIMIT, @@ -199,7 +199,7 @@ pub fn generate_default( )? .add_parameter( WASM_MAX_MEMORY, - Numeric::new(chain_wide_defaults::WASM_MAX_MEMORY_BYTES.into(), 0), + Numeric::new(chain_wide_defaults::WASM_MAX_MEMORY.get().into(), 0), )? .into_create_parameters();