Skip to content

Commit

Permalink
Remove check for stellar classic
Browse files Browse the repository at this point in the history
  • Loading branch information
urvisavla committed Jun 17, 2024
1 parent 3a31ed7 commit fc2844f
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 172 deletions.
107 changes: 4 additions & 103 deletions ingest/ledgerbackend/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import (
_ "embed"
"fmt"
"os"
"os/exec"
"regexp"
"strconv"
"strings"

"github.com/stellar/go/support/errors"
Expand Down Expand Up @@ -346,8 +344,6 @@ type CaptiveCoreTomlParams struct {
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 @@ -445,104 +441,13 @@ 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
ledgerProtocolVersion int
}

// IsEqualOrAbove 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) IsEqualOrAbove(major, minor int) bool {
if c.major == 0 && c.minor == 0 {
return false
}
return (c.major == major && c.minor >= minor) || (c.major > major)
}

// IsEqualOrAbove 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) IsProtocolVersionEqualOrAbove(protocolVer int) bool {
if c.ledgerProtocolVersion == 0 {
return false
}
return c.ledgerProtocolVersion >= protocolVer
}

func checkCoreVersion(coreBinaryPath string) coreVersion {
if coreBinaryPath == "" {
return coreVersion{}
}

versionBytes, err := exec.Command(coreBinaryPath, "version").Output()
if err != nil {
return coreVersion{}
}

// starting soroban, we want to use only the first row for the version.
versionRows := strings.Split(string(versionBytes), "\n")
versionRaw := versionRows[0]

var version [2]int

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

re = regexp.MustCompile(`^\s*ledger protocol version: (\d*)`)
var ledgerProtocol int
var ledgerProtocolStrings []string
for _, line := range versionRows {
ledgerProtocolStrings = re.FindStringSubmatch(line)
if len(ledgerProtocolStrings) > 0 {
break
}
}
if len(ledgerProtocolStrings) == 2 {
if val, err := strconv.Atoi(ledgerProtocolStrings[1]); err == nil {
ledgerProtocol = val
}
}

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

const MinimalBucketListDBCoreSupportVersionMajor = 19
const MinimalBucketListDBCoreSupportVersionMinor = 6
const MinimalSorobanProtocolSupport = 20

func (c *CaptiveCoreToml) setDefaults(params CaptiveCoreTomlParams) {
if params.UseDB && !c.tree.Has("DATABASE") {
c.Database = "sqlite3://stellar.db"
}

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 currentCoreVersion.IsEqualOrAbove(MinimalBucketListDBCoreSupportVersionMajor, MinimalBucketListDBCoreSupportVersionMinor) {
c.UseBucketListDB = true
}
c.UseBucketListDB = true
}

if c.UseBucketListDB && !c.tree.Has("EXPERIMENTAL_BUCKETLIST_DB_INDEX_PAGE_SIZE_EXPONENT") {
Expand Down Expand Up @@ -584,14 +489,10 @@ func (c *CaptiveCoreToml) setDefaults(params CaptiveCoreTomlParams) {
}

if params.EnforceSorobanDiagnosticEvents {
if currentCoreVersion.IsEqualOrAbove(20, 0) {
enforceOption(&c.EnableSorobanDiagnosticEvents)
}
if currentCoreVersion.IsEqualOrAbove(20, 1) {
enforceOption(&c.EnableDiagnosticsForTxSubmission)
}
enforceOption(&c.EnableSorobanDiagnosticEvents)
enforceOption(&c.EnableDiagnosticsForTxSubmission)
}
if params.EnforceSorobanTransactionMetaExtV1 && currentCoreVersion.IsEqualOrAbove(20, 4) {
if params.EnforceSorobanTransactionMetaExtV1 {
enforceOption(&c.EnableEmitSorobanTransactionMetaExtV1)
}
}
Expand Down
17 changes: 0 additions & 17 deletions ingest/ledgerbackend/toml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,6 @@ func TestGenerateConfig(t *testing.T) {
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 Down Expand Up @@ -497,13 +490,3 @@ func TestNonDBConfigDoesNotUpdateDatabase(t *testing.T) {
require.NoError(t, toml.unmarshal(configBytes, true))
assert.Equal(t, toml.Database, "")
}

func TestCheckCoreVersion(t *testing.T) {
coreBin := os.Getenv("HORIZON_INTEGRATION_TESTS_CAPTIVE_CORE_BIN")
if coreBin == "" {
t.SkipNow()
return
}
version := checkCoreVersion(coreBin)
require.True(t, version.IsEqualOrAbove(20, 0))
}
15 changes: 0 additions & 15 deletions services/horizon/docker/captive-core-classic-integration-tests.cfg

This file was deleted.

This file was deleted.

4 changes: 2 additions & 2 deletions services/horizon/internal/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func TestEnvironmentVariables(t *testing.T) {
assert.Equal(t, config.AdminPort, uint(6060))
assert.Equal(t, config.Port, uint(8001))
assert.Equal(t, config.CaptiveCoreBinaryPath, os.Getenv("HORIZON_INTEGRATION_TESTS_CAPTIVE_CORE_BIN"))
assert.Equal(t, config.CaptiveCoreConfigPath, "../docker/captive-core-classic-integration-tests.cfg")
assert.Equal(t, config.CaptiveCoreConfigPath, "../docker/captive-core-integration-tests.cfg")
assert.Equal(t, config.CaptiveCoreConfigUseDB, true)
}

Expand All @@ -324,7 +324,7 @@ func horizonEnvVars() map[string]string {
"ADMIN_PORT": "6060",
"PORT": "8001",
"CAPTIVE_CORE_BINARY_PATH": os.Getenv("HORIZON_INTEGRATION_TESTS_CAPTIVE_CORE_BIN"),
"CAPTIVE_CORE_CONFIG_PATH": "../docker/captive-core-classic-integration-tests.cfg",
"CAPTIVE_CORE_CONFIG_PATH": "../docker/captive-core-integration-tests.cfg",
"CAPTIVE_CORE_USE_DB": "true",
}
}
Expand Down
13 changes: 2 additions & 11 deletions services/horizon/internal/integration/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

"github.com/stellar/go/clients/horizonclient"
"github.com/stellar/go/historyarchive"
"github.com/stellar/go/ingest/ledgerbackend"
"github.com/stellar/go/keypair"
hProtocol "github.com/stellar/go/protocols/horizon"
horizoncmd "github.com/stellar/go/services/horizon/cmd"
Expand Down Expand Up @@ -535,7 +534,7 @@ func TestReingestDB(t *testing.T) {

horizonConfig.CaptiveCoreConfigPath = filepath.Join(
filepath.Dir(horizonConfig.CaptiveCoreConfigPath),
getCoreConfigFile(itest),
"captive-core-reingest-range-integration-tests.cfg",
)

horizoncmd.RootCmd.SetArgs(command(t, horizonConfig, "db",
Expand Down Expand Up @@ -703,14 +702,6 @@ func TestReingestDBWithFilterRules(t *testing.T) {
}, 30*time.Second, time.Second)
}

func getCoreConfigFile(itest *integration.Test) string {
coreConfigFile := "captive-core-reingest-range-classic-integration-tests.cfg"
if itest.Config().ProtocolVersion >= ledgerbackend.MinimalSorobanProtocolSupport {
coreConfigFile = "captive-core-reingest-range-integration-tests.cfg"
}
return coreConfigFile
}

func command(t *testing.T, horizonConfig horizon.Config, args ...string) []string {
return append([]string{
"--stellar-core-url",
Expand Down Expand Up @@ -848,7 +839,7 @@ func TestFillGaps(t *testing.T) {

horizonConfig.CaptiveCoreConfigPath = filepath.Join(
filepath.Dir(horizonConfig.CaptiveCoreConfigPath),
getCoreConfigFile(itest),
"captive-core-reingest-range-integration-tests.cfg",
)
horizoncmd.RootCmd.SetArgs(command(t, horizonConfig, "db", "fill-gaps", "--parallel-workers=1"))
tt.NoError(horizoncmd.RootCmd.Execute())
Expand Down
14 changes: 1 addition & 13 deletions services/horizon/internal/test/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (

sdk "github.com/stellar/go/clients/horizonclient"
"github.com/stellar/go/clients/stellarcore"
"github.com/stellar/go/ingest/ledgerbackend"
"github.com/stellar/go/keypair"
proto "github.com/stellar/go/protocols/horizon"
horizon "github.com/stellar/go/services/horizon/internal"
Expand Down Expand Up @@ -184,11 +183,7 @@ func NewTest(t *testing.T, config Config) *Test {
func (i *Test) configureCaptiveCore() {
composePath := findDockerComposePath()
i.coreConfig.binaryPath = os.Getenv("HORIZON_INTEGRATION_TESTS_CAPTIVE_CORE_BIN")
coreConfigFile := "captive-core-classic-integration-tests.cfg"
if i.config.ProtocolVersion >= ledgerbackend.MinimalSorobanProtocolSupport {
coreConfigFile = "captive-core-integration-tests.cfg"
}
i.coreConfig.configPath = filepath.Join(composePath, coreConfigFile)
i.coreConfig.configPath = filepath.Join(composePath, "captive-core-integration-tests.cfg")
i.coreConfig.storagePath = i.CurrentTest().TempDir()
i.coreConfig.useDB = true

Expand Down Expand Up @@ -254,13 +249,6 @@ func (i *Test) runComposeCommand(args ...string) {
)
}

if i.config.ProtocolVersion < ledgerbackend.MinimalSorobanProtocolSupport {
cmd.Env = append(
cmd.Environ(),
"CORE_CONFIG_FILE=stellar-core-classic-integration-tests.cfg",
)
}

i.t.Log("Running", cmd.Args)
out, innerErr := cmd.Output()
if len(out) > 0 {
Expand Down

0 comments on commit fc2844f

Please sign in to comment.