Skip to content

Commit

Permalink
refactor: unify executor data model
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Balashov <43530070+0x009922@users.noreply.github.com>
  • Loading branch information
0x009922 committed May 16, 2024
1 parent f12077d commit 1520c94
Show file tree
Hide file tree
Showing 56 changed files with 1,310 additions and 1,528 deletions.
21 changes: 6 additions & 15 deletions client/benches/tps/utils.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
use std::{fmt, fs::File, io::BufReader, path::Path, sync::mpsc, thread, time};

use eyre::{Result, WrapErr};
use iroha_client::{
client::Client,
crypto::KeyPair,
data_model::{
parameter::{default::MAX_TRANSACTIONS_IN_BLOCK, ParametersBuilder},
prelude::*,
},
};
use iroha_client::{client::Client,crypto::KeyPair,
data_model::prelude::*};
use iroha_data_model::events::pipeline::{BlockEventFilter, BlockStatus};
use nonzero_ext::nonzero;
use serde::Deserialize;
Expand Down Expand Up @@ -51,16 +45,13 @@ impl Config {

pub fn measure(self) -> Result<Tps> {
// READY
let (_rt, network, client) = Network::start_test_with_runtime(self.peers, None);
let (_rt, network, client) = Network::start_test_with_runtime(
NetworkOptions::with_n_peers(self.peers)
.with_max_txs_in_block(self.max_txs_per_block.try_into().unwrap()),
);
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(),
)?;

let unit_names = (UnitName::MIN..).take(self.peers as usize);
let units = clients
.into_iter()
Expand Down
17 changes: 11 additions & 6 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ impl_query_output! {
crate::data_model::block::BlockHeader,
crate::data_model::metadata::MetadataValueBox,
crate::data_model::query::TransactionQueryOutput,
crate::data_model::permission::PermissionTokenSchema,
crate::data_model::executor::ExecutorDataModel,
crate::data_model::trigger::Trigger,
crate::data_model::prelude::Numeric,
}
Expand Down Expand Up @@ -1523,11 +1523,6 @@ pub mod permission {
//! Module with queries for permission tokens
use super::*;

/// Construct a query to get all registered [`PermissionTokenDefinition`]s
pub const fn permission_token_schema() -> FindPermissionTokenSchema {
FindPermissionTokenSchema {}
}

/// Construct a query to get all [`PermissionToken`] granted
/// to account with given [`Id`][AccountId]
pub fn by_account_id(account_id: AccountId) -> FindPermissionTokensByAccountId {
Expand Down Expand Up @@ -1570,6 +1565,16 @@ pub mod parameter {
}
}

pub mod executor {
//! Queries for executor entities
use super::*;

/// Retrieve executor data model
pub const fn data_model() -> FindExecutorDataModel {
FindExecutorDataModel
}
}

#[cfg(test)]
mod tests {
use std::str::FromStr;
Expand Down
18 changes: 7 additions & 11 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::{
client::{self, QueryResult},
data_model::{
parameter::{default::MAX_TRANSACTIONS_IN_BLOCK, ParametersBuilder},
prelude::*,
},
data_model::prelude::*,
};
use iroha_config::parameters::actual::Root as Config;
use nonzero_ext::nonzero;
use test_network::*;
use test_samples::gen_account_in;

Expand All @@ -18,16 +16,14 @@ use test_samples::gen_account_in;
fn client_add_asset_quantity_to_existing_asset_should_increase_asset_amount_on_another_peer(
) -> Result<()> {
// Given
let (_rt, network, client) = Network::start_test_with_runtime(4, Some(10_450));
let (_rt, network, client) = Network::start_test_with_runtime(
NetworkOptions::with_n_peers(4)
.with_start_port(10_450)
.with_max_txs_in_block(nonzero!(1u32)),
);
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(),
)?;

let create_domain: InstructionBox =
Register::domain(Domain::new(DomainId::from_str("domain")?)).into();
let (account_id, _account_keypair) = gen_account_in("domain");
Expand Down
22 changes: 7 additions & 15 deletions client/tests/integration/events/pipeline.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
use std::thread::{self, JoinHandle};

use eyre::Result;
use iroha_client::{
crypto::HashOf,
data_model::{
parameter::{default::MAX_TRANSACTIONS_IN_BLOCK, ParametersBuilder},
prelude::*,
},
};
use iroha_client::{crypto::HashOf, data_model::prelude::*};
use iroha_config::parameters::actual::Root as Config;
use iroha_data_model::{
events::pipeline::{
Expand All @@ -17,6 +11,7 @@ use iroha_data_model::{
transaction::error::TransactionRejectionReason,
ValidationFail,
};
use nonzero_ext::nonzero;
use test_network::*;

// Needed to re-enable ignored tests.
Expand Down Expand Up @@ -49,18 +44,15 @@ fn test_with_instruction_and_status_and_port(
should_be: &TransactionStatus,
port: u16,
) -> Result<()> {
let (_rt, network, client) =
Network::start_test_with_runtime(PEER_COUNT.try_into().unwrap(), Some(port));
let (_rt, network, client) = Network::start_test_with_runtime(
NetworkOptions::with_n_peers(PEER_COUNT.try_into().unwrap())
.with_start_port(port)
.with_max_txs_in_block(nonzero!(1u32)),
);
let clients = network.clients();
wait_for_genesis_committed(&clients, 0);
let pipeline_time = Config::pipeline_time();

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

// Given
let submitter = client;
let transaction = submitter.build_transaction(instruction, UnlimitedMetadata::new());
Expand Down
19 changes: 11 additions & 8 deletions client/tests/integration/extra_functional/connected_peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ use tokio::runtime::Runtime;
#[ignore = "ignore, more in #2851"]
#[test]
fn connected_peers_with_f_2_1_2() -> Result<()> {
connected_peers_with_f(2, Some(11_020))
connected_peers_with_f(2, 11_020)
}

#[test]
fn connected_peers_with_f_1_0_1() -> Result<()> {
connected_peers_with_f(1, Some(11_000))
connected_peers_with_f(1, 11_000)
}

#[test]
fn register_new_peer() -> Result<()> {
let (_rt, network, _) = Network::start_test_with_runtime(4, Some(11_180));
let (_rt, network, _) =
Network::start_test_with_runtime(NetworkOptions::with_n_peers(4).with_start_port(11_180));
wait_for_genesis_committed(&network.clients(), 0);
let pipeline_time = Config::pipeline_time();

Expand Down Expand Up @@ -65,14 +66,16 @@ fn register_new_peer() -> Result<()> {
}

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

let (_rt, network, _) = Network::start_test_with_runtime(
(n_peers)
.try_into()
.wrap_err("`faults` argument `u64` value too high, cannot convert to `u32`")?,
start_port,
NetworkOptions::with_n_peers(
(n_peers)
.try_into()
.wrap_err("`faults` argument `u64` value too high, cannot convert to `u32`")?,
)
.with_start_port(start_port),
);
wait_for_genesis_committed(&network.clients(), 0);
let pipeline_time = Config::pipeline_time();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ use std::thread;
use eyre::Result;
use iroha_client::{
client::{self, Client, QueryResult},
data_model::{
parameter::{default::MAX_TRANSACTIONS_IN_BLOCK, ParametersBuilder},
prelude::*,
},
data_model::prelude::*,
};
use iroha_config::parameters::actual::Root as Config;
use nonzero_ext::nonzero;
use test_network::*;
use test_samples::gen_account_in;

Expand All @@ -18,16 +16,14 @@ const N_BLOCKS: usize = 510;
#[test]
fn long_multiple_blocks_created() -> Result<()> {
// Given
let (_rt, network, client) = Network::start_test_with_runtime(4, Some(10_965));
let (_rt, network, client) = Network::start_test_with_runtime(
NetworkOptions::with_n_peers(4)
.with_start_port(10_965)
.with_max_txs_in_block(nonzero!(1u32)),
);
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(),
)?;

let create_domain: InstructionBox = Register::domain(Domain::new("domain".parse()?)).into();
let (account_id, _account_keypair) = gen_account_in("domain");
let create_account = Register::account(Account::new(account_id.clone())).into();
Expand Down
13 changes: 6 additions & 7 deletions client/tests/integration/extra_functional/offline_peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ fn genesis_block_is_committed_with_some_offline_peers() -> Result<()> {
// Given
let rt = Runtime::test();

let (network, client) = rt.block_on(Network::start_test_with_offline_and_set_n_shifts(
4,
1,
Some(10_560),
let (network, client) = rt.block_on(Network::start_test(
NetworkOptions::with_n_peers(4)
.with_offline_peers(1)
.with_start_port(10_560),
));
wait_for_genesis_committed(&network.clients(), 1);

Expand All @@ -44,9 +44,8 @@ fn genesis_block_is_committed_with_some_offline_peers() -> Result<()> {

#[test]
fn register_offline_peer() -> Result<()> {
let n_peers = 4;

let (_rt, network, client) = Network::start_test_with_runtime(n_peers, Some(11_160));
let (_rt, network, client) =
Network::start_test_with_runtime(NetworkOptions::with_n_peers(4).with_start_port(11_160));
wait_for_genesis_committed(&network.clients(), 0);
let pipeline_time = Config::pipeline_time();
let peer_clients = Network::clients(&network);
Expand Down
4 changes: 3 additions & 1 deletion client/tests/integration/extra_functional/restart_peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ fn restarted_peer_should_have_the_same_asset_amount() -> Result<()> {
let mut removed_peer = {
let n_peers = 4;

let (_rt, network, _) = Network::start_test_with_runtime(n_peers, Some(11_205));
let (_rt, network, _) = Network::start_test_with_runtime(
NetworkOptions::with_n_peers(n_peers).with_start_port(11_205),
);
wait_for_genesis_committed(&network.clients(), 0);
let pipeline_time = Config::pipeline_time();
let peer_clients = Network::clients(&network);
Expand Down
21 changes: 10 additions & 11 deletions client/tests/integration/extra_functional/unregister_peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ use std::thread;
use eyre::Result;
use iroha_client::{
client::{self, QueryResult},
data_model::{
parameter::{default::MAX_TRANSACTIONS_IN_BLOCK, ParametersBuilder},
prelude::*,
},
data_model::prelude::*,
};
use iroha_config::parameters::actual::Root as Config;
use nonzero_ext::nonzero;
use test_network::*;
use test_samples::gen_account_in;

Expand Down Expand Up @@ -114,24 +112,25 @@ fn init() -> Result<(
AccountId,
AssetDefinitionId,
)> {
let (rt, network, client) = Network::start_test_with_runtime(4, Some(10_925));
let (rt, network, client) = Network::start_test_with_runtime(
NetworkOptions::with_n_peers(4)
.with_start_port(10_925)
.with_max_txs_in_block(nonzero!(1u32)),
);
let pipeline_time = Config::pipeline_time();
iroha_logger::info!("Started");
let parameters = ParametersBuilder::new()
.add_parameter(MAX_TRANSACTIONS_IN_BLOCK, 1u32)?
.into_set_parameters();
let create_domain = Register::domain(Domain::new("domain".parse()?));
let (account_id, _account_keypair) = gen_account_in("domain");
let create_account = Register::account(Account::new(account_id.clone()));
let asset_definition_id: AssetDefinitionId = "xor#domain".parse()?;
let create_asset =
Register::asset_definition(AssetDefinition::numeric(asset_definition_id.clone()));
let instructions = parameters.into_iter().chain([
let isi: [InstructionBox; 3] = [
create_domain.into(),
create_account.into(),
create_asset.into(),
]);
client.submit_all_blocking(instructions)?;
];
client.submit_all_blocking(isi)?;
iroha_logger::info!("Init");
Ok((
rt,
Expand Down
15 changes: 10 additions & 5 deletions client/tests/integration/extra_functional/unstable_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,16 @@ fn unstable_network(
{
configuration.sumeragi.debug_force_soft_fork = force_soft_fork;
}
let network = Network::new_with_offline_peers(
Some(configuration),
n_peers + n_offline_peers,
0,
Some(port),
let network = Network::new(
NetworkOptions::with_n_peers(n_peers + n_offline_peers)
.with_start_port(port)
.with_max_txs_in_block(MAX_TRANSACTIONS_IN_BLOCK.try_into().unwrap())
.with_config_mut(|cfg| {
#[cfg(debug_assertions)]
{
cfg.sumeragi.debug_force_soft_fork = force_soft_fork;
}
}),
)
.await
.expect("Failed to init peers");
Expand Down
2 changes: 1 addition & 1 deletion client/tests/integration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ mod events;
mod extra_functional;
mod non_mintable;
mod pagination;
mod parameters;
mod permissions;
mod queries;
mod roles;
mod set_parameter;
mod sorting;
mod status_response;
mod transfer_asset;
Expand Down
Empty file.
Loading

0 comments on commit 1520c94

Please sign in to comment.