graph/db: add v2 fields to ChannelEdgePolicy model

Extend ChannelEdgePolicy to support v2 channel updates by adding:

- Version field to track gossip protocol version (v1 or v2).
- LastBlockHeight for v2's block-height-based timestamps.
- SecondPeer flag to indicate which peer announced the policy in v2.
- DisableFlags for v2-specific channel disable signaling.
- ExtraSignedFields map for v2 extra signed TLV data.

Add version-aware methods:
- IsNode1() determines if the policy was announced by node_1, handling
  both v1 (via ChannelFlags direction bit) and v2 (via SecondPeer).
- IsDisabled() checks disable status using ChannelFlags for v1 and
  DisableFlags for v2.
- String() provides version-appropriate string representations.

The new fields use zero values for v1 compatibility (Version defaults
to GossipVersion1, LastBlockHeight to 0, SecondPeer to false). This
lays the groundwork for v2 policy support; a subsequent commit will
handle reading and writing these fields from/to the database.
This commit is contained in:
Elle Mouton committed 2026-02-13 07:21:24 +02:00
1 parent 0aa93c93e7
commit 3fe40c6540
15 files changed
+105 -6

No files matched your search

+6
View File
@@ -1044,6 +1044,7 @@ func createChannelEdge(node1, node2 *models.Node) (*models.ChannelEdgeInfo,
)
edge1 := &models.ChannelEdgePolicy{
Version: lnwire.GossipVersion1,
SigBytes: testSig.Serialize(),
ChannelID: chanID,
LastUpdate: nextUpdateTime(),
@@ -1058,6 +1059,7 @@ func createChannelEdge(node1, node2 *models.Node) (*models.ChannelEdgeInfo,
ExtraOpaqueData: []byte{1, 0},
}
edge2 := &models.ChannelEdgePolicy{
Version: lnwire.GossipVersion1,
SigBytes: testSig.Serialize(),
ChannelID: chanID,
LastUpdate: nextUpdateTime(),
@@ -1442,6 +1444,7 @@ func randEdgePolicy(chanID uint64) *models.ChannelEdgePolicy {
func copyEdgePolicy(p *models.ChannelEdgePolicy) *models.ChannelEdgePolicy {
return &models.ChannelEdgePolicy{
Version: p.Version,
SigBytes: p.SigBytes,
ChannelID: p.ChannelID,
LastUpdate: p.LastUpdate,
@@ -1459,6 +1462,7 @@ func copyEdgePolicy(p *models.ChannelEdgePolicy) *models.ChannelEdgePolicy {
func newEdgePolicy(chanID uint64, updateTime int64) *models.ChannelEdgePolicy {
return &models.ChannelEdgePolicy{
Version: lnwire.GossipVersion1,
ChannelID: chanID,
LastUpdate: time.Unix(updateTime, 0),
MessageFlags: 1,
@@ -3454,6 +3458,7 @@ func TestFilterChannelRange(t *testing.T) {
updateTime = time.Unix(updateTimeSeed, 0)
err = graph.UpdateEdgePolicy(
ctx, &models.ChannelEdgePolicy{
Version: lnwire.GossipVersion1,
ToNode: node.PubKeyBytes,
ChannelFlags: chanFlags,
ChannelID: chanID,
@@ -4747,6 +4752,7 @@ func TestLightningNodeSigVerification(t *testing.T) {
func TestComputeFee(t *testing.T) {
var (
policy = models.ChannelEdgePolicy{
Version: lnwire.GossipVersion1,
FeeBaseMSat: 10000,
FeeProportionalMillionths: 30000,
}
+46 -4
View File
@@ -14,6 +14,10 @@ import (
// information concerning fees, and minimum time-lock information which is
// utilized during path finding.
type ChannelEdgePolicy struct {
// Version is the gossip version of the channel update that produced
// this policy.
Version lnwire.GossipVersion
// SigBytes is the raw bytes of the signature of the channel edge
// policy. We'll only parse these if the caller needs to access the
// signature for validation purposes.
@@ -28,6 +32,14 @@ type ChannelEdgePolicy struct {
// was received.
LastUpdate time.Time
// LastBlockHeight is the block height that timestamps the last update
// for v2 channel updates.
LastBlockHeight uint32
// SecondPeer indicates whether this policy was announced by the second
// peer in the channel for v2 channel updates.
SecondPeer bool
// MessageFlags is a bitfield which indicates the presence of optional
// fields (like max_htlc) in the policy.
MessageFlags lnwire.ChanUpdateMsgFlags
@@ -36,6 +48,10 @@ type ChannelEdgePolicy struct {
// channel as well as the directed edge this update applies to.
ChannelFlags lnwire.ChanUpdateChanFlags
// DisableFlags is a v2-specific bitfield which signals whether the
// channel is disabled for incoming or outgoing traffic.
DisableFlags lnwire.ChanUpdateDisableFlags
// TimeLockDelta is the number of blocks this node will subtract from
// the expiry of an incoming HTLC. This value expresses the time buffer
// the node would like to HTLC exchanges.
@@ -77,11 +93,31 @@ type ChannelEdgePolicy struct {
// and ensure we're able to make upgrades to the network in a forwards
// compatible manner.
ExtraOpaqueData lnwire.ExtraOpaqueData
// ExtraSignedFields are the extra signed fields found in v2 channel
// updates.
ExtraSignedFields map[uint64][]byte
}
// IsNode1 returns true if this policy was announced by the channel's node_1.
func (c *ChannelEdgePolicy) IsNode1() bool {
if c.Version == lnwire.GossipVersion1 {
return c.ChannelFlags&lnwire.ChanUpdateDirection == 0
}
return !c.SecondPeer
}
// IsDisabled determines whether the edge has the disabled bit set.
//
// NOTE: for v2 channel updates, we return true here only if both the incoming
// and outgoing disabled bits are set.
func (c *ChannelEdgePolicy) IsDisabled() bool {
return c.ChannelFlags.IsDisabled()
if c.Version == lnwire.GossipVersion1 {
return c.ChannelFlags.IsDisabled()
}
return !c.DisableFlags.IsEnabled()
}
// ComputeFee computes the fee to forward an HTLC of `amt` milli-satoshis over
@@ -95,7 +131,13 @@ func (c *ChannelEdgePolicy) ComputeFee(
// String returns a human-readable version of the channel edge policy.
func (c *ChannelEdgePolicy) String() string {
return fmt.Sprintf("ChannelID=%v, MessageFlags=%v, ChannelFlags=%v, "+
"LastUpdate=%v", c.ChannelID, c.MessageFlags, c.ChannelFlags,
c.LastUpdate)
if c.Version == lnwire.GossipVersion1 {
return fmt.Sprintf("ChannelID=%v, MessageFlags=%v, "+
"ChannelFlags=%v, LastUpdate=%v", c.ChannelID,
c.MessageFlags, c.ChannelFlags, c.LastUpdate)
}
return fmt.Sprintf("ChannelID=%v, Node1=%v, DisableFlags=%v, "+
"BlockHeight=%v", c.ChannelID, !c.SecondPeer,
c.DisableFlags, c.LastBlockHeight)
}