• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 15736109134

18 Jun 2025 02:46PM UTC coverage: 58.197% (-10.1%) from 68.248%
15736109134

Pull #9752

github

web-flow
Merge d2634a68c into 31c74f20f
Pull Request #9752: routerrpc: reject payment to invoice that don't have payment secret or blinded paths

6 of 13 new or added lines in 2 files covered. (46.15%)

28331 existing lines in 455 files now uncovered.

97860 of 168153 relevant lines covered (58.2%)

1.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

25.93
/graph/db/models/channel_edge_policy.go
1
package models
2

3
import (
4
        "fmt"
5
        "time"
6

7
        "github.com/btcsuite/btcd/btcec/v2/ecdsa"
8
        "github.com/lightningnetwork/lnd/fn/v2"
9
        "github.com/lightningnetwork/lnd/lnwire"
10
)
11

12
// ChannelEdgePolicy represents a *directed* edge within the channel graph. For
13
// each channel in the database, there are two distinct edges: one for each
14
// possible direction of travel along the channel. The edges themselves hold
15
// information concerning fees, and minimum time-lock information which is
16
// utilized during path finding.
17
type ChannelEdgePolicy struct {
18
        // SigBytes is the raw bytes of the signature of the channel edge
19
        // policy. We'll only parse these if the caller needs to access the
20
        // signature for validation purposes. Do not set SigBytes directly, but
21
        // use SetSigBytes instead to make sure that the cache is invalidated.
22
        SigBytes []byte
23

24
        // sig is a cached fully parsed signature.
25
        sig *ecdsa.Signature
26

27
        // ChannelID is the unique channel ID for the channel. The first 3
28
        // bytes are the block height, the next 3 the index within the block,
29
        // and the last 2 bytes are the output index for the channel.
30
        ChannelID uint64
31

32
        // LastUpdate is the last time an authenticated edge for this channel
33
        // was received.
34
        LastUpdate time.Time
35

36
        // MessageFlags is a bitfield which indicates the presence of optional
37
        // fields (like max_htlc) in the policy.
38
        MessageFlags lnwire.ChanUpdateMsgFlags
39

40
        // ChannelFlags is a bitfield which signals the capabilities of the
41
        // channel as well as the directed edge this update applies to.
42
        ChannelFlags lnwire.ChanUpdateChanFlags
43

44
        // TimeLockDelta is the number of blocks this node will subtract from
45
        // the expiry of an incoming HTLC. This value expresses the time buffer
46
        // the node would like to HTLC exchanges.
47
        TimeLockDelta uint16
48

49
        // MinHTLC is the smallest value HTLC this node will forward, expressed
50
        // in millisatoshi.
51
        MinHTLC lnwire.MilliSatoshi
52

53
        // MaxHTLC is the largest value HTLC this node will forward, expressed
54
        // in millisatoshi.
55
        MaxHTLC lnwire.MilliSatoshi
56

57
        // FeeBaseMSat is the base HTLC fee that will be charged for forwarding
58
        // ANY HTLC, expressed in mSAT's.
59
        FeeBaseMSat lnwire.MilliSatoshi
60

61
        // FeeProportionalMillionths is the rate that the node will charge for
62
        // HTLCs for each millionth of a satoshi forwarded.
63
        FeeProportionalMillionths lnwire.MilliSatoshi
64

65
        // ToNode is the public key of the node that this directed edge leads
66
        // to. Using this pub key, the channel graph can further be traversed.
67
        ToNode [33]byte
68

69
        // InboundFee is the fee that must be paid for incoming HTLCs.
70
        //
71
        // NOTE: for our kvdb implementation of the graph store, inbound fees
72
        // are still only persisted as part of extra opaque data and so this
73
        // field is not explicitly stored but is rather populated from the
74
        // ExtraOpaqueData field on deserialization. For our SQL implementation,
75
        // this field will be explicitly persisted in the database.
76
        InboundFee fn.Option[lnwire.Fee]
77

78
        // ExtraOpaqueData is the set of data that was appended to this
79
        // message, some of which we may not actually know how to iterate or
80
        // parse. By holding onto this data, we ensure that we're able to
81
        // properly validate the set of signatures that cover these new fields,
82
        // and ensure we're able to make upgrades to the network in a forwards
83
        // compatible manner.
84
        ExtraOpaqueData lnwire.ExtraOpaqueData
85
}
86

87
// Signature is a channel announcement signature, which is needed for proper
88
// edge policy announcement.
89
//
90
// NOTE: By having this method to access an attribute, we ensure we only need
91
// to fully deserialize the signature if absolutely necessary.
92
func (c *ChannelEdgePolicy) Signature() (*ecdsa.Signature, error) {
×
93
        if c.sig != nil {
×
94
                return c.sig, nil
×
95
        }
×
96

97
        sig, err := ecdsa.ParseSignature(c.SigBytes)
×
98
        if err != nil {
×
99
                return nil, err
×
100
        }
×
101

102
        c.sig = sig
×
103

×
104
        return sig, nil
×
105
}
106

107
// SetSigBytes updates the signature and invalidates the cached parsed
108
// signature.
109
func (c *ChannelEdgePolicy) SetSigBytes(sig []byte) {
3✔
110
        c.SigBytes = sig
3✔
111
        c.sig = nil
3✔
112
}
3✔
113

114
// IsDisabled determines whether the edge has the disabled bit set.
115
func (c *ChannelEdgePolicy) IsDisabled() bool {
3✔
116
        return c.ChannelFlags.IsDisabled()
3✔
117
}
3✔
118

119
// ComputeFee computes the fee to forward an HTLC of `amt` milli-satoshis over
120
// the passed active payment channel. This value is currently computed as
121
// specified in BOLT07, but will likely change in the near future.
122
func (c *ChannelEdgePolicy) ComputeFee(
UNCOV
123
        amt lnwire.MilliSatoshi) lnwire.MilliSatoshi {
×
UNCOV
124

×
UNCOV
125
        return c.FeeBaseMSat + (amt*c.FeeProportionalMillionths)/feeRateParts
×
UNCOV
126
}
×
127

128
// String returns a human-readable version of the channel edge policy.
129
func (c *ChannelEdgePolicy) String() string {
×
130
        return fmt.Sprintf("ChannelID=%v, MessageFlags=%v, ChannelFlags=%v, "+
×
131
                "LastUpdate=%v", c.ChannelID, c.MessageFlags, c.ChannelFlags,
×
132
                c.LastUpdate)
×
133
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc