* first commit * gaia cleanup * ... * staking multihooks * missing module function return args * bank module name constant * working, module interface for x/ * got this thing compiling * make test compiles and passes * remove expanded simulation invariants * genesis issue * continued * continued * register crisis routes thought mm * begin blocker to mm * end blocker to mm * empty routes not initialized * move gaia initChainer sanity check to baseapp * remove codecs from module manager * reorging genesis stuff * module manager passed by reference/bugfixes from working last commit int int * move invariant checks from gaia to crisis * typo * basic refactors cmd/gaia/init * working * MultiStakingHooks from types to x/staking/types int * default module manager order of operations from input modules * working * typo * add AppModuleBasic * moduleBasicManager / non-test code compiles * working attempting to get tests passing * make test passes * sim random genesis fix * export bug * ... * genutil module * genutil working * refactored - happy with non-testing code in cmd/ * ... * lint fixes * comment improvement * cli test fix * compile housing * working through compile errors * working gettin' compilin' * non-test code compiles * move testnet to its own module * reworking tests int * bez staging PR 1 comments * concise module function-of names * moved all tests from genesis_test.go to other genutil tests * genaccounts package, add genutil and genaccounts to app.go * docs for genutil genaccounts * genaccounts iterate fn * non-test code with genaccounts/ now compiles * working test compiling * debugging tests * resolved all make test compile errors * test debuggin * resolved all unit tests, introduced param module * cli-test compile fixes * staking initialization bug * code comment improvements, changelog entries * BasicGaiaApp -> ModuleBasics * highlevel explanation in types/module.go * @alexanderbez comment revisions * @fedekunze PR comments * @alexanderbez PR comments (x2) * @cwgoes comments (minor updates) * @fedekunze suggestions * panic on init with multiple validator updates from different modules * initchain panic makes validate genesis fail int * AppModuleGenesis seperation int * test * remove init panic logic in validate genesis replaced with TODO * set maxprocs to match system's GOMAXPROCS * Update circleci * Cap maxprocs in CI to 4 * @alexanderbez recent comments addressed * less blocks in twouble sims int * runsim error output flag * -e on import_export as well * error out int * Try to fix failures * runsim
128 lines
3.4 KiB
Go
128 lines
3.4 KiB
Go
package slashing
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
)
|
|
|
|
// Query endpoints supported by the slashing querier
|
|
const (
|
|
QueryParameters = "parameters"
|
|
QuerySigningInfo = "signingInfo"
|
|
QuerySigningInfos = "signingInfos"
|
|
)
|
|
|
|
// NewQuerier creates a new querier for slashing clients.
|
|
func NewQuerier(k Keeper) sdk.Querier {
|
|
return func(ctx sdk.Context, path []string, req abci.RequestQuery) ([]byte, sdk.Error) {
|
|
switch path[0] {
|
|
case QueryParameters:
|
|
return queryParams(ctx, k)
|
|
case QuerySigningInfo:
|
|
return querySigningInfo(ctx, req, k)
|
|
case QuerySigningInfos:
|
|
return querySigningInfos(ctx, req, k)
|
|
default:
|
|
return nil, sdk.ErrUnknownRequest("unknown staking query endpoint")
|
|
}
|
|
}
|
|
}
|
|
|
|
func queryParams(ctx sdk.Context, k Keeper) ([]byte, sdk.Error) {
|
|
params := k.GetParams(ctx)
|
|
|
|
res, err := codec.MarshalJSONIndent(moduleCdc, params)
|
|
if err != nil {
|
|
return nil, sdk.ErrInternal(sdk.AppendMsgToErr("failed to marshal JSON", err.Error()))
|
|
}
|
|
|
|
return res, nil
|
|
}
|
|
|
|
// QuerySigningInfoParams defines the params for the following queries:
|
|
// - 'custom/slashing/signingInfo'
|
|
type QuerySigningInfoParams struct {
|
|
ConsAddress sdk.ConsAddress
|
|
}
|
|
|
|
func NewQuerySigningInfoParams(consAddr sdk.ConsAddress) QuerySigningInfoParams {
|
|
return QuerySigningInfoParams{consAddr}
|
|
}
|
|
|
|
func querySigningInfo(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, sdk.Error) {
|
|
var params QuerySigningInfoParams
|
|
|
|
err := moduleCdc.UnmarshalJSON(req.Data, ¶ms)
|
|
if err != nil {
|
|
return nil, sdk.ErrInternal(fmt.Sprintf("failed to parse params: %s", err))
|
|
}
|
|
|
|
signingInfo, found := k.getValidatorSigningInfo(ctx, params.ConsAddress)
|
|
if !found {
|
|
return nil, ErrNoSigningInfoFound(DefaultCodespace, params.ConsAddress)
|
|
}
|
|
|
|
res, err := codec.MarshalJSONIndent(moduleCdc, signingInfo)
|
|
if err != nil {
|
|
return nil, sdk.ErrInternal(sdk.AppendMsgToErr("failed to JSON marshal result: %s", err.Error()))
|
|
}
|
|
|
|
return res, nil
|
|
}
|
|
|
|
// QuerySigningInfosParams defines the params for the following queries:
|
|
// - 'custom/slashing/signingInfos'
|
|
type QuerySigningInfosParams struct {
|
|
Page, Limit int
|
|
}
|
|
|
|
func NewQuerySigningInfosParams(page, limit int) QuerySigningInfosParams {
|
|
return QuerySigningInfosParams{page, limit}
|
|
}
|
|
|
|
func querySigningInfos(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, sdk.Error) {
|
|
var params QuerySigningInfosParams
|
|
|
|
err := moduleCdc.UnmarshalJSON(req.Data, ¶ms)
|
|
if err != nil {
|
|
return nil, sdk.ErrInternal(fmt.Sprintf("failed to parse params: %s", err))
|
|
}
|
|
|
|
if params.Limit == 0 {
|
|
// set the default limit to max bonded if no limit was provided
|
|
params.Limit = int(k.validatorSet.MaxValidators(ctx))
|
|
}
|
|
|
|
var signingInfos []ValidatorSigningInfo
|
|
|
|
k.IterateValidatorSigningInfos(ctx, func(consAddr sdk.ConsAddress, info ValidatorSigningInfo) (stop bool) {
|
|
signingInfos = append(signingInfos, info)
|
|
return false
|
|
})
|
|
|
|
// get pagination bounds
|
|
start := (params.Page - 1) * params.Limit
|
|
end := params.Limit + start
|
|
if end >= len(signingInfos) {
|
|
end = len(signingInfos)
|
|
}
|
|
|
|
if start >= len(signingInfos) {
|
|
// page is out of bounds
|
|
signingInfos = []ValidatorSigningInfo{}
|
|
} else {
|
|
signingInfos = signingInfos[start:end]
|
|
}
|
|
|
|
res, err := codec.MarshalJSONIndent(moduleCdc, signingInfos)
|
|
if err != nil {
|
|
return nil, sdk.ErrInternal(sdk.AppendMsgToErr("failed to JSON marshal result: %s", err.Error()))
|
|
}
|
|
|
|
return res, nil
|
|
}
|