Commit graph

1446 commits

Author SHA1 Message Date
Matt Corallo
f1c7fd2ab9
Merge pull request #516 from TheBlueMatt/2020-02-checkin-arch
Add some basic arch diagrams/descriptions.
2020-03-21 01:50:53 +00:00
Matt Corallo
dd375e6157 Add some basic arch diagrams/descriptions. 2020-03-20 20:40:37 -04:00
Matt Corallo
ed0d5d1f6d
Merge pull request #554 from TheBlueMatt/2020-03-stale-mon-fail-man-deser
Fail to deserialize ChannelManager if it is ahead of any monitor(s)
2020-03-20 23:58:51 +00:00
Antoine Riard
1dbda4faed Remove Watchtower mode from Storage enum and make it a struct
Watchtower will be supported through external signer interface
where a watchtower implementation may differ from a local one
by the scope of key access and pre-signed datas.
2020-03-20 17:05:38 -04:00
Matt Corallo
8bd155e774
Merge pull request #552 from ariard/2020-03-ismine-spendable
Introduce IsMine logic in ChannelMonitor for SpendableOutputDescriptor detection
2020-03-20 19:09:10 +00:00
Antoine Riard
1c7b6c8288 Add test_static_spendable_outputs_timeout_tx
Cover previously missing SpendableOuputDescriptor for
timeout tx on non-revoked remote commitment tx.

Fix #338
2020-03-20 14:34:17 -04:00
Matt Corallo
4aa95af272 Test that ChannelManager fails to deserialize if monitors are stale 2020-03-20 12:50:34 -04:00
Matt Corallo
492983f54f Fail to deserialize ChannelManager if it is ahead of any monitor(s)
If any monitors are out of sync with the Channel, we previously
closed the channel, but we should really only do that if the
monitor is ahead of the channel, opting to call the whole thing
invalid if the channel is ahead of the monitor.
2020-03-20 12:30:57 -04:00
Antoine Riard
b7407b219d Implement reorg-safety for SpendableOutputDescriptor detection
We delay SpendableOutputDescriptor until reaching ANTI_REORG_DELAY
to avoid misleading user wallet in case of reorg and alternative
settlement on a channel output.

Fix tests in consequence.
2020-03-19 22:31:48 -04:00
Antoine Riard
aa84673cdb Move SpendableOutputDescriptor for closing tx in
is_paying_spendable_output

Add ChannelMonitor::shutdown_script to detect onchain tx
paying back to us
2020-03-19 22:29:26 -04:00
Antoine Riard
1cee5671c3 Move SpendableOutputDescriptor::DynamicOutputP2WPKH in
is_paying_spendable_output

Add ChannelMonitor::broadcasted_remote_payment_script to detect
onchain remote txn paying back to us.
2020-03-19 22:29:26 -04:00
Antoine Riard
a2bdadaeed Move SpendableOutputDescirptor::DynamicOutputP2WSH in
is_paying_spendable_output

Add ChannelMonitor::broadcasted_local_revokable_script to detect
onchain local txn paying back to us.

Fix tests in consequence
2020-03-19 22:29:26 -04:00
Antoine Riard
26ac188a3f Introduce ChannelMonitor::is_paying_spendable_output
Previously, we would generate SpendableOutputDescriptor::StaticOutput
in OnchainTxHandler even if our claiming transaction wouldn't confirm
onchain, misbehaving user wallet to think it receives more funds than
in reality.

Fix tests in consequence
2020-03-19 22:29:26 -04:00
Antoine Riard
c61d7de892 Add logger for SpendableOutputDescriptor 2020-03-19 22:29:26 -04:00
Matt Corallo
7df042b334
Merge pull request #551 from TheBlueMatt/2020-03-no-chan-mon
Generate latest local commitment transactions via monitor avoiding Channel's copy
2020-03-20 00:22:11 +00:00
Matt Corallo
feca83a8a8 Fetch latest commitment txn via monitor, not channel in test
Eventually, we want to remove the Channel's copy of its own
ChannelMonitor, reducing memory footprint and complexity of
ChannelManager greatly.

This removes the last uses of said ChannelMonitor for latest
local commitment transactions (though it is still used for
would_broadcast_at_height(), which is the last remaining use).
2020-03-19 19:21:36 -04:00
Matt Corallo
e1c1ac7576 Fetch latest local commitment txn via a macro in tests
This makes it easier to swap out how we fetch the latest local
commitment txn in testing (which we use to check or broadcast old
states).
2020-03-19 19:21:36 -04:00
Matt Corallo
03b5da10b7 Broadcast final local txn via ChannelMonitorUpdate 2020-03-19 19:21:36 -04:00
Matt Corallo
82d40eefb2 Deduplicate HTLC preimage events from channelmonitor.
This avoids calling get_update_fulfill_htlc_and_commit twice for
the same HTLC if we have to rescan a block.
2020-03-19 19:21:36 -04:00
Matt Corallo
32d62ada96 Remove bogus mon_update_id += 1 fulfilling already-fulfilled HTLCs
If we call get_update_fulfill_htlc (in this case via
ChannelManager::claim_funds_internal ->
Channel::get_update_fulfill_htlc_and_commit) and it finds that we
already have a holding-cell pending HTLC claim, it will return no
monitor update but leave latest_monitor_update_id incremented.

If we later go and add a new monitor update we'll panic as the
updates appear to have been applied out-of-order.
2020-03-19 19:20:27 -04:00
Matt Corallo
082b72065e
Merge pull request #547 from valentinewallace/add-PR539-test
Verify commitment point on ChannelReestablish (no updates case).
2020-03-19 02:52:40 +00:00
Valentine Wallace
f2b7ccaa86
Verify commitment point on ChannelReestablish (no updates case).
Adds a test for PR #537.
2020-03-18 17:56:54 -04:00
Matt Corallo
33b7c906f2
Merge pull request #537 from TheBlueMatt/2020-03-data-loss-spec-550
Update pre-HTLC DataLossProtect to match new spec changes
2020-03-17 18:49:06 +00:00
Matt Corallo
feb0a9fbcc
Merge pull request #546 from TheBlueMatt/2020-03-519-nits
Watch revoked HTLC-Success/Timeout outputs
2020-03-17 18:47:48 +00:00
Antoine Riard
2d2f658f71 Add more logs in OnchainTxHandler 2020-03-17 14:09:21 -04:00
Antoine Riard
3cba654e32 Watch outputs of revoked HTLC-transactions
Bumping of justice txn on revoked HTLC-Success/HTLC-timeout is triggered
until our claim is confirmed onchain with at least
ANTI_REORG_DELAY_SAFE. Before this patch, we weren't tracking them in
check_spend_remote_htlc, leading us to infinite bumps.

Fix #411

Small fixes by Matt Corallo <git@bluematt.me>
2020-03-17 14:09:21 -04:00
Antoine Riard
0d45ddc9e2 Fix duplicata of adjusted justice tx generation in OnchainTxHandler
Adjusted tx occurs when a previous aggregated claim tx has
seen one of its outpoint being partially claimed by a remote tx.
To pursue claiming of the remaining outpoint a adjusted claim tx
is generated  with leftover of claimable outpoints.

Previously, in case of block-rescan where a partial claim occurs,
we would generate duplicated adjusted tx, wrongly inflating feerate
for next bumps. At rescan, if input has already been dropped from
outpoints map from a claiming request, don't regenerate again
a adjuste tx.
2020-03-17 14:09:21 -04:00
Matt Corallo
c8236b2811
Merge pull request #545 from TheBlueMatt/2020-03-fuzz-0-fee
Don't return a feerate of 0 in full_stack_target fuzz on EOF
2020-03-17 18:01:06 +00:00
Matt Corallo
f2e91519d3
Merge pull request #544 from TheBlueMatt/2020-03-fix-mon-ser
Fix ChannelMonitor round-trip introduced by 3d640da5c3
2020-03-17 17:59:22 +00:00
Matt Corallo
8a03830d43 Don't return a feerate of 0 in full_stack_target fuzz on EOF
This triggered a (legitimate) panic in OnChainTxHandler that the
feerate in use was non-0, which is required by the feerate API.
2020-03-16 22:09:08 -04:00
Matt Corallo
6fe8c121a7 Fix ChannelMonitor round-trip introduced by 3d640da5c3
3d640da5c3 changed the indexes for
some enums in ChannelMonitor deserialization but not serialization.
Thus, the chanmon_deser_target fuzz target failed on travis on at
least one PR.
2020-03-16 20:02:48 -04:00
Matt Corallo
4c33197af8
Merge pull request #543 from TheBlueMatt/2020-03-513-warning
Add missing unwrap() in tests introduced in 4abfd515e5
2020-03-16 20:23:37 +00:00
Matt Corallo
cd3748cd9d Add missing unwrap() in tests introduced in 4abfd515e5 2020-03-11 16:10:01 -04:00
Matt Corallo
d6b1825186
Merge pull request #513 from ariard/2020-02-fix-zero-msat-htlc
BOLT2: Check we don't send and accept 0-msat HTLC
2020-03-11 19:57:38 +00:00
Antoine Riard
dd9c476a58 Add test_override_0msat_htlc_minimum 2020-03-11 14:28:22 -04:00
Antoine Riard
9e03d2bc7a Make htlc_minimum_msat configurable
Enforce a minimum htlc_minimum_msat of 1.

Instead of computing dynamically htlc_minimum_msat based on feerate,
relies on user-provided configuration value. This let user compute
an economical-driven channel parameter according to network dynamics.
2020-03-11 14:28:20 -04:00
Matt Corallo
d27e9e1c6a
Merge pull request #472 from TheBlueMatt/2020-01-net-async-await
Rewrite lightning-net-tokio using async/await and tokio 0.2
2020-03-11 17:41:57 +00:00
Matt Corallo
eee94672be
Merge pull request #541 from valentinewallace/fix-node-features
Fix node `with_relevant_init_flags`
2020-03-11 17:32:33 +00:00
Valentine Wallace
40a1aef322
Add test cases for feature messages from other lightning clients. 2020-03-11 12:55:00 -04:00
Valentine Wallace
658b681772
Fix blanking out non-node-context feature flags when pulling features from init context.
Fixes bug introduced in 912f877
2020-03-11 12:54:14 -04:00
Matt Corallo
174ccf5abe Fix typo in lightning-net-tokio crate description. 2020-03-11 12:19:39 -04:00
Matt Corallo
06d3b20512 Fix (and test) net-tokio outbound conns without a threaded env 2020-03-11 12:19:39 -04:00
Matt Corallo
60d37b2698 Fix long-standing race in net-tokio reading after a disconnect event
If rust-lightning tells us to disconnect a socket after we read
some bytes from the socket, but before we actually give those bytes
to rust-lightning, we may end up calling rust-lightning with a
Descriptor that isn't registered anymore.

Sadly, there really isn't a good way to solve this, and it should
be a pretty quick event, so we just busy-wait.
2020-03-11 12:19:39 -04:00
Matt Corallo
5ada940464 Rewrite lightning-net-tokio using async/await and tokio 0.2
This is a rather major rewrite, using async/await and tokio 0.2,
which cleans up the code a ton as well as adds significantly to
readability.
2020-03-11 12:19:39 -04:00
Antoine Riard
4abfd515e5 Add test_update_add_htlc_bolt2_receiver_zero_value_msat 2020-03-10 13:05:30 -04:00
Antoine Riard
d1c6f235f9 BOLT2: Check we don't send and accept 0-msat HTLC
Failing this requirement at sending means a strict receiver would
fail our channel while processing a HTLC routed from a third-party.

Fix by enforcing check on both sender and receiver side.
2020-03-10 13:05:30 -04:00
Matt Corallo
6f06858304 Swap read_event read type for a slice isntead of a Vec
It looks like we don't currently use the Vec as a Vec, and can
happily take a slice, which makes things easier on the calling
side.
2020-03-10 11:52:12 -04:00
Matt Corallo
83c9eb4b9e
Merge pull request #435 from TheBlueMatt/2020-01-node_announce
Add ability to broadcast our own node_announcement
2020-03-09 00:13:47 +00:00
Matt Corallo
4f06d7a83c Update pre-HTLC DataLossProtect to match new spec changes
This was the way DataLossProtect was originally written, however it
didn't match other implementations at the time during testing. It
turns out, other implementations didn't agree with each other
anyway (depending on the exact timeline), so the spec was clarified
somewhat in https://github.com/lightningnetwork/lightning-rfc/pull/550
. This updates us to be in line with the new guidance and appears
to solve out-of-sync issues in testing.
2020-03-05 21:16:47 -05:00
Matt Corallo
78c48f76d4 Use block timestamps as the min for generated update messages.
Fixes issue #493 and should resolve some issues where other nodes
(incorrectly) reject channel_update/node_announcement messages
which have a serial number that is not a relatively recent
timestamp.
2020-03-05 20:59:43 -05:00