Commit graph

124 commits

Author SHA1 Message Date
Oliver Gugger 3a5d9f84b0
multi: fix linter issues 2021-03-24 14:44:32 +01:00
Wilmer Paulino 90a0744ae4
chain: batch filter fetches for neutrino chain client
This greatly speeds up wallet recovery with a neutrino backend, as we'll
avoid unnecessary round trips for each block filter fetch.
2020-03-31 13:37:56 -07:00
Wilmer Paulino d7d2f14d61
build+chain: reuse buffers when reading ZMQ messages from bitcoind
`bitcoind` notifies transactions once they're accepted into the mempool
and once they're confirmed in a block. Previously, reading a message
from ZMQ would allocate a buffer with the size of the message. This can
cause nodes to perform a large number of allocations within a small
amount periodically (3000 300B allocations every 10 mins on average),
which can cause a lot of GC pressure on lower resourced nodes. To remedy
this, we introduce two static buffers, one for blocks and another for
transactions, that will be reused for every message read. Each is
constrained by its maximum expected size.
2019-11-12 18:18:59 -08:00
Wilmer Paulino 58ac163d48
chain: trace log timed out ZMQ connections 2019-11-08 12:39:00 -08:00
Wilmer Paulino 36ca842905
chain: extract ZMQ command strings into constants 2019-11-08 12:38:28 -08:00
Wilmer Paulino 333ecbf262 chain: notify block when not filtered for BitcoindClient 2019-09-09 17:10:38 +03:00
Olaoluwa Osuntokun cfb9bb1e32
build: pin against latest neutrino version 2019-09-05 18:31:03 -07:00
Wilmer Paulino 5124978a9b
chain: prevent filtering blocks when BitcoindClient has an empty filter 2019-08-09 18:16:40 -07:00
Wilmer Paulino 6c4dab5f7c
chain: remove extraneous rpcclient.Disconnect calls from BitcoindConn
These are not needed since they have no effect when the RPC client is
making HTTP POST requests.
2019-07-10 16:15:51 -07:00
Wilmer Paulino f02166e5de
chain: explicitly close connections in BitcoindConn's Stop method
Since it's now possible for gozmq.Conn to block when calling Receive,
BitcoindConn hangs upon being stopped because its goroutines are waiting
for a message to be delivered. To address this, we modify it to close
its ZMQ connections driving the goroutines once it's been stopped. This
allows the goroutines to unblock by detecting the EOF error and exiting.
2019-07-10 16:15:50 -07:00
Wilmer Paulino 4a913d02ea
chain: only allow bitcoind block notifications at tip after NotifyBlocks
One could argue that the behavior before this commit was incorrect, as
the ChainClient interface expects a call to NotifyBlocks before
notifying blocks at tip, so we decide to fix this.

Since we now wait for the chain backend to be considered "current"
before proceeding to sync the wallet with it, any blocks that were
processed while waiting would result in being notified and scanned
twice, once by processing it at tip, and another while rescanning the
wallet, which is not desirable.
2019-06-13 18:09:06 -07:00
Wilmer Paulino 39f81c630b
chain: add IsCurrent method to chain.Interface
IsCurrent allows us to determine if the chain backend considers itself
"current" with the chain.
2019-06-13 18:08:59 -07:00
Wilmer Paulino eedd5ce1b6
chain: prevent deadlock while notifying RescanFinished for NeutrinoClient 2019-06-07 13:00:09 -07:00
Wilmer Paulino 0efe836773
chain: avoid using defer for BitcoindClient onRescanFinished notification
Since defer will copy the function with the parameters evaluated at its
invocation, the RescanFinished notification would be dispatched with the
incorrect block. To fix this, we'll just send the notification at the
end ourselves manually.
2019-05-11 13:06:25 -07:00
Wilmer Paulino 28161bee42
chain: improve error logging within BitcoindClient.reorg 2019-05-11 13:05:27 -07:00
Wilmer Paulino ecfebcea03
chain: remove unnecessary returned error from BitcoindClient.filterBlock 2019-05-11 13:05:23 -07:00
Wilmer Paulino 8d6dd92706
chain: fix Fatalf format verb error 2019-05-11 13:05:17 -07:00
Wilmer Paulino e0f82255c7
chain: prevent panic if onBlockConnected is called before onFilteredBlockConnected 2019-04-19 12:27:33 -07:00
Wilmer Paulino b3643ed7a9
chain: dispatch RescanFinished notification after BlockConnected
In this commit, we address a bug within the wallet when running with
Neutrino where it wouldn't be able to mark it as synced with the chain
due to not receiving a RescanFinished notification if it was a block
behind the chain. This happened because of the order in which the
notifications are delivered within the underlying Neutrino ChainService,
FilteredBlockConnected gets dispatched before BlockConnected. This
doesn't always work however because there is an implicit dependency
between them in which BlockConnected must occur first.

To address it, rather than switching the order in which the
notifications are dispatched, we just check if we can dispatch the final
RescanFinished notification after dispatching BlockConnected.

Co-Authored-By: Roei Erez <roeierez@gmail.com>
2019-04-18 19:32:37 -07:00
Wilmer Paulino 767a7a95cf
chain: extract RescanFinished notification dispatch into method
Co-Authored-By: Roei Erez <roeierez@gmail.com>
2019-04-18 19:30:40 -07:00
Wilmer Paulino 8f25b8b4ef
chain: keep track of lastFilteredBlockHeader within NeutrinoClient
Co-Authored-By: Roei Erez <roeierez@gmail.com>
2019-04-18 19:23:05 -07:00
Olaoluwa Osuntokun d9a9f4176b
build+chain: update to latest version of neutrino
The latest version also includes a change to the way we need to
initialize the rescan object.
2019-03-12 21:05:42 -07:00
Wilmer Paulino ec210ad79c
chain/bitcoind_client: extend filterTx with script spend support
In this commit, we extend the BitcoindClient to properly detect the
spend of an arbitrary script on-chain. This is possible by looking at a
transaction's input and re-deriving the PkScript, from its signature
script/witness, of the output it's attempting to spend. Upon detecting
the spend, a chain.RelevantTx will be dispatched.
2019-01-14 18:38:45 -08:00
Johan T. Halseth 060361939b
chain/neutrino: use new neutrino API 2018-10-16 18:18:46 -07:00
Wilmer Paulino 1ddb9f2c11
chain: allow setting the client's birthday after creation 2018-09-12 14:24:30 -07:00
Olaoluwa Osuntokun 0059b9fcd9
Merge pull request #537 from cfromknecht/dont-print-rawtx-garbage
chain/bitcoind_conn: only print ASCII rawtx event types
2018-09-03 17:55:49 -07:00
Conner Fromknecht 042d409236
chain/bitcoind_conn: only print ASCII rawtx event types 2018-08-31 16:31:29 -07:00
Wilmer Paulino d179c276b4
chain/rpc: remove unnecessary ping keep alive
In this commit, we remove the keep-alive logic within the handler of the
RPCClient struct as this logic already exists within the backing
rpclient.Client instance. In this case, we'd completely stop the
connection after the ping timeout (1 min), which would render the
reconnection logic within rpcclient.Client useless.
2018-08-27 17:25:16 -07:00
Olaoluwa Osuntokun caab9f91f0
chain: update neutrino client due to recent API changes 2018-08-22 20:20:31 -07:00
Wilmer Paulino 850ad0959a
chain: ensure eventType from ZMQ response is human-readable
In this commit, we fix a small issue where it's possible that we read a
malformed message from the ZMQ connection to bitcoind due to it shutting
down. To fix this, we ensure that the event type is human readable
before attempting to log it.
2018-08-15 18:17:29 -07:00
Wilmer Paulino d6155a55e9
chain: improve error when filtering blocks and transactions 2018-08-15 17:37:04 -07:00
Wilmer Paulino 5f7060dadf
chain: handle ZMQ timeout error correctly 2018-08-15 17:37:03 -07:00
Wilmer Paulino 8357e86a4d chain: match transaction against currently watched transactions
In this commit, we extend the client's filtering process to also look at
the set of currently watched transactions. The logic to watch for
transaction hashes was previously there, but it was not used to filter
against incoming transactions.
2018-07-30 17:54:08 -07:00
Wilmer Paulino 00428d5828 chain: share the same bitcoind connection between multiple rescan clients 2018-07-30 17:54:08 -07:00
Wilmer Paulino 27e22b1f79 chain: return err when updating the rescan filter while shutting down 2018-07-30 14:55:56 -07:00
Wilmer Paulino 0b269d799e
chain: send empty struct instance rather than bool to reset filters 2018-07-26 16:38:58 -07:00
Wilmer Paulino 7df2b72beb
chain: switch BitcoindClient to use atomic started/stopped pattern 2018-07-26 16:38:57 -07:00
Wilmer Paulino 1aeead0eeb
chain: keep track of the best block within BitcoindClient
In the previous commit, we modified our BitcoindClient struct to use a
ConcurrentQueue struct to handle its notifications to the caller. Before
this, the BitcoindClient had a goroutine that would handle these
notifications in the background and detect when a OnBlockConnected
notification was received in order to update the best block. Due to this
logic being removed, we now keep track of the best block througout the
struct as a whole.
2018-07-26 16:38:56 -07:00
Wilmer Paulino 2091ac0936
chain: use ConcurrentQueue within BitcoindClient to handle event notifications 2018-07-26 16:38:55 -07:00
Wilmer Paulino fc73cc9678
chain: add concurrent unbounded queue implementation 2018-07-26 16:38:54 -07:00
Wilmer Paulino 8e9e4d6926
chain: rename bitcoind.go to bitcoind_client.go 2018-07-26 16:38:38 -07:00
Olaoluwa Osuntokun 5b3d124de2 chain: also accept map[wire.OutPoint]btcutil.Address for bitcoind rescans
In this commit, we update bitcoind to also accept a mapping from
outpoint to address for its implementation of the recan RPC. We do this
as in the near future, when bitcoind implements BIP 158 indexing, then
we'll be able to utilize that to do rescans.
2018-07-17 19:05:17 -07:00
Olaoluwa Osuntokun 6a0e6da280 chain: continue to accept []wire.OutPoint for rescan updates for bitcoind
In this commit, we fix a recently introduced bug that would cause
callers that attempted to get a spend notifications for a particular
outpoint to no longer get that precise notification. In a prior commit,
in preparation for the new neutrino gcs filter format, we added a
mapping from script to outpoint that will be used by neutrino, and later
other backends as well. However, we still need to match on outpoint
slices for bitcoind today.
2018-07-17 19:05:17 -07:00
Olaoluwa Osuntokun fdca047246 chain: update block filterer unit tests 2018-07-16 19:47:17 -07:00
Olaoluwa Osuntokun b29e917a24 chain: update Rescan method for bitcoind to adhere to new interface 2018-07-16 19:47:17 -07:00
Olaoluwa Osuntokun bc47007c50 chain: update block filterer to map outpoints to addrs 2018-07-16 19:47:17 -07:00
Olaoluwa Osuntokun 714ac383cb chain: update watched/found outpoints to map to addrs 2018-07-16 19:47:17 -07:00
Olaoluwa Osuntokun 2d600fe6ab chain: create new Rescan wrapper for btcd to comply w/ future BIP 158 usage 2018-07-16 19:47:17 -07:00
Olaoluwa Osuntokun b24714270a chain: update neutrino interface impl to use new InputWithScript 2018-07-16 19:47:17 -07:00
Olaoluwa Osuntokun 87d91316cd chain: update interface to map outpoints to their addresses
In this commit, we update the Rescan call in the interface to map the
outpoint to the address that the outpoint holds. We do this as BIP 158
has recently been updated to match on the prev output script rather than
the outpoint itself. Additionally, in the near future, btcd (then
bitcoind), will switch over to using the BIP 158 filters internally,
which will also match on the output scripts.
2018-07-16 19:47:17 -07:00