From 41549771e414df83eb810cca92d77a1c8ae58068 Mon Sep 17 00:00:00 2001 From: alfarok Date: Fri, 4 Nov 2022 10:11:03 -0400 Subject: [PATCH 1/6] add new RPC component filter that simply appends chain symbols to values (no rounding) --- components/utilities/filters.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/components/utilities/filters.js b/components/utilities/filters.js index 4586ba228c4a..e9e503996b42 100644 --- a/components/utilities/filters.js +++ b/components/utilities/filters.js @@ -46,6 +46,13 @@ module.exports = { setReturnValue(value.toString()); }, + Precise: function (value, network, setReturnValue) { + // Append symbol without rounding + value = `${value} ${values[network].symbol}`; + // Update value + setReturnValue(value); + }, + BlocksToDays: function (value, setReturnValue) { value = (value * 6) / 86400; // Update value From 693c8ae24f4b3d2ec3c7a3966c66463a9742bab2 Mon Sep 17 00:00:00 2001 From: alfarok Date: Fri, 4 Nov 2022 10:33:06 -0400 Subject: [PATCH 2/6] add new precision filter for RPC component --- components/RPC-Connection.jsx | 9 ++++--- components/utilities/filters.js | 4 ++- docs/learn/learn-staking-miner.md | 41 ++++++++++++++----------------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/components/RPC-Connection.jsx b/components/RPC-Connection.jsx index 96954c9fbfcf..64b0f0755945 100644 --- a/components/RPC-Connection.jsx +++ b/components/RPC-Connection.jsx @@ -1,6 +1,6 @@ import { useState, useEffect } from "react"; import { ApiPromise, WsProvider } from "@polkadot/api"; -import { HumanReadable, BlocksToDays } from "./utilities/filters"; +import { HumanReadable, Precise, BlocksToDays } from "./utilities/filters"; /* This component connects to the Polkadot/Kusama APIs and renders the response data. @@ -135,11 +135,14 @@ async function syncData(network, path, setReturnValue) { function applyFilter(value, filter, network, setReturnValue) { switch (filter) { case "humanReadable": - HumanReadable(value, network, setReturnValue) + HumanReadable(value, network, setReturnValue); break; + case "precise": + Precise(value, network, setReturnValue); + break; case "blocksToDays": BlocksToDays(value, setReturnValue); - break; + break; default: console.log("Ignoring unknown filter type"); return; diff --git a/components/utilities/filters.js b/components/utilities/filters.js index e9e503996b42..2651e79bd925 100644 --- a/components/utilities/filters.js +++ b/components/utilities/filters.js @@ -47,8 +47,10 @@ module.exports = { }, Precise: function (value, network, setReturnValue) { + // String to number + value = parseFloat(value); // Append symbol without rounding - value = `${value} ${values[network].symbol}`; + value = `${value / values[network].precision} ${values[network].symbol}`; // Update value setReturnValue(value); }, diff --git a/docs/learn/learn-staking-miner.md b/docs/learn/learn-staking-miner.md index a4f9b59a5b9c..322ed501d87b 100644 --- a/docs/learn/learn-staking-miner.md +++ b/docs/learn/learn-staking-miner.md @@ -16,20 +16,20 @@ discretion, as there is a risk of losing some funds. ::: -At the end of each era on Polkadot and Kusama, using [NPoS](learn-phragmen), a new set of validators -must be elected based on the nominator preferences. This is a computationally intensive process, hence -the usage of the term "mining" for computing the solution. The validators use -[off-chain workers](https://docs.substrate.io/reference/how-to-guides/offchain-workers/) to -compute the result and submit a transaction to propose the set of winners. This can also be delegated -to stand-alone programs, whose task is to mine the optimal solution. Staking miners compete with each other -to produce election solutions which consist of a validator set, stake distribution across that set, and a score -indicating how optimal the solution is. Staking miners run any given staking algorithms (as of now, -sequential Phragmén or PhragMMS, subject to change if improved algorithms are introduced) to produce results, -which are 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 the least covers the -transaction fee, and the bond is returned to the account. [The bond and the fee](learn-staking-miner#deposit-and-reward-mechanics) are lost if the solution -is invalid. - +At the end of each era on Polkadot and Kusama, using [NPoS](learn-phragmen), a new set of validators +must be elected based on the nominator preferences. This is a computationally intensive process, +hence the usage of the term "mining" for computing the solution. The validators use +[off-chain workers](https://docs.substrate.io/reference/how-to-guides/offchain-workers/) to compute +the result and submit a transaction to propose the set of winners. This can also be delegated to +stand-alone programs, whose task is to mine the optimal solution. Staking miners compete with each +other to produce election solutions which consist of a validator set, stake distribution across that +set, and a score indicating how optimal the solution is. Staking miners run any given staking +algorithms (as of now, sequential Phragmén or PhragMMS, subject to change if improved algorithms are +introduced) to produce results, which are 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 the least covers the transaction fee, and the bond is returned to the account. +[The bond and the fee](learn-staking-miner#deposit-and-reward-mechanics) are lost if the solution is +invalid. Staking miner uses a pallet called `pallet_election_provider_multi_phase` and can only produce solutions during the @@ -134,15 +134,10 @@ to receiving a `SignedRewardBase`. ### Deposit Current deposit(`SignedDepositBase`) is -{{ polkadot: :polkadot }} -{{ kusama: :kusama }} -which is a fixed amount. - -Current deposit per byte(`SignedDepositByte`) is -{{ polkadot: 0.0000097656 DOT :polkadot }}{{ kusama: 0.00000032551 KSM :kusama }} and the total is -variable depending on the size of the solution data. For example a solution weighing 200KB would -yield {{ polkadot: 200 x 0.0000097656 = **0.00195312 DOT**. :polkadot }} -{{ kusama: 200 x 0.00000032551 = **0.000065102 KSM**. :kusama }} +{{ polkadot: :polkadot }} +{{ kusama: :kusama }} +and the total is variable depending on the size of the solution data. For example a solution +weighing 200KB would yield {{ polkadot: 200 x 0.0000097656 = **0.00195312 DOT**. :polkadot }} And the weight deposit(`SignedDepositWeight`) is currently set to `0` and has no effect. From fb9bc421432f395f855a91efd6aaaf64acec57de Mon Sep 17 00:00:00 2001 From: alfarok Date: Fri, 4 Nov 2022 10:40:58 -0400 Subject: [PATCH 3/6] comment --- components/utilities/filters.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/utilities/filters.js b/components/utilities/filters.js index 2651e79bd925..99a18495ec8a 100644 --- a/components/utilities/filters.js +++ b/components/utilities/filters.js @@ -49,7 +49,7 @@ module.exports = { Precise: function (value, network, setReturnValue) { // String to number value = parseFloat(value); - // Append symbol without rounding + // Apply precision and append symbol without additional rounding value = `${value / values[network].precision} ${values[network].symbol}`; // Update value setReturnValue(value); From a212af377a83bed6230c4a07be6bfe1fdcfb702e Mon Sep 17 00:00:00 2001 From: alfarok Date: Fri, 4 Nov 2022 10:43:42 -0400 Subject: [PATCH 4/6] restore deleted section --- docs/learn/learn-staking-miner.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/learn/learn-staking-miner.md b/docs/learn/learn-staking-miner.md index 322ed501d87b..894748dca7ad 100644 --- a/docs/learn/learn-staking-miner.md +++ b/docs/learn/learn-staking-miner.md @@ -134,6 +134,11 @@ to receiving a `SignedRewardBase`. ### Deposit Current deposit(`SignedDepositBase`) is +{{ polkadot: :polkadot }} +{{ kusama: :kusama }} +which is a fixed amount. + +Current deposit per byte(`SignedDepositByte`) is {{ polkadot: :polkadot }} {{ kusama: :kusama }} and the total is variable depending on the size of the solution data. For example a solution From 6f1f0f3043dac227864420ed80d2b08273c13492 Mon Sep 17 00:00:00 2001 From: alfarok Date: Fri, 4 Nov 2022 10:57:45 -0400 Subject: [PATCH 5/6] clean up --- docs/learn/learn-staking-miner.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/learn/learn-staking-miner.md b/docs/learn/learn-staking-miner.md index 894748dca7ad..cb342d3ab3f9 100644 --- a/docs/learn/learn-staking-miner.md +++ b/docs/learn/learn-staking-miner.md @@ -141,8 +141,11 @@ which is a fixed amount. Current deposit per byte(`SignedDepositByte`) is {{ polkadot: :polkadot }} {{ kusama: :kusama }} -and the total is variable depending on the size of the solution data. For example a solution -weighing 200KB would yield {{ polkadot: 200 x 0.0000097656 = **0.00195312 DOT**. :polkadot }} +and the total is variable depending on the size of the solution data. For example, a solution +weighing 200KB would require a (200 x +{{ polkadot: ) :polkadot }} +{{ kusama: ) :kusama }} +deposit for the given payload. And the weight deposit(`SignedDepositWeight`) is currently set to `0` and has no effect. From f973e64186a2d59c46ebcb73d18a8fb9467bf628 Mon Sep 17 00:00:00 2001 From: alfarok Date: Wed, 9 Nov 2022 09:54:39 -0500 Subject: [PATCH 6/6] restore hard-coded math example --- docs/learn/learn-staking-miner.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/docs/learn/learn-staking-miner.md b/docs/learn/learn-staking-miner.md index cb342d3ab3f9..32eaf5d9c1c3 100644 --- a/docs/learn/learn-staking-miner.md +++ b/docs/learn/learn-staking-miner.md @@ -142,10 +142,8 @@ Current deposit per byte(`SignedDepositByte`) is {{ polkadot: :polkadot }} {{ kusama: :kusama }} and the total is variable depending on the size of the solution data. For example, a solution -weighing 200KB would require a (200 x -{{ polkadot: ) :polkadot }} -{{ kusama: ) :kusama }} -deposit for the given payload. +weighing 200KB would yield {{ polkadot: 200 x 0.0000097656 = **0.00195312 DOT**. :polkadot }} +{{ kusama: 200 x 0.00000032551 = **0.000065102 KSM**. :kusama }} And the weight deposit(`SignedDepositWeight`) is currently set to `0` and has no effect.