From 82fe5d9bbacee7a58fe67b4c92efb4a3e55f3409 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Tue, 9 Mar 2021 14:12:26 -0800 Subject: [PATCH] build: update btcwallet dependency introducing pruned bitcoind support This is achieved by some recent work within the BitcoindClient enabling it to retrieve pruned blocks from its server's peers. --- chainntnfs/test_utils.go | 17 +++++++++++++---- chainreg/chainregistry.go | 21 +++++++++++++++------ go.mod | 2 +- go.sum | 6 +++--- lnd.go | 3 +++ lnwallet/test/test_interface.go | 18 +++++++++++++----- routing/chainview/interface_test.go | 18 +++++++++++++----- 7 files changed, 61 insertions(+), 24 deletions(-) diff --git a/chainntnfs/test_utils.go b/chainntnfs/test_utils.go index 929f40d2..99db43f4 100644 --- a/chainntnfs/test_utils.go +++ b/chainntnfs/test_utils.go @@ -233,10 +233,19 @@ func NewBitcoindBackend(t *testing.T, minerAddr string, time.Sleep(time.Second) host := fmt.Sprintf("127.0.0.1:%d", rpcPort) - conn, err := chain.NewBitcoindConn( - NetParams, host, "weks", "weks", zmqBlockHost, zmqTxHost, - 100*time.Millisecond, - ) + conn, err := chain.NewBitcoindConn(&chain.BitcoindConfig{ + ChainParams: NetParams, + Host: host, + User: "weks", + Pass: "weks", + ZMQBlockHost: zmqBlockHost, + ZMQTxHost: zmqTxHost, + ZMQReadDeadline: 5 * time.Second, + // Fields only required for pruned nodes, not needed for these + // tests. + Dialer: nil, + PrunedModeMaxPeers: 0, + }) if err != nil { bitcoind.Process.Kill() bitcoind.Wait() diff --git a/chainreg/chainregistry.go b/chainreg/chainregistry.go index 30025ad1..31519419 100644 --- a/chainreg/chainregistry.go +++ b/chainreg/chainregistry.go @@ -105,6 +105,11 @@ type Config struct { // DBTimeOut specifies the timeout value to use when opening the wallet // database. DBTimeOut time.Duration + + // Dialer is a function closure that will be used to establish outbound + // TCP connections to Bitcoin peers in the event of a pruned block being + // requested. + Dialer chain.Dialer } const ( @@ -383,12 +388,16 @@ func NewChainControl(cfg *Config) (*ChainControl, error) { // Establish the connection to bitcoind and create the clients // required for our relevant subsystems. - bitcoindConn, err := chain.NewBitcoindConn( - cfg.ActiveNetParams.Params, bitcoindHost, - bitcoindMode.RPCUser, bitcoindMode.RPCPass, - bitcoindMode.ZMQPubRawBlock, bitcoindMode.ZMQPubRawTx, - 5*time.Second, - ) + bitcoindConn, err := chain.NewBitcoindConn(&chain.BitcoindConfig{ + ChainParams: cfg.ActiveNetParams.Params, + Host: bitcoindHost, + User: bitcoindMode.RPCUser, + Pass: bitcoindMode.RPCPass, + ZMQBlockHost: bitcoindMode.ZMQPubRawBlock, + ZMQTxHost: bitcoindMode.ZMQPubRawTx, + ZMQReadDeadline: 5 * time.Second, + Dialer: cfg.Dialer, + }) if err != nil { return nil, err } diff --git a/go.mod b/go.mod index 4fc95e74..13dee18a 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce github.com/btcsuite/btcutil/psbt v1.0.3-0.20201208143702-a53e38424cce - github.com/btcsuite/btcwallet v0.11.1-0.20210329233242-e0607006dce6 + github.com/btcsuite/btcwallet v0.11.1-0.20210405201449-683061f79797 github.com/btcsuite/btcwallet/wallet/txauthor v1.0.1-0.20210329233242-e0607006dce6 github.com/btcsuite/btcwallet/wallet/txrules v1.0.0 github.com/btcsuite/btcwallet/wallet/txsizes v1.0.1-0.20210329233242-e0607006dce6 // indirect diff --git a/go.sum b/go.sum index 61e75750..10f4df42 100644 --- a/go.sum +++ b/go.sum @@ -25,8 +25,8 @@ github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+Ce github.com/btcsuite/btcd v0.0.0-20190629003639-c26ffa870fd8/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI= github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI= github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= -github.com/btcsuite/btcd v0.20.1-beta.0.20200513120220-b470eee47728/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= github.com/btcsuite/btcd v0.21.0-beta.0.20201208033208-6bd4c64a54fa/go.mod h1:Sv4JPQ3/M+teHz9Bo5jBpkNcP0x6r7rdihlNL/7tTAs= +github.com/btcsuite/btcd v0.21.0-beta.0.20210316172410-f86ae60936d7/go.mod h1:Sv4JPQ3/M+teHz9Bo5jBpkNcP0x6r7rdihlNL/7tTAs= github.com/btcsuite/btcd v0.21.0-beta.0.20210401013323-36a96f6a0025 h1:aoVqvZk4mLyF3WZbqEVPq+vXnwL2wekZg4P4mjYJNLs= github.com/btcsuite/btcd v0.21.0-beta.0.20210401013323-36a96f6a0025/go.mod h1:9n5ntfhhHQBIhUvlhDvD3Qg6fRUj4jkN0VB8L8svzOA= github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9VhRV3jjAVU7DJVjMaK+IsvSeZvFo= @@ -37,8 +37,8 @@ github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce h1:YtWJF7RHm2pY github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce/go.mod h1:0DVlHczLPewLcPGEIeUEzfOJhqGPQ0mJJRDBtD307+o= github.com/btcsuite/btcutil/psbt v1.0.3-0.20201208143702-a53e38424cce h1:3PRwz+js0AMMV1fHRrCdQ55akoomx4Q3ulozHC3BDDY= github.com/btcsuite/btcutil/psbt v1.0.3-0.20201208143702-a53e38424cce/go.mod h1:LVveMu4VaNSkIRTZu2+ut0HDBRuYjqGocxDMNS1KuGQ= -github.com/btcsuite/btcwallet v0.11.1-0.20210329233242-e0607006dce6 h1:5Y6ui667YQrFCxPYV4Pmf9jpEsIkcJxMKsXJzNsMU9o= -github.com/btcsuite/btcwallet v0.11.1-0.20210329233242-e0607006dce6/go.mod h1:JBUz2SCnYLn2Dw9bcnqZYvKchnKVvWSLv8OUzihHTcc= +github.com/btcsuite/btcwallet v0.11.1-0.20210405201449-683061f79797 h1:FqPzyVNKoqE+qV57Cn8zpTfUy/G698M9b6dNprGj0cY= +github.com/btcsuite/btcwallet v0.11.1-0.20210405201449-683061f79797/go.mod h1:CevOfPKvF6kHr+JXhWD3TtqLbsJrD1CzrtDqZ+5G6ss= github.com/btcsuite/btcwallet/wallet/txauthor v1.0.0/go.mod h1:VufDts7bd/zs3GV13f/lXc/0lXrPnvxD/NvmpG/FEKU= github.com/btcsuite/btcwallet/wallet/txauthor v1.0.1-0.20210329233242-e0607006dce6 h1:mO7NxcfgLe75paLDHx+LWNG5BskiDQigHnSVT2KvNZA= github.com/btcsuite/btcwallet/wallet/txauthor v1.0.1-0.20210329233242-e0607006dce6/go.mod h1:VufDts7bd/zs3GV13f/lXc/0lXrPnvxD/NvmpG/FEKU= diff --git a/lnd.go b/lnd.go index d3edde16..2c2ebe32 100644 --- a/lnd.go +++ b/lnd.go @@ -543,6 +543,9 @@ func Main(cfg *Config, lisCfg ListenerCfg, interceptor signal.Interceptor) error NeutrinoCS: neutrinoCS, ActiveNetParams: cfg.ActiveNetParams, FeeURL: cfg.FeeURL, + Dialer: func(addr string) (net.Conn, error) { + return cfg.net.Dial("tcp", addr, cfg.ConnectionTimeout) + }, } activeChainControl, err := chainreg.NewChainControl(chainControlCfg) diff --git a/lnwallet/test/test_interface.go b/lnwallet/test/test_interface.go index 6873f2fe..32e3ce66 100644 --- a/lnwallet/test/test_interface.go +++ b/lnwallet/test/test_interface.go @@ -3323,11 +3323,19 @@ func runTests(t *testing.T, walletDriver *lnwallet.WalletDriver, host := fmt.Sprintf("127.0.0.1:%d", rpcPort) var chainConn *chain.BitcoindConn err = wait.NoError(func() error { - chainConn, err = chain.NewBitcoindConn( - netParams, host, "weks", "weks", - zmqBlockHost, zmqTxHost, - 100*time.Millisecond, - ) + chainConn, err = chain.NewBitcoindConn(&chain.BitcoindConfig{ + ChainParams: netParams, + Host: host, + User: "weks", + Pass: "weks", + ZMQBlockHost: zmqBlockHost, + ZMQTxHost: zmqTxHost, + ZMQReadDeadline: 5 * time.Second, + // Fields only required for pruned nodes, not + // needed for these tests. + Dialer: nil, + PrunedModeMaxPeers: 0, + }) if err != nil { return err } diff --git a/routing/chainview/interface_test.go b/routing/chainview/interface_test.go index d77b1a15..33975e0a 100644 --- a/routing/chainview/interface_test.go +++ b/routing/chainview/interface_test.go @@ -816,11 +816,19 @@ var interfaceImpls = []struct { time.Sleep(time.Second) host := fmt.Sprintf("127.0.0.1:%d", rpcPort) - chainConn, err := chain.NewBitcoindConn( - &chaincfg.RegressionNetParams, host, "weks", - "weks", zmqBlockHost, zmqTxHost, - 100*time.Millisecond, - ) + chainConn, err := chain.NewBitcoindConn(&chain.BitcoindConfig{ + ChainParams: &chaincfg.RegressionNetParams, + Host: host, + User: "weks", + Pass: "weks", + ZMQBlockHost: zmqBlockHost, + ZMQTxHost: zmqTxHost, + ZMQReadDeadline: 5 * time.Second, + // Fields only required for pruned nodes, not + // needed for these tests. + Dialer: nil, + PrunedModeMaxPeers: 0, + }) if err != nil { return cleanUp2, nil, fmt.Errorf("unable to "+ "establish connection to bitcoind: %v",