Skip to content

Commit

Permalink
Use transactionCount instead of feeCount
Browse files Browse the repository at this point in the history
  • Loading branch information
2opremio committed May 16, 2024
1 parent bd0eb1d commit c3e1eb2
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 69 deletions.
8 changes: 4 additions & 4 deletions cmd/soroban-rpc/internal/feewindow/feewindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type FeeDistribution struct {
P90 uint64
P95 uint64
P99 uint64
FeeCount uint64
FeeCount uint32
LedgerCount uint32
}

Expand Down Expand Up @@ -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{
Expand All @@ -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,
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-rpc/internal/feewindow/feewindow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
64 changes: 32 additions & 32 deletions cmd/soroban-rpc/internal/methods/get_fee_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

}
Expand Down
64 changes: 32 additions & 32 deletions cmd/soroban-rpc/internal/test/get_fee_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down

0 comments on commit c3e1eb2

Please sign in to comment.