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 11, 2023
1 parent b2fe6e1 commit c9a3539
Show file tree
Hide file tree
Showing 47 changed files with 774 additions and 626 deletions.
26 changes: 12 additions & 14 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ use iroha_core::{
prelude::{World, WorldStateView},
queue::Queue,
smartcontracts::isi::Registrable as _,
sumeragi::SumeragiHandle,
tx::{PeerId, TransactionValidator},
sumeragi::{SumeragiHandle, SumeragiStartArgs},
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 All @@ -271,18 +271,16 @@ impl Iroha {

let kura_thread_handler = Kura::start(Arc::clone(&kura));

// TODO: No function needs 10 parameters. It should accept one struct.
let sumeragi = SumeragiHandle::start(
&config.sumeragi,
events_sender.clone(),
let sumeragi = SumeragiHandle::start(SumeragiStartArgs {
configuration: &config.sumeragi,
events_sender: events_sender.clone(),
wsv,
transaction_validator,
Arc::clone(&queue),
Arc::clone(&kura),
network.clone(),
genesis,
&block_hashes,
);
queue: Arc::clone(&queue),
kura: Arc::clone(&kura),
network: network.clone(),
genesis_network: genesis,
block_hashes: &block_hashes,
});

let block_sync = BlockSynchronizer::from_configuration(
&config.block_sync,
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
16 changes: 12 additions & 4 deletions client/benches/tps/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ use std::{

use eyre::{Result, WrapErr};
use iroha_client::client::Client;
use iroha_data_model::prelude::*;
use iroha_data_model::{
parameter::{default::MAX_TRANSACTIONS_IN_BLOCK, ParametersBuilder},
prelude::*,
};
use serde::Deserialize;
use test_network::*;

Expand Down Expand Up @@ -56,11 +59,16 @@ 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, client) = <Network>::start_test_with_runtime(self.peers, None);
let clients = network.clients();
wait_for_genesis_committed(&clients, 0);

client.submit_blocking(
ParametersBuilder::new()
.add_parameter(MAX_TRANSACTIONS_IN_BLOCK, self.max_txs_per_block)?
.into_set_parameters(),
)?;

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
17 changes: 13 additions & 4 deletions client/tests/integration/asset_propagation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use std::{str::FromStr as _, thread};
use eyre::Result;
use iroha_client::client;
use iroha_crypto::KeyPair;
use iroha_data_model::prelude::*;
use iroha_data_model::{
parameter::{default::MAX_TRANSACTIONS_IN_BLOCK, ParametersBuilder},
prelude::*,
};
use test_network::*;

use super::Configuration;
Expand All @@ -14,25 +17,31 @@ 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, client) = <Network>::start_test_with_runtime(4, Some(10_450));
wait_for_genesis_committed(&network.clients(), 0);
let pipeline_time = Configuration::pipeline_time();

client.submit_blocking(
ParametersBuilder::new()
.add_parameter(MAX_TRANSACTIONS_IN_BLOCK, 1u32)?
.into_set_parameters(),
)?;

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();
let create_account = RegisterBox::new(Account::new(account_id.clone(), [public_key]));
let asset_definition_id = AssetDefinitionId::from_str("xor#domain")?;
let create_asset = RegisterBox::new(AssetDefinition::quantity(asset_definition_id.clone()));
iroha_client.submit_all(vec![
client.submit_all(vec![
create_domain.into(),
create_account.into(),
create_asset.into(),
])?;
thread::sleep(pipeline_time * 3);
//When
let quantity: u32 = 200;
iroha_client.submit(MintBox::new(
client.submit(MintBox::new(
quantity.to_value(),
IdBox::AssetId(AssetId::new(
asset_definition_id.clone(),
Expand Down
50 changes: 31 additions & 19 deletions client/tests/integration/connected_peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,78 @@

use std::thread;

use eyre::{Context, Result};
use iroha_client::client::Client;
use iroha_data_model::{peer::Peer as DataModelPeer, prelude::*};
use iroha_data_model::{
parameter::{default::MAX_TRANSACTIONS_IN_BLOCK, ParametersBuilder},
peer::Peer as DataModelPeer,
prelude::*,
};
use test_network::*;

use super::Configuration;

#[ignore = "ignore, more in #2851"]
#[test]
fn connected_peers_with_f_2_1_2() {
fn connected_peers_with_f_2_1_2() -> Result<()> {
connected_peers_with_f(2, 10_050)
}

#[test]
fn connected_peers_with_f_1_0_1() {
fn connected_peers_with_f_1_0_1() -> Result<()> {
connected_peers_with_f(1, 10_150)
}

/// Test the number of connected peers, changing the number of faults tolerated down and up
fn connected_peers_with_f(faults: u64, port: u16) {
fn connected_peers_with_f(faults: u64, port: u16) -> Result<()> {
let n_peers = 3 * faults + 1;

#[allow(clippy::expect_used)]
let (_rt, network, genesis_client) = <Network>::start_test_with_runtime(
let (_rt, network, client) = <Network>::start_test_with_runtime(
(n_peers)
.try_into()
.expect("`faults` argument `u64` value too high, cannot convert to `u32`"),
1,
.wrap_err("`faults` argument `u64` value too high, cannot convert to `u32`")?,
Some(port),
);
wait_for_genesis_committed(&network.clients(), 0);
let pipeline_time = Configuration::pipeline_time();

client.submit_blocking(
ParametersBuilder::new()
.add_parameter(MAX_TRANSACTIONS_IN_BLOCK, 1u32)?
.into_set_parameters(),
)?;

// Confirm all peers connected
let mut status = genesis_client.get_status().unwrap();
let mut status = client.get_status()?;
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
let peer = network.peers.values().last().unwrap();
let peer_client = Client::test(&peer.api_address, &peer.telemetry_address);
let unregister_peer = UnregisterBox::new(IdBox::PeerId(peer.id.clone()));
genesis_client.submit(unregister_peer).unwrap();
client.submit(unregister_peer)?;
thread::sleep(pipeline_time * 2);
status = genesis_client.get_status().unwrap();
status = client.get_status()?;
assert_eq!(status.peers, n_peers - 2);
assert_eq!(status.blocks, 2);
status = peer_client.get_status().unwrap();
assert_eq!(status.blocks, 3);
status = peer_client.get_status()?;
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
let register_peer = RegisterBox::new(DataModelPeer::new(peer.id.clone()));
genesis_client.submit(register_peer).unwrap();
client.submit(register_peer)?;
thread::sleep(pipeline_time * 4);
status = genesis_client.get_status().unwrap();
status = client.get_status()?;
assert_eq!(status.peers, n_peers - 1);
assert_eq!(status.blocks, 3);
status = peer_client.get_status().unwrap();
assert_eq!(status.blocks, 4);
status = peer_client.get_status()?;
assert_eq!(status.peers, n_peers - 1);
assert_eq!(status.blocks, 3);
assert_eq!(status.blocks, 4);

Ok(())
}
18 changes: 14 additions & 4 deletions client/tests/integration/events/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
use std::thread::{self, JoinHandle};

use eyre::Result;
use iroha_data_model::prelude::*;
use iroha_data_model::{
parameter::{default::MAX_TRANSACTIONS_IN_BLOCK, ParametersBuilder},
prelude::*,
};
use test_network::*;

use super::Configuration;
Expand Down Expand Up @@ -36,13 +39,20 @@ fn test_with_instruction_and_status_and_port(
should_be: PipelineStatusKind,
port: u16,
) -> Result<()> {
let (_rt, network, genesis_client) =
<Network>::start_test_with_runtime(PEER_COUNT.try_into().unwrap(), 1, Some(port));
let (_rt, network, client) =
<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();

client.submit_blocking(
ParametersBuilder::new()
.add_parameter(MAX_TRANSACTIONS_IN_BLOCK, 1u32)?
.into_set_parameters(),
)?;

// Given
let submitter = genesis_client;
let submitter = client;
let transaction = submitter.build_transaction(instruction, UnlimitedMetadata::new())?;
let hash = transaction.hash();
let mut handles = Vec::new();
Expand Down
Loading

0 comments on commit c9a3539

Please sign in to comment.