diff --git a/Cargo.lock b/Cargo.lock index d449cfdbf5d..60ed77cca5b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3150,6 +3150,7 @@ dependencies = [ "eyre", "iroha_crypto", "iroha_data_model", + "iroha_schema", "once_cell", "serde", "serde_json", diff --git a/configs/swarm/genesis.json b/configs/swarm/genesis.json index 9242ba5166e..7d547116ff5 100644 --- a/configs/swarm/genesis.json +++ b/configs/swarm/genesis.json @@ -1,4 +1,6 @@ { + "chain": "00000000-0000-0000-0000-000000000000", + "executor": "./executor.wasm", "instructions": [ { "Register": { @@ -185,7 +187,5 @@ } } ], - "executor": "./executor.wasm", - "chain": "00000000-0000-0000-0000-000000000000", "topology": [] } diff --git a/data_model/src/block.rs b/data_model/src/block.rs index 5827b7daf07..e1f03cea332 100644 --- a/data_model/src/block.rs +++ b/data_model/src/block.rs @@ -129,7 +129,6 @@ mod model { /// Signatures of peers which approved this block. pub(super) signatures: Vec, /// Block payload - #[serde(flatten)] pub(super) payload: BlockPayload, } } @@ -333,7 +332,6 @@ mod candidate { #[derive(Decode, Deserialize)] struct SignedBlockCandidate { signatures: Vec, - #[serde(flatten)] payload: BlockPayload, } diff --git a/data_model/src/query/mod.rs b/data_model/src/query/mod.rs index 1c89b0afa79..92ec08b6750 100644 --- a/data_model/src/query/mod.rs +++ b/data_model/src/query/mod.rs @@ -1317,7 +1317,6 @@ pub mod http { #[derive(Decode, Deserialize)] struct SignedQueryCandidate { signature: QuerySignature, - #[serde(flatten)] payload: ClientQueryPayload, } diff --git a/data_model/src/transaction.rs b/data_model/src/transaction.rs index 0ed738a7398..7ced1cab628 100644 --- a/data_model/src/transaction.rs +++ b/data_model/src/transaction.rs @@ -177,7 +177,6 @@ mod model { /// Signature of [`Self::payload`]. pub(super) signature: TransactionSignature, /// Payload of the transaction. - #[serde(flatten)] pub(super) payload: TransactionPayload, } @@ -361,7 +360,6 @@ mod candidate { #[derive(Decode, Deserialize)] struct SignedTransactionCandidate { signature: TransactionSignature, - #[serde(flatten)] payload: TransactionPayload, } diff --git a/docs/source/references/schema.json b/docs/source/references/schema.json index 1b9ce3711d9..e633ae613e1 100644 --- a/docs/source/references/schema.json +++ b/docs/source/references/schema.json @@ -3043,6 +3043,26 @@ ] }, "QuerySignature": "SignatureOf", + "RawGenesisTransaction": { + "Struct": [ + { + "name": "chain", + "type": "ChainId" + }, + { + "name": "executor", + "type": "String" + }, + { + "name": "instructions", + "type": "Vec" + }, + { + "name": "topology", + "type": "Vec" + } + ] + }, "Register": { "Struct": [ { diff --git a/genesis/Cargo.toml b/genesis/Cargo.toml index 964d5ee1aa8..49994d15f6a 100644 --- a/genesis/Cargo.toml +++ b/genesis/Cargo.toml @@ -12,6 +12,7 @@ workspace = true [dependencies] iroha_crypto = { workspace = true } +iroha_schema = { workspace = true } iroha_data_model = { workspace = true, features = ["http"] } derive_more = { workspace = true, features = ["deref"] } diff --git a/genesis/src/lib.rs b/genesis/src/lib.rs index 7bd2668fc61..9bd12b03c67 100644 --- a/genesis/src/lib.rs +++ b/genesis/src/lib.rs @@ -11,6 +11,7 @@ use std::{ use eyre::{eyre, Result, WrapErr}; use iroha_crypto::{KeyPair, PublicKey}; use iroha_data_model::{block::SignedBlock, prelude::*}; +use iroha_schema::IntoSchema; use once_cell::sync::Lazy; use serde::{Deserialize, Serialize}; @@ -34,17 +35,22 @@ pub struct GenesisBlock(pub SignedBlock); /// It should be signed, converted to [`GenesisBlock`], /// and serialized in SCALE format before supplying to Iroha peer. /// See `kagami genesis sign`. -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, IntoSchema)] pub struct RawGenesisTransaction { - instructions: Vec, - /// Path to the [`Executor`] file - executor: PathBuf, /// Unique id of blockchain chain: ChainId, + /// Path to the [`Executor`] file + executor: ExecutorPath, + instructions: Vec, /// Initial topology topology: Vec, } +/// Path to [`Executor`] file +#[derive(Debug, Clone, Deserialize, Serialize, IntoSchema)] +#[schema(transparent = "String")] +pub struct ExecutorPath(PathBuf); + impl RawGenesisTransaction { const WARN_ON_GENESIS_GTE: u64 = 1024 * 1024 * 1024; // 1Gb @@ -70,11 +76,12 @@ impl RawGenesisTransaction { path.as_ref().display() ) })?; - value.executor = path - .as_ref() - .parent() - .expect("genesis must be a file in some directory") - .join(value.executor); + value.executor = ExecutorPath( + path.as_ref() + .parent() + .expect("genesis must be a file in some directory") + .join(value.executor.0), + ); Ok(value) } @@ -95,7 +102,7 @@ impl RawGenesisTransaction { /// # Errors /// If executor couldn't be read from provided path pub fn build_and_sign(self, genesis_key_pair: &KeyPair) -> Result { - let executor = get_executor(&self.executor)?; + let executor = get_executor(&self.executor.0)?; let genesis = build_and_sign_genesis( self.instructions, executor, @@ -212,13 +219,13 @@ impl GenesisBuilder { /// Finish building and produce a [`RawGenesisTransaction`]. pub fn build_raw( self, - executor_file: PathBuf, chain_id: ChainId, + executor_file: PathBuf, topology: Vec, ) -> RawGenesisTransaction { RawGenesisTransaction { instructions: self.instructions, - executor: executor_file, + executor: ExecutorPath(executor_file), chain: chain_id, topology, } diff --git a/schema/gen/src/lib.rs b/schema/gen/src/lib.rs index 313c1c6d0f1..312c3f23ce7 100644 --- a/schema/gen/src/lib.rs +++ b/schema/gen/src/lib.rs @@ -54,6 +54,10 @@ pub fn build_schemas() -> MetaMap { // Never referenced, but present in type signature. Like `PhantomData` MerkleTree, + + // Genesis file - used by SDKs to generate the genesis block + // TODO: IMO it could/should be removed from the schema + iroha_genesis::RawGenesisTransaction, } } diff --git a/tools/kagami/src/genesis/generate.rs b/tools/kagami/src/genesis/generate.rs index 50a554af198..323a9ae612f 100644 --- a/tools/kagami/src/genesis/generate.rs +++ b/tools/kagami/src/genesis/generate.rs @@ -220,7 +220,7 @@ pub fn generate_default( // Will be replaced with actual topology either in scripts/test_env.py or in iroha_swarm let topology = vec![]; let chain_id = ChainId::from("00000000-0000-0000-0000-000000000000"); - let genesis = builder.build_raw(executor_path, chain_id, topology); + let genesis = builder.build_raw(chain_id, executor_path, topology); Ok(genesis) }