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

Develop #167

Merged
merged 12 commits into from
Dec 16, 2019
2 changes: 2 additions & 0 deletions Cargo.lock

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

6 changes: 6 additions & 0 deletions node/runtime/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ pub mod time {
pub const MINUTES: BlockNumber = 60 / (SECS_PER_BLOCK as BlockNumber);
pub const HOURS: BlockNumber = MINUTES * 60;
pub const DAYS: BlockNumber = HOURS * 24;

pub const SESSION_DURATION: BlockNumber = EPOCH_DURATION_IN_SLOTS as _;
// Develop
pub const SESSION_PER_ERA: sr_staking_primitives::SessionIndex = 1;
// Production
// pub const SESSION_PER_ERA: sr_staking_primitives::SessionIndex = 6;
}

// CRITICAL NOTE: The system module maintains two constants: a _maximum_ block weight and a _ratio_
Expand Down
106 changes: 60 additions & 46 deletions node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,27 +137,18 @@ impl indices::Trait for Runtime {
}

parameter_types! {
pub const ExistentialDeposit: Balance = 1 * COIN;
pub const TransferFee: Balance = 1 * MICRO;
pub const CreationFee: Balance = 1 * MICRO;
}
impl balances::Trait for Runtime {
type Balance = Balance;
type OnFreeBalanceZero = ((Staking, Contracts), Session);
type OnNewAccount = Indices;
type TransferPayment = ();
type DustRemoval = ();
type Event = Event;
type ExistentialDeposit = ExistentialDeposit;
type TransferFee = TransferFee;
type CreationFee = CreationFee;
}

parameter_types! {
pub const TransactionBaseFee: Balance = 1 * MICRO;
pub const TransactionByteFee: Balance = 10 * MICRO;
// Develop
pub const TransactionBaseFee: Balance = 0;
pub const TransactionByteFee: Balance = 0;
// setting this to zero will disable the weight fee.
pub const WeightFeeCoefficient: Balance = 1_000;
pub const WeightFeeCoefficient: Balance = 0;

// Production
// pub const TransactionBaseFee: Balance = 1 * MICRO;
// pub const TransactionByteFee: Balance = 10 * MICRO;
// // setting this to zero will disable the weight fee.
// pub const WeightFeeCoefficient: Balance = 1 * MICRO;

// for a sane configuration, this should always be less than `AvailableBlockRatio`.
pub const TargetBlockFullness: Perbill = Perbill::from_percent(25);
}
Expand Down Expand Up @@ -246,7 +237,7 @@ impl offences::Trait for Runtime {

type SubmitTransaction = TransactionSubmitter<ImOnlineId, Runtime, UncheckedExtrinsic>;
parameter_types! {
pub const SessionDuration: BlockNumber = EPOCH_DURATION_IN_SLOTS as _;
pub const SessionDuration: BlockNumber = SESSION_DURATION;
}
impl im_online::Trait for Runtime {
type AuthorityId = ImOnlineId;
Expand All @@ -272,15 +263,27 @@ impl finality_tracker::Trait for Runtime {
}

parameter_types! {
pub const ContractTransferFee: Balance = 1 * MICRO;
pub const ContractCreationFee: Balance = 1 * MICRO;
pub const ContractTransactionBaseFee: Balance = 1 * MICRO;
pub const ContractTransactionByteFee: Balance = 10 * MICRO;
pub const ContractFee: Balance = 1 * MICRO;
pub const TombstoneDeposit: Balance = 1 * COIN;
pub const RentByteFee: Balance = 1 * COIN;
pub const RentDepositOffset: Balance = 1000 * COIN;
pub const SurchargeReward: Balance = 150 * COIN;
// Develop
pub const ContractTransferFee: Balance = 0;
pub const ContractCreationFee: Balance = 0;
pub const ContractTransactionBaseFee: Balance = 0;
pub const ContractTransactionByteFee: Balance = 0;
pub const ContractFee: Balance = 0;
pub const TombstoneDeposit: Balance = 0;
pub const RentByteFee: Balance = 0;
pub const RentDepositOffset: Balance = 0;
pub const SurchargeReward: Balance = 0;

// Production
// pub const ContractTransferFee: Balance = 1 * MICRO;
// pub const ContractCreationFee: Balance = 1 * MICRO;
// pub const ContractTransactionBaseFee: Balance = 1 * MICRO;
// pub const ContractTransactionByteFee: Balance = 10 * MICRO;
// pub const ContractFee: Balance = 1 * MICRO;
// pub const TombstoneDeposit: Balance = 1 * COIN;
// pub const RentByteFee: Balance = 1 * COIN;
// pub const RentDepositOffset: Balance = 1000 * COIN;
// pub const SurchargeReward: Balance = 150 * COIN;
}
impl contracts::Trait for Runtime {
type Currency = Balances;
Expand Down Expand Up @@ -341,20 +344,30 @@ impl system::offchain::CreateTransaction<Runtime, UncheckedExtrinsic> for Runtim
}
}

impl kton::Trait for Runtime {
parameter_types! {
pub const ExistentialDeposit: Balance = 1 * COIN;
pub const TransferFee: Balance = 1 * MICRO;
pub const CreationFee: Balance = 1 * MICRO;
}
impl balances::Trait for Runtime {
type Balance = Balance;
type OnFreeBalanceZero = ((Staking, Contracts), Session);
type OnNewAccount = Indices;
type TransferPayment = ();
type DustRemoval = ();
type Event = Event;
type ExistentialDeposit = ExistentialDeposit;
type TransferFee = TransferFee;
type CreationFee = CreationFee;
}
impl kton::Trait for Runtime {
type Event = Event;
type OnMinted = ();
type OnRemoval = ();
}

parameter_types! {
// Develop
pub const SessionsPerEra: sr_staking_primitives::SessionIndex = 1;
// Production
// pub const SessionsPerEra: sr_staking_primitives::SessionIndex = 6;
// about 14 days = 14 * 24 * 60 * 60 * 1000
pub const BondingDuration: Moment = 1_209_600_000;
pub const SessionsPerEra: sr_staking_primitives::SessionIndex = SESSION_PER_ERA;
pub const BondingDuration: Moment = SESSION_PER_ERA as Moment * SESSION_DURATION as Moment * MILLISECS_PER_BLOCK;
pub const BondingDurationInEra: staking::EraIndex = SESSION_PER_ERA * SESSION_DURATION;
// decimal 9
pub const HardCap: Balance = 10_000_000_000 * COIN;
// date in Los Angeles*: 11/19/2019, 2:33:20 AM
Expand All @@ -364,19 +377,20 @@ parameter_types! {
pub const GenesisTime: Moment = 1_574_156_000_000;
}
impl staking::Trait for Runtime {
type Ring = Balances;
type Kton = Kton;
type Time = Timestamp;
type CurrencyToVote = CurrencyToVoteHandler;
type RingRewardRemainder = ();
type Event = Event;
type RingReward = ();
type KtonReward = ();
type RingSlash = ();
type KtonSlash = ();
type SessionsPerEra = SessionsPerEra;
type BondingDuration = BondingDuration;
type BondingDurationInEra = BondingDurationInEra;
type SessionInterface = Self;
type Ring = Balances;
type RingRewardRemainder = ();
type RingSlash = ();
type RingReward = ();
type Kton = Kton;
type KtonSlash = ();
type KtonReward = ();

type Cap = HardCap;
type GenesisTime = GenesisTime;
Expand Down
26 changes: 14 additions & 12 deletions srml/balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(all(feature = "std", test))]
mod mock;
#[cfg(all(feature = "std", test))]
mod tests;

use codec::{Codec, Decode, Encode};
use rstd::{cmp, fmt::Debug, mem, prelude::*, result};
use sr_primitives::{
Expand All @@ -37,14 +42,11 @@ use support::{
};
use system::{ensure_root, ensure_signed, IsDeadAccount, OnNewAccount};

#[cfg(all(feature = "std", test))]
mod mock;
#[cfg(all(feature = "std", test))]
mod tests;

use darwinia_support::{BalanceLock, LockIdentifier, LockableCurrency, WithdrawLock, WithdrawReason, WithdrawReasons};
use imbalances::{NegativeImbalance, PositiveImbalance};

pub type Balance = u128;

pub trait Subtrait<I: Instance = DefaultInstance>: system::Trait + timestamp::Trait {
/// The balance of an account.
type Balance: Parameter
Expand Down Expand Up @@ -387,7 +389,7 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
///
/// NOTE: LOW-LEVEL: This will not attempt to maintain total issuance. It is expected that
/// the caller will do this.
fn set_reserved_balance(who: &T::AccountId, balance: T::Balance) -> UpdateBalanceOutcome {
pub fn set_reserved_balance(who: &T::AccountId, balance: T::Balance) -> UpdateBalanceOutcome {
if balance < T::ExistentialDeposit::get() {
<ReservedBalance<T, I>>::insert(who, balance);
Self::on_reserved_too_low(who);
Expand All @@ -406,7 +408,7 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
///
/// NOTE: LOW-LEVEL: This will not attempt to maintain total issuance. It is expected that
/// the caller will do this.
fn set_free_balance(who: &T::AccountId, balance: T::Balance) -> UpdateBalanceOutcome {
pub fn set_free_balance(who: &T::AccountId, balance: T::Balance) -> UpdateBalanceOutcome {
// Commented out for now - but consider it instructive.
// assert!(!Self::total_balance(who).is_zero());
// assert!(Self::free_balance(who) > T::ExistentialDeposit::get());
Expand All @@ -423,15 +425,15 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
/// Register a new account (with existential balance).
///
/// This just calls appropriate hooks. It doesn't (necessarily) make any state changes.
fn new_account(who: &T::AccountId, balance: T::Balance) {
pub fn new_account(who: &T::AccountId, balance: T::Balance) {
T::OnNewAccount::on_new_account(&who);
Self::deposit_event(RawEvent::NewAccount(who.clone(), balance.clone()));
}

/// Unregister an account.
///
/// This just removes the nonce and leaves an event.
fn reap_account(who: &T::AccountId) {
pub fn reap_account(who: &T::AccountId) {
<system::AccountNonce<T>>::remove(who);
Self::deposit_event(RawEvent::ReapedAccount(who.clone()));
}
Expand All @@ -440,7 +442,7 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
/// free side and the account completely if its reserved size is already dead.
///
/// Will maintain total issuance.
fn on_free_too_low(who: &T::AccountId) {
pub fn on_free_too_low(who: &T::AccountId) {
let dust = <FreeBalance<T, I>>::take(who);
<Locks<T, I>>::remove(who);

Expand All @@ -460,7 +462,7 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
/// reserved side and the account completely if its free size is already dead.
///
/// Will maintain total issuance.
fn on_reserved_too_low(who: &T::AccountId) {
pub fn on_reserved_too_low(who: &T::AccountId) {
let dust = <ReservedBalance<T, I>>::take(who);

// underflow should never happen, but it if does, there's nothing to be done here.
Expand All @@ -476,7 +478,7 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {

// wrapping these imbalances in a private module is necessary to ensure absolute privacy
// of the inner member.
mod imbalances {
pub mod imbalances {
use super::{result, DefaultInstance, Imbalance, Instance, Saturating, StorageValue, Subtrait, Trait, Zero};
use rstd::mem;

Expand Down
Loading