Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check for empty tier slices and use int for slice indexes #11675

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading