Commit graph

1741 commits

Author SHA1 Message Date
Matt Corallo
bb4413cc65 Make max_total_cltv_expiry_delta include the final CLTV
This fixes an integer underflow found by the `router` fuzz target
in CI.
2022-03-16 22:10:46 +00:00
Matt Corallo
fef8acf70c Make routing benchmark robust against path changes
If the scoring in the routing benchmark causes us to take a
different path from the original scan, we may end up deciding that
the only path to a node has a too-high total CLTV delta, causing us
to panic in the benchmarking phase.

Here we simply check for that possibility and remove paths that
fail post-scoring.
2022-03-16 22:10:46 +00:00
Matt Corallo
ea769427fe Generate a funding_locked on relevant transactions_confirmed calls
Previously, if we were offline when a funding transaction was
locked in, and then we came back online, calling
`best_block_updated` once followed by `transactions_confirmed`,
we'd not generate a funding_locked until the next
`best_block_updated`.

We address this by re-calling `best_block_updated` in
`transactions_confirmed`, similar to how `ChannelMonitor` works.
2022-03-15 23:59:35 +00:00
Jeffrey Czyz
ca163c3fae
Merge pull request #1331 from TheBlueMatt/2022-02-no-copy-invoice-fields
Use &mut self in invoice updaters, not take-self-return-Self
2022-03-11 14:26:02 -06:00
Matt Corallo
b1cd5a7434
Merge pull request #1311 from TheBlueMatt/2022-02-0conf-part-1
Support for SCID Aliases
2022-03-10 00:47:23 +00:00
valentinewallace
756bcbc667
Merge pull request #1341 from jkczyz/2022-03-expiry-time-panic
Correct docs about invoice_expiry_delta_secs panic
2022-03-09 18:19:22 -05:00
Matt Corallo
2bba1d4251
Merge pull request #1348 from TheBlueMatt/2022-03-timer-tick-count
Reduce the number of timer ticks a peer is allowed to take
2022-03-09 21:28:05 +00:00
Matt Corallo
eafe7d2e24
Merge pull request #1355 from lightningdevkit/dependabot/cargo/lightning/regex-0.2.11
Update regex requirement from 0.1.80 to 0.2.11 in /lightning
2022-03-09 21:27:50 +00:00
Jeffrey Czyz
f1a6469a0a
Correct docs about invoice_expiry_delta_secs panic 2022-03-09 14:39:31 -06:00
Matt Corallo
e4486fe9f4 Support receiving multiple funding_locked messages
As a part of adding SCID aliases to channels, we now have to accept
otherwise-redundant funding_locked messages which serve only to
update the SCID alias. Previously, we'd failt he channel as such
an update used to be bogus.
2022-03-09 19:14:39 +00:00
Matt Corallo
84fa127661 Provide our peers with SCID aliases and forward payments with them
This creates an SCID alias for all of our outbound channels, which
we send to our counterparties as a part of the `funding_locked`
message and then recognize in any HTLC forwarding instructions.

Note that we generate an SCID alias for all channels, including
already open ones, even though we currently have no way of
communicating to our peers the SCID alias for already-open
channels.
2022-03-09 19:14:39 +00:00
Matt Corallo
10be993f94 Handle short_to_id state updates on channel closure via macros
This avoids needing to update channel closure code in many places
as we add multiple SCIDs for each channel and have to track them.
2022-03-09 19:14:38 +00:00
Matt Corallo
b2629afd88 Track SCID aliases from our counterparty and use them in invoices
New `funding_locked` messages can include SCID aliases which our
counterparty will recognize as "ours" for the purposes of relaying
transactions to us. This avoids telling the world about our
on-chain transactions every time we want to receive a payment, and
will allow for receiving payments before the funding transaction
appears on-chain.

Here we store the new SCID aliases and use them in invoices instead
of he "standard" SCIDs.
2022-03-09 19:14:38 +00:00
Matt Corallo
f54ebf78f6 Add support for deserializing the new SCID alias in funding_locked 2022-03-09 19:14:38 +00:00
Matt Corallo
a274261c59 Clean up the handle_monitor_err!() macro argument forms somewhat
`handle_monitor_err!()` has a number of different forms depending
on which messages and actions were outstanding when the monitor
updating first failed. Instead of matching by argument count, its
much more readable to put an explicit string in the arguments to
make it easy to scan for the called form.
2022-03-09 19:14:38 +00:00
dependabot[bot]
ca96bb7fb6
Update regex requirement from 0.1.80 to 0.2.11 in /lightning
Updates the requirements on [regex](https://github.com/rust-lang/regex) to permit the latest version.
- [Release notes](https://github.com/rust-lang/regex/releases)
- [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/regex/compare/0.1.80...0.2.11)

---
updated-dependencies:
- dependency-name: regex
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-03-09 17:38:53 +00:00
Elias Rohrer
e92b5a7ebd Add a random per-path CLTV offset for privacy. 2022-03-09 11:13:47 -06:00
Jeffrey Czyz
1a734492d9
Merge pull request #1347 from jkczyz/2022-03-log-approximation
Use log approximation in ProbabilisticScorer
2022-03-09 10:19:25 -06:00
Matt Corallo
82bbb807ad Refactor debug sync methods into helper functions 2022-03-09 06:23:39 +00:00
Jeffrey Czyz
d70292d6c8
Fix compilation warnings with --features=no-std 2022-03-08 23:23:25 -06:00
Jeffrey Czyz
7f83c559b4
Use log approximation in ProbabilisticScorer
Since f64::log10 exists in std but not core, unconditionally use log
approximation so --feature=no-std will compile.
2022-03-08 23:22:38 -06:00
Matt Corallo
09f8abad93 Move private channel and short-conf tests to new module 2022-03-08 19:16:17 +00:00
Matt Corallo
3fe76e61a3 Add a new functional test utility to open an unannounced channel 2022-03-08 19:16:17 +00:00
Matt Corallo
a9c4e70213 Give ChannelManagers channel_udpates for pub chans in test
This makes tests slightly more realistic by delivering
`channel_update`s to `ChannelManager`s, ensuring we have
forwarding data stored locally for all channels, including public
ones.
2022-03-08 19:16:17 +00:00
Matt Corallo
252280d6bf Reduce the number of timer ticks a peer is allowed to take
In 2d3a210897, we increased the
default ping timer in `lightning-background-processor` to ten
seconds from five. However, we didn't change the timer count at
which we disconnect peers if they're not responding, which we
likely should have done. We do so here, as well as update the
documentation for `PeerManager::timer_tick_occurred` to suggest
always ticking the timer every ten seconds instead of five.
2022-03-07 19:07:14 +00:00
Matt Corallo
0e0aabea07
Merge pull request #1317 from TheBlueMatt/2022-02-fix-bunk-test
Fix what `bolt2_open_channel_sending_node_checks_part1` tests
2022-03-05 20:54:57 +00:00
Matt Corallo
6e776d9fb9 Clean up TestKeysInterface random bytes override interface
Its very confusing to have multiple fields that do the same thing,
one of which isn't even used for its stated purpose anymore after
the previous few commits.
2022-03-04 21:54:32 +00:00
Matt Corallo
010c34f351 Fix what bolt2_open_channel_sending_node_checks_part1 tests
There are currently two issues with
`bolt2_open_channel_sending_node_checks_part1` which counteract
each other and hide that the test isn't testing what it should be.

First of all, the final `create_channel` call actually fails
because we try to open a channel with ourselves, instead of
panicing as the test is supposed to check for.

However, when we fix the create_channel call to panic, when we
drop `nodes[1]` after `create_channel` panics, we fail the
no-pending-messages test as it as an expeted `accept_channel` in
its outbound buffer. This causes a double-panic.

Previously, these two offset each other - instead of panicing in
`create_channel` we'd panic in the Node drop checks.

This fixes both by fetching the `accept_channel` before we go into
the panic'ing `create_channel` call (who's arguments were
		corrected).
2022-03-04 21:54:21 +00:00
Matt Corallo
60f7977ea8 Add Clone to a few structs which contain only a few fields
Specifically, `PhantomRouteHints`, `FixedPenaltyScorer`, and
`ScoringParamters`.
2022-03-03 18:10:59 +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
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
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
Matt Corallo
99073c74dd
Merge pull request #1324 from valentinewallace/2022-02-phantom-followup
#1199 Followup
2022-02-28 18:16:21 +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
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
Matt Corallo
b7d57ea83e Use &mut self in invoice updaters, not take-self-return-Self
The take-self-return-Self idiom in Rust is substantially less
usable than it is in Java, where its more common. Because we have
to take self by move, it prevents using the update methods to
actually update features, something we occasionally want to do.

See, eg, the change in lightning-invoice where we previously had
to copy and re-create an entire vec of fields just to update the
features field, which is nuts.

There are a few places where this makes things a little less clean,
but the tradeoff to enable more effecient and broader uses of the
update methods seems worth it.
2022-02-23 20:17:36 +00: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