Commit graph

3288 commits

Author SHA1 Message Date
Matt Corallo
84a08dbf8a Make lightning-block-sync's init module slightly more generic
Users who want to use lightning-block-sync's init module would
be reasonable in wanting to use it in a multithreaded environment,
however because it takes a list of listeners as dyn chain::Listen
without any Send or Sync bound they fail in doing so.

Here we make the type bounds on `chain::Listen` generic across
`chain::Listen + ?Sized`, which the existing bound of `&dyn
chain::Listen` satisfies. Thus, this is strictly less restrictive
and allows for the use of `&dyn chain::Listen + Send + Sync`.
2022-03-09 18:20:43 +00:00
Matt Corallo
6259e7a674
Merge pull request #1339 from TheBlueMatt/2022-02-0.0.105-sec
0.0.105 Security Fixes
2022-03-01 04:13:19 +00:00
Matt Corallo
d798ac15c0 Update CHANGELOG with security info for 0.0.105 2022-03-01 02:23:20 +00:00
Matt Corallo
f9983de485 Merge branch '2022-02-bal-panic' into 2022-02-0.0.105-sec 2022-03-01 02:23:14 +00:00
Matt Corallo
797a648b6c Merge branch '2022-02-fix-multi-hop-hint-panic' into 2022-02-0.0.105-sec 2022-03-01 02:23:07 +00:00
Matt Corallo
82b8d854e7
Merge pull request #1322 from TheBlueMatt/2022-02-0.0.105
Cut 0.0.105
2022-03-01 02:22:00 +00:00
Matt Corallo
ed8f36520d Ensure get_claimable_balances never panicks in tests
... by calling it both before and after every chain event in
testing and fuzzing.

This requires fixing some blockchain inconsistencies in
`do_test_onchain_htlc_reorg`, `do_retry_with_no_persist`, and
`do_test_dup_htlc_onchain_fails_on_reload` where we'd connect
conflicting transactions in the same chain.
2022-03-01 00:43:55 +00:00
Matt Corallo
b1653f0705 Fix HTLC tx balance calculation on local commitment transactions
When handling the broadcast of a local commitment transactions
(with associated CSV delays prior to spendability), we incorrectly
handled the CSV delays on HTLC transactions. This caused us to miss
spendable outputs for HTLCs which were awaiting a CSV delay.

Further, because of this, we could hit an assertion as
`get_claimable_balances` asserted that HTLCs were resolved after
the funding spend was resolved, which was not true if the HTLC did
not have a CSV delay attached (due to the above bug or due to it
being an HTLC claim by our counterparty).

This fixes both bugs, also converting some assertions to
`debug_assert`s to avoid future issues as balance mis-calculation
is not currently an indication of potential funds loss.

Thanks to Cash App for reporting this bug.
2022-03-01 00:43:55 +00:00
Matt Corallo
def0628332 Bump crate versions to 0.0.105/invoice 0.13 2022-03-01 00:43:24 +00:00
Matt Corallo
afc740056f Fill out CHANGELOG for 0.0.105 2022-03-01 00:43:24 +00:00
Matt Corallo
bd1b761655 Correct default value for A* heuristic for non-public nodes
This doesn't (appear) to change behavior, however if we have a
non-public node, we assign an A* heuristic of max-u32 fees, which
may result in us de-prioritizing the path in some rare cases around
multi-hop route hints which compete with public nodes.
2022-02-28 22:07:54 +00:00
Matt Corallo
19ebc8081a Fix panic when routing through multiple private last-hops
When we added support for routing through a multi-hop invoice hint
we failed to remove an assertion that we always are able to fill
in features for each hop except the last one. However, when a
multi-hop invoice hint is used, we will not have features for any
of the hinted hops, causing us to panic.
2022-02-28 22:07:54 +00:00
Arik Sosman
8219ae2439
Merge pull request #1327 from TheBlueMatt/2022-02-log-before-panic 2022-02-28 14:03:03 -08:00
Matt Corallo
5208f0c72a
Merge pull request #1303 from jkczyz/2022-02-docs-with-features
Generate docs with features for docs.rs
2022-02-28 21:00:05 +00:00
valentinewallace
219a4545be
Merge pull request #1335 from TheBlueMatt/2022-02-fix-honggfuzz-regression
Pin rustc in fuzzing to 1.58 due to honggfuzz-rs regression
2022-02-28 13:50:03 -05:00
Matt Corallo
99073c74dd
Merge pull request #1324 from valentinewallace/2022-02-phantom-followup
#1199 Followup
2022-02-28 18:16:21 +00:00
Matt Corallo
78174f349e
Merge pull request #1332 from TheBlueMatt/2022-02-persister-ignore-tmp
Ignore .tmp files when loading ChannelMonitors in persister
2022-02-26 01:30:29 +00:00
Matt Corallo
5da22534cd Pin rustc in fuzzing to 1.58 due to honggfuzz-rs regression 2022-02-25 22:09:30 +00:00
Valentine Wallace
694ef1ecb9
Fix bug where we encode flags field into all updates on htlc fail
Failing an HTLC with onion error channel_disabled requires encoding a 'flags' field into the failure
packet. However, we were encoding this 'flags' field for all failures packets that were failing on
update_add_htlc with an update (error 0x1000 UPDATE).

Discovered in the course of adding phantom payment failure tests, which also added testing for this bug
2022-02-24 22:33:35 -05:00
Valentine Wallace
26fe879896
Correctly wrap phantom onion errors
In any place where fail_htlc_backwards_internal was called for a phantom payment
failure, we weren't encoding the onion failure as if the phantom were the one
failing. Instead, we were encoding the failure as if it were coming from the
second-to-last hop. This caused our failures to not be parsed properly on the
payer's side.

Places we were encoding failures incorrectly include:
* on failure of a call to inbound_payment::verify
* on a user call to fail_htlc_backwards

Also drop some unnecessary panics when reading OnionHopData objects. This also
enables one of the phantom failure tests because we can construct OnionHopDatas
with invalid amounts.

Lastly, remove a bogus comment
2022-02-24 22:33:02 -05:00
Valentine Wallace
3faea33438
Fix phantom malformed onion error packet
Ensure we fail back phantom malformed payments with an update_fail_htlc s.t.
the error contains the sha256 of the onion, per LN protocol.
2022-02-24 22:33:02 -05:00
Valentine Wallace
f1aba79521
Add phantom shared secret to HTLCPreviousHopData
This also fixes a bug where we were failing back phantom payments with the
wrong scid, causing them to never actually be failed backwards (L3022 in
channelmanager.rs)

This new field will be used in upcoming commit(s) to encrypt phantom payment failure
packets.
2022-02-24 22:32:14 -05:00
Valentine Wallace
bafd141d2c
Add phantom shared secret to PendingHTLCRouting::Receive
This will be used in upcoming commit(s) to encrypt phantom payment failure packets.
2022-02-24 21:22:59 -05:00
Matt Corallo
4b77ce1959
Merge pull request #1318 from jurvis/jurvis/2022-02-log-router-penalty-data-4
Implement custom debug for PathBuildingHop
2022-02-24 19:50:51 +00:00
Matt Corallo
a2a90ee959 Ignore .tmp files when loading ChannelMonitors in persister
If we are in the middle of persisting an update to a
`ChannelMonitor` when we shutdown (or crash), we'll start up with
a .tmp file lying around. We should ignore it, as failure to
return from the update call should have prevented the
`ChannelManager` from taking any irrevocable action based on the
update.

We're somewhat protected from any filesystem inconsistency behavior
as the `ChannelManager` will refuse to load if we're outright
missing `ChannelMonitor`s.

Fixes #1330.
2022-02-24 19:09:44 +00:00
Jurvis Tan
a3c2dfdcbc
Implement custom debug for PathBuildingHop
Add other fields to log for PathBuildingHop

Use DebugStruct to print PathBuildingHop

Fix PathBuildingHop visibility

Add more useful fee print-outs

Remove Features<NodeContext> from hop print-out

Remove logging fields we don’t need

Add fields to log back to PathBuildingHop
2022-02-23 17:50:59 -08:00
valentinewallace
23f1ec80d3
Merge pull request #1309 from TheBlueMatt/2022-02-first-hop-log
Specify whether we have first-hop hints when routing
2022-02-22 12:23:32 -05:00
Valentine Wallace
1f6700c72d
Follow-up nits from #1199 (phantom node support) 2022-02-22 11:54:35 -05:00
Matt Corallo
040bf2284e Log more during ChannelMonitor updating
Fixes #1323.
2022-02-22 00:18:09 +00:00
Arik Sosman
e43cfe135a
Merge pull request #1314 from TheBlueMatt/2022-02-accept_chan_type
Update channel-type implementation to upstream spec as merged
2022-02-18 13:53:09 -08:00
Jeffrey Czyz
62b1e01ad9
Generate docs with features for docs.rs
Enable generating docs using --all-features or --features="std" where
applicable. Additionally, use doc_auto_cfg to tag items requiring a
feature.

https://doc.rust-lang.org/nightly/rustdoc/unstable-features.html#doc_auto_cfg-automatically-generate-doccfg

This requires building with nightly, which is what is used by docs.rs.

https://docs.rs/about/builds

To test locally, use:

RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc ...
2022-02-18 15:38:31 -06:00
Jeffrey Czyz
27101609c4
Fix rustdoc error on nightly 2022-02-18 15:35:58 -06:00
Jeffrey Czyz
63e3486e8d
Unhide struct docs in scoring module
The docs were hidden since a type alias should be used. However, the
alias docs don't contain much useful information and don't link to the
corresponding struct.
2022-02-18 15:34:07 -06:00
Jeffrey Czyz
6fb6994101
Fix cargo doc warning in lightning-block-sync 2022-02-18 15:34:07 -06:00
Matt Corallo
637e0d34ca Specify whether we have first-hop hints when routing
This is incredibly useful when debugging issues with the router,
and is somewhat of an oversight currently.
2022-02-18 19:20:18 +00:00
Matt Corallo
7ac4c3bba0
Merge pull request #1316 from TheBlueMatt/2022-02-no-fuzztarget
Drop `fuzztarget` feature entirely
2022-02-18 19:18:30 +00:00
Matt Corallo
b0cb5583b1 Add explicit compile errors when cfg=fuzzing is mis-set 2022-02-18 17:03:04 +00:00
Matt Corallo
acb4c539f7 Drop fuzztarget feature entirely
Some time ago we started transitioning to `cfg(fuzzing)` instead of
exposing a full feature. Here we complete the transition.
2022-02-18 17:03:04 +00:00
Matt Corallo
84c3f513ec
Merge pull request #1315 from TheBlueMatt/2022-02-fix-tokio-msrv
Restrict tokio to 1.14 as a dev-dependency
2022-02-17 19:51:13 +00:00
Matt Corallo
aca5b6934a Restrict tokio to 1.14 as a dev-dependency
This maintains our MSRV for simple `cargo test` runs, but doesn't
restrict users to any specific 1.X tokio version.
2022-02-17 17:47:13 +00:00
Matt Corallo
de1aca5ca2
Merge pull request #1266 from TheBlueMatt/2022-01-fix-double-fail-panic
Fix a debug panic caused by receiving MPP parts after a failure
2022-02-17 03:41:50 +00:00
Matt Corallo
be57e828b8 Fix a debug panic caused by receiving MPP parts after a failure
Prior to cryptographic payment secrets, when we process a received
payment in `process_pending_htlc_fowards` we'd remove its entry
from the `pending_inbound_payments` map and give the user a
`PaymentReceived` event.

Thereafter, if a second HTLC came in with the same payment hash, it
would find no entry in the `pending_inbound_payments` map and be
immediately failed in `process_pending_htlc_forwards`.

Thus, each HTLC will either result in a `PaymentReceived` event or
be failed, with no possibility for both.

As of 8464875555, we no longer
materially have a pending-inbound-payments map, and thus
more-than-happily accept a second payment with the same payment
hash even if we just failed a previous one for having mis-matched
payment data.

This can cause an issue if the two HTLCs are received back-to-back,
with the first being accepted as valid, generating a
`PaymentReceived` event. Then, when the second comes in we'll hit
the "total value {} ran over expected value" condition and fail
*all* pending HTLCs with the same payment hash. At this point,
we'll have a pending failure for both HTLCs, as well as a
`PaymentReceived` event for the user.

Thereafter, if the user attempts to fail the HTLC in response to
the `PaymentReceived`, they'll get a debug panic at channel.rs:1657
'Tried to fail an HTLC that was already failed'.

The solution is to avoid bulk-failing all pending HTLCs for a
payment. This feels like the right thing to do anyway - if a sender
accidentally sends an extra HTLC after a payment has ben fully
paid, we shouldn't fail the entire payment.

Found by the `chanmon_consistency` fuzz test.
2022-02-16 21:40:11 +00:00
Matt Corallo
6d7ae6e174 Update channel-type implementation to upstream spec as merged
Somehow, our channel type implementation doesn't echo back the
channel type as we believe it was negotiated, as we should. Though
the spec doesn't explicitly require this, some implementations may
require it and it appears to have been in the BOLTs from the start
of the channel type logic.
2022-02-16 21:34:16 +00:00
Matt Corallo
92556c868d Drop spurious whitespace in channel.rs 2022-02-16 21:12:22 +00:00
Jeffrey Czyz
8e7f241149
Merge pull request #1199 from valentinewallace/2021-11-phantom-node
Add support for multi-node receive
2022-02-15 15:43:10 -06:00
Valentine Wallace
710954f88b
Don't send channel updates for private chans on error
This commit also adds additional checks for the second-to-last (phantom) hop for phantom payments.
2022-02-14 14:25:55 -05:00
Valentine Wallace
c417a51b65
Support phantom payment receive in ChannelManager, with invoice util
See PhantomKeysManager and invoice util's create_phantom_invoice for more info
2022-02-14 14:25:53 -05:00
Valentine Wallace
410eb05365
Add get_phantom_scid and get_phantom_route_hints + scid_utils::fake_scid module
See method and module docs for more details
2022-02-14 14:22:38 -05:00
Valentine Wallace
70f7db9810
channelmanager: DRY PendingHTLCInfo creation for receives
Will be used to facilitate decoding multiple onion layers for phantom payment receive
2022-02-14 14:22:38 -05:00
Valentine Wallace
e1c33d49f0
scid_utils: add utils for retrieving txindex and vout 2022-02-14 14:22:38 -05:00