From 1d793a3fdd6ca15ab181dc93a8532b553eba9768 Mon Sep 17 00:00:00 2001 From: Leigh <351529+leighmcculloch@users.noreply.github.com> Date: Tue, 17 Feb 2026 23:37:50 +1100 Subject: [PATCH 1/2] bump go-stellar-sdk and golang.org/x deps --- go.mod | 12 ++++++------ go.sum | 28 ++++++++++++++-------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/go.mod b/go.mod index 1e45d072..551f2ad4 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/sirupsen/logrus v1.9.3 github.com/spf13/cobra v1.7.0 github.com/spf13/pflag v1.0.5 - github.com/stellar/go-stellar-sdk v0.0.0-20251208182759-7568ee53f4fd + github.com/stellar/go-stellar-sdk v0.0.0-20260211033645-9b3fcf4e75b1 github.com/stretchr/testify v1.11.1 ) @@ -129,14 +129,14 @@ require ( go.opentelemetry.io/otel/metric v1.38.0 // indirect go.opentelemetry.io/otel/trace v1.38.0 // indirect go.uber.org/multierr v1.11.0 // indirect - golang.org/x/crypto v0.43.0 // indirect + golang.org/x/crypto v0.45.0 // indirect golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 // indirect golang.org/x/mod v0.29.0 - golang.org/x/net v0.46.0 // indirect + golang.org/x/net v0.47.0 // indirect golang.org/x/oauth2 v0.32.0 // indirect - golang.org/x/sync v0.17.0 // indirect - golang.org/x/sys v0.37.0 // indirect - golang.org/x/text v0.30.0 // indirect + golang.org/x/sync v0.18.0 // indirect + golang.org/x/sys v0.38.0 // indirect + golang.org/x/text v0.31.0 // indirect golang.org/x/time v0.14.0 // indirect google.golang.org/api v0.254.0 // indirect google.golang.org/genproto v0.0.0-20251029180050-ab9386a59fda // indirect diff --git a/go.sum b/go.sum index 4162620f..563cee84 100644 --- a/go.sum +++ b/go.sum @@ -429,8 +429,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/spiffe/go-spiffe/v2 v2.6.0 h1:l+DolpxNWYgruGQVV0xsfeya3CsC7m8iBzDnMpsbLuo= github.com/spiffe/go-spiffe/v2 v2.6.0/go.mod h1:gm2SeUoMZEtpnzPNs2Csc0D/gX33k1xIx7lEzqblHEs= -github.com/stellar/go-stellar-sdk v0.0.0-20251208182759-7568ee53f4fd h1:90j0mtcO8J6v2v/EVgvyfK+L1WlLW9Fg2Vn4/zAv/0Q= -github.com/stellar/go-stellar-sdk v0.0.0-20251208182759-7568ee53f4fd/go.mod h1:fZPcxQZw1I0zZ+X76uFcVPqmQCaYbWc87lDFW/kQJaY= +github.com/stellar/go-stellar-sdk v0.0.0-20260211033645-9b3fcf4e75b1 h1:5gLvjIM/y0LaukrO4WRUfZK0Sa2HZxAoX4TCSE7Ujyk= +github.com/stellar/go-stellar-sdk v0.0.0-20260211033645-9b3fcf4e75b1/go.mod h1:4osSHRDfb/D7zE2iNjmPdg2Gmbx0M/JLhTM4YcwPW5s= 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= @@ -515,8 +515,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.43.0 h1:dduJYIi3A3KOfdGOHX8AVZ/jGiyPa3IbBozJ5kNuE04= -golang.org/x/crypto v0.43.0/go.mod h1:BFbav4mRNlXJL4wNeejLpWxB7wMbc79PdRGhWKncxR0= +golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q= +golang.org/x/crypto v0.45.0/go.mod h1:XTGrrkGJve7CYK7J8PEww4aY7gM3qMCElcJQ8n8JdX4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -587,8 +587,8 @@ golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.46.0 h1:giFlY12I07fugqwPuWJi68oOnpfqFnJIJzaIIm2JVV4= -golang.org/x/net v0.46.0/go.mod h1:Q9BGdFy1y4nkUwiLvT5qtyhAnEHgnQ/zd8PfU6nc210= +golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY= +golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -610,8 +610,8 @@ golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug= -golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= +golang.org/x/sync v0.18.0 h1:kr88TuHDroi+UVf+0hZnirlk8o8T+4MrK6mr60WkH/I= +golang.org/x/sync v0.18.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -650,11 +650,11 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ= -golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= +golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc= +golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.36.0 h1:zMPR+aF8gfksFprF/Nc/rd1wRS1EI6nDBGyWAvDzx2Q= -golang.org/x/term v0.36.0/go.mod h1:Qu394IJq6V6dCBRgwqshf3mPF85AqzYEzofzRdZkWss= +golang.org/x/term v0.37.0 h1:8EGAD0qCmHYZg6J17DvsMy9/wJ7/D/4pV/wfnld5lTU= +golang.org/x/term v0.37.0/go.mod h1:5pB4lxRNYYVZuTLmy8oR2BH8dflOR+IbTYFD8fi3254= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -663,8 +663,8 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k= -golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM= +golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM= +golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= From 3654611dc18909ee3d56e5829fb14d266abca6ef Mon Sep 17 00:00:00 2001 From: Leigh <351529+leighmcculloch@users.noreply.github.com> Date: Wed, 18 Feb 2026 00:04:14 +1100 Subject: [PATCH 2/2] add XDR build tag gating for new xdr types --- .github/workflows/golang.yml | 8 ++++ .github/workflows/stellar-rpc.yml | 11 +++++- Makefile | 23 +++++++---- .../internal/feewindow/feewindow.go | 30 ++++---------- .../feewindow/feewindow_no_xdr_hello_world.go | 18 +++++++++ .../feewindow_no_xdr_transaction_meta_v5.go | 22 +++++++++++ .../feewindow/feewindow_xdr_hello_world.go | 22 +++++++++++ .../feewindow_xdr_transaction_meta_v5.go | 27 +++++++++++++ .../integrationtest/get_fee_stats_test.go | 10 +---- ...helpers_no_xdr_transaction_meta_v5_test.go | 35 +++++++++++++++++ ...ta_helpers_xdr_transaction_meta_v5_test.go | 39 +++++++++++++++++++ .../integrationtest/transaction_test.go | 10 +---- .../internal/methods/simulate_transaction.go | 22 ++++++----- ...simulate_transaction_no_xdr_hello_world.go | 18 +++++++++ .../simulate_transaction_xdr_hello_world.go | 22 +++++++++++ .../internal/preflight/preflight.go | 6 ++- .../preflight/preflight_no_xdr_hello_world.go | 18 +++++++++ .../preflight/preflight_xdr_hello_world.go | 22 +++++++++++ go.mod | 2 +- go.sum | 4 +- 20 files changed, 306 insertions(+), 63 deletions(-) create mode 100644 cmd/stellar-rpc/internal/feewindow/feewindow_no_xdr_hello_world.go create mode 100644 cmd/stellar-rpc/internal/feewindow/feewindow_no_xdr_transaction_meta_v5.go create mode 100644 cmd/stellar-rpc/internal/feewindow/feewindow_xdr_hello_world.go create mode 100644 cmd/stellar-rpc/internal/feewindow/feewindow_xdr_transaction_meta_v5.go create mode 100644 cmd/stellar-rpc/internal/integrationtest/meta_helpers_no_xdr_transaction_meta_v5_test.go create mode 100644 cmd/stellar-rpc/internal/integrationtest/meta_helpers_xdr_transaction_meta_v5_test.go create mode 100644 cmd/stellar-rpc/internal/methods/simulate_transaction_no_xdr_hello_world.go create mode 100644 cmd/stellar-rpc/internal/methods/simulate_transaction_xdr_hello_world.go create mode 100644 cmd/stellar-rpc/internal/preflight/preflight_no_xdr_hello_world.go create mode 100644 cmd/stellar-rpc/internal/preflight/preflight_xdr_hello_world.go diff --git a/.github/workflows/golang.yml b/.github/workflows/golang.yml index e0fba29c..3a46853b 100644 --- a/.github/workflows/golang.yml +++ b/.github/workflows/golang.yml @@ -38,3 +38,11 @@ jobs: version: v2.1.6 # this is the golangci-lint version github-token: ${{ secrets.GITHUB_TOKEN }} only-new-issues: true + + - name: Run golangci-lint with XDR build tags + uses: golangci/golangci-lint-action@v7 + with: + version: v2.1.6 + github-token: ${{ secrets.GITHUB_TOKEN }} + only-new-issues: true + args: --build-tags xdr_hello_world,xdr_ledger_entry_ext_v2,xdr_transaction_meta_v5 diff --git a/.github/workflows/stellar-rpc.yml b/.github/workflows/stellar-rpc.yml index c368925e..f3206364 100644 --- a/.github/workflows/stellar-rpc.yml +++ b/.github/workflows/stellar-rpc.yml @@ -15,10 +15,11 @@ concurrency: jobs: test: - name: Unit tests + name: Unit tests${{ matrix.go_build_tags && ' (xdr tags)' || '' }} strategy: matrix: os: [ ubuntu-22.04 ] + go_build_tags: [ '', 'xdr_hello_world,xdr_ledger_entry_ext_v2,xdr_transaction_meta_v5' ] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 @@ -32,7 +33,7 @@ jobs: - run: rustup update - uses: stellar/actions/rust-cache@main - run: make build-libs - - run: go test -race -timeout 25m ./cmd/stellar-rpc/... + - run: go test -race -timeout 25m ${{ matrix.go_build_tags && format('-tags {0}', matrix.go_build_tags) || '' }} ./cmd/stellar-rpc/... build: name: Build @@ -84,6 +85,12 @@ jobs: CGO_ENABLED: 1 GOARCH: ${{ matrix.go_arch }} + - name: Verify build with XDR build tags + run: go vet -tags xdr_hello_world,xdr_ledger_entry_ext_v2,xdr_transaction_meta_v5 ./cmd/stellar-rpc/... + env: + CGO_ENABLED: 1 + GOARCH: ${{ matrix.go_arch }} + integration: name: Integration tests continue-on-error: true diff --git a/Makefile b/Makefile index aa00f9fe..7a4919bf 100644 --- a/Makefile +++ b/Makefile @@ -59,16 +59,25 @@ CARGO_BUILD_TARGET ?= $(shell rustc -vV | sed -n 's|host: ||p') STELLAR_RPC_BINARY := stellar-rpc +# XDR build tags for enabling gated XDR types from go-stellar-sdk. +# Set GO_BUILD_TAGS to a comma-separated list of tags, or use +# "make GO_BUILD_TAGS=$(XDR_BUILD_TAGS_ALL) build" to enable all. +XDR_BUILD_TAGS_ALL := xdr_hello_world,xdr_ledger_entry_ext_v2,xdr_transaction_meta_v5 +GO_BUILD_TAGS ?= +ifneq ($(strip $(GO_BUILD_TAGS)),) + GOTAGS := -tags $(GO_BUILD_TAGS) + GOLANGCI_LINT_TAGS := --build-tags $(GO_BUILD_TAGS) +endif # update the Cargo.lock every time the Cargo.toml changes. Cargo.lock: Cargo.toml cargo update --workspace install: build-libs - go install -ldflags="${GOLDFLAGS}" ./... + go install $(GOTAGS) -ldflags="${GOLDFLAGS}" ./... build: build-libs - go build -ldflags="${GOLDFLAGS}" ./... + go build $(GOTAGS) -ldflags="${GOLDFLAGS}" ./... build-libs: Cargo.lock cd cmd/stellar-rpc/lib/preflight && \ @@ -93,12 +102,12 @@ rust-test: cargo test go-test: build-libs - go test ./... + go test $(GOTAGS) ./... test: go-test rust-test bench: - go test -run=None -bench=. ./... + go test $(GOTAGS) -run=None -bench=. ./... clean: cargo clean @@ -108,13 +117,13 @@ clean: # https://github.com/stellar/pipelines/blob/master/stellar-rpc/Jenkinsfile-stellar-rpc-package-builder # as part of the package building. build-stellar-rpc: build-libs - go build -ldflags="${GOLDFLAGS}" ${MACOS_MIN_VER} -o ${STELLAR_RPC_BINARY} -trimpath -v ./cmd/stellar-rpc + go build $(GOTAGS) -ldflags="${GOLDFLAGS}" ${MACOS_MIN_VER} -o ${STELLAR_RPC_BINARY} -trimpath -v ./cmd/stellar-rpc go-check-branch: - golangci-lint run ./... --new-from-rev $$(git rev-parse origin/main) + golangci-lint run $(GOLANGCI_LINT_TAGS) ./... --new-from-rev $$(git rev-parse origin/main) go-check: - golangci-lint run ./... + golangci-lint run $(GOLANGCI_LINT_TAGS) ./... # PHONY lists all the targets that aren't file names, so that make would skip the timestamp based check. .PHONY: clean fmt watch test rust-test go-test check rust-check go-check install build build-stellar-rpc build-libs lint lint-changes diff --git a/cmd/stellar-rpc/internal/feewindow/feewindow.go b/cmd/stellar-rpc/internal/feewindow/feewindow.go index 77ae56c1..40b24828 100644 --- a/cmd/stellar-rpc/internal/feewindow/feewindow.go +++ b/cmd/stellar-rpc/internal/feewindow/feewindow.go @@ -172,30 +172,16 @@ func (fw *FeeWindows) IngestFees(meta xdr.LedgerCloseMeta) error { // should not happen continue } - if len(ops) == 1 { - switch ops[0].Body.Type { //nolint:exhaustive - case xdr.OperationTypeInvokeHostFunction, xdr.OperationTypeExtendFootprintTtl, xdr.OperationTypeRestoreFootprint: - var sorobanFees xdr.SorobanTransactionMetaExtV1 - switch tx.UnsafeMeta.V { - case 3: - if tx.UnsafeMeta.V3.SorobanMeta == nil || tx.UnsafeMeta.V3.SorobanMeta.Ext.V != 1 { - continue - } - sorobanFees = *tx.UnsafeMeta.V3.SorobanMeta.Ext.V1 - case 4: - if tx.UnsafeMeta.V4.SorobanMeta == nil || tx.UnsafeMeta.V4.SorobanMeta.Ext.V != 1 { - continue - } - sorobanFees = *tx.UnsafeMeta.V4.SorobanMeta.Ext.V1 - default: - continue - } - resourceFeeCharged := sorobanFees.TotalNonRefundableResourceFeeCharged + - sorobanFees.TotalRefundableResourceFeeCharged - inclusionFee := feeCharged - uint64(resourceFeeCharged) - sorobanInclusionFees = append(sorobanInclusionFees, inclusionFee) + if len(ops) == 1 && isSorobanOperation(ops[0].Body.Type) { + sorobanFees, ok := extractSorobanFees(tx.UnsafeMeta) + if !ok { continue } + resourceFeeCharged := sorobanFees.TotalNonRefundableResourceFeeCharged + + sorobanFees.TotalRefundableResourceFeeCharged + inclusionFee := feeCharged - uint64(resourceFeeCharged) + sorobanInclusionFees = append(sorobanInclusionFees, inclusionFee) + continue } feePerOp := feeCharged / uint64(len(ops)) classicFees = append(classicFees, feePerOp) diff --git a/cmd/stellar-rpc/internal/feewindow/feewindow_no_xdr_hello_world.go b/cmd/stellar-rpc/internal/feewindow/feewindow_no_xdr_hello_world.go new file mode 100644 index 00000000..402f8230 --- /dev/null +++ b/cmd/stellar-rpc/internal/feewindow/feewindow_no_xdr_hello_world.go @@ -0,0 +1,18 @@ +//go:build !xdr_hello_world + +package feewindow + +import "github.com/stellar/go-stellar-sdk/xdr" + +// isSorobanOperation returns true if the operation type is a Soroban +// operation that incurs Soroban-specific resource fees. +func isSorobanOperation(opType xdr.OperationType) bool { + switch opType { //nolint:exhaustive + case xdr.OperationTypeInvokeHostFunction, + xdr.OperationTypeExtendFootprintTtl, + xdr.OperationTypeRestoreFootprint: + return true + default: + return false + } +} diff --git a/cmd/stellar-rpc/internal/feewindow/feewindow_no_xdr_transaction_meta_v5.go b/cmd/stellar-rpc/internal/feewindow/feewindow_no_xdr_transaction_meta_v5.go new file mode 100644 index 00000000..0a1dba86 --- /dev/null +++ b/cmd/stellar-rpc/internal/feewindow/feewindow_no_xdr_transaction_meta_v5.go @@ -0,0 +1,22 @@ +//go:build !xdr_transaction_meta_v5 + +package feewindow + +import "github.com/stellar/go-stellar-sdk/xdr" + +func extractSorobanFees(meta xdr.TransactionMeta) (xdr.SorobanTransactionMetaExtV1, bool) { + switch meta.V { + case 3: + if meta.V3.SorobanMeta == nil || meta.V3.SorobanMeta.Ext.V != 1 { + return xdr.SorobanTransactionMetaExtV1{}, false + } + return *meta.V3.SorobanMeta.Ext.V1, true + case 4: + if meta.V4.SorobanMeta == nil || meta.V4.SorobanMeta.Ext.V != 1 { + return xdr.SorobanTransactionMetaExtV1{}, false + } + return *meta.V4.SorobanMeta.Ext.V1, true + default: + return xdr.SorobanTransactionMetaExtV1{}, false + } +} diff --git a/cmd/stellar-rpc/internal/feewindow/feewindow_xdr_hello_world.go b/cmd/stellar-rpc/internal/feewindow/feewindow_xdr_hello_world.go new file mode 100644 index 00000000..d98351e5 --- /dev/null +++ b/cmd/stellar-rpc/internal/feewindow/feewindow_xdr_hello_world.go @@ -0,0 +1,22 @@ +//go:build xdr_hello_world + +package feewindow + +import "github.com/stellar/go-stellar-sdk/xdr" + +// isSorobanOperation returns true if the operation type is a Soroban +// operation that incurs Soroban-specific resource fees. +// OperationTypeHelloWorld is a classic operation and does not incur +// Soroban fees. +func isSorobanOperation(opType xdr.OperationType) bool { + switch opType { //nolint:exhaustive + case xdr.OperationTypeInvokeHostFunction, + xdr.OperationTypeExtendFootprintTtl, + xdr.OperationTypeRestoreFootprint: + return true + case xdr.OperationTypeHelloWorld: + return false + default: + return false + } +} diff --git a/cmd/stellar-rpc/internal/feewindow/feewindow_xdr_transaction_meta_v5.go b/cmd/stellar-rpc/internal/feewindow/feewindow_xdr_transaction_meta_v5.go new file mode 100644 index 00000000..7a52327f --- /dev/null +++ b/cmd/stellar-rpc/internal/feewindow/feewindow_xdr_transaction_meta_v5.go @@ -0,0 +1,27 @@ +//go:build xdr_transaction_meta_v5 + +package feewindow + +import "github.com/stellar/go-stellar-sdk/xdr" + +func extractSorobanFees(meta xdr.TransactionMeta) (xdr.SorobanTransactionMetaExtV1, bool) { + switch meta.V { + case 3: + if meta.V3.SorobanMeta == nil || meta.V3.SorobanMeta.Ext.V != 1 { + return xdr.SorobanTransactionMetaExtV1{}, false + } + return *meta.V3.SorobanMeta.Ext.V1, true + case 4: + if meta.V4.SorobanMeta == nil || meta.V4.SorobanMeta.Ext.V != 1 { + return xdr.SorobanTransactionMetaExtV1{}, false + } + return *meta.V4.SorobanMeta.Ext.V1, true + case 5: + if meta.V5.SorobanMeta == nil || meta.V5.SorobanMeta.Ext.V != 1 { + return xdr.SorobanTransactionMetaExtV1{}, false + } + return *meta.V5.SorobanMeta.Ext.V1, true + default: + return xdr.SorobanTransactionMetaExtV1{}, false + } +} diff --git a/cmd/stellar-rpc/internal/integrationtest/get_fee_stats_test.go b/cmd/stellar-rpc/internal/integrationtest/get_fee_stats_test.go index 71a45a1a..2f7815b6 100644 --- a/cmd/stellar-rpc/internal/integrationtest/get_fee_stats_test.go +++ b/cmd/stellar-rpc/internal/integrationtest/get_fee_stats_test.go @@ -23,15 +23,7 @@ func TestGetFeeStats(t *testing.T) { sorobanTotalFee := sorobanTxResult.FeeCharged var sorobanTxMeta xdr.TransactionMeta require.NoError(t, xdr.SafeUnmarshalBase64(sorobanTxResponse.ResultMetaXDR, &sorobanTxMeta)) - var sorobanFees xdr.SorobanTransactionMetaExtV1 - switch sorobanTxMeta.V { - case 3: - sorobanFees = *sorobanTxMeta.V3.SorobanMeta.Ext.V1 - case 4: - sorobanFees = *sorobanTxMeta.V4.SorobanMeta.Ext.V1 - default: - t.Fatalf("Unexpected meta version: %d", sorobanTxMeta.V) - } + sorobanFees := extractSorobanFeesFromMeta(t, sorobanTxMeta) sorobanResourceFeeCharged := sorobanFees.TotalRefundableResourceFeeCharged + sorobanFees.TotalNonRefundableResourceFeeCharged sorobanInclusionFee := uint64(sorobanTotalFee - sorobanResourceFeeCharged) diff --git a/cmd/stellar-rpc/internal/integrationtest/meta_helpers_no_xdr_transaction_meta_v5_test.go b/cmd/stellar-rpc/internal/integrationtest/meta_helpers_no_xdr_transaction_meta_v5_test.go new file mode 100644 index 00000000..f55a67ea --- /dev/null +++ b/cmd/stellar-rpc/internal/integrationtest/meta_helpers_no_xdr_transaction_meta_v5_test.go @@ -0,0 +1,35 @@ +//go:build !xdr_transaction_meta_v5 + +package integrationtest + +import ( + "testing" + + "github.com/stellar/go-stellar-sdk/xdr" +) + +func extractReturnValue(t *testing.T, meta xdr.TransactionMeta) xdr.ScVal { + t.Helper() + switch meta.V { + case 3: + return meta.V3.SorobanMeta.ReturnValue + case 4: + return *meta.V4.SorobanMeta.ReturnValue + default: + t.Fatalf("Unexpected meta version: %d", meta.V) + return xdr.ScVal{} + } +} + +func extractSorobanFeesFromMeta(t *testing.T, meta xdr.TransactionMeta) xdr.SorobanTransactionMetaExtV1 { + t.Helper() + switch meta.V { + case 3: + return *meta.V3.SorobanMeta.Ext.V1 + case 4: + return *meta.V4.SorobanMeta.Ext.V1 + default: + t.Fatalf("Unexpected meta version: %d", meta.V) + return xdr.SorobanTransactionMetaExtV1{} + } +} diff --git a/cmd/stellar-rpc/internal/integrationtest/meta_helpers_xdr_transaction_meta_v5_test.go b/cmd/stellar-rpc/internal/integrationtest/meta_helpers_xdr_transaction_meta_v5_test.go new file mode 100644 index 00000000..7c678130 --- /dev/null +++ b/cmd/stellar-rpc/internal/integrationtest/meta_helpers_xdr_transaction_meta_v5_test.go @@ -0,0 +1,39 @@ +//go:build xdr_transaction_meta_v5 + +package integrationtest + +import ( + "testing" + + "github.com/stellar/go-stellar-sdk/xdr" +) + +func extractReturnValue(t *testing.T, meta xdr.TransactionMeta) xdr.ScVal { + t.Helper() + switch meta.V { + case 3: + return meta.V3.SorobanMeta.ReturnValue + case 4: + return *meta.V4.SorobanMeta.ReturnValue + case 5: + return *meta.V5.SorobanMeta.ReturnValue + default: + t.Fatalf("Unexpected meta version: %d", meta.V) + return xdr.ScVal{} + } +} + +func extractSorobanFeesFromMeta(t *testing.T, meta xdr.TransactionMeta) xdr.SorobanTransactionMetaExtV1 { + t.Helper() + switch meta.V { + case 3: + return *meta.V3.SorobanMeta.Ext.V1 + case 4: + return *meta.V4.SorobanMeta.Ext.V1 + case 5: + return *meta.V5.SorobanMeta.Ext.V1 + default: + t.Fatalf("Unexpected meta version: %d", meta.V) + return xdr.SorobanTransactionMetaExtV1{} + } +} diff --git a/cmd/stellar-rpc/internal/integrationtest/transaction_test.go b/cmd/stellar-rpc/internal/integrationtest/transaction_test.go index 35c0ce87..9dc3fcc7 100644 --- a/cmd/stellar-rpc/internal/integrationtest/transaction_test.go +++ b/cmd/stellar-rpc/internal/integrationtest/transaction_test.go @@ -45,15 +45,7 @@ func TestSendTransactionSucceedsWithResults(t *testing.T) { expectedScVal := xdr.ScVal{Type: xdr.ScValTypeScvBytes, Bytes: &contractHashBytes} var transactionMeta xdr.TransactionMeta require.NoError(t, xdr.SafeUnmarshalBase64(response.ResultMetaXDR, &transactionMeta)) - var retVal xdr.ScVal - switch transactionMeta.V { - case 3: - retVal = transactionMeta.V3.SorobanMeta.ReturnValue - case 4: - retVal = *transactionMeta.V4.SorobanMeta.ReturnValue - default: - t.Fatalf("Unexpected protocol version: %d", transactionMeta.V) - } + retVal := extractReturnValue(t, transactionMeta) require.True(t, expectedScVal.Equals(retVal)) var resultXdr xdr.TransactionResult require.NoError(t, xdr.SafeUnmarshalBase64(response.ResultXDR, &resultXdr)) diff --git a/cmd/stellar-rpc/internal/methods/simulate_transaction.go b/cmd/stellar-rpc/internal/methods/simulate_transaction.go index a946448f..4fe16ee1 100644 --- a/cmd/stellar-rpc/internal/methods/simulate_transaction.go +++ b/cmd/stellar-rpc/internal/methods/simulate_transaction.go @@ -293,8 +293,14 @@ func NewSimulateTransactionHandler(logger *log.Entry, sourceAccount = txEnvelope.SourceAccount().ToAccountId() } + if !isSorobanSimulationOp(op.Body.Type) { + return protocol.SimulateTransactionResponse{ + Error: "Transaction contains unsupported operation type: " + op.Body.Type.String(), + } + } + footprint := xdr.LedgerFootprint{} - switch op.Body.Type { + switch op.Body.Type { //nolint:exhaustive case xdr.OperationTypeInvokeHostFunction: // no-op case xdr.OperationTypeExtendFootprintTtl, xdr.OperationTypeRestoreFootprint: if txEnvelope.Type != xdr.EnvelopeTypeEnvelopeTypeTx && txEnvelope.V1.Tx.Ext.V != 1 { @@ -304,11 +310,6 @@ func NewSimulateTransactionHandler(logger *log.Entry, } } footprint = txEnvelope.V1.Tx.Ext.SorobanData.Resources.Footprint - - default: - return protocol.SimulateTransactionResponse{ - Error: "Transaction contains unsupported operation type: " + op.Body.Type.String(), - } } latestLedger, err := ledgerReader.GetLatestLedgerSequence(ctx) @@ -386,7 +387,11 @@ func validateAuthMode(opBody xdr.OperationBody, authModeRef *string) error { ) } - switch opBody.Type { + if !isSorobanSimulationOp(opBody.Type) { + return fmt.Errorf("transaction contains unsupported operation type: %s", opBody.Type.String()) + } + + switch opBody.Type { //nolint:exhaustive case xdr.OperationTypeInvokeHostFunction: hasAuth := len(opBody.MustInvokeHostFunctionOp().Auth) > 0 @@ -414,9 +419,6 @@ func validateAuthMode(opBody xdr.OperationBody, authModeRef *string) error { if authMode != "" { return errors.New("cannot set authMode with non-InvokeHostFunction operations") } - - default: - return fmt.Errorf("transaction contains unsupported operation type: %s", opBody.Type.String()) } return nil diff --git a/cmd/stellar-rpc/internal/methods/simulate_transaction_no_xdr_hello_world.go b/cmd/stellar-rpc/internal/methods/simulate_transaction_no_xdr_hello_world.go new file mode 100644 index 00000000..f3eda100 --- /dev/null +++ b/cmd/stellar-rpc/internal/methods/simulate_transaction_no_xdr_hello_world.go @@ -0,0 +1,18 @@ +//go:build !xdr_hello_world + +package methods + +import "github.com/stellar/go-stellar-sdk/xdr" + +// isSorobanSimulationOp returns true if the operation type is supported +// by the simulate transaction endpoint. +func isSorobanSimulationOp(opType xdr.OperationType) bool { + switch opType { //nolint:exhaustive + case xdr.OperationTypeInvokeHostFunction, + xdr.OperationTypeExtendFootprintTtl, + xdr.OperationTypeRestoreFootprint: + return true + default: + return false + } +} diff --git a/cmd/stellar-rpc/internal/methods/simulate_transaction_xdr_hello_world.go b/cmd/stellar-rpc/internal/methods/simulate_transaction_xdr_hello_world.go new file mode 100644 index 00000000..dac23db2 --- /dev/null +++ b/cmd/stellar-rpc/internal/methods/simulate_transaction_xdr_hello_world.go @@ -0,0 +1,22 @@ +//go:build xdr_hello_world + +package methods + +import "github.com/stellar/go-stellar-sdk/xdr" + +// isSorobanSimulationOp returns true if the operation type is supported +// by the simulate transaction endpoint. +// OperationTypeHelloWorld is a classic operation and is not supported +// for simulation. +func isSorobanSimulationOp(opType xdr.OperationType) bool { + switch opType { //nolint:exhaustive + case xdr.OperationTypeInvokeHostFunction, + xdr.OperationTypeExtendFootprintTtl, + xdr.OperationTypeRestoreFootprint: + return true + case xdr.OperationTypeHelloWorld: + return false + default: + return false + } +} diff --git a/cmd/stellar-rpc/internal/preflight/preflight.go b/cmd/stellar-rpc/internal/preflight/preflight.go index b69e3ae9..856ef5ec 100644 --- a/cmd/stellar-rpc/internal/preflight/preflight.go +++ b/cmd/stellar-rpc/internal/preflight/preflight.go @@ -158,7 +158,11 @@ func GoXDRDiffVector(xdrDiffVector C.xdr_diff_vector_t) []XDRDiff { } func GetPreflight(ctx context.Context, params Parameters) (Preflight, error) { - switch params.OpBody.Type { + if !isPreflightSupportedOp(params.OpBody.Type) { + return Preflight{}, fmt.Errorf("unsupported operation type: %s", params.OpBody.Type.String()) + } + + switch params.OpBody.Type { //nolint:exhaustive case xdr.OperationTypeInvokeHostFunction: return getInvokeHostFunctionPreflight(ctx, params) case xdr.OperationTypeExtendFootprintTtl, xdr.OperationTypeRestoreFootprint: diff --git a/cmd/stellar-rpc/internal/preflight/preflight_no_xdr_hello_world.go b/cmd/stellar-rpc/internal/preflight/preflight_no_xdr_hello_world.go new file mode 100644 index 00000000..f0fc8de3 --- /dev/null +++ b/cmd/stellar-rpc/internal/preflight/preflight_no_xdr_hello_world.go @@ -0,0 +1,18 @@ +//go:build !xdr_hello_world + +package preflight + +import "github.com/stellar/go-stellar-sdk/xdr" + +// isPreflightSupportedOp returns true if the operation type is supported +// by the preflight endpoint. +func isPreflightSupportedOp(opType xdr.OperationType) bool { + switch opType { //nolint:exhaustive + case xdr.OperationTypeInvokeHostFunction, + xdr.OperationTypeExtendFootprintTtl, + xdr.OperationTypeRestoreFootprint: + return true + default: + return false + } +} diff --git a/cmd/stellar-rpc/internal/preflight/preflight_xdr_hello_world.go b/cmd/stellar-rpc/internal/preflight/preflight_xdr_hello_world.go new file mode 100644 index 00000000..87984706 --- /dev/null +++ b/cmd/stellar-rpc/internal/preflight/preflight_xdr_hello_world.go @@ -0,0 +1,22 @@ +//go:build xdr_hello_world + +package preflight + +import "github.com/stellar/go-stellar-sdk/xdr" + +// isPreflightSupportedOp returns true if the operation type is supported +// by the preflight endpoint. +// OperationTypeHelloWorld is a classic operation and is not supported +// for preflight. +func isPreflightSupportedOp(opType xdr.OperationType) bool { + switch opType { //nolint:exhaustive + case xdr.OperationTypeInvokeHostFunction, + xdr.OperationTypeExtendFootprintTtl, + xdr.OperationTypeRestoreFootprint: + return true + case xdr.OperationTypeHelloWorld: + return false + default: + return false + } +} diff --git a/go.mod b/go.mod index 551f2ad4..d86692ba 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/sirupsen/logrus v1.9.3 github.com/spf13/cobra v1.7.0 github.com/spf13/pflag v1.0.5 - github.com/stellar/go-stellar-sdk v0.0.0-20260211033645-9b3fcf4e75b1 + github.com/stellar/go-stellar-sdk v0.0.0-20260216044013-b2a189759a2c github.com/stretchr/testify v1.11.1 ) diff --git a/go.sum b/go.sum index 563cee84..3ab8e7f7 100644 --- a/go.sum +++ b/go.sum @@ -429,8 +429,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/spiffe/go-spiffe/v2 v2.6.0 h1:l+DolpxNWYgruGQVV0xsfeya3CsC7m8iBzDnMpsbLuo= github.com/spiffe/go-spiffe/v2 v2.6.0/go.mod h1:gm2SeUoMZEtpnzPNs2Csc0D/gX33k1xIx7lEzqblHEs= -github.com/stellar/go-stellar-sdk v0.0.0-20260211033645-9b3fcf4e75b1 h1:5gLvjIM/y0LaukrO4WRUfZK0Sa2HZxAoX4TCSE7Ujyk= -github.com/stellar/go-stellar-sdk v0.0.0-20260211033645-9b3fcf4e75b1/go.mod h1:4osSHRDfb/D7zE2iNjmPdg2Gmbx0M/JLhTM4YcwPW5s= +github.com/stellar/go-stellar-sdk v0.0.0-20260216044013-b2a189759a2c h1:GfaTE2YK/w21gY069k77lO16mLLh8XCmtanfTJgyvzM= +github.com/stellar/go-stellar-sdk v0.0.0-20260216044013-b2a189759a2c/go.mod h1:4osSHRDfb/D7zE2iNjmPdg2Gmbx0M/JLhTM4YcwPW5s= 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=