Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

The Ambassador Program #2002

Open
wants to merge 53 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
f885e71
Ambassador Program minimum setup
muharem Dec 19, 2022
8e76281
head ambassador rank
muharem Jan 9, 2023
0541b4b
docs
muharem Jan 9, 2023
5cf1abf
pallet_collective_content, tests, benches
muharem Jan 11, 2023
07075dd
clean dev code
muharem Jan 11, 2023
80df39c
docs, worst case fot bench
muharem Jan 12, 2023
8c288e3
docs
muharem Jan 12, 2023
5bd566d
collective content pallet generic over instance (I)
muharem Jan 12, 2023
5356d11
fix docs
muharem Jan 12, 2023
8112e48
ranks public
muharem Jan 12, 2023
0ffbaaf
rustfmt
muharem Jan 12, 2023
b81ba28
fix
muharem Jan 12, 2023
9b89c1d
add try runtime feature to collective content pallet
muharem Jan 12, 2023
bbe116c
Merge remote-tracking branch 'origin/master' into muharem-ambassador-…
muharem Jan 14, 2023
6104edb
typo fixes, announcement origin, ambassador proxy
muharem Jan 25, 2023
f0c3a60
announcements with an expiration
muharem Jan 25, 2023
514fce9
cleaup announcements on idle
muharem Jan 27, 2023
1323be3
docs and proxy definition changes
joepetrowski Jan 31, 2023
f200aef
merge master
joepetrowski Jan 31, 2023
1b867de
remove unused import
joepetrowski Jan 31, 2023
174a9a8
review fixes
muharem Feb 6, 2023
9017a8b
storage map for the announcements
muharem Feb 6, 2023
d602443
max scheduler per block for benches
muharem Feb 7, 2023
07c7d86
rename weights files
muharem Feb 7, 2023
fe57ff2
remove todo, update comment
muharem Feb 14, 2023
5f111a2
ToParentTreasury impl
muharem Feb 16, 2023
2ef13d0
Merge remote-tracking branch 'origin/master' into muharem-ambassador-…
muharem Aug 1, 2023
48363a7
fixes after mater merge
muharem Aug 1, 2023
a9926fb
more ranks, renames, salary and core pallets
muharem Aug 9, 2023
5313c68
ensure origin types, reuse common types
muharem Aug 10, 2023
cb79c45
fixes
muharem Aug 11, 2023
f867832
Merge remote-tracking branch 'origin/master' into muharem-ambassador-…
muharem Aug 11, 2023
35e0417
benchmark script void output file name
muharem Aug 11, 2023
d515363
weights
muharem Aug 11, 2023
c238fb2
docs fixes
muharem Aug 14, 2023
9ab6aa4
promote origin for rank 0
muharem Aug 14, 2023
67902de
Apply suggestions from code review
muharem Aug 18, 2023
54bd222
renames
muharem Aug 18, 2023
d5118b0
benchmarks v2
muharem Aug 18, 2023
15ad2f5
defensive count inc/dec
muharem Aug 18, 2023
9a562c5
default announcement lifetime, fee free expired announcement removal
muharem Aug 18, 2023
08153e7
salary in dot
muharem Aug 18, 2023
b7d8da7
Merge remote-tracking branch 'origin/master' into muharem-ambassador-…
muharem Aug 18, 2023
273e9af
benchmark fix
muharem Aug 18, 2023
9ae1f68
paymaster test
muharem Aug 18, 2023
fd88108
".git/.scripts/commands/fmt/fmt.sh"
Aug 18, 2023
56baa6a
Merge remote-tracking branch 'origin/master' into muharem-ambassador-…
Aug 21, 2023
8efb683
Merge remote-tracking branch 'origin/master' into muharem-ambassador-…
muharem Aug 22, 2023
f9c1c06
rename and tracks settings
muharem Aug 22, 2023
40bf76e
Merge remote-tracking branch 'origin/master' into muharem-ambassador-…
muharem Aug 22, 2023
69036ba
ignore test
muharem Aug 22, 2023
421d3cf
comment test
muharem Aug 22, 2023
1d625c0
Merge remote-tracking branch 'origin/master' into muharem-ambassador-…
Aug 24, 2023
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
2 changes: 2 additions & 0 deletions Cargo.lock

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

16 changes: 0 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,6 @@ members = [
"primitives/parachain-inherent",
"primitives/timestamp",
"primitives/utility",
"polkadot-parachain",
"parachains/common",
"parachains/pallets/collective-content",
"parachains/pallets/parachain-info",
"parachains/pallets/ping",
"parachains/runtimes/testing/rococo-parachain",
"parachains/runtimes/starters/shell",
"parachains/runtimes/starters/seedling",
"parachains/runtimes/assets/statemint",
"parachains/runtimes/assets/statemine",
"parachains/runtimes/assets/westmint",
"parachains/runtimes/bridge-hubs/bridge-hub-rococo",
"parachains/runtimes/bridge-hubs/bridge-hub-kusama",
"parachains/runtimes/collectives/collectives-polkadot",
"parachains/runtimes/contracts/contracts-rococo",
"parachains/runtimes/testing/penpal",
"test/client",
"test/relay-sproof-builder",
"test/relay-validation-worker-provider",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright Parity Technologies (UK) Ltd.
// This file is part of Cumulus.

// Cumulus is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Cumulus is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.

//! Integration tests concerning the Fellowship.

use crate::*;
use collectives_polkadot_runtime::ambassador::AmbassadorSalaryPaymaster;
use frame_support::traits::{fungible::Mutate, tokens::Pay};
use sp_core::crypto::Ss58Codec;
use xcm_emulator::TestExt;

#[test]
fn pay_salary() {
let pay_from: AccountId =
<AccountId as Ss58Codec>::from_string("5DS1Gaf6R9eFAV8QyeZP9P89kTkJMurxv3y3J3TTMu8p8VCX")
.unwrap();
let pay_to = Polkadot::account_id_of(ALICE);
let pay_amount = 90000000000;

AssetHubPolkadot::execute_with(|| {
type AssetHubBalances = <AssetHubPolkadot as AssetHubPolkadotPallet>::Balances;

assert_ok!(<AssetHubBalances as Mutate<_>>::mint_into(&pay_from, pay_amount * 2));
});

Collectives::execute_with(|| {
type RuntimeEvent = <Collectives as Chain>::RuntimeEvent;

assert_ok!(AmbassadorSalaryPaymaster::pay(&pay_to, (), pay_amount));
assert_expected_events!(
Collectives,
vec![
RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::XcmpMessageSent { .. }) => {},
]
);
});

AssetHubPolkadot::execute_with(|| {
type RuntimeEvent = <AssetHubPolkadot as Chain>::RuntimeEvent;

assert_expected_events!(
AssetHubPolkadot,
vec![
RuntimeEvent::Balances(pallet_balances::Event::Transfer { from, to, amount }) => {
from: from == &pay_from,
to: to == &pay_to,
amount: amount == &pay_amount,
},
RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::Success { .. }) => {},
]
);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.

mod ambassador;
mod fellowship;
103 changes: 56 additions & 47 deletions parachains/pallets/collective-content/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

//! The pallet benchmarks.

use super::{DispatchTimeFor, Pallet as CollectiveContent, *};
use frame_benchmarking::benchmarks_instance_pallet;
use frame_support::traits::{EnsureOrigin, UnfilteredDispatchable};
use super::{Pallet as CollectiveContent, *};
use frame_benchmarking::{impl_benchmark_test_suite, v2::*};
use frame_support::traits::EnsureOrigin;

fn assert_last_event<T: Config<I>, I: 'static>(generic_event: <T as Config<I>>::RuntimeEvent) {
frame_system::Pallet::<T>::assert_last_event(generic_event.into());
Expand All @@ -29,78 +29,87 @@ fn create_cid(i: u8) -> OpaqueCid {
cid
}

benchmarks_instance_pallet! {
set_charter {
#[instance_benchmarks]
mod benchmarks {
use super::*;

#[benchmark]
fn set_charter() -> Result<(), BenchmarkError> {
let cid: OpaqueCid = create_cid(1);
let call = Call::<T, I>::set_charter { cid: cid.clone() };
let origin = T::CharterOrigin::successful_origin();
}: { call.dispatch_bypass_filter(origin)? }
verify {
let origin =
T::CharterOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;

#[extrinsic_call]
_(origin as T::RuntimeOrigin, cid.clone());

assert_eq!(CollectiveContent::<T, I>::charter(), Some(cid.clone()));
assert_last_event::<T, I>(Event::NewCharterSet { cid }.into());
Ok(())
}

announce {
let x in 0 .. 1;

let mut maybe_expire = None;
if x == 1 {
maybe_expire = Some(DispatchTimeFor::<T>::At(10u32.into()));
}
#[benchmark]
fn announce() -> Result<(), BenchmarkError> {
let expire_at = DispatchTime::<_>::At(10u32.into());
let now = frame_system::Pallet::<T>::block_number();
let cid: OpaqueCid = create_cid(1);
let call = Call::<T, I>::announce {
cid: cid.clone(),
maybe_expire: maybe_expire.clone(),
};
let origin = T::AnnouncementOrigin::successful_origin();
}: { call.dispatch_bypass_filter(origin)? }
verify {
let origin = T::AnnouncementOrigin::try_successful_origin()
.map_err(|_| BenchmarkError::Weightless)?;

#[extrinsic_call]
_(origin as T::RuntimeOrigin, cid.clone(), Some(expire_at.clone()));

assert_eq!(CollectiveContent::<T, I>::announcements_count(), 1);
assert_eq!(NextAnnouncementExpireAt::<T, I>::get().map_or(0, |_| 1), x);
assert_last_event::<T, I>(Event::AnnouncementAnnounced {
cid,
maybe_expire_at: maybe_expire.map_or(None, |e| Some(e.evaluate(now))),
}.into());
assert_last_event::<T, I>(
Event::AnnouncementAnnounced { cid, expire_at: expire_at.evaluate(now) }.into(),
);

Ok(())
}

remove_announcement {
#[benchmark]
fn remove_announcement() -> Result<(), BenchmarkError> {
let cid: OpaqueCid = create_cid(1);
let origin = T::AnnouncementOrigin::successful_origin();
CollectiveContent::<T, I>::announce(
origin.clone(),
cid.clone(),
None,
).expect("could not publish an announcement");
let origin = T::AnnouncementOrigin::try_successful_origin()
.map_err(|_| BenchmarkError::Weightless)?;
CollectiveContent::<T, I>::announce(origin.clone(), cid.clone(), None)
.expect("could not publish an announcement");
assert_eq!(CollectiveContent::<T, I>::announcements_count(), 1);

let call = Call::<T, I>::remove_announcement { cid: cid.clone() };
}: { call.dispatch_bypass_filter(origin)? }
verify {
#[extrinsic_call]
_(origin as T::RuntimeOrigin, cid.clone());

assert_eq!(CollectiveContent::<T, I>::announcements_count(), 0);
assert_last_event::<T, I>(Event::AnnouncementRemoved { cid }.into());

Ok(())
}

cleanup_announcements {
let x in 0 .. 100;
let origin = T::AnnouncementOrigin::successful_origin();
#[benchmark]
fn cleanup_announcements(x: Linear<0, 100>) -> Result<(), BenchmarkError> {
let origin = T::AnnouncementOrigin::try_successful_origin().unwrap();

let max_count = x;
for i in 0..max_count {
let cid: OpaqueCid = create_cid(i as u8);
CollectiveContent::<T, I>::announce(
origin.clone(),
cid,
Some(DispatchTimeFor::<T>::At(5u32.into())),
).expect("could not publish an announcement");
Some(DispatchTime::<_>::At(5u32.into())),
)
.expect("could not publish an announcement");
}
assert_eq!(CollectiveContent::<T, I>::announcements_count(), max_count);
frame_system::Pallet::<T>::set_block_number(10u32.into());
}: {
CollectiveContent::<T, I>::cleanup_announcements(10u32.into());
} verify {

#[block]
{
CollectiveContent::<T, I>::cleanup_announcements(10u32.into());
}

assert_eq!(CollectiveContent::<T, I>::announcements_count(), 0);
assert_eq!(frame_system::Pallet::<T>::events().len() as u32, max_count)
assert_eq!(frame_system::Pallet::<T>::events().len() as u32, max_count);

Ok(())
}

impl_benchmark_test_suite!(CollectiveContent, super::mock::new_bench_ext(), super::mock::Test);
Expand Down
Loading