Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: implement built-in vs custom on-chain parameters #4731

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

3 changes: 1 addition & 2 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,7 @@ impl Iroha {
None
}
}.unwrap_or_else(|| {
State::from_config(
config.chain_wide,
State::new(
world,
Arc::clone(&kura),
live_query_store_handle.clone(),
Expand Down
3 changes: 1 addition & 2 deletions cli/src/samples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ pub fn get_config_toml(
.write(["sumeragi", "trusted_peers"], peers)
.write(["network", "address"], DEFAULT_P2P_ADDR)
.write(["network", "block_gossip_period_ms"], 500)
.write(["network", "block_gossip_max_size"], 1)
.write(["network", "block_gossip_size"], 1)
mversic marked this conversation as resolved.
Show resolved Hide resolved
.write(["torii", "address"], DEFAULT_TORII_ADDR)
.write(["chain_wide", "max_transactions_in_block"], 2)
.write(["genesis", "public_key"], genesis_public_key)
.write(
["genesis", "signed_file"],
Expand Down
16 changes: 4 additions & 12 deletions client/benches/tps/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use iroha::{
crypto::KeyPair,
data_model::{
events::pipeline::{BlockEventFilter, BlockStatus},
parameter::{default::MAX_TRANSACTIONS_IN_BLOCK, ParametersBuilder},
parameter::BlockParameter,
prelude::*,
},
};
Expand All @@ -22,7 +22,7 @@ pub struct Config {
pub peers: u32,
/// Interval in microseconds between transactions to reduce load
pub interval_us_per_tx: u64,
pub max_txs_per_block: u32,
pub block_limits: BlockParameter,
pub blocks: u32,
pub sample_size: u32,
pub genesis_max_retries: u32,
Expand All @@ -33,11 +33,7 @@ impl fmt::Display for Config {
write!(
f,
"{}peers-{}interval_µs-{}max_txs-{}blocks-{}samples",
self.peers,
self.interval_us_per_tx,
self.max_txs_per_block,
self.blocks,
self.sample_size,
self.peers, self.interval_us_per_tx, self.block_limits, self.blocks, self.sample_size,
)
}
}
Expand All @@ -55,11 +51,7 @@ impl Config {
let clients = network.clients();
wait_for_genesis_committed_with_max_retries(&clients, 0, self.genesis_max_retries);

client.submit_all_blocking(
ParametersBuilder::new()
.add_parameter(MAX_TRANSACTIONS_IN_BLOCK, self.max_txs_per_block)?
.into_set_parameters(),
)?;
client.submit_blocking(SetParameter::new(Parameter::Block(self.block_limits)))?;

let unit_names = (UnitName::MIN..).take(self.peers as usize);
let units = clients
Expand Down
35 changes: 21 additions & 14 deletions client/examples/register_1000_triggers.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
//! Example of registering multiple triggers
//! Used to show Iroha's trigger deduplication capabilities

use std::num::NonZeroU64;

use iroha::{
client::Client,
crypto::KeyPair,
data_model::{prelude::*, trigger::TriggerId},
};
use iroha_data_model::parameter::{Parameter, SmartContractParameter};
use iroha_genesis::{GenesisBlock, GenesisBuilder};
use iroha_primitives::unique_vec;
use irohad::samples::{construct_executor, get_config};
Expand All @@ -18,17 +22,24 @@ use tokio::runtime::Runtime;
fn generate_genesis(
num_triggers: u32,
chain_id: ChainId,
genesis_key_pair: &iroha_crypto::KeyPair,
genesis_key_pair: &KeyPair,
topology: Vec<PeerId>,
) -> Result<GenesisBlock, Box<dyn std::error::Error>> {
let builder = GenesisBuilder::default();
let builder = GenesisBuilder::default()
.append_instruction(SetParameter::new(Parameter::Executor(
SmartContractParameter::Fuel(NonZeroU64::MAX),
)))
.append_instruction(SetParameter::new(Parameter::Executor(
SmartContractParameter::Memory(NonZeroU64::MAX),
)));

let wasm =
iroha_wasm_builder::Builder::new("tests/integration/smartcontracts/mint_rose_trigger")
.show_output()
.build()?
.optimize()?
.into_bytes()?;
let wasm = iroha_wasm_builder::Builder::new(
"client/tests/integration/smartcontracts/mint_rose_trigger",
)
.show_output()
.build()?
.optimize()?
.into_bytes()?;
let wasm = WasmSmartContract::from_compiled(wasm);
let (account_id, _account_keypair) = gen_account_in("wonderland");

Expand All @@ -54,7 +65,7 @@ fn generate_genesis(
})
.fold(builder, GenesisBuilder::append_instruction);

let executor = construct_executor("../default_executor").expect("Failed to construct executor");
let executor = construct_executor("default_executor").expect("Failed to construct executor");
Ok(builder.build_and_sign(executor, chain_id, genesis_key_pair, topology))
}

Expand All @@ -64,17 +75,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let chain_id = get_chain_id();
let genesis_key_pair = get_key_pair(test_network::Signatory::Genesis);
let topology = vec![peer.id.clone()];
let mut configuration = get_config(
let configuration = get_config(
unique_vec![peer.id.clone()],
chain_id.clone(),
get_key_pair(test_network::Signatory::Peer),
genesis_key_pair.public_key(),
);

// Increase executor limits for large genesis
configuration.chain_wide.executor_runtime.fuel_limit = u64::MAX;
configuration.chain_wide.executor_runtime.max_memory = u32::MAX.into();
mversic marked this conversation as resolved.
Show resolved Hide resolved

let genesis = generate_genesis(1_000_u32, chain_id, &genesis_key_pair, topology)?;

let builder = PeerBuilder::new()
Expand Down
8 changes: 4 additions & 4 deletions client/examples/tutorial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn domain_registration_test(config: Config) -> Result<(), Error> {
use iroha::{
client::Client,
data_model::{
metadata::UnlimitedMetadata,
metadata::Metadata,
prelude::{Domain, DomainId, InstructionBox, Register},
},
};
Expand All @@ -57,7 +57,7 @@ fn domain_registration_test(config: Config) -> Result<(), Error> {

// #region domain_register_example_prepare_tx
// Prepare a transaction
let metadata = UnlimitedMetadata::default();
let metadata = Metadata::default();
let instructions: Vec<InstructionBox> = vec![create_looking_glass.into()];
let tx = iroha.build_transaction(instructions, metadata);
// #endregion domain_register_example_prepare_tx
Expand Down Expand Up @@ -101,7 +101,7 @@ fn account_registration_test(config: Config) -> Result<(), Error> {
client::Client,
crypto::KeyPair,
data_model::{
metadata::UnlimitedMetadata,
metadata::Metadata,
prelude::{Account, AccountId, InstructionBox, Register},
},
};
Expand All @@ -127,7 +127,7 @@ fn account_registration_test(config: Config) -> Result<(), Error> {
// #region register_account_prepare_tx
// Prepare a transaction using the
// Account's RegisterBox
let metadata = UnlimitedMetadata::new();
let metadata = Metadata::default();
let instructions: Vec<InstructionBox> = vec![create_account.into()];
let tx = iroha.build_transaction(instructions, metadata);
// #endregion register_account_prepare_tx
Expand Down
17 changes: 9 additions & 8 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ impl_query_output! {
crate::data_model::executor::ExecutorDataModel,
crate::data_model::trigger::Trigger,
crate::data_model::prelude::Numeric,
crate::data_model::parameter::Parameters,
}

/// Iroha client
Expand Down Expand Up @@ -453,7 +454,7 @@ impl Client {
pub fn build_transaction(
&self,
instructions: impl Into<Executable>,
metadata: UnlimitedMetadata,
metadata: Metadata,
) -> SignedTransaction {
let tx_builder = TransactionBuilder::new(self.chain.clone(), self.account.clone());

Expand Down Expand Up @@ -510,7 +511,7 @@ impl Client {
&self,
instructions: impl IntoIterator<Item = impl Instruction>,
) -> Result<HashOf<SignedTransaction>> {
self.submit_all_with_metadata(instructions, UnlimitedMetadata::new())
self.submit_all_with_metadata(instructions, Metadata::default())
}

/// Instructions API entry point. Submits one Iroha Special Instruction to `Iroha` peers.
Expand All @@ -522,7 +523,7 @@ impl Client {
pub fn submit_with_metadata(
&self,
instruction: impl Instruction,
metadata: UnlimitedMetadata,
metadata: Metadata,
) -> Result<HashOf<SignedTransaction>> {
self.submit_all_with_metadata([instruction], metadata)
}
Expand All @@ -536,7 +537,7 @@ impl Client {
pub fn submit_all_with_metadata(
&self,
instructions: impl IntoIterator<Item = impl Instruction>,
metadata: UnlimitedMetadata,
metadata: Metadata,
) -> Result<HashOf<SignedTransaction>> {
self.submit_transaction(&self.build_transaction(instructions, metadata))
}
Expand Down Expand Up @@ -719,7 +720,7 @@ impl Client {
&self,
instructions: impl IntoIterator<Item = impl Instruction>,
) -> Result<HashOf<SignedTransaction>> {
self.submit_all_blocking_with_metadata(instructions, UnlimitedMetadata::new())
self.submit_all_blocking_with_metadata(instructions, Metadata::default())
}

/// Submits and waits until the transaction is either rejected or committed.
Expand All @@ -731,7 +732,7 @@ impl Client {
pub fn submit_blocking_with_metadata(
&self,
instruction: impl Instruction,
metadata: UnlimitedMetadata,
metadata: Metadata,
) -> Result<HashOf<SignedTransaction>> {
self.submit_all_blocking_with_metadata(vec![instruction.into()], metadata)
}
Expand All @@ -745,7 +746,7 @@ impl Client {
pub fn submit_all_blocking_with_metadata(
&self,
instructions: impl IntoIterator<Item = impl Instruction>,
metadata: UnlimitedMetadata,
metadata: Metadata,
) -> Result<HashOf<SignedTransaction>> {
let transaction = self.build_transaction(instructions, metadata);
self.submit_transaction_blocking(&transaction)
Expand Down Expand Up @@ -1621,7 +1622,7 @@ mod tests {
});

let build_transaction =
|| client.build_transaction(Vec::<InstructionBox>::new(), UnlimitedMetadata::new());
|| client.build_transaction(Vec::<InstructionBox>::new(), Metadata::default());
let tx1 = build_transaction();
let tx2 = build_transaction();
assert_ne!(tx1.hash(), tx2.hash());
Expand Down
8 changes: 5 additions & 3 deletions client/src/config/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ use iroha_config_base::{
util::{DurationMs, Emitter, EmitterResultExt},
ReadConfig, WithOrigin,
};
use iroha_crypto::{KeyPair, PrivateKey, PublicKey};
use iroha_data_model::prelude::{AccountId, ChainId, DomainId};
use url::Url;

use crate::config::BasicAuth;
use crate::{
config::BasicAuth,
crypto::{KeyPair, PrivateKey, PublicKey},
data_model::prelude::{AccountId, ChainId, DomainId},
};

/// Root of the user configuration
#[derive(Clone, Debug, ReadConfig)]
Expand Down
37 changes: 0 additions & 37 deletions client/tests/integration/add_domain.rs

This file was deleted.

6 changes: 3 additions & 3 deletions client/tests/integration/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ fn client_add_asset_quantity_to_existing_asset_should_increase_asset_amount() ->
let asset_definition_id = AssetDefinitionId::from_str("xor#wonderland").expect("Valid");
let create_asset =
Register::asset_definition(AssetDefinition::numeric(asset_definition_id.clone()));
let metadata = iroha::data_model::metadata::UnlimitedMetadata::default();
let metadata = iroha::data_model::metadata::Metadata::default();
//When
let quantity = numeric!(200);
let mint = Mint::asset_numeric(
Expand Down Expand Up @@ -137,7 +137,7 @@ fn client_add_big_asset_quantity_to_existing_asset_should_increase_asset_amount(
let asset_definition_id = AssetDefinitionId::from_str("xor#wonderland").expect("Valid");
let create_asset =
Register::asset_definition(AssetDefinition::numeric(asset_definition_id.clone()));
let metadata = iroha::data_model::metadata::UnlimitedMetadata::default();
let metadata = iroha::data_model::metadata::Metadata::default();
//When
let quantity = Numeric::new(2_u128.pow(65), 0);
let mint = Mint::asset_numeric(
Expand Down Expand Up @@ -168,7 +168,7 @@ fn client_add_asset_with_decimal_should_increase_asset_amount() -> Result<()> {
let asset_definition_id = AssetDefinitionId::from_str("xor#wonderland").expect("Valid");
let asset_definition = AssetDefinition::numeric(asset_definition_id.clone());
let create_asset = Register::asset_definition(asset_definition);
let metadata = iroha::data_model::metadata::UnlimitedMetadata::default();
let metadata = iroha::data_model::metadata::Metadata::default();

//When
let quantity = numeric!(123.456);
Expand Down
14 changes: 5 additions & 9 deletions client/tests/integration/asset_propagation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ use std::{str::FromStr as _, thread};
use eyre::Result;
use iroha::{
client::{self, QueryResult},
data_model::{
parameter::{default::MAX_TRANSACTIONS_IN_BLOCK, ParametersBuilder},
prelude::*,
},
data_model::{parameter::BlockParameter, prelude::*},
};
use iroha_config::parameters::actual::Root as Config;
use nonzero_ext::nonzero;
use test_network::*;
use test_samples::gen_account_in;

Expand All @@ -22,11 +20,9 @@ fn client_add_asset_quantity_to_existing_asset_should_increase_asset_amount_on_a
wait_for_genesis_committed(&network.clients(), 0);
let pipeline_time = Config::pipeline_time();

client.submit_all_blocking(
ParametersBuilder::new()
.add_parameter(MAX_TRANSACTIONS_IN_BLOCK, 1u32)?
.into_set_parameters(),
)?;
client.submit_blocking(SetParameter::new(Parameter::Block(
BlockParameter::MaxTransactions(nonzero!(1_u64)),
)))?;

let create_domain: InstructionBox =
Register::domain(Domain::new(DomainId::from_str("domain")?)).into();
Expand Down
2 changes: 1 addition & 1 deletion client/tests/integration/events/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ fn transaction_execution_should_produce_events(

// submit transaction to produce events
init_receiver.recv()?;
let transaction = client.build_transaction(executable, UnlimitedMetadata::new());
let transaction = client.build_transaction(executable, Metadata::default());
client.submit_transaction_blocking(&transaction)?;

// assertion
Expand Down
Loading
Loading