1
0
mirror of https://github.com/ACINQ/eclair.git synced 2024-11-20 02:27:32 +01:00
Commit Graph

679 Commits

Author SHA1 Message Date
Bastien Teinturier
ba4cca29e5
Use channel balance in path-finding (#1395)
* Use channel capacity and balance in path-finding

The path finding algorithm uses channel capacity instead of htlcMaximumMsat.
It also takes into account channel balance when available and excludes
channels that don't have enough funds to relay the payment.

This change also fixes an off-by-one error in weight computation: we were
incorrectly applying a channel's fee to the amount that needs to be relayed
through that channel (whereas this is instead what the node needs to receive
to collect enough fee *before* relaying).

* Refactor Graph file

Add documentation, update comments, rename fields and reformat to (helpfully)
make the code clearer.

* Simplify path-fiding implementation

There were a couple confusing steps in the implementation of Yen's algorithm.

The first one was the computation of the `edgesToIgnore` and the specific
handling of the case i = 0. This specific case wasn't needed and made the
code a bit hard to read.

The second one was the weight provided to dijkstra for spur paths.
The weight of the root path was applied to the target node. It was probably
an attempt to take into account the fact that dijkstra wasn't computing
a complete path and that fees may not match, but it couldn't really work.
I removed that and added a fee check at the end of the path-finding.

* Update graph balance for duplicate channel_update

This case regularly happens after a restart: the router already has the
latest channel_update for that channel, but we want to update the graph's
balances because they are all at `None` after a restart.
2020-05-11 09:49:27 +02:00
Bastien Teinturier
3f127fbf06
Update kamon (#1411)
* Update Kamon libraries
* Ignore unused channel state changes post-restart
2020-05-06 15:58:08 +02:00
Fabrice Drouin
273a3f0966
Release 0.4 (#1409)
* Release 0.4

* Set version to 0.4.1-SNAPSHOT
2020-05-05 14:55:09 +02:00
Pierre-Marie Padiou
e38f706c46
Minor: catch harmless unhandled events (#1407)
* minor: catch harmless unhandled events

This prevents unnecessary warnings to clog up the logs.

* fix race condition in test

Changing the fake ip address from 1.2.3.4:42000 to localhost:42000
in 32f15c85eb made the dummy connection
fail much faster, creating a race in the test. Reverting to the previous
ip and increasing the timeout should improve things a bit.
2020-05-05 12:09:16 +02:00
Fabrice Drouin
874bd4bc26
Unlock transaction inputs if tx cannot be published (#1404)
* Unlock transaction inputs if tx cannot be published

In some cases, funding a tx will work but publishing may fail (because mempool fees are not met for example).
In that case we need to make sure that the tx inputs are unlocked.
2020-05-05 11:03:26 +02:00
Bastien Teinturier
c4d085a537
Validate channel_announcement sigs early (#1406)
We should validate the announcement signatures in the channel too.
We still validate them in the router, but it's a different layer and the
check should happen as soon as possible.
We don't want to keep the channel open if the peer is sending us garbage.
2020-05-05 10:51:01 +02:00
Pierre-Marie Padiou
32f15c85eb
Delegate client creation to a specialized actor (#1400)
This allows decoupling the reconnection task from the actual client
creation.

Also improved tests.

Co-Authored-By: Bastien Teinturier <31281497+t-bast@users.noreply.github.com>
2020-04-30 18:10:55 +02:00
Pierre-Marie Padiou
a18d3a76a2
Platform.currentTime->System.currentTimeMillis (#1403)
This is a low hanging fruit, it is portable to android.
2020-04-30 16:52:14 +02:00
Bastien Teinturier
65e26c648b
Fix BitcoinCoreWalletSpec (#1401)
This test was randomly failing. There may be a rounding error or a bit of
randomness somewhere in Bitcoin Core 0.19.1, sometimes a feerate right
below the limit is accepted into the mempool.
2020-04-30 15:24:43 +02:00
Bastien Teinturier
c3a66f37a3
Disable backup handler in tests (#1399)
We've been witnessing random test suites freezes (since ages).
We've observed that when these freezes happen, there are usually a lot of
"too many open files" errors raised by the OS.

The backup handler is a likely culprit as the IntegrationSpec is running
multiple nodes and exchanging HTLCs at a fast rate.

At least it won't hurt disabling it in tests, and will speed up the
test suite.

We also increase the file limits in CI providers, when possible.
2020-04-30 11:56:44 +02:00
Pierre-Marie Padiou
0447bac58e
Remove unused attribute in Peer (#1397) 2020-04-27 18:27:51 +02:00
Bastien Teinturier
3809b023c0
Test preimage extraction from mempool (#1387)
Instead of waiting for htlc-success txs to be confirmed, eclair also looks
at mempool txs to detect preimages as soon as possible.

This has been the case for a very long time, but our integration tests
didn't showcase this correctly.

Refactored common watcher test helpers and added tests to
ZmqWatcherSpec.
2020-04-27 18:22:07 +02:00
araspitzu
22d476774d
Support bitcoin-0.19.1 (#1380)
* Support bitcoin-0.19.1

* Update supported versions of bitcoind in README
2020-04-27 16:10:45 +02:00
Pierre-Marie Padiou
19975d3d81
Update to scala 2.13 and akka 2.6 (incremental) (#1390)
This is almost a drop-in replacement. I had to relaxed compiler
parameters to allow deprecated features though.

Main changes:
- relaxed compiler parameters to minimize impact (e.g. allow
deprecated features)
- `scala.collection.JavaConverters` -> `scala.jdk.CollectionConverters`
- `MultiMap` -> `MultiDict`

Compilation is 25% faster on my machine, compiler is a bit more strict
(it found an "invalid comparison" bug).
2020-04-27 13:11:55 +02:00
Pierre-Marie Padiou
6aced1bf1c
Fix race condition in router tests (#1392)
Caused by the automated generation of node announcement following
c9f94eec6f.
2020-04-27 12:23:50 +02:00
Pierre-Marie Padiou
9c748e4d6f
Revert "Use sender instead of providing actor refs (#1379)" (#1391)
This reverts commit 86ee7eaabb.

It was error-prone (cf bff833b) and not a good practice according to @sstone.
2020-04-24 16:54:02 +02:00
Pierre-Marie Padiou
f4b56407b4
Prepare upgrade to scala 2.13 and akka 2.6 (#1389)
Do all the changes that will be required and are already possible to
minimize the diff:
- update dependencies
- `'something` -> `Symbol("something")`
- `BigDecimal.xValue()` -> `BigDecimal.xValue`
- `Map.filterKeys` -> `Map.filterKeys.toMap` (same for `Map.mapValues`)
- `def myMethod(...)` -> `def myMethod(...): Unit`
2020-04-24 15:31:25 +02:00
Bastien Teinturier
c9f94eec6f
Router channel balance (#1382)
Router uses channel events (LocalChannelUpdate and AvailableBalanceChanged)
to track the balance of local channels.

This information will be used in path-finding to improve path-finding,
especially in the MPP case.

The information is added to the graph structures, but it's not used yet in
path-finding. Some A/B testing will be needed before we can use those
safely for the path-finding algorithm.
2020-04-23 21:04:58 +02:00
Pierre-Marie Padiou
bff833b1b4
fixup! Use sender instead of providing actor refs (#1379) (#1386)
When switching to a new connection while already connected, peer
immediately kills the current connection and sends back the
`PeerConnection.ConnectionReady` to itself. Since #1379, the sender of
this message is assumed to be the `PeerConnection` actor. If peer
doesn't preserve the sender by using a `forward` instead of a `tell`, it
will assume that itself is the `PeerConnection`, which will break
everything.
2020-04-21 16:12:07 +02:00
Bastien Teinturier
e32d9ed99f
Refactor transaction generation errors (#1366)
Transaction generation functions used to throw exceptions.
We have a good TxGenerationSkipped type to express potential errors,
so these functions should return an Either to make the contract explicit.
2020-04-21 09:34:53 +02:00
Bastien Teinturier
ec7750211f
Send update_fee on reconnection (#1383)
We update transaction fees at every block (ie every 10 minutes). While this
works well when the remote peer is a node that's online for more than 10 minutes,
it's an issue for mobile wallets that usually come online for a few minutes
and then disconnect.

We want to make sure we send these wallet peers an update_fee when one
is needed, so we now check for feerate updates on reconnection.

Fixes #1381.
2020-04-20 16:23:05 +02:00
Pierre-Marie Padiou
86ee7eaabb
Use sender instead of providing actor refs (#1379)
In some messages, we provide a reference to the sending actor byt adding `self` in the message, but we could use `sender` instead.
2020-04-16 11:59:05 +02:00
Pierre-Marie Padiou
9103b99077
Add a rejection for update when channel is pruned (#1378)
In case a channel has been pruned, and we receive a recent update, we
"unprune" it and immediately request the channel announcement again
(which will cause us to revalidate it). We also discard the update,
assuming that we will receive it again with the channel announcement.

We were using a `GossipDecision.Duplicate` rejection for the channel
update, which is inaccurate. This PR introduces a new
`GossipDecision.RelatedChannelPruned`.
2020-04-15 17:05:43 +02:00
Bastien Teinturier
d56306728f
Gossip metrics (#1372)
Adding metrics for channel queries and gossip KPIs.
2020-04-15 17:00:38 +02:00
Bastien Teinturier
1483f3f88c
Revert Electrum Tor disabling SSL check (#1376)
This commit reverts #1278 where connecting to an Electrum server 
would disable the SSL check. The correct way to handle that is to
allow users to choose their SSL behavior in the frontend applications.
2020-04-14 13:45:19 +02:00
Bastien Teinturier
5fe6f675e5
Better tracking of channels count metric (#1369)
Track all channel states (cardinality shouldn't be too high).
Prevent duplicate transactions that messed up the gauge.
2020-04-10 19:25:27 +02:00
Pierre-Marie Padiou
7a5dbfdc56
Do not reconnect immediately if we keep getting disconnected (#1371)
If our latest successful connection attempt was less
than 30 seconds ago, we pick up the exponential
back-off retry delay where we left it. The
goal is to address cases where the reconnection
is successful, but we are disconnected right away.
2020-04-10 13:05:22 +02:00
Pierre-Marie Padiou
a58678eb0b
Move router handlers to separate files (#1352)
Also, acknowledge all gossip with a `GossipDecision`.
2020-04-09 16:08:10 +02:00
araspitzu
932f04851a
Support additional TLV records in SendPayentRequest (#1367)
* Support additional user defined TLVs when sending a payment (both single-part and MPP)

* Allow encoding and decoding of even TLV types above the high range
2020-04-09 10:36:30 +02:00
araspitzu
7866be11c3
Use correct type for parameters in ExtendedBitcoinClient (#1248)
* Use correct type for parameters in ExtendedBitcoinClient
2020-04-07 09:55:41 +02:00
Fabrice Drouin
d5951aa819
Release 0.3.4 (#1368)
* Release 0.3.4

* Set version to 0.3.5-SNAPSHOT
2020-04-06 13:41:17 +02:00
Pierre-Marie Padiou
4be5c34ad2
fixup! Split the Peer in two (#1347) (#1365) 2020-04-02 16:07:30 +02:00
Pierre-Marie Padiou
0e260985e2
fixup! Harden requirements on htlc-minimum-msat (#1339) (#1363)
Update fuzzy tests to not use zero-value amounts.
2020-04-02 15:40:00 +02:00
Pierre-Marie Padiou
7b58d3e831
fixup! Harden requirements on htlc-minimum-msat (#1339) (#1362)
Just less repetition and a better comment.
2020-04-02 12:52:30 +02:00
Bastien Teinturier
f9789b711a
PostRestartHtlcCleaner handle channel closing (#1338)
* Add missing cases to PostRestart

When a channel is closed we want to remove its HTLCs from our
list of pending broken HTLCs (they are being resolved on-chain).

We should also ignore outgoing HTLCs that have already been
settled upstream (which can happen when downstream is closing).

* Watch for downstream HTLC resolved on-chain

When a downstream channel is closing, we can safely fail upstream the
HTLCs that were either timed out on-chain or not included in the
broadcast commit transaction.

Channels will not always raise events about those after a reboot, so we
need to inspect the channel state and detect such HTLCs.

* Add helper function to HTLC scripts

To extract the payment_hash or preimage from an HTLC script seen on-chain.

* Cleanup on-chain HTLC timeout handling for MPP

With MPP, it's possible that a channel contains multiple HTLCs for the
same payment hash, and potentially even for the same expiry and amount.

We add more fine-grained handling of HTLC timeouts that share the same
payment hash. This allows a cleaner handling after a restart, and makes
sure we correctly detect failure that should be propagated upstream.
Otherwise we wouldn't be losing any money, but some channels may be closed
that we can avoid.

* Handle out-of-order htlc-timeout txs

It may happen that a commit tx and some htlc-timeout txs end up in the
same block. In that case, there is no guarantee on the order we'll receive
the confirmation events.

If any tx in a local/remoteCommitPublished is confirmed, that implicitly
means that the commit tx is confirmed (because it spends from it).
So we can consider the closing type known and forward the failure upstream.
2020-04-01 17:51:42 +02:00
Pierre-Marie Padiou
4875d4c879
fixup! Use CLTV as tie-breaker for offered htlc output sorting (#790) (#1360)
* removed the `Direction` class

* improved the non-reg test for htlcs

- check actual content instead of only success and roundtrip
- use randomized data for all fields instead of all-zero
- check the remaining data, not only the decoded value (codecs are
chained so a regression here will cause the next codec to fail)

Co-Authored-By: Bastien Teinturier <31281497+t-bast@users.noreply.github.com>
2020-03-31 18:31:47 +02:00
Bastien Teinturier
e8dac7324f
Add wallet balance metric (#1355)
And small tweaks/refactorings to RPC metrics.
2020-03-30 13:41:55 +02:00
araspitzu
9711da21c6
Use CLTV as tie-breaker for offered htlc output sorting (#790)
* Sort commit transaction outputs using BIP69 + CLTV as tie-breaker for offered HTLCs

* Type DirectedHtlc:
We now use a small hierarchy of classes to represent HTLC directions.
There is also a type alias for a collection of commitment output links.
2020-03-30 12:15:15 +02:00
Pierre-Marie Padiou
90b7fed021
fixup! Split the Peer in two (#1347) (#1357) 2020-03-30 11:05:36 +02:00
Pierre-Marie Padiou
0064aaedc3
fixup! Support for Tor onion services (#736) (#1356) 2020-03-26 10:51:00 +01:00
Pierre-Marie Padiou
e544207dd9
Minor: removed unused code (#1353)
And fixed formatting in Channel.scala.

Those are leftover from #1347.
2020-03-24 12:24:06 +01:00
Pierre-Marie Padiou
66f06413f1
Split the Peer in two (#1347)
* front now handles ping/sync

Peer has been split in two and now handles only channel related stuff.

A new `PeerConnection` class is in charge of managing the BOLT 1 part
(init handshake, pings) and has the same lifetime as the underlying
connection.

Also, made `TransportHandler` be a child of `PeerConnection` by making
the `remoteNodeId` an attribute of the state of `PeerConnection` instead
of a constructor argument (since we cannot be sure of the remote nodeid
before the auth handshake is done). Now we don't need to worry about
cleaning up the underlying `TransportHandler` if the `PeerConnection`
dies.

* remove `Authenticator`

Instead of first authenticating a connection, then passing it to the
`PeerConnection` actor, we pass the connection directly to the
`PeerConnection` and let it handle the crypto handshake, before the LN
init. This removes a central point of management and makes things easier
to reason about. As a side effect, the `TransportHandler` actor is now a
child of `PeerConnection` which gives us a guarantee that it dies when
its parent dies.

* separated connection logic from `Peer`

The `ReconnectionTask` actor handles outgoing connections to a peer. The
goal is to free
the `Peer` actor from the reconnection logic and have it just react to
already established
connections, independently of whether those connections are incoming or
outgoing.

The base assumption is that the `Peer` will send its state transitions
to the `ReconnectionTask` actor.

This is more complicated than it seems and there are various corner
cases to consider:
- multiple available addresses
- concurrent outgoing connections and conflict between
automated/user-requested attempts
- concurrent incoming/outgoing connections and risk of reconnection
loops
- etc.

Co-Authored-By: Bastien Teinturier <31281497+t-bast@users.noreply.github.com>
2020-03-23 21:35:43 +01:00
Bastien Teinturier
eae113f098
Improve AddHtlcFailed (#1349)
* Refactor timed out HTLC helpers: directly take a DATA_CLOSING
and extract the relevant parts.

* ClosingStateSpec: test dust HTLCs

* Improve ClosingStateSpec

* Clean up usage of AddHtlcFailed

We were abusing AddHtlcFailed in some cases where an outgoing HTLC
was correctly added, but was later settled on-chain (fulfilled, timed
 out or overridden by a different commit transaction).

These cases are now specifically handled with new Relayer.ForwardMessage
dedicated to on-chain settling.

* Refactor Relayer's ForwardMessages

ForwardFail and ForwardFulfill are now traits.
Handle both on-chain and remote fail/fulfills.
2020-03-20 12:11:33 +01:00
Bastien Teinturier
68874c2d6d
Centralize metrics per package (#1350)
Centralize metrics to avoid bloating the business logic.
Also fixed some build warnings and flatten a Future[Future[Future[Unit]]].
2020-03-19 11:35:53 +01:00
Bastien Teinturier
2df07277bb
Harden requirements on htlc-minimum-msat (#1339)
We were allowing users to set htlc-minimum-msat to 0, which directly
contradicts the fact that we must never send an HTLC for 0 msat.
We now explicitly disallow that behavior: the minimum is 1 msat.

In case the remote side of a channel had set its htlc-minimum-msat to 0,
we would forward HTLC with a value of 0 msat if a sender crafted such a
payment. The spec disallows that, so we now explicitly check for that
lower bound.
2020-03-16 16:51:29 +01:00
Pierre-Marie Padiou
ab7b373d58
Minor: Reduced some log levels (#1348)
Also removed string interpolation for some of the more expensive debug
lines. It's a trade-off performance vs readability and is probably not
worth changing for info level logs, which will be enabled anyway.

Co-Authored-By: Bastien Teinturier <31281497+t-bast@users.noreply.github.com>
2020-03-16 14:39:42 +01:00
Bastien Teinturier
26a54b5953
Funder reserve for future fee increase (#1319)
See https://github.com/lightningnetwork/lightning-rfc/issues/728

Add an additional reserve on the funder to prevent emptying and then
being stuck with an unusable channel.

As fundee we don't verify funders comply with that change.
We may enforce it in the future when we're confident the network as a
whole enforces that.
2020-03-11 15:12:48 +01:00
Pierre-Marie Padiou
b5bd2f074a
Re-send ChannelUpdate on reconnection (fixes 8afc00d) (#1342)
Previous implementation in #1317 wasn't working because in a bug in the
transition. Added a test and fixed it.

Co-authored-by: Bastien Teinturier <31281497+t-bast@users.noreply.github.com>
2020-03-11 15:02:03 +01:00
araspitzu
65371cd03b
Add more information to GetInfoResponse (#1344)
Add version, color and features
2020-03-10 14:17:09 +01:00
araspitzu
8b64e238f2
Allow users to have multiple wallets in bitcoind (#1334)
* Change the bitcoind RPC URL to use the default wallet named ""
2020-03-09 10:32:52 +01:00