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 flag to choose a custom peering port for Captive Core #3484

Merged
merged 5 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions ingest/ledgerbackend/captive_core_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ type CaptiveCoreConfig struct {
LedgerHashStore TrustedLedgerHashStore
// HTTPPort is the TCP port to listen for requests (defaults to 0, which disables the HTTP server)
HTTPPort uint
// PeerPort is the TCP port to bind to for connecting to the Stellar network
// (defaults to 11625). It may be useful for example when there's >1 Stellar-Core
// instance running on a machine.
PeerPort uint
// Log is an (optional) custom logger which will capture any output from the Stellar Core process.
// If Log is omitted then all output will be printed to stdout.
Log *log.Entry
Expand Down
8 changes: 8 additions & 0 deletions ingest/ledgerbackend/stellar_core_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type stellarCoreRunner struct {
networkPassphrase string
historyURLs []string
httpPort uint
peerPort uint
mode stellarCoreRunnerMode

started bool
Expand Down Expand Up @@ -89,6 +90,7 @@ func newStellarCoreRunner(config CaptiveCoreConfig, mode stellarCoreRunnerMode)
networkPassphrase: config.NetworkPassphrase,
historyURLs: config.HistoryArchiveURLs,
httpPort: config.HTTPPort,
peerPort: config.PeerPort,
mode: mode,
ctx: ctx,
cancel: cancel,
Expand Down Expand Up @@ -121,6 +123,10 @@ func (r *stellarCoreRunner) generateConfig() (string, error) {
fmt.Sprintf(`LOG_FILE_PATH="%s"`, r.logPath),
}

if r.peerPort > 0 {
lines = append(lines, fmt.Sprintf(`PEER_PORT=%d`, r.peerPort))
}

if r.mode == stellarCoreRunnerModeOffline {
// In offline mode, there is no need to connect to peers
lines = append(lines, "RUN_STANDALONE=true")
Expand Down Expand Up @@ -153,6 +159,8 @@ func (r *stellarCoreRunner) generateConfig() (string, error) {
}
result += strings.Join(lines, "\n")

fmt.Println(result)
Shaptic marked this conversation as resolved.
Show resolved Hide resolved

Shaptic marked this conversation as resolved.
Show resolved Hide resolved
return result, nil
}

Expand Down
1 change: 1 addition & 0 deletions ingest/ledgerbackend/stellar_core_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func TestGenerateConfig(t *testing.T) {
HistoryArchiveURLs: []string{"http://localhost:1170"},
Log: log.New(),
ConfigAppendPath: testCase.appendPath,
PeerPort: 12345,
Context: context.Background(),
NetworkPassphrase: "Public Global Stellar Network ; September 2015",
}, testCase.mode)
Expand Down
1 change: 1 addition & 0 deletions ingest/ledgerbackend/testdata/expected-offline-core.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ NETWORK_PASSPHRASE="Public Global Stellar Network ; September 2015"
BUCKET_DIR_PATH="/test-temp-dir/buckets"
HTTP_PORT=6789
LOG_FILE_PATH=""
PEER_PORT=12345
RUN_STANDALONE=true
UNSAFE_QUORUM=true
[QUORUM_SET]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ NETWORK_PASSPHRASE="Public Global Stellar Network ; September 2015"
BUCKET_DIR_PATH="/test-temp-dir/buckets"
HTTP_PORT=6789
LOG_FILE_PATH=""
PEER_PORT=12345
RUN_STANDALONE=true
UNSAFE_QUORUM=true

Expand Down
1 change: 1 addition & 0 deletions ingest/ledgerbackend/testdata/expected-online-core.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ NETWORK_PASSPHRASE="Public Global Stellar Network ; September 2015"
BUCKET_DIR_PATH="/test-temp-dir/buckets"
HTTP_PORT=6789
LOG_FILE_PATH=""
PEER_PORT=12345

[[HOME_DOMAINS]]
HOME_DOMAIN="testnet.stellar.org"
Expand Down
1 change: 1 addition & 0 deletions services/horizon/internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Config struct {
CaptiveCoreConfigAppendPath string
RemoteCaptiveCoreURL string
CaptiveCoreHTTPPort uint
CaptiveCorePeerPort uint
CaptiveCoreLogPath string

StellarCoreDatabaseURL string
Expand Down
8 changes: 8 additions & 0 deletions services/horizon/internal/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ func Flags() (*Config, support.ConfigOptions) {
Usage: "HTTP port for Captive Core to listen on (0 disables the HTTP server)",
ConfigKey: &config.CaptiveCoreHTTPPort,
},
&support.ConfigOption{
Name: "captive-core-peer-port",
OptType: types.Uint,
FlagDefault: uint(0),
Required: false,
Usage: "port for Captive Core to bind to for connecting to the Stellar swarm (0 uses Stellar Core's default)",
ConfigKey: &config.CaptiveCorePeerPort,
},
&support.ConfigOption{
Name: StellarCoreDBURLFlagName,
EnvVar: "STELLAR_CORE_DATABASE_URL",
Expand Down
2 changes: 2 additions & 0 deletions services/horizon/internal/ingest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type Config struct {
CaptiveCoreBinaryPath string
CaptiveCoreConfigAppendPath string
CaptiveCoreHTTPPort uint
CaptiveCorePeerPort uint
CaptiveCoreLogPath string
RemoteCaptiveCoreURL string
NetworkPassphrase string
Expand Down Expand Up @@ -198,6 +199,7 @@ func NewSystem(config Config) (System, error) {
BinaryPath: config.CaptiveCoreBinaryPath,
ConfigAppendPath: config.CaptiveCoreConfigAppendPath,
HTTPPort: config.CaptiveCoreHTTPPort,
PeerPort: config.CaptiveCorePeerPort,
NetworkPassphrase: config.NetworkPassphrase,
HistoryArchiveURLs: []string{config.HistoryArchiveURL},
CheckpointFrequency: config.CheckpointFrequency,
Expand Down
1 change: 1 addition & 0 deletions services/horizon/internal/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func initIngester(app *App) {
CaptiveCoreBinaryPath: app.config.CaptiveCoreBinaryPath,
CaptiveCoreConfigAppendPath: app.config.CaptiveCoreConfigAppendPath,
CaptiveCoreHTTPPort: app.config.CaptiveCoreHTTPPort,
CaptiveCorePeerPort: app.config.CaptiveCorePeerPort,
CaptiveCoreLogPath: app.config.CaptiveCoreLogPath,
RemoteCaptiveCoreURL: app.config.RemoteCaptiveCoreURL,
EnableCaptiveCore: app.config.EnableCaptiveCoreIngestion,
Expand Down