multi: rename due to required maxHTLC bit

We rename `ChanUpdateOptionMaxHtlc` to `ChanUpdateRequiredMaxHtlc`
as with the latest changes it is now required.

Similarly, rename `validateOptionalFields` to
`ValidateChannelUpdateFields`, export it to use it in a later commit.
This commit is contained in:
bitromortac 2023-02-17 18:36:50 +01:00
parent 581e195bfe
commit dd5273c88c
No known key found for this signature in database
GPG key ID: 1965063FC13BEBE2
14 changed files with 24 additions and 23 deletions

View file

@ -2924,7 +2924,7 @@ func TestEdgePolicyMissingMaxHtcl(t *testing.T) {
// Set the max_htlc field. The extra bytes added to the serialization // Set the max_htlc field. The extra bytes added to the serialization
// will be the opaque data containing the serialized field. // will be the opaque data containing the serialized field.
edge1.MessageFlags = lnwire.ChanUpdateOptionMaxHtlc edge1.MessageFlags = lnwire.ChanUpdateRequiredMaxHtlc
edge1.MaxHTLC = 13928598 edge1.MaxHTLC = 13928598
var b2 bytes.Buffer var b2 bytes.Buffer
err = serializeChanEdgePolicy(&b2, edge1, to) err = serializeChanEdgePolicy(&b2, edge1, to)

View file

@ -14,9 +14,9 @@ import (
type ChanUpdateMsgFlags uint8 type ChanUpdateMsgFlags uint8
const ( const (
// ChanUpdateOptionMaxHtlc is a bit that indicates whether the // ChanUpdateRequiredMaxHtlc is a bit that indicates whether the
// optional htlc_maximum_msat field is present in this ChannelUpdate. // optional htlc_maximum_msat field is present in this ChannelUpdate.
ChanUpdateOptionMaxHtlc ChanUpdateMsgFlags = 1 << iota ChanUpdateRequiredMaxHtlc ChanUpdateMsgFlags = 1 << iota
) )
// String returns the bitfield flags as a string. // String returns the bitfield flags as a string.
@ -27,7 +27,7 @@ func (c ChanUpdateMsgFlags) String() string {
// HasMaxHtlc returns true if the htlc_maximum_msat option bit is set in the // HasMaxHtlc returns true if the htlc_maximum_msat option bit is set in the
// message flags. // message flags.
func (c ChanUpdateMsgFlags) HasMaxHtlc() bool { func (c ChanUpdateMsgFlags) HasMaxHtlc() bool {
return c&ChanUpdateOptionMaxHtlc != 0 return c&ChanUpdateRequiredMaxHtlc != 0
} }
// ChanUpdateChanFlags is a bitfield that signals various options concerning a // ChanUpdateChanFlags is a bitfield that signals various options concerning a

View file

@ -1520,7 +1520,7 @@ func (d *AuthenticatedGossiper) retransmitStaleAnns(now time.Time) error {
if !edge.MessageFlags.HasMaxHtlc() { if !edge.MessageFlags.HasMaxHtlc() {
// We'll make sure we support the new max_htlc field if // We'll make sure we support the new max_htlc field if
// not already present. // not already present.
edge.MessageFlags |= lnwire.ChanUpdateOptionMaxHtlc edge.MessageFlags |= lnwire.ChanUpdateRequiredMaxHtlc
edge.MaxHTLC = lnwire.NewMSatFromSatoshis(info.Capacity) edge.MaxHTLC = lnwire.NewMSatFromSatoshis(info.Capacity)
edgesToUpdate = append(edgesToUpdate, updateTuple{ edgesToUpdate = append(edgesToUpdate, updateTuple{

View file

@ -582,7 +582,7 @@ func createUpdateAnnouncement(blockHeight uint32,
BlockHeight: blockHeight, BlockHeight: blockHeight,
}, },
Timestamp: timestamp, Timestamp: timestamp,
MessageFlags: lnwire.ChanUpdateOptionMaxHtlc, MessageFlags: lnwire.ChanUpdateRequiredMaxHtlc,
ChannelFlags: flags, ChannelFlags: flags,
TimeLockDelta: uint16(prand.Int63()), TimeLockDelta: uint16(prand.Int63()),
HtlcMinimumMsat: htlcMinMsat, HtlcMinimumMsat: htlcMinMsat,

View file

@ -3637,7 +3637,7 @@ func (f *Manager) newChanAnnouncement(localPubKey,
// Our channel update message flags will signal that we support the // Our channel update message flags will signal that we support the
// max_htlc field. // max_htlc field.
msgFlags := lnwire.ChanUpdateOptionMaxHtlc msgFlags := lnwire.ChanUpdateRequiredMaxHtlc
// We announce the channel with the default values. Some of // We announce the channel with the default values. Some of
// these values can later be changed by crafting a new ChannelUpdate. // these values can later be changed by crafting a new ChannelUpdate.

View file

@ -311,7 +311,8 @@ func (s *Server) ImportGraph(ctx context.Context,
policy.MaxHTLC = lnwire.MilliSatoshi( policy.MaxHTLC = lnwire.MilliSatoshi(
rpcPolicy.MaxHtlcMsat, rpcPolicy.MaxHtlcMsat,
) )
policy.MessageFlags |= lnwire.ChanUpdateOptionMaxHtlc policy.MessageFlags |=
lnwire.ChanUpdateRequiredMaxHtlc
} }
return policy return policy

View file

@ -13,9 +13,9 @@ import (
type ChanUpdateMsgFlags uint8 type ChanUpdateMsgFlags uint8
const ( const (
// ChanUpdateOptionMaxHtlc is a bit that indicates whether the // ChanUpdateRequiredMaxHtlc is a bit that indicates whether the
// optional htlc_maximum_msat field is present in this ChannelUpdate. // required htlc_maximum_msat field is present in this ChannelUpdate.
ChanUpdateOptionMaxHtlc ChanUpdateMsgFlags = 1 << iota ChanUpdateRequiredMaxHtlc ChanUpdateMsgFlags = 1 << iota
) )
// String returns the bitfield flags as a string. // String returns the bitfield flags as a string.
@ -26,7 +26,7 @@ func (c ChanUpdateMsgFlags) String() string {
// HasMaxHtlc returns true if the htlc_maximum_msat option bit is set in the // HasMaxHtlc returns true if the htlc_maximum_msat option bit is set in the
// message flags. // message flags.
func (c ChanUpdateMsgFlags) HasMaxHtlc() bool { func (c ChanUpdateMsgFlags) HasMaxHtlc() bool {
return c&ChanUpdateOptionMaxHtlc != 0 return c&ChanUpdateRequiredMaxHtlc != 0
} }
// ChanUpdateChanFlags is a bitfield that signals various options concerning a // ChanUpdateChanFlags is a bitfield that signals various options concerning a

View file

@ -772,7 +772,7 @@ func TestLightningWireProtocol(t *testing.T) {
// as being part of the ChannelUpdate, to pass // as being part of the ChannelUpdate, to pass
// serialization tests, as it will be ignored if the bit // serialization tests, as it will be ignored if the bit
// is not set. // is not set.
if msgFlags&ChanUpdateOptionMaxHtlc == 0 { if msgFlags&ChanUpdateRequiredMaxHtlc == 0 {
maxHtlc = 0 maxHtlc = 0
} }

View file

@ -690,7 +690,7 @@ func newMsgChannelUpdate(t testing.TB, r *rand.Rand) *lnwire.ChannelUpdate {
// as being part of the ChannelUpdate, to pass // as being part of the ChannelUpdate, to pass
// serialization tests, as it will be ignored if the bit // serialization tests, as it will be ignored if the bit
// is not set. // is not set.
if msgFlags&lnwire.ChanUpdateOptionMaxHtlc == 0 { if msgFlags&lnwire.ChanUpdateRequiredMaxHtlc == 0 {
maxHtlc = 0 maxHtlc = 0
} }

View file

@ -129,7 +129,7 @@ func ValidateNodeAnn(a *lnwire.NodeAnnouncement) error {
func ValidateChannelUpdateAnn(pubKey *btcec.PublicKey, capacity btcutil.Amount, func ValidateChannelUpdateAnn(pubKey *btcec.PublicKey, capacity btcutil.Amount,
a *lnwire.ChannelUpdate) error { a *lnwire.ChannelUpdate) error {
if err := validateOptionalFields(capacity, a); err != nil { if err := ValidateChannelUpdateFields(capacity, a); err != nil {
return err return err
} }
@ -160,9 +160,9 @@ func VerifyChannelUpdateSignature(msg *lnwire.ChannelUpdate,
return nil return nil
} }
// validateOptionalFields validates a channel update's message flags and // ValidateChannelUpdateFields validates a channel update's message flags and
// corresponding update fields. // corresponding update fields.
func validateOptionalFields(capacity btcutil.Amount, func ValidateChannelUpdateFields(capacity btcutil.Amount,
msg *lnwire.ChannelUpdate) error { msg *lnwire.ChannelUpdate) error {
if msg.MessageFlags.HasMaxHtlc() { if msg.MessageFlags.HasMaxHtlc() {

View file

@ -213,7 +213,7 @@ func (r *Manager) updateEdge(tx kvdb.RTx, chanPoint wire.OutPoint,
} }
// If the MaxHtlc flag wasn't already set, we can set it now. // If the MaxHtlc flag wasn't already set, we can set it now.
edge.MessageFlags |= lnwire.ChanUpdateOptionMaxHtlc edge.MessageFlags |= lnwire.ChanUpdateRequiredMaxHtlc
// Validate htlc amount constraints. // Validate htlc amount constraints.
switch { switch {

View file

@ -46,7 +46,7 @@ func TestManager(t *testing.T) {
currentPolicy := channeldb.ChannelEdgePolicy{ currentPolicy := channeldb.ChannelEdgePolicy{
MinHTLC: minHTLC, MinHTLC: minHTLC,
MessageFlags: lnwire.ChanUpdateOptionMaxHtlc, MessageFlags: lnwire.ChanUpdateRequiredMaxHtlc,
} }
updateForwardingPolicies := func( updateForwardingPolicies := func(

View file

@ -676,7 +676,7 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
if node1.testChannelPolicy != nil { if node1.testChannelPolicy != nil {
var msgFlags lnwire.ChanUpdateMsgFlags var msgFlags lnwire.ChanUpdateMsgFlags
if node1.MaxHTLC != 0 { if node1.MaxHTLC != 0 {
msgFlags |= lnwire.ChanUpdateOptionMaxHtlc msgFlags |= lnwire.ChanUpdateRequiredMaxHtlc
} }
var channelFlags lnwire.ChanUpdateChanFlags var channelFlags lnwire.ChanUpdateChanFlags
if node1.Disabled { if node1.Disabled {
@ -713,7 +713,7 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
if node2.testChannelPolicy != nil { if node2.testChannelPolicy != nil {
var msgFlags lnwire.ChanUpdateMsgFlags var msgFlags lnwire.ChanUpdateMsgFlags
if node2.MaxHTLC != 0 { if node2.MaxHTLC != 0 {
msgFlags |= lnwire.ChanUpdateOptionMaxHtlc msgFlags |= lnwire.ChanUpdateRequiredMaxHtlc
} }
var channelFlags lnwire.ChanUpdateChanFlags var channelFlags lnwire.ChanUpdateChanFlags
if node2.Disabled { if node2.Disabled {

View file

@ -25,7 +25,7 @@ func TestNodeEdgeUnifier(t *testing.T) {
FeeProportionalMillionths: 100000, FeeProportionalMillionths: 100000,
FeeBaseMSat: 30, FeeBaseMSat: 30,
TimeLockDelta: 60, TimeLockDelta: 60,
MessageFlags: lnwire.ChanUpdateOptionMaxHtlc, MessageFlags: lnwire.ChanUpdateRequiredMaxHtlc,
MaxHTLC: 5000, MaxHTLC: 5000,
MinHTLC: 100, MinHTLC: 100,
} }
@ -33,7 +33,7 @@ func TestNodeEdgeUnifier(t *testing.T) {
FeeProportionalMillionths: 190000, FeeProportionalMillionths: 190000,
FeeBaseMSat: 10, FeeBaseMSat: 10,
TimeLockDelta: 40, TimeLockDelta: 40,
MessageFlags: lnwire.ChanUpdateOptionMaxHtlc, MessageFlags: lnwire.ChanUpdateRequiredMaxHtlc,
MaxHTLC: 4000, MaxHTLC: 4000,
MinHTLC: 100, MinHTLC: 100,
} }