Skip to content

Commit

Permalink
Addressing review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
urvisavla committed Jun 13, 2024
1 parent cef3e0b commit 827c6b0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
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"
14 changes: 10 additions & 4 deletions ingest/ledgerbackend/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var (
//go:embed configs/captive-core-testnet.cfg
TestnetDefaultConfig []byte

DefaultBucketListDBPageSize uint = 12
defaultBucketListDBPageSize uint = 12
)

const (
Expand Down Expand Up @@ -544,7 +544,7 @@ func (c *CaptiveCoreToml) setDefaults(params CaptiveCoreTomlParams) {
deprecatedSqlLedgerState = true
} else {
if !c.tree.Has("BUCKETLIST_DB_INDEX_PAGE_SIZE_EXPONENT") {
c.BucketListDBPageSizeExp = &DefaultBucketListDBPageSize
c.BucketListDBPageSizeExp = &defaultBucketListDBPageSize
}
}
c.DeprecatedSqlLedgerState = &deprecatedSqlLedgerState
Expand Down Expand Up @@ -641,8 +641,14 @@ func (c *CaptiveCoreToml) validate(params CaptiveCoreTomlParams) error {
)
}

if def := c.tree.Has("DEPRECATED_SQL_LEDGER_STATE"); def && 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")
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
16 changes: 12 additions & 4 deletions ingest/ledgerbackend/toml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func TestCaptiveCoreTomlValidation(t *testing.T) {
peerPort *uint
logPath *string
expectedError string
inMemory bool
}{
{
name: "mismatching NETWORK_PASSPHRASE",
Expand Down Expand Up @@ -204,11 +205,18 @@ func TestCaptiveCoreTomlValidation(t *testing.T) {
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",
appendPath: filepath.Join("testdata", "sample-appendix-deprecated_sql_ledger_state.cfg"),
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 @@ -218,7 +226,7 @@ func TestCaptiveCoreTomlValidation(t *testing.T) {
PeerPort: testCase.peerPort,
LogPath: testCase.logPath,
Strict: true,
UseDB: true,
UseDB: !testCase.inMemory,
}
_, err := NewCaptiveCoreTomlFromFile(testCase.appendPath, params)
assert.EqualError(t, err, testCase.expectedError)
Expand Down Expand Up @@ -522,7 +530,7 @@ func TestDBConfigDefaultsToSqlite(t *testing.T) {
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.BucketListDBPageSizeExp, defaultBucketListDBPageSize)
assert.Equal(t, toml.BucketListDBCutoff, (*uint)(nil))
}

Expand Down

0 comments on commit 827c6b0

Please sign in to comment.