routing+channeldb: update CachedEdgePolicy

In preparation for CachedEdgePolicy being used to represent
ChannelEdgePolicy1 or ChannelEdgePolicy2, we update it to have
IsDisabled and HasMaxHTLC booleans (which can be extracted from both
messages) instead of having the MessageFlags and ChannelFlags which only
applies to ChannelEdgePolicy1.
This commit is contained in:
Elle Mouton 2023-10-27 12:26:47 +02:00
parent 12d21062d1
commit 674ff32a60
No known key found for this signature in database
GPG Key ID: D7D916376026F177
4 changed files with 26 additions and 27 deletions

@ -157,8 +157,8 @@ func assertCachedPolicyEqual(t *testing.T, original *models.ChannelEdgePolicy1,
cached *models.CachedEdgePolicy) {
require.Equal(t, original.ChannelID, cached.ChannelID)
require.Equal(t, original.MessageFlags, cached.MessageFlags)
require.Equal(t, original.ChannelFlags, cached.ChannelFlags)
require.Equal(t, original.MessageFlags.HasMaxHtlc(), cached.HasMaxHTLC)
require.Equal(t, original.ChannelFlags.IsDisabled(), cached.IsDisabled)
require.Equal(t, original.TimeLockDelta, cached.TimeLockDelta)
require.Equal(t, original.MinHTLC, cached.MinHTLC)
require.Equal(t, original.MaxHTLC, cached.MaxHTLC)

@ -11,7 +11,7 @@ const (
)
// CachedEdgePolicy is a struct that only caches the information of a
// ChannelEdgePolicy1 that we actually use for pathfinding and therefore need to
// ChannelEdgePolicy that we actually use for pathfinding and therefore need to
// store in the cache.
type CachedEdgePolicy struct {
// ChannelID is the unique channel ID for the channel. The first 3
@ -19,13 +19,12 @@ type CachedEdgePolicy struct {
// and the last 2 bytes are the output index for the channel.
ChannelID uint64
// MessageFlags is a bitfield which indicates the presence of optional
// fields (like max_htlc) in the policy.
MessageFlags lnwire.ChanUpdateMsgFlags
// HasMaxHTLC is true if the policy update includes a value for MaxHTLC.
HasMaxHTLC bool
// ChannelFlags is a bitfield which signals the capabilities of the
// channel as well as the directed edge this update applies to.
ChannelFlags lnwire.ChanUpdateChanFlags
// IsDisabled is true if this policy is signalling that the channel is
// disabled.
IsDisabled bool
// TimeLockDelta is the number of blocks this node will subtract from
// the expiry of an incoming HTLC. This value expresses the time buffer
@ -72,15 +71,17 @@ func (c *CachedEdgePolicy) ComputeFee(
}
// NewCachedPolicy turns a full policy into a minimal one that can be cached.
func NewCachedPolicy(policy *ChannelEdgePolicy1) *CachedEdgePolicy {
func NewCachedPolicy(policy ChannelEdgePolicy) *CachedEdgePolicy {
fwdingPolicy := policy.ForwardingPolicy()
return &CachedEdgePolicy{
ChannelID: policy.ChannelID,
MessageFlags: policy.MessageFlags,
ChannelFlags: policy.ChannelFlags,
TimeLockDelta: policy.TimeLockDelta,
MinHTLC: policy.MinHTLC,
MaxHTLC: policy.MaxHTLC,
FeeBaseMSat: policy.FeeBaseMSat,
FeeProportionalMillionths: policy.FeeProportionalMillionths,
ChannelID: policy.SCID().ToUint64(),
HasMaxHTLC: fwdingPolicy.HasMaxHTLC,
IsDisabled: policy.IsDisabled(),
TimeLockDelta: fwdingPolicy.TimeLockDelta,
MinHTLC: fwdingPolicy.MinHTLC,
MaxHTLC: fwdingPolicy.MaxHTLC,
FeeBaseMSat: fwdingPolicy.BaseFee,
FeeProportionalMillionths: fwdingPolicy.FeeRate,
}
}

@ -169,11 +169,10 @@ func (u *unifiedEdge) amtInRange(amt lnwire.MilliSatoshi) bool {
}
// Skip channels for which this htlc is too large.
if u.policy.MessageFlags.HasMaxHtlc() &&
amt > u.policy.MaxHTLC {
if u.policy.HasMaxHTLC && amt > u.policy.MaxHTLC {
log.Tracef("Exceeds policy's MaxHTLC: amt=%v, MaxHTLC=%v",
amt, u.policy.MaxHTLC)
return false
}
@ -350,18 +349,17 @@ func (u *edgeUnifier) getEdgeNetwork(netAmtReceived lnwire.MilliSatoshi,
}
// For network channels, skip the disabled ones.
edgeFlags := edge.policy.ChannelFlags
isDisabled := edgeFlags&lnwire.ChanUpdateDisabled != 0
if isDisabled {
if edge.policy.IsDisabled {
log.Debugf("Skipped edge %v due to it being disabled",
edge.policy.ChannelID)
continue
}
// Track the maximal capacity for usable channels. If we don't
// know the capacity, we fall back to MaxHTLC.
capMsat := lnwire.NewMSatFromSatoshis(edge.capacity)
if capMsat == 0 && edge.policy.MessageFlags.HasMaxHtlc() {
if capMsat == 0 && edge.policy.HasMaxHTLC {
log.Tracef("No capacity available for channel %v, "+
"using MaxHtlcMsat (%v) as a fallback.",
edge.policy.ChannelID, edge.policy.MaxHTLC)

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