Skip to content

Commit 2f2efc7

Browse files
authored
Merge pull request #8843 from ziggie1984/bumpforceclosefee-rpc
bumpforceclosefee rpc
2 parents 57a5e49 + 08aba8c commit 2f2efc7

19 files changed

+1479
-657
lines changed

cmd/lncli/walletrpc_active.go

Lines changed: 41 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package main
55

66
import (
77
"bytes"
8-
"context"
98
"encoding/base64"
109
"encoding/hex"
1110
"encoding/json"
@@ -21,7 +20,6 @@ import (
2120
"github.com/btcsuite/btcd/chaincfg/chainhash"
2221
"github.com/btcsuite/btcd/txscript"
2322
"github.com/btcsuite/btcd/wire"
24-
"github.com/lightningnetwork/lnd/lnrpc"
2523
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
2624
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
2725
"github.com/lightningnetwork/lnd/lnwallet/chanfunding"
@@ -431,51 +429,50 @@ var bumpForceCloseFeeCommand = cli.Command{
431429
allows the fee of a channel force closing transaction to be increased by
432430
using the child-pays-for-parent mechanism. It will instruct the sweeper
433431
to sweep the anchor outputs of the closing transaction at the requested
434-
fee rate or confirmation target. The specified fee rate will be the
435-
effective fee rate taking the parent fee into account.
432+
confirmation target and limit the fees to the specified budget.
436433
`,
437434
Flags: []cli.Flag{
438435
cli.Uint64Flag{
439436
Name: "conf_target",
440437
Usage: `
441-
The deadline in number of blocks that the input should be spent within.
442-
When not set, for new inputs, the default value (1008) is used; for
443-
exiting inputs, their current values will be retained.`,
438+
The deadline in number of blocks that the anchor output should be spent
439+
within to bump the closing transaction.`,
444440
},
445441
cli.Uint64Flag{
446442
Name: "sat_per_byte",
447443
Usage: "Deprecated, use sat_per_vbyte instead.",
448444
Hidden: true,
449445
},
450-
cli.BoolFlag{
451-
Name: "force",
452-
Usage: "Deprecated, use immediate instead.",
453-
Hidden: true,
454-
},
455446
cli.Uint64Flag{
456447
Name: "sat_per_vbyte",
457448
Usage: `
458-
The starting fee rate, expressed in sat/vbyte, that will be used to
459-
spend the input with initially. This value will be used by the
460-
sweeper's fee function as its starting fee rate. When not set, the
461-
sweeper will use the estimated fee rate using the target_conf as the
449+
The starting fee rate, expressed in sat/vbyte. This value will be used
450+
by the sweeper's fee function as its starting fee rate. When not set,
451+
the sweeper will use the estimated fee rate using the target_conf as the
462452
starting fee rate.`,
463453
},
454+
cli.BoolFlag{
455+
Name: "force",
456+
Usage: "Deprecated, use immediate instead.",
457+
Hidden: true,
458+
},
464459
cli.BoolFlag{
465460
Name: "immediate",
466461
Usage: `
467-
Whether this input will be swept immediately. When set to true, the
468-
sweeper will sweep this input without waiting for the next batch.`,
462+
Whether this cpfp transaction will be triggered immediately. When set to
463+
true, the sweeper will consider all currently pending registered sweeps
464+
and trigger new batch transactions including the sweeping of the anchor
465+
output related to the selected force close transaction.`,
469466
},
470467
cli.Uint64Flag{
471468
Name: "budget",
472469
Usage: `
473-
The max amount in sats that can be used as the fees. Setting this value
474-
greater than the input's value may result in CPFP - one or more wallet
475-
utxos will be used to pay the fees specified by the budget. If not set,
476-
for new inputs, by default 50% of the input's value will be treated as
477-
the budget for fee bumping; for existing inputs, their current budgets
478-
will be retained.`,
470+
The max amount in sats that can be used as the fees. For already
471+
registered anchor outputs if not set explicitly the old value will be
472+
used. For channel force closes which have no HTLCs in their commitment
473+
transaction this value has to be set to an appropriate amount to pay for
474+
the cpfp transaction of the force closed channel otherwise the fee
475+
bumping will fail.`,
479476
},
480477
},
481478
Action: actionDecorator(bumpForceCloseFee),
@@ -492,97 +489,42 @@ func bumpForceCloseFee(ctx *cli.Context) error {
492489

493490
// Validate the channel point.
494491
channelPoint := ctx.Args().Get(0)
495-
_, err := NewProtoOutPoint(channelPoint)
492+
rpcChannelPoint, err := parseChanPoint(channelPoint)
496493
if err != nil {
497494
return err
498495
}
499496

500-
// Fetch all waiting close channels.
501-
client, cleanUp := getClient(ctx)
502-
defer cleanUp()
503-
504-
// Fetch waiting close channel commitments.
505-
commitments, err := getWaitingCloseCommitments(
506-
ctxc, client, channelPoint,
507-
)
508-
if err != nil {
509-
return err
497+
// `sat_per_byte` was deprecated we only use sats/vbyte now.
498+
if ctx.IsSet("sat_per_byte") {
499+
return fmt.Errorf("deprecated, use sat_per_vbyte instead")
510500
}
511501

512502
// Retrieve pending sweeps.
513503
walletClient, cleanUp := getWalletClient(ctx)
514504
defer cleanUp()
515505

516-
sweeps, err := walletClient.PendingSweeps(
517-
ctxc, &walletrpc.PendingSweepsRequest{},
518-
)
519-
if err != nil {
520-
return err
521-
}
522-
523-
// Match pending sweeps with commitments of the channel for which a bump
524-
// is requested and bump their fees.
525-
commitSet := map[string]struct{}{
526-
commitments.LocalTxid: {},
527-
commitments.RemoteTxid: {},
528-
}
529-
if commitments.RemotePendingTxid != "" {
530-
commitSet[commitments.RemotePendingTxid] = struct{}{}
531-
}
532-
533-
for _, sweep := range sweeps.PendingSweeps {
534-
// Only bump anchor sweeps.
535-
if sweep.WitnessType != walletrpc.WitnessType_COMMITMENT_ANCHOR {
536-
continue
537-
}
538-
539-
// Skip unrelated sweeps.
540-
sweepTxID, err := chainhash.NewHash(sweep.Outpoint.TxidBytes)
541-
if err != nil {
542-
return err
543-
}
544-
if _, match := commitSet[sweepTxID.String()]; !match {
545-
continue
546-
}
547-
548-
resp, err := walletClient.BumpFee(
549-
ctxc, &walletrpc.BumpFeeRequest{
550-
Outpoint: sweep.Outpoint,
551-
TargetConf: uint32(ctx.Uint64("conf_target")),
552-
Budget: ctx.Uint64("budget"),
553-
Immediate: ctx.Bool("immediate"),
554-
SatPerVbyte: ctx.Uint64("sat_per_vbyte"),
555-
})
556-
if err != nil {
557-
return err
558-
}
559-
560-
// Bump fee of the anchor sweep.
561-
fmt.Printf("Bumping fee of %v:%v: %v\n",
562-
sweepTxID, sweep.Outpoint.OutputIndex, resp.GetStatus())
506+
// Parse immediate flag (force flag was deprecated).
507+
if ctx.IsSet("immediate") && ctx.IsSet("force") {
508+
return fmt.Errorf("cannot set immediate and force flag at " +
509+
"the same time")
563510
}
511+
immediate := ctx.Bool("immediate") || ctx.Bool("force")
564512

565-
return nil
566-
}
567-
568-
func getWaitingCloseCommitments(ctxc context.Context,
569-
client lnrpc.LightningClient, channelPoint string) (
570-
*lnrpc.PendingChannelsResponse_Commitments, error) {
571-
572-
req := &lnrpc.PendingChannelsRequest{}
573-
resp, err := client.PendingChannels(ctxc, req)
513+
resp, err := walletClient.BumpForceCloseFee(
514+
ctxc, &walletrpc.BumpForceCloseFeeRequest{
515+
ChanPoint: rpcChannelPoint,
516+
DeadlineDelta: uint32(ctx.Uint64("conf_target")),
517+
Budget: ctx.Uint64("budget"),
518+
Immediate: immediate,
519+
StartingFeerate: ctx.Uint64("sat_per_vbyte"),
520+
})
574521
if err != nil {
575-
return nil, err
522+
return err
576523
}
577524

578-
// Lookup the channel commit tx hashes.
579-
for _, channel := range resp.WaitingCloseChannels {
580-
if channel.Channel.ChannelPoint == channelPoint {
581-
return channel.Commitments, nil
582-
}
583-
}
525+
fmt.Printf("BumpForceCloseFee result: %s\n", resp.Status)
584526

585-
return nil, errors.New("channel not found")
527+
return nil
586528
}
587529

588530
var listSweepsCommand = cli.Command{
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Release Notes
2+
- [Bug Fixes](#bug-fixes)
3+
- [New Features](#new-features)
4+
- [Functional Enhancements](#functional-enhancements)
5+
- [RPC Additions](#rpc-additions)
6+
- [lncli Additions](#lncli-additions)
7+
- [Improvements](#improvements)
8+
- [Functional Updates](#functional-updates)
9+
- [RPC Updates](#rpc-updates)
10+
- [lncli Updates](#lncli-updates)
11+
- [Breaking Changes](#breaking-changes)
12+
- [Performance Improvements](#performance-improvements)
13+
- [Technical and Architectural Updates](#technical-and-architectural-updates)
14+
- [BOLT Spec Updates](#bolt-spec-updates)
15+
- [Testing](#testing)
16+
- [Database](#database)
17+
- [Code Health](#code-health)
18+
- [Tooling and Documentation](#tooling-and-documentation)
19+
20+
# Bug Fixes
21+
22+
# New Features
23+
## Functional Enhancements
24+
## RPC Additions
25+
26+
* [Add a new rpc endpoint](https://github.com/lightningnetwork/lnd/pull/8843)
27+
`BumpForceCloseFee` which moves the functionality soley available in the
28+
`lncli` to LND hence making it more universal.
29+
30+
## lncli Additions
31+
32+
# Improvements
33+
## Functional Updates
34+
35+
## RPC Updates
36+
37+
## lncli Updates
38+
39+
## Code Health
40+
41+
## Breaking Changes
42+
## Performance Improvements
43+
44+
# Technical and Architectural Updates
45+
## BOLT Spec Updates
46+
47+
## Testing
48+
## Database
49+
50+
## Code Health
51+
52+
## Tooling and Documentation
53+
54+
# Contributors (Alphabetical Order)
55+
56+
* Ziggie

itest/list_on_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,10 @@ var allTestCases = []*lntest.TestCase{
490490
Name: "bumpfee",
491491
TestFunc: testBumpFee,
492492
},
493+
{
494+
Name: "bumpforceclosefee",
495+
TestFunc: testBumpForceCloseFee,
496+
},
493497
{
494498
Name: "taproot",
495499
TestFunc: testTaproot,

itest/lnd_multi-hop_test.go

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,17 +1936,6 @@ func runMultiHopHtlcAggregation(ht *lntest.HarnessTest,
19361936

19371937
expectedTxes := 0
19381938
switch c {
1939-
// With the closing transaction confirmed, we should expect Bob's HTLC
1940-
// timeout transactions to be broadcast due to the expiry being reached.
1941-
// We will also expect the success transactions, since he learnt the
1942-
// preimages from Alice. We also expect Carol to sweep her commitment
1943-
// output.
1944-
case lnrpc.CommitmentType_LEGACY:
1945-
ht.AssertNumPendingSweeps(bob, numInvoices*2+1)
1946-
ht.AssertNumPendingSweeps(carol, 1)
1947-
1948-
expectedTxes = 2*numInvoices + 1
1949-
19501939
// In case of anchors, all success transactions will be aggregated into
19511940
// one, the same is the case for the timeout transactions. In this case
19521941
// Carol will also sweep her commitment and anchor output in a single
@@ -2068,12 +2057,6 @@ func runMultiHopHtlcAggregation(ht *lntest.HarnessTest,
20682057
}
20692058

20702059
switch c {
2071-
// In case this is a non-anchor channel type, we must mine 2 blocks, as
2072-
// the nursery waits an extra block before sweeping. Before the blocks
2073-
// are mined, we should expect to see Bob's commit sweep in the mempool.
2074-
case lnrpc.CommitmentType_LEGACY:
2075-
ht.MineBlocksAndAssertNumTxes(2, 1)
2076-
20772060
// Mining one additional block, Bob's second level tx is mature, and he
20782061
// can sweep the output. Before the blocks are mined, we should expect
20792062
// to see Bob's commit sweep in the mempool.
@@ -2478,11 +2461,6 @@ func runExtraPreimageFromRemoteCommit(ht *lntest.HarnessTest,
24782461
ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED)
24792462

24802463
switch c {
2481-
// For non-anchor channel type, we should expect to see Bob's commit
2482-
// sweep in the mempool.
2483-
case lnrpc.CommitmentType_LEGACY:
2484-
numTxesMempool++
2485-
24862464
// For anchor channel type, we should expect to see Bob's commit output
24872465
// and his anchor output be swept in a single tx in the mempool.
24882466
case lnrpc.CommitmentType_ANCHORS, lnrpc.CommitmentType_SIMPLE_TAPROOT:
@@ -2665,10 +2643,6 @@ func runExtraPreimageFromLocalCommit(ht *lntest.HarnessTest,
26652643
// - Bob's local output sweep tx, if this is NOT script enforced lease.
26662644
// - Carol's anchor sweep tx cannot be broadcast as it's uneconomical.
26672645
switch c {
2668-
case lnrpc.CommitmentType_LEGACY:
2669-
htlcOutpoint.Index = 0
2670-
ht.AssertNumTxsInMempool(2)
2671-
26722646
case lnrpc.CommitmentType_ANCHORS, lnrpc.CommitmentType_SIMPLE_TAPROOT:
26732647
htlcOutpoint.Index = 2
26742648
ht.AssertNumTxsInMempool(2)

0 commit comments

Comments
 (0)