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

lightningnetwork / lnd / 15561477203

10 Jun 2025 01:54PM UTC coverage: 58.351% (-10.1%) from 68.487%
15561477203

Pull #9356

github

web-flow
Merge 6440b25db into c6d6d4c0b
Pull Request #9356: lnrpc: add incoming/outgoing channel ids filter to forwarding history request

33 of 36 new or added lines in 2 files covered. (91.67%)

28366 existing lines in 455 files now uncovered.

97715 of 167461 relevant lines covered (58.35%)

1.81 hits per line

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

85.14
/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 {
3✔
22

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

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

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

41
                return bucket.Put(chanIDCopy, scratch)
3✔
42
        }, func() {})
3✔
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) {
3✔
50

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

3✔
54
        var forwardingPolicy *models.ForwardingPolicy
3✔
55
        err := kvdb.View(c.backend, func(tx kvdb.RTx) error {
6✔
56
                bucket := tx.ReadBucket(initialChannelForwardingPolicyBucket)
3✔
57
                if bucket == nil {
3✔
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)
3✔
65
                if stateBytes == nil {
3✔
UNCOV
66
                        return ErrChannelNotFound
×
UNCOV
67
                }
×
68

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

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

90
        return forwardingPolicy, err
3✔
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 {
3✔
97

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

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

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