Commit Graph

290 Commits

Author SHA1 Message Date
Elias Rohrer
f2453b7fff
Allow events processing without holding total_consistency_lock
Unfortunately, the RAII types used by `RwLock` are not `Send`, which is
why they can't be held over `await` boundaries. In order to allow
asynchronous events processing in multi-threaded environments, we here
allow to process events without holding the `total_consistency_lock`.
2023-04-21 18:02:54 +02:00
Valentine Wallace
d5b05e54c3
Replace Vec<RouteHop> with new Path struct
This lays groundwork for adding blinded path info to Path
2023-04-21 11:48:27 -04:00
Elias Rohrer
b5468226cc
Fix BP prune timer and don't panic on persistence notification failure 2023-04-21 11:44:36 +02:00
Arik
74328bd6e7
Merge pull request #2161 from benthecarman/prune-stale-channels-rgs
Prune stale channels from network graph after RGS sync.
2023-04-07 23:26:19 -07:00
Wilmer Paulino
5037298361
Use signal for handling ChannelPending in test_background_event_handling
This fixes two potential panics within the test if the
`BackgroundProcessor` for `nodes[0]` consumed the `ChannelPending` event
prior to us consuming it manually in `end_open_channel`. The first panic
would happen within the event handler, since `ChannelPending` was not
being handled. The second panic would happen upon expecting the
`ChannelPending` event after handling `nodes[1]`'s `funding_signed` if
the `BackgroundProcessor` handled the event first. To ensure we still
reliably receive a `ChannelPending` event once possible, we let the
`BackgroundProcessor` consume the event and notify it.
2023-04-06 15:10:12 -07:00
benthecarman
cff1b4bce3
Prune stale channels from network graph after RGS sync 2023-04-06 14:09:13 -05:00
Matt Corallo
068d2c65cb Add an async version of BP's test_channel_manager_persist_error
This gives us coverage of an async BP returning an error.
2023-04-04 20:59:56 +00:00
Matt Corallo
2bc55b22d3 Make BP's not_pruning_network_graph_until... test dual async-sync 2023-04-04 20:59:56 +00:00
Matt Corallo
f0b928b06d Make BP's test_payment_path_scoring dual sync/async.
This finally gives us a bit of test coverage of the async BP, which
was embarrassingly missing until now.
2023-04-04 20:59:56 +00:00
Matt Corallo
ca367f5d08 Ensure background-processor exits after any sleep future says to
If the user's sleep future passed to an async background processor
only returns true for exiting once and then reverts back to false,
we should exit anyway when we get a chance to. We do to this here
by always ensuring we check the exit flag even when only polling
sleep futures with no intent to (yet) exit. This is utilized in the
tests added in the coming commit(s).
2023-04-04 20:59:56 +00:00
Matt Corallo
8676c5aa4e Don't immediately exit BP if ChannelManager is persistable
If `ChannelManager` is persistable before the async background
processor even starts, it may not even get around to overwriting
the `should_exit` flag before testing it, and the default value is
(incorrectly) true, causing an immediate unconditional exit.

The default value should simply be false.

Fixes #2140
2023-04-04 20:59:56 +00:00
Matt Corallo
fcf1282975 Make lightning-background-processor test failures more debugable
Instead of asserting a `Result` `is_ok`, we should always simply
`unwrap` to get a backgrace, and we should avoid doing so if the
thread is already panicking.
2023-04-04 20:59:56 +00:00
Matt Corallo
3b8bf93251
Merge pull request #2090 from TheBlueMatt/2023-03-mon-wake-bp
Wake background-processor on async monitor update completion
2023-04-03 20:12:46 +00:00
Elias Rohrer
9873c7dad8
Add ChannelPending event emitted upon funding_signed
Currently, users don't have good way of being notified when channel open
negotiations have succeeded and new channels are pending confirmation on
chain. To this end, we add a new `ChannelPending` event that is emitted
when send or receive a `funding_signed` message, i.e., at the last
moment before waiting for the confirmation period.

We track whether the event had previously been emitted in `Channel` and
remove it from `internal_funding_created` entirely. Hence, we now
only emit the event after ChannelMonitorUpdate completion, or upon
channel reestablish. This mitigates a race condition where where we
wouldn't persist the event *and* wouldn't regenerate it on restart,
therefore potentially losing it, if async CMU wouldn't complete before
ChannelManager persistence.
2023-04-03 19:04:32 +02:00
Matt Corallo
94a11f7791 Expose an option to substantially reduce sleep time in futures BP
Some users have suggested that waking every 100ms can be
CPU-intensive in deployments with hundreds or thousands of nodes
all running on the same machine. Thus, we add an option to the
futures-based `background-processor` to avoid waking every 100ms to
check for iOS having backgrounded our app and cut our TCP sockets.

This cuts the normal sleep time down from 100ms to 10s, for those
who turn it on.
2023-04-03 16:49:54 +00:00
Matt Corallo
6890e43342 Wake the background processor if an async monitor update completes
If the `ChainMonitor` gets an async monitor update completion, this
means the `ChannelManager` needs to be polled for event processing.
Here we wake it using the new multi-`Future`-await `Sleeper`, or
the existing `select` block in the async BP.

Fixes #2052.
2023-04-03 16:49:54 +00:00
Matt Corallo
efcb5e02dc Move the pub wait methods from ChannelManager to Future
Rather than having three ways to await a `ChannelManager` being
persistable, this moves to just exposing the awaitable `Future` and
having sleep functions on that.
2023-04-03 16:49:54 +00:00
Matt Corallo
491100d8e5 Remove futures dependency in lightning-background-processor
As `futures` apparently makes no guarantees on MSRVs even in patch
releases we really can't rely on it at all, and while it currently
has an acceptable MSRV without the macros feature, its best to just
remove it wholesale.

Luckily, removing it is relatively trivial, even if it requires
the most trivial of unsafe tags.
2023-03-31 00:05:24 +00:00
Matt Corallo
54a51f8554 Replace futures select with our own select enum to fix MSRV
`futures` recently broke our MSRV by bumping the `syn` major
version in a patch release. This makes it impractical for us to
use, instead here we replace the usage of its `select_biased` macro
with a trivial enum.

Given its simplicity we likely should have done this without ever
taking the dependency.
2023-03-31 00:01:40 +00:00
Matt Corallo
2d4bf974e5
Merge pull request #2083 from wpaulino/events-module
Move events.rs into its own top-level module
2023-03-28 16:37:55 +00:00
Wilmer Paulino
ca9ca75f08
Move events.rs into its own top-level module
This is largely motivated by some follow-up work for anchors that will
introduce an event handler for `BumpTransaction` events, which we can
now include in this new top-level `events` module.
2023-03-22 11:49:33 -07:00
munjesi
b0bf50fa24 Replacing (C-not exported) in the docs 2023-03-22 14:30:36 +03:00
Valentine Wallace
753e4ce3c3
Remove PaymentPathFailed::retry
We now support automatic retries in ChannelManager and no longer support manual
retries, so the field is useless.
2023-03-13 11:59:03 -04:00
Matt Corallo
2e90ca11ca
Merge pull request #2081 from TheBlueMatt/2023-03-future-poll-panic 2023-03-08 15:49:43 +00:00
Matt Corallo
1751f77edf Avoid polling completed futures in the background-processor
`poll`ing completed futures invokes undefined behavior in Rust
(panics, etc, obviously not memory corruption as its not unsafe).
Sadly, in our futures-based version of
`lightning-background-processor` we have one case where we can
`poll` a completed future - if the timer for the network graph
prune + persist completes without a network graph to prune +
persist we'll happily poll the same future over and over again,
likely panicing in user code.
2023-03-07 18:06:12 +00:00
Matt Corallo
ccac926671
Merge pull request #2049 from douglaz/run-clippy-fix
Run clippy fix
2023-03-06 21:28:38 +00:00
Allan Douglas R. de Oliveira
57017dfc0b Run clippy --fix and cleanup code 2023-03-06 19:26:48 +00:00
Matt Corallo
a361be3544 Update crate versions to 0.0.114/invoice 0.22 2023-03-04 00:06:46 +00:00
Jeffrey Czyz
1d1323a3d0
Fix build warnings 2023-03-03 14:23:18 -06:00
Matt Corallo
d2f5dc01d1 Add some basic logging to Rapid Gossip Sync processing 2023-02-28 17:56:16 +00:00
Matt Corallo
a0c65c32a5
Merge pull request #2043 from valentinewallace/2023-02-initial-send-path-fails
`PaymentPathFailed`: add initial send error details
2023-02-27 18:10:27 +00:00
Matt Corallo
16b3c720a6
Merge pull request #2025 from TheBlueMatt/2023-02-no-pub-genesis-hashes
Remove genesis block hash from public API
2023-02-27 17:50:22 +00:00
Valentine Wallace
1dcb3ecb6c
Change PaymentPathFailed's optional network update to a Failure enum
This let us capture the errors when we fail without committing to an HTLC vs
failing via update_fail.
2023-02-25 16:13:42 -05:00
Valentine Wallace
2037a241f4
Remove all_paths_failed from PaymentPathFailed
This field was previous useful in manual retries for users to know when all
paths of a payment have failed and it is safe to retry. Now that we support
automatic retries in ChannelManager and no longer support manual retries, the
field is no longer useful.

For backwards compat, we now always write false for this field. If we didn't do
this, previous versions would default this field's value to true, which can be
problematic because some clients have relied on the field to indicate when a
full payment retry is safe.
2023-02-24 14:21:08 -05:00
Allan Douglas R. de Oliveira
19ef2bb6ac Only import lightning::io if futures are enabled 2023-02-24 02:56:11 +00:00
Matt Corallo
d7c818a3ad Rename BestBlock::from_genesis to from_network for clarity 2023-02-24 00:22:58 +00:00
Matt Corallo
2c3e12e309 Remove genesis block hash from public API
Forcing users to pass a genesis block hash has ended up being
error-prone largely due to byte-swapping questions for bindings
users. Further, our API is currently inconsistent - in
`ChannelManager` we take a `Bitcoin::Network` but in `NetworkGraph`
we take the genesis block hash.

Luckily `NetworkGraph` is the only remaining place where we require
users pass the genesis block hash, so swapping it for a `Network`
is a simple change.
2023-02-24 00:22:58 +00:00
Matt Corallo
4155f54716 Add an inbound flag to the peer_connected message handlers
Its useful for the message handlers to know if a peer is inbound
for DoS decision-making reasons.
2023-02-21 22:00:42 +00:00
Arik Sosman
2f36c921b6
Throw error for RGS data that's more than two weeks old, fixing #1785 2023-02-16 12:17:42 -08:00
Matt Corallo
51a3353740 Move chain::Access to routing and rename it UtxoLookup
The `chain::Access` trait (and the `chain::AccessError` enum) is a
bit strange - it only really makes sense if users import it via the
`chain` module, otherwise they're left with a trait just called
`Access`. Worse, for bindings users its always just called
`Access`, in part because many downstream languages don't have a
mechanism to import a module and then refer to it.

Further, its stuck dangling in the `chain` top-level mod.rs file,
sitting in a module that doesn't use it at all (it's only used in
`routing::gossip`).

Instead, we give it its full name - `UtxoLookup` (and rename the
error enum `UtxoLookupError`) and put it in the a new
`routing::utxo` module, next to `routing::gossip`.
2023-02-08 23:54:00 +00:00
Valentine Wallace
b28bfd382b
Remove InvoicePayer and replace with util methods 2023-02-06 16:28:23 -05:00
Valentine Wallace
2f9c3e5ea1
Score payment paths in BackgroundProcessor 2023-02-03 11:25:20 -05:00
Valentine Wallace
5aea2cf02b
Use TestScorer in BackgroundProcessor testing 2023-02-03 11:19:46 -05:00
Wilmer Paulino
acd2ae606d
Remove NodeSigner::get_node_secret
Secrets should not be exposed in-memory at the interface level as it
would be impossible the implement it against a hardware security
module/secure element.
2023-01-18 17:23:25 -08:00
Wilmer Paulino
19c4468bfc
Sign gossip messages with NodeSigner 2023-01-18 17:23:22 -08:00
Matt Corallo
c86950d510
Merge pull request #1962 from TheBlueMatt/2023-01-bp-no-std
Use the user-provided `SleepFuture` for interval checks in `background-processor`
2023-01-17 23:48:48 +00:00
Matt Corallo
e1b58a810f
Merge pull request #1960 from tnull/2023-01-deref-router-in-invoicepayer
Make `InvoicePayer`'s `Router` `Deref`
2023-01-17 23:21:22 +00:00
Matt Corallo
aa4c6f6418 Make background-processor no-std-friendly (ish)
This makes `background-processor` build without `std` at all. This
isn't particularly useful in the general no-std case as
`background-processor` is only useful with the `futures` feature,
and async will generally need `std` in some way or another. Still,
it ensures we don't end up reintroducing a dependency on the
current time, which breaks `wasm` use-cases.
2023-01-17 20:38:07 +00:00
Matt Corallo
e59b3847a3 Use the user-provided SleepFuture for interval checks in BP
`background-processor` does a number of jobs on various timers.
Instead of doing those by interrogating `std::time::Instant`, this
change swaps to using the existing user-provided sleep future.

Fixes #1864.
2023-01-17 00:26:21 +00:00
Matt Corallo
d308710d4f Use flexible timer types in background processor's regular jobs
`background-processor` does a number of jobs on various timers.
Currently, those are all done by checking the timers every 100ms
by interrogating `std::time::Instant`. This is fine for the
threaded version, but we'd like more flexibility in the `futures`-
based `background-processor`.

Here we swap the `std::time::Instant` interrogation for a lambda
which we will switch out to the user-provided sleeper in the next
commit.
2023-01-17 00:03:35 +00:00
Elias Rohrer
bc8e1e51e9
Make InvoicePayer's Router Deref
As of HEAD the `ChannelManager` is parametrized by a `Router`, while
`InvoicePayer` also owns a `Router`. In order to allow for a single
object being reused, we make the `InvoicePayer` side `Deref`.
2023-01-16 16:54:53 -06:00
Daniel Granhão
bcf174034a
Stop passing InitFeatures in msg handlers 2023-01-16 21:18:53 +00:00
Wilmer Paulino
abf4e79dcd
Use UserConfig to determine advertised InitFeatures by ChannelManager
This is purely a refactor that does not change the InitFeatures
advertised by a ChannelManager. This allows users to configure which
features should be advertised based on the values of `UserConfig`. While
there aren't any existing features currently leveraging this behavior,
it will be used by the upcoming anchors_zero_fee_htlc_tx feature.

The UserConfig dependency on provided_init_features caused most
callsites of the main test methods responsible for opening channels to
be updated. This commit foregos that completely by no longer requiring
the InitFeatures of each side to be provided to these methods. The
methods already require a reference to each node's ChannelManager to
open the channel, so we use that same reference to obtain their
InitFeatures. A way to override such features was required for some
tests, so a new `override_init_features` config option now exists on
the test harness.
2023-01-13 23:54:51 -08:00
Arik Sosman
72183bd932
Split up generic parameters that used to comprise KeysInterface. 2023-01-12 16:10:35 -08:00
Arik Sosman
5824e226ca
Remove KeysInterface trait. 2023-01-12 09:18:08 -08:00
Valentine Wallace
682bb9b0ae
Parameterize Simple*ChannelManager with DefaultRouter and ProbScorer 2023-01-05 11:29:00 -05:00
Valentine Wallace
3a274e0415
Implement routing against the netgraph in tests 2023-01-05 11:23:45 -05:00
Valentine Wallace
2e06efe2ff
Parameterize ChannelManager by a Router trait
This will be used in upcoming work to fetch routes on-the-fly for payment
retries, which will no longer be the responsibility of InvoicePayer.
2023-01-03 15:34:14 -05:00
Arik Sosman
9d7bb73b59
Split out KeysInterface into EntropySource, NodeSigner, and SignerProvider. 2022-12-20 10:09:11 -08:00
Matt Corallo
f96ac1d341 Bump crate versions to 0.0.113/invoice 0.21 2022-12-15 22:15:55 +00:00
Matt Corallo
5e577cb94a
Merge pull request #1862 from valentinewallace/2022-11-chanman-retries-prep
Prepare for Payment Retries in `ChannelManager`
2022-12-01 04:24:10 +00:00
Valentine Wallace
8a51a792aa
Move DefaultRouter to router module 2022-11-30 16:29:57 -05:00
Matt Corallo
46333affb9 Drop verbose log entries in BP when no network graph is provided
If no network graph is provided to the `BackgroundProcessor`, we
log every time the processor loop goes around (at least every
100ms, if not more) which fille up logs with useless indications
that we have no network graph.
2022-11-22 17:27:29 +00:00
Matt Corallo
49c9f1885d
Merge pull request #1806 from arik-so/2022-10-background-processor-deparametrization
Remove generic `Signer` parameter where it can be inferred from `KeysInterface`
2022-11-11 06:08:51 +00:00
Wilmer Paulino
9787b28e89
Drop DecoratingEventHandler in favor of inline closure 2022-11-10 10:57:20 -08:00
Wilmer Paulino
8d20ebc376
Handle events asynchronously in the BackgroundProcessor's async variant 2022-11-10 10:57:16 -08:00
Wilmer Paulino
05cb467234
Consume events by value in EventHandler's handle_event 2022-11-10 10:57:09 -08:00
Wilmer Paulino
b0d0f3d749
Apply network graph updates through NetworkUpdate's instead of Event's 2022-11-10 10:56:59 -08:00
Matt Corallo
384c4dc775
Merge pull request #1843 from TheBlueMatt/2022-11-fix-bp-exit-docs
Correct async `lightning-background-processor` exit check docs
2022-11-10 00:42:20 +00:00
Arik Sosman
1c8a06cf61
Remove generic Signer parameter where it can be inferred from KeysInterface 2022-11-09 16:15:11 -08:00
Matt Corallo
71739dbe04 Correct async lightning-background-processor exit check docs
The check to stop the background processor is true -> break, not
false -> break. This simply updates the docs and leaves the code
as-is.
2022-11-09 18:39:51 +00:00
Elias Rohrer
f4c2d40700
Add ChannelReady event
This adds a `ChannelReady` event that is emitted as soon as a new
channel becomes usable, i.e., after both sides have sent
`channel_ready`.
2022-11-03 11:45:28 +01:00
valentinewallace
2e343e78ca
Merge pull request #1797 from arik-so/2022-10-channel-manager-deparameterization
Deparametrize `ChannelManager` to infer `Signer` from its `KeysInterface`.
2022-10-26 13:32:09 -04:00
Arik Sosman
22c367b13b
Deparametrize ChannelManager to infer Signer from its KeysInterface. 2022-10-25 10:02:28 -07:00
Matt Corallo
35154a15c3 Bump crate versions to 0.0.112/invoice 0.20 2022-10-24 18:53:58 +00:00
Gabriel Comte
aa916bb594
Derive Eq for all structs that derive PartialEq 2022-10-14 13:24:02 +02:00
Elias Rohrer
0038a3f7de
Add futures CI check
This adds testing of the `futures` feature to CI. In order to avoid
introducing a dependency on `std`, we switch to using the `futures-util`
crate directly enabling only a subset of features. To this end, we also
switch to using the `select_biased!` macro, which is equivalent to
`select!` except that it doesn't choose ready futures pseudo-randomly
at runtime.
2022-10-10 14:47:18 -04:00
Elias Rohrer
d3c369dce7
Fix background-processor doc build for futures 2022-10-10 10:40:17 -04:00
Duncan Dean
63d7b2bf3e
Remove and track perm failed nodes & channels
We never had the `NetworkGraph::node_failed` method implemented. The
scorer now handles non-permanent failures by downgrading nodes, so we
don't want that implemented.

The method is renamed to `node_failed_permanent` to explicitly indicate
that this is the only case it handles. We also add tracking in the form
of two maps as fields of `NetworkGraph`, namely, `removed_nodes` and
`removed_channels`. We track these removed graph entries to ensure we
don't just resync them right away from gossip soon after removing them.
We stop tracking these removed nodes whenever `remove_stale_channels_and_tracking()`
is called and the entries have been tracked for longer than
`REMOVED_ENTRIES_TRACKING_AGE_LIMIT_SECS` which is currently set to one
week.
2022-10-07 12:00:39 +02:00
Jeffrey Czyz
ca76d0675b
Merge pull request #1694 from jurvis/jurvis/2022-08-move-scorer-from-router
Move `LockableScore` requirement away from `Router` trait
2022-09-16 14:01:38 -05:00
Jurvis Tan
c353c3ed7c
Move Scorer requirement away from Router trait
We do this to enable users to create routers that do not need a scorer.
This can be useful if they are running a node the delegates pathfinding.

* Move `Score` type parameterization from `InvoicePayer` and `Router` to
`DefaultRouter`
* Adds a new field, `scorer`, to `DefaultRouter`
* Move `AccountsForInFlightHtlcs` to `DefaultRouter`, which we
will use to wrap the new `scorer` field, so scoring only happens in
`DefaultRouter` explicitly.
* Add scoring related functions to `Router` trait that we used to call
directly from `InvoicePayer`.
* Instead of parameterizing `scorer` in `find_route`, we replace it with
inflight_map so `InvoicePayer` can pass on information about inflight
HTLCs to the router.
* Introduced a new tuple struct, InFlightHtlcs, that wraps functionality
for querying used liquidity.
2022-09-16 08:38:56 -07:00
Matt Corallo
d33f7268fb Stop relying on *Features::known in BP and persister tests
As we move towards specify supported/required feature bits in the
module(s) where they are supported, the global `known` feature set
constructors no longer make sense.

Here we stop relying on the `known` method in the
`lightning-background-processor` and `lightning-persister` crate
tests.
2022-09-14 20:09:36 +00:00
valentinewallace
d2a9ae0b8e
Merge pull request #1717 from TheBlueMatt/2022-09-req-features-in-handlers
Move checking of specific require peer feature bits to handlers
2022-09-13 16:17:57 -04:00
Matt Corallo
f725c5a90a Add now-missing unwraps on test calls to peer_connected. 2022-09-13 16:59:30 +00:00
Matt Corallo
f5473d5051 Bump versions to lightning* 0.0.111 and lightning-invoice 0.19 2022-09-12 22:34:27 +00:00
Matt Corallo
989cb064b5 Move broadcast_node_announcement to PeerManager
Some `NodeFeatures` will, in the future, represent features which
are not enabled by the `ChannelManager`, but by other message
handlers handlers. Thus, it doesn't make sense to determine the
node feature bits in the `ChannelManager`.

The simplest fix for this is to change to generating the
node_announcement in `PeerManager`, asking all the connected
handlers which feature bits they support and simply OR'ing them
together. While this may not be sufficient in the future as it
doesn't consider feature bit dependencies, support for those could
be handled at the feature level in the future.

This commit moves the `broadcast_node_announcement` function to
`PeerHandler` but does not yet implement feature OR'ing.
2022-09-08 19:50:36 +00:00
valentinewallace
8c6cb9953a
Merge pull request #1657 from TheBlueMatt/2022-08-async-man-update
Add a background processor which is async
2022-09-06 16:06:06 -04:00
Matt Corallo
2a5bac22bf Add a background processing function that is async.
Adds a method which operates like BackgroundProcessor::start but
instead of functioning by spawning a background thread it is async.
2022-09-06 17:42:24 +00:00
Valentine Wallace
4adff1039f
Add boilerplate for sending and receiving onion messages in PeerManager
Adds the boilerplate needed for PeerManager and OnionMessenger to work
together, with some corresponding docs and misc updates mostly due to the
PeerManager public API changing.
2022-08-26 19:02:59 -04:00
Matt Corallo
b414c0641b
Merge pull request #1658 from lightning-signer/2022-08-bitcoin-0-29
Update bitcoin crate to 0.29.0
2022-08-12 23:51:06 +00:00
Devrandom
7e05623bef Update bitcoin crate to 0.29.0 2022-08-11 00:21:26 +02:00
Valentine Wallace
c242003dd3
Fix CI to error on doc links to private items
Somehow we weren't doing this.
2022-08-07 13:49:12 -04:00
Matt Corallo
e10dfe4fd0 Bump crate versions to 0.0.110/invoice 0.18 2022-07-26 22:01:09 +00:00
Wilmer Paulino
6877539af4
Add convenient GossipSync variant constructors
These constructors fill in the missing types for each variant so that
users don't have to turbofish them manually.
2022-07-15 10:32:16 -07:00
Matt Corallo
156cc77753 Bump crate versions to 0.0.109/invoice 0.17 2022-07-01 16:05:33 +00:00
Matt Corallo
5ed3f25b21 Add ChannelManager methods to force close without broadcasting
If a user restores from a backup that they know is stale, they'd
like to force-close all of their channels (or at least the ones
they know are stale) *without* broadcasting the latest state,
asking their peers to do so instead. This simply adds methods to do
so, renaming the existing `force_close_channel` and
`force_close_all_channels` methods to disambiguate further.
2022-06-25 02:25:32 +00:00
Matt Corallo
c180ddd57a
Merge pull request #1541 from jkczyz/2022-06-nit-follow-ups 2022-06-15 02:52:35 -07:00
Jeffrey Czyz
04a46829ac
Fix grammar in BackgroundProcessor::start docs 2022-06-13 18:28:01 -05:00
Matt Corallo
deac430f17 Update crate versions to 0.0.108/invoice 0.16 2022-06-10 14:53:23 +00:00
Max Fang
e291fb6b41 Fix lightning-background-processor release build 2022-06-09 22:58:26 -07:00
Jeffrey Czyz
b2e635f619
Bump crate versions to 0.0.107/invoice 0.15 2022-06-08 18:16:48 -05:00
Jeffrey Czyz
c032e2888b
Support only one GossipSync in BackgroundProcessor
BackgroundProcessor can take an optional P2PGossipSync and an optional
RapidGossipSync, but doing so may be easy to misuse. Each has a
reference to a NetworkGraph, which could be different between the two,
but only one is actually used.

Instead, allow passing one object wrapped in a GossipSync enum. Also,
fix a bug where the NetworkGraph is not persisted on shutdown if only a
RapidGossipSync is given.
2022-06-06 13:03:16 -05:00
Jeffrey Czyz
4ccf4451c2
Implement EventHandler for NetworkGraph
Instead of implementing EventHandler for P2PGossipSync, implement it on
NetworkGraph. This allows RapidGossipSync to handle events, too, by
delegating to its NetworkGraph.
2022-06-06 13:02:47 -05:00
Jeffrey Czyz
67736b7480
Parameterize NetworkGraph with Logger
P2PGossipSync logs before delegating to NetworkGraph in its
EventHandler. In order to share this handling with RapidGossipSync,
NetworkGraph needs to take a logger so that it can implement
EventHandler instead.
2022-06-06 13:02:43 -05:00
Jeffrey Czyz
574870e9f8
Move network_graph.rs to gossip.rs
The routing::network_graph module contains a few structs related to p2p
gossip. So renaming the module to 'gossip' seems more appropriate.
2022-06-02 15:15:30 -07:00
Jeffrey Czyz
ac35492877
Rename NetGraphMsgHandler to P2PGossipSync
NetGraphMsgHandler implements RoutingMessageHandler to handle gossip
messages defined in BOLT 7 and maintains a view of the network by
updating NetworkGraph. Rename it to P2PGossipSync, which better
describes its purpose, and to contrast with RapidGossipSync.
2022-06-02 15:15:30 -07:00
Arik Sosman
784addcaa9
Create separate timer for scorer persistence in background processor 2022-06-02 10:14:13 -07:00
Arik Sosman
312f765bd7
Indicate ongoing rapid sync to background processor.
Create a wrapper struct for rapid gossip sync that can be passed to
BackgroundProcessor's start method, allowing it to only start pruning
the network graph upon rapid gossip sync's completion.
2022-06-02 10:14:08 -07:00
Elias Rohrer
e98f68aee6 Rename FundingLocked to ChannelReady. 2022-05-30 17:07:09 -07:00
Matt Corallo
998cdc0865
Merge pull request #1418 from bruteforcecat/timeout-outbound-paymnet-retires-instead-of-count-out
add timeout retry strategy to outbound payment
2022-05-17 17:32:46 +00:00
KaFai Choi
b7d6d0dc8e
add timeout retry strategy to outbound payment 2022-05-17 13:27:22 +07:00
Viktor Tigerström
c581bab8be Pass counterparty_node_id to funding_transaction_generated 2022-05-14 20:32:44 +02:00
Viktor Tigerström
14e52cd7a6 Pass counterparty_node_id to force_close_channel 2022-05-14 20:32:44 +02:00
Viktor Tigerström
7893ddc721 Add counterparty_node_id to FundingGenerationReady 2022-05-14 02:15:32 +02:00
Jeffrey Czyz
65920818db
Merge pull request #1389 from lightning-signer/2022-03-bitcoin
Update bitcoin crate to 0.28.1
2022-05-05 14:08:16 -05:00
Devrandom
28d33ff9e0 bitcoin crate 0.28.1 2022-05-05 18:04:42 +02:00
Jurvis Tan
e06bfdfeb7
Set last_prune_call outside of persistence block 2022-05-03 15:29:11 -07:00
Jurvis Tan
5eeb254b82
Add utils to persist scorer in BackgroundProcessor
move last_prune_call back
2022-05-03 15:28:10 -07:00
valentinewallace
72069bfc9d
Merge pull request #1436 from TheBlueMatt/2022-04-event-process-try-lock
Reorder the BP loop to make manager persistence more reliable
2022-04-26 13:02:29 -04:00
Matt Corallo
050b19cd9b Reorder the BP loop to make manager persistence more reliable
The main loop of the background processor has this line:
`peer_manager.process_events(); // Note that this may block on ChannelManager's locking`
which does, indeed, sometimes block waiting on the `ChannelManager`
to finish whatever its doing. Specifically, its the only place in
the background processor loop that we block waiting on the
`ChannelManager`, so if the `ChannelManager` is relatively busy, we
may end up being blocked there most of the time.

This should be fine, except today we had a user who's node was
particularly slow in processing some channel updates, resulting in
the background processor being blocked there (as expected). Then,
when the channel updates were completed (and persisted) the next
thing the background processor did was hand the user events to
process, creating yet more channel updates. Ultimately, the users'
node crashed before finishing the event processing. This left us
with an updated monitor on disk and an outdated manager, and they
lost the channel on startup.

Here we simply move the above quoted line to after the normal event
processing, ensuring the next thing we do after blocking on
`ChannelManager` locks is persist the manager, prior to event
handling.
2022-04-26 15:29:16 +00:00
Matt Corallo
fa9fc0d094 Fix several "unused" warnings introduced in #1417 2022-04-24 16:03:26 +00:00
John Cantrell
4964944279
implement Persist and Persister with generic KVStorePersister trait 2022-04-20 16:46:58 -04:00
Matt Corallo
0a0f87c00f
Merge pull request #1397 from jkczyz/2022-03-release-0.0.106
Cut 0.0.106
2022-04-03 16:31:54 +00:00
Jeffrey Czyz
de8bb8d261
Bump crate versions to 0.0.106/invoice 0.14 2022-04-03 08:05:08 -05:00
Jeffrey Czyz
aeeafed7d5
Merge pull request #1376 from jurvis/jurvis/persist-networkgraph
Persist NetworkGraph on removal of stale channels
2022-03-30 13:38:39 -07:00
Jurvis Tan
df2e60d101
Use common Persister for persistence tests 2022-03-29 19:38:41 -07:00
Jurvis Tan
6ebc739255
Move expected_bytes to check_persisted_data! macro 2022-03-29 19:38:40 -07:00
Jurvis Tan
afb7aa85cf
Add NetworkGraph persistence
Instead of creating a separate trait for persisting NetworkGraph, use and rename the existing ChannelManagerPersister to handle them both. persist_graph is then called on removal of stale channels and on exit.
2022-03-29 19:38:40 -07:00
psycho-pirate
20a81e5c14 added network address in methods, filter_address function with tests and updated documentation 2022-03-23 04:44:28 +05:30
Elias Rohrer
e92b5a7ebd Add a random per-path CLTV offset for privacy. 2022-03-09 11:13:47 -06:00
Matt Corallo
def0628332 Bump crate versions to 0.0.105/invoice 0.13 2022-03-01 00:43:24 +00: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
Valentine Wallace
adeec71ed8
keysinterface: adapt get_node_secret for phantom payments
We want LDK to be able to retrieve the phantom secret key when we see that a payment
is destined for a phantom node.
2022-02-14 14:22:38 -05:00
Jeffrey Czyz
28faf89df3
Deprecate Scorer in favor of ProbabilisticScorer 2022-02-02 20:22:27 -06:00
valentinewallace
07776d3dab
Merge pull request #1253 from TheBlueMatt/2022-01-background-persist-exit
Persist `ChannelManager` before `BackgroundProcessor` exits
2022-01-24 11:23:12 -05:00
Matt Corallo
2d3a210897 Increase our PING_TIMER to ten seconds, from five.
Because many lightning nodes can take quite some time to respond to
pings, the five second ping timer can sometimes cause spurious
disconnects even though a peer is online. However, in part as a
response to mobile users where a connection may be lost as result
of only a short time with the app in a "paused" state, we had a
rather aggressive ping time to ensure we would disconnect quickly.

However, since we now just used a fixed time for the "went to
sleep" detection, we can somewhat increase the ping timer. We still
want to be fairly aggressive to avoid sending HTLCs to a peer that
is offline, but the tradeoff between spurious disconnections and
stuck payments is likely doesn't need to be quite as aggressive.
2022-01-21 00:36:59 +00:00
Matt Corallo
8f5023a006 Avoid disconnecting all peers if user code is slow
In the sample client (and likely other downstream users), event
processing may block on slow operations (e.g. Bitcoin Core RPCs)
and ChannelManager persistence may take some time. This should be
fine, except that we consider this a case of possible backgrounding
and disconnect all of our peers when it happens.

Instead, we here avoid considering event processing time in the
time between PeerManager events.
2022-01-21 00:36:59 +00:00
Matt Corallo
ce82a33186 Persist ChannelManager before BackgroundProcessor exits
Fixes #1237.
2022-01-18 22:07:15 +00:00
hackerrdave
d46c2a20e1 update repo name to use lightningdevkit 2021-12-26 22:53:16 -05:00
Matt Corallo
ec86e2a1a7 Bump versions to 0.0.104/invoice 0.12 2021-12-17 21:34:19 +00:00
Matt Corallo
73e8dc41a6 Automatically prune NetworkGraph of stale channels hourly in BP 2021-12-16 18:33:24 +00:00
Matt Corallo
c575429639 Drop allow_wallclock_use feature in favor of simply using std
Fixes #1147.
2021-12-16 18:33:24 +00:00
Matt Corallo
8f89371bae Update ChannelUpdate::timestamp when channels are dis-/en-abled
We update the `Channel::update_time_counter` field (which is copied
into `ChannelUpdate::timestamp`) only when the channel is
initialized or closes, and when a new block is connected. However,
if a peer disconnects or reconnects, we may wish to generate
`ChannelUpdate` updates in between new blocks. In such a case, we
need to make sure the `timestamp` field is newer than any previous
updates' `timestamp` fields, which we do here by simply
incrementing it when the channel status is changed.

As a side effect of this we have to update
`test_background_processor` to ensure it eventually succeeds even
if the serialization of the `ChannelManager` changes after the test
begins.
2021-11-23 22:17:18 +00:00
Matt Corallo
8e96f6b92e Log before+after ChannelMonitor/Manager updates for visibility
I realized on my own node that I don't have any visibility into how
long a monitor or manager persistence call takes, potentially
blocking other operations. This makes it much more clear by adding
a relevant log_trace!() print immediately before and immediately
after persistence.
2021-11-10 22:02:38 +00:00
Matt Corallo
c0bbd4d918
Merge pull request #1078 from TheBlueMatt/2021-09-chan-types
Implement channel_type negotiation
2021-11-03 16:58:33 +00:00
Matt Corallo
2b837bb272 Bump crate versions to 0.0.103/invoice 0.11 2021-11-03 02:20:51 +00:00
Jeffrey Czyz
a8d3b5aabf
Parameterize Scorer by a Time trait
Scorer uses time to determine how much to penalize a channel after a
failure occurs. Parameterizing it by time cleans up the code such that
no-std support is in a single AlwaysPresent struct, which implements the
Time trait. Time is implemented for std::time::Instant when std is
available.

This parameterization also allows for deterministic testing since a
clock could be devised to advance forward as needed.
2021-11-02 14:48: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
Matt Corallo
c53048a40f
Merge pull request #1144 from jkczyz/2021-10-invoice-payer-scoring
Penalize failed channels
2021-10-29 20:16:36 +00:00
Jeffrey Czyz
db05a14a0b
Test InvoicePayer in BackgroundProcessor
Proof of concept showing InvoicePayer can be used with an
Arc<ChannelManager> passed to BackgroundProcessor. Likely do not need to
merge this commit.
2021-10-29 14:26:58 -05:00