Commit Graph
100 Commits
Author SHA1 Message Date
Wilmer Paulino 8d7879bab1 Merge pull request #2496 from halseth/itest-print-btc-amount
[trivial] lntest/node: print amounts in same format
2019-02-01 13:01:05 -08:00
Wilmer Paulino 016add6adc lnd_test: extend chain claim test with invoice settled check
In this commit, we extend the remote/receiver chain claim integration
test to assert that the on-disk representation of the invoice on the
receiving side (Carol) is marked as settled due to the claiming the HTLC
on-chain.
2019-01-22 20:46:14 -08:00
Wilmer Paulino 41f638c7cf contractcourt+server: settle invoice for on-chain HTLC sweep
In this commit, we extend the htlcSuccessResolver to settle the invoice,
if any, of the corresponding on-chain HTLC sweep. This ensures that the
invoice state is consistent as when claiming the HTLC "off-chain".
2019-01-22 20:46:14 -08:00
Wilmer PaulinoandJoost Jager 974e0f2df5 cnct: make original htlc amt available for contract resolvers
Previously, contract resolvers that needed to publish a second level tx,
did not have access to the original htlc amount.

This commit reconstructs this amount from data that is already persisted
in arbitrator log.

Co-authored-by: Joost Jager <joost.jager@gmail.com>
2019-01-22 20:47:17 -08:00
Wilmer PaulinoandJoost Jager 93754f8d37 lnwallet: add HtlcPoint() resolution helper methods
Co-authored-by: Joost Jager <joost.jager@gmail.com>
2019-01-22 20:47:13 -08:00
Wilmer PaulinoandJoost Jager 865f7568d6 cnct: extract relaunching of resolvers to method
Co-authored-by: Joost Jager <joost.jager@gmail.com>
2019-01-22 20:46:14 -08:00
Wilmer Paulino ba2d9ff81a build: update btcwallet with initial sync improvements
In this commit, we update our btcwallet dependency to point to the
latest version. This latest version redefines what the wallet will
consider as an initial sync. We'll now define it by determining if the
wallet has synced up to its birthday block, rather than looking at the
number of UTXOs in the wallet. This was needed, especially for light
clients, because it would cause unnecessary rescans to happen from the
wallet's birthday if the wallet had no UTXOs.
2019-01-22 19:53:33 -08:00
Wilmer Paulino e684efa5a7 lnrpc: update ListInvoices documentation
Currently, the documentation includes details for `lncli`. This commit
modifies it to reflect the behavior of the RPC interface instead, as it
should.
2019-01-22 18:23:39 -08:00
Wilmer Paulino 9860df69fe Merge pull request #2247 from wpaulino/grpc-proxy-endpoint
rpcserver: forward gRPC proxy requests to localhost when listening on all interfaces
2019-01-22 16:21:21 -08:00
Wilmer Paulino 552b71c620 rpcserver: forward gRPC proxy requests to localhost when listening on all interfaces
This prevents certificate issues when accessing the gRPC REST proxy externally.
2019-01-21 16:07:19 -08:00
Wilmer Paulino 59e2be5306 config: add ChainRPC config 2019-01-21 14:02:00 -08:00
Wilmer Paulino 3d91aa2312 lnrpc/chainrpc: add ChainNotifier subserver registration driver 2019-01-21 14:01:22 -08:00
Wilmer Paulino 1f8eef2833 lnrpc/chainrpc: add ChainNotifier subserver implementation 2019-01-21 14:01:22 -08:00
Wilmer Paulino 5e98af8c99 lnrpc/chainrpc: add ChainNotifier subserver Config 2019-01-21 14:01:22 -08:00
Wilmer Paulino d06f6c14f5 lnrpc/chainrpc: add ChainNotifier subserver protos 2019-01-21 14:01:20 -08:00
Wilmer Paulino 26d53c64f1 chainntnfs: dispatch block notification for current tip upon registration 2019-01-21 13:58:52 -08:00
Wilmer Paulino 568f8271a0 chainntnfs/neutrinonotify: track best block hash 2019-01-21 13:58:52 -08:00
Wilmer Paulino 060f2f7774 chainntnfs: add Done chan to events to signal reorg safety 2019-01-21 13:58:52 -08:00
Wilmer Paulino 52a80f2d37 chainntnfs/txnotifier: track reorg risk for transactions within ConnectTip 2019-01-21 13:58:52 -08:00
Wilmer Paulino 0c579b110c chainntnfs: add support to cancel pending registered confirmation 2019-01-21 13:58:52 -08:00
Wilmer Paulino be2c321c8c chainntnfs: declare common ErrChainNotifierShuttingDown for all backends 2019-01-21 13:58:52 -08:00
Wilmer Paulino 50650d054e chainntnfs: include transaction in confirmation details 2019-01-21 13:58:52 -08:00
Wilmer Paulino 5ab30cf7ea chainntnfs/interface_test: add script dispatch test cases 2019-01-21 13:57:43 -08:00
Wilmer Paulino 83c7f204cd chainntnfs: modify GetTestTxidAndScript to generate new P2PKH scripts
In this commit, we modify GetTestTxidAndScript to generate new P2PKH
scripts. This is needed to properly test confirmations and spends of
unique scripts on-chain within the set of interface-level test cases.
2019-01-21 13:57:43 -08:00
Wilmer Paulino 52db5ed682 chainntnfs/neutrinonotify: support registration for script spends
In this commit, we extend the NeutrinoNotifier to support registering
scripts for spends notifications. Once the script has been detected as
spent within the chain, a spend notification will be dispatched through
the Spend channel of the SpendEvent returned upon registration.

For scripts that have been spent in the past, the rescan logic has been
modified to match on the script rather than the outpoint. A concurrent
queue for relevant transactions has been added to proxy notifications
from the underlying rescan to the txNotifier. This is needed for
scripts, as we cannot perform a historical rescan for scripts through
`GetUtxo`, like we do with outpoints.

For scripts that are unspent, a filter update is sent to the underlying
rescan to ensure that we match and dispatch on the script when
processing new blocks.

Along the way, we also address an issue where we'd miss detecting that
an outpoint/script has been spent in the future due to not receiving a
historical dispatch request from the underlying txNotifier. To fix this,
we ensure that we always request the backend to notify us of the spend
once it detects it at tip, regardless of whether a historical rescan was
detected or not.
2019-01-21 13:57:43 -08:00
Wilmer Paulino 482f05a3bc chainntnfs/bitcoindnotify: support registration for script spends
In this commit, we extend the BitcoindNotifier to support registering
scripts for spends notifications. Once the script has been detected as
spent within the chain, a spend notification will be dispatched through
the Spend channel of the SpendEvent returned upon registration.

For scripts that have been spent in the past, the rescan logic has been
modified to match on the script rather than the outpoint. This is done
by re-deriving the script of the output a transaction input is spending
and checking whether it matches ours.

For scripts that are unspent, a request to the backend will be sent to
alert the BitcoindNotifier of when the script was spent by a
transaction. To make this request we encode the script as an address, as
this is what the backend uses to detect the spend. The transaction will
then be proxied through the txUpdates concurrent queue, which will hand
it off to the underlying txNotifier and dispatch spend notifications to
the relevant clients.

Along the way, we also address an issue where we'd miss detecting that
an outpoint/script has been spent in the future due to not receiving a
historical dispatch request from the underlying txNotifier. To fix this,
we ensure that we always request the backend to notify us of the spend
once it detects it at tip, regardless of whether a historical rescan was
detected or not.
2019-01-21 13:57:43 -08:00
Wilmer Paulino 808c6ae660 chainntnfs/btcdnotify: support registration for script spends
In this commit, we extend the BtcdNotifier to support registering
scripts for spends notifications. Once the script has been detected as
spent within the chain, a spend notification will be dispatched through
the Spend channel of the SpendEvent returned upon registration.

For scripts that have been spent in the past, the rescan logic has been
modified to match on the script rather than the outpoint. This is done
by encoding the script as an address.

For scripts that are unspent, a request to the backend will be sent to
alert the BtcdNotifier of when the script was spent by a transaction. To
make this request we encode the script as an address, as this is what
the backend uses to detect the spend. The transaction will then be
proxied through the txUpdates concurrent queue, which will hand it off
to the underlying txNotifier and dispatch spend notifications to the
relevant clients.

Along the way, we also address an issue where we'd miss detecting that
an outpoint/script has been spent in the future due to not receiving a
historical dispatch request from the underlying txNotifier. To fix this,
we ensure that we always request the backend to notify us of the spend
once it detects it at tip, regardless of whether a historical rescan was
detected or not.
2019-01-21 13:57:43 -08:00
Wilmer Paulino f02590d8c0 chainntnfs/neutrinonotify: support registration for script confirmations
In this commit, we extend the NeutrinoNotifier to support registering
scripts for confirmation notifications. Once the script has been
detected as confirmed within the chain, a confirmation notification will
be dispatched to through the Confirmed channel of the ConfirmationEvent
returned upon registration.

For scripts that have confirmed in the past, the `historicalConfDetails`
method has been modified to determine whether the script has been
confirmed by locating the script in an output of a confirmed
transaction.

For scripts that have yet to confirm, a filter update is sent to the
underlying rescan to ensure that we match and dispatch on the script
when processing new blocks.

Along the way, we also address an issue where we'd miss detecting that a
transaction/script has confirmed in the future due to not receiving a
historical dispatch request from the underlying txNotifier. To fix this,
we ensure that we always update our filters to detect the confirmation
at tip, regardless of whether a historical rescan was detected or not.
2019-01-21 13:57:43 -08:00
Wilmer Paulino 1a41e23bf4 chainntnfs/bitcoindnotify: support registration for script confirmations
In this commit, we extend the BitcoindNotifier to support registering
scripts for confirmation notifications. Once the script has been
detected as confirmed within the chain, a confirmation notification will
be dispatched to through the Confirmed channel of the ConfirmationEvent
returned upon registration.

For scripts that have confirmed in the past, the `historicalConfDetails`
method has been modified to skip the txindex and go straight to scanning
the chain manually if confirmation request is for a script. When
scanning the chain, we'll determine whether the script has been
confirmed by locating the script in an output of a confirmed
transaction.

For scripts that have yet to confirm, they will be properly tracked
within the TxNotifier.
2019-01-21 13:57:43 -08:00
Wilmer Paulino 1323c92947 chainntnfs/btcdnotify: support registration for script confirmations
In this commit, we extend the BtcdNotifier to support registering
scripts for confirmation notifications. Once the script has been
detected as confirmed within the chain, a confirmation notification will
be dispatched to through the Confirmed channel of the ConfirmationEvent
returned upon registration.

For scripts that have confirmed in the past, the `historicalConfDetails`
method has been modified to skip the txindex and go straight to scanning
the chain manually if confirmation request is for a script. When
scanning the chain, we'll determine whether the script has been
confirmed by locating the script in an output of a confirmed
transaction.

For scripts that have yet to confirm, they will be properly tracked
within the TxNotifier.
2019-01-21 13:57:43 -08:00
Wilmer Paulino 72cc843e92 chainntnfs/interface: update docs to note support for scripts 2019-01-21 13:57:43 -08:00
Wilmer Paulino c72da48111 multi: update to latest ChainNotifier impl New method 2019-01-21 13:57:43 -08:00
Wilmer Paulino 969acf6145 chainntnfs/neutrinonotify: clean up neutrinonotify.New 2019-01-21 13:57:43 -08:00
Wilmer Paulino 686e734e22 chainntnfs/bitcoindnotify: add chainParams parameter to bitcoindnotify.New
In this commit, we add the current chain parameters to the
BitcoindNotifier. This will be used in a future commit in order to
convert outputs scripts into addresses. This is needed since the
bitcoind backend uses these addresses to detect whether the script
encoded within it was spent by a transaction in the chain.
2019-01-21 13:57:43 -08:00
Wilmer Paulino 1ee8d7518c chainntnfs/btcdnotify: add chainParams parameter to btcdnotify.New
In this commit, we add the current chain parameters to the BtcdNotifier.
This will be used in a future commit in order to convert outputs scripts
into addresses. This is needed since the btcd backend uses these
addresses to detect whether the script encoded within it was spent by a
transaction in the chain.
2019-01-21 13:57:43 -08:00
Wilmer Paulino 7f644019b8 chainntnfs/txnotifier_test: update tests with new registration changes 2019-01-21 13:57:43 -08:00
Wilmer Paulino c3d5204f09 chainntnfs/txnotifier: refactor ProcessRelevantSpendTx to detect script spends
In this commit, we refactor the TxNotifier's ProcessRelevantSpendTx to
also detect script spends. This can easily be done as the transaction
filtering logic was refactored into its own method in a previous commit.
2019-01-21 13:57:43 -08:00
Wilmer Paulino 8042d4f1c8 chainntnfs/txnotifier: batch update confirm and spends hints for scripts 2019-01-21 13:57:43 -08:00
Wilmer Paulino f4f5c1ef8b chainntnfs/txnotifier: support reorg detection for scripts 2019-01-21 13:57:43 -08:00
Wilmer Paulino 83c8ccb3eb chainntnfs/txnotifier: notify confirmations and spends of scripts at tip 2019-01-21 13:57:43 -08:00
Wilmer Paulino ecd70deb8c chainntnfs/txnotifer: detect confirmations and spends of scripts at tip
In this commit, we modify the TxNotifier's ConnectTip method to also
detect whether a registered script has been confirmed or spent on-chain
by a transaction in the connected block. Once detected, notifications
for them will be queued up for dispatch as with txids/outpoints.

We've also refactored the ConnectTip method into smaller and reusable
methods, which will serve useful later.
2019-01-21 13:57:43 -08:00
Wilmer Paulino b579c23310 chainntnfs/txnotifier: support registration of scripts for spends 2019-01-21 13:57:43 -08:00
Wilmer Paulino 0f4ff2d09c chainntnfs/txnotifier: support registration of scripts for confirmations 2019-01-21 13:57:43 -08:00
Wilmer Paulino a0d3b7d9e3 chainntnfs: support caching confirm/spend hints for scripts
In this commit, we refactor the HeightHintCache and its underlying
interfaces to be able to manipulate hints for ConfRequests and
SpendRequests. By doing so, we'll be able to manipulate hints for
scripts if the request includes either a zero hash or a zero outpoint.
2019-01-21 13:57:43 -08:00
Wilmer Paulino de0adc4d52 chainntnfs/txnotifier: add ConfRequest and SpendRequest structs
These structs allow us to request notifications for either
txids/outpoints or output scripts. We'll be using these in later commits
to index confirmation and spend requests within the TxNotifier.
2019-01-21 13:57:43 -08:00
Wilmer Paulino cdf2a65db6 build: update deps to support detecting script spends within rescans 2019-01-21 13:57:43 -08:00
Wilmer Paulino 3420d6d917 lnrpc/signrpc/signer_server: fix incorrect lnwallet.InputScript field 2019-01-15 19:27:28 -08:00
Wilmer Paulino cbce6e03fc server: implement notifications for disconnected peers 2019-01-14 22:44:45 -08:00
Wilmer Paulino 4f953afeee lnwallet+fundingmanager: enforce max MinAcceptDepth within funding proposals 2019-01-11 17:05:35 -08:00
Wilmer Paulino 71410f6a08 lnwallet+fundingmanager: use ChannelConstraints struct with CommitConstraints 2019-01-11 17:01:27 -08:00
Wilmer Paulino b951f06456 multi: move CsvDelay into ChannelConstraints 2019-01-11 16:58:15 -08:00
Wilmer Paulino 5be8f08b16 chainntnfs/txnotiifer: define MaxNumConfs supported as ReorgSafetyLimit 2019-01-11 16:58:15 -08:00
Wilmer Paulino fd2bfaa007 chainntnfs: add TestTxNotifierMaxConfs 2019-01-11 16:58:15 -08:00
Wilmer Paulino 7239e04696 chainntnfs: initialize TxNotifier with new ReorgSafetyLimit 2019-01-11 16:58:15 -08:00
Wilmer Paulino 9d51114546 chainntnfs/txnotifier: define ReorgSafetyLimit as 144 blocks 2019-01-11 16:58:15 -08:00
Wilmer Paulino 55b580f2b8 Merge pull request #2462 from Roasbeef/fix-length-update
lnwire: ensure we precisely encode the length for onion errors w/ cha…
2019-01-11 16:12:04 -08:00
Wilmer Paulino 70d3fc640a channeldb/db: prevent filtering channels with unconfirmed close txs
In this commit, we address an issue with the FetchWaitingCloseChannels
method where it would not properly return channels that are unconfirmed
and also have an unconfirmed closing transaction because they were
filtered out. We fix this by fetching channels that remain unconfirmed
that are also waiting for a confirmed closing transaction.

This will allow the recently added test TestFetchWaitingCloseChannels to
pass.
2019-01-03 20:48:28 -05:00
Wilmer Paulino 409efd1361 channeldb/channel_test: add TestFetchWaitingCloseChannels
In this commit, we add a test case for FetchWaitingCloseChannels to
ensure it behaves as intended. Currently, this test fails due to not
fetching channels which are pending to be closed but are also pending to
be opened. This will be fixed in the following commit and should allow
the test to pass.
2019-01-03 20:48:28 -05:00
Wilmer Paulino f6c02aec20 channeldb/channel_test: use random outpoint when creating new test channels
In this commit, we use random outpoints when creating new test channels
to ensure we can uniquely identify them.
2019-01-03 20:33:33 -05:00
Wilmer Paulino e71151f56a htlcswitch/link: return FinalFailExpiryTooSoon for last htlc
In this commit, we fix a minor discrepancy with the spec. We should
return a FinalFailExpiryTooSoon error, rather than a
FinalFailIncorrectCltvExpiry error, when the last HTLC of a route (exit
hop) has an expiration height that is deemed too soon by the final
destination of the HTLC.
2018-12-17 15:26:11 -05:00
Wilmer Paulino 60036aca1d contractcourt/channel_arbitrator: prevent force closing same channel twice
In this commit, we prevent the ChainArbitrator from sending a force
close request for a channel if it has previously already sent one. We do
this to prevent blocking the caller of ForceCloseContract.
2018-12-10 20:37:58 -08:00
Wilmer Paulino 62071d9082 build: update btcwallet dep to fix birthday block sanity check infinite loop
In this commit, we update our btcwallet dependency that includes a fix
to address an issue that would cause users to be stuck in an infinite
loop by fetching the same candidate birthday block due to its height not
being updated if the sanity check was attempting to fix an estimate in
the future.
2018-11-20 15:42:06 -08:00
Wilmer Paulino 9ca9802d9c lnwallet/btcwallet: check wallet rescan is complete within IsSynced
In this commit, we add an additional check to btcwallet's IsSynced
method to ensure that it is not currently undergoing a rescan. We do
this to block upon starting the server and all other dependent
subsystems until the rescan is complete.
2018-11-14 20:17:36 -08:00
Wilmer Paulino b1860a95e0 lnwallet/btcwallet: add lightning addr scope before wallet start
In this commit, we add the lightning address scope before the wallet
starts to prevent a race condition between the wallet syncing and adding
the scope itself. This became more apparent with the recent btcwallet
fixes, as several database transactions now occur between the wallet
being started and it syncing.
2018-11-14 20:17:36 -08:00
Wilmer Paulino f9b15e97f3 build: update btcwallet dependency to address SendOutputs bug
In this commit, we update our btcwallet dependency to include the latest
changes that aim to address the recently discovered SendOutputs bug.

This commit will also allow the lnwallet test case added in the
previous commit to succeed.
2018-11-14 20:17:36 -08:00
Wilmer Paulino 5b42a38c0f lnwallet/interface_test: add test to detect confirmation of change output spend tx
In this commit, we add a new test to the existing set of wallet tests to
ensure we can properly detect the confirmation of transactions that
spend our change outputs. We do this as a measure to prevent future
regressions from happening where the wallet doesn't request its backend
to be notified of when an on-chain transaction pays to a change address,
like with the recently discovered SendOutputs bug.

As is, this test will not pass until we update the btcwallet dependency
in the next commit.
2018-11-14 20:17:36 -08:00
Wilmer Paulino 255f38e72d lnwallet/btcwallet: check output is under our control in FetchInputInfo
In this commit, we add an additional check to btcwallet's FetchInputInfo
method to ensure the output is actually under control of the wallet.
Previously, the wallet would assume the output was under its control if
the txid of the output was found within the wallet. This is not a safe
assumption to make however, because if we happened to be the sender of
this transaction, it would be found within the wallet but it's not
actually under our control. To fix this, we explicitly check that there
exists an address in our wallet for this output.
2018-11-14 20:17:36 -08:00
Wilmer Paulino 55094f1470 discovery/gossiper: send node anns when constructing full chan proof
In this commit, we allow the gossiper to also broadcast the
corresponding node announcements, if we know of them, of a channel when
constructing its full proof. We do this to ensure peers (other than our
remote peer) receive all the relevant announcements for a channel.

The tests changes were made to ensure the new behavior introduced works
as intended. Previously, the node announcements for each test channel
announcement were not processed, so they never existed from the
gossiper's point of view.

This also addresses an existing flake in the integration test
`testNodeAnnouncement`. This problem arose due to the node announcement
being sent before the connection between Dave (node announcement sender)
and Alice (node announcement receiver) was initiated and the full
channel proof was constructed.
2018-11-11 17:48:07 -08:00
Wilmer Paulino c9e79527af discovery/gossiper: add trace log when skipping unadvertised node ann 2018-11-11 17:48:06 -08:00
Wilmer Paulino 4f45e339f1 discovery+routing: add FetchLightningNode to ChannelGraphSource interface 2018-11-11 17:48:05 -08:00
Wilmer Paulino 3a314ba4a7 lnrpc: modify AbandonChannel REST endpoint
In this commit, we modify the AbandonChannel REST endpoint to avoid
conflicting with the CloseChannel's. Otherwise, if a debug build of lnd
is being used, there's no way of closing channels through the REST API
as it's been overwritten by AbandonChannel.
2018-11-08 16:16:31 -08:00
Wilmer Paulino e402a4e146 chainntnfs: dispatch conf/spend notifications after blocks
In this commit, we alter the different ChainNotifier implementations to
dispatch confirmation and spend notifications after blocks. We do this
to ensure the external consistency of our registered clients.
2018-10-31 09:20:22 -07:00
Wilmer Paulino 770e005943 chainntnfs/txnotifer: prevent dispatching notifications within ConnectTip
In this commit, we modify the TxNotifier's ConnectTip method to no
longer dispatch notifications to any clients who had a request fulfilled
within the height connected. Instead, it will queue the notifications
for dispatch and we add a new method NotifyHeight, which will actually
dispatch them. We do this to allow the users of the TxNotifier to be
more flexible when dispatching notifications.
2018-10-31 09:20:22 -07:00
Wilmer Paulino 9a025867d0 Revert "chainntnfs/btcdnotify: disable height hint cache in testing"
This reverts commit 98e7c968d4.
2018-10-31 09:20:22 -07:00
Wilmer Paulino 5127f2aa82 Revert "chainntnfs/bitcoindnotify: disable height hints in testing"
This reverts commit ab28db5b0d.
2018-10-31 09:20:22 -07:00
Wilmer Paulino 7d94c65afc Revert "chainregistry: disable height hint cache"
This reverts commit 0e29a457e1.
2018-10-31 09:20:22 -07:00
Wilmer Paulino c740b8b85f Revert "lnwallet/interface_test: run tests with disabled hint cache"
This reverts commit 70ba3119b7.
2018-10-31 09:20:22 -07:00
Wilmer Paulino 35bfb79099 Revert "chainntnfs/interface_test: run tests w/ disabled cache"
This reverts commit 12761a4f43.
2018-10-31 09:20:22 -07:00
Wilmer Paulino 88ac985c95 Revert "chainntnfs/height_hint_cache_test: add tests for disabled cache"
This reverts commit 45a2c9aca8.
2018-10-31 09:20:22 -07:00
Wilmer Paulino 716c20b18d Revert "chainntnfs/height_hint_cache: add disable flag to hint cache"
This reverts commit 7df9ae0266.
2018-10-31 09:20:22 -07:00
Wilmer Paulino e6b1a27cd7 chainntnfs/neutrinonotify: make filter update synchronous
In this commit, we modify the notifier to handle filter updates
synchronously. We do this to prevent race conditions between new block
notifications and filter updates. Otherwise, it's possible for a new
block to come in that should match our filter, but doesn't due to the
filter being updated after.

We also modify their order so that the filter is updated first. We do
this so we can immediately start watching for the event at tip while the
rescan is ongoing.
2018-10-30 17:59:31 -07:00
Wilmer Paulino 60a1d73e08 chainntnfs/txnotifier: commit height hint after rescan is complete
In this commit, we'll now commit the current height of the TxNotifier as
the height hint for an outpoint/transaction after a rescan has been
completed and has determined that the outpoint is unspent/transaction is
unconfirmed. We do this to prevent another potentially long rescan if
the daemon is restarted before a new block comes in (which is when the
hints will be updated again).
2018-10-30 17:59:31 -07:00
Wilmer Paulino 6458868ba0 chainntnfs/interface_test: add spend reorg test 2018-10-30 17:59:31 -07:00
Wilmer Paulino deca4cfe44 chainntnfs/neutrinonotify: remove old spend notification handling logic
In this commit, we remove the old spend notification logic within the
NeutrinoNotifier as it's been phased out by the TxNotifier.
2018-10-30 17:59:31 -07:00
Wilmer Paulino bfd11a251e chainntnfs/neutrinonotify: handle spend notification registration w/ TxNotifier
In this commit, we modify the logic within RegisterSpendNtfn for the
NeutrinoNotifier to account for the recent changes made to the
TxNotifier. Since it is now able to handle spend notification
registration and dispatch, we can bypass all the current logic within
the NeutrinoNotifier and interact directly with the TxNotifier instead.

The most notable change is that now we'll only attempt a historical
rescan if the TxNotifier tells us so.
2018-10-30 17:59:31 -07:00
Wilmer Paulino 74139c9a3f chainntnfs/btcdnotify: remove old spend notification handling logic
In this commit, we remove the old spend notification logic within the
BtcdNotifier as it's been phased out by the TxNotifier.
2018-10-30 17:59:31 -07:00
Wilmer Paulino 88edd320d5 chainntnfs/btcdnotify: handle spend notification registration w/ TxNotifier
In this commit, we modify the logic within RegisterSpendNtfn for the
BtcdNotifier to account for the recent changes made to the TxNotifier.
Since it is now able to handle spend notification registration and
dispatch, we can bypass all the current logic within the
BtcdNotifier and interact directly with the TxNotifier instead.

The most notable change is that now we'll only attempt a historical
rescan if the TxNotifier tells us so.
2018-10-30 17:59:31 -07:00
Wilmer Paulino 0927f35dc1 chainntnfs/bitcoindnotify: remove old spend notification handling logic
In this commit, we remove the old spend notification logic within the
BitcoindNotifier as it's been phased out by the TxNotifier.
2018-10-30 17:59:31 -07:00
Wilmer Paulino 180dffd154 chainntnfs/bitcoindnotify: handle spend notification registration w/ TxNotifier
In this commit, we modify the logic within RegisterSpendNtfn for the
BitcoindNotifier to account for the recent changes made to the
TxNotifier. Since it is now able to handle spend notification
registration and dispatch, we can bypass all the current logic within
the BitcoindNotifier and interact directly with the TxNotifier instead.

The most notable changes include the following:

  1. We'll only attempt a historical rescan if the TxNotifier tells us
  so.

  2. We'll dispatch the historical rescan within the main goroutine to
  prevent WaitGroup panics, due to the asynchronous nature of the
  notifier.
2018-10-30 17:59:31 -07:00
Wilmer Paulino 1fe3d59836 chainntnfs/txnotifier_test: extend tests to handle spend notifications 2018-10-30 17:59:31 -07:00
Wilmer Paulino 2935392f51 chainntnfs/txnotifier: correctly update confirm/spend hints on chain updates
In this commit, we address an issue w.r.t. updating the confirm hints
for transactions and spend hints for outpoints on chain updates.
Previously, upon a block being disconnected, we'd attempt to commit a
new height hint for all outstanding confirmation notifications. This is
not correct because we'll end up modifying the height hint for things
that have confirmed at a previous height than the one being
disconnected. This would cause issues on restart when attempting a
historical dispatch, as we would start scanning at a height above which
the transaction actually confirmed in.

This has been addressed by only updating the hints for outstanding
notifications that are still unconfirmed/unspent and for notifications
that were confirmed/spent within the block being connected/disconnected.
2018-10-30 17:59:31 -07:00
Wilmer Paulino f27e73fcb8 chainntnfs/txnotifier: detect reorgs for spending transactions of registered outpoints
In this commit, we introduce support to the TxNotifier to detect
spending transactions of registered outpoints being reorged out of the
chain. In the event that a reorg does occur, we'll consume the Spend
notification if it hasn't been consumed yet, and dispatch a Reorg
notification instead.
2018-10-30 17:59:31 -07:00
Wilmer Paulino e6b2755a57 chainntnfs/txnotifier: watch for spends at tip
In this commit, we add support to allow the TxNotifier to properly
determine whether a new block extending the chain contains a transaction
that spends a registered outpoint. In the event that it does, spend
notifications will be dispatched to all active registered clients for
such outpoint.
2018-10-30 17:59:31 -07:00
Wilmer Paulino 4d7fa9ecc4 chainntnfs/txnotifier: allow registration of spend notifications
In this commit, we introduce the registration logic for spend
notifications to the TxNotifier. Most of this logic was taken from the
different existing ChainNotifier implementations, however, it features
some useful additions in order to make the ChainNotifier a bit more robust.

Some of these additions include the following:

  1. RegisterSpend will now return a HistoricalSpendDispatch struct,
  which includes the details for successfully determining if an outpoint
  was spent in the past. A HistoricalSpendDispatch will only be returned
  upon the first registration of an outpoint. This is done as,
  previously, if multiple clients registered for the same outpoint, then
  multiple historical rescans would also be dispatched, incurring a toll
  on the backend itself.

  2. UpdateSpendDetails will now be used to determine when a historical
  rescan has completed, no matter if a spending transaction was found or
  not. This is needed in order to responsibly update the spend hints for
  outpoints at tip, otherwise we'd attempt to update them even though we
  haven't yet determined if they have been spent or not. This will
  dispatch notifications to all currently registered clients for the
  same outpoint. In the event that another client registers later on,
  then the spending details are cached in memory in order to prevent
  further historical rescans.
2018-10-30 17:59:31 -07:00
Wilmer Paulino fc7a33b64f chainntnfs/txnotifier: add fields/structs to track spend notifications
In this commit, we introduce the required fields for the TxNotifier to
properly carry its duties in notifying its registered clients about the
spend of an outpoint. These are not yet used, but will be throughout the
some of the following commits.
2018-10-30 17:59:31 -07:00
Wilmer Paulino 87123d5e23 chainntnfs: extend SpendEvent with reorg channel
In this commit, we add a new channel within the SpendEvent struct that
will be sent upon whenever the spending transaction of the registered
outpoint gets reorged out of the chain. This will pave the road for
successfully handling a funding transaction getting reorged out of the
chain among other things.
2018-10-30 17:59:31 -07:00
Wilmer Paulino f4128c9afb chainntnfs/txnotifier: move rescanState & confNtfnSet decl to top 2018-10-30 17:59:31 -07:00
Wilmer Paulino 405e8f0fad chainntnfs/txnotifier: rename hintCache -> confirmHintCache 2018-10-30 17:59:31 -07:00
Wilmer Paulino f65401b439 chainntnfs/txnotifier: rename Register -> RegisterConf 2018-10-30 17:59:31 -07:00
Wilmer Paulino 82f6fd7a91 chainntnfs: rename TxConfNotifier -> TxNotifier 2018-10-30 17:59:31 -07:00