Commit Graph
328 Commits
Author SHA1 Message Date
Conner Fromknecht c180065a84 htlcswitch/link: remove deadlock in htlc validation
This commit removes a possible deadlock in the switch,
which can be triggered under certain failure conditions.
Previously, we would acquire the link's read lock for
the duration of HtlcSatisfiesPolicy, though we only
need to use it grab the current policy. The deadlock could
be caused in the cases where we attempt to log the failure,
which access the read-protected ShortChanID method.
2018-06-06 18:11:36 -07:00
Olaoluwa Osuntokun 4af9da40c5 htlcswitch: fix alignment in packetQueue for ARM
Fixes #1328.
2018-06-05 12:55:06 -07:00
maurycy 3be08e69cf multi: 64bit aligment of atomic vars on arm/x86-32 2018-06-04 20:02:34 -07:00
Conner Fromknecht d62d142d18 htlcswitch/decayedlog_test: create unique test dbs
This commit changes the decayed log tests to create
a new temporary database for each test. Previously, all
instances referenced the same db path. Since the tests
are run in parallel, the tests would create/delete the
shared db out from under each other, causing flakes in
the unit tests.
2018-05-31 16:05:02 -07:00
Johan T. Halseth 4dfb4547a0 htlcswitch: remove unused Disconnect from Peer interface 2018-05-25 06:58:24 +02:00
Johan T. Halseth f95ae1cdd6 htlcswitch/link: add failed variable to ensure exit 2018-05-25 06:58:24 +02:00
Johan T. Halseth 49fd3f34d4 htlcswitch/link: settle with fake preimage if BogusSettle active 2018-05-25 06:58:24 +02:00
Johan T. Halseth 71a1aae417 htlcswitch/hodl: add flag BogusSettle
This commit adds a new hodl flag "BogusSettle" which will be used to
emulate a node trying to settle back an incoming HTLC with a fake
preimage.
2018-05-25 06:58:23 +02:00
Johan T. Halseth 88670175c7 htlcswitch/link_test: add TestChannelLinkFail 2018-05-25 06:58:23 +02:00
Johan T. Halseth 9a47494517 htlcswitch/link_test: extract adding link to switch 2018-05-25 06:58:23 +02:00
Johan T. Halseth fbec83699c htlcswitch/link: make fail() call OnChannelFailure with LinkFailureError
Adds a new closure OnChannelFailure to the link config, which is called
when the link fails. This function closure should use the given
LinkFailureError to properly force close the channel, send an error to
the peer, and disconnect the peer.
2018-05-25 06:58:23 +02:00
Johan T. Halseth 92afcbe3f4 htlcswitch/linkfailure: define LinkFailureError
This commit introduces a new error type LinkFailureError which is used
to distinguish the different kinds of errors that we can encounter
during link operation. It encapsulates the information necessary to
decide how we should handle the error.
2018-05-25 06:58:18 +02:00
Olaoluwa Osuntokun b60575fdac htlcswitch: run decay log tests in parallel 2018-05-22 16:55:08 -07:00
Olaoluwa Osuntokun 5e3b239ebc htlcswitch: ensure we don't attempt to create fwding events for fails
In this commit, we fix an existing source of a panic, that could at
times lead to a deadlock. If the circuit returned from closeCircuit
didn't have an outgoing key (as it was an incomplete forward), then we
would attempt to de-ref a nil pointer. This would trigger a panic, and
the runtime would start to unwind the stack, and execute each defer in
line. A deadlock can arise here, as in the defer at the root goroutine,
we need to grab the fwdingEventMtx. However, we already have it at the
panic site.

We fix this issue by ensuring we only attempt to add the event if it's a
_settle_ and also actually has an outgoing circuit (which it should
already, just a defensive check).
2018-05-22 16:46:55 -07:00
Olaoluwa Osuntokun b73eef12b3 Merge pull request #945 from jimpo/decayedlog
Move DecayedLog from lightning-onion to htlcswitch.
2018-05-10 20:06:53 -07:00
Conner Fromknecht 57551fbd74 htlcswitch/mailbox_test: add orchestrator pending/live test 2018-05-09 16:07:52 -07:00
Conner Fromknecht 418983cadc htlcswitch/switch_test: test send pending channel 2018-05-09 16:07:51 -07:00
Conner Fromknecht c290398b4b htlcswitch/mailbox: adds mailOrchestrator 2018-05-09 16:07:51 -07:00
Conner Fromknecht d3403306b6 htlcswitch/switch: segment pending links from live links 2018-05-09 16:07:51 -07:00
Conner Fromknecht 1dace1fed4 htlcswitch/mock: impl UpdateShortChanID w/ error 2018-05-09 16:07:25 -07:00
Conner Fromknecht 3e46a5e815 htlcswitch/link: fix UpdateShortChanID 2018-05-09 16:07:25 -07:00
Conner Fromknecht b5591cd66c htlcswitch/interfaces: return err from UpdateShortChanID 2018-05-09 16:06:49 -07:00
Conner Fromknecht f963f91a3c multi: use mutex-guarded ShortChanID() on OpenChannel 2018-05-09 16:06:49 -07:00
Conner Fromknecht 7ad56943c7 channeldb/channel: adds RefreshShortChanID 2018-05-09 16:06:49 -07:00
Johan T. Halseth 854e2a0581 link test: add TestChannelLinkWaitForRevocation
This commit adds a test where we trigger a situation which would
previously make the link think it was never in sync, and potentially
create a lot of empty state updates. This would happen if we were
waiting for a revocation, while still receiving updates from the remote.
Since in this case we could not ACK the updates because of the exhausted
revocation window, our local commitchain would extend, while the remote
chain would stall. When we finally got the revocation the local
commitment height would be far larger than the remote, and FullySynced
would return false from that point on.
2018-05-09 08:47:21 +02:00
Johan T. Halseth db254c1258 link test: add TestChannelLinkNoMoreUpdates
This commit adds a new test that makes sure we don't try to send
commitments for states where there are now new updates. Before the
recent change to FullySynced we would do this in this test scenario, as
the local an remote commitment heights would differ.

The test makes the local commitment chain extend by 1 vs the remote,
which would earlier trigger another state update, and checks taht no
such state update is made.
2018-05-09 08:47:21 +02:00
Olaoluwa Osuntokun ddcbb40898 Merge pull request #1206 from wpaulino/temp-chan-failure-update
htlcswitch+server: ensure we always send an update w/ a TempChannelFailure
2018-05-08 19:33:20 -07:00
Conner Fromknecht de9de771bb htlcswitch/link: ensure circuits are committed in-order
This commit makes the call to forwardBatch after locking
in Adds synchronous. This ensures that circuits for any Add
packets are added to the switch in the same order that they
are prescribed in the channel state. Though it is very unlikely
this case would arise, it may happen under more greater loads.

In addition, this also makes some trivial optimizations wrt. to
not spawning unnecessary goroutines if no settle/fail packets
are locked in.
2018-05-08 16:37:35 -07:00
Olaoluwa Osuntokun 72f48b6abe htlcswitch+server: ensure we always send an update w/ a TempChannelFailure
In this commit, we ensure that any time we send a TempChannelFailure
that's destined for a multi-hop source sender, then we'll always package
the latest channel update along with it.
2018-05-08 13:00:28 -04:00
littleskunk d2a6c4eec9 htlcswitch: typo fix 2018-05-07 21:33:32 -07:00
Olaoluwa Osuntokun ddd12eff9c htlcswitch: move link trimming to link start up
In this commit, we fix a race in the set of TestChannelLinkTrimCircuits*
tests. Before this commit, we would trim the circuits in the htlcManager
goroutine. However, this was problematic as the scheduling order of
goroutines isn't predictable. Instead, we'll now trim the circuits in
the Start method.

Additionally, we fix a series of off-by-2 bugs in the tests themselves.
2018-05-03 20:11:52 -07:00
Conner Fromknecht 42a9a78180 htlcswitch/link: trim fix 2018-05-02 01:12:18 -07:00
Conner Fromknecht ed4f77871a htlcswitch/circuit_map: trim using NextLocalHtlcIndex 2018-05-02 01:12:17 -07:00
Conner Fromknecht 308ad1caf6 htlcswitch/link_test: add link trimming tests 2018-05-02 01:12:17 -07:00
Jim Posen 56e65339e0 multi: Complete upgrade to new sphinx package interface. 2018-05-02 00:22:25 -07:00
Jim Posen 5d0d7a8511 htlcswitch: Move DecayedLog definition from sphinx package.
This moves over the implementation deleted in
https://github.com/lightningnetwork/lightning-onion/pull/22 to
structure package dependencies better.
2018-05-02 00:22:24 -07:00
Conner Fromknecht 9c178f3d7f htlcswitch/link_test: use hodl ExitSettle instead of HodlHTLC 2018-05-02 00:21:09 -07:00
Conner Fromknecht a36e1e6278 htlcswitch/link: adds HodlFlag breakpoints
This commit inserts an initial set of HodlFlags into
their correct places within the switch. In lieu of the
existing HtlcHodl mode, it is been replaced with a
configurable HodlMask, which is a bitvector representing
the desired breakpoints. This will allow for fine grained
testing of the switch's internals, since we can create
arbitrary delays inside a otherwise asynchronous system.
2018-05-02 00:18:51 -07:00
Conner Fromknecht 137ec37450 htlcswitch/hodl_mask_test: tests HodlMask active flags 2018-05-02 00:18:50 -07:00
Conner Fromknecht 8f786bb860 htlcswitch/hodl/mask_debug: enable Mask w/ debug flag 2018-05-02 00:18:50 -07:00
Conner Fromknecht cd43285993 htlcswitch/hodl/mask_production: disables Mask w/o debug flag 2018-05-02 00:18:50 -07:00
Conner Fromknecht 941bdcafad htlcswitch/hodl/flags: adds flags signifying switch breakpoints 2018-05-02 00:18:50 -07:00
Conner Fromknecht e677b1e9c4 htlcswitch/hodl/config: adds CLI bindings for hodl flags 2018-05-02 00:18:49 -07:00
Johan T. Halseth 5cdc7550b5 htlcswitch: use FetchAllOpenChannels
This commit changes from using FetchAllChannels to FetchAllOpenChannels,
making the check for whether a channel is pending unnecessary.
2018-04-25 09:37:25 +02:00
Johan T. Halseth bc6b8a7eeb htlcswitch/link: rename UnilateralClose -> RemoteUnilateralClose 2018-04-25 09:37:22 +02:00
Dimitris Tsapakidis 4009f7f874 multi: fix typos in comments 2018-04-17 19:03:27 -07:00
practicalswift 663c396235 multi: fix a-vs-an typos 2018-04-17 19:02:04 -07:00
Olaoluwa Osuntokun 3fa2e08665 test: update testUpdateChannelPolicy to ensure Bob's link uses the proper policies
In this commit, we update the testUpdateChannelPolicy to exercise the
recent set of changes within the switch. If one applies this test to a
fresh branch (without those new changes) it should fail. This is due to
the fact that before, Bob would attempt to apply the constraints of the
incoming link (which we updated) instead of the outgoing link. With the
recent set of changes, the test now properly passes.
2018-04-06 14:52:01 -07:00
Olaoluwa Osuntokun 8b520377bb htlcswitch: fix TestUpdateForwardingPolicy
In this commit, we fix the TestUpdateForwardingPolicy test case after
the recent modification in the way we handling validating constraints
within the link. After the recent set of changes, Bob will properly use
his outgoing link to validate the set of fee related constraints rather
than the incoming link. As a result, we need to modify the second
channel link, not the first for the test to still be applicable.
2018-04-06 14:52:01 -07:00
Olaoluwa Osuntokun ec8e3b626d htlcswitch: update unit tests to account for recent API changes 2018-04-06 14:52:00 -07:00