Commit Graph

290 Commits

Author SHA1 Message Date
Elias Rohrer
8599bc9784
Add simple test for event replaying 2024-07-18 15:54:21 +02:00
Elias Rohrer
018908fe9e
Make event handling fallible
Previously, we would require our users to handle all events
successfully inline or panic will trying to do so. If they would exit
the `EventHandler` any other way we'd forget about the event and
wouldn't replay them after restart.

Here, we implement fallible event handling, allowing the user to return
`Err(())` which signals to our event providers they should abort event
processing and replay any unhandled events later (i.e., in the next
invocation).
2024-07-18 15:54:21 +02:00
Matt Corallo
ddb40bd04c
Merge pull request #3173 from dunxen/2024-07-cargocheckcfg
Use native check-cfg lint in cargo beta
2024-07-15 11:33:08 -07:00
Duncan Dean
99aa6e27f6
Use native check-cfg lint in cargo beta
This uses the newly introduced conditional configuration checks that are
now configurable withint Cargo (beta).

This allows us to get rid of our custom python script that checks for
expected features and cfgs.

This does introduce a warning regarding the unknown lint in Cargo
versions prior to the current beta, but since these are not rustc errors,
they won't break any builds with the "-D warnings" RUSTFLAG.

Moving to this lint actually exposed the "strict" feature not being
present in the lightning-invoice crate, as our python script didnt
correctly parse the cfg_attr where it appeared.
2024-07-12 11:48:15 +02:00
Elias Rohrer
438515d2c4
rustfmt: Run on lightning-background-processor/src/lib.rs 2024-07-09 10:26:00 +02:00
Elias Rohrer
a60f7a7fcf
Prepare lightning-background-processor/src/lib.rs 2024-07-09 10:25:47 +02:00
Valentine Wallace
969578703d
Implement AsyncPaymentsMessageHandler for ChanMan and use everywhere
Dummy implementation for now. This avoids having to change a bunch of type
signatures in the future when we replace the dummy impl with a real one.
2024-06-25 16:40:35 -04:00
Valentine Wallace
e8f154dd3c
AsyncPaymentsMessageHandler trait for OnionMessenger
Add a trait for handling async payments messages to OnionMessenger. This allows
users to either provide their own custom handling for async payments messages
or rely on a version provided by LDK.
2024-06-20 14:24:03 -04:00
Matt Corallo
3cd1cb5946
Merge pull request #3060 from TheBlueMatt/2024-05-parallel-async-om-events
Add a parallel async event handler to OnionMessenger and pass it directly to BackgroundProcessor
2024-06-04 12:10:43 -07:00
Arik
993cd1e525
Merge pull request #2889 from Sharmalm/2840
Allow for user-specified error message during force close channel
2024-06-03 14:48:52 -07:00
Matt Corallo
f96fbdd361 f fix imports in BP 2024-06-03 18:51:28 +00:00
Matt Corallo
92bf460292 Switch to using the OnionMessenger directly in BP
When `OnionMessenger` first developed a timer and events interface,
we accessed the `OnionMessenger` indirectly via the `PeerManager`.
While this is a fairly awkward interface, it avoided a large pile
of generics on the background processor interfaces. However, since
we now have an `AOnionMessenger` trait, this concern is no longer
significant. Further, because we now want to use the built-in
`OnionMessenger` async event processing method, we really need a
direct referene to the `OnionMessenger` in the background
processor, which we add here optionally.
2024-06-03 18:51:28 +00:00
Jiri Jakes
a8bd4c097f
Upgrade rust-bitcoin to 0.31 2024-05-30 18:35:29 +08:00
Matt Corallo
e818c4b13f Move [u8; 32] wrapper types to a common module
The `PaymentHash`, `PaymentSecret`, `PaymentPreimage`, and
`ChannelId` types are all small wrappers around `[u8; 32]` and are
used throughout the codebase but were defined in the top-level
`ln/mod.rs` file and the relatively sparsely-populated
`ln/channel_id.rs` file.

Here we move them to a common `types` module and go ahead and
update all our in-crate `use` statements to refer to the new
module for bindings. We do, however, leave a `pub use` alias for
the old paths to avoid upgrade hassle for users.
2024-05-01 19:01:40 +00:00
Elias Rohrer
afb452a813
Make OutputSweeper::track_spendable_outputs fallible
.. as otherwise we might only log an error and continue if we fail to
persist the sweeper state.
2024-04-24 09:46:34 +02:00
Lalitmohansharma1
d17e759d02 Allowing user-specified error message during force close channel
In this commit i added additional parameter `error_message` to
`force_close_sending_error`. This parameter will allow users to
configure error message and send to peers during the force closing
of channel.I have also updated the tests for this updated function.
2024-04-20 19:12:59 +05:30
Matt Corallo
49b375311b Bump crate versions to 0.0.123-beta/invoice 0.31-beta 2024-04-19 01:03:03 +00:00
Elias Rohrer
681106d23f
Add basic OutputSweeper test in BP
.. we simply check that the `OutputSweeper` generates a spending tx and
that the `TrackedSpendableOutput` is pruned once it reaches
`ANTI_REORG_DELAY`.
2024-04-18 16:20:03 +02:00
Jeffrey Czyz
d29e2ba949
Use AChannelManager in BackgroundProcessor
Replace instance of ChannelManager in BackgroundProcessor and in
Persister with AChannelManager. This reduces the number of type
parameters need in those types, which would need to be repeated in an
async version of Persister.
2024-03-23 17:02:28 -05:00
Jeffrey Czyz
5e56c5ed45
Fix indentation in doc example 2024-03-23 16:18:58 -05:00
Elias Rohrer
57911dcd41
Refactor BestBlock to expose inner fields rather than accessors
.. which is more idiomatic Rust, and easier to handle in (downstream)
bindings.
2024-03-07 11:02:23 +01:00
Matt Corallo
8157c01eab Never store more than one StdWaker per live Future
When an `std::future::Future` is `poll()`ed, we're only supposed to
use the latest `Waker` provided. However, we currently push an
`StdWaker` onto our callback list every time `poll` is called,
waking every `Waker` but also using more and more memory until the
`Future` itself is woken.

Here we fix this by removing any `StdWaker`s stored for a given
`Future` when it is `drop`ped or prior to pushing a new `StdWaker`
onto the list when `poll`ed.

Sadly, the introduction of a `Drop` impl for `Future` means we
can't trivially destructure the struct any longer, causing a few
methods to need to take `Future`s by reference rather than
ownership and `clone` a few `Arc`s.

Fixes #2874
2024-02-15 21:52:06 +00:00
Matt Corallo
e594021052
Merge pull request #2847 from TheBlueMatt/2024-01-bindings-upstream
Misc Tweaks for bindings
2024-02-05 23:49:19 +00:00
Matt Corallo
5d5c8187b4 Store EntropySource in DefaultRouter instead of passing it
...as an arg to `Router`. Passing an `EntropySource` around all
the time is a bit strange as the `Router` may or may not actually
use it, and the `DefaultRouter` can just as easily store it.
2024-01-30 23:56:12 +00:00
Duncan Dean
cf2c27800a
Remove Outpoint::to_channel_id method
To avoid confusion and for accuracy going forward, we remove this method
as it is inconsistent with channel IDs generated during V2 channel
establishment. If one wants to create a V1, funding outpoint-based
channel ID, then `ChannelId::v1_from_funding_outpoint` should be used
instead.

A large portion of the library has always made the assumption that having
the funding outpoint will always allow us to generate the channel ID.
This will not be the case anymore and we need to pass the channel ID along
where appropriate. All channels that could have been persisted up to this
point could only have used V1 establishment, so if some structures don't
store a channel ID for them they can safely fall back to the funding
outpoint-based version.
2024-01-30 12:30:26 +02:00
Matt Corallo
7b31b303c6 Bump versions to LDK 0.0.121/invoice 0.29 2024-01-22 22:32:30 +00:00
Matt Corallo
37017ec39f Bump crate versions to 0.0.120/invoice 0.28 2024-01-17 21:34:29 +00:00
Elias Rohrer
e76ad1a245
Fix redundant import warning in BP's futures 2023-12-18 08:53:27 +01:00
Matt Corallo
c6e4debee9 Bump versions to 0.0.119/lightning-invoice 0.27 2023-12-15 23:53:40 +00:00
Matt Corallo
c92db69183
Merge pull request #2656 from TheBlueMatt/2023-09-scoring-decay-timer
Stop decaying liquidity information during scoring
2023-12-15 20:06:30 +00:00
Matt Corallo
21facd0d17 Make scorer decay + persistence more frequent
There's some edge cases in our scoring when the information really
should be decayed but hasn't yet been prior to an update. Rather
than try to fix them exactly, we instead decay the scorer a bit
more often, which largely solves them but also gives us a bit more
accurate bounds on our channels, allowing us to reuse channels at
a similar amount to what just failed immediately, but at a
substantial penalty.
2023-12-13 23:26:09 +00:00
Matt Corallo
b84842a904 Add a scoring decay method to the ScoreUpdate trait
Rather than relying on fetching the current time during
routefinding, here we introduce a new trait method to `ScoreUpdate`
to do so. This largely mirrors what we do with the `NetworkGraph`,
and allows us to take on much more expensive operations (floating
point exponentiation) in our decaying.
2023-12-13 23:26:09 +00:00
olegkubrakov
348db3baf7 Update tokio version to the latest to avoid tokio versions with security bugs.
This commit will set tokio version requirement to >=1.35.0, <2.0.0 to avoid versions with security issues (https://rustsec.org/packages/tokio.html).
2023-12-13 10:37:58 -08:00
Matt Corallo
6c366cf35f Pass the current time through ScoreUpDate methods
In the coming commits, we'll stop relying on fetching the time
during routefetching, preferring to decay score data in the
background instead.

The first step towards this - passing the current time through into
the scorer when updating.
2023-12-13 18:36:40 +00:00
Elias Rohrer
5112ac2f3f
Remove unused NodeId in BP tests 2023-12-11 19:58:46 +01: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
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
Jeffrey Czyz
e25af3eb01
Call OnionMessageHandler::timer_tick_occurred
lightning-background-processor processes events provided by the
PeerManager's OnionMessageHandler for when a connection is needed. If a
connection is not established in a reasonable amount of time, drop any
buffered onion messages by calling timer_tick_occurred.
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
Jeffrey Czyz
ce68f223e9
Re-order define_run_body macro parameters
Simply to avoid excessive wrapping when possible.
2023-12-06 14:43:39 -06:00
Jeffrey Czyz
36ecc8e729
Re-wrap define_run_body macro parameters
Some code hygiene before another parameter is added and rustfmt is
eventually used.
2023-12-06 14:43:39 -06:00
Jeffrey Czyz
ae9851794c
Remove unnecessary BackgroundProcessor type param 2023-12-06 14:43:38 -06:00
jbesraa
f0ecc3ec73
Use CandidateRouteHop as input for channel_penalty_msat
We remove `source`, `target` and `scid` from
  `channel_penalty_msat` inputs to consume them from
  `candidate` of type `CandidateRouteHop`
2023-12-05 21:07:48 +02:00
Matt Corallo
dfb02f1878 Marginally optimize test logging
973636bd2a introduced a new `HashMap`
in the `TestLogger` but then did lookups by iterating the entire
map. This fixes that, and also takes this opportunity to stop
allocating new `String`s for the module to store each log entry in
the `TestLogger`
2023-12-02 19:19:07 +00:00
Arik Sosman
27b9794bed
Rename SignerProvider's Signer to EcdsaSigner. 2023-11-27 16:27:20 -08:00
Wilmer Paulino
ec928d55b4
Bump rust-bitcoin to v0.30.2 2023-11-22 15:58:01 -08:00
Matthew Rheaume
bf395070dd Added temporary_channel_id to create_channel.
By default, LDK will generate the initial temporary channel ID for you.
However, in certain cases, it's desirable to have a temporary channel ID
specified by the caller in case of any pre-negotiation that needs to
happen between peers prior to the channel open message. For example, LND
has a `FundingShim` API that allows for advanced funding flows based on
the temporary channel ID of the channel.

This patch adds support for optionally specifying the temporary channel
ID of the channel through the `create_channel` API.
2023-11-03 17:44:50 -07:00
Matt Corallo
b664875c1b Bump crate versions to lightning 0.0.118, invoice 0.26 2023-10-23 23:41:11 +00:00
Matt Corallo
bbb8facbe6 Fix (and test) the c_bindings build flag
Rather than only building with the `c_bindings` flag in certain
crates, we go ahead and test all crates with the flag in CI here.
2023-10-21 14:30:21 +00:00
Matt Corallo
c74874604e Bump crate versions to 0.0.117/invoice 0.25 2023-10-03 23:00:48 +00:00