Skip to content

Commit

Permalink
Use new ledgerbackend changes
Browse files Browse the repository at this point in the history
  • Loading branch information
chowbao committed Apr 22, 2024
1 parent 29f8147 commit dd99736
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.17.0
github.com/stellar/go v0.0.0-20240419044405-2d7308b67c07
github.com/stellar/go v0.0.0-20240419222646-3a79646669ab
github.com/stretchr/testify v1.9.0
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ github.com/spf13/viper v1.17.0 h1:I5txKw7MJasPL/BrfkbA0Jyo/oELqVmux4pR/UxOMfI=
github.com/spf13/viper v1.17.0/go.mod h1:BmMMMLQXSbcHK6KAOiFLz0l5JHrU89OdIRHvsk0+yVI=
github.com/stellar/go v0.0.0-20240419044405-2d7308b67c07 h1:AgxlbRmsFAc9VaOLj29K9RpsSmlmtJ0KCVnGxV7bUwo=
github.com/stellar/go v0.0.0-20240419044405-2d7308b67c07/go.mod h1:ckzsX0B0qfTMVZQJtPELJLs7cJ6xXMYHPVLyIsReGsU=
github.com/stellar/go v0.0.0-20240419222646-3a79646669ab h1:+uTCn/DrOc1cXugQ8PKZPAkZS3KWeHk5f2aKk9jdrDs=
github.com/stellar/go v0.0.0-20240419222646-3a79646669ab/go.mod h1:ckzsX0B0qfTMVZQJtPELJLs7cJ6xXMYHPVLyIsReGsU=
github.com/stellar/go-xdr v0.0.0-20231122183749-b53fb00bcac2 h1:OzCVd0SV5qE3ZcDeSFCmOWLZfEWZ3Oe8KtmSOYKEVWE=
github.com/stellar/go-xdr v0.0.0-20231122183749-b53fb00bcac2/go.mod h1:yoxyU/M8nl9LKeWIoBrbDPQ7Cy+4jxRcWcOayZ4BMps=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
29 changes: 24 additions & 5 deletions internal/utils/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"math/big"
"net/url"
"time"

"github.com/spf13/pflag"
Expand Down Expand Up @@ -657,16 +658,15 @@ func GetEnvironmentDetails(isTest bool, isFuture bool, datastoreUrl string) (det
details.NetworkPassphrase = network.TestNetworkPassphrase
details.ArchiveURLs = testArchiveURLs
details.BinaryPath = "/usr/bin/stellar-core"
details.CoreConfig = "/etl/docker/stellar-core_testnet.cfg"
// TODO: change exporter-test to the real bucket whatever that is
details.CoreConfig = "/etl/docker/stellar-core_testnet.cfg"
details.StorageURL = datastoreUrl
return details
} else if isFuture {
// details.NetworkPassphrase = network.FutureNetworkPassphrase
details.NetworkPassphrase = "Test SDF Future Network ; October 2022"
details.ArchiveURLs = futureArchiveURLs
details.BinaryPath = "/usr/bin/stellar-core"
details.CoreConfig = "/etl/docker/stellar-core_futurenet.cfg"
details.CoreConfig = "/etl/docker/stellar-core_futurenet.cfg"
details.StorageURL = datastoreUrl
return details
} else {
Expand Down Expand Up @@ -747,6 +747,7 @@ func LedgerEntryToLedgerKeyHash(ledgerEntry xdr.LedgerEntry) string {
// CreateLedgerBackend creates a ledger backend using captive core or datastore
// Defaults to using datastore
func CreateLedgerBackend(ctx context.Context, useCaptiveCore bool, env EnvironmentDetails) (ledgerbackend.LedgerBackend, error) {
// Create ledger backend from captive core
if useCaptiveCore {
backend, err := env.CreateCaptiveCoreBackend()
if err != nil {
Expand All @@ -755,11 +756,29 @@ func CreateLedgerBackend(ctx context.Context, useCaptiveCore bool, env Environme
return backend, nil
}

backend, err := ledgerbackend.NewCloudStorageBackend(ctx, env.StorageURL)
// Create ledger backend from datastore
fileConfig := ledgerbackend.LCMFileConfig{
StorageURL: env.StorageURL,
FileSuffix: ".xdr.gz",
LedgersPerFile: 1,
FilesPerPartition: 64000,
}

parsed, err := url.Parse(env.StorageURL)
if err != nil {
return nil, err
}
return backend, nil

// Using the GCS datastore backend
if parsed.Scheme == "gcs" {
backend, err := ledgerbackend.NewGCSBackend(ctx, fileConfig)
if err != nil {
return nil, err
}
return backend, nil
}

return nil, errors.New("no valid ledgerbackend selected")
}

func LedgerKeyToLedgerKeyHash(ledgerKey xdr.LedgerKey) string {
Expand Down

0 comments on commit dd99736

Please sign in to comment.