]> git.bitcoin.ninja Git - rust-lightning/log
rust-lightning
4 years agoSupport (de)serializing payment_data in onion TLVs and track them
Matt Corallo [Thu, 2 Jan 2020 01:20:42 +0000 (20:20 -0500)]
Support (de)serializing payment_data in onion TLVs and track them

This is the first step in Base AMP support, just tracking the
relevant data in internal datastructures.

4 years agoSplit only-receive/forward data out of PendingHTLCInfo into an enum
Matt Corallo [Wed, 1 Jan 2020 22:39:51 +0000 (17:39 -0500)]
Split only-receive/forward data out of PendingHTLCInfo into an enum

This should avoid blowing up the size of the struct when we add
additional data that is only relevant for receive.

4 years agoMerge pull request #582 from arik-so/trailing_newline_config
Matt Corallo [Sat, 11 Apr 2020 20:28:26 +0000 (20:28 +0000)]
Merge pull request #582 from arik-so/trailing_newline_config

Mandate new line at end of file in editorconfig.

4 years agoMandate new line at end of file in editorconfig.
Arik Sosman [Sat, 11 Apr 2020 18:33:07 +0000 (11:33 -0700)]
Mandate new line at end of file in editorconfig.

4 years agoMerge pull request #570 from naumenkogs/2020_04_routing_message_handler_tests
Matt Corallo [Sat, 11 Apr 2020 18:31:00 +0000 (18:31 +0000)]
Merge pull request #570 from naumenkogs/2020_04_routing_message_handler_tests

Add tests for routing message handler

4 years agoAdd tests for getting node announcements
User [Mon, 6 Apr 2020 23:28:17 +0000 (19:28 -0400)]
Add tests for getting node announcements

4 years agoAdd tests for getting next channel announcements
User [Mon, 6 Apr 2020 21:47:14 +0000 (17:47 -0400)]
Add tests for getting next channel announcements

4 years agoAdd tests for handling htlc fail channel updates
User [Mon, 6 Apr 2020 23:25:02 +0000 (19:25 -0400)]
Add tests for handling htlc fail channel updates

4 years agoAdd tests for handling channel updates
User [Mon, 6 Apr 2020 23:23:43 +0000 (19:23 -0400)]
Add tests for handling channel updates

4 years agoAdd tests for handling channel announcements
User [Mon, 6 Apr 2020 23:21:14 +0000 (19:21 -0400)]
Add tests for handling channel announcements

4 years agoAllow relaying of only one direction in a channel, log on recv
Matt Corallo [Mon, 24 Feb 2020 18:18:50 +0000 (13:18 -0500)]
Allow relaying of only one direction in a channel, log on recv

4 years agoAdd tests for handling node announcements
User [Thu, 2 Apr 2020 18:52:14 +0000 (14:52 -0400)]
Add tests for handling node announcements

4 years agoMerge pull request #581 from arik-so/fuzz_docs
Matt Corallo [Sat, 11 Apr 2020 03:10:58 +0000 (03:10 +0000)]
Merge pull request #581 from arik-so/fuzz_docs

Create docs for fuzzing

4 years agoUpdate documentation to reflect target-dependent local reproduction steps.
Arik Sosman [Sat, 11 Apr 2020 00:15:12 +0000 (17:15 -0700)]
Update documentation to reflect target-dependent local reproduction steps.

4 years agoAdd details on asserting latest version in the dependencies and listing targets.
Arik Sosman [Fri, 10 Apr 2020 18:22:46 +0000 (11:22 -0700)]
Add details on asserting latest version in the dependencies and listing targets.

4 years agoCreate docs for fuzzing
Arik Sosman [Fri, 10 Apr 2020 08:28:45 +0000 (01:28 -0700)]
Create docs for fuzzing

4 years agoMerge pull request #571 from ariard/2020-04-fix-minimalif
Matt Corallo [Fri, 3 Apr 2020 16:15:27 +0000 (16:15 +0000)]
Merge pull request #571 from ariard/2020-04-fix-minimalif

Enforce MINIMALIF-compliant witnesses

4 years agoEnforce MINIMALIF-compliant witness for spending revokable redeemscript
Antoine Riard [Thu, 2 Apr 2020 21:13:13 +0000 (17:13 -0400)]
Enforce MINIMALIF-compliant witness for spending revokable redeemscript

4 years agoEnforce MINIMALIF-compliant witness for timeout tx
Antoine Riard [Thu, 2 Apr 2020 21:10:35 +0000 (17:10 -0400)]
Enforce MINIMALIF-compliant witness for timeout tx

4 years agoMerge pull request #568 from jkczyz/2020-03-handle-error-deadlock
Matt Corallo [Thu, 2 Apr 2020 20:06:00 +0000 (20:06 +0000)]
Merge pull request #568 from jkczyz/2020-03-handle-error-deadlock

Fix deadlock in ChannelManager's handle_error!()

4 years agoTest failing backward any pending HTLCs
Jeffrey Czyz [Fri, 27 Mar 2020 23:46:57 +0000 (16:46 -0700)]
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.

4 years agoFix deadlock in handle_error!() when we have HTLCs to fail-back.
Matt Corallo [Mon, 13 Jan 2020 21:10:30 +0000 (16:10 -0500)]
Fix deadlock in handle_error!() when we have HTLCs to fail-back.

This partially reverts 933ae3470309f21ef7537ffbcdc42070d60e1e74,
though note that 933ae3470309f21ef7537ffbcdc42070d60e1e74 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>
4 years agoMerge pull request #556 from valentinewallace/add-PR550-test
Matt Corallo [Fri, 27 Mar 2020 20:27:15 +0000 (20:27 +0000)]
Merge pull request #556 from valentinewallace/add-PR550-test

Test that do_attempt_write_data does not infinitely loop

4 years agoTest that do_attempt_write_data does not infinitely loop
Valentine Wallace [Fri, 20 Mar 2020 22:42:02 +0000 (18:42 -0400)]
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.

4 years agoFix initial outbound sync infinite loop
Matt Corallo [Sun, 23 Feb 2020 23:04:03 +0000 (18:04 -0500)]
Fix initial outbound sync infinite loop

4 years agoMerge pull request #555 from ariard/2020-03-begin-dryup-chanmon-keys
Matt Corallo [Sat, 21 Mar 2020 22:21:38 +0000 (22:21 +0000)]
Merge pull request #555 from ariard/2020-03-begin-dryup-chanmon-keys

Begin dry-up ChannelMonitor key access

4 years agoRemove useless local commitment txn signatures
Antoine Riard [Fri, 20 Mar 2020 20:58:13 +0000 (16:58 -0400)]
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.

4 years agoDryup SecretKey from ChannelMonitor::OnchainDetection
Antoine Riard [Sat, 21 Mar 2020 18:26:58 +0000 (14:26 -0400)]
Dryup SecretKey from ChannelMonitor::OnchainDetection

Key access is provided through ChanSigner.

4 years agoAdd ChanSigner in OnchainTxHandler
Antoine Riard [Wed, 18 Mar 2020 04:29:26 +0000 (00:29 -0400)]
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.

4 years agoMerge pull request #557 from ariard/2020-03-link-arch-md
Matt Corallo [Sat, 21 Mar 2020 19:10:26 +0000 (19:10 +0000)]
Merge pull request #557 from ariard/2020-03-link-arch-md

Link ARCH.md in README.md

4 years agoLink ARCH.md in README.md
Antoine Riard [Sat, 21 Mar 2020 03:13:37 +0000 (23:13 -0400)]
Link ARCH.md in README.md

4 years agoMerge pull request #516 from TheBlueMatt/2020-02-checkin-arch
Matt Corallo [Sat, 21 Mar 2020 01:50:53 +0000 (01:50 +0000)]
Merge pull request #516 from TheBlueMatt/2020-02-checkin-arch

Add some basic arch diagrams/descriptions.

4 years agoAdd some basic arch diagrams/descriptions. 2020-02-checkin-arch
Matt Corallo [Tue, 25 Feb 2020 20:57:58 +0000 (15:57 -0500)]
Add some basic arch diagrams/descriptions.

4 years agoMerge pull request #554 from TheBlueMatt/2020-03-stale-mon-fail-man-deser
Matt Corallo [Fri, 20 Mar 2020 23:58:51 +0000 (23:58 +0000)]
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)

4 years agoRemove Watchtower mode from Storage enum and make it a struct
Antoine Riard [Wed, 18 Mar 2020 05:15:28 +0000 (01:15 -0400)]
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.

4 years agoMerge pull request #552 from ariard/2020-03-ismine-spendable
Matt Corallo [Fri, 20 Mar 2020 19:09:10 +0000 (19:09 +0000)]
Merge pull request #552 from ariard/2020-03-ismine-spendable

Introduce IsMine logic in ChannelMonitor for SpendableOutputDescriptor detection

4 years agoAdd test_static_spendable_outputs_timeout_tx
Antoine Riard [Tue, 3 Mar 2020 19:43:09 +0000 (14:43 -0500)]
Add test_static_spendable_outputs_timeout_tx

Cover previously missing SpendableOuputDescriptor for
timeout tx on non-revoked remote commitment tx.

Fix #338

4 years agoTest that ChannelManager fails to deserialize if monitors are stale 2020-03-stale-mon-fail-man-deser
Matt Corallo [Fri, 20 Mar 2020 01:31:18 +0000 (21:31 -0400)]
Test that ChannelManager fails to deserialize if monitors are stale

4 years agoFail to deserialize ChannelManager if it is ahead of any monitor(s)
Matt Corallo [Thu, 19 Mar 2020 23:15:06 +0000 (19:15 -0400)]
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.

4 years agoImplement reorg-safety for SpendableOutputDescriptor detection
Antoine Riard [Thu, 19 Mar 2020 00:58:05 +0000 (20:58 -0400)]
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.

4 years agoMove SpendableOutputDescriptor for closing tx in
Antoine Riard [Thu, 19 Mar 2020 01:39:28 +0000 (21:39 -0400)]
Move SpendableOutputDescriptor for closing tx in
is_paying_spendable_output

Add ChannelMonitor::shutdown_script to detect onchain tx
paying back to us

4 years agoMove SpendableOutputDescriptor::DynamicOutputP2WPKH in
Antoine Riard [Wed, 18 Mar 2020 22:02:31 +0000 (18:02 -0400)]
Move SpendableOutputDescriptor::DynamicOutputP2WPKH in
is_paying_spendable_output

Add ChannelMonitor::broadcasted_remote_payment_script to detect
onchain remote txn paying back to us.

4 years agoMove SpendableOutputDescirptor::DynamicOutputP2WSH in
Antoine Riard [Wed, 18 Mar 2020 21:57:29 +0000 (17:57 -0400)]
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

4 years agoIntroduce ChannelMonitor::is_paying_spendable_output
Antoine Riard [Wed, 18 Mar 2020 20:56:32 +0000 (16:56 -0400)]
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

4 years agoAdd logger for SpendableOutputDescriptor
Antoine Riard [Tue, 3 Mar 2020 19:41:13 +0000 (14:41 -0500)]
Add logger for SpendableOutputDescriptor

4 years agoMerge pull request #551 from TheBlueMatt/2020-03-no-chan-mon
Matt Corallo [Fri, 20 Mar 2020 00:22:11 +0000 (00:22 +0000)]
Merge pull request #551 from TheBlueMatt/2020-03-no-chan-mon

Generate latest local commitment transactions via monitor avoiding Channel's copy

4 years agoFetch latest commitment txn via monitor, not channel in test 2020-03-no-chan-mon
Matt Corallo [Thu, 19 Mar 2020 01:37:09 +0000 (21:37 -0400)]
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).

4 years agoFetch latest local commitment txn via a macro in tests
Matt Corallo [Thu, 19 Mar 2020 01:30:34 +0000 (21:30 -0400)]
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).

4 years agoBroadcast final local txn via ChannelMonitorUpdate
Matt Corallo [Wed, 18 Mar 2020 20:30:05 +0000 (16:30 -0400)]
Broadcast final local txn via ChannelMonitorUpdate

4 years agoDeduplicate HTLC preimage events from channelmonitor.
Matt Corallo [Thu, 19 Mar 2020 22:16:07 +0000 (18:16 -0400)]
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.

4 years agoRemove bogus mon_update_id += 1 fulfilling already-fulfilled HTLCs
Matt Corallo [Thu, 19 Mar 2020 01:10:22 +0000 (21:10 -0400)]
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.

4 years agoMerge pull request #547 from valentinewallace/add-PR539-test
Matt Corallo [Thu, 19 Mar 2020 02:52:40 +0000 (02:52 +0000)]
Merge pull request #547 from valentinewallace/add-PR539-test

Verify commitment point on ChannelReestablish (no updates case).

4 years agoVerify commitment point on ChannelReestablish (no updates case).
Valentine Wallace [Tue, 17 Mar 2020 23:54:16 +0000 (19:54 -0400)]
Verify commitment point on ChannelReestablish (no updates case).

Adds a test for PR #537.

4 years agoMerge pull request #537 from TheBlueMatt/2020-03-data-loss-spec-550
Matt Corallo [Tue, 17 Mar 2020 18:49:06 +0000 (18:49 +0000)]
Merge pull request #537 from TheBlueMatt/2020-03-data-loss-spec-550

Update pre-HTLC DataLossProtect to match new spec changes

4 years agoMerge pull request #546 from TheBlueMatt/2020-03-519-nits
Matt Corallo [Tue, 17 Mar 2020 18:47:48 +0000 (18:47 +0000)]
Merge pull request #546 from TheBlueMatt/2020-03-519-nits

Watch revoked HTLC-Success/Timeout outputs

4 years agoAdd more logs in OnchainTxHandler 2020-03-519-nits
Antoine Riard [Wed, 26 Feb 2020 23:21:53 +0000 (18:21 -0500)]
Add more logs in OnchainTxHandler

4 years agoWatch outputs of revoked HTLC-transactions
Antoine Riard [Wed, 26 Feb 2020 23:18:27 +0000 (18:18 -0500)]
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>

4 years agoFix duplicata of adjusted justice tx generation in OnchainTxHandler
Antoine Riard [Wed, 11 Mar 2020 19:10:29 +0000 (15:10 -0400)]
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.

4 years agoMerge pull request #545 from TheBlueMatt/2020-03-fuzz-0-fee
Matt Corallo [Tue, 17 Mar 2020 18:01:06 +0000 (18:01 +0000)]
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

4 years agoMerge pull request #544 from TheBlueMatt/2020-03-fix-mon-ser
Matt Corallo [Tue, 17 Mar 2020 17:59:22 +0000 (17:59 +0000)]
Merge pull request #544 from TheBlueMatt/2020-03-fix-mon-ser

Fix ChannelMonitor round-trip introduced by 3d640da5c343111f538f006

4 years agoDon't return a feerate of 0 in full_stack_target fuzz on EOF 2020-03-fuzz-0-fee
Matt Corallo [Tue, 17 Mar 2020 02:05:57 +0000 (22:05 -0400)]
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.

4 years agoFix ChannelMonitor round-trip introduced by 3d640da5c343111f538f006 2020-03-fix-mon-ser
Matt Corallo [Mon, 16 Mar 2020 23:01:17 +0000 (19:01 -0400)]
Fix ChannelMonitor round-trip introduced by 3d640da5c343111f538f006

3d640da5c343111f538f006996c13c9a98e0d9e6 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.

4 years agoMerge pull request #543 from TheBlueMatt/2020-03-513-warning
Matt Corallo [Mon, 16 Mar 2020 20:23:37 +0000 (20:23 +0000)]
Merge pull request #543 from TheBlueMatt/2020-03-513-warning

Add missing unwrap() in tests introduced in 4abfd515e554bef90c25dbe

4 years agoAdd missing unwrap() in tests introduced in 4abfd515e554bef90c25dbe 2020-03-513-warning
Matt Corallo [Wed, 11 Mar 2020 20:10:01 +0000 (16:10 -0400)]
Add missing unwrap() in tests introduced in 4abfd515e554bef90c25dbe

4 years agoMerge pull request #513 from ariard/2020-02-fix-zero-msat-htlc
Matt Corallo [Wed, 11 Mar 2020 19:57:38 +0000 (19:57 +0000)]
Merge pull request #513 from ariard/2020-02-fix-zero-msat-htlc

BOLT2: Check we don't send and accept 0-msat HTLC

4 years agoAdd test_override_0msat_htlc_minimum
Antoine Riard [Tue, 10 Mar 2020 23:29:56 +0000 (19:29 -0400)]
Add test_override_0msat_htlc_minimum

4 years agoMake htlc_minimum_msat configurable
Antoine Riard [Tue, 10 Mar 2020 17:03:10 +0000 (13:03 -0400)]
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.

4 years agoMerge pull request #472 from TheBlueMatt/2020-01-net-async-await
Matt Corallo [Wed, 11 Mar 2020 17:41:57 +0000 (17:41 +0000)]
Merge pull request #472 from TheBlueMatt/2020-01-net-async-await

Rewrite lightning-net-tokio using async/await and tokio 0.2

4 years agoMerge pull request #541 from valentinewallace/fix-node-features
Matt Corallo [Wed, 11 Mar 2020 17:32:33 +0000 (17:32 +0000)]
Merge pull request #541 from valentinewallace/fix-node-features

Fix node `with_relevant_init_flags`

4 years agoAdd test cases for feature messages from other lightning clients.
Valentine Wallace [Tue, 10 Mar 2020 00:51:32 +0000 (20:51 -0400)]
Add test cases for feature messages from other lightning clients.

4 years agoFix blanking out non-node-context feature flags when pulling features from init context.
Valentine Wallace [Tue, 10 Mar 2020 00:50:41 +0000 (20:50 -0400)]
Fix blanking out non-node-context feature flags when pulling features from init context.

Fixes bug introduced in 912f877

4 years agoFix typo in lightning-net-tokio crate description. 2020-01-net-async-await
Matt Corallo [Mon, 3 Feb 2020 23:47:38 +0000 (18:47 -0500)]
Fix typo in lightning-net-tokio crate description.

4 years agoFix (and test) net-tokio outbound conns without a threaded env
Matt Corallo [Fri, 28 Feb 2020 16:55:34 +0000 (11:55 -0500)]
Fix (and test) net-tokio outbound conns without a threaded env

4 years agoFix long-standing race in net-tokio reading after a disconnect event
Matt Corallo [Mon, 24 Feb 2020 19:17:04 +0000 (14:17 -0500)]
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.

4 years agoRewrite lightning-net-tokio using async/await and tokio 0.2
Matt Corallo [Sat, 1 Feb 2020 17:27:30 +0000 (12:27 -0500)]
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.

4 years agoAdd test_update_add_htlc_bolt2_receiver_zero_value_msat
Antoine Riard [Wed, 26 Feb 2020 21:05:00 +0000 (16:05 -0500)]
Add test_update_add_htlc_bolt2_receiver_zero_value_msat

4 years agoBOLT2: Check we don't send and accept 0-msat HTLC
Antoine Riard [Fri, 21 Feb 2020 00:20:29 +0000 (19:20 -0500)]
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.

4 years agoSwap read_event read type for a slice isntead of a Vec
Matt Corallo [Sat, 1 Feb 2020 01:57:01 +0000 (20:57 -0500)]
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.

4 years agoMerge pull request #435 from TheBlueMatt/2020-01-node_announce
Matt Corallo [Mon, 9 Mar 2020 00:13:47 +0000 (00:13 +0000)]
Merge pull request #435 from TheBlueMatt/2020-01-node_announce

Add ability to broadcast our own node_announcement

4 years agoUpdate pre-HTLC DataLossProtect to match new spec changes 2020-03-data-loss-spec-550
Matt Corallo [Sat, 15 Feb 2020 03:32:30 +0000 (22:32 -0500)]
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.

4 years agoUse block timestamps as the min for generated update messages. 2020-01-node_announce
Matt Corallo [Thu, 5 Mar 2020 23:01:06 +0000 (18:01 -0500)]
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.

4 years agoFurther document the initial routing table send.
Matt Corallo [Wed, 12 Feb 2020 18:40:29 +0000 (13:40 -0500)]
Further document the initial routing table send.

As requested by Arik at https://github.com/rust-bitcoin/rust-lightning/pull/435#discussion_r378093821

4 years agoAdd ability to broadcast our own node_announcement.
Matt Corallo [Fri, 3 Jan 2020 01:32:37 +0000 (20:32 -0500)]
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.

4 years agoAllow more than one address per type in node_announcement messages
Matt Corallo [Thu, 5 Mar 2020 18:39:53 +0000 (13:39 -0500)]
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.

4 years agoAllow node_announcement timestamps of 0 in accordance with BOLT 7
Matt Corallo [Fri, 3 Jan 2020 19:03:46 +0000 (14:03 -0500)]
Allow node_announcement timestamps of 0 in accordance with BOLT 7

Unlike channel_update messages, node_announcement messages have no
requirement that the timestamp is greater than 0.

4 years agoMerge pull request #535 from TheBlueMatt/2020-03-462-nits
Matt Corallo [Thu, 5 Mar 2020 16:19:14 +0000 (16:19 +0000)]
Merge pull request #535 from TheBlueMatt/2020-03-462-nits

A few minor nits on #462

4 years agoTake multiple spent-txn to check_spends! in functional_tests 2020-03-462-nits
Matt Corallo [Wed, 4 Mar 2020 22:45:27 +0000 (17:45 -0500)]
Take multiple spent-txn to check_spends! in functional_tests

This reintroduces a check_spends!() removed in 3d640da5c343111f538f
due to check_spends not being able to check a transaction which
spends multiple other transactions.

It also simplifies a few calls in claim_htlc_outputs_single_tx by
using check_spends!().

4 years agoDrop redundant .clone() in check_spends calls.
Matt Corallo [Wed, 4 Mar 2020 22:36:12 +0000 (17:36 -0500)]
Drop redundant .clone() in check_spends calls.

The API to rust-bitcoin to check a transaction correctly spends
another changed some time ago, but we still have a lot of needless
.clone()s in our tests.

4 years agoCorrect comment in onchaintx.rs
Matt Corallo [Wed, 4 Mar 2020 22:53:16 +0000 (17:53 -0500)]
Correct comment in onchaintx.rs

This comment was stale and referred to a previous implementation
of #462, which changed before it was merged.

4 years agoFlatten Vec passed from channelmonitor to onchaintx block_connected
Matt Corallo [Wed, 4 Mar 2020 22:27:03 +0000 (17:27 -0500)]
Flatten Vec passed from channelmonitor to onchaintx block_connected

Instead of passing a Vec of Vecs drop them into one as we go in
ChannelMonitor, hopefully avoiding a bit of memory fragmentation
and improving readability.

4 years agoMerge pull request #462 from ariard/2020-01-refactor-chan
Matt Corallo [Wed, 4 Mar 2020 22:23:28 +0000 (22:23 +0000)]
Merge pull request #462 from ariard/2020-01-refactor-chan

Introduce OnchainTxHandler, move bumping and tracking logic

4 years agoRename InputMaterial script to witness_script
Antoine Riard [Mon, 2 Mar 2020 23:12:18 +0000 (18:12 -0500)]
Rename InputMaterial script to witness_script

4 years agoComment better get_height_timer logic.
Antoine Riard [Tue, 18 Feb 2020 18:11:56 +0000 (13:11 -0500)]
Comment better get_height_timer logic.

Height timer as an important component of a more-secure, fee-sensitive
claiming of time-constrained LN outputs, therefore document assumptions.

4 years agoRemove TestBroadcaster temporary dedup buffer
Antoine Riard [Fri, 24 Jan 2020 22:48:27 +0000 (17:48 -0500)]
Remove TestBroadcaster temporary dedup buffer

4 years agoStructurify claim request handed between detection/reaction
Antoine Riard [Wed, 12 Feb 2020 18:00:29 +0000 (13:00 -0500)]
Structurify claim request handed between detection/reaction

4 years agoIntroduce OnchainTxHandler, move bumping and tracking logic
Antoine Riard [Fri, 24 Jan 2020 16:57:52 +0000 (11:57 -0500)]
Introduce OnchainTxHandler, move bumping and tracking logic

Encapsulates tracking and bumping of in-flight transactions in
its own component. This component may be latter abstracted
to reuse tracking and RBF for new features (e.g dual-funding,
splicing)

Build all transactions generation in one place. Also as fees
and signatures are closely tied, what keys do you have determine
what bumping mode you can use.

4 years agoMerge pull request #523 from TheBlueMatt/2020-02-router-ser-fix
Matt Corallo [Wed, 4 Mar 2020 20:37:58 +0000 (20:37 +0000)]
Merge pull request #523 from TheBlueMatt/2020-02-router-ser-fix

Fix Router Serialization Roundtrip

4 years agoTest Router serialization round-trip in functional_tests. 2020-02-router-ser-fix
Matt Corallo [Mon, 24 Feb 2020 04:26:10 +0000 (23:26 -0500)]
Test Router serialization round-trip in functional_tests.

This tests Router serialization round-trip at the end of each
functional test in the same way we do ChannelMonitors and
ChannelManagers to catch any cases where we were able to get into
a state which would have prevented reading a Router back off disk.

We further walk all of the announcements which both the original
and deserialized Routers would send to peers requesting initial
sync to ensure they match.

4 years agoChange Option<T> serialization format to include length
Matt Corallo [Mon, 24 Feb 2020 04:25:43 +0000 (23:25 -0500)]
Change Option<T> serialization format to include length

This is a cheap way to fix an error in Router serialization
roundtrip due to us calling read_to_end during the read of
channel/node announcement/updates. During normal message reading,
we only have limited bytes to read (specifically the message buffer)
so this is fine, however when we read them inside Router, we have
more data from other fields of the Router available as well. Thus,
we end up reading the entire rest of the Router into one message
field, and failing to deserialize.

Because such fields are always stored in Option<>s, we can simply
use a LengthLimitingStream in the Option<> serialization format and
make only the correct number of bytes available.

By using a variable-length integer for the new field, we avoid
wasting space compared to the existing serialization format.

4 years agoMake Readable::read a templated on the stream, not Readable itself
Matt Corallo [Mon, 24 Feb 2020 04:12:19 +0000 (23:12 -0500)]
Make Readable::read a templated on the stream, not Readable itself

This makes Readable symmetric with Writeable and makes sense -
something which is Readable should be Readable for any stream which
implements std::io::Read, not only for a stream type it decides on.

This solves some lifetime-compatibility issues in trying to read()
from a LengthLimitingReader in arbitrary Readable impls.