Commit graph

4231 commits

Author SHA1 Message Date
Matt Corallo
a534dcc5cd Include all channel route hints if no connected channels exist
Mobile clients often take a second or two before they reconnect to
their peers as its not always clear immediately that connections
have been killed (especially on iOS). This can cause us to
spuriously fail to include route hints in our invoices if we're on
mobile.

The fix is simple, if we're selecting channels to include in route
hints and we're not not connected to the peer for any of our
channels, we should simply include the hints for all channels, even
though we're disconencted.

Fixes #1768.
2022-10-18 21:46:13 +00:00
Wilmer Paulino
abe85a1f44
Add public helper to build anchor input witnesses 2022-10-18 12:23:29 -07:00
Wilmer Paulino
2fa45ae891
Add holder anchor signing support to BaseSign 2022-10-18 12:23:25 -07:00
Wilmer Paulino
843b8263d5
Document expected call frequency of ChainMonitor::process_pending_events 2022-10-18 12:23:20 -07:00
Wilmer Paulino
892f8fe843
Yield channel close bump events 2022-10-18 12:23:15 -07:00
Wilmer Paulino
e9ac2b1669
Generate ClaimEvent for HolderFundingOutput inputs from anchor channels 2022-10-18 12:23:10 -07:00
Wilmer Paulino
bac1b79fbb
Refactor generate_claim_tx to return OnchainClaim enum 2022-10-18 12:23:04 -07:00
Wilmer Paulino
40b1d4f027
Split finalize_package into separate methods per malleability 2022-10-18 12:22:59 -07:00
Wilmer Paulino
ccf318e597
Track funding amount in HolderFundingOutput
This will be useful later on when determining the appropriate fee rate
to use on the anchor transaction to bump its commitment transaction.
2022-10-18 12:22:53 -07:00
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