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

lightningnetwork / lnd / 12199391122

06 Dec 2024 01:10PM UTC coverage: 49.807% (-9.1%) from 58.933%
12199391122

push

github

web-flow
Merge pull request #9337 from Guayaba221/patch-1

chore: fix typo in ruby.md

100137 of 201051 relevant lines covered (49.81%)

2.07 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 {
4✔
22

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

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

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

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

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

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

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

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

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

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

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

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