Commit graph

1315 commits

Author SHA1 Message Date
Matt Corallo
60dd37d9a0
Merge pull request #581 from arik-so/fuzz_docs
Create docs for fuzzing
2020-04-11 03:10:58 +00:00
Arik Sosman
cdb1f8e48a
Update documentation to reflect target-dependent local reproduction steps. 2020-04-10 17:15:12 -07:00
Arik Sosman
aea2971f5c
Add details on asserting latest version in the dependencies and listing targets. 2020-04-10 11:22:46 -07:00
Arik Sosman
df18f99b5a
Create docs for fuzzing 2020-04-10 01:28:45 -07: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
Matt Corallo
b8876a90ae
Merge pull request #556 from valentinewallace/add-PR550-test
Test that do_attempt_write_data does not infinitely loop
2020-03-27 20:27:15 +00: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
e2be482306
Merge pull request #557 from ariard/2020-03-link-arch-md
Link ARCH.md in README.md
2020-03-21 19:10:26 +00:00
Antoine Riard
e2bd46df63 Link ARCH.md in README.md 2020-03-20 23:13:37 -04:00
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