Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
4 changes: 2 additions & 2 deletions components/RPC-Connection.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState, useEffect } from "react";
import { ApiPromise, WsProvider } from "@polkadot/api";
import { HumanReadable, BlocksToDays} from "./utilities/filters";
import { HumanReadable, BlocksToDays } from "./utilities/filters";

/*
This component connects to the Polkadot/Kusama APIs and renders the response data.
Expand Down Expand Up @@ -139,7 +139,7 @@ function applyFilter(value, filter, network, setReturnValue) {
break;
case "blocksToDays":
BlocksToDays(value, setReturnValue);
break;
break;
Comment thread
emresurmeli marked this conversation as resolved.
default:
console.log("Ignoring unknown filter type");
return;
Expand Down
10 changes: 5 additions & 5 deletions components/utilities/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ const Statemint = "statemint";

const values = {
polkadot: {
precision: 1e10,
symbol: "DOT",
precision: 1e10,
symbol: "DOT",
},
kusama: {
precision: 1e12,
symbol: "KSM",
kusama: {
precision: 1e12,
symbol: "KSM",
},
statemint: {
precision: 1e10,
Expand Down
42 changes: 34 additions & 8 deletions docs/learn/learn-staking-miner.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ compete with each other to produce election solutions which consist of a validat
distribution across that set, and a score indicating how optimal the solution is. Staking miners run
the any given staking algortihms(as of now, sequential Phragmén or PhragMMS, this is subject to
change if improved algorithms are introduced) to produce results, and the result is then sent as a
transaction to the relay chain via a normal signed extrinsic. The transaction requires a bond, and a
transaction fee. The best solution is rewarded which in the least covers the transaction fee, and
the bond is returned to the account. If the solution is not valid, the bond and the fee are lost.
transaction to the relay chain via a normal signed extrinsic. The transaction requires a deposit,
and a transaction fee. The best solution is rewarded which in the least covers the transaction fee,
and the deposit is returned to the account. If the solution is not valid, the
[deposit and the fee](learn-staking-miner#deposit-and-reward-mechanics) are lost.

Staking miner uses a pallet called `pallet_election_provider_multi_phase` and can only produce
solutions during the
Expand All @@ -35,11 +36,13 @@ starts, only the off-chain workers can provide election results.

Running the staking miner requires passing the seed of a funded account in order to pay the fees for
the transactions that will be sent. The same account's balance is used to reserve deposits as well.
The best solution in each round is rewarded. All correct solutions will get their bond back and the
ones that submit invalid solutions will lose their bond.
The best solution in each round is rewarded. All correct solutions will get their deposit back and
the ones that submit invalid solutions will lose their deposit.

## NPoS election optimization

![NPoS election optimization](../assets/staking-miner/NPoS-election-optimization.png)
Comment thread
emresurmeli marked this conversation as resolved.

A basic election solution is a simple distribution of stake across validators, but this can be
optimized for better distribution equaling a higher security score. The staking miner does not act
as a validator and focuses solely on the election result and optimization of the solution. It
Expand All @@ -48,7 +51,28 @@ order to submit solutions to the NPoS election. When the correct time comes, it
solution and submits it to the chain. The default miner algorithm is sequential Phragmén with a
configurable number of balancing iterations that improve the score.

![NPoS election optimization](../assets/staking-miner/NPoS-election-optimization.png)
## Deposit and reward mechanics

The staking miners are required to pay a deposit in order to post their solutions. The deposit is a
sum of the `SignedDepositBase`, which is a fixed amount and `SignedDepositByte`, a variable amount
per KB of solution data. All good solutions are subject to recieving a `SignedRewardBase`.
Comment thread
emresurmeli marked this conversation as resolved.
Outdated
Comment thread
emresurmeli marked this conversation as resolved.
Outdated

Current deposit(**SignedDepositBase**) is
{{ polkadot: <RPC network="polkadot" path="consts.electionProviderMultiPhase.signedDepositBase" defaultValue={16} filter="humanReadable"/> :polkadot }}
{{ kusama: <RPC network="kusama" path="consts.electionProviderMultiPhase.signedDepositBase" defaultValue={16} filter="humanReadable"/> :kusama }}

Current deposit per byte(**SignedDepositByte**) is
{{ polkadot: <RPC network="polkadot" path="consts.electionProviderMultiPhase.signedDepositByte" defaultValue={16} filter="humanReadable"/> :polkadot }}
{{ kusama: <RPC network="kusama" path="consts.electionProviderMultiPhase.signedDepositByte" defaultValue={16} filter="humanReadable"/> :kusama }}

Current rewards(**SignedRewardBase**) is
{{ polkadot: <RPC network="polkadot" path="consts.electionProviderMultiPhase.signedRewardBase" defaultValue={16} filter="humanReadable"/> :polkadot }}
{{ kusama: <RPC network="kusama" path="consts.electionProviderMultiPhase.signedRewardBase" defaultValue={16} filter="humanReadable"/> :kusama }}
Comment thread
emresurmeli marked this conversation as resolved.
Outdated

Once the staking miner with a good solution is ready to be rewarded,
[`finalize_signed_phase_accept_solution`](https://github.com/paritytech/substrate/blob/master/frame/election-provider-multi-phase/src/signed.rs#L453-L474)
Comment thread
emresurmeli marked this conversation as resolved.
Outdated
Comment thread
emresurmeli marked this conversation as resolved.
Outdated
will be called, which will submit the solution to the queue of solutions, reward the staking miner
and refund the deposit.
Comment thread
emresurmeli marked this conversation as resolved.
Outdated

## Signed Phase of the election pallet

Expand Down Expand Up @@ -89,10 +113,10 @@ Upon arrival of a new solution:

1. If the queue is not full, it is stored in the appropriate sorted index.
2. If the queue is full but the submitted solution is better than one of the queued ones, the worse
solution is discarded, the bond of the outgoing solution is returned, and the new solution is
solution is discarded, the deposit of the outgoing solution is returned, and the new solution is
stored in the correct index.
3. If the queue is full and the solution is not an improvement compared to any of the queued ones,
it is instantly rejected and no bond is reserved.
it is instantly rejected and no deposit is reserved.

Upon the end of the signed phase, no more solutions can be submitted and the solutions in the queue
will be checked using
Expand Down Expand Up @@ -124,3 +148,5 @@ resources section below.

- [Election Pallet definition](https://crates.parity.io/pallet_election_provider_multi_phase/index.html)
- [Staking Miner repository](https://github.com/paritytech/staking-miner-v2)
- [Signed phase parameter configuration on Polkadot](https://github.com/paritytech/polkadot/blob/master/runtime/polkadot/src/lib.rs#L389:L397)
Comment thread
emresurmeli marked this conversation as resolved.
Outdated