Skip to content

Commit

Permalink
[refactor] #4291: update genesis config & schema (#4370)
Browse files Browse the repository at this point in the history
* [refactor] #4291: update genesis config & schema

- remove inline executor mode
- rename field to `executor_file`
- remove genesis from schema (revert #1391)

Signed-off-by: Dmitry Balashov <[email protected]>
  • Loading branch information
0x009922 authored Mar 19, 2024
1 parent ac872b2 commit c9dce26
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 245 deletions.
16 changes: 9 additions & 7 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,10 +516,11 @@ pub fn read_config_and_genesis<P: AsRef<Path>>(
let genesis = if let Genesis::Full { key_pair, file } = &config.genesis {
let raw_block = RawGenesisBlock::from_path(file)?;

Some(
GenesisNetwork::new(raw_block, &config.common.chain_id, key_pair)
.wrap_err("Failed to construct the genesis")?,
)
Some(GenesisNetwork::new(
raw_block,
&config.common.chain_id,
key_pair,
))
} else {
None
};
Expand Down Expand Up @@ -559,10 +560,11 @@ mod tests {
}

mod config_integration {
use std::path::PathBuf;

use assertables::{assert_contains, assert_contains_as_result};
use iroha_config::parameters::user::RootPartial as PartialUserConfig;
use iroha_crypto::KeyPair;
use iroha_genesis::{ExecutorMode, ExecutorPath};
use iroha_primitives::addr::socket_addr;
use path_absolutize::Absolutize as _;

Expand Down Expand Up @@ -591,7 +593,7 @@ mod tests {
// Given

let genesis = RawGenesisBlockBuilder::default()
.executor(ExecutorMode::Path(ExecutorPath("./executor.wasm".into())))
.executor_file(PathBuf::from("./executor.wasm"))
.build();

let config = {
Expand Down Expand Up @@ -649,7 +651,7 @@ mod tests {
// Given

let genesis = RawGenesisBlockBuilder::default()
.executor(ExecutorMode::Path(ExecutorPath("./executor.wasm".into())))
.executor_file(PathBuf::from("./executor.wasm"))
.build();

let config = {
Expand Down
10 changes: 4 additions & 6 deletions client/benches/torii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn query_requests(criterion: &mut Criterion) {
get_key_pair().public_key().clone(),
)
.finish_domain()
.executor(
.executor_blob(
construct_executor("../default_executor").expect("Failed to construct executor"),
)
.build(),
Expand All @@ -45,8 +45,7 @@ fn query_requests(criterion: &mut Criterion) {
.genesis
.key_pair()
.expect("genesis config should be full, probably a bug"),
)
.expect("genesis creation failed");
);

let builder = PeerBuilder::new()
.with_config(configuration)
Expand Down Expand Up @@ -143,7 +142,7 @@ fn instruction_submits(criterion: &mut Criterion) {
configuration.common.key_pair.public_key().clone(),
)
.finish_domain()
.executor(
.executor_blob(
construct_executor("../default_executor").expect("Failed to construct executor"),
)
.build(),
Expand All @@ -152,8 +151,7 @@ fn instruction_submits(criterion: &mut Criterion) {
.genesis
.key_pair()
.expect("config should be full; probably a bug"),
)
.expect("failed to create genesis");
);
let builder = PeerBuilder::new()
.with_config(configuration)
.with_into_genesis(genesis);
Expand Down
7 changes: 4 additions & 3 deletions client/examples/million_accounts_genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ fn generate_genesis(num_domains: u32) -> RawGenesisBlock {
}

builder
.executor(construct_executor("../default_executor").expect("Failed to construct executor"))
.executor_blob(
construct_executor("../default_executor").expect("Failed to construct executor"),
)
.build()
}

Expand All @@ -53,8 +55,7 @@ fn main_genesis() {
.genesis
.key_pair()
.expect("should be available in the config; probably a bug"),
)
.expect("genesis creation failed");
);

let builder = PeerBuilder::new()
.with_into_genesis(genesis)
Expand Down
2 changes: 1 addition & 1 deletion config/tests/fixtures/empty_ok_genesis.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"transactions": [],
"executor": "./executor.wasm"
"executor_file": "./executor.wasm"
}
2 changes: 1 addition & 1 deletion configs/swarm/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,5 +184,5 @@
}
]
],
"executor": "./executor.wasm"
"executor_file": "./executor.wasm"
}
25 changes: 14 additions & 11 deletions core/test_network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use iroha_client::{
use iroha_config::parameters::actual::Root as Config;
use iroha_crypto::prelude::*;
use iroha_data_model::{query::QueryOutputBox, ChainId};
use iroha_genesis::{GenesisNetwork, RawGenesisBlock};
use iroha_genesis::{GenesisNetwork, RawGenesisBlockFile};
use iroha_logger::InstrumentFutures;
use iroha_primitives::{
addr::{socket_addr, SocketAddr},
Expand Down Expand Up @@ -81,7 +81,7 @@ impl TestGenesis for GenesisNetwork {
// TODO: Fix this somehow. Probably we need to make `kagami` a library (#3253).
let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
let mut genesis =
RawGenesisBlock::from_path(manifest_dir.join("../../configs/swarm/genesis.json"))
RawGenesisBlockFile::from_path(manifest_dir.join("../../configs/swarm/genesis.json"))
.expect("Failed to deserialize genesis block from file");

let rose_definition_id =
Expand Down Expand Up @@ -126,15 +126,18 @@ impl TestGenesis for GenesisNetwork {
first_transaction.append_instruction(isi);
}

GenesisNetwork::new(genesis, &cfg.common.chain_id, {
use iroha_config::parameters::actual::Genesis;
if let Genesis::Full { key_pair, .. } = &cfg.genesis {
key_pair
} else {
unreachable!("test config should contain full genesis config (or it is a bug)")
}
})
.expect("Failed to init genesis")
GenesisNetwork::new(
genesis.try_into().expect("genesis should load fine"),
&cfg.common.chain_id,
{
use iroha_config::parameters::actual::Genesis;
if let Genesis::Full { key_pair, .. } = &cfg.genesis {
key_pair
} else {
unreachable!("test config should contain full genesis config (or it is a bug)")
}
},
)
}
}

Expand Down
29 changes: 0 additions & 29 deletions docs/source/references/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1001,20 +1001,6 @@
]
},
"ExecutorEventSet": "u32",
"ExecutorMode": {
"Enum": [
{
"tag": "Path",
"discriminant": 0,
"type": "String"
},
{
"tag": "Inline",
"discriminant": 1,
"type": "Executor"
}
]
},
"Fail": {
"Struct": [
{
Expand Down Expand Up @@ -2864,18 +2850,6 @@
}
]
},
"RawGenesisBlock": {
"Struct": [
{
"name": "transactions",
"type": "Vec<Vec<InstructionBox>>"
},
{
"name": "executor",
"type": "ExecutorMode"
}
]
},
"Register<Account>": {
"Struct": [
{
Expand Down Expand Up @@ -4114,9 +4088,6 @@
"Vec<TransactionValue>": {
"Vec": "TransactionValue"
},
"Vec<Vec<InstructionBox>>": {
"Vec": "Vec<InstructionBox>"
},
"Vec<u8>": {
"Vec": "u8"
},
Expand Down
3 changes: 3 additions & 0 deletions genesis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ serde_json = { workspace = true }
once_cell = { workspace = true }
tracing = { workspace = true }
eyre = { workspace = true }

[dev-dependencies]
iroha_crypto = { workspace = true, features = ["rand"] }
Loading

0 comments on commit c9dce26

Please sign in to comment.