Commit graph

100 commits

Author SHA1 Message Date
Matt Corallo
a82067d359
Merge pull request #1013 from TheBlueMatt/2021-07-warning-msgs 2022-01-11 22:52:44 +00:00
Matt Corallo
e137cfb3c4 Send warning messages when appropriate in gossip handling pipeline 2022-01-11 19:48:20 +00:00
Matt Corallo
3ca63426f9
Merge pull request #1220 from TheBlueMatt/2021-12-stale-update-gossip-log
Log gossip rejections due to stale channel_updates at GOSSIP level
2022-01-03 19:54:20 +00:00
Matt Corallo
d5a1435905 Log gossip rejections due to stale channel_updates at GOSSIP level
This further reduces noise at the TRACE level during initial gossip
sync.
2021-12-19 20:13:38 +00:00
Matt Corallo
d26469a77a Add a C-not exported tag to NetGraphMsgHandler.network_graph 2021-12-18 20:20:23 +00:00
Matt Corallo
73e8dc41a6 Automatically prune NetworkGraph of stale channels hourly in BP 2021-12-16 18:33:24 +00:00
Matt Corallo
cd43ff4a5e Reject channel_update messages with timestamps too old or new
Because we time out channel info that is older than two weeks now,
we should also reject new channel info that is older than two
weeks, in addition to rejecting future channel info.
2021-12-16 18:33:24 +00:00
Matt Corallo
4677e14c00 Add a method to prune stale channels from NetworkGraph
We define "stale" as "haven't heard an updated channel_update in
two weeks", as described in BOLT 7.

We also filter out stale channels at write-time for `std` users, as
we can look up the current time.
2021-12-16 18:33:24 +00:00
Matt Corallo
11d644824e DRY up network_graph tests substantially with message creation fns 2021-12-16 18:33:24 +00:00
Matt Corallo
0fe2aef0e6 Add a comment describing the timestamp field's use 2021-12-09 03:49:50 +00:00
Matt Corallo
391fbfbe1a Re-broadcast our own gossip even if its same as the last broadcast
Even if our gossip hasn't changed, we should be willing to
re-broadcast it to our peers. All our peers may have been
disconnected the last time we broadcasted it.
2021-11-23 22:18:00 +00:00
Elias Rohrer
3b4b74bc66 Add a new log-level for gossip messages. 2021-11-22 18:19:08 +01:00
Jeffrey Czyz
c4d7b9d50f
Make NetGraphMsgHandler::network_graph private
Since NetworkGraph has shared ownership, NetGraphMsgHandler does not
need to expose its field.
2021-11-01 15:01:39 -05:00
Jeffrey Czyz
bcdd852279
Parameterize NetGraphMsgHandler with NetworkGraph
NetworkGraph is owned by NetGraphMsgHandler, but DefaultRouter requires
a reference to it. Introduce shared ownership to NetGraphMsgHandler so
that both can use the same NetworkGraph.
2021-11-01 13:14:14 -05:00
Jeffrey Czyz
73f601fd3d
Add PaymentId to PaymentPathFailed event
The PaymentId is needed when retrying payments. Include it in the
PaymentPathFailed event so it can be used in that manner.
2021-10-26 01:12:30 -05:00
Jeffrey Czyz
46b68c517d
Include PaymentPathRetry data in PaymentPathFailed
When a payment path fails, it may be retried. Typically, this means
re-computing the route after updating the NetworkGraph and channel
scores in order to avoid the failing hop. The last hop in
PaymentPathFailed's path field contains the pubkey, amount, and CLTV
values needed to pass to get_route. However, it does not contain the
payee's features and route hints from the invoice.

Include the entire set of parameters in PaymentPathRetry and add it to
the PaymentPathFailed event. Add a get_retry_route wrapper around
get_route that takes PaymentPathRetry. This allows an EventHandler to
retry failed payment paths using the payee's route hints and features.
2021-10-25 10:18:11 -05:00
Matt Corallo
2144166bc6
Merge pull request #1115 from TheBlueMatt/2021-10-expose-addr-vec
Expose ReadOnlyNetworkGraph::get_addresses to C by cloning result
2021-10-13 16:54:09 +00:00
Matt Corallo
d2b7f6cc08 Expose ReadOnlyNetworkGraph::get_addresses to C by cloning result
We cannot expose ReadOnlyNetworkGraph::get_addresses as is in C as
it returns a list of references to an enum, which the bindings
dont support. Instead, we simply clone the result so that it
doesn't contain references.
2021-10-13 01:18:43 +00:00
Matt Corallo
fe8c10db95
Merge pull request #1077 from jkczyz/2021-09-failing-route-hop
Include short channel id in PaymentPathFailed
2021-10-13 01:13:41 +00:00
Jeffrey Czyz
202acd9e16
Add failing short channel id to PaymentPathFailed
This will be useful for scoring channels when a payment fails.
2021-10-12 18:40:06 -05:00
Duncan Dean
fce631ca21
Replace PublicKey with [u8; 33] in NetworkGraph 2021-10-08 18:37:55 +02:00
Matt Corallo
6c569d82b0 Make NetworkGraph Clone-able again
There isn't a lot of user-utility for cloning `NetworkGraph`
directly (its a rather large struct, and there probably isn't a lot
of reason to have *multiple* `NetworkGraph`s). Thus, when locks
were pushed down into it, the `Clone`-ability of it was dropped as
well.

Sadly, mapping the Java memory model onto:
 * `Read`-ing a `NetworkGraph`, creating a Java-owned
   `NetworkGraph` object that the JVM will destruct for us,
 * Passing it to a `NetGraphMsgHandler`, which now expects to own
   the `NetworkGraph`, including destructing it,
isn't really practical without adding a clone in between.

Given this, and the fact that there's nothing inherently wrong with
clone-ing a `NetworkGraph`, we simply re-add `Clone` here.
2021-09-26 04:31:29 +00:00
Valentine Wallace
e5310dd5f0
Add path field to PaymentPathFailed event 2021-09-21 17:40:09 -04:00
Valentine Wallace
bf16dfd153
Rename PaymentFailed -> PaymentPathFailed
Since we don't want to imply to users that a payment has
completely failed when it really has just partially
failed
2021-09-21 17:39:40 -04:00
Valentine Wallace
c828ff42c0
Add all_paths_failed field to PaymentFailed
see field docs for details
2021-09-17 15:36:27 -04:00
Jeffrey Czyz
ba2c00b3f8
EventHandler for applying NetworkUpdate
PaymentFailed events contain an optional NetworkUpdate describing
changes to the NetworkGraph as conveyed by a node along a failed payment
path according to BOLT 4. An EventHandler should apply the update to the
graph so that future routing decisions can account for it.

Implement EventHandler for NetGraphMsgHandler to update NetworkGraph.
Previously, NetGraphMsgHandler::handle_htlc_fail_channel_update
implemented this behavior.
2021-09-15 11:50:31 -05:00
Jeffrey Czyz
eff9a47075
Refactor PaymentFailureNetworkUpdate event
MessageSendEvent::PaymentFailureNetworkUpdate served as a hack to pass
an HTLCFailChannelUpdate from ChannelManager to NetGraphMsgHandler via
PeerManager. Instead, remove the event entirely and move the contained
data (renamed NetworkUpdate) to Event::PaymentFailed to be processed by
an event handler.
2021-09-15 11:50:27 -05:00
Jeffrey Czyz
798cf6ea83
Add a read-only view of NetworkGraph
Hide the internal locking of NetworkGraph by providing a read-only
view. This way the locking order is handled internally.
2021-09-09 23:11:12 -05:00
Jeffrey Czyz
16ad7f17a1
Remove RwLock from around NetworkGraph
Now that NetworkGraph uses interior mutability, the RwLock used around
it in NetGraphMsgHandler is no longer needed. This allows for shared
ownership without a lock.
2021-09-09 23:11:09 -05:00
Jeffrey Czyz
777661ae52
Individually lock NetworkGraph fields
In preparation for giving NetworkGraph shared ownership, wrap individual
fields in RwLock. This allows removing the outer RwLock used in
NetGraphMsgHandler.
2021-09-09 23:01:28 -05:00
Matt Corallo
75f7af64f3 Implement core:#️⃣:Hash more incl invoice::RawTaggedField 2021-08-31 21:29:51 +00:00
Devrandom
0dfcacd22c Actual no_std support 2021-08-03 09:34:56 +02:00
Devrandom
002a5db5b0 Collect all lightning std::sync imports under crate::sync
in preparation for no-std sync dummies
2021-07-19 15:01:58 +02:00
Matt Corallo
96a738aa53
Merge pull request #961 from TheBlueMatt/2021-06-workaround-broken-cln
Use the query start block for ReplyChannelRange response messages
2021-07-08 14:51:47 +00:00
Matt Corallo
42f6a8f111 Use the query start block for ReplyChannelRange response messages
C-Lightning versions prior to 0.10 (incorrectly) enforce that the
reply_channel_range first_blocknum field is set to at least the
value they sent in their query_channel_range message. Sending a 0
results in them responding with an Error message, closing open
channels spuriously.

Further, C-Lightning versions prior to 0.10 require that the
reply_channel_range first_blocknum is either the same block implied
as the last block of the previous reply_channel_range or one
greater. This is not only a creative interpretation of the spec,
but a perfectly reasonable implementation might still receive an
Error message in the case of replies split by an empty block.

This code is extracted and modified from a previous version of
the original query_channel_range PR in commit
44ba52ccf1. The original commit is by
`bmancini55 <bmancini@gmail.com>`.
2021-07-08 14:05:32 +00:00
Matt Corallo
f4729075cb
Merge pull request #965 from TheBlueMatt/2021-06-log-cleanups
Cleanup logging
2021-06-29 20:13:50 +00:00
Matt Corallo
1f592b045f Do not log_debug when we receive duplicate gossip messages
We very often receive duplicate gossip messages, which now causes us
to log at the DEBUG level, which is almost certainly not what a
user wants. Instead, we add a new form of ErrorAction which causes
us to only log at the TRACE level.
2021-06-29 19:36:47 +00:00
Valentine Wallace
40959b74b7
Fix TLV serialization to work with large types.
Previous to this PR, TLV serialization involved iterating from 0 to the highest
given TLV type. This worked until we decided to implement keysend, which has a
TLV type of ~5.48 billion.

So instead, we now specify the type of whatever is being (de)serialized (which
can be an Option, a Vec type, or a non-Option (specified in the serialization macros as "required").
2021-06-24 16:25:31 -04:00
Matt Corallo
c5a6135edc log_debug information about network graph updates from payments 2021-06-23 01:35:26 +00:00
Matt Corallo
c7113bcd92 Add benchmark of deserializing a NetworkGraph.
NetworkGraph is one of the largest structures we generally
deserialize, so it makes for a good benchmark, even if it isn't the
most complicated one.

As of this commit, on an Intel 2687W v3, these benchmarks take:

test routing::network_graph::benches::read_network_graph  ... bench: 2,101,420,078 ns/iter (+/- 6,649,020)
test routing::network_graph::benches::write_network_graph ... bench: 344,696,835 ns/iter (+/- 229,061)
2021-06-01 15:47:01 +00:00
Matt Corallo
df829a8526
Merge pull request #928 from TheBlueMatt/2021-05-really-tlv-ser
Migrate some inner structs to TLVs
2021-05-27 23:05:47 +00:00
Matt Corallo
321b19c4d9 Move NetworkGraph inner structs to TLV storage 2021-05-27 21:41:07 +00:00
Gene Ferneau
12461fcba1
Use alloc for no_std builds
Replace std structs with alloc equivalents to support no_std builds

f use prelude::* credit @devrandom
2021-05-27 17:35:20 +00:00
Matt Corallo
5b59178f89 Add version and TLV suffix for more user-facing "major" structs 2021-05-25 20:06:45 +00:00
Gene Ferneau
ec3739b7a2
Use core replacements for std members
In preparation for no_std build support, replace std structs and
functions with core equivalents
2021-05-23 23:48:27 +00:00
Devrandom
ec35fe62a1 Remove Send and Sync from core crate 2021-04-29 21:07:28 +02:00
bmancini55
7b842b61f8 Simplify sequencing of handle_query_channel_range
Modify NetGraphMsgHandler::handle_query_channel_range to always use
first_blocknum=0 in replies. This is spec compliant after changes to
make sequence completion explicity using sync_complete.
2021-03-16 19:36:38 -04:00
bmancini55
7815965bf7 Comment cleanup for handling query_channel_range
Cleans up NetGraphMsgHandler::handle_query_channel_range
2021-03-16 19:36:30 -04:00
bmancini55
f4adb9f013 Use constant MAX_REPLY_SCID
Modifies NetGraphMsgHandler::handle_query_channel_range to use a constant
max value in replies. Modifies tests to generate 8000 channels instead
of making this value configurable.
2021-03-13 14:51:36 -05:00
bmancini55
deffb4a3d8 Clean up iteration in handle_query_channel_range
Refactor to use an enumerator in NetGraphMsgHandler::handle_query_channel_range
2021-03-09 16:30:52 -05:00