Skip to content

Commit b94ce6f

Browse files
committed
lnwallet: use custom LockTime for rbf coop close
1 parent ab4297e commit b94ce6f

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

lnwallet/chancloser/rbf_coop_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,8 +547,8 @@ func (r *rbfCloserTestHarness) expectHalfSignerIteration(
547547
}
548548

549549
case *SendOfferEvent:
550-
expectedStates = []RbfState{&ClosingNegotiation{}}
551550

551+
expectedStates = []RbfState{&ClosingNegotiation{}}
552552
case *ChannelFlushed:
553553
// If we're sending a flush event here, then this means that we
554554
// also have enough balance to cover the fee so we'll have
@@ -1534,7 +1534,7 @@ func TestRbfCloseClosingNegotiationRemote(t *testing.T) {
15341534
feeOffer := &OfferReceivedEvent{
15351535
SigMsg: lnwire.ClosingComplete{
15361536
FeeSatoshis: absoluteFee,
1537-
LockTime: 10,
1537+
LockTime: 1,
15381538
ClosingSigs: lnwire.ClosingSigs{
15391539
CloserAndClosee: newSigTlv[tlv.TlvType3]( //nolint:ll
15401540
remoteWireSig,

lnwallet/chancloser/rbf_coop_transitions.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,7 @@ func (l *RemoteCloseStart) ProcessEvent(event ProtocolEvent, env *Environment,
902902

903903
chanOpts := []lnwallet.ChanCloseOpt{
904904
lnwallet.WithCustomSequence(mempool.MaxRBFSequence),
905+
lnwallet.WithCustomLockTime(msg.SigMsg.LockTime),
905906
}
906907

907908
chancloserLog.Infof("responding to close w/ local_addr=%x, "+

lnwallet/channel.go

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8201,6 +8201,8 @@ type chanCloseOpt struct {
82018201
customSort CloseSortFunc
82028202

82038203
customSequence fn.Option[uint32]
8204+
8205+
customLockTime fn.Option[uint32]
82048206
}
82058207

82068208
// ChanCloseOpt is a closure type that cen be used to modify the set of default
@@ -8234,7 +8236,7 @@ func WithExtraCloseOutputs(extraOutputs []CloseOutput) ChanCloseOpt {
82348236
func WithCustomCoopSort(sorter CloseSortFunc) ChanCloseOpt {
82358237
return func(opts *chanCloseOpt) {
82368238
opts.customSort = sorter
8237-
}
8239+
}
82388240
}
82398241

82408242
// WithCustomSequence can be used to specify a custom sequence number for the
@@ -8245,6 +8247,14 @@ func WithCustomSequence(sequence uint32) ChanCloseOpt {
82458247
}
82468248
}
82478249

8250+
// WithCustomLockTime can be used to specify a custom lock time for the coop
8251+
// close transaction.
8252+
func WithCustomLockTime(lockTime uint32) ChanCloseOpt {
8253+
return func(opts *chanCloseOpt) {
8254+
opts.customLockTime = fn.Some(lockTime)
8255+
}
8256+
}
8257+
82488258
// CreateCloseProposal is used by both parties in a cooperative channel close
82498259
// workflow to generate proposed close transactions and signatures. This method
82508260
// should only be executed once all pending HTLCs (if any) on the channel have
@@ -8310,6 +8320,12 @@ func (lc *LightningChannel) CreateCloseProposal(proposedFee btcutil.Amount,
83108320
))
83118321
})
83128322

8323+
opts.customLockTime.WhenSome(func(lockTime uint32) {
8324+
closeTxOpts = append(closeTxOpts, WithCustomTxLockTime(
8325+
lockTime,
8326+
))
8327+
})
8328+
83138329
closeTx, err := CreateCooperativeCloseTx(
83148330
fundingTxIn(lc.channelState), lc.channelState.LocalChanCfg.DustLimit,
83158331
lc.channelState.RemoteChanCfg.DustLimit, ourBalance, theirBalance,
@@ -8417,6 +8433,12 @@ func (lc *LightningChannel) CompleteCooperativeClose(
84178433
))
84188434
})
84198435

8436+
opts.customLockTime.WhenSome(func(lockTime uint32) {
8437+
closeTxOpts = append(closeTxOpts, WithCustomTxLockTime(
8438+
lockTime,
8439+
))
8440+
})
8441+
84208442
// Create the transaction used to return the current settled balance
84218443
// on this active channel back to both parties. In this current model,
84228444
// the initiator pays full fees for the cooperative close transaction.
@@ -9138,6 +9160,8 @@ type closeTxOpts struct {
91389160
// close transaction. This gives slightly more control compared to the
91399161
// enableRBF option.
91409162
customSequence fn.Option[uint32]
9163+
9164+
customLockTime fn.Option[uint32]
91419165
}
91429166

91439167
// defaultCloseTxOpts returns a closeTxOpts struct with default values.
@@ -9171,7 +9195,7 @@ func WithExtraTxCloseOutputs(extraOutputs []CloseOutput) CloseTxOpt {
91719195
func WithCustomTxSort(sorter CloseSortFunc) CloseTxOpt {
91729196
return func(opts *closeTxOpts) {
91739197
opts.customSort = sorter
9174-
}
9198+
}
91759199
}
91769200

91779201
// WithCustomTxInSequence allows a caller to set a custom sequence on the sole
@@ -9182,6 +9206,12 @@ func WithCustomTxInSequence(sequence uint32) CloseTxOpt {
91829206
}
91839207
}
91849208

9209+
func WithCustomTxLockTime(lockTime uint32) CloseTxOpt {
9210+
return func(o *closeTxOpts) {
9211+
o.customLockTime = fn.Some(lockTime)
9212+
}
9213+
}
9214+
91859215
// CreateCooperativeCloseTx creates a transaction which if signed by both
91869216
// parties, then broadcast cooperatively closes an active channel. The creation
91879217
// of the closure transaction is modified by a boolean indicating if the party
@@ -9216,6 +9246,10 @@ func CreateCooperativeCloseTx(fundingTxIn wire.TxIn,
92169246
closeTx := wire.NewMsgTx(2)
92179247
closeTx.AddTxIn(&fundingTxIn)
92189248

9249+
opts.customLockTime.WhenSome(func(lockTime uint32) {
9250+
closeTx.LockTime = lockTime
9251+
})
9252+
92199253
// TODO(roasbeef): needs support for dropping inputs
92209254

92219255
// Create both cooperative closure outputs, properly respecting the

0 commit comments

Comments
 (0)