Skip to content

Commit a0a08d4

Browse files
envestccdustinxie
andauthored
[api] fix feeHistory (#4616)
Co-authored-by: dustinxie <[email protected]>
1 parent 07cb4a1 commit a0a08d4

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

gasstation/gasstattion.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ func (gs *GasStation) FeeHistory(ctx context.Context, blocks, lastBlock uint64,
137137
log.T(ctx).Warn("Sanitizing fee history length", zap.Uint64("requested", blocks), zap.Uint64("truncated", maxFeeHistory))
138138
blocks = maxFeeHistory
139139
}
140+
if blocks > lastBlock {
141+
blocks = lastBlock
142+
}
140143
for i, p := range rewardPercentiles {
141144
if p < 0 || p > 100 {
142145
return 0, nil, nil, nil, nil, nil, status.Error(codes.InvalidArgument, "percentile must be in [0, 100]")
@@ -199,7 +202,11 @@ func (gs *GasStation) FeeHistory(ctx context.Context, blocks, lastBlock uint64,
199202
}
200203
fees := make([]*big.Int, 0, len(receipts))
201204
for _, r := range receipts {
202-
fees = append(fees, r.PriorityFee())
205+
if pf := r.PriorityFee(); pf != nil {
206+
fees = append(fees, pf)
207+
} else {
208+
fees = append(fees, big.NewInt(0))
209+
}
203210
}
204211
sort.Slice(fees, func(i, j int) bool {
205212
return fees[i].Cmp(fees[j]) < 0

0 commit comments

Comments
 (0)