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

lightningnetwork / lnd / 15951470896

29 Jun 2025 04:23AM UTC coverage: 67.594% (-0.01%) from 67.606%
15951470896

Pull #9751

github

web-flow
Merge 599d9b051 into 6290edf14
Pull Request #9751: multi: update Go to 1.23.10 and update some packages

135088 of 199851 relevant lines covered (67.59%)

21909.44 hits per line

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

87.84
/channeldb/forwarding_policy.go
1
package channeldb
2

3
import (
4
        "github.com/lightningnetwork/lnd/graph/db/models"
5
        "github.com/lightningnetwork/lnd/kvdb"
6
        "github.com/lightningnetwork/lnd/lnwire"
7
)
8

9
var (
10
        // initialChannelForwardingPolicyBucket is the database bucket used to
11
        // store the forwarding policy for each permanent channel that is
12
        // currently in the process of being opened.
13
        initialChannelForwardingPolicyBucket = []byte(
14
                "initialChannelFwdingPolicy",
15
        )
16
)
17

18
// SaveInitialForwardingPolicy saves the serialized forwarding policy for the
19
// provided permanent channel id to the initialChannelForwardingPolicyBucket.
20
func (c *ChannelStateDB) SaveInitialForwardingPolicy(chanID lnwire.ChannelID,
21
        forwardingPolicy *models.ForwardingPolicy) error {
70✔
22

70✔
23
        chanIDCopy := make([]byte, 32)
70✔
24
        copy(chanIDCopy, chanID[:])
70✔
25

70✔
26
        scratch := make([]byte, 36)
70✔
27
        byteOrder.PutUint64(scratch[:8], uint64(forwardingPolicy.MinHTLCOut))
70✔
28
        byteOrder.PutUint64(scratch[8:16], uint64(forwardingPolicy.MaxHTLC))
70✔
29
        byteOrder.PutUint64(scratch[16:24], uint64(forwardingPolicy.BaseFee))
70✔
30
        byteOrder.PutUint64(scratch[24:32], uint64(forwardingPolicy.FeeRate))
70✔
31
        byteOrder.PutUint32(scratch[32:], forwardingPolicy.TimeLockDelta)
70✔
32

70✔
33
        return kvdb.Update(c.backend, func(tx kvdb.RwTx) error {
140✔
34
                bucket, err := tx.CreateTopLevelBucket(
70✔
35
                        initialChannelForwardingPolicyBucket,
70✔
36
                )
70✔
37
                if err != nil {
70✔
38
                        return err
×
39
                }
×
40

41
                return bucket.Put(chanIDCopy, scratch)
70✔
42
        }, func() {})
70✔
43
}
44

45
// GetInitialForwardingPolicy fetches the serialized forwarding policy for the
46
// provided channel id from the database, or returns ErrChannelNotFound if
47
// a forwarding policy for this channel id is not found.
48
func (c *ChannelStateDB) GetInitialForwardingPolicy(
49
        chanID lnwire.ChannelID) (*models.ForwardingPolicy, error) {
98✔
50

98✔
51
        chanIDCopy := make([]byte, 32)
98✔
52
        copy(chanIDCopy, chanID[:])
98✔
53

98✔
54
        var forwardingPolicy *models.ForwardingPolicy
98✔
55
        err := kvdb.View(c.backend, func(tx kvdb.RTx) error {
196✔
56
                bucket := tx.ReadBucket(initialChannelForwardingPolicyBucket)
98✔
57
                if bucket == nil {
98✔
58
                        // If the bucket does not exist, it means we
×
59
                        // never added a channel fees to the db, so
×
60
                        // return ErrChannelNotFound.
×
61
                        return ErrChannelNotFound
×
62
                }
×
63

64
                stateBytes := bucket.Get(chanIDCopy)
98✔
65
                if stateBytes == nil {
122✔
66
                        return ErrChannelNotFound
24✔
67
                }
24✔
68

69
                forwardingPolicy = &models.ForwardingPolicy{
74✔
70
                        MinHTLCOut: lnwire.MilliSatoshi(
74✔
71
                                byteOrder.Uint64(stateBytes[:8]),
74✔
72
                        ),
74✔
73
                        MaxHTLC: lnwire.MilliSatoshi(
74✔
74
                                byteOrder.Uint64(stateBytes[8:16]),
74✔
75
                        ),
74✔
76
                        BaseFee: lnwire.MilliSatoshi(
74✔
77
                                byteOrder.Uint64(stateBytes[16:24]),
74✔
78
                        ),
74✔
79
                        FeeRate: lnwire.MilliSatoshi(
74✔
80
                                byteOrder.Uint64(stateBytes[24:32]),
74✔
81
                        ),
74✔
82
                        TimeLockDelta: byteOrder.Uint32(stateBytes[32:36]),
74✔
83
                }
74✔
84

74✔
85
                return nil
74✔
86
        }, func() {
98✔
87
                forwardingPolicy = nil
98✔
88
        })
98✔
89

90
        return forwardingPolicy, err
98✔
91
}
92

93
// DeleteInitialForwardingPolicy removes the forwarding policy for a given
94
// channel from the database.
95
func (c *ChannelStateDB) DeleteInitialForwardingPolicy(
96
        chanID lnwire.ChannelID) error {
27✔
97

27✔
98
        chanIDCopy := make([]byte, 32)
27✔
99
        copy(chanIDCopy, chanID[:])
27✔
100

27✔
101
        return kvdb.Update(c.backend, func(tx kvdb.RwTx) error {
54✔
102
                bucket := tx.ReadWriteBucket(
27✔
103
                        initialChannelForwardingPolicyBucket,
27✔
104
                )
27✔
105
                if bucket == nil {
27✔
106
                        return ErrChannelNotFound
×
107
                }
×
108

109
                return bucket.Delete(chanIDCopy)
27✔
110
        }, func() {})
27✔
111
}
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