From 296b61f9a6bc2bea790ddb38900d6bdf91ff879d Mon Sep 17 00:00:00 2001 From: atheesh Date: Mon, 21 Jun 2021 15:23:52 +0530 Subject: [PATCH] update refund logic --- go.mod | 2 +- go.sum | 6 ++++-- x/gov/abci.go | 6 ++---- x/gov/client/testutil/deposits.go | 11 +++++++---- x/gov/keeper/deposit.go | 20 ++++---------------- x/gov/keeper/deposit_test.go | 2 +- 6 files changed, 19 insertions(+), 28 deletions(-) diff --git a/go.mod b/go.mod index aa3b80eb3332..173d0975863a 100644 --- a/go.mod +++ b/go.mod @@ -36,7 +36,7 @@ require ( github.com/prometheus/common v0.29.0 github.com/rakyll/statik v0.1.7 github.com/regen-network/cosmos-proto v0.3.1 - github.com/rs/zerolog v1.22.0 + github.com/rs/zerolog v1.23.0 github.com/spf13/afero v1.3.4 // indirect github.com/spf13/cast v1.3.1 github.com/spf13/cobra v1.1.3 diff --git a/go.sum b/go.sum index a957981684f9..266b5b8b61ee 100644 --- a/go.sum +++ b/go.sum @@ -151,6 +151,7 @@ github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3Ee github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= @@ -267,6 +268,7 @@ github.com/gobwas/ws v1.0.2 h1:CoAavW/wd/kulfZmSIBt6p24n4j7tHgNVCjsfHVNUbo= github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM= github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 h1:ZpnhV/YsD2/4cESfV5+Hoeu/iUR3ruzNvZ+yQfO03a0= github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4= +github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gogo/gateway v1.1.0 h1:u0SuhL9+Il+UbjM9VIE3ntfRujKbvVpFvNB4HbjeVQ0= github.com/gogo/gateway v1.1.0/go.mod h1:S7rR8FRQyG3QFESeSv4l2WnsyzlCLG0CzBbUUo/mbic= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= @@ -649,8 +651,8 @@ github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/rs/xhandler v0.0.0-20160618193221-ed27b6fd6521/go.mod h1:RvLn4FgxWubrpZHtQLnOf6EwhN2hEMusxZOhcW9H3UQ= github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= -github.com/rs/zerolog v1.22.0 h1:XrVUjV4K+izZpKXZHlPrYQiDtmdGiCylnT4i43AAWxg= -github.com/rs/zerolog v1.22.0/go.mod h1:ZPhntP/xmq1nnND05hhpAh2QMhSsA4UN3MGZ6O2J3hM= +github.com/rs/zerolog v1.23.0 h1:UskrK+saS9P9Y789yNNulYKdARjPZuS35B8gJF2x60g= +github.com/rs/zerolog v1.23.0/go.mod h1:6c7hFfxPOy7TacJc4Fcdi24/J0NKYGzjG8FWRI916Qo= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= diff --git a/x/gov/abci.go b/x/gov/abci.go index ed7b800be7df..fc5309e6a843 100644 --- a/x/gov/abci.go +++ b/x/gov/abci.go @@ -19,7 +19,7 @@ func EndBlocker(ctx sdk.Context, keeper keeper.Keeper) { // delete inactive proposal from store and its deposits keeper.IterateInactiveProposalsQueue(ctx, ctx.BlockHeader().Time, func(proposal types.Proposal) bool { keeper.DeleteProposal(ctx, proposal.ProposalId) - keeper.DeleteAndBurnDeposits(ctx, proposal.ProposalId) + keeper.DeleteDeposits(ctx, proposal.ProposalId) // called when proposal become inactive keeper.AfterProposalFailedMinDeposit(ctx, proposal.ProposalId) @@ -49,9 +49,7 @@ func EndBlocker(ctx sdk.Context, keeper keeper.Keeper) { passes, burnDeposits, tallyResults := keeper.Tally(ctx, proposal) - if burnDeposits { - keeper.BurnDeposits(ctx, proposal.ProposalId) - } else { + if !burnDeposits { keeper.RefundDeposits(ctx, proposal.ProposalId) } diff --git a/x/gov/client/testutil/deposits.go b/x/gov/client/testutil/deposits.go index 389c7b9b3d74..1f9d08d76e4f 100644 --- a/x/gov/client/testutil/deposits.go +++ b/x/gov/client/testutil/deposits.go @@ -40,7 +40,7 @@ func (s *DepositTestSuite) SetupSuite() { val := s.network.Validators[0] deposits := sdk.Coins{ - sdk.NewCoin(s.cfg.BondDenom, types.DefaultMinDepositTokens.Sub(sdk.NewInt(20))), + sdk.NewCoin(s.cfg.BondDenom, types.DefaultMinDepositTokens.Sub(sdk.NewInt(120))), sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(0)), sdk.NewCoin(s.cfg.BondDenom, types.DefaultMinDepositTokens.Sub(sdk.NewInt(50))), sdk.NewCoin(s.cfg.BondDenom, types.DefaultMinDepositTokens), @@ -80,7 +80,7 @@ func (s *DepositTestSuite) TearDownSuite() { func (s *DepositTestSuite) TestQueryDepositsInitialDeposit() { val := s.network.Validators[0] clientCtx := val.ClientCtx - initialDeposit := sdk.NewCoin(s.cfg.BondDenom, types.DefaultMinDepositTokens.Sub(sdk.NewInt(20))).String() + initialDeposit := s.deposits[0].String() proposalID := s.proposalIDs[0] commonArgs := []string{ @@ -89,11 +89,14 @@ func (s *DepositTestSuite) TestQueryDepositsInitialDeposit() { fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(10))).String()), } - info, _, err := val.ClientCtx.Keyring.NewMnemonic("grantee", keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1) + info, _, err := val.ClientCtx.Keyring.NewMnemonic("acc", keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1) s.Require().NoError(err) acc := sdk.AccAddress(info.GetPubKey().Address()) - sendAmount := sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(150)) + _, err = s.network.WaitForHeight(1) + s.Require().NoError(err) + + sendAmount := sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(200)) _, err = testutil.MsgSendExec(val.ClientCtx, val.Address, acc, sendAmount, commonArgs...) s.Require().NoError(err) diff --git a/x/gov/keeper/deposit.go b/x/gov/keeper/deposit.go index 0e560eef8b55..6a0544044ad5 100644 --- a/x/gov/keeper/deposit.go +++ b/x/gov/keeper/deposit.go @@ -53,8 +53,8 @@ func (keeper Keeper) GetDeposits(ctx sdk.Context, proposalID uint64) (deposits t return } -// DeleteAndBurnDeposits deletes and burns all the deposits on a specific proposal without refunding them -func (keeper Keeper) DeleteAndBurnDeposits(ctx sdk.Context, proposalID uint64) { +// DeleteDeposits deletes all the deposits on a specific proposal without refunding them +func (keeper Keeper) DeleteDeposits(ctx sdk.Context, proposalID uint64) { store := ctx.KVStore(keeper.storeKey) keeper.IterateDeposits(ctx, proposalID, func(deposit types.Deposit) bool { @@ -72,18 +72,6 @@ func (keeper Keeper) DeleteAndBurnDeposits(ctx sdk.Context, proposalID uint64) { }) } -// BurnDeposits burns all the deposits on a specific proposal -func (keeper Keeper) BurnDeposits(ctx sdk.Context, proposalID uint64) { - keeper.IterateDeposits(ctx, proposalID, func(deposit types.Deposit) bool { - err := keeper.bankKeeper.BurnCoins(ctx, types.ModuleName, deposit.Amount) - if err != nil { - panic(err) - } - - return false - }) -} - // IterateAllDeposits iterates over the all the stored deposits and performs a callback function func (keeper Keeper) IterateAllDeposits(ctx sdk.Context, cb func(deposit types.Deposit) (stop bool)) { store := ctx.KVStore(keeper.storeKey) @@ -180,7 +168,7 @@ func (keeper Keeper) AddDeposit(ctx sdk.Context, proposalID uint64, depositorAdd // RefundDeposits refunds and deletes all the deposits on a specific proposal func (keeper Keeper) RefundDeposits(ctx sdk.Context, proposalID uint64) { - store := ctx.KVStore(keeper.storeKey) + // store := ctx.KVStore(keeper.storeKey) keeper.IterateDeposits(ctx, proposalID, func(deposit types.Deposit) bool { depositor, err := sdk.AccAddressFromBech32(deposit.Depositor) @@ -193,7 +181,7 @@ func (keeper Keeper) RefundDeposits(ctx sdk.Context, proposalID uint64) { panic(err) } - store.Delete(types.DepositKey(proposalID, depositor)) + // store.Delete(types.DepositKey(proposalID, depositor)) return false }) } diff --git a/x/gov/keeper/deposit_test.go b/x/gov/keeper/deposit_test.go index 534cf0fe2da5..0c8e370681aa 100644 --- a/x/gov/keeper/deposit_test.go +++ b/x/gov/keeper/deposit_test.go @@ -104,7 +104,7 @@ func TestDeposits(t *testing.T) { // Test delete deposits _, err = app.GovKeeper.AddDeposit(ctx, proposalID, TestAddrs[0], fourStake) require.NoError(t, err) - app.GovKeeper.DeleteAndBurnDeposits(ctx, proposalID) + app.GovKeeper.DeleteDeposits(ctx, proposalID) deposits = app.GovKeeper.GetDeposits(ctx, proposalID) require.Len(t, deposits, 0) }