Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multi: share the same bitcoind connection between multiple rescan clients #1566

Merged
merged 4 commits into from
Aug 10, 2018
Merged

multi: share the same bitcoind connection between multiple rescan clients #1566

merged 4 commits into from
Aug 10, 2018

Conversation

wpaulino
Copy link
Contributor

@wpaulino wpaulino commented Jul 17, 2018

In this PR, we introduce a nice optimization with regards to lnd's interaction with a bitcoind backend. Within lnd, we currently have three different subsystems responsible for watching the chain: chainntnfs, lnwallet, and routing/chainview. Each of these subsystems has an active RPC and ZMQ connection to the underlying bitcoind node. This would incur a toll on the underlying bitcoind node and would cause us to miss ZMQ events, which are crucial to lnd. We remedy this issue by sharing the same connection to a bitcoind node between the different clients within lnd.

We now also require the backing bitcoind node to use different hosts to provide its ZMQ raw block and raw transaction notifications (zmqpubrawblock and zmqpubrawtx). This was needed as the notification queue maintained by the bitcoind node would sometimes overflow with transactions and would cause block notifications to be dropped/missed.

Depends on btcsuite/btcwallet#511.
Fixes #1174.

@wpaulino wpaulino added config Parameters/arguments/config file related issues/PRs notifications backend Related to the node backend software/interface (e.g. btcd, bitcoin-core) bitcoind Bitcoin Core backend P2 should be fixed if one has time needs review PR needs review by regular contributors needs testing PR hasn't yet been actively tested on testnet/mainnet labels Jul 17, 2018
@Roasbeef Roasbeef requested a review from halseth July 17, 2018 06:25
@Roasbeef Roasbeef added this to the 0.5 milestone Jul 17, 2018
Copy link
Contributor

@halseth halseth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK, pending the btcwallet dependency 👍

config.go Outdated
RPCUser string `long:"rpcuser" description:"Username for RPC connections"`
RPCPass string `long:"rpcpass" default-mask:"-" description:"Password for RPC connections"`
ZMQBlockHost string `long:"zmqblockhost" description:"The ZMQ host providing raw block notifications"`
ZMQTxHost string `long:"zmqtxhost" description:"The ZMQ host providing raw transaction notifications"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to call these zmqpubrawtx and zmqpubrawblock?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

"github.com/btcsuite/btcwallet/walletdb"
_ "github.com/btcsuite/btcwallet/walletdb/bdb" // Required to register the boltdb walletdb implementation.

"github.com/lightninglabs/neutrino"
"github.com/ltcsuite/ltcd/btcjson"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

guess this should be btcd, really

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@wpaulino
Copy link
Contributor Author

Note that this won't build until we're caught up with btcsuite master.

@Roasbeef
Copy link
Member

Roasbeef commented Aug 1, 2018

The dependent btcwallet PR has been merged now, so this needs a rebase! You may want to wait until after #1579 is in however.

if err != nil {
t.Fatalf("couldn't start alice client: %v", err)
}
time.Sleep(time.Second)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why's this sleep necessary now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To ensure bitcoind has started before we attempt to connect to it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has that changed with the new dependency, or is it something that could fail also earlier?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something that could have happened earlier. It's also done within the ChainNotifier and FilteredChainView tests.

@Roasbeef Roasbeef added ready to merge LGTM'd, may need rebase to address conflicts, anyone can merge and removed needs review PR needs review by regular contributors labels Aug 1, 2018
@Roasbeef
Copy link
Member

Roasbeef commented Aug 9, 2018

Needs rebase.

Due to recent changes to the BitcoindClient interface, we now require
the backing bitcoind to use different hosts for its ZMQ raw block and
raw transaction notifications. This was needed as the notification queue
maintained by the bitcoind node would sometimes overflow with
transactions and cause block notifications to be dropped/missed.
In this commit, we expand extractBitcoindRPCParams to account for this.
In this commit, we introduce a nice optimization with regards to lnd's
interaction with a bitcoind backend. Within lnd, we currently have three
different subsystems responsible for watching the chain: chainntnfs,
lnwallet, and routing/chainview. Each of these subsystems has an active
RPC and ZMQ connection to the underlying bitcoind node. This would incur
a toll on the underlying bitcoind node and would cause us to miss ZMQ
events, which are crucial to lnd. We remedy this issue by sharing the
same connection to a bitcoind node between the different clients within
lnd.
}

// If only one or two of the parameters are set, we assume the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: ...or three 😛

if err != nil {
t.Fatalf("couldn't start alice client: %v", err)
}
time.Sleep(time.Second)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has that changed with the new dependency, or is it something that could fail also earlier?

Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 💧

@Roasbeef Roasbeef merged commit 30b156c into lightningnetwork:master Aug 10, 2018
@wpaulino wpaulino deleted the bitcoind-rescan-client branch August 10, 2018 00:20
@githorray
Copy link
Contributor

Typo in the docs?

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

Results in:

unable to load RPC credentials for bitcoind: please set all or none of bitcoind.rpcuser, bitcoind.rpcpass, bitcoind.zmqpubrawblock, bitcoind.zmqpubrawtx

@wpaulino
Copy link
Contributor Author

Whoops, yeah the second should be --bitcoind.zmqpubrawtx=tcp://127.0.0.1:28333 .

@githorray
Copy link
Contributor

Also, [INF] LNWL: Started listening for blocks via ZMQ on never appears in the log after the update and LND keeps losing chain sync. I am still trying to track that one down.

@bretton
Copy link
Contributor

bretton commented Aug 10, 2018

So now bitcoin.conf must set different ports for zmq as follows

zmqpubrawblock=tcp://127.0.0.1:28332
zmqpubrawtx=tcp://127.0.0.1:28333

lnd.conf used to have

bitcoind.zmqpath=tcp://127.0.0.1:28332

however now it must have

bitcoind.zmqpubrawblock=tcp://127.0.0.1:28332
bitcoind.zmqpubrawtx=tcp://127.0.0.1:28333

???

but the sample lnd.conf file is incorrect?

https://github.com/lightningnetwork/lnd/blob/master/sample-lnd.conf

; bitcoind.zmqblockhost=tcp://127.0.0.1:28332
; bitcoind.zmqtxhost=tcp://127.0.0.1:28333

can submit PR if needed?

@wpaulino
Copy link
Contributor Author

See #1717.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Related to the node backend software/interface (e.g. btcd, bitcoin-core) bitcoind Bitcoin Core backend config Parameters/arguments/config file related issues/PRs needs testing PR hasn't yet been actively tested on testnet/mainnet notifications P2 should be fixed if one has time ready to merge LGTM'd, may need rebase to address conflicts, anyone can merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants