Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

protocols/horizon: Change Transaction.AccountSequence to int64 #4409

Merged
merged 6 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clients/horizonclient/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
All notable changes to this project will be documented in this
file. This project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

* Type of `AccountSequence` field in `protocols/horizon.Account` was changed to `int64`.

## [v10.0.0](https://github.com/stellar/go/releases/tag/horizonclient-v10.0.0) - 2022-04-18

Expand Down
2 changes: 1 addition & 1 deletion protocols/horizon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ type Transaction struct {
Account string `json:"source_account"`
AccountMuxed string `json:"account_muxed,omitempty"`
AccountMuxedID uint64 `json:"account_muxed_id,omitempty,string"`
AccountSequence string `json:"source_account_sequence"`
AccountSequence int64 `json:"source_account_sequence,string"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a breaking change to the Go SDK?

Also, we have some other fields like this (that are strings but could be int64s). We should probably do a pass to find them all (this came up briefly during P19).

Copy link
Contributor Author

@bartekn bartekn May 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a breaking change to the Go SDK?

Yes, this is a breaking change. However this will probably allow Go SDK users to remove some conversion code. Are we ok with merging this into master?

Also, we have some other fields like this (that are strings but could be int64s). We should probably do a pass to find them all (this came up briefly during P19).

Sounds good. I changed this one because it simplifies the code in Starbridge. I did a quick pass and couldn't find anything else but if there are other instances of this we should definitely change them to ints.

Copy link
Member

@leighmcculloch leighmcculloch May 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 We should do this. It moves validation of the response data into the SDK so if the response contained a non-integer string the failure would occur at response parsing rather than later on in application code, so this is a good move and I doubt anyone would be disappointed by it. Thanks for shipping it! Let's do this in all the integer fields we can.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a line to horizonclient CHANGELOG for visibility.

FeeAccount string `json:"fee_account"`
FeeAccountMuxed string `json:"fee_account_muxed,omitempty"`
FeeAccountMuxedID uint64 `json:"fee_account_muxed_id,omitempty,string"`
Expand Down
14 changes: 7 additions & 7 deletions services/horizon/internal/actions_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func TestTransactionActions_PostSuccessful(t *testing.T) {

w := ht.Post("/transactions", form)
ht.Assert.Equal(200, w.Code)
ht.Assert.Contains(string(w.Body.Bytes()), `"result_xdr": "AAAAAAAAAGQAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAA="`)
ht.Assert.Contains(w.Body.String(), `"result_xdr": "AAAAAAAAAGQAAAAAAAAAAQAAAAAAAAABAAAAAAAAAAA="`)
}

func TestTransactionActions_PostFailed(t *testing.T) {
Expand All @@ -355,8 +355,8 @@ func TestTransactionActions_PostFailed(t *testing.T) {

w := ht.Post("/transactions", form)
ht.Assert.Equal(400, w.Code)
ht.Assert.Contains(string(w.Body.Bytes()), "op_underfunded")
ht.Assert.Contains(string(w.Body.Bytes()), `"result_xdr": "AAAAAAAAAGT/////AAAAAQAAAAAAAAAB/////gAAAAA="`)
ht.Assert.Contains(w.Body.String(), "op_underfunded")
ht.Assert.Contains(w.Body.String(), `"result_xdr": "AAAAAAAAAGT/////AAAAAQAAAAAAAAAB/////gAAAAA="`)
}

func TestPostFeeBumpTransaction(t *testing.T) {
Expand Down Expand Up @@ -412,14 +412,14 @@ func TestPostFailedFeeBumpTransaction(t *testing.T) {
form := url.Values{"tx": []string{fixture.Transaction.TxEnvelope}}
w := ht.Post("/transactions", form)
ht.Assert.Equal(400, w.Code)
ht.Assert.Contains(string(w.Body.Bytes()), "tx_fee_bump_inner_failed")
ht.Assert.Contains(string(w.Body.Bytes()), "tx_bad_auth")
ht.Assert.Contains(w.Body.String(), "tx_fee_bump_inner_failed")
ht.Assert.Contains(w.Body.String(), "tx_bad_auth")

innerTxEnvelope, err := xdr.MarshalBase64(fixture.Envelope.FeeBump.Tx.InnerTx.V1)
ht.Assert.NoError(err)
form = url.Values{"tx": []string{innerTxEnvelope}}
w = ht.Post("/transactions", form)
ht.Assert.Equal(400, w.Code)
ht.Assert.Contains(string(w.Body.Bytes()), "tx_bad_auth")
ht.Assert.NotContains(string(w.Body.Bytes()), "tx_fee_bump_inner_failed")
ht.Assert.Contains(w.Body.String(), "tx_bad_auth")
ht.Assert.NotContains(w.Body.String(), "tx_fee_bump_inner_failed")
}
4 changes: 2 additions & 2 deletions services/horizon/internal/db2/history/fee_bump_scenario.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func FeeBumpScenario(tt *test.T, q *Q, successful bool) FeeBumpFixture {
LedgerSequence: fixture.Ledger.Sequence,
ApplicationOrder: 1,
Account: account.Address(),
AccountSequence: "97",
AccountSequence: 97,
MaxFee: int64(fixture.Envelope.Fee()),
FeeCharged: int64(resultPair.Result.FeeCharged),
OperationCount: 1,
Expand Down Expand Up @@ -336,7 +336,7 @@ func FeeBumpScenario(tt *test.T, q *Q, successful bool) FeeBumpFixture {
LedgerSequence: fixture.Ledger.Sequence,
ApplicationOrder: 1,
Account: "GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY",
AccountSequence: "78621794419880145",
AccountSequence: 78621794419880145,
MaxFee: 200,
FeeCharged: 300,
OperationCount: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/base64"
"encoding/hex"
"fmt"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -121,7 +120,7 @@ type TransactionWithoutLedger struct {
ApplicationOrder int32 `db:"application_order"`
Account string `db:"account"`
AccountMuxed null.String `db:"account_muxed"`
AccountSequence string `db:"account_sequence"`
AccountSequence int64 `db:"account_sequence"`
MaxFee int64 `db:"max_fee"`
FeeCharged int64 `db:"fee_charged"`
OperationCount int32 `db:"operation_count"`
Expand Down Expand Up @@ -179,7 +178,7 @@ func transactionToRow(transaction ingest.LedgerTransaction, sequence uint32, enc
ApplicationOrder: int32(transaction.Index),
Account: account.Address(),
AccountMuxed: accountMuxed,
AccountSequence: strconv.FormatInt(transaction.Envelope.SeqNum(), 10),
AccountSequence: transaction.Envelope.SeqNum(),
MaxFee: int64(transaction.Envelope.Fee()),
FeeCharged: int64(transaction.Result.Result.FeeCharged),
OperationCount: int32(len(transaction.Envelope.Operations())),
Expand Down
26 changes: 13 additions & 13 deletions services/horizon/internal/db2/history/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func TestInsertTransaction(t *testing.T) {
LedgerSequence: ledger.Sequence,
ApplicationOrder: 1,
Account: "GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY",
AccountSequence: "78621794419880145",
AccountSequence: 78621794419880145,
MaxFee: 200,
FeeCharged: 300,
OperationCount: 1,
Expand Down Expand Up @@ -385,7 +385,7 @@ func TestInsertTransaction(t *testing.T) {
LedgerSequence: ledger.Sequence,
ApplicationOrder: 1,
Account: "GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY",
AccountSequence: "78621794419880145",
AccountSequence: 78621794419880145,
MaxFee: 200,
FeeCharged: 300,
OperationCount: 1,
Expand Down Expand Up @@ -422,7 +422,7 @@ func TestInsertTransaction(t *testing.T) {
LedgerSequence: ledger.Sequence,
ApplicationOrder: 1,
Account: "GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY",
AccountSequence: "78621794419880145",
AccountSequence: 78621794419880145,
MaxFee: 200,
FeeCharged: 123,
OperationCount: 1,
Expand Down Expand Up @@ -459,7 +459,7 @@ func TestInsertTransaction(t *testing.T) {
LedgerSequence: ledger.Sequence,
ApplicationOrder: 1,
Account: "GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY",
AccountSequence: "78621794419880145",
AccountSequence: 78621794419880145,
// set max fee to a value larger than MAX_INT32 but less than or equal to MAX_UINT32
MaxFee: 2500000000,
FeeCharged: int64(1 << 33),
Expand Down Expand Up @@ -497,7 +497,7 @@ func TestInsertTransaction(t *testing.T) {
LedgerSequence: ledger.Sequence,
ApplicationOrder: 1,
Account: "GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY",
AccountSequence: "78621794419880145",
AccountSequence: 78621794419880145,
MaxFee: 200,
FeeCharged: 300,
OperationCount: 1,
Expand Down Expand Up @@ -534,7 +534,7 @@ func TestInsertTransaction(t *testing.T) {
LedgerSequence: ledger.Sequence,
ApplicationOrder: 1,
Account: "GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY",
AccountSequence: "78621794419880145",
AccountSequence: 78621794419880145,
MaxFee: 200,
FeeCharged: 300,
OperationCount: 1,
Expand Down Expand Up @@ -571,7 +571,7 @@ func TestInsertTransaction(t *testing.T) {
LedgerSequence: ledger.Sequence,
ApplicationOrder: 1,
Account: "GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY",
AccountSequence: "78621794419880145",
AccountSequence: 78621794419880145,
MaxFee: 200,
FeeCharged: 300,
OperationCount: 1,
Expand Down Expand Up @@ -608,7 +608,7 @@ func TestInsertTransaction(t *testing.T) {
LedgerSequence: ledger.Sequence,
ApplicationOrder: 1,
Account: "GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY",
AccountSequence: "78621794419880145",
AccountSequence: 78621794419880145,
MaxFee: 200,
FeeCharged: 300,
OperationCount: 1,
Expand Down Expand Up @@ -646,7 +646,7 @@ func TestInsertTransaction(t *testing.T) {
LedgerSequence: ledger.Sequence,
ApplicationOrder: 1,
Account: "GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY",
AccountSequence: "123456",
AccountSequence: 123456,
MaxFee: 100,
FeeCharged: 300,
OperationCount: 1,
Expand Down Expand Up @@ -683,7 +683,7 @@ func TestInsertTransaction(t *testing.T) {
LedgerSequence: ledger.Sequence,
ApplicationOrder: 1,
Account: "GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY",
AccountSequence: "123456",
AccountSequence: 123456,
MaxFee: 100,
FeeCharged: 300,
OperationCount: 1,
Expand Down Expand Up @@ -720,7 +720,7 @@ func TestInsertTransaction(t *testing.T) {
LedgerSequence: ledger.Sequence,
ApplicationOrder: 1,
Account: "GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY",
AccountSequence: "123456",
AccountSequence: 123456,
MaxFee: 100,
FeeCharged: 300,
OperationCount: 1,
Expand Down Expand Up @@ -760,7 +760,7 @@ func TestInsertTransaction(t *testing.T) {
LedgerSequence: ledger.Sequence,
ApplicationOrder: 1,
Account: "GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3",
AccountSequence: "1",
AccountSequence: 1,
MaxFee: 100,
FeeCharged: 300,
OperationCount: 1,
Expand Down Expand Up @@ -800,7 +800,7 @@ func TestInsertTransaction(t *testing.T) {
LedgerSequence: ledger.Sequence,
ApplicationOrder: 1,
Account: "GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY",
AccountSequence: "123456",
AccountSequence: 123456,
MaxFee: 200,
FeeCharged: 300,
OperationCount: 2,
Expand Down
2 changes: 1 addition & 1 deletion services/horizon/internal/db2/history/txsub_result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestTxSubResult(t *testing.T) {
LedgerSequence: int32(sequence),
ApplicationOrder: 1,
Account: "GAUJETIZVEP2NRYLUESJ3LS66NVCEGMON4UDCBCSBEVPIID773P2W6AY",
AccountSequence: "78621794419880145",
AccountSequence: 78621794419880145,
MaxFee: 200,
FeeCharged: 300,
OperationCount: 1,
Expand Down
3 changes: 1 addition & 2 deletions services/horizon/internal/integration/txsub_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package integration

import (
"strconv"
"sync"
"testing"

Expand Down Expand Up @@ -58,7 +57,7 @@ func TestTxsub(t *testing.T) {
tt.Equal(accounts[i].GetAccountID(), txResp.Account)
seq, err := account.GetSequenceNumber()
assert.NoError(t, err)
tt.Equal(strconv.FormatInt(seq, 10), txResp.AccountSequence)
tt.Equal(seq, txResp.AccountSequence)
t.Logf("%d/%d done", i, j)
}(i, j, account)
}
Expand Down
20 changes: 12 additions & 8 deletions services/horizon/internal/resourceadapter/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import (
)

func TestNewOperationAllTypesCovered(t *testing.T) {
tx := &history.Transaction{}
for typ, s := range xdr.OperationTypeToStringMap {
row := history.Operation{
Type: xdr.OperationType(typ),
}
op, err := NewOperation(context.Background(), row, "foo", &history.Transaction{}, history.Ledger{})
op, err := NewOperation(context.Background(), row, "foo", tx, history.Ledger{})
assert.NoError(t, err, s)
// if we got a base type, the operation is not covered
if _, ok := op.(operations.Base); ok {
Expand All @@ -30,7 +31,7 @@ func TestNewOperationAllTypesCovered(t *testing.T) {
row := history.Operation{
Type: xdr.OperationType(200000),
}
op, err := NewOperation(context.Background(), row, "foo", &history.Transaction{}, history.Ledger{})
op, err := NewOperation(context.Background(), row, "foo", tx, history.Ledger{})
assert.NoError(t, err)
assert.IsType(t, op, operations.Base{})

Expand Down Expand Up @@ -82,9 +83,10 @@ func TestPopulateOperation_WithTransaction(t *testing.T) {
operationsRow = history.Operation{TransactionSuccessful: true}
transactionRow = history.Transaction{
TransactionWithoutLedger: history.TransactionWithoutLedger{
Successful: true,
MaxFee: 10000,
FeeCharged: 100,
Successful: true,
MaxFee: 10000,
FeeCharged: 100,
AccountSequence: 1,
},
}

Expand Down Expand Up @@ -295,9 +297,10 @@ func getJSONResponse(typ xdr.OperationType, details string) (rsp map[string]inte
ctx, _ := test.ContextWithLogBuffer()
transactionRow := history.Transaction{
TransactionWithoutLedger: history.TransactionWithoutLedger{
Successful: true,
MaxFee: 10000,
FeeCharged: 100,
Successful: true,
MaxFee: 10000,
FeeCharged: 100,
AccountSequence: 1,
},
}
operationsRow := history.Operation{
Expand Down Expand Up @@ -330,6 +333,7 @@ func TestFeeBumpOperation(t *testing.T) {
TransactionHash: "cebb875a00ff6e1383aef0fd251a76f22c1f9ab2a2dffcb077855736ade2659a",
FeeAccount: null.StringFrom("GCXKG6RN4ONIEPCMNFB732A436Z5PNDSRLGWK7GBLCMQLIFO4S7EYWVU"),
Account: "GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H",
AccountSequence: 1,
NewMaxFee: null.IntFrom(10000),
InnerTransactionHash: null.StringFrom("2374e99349b9ef7dba9a5db3339b78fda8f34777b1af33ba468ad5c0df946d4d"),
Signatures: []string{"a", "b", "c"},
Expand Down
2 changes: 2 additions & 0 deletions services/horizon/internal/resourceadapter/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ func TestPopulateTransaction_PreconditionsV2_Omissions(t *testing.T) {
MinAccountSequenceAge: null.StringFrom("0"),
ExtraSigners: pq.StringArray{},
}, {
AccountSequence: 1,
MinAccountSequenceLedgerGap: null.IntFrom(0),
TimeBounds: history.TimeBounds{Null: true},
LedgerBounds: history.LedgerBounds{Null: true},
Expand Down Expand Up @@ -368,6 +369,7 @@ func TestFeeBumpTransaction(t *testing.T) {
FeeAccount: null.StringFrom("GA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVSGZ"),
FeeAccountMuxed: null.StringFrom("MA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJUAAAAAAAAAAAACJUQ"),
Account: "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY",
AccountSequence: 1,
AccountMuxed: null.StringFrom("MAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSAAAAAAAAAAE2LP26"),
NewMaxFee: null.IntFrom(10000),
InnerTransactionHash: null.StringFrom("2374e99349b9ef7dba9a5db3339b78fda8f34777b1af33ba468ad5c0df946d4d"),
Expand Down