Skip to content

Commit

Permalink
Merge e58486b into 61681a5
Browse files Browse the repository at this point in the history
  • Loading branch information
wpaulino committed Aug 9, 2018
2 parents 61681a5 + e58486b commit 160c224
Show file tree
Hide file tree
Showing 12 changed files with 251 additions and 237 deletions.
18 changes: 8 additions & 10 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Expand Up @@ -72,7 +72,7 @@

[[constraint]]
name = "github.com/btcsuite/btcwallet"
revision = "a4d9da433fcfaeec50d3e9657e6d511d14cddadf"
revision = "1ede0a1a66bad8f7db796615e496a0a0faba5182"

[[constraint]]
name = "github.com/tv42/zbase32"
Expand Down
18 changes: 3 additions & 15 deletions chainntnfs/bitcoindnotify/bitcoind.go
Expand Up @@ -8,9 +8,7 @@ import (
"time"

"github.com/btcsuite/btcd/btcjson"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/rpcclient"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcwallet/chain"
Expand Down Expand Up @@ -87,8 +85,7 @@ var _ chainntnfs.ChainNotifier = (*BitcoindNotifier)(nil)
// New returns a new BitcoindNotifier instance. This function assumes the
// bitcoind node detailed in the passed configuration is already running, and
// willing to accept RPC requests and new zmq clients.
func New(config *rpcclient.ConnConfig, zmqConnect string,
params chaincfg.Params) (*BitcoindNotifier, error) {
func New(chainConn *chain.BitcoindConn) *BitcoindNotifier {
notifier := &BitcoindNotifier{
notificationCancels: make(chan interface{}),
notificationRegistry: make(chan interface{}),
Expand All @@ -100,18 +97,9 @@ func New(config *rpcclient.ConnConfig, zmqConnect string,
quit: make(chan struct{}),
}

// Disable connecting to bitcoind within the rpcclient.New method. We
// defer establishing the connection to our .Start() method.
config.DisableConnectOnNew = true
config.DisableAutoReconnect = false
chainConn, err := chain.NewBitcoindClient(&params, config.Host,
config.User, config.Pass, zmqConnect, 100*time.Millisecond)
if err != nil {
return nil, err
}
notifier.chainConn = chainConn
notifier.chainConn = chainConn.NewBitcoindClient(time.Unix(0, 0))

return notifier, nil
return notifier
}

// Start connects to the running bitcoind node over websockets, registers for
Expand Down
27 changes: 7 additions & 20 deletions chainntnfs/bitcoindnotify/driver.go
Expand Up @@ -3,38 +3,25 @@ package bitcoindnotify
import (
"fmt"

"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/rpcclient"
"github.com/btcsuite/btcwallet/chain"
"github.com/lightningnetwork/lnd/chainntnfs"
)

// createNewNotifier creates a new instance of the ChainNotifier interface
// implemented by BitcoindNotifier.
func createNewNotifier(args ...interface{}) (chainntnfs.ChainNotifier, error) {
if len(args) != 3 {
if len(args) != 1 {
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 {
return nil, fmt.Errorf("first argument to bitcoindnotifier." +
"New is incorrect, expected a *rpcclient.ConnConfig")
return nil, fmt.Errorf("first argument to bitcoindnotify.New " +
"is incorrect, expected a *chain.BitcoindConn")
}

zmqConnect, ok := args[1].(string)
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)
return New(chainConn), nil
}

// init registers a driver for the BtcdNotifier concrete implementation of the
Expand Down
49 changes: 28 additions & 21 deletions chainntnfs/interface_test.go
Expand Up @@ -13,19 +13,19 @@ import (
"testing"
"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/btcjson"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/integration/rpctest"
"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/lightninglabs/neutrino"
"github.com/lightningnetwork/lnd/chainntnfs"

// Required to auto-register the bitcoind backed ChainNotifier
// implementation.
Expand Down Expand Up @@ -1375,7 +1375,8 @@ func TestInterfaces(t *testing.T) {
if err != nil {
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() {
os.RemoveAll(tempBitcoindDir)
}
Expand All @@ -1392,8 +1393,8 @@ func TestInterfaces(t *testing.T) {
"220110063096c221be9933c82d38e1",
fmt.Sprintf("-rpcport=%d", rpcPort),
"-disablewallet",
"-zmqpubrawblock="+zmqPath,
"-zmqpubrawtx="+zmqPath,
"-zmqpubrawblock="+zmqBlockHost,
"-zmqpubrawtx="+zmqTxHost,
)
err = bitcoind.Start()
if err != nil {
Expand All @@ -1410,20 +1411,26 @@ func TestInterfaces(t *testing.T) {
// Wait for the bitcoind instance to start up.
time.Sleep(time.Second)

// Start the FilteredChainView implementation instance.
config := rpcclient.ConnConfig{
Host: fmt.Sprintf(
"127.0.0.1:%d", rpcPort),
User: "weks",
Pass: "weks",
DisableAutoReconnect: false,
DisableConnectOnNew: true,
DisableTLS: true,
HTTPPostMode: true,
host := fmt.Sprintf("127.0.0.1:%d", rpcPort)
chainConn, err := chain.NewBitcoindConn(
netParams, host, "weks", "weks", zmqBlockHost,
zmqTxHost, 100*time.Millisecond,
)
if err != nil {
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)
}
cleanUp3 := func() {
chainConn.Stop()
cleanUp2()
}
cleanUp = cleanUp3

notifier, err = notifierDriver.New(&config, zmqPath,
*netParams)
notifier, err = notifierDriver.New(chainConn)
if err != nil {
t.Fatalf("unable to create %v notifier: %v",
notifierType, err)
Expand Down
53 changes: 21 additions & 32 deletions chainregistry.go
Expand Up @@ -171,9 +171,8 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB,
}

var (
err error
cleanUp func()
bitcoindConn *chain.BitcoindClient
err error
cleanUp func()
)

// If spv mode is active, then we'll be using a distinct set of
Expand Down Expand Up @@ -300,47 +299,37 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB,
}
}

bitcoindUser := bitcoindMode.RPCUser
bitcoindPass := bitcoindMode.RPCPass
rpcConfig := &rpcclient.ConnConfig{
Host: bitcoindHost,
User: bitcoindUser,
Pass: bitcoindPass,
DisableConnectOnNew: true,
DisableAutoReconnect: false,
DisableTLS: true,
HTTPPostMode: true,
}
cc.chainNotifier, err = bitcoindnotify.New(rpcConfig,
bitcoindMode.ZMQPath, *activeNetParams.Params)
bitcoindConn, err := chain.NewBitcoindConn(
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, err = chainview.NewBitcoindFilteredChainView(
*rpcConfig, bitcoindMode.ZMQPath,
*activeNetParams.Params)
if err != nil {
srvrLog.Errorf("unable to create chain view: %v", err)
return nil, nil, err
}
cc.chainView = chainview.NewBitcoindFilteredChainView(bitcoindConn)

// 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
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{
Host: bitcoindHost,
User: bitcoindMode.RPCUser,
Pass: bitcoindMode.RPCPass,
DisableConnectOnNew: true,
DisableAutoReconnect: false,
DisableTLS: true,
HTTPPostMode: true,
}
if cfg.Bitcoin.Active && !cfg.Bitcoin.RegTest {
ltndLog.Infof("Initializing bitcoind backed fee estimator")

Expand Down

0 comments on commit 160c224

Please sign in to comment.