Skip to content

Commit

Permalink
feat: liquidator query enabled by runtime flag (#1577)
Browse files Browse the repository at this point in the history
## Description

The query `liquidation-targets` is enabled at runtime the node is started with a flag:

```bash
# Enabled
umeed start --enable-liquidator-query

# Enabled
umeed start -l

# Disabled
umeed start
```

closes: #1400

---

### Author Checklist

_All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues._

I have...

- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [x] added `!` to the type prefix if API or client breaking change
- [x] added appropriate labels to the PR
- [x] targeted the correct branch (see [PR Targeting](https://github.com/umee-network/umee/blob/main/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [x] added a changelog entry to `CHANGELOG.md`
- [x] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [x] updated the relevant documentation or specification
- [x] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

_All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items._

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
  • Loading branch information
toteki committed Nov 14, 2022
1 parent 9ce113f commit 60f7da4
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 38 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
## [Unreleased]

### Features

- [1555](https://github.com/umee-network/umee/pull/1555) Updates IBC to v5.1.0 that adds adds optional memo field to `FungibleTokenPacketData` and `MsgTransfer`.
- [1577](https://github.com/umee-network/umee/pull/1577) Removes LIQUIDATOR build flag and adds `--enable-liquidator-query` or `-l` runtime flag to `umeed start`. See [README.md](README.md) file for more details.

### State Machine Breaking

Expand Down
7 changes: 1 addition & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ TM_VERSION := $(shell go list -m github.com/tendermint/tendermint | sed 's:.
DOCKER := $(shell which docker)
PROJECT_NAME := umee
HTTPS_GIT := https://github.com/umee-network/umee.git
LIQUIDATOR := $(if $(LIQUIDATOR),true,false)

###############################################################################
## Version ##
Expand Down Expand Up @@ -70,8 +69,7 @@ ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=umee \
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \
-X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)" \
-X github.com/tendermint/tendermint/version.TMCoreSemVer=$(TM_VERSION) \
-X github.com/umee-network/umee/v3/x/leverage/keeper.EnableLiquidator=$(LIQUIDATOR)
-X github.com/tendermint/tendermint/version.TMCoreSemVer=$(TM_VERSION)

ifeq ($(LINK_STATICALLY),true)
ldflags += -linkmode=external -extldflags "-Wl,-z,muldefs -static"
Expand All @@ -97,9 +95,6 @@ build-no_cgo:
build-linux: go.sum
LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build

build-liquidator:
LIQUIDATOR=true $(MAKE) build

install: go.sum
@echo "--> Installing..."
go install -mod=readonly $(BUILD_FLAGS) ./...
Expand Down
5 changes: 3 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ func New(
app.BankKeeper,
app.OracleKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
cast.ToBool(appOpts.Get(leveragetypes.FlagEnableLiquidatorQuery)),
)
if err != nil {
panic(err)
Expand Down Expand Up @@ -750,8 +751,8 @@ func New(
}

func (app *UmeeApp) setAnteHandler(txConfig client.TxConfig,
wasmConfig *wasmtypes.WasmConfig, wasmStoreKey *storetypes.KVStoreKey) {

wasmConfig *wasmtypes.WasmConfig, wasmStoreKey *storetypes.KVStoreKey,
) {
anteHandler, err := customante.NewAnteHandler(
customante.HandlerOptions{
AccountKeeper: app.AccountKeeper,
Expand Down
2 changes: 2 additions & 0 deletions cmd/umeed/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

umeeapp "github.com/umee-network/umee/v3/app"
appparams "github.com/umee-network/umee/v3/app/params"
"github.com/umee-network/umee/v3/x/leverage"
)

// NewRootCmd returns the root command handler for the Umee daemon.
Expand Down Expand Up @@ -187,6 +188,7 @@ func initRootCmd(rootCmd *cobra.Command, a appCreator) {

func addModuleInitFlags(startCmd *cobra.Command) {
crisis.AddModuleInitFlags(startCmd)
leverage.AddModuleInitFlags(startCmd)
}

func queryCommand(ac appCreator) *cobra.Command {
Expand Down
13 changes: 13 additions & 0 deletions x/leverage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,19 @@ Similarly, `AdjustedTotalBorrowed` is never set independently during regular ope

See [leverage query proto](https://github.com/umee-network/umee/blob/main/proto/umee/leverage/v1/query.proto) for list of supported queries.

Additionally, the query `liquidation-targets` is only enabled if the node is started with a flag:

```bash
# Enabled
umeed start --enable-liquidator-query

# Enabled
umeed start -l

# Disabled
umeed start
```

## Messages

See [leverage tx proto](https://github.com/umee-network/umee/blob/main/proto/umee/leverage/v1/tx.proto#L11) for list of supported messages.
Expand Down
6 changes: 1 addition & 5 deletions x/leverage/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keeper

import (
"context"
"strings"

sdk "github.com/cosmos/cosmos-sdk/types"
"google.golang.org/grpc/codes"
Expand All @@ -11,9 +10,6 @@ import (
"github.com/umee-network/umee/v3/x/leverage/types"
)

// EnableLiquidator must be set to "true" at compile time to enable QueryLiquidationTargets
var EnableLiquidator = ""

var _ types.QueryServer = Querier{}

// Querier implements a QueryServer for the x/leverage module.
Expand Down Expand Up @@ -241,7 +237,7 @@ func (q Querier) LiquidationTargets(
return nil, status.Error(codes.InvalidArgument, "empty request")
}

if strings.ToLower(EnableLiquidator) != "true" {
if !q.Keeper.liquidatorQueryEnabled {
return nil, types.ErrNotLiquidatorNode
}

Expand Down
8 changes: 0 additions & 8 deletions x/leverage/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/umee-network/umee/v3/x/leverage/fixtures"
"github.com/umee-network/umee/v3/x/leverage/keeper"
"github.com/umee-network/umee/v3/x/leverage/types"
)

Expand Down Expand Up @@ -120,13 +119,6 @@ func (s *IntegrationTestSuite) TestQuerier_AccountSummary() {
func (s *IntegrationTestSuite) TestQuerier_LiquidationTargets() {
ctx, require := s.ctx, s.Require()

keeper.EnableLiquidator = "false"

_, err := s.queryClient.LiquidationTargets(ctx.Context(), &types.QueryLiquidationTargets{})
require.ErrorIs(err, types.ErrNotLiquidatorNode)

keeper.EnableLiquidator = "true"

resp, err := s.queryClient.LiquidationTargets(ctx.Context(), &types.QueryLiquidationTargets{})
require.NoError(err)

Expand Down
2 changes: 2 additions & 0 deletions x/leverage/keeper/internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func NewTestKeeper(
bk types.BankKeeper,
ok types.OracleKeeper,
authority string,
enableLiquidatorQuery bool,
) (Keeper, TestKeeper) {
k, err := NewKeeper(
cdc,
Expand All @@ -35,6 +36,7 @@ func NewTestKeeper(
bk,
ok,
authority,
enableLiquidatorQuery,
)
require.NoError(err)
return k, TestKeeper{&k}
Expand Down
29 changes: 16 additions & 13 deletions x/leverage/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ import (
)

type Keeper struct {
cdc codec.Codec
storeKey storetypes.StoreKey
paramSpace paramtypes.Subspace
hooks types.Hooks
bankKeeper types.BankKeeper
oracleKeeper types.OracleKeeper
authority string // the gov module account
cdc codec.Codec
storeKey storetypes.StoreKey
paramSpace paramtypes.Subspace
hooks types.Hooks
bankKeeper types.BankKeeper
oracleKeeper types.OracleKeeper
authority string // the gov module account
liquidatorQueryEnabled bool
}

func NewKeeper(
Expand All @@ -31,19 +32,21 @@ func NewKeeper(
bk types.BankKeeper,
ok types.OracleKeeper,
authority string,
enableLiquidatorQuery bool,
) (Keeper, error) {
// set KeyTable if it has not already been set
if !paramSpace.HasKeyTable() {
paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable())
}

return Keeper{
cdc: cdc,
storeKey: storeKey,
paramSpace: paramSpace,
bankKeeper: bk,
oracleKeeper: ok,
authority: authority,
cdc: cdc,
storeKey: storeKey,
paramSpace: paramSpace,
bankKeeper: bk,
oracleKeeper: ok,
authority: authority,
liquidatorQueryEnabled: enableLiquidatorQuery,
}, nil
}

Expand Down
4 changes: 1 addition & 3 deletions x/leverage/keeper/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ func (s *IntegrationTestSuite) SetupTest() {
Time: time.Unix(0, 0),
})

// Enable liquidation queries for testing
keeper.EnableLiquidator = "true"

// we only override the Leverage keeper so we can supply a custom mock oracle
k, tk := keeper.NewTestKeeper(
s.Require(),
Expand All @@ -65,6 +62,7 @@ func (s *IntegrationTestSuite) SetupTest() {
app.BankKeeper,
newMockOracleKeeper(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
true,
)

s.tk = tk
Expand Down
5 changes: 5 additions & 0 deletions x/leverage/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,8 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp
simState.AppParams, simState.Cdc, am.accountKeeper, am.bankKeeper, am.keeper,
)
}

// AddModuleInitFlags implements servertypes.ModuleInitFlags interface.
func AddModuleInitFlags(startCmd *cobra.Command) {
startCmd.Flags().BoolP(types.FlagEnableLiquidatorQuery, "l", false, "enable liquidator query")
}
3 changes: 3 additions & 0 deletions x/leverage/types/flag.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package types

const FlagEnableLiquidatorQuery = "enable-liquidator-query"

0 comments on commit 60f7da4

Please sign in to comment.