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

lightningnetwork / lnd / 13725358077

07 Mar 2025 04:51PM UTC coverage: 58.224% (-10.4%) from 68.615%
13725358077

Pull #9458

github

web-flow
Merge bf4c6625f into ab2dc09eb
Pull Request #9458: multi+server.go: add initial permissions for some peers

346 of 549 new or added lines in 10 files covered. (63.02%)

27466 existing lines in 443 files now uncovered.

94609 of 162492 relevant lines covered (58.22%)

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/lnwire"
9
)
10

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

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

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

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

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

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

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

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

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

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

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

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

68
        // ExtraOpaqueData is the set of data that was appended to this
69
        // message, some of which we may not actually know how to iterate or
70
        // parse. By holding onto this data, we ensure that we're able to
71
        // properly validate the set of signatures that cover these new fields,
72
        // and ensure we're able to make upgrades to the network in a forwards
73
        // compatible manner.
74
        ExtraOpaqueData lnwire.ExtraOpaqueData
75
}
76

77
// Signature is a channel announcement signature, which is needed for proper
78
// edge policy announcement.
79
//
80
// NOTE: By having this method to access an attribute, we ensure we only need
81
// to fully deserialize the signature if absolutely necessary.
82
func (c *ChannelEdgePolicy) Signature() (*ecdsa.Signature, error) {
×
83
        if c.sig != nil {
×
84
                return c.sig, nil
×
85
        }
×
86

87
        sig, err := ecdsa.ParseSignature(c.SigBytes)
×
88
        if err != nil {
×
89
                return nil, err
×
90
        }
×
91

92
        c.sig = sig
×
93

×
94
        return sig, nil
×
95
}
96

97
// SetSigBytes updates the signature and invalidates the cached parsed
98
// signature.
99
func (c *ChannelEdgePolicy) SetSigBytes(sig []byte) {
3✔
100
        c.SigBytes = sig
3✔
101
        c.sig = nil
3✔
102
}
3✔
103

104
// IsDisabled determines whether the edge has the disabled bit set.
105
func (c *ChannelEdgePolicy) IsDisabled() bool {
3✔
106
        return c.ChannelFlags.IsDisabled()
3✔
107
}
3✔
108

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

×
UNCOV
115
        return c.FeeBaseMSat + (amt*c.FeeProportionalMillionths)/feeRateParts
×
UNCOV
116
}
×
117

118
// String returns a human-readable version of the channel edge policy.
119
func (c *ChannelEdgePolicy) String() string {
×
120
        return fmt.Sprintf("ChannelID=%v, MessageFlags=%v, ChannelFlags=%v, "+
×
121
                "LastUpdate=%v", c.ChannelID, c.MessageFlags, c.ChannelFlags,
×
122
                c.LastUpdate)
×
123
}
×
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