From 9910cd91d3dff4b5525e7bb633d463f9e8cd439d Mon Sep 17 00:00:00 2001 From: Elias Van Ootegem Date: Wed, 11 Sep 2024 17:54:39 +0100 Subject: [PATCH] fix: check for empty tier slices and use int for slice indexes Signed-off-by: Elias Van Ootegem --- datanode/service/party_stats.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/datanode/service/party_stats.go b/datanode/service/party_stats.go index 14893b0b22..733d159147 100644 --- a/datanode/service/party_stats.go +++ b/datanode/service/party_stats.go @@ -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 } } @@ -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 } }