Merge pull request #1566 from wpaulino/bitcoind-rescan-client
multi: share the same bitcoind connection between multiple rescan clients
This commit is contained in:
commit
30b156c706
18
Gopkg.lock
generated
18
Gopkg.lock
generated
@ -12,7 +12,7 @@
|
|||||||
"internal/modes",
|
"internal/modes",
|
||||||
]
|
]
|
||||||
pruneopts = "UT"
|
pruneopts = "UT"
|
||||||
revision = "e06297f34865a50b8e473105e52cb64ad1b55da8"
|
revision = "c0276d75487ef7aceab140c9eb31601dd7d18bd4"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
@ -46,14 +46,14 @@
|
|||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
digest = "1:9968b12a9d89a2f0aff1e67b36544002d86f35757253055289ecb6051c4081b1"
|
digest = "1:e05c7b72aeba7570b1d2f9c6dc9f0373d224b16b70fa886c504de867bffe1c2e"
|
||||||
name = "github.com/aead/chacha20"
|
name = "github.com/aead/chacha20"
|
||||||
packages = [
|
packages = [
|
||||||
".",
|
".",
|
||||||
"chacha",
|
"chacha",
|
||||||
]
|
]
|
||||||
pruneopts = "UT"
|
pruneopts = "UT"
|
||||||
revision = "e2538746bfea853aaa589feb8ec46bd46ee78f86"
|
revision = "8b13a72661dae6e9e5dea04f344f0dc95ea29547"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
@ -120,7 +120,7 @@
|
|||||||
revision = "ab6388e0c60ae4834a1f57511e20c17b5f78be4b"
|
revision = "ab6388e0c60ae4834a1f57511e20c17b5f78be4b"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:9fd2a2efb76ddbde252f60de59aa921e3995ca1a477102b570dff963fd43d4b2"
|
digest = "1:a9bb59675f2aa863eff2bab6f0668b5e6feacaf6b7978fe5a654b068d5ca8e36"
|
||||||
name = "github.com/btcsuite/btcwallet"
|
name = "github.com/btcsuite/btcwallet"
|
||||||
packages = [
|
packages = [
|
||||||
"chain",
|
"chain",
|
||||||
@ -140,7 +140,7 @@
|
|||||||
"wtxmgr",
|
"wtxmgr",
|
||||||
]
|
]
|
||||||
pruneopts = "UT"
|
pruneopts = "UT"
|
||||||
revision = "a4d9da433fcfaeec50d3e9657e6d511d14cddadf"
|
revision = "1ede0a1a66bad8f7db796615e496a0a0faba5182"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
@ -298,10 +298,9 @@
|
|||||||
revision = "ac4d9da8f1d67c95f1fafdc65e1a4902d6f5a940"
|
revision = "ac4d9da8f1d67c95f1fafdc65e1a4902d6f5a940"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:9acb4594b6cbb2658faebd72023de1e6b8a2b9af05384b97033771dfcd2e9f9d"
|
digest = "1:9e09c46058b3f1456c2690bd853ecd769fce3df943f7883fba64cb8f2be34f33"
|
||||||
name = "github.com/ltcsuite/ltcd"
|
name = "github.com/ltcsuite/ltcd"
|
||||||
packages = [
|
packages = [
|
||||||
"btcjson",
|
|
||||||
"chaincfg",
|
"chaincfg",
|
||||||
"chaincfg/chainhash",
|
"chaincfg/chainhash",
|
||||||
"wire",
|
"wire",
|
||||||
@ -384,7 +383,7 @@
|
|||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
digest = "1:29581da029e6dfb8e5ad30790fc66f9b59ba43805b66d840ea84000027175073"
|
digest = "1:01b240e338435648db3155614b819aa03735c3e7920712f32638f53272895bfb"
|
||||||
name = "golang.org/x/sys"
|
name = "golang.org/x/sys"
|
||||||
packages = [
|
packages = [
|
||||||
"cpu",
|
"cpu",
|
||||||
@ -392,7 +391,7 @@
|
|||||||
"windows",
|
"windows",
|
||||||
]
|
]
|
||||||
pruneopts = "UT"
|
pruneopts = "UT"
|
||||||
revision = "56ede360ec1c541828fb88741b3f1049406d28f5"
|
revision = "904bdc257025c7b3f43c19360ad3ab85783fad78"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:436b24586f8fee329e0dd65fd67c817681420cda1d7f934345c13fe78c212a73"
|
digest = "1:436b24586f8fee329e0dd65fd67c817681420cda1d7f934345c13fe78c212a73"
|
||||||
@ -534,7 +533,6 @@
|
|||||||
"github.com/kkdai/bstream",
|
"github.com/kkdai/bstream",
|
||||||
"github.com/lightninglabs/neutrino",
|
"github.com/lightninglabs/neutrino",
|
||||||
"github.com/lightningnetwork/lightning-onion",
|
"github.com/lightningnetwork/lightning-onion",
|
||||||
"github.com/ltcsuite/ltcd/btcjson",
|
|
||||||
"github.com/ltcsuite/ltcd/chaincfg",
|
"github.com/ltcsuite/ltcd/chaincfg",
|
||||||
"github.com/ltcsuite/ltcd/wire",
|
"github.com/ltcsuite/ltcd/wire",
|
||||||
"github.com/miekg/dns",
|
"github.com/miekg/dns",
|
||||||
|
@ -72,7 +72,7 @@
|
|||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
name = "github.com/btcsuite/btcwallet"
|
name = "github.com/btcsuite/btcwallet"
|
||||||
revision = "a4d9da433fcfaeec50d3e9657e6d511d14cddadf"
|
revision = "1ede0a1a66bad8f7db796615e496a0a0faba5182"
|
||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
name = "github.com/tv42/zbase32"
|
name = "github.com/tv42/zbase32"
|
||||||
|
@ -8,9 +8,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcjson"
|
"github.com/btcsuite/btcd/btcjson"
|
||||||
"github.com/btcsuite/btcd/chaincfg"
|
|
||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
"github.com/btcsuite/btcd/rpcclient"
|
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
"github.com/btcsuite/btcwallet/chain"
|
"github.com/btcsuite/btcwallet/chain"
|
||||||
@ -87,8 +85,7 @@ var _ chainntnfs.ChainNotifier = (*BitcoindNotifier)(nil)
|
|||||||
// New returns a new BitcoindNotifier instance. This function assumes the
|
// New returns a new BitcoindNotifier instance. This function assumes the
|
||||||
// bitcoind node detailed in the passed configuration is already running, and
|
// bitcoind node detailed in the passed configuration is already running, and
|
||||||
// willing to accept RPC requests and new zmq clients.
|
// willing to accept RPC requests and new zmq clients.
|
||||||
func New(config *rpcclient.ConnConfig, zmqConnect string,
|
func New(chainConn *chain.BitcoindConn) *BitcoindNotifier {
|
||||||
params chaincfg.Params) (*BitcoindNotifier, error) {
|
|
||||||
notifier := &BitcoindNotifier{
|
notifier := &BitcoindNotifier{
|
||||||
notificationCancels: make(chan interface{}),
|
notificationCancels: make(chan interface{}),
|
||||||
notificationRegistry: make(chan interface{}),
|
notificationRegistry: make(chan interface{}),
|
||||||
@ -100,18 +97,9 @@ func New(config *rpcclient.ConnConfig, zmqConnect string,
|
|||||||
quit: make(chan struct{}),
|
quit: make(chan struct{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable connecting to bitcoind within the rpcclient.New method. We
|
notifier.chainConn = chainConn.NewBitcoindClient(time.Unix(0, 0))
|
||||||
// defer establishing the connection to our .Start() method.
|
|
||||||
config.DisableConnectOnNew = true
|
|
||||||
config.DisableAutoReconnect = false
|
|
||||||
chainConn, err := chain.NewBitcoindClient(¶ms, config.Host,
|
|
||||||
config.User, config.Pass, zmqConnect, 100*time.Millisecond)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
notifier.chainConn = chainConn
|
|
||||||
|
|
||||||
return notifier, nil
|
return notifier
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start connects to the running bitcoind node over websockets, registers for
|
// Start connects to the running bitcoind node over websockets, registers for
|
||||||
|
@ -3,38 +3,25 @@ package bitcoindnotify
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/chaincfg"
|
"github.com/btcsuite/btcwallet/chain"
|
||||||
"github.com/btcsuite/btcd/rpcclient"
|
|
||||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||||
)
|
)
|
||||||
|
|
||||||
// createNewNotifier creates a new instance of the ChainNotifier interface
|
// createNewNotifier creates a new instance of the ChainNotifier interface
|
||||||
// implemented by BitcoindNotifier.
|
// implemented by BitcoindNotifier.
|
||||||
func createNewNotifier(args ...interface{}) (chainntnfs.ChainNotifier, error) {
|
func createNewNotifier(args ...interface{}) (chainntnfs.ChainNotifier, error) {
|
||||||
if len(args) != 3 {
|
if len(args) != 1 {
|
||||||
return nil, fmt.Errorf("incorrect number of arguments to "+
|
return nil, fmt.Errorf("incorrect number of arguments to "+
|
||||||
".New(...), expected 3, instead passed %v", len(args))
|
".New(...), expected 1, instead passed %v", len(args))
|
||||||
}
|
}
|
||||||
|
|
||||||
config, ok := args[0].(*rpcclient.ConnConfig)
|
chainConn, ok := args[0].(*chain.BitcoindConn)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("first argument to bitcoindnotifier." +
|
return nil, fmt.Errorf("first argument to bitcoindnotify.New " +
|
||||||
"New is incorrect, expected a *rpcclient.ConnConfig")
|
"is incorrect, expected a *chain.BitcoindConn")
|
||||||
}
|
}
|
||||||
|
|
||||||
zmqConnect, ok := args[1].(string)
|
return New(chainConn), nil
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("second argument to bitcoindnotifier." +
|
|
||||||
"New is incorrect, expected a string")
|
|
||||||
}
|
|
||||||
|
|
||||||
params, ok := args[2].(chaincfg.Params)
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("third argument to bitcoindnotifier." +
|
|
||||||
"New is incorrect, expected a chaincfg.Params")
|
|
||||||
}
|
|
||||||
|
|
||||||
return New(config, zmqConnect, params)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// init registers a driver for the BtcdNotifier concrete implementation of the
|
// init registers a driver for the BtcdNotifier concrete implementation of the
|
||||||
|
@ -13,19 +13,19 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
|
||||||
"github.com/btcsuite/btcwallet/walletdb"
|
|
||||||
"github.com/lightninglabs/neutrino"
|
|
||||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
|
||||||
"github.com/ltcsuite/ltcd/btcjson"
|
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcec"
|
"github.com/btcsuite/btcd/btcec"
|
||||||
|
"github.com/btcsuite/btcd/btcjson"
|
||||||
"github.com/btcsuite/btcd/chaincfg"
|
"github.com/btcsuite/btcd/chaincfg"
|
||||||
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
"github.com/btcsuite/btcd/integration/rpctest"
|
"github.com/btcsuite/btcd/integration/rpctest"
|
||||||
"github.com/btcsuite/btcd/rpcclient"
|
"github.com/btcsuite/btcd/rpcclient"
|
||||||
"github.com/btcsuite/btcd/txscript"
|
"github.com/btcsuite/btcd/txscript"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
|
"github.com/btcsuite/btcwallet/chain"
|
||||||
|
"github.com/btcsuite/btcwallet/walletdb"
|
||||||
|
"github.com/lightninglabs/neutrino"
|
||||||
|
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||||
|
|
||||||
// Required to auto-register the bitcoind backed ChainNotifier
|
// Required to auto-register the bitcoind backed ChainNotifier
|
||||||
// implementation.
|
// implementation.
|
||||||
@ -1375,7 +1375,8 @@ func TestInterfaces(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to create temp dir: %v", err)
|
t.Fatalf("Unable to create temp dir: %v", err)
|
||||||
}
|
}
|
||||||
zmqPath := "ipc:///" + tempBitcoindDir + "/weks.socket"
|
zmqBlockHost := "ipc:///" + tempBitcoindDir + "/blocks.socket"
|
||||||
|
zmqTxHost := "ipc:///" + tempBitcoindDir + "/tx.socket"
|
||||||
cleanUp1 := func() {
|
cleanUp1 := func() {
|
||||||
os.RemoveAll(tempBitcoindDir)
|
os.RemoveAll(tempBitcoindDir)
|
||||||
}
|
}
|
||||||
@ -1392,8 +1393,8 @@ func TestInterfaces(t *testing.T) {
|
|||||||
"220110063096c221be9933c82d38e1",
|
"220110063096c221be9933c82d38e1",
|
||||||
fmt.Sprintf("-rpcport=%d", rpcPort),
|
fmt.Sprintf("-rpcport=%d", rpcPort),
|
||||||
"-disablewallet",
|
"-disablewallet",
|
||||||
"-zmqpubrawblock="+zmqPath,
|
"-zmqpubrawblock="+zmqBlockHost,
|
||||||
"-zmqpubrawtx="+zmqPath,
|
"-zmqpubrawtx="+zmqTxHost,
|
||||||
)
|
)
|
||||||
err = bitcoind.Start()
|
err = bitcoind.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1410,20 +1411,26 @@ func TestInterfaces(t *testing.T) {
|
|||||||
// Wait for the bitcoind instance to start up.
|
// Wait for the bitcoind instance to start up.
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
|
|
||||||
// Start the FilteredChainView implementation instance.
|
host := fmt.Sprintf("127.0.0.1:%d", rpcPort)
|
||||||
config := rpcclient.ConnConfig{
|
chainConn, err := chain.NewBitcoindConn(
|
||||||
Host: fmt.Sprintf(
|
netParams, host, "weks", "weks", zmqBlockHost,
|
||||||
"127.0.0.1:%d", rpcPort),
|
zmqTxHost, 100*time.Millisecond,
|
||||||
User: "weks",
|
)
|
||||||
Pass: "weks",
|
if err != nil {
|
||||||
DisableAutoReconnect: false,
|
t.Fatalf("unable to establish connection to "+
|
||||||
DisableConnectOnNew: true,
|
"bitcoind: %v", err)
|
||||||
DisableTLS: true,
|
|
||||||
HTTPPostMode: true,
|
|
||||||
}
|
}
|
||||||
|
if err := chainConn.Start(); err != nil {
|
||||||
|
t.Fatalf("unable to establish connection to "+
|
||||||
|
"bitcoind: %v", err)
|
||||||
|
}
|
||||||
|
cleanUp3 := func() {
|
||||||
|
chainConn.Stop()
|
||||||
|
cleanUp2()
|
||||||
|
}
|
||||||
|
cleanUp = cleanUp3
|
||||||
|
|
||||||
notifier, err = notifierDriver.New(&config, zmqPath,
|
notifier, err = notifierDriver.New(chainConn)
|
||||||
*netParams)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create %v notifier: %v",
|
t.Fatalf("unable to create %v notifier: %v",
|
||||||
notifierType, err)
|
notifierType, err)
|
||||||
|
@ -171,9 +171,8 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB,
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
cleanUp func()
|
cleanUp func()
|
||||||
bitcoindConn *chain.BitcoindClient
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// If spv mode is active, then we'll be using a distinct set of
|
// If spv mode is active, then we'll be using a distinct set of
|
||||||
@ -300,47 +299,37 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bitcoindUser := bitcoindMode.RPCUser
|
bitcoindConn, err := chain.NewBitcoindConn(
|
||||||
bitcoindPass := bitcoindMode.RPCPass
|
activeNetParams.Params, bitcoindHost,
|
||||||
|
bitcoindMode.RPCUser, bitcoindMode.RPCPass,
|
||||||
|
bitcoindMode.ZMQPubRawBlock, bitcoindMode.ZMQPubRawTx,
|
||||||
|
100*time.Millisecond,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
cc.chainNotifier = bitcoindnotify.New(bitcoindConn)
|
||||||
|
|
||||||
|
// Next, we'll create an instance of the bitcoind chain view to
|
||||||
|
// be used within the routing layer.
|
||||||
|
cc.chainView = chainview.NewBitcoindFilteredChainView(bitcoindConn)
|
||||||
|
|
||||||
|
// Create a special rpc+ZMQ client for bitcoind which will be
|
||||||
|
// used by the wallet for notifications, calls, etc.
|
||||||
|
walletConfig.ChainSource = bitcoindConn.NewBitcoindClient(birthday)
|
||||||
|
|
||||||
|
// If we're not in regtest mode, then we'll attempt to use a
|
||||||
|
// proper fee estimator for testnet.
|
||||||
rpcConfig := &rpcclient.ConnConfig{
|
rpcConfig := &rpcclient.ConnConfig{
|
||||||
Host: bitcoindHost,
|
Host: bitcoindHost,
|
||||||
User: bitcoindUser,
|
User: bitcoindMode.RPCUser,
|
||||||
Pass: bitcoindPass,
|
Pass: bitcoindMode.RPCPass,
|
||||||
DisableConnectOnNew: true,
|
DisableConnectOnNew: true,
|
||||||
DisableAutoReconnect: false,
|
DisableAutoReconnect: false,
|
||||||
DisableTLS: true,
|
DisableTLS: true,
|
||||||
HTTPPostMode: true,
|
HTTPPostMode: true,
|
||||||
}
|
}
|
||||||
cc.chainNotifier, err = bitcoindnotify.New(rpcConfig,
|
|
||||||
bitcoindMode.ZMQPath, *activeNetParams.Params)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Next, we'll create an instance of the bitcoind chain view to
|
|
||||||
// be used within the routing layer.
|
|
||||||
cc.chainView, err = chainview.NewBitcoindFilteredChainView(
|
|
||||||
*rpcConfig, bitcoindMode.ZMQPath,
|
|
||||||
*activeNetParams.Params)
|
|
||||||
if err != nil {
|
|
||||||
srvrLog.Errorf("unable to create chain view: %v", err)
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a special rpc+ZMQ client for bitcoind which will be
|
|
||||||
// used by the wallet for notifications, calls, etc.
|
|
||||||
bitcoindConn, err = chain.NewBitcoindClient(
|
|
||||||
activeNetParams.Params, bitcoindHost, bitcoindUser,
|
|
||||||
bitcoindPass, bitcoindMode.ZMQPath,
|
|
||||||
time.Millisecond*100)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
walletConfig.ChainSource = bitcoindConn
|
|
||||||
|
|
||||||
// If we're not in regtest mode, then we'll attempt to use a
|
|
||||||
// proper fee estimator for testnet.
|
|
||||||
if cfg.Bitcoin.Active && !cfg.Bitcoin.RegTest {
|
if cfg.Bitcoin.Active && !cfg.Bitcoin.RegTest {
|
||||||
ltndLog.Infof("Initializing bitcoind backed fee estimator")
|
ltndLog.Infof("Initializing bitcoind backed fee estimator")
|
||||||
|
|
||||||
|
118
config.go
118
config.go
@ -133,11 +133,12 @@ type btcdConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type bitcoindConfig struct {
|
type bitcoindConfig struct {
|
||||||
Dir string `long:"dir" description:"The base directory that contains the node's data, logs, configuration file, etc."`
|
Dir string `long:"dir" description:"The base directory that contains the node's data, logs, configuration file, etc."`
|
||||||
RPCHost string `long:"rpchost" description:"The daemon's rpc listening address. If a port is omitted, then the default port for the selected chain parameters will be used."`
|
RPCHost string `long:"rpchost" description:"The daemon's rpc listening address. If a port is omitted, then the default port for the selected chain parameters will be used."`
|
||||||
RPCUser string `long:"rpcuser" description:"Username for RPC connections"`
|
RPCUser string `long:"rpcuser" description:"Username for RPC connections"`
|
||||||
RPCPass string `long:"rpcpass" default-mask:"-" description:"Password for RPC connections"`
|
RPCPass string `long:"rpcpass" default-mask:"-" description:"Password for RPC connections"`
|
||||||
ZMQPath string `long:"zmqpath" description:"The path to the ZMQ socket providing at least raw blocks. Raw transactions can be handled as well."`
|
ZMQPubRawBlock string `long:"zmqpubrawblock" description:"The address listening for ZMQ connections to deliver raw block notifications"`
|
||||||
|
ZMQPubRawTx string `long:"zmqpubrawtx" description:"The address listening for ZMQ connections to deliver raw transaction notifications"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type autoPilotConfig struct {
|
type autoPilotConfig struct {
|
||||||
@ -1057,8 +1058,12 @@ func parseRPCParams(cConfig *chainConfig, nodeConfig interface{}, net chainCode,
|
|||||||
switch net {
|
switch net {
|
||||||
case bitcoinChain:
|
case bitcoinChain:
|
||||||
daemonName = "btcd"
|
daemonName = "btcd"
|
||||||
|
confDir = conf.Dir
|
||||||
|
confFile = "btcd"
|
||||||
case litecoinChain:
|
case litecoinChain:
|
||||||
daemonName = "ltcd"
|
daemonName = "ltcd"
|
||||||
|
confDir = conf.Dir
|
||||||
|
confFile = "ltcd"
|
||||||
}
|
}
|
||||||
|
|
||||||
// If only ONE of RPCUser or RPCPass is set, we assume the
|
// If only ONE of RPCUser or RPCPass is set, we assume the
|
||||||
@ -1068,18 +1073,11 @@ func parseRPCParams(cConfig *chainConfig, nodeConfig interface{}, net chainCode,
|
|||||||
"%[1]v.rpcuser, %[1]v.rpcpass", daemonName)
|
"%[1]v.rpcuser, %[1]v.rpcpass", daemonName)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch net {
|
|
||||||
case bitcoinChain:
|
|
||||||
confDir = conf.Dir
|
|
||||||
confFile = "btcd"
|
|
||||||
case litecoinChain:
|
|
||||||
confDir = conf.Dir
|
|
||||||
confFile = "ltcd"
|
|
||||||
}
|
|
||||||
case *bitcoindConfig:
|
case *bitcoindConfig:
|
||||||
// If all of RPCUser, RPCPass, and ZMQPath are set, we assume
|
// If all of RPCUser, RPCPass, ZMQBlockHost, and ZMQTxHost are
|
||||||
// those parameters are good to use.
|
// set, we assume those parameters are good to use.
|
||||||
if conf.RPCUser != "" && conf.RPCPass != "" && conf.ZMQPath != "" {
|
if conf.RPCUser != "" && conf.RPCPass != "" &&
|
||||||
|
conf.ZMQPubRawBlock != "" && conf.ZMQPubRawTx != "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1087,25 +1085,24 @@ func parseRPCParams(cConfig *chainConfig, nodeConfig interface{}, net chainCode,
|
|||||||
switch net {
|
switch net {
|
||||||
case bitcoinChain:
|
case bitcoinChain:
|
||||||
daemonName = "bitcoind"
|
daemonName = "bitcoind"
|
||||||
case litecoinChain:
|
|
||||||
daemonName = "litecoind"
|
|
||||||
}
|
|
||||||
// If only one or two of the parameters are set, we assume the
|
|
||||||
// user did that unintentionally.
|
|
||||||
if conf.RPCUser != "" || conf.RPCPass != "" || conf.ZMQPath != "" {
|
|
||||||
return fmt.Errorf("please set all or none of "+
|
|
||||||
"%[1]v.rpcuser, %[1]v.rpcpass, "+
|
|
||||||
"and %[1]v.zmqpath", daemonName)
|
|
||||||
}
|
|
||||||
|
|
||||||
switch net {
|
|
||||||
case bitcoinChain:
|
|
||||||
confDir = conf.Dir
|
confDir = conf.Dir
|
||||||
confFile = "bitcoin"
|
confFile = "bitcoin"
|
||||||
case litecoinChain:
|
case litecoinChain:
|
||||||
|
daemonName = "litecoind"
|
||||||
confDir = conf.Dir
|
confDir = conf.Dir
|
||||||
confFile = "litecoin"
|
confFile = "litecoin"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If only one or two of the parameters are set, we assume the
|
||||||
|
// user did that unintentionally.
|
||||||
|
if conf.RPCUser != "" || conf.RPCPass != "" ||
|
||||||
|
conf.ZMQPubRawBlock != "" || conf.ZMQPubRawTx != "" {
|
||||||
|
|
||||||
|
return fmt.Errorf("please set all or none of "+
|
||||||
|
"%[1]v.rpcuser, %[1]v.rpcpass, "+
|
||||||
|
"%[1]v.zmqpubrawblock, %[1]v.zmqpubrawtx",
|
||||||
|
daemonName)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we're in simnet mode, then the running btcd instance won't read
|
// If we're in simnet mode, then the running btcd instance won't read
|
||||||
@ -1132,13 +1129,15 @@ func parseRPCParams(cConfig *chainConfig, nodeConfig interface{}, net chainCode,
|
|||||||
nConf.RPCUser, nConf.RPCPass = rpcUser, rpcPass
|
nConf.RPCUser, nConf.RPCPass = rpcUser, rpcPass
|
||||||
case "bitcoind", "litecoind":
|
case "bitcoind", "litecoind":
|
||||||
nConf := nodeConfig.(*bitcoindConfig)
|
nConf := nodeConfig.(*bitcoindConfig)
|
||||||
rpcUser, rpcPass, zmqPath, err := extractBitcoindRPCParams(confFile)
|
rpcUser, rpcPass, zmqBlockHost, zmqTxHost, err :=
|
||||||
|
extractBitcoindRPCParams(confFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to extract RPC credentials:"+
|
return fmt.Errorf("unable to extract RPC credentials:"+
|
||||||
" %v, cannot start w/o RPC connection",
|
" %v, cannot start w/o RPC connection",
|
||||||
err)
|
err)
|
||||||
}
|
}
|
||||||
nConf.RPCUser, nConf.RPCPass, nConf.ZMQPath = rpcUser, rpcPass, zmqPath
|
nConf.RPCUser, nConf.RPCPass = rpcUser, rpcPass
|
||||||
|
nConf.ZMQPubRawBlock, nConf.ZMQPubRawTx = zmqBlockHost, zmqTxHost
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Automatically obtained %v's RPC credentials\n", daemonName)
|
fmt.Printf("Automatically obtained %v's RPC credentials\n", daemonName)
|
||||||
@ -1196,13 +1195,12 @@ func extractBtcdRPCParams(btcdConfigPath string) (string, string, error) {
|
|||||||
// location of bitcoind's bitcoin.conf on the target system. The routine looks
|
// location of bitcoind's bitcoin.conf on the target system. The routine looks
|
||||||
// for a cookie first, optionally following the datadir configuration option in
|
// for a cookie first, optionally following the datadir configuration option in
|
||||||
// the bitcoin.conf. If it doesn't find one, it looks for rpcuser/rpcpassword.
|
// the bitcoin.conf. If it doesn't find one, it looks for rpcuser/rpcpassword.
|
||||||
func extractBitcoindRPCParams(bitcoindConfigPath string) (string, string, string, error) {
|
func extractBitcoindRPCParams(bitcoindConfigPath string) (string, string, string, string, error) {
|
||||||
|
|
||||||
// First, we'll open up the bitcoind configuration file found at the
|
// First, we'll open up the bitcoind configuration file found at the
|
||||||
// target destination.
|
// target destination.
|
||||||
bitcoindConfigFile, err := os.Open(bitcoindConfigPath)
|
bitcoindConfigFile, err := os.Open(bitcoindConfigPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", "", err
|
return "", "", "", "", err
|
||||||
}
|
}
|
||||||
defer bitcoindConfigFile.Close()
|
defer bitcoindConfigFile.Close()
|
||||||
|
|
||||||
@ -1210,18 +1208,36 @@ func extractBitcoindRPCParams(bitcoindConfigPath string) (string, string, string
|
|||||||
// we can attempt to locate the RPC credentials.
|
// we can attempt to locate the RPC credentials.
|
||||||
configContents, err := ioutil.ReadAll(bitcoindConfigFile)
|
configContents, err := ioutil.ReadAll(bitcoindConfigFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", "", err
|
return "", "", "", "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
// First, we look for the ZMQ path for raw blocks. If raw transactions
|
// First, we'll look for the ZMQ hosts providing raw block and raw
|
||||||
// are sent over this interface, we can also get unconfirmed txs.
|
// transaction notifications.
|
||||||
zmqPathRE, err := regexp.Compile(`(?m)^\s*zmqpubrawblock\s*=\s*([^\s]+)`)
|
zmqBlockHostRE, err := regexp.Compile(
|
||||||
|
`(?m)^\s*zmqpubrawblock\s*=\s*([^\s]+)`,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", "", err
|
return "", "", "", "", err
|
||||||
}
|
}
|
||||||
zmqPathSubmatches := zmqPathRE.FindSubmatch(configContents)
|
zmqBlockHostSubmatches := zmqBlockHostRE.FindSubmatch(configContents)
|
||||||
if len(zmqPathSubmatches) < 2 {
|
if len(zmqBlockHostSubmatches) < 2 {
|
||||||
return "", "", "", fmt.Errorf("unable to find zmqpubrawblock in config")
|
return "", "", "", "", fmt.Errorf("unable to find " +
|
||||||
|
"zmqpubrawblock in config")
|
||||||
|
}
|
||||||
|
zmqTxHostRE, err := regexp.Compile(`(?m)^\s*zmqpubrawtx\s*=\s*([^\s]+)`)
|
||||||
|
if err != nil {
|
||||||
|
return "", "", "", "", err
|
||||||
|
}
|
||||||
|
zmqTxHostSubmatches := zmqTxHostRE.FindSubmatch(configContents)
|
||||||
|
if len(zmqTxHostSubmatches) < 2 {
|
||||||
|
return "", "", "", "", errors.New("unable to find zmqpubrawtx " +
|
||||||
|
"in config")
|
||||||
|
}
|
||||||
|
zmqBlockHost := string(zmqBlockHostSubmatches[1])
|
||||||
|
zmqTxHost := string(zmqTxHostSubmatches[1])
|
||||||
|
if zmqBlockHost == zmqTxHost {
|
||||||
|
return "", "", "", "", errors.New("zmqpubrawblock and " +
|
||||||
|
"zmqpubrawtx must be different")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Next, we'll try to find an auth cookie. We need to detect the chain
|
// Next, we'll try to find an auth cookie. We need to detect the chain
|
||||||
@ -1229,7 +1245,7 @@ func extractBitcoindRPCParams(bitcoindConfigPath string) (string, string, string
|
|||||||
dataDir := path.Dir(bitcoindConfigPath)
|
dataDir := path.Dir(bitcoindConfigPath)
|
||||||
dataDirRE, err := regexp.Compile(`(?m)^\s*datadir\s*=\s*([^\s]+)`)
|
dataDirRE, err := regexp.Compile(`(?m)^\s*datadir\s*=\s*([^\s]+)`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", "", err
|
return "", "", "", "", err
|
||||||
}
|
}
|
||||||
dataDirSubmatches := dataDirRE.FindSubmatch(configContents)
|
dataDirSubmatches := dataDirRE.FindSubmatch(configContents)
|
||||||
if dataDirSubmatches != nil {
|
if dataDirSubmatches != nil {
|
||||||
@ -1250,8 +1266,8 @@ func extractBitcoindRPCParams(bitcoindConfigPath string) (string, string, string
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
splitCookie := strings.Split(string(cookie), ":")
|
splitCookie := strings.Split(string(cookie), ":")
|
||||||
if len(splitCookie) == 2 {
|
if len(splitCookie) == 2 {
|
||||||
return splitCookie[0], splitCookie[1],
|
return splitCookie[0], splitCookie[1], zmqBlockHost,
|
||||||
string(zmqPathSubmatches[1]), nil
|
zmqTxHost, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1260,11 +1276,12 @@ func extractBitcoindRPCParams(bitcoindConfigPath string) (string, string, string
|
|||||||
// expression then we'll exit with an error.
|
// expression then we'll exit with an error.
|
||||||
rpcUserRegexp, err := regexp.Compile(`(?m)^\s*rpcuser\s*=\s*([^\s]+)`)
|
rpcUserRegexp, err := regexp.Compile(`(?m)^\s*rpcuser\s*=\s*([^\s]+)`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", "", err
|
return "", "", "", "", err
|
||||||
}
|
}
|
||||||
userSubmatches := rpcUserRegexp.FindSubmatch(configContents)
|
userSubmatches := rpcUserRegexp.FindSubmatch(configContents)
|
||||||
if userSubmatches == nil {
|
if userSubmatches == nil {
|
||||||
return "", "", "", fmt.Errorf("unable to find rpcuser in config")
|
return "", "", "", "", fmt.Errorf("unable to find rpcuser in " +
|
||||||
|
"config")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Similarly, we'll use another regular expression to find the set
|
// Similarly, we'll use another regular expression to find the set
|
||||||
@ -1272,15 +1289,16 @@ func extractBitcoindRPCParams(bitcoindConfigPath string) (string, string, string
|
|||||||
// error.
|
// error.
|
||||||
rpcPassRegexp, err := regexp.Compile(`(?m)^\s*rpcpassword\s*=\s*([^\s]+)`)
|
rpcPassRegexp, err := regexp.Compile(`(?m)^\s*rpcpassword\s*=\s*([^\s]+)`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", "", err
|
return "", "", "", "", err
|
||||||
}
|
}
|
||||||
passSubmatches := rpcPassRegexp.FindSubmatch(configContents)
|
passSubmatches := rpcPassRegexp.FindSubmatch(configContents)
|
||||||
if passSubmatches == nil {
|
if passSubmatches == nil {
|
||||||
return "", "", "", fmt.Errorf("unable to find rpcpassword in config")
|
return "", "", "", "", fmt.Errorf("unable to find rpcpassword " +
|
||||||
|
"in config")
|
||||||
}
|
}
|
||||||
|
|
||||||
return string(userSubmatches[1]), string(passSubmatches[1]),
|
return string(userSubmatches[1]), string(passSubmatches[1]),
|
||||||
string(zmqPathSubmatches[1]), nil
|
zmqBlockHost, zmqTxHost, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// normalizeNetwork returns the common name of a network type used to create
|
// normalizeNetwork returns the common name of a network type used to create
|
||||||
|
@ -240,10 +240,10 @@ the following:
|
|||||||
([this has now been fixed](https://github.com/Homebrew/homebrew-core/pull/23088)
|
([this has now been fixed](https://github.com/Homebrew/homebrew-core/pull/23088)
|
||||||
in the latest Homebrew recipe for bitcoin)
|
in the latest Homebrew recipe for bitcoin)
|
||||||
- Configure the `bitcoind` instance for ZMQ with `--zmqpubrawblock` and
|
- Configure the `bitcoind` instance for ZMQ with `--zmqpubrawblock` and
|
||||||
`--zmqpubrawtx` (the latter is optional but allows you to see unconfirmed
|
`--zmqpubrawtx`. These options must each use their own unique address in order
|
||||||
transactions in your wallet). They must be combined in the same ZMQ socket
|
to provide a reliable delivery of notifications (e.g.
|
||||||
address (e.g. `--zmqpubrawblock=tcp://127.0.0.1:28332` and
|
`--zmqpubrawblock=tcp://127.0.0.1:28332` and
|
||||||
`--zmqpubrawtx=tcp://127.0.0.1:28332`).
|
`--zmqpubrawtx=tcp://127.0.0.1:28333`).
|
||||||
- Start `bitcoind` running against testnet, and let it complete a full sync with
|
- Start `bitcoind` running against testnet, and let it complete a full sync with
|
||||||
the testnet chain (alternatively, use `--bitcoind.regtest` instead).
|
the testnet chain (alternatively, use `--bitcoind.regtest` instead).
|
||||||
|
|
||||||
@ -253,21 +253,43 @@ testnet=1
|
|||||||
server=1
|
server=1
|
||||||
daemon=1
|
daemon=1
|
||||||
zmqpubrawblock=tcp://127.0.0.1:28332
|
zmqpubrawblock=tcp://127.0.0.1:28332
|
||||||
zmqpubrawtx=tcp://127.0.0.1:28332
|
zmqpubrawtx=tcp://127.0.0.1:28333
|
||||||
```
|
```
|
||||||
|
|
||||||
Once all of the above is complete, and you've confirmed `bitcoind` is fully updated with the latest blocks on testnet, run the command below to launch `lnd` with `bitcoind` as your backend (as with `bitcoind`, you can create an `lnd.conf` to save these options, more info on that is described further below):
|
Once all of the above is complete, and you've confirmed `bitcoind` is fully
|
||||||
|
updated with the latest blocks on testnet, run the command below to launch `lnd`
|
||||||
|
with `bitcoind` as your backend (as with `bitcoind`, you can create an
|
||||||
|
`lnd.conf` to save these options, more info on that is described further below):
|
||||||
|
|
||||||
```
|
```
|
||||||
lnd --bitcoin.active --bitcoin.testnet --debuglevel=debug --bitcoin.node=bitcoind --bitcoind.rpcuser=REPLACEME --bitcoind.rpcpass=REPLACEME --bitcoind.zmqpath=tcp://127.0.0.1:28332 --externalip=X.X.X.X
|
lnd --bitcoin.active --bitcoin.testnet --debuglevel=debug --bitcoin.node=bitcoind --bitcoind.rpcuser=REPLACEME --bitcoind.rpcpass=REPLACEME --bitcoind.zmqpubrawblock=tcp://127.0.0.1:28332 --bitcoind.zmqpubrawblock=tcp://127.0.0.1:28333 --externalip=X.X.X.X
|
||||||
```
|
```
|
||||||
|
|
||||||
*NOTE:*
|
*NOTE:*
|
||||||
- The auth parameters `rpcuser` and `rpcpass` parameters can typically be determined by `lnd` for a `bitcoind` instance running under the same user, including when using cookie auth. In this case, you can exclude them from the `lnd` options entirely.
|
- The auth parameters `rpcuser` and `rpcpass` parameters can typically be
|
||||||
- If you DO choose to explicitly pass the auth parameters in your `lnd.conf` or command line options for `lnd` (`bitcoind.rpcuser` and `bitcoind.rpcpass` as shown in example command above), you must also specify the `bitcoind.zmqpath` option. Otherwise, `lnd` will attempt to get the configuration from your `bitcoin.conf`.
|
determined by `lnd` for a `bitcoind` instance running under the same user,
|
||||||
- You must ensure the same address (including port) is used for the `bitcoind.zmqpath` option passed to `lnd` as for the `zmqpubrawblock` and `zmqpubrawtx` passed in the `bitcoind` options.
|
including when using cookie auth. In this case, you can exclude them from the
|
||||||
- When running lnd and bitcoind on the same Windows machine, ensure you use 127.0.0.1, not localhost, for all configuration options that require a TCP/IP host address. If you use "localhost" as the host name, you may see extremely slow inter-process-communication between lnd and the bitcoind backend. If lnd is experiencing this issue, you'll see "Waiting for chain backend to finish sync, start_height=XXXXXX" as the last entry in the console or log output, and lnd will appear to hang. Normal lnd output will quickly show multiple messages like this as lnd consumes blocks from bitcoind.
|
`lnd` options entirely.
|
||||||
- Don't connect more than one instance of `lnd` to `bitcoind`. With the default `bitcoind` settings, having more than one instance of `lnd`, or `lnd` plus any application that consumes the RPC could cause `lnd` to miss crucial updates from the backend.
|
- If you DO choose to explicitly pass the auth parameters in your `lnd.conf` or
|
||||||
|
command line options for `lnd` (`bitcoind.rpcuser` and `bitcoind.rpcpass` as
|
||||||
|
shown in example command above), you must also specify the
|
||||||
|
`bitcoind.zmqpubrawblock` and `bitcoind.zmqpubrawtx` options. Otherwise, `lnd`
|
||||||
|
will attempt to get the configuration from your `bitcoin.conf`.
|
||||||
|
- You must ensure the same addresses are used for the `bitcoind.zmqpubrawblock`
|
||||||
|
and `bitcoind.zmqpubrawtx` options passed to `lnd` as for the `zmqpubrawblock`
|
||||||
|
and `zmqpubrawtx` passed in the `bitcoind` options respectively.
|
||||||
|
- When running lnd and bitcoind on the same Windows machine, ensure you use
|
||||||
|
127.0.0.1, not localhost, for all configuration options that require a TCP/IP
|
||||||
|
host address. If you use "localhost" as the host name, you may see extremely
|
||||||
|
slow inter-process-communication between lnd and the bitcoind backend. If lnd
|
||||||
|
is experiencing this issue, you'll see "Waiting for chain backend to finish
|
||||||
|
sync, start_height=XXXXXX" as the last entry in the console or log output, and
|
||||||
|
lnd will appear to hang. Normal lnd output will quickly show multiple
|
||||||
|
messages like this as lnd consumes blocks from bitcoind.
|
||||||
|
- Don't connect more than two or three instances of `lnd` to `bitcoind`. With
|
||||||
|
the default `bitcoind` settings, having more than one instance of `lnd`, or
|
||||||
|
`lnd` plus any application that consumes the RPC could cause `lnd` to miss
|
||||||
|
crucial updates from the backend.
|
||||||
|
|
||||||
#### Disabling Wallet Encryption
|
#### Disabling Wallet Encryption
|
||||||
|
|
||||||
|
@ -16,18 +16,21 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/coreos/bbolt"
|
"github.com/btcsuite/btcd/btcec"
|
||||||
"github.com/davecgh/go-spew/spew"
|
|
||||||
|
|
||||||
"github.com/btcsuite/btcwallet/chain"
|
|
||||||
"github.com/btcsuite/btcwallet/walletdb"
|
|
||||||
_ "github.com/btcsuite/btcwallet/walletdb/bdb"
|
|
||||||
"github.com/lightninglabs/neutrino"
|
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcjson"
|
"github.com/btcsuite/btcd/btcjson"
|
||||||
"github.com/btcsuite/btcd/chaincfg"
|
"github.com/btcsuite/btcd/chaincfg"
|
||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
|
"github.com/btcsuite/btcd/integration/rpctest"
|
||||||
"github.com/btcsuite/btcd/rpcclient"
|
"github.com/btcsuite/btcd/rpcclient"
|
||||||
|
"github.com/btcsuite/btcd/txscript"
|
||||||
|
"github.com/btcsuite/btcd/wire"
|
||||||
|
"github.com/btcsuite/btcutil"
|
||||||
|
"github.com/btcsuite/btcwallet/chain"
|
||||||
|
"github.com/btcsuite/btcwallet/walletdb"
|
||||||
|
_ "github.com/btcsuite/btcwallet/walletdb/bdb"
|
||||||
|
"github.com/coreos/bbolt"
|
||||||
|
"github.com/davecgh/go-spew/spew"
|
||||||
|
"github.com/lightninglabs/neutrino"
|
||||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||||
"github.com/lightningnetwork/lnd/chainntnfs/btcdnotify"
|
"github.com/lightningnetwork/lnd/chainntnfs/btcdnotify"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
@ -35,12 +38,6 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet/btcwallet"
|
"github.com/lightningnetwork/lnd/lnwallet/btcwallet"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcec"
|
|
||||||
"github.com/btcsuite/btcd/integration/rpctest"
|
|
||||||
"github.com/btcsuite/btcd/txscript"
|
|
||||||
"github.com/btcsuite/btcd/wire"
|
|
||||||
"github.com/btcsuite/btcutil"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -2150,7 +2147,8 @@ func runTests(t *testing.T, walletDriver *lnwallet.WalletDriver,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create temp directory: %v", err)
|
t.Fatalf("unable to create temp directory: %v", err)
|
||||||
}
|
}
|
||||||
zmqPath := "ipc:///" + tempBitcoindDir + "/weks.socket"
|
zmqBlockHost := "ipc:///" + tempBitcoindDir + "/blocks.socket"
|
||||||
|
zmqTxHost := "ipc:///" + tempBitcoindDir + "/tx.socket"
|
||||||
defer os.RemoveAll(tempBitcoindDir)
|
defer os.RemoveAll(tempBitcoindDir)
|
||||||
rpcPort := rand.Int()%(65536-1024) + 1024
|
rpcPort := rand.Int()%(65536-1024) + 1024
|
||||||
bitcoind := exec.Command(
|
bitcoind := exec.Command(
|
||||||
@ -2164,8 +2162,8 @@ func runTests(t *testing.T, walletDriver *lnwallet.WalletDriver,
|
|||||||
"220110063096c221be9933c82d38e1",
|
"220110063096c221be9933c82d38e1",
|
||||||
fmt.Sprintf("-rpcport=%d", rpcPort),
|
fmt.Sprintf("-rpcport=%d", rpcPort),
|
||||||
"-disablewallet",
|
"-disablewallet",
|
||||||
"-zmqpubrawblock="+zmqPath,
|
"-zmqpubrawblock="+zmqBlockHost,
|
||||||
"-zmqpubrawtx="+zmqPath,
|
"-zmqpubrawtx="+zmqTxHost,
|
||||||
)
|
)
|
||||||
err = bitcoind.Start()
|
err = bitcoind.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -2174,21 +2172,28 @@ func runTests(t *testing.T, walletDriver *lnwallet.WalletDriver,
|
|||||||
defer bitcoind.Wait()
|
defer bitcoind.Wait()
|
||||||
defer bitcoind.Process.Kill()
|
defer bitcoind.Process.Kill()
|
||||||
|
|
||||||
// Start an Alice btcwallet bitcoind back end instance.
|
// Wait for the bitcoind instance to start up.
|
||||||
aliceClient, err = chain.NewBitcoindClient(netParams,
|
time.Sleep(time.Second)
|
||||||
fmt.Sprintf("127.0.0.1:%d", rpcPort), "weks",
|
|
||||||
"weks", zmqPath, 100*time.Millisecond)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("couldn't start alice client: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start a Bob btcwallet bitcoind back end instance.
|
host := fmt.Sprintf("127.0.0.1:%d", rpcPort)
|
||||||
bobClient, err = chain.NewBitcoindClient(netParams,
|
chainConn, err := chain.NewBitcoindConn(
|
||||||
fmt.Sprintf("127.0.0.1:%d", rpcPort), "weks",
|
netParams, host, "weks", "weks", zmqBlockHost,
|
||||||
"weks", zmqPath, 100*time.Millisecond)
|
zmqTxHost, 100*time.Millisecond,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("couldn't start bob client: %v", err)
|
t.Fatalf("unable to establish connection to "+
|
||||||
|
"bitcoind: %v", err)
|
||||||
}
|
}
|
||||||
|
if err := chainConn.Start(); err != nil {
|
||||||
|
t.Fatalf("unable to establish connection to "+
|
||||||
|
"bitcoind: %v", err)
|
||||||
|
}
|
||||||
|
defer chainConn.Stop()
|
||||||
|
|
||||||
|
// Create a btcwallet bitcoind client for both Alice and
|
||||||
|
// Bob.
|
||||||
|
aliceClient = chainConn.NewBitcoindClient(time.Unix(0, 0))
|
||||||
|
bobClient = chainConn.NewBitcoindClient(time.Unix(0, 0))
|
||||||
default:
|
default:
|
||||||
t.Fatalf("unknown chain driver: %v", backEnd)
|
t.Fatalf("unknown chain driver: %v", backEnd)
|
||||||
}
|
}
|
||||||
|
@ -9,9 +9,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcjson"
|
"github.com/btcsuite/btcd/btcjson"
|
||||||
"github.com/btcsuite/btcd/chaincfg"
|
|
||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
"github.com/btcsuite/btcd/rpcclient"
|
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcwallet/chain"
|
"github.com/btcsuite/btcwallet/chain"
|
||||||
"github.com/btcsuite/btcwallet/wtxmgr"
|
"github.com/btcsuite/btcwallet/wtxmgr"
|
||||||
@ -63,9 +61,8 @@ var _ FilteredChainView = (*BitcoindFilteredChainView)(nil)
|
|||||||
|
|
||||||
// NewBitcoindFilteredChainView creates a new instance of a FilteredChainView
|
// NewBitcoindFilteredChainView creates a new instance of a FilteredChainView
|
||||||
// from RPC credentials and a ZMQ socket address for a bitcoind instance.
|
// from RPC credentials and a ZMQ socket address for a bitcoind instance.
|
||||||
func NewBitcoindFilteredChainView(config rpcclient.ConnConfig,
|
func NewBitcoindFilteredChainView(
|
||||||
zmqConnect string, params chaincfg.Params) (*BitcoindFilteredChainView,
|
chainConn *chain.BitcoindConn) *BitcoindFilteredChainView {
|
||||||
error) {
|
|
||||||
|
|
||||||
chainView := &BitcoindFilteredChainView{
|
chainView := &BitcoindFilteredChainView{
|
||||||
chainFilter: make(map[wire.OutPoint]struct{}),
|
chainFilter: make(map[wire.OutPoint]struct{}),
|
||||||
@ -74,16 +71,10 @@ func NewBitcoindFilteredChainView(config rpcclient.ConnConfig,
|
|||||||
quit: make(chan struct{}),
|
quit: make(chan struct{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
chainConn, err := chain.NewBitcoindClient(¶ms, config.Host,
|
chainView.chainClient = chainConn.NewBitcoindClient(time.Unix(0, 0))
|
||||||
config.User, config.Pass, zmqConnect, 100*time.Millisecond)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
chainView.chainClient = chainConn
|
|
||||||
|
|
||||||
chainView.blockQueue = newBlockEventQueue()
|
chainView.blockQueue = newBlockEventQueue()
|
||||||
|
|
||||||
return chainView, nil
|
return chainView
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start starts all goroutines necessary for normal operation.
|
// Start starts all goroutines necessary for normal operation.
|
||||||
@ -325,9 +316,11 @@ func (b *BitcoindFilteredChainView) chainFilterer() {
|
|||||||
// will cause all following notifications from and
|
// will cause all following notifications from and
|
||||||
// calls to it return blocks filtered with the new
|
// calls to it return blocks filtered with the new
|
||||||
// filter.
|
// filter.
|
||||||
b.chainClient.LoadTxFilter(
|
err := b.chainClient.LoadTxFilter(false, update.newUtxos)
|
||||||
false, update.newUtxos,
|
if err != nil {
|
||||||
)
|
log.Errorf("Unable to update filter: %v", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// All blocks gotten after we loaded the filter will
|
// All blocks gotten after we loaded the filter will
|
||||||
// have the filter applied, but we will need to rescan
|
// have the filter applied, but we will need to rescan
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcec"
|
"github.com/btcsuite/btcd/btcec"
|
||||||
|
"github.com/btcsuite/btcd/btcjson"
|
||||||
"github.com/btcsuite/btcd/chaincfg"
|
"github.com/btcsuite/btcd/chaincfg"
|
||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
"github.com/btcsuite/btcd/integration/rpctest"
|
"github.com/btcsuite/btcd/integration/rpctest"
|
||||||
@ -20,12 +21,12 @@ import (
|
|||||||
"github.com/btcsuite/btcd/txscript"
|
"github.com/btcsuite/btcd/txscript"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
"github.com/lightninglabs/neutrino"
|
"github.com/btcsuite/btcwallet/chain"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
|
||||||
"github.com/ltcsuite/ltcd/btcjson"
|
|
||||||
|
|
||||||
"github.com/btcsuite/btcwallet/walletdb"
|
"github.com/btcsuite/btcwallet/walletdb"
|
||||||
_ "github.com/btcsuite/btcwallet/walletdb/bdb" // Required to register the boltdb walletdb implementation.
|
_ "github.com/btcsuite/btcwallet/walletdb/bdb" // Required to register the boltdb walletdb implementation.
|
||||||
|
|
||||||
|
"github.com/lightninglabs/neutrino"
|
||||||
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -776,7 +777,8 @@ var interfaceImpls = []struct {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
zmqPath := "ipc:///" + tempBitcoindDir + "/weks.socket"
|
zmqBlockHost := "ipc:///" + tempBitcoindDir + "/blocks.socket"
|
||||||
|
zmqTxHost := "ipc:///" + tempBitcoindDir + "/tx.socket"
|
||||||
cleanUp1 := func() {
|
cleanUp1 := func() {
|
||||||
os.RemoveAll(tempBitcoindDir)
|
os.RemoveAll(tempBitcoindDir)
|
||||||
}
|
}
|
||||||
@ -792,8 +794,8 @@ var interfaceImpls = []struct {
|
|||||||
"220110063096c221be9933c82d38e1",
|
"220110063096c221be9933c82d38e1",
|
||||||
fmt.Sprintf("-rpcport=%d", rpcPort),
|
fmt.Sprintf("-rpcport=%d", rpcPort),
|
||||||
"-disablewallet",
|
"-disablewallet",
|
||||||
"-zmqpubrawblock="+zmqPath,
|
"-zmqpubrawblock="+zmqBlockHost,
|
||||||
"-zmqpubrawtx="+zmqPath,
|
"-zmqpubrawtx="+zmqTxHost,
|
||||||
)
|
)
|
||||||
err = bitcoind.Start()
|
err = bitcoind.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -809,25 +811,30 @@ var interfaceImpls = []struct {
|
|||||||
// Wait for the bitcoind instance to start up.
|
// Wait for the bitcoind instance to start up.
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
|
|
||||||
// Start the FilteredChainView implementation instance.
|
host := fmt.Sprintf("127.0.0.1:%d", rpcPort)
|
||||||
config := rpcclient.ConnConfig{
|
chainConn, err := chain.NewBitcoindConn(
|
||||||
Host: fmt.Sprintf(
|
&chaincfg.RegressionNetParams, host, "weks",
|
||||||
"127.0.0.1:%d", rpcPort),
|
"weks", zmqBlockHost, zmqTxHost,
|
||||||
User: "weks",
|
100*time.Millisecond,
|
||||||
Pass: "weks",
|
)
|
||||||
DisableAutoReconnect: false,
|
if err != nil {
|
||||||
DisableConnectOnNew: true,
|
return cleanUp2, nil, fmt.Errorf("unable to "+
|
||||||
DisableTLS: true,
|
"establish connection to bitcoind: %v",
|
||||||
HTTPPostMode: true,
|
err)
|
||||||
|
}
|
||||||
|
if err := chainConn.Start(); err != nil {
|
||||||
|
return cleanUp2, nil, fmt.Errorf("unable to "+
|
||||||
|
"establish connection to bitcoind: %v",
|
||||||
|
err)
|
||||||
|
}
|
||||||
|
cleanUp3 := func() {
|
||||||
|
chainConn.Stop()
|
||||||
|
cleanUp2()
|
||||||
}
|
}
|
||||||
|
|
||||||
chainView, err := NewBitcoindFilteredChainView(config,
|
chainView := NewBitcoindFilteredChainView(chainConn)
|
||||||
zmqPath, chaincfg.RegressionNetParams)
|
|
||||||
if err != nil {
|
return cleanUp3, chainView, nil
|
||||||
cleanUp2()
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
return cleanUp2, chainView, nil
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -205,11 +205,11 @@ bitcoin.node=btcd
|
|||||||
; (other than for a remote bitcoind instance).
|
; (other than for a remote bitcoind instance).
|
||||||
; bitcoind.rpcpass=kek
|
; bitcoind.rpcpass=kek
|
||||||
|
|
||||||
; ZMQ socket which sends rawblock and (optionally) rawtx notifications from
|
; ZMQ socket which sends rawblock and rawtx notifications from bitcoind. By
|
||||||
; bitcoind. By default, lnd will attempt to automatically obtain this
|
; default, lnd will attempt to automatically obtain this information, so this
|
||||||
; information, so this likely won't need to be set (other than for a remote
|
; likely won't need to be set (other than for a remote bitcoind instance).
|
||||||
; bitcoind instance).
|
; bitcoind.zmqblockhost=tcp://127.0.0.1:28332
|
||||||
; bitcoind.zmqpath=tcp://127.0.0.1:28332
|
; bitcoind.zmqtxhost=tcp://127.0.0.1:28333
|
||||||
|
|
||||||
|
|
||||||
[neutrino]
|
[neutrino]
|
||||||
@ -283,11 +283,11 @@ litecoin.node=ltcd
|
|||||||
; (other than for a remote litecoind instance).
|
; (other than for a remote litecoind instance).
|
||||||
; litecoind.rpcpass=kek
|
; litecoind.rpcpass=kek
|
||||||
|
|
||||||
; ZMQ socket which sends rawblock and (optionally) rawtx notifications from
|
; ZMQ socket which sends rawblock and rawtx notifications from litecoind. By
|
||||||
; litecoind. By default, lnd will attempt to automatically obtain this
|
; default, lnd will attempt to automatically obtain this information, so this
|
||||||
; information, so this likely won't need to be set (other than for a remote
|
; likely won't need to be set (other than for a remote litecoind instance).
|
||||||
; litecoind instance).
|
; litecoind.zmqblockhost=tcp://127.0.0.1:28332
|
||||||
; litecoind.zmqpath=tcp://127.0.0.1:28332
|
; litecoind.zmqtxhost=tcp://127.0.0.1:28333
|
||||||
|
|
||||||
|
|
||||||
[autopilot]
|
[autopilot]
|
||||||
|
Loading…
Reference in New Issue
Block a user