lnwallet: use custom LockTime for rbf coop close
This commit is contained in:
3 files changed
+39
-4
No files matched your search
@@ -547,8 +547,8 @@ func (r *rbfCloserTestHarness) expectHalfSignerIteration(
|
|||||||
}
|
}
|
||||||
|
|
||||||
case *SendOfferEvent:
|
case *SendOfferEvent:
|
||||||
expectedStates = []RbfState{&ClosingNegotiation{}}
|
|
||||||
|
|
||||||
|
expectedStates = []RbfState{&ClosingNegotiation{}}
|
||||||
case *ChannelFlushed:
|
case *ChannelFlushed:
|
||||||
// If we're sending a flush event here, then this means that we
|
// 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
|
// also have enough balance to cover the fee so we'll have
|
||||||
@@ -1534,7 +1534,7 @@ func TestRbfCloseClosingNegotiationRemote(t *testing.T) {
|
|||||||
feeOffer := &OfferReceivedEvent{
|
feeOffer := &OfferReceivedEvent{
|
||||||
SigMsg: lnwire.ClosingComplete{
|
SigMsg: lnwire.ClosingComplete{
|
||||||
FeeSatoshis: absoluteFee,
|
FeeSatoshis: absoluteFee,
|
||||||
LockTime: 10,
|
LockTime: 1,
|
||||||
ClosingSigs: lnwire.ClosingSigs{
|
ClosingSigs: lnwire.ClosingSigs{
|
||||||
CloserAndClosee: newSigTlv[tlv.TlvType3]( //nolint:ll
|
CloserAndClosee: newSigTlv[tlv.TlvType3]( //nolint:ll
|
||||||
remoteWireSig,
|
remoteWireSig,
|
||||||
|
|||||||
@@ -902,6 +902,7 @@ func (l *RemoteCloseStart) ProcessEvent(event ProtocolEvent, env *Environment,
|
|||||||
|
|
||||||
chanOpts := []lnwallet.ChanCloseOpt{
|
chanOpts := []lnwallet.ChanCloseOpt{
|
||||||
lnwallet.WithCustomSequence(mempool.MaxRBFSequence),
|
lnwallet.WithCustomSequence(mempool.MaxRBFSequence),
|
||||||
|
lnwallet.WithCustomLockTime(msg.SigMsg.LockTime),
|
||||||
}
|
}
|
||||||
|
|
||||||
chancloserLog.Infof("responding to close w/ local_addr=%x, "+
|
chancloserLog.Infof("responding to close w/ local_addr=%x, "+
|
||||||
|
|||||||
+36
-2
@@ -8201,6 +8201,8 @@ type chanCloseOpt struct {
|
|||||||
customSort CloseSortFunc
|
customSort CloseSortFunc
|
||||||
|
|
||||||
customSequence fn.Option[uint32]
|
customSequence fn.Option[uint32]
|
||||||
|
|
||||||
|
customLockTime fn.Option[uint32]
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChanCloseOpt is a closure type that cen be used to modify the set of default
|
// 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 {
|
func WithCustomCoopSort(sorter CloseSortFunc) ChanCloseOpt {
|
||||||
return func(opts *chanCloseOpt) {
|
return func(opts *chanCloseOpt) {
|
||||||
opts.customSort = sorter
|
opts.customSort = sorter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithCustomSequence can be used to specify a custom sequence number for the
|
// 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
|
// CreateCloseProposal is used by both parties in a cooperative channel close
|
||||||
// workflow to generate proposed close transactions and signatures. This method
|
// workflow to generate proposed close transactions and signatures. This method
|
||||||
// should only be executed once all pending HTLCs (if any) on the channel have
|
// 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(
|
closeTx, err := CreateCooperativeCloseTx(
|
||||||
fundingTxIn(lc.channelState), lc.channelState.LocalChanCfg.DustLimit,
|
fundingTxIn(lc.channelState), lc.channelState.LocalChanCfg.DustLimit,
|
||||||
lc.channelState.RemoteChanCfg.DustLimit, ourBalance, theirBalance,
|
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
|
// Create the transaction used to return the current settled balance
|
||||||
// on this active channel back to both parties. In this current model,
|
// on this active channel back to both parties. In this current model,
|
||||||
// the initiator pays full fees for the cooperative close transaction.
|
// 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
|
// close transaction. This gives slightly more control compared to the
|
||||||
// enableRBF option.
|
// enableRBF option.
|
||||||
customSequence fn.Option[uint32]
|
customSequence fn.Option[uint32]
|
||||||
|
|
||||||
|
customLockTime fn.Option[uint32]
|
||||||
}
|
}
|
||||||
|
|
||||||
// defaultCloseTxOpts returns a closeTxOpts struct with default values.
|
// defaultCloseTxOpts returns a closeTxOpts struct with default values.
|
||||||
@@ -9171,7 +9195,7 @@ func WithExtraTxCloseOutputs(extraOutputs []CloseOutput) CloseTxOpt {
|
|||||||
func WithCustomTxSort(sorter CloseSortFunc) CloseTxOpt {
|
func WithCustomTxSort(sorter CloseSortFunc) CloseTxOpt {
|
||||||
return func(opts *closeTxOpts) {
|
return func(opts *closeTxOpts) {
|
||||||
opts.customSort = sorter
|
opts.customSort = sorter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithCustomTxInSequence allows a caller to set a custom sequence on the sole
|
// 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
|
// CreateCooperativeCloseTx creates a transaction which if signed by both
|
||||||
// parties, then broadcast cooperatively closes an active channel. The creation
|
// parties, then broadcast cooperatively closes an active channel. The creation
|
||||||
// of the closure transaction is modified by a boolean indicating if the party
|
// 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 := wire.NewMsgTx(2)
|
||||||
closeTx.AddTxIn(&fundingTxIn)
|
closeTx.AddTxIn(&fundingTxIn)
|
||||||
|
|
||||||
|
opts.customLockTime.WhenSome(func(lockTime uint32) {
|
||||||
|
closeTx.LockTime = lockTime
|
||||||
|
})
|
||||||
|
|
||||||
// TODO(roasbeef): needs support for dropping inputs
|
// TODO(roasbeef): needs support for dropping inputs
|
||||||
|
|
||||||
// Create both cooperative closure outputs, properly respecting the
|
// Create both cooperative closure outputs, properly respecting the
|
||||||
|
|||||||
Reference in new issue
Block a user