diff --git a/cmd/soroban-rpc/internal/feewindow/feewindow.go b/cmd/soroban-rpc/internal/feewindow/feewindow.go index 66e78735..4adc4880 100644 --- a/cmd/soroban-rpc/internal/feewindow/feewindow.go +++ b/cmd/soroban-rpc/internal/feewindow/feewindow.go @@ -26,7 +26,7 @@ type FeeDistribution struct { P90 uint64 P95 uint64 P99 uint64 - FeeCount uint64 + FeeCount uint32 LedgerCount uint32 } @@ -90,11 +90,11 @@ func computeFeeDistribution(fees []uint64, ledgerCount uint32) FeeDistribution { mode = fees[len(fees)-1] } - count := uint64(len(fees)) + count := len(fees) // nearest-rank percentile percentile := func(p uint64) uint64 { // ceiling(p*count/100) - kth := ((p * count) + 100 - 1) / 100 + kth := ((p * uint64(count)) + 100 - 1) / 100 return fees[kth-1] } return FeeDistribution{ @@ -112,7 +112,7 @@ func computeFeeDistribution(fees []uint64, ledgerCount uint32) FeeDistribution { P90: percentile(90), P95: percentile(95), P99: percentile(99), - FeeCount: count, + FeeCount: uint32(count), LedgerCount: ledgerCount, } } diff --git a/cmd/soroban-rpc/internal/feewindow/feewindow_test.go b/cmd/soroban-rpc/internal/feewindow/feewindow_test.go index c4391e1e..53969ff2 100644 --- a/cmd/soroban-rpc/internal/feewindow/feewindow_test.go +++ b/cmd/soroban-rpc/internal/feewindow/feewindow_test.go @@ -284,7 +284,7 @@ func alternativeComputeFeeDistribution(fees []uint64, ledgerCount uint32) (FeeDi P90: uint64(p90), P95: uint64(p95), P99: uint64(p99), - FeeCount: uint64(len(fees)), + FeeCount: uint32(len(fees)), LedgerCount: ledgerCount, } return result, nil diff --git a/cmd/soroban-rpc/internal/methods/get_fee_stats.go b/cmd/soroban-rpc/internal/methods/get_fee_stats.go index ca41380a..e1f1182b 100644 --- a/cmd/soroban-rpc/internal/methods/get_fee_stats.go +++ b/cmd/soroban-rpc/internal/methods/get_fee_stats.go @@ -9,42 +9,42 @@ import ( ) type FeeDistribution struct { - Max uint64 `json:"max,string"` - Min uint64 `json:"min,string"` - Mode uint64 `json:"mode,string"` - P10 uint64 `json:"p10,string"` - P20 uint64 `json:"p20,string"` - P30 uint64 `json:"p30,string"` - P40 uint64 `json:"p40,string"` - P50 uint64 `json:"p50,string"` - P60 uint64 `json:"p60,string"` - P70 uint64 `json:"p70,string"` - P80 uint64 `json:"p80,string"` - P90 uint64 `json:"p90,string"` - P95 uint64 `json:"p95,string"` - P99 uint64 `json:"p99,string"` - FeeCount uint64 `json:"feeCount,string"` - LedgerCount uint32 `json:"ledgerCount"` + Max uint64 `json:"max,string"` + Min uint64 `json:"min,string"` + Mode uint64 `json:"mode,string"` + P10 uint64 `json:"p10,string"` + P20 uint64 `json:"p20,string"` + P30 uint64 `json:"p30,string"` + P40 uint64 `json:"p40,string"` + P50 uint64 `json:"p50,string"` + P60 uint64 `json:"p60,string"` + P70 uint64 `json:"p70,string"` + P80 uint64 `json:"p80,string"` + P90 uint64 `json:"p90,string"` + P95 uint64 `json:"p95,string"` + P99 uint64 `json:"p99,string"` + TransactionCount uint32 `json:"transactionCount,string"` + LedgerCount uint32 `json:"ledgerCount"` } func convertFeeDistribution(distribution feewindow.FeeDistribution) FeeDistribution { return FeeDistribution{ - Max: distribution.Max, - Min: distribution.Min, - Mode: distribution.Mode, - P10: distribution.P10, - P20: distribution.P20, - P30: distribution.P30, - P40: distribution.P40, - P50: distribution.P50, - P60: distribution.P60, - P70: distribution.P70, - P80: distribution.P80, - P90: distribution.P90, - P95: distribution.P95, - P99: distribution.P99, - FeeCount: distribution.FeeCount, - LedgerCount: distribution.LedgerCount, + Max: distribution.Max, + Min: distribution.Min, + Mode: distribution.Mode, + P10: distribution.P10, + P20: distribution.P20, + P30: distribution.P30, + P40: distribution.P40, + P50: distribution.P50, + P60: distribution.P60, + P70: distribution.P70, + P80: distribution.P80, + P90: distribution.P90, + P95: distribution.P95, + P99: distribution.P99, + TransactionCount: distribution.FeeCount, + LedgerCount: distribution.LedgerCount, } } diff --git a/cmd/soroban-rpc/internal/test/get_fee_stats_test.go b/cmd/soroban-rpc/internal/test/get_fee_stats_test.go index edaf8602..b1de24e7 100644 --- a/cmd/soroban-rpc/internal/test/get_fee_stats_test.go +++ b/cmd/soroban-rpc/internal/test/get_fee_stats_test.go @@ -76,40 +76,40 @@ func TestGetFeeStats(t *testing.T) { } expectedResult := methods.GetFeeStatsResult{ SorobanInclusionFee: methods.FeeDistribution{ - Max: sorobanInclusionFee, - Min: sorobanInclusionFee, - Mode: sorobanInclusionFee, - P10: sorobanInclusionFee, - P20: sorobanInclusionFee, - P30: sorobanInclusionFee, - P40: sorobanInclusionFee, - P50: sorobanInclusionFee, - P60: sorobanInclusionFee, - P70: sorobanInclusionFee, - P80: sorobanInclusionFee, - P90: sorobanInclusionFee, - P95: sorobanInclusionFee, - P99: sorobanInclusionFee, - FeeCount: 1, - LedgerCount: result.SorobanInclusionFee.LedgerCount, + Max: sorobanInclusionFee, + Min: sorobanInclusionFee, + Mode: sorobanInclusionFee, + P10: sorobanInclusionFee, + P20: sorobanInclusionFee, + P30: sorobanInclusionFee, + P40: sorobanInclusionFee, + P50: sorobanInclusionFee, + P60: sorobanInclusionFee, + P70: sorobanInclusionFee, + P80: sorobanInclusionFee, + P90: sorobanInclusionFee, + P95: sorobanInclusionFee, + P99: sorobanInclusionFee, + TransactionCount: 1, + LedgerCount: result.SorobanInclusionFee.LedgerCount, }, InclusionFee: methods.FeeDistribution{ - Max: classicFee, - Min: classicFee, - Mode: classicFee, - P10: classicFee, - P20: classicFee, - P30: classicFee, - P40: classicFee, - P50: classicFee, - P60: classicFee, - P70: classicFee, - P80: classicFee, - P90: classicFee, - P95: classicFee, - P99: classicFee, - FeeCount: 1, - LedgerCount: result.InclusionFee.LedgerCount, + Max: classicFee, + Min: classicFee, + Mode: classicFee, + P10: classicFee, + P20: classicFee, + P30: classicFee, + P40: classicFee, + P50: classicFee, + P60: classicFee, + P70: classicFee, + P80: classicFee, + P90: classicFee, + P95: classicFee, + P99: classicFee, + TransactionCount: 1, + LedgerCount: result.InclusionFee.LedgerCount, }, LatestLedger: result.LatestLedger, }