Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backfill fee stats data to make the client compatible with horizon 1.X and 0.X. #2290

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions clients/horizonclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,30 @@ func (c *Client) Metrics() (metrics hProtocol.Metrics, err error) {

// FeeStats returns information about fees in the last 5 ledgers.
// See https://www.stellar.org/developers/horizon/reference/endpoints/fee-stats.html
func (c *Client) FeeStats() (feestats hProtocol.FeeStats, err error) {
func (c *Client) FeeStats() (feeStats hProtocol.FeeStats, err error) {
request := feeStatsRequest{endpoint: "fee_stats"}
err = c.sendRequest(request, &feestats)
err = c.sendRequest(request, &feeStats)
if err != nil {
return
}

// Action needed in release: horizonclient-v3.0.0
// Remove this back-fill, this is done to allow people to use this client
// with horizon < 1.0 or >= 1.0
feeStats.MinAcceptedFee = int(feeStats.MaxFee.Min)
feeStats.ModeAcceptedFee = int(feeStats.MaxFee.Mode)
feeStats.P10AcceptedFee = int(feeStats.MaxFee.P10)
feeStats.P20AcceptedFee = int(feeStats.MaxFee.P20)
feeStats.P30AcceptedFee = int(feeStats.MaxFee.P30)
feeStats.P40AcceptedFee = int(feeStats.MaxFee.P40)
feeStats.P50AcceptedFee = int(feeStats.MaxFee.P50)
feeStats.P60AcceptedFee = int(feeStats.MaxFee.P60)
feeStats.P70AcceptedFee = int(feeStats.MaxFee.P70)
feeStats.P80AcceptedFee = int(feeStats.MaxFee.P80)
feeStats.P90AcceptedFee = int(feeStats.MaxFee.P90)
feeStats.P95AcceptedFee = int(feeStats.MaxFee.P95)
feeStats.P99AcceptedFee = int(feeStats.MaxFee.P99)

return
}

Expand Down
44 changes: 31 additions & 13 deletions clients/horizonclient/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1363,19 +1363,37 @@ var feesResponse = `{
"last_ledger": "22606298",
"last_ledger_base_fee": "100",
"ledger_capacity_usage": "0.97",
"min_accepted_fee": "130",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't these fields be kept, not removed? These are the ones being backfilled right, so we'd expect them in the response, wouldn't we?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ire-and-curses no, they are being removed from the response and then we backfill from the values in max_fee -- but the backfill doesn't happen in the response but inside the FeeStat struct which is what we do here
https://github.com/stellar/go/pull/2290/files#diff-a12e7e90b7de9b52aa97a8dca1ea276cR324

"mode_accepted_fee": "250",
"p10_accepted_fee": "150",
"p20_accepted_fee": "200",
"p30_accepted_fee": "300",
"p40_accepted_fee": "400",
"p50_accepted_fee": "500",
"p60_accepted_fee": "1000",
"p70_accepted_fee": "2000",
"p80_accepted_fee": "3000",
"p90_accepted_fee": "4000",
"p95_accepted_fee": "5000",
"p99_accepted_fee": "8000"
"fee_charged": {
"max": "100",
"min": "100",
"mode": "100",
"p10": "100",
"p20": "100",
"p30": "100",
"p40": "100",
"p50": "100",
"p60": "100",
"p70": "100",
"p80": "100",
"p90": "100",
"p95": "100",
"p99": "100"
},
"max_fee": {
"min": "130",
"mode": "250",
"p10": "150",
"p20": "200",
"p30": "300",
"p40": "400",
"p50": "500",
"p60": "1000",
"p70": "2000",
"p80": "3000",
"p90": "4000",
"p95": "5000",
"p99": "8000"
}
}`

var offersResponse = `{
Expand Down