diff --git a/lnwallet/chancloser/rbf_coop_transitions.go b/lnwallet/chancloser/rbf_coop_transitions.go index 2667b7e4a..01ab5c32f 100644 --- a/lnwallet/chancloser/rbf_coop_transitions.go +++ b/lnwallet/chancloser/rbf_coop_transitions.go @@ -722,12 +722,13 @@ func (l *LocalCloseStart) ProcessEvent(event ProtocolEvent, env *Environment, // TODO(roasbeef): type alias for protocol event sendEvent := protofsm.DaemonEventSet{&protofsm.SendMsgEvent[ProtocolEvent]{ //nolint:ll TargetPeer: env.ChanPeer, - // TODO(roasbeef): mew new func Msgs: []lnwire.Message{&lnwire.ClosingComplete{ - ChannelID: env.ChanID, - FeeSatoshis: absoluteFee, - LockTime: env.BlockHeight, - ClosingSigs: closingSigs, + ChannelID: env.ChanID, + CloserScript: l.LocalDeliveryScript, + CloseeScript: l.RemoteDeliveryScript, + FeeSatoshis: absoluteFee, + LockTime: env.BlockHeight, + ClosingSigs: closingSigs, }}, }} @@ -991,8 +992,12 @@ func (l *RemoteCloseStart) ProcessEvent(event ProtocolEvent, env *Environment, sendEvent := &protofsm.SendMsgEvent[ProtocolEvent]{ TargetPeer: env.ChanPeer, Msgs: []lnwire.Message{&lnwire.ClosingSig{ - ChannelID: env.ChanID, - ClosingSigs: closingSigs, + ChannelID: env.ChanID, + CloserScript: l.RemoteDeliveryScript, + CloseeScript: l.LocalDeliveryScript, + FeeSatoshis: msg.SigMsg.FeeSatoshis, + LockTime: msg.SigMsg.LockTime, + ClosingSigs: closingSigs, }}, } broadcastEvent := &protofsm.BroadcastTxn{ diff --git a/lnwire/closing_complete.go b/lnwire/closing_complete.go index c16760a4e..4d390fd6f 100644 --- a/lnwire/closing_complete.go +++ b/lnwire/closing_complete.go @@ -30,6 +30,14 @@ type ClosingComplete struct { // ChannelID serves to identify which channel is to be closed. ChannelID ChannelID + // CloserScript is the script to which the channel funds will be paid + // for the closer (the person sending the ClosingComplete) message. + CloserScript DeliveryAddress + + // CloseeScript is the script to which the channel funds will be paid + // (the person receiving the ClosingComplete message). + CloseeScript DeliveryAddress + // FeeSatoshis is the total fee in satoshis that the party to the // channel would like to propose for the close transaction. FeeSatoshis btcutil.Amount @@ -79,7 +87,10 @@ func decodeClosingSigs(c *ClosingSigs, tlvRecords ExtraOpaqueData) error { // passed io.Reader. func (c *ClosingComplete) Decode(r io.Reader, _ uint32) error { // First, read out all the fields that are hard coded into the message. - err := ReadElements(r, &c.ChannelID, &c.FeeSatoshis, &c.LockTime) + err := ReadElements( + r, &c.ChannelID, &c.CloserScript, &c.CloseeScript, + &c.FeeSatoshis, &c.LockTime, + ) if err != nil { return err } @@ -125,6 +136,13 @@ func (c *ClosingComplete) Encode(w *bytes.Buffer, _ uint32) error { return err } + if err := WriteDeliveryAddress(w, c.CloserScript); err != nil { + return err + } + if err := WriteDeliveryAddress(w, c.CloseeScript); err != nil { + return err + } + if err := WriteSatoshi(w, c.FeeSatoshis); err != nil { return err } diff --git a/lnwire/closing_sig.go b/lnwire/closing_sig.go index df160d12e..2c73fa720 100644 --- a/lnwire/closing_sig.go +++ b/lnwire/closing_sig.go @@ -3,6 +3,8 @@ package lnwire import ( "bytes" "io" + + "github.com/btcsuite/btcd/btcutil" ) // ClosingSig is sent in response to a ClosingComplete message. It carries the @@ -11,6 +13,22 @@ type ClosingSig struct { // ChannelID serves to identify which channel is to be closed. ChannelID ChannelID + // CloserScript is the script to which the channel funds will be paid + // for the closer (the person sending the ClosingComplete) message. + CloserScript DeliveryAddress + + // CloseeScript is the script to which the channel funds will be paid + // (the person receiving the ClosingComplete message). + CloseeScript DeliveryAddress + + // FeeSatoshis is the total fee in satoshis that the party to the + // channel proposed for the close transaction. + FeeSatoshis btcutil.Amount + + // LockTime is the locktime number to be used in the input spending the + // funding transaction. + LockTime uint32 + // ClosingSigs houses the 3 possible signatures that can be sent. ClosingSigs @@ -24,7 +42,10 @@ type ClosingSig struct { // io.Reader. func (c *ClosingSig) Decode(r io.Reader, _ uint32) error { // First, read out all the fields that are hard coded into the message. - err := ReadElements(r, &c.ChannelID) + err := ReadElements( + r, &c.ChannelID, &c.CloserScript, &c.CloseeScript, + &c.FeeSatoshis, &c.LockTime, + ) if err != nil { return err } @@ -53,6 +74,21 @@ func (c *ClosingSig) Encode(w *bytes.Buffer, _ uint32) error { return err } + if err := WriteDeliveryAddress(w, c.CloserScript); err != nil { + return err + } + if err := WriteDeliveryAddress(w, c.CloseeScript); err != nil { + return err + } + + if err := WriteSatoshi(w, c.FeeSatoshis); err != nil { + return err + } + + if err := WriteUint32(w, c.LockTime); err != nil { + return err + } + recordProducers := closingSigRecords(&c.ClosingSigs) err := EncodeMessageExtraData(&c.ExtraData, recordProducers...) diff --git a/lnwire/lnwire_test.go b/lnwire/lnwire_test.go index db3ffd39d..123689902 100644 --- a/lnwire/lnwire_test.go +++ b/lnwire/lnwire_test.go @@ -1355,6 +1355,18 @@ func TestLightningWireProtocol(t *testing.T) { LockTime: uint32(r.Int63()), ClosingSigs: ClosingSigs{}, } + req.CloserScript, err = randDeliveryAddress(r) + if err != nil { + t.Fatalf("unable to generate delivery "+ + "address: %v", err) + return + } + req.CloseeScript, err = randDeliveryAddress(r) + if err != nil { + t.Fatalf("unable to generate delivery "+ + "address: %v", err) + return + } if r.Intn(2) == 0 { sig := req.CloserNoClosee.Zero() @@ -1403,6 +1415,20 @@ func TestLightningWireProtocol(t *testing.T) { req := ClosingSig{ ChannelID: ChannelID(c), ClosingSigs: ClosingSigs{}, + FeeSatoshis: btcutil.Amount(r.Int63()), + LockTime: uint32(r.Int63()), + } + req.CloserScript, err = randDeliveryAddress(r) + if err != nil { + t.Fatalf("unable to generate delivery "+ + "address: %v", err) + return + } + req.CloseeScript, err = randDeliveryAddress(r) + if err != nil { + t.Fatalf("unable to generate delivery "+ + "address: %v", err) + return } if r.Intn(2) == 0 {