Commit Graph

96 Commits

Author SHA1 Message Date
Olaoluwa Osuntokun
2eaa9fd683
htlcswitch: fix linter error 2017-10-10 22:19:29 -07:00
Olaoluwa Osuntokun
93c008bb46
htlcswitch: update tests to expect new ForwardingError type 2017-10-10 22:19:19 -07:00
Olaoluwa Osuntokun
12ae63101d
Htlcswitch: rename Deobfuscator and Obfuscator interfaces
This commit renames the Deobfuscator interface to ErrorDecrypter and
the Obfuscator interface to ErrorEncrypter. With this rename, the
purpose of these two interfaces are a bit clearer.

Additionally, DecryptError (which was formerly Deobfuscate) now
directly returns an ForwardingError type instead of the
lnwire.FailureMessage.
2017-10-10 22:19:19 -07:00
Olaoluwa Osuntokun
30a46291f8
htlcswitch: introduce new ForwardingError type
This commit introduces a new type to the package: ForwardingError. It
wraps an existing lnwire.FailureMessage interface, and also includes
the _source_ of the error message. By including the source of the
message, the router can now prune the set of available routes down in
order to reduce the number of subsequent failures based on the source
of the error and the type of the error itself.
2017-10-10 22:19:18 -07:00
Olaoluwa Osuntokun
ebd2dfbfd9
htlcswitch: use Tracef rather than Debugf for log examining HTLC's 2017-10-04 20:46:04 -07:00
Olaoluwa Osuntokun
685e09c904
htlcswitch: expect proper error within TestChannelLinkMultiHopInsufficientPayment 2017-10-02 22:24:57 -07:00
Olaoluwa Osuntokun
31b2f8c865
htlcswitch: modify link_test.go to assert errors directly against expected type
We must now assert directly against the expected type as the concrete
error is returned, rather than simply the code.
2017-10-02 22:14:17 -07:00
Olaoluwa Osuntokun
710c2f5dac
htlcswitch: if unable to add half in channel link, properly increment bandwidth
This commit fixes an existing bug, wherein if we failed to account for
the fact that if we we’re unable to add an HTLC for any reason other
than an overflown commitment transaction, then we wouldn’t properly
re-add the available bandwidth of the offending HTLC.
2017-10-02 22:14:15 -07:00
Olaoluwa Osuntokun
30906b1a1a
htlcswitch: within handleLocalDispatch bubble up the decode error 2017-10-02 22:14:15 -07:00
Olaoluwa Osuntokun
7038842f03
htlcswitch: in local outgoing payment attempt print a nicer error if no bandwidth
This commit modifies the error we return to the end user in the case of
an insufficient link capacity error when handling a local payment
dispatch. Previously we would return a
lnwire.CodeTemporaryChannelFailure, however, this isn’t necessary as
this is a local payment attempt and we don’t give up any sensitive
information by returning the best available bandwidth, and what we need
to complete the payment.
2017-10-02 22:14:14 -07:00
John Griffith
54c4fc4559 htlcswitch+server: pass onion error to ChannelRouter 2017-10-02 22:12:50 -07:00
Johan T. Halseth
5d03256baf
htlcswith/link: resend fundingLocked from channelLink when numUpdates == 0.
In the case where the channelLink get started and the number of
updates on this channel is zero, this means no paymenys has been
done using this channel. This might mean that the fundingLocked
never was sent successfully, so we resend to make sure this
channel gets opened correctly.
2017-10-02 13:29:50 +02:00
Olaoluwa Osuntokun
5ec3ee2ece
htlcswitch: expand TestWaitingQueueThreadSafety to assert proper queue length 2017-09-25 16:55:18 -07:00
Olaoluwa Osuntokun
7ae436e30e
htlcswitch+test: send switch back error on lnwallet.ErrInsufficientBalance
This commit fixes a bug related to swallowing an error that should go
to the switch in the case of an insufficient balance error when
attempting to add a new HTLC to the channel state machine. In this
case, an error would never be returned back to the client/switch, and
the internal processing within the channelLink would loop forever,
attempting to add an HTLC that can’t be added due to insufficient
balance to state machine itself.

We fix this issue by only treating the lnwallet.ErrMaxHTLCNumber as the
only error that prompts adding an HTLC to the overflow queue rather
than sending the error directly back to the switch.
2017-09-25 16:10:20 -07:00
Olaoluwa Osuntokun
97e730cf51
htlcswitch: fix possible deadlock bug in packetQueue
This commit fixes a possible deadlock within the packetQueue that could
be caused by the following circular waiting dependency:
packetCoordinator woken up, grabs lock, queue isn’t empty, attempts to
send packet to link (lock still held) -> channelLink has commitment
overflow, attempts to add new item to packet queue, in AddPkt grabs
Lock -> circular wait.

We avoid this scenario by *not* holding the lock within the
packetCoordinator when we attempt to send a new packet to the switch.
Instead, we release the lock before the second select statement in the
main processing loop.
2017-09-25 15:59:31 -07:00
Olaoluwa Osuntokun
2c36051a52
htlcswitch: add new TestChannelLinkBandwidthConsistencyOverflow test
This commit adds a new test case for the default implementation of the
ChannelLink to ensure that the bandwidth is updated properly in the
face of commitment transaction overflows, and the subsequent draining
of said overflown commitment transaction.
2017-09-25 13:01:34 -07:00
Olaoluwa Osuntokun
ead5b710d6
htlcswitch: add new tests for excising link bandwidth consistency
This commit adds a new test for the current default ChannelLink
implementation to ensure that the bandwidth updates for a link are
externally consistent from the PoV of callers after a modifying action.
2017-09-25 12:50:07 -07:00
Olaoluwa Osuntokun
be5b2d46a5
htlcswitch: ensure the packetQueue can handle total+partial commitment overflows
In this commit, we’ve moved away from the internal queryHandler within
the packetQueue entirely. We now use an internal queueLen variable
internally to allow callers to sample the queue’s size, and also for
synchronization purposes internally.

This commit also introduces a chan struct{} (freeSlots) that is used
internally as a semaphore. The current value of freeSlots reflects the
number of available slots within the commitment transaction. Within the
link, after an HTLC has been removed/modified, then a “slot” is freed
up. The main packetConsumer then interprets these messages as a signal
to attempt to free up a new slot within the queue itself by dumping off
to the commitment transaction.
2017-09-25 12:47:34 -07:00
Olaoluwa Osuntokun
210fc6e714
htlcswitch: eliminate internal queryHandler within packetQueue
This commit removes the internal queryHandler within the packetQueue
itself in order to make way for an upcoming commit which uses atomic
variables to report the length of the queue to outside callers.
Additionally, due to the recent change within the channeling, we no
longer need to report the total value of all pending HTLC’s to the
outside world.
2017-09-25 12:34:56 -07:00
Olaoluwa Osuntokun
64317c04f1
htlcswitch: use atomic integer to track link bandwidth internally
This commit modifies the way the bandwidth of a given channel link is
tracked, and reported externally. The prior approach pushed most of the
logic for tracking channel bandwidth into the link itself, and relied
on a report from the queue in order to determine the total available
bandwidth. This approach at times could inadvertently introduce
deadlocks when working on new features as since the query was handled
internally, it required the link to be _active_ and non-blocked in
order to respond to.

We’ve now abandoned this approach in favor of lifting the bandwidth
accounting to the highest possible abstraction layer within the link
itself. We now maintain a availableBandwidth integer that’s used
atomically within the link in response to: us adding+settling an HTLC,
and the remote party failing one of our HTLC’s.
2017-09-25 12:31:59 -07:00
Olaoluwa Osuntokun
8ecb8c70bb
htlcswitch: properly populate CommitFee for channels created in tests 2017-09-25 11:07:33 -07:00
Olaoluwa Osuntokun
457aebd16f
htlcswitch: ensure channel state machine is stopped on link stoppage 2017-09-22 15:56:12 -07:00
Olaoluwa Osuntokun
be62188962
htlcswitch: fix minor typos in switch test file 2017-09-22 15:54:43 -07:00
Olaoluwa Osuntokun
6f5ef249e4
htlcswitch: re-write link's packet overflow queue for readability+extensibility
This commit completes a full re-write of the link’s packet overflow
queue with the goals of the making the code itself more understandable
and also allowing it to be more extensible in the future with various
algorithms for handling HTLC congestion avoidance and persistent queue
back pressure.

The new design is simpler and consumes much less coroutines (no longer
a new goroutine for each active HLTC). We now implement a simple
synchronized queue using a standard condition variable.
2017-09-22 15:54:16 -07:00
Conner Fromknecht
74322a99be config+htlclink+peer: htlc hodl mode!
This commit adds a new debug mode for lnd
  called hodlhtlc. This mode instructs a node
  to refrain from settling incoming HTLCs for
  which it is the exit node. We plan to use
  this in testing to more precisely control
  the states a node can take during
  execution.
2017-09-19 11:31:52 -07:00
Olaoluwa Osuntokun
bf071c1985
htlcswitch: properly verify OutgoingCTLV+Timeout when final hop in link
This commit fixes an existing bug in the way we perform validation of
the timelock information as the final hop in the route. Previously, we
would assert that the outgoing time lock in the per-hop payload would
exactly match our time lock delta.

Instead, we should be asserting two things:
   1. That the time lock in the payload is >= the expected time lock
   2. That timeout on the HTLC is exactly equal to the payload
2017-09-12 22:04:59 +02:00
Olaoluwa Osuntokun
246164e290
htlcswitch: when generating routes in test payload for last hop in absolute timeout 2017-09-12 21:32:07 +02:00
Olaoluwa Osuntokun
f32a7a28ab
htlcswitch: if we fail to parse and onion error, return the proper lnwire.FailCode 2017-09-12 18:10:40 +02:00
Olaoluwa Osuntokun
3d95efdc0f
htlcswitch: use %x when printing the payment hash of an HTLC
We use %x as it’ll hex-encode the raw bytes, instead of printing the
individual integers within the byte array.
2017-09-12 18:08:50 +02:00
Olaoluwa Osuntokun
7f575b688e
multi: txscript.WitnessScript -> txscript.WitnessSignature 2017-08-24 18:55:32 -07:00
Olaoluwa Osuntokun
2d45552ad9
htlcswitch: properly format chan_id on failure to find 2017-08-22 20:12:56 -07:00
Olaoluwa Osuntokun
90a03954b2
htlcswitch: fix linter errors 2017-08-22 01:05:32 -07:00
Olaoluwa Osuntokun
475c3b6c0c
htlcswitch: accept over-paid HTLC's fee-wise
This commit modifies fee acceptance logic to allow remote nodes to
*over pay* for the HTLC’s sent.
2017-08-22 00:53:20 -07:00
Olaoluwa Osuntokun
4d92d23762
htlcswitch: add new UpdateForwardingPolicies method
This commit adds a new method to the HtlcSwitch:
UpdateForwardingPolicies. With this method callers are now able to
modify the forwarding policies of all, or some currently active links.
We also make a slight modification to the way that forwarding policy
updates are handled within the links themselves to ensure that we don’t
override with a zero value for any of the fields.
2017-08-22 00:53:18 -07:00
Olaoluwa Osuntokun
8a51b1a0c6
Htlcswitch: switch all accounting and forwarding decisions to use mSAT's 2017-08-22 00:53:04 -07:00
Olaoluwa Osuntokun
572eef2840
htlcswitch: add channel point prefix to HTLC examine logs 2017-08-15 17:55:06 -07:00
Conner Fromknecht
8930b4e481 htlcswitch: sync mock server shutdown of switch 2017-08-10 16:14:01 -07:00
Olaoluwa Osuntokun
0d4ee08372
htlcswitch: asynchronously handle channel close requests
This commit modifies how the htlcswitch handles close requests.
Previously it could be the case that a new channel was added, but at
the same time a channel was requested to be closed. This would result
in a circular waiting dependency: the peer contacts the switch, who
tries to contact the peer.

We eliminate this possibility by ensuring that the switch handles all
close requests asynchronously. With this, the switch won't block
indefinitely in the scenario described above.
2017-08-03 16:59:16 -07:00
Olaoluwa Osuntokun
b1205e71ec
htlcswitch: expect proper error in TestChannelLinkExpiryTooSoonMidNode 2017-08-02 21:30:32 -07:00
Olaoluwa Osuntokun
e6e4742b92
htlcswitch: add tests to exercise new HTLC expiry policies 2017-08-02 21:13:16 -07:00
Olaoluwa Osuntokun
cdb7436e34
htlcswitch: update tests to account for new HTLC expiry observence 2017-08-02 21:11:40 -07:00
Olaoluwa Osuntokun
ee1acb1610
htlcswitch: reject HTLC's which expire too soon
This commit implements a missing policy within the current ChannelLink
interface. If an HTLC arrives that is too close to the current block
height, then we’ll reject it. As otherwise, it may be possible for us
to lose an on-chain claim if they HTLC expires already or expires
before we’re able to get a commitment transaction in the chain.

As the exit node, we have a grace period that governs out decision. As
an intermediate node, we ensure that the HTLC isn’t close to expiry on
our outgoing link end if we forward it.
2017-08-02 21:10:43 -07:00
Olaoluwa Osuntokun
b6057abe93
hltcswitch: increase timeout for bi-di payment test due to travis slowness
This commit temporary increases the timeout for the
TestChannelLinkBidirectionalOneHopPayments test in order to account for
the slowness of the travis instances that our tests are run on.
2017-08-01 12:53:17 -07:00
Steven Roose
09719626e5 htlcswitch: Fix typo in logging
Because the .String() method of an amount already includes a unit string
("BTC" usually), it was printing "0.00000001 BTC satoshi".
2017-07-31 21:45:15 -07:00
Olaoluwa Osuntokun
747e0f57d1
multi: fix linter errors 2017-07-30 18:22:45 -07:00
Olaoluwa Osuntokun
8eadd09403
htlcswitch: add additional logging statement when forwarding HTLC's 2017-07-30 17:52:25 -07:00
Olaoluwa Osuntokun
976dcb7b97
htlcswitch: update TestChannelLinkSingleHopMessageOrdering to ignore rev window 2017-07-30 17:51:31 -07:00
Olaoluwa Osuntokun
1d771eeb1b
htlcswitch: ensure payments in TestChannelLinkBidirectionalOneHopPayments aren't dust
This commit modifies the TestChannelLinkBidirectionalOneHopPayments
test to ensure that each payment sent is safely above the dust
threshold. Note that the dust threshold itself is now higher due to the
existence of the HTLC covenant transactions which the HTLC values
themselves must cover.

This change ensure that this test operates under “normal” operation
conditions in order to catch any bugs introduced during a major change.
2017-07-30 17:51:27 -07:00
Olaoluwa Osuntokun
f8e536dff5
htlcswitch: update messageToString helper test func to new msgs 2017-07-30 17:51:23 -07:00
Olaoluwa Osuntokun
402112e6ee
htlcswitch: update tests utilities to be aware of new commitment design 2017-07-30 17:51:20 -07:00