From ace1afabca30aa7498a95a6c1f8f24ed7865140c Mon Sep 17 00:00:00 2001 From: VAmuzing Date: Wed, 3 Apr 2024 02:48:36 +0300 Subject: [PATCH] [fix] genesis to have 1 transaction: executor fix tests change test_env.py to reflect the changes Signed-off-by: VAmuzing --- Cargo.lock | 2 +- cli/Cargo.toml | 2 +- cli/src/lib.rs | 6 +- config/iroha_test_config.toml | 1 - config/src/parameters/user.rs | 33 ++------- config/tests/fixtures.rs | 9 +-- config/tests/fixtures/absolute_paths.toml | 2 +- .../tests/fixtures/bad.extends_nowhere.toml | 2 +- config/tests/fixtures/bad.extra_fields.toml | 2 +- config/tests/fixtures/bad.missing_fields.toml | 2 +- config/tests/fixtures/base.toml | 2 +- config/tests/fixtures/empty_ok_genesis.json | 2 +- config/tests/fixtures/full.env | 2 - config/tests/fixtures/full.toml | 1 - .../tests/fixtures/inconsistent_genesis.toml | 3 +- .../fixtures/minimal_alone_with_genesis.toml | 3 +- .../tests/fixtures/minimal_file_and_env.env | 2 +- config/tests/fixtures/multiple_extends.1.toml | 2 +- config/tests/fixtures/multiple_extends.2.toml | 2 +- .../tests/fixtures/multiple_extends.2a.toml | 2 +- config/tests/fixtures/multiple_extends.toml | 2 +- configs/peer.template.toml | 1 - core/test_network/src/lib.rs | 11 +-- genesis/src/lib.rs | 23 +++++- hooks/pre-commit.sample | 6 +- scripts/test_env.py | 43 +++++++---- tools/kagami/src/crypto.rs | 3 +- tools/swarm/src/compose.rs | 72 ++----------------- 28 files changed, 88 insertions(+), 155 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4cacfb1766b..ba3b0a33747 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2688,8 +2688,8 @@ dependencies = [ "json5", "once_cell", "owo-colors", - "parity-scale-codec", "path-absolutize", + "serde_json", "serial_test", "supports-color 2.1.0", "tempfile", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index ee6c75e1083..cf4df61f82b 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -58,8 +58,8 @@ tracing = { workspace = true } tokio = { workspace = true, features = ["macros", "signal"] } once_cell = { workspace = true } owo-colors = { workspace = true, features = ["supports-colors"] } -parity-scale-codec = { workspace = true } supports-color = { workspace = true } +serde_json = { workspace = true } thread-local-panic-hook = { version = "0.1.0", optional = true } diff --git a/cli/src/lib.rs b/cli/src/lib.rs index d52a26d5065..0fbd8b58b1d 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -36,8 +36,6 @@ use tokio::{ task, }; -use parity_scale_codec::Decode; - // FIXME: move from CLI pub mod samples; @@ -520,9 +518,9 @@ pub fn read_config_and_genesis>( .wrap_err("failed to load configuration")?; let genesis = if let Genesis::Full { public_key: _, file } = &config.genesis { - let encoded_block = fs::read(file)?; + let signed_json_block = fs::read(file)?; - Some(GenesisNetwork::decode(&mut encoded_block.as_slice())?) + Some(serde_json::from_slice(signed_json_block.as_slice())?) } else { None }; diff --git a/config/iroha_test_config.toml b/config/iroha_test_config.toml index 0325903d1d2..daef9dd94a1 100644 --- a/config/iroha_test_config.toml +++ b/config/iroha_test_config.toml @@ -7,7 +7,6 @@ address = "127.0.0.1:1337" [genesis] public_key = "ed01204CFFD0EE429B1BDD36B3910EC570852B8BB63F18750341772FB46BC856C5CAAF" -public_key_algorithm = "ed25519" file = "./genesis.json" [torii] diff --git a/config/src/parameters/user.rs b/config/src/parameters/user.rs index f7485abb8e5..58ab90df2f2 100644 --- a/config/src/parameters/user.rs +++ b/config/src/parameters/user.rs @@ -146,14 +146,7 @@ impl Root { None }, Some); - let genesis = self.genesis.parse().map_or_else( - |err| { - // FIXME - emitter.emit(eyre!("{err}")); - None - }, - Some, - ); + let genesis = self.genesis.parse(); let kura = self.kura.parse(); @@ -197,7 +190,6 @@ impl Root { p2p_address, }; let (telemetry, dev_telemetry) = telemetries.unwrap(); - let genesis = genesis.unwrap(); let sumeragi = { let mut x = sumeragi.unwrap(); x.trusted_peers.push(peer.peer_id()); @@ -223,7 +215,6 @@ impl Root { } } -// TODO: FIX? pub(crate) fn private_key_from_env( emitter: &mut Emitter, env: &impl ReadEnv, @@ -296,15 +287,15 @@ pub struct Genesis { } impl Genesis { - fn parse(self) -> Result { + fn parse(self) -> actual::Genesis { match self.file { - None => Ok(actual::Genesis::Partial { + None => actual::Genesis::Partial { public_key: self.public_key, - }), - Some(file) => Ok(actual::Genesis::Full { + }, + Some(file) => actual::Genesis::Full { public_key: self.public_key, file, - }), + }, // (Some(_), Some(_), false) => Err(GenesisConfigError::GenesisWithoutSubmit), // (None, None, true) => Err(GenesisConfigError::SubmitWithoutGenesis), // _ => Err(GenesisConfigError::Inconsistent), @@ -312,18 +303,6 @@ impl Genesis { } } -#[derive(Debug, displaydoc::Display, thiserror::Error)] -pub enum GenesisConfigError { - /// `genesis.file` and `genesis.private_key` are presented, but `--submit-genesis` was not set - GenesisWithoutSubmit, - /// `--submit-genesis` was set, but `genesis.file` and `genesis.private_key` are not presented - SubmitWithoutGenesis, - /// `genesis.file` and `genesis.private_key` should be set together - Inconsistent, - /// failed to construct the genesis's keypair using `genesis.public_key` and `genesis.private_key` configuration parameters - KeyPair(#[from] iroha_crypto::error::Error), -} - #[derive(Debug)] pub struct Kura { pub init_mode: KuraInitMode, diff --git a/config/tests/fixtures.rs b/config/tests/fixtures.rs index ab5ab64fcb6..6efdbd668fb 100644 --- a/config/tests/fixtures.rs +++ b/config/tests/fixtures.rs @@ -179,6 +179,7 @@ fn config_with_genesis() -> Result<()> { } #[test] +#[ignore = "--submit-genesis was removed, more in #4225"] fn minimal_with_genesis_but_no_cli_arg_fails() -> Result<()> { let error = RootPartial::from_toml(fixtures_dir().join("minimal_alone_with_genesis.toml"))? .unwrap_partial()? @@ -194,6 +195,7 @@ fn minimal_with_genesis_but_no_cli_arg_fails() -> Result<()> { } #[test] +#[ignore = "--submit-genesis was removed, more in #4225"] fn minimal_without_genesis_but_with_submit_fails() -> Result<()> { let error = RootPartial::from_toml(fixtures_dir().join("minimal_with_trusted_peers.toml"))? .unwrap_partial()? @@ -250,6 +252,7 @@ fn extra_fields() { } #[test] +#[ignore = "temporarily, more in #4225"] fn inconsistent_genesis_config() -> Result<()> { let error = RootPartial::from_toml(fixtures_dir().join("inconsistent_genesis.toml"))? .unwrap_partial() @@ -304,11 +307,6 @@ fn full_envs_set_is_consumed() -> Result<()> { ), ), ), - private_key: Some( - ed25519( - "8F4C15E5D664DA3F13778801D23D4E89B76E94C1B94B389544168B6CB894F84F8BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB", - ), - ), file: None, }, kura: KuraPartial { @@ -422,7 +420,6 @@ fn multiple_env_parsing_errors() { let expected = expect_test::expect![[r#" `PRIVATE_KEY_PAYLOAD` env was provided, but `PRIVATE_KEY_ALGORITHM` was not - failed to parse `genesis.private_key.algorithm` field from `GENESIS_PRIVATE_KEY_ALGORITHM` env variable failed to parse `kura.debug.output_new_blocks` field from `KURA_DEBUG_OUTPUT_NEW_BLOCKS` env variable failed to parse `logger.format` field from `LOG_FORMAT` env variable failed to parse `torii.address` field from `API_ADDRESS` env variable"#]]; diff --git a/config/tests/fixtures/absolute_paths.toml b/config/tests/fixtures/absolute_paths.toml index c176502b257..cf29613b496 100644 --- a/config/tests/fixtures/absolute_paths.toml +++ b/config/tests/fixtures/absolute_paths.toml @@ -11,4 +11,4 @@ out_file = "/telemetry/file.json" [genesis] file = "/oh/my/genesis.json" -private_key = { algorithm = "ed25519", payload = "8f4c15e5d664da3f13778801d23d4e89b76e94c1b94b389544168b6cb894f84f8ba62848cf767d72e7f7f4b9d2d7ba07fee33760f79abe5597a51520e292a0cb" } \ No newline at end of file +public_key = "ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB" diff --git a/config/tests/fixtures/bad.extends_nowhere.toml b/config/tests/fixtures/bad.extends_nowhere.toml index 30129b39359..aa129652c1f 100644 --- a/config/tests/fixtures/bad.extends_nowhere.toml +++ b/config/tests/fixtures/bad.extends_nowhere.toml @@ -1 +1 @@ -extends = "nowhere.toml" \ No newline at end of file +extends = "nowhere.toml" diff --git a/config/tests/fixtures/bad.extra_fields.toml b/config/tests/fixtures/bad.extra_fields.toml index bc2baaf8783..6edf6f057f4 100644 --- a/config/tests/fixtures/bad.extra_fields.toml +++ b/config/tests/fixtures/bad.extra_fields.toml @@ -1,4 +1,4 @@ # Iroha should not silently ignore extra fields i_am_unknown = true foo = false -bar = 0.5 \ No newline at end of file +bar = 0.5 diff --git a/config/tests/fixtures/bad.missing_fields.toml b/config/tests/fixtures/bad.missing_fields.toml index d5bd33cac2e..c5bb0c61aa7 100644 --- a/config/tests/fixtures/bad.missing_fields.toml +++ b/config/tests/fixtures/bad.missing_fields.toml @@ -1 +1 @@ -# all fields are missing \ No newline at end of file +# all fields are missing diff --git a/config/tests/fixtures/base.toml b/config/tests/fixtures/base.toml index 052b9a6df5b..1e7a5fadbf3 100644 --- a/config/tests/fixtures/base.toml +++ b/config/tests/fixtures/base.toml @@ -10,4 +10,4 @@ address = "127.0.0.1:1337" public_key = "ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB" [torii] -address = "127.0.0.1:8080" \ No newline at end of file +address = "127.0.0.1:8080" diff --git a/config/tests/fixtures/empty_ok_genesis.json b/config/tests/fixtures/empty_ok_genesis.json index 08e913dbb74..2888613b763 100644 --- a/config/tests/fixtures/empty_ok_genesis.json +++ b/config/tests/fixtures/empty_ok_genesis.json @@ -1,4 +1,4 @@ { "transactions": [], "executor_file": "./executor.wasm" -} \ No newline at end of file +} diff --git a/config/tests/fixtures/full.env b/config/tests/fixtures/full.env index 35b61e9e5f7..8465960ada8 100644 --- a/config/tests/fixtures/full.env +++ b/config/tests/fixtures/full.env @@ -4,8 +4,6 @@ PRIVATE_KEY_ALGORITHM=ed25519 PRIVATE_KEY_PAYLOAD=8f4c15e5d664da3f13778801d23d4e89b76e94c1b94b389544168b6cb894f84f8ba62848cf767d72e7f7f4b9d2d7ba07fee33760f79abe5597a51520e292a0cb P2P_ADDRESS=127.0.0.1:5432 GENESIS_PUBLIC_KEY=ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB -GENESIS_PRIVATE_KEY_ALGORITHM=ed25519 -GENESIS_PRIVATE_KEY_PAYLOAD=8f4c15e5d664da3f13778801d23d4e89b76e94c1b94b389544168b6cb894f84f8ba62848cf767d72e7f7f4b9d2d7ba07fee33760f79abe5597a51520e292a0cb API_ADDRESS=127.0.0.1:8080 KURA_INIT_MODE=strict KURA_STORE_DIR=/store/path/from/env diff --git a/config/tests/fixtures/full.toml b/config/tests/fixtures/full.toml index f38ad0e38ef..d269c8cc011 100644 --- a/config/tests/fixtures/full.toml +++ b/config/tests/fixtures/full.toml @@ -7,7 +7,6 @@ private_key = { algorithm = "ed25519", payload = "8f4c15e5d664da3f13778801d23d4e [genesis] file = "genesis.json" public_key = "ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB" -private_key = { algorithm = "ed25519", payload = "8f4c15e5d664da3f13778801d23d4e89b76e94c1b94b389544168b6cb894f84f8ba62848cf767d72e7f7f4b9d2d7ba07fee33760f79abe5597a51520e292a0cb" } [network] address = "localhost:3840" diff --git a/config/tests/fixtures/inconsistent_genesis.toml b/config/tests/fixtures/inconsistent_genesis.toml index 6aabaa5e05f..ac540353b32 100644 --- a/config/tests/fixtures/inconsistent_genesis.toml +++ b/config/tests/fixtures/inconsistent_genesis.toml @@ -1,7 +1,6 @@ extends = "base.toml" [genesis] -private_key.algorithm = "ed25519" -private_key.payload = "8f4c15e5d664da3f13778801d23d4e89b76e94c1b94b389544168b6cb894f84f8ba62848cf767d72e7f7f4b9d2d7ba07fee33760f79abe5597a51520e292a0cb" +public_key = "ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB" # should fail without it: # file = ... diff --git a/config/tests/fixtures/minimal_alone_with_genesis.toml b/config/tests/fixtures/minimal_alone_with_genesis.toml index 3dd6c5f3c2c..8b886c8b8f5 100644 --- a/config/tests/fixtures/minimal_alone_with_genesis.toml +++ b/config/tests/fixtures/minimal_alone_with_genesis.toml @@ -2,5 +2,4 @@ extends = "base.toml" [genesis] file = "./empty_ok_genesis.json" -private_key.algorithm = "ed25519" -private_key.payload = "8f4c15e5d664da3f13778801d23d4e89b76e94c1b94b389544168b6cb894f84f8ba62848cf767d72e7f7f4b9d2d7ba07fee33760f79abe5597a51520e292a0cb" +public_key = "ed01208BA62848CF767D72E7F7F4B9D2D7BA07FEE33760F79ABE5597A51520E292A0CB" diff --git a/config/tests/fixtures/minimal_file_and_env.env b/config/tests/fixtures/minimal_file_and_env.env index 7ee9d329ee5..6697ecec2d4 100644 --- a/config/tests/fixtures/minimal_file_and_env.env +++ b/config/tests/fixtures/minimal_file_and_env.env @@ -1 +1 @@ -API_ADDRESS=127.0.0.1:8080 \ No newline at end of file +API_ADDRESS=127.0.0.1:8080 diff --git a/config/tests/fixtures/multiple_extends.1.toml b/config/tests/fixtures/multiple_extends.1.toml index 46b1262777b..b85ade6408c 100644 --- a/config/tests/fixtures/multiple_extends.1.toml +++ b/config/tests/fixtures/multiple_extends.1.toml @@ -1,2 +1,2 @@ [logger] -format = "pretty" \ No newline at end of file +format = "pretty" diff --git a/config/tests/fixtures/multiple_extends.2.toml b/config/tests/fixtures/multiple_extends.2.toml index 47e9616ccfd..d40128c0a3c 100644 --- a/config/tests/fixtures/multiple_extends.2.toml +++ b/config/tests/fixtures/multiple_extends.2.toml @@ -2,4 +2,4 @@ extends = "multiple_extends.2a.toml" [logger] -format = "compact" \ No newline at end of file +format = "compact" diff --git a/config/tests/fixtures/multiple_extends.2a.toml b/config/tests/fixtures/multiple_extends.2a.toml index c7b048bc674..57af8e433b0 100644 --- a/config/tests/fixtures/multiple_extends.2a.toml +++ b/config/tests/fixtures/multiple_extends.2a.toml @@ -1,2 +1,2 @@ [logger] -level = "DEBUG" \ No newline at end of file +level = "DEBUG" diff --git a/config/tests/fixtures/multiple_extends.toml b/config/tests/fixtures/multiple_extends.toml index 83b87043034..e6b277be4e9 100644 --- a/config/tests/fixtures/multiple_extends.toml +++ b/config/tests/fixtures/multiple_extends.toml @@ -3,4 +3,4 @@ extends = ["multiple_extends.1.toml", "multiple_extends.2.toml"] [logger] # final value -level = "ERROR" \ No newline at end of file +level = "ERROR" diff --git a/configs/peer.template.toml b/configs/peer.template.toml index bc01942940e..65d16144510 100644 --- a/configs/peer.template.toml +++ b/configs/peer.template.toml @@ -16,7 +16,6 @@ [genesis] # file = # public_key = -# private_key = { algorithm = "", payload = "" } [network] # address = diff --git a/core/test_network/src/lib.rs b/core/test_network/src/lib.rs index 1105147b6f6..19437598f3a 100644 --- a/core/test_network/src/lib.rs +++ b/core/test_network/src/lib.rs @@ -130,16 +130,7 @@ impl TestGenesis for GenesisNetwork { GenesisNetwork::new( genesis.try_into().expect("genesis should load fine"), &cfg.common.chain_id, - // TODO: FIX - &KeyPair::random() - // { - // 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)") - // } - // }, + &cfg.common.key_pair, ) } } diff --git a/genesis/src/lib.rs b/genesis/src/lib.rs index 8f9f5e5ed20..32ba38684b6 100644 --- a/genesis/src/lib.rs +++ b/genesis/src/lib.rs @@ -43,13 +43,32 @@ impl GenesisNetwork { raw_block: RawGenesisBlock, chain_id: &ChainId, genesis_key_pair: &KeyPair, + ) -> GenesisNetwork { + Self::new_with_executor_and_txs(raw_block.executor, raw_block.transactions, chain_id, genesis_key_pair) + } + + /// Construct from configuration with only [`Executor`] from genesis block + pub fn new_without_transactions( + raw_block: RawGenesisBlock, + chain_id: &ChainId, + genesis_key_pair: &KeyPair, + ) -> GenesisNetwork { + Self::new_with_executor_and_txs(raw_block.executor, Vec::new(), chain_id, genesis_key_pair) + } + + /// Construct from configuration with explicit separation between [`Executor`] and transactions + fn new_with_executor_and_txs( + executor: Executor, + transactions: Vec, + chain_id: &ChainId, + genesis_key_pair: &KeyPair, ) -> GenesisNetwork { // The first instruction should be Executor upgrade. // This makes it possible to grant permissions to users in genesis. let transactions_iter = std::iter::once(GenesisTransactionBuilder { - isi: vec![Upgrade::new(raw_block.executor).into()], + isi: vec![Upgrade::new(executor).into()], }) - .chain(raw_block.transactions); + .chain(transactions); let transactions = transactions_iter .map(|raw_transaction| raw_transaction.sign(chain_id.clone(), genesis_key_pair)) diff --git a/hooks/pre-commit.sample b/hooks/pre-commit.sample index 978c34e590c..cb2ec5d9621 100755 --- a/hooks/pre-commit.sample +++ b/hooks/pre-commit.sample @@ -4,6 +4,6 @@ cargo +nightly fmt --all -- --check cargo +nightly lints clippy --workspace --benches --tests --examples --all-features cargo run --bin kagami -- genesis >configs/swarm/genesis.json cargo run --bin kagami -- schema >docs/source/references/schema.json -cargo run --bin kagami -- crypto key-pair-generation -j >configs/swarm/keypair.json -cargo run --bin kagami -- crypto --keypair-path configs/swarm/keypair.json --genesis-path configs/swarm/genesis.json --chain-id 01234 -o configs/swarm/signes_genesis.scale -git add configs/peer/genesis.json configs/swarm/keypair.json configs/swarm/signes_genesis.scale docs/source/references/schema.json +cargo run --bin kagami -- crypto generate-key-pair -j >configs/swarm/keypair.json +cargo run --bin kagami -- crypto sign-transaction --keypair-file configs/swarm/keypair.json --genesis-file configs/swarm/genesis.json --chain-id 00000000-0000-0000-0000-000000000000 --out-file configs/swarm/signed_genesis.json +git add configs/peer/genesis.json configs/swarm/keypair.json configs/swarm/signed_genesis.json docs/source/references/schema.json diff --git a/scripts/test_env.py b/scripts/test_env.py index 1e5b7144323..beaad9f498b 100755 --- a/scripts/test_env.py +++ b/scripts/test_env.py @@ -21,6 +21,7 @@ SWARM_CONFIGS_DIRECTORY = pathlib.Path("configs/swarm") SHARED_CONFIG_FILE_NAME = "config.base.toml" +CHAIN_ID = "00000000-0000-0000-0000-000000000000" class Network: """ @@ -38,9 +39,12 @@ def __init__(self, args: argparse.Namespace): logging.info("Generating shared configuration...") trusted_peers = [{"address": f"{peer.host_ip}:{peer.p2p_port}", "public_key": peer.public_key} for peer in self.peers] shared_config = { - "chain_id": "00000000-0000-0000-0000-000000000000", + "chain_id": CHAIN_ID, "genesis": { - "public_key": self.peers[0].public_key + "public_key": self.peers[0].public_key, + # At this moment the inclusion of file parameter causes all peers but one to crash because of a race condition + # More on that will be in #4388 + # "file": "./signed_genesis.json" }, "sumeragi": { "trusted_peers": trusted_peers @@ -77,7 +81,7 @@ def wait_for_genesis(self, n_tries: int): def run(self): for i, peer in enumerate(self.peers): - peer.run(submit_genesis=(i == 0)) + peer.run() self.wait_for_genesis(20) class _Peer: @@ -99,19 +103,18 @@ def __init__(self, args: argparse.Namespace, nth: int): logging.info(f"Peer {self.name} generating key pair...") - command = [self.out_dir / "kagami", "crypto", "-j"] + command = [self.out_dir / "kagami", "crypto", "generate-key-pair", "-j"] if args.peer_name_as_seed: command.extend(["-s", self.name]) - kagami = subprocess.run(command, capture_output=True) - if kagami.returncode: + kagami_keypair = subprocess.run(command, capture_output=True) + if kagami_keypair.returncode: logging.error("Kagami failed to generate a key pair.") sys.exit(3) - str_keypair = kagami.stdout + str_keypair = kagami_keypair.stdout # dict with `{ public_key: string, private_key: { algorithm: string, payload: string } }` self.key_pair = json.loads(str_keypair) os.makedirs(self.peer_dir, exist_ok=True) - config = { "extends": f"../{SHARED_CONFIG_FILE_NAME}", "public_key": self.public_key, @@ -143,10 +146,24 @@ def __init__(self, args: argparse.Namespace, nth: int): logging.error(f"Some of the config files are missing. \ Please provide them in the `{target}` directory") sys.exit(1) + + sign_command = [self.out_dir / "kagami", "crypto", "sign-transaction", "--chain-id", CHAIN_ID, + "--genesis-file", self.peer_dir / "./genesis.json", "--out-file", self.peer_dir/ "./signed_genesis.json", + "-a", self.private_key["algorithm"], + "--private-key-string", self.private_key["payload"], + "--public-key-string", self.public_key] + + kagami_genesis = subprocess.run(sign_command, capture_output=True) + if kagami_genesis.returncode: + logging.error(kagami_genesis.stderr) + logging.error("Kagami failed to sign genesis block.") + sys.exit(5) + config["genesis"] = { - "private_key": self.private_key, - "file": "./genesis.json" + "public_key": self.public_key, + "file": "./signed_genesis.json" } + with open(self.config_path, "wb") as f: tomli_w.dump(config, f) logging.info(f"Peer {self.name} initialized") @@ -159,14 +176,14 @@ def public_key(self): def private_key(self): return self.key_pair["private_key"] - def run(self, submit_genesis: bool = False): + def run(self): logging.info(f"Running peer {self.name}...") # FD never gets closed stdout_file = open(self.peer_dir / ".stdout", "w") stderr_file = open(self.peer_dir / ".stderr", "w") # These processes are created detached from the parent process already - subprocess.Popen([self.name, "--config", self.config_path] + (["--submit-genesis"] if submit_genesis else []), + subprocess.Popen([self.name, "--config", self.config_path], executable=self.out_dir / "peers/iroha", stdout=stdout_file, stderr=stderr_file) def pos_int(arg): @@ -175,6 +192,7 @@ def pos_int(arg): else: raise argparse.ArgumentTypeError(f"Argument {arg} must be a positive integer") + def copy_or_prompt_build_bin(bin_name: str, root_dir: pathlib.Path, target_dir: pathlib.Path): bin_path = root_dir / "target/debug" / bin_name try: @@ -247,7 +265,6 @@ def cleanup(out_dir: pathlib.Path): Defaults to 4. If setup was run with a custom number of peers, \ the same number doesn't need to be provided to cleanup as \ it kills all processes named `iroha`, so proper caution is advised") - parser.add_argument("--out-dir", "-o", default="./test", type=pathlib.Path, help="Directory to store config and log files. \ Defaults to `./test`. If setup was run with a custom directory, \ diff --git a/tools/kagami/src/crypto.rs b/tools/kagami/src/crypto.rs index fdc29290033..29f7d30f5de 100644 --- a/tools/kagami/src/crypto.rs +++ b/tools/kagami/src/crypto.rs @@ -151,7 +151,7 @@ impl RunArgs for SignGenesisArgs { }; let genesis_block = RawGenesisBlock::from_path(&self.genesis_file)?; - let genesis_network = GenesisNetwork::new(genesis_block, &self.chain_id, &key_pair); + let genesis_network = GenesisNetwork::new_without_transactions(genesis_block, &self.chain_id, &key_pair); let encoded_genesis_network = if self.scale { genesis_network.encode() @@ -289,6 +289,7 @@ impl GenerateKeyPairArgs { #[cfg(test)] mod tests { + // use iroha_data_model::transaction::{SignedTransactionV1, TransactionPayload}; use parity_scale_codec::Decode; use super::*; diff --git a/tools/swarm/src/compose.rs b/tools/swarm/src/compose.rs index 4e4cbc328fb..63b09782b4b 100644 --- a/tools/swarm/src/compose.rs +++ b/tools/swarm/src/compose.rs @@ -8,7 +8,7 @@ use std::{ }; use color_eyre::eyre::{eyre, Context, ContextCompat}; -use iroha_crypto::{Algorithm, KeyPair, PrivateKey, PublicKey}; +use iroha_crypto::{Algorithm, KeyPair, PublicKey}; use iroha_data_model::{prelude::PeerId, ChainId}; use iroha_primitives::addr::{socket_addr, SocketAddr}; use peer_generator::Peer; @@ -20,8 +20,6 @@ use crate::{cli::SourceParsed, util::AbsolutePath}; const DIR_CONFIG_IN_DOCKER: &str = "/config"; const PATH_TO_GENESIS: &str = "/config/genesis.json"; const GENESIS_KEYPAIR_SEED: &[u8; 7] = b"genesis"; -// TODO: FIX -const COMMAND_SUBMIT_GENESIS: &str = "iroha --submit-genesis"; const DOCKER_COMPOSE_VERSION: &str = "3.8"; const PLATFORM_ARCHITECTURE: &str = "linux/amd64"; @@ -93,7 +91,6 @@ pub struct DockerComposeServiceBuilder { volumes: Vec<(String, String)>, trusted_peers: BTreeSet, genesis_public_key: PublicKey, - genesis_private_key: Option, health_check: bool, } @@ -106,8 +103,6 @@ pub struct DockerComposeService { ports: Vec>, volumes: Vec>, init: AlwaysTrue, - #[serde(skip_serializing_if = "ServiceCommand::is_none")] - command: ServiceCommand, #[serde(skip_serializing_if = "Option::is_none")] healthcheck: Option, } @@ -128,7 +123,6 @@ impl DockerComposeServiceBuilder { volumes, trusted_peers, genesis_public_key, - genesis_private_key: None, health_check: false, } } @@ -138,11 +132,6 @@ impl DockerComposeServiceBuilder { self } - pub fn submit_genesis_with(mut self, private_key: PrivateKey) -> Self { - self.genesis_private_key = Some(private_key); - self - } - pub fn build(self) -> DockerComposeService { let Self { chain_id, @@ -151,7 +140,6 @@ impl DockerComposeServiceBuilder { volumes, trusted_peers, genesis_public_key, - genesis_private_key, health_check, } = self; @@ -160,12 +148,6 @@ impl DockerComposeServiceBuilder { PairColon(peer.port_api, peer.port_api), ]; - let command = if genesis_private_key.is_some() { - ServiceCommand::SubmitGenesis - } else { - ServiceCommand::None - }; - let compact_env = CompactPeerEnv { chain_id, trusted_peers, @@ -178,7 +160,6 @@ impl DockerComposeServiceBuilder { DockerComposeService { source, platform: PlatformArchitecture, - command, init: AlwaysTrue, volumes: volumes.into_iter().map(|(a, b)| PairColon(a, b)).collect(), ports, @@ -202,30 +183,6 @@ impl Serialize for AlwaysTrue { } } -#[derive(Debug)] -enum ServiceCommand { - SubmitGenesis, - None, -} - -impl ServiceCommand { - fn is_none(&self) -> bool { - matches!(self, Self::None) - } -} - -impl Serialize for ServiceCommand { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - match self { - Self::None => serializer.serialize_none(), - Self::SubmitGenesis => serializer.serialize_str(COMMAND_SUBMIT_GENESIS), - } - } -} - /// Serializes as a Iroha health check according to the /// [spec](https://docs.docker.com/compose/compose-file/compose-file-v3/#healthcheck). #[derive(Debug)] @@ -304,7 +261,6 @@ struct FullPeerEnv { p2p_address: SocketAddr, api_address: SocketAddr, genesis_public_key: PublicKey, - genesis_public_key_algorithm: Algorithm, genesis_file: Option, #[serde_as(as = "Option")] sumeragi_trusted_peers: Option>, @@ -319,21 +275,9 @@ struct CompactPeerEnv { trusted_peers: BTreeSet, } -// TODO: FIX impl From for FullPeerEnv { fn from(value: CompactPeerEnv) -> Self { let genesis_file = Some(PATH_TO_GENESIS.to_string()); - // TODO: FIX - // let (genesis_private_key_algorithm, genesis_private_key_payload, genesis_file) = value - // .genesis_private_key - // .map_or((None, None, None), |private_key| { - // let (algorithm, payload) = private_key.to_bytes(); - // ( - // Some(algorithm), - // Some(payload), - // Some(PATH_TO_GENESIS.to_string()), - // ) - // }); let (private_key_algorithm, private_key_payload) = { let (algorithm, payload) = value.key_pair.private_key().clone().to_bytes(); @@ -345,7 +289,6 @@ impl From for FullPeerEnv { public_key: value.key_pair.public_key().clone(), private_key_algorithm, private_key_payload, - genesis_public_key_algorithm: value.genesis_public_key.algorithm(), genesis_public_key: value.genesis_public_key, genesis_file, p2p_address: value.p2p_addr, @@ -418,7 +361,6 @@ impl DockerComposeBuilder<'_> { .collect(), genesis_key_pair.public_key().clone(), ) - .submit_genesis_with(genesis_key_pair.private_key().clone()) .set_health_check(self.health_check) .build(); @@ -548,7 +490,6 @@ impl TryFrom for ResolvedImageSource { } } -// TODO: FIX TESTS #[cfg(test)] mod tests { use std::{ @@ -665,7 +606,6 @@ mod tests { "/config".to_owned(), )], init: AlwaysTrue, - command: ServiceCommand::SubmitGenesis, healthcheck: None, }, ); @@ -690,8 +630,6 @@ mod tests { P2P_ADDRESS: iroha1:1339 API_ADDRESS: iroha1:1338 GENESIS_PUBLIC_KEY: ed012039E5BF092186FACC358770792A493CA98A83740643A3D41389483CF334F748C8 - GENESIS_PRIVATE_KEY_ALGORITHM: ed25519 - GENESIS_PRIVATE_KEY_PAYLOAD: db9d90d20f969177bd5882f9fe211d14d1399d5440d04e3468783d169bbc4a8e39e5bf092186facc358770792a493ca98a83740643a3d41389483cf334f748c8 GENESIS_FILE: /config/genesis.json ports: - 1337:1337 @@ -700,7 +638,6 @@ mod tests { volumes: - ./configs/peer/legacy_stable:/config init: true - command: iroha --submit-genesis "#]]; expected.assert_eq(&actual); } @@ -731,6 +668,7 @@ mod tests { P2P_ADDRESS: iroha0:1337 API_ADDRESS: iroha0:1337 GENESIS_PUBLIC_KEY: ed0120415388A90FA238196737746A70565D041CFB32EAA0C89FF8CB244C7F832A6EBD + GENESIS_FILE: /config/genesis.json "#]]; expected.assert_eq(&actual); } @@ -773,8 +711,6 @@ mod tests { P2P_ADDRESS: 0.0.0.0:1337 API_ADDRESS: 0.0.0.0:8080 GENESIS_PUBLIC_KEY: ed01203420F48A9EEB12513B8EB7DAF71979CE80A1013F5F341C10DCDA4F6AA19F97A9 - GENESIS_PRIVATE_KEY_ALGORITHM: ed25519 - GENESIS_PRIVATE_KEY_PAYLOAD: 5a6d5f06a90d29ad906e2f6ea8b41b4ef187849d0d397081a4a15ffcbe71e7c73420f48a9eeb12513b8eb7daf71979ce80a1013f5f341c10dcda4f6aa19f97a9 GENESIS_FILE: /config/genesis.json SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha2:1339","public_key":"ed0120312C1B7B5DE23D366ADCF23CD6DB92CE18B2AA283C7D9F5033B969C2DC2B92F4"},{"address":"iroha3:1340","public_key":"ed0120854457B2E3D6082181DA73DC01C1E6F93A72D0C45268DC8845755287E98A5DEE"},{"address":"iroha1:1338","public_key":"ed0120A88554AA5C86D28D0EEBEC497235664433E807881CD31E12A1AF6C4D8B0F026C"}]' ports: @@ -783,7 +719,6 @@ mod tests { volumes: - ./config:/config init: true - command: iroha --submit-genesis healthcheck: test: test $(curl -s http://127.0.0.1:8080/status/blocks) -gt 0 interval: 2s @@ -801,6 +736,7 @@ mod tests { P2P_ADDRESS: 0.0.0.0:1338 API_ADDRESS: 0.0.0.0:8081 GENESIS_PUBLIC_KEY: ed01203420F48A9EEB12513B8EB7DAF71979CE80A1013F5F341C10DCDA4F6AA19F97A9 + GENESIS_FILE: /config/genesis.json SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha2:1339","public_key":"ed0120312C1B7B5DE23D366ADCF23CD6DB92CE18B2AA283C7D9F5033B969C2DC2B92F4"},{"address":"iroha3:1340","public_key":"ed0120854457B2E3D6082181DA73DC01C1E6F93A72D0C45268DC8845755287E98A5DEE"},{"address":"iroha0:1337","public_key":"ed0120F0321EB4139163C35F88BF78520FF7071499D7F4E79854550028A196C7B49E13"}]' ports: - 1338:1338 @@ -825,6 +761,7 @@ mod tests { P2P_ADDRESS: 0.0.0.0:1339 API_ADDRESS: 0.0.0.0:8082 GENESIS_PUBLIC_KEY: ed01203420F48A9EEB12513B8EB7DAF71979CE80A1013F5F341C10DCDA4F6AA19F97A9 + GENESIS_FILE: /config/genesis.json SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha3:1340","public_key":"ed0120854457B2E3D6082181DA73DC01C1E6F93A72D0C45268DC8845755287E98A5DEE"},{"address":"iroha1:1338","public_key":"ed0120A88554AA5C86D28D0EEBEC497235664433E807881CD31E12A1AF6C4D8B0F026C"},{"address":"iroha0:1337","public_key":"ed0120F0321EB4139163C35F88BF78520FF7071499D7F4E79854550028A196C7B49E13"}]' ports: - 1339:1339 @@ -849,6 +786,7 @@ mod tests { P2P_ADDRESS: 0.0.0.0:1340 API_ADDRESS: 0.0.0.0:8083 GENESIS_PUBLIC_KEY: ed01203420F48A9EEB12513B8EB7DAF71979CE80A1013F5F341C10DCDA4F6AA19F97A9 + GENESIS_FILE: /config/genesis.json SUMERAGI_TRUSTED_PEERS: '[{"address":"iroha2:1339","public_key":"ed0120312C1B7B5DE23D366ADCF23CD6DB92CE18B2AA283C7D9F5033B969C2DC2B92F4"},{"address":"iroha1:1338","public_key":"ed0120A88554AA5C86D28D0EEBEC497235664433E807881CD31E12A1AF6C4D8B0F026C"},{"address":"iroha0:1337","public_key":"ed0120F0321EB4139163C35F88BF78520FF7071499D7F4E79854550028A196C7B49E13"}]' ports: - 1340:1340