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

lightningnetwork / lnd / 12033440129

26 Nov 2024 03:03PM UTC coverage: 48.738% (-10.3%) from 58.999%
12033440129

Pull #9309

github

yyforyongyu
gomod: update `btcd` for shutdown fix
Pull Request #9309: chainntnfs: fix `TestHistoricalConfDetailsTxIndex`

97664 of 200385 relevant lines covered (48.74%)

0.52 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 {
1✔
22

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

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

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

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

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

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

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

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

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

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

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

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