Skip to content

Commit

Permalink
Add --max_assets_per_path_request flag (#4046)
Browse files Browse the repository at this point in the history
  • Loading branch information
erika-sdf authored Nov 5, 2021
1 parent ef33e4c commit 2226900
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 34 deletions.
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

0 comments on commit 2226900

Please sign in to comment.