Skip to content

Add staker info tools to nucypher status#1259

Merged
cygnusv merged 15 commits intonucypher:masterfrom
cygnusv:stakers
Sep 10, 2019
Merged

Add staker info tools to nucypher status#1259
cygnusv merged 15 commits intonucypher:masterfrom
cygnusv:stakers

Conversation

@cygnusv
Copy link
Member

@cygnusv cygnusv commented Aug 24, 2019

If you have ideas to improve these commands (or new commands), don't be shy! Maybe I can add them.

Usage:

  • To see evolution of overall locked tokens of the network for next N days (default is 90):
    nucypher status locked-tokens --provider <GETH> --poa [--periods N]
    image

  • To see all stakers info (optionally a staking address can be supplied):
    nucypher status stakers --provider <GETH> --poa [--staking-address 0xfoobar]
    image

@codecov
Copy link

codecov bot commented Sep 4, 2019

Codecov Report

Merging #1259 into master will decrease coverage by 1.64%.
The diff coverage is 73.22%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1259      +/-   ##
==========================================
- Coverage   81.19%   79.55%   -1.65%     
==========================================
  Files          72       72              
  Lines       10018    10269     +251     
==========================================
+ Hits         8134     8169      +35     
- Misses       1884     2100     +216
Impacted Files Coverage Δ
nucypher/cli/characters/stake.py 81.36% <0%> (+0.5%) ⬆️
nucypher/cli/characters/ursula.py 64.9% <0%> (ø) ⬆️
nucypher/blockchain/economics.py 98.34% <100%> (ø) ⬆️
nucypher/cli/actions.py 74.25% <100%> (-2.4%) ⬇️
nucypher/utilities/sandbox/constants.py 98.36% <100%> (+0.14%) ⬆️
nucypher/blockchain/eth/token.py 88.96% <100%> (+0.07%) ⬆️
nucypher/blockchain/eth/registry.py 70.94% <100%> (-5.58%) ⬇️
nucypher/blockchain/eth/interfaces.py 70.91% <50%> (-1.07%) ⬇️
nucypher/blockchain/eth/agents.py 75.9% <55.88%> (-15.06%) ⬇️
nucypher/cli/deploy.py 51.65% <66.66%> (-23.35%) ⬇️
... and 22 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a1db783...7565c24. Read the comment docs.

@cygnusv cygnusv force-pushed the stakers branch 2 times, most recently from 5f10d15 to 52790ac Compare September 4, 2019 22:09
@cygnusv cygnusv changed the title [WIP] Staker info tools Add staker info tools to nucypher status Sep 4, 2019
@cygnusv cygnusv marked this pull request as ready for review September 4, 2019 22:11
@vepkenez
Copy link
Contributor

vepkenez commented Sep 4, 2019

I very much wish there was an --json option to get this data as json.


MAX_ROWS = 30
period_range = list(range(1, periods + 1))
token_counter = Counter({day: agent.get_all_locked_tokens(day) for day in period_range})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a reminder - this will print using only "active" workers/stakers

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can we get the non active stakers too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not trivial question. Because if you want to print period by period all stakes for all stakers - this will be not fast, because should do this manualy (calculate next period, get next staker, get locked tokens, sum or get next staker, get all sub stakes and then do all others summarization)
Also possible other solution if only current/next periods will be enough

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be derived by listing all the stakers that have ever connected to the network, then removing the currently active stakers?

Copy link
Contributor

@michwill michwill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Omg, this is insanely awesome!

@cygnusv
Copy link
Member Author

cygnusv commented Sep 5, 2019

@szotov Thanks, man! You've made very good points. I'll fix these issues now.

@vepkenez

I very much wish there was an --json option to get this data as json.

Yes! That's a wonderful idea, I don't know why I didn't think of that. I'll work on it.

Actively Staked Tokens ... {NU.from_nunits(staking_agent.get_global_locked_tokens())}
Published Stakes ......... {staking_agent.get_staker_population()}
Gas Price ................ {Web3.fromWei(blockchain.client.gas_price, 'gwei')} Gwei
Active Staking Ursulas ... {staking_agent.get_staker_population()}
Copy link
Member

@derekpierre derekpierre Sep 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This prints the same thing as the line before ('Published Stakes')? Rebase issue perhaps...?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think published stakes doesn't make much sense here, since there's a 1 to 1 relation between stake and stakers. I also changed the Active Staking Ursulas part since "Staking Ursulas" is not correct, and also get_staker_population() gives you all stakers, both active and inactive. Instead, I added a new functionality to get stakers partitioned by different confirmation status.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@derekpierre derekpierre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a prior comment about a problematic line in painting.py

Copy link
Member

@KPrasch KPrasch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome Work! Giving eyes to the network.... Approved with pending rebase over master. I'd love to see a follow-up PR that allows for JSON output generation, perhaps via composition on Moe.

@KPrasch KPrasch added CLI This effects the nucypher CLI Enhancement New or improved features labels Sep 9, 2019
Copy link
Member

@derekpierre derekpierre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff @cygnusv !! A couple comments about the units used for token balance output.

@cygnusv
Copy link
Member Author

cygnusv commented Sep 10, 2019

@vepkenez @KPrasch

I very much wish there was an --json option to get this data as json.

I'm afraid I'll have to leave that for a later PR. I lean now towards merging this soon and moving on into other work I don't want to grow stale (#1227).

@cygnusv cygnusv merged commit d6e842d into nucypher:master Sep 10, 2019
Copy link
Member

@arjunhassard arjunhassard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tools like this really level the playing field between large and small stakers! @cygnusv


stake = agent.owned_tokens(staker)
last_confirmed_period = agent.get_last_active_period(staker)
worker = agent.get_worker_from_staker(staker)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this function retrieve the addresses of multiple workers associated with the same staker/stake? Re: #1302

    def get_worker_from_staker(self, staker_address: str) -> str:
        worker = self.contract.functions.getWorkerFromStaker(staker_address).call()
        return to_checksum_address(worker)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our current model assumes a 1-to-1 relation between Workers and Stakers.

bucket_end = bucket[-1]

bucket_max = max([token_counter[period] for period in bucket])
bucket_min = min([token_counter[period] for period in bucket])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Visuals showing min, max and total tokens locked for each set of periods are great. Maybe a note explaining what min and max mean wouldn't go amiss?


MAX_ROWS = 30
period_range = list(range(1, periods + 1))
token_counter = Counter({day: agent.get_all_locked_tokens(day) for day in period_range})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be derived by listing all the stakers that have ever connected to the network, then removing the currently active stakers?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLI This effects the nucypher CLI Enhancement New or improved features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants