Merge pull request #11365 from saubyk/7316-listchaintxns-reverse
What changed, and why it matters
This commit adds a new optional 'reverse' flag to the lncli listchaintxns and GetTransactions RPC that lets users list wallet transactions oldest-first instead of newest-first. It also fixes a minor ordering stability issue so transactions in the same block now appear in a predictable order. There is no security vulnerability here; it is a user-facing feature and small bug-fix for transaction listing.
No security action required. Treat as a normal feature/bug-fix release. Operators and integrators may want to update client code to take advantage of the new reverse flag and deterministic ordering, but no mitigation is needed.
Security signals we found
No input validation changes that could introduce injection or parsing issues
No privilege or authorization changes
No cryptographic or wallet-balance logic changes
New boolean flag is passed through to a stable sort comparator
Release notes describe the change as a bug fix and feature addition, not a security fix
Evidence from the diff
The change introduces a boolean reverse field to GetTransactionsRequest, propagates it through the RPC/CLI layers, and uses sort.SliceStable in RPCTransactionDetails to produce deterministic ordering for transactions with equal confirmation counts. The wallet layer’s pagination logic is unchanged; only the presentation order of the returned page is affected. Existing callers (e.g., ListSweeps) pass false to preserve prior behavior. The release notes explicitly frame this as a bug fix for unstable ordering plus a new feature for reverse ordering.
Changed components
lnrpc/lightning.protolnrpc/lightning.pb.golnrpc/lightning.swagger.jsonlnrpc/rpc_utils.golnrpc/rpc_utils_test.golnrpc/walletrpc/walletkit_server.gocmd/commands/commands.gorpcserver.golnwallet/btcwallet/btcwallet.golnwallet/interface.goInspect captured patch +353 / −37
### cmd/commands/commands.go
@@ -2287,6 +2287,13 @@ var listChainTxnsCommand = cli.Command{
"all transactions",
Value: 0,
},
+ cli.BoolFlag{
+ Name: "reverse",
+ Usage: "if set, the transactions will be " +
+ "returned in reverse order, with the " +
+ "oldest confirmed transaction first and " +
+ "unconfirmed transactions last",
+ },
},
Description: `
List all transactions an address of the wallet was involved in.
@@ -2295,7 +2302,12 @@ var listChainTxnsCommand = cli.Command{
to an address our wallet controls, or spent utxos that we held.
By default, this call will get all transactions until the chain tip,
- including unconfirmed transactions (end_height=-1).`,
+ including unconfirmed transactions (end_height=-1).
+
+ The default ordering lists unconfirmed transactions first, followed by
+ the most recent confirmed transactions down to the oldest. Use the
+ reverse flag to list the oldest confirmed transaction first instead,
+ with unconfirmed transactions last.`,
Action: actionDecorator(listChainTxns),
}
@@ -2337,6 +2349,7 @@ func listChainTxns(ctx *cli.Context) error {
MaxTransactions: uint32(ctx.Uint64("max_transactions")),
StartHeight: startHeight,
EndHeight: endHeight,
+ Reverse: ctx.Bool("reverse"),
}
resp, err := client.GetTransactions(ctxc, req)
### docs/release-notes/unreleased/11365.md
@@ -0,0 +1,27 @@
+# Bug Fixes
+
+* The ordering of the transactions returned by `GetTransactions` and
+ `lncli listchaintxns` is now
+ [guaranteed to be stable](https://github.com/lightningnetwork/lnd/pull/11365):
+ transactions with the same number of confirmations (e.g. transactions in the
+ same block, or several unconfirmed transactions) keep their relative order,
+ so the order within a page is deterministic. The default ordering itself is
+ unchanged.
+
+# New Features
+
+## RPC Additions
+
+* The `GetTransactions` RPC now accepts a
+ [`reverse` flag](https://github.com/lightningnetwork/lnd/pull/11365) to
+ return wallet transactions oldest-first, with unconfirmed transactions last.
+ Previously, transactions were always returned newest-first
+ ([#7316](https://github.com/lightningnetwork/lnd/issues/7316)). The flag only
+ changes the order of the transactions within the response; pagination
+ selects the same page either way.
+
+## lncli Additions
+
+* `lncli listchaintxns` gained a
+ [`--reverse` flag](https://github.com/lightningnetwork/lnd/pull/11365) that
+ exposes the new `GetTransactions` ordering option.
### lnrpc/lightning.pb.go
@@ -2399,14 +2399,23 @@ type GetTransactionsRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
//
//The height from which to list transactions, inclusive. If this value is
- //greater than end_height, transactions will be read in reverse.
+ //greater than end_height, the wallet reads the blocks in reverse, so
+ //pagination (index_offset/max_transactions) walks the result set starting
+ //from the newest transaction rather than the oldest. For this comparison
+ //an end_height of -1 counts as the chain tip, not as a negative height,
+ //so start_height=0 with end_height=-1 (or an omitted end_height) walks
+ //the result set from the oldest transaction. The ordering of the
+ //transactions within the response is governed by the reverse flag either
+ //way.
StartHeight int32 `protobuf:"varint,1,opt,name=start_height,json=startHeight,proto3" json:"start_height,omitempty"`
//
//The height until which to list transactions, inclusive. To include
//unconfirmed transactions, this value should be set to -1, which will
//return transactions from start_height until the current chain tip and
//unconfirmed transactions. If no end_height is provided, the call will
- //default to this option.
+ //default to this option. A value of -1 is treated as the chain tip when
+ //determining the read direction described for start_height, so it never
+ //causes the blocks to be read in reverse on its own.
EndHeight int32 `protobuf:"varint,2,opt,name=end_height,json=endHeight,proto3" json:"end_height,omitempty"`
// An optional filter to only include transactions relevant to an account.
Account string `protobuf:"bytes,3,opt,name=account,proto3" json:"account,omitempty"`
@@ -2418,8 +2427,26 @@ type GetTransactionsRequest struct {
//The maximal number of transactions returned in the response to this query.
//This value should be set to 0 to return all transactions.
MaxTransactions uint32 `protobuf:"varint,5,opt,name=max_transactions,json=maxTransactions,proto3" json:"max_transactions,omitempty"`
- unknownFields protoimpl.UnknownFields
- sizeCache protoimpl.SizeCache
+ //
+ //If set, the transactions will be returned in reverse order, with the
+ //oldest transaction first and unconfirmed transactions last. Otherwise,
+ //the default ordering is used, which lists unconfirmed transactions
+ //first, followed by the most recent confirmed transactions down to the
+ //oldest. Transactions with the same number of confirmations (e.g. several
+ //transactions in the same block, or several unconfirmed transactions)
+ //keep the order produced by the wallet in both modes, so the reverse
+ //ordering is not an exact mirror of the default one for such ties.
+ //
+ //This flag does not affect which transactions are selected: pagination
+ //(index_offset/max_transactions) walks the result set starting from the
+ //oldest transaction (or from the newest when start_height is greater
+ //than end_height), regardless of this flag, so the same page is selected
+ //either way; only the order of the transactions within the response
+ //changes. This flag only applies to GetTransactions and is ignored by
+ //SubscribeTransactions.
+ Reverse bool `protobuf:"varint,6,opt,name=reverse,proto3" json:"reverse,omitempty"`
+ unknownFields protoimpl.UnknownFields
+ sizeCache protoimpl.SizeCache
}
func (x *GetTransactionsRequest) Reset() {
@@ -2487,6 +2514,13 @@ func (x *GetTransactionsRequest) GetMaxTransactions() uint32 {
return 0
}
+func (x *GetTransactionsRequest) GetReverse() bool {
+ if x != nil {
+ return x.Reverse
+ }
+ return false
+}
+
type TransactionDetails struct {
state protoimpl.MessageState `protogen:"open.v1"`
// The list of transactions relevant to the wallet.
@@ -18944,14 +18978,15 @@ const file_lightning_proto_rawDesc = "" +
"raw_tx_hex\x18\t \x01(\tR\brawTxHex\x12\x14\n" +
"\x05label\x18\n" +
" \x01(\tR\x05label\x12F\n" +
- "\x12previous_outpoints\x18\f \x03(\v2\x17.lnrpc.PreviousOutPointR\x11previousOutpoints\"\xc2\x01\n" +
+ "\x12previous_outpoints\x18\f \x03(\v2\x17.lnrpc.PreviousOutPointR\x11previousOutpoints\"\xdc\x01\n" +
"\x16GetTransactionsRequest\x12!\n" +
"\fstart_height\x18\x01 \x01(\x05R\vstartHeight\x12\x1d\n" +
"\n" +
"end_height\x18\x02 \x01(\x05R\tendHeight\x12\x18\n" +
"\aaccount\x18\x03 \x01(\tR\aaccount\x12!\n" +
"\findex_offset\x18\x04 \x01(\rR\vindexOffset\x12)\n" +
- "\x10max_transactions\x18\x05 \x01(\rR\x0fmaxTransactions\"\x8c\x01\n" +
+ "\x10max_transactions\x18\x05 \x01(\rR\x0fmaxTransactions\x12\x18\n" +
+ "\areverse\x18\x06 \x01(\bR\areverse\"\x8c\x01\n" +
"\x12TransactionDetails\x126\n" +
"\ftransactions\x18\x01 \x03(\v2\x12.lnrpc.TransactionR\ftransactions\x12\x1d\n" +
"\n" +
### lnrpc/lightning.proto
@@ -795,7 +795,14 @@ message Transaction {
message GetTransactionsRequest {
/*
The height from which to list transactions, inclusive. If this value is
- greater than end_height, transactions will be read in reverse.
+ greater than end_height, the wallet reads the blocks in reverse, so
+ pagination (index_offset/max_transactions) walks the result set starting
+ from the newest transaction rather than the oldest. For this comparison
+ an end_height of -1 counts as the chain tip, not as a negative height,
+ so start_height=0 with end_height=-1 (or an omitted end_height) walks
+ the result set from the oldest transaction. The ordering of the
+ transactions within the response is governed by the reverse flag either
+ way.
*/
int32 start_height = 1;
@@ -804,7 +811,9 @@ message GetTransactionsRequest {
unconfirmed transactions, this value should be set to -1, which will
return transactions from start_height until the current chain tip and
unconfirmed transactions. If no end_height is provided, the call will
- default to this option.
+ default to this option. A value of -1 is treated as the chain tip when
+ determining the read direction described for start_height, so it never
+ causes the blocks to be read in reverse on its own.
*/
int32 end_height = 2;
@@ -822,6 +831,26 @@ message GetTransactionsRequest {
This value should be set to 0 to return all transactions.
*/
uint32 max_transactions = 5;
+
+ /*
+ If set, the transactions will be returned in reverse order, with the
+ oldest transaction first and unconfirmed transactions last. Otherwise,
+ the default ordering is used, which lists unconfirmed transactions
+ first, followed by the most recent confirmed transactions down to the
+ oldest. Transactions with the same number of confirmations (e.g. several
+ transactions in the same block, or several unconfirmed transactions)
+ keep the order produced by the wallet in both modes, so the reverse
+ ordering is not an exact mirror of the default one for such ties.
+
+ This flag does not affect which transactions are selected: pagination
+ (index_offset/max_transactions) walks the result set starting from the
+ oldest transaction (or from the newest when start_height is greater
+ than end_height), regardless of this flag, so the same page is selected
+ either way; only the order of the transactions within the response
+ changes. This flag only applies to GetTransactions and is ignored by
+ SubscribeTransactions.
+ */
+ bool reverse = 6;
}
message TransactionDetails {
### lnrpc/lightning.swagger.json
@@ -2665,15 +2665,15 @@
"parameters": [
{
"name": "start_height",
- "description": "The height from which to list transactions, inclusive. If this value is\ngreater than end_height, transactions will be read in reverse.",
+ "description": "The height from which to list transactions, inclusive. If this value is\ngreater than end_height, the wallet reads the blocks in reverse, so\npagination (index_offset/max_transactions) walks the result set starting\nfrom the newest transaction rather than the oldest. For this comparison\nan end_height of -1 counts as the chain tip, not as a negative height,\nso start_height=0 with end_height=-1 (or an omitted end_height) walks\nthe result set from the oldest transaction. The ordering of the\ntransactions within the response is governed by the reverse flag either\nway.",
"in": "query",
"required": false,
"type": "integer",
"format": "int32"
},
{
"name": "end_height",
- "description": "The height until which to list transactions, inclusive. To include\nunconfirmed transactions, this value should be set to -1, which will\nreturn transactions from start_height until the current chain tip and\nunconfirmed transactions. If no end_height is provided, the call will\ndefault to this option.",
+ "description": "The height until which to list transactions, inclusive. To include\nunconfirmed transactions, this value should be set to -1, which will\nreturn transactions from start_height until the current chain tip and\nunconfirmed transactions. If no end_height is provided, the call will\ndefault to this option. A value of -1 is treated as the chain tip when\ndetermining the read direction described for start_height, so it never\ncauses the blocks to be read in reverse on its own.",
"in": "query",
"required": false,
"type": "integer",
@@ -2701,6 +2701,13 @@
"required": false,
"type": "integer",
"format": "int64"
+ },
+ {
+ "name": "reverse",
+ "description": "If set, the transactions will be returned in reverse order, with the\noldest transaction first and unconfirmed transactions last. Otherwise,\nthe default ordering is used, which lists unconfirmed transactions\nfirst, followed by the most recent confirmed transactions down to the\noldest. Transactions with the same number of confirmations (e.g. several\ntransactions in the same block, or several unconfirmed transactions)\nkeep the order produced by the wallet in both modes, so the reverse\nordering is not an exact mirror of the default one for such ties.\n\nThis flag does not affect which transactions are selected: pagination\n(index_offset/max_transactions) walks the result set starting from the\noldest transaction (or from the newest when start_height is greater\nthan end_height), regardless of this flag, so the same page is selected\neither way; only the order of the transactions within the response\nchanges. This flag only applies to GetTransactions and is ignored by\nSubscribeTransactions.",
+ "in": "query",
+ "required": false,
+ "type": "boolean"
}
],
"tags": [
@@ -2871,15 +2878,15 @@
"parameters": [
{
"name": "start_height",
- "description": "The height from which to list transactions, inclusive. If this value is\ngreater than end_height, transactions will be read in reverse.",
+ "description": "The height from which to list transactions, inclusive. If this value is\ngreater than end_height, the wallet reads the blocks in reverse, so\npagination (index_offset/max_transactions) walks the result set starting\nfrom the newest transaction rather than the oldest. For this comparison\nan end_height of -1 counts as the chain tip, not as a negative height,\nso start_height=0 with end_height=-1 (or an omitted end_height) walks\nthe result set from the oldest transaction. The ordering of the\ntransactions within the response is governed by the reverse flag either\nway.",
"in": "query",
"required": false,
"type": "integer",
"format": "int32"
},
{
"name": "end_height",
- "description": "The height until which to list transactions, inclusive. To include\nunconfirmed transactions, this value should be set to -1, which will\nreturn transactions from start_height until the current chain tip and\nunconfirmed transactions. If no end_height is provided, the call will\ndefault to this option.",
+ "description": "The height until which to list transactions, inclusive. To include\nunconfirmed transactions, this value should be set to -1, which will\nreturn transactions from start_height until the current chain tip and\nunconfirmed transactions. If no end_height is provided, the call will\ndefault to this option. A value of -1 is treated as the chain tip when\ndetermining the read direction described for start_height, so it never\ncauses the blocks to be read in reverse on its own.",
"in": "query",
"required": false,
"type": "integer",
@@ -2907,6 +2914,13 @@
"required": false,
"type": "integer",
"format": "int64"
+ },
+ {
+ "name": "reverse",
+ "description": "If set, the transactions will be returned in reverse order, with the\noldest transaction first and unconfirmed transactions last. Otherwise,\nthe default ordering is used, which lists unconfirmed transactions\nfirst, followed by the most recent confirmed transactions down to the\noldest. Transactions with the same number of confirmations (e.g. several\ntransactions in the same block, or several unconfirmed transactions)\nkeep the order produced by the wallet in both modes, so the reverse\nordering is not an exact mirror of the default one for such ties.\n\nThis flag does not affect which transactions are selected: pagination\n(index_offset/max_transactions) walks the result set starting from the\noldest transaction (or from the newest when start_height is greater\nthan end_height), regardless of this flag, so the same page is selected\neither way; only the order of the transactions within the response\nchanges. This flag only applies to GetTransactions and is ignored by\nSubscribeTransactions.",
+ "in": "query",
+ "required": false,
+ "type": "boolean"
}
],
"tags": [
### lnrpc/rpc_utils.go
@@ -116,9 +116,22 @@ func RPCTransaction(tx *lnwallet.TransactionDetail) *Transaction {
}
}
-// RPCTransactionDetails returns a set of rpc transaction details.
+// RPCTransactionDetails returns a set of rpc transaction details. If reverse
+// is false, the transactions are sorted by number of confirmations in
+// ascending order, which puts unconfirmed transactions first, followed by the
+// most recent confirmed transactions down to the oldest. If reverse is true,
+// the transactions are sorted in descending order instead, which puts the
+// oldest confirmed transactions first and unconfirmed transactions last.
+//
+// NOTE: The sort is stable so that transactions with an equal number of
+// confirmations (e.g. several transactions in the same block or several
+// unconfirmed transactions) keep their relative order, giving the returned
+// page a deterministic order. Such ties keep the wallet order in both modes,
+// so the reverse ordering is not an exact mirror of the default one for them.
+// Pagination (index_offset/max_transactions) is applied by the wallet layer
+// before this sort and is unaffected by it.
func RPCTransactionDetails(txns []*lnwallet.TransactionDetail, firstIdx,
- lastIdx uint64) *TransactionDetails {
+ lastIdx uint64, reverse bool) *TransactionDetails {
txDetails := &TransactionDetails{
Transactions: make([]*Transaction, len(txns)),
@@ -130,12 +143,12 @@ func RPCTransactionDetails(txns []*lnwallet.TransactionDetail, firstIdx,
txDetails.Transactions[i] = RPCTransaction(tx)
}
- // Sort transactions by number of confirmations rather than height so
- // that unconfirmed transactions (height =0; confirmations =-1) will
- // follow the most recently set of confirmed transactions. If we sort
- // by height, unconfirmed transactions will follow our oldest
- // transactions, because they have lower block heights.
- sort.Slice(txDetails.Transactions, func(i, j int) bool {
+ sort.SliceStable(txDetails.Transactions, func(i, j int) bool {
+ if reverse {
+ return txDetails.Transactions[i].NumConfirmations >
+ txDetails.Transactions[j].NumConfirmations
+ }
+
return txDetails.Transactions[i].NumConfirmations <
txDetails.Transactions[j].NumConfirmations
})
### lnrpc/rpc_utils_test.go
@@ -0,0 +1,167 @@
+package lnrpc
+
+import (
+ "fmt"
+ "strings"
+ "testing"
+
+ "github.com/btcsuite/btcd/chainhash/v2"
+ "github.com/lightningnetwork/lnd/lnwallet"
+ "github.com/stretchr/testify/require"
+)
+
+// chainHeight is the height of the current chain tip used by the ordering
+// tests.
+const chainHeight = 110
+
+// txHash returns a 64 character hex transaction hash with the given two
+// character hex prefix, so transactions are easy to tell apart in test
+// failures.
+func txHash(prefix string) string {
+ return strings.Repeat(prefix, 32)
+}
+
+// blockHash returns a deterministic block hash for the given block height,
+// so transactions in the same block share the same block hash.
+func blockHash(t *testing.T, height int32) *chainhash.Hash {
+ h, err := chainhash.NewHashFromStr(
+ strings.Repeat(fmt.Sprintf("%02x", height), 32),
+ )
+ require.NoError(t, err)
+
+ return h
+}
+
+// newTxDetail returns a transaction detail for a transaction with the given
+// hash and number of confirmations. Unconfirmed transactions report zero
+// confirmations, confirmed ones are placed in a block relative to the chain
+// tip.
+func newTxDetail(t *testing.T, hash string,
+ confs int32) *lnwallet.TransactionDetail {
+
+ h, err := chainhash.NewHashFromStr(hash)
+ require.NoError(t, err)
+
+ detail := &lnwallet.TransactionDetail{
+ Hash: *h,
+ NumConfirmations: confs,
+ OutputDetails: []lnwallet.OutputDetail{},
+ PreviousOutpoints: []lnwallet.PreviousOutPoint{},
+ }
+
+ if confs > 0 {
+ detail.BlockHeight = chainHeight - confs + 1
+ detail.BlockHash = blockHash(t, detail.BlockHeight)
+ }
+
+ return detail
+}
+
+// txHashes returns the hashes of the response transactions in the order
+// they appear in.
+func txHashes(resp *TransactionDetails) []string {
+ hashes := make([]string, 0, len(resp.Transactions))
+ for _, tx := range resp.Transactions {
+ hashes = append(hashes, tx.TxHash)
+ }
+
+ return hashes
+}
+
+// TestRPCTransactionDetailsOrdering asserts the exact ordering of the
+// transactions returned by RPCTransactionDetails, for both the default and
+// the reverse ordering.
+//
+// The default ordering lists unconfirmed transactions first, followed by the
+// most recent confirmed transactions down to the oldest. The reverse ordering
+// lists the oldest confirmed transactions first, up to the most recent one,
+// with unconfirmed transactions last. Transactions sharing the same number of
+// confirmations (e.g. transactions in the same block, or unconfirmed
+// transactions) keep their wallet order in both orderings, so the order
+// within a returned page is deterministic and the reverse ordering is not an
+// exact mirror of the default one for such ties.
+//
+// The first and last index of the page are passed through unmodified in both
+// orderings, as pagination is applied by the wallet layer before
+// RPCTransactionDetails is invoked and is independent of the ordering.
+func TestRPCTransactionDetailsOrdering(t *testing.T) {
+ t.Parallel()
+
+ // The fixture mimics the ordering produced by the wallet layer:
+ // confirmed transactions from the oldest block to the newest, with
+ // unconfirmed transactions last.
+ //
+ // It is deliberately tie-heavy and larger than the threshold below
+ // which Go's unstable sort.Slice happens to be stable (it falls back
+ // to insertion sort for 12 or fewer elements), so that an unstable
+ // sort would reorder the ties and fail the ordering assertions.
+ txns := []*lnwallet.TransactionDetail{
+ // Oldest block, four transactions.
+ newTxDetail(t, txHash("a1"), 10),
+ newTxDetail(t, txHash("a2"), 10),
+ newTxDetail(t, txHash("a3"), 10),
+ newTxDetail(t, txHash("a4"), 10),
+
+ // A single transaction in a later block.
+ newTxDetail(t, txHash("b1"), 7),
+
+ // Another block with four transactions.
+ newTxDetail(t, txHash("c1"), 5),
+ newTxDetail(t, txHash("c2"), 5),
+ newTxDetail(t, txHash("c3"), 5),
+ newTxDetail(t, txHash("c4"), 5),
+
+ // Tip block, four transactions.
+ newTxDetail(t, txHash("d1"), 1),
+ newTxDetail(t, txHash("d2"), 1),
+ newTxDetail(t, txHash("d3"), 1),
+ newTxDetail(t, txHash("d4"), 1),
+
+ // Unconfirmed transactions.
+ newTxDetail(t, txHash("e1"), 0),
+ newTxDetail(t, txHash("e2"), 0),
+ newTxDetail(t, txHash("e3"), 0),
+ newTxDetail(t, txHash("e4"), 0),
+ }
+
+ // Mimic a page cut by the wallet layer with a nonzero index offset to
+ // assert the indexes are passed through unmodified.
+ const (
+ firstIdx = 3
+ lastIdx = firstIdx + 16
+ )
+ require.Len(t, txns, lastIdx-firstIdx+1)
+
+ // The default ordering lists unconfirmed transactions first, then the
+ // most recently confirmed transactions down to the oldest.
+ // Transactions sharing a block, and the unconfirmed transactions,
+ // keep their wallet order.
+ defaultOrder := []string{
+ txHash("e1"), txHash("e2"), txHash("e3"), txHash("e4"),
+ txHash("d1"), txHash("d2"), txHash("d3"), txHash("d4"),
+ txHash("c1"), txHash("c2"), txHash("c3"), txHash("c4"),
+ txHash("b1"),
+ txHash("a1"), txHash("a2"), txHash("a3"), txHash("a4"),
+ }
+
+ resp := RPCTransactionDetails(txns, firstIdx, lastIdx, false)
+ require.Equal(t, defaultOrder, txHashes(resp))
+ require.EqualValues(t, firstIdx, resp.FirstIndex)
+ require.EqualValues(t, lastIdx, resp.LastIndex)
+
+ // The reverse ordering lists the oldest confirmed transactions first,
+ // up to the most recent one, with unconfirmed transactions last. Ties
+ // keep their wallet order here as well, so e.g. a1 still precedes a2.
+ reverseOrder := []string{
+ txHash("a1"), txHash("a2"), txHash("a3"), txHash("a4"),
+ txHash("b1"),
+ txHash("c1"), txHash("c2"), txHash("c3"), txHash("c4"),
+ txHash("d1"), txHash("d2"), txHash("d3"), txHash("d4"),
+ txHash("e1"), txHash("e2"), txHash("e3"), txHash("e4"),
+ }
+
+ resp = RPCTransactionDetails(txns, firstIdx, lastIdx, true)
+ require.Equal(t, reverseOrder, txHashes(resp))
+ require.EqualValues(t, firstIdx, resp.FirstIndex)
+ require.EqualValues(t, lastIdx, resp.LastIndex)
+}
### lnrpc/walletrpc/walletkit_server.go
@@ -1618,7 +1618,7 @@ func (w *WalletKit) ListSweeps(ctx context.Context,
return &ListSweepsResponse{
Sweeps: &ListSweepsResponse_TransactionDetails{
TransactionDetails: lnrpc.RPCTransactionDetails(
- txDetails, firstIdx, lastIdx,
+ txDetails, firstIdx, lastIdx, false,
),
},
}, nil
### lnwallet/btcwallet/btcwallet.go
@@ -1758,14 +1758,20 @@ func transactionDetailsPage(txDetails []*lnwallet.TransactionDetail,
}
// ListTransactionDetails returns a list of all transactions which are relevant
-// to the wallet over [startHeight;endHeight]. If start height is greater than
-// end height, the transactions will be retrieved in reverse order. To include
-// unconfirmed transactions, endHeight should be set to the special value -1.
-// This will return transactions from the tip of the chain until the start
-// height (inclusive) and unconfirmed transactions. The account parameter serves
-// as a filter to retrieve the transactions relevant to a specific account. When
+// to the wallet over [startHeight;endHeight]. To include unconfirmed
+// transactions, endHeight should be set to the special value -1. This will
+// return transactions from the tip of the chain until the start height
+// (inclusive) and unconfirmed transactions. The account parameter serves as
+// a filter to retrieve the transactions relevant to a specific account. When
// empty, transactions of all wallet accounts are returned.
//
+// The returned confirmed transactions are ordered from the oldest to the
+// newest when startHeight is not greater than endHeight. If startHeight is
+// greater than endHeight, the blocks are read in reverse and the confirmed
+// transactions are ordered from the newest to the oldest instead. Unconfirmed
+// transactions always come last. Pagination (indexOffset/maxTransactions) is
+// applied over this ordering. Any presentation ordering is left to the caller.
+//
// This is a part of the WalletController interface.
func (b *BtcWallet) ListTransactionDetails(startHeight, endHeight int32,
accountFilter string, indexOffset uint32,
### lnwallet/interface.go
@@ -449,14 +449,24 @@ type WalletController interface {
accountFilter string) ([]*Utxo, error)
// ListTransactionDetails returns a list of all transactions which are
- // relevant to the wallet over [startHeight;endHeight]. If start height
- // is greater than end height, the transactions will be retrieved in
- // reverse order. To include unconfirmed transactions, endHeight should
- // be set to the special value -1. This will return transactions from
- // the tip of the chain until the start height (inclusive) and
- // unconfirmed transactions. The account parameter serves as a filter to
- // retrieve the transactions relevant to a specific account. When
- // empty, transactions of all wallet accounts are returned.
+ // relevant to the wallet over [startHeight;endHeight]. To include
+ // unconfirmed transactions, endHeight should be set to the special
+ // value -1. This will return transactions from the tip of the chain
+ // until the start height (inclusive) and unconfirmed transactions.
+ // The account parameter serves as a filter to retrieve the
+ // transactions relevant to a specific account. When empty,
+ // transactions of all wallet accounts are returned.
+ //
+ // NOTE: The returned confirmed transactions are ordered from the
+ // oldest to the newest when startHeight is not greater than
+ // endHeight. If startHeight is greater than endHeight, the blocks are
+ // read in reverse and the confirmed transactions are ordered from the
+ // newest to the oldest instead. For this comparison the special value
+ // -1 counts as the chain tip rather than as a negative height, so
+ // startHeight=0 with endHeight=-1 reads the blocks forward, oldest
+ // first. Unconfirmed transactions always come last. Pagination
+ // (indexOffset/maxTransactions) is applied over this ordering. Any
+ // presentation ordering is left to the caller.
ListTransactionDetails(startHeight, endHeight int32,
accountFilter string, indexOffset uint32,
maxTransactions uint32) ([]*TransactionDetail, uint64, uint64,
### rpcserver.go
@@ -6212,7 +6212,9 @@ func (r *rpcServer) GetTransactions(ctx context.Context,
return nil, err
}
- return lnrpc.RPCTransactionDetails(txns, firstIdx, lastIdx), nil
+ return lnrpc.RPCTransactionDetails(
+ txns, firstIdx, lastIdx, req.Reverse,
+ ), nil
}
// DescribeGraph returns a description of the latest graph state from the PoVWhy this scored 20/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.