Skip to content

Commit

Permalink
Move captive-core binary check back to setCaptiveCoreConfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
urvisavla committed Oct 4, 2023
1 parent 1cf3e6e commit 532e701
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 27 deletions.
18 changes: 9 additions & 9 deletions services/horizon/internal/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,15 @@ func getCaptiveCoreConfigFromNetworkParameter(config *Config) (networkConfig, er
func setCaptiveCoreConfiguration(config *Config, options ApplyOptions) error {
stdLog.Println("Preparing captive core...")

// If the user didn't specify a Stellar Core binary, we can check the
// $PATH and possibly fill it in for them.
if config.CaptiveCoreBinaryPath == "" {
var err error
if config.CaptiveCoreBinaryPath, err = getCaptiveCoreBinaryPath(); err != nil {
return fmt.Errorf("captive core requires %s", StellarCoreBinaryPathName)
}
}

var defaultNetworkConfig networkConfig
if config.Network != "" {
var err error
Expand Down Expand Up @@ -825,15 +834,6 @@ func ApplyFlags(config *Config, flags support.ConfigOptions, options ApplyOption
}

if config.EnableCaptiveCoreIngestion {
// If the user didn't specify a Stellar Core binary, we can check the
// $PATH and possibly fill it in for them.
if config.CaptiveCoreBinaryPath == "" {
var err error
if config.CaptiveCoreBinaryPath, err = getCaptiveCoreBinaryPath(); err != nil {
return fmt.Errorf("captive core requires %s", StellarCoreBinaryPathName)
}
}

err := setCaptiveCoreConfiguration(config, options)
if err != nil {
return errors.Wrap(err, "error generating captive core configuration")
Expand Down
52 changes: 34 additions & 18 deletions services/horizon/internal/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,52 +19,61 @@ func Test_createCaptiveCoreDefaultConfig(t *testing.T) {
errStr string
}{
{
name: "testnet default config",
config: Config{Network: StellarTestnet},
name: "testnet default config",
config: Config{Network: StellarTestnet,
CaptiveCoreBinaryPath: "/path/to/captive-core/binary",
},
networkPassphrase: TestnetConf.NetworkPassphrase,
historyArchiveURLs: TestnetConf.HistoryArchiveURLs,
},
{
name: "pubnet default config",
config: Config{Network: StellarPubnet},
name: "pubnet default config",
config: Config{Network: StellarPubnet,
CaptiveCoreBinaryPath: "/path/to/captive-core/binary",
},
networkPassphrase: PubnetConf.NetworkPassphrase,
historyArchiveURLs: PubnetConf.HistoryArchiveURLs,
},
{
name: "testnet validation; history archive urls supplied",
config: Config{Network: StellarTestnet,
HistoryArchiveURLs: []string{"network history archive urls supplied"},
HistoryArchiveURLs: []string{"network history archive urls supplied"},
CaptiveCoreBinaryPath: "/path/to/captive-core/binary",
},
errStr: fmt.Sprintf(errorMsgDefaultConfig, HistoryArchiveURLsFlagName),
},
{
name: "pubnet validation; history archive urls supplied",
config: Config{Network: StellarPubnet,
HistoryArchiveURLs: []string{"network history archive urls supplied"},
HistoryArchiveURLs: []string{"network history archive urls supplied"},
CaptiveCoreBinaryPath: "/path/to/captive-core/binary",
},
errStr: fmt.Sprintf(errorMsgDefaultConfig, HistoryArchiveURLsFlagName),
},
{
name: "testnet validation; network passphrase supplied",
config: Config{Network: StellarTestnet,
NetworkPassphrase: "network passphrase supplied",
HistoryArchiveURLs: []string{},
NetworkPassphrase: "network passphrase supplied",
HistoryArchiveURLs: []string{},
CaptiveCoreBinaryPath: "/path/to/captive-core/binary",
},
errStr: fmt.Sprintf(errorMsgDefaultConfig, NetworkPassphraseFlagName),
},
{
name: "pubnet validation; network passphrase supplied",
config: Config{Network: StellarPubnet,
NetworkPassphrase: "pubnet network passphrase supplied",
HistoryArchiveURLs: []string{},
NetworkPassphrase: "pubnet network passphrase supplied",
HistoryArchiveURLs: []string{},
CaptiveCoreBinaryPath: "/path/to/captive-core/binary",
},
errStr: fmt.Sprintf(errorMsgDefaultConfig, NetworkPassphraseFlagName),
},
{
name: "unknown network specified",
config: Config{Network: "unknown",
NetworkPassphrase: "",
HistoryArchiveURLs: []string{},
NetworkPassphrase: "",
HistoryArchiveURLs: []string{},
CaptiveCoreBinaryPath: "/path/to/captive-core/binary",
},
errStr: "no default configuration found for network unknown",
},
Expand Down Expand Up @@ -104,6 +113,7 @@ func Test_createCaptiveCoreConfig(t *testing.T) {
NetworkPassphrase: PubnetConf.NetworkPassphrase,
HistoryArchiveURLs: PubnetConf.HistoryArchiveURLs,
CaptiveCoreConfigPath: "configs/captive-core-pubnet.cfg",
CaptiveCoreBinaryPath: "/path/to/captive-core/binary",
},
networkPassphrase: PubnetConf.NetworkPassphrase,
historyArchiveURLs: PubnetConf.HistoryArchiveURLs,
Expand All @@ -112,24 +122,27 @@ func Test_createCaptiveCoreConfig(t *testing.T) {
name: "no network specified; passphrase not supplied",
requireCaptiveCoreConfig: true,
config: Config{
HistoryArchiveURLs: []string{"HistoryArchiveURLs"},
HistoryArchiveURLs: []string{"HistoryArchiveURLs"},
CaptiveCoreBinaryPath: "/path/to/captive-core/binary",
},
errStr: fmt.Sprintf(errorMsgConfig, NetworkPassphraseFlagName),
},
{
name: "no network specified; history archive urls not supplied",
requireCaptiveCoreConfig: true,
config: Config{
NetworkPassphrase: "NetworkPassphrase",
NetworkPassphrase: "NetworkPassphrase",
CaptiveCoreBinaryPath: "/path/to/captive-core/binary",
},
errStr: fmt.Sprintf(errorMsgConfig, HistoryArchiveURLsFlagName),
},
{
name: "no network specified; captive-core-config-path not supplied",
requireCaptiveCoreConfig: true,
config: Config{
NetworkPassphrase: PubnetConf.NetworkPassphrase,
HistoryArchiveURLs: PubnetConf.HistoryArchiveURLs,
NetworkPassphrase: PubnetConf.NetworkPassphrase,
HistoryArchiveURLs: PubnetConf.HistoryArchiveURLs,
CaptiveCoreBinaryPath: "/path/to/captive-core/binary",
},
errStr: fmt.Sprintf("invalid config: captive core requires that --%s is set or "+
"you can set the --%s parameter to use the default captive core config", CaptiveCoreConfigPathName, NetworkFlagName),
Expand All @@ -141,6 +154,7 @@ func Test_createCaptiveCoreConfig(t *testing.T) {
NetworkPassphrase: PubnetConf.NetworkPassphrase,
HistoryArchiveURLs: PubnetConf.HistoryArchiveURLs,
CaptiveCoreConfigPath: "xyz.cfg",
CaptiveCoreBinaryPath: "/path/to/captive-core/binary",
},
errStr: "invalid captive core toml file: could not load toml path:" +
" open xyz.cfg: no such file or directory",
Expand All @@ -152,6 +166,7 @@ func Test_createCaptiveCoreConfig(t *testing.T) {
NetworkPassphrase: PubnetConf.NetworkPassphrase,
HistoryArchiveURLs: PubnetConf.HistoryArchiveURLs,
CaptiveCoreConfigPath: "configs/captive-core-testnet.cfg",
CaptiveCoreBinaryPath: "/path/to/captive-core/binary",
},
errStr: fmt.Sprintf("invalid captive core toml file: invalid captive core toml: "+
"NETWORK_PASSPHRASE in captive core config file: %s does not match Horizon "+
Expand All @@ -161,8 +176,9 @@ func Test_createCaptiveCoreConfig(t *testing.T) {
name: "no network specified; captive-core-config not required",
requireCaptiveCoreConfig: false,
config: Config{
NetworkPassphrase: PubnetConf.NetworkPassphrase,
HistoryArchiveURLs: PubnetConf.HistoryArchiveURLs,
NetworkPassphrase: PubnetConf.NetworkPassphrase,
HistoryArchiveURLs: PubnetConf.HistoryArchiveURLs,
CaptiveCoreBinaryPath: "/path/to/captive-core/binary",
},
networkPassphrase: PubnetConf.NetworkPassphrase,
historyArchiveURLs: PubnetConf.HistoryArchiveURLs,
Expand Down

0 comments on commit 532e701

Please sign in to comment.