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

services/horizon: Add --max-assets-per-path-request flag #4046

Merged
merged 2 commits into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions services/horizon/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ file. This project adheres to [Semantic Versioning](http://semver.org/).

### Changes

* Add a new horizon flag `--max-assets-per-path-request` (`15` by default) that sets the number of assets to consider for strict-send and strict-recieve ([4046](https://github.com/stellar/go/pull/4046))
* Add `is_source=true` parameter to transaction endpoints (e.g. `GET /accounts/{account_id}/transactions?is_source=true` ) to
allow filtering transactions based on their source account. [4044](https://github.com/stellar/go/pull/4044)
* Add an endpoint that allows querying for which liquidity pools an account is participating in [4043](https://github.com/stellar/go/pull/4043)
Expand Down
35 changes: 20 additions & 15 deletions services/horizon/internal/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ func (a *App) HorizonSession() db.SessionInterface {
return a.historyQ.SessionInterface.Clone()
}

func (a *App) Config() Config {
return a.config
}

// UpdateCoreLedgerState triggers a refresh of Stellar-Core ledger state.
// This is done separately from Horizon ledger state update to prevent issues
// in case Stellar-Core query timeout.
Expand Down Expand Up @@ -511,21 +515,22 @@ func (a *App) init() error {
initTxSubMetrics(a)

routerConfig := httpx.RouterConfig{
DBSession: a.historyQ.SessionInterface,
TxSubmitter: a.submitter,
RateQuota: a.config.RateQuota,
BehindCloudflare: a.config.BehindCloudflare,
BehindAWSLoadBalancer: a.config.BehindAWSLoadBalancer,
SSEUpdateFrequency: a.config.SSEUpdateFrequency,
StaleThreshold: a.config.StaleThreshold,
ConnectionTimeout: a.config.ConnectionTimeout,
NetworkPassphrase: a.config.NetworkPassphrase,
MaxPathLength: a.config.MaxPathLength,
PathFinder: a.paths,
PrometheusRegistry: a.prometheusRegistry,
CoreGetter: a,
HorizonVersion: a.horizonVersion,
FriendbotURL: a.config.FriendbotURL,
DBSession: a.historyQ.SessionInterface,
TxSubmitter: a.submitter,
RateQuota: a.config.RateQuota,
BehindCloudflare: a.config.BehindCloudflare,
BehindAWSLoadBalancer: a.config.BehindAWSLoadBalancer,
SSEUpdateFrequency: a.config.SSEUpdateFrequency,
StaleThreshold: a.config.StaleThreshold,
ConnectionTimeout: a.config.ConnectionTimeout,
NetworkPassphrase: a.config.NetworkPassphrase,
MaxPathLength: a.config.MaxPathLength,
MaxAssetsPerPathRequest: a.config.MaxAssetsPerPathRequest,
PathFinder: a.paths,
PrometheusRegistry: a.prometheusRegistry,
CoreGetter: a,
HorizonVersion: a.horizonVersion,
FriendbotURL: a.config.FriendbotURL,
HealthCheck: healthCheck{
session: a.historyQ.SessionInterface,
ctx: a.ctx,
Expand Down
6 changes: 4 additions & 2 deletions services/horizon/internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ type Config struct {
LogFile string

// MaxPathLength is the maximum length of the path returned by `/paths` endpoint.
MaxPathLength uint
DisablePoolPathFinding bool
MaxPathLength uint
// MaxAssetsPerPathRequest is the maximum number of assets considered for `/paths/strict-send` and `/paths/strict-recieve`
MaxAssetsPerPathRequest int
DisablePoolPathFinding bool

NetworkPassphrase string
SentryDSN string
Expand Down
7 changes: 7 additions & 0 deletions services/horizon/internal/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,13 @@ func Flags() (*Config, support.ConfigOptions) {
FlagDefault: uint(3),
Usage: "the maximum number of assets on the path in `/paths` endpoint, warning: increasing this value will increase /paths response time",
},
&support.ConfigOption{
Name: "max-assets-per-path-request",
ConfigKey: &config.MaxAssetsPerPathRequest,
OptType: types.Int,
FlagDefault: int(15),
Usage: "the maximum number of assets in '/paths/strict-send' and '/paths/strict-recieve' endpoints",
},
&support.ConfigOption{
Name: "disable-pool-path-finding",
ConfigKey: &config.DisablePoolPathFinding,
Expand Down
33 changes: 16 additions & 17 deletions services/horizon/internal/httpx/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,26 @@ import (
"github.com/stellar/go/support/render/problem"
)

const maxAssetsForPathFinding = 15

type RouterConfig struct {
DBSession db.SessionInterface
PrimaryDBSession db.SessionInterface
TxSubmitter *txsub.System
RateQuota *throttled.RateQuota

BehindCloudflare bool
BehindAWSLoadBalancer bool
SSEUpdateFrequency time.Duration
StaleThreshold uint
ConnectionTimeout time.Duration
NetworkPassphrase string
MaxPathLength uint
PathFinder paths.Finder
PrometheusRegistry *prometheus.Registry
CoreGetter actions.CoreStateGetter
HorizonVersion string
FriendbotURL *url.URL
HealthCheck http.Handler
BehindCloudflare bool
BehindAWSLoadBalancer bool
SSEUpdateFrequency time.Duration
StaleThreshold uint
ConnectionTimeout time.Duration
NetworkPassphrase string
MaxPathLength uint
MaxAssetsPerPathRequest int
PathFinder paths.Finder
PrometheusRegistry *prometheus.Registry
CoreGetter actions.CoreStateGetter
HorizonVersion string
FriendbotURL *url.URL
HealthCheck http.Handler
}

type Router struct {
Expand Down Expand Up @@ -189,13 +188,13 @@ func (r *Router) addRoutes(config *RouterConfig, rateLimiter *throttled.HTTPRate
StaleThreshold: config.StaleThreshold,
SetLastLedgerHeader: true,
MaxPathLength: config.MaxPathLength,
MaxAssetsParamLength: maxAssetsForPathFinding,
MaxAssetsParamLength: config.MaxAssetsPerPathRequest,
PathFinder: config.PathFinder,
}}
findFixedPaths := ObjectActionHandler{actions.FindFixedPathsHandler{
MaxPathLength: config.MaxPathLength,
SetLastLedgerHeader: true,
MaxAssetsParamLength: maxAssetsForPathFinding,
MaxAssetsParamLength: config.MaxAssetsPerPathRequest,
PathFinder: config.PathFinder,
}}
r.With(stateMiddleware.Wrap).Method(http.MethodGet, "/paths", findPaths)
Expand Down
19 changes: 19 additions & 0 deletions services/horizon/internal/integration/parameters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,25 @@ func TestCaptiveCoreConfigFilesystemState(t *testing.T) {
})
}

func TestMaxAssetsForPathRequests(t *testing.T) {
t.Run("default", func(t *testing.T) {
test := NewParameterTest(t, map[string]string{})
err := test.StartHorizon()
assert.NoError(t, err)
test.WaitForHorizon()
assert.Equal(t, test.Horizon().Config().MaxAssetsPerPathRequest, 15)
test.Shutdown()
})
t.Run("set to 2", func(t *testing.T) {
test := NewParameterTest(t, map[string]string{"max-assets-per-path-request": "2"})
err := test.StartHorizon()
assert.NoError(t, err)
test.WaitForHorizon()
assert.Equal(t, test.Horizon().Config().MaxAssetsPerPathRequest, 2)
test.Shutdown()
})
}

// Pattern taken from testify issue:
// https://github.com/stretchr/testify/issues/858#issuecomment-600491003
//
Expand Down