diff --git a/lnd_test.go b/lnd_test.go index d6d8f68a..7a5bf241 100644 --- a/lnd_test.go +++ b/lnd_test.go @@ -457,7 +457,7 @@ func testOnchainFundRecovery(net *lntest.NetworkHarness, t *harnessTest) { // used for key derivation. This will bring up Carol with an empty // wallet, and such that she is synced up. password := []byte("The Magic Words are Squeamish Ossifrage") - carol, mnemonic, err := net.NewNodeWithSeed(nil, password) + carol, mnemonic, err := net.NewNodeWithSeed("Carol", nil, password) if err != nil { t.Fatalf("unable to create node with seed; %v", err) } @@ -477,7 +477,7 @@ func testOnchainFundRecovery(net *lntest.NetworkHarness, t *harnessTest) { // Restore Carol, passing in the password, mnemonic, and // desired recovery window. node, err := net.RestoreNodeWithSeed( - nil, password, mnemonic, recoveryWindow, + "Carol", nil, password, mnemonic, recoveryWindow, ) if err != nil { t.Fatalf("unable to restore node: %v", err) @@ -708,7 +708,7 @@ func testUpdateChannelPolicy(net *lntest.NetworkHarness, t *harnessTest) { } // Create Carol and a new channel Bob->Carol. - carol, err := net.NewNode(nil) + carol, err := net.NewNode("Carol", nil) if err != nil { t.Fatalf("unable to create new nodes: %v", err) } @@ -1335,7 +1335,7 @@ func testChannelFundingPersistence(net *lntest.NetworkHarness, t *harnessTest) { // we'll need to create a new node instance. const numConfs = 5 carolArgs := []string{fmt.Sprintf("--bitcoin.defaultchanconfs=%v", numConfs)} - carol, err := net.NewNode(carolArgs) + carol, err := net.NewNode("Carol", carolArgs) if err != nil { t.Fatalf("unable to create new node: %v", err) } @@ -1665,7 +1665,7 @@ func testChannelForceClosure(net *lntest.NetworkHarness, t *harnessTest) { // Since we'd like to test failure scenarios with outstanding htlcs, // we'll introduce another node into our test network: Carol. - carol, err := net.NewNode([]string{"--debughtlc", "--hodlhtlc"}) + carol, err := net.NewNode("Carol", []string{"--debughtlc", "--hodlhtlc"}) if err != nil { t.Fatalf("unable to create new nodes: %v", err) } @@ -2248,7 +2248,7 @@ func testSphinxReplayPersistence(net *lntest.NetworkHarness, t *harnessTest) { chanAmt := btcutil.Amount(100000) // First, we'll create Dave, the receiver, and start him in hodl mode. - dave, err := net.NewNode([]string{"--debughtlc", "--hodlhtlc"}) + dave, err := net.NewNode("Dave", []string{"--debughtlc", "--hodlhtlc"}) if err != nil { t.Fatalf("unable to create new nodes: %v", err) } @@ -2257,7 +2257,7 @@ func testSphinxReplayPersistence(net *lntest.NetworkHarness, t *harnessTest) { // Dave. Carol is started in both unsafe-replay and unsafe-disconnect, // which will cause her to replay any pending Adds held in memory upon // reconnection. - carol, err := net.NewNode([]string{"--unsafe-replay"}) + carol, err := net.NewNode("Carol", []string{"--unsafe-replay"}) if err != nil { t.Fatalf("unable to create new nodes: %v", err) } @@ -2780,7 +2780,7 @@ func testMultiHopPayments(net *lntest.NetworkHarness, t *harnessTest) { // Carol -> Dave -> Alice -> Bob // // First, we'll create Dave and establish a channel to Alice. - dave, err := net.NewNode(nil) + dave, err := net.NewNode("Dave", nil) if err != nil { t.Fatalf("unable to create new nodes: %v", err) } @@ -2811,7 +2811,7 @@ func testMultiHopPayments(net *lntest.NetworkHarness, t *harnessTest) { // Next, we'll create Carol and establish a channel to from her to // Dave. - carol, err := net.NewNode(nil) + carol, err := net.NewNode("Carol", nil) if err != nil { t.Fatalf("unable to create new nodes: %v", err) } @@ -3040,7 +3040,7 @@ func testPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) { } // Create Dave, and a channel to Alice of 100k. - dave, err := net.NewNode(nil) + dave, err := net.NewNode("Dave", nil) if err != nil { t.Fatalf("unable to create new nodes: %v", err) } @@ -3071,7 +3071,7 @@ func testPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) { // Next, we'll create Carol and establish a channel from her to // Dave of 100k. - carol, err := net.NewNode(nil) + carol, err := net.NewNode("Carol", nil) if err != nil { t.Fatalf("unable to create new nodes: %v", err) } @@ -3363,7 +3363,7 @@ func testInvoiceRoutingHints(net *lntest.NetworkHarness, t *harnessTest) { // Then, we'll create Carol's node and open a public channel between her // and Alice. This channel will not be considered as a routing hint due // to it being public. - carol, err := net.NewNode(nil) + carol, err := net.NewNode("Carol", nil) if err != nil { t.Fatalf("unable to create carol's node: %v", err) } @@ -3379,7 +3379,7 @@ func testInvoiceRoutingHints(net *lntest.NetworkHarness, t *harnessTest) { // and Alice. We will not include a push amount in order to not consider // this channel as a routing hint as it will not have enough remote // balance for the invoice's amount. - dave, err := net.NewNode(nil) + dave, err := net.NewNode("Dave", nil) if err != nil { t.Fatalf("unable to create dave's node: %v", err) } @@ -3395,7 +3395,7 @@ func testInvoiceRoutingHints(net *lntest.NetworkHarness, t *harnessTest) { // her and Alice. This time though, we'll take Eve's node down after the // channel has been created to avoid populating routing hints for // inactive channels. - eve, err := net.NewNode(nil) + eve, err := net.NewNode("Eve", nil) if err != nil { t.Fatalf("unable to create eve's node: %v", err) } @@ -3553,7 +3553,7 @@ func testMultiHopOverPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) // Next, we'll create Carol's node and open a public channel between // her and Bob with Bob being the funder. - carol, err := net.NewNode(nil) + carol, err := net.NewNode("Carol", nil) if err != nil { t.Fatalf("unable to create carol's node: %v", err) } @@ -3600,7 +3600,7 @@ func testMultiHopOverPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) // Next, we'll create Dave's node and open a private channel between him // and Carol with Carol being the funder. - dave, err := net.NewNode(nil) + dave, err := net.NewNode("Dave", nil) if err != nil { t.Fatalf("unable to create dave's node: %v", err) } @@ -3868,7 +3868,7 @@ func testMaxPendingChannels(net *lntest.NetworkHarness, t *harnessTest) { args := []string{ fmt.Sprintf("--maxpendingchannels=%v", maxPendingChannels), } - carol, err := net.NewNode(args) + carol, err := net.NewNode("Carol", args) if err != nil { t.Fatalf("unable to create new nodes: %v", err) } @@ -4303,7 +4303,7 @@ func testRevokedCloseRetributionZeroValueRemoteOutput(net *lntest.NetworkHarness // Since we'd like to test some multi-hop failure scenarios, we'll // introduce another node into our test network: Carol. - carol, err := net.NewNode([]string{"--debughtlc", "--hodlhtlc"}) + carol, err := net.NewNode("Carol", []string{"--debughtlc", "--hodlhtlc"}) if err != nil { t.Fatalf("unable to create new nodes: %v", err) } @@ -4537,7 +4537,7 @@ func testRevokedCloseRetributionRemoteHodl(net *lntest.NetworkHarness, // Since this test will result in the counterparty being left in a // weird state, we will introduce another node into our test network: // Carol. - carol, err := net.NewNode([]string{"--debughtlc", "--hodlhtlc"}) + carol, err := net.NewNode("Carol", []string{"--debughtlc", "--hodlhtlc"}) if err != nil { t.Fatalf("unable to create new nodes: %v", err) } @@ -4545,7 +4545,7 @@ func testRevokedCloseRetributionRemoteHodl(net *lntest.NetworkHarness, // We'll also create a new node Dave, who will have a channel with // Carol, and also use similar settings so we can broadcast a commit // with active HTLCs. - dave, err := net.NewNode([]string{"--debughtlc", "--hodlhtlc"}) + dave, err := net.NewNode("Dave", []string{"--debughtlc", "--hodlhtlc"}) if err != nil { t.Fatalf("unable to create new dave node: %v", err) } @@ -4996,7 +4996,7 @@ func testHtlcErrorPropagation(net *lntest.NetworkHarness, t *harnessTest) { // Since we'd like to test some multi-hop failure scenarios, we'll // introduce another node into our test network: Carol. - carol, err := net.NewNode(nil) + carol, err := net.NewNode("Carol", nil) if err != nil { t.Fatalf("unable to create new nodes: %v", err) } @@ -5405,7 +5405,7 @@ func testGraphTopologyNotifications(net *lntest.NetworkHarness, t *harnessTest) if err := net.DisconnectNodes(ctxt, net.Alice, net.Bob); err != nil { t.Fatalf("unable to disconnect alice and bob: %v", err) } - carol, err := net.NewNode(nil) + carol, err := net.NewNode("Carol", nil) if err != nil { t.Fatalf("unable to create new nodes: %v", err) } @@ -5499,7 +5499,7 @@ func testNodeAnnouncement(net *lntest.NetworkHarness, t *harnessTest) { lndArgs = append(lndArgs, "--externalip="+address) } - dave, err := net.NewNode(lndArgs) + dave, err := net.NewNode("Dave", lndArgs) if err != nil { t.Fatalf("unable to create new nodes: %v", err) } @@ -5600,7 +5600,7 @@ func testNodeSignVerify(net *lntest.NetworkHarness, t *harnessTest) { } // carol is a new node that is unconnected to alice or bob. - carol, err := net.NewNode(nil) + carol, err := net.NewNode("Carol", nil) if err != nil { t.Fatalf("unable to create new node: %v", err) } @@ -6190,7 +6190,7 @@ func createThreeHopHodlNetwork(t *harnessTest, // Next, we'll create a new node "carol" and have Bob connect to her. // In this test, we'll make carol always hold onto the HTLC, this way // it'll force Bob to go to chain to resolve the HTLC. - carol, err := net.NewNode([]string{"--debughtlc", "--hodlhtlc"}) + carol, err := net.NewNode("Carol", []string{"--debughtlc", "--hodlhtlc"}) if err != nil { t.Fatalf("unable to create new node: %v", err) } @@ -7569,7 +7569,7 @@ func testSwitchCircuitPersistence(net *lntest.NetworkHarness, t *harnessTest) { // Carol -> Dave -> Alice -> Bob // // First, we'll create Dave and establish a channel to Alice. - dave, err := net.NewNode(nil) + dave, err := net.NewNode("Dave", nil) if err != nil { t.Fatalf("unable to create new nodes: %v", err) } @@ -7601,7 +7601,7 @@ func testSwitchCircuitPersistence(net *lntest.NetworkHarness, t *harnessTest) { // Next, we'll create Carol and establish a channel to from her to // Dave. Carol is started in htlchodl mode so that we can disconnect the // intermediary hops before starting the settle. - carol, err := net.NewNode([]string{"--debughtlc", "--hodlhtlc"}) + carol, err := net.NewNode("Carol", []string{"--debughtlc", "--hodlhtlc"}) if err != nil { t.Fatalf("unable to create new nodes: %v", err) } @@ -7890,7 +7890,7 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) { // Carol -> Dave -> Alice -> Bob // // First, we'll create Dave and establish a channel to Alice. - dave, err := net.NewNode([]string{"--unsafe-disconnect"}) + dave, err := net.NewNode("Dave", []string{"--unsafe-disconnect"}) if err != nil { t.Fatalf("unable to create new nodes: %v", err) } @@ -7922,7 +7922,7 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) { // Next, we'll create Carol and establish a channel to from her to // Dave. Carol is started in htlchodl mode so that we can disconnect the // intermediary hops before starting the settle. - carol, err := net.NewNode([]string{"--debughtlc", "--hodlhtlc"}) + carol, err := net.NewNode("Carol", []string{"--debughtlc", "--hodlhtlc"}) if err != nil { t.Fatalf("unable to create new nodes: %v", err) } @@ -8216,7 +8216,7 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness // Carol -> Dave -> Alice -> Bob // // First, we'll create Dave and establish a channel to Alice. - dave, err := net.NewNode([]string{"--unsafe-disconnect"}) + dave, err := net.NewNode("Dave", []string{"--unsafe-disconnect"}) if err != nil { t.Fatalf("unable to create new nodes: %v", err) } @@ -8248,7 +8248,7 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness // Next, we'll create Carol and establish a channel to from her to // Dave. Carol is started in htlchodl mode so that we can disconnect the // intermediary hops before starting the settle. - carol, err := net.NewNode([]string{"--debughtlc", "--hodlhtlc"}) + carol, err := net.NewNode("Dave", []string{"--debughtlc", "--hodlhtlc"}) if err != nil { t.Fatalf("unable to create new nodes: %v", err) } @@ -8543,7 +8543,7 @@ func testSwitchOfflineDeliveryOutgoingOffline( // Carol -> Dave -> Alice -> Bob // // First, we'll create Dave and establish a channel to Alice. - dave, err := net.NewNode([]string{"--unsafe-disconnect"}) + dave, err := net.NewNode("Dave", []string{"--unsafe-disconnect"}) if err != nil { t.Fatalf("unable to create new nodes: %v", err) } @@ -8575,7 +8575,7 @@ func testSwitchOfflineDeliveryOutgoingOffline( // Next, we'll create Carol and establish a channel to from her to // Dave. Carol is started in htlchodl mode so that we can disconnect the // intermediary hops before starting the settle. - carol, err := net.NewNode([]string{"--debughtlc", "--hodlhtlc"}) + carol, err := net.NewNode("Carol", []string{"--debughtlc", "--hodlhtlc"}) if err != nil { t.Fatalf("unable to create new nodes: %v", err) } @@ -8799,7 +8799,7 @@ func testQueryRoutes(net *lntest.NetworkHarness, t *harnessTest) { networkChans = append(networkChans, chanPointAlice) // Create Carol and establish a channel from Bob. - carol, err := net.NewNode(nil) + carol, err := net.NewNode("Carol", nil) if err != nil { t.Fatalf("unable to create new nodes: %v", err) } @@ -8817,7 +8817,7 @@ func testQueryRoutes(net *lntest.NetworkHarness, t *harnessTest) { networkChans = append(networkChans, chanPointBob) // Create Dave and establish a channel from Carol. - dave, err := net.NewNode(nil) + dave, err := net.NewNode("Dave", nil) if err != nil { t.Fatalf("unable to create new nodes: %v", err) } diff --git a/lntest/harness.go b/lntest/harness.go index c16547ad..cbe0c0b3 100644 --- a/lntest/harness.go +++ b/lntest/harness.go @@ -123,7 +123,7 @@ func (n *NetworkHarness) SetUp(lndArgs []string) error { wg.Add(2) go func() { defer wg.Done() - node, err := n.NewNode(lndArgs) + node, err := n.NewNode("Alice", lndArgs) if err != nil { errChan <- err return @@ -132,7 +132,7 @@ func (n *NetworkHarness) SetUp(lndArgs []string) error { }() go func() { defer wg.Done() - node, err := n.NewNode(lndArgs) + node, err := n.NewNode("Bob", lndArgs) if err != nil { errChan <- err return @@ -237,18 +237,18 @@ func (n *NetworkHarness) TearDownAll() error { // NewNode fully initializes a returns a new HarnessNode bound to the // current instance of the network harness. The created node is running, but // not yet connected to other nodes within the network. -func (n *NetworkHarness) NewNode(extraArgs []string) (*HarnessNode, error) { - return n.newNode(extraArgs, false) +func (n *NetworkHarness) NewNode(name string, extraArgs []string) (*HarnessNode, error) { + return n.newNode(name, extraArgs, false) } // NewNodeWithSeed fully initializes a new HarnessNode after creating a fresh // aezeed. The provided password is used as both the aezeed password and the // wallet password. The generated mnemonic is returned along with the // initialized harness node. -func (n *NetworkHarness) NewNodeWithSeed(extraArgs []string, +func (n *NetworkHarness) NewNodeWithSeed(name string, extraArgs []string, password []byte) (*HarnessNode, []string, error) { - node, err := n.newNode(extraArgs, true) + node, err := n.newNode(name, extraArgs, true) if err != nil { return nil, nil, err } @@ -294,11 +294,11 @@ func (n *NetworkHarness) NewNodeWithSeed(extraArgs []string, // password, and recovery window. After providing the initialization request to // unlock the node, this method will finish initializing the LightningClient // such that the HarnessNode can be used for regular rpc operations. -func (n *NetworkHarness) RestoreNodeWithSeed(extraArgs []string, +func (n *NetworkHarness) RestoreNodeWithSeed(name string, extraArgs []string, password []byte, mnemonic []string, recoveryWindow int32) (*HarnessNode, error) { - node, err := n.newNode(extraArgs, true) + node, err := n.newNode(name, extraArgs, true) if err != nil { return nil, err } @@ -326,8 +326,9 @@ func (n *NetworkHarness) RestoreNodeWithSeed(extraArgs []string, // wallet with or without a seed. If hasSeed is false, the returned harness node // 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(extraArgs []string, hasSeed bool) (*HarnessNode, error) { +func (n *NetworkHarness) newNode(name string, extraArgs []string, hasSeed bool) (*HarnessNode, error) { node, err := newNode(nodeConfig{ + Name: name, HasSeed: hasSeed, RPCConfig: &n.rpcConfig, NetParams: n.netParams, diff --git a/lntest/node.go b/lntest/node.go index 5c54a3e6..5f89b1ea 100644 --- a/lntest/node.go +++ b/lntest/node.go @@ -59,6 +59,12 @@ var ( logOutput = flag.Bool("logoutput", false, "log output from node n to file outputn.log") + // logPubKeyBytes is the number of bytes of the node's PubKey that + // will be appended to the log file name. The whole PubKey is too + // long and not really necessary to quickly identify what node + // produced which log file. + logPubKeyBytes = 4 + // trickleDelay is the amount of time in milliseconds between each // release of announcements by AuthenticatedGossiper to the network. trickleDelay = 50 @@ -85,6 +91,7 @@ func generateListeningPorts() (int, int, int) { } type nodeConfig struct { + Name string RPCConfig *rpcclient.ConnConfig NetParams *chaincfg.Params BaseDir string @@ -262,7 +269,8 @@ func (hn *HarnessNode) start(lndError chan<- error) error { // If the logoutput flag is passed, redirect output from the nodes to // log files. if *logOutput { - fileName := fmt.Sprintf("output%d.log", hn.NodeID) + fileName := fmt.Sprintf("output-%d-%s-%s.log", hn.NodeID, + hn.cfg.Name, hex.EncodeToString(hn.PubKey[:logPubKeyBytes])) // Create file if not exists, otherwise append. file, err := os.OpenFile(fileName,