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

lightningnetwork / lnd / 11216766535

07 Oct 2024 01:37PM UTC coverage: 57.817% (-1.0%) from 58.817%
11216766535

Pull #9148

github

ProofOfKeags
lnwire: remove kickoff feerate from propose/commit
Pull Request #9148: DynComms [2/n]: lnwire: add authenticated wire messages for Dyn*

571 of 879 new or added lines in 16 files covered. (64.96%)

23253 existing lines in 251 files now uncovered.

99022 of 171268 relevant lines covered (57.82%)

38420.67 hits per line

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

97.73
/chanbackup/recover.go
1
package chanbackup
2

3
import (
4
        "net"
5

6
        "github.com/btcsuite/btcd/btcec/v2"
7
        "github.com/lightningnetwork/lnd/channeldb"
8
        "github.com/lightningnetwork/lnd/keychain"
9
        "github.com/lightningnetwork/lnd/lnutils"
10
)
11

12
// ChannelRestorer is an interface that allows the Recover method to map the
13
// set of single channel backups into a set of "channel shells" and store these
14
// persistently on disk. The channel shell should contain all the information
15
// needed to execute the data loss recovery protocol once the channel peer is
16
// connected to.
17
type ChannelRestorer interface {
18
        // RestoreChansFromSingles attempts to map the set of single channel
19
        // backups to channel shells that will be stored persistently. Once
20
        // these shells have been stored on disk, we'll be able to connect to
21
        // the channel peer an execute the data loss recovery protocol.
22
        RestoreChansFromSingles(...Single) error
23
}
24

25
// PeerConnector is an interface that allows the Recover method to connect to
26
// the target node given the set of possible addresses.
27
type PeerConnector interface {
28
        // ConnectPeer attempts to connect to the target node at the set of
29
        // available addresses. Once this method returns with a non-nil error,
30
        // the connector should attempt to persistently connect to the target
31
        // peer in the background as a persistent attempt.
32
        ConnectPeer(node *btcec.PublicKey, addrs []net.Addr) error
33
}
34

35
// Recover attempts to recover the static channel state from a set of static
36
// channel backups. If successfully, the database will be populated with a
37
// series of "shell" channels. These "shell" channels cannot be used to operate
38
// the channel as normal, but instead are meant to be used to enter the data
39
// loss recovery phase, and recover the settled funds within
40
// the channel. In addition a LinkNode will be created for each new peer as
41
// well, in order to expose the addressing information required to locate to
42
// and connect to each peer in order to initiate the recovery protocol.
43
func Recover(backups []Single, restorer ChannelRestorer,
44
        peerConnector PeerConnector) error {
6✔
45

6✔
46
        for i, backup := range backups {
30✔
47
                log.Infof("Restoring ChannelPoint(%v) to disk: ",
24✔
48
                        backup.FundingOutpoint)
24✔
49

24✔
50
                err := restorer.RestoreChansFromSingles(backup)
24✔
51

24✔
52
                // If a channel is already present in the channel DB, we can
24✔
53
                // just continue. No reason to fail a whole set of multi backups
24✔
54
                // for example. This allows resume of a restore in case another
24✔
55
                // error happens.
24✔
56
                if err == channeldb.ErrChanAlreadyExists {
24✔
UNCOV
57
                        continue
×
58
                }
59
                if err != nil {
26✔
60
                        return err
2✔
61
                }
2✔
62

63
                log.Infof("Attempting to connect to node=%x (addrs=%v) to "+
22✔
64
                        "restore ChannelPoint(%v)",
22✔
65
                        backup.RemoteNodePub.SerializeCompressed(),
22✔
66
                        lnutils.SpewLogClosure(backups[i].Addresses),
22✔
67
                        backup.FundingOutpoint)
22✔
68

22✔
69
                err = peerConnector.ConnectPeer(
22✔
70
                        backup.RemoteNodePub, backup.Addresses,
22✔
71
                )
22✔
72
                if err != nil {
24✔
73
                        return err
2✔
74
                }
2✔
75

76
                // TODO(roasbeef): to handle case where node has changed addrs,
77
                // need to subscribe to new updates for target node pub to
78
                // attempt to connect to other addrs
79
                //
80
                //  * just to to fresh w/ call to node addrs and de-dup?
81
        }
82

83
        return nil
2✔
84
}
85

86
// TODO(roasbeef): more specific keychain interface?
87

88
// UnpackAndRecoverSingles is a one-shot method, that given a set of packed
89
// single channel backups, will restore the channel state to a channel shell,
90
// and also reach out to connect to any of the known node addresses for that
91
// channel. It is assumes that after this method exists, if a connection we
92
// able to be established, then then PeerConnector will continue to attempt to
93
// re-establish a persistent connection in the background.
94
func UnpackAndRecoverSingles(singles PackedSingles,
95
        keyChain keychain.KeyRing, restorer ChannelRestorer,
96
        peerConnector PeerConnector) error {
4✔
97

4✔
98
        chanBackups, err := singles.Unpack(keyChain)
4✔
99
        if err != nil {
5✔
100
                return err
1✔
101
        }
1✔
102

103
        return Recover(chanBackups, restorer, peerConnector)
3✔
104
}
105

106
// UnpackAndRecoverMulti is a one-shot method, that given a set of packed
107
// multi-channel backups, will restore the channel states to channel shells,
108
// and also reach out to connect to any of the known node addresses for that
109
// channel. It is assumes that after this method exists, if a connection we
110
// able to be established, then then PeerConnector will continue to attempt to
111
// re-establish a persistent connection in the background.
112
func UnpackAndRecoverMulti(packedMulti PackedMulti,
113
        keyChain keychain.KeyRing, restorer ChannelRestorer,
114
        peerConnector PeerConnector) error {
4✔
115

4✔
116
        chanBackups, err := packedMulti.Unpack(keyChain)
4✔
117
        if err != nil {
5✔
118
                return err
1✔
119
        }
1✔
120

121
        return Recover(chanBackups.StaticBackups, restorer, peerConnector)
3✔
122
}
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