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

pallet alliance #11112

Merged
merged 81 commits into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from 70 commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
94cf161
Add pallet-alliance
koushiro Sep 17, 2021
f12601d
Update multihash/cid and format
koushiro Sep 17, 2021
0d93dd6
Remove useless deps
koushiro Sep 18, 2021
3bfc260
Add pallet-alliance into node runtime
koushiro Sep 18, 2021
445649e
Fix has_identity
koushiro Sep 22, 2021
0d2eaee
Add TooMantBlacklist Error
koushiro Oct 4, 2021
b69980d
Add TooLongWebsiteUrlLength Error
koushiro Oct 4, 2021
9cab715
Add remove_announcement
koushiro Oct 4, 2021
9241f08
Derive pallet_identity::Config and Fix test/benchmarking
koushiro Oct 5, 2021
0a71502
Add part weight for call of pallet-alliance
koushiro Oct 5, 2021
d7aeddf
Remove pallet_identity Config trait
koushiro Oct 9, 2021
b07520e
Fix propose arguments
koushiro Oct 11, 2021
9774055
Some nits
koushiro Oct 11, 2021
0013afd
cargo fmt
koushiro Oct 11, 2021
6b2c8af
Fix benchmarking of add_blacklist/remove_blacklist
koushiro Oct 11, 2021
1d2bc71
Some nits
koushiro Oct 11, 2021
e7f0cd3
Add benchmarking for init_members
koushiro Oct 11, 2021
181738b
Add benchmarking for propose/vote/veto
koushiro Oct 11, 2021
a359aea
Fix benchmarking
koushiro Oct 11, 2021
d1bb18d
Remove some useless
koushiro Oct 11, 2021
a2f986f
fix some compile issue
xlc Mar 12, 2022
e37664e
more fix
xlc Mar 12, 2022
a04c5b8
all checks
xlc Mar 12, 2022
fde2562
refactor
xlc Mar 12, 2022
1757810
refactor event
xlc Mar 12, 2022
03a6be5
refactor
xlc Mar 12, 2022
3e4e7f4
cleanup
xlc Mar 12, 2022
7333148
cleanup
xlc Mar 12, 2022
06b42a8
Merge branch 'master' into polkadot-alliance-review
xlc Mar 24, 2022
c49b633
fix benchmarking
xlc Mar 24, 2022
bbd087b
fix warning
xlc Mar 24, 2022
062bad8
fmt
xlc Mar 24, 2022
8ab53a8
fix benchmarks
xlc Mar 25, 2022
86b4fcf
Merge remote-tracking branch 'origin/master' into polkadot-alliance-r…
xlc Mar 31, 2022
c16c2a7
with storage info
xlc Mar 31, 2022
58ca07d
fmt
xlc Mar 31, 2022
4013d84
add new config
xlc Apr 2, 2022
a0c0971
fix benchmarks
xlc Apr 2, 2022
31f846b
fix
xlc Apr 3, 2022
616646b
fmt
xlc Apr 3, 2022
02aaf4e
Apply suggestions from code review
xlc Apr 4, 2022
82f84d1
improvements
xlc Apr 8, 2022
551e830
fix
xlc Apr 8, 2022
451396e
update docs
joepetrowski Apr 9, 2022
814d520
rename events, errors, and functions
joepetrowski Apr 9, 2022
f90df9e
make kicking events clearer
joepetrowski Apr 9, 2022
d93f872
Merge pull request #2 from joepetrowski/polkadot-alliance-review
xlc Apr 10, 2022
35d50b9
fix
xlc Apr 10, 2022
e024c73
fix tests
xlc Apr 10, 2022
1d0eef4
fix tests
xlc Apr 10, 2022
4f2a0bd
fix runtime
xlc Apr 10, 2022
3c8b878
fix build
xlc Apr 10, 2022
0f12ed4
remove unneeded change
xlc Apr 10, 2022
b20b72a
Merge remote-tracking branch 'origin/master' into polkadot-alliance-r…
xlc Apr 13, 2022
5b6b336
remove Candidate role from Alliance
joepetrowski Apr 30, 2022
a97b897
merge master
joepetrowski Apr 30, 2022
0970b78
fmt grumbles
joepetrowski Apr 30, 2022
d292548
update lock
joepetrowski Apr 30, 2022
6da40be
update recursion limit
joepetrowski Apr 30, 2022
dc6400c
benchmarks
joepetrowski Apr 30, 2022
428638a
convert-try
joepetrowski Apr 30, 2022
c029b0c
benchmark assertions
joepetrowski Apr 30, 2022
5ed70ae
fmt ,
joepetrowski Apr 30, 2022
d7766b0
merge master
joepetrowski May 19, 2022
50726b3
cargo lock
joepetrowski May 20, 2022
60d9434
Update frame/alliance/src/benchmarking.rs
joepetrowski May 20, 2022
2809717
Apply suggestions from code review
joepetrowski May 20, 2022
f270ada
add docs to public interfaces
joepetrowski May 20, 2022
955854a
Apply suggestions from code review
joepetrowski May 23, 2022
944a612
fix build (node)
joepetrowski May 23, 2022
7c063c8
review
joepetrowski May 23, 2022
5feb2d1
Merge remote-tracking branch 'origin' into polkadot-alliance-review
joepetrowski May 25, 2022
a576428
Merge remote-tracking branch 'origin' into polkadot-alliance-review
joepetrowski May 30, 2022
fb8dd06
merge master
joepetrowski Jun 8, 2022
0e39490
use EitherOfDiverse
joepetrowski Jun 8, 2022
d89078d
update cargo toml
joepetrowski Jun 9, 2022
8338125
make all dispatch class Normal
joepetrowski Jun 10, 2022
fdf4dc9
change blacklist to unscrupulous
joepetrowski Jun 10, 2022
0c10bcd
formatting
joepetrowski Jun 10, 2022
3ee24a8
fmt oops
joepetrowski Jun 10, 2022
78b63c1
rename benchmarking unscrupulous account creator
joepetrowski Jun 10, 2022
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
23 changes: 23 additions & 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ members = [
"client/transaction-pool",
"client/transaction-pool/api",
"client/utils",
"frame/alliance",
"frame/assets",
"frame/atomic-swap",
"frame/aura",
Expand Down
2 changes: 2 additions & 0 deletions bin/node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ pub fn testnet_genesis(
gilt: Default::default(),
transaction_storage: Default::default(),
transaction_payment: Default::default(),
alliance: Default::default(),
alliance_motion: Default::default(),
nomination_pools: Default::default(),
}
}
Expand Down
4 changes: 4 additions & 0 deletions bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ frame-system-benchmarking = { version = "4.0.0-dev", default-features = false, p
frame-election-provider-support = { version = "4.0.0-dev", default-features = false, path = "../../../frame/election-provider-support" }
frame-system-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, path = "../../../frame/system/rpc/runtime-api/" }
frame-try-runtime = { version = "0.10.0-dev", default-features = false, path = "../../../frame/try-runtime", optional = true }
pallet-alliance = { version = "4.0.0-dev", default-features = false, path = "../../../frame/alliance" }
pallet-assets = { version = "4.0.0-dev", default-features = false, path = "../../../frame/assets" }
pallet-authority-discovery = { version = "4.0.0-dev", default-features = false, path = "../../../frame/authority-discovery" }
pallet-authorship = { version = "4.0.0-dev", default-features = false, path = "../../../frame/authorship" }
Expand Down Expand Up @@ -185,12 +186,14 @@ std = [
"frame-try-runtime/std",
"sp-io/std",
"pallet-child-bounties/std",
"pallet-alliance/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"pallet-alliance/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"pallet-babe/runtime-benchmarks",
"pallet-bags-list/runtime-benchmarks",
Expand Down Expand Up @@ -240,6 +243,7 @@ try-runtime = [
"frame-executive/try-runtime",
"frame-try-runtime",
"frame-system/try-runtime",
"pallet-alliance/try-runtime",
"pallet-assets/try-runtime",
"pallet-authority-discovery/try-runtime",
"pallet-authorship/try-runtime",
Expand Down
77 changes: 73 additions & 4 deletions bin/node/runtime/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@

//! Some configurable implementations as associated type for the substrate runtime.

use crate::{AccountId, Assets, Authorship, Balances, NegativeImbalance, Runtime};
use frame_support::traits::{
fungibles::{Balanced, CreditOf},
Currency, OnUnbalanced,
use crate::{
AccountId, AllianceMotion, Assets, Authorship, Balances, Call, Hash, NegativeImbalance, Runtime,
};
use frame_support::{
pallet_prelude::*,
traits::{
fungibles::{Balanced, CreditOf},
Currency, OnUnbalanced,
},
};
use pallet_alliance::{IdentityVerifier, ProposalIndex, ProposalProvider};
use pallet_asset_tx_payment::HandleCredit;
use sp_std::prelude::*;

pub struct Author;
impl OnUnbalanced<NegativeImbalance> for Author {
Expand All @@ -45,6 +52,68 @@ impl HandleCredit<AccountId, Assets> for CreditToBlockAuthor {
}
}

pub struct AllianceIdentityVerifier;
impl IdentityVerifier<AccountId> for AllianceIdentityVerifier {
fn has_identity(who: &AccountId, fields: u64) -> bool {
crate::Identity::has_identity(who, fields)
}

fn has_good_judgement(who: &AccountId) -> bool {
use pallet_identity::Judgement;
if let Some(judgements) =
crate::Identity::identity(who).map(|registration| registration.judgements)
{
judgements
.iter()
.any(|(_, j)| matches!(j, Judgement::KnownGood | Judgement::Reasonable))
} else {
false
}
}

fn super_account_id(who: &AccountId) -> Option<AccountId> {
crate::Identity::super_of(who).map(|parent| parent.0)
}
}

pub struct AllianceProposalProvider;
impl ProposalProvider<AccountId, Hash, Call> for AllianceProposalProvider {
fn propose_proposal(
who: AccountId,
threshold: u32,
proposal: Box<Call>,
length_bound: u32,
) -> Result<(u32, u32), DispatchError> {
AllianceMotion::do_propose_proposed(who, threshold, proposal, length_bound)
}

fn vote_proposal(
who: AccountId,
proposal: Hash,
index: ProposalIndex,
approve: bool,
) -> Result<bool, DispatchError> {
AllianceMotion::do_vote(who, proposal, index, approve)
}

fn veto_proposal(proposal_hash: Hash) -> u32 {
AllianceMotion::do_disapprove_proposal(proposal_hash)
}

fn close_proposal(
proposal_hash: Hash,
proposal_index: ProposalIndex,
proposal_weight_bound: Weight,
length_bound: u32,
) -> DispatchResultWithPostInfo {
AllianceMotion::do_close(proposal_hash, proposal_index, proposal_weight_bound, length_bound)
}

fn proposal_of(proposal_hash: Hash) -> Option<Call> {
AllianceMotion::proposal_of(proposal_hash)
}
}

#[cfg(test)]
mod multiplier_tests {
use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment};
Expand Down
72 changes: 68 additions & 4 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
//! The Substrate runtime. This can be compiled with `#[no_std]`, ready for Wasm.

#![cfg_attr(not(feature = "std"), no_std)]
// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.
#![recursion_limit = "256"]
// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 512.
#![recursion_limit = "512"]

use codec::{Decode, Encode, MaxEncodedLen};
use frame_election_provider_support::{
Expand Down Expand Up @@ -90,7 +90,9 @@ pub use sp_runtime::BuildStorage;

/// Implementations of some helper traits passed into runtime modules as associated types.
pub mod impls;
use impls::{Author, CreditToBlockAuthor};
#[cfg(not(feature = "runtime-benchmarks"))]
use impls::AllianceIdentityVerifier;
use impls::{AllianceProposalProvider, Author, CreditToBlockAuthor};

/// Constant values used within the runtime.
pub mod constants;
Expand Down Expand Up @@ -1473,6 +1475,67 @@ impl pallet_state_trie_migration::Config for Runtime {
type WeightInfo = ();
}

parameter_types! {
pub const AllianceMotionDuration: BlockNumber = 5 * DAYS;
pub const AllianceMaxProposals: u32 = 100;
pub const AllianceMaxMembers: u32 = 100;
}

type AllianceCollective = pallet_collective::Instance3;
impl pallet_collective::Config<AllianceCollective> for Runtime {
type Origin = Origin;
type Proposal = Call;
type Event = Event;
type MotionDuration = AllianceMotionDuration;
type MaxProposals = AllianceMaxProposals;
type MaxMembers = AllianceMaxMembers;
type DefaultVote = pallet_collective::PrimeDefaultVote;
type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
}

parameter_types! {
pub const MaxFounders: u32 = 10;
pub const MaxFellows: u32 = AllianceMaxMembers::get() - MaxFounders::get();
pub const MaxAllies: u32 = 100;
pub const AllyDeposit: Balance = 10 * DOLLARS;
}

impl pallet_alliance::Config for Runtime {
type Event = Event;
type Proposal = Call;
type AdminOrigin = EnsureOneOf<
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionMoreThan<AccountId, AllianceCollective, 2, 3>,
>;
type MembershipManager = EnsureOneOf<
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionMoreThan<AccountId, AllianceCollective, 2, 3>,
>;
type AnnouncementOrigin = EnsureOneOf<
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionMoreThan<AccountId, AllianceCollective, 2, 3>,
>;
type Currency = Balances;
type Slashed = Treasury;
type InitializeMembers = AllianceMotion;
type MembershipChanged = AllianceMotion;
#[cfg(not(feature = "runtime-benchmarks"))]
type IdentityVerifier = AllianceIdentityVerifier;
#[cfg(feature = "runtime-benchmarks")]
type IdentityVerifier = ();
type ProposalProvider = AllianceProposalProvider;
type MaxProposals = AllianceMaxProposals;
type MaxFounders = MaxFounders;
type MaxFellows = MaxFellows;
type MaxAllies = MaxAllies;
type MaxBlacklistCount = ConstU32<100>;
type MaxWebsiteUrlLength = ConstU32<255>;
type MaxAnnouncementsCount = ConstU32<100>;
type MaxMembersCount = AllianceMaxMembers;
type AllyDeposit = AllyDeposit;
type WeightInfo = pallet_alliance::weights::SubstrateWeight<Runtime>;
}

construct_runtime!(
pub enum Runtime where
Block = Block,
Expand Down Expand Up @@ -1530,6 +1593,8 @@ construct_runtime!(
Remark: pallet_remark,
ConvictionVoting: pallet_conviction_voting,
Whitelist: pallet_whitelist,
AllianceMotion: pallet_collective::<Instance3>,
Alliance: pallet_alliance,
NominationPools: pallet_nomination_pools,
}
);
Expand Down Expand Up @@ -2013,7 +2078,6 @@ impl_runtime_apis! {
let mut batches = Vec::<BenchmarkBatch>::new();
let params = (&config, &whitelist);
add_benchmarks!(params, batches);

Ok(batches)
}
}
Expand Down
2 changes: 2 additions & 0 deletions bin/node/testing/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ pub fn config_endowed(code: Option<&[u8]>, extra_endowed: Vec<AccountId>) -> Gen
gilt: Default::default(),
transaction_storage: Default::default(),
transaction_payment: Default::default(),
alliance: Default::default(),
alliance_motion: Default::default(),
nomination_pools: Default::default(),
}
}
68 changes: 68 additions & 0 deletions frame/alliance/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
[package]
name = "pallet-alliance"
version = "4.0.0-dev"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
license = "Apache-2.0"
homepage = "https://substrate.dev"
repository = "https://github.com/paritytech/substrate/"
description = "The Alliance Pallet provides a DAO to form an industry group."
readme = "README.md"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
hex = { version = "0.4", default-features = false, features = ["alloc"], optional = true }
sha2 = { version = "0.10.1", default-features = false, optional = true }
log = { version = "0.4.14", default-features = false }

codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
scale-info = { version = "2.0.1", default-features = false, features = ["derive"] }

sp-std = { version = "4.0.0", default-features = false, path = "../../primitives/std" }
sp-core = { version = "6.0.0", default-features = false, path = "../../primitives/core" }
sp-io = { version = "6.0.0", default-features = false, path = "../../primitives/io" }
sp-runtime = { version = "6.0.0", default-features = false, path = "../../primitives/runtime" }

frame-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../benchmarking", optional = true }
frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" }
frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" }

pallet-identity = { version = "4.0.0-dev", path = "../identity", default-features = false }
pallet-collective = { version = "4.0.0-dev", path = "../collective", default-features = false, optional = true }

[dev-dependencies]
hex-literal = "0.3.1"
sha2 = "0.10.1"
pallet-balances = { version = "4.0.0-dev", path = "../balances" }
pallet-collective = { version = "4.0.0-dev", path = "../collective" }

[features]
default = ["std"]
std = [
"log/std",
"codec/std",
"scale-info/std",
"sp-std/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"frame-support/std",
"frame-system/std",
"pallet-identity/std",
]
runtime-benchmarks = [
"hex",
"sha2",
"frame-benchmarking",
"sp-runtime/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-collective/runtime-benchmarks",
"pallet-identity/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
]
Loading