Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chanbackup: continue recovery if channel already exists #3737

Merged
merged 2 commits into from Nov 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions chanbackup/recover.go
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/btcsuite/btcd/btcec"
"github.com/davecgh/go-spew/spew"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/keychain"
)

Expand Down Expand Up @@ -47,6 +48,14 @@ func Recover(backups []Single, restorer ChannelRestorer,
backup.FundingOutpoint)

err := restorer.RestoreChansFromSingles(backup)

// If a channel is already present in the channel DB, we can
// just continue. No reason to fail a whole set of multi backups
// for example. This allows resume of a restore in case another
// error happens.
if err == channeldb.ErrChanAlreadyExists {
cfromknecht marked this conversation as resolved.
Show resolved Hide resolved
continue
}
if err != nil {
return err
}
Expand Down
66 changes: 66 additions & 0 deletions lntest/itest/lnd_test.go
Expand Up @@ -14130,6 +14130,72 @@ func testChannelBackupRestore(net *lntest.NetworkHarness, t *harnessTest) {
}, nil
},
},

// Restore the backup from the on-disk file a second time to
// make sure imports can be canceled and later resumed.
{
name: "restore from backup file twice",
initiator: true,
private: false,
restoreMethod: func(oldNode *lntest.HarnessNode,
backupFilePath string,
mnemonic []string) (nodeRestorer, error) {

// Read the entire Multi backup stored within
// this node's chaannels.backup file.
multi, err := ioutil.ReadFile(backupFilePath)
if err != nil {
return nil, err
}

// Now that we have Dave's backup file, we'll
// create a new nodeRestorer that will restore
// using the on-disk channels.backup.
backup := &lnrpc.RestoreChanBackupRequest_MultiChanBackup{
MultiChanBackup: multi,
}

ctxb := context.Background()

return func() (*lntest.HarnessNode, error) {
newNode, err := net.RestoreNodeWithSeed(
"dave", nil, password, mnemonic,
1000, nil,
)
if err != nil {
return nil, fmt.Errorf("unable to "+
"restore node: %v", err)
}

_, err = newNode.RestoreChannelBackups(
ctxb,
&lnrpc.RestoreChanBackupRequest{
Backup: backup,
},
)
if err != nil {
return nil, fmt.Errorf("unable "+
"to restore backups: %v",
err)
}

_, err = newNode.RestoreChannelBackups(
ctxb,
&lnrpc.RestoreChanBackupRequest{
Backup: backup,
},
)
if err != nil {
return nil, fmt.Errorf("unable "+
"to restore backups the"+
"second time: %v",
err)
}

return newNode, nil
}, nil
},
},
}

// TODO(roasbeef): online vs offline close?
Expand Down