Skip to content

Commit

Permalink
rpc: Add diagnostic events to sendTransaction response
Browse files Browse the repository at this point in the history
  • Loading branch information
2opremio committed Jan 4, 2024
1 parent d38ab7f commit 9e609b1
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/soroban-rpc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ jobs:
env:
SOROBAN_RPC_INTEGRATION_TESTS_ENABLED: true
SOROBAN_RPC_INTEGRATION_TESTS_CAPTIVE_CORE_BIN: /usr/bin/stellar-core
PROTOCOL_20_CORE_DEBIAN_PKG_VERSION: 20.0.2-1633.669916b56.focal
PROTOCOL_20_CORE_DEBIAN_PKG_VERSION: 20.0.3-1645.ab1d1b50c.focal
steps:
- uses: actions/checkout@v3
with:
Expand Down
12 changes: 12 additions & 0 deletions cmd/soroban-rpc/internal/methods/send_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ type SendTransactionResponse struct {
// ErrorResultXDR is a TransactionResult xdr string which contains details on why
// the transaction could not be accepted by stellar-core.
ErrorResultXDR string `json:"errorResultXdr,omitempty"`
// DiagnosticEventsXDR is present only if Status is equal to proto.TXStatusError.
// DiagnosticEventsXDR is a base64-encoded slice of xdr.DiagnosticEvent
DiagnosticEventsXDR []string `json:"diagnosticEventsXdr,omitempty"`
// Status represents the status of the transaction submission returned by stellar-core.
// Status can be one of: proto.TXStatusPending, proto.TXStatusDuplicate,
// proto.TXStatusTryAgainLater, or proto.TXStatusError.
Expand Down Expand Up @@ -94,8 +97,17 @@ func NewSendTransactionHandler(daemon interfaces.Daemon, logger *log.Entry, stor

switch resp.Status {
case proto.TXStatusError:
events, err := proto.DiagnosticEventsToSlice(resp.DiagnosticEvents)
if err != nil {
logger.WithField("tx", request.Transaction).Error("Cannot decode diagnostic events:", err)
return SendTransactionResponse{}, &jrpc2.Error{
Code: jrpc2.InternalError,
Message: "could not decode diagnostic events",
}
}
return SendTransactionResponse{
ErrorResultXDR: resp.Error,
DiagnosticEventsXDR: events,
Status: resp.Status,
Hash: txHash,
LatestLedger: ledgerInfo.Sequence,
Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-rpc/internal/test/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ services:
# Note: Please keep the image pinned to an immutable tag matching the Captive Core version.
# This avoids implicit updates which break compatibility between
# the Core container and captive core.
image: ${CORE_IMAGE:-stellar/unsafe-stellar-core:20.0.2-1633.669916b56.focal}
image: ${CORE_IMAGE:-stellar/unsafe-stellar-core:20.0.3-1645.ab1d1b50c.focal}
depends_on:
- core-postgres
restart: on-failure
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
ARTIFICIALLY_ACCELERATE_TIME_FOR_TESTING=true
ENABLE_DIAGNOSTICS_FOR_TX_SUBMISSION=true

NETWORK_PASSPHRASE="Standalone Network ; February 2017"

Expand Down
52 changes: 52 additions & 0 deletions cmd/soroban-rpc/internal/test/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,58 @@ func TestSendTransactionBadSequence(t *testing.T) {
assert.Equal(t, xdr.TransactionResultCodeTxBadSeq, errorResult.Result.Code)
}

func TestSendTransactionFailedInsufficientResourceFee(t *testing.T) {
test := NewTest(t)

ch := jhttp.NewChannel(test.sorobanRPCURL(), nil)
client := jrpc2.NewClient(ch, nil)

kp := keypair.Root(StandaloneNetworkPassphrase)
address := kp.Address()
account := txnbuild.NewSimpleAccount(address, 0)

contractBinary := getHelloWorldContract(t)
params := preflightTransactionParams(t, client, txnbuild.TransactionParams{
SourceAccount: &account,
IncrementSequenceNum: true,
Operations: []txnbuild.Operation{
createInstallContractCodeOperation(account.AccountID, contractBinary),
},
BaseFee: txnbuild.MinBaseFee,
Preconditions: txnbuild.Preconditions{
TimeBounds: txnbuild.NewInfiniteTimeout(),
},
})

// make the transaction fail due to insufficient resource fees
params.Operations[0].(*txnbuild.InvokeHostFunction).Ext.SorobanData.ResourceFee /= 2

tx, err := txnbuild.NewTransaction(params)
assert.NoError(t, err)

assert.NoError(t, err)
tx, err = tx.Sign(StandaloneNetworkPassphrase, kp)
assert.NoError(t, err)
b64, err := tx.Base64()
assert.NoError(t, err)

request := methods.SendTransactionRequest{Transaction: b64}
var result methods.SendTransactionResponse
err = client.CallResult(context.Background(), "sendTransaction", request, &result)
assert.NoError(t, err)

assert.Equal(t, proto.TXStatusError, result.Status)
var errorResult xdr.TransactionResult
assert.NoError(t, xdr.SafeUnmarshalBase64(result.ErrorResultXDR, &errorResult))
assert.Equal(t, xdr.TransactionResultCodeTxSorobanInvalid, errorResult.Result.Code)

assert.Greater(t, len(result.DiagnosticEventsXDR), 0)
var event xdr.DiagnosticEvent
err = xdr.SafeUnmarshalBase64(result.DiagnosticEventsXDR[0], &event)
assert.NoError(t, err)

}

func TestSendTransactionFailedInLedger(t *testing.T) {
test := NewTest(t)

Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,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 v0.0.0-20231204183605-af6f4ebad728
github.com/stellar/go v0.0.0-20240102161234-51c1b1571944
github.com/stretchr/testify v1.8.4
golang.org/x/mod v0.13.0
gotest.tools/v3 v3.5.0
Expand All @@ -37,7 +37,6 @@ require (
github.com/skeema/knownhosts v1.2.1 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/xdrpp/goxdr v0.1.1 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/tools v0.14.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
15 changes: 6 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ github.com/gobuffalo/logger v1.0.6 h1:nnZNpxYo0zx+Aj9RfMPBm+x9zAU2OayFh/xrAWi34H
github.com/gobuffalo/logger v1.0.6/go.mod h1:J31TBEHR1QLV2683OXTAItYIg8pv2JMHnF/quuAbMjs=
github.com/gobuffalo/packd v1.0.2 h1:Yg523YqnOxGIWCp69W12yYBKsoChwI7mtu6ceM9Bwfw=
github.com/gobuffalo/packd v1.0.2/go.mod h1:sUc61tDqGMXON80zpKGp92lDb86Km28jfvX7IAyxFT8=
github.com/gobuffalo/packr v1.30.1 h1:hu1fuVR3fXEZR7rXNW3h8rqSML8EVAf6KNm0NKO/wKg=
github.com/gobuffalo/packr/v2 v2.8.3 h1:xE1yzvnO56cUC0sTpKR3DIbxZgB54AftTFMhB2XEWlY=
github.com/gobuffalo/packr/v2 v2.8.3/go.mod h1:0SahksCVcx4IMnigTjiFuyldmTrdTctXsOdiU5KwbKc=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
Expand Down Expand Up @@ -204,8 +203,10 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g=
github.com/gorilla/schema v1.1.0 h1:CamqUDOFUBqzrvxuz2vEwo8+SUdwsluFh7IlzJh30LY=
github.com/gorilla/schema v1.1.0/go.mod h1:kgLaKoK1FELgZqMAVxx/5cbj0kT+57qxUrAlIO2eleU=
github.com/gorilla/schema v1.2.0 h1:YufUaxZYCKGFuAq3c96BOhjgd5nmXiOY9NGzF247Tsc=
github.com/gorilla/schema v1.2.0/go.mod h1:kgLaKoK1FELgZqMAVxx/5cbj0kT+57qxUrAlIO2eleU=
github.com/guregu/null v4.0.0+incompatible h1:4zw0ckM7ECd6FNNddc3Fu4aty9nTlpkkzH7dPn4/4Gw=
github.com/guregu/null v4.0.0+incompatible/go.mod h1:ePGpQaN9cw0tj45IR5E5ehMvsFlLlQZAkkOXZurJ3NM=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
Expand Down Expand Up @@ -333,12 +334,8 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
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-20231114175958-eb2984b58392 h1:sYxHgLDT3z6cJrWuf0O9Fbs/E2UNGh3PPoOlM8DJ2vk=
github.com/stellar/go v0.0.0-20231114175958-eb2984b58392/go.mod h1:g78pyZyDFnKMJUaBIXxH7xyQ7PdDrvrJTFCxdGMMb3c=
github.com/stellar/go v0.0.0-20231204183605-af6f4ebad728 h1:lyATpWxLxhZSZIGP3MfCs+C5bVJWvX/FcvQCslknK4E=
github.com/stellar/go v0.0.0-20231204183605-af6f4ebad728/go.mod h1:3wMphjCZGi42wsrrKknendsozw7g9FVBm4YSlI1LpA4=
github.com/stellar/go-xdr v0.0.0-20230919160922-6c7b68458206 h1:UFuvvpbWL8+jqO1QmKYWSVhiMp4MRiIFd8/zQlUINH0=
github.com/stellar/go-xdr v0.0.0-20230919160922-6c7b68458206/go.mod h1:yoxyU/M8nl9LKeWIoBrbDPQ7Cy+4jxRcWcOayZ4BMps=
github.com/stellar/go v0.0.0-20240102161234-51c1b1571944 h1:zuaWX3KC9z7zVAmnX4nIrlnKMGUpNEQOsWAD7m+Bjl8=
github.com/stellar/go v0.0.0-20240102161234-51c1b1571944/go.mod h1:PAWie4LYyDzJXqDVG4Qcj1Nt+uNk7sjzgSCXndQYsBA=
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

0 comments on commit 9e609b1

Please sign in to comment.