Commit Graph

206 Commits

Author SHA1 Message Date
Joost Jager
e0a080454a routing: track unifiedPolicyEdge
Preparation so that we can have the inbound fee available
in addition to the outgoing policy.
2024-03-31 18:12:28 +02:00
ziggie
c1b91fff14
multi: use new AdditionalEdge interface.
In the previous commit the AdditionalEdge interface was introduced
with both of its implementations `BlindedEdge` and `PrivateEdge`.
In both cases where we append a route either by a blinded route
section or private route hints we now use these new types. In
addition the `PayloadSizeFunc` type is introduced in the
`unifiedEdge` struct. This is necessary to have the payload size
function at hand when searching for a route hence not overshooting
the max sphinx package size of 1300 bytes.
2024-02-03 12:10:46 +00:00
Carla Kirk-Cohen
a75bc13230
routing/test: set outgoing timelock on non-legacy test cases
Provide valid hop payloads for tests cases that use TLV onion format.
2023-12-18 11:27:49 -05:00
yyforyongyu
678f416008
routing+docs: make sure non-MPP cannot use skipTempErr 2023-11-13 16:11:06 +08:00
yyforyongyu
8f5c6e8367
trivial: fix typos 2023-11-13 16:10:28 +08:00
yyforyongyu
6e93764bc1
routing: make sure payment hash is random in unit tests
This commit makes sure a testing payment is created via
`createDummyLightningPayment` to ensure the payment hash is unique to
avoid collision of the same payment hash being used in uint tests. Since
the tests are running in parallel and accessing db, if two difference
tests are using the same payment hash, no clean test state can be
guaranteed.
2023-11-13 16:09:12 +08:00
yyforyongyu
e46c689bf1
routing: refactor attempt makers to return pointers
Thus adding following unit tests can be a bit easier.
2023-11-13 16:09:12 +08:00
yyforyongyu
ddad6ad4c4
routing: update mockers in unit test
This commit adds more mockers to be used in coming unit tests and
simplified the mockers to be more straightforward.
2023-11-13 16:09:12 +08:00
yyforyongyu
01e3bd87ab
routing: delete old payment lifecycle related unit tests
The old payment lifecycle is removed due to it's not "unit" -
maintaining these tests probably takes as much work as the actual
methods being tested, if not more so. Moreover, the usage of the old
mockers in current payment lifecycle test is removed as it re-implements
other interfaces and sometimes implements it uniquely just for the
tests. This is bad as, not only we need to work on the actual interface
implementations and test them , but also re-implement them again in the
test without testing them!
2023-11-13 16:09:11 +08:00
yyforyongyu
da8f1c084a
channeldb+routing: add new interface method TerminalInfo
This commit adds a new interface method `TerminalInfo` and changes its
implementation to return an `*HTLCAttempt` so it includes the route for
a successful payment. Method `GetFailureReason` is now removed as its
returned value can be found in the above method.
2023-11-13 16:09:11 +08:00
yyforyongyu
3c5c37b693
routing: introduce stateStep to manage payment lifecycle
This commit adds a new struct, `stateStep`, to decide the workflow
inside `resumePayment`.

It also refactors `collectResultAsync` introducing a new channel
`resultCollected`. This channel is used to signal the payment
lifecycle that an HTLC attempt result is ready to be processed.
2023-11-13 16:09:11 +08:00
bitromortac
9a0db291b5
routing: fix tests after main refactor
Delete TestSendMPPaymentFailedWithShardsInFlight as it seems to be the
same test as TestSendMPPaymentFailed.
2023-11-13 16:09:11 +08:00
yyforyongyu
7209c65ccf
routing: split launchShard into registerAttempt and sendAttempt
This commit removes the method `launchShard` and splits its original
functionality into two steps - first create the attempt, second send the
attempt. This enables us to have finer control over "which error is
returned from which system and how to handle it".
2023-11-13 16:09:10 +08:00
Elle Mouton
84cdcd6847
multi: move DB schemas to channeldb/models
This commit moves the ChannelEdgePolicy, ChannelEdgeInfo,
ChanelAuthProof and CachedEdgePolicy structs to the `channeldb/models`
package.
2023-11-08 14:50:35 +02:00
Elle Mouton
3a17479ff4
multi: remove LightningNode from ChannelEdgePolicy
Finally, The LightningNode object is removed from ChannelEdgePolicy.
This is a step towards letting ChannelEdgePolicy reflect exactly the
schema that is on disk.

This is also nice because the `Node` object is not necessarily always
required when the ChannelEdgePolicy is loaded from the DB, so now it
only get's loaded when needed.
2023-11-08 14:50:34 +02:00
Elle Mouton
6c76d31e89
multi: let FetchLightningNode take an optional tx
In preparation for the next commit which will remove the
`*LightningNode` from the `ChannelEdgePolicy` struct,
`FetchLightningNode` is modified to take in an optional transaction so
that it can be utilised in places where a transaction exists.
2023-11-08 14:50:34 +02:00
Carla Kirk-Cohen
c9609b8214 multi: add blinded route to route requests expressed as hints
Add the option to include a blinded route in a route request (exclusive
to including hop hints, because it's incongruous to include both), and
express the route as a chain of hop hints.

Using a chain of hints over a single hint to represent the whole path
allows us to re-use our route construction to fill in a lot of the
path on our behalf.
2023-10-06 16:38:33 -07:00
Carla Kirk-Cohen
48e36d93d4 multi/refactor: add RouteRequest to hold FindRoute parameters
This commit introduces a single struct to hold all of the parameters
that are passed to FindRoute. This cleans up an already overloaded
function signature and prepares us for handling requests with blinded
routes where we need to perform some additional processing on our
para (such as extracting the target node from the blinded path).
2023-10-06 16:38:33 -07:00
yyforyongyu
34d0e5d4c5 routing+channeldb: make MPPayment into an interface
This commit turns `MPPayment` into an interface inside `routing`. Having
this interface gives us the benefit to write more granular unit tests
inside payment lifecycle. As seen from the modified unit tests, several
hacky ways of testing the `SendPayment` method is now replaced by a mock
over `MPPayment`.
2023-10-06 16:38:33 -07:00
Olaoluwa Osuntokun
b368e476c5
lnwire: update Sig to support both ECDSA and schnorr sigs
In this commit, we update the Sig type to support ECDSA and schnorr
signatures. We need to do this as the HTLC signatures will become
schnorr sigs for taproot channels. The current spec draft opts to
overload this field since both the sigs are actually 64 bytes in length.
The only consideration with this move is that callers need to "coerce" a
sig to the proper type if they need schnorr signatures.
2023-08-22 16:29:19 -07:00
positiveblue
83ccf61df9
routing: fix index out of range panic
Make sure that we do not crash the node trying to access an invalid
position for an array (-1) in `BuildRoute`.
2023-07-25 10:13:26 -07:00
bitromortac
a73581610e
routing+lnrpc: make capacity factor configurable
We make the capacity factor configurable via an lnd.conf routerrpc
apriori parameter. The capacity factor trades off increased success
probability with a reduced set of channel candidates, which may lead to
increased fees. To let users choose whether the factor is active or not,
we add a config setting where a capacity fraction of 1.0 disables the
factor. We limit the capacity fraction to values between 0.75 and 1.0.
Lower values may discard too many channels.
2023-02-24 15:28:55 +01:00
bitromortac
16986ee5c7
lnd+routing+rpc: switch mc to (external) estimator
We use a more general `Estimator` interface for probability estimation
in missioncontrol.

The estimator is created outside of `NewMissionControl`, passed in as a
`MissionControlConfig` field, to facilitate usage of externally supplied
estimators.
2023-02-14 13:34:25 +01:00
bitromortac
b0a998af8d
routing: rename apriori estimator
* we rename the current probability estimator to be the "apriori"
  probability estimator to distinguish from a different implementation
  later
* the AprioriEstimator is exported to later be able to type switch
* getLocalPairProbability -> LocalPairProbabiltiy (later part of an
  exported interface)
* getPairProbability -> getPairProbabiltiy (later part of an exported
  interface)
2023-02-07 16:18:38 +01:00
bitromortac
66ffc64776
router: return probability from findPath
The returned probability can then be used in QueryRoutes to not having
to reconstruct the probability.
2022-12-12 13:22:29 +01:00
yyforyongyu
8d49dfb07e
routing: stop tracking totalAmount in paymentLifecycle
This commit removes the field `totalAmount` from `paymentLifecycle` and
only reads it from the channeldb payment.
2022-12-07 18:38:01 +08:00
yyforyongyu
e3bc4f4cc9
htlcswitch+routing: rename GetPaymentResult to GetAttemptResult
This commit renames the method `GetPaymentResult` to be
`GetAttemptResult` to avoid potential confusion and to address the
one-to-many relationship between a payment and its attempts.
2022-12-07 18:38:01 +08:00
yyforyongyu
d1611c999a
routing: rename Fail to FailPayment
This commit renames the method `Fail` to be `FailPayment` to explicitly
address its purpose.
2022-12-07 18:38:01 +08:00
andreihod
3ed0e8ee96
lint: remove unnecessary leading newline 2022-11-11 04:23:55 -03:00
andreihod
befa1b7cf0
routing: Fix possible infinite loop on first hop misleading hint
Add ignore condition to additional edges that connect to self. These
edges are already known and avoiding these hints protect the payment
from malformed channel ids which could lead to infinite loop.

Fixes lightningnetwork#6169.

Co-authored-by: lsunsi <lsunsi@pm.me>
2022-11-11 04:23:55 -03:00
eugene
64b608bce0
routing: check pubkey when applying channel update 2022-10-27 03:09:02 +08:00
Eng Zer Jun
ff3f477ebf
routing: replace defer cleanup with t.Cleanup
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-10-13 17:47:04 +08:00
Eng Zer Jun
b5a626be78
routing: use T.TempDir to create temporary test directory
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-08-24 09:03:05 +08:00
yyforyongyu
39ac4ca92c
routing: fix unit test for SendToRoute
This commit removes the old multi shards test for `SendToRoute` as the
method doesn't support sending MPP. The original test passed due to a
flawed mocking method, where the mockers bypassed the public interfaces
to maintain their internal state, which caused a non-exsiting situation
that a temp error wouldn't fail the payment. A new unit test is added to
demonstrate the actual case.
2022-07-15 19:03:12 +08:00
yyforyongyu
d9915723dd
routing: add unit test for SendToRouteSkipTempErr 2022-07-15 19:03:12 +08:00
eugene
59fea192b7
server+routing: pass isAlias to router
This allows the router to determine what is and isn't an alias from
lnd's definition of an alias. Any ChannelAnnouncement that has an
alias ShortChannelID field is not verified on-chain. To prevent a
DoS vector from existing, the gossiper ensures that only the local
lnd node can send its ChannelAnnouncements to the router with an
alias ShortChannelID.
2022-07-07 17:10:28 -04:00
Tommy Volk
2dd11ed249 channeldb+routing: htlcs are pruned on settle 2022-07-03 21:04:34 +00:00
Tommy Volk
9a10c80bcb multi: move many t.Fatalf calls to require.NoError 2022-06-17 04:26:55 +00:00
Joost Jager
ba5abdc090
routing: add time_pref parameter to queryroutes and sendpayment 2022-04-13 20:26:46 +02:00
Andras Banki-Horvath
3d5f33a0cf
routing: fail in-flight attempts cleanly on terminal payment failure
In case of a multi shard payment with more than one in-flight shards,
one shard quitting with a terminal failure will stop the payment
lifecycle and close the `shardHandler`'s `quit` channel. In the
`collectResult` function we're waiting for the `Switch` to
asynchronously return a result for each shard. This may have been
interrupted by the aformentioned `quit` channel's closing skipping
attempt failure (or success) notification towards the control tower
and therefore skipping proper settle/fail info fill in the channel db.
Since payments have a composite state of a global failure reason and
settle/fail info for all attempts, any attempt with an unfilled
settle/fail info keeps a payment in-flight even if the payment itself
isn't in-flight anymore.
2022-04-12 11:56:33 +02:00
Oliver Gugger
7dfe4018ce
multi: use btcd's btcec/v2 and btcutil modules
This commit was previously split into the following parts to ease
review:
 - 2d746f68: replace imports
 - 4008f0fd: use ecdsa.Signature
 - 849e33d1: remove btcec.S256()
 - b8f6ebbd: use v2 library correctly
 - fa80bca9: bump go modules
2022-03-09 19:02:37 +01:00
Oliver Gugger
13f187046b
multi: fix issues reported by whitespace linter 2022-02-15 16:26:08 +01:00
Oliver Gugger
895a2e497b
multi: formatting and comment fixes 2022-02-10 11:02:02 +01:00
Oliver Gugger
dfdc2bff8b
multi: run gosimports 2022-02-10 11:02:01 +01:00
Dimitris Apostolou
530a2059e5
multi: Fix typos [skip ci] 2022-01-24 12:19:02 +02:00
Oliver Gugger
01015aced4
routing: run path finding tests against cache and DB
To make sure we don't hit any edge cases we refactor the path finding
tests to run both with and without the cache enabled.
2021-10-22 09:32:49 +02:00
Oliver Gugger
0a2ccfc52b
multi: use single read transaction for path finding
This commit partially reverts bf27d05a.
To avoid creating multiple database transactions during a single path
finding operation, we create an explicit transaction when the cached
graph is instantiated.
We cache the source node to avoid needing to look that up for every path
finding session.
The database transaction will be nil in case of the in-memory graph.
2021-10-22 09:32:49 +02:00
carla
45de686d35
multi: move bandwidth hints behind interface 2021-10-19 09:50:49 +02:00
Oliver Gugger
bf27d05aa8
routing+server: use cached graph interface 2021-09-29 17:00:05 +02:00
Oliver Gugger
1d1c42f9ba
multi: use minimal policy in cache 2021-09-29 17:00:04 +02:00