-
Notifications
You must be signed in to change notification settings - Fork 6
Ak adjust westend and tests #148
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
Changes from 4 commits
64401a5
373eda4
c538a1a
209867a
da27436
3658f38
32d839f
1c11c48
3810dc5
014ef43
3f9f609
65a5578
c50859f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,26 @@ use xcm_runtime_apis::conversions::LocationToAccountHelper; | |
|
|
||
| const ALICE: [u8; 32] = [1u8; 32]; | ||
|
|
||
| /// Advance to the next block for testing transaction storage. | ||
| fn advance_block() { | ||
| use bulletin_westend_runtime::TransactionStorage; | ||
| use frame_support::traits::{OnFinalize, OnInitialize}; | ||
|
|
||
| let current = frame_system::Pallet::<Runtime>::block_number(); | ||
|
|
||
| TransactionStorage::on_finalize(current); | ||
| System::on_finalize(current); | ||
|
|
||
| let next = current + 1; | ||
| System::set_block_number(next); | ||
|
|
||
| frame_system::BlockWeight::<Runtime>::kill(); | ||
| frame_system::AllExtrinsicsLen::<Runtime>::kill(); | ||
|
|
||
| System::on_initialize(next); | ||
| TransactionStorage::on_initialize(next); | ||
| } | ||
|
|
||
| fn construct_extrinsic( | ||
| sender: sp_core::sr25519::Pair, | ||
| call: RuntimeCall, | ||
|
|
@@ -105,11 +125,11 @@ fn transaction_storage_runtime_sizes() { | |
| let who: AccountId = account.to_account_id(); | ||
| #[allow(clippy::identity_op)] | ||
| let sizes: [usize; 5] = [ | ||
| 2000, // 2 KB | ||
| 256 * 1024, // 256 KB | ||
| 512 * 1024, // 512 KB | ||
| 1 * 1024 * 1024, // 1 MB | ||
| (3 * 1024 * 1024) / 2, // 1.5 MB | ||
| 2000, // 2 KB | ||
| 1 * 1024 * 1024, // 1 MB | ||
| 4 * 1024 * 1024, // 4 MB | ||
| 6 * 1024 * 1024, // 6 MB | ||
| 8 * 1024 * 1024, // 8 MB | ||
| ]; | ||
| let total_bytes: u64 = sizes.iter().map(|s| *s as u64).sum(); | ||
|
|
||
|
|
@@ -131,6 +151,9 @@ fn transaction_storage_runtime_sizes() { | |
|
|
||
| // store data via signed extrinsics (ValidateSigned consumes authorization) | ||
| for (index, size) in sizes.into_iter().enumerate() { | ||
| // Advance to a new block for each store | ||
| advance_block(); | ||
|
|
||
| tracing::info!("Storing data with size: {size} and index: {index}"); | ||
| let res = construct_and_apply_extrinsic( | ||
| account.pair(), | ||
|
|
@@ -178,6 +201,66 @@ fn transaction_storage_runtime_sizes() { | |
| }); | ||
| } | ||
|
|
||
| /// Test maximum write throughput: 8 transactions of 1 MiB each in a single block (8 MiB total). | ||
| #[test] | ||
| fn transaction_storage_max_throughput() { | ||
bkontur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| use bulletin_westend_runtime as runtime; | ||
| use bulletin_westend_runtime::BuildStorage; | ||
| use frame_support::assert_ok; | ||
| use pallet_transaction_storage::{AuthorizationExtent, Call as TxStorageCall}; | ||
| use sp_keyring::Sr25519Keyring; | ||
|
|
||
| const NUM_TRANSACTIONS: u32 = 8; | ||
bkontur marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const TRANSACTION_SIZE: usize = 1 * 1024 * 1024; // 1 MiB | ||
bkontur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const TOTAL_BYTES: u64 = (NUM_TRANSACTIONS as u64) * (TRANSACTION_SIZE as u64); // 8 MiB | ||
|
|
||
| sp_io::TestExternalities::new( | ||
| runtime::RuntimeGenesisConfig::default().build_storage().unwrap(), | ||
| ) | ||
| .execute_with(|| { | ||
| let account = Sr25519Keyring::Alice; | ||
| let who: AccountId = account.to_account_id(); | ||
|
|
||
| // fund Alice to cover length-based tx fees | ||
| let initial: Balance = 10_000_000_000_000_000_000u128; | ||
| <pallet_balances::Pallet<Runtime> as FungibleMutate<_>>::set_balance(&who, initial); | ||
bkontur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // authorize 8 transactions of 1 MiB each | ||
| assert_ok!(runtime::TransactionStorage::authorize_account( | ||
| RuntimeOrigin::root(), | ||
| who.clone(), | ||
| NUM_TRANSACTIONS, | ||
| TOTAL_BYTES, | ||
| )); | ||
| assert_eq!( | ||
| runtime::TransactionStorage::account_authorization_extent(who.clone()), | ||
| AuthorizationExtent { transactions: NUM_TRANSACTIONS, bytes: TOTAL_BYTES }, | ||
| ); | ||
|
|
||
| // Advance to a fresh block | ||
| advance_block(); | ||
|
|
||
| // Store all 8 transactions in the same block (no advance_block between them) | ||
| for index in 0..NUM_TRANSACTIONS { | ||
| tracing::info!("Storing 1 MiB transaction {}/{}", index + 1, NUM_TRANSACTIONS); | ||
bkontur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| let res = construct_and_apply_extrinsic( | ||
| account.pair(), | ||
| RuntimeCall::TransactionStorage(TxStorageCall::<Runtime>::store { | ||
| data: vec![0u8; TRANSACTION_SIZE], | ||
| }), | ||
| ); | ||
| assert_ok!(res); | ||
| assert_ok!(res.unwrap()); | ||
| } | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @antkve when 8 (or 9) passes, then I would add here one more store with construct_and_apply_extrinsic, which should fail because of We should also cover
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bkontur Okay but at the moment we'd need to advance it for the whole set storage period to call check_proof. Should I do that or just leave a TODO for when configurable StoragePeriod is merged?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Create follow-up issue and TODO please |
||
| // Verify all authorizations were consumed | ||
| assert_eq!( | ||
| runtime::TransactionStorage::account_authorization_extent(who.clone()), | ||
| AuthorizationExtent { transactions: 0, bytes: 0 }, | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| #[test] | ||
| fn location_conversion_works() { | ||
| // the purpose of hardcoded values is to catch an unintended location conversion logic change. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.