Skip to content

Commit

Permalink
Add default config for "Standalone" network
Browse files Browse the repository at this point in the history
  • Loading branch information
urvisavla committed Jul 12, 2023
1 parent c00f1e2 commit 7bbc11e
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 15 deletions.
2 changes: 2 additions & 0 deletions network/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const (
PublicNetworkPassphrase = "Public Global Stellar Network ; September 2015"
// TestNetworkPassphrase is the pass phrase used for every transaction intended for the SDF-run test network
TestNetworkPassphrase = "Test SDF Network ; September 2015"
// StandaloneNetworkPassphrase is the pass phrase used for standalone network
StandaloneNetworkPassphrase = "Standalone Network ; February 2017"
)

// ID returns the network ID derived from the provided passphrase. This value
Expand Down
7 changes: 1 addition & 6 deletions services/horizon/docker/docker-compose.standalone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,8 @@ services:

horizon:
environment:
- HISTORY_ARCHIVE_URLS=http://host.docker.internal:1570
- NETWORK_PASSPHRASE=Standalone Network ; February 2017
- CAPTIVE_CORE_CONFIG_APPEND_PATH=/captive-core-standalone.cfg
- NETWORK=standalone
- STELLAR_CORE_URL=http://host.docker.internal:11626
volumes:
- ./captive-core-standalone.cfg:/captive-core-standalone.cfg

# this container will invoke a request to upgrade stellar core to protocol 17 (by default)
core-upgrade:
restart: on-failure
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
# simple captive core configuration for a standalone test "network"
# To avoid conflicts with the core instance
PEER_PORT=11725

UNSAFE_QUORUM=true
FAILURE_SAFETY=0

QUALITY="MEDIUM"

[[VALIDATORS]]
NAME="local_core"
HOME_DOMAIN="core.local"
# From "SACJC372QBSSKJYTV5A7LWT4NXWHTQO6GHG4QDAVC2XDPX6CNNXFZ4JK"
PUBLIC_KEY="GD5KD2KEZJIGTC63IGW6UMUSMVUVG5IHG64HUTFWCHVZH2N2IBOQN7PS"
ADDRESS="host.docker.internal"
QUALITY="MEDIUM"
ADDRESS="localhost:11625"
QUALITY="MEDIUM"
HISTORY="curl -sf http://localhost:1570/{0} -o {1}"
28 changes: 21 additions & 7 deletions services/horizon/internal/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ const (
StellarPubnet = "pubnet"
// StellarTestnet is a constant representing the Stellar test network
StellarTestnet = "testnet"
// StandaloneNetwork is a constant representing the standalone network mode.
StandaloneNetwork = "standalone"
)

// validateBothOrNeither ensures that both options are provided, if either is provided.
Expand Down Expand Up @@ -579,17 +581,18 @@ func Flags() (*Config, support.ConfigOptions) {
Required: false,
CustomSetValue: func(co *support.ConfigOption) error {
val := viper.GetString(co.Name)
if val != "" && val != StellarPubnet && val != StellarTestnet {
return fmt.Errorf("invalid network %s. Use '%s' or '%s'",
val, StellarPubnet, StellarTestnet)
if val != "" && val != StellarPubnet && val != StellarTestnet && val != StandaloneNetwork {
return fmt.Errorf("invalid network %s. Use '%s', '%s' or '%s'",
val, StellarPubnet, StellarTestnet, StandaloneNetwork)
}
*co.ConfigKey.(*string) = val
return nil
},
Usage: fmt.Sprintf("stellar public network, either '%s' or '%s'."+
" It automatically configures network settings, including %s, %s, and %s.",
StellarPubnet, StellarTestnet, NetworkPassphraseFlagName,
HistoryArchiveURLsFlagName, CaptiveCoreConfigPathName),
Usage: fmt.Sprintf("stellar public network, either '%s', '%s' or '%s'."+
" It automatically configures network settings, including %s, %s, and %s."+
" For %s network mode, ensure you have a locally running instance of stellar-core and a history archive.",
StellarPubnet, StellarTestnet, StandaloneNetwork, NetworkPassphraseFlagName,
HistoryArchiveURLsFlagName, CaptiveCoreConfigPathName, StandaloneNetwork),
},
}

Expand Down Expand Up @@ -636,6 +639,9 @@ var (
//go:embed configs/captive-core-testnet.cfg
TestnetDefaultConfig []byte

//go:embed configs/captive-core-standalone.cfg
StandaloneDefaultConfig []byte

pubnetConf = networkConfig{
defaultConfig: PubnetDefaultConfig,
historyArchiveURLs: []string{"https://history.stellar.org/prd/core-live/core_live_001/",
Expand All @@ -651,6 +657,12 @@ var (
"https://history.stellar.org/prd/core-testnet/core_testnet_003"},
networkPassphrase: network.TestNetworkPassphrase,
}

standaloneConf = networkConfig{
defaultConfig: StandaloneDefaultConfig,
historyArchiveURLs: []string{"http://localhost:1570"},
networkPassphrase: network.StandaloneNetworkPassphrase,
}
)

// getCaptiveCoreBinaryPath retrieves the path of the Captive Core binary
Expand Down Expand Up @@ -711,6 +723,8 @@ func createCaptiveCoreDefaultConfig(config *Config) error {
defaultNetworkConfig = pubnetConf
case StellarTestnet:
defaultNetworkConfig = testnetConf
case StandaloneNetwork:
defaultNetworkConfig = standaloneConf
default:
return fmt.Errorf("no default configuration found for network %s", config.Network)
}
Expand Down
21 changes: 21 additions & 0 deletions services/horizon/internal/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ func Test_createCaptiveCoreDefaultConfig(t *testing.T) {
networkPassphrase: pubnetConf.networkPassphrase,
historyArchiveURLs: pubnetConf.historyArchiveURLs,
},
{
name: "standalone network default config",
config: Config{Network: StandaloneNetwork},
networkPassphrase: standaloneConf.networkPassphrase,
historyArchiveURLs: standaloneConf.historyArchiveURLs,
},
{
name: "testnet validation; history archive urls supplied",
config: Config{Network: StellarTestnet,
Expand All @@ -44,6 +50,13 @@ func Test_createCaptiveCoreDefaultConfig(t *testing.T) {
},
errStr: fmt.Sprintf(errorMsgDefaultConfig, HistoryArchiveURLsFlagName, StellarPubnet),
},
{
name: "standalone network validation; history archive urls supplied",
config: Config{Network: StandaloneNetwork,
HistoryArchiveURLs: []string{"network history archive urls supplied"},
},
errStr: fmt.Sprintf(errorMsgDefaultConfig, HistoryArchiveURLsFlagName, StandaloneNetwork),
},
{
name: "testnet validation; network passphrase supplied",
config: Config{Network: StellarTestnet,
Expand All @@ -60,6 +73,14 @@ func Test_createCaptiveCoreDefaultConfig(t *testing.T) {
},
errStr: fmt.Sprintf(errorMsgDefaultConfig, NetworkPassphraseFlagName, StellarPubnet),
},
{
name: "standalone network validation; network passphrase supplied",
config: Config{Network: StandaloneNetwork,
NetworkPassphrase: "network passphrase supplied",
HistoryArchiveURLs: []string{},
},
errStr: fmt.Sprintf(errorMsgDefaultConfig, NetworkPassphraseFlagName, StandaloneNetwork),
},
{
name: "unknown network specified",
config: Config{Network: "unknown",
Expand Down

0 comments on commit 7bbc11e

Please sign in to comment.