diff --git a/ingest/ledgerbackend/testdata/appendix-disable-diagnostic-events-and-metav1.cfg b/ingest/ledgerbackend/testdata/appendix-disable-diagnostic-events-and-metav1.cfg new file mode 100644 index 0000000000..6d3b643426 --- /dev/null +++ b/ingest/ledgerbackend/testdata/appendix-disable-diagnostic-events-and-metav1.cfg @@ -0,0 +1,3 @@ +EMIT_SOROBAN_TRANSACTION_META_EXT_V1=false +ENABLE_SOROBAN_DIAGNOSTIC_EVENTS=false +ENABLE_DIAGNOSTICS_FOR_TX_SUBMISSION=false \ No newline at end of file diff --git a/ingest/ledgerbackend/testdata/appendix-disable-diagnostic-events.cfg b/ingest/ledgerbackend/testdata/appendix-disable-diagnostic-events.cfg deleted file mode 100644 index 9fcb0f804b..0000000000 --- a/ingest/ledgerbackend/testdata/appendix-disable-diagnostic-events.cfg +++ /dev/null @@ -1 +0,0 @@ -ENABLE_SOROBAN_DIAGNOSTIC_EVENTS=false diff --git a/ingest/ledgerbackend/testdata/expected-offline-core.cfg b/ingest/ledgerbackend/testdata/expected-offline-core.cfg index d6a80a628d..53838f6165 100644 --- a/ingest/ledgerbackend/testdata/expected-offline-core.cfg +++ b/ingest/ledgerbackend/testdata/expected-offline-core.cfg @@ -1,5 +1,7 @@ # Generated file, do not edit DATABASE = "sqlite3://stellar.db" +EXPERIMENTAL_BUCKETLIST_DB = true +EXPERIMENTAL_BUCKETLIST_DB_INDEX_PAGE_SIZE_EXPONENT = 12 FAILURE_SAFETY = 0 HTTP_PORT = 0 LOG_FILE_PATH = "" diff --git a/ingest/ledgerbackend/testdata/expected-offline-enforce-diagnostic-events.cfg b/ingest/ledgerbackend/testdata/expected-offline-enforce-diag-events-and-metav1.cfg similarity index 82% rename from ingest/ledgerbackend/testdata/expected-offline-enforce-diagnostic-events.cfg rename to ingest/ledgerbackend/testdata/expected-offline-enforce-diag-events-and-metav1.cfg index 48b6223377..8c66b4a5ad 100644 --- a/ingest/ledgerbackend/testdata/expected-offline-enforce-diagnostic-events.cfg +++ b/ingest/ledgerbackend/testdata/expected-offline-enforce-diag-events-and-metav1.cfg @@ -1,4 +1,6 @@ # Generated file, do not edit +EMIT_SOROBAN_TRANSACTION_META_EXT_V1 = true +ENABLE_DIAGNOSTICS_FOR_TX_SUBMISSION = true ENABLE_SOROBAN_DIAGNOSTIC_EVENTS = true FAILURE_SAFETY = 0 HTTP_PORT = 0 diff --git a/ingest/ledgerbackend/testdata/expected-online-with-no-http-port-diag-events.cfg b/ingest/ledgerbackend/testdata/expected-online-with-no-http-port-diag-events-metav1.cfg similarity index 85% rename from ingest/ledgerbackend/testdata/expected-online-with-no-http-port-diag-events.cfg rename to ingest/ledgerbackend/testdata/expected-online-with-no-http-port-diag-events-metav1.cfg index fa785894e5..f2227376a9 100644 --- a/ingest/ledgerbackend/testdata/expected-online-with-no-http-port-diag-events.cfg +++ b/ingest/ledgerbackend/testdata/expected-online-with-no-http-port-diag-events-metav1.cfg @@ -1,4 +1,6 @@ # Generated file, do not edit +EMIT_SOROBAN_TRANSACTION_META_EXT_V1 = true +ENABLE_DIAGNOSTICS_FOR_TX_SUBMISSION = true ENABLE_SOROBAN_DIAGNOSTIC_EVENTS = true FAILURE_SAFETY = -1 HTTP_PORT = 11626 diff --git a/ingest/ledgerbackend/toml.go b/ingest/ledgerbackend/toml.go index f156d5b888..a4f61a454d 100644 --- a/ingest/ledgerbackend/toml.go +++ b/ingest/ledgerbackend/toml.go @@ -342,8 +342,12 @@ type CaptiveCoreTomlParams struct { UseDB bool // the path to the core binary, used to introspect core at runtime, determine some toml capabilities CoreBinaryPath string - // Enforce EnableSorobanDiagnosticEvents when not disabled explicitly + // Enforce EnableSorobanDiagnosticEvents and EnableDiagnosticsForTxSubmission when not disabled explicitly EnforceSorobanDiagnosticEvents bool + // Enfore EnableSorobanTransactionMetaExtV1 when not disabled explicitly + EnforceSorobanTransactionMetaExtV1 bool + // used for testing + checkCoreVersion func(coreBinaryPath string) coreVersion } // NewCaptiveCoreTomlFromFile constructs a new CaptiveCoreToml instance by merging configuration @@ -470,7 +474,7 @@ func (c *coreVersion) IsProtocolVersionEqualOrAbove(protocolVer int) bool { return c.ledgerProtocolVersion >= protocolVer } -func (c *CaptiveCoreToml) checkCoreVersion(coreBinaryPath string) coreVersion { +func checkCoreVersion(coreBinaryPath string) coreVersion { if coreBinaryPath == "" { return coreVersion{} } @@ -529,10 +533,14 @@ func (c *CaptiveCoreToml) setDefaults(params CaptiveCoreTomlParams) { c.Database = "sqlite3://stellar.db" } - coreVersion := c.checkCoreVersion(params.CoreBinaryPath) + checkCoreVersionF := params.checkCoreVersion + if checkCoreVersionF == nil { + checkCoreVersionF = checkCoreVersion + } + currentCoreVersion := checkCoreVersionF(params.CoreBinaryPath) if def := c.tree.Has("EXPERIMENTAL_BUCKETLIST_DB"); !def && params.UseDB { // Supports version 19.6 and above - if coreVersion.IsEqualOrAbove(MinimalBucketListDBCoreSupportVersionMajor, MinimalBucketListDBCoreSupportVersionMinor) { + if currentCoreVersion.IsEqualOrAbove(MinimalBucketListDBCoreSupportVersionMajor, MinimalBucketListDBCoreSupportVersionMinor) { c.UseBucketListDB = true } } @@ -575,19 +583,30 @@ func (c *CaptiveCoreToml) setDefaults(params CaptiveCoreTomlParams) { } } - // starting version 20, we have dignostics events. - if params.EnforceSorobanDiagnosticEvents && coreVersion.IsProtocolVersionEqualOrAbove(MinimalSorobanProtocolSupport) { - if c.EnableSorobanDiagnosticEvents == nil { - // We are generating the file from scratch or the user didn't explicitly oppose to diagnostic events in the config file. - // Enforce it. - t := true - c.EnableSorobanDiagnosticEvents = &t + if params.EnforceSorobanDiagnosticEvents { + if currentCoreVersion.IsEqualOrAbove(20, 0) { + enforceOption(&c.EnableSorobanDiagnosticEvents) } - if !*c.EnableSorobanDiagnosticEvents { - // The user opposed to diagnostic events in the config file, but there is no need to pass on the option - c.EnableSorobanDiagnosticEvents = nil + if currentCoreVersion.IsEqualOrAbove(20, 1) { + enforceOption(&c.EnableDiagnosticsForTxSubmission) } } + if params.EnforceSorobanTransactionMetaExtV1 && currentCoreVersion.IsEqualOrAbove(20, 4) { + enforceOption(&c.EnableEmitSorobanTransactionMetaExtV1) + } +} + +func enforceOption(opt **bool) { + if *opt == nil { + // We are generating the file from scratch or the user didn't explicitly oppose the option. + // Enforce it. + t := true + *opt = &t + } + if !**opt { + // The user opposed the option, but there is no need to pass it on + *opt = nil + } } func (c *CaptiveCoreToml) validate(params CaptiveCoreTomlParams) error { diff --git a/ingest/ledgerbackend/toml_test.go b/ingest/ledgerbackend/toml_test.go index c5d40c77e3..fecf50c8d9 100644 --- a/ingest/ledgerbackend/toml_test.go +++ b/ingest/ledgerbackend/toml_test.go @@ -232,7 +232,7 @@ func checkTestingAboveProtocol19() bool { } func TestGenerateConfig(t *testing.T) { - testCases := []struct { + for _, testCase := range []struct { name string appendPath string mode stellarCoreRunnerMode @@ -242,6 +242,7 @@ func TestGenerateConfig(t *testing.T) { logPath *string useDB bool enforceSorobanDiagnosticEvents bool + enforceEmitMetaV1 bool }{ { name: "offline config with no appendix", @@ -315,67 +316,63 @@ func TestGenerateConfig(t *testing.T) { httpPort: newUint(6789), peerPort: newUint(12345), logPath: nil, - }} - if checkTestingAboveProtocol19() { - testCases = append(testCases, []struct { - name string - appendPath string - mode stellarCoreRunnerMode - expectedPath string - httpPort *uint - peerPort *uint - logPath *string - useDB bool - enforceSorobanDiagnosticEvents bool - }{ - { - name: "offline config with enforce diagnostic events", - mode: stellarCoreRunnerModeOffline, - expectedPath: filepath.Join("testdata", "expected-offline-enforce-diagnostic-events.cfg"), - logPath: nil, - enforceSorobanDiagnosticEvents: true, - }, - { - name: "offline config disabling enforced diagnostic events", - mode: stellarCoreRunnerModeOffline, - expectedPath: filepath.Join("testdata", "expected-offline-enforce-disabled-diagnostic-events.cfg"), - appendPath: filepath.Join("testdata", "appendix-disable-diagnostic-events.cfg"), - logPath: nil, - enforceSorobanDiagnosticEvents: true, - }, - { - name: "online config with enforce diagnostic events", - mode: stellarCoreRunnerModeOnline, - appendPath: filepath.Join("testdata", "sample-appendix.cfg"), - expectedPath: filepath.Join("testdata", "expected-online-with-no-http-port-diag-events.cfg"), - httpPort: nil, - peerPort: newUint(12345), - logPath: nil, - enforceSorobanDiagnosticEvents: true, - }, - { - name: "offline config with minimum persistent entry in appendix", - mode: stellarCoreRunnerModeOnline, - appendPath: filepath.Join("testdata", "appendix-with-minimum-persistent-entry.cfg"), - expectedPath: filepath.Join("testdata", "expected-online-with-appendix-minimum-persistent-entry.cfg"), - logPath: nil, - }, - }...) - } - - for _, testCase := range testCases { + }, + { + name: "offline config with enforce diagnostic events and metav1", + mode: stellarCoreRunnerModeOffline, + expectedPath: filepath.Join("testdata", "expected-offline-enforce-diag-events-and-metav1.cfg"), + logPath: nil, + enforceSorobanDiagnosticEvents: true, + enforceEmitMetaV1: true, + }, + { + name: "offline config disabling enforced diagnostic events and metav1", + mode: stellarCoreRunnerModeOffline, + expectedPath: filepath.Join("testdata", "expected-offline-enforce-disabled-diagnostic-events.cfg"), + appendPath: filepath.Join("testdata", "appendix-disable-diagnostic-events-and-metav1.cfg"), + logPath: nil, + enforceSorobanDiagnosticEvents: true, + enforceEmitMetaV1: true, + }, + { + name: "online config with enforce diagnostic events and meta v1", + mode: stellarCoreRunnerModeOnline, + appendPath: filepath.Join("testdata", "sample-appendix.cfg"), + expectedPath: filepath.Join("testdata", "expected-online-with-no-http-port-diag-events-metav1.cfg"), + httpPort: nil, + peerPort: newUint(12345), + logPath: nil, + enforceSorobanDiagnosticEvents: true, + enforceEmitMetaV1: true, + }, + { + name: "offline config with minimum persistent entry in appendix", + mode: stellarCoreRunnerModeOnline, + appendPath: filepath.Join("testdata", "appendix-with-minimum-persistent-entry.cfg"), + expectedPath: filepath.Join("testdata", "expected-online-with-appendix-minimum-persistent-entry.cfg"), + logPath: nil, + }, + } { t.Run(testCase.name, func(t *testing.T) { var err error var captiveCoreToml *CaptiveCoreToml params := CaptiveCoreTomlParams{ - NetworkPassphrase: "Public Global Stellar Network ; September 2015", - HistoryArchiveURLs: []string{"http://localhost:1170"}, - HTTPPort: testCase.httpPort, - PeerPort: testCase.peerPort, - LogPath: testCase.logPath, - Strict: false, - UseDB: testCase.useDB, - EnforceSorobanDiagnosticEvents: testCase.enforceSorobanDiagnosticEvents, + NetworkPassphrase: "Public Global Stellar Network ; September 2015", + HistoryArchiveURLs: []string{"http://localhost:1170"}, + HTTPPort: testCase.httpPort, + PeerPort: testCase.peerPort, + LogPath: testCase.logPath, + Strict: false, + UseDB: testCase.useDB, + EnforceSorobanDiagnosticEvents: testCase.enforceSorobanDiagnosticEvents, + EnforceSorobanTransactionMetaExtV1: testCase.enforceEmitMetaV1, + checkCoreVersion: func(coreBinaryPath string) coreVersion { + return coreVersion{ + major: 21, + minor: 0, + ledgerProtocolVersion: 21, + } + }, } if testCase.appendPath != "" { captiveCoreToml, err = NewCaptiveCoreTomlFromFile(testCase.appendPath, params) @@ -390,7 +387,7 @@ func TestGenerateConfig(t *testing.T) { expectedByte, err := ioutil.ReadFile(testCase.expectedPath) assert.NoError(t, err) - assert.Equal(t, string(configBytes), string(expectedByte)) + assert.Equal(t, string(expectedByte), string(configBytes)) }) } } @@ -507,7 +504,6 @@ func TestCheckCoreVersion(t *testing.T) { t.SkipNow() return } - var cctoml CaptiveCoreToml - version := cctoml.checkCoreVersion(coreBin) - require.True(t, version.IsEqualOrAbove(19, 0)) + version := checkCoreVersion(coreBin) + require.True(t, version.IsEqualOrAbove(20, 0)) }