Skip to content

Commit

Permalink
Staking support (paritytech#99)
Browse files Browse the repository at this point in the history
* Initial Staking API

* Add more staking types

* Reformat

* Remove dead code

* Fix missing documentation

* Reformat

* Staking: use proc macros

* Add partial session support

* Reformat

* Try to implement nomination

This currently fails with compilation errors I do not understand.

* Use the #[module] macro

This fixes a compile error

* Explain undefined method diagnostics

* Use ‘#[module]’ and implement session for Kusama

* Don’t impl ‘Staking’ for all ‘T: System’

* Add staking payout support

* Fix compilation errors and remove useless lifetimes

* Respond to code review

This fixes most of the issues found during review, with the exception of
tests.

* Make signing fallable and asynchronous

This is needed for hardware wallets, which require human confirmation to
sign transactions.  Blocking on a human to sign transactions is not a
good idea, and the signing might fail for many reasons (device
unplugged, authorization not granted, etc).

* Reformat

* Refactor as suggested by Andrew Jones (@ascjones).

* Reformat

* Refactor as suggested by Andrew Jones (@ascjones).

* Trait cleanups

* Make the `Signer` impl require Send + Sync

This is what Ledgeracio needs.

* Use the correct key for staking maps

They use the key type, not ‘PhantomData’.

* Implement set_payee call

* Switch to associated types for Staking

* Implement `set_keys`

This is needed for Ledgeracio.

* Remove impl of Signer for Box<dyn Signer + Send + Sync>

It isn’t needed, since Box implements Deref.

* Fix Polkadot and Kusama ‘SessionKey’ structs

I had failed to include the ‘Parachains’ component, which the default
Substrate runtime doesn’t have.

* Include a copy of `ValidatorId`

This avoids needing to depend on Polkadot.

* Fix syntax error in Cargo.toml

* Fix compile errors

* Add Debug impls

* Fix return type of `BondedStore`

* Use some upstream type definitions

Also add `Default` impls.

* Bump deps and fix build

* Remove last reference to Kusama feature

* Fix compilation errors

* Implement the `concat` in `twox_64_concat`

* Expose properties and per-era preferences

* Era rewards point support

I also did some refactoring.

* Expose clipped exposure

* Era reward points support

* Make `PayoutStakersCall` public

* Add in all default features for debugging

* Chill support and update to latest Substrate

* If property fetch fails, use dummy values

* Fix tests

* Fix header

* Remove some code Ledgeracio does not need

* More deletions

* Remove more code not needed for Ledgeracio

* Remove a pointless change in Cargo.toml

w.r.t. upstream.

* Remove more junk

* Revert contracts put_code test to pure code (not using the macro)

* Test contract instantiate

* Fmt

* WIP

* Add some more submission tests

* Reformat

* More tests

* Cleanup

* Hopefully fix CI

* Remove dead code

* Test chill

* Add missing docs

* Remove unnecessary use

* Revert "Remove unnecessary use"

This reverts commit bc8bc36bde581f1892ea88a778dfe0fe5bff24d7.

* Retry on temporary failures

* Ignore the staking tests on CI

* Obey the fmt

* Run CI with at most one test thread

* Implement tests for staking

* More tests

* Remove unhelpful println!

* Revert changes in contract tests

* Reformat

* Remove spurious diff

* More tests

Co-authored-by: Demi M. Obenour <demiobenour@gmail.com>
Co-authored-by: David Palm <dvdplm@gmail.com>
Co-authored-by: Andrew Jones <ascjones@gmail.com>
  • Loading branch information
4 people authored Sep 21, 2020
1 parent 0c7454d commit f9f69b8
Show file tree
Hide file tree
Showing 12 changed files with 606 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ jobs:
run: cargo build --workspace --verbose

- name: test
run: cargo test --workspace --verbose
run: cargo test --workspace --verbose -- --test-threads=1
13 changes: 12 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ keywords = ["parity", "substrate", "blockchain"]
include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE"]

[features]
kusama = []
default = ["kusama"]
client = ["substrate-subxt-client"]

# enable this feature to run tests which require a local dev chain node
Expand All @@ -31,14 +33,22 @@ 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" }
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" }
sp-finality-grandpa = "2.0.0-rc6"
sp-consensus-babe = "0.8.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" }
sc-rpc-api = { version = "0.8.0-rc6", package = "sc-rpc-api" }
Expand All @@ -56,3 +66,4 @@ substrate-subxt-client = { version = "0.4.0", path = "client" }
tempdir = "0.3.7"
test-node = { path = "test-node" }
wabt = "0.10.0"
assert_matches = "1.3"
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ A library to **sub**mit e**xt**rinsics to a [substrate](https://github.com/parit

See [examples](./examples).

If you use `#[derive(Call)]` without `#[module]` in the same module, you will get errors
complaining about an undefined method with a name starting with `with_`.

**Alternatives**

[substrate-api-client](https://github.com/scs/substrate-api-client) provides similar functionality.
Expand Down
1 change: 1 addition & 0 deletions src/extrinsic/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub trait Signer<T: Runtime> {
}

/// Extrinsic signer using a private key.
#[derive(Debug)]
pub struct PairSigner<T: Runtime, P: Pair> {
account_id: T::AccountId,
nonce: Option<T::Index>,
Expand Down
2 changes: 2 additions & 0 deletions src/frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ use sp_core::storage::StorageKey;

pub mod balances;
pub mod contracts;
pub mod session;
pub mod staking;
pub mod sudo;
pub mod system;

Expand Down
75 changes: 75 additions & 0 deletions src/frame/session.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// 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
// 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,
// 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 <http://www.gnu.org/licenses/>.

//! Session support
use crate::frame::system::{
System,
SystemEventsDecoder as _,
};
use codec::Encode;
use frame_support::Parameter;
use sp_runtime::traits::{
Member,
OpaqueKeys,
};
use std::{
fmt::Debug,
marker::PhantomData,
};
use substrate_subxt_proc_macro::Store;

/// 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<T: Session> Default for $name<T> {
fn default() -> Self {
Self {
_runtime: PhantomData,
}
}
}
};
}

/// The trait needed for this module.
#[module]
pub trait Session: System {
/// The validator account identifier type for the runtime.
type ValidatorId: Parameter + Debug + Ord + Default + Send + Sync + 'static;

/// The keys.
type Keys: OpaqueKeys + Member + Parameter + Default;
}

/// The current set of validators.
#[derive(Encode, Store, Debug)]
pub struct ValidatorsStore<T: Session> {
#[store(returns = Vec<<T as Session>::ValidatorId>)]
/// Marker for the runtime
pub _runtime: PhantomData<T>,
}

default_impl!(ValidatorsStore);

/// Set the session keys for a validator.
#[derive(Encode, Call, Debug)]
pub struct SetKeysCall<T: Session> {
/// The keys
pub keys: T::Keys,
/// The proof. This is not currently used and can be set to an empty vector.
pub proof: Vec<u8>,
}
Loading

0 comments on commit f9f69b8

Please sign in to comment.