From e4873ac87808dc034a0ee52e58ca31863c6f182d Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Fri, 14 May 2021 10:09:05 +0200 Subject: [PATCH] lntest: re-use P2P ports during SCB recovery In some rare instances it can happen that the nodes don't find each other again after one of them has been re-created and the other one has been restarted in the SCB tests. By making sure the re-created has the same P2P port again as before, we make sure they can connect to each other again successfully for executing DLP. --- lntest/harness.go | 19 ++++++++++---- lntest/itest/lnd_channel_backup_test.go | 34 +++++++++++++++++-------- lntest/itest/log_error_whitelist.txt | 4 +++ lntest/node.go | 22 ++++++++++------ 4 files changed, 56 insertions(+), 23 deletions(-) diff --git a/lntest/harness.go b/lntest/harness.go index f83e7ae6..c0303c02 100644 --- a/lntest/harness.go +++ b/lntest/harness.go @@ -32,6 +32,9 @@ import ( // DefaultCSV is the CSV delay (remotedelay) we will start our test nodes with. const DefaultCSV = 4 +// NodeOption is a function for updating a node's configuration. +type NodeOption func(*NodeConfig) + // NetworkHarness is an integration testing harness for the lightning network. // The harness by default is created with two active nodes on the network: // Alice and Bob. @@ -427,10 +430,11 @@ func (n *NetworkHarness) newNodeWithSeed(name string, extraArgs []string, // be used for regular rpc operations. func (n *NetworkHarness) RestoreNodeWithSeed(name string, extraArgs []string, password []byte, mnemonic []string, recoveryWindow int32, - chanBackups *lnrpc.ChanBackupSnapshot) (*HarnessNode, error) { + chanBackups *lnrpc.ChanBackupSnapshot, + opts ...NodeOption) (*HarnessNode, error) { node, err := n.newNode( - name, extraArgs, true, password, n.embeddedEtcd, true, + name, extraArgs, true, password, n.embeddedEtcd, true, opts..., ) if err != nil { return nil, err @@ -461,10 +465,10 @@ func (n *NetworkHarness) RestoreNodeWithSeed(name string, extraArgs []string, // can be used immediately. Otherwise, the node will require an additional // initialization phase where the wallet is either created or restored. func (n *NetworkHarness) newNode(name string, extraArgs []string, hasSeed bool, - password []byte, embeddedEtcd, wait bool) ( + password []byte, embeddedEtcd, wait bool, opts ...NodeOption) ( *HarnessNode, error) { - node, err := newNode(NodeConfig{ + cfg := &NodeConfig{ Name: name, LogFilenamePrefix: n.currentTestCase, HasSeed: hasSeed, @@ -474,7 +478,12 @@ func (n *NetworkHarness) newNode(name string, extraArgs []string, hasSeed bool, ExtraArgs: extraArgs, FeeURL: n.feeService.url, Etcd: embeddedEtcd, - }) + } + for _, opt := range opts { + opt(cfg) + } + + node, err := newNode(*cfg) if err != nil { return nil, err } diff --git a/lntest/itest/lnd_channel_backup_test.go b/lntest/itest/lnd_channel_backup_test.go index cc8e526b..1b299e29 100644 --- a/lntest/itest/lnd_channel_backup_test.go +++ b/lntest/itest/lnd_channel_backup_test.go @@ -63,7 +63,7 @@ func testChannelBackupRestore(net *lntest.NetworkHarness, t *harnessTest) { // the node from seed, then manually recover // the channel backup. return chanRestoreViaRPC( - net, password, mnemonic, multi, + net, password, mnemonic, multi, oldNode, ) }, }, @@ -89,7 +89,7 @@ func testChannelBackupRestore(net *lntest.NetworkHarness, t *harnessTest) { // create a new nodeRestorer that will restore // using the on-disk channels.backup. return chanRestoreViaRPC( - net, password, mnemonic, multi, + net, password, mnemonic, multi, oldNode, ) }, }, @@ -124,6 +124,7 @@ func testChannelBackupRestore(net *lntest.NetworkHarness, t *harnessTest) { return net.RestoreNodeWithSeed( "dave", nil, password, mnemonic, 1000, backupSnapshot, + copyPorts(oldNode), ) }, nil }, @@ -160,6 +161,7 @@ func testChannelBackupRestore(net *lntest.NetworkHarness, t *harnessTest) { newNode, err := net.RestoreNodeWithSeed( "dave", nil, password, mnemonic, 1000, nil, + copyPorts(oldNode), ) if err != nil { return nil, err @@ -206,7 +208,7 @@ func testChannelBackupRestore(net *lntest.NetworkHarness, t *harnessTest) { return func() (*lntest.HarnessNode, error) { newNode, err := net.RestoreNodeWithSeed( "dave", nil, password, mnemonic, - 1000, nil, + 1000, nil, copyPorts(oldNode), ) if err != nil { return nil, fmt.Errorf("unable to "+ @@ -276,7 +278,7 @@ func testChannelBackupRestore(net *lntest.NetworkHarness, t *harnessTest) { // the node from seed, then manually recover // the channel backup. return chanRestoreViaRPC( - net, password, mnemonic, multi, + net, password, mnemonic, multi, oldNode, ) }, }, @@ -326,7 +328,7 @@ func testChannelBackupRestore(net *lntest.NetworkHarness, t *harnessTest) { // the channel backup. multi := chanBackup.MultiChanBackup.MultiChanBackup return chanRestoreViaRPC( - net, password, mnemonic, multi, + net, password, mnemonic, multi, oldNode, ) }, }, @@ -353,7 +355,7 @@ func testChannelBackupRestore(net *lntest.NetworkHarness, t *harnessTest) { // create a new nodeRestorer that will restore // using the on-disk channels.backup. return chanRestoreViaRPC( - net, password, mnemonic, multi, + net, password, mnemonic, multi, oldNode, ) }, }, @@ -384,7 +386,7 @@ func testChannelBackupRestore(net *lntest.NetworkHarness, t *harnessTest) { // the node from seed, then manually recover the // channel backup. return chanRestoreViaRPC( - net, password, mnemonic, multi, + net, password, mnemonic, multi, oldNode, ) }, }, @@ -1228,9 +1230,9 @@ func createLegacyRevocationChannel(net *lntest.NetworkHarness, t *harnessTest, // chanRestoreViaRPC is a helper test method that returns a nodeRestorer // instance which will restore the target node from a password+seed, then // trigger a SCB restore using the RPC interface. -func chanRestoreViaRPC(net *lntest.NetworkHarness, - password []byte, mnemonic []string, - multi []byte) (nodeRestorer, error) { +func chanRestoreViaRPC(net *lntest.NetworkHarness, password []byte, + mnemonic []string, multi []byte, + oldNode *lntest.HarnessNode) (nodeRestorer, error) { backup := &lnrpc.RestoreChanBackupRequest_MultiChanBackup{ MultiChanBackup: multi, @@ -1241,6 +1243,7 @@ func chanRestoreViaRPC(net *lntest.NetworkHarness, return func() (*lntest.HarnessNode, error) { newNode, err := net.RestoreNodeWithSeed( "dave", nil, password, mnemonic, 1000, nil, + copyPorts(oldNode), ) if err != nil { return nil, fmt.Errorf("unable to "+ @@ -1260,3 +1263,14 @@ func chanRestoreViaRPC(net *lntest.NetworkHarness, return newNode, nil }, nil } + +// copyPorts returns a node option function that copies the ports of an existing +// node over to the newly created one. +func copyPorts(oldNode *lntest.HarnessNode) lntest.NodeOption { + return func(cfg *lntest.NodeConfig) { + cfg.P2PPort = oldNode.Cfg.P2PPort + cfg.RPCPort = oldNode.Cfg.RPCPort + cfg.RESTPort = oldNode.Cfg.RESTPort + cfg.ProfilePort = oldNode.Cfg.ProfilePort + } +} diff --git a/lntest/itest/log_error_whitelist.txt b/lntest/itest/log_error_whitelist.txt index 665b3266..f75e7cc0 100644 --- a/lntest/itest/log_error_whitelist.txt +++ b/lntest/itest/log_error_whitelist.txt @@ -1,5 +1,7 @@