Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: revert _ms and _bytes suffixes in config #4667

Merged
merged 3 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/src/samples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,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)
Expand Down
2 changes: 1 addition & 1 deletion client/examples/register_1000_triggers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

// Increase executor limits for large genesis
configuration.chain_wide.executor_runtime.fuel_limit = u64::MAX;
configuration.chain_wide.executor_runtime.max_memory_bytes = u32::MAX;
configuration.chain_wide.executor_runtime.max_memory = u32::MAX.into();

let genesis = generate_genesis(1_000_u32, chain_id, &genesis_key_pair)?;

Expand Down
4 changes: 2 additions & 2 deletions client/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,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
}
}
Expand Down
10 changes: 5 additions & 5 deletions client/src/config/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<HumanDuration>,
pub time_to_live_ms: WithOrigin<DurationMs>,
#[config(default = "super::DEFAULT_TRANSACTION_STATUS_TIMEOUT.into()")]
pub status_timeout: WithOrigin<HumanDuration>,
pub status_timeout_ms: WithOrigin<DurationMs>,
#[config(default = "super::DEFAULT_TRANSACTION_NONCE")]
pub nonce: bool,
}
Expand Down
21 changes: 10 additions & 11 deletions config/base/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Duration> for HumanDuration {
impl From<Duration> 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<T: num_traits::int::PrimInt>(pub T);
pub struct Bytes<T: num_traits::int::PrimInt>(pub T);

impl<T: num_traits::int::PrimInt> HumanBytes<T> {
impl<T: num_traits::int::PrimInt> Bytes<T> {
/// Get the number of bytes
pub fn get(self) -> T {
self.0
}
}

impl<T: num_traits::int::PrimInt> From<T> for HumanBytes<T> {
impl<T: num_traits::int::PrimInt> From<T> for Bytes<T> {
fn from(value: T) -> Self {
Self(value)
}
Expand Down Expand Up @@ -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! {
Expand Down
2 changes: 1 addition & 1 deletion config/base/tests/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ fn full_config_ok() {

[torii]
address = "127.0.0.2:1337"
max_content_length = 19
max_content_len = 19

[kura]
store_dir = "./my-storage"
Expand Down
9 changes: 4 additions & 5 deletions config/src/parameters/actual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
};

use error_stack::{Result, ResultExt};
use iroha_config_base::{read::ConfigReader, toml::TomlSource, WithOrigin};
use iroha_config_base::{read::ConfigReader, toml::TomlSource, util::Bytes, WithOrigin};
use iroha_crypto::{KeyPair, PublicKey};
use iroha_data_model::{
metadata::Limits as MetadataLimits, peer::PeerId, transaction::TransactionLimits, ChainId,
Expand Down Expand Up @@ -230,15 +230,14 @@ 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,
pub max_memory: Bytes<u32>,
}

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: defaults::chain_wide::WASM_MAX_MEMORY,
}
}
}
Expand All @@ -247,7 +246,7 @@ impl Default for WasmRuntime {
#[allow(missing_docs)]
pub struct Torii {
pub address: WithOrigin<SocketAddr>,
pub max_content_len_bytes: u64,
pub max_content_len: Bytes<u64>,
}

/// Complete configuration needed to start regular telemetry.
Expand Down
9 changes: 6 additions & 3 deletions config/src/parameters/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32> = Bytes(500 * 2_u32.pow(20));

/// Default estimation of consensus duration.
pub const CONSENSUS_ESTIMATION: Duration =
Expand Down Expand Up @@ -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_LEN: Bytes<u64> = Bytes(2_u64.pow(20) * 16);
pub const QUERY_IDLE_TIME: Duration = Duration::from_secs(30);
}

Expand Down
66 changes: 33 additions & 33 deletions config/src/parameters/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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 {
Expand All @@ -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;

(
Expand Down Expand Up @@ -330,19 +330,19 @@ 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 {
pub fn parse(self) -> actual::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,
Expand Down Expand Up @@ -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))
}
}

Expand All @@ -402,7 +402,7 @@ impl From<Telemetry> 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 {
Expand All @@ -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"
Expand All @@ -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")]
Expand All @@ -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<u32>,
#[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<u32>,
}

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,
Expand All @@ -487,8 +487,8 @@ impl ChainWide {

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,
Expand All @@ -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: executor_max_memory,
},
wasm_runtime: actual::WasmRuntime {
fuel_limit: wasm_fuel_limit,
max_memory_bytes: wasm_max_memory,
max_memory: wasm_max_memory,
},
}
}
Expand All @@ -512,21 +512,21 @@ impl ChainWide {
pub struct Torii {
#[config(env = "API_ADDRESS")]
pub address: WithOrigin<SocketAddr>,
#[config(default = "defaults::torii::MAX_CONTENT_LENGTH.into()")]
pub max_content_length: HumanBytes<u64>,
#[config(default = "defaults::torii::MAX_CONTENT_LEN")]
pub max_content_len: Bytes<u64>,
#[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: self.max_content_len,
};

let query = actual::LiveQueryStore {
idle_time: self.query_idle_time.get(),
idle_time: self.query_idle_time_ms.get(),
};

(torii, query)
Expand Down
Loading
Loading