Skip to content

Commit

Permalink
fix: remove _bytes suffix
Browse files Browse the repository at this point in the history
Signed-off-by: 0x009922 <[email protected]>
  • Loading branch information
0x009922 committed Jun 11, 2024
1 parent f5d967f commit d224e9d
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 36 deletions.
2 changes: 1 addition & 1 deletion client/examples/register_1000_triggers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,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
8 changes: 4 additions & 4 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,14 +230,14 @@ impl Default for ChainWide {
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub struct WasmRuntime {
pub fuel_limit: u64,
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.get(),
max_memory: defaults::chain_wide::WASM_MAX_MEMORY,
}
}
}
Expand All @@ -246,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
16 changes: 8 additions & 8 deletions config/src/parameters/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,11 +459,11 @@ pub struct ChainWide {
#[config(default = "defaults::chain_wide::WASM_FUEL_LIMIT")]
pub executor_fuel_limit: u64,
#[config(default = "defaults::chain_wide::WASM_MAX_MEMORY")]
pub executor_max_memory_bytes: Bytes<u32>,
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")]
pub wasm_max_memory_bytes: Bytes<u32>,
pub wasm_max_memory: Bytes<u32>,
}

impl ChainWide {
Expand All @@ -480,9 +480,9 @@ impl ChainWide {
domain_metadata_limits,
ident_length_limits,
executor_fuel_limit,
executor_max_memory_bytes,
executor_max_memory,
wasm_fuel_limit,
wasm_max_memory_bytes,
wasm_max_memory,
} = self;

actual::ChainWide {
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_bytes.get(),
max_memory: executor_max_memory,
},
wasm_runtime: actual::WasmRuntime {
fuel_limit: wasm_fuel_limit,
max_memory_bytes: wasm_max_memory_bytes.get(),
max_memory: wasm_max_memory,
},
}
}
Expand All @@ -513,7 +513,7 @@ pub struct Torii {
#[config(env = "API_ADDRESS")]
pub address: WithOrigin<SocketAddr>,
#[config(default = "defaults::torii::MAX_CONTENT_LENGTH")]
pub max_content_length_bytes: Bytes<u64>,
pub max_content_len: Bytes<u64>,
#[config(default = "defaults::torii::QUERY_IDLE_TIME.into()")]
pub query_idle_time_ms: DurationMs,
}
Expand All @@ -522,7 +522,7 @@ impl Torii {
fn parse(self) -> (actual::Torii, actual::LiveQueryStore) {
let torii = actual::Torii {
address: self.address,
max_content_len_bytes: self.max_content_length_bytes.get(),
max_content_len: self.max_content_len,
};

let query = actual::LiveQueryStore {
Expand Down
12 changes: 9 additions & 3 deletions config/tests/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ fn minimal_config_snapshot() {
path: "tests/fixtures/base.toml",
},
},
max_content_len_bytes: 16777216,
max_content_len: Bytes(
16777216,
),
},
kura: Kura {
init_mode: Strict,
Expand Down Expand Up @@ -229,11 +231,15 @@ fn minimal_config_snapshot() {
},
executor_runtime: WasmRuntime {
fuel_limit: 55000000,
max_memory_bytes: 524288000,
max_memory: Bytes(
524288000,
),
},
wasm_runtime: WasmRuntime {
fuel_limit: 55000000,
max_memory_bytes: 524288000,
max_memory: Bytes(
524288000,
),
},
},
}"#]].assert_eq(&format!("{config:#?}"));
Expand Down
2 changes: 1 addition & 1 deletion config/tests/fixtures/full.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ idle_timeout_ms = 10_000

[torii]
address = "localhost:5000"
max_content_length_bytes = 16_000
max_content_len = 16_000
query_idle_time_ms = 30_000

[kura]
Expand Down
2 changes: 1 addition & 1 deletion core/benches/blocks/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ pub fn build_state(rt: &tokio::runtime::Handle, account_id: &AccountId) -> State

state_block.config.transaction_limits = TransactionLimits::new(u64::MAX, u64::MAX);
state_block.config.executor_runtime.fuel_limit = u64::MAX;
state_block.config.executor_runtime.max_memory_bytes = u32::MAX;
state_block.config.executor_runtime.max_memory = u32::MAX.into();

let mut state_transaction = state_block.transaction();
let path_to_executor = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
Expand Down
2 changes: 1 addition & 1 deletion core/src/smartcontracts/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ pub mod state {
/// on any supported platform
pub fn store_limits_from_config(config: &Config) -> StoreLimits {
StoreLimitsBuilder::new()
.memory_size(config.max_memory_bytes as usize)
.memory_size(config.max_memory.get() as usize)
.instances(1)
.memories(1)
.tables(1)
Expand Down
27 changes: 14 additions & 13 deletions core/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{
};

use eyre::Result;
use iroha_config::parameters::actual::ChainWide as Config;
use iroha_config::{base::util::Bytes, parameters::actual::ChainWide as Config};
use iroha_crypto::HashOf;
use iroha_data_model::{
account::AccountId,
Expand Down Expand Up @@ -1384,6 +1384,14 @@ impl StateTransaction<'_, '_> {
*destination = value;
})
}

fn try_and_write_duration(self, id: &str, destination: &mut Duration) -> Self {
self.try_and_then(id, |value| *destination = Duration::from_millis(value))
}

fn try_and_write_bytes(self, id: &str, destination: &mut Bytes<u32>) -> Self {
self.try_and_then(id, |value| *destination = Bytes(value))
}
}

Reader(Some(parameter))
Expand All @@ -1392,12 +1400,8 @@ impl StateTransaction<'_, '_> {
self.config.max_transactions_in_block = checked;
}
})
.try_and_then(BLOCK_TIME, |value| {
self.config.block_time = Duration::from_millis(value);
})
.try_and_then(COMMIT_TIME_LIMIT, |value| {
self.config.commit_time = Duration::from_millis(value);
})
.try_and_write_duration(BLOCK_TIME, &mut self.config.block_time)
.try_and_write_duration(COMMIT_TIME_LIMIT, &mut self.config.commit_time)
.try_and_write(
WSV_DOMAIN_METADATA_LIMITS,
&mut self.config.domain_metadata_limits,
Expand Down Expand Up @@ -1426,15 +1430,12 @@ impl StateTransaction<'_, '_> {
EXECUTOR_FUEL_LIMIT,
&mut self.config.executor_runtime.fuel_limit,
)
.try_and_write(
.try_and_write_bytes(
EXECUTOR_MAX_MEMORY,
&mut self.config.executor_runtime.max_memory_bytes,
&mut self.config.executor_runtime.max_memory,
)
.try_and_write(WASM_FUEL_LIMIT, &mut self.config.wasm_runtime.fuel_limit)
.try_and_write(
WASM_MAX_MEMORY,
&mut self.config.wasm_runtime.max_memory_bytes,
)
.try_and_write_bytes(WASM_MAX_MEMORY, &mut self.config.wasm_runtime.max_memory)
.try_and_write(TRANSACTION_LIMITS, &mut self.config.transaction_limits);
}

Expand Down
8 changes: 4 additions & 4 deletions torii/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::{
};

use futures::{stream::FuturesUnordered, StreamExt};
use iroha_config::parameters::actual::Torii as Config;
use iroha_config::{base::util::Bytes, parameters::actual::Torii as Config};
#[cfg(feature = "telemetry")]
use iroha_core::metrics::MetricsReporter;
use iroha_core::{
Expand Down Expand Up @@ -52,7 +52,7 @@ pub struct Torii {
notify_shutdown: Arc<Notify>,
query_service: LiveQueryStoreHandle,
kura: Arc<Kura>,
transaction_max_content_length: u64,
transaction_max_content_length: Bytes<u64>,
address: SocketAddr,
state: Arc<State>,
#[cfg(feature = "telemetry")]
Expand Down Expand Up @@ -86,7 +86,7 @@ impl Torii {
#[cfg(feature = "telemetry")]
metrics_reporter,
address: config.address.into_value(),
transaction_max_content_length: config.max_content_len_bytes,
transaction_max_content_length: config.max_content_len,
}
}

Expand Down Expand Up @@ -168,7 +168,7 @@ impl Torii {
warp::path(uri::TRANSACTION)
.and(add_state!(self.chain_id, self.queue, self.state.clone()))
.and(warp::body::content_length_limit(
self.transaction_max_content_length,
self.transaction_max_content_length.get(),
))
.and(body::versioned()),
)
Expand Down

0 comments on commit d224e9d

Please sign in to comment.