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

feat: require compile-time flag to enable liquidator query #1395

Merged
merged 6 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
- [1331](https://github.com/umee-network/umee/pull/1331) Implemented MinCollateralLiquidity.
- [1343](https://github.com/umee-network/umee/pull/1343) RepayBadDebt and Liquidate automatically clear blacklisted collateral.
- [1379](https://github.com/umee-network/umee/pull/1379) Add `mininumCommissionRate` update to all validators.
- [1395](https://github.com/umee-network/umee/pull/1395) Require compile-time flag to enable liquidation_targets query.

### Improvements

Expand Down
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ LEDGER_ENABLED ?= true
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
HTTPS_GIT := https://github.com/umee-network/umee.git
LIQUIDATOR := $(if $(LIQUIDATOR),true,false)

###############################################################################
## Version ##
Expand Down Expand Up @@ -62,7 +63,8 @@ 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/tendermint/tendermint/version.TMCoreSemVer=$(TM_VERSION) \
-X github.com/umee-network/umee/v3/x/leverage/keeper.EnableLiquidator=$(LIQUIDATOR)

ldflags += $(LDFLAGS)
ldflags := $(strip $(ldflags))
Expand All @@ -80,6 +82,9 @@ 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
8 changes: 8 additions & 0 deletions x/leverage/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"context"
"strings"

sdk "github.com/cosmos/cosmos-sdk/types"
"google.golang.org/grpc/codes"
Expand All @@ -10,6 +11,9 @@ 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 @@ -237,6 +241,10 @@ func (q Querier) LiquidationTargets(
return nil, status.Error(codes.InvalidArgument, "empty request")
}

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

ctx := sdk.UnwrapSDKContext(goCtx)

targets, err := q.Keeper.GetEligibleLiquidationTargets(ctx)
Expand Down
8 changes: 8 additions & 0 deletions x/leverage/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"

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

Expand Down Expand Up @@ -118,6 +119,13 @@ 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
3 changes: 3 additions & 0 deletions x/leverage/keeper/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ func (s *IntegrationTestSuite) SetupTest() {
Time: time.Unix(0, 0),
})

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

umeeToken := newToken(appparams.BondDenom, "UMEE")
atomIBCToken := newToken(atomDenom, "ATOM")

Expand Down
3 changes: 3 additions & 0 deletions x/leverage/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,7 @@ var (
ErrInvalidExchangeRate = sdkerrors.Register(ModuleName, 604, "exchange rate less than one")
ErrInconsistentTotalBorrow = sdkerrors.Register(ModuleName, 605, "total adjusted borrow inconsistency")
ErrExcessiveTimeElapsed = sdkerrors.Register(ModuleName, 606, "excessive time elapsed since last interest time")

// 7XX = Disabled Functionality
ErrNotLiquidatorNode = sdkerrors.Register(ModuleName, 700, "node has disabled liquidator queries")
)