Skip to content

Commit 5214a6a

Browse files
authored
refactor!: revert _ms and _bytes suffixes in config (#4667)
Signed-off-by: 0x009922 <[email protected]>
1 parent c4dc77a commit 5214a6a

File tree

19 files changed

+121
-109
lines changed

19 files changed

+121
-109
lines changed

cli/src/samples.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub fn get_config_toml(
6666
.write("private_key", ExposedPrivateKey(private_key))
6767
.write(["sumeragi", "trusted_peers"], peers)
6868
.write(["network", "address"], DEFAULT_P2P_ADDR)
69-
.write(["network", "block_gossip_period"], 500)
69+
.write(["network", "block_gossip_period_ms"], 500)
7070
.write(["network", "block_gossip_max_size"], 1)
7171
.write(["torii", "address"], DEFAULT_TORII_ADDR)
7272
.write(["chain_wide", "max_transactions_in_block"], 2)

client/examples/register_1000_triggers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
7171

7272
// Increase executor limits for large genesis
7373
configuration.chain_wide.executor_runtime.fuel_limit = u64::MAX;
74-
configuration.chain_wide.executor_runtime.max_memory_bytes = u32::MAX;
74+
configuration.chain_wide.executor_runtime.max_memory = u32::MAX.into();
7575

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

client/src/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ mod tests {
124124
private_key = "802640CCF31D85E3B32A4BEA59987CE0C78E3B8E2DB93881468AB2435FE45D5C9DCD53CE7FA46C9DCE7EA4B125E2E36BDB63EA33073E7590AC92816AE1E861B7048B03"
125125

126126
[transaction]
127-
time_to_live = 100_000
128-
status_timeout = 100_000
127+
time_to_live_ms = 100_000
128+
status_timeout_ms = 100_000
129129
nonce = false
130130
}
131131
}

client/src/config/user.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use error_stack::{Report, ResultExt};
44
use iroha_config_base::{
55
attach::ConfigValueAndOrigin,
6-
util::{Emitter, EmitterResultExt, HumanDuration},
6+
util::{DurationMs, Emitter, EmitterResultExt},
77
ReadConfig, WithOrigin,
88
};
99
use iroha_crypto::{KeyPair, PrivateKey, PublicKey};
@@ -55,8 +55,8 @@ impl Root {
5555
},
5656
transaction:
5757
Transaction {
58-
time_to_live: tx_ttl,
59-
status_timeout: tx_timeout,
58+
time_to_live_ms: tx_ttl,
59+
status_timeout_ms: tx_timeout,
6060
nonce: tx_add_nonce,
6161
},
6262
} = self;
@@ -122,9 +122,9 @@ pub struct Account {
122122
#[allow(missing_docs)]
123123
pub struct Transaction {
124124
#[config(default = "super::DEFAULT_TRANSACTION_TIME_TO_LIVE.into()")]
125-
pub time_to_live: WithOrigin<HumanDuration>,
125+
pub time_to_live_ms: WithOrigin<DurationMs>,
126126
#[config(default = "super::DEFAULT_TRANSACTION_STATUS_TIMEOUT.into()")]
127-
pub status_timeout: WithOrigin<HumanDuration>,
127+
pub status_timeout_ms: WithOrigin<DurationMs>,
128128
#[config(default = "super::DEFAULT_TRANSACTION_NONCE")]
129129
pub nonce: bool,
130130
}

config/base/src/util.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,37 @@ use drop_bomb::DropBomb;
77
use error_stack::Report;
88
use serde::{Deserialize, Serialize};
99

10-
/// [`Duration`], but can parse a human-readable string.
11-
/// TODO: currently deserializes just as [`Duration`]
10+
/// (De-)serialize [`Duration`] as a number of milliseconds
1211
#[serde_with::serde_as]
1312
#[derive(Debug, Copy, Clone, Deserialize, Serialize, Ord, PartialOrd, Eq, PartialEq, Display)]
1413
#[display(fmt = "{_0:?}")]
15-
pub struct HumanDuration(#[serde_as(as = "serde_with::DurationMilliSeconds")] pub Duration);
14+
pub struct DurationMs(#[serde_as(as = "serde_with::DurationMilliSeconds")] pub Duration);
1615

17-
impl HumanDuration {
16+
impl DurationMs {
1817
/// Get the [`Duration`]
1918
pub fn get(self) -> Duration {
2019
self.0
2120
}
2221
}
2322

24-
impl From<Duration> for HumanDuration {
23+
impl From<Duration> for DurationMs {
2524
fn from(value: Duration) -> Self {
2625
Self(value)
2726
}
2827
}
2928

30-
/// Representation of number of bytes, parseable from a human-readable string.
29+
/// A number of bytes
3130
#[derive(Debug, Copy, Clone, Deserialize, Serialize)]
32-
pub struct HumanBytes<T: num_traits::int::PrimInt>(pub T);
31+
pub struct Bytes<T: num_traits::int::PrimInt>(pub T);
3332

34-
impl<T: num_traits::int::PrimInt> HumanBytes<T> {
33+
impl<T: num_traits::int::PrimInt> Bytes<T> {
3534
/// Get the number of bytes
3635
pub fn get(self) -> T {
3736
self.0
3837
}
3938
}
4039

41-
impl<T: num_traits::int::PrimInt> From<T> for HumanBytes<T> {
40+
impl<T: num_traits::int::PrimInt> From<T> for Bytes<T> {
4241
fn from(value: T) -> Self {
4342
Self(value)
4443
}
@@ -238,10 +237,10 @@ mod tests {
238237
}
239238

240239
#[test]
241-
fn deserialize_human_duration() {
240+
fn deserialize_duration_ms() {
242241
#[derive(Deserialize)]
243242
struct Test {
244-
value: HumanDuration,
243+
value: DurationMs,
245244
}
246245

247246
let Test { value } = toml::toml! {

config/base/tests/misc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ fn full_config_ok() {
382382

383383
[torii]
384384
address = "127.0.0.2:1337"
385-
max_content_length = 19
385+
max_content_len = 19
386386

387387
[kura]
388388
store_dir = "./my-storage"

config/src/parameters/actual.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::{
88
};
99

1010
use error_stack::{Result, ResultExt};
11-
use iroha_config_base::{read::ConfigReader, toml::TomlSource, WithOrigin};
11+
use iroha_config_base::{read::ConfigReader, toml::TomlSource, util::Bytes, WithOrigin};
1212
use iroha_crypto::{KeyPair, PublicKey};
1313
use iroha_data_model::{
1414
metadata::Limits as MetadataLimits, peer::PeerId, transaction::TransactionLimits, ChainId,
@@ -230,15 +230,14 @@ impl Default for ChainWide {
230230
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
231231
pub struct WasmRuntime {
232232
pub fuel_limit: u64,
233-
// TODO: wrap into a `Bytes` newtype
234-
pub max_memory_bytes: u32,
233+
pub max_memory: Bytes<u32>,
235234
}
236235

237236
impl Default for WasmRuntime {
238237
fn default() -> Self {
239238
Self {
240239
fuel_limit: defaults::chain_wide::WASM_FUEL_LIMIT,
241-
max_memory_bytes: defaults::chain_wide::WASM_MAX_MEMORY_BYTES,
240+
max_memory: defaults::chain_wide::WASM_MAX_MEMORY,
242241
}
243242
}
244243
}
@@ -247,7 +246,7 @@ impl Default for WasmRuntime {
247246
#[allow(missing_docs)]
248247
pub struct Torii {
249248
pub address: WithOrigin<SocketAddr>,
250-
pub max_content_len_bytes: u64,
249+
pub max_content_len: Bytes<u64>,
251250
}
252251

253252
/// Complete configuration needed to start regular telemetry.

config/src/parameters/defaults.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,15 @@ pub mod snapshot {
4646
}
4747

4848
pub mod chain_wide {
49+
use iroha_config_base::util::Bytes;
50+
4951
use super::*;
5052

5153
pub const MAX_TXS: NonZeroU32 = nonzero!(2_u32.pow(9));
5254
pub const BLOCK_TIME: Duration = Duration::from_secs(2);
5355
pub const COMMIT_TIME: Duration = Duration::from_secs(4);
5456
pub const WASM_FUEL_LIMIT: u64 = 55_000_000;
55-
// TODO: wrap into a `Bytes` newtype
56-
pub const WASM_MAX_MEMORY_BYTES: u32 = 500 * 2_u32.pow(20);
57+
pub const WASM_MAX_MEMORY: Bytes<u32> = Bytes(500 * 2_u32.pow(20));
5758

5859
/// Default estimation of consensus duration.
5960
pub const CONSENSUS_ESTIMATION: Duration =
@@ -82,7 +83,9 @@ pub mod chain_wide {
8283
pub mod torii {
8384
use std::time::Duration;
8485

85-
pub const MAX_CONTENT_LENGTH: u64 = 2_u64.pow(20) * 16;
86+
use iroha_config_base::util::Bytes;
87+
88+
pub const MAX_CONTENT_LEN: Bytes<u64> = Bytes(2_u64.pow(20) * 16);
8689
pub const QUERY_IDLE_TIME: Duration = Duration::from_secs(30);
8790
}
8891

config/src/parameters/user.rs

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use error_stack::{Result, ResultExt};
2121
use iroha_config_base::{
2222
attach::ConfigValueAndOrigin,
2323
env::FromEnvStr,
24-
util::{Emitter, EmitterResultExt, HumanBytes, HumanDuration},
24+
util::{Bytes, DurationMs, Emitter, EmitterResultExt},
2525
ReadConfig, WithOrigin,
2626
};
2727
use iroha_crypto::{PrivateKey, PublicKey};
@@ -275,14 +275,14 @@ pub struct Network {
275275
#[config(default = "defaults::network::BLOCK_GOSSIP_MAX_SIZE")]
276276
pub block_gossip_max_size: NonZeroU32,
277277
#[config(default = "defaults::network::BLOCK_GOSSIP_PERIOD.into()")]
278-
pub block_gossip_period: HumanDuration,
278+
pub block_gossip_period_ms: DurationMs,
279279
#[config(default = "defaults::network::TRANSACTION_GOSSIP_MAX_SIZE")]
280280
pub transaction_gossip_max_size: NonZeroU32,
281281
#[config(default = "defaults::network::TRANSACTION_GOSSIP_PERIOD.into()")]
282-
pub transaction_gossip_period: HumanDuration,
282+
pub transaction_gossip_period_ms: DurationMs,
283283
/// Duration of time after which connection with peer is terminated if peer is idle
284284
#[config(default = "defaults::network::IDLE_TIMEOUT.into()")]
285-
pub idle_timeout: HumanDuration,
285+
pub idle_timeout_ms: DurationMs,
286286
}
287287

288288
impl Network {
@@ -296,10 +296,10 @@ impl Network {
296296
let Self {
297297
address,
298298
block_gossip_max_size,
299-
block_gossip_period,
299+
block_gossip_period_ms: block_gossip_period,
300300
transaction_gossip_max_size,
301-
transaction_gossip_period,
302-
idle_timeout,
301+
transaction_gossip_period_ms: transaction_gossip_period,
302+
idle_timeout_ms: idle_timeout,
303303
} = self;
304304

305305
(
@@ -330,19 +330,19 @@ pub struct Queue {
330330
pub capacity_per_user: NonZeroUsize,
331331
/// The transaction will be dropped after this time if it is still in the queue.
332332
#[config(default = "defaults::queue::TRANSACTION_TIME_TO_LIVE.into()")]
333-
pub transaction_time_to_live: HumanDuration,
333+
pub transaction_time_to_live_ms: DurationMs,
334334
/// The threshold to determine if a transaction has been tampered to have a future timestamp.
335335
#[config(default = "defaults::queue::FUTURE_THRESHOLD.into()")]
336-
pub future_threshold: HumanDuration,
336+
pub future_threshold_ms: DurationMs,
337337
}
338338

339339
impl Queue {
340340
pub fn parse(self) -> actual::Queue {
341341
let Self {
342342
capacity,
343343
capacity_per_user,
344-
transaction_time_to_live,
345-
future_threshold,
344+
transaction_time_to_live_ms: transaction_time_to_live,
345+
future_threshold_ms: future_threshold,
346346
} = self;
347347
actual::Queue {
348348
capacity,
@@ -374,17 +374,17 @@ pub struct Telemetry {
374374
name: String,
375375
url: Url,
376376
#[serde(default)]
377-
min_retry_period: TelemetryMinRetryPeriod,
377+
min_retry_period_ms: TelemetryMinRetryPeriod,
378378
#[serde(default)]
379379
max_retry_delay_exponent: TelemetryMaxRetryDelayExponent,
380380
}
381381

382382
#[derive(Deserialize, Debug, Copy, Clone)]
383-
struct TelemetryMinRetryPeriod(HumanDuration);
383+
struct TelemetryMinRetryPeriod(DurationMs);
384384

385385
impl Default for TelemetryMinRetryPeriod {
386386
fn default() -> Self {
387-
Self(HumanDuration(defaults::telemetry::MIN_RETRY_PERIOD))
387+
Self(DurationMs(defaults::telemetry::MIN_RETRY_PERIOD))
388388
}
389389
}
390390

@@ -402,7 +402,7 @@ impl From<Telemetry> for actual::Telemetry {
402402
Telemetry {
403403
name,
404404
url,
405-
min_retry_period: TelemetryMinRetryPeriod(HumanDuration(min_retry_period)),
405+
min_retry_period_ms: TelemetryMinRetryPeriod(DurationMs(min_retry_period)),
406406
max_retry_delay_exponent: TelemetryMaxRetryDelayExponent(max_retry_delay_exponent),
407407
}: Telemetry,
408408
) -> Self {
@@ -425,7 +425,7 @@ pub struct Snapshot {
425425
#[config(default, env = "SNAPSHOT_MODE")]
426426
pub mode: SnapshotMode,
427427
#[config(default = "defaults::snapshot::CREATE_EVERY.into()")]
428-
pub create_every: HumanDuration,
428+
pub create_every_ms: DurationMs,
429429
#[config(
430430
default = "PathBuf::from(defaults::snapshot::STORE_DIR)",
431431
env = "SNAPSHOT_STORE_DIR"
@@ -439,9 +439,9 @@ pub struct ChainWide {
439439
#[config(default = "defaults::chain_wide::MAX_TXS")]
440440
pub max_transactions_in_block: NonZeroU32,
441441
#[config(default = "defaults::chain_wide::BLOCK_TIME.into()")]
442-
pub block_time: HumanDuration,
442+
pub block_time_ms: DurationMs,
443443
#[config(default = "defaults::chain_wide::COMMIT_TIME.into()")]
444-
pub commit_time: HumanDuration,
444+
pub commit_time_ms: DurationMs,
445445
#[config(default = "defaults::chain_wide::TRANSACTION_LIMITS")]
446446
pub transaction_limits: TransactionLimits,
447447
#[config(default = "defaults::chain_wide::METADATA_LIMITS")]
@@ -458,20 +458,20 @@ pub struct ChainWide {
458458
pub ident_length_limits: LengthLimits,
459459
#[config(default = "defaults::chain_wide::WASM_FUEL_LIMIT")]
460460
pub executor_fuel_limit: u64,
461-
#[config(default = "defaults::chain_wide::WASM_MAX_MEMORY_BYTES")]
462-
pub executor_max_memory: u32,
461+
#[config(default = "defaults::chain_wide::WASM_MAX_MEMORY")]
462+
pub executor_max_memory: Bytes<u32>,
463463
#[config(default = "defaults::chain_wide::WASM_FUEL_LIMIT")]
464464
pub wasm_fuel_limit: u64,
465-
#[config(default = "defaults::chain_wide::WASM_MAX_MEMORY_BYTES")]
466-
pub wasm_max_memory: u32,
465+
#[config(default = "defaults::chain_wide::WASM_MAX_MEMORY")]
466+
pub wasm_max_memory: Bytes<u32>,
467467
}
468468

469469
impl ChainWide {
470470
fn parse(self) -> actual::ChainWide {
471471
let Self {
472472
max_transactions_in_block,
473-
block_time,
474-
commit_time,
473+
block_time_ms: DurationMs(block_time),
474+
commit_time_ms: DurationMs(commit_time),
475475
transaction_limits,
476476
asset_metadata_limits,
477477
trigger_metadata_limits,
@@ -487,8 +487,8 @@ impl ChainWide {
487487

488488
actual::ChainWide {
489489
max_transactions_in_block,
490-
block_time: block_time.get(),
491-
commit_time: commit_time.get(),
490+
block_time,
491+
commit_time,
492492
transaction_limits,
493493
asset_metadata_limits,
494494
trigger_metadata_limits,
@@ -498,11 +498,11 @@ impl ChainWide {
498498
ident_length_limits,
499499
executor_runtime: actual::WasmRuntime {
500500
fuel_limit: executor_fuel_limit,
501-
max_memory_bytes: executor_max_memory,
501+
max_memory: executor_max_memory,
502502
},
503503
wasm_runtime: actual::WasmRuntime {
504504
fuel_limit: wasm_fuel_limit,
505-
max_memory_bytes: wasm_max_memory,
505+
max_memory: wasm_max_memory,
506506
},
507507
}
508508
}
@@ -512,21 +512,21 @@ impl ChainWide {
512512
pub struct Torii {
513513
#[config(env = "API_ADDRESS")]
514514
pub address: WithOrigin<SocketAddr>,
515-
#[config(default = "defaults::torii::MAX_CONTENT_LENGTH.into()")]
516-
pub max_content_length: HumanBytes<u64>,
515+
#[config(default = "defaults::torii::MAX_CONTENT_LEN")]
516+
pub max_content_len: Bytes<u64>,
517517
#[config(default = "defaults::torii::QUERY_IDLE_TIME.into()")]
518-
pub query_idle_time: HumanDuration,
518+
pub query_idle_time_ms: DurationMs,
519519
}
520520

521521
impl Torii {
522522
fn parse(self) -> (actual::Torii, actual::LiveQueryStore) {
523523
let torii = actual::Torii {
524524
address: self.address,
525-
max_content_len_bytes: self.max_content_length.get(),
525+
max_content_len: self.max_content_len,
526526
};
527527

528528
let query = actual::LiveQueryStore {
529-
idle_time: self.query_idle_time.get(),
529+
idle_time: self.query_idle_time_ms.get(),
530530
};
531531

532532
(torii, query)

0 commit comments

Comments
 (0)