1
0
Fork 0
mirror of https://github.com/ACINQ/eclair.git synced 2025-02-24 06:47:46 +01:00
Commit graph

2023 commits

Author SHA1 Message Date
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
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
Fabrice Drouin
dbecb28d96
Include routing hints in parseinvoice API call response (#1833)
JSON objects returned by parseinvoice do not include routing hints which can be misleading when decoding payment requests created by mobile wallets.
2021-06-01 16:06:38 +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
Pierre-Marie Padiou
f829a2e8ca
Add json type hints on channel data (#1824)
This is particularly helpful when in `OFFLINE` state.
2021-05-25 17:33:09 +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
Anton Kumaigorodski
d437ea1ed1
Improve API plugin support (#1819)
Move `onKit` before `startApiServiceIfEnabled`.
This allows plugins to properly initialize before providing their routes.
2021-05-25 13:01:20 +02:00
Anton Kumaigorodski
9a20aade0a
Allow plugins to inject their own routes into API (#1805)
Plugins can extend the `RouteProvider` trait to enrich the API with
custom calls, removing the need to setup a separate endpoint on a
different port.

When routes clash between plugins, the second one is simply ignored.
Plugin developers should prepend their route with their plugin name
to avoid such silent clashes.
2021-05-19 17:47:06 +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
Dave Scotese
e2b3b4735d
Update Tor doc for Windows (#1811)
Windows needs quotes around file paths.
2021-05-18 09:17:30 +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
Dave Scotese
55a629f11d
Update instructions for downloading Tor Bundle (#1784)
Tor project's website is a bit difficult to navigate. 
Until they fix it, this change will help readers find the Windows "Expert Bundle."
2021-05-14 08:52:14 +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