Commit graph

1732 commits

Author SHA1 Message Date
Jeffrey Czyz
51a5a1a50f
Move ln/channelmonitor.rs to chain/chainmonitor.rs 2020-10-01 08:50:15 -07:00
Jeffrey Czyz
819a8653af
Move channelmonitor.rs from ln to chain module
Given the chain::Watch interface is defined in terms of ChannelMonitor
and ChannelMonitorUpdateErr, move channelmonitor.rs from the ln module
to the chain module.
2020-09-30 22:41:52 -07:00
Jeffrey Czyz
e09767ba2d
Merge ChainMonitor impl blocks 2020-09-30 22:41:52 -07:00
Jeffrey Czyz
8b1e5afddd
Define type alias for enumerated transaction data
Transaction data from a block may be filtered before it is passed to
block_connected functions, which may need the index of each transaction
within the block. Rather than define each function in terms of a slice
of tuples, define a type alias for the slice where it can be documented.
2020-09-30 22:41:52 -07:00
Jeffrey Czyz
71230c995c
Replace WatchEvent usage with get_outputs_to_watch
Outputs to watch are tracked by ChannelMonitor as of
73dce207dd. Instead of determining new
outputs to watch independently using ChainWatchedUtil, do so by
comparing against outputs already tracked. Thus, ChainWatchedUtil and
WatchEvent are no longer needed.
2020-09-30 22:41:23 -07:00
Jeffrey Czyz
9e14256b71
Include funding TXO in outputs to watch
The funding TXO was never added to ChannelMonitor's outputs_to_watch in
73dce207dd. Include it when constructing a
ChannelMonitor.
2020-09-30 22:41:23 -07:00
Jeffrey Czyz
95b7eee0e9
Fix architecture diagram arrow directions
Arrows should signify "calls" or "generates" unless noted.
2020-09-30 22:41:23 -07:00
Jeffrey Czyz
e83dcda03a
Fix architecture diagram line length 2020-09-30 22:41:23 -07:00
Jeffrey Czyz
98bc46beb9
Replace WatchEventProvider with chain::Filter
WatchEventProvider served as a means for replacing ChainWatchInterface.
However, it requires users to explicitly fetch WatchEvents, even if not
interested in them. Replace WatchEventProvider by chain::Filter, which
is an optional member of ChainMonitor. If set, interesting transactions
and output spends are registered such that blocks containing them can be
retrieved from a chain source in an efficient manner.

This is useful when the chain source is not a full node. For Electrum,
it allows for pre-filtered blocks. For BIP157/158, it serves as a means
to match against compact filters.
2020-09-30 22:40:33 -07:00
Jeffrey Czyz
1599a13643
Remove ChainListener
BlockNotifier was removed in the previous commit, thus ChainListener is
no longer needed. Instead, anything needing chain events should be
notified directly.
2020-09-30 22:40:12 -07:00
Jeffrey Czyz
367834ca90
Remove BlockNotifier
BlockNotifier is a convenience for handing blocks to listeners. However,
it requires that each listener conforms to the ChainListener interface.
Additionally, there are only two listeners, ChannelManager and
ChainMonitor, the latter of which may not be used when monitoring
channels remotely. Remove BlockNotifier since it doesn't provide much
value and constrains each listener to a specific interface.
2020-09-30 22:39:56 -07:00
Jeffrey Czyz
851283d9e5
Remove Key parameter from ChainMonitor
ChainMonitor's template Key parameter was meant to allow supporting
both local monitoring, where Key=OutPoint, and watchtowers, where Key=
(PublicKey, u32). Use OutPoint directly since the watchtower case will
not be supported this way.
2020-09-30 22:39:55 -07:00
Jeffrey Czyz
6662e959c8
Rename SimpleManyChannelMonitor to ChainMonitor
ManyChannelMonitor was renamed chain::Watch in the previous commit. Use
a more concise name for an implementation that monitors the chain for
channel activity. Future work will parameterize the struct to allow for
different varieties of persistence. Thus, users usually will be able to
use ChainMonitor directly rather than implementing a chain::Watch that
wraps it.
2020-09-30 22:39:55 -07:00
Jeffrey Czyz
801b775a7d
Replace ManyChannelMonitor with chain::Watch
Rename ManyChannelMonitor to chain::Watch and move to chain/mod.rs,
where chain-related interfaces live. Update the documentation for
clarity and to conform to rustdoc formatting.
2020-09-30 22:39:39 -07:00
Jeffrey Czyz
bc4f4631cc
Remove ChainWatchInterface
The remaining use of ChainWatchInterface was replaced by chain::Access
in the previous commit, and thus it is no longer needed.
2020-09-30 22:39:38 -07:00
Jeffrey Czyz
3ee6a27bc6
Replace ChainWatchInterface in NetGraphMsgHandler
ChainWatchInterface was intended as an interface for watching rather
than accessing the chain. Remove get_chain_utxo and add chain::Access
trait for this behavior. Wrap it with an Option in NetGraphMsgHandler in
order to simplify the error interface.
2020-09-30 22:39:38 -07:00
Jeffrey Czyz
87398be293
Remove ChainWatchInterface from channelmonitor.rs
Use of ChainWatchInterface was replaced with WatchEvent in the previous
commit. Remove it from the parameterization of SimpleManyChannelMonitor
since it is no longer needed.
2020-09-30 22:39:12 -07:00
Jeffrey Czyz
bd39b20f64
Replace use of ChainWatchInterface with WatchEvent
SimpleManyChannelMonitor is parameterized by ChainWatchInterface to
signal what transactions and outputs to watch for on chain. The
interface has grown to cover chain access (via get_chain_utxo) and block
block filtering (via filter_block and reentered), which has added
complexity for implementations and user (see ChainWatchInterfaceUtil).

Pull the watch functionality out as a first step to eliminating
ChainWatchInterface entirely.
2020-09-24 11:56:29 -07:00
Jeffrey Czyz
1ab0a1acc1
Add test utilities for {dis}connecting a block
Replace direct uses of BlockNotifier in functional tests with utility
functions. This is in preparation for signaling watch events back via a
refactoring of ManyChannelMonitor and ChainWatchInterface. Those events
will be processed by connect_block.
2020-09-24 11:04:35 -07:00
Jeffrey Czyz
5381c23d72
Replace BlockNotifier with Node in test utilities
Change confirm_transaction and connect_blocks to take a Node instead of
a BlockNotifier. This is in preparation for signaling watch events back
via a refactoring of ManyChannelMonitor and ChainWatchInterface.
2020-09-24 10:45:37 -07:00
Jeffrey Czyz
82b608d5f3
Simplify BlockNotifier tests
Use a simple ChainListner implementation rather than large test objects
for testing BlockNotifier.

Remove unregister_single_listener_ref_test since it is redundant with
unregister_single_listener_test.

Remove unnecessary clone() calls.
2020-09-24 10:29:34 -07:00
Jeffrey Czyz
f69d9d7f30
Align ChannelMonitor interface with ChainListener
ChannelMonitor has block_connected and block_disconnected methods called
by <SimpleManyChannelMonitor as ChainListener>. Use similar parameters
in ChannelMonitor such that transformations are not needed and the
interface is more closely aligned with ChainListener.
2020-09-24 10:22:06 -07:00
Jeffrey Czyz
a7b2eb6d98
Remove ChainWatchInterface from BlockNotifier
ChainListeners should be independent of each other, but in practice this
is not the case because ChainWatchInterface introduces a dependency
between them. Push ChainWatchInterface down into the ChainListener
implementations where needed. Update ChainListener's block_connected
method to take a slice of the form &[(usize, &Transaction)] where each
transaction is paired with its position within the block.
2020-09-24 10:21:54 -07:00
Matt Corallo
8640173689
Merge pull request #715 from TheBlueMatt/2020-09-no-rescan-tests
Do not test any block-contents-rescan cases
2020-09-22 11:31:31 -07:00
Matt Corallo
38dacf1b93 Do not test any block-contents-rescan cases
In anticipation for removing support for users calling
block_connected multiple times for the same block to include all
relevant transactions in the next PR, this commit stops testing
such cases. Specifically, users who filter blocks for relevant
transactions before calling block_connected will need to filter by
including any transactions which spend a previously-matched
transaction in the same block (and we now do so in our own
filtering logic, which is also used in our testing).
2020-09-21 13:34:34 -04:00
Matt Corallo
9c1c43203f Clean up test_bump_penalty_txn_on_revoked_htlcs
Add a few comments to make it clear whats going on a bit more and
assert the basic structure of more transactions.

Further, point out where transactions are double-spends and don't
confirm double-spends.
2020-09-21 13:34:34 -04:00
Matt Corallo
ebb8d2d69f Clean up static_spendable_outputs_justice_tx_revoked_htlc_success_tx
Add a few comments to make it clear whats going on a bit more and
don't test/confirm a double-spend transaction.
2020-09-19 16:08:17 -04:00
Matt Corallo
07a0ad7cac Clean up static_spendable_outputs_justice_tx_revoked_htlc_timeout_tx
Add a few comments to make it clear whats going on a bit more and
don't test/confirm a bogus transaction.
2020-09-18 18:29:48 -04:00
Matt Corallo
e7678d42d9 derive(Debug) on Events
We'd previously largely not turned on derive(Debug) on any of our
structs, but not for good reason. Especially for Events objects,
Debug can be a very useful for users to quickly print what they
received from us without having to write out a large match.
2020-09-18 18:29:48 -04:00
Matt Corallo
640ae63a5a
Merge pull request #713 from valentinewallace/cross-platform-ci
Update CI to run on Macos and Windows in addition to Ubuntu.
2020-09-18 07:48:56 -07:00
Valentine Wallace
ce1f4562f5
Update CI to run build and tests on Macos and Windows in addition to Ubuntu.
We only run Macos and Windows on Rust stable, for efficient CI.
2020-09-17 16:07:39 -04:00
Valentine Wallace
b0e9b0107b
Remove unnecessary include in Github Actions script. 2020-09-17 16:07:39 -04:00
Valentine Wallace
b8a06d2945
Only link dead code when necessary in CI. 2020-09-17 16:07:36 -04:00
Matt Corallo
d735085cec
Merge pull request #690 from TheBlueMatt/2020-09-633-bindings
Small tweaks post #633/#684
2020-09-16 08:40:30 -07:00
Matt Corallo
0f6b0004c4 Fix two bugs which access the wrong peer's htlc_minimum_msat value
* Channel::get_counterparty_htlc_minimum_msat() returned
   holder_htlc_minimum_msat, which was obviously incorrect.
 * ChannelManager::get_channel_update set htlc_minimum_msat to
   Channel::get_holder_htlc_minimum_msat(), but the spec explicitly
   states we "MUST set htlc_minimum_msat to the minimum HTLC value
   (in millisatoshi) that the channel peer will accept." This makes
   sense because the reason we're rejecting the HTLC is because our
   counterparty's HTLC minimum value is too small for us to send to
   them, our own HTLC minimum value plays no role. Further, our
   router already expects this - looking at the same directional
   channel info as it does fees.

Finally, we add a test in the existing onion router test cases
which fails if either of the above is incorrect (the second issue
discovered in the process of writing the test).
2020-09-16 11:12:51 -04:00
Matt Corallo
a8be9af7d3 Move onion failure tests from functional_tests to their own file
They all have a specific structure, so having them in the mess that
is functional_tests isn't really conducive to readability. More
importantly, functional_tests is so big it slows down compilation,
so even dropping a few hundred lines is a win.
2020-09-16 11:12:51 -04:00
Matt Corallo
49e0a8ce7b Update bindings after merge of #633, #679, #683. 2020-09-16 11:12:51 -04:00
Matt Corallo
518f523637 Clarify docs on payment_point slightly 2020-09-16 10:50:54 -04:00
Matt Corallo
e9d3033e5c Merge pull request #679 from ariard/2020-08-concurrent-watchtowers
Implement concurrent broadcast tolerance for distributed watchtowers
2020-09-15 21:01:37 -04:00
Matt Corallo
26ee7e6379
Merge pull request #696 from TheBlueMatt/2020-09-ci-check-commits
Check each commit at least builds in CI
2020-09-15 17:45:50 -07:00
Matt Corallo
4d9532a165 Check each commit at least builds in CI 2020-09-15 19:24:08 -04:00
Antoine Riard
6622ea724f Improve PermanentFailure requiremnts documentation
Sources of the failure may be multiple in case of distributed watchtower
deployment. In either case, the channel manager must return a final
update asking to its channel monitor(s) to broadcast the lastest state
available. Revocation secret must not be released for the faultive
channel.

In the future, we may return wider type of failures to take more
fine-grained processing decision (e.g if local disk failure and
redudant remote channel copy available channel may still be processed
forward).
2020-09-15 18:17:37 -04:00
Antoine Riard
e706c67bdb Add test_concurrent_monitor_claim
Watchower Alice receives block 134, broadcasts state X, rejects state Y.
Watchtower Bob accepts state Y, receives blocks 135, broadcasts state Y.
State Y confirms onchain. Alice must be able to claim outputs.
2020-09-15 18:17:37 -04:00
Antoine Riard
e73036c684 Implement concurrent broadcast tolerance for distributed watchtowers
With a distrbuted watchtowers deployment, where each monitor is plugged
to its own chain view, there is no guarantee that block are going to be
seen in same order. Watchtower may diverge in their acceptance of a
submitted `commitment_signed` update due to a block timing-out a HTLC
and provoking a subset but yet not seen by the other watchtower subset.
Any update reject by one of the watchtower must block offchain coordinator
to move channel state forward and release revocation secret for previous
state.

In this case, we want any watchtower from the rejection subset to still
be able to claim outputs if the concurrent state, has accepted by the
other subset, is confirming. This improve overall watchtower system
fault-tolerance.

This change stores local commitment transaction unconditionally and fail
the update if there is knowledge of an already signed commitment
transaction (ChannelMonitor.local_tx_signed=true).
2020-09-15 18:17:35 -04:00
Matt Corallo
343aacc50c
Merge pull request #684 from bmancini55/gossip_queries
Adding gossip_queries messages and serializations
2020-09-14 13:45:12 -07:00
bmancini55
10e818ac53 Adding fuzzers for gossip_queries messages
This commit adds ser/deser fuzzers for five new structs in ln::msgs used
for gossip_queries.
2020-09-14 16:19:32 -04:00
bmancini55
5ba4560be9 Adding gossip_queries message structs and serialization
This adds the message structs and implements Readable and Writeable
traits for the standard gossip_queries messages.
2020-09-14 16:19:23 -04:00
Matt Corallo
d5912ec75f
Merge pull request #633 from ariard/2020-05-rename-keys-var
Rename a's keys as local's keys and b's keys as remote's keys
2020-09-14 12:49:56 -07:00
Antoine Riard
21d0a955ef Cleanup locally-selected-delay
Comment meaning of holder/counterparty

Diverse chan_utils cleanups

Cleanups post-cbindings merge

Fix misusage of holder_selected_contest_delay instead of counterparty
_selected_contest_delay in HolderCommitmentTransaction

Fix old payment_point comment
2020-09-14 15:19:06 -04:00
Antoine Riard
6133498ca1 Overhaul LocalCommitmentTx to new nomenclature 2020-09-14 14:39:47 -04:00