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 1 commit
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
Next Next commit
Ambassador Program minimum setup
  • Loading branch information
muharem committed Dec 19, 2022
commit f885e715d08dcb54d41e9e1f9b29f5630bd4338b
4 changes: 4 additions & 0 deletions Cargo.lock

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

16 changes: 16 additions & 0 deletions parachains/runtimes/collectives/collectives-polkadot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ pallet-authorship = { git = "https://github.com/paritytech/substrate", default-f
pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-collective = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-multisig = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-preimage = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-proxy = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-scheduler = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-utility = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-referenda = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
pallet-ranked-collective = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-block-builder = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-consensus-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
Expand Down Expand Up @@ -95,6 +99,10 @@ runtime-benchmarks = [
"cumulus-pallet-session-benchmarking/runtime-benchmarks",
"pallet-collator-selection/runtime-benchmarks",
"cumulus-pallet-xcmp-queue/runtime-benchmarks",
"pallet-scheduler/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"pallet-referenda/runtime-benchmarks",
"pallet-ranked-collective/runtime-benchmarks",
]
try-runtime = [
"cumulus-pallet-aura-ext/try-runtime",
Expand All @@ -119,6 +127,10 @@ try-runtime = [
"pallet-utility/try-runtime",
"pallet-xcm/try-runtime",
"parachain-info/try-runtime",
"pallet-scheduler/try-runtime",
"pallet-preimage/try-runtime",
"pallet-referenda/try-runtime",
"pallet-ranked-collective/try-runtime",
]
std = [
"codec/std",
Expand Down Expand Up @@ -170,4 +182,8 @@ std = [
"pallet-collator-selection/std",
"parachain-info/std",
"parachains-common/std",
"pallet-scheduler/std",
"pallet-preimage/std",
"pallet-referenda/std",
"pallet-ranked-collective/std",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Copyright (C) 2022 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 Ambassador Program.
/// todo docs
mod pallet;
mod tracks;
pub mod types;

use super::*;
use frame_support::traits::MapSuccess;
pub use pallet::pallet as pallet_ambassador;
use pallet::pallet::{
Ambassador as AmbassadorOrigin, Origin, SeniorAmbassador as SeniorAmbassadorOrigin,
};
use sp_runtime::traits::Replace;

impl pallet_ambassador::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type AmbassadorOrigin = AmbassadorOrigin;
type MemberOrigin = pallet_ranked_collective::EnsureMember<
Runtime,
AmbassadorCollectiveInstance,
1, // todo types::ranks::AMBASSADOR
>;
type MaxAnnouncementsCount = ConstU32<100>;
}

parameter_types! {
pub const AlarmInterval: BlockNumber = 1;
pub const SubmissionDeposit: Balance = 0;
pub const UndecidingTimeout: BlockNumber = 7 * DAYS;
}

pub type AmbassadorReferendaInstance = pallet_referenda::Instance1;

impl pallet_referenda::Config<AmbassadorReferendaInstance> for Runtime {
type WeightInfo = (); // TODO use actual weights
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type Scheduler = Scheduler;
type Currency = Balances;
type SubmitOrigin = pallet_ranked_collective::EnsureMember<
Runtime,
AmbassadorCollectiveInstance,
1, // todo types::ranks::AMBASSADOR
>;
type CancelOrigin = EitherOf<EnsureRoot<AccountId>, SeniorAmbassadorOrigin>;
type KillOrigin = EitherOf<EnsureRoot<AccountId>, SeniorAmbassadorOrigin>;
type Slash = ToParentTreasury<Runtime>;
type Votes = pallet_ranked_collective::Votes;
type Tally = pallet_ranked_collective::TallyOf<Runtime, AmbassadorCollectiveInstance>;
type SubmissionDeposit = SubmissionDeposit;
type MaxQueued = ConstU32<100>;
type UndecidingTimeout = UndecidingTimeout;
type AlarmInterval = AlarmInterval;
type Tracks = tracks::TracksInfo;
type Preimages = Preimage;
}

parameter_types! {
pub const CandidateRank: types::Rank = types::ranks::CANDIDATE;
pub const AmbassadorRank: types::Rank = types::ranks::AMBASSADOR;
pub const SeniorAmbassadorRank: types::Rank = types::ranks::SENIOR_AMBASSADOR;
}

pub type AmbassadorCollectiveInstance = pallet_ranked_collective::Instance1;

impl pallet_ranked_collective::Config<AmbassadorCollectiveInstance> for Runtime {
type WeightInfo = (); // TODO use actual weights
type RuntimeEvent = RuntimeEvent;
type PromoteOrigin = EitherOf<
frame_system::EnsureRootWithSuccess<Self::AccountId, CandidateRank>,
EitherOf<
MapSuccess<AmbassadorOrigin, Replace<CandidateRank>>,
MapSuccess<SeniorAmbassadorOrigin, Replace<AmbassadorRank>>,
>,
>;
type DemoteOrigin = EitherOf<
frame_system::EnsureRootWithSuccess<Self::AccountId, SeniorAmbassadorRank>,
MapSuccess<SeniorAmbassadorOrigin, Replace<AmbassadorRank>>,
>;
type Polls = AmbassadorReferenda;
type MinRankOfClass = sp_runtime::traits::Identity;
type VoteWeight = pallet_ranked_collective::Geometric;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
// Copyright (C) 2022 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.

#[frame_support::pallet]
pub mod pallet {
use super::super::types::Cid;

use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;

/// The current storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(0);

#[pallet::pallet]
#[pallet::generate_store(pub (super) trait Store)]
#[pallet::storage_version(STORAGE_VERSION)]
pub struct Pallet<T>(PhantomData<T>);

/// The module configuration trait.
#[pallet::config]
pub trait Config: frame_system::Config {
/// The overarching event type.
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;

/// A member of the Ambassador Program.
type MemberOrigin: EnsureOrigin<Self::RuntimeOrigin>;

/// Ambassador plurality voice.
type AmbassadorOrigin: EnsureOrigin<Self::RuntimeOrigin>;

/// The maximum number of announcements.
#[pallet::constant]
type MaxAnnouncementsCount: Get<u32>;
}

#[derive(PartialEq, Eq, Clone, MaxEncodedLen, Encode, Decode, TypeInfo, RuntimeDebug)]
#[pallet::origin]
pub enum Origin {
/// Candidates plurality voice given via referendum.
Candidate,
/// Ambassador plurality voice given via referendum.
Ambassador,
/// SeniorAmbassador plurality voice given via referendum.
SeniorAmbassador,
}

#[pallet::error]
pub enum Error<T> {
/// The announcement is not found.
MissingAnnouncement,
/// Number of announcements exceeds `MaxAnnouncementsCount`.
TooManyAnnouncements,
}

#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// A new charter has been set.
NewCharterSet { cid: Cid },
/// A new announcement has been proposed.
AnnouncementAnnounced { cid: Cid },
/// An on-chain announcement has been removed.
AnnouncementRemoved { cid: Cid },
}

/// The Ambassador Program's charter.
#[pallet::storage]
#[pallet::getter(fn charter)]
pub type Charter<T: Config> = StorageValue<_, Cid, OptionQuery>;

/// The Ambassador Program's announcements.
#[pallet::storage]
#[pallet::getter(fn announcements)]
pub type Announcements<T: Config> =
StorageValue<_, BoundedVec<Cid, T::MaxAnnouncementsCount>, ValueQuery>;

#[pallet::call]
impl<T: Config> Pallet<T> {
/// Set the Ambassador Program's charter.
#[pallet::call_index(0)]
#[pallet::weight(0)] // TODO
pub fn set_charter(origin: OriginFor<T>, cid: Cid) -> DispatchResult {
T::AmbassadorOrigin::ensure_origin(origin)?;

Charter::<T>::put(&cid);

Self::deposit_event(Event::<T>::NewCharterSet { cid });
Ok(())
}

/// Publish an announcement.
#[pallet::call_index(1)]
#[pallet::weight(0)] // TODO
pub fn announce(origin: OriginFor<T>, cid: Cid) -> DispatchResult {
T::MemberOrigin::ensure_origin(origin)?;

let mut announcements = <Announcements<T>>::get();
announcements
.try_push(cid.clone())
.map_err(|_| Error::<T>::TooManyAnnouncements)?;
<Announcements<T>>::put(announcements);

Self::deposit_event(Event::<T>::AnnouncementAnnounced { cid });
Ok(())
}

/// Remove an announcement.
#[pallet::call_index(2)]
#[pallet::weight(0)] // TODO
pub fn remove_announcement(origin: OriginFor<T>, cid: Cid) -> DispatchResult {
T::MemberOrigin::ensure_origin(origin)?;

let mut announcements = <Announcements<T>>::get();
let pos =
announcements.binary_search(&cid).ok().ok_or(Error::<T>::MissingAnnouncement)?;
announcements.remove(pos);
<Announcements<T>>::put(announcements);

Self::deposit_event(Event::<T>::AnnouncementRemoved { cid });
Ok(())
}
}

pub struct Ambassador;
// todo P2 check impl
impl<O: Into<Result<Origin, O>> + From<Origin>> EnsureOrigin<O> for Ambassador {
type Success = ();
fn try_origin(o: O) -> Result<Self::Success, O> {
o.into().and_then(|o| match o {
Origin::Ambassador => Ok(()),
r => Err(O::from(r)),
})
}
}

pub struct SeniorAmbassador;
impl<O: Into<Result<Origin, O>> + From<Origin>> EnsureOrigin<O> for SeniorAmbassador {
type Success = ();
fn try_origin(o: O) -> Result<Self::Success, O> {
o.into().and_then(|o| match o {
Origin::SeniorAmbassador => Ok(()),
r => Err(O::from(r)),
})
}
}
}
Loading