Skip to content

Commit 85d5e31

Browse files
committed
wip
1 parent 5ca4423 commit 85d5e31

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

ingest/ledgerbackend/toml.go

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"os"
88
"regexp"
9+
"strconv"
910
"strings"
1011

1112
"github.com/stellar/go/support/errors"
@@ -455,6 +456,56 @@ func (c *CaptiveCoreToml) CatchupToml() (*CaptiveCoreToml, error) {
455456
return offline, nil
456457
}
457458

459+
// coreVersion helper struct identify a core version and provides the
460+
// utilities to compare the version ( i.e. minor + major pair ) to a predefined
461+
// version.
462+
type coreVersion struct {
463+
major int
464+
minor int
465+
}
466+
467+
// greaterThanOrEqual compares the core version to a version specific. If unable
468+
// to make the decision, the result is always "false", leaning toward the
469+
// common denominator.
470+
func (c coreVersion) greaterThanOrEqual(other coreVersion) bool {
471+
if c.major == 0 && c.minor == 0 {
472+
return false
473+
}
474+
return (c.major == other.major && c.minor >= other.minor) || (c.major > other.minor)
475+
}
476+
477+
func (c *CaptiveCoreToml) checkCoreVersion(coreBinaryPath string) coreVersion {
478+
if coreBinaryPath == "" {
479+
return coreVersion{}
480+
}
481+
482+
versionRaw, err := CoreBuildVersion(coreBinaryPath)
483+
if err != nil {
484+
return coreVersion{}
485+
}
486+
487+
var version [2]int
488+
489+
re := regexp.MustCompile(`\D*(\d*)\.(\d*).*`)
490+
versionStr := re.FindStringSubmatch(versionRaw)
491+
if err == nil && len(versionStr) == 3 {
492+
for i := 1; i < len(versionStr); i++ {
493+
val, err := strconv.Atoi((versionStr[i]))
494+
if err != nil {
495+
break
496+
}
497+
version[i-1] = val
498+
}
499+
}
500+
501+
return coreVersion{
502+
major: version[0],
503+
minor: version[1],
504+
}
505+
}
506+
507+
var minVersionForBucketlistCaching = coreVersion{major: 22, minor: 2}
508+
458509
func (c *CaptiveCoreToml) setDefaults(params CaptiveCoreTomlParams) {
459510
if params.UseDB && !c.tree.Has("DATABASE") {
460511
c.Database = "sqlite3://stellar.db"
@@ -523,7 +574,8 @@ func (c *CaptiveCoreToml) setDefaults(params CaptiveCoreTomlParams) {
523574

524575
}
525576

526-
if !c.tree.Has("BUCKETLIST_DB_MEMORY_FOR_CACHING") {
577+
if !c.tree.Has("BUCKETLIST_DB_MEMORY_FOR_CACHING") &&
578+
c.checkCoreVersion(params.CoreBinaryPath).greaterThanOrEqual(minVersionForBucketlistCaching) {
527579
// set BUCKETLIST_DB_MEMORY_FOR_CACHING to 0 to disable allocation of
528580
// memory for caching entries in BucketListDB.
529581
// If we do not set BUCKETLIST_DB_MEMORY_FOR_CACHING, core will apply

0 commit comments

Comments
 (0)