From 6218f7b86868c7f85b401497b0ae48bb3aa240f9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:57:53 +0400 Subject: [PATCH 1/2] chore(deps): bump golangci/golangci-lint-action from 3 to 4 (#1137) Bumps [golangci/golangci-lint-action](https://github.com/golangci/golangci-lint-action) from 3 to 4. - [Release notes](https://github.com/golangci/golangci-lint-action/releases) - [Commits](https://github.com/golangci/golangci-lint-action/compare/v3...v4) --- updated-dependencies: - dependency-name: golangci/golangci-lint-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/golangci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/golangci.yml b/.github/workflows/golangci.yml index a3611b7f3..4158f8f20 100644 --- a/.github/workflows/golangci.yml +++ b/.github/workflows/golangci.yml @@ -30,7 +30,7 @@ jobs: go-version: '1.21' cache: false - name: golangci-lint - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v4 with: # Require: The version of golangci-lint to use. # When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version. From 9850a443c0df6aaa1bb183f42ae406206f9a1e44 Mon Sep 17 00:00:00 2001 From: Tien Nguyen Date: Mon, 12 Feb 2024 22:59:30 +0700 Subject: [PATCH 2/2] Ensure safe casting from math.Int to go primitive type. (#1134) * Ensure safe casting from math.Int to go primitive type. * Fix lint revive. * add arm64 again * Revert "add arm64 again" This reverts commit 4ac37295b32b9be9285df7959f8fbdae7189c4b3. --------- Co-authored-by: Jacob Gadikian --- x/interchainstaking/keeper/grpc_query.go | 9 ++++++--- x/interchainstaking/keeper/keeper.go | 5 +++++ x/interchainstaking/keeper/redemptions.go | 2 +- x/interchainstaking/keeper/withdrawal_record.go | 2 +- x/interchainstaking/types/redemptions.go | 6 +++--- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/x/interchainstaking/keeper/grpc_query.go b/x/interchainstaking/keeper/grpc_query.go index e36a61ace..e8cd63105 100644 --- a/x/interchainstaking/keeper/grpc_query.go +++ b/x/interchainstaking/keeper/grpc_query.go @@ -181,15 +181,18 @@ func (k *Keeper) Delegations(c context.Context, req *types.QueryDelegationsReque } delegations := make([]types.Delegation, 0) - var sum int64 + sum := sdk.ZeroInt() k.IterateAllDelegations(ctx, zone.ChainId, func(delegation types.Delegation) (stop bool) { delegations = append(delegations, delegation) - sum += delegation.Amount.Amount.Int64() + sum = sum.Add(delegation.Amount.Amount) return false }) - return &types.QueryDelegationsResponse{Delegations: delegations, Tvl: sum}, nil + if sum.IsInt64() { + return &types.QueryDelegationsResponse{Delegations: delegations, Tvl: sum.Int64()}, nil + } + return &types.QueryDelegationsResponse{Delegations: delegations}, status.Error(codes.OutOfRange, "tvl out of bound Int64") } func (k *Keeper) Receipts(c context.Context, req *types.QueryReceiptsRequest) (*types.QueryReceiptsResponse, error) { diff --git a/x/interchainstaking/keeper/keeper.go b/x/interchainstaking/keeper/keeper.go index d6520d7f3..4d0322702 100644 --- a/x/interchainstaking/keeper/keeper.go +++ b/x/interchainstaking/keeper/keeper.go @@ -739,6 +739,11 @@ func (k *Keeper) Rebalance(ctx sdk.Context, zone *types.Zone, epochNumber int64) for _, rebalance := range rebalances { if rebalance.Amount.GTE(sdk.NewInt(1_000_000)) { // don't redelegate dust; TODO: config per zone + if !rebalance.Amount.IsInt64() { + k.Logger(ctx).Error("Rebalance amount out of bound Int64", "amount", rebalance.Amount.String()) + // Ignore this + continue + } msgs = append(msgs, &stakingtypes.MsgBeginRedelegate{DelegatorAddress: zone.DelegationAddress.Address, ValidatorSrcAddress: rebalance.Source, ValidatorDstAddress: rebalance.Target, Amount: sdk.NewCoin(zone.BaseDenom, rebalance.Amount)}) k.SetRedelegationRecord(ctx, types.RedelegationRecord{ ChainId: zone.ChainId, diff --git a/x/interchainstaking/keeper/redemptions.go b/x/interchainstaking/keeper/redemptions.go index 78d624ebf..f9fe6d06a 100644 --- a/x/interchainstaking/keeper/redemptions.go +++ b/x/interchainstaking/keeper/redemptions.go @@ -404,7 +404,7 @@ WITHDRAWAL: } if !sumIn.Equal(sumOut) { - return nil, nil, nil, fmt.Errorf("sumIn <-> sumOut mismatch; sumIn = %d, sumOut = %d", sumIn.Amount.Int64(), sumOut.Amount.Int64()) + return nil, nil, nil, fmt.Errorf("sumIn <-> sumOut mismatch; sumIn = %s, sumOut = %s", sumIn.Amount.String(), sumOut.Amount.String()) } return coinsOutPerValidator, txHashesPerValidator, distributionsPerWithdrawal, nil diff --git a/x/interchainstaking/keeper/withdrawal_record.go b/x/interchainstaking/keeper/withdrawal_record.go index 7c8a87623..f18ab350f 100644 --- a/x/interchainstaking/keeper/withdrawal_record.go +++ b/x/interchainstaking/keeper/withdrawal_record.go @@ -245,7 +245,7 @@ func (k *Keeper) UpdateWithdrawalRecordsForSlash(ctx sdk.Context, zone *types.Zo thisSubAmount := distAmount.TruncateInt().Sub(newAmount) recordSubAmount = recordSubAmount.Add(thisSubAmount) d.Amount = newAmount.Uint64() - k.Logger(ctx).Info("Updated withdrawal record due to slashing", "valoper", valoper, "old_amount", d.Amount, "new_amount", newAmount.Int64(), "sub_amount", thisSubAmount.Int64()) + k.Logger(ctx).Info("Updated withdrawal record due to slashing", "valoper", valoper, "old_amount", d.Amount, "new_amount", newAmount.String(), "sub_amount", thisSubAmount.String()) } record.Distribution = distr subAmount := sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, recordSubAmount)) diff --git a/x/interchainstaking/types/redemptions.go b/x/interchainstaking/types/redemptions.go index 07b642df2..ec985b026 100644 --- a/x/interchainstaking/types/redemptions.go +++ b/x/interchainstaking/types/redemptions.go @@ -28,7 +28,7 @@ func DetermineAllocationsForUndelegation(currentAllocations map[string]math.Int, } if !amount[0].Amount.IsPositive() { - return outWeights, fmt.Errorf("amount was invalid, expected positive value, got %d", amount[0].Amount.Int64()) + return outWeights, fmt.Errorf("amount was invalid, expected positive value, got %s", amount[0].Amount.String()) } input := amount[0].Amount underAllocated, overAllocated := CalculateAllocationDeltas(currentAllocations, lockedAllocations, currentSum /* .Sub(input) */, targetAllocations, make(map[string]math.Int)) @@ -159,7 +159,7 @@ func DetermineAllocationsForUndelegation(currentAllocations map[string]math.Int, } if !outSum.LTE(amount[0].Amount) { - return map[string]math.Int{}, fmt.Errorf("outSum (%d) is unexpectedly greater than the input amount (%d), aborting", outSum.Int64(), amount[0].Amount.Int64()) + return map[string]math.Int{}, fmt.Errorf("outSum (%s) is unexpectedly greater than the input amount (%s), aborting", outSum.String(), amount[0].Amount.String()) } if input.IsNegative() { return map[string]math.Int{}, fmt.Errorf("input is unexpectedly negative (2), aborting") @@ -317,7 +317,7 @@ func DetermineAllocationsForUndelegationPredef(currentAllocations map[string]mat } if !outSum.LTE(amount[0].Amount) { - return map[string]math.Int{}, fmt.Errorf("outSum (%d) is unexpectedly greater than the input amount (%d), aborting", outSum.Int64(), amount[0].Amount.Int64()) + return map[string]math.Int{}, fmt.Errorf("outSum (%s) is unexpectedly greater than the input amount (%s), aborting", outSum.String(), amount[0].Amount.String()) } if input.IsNegative() { return map[string]math.Int{}, fmt.Errorf("input is unexpectedly negative (2), aborting")