From 54e3360242a937dc95b144083461fb954482c067 Mon Sep 17 00:00:00 2001 From: George Date: Wed, 23 Oct 2024 13:46:22 -0700 Subject: [PATCH 1/5] Add both versions of getVersionInfo in, change type of createdAt --- .../internal/methods/get_events.go | 3 ++- .../internal/methods/get_transactions.go | 2 +- .../internal/methods/get_version_info.go | 22 ++++++++++++++----- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/cmd/soroban-rpc/internal/methods/get_events.go b/cmd/soroban-rpc/internal/methods/get_events.go index e63f9132..a7d78eb1 100644 --- a/cmd/soroban-rpc/internal/methods/get_events.go +++ b/cmd/soroban-rpc/internal/methods/get_events.go @@ -337,7 +337,8 @@ type PaginationOptions struct { type GetEventsResponse struct { Events []EventInfo `json:"events"` LatestLedger uint32 `json:"latestLedger"` - // Cursor represents last populated event ID if total events reach the limit or end of the search window + // Cursor represents last populated event ID if total events reach the limit + // or end of the search window Cursor string `json:"cursor"` } diff --git a/cmd/soroban-rpc/internal/methods/get_transactions.go b/cmd/soroban-rpc/internal/methods/get_transactions.go index beb0affe..e98598d1 100644 --- a/cmd/soroban-rpc/internal/methods/get_transactions.go +++ b/cmd/soroban-rpc/internal/methods/get_transactions.go @@ -82,7 +82,7 @@ type TransactionInfo struct { // Ledger is the sequence of the ledger which included the transaction. Ledger uint32 `json:"ledger"` // LedgerCloseTime is the unix timestamp of when the transaction was included in the ledger. - LedgerCloseTime int64 `json:"createdAt,string"` + LedgerCloseTime int64 `json:"createdAt"` } // GetTransactionsResponse encapsulates the response structure for getTransactions queries. diff --git a/cmd/soroban-rpc/internal/methods/get_version_info.go b/cmd/soroban-rpc/internal/methods/get_version_info.go index 038bf54a..cb73cb35 100644 --- a/cmd/soroban-rpc/internal/methods/get_version_info.go +++ b/cmd/soroban-rpc/internal/methods/get_version_info.go @@ -19,6 +19,14 @@ type GetVersionInfoResponse struct { BuildTimestamp string `json:"buildTimestamp"` CaptiveCoreVersion string `json:"captiveCoreVersion"` ProtocolVersion uint32 `json:"protocolVersion"` + //nolint:tagliatelle + CommitHashDeprecated string `json:"commit_hash"` + //nolint:tagliatelle + BuildTimestampDeprecated string `json:"build_timestamp"` + //nolint:tagliatelle + CaptiveCoreVersionDeprecated string `json:"captive_core_version"` + //nolint:tagliatelle + ProtocolVersionDeprecated uint32 `json:"protocol_version"` } func NewGetVersionInfoHandler( @@ -37,11 +45,15 @@ func NewGetVersionInfoHandler( } return GetVersionInfoResponse{ - Version: config.Version, - CommitHash: config.CommitHash, - BuildTimestamp: config.BuildTimestamp, - CaptiveCoreVersion: captiveCoreVersion, - ProtocolVersion: protocolVersion, + Version: config.Version, + CommitHash: config.CommitHash, + CommitHashDeprecated: config.CommitHash, + BuildTimestamp: config.BuildTimestamp, + BuildTimestampDeprecated: config.BuildTimestamp, + CaptiveCoreVersion: captiveCoreVersion, + CaptiveCoreVersionDeprecated: captiveCoreVersion, + ProtocolVersion: protocolVersion, + ProtocolVersionDeprecated: protocolVersion, }, nil }) } From e04483ad41545c0fda607d08a9601ef485707774 Mon Sep 17 00:00:00 2001 From: George Date: Thu, 24 Oct 2024 12:12:11 -0700 Subject: [PATCH 2/5] Make createdAt properly non-breaking --- .../internal/methods/get_transaction.go | 10 ++++-- .../internal/methods/get_transaction_test.go | 18 +++++------ .../internal/methods/get_transactions.go | 31 ++++++++++++------- .../internal/methods/get_transactions_test.go | 22 +++++++------ 4 files changed, 49 insertions(+), 32 deletions(-) diff --git a/cmd/soroban-rpc/internal/methods/get_transaction.go b/cmd/soroban-rpc/internal/methods/get_transaction.go index e6882b96..f08c89f6 100644 --- a/cmd/soroban-rpc/internal/methods/get_transaction.go +++ b/cmd/soroban-rpc/internal/methods/get_transaction.go @@ -38,8 +38,14 @@ type GetTransactionResponse struct { // LatestLedgerCloseTime is the unix timestamp of when the oldest ledger was closed. OldestLedgerCloseTime int64 `json:"oldestLedgerCloseTime,string"` - // Many of the fields below are only present if Status is not TransactionNotFound. - TransactionInfo + // Many of the fields below are only present if Status is not + // TransactionNotFound. + TransactionDetails + // LedgerCloseTime is the unix timestamp of when the transaction was + // included in the ledger. It isn't part of `TransactionInfo` because of a + // bug in which `createdAt` in getTransactions is encoded as a number + // whereas in getTransaction (singular) it's encoded as a string. + LedgerCloseTime int64 `json:"createdAt,string"` } type GetTransactionRequest struct { diff --git a/cmd/soroban-rpc/internal/methods/get_transaction_test.go b/cmd/soroban-rpc/internal/methods/get_transaction_test.go index 38e6d5a3..847b2e6e 100644 --- a/cmd/soroban-rpc/internal/methods/get_transaction_test.go +++ b/cmd/soroban-rpc/internal/methods/get_transaction_test.go @@ -36,7 +36,7 @@ func TestGetTransaction(t *testing.T) { tx, err := GetTransaction(ctx, log, store, ledgerReader, GetTransactionRequest{hash, ""}) require.NoError(t, err) require.Equal(t, GetTransactionResponse{ - TransactionInfo: TransactionInfo{ + TransactionDetails: TransactionDetails{ Status: TransactionStatusNotFound, }, }, tx) @@ -60,7 +60,7 @@ func TestGetTransaction(t *testing.T) { LatestLedgerCloseTime: 2625, OldestLedger: 101, OldestLedgerCloseTime: 2625, - TransactionInfo: TransactionInfo{ + TransactionDetails: TransactionDetails{ Status: TransactionStatusSuccess, ApplicationOrder: 1, FeeBump: false, @@ -68,9 +68,9 @@ func TestGetTransaction(t *testing.T) { ResultXDR: expectedTxResult, ResultMetaXDR: expectedTxMeta, Ledger: 101, - LedgerCloseTime: 2625, DiagnosticEventsXDR: []string{}, }, + LedgerCloseTime: 2625, }, tx) // ingest another (failed) transaction @@ -85,7 +85,7 @@ func TestGetTransaction(t *testing.T) { LatestLedgerCloseTime: 2650, OldestLedger: 101, OldestLedgerCloseTime: 2625, - TransactionInfo: TransactionInfo{ + TransactionDetails: TransactionDetails{ Status: TransactionStatusSuccess, ApplicationOrder: 1, FeeBump: false, @@ -93,9 +93,9 @@ func TestGetTransaction(t *testing.T) { ResultXDR: expectedTxResult, ResultMetaXDR: expectedTxMeta, Ledger: 101, - LedgerCloseTime: 2625, DiagnosticEventsXDR: []string{}, }, + LedgerCloseTime: 2625, }, tx) // the new transaction should also be there @@ -116,7 +116,7 @@ func TestGetTransaction(t *testing.T) { LatestLedgerCloseTime: 2650, OldestLedger: 101, OldestLedgerCloseTime: 2625, - TransactionInfo: TransactionInfo{ + TransactionDetails: TransactionDetails{ Status: TransactionStatusFailed, ApplicationOrder: 1, FeeBump: false, @@ -124,9 +124,9 @@ func TestGetTransaction(t *testing.T) { ResultXDR: expectedTxResult, ResultMetaXDR: expectedTxMeta, Ledger: 102, - LedgerCloseTime: 2650, DiagnosticEventsXDR: []string{}, }, + LedgerCloseTime: 2650, }, tx) // Test Txn with events @@ -151,7 +151,7 @@ func TestGetTransaction(t *testing.T) { tx, err = GetTransaction(ctx, log, store, ledgerReader, GetTransactionRequest{hash, ""}) require.NoError(t, err) require.Equal(t, GetTransactionResponse{ - TransactionInfo: TransactionInfo{ + TransactionDetails: TransactionDetails{ Status: TransactionStatusSuccess, ApplicationOrder: 1, FeeBump: false, @@ -159,9 +159,9 @@ func TestGetTransaction(t *testing.T) { ResultXDR: expectedTxResult, ResultMetaXDR: expectedTxMeta, Ledger: 103, - LedgerCloseTime: 2675, DiagnosticEventsXDR: []string{expectedEventsMeta}, }, + LedgerCloseTime: 2675, LatestLedger: 103, LatestLedgerCloseTime: 2675, OldestLedger: 101, diff --git a/cmd/soroban-rpc/internal/methods/get_transactions.go b/cmd/soroban-rpc/internal/methods/get_transactions.go index e98598d1..3d1d7efe 100644 --- a/cmd/soroban-rpc/internal/methods/get_transactions.go +++ b/cmd/soroban-rpc/internal/methods/get_transactions.go @@ -55,14 +55,15 @@ func (req GetTransactionsRequest) isValid(maxLimit uint, ledgerRange ledgerbucke return IsValidFormat(req.Format) } -type TransactionInfo struct { +type TransactionDetails struct { // Status is one of: TransactionSuccess, TransactionFailed, TransactionNotFound. Status string `json:"status"` - // TransactionHash is the hex encoded hash of the transaction. Note that for fee-bump transaction - // this will be the hash of the fee-bump transaction instead of the inner transaction hash. + // TransactionHash is the hex encoded hash of the transaction. Note that for + // fee-bump transaction this will be the hash of the fee-bump transaction + // instead of the inner transaction hash. TransactionHash string `json:"txHash"` - // ApplicationOrder is the index of the transaction among all the transactions - // for that ledger. + // ApplicationOrder is the index of the transaction among all the + // transactions for that ledger. ApplicationOrder int32 `json:"applicationOrder"` // FeeBump indicates whether the transaction is a feebump transaction FeeBump bool `json:"feeBump"` @@ -81,7 +82,13 @@ type TransactionInfo struct { DiagnosticEventsJSON []json.RawMessage `json:"diagnosticEventsJson,omitempty"` // Ledger is the sequence of the ledger which included the transaction. Ledger uint32 `json:"ledger"` - // LedgerCloseTime is the unix timestamp of when the transaction was included in the ledger. +} + +type TransactionInfo struct { + TransactionDetails + + // LedgerCloseTime is the unix timestamp of when the transaction was + // included in the ledger. LedgerCloseTime int64 `json:"createdAt"` } @@ -197,11 +204,13 @@ func (h transactionsRPCHandler) processTransactionsInLedger( } txInfo := TransactionInfo{ - TransactionHash: tx.TransactionHash, - ApplicationOrder: tx.ApplicationOrder, - FeeBump: tx.FeeBump, - Ledger: tx.Ledger.Sequence, - LedgerCloseTime: tx.Ledger.CloseTime, + TransactionDetails: TransactionDetails{ + TransactionHash: tx.TransactionHash, + ApplicationOrder: tx.ApplicationOrder, + FeeBump: tx.FeeBump, + Ledger: tx.Ledger.Sequence, + }, + LedgerCloseTime: tx.Ledger.CloseTime, } switch format { diff --git a/cmd/soroban-rpc/internal/methods/get_transactions_test.go b/cmd/soroban-rpc/internal/methods/get_transactions_test.go index 24e3f429..531ed9de 100644 --- a/cmd/soroban-rpc/internal/methods/get_transactions_test.go +++ b/cmd/soroban-rpc/internal/methods/get_transactions_test.go @@ -21,16 +21,18 @@ const ( ) var expectedTransactionInfo = TransactionInfo{ - Status: "SUCCESS", - TransactionHash: "b0d0b35dcaed0152d62fbbaa28ed3fa4991c87e7e169a8fca2687b17ee26ca2d", - ApplicationOrder: 1, - FeeBump: false, - Ledger: 1, - LedgerCloseTime: 125, - EnvelopeXDR: "AAAAAgAAAQCAAAAAAAAAAD8MNL+TrQ2ZcdBMzJD3BVEcg4qtlzSkovsNegP8f+iaAAAAAQAAAAD///+dAAAAAAAAAAAAAAAAAAAAAAAAAAA=", //nolint:lll - ResultMetaXDR: "AAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAA", - ResultXDR: "AAAAAAAAAGQAAAAAAAAAAAAAAAA=", - DiagnosticEventsXDR: []string{}, + TransactionDetails{ + Status: "SUCCESS", + TransactionHash: "b0d0b35dcaed0152d62fbbaa28ed3fa4991c87e7e169a8fca2687b17ee26ca2d", + ApplicationOrder: 1, + FeeBump: false, + Ledger: 1, + EnvelopeXDR: "AAAAAgAAAQCAAAAAAAAAAD8MNL+TrQ2ZcdBMzJD3BVEcg4qtlzSkovsNegP8f+iaAAAAAQAAAAD///+dAAAAAAAAAAAAAAAAAAAAAAAAAAA=", //nolint:lll + ResultMetaXDR: "AAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAA", + ResultXDR: "AAAAAAAAAGQAAAAAAAAAAAAAAAA=", + DiagnosticEventsXDR: []string{}, + }, + 125, } // createTestLedger Creates a test ledger with 2 transactions From 4b948c3b197a8db483ff232ec1bf7d0cc0599b5e Mon Sep 17 00:00:00 2001 From: George Date: Thu, 24 Oct 2024 12:31:15 -0700 Subject: [PATCH 3/5] Revert "Remove pagingToken from getEvents (#297)" This reverts commit 44db01f8c6aef623a10a83c0a27f728c918d9a04. --- cmd/soroban-rpc/internal/methods/get_events.go | 3 +++ cmd/soroban-rpc/internal/methods/get_events_test.go | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/cmd/soroban-rpc/internal/methods/get_events.go b/cmd/soroban-rpc/internal/methods/get_events.go index a7d78eb1..933e6d81 100644 --- a/cmd/soroban-rpc/internal/methods/get_events.go +++ b/cmd/soroban-rpc/internal/methods/get_events.go @@ -92,6 +92,8 @@ type EventInfo struct { ContractID string `json:"contractId"` ID string `json:"id"` + // Deprecated: PagingToken field is deprecated, please use Cursor at top level for pagination + PagingToken string `json:"pagingToken"` InSuccessfulContractCall bool `json:"inSuccessfulContractCall"` TransactionHash string `json:"txHash"` @@ -554,6 +556,7 @@ func eventInfoForEvent( Ledger: int32(cursor.Ledger), LedgerClosedAt: ledgerClosedAt, ID: cursor.String(), + PagingToken: cursor.String(), InSuccessfulContractCall: event.InSuccessfulContractCall, TransactionHash: txHash, } diff --git a/cmd/soroban-rpc/internal/methods/get_events_test.go b/cmd/soroban-rpc/internal/methods/get_events_test.go index 81a9c169..cd06b0e3 100644 --- a/cmd/soroban-rpc/internal/methods/get_events_test.go +++ b/cmd/soroban-rpc/internal/methods/get_events_test.go @@ -649,6 +649,7 @@ func TestGetEvents(t *testing.T) { LedgerClosedAt: now.Format(time.RFC3339), ContractID: "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABSC4", ID: id, + PagingToken: id, TopicXDR: []string{value}, ValueXDR: value, InSuccessfulContractCall: true, @@ -795,6 +796,7 @@ func TestGetEvents(t *testing.T) { LedgerClosedAt: now.Format(time.RFC3339), ContractID: "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABSC4", ID: id, + PagingToken: id, TopicXDR: []string{counterXdr, value}, ValueXDR: value, InSuccessfulContractCall: true, @@ -941,6 +943,7 @@ func TestGetEvents(t *testing.T) { LedgerClosedAt: now.Format(time.RFC3339), ContractID: strkey.MustEncode(strkey.VersionByteContract, contractID[:]), ID: id, + PagingToken: id, TopicXDR: []string{counterXdr, value}, ValueXDR: value, InSuccessfulContractCall: true, @@ -1017,6 +1020,7 @@ func TestGetEvents(t *testing.T) { LedgerClosedAt: now.Format(time.RFC3339), ContractID: strkey.MustEncode(strkey.VersionByteContract, contractID[:]), ID: id, + PagingToken: id, TopicXDR: []string{counterXdr}, ValueXDR: counterXdr, InSuccessfulContractCall: true, @@ -1089,6 +1093,7 @@ func TestGetEvents(t *testing.T) { LedgerClosedAt: now.Format(time.RFC3339), ContractID: "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABSC4", ID: id, + PagingToken: id, TopicXDR: []string{value}, ValueXDR: value, InSuccessfulContractCall: true, @@ -1190,6 +1195,7 @@ func TestGetEvents(t *testing.T) { LedgerClosedAt: now.Format(time.RFC3339), ContractID: strkey.MustEncode(strkey.VersionByteContract, contractID[:]), ID: id, + PagingToken: id, TopicXDR: []string{counterXdr}, ValueXDR: expectedXdr, InSuccessfulContractCall: true, From fbfc019c4795b6c4c9d7fc3770c7a12e0eac6c89 Mon Sep 17 00:00:00 2001 From: George Date: Thu, 24 Oct 2024 12:39:56 -0700 Subject: [PATCH 4/5] Fixup the origin version in tests --- cmd/soroban-rpc/internal/integrationtest/migrate_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd/soroban-rpc/internal/integrationtest/migrate_test.go b/cmd/soroban-rpc/internal/integrationtest/migrate_test.go index 750b8b82..a12eae86 100644 --- a/cmd/soroban-rpc/internal/integrationtest/migrate_test.go +++ b/cmd/soroban-rpc/internal/integrationtest/migrate_test.go @@ -31,6 +31,10 @@ func TestMigrate(t *testing.T) { // This version of RPC wasn't published as a docker container continue } + if originVersion == "22.0.0-rc2" { + // This version of RPC wasn't published without a deb build number suffix. + originVersion = "22.0.0-rc2-100" + } t.Run(originVersion, func(t *testing.T) { testMigrateFromVersion(t, originVersion) }) From b50fdfbee18520ef501059a4b4430e4552f21966 Mon Sep 17 00:00:00 2001 From: George Date: Thu, 24 Oct 2024 20:07:46 -0700 Subject: [PATCH 5/5] Ignore the latest version since it matches the one being used --- cmd/soroban-rpc/internal/integrationtest/migrate_test.go | 5 +++-- cmd/soroban-rpc/internal/integrationtest/upgrade_test.go | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/cmd/soroban-rpc/internal/integrationtest/migrate_test.go b/cmd/soroban-rpc/internal/integrationtest/migrate_test.go index a12eae86..7358bc06 100644 --- a/cmd/soroban-rpc/internal/integrationtest/migrate_test.go +++ b/cmd/soroban-rpc/internal/integrationtest/migrate_test.go @@ -32,8 +32,9 @@ func TestMigrate(t *testing.T) { continue } if originVersion == "22.0.0-rc2" { - // This version of RPC wasn't published without a deb build number suffix. - originVersion = "22.0.0-rc2-100" + // This version of RPC can't be upgraded to since that's the one + // set in the soroban_rpc.yml file + continue } t.Run(originVersion, func(t *testing.T) { testMigrateFromVersion(t, originVersion) diff --git a/cmd/soroban-rpc/internal/integrationtest/upgrade_test.go b/cmd/soroban-rpc/internal/integrationtest/upgrade_test.go index efd26cb2..70f9343a 100644 --- a/cmd/soroban-rpc/internal/integrationtest/upgrade_test.go +++ b/cmd/soroban-rpc/internal/integrationtest/upgrade_test.go @@ -23,10 +23,11 @@ func TestUpgradeFrom20To21(t *testing.T) { test.UploadHelloWorldContract() - // Upgrade to protocol 21 and re-upload the contract, which should cause a caching of the contract - // estimations + // Upgrade to protocol 21 and re-upload the contract, which should cause a + // caching of the contract estimations test.UpgradeProtocol(21) - // Wait for the ledger to advance, so that the simulation library passes the right protocol number + // Wait for the ledger to advance, so that the simulation library passes the + // right protocol number rpcDB := test.GetDaemon().GetDB() initialLedgerSequence, err := db.NewLedgerEntryReader(rpcDB).GetLatestLedgerSequence(context.Background()) require.NoError(t, err)