Skip to content

Commit

Permalink
Add DEPRECATED_SQL_LEDGER_STATE param. Add unit tests for DEPRECATED_…
Browse files Browse the repository at this point in the history
…SQL_LEDGER_STATE.
  • Loading branch information
urvisavla committed Jun 7, 2024
1 parent d2e9ad6 commit 2a4e60d
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 9 deletions.
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}"
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"
5 changes: 3 additions & 2 deletions ingest/ledgerbackend/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ var (

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

DefaultBucketListDBPageSize uint = 12
)

const (
Expand Down Expand Up @@ -541,8 +543,7 @@ func (c *CaptiveCoreToml) setDefaults(params CaptiveCoreTomlParams) {
c.DeprecatedSqlLedgerState = true
} else {
if !c.tree.Has("BUCKETLIST_DB_INDEX_PAGE_SIZE_EXPONENT") {
n := uint(12)
c.BucketListDBPageSizeExp = &n // Set default page size to 4KB
c.BucketListDBPageSizeExp = &DefaultBucketListDBPageSize
}
c.DeprecatedSqlLedgerState = false
}
Expand Down
56 changes: 49 additions & 7 deletions ingest/ledgerbackend/toml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,6 @@ func TestCaptiveCoreTomlValidation(t *testing.T) {
PeerPort: testCase.peerPort,
LogPath: testCase.logPath,
Strict: true,
checkCoreVersion: func(coreBinaryPath string) coreVersion {
return coreVersion{
major: 21,
minor: 0,
ledgerProtocolVersion: 21,
}
},
}
_, err := NewCaptiveCoreTomlFromFile(testCase.appendPath, params)
assert.EqualError(t, err, testCase.expectedError)
Expand Down Expand Up @@ -359,6 +352,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 @@ -399,6 +408,36 @@ 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,
checkCoreVersion: func(coreBinaryPath string) coreVersion {
return coreVersion{
major: 21,
minor: 0,
ledgerProtocolVersion: 21,
}
},
}
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 @@ -475,6 +514,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
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
EXPERIMENTAL_BUCKETLIST_DB = true
PEER_PORT=11725
ARTIFICIALLY_ACCELERATE_TIME_FOR_TESTING=true

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DEPRECATED_SQL_LEDGER_STATE=false
ARTIFICIALLY_ACCELERATE_TIME_FOR_TESTING=true

NETWORK_PASSPHRASE="Standalone Network ; February 2017"
Expand Down
1 change: 1 addition & 0 deletions services/horizon/docker/stellar-core-integration-tests.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DEPRECATED_SQL_LEDGER_STATE=false
ARTIFICIALLY_ACCELERATE_TIME_FOR_TESTING=true

NETWORK_PASSPHRASE="Standalone Network ; February 2017"
Expand Down

0 comments on commit 2a4e60d

Please sign in to comment.