diff --git a/channeldb/graph.go b/channeldb/graph.go index 19a19439..dba5108c 100644 --- a/channeldb/graph.go +++ b/channeldb/graph.go @@ -3372,7 +3372,7 @@ func serializeChanEdgePolicy(w io.Writer, edge *ChannelEdgePolicy, // of the opaque data. // TODO(halseth): clean up when moving to TLV. var opaqueBuf bytes.Buffer - if edge.MessageFlags&lnwire.ChanUpdateOptionMaxHtlc != 0 { + if edge.MessageFlags.HasMaxHtlc() { err := binary.Write(&opaqueBuf, byteOrder, uint64(edge.MaxHTLC)) if err != nil { return err @@ -3465,7 +3465,7 @@ func deserializeChanEdgePolicy(r io.Reader, } // See if optional fields are present. - if edge.MessageFlags&lnwire.ChanUpdateOptionMaxHtlc != 0 { + if edge.MessageFlags.HasMaxHtlc() { // The max_htlc field should be at the beginning of the opaque // bytes. opq := edge.ExtraOpaqueData diff --git a/discovery/gossiper.go b/discovery/gossiper.go index 1cd405d0..a8f15440 100644 --- a/discovery/gossiper.go +++ b/discovery/gossiper.go @@ -1324,7 +1324,7 @@ func (d *AuthenticatedGossiper) retransmitStaleChannels() error { // If this edge has a ChannelUpdate that was created before the // introduction of the MaxHTLC field, then we'll update this // edge to propagate this information in the network. - if edge.MessageFlags&lnwire.ChanUpdateOptionMaxHtlc == 0 { + if !edge.MessageFlags.HasMaxHtlc() { edgesToUpdate = append(edgesToUpdate, updateTuple{ info: info, edge: edge, @@ -2520,7 +2520,7 @@ func (d *AuthenticatedGossiper) updateChannel(info *channeldb.ChannelEdgeInfo, // We'll make sure we support the new max_htlc field if not already // present. - if edge.MessageFlags&lnwire.ChanUpdateOptionMaxHtlc == 0 { + if !edge.MessageFlags.HasMaxHtlc() { edge.MessageFlags |= lnwire.ChanUpdateOptionMaxHtlc edge.MaxHTLC = lnwire.NewMSatFromSatoshis(info.Capacity) } diff --git a/lnwire/channel_update.go b/lnwire/channel_update.go index 1788cdc7..fd627646 100644 --- a/lnwire/channel_update.go +++ b/lnwire/channel_update.go @@ -24,6 +24,12 @@ func (c ChanUpdateMsgFlags) String() string { return fmt.Sprintf("%08b", c) } +// HasMaxHtlc returns true if the htlc_maximum_msat option bit is set in the +// message flags. +func (c ChanUpdateMsgFlags) HasMaxHtlc() bool { + return c&ChanUpdateOptionMaxHtlc != 0 +} + // ChanUpdateChanFlags is a bitfield that signals various options concerning a // particular channel edge. Each bit is to be examined in order to determine // how the ChannelUpdate message is to be interpreted. @@ -139,7 +145,7 @@ func (a *ChannelUpdate) Decode(r io.Reader, pver uint32) error { } // Now check whether the max HTLC field is present and read it if so. - if a.MessageFlags&ChanUpdateOptionMaxHtlc != 0 { + if a.MessageFlags.HasMaxHtlc() { if err := ReadElements(r, &a.HtlcMaximumMsat); err != nil { return err } @@ -183,7 +189,7 @@ func (a *ChannelUpdate) Encode(w io.Writer, pver uint32) error { // Now append optional fields if they are set. Currently, the only // optional field is max HTLC. - if a.MessageFlags&ChanUpdateOptionMaxHtlc != 0 { + if a.MessageFlags.HasMaxHtlc() { if err := WriteElements(w, a.HtlcMaximumMsat); err != nil { return err } @@ -232,7 +238,7 @@ func (a *ChannelUpdate) DataToSign() ([]byte, error) { // Now append optional fields if they are set. Currently, the only // optional field is max HTLC. - if a.MessageFlags&ChanUpdateOptionMaxHtlc != 0 { + if a.MessageFlags.HasMaxHtlc() { if err := WriteElements(&w, a.HtlcMaximumMsat); err != nil { return nil, err } diff --git a/routing/ann_validation.go b/routing/ann_validation.go index 5c70dd86..4b304b5a 100644 --- a/routing/ann_validation.go +++ b/routing/ann_validation.go @@ -156,7 +156,7 @@ func ValidateChannelUpdateAnn(pubKey *btcec.PublicKey, capacity btcutil.Amount, func validateOptionalFields(capacity btcutil.Amount, msg *lnwire.ChannelUpdate) error { - if msg.MessageFlags&lnwire.ChanUpdateOptionMaxHtlc != 0 { + if msg.MessageFlags.HasMaxHtlc() { maxHtlc := msg.HtlcMaximumMsat if maxHtlc == 0 || maxHtlc < msg.HtlcMinimumMsat { return errors.Errorf("invalid max htlc for channel "+