Commit Graph

134 Commits

Author SHA1 Message Date
Olaoluwa Osuntokun 632f230fef
htlcswitch: add quit case to initial channel state sync select in channelLink
In this commit we add a quit case to the select statement that’s
entered once a link is created. Before this commit, upon restart it
would be possible that the deamon would never ben able to shutdown as
the link would be waiting for the messages to be sent by the other
side.
2017-11-10 19:51:13 -08:00
Olaoluwa Osuntokun 431f6fc2c8
htlcswitch: update TestChannelRetransmission to print out expected balance when failure 2017-11-10 19:51:08 -08:00
Olaoluwa Osuntokun 9a6e3b5d9c
htlcswitch: disable extra logging within TestChannelRetransmission 2017-11-10 19:51:07 -08:00
Olaoluwa Osuntokun 5e2b2a5cc8
htlcswitch: move retransmissionTests var into scope of test 2017-11-10 19:51:07 -08:00
Olaoluwa Osuntokun fceec1306d
htlcswitch: update TestChannelLinkBandwidthConsistencyOverflow to account for HTLC fees 2017-11-10 19:51:06 -08:00
Olaoluwa Osuntokun 3e00b2a0a9
htlcswitch: update TestChannelLinkBandwidthConsistency to account for HTLC fees 2017-11-10 19:51:06 -08:00
Olaoluwa Osuntokun d7cc3c5015
htlcswitch: account for FundingLocked retransmission in TestChannelLinkSingleHopMessageOrdering 2017-11-10 19:51:05 -08:00
Olaoluwa Osuntokun 0dc98d9955
htlcswitch: fix TestChannelLinkMultiHopInsufficientPayment add additional comment 2017-11-10 19:51:05 -08:00
Olaoluwa Osuntokun a558925978
htlcswitch: correct godoc comment on TestLinkForwardTimelockPolicyMismatch 2017-11-10 19:51:05 -08:00
Olaoluwa Osuntokun f39ffd67ef
htlcswitch: update getChanID to be aware of FundingLocked
In this commit, we update getChanID to be aware of the FundingLocked
message as it will be retransmitted upon reconnect if both nodes think
that they’re at the very first commitment state.
2017-11-10 19:51:04 -08:00
Olaoluwa Osuntokun cb85b2bd26
htlcswitch: update createTestChannel to adhere to latest channeldb API's 2017-11-10 19:51:04 -08:00
Olaoluwa Osuntokun 9873d4ece8
htlcswitch: update mockServer to be able to fail test directly 2017-11-10 19:51:03 -08:00
Olaoluwa Osuntokun a48ceac98f
htlcswitch: update link to adhere to new channeldb API's 2017-11-10 19:51:03 -08:00
Olaoluwa Osuntokun ea334e4d47
htlcswitch: re-write channel connection re-establishment for correctness
In this commit, we’ve re-written the process of syncing the state of
channels after we reconnect. This re-write ensure correctness, and also
simplified the existing logic which would attempt to launch another
goroutine to handle requests from the switch to ensure that it doesn’t
block. This is no longer necessary as the AddPacket method that the
switch indirectly calls is non-blocking.
2017-11-10 19:51:03 -08:00
Olaoluwa Osuntokun de3af9b0c0
htlcswitch: modify Bandwidth() method on links to use more accurate accoutning
In this commit, we modify the existing implementation of the
Bandwidth() method on the default ChannelLink implementation to use
much tighter accounting. Before this commit, there was a bug wherein if
the link restarted with pending un-settled HTLC’s, and one of them was
settled, then the bandwidth wouldn’t properly be updated to reflect
this fact.

To fix this, we’ve done away with the manual accounting and instead
grab the current balances from two sources: the set of active HTLC’s
within the overflow queue, and the report from the link itself which
includes the pending HTLC’s and factors in the amount we’d need to (or
not need to) pay in fees for each HTLC.
2017-11-10 19:51:02 -08:00
Olaoluwa Osuntokun 70ed50738a
htlcswitch: utilize memoryMailBox within link, no longer spawn goroutine to forward in switch
In this commit, we’ve modified the link and the switch to start to use
the new mailBox in place of the existing synchronous message send
directly into the link’s upstream/downstream channels. With his change,
we no longer need to spawn a new goroutine each time an HTLC needs to
be forwarded, or a user payment is initiated.
2017-11-10 19:51:02 -08:00
Olaoluwa Osuntokun 890559edfa
htlcswitch: add new mailBox abstraction to the package
In this commit, we add a new abstraction to the package: the mailBox.
The mailBox is a non-blocking, concurrent safe, in-order queue for
delivering messages to a given channelLink instance. With this
abstraction in place, we can now allow the switch to no longer launch a
new goroutine for each forwarded HTLC, or instantiated user payment.
2017-11-10 19:51:01 -08:00
Andrey Samokhvalov 9247168c5d not finished index persistence 2017-11-09 16:38:58 -08:00
Andrey Samokhvalov a10ed36e8f htlcswitch+lnwallet: add malformed payment descriptor 2017-11-09 16:38:58 -08:00
Andrey Samokhvalov e29193d550 htlcswitch+channel: remove cancel reasons from channel link 2017-11-09 16:38:58 -08:00
Andrey Samokhvalov 1b4e723a5d htlcswicth+channel: switch to store onion blobs in payment descriptor
After addition of the retransmission logic in the channel link, we
should make the onion blobs persistant, the proper way to do this is
include the onion blobs in the payment descriptor rather than storing
them in the distinct struct in the channel link.
2017-11-09 16:38:57 -08:00
Andrey Samokhvalov 3555c4c463 htlcswitch: fix clean of channel link 2017-11-09 16:38:57 -08:00
Andrey Samokhvalov 291232f0c3 htlcswicth: fix deadlock
After addition of the channel reestablish message exchange we couldn't
use the Bandwidth() function, at least in the test framework.
2017-11-09 16:38:57 -08:00
Andrey Samokhvalov d70ffe93e4 htlcswitch+channel: add channel states synchronization
In this commit BOLT№2 retranmission logic for the channel link have
been added. Now if channel link have been initialised with the
'SyncState' field than it will send the lnwire.ChannelReestablish
message and will be waiting for receiving the same message from remote
side. Exchange of this message allow both sides understand which
updates they should exchange with each other in order sync their
states.
2017-11-09 16:38:57 -08:00
Andrey Samokhvalov bea9c0b52b htlcswitch: make stop of the link not in the goroutine
In order to be able to properly restart switch several times we should
have the sequential process of channel link stop. In other words if we
stopped the switch we should be sure that all channel links have been
stopped too. Addition of the goroutine during the force close was added
because of the deadlock:

Trace:
1. link:force_close_notification
2. link:wipe_channel
3. peer:switch_remove_link
4. switch:stop_link
5. link:wait <-- deadlock
2017-11-09 16:38:57 -08:00
Andrey Samokhvalov 25efbb61a4 htlcswicth.test: add 'future' payment response
Add js-like future object which might be used to wait for the response
to be received or return the error otherwise.
2017-11-09 16:38:57 -08:00
Andrey Samokhvalov e170b43615 htlcswitch.test: add server error channel to concurrent access panic
This commit where added as a measure to avoid the panic during several
server simultanoius fault. The panic happened becuase *t.Testing
structure is not concurrent safe.
2017-11-09 16:38:57 -08:00
Andrey Samokhvalov 1eb906bcfb htlcswitch.test: add message interceptor handler
Add message interceptor which checks the order and may skip the
messages which were denoted to be skipeed.
2017-11-09 16:38:56 -08:00
Jim Posen a13ad0a339 multi: Fix various typos. 2017-10-25 13:20:54 -07:00
Jim Posen 2b58a39d30 lnwallet: Simplify updateLog struct by removing redundant pointers.
The updateLog struct contains pointers that refer to the state of the
commitment chains. Instead, query the commitments directly.
2017-10-25 13:11:46 -07:00
Olaoluwa Osuntokun 21446c2872
htlcswitch: finish remainder of TestUpdateForwardingPolicy test case
In this commit, we address a lingering TODO within the
TestUpdateForwardingPolicy test case to ensure that Bob will reject the
payment the second time around due to an update in his fee policy.
2017-10-24 18:31:46 -07:00
Olaoluwa Osuntokun e02af3f877
htlcswitch: as exit node check for invoice and HTLC value match after existence 2017-10-22 18:37:00 -07:00
Olaoluwa Osuntokun 74165ca8c1
htlcswitch: update l.clearedOnionBlobs in link to use new HtlcIndex 2017-10-22 18:36:57 -07:00
Olaoluwa Osuntokun da9a771a58
htlcswitch: update timelock policy mismatch test due to time lock changes
In this commit, we update the TestLinkForwardTimelockPolicyMismatch to
instead _subtract_ time from the first HTLC extended to the initial
hop. We now subtract instead as giving intermediate hops more time
is.now permitted.
2017-10-22 18:36:56 -07:00
Olaoluwa Osuntokun 6a255fb588
htlcswitch: relax timelock verification in middle link to allow for shadow routes
In this commit, we relax the time lock verification when we realize
we’re an intermediate hop. We no longer directly assert that the time
lock we receive is _identical_, instead we allow slow slack and will
reject iff, the incoming timelock minus the outgoing time lock doesn’t
meet our delta requirements.
2017-10-22 18:36:56 -07:00
Olaoluwa Osuntokun 65c03c98d0
htlcswitch: always return an instance of ForwardingError from handleLocalDispatch
This commit modifies the errors that we return within the
handleLocalDispatch method. Rather than returning a regular error, or
simply the matching error code in some instances, we now _always_
return an instance of ForwardingError. This will allow the router to
make more intelligent decisions w.r.t routing HTLC’s as with this
information it will now be able to differentiate errors that occur
within the switch (before sending out the HTLC), from errors that occur
within the HTLC route itself.
2017-10-16 18:42:16 -07:00
Olaoluwa Osuntokun 61be23dc31
htlcswitch+server: add new field SelfKey to htlcswitch.Config
This commit adds a new field to the switch’s Config, namely the public
key of the backing lightning node. This field will soon be used to
return more detailed errors messages back to the ChannelRouter itself.
2017-10-16 18:39:17 -07:00
Olaoluwa Osuntokun 51d04e8922
htlcswitch: add new ExtraMsg field to ForwardingError
This commit adds a new field to the ForwardingError struct: ExtraMsg.
The purpose of this field is to allow the htlcswitch to tack on
additional error context to ForwardingError messages returned to the L3
router.
2017-10-16 18:15:51 -07:00
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