Skip to content

Commit

Permalink
ingest/ledgerbackend: Update captive-core config with new BucketlistD…
Browse files Browse the repository at this point in the history
…B parameters (#5333)

* Update bucketlistdb config parameters
* Remove EXPERIMENTAL_BUCKETLIST_DB flag
* Add DEPRECATED_SQL_LEDGER_STATE param. Add unit tests for DEPRECATED_SQL_LEDGER_STATE.
* Update changelog
* Update Horizon changelog
  • Loading branch information
urvisavla authored Jun 24, 2024
1 parent 0b7df85 commit 90c18e2
Show file tree
Hide file tree
Showing 34 changed files with 199 additions and 55 deletions.
7 changes: 5 additions & 2 deletions ingest/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).


## Unreleased
### Stellar Core Protocol 21 Configuration Update:
* BucketlistDB is now the default database for stellar-core, replacing the experimental option. As a result, the `EXPERIMENTAL_BUCKETLIST_DB` configuration parameter has been deprecated.
* A new mandatory parameter, `DEPRECATED_SQL_LEDGER_STATE`, has been added with a default value of false which equivalent to `EXPERIMENTAL_BUCKETLIST_DB` being set to true.
* The parameter `EXPERIMENTAL_BUCKETLIST_DB_INDEX_PAGE_SIZE_EXPONENT` has been renamed to `BUCKETLIST_DB_INDEX_PAGE_SIZE_EXPONENT`.
* The parameter `EXPERIMENTAL_BUCKETLIST_DB_INDEX_CUTOFF` has been renamed to `BUCKETLIST_DB_INDEX_CUTOFF`.

### New Features
* Support for Soroban and Protocol 20!
Expand Down
2 changes: 0 additions & 2 deletions ingest/ledgerbackend/configs/captive-core-pubnet.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ FAILURE_SAFETY=1
HTTP_PORT=11626
PEER_PORT=11725

EXPERIMENTAL_BUCKETLIST_DB=true

[[HOME_DOMAINS]]
HOME_DOMAIN="publicnode.org"
QUALITY="HIGH"
Expand Down
2 changes: 0 additions & 2 deletions ingest/ledgerbackend/configs/captive-core-testnet.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ NETWORK_PASSPHRASE="Test SDF Network ; September 2015"
UNSAFE_QUORUM=true
FAILURE_SAFETY=1

EXPERIMENTAL_BUCKETLIST_DB=true

[[HOME_DOMAINS]]
HOME_DOMAIN="testnet.stellar.org"
QUALITY="HIGH"
Expand Down
22 changes: 22 additions & 0 deletions ingest/ledgerbackend/testdata/expected-bucketlistdb-core.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated file, do not edit
BUCKETLIST_DB_INDEX_CUTOFF = 20
BUCKETLIST_DB_INDEX_PAGE_SIZE_EXPONENT = 15
DATABASE = "sqlite3://stellar.db"
DEPRECATED_SQL_LEDGER_STATE = false
FAILURE_SAFETY = -1
HTTP_PORT = 11626
LOG_FILE_PATH = ""
NETWORK_PASSPHRASE = "Public Global Stellar Network ; September 2015"

[[HOME_DOMAINS]]
HOME_DOMAIN = "testnet.stellar.org"
QUALITY = "MEDIUM"

[[VALIDATORS]]
ADDRESS = "localhost:123"
HOME_DOMAIN = "testnet.stellar.org"
NAME = "sdf_testnet_1"
PUBLIC_KEY = "GDKXE2OZMJIPOSLNA6N6F2BVCI3O777I2OOC4BV7VOYUEHYX7RTRYA7Y"

[HISTORY.h0]
get = "curl -sf http://localhost:1170/{0} -o {1}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated file, do not edit
BUCKETLIST_DB_INDEX_PAGE_SIZE_EXPONENT = 12
DATABASE = "sqlite3://stellar.db"
DEPRECATED_SQL_LEDGER_STATE = false
FAILURE_SAFETY = -1
HTTP_PORT = 11626
LOG_FILE_PATH = ""
NETWORK_PASSPHRASE = "Public Global Stellar Network ; September 2015"

[[HOME_DOMAINS]]
HOME_DOMAIN = "testnet.stellar.org"
QUALITY = "MEDIUM"

[[VALIDATORS]]
ADDRESS = "localhost:123"
HOME_DOMAIN = "testnet.stellar.org"
NAME = "sdf_testnet_1"
PUBLIC_KEY = "GDKXE2OZMJIPOSLNA6N6F2BVCI3O777I2OOC4BV7VOYUEHYX7RTRYA7Y"

[HISTORY.h0]
get = "curl -sf http://localhost:1170/{0} -o {1}"
19 changes: 19 additions & 0 deletions ingest/ledgerbackend/testdata/expected-in-mem-core.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated file, do not edit
DEPRECATED_SQL_LEDGER_STATE = true
FAILURE_SAFETY = -1
HTTP_PORT = 11626
LOG_FILE_PATH = ""
NETWORK_PASSPHRASE = "Public Global Stellar Network ; September 2015"

[[HOME_DOMAINS]]
HOME_DOMAIN = "testnet.stellar.org"
QUALITY = "MEDIUM"

[[VALIDATORS]]
ADDRESS = "localhost:123"
HOME_DOMAIN = "testnet.stellar.org"
NAME = "sdf_testnet_1"
PUBLIC_KEY = "GDKXE2OZMJIPOSLNA6N6F2BVCI3O777I2OOC4BV7VOYUEHYX7RTRYA7Y"

[HISTORY.h0]
get = "curl -sf http://localhost:1170/{0} -o {1}"
4 changes: 2 additions & 2 deletions ingest/ledgerbackend/testdata/expected-offline-core.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated file, do not edit
BUCKETLIST_DB_INDEX_PAGE_SIZE_EXPONENT = 12
DATABASE = "sqlite3://stellar.db"
EXPERIMENTAL_BUCKETLIST_DB = true
EXPERIMENTAL_BUCKETLIST_DB_INDEX_PAGE_SIZE_EXPONENT = 12
DEPRECATED_SQL_LEDGER_STATE = false
FAILURE_SAFETY = 0
HTTP_PORT = 0
LOG_FILE_PATH = ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Generated file, do not edit
DEPRECATED_SQL_LEDGER_STATE = true
EMIT_SOROBAN_TRANSACTION_META_EXT_V1 = true
ENABLE_DIAGNOSTICS_FOR_TX_SUBMISSION = true
ENABLE_SOROBAN_DIAGNOSTIC_EVENTS = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Generated file, do not edit
DEPRECATED_SQL_LEDGER_STATE = true
FAILURE_SAFETY = 0
HTTP_PORT = 0
LOG_FILE_PATH = ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Generated file, do not edit
DEPRECATED_SQL_LEDGER_STATE = true
FAILURE_SAFETY = 0
HTTP_PORT = 0
LOG_FILE_PATH = ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Generated file, do not edit
DEPRECATED_SQL_LEDGER_STATE = true
FAILURE_SAFETY = 0
HTTP_PORT = 0
LOG_FILE_PATH = ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Generated file, do not edit
DEPRECATED_SQL_LEDGER_STATE = true
FAILURE_SAFETY = 0
HTTP_PORT = 0
LOG_FILE_PATH = "/var/stellar-core/test.log"
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
@@ -1,4 +1,5 @@
# Generated file, do not edit
DEPRECATED_SQL_LEDGER_STATE = true
FAILURE_SAFETY = -1
HTTP_PORT = 6789
LOG_FILE_PATH = ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Generated file, do not edit
DEPRECATED_SQL_LEDGER_STATE = true
FAILURE_SAFETY = -1
HTTP_PORT = 11626
LOG_FILE_PATH = ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Generated file, do not edit
DEPRECATED_SQL_LEDGER_STATE = true
EMIT_SOROBAN_TRANSACTION_META_EXT_V1 = true
ENABLE_DIAGNOSTICS_FOR_TX_SUBMISSION = true
ENABLE_SOROBAN_DIAGNOSTIC_EVENTS = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Generated file, do not edit
DEPRECATED_SQL_LEDGER_STATE = true
FAILURE_SAFETY = -1
HTTP_PORT = 11626
LOG_FILE_PATH = ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Generated file, do not edit
DEPRECATED_SQL_LEDGER_STATE = true
FAILURE_SAFETY = -1
HTTP_PORT = 6789
LOG_FILE_PATH = "/var/stellar-core/test.log"
Expand Down
12 changes: 12 additions & 0 deletions ingest/ledgerbackend/testdata/sample-appendix-bucketlistdb.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
BUCKETLIST_DB_INDEX_CUTOFF = 20
BUCKETLIST_DB_INDEX_PAGE_SIZE_EXPONENT = 15

[[HOME_DOMAINS]]
HOME_DOMAIN="testnet.stellar.org"
QUALITY="MEDIUM"

[[VALIDATORS]]
NAME="sdf_testnet_1"
HOME_DOMAIN="testnet.stellar.org"
PUBLIC_KEY="GDKXE2OZMJIPOSLNA6N6F2BVCI3O777I2OOC4BV7VOYUEHYX7RTRYA7Y"
ADDRESS="localhost:123"
11 changes: 11 additions & 0 deletions ingest/ledgerbackend/testdata/sample-appendix-in-memory.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
DEPRECATED_SQL_LEDGER_STATE = false

[[HOME_DOMAINS]]
HOME_DOMAIN="testnet.stellar.org"
QUALITY="MEDIUM"

[[VALIDATORS]]
NAME="sdf_testnet_1"
HOME_DOMAIN="testnet.stellar.org"
PUBLIC_KEY="GDKXE2OZMJIPOSLNA6N6F2BVCI3O777I2OOC4BV7VOYUEHYX7RTRYA7Y"
ADDRESS="localhost:123"
11 changes: 11 additions & 0 deletions ingest/ledgerbackend/testdata/sample-appendix-on-disk.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
DEPRECATED_SQL_LEDGER_STATE = true

[[HOME_DOMAINS]]
HOME_DOMAIN="testnet.stellar.org"
QUALITY="MEDIUM"

[[VALIDATORS]]
NAME="sdf_testnet_1"
HOME_DOMAIN="testnet.stellar.org"
PUBLIC_KEY="GDKXE2OZMJIPOSLNA6N6F2BVCI3O777I2OOC4BV7VOYUEHYX7RTRYA7Y"
ADDRESS="localhost:123"
35 changes: 21 additions & 14 deletions ingest/ledgerbackend/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ var (

//go:embed configs/captive-core-testnet.cfg
TestnetDefaultConfig []byte

defaultBucketListDBPageSize uint = 12
)

const (
Expand Down Expand Up @@ -95,9 +97,9 @@ type captiveCoreTomlValues struct {
Validators []Validator `toml:"VALIDATORS,omitempty"`
HistoryEntries map[string]History `toml:"-"`
QuorumSetEntries map[string]QuorumSet `toml:"-"`
UseBucketListDB bool `toml:"EXPERIMENTAL_BUCKETLIST_DB,omitempty"`
BucketListDBPageSizeExp *uint `toml:"EXPERIMENTAL_BUCKETLIST_DB_INDEX_PAGE_SIZE_EXPONENT,omitempty"`
BucketListDBCutoff *uint `toml:"EXPERIMENTAL_BUCKETLIST_DB_INDEX_CUTOFF,omitempty"`
BucketListDBPageSizeExp *uint `toml:"BUCKETLIST_DB_INDEX_PAGE_SIZE_EXPONENT,omitempty"`
BucketListDBCutoff *uint `toml:"BUCKETLIST_DB_INDEX_CUTOFF,omitempty"`
DeprecatedSqlLedgerState *bool `toml:"DEPRECATED_SQL_LEDGER_STATE,omitempty"`
EnableSorobanDiagnosticEvents *bool `toml:"ENABLE_SOROBAN_DIAGNOSTIC_EVENTS,omitempty"`
TestingMinimumPersistentEntryLifetime *uint `toml:"TESTING_MINIMUM_PERSISTENT_ENTRY_LIFETIME,omitempty"`
TestingSorobanHighLimitOverride *bool `toml:"TESTING_SOROBAN_HIGH_LIMIT_OVERRIDE,omitempty"`
Expand Down Expand Up @@ -446,14 +448,15 @@ func (c *CaptiveCoreToml) setDefaults(params CaptiveCoreTomlParams) {
c.Database = "sqlite3://stellar.db"
}

if def := c.tree.Has("EXPERIMENTAL_BUCKETLIST_DB"); !def && params.UseDB {
c.UseBucketListDB = true
}

if c.UseBucketListDB && !c.tree.Has("EXPERIMENTAL_BUCKETLIST_DB_INDEX_PAGE_SIZE_EXPONENT") {
n := uint(12)
c.BucketListDBPageSizeExp = &n // Set default page size to 4KB
deprecatedSqlLedgerState := false
if !params.UseDB {
deprecatedSqlLedgerState = true
} else {
if !c.tree.Has("BUCKETLIST_DB_INDEX_PAGE_SIZE_EXPONENT") {
c.BucketListDBPageSizeExp = &defaultBucketListDBPageSize
}
}
c.DeprecatedSqlLedgerState = &deprecatedSqlLedgerState

if !c.tree.Has("NETWORK_PASSPHRASE") {
c.NetworkPassphrase = params.NetworkPassphrase
Expand Down Expand Up @@ -543,10 +546,14 @@ func (c *CaptiveCoreToml) validate(params CaptiveCoreTomlParams) error {
)
}

if def := c.tree.Has("EXPERIMENTAL_BUCKETLIST_DB"); def && !params.UseDB {
return fmt.Errorf(
"BucketListDB enabled in captive core config file, requires Horizon flag --captive-core-use-db",
)
if c.tree.Has("DEPRECATED_SQL_LEDGER_STATE") {
if params.UseDB && *c.DeprecatedSqlLedgerState {
return fmt.Errorf("CAPTIVE_CORE_USE_DB parameter is set to true, indicating stellar-core on-disk mode," +
" in which DEPRECATED_SQL_LEDGER_STATE must be set to false")
} else if !params.UseDB && !*c.DeprecatedSqlLedgerState {
return fmt.Errorf("CAPTIVE_CORE_USE_DB parameter is set to false, indicating stellar-core in-memory mode," +
" in which DEPRECATED_SQL_LEDGER_STATE must be set to true")
}
}

homeDomainSet := map[string]HomeDomain{}
Expand Down
71 changes: 57 additions & 14 deletions ingest/ledgerbackend/toml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package ledgerbackend

import (
"io/ioutil"
"os"
"path/filepath"
"strconv"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -28,6 +26,7 @@ func TestCaptiveCoreTomlValidation(t *testing.T) {
peerPort *uint
logPath *string
expectedError string
inMemory bool
}{
{
name: "mismatching NETWORK_PASSPHRASE",
Expand Down Expand Up @@ -203,6 +202,19 @@ func TestCaptiveCoreTomlValidation(t *testing.T) {
appendPath: filepath.Join("testdata", "appendix-with-bucket-dir-path.cfg"),
expectedError: "could not unmarshal captive core toml: setting BUCKET_DIR_PATH is disallowed for Captive Core, use CAPTIVE_CORE_STORAGE_PATH instead",
},
{
name: "invalid DEPRECATED_SQL_LEDGER_STATE on-disk",
appendPath: filepath.Join("testdata", "sample-appendix-on-disk.cfg"),
expectedError: "invalid captive core toml: CAPTIVE_CORE_USE_DB parameter is set to true, indicating " +
"stellar-core on-disk mode, in which DEPRECATED_SQL_LEDGER_STATE must be set to false",
},
{
name: "invalid DEPRECATED_SQL_LEDGER_STATE in-memory",
appendPath: filepath.Join("testdata", "sample-appendix-in-memory.cfg"),
expectedError: "invalid captive core toml: CAPTIVE_CORE_USE_DB parameter is set to false, indicating " +
"stellar-core in-memory mode, in which DEPRECATED_SQL_LEDGER_STATE must be set to true",
inMemory: true,
},
} {
t.Run(testCase.name, func(t *testing.T) {
params := CaptiveCoreTomlParams{
Expand All @@ -212,25 +224,14 @@ func TestCaptiveCoreTomlValidation(t *testing.T) {
PeerPort: testCase.peerPort,
LogPath: testCase.logPath,
Strict: true,
UseDB: !testCase.inMemory,
}
_, err := NewCaptiveCoreTomlFromFile(testCase.appendPath, params)
assert.EqualError(t, err, testCase.expectedError)
})
}
}

func checkTestingAboveProtocol19() bool {
str := os.Getenv("HORIZON_INTEGRATION_TESTS_CORE_MAX_SUPPORTED_PROTOCOL")
if str == "" {
return false
}
version, err := strconv.ParseUint(str, 10, 32)
if err != nil {
return false
}
return uint32(version) > 19
}

func TestGenerateConfig(t *testing.T) {
for _, testCase := range []struct {
name string
Expand Down Expand Up @@ -352,6 +353,22 @@ func TestGenerateConfig(t *testing.T) {
expectedPath: filepath.Join("testdata", "expected-online-with-appendix-minimum-persistent-entry.cfg"),
logPath: nil,
},
{
name: "default BucketlistDB config",
mode: stellarCoreRunnerModeOnline,
appendPath: filepath.Join("testdata", "sample-appendix.cfg"),
expectedPath: filepath.Join("testdata", "expected-default-bucketlistdb-core.cfg"),
useDB: true,
logPath: nil,
},
{
name: "BucketlistDB config in appendix",
mode: stellarCoreRunnerModeOnline,
appendPath: filepath.Join("testdata", "sample-appendix-bucketlistdb.cfg"),
expectedPath: filepath.Join("testdata", "expected-bucketlistdb-core.cfg"),
useDB: true,
logPath: nil,
},
} {
t.Run(testCase.name, func(t *testing.T) {
var err error
Expand Down Expand Up @@ -385,6 +402,29 @@ func TestGenerateConfig(t *testing.T) {
}
}

func TestGenerateCoreConfigInMemory(t *testing.T) {
appendPath := filepath.Join("testdata", "sample-appendix.cfg")
expectedPath := filepath.Join("testdata", "expected-in-mem-core.cfg")
var err error
var captiveCoreToml *CaptiveCoreToml
params := CaptiveCoreTomlParams{
NetworkPassphrase: "Public Global Stellar Network ; September 2015",
HistoryArchiveURLs: []string{"http://localhost:1170"},
Strict: false,
UseDB: false,
}
captiveCoreToml, err = NewCaptiveCoreTomlFromFile(appendPath, params)
assert.NoError(t, err)

configBytes, err := generateConfig(captiveCoreToml, stellarCoreRunnerModeOnline)
assert.NoError(t, err)

expectedByte, err := ioutil.ReadFile(expectedPath)
assert.NoError(t, err)

assert.Equal(t, string(expectedByte), string(configBytes))
}

func TestHistoryArchiveURLTrailingSlash(t *testing.T) {
httpPort := uint(8000)
peerPort := uint(8000)
Expand Down Expand Up @@ -461,6 +501,9 @@ func TestDBConfigDefaultsToSqlite(t *testing.T) {
toml := CaptiveCoreToml{}
require.NoError(t, toml.unmarshal(configBytes, true))
assert.Equal(t, toml.Database, "sqlite3://stellar.db")
assert.Equal(t, *toml.DeprecatedSqlLedgerState, false)
assert.Equal(t, *toml.BucketListDBPageSizeExp, defaultBucketListDBPageSize)
assert.Equal(t, toml.BucketListDBCutoff, (*uint)(nil))
}

func TestNonDBConfigDoesNotUpdateDatabase(t *testing.T) {
Expand Down
Loading

0 comments on commit 90c18e2

Please sign in to comment.