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

lightningnetwork / lnd / 12118348650

02 Dec 2024 11:25AM UTC coverage: 58.552% (-0.4%) from 58.977%
12118348650

Pull #9175

github

ellemouton
lnwire: add NodeAnnouncement2
Pull Request #9175: lnwire+netann: update structure of g175 messages to be pure TLV

405 of 571 new or added lines in 11 files covered. (70.93%)

1754 existing lines in 33 files now uncovered.

133774 of 228469 relevant lines covered (58.55%)

19422.52 hits per line

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

54.9
/lnwire/announcement_signatures_2.go
1
package lnwire
2

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

7
        "github.com/lightningnetwork/lnd/tlv"
8
)
9

10
// AnnounceSignatures2 is a direct message between two endpoints of a
11
// channel and serves as an opt-in mechanism to allow the announcement of
12
// a taproot channel to the rest of the network. It contains the necessary
13
// signatures by the sender to construct the channel_announcement_2 message.
14
type AnnounceSignatures2 struct {
15
        // ChannelID is the unique description of the funding transaction.
16
        // Channel id is better for users and debugging and short channel id is
17
        // used for quick test on existence of the particular utxo inside the
18
        // blockchain, because it contains information about block.
19
        ChannelID tlv.RecordT[tlv.TlvType0, ChannelID]
20

21
        // ShortChannelID is the unique description of the funding transaction.
22
        // It is constructed with the most significant 3 bytes as the block
23
        // height, the next 3 bytes indicating the transaction index within the
24
        // block, and the least significant two bytes indicating the output
25
        // index which pays to the channel.
26
        ShortChannelID tlv.RecordT[tlv.TlvType2, ShortChannelID]
27

28
        // PartialSignature is the combination of the partial Schnorr signature
29
        // created for the node's bitcoin key with the partial signature created
30
        // for the node's node ID key.
31
        PartialSignature tlv.RecordT[tlv.TlvType4, PartialSig]
32

33
        // Any extra fields in the signed range that we do not yet know about,
34
        // but we need to keep them for signature validation and to produce a
35
        // valid message.
36
        ExtraSignedFields
37
}
38

39
// NewAnnSigs2 is a constructor for AnnounceSignatures2.
40
func NewAnnSigs2(chanID ChannelID, scid ShortChannelID,
NEW
41
        partialSig PartialSig) *AnnounceSignatures2 {
×
NEW
42

×
NEW
43
        return &AnnounceSignatures2{
×
NEW
44
                ChannelID: tlv.NewRecordT[tlv.TlvType0, ChannelID](chanID),
×
NEW
45
                ShortChannelID: tlv.NewRecordT[tlv.TlvType2, ShortChannelID](
×
NEW
46
                        scid,
×
NEW
47
                ),
×
NEW
48
                PartialSignature: tlv.NewRecordT[tlv.TlvType4, PartialSig](
×
NEW
49
                        partialSig,
×
NEW
50
                ),
×
NEW
51
                ExtraSignedFields: make(ExtraSignedFields),
×
NEW
52
        }
×
UNCOV
53
}
×
54

55
// A compile time check to ensure AnnounceSignatures2 implements the
56
// lnwire.Message interface.
57
var _ Message = (*AnnounceSignatures2)(nil)
58

59
// Decode deserializes a serialized AnnounceSignatures2 stored in the passed
60
// io.Reader observing the specified protocol version.
61
//
62
// This is part of the lnwire.Message interface.
63
func (a *AnnounceSignatures2) Decode(r io.Reader, _ uint32) error {
100✔
64
        stream, err := tlv.NewStream(ProduceRecordsSorted(
100✔
65
                &a.ChannelID, &a.ShortChannelID, &a.PartialSignature,
100✔
66
        )...)
100✔
67
        if err != nil {
100✔
68
                return err
×
69
        }
×
70

71
        typeMap, err := stream.DecodeWithParsedTypesP2P(r)
100✔
72
        if err != nil {
100✔
73
                return err
×
74
        }
×
75

76
        a.ExtraSignedFields = ExtraSignedFieldsFromTypeMap(typeMap)
100✔
77

100✔
78
        return nil
100✔
79
}
80

81
// Encode serializes the target AnnounceSignatures2 into the passed io.Writer
82
// observing the protocol version specified.
83
//
84
// This is part of the lnwire.Message interface.
85
func (a *AnnounceSignatures2) Encode(w *bytes.Buffer, _ uint32) error {
100✔
86
        return EncodePureTLVMessage(a, w)
100✔
87
}
100✔
88

89
// MsgType returns the integer uniquely identifying this message type on the
90
// wire.
91
//
92
// This is part of the lnwire.Message interface.
93
func (a *AnnounceSignatures2) MsgType() MessageType {
100✔
94
        return MsgAnnounceSignatures2
100✔
95
}
100✔
96

97
// AllRecords returns all the TLV records for the message. This will include all
98
// the records we know about along with any that we don't know about but that
99
// fall in the signed TLV range.
100
//
101
// NOTE: this is part of the PureTLVMessage interface.
102
func (a *AnnounceSignatures2) AllRecords() []tlv.Record {
100✔
103
        recordProducers := []tlv.RecordProducer{
100✔
104
                &a.ChannelID, &a.ShortChannelID,
100✔
105
                &a.PartialSignature,
100✔
106
        }
100✔
107

100✔
108
        recordProducers = append(recordProducers, RecordsAsProducers(
100✔
109
                tlv.MapToRecords(a.ExtraSignedFields),
100✔
110
        )...)
100✔
111

100✔
112
        return ProduceRecordsSorted(recordProducers...)
100✔
113
}
100✔
114

115
// SCID returns the ShortChannelID of the channel.
116
//
117
// NOTE: this is part of the AnnounceSignatures interface.
118
func (a *AnnounceSignatures2) SCID() ShortChannelID {
×
NEW
119
        return a.ShortChannelID.Val
×
120
}
×
121

122
// ChanID returns the ChannelID identifying the channel.
123
//
124
// NOTE: this is part of the AnnounceSignatures interface.
125
func (a *AnnounceSignatures2) ChanID() ChannelID {
×
NEW
126
        return a.ChannelID.Val
×
127
}
×
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