Commit Graph

860 Commits

Author SHA1 Message Date
yyforyongyu
dd74486b59
routing+discovery: uniform error codes in routing 2022-01-05 04:27:33 +08:00
yyforyongyu
46050fc631
multi: enhance logging for debugging peer connection 2021-12-23 15:14:37 +08:00
Oliver Gugger
b147d589c1
channeldb: add NoMigration mode
In case the channeldb package is used as a library in external tools, it
can be useful to allow read-only access to a DB. This allows such a
tool to access a DB even if not all migrations were executed, which can
be useful for recovery purposes.
To make it possible to even start the DB with a read-only backend, we
need to disable the automatic migration step.
2021-12-13 12:31:49 +01:00
Andras Banki-Horvath
8cd607447e
routing: fix memory corruption in MC store
Since bbolt returns references to internally stored data when storing
locally it's best to copy the byte slices returned or alternatively
convert them to string (which also makes a copy) to avoid crashes casued
by memory corruption.
2021-12-08 23:10:16 +01:00
Joost Jager
d997bbf6b3
channeldb/test: test with postgres 2021-10-29 10:54:44 +02:00
Olaoluwa Osuntokun
0a3bc3ee3d
Merge pull request #5840 from guggero/bolt-pathfinding-fallback
db: allow turning off in-memory graph cache for bbolt
2021-10-25 14:24:10 -07:00
Olaoluwa Osuntokun
11b157705c
Merge pull request #5598 from champo/relax_channel_disabled
routing: relax penalties for channel disabled errors
2021-10-25 14:21:36 -07:00
Juan Pablo Civile
04c0718401 routing: report success up to the failing node on FailChannelDisabled 2021-10-24 16:53:50 -03: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
Oliver Gugger
f216da32f3
lnd+channeldb: add graph cache option to channeldb
With this commit we forward the config option for disabling the channel
graph cache as a boolean to the channeldb. But we invert its meaning to
make the flag easier to understand.
2021-10-22 09:32:48 +02:00
carla
990dda4b18
multi: thread bandwidth check amount down to MayAddOutgoingHtlc
Pass htlc amount down to the channel so that we don't need to rely
on minHtlc (and pad it when the channel sets a 0 min htlc). Update
test to just check some sane values since we're no longer relying
on minHtlc amount at all.
2021-10-19 09:50:51 +02:00
carla
45de686d35
multi: move bandwidth hints behind interface 2021-10-19 09:50:49 +02:00
Oliver Gugger
a95a3728b5
lnd+channeldb: pre-allocate cache size
To avoid the channel map needing to be re-grown while we fill the cache
initially, we might as well pre-allocate it with a somewhat sane value
to decrease the number of grow events.
2021-09-29 17:00:05 +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
Oliver Gugger
15d3f62d5e
multi: use cache for source channels 2021-09-29 17:00:04 +02:00
Joost Jager
369c09be61
channeldb+routing: add in-memory graph
Adds an in-memory channel graph cache for faster pathfinding.

Original PoC by: Joost Jager
Co-Authored by: Oliver Gugger
2021-09-29 17:00:04 +02:00
Oliver Gugger
d6fa912188
multi: further decouple graph
To further separate the channel graph from the channel state, we
refactor the AddrsForNode method to use the graphs's public methods
instead of directly accessing any buckets. This makes sure that we can
have the channel state cached with just its buckets while not using a
kvdb level cache for the graph.
At the same time we refactor the graph's test to also be less dependent
upon the channel state DB.
2021-09-29 17:00:03 +02:00
Juan Pablo Civile
100abb4a30 routing: add test case for result interpretation of Channel Disabled failure 2021-09-20 12:22:51 -03:00
Juan Pablo Civile
78ce3abee5 routing: relax penalties for channel disabled errors
It was being considered a misbehaviour from the intermediate hop which
penalized that hop, which is a bit harsh considering mobile nodes. We
change it be considered as other channel update types and only penalize
the channel that failed.
2021-09-20 12:22:51 -03:00
Olaoluwa Osuntokun
650827aade
routing: add wait.NoError to TestBlockDifferenceFix assertion
This fixes a flake I've seen in the wild lately:
```
--- FAIL: TestBlockDifferenceFix (0.01s)
    router_test.go:4335: height should have been updated to 5, instead got 4
FAIL
FAIL	github.com/lightningnetwork/lnd/routing	3.865s
FAIL
```

We wrap things in an assertion loop to ensure that timing quirks don't
cause the test to fail sporadically.
2021-09-17 17:02:03 -07:00
yyforyongyu
eadbd69882
routing: increase log level when notifying topology change 2021-09-17 07:50:41 +08:00
Oliver Gugger
d9534ea108
Merge pull request #5405 from ErikEk/routing-updatechanpolicy-chan-check
routing: report invalid channels in updatechanpolicy call
2021-09-16 09:41:02 +02:00
yyforyongyu
3204e2d74b
multi: add shutdown logs in subservers
This commit adds a simple shutdown to every subserver to assist
debugging.
2021-09-15 19:52:03 +08:00
ErikEk
46e9481e6c routing: invalid channels updatechanpolicy call 2021-09-15 10:20:49 +02:00
Turtle
70dfa34f38
router: test that this change catches up router to the latest blocks 2021-09-13 21:15:50 -04:00
Turtle
147c7dc94c
router: fix 'out of order block error' by retrieving missing blocks in router
Fixes an issue where an out of order block error occurs in the router. When this occurs, the change uses the chain notifier to catch up on missed blocks and uses those blocks to fully update the routing graph with closed channels. Fixes #4710, #5132
2021-09-13 21:15:49 -04:00
Joost Jager
bd07b5f49e
routing/localchans: fix nested db tx
This commit fixes a bug where a db tx is opened within another db tx.
2021-08-24 13:43:26 +02:00
Joost Jager
3f775778c3
channeldb+routing: add tx parameter
Adds an optional tx parameter to ForAllOutgoingChannels and FetchChannel
so that data can be queried within the context of an existing database
transaction.
2021-08-24 13:43:24 +02:00
yyforyongyu
46747057c3
routing: fix race in TestSendMPPaymentFailed 2021-07-30 12:05:58 +08:00
Andras Banki-Horvath
6d80ddfe91
routing: store missioncontrol state in blocks and eliminate cursor use
This commit changes missioncontrol's store update from per payment to
every second. Updating the missioncontrol store on every payment caused
gradual slowdown when using etcd.
We also completely eliminate the use of the cursor, further reducing
the performance bottleneck.
2021-07-26 17:02:11 +02:00
Olaoluwa Osuntokun
525ef594c7
routing: don't return an error from failPayment within handleSendError
In this commit, we fix a regression introduced by a recent bug fix in
this area. Before this change, we'd inspect the error returned by
`processSendError`, and then fail the payment from the PoV of mission
control using the returned error.

A recent refactoring removed `processSendError` and combined the logic
with `tryApplyChannelUpdate` in order to introduce a new
`handleSendError` method that consolidates the logic within the
`shardHandler`. Along the way, the behavior of the prior check was
replicated in the form of a new internal `failPayment` closure. However,
the new function closure ends up returning a `channeldb.FailureReason`
instance, which is actually an `error`.

In the wild, when `SendToRoute` fails due to an error at the
destination, then this new logic caused the `handleSendErorr` method to
fail with an error, returning an unstructured error back to the caller,
instead of the usual payment failure details.

We fix this by no longer checking the `handleSendErorr` for an error as
normal. The `handleSendErorr` function as is will always return an error
of type `*channeldb.FailureReason`, therefore we don't need to treat it
as a normal error. Instead, we check for the type of error returned, and
update the control tower state accordingly.

With this commit, the test added in the prior commit now passes.

Fixes #5477.
2021-07-07 15:31:22 -07:00
Olaoluwa Osuntokun
b24edb2833
routing: modify TestSendToRouteStructuredError to return non-second chance error
In this commit, we modify the existing `TestSendToRouteStructuredError`
test to return an error that doesn't trigger the second chance logic.
Otherwise, we'll get a nil failure result from the mission control
interpretation, meaning we won't exercise the full code path. Instead,
we use a terminal error to ensure that the expected code path is hit.

As is, this test will fail as a recent refactoring causes us to return a
`channeldb.FailureReason` error, since the newly added `handleSendError`
code path in the `SendToRoute` method will return the raw error, rather
than the `shardError`, which is of the expected type.
2021-07-07 15:31:19 -07:00
yyforyongyu
4a23c08b60
routing: rename method and add err check when launch shard
A followup commit for PR#5332. In this commit we add more docs, rename
function updatePaymentState to fetchePaymentState, and add back the
check for channeldb.ErrPaymentTerminal after we launch shard.
2021-06-27 17:48:32 +08:00
yyforyongyu
cd35981569
routing: refactor update payment state tests
This commit refactors the resumePayment to extract some logics back to
paymentState so that the code is more testable. It also adds unit tests
for paymentState, and breaks the original MPPayment tests into independent tests
so that it's easier to maintain and debug. All the new tests are built
using mock so that the control flow is eaiser to setup and change.
2021-06-23 20:35:29 +08:00
yyforyongyu
e79e46ed21
routing: add mock structs for testing
This commit uses the package mock to create new mock structs, replacing
the old ones for better control when writing tests.
2021-06-23 20:35:29 +08:00
yyforyongyu
289d97fbfb
routing: rename mock structs to make them obsolete
This commit renames the mock structs by appending Old in their names. In
doing so the old tests stay unchanged and new mock structs can be added
in the following commit.
2021-06-23 20:35:28 +08:00
yyforyongyu
735e89ca37
routing: add TestSendPaymentPrivateEdgeUpdateFeeExceedsLimit 2021-06-23 18:13:04 +08:00
yyforyongyu
e05b78fb9c
routing: refactor TestSendPaymentErrorFeeInsufficientPrivateEdge 2021-06-23 18:13:04 +08:00
yyforyongyu
f31001e103
routing: make shardHandler aware of payment session
This commit adds payment session to shardHandler to enable private edge
policies being updated in shardHandler. The relevant interface and mock
are updated. From now on, upon seeing a ChannelUpdate message,
shardHandler will first try to find the target policy in additionalEdges
and update it. If nothing found, it will then check the database for
edge policy to update.
2021-06-23 18:13:04 +08:00
yyforyongyu
5df776e80b
routing: add method UpdateAdditionalEdge and GetAdditionalEdgePolicy
This commit adds the method UpdateAdditionalEdge in PaymentSession,
which allows the addtional channel edge policy to be updated from a
ChannelUpdate message. Another method, GetAdditionalEdgePolicy is added
to allow querying additional edge policies.
2021-06-23 18:13:04 +08:00
yyforyongyu
cf2b5744a1
routing: move sendErr handling in shardHandler
This commit moves the handleSendError method from ChannelRouter to
shardHandler. In doing so, shardHandler can now apply updates to the
in-memory paymentSession if they are found in the error message.
2021-06-23 18:13:04 +08:00
yyforyongyu
1656611358
routing: use shardHandler to process err in SendToRoute 2021-06-23 18:13:03 +08:00
yyforyongyu
54aacacc11
routing: use require in router test
This commit refactors some of the tests in router_test.go to use the
require package.
2021-06-23 18:13:03 +08:00
yyforyongyu
8172811e74
routing: rm hardcoded channel id in router test 2021-06-23 18:13:03 +08:00
yyforyongyu
ae6d8a9a8f
routing: parse Channel ID from json file 2021-06-23 18:13:03 +08:00
bluetegu
37d0e21f05
routing: test private edge on fee error 2021-06-23 18:13:03 +08:00
bluetegu
242a844012
routing: fix TestSendPaymentErrorRepeatedFeeInsufficient
The simulated error returned was rejected due to signature failure,
and didn't simulate correctly the insufficient fees error as
intended. Fix error by including correct signature.
2021-06-23 18:13:03 +08:00
bluetegu
fc113c7508
routing: add private key attribute in router test 2021-06-23 18:13:02 +08:00