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

lightningnetwork / lnd / 11170835610

03 Oct 2024 10:41PM UTC coverage: 49.188% (-9.6%) from 58.738%
11170835610

push

github

web-flow
Merge pull request #9154 from ziggie1984/master

multi: bump btcd version.

3 of 6 new or added lines in 6 files covered. (50.0%)

26110 existing lines in 428 files now uncovered.

97359 of 197934 relevant lines covered (49.19%)

1.04 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/channeldb/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 {
2✔
22

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

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

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

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

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

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

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

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

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

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

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

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