Commit graph

3735 commits

Author SHA1 Message Date
User
fce5c15711 Add tests for handling node announcements 2020-04-11 08:30:21 -04:00
Matt Corallo
a4e4056240
Merge pull request #571 from ariard/2020-04-fix-minimalif
Enforce MINIMALIF-compliant witnesses
2020-04-03 16:15:27 +00:00
Antoine Riard
1508253bf0 Enforce MINIMALIF-compliant witness for spending revokable redeemscript 2020-04-02 17:13:13 -04:00
Antoine Riard
0bc82ee1bc Enforce MINIMALIF-compliant witness for timeout tx 2020-04-02 17:10:35 -04:00
Matt Corallo
f0b037ce14
Merge pull request #568 from jkczyz/2020-03-handle-error-deadlock
Fix deadlock in ChannelManager's handle_error!()
2020-04-02 20:06:00 +00:00
Jeffrey Czyz
3968647997 Test failing backward any pending HTLCs
Upon channel failure, any pending HTLCs in a channel's holding cell must
be failed backward. The added test exercises this behavior and
demonstrates a deadlock triggered within the handle_error!() macro. The
deadlock occurs when the channel_state lock is already held and then
reacquired when finish_force_close_channel() is called.
2020-04-01 16:36:49 -07:00
Matt Corallo
86143fd69d Fix deadlock in handle_error!() when we have HTLCs to fail-back.
This partially reverts 933ae34703,
though note that 933ae34703 fixed a
similar deadlock while introducing this one.

If we have HTLCs to fail backwards, handle_error!() will call
finish_force_close_channel() which will attempt to lock channel_state
while it is locked at the original caller. Instead, hold the lock for
shorter scopes such that it is not held upon entering handle_error!().

Co-authored-by: Matt Corallo <git@bluematt.me>
Co-authored-by: Jeffrey Czyz <jkczyz@gmail.com>
2020-04-01 16:27:22 -07:00
Valentine Wallace
3e0aed23a3
Test that do_attempt_write_data does not infinitely loop
when all the channel messages can't fit into the buffer.

Adds a test for PR #550.
2020-03-27 16:15:57 -04:00
Matt Corallo
a5e08346c2
Fix initial outbound sync infinite loop 2020-03-23 17:47:17 -04:00
Matt Corallo
e5bedc43d2
Merge pull request #555 from ariard/2020-03-begin-dryup-chanmon-keys
Begin dry-up ChannelMonitor key access
2020-03-21 22:21:38 +00:00
Antoine Riard
502197d943 Remove useless local commitment txn signatures
check_spend_local_transaction is tasked with detection of
onchain local commitment transaction and generate HTLC transaction.
Signing an already onchain tx isn't necessary.
2020-03-21 17:03:54 -04:00
Antoine Riard
82e78872df Dryup SecretKey from ChannelMonitor::OnchainDetection
Key access is provided through ChanSigner.
2020-03-21 17:03:54 -04:00
Antoine Riard
16fba9fd66 Add ChanSigner in OnchainTxHandler
Rename ChannelMonitor::Storage to OnchainDetection,
holder of channel state (base_key+per_commitment_point)
to detect onchain transactions accordingly.

Going further between splitting detection and transaction
generation, we endow OnchainTxHandler with keys access.
That way, in latter commits, we may remove secret keys entirely
from ChannelMonitor.
2020-03-21 17:03:48 -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
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
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
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
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
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
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
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
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
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
Matt Corallo
c2ca6d3cdc Further document the initial routing table send.
As requested by Arik at https://github.com/rust-bitcoin/rust-lightning/pull/435#discussion_r378093821
2020-03-05 20:59:43 -05:00
Matt Corallo
a8114a70cb Add ability to broadcast our own node_announcement.
This is a somewhat-obvious oversight in the capabilities of
rust-lightning, though not a particularly interesting one until we
start relying on node_features (eg for variable-length-onions and
Base AMP).

Sadly its not fully automated as we don't really want to store the
list of available addresses from the user. However, with a simple
call to ChannelManager::broadcast_node_announcement and a sensible
peer_handler, the announcement is made.
2020-03-05 20:59:43 -05:00
Matt Corallo
107da97cd0 Allow more than one address per type in node_announcement messages
lnd has been blatantly ignoring this line in the spec forever, so
its somewhat of a lost cause trying to enforce it.
2020-03-05 18:42:49 -05:00