From 53db5ce7726b44a7a6cee60852a716926402d6a7 Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Thu, 27 Jul 2023 20:44:38 +0200 Subject: [PATCH] ingest/ledgerbackend: Add parameter to enforce diagnostic events in captive core backend The configuration parameter (`EnforceSorobanDiagnosticEvents`)is optional and makes sure `ENABLE_SOROBAN_DIAGNOSTIC_EVENTS` is set to true for captive core unless the user explicitly sets `ENABLE_SOROBAN_DIAGNOSTIC_EVENTS=false` in the appendix file. This fixes https://github.com/stellar/soroban-tools/issues/806 (when `EnforceSorobanDiagnosticEvents` is set to true) --- .../appendix-disable-diagnostic-events.cfg | 1 + ...cted-offline-enforce-diagnostic-events.cfg | 15 +++++ ...ine-enforce-disabled-diagnostic-events.cfg | 14 +++++ ...d-online-with-no-http-port-diag-events.cfg | 20 +++++++ ingest/ledgerbackend/toml.go | 16 +++++- ingest/ledgerbackend/toml_test.go | 57 ++++++++++++++----- 6 files changed, 107 insertions(+), 16 deletions(-) create mode 100644 ingest/ledgerbackend/testdata/appendix-disable-diagnostic-events.cfg create mode 100644 ingest/ledgerbackend/testdata/expected-offline-enforce-diagnostic-events.cfg create mode 100644 ingest/ledgerbackend/testdata/expected-offline-enforce-disabled-diagnostic-events.cfg create mode 100644 ingest/ledgerbackend/testdata/expected-online-with-no-http-port-diag-events.cfg diff --git a/ingest/ledgerbackend/testdata/appendix-disable-diagnostic-events.cfg b/ingest/ledgerbackend/testdata/appendix-disable-diagnostic-events.cfg new file mode 100644 index 0000000000..9fcb0f804b --- /dev/null +++ b/ingest/ledgerbackend/testdata/appendix-disable-diagnostic-events.cfg @@ -0,0 +1 @@ +ENABLE_SOROBAN_DIAGNOSTIC_EVENTS=false diff --git a/ingest/ledgerbackend/testdata/expected-offline-enforce-diagnostic-events.cfg b/ingest/ledgerbackend/testdata/expected-offline-enforce-diagnostic-events.cfg new file mode 100644 index 0000000000..48b6223377 --- /dev/null +++ b/ingest/ledgerbackend/testdata/expected-offline-enforce-diagnostic-events.cfg @@ -0,0 +1,15 @@ +# Generated file, do not edit +ENABLE_SOROBAN_DIAGNOSTIC_EVENTS = true +FAILURE_SAFETY = 0 +HTTP_PORT = 0 +LOG_FILE_PATH = "" +NETWORK_PASSPHRASE = "Public Global Stellar Network ; September 2015" +RUN_STANDALONE = true +UNSAFE_QUORUM = true + +[HISTORY.h0] + get = "curl -sf http://localhost:1170/{0} -o {1}" + +[QUORUM_SET] + THRESHOLD_PERCENT = 100 + VALIDATORS = ["GCZBOIAY4HLKAJVNJORXZOZRAY2BJDBZHKPBHZCRAIUR5IHC2UHBGCQR"] diff --git a/ingest/ledgerbackend/testdata/expected-offline-enforce-disabled-diagnostic-events.cfg b/ingest/ledgerbackend/testdata/expected-offline-enforce-disabled-diagnostic-events.cfg new file mode 100644 index 0000000000..df307a3a00 --- /dev/null +++ b/ingest/ledgerbackend/testdata/expected-offline-enforce-disabled-diagnostic-events.cfg @@ -0,0 +1,14 @@ +# Generated file, do not edit +FAILURE_SAFETY = 0 +HTTP_PORT = 0 +LOG_FILE_PATH = "" +NETWORK_PASSPHRASE = "Public Global Stellar Network ; September 2015" +RUN_STANDALONE = true +UNSAFE_QUORUM = true + +[HISTORY.h0] + get = "curl -sf http://localhost:1170/{0} -o {1}" + +[QUORUM_SET] + THRESHOLD_PERCENT = 100 + VALIDATORS = ["GCZBOIAY4HLKAJVNJORXZOZRAY2BJDBZHKPBHZCRAIUR5IHC2UHBGCQR"] 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.cfg new file mode 100644 index 0000000000..fa785894e5 --- /dev/null +++ b/ingest/ledgerbackend/testdata/expected-online-with-no-http-port-diag-events.cfg @@ -0,0 +1,20 @@ +# Generated file, do not edit +ENABLE_SOROBAN_DIAGNOSTIC_EVENTS = true +FAILURE_SAFETY = -1 +HTTP_PORT = 11626 +LOG_FILE_PATH = "" +NETWORK_PASSPHRASE = "Public Global Stellar Network ; September 2015" +PEER_PORT = 12345 + +[[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}" diff --git a/ingest/ledgerbackend/toml.go b/ingest/ledgerbackend/toml.go index 600e11d329..ecfcae10c8 100644 --- a/ingest/ledgerbackend/toml.go +++ b/ingest/ledgerbackend/toml.go @@ -89,7 +89,7 @@ type captiveCoreTomlValues struct { 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"` - EnableSorobanDiagnosticEvents bool `toml:"ENABLE_SOROBAN_DIAGNOSTIC_EVENTS,omitempty"` + EnableSorobanDiagnosticEvents *bool `toml:"ENABLE_SOROBAN_DIAGNOSTIC_EVENTS,omitempty"` } // QuorumSetIsConfigured returns true if there is a quorum set defined in the configuration. @@ -326,6 +326,8 @@ type CaptiveCoreTomlParams struct { UseDB bool // the path to the core binary, used to introspect core at runtie, determine some toml capabilities CoreBinaryPath string + // Enforce EnableSorobanDiagnosticEvents when not disabled explicitly + EnforceSorobanDiagnosticEvents bool } // NewCaptiveCoreTomlFromFile constructs a new CaptiveCoreToml instance by merging configuration @@ -499,6 +501,18 @@ func (c *CaptiveCoreToml) setDefaults(params CaptiveCoreTomlParams) { } } } + if params.EnforceSorobanDiagnosticEvents { + 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 !*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 + } + } } func (c *CaptiveCoreToml) validate(params CaptiveCoreTomlParams) error { diff --git a/ingest/ledgerbackend/toml_test.go b/ingest/ledgerbackend/toml_test.go index 92f5c10cb5..1271591cfe 100644 --- a/ingest/ledgerbackend/toml_test.go +++ b/ingest/ledgerbackend/toml_test.go @@ -219,14 +219,15 @@ func TestCaptiveCoreTomlValidation(t *testing.T) { func TestGenerateConfig(t *testing.T) { for _, testCase := range []struct { - name string - appendPath string - mode stellarCoreRunnerMode - expectedPath string - httpPort *uint - peerPort *uint - logPath *string - useDB bool + name string + appendPath string + mode stellarCoreRunnerMode + expectedPath string + httpPort *uint + peerPort *uint + logPath *string + useDB bool + enforceSorobanDiagnosticEvents bool }{ { name: "offline config with no appendix", @@ -301,18 +302,44 @@ func TestGenerateConfig(t *testing.T) { peerPort: newUint(12345), logPath: nil, }, + { + 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, + }, } { 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, + 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, } if testCase.appendPath != "" { captiveCoreToml, err = NewCaptiveCoreTomlFromFile(testCase.appendPath, params)