Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pallet-alliance #24

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 27 additions & 4 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 @@ -64,6 +64,7 @@ members = [
"client/transaction-pool",
"client/transaction-pool/api",
"client/utils",
"frame/alliance",
"frame/assets",
"frame/atomic-swap",
"frame/aura",
Expand Down
6 changes: 5 additions & 1 deletion bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,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 @@ -171,14 +172,16 @@ std = [
"log/std",
"frame-try-runtime/std",
"sp-npos-elections/std",
"sp-io/std"
"sp-io/std",
"pallet-alliance/std",
]
runtime-benchmarks = [
"frame-benchmarking",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-election-provider-multi-phase/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 @@ -217,6 +220,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
94 changes: 92 additions & 2 deletions bin/node/runtime/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,17 @@

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

use crate::{Authorship, Balances, NegativeImbalance};
use frame_support::traits::{Currency, OnUnbalanced};
use node_primitives::{AccountId, Hash};
use sp_std::prelude::*;

use frame_support::{
dispatch::{DispatchError, DispatchResultWithPostInfo},
traits::{Currency, OnUnbalanced},
weights::Weight,
};
use pallet_alliance::{IdentityVerifier, ProposalIndex, ProposalProvider};

use crate::{AllianceMotion, Authorship, Balances, Call, NegativeImbalance};

pub struct Author;
impl OnUnbalanced<NegativeImbalance> for Author {
Expand All @@ -27,6 +36,87 @@ impl OnUnbalanced<NegativeImbalance> for Author {
}
}

pub struct AllianceIdentityVerifier;
impl IdentityVerifier<AccountId> for AllianceIdentityVerifier {
#[cfg(not(feature = "runtime-benchmarks"))]
fn has_identity(who: &AccountId, fields: u64) -> bool {
crate::Identity::has_identity(who, fields)
}

#[cfg(feature = "runtime-benchmarks")]
fn has_identity(_who: &AccountId, _fields: u64) -> bool {
true
}

#[cfg(not(feature = "runtime-benchmarks"))]
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()
.filter(|(_, j)| Judgement::KnownGood == *j || Judgement::Reasonable == *j)
.count() > 0
} else {
false
}
}

#[cfg(feature = "runtime-benchmarks")]
fn has_good_judgement(_who: &AccountId) -> bool {
true
}

#[cfg(not(feature = "runtime-benchmarks"))]
fn super_account_id(who: &AccountId) -> Option<AccountId> {
crate::Identity::super_of(who).map(|parent| parent.0)
}

#[cfg(feature = "runtime-benchmarks")]
fn super_account_id(_who: &AccountId) -> Option<AccountId> {
None
}
}

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
56 changes: 55 additions & 1 deletion bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub use sp_runtime::BuildStorage;

/// Implementations of some helper traits passed into runtime modules as associated types.
pub mod impls;
use impls::Author;
use impls::{AllianceIdentityVerifier, AllianceProposalProvider, Author};

/// Constant values used within the runtime.
pub mod constants;
Expand Down Expand Up @@ -1241,6 +1241,56 @@ impl pallet_transaction_storage::Config for Runtime {
type WeightInfo = pallet_transaction_storage::weights::SubstrateWeight<Runtime>;
}

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 MaxBlacklistCount: u32 = 100;
pub const MaxWebsiteUrlLength: u32 = 255;
}

impl pallet_alliance::Config<AllianceCollective> for Runtime {
type Event = Event;
type Proposal = Call;
type SuperMajorityOrigin = EnsureOneOf<
AccountId,
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionMoreThan<_2, _3, AccountId, AllianceCollective>,
>;
type Currency = Balances;
type Slashed = Treasury;
type InitializeMembers = AllianceMotion;
type MembershipChanged = AllianceMotion;
type IdentityVerifier = AllianceIdentityVerifier;
type ProposalProvider = AllianceProposalProvider;
type MaxProposals = AllianceMaxProposals;
type MaxFounders = MaxFounders;
type MaxFellows = MaxFellows;
type MaxAllies = MaxAllies;
type MaxBlacklistCount = MaxBlacklistCount;
type MaxWebsiteUrlLength = MaxWebsiteUrlLength;
type CandidateDeposit = CandidateDeposit;
type WeightInfo = pallet_alliance::weights::SubstrateWeight<Runtime>;
}

construct_runtime!(
pub enum Runtime where
Block = Block,
Expand Down Expand Up @@ -1288,6 +1338,8 @@ construct_runtime!(
Uniques: pallet_uniques::{Pallet, Call, Storage, Event<T>},
TransactionStorage: pallet_transaction_storage::{Pallet, Call, Storage, Inherent, Config<T>, Event<T>},
BagsList: pallet_bags_list::{Pallet, Call, Storage, Event<T>},
AllianceMotion: pallet_collective::<Instance3>::{Pallet, Storage, Origin<T>, Event<T>},
Alliance: pallet_alliance::<Instance3>::{Pallet, Call, Storage, Event<T>},
}
);

Expand Down Expand Up @@ -1620,6 +1672,7 @@ impl_runtime_apis! {

let mut list = Vec::<BenchmarkList>::new();

list_benchmark!(list, extra, pallet_alliance, Alliance);
list_benchmark!(list, extra, pallet_assets, Assets);
list_benchmark!(list, extra, pallet_babe, Babe);
list_benchmark!(list, extra, pallet_bags_list, BagsList);
Expand Down Expand Up @@ -1694,6 +1747,7 @@ impl_runtime_apis! {
let mut batches = Vec::<BenchmarkBatch>::new();
let params = (&config, &whitelist);

add_benchmark!(params, batches, pallet_alliance, Alliance);
add_benchmark!(params, batches, pallet_assets, Assets);
add_benchmark!(params, batches, pallet_babe, Babe);
add_benchmark!(params, batches, pallet_balances, Balances);
Expand Down
67 changes: 67 additions & 0 deletions frame/alliance/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
[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 = "Collective system: Members of a set of account IDs can make their collective feelings known through dispatched calls from one of two specialized origins."
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.9", default-features = false, optional = true }
log = { version = "0.4.14", default-features = false }

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

sp-std = { version = "4.0.0-dev", default-features = false, path = "../../primitives/std" }
sp-core = { version = "4.0.0-dev", default-features = false, path = "../../primitives/core" }
sp-io = { version = "4.0.0-dev", default-features = false, path = "../../primitives/io" }
sp-runtime = { version = "4.0.0-dev", 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-collective = { version = "4.0.0-dev", path = "../collective", default-features = false, optional = true }
pallet-identity = { version = "4.0.0-dev", path = "../identity", default-features = false, optional = true }

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

[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",
]
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