Skip to content

Commit 67b0b08

Browse files
authored
chore: update gosec rules and resolve errs (#2090)
1 parent 706fb44 commit 67b0b08

File tree

4 files changed

+38
-9
lines changed

4 files changed

+38
-9
lines changed

.github/workflows/gosec.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ jobs:
2828
- name: Run Gosec Security Scanner
2929
uses: securego/gosec@master
3030
with:
31-
args: -exclude-dir=tests ./... -exclude-generated ./...
31+
args: -exclude-dir=tests -exclude-dir=app -exclude-generated ./...

x/ccv/consumer/module.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,10 @@ func (am AppModule) BeginBlock(goCtx context.Context) error {
172172
am.keeper.SetHeightValsetUpdateID(ctx, blockHeight+1, vID)
173173
am.keeper.Logger(ctx).Debug("block height was mapped to vscID", "height", blockHeight+1, "vscID", vID)
174174

175-
am.keeper.TrackHistoricalInfo(ctx)
175+
err := am.keeper.TrackHistoricalInfo(ctx)
176+
if err != nil {
177+
am.keeper.Logger(ctx).Warn("failed to track historical info", "error", err)
178+
}
176179
return nil
177180
}
178181

x/ccv/democracy/distribution/module.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,12 @@ func (am AppModule) AllocateTokens(
127127
representativesFraction := math.LegacyOneDec().Sub(communityTax)
128128

129129
// allocate tokens proportionally to representatives voting power
130-
vs.IterateBondedValidatorsByPower(ctx, func(_ int64, validator stakingtypes.ValidatorI) bool {
130+
_ = vs.IterateBondedValidatorsByPower(ctx, func(_ int64, validator stakingtypes.ValidatorI) bool {
131131
// we get this validator's percentage of the total power by dividing their tokens by the total bonded tokens
132132
powerFraction := math.LegacyNewDecFromInt(validator.GetTokens()).QuoTruncate(math.LegacyNewDecFromInt(totalBondedTokens))
133133
// we truncate here again, which means that the reward will be slightly lower than it should be
134134
reward := feesCollected.MulDecTruncate(representativesFraction).MulDecTruncate(powerFraction)
135-
am.keeper.AllocateTokensToValidator(ctx, validator, reward)
135+
_ = am.keeper.AllocateTokensToValidator(ctx, validator, reward)
136136
remaining = remaining.Sub(reward)
137137

138138
return false

x/ccv/democracy/governance/module.go

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,41 @@ func deleteForbiddenProposal(ctx sdk.Context, am AppModule, proposal govv1.Propo
113113
return
114114
}
115115

116+
logger := am.keeper.Logger(ctx)
117+
116118
// delete the votes related to the proposal calling Tally
117119
// Tally's return result won't be used in decision if the tokens will be burned or refunded (they are always refunded), but
118120
// this function needs to be called to delete the votes related to the given proposal, since the deleteVote function is
119121
// private and cannot be called directly from the overridden app module
120-
am.keeper.Tally(ctx, proposal)
122+
_, _, _, err := am.keeper.Tally(ctx, proposal)
123+
if err != nil {
124+
logger.Warn(
125+
"failed to tally disallowed proposal",
126+
"proposal", proposal.Id,
127+
"title", proposal.GetTitle(),
128+
"total_deposit", proposal.TotalDeposit)
129+
return
130+
}
121131

122-
am.keeper.DeleteProposal(ctx, proposal.Id)
123-
am.keeper.RefundAndDeleteDeposits(ctx, proposal.Id)
132+
err = am.keeper.DeleteProposal(ctx, proposal.Id)
133+
if err != nil {
134+
logger.Warn(
135+
"failed to delete disallowed proposal",
136+
"proposal", proposal.Id,
137+
"title", proposal.GetTitle(),
138+
"total_deposit", proposal.TotalDeposit)
139+
return
140+
}
141+
142+
err = am.keeper.RefundAndDeleteDeposits(ctx, proposal.Id)
143+
if err != nil {
144+
logger.Warn(
145+
"failed to refund deposits for disallowed proposal",
146+
"proposal", proposal.Id,
147+
"title", proposal.GetTitle(),
148+
"total_deposit", proposal.TotalDeposit)
149+
return
150+
}
124151

125152
ctx.EventManager().EmitEvent(
126153
sdk.NewEvent(
@@ -130,9 +157,8 @@ func deleteForbiddenProposal(ctx sdk.Context, am AppModule, proposal govv1.Propo
130157
),
131158
)
132159

133-
logger := am.keeper.Logger(ctx)
134160
logger.Info(
135-
"proposal is not whitelisted; deleted",
161+
"proposal is not allowed; deleted",
136162
"proposal", proposal.Id,
137163
"title", proposal.GetTitle(),
138164
"total_deposit", proposal.TotalDeposit)

0 commit comments

Comments
 (0)