Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R4R: Implement fee distribution RESTful endpoints #3460

Merged
merged 29 commits into from
Feb 5, 2019

Conversation

alessio
Copy link
Contributor

@alessio alessio commented Jan 31, 2019

[@alessio]

[@rigelrozanski ]

  • Distribution querier endpoints change: "all_delegation_rewards" -> "total_delegation_rewards"
  • New query endpoint "delegator_validators"

Closes: #3476
Closes: #2358
Closes: #3490


  • Linked to github-issue with discussion and accepted design OR link to spec that describes this work.
  • Wrote tests
  • Updated relevant documentation (docs/)
  • Added entries in PENDING.md with issue #
  • rereviewed Files changed in the github PR explorer

For Admin Use:

  • Added appropriate labels to PR (ex. wip, ready-for-review, docs)
  • Reviewers Assigned
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

@codecov
Copy link

codecov bot commented Jan 31, 2019

Codecov Report

Merging #3460 into develop will increase coverage by 1.72%.
The diff coverage is 31.25%.

@@             Coverage Diff             @@
##           develop    #3460      +/-   ##
===========================================
+ Coverage    52.95%   54.67%   +1.72%     
===========================================
  Files          137      139       +2     
  Lines        10746    10375     -371     
===========================================
- Hits          5691     5673      -18     
+ Misses        4705     4343     -362     
- Partials       350      359       +9

@alessio alessio requested a review from sabau January 31, 2019 04:18
@faboweb
Copy link
Contributor

faboweb commented Jan 31, 2019

Tested:
My account: cosmos1dhcyvz8vltlkstn53al76l6wmzrxv0s02teyzf
Validated to majority validator cosmosvaloper1dhcyvz8vltlkstn53al76l6wmzrxv0s00ld3w6

GET /distribution/parameters seems to work

GET /distribution/pool returns { "community_pool": null }

GET /distribution/delegators/cosmos1dhcyvz8vltlkstn53al76l6wmzrxv0s02teyzf/rewards returns null

GET /distribution/delegators/cosmos1dhcyvz8vltlkstn53al76l6wmzrxv0s02teyzf/rewards/cosmosvaloper1dhcyvz8vltlkstn53al76l6wmzrxv0s00ld3w6 returns null

@alessio alessio force-pushed the alessio/2358-fee-dist-rest branch 2 times, most recently from 51b2b11 to 7e5e0c2 Compare January 31, 2019 23:46
@alessio
Copy link
Contributor Author

alessio commented Jan 31, 2019

/distribution/pool (GET) is supposed to return val_pool and val_accum, which resemble some sort of validators specific information. I couldn't find any reference in the code other than the following results returned by grep:

alessio@bangalter:~/.../cosmos/cosmos-sdk$ grep -rw accum
CHANGELOG.md:  * [\#3181](https://github.com/cosmos/cosmos-sdk/issues/3181) Correctly reset total accum update height and jailed-validator bond height / unbonding height on export-for-zero-height
CHANGELOG.md: * [\#2573](https://github.com/cosmos/cosmos-sdk/issues/2573) [x/distribution] add accum invariance
CHANGELOG.md:      * [x/distribution] Add sanity checks for incorrect accum / total accum relations
CHANGELOG.md:    * #2573 [x/distribution] add accum invariance
CHANGELOG.md:    * #2573 [x/distribution] accum invariance bugfix
docs/spec/distribution/messages.md:### Update total validator accum
docs/spec/distribution/messages.md:The total amount of validator accum must be calculated in order to determine
docs/spec/distribution/messages.md:block. The accum is always additive to the existing accum. This term is to be
docs/spec/distribution/messages.md:The total amount of delegator accum must be updated in order to determine the
docs/spec/distribution/messages.md:other delegators for that validator. The accum is always additive to
docs/spec/distribution/messages.md:the existing accum. This term is to be updated each time a
docs/spec/distribution/messages.md:    accum = blocks * vdTokens
docs/spec/distribution/messages.md:    withdrawalTokens := g.Pool * accum / g.TotalValAccum 
docs/spec/distribution/messages.md:    accum = delegatorShares * blocks 
docs/spec/distribution/messages.md:    withdrawalTokens := vi.Pool * accum / vi.TotalDelAccum
docs/spec/distribution/messages.md:    vi.TotalDelAccum -= accum
docs/spec/distribution/messages.md:    vi.TotalDelAccum -= accum
docs/spec/distribution/state.md:    TotalValAccumUpdateHeight  int64    // last height which the total validator accum was updated
docs/spec/distribution/state.md:    TotalValAccum              sdk.Dec  // total valdator accum held by validators
docs/spec/distribution/state.md:    TotalDelAccumUpdateHeight  int64    // last height which the total delegator accum was updated
client/lcd/swagger-ui/swagger.yaml:      accum:
client/lcd/swagger-ui/swagger.yaml:      accum:
x/staking/keeper/val_state_change.go:			// This hook is extremely useful, otherwise lazy accum bugs will be difficult to solve.

@cwgoes can you shed some light on this please? Either something is missing here, or frontend ICS24 specs need update. Note that presently /distribution/pool returns the following:

{
  "community_pool": [
    {
      "denom": "stake",
      "amount": "1932.480000000000000000"
    }
  ]
}

@alessio
Copy link
Contributor Author

alessio commented Feb 1, 2019

All GET endpoints are now complete. Please test @cosmos/cosmos-ui.

@faboweb @fedekunze @sabau Note that specs are changed, @cwgoes reviewed and updated them. I'd suggest you regenerate swagger docs and validate endpoints compliance against the new interfaces.

Please keep me posted

@alessio alessio assigned alexanderbez and unassigned alexanderbez Feb 1, 2019
@alessio alessio changed the title WIP: Implement fee distribution RESTful endpoints R4R: Implement fee distribution RESTful endpoints Feb 2, 2019
@alessio
Copy link
Contributor Author

alessio commented Feb 2, 2019

Progress tracking:

Endpoint GET POST
/distribution/delegators/{delegatorAddr}/rewards
/distribution/delegators/{delegatorAddr}/rewards/{validatorAddr}
/distribution/delegators/{delegatorAddr}/withdraw_address
/distribution/validators/{validatorAddr}
N/A
/distribution/validators/{validatorAddr}/rewards
/distribution/parameters
N/A
/distribution/outstanding_rewards
N/A

@alessio
Copy link
Contributor Author

alessio commented Feb 2, 2019

How to test the PR

  1. Get started
$ gaiad init --moniker=[YOUR_MONIKER_HERE]
  1. open your genesis.json, then look up inflation in the mint params:
    "mint": {
      "minter": {
        "inflation": "10000.000000000000000000",

inflation needs to be very high. I tested with 10000.000000000000000000 and rewards popped up pretty quickly.

Now, modify inflation_rate_change and inflation_max according to your inflation:

      "params": {
        "mint_denom": "stake",
        "inflation_rate_change": "10000.000000000000000000",
        "inflation_max": "20000.000000000000000000",
  1. create a key with gaiacli:
$ gaiacli keys add foo
  1. Add foo to genesis.json and give it lots of coins:
$ gaiad add-genesis-account foo 10000000stake   # 10 mln
  1. Generate a gentx. Still, delegate lots of coins:
$ gaiad gentx --name=foo --amount=500000stake   # 0.5 mln
  1. Collect the gentx and start gaiad
$ gaiad collect-gentxs
$ gaiad start
  1. Start the REST server:
$ gaiacli rest-server

@sabau
Copy link
Contributor

sabau commented Feb 2, 2019

just to go quicker I scripted the boot process if anyone is interested in playing on the parameters

kickoff.sh

@sabau
Copy link
Contributor

sabau commented Feb 2, 2019

I haven't finished all the rounds. Generally the errors and some return values are plain strings so not json parsable.

The behaviour seems to work but I need a bit more time

Regarding the errors (null string or plain text anyway) I think is something not related to this PR but generic.

@jackzampolin
Copy link
Member

@sabau We are working on better error returns over in this PR: #3451

@alessio
Copy link
Contributor Author

alessio commented Feb 2, 2019

@jackzampolin I think Karoly is talking about JSON error responses. I'll open a PR about it

@sabau
Copy link
Contributor

sabau commented Feb 2, 2019

Exaclty, I imagine everything produced by an API to be consumable by a client that interpret only that format (let it be xml, json, ...). If an error occurs it shuold be interpretable too, otherwise every client will have to implement those special cases

@@ -0,0 +1,143 @@
package common
Copy link
Contributor

Choose a reason for hiding this comment

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

nice 👍 common module

Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

Look great @alessio -- I left a minor comment, but overall it looks solid. The localnet CI task is failing. Also, correct me if I'm wrong, but there aren't any LCD tests, so have all the endpoints been tested?

x/distribution/client/common/common.go Outdated Show resolved Hide resolved
@sabau
Copy link
Contributor

sabau commented Feb 4, 2019

Would be great if you can add unit tests (GET and POST) for the happy paths at the endpoint:
/distribution/delegators/{delegatorAddr}/rewards/{validatorAddr}

If you are running out of time I can ask @faboweb if I can borrow some Voyager hours to write unit tests to cover the others.

Manually so far so good!

Alessio Treglia added 2 commits February 4, 2019 12:34
@jackzampolin jackzampolin merged commit a2b73c8 into develop Feb 5, 2019
@jackzampolin jackzampolin deleted the alessio/2358-fee-dist-rest branch February 5, 2019 00:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants