Commit graph

4122 commits

Author SHA1 Message Date
Wilmer Paulino
492b24059e
Track whether HolderFundingOutput originated from an anchor channel 2022-10-18 12:22:46 -07:00
Wilmer Paulino
519ec902aa
Store anchors option for supported output types
As we integrate the support of anchor outputs, we'll want to know if
each input we're working with came from an anchor outputs channel.
Instead of threading through a `opt_anchors` boolean across several
methods on `PackageSolvingData` and `PackageTemplate`, we decide to
store a reference in each `PackageSolvingData` variant instead that
features a change in behavior between channels with and without anchor
outputs.
2022-10-18 12:22:28 -07:00
Gursharan Singh
7f089df1e3 Dedupe gossip msgs while updating networkGraph from RGS
While applying gossip info from RGS-server, number of harmless
errors might arise which should be ignored. E.g. client should not
fail if there is a duplicate gossip for same channel or duplicate
update.
2022-10-18 10:43:53 -07:00
Valentine Wallace
ec538d1816
Update send_onion_message API to take new OnionMessageContents enum
OnionMessageContents specifies the data TLV that the sender wants in the onion
message. This enum only has one variant for now, Custom. When offers are added,
additional variants for invoice, invoice_request, and invoice_error will be
added.

This commit does not actually implement sending the custom OM contents, just
the API change.
2022-10-18 13:28:29 -04:00
Valentine Wallace
87b637c990
Fix accidental newline in OnionMessenger docs 2022-10-18 13:14:35 -04:00
Valentine Wallace
333be69bb4
Tweak OnionMessenger log on inbound onion message receipt 2022-10-18 13:12:59 -04:00
Valentine Wallace
75fd0f3cbb
Parameterize OnionMessenger by new CustomOnionMessageHandler trait
OnionMessenger::new will now take a custom onion message handler trait
implementation. This handler will be used in upcoming commit(s) to handle
inbound custom onion messages.

The new trait also specifies what custom messages are supported via its
associated type, CustomMessage. This associated type must implement a new
CustomOnionMessagesContents trait, which requires custom messages to support
being written, being read, and supplying their TLV type.
2022-10-18 11:39:39 -04:00
Valentine Wallace
2a8179edb7
Optionally parameterize decode_tlv_stream with custom decode closure
Useful for decoding custom or user-provided TLVs. See macro docs for more info.

Used in upcoming commit(s) to support custom onion message TLVs
2022-10-17 16:07:42 -04:00
Valentine Wallace
a40e32b197
ser: Add MaybeReadableArgs trait
Useful in decoding a custom message, so (a) the message type can be provided to
the handler and (b) None can be returned if the message type is unknown.

Used in upcoming commit(s) to support custom onion messages.
2022-10-17 16:05:36 -04:00
Matt Corallo
e61f3a238a
Merge pull request #1763 from gcomte/feature/derive-eq
Derive Eq for all structs that derive PartialEq
2022-10-17 16:03:23 +00:00
Matt Corallo
1caf1ab84e
Merge pull request #1774 from futurepaul/disable-rustfmt
disable automatic formatting
2022-10-17 14:51:22 +00:00
Paul Miller
e24afa7ee3
disable all formatting 2022-10-15 17:46:06 -04:00
Gabriel Comte
aa916bb594
Derive Eq for all structs that derive PartialEq 2022-10-14 13:24:02 +02:00
valentinewallace
67726097c2
Merge pull request #1765 from gcomte/refactor/remove-redundant-field-names
Remove redundant field names
2022-10-12 10:46:36 -04:00
Gabriel Comte
8abf02ccfe
Remove redundant field names 2022-10-12 00:35:22 +02:00
Matt Corallo
fdfd4f034c
Merge pull request #1754 from TheBlueMatt/2022-10-better-liq-halflife-docs
Rewrite some documentation on `ProbabilisticScorer` and increase half-life to 6 hours.
2022-10-11 21:54:48 +00:00
Matt Corallo
9e8496659f Increase the default liquidity_offset_half_life to six hours
Even at relatively high payment volumes, decaying knowledge of each
individual channel every hour causes aggressive retrying of
channels as we quickly forget the state of a channel. Even with the
historical tracker, this isn't fully remedied, as we'll track the
history bounds with the decayed value.

Instead, we decay every six hours here, reducing how often we'll
retry a channel due to decay.

In addition to this, the decay likely needs to be substantially
more linear, as tracked in #1752.
2022-10-11 18:25:43 +00:00
Matt Corallo
fe531c583d Rewrite documentation some on ProbabilisticScorer
We had some user confusion on how the probabilistic scorer works,
especially in reference to the half-life parameter. This attempts
to clarify how the bounds work, and how they are decayed.
2022-10-11 18:25:43 +00:00
Matt Corallo
6738fd56cf
Merge pull request #1744 from tnull/2022-09-fix-bp-futures-doc
Fix `background-processor` doc build for `futures`
2022-10-10 20:29:11 +00: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
valentinewallace
559ed20f92
Merge pull request #1756 from TheBlueMatt/2022-10-rgs-no-std
Fix `rapid-gossip-sync` `no-std` and properly test no-std in CI
2022-10-07 17:01:10 -04:00
Valentine Wallace
a031ff952b
Specify full import path in decode_tlv macro
Prevents unresolved import error
2022-10-07 15:36:34 -04:00
Matt Corallo
a626828c96
Merge pull request #1649 from dunxen/2022-08-implementnodefailure
Implement permanent node failure handling
2022-10-07 18:41:19 +00:00
Jeffrey Czyz
2fda791d5c
Merge pull request #1693 from valentinewallace/2022-09-readme-updates
Fix outdated README sections
2022-10-07 12:44:52 -05:00
Matt Corallo
5c8e9ad092
Merge pull request #1758 from TheBlueMatt/2022-10-fix-pre-notified-future
Fix (and test) `Future` creation after a `Notifier` was notified
2022-10-07 17:38:50 +00:00
Matt Corallo
ada0df2d9f Test a full no-std build in the no-std-check crate in CI
Rust is incredibly forgiving in attempts to access `std`, making it
rather difficult to test `no-std` properly. In practice, the only
decent way to do so is to actually build for a platform that does
not have `std`, which we do here by building the `no-std-check`
crate for `arm-thumbv7m-none-eabi`.
2022-10-07 17:19:12 +00:00
Matt Corallo
4cd9901427
Merge pull request #1625 from TheBlueMatt/2022-07-history-tracking 2022-10-07 16:32:10 +00:00
valentinewallace
d9f5c407de
Merge pull request #1751 from TheBlueMatt/2022-10-fix-score-log-direction
Correct the directionality of liquidity non-update messages
2022-10-07 12:28:23 -04:00
Matt Corallo
5f8d7c5762
Merge pull request #1760 from TheBlueMatt/2022-10-invoice-builder-round 2022-10-07 16:25:25 +00:00
Valentine Wallace
6817762841
Fix outdated README sections 2022-10-07 12:03:02 -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
Matt Corallo
008da77263 Drop the subsecond part of timestamps when constructing invoices
We had a user who was confused why an invoice failed to round-trip
(i.e. was not `PartialEq` with itself after write/read) when a
subsecond creation time was used (e.g. via the `from_system_time`
constructor).

This commit should address this confusion by dropping subsecond
parts in easily-accessible constructors when creating BOLT 11
invoices.

Fixes #1759.
2022-10-07 02:05:46 +00:00
Matt Corallo
92963ebe52 Support platforms with only 32-bit atomics
Given there is only one instance in our code of `AtomicU64` its
simplest to just remove it rather than try to add some kind of
wrapper.
2022-10-06 23:59:30 +00:00
Matt Corallo
e2e8847254 Test rapid-gossip-sync in no-std in CI 2022-10-06 23:59:30 +00:00
Matt Corallo
3852d52801 Update rapid-gossip-sync docs to not reference std-only methods 2022-10-06 23:59:30 +00:00
Matt Corallo
cf3471f8ad Fix (and test) Future creation after a Notifier was notified
After a `Notifier` has been `notify`'d, attempts to `get_future`
should return a `Future` which is pre-completed, however this was
not the case.

This commit simply fixes the behavior, adding a test to demonstrate
the issue.
2022-10-06 23:54:52 +00:00
Matt Corallo
c8fb859ad6 Decay historical liquidity tracking when no new data is added
To avoid scoring based on incredibly old historical liquidity data,
we add a new half-life here which is used to (very slowly) decay
historical liquidity tracking buckets.
2022-10-06 21:10:23 +00:00
Matt Corallo
ec68f1326d Track a reference to scoring parameters in DirectedChannelLiquidity
This simplifies adding additional half lives in
DirectedChannelLiquidity by simply storing a reference to the full
parameter set rather than only the single current half-life.
2022-10-06 21:10:23 +00:00
Matt Corallo
6852ea9741 Calculate a new penalty based on historical channel liquidity range
Our current `ProbabilisticScorer` attempts to build a model of the
current liquidity across the payment channel network. This works
fine to ignore channels we *just* tried to pay through, but it
fails to remember patterns over longer time horizons.

Specifically, there are *many* channels within the network that are
very often either fully saturated in one direction, or are
regularly rebalanced and rarely saturated. While our model may
discover that, when it decays its offsets or if there is a
temporary change in liquidity, it effectively forgets the "normal"
state of the channel.

This causes substantially suboptimal routing in practice, and
avoiding discarding older knowledge when new datapoints come in is
a potential solution to this.

Here, we implement one such design, using the decaying buckets
added in the previous commit to calculate a probability of payment
success based on a weighted average of recent liquidity estimates
for a channel.

For each min/max liquidity bucket pair (where the min liquidity is
less than the max liquidity), we can calculate the probability that
a payment succeeds using our traditional `amount / capacity`
formula. From there, we weigh the probability by the number of
points in each bucket pair, calculating a total probability for the
payment, and assigning a penalty using the same log-probability
calculation used for the non-historical penalties.
2022-10-06 21:10:23 +00:00
Matt Corallo
c5eab6e11f Track history of where channel liquidities have been in the past
This introduces two new fields to the `ChannelLiquidity` struct -
`min_liquidity_offset_history` and `max_liquidity_offset_history`,
both an array of 8 `u16`s. Each entry represents the proportion of
time that we spent with the min or max liquidity offset in the
given 1/8th of the channel's liquidity range. ie the first bucket
in `min_liquidity_offset_history` represents the proportion of time
we've thought the channel's minimum liquidity is lower than 1/8th's
the channel's capacity.

Each bucket is stored, effectively, as a fixed-point number with
5 bits for the fractional part, which is incremented by one (ie 32)
each time we update our liquidity estimates and decide our
estimates are in that bucket. We then decay each bucket by
2047/2048.

Thus, memory of a payment sticks around for more than 8,000
data points, though the majority of that memory decays after 1,387
data points.
2022-10-06 21:10:23 +00:00
Matt Corallo
5d0deacc3d Correct the directionality of liquidity non-update messages
When we log liquidity updates, if we decline to update anything as
the new bounds are already within the old bounds, the
directionality of the log entries was reversed.

While we're at it, we also log the old values.
2022-10-06 17:54:28 +00:00
Matt Corallo
f9acac8fec Correct rapid-gossip-sync no-std build and test
While `rapid-gossip-sync` recently gained a `no-std` feature, it
didn't actually work, as there were still dangling references to
`std` and prelude assumptions. This makes `rapid-gossip-sync`
build (and test) properly in `no-std`.
2022-10-06 17:51:12 +00:00
Matt Corallo
7544030bb6
Merge pull request #1106 from TheBlueMatt/2021-10-no-perm-err-broadcast
Do not broadcast commitment txn on Permanent mon update failure
2022-09-29 22:02:07 +00:00
Matt Corallo
52934e0fff Clarify ambiguous comment in persist methods 2022-09-29 20:27:53 +00:00
Matt Corallo
f961daef33 Rename APIError::MonitorUpdateFailed to MonitorUpdateInProgress
This much more accurately represents the error, indicating that a
monitor update is in progress asynchronously and may complete at a
later time.
2022-09-29 20:27:53 +00:00
Matt Corallo
fb0a481696 Rename handle_monitor_err!() handle_monitor_update_res! 2022-09-29 20:27:53 +00:00
Matt Corallo
721a858533 Rename Channel::monitor_update_failed to monitor_updating_paused 2022-09-29 20:27:53 +00:00
Matt Corallo
72416b951e Add a TODO for an important issue for making async mon updates safe
If we receive a monitor event from a forwarded-to channel which
contains a preimage for an HTLC, we have to propogate that preimage
back to the forwarded-from channel monitor. However, once we have
that update, we're running in a relatively unsafe state - we have
the preimage in memory, but if we were to crash the forwarded-to
channel monitor will not regenerate the update with the preimage
for us. If we haven't managed to write the monitor update to the
forwarded-from channel by that point, we've lost the preimage, and,
thus, money!
2022-09-29 20:27:53 +00:00
Matt Corallo
12fa0b11a6 Rework chain::Watch return types to make async updates less scary
When a `chain::Watch` `ChannelMonitor` update method is called, the
user has three options:
 (a) persist the monitor update immediately and return success,
 (b) fail to persist the monitor update immediately and return
     failure,
 (c) return a flag indicating the monitor update is in progress and
     will complete in the future.

(c) is rather harmless, and in some deployments should be expected
to be the return value for all monitor update calls, but currently
requires returning `Err(ChannelMonitorUpdateErr::TemporaryFailure)`
which isn't very descriptive and sounds scarier than it is.

Instead, here, we change the return type used to be a single enum
(rather than a Result) and rename `TemporaryFailure`
`UpdateInProgress`.
2022-09-29 20:27:53 +00:00