Commit Graph

93 Commits

Author SHA1 Message Date
Olaoluwa Osuntokun
f028eaa152
Merge pull request #1698 from cfromknecht/switch-fwdpkg-cleanup
[htlcswitch] fwdpkg cleanup
2018-08-21 18:56:15 -07:00
Conner Fromknecht
6a8507cfb5
htlcswitch/switch: ignore pending/local responses on reforward 2018-08-21 17:13:58 -07:00
Conner Fromknecht
4e093a6cd2
htlcswitch/switch: shutdown links concurrently 2018-08-20 22:05:05 -07:00
Wilmer Paulino
44e97ee72f htlcswitch: remove no longer needed destNode field in htlcPacket 2018-08-20 21:04:52 -07:00
Wilmer Paulino
7535371238 htlcswitch: implement strict forwarding for locally dispatched payments
In this commit, we address an issue that could arise when using the
SendToRoute RPC. In this RPC, we specify the exact hops that a payment
should take. However, within the switch, we would set a constraint for
the first hop to be any hop as long as the first peer was at the end of
it. This would cause discrepancies when attempting to use the RPC as the
payment would actually go through another hop with the same peer. We fix
this by explicitly specifying the channel ID of the first hop.

Fixes #1500.
Fixes #1515.
2018-08-20 21:04:47 -07:00
Conner Fromknecht
4f2137eafc
htlcswitch/switch: set SourceRef of failed packets 2018-08-20 18:47:03 -07:00
Conner Fromknecht
48b616629a
htlcswitch/switch: remove unnecessary defer closure 2018-08-18 20:19:17 -07:00
Conner Fromknecht
9047eee2f1
htlcswitch/switch: adds concrete ErrSwitchExisting 2018-08-18 20:19:17 -07:00
Conner Fromknecht
0d49a60924
htlcswitch/switch: remove go-errors pkg 2018-08-18 20:19:17 -07:00
Johan T. Halseth
887722f38f
htlcswitch/switch: add method HasActiveLink 2018-08-17 23:24:12 +02:00
Olaoluwa Osuntokun
7a113d469b
Merge pull request #1551 from cfromknecht/switch-revert-replace-link
[htlcswitch]: revert replace link, ensure removed links are stopped
2018-08-13 21:44:42 -07:00
Conner Fromknecht
f84cd14b12
htlcswitch/switch: permit link shutdown mid-forwarding
In this commit, we thread through a link's quit channel into
routeAsync, the primary helper method allowing links to send
htlcPackets through the switch. This is intended to remove
deadlocks from happening, where the link is synchronously
blocking on forwarding packets to the switch, but also
needs to shutdown.
2018-08-10 11:42:26 -07:00
Conner Fromknecht
c78e81d32b
htlcswitch/switch: synchronous stop of links after removal 2018-08-10 11:42:25 -07:00
Conner Fromknecht
1113684dc3
Revert "htlcswitch: in event of duplicate link add, prefer newer link"
This reverts commit e60d2b774a35e446081f9be2d4901925cac05379.
2018-08-10 11:42:20 -07:00
Valentine Wallace
1ffc3bb82e
multi: update to latest RegisterBlockEpochNtfn interface 2018-08-10 01:08:57 -07:00
Conner Fromknecht
e3253a4f3b
htlcswitch/switch: add log/fwd event tickers to Config 2018-08-09 02:48:07 -07:00
Olaoluwa Osuntokun
6f60f139f4 multi: switch over import paths from roasbeef/* to btcsuite/* 2018-07-13 17:05:39 -07:00
Olaoluwa Osuntokun
d889644f52
htlcswitch: use Batch for calls within ackSettleFail 2018-06-30 17:15:31 -05:00
Olaoluwa Osuntokun
bdecc5bea9
htlcswitch: update forwarding policy verification to use new time lock info 2018-06-26 17:29:42 -07:00
Olaoluwa Osuntokun
19a0eab804
htlcswitch: in removeLink use new goroutine to stop existing link
In this commit, we modify the removeLink method to be more asynchronous.
Before this commit, we would attempt to block until the peer exits.
However, it may be the case that at times time, then target link is
attempting to forward a batch of packets to the switch (forwardBatch).
Atm, this method doesn't pass in an external context/quit, so we can't
cancel this message/request. As a result, we'll now ensure that
`removeLink` doesn't block, so we can resume the switch's main loop as
soon as possible.
2018-06-25 16:04:24 -07:00
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
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
Conner Fromknecht
e5233c8ec7
htlcswitch/switch: reject duplicate links, purge link indexes 2018-06-09 04:33:04 -07:00
maurycy
3be08e69cf multi: 64bit aligment of atomic vars on arm/x86-32 2018-06-04 20:02:34 -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
Conner Fromknecht
d3403306b6
htlcswitch/switch: segment pending links from live links 2018-05-09 16:07:51 -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
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
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
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
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
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
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
Conner Fromknecht
c762fe0caa
htlcswitch/switch: pass ExtractErrorEncrypter to circuitMap 2018-03-13 16:33:29 -07: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
1af8fa9367
htlcswitch: add additional comments and logging 2018-03-12 18:58:44 -07:00
Conner Fromknecht
914c59eb30
htlcswitch/switch: ensures safe shutdown of switch 2018-03-12 16:40:16 -07: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
5fd1206da6
htlcswitch/switch: modifies forward method to support async invocation 2018-03-09 21:08:44 -08:00
Olaoluwa Osuntokun
473dfd115b
htlcswitch: add set of tests for the forwarding log 2018-03-06 13:56:11 -05:00
Olaoluwa Osuntokun
ad522a72c1
htlcswitch: add new ticker in switch to batch log forwarding events
In this commit, we extend the switch as is, to record details
concerning settled payment circuits. To do this, we introduce a new
interface to the package: the ForwardingLog. This is a tiny interface
that simply lets us abstract away the details of the storage backing of
the forwarding log.

Each time we receive a successful HTLC settle, we’ll log the full
details (chans, fees, time) as a pending forwarding log entry. Every 15
seconds, we’ll then batch flush out these entries to disk. When we’re
exiting, we’ll try to flush out all entries to ensure everything gets
recorded to disk.
2018-03-06 13:56:11 -05:00
Johan T. Halseth
80277c0517
htlcswitch: use fee rate types instead of btcutil.Amount for fee rates 2018-02-26 22:42:25 +01:00