Skip to content

Commit

Permalink
Add max for fee_charged and max_fee.
Browse files Browse the repository at this point in the history
  • Loading branch information
abuiles committed Nov 21, 2019
1 parent e005f1b commit 1c6f06a
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 66 deletions.
1 change: 1 addition & 0 deletions protocols/horizon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ type Metrics struct {
}

type feeStatsBase struct {
Max int `json:"max,string"`
Min int `json:"min,string"`
Mode int `json:"mode,string"`
P10 int `json:"p10,string"`
Expand Down
2 changes: 2 additions & 0 deletions services/horizon/internal/actions_operation_fee_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func (action *FeeStatsAction) loadRecords() {
action.FeeStats.LedgerCapacityUsage = ledgerCapacityUsage

// FeeCharged
action.FeeStats.FeeCharged.Max = int(cur.FeeChargedMax)
action.FeeStats.FeeCharged.Min = int(cur.FeeChargedMin)
action.FeeStats.FeeCharged.Mode = int(cur.FeeChargedMode)
action.FeeStats.FeeCharged.P10 = int(cur.FeeChargedP10)
Expand All @@ -82,6 +83,7 @@ func (action *FeeStatsAction) loadRecords() {
action.FeeStats.FeeCharged.P99 = int(cur.FeeChargedP99)

// MaxFee
action.FeeStats.MaxFee.Max = int(cur.FeeMax)
action.FeeStats.MaxFee.Min = int(cur.FeeMin)
action.FeeStats.MaxFee.Mode = int(cur.FeeMode)
action.FeeStats.MaxFee.P10 = int(cur.FeeP10)
Expand Down
143 changes: 78 additions & 65 deletions services/horizon/internal/actions_operation_fee_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ func TestOperationFeeTestsActions_Show(t *testing.T) {
testCases := []struct {
scenario string
lastbasefee int
max int
min int
mode int
p10 int
Expand All @@ -23,6 +24,7 @@ func TestOperationFeeTestsActions_Show(t *testing.T) {
p90 int
p95 int
p99 int
feeChargedMax int
feeChargedMin int
feeChargedMode int
feeChargedP10 int
Expand All @@ -42,6 +44,7 @@ func TestOperationFeeTestsActions_Show(t *testing.T) {
{
scenario: "operation_fee_stats_1",
lastbasefee: 100,
max: 100,
min: 100,
mode: 100,
p10: 100,
Expand All @@ -55,6 +58,7 @@ func TestOperationFeeTestsActions_Show(t *testing.T) {
p90: 100,
p95: 100,
p99: 100,
feeChargedMax: 100,
feeChargedMin: 100,
feeChargedMode: 100,
feeChargedP10: 100,
Expand All @@ -75,6 +79,7 @@ func TestOperationFeeTestsActions_Show(t *testing.T) {
scenario: "operation_fee_stats_2",
ledgerCapacityUsage: 0.00,
lastbasefee: 100,
max: 100,
min: 100,
mode: 100,
p10: 100,
Expand All @@ -88,6 +93,7 @@ func TestOperationFeeTestsActions_Show(t *testing.T) {
p90: 100,
p95: 100,
p99: 100,
feeChargedMax: 100,
feeChargedMin: 100,
feeChargedMode: 100,
feeChargedP10: 100,
Expand All @@ -107,6 +113,7 @@ func TestOperationFeeTestsActions_Show(t *testing.T) {
scenario: "operation_fee_stats_3",
ledgerCapacityUsage: 0.03,
lastbasefee: 100,
max: 400,
min: 200,
mode: 400,
p10: 200,
Expand All @@ -120,6 +127,7 @@ func TestOperationFeeTestsActions_Show(t *testing.T) {
p90: 400,
p95: 400,
p99: 400,
feeChargedMax: 100,
feeChargedMin: 100,
feeChargedMode: 100,
feeChargedP10: 100,
Expand Down Expand Up @@ -185,19 +193,20 @@ func TestOperationFeeTestsActions_Show(t *testing.T) {
ht.Assert.Equal(kase.p95, result.MaxFee.P95, "p95")
ht.Assert.Equal(kase.p99, result.MaxFee.P99, "p99")

ht.Assert.Equal(kase.feeChargedMin, result.FeeCharged.Min, "min")
ht.Assert.Equal(kase.feeChargedMode, result.FeeCharged.Mode, "mode")
ht.Assert.Equal(kase.feeChargedP10, result.FeeCharged.P10, "p10")
ht.Assert.Equal(kase.feeChargedP20, result.FeeCharged.P20, "p20")
ht.Assert.Equal(kase.feeChargedP30, result.FeeCharged.P30, "p30")
ht.Assert.Equal(kase.feeChargedP40, result.FeeCharged.P40, "p40")
ht.Assert.Equal(kase.feeChargedP50, result.FeeCharged.P50, "p50")
ht.Assert.Equal(kase.feeChargedP60, result.FeeCharged.P60, "p60")
ht.Assert.Equal(kase.feeChargedP70, result.FeeCharged.P70, "p70")
ht.Assert.Equal(kase.feeChargedP80, result.FeeCharged.P80, "p80")
ht.Assert.Equal(kase.feeChargedP90, result.FeeCharged.P90, "p90")
ht.Assert.Equal(kase.feeChargedP95, result.FeeCharged.P95, "p95")
ht.Assert.Equal(kase.feeChargedP99, result.FeeCharged.P99, "p99")
ht.Assert.Equal(kase.feeChargedMax, result.FeeCharged.Max, "fee_charged_max")
ht.Assert.Equal(kase.feeChargedMin, result.FeeCharged.Min, "fee_charged_min")
ht.Assert.Equal(kase.feeChargedMode, result.FeeCharged.Mode, "fee_charged_mode")
ht.Assert.Equal(kase.feeChargedP10, result.FeeCharged.P10, "fee_charged_p10")
ht.Assert.Equal(kase.feeChargedP20, result.FeeCharged.P20, "fee_charged_p20")
ht.Assert.Equal(kase.feeChargedP30, result.FeeCharged.P30, "fee_charged_p30")
ht.Assert.Equal(kase.feeChargedP40, result.FeeCharged.P40, "fee_charged_p40")
ht.Assert.Equal(kase.feeChargedP50, result.FeeCharged.P50, "fee_charged_p50")
ht.Assert.Equal(kase.feeChargedP60, result.FeeCharged.P60, "fee_charged_p60")
ht.Assert.Equal(kase.feeChargedP70, result.FeeCharged.P70, "fee_charged_p70")
ht.Assert.Equal(kase.feeChargedP80, result.FeeCharged.P80, "fee_charged_p80")
ht.Assert.Equal(kase.feeChargedP90, result.FeeCharged.P90, "fee_charged_p90")
ht.Assert.Equal(kase.feeChargedP95, result.FeeCharged.P95, "fee_charged_p95")
ht.Assert.Equal(kase.feeChargedP99, result.FeeCharged.P99, "fee_charged_p99")
}
})
}
Expand Down Expand Up @@ -243,33 +252,35 @@ func TestOperationFeeTestsActions_ShowMultiOp(t *testing.T) {
ht.Assert.Equal(200, result.P99AcceptedFee, "p99")

// AcceptedFee is an alias for MaxFee data
ht.Assert.Equal(100, result.MaxFee.Min, "min")
ht.Assert.Equal(200, result.MaxFee.Mode, "mode")
ht.Assert.Equal(100, result.MaxFee.P10, "p10")
ht.Assert.Equal(150, result.MaxFee.P20, "p20")
ht.Assert.Equal(200, result.MaxFee.P30, "p30")
ht.Assert.Equal(200, result.MaxFee.P40, "p40")
ht.Assert.Equal(200, result.MaxFee.P50, "p50")
ht.Assert.Equal(200, result.MaxFee.P60, "p60")
ht.Assert.Equal(200, result.MaxFee.P70, "p70")
ht.Assert.Equal(200, result.MaxFee.P80, "p80")
ht.Assert.Equal(200, result.MaxFee.P90, "p90")
ht.Assert.Equal(200, result.MaxFee.P95, "p95")
ht.Assert.Equal(200, result.MaxFee.P99, "p99")
ht.Assert.Equal(200, result.MaxFee.Max, "max_fee_max")
ht.Assert.Equal(100, result.MaxFee.Min, "max_fee_min")
ht.Assert.Equal(200, result.MaxFee.Mode, "max_fee_mode")
ht.Assert.Equal(100, result.MaxFee.P10, "max_fee_p10")
ht.Assert.Equal(150, result.MaxFee.P20, "max_fee_p20")
ht.Assert.Equal(200, result.MaxFee.P30, "max_fee_p30")
ht.Assert.Equal(200, result.MaxFee.P40, "max_fee_p40")
ht.Assert.Equal(200, result.MaxFee.P50, "max_fee_p50")
ht.Assert.Equal(200, result.MaxFee.P60, "max_fee_p60")
ht.Assert.Equal(200, result.MaxFee.P70, "max_fee_p70")
ht.Assert.Equal(200, result.MaxFee.P80, "max_fee_p80")
ht.Assert.Equal(200, result.MaxFee.P90, "max_fee_p90")
ht.Assert.Equal(200, result.MaxFee.P95, "max_fee_p95")
ht.Assert.Equal(200, result.MaxFee.P99, "max_fee_p99")

ht.Assert.Equal(50, result.FeeCharged.Min, "min")
ht.Assert.Equal(50, result.FeeCharged.Mode, "mode")
ht.Assert.Equal(50, result.FeeCharged.P10, "p10")
ht.Assert.Equal(50, result.FeeCharged.P20, "p20")
ht.Assert.Equal(50, result.FeeCharged.P30, "p30")
ht.Assert.Equal(50, result.FeeCharged.P40, "p40")
ht.Assert.Equal(50, result.FeeCharged.P50, "p50")
ht.Assert.Equal(50, result.FeeCharged.P60, "p60")
ht.Assert.Equal(50, result.FeeCharged.P70, "p70")
ht.Assert.Equal(50, result.FeeCharged.P80, "p80")
ht.Assert.Equal(50, result.FeeCharged.P90, "p90")
ht.Assert.Equal(50, result.FeeCharged.P95, "p95")
ht.Assert.Equal(50, result.FeeCharged.P99, "p99")
ht.Assert.Equal(50, result.FeeCharged.Max, "fee_charged_max")
ht.Assert.Equal(50, result.FeeCharged.Min, "fee_charged_min")
ht.Assert.Equal(50, result.FeeCharged.Mode, "fee_charged_mode")
ht.Assert.Equal(50, result.FeeCharged.P10, "fee_charged_p10")
ht.Assert.Equal(50, result.FeeCharged.P20, "fee_charged_p20")
ht.Assert.Equal(50, result.FeeCharged.P30, "fee_charged_p30")
ht.Assert.Equal(50, result.FeeCharged.P40, "fee_charged_p40")
ht.Assert.Equal(50, result.FeeCharged.P50, "fee_charged_p50")
ht.Assert.Equal(50, result.FeeCharged.P60, "fee_charged_p60")
ht.Assert.Equal(50, result.FeeCharged.P70, "fee_charged_p70")
ht.Assert.Equal(50, result.FeeCharged.P80, "fee_charged_p80")
ht.Assert.Equal(50, result.FeeCharged.P90, "fee_charged_p90")
ht.Assert.Equal(50, result.FeeCharged.P95, "fee_charged_p95")
ht.Assert.Equal(50, result.FeeCharged.P99, "fee_charged_p99")
}
}

Expand Down Expand Up @@ -310,32 +321,34 @@ func TestOperationFeeTestsActions_NotInterpolating(t *testing.T) {
ht.Assert.Equal(16000, result.P99AcceptedFee, "p99")

// AcceptedFee is an alias for MaxFee data
ht.Assert.Equal(200, result.MaxFee.Min, "min")
ht.Assert.Equal(400, result.MaxFee.Mode, "mode")
ht.Assert.Equal(200, result.MaxFee.P10, "p10")
ht.Assert.Equal(300, result.MaxFee.P20, "p20")
ht.Assert.Equal(400, result.MaxFee.P30, "p30")
ht.Assert.Equal(400, result.MaxFee.P40, "p40")
ht.Assert.Equal(400, result.MaxFee.P50, "p50")
ht.Assert.Equal(400, result.MaxFee.P60, "p60")
ht.Assert.Equal(400, result.MaxFee.P70, "p70")
ht.Assert.Equal(400, result.MaxFee.P80, "p80")
ht.Assert.Equal(16000, result.MaxFee.P90, "p90")
ht.Assert.Equal(16000, result.MaxFee.P95, "p95")
ht.Assert.Equal(16000, result.MaxFee.P99, "p99")
ht.Assert.Equal(16000, result.MaxFee.Max, "max_fee_max")
ht.Assert.Equal(200, result.MaxFee.Min, "max_fee_min")
ht.Assert.Equal(400, result.MaxFee.Mode, "max_fee_mode")
ht.Assert.Equal(200, result.MaxFee.P10, "max_fee_p10")
ht.Assert.Equal(300, result.MaxFee.P20, "max_fee_p20")
ht.Assert.Equal(400, result.MaxFee.P30, "max_fee_p30")
ht.Assert.Equal(400, result.MaxFee.P40, "max_fee_p40")
ht.Assert.Equal(400, result.MaxFee.P50, "max_fee_p50")
ht.Assert.Equal(400, result.MaxFee.P60, "max_fee_p60")
ht.Assert.Equal(400, result.MaxFee.P70, "max_fee_p70")
ht.Assert.Equal(400, result.MaxFee.P80, "max_fee_p80")
ht.Assert.Equal(16000, result.MaxFee.P90, "max_fee_p90")
ht.Assert.Equal(16000, result.MaxFee.P95, "max_fee_p95")
ht.Assert.Equal(16000, result.MaxFee.P99, "max_fee_p99")

ht.Assert.Equal(6, result.FeeCharged.Min, "min")
ht.Assert.Equal(100, result.FeeCharged.Mode, "mode")
ht.Assert.Equal(6, result.FeeCharged.P10, "p10")
ht.Assert.Equal(100, result.FeeCharged.P20, "p20")
ht.Assert.Equal(100, result.FeeCharged.P30, "p30")
ht.Assert.Equal(100, result.FeeCharged.P40, "p40")
ht.Assert.Equal(100, result.FeeCharged.P50, "p50")
ht.Assert.Equal(100, result.FeeCharged.P60, "p60")
ht.Assert.Equal(100, result.FeeCharged.P70, "p70")
ht.Assert.Equal(100, result.FeeCharged.P80, "p80")
ht.Assert.Equal(100, result.FeeCharged.P90, "p90")
ht.Assert.Equal(100, result.FeeCharged.P95, "p95")
ht.Assert.Equal(100, result.FeeCharged.P99, "p99")
ht.Assert.Equal(100, result.FeeCharged.Max, "fee_charged_max")
ht.Assert.Equal(6, result.FeeCharged.Min, "fee_charged_min")
ht.Assert.Equal(100, result.FeeCharged.Mode, "fee_charged_mode")
ht.Assert.Equal(6, result.FeeCharged.P10, "fee_charged_p10")
ht.Assert.Equal(100, result.FeeCharged.P20, "fee_charged_p20")
ht.Assert.Equal(100, result.FeeCharged.P30, "fee_charged_p30")
ht.Assert.Equal(100, result.FeeCharged.P40, "fee_charged_p40")
ht.Assert.Equal(100, result.FeeCharged.P50, "fee_charged_p50")
ht.Assert.Equal(100, result.FeeCharged.P60, "fee_charged_p60")
ht.Assert.Equal(100, result.FeeCharged.P70, "fee_charged_p70")
ht.Assert.Equal(100, result.FeeCharged.P80, "fee_charged_p80")
ht.Assert.Equal(100, result.FeeCharged.P90, "fee_charged_p90")
ht.Assert.Equal(100, result.FeeCharged.P95, "fee_charged_p95")
ht.Assert.Equal(100, result.FeeCharged.P99, "fee_charged_p99")
}
}
4 changes: 4 additions & 0 deletions services/horizon/internal/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ func (a *App) UpdateFeeStatsState() {
// latest ledger's base fee for all
if !feeStats.MaxFeeMode.Valid && !feeStats.MaxFeeMin.Valid {
// MaxFee
next.FeeMax = next.LastBaseFee
next.FeeMin = next.LastBaseFee
next.FeeMode = next.LastBaseFee
next.FeeP10 = next.LastBaseFee
Expand All @@ -278,6 +279,7 @@ func (a *App) UpdateFeeStatsState() {
next.FeeP99 = next.LastBaseFee

// FeeCharged
next.FeeChargedMax = next.LastBaseFee
next.FeeChargedMin = next.LastBaseFee
next.FeeChargedMode = next.LastBaseFee
next.FeeChargedP10 = next.LastBaseFee
Expand All @@ -294,6 +296,7 @@ func (a *App) UpdateFeeStatsState() {

} else {
// MaxFee
next.FeeMax = feeStats.MaxFeeMax.Int64
next.FeeMin = feeStats.MaxFeeMin.Int64
next.FeeMode = feeStats.MaxFeeMode.Int64
next.FeeP10 = feeStats.MaxFeeP10.Int64
Expand All @@ -309,6 +312,7 @@ func (a *App) UpdateFeeStatsState() {
next.FeeP99 = feeStats.MaxFeeP99.Int64

// FeeCharged
next.FeeChargedMax = feeStats.FeeChargedMax.Int64
next.FeeChargedMin = feeStats.FeeChargedMin.Int64
next.FeeChargedMode = feeStats.FeeChargedMode.Int64
next.FeeChargedP10 = feeStats.FeeChargedP10.Int64
Expand Down
2 changes: 2 additions & 0 deletions services/horizon/internal/db2/history/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ type EffectType int
// FeeStats is a row of data from the min, mode, percentile aggregate functions over the
// `history_transactions` table.
type FeeStats struct {
FeeChargedMax null.Int `db:"fee_charged_max"`
FeeChargedMin null.Int `db:"fee_charged_min"`
FeeChargedMode null.Int `db:"fee_charged_mode"`
FeeChargedP10 null.Int `db:"fee_charged_p10"`
Expand All @@ -305,6 +306,7 @@ type FeeStats struct {
FeeChargedP90 null.Int `db:"fee_charged_p90"`
FeeChargedP95 null.Int `db:"fee_charged_p95"`
FeeChargedP99 null.Int `db:"fee_charged_p99"`
MaxFeeMax null.Int `db:"max_fee_max"`
MaxFeeMin null.Int `db:"max_fee_min"`
MaxFeeMode null.Int `db:"max_fee_mode"`
MaxFeeP10 null.Int `db:"max_fee_p10"`
Expand Down
4 changes: 3 additions & 1 deletion services/horizon/internal/db2/history/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func (r *Operation) UnmarshalDetails(dest interface{}) error {
func (q *Q) FeeStats(currentSeq int32, dest *FeeStats) error {
return q.GetRaw(dest, `
SELECT
ceil(max(fee_charged/operation_count))::bigint AS "fee_charged_max",
ceil(min(fee_charged/operation_count))::bigint AS "fee_charged_min",
ceil(mode() within group (order by fee_charged/operation_count))::bigint AS "fee_charged_mode",
ceil(percentile_disc(0.10) WITHIN GROUP (ORDER BY fee_charged/operation_count))::bigint AS "fee_charged_p10",
Expand All @@ -56,7 +57,8 @@ func (q *Q) FeeStats(currentSeq int32, dest *FeeStats) error {
ceil(percentile_disc(0.80) WITHIN GROUP (ORDER BY fee_charged/operation_count))::bigint AS "fee_charged_p80",
ceil(percentile_disc(0.90) WITHIN GROUP (ORDER BY fee_charged/operation_count))::bigint AS "fee_charged_p90",
ceil(percentile_disc(0.95) WITHIN GROUP (ORDER BY fee_charged/operation_count))::bigint AS "fee_charged_p95",
ceil(percentile_disc(0.99) WITHIN GROUP (ORDER BY fee_charged/operation_count))::bigint AS "fee_charged_p99",
ceil(percentile_disc(0.99) WITHIN GROUP (ORDER BY fee_charged/operation_count))::bigint AS "fee_charged_p99",
ceil(max(max_fee/operation_count))::bigint AS "max_fee_max",
ceil(min(max_fee/operation_count))::bigint AS "max_fee_min",
ceil(mode() within group (order by max_fee/operation_count))::bigint AS "max_fee_mode",
ceil(percentile_disc(0.10) WITHIN GROUP (ORDER BY max_fee/operation_count))::bigint AS "max_fee_p10",
Expand Down
2 changes: 2 additions & 0 deletions services/horizon/internal/operationfeestats/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
// State represents a snapshot of horizon's view of the state of operation fee's
// on the network.
type State struct {
FeeChargedMax int64
FeeChargedMin int64
FeeChargedMode int64
FeeChargedP10 int64
Expand All @@ -27,6 +28,7 @@ type State struct {
FeeChargedP99 int64

// MaxFee
FeeMax int64
FeeMin int64
FeeMode int64
FeeP10 int64
Expand Down

0 comments on commit 1c6f06a

Please sign in to comment.