Skip to content

Commit

Permalink
perf: read build config
Browse files Browse the repository at this point in the history
Signed-off-by: Lohachov Mykhailo <[email protected]>
  • Loading branch information
aoyako committed Dec 12, 2024
1 parent b462b2f commit 1e759d2
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 22 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions crates/iroha_core/src/sumeragi/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,12 @@ impl Sumeragi {
};

if block.as_ref().errors().next().is_some() {
error!("Genesis contains invalid transactions");

for error in block.as_ref().errors() {
error!(
peer_id=%self.peer,
role=%self.role(),
?error
?error,
"Invalid transaction in genesis"
);
}
continue;
Expand Down
9 changes: 0 additions & 9 deletions crates/iroha_test_network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,15 +339,6 @@ impl NetworkBuilder {
commit_time = SumeragiParameters::default().commit_time();
}

// Unoptimized profile requires additional resources.
// if cfg!(debug_assertions) {
// extra_isi.push(InstructionBox::SetParameter(SetParameter::new(
// Parameter::Executor(SmartContractParameter::Fuel(
// std::num::NonZeroU64::new(80000000).expect("Fuel must be positive."),
// )),
// )));
// }

let genesis = config::genesis(
[
InstructionBox::SetParameter(SetParameter::new(Parameter::Sumeragi(
Expand Down
18 changes: 9 additions & 9 deletions crates/iroha_test_samples/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::{
use iroha_crypto::KeyPair;
use iroha_data_model::prelude::{AccountId, WasmSmartContract};
use iroha_wasm_builder::Profile;
use serde::Deserialize;

/// Generate [`AccountId`](iroha_data_model::account::AccountId) in the given `domain`.
///
Expand Down Expand Up @@ -130,6 +131,11 @@ pub fn load_sample_wasm(name: impl AsRef<str>) -> WasmSmartContract {
}
}

#[derive(Deserialize)]
struct WasmBuildConfiguration {
profile: Profile,
}

/// Load WASM smart contract build profile
///
/// WASMs must be pre-built with the `build_wasm.sh` script
Expand All @@ -150,15 +156,9 @@ pub fn load_wasm_build_profile() -> Profile {
panic!("could not read WASM build profile");
}
Ok(content) => {
let parsed: toml::Value =
toml::from_str(content.as_str()).expect("must parse config file");
let profile_str = parsed
.get("profile")
.and_then(toml::Value::as_str)
.expect("profile must be present in config");
profile_str
.parse()
.unwrap_or_else(|_| panic!("unrecognized profile {profile_str}"))
let WasmBuildConfiguration { profile } = toml::from_str(content.as_str())
.expect("a valid config must be written by `build_wasm.sh`");
profile
}
}
}
1 change: 1 addition & 0 deletions crates/iroha_wasm_builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ workspace = true
[dependencies]
eyre = { workspace = true }
serde_json = { workspace = true, features = ["std"] }
serde = { workspace = true, features = ["std"] }
sha256 = "1.5.0"
path-absolutize = { workspace = true }
strum = { workspace = true, features = ["derive", "std"] }
Expand Down
14 changes: 13 additions & 1 deletion crates/iroha_wasm_builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,24 @@ use std::{

use eyre::{bail, eyre, Context as _, Result};
use path_absolutize::Absolutize;
use serde::{Deserialize, Serialize};

/// Current toolchain used to build smartcontracts
const TOOLCHAIN: &str = "+nightly-2024-09-09";

/// Build profile for smartcontracts
#[derive(Debug, Copy, Clone, Eq, PartialEq, strum::Display, strum::EnumString, Default)]
#[derive(
Debug,
Copy,
Clone,
Eq,
PartialEq,
strum::Display,
strum::EnumString,
Default,
Serialize,
Deserialize,
)]
#[strum(serialize_all = "snake_case")]
pub enum Profile {
/// Applies release optimization
Expand Down

0 comments on commit 1e759d2

Please sign in to comment.