From 2226900ed2f8e717cbfe44da9e3592afed40a67b Mon Sep 17 00:00:00 2001 From: erika-sdf <92893480+erika-sdf@users.noreply.github.com> Date: Fri, 5 Nov 2021 11:01:46 -0700 Subject: [PATCH] Add --max_assets_per_path_request flag (#4046) --- services/horizon/CHANGELOG.md | 1 + services/horizon/internal/app.go | 35 +++++++++++-------- services/horizon/internal/config.go | 6 ++-- services/horizon/internal/flags.go | 7 ++++ services/horizon/internal/httpx/router.go | 33 +++++++++-------- .../internal/integration/parameters_test.go | 19 ++++++++++ 6 files changed, 67 insertions(+), 34 deletions(-) diff --git a/services/horizon/CHANGELOG.md b/services/horizon/CHANGELOG.md index 128dd1fdcc..c17294090a 100644 --- a/services/horizon/CHANGELOG.md +++ b/services/horizon/CHANGELOG.md @@ -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) diff --git a/services/horizon/internal/app.go b/services/horizon/internal/app.go index 4a8e0b7e30..48be02d14c 100644 --- a/services/horizon/internal/app.go +++ b/services/horizon/internal/app.go @@ -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. @@ -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, diff --git a/services/horizon/internal/config.go b/services/horizon/internal/config.go index 8c0d46cf50..b9e69d3b36 100644 --- a/services/horizon/internal/config.go +++ b/services/horizon/internal/config.go @@ -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 diff --git a/services/horizon/internal/flags.go b/services/horizon/internal/flags.go index 4c6fdf7675..7c47c1292e 100644 --- a/services/horizon/internal/flags.go +++ b/services/horizon/internal/flags.go @@ -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, diff --git a/services/horizon/internal/httpx/router.go b/services/horizon/internal/httpx/router.go index 7a825aebef..922f5ac7af 100644 --- a/services/horizon/internal/httpx/router.go +++ b/services/horizon/internal/httpx/router.go @@ -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 { @@ -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) diff --git a/services/horizon/internal/integration/parameters_test.go b/services/horizon/internal/integration/parameters_test.go index 204cd8bd86..3679b146e3 100644 --- a/services/horizon/internal/integration/parameters_test.go +++ b/services/horizon/internal/integration/parameters_test.go @@ -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 //