Commit Graph

392 Commits

Author SHA1 Message Date
Wilmer Paulino
8198466972
multi: move block epochs dependency from links to switch
In this commit, we move the block height dependency from the links in
the switch to the switch itself. This is possible due to a recent change
on the links no longer depending on the block height to update their
commitment fees.

We'll now only have the switch be alerted of new blocks coming in and
links will retrieve the height from it atomically.
2018-06-13 17:41:21 -07:00
Wilmer Paulino
4cc60493d2
peer+htlcswitch: randomize link commitment fee updates
In this commit, we modify the behavior of links updating their
commitment fees. Rather than attempting to update the commitment fee for
each link every time a new block comes in, we'll use a timer with a
random interval between 10 and 60 minutes for each link to determine
when to update their corresponding commitment fee. This prevents us from
oscillating the fee rate for our various commitment transactions.
2018-06-13 17:41:01 -07:00
Olaoluwa Osuntokun
e60d2b774a
htlcswitch: in event of duplicate link add, prefer newer link 2018-06-12 00:44:30 -07:00
Olaoluwa Osuntokun
3db06cf7d5
htlcswitch: in removeLink properly remove items from the interfaceIndex
In this commit, we fix a bug in the way we handle removing items from
the interfaceIndex. Before this commit, we would delete all items items
with the target public key that of the peer that owns the link being
removed. However, this is incorrect as the peer may have other links
sill active.

In this commit, we fix this by first only deleting the link from the
peer's index, and then checking to see if the index is empty after this
deletion. Only if so do we delete the index for the peer all together.
2018-06-11 23:06:22 -07:00
Olaoluwa Osuntokun
03810603ee
htlcswitch: modify interfaceIndex to no longer key 2nd lvl by ChannelLink
In this commit, we modify the interfaceIndex to no longer key the second
level of the index by the ChannelLink. Instead, we'll use the chan ID as
it's a stable identifier, unlike a reference to an interface.
2018-06-11 23:02:16 -07:00
Olaoluwa Osuntokun
2e838abb3f
Merge pull request #1350 from cfromknecht/switch-duplicate-links
Switch duplicate links
2018-06-10 18:13:26 -07:00
Conner Fromknecht
e5233c8ec7
htlcswitch/switch: reject duplicate links, purge link indexes 2018-06-09 04:33:04 -07:00
Conner Fromknecht
a779befda5
htlcswitch/switch_test: adds duplicate link add test 2018-06-09 04:28:03 -07:00
Conner Fromknecht
4dace6c941
htlcswitch/multi: update tests for lnpeer.Peer iface 2018-06-08 16:29:49 -07:00
Conner Fromknecht
4380c67124
htlcswitch/link: upgrade to use lnpeer.Peer.SendMessage 2018-06-08 16:29:49 -07:00
Conner Fromknecht
3046ea6c5b
htlcswitch/interfaces: removes Peer iface, use new lnpeer.Peer 2018-06-08 16:29:48 -07:00
Olaoluwa Osuntokun
b2e24f876b
htlcswitch: ensure the packet queue exits on stop
In this commit, we ensure that the packet queue will always exit, by
continually signalling the main goroutine until it atomically sets a
bool that indicates its has been fully shutdown. It has been observed
that at times the main goroutine will wake up (due to the signal), but
then bypass the select and actually miss the quit signal, as a result
another signal is required. We'll continue to signals in a lazy loop
until the goroutine has fully exited.
2018-06-08 13:51:37 -07:00
Olaoluwa Osuntokun
4bde4c1c26
Merge pull request #1333 from Roasbeef/min-fee-rate
funding+htlcswitch: enforce min fee rate of 253 sat/kw on commitments
2018-06-06 21:00:13 -07:00
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
8f68d0e605
funding+htlcswitch: enforce min fee rate of 253 sat/kw on commitments
In this commit, we add and enforce a min fee rate for commitment
transactions created, and also any updates we propose to the remote
party. It's important to note that this is only a temporary patch, as
nodes can dynamically raise their min fee rate whenever their mempool is
saturated.

Fixes #1330.
2018-06-05 17:50:50 -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
Olaoluwa Osuntokun
0a47b2c4ad
htlcswitch: remove linkControl in favor of a mutex guarding all channel indexes
In this commit, we simplify the switch's code a bit. Rather than having
a set of channels we use to mutate or query for the set of current
links, we'll instead now just use a mutex to guard a set of link
indexes. This serves to simplify the ode, and also make it such that we
don't need to block forwarding in order to add/remove a link.
2018-04-06 14:52:00 -07:00
Olaoluwa Osuntokun
7037d55f65
htlcswitch: perform fee related checks at forwarding time
In this commit, we fix a very old, lingering bug within the link. When
accepting an HTLC we are meant to validate the fee against the
constraints of the *outgoing* link. This is due to the fact that we're
offering a payment transit service on our outgoing link. Before this
commit, we would use the policies of the *incoming* link. This would at
times lead to odd routing errors as we would go to route, get an error
update and then route again, repeating the process.

With this commit, we'll properly use the incoming link for timelock
related constraints, and the outgoing link for fee related constraints.
We do this by introducing a new HtlcSatisfiesPolicy method in the link.
This method should return a non-nil error if the link can carry the HTLC
as it satisfies its current forwarding policy. We'll use this method now
at *forwarding* time to ensure that we only forward to links that
actually accept the policy. This fixes a number of bugs that existed
before that could result in a link accepting an HTLC that actually
violated its policy. In the case that the policy is violated for *all*
links, we take care to return the error returned by the *target* link so
the caller can update their sending accordingly.

In this commit, we also remove the prior linkControl channel in the
channelLink. Instead, of sending a message to update the internal link
policy, we'll use a mutex in place. This simplifies the code, and also
adds some necessary refactoring in anticipation of the next follow up
commit.
2018-04-06 14:52:00 -07:00
Olaoluwa Osuntokun
e30881a14c
Merge pull request #1033 from stevenroose/close-offline
rpcserver: Clarify failure closing offline channel
2018-04-06 12:20:30 -07:00
Steven Roose
445924b7a9 rpcserver: Clarify failure closing offline channel 2018-04-06 10:42:14 +02:00
Olaoluwa Osuntokun
e0adb0a4dd
Merge pull request #1007 from wpaulino/htlc-switch-stats
htlcswitch: fix periodic calculation of satoshis sent/received
2018-04-05 20:44:27 -07:00
Olaoluwa Osuntokun
ca9174e166
peer: extend SendMessage to allow callers to block until msg is sent 2018-04-04 17:43:57 -07:00
Olaoluwa Osuntokun
b3bc374ba1
htlcswitch: send a direct Error if we get a known channel error on validate commit 2018-04-04 17:41:47 -07:00
Olaoluwa Osuntokun
0dbd325fd0
htlcswitch: synchronously send the error to the peer on commitment verify fail
In this commit, we fix a slight bug in lnd. Before this commit, we would
send the error to the remote peer, but in an async manner. As a result,
it was possible for the connections to be closed _before_ the error
actually reached the remote party. The fix is simple: wait for the error
to be returned when sending the message. This ensures that the error
reaches the remote party before we kill the connection.
2018-04-04 17:38:35 -07:00
Olaoluwa Osuntokun
f53a99e18e
htlcswitch: modify the SendMessage method on the Peer interface to optionally block
In this commit, add a new argument to the SendMessage method to allow
callers to request that the method block until the message has been sent
on the socket to the remote peer.
2018-04-04 17:36:44 -07:00
Wilmer Paulino
fca0df28e9
htlcswitch: fix periodic calculation of satoshis sent/received
In this commit, we fix an issue where users would be displayed negative
amounts of satoshis either as sent or received. This can happen if the
total amount of channel updates decreases due to channels being closed.

To fix this, we properly handle a negative difference of channel
updates by updating the stats logged to only include active
channels/links to the switch.
2018-04-02 21:23:55 -04:00
Olaoluwa Osuntokun
5984cbd4ff
htlcswitch: allow overpaying for incoming payments
In this commit, we relax the constraints on accepting an exit hop
payment a bit. We'll now accept any incoming payment that _at least_
pays the invoice amount. This puts us further inline with the
specification, which recommends that nodes accept overpayment by a
certain margin.

Fixes #1002.
2018-04-02 15:58:56 -07:00
Alex Bosworth
1614fe0fa6 htlcswitch: trivial whitespace
Missing space results in `unable to get channel links: unable to locate channel link bydestination hop id` log messages
2018-03-28 15:16:06 -07:00
Olaoluwa Osuntokun
0fb7804e4a
Merge pull request #826 from cfromknecht/reextract-circuit-encrypters
Reextract Circuit Error Encrypters
2018-03-13 18:10:12 -07:00
Conner Fromknecht
f1e407cecc
htlcswitch/test_utils: DecodeOnionObfuscator - ExtractErrorEncrypter 2018-03-13 16:33:29 -07:00
Conner Fromknecht
c762fe0caa
htlcswitch/switch: pass ExtractErrorEncrypter to circuitMap 2018-03-13 16:33:29 -07:00
Conner Fromknecht
cee221f8cc
htlcswitch/mock: add Reextract NOP to mockObfuscator 2018-03-13 16:33:28 -07:00
Conner Fromknecht
2fbb0c8b92
htlcswitch/link_test: DecodeOnionObfuscator -> ExtractErrorEncrypter 2018-03-13 16:33:28 -07:00
Conner Fromknecht
d13a566284
htlcswitch/link: DecodeOnionObfuscator -> ExtractErrorEncrypter 2018-03-13 16:33:28 -07:00
Conner Fromknecht
3d487e3ca3
htlcswitch/iterator: extract error encrypter from ephemeral key 2018-03-13 16:33:28 -07:00
Conner Fromknecht
dccab0a654
htlcswitch/failure: add Reextract to SphinxErrorEncrypter 2018-03-13 16:33:28 -07:00
Conner Fromknecht
75c7349823
htlcswitch/circuit_test: use circuit map config and test rextraction 2018-03-13 16:33:28 -07:00
Conner Fromknecht
64ee4e0247
htlcswitch/circuit_map: add Config and Reextract obfuscators 2018-03-13 16:33:27 -07:00
Johan T. Halseth
b2608dd292
htlcswitch/link_test: increase timeout for message sends
This commit increases the time we wait for a message to be sent for
several test cases, aiming to decrease the false negative rate on
Travis.
2018-03-13 12:20:58 +01:00
Olaoluwa Osuntokun
45eaa70814
Merge pull request #821 from cfromknecht/switch-early-shutdown
htlcswitch/switch: improve safety of switch shutdown
2018-03-12 19:57:19 -07:00
Olaoluwa Osuntokun
8988a07bce
htlcswitch: eliminate unnecessary indentation in processRemoteAdds
In this commit, we remove a ton of unnecessary indentation in the
processRemoteAdds method. Before this commit, we had a switch statement
on the type of the entry. This was required before when the method was
generic, but now since we already know that it’s an Add, we no longer
require such a statement.
2018-03-12 18:58:46 -07:00
Olaoluwa Osuntokun
069311c47f
htlcswitch: log dangling circuits in unable to create new commitment 2018-03-12 18:58:45 -07:00
Olaoluwa Osuntokun
bdd01cccb2
htlcswitch: remove getBandwidthCmd as it's no longer needed 2018-03-12 18:58:45 -07:00
Olaoluwa Osuntokun
1af8fa9367
htlcswitch: add additional comments and logging 2018-03-12 18:58:44 -07:00
Olaoluwa Osuntokun
c285bb5814 htlcswitch+peer: remove DecodeHopIterator from ChannelLinkConfig
In this commit, we remove the DecodeHopIterator method from the
ChannelLinkConfig struct. We do this as we no longer use this method,
since we only ever use the DecodeHopIterators method now.
2018-03-12 18:58:08 -07:00
Olaoluwa Osuntokun
f2b676e93c
Merge pull request #790 from halseth/wire-error-handoff
Wire error handoff
2018-03-12 18:56:35 -07:00
Conner Fromknecht
914c59eb30
htlcswitch/switch: ensures safe shutdown of switch 2018-03-12 16:40:16 -07:00
Conner Fromknecht
5df8b52dae
multi: set initiator funding txn 2018-03-11 15:06:22 -07:00
Johan T. Halseth
33762e0f81
htlcswitch/link: fail channel on lnwire.Error 2018-03-11 17:21:23 +01:00
Olaoluwa Osuntokun
7ea9e7cf4c
htlcswitch: fix linter warning 2018-03-10 19:09:18 -08:00
Olaoluwa Osuntokun
800eea931f
build+multi: switch from bolt to bbolt
In this commit, we switch from boltbd/bolt to coreos/bbolt as the
former is no longer being actively maintained.
2018-03-10 19:01:13 -08:00
Conner Fromknecht
02489dc6c0
htlcswitch/test_utils: instantiate config with batch onoin processing 2018-03-09 21:08:44 -08:00