multi: fix verbose output for listsweeps and check all against wallet
Previously, the verbose output of listsweeps would fail if we did not find some sweeps in our wallet's listtransactions output. This could be the case for sweeps that were rbf-ed, so the endpoint would fail. This commit also updates the listsweeps endpoint to always check against the wallet, so that we do not return these discarded sweeps that never confirmed.
This commit is contained in:
5 files changed
+81
-57
No files matched your search
@@ -1117,7 +1117,8 @@ var xxx_messageInfo_BumpFeeResponse proto.InternalMessageInfo
|
||||
type ListSweepsRequest struct {
|
||||
//
|
||||
//Retrieve the full sweep transaction details. If false, only the sweep txids
|
||||
//will be returned.
|
||||
//will be returned. Note that some sweeps that LND publishes will have been
|
||||
//replaced-by-fee, so will not be included in this output.
|
||||
Verbose bool `protobuf:"varint,1,opt,name=verbose,proto3" json:"verbose,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
|
||||
@@ -464,7 +464,8 @@ message BumpFeeResponse {
|
||||
message ListSweepsRequest {
|
||||
/*
|
||||
Retrieve the full sweep transaction details. If false, only the sweep txids
|
||||
will be returned.
|
||||
will be returned. Note that some sweeps that LND publishes will have been
|
||||
replaced-by-fee, so will not be included in this output.
|
||||
*/
|
||||
bool verbose = 1;
|
||||
}
|
||||
|
||||
@@ -299,7 +299,7 @@
|
||||
"parameters": [
|
||||
{
|
||||
"name": "verbose",
|
||||
"description": "Retrieve the full sweep transaction details. If false, only the sweep txids\nwill be returned.",
|
||||
"description": "Retrieve the full sweep transaction details. If false, only the sweep txids\nwill be returned. Note that some sweeps that LND publishes will have been\nreplaced-by-fee, so will not be included in this output.",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"type": "boolean",
|
||||
|
||||
@@ -782,29 +782,14 @@ func (w *WalletKit) ListSweeps(ctx context.Context,
|
||||
}
|
||||
|
||||
sweepTxns := make(map[string]bool)
|
||||
|
||||
txids := make([]string, len(sweeps))
|
||||
for i, sweep := range sweeps {
|
||||
for _, sweep := range sweeps {
|
||||
sweepTxns[sweep.String()] = true
|
||||
txids[i] = sweep.String()
|
||||
}
|
||||
|
||||
// If the caller does not want verbose output, just return the set of
|
||||
// sweep txids.
|
||||
if !in.Verbose {
|
||||
txidResp := &ListSweepsResponse_TransactionIDs{
|
||||
TransactionIds: txids,
|
||||
}
|
||||
|
||||
return &ListSweepsResponse{
|
||||
Sweeps: &ListSweepsResponse_TransactionIds{
|
||||
TransactionIds: txidResp,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// If the caller does want full transaction lookups, query our wallet
|
||||
// for all transactions, including unconfirmed transactions.
|
||||
// Some of our sweeps could have been replaced by fee, or dropped out
|
||||
// of the mempool. Here, we lookup our wallet transactions so that we
|
||||
// can match our list of sweeps against the list of transactions that
|
||||
// the wallet is still tracking.
|
||||
transactions, err := w.cfg.Wallet.ListTransactionDetails(
|
||||
0, btcwallet.UnconfirmedHeight,
|
||||
)
|
||||
@@ -812,26 +797,41 @@ func (w *WalletKit) ListSweeps(ctx context.Context,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var sweepTxDetails []*lnwallet.TransactionDetail
|
||||
var (
|
||||
txids []string
|
||||
txDetails []*lnwallet.TransactionDetail
|
||||
)
|
||||
|
||||
for _, tx := range transactions {
|
||||
_, ok := sweepTxns[tx.Hash.String()]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
sweepTxDetails = append(sweepTxDetails, tx)
|
||||
// Add the txid or full tx details depending on whether we want
|
||||
// verbose output or not.
|
||||
if in.Verbose {
|
||||
txDetails = append(txDetails, tx)
|
||||
} else {
|
||||
txids = append(txids, tx.Hash.String())
|
||||
}
|
||||
}
|
||||
|
||||
// Fail if we have not retrieved all of our sweep transactions from the
|
||||
// wallet.
|
||||
if len(sweepTxDetails) != len(txids) {
|
||||
return nil, fmt.Errorf("not all sweeps found by list "+
|
||||
"transactions: %v, %v", len(sweepTxDetails), len(txids))
|
||||
if in.Verbose {
|
||||
return &ListSweepsResponse{
|
||||
Sweeps: &ListSweepsResponse_TransactionDetails{
|
||||
TransactionDetails: lnrpc.RPCTransactionDetails(
|
||||
txDetails,
|
||||
),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
return &ListSweepsResponse{
|
||||
Sweeps: &ListSweepsResponse_TransactionDetails{
|
||||
TransactionDetails: lnrpc.RPCTransactionDetails(transactions),
|
||||
Sweeps: &ListSweepsResponse_TransactionIds{
|
||||
TransactionIds: &ListSweepsResponse_TransactionIDs{
|
||||
TransactionIds: txids,
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user