Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ingest/ledgerbackend: tweak enforcing toml parameters and tests #5317

Merged
merged 2 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
EMIT_SOROBAN_TRANSACTION_META_EXT_V1=false
ENABLE_SOROBAN_DIAGNOSTIC_EVENTS=false
ENABLE_DIAGNOSTICS_FOR_TX_SUBMISSION=false

This file was deleted.

2 changes: 2 additions & 0 deletions ingest/ledgerbackend/testdata/expected-offline-core.cfg
Original file line number Diff line number Diff line change
@@ -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 = ""
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
47 changes: 33 additions & 14 deletions ingest/ledgerbackend/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{}
}
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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 {
Expand Down
120 changes: 58 additions & 62 deletions ingest/ledgerbackend/toml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func checkTestingAboveProtocol19() bool {
}

func TestGenerateConfig(t *testing.T) {
testCases := []struct {
for _, testCase := range []struct {
name string
appendPath string
mode stellarCoreRunnerMode
Expand All @@ -242,6 +242,7 @@ func TestGenerateConfig(t *testing.T) {
logPath *string
useDB bool
enforceSorobanDiagnosticEvents bool
enforceEmitMetaV1 bool
}{
{
name: "offline config with no appendix",
Expand Down Expand Up @@ -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)
Expand All @@ -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))
})
}
}
Expand Down Expand Up @@ -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))
}
Loading