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: Staking Querier pt1 #2249

Merged
merged 64 commits into from
Sep 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
2ca7e61
Cherry picked commits from prev branch
Aug 24, 2018
5e285e1
Added new keepers for querier functionalities
Aug 24, 2018
ec13fbe
Renaming
Aug 24, 2018
3eacdfa
Fixed gov errors and messages
Aug 24, 2018
682008f
Added Querier to stake and app
Aug 27, 2018
ceae374
Update delegation keepers
Aug 27, 2018
9ba98ab
REST Queriers not working
Aug 27, 2018
8bf6b2c
Fix marshalling error
Aug 27, 2018
cd0ca86
Querier tests working
Aug 28, 2018
01304c9
Pool and params working
Aug 28, 2018
7889374
sdk.NewCoin for test handler
Aug 28, 2018
d3b6c3e
Refactor and renaming
Aug 28, 2018
5fb1547
Update LCD queries and added more tests for queriers
Aug 29, 2018
8cfc507
use sdk.NewCoin
Aug 29, 2018
044b851
Delegator summary query and tests
Aug 29, 2018
685f05a
Added more tests for keeper
Aug 29, 2018
6d9c8b7
Update PENDING.md
Aug 29, 2018
3f5ad5f
Merge branch 'develop' into fedekunze/2009-queriers-staking
fedekunze Aug 29, 2018
f6aed4e
Update stake rest query
Aug 29, 2018
b9b04a0
Format and replaced panics for sdk.Error
Aug 30, 2018
2852b4a
Refactor and addressed comments from Sunny and Aleks
Aug 31, 2018
128deb5
Merge branch 'develop' into fedekunze/2009-queriers-staking
fedekunze Aug 31, 2018
e93a937
Fixed some of the errors produced by addr type change
Aug 31, 2018
80cd207
Fixed remaining errors
Aug 31, 2018
c83172d
Updated and fixed lite tests
Aug 31, 2018
7f3a42c
JSON Header and consistency on errors
Aug 31, 2018
87c1a0f
Increased cov for genesis
Aug 31, 2018
5ecedad
Added comment for maxRetrieve param in keepers
Aug 31, 2018
af757dd
Comment on DelegationWithoutDec
Aug 31, 2018
80db853
Bech32Validator Keepers
Aug 31, 2018
99acd57
Changed Bech validator
Sep 1, 2018
8abb44e
Updated remaining tests and bech32 validator
Sep 1, 2018
55ff4b7
Merge branch 'develop' into fedekunze/2009-queriers-staking
fedekunze Sep 2, 2018
450539b
Addressed most of Rigel's comments
Sep 3, 2018
61efdf6
Updated tests and types
Sep 6, 2018
0bd0417
Make codec to be unexported from keeper
Sep 6, 2018
8a2d144
Moved logic to query_utils and updated tests
Sep 6, 2018
a032ea1
Querier PR part 1 wo/gov stuff
Sep 6, 2018
613edae
Fix linter err and PENDING
Sep 6, 2018
9dbf12f
Fix err
Sep 6, 2018
d11befe
Fix err
Sep 6, 2018
cb5c6b7
Fixed tests
Sep 6, 2018
1325649
Update PENDING description
Sep 6, 2018
a5f30d8
Update UpdateBondedValidatorsFull
Sep 6, 2018
08eed09
Update iterator
Sep 6, 2018
9618800
defer iterator.Close()
Sep 7, 2018
f0ae6d9
delete comment
Sep 7, 2018
5e90876
Address some of Aleks comments, need to fix tests
Sep 10, 2018
de5cded
export querier
Sep 10, 2018
887116c
Fixed tests
Sep 10, 2018
454620e
Merge develop and delete bech32validator calls
Sep 11, 2018
9d64fb0
Address Rigel's comments
Sep 11, 2018
ee7b2cf
More tests
Sep 11, 2018
5a3f719
Fix conflicts
Sep 11, 2018
40bfa9d
return error for GetDelegatorValidator
Sep 11, 2018
c40bcc1
Fixed conflicts
Sep 12, 2018
02ab6d3
Fixed conflicts
Sep 12, 2018
08af1c2
Fix linter warnings
Sep 12, 2018
9958ddc
Address @rigelrozanski comments
Sep 13, 2018
99fcad1
Merge branch 'develop' into fedekunze/2009-querier-pt1
fedekunze Sep 13, 2018
3a496e1
Delete comments
Sep 13, 2018
8470d3a
Solve conflicts
Sep 13, 2018
7884871
Merge branch 'develop' into fedekunze/2009-querier-pt1
fedekunze Sep 13, 2018
92d4cfc
wire ––> codec
Sep 13, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ test_sim_gaia_fast:
@go test ./cmd/gaia/app -run TestFullGaiaSimulation -SimulationEnabled=true -SimulationNumBlocks=400 -SimulationBlockSize=200 -SimulationCommit=true -v -timeout 24h

test_sim_gaia_slow:
@echo "Running full Gaia simulation. This may take awhile!"
@go test ./cmd/gaia/app -run TestFullGaiaSimulation -SimulationEnabled=true -SimulationNumBlocks=1000 -SimulationVerbose=true -SimulationCommit=true -v -timeout 24h
@echo "Running full Gaia simulation. This may take a while!"
@go test ./cmd/gaia/app -run TestFullGaiaSimulation -SimulationEnabled=true -SimulationNumBlocks=1000 -SimulationVerbose=true -SimulationCommit=true -v -timeout 24h

SIM_NUM_BLOCKS ?= 210
SIM_BLOCK_SIZE ?= 200
Expand Down
3 changes: 2 additions & 1 deletion PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ IMPROVEMENTS
* [x/stake] Improve speed of GetValidator, which was shown to be a performance bottleneck. [#2046](https://github.com/tendermint/tendermint/pull/2200)
* [genesis] \#2229 Ensure that there are no duplicate accounts or validators in the genesis state.
* Add SDK validation to `config.toml` (namely disabling `create_empty_blocks`) \#1571

* SDK
* [tools] Make get_vendor_deps deletes `.vendor-new` directories, in case scratch files are present.
* [spec] Added simple piggy bank distribution spec
Expand All @@ -113,6 +113,7 @@ IMPROVEMENTS
* [simulation] Add a concept of weighting the operations \#2303
* [simulation] Logs get written to file if large, and also get printed on panics \#2285
* [gaiad] \#1992 Add optional flag to `gaiad testnet` to make config directory of daemon (default `gaiad`) and cli (default `gaiacli`) configurable
* [x/stake] Add stake `Queriers` for Gaia-lite endpoints. This increases the staking endpoints performance by reusing the staking `keeper` logic for queries. [#2249](https://github.com/cosmos/cosmos-sdk/pull/2149)

* Tendermint

Expand Down
46 changes: 24 additions & 22 deletions client/lcd/lcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/gov"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/stake"
"github.com/cosmos/cosmos-sdk/x/stake/client/rest"
)

func init() {
Expand Down Expand Up @@ -510,6 +509,7 @@ func TestBonding(t *testing.T) {
cleanup, pks, port := InitializeTestLCD(t, 1, []sdk.AccAddress{addr})
defer cleanup()

amt := sdk.NewDec(60)
validator1Operator := sdk.ValAddress(pks[0].Address())
validator := getValidator(t, port, validator1Operator)

Expand All @@ -527,18 +527,18 @@ func TestBonding(t *testing.T) {

// query validator
bond := getDelegation(t, port, addr, validator1Operator)
require.Equal(t, "60.0000000000", bond.Shares)
require.Equal(t, amt, bond.Shares)

summary := getDelegationSummary(t, port, addr)

require.Len(t, summary.Delegations, 1, "Delegation summary holds all delegations")
require.Equal(t, "60.0000000000", summary.Delegations[0].Shares)
require.Equal(t, amt, summary.Delegations[0].Shares)
require.Len(t, summary.UnbondingDelegations, 0, "Delegation summary holds all unbonding-delegations")

bondedValidators := getDelegatorValidators(t, port, addr)
require.Len(t, bondedValidators, 1)
require.Equal(t, validator1Operator, bondedValidators[0].OperatorAddr)
require.Equal(t, validator.DelegatorShares.Add(sdk.NewDec(60)).String(), bondedValidators[0].DelegatorShares.String())
require.Equal(t, validator.DelegatorShares.Add(amt).String(), bondedValidators[0].DelegatorShares.String())

bondedValidator := getDelegatorValidator(t, port, addr, validator1Operator)
require.Equal(t, validator1Operator, bondedValidator.OperatorAddr)
Expand All @@ -558,9 +558,8 @@ func TestBonding(t *testing.T) {
coins = acc.GetCoins()
require.Equal(t, int64(40), coins.AmountOf("steak").Int64())

unbondings := getUndelegations(t, port, addr, validator1Operator)
require.Len(t, unbondings, 1, "Unbondings holds all unbonding-delegations")
require.Equal(t, "60", unbondings[0].Balance.Amount.String())
unbonding := getUndelegation(t, port, addr, validator1Operator)
require.Equal(t, "60", unbonding.Balance.Amount.String())

summary = getDelegationSummary(t, port, addr)

Expand Down Expand Up @@ -895,43 +894,43 @@ func doIBCTransfer(t *testing.T, port, seed, name, password string, addr sdk.Acc
func getSigningInfo(t *testing.T, port string, validatorPubKey string) slashing.ValidatorSigningInfo {
res, body := Request(t, port, "GET", fmt.Sprintf("/slashing/signing_info/%s", validatorPubKey), nil)
require.Equal(t, http.StatusOK, res.StatusCode, body)

var signingInfo slashing.ValidatorSigningInfo
err := cdc.UnmarshalJSON([]byte(body), &signingInfo)
require.Nil(t, err)

return signingInfo
}

// ============= Stake Module ================

func getDelegation(t *testing.T, port string, delAddr sdk.AccAddress, valAddr sdk.ValAddress) rest.DelegationWithoutRat {
res, body := Request(t, port, "GET", fmt.Sprintf("/stake/delegators/%s/delegations/%s", delAddr, valAddr), nil)
func getDelegation(t *testing.T, port string, delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress) stake.Delegation {
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
res, body := Request(t, port, "GET", fmt.Sprintf("/stake/delegators/%s/delegations/%s", delegatorAddr, validatorAddr), nil)
require.Equal(t, http.StatusOK, res.StatusCode, body)

var bond rest.DelegationWithoutRat

var bond stake.Delegation
err := cdc.UnmarshalJSON([]byte(body), &bond)
require.Nil(t, err)

return bond
}

func getUndelegations(t *testing.T, port string, delAddr sdk.AccAddress, valAddr sdk.ValAddress) []stake.UnbondingDelegation {
res, body := Request(t, port, "GET", fmt.Sprintf("/stake/delegators/%s/unbonding_delegations/%s", delAddr, valAddr), nil)
func getUndelegation(t *testing.T, port string, delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress) stake.UnbondingDelegation {
res, body := Request(t, port, "GET", fmt.Sprintf("/stake/delegators/%s/unbonding_delegations/%s", delegatorAddr, validatorAddr), nil)
require.Equal(t, http.StatusOK, res.StatusCode, body)

var unbondings []stake.UnbondingDelegation

var unbondings stake.UnbondingDelegation
err := cdc.UnmarshalJSON([]byte(body), &unbondings)
require.Nil(t, err)

return unbondings
}

func getDelegationSummary(t *testing.T, port string, delegatorAddr sdk.AccAddress) rest.DelegationSummary {
func getDelegationSummary(t *testing.T, port string, delegatorAddr sdk.AccAddress) stake.DelegationSummary {
res, body := Request(t, port, "GET", fmt.Sprintf("/stake/delegators/%s", delegatorAddr), nil)
require.Equal(t, http.StatusOK, res.StatusCode, body)

var summary rest.DelegationSummary
var summary stake.DelegationSummary

err := cdc.UnmarshalJSON([]byte(body), &summary)
require.Nil(t, err)
Expand Down Expand Up @@ -970,8 +969,8 @@ func getDelegatorValidators(t *testing.T, port string, delegatorAddr sdk.AccAddr
return bondedValidators
}

func getDelegatorValidator(t *testing.T, port string, delAddr sdk.AccAddress, valAddr sdk.ValAddress) stake.Validator {
res, body := Request(t, port, "GET", fmt.Sprintf("/stake/delegators/%s/validators/%s", delAddr, valAddr), nil)
func getDelegatorValidator(t *testing.T, port string, delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress) stake.Validator {
res, body := Request(t, port, "GET", fmt.Sprintf("/stake/delegators/%s/validators/%s", delegatorAddr, validatorAddr), nil)
require.Equal(t, http.StatusOK, res.StatusCode, body)

var bondedValidator stake.Validator
Expand Down Expand Up @@ -1097,18 +1096,22 @@ func doBeginRedelegation(t *testing.T, port, seed, name, password string,
func getValidators(t *testing.T, port string) []stake.Validator {
res, body := Request(t, port, "GET", "/stake/validators", nil)
require.Equal(t, http.StatusOK, res.StatusCode, body)

var validators []stake.Validator
err := cdc.UnmarshalJSON([]byte(body), &validators)
require.Nil(t, err)

return validators
}

func getValidator(t *testing.T, port string, valAddr sdk.ValAddress) stake.Validator {
res, body := Request(t, port, "GET", fmt.Sprintf("/stake/validators/%s", valAddr.String()), nil)
func getValidator(t *testing.T, port string, validatorAddr sdk.ValAddress) stake.Validator {
res, body := Request(t, port, "GET", fmt.Sprintf("/stake/validators/%s", validatorAddr.String()), nil)
require.Equal(t, http.StatusOK, res.StatusCode, body)

var validator stake.Validator
err := cdc.UnmarshalJSON([]byte(body), &validator)
require.Nil(t, err)

return validator
}

Expand Down Expand Up @@ -1284,7 +1287,6 @@ func doVote(t *testing.T, port, seed, name, password string, proposerAddr sdk.Ac
}
}`, proposerAddr, name, password, chainID, accnum, sequence))
res, body := Request(t, port, "POST", fmt.Sprintf("/gov/proposals/%d/votes", proposalID), jsonStr)
fmt.Println(res)
require.Equal(t, http.StatusOK, res.StatusCode, body)

var results ctypes.ResultBroadcastTxCommit
Expand Down
1 change: 1 addition & 0 deletions client/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func SignStdTx(txBldr authtxb.TxBuilder, cliCtx context.CLIContext, name string,
return txBldr.SignStdTx(name, passphrase, stdTx, appendSig)
}

// nolint
// SimulateMsgs simulates the transaction and returns the gas estimate and the adjusted value.
func simulateMsgs(txBldr authtxb.TxBuilder, cliCtx context.CLIContext, name string, msgs []sdk.Msg) (estimated, adjusted int64, err error) {
txBytes, err := txBldr.BuildWithPubKey(name, msgs)
Expand Down
3 changes: 2 additions & 1 deletion cmd/gaia/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio
AddRoute("gov", gov.NewHandler(app.govKeeper))

app.QueryRouter().
AddRoute("gov", gov.NewQuerier(app.govKeeper))
AddRoute("gov", gov.NewQuerier(app.govKeeper)).
AddRoute("stake", stake.NewQuerier(app.stakeKeeper, app.cdc))

// initialize BaseApp
app.SetInitChainer(app.initChainer)
Expand Down
1 change: 1 addition & 0 deletions x/auth/client/rest/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type SignBody struct {
AppendSig bool `json:"append_sig"`
}

// nolint: unparam
Copy link
Contributor

Choose a reason for hiding this comment

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

If we do _ context.CLIContext do we still get a lint error?

// sign tx REST handler
func SignTxRequestHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {

Expand Down
Loading