Turn storage items into parameters (#2883)

* balances: Turn storage items into parameters.

* contract: Turn storage items into parameters.

* council: Turn storage items into parameters.

* finality-tracker: Turn storage items into parameters.

* treasury: Turn storage items into parameters.

* democracy: Fix tests.

* example: Fix tests.

* executive: Fix tests.

* staking: Fix tests.

* Update runtime.

* Update template-node.

* Update runtime version.

* Fix executor tests.

* Fix node cli tests.

* Address grumbles.

* Add removed default values to docs.

* Make gas price a storage item.

* Set associated consts must be callable outside of build.

* Fix not enough gas to pay for transfer fee.

* Fix build.

* Emit metadata.

* Fix build.

* Add default values for all parameter types.

* Fix build.

* Fix build.

* Fix build.

* Fix build.
This commit is contained in:
David Craven
2019-07-02 12:52:58 +02:00
committed by GitHub
parent b2622b611e
commit cf036f685e
23 changed files with 943 additions and 597 deletions
+116 -23
View File
@@ -26,7 +26,8 @@ use support::{
};
use substrate_primitives::u32_trait::{_1, _2, _3, _4};
use node_primitives::{
AccountId, AccountIndex, Balance, BlockNumber, Hash, Index, Signature, AuraId
AccountId, AccountIndex, AuraId, Balance, BlockNumber, Hash, Index,
Moment, Signature,
};
use grandpa::fg_primitives::{self, ScheduledChange};
use client::{
@@ -39,18 +40,20 @@ use runtime_primitives::traits::{
BlakeTwo256, Block as BlockT, DigestFor, NumberFor, StaticLookup, Convert,
};
use version::RuntimeVersion;
use council::{motions as council_motions};
use council::{motions as council_motions, VoteIndex};
#[cfg(feature = "std")]
use council::seats as council_seats;
#[cfg(any(feature = "std", test))]
use version::NativeVersion;
use substrate_primitives::OpaqueMetadata;
use grandpa::{AuthorityId as GrandpaId, AuthorityWeight as GrandpaWeight};
use finality_tracker::{DEFAULT_REPORT_LATENCY, DEFAULT_WINDOW_SIZE};
#[cfg(any(feature = "std", test))]
pub use runtime_primitives::BuildStorage;
pub use timestamp::Call as TimestampCall;
pub use balances::Call as BalancesCall;
pub use contracts::Gas;
pub use runtime_primitives::{Permill, Perbill, impl_opaque_keys};
pub use support::StorageValue;
pub use staking::StakerStatus;
@@ -60,8 +63,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("node"),
impl_name: create_runtime_str!("substrate-node"),
authoring_version: 10,
spec_version: 100,
impl_version: 100,
spec_version: 101,
impl_version: 101,
apis: RUNTIME_API_VERSIONS,
};
@@ -74,6 +77,10 @@ pub fn native_version() -> NativeVersion {
}
}
pub const MILLICENTS: Balance = 1_000_000_000;
pub const CENTS: Balance = 1_000 * MILLICENTS; // assume this is worth about a cent.
pub const DOLLARS: Balance = 100 * CENTS;
type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;
pub struct Author;
@@ -91,19 +98,10 @@ pub type DealWithFees = SplitTwoWays<
_1, Author, // 1 part (20%) goes to the block author.
>;
pub struct CurrencyToVoteHandler;
impl CurrencyToVoteHandler {
fn factor() -> u128 { (Balances::total_issuance() / u64::max_value() as u128).max(1) }
}
impl Convert<u128, u64> for CurrencyToVoteHandler {
fn convert(x: u128) -> u64 { (x / Self::factor()) as u64 }
}
impl Convert<u128, u128> for CurrencyToVoteHandler {
fn convert(x: u128) -> u128 { x * Self::factor() }
}
pub const SECS_PER_BLOCK: Moment = 6;
pub const MINUTES: Moment = 60 / SECS_PER_BLOCK;
pub const HOURS: Moment = MINUTES * 60;
pub const DAYS: Moment = HOURS * 24;
impl system::Trait for Runtime {
type Origin = Origin;
@@ -129,6 +127,14 @@ impl indices::Trait for Runtime {
type Event = Event;
}
parameter_types! {
pub const ExistentialDeposit: Balance = 1 * DOLLARS;
pub const TransferFee: Balance = 1 * CENTS;
pub const CreationFee: Balance = 1 * CENTS;
pub const TransactionBaseFee: Balance = 1 * CENTS;
pub const TransactionByteFee: Balance = 10 * MILLICENTS;
}
impl balances::Trait for Runtime {
type Balance = Balance;
type OnFreeBalanceZero = ((Staking, Contracts), Session);
@@ -137,10 +143,15 @@ impl balances::Trait for Runtime {
type TransactionPayment = DealWithFees;
type DustRemoval = ();
type TransferPayment = ();
type ExistentialDeposit = ExistentialDeposit;
type TransferFee = TransferFee;
type CreationFee = CreationFee;
type TransactionBaseFee = TransactionBaseFee;
type TransactionByteFee = TransactionByteFee;
}
impl timestamp::Trait for Runtime {
type Moment = u64;
type Moment = Moment;
type OnTimestampSet = Aura;
}
@@ -185,6 +196,20 @@ parameter_types! {
pub const BondingDuration: staking::EraIndex = 24 * 28;
}
pub struct CurrencyToVoteHandler;
impl CurrencyToVoteHandler {
fn factor() -> u128 { (Balances::total_issuance() / u64::max_value() as u128).max(1) }
}
impl Convert<u128, u64> for CurrencyToVoteHandler {
fn convert(x: u128) -> u64 { (x / Self::factor()) as u64 }
}
impl Convert<u128, u128> for CurrencyToVoteHandler {
fn convert(x: u128) -> u128 { x * Self::factor() }
}
impl staking::Trait for Runtime {
type Currency = Balances;
type CurrencyToVote = CurrencyToVoteHandler;
@@ -196,14 +221,11 @@ impl staking::Trait for Runtime {
type BondingDuration = BondingDuration;
}
const MINUTES: BlockNumber = 6;
const BUCKS: Balance = 1_000_000_000_000;
parameter_types! {
pub const LaunchPeriod: BlockNumber = 28 * 24 * 60 * MINUTES;
pub const VotingPeriod: BlockNumber = 28 * 24 * 60 * MINUTES;
pub const EmergencyVotingPeriod: BlockNumber = 3 * 24 * 60 * MINUTES;
pub const MinimumDeposit: Balance = 100 * BUCKS;
pub const MinimumDeposit: Balance = 100 * DOLLARS;
pub const EnactmentPeriod: BlockNumber = 30 * 24 * 60 * MINUTES;
pub const CooloffPeriod: BlockNumber = 30 * 24 * 60 * MINUTES;
}
@@ -225,6 +247,18 @@ impl democracy::Trait for Runtime {
type CooloffPeriod = CooloffPeriod;
}
parameter_types! {
pub const CandidacyBond: Balance = 10 * DOLLARS;
pub const VotingBond: Balance = 1 * DOLLARS;
pub const VotingFee: Balance = 2 * DOLLARS;
pub const PresentSlashPerVoter: Balance = 1 * CENTS;
pub const CarryCount: u32 = 6;
// one additional vote should go by before an inactive voter can be reaped.
pub const InactiveGracePeriod: VoteIndex = 1;
pub const CouncilVotingPeriod: BlockNumber = 2 * DAYS;
pub const DecayRatio: u32 = 0;
}
impl council::Trait for Runtime {
type Event = Event;
type BadPresentation = ();
@@ -232,6 +266,14 @@ impl council::Trait for Runtime {
type BadVoterIndex = ();
type LoserCandidate = ();
type OnMembersChanged = CouncilMotions;
type CandidacyBond = CandidacyBond;
type VotingBond = VotingBond;
type VotingFee = VotingFee;
type PresentSlashPerVoter = PresentSlashPerVoter;
type CarryCount = CarryCount;
type InactiveGracePeriod = InactiveGracePeriod;
type CouncilVotingPeriod = CouncilVotingPeriod;
type DecayRatio = DecayRatio;
}
impl council::motions::Trait for Runtime {
@@ -240,6 +282,13 @@ impl council::motions::Trait for Runtime {
type Event = Event;
}
parameter_types! {
pub const ProposalBond: Permill = Permill::from_percent(5);
pub const ProposalBondMinimum: Balance = 1 * DOLLARS;
pub const SpendPeriod: BlockNumber = 1 * DAYS;
pub const Burn: Permill = Permill::from_percent(50);
}
impl treasury::Trait for Runtime {
type Currency = Balances;
type ApproveOrigin = council_motions::EnsureMembers<_4, AccountId>;
@@ -247,6 +296,28 @@ impl treasury::Trait for Runtime {
type Event = Event;
type MintedForSpending = ();
type ProposalRejection = ();
type ProposalBond = ProposalBond;
type ProposalBondMinimum = ProposalBondMinimum;
type SpendPeriod = SpendPeriod;
type Burn = Burn;
}
parameter_types! {
pub const SignedClaimHandicap: BlockNumber = 2;
pub const TombstoneDeposit: Balance = 16;
pub const StorageSizeOffset: u32 = 8;
pub const RentByteFee: Balance = 4;
pub const RentDepositOffset: Balance = 1000;
pub const SurchargeReward: Balance = 150;
pub const ContractTransferFee: Balance = 1 * CENTS;
pub const ContractCreationFee: Balance = 1 * CENTS;
pub const ContractTransactionBaseFee: Balance = 1 * CENTS;
pub const ContractTransactionByteFee: Balance = 10 * MILLICENTS;
pub const ContractFee: Balance = 1 * CENTS;
pub const CallBaseFee: Gas = 1000;
pub const CreateBaseFee: Gas = 1000;
pub const MaxDepth: u32 = 1024;
pub const BlockGasLimit: Gas = 10_000_000;
}
impl contracts::Trait for Runtime {
@@ -257,6 +328,21 @@ impl contracts::Trait for Runtime {
type ComputeDispatchFee = contracts::DefaultDispatchFeeComputor<Runtime>;
type TrieIdGenerator = contracts::TrieIdFromParentCounter<Runtime>;
type GasPayment = ();
type SignedClaimHandicap = SignedClaimHandicap;
type TombstoneDeposit = TombstoneDeposit;
type StorageSizeOffset = StorageSizeOffset;
type RentByteFee = RentByteFee;
type RentDepositOffset = RentDepositOffset;
type SurchargeReward = SurchargeReward;
type TransferFee = ContractTransferFee;
type CreationFee = ContractCreationFee;
type TransactionBaseFee = ContractTransactionBaseFee;
type TransactionByteFee = ContractTransactionByteFee;
type ContractFee = ContractFee;
type CallBaseFee = CallBaseFee;
type CreateBaseFee = CreateBaseFee;
type MaxDepth = MaxDepth;
type BlockGasLimit = BlockGasLimit;
}
impl sudo::Trait for Runtime {
@@ -268,8 +354,15 @@ impl grandpa::Trait for Runtime {
type Event = Event;
}
parameter_types! {
pub const WindowSize: BlockNumber = DEFAULT_WINDOW_SIZE.into();
pub const ReportLatency: BlockNumber = DEFAULT_REPORT_LATENCY.into();
}
impl finality_tracker::Trait for Runtime {
type OnFinalizationStalled = Grandpa;
type WindowSize = WindowSize;
type ReportLatency = ReportLatency;
}
construct_runtime!(
@@ -292,7 +385,7 @@ construct_runtime!(
CouncilSeats: council_seats::{Config<T>},
FinalityTracker: finality_tracker::{Module, Call, Inherent},
Grandpa: grandpa::{Module, Call, Storage, Config, Event},
Treasury: treasury,
Treasury: treasury::{Module, Call, Storage, Event<T>},
Contracts: contracts,
Sudo: sudo,
}