multi: switch to lock time from sequence for coop close v2
This commit is contained in:
5 files changed
+18
-41
No files matched your search
@@ -1430,31 +1430,6 @@ func TestRbfCloseClosingNegotiationRemote(t *testing.T) {
|
|||||||
closeHarness.assertNoStateTransitions()
|
closeHarness.assertNoStateTransitions()
|
||||||
})
|
})
|
||||||
|
|
||||||
// If the remote party sends us a signature with a final sequence, then
|
|
||||||
// we'll error out as it can't be RBF'd
|
|
||||||
t.Run("recv_offer_final_sequence", func(t *testing.T) {
|
|
||||||
closeHarness := newCloser(t, &harnessCfg{
|
|
||||||
initialState: fn.Some[ProtocolState](startingState),
|
|
||||||
})
|
|
||||||
defer closeHarness.stopAndAssert()
|
|
||||||
|
|
||||||
// We should fail as they sent a non final sequence.
|
|
||||||
closeHarness.expectFailure(ErrNonFinalSequence)
|
|
||||||
|
|
||||||
// We'll send an offer with something beyond the max RBF value,
|
|
||||||
// this should fail.
|
|
||||||
feeOffer := &OfferReceivedEvent{
|
|
||||||
SigMsg: lnwire.ClosingComplete{
|
|
||||||
FeeSatoshis: absoluteFee,
|
|
||||||
Sequence: mempool.MaxRBFSequence + 1,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
closeHarness.chanCloser.SendEvent(feeOffer)
|
|
||||||
|
|
||||||
// We shouldn't have transitioned to a new state.
|
|
||||||
closeHarness.assertNoStateTransitions()
|
|
||||||
})
|
|
||||||
|
|
||||||
// If our balance, is dust, then the remote party should send a
|
// If our balance, is dust, then the remote party should send a
|
||||||
// signature that doesn't include our output.
|
// signature that doesn't include our output.
|
||||||
t.Run("recv_offer_err_closer_no_closee", func(t *testing.T) {
|
t.Run("recv_offer_err_closer_no_closee", func(t *testing.T) {
|
||||||
@@ -1559,7 +1534,7 @@ func TestRbfCloseClosingNegotiationRemote(t *testing.T) {
|
|||||||
feeOffer := &OfferReceivedEvent{
|
feeOffer := &OfferReceivedEvent{
|
||||||
SigMsg: lnwire.ClosingComplete{
|
SigMsg: lnwire.ClosingComplete{
|
||||||
FeeSatoshis: absoluteFee,
|
FeeSatoshis: absoluteFee,
|
||||||
Sequence: sequence,
|
LockTime: 10,
|
||||||
ClosingSigs: lnwire.ClosingSigs{
|
ClosingSigs: lnwire.ClosingSigs{
|
||||||
CloserAndClosee: newSigTlv[tlv.TlvType3]( //nolint:ll
|
CloserAndClosee: newSigTlv[tlv.TlvType3]( //nolint:ll
|
||||||
remoteWireSig,
|
remoteWireSig,
|
||||||
|
|||||||
@@ -716,7 +716,9 @@ func (l *LocalCloseStart) ProcessEvent(event ProtocolEvent, env *Environment,
|
|||||||
Msgs: []lnwire.Message{&lnwire.ClosingComplete{
|
Msgs: []lnwire.Message{&lnwire.ClosingComplete{
|
||||||
ChannelID: env.ChanID,
|
ChannelID: env.ChanID,
|
||||||
FeeSatoshis: absoluteFee,
|
FeeSatoshis: absoluteFee,
|
||||||
Sequence: mempool.MaxRBFSequence,
|
// TODO(roasbeef): thread thru proper height
|
||||||
|
// value
|
||||||
|
LockTime: mempool.MaxRBFSequence,
|
||||||
ClosingSigs: closingSigs,
|
ClosingSigs: closingSigs,
|
||||||
}},
|
}},
|
||||||
}}
|
}}
|
||||||
@@ -862,18 +864,11 @@ func (l *RemoteCloseStart) ProcessEvent(event ProtocolEvent, env *Environment,
|
|||||||
// To start, we'll perform some basic validation of the sig
|
// To start, we'll perform some basic validation of the sig
|
||||||
// message they've sent. We'll validate that the remote party
|
// message they've sent. We'll validate that the remote party
|
||||||
// actually has enough fees to pay the closing fees.
|
// actually has enough fees to pay the closing fees.
|
||||||
switch {
|
if !l.RemoteCanPayFees(msg.SigMsg.FeeSatoshis) {
|
||||||
case !l.RemoteCanPayFees(msg.SigMsg.FeeSatoshis):
|
|
||||||
return nil, fmt.Errorf("%w: %v vs %v",
|
return nil, fmt.Errorf("%w: %v vs %v",
|
||||||
ErrRemoteCannotPay,
|
ErrRemoteCannotPay,
|
||||||
msg.SigMsg.FeeSatoshis,
|
msg.SigMsg.FeeSatoshis,
|
||||||
l.RemoteBalance.ToSatoshis())
|
l.RemoteBalance.ToSatoshis())
|
||||||
|
|
||||||
// The sequence they send can't be the max sequence, as that would
|
|
||||||
// prevent RBF.
|
|
||||||
case msg.SigMsg.Sequence > mempool.MaxRBFSequence:
|
|
||||||
return nil, fmt.Errorf("%w: %v", ErrNonFinalSequence,
|
|
||||||
msg.SigMsg.Sequence)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// With the basic sanity checks out of the way, we'll now
|
// With the basic sanity checks out of the way, we'll now
|
||||||
@@ -908,7 +903,7 @@ func (l *RemoteCloseStart) ProcessEvent(event ProtocolEvent, env *Environment,
|
|||||||
}
|
}
|
||||||
|
|
||||||
chanOpts := []lnwallet.ChanCloseOpt{
|
chanOpts := []lnwallet.ChanCloseOpt{
|
||||||
lnwallet.WithCustomSequence(msg.SigMsg.Sequence),
|
lnwallet.WithCustomSequence(mempool.MaxRBFSequence),
|
||||||
}
|
}
|
||||||
|
|
||||||
chancloserLog.Infof("responding to close w/ local_addr=%x, "+
|
chancloserLog.Infof("responding to close w/ local_addr=%x, "+
|
||||||
|
|||||||
@@ -34,9 +34,9 @@ type ClosingComplete struct {
|
|||||||
// channel would like to propose for the close transaction.
|
// channel would like to propose for the close transaction.
|
||||||
FeeSatoshis btcutil.Amount
|
FeeSatoshis btcutil.Amount
|
||||||
|
|
||||||
// Sequence is the sequence number to be used in the input spending the
|
// LockTime is the locktime number to be used in the input spending the
|
||||||
// funding transaction.
|
// funding transaction.
|
||||||
Sequence uint32
|
LockTime uint32
|
||||||
|
|
||||||
// ClosingSigs houses the 3 possible signatures that can be sent.
|
// ClosingSigs houses the 3 possible signatures that can be sent.
|
||||||
ClosingSigs
|
ClosingSigs
|
||||||
@@ -79,7 +79,7 @@ func decodeClosingSigs(c *ClosingSigs, tlvRecords ExtraOpaqueData) error {
|
|||||||
// passed io.Reader.
|
// passed io.Reader.
|
||||||
func (c *ClosingComplete) Decode(r io.Reader, _ uint32) error {
|
func (c *ClosingComplete) Decode(r io.Reader, _ uint32) error {
|
||||||
// First, read out all the fields that are hard coded into the message.
|
// First, read out all the fields that are hard coded into the message.
|
||||||
err := ReadElements(r, &c.ChannelID, &c.FeeSatoshis, &c.Sequence)
|
err := ReadElements(r, &c.ChannelID, &c.FeeSatoshis, &c.LockTime)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -129,7 +129,7 @@ func (c *ClosingComplete) Encode(w *bytes.Buffer, _ uint32) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := WriteUint32(w, c.Sequence); err != nil {
|
if err := WriteUint32(w, c.LockTime); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1352,7 +1352,7 @@ func TestLightningWireProtocol(t *testing.T) {
|
|||||||
req := ClosingComplete{
|
req := ClosingComplete{
|
||||||
ChannelID: ChannelID(c),
|
ChannelID: ChannelID(c),
|
||||||
FeeSatoshis: btcutil.Amount(r.Int63()),
|
FeeSatoshis: btcutil.Amount(r.Int63()),
|
||||||
Sequence: uint32(r.Int63()),
|
LockTime: uint32(r.Int63()),
|
||||||
ClosingSigs: ClosingSigs{},
|
ClosingSigs: ClosingSigs{},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2275,6 +2275,13 @@ func messageSummary(msg lnwire.Message) string {
|
|||||||
return fmt.Sprintf("chan_id=%v, script=%x", msg.ChannelID,
|
return fmt.Sprintf("chan_id=%v, script=%x", msg.ChannelID,
|
||||||
msg.Address[:])
|
msg.Address[:])
|
||||||
|
|
||||||
|
case *lnwire.ClosingComplete:
|
||||||
|
return fmt.Sprintf("chan_id=%v, fee_sat=%v, locktime=%v",
|
||||||
|
msg.ChannelID, msg.FeeSatoshis, msg.LockTime)
|
||||||
|
|
||||||
|
case *lnwire.ClosingSig:
|
||||||
|
return fmt.Sprintf("chan_id=%v", msg.ChannelID)
|
||||||
|
|
||||||
case *lnwire.ClosingSigned:
|
case *lnwire.ClosingSigned:
|
||||||
return fmt.Sprintf("chan_id=%v, fee_sat=%v", msg.ChannelID,
|
return fmt.Sprintf("chan_id=%v, fee_sat=%v", msg.ChannelID,
|
||||||
msg.FeeSatoshis)
|
msg.FeeSatoshis)
|
||||||
|
|||||||
Reference in new issue
Block a user