lnwire: fix serialization order of global+local features in Init msg

Fixes #428.
This commit is contained in:
Olaoluwa Osuntokun 2017-11-17 13:26:39 -08:00
parent 4168c97a27
commit 53f1743be0
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
2 changed files with 14 additions and 14 deletions

@ -16,9 +16,9 @@ import (
type FeatureBit uint16 type FeatureBit uint16
const ( const (
// InitialRoutingSync is a local feature bit meaning that the receiving node // InitialRoutingSync is a local feature bit meaning that the receiving
// should send a complete dump of routing information when a new connection // node should send a complete dump of routing information when a new
// is established. // connection is established.
InitialRoutingSync FeatureBit = 3 InitialRoutingSync FeatureBit = 3
// maxAllowedSize is a maximum allowed size of feature vector. // maxAllowedSize is a maximum allowed size of feature vector.
@ -51,10 +51,10 @@ var LocalFeatures = map[FeatureBit]string{
// description of these feature bits is provided in the BOLT-09 specification. // description of these feature bits is provided in the BOLT-09 specification.
var GlobalFeatures map[FeatureBit]string var GlobalFeatures map[FeatureBit]string
// RawFeatureVector represents a set of feature bits as defined in BOLT-09. // RawFeatureVector represents a set of feature bits as defined in BOLT-09. A
// A RawFeatureVector itself just stores a set of bit flags but can be used to // RawFeatureVector itself just stores a set of bit flags but can be used to
// construct a FeatureVector which binds meaning to each bit. Feature vectors // construct a FeatureVector which binds meaning to each bit. Feature vectors
//can be serialized and deserialized to/from a byte representation that is // can be serialized and deserialized to/from a byte representation that is
// transmitted in Lightning network messages. // transmitted in Lightning network messages.
type RawFeatureVector struct { type RawFeatureVector struct {
features map[FeatureBit]bool features map[FeatureBit]bool
@ -169,9 +169,9 @@ type FeatureVector struct {
featureNames map[FeatureBit]string featureNames map[FeatureBit]string
} }
// NewFeatureVector constructs a new FeatureVector from a raw feature vector and // NewFeatureVector constructs a new FeatureVector from a raw feature vector
// mapping of feature definitions. If the feature vector argument is nil, a new // and mapping of feature definitions. If the feature vector argument is nil, a
// one will be constructed with no enabled features. // new one will be constructed with no enabled features.
func NewFeatureVector(featureVector *RawFeatureVector, func NewFeatureVector(featureVector *RawFeatureVector,
featureNames map[FeatureBit]string) *FeatureVector { featureNames map[FeatureBit]string) *FeatureVector {
@ -194,9 +194,9 @@ func (fv *FeatureVector) HasFeature(feature FeatureBit) bool {
(fv.isFeatureBitPair(feature) && fv.IsSet(feature^1)) (fv.isFeatureBitPair(feature) && fv.IsSet(feature^1))
} }
// UnknownRequiredFeatures returns a list of feature bits set in the vector that // UnknownRequiredFeatures returns a list of feature bits set in the vector
// are unknown and in an even bit position. Feature bits with an even index must // that are unknown and in an even bit position. Feature bits with an even
// be known to a node receiving the feature vector in a message. // index must be known to a node receiving the feature vector in a message.
func (fv *FeatureVector) UnknownRequiredFeatures() []FeatureBit { func (fv *FeatureVector) UnknownRequiredFeatures() []FeatureBit {
var unknown []FeatureBit var unknown []FeatureBit
for feature := range fv.features { for feature := range fv.features {

@ -34,8 +34,8 @@ var _ Message = (*Init)(nil)
// This is part of the lnwire.Message interface. // This is part of the lnwire.Message interface.
func (msg *Init) Decode(r io.Reader, pver uint32) error { func (msg *Init) Decode(r io.Reader, pver uint32) error {
return readElements(r, return readElements(r,
&msg.LocalFeatures,
&msg.GlobalFeatures, &msg.GlobalFeatures,
&msg.LocalFeatures,
) )
} }
@ -45,8 +45,8 @@ func (msg *Init) Decode(r io.Reader, pver uint32) error {
// This is part of the lnwire.Message interface. // This is part of the lnwire.Message interface.
func (msg *Init) Encode(w io.Writer, pver uint32) error { func (msg *Init) Encode(w io.Writer, pver uint32) error {
return writeElements(w, return writeElements(w,
msg.LocalFeatures,
msg.GlobalFeatures, msg.GlobalFeatures,
msg.LocalFeatures,
) )
} }