3

Using substrate-interface I'm trying to get the amount of DOT in staking for non-active validators, those that are waiting. I can get the active validators' amount by using the storage_function ErasStakers, but I can't find any for the rest of the validators.

I get the {'total': 0, 'own': 0, 'others': []} but just for the active stakers of the current era (Staking:ActiveEra):

active_validator = substrate.query_map(
    module='Staking',
    storage_function='ErasStakers',
    page_size=300,
    params=[era_index]
)

Is there any call or combination of calls I could use to get the staked amount for the full set of validators (active+waiting)?

1 Answer 1

2

I believe you will need to do a few queries here to get the data you want:

  1. Get all validator stash accounts from iterating over the Validators storage map
  2. Get all the controller accounts by mapping the validator stash to the validator controller via the Bonded storage map
  3. Get the amount of tokens staked for that validator from the Ledger storage map

From there, you need to add up all the values to get the total amount staked.

6
  • github.com/paritytech/substrate-debug-kit/blob/master/… may also take Kian's offline-election tool as reference
    – Ron
    Apr 21, 2022 at 14:13
  • I'm not sure if I follow your idea, sorry. As an example: - Starting with a random active validator's stash account: JACO(V05), "148CkH8YBzA1pbudK1bMo2zUMHZwbucBVH8s3utwTS687UiR". It has 2.04 MDOT in staking. - Its controller (according to Staking:Bonded) is "148CkH8YBzA1pbudK1bMo2zUMHZwbucBVH8s3utwTS687UiR" with 570.9 DOT in it (500 DOT blocked for itself) - And passing that controller account to Staking:Ledger I got those 500 DOT, not the 2.04 MDOT. I'll keep trying, perhaps I'm missing something. Thanks!
    – Saccharo
    Apr 22, 2022 at 7:52
  • JACO does not have 2.04 MDOT personally in staking. That 2.04 MDOT number comes from all of the nominations that JACO has accumulated, specifically from being active. So for non-active validators, their number will always be 0, since no stake will be used to back them in an era where they are not active.
    – Shawn Tabrizi
    Apr 22, 2022 at 8:30
  • Exactly, that was my original question. Is there a way to know the DOT that a non-active validator for the current era has from its own and other's stake? I guess there's a way because the system must know that the validator 298th has less than the 297th and it doesn't deserve to be validating
    – Saccharo
    Apr 22, 2022 at 8:49
  • 1
    I believe the staking system is more complex than you are making it out to be. The distribution of funds is calculated using a Phragmen Election Algorithm, and the amount of stake behind users is dynamically adjusted at the time of calculation. If you are not "active", then it does not really make sense to look up a number like what you are describing. See videos like: youtube.com/watch?v=MjOvVhc1oXw
    – Shawn Tabrizi
    Apr 22, 2022 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.