diff --git a/configs/swarm/executor.wasm b/configs/swarm/executor.wasm index 0fefcfab3a1..26823f64271 100644 Binary files a/configs/swarm/executor.wasm and b/configs/swarm/executor.wasm differ diff --git a/configs/swarm/genesis.json b/configs/swarm/genesis.json index 121cc6ae593..e72cafa70fb 100644 --- a/configs/swarm/genesis.json +++ b/configs/swarm/genesis.json @@ -1,6 +1,53 @@ { "chain": "00000000-0000-0000-0000-000000000000", "executor": "./executor.wasm", + "parameters": [ + { + "Sumeragi": { + "BlockTimeMs": 2000 + } + }, + { + "Sumeragi": { + "CommitTimeMs": 4000 + } + }, + { + "Block": { + "MaxTransactions": 512 + } + }, + { + "Transaction": { + "MaxInstructions": 4096 + } + }, + { + "Transaction": { + "SmartContractSize": 4194304 + } + }, + { + "Executor": { + "Fuel": 55000000 + } + }, + { + "Executor": { + "Memory": 55000000 + } + }, + { + "SmartContract": { + "Fuel": 55000000 + } + }, + { + "SmartContract": { + "Memory": 55000000 + } + } + ], "instructions": [ { "Register": { @@ -137,69 +184,6 @@ ] } } - }, - { - "SetParameter": { - "Sumeragi": { - "BlockTimeMs": 2000 - } - } - }, - { - "SetParameter": { - "Sumeragi": { - "CommitTimeMs": 4000 - } - } - }, - { - "SetParameter": { - "Block": { - "MaxTransactions": 512 - } - } - }, - { - "SetParameter": { - "Transaction": { - "MaxInstructions": 4096 - } - } - }, - { - "SetParameter": { - "Transaction": { - "SmartContractSize": 4194304 - } - } - }, - { - "SetParameter": { - "SmartContract": { - "Fuel": 55000000 - } - } - }, - { - "SetParameter": { - "SmartContract": { - "Memory": 55000000 - } - } - }, - { - "SetParameter": { - "SmartContract": { - "Fuel": 55000000 - } - } - }, - { - "SetParameter": { - "SmartContract": { - "Memory": 55000000 - } - } } ], "topology": [] diff --git a/data_model/src/block.rs b/data_model/src/block.rs index f355b462a4b..b9b60110e86 100644 --- a/data_model/src/block.rs +++ b/data_model/src/block.rs @@ -383,9 +383,9 @@ mod candidate { ); }; - if transactions.len() > 2 { + if transactions.len() > 3 { return Err( - "Genesis block must have one or two transactions (first with executor upgrade)", + "Genesis block must have 1 to 3 transactions (executor upgrade, parameters, other isi)", ); } diff --git a/data_model/src/parameter.rs b/data_model/src/parameter.rs index 4841549d353..afff07b46d7 100644 --- a/data_model/src/parameter.rs +++ b/data_model/src/parameter.rs @@ -377,7 +377,7 @@ impl Parameters { .map(Parameter::Sumeragi) .chain(self.block.parameters().map(Parameter::Block)) .chain(self.transaction.parameters().map(Parameter::Transaction)) - .chain(self.executor.parameters().map(Parameter::SmartContract)) + .chain(self.executor.parameters().map(Parameter::Executor)) .chain( self.smart_contract .parameters() diff --git a/docs/source/references/schema.json b/docs/source/references/schema.json index b8ef73c6e7e..ec3064d9867 100644 --- a/docs/source/references/schema.json +++ b/docs/source/references/schema.json @@ -3175,6 +3175,10 @@ "name": "executor", "type": "String" }, + { + "name": "parameters", + "type": "Vec" + }, { "name": "instructions", "type": "Vec" @@ -4558,6 +4562,9 @@ "Vec": { "Vec": "InstructionBox" }, + "Vec": { + "Vec": "Parameter" + }, "Vec": { "Vec": "PeerId" }, diff --git a/genesis/src/lib.rs b/genesis/src/lib.rs index fcecd5b0772..078ba4bc2f1 100644 --- a/genesis/src/lib.rs +++ b/genesis/src/lib.rs @@ -10,7 +10,7 @@ use std::{ use eyre::{eyre, Result, WrapErr}; use iroha_crypto::{KeyPair, PublicKey}; -use iroha_data_model::{block::SignedBlock, isi::Instruction, prelude::*}; +use iroha_data_model::{block::SignedBlock, isi::Instruction, parameter::Parameter, prelude::*}; use iroha_schema::IntoSchema; use once_cell::sync::Lazy; use parity_scale_codec::{Decode, Encode}; @@ -37,6 +37,9 @@ pub struct RawGenesisTransaction { chain: ChainId, /// Path to the [`Executor`] file executor: ExecutorPath, + /// Parameters + #[serde(default)] + parameters: Vec, instructions: Vec, /// Initial topology topology: Vec, @@ -105,6 +108,7 @@ impl RawGenesisTransaction { self.chain, genesis_key_pair, self.topology, + self.parameters, ); Ok(genesis) } @@ -116,8 +120,15 @@ fn build_and_sign_genesis( chain_id: ChainId, genesis_key_pair: &KeyPair, topology: Vec, + parameters: Vec, ) -> GenesisBlock { - let transactions = build_transactions(instructions, executor, chain_id, genesis_key_pair); + let transactions = build_transactions( + instructions, + executor, + parameters, + chain_id, + genesis_key_pair, + ); let block = SignedBlock::genesis(transactions, genesis_key_pair.private_key(), topology); GenesisBlock(block) } @@ -125,18 +136,31 @@ fn build_and_sign_genesis( fn build_transactions( instructions: Vec, executor: Executor, + parameters: Vec, chain_id: ChainId, genesis_key_pair: &KeyPair, ) -> Vec { let upgrade_isi = Upgrade::new(executor).into(); let transaction_executor = build_transaction(vec![upgrade_isi], chain_id.clone(), genesis_key_pair); - if instructions.is_empty() { - vec![transaction_executor] - } else { + let mut transactions = vec![transaction_executor]; + if !parameters.is_empty() { + let parameters = build_transaction( + parameters + .into_iter() + .map(SetParameter) + .map(InstructionBox::from) + .collect(), + chain_id.clone(), + genesis_key_pair, + ); + transactions.push(parameters); + } + if !instructions.is_empty() { let transaction_instructions = build_transaction(instructions, chain_id, genesis_key_pair); - vec![transaction_executor, transaction_instructions] + transactions.push(transaction_instructions); } + transactions } fn build_transaction( @@ -166,6 +190,7 @@ fn get_executor(file: &Path) -> Result { #[derive(Default)] pub struct GenesisBuilder { instructions: Vec, + parameters: Vec, } /// `Domain` subsection of the [`GenesisBuilder`]. Makes @@ -174,6 +199,7 @@ pub struct GenesisBuilder { #[must_use] pub struct GenesisDomainBuilder { instructions: Vec, + parameters: Vec, domain_id: DomainId, } @@ -196,6 +222,7 @@ impl GenesisBuilder { self.instructions.push(Register::domain(new_domain).into()); GenesisDomainBuilder { instructions: self.instructions, + parameters: self.parameters, domain_id, } } @@ -206,6 +233,12 @@ impl GenesisBuilder { self } + /// Add parameter to the end of parameter list + pub fn append_parameter(mut self, parameter: Parameter) -> Self { + self.parameters.push(parameter); + self + } + /// Finish building, sign, and produce a [`GenesisBlock`]. pub fn build_and_sign( self, @@ -220,6 +253,7 @@ impl GenesisBuilder { chain_id, genesis_key_pair, topology, + self.parameters, ) } @@ -233,6 +267,7 @@ impl GenesisBuilder { RawGenesisTransaction { instructions: self.instructions, executor: ExecutorPath(executor_file), + parameters: self.parameters, chain: chain_id, topology, } @@ -245,6 +280,7 @@ impl GenesisDomainBuilder { pub fn finish_domain(self) -> GenesisBuilder { GenesisBuilder { instructions: self.instructions, + parameters: self.parameters, } } diff --git a/tools/kagami/src/genesis/generate.rs b/tools/kagami/src/genesis/generate.rs index e8e0d409479..6615f69180b 100644 --- a/tools/kagami/src/genesis/generate.rs +++ b/tools/kagami/src/genesis/generate.rs @@ -139,10 +139,11 @@ pub fn generate_default( .into(); let parameters = Parameters::default(); - let set_parameters = parameters - .parameters() - .map(SetParameter) - .map(InstructionBox::from); + let parameters = parameters.parameters(); + + for parameter in parameters { + builder = builder.append_parameter(parameter); + } for isi in [ mint.into(), @@ -153,7 +154,6 @@ pub fn generate_default( ] .into_iter() .chain(std::iter::once(register_user_metadata_access)) - .chain(set_parameters) { builder = builder.append_instruction(isi); }