multi: add ChanEdgePolicyFromWire constructor for ChannelEdgePolicy

Add ChanEdgePolicyFromWire to construct ChannelEdgePolicy from channel
update messages, centralizing v1/v2 field mapping.
Update call sites to use the helper:

- discovery/gossiper: handleChanUpdate
- graph/builder: ApplyChannelUpdate
- routing/router_test: ApplyChannelUpdate test helper

This consolidates update-to-policy conversion logic across versions.
This commit is contained in:
Elle Mouton committed 2026-02-13 07:21:24 +02:00
1 parent 9c7a12c0e0
commit a73c45946b
4 files changed
+69 -42

No files matched your search

+50
View File
@@ -99,6 +99,56 @@ type ChannelEdgePolicy struct {
ExtraSignedFields map[uint64][]byte
}
// ChanEdgePolicyFromWire constructs a ChannelEdgePolicy from a channel update
// message.
func ChanEdgePolicyFromWire(scid uint64,
update lnwire.ChannelUpdate) (*ChannelEdgePolicy, error) {
switch upd := update.(type) {
case *lnwire.ChannelUpdate1:
//nolint:ll
return &ChannelEdgePolicy{
Version: lnwire.GossipVersion1,
SigBytes: upd.Signature.ToSignatureBytes(),
ChannelID: scid,
LastUpdate: time.Unix(int64(upd.Timestamp), 0),
MessageFlags: upd.MessageFlags,
ChannelFlags: upd.ChannelFlags,
TimeLockDelta: upd.TimeLockDelta,
MinHTLC: upd.HtlcMinimumMsat,
MaxHTLC: upd.HtlcMaximumMsat,
FeeBaseMSat: lnwire.MilliSatoshi(upd.BaseFee),
FeeProportionalMillionths: lnwire.MilliSatoshi(upd.FeeRate),
InboundFee: upd.InboundFee.ValOpt(),
ExtraOpaqueData: upd.ExtraOpaqueData,
}, nil
case *lnwire.ChannelUpdate2:
return &ChannelEdgePolicy{
Version: lnwire.GossipVersion2,
SigBytes: upd.Signature.Val.ToSignatureBytes(),
ChannelID: scid,
LastBlockHeight: upd.BlockHeight.Val,
SecondPeer: upd.SecondPeer.IsSome(),
DisableFlags: upd.DisabledFlags.Val,
TimeLockDelta: upd.CLTVExpiryDelta.Val,
MinHTLC: upd.HTLCMinimumMsat.Val,
MaxHTLC: upd.HTLCMaximumMsat.Val,
FeeBaseMSat: lnwire.MilliSatoshi(
upd.FeeBaseMsat.Val,
),
FeeProportionalMillionths: lnwire.MilliSatoshi(
upd.FeeProportionalMillionths.Val,
),
InboundFee: upd.InboundFee.ValOpt(),
ExtraSignedFields: upd.ExtraSignedFields,
}, nil
}
return nil, fmt.Errorf("unknown channel update version: %v",
update.MsgType())
}
// IsNode1 returns true if this policy was announced by the channel's node_1.
func (c *ChannelEdgePolicy) IsNode1() bool {
if c.Version == lnwire.GossipVersion1 {