Commit Graph

442 Commits

Author SHA1 Message Date
Conner Fromknecht
4f68d1beca
htlcswitch/switch_test: change forward() -> send() 2018-03-09 21:08:44 -08:00
Conner Fromknecht
1b7afc6da5
htlcswitch/mock: add mock fwding log to initSwitchWithDB 2018-03-09 21:08:44 -08:00
Conner Fromknecht
5fd1206da6
htlcswitch/switch: modifies forward method to support async invocation 2018-03-09 21:08:44 -08:00
Conner Fromknecht
fbb8f0bcce
htlcswitch/sequencer: adds a persistent emitter of payment IDs 2018-03-09 21:08:44 -08:00
Conner Fromknecht
e4fb420665
htlcswitch/packet: adds serialization to htlcPacket 2018-03-09 21:08:44 -08:00
Conner Fromknecht
3048dfd4be
htlcswitch/mock: adds Encode/Decode to mock obfuscator 2018-03-09 21:08:43 -08:00
Conner Fromknecht
3ae7772ecb
htlcswitch/mailbox_test: adds checks for reset and replay of pkts 2018-03-09 21:08:43 -08:00
Conner Fromknecht
9b00f83656
htlcswitch/mailbox: makes pkts replayable via Reset 2018-03-09 21:08:43 -08:00
Conner Fromknecht
3a186a02a9
htlcswitch/link_test: generate random preimages 2018-03-09 21:08:43 -08:00
Conner Fromknecht
101ad09e9f
htlcswitch/link: batches processing of locked in htlcs 2018-03-09 21:08:43 -08:00
Conner Fromknecht
2c3d35bb40
htlcswitch/interfaces: have HandleSwitchPacket return an error 2018-03-09 21:08:43 -08:00
Conner Fromknecht
403028da78
htlcswitch/circuit_test: use half adds in circuit map test 2018-03-09 21:08:42 -08:00
Conner Fromknecht
0b71f74199
htlcswitch/circuit_map: moves circuit map impl to own file 2018-03-09 21:08:42 -08:00
Conner Fromknecht
067b261602
htlcswitch/circuit: add half adds to circuit map 2018-03-09 21:08:42 -08:00
Conner Fromknecht
02c65db0d1
htlcswitch/link_test: integrate new channel update APIs 2018-03-09 17:35:54 -08:00
Conner Fromknecht
1fe7c6d431
htlcswitch/link: integrate persistence changes to lnwallet APIs 2018-03-09 17:35:53 -08:00
Conner Fromknecht
6a88ff940a
htlcswitch_/test_utils: init OpenChannels w/ Packager 2018-03-09 14:45:31 -08:00
Olaoluwa Osuntokun
51a3cab39c
htlcswitch: fix race in forwarding log test by grabbing log mtx 2018-03-08 20:11:49 -08:00
Olaoluwa Osuntokun
649be5ee0b
Merge pull request #775 from cfromknecht/sphinx-replay
Switch Persistence [1/4]: Infra for Sphinx Batched Decoding and Replay Protection
2018-03-08 23:03:01 -05:00
Conner Fromknecht
c2ec3a6ef5
htlcswitch/test_utils: use new ErrorEncrypter and HopIterator ifaces 2018-03-08 21:12:05 -05:00
Conner Fromknecht
5cbdb29bcc
htlcswitch/link_test: mock extracting of error encrypter from onion pkt 2018-03-08 21:12:04 -05:00
Conner Fromknecht
06fb524a3b
htlcswitch/mock: update mock obfuscator and iterators w/ new sphinx API 2018-03-08 21:12:04 -05:00
Conner Fromknecht
27df8d8ad1
htlcswitch/link: extract error encrypter from hop iterator 2018-03-08 21:12:04 -05:00
Conner Fromknecht
f075905d6c
htlcswitch/iterator: use batch API for sphinx router 2018-03-08 21:12:04 -05:00
Conner Fromknecht
fcf08382f7
htlcswitch/failure: add Encode/Decode to ErrorEncrypter 2018-03-08 21:12:03 -05:00
Olaoluwa Osuntokun
7031b5d217
htlcswitch: modify forwarding fee assertion to compare emperical fees
In this commit, we fix a bug that was uncovered by the recent change to
lnwire.MilliSatoshi. Rather than manually compute the diff in fees,
we’ll directly compare the fee that is given against the fee that we
expect.
2018-03-08 12:50:49 -05:00
Olaoluwa Osuntokun
4b20e805fe
multi: update packages due to recent SignDescriptor and WalletController changes 2018-03-06 16:04:03 -05: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
Olaoluwa Osuntokun
6f11fee1a4
htlcswitch: when forwarding htlcs, set the incomingHtlcAmt 2018-03-06 13:56:10 -05:00
Olaoluwa Osuntokun
d377ffafdd
htlcswitch: populate the incoming+outgoing in the payment circuit 2018-03-06 13:56:10 -05:00
Olaoluwa Osuntokun
157e052958
htlcswitch: add the incoming payment amount to the htlcPacket
We’ll need this value within the link+switch in order to fully populate
the forwarding event that will be generated if this HTLC circuit is
successfully completed.
2018-03-06 13:56:10 -05:00
Olaoluwa Osuntokun
2b8cad2f08
htlcswitch: add incoming+outgoing amounts to the PaymentCircuit
In this commit, we add the incoming+outgoing amounts if the HTLC’s that
the payment circuit consists of. With these new fields, we’ll be able
to populate the forwarding event log once the payment circuit has been
successfully completed.
2018-03-06 13:56:09 -05:00
Johan T. Halseth
4d2a36dce8
htlcswitch tests: update tests to new FeeEstimator and fee rate types 2018-02-26 22:42:25 +01: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
practicalswift
b8e1351cf3 multi: fix some recently introduced typos 2018-02-18 15:27:29 -08:00
Johan T. Halseth
509adce2ad
htlcswitch test: add TestChannelLinkBandwidthChanReserve 2018-02-08 18:35:24 -05:00
Johan T. Halseth
e6f7a46d90
htlcswitch: don't return negative value from Bandwidth()
This commits prevents the Bandwith() method from returning
a negative value if the channel reserve is larger than
the actual available balance.
2018-02-08 18:35:24 -05:00
nsa
7e84892c21
htlcswitch: account for channel reserve in Bandwidth 2018-02-08 18:35:23 -05:00
Conner Fromknecht
1dc12549d2
htlcswitch/switch: select on quit channels for switch commands
This commit fixes a deadlock scenario caused when some
switch methods are waiting for a response on the
command's done/err chan. However, no such response will
be delivered if the main event loop has already exited.
This is resolved by selecting on the command's done/err chan
and the server's quit chan simultaneously.
2018-02-07 20:43:53 -08:00
Olaoluwa Osuntokun
850abbbeb5
htlcswitch: update tests to respect recent API changes 2018-02-06 20:14:31 -08:00
Olaoluwa Osuntokun
1afadf4822
htlcswitch: properly rename struct in tests 2018-02-06 19:28:36 -08:00
Daniel McNally
8543497dcc multi: fixing it's/its typos in comments 2018-02-06 19:13:07 -08:00
practicalswift
a93736d21e multi: comprehensive typo fixes across all packages 2018-02-06 19:11:11 -08:00
Olaoluwa Osuntokun
18741831dd
Merge pull request #485 from halseth/fix-negative-balance
Use remoteACKed index when calculating availableBalance.
2018-02-05 16:23:17 -08:00
Olaoluwa Osuntokun
30dbbd69a0
funding+htlcswitch: dynamically update short chan id of existing link
In this commit, we fix an existing bug that would result in some
payments getting “stuck”. This would happen if one side restarted
before the channel was fully locked in. In this case, since upon
re-connection, the link will get added to the switch with a *short
channel ID of zero*. If A then tries to make a multi-hop payment
through B, B will fail to forward the payment, as it’ll mistakenly
think that the payment originated from a local-subsystem as the channel
ID is zero. A short channel ID of zero is used to map local payments
back to their caller.

With fix this by allowing the funding manager to dynamically update the
short channel ID of a link after it discovers the short channel ID.

In this commit, we fix a second instance of reported “stuck” payments
by users.
2018-02-03 18:14:15 -08:00
Johan T. Halseth
12d3327833
htlcswitch/link_test: update Bandwidth tests
This commit updates the tests for checking a links Bandwidth()
calculation, after the change that made us use the remoteACKedIndex
instead of the logIndex when calculating it. The main result of this
change is that we never consider incoming updates before they are
acked, when calculating the bandwidth. This is because this was
inconsistent with the state we actually end up signing later on.
2018-02-02 21:16:37 -05:00
Johan T. Halseth
ab75cd3a4d
htlcswitch/test_utils: set BatchTicker mock and BatchSize
This commit adds the mockTicker and BatchSize to the link
config. It also exits the goroutines draining the HtlcUpdates
gracefully.
2018-02-02 21:16:37 -05:00
Johan T. Halseth
cc050f183f
htlcswitch tests: add mockTicker struct 2018-02-02 21:16:37 -05:00
Johan T. Halseth
9b7b3fa3b6
channellink: make BatchTicker and BatchSize configurable
This commit introduces a new Ticker interface, that can be used
to control when the batch timer should tick. This is done to be
able to more easily control the ticker during tests. The batch
timer is wrapped in the new BatchTicker struct, and made part
of the config together with BatchSize.
2018-02-02 21:16:36 -05:00
Wilmer Paulino
f0d6d31ca4
htlcswitch: allow sending htlcs when paying invoices with a zero amount 2018-01-27 19:05:23 -05:00
Olaoluwa Osuntokun
f8adab1f1c
test: add comprehensive integration tests for on-chain HTLC handling
In this commit, we add 6 new integration tests to test the various
actions that may need to be performed when either side goes on-chain to
fully resolve HTLC’s. Many of the tests are mirrors of each other as
they test sweeping/resolving HTLC’s from both commitment transactions.
2018-01-22 19:20:02 -08:00
Olaoluwa Osuntokun
96fbc7da84
htlcswitch: fix deadlock during chainWatcher notifications 2018-01-22 19:19:59 -08:00
Olaoluwa Osuntokun
ca613a625f
htlcswitch: handleLocalDispatch can now handle locally sourced resolutions
In this commit, we update the failure case within handleLocalDispatch
to handle locally sourced resolutions. This is the case that we send a
payment out, but before it can even get past the first hop, we need to
go to chain (may have been a cascading failure). Once the HTLC is fully
resolved, we’ll send back a resolution message, however, that message
doesn’t have a failure reason populated. To properly handle this, we’ll
send back a permanent channel failure to the router.
2018-01-22 19:19:56 -08:00
Olaoluwa Osuntokun
239416f242
htlcswitch: update to use new event stream from the chainWatcher 2018-01-22 19:19:51 -08:00
Olaoluwa Osuntokun
703057c821
htlcswitch: with debughtlc+hodlhtlc mode, skip all HTLC level checks 2018-01-22 19:19:41 -08:00
Olaoluwa Osuntokun
e34850c7af
htlcswitch: update tests to account for new API changes 2018-01-22 19:19:41 -08:00
Olaoluwa Osuntokun
dbe76a1507
htlcswitch: upon restart, examine all active HTLC's, settle those that we can
In this commit, we address a lingering TODO: before this if we had a
set of HTLC’s that we knew the pre-image to on our commitment
transaction after a restart, then we wouldn’t attempt to settle them.
With this new change, we’ll check that we didn’t already retransmit the
settles for them, and check the preimage cache to see if we already
know the preimage. If we do, then we’ll immediately settle them.
2018-01-22 19:19:40 -08:00
Olaoluwa Osuntokun
ca4eb970ec
htlcswitch: move channel re-sync into distinct function 2018-01-22 19:19:40 -08:00
Olaoluwa Osuntokun
2d133acaeb
htlcswitch: after each new state update, notify callers to set of new HTLC's 2018-01-22 19:19:39 -08:00
Olaoluwa Osuntokun
1418d672f9
htlcswitch: notify the ChainArbitrator of fresh signals upon link creation 2018-01-22 19:19:39 -08:00
Olaoluwa Osuntokun
f2642a70db
htlcswitch: once we discover a pre-image, add it to the witness cache
In this commit, we add some additional logic to the case when we
receive a pre-image from an upstream peer. We’ll immediately add it to
the witness cache, as an incoming HTLC might be waiting on-chain to
fully resolve the HTLC with knowledge of the newly discovered
pre-image.
2018-01-22 19:19:39 -08:00
Olaoluwa Osuntokun
9cb3657314
htlcswitch: add new ProcessContractResolution method
In this commit, we add a new method: ProcessContractResolution. This
will be used by entities of the contract court package to notify us
whenever they discover that we can resolve an incoming contract
off-chain after the outgoing contract was fully resolved on-chain.

We’ll take a contractcourt.ResolutionMsg and map it to the proper
internal package so we can fully resolve an active circuit.
2018-01-22 19:19:38 -08:00
Johan T. Halseth
9bdb483757
htlcswitch/link: make MinHTLC non-changable
This commit specifies that the MinHTLC value for a link is static
over the lifetime of a channel, and don't process the field
during a policyUpdate.
2018-01-12 22:56:29 +01:00
Olaoluwa Osuntokun
912366ada5
htlcswitch: fix notifier goroutine leak by cancelling epoch when htlcManager exits
Before this commit, if the htlcManager unexpectedly exited (due to a
protocol error, etc), the underlying block epoch notification intent
that was created for it would never be cancelled. This would result in
tens, or hundreds of goroutine leaks as the client would never consume
those notifications.

To fix this, we move cancellation of the block epoch intent from the
Stop() method of the channel link, to the defer statement at the top of
the htlcManager.
2018-01-08 19:50:24 -08:00
Olaoluwa Osuntokun
795b5559f0
htlcswitch: print rhash in error messages of mockInvoiceRegistry 2018-01-08 19:50:23 -08:00
Olaoluwa Osuntokun
dbf6a511fc
htlcswitch: if we detect an InvalidCommitSigError, send over detailed error
In this commit, we add an additional case when handling a failed
commitment signature. If we detect that it’s a InvalidCommitSigError,
then we’ll send over an lnwire.Error message with the full details. We
don’t yet properly dispatch this error on the reciting side, but that
will be done in a follow up a commit.
2018-01-08 19:50:23 -08:00
Olaoluwa Osuntokun
e54e88ee2f
htlcswitch: ensure onion related errors always have the BadOnion bit set
In this commit, we fix a lingering protocol level bug when reporting
errors encountered during onion blob processing. The spec states that
if one sends an UpdateFailMalformedHtlc, then the error reason MUST
have the BadOnion bit set. Before this commit, we would return
CodeTemporaryChannelFailure. This is incorrect as this doesn’t have the
BadOnio bit set.
2018-01-08 19:50:21 -08:00
Olaoluwa Osuntokun
e2fe4c2955
htlcswitch: reject duplicate payments to same invoice
In this commit, we modify the way the link handles HTLC’s that it
detects is destined for itself. Before this commit if a payment hash
came across for an invoice we’d already settled, then we’d gladly
accept the payment _again_. As we’d like to enforce the norm that an
invoice is NEVER to be used twice, this commit modifies that behavior
to instead reject an incoming payment that attempts to re-use an
invoice.

Fixes #560.
2018-01-04 14:23:37 -06:00
Olaoluwa Osuntokun
b74b9fc16e
test: extend time outs in flaky tests due to Travis CI instance speed variance 2017-12-22 19:43:50 +01:00
Olaoluwa Osuntokun
9777176d7d
lnwallet: don't use persistent pointer to funding tx within channel state machine
This commit fixes a lingering bug that could at times cause
incompatibilities with other implementations when attempting a
cooperative channel close. Before this commit, we would use a pointer
to the funding txin everywhere. As a result, each time we made a new
state, or verified one, we would modify the sequence field of the main
txin of the commitment transaction. Due to this if we updated the
channel, then went to do a cooperative channel closure, the sequence of
the txin would still be set to the value we used as the state hint.

To remedy this, we now copy the txin each time when making the
commitment transaction, and also the cooperative closure transaction.
This avoids accidentally mutating the txin itself.

Fixes #502.
2017-12-22 19:26:35 +01:00
Olaoluwa Osuntokun
151a4325b1
htlcswitch: fix alignment of the packetQueue's fields for 32-bit systems (#507)
In this commit, we fix an existing issue that would cause lnd to panic
on 32-bit systems. Within the packetQueue we utilize atomics heavily.
However, it's the caller's job to ensure 64-bit alignment of 64-bit words
accessed atomically. This is documented within the sync/atomic package
as a set of known bugs.

The old alignment of this struct was:

⛰  structlayout github.com/lightningnetwork/lnd/htlcswitch packetQueue
packetQueue.queueLen int32: 0-4 (size 4, align 4)
padding: 4-8 (size 4, align 0)
packetQueue.totalHtlcAmt int64: 8-16 (size 8, align 8)
packetQueue.queueCond *sync.Cond: 16-24 (size 8, align 8)
packetQueue.queueMtx.state int32: 24-28 (size 4, align 4)
packetQueue.queueMtx.sema uint32: 28-32 (size 4, align 4)
packetQueue.queue []*github.com/lightningnetwork/lnd/htlcswitch.htlcPacket: 32-56 (size 24, align 8)
packetQueue.outgoingPkts chan *github.com/lightningnetwork/lnd/htlcswitch.htlcPacket: 56-64 (size 8, align 8)
packetQueue.freeSlots chan struct{}: 64-72 (size 8, align 8)
packetQueue.wg.noCopy sync.noCopy: 72-72 (size 0, align 1)
packetQueue.wg.state1 [12]byte: 72-84 (size 12, align 1)
packetQueue.wg.sema uint32: 84-88 (size 4, align 4)
packetQueue.quit chan struct{}: 88-96 (size 8, align 8)

After this commit, the new alignment of this sturct is:

⛰  structlayout  -json github.com/lightningnetwork/lnd/htlcswitch packetQueue | structlayout-optimize
packetQueue.queue []*github.com/lightningnetwork/lnd/htlcswitch.htlcPacket: 0-24 (size 24, align 8)
packetQueue.wg struct: 24-40 (size 16, align 8)
packetQueue.freeSlots chan struct{}: 40-48 (size 8, align 8)
packetQueue.queueCond *sync.Cond: 48-56 (size 8, align 8)
packetQueue.queueMtx struct: 56-64 (size 8, align 8)
packetQueue.outgoingPkts chan *github.com/lightningnetwork/lnd/htlcswitch.htlcPacket: 64-72 (size 8, align 8)
packetQueue.totalHtlcAmt int64: 72-80 (size 8, align 8)
packetQueue.quit chan struct{}: 80-88 (size 8, align 8)
packetQueue.queueLen int32: 88-92 (size 4, align 8)
padding: 92-96 (size 4, align 0)

Fixes #505, and #463.
2017-12-22 16:32:11 +01:00
Olaoluwa Osuntokun
3b986b4c14
htlcswitch: extend timeouts within bandwidth consistency tests 2017-12-21 11:47:45 +01:00
Matt Drollette
adf0d98194 multi: fix several typos in godoc comments 2017-12-17 18:40:05 -08:00
Jim Posen
88dc73adb0 htlcswitch: Fix failure error handling on outgoing adds. 2017-12-14 17:53:58 -08:00
Jim Posen
813c012ffe htlcswitch: mockChannelLink adds to circuit map to simplify tests. 2017-12-14 17:53:58 -08:00
Jim Posen
6ea533275c htlcswitch: Remove obsolete fields from htlcPacket. 2017-12-14 17:53:58 -08:00
Jim Posen
40fb0ddcfc htlcswitch: Assign each pending payment a unique ID.
This simplifies the pending payment handling code because it allows it
be handled in nearly the same way as forwarded HTLCs by treating an
empty channel ID as local dispatch.
2017-12-14 17:53:58 -08:00
Jim Posen
4a29fbdab2 htlcswitch: Rename htlcPacket fields for clarity.
The src/dest terminology for routing packets is kind of confusing
because the source HTLC may not be the source of the packet for
settles/fails traversing the circuit in the opposite direction. This
changes the nomenclature to incoming/outgoing and always references
the HTLCs themselves.
2017-12-14 17:53:58 -08:00
Jim Posen
66e654bb42 htlcswitch: Unit tests for CircuitMap. 2017-12-14 17:53:58 -08:00
Jim Posen
317b44e220 lnwallet: Change channel update methods to accept HTLC ID.
Previously, some methods on a LightningChannel like SettleHTLC and
FailHTLC would identify HTLCs by payment hash. This would not always
work correctly if there are multiple HTLCs with the same payment hash,
so instead we change these methods to identify HTLCs by their unique
identifiers instead.
2017-12-14 17:53:58 -08:00
Jim Posen
1328e61c00 htlcswitch: Change circuit map keys to (channel ID, HTLC ID).
This changes the circuit map internals and API to reference circuits
by a primary key of (channel ID, HTLC ID) instead of paymnet
hash. This is because each circuit has a unique offered HTLC, but
there may be multiple circuits for a payment hash with different
source or destination channels.
2017-12-14 17:53:58 -08:00
Jim Posen
bc8d674958 htlcswitch: Remove constructor functions for htlcPacket.
The constructor functions have no additional logic other than passing
function parameters into struct fields. Given the large function
signatures, it is more clear to directly construct the htlcPacket in
client code than call a function with lots of positional arguments.
2017-12-14 17:53:58 -08:00
Olaoluwa Osuntokun
4cca23264d
htlcswitch: add new default case when handling UpdateFailMalformedHLTC
In this commit, we modify the existing logic to handle
UpdateFailMalformedHLTC message from an incoming peer. Rather than fail
the Chanel if they give us an invalid failure code, we’ll instead treat
it as a temporary channel failure so we can continue to forward the
error.
2017-12-12 11:42:47 -08:00
Olaoluwa Osuntokun
8da46e0b5a
htlcswitch: add tests to ensure we don't forward to inactive links 2017-12-10 16:19:47 -08:00
Olaoluwa Osuntokun
c3d345b575
htlcswitch: don't add UpdateFee to channel if not able to forward
This commit is a follow up to a prior commit which skipped sending the
commitment sig message (and sending out the update fee) message if the
channel wasn’t yet able to forward any HTLC’s. We’ll modify the prior
commit to not add the fee update to the channel at all. Otherwise, we
risk a state desynchronization.
2017-12-10 16:19:21 -08:00
Olaoluwa Osuntokun
b40c84833e
htlcswitch: add additional error logging during onion process failures 2017-12-10 15:52:37 -08:00
Ben Congdon
720a8c7e96 htlcswitch: Only send UpdateFee message when channel is eligible
This commit adds a check to `updateChannelFee` which skipssending the
`update_fee` message when the channel is not eligable for forwarding
messages (likely due to the channel's `RemoteNextRevocation` not yet
being set).

This addresses #470.
2017-12-10 10:46:30 -08:00
Olaoluwa Osuntokun
8a7085f8b4
htlcswitch: ensure we don't dispatch local HTLC's to link that aren't eligible to forward
This commit fixes an existing bug wherein we would incorrectly attempt
to forward and HTLC to a link that wasn’t yet eligible for forwarding.
This would occur when we’ve added a link to the switch, but haven’t yet
received a FundingLocked message for the channel. As a result, the
channel won’t have the next revocation point available. A logic error
prior to this commit would skip tallying the largest bandwidth rather
than skipping examining the link all together.

Fixes #464.
2017-12-07 19:03:27 -08:00
Olaoluwa Osuntokun
669c2ee1a0
htlcswitch: only re-send FundingLocked if the channel is fully confirmed 2017-12-06 16:43:02 -08:00
Olaoluwa Osuntokun
be1a96b78a
htlcswitch: ensure links are eligible to forward when selecting outgoing links
In this commit, when selecting a candidate link to forward a payment,
we’ll ensure that it’s actually able to take on the HTLC. Otherwise,
we’ll skip over the link itself. Currently, a link is only fully
eligible for forwarding, *after* we’ve received and fully processed the
FundingLocked message.
2017-12-06 16:42:58 -08:00
Olaoluwa Osuntokun
36956d390f
htlcswitch: add new method to the ChannelLink interface, EligibleToForward
In this commit, we add a new method to the ChanneLink interface:
EligibleToForward. This method allows a link to be added to the switch,
but in an intermediate state which indicates that it isn’t yet ready to
forward any incoming HTLC’s.
2017-12-06 16:42:57 -08:00
Olaoluwa Osuntokun
260ff8831a
htlcswitch: update UpdateFee usage due to recent API change 2017-11-30 22:17:56 -08:00
Olaoluwa Osuntokun
62473009b5
htlcswitch: within link, with each new block, check to see if commit fee should change
In this commit we add a new case to the main select statement within a
channel link. This select statement will serve as a Sipping Bird which
will check the network fee rate (as returned by the fee estimator) and
compare that to the fee on the commitment transaction. Using the
shouldAdjustCommitFee function, we determine if we should update the
commitment fee. If so, then we’ll send an UpdateFee message and also
trigger a new commitment update.

We also add a new unit test: TestChannelLinkUpdateCommitFee to ensure
that we update the fee accordingly if the fee increases or decreases by
a large portion.
2017-11-23 23:10:19 -06:00
Olaoluwa Osuntokun
c560200ba1
htlcswitch: add new shouldAdjustCommitFee helper function
In this commit, we add a new helper function to the link which will be
utilized in a later commit. This helper function will help us determine
if we should update the commitment fee, in response to a change in the
network fee return by our fee estimators.
2017-11-23 23:10:19 -06:00
Olaoluwa Osuntokun
5a51600f95
htlcswitch: update CloseLink to accept ideal fee rate 2017-11-23 23:10:12 -06:00
Olaoluwa Osuntokun
25082f0b5b
htlcswitch: update WipeChannel on Peer interface to simply take the chanPoint
The WipeChannel method doesn’t need to take the channel itself, as any
relevant indexes should be able to be queried based on the channel
point along.
2017-11-23 23:10:10 -06:00
Olaoluwa Osuntokun
3aabbce551
htlcswitch: update tests to adhere to new FeeEstimator changes 2017-11-23 23:10:10 -06:00
Olaoluwa Osuntokun
b31e94573b
htlcswitch: properly set HtlcBasePoint in createTestChannel 2017-11-16 20:00:08 -08:00
Olaoluwa Osuntokun
6afebfba5d
htlcswitch: update link to match latest ChanSyncMsg API change 2017-11-16 20:00:06 -08:00
Olaoluwa Osuntokun
d7aa769275
htlcswitch: add additional sleep to end of TestChannelLinkBidirectionalOneHopPayments 2017-11-15 18:25:01 -08:00
Olaoluwa Osuntokun
e7e426a1cc
Merge pull request #398 from halseth/sighash-signdesc-hashtype
Use dynamic SigHash type when signing transactions.
2017-11-11 17:30:54 -08:00
Olaoluwa Osuntokun
b6f64932c2
htlcswitch: face race condition in unit tests by returning invoice
In this commit we modify the primary InvoiceRegistry interface within
the package to instead return a direct value for LookupInvoice rather
than a pointer. This fixes an existing race condition wherein a caller
could modify or read the value of the returned invoice.
2017-11-11 16:09:29 -08:00
Olaoluwa Osuntokun
7d10ab3ae8
htlcswitch: increase timeouts of tests due to race condition detector 2017-11-11 15:07:02 -08:00
Olaoluwa Osuntokun
9d6e9c73f1
htlcswitch: modify TestChannelRetransmission to exit on first test failure 2017-11-11 15:06:25 -08:00
Olaoluwa Osuntokun
849abde253
htlcswitch: fix mockInvoiceRegistry implementation of SettleInvoice
In this commit we fix the implementation of SettleInvoice by ensuring
the lock is held for the duration of the method.
2017-11-11 15:05:58 -08:00
Olaoluwa Osuntokun
a702aace9c
htlcswitch: add new concurrentTester wrapper struct
In this commit we add a new wrapper struct for the testing.T struct
that allows multiple clients to attempt to fail a given test at the
same time.
2017-11-11 15:05:15 -08:00
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
Johan T. Halseth
df17a680c4
htlcswitch test: use signDesc.HashType instead of SigHashAll in mock
signer.
2017-11-06 14:31:22 +01: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
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
Olaoluwa Osuntokun
2d1a598b66
htlcswitch: modify channelLink to use new create+verify commitment API 2017-07-30 17:51:16 -07:00
Olaoluwa Osuntokun
f7c4237686
htlcswitch: remove initial revocation window extension in channelLink
We can safely remove the initial revocation window extension as this
has gone away with the new state machine. We instead now just fill the
window once the channel has been opened, and then maintain a fixed
window size of 2 from there on.
2017-07-30 17:51:13 -07:00
Olaoluwa Osuntokun
a04fa76a4c
lnwire+htlcswitch: minor grammatical, formatting fixes after error PR 2017-07-14 20:08:37 -07:00
Andrey Samokhvalov
79b8d26b1a htlcswitch+router+server: handle payment error topology updates
In previous commits we have intoduced the onion errors. Some of this
errors include lnwire.ChannelUpdate message. In order to change
topology accordingly to the received error, from nodes where failure
have occured, we have to propogate the update to the router subsystem.
2017-07-14 19:08:04 -07:00
Andrey Samokhvalov
2d378b3280 htlcswitch+router: add onion error obfuscation
Within the network, it's important that when an HTLC forwarding failure
occurs, the recipient is notified in a timely manner in order to ensure
that errors are graceful and not unknown. For that reason with
accordance to BOLT №4 onion failure obfuscation have been added.
2017-07-14 19:08:04 -07:00
Andrey Samokhvalov
ef73062c14 peer+server+htlcswitch: add reason to disconnnect function
In order to recognize exact reason of the disconnect the additional
field have been added in the disconnect function.
2017-07-14 19:08:04 -07:00
Johan T. Halseth
f4db249cb8 htlcswitch: handle update_fee message received from peer.
This commit makes the channellink update a channel's fee
if an update_fee message is received from the peer.
2017-07-14 16:39:15 -07:00
Olaoluwa Osuntokun
01d54c29af
htlcswitch: restore the ability to properly handle debughtlc recv's
This commit fixes a regression introduce in the prior commit which
added full verification of the per-hop payloads to the ChannelLink
interface. When this was initially implemented, the added checks
weren’t guarded on the existence of debughtlc’s. As a result,
debughtlc’s would be rejected as they don’t match the expected invoice
value.

This commit fixes that issue by only checking the hop payload if debug
HTLC mode isn’t on.
2017-07-04 15:58:23 -07:00
Andrey Samokhvalov
c13e36617c htlcswitch: return time result from bidirection test 2017-06-26 20:26:27 +03:00
Andrey Samokhvalov
8fa2b95c12 lnd: remove seelog logger
The btclog package has been changed to defining its own logging
interface (rather than seelog's) and provides a default implementation
for callers to use.

There are two primary advantages to the new logger implementation.

First, all log messages are created before the call returns.  Compared
to seelog, this prevents data races when mutable variables are logged.

Second, the new logger does not implement any kind of artifical rate
limiting (what seelog refers to as "adaptive logging").  Log messages
are outputted as soon as possible and the application will appear to
perform much better when watching standard output.

Because log rotation is not a feature of the btclog logging
implementation, it is handled by the main package by importing a file
rotation package that provides an io.Reader interface for creating
output to a rotating file output.  The rotator has been configured
with the same defaults that btcd previously used in the seelog config
(10MB file limits with maximum of 3 rolls) but now compresses newly
created roll files.  Due to the high compressibility of log text, the
compressed files typically reduce to around 15-30% of the original
10MB file.
2017-06-25 14:19:56 +01:00
Andrey Samokhvalov
c233b8816e htlcswitch: increase payment timeout in bydirectional unit test
During travis tests the latency of payment might lead to test failure,
for that reason we increase the waiting timeout.
2017-06-25 14:19:56 +01:00
Olaoluwa Osuntokun
286026fbb9
htlcswitch: increase timeout in bidi payment test due to travis slowness 2017-06-21 13:36:28 +01:00
Olaoluwa Osuntokun
0fc62f123d
htlcswitch: log regular channel ID when registering channels 2017-06-19 16:39:45 +02:00
Olaoluwa Osuntokun
e2e21243d2
htlcswitch: make linter happy on go 1.7 2017-06-17 01:10:08 +02:00
Olaoluwa Osuntokun
4b0e331c62
htlcswitch: fix linter issues 2017-06-17 01:04:21 +02:00
Olaoluwa Osuntokun
1be4d67ce4
multi: run all test instances in parallel 2017-06-17 01:00:07 +02:00
Olaoluwa Osuntokun
bb9bc9205a
htlcswitch: run all unit tests in parallel 2017-06-17 00:41:47 +02:00
Olaoluwa Osuntokun
cae99134e1
htlcswitch: add tests to exercise payload verification and policy change s 2017-06-17 00:09:53 +02:00
Olaoluwa Osuntokun
7fc09edb76
htlcswitch: update link tests to be aware of fee implementation, API changes 2017-06-17 00:08:26 +02:00
Olaoluwa Osuntokun
e477241de1
htlcswitch: update test utilities to latest switch/link changes 2017-06-17 00:03:42 +02:00
Olaoluwa Osuntokun
399d193e2c
htlcswitch: add a new UpdateFeePolicy to ChannelLink interface
This commit adds a new method to the ChannelLink interface which is
meant to allow outside sub-system to update the forwarding policy of a
channel. This can be triggered either by a new RPC method, or
automatically by some sort of control system which seeks to optimize
fee revenue, or block off channels, etc.
2017-06-17 00:01:10 +02:00
Olaoluwa Osuntokun
cd10dc712f
htlcswitch: implement full HTLC onion payload validation logic
This commit puts a missing piece in place by properly parsing and
validating the per hop payload received in incoming HTLC’s. When
forwarding HTLC’s we ensure that the payload recovered is consistent
with our current forwarding policy. Additionally, when we’re the “exit
node” for a payment, then we ensure that the HTLC extended matches up
with our expectation w.r.t the payment amount to be received.
2017-06-16 23:58:08 +02:00
Olaoluwa Osuntokun
1f5a4fcb8e
htlcswitch: change over all internal indexes to use short channel ID's 2017-06-16 23:49:46 +02:00
Olaoluwa Osuntokun
4c7af9f16d
htlcswitch: eliminate HopID in favor of a [33]byte for compressed pub keys 2017-06-16 23:38:52 +02:00
Olaoluwa Osuntokun
ea57a94c2e
htlcswitch: add a ShortChanID method to the ChannelLink interface 2017-06-16 23:32:47 +02:00
Olaoluwa Osuntokun
058e641d7e
htlcswitch: add new ForwardingPolicy struct guide forwarding decisions 2017-06-16 23:31:00 +02:00
Olaoluwa Osuntokun
5cee9d4bf1
htlcswitch: modify the HopIterator interface to utilize per-hop payloads
This commit modifies the HopIterator interface to allow nodes that
receive incoming HTLC’s to make forwarding decisions based on the
returned peer hop information, rather than just the next hop. With this
change, we can now enforce our routing policy, and reject any HTLC’s
that violate the policy.
2017-06-16 23:29:44 +02:00
Olaoluwa Osuntokun
9a972a6fc3
htlcswitch: remove unused NewSphinxBlob function 2017-06-16 23:27:39 +02:00
Olaoluwa Osuntokun
c3497e515b
htlcswitch: add new ForwardingInfo struct to represent per-hop payloads 2017-06-16 23:26:56 +02:00
Olaoluwa Osuntokun
74897dc328
htlcswitch: fix linter error 2017-05-31 16:48:12 -07:00
Olaoluwa Osuntokun
2ab03c57be
htlcswitch: re-introduce dynamic commitment log tick timer
This commit fixes a slight regression in the logic of the switch by
ensuring that the log commitment timer is only start _after_ we receive
a new commitment signature. Otherwise, the ticker will keep ticking and
possibly settle HTLC’s that’ve yet to be locked in, or waste a
signature causing us to be deprived of a revocation which is required
for us to initiate a new state transition.

Additionally, the commit performs a few minor post-merge clean ups.
2017-05-31 16:43:48 -07:00
Olaoluwa Osuntokun
048e4c0a39
htlcswitch: fix issues with forwarding stats logger display
This commit fixes some issues in the display of the stats logger which
resulted in: stats being printed even though no forwarding activity
took place, and underflow of integers resulting in weird outputs when
forwarding.

This commit also adds some additional comments and renames the main
forwarding goroutine to its former name.
2017-05-31 16:16:58 -07:00
Andrey Samokhvalov
a5d90b9ad1 htlcswitch: fix last-mile settle stalling in concurrent multi-hop setting
This commit fixes an issue that would at times cause the htlcManager
which manages the link that’s the final hop to settle in an HTLC flow.
Previously, a case would arise wherein a set of HTLC’s were settled to,
but not properly committed to in the commitment transaction of the
remote node. This wasn’t an issue with HTLC’s which were added but
uncleared, as that batch was tracked independently.

In order to fix this issue, we now track pending HTLC settles
independently. This is a temporary fix, as has been noted in a TODO
within this commit.
2017-05-31 11:06:08 -07:00
Andrey Samokhvalov
7595bee27c htlcswitch: add usage of queue in channel link
In this commit usage of the pending packet queue have been added.
This queue will consume the downstream packets if state machine return
the error that we do not have enough capacity for htlc in commitment
transaction. Upon receiving settle/fail payment descriptors - add htlc
have been removed, we release the slot, and process pending add htlc
requests.
2017-05-31 11:06:08 -07:00
Andrey Samokhvalov
22d90d6b35 htlcswitch: add packet queue
In this commit pending packet queue have been added. This queue
consumes the htlc packet, store it inside the golang list and send it
to the pending channel upon release notification.
2017-05-31 11:06:08 -07:00
Andrey Samokhvalov
06946f3911 htlcswitch: add real sphinx iterator
Before using the htlcswitch inside the lnd we need to implement the
sphinx version of the hop iterator, which will be process the real
onion blobs.
2017-05-31 11:06:08 -07:00
Andrey Samokhvalov
882aec704d htlcswitch: add channel link tests
Step #5 in making htlcManager (aka channelLink) testable:
Combine all that have been done so far and add test framework for channel
links which allow unit test:

* message ordering
* detect redundant messages
* single hop payment
* multihop payment
* several cancel payment scenarios
2017-05-31 11:06:08 -07:00
Andrey Samokhvalov
a14f25830e htlcswitch: remove redudant variables
Because processing of onion blob have been moved in another place we
could get rid of the variables which are not needed any more.

NOTE: pendingBatch have been replaced with batchCounter variable, but
it should be removed at all, because number of pending batch updates
might be counted by the state machine itself.
2017-05-31 11:06:08 -07:00
Andrey Samokhvalov
0e2209cb12 htlcswitch: move onion blob processing
Step №4 in making htlcManager (aka channelLink) testable:

This step consist of two:
1. Start using the hop iterator abstraction, the concrete
implementation of which will be added later, basically it will we the
same sphinx onion packet processor, but wrapped in hop iterator
abstraction.

2. The RevokAndAck processing part have been replaced by the
"processLockedInHtlcs" function which implement the same logic, but make
it a bit simpler.

Such changes will allow as to get rid of the the unnecessary variables.
2017-05-31 11:06:08 -07:00
Andrey Samokhvalov
de01721aed htlcswitch: add hop iterator
Short: such abstraction give as ability to test the channel link in the
future.

Long: hop iterator represents the entity which is be able to give payment
route hop by hop. This interface will be used to have an abstraction
over the algorithm which we use to determine the next hope in htlc route
and also helps the unit test to create mock representation of such
algorithm which uses simple array of hops.
2017-05-31 11:06:08 -07:00
Andrey Samokhvalov
db30571efe htlcswitch: start using config in channel link
Step №3 in making htlcManager (aka channelLink) testable:
Apply the channel link config inside the channel link itself.
2017-05-31 11:06:08 -07:00
Andrey Samokhvalov
2eea76375c htlcswitch: make channel link implements interface
Step №2 in making htlcManager (aka channelLink) testable:
Implement the ChannelLink interface which is needed to use it in pair
with htlc switch. With this commit channel link impelements interface,
but isn't able to operate properly yet.
2017-05-31 11:06:08 -07:00
Andrey Samokhvalov
7f572fc155 htlcswitch: add channel link config
Step №1 in making htlcManager (aka channelLink) testable:
Start use config which will allow as mock/stub external subsystems.
2017-05-31 11:06:08 -07:00
Andrey Samokhvalov
0de4ea2712 htlcswitch: copy the initial representation of htlc manager
In this commit all initial code which will be transformed into channel
link have been added. Rather than changing the in the same commit is
better to create the standalone commit, in order to see the changes
which have been applied to relocated code.
2017-05-31 11:06:08 -07:00
Andrey Samokhvalov
b86409cdb3 htlcswitch: recreate hlcswitch from scratch
This commit gives the start for making the htlc manager and htlc switch
testable. The testability of htlc switch have been achieved by mocking
all external subsystems. The concrete list of updates:

1. create standalone package for htlc switch.
2. add "ChannelLink" interface, which represent the previous htlc link.
3. add "Peer" interface, which represent the remote node inside our
subsystem.
4. add htlc switch config to htlc switch susbystem, which stores the
handlers which are not elongs to any of the above interfaces.

With this commit we are able test htlc switch even without having
the concrete implementation of Peer, ChannelLink structures, they will
be added later.
2017-05-31 11:06:08 -07:00
Andrey Samokhvalov
07afcad6de htlcswitch: add hop id
Add hop id structure wich represent the next lnd node in sphinx payment
route. This structure will be removed when we switch to use the channel
id as the pointers to the htlc update.
2017-05-31 11:06:08 -07:00