Commit Graph

780 Commits

Author SHA1 Message Date
eugene
ea467783e9 htlcswitch+peer: remove fwd pkgs once before tick, bump timer to 1hr
This commit changes the logic when garbage collecting forwarding
packages such that they are removed once when the function is called,
and then again upon subsequent ticks. This allows us to bump the
peer timer to 1 hour to limit the number of db transactions happening
in lnd. The forwarding packages need to be removed initially as
otherwise a flappy node will never have them garbage collected.
2020-08-31 20:52:51 -04:00
eugene
62e19185f1 htlcswitch+channeldb: single tx for removing fwdpkgs
This commit changes RemoveFwdPkg to RemoveFwdPkgs so that a single
tx is used instead of N where N is the number of fwd pkgs to remove.
2020-08-31 20:52:51 -04:00
Johan T. Halseth
85b53c357f
htlcswitch: use kvdb.View for loading fwdpkgs
Not necessary to open a write tx.
2020-08-13 14:36:48 +02:00
Joost Jager
2903505164
htlcswitch: expose custom records on intercepted packet 2020-06-27 11:00:46 +02:00
Joost Jager
363142de33
htlcswitch: expose additional fields for intercepted packets 2020-06-27 11:00:44 +02:00
Joost Jager
74db43282c
htlcswitch: encapsulate exposed packet info 2020-06-27 10:59:08 +02:00
yyforyongyu
0b573827ac htlcswitch: remove fastsha256 in test 2020-06-24 18:08:38 +08:00
Roei Erez
0f50d8b2ed htlcswitch: introducing interceptable switch.
In this commit we implement a wrapper arround the switch, called
InterceptableSwitch. This kind of wrapper behaves like a proxy which
intercepts forwarded packets and allows an external interceptor to
signal if it is interested to hold this forward and resolve it
manually later or let the switch execute its default behavior.
This infrastructure allows the RPC layer to expose interceptor
registration API to the user and by that enable the implementation
of custom routing behavior.
2020-06-18 15:12:50 +03:00
Roei Erez
1a6701122c htlcswitch: change ForwardPackets to return error
As part of the preparation to the switch interceptor feature, this
function is changed  to return error instead of error channel that
is closed automatically.
Returning an error channel has become complex to maintain and
implement when adding more asynchronous flows to the switch.
The change doesn't affect the current behavior which logs the
errors as before.
2020-06-18 12:48:21 +03:00
Joost Jager
d416ed59ea
multi: add explicit hodl invoice flag to invoice
Previously it wasn't possible to store a preimage in the invoice
database and signal that a payment should not be settled right away. The
only way to hold a payment was to insert the magic UnknownPreimage value
in the invoice database. This commit introduces a distinct flag to
signal that an invoice is a hold invoice and thereby allows the preimage
to be present in the database already.

Preparation for (key send) hodl invoices for which we already know the
preimage.
2020-06-02 07:34:23 +02:00
Conner Fromknecht
0f3ab775c7
Merge pull request #4285 from cfromknecht/pay-addr-index
channeldb: index payments by payment addr, use payment hash as fallback
2020-05-27 17:36:30 -07:00
Conner Fromknecht
cbf71b5452
channeldb+invoices: use payment addr as primary index 2020-05-26 18:55:27 -07:00
Conner Fromknecht
d0d2ca403d
multi: rename ReadTx to RTx 2020-05-26 18:20:37 -07:00
Olaoluwa Osuntokun
c2e7ca9b5f
Merge pull request #4300 from guggero/no-fastsha
channeldb+htlcswitch: don't use fastsha256 in tests
2020-05-21 17:21:50 -07:00
Conner Fromknecht
64b8aa8f11
Merge pull request #4227 from guggero/signing-abstraction
multi: Remove need for DerivePrivKey from watchtower, brontide, netann and sphinx package
2020-05-20 16:07:44 -07:00
Joost Jager
ca9c58aec9
Merge pull request #4183 from joostjager/sync-local-payment
htlcswitch: sync local payment hand-off to link
2020-05-20 11:23:15 +02:00
Oliver Gugger
a17ddc5dd1
channeldb+htlcswitch: don't use fastsha256 in tests
The btcsuite/fastsha256 registers itself in the crypto package of
golang as a replacement for sha256. This causes problems in TLS1.3
connections that require the hash implementations to be serializable
and results in the "tls: internal error: failed to clone hash" error.
By removing all uses of the library we fix that error.
2020-05-20 11:07:38 +02:00
Oliver Gugger
ee74e4ba86
server+mod: use ECDH interface for sphinx router 2020-05-20 09:05:36 +02:00
Joost Jager
8119dc7a88
htlcswitch: rename to getLocalLink
Align function name with the contained logic.
2020-05-20 08:03:52 +02:00
Joost Jager
e00840e2ab
htlcswitch: return local add failure to caller
Fixes a pre-existing issue where nil was returned when a failure had
occurred during commiting of the circuit.
2020-05-20 08:03:50 +02:00
Joost Jager
c325bf8c57
htlcswitch: sync link hand-off
This commit extends the link with a new synchronous delivery point for
local UpdateAddHTLC messages. The switch method SendHTLC is updated to
use this delivery point and thereby becomes a synchronous call.

For MPP payments, synchronous hand-off is important. Otherwise the next
pathfinding round could start without the channel balance updated yet.
2020-05-20 08:03:48 +02:00
Joost Jager
de2df5606a
htlcswitch: extract handleDownstreamUpdateAdd in link
To be able to call just the UpdateAdd logic for synchronously handled
local adds in a later commit.
2020-05-20 08:03:46 +02:00
Joost Jager
55930df70d
htlcswitch: update commit tx per downstream msg type
Unroll common code to allow splitting in separate handlers per message
type.
2020-05-20 08:03:44 +02:00
Joost Jager
b559811bf5
htlcswitch: extract updateCommitTxOrFail in link
Deduplicate code and prepare for further split of
handleDownstreamPkt.
2020-05-20 08:03:42 +02:00
Joost Jager
7afb43a012
htlcswitch: bypass main loop for local sends
There is no concurrent access in this code path, so there is no need to
pass the call through the main event loop.
2020-05-20 08:03:40 +02:00
Joost Jager
fe35d35458
htlcswitch: simplify local sends
Embed forward method into SendHTLC and remove redundant type check.
2020-05-20 08:03:38 +02:00
Joost Jager
babb0a36b4
switch/test: use external interface for testing
Previously the forward(...) method was used in forwarding tests,
while that code path isn't used for forwards in reality.
2020-05-20 08:03:36 +02:00
Olaoluwa Osuntokun
280bf8d26c
Merge pull request #4226 from breez/fix-chainrpc-crash
Fix crash when ChainNotifier is being accessed too early.
2020-05-15 16:17:40 -07:00
Joost Jager
341308327e
htlcswitch: refactor handleLocalDispatch
Move creation of the goroutine as a preparation for sync local routing
2020-05-13 17:47:19 +02:00
Olaoluwa Osuntokun
704ce02712
Merge pull request #3018 from cryptagoras/log-htlcsuccess
htlcswitch/switch: log successfully forwarded HTLCs
2020-05-11 17:55:45 -07:00
cryptagoras
0f734b769e htlcswitch/switch: log successfully forwarded HTLCs 2020-05-10 01:52:36 +03:00
Roei Erez
ae2c37e043 Ensure chain notifier is started before accessed.
The use case comes from the RPC layer that is ready before the
chain notifier which is used in the sub server.
2020-04-30 12:54:33 +03:00
Andras Banki-Horvath
556e3525ea misc: fix error formatting in multiple files 2020-04-24 19:15:08 +02:00
Andras Banki-Horvath
b93140cd3c switch: remove unused code 2020-04-24 19:15:08 +02:00
Conner Fromknecht
6ec2cc5669
htlcswitch/mailbox_test: use mailboxContext everywhere
Modifies some of the older mailbox tests that were left untouched as of
PR #4174 to use the new mailbox test context. This ensures that the
config members of each mailbox's config are properly initialized. In
certain instances where travis is slow, this would cause test panics.
2020-04-20 15:37:33 -07:00
Conner Fromknecht
b467f549b7
htlcswitch/link: return error from AddPacket 2020-04-14 22:34:59 -07:00
Conner Fromknecht
0a3fdf0271
htlcswitch/test_utils: extend PendingCommit timeout
Flakes locally on darwin.
2020-04-14 22:34:59 -07:00
Conner Fromknecht
55f90be2a5
htlcswitch/mailbox: rename Settle/Fail queue to indicate replies
This commit renames the variables associated with processing the
Settle/Fail packets to indicate that they are replies.
2020-04-14 10:51:48 -07:00
Conner Fromknecht
ec1b8d874d
htlcswitch/link: add pending commit ticker for stall detection
This commit adds a PendingCommitTicker to the link config, which allows
us to control how quickly we fail the link if the commitment dance
stalls. Now that the mailbox has the ability to cancel packets, when the
link fails it will reset the mailbox packets on exit, forcing a
reevaluation of the HTLCs against their mailbox expiries.
2020-04-14 10:51:30 -07:00
Conner Fromknecht
a8977651cc
htlcswitch/linkfailure: use whitelist for ShouldSendToPeer 2020-04-14 10:51:06 -07:00
Conner Fromknecht
6fca22be2b
htlcswitch/link: use return instead of break out
There is no clean up logic after the loop, done purely to improve
clarity.
2020-04-14 10:50:45 -07:00
Conner Fromknecht
16ad0274c9
htlcswitch/mailbox: fail on duplicate adds 2020-04-14 10:50:25 -07:00
Conner Fromknecht
e7ece11c29
htlcswitch/mailbox: fail htlcs when delayed for 1 minute
Now that packet failure is handled by the mailbox, we can now enforce
a delivery deadline and fail the packet if it the deadilne is exceeded.
This gives senders quicker feedback about tried routes, and allows them
to try alternative paths to the destination in the meantime.
2020-04-14 10:50:07 -07:00
Conner Fromknecht
1aa2dde4a4
htlcswithc/mailbox: prioritize settles/fails over adds
This commit splits the packet courier internally into two distinct
queues, one for adds and one for settles+fails. This allows us to
prioritize HTLCs that will clear the commitment transaction and make
space for adds. Previously this responsibility was handled by the
overflow queue.
2020-04-14 10:49:48 -07:00
Conner Fromknecht
37dca27a3d
htlcswitch: thread clock from switch to mailbox 2020-04-14 10:49:26 -07:00
Conner Fromknecht
63f3d0b012
htlcswitch/mailbox: advance packet head after delivery
This commit delays the advancement of the pktHead until after the
message has been delivered. This is a prepatory step, as in the future
we may fail to deliver the packet due to a deadline expiring.
2020-04-14 10:48:59 -07:00
Conner Fromknecht
564534c829
htlcswitch: move packet failure to mailbox
This commit moves the current logic for sending failures out of the link
and into the mailbox in preparation for our failing delayed htlcs. We do
so because the mailbox may need to fail packets while the link is
offline, and needs to be able to complete the task without member
methods on the link.
2020-04-14 10:48:40 -07:00
Conner Fromknecht
12bbf28e65
htlcswitch: make handleBatchFwdErrors a pure function 2020-04-14 10:48:23 -07:00
Conner Fromknecht
f3051efeb3
htlcswitch/mailbox: block until mailbox shutdown
Fixes a bug where Stop() wouldn't actually wait for the mailbox to exit.
2020-04-14 10:48:06 -07:00
Conner Fromknecht
5b38ed0b3e
htlcswitch/link: correct link log statement 2020-04-14 10:47:47 -07:00