diff --git a/ingest/ledgerbackend/testdata/sample-appendix-in-memory.cfg b/ingest/ledgerbackend/testdata/sample-appendix-in-memory.cfg new file mode 100644 index 0000000000..958019998c --- /dev/null +++ b/ingest/ledgerbackend/testdata/sample-appendix-in-memory.cfg @@ -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" diff --git a/ingest/ledgerbackend/testdata/sample-appendix-deprecated_sql_ledger_state.cfg b/ingest/ledgerbackend/testdata/sample-appendix-on-disk.cfg similarity index 100% rename from ingest/ledgerbackend/testdata/sample-appendix-deprecated_sql_ledger_state.cfg rename to ingest/ledgerbackend/testdata/sample-appendix-on-disk.cfg diff --git a/ingest/ledgerbackend/toml.go b/ingest/ledgerbackend/toml.go index efd2bdf3a9..1edb79f7db 100644 --- a/ingest/ledgerbackend/toml.go +++ b/ingest/ledgerbackend/toml.go @@ -24,7 +24,7 @@ var ( //go:embed configs/captive-core-testnet.cfg TestnetDefaultConfig []byte - DefaultBucketListDBPageSize uint = 12 + defaultBucketListDBPageSize uint = 12 ) const ( @@ -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 @@ -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{} diff --git a/ingest/ledgerbackend/toml_test.go b/ingest/ledgerbackend/toml_test.go index 1c51068c44..a76d2c01f6 100644 --- a/ingest/ledgerbackend/toml_test.go +++ b/ingest/ledgerbackend/toml_test.go @@ -28,6 +28,7 @@ func TestCaptiveCoreTomlValidation(t *testing.T) { peerPort *uint logPath *string expectedError string + inMemory bool }{ { name: "mismatching NETWORK_PASSPHRASE", @@ -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{ @@ -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) @@ -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)) }