Skip to content

Commit

Permalink
feat: include parameters into generated genesis (#4806)
Browse files Browse the repository at this point in the history
Signed-off-by: Shanin Roman <[email protected]>
  • Loading branch information
Erigara authored Jul 5, 2024
1 parent ebe738c commit 6df73f6
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 1 deletion.
63 changes: 63 additions & 0 deletions configs/swarm/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,69 @@
]
}
}
},
{
"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": []
Expand Down
52 changes: 52 additions & 0 deletions data_model/src/parameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,24 @@ impl Default for SmartContractParameters {
}
}

impl Parameters {
/// Convert [`Self`] into iterator of individual parameters
pub fn parameters(&self) -> impl Iterator<Item = Parameter> + '_ {
self.sumeragi
.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.smart_contract
.parameters()
.map(Parameter::SmartContract),
)
.chain(self.custom.values().cloned().map(Parameter::Custom))
}
}

impl SumeragiParameters {
/// Construct [`Self`]
pub fn new(block_time: Duration, commit_time: Duration) -> Self {
Expand All @@ -383,13 +401,27 @@ impl SumeragiParameters {
.expect("INTERNAL BUG: Time should fit into u64"),
}
}

/// Convert [`Self`] into iterator of individual parameters
pub fn parameters(&self) -> impl Iterator<Item = SumeragiParameter> {
[
SumeragiParameter::BlockTimeMs(self.block_time_ms),
SumeragiParameter::CommitTimeMs(self.commit_time_ms),
]
.into_iter()
}
}

impl BlockParameters {
/// Construct [`Self`]
pub const fn new(max_transactions: NonZeroU64) -> Self {
Self { max_transactions }
}

/// Convert [`Self`] into iterator of individual parameters
pub fn parameters(&self) -> impl Iterator<Item = BlockParameter> {
[BlockParameter::MaxTransactions(self.max_transactions)].into_iter()
}
}

impl TransactionParameters {
Expand All @@ -400,6 +432,26 @@ impl TransactionParameters {
smart_contract_size,
}
}

/// Convert [`Self`] into iterator of individual parameters
pub fn parameters(&self) -> impl Iterator<Item = TransactionParameter> {
[
TransactionParameter::MaxInstructions(self.max_instructions),
TransactionParameter::SmartContractSize(self.smart_contract_size),
]
.into_iter()
}
}

impl SmartContractParameters {
/// Convert [`Self`] into iterator of individual parameters
pub fn parameters(&self) -> impl Iterator<Item = SmartContractParameter> {
[
SmartContractParameter::Fuel(self.fuel),
SmartContractParameter::Memory(self.memory),
]
.into_iter()
}
}

impl CustomParameterId {
Expand Down
1 change: 1 addition & 0 deletions schema/gen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ types!(
Option<HashOf<SignedBlock>>,
Option<HashOf<SignedTransaction>>,
Option<IpfsPath>,
Option<JsonString>,
Option<Name>,
Option<NonZeroU32>,
Option<NonZeroU64>,
Expand Down
9 changes: 8 additions & 1 deletion tools/kagami/src/genesis/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{

use clap::{Parser, Subcommand};
use color_eyre::eyre::WrapErr as _;
use iroha_data_model::prelude::*;
use iroha_data_model::{isi::InstructionBox, parameter::Parameters, prelude::*};
use iroha_executor_data_model::permission::{
account::{CanRemoveKeyValueInAccount, CanSetKeyValueInAccount},
parameter::CanSetParameters,
Expand Down Expand Up @@ -138,6 +138,12 @@ pub fn generate_default(
)
.into();

let parameters = Parameters::default();
let set_parameters = parameters
.parameters()
.map(SetParameter)
.map(InstructionBox::from);

for isi in [
mint.into(),
mint_cabbage.into(),
Expand All @@ -147,6 +153,7 @@ pub fn generate_default(
]
.into_iter()
.chain(std::iter::once(register_user_metadata_access))
.chain(set_parameters)
{
builder = builder.append_instruction(isi);
}
Expand Down

0 comments on commit 6df73f6

Please sign in to comment.