Skip to content

Commit

Permalink
adds cap_limit, end_block and update_vault (#1039)
Browse files Browse the repository at this point in the history
* adds cap_limit, end_block and update_vault

* updates cap and fixes relay block check

* updates benchmarking

* Update benchmarking.rs

* fixes benchmarking

* add missing commas

* adds UpdateVaultOrigin to all runtimes

* adds RelayChainBlockNumberProvider to runtimes

* add BlockNumberProvider to runtime imports

* add BlockNumberProvider to heiko runtime

* remove unneeded conversion

* clippy fix

* Fix lint & cap

Signed-off-by: Cheng JIANG <[email protected]>

* updates launch to include new vault args

* update benchmarks and launch for trie_index

* refactor and fix new vault args

* refactor benchmarking

* refactor benchmarking and tests

* update cap type and add hash trait

* add missing trie_index

* create vault before update in bench

* add missing vault check on create

* remove try-runtime ci

Signed-off-by: Cheng JIANG <[email protected]>

* Fix build

Signed-off-by: Cheng JIANG <[email protected]>

* remove unecessary clippy allow

Signed-off-by: Cheng JIANG <[email protected]>

* Fix benchs

Signed-off-by: Cheng JIANG <[email protected]>

* /home/alex_cj96/.cargo/bin/cargo run --release --features=runtime-benchmarks --bin parallel -- benchmark --chain=vanilla-dev --steps=50 --repeat=20 --pallet=pallet_crowdloans --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./pallets/crowdloans/src/weights.rs --template=./.maintain/frame-weight-template.hbs

* /home/alex_cj96/.cargo/bin/cargo run --release --features=runtime-benchmarks --bin parallel -- benchmark --chain=vanilla-dev --steps=50 --repeat=20 --pallet=pallet_crowdloans --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./pallets/crowdloans/src/weights.rs --template=./.maintain/frame-weight-template.hbs

Co-authored-by: Cheng JIANG <[email protected]>
  • Loading branch information
drbh and GopherJ authored Dec 16, 2021
1 parent 1a43f64 commit 723c7c4
Show file tree
Hide file tree
Showing 11 changed files with 366 additions and 173 deletions.
54 changes: 0 additions & 54 deletions .github/workflows/try-runtime.yml

This file was deleted.

5 changes: 3 additions & 2 deletions launch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ async function para() {
const keyring = new Keyring({ type: 'sr25519', ss58Format: 110 })
const signer = keyring.addFromUri('//Dave')
const call = []
const height = await chainHeight(api)

for (const { name, symbol, assetId, decimal, marketOption, balances } of config.assets) {
console.log(`Create ${name}(${symbol}) asset, ptokenId is ${marketOption.ptokenId}`)
Expand All @@ -132,8 +133,8 @@ async function para() {
call.push(...balances.map(([account, amount]) => api.tx.assets.mint(assetId, account, amount)))
}

for (const { paraId, image, chain, ctokenId, pending } of config.crowdloans) {
call.push(api.tx.sudo.sudo(api.tx.crowdloans.createVault(paraId, ctokenId, 'XCM')))
for (const { paraId, image, chain, ctokenId, cap, duration, pending } of config.crowdloans) {
call.push(api.tx.sudo.sudo(api.tx.crowdloans.createVault(paraId, ctokenId, 'XCM', cap, height + duration)))
if (!pending) {
call.push(api.tx.sudo.sudo(api.tx.crowdloans.open(paraId)))
}
Expand Down
78 changes: 56 additions & 22 deletions pallets/crowdloans/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ const XCM_WEIGHT: XcmWeightMisc<Weight> = XcmWeightMisc {
const CONTRIBUTE_AMOUNT: u128 = 20000000000000u128;
const INITIAL_RESERVES: u128 = 1000000000000000u128;
const INITIAL_AMOUNT: u128 = 1000000000000000u128;
const LARGE_CAP: u128 = 1_000_000_000_000_000u128;
const CAP: u128 = 1_000_000_000_000_000u128;
const END_BLOCK: u32 = 1_000_000_000u32;

fn assert_last_event<T: Config>(generic_event: <T as Config>::Event) {
frame_system::Pallet::<T>::assert_last_event(generic_event.into());
Expand Down Expand Up @@ -92,24 +95,46 @@ benchmarks! {
create_vault {
let ctoken = 8;
let caller: T::AccountId = whitelisted_caller();
let crowdloan = ParaId::from(1334);
let crowdloan = ParaId::from(1334u32);

initial_set_up::<T>(caller, ctoken);
}: _(
SystemOrigin::Root,
crowdloan,
ctoken,
ContributionStrategy::XCM
ContributionStrategy::XCM,
CAP,
END_BLOCK
)
verify {
assert_last_event::<T>(Event::<T>::VaultCreated(crowdloan, ctoken).into())
}

update_vault {
let ctoken = 8;
let crowdloan = ParaId::from(1334u32);
let caller: T::AccountId = whitelisted_caller();
initial_set_up::<T>(caller, ctoken);
// create vault before update
assert_ok!(Crowdloans::<T>::create_vault(SystemOrigin::Root.into(), crowdloan, ctoken, ContributionStrategy::XCM, CAP, END_BLOCK));
}: _(
SystemOrigin::Root,
crowdloan,
Some(1_000_000_000_001),
Some(1_000_000_001u32),
Some(ContributionStrategy::XCM)
)
verify {
assert_last_event::<T>(Event::<T>::VaultUpdated(crowdloan).into())
}

contribute {
let ctoken = 9;
let caller: T::AccountId = whitelisted_caller();
let crowdloan = ParaId::from(1335);
let crowdloan = ParaId::from(1335u32);

initial_set_up::<T>(caller.clone(), ctoken);
assert_ok!(Crowdloans::<T>::create_vault(SystemOrigin::Root.into(), crowdloan, ctoken, ContributionStrategy::XCM));
assert_ok!(Crowdloans::<T>::create_vault(SystemOrigin::Root.into(), crowdloan, ctoken, ContributionStrategy::XCM, CAP, END_BLOCK));
assert_ok!(Crowdloans::<T>::open(SystemOrigin::Root.into(), crowdloan));
}: _(
SystemOrigin::Signed(caller.clone()),
Expand All @@ -124,9 +149,10 @@ benchmarks! {
open {
let ctoken = 10;
let caller: T::AccountId = whitelisted_caller();
let crowdloan = ParaId::from(1336);
let crowdloan = ParaId::from(1336u32);

initial_set_up::<T>(caller, ctoken);
assert_ok!(Crowdloans::<T>::create_vault(SystemOrigin::Root.into(), crowdloan, ctoken, ContributionStrategy::XCM));
assert_ok!(Crowdloans::<T>::create_vault(SystemOrigin::Root.into(), crowdloan, ctoken, ContributionStrategy::XCM, CAP, END_BLOCK));
}: _(
SystemOrigin::Root,
crowdloan
Expand All @@ -138,9 +164,10 @@ benchmarks! {
close {
let ctoken = 11;
let caller: T::AccountId = whitelisted_caller();
let crowdloan = ParaId::from(1337);
let crowdloan = ParaId::from(1337u32);

initial_set_up::<T>(caller, ctoken);
assert_ok!(Crowdloans::<T>::create_vault(SystemOrigin::Root.into(), crowdloan, ctoken, ContributionStrategy::XCM));
assert_ok!(Crowdloans::<T>::create_vault(SystemOrigin::Root.into(), crowdloan, ctoken, ContributionStrategy::XCM, CAP, END_BLOCK));
assert_ok!(Crowdloans::<T>::open(SystemOrigin::Root.into(), crowdloan));
}: _(
SystemOrigin::Root,
Expand All @@ -153,9 +180,10 @@ benchmarks! {
set_vrfs {
let ctoken = 12;
let caller: T::AccountId = whitelisted_caller();
let crowdloan = ParaId::from(1338);
let crowdloan = ParaId::from(1338u32);

initial_set_up::<T>(caller, ctoken);
assert_ok!(Crowdloans::<T>::create_vault(SystemOrigin::Root.into(), crowdloan, ctoken, ContributionStrategy::XCM));
assert_ok!(Crowdloans::<T>::create_vault(SystemOrigin::Root.into(), crowdloan, ctoken, ContributionStrategy::XCM, CAP, END_BLOCK));
}: _(
SystemOrigin::Root,
vec![ParaId::from(1336u32), ParaId::from(1337u32)]
Expand All @@ -168,9 +196,10 @@ benchmarks! {
reopen {
let ctoken = 13;
let caller: T::AccountId = whitelisted_caller();
let crowdloan = ParaId::from(1339);
let crowdloan = ParaId::from(1339u32);

initial_set_up::<T>(caller, ctoken);
assert_ok!(Crowdloans::<T>::create_vault(SystemOrigin::Root.into(), crowdloan, ctoken, ContributionStrategy::XCM));
assert_ok!(Crowdloans::<T>::create_vault(SystemOrigin::Root.into(), crowdloan, ctoken, ContributionStrategy::XCM, CAP, END_BLOCK));
assert_ok!(Crowdloans::<T>::open(SystemOrigin::Root.into(), crowdloan));
assert_ok!(Crowdloans::<T>::close(SystemOrigin::Root.into(), crowdloan));
}: _(
Expand All @@ -184,9 +213,10 @@ benchmarks! {
auction_failed {
let ctoken = 14;
let caller: T::AccountId = whitelisted_caller();
let crowdloan = ParaId::from(1340);
let crowdloan = ParaId::from(1340u32);

initial_set_up::<T>(caller.clone(), ctoken);
assert_ok!(Crowdloans::<T>::create_vault(SystemOrigin::Root.into(), crowdloan, ctoken, ContributionStrategy::XCM));
assert_ok!(Crowdloans::<T>::create_vault(SystemOrigin::Root.into(), crowdloan, ctoken, ContributionStrategy::XCM, LARGE_CAP, END_BLOCK));
assert_ok!(Crowdloans::<T>::open(SystemOrigin::Root.into(), crowdloan));
assert_ok!(Crowdloans::<T>::contribute(SystemOrigin::Signed(caller).into(), crowdloan, CONTRIBUTE_AMOUNT, Vec::new()));
assert_ok!(Crowdloans::<T>::close(SystemOrigin::Root.into(), crowdloan));
Expand All @@ -202,9 +232,10 @@ benchmarks! {
claim_refund {
let ctoken = 15;
let caller: T::AccountId = whitelisted_caller();
let crowdloan = ParaId::from(1341);
let crowdloan = ParaId::from(1341u32);

initial_set_up::<T>(caller.clone(), ctoken);
assert_ok!(Crowdloans::<T>::create_vault(SystemOrigin::Root.into(), crowdloan, ctoken, ContributionStrategy::XCM));
assert_ok!(Crowdloans::<T>::create_vault(SystemOrigin::Root.into(), crowdloan, ctoken, ContributionStrategy::XCM, LARGE_CAP, END_BLOCK));
assert_ok!(Crowdloans::<T>::open(SystemOrigin::Root.into(), crowdloan));
assert_ok!(Crowdloans::<T>::contribute(SystemOrigin::Signed(caller.clone()).into(), crowdloan, CONTRIBUTE_AMOUNT, Vec::new()));
assert_ok!(Crowdloans::<T>::notification_received(
Expand All @@ -231,9 +262,10 @@ benchmarks! {
slot_expired {
let ctoken = 16;
let caller: T::AccountId = whitelisted_caller();
let crowdloan = ParaId::from(1342);
let crowdloan = ParaId::from(1342u32);

initial_set_up::<T>(caller.clone(), ctoken);
assert_ok!(Crowdloans::<T>::create_vault(SystemOrigin::Root.into(), crowdloan, ctoken, ContributionStrategy::XCM));
assert_ok!(Crowdloans::<T>::create_vault(SystemOrigin::Root.into(), crowdloan, ctoken, ContributionStrategy::XCM, LARGE_CAP, END_BLOCK));
assert_ok!(Crowdloans::<T>::open(SystemOrigin::Root.into(), crowdloan));
assert_ok!(Crowdloans::<T>::contribute(SystemOrigin::Signed(caller).into(), crowdloan, CONTRIBUTE_AMOUNT, Vec::new()));
assert_ok!(Crowdloans::<T>::close(SystemOrigin::Root.into(), crowdloan));
Expand All @@ -248,9 +280,10 @@ benchmarks! {
migrate_pending {
let ctoken = 17;
let caller: T::AccountId = whitelisted_caller();
let crowdloan = ParaId::from(1343);
let crowdloan = ParaId::from(1343u32);

initial_set_up::<T>(caller.clone(), ctoken);
assert_ok!(Crowdloans::<T>::create_vault(SystemOrigin::Root.into(), crowdloan, ctoken, ContributionStrategy::XCM));
assert_ok!(Crowdloans::<T>::create_vault(SystemOrigin::Root.into(), crowdloan, ctoken, ContributionStrategy::XCM, LARGE_CAP, END_BLOCK));
for _ in 0..10 {
assert_ok!(Crowdloans::<T>::contribute(SystemOrigin::Signed(caller.clone()).into(), crowdloan, CONTRIBUTE_AMOUNT, Vec::new()));
}
Expand All @@ -265,9 +298,10 @@ benchmarks! {
notification_received {
let ctoken = 18;
let caller: T::AccountId = whitelisted_caller();
let crowdloan = ParaId::from(1344);
let crowdloan = ParaId::from(1344u32);

initial_set_up::<T>(caller.clone(), ctoken);
assert_ok!(Crowdloans::<T>::create_vault(SystemOrigin::Root.into(), crowdloan, ctoken, ContributionStrategy::XCM));
assert_ok!(Crowdloans::<T>::create_vault(SystemOrigin::Root.into(), crowdloan, ctoken, ContributionStrategy::XCM, LARGE_CAP, END_BLOCK));
assert_ok!(Crowdloans::<T>::open(SystemOrigin::Root.into(), crowdloan));
assert_ok!(Crowdloans::<T>::contribute(SystemOrigin::Signed(caller).into(), crowdloan, CONTRIBUTE_AMOUNT, Vec::new()));
}: _(
Expand Down
Loading

0 comments on commit 723c7c4

Please sign in to comment.