From 59decaf5752e1925ee1916e7a01445319ccc2082 Mon Sep 17 00:00:00 2001 From: "Demi M. Obenour" Date: Mon, 17 Aug 2020 13:49:35 -0400 Subject: [PATCH 01/11] Make `PayoutStakersCall` public --- src/frame/staking.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/frame/staking.rs b/src/frame/staking.rs index 8b155af4bb..63731d0035 100644 --- a/src/frame/staking.rs +++ b/src/frame/staking.rs @@ -309,7 +309,7 @@ pub struct NominateCall { /// Claim a payout. #[derive(PartialEq, Eq, Clone, Call, Encode, Decode, Debug)] -struct PayoutStakersCall<'a, T: Staking> { +pub struct PayoutStakersCall<'a, T: Staking> { pub validator_stash: &'a T::AccountId, pub era: EraIndex, } From b03b28b9f051b7779982ecf44ec7ea379dbcaa3e Mon Sep 17 00:00:00 2001 From: "Demi M. Obenour" Date: Fri, 28 Aug 2020 14:28:33 -0400 Subject: [PATCH 02/11] Add in all default features for debugging --- Cargo.toml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4ecfdf1b76..a7aa62f734 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,11 +26,11 @@ log = "0.4.11" thiserror = "1.0.20" futures = "0.3.5" jsonrpsee = { version = "0.1.0", features = ["ws"] } -num-traits = { version = "0.2.12", default-features = false } +num-traits = { version = "0.2.12" } serde = { version = "1.0.115", features = ["derive"] } serde_json = "1.0.57" url = "2.1.1" -codec = { package = "parity-scale-codec", version = "1.3.4", default-features = false, features = ["derive", "full"] } +codec = { package = "parity-scale-codec", version = "1.3.4", features = ["derive", "full"] } frame-metadata = { version = "11.0.0-rc6", package = "frame-metadata" } frame-support = { version = "2.0.0-rc6", package = "frame-support" } @@ -39,12 +39,12 @@ sp-version = { version = "2.0.0-rc6", package = "sp-version" } pallet-indices = { version = "2.0.0-rc6", package = "pallet-indices" } hex = "0.4.2" sp-std = "2.0.0-rc6" -application-crypto = { version = "2.0.0-rc6", package = "sp-application-crypto", default-features = false } -sp-finality-grandpa = { version = "2.0.0-rc6", default-features = false } +application-crypto = { version = "2.0.0-rc6", package = "sp-application-crypto" } +sp-finality-grandpa = { version = "2.0.0-rc6" } sp-consensus-babe = "0.8.0-rc6" -pallet-im-online = { version = "2.0.0-rc6", default-features = false } -sp-authority-discovery = { version = "2.0.0-rc6", default-features = false } -pallet-staking = { version = "2.0.0-rc6", default-features = false } +pallet-im-online = { version = "2.0.0-rc6" } +sp-authority-discovery = { version = "2.0.0-rc6" } +pallet-staking = { version = "2.0.0-rc6" } sp-rpc = { version = "2.0.0-rc6", package = "sp-rpc" } sp-core = { version = "2.0.0-rc6", package = "sp-core" } From 274412745b5619c3dfd4fe9ef699522aeca77b83 Mon Sep 17 00:00:00 2001 From: "Demi M. Obenour" Date: Mon, 31 Aug 2020 15:21:16 -0400 Subject: [PATCH 03/11] Chill support and update to latest Substrate --- Cargo.toml | 18 +++++++++++++++++ src/frame/staking.rs | 47 ++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a7aa62f734..fb9adb372e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,3 +63,21 @@ substrate-subxt-client = { version = "0.3.0", path = "client" } tempdir = "0.3.7" test-node = { path = "test-node" } wabt = "0.10.0" + +[patch.crates-io] +frame-metadata = { git = "https://github.com/paritytech/substrate" } +frame-support = { git = "https://github.com/paritytech/substrate" } +sp-runtime = { git = "https://github.com/paritytech/substrate" } +sp-version = { git = "https://github.com/paritytech/substrate" } +pallet-indices = { git = "https://github.com/paritytech/substrate" } +sp-rpc = { git = "https://github.com/paritytech/substrate" } +sp-core = { git = "https://github.com/paritytech/substrate" } +sc-rpc-api = { git = "https://github.com/paritytech/substrate" } +sp-transaction-pool = { git = "https://github.com/paritytech/substrate" } +sp-std = { git = "https://github.com/paritytech/substrate" } +application-crypto = { git = "https://github.com/paritytech/substrate", package = "sp-application-crypto", default-features = false } +sp-finality-grandpa = { git = "https://github.com/paritytech/substrate" } +sp-consensus-babe = { git = "https://github.com/paritytech/substrate" } +pallet-im-online = { git = "https://github.com/paritytech/substrate" } +sp-authority-discovery = { git = "https://github.com/paritytech/substrate" } +pallet-staking = { git = "https://github.com/paritytech/substrate" } diff --git a/src/frame/staking.rs b/src/frame/staking.rs index 8df4bc7491..25a4d4e7cf 100644 --- a/src/frame/staking.rs +++ b/src/frame/staking.rs @@ -76,7 +76,7 @@ pub struct ErasRewardPointsStore { #[derive(Clone, Encode, Decode, Debug, Call)] pub struct SetPayeeCall { /// The payee - pub payee: RewardDestination, + pub payee: RewardDestination, /// Marker for the runtime pub _runtime: PhantomData, } @@ -183,7 +183,7 @@ pub struct LedgerStore { /// Where the reward payment should be made. Keyed by stash. #[derive(Encode, Copy, Clone, Debug, Hash, PartialEq, Eq, Ord, PartialOrd, Store)] pub struct PayeeStore { - #[store(returns = RewardDestination)] + #[store(returns = RewardDestination)] /// Tٗhe stash account pub stash: T::AccountId, } @@ -257,6 +257,45 @@ pub struct ActiveEraStore { pub _runtime: PhantomData, } +/// Declare no desire to either validate or nominate. +/// +/// Effects will be felt at the beginning of the next era. +/// +/// The dispatch origin for this call must be _Signed_ by the controller, not the stash. +/// And, it can be only called when [`EraElectionStatus`] is `Closed`. +/// +/// # +/// - Independent of the arguments. Insignificant complexity. +/// - Contains one read. +/// - Writes are limited to the `origin` account key. +/// -------- +/// Base Weight: 16.53 µs +/// DB Weight: +/// - Read: EraElectionStatus, Ledger +/// - Write: Validators, Nominators +/// # +#[derive(Debug, Call, Encode)] +pub struct ChillCall { + /// Runtime marker + pub _runtime: PhantomData, +} + +impl Default for ChillCall { + fn default() -> Self { + Self { + _runtime: PhantomData, + } + } +} +impl Clone for ChillCall { + fn clone(&self) -> Self { + Self { + _runtime: self._runtime, + } + } +} +impl Copy for ChillCall {} + /// Declare the desire to validate for the origin controller. /// /// Effects will be felt at the beginning of the next era. @@ -276,9 +315,9 @@ pub struct ActiveEraStore { /// # #[derive(Clone, Debug, PartialEq, Call, Encode)] pub struct ValidateCall { - /// Runtime marker. + /// Runtime marker pub _runtime: PhantomData, - /// Validation preferences. + /// Validation preferences pub prefs: ValidatorPrefs, } From 3efe16f2ff4ad7924b33b5982448313a55e6bc79 Mon Sep 17 00:00:00 2001 From: "Demi M. Obenour" Date: Sun, 6 Sep 2020 18:12:25 -0400 Subject: [PATCH 04/11] If property fetch fails, use dummy values --- src/lib.rs | 2 +- src/rpc.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a4cc5949ac..49600f09b0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -174,7 +174,7 @@ impl ClientBuilder { rpc, genesis_hash: genesis_hash?, metadata: metadata?, - properties: properties?, + properties: properties.unwrap_or_else(|_| Default::default()), runtime_version: runtime_version?, _marker: PhantomData, page_size: self.page_size.unwrap_or(10), diff --git a/src/rpc.rs b/src/rpc.rs index a29582abd0..969a977782 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -96,7 +96,7 @@ impl From for BlockNumber { } } -#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] +#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq, Default)] #[serde(rename_all = "camelCase")] /// System properties for a Substrate-based runtime pub struct Properties { From d3865a613e1f0ab6317ea3b79614933b27de754c Mon Sep 17 00:00:00 2001 From: "Demi M. Obenour" Date: Fri, 11 Sep 2020 15:40:45 -0400 Subject: [PATCH 05/11] Fix tests --- Cargo.toml | 46 ++++++++++++++++---------------- src/frame/session.rs | 19 +++++++------ src/frame/staking.rs | 63 ++++++++++---------------------------------- src/lib.rs | 8 +++--- src/rpc.rs | 4 +-- 5 files changed, 54 insertions(+), 86 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 99e19dee93..aaca8753be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,11 +26,11 @@ log = "0.4.11" thiserror = "1.0.20" futures = "0.3.5" jsonrpsee = { version = "0.1.0", features = ["ws"] } -num-traits = { version = "0.2.12" } +num-traits = "0.2.12" serde = { version = "1.0.115", features = ["derive"] } serde_json = "1.0.57" url = "2.1.1" -codec = { package = "parity-scale-codec", version = "1.3.4", features = ["derive", "full"] } +codec = { package = "parity-scale-codec", version = "1.3.5", features = ["derive", "full"] } frame-metadata = { version = "11.0.0-rc6", package = "frame-metadata" } frame-support = { version = "2.0.0-rc6", package = "frame-support" } @@ -40,11 +40,11 @@ pallet-indices = { version = "2.0.0-rc6", package = "pallet-indices" } hex = "0.4.2" sp-std = "2.0.0-rc6" application-crypto = { version = "2.0.0-rc6", package = "sp-application-crypto" } -sp-finality-grandpa = { version = "2.0.0-rc6" } +sp-finality-grandpa = "2.0.0-rc6" sp-consensus-babe = "0.8.0-rc6" -pallet-im-online = { version = "2.0.0-rc6" } -sp-authority-discovery = { version = "2.0.0-rc6" } -pallet-staking = { version = "2.0.0-rc6" } +pallet-im-online = "2.0.0-rc6" +sp-authority-discovery = "2.0.0-rc6" +pallet-staking = "2.0.0-rc6" sp-rpc = { version = "2.0.0-rc6", package = "sp-rpc" } sp-core = { version = "2.0.0-rc6", package = "sp-core" } @@ -64,20 +64,20 @@ tempdir = "0.3.7" test-node = { path = "test-node" } wabt = "0.10.0" -[patch.crates-io] -frame-metadata = { git = "https://github.com/paritytech/substrate" } -frame-support = { git = "https://github.com/paritytech/substrate" } -sp-runtime = { git = "https://github.com/paritytech/substrate" } -sp-version = { git = "https://github.com/paritytech/substrate" } -pallet-indices = { git = "https://github.com/paritytech/substrate" } -sp-rpc = { git = "https://github.com/paritytech/substrate" } -sp-core = { git = "https://github.com/paritytech/substrate" } -sc-rpc-api = { git = "https://github.com/paritytech/substrate" } -sp-transaction-pool = { git = "https://github.com/paritytech/substrate" } -sp-std = { git = "https://github.com/paritytech/substrate" } -application-crypto = { git = "https://github.com/paritytech/substrate", package = "sp-application-crypto", default-features = false } -sp-finality-grandpa = { git = "https://github.com/paritytech/substrate" } -sp-consensus-babe = { git = "https://github.com/paritytech/substrate" } -pallet-im-online = { git = "https://github.com/paritytech/substrate" } -sp-authority-discovery = { git = "https://github.com/paritytech/substrate" } -pallet-staking = { git = "https://github.com/paritytech/substrate" } +# [patch.crates-io] +# frame-metadata = { git = "https://github.com/paritytech/substrate" } +# frame-support = { git = "https://github.com/paritytech/substrate" } +# sp-runtime = { git = "https://github.com/paritytech/substrate" } +# sp-version = { git = "https://github.com/paritytech/substrate" } +# pallet-indices = { git = "https://github.com/paritytech/substrate" } +# sp-rpc = { git = "https://github.com/paritytech/substrate" } +# sp-core = { git = "https://github.com/paritytech/substrate" } +# sc-rpc-api = { git = "https://github.com/paritytech/substrate" } +# sp-transaction-pool = { git = "https://github.com/paritytech/substrate" } +# sp-std = { git = "https://github.com/paritytech/substrate" } +# application-crypto = { git = "https://github.com/paritytech/substrate", package = "sp-application-crypto", default-features = false } +# sp-finality-grandpa = { git = "https://github.com/paritytech/substrate" } +# sp-consensus-babe = { git = "https://github.com/paritytech/substrate" } +# pallet-im-online = { git = "https://github.com/paritytech/substrate" } +# sp-authority-discovery = { git = "https://github.com/paritytech/substrate" } +# pallet-staking = { git = "https://github.com/paritytech/substrate" } diff --git a/src/frame/session.rs b/src/frame/session.rs index 4f7b90af6f..fca862a9a3 100644 --- a/src/frame/session.rs +++ b/src/frame/session.rs @@ -1,12 +1,12 @@ // Copyright 2019-2020 Parity Technologies (UK) Ltd. // This file is part of substrate-subxt. // -// subxt is free software: you can redistribute it and/or modify +// substrate-subxt is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // -// subxt is distributed in the hope that it will be useful, +// substrate-subxt is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. @@ -32,7 +32,9 @@ use std::{ }; use substrate_subxt_proc_macro::Store; -macro_rules! def { +/// Impls `Default::default` for some types that have a `_runtime` field of type +/// `PhantomData` as their only field. +macro_rules! default_impl { ($name:ident) => { impl Default for $name { fn default() -> Self { @@ -50,7 +52,7 @@ pub trait Session: System { /// The validator account identifier type for the runtime. type ValidatorId: Parameter + Debug + Ord + Default + Send + Sync + 'static; - /// The validator account identifier type for the runtime. + /// The session index identifier type for the runtime. type SessionIndex: Parameter + Debug + Ord + Default + Send + Sync + 'static; /// The keys. @@ -65,7 +67,7 @@ pub struct ValidatorsStore { pub _runtime: PhantomData, } -def!(ValidatorsStore); +default_impl!(ValidatorsStore); /// Current index of the session. #[derive(Encode, Store, Debug)] @@ -75,7 +77,7 @@ pub struct CurrentIndexStore { pub _runtime: PhantomData, } -def!(CurrentIndexStore); +default_impl!(CurrentIndexStore); /// True if the underlying economic identities or weighting behind the validators /// has changed in the queued validator set. @@ -86,9 +88,9 @@ pub struct QueuedChangedStore { pub _runtime: PhantomData, } -def!(QueuedChangedStore); +default_impl!(QueuedChangedStore); -/// The current set of validators. +/// Set the session keys for a validator. #[derive(Encode, Call, Debug)] pub struct SetKeysCall { /// The keys @@ -103,6 +105,7 @@ mod tests { use crate::tests::test_client; #[async_std::test] + #[ignore] async fn test_state_read_free_balance() { env_logger::try_init().ok(); let (client, _) = test_client().await; diff --git a/src/frame/staking.rs b/src/frame/staking.rs index 25a4d4e7cf..d4a6c7b469 100644 --- a/src/frame/staking.rs +++ b/src/frame/staking.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with substrate-subxt. If not, see . -//! Implements support for the frame_staking module. +//! Implements support for the pallet_staking module. use super::balances::{ Balances, @@ -51,7 +51,7 @@ pub use pallet_staking::{ /// /// This is keyed first by the era index to allow bulk deletion and then the stash account. /// -/// Is it removed after `HISTORY_DEPTH` eras. +/// It is removed after `HISTORY_DEPTH` eras. #[derive(Encode, Decode, Debug, Store)] pub struct ErasValidatorPrefsStore { #[store(returns = ValidatorPrefs)] @@ -76,7 +76,7 @@ pub struct ErasRewardPointsStore { #[derive(Clone, Encode, Decode, Debug, Call)] pub struct SetPayeeCall { /// The payee - pub payee: RewardDestination, + pub payee: RewardDestination, /// Marker for the runtime pub _runtime: PhantomData, } @@ -111,13 +111,13 @@ pub trait Staking: Balances { const MAX_NOMINATORS: usize; } -/// Just a Balance/BlockNumber tuple to encode when a chunk of funds will be unlocked. +/// A Balance/BlockNumber tuple to encode when a chunk of funds will be unlocked. #[derive(Clone, Encode, Decode, Debug)] pub struct UnlockChunk { /// Amount of funds to be unlocked. #[codec(compact)] pub value: T::Balance, - /// Era number at which point it'll be unlocked. + /// Era number at which point the funds will be unlocked. #[codec(compact)] pub era: EraIndex, } @@ -183,7 +183,7 @@ pub struct LedgerStore { /// Where the reward payment should be made. Keyed by stash. #[derive(Encode, Copy, Clone, Debug, Hash, PartialEq, Eq, Ord, PartialOrd, Store)] pub struct PayeeStore { - #[store(returns = RewardDestination)] + #[store(returns = RewardDestination)] /// Tٗhe stash account pub stash: T::AccountId, } @@ -235,7 +235,7 @@ pub struct EraRewardPoints { /// /// This is keyed fist by the era index to allow bulk deletion and then the stash account. /// -/// Is it removed after `HISTORY_DEPTH` eras. +/// It is removed after `HISTORY_DEPTH` eras. /// If stakers hasn't been set or has been removed then empty exposure is returned. #[derive(Encode, Copy, Clone, Debug, Store)] pub struct ErasStakersClippedStore { @@ -246,7 +246,7 @@ pub struct ErasStakersClippedStore { pub validator_stash: T::AccountId, } -/// The active era information, it holds index and start. +/// The active era information, holds index and start. /// /// The active era is the era currently rewarded. /// Validator set of this era must be equal to `SessionInterface::validators`. @@ -259,21 +259,10 @@ pub struct ActiveEraStore { /// Declare no desire to either validate or nominate. /// -/// Effects will be felt at the beginning of the next era. +/// Effective at the beginning of the next era. /// /// The dispatch origin for this call must be _Signed_ by the controller, not the stash. -/// And, it can be only called when [`EraElectionStatus`] is `Closed`. -/// -/// # -/// - Independent of the arguments. Insignificant complexity. -/// - Contains one read. -/// - Writes are limited to the `origin` account key. -/// -------- -/// Base Weight: 16.53 µs -/// DB Weight: -/// - Read: EraElectionStatus, Ledger -/// - Write: Validators, Nominators -/// # +/// Can only be called when [`EraElectionStatus`] is `Closed`. #[derive(Debug, Call, Encode)] pub struct ChillCall { /// Runtime marker @@ -298,21 +287,10 @@ impl Copy for ChillCall {} /// Declare the desire to validate for the origin controller. /// -/// Effects will be felt at the beginning of the next era. +/// Effective at the beginning of the next era. /// /// The dispatch origin for this call must be _Signed_ by the controller, not the stash. -/// And, it can be only called when [`EraElectionStatus`] is `Closed`. -/// -/// # -/// - Independent of the arguments. Insignificant complexity. -/// - Contains a limited number of reads. -/// - Writes are limited to the `origin` account key. -/// ----------- -/// Base Weight: 17.13 µs -/// DB Weight: -/// - Read: Era Election Status, Ledger -/// - Write: Nominators, Validators -/// # +/// Can only be called when [`EraElectionStatus`] is `Closed`. #[derive(Clone, Debug, PartialEq, Call, Encode)] pub struct ValidateCall { /// Runtime marker @@ -323,23 +301,10 @@ pub struct ValidateCall { /// Declare the desire to nominate `targets` for the origin controller. /// -/// Effects will be felt at the beginning of the next era. This can only be called when -/// [`EraElectionStatus`] is `Closed`. +/// Effective at the beginning of the next era. /// /// The dispatch origin for this call must be _Signed_ by the controller, not the stash. -/// And, it can be only called when [`EraElectionStatus`] is `Closed`. -/// -/// # -/// - The transaction's complexity is proportional to the size of `targets` (N) -/// which is capped at CompactAssignments::LIMIT (MAX_NOMINATIONS). -/// - Both the reads and writes follow a similar pattern. -/// --------- -/// Base Weight: 22.34 + .36 * N µs -/// where N is the number of targets -/// DB Weight: -/// - Reads: Era Election Status, Ledger, Current Era -/// - Writes: Validators, Nominators -/// # +/// Can only be called when [`EraElectionStatus`] is `Closed`. #[derive(Call, Encode, Debug)] pub struct NominateCall { /// The targets that are being nominated diff --git a/src/lib.rs b/src/lib.rs index 49600f09b0..738420a11d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -94,7 +94,7 @@ pub use crate::{ rpc::{ BlockNumber, ExtrinsicSuccess, - Properties, + SystemProperties, }, runtimes::*, subscription::*, @@ -167,7 +167,7 @@ impl ClientBuilder { rpc.metadata(), rpc.genesis_hash(), rpc.runtime_version(None), - rpc.properties(), + rpc.system_properties(), ) .await; Ok(Client { @@ -187,7 +187,7 @@ pub struct Client { rpc: Rpc, genesis_hash: T::Hash, metadata: Metadata, - properties: Properties, + properties: SystemProperties, runtime_version: RuntimeVersion, _marker: PhantomData<(fn() -> T::Signature, T::Extra)>, page_size: u32, @@ -265,7 +265,7 @@ impl Client { } /// Returns the system properties - pub fn properties(&self) -> &Properties { + pub fn properties(&self) -> &SystemProperties { &self.properties } diff --git a/src/rpc.rs b/src/rpc.rs index 969a977782..25ec9c3e0f 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -99,7 +99,7 @@ impl From for BlockNumber { #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq, Default)] #[serde(rename_all = "camelCase")] /// System properties for a Substrate-based runtime -pub struct Properties { +pub struct SystemProperties { /// The address format pub ss58_format: u8, /// The number of digits after the decimal point in the native token @@ -221,7 +221,7 @@ impl Rpc { } /// Fetch system properties - pub async fn properties(&self) -> Result { + pub async fn system_properties(&self) -> Result { Ok(self .client .request("system_properties", Params::None) From 0084f875756e08ae529e9766a4519fec65f1b01f Mon Sep 17 00:00:00 2001 From: "Demi M. Obenour" Date: Fri, 11 Sep 2020 16:20:08 -0400 Subject: [PATCH 06/11] Fix header --- src/frame/session.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/frame/session.rs b/src/frame/session.rs index fca862a9a3..3640355e77 100644 --- a/src/frame/session.rs +++ b/src/frame/session.rs @@ -1,19 +1,18 @@ // Copyright 2019-2020 Parity Technologies (UK) Ltd. // This file is part of substrate-subxt. // -// substrate-subxt is free software: you can redistribute it and/or modify +// subxt is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // -// substrate-subxt is distributed in the hope that it will be useful, +// subxt is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with substrate-subxt. If not, see . -// Copyright 2019-2020 Parity Technologies (UK) Ltd. //! Session support use crate::frame::system::{ From 33f171090970f205fced4cc5ab10852e3b09615b Mon Sep 17 00:00:00 2001 From: "Demi M. Obenour" Date: Fri, 11 Sep 2020 19:37:00 -0400 Subject: [PATCH 07/11] Remove some code Ledgeracio does not need --- src/frame/staking.rs | 59 -------------------------------------------- src/runtimes.rs | 4 --- 2 files changed, 63 deletions(-) diff --git a/src/frame/staking.rs b/src/frame/staking.rs index d4a6c7b469..b08d5940e0 100644 --- a/src/frame/staking.rs +++ b/src/frame/staking.rs @@ -47,20 +47,6 @@ pub use pallet_staking::{ ValidatorPrefs, }; -/// Similar to `ErasStakers`, this holds the preferences of validators. -/// -/// This is keyed first by the era index to allow bulk deletion and then the stash account. -/// -/// It is removed after `HISTORY_DEPTH` eras. -#[derive(Encode, Decode, Debug, Store)] -pub struct ErasValidatorPrefsStore { - #[store(returns = ValidatorPrefs)] - /// Era index - pub index: EraIndex, - /// Account ID - pub account_id: T::AccountId, -} - /// Rewards for the last `HISTORY_DEPTH` eras. /// If reward hasn't been set or has been removed then 0 reward is returned. #[derive(Clone, Encode, Decode, Debug, Store)] @@ -103,23 +89,6 @@ pub trait Staking: Balances { + Copy + MaybeSerialize + Debug; - - /// Maximum number of validators that can be stored in a snapshot. - const MAX_VALIDATORS: usize; - - /// Maximum number of nominators that can be stored in a snapshot. - const MAX_NOMINATORS: usize; -} - -/// A Balance/BlockNumber tuple to encode when a chunk of funds will be unlocked. -#[derive(Clone, Encode, Decode, Debug)] -pub struct UnlockChunk { - /// Amount of funds to be unlocked. - #[codec(compact)] - pub value: T::Balance, - /// Era number at which point the funds will be unlocked. - #[codec(compact)] - pub era: EraIndex, } /// Number of eras to keep in history. @@ -136,34 +105,6 @@ pub struct HistoryDepthStore { pub _runtime: PhantomData, } -/// The ideal number of staking participants. -#[derive(Encode, Decode, Copy, Clone, Debug, Store)] -pub struct ValidatorCountStore { - #[store(returns = u32)] - /// Marker for the runtime - pub _runtime: PhantomData, -} - -/// Minimum number of staking participants before emergency conditions are imposed. -#[derive( - Encode, Decode, Copy, Clone, Debug, Hash, PartialEq, Eq, Ord, PartialOrd, Store, -)] -pub struct MinimumValidatorCountStore { - #[store(returns = u32)] - /// Marker for the runtime - pub _runtime: PhantomData, -} - -/// Any validators that may never be slashed or forcibly kicked. It's a Vec since they're -/// easy to initialize and the performance hit is minimal (we expect no more than four -/// invulnerables) and restricted to testnets. -#[derive(Encode, Copy, Clone, Debug, Hash, PartialEq, Eq, Ord, PartialOrd, Store)] -pub struct InvulnerablesStore { - #[store(returns = Vec)] - /// Marker for the runtime - pub _runtime: PhantomData, -} - /// Map from all locked "stash" accounts to the controller account. #[derive(Encode, Copy, Clone, Debug, Hash, PartialEq, Eq, Ord, PartialOrd, Store)] pub struct BondedStore { diff --git a/src/runtimes.rs b/src/runtimes.rs index b38bee0dbe..f86096e0d5 100644 --- a/src/runtimes.rs +++ b/src/runtimes.rs @@ -149,8 +149,6 @@ pub struct DefaultNodeRuntime; impl Staking for DefaultNodeRuntime { type NominatorIndex = u32; type ValidatorIndex = u16; - const MAX_VALIDATORS: usize = Self::ValidatorIndex::max_value() as usize; - const MAX_NOMINATORS: usize = Self::NominatorIndex::max_value() as usize; } impl Runtime for DefaultNodeRuntime { @@ -257,8 +255,6 @@ impl Session for KusamaRuntime { impl Staking for KusamaRuntime { type NominatorIndex = u32; type ValidatorIndex = u16; - const MAX_VALIDATORS: usize = Self::ValidatorIndex::max_value() as usize; - const MAX_NOMINATORS: usize = Self::NominatorIndex::max_value() as usize; } impl Balances for KusamaRuntime { From 9f34f76d81ca17ee50a31e9f00b74b14e5ffe265 Mon Sep 17 00:00:00 2001 From: "Demi M. Obenour" Date: Fri, 11 Sep 2020 19:42:46 -0400 Subject: [PATCH 08/11] More deletions --- src/frame/staking.rs | 40 ---------------------------------------- 1 file changed, 40 deletions(-) diff --git a/src/frame/staking.rs b/src/frame/staking.rs index b08d5940e0..5a48d9d9f1 100644 --- a/src/frame/staking.rs +++ b/src/frame/staking.rs @@ -167,37 +167,6 @@ pub struct EraRewardPoints { pub individual: BTreeMap, } -/// Clipped Exposure of validator at era. -/// -/// This is similar to [`ErasStakers`] but number of nominators exposed is reduced to the -/// `T::MaxNominatorRewardedPerValidator` biggest stakers. -/// (Note: the field `total` and `own` of the exposure remains unchanged). -/// This is used to limit the i/o cost for the nominator payout. -/// -/// This is keyed fist by the era index to allow bulk deletion and then the stash account. -/// -/// It is removed after `HISTORY_DEPTH` eras. -/// If stakers hasn't been set or has been removed then empty exposure is returned. -#[derive(Encode, Copy, Clone, Debug, Store)] -pub struct ErasStakersClippedStore { - #[store(returns = Exposure)] - /// Era index - pub era: EraIndex, - /// Stash account of the validator - pub validator_stash: T::AccountId, -} - -/// The active era information, holds index and start. -/// -/// The active era is the era currently rewarded. -/// Validator set of this era must be equal to `SessionInterface::validators`. -#[derive(Encode, Copy, Clone, Debug, Hash, PartialEq, Eq, Ord, PartialOrd, Store)] -pub struct ActiveEraStore { - #[store(returns = Option)] - /// Marker for the runtime - pub _runtime: PhantomData, -} - /// Declare no desire to either validate or nominate. /// /// Effective at the beginning of the next era. @@ -251,12 +220,3 @@ pub struct NominateCall { /// The targets that are being nominated pub targets: Vec, } - -/// Claim a payout for a validator’s stakers -#[derive(PartialEq, Eq, Clone, Call, Encode, Decode, Debug)] -pub struct PayoutStakersCall<'a, T: Staking> { - /// Stash account of the validator - pub validator_stash: &'a T::AccountId, - /// Era index - pub era: EraIndex, -} From 1df5a640245a7db6cf536abb7bb64033baf520aa Mon Sep 17 00:00:00 2001 From: "Demi M. Obenour" Date: Fri, 11 Sep 2020 20:26:14 -0400 Subject: [PATCH 09/11] Remove more code not needed for Ledgeracio --- src/frame/session.rs | 42 ------------------------------------------ src/frame/staking.rs | 27 +-------------------------- src/runtimes.rs | 13 ++----------- 3 files changed, 3 insertions(+), 79 deletions(-) diff --git a/src/frame/session.rs b/src/frame/session.rs index 3640355e77..f5f527b81b 100644 --- a/src/frame/session.rs +++ b/src/frame/session.rs @@ -51,9 +51,6 @@ pub trait Session: System { /// The validator account identifier type for the runtime. type ValidatorId: Parameter + Debug + Ord + Default + Send + Sync + 'static; - /// The session index identifier type for the runtime. - type SessionIndex: Parameter + Debug + Ord + Default + Send + Sync + 'static; - /// The keys. type Keys: OpaqueKeys + Member + Parameter + Default; } @@ -68,27 +65,6 @@ pub struct ValidatorsStore { default_impl!(ValidatorsStore); -/// Current index of the session. -#[derive(Encode, Store, Debug)] -pub struct CurrentIndexStore { - #[store(returns = ::SessionIndex)] - /// Marker for the runtime - pub _runtime: PhantomData, -} - -default_impl!(CurrentIndexStore); - -/// True if the underlying economic identities or weighting behind the validators -/// has changed in the queued validator set. -#[derive(Encode, Store, Debug)] -pub struct QueuedChangedStore { - #[store(returns = bool)] - /// Marker for the runtime - pub _runtime: PhantomData, -} - -default_impl!(QueuedChangedStore); - /// Set the session keys for a validator. #[derive(Encode, Call, Debug)] pub struct SetKeysCall { @@ -97,21 +73,3 @@ pub struct SetKeysCall { /// The proof. This is not currently used and can be set to an empty vector. pub proof: Vec, } - -#[cfg(test)] -mod tests { - use super::*; - use crate::tests::test_client; - - #[async_std::test] - #[ignore] - async fn test_state_read_free_balance() { - env_logger::try_init().ok(); - let (client, _) = test_client().await; - assert!(client - .fetch(&QueuedChangedStore::default(), None) - .await - .unwrap() - .unwrap()); - } -} diff --git a/src/frame/staking.rs b/src/frame/staking.rs index 5a48d9d9f1..417222e338 100644 --- a/src/frame/staking.rs +++ b/src/frame/staking.rs @@ -24,11 +24,6 @@ use codec::{ Decode, Encode, }; -use frame_support::Parameter; -use sp_runtime::traits::{ - MaybeSerialize, - Member, -}; use std::{ collections::BTreeMap, @@ -69,27 +64,7 @@ pub struct SetPayeeCall { /// The subset of the `frame::Trait` that a client must implement. #[module] -pub trait Staking: Balances { - /// Data type used to index nominators in the compact type - type NominatorIndex: Parameter - + codec::Codec - + Member - + Default - + Copy - + MaybeSerialize - + Debug; - - /// Data type used to index validators in the compact type. - type ValidatorIndex: Parameter - + codec::Codec - + Send - + Sync - + Default - + Member - + Copy - + MaybeSerialize - + Debug; -} +pub trait Staking: Balances {} /// Number of eras to keep in history. /// diff --git a/src/runtimes.rs b/src/runtimes.rs index f86096e0d5..6bbd8b7c26 100644 --- a/src/runtimes.rs +++ b/src/runtimes.rs @@ -146,10 +146,7 @@ pub trait Runtime: System + Sized + Send + Sync + 'static { #[derive(Debug, Clone, Eq, PartialEq)] pub struct DefaultNodeRuntime; -impl Staking for DefaultNodeRuntime { - type NominatorIndex = u32; - type ValidatorIndex = u16; -} +impl Staking for DefaultNodeRuntime {} impl Runtime for DefaultNodeRuntime { type Signature = MultiSignature; @@ -173,7 +170,6 @@ impl Balances for DefaultNodeRuntime { } impl Session for DefaultNodeRuntime { - type SessionIndex = u32; type ValidatorId = ::AccountId; type Keys = BasicSessionKeys; } @@ -213,7 +209,6 @@ impl Balances for NodeTemplateRuntime { } impl Session for NodeTemplateRuntime { - type SessionIndex = u32; type ValidatorId = ::AccountId; type Keys = BasicSessionKeys; } @@ -247,15 +242,11 @@ impl System for KusamaRuntime { } impl Session for KusamaRuntime { - type SessionIndex = u32; type ValidatorId = ::AccountId; type Keys = SessionKeys; } -impl Staking for KusamaRuntime { - type NominatorIndex = u32; - type ValidatorIndex = u16; -} +impl Staking for KusamaRuntime {} impl Balances for KusamaRuntime { type Balance = u128; From c622641a8e163953062c031a7bc9606b07616a2c Mon Sep 17 00:00:00 2001 From: "Demi M. Obenour" Date: Fri, 11 Sep 2020 20:47:02 -0400 Subject: [PATCH 10/11] Remove a pointless change in Cargo.toml w.r.t. upstream. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index aaca8753be..155d78c4a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,7 @@ num-traits = "0.2.12" serde = { version = "1.0.115", features = ["derive"] } serde_json = "1.0.57" url = "2.1.1" -codec = { package = "parity-scale-codec", version = "1.3.5", features = ["derive", "full"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive", "full"] } frame-metadata = { version = "11.0.0-rc6", package = "frame-metadata" } frame-support = { version = "2.0.0-rc6", package = "frame-support" } From b253a7ab39ddd55546d129c43517114e8494b590 Mon Sep 17 00:00:00 2001 From: "Demi M. Obenour" Date: Fri, 11 Sep 2020 21:37:06 -0400 Subject: [PATCH 11/11] Remove more junk --- Cargo.toml | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 155d78c4a2..2fcd351343 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ log = "0.4.11" thiserror = "1.0.20" futures = "0.3.5" jsonrpsee = { version = "0.1.0", features = ["ws"] } -num-traits = "0.2.12" +num-traits = { version = "0.2.12", default-features = false } serde = { version = "1.0.115", features = ["derive"] } serde_json = "1.0.57" url = "2.1.1" @@ -63,21 +63,3 @@ substrate-subxt-client = { version = "0.4.0", path = "client" } tempdir = "0.3.7" test-node = { path = "test-node" } wabt = "0.10.0" - -# [patch.crates-io] -# frame-metadata = { git = "https://github.com/paritytech/substrate" } -# frame-support = { git = "https://github.com/paritytech/substrate" } -# sp-runtime = { git = "https://github.com/paritytech/substrate" } -# sp-version = { git = "https://github.com/paritytech/substrate" } -# pallet-indices = { git = "https://github.com/paritytech/substrate" } -# sp-rpc = { git = "https://github.com/paritytech/substrate" } -# sp-core = { git = "https://github.com/paritytech/substrate" } -# sc-rpc-api = { git = "https://github.com/paritytech/substrate" } -# sp-transaction-pool = { git = "https://github.com/paritytech/substrate" } -# sp-std = { git = "https://github.com/paritytech/substrate" } -# application-crypto = { git = "https://github.com/paritytech/substrate", package = "sp-application-crypto", default-features = false } -# sp-finality-grandpa = { git = "https://github.com/paritytech/substrate" } -# sp-consensus-babe = { git = "https://github.com/paritytech/substrate" } -# pallet-im-online = { git = "https://github.com/paritytech/substrate" } -# sp-authority-discovery = { git = "https://github.com/paritytech/substrate" } -# pallet-staking = { git = "https://github.com/paritytech/substrate" }