Skip to content

Commit

Permalink
experiment hrmp weighing
Browse files Browse the repository at this point in the history
  • Loading branch information
JuaniRios committed Jul 8, 2024
1 parent 9139d8a commit d7ce482
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ scale-info = { workspace = true, features = ["derive"] }

# Local
polimec-receiver.workspace = true
polimec-xcm-executor.workspace = true
macros.workspace = true
polimec-common.workspace = true
polimec-common-test-utils.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/src/tests/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,4 @@ fn execution_fees_go_to_treasury() {
assert_reserve_asset_fee_goes_to_treasury(usdt_amount);
assert_reserve_asset_fee_goes_to_treasury(usdc_amount);
assert_plmc_fee_goes_to_treasury();
}
}
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ benchmark-runtime chain="polimec-paseo-local" pallet="pallet-elections-phragmen"
# src: https://github.com/paritytech/polkadot-sdk/blob/bc2e5e1fe26e2c2c8ee766ff9fe7be7e212a0c62/substrate/frame/nfts/src/weights.rs
# Run the Runtime benchmarks for a specific pallet
benchmark-pallet chain="polimec-paseo-local" pallet="pallet-dispenser":
cargo run --features runtime-benchmarks --release -p polimec-node benchmark pallet \
cargo run --features runtime-benchmarks --profile=production -p polimec-node benchmark pallet \
--chain={{ chain }} \
--steps=50 \
--repeat=20 \
Expand Down
115 changes: 115 additions & 0 deletions pallets/funding/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3340,6 +3340,107 @@ mod benchmarks {
);
}

#[benchmark]
fn do_handle_channel_open_request() {
// setup
let mut inst = BenchInstantiator::<T>::new(None);
<T as Config>::SetPrices::set_prices();

let issuer = account::<AccountIdOf<T>>("issuer", 0, 0);

let project_metadata = default_project_metadata::<T>(issuer.clone());
let project_id = inst.create_finished_project(
project_metadata.clone(),
issuer.clone(),
default_evaluations::<T>(),
default_bids::<T>(),
default_community_contributions::<T>(),
vec![],
);

let settlement_block = inst.get_update_block(project_id, &UpdateType::StartSettlement).unwrap();
inst.jump_to_block(settlement_block);

inst.settle_project(project_id).unwrap();

let jwt = get_mock_jwt_with_cid(
issuer.clone(),
InvestorType::Institutional,
generate_did_from_account(issuer.clone()),
project_metadata.clone().policy_ipfs_cid.unwrap(),
);

crate::Pallet::<T>::start_pallet_migration(
RawOrigin::Signed(issuer.clone()).into(),
jwt.clone(),
project_id,
6969u32.into(),
)
.unwrap();

#[block]
{
crate::Pallet::<T>::do_handle_channel_open_request(Instruction::HrmpNewChannelOpenRequest {
sender: 6969u32,
max_message_size: 102_400u32,
max_capacity: 1000,
})
.unwrap();
}
}

#[benchmark]
fn do_handle_channel_accepted() {
// setup
let mut inst = BenchInstantiator::<T>::new(None);
<T as Config>::SetPrices::set_prices();

let issuer = account::<AccountIdOf<T>>("issuer", 0, 0);

let project_metadata = default_project_metadata::<T>(issuer.clone());
let project_id = inst.create_finished_project(
project_metadata.clone(),
issuer.clone(),
default_evaluations::<T>(),
default_bids::<T>(),
default_community_contributions::<T>(),
vec![],
);

let settlement_block = inst.get_update_block(project_id, &UpdateType::StartSettlement).unwrap();
inst.jump_to_block(settlement_block);

inst.settle_project(project_id).unwrap();

let jwt = get_mock_jwt_with_cid(
issuer.clone(),
InvestorType::Institutional,
generate_did_from_account(issuer.clone()),
project_metadata.clone().policy_ipfs_cid.unwrap(),
);

crate::Pallet::<T>::start_pallet_migration(
RawOrigin::Signed(issuer.clone()).into(),
jwt.clone(),
project_id,
6969u32.into(),
)
.unwrap();

crate::Pallet::<T>::do_handle_channel_open_request(Instruction::HrmpNewChannelOpenRequest {
sender: 6969u32,
max_message_size: 102_400u32,
max_capacity: 1000,
})
.unwrap();

#[block]
{
crate::Pallet::<T>::do_handle_channel_accepted(Instruction::HrmpChannelAccepted { recipient: 6969u32 })
.unwrap();
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -3604,5 +3705,19 @@ mod benchmarks {
assert_ok!(PalletFunding::<TestRuntime>::test_confirm_pallet_migrations());
});
}

#[test]
fn bench_do_handle_channel_open_request() {
new_test_ext().execute_with(|| {
assert_ok!(PalletFunding::<TestRuntime>::test_do_handle_channel_open_request());
});
}

#[test]
fn bench_do_handle_channel_accepted() {
new_test_ext().execute_with(|| {
assert_ok!(PalletFunding::<TestRuntime>::test_do_handle_channel_accepted());
});
}
}
}

0 comments on commit d7ce482

Please sign in to comment.