1
0
mirror of https://github.com/ACINQ/eclair.git synced 2024-11-19 18:10:42 +01:00
Commit Graph

982 Commits

Author SHA1 Message Date
Bastien Teinturier
d43d06f6e2
Rework TxPublisher (#1844)
Splt the TxPublisher in many smaller actors with clear responsibilities.
Each tx publishing attempt is its own actor and watches the tx until it
either confirms or becomes evicted, and reports the result to its parent.

The TxPublisher (one per channel) orchestrates publishing attempts and
will in the future decide to RBF txs based on deadline information.
2021-06-22 17:47:12 +02:00
Bastien Teinturier
afb1b41ea0
Update bolt 3 spec test vectors (#1669)
Update bolt 3 spec test vectors to match the latest test vectors
from https://github.com/lightningnetwork/lightning-rfc/pull/539 and
https://github.com/lightningnetwork/lightning-rfc/pull/852 and
clarify HTLC outputs (see https://github.com/lightningnetwork/lightning-rfc/pull/852).
2021-06-22 11:02:43 +02:00
Bastien Teinturier
bbfbad5975
Validate payment secret when decoding (#1840)
The `payment_secret` feature was made mandatory in #1810 and is the default
in other implementations as well. We can thus force it to be available when
decoding onion payloads, which simplifies downstream components (no need
to handle the case where a `payment_secret` may be missing anymore).

We also rename messages in `PaymentInitiator` to remove the confusion with
Bolt 11 payment requests.
2021-06-11 18:11:37 +02:00
Fabrice Drouin
e750474c72
Use bitcoin-lib 0.19 (#1839)
There are no functional changes, but bitcoin-lib 0.19 is based on secp256k1-kmp (instead of our own fork of secp256k1's JNI wrapper) which is cleaner, easier to maintain and used in our mobile apps.
2021-06-09 15:56:35 +02:00
Bastien Teinturier
d4b25d565d
Udpate to Bitcoin Core 0.21.1 (#1841)
Update the default version of `bitcoind` to 0.21.1.
Deprecate support for version 0.18.1 and 0.19.1.
2021-06-09 14:20:00 +02:00
Pierre-Marie Padiou
a7bb2c2b24
Do not store CannotAffordFees errors (#1834)
That error can get spammy because it will be emitted at every block for
every channel, and it doesn't bring a lot of value to store it anyway.
2021-06-07 14:54:46 +02:00
Pierre-Marie Padiou
bd6bad1bfd
Fix eventually statements (#1835)
With the move to akka _typed_, we will be using more and more
scalatest's `eventually` as a replacement for akka's `awaitCond`
(which isn't available in `testkit.typed`).

But there is a catch:
- `awaitCond` expects a boolean
- `eventually` expects a non-failure

Which means that we must use `eventually(assert(cond))`, and not
`eventually(cond)`.
2021-06-07 14:53:49 +02:00
Anton Kumaigorodski
2b6d564d21
Expose eclair datadir to plugins (#1837)
Make `Setup.datadir` visible to code that receives an instance of
`Setup`. This allows plugin to know where the eclair data directory
is and potentially enrich it.
2021-06-07 14:17:46 +02:00
Bastien Teinturier
af618bc44f
Symmetrical HTLC limits (#1828)
The spec defines `max_accepted_htlcs` and `max_htlc_value_in_flight_msat`
to let nodes reduce their exposure to pending HTLCs. This only applies to
received HTLCs, and we use the remote peer's values for outgoing HTLCs.

But when we're more restrictive than our peer, it makes sense to apply our
limits to outgoing HTLCs as well.
2021-05-28 17:13:37 +02:00
Pierre-Marie Padiou
43a89f8659
Add a random delay before processing blocks (#1825)
The goal is to reduce herd effects when there are lots of channels.

Co-authored-by: Bastien Teinturier <31281497+t-bast@users.noreply.github.com>
2021-05-26 16:44:02 +02:00
Pierre-Marie Padiou
6f6c458a2d
Add metrics on channels processing time (#1826)
It's similar with built-in akka metrics, but with message-type granularity.
2021-05-26 10:27:14 +02:00
Pierre-Marie Padiou
4dc2910c4e
Make result set an iterable (#1823)
This allows us to use the full power of scala collections, to iterate
over results, convert to options, etc. while staying purely functional
and immutable.

There is a catch though: the iterator is lazy, it must be materialized
before the result set is closed, by converting the end result in a
collection or an option. In other words, database methods must never
return an `Iterable` or `Iterator`.
2021-05-25 19:03:17 +02:00
Bastien Teinturier
e8c33baf54
Various improvements and fixes (#1817)
* Reduce log level for explorer API errors
* Reduce log level for remote peer invalid open_channel
* Don't send duplicate commands in PostRestartHtlcCleaner: if there
  is already a pending HTLC settlement command in the DB, the post
  restart handler should let the channel replay it instead of sending
  a conflicting command.
* Workaround for lnd bug in reestablish: sometimes lnd sends
  announcement_signatures before sending their channel reestablish.
  This is a minor spec violation, we can simply delay the message and
  handle it later (hopefully once we've received their reestablish).
* Log shared secrets in Sphinx error: Breez sometimes returns errors
  that we fail to parse. Unfortunately we didn't correctly log the shared
  secrets because the variable was shadowed, so we can't investigate
  further for now.
* Fix utxo metric checks: if we're unable to fetch the number of
  unconfirmed parents for a utxo, this shouldn't cause the global utxo
  check to fail. We log a warning and let operations continue to ensure
  the metric is updated.
* Handle ChannelIdAssigned when disconnected: there may be a race
  condition where a peer disconnect in the middle of a channel id assignment.
  In that case, we still want to record the up-to-date mapping.
2021-05-25 17:01:51 +02:00
Pierre-Marie Padiou
98cae455fb
Rename pending_relay to pending_commands (#1822)
Naming was confusing because it led to believe messages were related to
htlcs that have not yet been relayed, whereas those are settlement
messages, meaning that htlcs have relayed and are pending resolution
upstream.

The database has been renamed to a more generic `PendingCommandsDb`
because we may store other types of commands for which we need reliable
delivery.
2021-05-25 15:06:53 +02:00
Bastien Teinturier
76894bd2e1
Add additional PRNG (#1774)
In case of catastrophic failures of the `SecureRandom` instance, we add
a secondary randomness source that we mix into the random stream.

This is a somewhat weak random source and should not be used on its own,
but it doesn't hurt to xor it with the output of `SecureRandom`.

We use an actor that listens to events in the system and inject them
in our weak pseudo-RNG.
2021-05-19 15:29:32 +02:00
Bastien Teinturier
a658fa26f4
Set version to 0.6.1-SNAPSHOT (#1813) 2021-05-19 15:08:42 +02:00
Bastien Teinturier
f89b0925a7
Set version to 0.6.0 (#1812) 2021-05-19 11:54:44 +02:00
Bastien Teinturier
5a92f84744
Add support for option_shutdown_anysegwit (#1801)
Opt-in to allow any future segwit script in shutdown as long as it complies
with BIP 141 (see https://github.com/lightningnetwork/lightning-rfc/pull/672).
2021-05-17 15:32:56 +02:00
Bastien Teinturier
1fbede7618
Add TCP keep-alive on ZMQ socket (#1807)
One of ZMQ's drawbacks is that subscribers on an unreliable network may
silently disconnect from publishers in case of network failures.

In our case, we want to reconnect immediately when that happens, so we set
a tcp keep-alive to ensure this.

Fixes #1789
2021-05-17 15:32:25 +02:00
Bastien Teinturier
91419980bd
Make payment_secret mandatory (#1810)
This is a security feature that has been introduced a long time ago and is
widely supported across the network.

We can safely make it mandatory which closes probing attack vectors.
2021-05-17 15:09:50 +02:00
Bastien Teinturier
9c3ee59cf8
Check blockchain watchdogs regularly (#1808)
We want to check secondary blockchain sources when we haven't received
blocks in a while.

Fixes #1803
2021-05-17 14:58:24 +02:00
Pierre-Marie Padiou
ec276f8e78
Use satoshi for htlc ordering (#1806)
Fixes #1804.
2021-05-17 11:26:23 +02:00
Anton Kumaigorodski
0805d51af4
Do not retry sending if payment gets confirmed on chain (#1799)
The `PaymentLifecycle` state machine already had that mechanism, but
the `MultiPartPaymentLifecycle` didn't.
2021-05-17 09:50:40 +02:00
Anton Kumaigorodski
898c17bc76
Remove ConnectionControlPlugin trait (#1797) 2021-05-14 09:17:11 +02:00
Bastien Teinturier
340fd299bb
Update default path-finding weight ratios (#1796)
* Update default path-finding weight ratios

* The two months window for channel age was too small for today's network
* CLTV is less of an issue nowadays: there are fewer stuck payments and
  we're encouraging nodes to increase their CLTV because of the recent
  mempool congestions
2021-05-12 16:30:11 +02:00
thomash-acinq
c641549387
Fix computation of path weight (#1794)
There are two cases depending on whether you use weight ratios or not.
They used to behave very differently:

* Without weight ratios, the weight would be the total amount to send (base amount + fees)
* With weight ratios, the ratios would apply to the total amount, not just the fees.
  The effect is that only the number of hops and then the weight factors matter as
  the fee itself is negligible compared to the total amount.

The code is now shared and the weight is now the sum of the fees
(multiplied by a factor if using weight ratios).
2021-05-12 14:21:30 +02:00
Bastien Teinturier
55b50ecf4a
ZMQ actors should subscribe to a single topic (#1793)
We use one actor per topic, but each actor previously registered to multiple
topics so we received duplicate events and consumed twice the necessary
bandwidth.
2021-05-11 11:24:53 +02:00
Pierre-Marie Padiou
a8d4e07bdd
Use less strict isolation level for channel meta (#1790)
We don't need `SERIALIZABLE` consistency guarantees when all we do is
updating timestamp columns. This happens concurrently to channel data
update and raised serialization errors in postgres.

Fixed #1786.

Co-authored-by: Bastien Teinturier <31281497+t-bast@users.noreply.github.com>
2021-05-10 15:32:26 +02:00
Pierre-Marie Padiou
3079cb4fc6
Remove unused class (#1792) 2021-05-10 15:32:07 +02:00
Bastien Teinturier
90fbcd32f3
Index trampoline payments by hash and secret (#1770)
We need to group incoming HTLCs together by payment_hash and payment_secret,
otherwise we will reject valid payments that are split into multiple distinct
trampoline parts (same payment_hash but different payment_secret).

Fixes #1723
2021-05-04 18:38:54 +02:00
Bastien Teinturier
9e4042fd4c
Migrate ZmqWatcher to akka-typed (#1759)
And re-work watch types and bitcoin events.
The type architecture is cleaner and more future-proof.
More tests have also been added.
2021-05-04 18:22:48 +02:00
Bastien Teinturier
3669428b53
Don't log ClosingType object (#1781)
It may contain a lot of data and pollute the logs.
2021-05-03 19:02:15 +02:00
Bastien Teinturier
62dd3932ff
Use bouncycastle instead of spongycastle (#1772)
* Use bouncycastle instead of spongycastle
* Reformat a few files
* Remove wireshark dissector support

Fixes #1375
2021-04-22 11:39:45 +02:00
Pierre-Marie Padiou
e14c40d7c3
Use proper data type for timestamps in Postgres (#1778)
Did some refactoring in tests and introduced a new `migrationCheck`
helper method.

Note that the change of data type in sqlite for the `commitment_number`
field (from `BLOB` to `INTEGER`) is not a migration. If the table has
been created before, it will stay like it was. It doesn't matter due to
how sqlite stores data, and we make sure in tests that there is no
regression.
2021-04-22 10:16:40 +02:00
Bastien Teinturier
4a1dfd2a27
Reenable ServerSocket tests (#1777)
There are issues with IPv6 loopback addresses on build machines, so we
force IPv4 and use non-blocking socket servers.
2021-04-20 18:30:46 +02:00
Pierre-Marie Padiou
e092677b9a
Rework the db version management (#1775)
* rework the db version management

The way our `getVersion`/`setVersion` was very unintuitive and led to
comments like the following in tests:
```scala
dbs.getVersion(statement, "network", 1) // this will set version to 1
```

The reason is that we treat unitialized databases and up-to-date
databases exactly the same way. That is why a `getVersion` will set the
version to the most up-to-date if none is found. It's also why we use
`CREATE IF NOT EXISTS` statements for tables and indices.

With this change, the `getVersion` now only _gets_ the version, or
returns `None` if no version exists.

Since we now differentiate between uninitialized and up-to-date db, we
don't need to make the create statements idempotent. This makes the code
more strict, and we will see errors if our versioning system has bugs.

Internal tables (used for versioning, locking, etc.) have been left
unchanged.

Co-authored-by: Bastien Teinturier <31281497+t-bast@users.noreply.github.com>
2021-04-20 14:10:24 +02:00
Pierre-Marie Padiou
33d52b6535
More database nits (#1773)
* use prepared statements for pruning

* optional read-only user

It is good practice to create a dedicated read-only user to browse the
database safely. But since the app itself creates its tables, the
postgres user is the owner and a manual `GRANT` is required everytime a
new table is added.

This PR makes it possible to specify an arbitrary username, that will be
granted read-only access to all tables in the `public` schema.

NB: The assumption here is that eclair is the only app using the
eclair database (in the `CREATE DATABASE eclair` sense), which I believe
is reasonable.

* set timezone on lease table

This only affects newly created table, there is no migration.

Users that are already using postgres will keep the previous column
type, it doesn't change anything for them.

* put back lock timeout on lease table

We use a timeout, because due to concurrency we may not be able to
obtain a lock immediately.

The timeout has been set to its original value of 5s and made
configurable.

* obtain lock before initializing tables
2021-04-20 12:38:49 +02:00
Pierre-Marie Padiou
32a86a476f
Ignore tests with ServerSocket (#1776)
This is just to unblock CI and should be reverted when we find the root issue.
2021-04-19 18:54:03 +02:00
thomash-acinq
15ddc17189
Add trampoline info to auditDB (#1767)
* Add trampoline info to auditDB

Add a new table containing the recipient and amount sent to the recipient in case of trampoline relaying.
When using trampoline, the recipient may not be the next node on the path.
2021-04-15 09:15:33 +02:00
Pierre-Marie Padiou
eb834e2522
Do not explicitly provide address for ServerSocket in tests (#1766) 2021-04-14 10:38:38 +02:00
Pierre-Marie Padiou
ccae92d7dc
(Minor) Minimize conflicts with feature branches (#1765)
* optional label in getReceiveAddress

* use a separate variable for channel version
2021-04-13 18:38:26 +02:00
Pierre-Marie Padiou
205653d092
Make db errors fatal in channels (#1764)
We don't want a database error to cause force close of channels.
Database errors are more likely to happen when using Postgres, but can
also happen with Sqlite in case of e.g. full disk.

Since we always write to disk before sending messages, we should be able
to recover gracefully after the db issue is fixed and eclair is
restarted.
2021-04-13 18:11:11 +02:00
Pierre-Marie Padiou
357f7f9942
Catch all connection failures and reconnect (#1760)
The `ReconnectionTask` was only catching
`ConnectionResult.Failure.ConnectionFailed`, which is a subset of
possible failures. It should instead have caught
`ConnectionResult.Failure`.

All authentication and initialization failures were not caught and
didn't trigger reconnections.

Co-authored-by: Bastien Teinturier <31281497+t-bast@users.noreply.github.com>
2021-04-12 18:49:50 +02:00
Bastien Teinturier
48c0c4c98b
Extract tx publishing from watchers (#1749)
Introduce a `TxPublisher` actor to publish channel txs.
Move logic from watcher to this new actor.

Remove the `TxSigningKit` abstraction that was introduced a bit too early.
The `TxPublisher` will hold all the logic so we'll start by providing the full
commitments, and we'll extract more compact objects later.

We also now publish the commit-tx and its anchor-tx independently.
2021-04-12 17:17:27 +02:00
Pierre-Marie Padiou
6518bb47a0
Posgres: fix concurrency in channels db (#1762)
* preserve pg lock exception cause

* specialize connections by backend type

* added concurrency test on channels table

This test unveils a concurrency issue in the upsert logic of the local
channels db, with the following error being thrown when we update many
channels concurrently:

```
Canceled on identification as a pivot, during conflict out checking
```

* use pg upsert construct

This is the recommended pattern according to postgres doc
(https://www.postgresql.org/docs/current/plpgsql-control-structures.html#PLPGSQL-UPSERT-EXAMPLE):

> It is recommended that applications use INSERT with ON CONFLICT DO
UPDATE rather than actually using this pattern.

* reproduce and fix same issue in peers db
2021-04-12 12:18:17 +02:00
Pierre-Marie Padiou
1e2abaed0c
Index database metrics by backend (#1758) 2021-04-08 16:26:12 +02:00
Pierre-Marie Padiou
5f68bf9223
Database nits (#1755)
* proper formatting

* prefix sqlite-specific tests

* fix double init tests

Due to how the `TestDatabases` is instantiated, calling `dbs.dbName`
twice was a no-op.

* add jdbcurl files to gitignore
2021-04-06 15:51:48 +02:00
Fabrice Drouin
13217610ae
Make signing payment requests faster (#1754)
* Make signing payment requests faster

There was a much more efficient method to compute the pukey recovery id that was not used.
2021-04-02 16:15:07 +02:00
Bastien Teinturier
b25e5523e7
Remove Docker test dependency (#1753)
It was only used by Electrum which was removed in #1750
2021-04-02 12:27:40 +02:00
Bastien Teinturier
89d2489296
Remove Electrum support (#1750)
Electrum support was provided for mobile wallets, server nodes should always
run a bitcoind node as this provides more control (especially for utxo
management for anchor outputs channels).

Since wallets will use https://github.com/acinq/eclair-kmp instead of eclair,
we can now remove Electrum and API fee providers from eclair.

We also removed 3rd-party fee API providers that were only used on wallets.
2021-04-02 09:18:54 +02:00
Bastien Teinturier
5729b28912
Add blocking option to payinvoice API (#1751)
Add an option to block until the payment completes to the payinvoice API.
This can be simpler to use for payments that complete quickly.
2021-04-02 08:36:20 +02:00
Bastien Teinturier
ac2b784373
Fix flaky relay-htlc-add test (#1752)
We need to wait for the channel relayer to be registered to the event stream
before publishing an event, otherwise the channel relayer will never receive it.

We send it a first message and wait for its response to ensure it had time
to correctly initialize.
2021-04-01 19:19:21 +02:00
Pierre-Marie Padiou
936f36b9fc
Refactor Postgres code (#1743)
More symmetry between postgres and sqlite init.

* define SqliteDatabases and PostgresDatabase

Those classes implement traits `Databases`, `FileBackup` and
`ExclusiveLock`.

The goal is to have access to backend-specific attributes, particularly
in tests. It arguably makes the `Databases` cleaner and simpler, with a
nice symmetry between the `apply methods`.

* replace 5s lock timeout by NOLOCK

* use chaindir instead of datadir for jdbcurl file

It is more consistent with sqlite, and makes sense because we don't want
to mix up testnet and mainnet databases.

* add tests on locks and jdbc url check
2021-03-31 16:12:06 +02:00
thomash-acinq
75cb777c61
Prevent loops and improve shortest paths perf (#1747)
Reverse the flow of yen's k-shortest path: go backwards like
we do in dijkstra.

Better tracking of already explored spur paths which improves
performance (especially tail latency).
2021-03-31 15:37:54 +02:00
Bastien Teinturier
c6a76af9d3
Introduce actor factories (#1744)
This removes unnecessary fields and allows more flexibility in tests.
2021-03-31 08:58:40 +02:00
thomash-acinq
e5429ebdf4
Avoid visiting vertices multiple times in Dijkstra's algorithm (#1745)
Fix implementation of Dijsktra to visit each node only once.
This is a great speed-up in the worst-case scenario.
2021-03-29 17:18:57 +02:00
Bastien Teinturier
c37eb1ad54
Handle aggregated anchor outputs htlc txs (#1738)
An interesting side-effect of anchor outputs is that htlc txs can be merged
when they have the same lockTime (thanks to sighash flags).

We're not currently doing that, but our peers may do it, so we need to handle
it in the revoked commit tx case and correctly claim multiple outputs if
necessary.
2021-03-25 14:27:50 +01:00
Bastien Teinturier
f202587e9c
Clarify commit tx fee anchor cost (#1721)
Since anchor outputs, we not only deduce the commit tx fee from the funder's
main output but the cost of the anchors as well.

We rename the function that does that for more clarity.
2021-03-24 09:19:17 +01:00
Bastien Teinturier
3d3766ef56
Clarify some comments and add tests (#1734)
This commit clarifies some parts of the code on which we regularly have
questions during pull requests.

We also add a test for an edge case in shutdown that was correctly handled,
but not properly tested, to ensure non-regression.
2021-03-23 15:06:39 +01:00
Bastien Teinturier
7819faec39
Move protocol codecs to their own package (#1736)
This is a follow-up for #1732

Codecs in the protocol package will always be backwards-compatible,
as they are defined in the spec.
2021-03-23 13:57:02 +01:00
Bastien Teinturier
6d28cbc8e1
Rework XxxCommitPublished types (#1728)
Re-work the `CommitPublished` types to work better with anchor outputs.
We previously stored the txs spending utxos that we could claim: this
doesn't make sense anymore if these txs may be RBF-ed, because the final
tx will be different from the initial one.

We instead track what `OutPoint`s we can claim, and the information
necessary to claim them. This way we can in the future let a different
actor finalize the txs that spend these outpoints (set the fees and sign).

We also add information on mutual close txs to immediately identify our
output and its amount: this makes auditing how much sats we'll get back
very easy from the API when we have many channels to watch.

This commit contains a DB migration of the channel data types, but in a
backwards-compatible way: we can still read from old data. The only
scenario impacted is channels that started force-closing before the migration.
They need special care to handle the fact that they had less data than
migrated channels, which is why we keep some legacy code around.
2021-03-22 15:44:38 +01:00
Pierre-Marie Padiou
4bc2dec66c
Reorganize internal codecs (master) (#1732)
The goal is to ensure maximum safety when migrating data.

To achieve this, we strictly segregate each codec version (to make sure
that we don't accidentally mix codec versions), while still letting
tests access each unitary codecs (which using inner `private classes`
would have prevented). Relevant tests only need to be moved to the
appropriate package.

The package structure is now:

```
wire
 |
 `-- internal
 |       |
 |       `-- channel
 |       |      |
 |       |      `-- version0
 |       |      |      |
 |       |      |      `-- ChannelCodecs0
 |       |      |
 |       |      `-- version1
 |       |      |      |
 |       |      |      `-- ChannelCodecs1
 |       |      |
 |       |      `-- ChannelCodecs
 |       |
 |       `-- CommandCodecs
 |
 `-- others
```

Co-authored-by: Bastien Teinturier <31281497+t-bast@users.noreply.github.com>
2021-03-19 12:20:12 +01:00
Pierre-Marie Padiou
ded5ce0e17
Add metadata to local_channels table (#1724)
* rename `Auditor` to `DbEventHandler`

Move it to the `db` package (it was in the `payments` package for
historical reasons but doesn't deal only with payment anymore).

Better typing for channel lifecycle event.

* add meta info to local_channels table

Here is the rationale for implementing channel metadata as additional
columns in the `local_channels` table of the `channels` db, as opposed
to a dedicated `channel_metadata` table of a `audit` db:

1) There is a migration to do (in the `local_channels` table, no less!),
but it's just a table migration, as opposed to a data migration, if we
had to populate a new table in a separate database.
2) We don't need to worry about creating a new metadata line when a new
channel is created (compared to doing add-or-update stuff). It's only
_updating_ optional columns in a best-effort manner.
3) We don't need to worry about inconsistencies between two tables
located in two separated databases (that's a big one).
4) We may want to use the metadata during operations, not just for
audit purposes. For example to close channels that have stayed unused
for a long time.
5) The audit db is an append-only log of events and shouldn't be used
for anything else. There is no `UPDATE` sql statement in
`*AuditDb.scala`. The `channel_metadata` would break that heuristic.
2021-03-10 19:32:38 +01:00
Bastien Teinturier
2772138755
Better handling of TemporaryChannelFailure (#1726)
When a node returns a TemporaryChannelFailure, we should ignore this channel
when retrying. In some cases (such as channels from routing hints) this was
not correctly handled.

Fixes #1725
2021-03-10 10:49:23 +01:00
Anton Kumaigorodski
6364ae3350
Reject trampoline payments with expired outgoing cltv (#1727)
When we receive a trampoline payment asking us to relay with an
expiry that is already below the current chain height, we know that
this payment will fail when it reaches the next trampoline node.

Instead of waiting for the next trampoline node to reject it, we reject
it immediately.
2021-03-10 09:05:24 +01:00
Thomas Profelt
9ff2f833e7
Refactor and simplify API dsl (#1690)
Refactor the API handlers.
Split handlers and directives in several files to make them more composable.

Co-authored-by: Pierre-Marie Padiou <pm47@users.noreply.github.com>
Co-authored-by: Bastien Teinturier <31281497+t-bast@users.noreply.github.com>
2021-03-09 15:23:50 +01:00
Bastien Teinturier
ea8f94022e
Fix potential race condition in node-relay (#1716)
We previously relied on `context.child` to check whether we already had a
relay handler for a given payment_hash.

Unfortunately this could return an actor that is currently stopping itself.
When that happens our relay command can end up in the dead letters and the
payment will not be relayed, nor be failed upstream.

We fix that by maintaining the list of current relay handlers in the
NodeRelayer and removing them from the list before stopping them.
This is similar to what's done in the MultiPartPaymentFSM.
2021-03-08 16:14:24 +01:00
Bastien Teinturier
92e53dc9a9
Configurable anchor output max commitment feerate (#1718)
It makes sense to allow node operators to configure the value they want
to use as a maximum threshold for anchor outputs commitment tx feerate.

This allows node operators to raise this value when mempools start getting
full in anticipation of a potential rise of the min-relay-fee.

This value can also be overridden for specific nodes.
2021-03-08 16:03:39 +01:00
Bastien Teinturier
c4c0248ee3
Use bech32 addresses by default (#1717)
Drop mention of p2sh-segwit. We should encourage users to use bech32.
2021-03-05 17:47:37 +01:00
Bastien Teinturier
afa378fbb7
Fix Bolt 3 spec change that broke our test suite (#1719)
We just merged lightningnetwork/lightning-rfc@b201efe in the spec
which added Bolt 3 tests, invalidating one of our tests and failing the build.
2021-03-05 13:48:31 +01:00
Bastien Teinturier
844829a9b1
Features should be a Map (#1715)
We previously used a Set, which means you could theoretically have a feature
that is both activated as `optional` and `mandatory`.

We change that to be a Map `feature -> support`.
2021-03-04 08:40:56 +01:00
Bastien Teinturier
163700a232
Set version to 0.5.2-SNAPSHOT (#1714) 2021-03-03 15:29:26 +01:00
Bastien Teinturier
98bb7be70a
Set version to 0.5.1 (#1707) 2021-03-03 11:38:00 +01:00
Pierre-Marie Padiou
264688622f
fixup! Improve channel state tests (#1709) (#1712) 2021-03-01 13:54:25 +01:00
Pierre-Marie Padiou
8d4da2faad
Improve channel state tests (#1709)
* add tests on funding mindepth

We verify that when using wumbo channels:
- if we are funder we keep our regular min_depth
- if we are fundee we use a greater min_depth

* use lenses to simplify tags handling

Co-authored-by: Bastien Teinturier <31281497+t-bast@users.noreply.github.com>
2021-02-26 18:24:45 +01:00
Pierre-Marie Padiou
8065d0bb80
Add a serializer for DoSync (#1708)
This command is sent by the `Peer` to its `PeerConnection`, therefore it
needs to be a `RemoteType` and have its own codec.
2021-02-26 12:09:21 +01:00
Bastien Teinturier
5d662fc3d7
Set anchor output feerates when force-closing (#1702)
When using anchor outputs, the commitment feerate is kept low (<10 sat/byte).
When we need to force-close a channel, we must ensure the commit tx and htlc
txs confirm before a given deadline, so we need to increase their feerates.

This is currently done only once, at broadcast time.
We use CPFP for the commit tx and RBF for the htlc txs.
If publishing fails because we don't have enough utxos available, it will
be retried after the next block is confirmed.

Note that it's still not recommended to activate anchor outputs.
More work needs to be done on this fee bumping logic and utxos management.
2021-02-24 19:28:44 +01:00
Bastien Teinturier
bf2a35f74c
Relay partially failed htlcs when closing (#1706)
If a channel closes when we've received an UpdateFailHtlc, signed it but
not yet received our peer's revocation, we need to fail the htlc upstream.

That specific scenario was not correctly handled, resulting in upstream
htlcs that were not failed which would force our upstream peer to close
the channel.
2021-02-24 19:08:51 +01:00
Pierre-Marie Padiou
a3c477e3f7
Address all intellij warnings for Channel.scala (#1705) 2021-02-24 18:13:02 +01:00
Pierre-Marie Padiou
d02b900a0c
Fix annoying compiler warning (#1704)
This fixes the `multiarg infix syntax looks like a tuple and will
be deprecated` warning.
2021-02-24 15:13:23 +01:00
Pierre-Marie Padiou
c1bf9bd100
Optimize watching for spending txs (#1699)
Since we almost always know which transactions will spend the utxos that we are watching, we can optimize the watcher to look for those instead of starting from scratch.
2021-02-24 14:37:43 +01:00
Bastien Teinturier
fa759f1e6b
Fix PaymentLifecycle warning (#1703)
Type is erased at runtime, but it's not needed, so let's simply remove it.
2021-02-23 12:04:35 +01:00
Thomas Profelt
5163749a9a
[eclair-cli] Use multiplatform escape sequence
Also added cli `findroutebetweennodes` to the commands list.

Fixes #1206
2021-02-22 18:14:49 +01:00
Bastien Teinturier
d9c0b862bb
Refactor bitcoin clients (#1697)
And improve test coverage specifically for the calls we'll rely on for CPFP
and RBF.
2021-02-19 14:33:48 +01:00
Bastien Teinturier
083515086f
Update funding timeout fundee (#1692)
Our previous timeout was based on timestamps, mostly because blockCount
could be 0 on mobile using Electrum until a new block was received.
Now that we're diverging from the mobile wallet codebase, we can use block
heights instead which is more accurate.

See lightningnetwork/lightning-rfc#839
2021-02-19 14:16:30 +01:00
Bastien Teinturier
ab89851cdf
Relax single tx input requirements (#1677)
In some places of the codebase we relied on the fact that lightning transactions
had a single input. That was correct with the standard commitments format,
but will not be the case with anchor outputs: 2nd-stage txs (htlc-txs) and
3rd-stage txs (claim-htlc-txs) can be RBF-ed and have any number of inputs
and outputs.
2021-02-18 15:39:08 +01:00
Bastien Teinturier
9618a6a79c
Add a maximum fee threshold for anchor outputs (#1672)
With anchor outputs, the actual feerate for the commit tx can be decided
when broadcasting the tx by using CPFP on the anchor.

That means we don't need to constantly keep the channel feerate close to
what's happening on-chain. We just need a feerate that's good enough to get
the tx to propagate through the bitcoin network.

We set the upper threshold to 10 sat/byte, which is what lnd does as well.
We let the feerate be lower than that when possible, but do note that
depending on your configured `feerate-tolerance`, that means you can still
experience some force-close events because of feerate mismatch.

Fix anchor outputs closing fee requirements: when using anchor outputs,
the mutual close fee is allowed to be greater than the commit tx fee,
because we're targeting a specific confirmation window.

Fix fee mismatch without htlc: we allow disagreeing on fees while the channel
doesn't contain any htlc, because no funds can be at risk in that case.
But we used the latest signed fee when adding a new HTLC, whereas we must
also take into account the latest proposed (unsigned) fee.
2021-02-18 14:20:36 +01:00
Thomas Profelt
fdb57b43d3
Find route between nodes (#1695)
Added additional method to Eclair like findRoute but allowing for 2 nodeIds.
Also added a new endpoint to the http Api "findroutebetweennodes" which
takes sourceNode and targetNode as params.

Fixes #1068
2021-02-18 13:55:50 +01:00
Bastien Teinturier
3a94a80447
Reject unreasonable remote dust limit (#1694)
It makes no sense to use a dust limit that's much higher than what bitcoin
mandates, so we should not allow our peer to use invalid values.
2021-02-17 15:17:44 +01:00
Bastien Teinturier
82e5b5968d
Sort addresses in node announcement (#1693)
Addresses in node announcement should be sorted.
We accept node announcements that don't do this, but we should do it for
our own announcements.

See https://github.com/lightningnetwork/lightning-rfc/pull/842
2021-02-17 15:12:39 +01:00
Bastien Teinturier
2a359c6a56
Publish txs with min-relay-fee met (#1687)
When our mempool is full, its min-relay-fee may be constantly changing.
To ensure our txs can be published, we need to check the min-relay-fee when
we fund the transaction, and raise it if necessary.
2021-02-15 19:17:48 +01:00
Bastien Teinturier
36e8c056f1
Shutdown and UpdateFee should not be intertwined (#1661)
We were not correctly handling intertwined `update_fee` and `shutdown` 
and could end up stuck between shutdown and negotiating.
2021-02-15 18:33:31 +01:00
Bastien Teinturier
fdeb3ce7e1
Correctly set gossip sync_complete (#1668)
We are restoring the previous behavior of using the `sync_complete` field
to signal the end of a `channel_range_query` sync.

The first step is to correctly set that field, before we can read it and
interpret it to mark the end of sync.

See https://github.com/lightningnetwork/lightning-rfc/pull/826
2021-02-15 17:05:48 +01:00
Bastien Teinturier
72179de0a4
PaymentLifecycle handle disconnected peers (#1688)
When a peer is disconnected, the register will return a forward failure.
This can happen if the peer is connected when we start the payment FSM and
then disconnects before we send them an HTLC.
2021-02-12 18:42:46 +01:00
Bastien Teinturier
15c1837d84
Add tx signing metrics (#1659)
Monitor the rate at which we sign channel txs and the duration of the
signing operations.
2021-02-12 12:10:56 +01:00
Bastien Teinturier
5d3958dd03
Fix MPP path-finding edge case (#1685)
Obviously the route amount must be strictly positive.
We don't control htlcMinimumMsat (it is set by our peer) and for backwards
compatibility reasons we allow it to be 0 msat (even though it doesn't make
much sense), so we need to enrich our condition to detect empty channels.
2021-02-08 11:49:38 +01:00
Aris
63d972bdc6
Fix a few typos (#1684)
Fix a few typos in the documentation and variable names.
2021-02-08 11:20:23 +01:00
Bastien Teinturier
f241ef933b
Remove support for initial_routing_sync (#1683)
We keep the GetRoutingState API available in the router as it's useful to
query network information locally (or between actors), but we stop sending
that data to remote nodes.
2021-02-04 16:53:41 +01:00
Bastien Teinturier
49023625b2
Refactor channel test helpers (#1682)
It's useful to separate channel state test methods in a dedicated trait
instead of always bundling it with `FixtureTestSuite`.

In particular, it was previously impossible to use both `BitcoindService`
and `StateTestsHelperMethods` because `BitcoindService` doesn't work with
fixtures (it leverages `beforeAll` and `afterAll` instead because launching
one bitcoind instance per-test would be too expensive and useless).
2021-02-04 16:52:05 +01:00
Pierre-Marie Padiou
d05318832f
Truncate hex strings in front logs (#1679)
Front-end logs can produce a huge amount of logs, with significant
duplication. In order to reduce the log volume, we truncate `nodeId` and
`channelId` in the MDC to only keep the first 8 hexadecimal characters.

Also, override a few `toString` because some channel-queries-related
case classes produce huge strings.
2021-02-04 16:46:49 +01:00