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

lightningnetwork / lnd / 12312390362

13 Dec 2024 08:44AM UTC coverage: 57.458% (+8.5%) from 48.92%
12312390362

Pull #9343

github

ellemouton
fn: rework the ContextGuard and add tests

In this commit, the ContextGuard struct is re-worked such that the
context that its new main WithCtx method provides is cancelled in sync
with a parent context being cancelled or with it's quit channel being
cancelled. Tests are added to assert the behaviour. In order for the
close of the quit channel to be consistent with the cancelling of the
derived context, the quit channel _must_ be contained internal to the
ContextGuard so that callers are only able to close the channel via the
exposed Quit method which will then take care to first cancel any
derived context that depend on the quit channel before returning.
Pull Request #9343: fn: expand the ContextGuard and add tests

101853 of 177264 relevant lines covered (57.46%)

24972.93 hits per line

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

0.0
/zpay32/hophint.go
1
package zpay32
2

3
import (
4
        "github.com/btcsuite/btcd/btcec/v2"
5
        "github.com/lightningnetwork/lnd/lnwire"
6
)
7

8
const (
9
        // DefaultAssumedFinalCLTVDelta is the default value to be used as the
10
        // final CLTV delta for a route if one is unspecified in the payment
11
        // request.
12
        // We adhere to the recommendation in BOLT 02 for terminal payments.
13
        // See also:
14
        // https://github.com/lightning/bolts/blob/master/02-peer-protocol.md
15
        DefaultAssumedFinalCLTVDelta = 18
16

17
        // feeRateParts is the total number of parts used to express fee rates.
18
        feeRateParts = 1e6
19
)
20

21
// HopHint is a routing hint that contains the minimum information of a channel
22
// required for an intermediate hop in a route to forward the payment to the
23
// next. This should be ideally used for private channels, since they are not
24
// publicly advertised to the network for routing.
25
type HopHint struct {
26
        // NodeID is the public key of the node at the start of the channel.
27
        NodeID *btcec.PublicKey
28

29
        // ChannelID is the unique identifier of the channel.
30
        ChannelID uint64
31

32
        // FeeBaseMSat is the base fee of the channel in millisatoshis.
33
        FeeBaseMSat uint32
34

35
        // FeeProportionalMillionths is the fee rate, in millionths of a
36
        // satoshi, for every satoshi sent through the channel.
37
        FeeProportionalMillionths uint32
38

39
        // CLTVExpiryDelta is the time-lock delta of the channel.
40
        CLTVExpiryDelta uint16
41
}
42

43
// Copy returns a deep copy of the hop hint.
44
func (h HopHint) Copy() HopHint {
×
45
        nodeID := *h.NodeID
×
46
        return HopHint{
×
47
                NodeID:                    &nodeID,
×
48
                ChannelID:                 h.ChannelID,
×
49
                FeeBaseMSat:               h.FeeBaseMSat,
×
50
                FeeProportionalMillionths: h.FeeProportionalMillionths,
×
51
                CLTVExpiryDelta:           h.CLTVExpiryDelta,
×
52
        }
×
53
}
×
54

55
// HopFee calculates the fee for a given amount that is forwarded over a hop.
56
// The amount has to be denoted in milli satoshi. The returned fee is also
57
// denoted in milli satoshi.
58
func (h HopHint) HopFee(amt lnwire.MilliSatoshi) lnwire.MilliSatoshi {
×
59
        baseFee := lnwire.MilliSatoshi(h.FeeBaseMSat)
×
60
        feeRate := lnwire.MilliSatoshi(h.FeeProportionalMillionths)
×
61

×
62
        return baseFee + (amt*feeRate)/feeRateParts
×
63
}
×
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