Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/go_modules/go_modules-8c406a6806
Browse files Browse the repository at this point in the history
  • Loading branch information
tamirms authored Dec 20, 2024
2 parents 4ad1e16 + 981158a commit 352c4c2
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/galexie-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
# this is the multi-arch index sha, get it by 'docker buildx imagetools inspect stellar/quickstart:testing'
GALEXIE_INTEGRATION_TESTS_QUICKSTART_IMAGE: docker.io/stellar/quickstart:testing@sha256:5333ec87069efd7bb61f6654a801dc093bf0aad91f43a5ba84806d3efe4a6322
GALEXIE_INTEGRATION_TESTS_QUICKSTART_IMAGE_PULL: "false"
STELLAR_CORE_VERSION: 22.0.0-2138.721fd0a65.focal
STELLAR_CORE_VERSION: 22.1.0-2194.0241e79f7.focal
steps:
- name: Set VERSION
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/galexie.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
name: Test
runs-on: ubuntu-latest
env:
CAPTIVE_CORE_DEBIAN_PKG_VERSION: 22.0.0-2138.721fd0a65.focal
CAPTIVE_CORE_DEBIAN_PKG_VERSION: 22.1.0-2194.0241e79f7.focal
GALEXIE_INTEGRATION_TESTS_ENABLED: "true"
GALEXIE_INTEGRATION_TESTS_CAPTIVE_CORE_BIN: /usr/bin/stellar-core
# this pins to a version of quickstart:testing that has the same version as GALEXIE_INTEGRATION_TESTS_CAPTIVE_CORE_BIN
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/horizon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ jobs:
PROTOCOL_21_CORE_DEBIAN_PKG_VERSION: 21.3.1-2007.4ede19620.focal
PROTOCOL_21_CORE_DOCKER_IMG: stellar/stellar-core:21.3.1-2007.4ede19620.focal
PROTOCOL_21_SOROBAN_RPC_DOCKER_IMG: stellar/soroban-rpc:21.5.1
PROTOCOL_22_CORE_DEBIAN_PKG_VERSION: 22.0.0-2138.721fd0a65.focal
PROTOCOL_22_CORE_DOCKER_IMG: stellar/stellar-core:22.0.0-2138.721fd0a65.focal
PROTOCOL_22_CORE_DEBIAN_PKG_VERSION: 22.1.0-2194.0241e79f7.focal
PROTOCOL_22_CORE_DOCKER_IMG: stellar/stellar-core:22.1.0-2194.0241e79f7.focal
PROTOCOL_22_SOROBAN_RPC_DOCKER_IMG: stellar/soroban-rpc:22.0.0-rc3-101
PGHOST: localhost
PGPORT: 5432
Expand Down Expand Up @@ -126,7 +126,7 @@ jobs:
name: Test (and push) verify-range image
runs-on: ubuntu-22.04
env:
STELLAR_CORE_VERSION: 21.3.1-2007.4ede19620.focal
STELLAR_CORE_VERSION: 22.1.0-2194.0241e79f7.focal
CAPTIVE_CORE_STORAGE_PATH: /tmp
steps:
- uses: actions/checkout@v3
Expand Down
100 changes: 97 additions & 3 deletions clients/stellarcore/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import (
"io"
"net/http"
"net/url"
"os/exec"
"path"
"strconv"
"strings"
"time"

"github.com/stellar/go/keypair"
proto "github.com/stellar/go/protocols/stellarcore"
"github.com/stellar/go/support/errors"
"github.com/stellar/go/xdr"
Expand Down Expand Up @@ -56,12 +58,104 @@ func drainReponse(hresp *http.Response, close bool, err *error) (outerror error)
}

// Upgrade upgrades the protocol version running on the stellar core instance
//
// Deprecated: use UpgradeProtocol instead
func (c *Client) Upgrade(ctx context.Context, version int) (err error) {
return c.UpgradeProtocol(ctx, version, time.Unix(int64(0), 0))
}

// UpgradeProtocol upgrades the protocol version running on the stellar core instance
func (c *Client) UpgradeProtocol(ctx context.Context, protocolVersion int, at time.Time) (err error) {
queryParams := url.Values{}
queryParams.Add("protocolversion", strconv.Itoa(protocolVersion))
return c.setUpgradesAt(ctx, at, queryParams)
}

// UpgradeSorobanConfig upgrades the Soroban configuration to that indicated by the supplied ConfigUpgradeSetKey at the specified time
func (c *Client) UpgradeSorobanConfig(ctx context.Context, configKey xdr.ConfigUpgradeSetKey, at time.Time) error {
keyB64, err := xdr.MarshalBase64(configKey)
if err != nil {
return err
}
queryParams := url.Values{}
queryParams.Add("configupgradesetkey", keyB64)
return c.setUpgradesAt(ctx, at, queryParams)
}

type GenSorobanConfig struct {
BaseSeqNum uint32
NetworkPassphrase string
SigningKey *keypair.Full
// looks for `stellar-core` in the system PATH if empty
StellarCorePath string
}

func GenSorobanConfigUpgradeTxAndKey(
config GenSorobanConfig, upgradeConfig xdr.ConfigUpgradeSet) ([]xdr.TransactionEnvelope, xdr.ConfigUpgradeSetKey, error) {
upgradeConfigB64, err := xdr.MarshalBase64(upgradeConfig)
if err != nil {
return nil, xdr.ConfigUpgradeSetKey{}, err
}
corePath := config.StellarCorePath
if corePath == "" {
corePath = "stellar-core"
}
cmd := exec.Command(corePath, "get-settings-upgrade-txs",
config.SigningKey.Address(),
strconv.FormatUint(uint64(config.BaseSeqNum), 10),
config.NetworkPassphrase,
"--xdr", upgradeConfigB64,
"--signtxs")
inputStr := config.SigningKey.Seed()
cmd.Stdin = strings.NewReader(inputStr)
out, err := cmd.Output()
if err != nil {
return nil, xdr.ConfigUpgradeSetKey{}, err
}
lines := strings.Split(string(out), "\n")
if len(lines) < 9 {
return nil, xdr.ConfigUpgradeSetKey{}, fmt.Errorf("get-settings-upgrade-txs: unexpected output: %q", string(out))
}
txsB64 := []string{lines[0], lines[2], lines[4], lines[6]}
keyB64 := lines[8]

txs := make([]xdr.TransactionEnvelope, len(txsB64))
for i, txB64 := range txsB64 {
err = xdr.SafeUnmarshalBase64(txB64, &txs[i])
if err != nil {
return nil, xdr.ConfigUpgradeSetKey{}, err
}
}
var key xdr.ConfigUpgradeSetKey
err = xdr.SafeUnmarshalBase64(keyB64, &key)
return txs, key, err
}

// UpgradeTxSetSize upgrades the maximum number of transactions per ledger
func (c *Client) UpgradeTxSetSize(ctx context.Context, maxTxSetSize uint32, at time.Time) error {
queryParams := url.Values{}
queryParams.Add("mode", "set")
queryParams.Add("upgradetime", "1970-01-01T00:00:00Z")
queryParams.Add("protocolversion", strconv.Itoa(version))
queryParams.Add("maxtxsetsize", strconv.FormatUint(uint64(maxTxSetSize), 10))
return c.setUpgradesAt(ctx, at, queryParams)
}

// UpgradeSorobanTxSetSize upgrades the maximum number of transactions per ledger
func (c *Client) UpgradeSorobanTxSetSize(ctx context.Context, maxTxSetSize uint32, at time.Time) error {
queryParams := url.Values{}
queryParams.Add("maxsorobantxsetsize", strconv.FormatUint(uint64(maxTxSetSize), 10))
return c.setUpgradesAt(ctx, at, queryParams)
}

func (c *Client) setUpgradesAt(ctx context.Context, at time.Time, extraQueryParams url.Values) (err error) {
finalQueryParams := url.Values{}
for k, v := range extraQueryParams {
finalQueryParams[k] = v
}
finalQueryParams.Add("mode", "set")
finalQueryParams.Add("upgradetime", at.Format("2006-01-02T15:04:05Z"))
return c.upgrades(ctx, finalQueryParams)
}

func (c *Client) upgrades(ctx context.Context, queryParams url.Values) (err error) {
var req *http.Request
req, err = c.simpleGet(ctx, "upgrades", queryParams)
if err != nil {
Expand Down
39 changes: 39 additions & 0 deletions clients/stellarcore/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import (
"io"
"net/http"
"net/url"
"os"
"os/exec"
"testing"

"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/stellar/go/keypair"
"github.com/stellar/go/network"
proto "github.com/stellar/go/protocols/stellarcore"
"github.com/stellar/go/support/http/httptest"
"github.com/stellar/go/xdr"
Expand Down Expand Up @@ -135,3 +138,39 @@ func TestGetLedgerEntries(t *testing.T) {
require.Equal(t, "pretend this is XDR lol", resp.Entries[0].Entry)
require.Equal(t, "pretend this is another XDR lol", resp.Entries[1].Entry)
}

func TestGenSorobanConfigUpgradeTxAndKey(t *testing.T) {
coreBinary := os.Getenv("STELLAR_CORE_BINARY_PATH")
if coreBinary == "" {
var err error
coreBinary, err = exec.LookPath("stellar-core")
if err != nil {
t.Skip("couldn't find stellar core binary")
}
}
key, err := keypair.ParseFull("SB6VZS57IY25334Y6F6SPGFUNESWS7D2OSJHKDPIZ354BK3FN5GBTS6V")
require.NoError(t, err)
funcConfig := GenSorobanConfig{
BaseSeqNum: 1,
NetworkPassphrase: network.TestNetworkPassphrase,
SigningKey: key,
StellarCorePath: coreBinary,
}
config := xdr.ConfigUpgradeSet{
UpdatedEntry: []xdr.ConfigSettingEntry{
{
ConfigSettingId: xdr.ConfigSettingIdConfigSettingContractComputeV0,
ContractCompute: &xdr.ConfigSettingContractComputeV0{
LedgerMaxInstructions: 1000,
TxMaxInstructions: 100,
FeeRatePerInstructionsIncrement: 1000,
TxMemoryLimit: 10,
},
},
},
}

txs, _, err := GenSorobanConfigUpgradeTxAndKey(funcConfig, config)
require.NoError(t, err)
require.Len(t, txs, 4)
}

0 comments on commit 352c4c2

Please sign in to comment.