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 46 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
16 changes: 16 additions & 0 deletions Cargo.lock

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

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;
45 changes: 45 additions & 0 deletions parachains/pallets/collective-content/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[package]
name = "pallet-collective-content"
version = "0.1.0"
authors = ["Parity Technologies <[email protected]>"]
edition = "2021"
description = "Managed content"

[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive", "max-encoded-len"] }
scale-info = { version = "2.3.0", default-features = false, features = ["derive"] }

frame-benchmarking = { git = "https://github.com/paritytech/substrate", optional = true, default-features = false, branch = "master" }
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }

sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }

[dev-dependencies]
sp-io = { git = "https://github.com/paritytech/substrate", branch = "master" }

[features]
default = [ "std" ]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]

std = [
"codec/std",
"scale-info/std",
"frame-support/std",
"frame-system/std",
"sp-core/std",
"sp-runtime/std",
"sp-std/std",
]

try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
]
116 changes: 116 additions & 0 deletions parachains/pallets/collective-content/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// Copyright (C) 2023 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! The pallet benchmarks.

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());
}

/// returns CID hash of 68 bytes of given `i`.
fn create_cid(i: u8) -> OpaqueCid {
let cid: OpaqueCid = [i; 68].to_vec().try_into().unwrap();
cid
}

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

#[benchmark]
fn set_charter() -> Result<(), BenchmarkError> {
let cid: OpaqueCid = create_cid(1);
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(())
}

#[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 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_last_event::<T, I>(
Event::AnnouncementAnnounced { cid, expire_at: expire_at.evaluate(now) }.into(),
);

Ok(())
}

#[benchmark]
fn remove_announcement() -> Result<(), BenchmarkError> {
let cid: OpaqueCid = create_cid(1);
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);

#[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(())
}

#[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(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());

#[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);

Ok(())
}

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