diff --git a/types/tx.go b/types/tx.go index a4513e6f7..a7b9b1cb2 100644 --- a/types/tx.go +++ b/types/tx.go @@ -243,8 +243,9 @@ func sortedCopy(txs Txs) Txs { // Both lists must be sorted. func containsAnyTxs(a, b []Tx) (int, bool) { aix, bix := 0, 0 + +nextA: for ; aix < len(a); aix++ { - LOOP: for bix < len(b) { switch bytes.Compare(b[bix], a[aix]) { case 0: @@ -259,7 +260,7 @@ func containsAnyTxs(a, b []Tx) (int, bool) { return -1, false } case 1: - break LOOP + continue nextA } } } diff --git a/types/tx_test.go b/types/tx_test.go index c50e51f61..105b03e86 100644 --- a/types/tx_test.go +++ b/types/tx_test.go @@ -158,4 +158,42 @@ func TestValidateTxRecordSet(t *testing.T) { err := txrSet.Validate(100, []Tx{}) require.Error(t, err) }) + t.Run("TxRecordSet preserves order", func(t *testing.T) { + trs := []*abci.TxRecord{ + { + Action: abci.TxRecord_ADDED, + Tx: Tx([]byte{100}), + }, + { + Action: abci.TxRecord_ADDED, + Tx: Tx([]byte{99}), + }, + { + Action: abci.TxRecord_ADDED, + Tx: Tx([]byte{55}), + }, + { + Action: abci.TxRecord_ADDED, + Tx: Tx([]byte{12}), + }, + { + Action: abci.TxRecord_ADDED, + Tx: Tx([]byte{66}), + }, + { + Action: abci.TxRecord_ADDED, + Tx: Tx([]byte{9}), + }, + { + Action: abci.TxRecord_ADDED, + Tx: Tx([]byte{17}), + }, + } + txrSet := NewTxRecordSet(trs) + err := txrSet.Validate(100, []Tx{}) + require.NoError(t, err) + for i, tx := range txrSet.IncludedTxs() { + require.Equal(t, Tx(trs[i].Tx), tx) + } + }) }