-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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: Redelegation Querier #2559
Changes from 12 commits
52325f8
da690ce
75feb13
c4ff53b
5b5f421
bfe6994
b60db92
73df9bc
2285ee9
9b3a0fb
a344815
81cf2a6
fa18461
482b664
16281b4
93fd680
5fd59ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,8 +29,12 @@ BREAKING CHANGES | |
FEATURES | ||
|
||
* Gaia REST API (`gaiacli advanced rest-server`) | ||
<<<<<<< HEAD | ||
* [gaia-lite] [\#2182] Added LCD endpoint for querying redelegations | ||
======= | ||
* [gov] [\#2479](https://github.com/cosmos/cosmos-sdk/issues/2479) Added governance parameter | ||
query REST endpoints. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? |
||
>>>>>>> develop | ||
|
||
* Gaia CLI (`gaiacli`) | ||
* [gov][cli] [\#2479](https://github.com/cosmos/cosmos-sdk/issues/2479) Added governance | ||
|
@@ -46,6 +50,8 @@ FEATURES | |
* [app] \#2791 Support export at a specific height, with `gaiad export --height=HEIGHT`. | ||
* [app] \#2812 Support export alterations to prepare for restarting at zero-height | ||
|
||
* [\#2182] [x/stake] Added querier for querying a single redelegation | ||
|
||
* SDK | ||
* [simulator] \#2682 MsgEditValidator now looks at the validator's max rate, thus it now succeeds a significant portion of the time | ||
* [core] \#2775 Add deliverTx maximum block gas limit | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -586,19 +586,23 @@ func TestBonding(t *testing.T) { | |
require.Len(t, delegatorDels, 1) | ||
require.Equal(t, "30.0000000000", delegatorDels[0].GetShares().String()) | ||
|
||
redelegation := getRedelegations(t, port, addr, operAddrs[0], operAddrs[1]) | ||
require.Len(t, redelegation, 1) | ||
require.Equal(t, "30", redelegation[0].Balance.Amount.String()) | ||
|
||
delegatorUbds := getDelegatorUnbondingDelegations(t, port, addr) | ||
require.Len(t, delegatorUbds, 1) | ||
require.Equal(t, "30", delegatorUbds[0].Balance.Amount.String()) | ||
|
||
delegatorReds := getDelegatorRedelegations(t, port, addr) | ||
delegatorReds := getRedelegations(t, port, addr, nil, nil) | ||
require.Len(t, delegatorReds, 1) | ||
require.Equal(t, "30", delegatorReds[0].Balance.Amount.String()) | ||
|
||
validatorUbds := getValidatorUnbondingDelegations(t, port, operAddrs[0]) | ||
require.Len(t, validatorUbds, 1) | ||
require.Equal(t, "30", validatorUbds[0].Balance.Amount.String()) | ||
|
||
validatorReds := getValidatorRedelegations(t, port, operAddrs[0]) | ||
validatorReds := getRedelegations(t, port, nil, operAddrs[0], nil) | ||
require.Len(t, validatorReds, 1) | ||
require.Equal(t, "30", validatorReds[0].Balance.Amount.String()) | ||
|
||
|
@@ -1043,16 +1047,31 @@ func getDelegatorUnbondingDelegations(t *testing.T, port string, delegatorAddr s | |
return ubds | ||
} | ||
|
||
func getDelegatorRedelegations(t *testing.T, port string, delegatorAddr sdk.AccAddress) []stake.Redelegation { | ||
res, body := Request(t, port, "GET", fmt.Sprintf("/stake/delegators/%s/redelegations", delegatorAddr), nil) | ||
require.Equal(t, http.StatusOK, res.StatusCode, body) | ||
func getRedelegations(t *testing.T, port string, delegatorAddr sdk.AccAddress, srcValidatorAddr sdk.ValAddress, dstValidatorAddr sdk.ValAddress) []stake.Redelegation { | ||
var res *http.Response | ||
var body string | ||
|
||
endpoint := "/stake/redelegations?" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still think this is a terrible design, we should only add the query parameters to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The thing I don't like about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would agree with @fedekunze here. I don't think how we have the data structured internally matters to users. Presenting the data in a way that is logically consistent (delegators have redelegations) is a great idea. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are /stake/delegators/<>/redelegations vs /stake/validators/<>/redelegations? I think over-emphasis on the URL design of API endpoints often leads to premature design constraints that end up causing more headache down the line. It is simpler to model the API after what is modeled in the implementation. REST isn't just about pretty URLs... there's nothing wrong with query parameters, esp given a context where we will want to provide filters etc. I favor Sunny's approach here, it's faster to execute and less brittle going into the future. The end users here are developers who can deal with query parameters. We're not talking about website URLs, which is a different story. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think simple to implement is not what we want with an API. An API should be consistent for quiet some time so developers don't need to adjust to constant changes (this is frustrating from experience). We should come up with a design that reflects the expectation of the developers that want to use the API. Let's invite more of them to stakeholder meetings and discuss together with them the API design. |
||
|
||
if !delegatorAddr.Empty() { | ||
endpoint += fmt.Sprintf("delegator=%s&", delegatorAddr) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consider using https://golang.org/pkg/strings/#Builder There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm interesting - yeah seems like it would make the code a bit smaller - but I don't see builders often so might just be more confusing for new devs... but then again maybe we should all learn! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think in this situation, it is simple enough that we can just use the |
||
} | ||
if !srcValidatorAddr.Empty() { | ||
endpoint += fmt.Sprintf("validator_from=%s&", srcValidatorAddr) | ||
} | ||
if !dstValidatorAddr.Empty() { | ||
endpoint += fmt.Sprintf("validator_to=%s&", dstValidatorAddr) | ||
} | ||
|
||
var reds []stake.Redelegation | ||
res, body = Request(t, port, "GET", endpoint, nil) | ||
|
||
err := cdc.UnmarshalJSON([]byte(body), &reds) | ||
require.Equal(t, http.StatusOK, res.StatusCode, body) | ||
|
||
var redels []stake.Redelegation | ||
err := cdc.UnmarshalJSON([]byte(body), &redels) | ||
require.Nil(t, err) | ||
|
||
return reds | ||
return redels | ||
} | ||
|
||
func getBondingTxs(t *testing.T, port string, delegatorAddr sdk.AccAddress, query string) []tx.Info { | ||
|
@@ -1254,17 +1273,6 @@ func getValidatorUnbondingDelegations(t *testing.T, port string, validatorAddr s | |
return ubds | ||
} | ||
|
||
func getValidatorRedelegations(t *testing.T, port string, validatorAddr sdk.ValAddress) []stake.Redelegation { | ||
res, body := Request(t, port, "GET", fmt.Sprintf("/stake/validators/%s/redelegations", validatorAddr.String()), nil) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should stay the same, see comment above |
||
require.Equal(t, http.StatusOK, res.StatusCode, body) | ||
|
||
var reds []stake.Redelegation | ||
err := cdc.UnmarshalJSON([]byte(body), &reds) | ||
require.Nil(t, err) | ||
|
||
return reds | ||
} | ||
|
||
// ============= Governance Module ================ | ||
|
||
func getDepositParam(t *testing.T, port string) gov.DepositParams { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -753,15 +753,25 @@ paths: | |
description: Invalid delegator address | ||
500: | ||
description: Internal Server Error | ||
/stake/delegators/{delegatorAddr}/redelegations: | ||
/stake/redelegations: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why would you want to get all the redelegations in the state ? there's no use case for that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe not in Voyager? But that totally seems like something some block explorer might want. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but you can still go through the list of validators and do that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and through the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Either through that or with the |
||
parameters: | ||
- in: path | ||
name: delegatorAddr | ||
description: Bech32 AccAddress of Delegator | ||
required: true | ||
type: string | ||
- in: query | ||
name: delegator | ||
description: Bech32 AccAddress of Delegator | ||
required: false | ||
type: string | ||
- in: query | ||
name: validator_from | ||
description: Bech32 ValAddress of SrcValidator | ||
required: false | ||
type: string | ||
- in: query | ||
name: validator_to | ||
description: Bech32 ValAddress of DstValidator | ||
required: false | ||
type: string | ||
get: | ||
summary: Get all redelegations from a delegator | ||
summary: Get all redelegations (filter by query params) | ||
tags: | ||
- ICS21 | ||
produces: | ||
|
@@ -774,8 +784,6 @@ paths: | |
items: | ||
type: object | ||
"$ref": "#/definitions/Redelegation" | ||
400: | ||
description: Invalid delegator address | ||
500: | ||
description: Internal Server Error | ||
/stake/delegators/{delegatorAddr}/validators: | ||
|
@@ -998,30 +1006,6 @@ paths: | |
description: Invalid validator address | ||
500: | ||
description: Internal Server Error | ||
/stake/validators/{validatorAddr}/redelegations: | ||
parameters: | ||
- in: path | ||
name: validatorAddr | ||
description: Bech32 OperatorAddress of validator | ||
required: true | ||
type: string | ||
get: | ||
summary: Get all outgoing redelegations from a validator | ||
tags: | ||
- ICS21 | ||
produces: | ||
- application/json | ||
responses: | ||
200: | ||
description: OK | ||
schema: | ||
type: array | ||
items: | ||
$ref: "#/definitions/Redelegation" | ||
400: | ||
description: Invalid validator address | ||
500: | ||
description: Internal Server Error | ||
/stake/pool: | ||
get: | ||
summary: Get the current state of the staking pool | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have been in breaking changes cc: @sunnya97 @jackzampolin. I'll update it