lnwire: shift fields in NodeAnnouncment to match recent BOLT-0007 changes

This commit modifies the NodeAnnouncement message to ensure that it
matches the current spec ordering. The spec was recently modified to
place the feature vector first to allow for future changes to the
fields to be forwards compatible.
This commit is contained in:
Olaoluwa Osuntokun 2017-08-21 22:42:50 -07:00
parent 96696ccd99
commit 29af6e6932
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
2 changed files with 18 additions and 17 deletions

View File

@ -384,14 +384,14 @@ func TestLightningWireProtocol(t *testing.T) {
req := NodeAnnouncement{
Signature: testSig,
Features: randFeatureVector(r),
Timestamp: uint32(r.Int31()),
Alias: newAlias(a[:]),
Alias: a,
RGBColor: RGB{
red: uint8(r.Int31()),
green: uint8(r.Int31()),
blue: uint8(r.Int31()),
},
Features: randFeatureVector(r),
Addresses: testAddrs,
}
req.Features.featuresMap = nil

View File

@ -58,26 +58,25 @@ type NodeAnnouncement struct {
// Signature is used to prove the ownership of node id.
Signature *btcec.Signature
// Timestamp allows ordering in the case of multiple
// announcements.
// Features is the list of protocol features this node supports.
Features *FeatureVector
// Timestamp allows ordering in the case of multiple announcements.
Timestamp uint32
// NodeID is a public key which is used as node identification.
NodeID *btcec.PublicKey
// RGBColor is used to customize their node's appearance in
// maps and graphs
// RGBColor is used to customize their node's appearance in maps and
// graphs
RGBColor RGB
// Features is the list of protocol features this node supports.
Features *FeatureVector
// Alias is used to customize their node's appearance in maps and
// graphs
Alias NodeAlias
// Address includes two specification fields: 'ipv6' and 'port' on which
// the node is accepting incoming connections.
// Address includes two specification fields: 'ipv6' and 'port' on
// which the node is accepting incoming connections.
Addresses []net.Addr
}
@ -92,11 +91,11 @@ var _ Message = (*NodeAnnouncement)(nil)
func (a *NodeAnnouncement) Decode(r io.Reader, pver uint32) error {
return readElements(r,
&a.Signature,
&a.Features,
&a.Timestamp,
&a.NodeID,
&a.RGBColor,
&a.Alias,
&a.Features,
a.Alias[:],
&a.Addresses,
)
}
@ -107,11 +106,11 @@ func (a *NodeAnnouncement) Decode(r io.Reader, pver uint32) error {
func (a *NodeAnnouncement) Encode(w io.Writer, pver uint32) error {
return writeElements(w,
a.Signature,
a.Features,
a.Timestamp,
a.NodeID,
a.RGBColor,
a.Alias,
a.Features,
a.Alias[:],
a.Addresses,
)
}
@ -138,16 +137,18 @@ func (a *NodeAnnouncement) DataToSign() ([]byte, error) {
// We should not include the signatures itself.
var w bytes.Buffer
err := writeElements(&w,
a.Features,
a.Timestamp,
a.NodeID,
a.RGBColor,
a.Alias,
a.Features,
a.Alias[:],
a.Addresses,
)
if err != nil {
return nil, err
}
// TODO(roasbeef): also capture the excess bytes in msg padded out?
return w.Bytes(), nil
}