Skip to content

Commit

Permalink
Merge pull request #11675 from vegaprotocol/fix-underflow
Browse files Browse the repository at this point in the history
fix: check for empty tier slices and use int for slice indexes
  • Loading branch information
jeremyletang authored Sep 11, 2024
2 parents 30f651a + 9910cd9 commit 1faa950
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions datanode/service/party_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,14 @@ func (s *PSvc) getVolumeDiscountTier(ctx context.Context, stats entities.Flatten
if err != nil {
return nil, err
}
for i := uint64(len(current.BenefitTiers)) - 1; i >= uint64(0); i-- {
if len(current.BenefitTiers) == 0 {
return nil, nil
}
for i := len(current.BenefitTiers) - 1; i >= 0; i-- {
dt := current.BenefitTiers[i]
minV, _ := num.DecimalFromString(dt.MinimumRunningNotionalTakerVolume)
if vol.GreaterThanOrEqual(minV) {
dt.TierNumber = &i
dt.TierNumber = ptr.From(uint64(i))
return dt, nil
}
}
Expand All @@ -300,11 +303,14 @@ func (s *PSvc) getVolumeRebateTier(ctx context.Context, stats entities.FlattenVo
if err != nil {
return nil, err
}
for i := uint64(len(current.BenefitTiers)) - 1; i >= uint64(0); i-- {
if len(current.BenefitTiers) == 0 {
return nil, nil
}
for i := len(current.BenefitTiers) - 1; i >= 0; i-- {
bt := current.BenefitTiers[i]
minF, _ := num.DecimalFromString(bt.MinimumPartyMakerVolumeFraction)
if vf.GreaterThanOrEqual(minF) {
bt.TierNumber = &i
bt.TierNumber = ptr.From(uint64(i))
return bt, nil
}
}
Expand Down

0 comments on commit 1faa950

Please sign in to comment.