-
Notifications
You must be signed in to change notification settings - Fork 283
feat: generic structure through execution cycle #5355
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
Draft
s8sato
wants to merge
10
commits into
hyperledger-iroha:main
Choose a base branch
from
s8sato:feat/GXC
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5fb5fc0
ci: install `irohad` with features
s8sato 8e200b6
test: tests for #4937 trigger per transaction
s8sato 5e68f2c
test: benchmark for #5356 refactoring execution cycle
s8sato 5150b36
feat: generic structure through execution cycle
s8sato 5b0aa90
feat: safe trigger registration behind `prediction` feature (not yet …
s8sato c037b99
docs: add references to related issues
s8sato e29878d
fixup! feat: safe trigger registration behind `prediction` feature (n…
s8sato 820187c
fixup! ci: install `irohad` with features
s8sato 63bd64b
fixup! feat: generic structure through execution cycle
s8sato 8825d23
Merge branch 'main' into feat/GXC
s8sato File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| #![expect(missing_docs)] | ||
|
|
||
| use criterion::{criterion_group, criterion_main, Criterion}; | ||
| use iroha::{ | ||
| client::Client, | ||
| data_model::{parameter::BlockParameter, prelude::*}, | ||
| }; | ||
| use iroha_test_network::*; | ||
| use iroha_test_samples::{load_sample_wasm, ALICE_ID, BOB_ID}; | ||
| use nonzero_ext::nonzero; | ||
|
|
||
| const N_TRANSACTIONS_PER_BLOCK: u64 = 1; | ||
|
|
||
| fn bench(c: &mut Criterion) { | ||
| let mut group = c.benchmark_group("one_block"); | ||
| group.sample_size(10); | ||
| group.bench_function("trigger_executable_builtin", |b| { | ||
| b.iter_batched(setup_builtin, routine, criterion::BatchSize::SmallInput); | ||
| }); | ||
| group.bench_function("trigger_executable_wasm", |b| { | ||
| b.iter_batched(setup_wasm, routine, criterion::BatchSize::SmallInput); | ||
| }); | ||
| group.finish(); | ||
| } | ||
|
|
||
| fn setup_builtin() -> Input { | ||
| let rose: AssetDefinitionId = "rose#wonderland".parse().unwrap(); | ||
| let rose_alice: AssetId = format!("{rose}#{}", ALICE_ID.clone()).parse().unwrap(); | ||
| let transfer_rose_alice_bob = Transfer::asset_numeric(rose_alice.clone(), 1u32, BOB_ID.clone()); | ||
| setup(vec![transfer_rose_alice_bob]) | ||
| } | ||
|
|
||
| fn setup_wasm() -> Input { | ||
| setup(load_sample_wasm("trigger_transfer_one")) | ||
| } | ||
|
|
||
| /// Given a test network equipped with a trigger | ||
| fn setup(trigger_executable: impl Into<Executable>) -> Input { | ||
| let rose: AssetDefinitionId = "rose#wonderland".parse().unwrap(); | ||
| let rose_alice: AssetId = format!("{rose}#{}", ALICE_ID.clone()).parse().unwrap(); | ||
| let rose_bob: AssetId = format!("{rose}#{}", BOB_ID.clone()).parse().unwrap(); | ||
| let register_trigger = Register::trigger(Trigger::new( | ||
| "transfer_one_to_bob_on_mint_roses_at_alice" | ||
| .parse() | ||
| .unwrap(), | ||
| Action::new( | ||
| trigger_executable, | ||
| Repeats::Indefinitely, | ||
| ALICE_ID.clone(), | ||
| AssetEventFilter::new() | ||
| .for_asset(rose_alice.clone()) | ||
| .for_events(AssetEventSet::Created), | ||
| ), | ||
| )); | ||
| let (network, rt) = NetworkBuilder::new() | ||
| .with_genesis_instruction(register_trigger) | ||
| .with_genesis_instruction(SetParameter::new(Parameter::Block( | ||
| BlockParameter::MaxTransactions(nonzero!(N_TRANSACTIONS_PER_BLOCK)), | ||
| ))) | ||
| .start_blocking() | ||
| .unwrap(); | ||
| let mut test_client = network.client(); | ||
| test_client.add_transaction_nonce = true; | ||
| let n0_rose_alice = get_asset_value(&test_client, rose_alice.clone()); | ||
| let n0_rose_bob = get_asset_value(&test_client, rose_bob.clone()); | ||
| let mint_rose_alice = Mint::asset_numeric(1u32, rose_alice.clone()); | ||
|
|
||
| Input { | ||
| network, | ||
| rt, | ||
| test_client, | ||
| rose_alice, | ||
| rose_bob, | ||
| n0_rose_alice, | ||
| n0_rose_bob, | ||
| mint_rose_alice, | ||
| } | ||
| } | ||
|
|
||
| struct Input { | ||
| network: Network, | ||
| rt: tokio::runtime::Runtime, | ||
| test_client: Client, | ||
| rose_alice: AssetId, | ||
| rose_bob: AssetId, | ||
| n0_rose_alice: Numeric, | ||
| n0_rose_bob: Numeric, | ||
| mint_rose_alice: Mint<Numeric, Asset>, | ||
| } | ||
|
|
||
| /// # Scenario | ||
| /// | ||
| /// 0. Transaction: [mint a rose for Alice, mint another rose for Alice] | ||
| /// 0. Trigger execution: asset created (some roses for Alice) -> transfer a rose from Alice to Bob | ||
| fn routine( | ||
| Input { | ||
| network: _network, | ||
| rt: _rt, | ||
| test_client, | ||
| rose_alice, | ||
| rose_bob, | ||
| n0_rose_alice, | ||
| n0_rose_bob, | ||
| mint_rose_alice, | ||
| }: Input, | ||
| ) { | ||
| let mint_twice = [mint_rose_alice.clone(), mint_rose_alice]; | ||
| #[allow(clippy::reversed_empty_ranges)] | ||
| for _ in 1..N_TRANSACTIONS_PER_BLOCK { | ||
| // Transaction nonce is enabled in setup, otherwise hashes may collide | ||
| test_client | ||
| .submit_all(mint_twice.clone()) | ||
| .expect("transaction should be submitted"); | ||
| } | ||
| test_client | ||
| .submit_all_blocking(mint_twice) | ||
| .expect("transaction should be committed"); | ||
| // TODO peer.once_block(2) | ||
| assert_eq!( | ||
| test_client.get_status().unwrap().blocks, | ||
| 2, | ||
| "Extra blocks created" | ||
| ); | ||
|
|
||
| let n1_rose_alice = get_asset_value(&test_client, rose_alice); | ||
| let n1_rose_bob = get_asset_value(&test_client, rose_bob); | ||
|
|
||
| // FIXME | ||
| // assert_eq!( | ||
| // n1_rose_alice, | ||
| // n0_rose_alice.checked_add(N_TRANSACTIONS_PER_BLOCK.into()).unwrap() | ||
| // ); | ||
| // assert_eq!(n1_rose_bob, n0_rose_bob.checked_add(N_TRANSACTIONS_PER_BLOCK.into()).unwrap()); | ||
| assert_eq!( | ||
| n1_rose_alice, | ||
| n0_rose_alice | ||
| .checked_add(Numeric::from(2 * N_TRANSACTIONS_PER_BLOCK)) | ||
| .unwrap() | ||
| ); | ||
| assert_eq!(n1_rose_bob, n0_rose_bob); | ||
| } | ||
|
|
||
| fn get_asset_value(client: &Client, asset_id: AssetId) -> Numeric { | ||
| let Ok(asset) = client | ||
| .query(FindAssets::new()) | ||
| .filter_with(|asset| asset.id.eq(asset_id)) | ||
| .execute_single() | ||
| else { | ||
| return Numeric::ZERO; | ||
| }; | ||
|
|
||
| *asset.value() | ||
| } | ||
|
|
||
| criterion_group!(benches, bench); | ||
| criterion_main!(benches); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.