Commit Graph

15672 Commits

Author SHA1 Message Date
yyforyongyu
168cfd7cd5
docs: emphasize the new payment status StatusInitiated 2023-11-13 16:10:51 +08:00
yyforyongyu
98378d9408
routing: unify all dummy errors to be errDummy 2023-11-13 16:10:28 +08:00
yyforyongyu
7ccb77269d
routing: log preimage when it's failed to be saved to db 2023-11-13 16:10:28 +08:00
yyforyongyu
8f5c6e8367
trivial: fix typos 2023-11-13 16:10:28 +08:00
yyforyongyu
e3dadd528b
routing: mark payment as failed when no route can be found 2023-11-13 16:10:28 +08:00
yyforyongyu
27ee917a20
docs: update release note for payment lifecycle 2023-11-13 16:10:26 +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
10052ff4f5
routing: patch unit tests for payment lifecycle
This commit adds unit tests for `resumePayment`. In addition, the
`resumePayment` has been split into two parts so it's easier to be
tested, 1) sending the htlc, and 2) collecting results. As seen in the
new tests, this split largely reduces the complexity involved and makes
the unit test flow sequential.

This commit also makes full use of `mock.Mock` in the unit tests to
provide a more clear testing flow.
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
09a5d235ec
routing: fail attempt when no shard is found or circuit generation fails 2023-11-13 16:09:11 +08:00
yyforyongyu
eda24ec871
routing: catch lifecycle quit signal in collectResult 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
yyforyongyu
e8c0226e1c
routing: add AllowMoreAttempts to decide whether more attempts are allowed 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
173900c8dc
routing: only fail attempt inside handleSwitchErr
This commit makes sure we only fail attempt inside `handleSwitchErr` to
ensure the orders in failing payment and attempts. It refactors
`collectResult` to return `attemptResult`, and expands `handleSwitchErr`
to also handle the case where the attemptID is not found.
2023-11-13 16:09:10 +08:00
yyforyongyu
703ea08316
routing: add methods checkTimeout and requestRoute
This commit refactors the `resumePayment` method by adding the methods
`checkTimeout` and `requestRoute` so it's easier to understand the flow
and reason about the error handling.
2023-11-13 16:09:10 +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
yyforyongyu
49bafc0207
routing: handle switch error when sendAttempt fails
This commit starts handling switch error inside `sendAttempt` when an
error is returned from sending the HTLC. To make sure the updated
`HTLCAttempt` is always returned to the callsite, `handleSwitchErr` now
also returns a `attemptResult`.
2023-11-13 16:09:10 +08:00
yyforyongyu
568b977a1f
routing: add new method registerAttempt
This commit adds a new method `registerAttempt` to take care of creating
and saving an htlc attempt to disk.
2023-11-13 16:09:10 +08:00
yyforyongyu
071d05e0e3
routing: unify shardResult and launchOutcome to be attemptResult
This commit removes the `launchOutcome` and `shardResult` and uses
`attemptResult` instead. This struct is also used in `failAttempt` so we
can future distinguish critical vs non-critical errors when handling
HTLC attempts.
2023-11-13 16:09:10 +08:00
yyforyongyu
4bb8db46df
routing: fail payment before attempt inside handleSwitchErr
`handleSwitchErr` is now responsible for failing the given HTLC attempt
after deciding to fail the payment or not. This is crucial as
previously, we might enter into a state where the payment's HTLC has
already been marked as failed, and while we are marking the payment as
failed, another HTLC attempt can be made at the same time, leading to
potential stuck payments.
2023-11-13 16:09:09 +08:00
yyforyongyu
8458966f02
routing: remove the abstraction shardHandler
This commit removes the unclear abstraction `shardHandler` that's used
in our payment lifecycle. As we'll see in the following commits,
`shardHandler` is an unnecessary layer and everything can be cleanly
managed inside `paymentLifecycle`.
2023-11-13 16:09:09 +08:00
Olaoluwa Osuntokun
9937b1d6de Merge branch 'dyncomms' 2023-11-10 13:30:28 -08:00
Keagan McClelland
9793fbb94b lnwire: add musig2 taproot execution messages for dynamic commitments 2023-11-10 13:29:52 -08:00
Keagan McClelland
9b1c04c210 docs: update release notes 2023-11-10 13:29:51 -08:00
Keagan McClelland
564bf852bb lnwire: add fuzz tests for new dynamic commitment message types 2023-11-10 13:29:30 -08:00
Keagan McClelland
3e84d22eeb lnwire: add TLV extension to channel_reestablish for dynamic commitments 2023-11-10 13:29:30 -08:00
Keagan McClelland
e5f7ed8ba1 lnwire: introduce message types for dynamic commitment negotiation
lnwire: add tests for dynamic commitment wire serialization
2023-11-10 13:29:30 -08:00
Keagan McClelland
b298c84d21 fn: introduce option type
this commit introduces many of the most common functions you will
want to use with the Option type. Not all of them are used
immediately in this PR.
2023-11-10 13:29:30 -08:00
Elle
a3f8011ed6
Merge pull request #8156 from hieblmi/improve-fc-logging
contractcourt: log amount if incoming htlc times out
2023-11-09 17:32:18 +02:00
Elle
6122452509
Merge pull request #8117 from ellemouton/removeDBFromChannelDBSchemas
channeldb+refactor: remove `kvdb.Backend` from channel DB schemas
2023-11-09 07:47:11 +02:00
Olaoluwa Osuntokun
6de3fea8e6
Merge pull request #8158 from Crypt-iQ/writeMessage_fix
peer: send messages in Start via writeMessage to bypass writeHandler
2023-11-08 14:54:54 -08:00
Eugene Siegel
38fb12fb4f
release-notes: update for 0.17.1 2023-11-08 16:36:04 -05:00
Eugene Siegel
955a345153
peer: send messages in Start via writeMessage to bypass writeHandler
Without this the following could happen:

* InboundPeerConnected is called while we already have an inbound
connection with the peer. This calls removePeer which calls Disconnect.
* If the peer is starting up in Start, it may be sending messages
synchronously via SendMessage(true, ...). This eventually calls the
writeMessage function which will exit if disconnect is set to 1.
* Since Disconnect was called, disconnect will be 1 and writeMessage
will exit, causing writeHandler to exit.
* If there is more than 1 message being sent, later messages will
queue in queueHandler but be unable to get into sendQueue as the
writeHandler goroutine has exited.
* The synchronous sends will be waiting on the errChan indefinitely
and startReady will never get closed meaning Disconnect will never
proceed.

The end result is that the server's mutex will be held until shutdown.

Avoid this by using writeMessage to bypass the writeHandler goroutine.
2023-11-08 16:36:02 -05:00
Elle Mouton
0e82293e45
multi: address linter issues 2023-11-08 14:50:35 +02: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
be23986eda
docs: update release notes 2023-11-08 14:50:35 +02:00
Elle Mouton
78ff28fea1
channeldb: remove unused func arguments 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
Elle Mouton
9a62a46aa3
channeldb: remove kvdb.Backend from ChannelEdgePolicy 2023-11-08 14:50:34 +02:00
Elle Mouton
f06f08f596
channeldb: remove kvdb.Backend from ChannelEdgeInfo 2023-11-08 14:50:34 +02:00
Elle Mouton
9dc1a1dfec
channeldb: convert FetchOtherNode to ChannelGraph method
To prepare for the `kvdb.Backend` member of `ChannelEdgeInfo` being
removed, the `FetchOtherNode` method is moved from the `ChannelEdgeInfo`
to the `ChannelGraph` struct.
2023-11-08 14:50:34 +02:00
Elle Mouton
6d878c65fc
channeldb: remove kvdb.Backend from LightningNode
Now that the kvdb.Backend is no longer required, it is removed from the
LightningNode struct.
2023-11-08 14:50:34 +02:00
Elle Mouton
d37f5d7e1a
autopilot: use pointer receivers for dbNode methods 2023-11-08 14:50:21 +02:00
Slyghtning
dd49c0175a
docs: update release notes 2023-11-08 10:15:52 +01:00
Slyghtning
8c04c1e7ce
contractcourt: log amount if incoming htlc times out 2023-11-08 09:56:03 +01:00