diff --git a/x/interchainstaking/keeper/callbacks.go b/x/interchainstaking/keeper/callbacks.go index 67a865334..3ab74937c 100644 --- a/x/interchainstaking/keeper/callbacks.go +++ b/x/interchainstaking/keeper/callbacks.go @@ -685,7 +685,9 @@ func DelegationAccountBalancesCallback(k *Keeper, ctx sdk.Context, args []byte, 0, ) - zone.IncrementWithdrawalWaitgroup(k.Logger(ctx), 1, fmt.Sprintf("delegation account balance for %s", coin.Denom)) + if err = zone.IncrementWithdrawalWaitgroup(k.Logger(ctx), 1, fmt.Sprintf("delegation account balance for %s", coin.Denom)); err != nil { + return err + } k.Logger(ctx).Info("Emitting balance request for denom", "denom", coin.Denom, "waitgroup", zone.GetWithdrawalWaitgroup()) } k.SetZone(ctx, &zone) diff --git a/x/interchainstaking/keeper/callbacks_test.go b/x/interchainstaking/keeper/callbacks_test.go index 28d990bc4..2aa8b9514 100644 --- a/x/interchainstaking/keeper/callbacks_test.go +++ b/x/interchainstaking/keeper/callbacks_test.go @@ -721,7 +721,7 @@ func (suite *KeeperTestSuite) TestHandleRewardsCallbackNonDelegator() { ctx := suite.chainA.GetContext() zone, _ := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) - zone.IncrementWithdrawalWaitgroup(quicksilver.Logger(), 1, "test rewards callback handler") + suite.NoError(zone.IncrementWithdrawalWaitgroup(quicksilver.Logger(), 1, "test rewards callback handler")) quicksilver.InterchainstakingKeeper.SetZone(ctx, &zone) user := addressutils.GenerateAccAddressForTest() @@ -757,7 +757,7 @@ func (suite *KeeperTestSuite) TestHandleRewardsCallbackEmptyResponse() { ctx := suite.chainA.GetContext() zone, _ := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) - zone.IncrementWithdrawalWaitgroup(quicksilver.Logger(), 1, "test rewards callback handler") + suite.NoError(zone.IncrementWithdrawalWaitgroup(quicksilver.Logger(), 1, "test rewards callback handler")) quicksilver.InterchainstakingKeeper.SetZone(ctx, &zone) @@ -787,7 +787,7 @@ func (suite *KeeperTestSuite) TestHandleValideRewardsCallback() { ctx := suite.chainA.GetContext() zone, _ := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) - zone.IncrementWithdrawalWaitgroup(quicksilver.Logger(), 1, "test rewards callback handler") + suite.NoError(zone.IncrementWithdrawalWaitgroup(quicksilver.Logger(), 1, "test rewards callback handler")) quicksilver.InterchainstakingKeeper.SetZone(ctx, &zone) diff --git a/x/interchainstaking/keeper/delegation.go b/x/interchainstaking/keeper/delegation.go index 4c0c94f4a..d4cdfedab 100644 --- a/x/interchainstaking/keeper/delegation.go +++ b/x/interchainstaking/keeper/delegation.go @@ -275,7 +275,9 @@ func (k *Keeper) WithdrawDelegationRewardsForResponse(ctx sdk.Context, zone *typ // this allows us to track individual msg responses and ensure all // responses have been received and handled... // HandleWithdrawRewards contains the opposing decrement. - zone.IncrementWithdrawalWaitgroup(k.Logger(ctx), uint32(len(msgs)), "WithdrawDelegationRewardsForResponse") + if err = zone.IncrementWithdrawalWaitgroup(k.Logger(ctx), uint32(len(msgs)), "WithdrawDelegationRewardsForResponse"); err != nil { + return err + } k.SetZone(ctx, zone) k.Logger(ctx).Info("Received WithdrawDelegationRewardsForResponse acknowledgement", "wg", zone.GetWithdrawalWaitgroup(), "address", delegator) @@ -347,7 +349,9 @@ func (k *Keeper) FlushOutstandingDelegations(ctx sdk.Context, zone *types.Zone, if err != nil { return err } - zone.IncrementWithdrawalWaitgroup(k.Logger(ctx), uint32(numMsgs), "sending flush messages") + if err = zone.IncrementWithdrawalWaitgroup(k.Logger(ctx), uint32(numMsgs), "sending flush messages"); err != nil { + return err + } k.SetZone(ctx, zone) return nil } diff --git a/x/interchainstaking/keeper/hooks.go b/x/interchainstaking/keeper/hooks.go index 383904ed7..ac77c7ce1 100644 --- a/x/interchainstaking/keeper/hooks.go +++ b/x/interchainstaking/keeper/hooks.go @@ -132,7 +132,6 @@ func (k *Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNum if zone.GetWithdrawalWaitgroup() > 0 { zone.SetWithdrawalWaitgroup(k.Logger(ctx), 0, "epoch waitgroup was unexpected > 0") - } // OnChanOpenAck calls SetWithdrawalAddress (see ibc_module.go) @@ -173,7 +172,7 @@ func (k *Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNum 0, ) // increment waitgroup; decremented in delegationaccountbalance callback - zone.IncrementWithdrawalWaitgroup(k.Logger(ctx), 1, "delegationaccountbalances trigger") + _ = zone.IncrementWithdrawalWaitgroup(k.Logger(ctx), 1, "delegationaccountbalances trigger") rewardsQuery := distrtypes.QueryDelegationTotalRewardsRequest{DelegatorAddress: zone.DelegationAddress.Address} bz = k.cdc.MustMarshal(&rewardsQuery) @@ -193,7 +192,8 @@ func (k *Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNum // increment the WithdrawalWaitgroup // this allows us to track the response for every protocol delegator // WithdrawalWaitgroup is decremented in RewardsCallback - zone.IncrementWithdrawalWaitgroup(k.Logger(ctx), 1, "rewards trigger") + _ = zone.IncrementWithdrawalWaitgroup(k.Logger(ctx), 1, "rewards trigger") + k.SetZone(ctx, zone) return false diff --git a/x/interchainstaking/keeper/keeper.go b/x/interchainstaking/keeper/keeper.go index 9f484dd41..cdba0cef5 100644 --- a/x/interchainstaking/keeper/keeper.go +++ b/x/interchainstaking/keeper/keeper.go @@ -797,7 +797,6 @@ func (k *Keeper) UnmarshalValidator(data []byte) (lsmstakingtypes.Validator, err } func (k *Keeper) SendToWithdrawal(ctx sdk.Context, zone *types.Zone, sender *types.ICAAccount, amount sdk.Coins) error { - var msgs []sdk.Msg sendMsg := banktypes.MsgSend{ diff --git a/x/interchainstaking/types/zones.go b/x/interchainstaking/types/zones.go index b35bfd39e..e59748d74 100644 --- a/x/interchainstaking/types/zones.go +++ b/x/interchainstaking/types/zones.go @@ -6,9 +6,10 @@ import ( "fmt" "strings" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/tendermint/tendermint/libs/log" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/quicksilver-zone/quicksilver/utils/addressutils" ) @@ -48,21 +49,21 @@ func (z *Zone) SetWithdrawalWaitgroup(logger log.Logger, num uint32, reason stri } func (z *Zone) DecrementWithdrawalWaitgroup(logger log.Logger, num uint32, reason string) error { - if uint32(z.WithdrawalWaitgroup-num) > z.WithdrawalWaitgroup { // underflow + if z.WithdrawalWaitgroup-num > z.WithdrawalWaitgroup { // underflow logger.Error("error decrementing withdrawal waitgroup: uint32 underflow ", "zone", z.ChainId, "existing", z.WithdrawalWaitgroup, "decrement", num, "reason", reason) return errors.New("unable to decrement the withdrawal waitgroup below 0") } - logger.Info("decrementing withdrawal waitgroup", "zone", z.ChainId, "existing", z.WithdrawalWaitgroup, "decrement", num, "new", uint32(z.WithdrawalWaitgroup-num), "reason", reason) + logger.Info("decrementing withdrawal waitgroup", "zone", z.ChainId, "existing", z.WithdrawalWaitgroup, "decrement", num, "new", z.WithdrawalWaitgroup-num, "reason", reason) z.WithdrawalWaitgroup -= num return nil } func (z *Zone) IncrementWithdrawalWaitgroup(logger log.Logger, num uint32, reason string) error { - if uint32(z.WithdrawalWaitgroup+num) < z.WithdrawalWaitgroup { // overflow + if z.WithdrawalWaitgroup+num < z.WithdrawalWaitgroup { // overflow logger.Error("error incrementing withdrawal waitgroup: uint32 overflow ", "zone", z.ChainId, "existing", z.WithdrawalWaitgroup, "increment", num, "reason", reason) return errors.New("unable to increment the withdrawal waitgroup above 4294967295") } - logger.Info("incrementing withdrawal waitgroup", "zone", z.ChainId, "existing", z.WithdrawalWaitgroup, "increment", num, "new", uint32(z.WithdrawalWaitgroup+num), "reason", reason) + logger.Info("incrementing withdrawal waitgroup", "zone", z.ChainId, "existing", z.WithdrawalWaitgroup, "increment", num, "new", z.WithdrawalWaitgroup+num, "reason", reason) z.WithdrawalWaitgroup += num return nil } diff --git a/x/interchainstaking/types/zones_test.go b/x/interchainstaking/types/zones_test.go index 6f495082a..85e0690e1 100644 --- a/x/interchainstaking/types/zones_test.go +++ b/x/interchainstaking/types/zones_test.go @@ -43,7 +43,7 @@ func TestDecrementWithdrawalWg(t *testing.T) { testlog := log.NewNopLogger() zone := types.Zone{WithdrawalWaitgroup: 0} oldWg := zone.GetWithdrawalWaitgroup() - zone.IncrementWithdrawalWaitgroup(testlog, 1, "test increment") + require.NoError(t, zone.IncrementWithdrawalWaitgroup(testlog, 1, "test increment")) firstWg := zone.GetWithdrawalWaitgroup() require.Equal(t, oldWg+1, firstWg) require.NoError(t, zone.DecrementWithdrawalWaitgroup(testlog, 1, "test decrement")) @@ -87,7 +87,6 @@ func TestValidateCoinsForZone(t *testing.T) { valid, matches = zone.ValidateCoinsForZone(sdk.NewCoins(sdk.NewCoin("uatom", sdk.OneInt())), valAddresses) require.True(t, valid) require.True(t, matches) - } func TestCoinsToIntent(t *testing.T) {