Skip to content

Commit

Permalink
fix: restore RawGenesisTransaction schema (#4765)
Browse files Browse the repository at this point in the history
Signed-off-by: Marin Veršić <marin.versic101@gmail.com>
  • Loading branch information
mversic committed Jun 24, 2024
1 parent 3dca4dd commit d5086e7
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 20 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.

4 changes: 2 additions & 2 deletions configs/swarm/genesis.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"chain": "00000000-0000-0000-0000-000000000000",
"executor": "./executor.wasm",
"instructions": [
{
"Register": {
Expand Down Expand Up @@ -185,7 +187,5 @@
}
}
],
"executor": "./executor.wasm",
"chain": "00000000-0000-0000-0000-000000000000",
"topology": []
}
2 changes: 0 additions & 2 deletions data_model/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ mod model {
/// Signatures of peers which approved this block.
pub(super) signatures: Vec<BlockSignature>,
/// Block payload
#[serde(flatten)]
pub(super) payload: BlockPayload,
}
}
Expand Down Expand Up @@ -333,7 +332,6 @@ mod candidate {
#[derive(Decode, Deserialize)]
struct SignedBlockCandidate {
signatures: Vec<BlockSignature>,
#[serde(flatten)]
payload: BlockPayload,
}

Expand Down
1 change: 0 additions & 1 deletion data_model/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,6 @@ pub mod http {
#[derive(Decode, Deserialize)]
struct SignedQueryCandidate {
signature: QuerySignature,
#[serde(flatten)]
payload: ClientQueryPayload,
}

Expand Down
2 changes: 0 additions & 2 deletions data_model/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ mod model {
/// Signature of [`Self::payload`].
pub(super) signature: TransactionSignature,
/// Payload of the transaction.
#[serde(flatten)]
pub(super) payload: TransactionPayload,
}

Expand Down Expand Up @@ -361,7 +360,6 @@ mod candidate {
#[derive(Decode, Deserialize)]
struct SignedTransactionCandidate {
signature: TransactionSignature,
#[serde(flatten)]
payload: TransactionPayload,
}

Expand Down
20 changes: 20 additions & 0 deletions docs/source/references/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3043,6 +3043,26 @@
]
},
"QuerySignature": "SignatureOf<ClientQueryPayload>",
"RawGenesisTransaction": {
"Struct": [
{
"name": "chain",
"type": "ChainId"
},
{
"name": "executor",
"type": "String"
},
{
"name": "instructions",
"type": "Vec<InstructionBox>"
},
{
"name": "topology",
"type": "Vec<PeerId>"
}
]
},
"Register<Account>": {
"Struct": [
{
Expand Down
1 change: 1 addition & 0 deletions genesis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
31 changes: 19 additions & 12 deletions genesis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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<InstructionBox>,
/// Path to the [`Executor`] file
executor: PathBuf,
/// Unique id of blockchain
chain: ChainId,
/// Path to the [`Executor`] file
executor: ExecutorPath,
instructions: Vec<InstructionBox>,
/// Initial topology
topology: Vec<PeerId>,
}

/// 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

Expand All @@ -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)
}

Expand All @@ -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<GenesisBlock> {
let executor = get_executor(&self.executor)?;
let executor = get_executor(&self.executor.0)?;
let genesis = build_and_sign_genesis(
self.instructions,
executor,
Expand Down Expand Up @@ -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<PeerId>,
) -> RawGenesisTransaction {
RawGenesisTransaction {
instructions: self.instructions,
executor: executor_file,
executor: ExecutorPath(executor_file),
chain: chain_id,
topology,
}
Expand Down
4 changes: 4 additions & 0 deletions schema/gen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ pub fn build_schemas() -> MetaMap {

// Never referenced, but present in type signature. Like `PhantomData<X>`
MerkleTree<SignedTransaction>,

// Genesis file - used by SDKs to generate the genesis block
// TODO: IMO it could/should be removed from the schema
iroha_genesis::RawGenesisTransaction,
}
}

Expand Down
2 changes: 1 addition & 1 deletion tools/kagami/src/genesis/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit d5086e7

Please sign in to comment.