From 466294ed4c87c0e121799d36b7d02021dabda803 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Fri, 24 Jan 2020 11:03:02 +0100 Subject: [PATCH 1/7] aezeed: use fast scrypt options in itest --- aezeed/cipherseed_rpctest.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 aezeed/cipherseed_rpctest.go diff --git a/aezeed/cipherseed_rpctest.go b/aezeed/cipherseed_rpctest.go new file mode 100644 index 000000000..82f782cd2 --- /dev/null +++ b/aezeed/cipherseed_rpctest.go @@ -0,0 +1,13 @@ +// +build rpctest + +package aezeed + +import "github.com/btcsuite/btcwallet/waddrmgr" + +func init() { + // For the purposes of our itest, we'll crank down the scrypt params a + // bit. + scryptN = waddrmgr.FastScryptOptions.N + scryptR = waddrmgr.FastScryptOptions.R + scryptP = waddrmgr.FastScryptOptions.P +} From 847d27f8a688a3136de45e9560063d237c4e2bff Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Fri, 17 Jan 2020 14:23:42 +0100 Subject: [PATCH 2/7] macaroons: use fast scrypt options in itest and unit tests --- macaroons/security.go | 13 +++++++++++++ macaroons/security_rpctest.go | 14 ++++++++++++++ macaroons/security_test.go | 12 ++++++++++++ macaroons/store.go | 5 +++-- 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 macaroons/security.go create mode 100644 macaroons/security_rpctest.go create mode 100644 macaroons/security_test.go diff --git a/macaroons/security.go b/macaroons/security.go new file mode 100644 index 000000000..814b0d256 --- /dev/null +++ b/macaroons/security.go @@ -0,0 +1,13 @@ +// +build !rpctest + +package macaroons + +import "github.com/btcsuite/btcwallet/snacl" + +var ( + // Below are the default scrypt parameters that are used when creating + // the encryption key for the macaroon database with snacl.NewSecretKey. + scryptN = snacl.DefaultN + scryptR = snacl.DefaultR + scryptP = snacl.DefaultP +) diff --git a/macaroons/security_rpctest.go b/macaroons/security_rpctest.go new file mode 100644 index 000000000..d49819e0f --- /dev/null +++ b/macaroons/security_rpctest.go @@ -0,0 +1,14 @@ +// +build rpctest + +package macaroons + +import "github.com/btcsuite/btcwallet/waddrmgr" + +var ( + // Below are the reduced scrypt parameters that are used when creating + // the encryption key for the macaroon database with snacl.NewSecretKey. + // We use very low values for our itest/rpctest to speed things up. + scryptN = waddrmgr.FastScryptOptions.N + scryptR = waddrmgr.FastScryptOptions.R + scryptP = waddrmgr.FastScryptOptions.P +) diff --git a/macaroons/security_test.go b/macaroons/security_test.go new file mode 100644 index 000000000..48c18e313 --- /dev/null +++ b/macaroons/security_test.go @@ -0,0 +1,12 @@ +package macaroons + +import "github.com/btcsuite/btcwallet/waddrmgr" + +func init() { + // Below are the reduced scrypt parameters that are used when creating + // the encryption key for the macaroon database with snacl.NewSecretKey. + // We use very low values for our itest/rpctest to speed things up. + scryptN = waddrmgr.FastScryptOptions.N + scryptR = waddrmgr.FastScryptOptions.R + scryptP = waddrmgr.FastScryptOptions.P +} diff --git a/macaroons/store.go b/macaroons/store.go index 16ccc9a38..affb0c506 100644 --- a/macaroons/store.go +++ b/macaroons/store.go @@ -106,8 +106,9 @@ func (r *RootKeyStorage) CreateUnlock(password *[]byte) error { } // We haven't yet stored a key, so create a new one. - encKey, err := snacl.NewSecretKey(password, snacl.DefaultN, - snacl.DefaultR, snacl.DefaultP) + encKey, err := snacl.NewSecretKey( + password, scryptN, scryptR, scryptP, + ) if err != nil { return err } From 95a67967783178579c595ced89236925e3d24850 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Fri, 17 Jan 2020 23:19:27 +0100 Subject: [PATCH 3/7] lnwallet/btcwallet: use fast scrypt options in itest --- lnwallet/btcwallet/btcwallet_rpctest.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 lnwallet/btcwallet/btcwallet_rpctest.go diff --git a/lnwallet/btcwallet/btcwallet_rpctest.go b/lnwallet/btcwallet/btcwallet_rpctest.go new file mode 100644 index 000000000..7139e4cc1 --- /dev/null +++ b/lnwallet/btcwallet/btcwallet_rpctest.go @@ -0,0 +1,23 @@ +// +build rpctest + +package btcwallet + +import ( + "github.com/btcsuite/btcwallet/snacl" + "github.com/btcsuite/btcwallet/waddrmgr" +) + +func init() { + // Instruct waddrmgr to use the cranked down scrypt parameters when + // creating new wallet encryption keys. This will speed up the itests + // considerably. + fastScrypt := waddrmgr.FastScryptOptions + keyGen := func(passphrase *[]byte, config *waddrmgr.ScryptOptions) ( + *snacl.SecretKey, error) { + + return snacl.NewSecretKey( + passphrase, fastScrypt.N, fastScrypt.R, fastScrypt.P, + ) + } + waddrmgr.SetSecretKeyGen(keyGen) +} From a101c8eeedb33a2a2cd450ae8b5e961f35610385 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Fri, 17 Jan 2020 23:19:56 +0100 Subject: [PATCH 4/7] lntest: fix timing issue with auto reconnect --- lntest/itest/lnd_test.go | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/lntest/itest/lnd_test.go b/lntest/itest/lnd_test.go index 0e8237d02..f2d53cc9e 100644 --- a/lntest/itest/lnd_test.go +++ b/lntest/itest/lnd_test.go @@ -7328,10 +7328,12 @@ func testRevokedCloseRetribution(net *lntest.NetworkHarness, t *harnessTest) { // Carol will be the breached party. We set --nolisten to ensure Bob // won't be able to connect to her and trigger the channel data - // protection logic automatically. + // protection logic automatically. We also can't have Carol + // automatically re-connect too early, otherwise DLP would be initiated + // instead of the breach we want to provoke. carol, err := net.NewNode( "Carol", - []string{"--hodl.exit-settle", "--nolisten"}, + []string{"--hodl.exit-settle", "--nolisten", "--minbackoff=1h"}, ) if err != nil { t.Fatalf("unable to create new carol node: %v", err) @@ -7591,10 +7593,12 @@ func testRevokedCloseRetributionZeroValueRemoteOutput(net *lntest.NetworkHarness // Dave will be the breached party. We set --nolisten to ensure Carol // won't be able to connect to him and trigger the channel data - // protection logic automatically. + // protection logic automatically. We also can't have Dave automatically + // re-connect too early, otherwise DLP would be initiated instead of the + // breach we want to provoke. dave, err := net.NewNode( "Dave", - []string{"--hodl.exit-settle", "--nolisten"}, + []string{"--hodl.exit-settle", "--nolisten", "--minbackoff=1h"}, ) if err != nil { t.Fatalf("unable to create new node: %v", err) @@ -8658,15 +8662,23 @@ func assertDLPExecuted(net *lntest.NetworkHarness, t *harnessTest, dave *lntest.HarnessNode, daveStartingBalance int64, anchors bool) { + // We disabled auto-reconnect for some tests to avoid timing issues. + // To make sure the nodes are initiating DLP now, we have to manually + // re-connect them. + ctxb := context.Background() + err := net.ConnectNodes(ctxb, carol, dave) + if err != nil && !strings.Contains(err.Error(), "already connected") { + t.Fatalf("unable to connect Carol to Dave to initiate DLP: %v", + err) + } + // Upon reconnection, the nodes should detect that Dave is out of sync. // Carol should force close the channel using her latest commitment. expectedTxes := 1 if anchors { expectedTxes = 2 } - - ctxb := context.Background() - _, err := waitForNTxsInMempool( + _, err = waitForNTxsInMempool( net.Miner.Node, expectedTxes, minerMempoolTimeout, ) if err != nil { @@ -8777,8 +8789,12 @@ func testDataLossProtection(net *lntest.NetworkHarness, t *harnessTest) { // Carol will be the up-to-date party. We set --nolisten to ensure Dave // won't be able to connect to her and trigger the channel data - // protection logic automatically. - carol, err := net.NewNode("Carol", []string{"--nolisten"}) + // protection logic automatically. We also can't have Carol + // automatically re-connect too early, otherwise DLP would be initiated + // at the wrong moment. + carol, err := net.NewNode( + "Carol", []string{"--nolisten", "--minbackoff=1h"}, + ) if err != nil { t.Fatalf("unable to create new carol node: %v", err) } From eb531d0449cb3b95a3d3ff9a03a0ad0e15e91651 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Thu, 5 Mar 2020 15:57:28 +0100 Subject: [PATCH 5/7] htlcswitch: add causing error to log and err msg --- htlcswitch/link.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htlcswitch/link.go b/htlcswitch/link.go index 7c834827d..9b8323cd5 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -627,7 +627,7 @@ func (l *channelLink) syncChanStates() error { if err := l.cfg.Peer.SendMessage(true, localChanSyncMsg); err != nil { return fmt.Errorf("Unable to send chan sync message for "+ - "ChannelPoint(%v)", l.channel.ChannelPoint()) + "ChannelPoint(%v): %v", l.channel.ChannelPoint(), err) } var msgsToReSend []lnwire.Message @@ -3121,7 +3121,7 @@ func (l *channelLink) fail(linkErr LinkFailureError, return } - l.log.Errorf("failing link: %s", reason) + l.log.Errorf("failing link: %s with error: %v", reason, linkErr) // Set failed, such that we won't process any more updates, and notify // the peer about the failure. From 770c80635ca14852f5097948298e892cf2e7a5fd Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Thu, 5 Mar 2020 15:59:01 +0100 Subject: [PATCH 6/7] lntest: give async payments enough time to complete --- lntest/timeouts.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lntest/timeouts.go b/lntest/timeouts.go index 052138460..d099d06b1 100644 --- a/lntest/timeouts.go +++ b/lntest/timeouts.go @@ -23,5 +23,5 @@ const ( // AsyncBenchmarkTimeout is the timeout used when running the async // payments benchmark. - AsyncBenchmarkTimeout = time.Minute + AsyncBenchmarkTimeout = 2 * time.Minute ) From 81730e644450d6f9caf2528a3cb7633ff249856e Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Tue, 24 Mar 2020 10:00:53 +0100 Subject: [PATCH 7/7] mod: update btcwallet dependency to fix neutrino flake --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index de7f0a9db..987ffb5a0 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/btcsuite/btcd v0.20.1-beta github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d - github.com/btcsuite/btcwallet v0.11.1-0.20200219004649-ae9416ad7623 + github.com/btcsuite/btcwallet v0.11.1-0.20200323235326-015c045a3bb7 github.com/btcsuite/btcwallet/wallet/txauthor v1.0.0 github.com/btcsuite/btcwallet/wallet/txrules v1.0.0 github.com/btcsuite/btcwallet/walletdb v1.2.0 diff --git a/go.sum b/go.sum index 3015a6d4b..7fff12d55 100644 --- a/go.sum +++ b/go.sum @@ -26,8 +26,8 @@ github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9 github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d h1:yJzD/yFppdVCf6ApMkVy8cUxV0XrxdP9rVf6D87/Mng= github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= -github.com/btcsuite/btcwallet v0.11.1-0.20200219004649-ae9416ad7623 h1:ZuJRjucNsTmlrbZncsqzD0z3EaXrOobCx2I4lc12R4g= -github.com/btcsuite/btcwallet v0.11.1-0.20200219004649-ae9416ad7623/go.mod h1:1O1uRHMPXHdwA4/od8nqYqrgclVKp+wtfXUAqHmeRvE= +github.com/btcsuite/btcwallet v0.11.1-0.20200323235326-015c045a3bb7 h1:ubYJYIi13atgwPCX7FZQZV2mytkaRHWPycDFdF28U0o= +github.com/btcsuite/btcwallet v0.11.1-0.20200323235326-015c045a3bb7/go.mod h1:1O1uRHMPXHdwA4/od8nqYqrgclVKp+wtfXUAqHmeRvE= github.com/btcsuite/btcwallet/wallet/txauthor v1.0.0 h1:KGHMW5sd7yDdDMkCZ/JpP0KltolFsQcB973brBnfj4c= github.com/btcsuite/btcwallet/wallet/txauthor v1.0.0/go.mod h1:VufDts7bd/zs3GV13f/lXc/0lXrPnvxD/NvmpG/FEKU= github.com/btcsuite/btcwallet/wallet/txrules v1.0.0 h1:2VsfS0sBedcM5KmDzRMT3+b6xobqWveZGvjb+jFez5w=