Commit Graph

274 Commits

Author SHA1 Message Date
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
Jeffrey Czyz
7a8954e1ca
Notify scorer of failing payment path and channel
Upon receiving a PaymentPathFailed event, the failing payment may be
retried on a different path. To avoid using the channel responsible for
the failure, a scorer should be notified of the failure before being
used to find a new route.

Add a payment_path_failed method to routing::Score and call it in
InvoicePayer's event handler. Introduce a LockableScore parameterization
to InvoicePayer so the scorer is locked only once before calling
find_route.
2021-10-29 14:24:53 -05:00
Matt Corallo
4a58e9ad83 Add PeerManager::disconnect_all_peers to avoid complexity in BP
In the coming commits simply calling `timer_tick_occurred` will no
longer disconnect all peers, so its helpful to have a utility
method.
2021-10-26 02:04:34 +00:00
Matt Corallo
d0c3fb745d Fix cargo doc on older rustc
Apparently at least rustc 1.48 doesn't support `Self` in doc links,
so we make it explicit.
2021-10-22 19:34:18 +00:00
Matt Corallo
f2e47e0db2 Bump crate versions to 0.0.102 and lightning-invoice 0.10 2021-10-18 18:32:36 +00:00
Matt Corallo
0dfb24e661 Move Persist trait to chainmonitor as that's the only reference 2021-10-14 00:16:50 +00:00
Jeffrey Czyz
d7c8c8c572
Speed up test_timer_tick_called 2021-10-13 10:25:18 -05:00
Matt Corallo
43fe3d55f1 Bump Crate versions to 0.0.101 (and invoice to 0.9) 2021-09-23 18:22:59 +00:00
Antoine Riard
6ce7f3e1ce Add ChannelClosed generation at cooperative/force-close/error processing
When we detect a channel `is_shutdown()` or call on it
`force_shutdown()`, we notify the user with a Event::ChannelClosed
informing about the id and closure reason.
2021-09-21 15:46:42 -04:00
Jeffrey Czyz
992df51001
Update NetworkGraph in BackgroundProcessor
Decorate the user-supplied EventHandler with NetGraphMsgHandler in
the BackgroundProcessor. The resulting handler will intercept
PaymentFailed events in order to update the NetworkGraph in the
background before delegating to the user's event handler.
2021-09-15 11:53:13 -05:00
Jeffrey Czyz
e2f088c371
Expand and format BackgroundProcessor docs 2021-09-15 11:53:12 -05:00
Jeffrey Czyz
a6e650630d
Pass Event by reference to EventHandler
Passing an Event by reference rather and by move gives more flexibility
for composing event handlers without needing to clone events.
2021-09-09 22:57:51 -05:00
Matt Corallo
45853b3a95
Merge pull request #1031 from p2pderivatives/dlc-version-generic
Dlc version generic
2021-08-25 17:22:20 +00:00
Tibo-lg
2e5e40e0b2 Add custom message handler to peer manager 2021-08-25 13:22:09 +09:00
Joseph Goulden
af4eb23a1c test: increase ping timeout when running in debug mode 2021-08-20 15:48:40 +01:00
Matt Corallo
11f78798d3 Update versions to 0.0.100 and lightning-invoice to 0.8 2021-08-17 18:55:07 +00:00
Matt Corallo
03439ec99f Automatically update fees on outbound channels as fees change
Previously we'd been expecting to implement anchor outputs before
shipping 0.1, thus reworking our channel fee update process
entirely and leaving it as a future task. However, due to the
difficulty of working with on-chain anchor pools, we are now likely
to ship 0.1 without requiring anchor outputs.

In either case, there isn't a lot of reason to require that users
call an explicit "prevailing feerates have changed" function now
that we have a timer method which is called regularly. Further, we
really should be the ones deciding on the channel feerate in terms
of the users' FeeEstimator, instead of requiring users implement a
second fee-providing interface by calling an update_fee method.

Finally, there is no reason for an update_fee method to be
channel-specific, as we should be updating all (outbound) channel
fees at once.

Thus, we move the update_fee handling to the background, calling it
on the regular 1-minute timer. We also update the regular 1-minute
timer to fire on startup as well as every minute to ensure we get
fee updates even on mobile clients that are rarely, if ever, open
for more than one minute.
2021-08-13 21:54:50 +00:00
Matt Corallo
767f12030b
Merge pull request #1019 from jkczyz/2021-07-shutdown-pubkey
Fetch shutdown script based on `commit_upfront_shutdown_pubkey`
2021-08-09 21:41:02 +00:00
Jeffrey Czyz
89fa27432a
Connect nodes in remaining tests
Similar to 2745bd5ac7, this ensures that
ChannelManager knows about the features its peers.
2021-08-09 15:55:26 -05:00
Matt Corallo
03537cc346
Merge pull request #1035 from TheBlueMatt/2021-08-faster-pings
Suggest faster ping in `PeerManager::timer_tick_occurred` docs
2021-08-09 18:52:25 +00:00
Matt Corallo
0f1a3b1698 Handle being asleep for more than double our ping time gracefully
If we've been asleep for double our ping time, for whatever reason,
disconnect all open sockets.
2021-08-09 18:11:19 +00:00
Matt Corallo
a00eec1865 Update lightning-background-processor to ping every five seconds
This updates lightning-background-processor calls to
PeerManager::timer_tick_occurred to match the new suggested rate in
the documentation.
2021-08-09 18:11:19 +00:00
Matt Corallo
5307b5e8ce Make BackgroundProcessor #[must_use] to avoid dropping immediately
It is easy for users to have a bug where they drop a
`BackgroundProcessor` immediately, causing it to start and then
immediately stop. Instead, add a `#[must_use]` tag to provide a
compiler warning for such instances.
2021-08-05 20:24:21 +00:00
Matt Corallo
3f229052ea Bump dependencies to bitcoin 0.27 and bech32 0.8 2021-07-31 18:29:07 +00:00
Jeffrey Czyz
e260cfcd9b
Add join method to BackgroundProcessor
The previous commit wraps the background thread's JoinHandle in an
Option. Providing a dedicated method to join hides this implementation
detail from users.
2021-07-28 16:30:51 -05:00
Jeffrey Czyz
4f05db6af8
Stop BackgroundProcessor's thread on drop
Without stopping the thread when BackgroundProcessor is dropped, it will
run free. In the context of language bindings, it is difficult to know
how long references held by the thread should live. Implement Drop to
stop the thread just as is done when explicitly calling stop().
2021-07-18 13:11:01 -05:00
Jeffrey Czyz
d9fa8f1c38
Correctly assert BackgroundProcessor error
The specific error from the ChannelManager persister is not asserted for
in test_persist_error. Rather, any error will do. Update the test to use
BackgroundProcessor::stop and assert for the expected value.
2021-07-18 12:59:27 -05:00
Matt Corallo
c9a8b26d58 Bump most crate versions to 0.0.99 and lightning-invoice to 0.7.0 2021-07-09 16:34:46 +00:00
Matt Corallo
c620944f16 Make the base fee configurable in ChannelConfig
Currently the base fee we apply is always the expected cost to
claim an HTLC on-chain in case of closure. This results in
significantly higher than market rate fees [1], and doesn't really
match the actual forwarding trust model anyway - as long as
channel counterparties are honest, our HTLCs shouldn't end up
on-chain no matter what the HTLC sender/recipient do.

While some users may wish to use a feerate that implies they will
not lose funds even if they go to chain (assuming no flood-and-loot
style attacks), they should do so by calculating fees themselves;
since they're already charging well above market-rate,
over-estimating some won't have a large impact.

Worse, we current re-calculate fees at forward-time, not based on
the fee we set in the channel_update. This means that the fees
others expect to pay us (and which they calculate their route based
on), is not what we actually want to charge, and that any attempt
to forward through us is inherently race-y.

This commit adds a configuration knob to set the base fee
explicitly, defaulting to 1 sat, which appears to be market-rate
today.

[1] Note that due to an msat-vs-sat bug we currently actually
    charge 1000x *less* than the calculated cost.
2021-07-09 00:50:30 +00:00
Matt Corallo
99938455f7
Merge pull request #949 from TheBlueMatt/2021-06-send-priv-update
Send channel_update messages to direct peers on private channels
2021-07-07 20:17:10 +00:00
Matt Corallo
e3968e0993 Send channel_update messages to direct peers on private channels
If we are a public node and have a private channel, our
counterparty needs to know the fees which we will charge to forward
payments to them. Without sending them a channel_update, they have
no way to learn that information, resulting in the channel being
effectively useless for outbound-from-us payments.

This commit fixes our lack of channel_update messages to private
channel counterparties, ensuring we always send them a
channel_update after the channel funding is confirmed.
2021-07-07 19:45:33 +00:00
Matt Corallo
da298e498f Expose the current best chain tip from ChannelManager + Monitors
Fixes #979
2021-07-06 00:18:27 +00:00
Matt Corallo
9c9081dfcb Bump versions to 0.0.98, lightning-invoice to 0.6.0 2021-06-08 21:08:29 +00:00
Matt Corallo
e60ccbb1a8 Delay DelayedPaymentOutput spendable events until the CSV delay 2021-06-01 22:32:56 +00:00
Matt Corallo
90e984e797 Track the blocks a node has connected in the TestBroadcaster 2021-05-28 23:56:44 +00:00
Jeffrey Czyz
f63fd83fd6
Process ChainMonitor events in the background 2021-05-25 00:28:59 -07:00
Jeffrey Czyz
501b54300c
Process ChannelManager events in the background 2021-05-25 00:28:58 -07:00
Jeffrey Czyz
7c465d69dc
Refactor EventsProvider to take an EventHandler 2021-05-24 14:16:16 -07:00
Matt Corallo
f551d5946b Bump versions to 0.0.14, lightning-invoice 0.5 2021-05-01 00:43:15 +00:00
Valentine Wallace
6f5d81631a
Make _test_utils depend on bitcoinconsensus feature 2021-04-29 18:39:47 -04:00
Matt Corallo
452b72078e Rename background-processor to lightning-... to match other crates 2021-04-15 15:23:05 -04:00