Skip to content

Commit

Permalink
services/horizon: Add optional configuration parameter NETWORK (#4949)
Browse files Browse the repository at this point in the history
The PR introduces a new optional Horizon configuration parameter called NETWORK. This parameter allows users to specify the desired Stellar network, pubnet or testnet. When the NETWORK parameter is set, Horizon automatically adjusts the remaining configuration settings and generates the corresponding captive core config file.
  • Loading branch information
urvisavla authored Jul 18, 2023
1 parent 9a7105a commit 95c2976
Show file tree
Hide file tree
Showing 14 changed files with 367 additions and 359 deletions.
19 changes: 12 additions & 7 deletions ingest/ledgerbackend/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package ledgerbackend
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"os/exec"
"regexp"
"strconv"
Expand Down Expand Up @@ -330,13 +330,19 @@ type CaptiveCoreTomlParams struct {
// NewCaptiveCoreTomlFromFile constructs a new CaptiveCoreToml instance by merging configuration
// from the toml file located at `configPath` and the configuration provided by `params`.
func NewCaptiveCoreTomlFromFile(configPath string, params CaptiveCoreTomlParams) (*CaptiveCoreToml, error) {
var captiveCoreToml CaptiveCoreToml
data, err := ioutil.ReadFile(configPath)
data, err := os.ReadFile(configPath)
if err != nil {
return nil, errors.Wrap(err, "could not load toml path")
}
return NewCaptiveCoreTomlFromData(data, params)
}

// NewCaptiveCoreTomlFromData constructs a new CaptiveCoreToml instance by merging configuration
// from the toml data and the configuration provided by `params`.
func NewCaptiveCoreTomlFromData(data []byte, params CaptiveCoreTomlParams) (*CaptiveCoreToml, error) {
var captiveCoreToml CaptiveCoreToml

if err = captiveCoreToml.unmarshal(data, params.Strict); err != nil {
if err := captiveCoreToml.unmarshal(data, params.Strict); err != nil {
return nil, errors.Wrap(err, "could not unmarshal captive core toml")
}
// disallow setting BUCKET_DIR_PATH through a file since it can cause multiple
Expand All @@ -345,14 +351,13 @@ func NewCaptiveCoreTomlFromFile(configPath string, params CaptiveCoreTomlParams)
return nil, errors.New("could not unmarshal captive core toml: setting BUCKET_DIR_PATH is disallowed for Captive Core, use CAPTIVE_CORE_STORAGE_PATH instead")
}

if err = captiveCoreToml.validate(params); err != nil {
if err := captiveCoreToml.validate(params); err != nil {
return nil, errors.Wrap(err, "invalid captive core toml")
}

if len(captiveCoreToml.HistoryEntries) > 0 {
log.Warnf(
"Configuring captive core with history archive from %s instead of %v",
configPath,
"Configuring captive core with history archive from %s",
params.HistoryArchiveURLs,
)
}
Expand Down
12 changes: 12 additions & 0 deletions network/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ const (
TestNetworkPassphrase = "Test SDF Network ; September 2015"
)

var (
// PublicNetworkhistoryArchiveURLs is a list of history archive URLs for stellar 'pubnet'
PublicNetworkhistoryArchiveURLs = []string{"https://history.stellar.org/prd/core-live/core_live_001/",
"https://history.stellar.org/prd/core-live/core_live_002/",
"https://history.stellar.org/prd/core-live/core_live_003/"}

// TestNetworkhistoryArchiveURLs is a list of history archive URLs for stellar 'testnet'
TestNetworkhistoryArchiveURLs = []string{"https://history.stellar.org/prd/core-testnet/core_testnet_001/",
"https://history.stellar.org/prd/core-testnet/core_testnet_002/",
"https://history.stellar.org/prd/core-testnet/core_testnet_003"}
)

// ID returns the network ID derived from the provided passphrase. This value
// also happens to be the raw (i.e. not strkey encoded) secret key for the root
// account of the network.
Expand Down
1 change: 1 addition & 0 deletions services/horizon/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ file. This project adheres to [Semantic Versioning](http://semver.org/).
## Unreleased

- The command line flag --remote-captive-core-url has been removed as remote captive core functionality is now deprecated ([4940](https://github.com/stellar/go/pull/4940)).
- Added new command-line flag --network to specify the Stellar network (pubnet or testnet), aiming at simplifying the configuration process by automatically configuring the following parameters based on the chosen network: --history-archive-urls, --network-passphrase, --captive-core-config-path. ([4949](https://github.com/stellar/go/pull/4949)).

## 2.26.0
### Changes
Expand Down
192 changes: 0 additions & 192 deletions services/horizon/docker/captive-core-pubnet.cfg

This file was deleted.

29 changes: 0 additions & 29 deletions services/horizon/docker/captive-core-testnet.cfg

This file was deleted.

6 changes: 1 addition & 5 deletions services/horizon/docker/docker-compose.pubnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,4 @@ services:
horizon:
platform: linux/amd64
environment:
- HISTORY_ARCHIVE_URLS=https://history.stellar.org/prd/core-live/core_live_001
- NETWORK_PASSPHRASE=Public Global Stellar Network ; September 2015
- CAPTIVE_CORE_CONFIG_APPEND_PATH=/captive-core-pubnet.cfg
volumes:
- ./captive-core-pubnet.cfg:/captive-core-pubnet.cfg
- NETWORK=pubnet
7 changes: 1 addition & 6 deletions services/horizon/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,8 @@ services:
- "11725:11725"
environment:
- DATABASE_URL=postgres://[email protected]:5432/horizon?sslmode=disable
- CAPTIVE_CORE_CONFIG_APPEND_PATH=/captive-core-testnet.cfg
- HISTORY_ARCHIVE_URLS=https://history.stellar.org/prd/core-testnet/core_testnet_001
- NETWORK_PASSPHRASE=Test SDF Network ; September 2015
- INGEST=true
- NETWORK=testnet
- PER_HOUR_RATE_LIMIT=0
volumes:
- ./captive-core-testnet.cfg:/captive-core-testnet.cfg
command: ["--apply-migrations"]
extra_hosts:
- "host.docker.internal:host-gateway"
Expand Down
16 changes: 0 additions & 16 deletions services/horizon/internal/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,22 +118,6 @@ func (a *App) Serve() error {
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)

if a.config.UsingDefaultPubnetConfig {
const warnMsg = "Horizon started using the default pubnet configuration. " +
"This is not safe! Please provide a custom --captive-core-config-path."
log.Warn(warnMsg)
go func() {
for {
select {
case <-time.After(time.Hour):
log.Warn(warnMsg)
case <-a.done:
return
}
}
}()
}

go func() {
select {
case <-signalChan:
Expand Down
3 changes: 2 additions & 1 deletion services/horizon/internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ type Config struct {

EnableCaptiveCoreIngestion bool
EnableIngestionFiltering bool
UsingDefaultPubnetConfig bool
CaptiveCoreBinaryPath string
RemoteCaptiveCoreURL string
CaptiveCoreConfigPath string
Expand Down Expand Up @@ -114,4 +113,6 @@ type Config struct {
BehindAWSLoadBalancer bool
// RoundingSlippageFilter excludes trades from /trade_aggregations with rounding slippage >x bps
RoundingSlippageFilter int
// Stellar network: 'testnet' or 'pubnet'
Network string
}
Loading

0 comments on commit 95c2976

Please sign in to comment.