Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Staking Miner #3141

Merged
merged 39 commits into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
36502dc
Companion for Decouple Staking and Election - Part 3: Signed Phase
coriolinus Apr 1, 2021
1e509e9
Merge remote-tracking branch 'origin/master' into prgn-companion-for-…
coriolinus May 26, 2021
9638fcf
Merge remote-tracking branch 'origin/master' into prgn-companion-for-…
coriolinus May 27, 2021
59646c2
Merge branch 'prgn-companion-for-7910' of github.com:paritytech/polka…
kianenigma May 29, 2021
271d351
Template added
kianenigma May 29, 2021
7e21f24
Add stuff
kianenigma May 29, 2021
61cf070
First working version
kianenigma May 31, 2021
95b6ea0
revamp rpc stuff
kianenigma May 31, 2021
1709494
remove all the stale js stuff
kianenigma Jun 1, 2021
0c10c66
Major updates, closer to completion.
kianenigma Jun 3, 2021
a4aa730
removing my generic WIP for tidyness.
kianenigma Jun 3, 2021
72db361
add --at
kianenigma Jun 3, 2021
dc1a623
ass measure snapshot
kianenigma Jun 13, 2021
5fa5a3f
some new little debugging thigs
kianenigma Jun 17, 2021
138e8b9
pre-merge
kianenigma Jun 25, 2021
c3cfe94
Merge branch 'master' of github.com:paritytech/polkadot into kiz-stak…
kianenigma Jun 25, 2021
863ea3a
Master.into()
kianenigma Jun 28, 2021
3980e85
Fix
kianenigma Jun 28, 2021
d1ba0cb
revert dep update
kianenigma Jun 30, 2021
fe76cee
update to master
kianenigma Jun 30, 2021
3777a8a
revert all the toml shit
kianenigma Jun 30, 2021
64c22d9
Apply suggestions from code review
kianenigma Jun 30, 2021
bcd394d
cleanup
kianenigma Jun 30, 2021
e74218e
Fix more
kianenigma Jun 30, 2021
3ce287f
Fix era
kianenigma Jul 1, 2021
7dd7e64
Apply suggestions from code review
kianenigma Jul 1, 2021
ab87195
Few fixes
kianenigma Jul 1, 2021
c77bf51
Better reward scheme
kianenigma Jul 1, 2021
b25ee40
y
kianenigma Jul 1, 2021
10508ae
Update utils/staking-miner/src/main.rs
kianenigma Jul 1, 2021
f83ddb6
Update utils/staking-miner/src/dry_run.rs
kianenigma Jul 1, 2021
913e75a
Update utils/staking-miner/src/dry_run.rs
kianenigma Jul 1, 2021
89e0a38
Update utils/staking-miner/src/monitor.rs
kianenigma Jul 1, 2021
dcbe582
More chnages
kianenigma Jul 1, 2021
f10f00b
Merge branch 'kiz-staking-miner' of github.com:paritytech/polkadot in…
kianenigma Jul 1, 2021
df8725b
Fix
kianenigma Jul 1, 2021
1e4f6be
Master.into()
kianenigma Jul 1, 2021
01e92c4
Make it restart automatically.
kianenigma Jul 1, 2021
979cfcc
Final touches
kianenigma Jul 1, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ members = [
"parachain/test-parachains",
"parachain/test-parachains/adder",
"parachain/test-parachains/adder/collator",
"utils/staking-miner",
]

# We want to be able to build the bridge relayer without pulling it (and all of its
Expand Down
6 changes: 3 additions & 3 deletions node/service/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,7 @@ pub fn polkadot_testnet_genesis(
},
staking: polkadot::StakingConfig {
minimum_validator_count: 1,
validator_count: 2,
validator_count: initial_authorities.len() as u32,
stakers: initial_authorities
.iter()
.map(|x| {
Expand Down Expand Up @@ -1312,7 +1312,7 @@ pub fn kusama_testnet_genesis(
},
staking: kusama::StakingConfig {
minimum_validator_count: 1,
validator_count: 2,
validator_count: initial_authorities.len() as u32,
stakers: initial_authorities
.iter()
.map(|x| {
Expand Down Expand Up @@ -1416,7 +1416,7 @@ pub fn westend_testnet_genesis(
},
staking: westend::StakingConfig {
minimum_validator_count: 1,
validator_count: 2,
validator_count: initial_authorities.len() as u32,
stakers: initial_authorities
.iter()
.map(|x| {
Expand Down
37 changes: 22 additions & 15 deletions runtime/common/src/elections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@

use frame_support::{
parameter_types,
traits::Get,
weights::{DispatchClass, Weight, WeightToFeePolynomial},
weights::{DispatchClass, Weight},
};
use sp_runtime::Perbill;
use sp_runtime::{
traits::{Zero, Dispatchable},
FixedU128, FixedPointNumber, Perbill,
};
use pallet_transaction_payment::OnChargeTransaction;
use frame_support::weights::{DispatchInfo, Pays};
use super::{BlockExecutionWeight, BlockLength, BlockWeights};

parameter_types! {
Expand All @@ -44,18 +48,21 @@ parameter_types! {
.get(DispatchClass::Normal);
}

/// Compute the expected fee for submitting an election solution.
///
/// This is `multiplier` multiplied by the fee for the expected submission weight according to the
/// weight info.
///
/// Assumes that the signed submission queue is full.
pub fn fee_for_submit_call<T, WeightToFee, WeightInfo>(multiplier: Perbill) -> WeightToFee::Balance
pub fn fee_for_submit_call<T>(
multiplier: FixedU128,
weight: Weight,
length: u32,
) -> primitives::v1::Balance
where
T: pallet_election_provider_multi_phase::Config,
WeightToFee: WeightToFeePolynomial,
WeightInfo: pallet_election_provider_multi_phase::WeightInfo,
T: pallet_transaction_payment::Config,
<T as pallet_transaction_payment::Config>::OnChargeTransaction:
OnChargeTransaction<T, Balance = primitives::v1::Balance>,
<T as frame_system::Config>::Call: Dispatchable<Info = DispatchInfo>,
{
let expected_weight = WeightInfo::submit(T::SignedMaxSubmissions::get());
multiplier * WeightToFee::calc(&expected_weight)
let info = DispatchInfo { weight, class: DispatchClass::Normal, pays_fee: Pays::Yes };
multiplier.saturating_mul_int(pallet_transaction_payment::Pallet::<T>::compute_fee(
length,
&info,
Zero::zero(),
))
}
19 changes: 12 additions & 7 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ use xcm_builder::{
use xcm_executor::XcmExecutor;
use sp_arithmetic::Perquintill;
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
ApplyExtrinsicResult, KeyTypeId, Percent, Permill, Perbill,
create_runtime_str, generic, impl_opaque_keys, ApplyExtrinsicResult, KeyTypeId, Percent,
Permill, Perbill, FixedPointNumber,
transaction_validity::{TransactionValidity, TransactionSource, TransactionPriority},
traits::{
BlakeTwo256, Block as BlockT, OpaqueKeys, ConvertInto, AccountIdLookup,
Expand Down Expand Up @@ -101,6 +101,7 @@ pub use pallet_staking::StakerStatus;
pub use sp_runtime::BuildStorage;
pub use pallet_timestamp::Call as TimestampCall;
pub use pallet_balances::Call as BalancesCall;
pub use pallet_election_provider_multi_phase::Call as EPMCall;

/// Constant values used within the runtime.
pub mod constants;
Expand Down Expand Up @@ -348,6 +349,7 @@ impl pallet_session::historical::Config for Runtime {
type FullIdentificationOf = pallet_staking::ExposureOf<Runtime>;
}

use pallet_election_provider_multi_phase::WeightInfo;
parameter_types! {
// phase durations. 1/4 of the last session for each.
pub const SignedPhase: u32 = EPOCH_DURATION_IN_SLOTS / 4;
Expand All @@ -360,11 +362,14 @@ parameter_types! {
// This formula is currently adjusted such that a typical solution will spend an amount equal
// to the base deposit for every 50 kb.
pub const SignedDepositByte: Balance = deposit(1, 0) / (50 * 1024);
pub SignedRewardBase: Balance = fee_for_submit_call::<
Runtime,
crate::constants::fee::WeightToFee,
crate::weights::pallet_election_provider_multi_phase::WeightInfo<Runtime>,
>(Perbill::from_perthousand(1500));
pub SignedRewardBase: Balance = fee_for_submit_call::<Runtime>(
// give 20% threshold.
sp_runtime::FixedU128::saturating_from_rational(12, 10),
// maximum weight possible.
weights::pallet_election_provider_multi_phase::WeightInfo::<Runtime>::submit(SignedMaxSubmissions::get()),
// assume a solution of 100kb length.
100 * 1024
);

// fallback: emergency phase.
pub const Fallback: pallet_election_provider_multi_phase::FallbackStrategy =
Expand Down
17 changes: 11 additions & 6 deletions runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use primitives::v1::{
ValidatorIndex, InboundDownwardMessage, InboundHrmpMessage, SessionInfo,
};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys, ApplyExtrinsicResult,
create_runtime_str, generic, impl_opaque_keys, ApplyExtrinsicResult, FixedPointNumber,
KeyTypeId, Percent, Permill, Perbill, curve::PiecewiseLinear,
transaction_validity::{TransactionValidity, TransactionSource, TransactionPriority},
traits::{
Expand Down Expand Up @@ -77,6 +77,7 @@ pub use pallet_staking::StakerStatus;
pub use sp_runtime::BuildStorage;
pub use pallet_timestamp::Call as TimestampCall;
pub use pallet_balances::Call as BalancesCall;
pub use pallet_election_provider_multi_phase::Call as EPMCall;
kianenigma marked this conversation as resolved.
Show resolved Hide resolved

/// Constant values used within the runtime.
pub mod constants;
Expand Down Expand Up @@ -328,6 +329,7 @@ impl pallet_session::historical::Config for Runtime {
type FullIdentificationOf = pallet_staking::ExposureOf<Runtime>;
}

use pallet_election_provider_multi_phase::WeightInfo;
parameter_types! {
// phase durations. 1/4 of the last session for each.
pub const SignedPhase: u32 = EPOCH_DURATION_IN_SLOTS / 4;
Expand All @@ -340,11 +342,14 @@ parameter_types! {
// This formula is currently adjusted such that a typical solution will spend an amount equal
// to the base deposit for every 50 kb.
pub const SignedDepositByte: Balance = deposit(1, 0) / (50 * 1024);
pub SignedRewardBase: Balance = fee_for_submit_call::<
Runtime,
crate::constants::fee::WeightToFee,
crate::weights::pallet_election_provider_multi_phase::WeightInfo<Runtime>,
>(Perbill::from_perthousand(1500));
pub SignedRewardBase: Balance = fee_for_submit_call::<Runtime>(
// give 20% threshold.
sp_runtime::FixedU128::saturating_from_rational(12, 10),
// maximum weight possible.
weights::pallet_election_provider_multi_phase::WeightInfo::<Runtime>::submit(SignedMaxSubmissions::get()),
// assume a solution of 200kb length.
200 * 1024
);

// fallback: emergency phase.
pub const Fallback: pallet_election_provider_multi_phase::FallbackStrategy =
Expand Down
17 changes: 11 additions & 6 deletions runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ use xcm_builder::{
};

use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
create_runtime_str, generic, impl_opaque_keys, FixedPointNumber,
ApplyExtrinsicResult, KeyTypeId, Perbill, curve::PiecewiseLinear,
transaction_validity::{TransactionValidity, TransactionSource, TransactionPriority},
traits::{
Expand Down Expand Up @@ -100,6 +100,7 @@ pub use pallet_staking::StakerStatus;
pub use sp_runtime::BuildStorage;
pub use pallet_timestamp::Call as TimestampCall;
pub use pallet_balances::Call as BalancesCall;
pub use pallet_election_provider_multi_phase::Call as EPMCall;
kianenigma marked this conversation as resolved.
Show resolved Hide resolved

/// Constant values used within the runtime.
pub mod constants;
Expand Down Expand Up @@ -333,6 +334,7 @@ impl pallet_session::historical::Config for Runtime {
type FullIdentificationOf = pallet_staking::ExposureOf<Runtime>;
}

use pallet_election_provider_multi_phase::WeightInfo;
parameter_types! {
// phase durations. 1/4 of the last session for each.
pub const SignedPhase: u32 = EPOCH_DURATION_IN_SLOTS / 4;
Expand All @@ -345,11 +347,14 @@ parameter_types! {
// This formula is currently adjusted such that a typical solution will spend an amount equal
// to the base deposit for every 50 kb.
pub const SignedDepositByte: Balance = deposit(1, 0) / (50 * 1024);
pub SignedRewardBase: Balance = fee_for_submit_call::<
Runtime,
crate::constants::fee::WeightToFee,
crate::weights::pallet_election_provider_multi_phase::WeightInfo<Runtime>,
>(Perbill::from_perthousand(1500));
pub SignedRewardBase: Balance = fee_for_submit_call::<Runtime>(
// give 20% threshold.
sp_runtime::FixedU128::saturating_from_rational(12, 10),
// maximum weight possible.
weights::pallet_election_provider_multi_phase::WeightInfo::<Runtime>::submit(SignedMaxSubmissions::get()),
// assume a solution of 100kb length.
100 * 1024
);

// fallback: emergency phase.
pub const Fallback: pallet_election_provider_multi_phase::FallbackStrategy =
Expand Down
2 changes: 2 additions & 0 deletions utils/staking-miner/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.key
*.bin
47 changes: 47 additions & 0 deletions utils/staking-miner/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[package]
name = "staking-miner"
version = "0.9.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"

[dependencies]
codec = { package = "parity-scale-codec", version = "2.0.0" }
tokio = { version = "0.2", features = ["macros"] }
log = "0.4.11"
env_logger = "0.8.3"
structopt = "0.3.0"
jsonrpsee-ws-client = { version = "0.2.0", default-features = false, features = ["tokio02"] }
jsonrpsee-types = { version = "0.2.0" }
jsonrpsee = "=0.2.0-alpha.6"
serde_json = "1.0"
serde = "1.0.0"
hex = "0.4.0"
lazy_static = "1.4.0"
paste = "1.0.5"
thiserror = "1.0.0"

remote-externalities = { git = "https://github.com/paritytech/substrate", branch = "master" }

sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-npos-elections = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "master" }


frame-system = { git = "https://github.com/paritytech/substrate", branch = "master" }
frame-support = { git = "https://github.com/paritytech/substrate", branch = "master" }
frame-election-provider-support = { git = "https://github.com/paritytech/substrate", branch = "master" }
pallet-election-provider-multi-phase = { git = "https://github.com/paritytech/substrate", branch = "master" }
pallet-staking = { git = "https://github.com/paritytech/substrate", branch = "master" }
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "master" }

core-primitives = { package = "polkadot-core-primitives", path = "../../core-primitives" }

runtime-common = { package = "polkadot-runtime-common", path = "../../runtime/common" }
polkadot-runtime = { path = "../../runtime/polkadot" }
kusama-runtime = { path = "../../runtime/kusama" }
westend-runtime = { path = "../../runtime/westend" }

[dev-dependencies]
sp-version = { git = "https://github.com/paritytech/substrate", branch = "master" }
Loading