1
0
mirror of https://github.com/ACINQ/eclair.git synced 2024-11-19 09:54:02 +01:00
Commit Graph

982 Commits

Author SHA1 Message Date
Pierre-Marie Padiou
54fa208c7d
Add validation on the recid in verifymessage (#1928)
We offset the `recid` by `31` for compatibility with `lnd` [1] but we
should also support normal values (0-3), and also add boundary checks.

[1] https://twitter.com/rusty_twit/status/1182102005914800128
2021-08-31 15:28:40 +02:00
Bastien Teinturier
59ccf3427a
Explicit channel type in channel open (#1867)
Add support for https://github.com/lightningnetwork/lightning-rfc/pull/880

This lets node operators open a channel with different features than what
the implicit choice based on activated features would use.
2021-08-31 09:01:06 +02:00
thomash-acinq
275581df96
Make route params explicit (#1923)
For path finding we always need `routeParams`, however all of the messages asking for finding a route have `routeParams` as an optional parameter. This makes it hard to enforce that a given payments uses a given `routeParams` as there may be a `None` somewhere that reverts to the global defaults.
It seems that the reason all the `routeParams` are optional is that the messages asking for finding a route are sometimes used when we already have a route. This is a hacky solution and I've tried to replace these messages by traits that work both when we want to find a route and when we already have it.
I'm trying to enable AB testing which requires using different `routeParams` for different payments and this is a blocker.
2021-08-30 18:12:21 +02:00
Bastien Teinturier
d53f57fed9
Switch ZMQ to block hash and improve resiliency (#1910)
* Disable ZMQ high watermark

This should prevent messages from being dropped.
We also configure the socket before subscribing to topics and connecting.

* Switch ZMQ raw block to block hash only

We were receiving raw blocks on the ZMQ socket, whereas we don't use it.
We only use this event as a trigger that a new block has been found, so we
can save bandwidth by switching to block hash subscriptions instead.

* Regularly check blocks

In case we haven't received block events on the ZMQ socket, we regularly
check whether we're behind.
2021-08-30 18:08:22 +02:00
Bastien Teinturier
92091a1504
Fix ZmqWatcher flaky test (#1925)
There's a very annoying race condition in that test, and we can end up
emitting events twice on slow machines. This isn't an issue so we stop
verifying that we avoid duplicate events.
2021-08-30 16:38:04 +02:00
thomash-acinq
07b022e7fb
Split SendPayment in SendPaymentToRoute and SendPaymentToNode (#1921)
In case we want to retry, this allow us to know what we started with and not try to find a new route when using `SendPaymentToRoute`
2021-08-30 13:15:27 +02:00
Bastien Teinturier
fc36321403
Add TlvStream to all lightning messages (#1891)
This ensures we'll be able to easily enrich messages with future
tlv fields and minimizes the risk of future backwards-compatibility
issues.
2021-08-25 13:36:28 +02:00
Bastien Teinturier
c504658264
Better handling of remote commit confirmation in TxPublisher (#1905)
* Never retry anchor publish when commit confirmed

We used to check the feerate before checking whether the commit tx was
already confirmed: when the commit feerate was good enough, we would
respawn a publish actor every block whereas the commit tx was already
confirmed.

* Abandon evicted replaceable txs

This ensures the bitcoind wallet won't keep the transaction around and
avoid using its inputs for other transactions.

Fixes #1898
2021-08-23 10:21:11 +02:00
Bastien Teinturier
9a0fc14710
Nicer feerate string representation (#1908)
Override toString() for the various feerate classes.
2021-08-18 12:35:26 +02:00
Bastien Teinturier
49e1996391
MPP scale min part amount based on total amount (#1911)
Scale MPP partial amounts based on the total amount we want to
send and the number of parts we allow.

This avoids polluting the results with cheap routes that don't have the
capacity to route when the amount is big.
2021-08-17 16:35:43 +02:00
thomash-acinq
ebed5ad9ea
Add cost per hop and base weight ratio (#1815)
- Add a base weight ratio. Allows to give more weight to the fee itself. Setting the base to 1 is like not using weight ratios.
- Add checks that the configuration values make sense (all weights should be nonnegative and sum to 1). Checks are performed when loading the configuration.
- Add a virtual cost per hop which allows prioritizing short paths. The cost per hop has a base component and a proportional one, similar to channel fees.
2021-08-17 12:36:29 +02:00
thomash-acinq
aab83fdfbc
Don't add channel update to auditDb if it hasn't changed (#1906)
Don't add channel update to auditDb if it hasn't changed
2021-08-17 10:28:25 +02:00
Bastien Teinturier
4cde8c555f
Handle shutdown retransmit when negotiating (#1902)
We didn't handle shutdown messages in the negotiating state, whereas they
may be received upon reconnection. This created some unnecessary warnings
in the logs.
2021-08-16 10:18:54 +02:00
Bastien Teinturier
9f2b0368c7
Rename channel type traits (#1909)
No functional changes, we just rename some traits and a file for clarity.
2021-08-16 09:32:39 +02:00
thomash-acinq
19f4d1f9e1
Refactor db migration (#1901)
* Refactor migration to newer versions of databases
* Put DB name and version in companion object and share it with tests
2021-08-12 12:07:30 +02:00
Bastien Teinturier
a3427172b7
Retry local channel failures in trampoline payments (#1899)
We previously made a single payment attempt per trampoline fee.
Since our channel selection for the first attempt is deterministic, if we
encountered a local failure with that channel, the retries with higher
trampoline fees were hitting the exact same error, whereas we should
instead try a different channel.
2021-08-12 10:19:12 +02:00
thomash-acinq
8f5f6ace54
Set relay fees per node and save them to database (#1890)
* Set relay fees per node and save them to database

- Fees are set per node instead of per channel (setting different fees for different channels to the same node is most probably an error)
- Fees are saved to a database so that we can keep a trace of historic fees and new channels with a known node use the fee that we set and not the default fee.
2021-08-11 18:02:27 +02:00
Pierre-Marie Padiou
131ae8b11d
Balance: do not deduplicate identical htlcs amounts (#1894)
HTLCs are stored in a `Set`, and doing `htlcs.map(_.amount).sum` will
deduplicate identical amounts, resulting in an erroneous balance
calculation. The `Set` must be converted to a `List` first.

Identical htlcs amount are quite frequent due to splitting for AMP.

Co-authored-by: Bastien Teinturier <31281497+t-bast@users.noreply.github.com>
2021-08-09 16:08:43 +02:00
thomash-acinq
6d4da4072c
Different default relay fees for announced and unannounced channels (#1893)
* Different default relay fees for announced and unannounced channels

* nit

Co-authored-by: Pierre-Marie Padiou <pm47@users.noreply.github.com>
2021-07-29 09:04:32 +02:00
Bastien Teinturier
cafaeedef4
Set version to 0.6.2-SNAPSHOT (#1888) 2021-07-19 17:14:08 +02:00
Bastien Teinturier
d3ae32326e
Set version to 0.6.1 (#1887) 2021-07-19 15:36:23 +02:00
Bastien Teinturier
3f1c2506a6
Fix watcher flaky test (#1883)
This test sometimes fail when the `NewTransaction` events are delayed too
much because the CI machine is overloaded.
2021-07-16 19:29:33 +02:00
Bastien Teinturier
adf36de0e1
Fix yet another flaky test (#1886)
If we want C to go to the closed state, we must ensure it's really his claim
transaction that's in the mempool before generating blocks.
2021-07-16 19:18:55 +02:00
Pierre-Marie Padiou
c22596bb92
Update dependencies and enable fatal warnings (#1885)
Co-authored-by: Bastien Teinturier <31281497+t-bast@users.noreply.github.com>
2021-07-16 19:02:18 +02:00
Fabrice Drouin
01b40730fe
Implement option-upfront-shutdown-script (#1846)
* Implement option-upfront-shutdown-script

* Do not activate option_upfront_shutdown_Script by defaut

Users will need to explicitly activate it.

* Send back a warning when we receive an invalid shutdown script
2021-07-16 17:27:56 +02:00
Pierre-Marie Padiou
8c49f779ad
Fix payment handler tests (#1882)
The parallelization introduced with #1880 has created race conditions in tests.
2021-07-16 16:08:16 +02:00
Pierre-Marie Padiou
b4183edfa1
Fetch incoming payments in parallel (#1880)
This is a simpler approach to completely parallelizing the handling of
payments, where we simply parallelize the fetch from the database.

This brings a ~30% performance improvement in performance in `PerformanceIntegrationSpec`.
2021-07-16 14:36:26 +02:00
Bastien Teinturier
51824028b3
Fix flaky channel integration tests (#1879)
Our test suite is putting a lot of strain on our CI machines, and we start
hitting some timeouts. There were places where we would put a 60 seconds
timeout on an `awaitCond` but inside we'd still use the default 15 seconds
timeout.
2021-07-16 14:18:07 +02:00
Pierre-Marie Padiou
3bb7ee8a3e
Parallel payment request generation (#1878)
Delegate the payment request generation, signature and db write to a short-lived child actor.

There is small (~5%) gain in performance in `PerformanceIntegrationSpec` because what matters is the db write, and it is not parallelized in WAL mode.
2021-07-16 13:55:38 +02:00
Pierre-Marie Padiou
d02760d96f
Fail unsigned outgoing htlcs on force-close (#1832)
Fail outgoing _unsigned_ htlcs on force close, just like we do when disconnected.

Fixes #1829.

Co-authored-by: Bastien Teinturier <31281497+t-bast@users.noreply.github.com>
2021-07-16 13:52:25 +02:00
Bastien Teinturier
3ae9a4ae37
Additional reestablish test (#1875)
This test was added to lightning-kmp where this case wasn't correctly
handled: https://github.com/ACINQ/lightning-kmp/pull/278

It is correctly handled by eclair, but an additional test doesn't hurt.
2021-07-16 13:31:24 +02:00
Pierre-Marie Padiou
ca51a2d168
Enable WAL mode on Sqlite (#1871)
[Write-Ahead Logging](https://sqlite.org/wal.html) is both much more performant in general, and more suited to our particular access patterns.

With a simple throughput performance test, it improves performance by a factor of 5-20x depending on the sync flag.

 version                                 | throughput
-------------------------------|-------------
mode=journal sync=normal (*)| 11 htlc/s
mode=journal sync=full| 7 htlc/s
mode=wal sync=normal| 248 htlc/s
mode=wal sync=full (**)| 62 htlc/s 

(*) previous setting
(**) new setting

I went with a conservative new setting of wal+full sync, which is both 5x more performant, and more secure than what we had before.

> In WAL mode when synchronous is NORMAL (1), the WAL file is synchronized before each checkpoint and the database file is synchronized after each completed checkpoint and the WAL file header is synchronized when a WAL file begins to be reused after a checkpoint, but no sync operations occur during most transactions. With synchronous=FULL in WAL mode, an additional sync operation of the WAL file happens after each transaction commit. The extra WAL sync following each transaction help ensure that transactions are durable across a power loss. Transactions are consistent with or without the extra syncs provided by synchronous=FULL. If durability is not a concern, then synchronous=NORMAL is normally all one needs in WAL mode.

Co-authored-by: Bastien Teinturier <31281497+t-bast@users.noreply.github.com>
2021-07-15 18:12:26 +02:00
Bastien Teinturier
733c6e7688
Refactor global balance tests (#1874)
Move balance check test to their own file instead of
adding bloat to the NormalStateSpec tests.

Remove unnecessary parts that belonged to the
NormalStateSpec test.
2021-07-15 17:45:34 +02:00
Pierre-Marie Padiou
e9df4eece0
Channels data format migration (#1849)
There are three otherwise unrelated changes, that we group together to only have one migration:
- remove local signatures for local commitments (this PR)
- separate internal channel config from channel features (#1848)
- upfront shutdown script (#1846)

We increase database version number in sqlite and postgres to force a full data migration.

The goal of removing local signatures from the channel data is that even if the node database or
a backup is compromised, the attacker won't be able to force close channels from the outside.
2021-07-15 16:25:29 +02:00
Pierre-Marie Padiou
547d7e700f
Create chain directory (#1872)
Otherwise the creation of the jdbc url check file for postgres fails.
2021-07-15 10:05:57 +02:00
Pierre-Marie Padiou
95fffe348c
Reduce pg transaction isolation (#1860)
I was able to reproduce #1856 by replaying the "concurrent channel
updates" test with hardcoded additional delays in the database code. It
was due to a conflict between `addOrUpdateChannel` and
`updateChannelMetaTimestampColumn`. The two calls run in parallel and
the latter completed before the former, causing it to fail. Reducing
the isolation level makes the problem disappear.

We reduce the transaction isolation level from `SERIALIZABLE` to
`READ_COMMITTED`. Note that [*]:

> Read Committed is the default isolation level in PostgreSQL.

I'm not sure why we were using a stricter isolation level than the
default one, since we only use very basic queries. Doc does say that:

> This behavior makes Read Committed mode unsuitable for commands that involve complex search conditions; however, it is just right for simpler cases

To make sure this didn't cause regression withe the locking
mechanism, I wrote an additional test specifically on the `withLock`
method.

Here is what the doc says on the `INSERT ON CONFLICT DO UPDATE`
statement, which we use for `addOrUpdateChannel`:

> INSERT with an ON CONFLICT DO UPDATE clause behaves similarly. In Read Committed mode, each row proposed for insertion will either insert or update. Unless there are unrelated errors, one of those two outcomes is guaranteed. If a conflict originates in another transaction whose effects are not yet visible to the INSERT, the UPDATE clause will affect that row, even though possibly no version of that row is conventionally visible to the command.

In the scenario described above, the `addOrUpdate` will update the row
which timestamp was updated in parallel by the
`updateChannelMetaTimestampColumn`, and it's exactly what we want.

Fixes #1856.

[*] https://www.postgresql.org/docs/13/transaction-iso.html
2021-07-08 17:10:16 +02:00
Pierre-Marie Padiou
cea3fc026d
Use proper data type for timestamps in Postgres 2 (#1862)
For some reason, the payments database was forgotten by #1778.
2021-07-08 16:11:06 +02:00
Pierre-Marie Padiou
f8feb19593
Use schemas in Postgres (#1866)
Instead of having a flat organization under the default `public` schema, we classify tables in schemas. There is roughly one schema per database type.

The new hierarchy is:
- `local`
  - `channels`
  - `htlc_infos`
  - `pending_settlement_commands`
  - `peers`
- `network`
  - `nodes`
  - `public_channels`
  - `pruned_channels`
- `payments`
  - `received`
  - `sent`
- `audit`
  - (all the audit db tables)
- `public`
  - `lease`
  - `versions`

Note in particular, the change in naming for local channels vs external channels:
- `local_channels` -> `local.channels`
- `channels` -> `network.public_channels`

The two internal tables `lease` and `versions` stay in the `public`
schema, because we have no meta way of migrating them.
2021-07-08 15:48:22 +02:00
Pierre-Marie Padiou
08faf3b7fd
Add json columns in Postgres (#1865)
A json column has been added to the few tables that contains an
opaque serialized blob:
- `local_channels.data`
- `nodes.data`
- `channels.channel_announcement`, `channels.channel_update_x`

We can now access all the individual data fields from SQL.

For the serialization, we use the same serializers than the one
that were previously used by the API. They have been moved to the
`eclair-core` module and simplified a bit.

There are two json data types in Postgres: `JSON` and `JSONB`. We use
the latter one, which is more recent, and allows indexing.

An alternative to this PR would have been to use columns, but:
- there would have been a *lot* of columns for the channel data
- every modification of our types would have required a db migration

NB: to handle non-backwards compatible changes in the json serializersi,
 all the json columns can be recomputed on restart by setting
`eclair.db.reset-json-columns=true`.

Change in in ChannelCodecsSpec:

The goal of this test is to make sure that, in addition to successfully
decoding data that encoded with an older codec, we actually read the
correct data. Just because there is no error doesn't mean that we
interpreted the data properly. For example we could invert a
`payment_hash` and a `payment_preimage`.

We can't compare object to object, because the current version of the
class has probably changed too. That's why we compare using the json
representation of the data, that we amend to ignore new or modified
fields.

After doing a manual comparison, I updated the test to use the current
json serializers, and replaced the test data with the latest json
serialization. This allows us to remove all the tweaks that we added
over time to take into account new and updated fields.
2021-07-08 15:02:27 +02:00
Pierre-Marie Padiou
bd57d41ef3
Add a globalbalance api call (#1737)
It returns an overall balance, separating onchain, offchain, and
removing duplicates (e.g. mutual closes that haven't reached min depth
still have an associated channel, but they already appear in the
on-chain balance). We also take into account known preimages, even if
the htlc hasn't been formally resolved.

Metrics have also been added.

Co-authored-by: Bastien Teinturier <31281497+t-bast@users.noreply.github.com>
2021-07-08 13:57:49 +02:00
llya Evdokimov
3a573e267a
Improve message for CannotRetrieveFeerates error (#1859)
On testnet or regtest, this can happen frequently because
not enough blocks have been received to estimate fees.
2021-07-07 12:40:50 +02:00
Pierre-Marie Padiou
af8394a280
Add support for dual db backend (#1746)
We still use sqlite as the primary db, but all calls are replicated
asynchronously on postgres.

The goal is to prepare a smooth transition from sqlite to postgres
on a production server. This is a very specific use case and most users
shouldn't use it, which is why the new config `eclair.db.driver=dual` is
not documented.
2021-07-07 11:06:05 +02:00
Bastien Teinturier
d9a03a52b8
Use warning messages for connection issues (#1863)
https://github.com/lightningnetwork/lightning-rfc/pull/834 recommends sending
warning messages instead of connection-level errors in some cases, which
avoids unnecessary channel closure.
2021-07-06 17:56:49 +02:00
Pierre-Marie Padiou
291c128cab
Reduce some log levels (#1864) 2021-07-06 17:17:14 +02:00
Pierre-Marie Padiou
4ca5c62abb
Remove println in tests (#1861) 2021-07-05 18:13:09 +02:00
Bastien Teinturier
516929b1a3
Fix default file backup config (#1857)
The `file-backup` section should be inside `eclair`, otherwise startup fails.
2021-07-02 10:48:45 +02:00
Bastien Teinturier
f52c3dd3fc
Decode warning messages (#1854)
Add support for logging warning messages as introduced in
https://github.com/lightningnetwork/lightning-rfc/pull/834

Support for sending warning messages instead of current errors will be
added in a later PR.
2021-07-01 15:59:08 +02:00
thomash-acinq
f857368ea0
Make trampoline payments use per-channel fee and cltv (#1853)
Trampoline payments used to ignore the fee and cltv set for the local channel and use a global default value instead. We now use the correct fee and cltv for the specific local channel that we take.
2021-07-01 13:32:04 +02:00
Bastien Teinturier
85ed4338a3
Reject 0-value trampoline payments (#1851)
It doesn't make any sense to forward empty payments.
This is also checked when adding the htlcs in the outgoing channel, but
we should fail early here.
2021-06-28 16:50:55 +02:00
Pierre-Marie Padiou
45204e2380
Schedule backup at regular interval (#1845)
This is a bit less trigger happy than previously, and the implementation
is simpler.
2021-06-23 14:37:13 +02:00