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 +} diff --git a/go.mod b/go.mod index bcce60d79..5abf1a58d 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= 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. diff --git a/lntest/itest/lnd_test.go b/lntest/itest/lnd_test.go index 482d2a7fc..c13bfa475 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) } 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 ) 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) +} 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 }