diff --git a/Cargo.toml b/Cargo.toml index 32214073a0..2fcd351343 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,7 @@ 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" -codec = { package = "parity-scale-codec", version = "1.3.4", default-features = false, 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" } @@ -38,9 +38,8 @@ sp-runtime = { version = "2.0.0-rc6", package = "sp-runtime" } 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 } +application-crypto = { version = "2.0.0-rc6", package = "sp-application-crypto" } sp-finality-grandpa = "2.0.0-rc6" sp-consensus-babe = "0.8.0-rc6" pallet-im-online = "2.0.0-rc6" diff --git a/src/frame/session.rs b/src/frame/session.rs index 4f7b90af6f..f5f527b81b 100644 --- a/src/frame/session.rs +++ b/src/frame/session.rs @@ -13,7 +13,6 @@ // // 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::{ @@ -32,7 +31,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,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 validator account identifier type for the runtime. - type SessionIndex: Parameter + Debug + Ord + Default + Send + Sync + 'static; - /// The keys. type Keys: OpaqueKeys + Member + Parameter + Default; } @@ -65,30 +63,9 @@ pub struct ValidatorsStore { pub _runtime: PhantomData, } -def!(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, -} - -def!(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, -} - -def!(QueuedChangedStore); - -/// The current set of validators. +/// Set the session keys for a validator. #[derive(Encode, Call, Debug)] pub struct SetKeysCall { /// The keys @@ -96,20 +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] - 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 8b155af4bb..417222e338 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, @@ -24,11 +24,6 @@ use codec::{ Decode, Encode, }; -use frame_support::Parameter; -use sp_runtime::traits::{ - MaybeSerialize, - Member, -}; use std::{ collections::BTreeMap, @@ -47,20 +42,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. -/// -/// Is it 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)] @@ -83,44 +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; - - /// 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; -} - -/// Just 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. - #[codec(compact)] - pub era: EraIndex, -} +pub trait Staking: Balances {} /// Number of eras to keep in history. /// @@ -136,34 +80,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 { @@ -226,90 +142,56 @@ pub struct EraRewardPoints { pub individual: BTreeMap, } -/// Clipped Exposure of validator at era. +/// Declare no desire to either validate or nominate. /// -/// 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. +/// Effective at the beginning of the next era. /// -/// This is keyed fist by the era index to allow bulk deletion and then the stash account. -/// -/// Is it 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, it 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 +/// The dispatch origin for this call must be _Signed_ by the controller, not the stash. +/// Can only be called when [`EraElectionStatus`] is `Closed`. +#[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. +/// 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. + /// Runtime marker pub _runtime: PhantomData, - /// Validation preferences. + /// Validation preferences pub prefs: ValidatorPrefs, } /// 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 pub targets: Vec, } - -/// Claim a payout. -#[derive(PartialEq, Eq, Clone, Call, Encode, Decode, Debug)] -struct PayoutStakersCall<'a, T: Staking> { - pub validator_stash: &'a T::AccountId, - pub era: EraIndex, -} diff --git a/src/lib.rs b/src/lib.rs index a4cc5949ac..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,14 +167,14 @@ impl ClientBuilder { rpc.metadata(), rpc.genesis_hash(), rpc.runtime_version(None), - rpc.properties(), + rpc.system_properties(), ) .await; Ok(Client { 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), @@ -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 a29582abd0..25ec9c3e0f 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -96,10 +96,10 @@ 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 { +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) diff --git a/src/runtimes.rs b/src/runtimes.rs index b38bee0dbe..6bbd8b7c26 100644 --- a/src/runtimes.rs +++ b/src/runtimes.rs @@ -146,12 +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; - const MAX_VALIDATORS: usize = Self::ValidatorIndex::max_value() as usize; - const MAX_NOMINATORS: usize = Self::NominatorIndex::max_value() as usize; -} +impl Staking for DefaultNodeRuntime {} impl Runtime for DefaultNodeRuntime { type Signature = MultiSignature; @@ -175,7 +170,6 @@ impl Balances for DefaultNodeRuntime { } impl Session for DefaultNodeRuntime { - type SessionIndex = u32; type ValidatorId = ::AccountId; type Keys = BasicSessionKeys; } @@ -215,7 +209,6 @@ impl Balances for NodeTemplateRuntime { } impl Session for NodeTemplateRuntime { - type SessionIndex = u32; type ValidatorId = ::AccountId; type Keys = BasicSessionKeys; } @@ -249,17 +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; - const MAX_VALIDATORS: usize = Self::ValidatorIndex::max_value() as usize; - const MAX_NOMINATORS: usize = Self::NominatorIndex::max_value() as usize; -} +impl Staking for KusamaRuntime {} impl Balances for KusamaRuntime { type Balance = u128;