Skip to content

Commit

Permalink
ingest/ledgerbackend: Add parameter to enforce diagnostic events in c…
Browse files Browse the repository at this point in the history
…aptive 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 stellar/stellar-cli#806 (when `EnforceSorobanDiagnosticEvents` is set to true)
  • Loading branch information
2opremio committed Jul 28, 2023
1 parent db6a29c commit 53db5ce
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ENABLE_SOROBAN_DIAGNOSTIC_EVENTS=false
Original file line number Diff line number Diff line change
@@ -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"]
Original file line number Diff line number Diff line change
@@ -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"]
Original file line number Diff line number Diff line change
@@ -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}"
16 changes: 15 additions & 1 deletion ingest/ledgerbackend/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
57 changes: 42 additions & 15 deletions ingest/ledgerbackend/toml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 53db5ce

Please sign in to comment.