Commit Graph

1232 Commits

Author SHA1 Message Date
ziggie
dd1d57d82d routing: make sure attempts are always resolved after a timeout
We check the context of the payment lifecycle at the beginning of
the `resumepayment` loop. This will make sure we have always the
latest state of the payment before deciding on the next steps in
the function `decideNextStep`.
2025-08-12 21:25:15 +02:00
ziggie
97c4012753 multi: skip range check in pathfinder and switch for custom htlc payments 2025-08-06 14:47:41 +02:00
ziggie
e1f9e87e47 routing: return error for getBandwidth and log it 2025-07-08 16:25:39 +02:00
ziggie
7bcb65d9e6 multi: add logs to debug potential payment sending issue 2025-07-08 16:25:39 +02:00
George Tsagkarelis
128b23e813 htlcswitch+routing: PaymentBandwidth accepts channel peer pubkey argument 2025-07-02 16:52:06 +02:00
George Tsagkarelis
ab036990b5 routing+htlcswitch: ProduceHtlcExtraData uses first hop pub key 2025-07-02 16:52:05 +02:00
Elle Mouton
9b877b94c3 multi: use the "errors" package everywhere
Replace all usages of the "github.com/go-errors/errors" and
"github.com/pkg/errors" packages with the standard lib's "errors"
package. This ensures that error wrapping and `errors.Is` checks will
work as expected.
2025-07-01 20:08:12 +02:00
Oliver Gugger
ee25c228e9 Merge pull request #8330 from bitromortac/2401-bimodal-improvements
bimodal pathfinding probability improvements
2025-05-08 21:35:49 +02:00
bitromortac
07f863a2a5 routing: refine amount scaling
Mission control may have outdated success/failure amounts for node pairs
that have channels with differing capacities. In that case we assume to
still find the liquidity as before and rescale the amounts to the
according range.
2025-05-02 10:30:28 +02:00
bitromortac
5afb0de8a8 routing: forget info for contradictions
If we encounter invalid mission control data, we fall back to no
knowledge about the node pair.
2025-05-02 10:30:28 +02:00
bitromortac
5ba9619d22 routing: don't compute prob for success amounts
We skip the evaluation of probabilities when the amount is lower than
the last success amount, as the probability would be evaluated to 1 in
that case.
2025-05-02 10:30:28 +02:00
bitromortac
3819941c12 routing: regularize bimodal model
If the success and fail amounts indicate that a channel doesn't obey a
bimodal distribution, we fall back to a uniform/linear success
probability model. This also helps to avoid numerical normalization
issues with the bimodal model.

This is achieved by adding a very small summand to the balance
distribution P(x) ~ exp(-x/s) + exp((x-c)/s), 1/c that helps to
regularize the probability distribution. The distribution becomes finite
for intermediate balances where the exponentials would be evaluated to
an exact zero (float) otherwise. This regularization is effective in
edge cases and leads to falling back to a uniform model should the
bimodal model fail.

This affects the normalization to be s * (-2 * exp(-c/s) + 2 + 1/s) and
the primitive function to receive an extra term x/(cs).

The previously added fuzz seed is expected to be resolved with this.
2025-05-02 10:30:12 +02:00
bitromortac
fe32105b3e routing: add test for small scale
This test demonstrates that the current bimodal model leads to numerical
inaccuracies in a certain regime of successes and failures.
2025-05-02 10:26:13 +02:00
bitromortac
615b617cda routing: add test for fuzz test special case
This test demonstrates an error found in a fuzz test by adding a
previously found seed, which will be fixed in an upcoming commit.

The following fuzz test is expected to fail:
go test -v -fuzz=Prob ./routing/
2025-05-02 10:25:19 +02:00
bitromortac
04eec71d54 routing: use default tolerance for bimodal testing 2025-05-02 10:24:22 +02:00
bitromortac
55e7343b14 routing: update to realistic test values
The bimodal model doesn't depend on the unit, which is why updating to
more realistic values doesn't require changes in tests.

We pin the scale in the fuzz test to not invalidate the corpus.
2025-05-02 10:23:56 +02:00
bitromortac
aa9abb3d96 routing: make sure failure message is valid 2025-04-30 17:43:58 +02:00
bitromortac
a450d85309 routing: remove paymentFailure pointer
This introduces an option instead to signal whether there was a failure
for result interpretation.
2025-04-30 17:43:58 +02:00
bitromortac
4498a78cb0 routing: remove paymentFailureInfo
We can remove paymentFailureInfo since we can gate the result
interpretation on the source index, meaning that if we don't have a
source index, we deal with an unknown payment outcome because we
couldn't pinpoint the failing hop.
2025-04-30 17:43:57 +02:00
bitromortac
e5c541407f routing: make msg and index optional
This is later used to handle their nil values.
2025-04-30 17:42:53 +02:00
Oliver Gugger
56d2381f51 htlcswitch+routing: add funding blob to PaymentBandwidth
For certain auxiliary bandwidth checks we need to know the funding blob
that was present when the channel was created.
2025-04-22 21:21:11 +02:00
Olaoluwa Osuntokun
9d53617586 Merge pull request #9734 from ziggie1984/improve-logging-for-invoices-payments
Improve logging when fetching invoices and payments
2025-04-18 16:10:45 -07:00
ziggie
440ed31419 multi: add more logging when fetching invoices and payments. 2025-04-18 16:33:39 +02:00
Oliver Gugger
5fb0f43172 htlcswitch+routing: add htlc blob to ShouldHandleTraffic
Whether we should let the aux bandwidth manager decide what the
bandwidth of a channel is should also depend on whether the HTLC is a
custom HTLC, not just the channel.
2025-04-17 11:52:56 +02:00
Oliver Gugger
7381f4b221 Merge pull request #9687 from GeorgeTsagk/aux-trff-shpr-htlcview
`AuxTrafficShaper.PaymentBandwidth` uses HTLC view
2025-04-17 07:59:00 +02:00
Oliver Gugger
6d648ad90a Merge pull request #9684 from ziggie1984/master
multi: update new walletdb version in main go.mod and kvdb go.mod
2025-04-14 15:56:16 +02:00
George Tsagkarelis
d0ef248ae2 htlcswitch: add HtlcView as PaymentBandwidth argument
In order to get more precise bandwidth reports, we also need to provide
this method with the latest htlc view. Since aux data is committed to in
the channel commitment, some uncommited HTLCs may not be accounted for,
so we need to manually provide them via the HTLC view.
2025-04-14 15:42:28 +02:00
yyforyongyu
106e1e91f0 routing: patch the hash field for legacy payments
For legacy payments, the hash field will be nil, and we need to use the
payment identifier instead. We have multiple ways to fix this:

A trivial solution is we can simply call `sharder.GetHash` in
`collectResult`, and pass this hash to `attempt.Circuit()`, which ends
up multiple methods taking the hash. This is bad as it's confusing why
the methods of `HTLCAttempt` need to take another hash value, while
itself already has the info via `HTLCAttempt.Hash`. We don't want an
exceptional case to influence our main flow.

We can then patch the field `HTLCAttempt.Hash`, and set it to the
payment hash if it's nil, which can be done in `collectResult`. This is
also less optimal as it means every htlc attempts, either legacy or not,
now need to bear this context.

The best way to do this is to patch the field in
`reloadInflightAttempts`. As we are sure any new payments made won't be
legacy, and the only source of legacy payments comes from reloading
existing payments.
2025-04-11 21:52:15 +08:00
yyforyongyu
8689eeede4 routing: add regression test to catch the panic 2025-04-11 21:52:14 +08:00
ziggie
490347b056 multi: update walletdb package 2025-04-09 18:47:53 +02:00
Oliver Gugger
cf35be847c Merge pull request #9626 from ziggie1984/payment-lifecycle-small-fix
payment lifecycle small fix
2025-03-25 08:15:48 -06:00
Oliver Gugger
af2f11edff Merge pull request #9544 from lightningnetwork/elle-graphCacheBase
graph: move graph cache out of CRUD layer
2025-03-25 07:43:06 -06:00
ziggie
013e408abe multi: make validation for keysend stricter 2025-03-25 04:42:03 -05:00
ziggie
4bdd37534e routing: Ensure to not fail a payment twice 2025-03-24 09:17:09 -05:00
Elle Mouton
b497c4694e multi: add Start and Stop methods for ChannelGraph
We do this in preparation for moving channel cache population logic out
of the constructor and into the Start method. We also will later on
(when topology subscription is moved to the ChannelGraph), have a
goroutine that will need to be kicked off and stopped.
2025-03-24 15:05:47 +02:00
Elle Mouton
88398e3dd9 graph/db: let ChannelGraph init the graphCache
In this commit, we let the ChannelGraph be responsible for populating
the graphCache and then passing it to the KVStore. This is a first step
in moving the graphCache completely out of the KVStore layer.
2025-03-24 15:05:46 +02:00
Elle Mouton
00432e46f3 multi: add ChannelGraph Config struct
And use this struct to pass NewChannelGraph anything it needs to be able
to init the KVStore that it houses. This will allow us to add
ChannelGraph specific options.
2025-03-24 15:05:46 +02:00
Oliver Gugger
dac5de5ce9 htlcswitch+routing: return IsHandled from AuxBandwidth
To make it more clear whether the external traffic shaper is handling a
channel or not, we return an explicit boolean.
2025-03-13 12:26:50 -05:00
fuyangpengqi
150f72414a refactor: use a more straightforward return value
Signed-off-by: fuyangpengqi <995764973@qq.com>
2025-02-28 17:09:56 +08:00
yyforyongyu
cfa4341740 routing: fix flake in TestFilteredChainView/bitcoind_polling 2025-02-26 19:51:53 +08:00
yyforyongyu
56fa3aae34 routing/chainview: refactor TestFilteredChainView
So each test has its own miner and chainView.
2025-02-26 19:51:53 +08:00
yyforyongyu
99d49dec6a multi: change NewBitcoindBackend to take a miner as its param
Prepares for the following commit where we assert the chain backend is
synced to the miner.
2025-02-26 19:51:52 +08:00
Elle Mouton
e004447da6 multi: remove the need for the graphsession package
In this commit, we add a `GraphSession` method to the `ChannelGraph`.
This method provides a caller with access to a `NodeTraverser`. This is
used by pathfinding to create a graph "session" overwhich to perform a
set of queries for a pathfinding attempt. With this refactor, we hide
details such as DB transaction creation and transaction commits from the
caller. So with this, pathfinding does not need to remember to "close
the graph session". With this commit, the `graphsession` package may be
completely removed.
2025-02-18 10:15:41 -03:00
Elle Mouton
dfe2314a2a routing: refactor pathfinding loop
In preparation for the next commit where we will start hiding underlying
graph details such as that a graph session needs to be "closed" after
pathfinding is done with it, we refactor things here so that the main
pathfinding logic is done in a call-back.
2025-02-18 10:11:34 -03:00
Elle Mouton
5d5cfe36c7 routing: rename routing Graph method
In preparation for having the ChannelGraph directly implement the
`routing.Graph` interface, we rename the `ForEachNodeChannel` method to
`ForEachNodeDirectedChannel` since the ChannelGraph already uses the
`ForEachNodeChannel` name and the new name is more appropriate since the
ChannelGraph currently has a `ForEachNodeDirectedChannelTx` method which
passes the same DirectedChannel type to the given call-back.
2025-02-18 07:59:57 -03:00
Elle Mouton
971832c792 graph: temporarily rename some ChannelGraph methods
Add the `Tx` suffix to both ForEachNodeDirectedChannelTx and
FetchNodeFeatures temporarily so that we free up the original names for
other use. The renamed methods will be removed or unexported in an
upcoming commit. The aim is to have no exported methods on the
ChannelGraph that accept a kvdb.RTx as a parameter.
2025-02-18 07:59:57 -03:00
Elle Mouton
9068ffcd8b graph: let FetchNodeFeatures take an optional read tx
For consistency in the graphsessoin.graph interface, we let the
FetchNodeFeatures method take a read transaction just like the
ForEachNodeDirectedChannel. This is nice because then all calls in the
same pathfinding transaction use the same read transaction.
2025-02-18 07:59:57 -03:00
Olaoluwa Osuntokun
7b294311bc Merge pull request #9150 from yyforyongyu/fix-stuck-payment
routing+htlcswitch: fix stuck inflight payments
2025-02-11 18:02:02 -08:00
yyforyongyu
58e76b726e routing: add docs and monior refactor decideNextStep
Add verbose docs and refactor the method to exit early when `allow` is
true.
2025-02-10 11:36:18 +08:00
yyforyongyu
5a62528fd7 routing: improve loggings for attempt result handling 2025-02-10 11:31:50 +08:00