Skip to content

Commit

Permalink
[feature] hyperledger-iroha#3941, hyperledger-iroha#3612: Remove expr…
Browse files Browse the repository at this point in the history
…essions

Signed-off-by: Daniil Polyakov <[email protected]>
  • Loading branch information
Arjentix committed Dec 13, 2023
1 parent a2ff9a0 commit efdcc4e
Show file tree
Hide file tree
Showing 108 changed files with 4,003 additions and 6,822 deletions.
23 changes: 0 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ members = [
"genesis",
"primitives",
"primitives/derive",
"dsl",
"ffi",
"ffi/derive",
"futures",
Expand Down
4 changes: 1 addition & 3 deletions cli/src/torii/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ impl Error {
QueryFailed(query_error)
| InstructionFailed(InstructionExecutionError::Query(query_error)) => match query_error
{
Evaluate(_) | Conversion(_) | UnknownCursor | FetchSizeTooBig => {
StatusCode::BAD_REQUEST
}
Conversion(_) | UnknownCursor | FetchSizeTooBig => StatusCode::BAD_REQUEST,
Signature(_) => StatusCode::UNAUTHORIZED,
Find(_) => StatusCode::NOT_FOUND,
},
Expand Down
29 changes: 14 additions & 15 deletions client/benches/torii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use iroha_client::{
data_model::prelude::*,
};
use iroha_crypto::KeyPair;
use iroha_data_model::isi::InstructionBox;
use iroha_genesis::{GenesisNetwork, RawGenesisBlockBuilder};
use iroha_primitives::unique_vec;
use iroha_version::Encode;
Expand Down Expand Up @@ -51,18 +52,19 @@ fn query_requests(criterion: &mut Criterion) {
});
let mut group = criterion.benchmark_group("query-requests");
let domain_id: DomainId = "domain".parse().expect("Valid");
let create_domain = RegisterExpr::new(Domain::new(domain_id.clone()));
let create_domain = Register::domain(Domain::new(domain_id.clone()));
let account_id = AccountId::new("account".parse().expect("Valid"), domain_id.clone());
let (public_key, _) = KeyPair::generate()
.expect("Failed to generate KeyPair")
.into();
let create_account = RegisterExpr::new(Account::new(account_id.clone(), [public_key]));
let create_account = Register::account(Account::new(account_id.clone(), [public_key]));
let asset_definition_id = AssetDefinitionId::new("xor".parse().expect("Valid"), domain_id);
let create_asset = RegisterExpr::new(AssetDefinition::quantity(asset_definition_id.clone()));
let create_asset =
Register::asset_definition(AssetDefinition::quantity(asset_definition_id.clone()));
let quantity: u32 = 200;
let mint_asset = MintExpr::new(
quantity.to_value(),
IdBox::AssetId(AssetId::new(asset_definition_id, account_id.clone())),
let mint_asset = Mint::asset_quantity(
quantity,
AssetId::new(asset_definition_id, account_id.clone()),
);
let mut client_config = iroha_client::samples::get_client_config(&get_key_pair());

Expand All @@ -71,7 +73,7 @@ fn query_requests(criterion: &mut Criterion) {
let iroha_client = Client::new(&client_config).expect("Invalid client configuration");
thread::sleep(std::time::Duration::from_millis(5000));

let instructions: [InstructionExpr; 4] = [
let instructions: [InstructionBox; 4] = [
create_domain.into(),
create_account.into(),
create_asset.into(),
Expand Down Expand Up @@ -140,12 +142,12 @@ fn instruction_submits(criterion: &mut Criterion) {
rt.block_on(builder.start_with_peer(&mut peer));
let mut group = criterion.benchmark_group("instruction-requests");
let domain_id: DomainId = "domain".parse().expect("Valid");
let create_domain = RegisterExpr::new(Domain::new(domain_id.clone()));
let create_domain: InstructionBox = Register::domain(Domain::new(domain_id.clone())).into();
let account_id = AccountId::new("account".parse().expect("Valid"), domain_id.clone());
let (public_key, _) = KeyPair::generate()
.expect("Failed to generate Key-pair.")
.into();
let create_account = RegisterExpr::new(Account::new(account_id.clone(), [public_key]));
let create_account = Register::account(Account::new(account_id.clone(), [public_key])).into();
let asset_definition_id = AssetDefinitionId::new("xor".parse().expect("Valid"), domain_id);
let mut client_config = iroha_client::samples::get_client_config(&get_key_pair());
client_config.torii_api_url = format!("http://{}", peer.api_address).parse().unwrap();
Expand All @@ -160,12 +162,9 @@ fn instruction_submits(criterion: &mut Criterion) {
let _dropable = group.bench_function("instructions", |b| {
b.iter(|| {
let quantity: u32 = 200;
let mint_asset = MintExpr::new(
quantity.to_value(),
IdBox::AssetId(AssetId::new(
asset_definition_id.clone(),
account_id.clone(),
)),
let mint_asset = Mint::asset_quantity(
quantity,
AssetId::new(asset_definition_id.clone(), account_id.clone()),
);
match iroha_client.submit(mint_asset) {
Ok(_) => success_count += 1,
Expand Down
58 changes: 14 additions & 44 deletions client/benches/tps/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Config {
let clients = network.clients();
wait_for_genesis_committed(&clients, 0);

client.submit_blocking(
client.submit_all_blocking(
ParametersBuilder::new()
.add_parameter(MAX_TRANSACTIONS_IN_BLOCK, self.max_txs_per_block)?
.into_set_parameters(),
Expand All @@ -70,13 +70,12 @@ impl Config {
let unit_names = (UnitName::MIN..).take(self.peers as usize);
let units = clients
.into_iter()
.zip(unit_names.clone().zip(unit_names.cycle().skip(1)))
.map(|(client, pair)| {
.zip(unit_names)
.map(|(client, name)| {
let unit = MeasurerUnit {
config: self,
client,
name: pair.0,
next_name: pair.1,
name,
};
unit.ready()
})
Expand Down Expand Up @@ -155,7 +154,6 @@ struct MeasurerUnit {
pub config: Config,
pub client: Client,
pub name: UnitName,
pub next_name: UnitName,
}

type UnitName = u32;
Expand All @@ -172,7 +170,7 @@ impl MeasurerUnit {
let alice_id = AccountId::from_str("alice@wonderland")?;
let asset_id = asset_id(self.name);

let register_me = RegisterExpr::new(Account::new(
let register_me = Register::account(Account::new(
account_id.clone(),
[keypair.public_key().clone()],
));
Expand All @@ -182,12 +180,14 @@ impl MeasurerUnit {
"CanBurnUserAsset".parse().unwrap(),
&json!({ "asset_id": asset_id }),
);
let allow_alice_to_burn_my_asset = GrantExpr::new(can_burn_my_asset, alice_id.clone());
let allow_alice_to_burn_my_asset =
Grant::permission_token(can_burn_my_asset, alice_id.clone());
let can_transfer_my_asset = PermissionToken::new(
"CanTransferUserAsset".parse().unwrap(),
&json!({ "asset_id": asset_id }),
);
let allow_alice_to_transfer_my_asset = GrantExpr::new(can_transfer_my_asset, alice_id);
let allow_alice_to_transfer_my_asset =
Grant::permission_token(can_transfer_my_asset, alice_id);
let grant_tx = TransactionBuilder::new(account_id)
.with_instructions([
allow_alice_to_burn_my_asset,
Expand All @@ -196,7 +196,7 @@ impl MeasurerUnit {
.sign(keypair)?;
self.client.submit_transaction_blocking(&grant_tx)?;

let mint_a_rose = MintExpr::new(1_u32, asset_id);
let mint_a_rose = Mint::asset_quantity(1_u32, asset_id);
self.client.submit_blocking(mint_a_rose)?;

Ok(self)
Expand Down Expand Up @@ -267,42 +267,12 @@ impl MeasurerUnit {
})
}

fn instructions(&self) -> impl Iterator<Item = InstructionExpr> {
[self.mint_or_burn(), self.relay_a_rose()]
.into_iter()
.cycle()
}

fn mint_or_burn(&self) -> InstructionExpr {
let is_running_out = Less::new(
EvaluatesTo::new_unchecked(Expression::Query(
FindAssetQuantityById::new(asset_id(self.name)).into(),
)),
100_u32,
);
let supply_roses = MintExpr::new(100_u32.to_value(), asset_id(self.name));
let burn_a_rose = BurnExpr::new(1_u32.to_value(), asset_id(self.name));

ConditionalExpr::with_otherwise(is_running_out, supply_roses, burn_a_rose).into()
fn instructions(&self) -> impl Iterator<Item = InstructionBox> {
std::iter::once(self.mint()).cycle()
}

fn relay_a_rose(&self) -> InstructionExpr {
// Save at least one rose
// because if asset value hits 0 it's automatically deleted from account
// and query `FindAssetQuantityById` return error
let enough_to_transfer = Greater::new(
EvaluatesTo::new_unchecked(Expression::Query(
FindAssetQuantityById::new(asset_id(self.name)).into(),
)),
1_u32,
);
let transfer_rose = TransferExpr::new(
asset_id(self.name),
1_u32.to_value(),
account_id(self.next_name),
);

ConditionalExpr::new(enough_to_transfer, transfer_rose).into()
fn mint(&self) -> InstructionBox {
Mint::asset_quantity(1_u32, asset_id(self.name)).into()
}
}

Expand Down
5 changes: 3 additions & 2 deletions client/examples/million_accounts_genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{thread, time::Duration};

use iroha::samples::{construct_executor, get_config};
use iroha_client::data_model::prelude::*;
use iroha_data_model::isi::InstructionBox;
use iroha_genesis::{GenesisNetwork, RawGenesisBlock, RawGenesisBlockBuilder};
use iroha_primitives::unique_vec;
use test_network::{
Expand Down Expand Up @@ -64,8 +65,8 @@ fn create_million_accounts_directly() {
format!("bob-{i}").parse().expect("Valid"),
domain_id.clone(),
);
let create_domain = RegisterExpr::new(Domain::new(domain_id));
let create_account = RegisterExpr::new(Account::new(normal_account_id.clone(), []));
let create_domain: InstructionBox = Register::domain(Domain::new(domain_id)).into();
let create_account = Register::account(Account::new(normal_account_id.clone(), [])).into();
if test_client
.submit_all([create_domain, create_account])
.is_err()
Expand Down
Loading

0 comments on commit efdcc4e

Please sign in to comment.