• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 13536249039

26 Feb 2025 03:42AM UTC coverage: 57.462% (-1.4%) from 58.835%
13536249039

Pull #8453

github

Roasbeef
peer: update chooseDeliveryScript to gen script if needed

In this commit, we update `chooseDeliveryScript` to generate a new
script if needed. This allows us to fold in a few other lines that
always followed this function into this expanded function.

The tests have been updated accordingly.
Pull Request #8453: [4/4] - multi: integrate new rbf coop close FSM into the existing peer flow

275 of 1318 new or added lines in 22 files covered. (20.86%)

19521 existing lines in 257 files now uncovered.

103858 of 180741 relevant lines covered (57.46%)

24750.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

65.22
/lnwire/closing_sig.go
1
package lnwire
2

3
import (
4
        "bytes"
5
        "io"
6

7
        "github.com/btcsuite/btcd/btcutil"
8
)
9

10
// ClosingSig is sent in response to a ClosingComplete message. It carries the
11
// signatures of the closee to the closer.
12
type ClosingSig struct {
13
        // ChannelID serves to identify which channel is to be closed.
14
        ChannelID ChannelID
15

16
        // CloserScript is the script to which the channel funds will be paid
17
        // for the closer (the person sending the ClosingComplete) message.
18
        CloserScript DeliveryAddress
19

20
        // CloseeScript is the script to which the channel funds will be paid
21
        // (the person receiving the ClosingComplete message).
22
        CloseeScript DeliveryAddress
23

24
        // FeeSatoshis is the total fee in satoshis that the party to the
25
        // channel proposed for the close transaction.
26
        FeeSatoshis btcutil.Amount
27

28
        // LockTime is the locktime number to be used in the input spending the
29
        // funding transaction.
30
        LockTime uint32
31

32
        // ClosingSigs houses the 3 possible signatures that can be sent.
33
        ClosingSigs
34

35
        // ExtraData is the set of data that was appended to this message to
36
        // fill out the full maximum transport message size. These fields can
37
        // be used to specify optional data such as custom TLV fields.
38
        ExtraData ExtraOpaqueData
39
}
40

41
// Decode deserializes a serialized ClosingSig message stored in the passed
42
// io.Reader.
43
func (c *ClosingSig) Decode(r io.Reader, _ uint32) error {
153✔
44
        // First, read out all the fields that are hard coded into the message.
153✔
45
        err := ReadElements(
153✔
46
                r, &c.ChannelID, &c.CloserScript, &c.CloseeScript,
153✔
47
                &c.FeeSatoshis, &c.LockTime,
153✔
48
        )
153✔
49
        if err != nil {
206✔
50
                return err
53✔
51
        }
53✔
52

53
        // With the hard coded messages read, we'll now read out the TLV fields
54
        // of the message.
55
        var tlvRecords ExtraOpaqueData
100✔
56
        if err := ReadElements(r, &tlvRecords); err != nil {
100✔
57
                return err
×
58
        }
×
59

60
        if err := decodeClosingSigs(&c.ClosingSigs, tlvRecords); err != nil {
100✔
UNCOV
61
                return err
×
UNCOV
62
        }
×
63

64
        if len(tlvRecords) != 0 {
190✔
65
                c.ExtraData = tlvRecords
90✔
66
        }
90✔
67

68
        return nil
100✔
69
}
70

71
// Encode serializes the target ClosingSig into the passed io.Writer.
72
func (c *ClosingSig) Encode(w *bytes.Buffer, _ uint32) error {
100✔
73
        if err := WriteChannelID(w, c.ChannelID); err != nil {
100✔
74
                return err
×
75
        }
×
76

77
        if err := WriteDeliveryAddress(w, c.CloserScript); err != nil {
100✔
NEW
78
                return err
×
NEW
79
        }
×
80
        if err := WriteDeliveryAddress(w, c.CloseeScript); err != nil {
100✔
NEW
81
                return err
×
NEW
82
        }
×
83

84
        if err := WriteSatoshi(w, c.FeeSatoshis); err != nil {
100✔
NEW
85
                return err
×
NEW
86
        }
×
87

88
        if err := WriteUint32(w, c.LockTime); err != nil {
100✔
NEW
89
                return err
×
NEW
90
        }
×
91

92
        recordProducers := closingSigRecords(&c.ClosingSigs)
100✔
93

100✔
94
        err := EncodeMessageExtraData(&c.ExtraData, recordProducers...)
100✔
95
        if err != nil {
100✔
96
                return err
×
97
        }
×
98

99
        return WriteBytes(w, c.ExtraData)
100✔
100
}
101

102
// MsgType returns the uint32 code which uniquely identifies this message as a
103
// ClosingSig message on the wire.
104
//
105
// This is part of the lnwire.Message interface.
106
func (c *ClosingSig) MsgType() MessageType {
100✔
107
        return MsgClosingSig
100✔
108
}
100✔
109

110
// A compile time check to ensure ClosingSig implements the lnwire.Message
111
// interface.
112
var _ Message = (*ClosingSig)(nil)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc