diff --git a/lnwallet/chancloser/rbf_coop_test.go b/lnwallet/chancloser/rbf_coop_test.go index 5cf985e8d..6b6f985fe 100644 --- a/lnwallet/chancloser/rbf_coop_test.go +++ b/lnwallet/chancloser/rbf_coop_test.go @@ -547,8 +547,8 @@ func (r *rbfCloserTestHarness) expectHalfSignerIteration( } case *SendOfferEvent: - expectedStates = []RbfState{&ClosingNegotiation{}} + expectedStates = []RbfState{&ClosingNegotiation{}} case *ChannelFlushed: // If we're sending a flush event here, then this means that we // also have enough balance to cover the fee so we'll have @@ -1534,7 +1534,7 @@ func TestRbfCloseClosingNegotiationRemote(t *testing.T) { feeOffer := &OfferReceivedEvent{ SigMsg: lnwire.ClosingComplete{ FeeSatoshis: absoluteFee, - LockTime: 10, + LockTime: 1, ClosingSigs: lnwire.ClosingSigs{ CloserAndClosee: newSigTlv[tlv.TlvType3]( //nolint:ll remoteWireSig, diff --git a/lnwallet/chancloser/rbf_coop_transitions.go b/lnwallet/chancloser/rbf_coop_transitions.go index 0b57463c4..fc54c9b1c 100644 --- a/lnwallet/chancloser/rbf_coop_transitions.go +++ b/lnwallet/chancloser/rbf_coop_transitions.go @@ -902,6 +902,7 @@ func (l *RemoteCloseStart) ProcessEvent(event ProtocolEvent, env *Environment, chanOpts := []lnwallet.ChanCloseOpt{ lnwallet.WithCustomSequence(mempool.MaxRBFSequence), + lnwallet.WithCustomLockTime(msg.SigMsg.LockTime), } chancloserLog.Infof("responding to close w/ local_addr=%x, "+ diff --git a/lnwallet/channel.go b/lnwallet/channel.go index 8e1aed81b..a1bc7cda2 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -8201,6 +8201,8 @@ type chanCloseOpt struct { customSort CloseSortFunc customSequence fn.Option[uint32] + + customLockTime fn.Option[uint32] } // ChanCloseOpt is a closure type that cen be used to modify the set of default @@ -8234,7 +8236,7 @@ func WithExtraCloseOutputs(extraOutputs []CloseOutput) ChanCloseOpt { func WithCustomCoopSort(sorter CloseSortFunc) ChanCloseOpt { return func(opts *chanCloseOpt) { opts.customSort = sorter - } + } } // WithCustomSequence can be used to specify a custom sequence number for the @@ -8245,6 +8247,14 @@ func WithCustomSequence(sequence uint32) ChanCloseOpt { } } +// WithCustomLockTime can be used to specify a custom lock time for the coop +// close transaction. +func WithCustomLockTime(lockTime uint32) ChanCloseOpt { + return func(opts *chanCloseOpt) { + opts.customLockTime = fn.Some(lockTime) + } +} + // CreateCloseProposal is used by both parties in a cooperative channel close // workflow to generate proposed close transactions and signatures. This method // 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, )) }) + opts.customLockTime.WhenSome(func(lockTime uint32) { + closeTxOpts = append(closeTxOpts, WithCustomTxLockTime( + lockTime, + )) + }) + closeTx, err := CreateCooperativeCloseTx( fundingTxIn(lc.channelState), lc.channelState.LocalChanCfg.DustLimit, lc.channelState.RemoteChanCfg.DustLimit, ourBalance, theirBalance, @@ -8417,6 +8433,12 @@ func (lc *LightningChannel) CompleteCooperativeClose( )) }) + opts.customLockTime.WhenSome(func(lockTime uint32) { + closeTxOpts = append(closeTxOpts, WithCustomTxLockTime( + lockTime, + )) + }) + // Create the transaction used to return the current settled balance // on this active channel back to both parties. In this current model, // the initiator pays full fees for the cooperative close transaction. @@ -9138,6 +9160,8 @@ type closeTxOpts struct { // close transaction. This gives slightly more control compared to the // enableRBF option. customSequence fn.Option[uint32] + + customLockTime fn.Option[uint32] } // defaultCloseTxOpts returns a closeTxOpts struct with default values. @@ -9171,7 +9195,7 @@ func WithExtraTxCloseOutputs(extraOutputs []CloseOutput) CloseTxOpt { func WithCustomTxSort(sorter CloseSortFunc) CloseTxOpt { return func(opts *closeTxOpts) { opts.customSort = sorter - } + } } // WithCustomTxInSequence allows a caller to set a custom sequence on the sole @@ -9182,6 +9206,12 @@ func WithCustomTxInSequence(sequence uint32) CloseTxOpt { } } +func WithCustomTxLockTime(lockTime uint32) CloseTxOpt { + return func(o *closeTxOpts) { + o.customLockTime = fn.Some(lockTime) + } +} + // CreateCooperativeCloseTx creates a transaction which if signed by both // parties, then broadcast cooperatively closes an active channel. The creation // of the closure transaction is modified by a boolean indicating if the party @@ -9216,6 +9246,10 @@ func CreateCooperativeCloseTx(fundingTxIn wire.TxIn, closeTx := wire.NewMsgTx(2) closeTx.AddTxIn(&fundingTxIn) + opts.customLockTime.WhenSome(func(lockTime uint32) { + closeTx.LockTime = lockTime + }) + // TODO(roasbeef): needs support for dropping inputs // Create both cooperative closure outputs, properly respecting the