Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Bowman committed Feb 10, 2024
1 parent 7705109 commit b6bdf51
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 17 deletions.
4 changes: 3 additions & 1 deletion x/interchainstaking/keeper/callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions x/interchainstaking/keeper/callbacks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
8 changes: 6 additions & 2 deletions x/interchainstaking/keeper/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
}
6 changes: 3 additions & 3 deletions x/interchainstaking/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion x/interchainstaking/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
11 changes: 6 additions & 5 deletions x/interchainstaking/types/zones.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions x/interchainstaking/types/zones_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit b6bdf51

Please sign in to comment.