mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-13 19:16:56 +01:00
lnwire: update closing_complete and closing_sig to latest spec draft
Both these messages now carry the address of both parties, so you can update an address without needing to send shutdown again.
This commit is contained in:
parent
7fc62840de
commit
b34ff32dda
4 changed files with 94 additions and 9 deletions
|
@ -722,9 +722,10 @@ 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,
|
||||
CloserScript: l.LocalDeliveryScript,
|
||||
CloseeScript: l.RemoteDeliveryScript,
|
||||
FeeSatoshis: absoluteFee,
|
||||
LockTime: env.BlockHeight,
|
||||
ClosingSigs: closingSigs,
|
||||
|
@ -992,6 +993,10 @@ func (l *RemoteCloseStart) ProcessEvent(event ProtocolEvent, env *Environment,
|
|||
TargetPeer: env.ChanPeer,
|
||||
Msgs: []lnwire.Message{&lnwire.ClosingSig{
|
||||
ChannelID: env.ChanID,
|
||||
CloserScript: l.RemoteDeliveryScript,
|
||||
CloseeScript: l.LocalDeliveryScript,
|
||||
FeeSatoshis: msg.SigMsg.FeeSatoshis,
|
||||
LockTime: msg.SigMsg.LockTime,
|
||||
ClosingSigs: closingSigs,
|
||||
}},
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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...)
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue