Skip to content

Commit

Permalink
[feature] #3090: Propagate on-chain parameters
Browse files Browse the repository at this point in the history
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
  • Loading branch information
Erigara committed May 5, 2023
1 parent 7b7d8c6 commit f8d60a5
Show file tree
Hide file tree
Showing 36 changed files with 516 additions and 342 deletions.
5 changes: 2 additions & 3 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use iroha_core::{
queue::Queue,
smartcontracts::isi::Registrable as _,
sumeragi::SumeragiHandle,
tx::{PeerId, TransactionValidator},
tx::PeerId,
IrohaNetwork,
};
use iroha_data_model::prelude::*;
Expand Down Expand Up @@ -245,7 +245,7 @@ impl Iroha {
)?;
let wsv = WorldStateView::from_configuration(config.wsv, world, Arc::clone(&kura));

let transaction_validator = TransactionValidator::new(config.sumeragi.transaction_limits);
let transaction_validator = wsv.transaction_validator();

// Validate every transaction in genesis block
if let Some(ref genesis) = genesis {
Expand Down Expand Up @@ -276,7 +276,6 @@ impl Iroha {
&config.sumeragi,
events_sender.clone(),
wsv,
transaction_validator,
Arc::clone(&queue),
Arc::clone(&kura),
network.clone(),
Expand Down
2 changes: 1 addition & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ async fn main() -> Result<(), color_eyre::Report> {
.as_ref(),
)?,
Some(&config.genesis),
&config.sumeragi.transaction_limits,
&config.wsv.transaction_limits,
)
.wrap_err("Failed to initialize genesis.")?
} else {
Expand Down
8 changes: 4 additions & 4 deletions cli/src/torii/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ impl TryFrom<SignedQuery> for VerifiedQuery {

#[iroha_futures::telemetry_future]
pub(crate) async fn handle_instructions(
iroha_cfg: Configuration,
queue: Arc<Queue>,
sumeragi: SumeragiHandle,
transaction: VersionedSignedTransaction,
) -> Result<Empty> {
let transaction: SignedTransaction = transaction.into_v1();
let transaction = AcceptedTransaction::accept::<false>(transaction, &iroha_cfg.sumeragi.transaction_limits)
let transaction_limits = sumeragi.wsv(|wsv| wsv.config.borrow().transaction_limits);
let transaction = AcceptedTransaction::accept::<false>(transaction, &transaction_limits)
.map_err(Error::AcceptTransaction)?
.into();
sumeragi
Expand Down Expand Up @@ -550,10 +550,10 @@ impl Torii {
.and_then(|| async { Ok::<_, Infallible>(handle_schema().await) }));

let post_router = warp::post()
.and(endpoint4(
.and(endpoint3(
handle_instructions,
warp::path(uri::TRANSACTION)
.and(add_state!(self.iroha_cfg, self.queue, self.sumeragi))
.and(add_state!(self.queue, self.sumeragi))
.and(warp::body::content_length_limit(
self.iroha_cfg.torii.max_content_len.into(),
))
Expand Down
4 changes: 2 additions & 2 deletions client/benches/torii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn query_requests(criterion: &mut Criterion) {
)
.build(),
Some(&configuration.genesis),
&configuration.sumeragi.transaction_limits,
&configuration.wsv.transaction_limits,
)
.expect("genesis creation failed");

Expand Down Expand Up @@ -140,7 +140,7 @@ fn instruction_submits(criterion: &mut Criterion) {
)
.build(),
Some(&configuration.genesis),
&configuration.sumeragi.transaction_limits,
&configuration.wsv.transaction_limits,
)
.expect("failed to create genesis");
let builder = PeerBuilder::new()
Expand Down
14 changes: 11 additions & 3 deletions client/benches/tps/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,19 @@ impl Config {
#[allow(clippy::expect_used, clippy::unwrap_in_result)]
pub fn measure(self) -> Result<Tps> {
// READY
let (_rt, network, _genesis_client) =
<Network>::start_test_with_runtime(self.peers, self.max_txs_per_block, None);
let (_rt, network, genesis_client) = <Network>::start_test_with_runtime(self.peers, None);
let clients = network.clients();
wait_for_genesis_committed(&clients, 0);

let parameter = Parameter::new(
ParameterId {
name: Name::from_str("MaxTransactionsInBlock")?,
},
self.max_txs_per_block.to_value(),
);
let param_box = SetParameterBox::new(parameter);
genesis_client.submit_blocking(param_box)?;

let unit_names = (UnitName::MIN..).take(self.peers as usize);
let units = clients
.into_iter()
Expand Down Expand Up @@ -108,7 +116,7 @@ impl Config {
handle.join().expect("Transaction submitter panicked");
}

let blocks_out_of_measure = 1 + MeasurerUnit::PREPARATION_BLOCKS_NUMBER * self.peers;
let blocks_out_of_measure = 2 + MeasurerUnit::PREPARATION_BLOCKS_NUMBER * self.peers;
let blocks_wsv = network
.genesis
.iroha
Expand Down
2 changes: 1 addition & 1 deletion client/examples/million_accounts_genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn main_genesis() {
true,
generate_genesis(1_000_000_u32),
Some(&configuration.genesis),
&configuration.sumeragi.transaction_limits,
&configuration.wsv.transaction_limits,
)
.expect("genesis creation failed");

Expand Down
11 changes: 10 additions & 1 deletion client/tests/integration/asset_propagation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,19 @@ use super::Configuration;
fn client_add_asset_quantity_to_existing_asset_should_increase_asset_amount_on_another_peer(
) -> Result<()> {
// Given
let (_rt, network, iroha_client) = <Network>::start_test_with_runtime(4, 1, Some(10_450));
let (_rt, network, iroha_client) = <Network>::start_test_with_runtime(4, Some(10_450));
wait_for_genesis_committed(&network.clients(), 0);
let pipeline_time = Configuration::pipeline_time();

let parameter = Parameter::new(
ParameterId {
name: Name::from_str("MaxTransactionsInBlock")?,
},
1u32.to_value(),
);
let param_box = SetParameterBox::new(parameter);
iroha_client.submit_blocking(param_box)?;

let create_domain = RegisterBox::new(Domain::new(DomainId::from_str("domain")?));
let account_id = AccountId::from_str("account@domain")?;
let (public_key, _) = KeyPair::generate()?.into();
Expand Down
24 changes: 17 additions & 7 deletions client/tests/integration/connected_peers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(clippy::pedantic, clippy::restriction)]

use std::thread;
use std::{str::FromStr, thread};

use iroha_client::client::Client;
use iroha_data_model::{peer::Peer as DataModelPeer, prelude::*};
Expand Down Expand Up @@ -28,16 +28,26 @@ fn connected_peers_with_f(faults: u64, port: u16) {
(n_peers)
.try_into()
.expect("`faults` argument `u64` value too high, cannot convert to `u32`"),
1,
Some(port),
);
wait_for_genesis_committed(&network.clients(), 0);
let pipeline_time = Configuration::pipeline_time();

let parameter = Parameter::new(
ParameterId {
name: Name::from_str("MaxTransactionsInBlock").expect("Failed to parse name"),
},
1u32.to_value(),
);
let param_box = SetParameterBox::new(parameter);
genesis_client
.submit_blocking(param_box)
.expect("Failed to submit transaction");

// Confirm all peers connected
let mut status = genesis_client.get_status().unwrap();
assert_eq!(status.peers, n_peers - 1);
assert_eq!(status.blocks, 1);
assert_eq!(status.blocks, 2);

// Unregister a peer: committed with f = `faults`
// then `status.peers` decrements
Expand All @@ -48,10 +58,10 @@ fn connected_peers_with_f(faults: u64, port: u16) {
thread::sleep(pipeline_time * 2);
status = genesis_client.get_status().unwrap();
assert_eq!(status.peers, n_peers - 2);
assert_eq!(status.blocks, 2);
assert_eq!(status.blocks, 3);
status = peer_client.get_status().unwrap();
assert_eq!(status.peers, 0);
assert_eq!(status.blocks, 2);
assert_eq!(status.blocks, 3);

// Re-register the peer: committed with f = `faults` - 1 then
// `status.peers` increments
Expand All @@ -60,8 +70,8 @@ fn connected_peers_with_f(faults: u64, port: u16) {
thread::sleep(pipeline_time * 4);
status = genesis_client.get_status().unwrap();
assert_eq!(status.peers, n_peers - 1);
assert_eq!(status.blocks, 3);
assert_eq!(status.blocks, 4);
status = peer_client.get_status().unwrap();
assert_eq!(status.peers, n_peers - 1);
assert_eq!(status.blocks, 3);
assert_eq!(status.blocks, 4);
}
17 changes: 15 additions & 2 deletions client/tests/integration/events/pipeline.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#![allow(clippy::restriction)]

use std::thread::{self, JoinHandle};
use std::{
str::FromStr,
thread::{self, JoinHandle},
};

use eyre::Result;
use iroha_data_model::prelude::*;
Expand Down Expand Up @@ -37,10 +40,20 @@ fn test_with_instruction_and_status_and_port(
port: u16,
) -> Result<()> {
let (_rt, network, genesis_client) =
<Network>::start_test_with_runtime(PEER_COUNT.try_into().unwrap(), 1, Some(port));
<Network>::start_test_with_runtime(PEER_COUNT.try_into().unwrap(), Some(port));
let clients = network.clients();
wait_for_genesis_committed(&clients, 0);
let pipeline_time = Configuration::pipeline_time();

let parameter = Parameter::new(
ParameterId {
name: Name::from_str("MaxTransactionsInBlock")?,
},
1u32.to_value(),
);
let param_box = SetParameterBox::new(parameter);
genesis_client.submit_blocking(param_box)?;

// Given
let submitter = genesis_client;
let transaction = submitter.build_transaction(instruction, UnlimitedMetadata::new())?;
Expand Down
15 changes: 13 additions & 2 deletions client/tests/integration/multiple_blocks_created.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(clippy::restriction)]

use std::thread;
use std::{str::FromStr, thread};

use iroha_client::client::{self, Client};
use iroha_crypto::KeyPair;
Expand All @@ -15,10 +15,21 @@ const N_BLOCKS: usize = 510;
#[test]
fn long_multiple_blocks_created() {
// Given
let (_rt, network, iroha_client) = <Network>::start_test_with_runtime(4, 1, Some(10_965));
let (_rt, network, iroha_client) = <Network>::start_test_with_runtime(4, Some(10_965));
wait_for_genesis_committed(&network.clients(), 0);
let pipeline_time = Configuration::pipeline_time();

let parameter = Parameter::new(
ParameterId {
name: Name::from_str("MaxTransactionsInBlock").expect("Failed to parse Name"),
},
1u32.to_value(),
);
let param_box = SetParameterBox::new(parameter);
iroha_client
.submit_blocking(param_box)
.expect("Failed to submit transaction");

let create_domain = RegisterBox::new(Domain::new("domain".parse().expect("Valid")));
let account_id: AccountId = "account@domain".parse().expect("Valid");
let (public_key, _) = KeyPair::generate()
Expand Down
13 changes: 12 additions & 1 deletion client/tests/integration/multisignature_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,21 @@ use super::Configuration;
#[allow(clippy::too_many_lines)]
#[test]
fn multisignature_transactions_should_wait_for_all_signatures() {
let (_rt, network, _) = <Network>::start_test_with_runtime(4, 1, Some(10_945));
let (_rt, network, iroha_client) = <Network>::start_test_with_runtime(4, Some(10_945));
wait_for_genesis_committed(&network.clients(), 0);
let pipeline_time = Configuration::pipeline_time();

let parameter = Parameter::new(
ParameterId {
name: Name::from_str("MaxTransactionsInBlock").expect("Failed to parse Name"),
},
1u32.to_value(),
);
let param_box = SetParameterBox::new(parameter);
iroha_client
.submit_blocking(param_box)
.expect("Failed to submit transaction");

let alice_id = AccountId::from_str("alice@wonderland").expect("Valid");
let alice_key_pair = get_key_pair();
let key_pair_2 = KeyPair::generate().expect("Failed to generate KeyPair.");
Expand Down
14 changes: 13 additions & 1 deletion client/tests/integration/offline_peers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![allow(clippy::restriction)]

use std::str::FromStr;

use iroha_client::client;
use iroha_data_model::prelude::*;
use test_network::*;
Expand All @@ -13,11 +15,21 @@ fn genesis_block_is_commited_with_some_offline_peers() {
let (network, iroha_client) = rt.block_on(<Network>::start_test_with_offline_and_set_n_shifts(
4,
1,
1,
Some(10_560),
));
wait_for_genesis_committed(&network.clients(), 1);

let parameter = Parameter::new(
ParameterId {
name: Name::from_str("MaxTransactionsInBlock").expect("Failed to parse Name"),
},
1u32.to_value(),
);
let param_box = SetParameterBox::new(parameter);
iroha_client
.submit_blocking(param_box)
.expect("Failed to submit transaction");

//When
let alice_id: AccountId = "alice@wonderland".parse().expect("Valid");
let alice_has_roses = 13;
Expand Down
26 changes: 24 additions & 2 deletions client/tests/integration/set_parameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ fn can_change_parameter_value() -> Result<()> {
let (_rt, _peer, test_client) = <PeerBuilder>::new().with_port(10_800).start_with_runtime();
wait_for_genesis_committed(&vec![test_client.clone()], 0);

let parameter = Parameter::from_str("?BlockSyncGossipPeriod=20000")?;
let parameter_id = ParameterId::from_str("BlockSyncGossipPeriod")?;
let parameter = Parameter::from_str("?BlockTime=4000")?;
let parameter_id = ParameterId::from_str("BlockTime")?;
let param_box = SetParameterBox::new(parameter);

let old_params = test_client.request(client::parameter::all())?;
Expand All @@ -36,3 +36,25 @@ fn can_change_parameter_value() -> Result<()> {
assert_ne!(param_val_old, param_val_new);
Ok(())
}

#[test]
fn parameter_propagated() -> Result<()> {
let (_rt, _peer, test_client) = <PeerBuilder>::new().with_port(10_985).start_with_runtime();
wait_for_genesis_committed(&vec![test_client.clone()], 0);

let too_long_domain_name: DomainId = "0".repeat(2_usize.pow(8)).parse()?;
let create_domain = RegisterBox::new(Domain::new(too_long_domain_name));
let _ = test_client
.submit_blocking(create_domain.clone())
.expect_err("Should fail before ident length limits update");

let parameter = Parameter::from_str("?WSVIdentLengthLimits=1,256_LL")?;
let param_box = SetParameterBox::new(parameter);
test_client.submit_blocking(param_box)?;

test_client
.submit_blocking(create_domain)
.expect("Should work after ident length limits update");

Ok(())
}
12 changes: 10 additions & 2 deletions client/tests/integration/unregister_peer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![allow(clippy::restriction)]
use std::thread;
use std::{str::FromStr, thread};

use eyre::Result;
use iroha_client::client;
Expand Down Expand Up @@ -99,17 +99,25 @@ fn init() -> Result<(
AccountId,
AssetDefinitionId,
)> {
let (rt, network, client) = <Network>::start_test_with_runtime(4, 1, Some(10_925));
let (rt, network, client) = <Network>::start_test_with_runtime(4, Some(10_925));
let pipeline_time = Configuration::pipeline_time();
thread::sleep(pipeline_time * 2);
iroha_logger::info!("Started");
let parameter = Parameter::new(
ParameterId {
name: Name::from_str("MaxTransactionsInBlock").expect("Failed to parse Name"),
},
1u32.to_value(),
);
let param_box = SetParameterBox::new(parameter);
let create_domain = RegisterBox::new(Domain::new("domain".parse().expect("Valid")));
let account_id: AccountId = "account@domain".parse().expect("Valid");
let (public_key, _) = KeyPair::generate()?.into();
let create_account = RegisterBox::new(Account::new(account_id.clone(), [public_key]));
let asset_definition_id: AssetDefinitionId = "xor#domain".parse().expect("Valid");
let create_asset = RegisterBox::new(AssetDefinition::quantity(asset_definition_id.clone()));
client.submit_all(vec![
param_box.into(),
create_domain.into(),
create_account.into(),
create_asset.into(),
Expand Down
Loading

0 comments on commit f8d60a5

Please sign in to comment.