Skip to content
New issue

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

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

Already on GitHub? # to your account

ingest/ledgerbackend: Add core configuration support for BUCKETLIST_DB_MEMORY_FOR_CACHING #5632

Merged
merged 4 commits into from
Mar 26, 2025
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,12 @@
BUCKETLIST_DB_MEMORY_FOR_CACHING = 3000

[[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"

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated file, do not edit
BUCKETLIST_DB_INDEX_CUTOFF = 20
BUCKETLIST_DB_INDEX_PAGE_SIZE_EXPONENT = 15
BUCKETLIST_DB_MEMORY_FOR_CACHING = 0
DATABASE = "sqlite3://stellar.db"
DEPRECATED_SQL_LEDGER_STATE = false
FAILURE_SAFETY = -1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated file, do not edit
BUCKETLIST_DB_INDEX_PAGE_SIZE_EXPONENT = 12
DATABASE = "sqlite3://stellar.db"
DEPRECATED_SQL_LEDGER_STATE = false
FAILURE_SAFETY = -1
HTTP_PORT = 11626
LOG_FILE_PATH = ""
NETWORK_PASSPHRASE = "Public Global Stellar Network ; September 2015"

[[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}"
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated file, do not edit
BUCKETLIST_DB_INDEX_PAGE_SIZE_EXPONENT = 12
BUCKETLIST_DB_MEMORY_FOR_CACHING = 0
DATABASE = "sqlite3://stellar.db"
DEPRECATED_SQL_LEDGER_STATE = false
FAILURE_SAFETY = -1
Expand Down
1 change: 1 addition & 0 deletions ingest/ledgerbackend/testdata/expected-offline-core.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated file, do not edit
BUCKETLIST_DB_INDEX_PAGE_SIZE_EXPONENT = 12
BUCKETLIST_DB_MEMORY_FOR_CACHING = 0
DATABASE = "sqlite3://stellar.db"
DEPRECATED_SQL_LEDGER_STATE = false
FAILURE_SAFETY = 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Generated file, do not edit
BUCKETLIST_DB_MEMORY_FOR_CACHING = 0
DEPRECATED_SQL_LEDGER_STATE = true
EMIT_SOROBAN_TRANSACTION_META_EXT_V1 = true
ENABLE_DIAGNOSTICS_FOR_TX_SUBMISSION = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Generated file, do not edit
BUCKETLIST_DB_MEMORY_FOR_CACHING = 0
DEPRECATED_SQL_LEDGER_STATE = true
FAILURE_SAFETY = 0
HTTP_PORT = 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Generated file, do not edit
BUCKETLIST_DB_MEMORY_FOR_CACHING = 0
DEPRECATED_SQL_LEDGER_STATE = true
FAILURE_SAFETY = 0
HTTP_PORT = 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Generated file, do not edit
BUCKETLIST_DB_MEMORY_FOR_CACHING = 0
DEPRECATED_SQL_LEDGER_STATE = true
FAILURE_SAFETY = 0
HTTP_PORT = 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Generated file, do not edit
BUCKETLIST_DB_MEMORY_FOR_CACHING = 0
DEPRECATED_SQL_LEDGER_STATE = true
FAILURE_SAFETY = 0
HTTP_PORT = 0
Expand Down
1 change: 1 addition & 0 deletions ingest/ledgerbackend/testdata/expected-online-core.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Generated file, do not edit
BUCKETLIST_DB_MEMORY_FOR_CACHING = 0
DEPRECATED_SQL_LEDGER_STATE = true
FAILURE_SAFETY = -1
HTTP_PORT = 6789
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Generated file, do not edit
BUCKETLIST_DB_MEMORY_FOR_CACHING = 0
DEPRECATED_SQL_LEDGER_STATE = true
FAILURE_SAFETY = -1
HTTP_PORT = 11626
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Generated file, do not edit
BUCKETLIST_DB_MEMORY_FOR_CACHING = 0
DEPRECATED_SQL_LEDGER_STATE = true
EMIT_SOROBAN_TRANSACTION_META_EXT_V1 = true
ENABLE_DIAGNOSTICS_FOR_TX_SUBMISSION = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Generated file, do not edit
BUCKETLIST_DB_MEMORY_FOR_CACHING = 0
DEPRECATED_SQL_LEDGER_STATE = true
FAILURE_SAFETY = -1
HTTP_PORT = 11626
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Generated file, do not edit
BUCKETLIST_DB_MEMORY_FOR_CACHING = 0
DEPRECATED_SQL_LEDGER_STATE = true
FAILURE_SAFETY = -1
HTTP_PORT = 6789
Expand Down
1 change: 1 addition & 0 deletions ingest/ledgerbackend/testdata/expected-query-params.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated file, do not edit
BUCKETLIST_DB_INDEX_PAGE_SIZE_EXPONENT = 12
BUCKETLIST_DB_MEMORY_FOR_CACHING = 0
DATABASE = "sqlite3://stellar.db"
DEPRECATED_SQL_LEDGER_STATE = false
FAILURE_SAFETY = -1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated file, do not edit
BUCKETLIST_DB_INDEX_PAGE_SIZE_EXPONENT = 12
BUCKETLIST_DB_MEMORY_FOR_CACHING = 3000
DATABASE = "sqlite3://stellar.db"
DEPRECATED_SQL_LEDGER_STATE = false
FAILURE_SAFETY = -1
HTTP_PORT = 11626
LOG_FILE_PATH = ""
NETWORK_PASSPHRASE = "Public Global Stellar Network ; September 2015"

[[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}"
70 changes: 70 additions & 0 deletions ingest/ledgerbackend/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"os"
"regexp"
"strconv"
"strings"

"github.com/stellar/go/support/errors"
Expand Down Expand Up @@ -109,6 +110,7 @@ type captiveCoreTomlValues struct {
HTTPQueryPort *uint `toml:"HTTP_QUERY_PORT,omitempty"`
QueryThreadPoolSize *uint `toml:"QUERY_THREAD_POOL_SIZE,omitempty"`
QuerySnapshotLedgers *uint `toml:"QUERY_SNAPSHOT_LEDGERS,omitempty"`
BucketListDBMemoryForCaching *uint `toml:"BUCKETLIST_DB_MEMORY_FOR_CACHING,omitempty"`
}

// QuorumSetIsConfigured returns true if there is a quorum set defined in the configuration.
Expand Down Expand Up @@ -357,6 +359,8 @@ type CaptiveCoreTomlParams struct {
EnforceSorobanTransactionMetaExtV1 bool
// Fast HTTP Query Server parameters
HTTPQueryServerParams *HTTPQueryServerParams
// CoreBuildVersionFn is a function that returns the build version of the stellar-core binary.
CoreBuildVersionFn CoreBuildVersionFunc
}

// NewCaptiveCoreTomlFromFile constructs a new CaptiveCoreToml instance by merging configuration
Expand Down Expand Up @@ -454,6 +458,61 @@ func (c *CaptiveCoreToml) CatchupToml() (*CaptiveCoreToml, error) {
return offline, nil
}

// coreVersion helper struct identify a core version and provides the
// utilities to compare the version ( i.e. minor + major pair ) to a predefined
// version.
type coreVersion struct {
major int
minor int
}

// greaterThanOrEqual compares the core version to a version specific. If unable
// to make the decision, the result is always "false", leaning toward the
// common denominator.
func (c coreVersion) greaterThanOrEqual(other coreVersion) bool {
if c.major == 0 && c.minor == 0 {
return false
}
return (c.major == other.major && c.minor >= other.minor) || (c.major > other.major)
}

func (c *CaptiveCoreToml) checkCoreVersion(params CaptiveCoreTomlParams) coreVersion {
if params.CoreBinaryPath == "" {
return coreVersion{}
}

getCoreVersion := params.CoreBuildVersionFn
if getCoreVersion == nil {
getCoreVersion = CoreBuildVersion
}

versionRaw, err := getCoreVersion(params.CoreBinaryPath)
if err != nil {
return coreVersion{}
}

var version [2]int

re := regexp.MustCompile(`\D*(\d*)\.(\d*).*`)
versionStr := re.FindStringSubmatch(versionRaw)
if err == nil && len(versionStr) == 3 {
for i := 1; i < len(versionStr); i++ {
val, err := strconv.Atoi((versionStr[i]))
if err != nil {
break
}
version[i-1] = val
}
}

return coreVersion{
major: version[0],
minor: version[1],
}
}

var minVersionForBucketlistCaching = coreVersion{major: 22, minor: 2}

func (c *CaptiveCoreToml) setDefaults(params CaptiveCoreTomlParams) {
if params.UseDB && !c.tree.Has("DATABASE") {
c.Database = "sqlite3://stellar.db"
Expand Down Expand Up @@ -521,6 +580,17 @@ func (c *CaptiveCoreToml) setDefaults(params CaptiveCoreTomlParams) {
c.QueryThreadPoolSize = &poolSize

}

if !c.tree.Has("BUCKETLIST_DB_MEMORY_FOR_CACHING") &&
c.checkCoreVersion(params).greaterThanOrEqual(minVersionForBucketlistCaching) {
// set BUCKETLIST_DB_MEMORY_FOR_CACHING to 0 to disable allocation of
// memory for caching entries in BucketListDB.
// If we do not set BUCKETLIST_DB_MEMORY_FOR_CACHING, core will apply
// the default value which may result in additional 2-3 GB of memory usage
// in captive core
var disable uint = 0
c.BucketListDBMemoryForCaching = &disable
}
}

func enforceOption(opt **bool) {
Expand Down
Loading
Loading