Commit graph

4254 commits

Author SHA1 Message Date
benthecarman
489b408520
Change WalletSource::sign_tx to sign_psbt 2023-12-11 17:17:19 -06:00
Matt Corallo
4b35697aff
Merge pull request #2637 from Sharmalm/2348
Improve block connection logging and filtered txids
2023-12-11 22:59:05 +00:00
Elias Rohrer
c9ea2cebee
Markup packages link as hyperlink 2023-12-11 19:52:24 +01:00
Elias Rohrer
79cff6ce9f
Remove unused chan_id 2023-12-11 19:50:46 +01:00
Elias Rohrer
17e829217e
Fix leftover rustdoc warnings
.. as these slipped in again.
2023-12-11 19:48:51 +01:00
Matt Corallo
e839d49f7b
Merge pull request #2681 from tnull/2023-10-bump-msrv-to-1.63.0
Bump MSRV to rustc 1.63.0
2023-12-11 18:31:30 +00:00
Lalitmohansharma1
f89d42cb79 Improving block conenction logging and filtered txids
Implement the Display trait for Outpoint and utilize it in the codebase for monitoring outpoints.
Additionally, add log tracing for best_block_update and confirmed transactions.
solves #2348
2023-12-11 20:59:46 +05:30
Matt Corallo
0c677533fc
Merge pull request #2752 from valentinewallace/2023-11-large-final-onion-payload-fixes
Large final onion payload fixes
2023-12-08 23:53:27 +00:00
Elias Rohrer
e94af0c341
Merge pull request #2774 from TheBlueMatt/2023-12-2551-followups
Doc and performance followups to #2551
2023-12-08 23:46:43 +01:00
Valentine Wallace
80ba9acd77
Error if onion payloads exceed max length on packet construction.
Ensure that if we call construct_onion_packet and friends where payloads are
too large for the allotted packet length, we'll fail to construct. Previously,
senders would happily construct invalid packets by array-shifting the final
node's HMAC out of the packet when adding an intermediate onion layer, causing
the receiver to error with "final payload provided for us as an intermediate
node."
2023-12-08 17:33:40 -05:00
Valentine Wallace
e9bd893447
Fix debug panic in onion utils on large custom TLVs or metadata.
We previously assumed that the final node's payload would be ~93 bytes, and had
code to ensure that the filler encoded after that payload is not all 0s. Now
with custom TLVs and metadata supported, the final node's payload may take up
the entire onion packet, so we can't assume that there are 64 bytes of filler
to check.
2023-12-08 17:33:38 -05:00
Matt Corallo
1171bc1913 Pre-calculate heap element scores (retaining RouteGraphNode size)
`RouteGraphNode` currently recalculates scores in its `Ord`
implementation, wasting time while sorting the main Dijkstra's
heap.

Further, some time ago, when implementing the `htlc_maximum_msat`
amount reduction while walking the graph, we added
`PathBuildingHop::was_processed`, looking up the source node in
`dist` each time we pop'ed an element off of the binary heap.
As a result, we now have a reference to our `PathBuildingHop` when
processing a best-node's channels, leading to several fields in
`RouteGraphNode` being entirely redundant.

Here we drop those fields, but add a pre-calculated score field,
as well as force a suboptimal `RouteGraphNode` layout, retaining
its existing 64 byte size.

Without the suboptimal layout, performance is very mixed, but with
it performance is mostly improved, by around 10% in most tests.
2023-12-08 20:45:06 +00:00
Matt Corallo
8ba3e83bb0 Reorder PathBuildingHop fields somewhat
Given `PathBuildingHop` is now an even multiple of cache lines, we
can pick which fields "fall off" the cache line we have visible
when dealing with hops, which we do here.
2023-12-08 20:45:06 +00:00
Matt Corallo
e2f34cb122 Make find_route's dist map elements fit in 128 bytes
We'd previously aggressively cached elements in the
`PathBuildingHop` struct (and its sub-structs), which resulted in a
rather bloated size. This implied cache misses as we read from and
write to multiple cache lines during processing of a single
channel.

Here, we reduce caching in `DirectedChannelInfo`, fitting the
`(NodeId, PathBuildingHop)` tuple in exactly 128 bytes. While this
should fit in a single cache line, it sadly does not generally lie
in only two lines, as glibc returns large buffers from `malloc`
which are very well aligned, plus 16 bytes (for its own allocation
tracking). Thus, we try to avoid reading from the last 16 bytes of
a `PathBuildingHop`, but luckily that isn't super hard.

Note that here we make accessing
`DirectedChannelInfo::effective_capacity` somewhat slower, but
that's okay as its only ever done once per `DirectedChannelInfo`
anyway.

While our routing benchmarks are quite noisy, this appears to
result in between a 5% and 15% performance improvement in the
probabilistic scoring benchmarks.
2023-12-08 20:45:06 +00:00
Matt Corallo
d0084c22d4 Make CandidateRouteHop::PrivateHop::target_node_id a reference
This avoids bloating `CandidateRouteHop` with a full 33-byte
node_id (and avoids repeated public key serialization when we do
multiple pathfinding passes).
2023-12-08 20:45:06 +00:00
Matt Corallo
2b7d097dc7 Simplify and make scoring calls in TestRouter more complete
`TestRouter` tries to make scoring calls that mimic what an actual
router would do, but the changes in f0ecc3ec73
failed to make scoring calls for private hints or if we take a
public hop for the last hop.

This fixes those regressions, though no tests currently depend on
this behavior.
2023-12-08 20:45:06 +00:00
Matt Corallo
6ae051694d Make CandidateRouteHop method docs somewhat more descriptive 2023-12-08 20:45:06 +00:00
Matt Corallo
e9bad1b95c Fix indentation in router.rs broken in a1d15ac192 2023-12-08 20:45:06 +00:00
Matt Corallo
cc4bc1df5a Rename CandidateRouteHop::FirstHop::node_id and make it a ref
Rather than calling `CandidateRouteHop::FirstHop::node_id` just
`node_id`, we should call it `payer_node_id` to provide more
context.

We also take this opportunity to make it a reference, avoiding
bloating `CandidateRouteHop`.
2023-12-08 20:45:06 +00:00
Matt Corallo
57857fd520 #[inline] CandidateRouteHop accessors
These are used in the performance-critical routing and scoring
operations, which may happen outside of our crate. Thus, we really
need to allow downstream crates to inline these accessors into
their code, which we do here.
2023-12-08 20:45:06 +00:00
Matt Corallo
fc44e84ca8 Fix new unused warnings in scoring.rs 2023-12-08 20:45:06 +00:00
Matt Corallo
99e4a1fbb6 Privatise CandidateRouteHop::short_channel_id as its a footgun
Short channel "ID"s are not globally unique when they come from a
BOLT 11 route hint or a first hop (which can be an outbound SCID
alias). In those cases, its rather confusing that we have a
`short_channel_id` method which mixes them all together, and even
more confusing that we have a `CandidateHopId` which is not, in
fact returning a unique identifier.

In our routing logic this is mostly fine - the cost of a collision
isn't super high and we should still do just fine finding a route,
however the same can't be true for downstream users, as they may or
may not rely on the apparent guarantees.

Thus, here, we privatise the SCID and id accessors.
2023-12-08 20:45:06 +00:00
Matt Corallo
2caccc5cd6 Fix and re-enable the remembers_historical_failures test
f0ecc3ec73 introduced a regression in
the `remembers_historical_failures` test, and disabled it by simply
removing the `#[test]` annotation. This fixes the test and marks it
as a test again.
2023-12-08 20:45:06 +00:00
Matt Corallo
98ed285b9c Rename DirectedChannelInfo::outbound to from_node_one
...to give a bit more readability on accessing sites.
2023-12-08 20:45:06 +00:00
Matt Corallo
9973331d8e Rewrite docs in CandidateRouteHop to be somewhat more descriptive 2023-12-08 20:45:06 +00:00
Valentine Wallace
df2d0a47d5
Add variant for non-intro-nodes to BlindedFailure enum
For use in supporting receiving to multi-hop blinded paths.
2023-12-08 14:33:40 -05:00
Valentine Wallace
2a46505815
Test successfully receiving to a multihop blinded path. 2023-12-08 14:33:40 -05:00
Valentine Wallace
51f41ce7ce
Support receiving to multi-hop blinded payment paths.
The only remaining step is to use the update_add blinding point in decoding
inbound onion payloads.

Error handling will be completed in upcoming commits.
2023-12-08 14:33:40 -05:00
Valentine Wallace
87a25c7a5b
Support parsing blinded non-intro onion receive payloads.
Support for receiving to multi-hop blinded payment paths will be completed in
the next commit, sans error handling.
2023-12-08 14:33:40 -05:00
Valentine Wallace
e1ed52fae7
Pass in update add blinding point on onion decode
Will be used to read encrypted_tlvs on non-intro-node onion receipt.
2023-12-08 14:33:40 -05:00
Wilmer Paulino
ec8e0fe478
Merge pull request #2760 from TheBlueMatt/2023-11-chan-close-loop
Fix infinite loop when closing a pre-funding channel
2023-12-08 10:16:12 -08:00
Elias Rohrer
ddf2509227
Bump MSRV to rustc 1.63.0 and edition to 2021
.. which is a reasonable common ground, also supported by Debian stable.
2023-12-08 14:03:45 +01:00
Jeffrey Czyz
1c4d3289ff
Return correct SendSuccess in OnionMessenger
When enqueuing a message for a node already awaiting a connection,
BufferedAwaitingConnection should be returned when a node is not yet
connected as a peer. However, it was only returned when the first
message was enqueued. Any messages enqueued after but before a
connection was established incorrectly returned Buffered.
2023-12-07 23:44:47 -06:00
Jeffrey Czyz
be618bb7b5
Rename OnionMessagePath::addresses
The name itself doesn't provide much meaning to what the addresses
correspond to.
2023-12-07 23:44:41 -06:00
Jeffrey Czyz
5892fd698e
Fix create_onion_message return type documentation 2023-12-07 22:25:25 -06:00
Matt Corallo
5ba4c079bb Immediately error in close_channel_internal if there is no chan
Previously, unfunded channels would be stored outside of
`PeerState::channel_by_id`, and thus if there is no channel when
we look in `PeerState::channel_by_id`, `close_channel_internal`
called `force_close_channel_with_peer` to hunt for unfunded
channels.

However, that is no longer the case, so the call is redundant, and
we can simply return an error instead.
2023-12-08 02:26:00 +00:00
Matt Corallo
3a2690c8aa Move pre-funded-channel immediate shutdown logic to the right place
Because a `Funded` `Channel` cannot possibly be pre-funding, the
logic in `ChannelManager::close_channel_internal` to handle
pre-funding channels is in the wrong place.

Rather than being handled inside the `Funded` branch, it should be
in an `else` following it, handling either of the two
`ChannelPhases` outside of `Funded`.

Sadly, because of a previous control flow management `loop {}`, the
existing code will infinite loop, which is fixed here.
2023-12-08 02:26:00 +00:00
Matt Corallo
1667b4d200 Drop unreachable shutdown code in Channel::get_shutdown
`Channel` is only a thing for funded channels. Thus, checking if a
channel has not yet been funded is dead code and can simply be
elided.
2023-12-08 02:25:59 +00:00
Matt Corallo
8e519b56d6 Limit the scope of get_funding_created_msg to outbound channels
Since we no longer use `ChannelContext::get_funding_created_msg`,
it can be moved back into `UnfundedOutboundV1` channels only,
where it realistically belongs.
2023-12-08 02:22:03 +00:00
Matt Corallo
6ab56a40be Move to Funded after funding_signed rather than on funding
Previously, channels were stored in different maps in `PeerState`
based on whether the funding had been set, keeping the keys across
the maps consistent (pre-funding temporary_channel_ids vs
funding-outpoint-based channel_ids). However, channels are now
stored in a single `channel_by_id` map, making that point moot.

Instead, here, we convert the `ChannelPhase` state transition
boundary to "once we have a `ChannelMonitor`", which makes more
sense now, and was actually the original proposed boundary.

This also requires calling `signer_maybe_unblocked` on a pre-funded
outbound channel, but that nicely also lets us limit the scope of
`FundingCreated` message generation, which we do in the next
commit.
2023-12-08 02:22:03 +00:00
Matt Corallo
2d266794c2
Merge pull request #2723 from jkczyz/2023-11-direct-connect
Direct connect for `OnionMessage` sending
2023-12-08 01:39:13 +00:00
Matt Corallo
61994066f8
Merge pull request #2691 from wpaulino/refactor-channel-state
Refactor ChannelState to decouple state flags from states
2023-12-07 23:59:13 +00:00
Wilmer Paulino
6492cc90ea
Rename certain flags to align with dual funding
`FundingCreated` and `FundingSent` were mostly named after the
respective `funding_created` and `funding_sent` wire messages. They
include the signature for the initial commitment transaction when
opening a channel. With dual funding, these messages are no longer used,
and instead we rely on the existing `commitment_signed` to exchange
those signatures.
2023-12-07 12:37:18 -08:00
Jeffrey Czyz
0b83116436
Rename OnionMessageBuffer to OnionMessageRecipient 2023-12-06 14:45:24 -06:00
Jeffrey Czyz
d46519bbd0
Remove superfluous space from where clause 2023-12-06 14:45:24 -06:00
Jeffrey Czyz
89e630b918
Test pending connection onion message buffering
Add tests for onion message buffering checking that messages are cleared
upon disconnection and timed out after MAX_TIMER_TICKS. Also, checks
that ConnectionNeeded events are generated.
2023-12-06 14:45:18 -06:00
Jeffrey Czyz
210407e1bb
Reuse MessengerNode in spec_test_vector
Additional tests will be added needing a similar node struct, so
consolidate its usage.
2023-12-06 14:43:39 -06:00
Jeffrey Czyz
6ca81ff2bb
Process OnionMessageHandler events in background
OnionMessageHandler implementations now also implement EventsProvider.
Update lightning-background-processor to also process any events the
PeerManager's OnionMessageHandler provides.
2023-12-06 14:43:39 -06:00
Matt Corallo
fcf47a429c
Merge pull request #2765 from TheBlueMatt/2023-12-2314-cleanups-1
Post-#2314 Cleanups
2023-12-06 20:37:06 +00:00
Jeffrey Czyz
cfaa7f3617
Drop buffered messages for timed out nodes
OnionMessenger buffers onion messages for nodes that are pending a
connection. To prevent DoS concerns, add a timer_tick_occurred method to
OnionMessageHandler so that buffered messages can be dropped. This will
be called in lightning-background-processor every 10 seconds.
2023-12-06 14:25:31 -06:00