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

Commit

Permalink
Companion for substrate/pull/6896 (#1610)
Browse files Browse the repository at this point in the history
* make polkadot work again,

* Fix build

* "Update Substrate"

Co-authored-by: parity-processbot <>
  • Loading branch information
kianenigma authored Oct 8, 2020
1 parent ba0d1a3 commit b6ea6dd
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 182 deletions.
268 changes: 134 additions & 134 deletions Cargo.lock

Large diffs are not rendered by default.

31 changes: 0 additions & 31 deletions runtime/common/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

//! Auxillary struct/enums for polkadot runtime.

use sp_runtime::traits::Convert;
use frame_support::traits::{OnUnbalanced, Imbalance, Currency};
use crate::NegativeImbalance;

Expand All @@ -41,33 +40,3 @@ where
<frame_system::Module<R>>::deposit_event(pallet_balances::RawEvent::Deposit(author, numeric_amount));
}
}

/// Converter for currencies to votes.
pub struct CurrencyToVoteHandler<R>(sp_std::marker::PhantomData<R>);

impl<R> CurrencyToVoteHandler<R>
where
R: pallet_balances::Trait,
R::Balance: Into<u128>,
{
fn factor() -> u128 {
let issuance: u128 = <pallet_balances::Module<R>>::total_issuance().into();
(issuance / u64::max_value() as u128).max(1)
}
}

impl<R> Convert<u128, u64> for CurrencyToVoteHandler<R>
where
R: pallet_balances::Trait,
R::Balance: Into<u128>,
{
fn convert(x: u128) -> u64 { (x / Self::factor()) as u64 }
}

impl<R> Convert<u128, u128> for CurrencyToVoteHandler<R>
where
R: pallet_balances::Trait,
R::Balance: Into<u128>,
{
fn convert(x: u128) -> u128 { x * Self::factor() }
}
8 changes: 7 additions & 1 deletion runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub use pallet_timestamp::Call as TimestampCall;
pub use pallet_balances::Call as BalancesCall;

/// Implementations of some helper traits passed into runtime modules as associated types.
pub use impls::{CurrencyToVoteHandler, ToAuthor};
pub use impls::ToAuthor;

pub type NegativeImbalance<T> = <pallet_balances::Module<T> as Currency<<T as frame_system::Trait>::AccountId>>::NegativeImbalance;

Expand Down Expand Up @@ -89,6 +89,12 @@ pub type SlowAdjustingFeeUpdate<R> = TargetedFeeAdjustment<
MinimumMultiplier
>;

/// The type used for currency conversion.
///
/// This must only be used as long as the balance type is u128.
pub type CurrencyToVote = frame_support::traits::U128CurrencyToVote;
static_assertions::assert_eq_size!(primitives::v1::Balance, u128);

/// A placeholder since there is currently no provided session key handler for parachain validator
/// keys.
pub struct ParachainSessionKeyPlaceholder<T>(sp_std::marker::PhantomData<T>);
Expand Down
2 changes: 1 addition & 1 deletion runtime/common/src/paras_registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ mod tests {

impl pallet_staking::Trait for Test {
type RewardRemainder = ();
type CurrencyToVote = ();
type CurrencyToVote = frame_support::traits::SaturatingCurrencyToVote;
type Event = ();
type Currency = pallet_balances::Module<Test>;
type Slash = ();
Expand Down
8 changes: 4 additions & 4 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ use primitives::v1::{
PersistedValidationData, Signature, ValidationCode, ValidationData, ValidatorId, ValidatorIndex,
};
use runtime_common::{
claims, SlowAdjustingFeeUpdate,
impls::{CurrencyToVoteHandler, ToAuthor},
claims, SlowAdjustingFeeUpdate, CurrencyToVote,
impls::ToAuthor,
NegativeImbalance, BlockHashCount, MaximumBlockWeight, AvailableBlockRatio,
MaximumBlockLength, BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight,
MaximumExtrinsicWeight, ParachainSessionKeyPlaceholder,
Expand Down Expand Up @@ -346,7 +346,7 @@ type SlashCancelOrigin = EnsureOneOf<
impl pallet_staking::Trait for Runtime {
type Currency = Balances;
type UnixTime = Timestamp;
type CurrencyToVote = CurrencyToVoteHandler<Self>;
type CurrencyToVote = CurrencyToVote;
type RewardRemainder = Treasury;
type Event = Event;
type Slash = Treasury;
Expand Down Expand Up @@ -469,7 +469,7 @@ impl pallet_elections_phragmen::Trait for Runtime {
type Currency = Balances;
type ChangeMembers = Council;
type InitializeMembers = Council;
type CurrencyToVote = CurrencyToVoteHandler<Self>;
type CurrencyToVote = frame_support::traits::U128CurrencyToVote;
type CandidacyBond = CandidacyBond;
type VotingBond = VotingBond;
type LoserCandidate = Treasury;
Expand Down
8 changes: 4 additions & 4 deletions runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#![recursion_limit="256"]

use runtime_common::{
claims, SlowAdjustingFeeUpdate,
impls::{CurrencyToVoteHandler, ToAuthor},
claims, SlowAdjustingFeeUpdate, CurrencyToVote,
impls::ToAuthor,
NegativeImbalance, BlockHashCount, MaximumBlockWeight, AvailableBlockRatio,
MaximumBlockLength, BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight,
MaximumExtrinsicWeight, ParachainSessionKeyPlaceholder,
Expand Down Expand Up @@ -353,7 +353,7 @@ type SlashCancelOrigin = EnsureOneOf<
impl pallet_staking::Trait for Runtime {
type Currency = Balances;
type UnixTime = Timestamp;
type CurrencyToVote = CurrencyToVoteHandler<Self>;
type CurrencyToVote = CurrencyToVote;
type RewardRemainder = Treasury;
type Event = Event;
type Slash = Treasury;
Expand Down Expand Up @@ -516,7 +516,7 @@ impl pallet_elections_phragmen::Trait for Runtime {
type Currency = Balances;
type ChangeMembers = Council;
type InitializeMembers = Council;
type CurrencyToVote = CurrencyToVoteHandler<Self>;
type CurrencyToVote = frame_support::traits::U128CurrencyToVote;
type CandidacyBond = CandidacyBond;
type VotingBond = VotingBond;
type LoserCandidate = Treasury;
Expand Down
4 changes: 2 additions & 2 deletions runtime/rococo-v1/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use primitives::v1::{
};
use runtime_common::{
SlowAdjustingFeeUpdate,
impls::{CurrencyToVoteHandler, ToAuthor},
impls::ToAuthor,
BlockHashCount, MaximumBlockWeight, AvailableBlockRatio, MaximumBlockLength,
BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, MaximumExtrinsicWeight,
};
Expand Down Expand Up @@ -560,7 +560,7 @@ impl pallet_im_online::Trait for Runtime {
impl pallet_staking::Trait for Runtime {
type Currency = Balances;
type UnixTime = Timestamp;
type CurrencyToVote = CurrencyToVoteHandler<Self>;
type CurrencyToVote = frame_support::traits::U128CurrencyToVote;
type RewardRemainder = ();
type Event = Event;
type Slash = ();
Expand Down
4 changes: 2 additions & 2 deletions runtime/test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use primitives::v1::{
PersistedValidationData, Signature, ValidationCode, ValidationData, ValidatorId, ValidatorIndex,
};
use runtime_common::{
claims, SlowAdjustingFeeUpdate, impls::CurrencyToVoteHandler,
claims, SlowAdjustingFeeUpdate,
BlockHashCount, MaximumBlockWeight, AvailableBlockRatio,
MaximumBlockLength, BlockExecutionWeight, ExtrinsicBaseWeight, ParachainSessionKeyPlaceholder,
};
Expand Down Expand Up @@ -297,7 +297,7 @@ parameter_types! {
impl pallet_staking::Trait for Runtime {
type Currency = Balances;
type UnixTime = Timestamp;
type CurrencyToVote = CurrencyToVoteHandler<Self>;
type CurrencyToVote = frame_support::traits::U128CurrencyToVote;
type RewardRemainder = ();
type Event = Event;
type Slash = ();
Expand Down
6 changes: 3 additions & 3 deletions runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use primitives::v1::{
PersistedValidationData, Signature, ValidationCode, ValidationData, ValidatorId, ValidatorIndex,
};
use runtime_common::{
SlowAdjustingFeeUpdate,
impls::{CurrencyToVoteHandler, ToAuthor},
SlowAdjustingFeeUpdate, CurrencyToVote,
impls::ToAuthor,
BlockHashCount, MaximumBlockWeight, AvailableBlockRatio, MaximumBlockLength,
BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, MaximumExtrinsicWeight,
ParachainSessionKeyPlaceholder,
Expand Down Expand Up @@ -318,7 +318,7 @@ parameter_types! {
impl pallet_staking::Trait for Runtime {
type Currency = Balances;
type UnixTime = Timestamp;
type CurrencyToVote = CurrencyToVoteHandler<Self>;
type CurrencyToVote = CurrencyToVote;
type RewardRemainder = ();
type Event = Event;
type Slash = ();
Expand Down

0 comments on commit b6ea6dd

Please sign in to comment.