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

lightningnetwork / lnd / 13211764208

08 Feb 2025 03:08AM UTC coverage: 49.288% (-9.5%) from 58.815%
13211764208

Pull #9489

github

calvinrzachman
itest: verify switchrpc server enforces send then track

We prevent the rpc server from allowing onion dispatches for
attempt IDs which have already been tracked by rpc clients.

This helps protect the client from leaking a duplicate onion
attempt. NOTE: This is not the only method for solving this
issue! The issue could be addressed via careful client side
programming which accounts for the uncertainty and async
nature of dispatching onions to a remote process via RPC.
This would require some lnd ChannelRouter changes for how
we intend to use these RPCs though.
Pull Request #9489: multi: add BuildOnion, SendOnion, and TrackOnion RPCs

474 of 990 new or added lines in 11 files covered. (47.88%)

27321 existing lines in 435 files now uncovered.

101192 of 205306 relevant lines covered (49.29%)

1.54 hits per line

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

0.0
/watchtower/wtdb/migration2/client_db.go
1
package migration2
2

3
import (
4
        "errors"
5

6
        "github.com/lightningnetwork/lnd/kvdb"
7
)
8

9
var (
10
        // cChanSummaryBkt is a top-level bucket storing:
11
        //   channel-id -> encoded ClientChanSummary.
12
        cChanSummaryBkt = []byte("client-channel-summary-bucket")
13

14
        // cChanDetailsBkt is a top-level bucket storing:
15
        //   channel-id => cChannelSummary -> encoded ClientChanSummary.
16
        cChanDetailsBkt = []byte("client-channel-detail-bucket")
17

18
        // cChannelSummary is a key used in cChanDetailsBkt to store the encoded
19
        // body of ClientChanSummary.
20
        cChannelSummary = []byte("client-channel-summary")
21

22
        // ErrUninitializedDB signals that top-level buckets for the database
23
        // have not been initialized.
24
        ErrUninitializedDB = errors.New("db not initialized")
25

26
        // ErrCorruptChanSummary signals that the clients channel summary's
27
        // on-disk structure deviates from what is expected.
28
        ErrCorruptChanSummary = errors.New("channel summary corrupted")
29
)
30

31
// MigrateClientChannelDetails creates a new channel-details bucket that uses
32
// channel IDs as sub-buckets where the channel summaries are moved to from the
33
// channel summary bucket. If the migration is successful then the channel
34
// summary bucket is deleted.
UNCOV
35
func MigrateClientChannelDetails(tx kvdb.RwTx) error {
×
UNCOV
36
        log.Infof("Migrating the tower client db to move the channel " +
×
UNCOV
37
                "summaries to the new channel-details bucket")
×
UNCOV
38

×
UNCOV
39
        // Create the new top level cChanDetailsBkt.
×
UNCOV
40
        chanDetailsBkt, err := tx.CreateTopLevelBucket(cChanDetailsBkt)
×
UNCOV
41
        if err != nil {
×
42
                return err
×
43
        }
×
44

45
        // Get the top-level channel summaries bucket.
UNCOV
46
        chanSummaryBkt := tx.ReadWriteBucket(cChanSummaryBkt)
×
UNCOV
47
        if chanSummaryBkt == nil {
×
48
                return ErrUninitializedDB
×
49
        }
×
50

51
        // Iterate over the cChanSummaryBkt's keys. Each key is a channel-id.
52
        // For each of these, create a new sub-bucket with this key in
53
        // cChanDetailsBkt. In this sub-bucket, add the cChannelSummary key with
54
        // the encoded ClientChanSummary as the value.
UNCOV
55
        err = chanSummaryBkt.ForEach(func(chanID, summary []byte) error {
×
UNCOV
56
                // Force the migration to fail if the summary is empty. This
×
UNCOV
57
                // should never be the case, but it is added so that we can
×
UNCOV
58
                // force the migration to fail in a test so that we can test
×
UNCOV
59
                // that the db remains unaffected if a migration failure takes
×
UNCOV
60
                // place.
×
UNCOV
61
                if len(summary) == 0 {
×
UNCOV
62
                        return ErrCorruptChanSummary
×
UNCOV
63
                }
×
64

65
                // Create a new sub-bucket in the channel details bucket using
66
                // this channel ID.
UNCOV
67
                channelBkt, err := chanDetailsBkt.CreateBucket(chanID)
×
UNCOV
68
                if err != nil {
×
69
                        return err
×
70
                }
×
71

72
                // Add the encoded channel summary in the new bucket under the
73
                // channel-summary key.
UNCOV
74
                return channelBkt.Put(cChannelSummary, summary)
×
75
        })
UNCOV
76
        if err != nil {
×
UNCOV
77
                return err
×
UNCOV
78
        }
×
79

80
        // Now delete the cChanSummaryBkt from the DB.
UNCOV
81
        return tx.DeleteTopLevelBucket(cChanSummaryBkt)
×
82
}
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