Skip to content

Commit

Permalink
fix: check for empty tier slices and use int for slice indexes
Browse files Browse the repository at this point in the history
Signed-off-by: Elias Van Ootegem <[email protected]>
  • Loading branch information
EVODelavega committed Sep 11, 2024
1 parent 30f651a commit 9910cd9
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 9910cd9

Please sign in to comment.