|
6 | 6 | "fmt" |
7 | 7 | "os" |
8 | 8 | "regexp" |
| 9 | + "strconv" |
9 | 10 | "strings" |
10 | 11 |
|
11 | 12 | "github.com/stellar/go/support/errors" |
@@ -455,6 +456,56 @@ func (c *CaptiveCoreToml) CatchupToml() (*CaptiveCoreToml, error) { |
455 | 456 | return offline, nil |
456 | 457 | } |
457 | 458 |
|
| 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 | + |
458 | 509 | func (c *CaptiveCoreToml) setDefaults(params CaptiveCoreTomlParams) { |
459 | 510 | if params.UseDB && !c.tree.Has("DATABASE") { |
460 | 511 | c.Database = "sqlite3://stellar.db" |
@@ -523,7 +574,8 @@ func (c *CaptiveCoreToml) setDefaults(params CaptiveCoreTomlParams) { |
523 | 574 |
|
524 | 575 | } |
525 | 576 |
|
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) { |
527 | 579 | // set BUCKETLIST_DB_MEMORY_FOR_CACHING to 0 to disable allocation of |
528 | 580 | // memory for caching entries in BucketListDB. |
529 | 581 | // If we do not set BUCKETLIST_DB_MEMORY_FOR_CACHING, core will apply |
|
0 commit comments