Skip to content

Commit

Permalink
Protonet runtime 102
Browse files Browse the repository at this point in the history
The new runtime includes the following changes:

Staking pallet: v3.0.0 -> v3.1.0
    - Added chill_other extrinsic that allows removing validators that no longer meet the minimum validator bond, when it gets increased.
    - Fix the logic of validate to allow existing validators to modify their commission without needing to stop first.

XXNetwork pallet: v0.1.0 -> v0.1.1
    - Fix custody payout to always empty Custody and Reserve accounts at the end of the custody period. This prevents any funds sent to these accounts from getting stuck forever.
    - Fix TotalCustody underflow when paying out extra custody funds. If an account has extra funds, the TotalCustody value might reach 0 before desired.

Protonet runtime: v0.1.0 -> v0.1.2
    - Increase custody period from 45 days to 3 years. This allows continued testing for the team multiplier in protonet.
    - Bump spec version to 102.
  • Loading branch information
bernardo-xxnet committed Oct 8, 2021
1 parent eefb4d2 commit 6d77731
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 38 deletions.
20 changes: 10 additions & 10 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xxnetwork-cli"
version = "0.1.1"
version = "0.1.2"
authors = ["xxlabs <[email protected]>"]
description = "Substrate based, xxnetwork blockchain node implementation in Rust."
build = "build.rs"
Expand Down Expand Up @@ -80,12 +80,12 @@ pallet-transaction-payment = { git = "https://github.com/xx-labs/substrate", bra
frame-support = { git = "https://github.com/xx-labs/substrate", branch = "xx-protonet", default-features = false }
pallet-im-online = { git = "https://github.com/xx-labs/substrate", branch = "xx-protonet", default-features = false }
pallet-authority-discovery = { git = "https://github.com/xx-labs/substrate", branch = "xx-protonet" }
pallet-staking = { version = "3.0.0", path = "../staking" }
pallet-staking = { version = "3.1.0", path = "../staking" }
pallet-grandpa = { git = "https://github.com/xx-labs/substrate", branch = "xx-protonet" }

# node-specific dependencies
xxnetwork-runtime = { version = "0.1.0", path = "../runtime/xxnetwork" }
protonet-runtime = { version = "0.1.0", path = "../runtime/protonet" }
protonet-runtime = { version = "0.1.2", path = "../runtime/protonet" }
phoenixx-runtime = { version = "0.1.0", path = "../runtime/phoenixx" }
node-rpc = { version = "0.1.0", path = "../rpc" }
node-primitives = { version = "0.1.0", path = "../primitives" }
Expand Down
2 changes: 1 addition & 1 deletion executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ targets = ["x86_64-unknown-linux-gnu"]
codec = { package = "parity-scale-codec", version = "2.0.0" }
node-primitives = { version = "0.1.0", path = "../primitives" }
xxnetwork-runtime = { version = "0.1.0", path = "../runtime/xxnetwork" }
protonet-runtime = { version = "0.1.0", path = "../runtime/protonet" }
protonet-runtime = { version = "0.1.2", path = "../runtime/protonet" }
phoenixx-runtime = { version = "0.1.0", path = "../runtime/phoenixx" }
sc-executor = { git = "https://github.com/xx-labs/substrate", branch = "xx-protonet" }
sp-core = { git = "https://github.com/xx-labs/substrate", branch = "xx-protonet" }
Expand Down
2 changes: 1 addition & 1 deletion runtime/phoenixx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pallet-proxy = { git = "https://github.com/xx-labs/substrate", branch = "xx-prot
pallet-randomness-collective-flip = { git = "https://github.com/xx-labs/substrate", branch = "xx-protonet", default-features = false }
pallet-session = { git = "https://github.com/xx-labs/substrate", branch = "xx-protonet", features = ["historical"], default-features = false }
pallet-session-benchmarking = { git = "https://github.com/xx-labs/substrate", branch = "xx-protonet", default-features = false, optional = true }
pallet-staking = { version = "3.0.0", default-features = false, path = "../../staking" }
pallet-staking = { version = "3.1.0", default-features = false, path = "../../staking" }
pallet-staking-reward-curve = { git = "https://github.com/xx-labs/substrate", branch = "xx-protonet", default-features = false }
pallet-scheduler = { git = "https://github.com/xx-labs/substrate", branch = "xx-protonet", default-features = false }
pallet-timestamp = { git = "https://github.com/xx-labs/substrate", branch = "xx-protonet", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions runtime/protonet/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "protonet-runtime"
version = "0.1.0"
version = "0.1.2"
authors = ["xxlabs <[email protected]>"]
edition = "2018"
build = "build.rs"
Expand Down Expand Up @@ -67,7 +67,7 @@ pallet-proxy = { git = "https://github.com/xx-labs/substrate", branch = "xx-prot
pallet-randomness-collective-flip = { git = "https://github.com/xx-labs/substrate", branch = "xx-protonet", default-features = false }
pallet-session = { git = "https://github.com/xx-labs/substrate", branch = "xx-protonet", features = ["historical"], default-features = false }
pallet-session-benchmarking = { git = "https://github.com/xx-labs/substrate", branch = "xx-protonet", default-features = false, optional = true }
pallet-staking = { version = "3.0.0", default-features = false, path = "../../staking" }
pallet-staking = { version = "3.1.0", default-features = false, path = "../../staking" }
pallet-staking-reward-curve = { git = "https://github.com/xx-labs/substrate", branch = "xx-protonet", default-features = false }
pallet-scheduler = { git = "https://github.com/xx-labs/substrate", branch = "xx-protonet", default-features = false }
pallet-timestamp = { git = "https://github.com/xx-labs/substrate", branch = "xx-protonet", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions runtime/protonet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// and set impl_version to 0. If only runtime
// implementation changes and behavior does not, then leave spec_version as
// is and increment impl_version.
spec_version: 100,
spec_version: 102,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down Expand Up @@ -461,7 +461,7 @@ parameter_types! {
pub const RewardsPoolId: PalletId = PalletId(*b"xx/rwrds");
pub const EraDuration: BlockNumber = ERA_DURATION_IN_SESSIONS * EPOCH_DURATION_IN_BLOCKS;
pub const PayoutFrequency: BlockNumber = 3 * DAYS;
pub const CustodyDuration: BlockNumber = 45 * DAYS;
pub const CustodyDuration: BlockNumber = 3 * YEARS;
pub const GovernanceCustodyDuration: BlockNumber = 45 * DAYS;
pub const GovernanceProxy: ProxyType = ProxyType::Governance;
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/xxnetwork/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pallet-proxy = { git = "https://github.com/xx-labs/substrate", branch = "xx-prot
pallet-randomness-collective-flip = { git = "https://github.com/xx-labs/substrate", branch = "xx-protonet", default-features = false }
pallet-session = { git = "https://github.com/xx-labs/substrate", branch = "xx-protonet", features = ["historical"], default-features = false }
pallet-session-benchmarking = { git = "https://github.com/xx-labs/substrate", branch = "xx-protonet", default-features = false, optional = true }
pallet-staking = { version = "3.0.0", default-features = false, path = "../../staking" }
pallet-staking = { version = "3.1.0", default-features = false, path = "../../staking" }
pallet-staking-reward-curve = { git = "https://github.com/xx-labs/substrate", branch = "xx-protonet", default-features = false }
pallet-scheduler = { git = "https://github.com/xx-labs/substrate", branch = "xx-protonet", default-features = false }
pallet-timestamp = { git = "https://github.com/xx-labs/substrate", branch = "xx-protonet", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion staking/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pallet-staking"
version = "3.0.0"
version = "3.1.0"
authors = ["xxlabs <[email protected]>"]
edition = "2018"
homepage = "https://xx.network"
Expand Down
46 changes: 44 additions & 2 deletions staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,8 @@ decl_error! {
ValidatorInsufficientBond,
/// CMIX ID already exists
ValidatorCmixIdNotUnique,
/// The validator has enough bond and thus cannot be chilled forcefully by an external user.
CannotChillOther,
}
}

Expand Down Expand Up @@ -1484,9 +1486,13 @@ decl_module! {
ensure!(ledger.active >= <ValidatorMinBond<T>>::get(),
Error::<T>::ValidatorInsufficientBond);
// Ensure validator cmix id is unique
// unless validator exists and cmix id remains the same
let existing_prefs = <Validators<T>>::get(stash);
let cmix_root = prefs.cmix_root.clone();
if <CmixIds<T>>::contains_key(&cmix_root) {
Err(Error::<T>::ValidatorCmixIdNotUnique)?
if existing_prefs.cmix_root != cmix_root {
if <CmixIds<T>>::contains_key(&cmix_root) {
Err(Error::<T>::ValidatorCmixIdNotUnique)?
}
}
<Nominators<T>>::remove(stash);
// Remove existing prefs to ensure cmix ID is cleared
Expand Down Expand Up @@ -1928,6 +1934,42 @@ decl_module! {

Ok(())
}

/// Declare a `controller` to stop participating as a validator.
///
/// Effects will be felt at the beginning of the next era.
///
/// The dispatch origin for this call must be _Signed_, but can be called by anyone.
///
/// If the caller is the same as the controller being targeted, then no further checks are
/// enforced, and this function behaves just like `chill`.
///
/// If the caller is different than the controller being targeted, the stash must be a
/// validator, and the active bond must be lower than the minimum validator bond.
///
/// This can be helpful if the minimum validator bond is increased, and we need to remove
/// validators who don't satisfy the new bond.
#[weight = T::WeightInfo::chill_other()]
pub fn chill_other(origin, controller: T::AccountId) -> DispatchResult {
// Anyone can call this function.
let caller = ensure_signed(origin)?;
let ledger = Self::ledger(&controller).ok_or(Error::<T>::NotController)?;
let stash = ledger.stash;

// In order for one user to chill another user, the stash must be a
// validator, and the active bond must be lower than the minimum validator bond.
//
// Otherwise, if caller is the same as the controller, this is just like `chill`.
if caller != controller {
if !Validators::<T>::contains_key(&stash) {
Err(Error::<T>::CannotChillOther)?
}
ensure!(ledger.active < <ValidatorMinBond<T>>::get(), Error::<T>::CannotChillOther);
}

Self::chill_stash(&stash);
Ok(())
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions staking/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pub trait WeightInfo {
fn new_era(v: u32, n: u32, ) -> Weight;
fn get_npos_voters(v: u32, n: u32, s: u32, ) -> Weight;
fn get_npos_targets(v: u32, ) -> Weight;
fn chill_other() -> Weight;
}

/// Weights for pallet_staking using the Substrate node and recommended hardware.
Expand Down Expand Up @@ -251,6 +252,11 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(v as Weight)))
}
fn chill_other() -> Weight {
(58_222_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
}

// For backwards compatibility and tests
Expand Down Expand Up @@ -431,4 +437,9 @@ impl WeightInfo for () {
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
.saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(v as Weight)))
}
fn chill_other() -> Weight {
(58_222_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
}
2 changes: 1 addition & 1 deletion testing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ sp-io = { git = "https://github.com/xx-labs/substrate", branch = "xx-protonet" }
frame-support = { git = "https://github.com/xx-labs/substrate", branch = "xx-protonet" }
pallet-session = { git = "https://github.com/xx-labs/substrate", branch = "xx-protonet" }
sp-runtime = { git = "https://github.com/xx-labs/substrate", branch = "xx-protonet" }
pallet-staking = { version = "3.0.0", path = "../staking" }
pallet-staking = { version = "3.1.0", path = "../staking" }
sc-executor = { git = "https://github.com/xx-labs/substrate", branch = "xx-protonet", features = ["wasmtime"] }
sp-consensus = { git = "https://github.com/xx-labs/substrate", branch = "xx-protonet" }
frame-system = { git = "https://github.com/xx-labs/substrate", branch = "xx-protonet" }
Expand Down
4 changes: 2 additions & 2 deletions xxnetwork/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xxnetwork"
version = "0.1.0"
version = "0.1.1"
authors = ["Bernardo Cardoso <[email protected]>"]
edition = "2018"

Expand All @@ -18,7 +18,7 @@ sp-arithmetic = { git = "https://github.com/xx-labs/substrate", branch = "xx-pro
frame-support = { git = "https://github.com/xx-labs/substrate", branch = "xx-protonet", default-features = false }
frame-system = { git = "https://github.com/xx-labs/substrate", branch = "xx-protonet", default-features = false }

pallet-staking = { version = "3.0.0", default-features = false, path = "../staking" }
pallet-staking = { version = "3.1.0", default-features = false, path = "../staking" }
pallet-staking-reward-fn = { git = "https://github.com/xx-labs/substrate", branch = "xx-protonet", default-features = false }
pallet-proxy = { git = "https://github.com/xx-labs/substrate", branch = "xx-protonet", default-features = false }

Expand Down
25 changes: 13 additions & 12 deletions xxnetwork/src/custody.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,13 @@ impl<AccountId, Balance> CustodyInfo<AccountId, Balance> where
{
/// Return true if self is fully vested
fn is_vested(&self) -> bool {
self.allocation == self.vested
self.allocation <= self.vested
}

/// Increase vested amount in self
fn increase_vested(&mut self, amount: Balance) {
self.vested += amount;
}

/// Get the remaining payout
fn remaining_payout(&self) -> Balance {
self.allocation - self.vested
}
}

/// Implement Custody sub module functions
Expand Down Expand Up @@ -234,7 +229,7 @@ impl<T: Config> Module<T> {
// 3.2. Remove any proxies on the custody account
Self::refund_team_custody_proxy(who.clone(), info.clone())?;
// 3.3. Payout remaining amount
Self::do_payout(who.clone(), info.remaining_payout(), info, false)?;
Self::do_payout(who.clone(), Zero::zero(), info, false)?;
// 3.4. Emmit custody done event
Self::deposit_event(RawEvent::CustodyDone(who));
return Ok(())
Expand Down Expand Up @@ -299,17 +294,23 @@ impl<T: Config> Module<T> {
// limit transfers down to existential deposit until end of the custody period
let reserve = info.reserve.clone();
let reserve_transferable_balance =
T::Inspect::reducible_balance(&reserve, keep_alive);
T::Inspect::reducible_balance(&reserve, keep_alive.clone());
// T::Currency and T::Inspect are both implemented by Balances pallet, so the
// balance type is the same. However, explicit conversion is needed here.
let reserve_balance = <BalanceOf<T>>::try_from(
reserve_transferable_balance.saturated_into::<u128>()
).ok().unwrap_or(Zero::zero());

// 3. Calculate amounts to withdraw from custody and reserve
let withdraw_custody = amount.min(custody_balance);
let withdraw_reserve = amount - withdraw_custody;
let withdraw_reserve = withdraw_reserve.min(reserve_balance);
// If custody period is done, transfer full amount from both accounts
// in order to not leave any inaccessible funds around
let (withdraw_custody, withdraw_reserve) = if keep_alive {
let from_custody = amount.min(custody_balance);
let from_reserve = amount - from_custody;
(from_custody, from_reserve.min(reserve_balance))
} else {
(custody_balance, reserve_balance)
};
let withdraw = withdraw_custody + withdraw_reserve;

// 4. Make transfer from custody, if possible
Expand All @@ -324,7 +325,7 @@ impl<T: Config> Module<T> {
// Emmit TeamPayoutCustody event
Self::deposit_event(RawEvent::PayoutFromCustody(who.clone(), withdraw_custody));
// Update total amount under custody
<TotalCustody<T>>::mutate(|n| *n -= withdraw_custody);
<TotalCustody<T>>::mutate(|n| *n = n.clone().saturating_sub(withdraw_custody));
}

// 5. Make transfer from reserve, if possible
Expand Down

0 comments on commit 6d77731

Please sign in to comment.