From a99a102f927342e5aa57b7986ecad28dd0dcb10d Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Thu, 15 Sep 2022 23:31:06 -0700 Subject: [PATCH 1/4] feat: require compile-time flag to enable liquidator query --- Makefile | 11 +++++++++-- x/leverage/keeper/grpc_query.go | 8 ++++++++ x/leverage/keeper/grpc_query_test.go | 8 ++++++++ x/leverage/keeper/suite_test.go | 3 +++ x/leverage/types/errors.go | 3 +++ 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 9ba64b14ba..d5ac0dc336 100644 --- a/Makefile +++ b/Makefile @@ -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 ## @@ -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)) @@ -71,6 +73,7 @@ BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)' build: go.sum @echo "--> Building..." + @echo "LIQUIDATOR:" $(LIQUIDATOR) go build -mod=readonly $(BUILD_FLAGS) -o $(BUILD_DIR)/ ./... build-no_cgo: @@ -80,8 +83,12 @@ 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..." + @echo "LIQUIDATOR:" $(LIQUIDATOR) go install -mod=readonly $(BUILD_FLAGS) ./... go-mod-cache: go.sum diff --git a/x/leverage/keeper/grpc_query.go b/x/leverage/keeper/grpc_query.go index c5d1014829..6254e8c00b 100644 --- a/x/leverage/keeper/grpc_query.go +++ b/x/leverage/keeper/grpc_query.go @@ -2,6 +2,7 @@ package keeper import ( "context" + "strings" sdk "github.com/cosmos/cosmos-sdk/types" "google.golang.org/grpc/codes" @@ -10,6 +11,9 @@ import ( "github.com/umee-network/umee/v3/x/leverage/types" ) +// EnableLiquidator must be true at compile time to enable QueryLiquidationTargets +var EnableLiquidator = "" + var _ types.QueryServer = Querier{} // Querier implements a QueryServer for the x/leverage module. @@ -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) diff --git a/x/leverage/keeper/grpc_query_test.go b/x/leverage/keeper/grpc_query_test.go index 49c01053e2..676840979d 100644 --- a/x/leverage/keeper/grpc_query_test.go +++ b/x/leverage/keeper/grpc_query_test.go @@ -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" ) @@ -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) diff --git a/x/leverage/keeper/suite_test.go b/x/leverage/keeper/suite_test.go index 89eed1125b..d4d73d3c4a 100644 --- a/x/leverage/keeper/suite_test.go +++ b/x/leverage/keeper/suite_test.go @@ -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") diff --git a/x/leverage/types/errors.go b/x/leverage/types/errors.go index d2f7334920..0a698ce7f6 100644 --- a/x/leverage/types/errors.go +++ b/x/leverage/types/errors.go @@ -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") ) From 8d87c8b52f2d6d6099fbe76d56a6bf84e21c4e94 Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Thu, 15 Sep 2022 23:33:46 -0700 Subject: [PATCH 2/4] changelog++ --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 828b7a6aaf..80615b97ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 From 1136a9cc9e4d14f932c51cf670f616da5747f774 Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Thu, 15 Sep 2022 23:35:23 -0700 Subject: [PATCH 3/4] comment++ --- x/leverage/keeper/grpc_query.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/leverage/keeper/grpc_query.go b/x/leverage/keeper/grpc_query.go index 6254e8c00b..142f110458 100644 --- a/x/leverage/keeper/grpc_query.go +++ b/x/leverage/keeper/grpc_query.go @@ -11,7 +11,7 @@ import ( "github.com/umee-network/umee/v3/x/leverage/types" ) -// EnableLiquidator must be true at compile time to enable QueryLiquidationTargets +// EnableLiquidator must be set to "true" at compile time to enable QueryLiquidationTargets var EnableLiquidator = "" var _ types.QueryServer = Querier{} From c13ed92221b279957db12de9ceda6f43ac5fd965 Mon Sep 17 00:00:00 2001 From: toteki <63419657+toteki@users.noreply.github.com> Date: Fri, 16 Sep 2022 05:17:49 -0700 Subject: [PATCH 4/4] Apply suggestions from code review Co-authored-by: Rafael Tenfen --- Makefile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Makefile b/Makefile index d5ac0dc336..77bc4fd3d3 100644 --- a/Makefile +++ b/Makefile @@ -73,7 +73,6 @@ BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)' build: go.sum @echo "--> Building..." - @echo "LIQUIDATOR:" $(LIQUIDATOR) go build -mod=readonly $(BUILD_FLAGS) -o $(BUILD_DIR)/ ./... build-no_cgo: @@ -88,7 +87,6 @@ build-liquidator: install: go.sum @echo "--> Installing..." - @echo "LIQUIDATOR:" $(LIQUIDATOR) go install -mod=readonly $(BUILD_FLAGS) ./... go-mod-cache: go.sum