Skip to content

Commit

Permalink
Refactor handling of stellar-core-binary-path (#3101)
Browse files Browse the repository at this point in the history
Containers and configurations should be allowed to set
`--stellar-core-binary-path` regardless of the behavior we want
from Horizon.

1. Do not assume that a non-empty `--stellar-core-binary-path` (or
   `--remote-captive-core-url`) implies captive core should be used
   (use the pre-existing `--enable-captive-core-ingestion` as a tollgate
   instead).
2. Allow setting both `--remote-captive-core-url` and `--stellar-core-binary-path` simultaneously, associating a higher priority to the URL.
  • Loading branch information
2opremio authored Oct 6, 2020
1 parent 947b63b commit aa36914
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 32 deletions.
8 changes: 4 additions & 4 deletions services/horizon/cmd/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,12 @@ var dbReingestRangeCmd = &cobra.Command{
HistoryArchiveURL: config.HistoryArchiveURLs[0],
MaxReingestRetries: int(retries),
ReingestRetryBackoffSeconds: int(retryBackoffSeconds),
EnableCaptiveCore: config.EnableCaptiveCoreIngestion,
StellarCoreBinaryPath: config.StellarCoreBinaryPath,
RemoteCaptiveCoreURL: config.RemoteCaptiveCoreURL,
}

if config.EnableCaptiveCoreIngestion {
ingestConfig.StellarCoreBinaryPath = config.StellarCoreBinaryPath
ingestConfig.RemoteCaptiveCoreURL = config.RemoteCaptiveCoreURL
} else {
if !ingestConfig.EnableCaptiveCore {
if config.StellarCoreDatabaseURL == "" {
log.Fatalf("flag --%s cannot be empty", stellarCoreDBURLFlagName)
}
Expand Down
15 changes: 8 additions & 7 deletions services/horizon/cmd/ingest.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,15 @@ var ingestVerifyRangeCmd = &cobra.Command{
}

ingestConfig := expingest.Config{
NetworkPassphrase: config.NetworkPassphrase,
HistorySession: horizonSession,
HistoryArchiveURL: config.HistoryArchiveURLs[0],
NetworkPassphrase: config.NetworkPassphrase,
HistorySession: horizonSession,
HistoryArchiveURL: config.HistoryArchiveURLs[0],
EnableCaptiveCore: config.EnableCaptiveCoreIngestion,
StellarCoreBinaryPath: config.StellarCoreBinaryPath,
RemoteCaptiveCoreURL: config.RemoteCaptiveCoreURL,
}
if config.EnableCaptiveCoreIngestion {
ingestConfig.StellarCoreBinaryPath = config.StellarCoreBinaryPath
ingestConfig.RemoteCaptiveCoreURL = config.RemoteCaptiveCoreURL
} else {

if !ingestConfig.EnableCaptiveCore {
if config.StellarCoreDatabaseURL == "" {
log.Fatalf("flag --%s cannot be empty", stellarCoreDBURLFlagName)
}
Expand Down
5 changes: 1 addition & 4 deletions services/horizon/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ var configOpts = support.ConfigOptions{
OptType: types.String,
FlagDefault: "",
Required: false,
Usage: "path to stellar core binary",
Usage: "path to stellar core binary (--remote-captive-core-url has higher precedence)",
ConfigKey: &config.StellarCoreBinaryPath,
},
&support.ConfigOption{
Expand Down Expand Up @@ -429,9 +429,6 @@ func initRootConfig() {
if binaryPath == "" && remoteURL == "" {
stdLog.Fatalf("Invalid config: captive core requires that either --stellar-core-binary-path or --remote-captive-core-url is set")
}
if binaryPath != "" && remoteURL != "" {
stdLog.Fatalf("Invalid config: --stellar-core-binary-path and --remote-captive-core-url cannot both be set.")
}
}
if config.Ingest {
// When running live ingestion a config file is required too
Expand Down
37 changes: 20 additions & 17 deletions services/horizon/internal/expingest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type Config struct {
CoreSession *db.Session
StellarCoreURL string
StellarCoreCursor string
EnableCaptiveCore bool
StellarCoreBinaryPath string
StellarCoreConfigPath string
RemoteCaptiveCoreURL string
Expand Down Expand Up @@ -157,23 +158,25 @@ func NewSystem(config Config) (System, error) {
}

var ledgerBackend ledgerbackend.LedgerBackend
if len(config.RemoteCaptiveCoreURL) > 0 {
ledgerBackend, err = ledgerbackend.NewRemoteCaptive(config.RemoteCaptiveCoreURL)
if err != nil {
cancel()
return nil, errors.Wrap(err, "error creating captive core backend")
}
}
if len(config.StellarCoreBinaryPath) > 0 {
ledgerBackend, err = ledgerbackend.NewCaptive(
config.StellarCoreBinaryPath,
config.StellarCoreConfigPath,
config.NetworkPassphrase,
[]string{config.HistoryArchiveURL},
)
if err != nil {
cancel()
return nil, errors.Wrap(err, "error creating captive core backend")
if config.EnableCaptiveCore {
if len(config.RemoteCaptiveCoreURL) > 0 {
ledgerBackend, err = ledgerbackend.NewRemoteCaptive(config.RemoteCaptiveCoreURL)
if err != nil {
cancel()
return nil, errors.Wrap(err, "error creating captive core backend")
}
} else {
//
ledgerBackend, err = ledgerbackend.NewCaptive(
config.StellarCoreBinaryPath,
config.StellarCoreConfigPath,
config.NetworkPassphrase,
[]string{config.HistoryArchiveURL},
)
if err != nil {
cancel()
return nil, errors.Wrap(err, "error creating captive core backend")
}
}
} else {
coreSession := config.CoreSession.Clone()
Expand Down

0 comments on commit aa36914

Please sign in to comment.