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

[feature] #3941, #3612: Remove expressions #4089

Merged
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
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
76 changes: 11 additions & 65 deletions client/benches/tps/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use iroha_client::{
},
};
use serde::Deserialize;
use serde_json::json;
use test_network::*;

pub type Tps = f64;
Expand Down Expand Up @@ -61,7 +60,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 +69,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 +153,6 @@ struct MeasurerUnit {
pub config: Config,
pub client: Client,
pub name: UnitName,
pub next_name: UnitName,
}

type UnitName = u32;
Expand All @@ -169,34 +166,13 @@ impl MeasurerUnit {
let keypair = iroha_crypto::KeyPair::generate().expect("Failed to generate KeyPair.");

let account_id = account_id(self.name);
let alice_id = AccountId::from_str("alice@wonderland")?;
let asset_id = asset_id(self.name);

let register_me = RegisterExpr::new(Account::new(
account_id.clone(),
[keypair.public_key().clone()],
));
let register_me =
Register::account(Account::new(account_id, [keypair.public_key().clone()]));
self.client.submit_blocking(register_me)?;

let can_burn_my_asset = PermissionToken::new(
"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 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 grant_tx = TransactionBuilder::new(account_id)
.with_instructions([
allow_alice_to_burn_my_asset,
allow_alice_to_transfer_my_asset,
])
.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 +243,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
Loading