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

2656 Commits

Author SHA1 Message Date
Thomas HUET
ca3f6814a4
Allow using outgoing channel id for onion messages (#2762)
Allow using a short channel id instead of a public key to designate the next node a message should be relayed to.
2023-11-02 19:38:40 +01:00
Richard Myers
2879a54ad6
Fix a flaky async payment triggerer test (#2764)
Sometimes the notifier for node A has not been killed before node A connects. This causes an extra GetPeerInfo message to be sent to the switchboard and the `assert(request3.remoteNodeId == remoteNodeId2)` check to fail when the GetPeerInfo for node A comes first. Just waiting to receive the `AsyncPaymentTimeout` message is not enough.

If node A connects after node B then this race does not occur.
2023-10-30 17:07:38 +01:00
Thomas HUET
63a3c4297f
Ignore disabled edges for routing messages (#2750)
Other implementations and Eclair (#2703) disable channels only when the other peer is offline.
So disabled channels should no be used for routing messages.

This PR removes `ActiveEdge` that was introduced in #2656
2023-10-02 16:57:45 +02:00
Thomas HUET
9ca922716f
Adapt max HTLC amount to balance (#2703)
Some channels have only a few sats available to send but other nodes don't know it so they try to use them and fail.
When the balance goes below configurable thresholds we now advertize a lower maxHtlcAmount.
This should reduce the number of failed attempts and benefit the network.
2023-10-02 14:47:23 +02:00
Pierre-Marie Padiou
db8e0f9ba6
Fixup! Add metrics on splicing (#2756) (#2759)
We were considering all local outputs as splice outputs, but some may be change.
2023-09-29 17:15:42 +02:00
Bastien Teinturier
e4103a2a65
Simplify dual-funded min-depth calculation (#2758)
We added an override and an optional paramter to be used in feature
branches, but it was actually unnecessary.
2023-09-29 14:08:01 +02:00
Pierre-Marie Padiou
e199d15d9f
Strip witness of interactive tx parents (#2755)
Equivalent to ACINQ/lightning-kmp#542.
2023-09-29 14:06:47 +02:00
Pierre-Marie Padiou
f6dbefd093
Add metrics on splicing (#2756)
This is best effort but should already be pretty useful.
2023-09-29 13:33:26 +02:00
Bastien Teinturier
a3b1f9fb23
Handle splice with local/remote index mismatch (#2757)
We assumed that once quiescent, the local and remote commitment index
would be the same, but that's not true. Those two indices may diverge
because of concurrent updates. We need to keep using the right index for
each commitment during and after a splice, otherwise it leads to "invalid
commit sig" errors.
2023-09-28 17:50:54 +02:00
Bastien Teinturier
0e4985c0e0
Poll bitcoind at startup instead of trying only once (#2739)
When we start, bitcoind may not be ready to handle requests if we restarted
it around the same time. We thus poll it for 30 seconds before giving up.
This is especially useful for tests (e.g. on regtest).
2023-09-27 18:05:18 +02:00
Pierre-Marie Padiou
5dfa0be80d
Remove ChannelFeatures->ChannelType conversion (#2753)
The `ChannelFeatures`->`ChannelType` conversion is problematic for the following reasons:
- It creates an implicit bidirectional mapping between the two classes, which is illogical and error-prone because both directions must be kept in sync.
- Not only must the conversions be kept in sync, it must also be stable over time.
- From the spec p.o.v., the scope of `ChannelType` is really limited to channel opening negotiation, while we currently make it a permanent concept.
- It has weird semantic side effects where we would check channel types in places where we really meant to check commitment formats.
2023-09-27 16:55:41 +02:00
Bastien Teinturier
37f3fbe4b5
Assume widely supported features (#2732)
https://github.com/lightning/bolts/pull/1092 makes some features compulsory
and lets us assume that other nodes have support for them.
2023-09-27 14:14:01 +02:00
Richard Myers
3e1cc9d39c
Update splice to handle pending committed htlcs (#2720)
If a channel has negotiated quiescence with pending htlcs then `InteractiveTxBuilder` will create/verify commit txs which include htlc outputs and create/verify htlc signatures when exchanging `CommitSig`.

 The new attribute `htlcsAmount` of `Output.Shared` and `Input.Shared` accounts for the value in htlcs when computing fees.
2023-09-26 16:45:07 +02:00
Bastien Teinturier
e3ba524306
Improve startup resource usage (#2733)
* Move some logs to debug level

This should reduce the pressure on the file system and RAM without impacting
our ability to troubleshoot common issues.

* Avoid herd effect watching external channels

When we restart, we put watches on every public channel in the network.
That creates a lot of RPC calls to bitcoind, which aren't time-sensitive.
It's ok if we don't see immediately that an external channel was closed,
the spec even recommends waiting for 12 blocks to distinguish a channel
close from a splice.

By default, we now smooth that over a 1 hour period. This means we should
also allow our peers to be late at discovering that a channel was closed.
We thus stop sending a `warning` in that case and increase our tolerance
to that kind of behavior.

* Avoid herd effect watching local channels

When we restart, we set watches on our funding transactions. But we don't
actually need to watch them immediately, we just need enough time to react
to our peer broadcasting their commitment. We use long `cltv_delta` delays
to guarantee funds safety, so we can spread out the watches across several
blocks to reduce the start-up load. It essentially is the same thing as
receiving mempool transactions or blocks after a delay, which is something
that our threat model already takes into account.
2023-09-26 16:31:17 +02:00
Bastien Teinturier
d274fc1939
Allow splicing on non dual-funded channels (#2727)
* Allow splicing on non dual-funded channels

We currently allow splicing on top of a channel that was created without
using dual funding, but it results in an incorrect channel reserve being
used post-splice.

* Rename requestedChannelReserve_opt

This field only applies to the first funding index, so we rename it to
make that explicit. Once a splice has happened, it will be ignored.
2023-09-26 11:22:00 +02:00
Richard Myers
70d150bff6
Fix tests that expect network minimum feerate to be less than other rates (#2751)
A minor fix for tests that rely on the minimum feerate being low.

---------

Co-authored-by: Bastien Teinturier <31281497+t-bast@users.noreply.github.com>
2023-09-26 10:03:08 +02:00
Bastien Teinturier
d4c502a7d6
Use bumpforceclose RPC to also bump remote commit fees (#2744)
We want to be able to bump a force-close regardless of which commitment
was published. If the remote commitment is in our mempool, we will use
our anchor on that commit tx to bump the fees.
2023-09-22 17:53:42 +02:00
Bastien Teinturier
55f9698714
Fix tx_signatures retransmission (#2748)
* Always retransmit tx_signatures if requested

If our peer asks us to retransmit our `tx_signatures`, we should do it even
if the transaction is already confirmed. That means we need to store our
`tx_signatures` because they're annoying to recompute.

* Ignore previously received commit_sig

When expecting a retransmission of `tx_signatures`, we should ignore the
`commit_sig` they send just before if we've already received it. The right
way to check that we've already received it is to compare its signature
to our latest commitment transaction.
2023-09-22 17:48:45 +02:00
Bastien Teinturier
59c612eb21
Fix flaky coin selection tests (#2749)
Some tests related to bitcoind's funding behavior have been randomly
failing since we updated to bitcoind 24.1. They now have more sensibility
over the exact set of available utxos, so we needed to fine-tune them
accordingly.

I also imported some tests that were added to feature branches but never
backported to `master`.
2023-09-22 15:42:43 +02:00
Bastien Teinturier
96ebbfe789
Limit how far we look into the blockchain (#2731)
If we're unable to find the spending tx in the mempool, we start looking
for it in the blockchain. Unfortunately, there are cases where we end up
in that code path even though the spending tx is not confirmed:

- a timeout on the `getTransaction` call
- the spending tx gets dropped from our mempool for some reason
- bitcoind is malicious or buggy

Fetching the whole blockchain isn't really useful: after enough time has
passed, we can be pretty sure that a potential attacker would have claimed
the transaction's outputs already and we can't punish them.
2023-09-21 18:31:08 +02:00
Pierre-Marie Padiou
4e339aa841
Allow specifying a bitcoin wallet with an empty name (#2737)
We make the distinction between _not_ defining a bitcoin wallet name, and using an bitcoin wallet with an _empty_ name.

This remains mostly backward compatible, as:
- by default `eclair.bitcoind.wallet` is undefined so we keep using the default loaded wallet as before
- if user already set `eclair.bitcoind.wallet`, then eclair will use that wallet.
- only in the case where the user left `eclair.bitcoind.wallet` undefined, and if bitcoin had only one wallet with a non-empty name, then eclair will fail right at startup with an explicit error

---------

Co-authored-by: Bastien Teinturier <31281497+t-bast@users.noreply.github.com>
2023-09-21 18:15:25 +02:00
Fabrice Drouin
6f8713788c
Delegate Bitcoin Core's private key management to Eclair (#2613)
* Make Eclair manage bitcoin core's wallet private keys

We create an empty watch-only wallet and import public descriptors generated by Eclair.
Bitcoin Core can fund transaction and manage utxos, but can no longer sign transactions.

* Check that spent amounts and utxos are consistent before we sign a PSBT

PSBT utxo fields include the amount that are being spent by the PSBT inputs, but there is a "fee attack"
where using amounts that are lower than what is actually spent may make us sign a tx that spends much more
in fees than we think.

* Check that non-segwit uxto has been provided and inputs are signed with SIGHASH_ALL

* Verify that Bitcoin Core's fee match what we specified

When we call Bitcoin Core's `fundrawtransaction` RPC method, we check that the fee that we pay match the fee rate that we requested.
The fee is computed using the utxo information that Bitcoin Core adds to our PSBT before we sign it.

We can safely used this information because if Bitcoin Core lies about the value of the inputs that we're spending then the signature we produce will also not be valid (it commits to the value being spent).

When we're adding wallet inputs to "bump" the fees of a parent transaction we need to take the whole package into account when we verify the actual fee rate, which is why some internal methods were modified to return the package weight that was used as reference when `fundrawtransaction` was called.

* Check that fundrawtransaction does not add more than 1 change output

* Validate addresses and keys generated by bitcoin core

When eclair manages private keys, make sure that we can re-compute addresses and keys
generated by bitcoin core.

* Add a separate configuration file for Eclair's onchain signer

Eclair's onchain signer now has its own `eclair-signer.conf` configuration file in HOCON format.
It includes BIP39 mnemonic codes and passphrase, a wallet name and a timestamp.

When an `eclair-signer.conf` file is found, Eclair's API will return descriptors that can be imported into an
empty watch-only Bitcoin Wallet.
When wallet name in `eclair-signer.conf` matches the name of the Bitcoin Core wallet defined in `eclair.conf`
(`eclair.bitcoind.wallet`), Eclair will bypass Bitcoin Core and sign onchain transactions directly.

* Skip validation of local non-change outputs:

Local non-change outputs send to an external address, for splicing out funds for example.
We assume that these inputs are trusted i.e have been created by a trusted API call and our local
onchain key manager will not validate them during the signing process.

* Document why we use a separate, specific file for the onchain key manager

Using a new signer section is eclair.conf would be simpler but "leaks" because it becomes available everywhere
in the code through the actor system's settings instead of being contained to where it is actually needed
and could potentially be exposed through a bug that "exports" the configuration (through logs, ....)
though this is highly unlikely.

* Additional changes to delegate bitcoin core keys to eclair (#2726)

Refactor the `BitcoinCoreClient` and `LocalOnChainKeyManager` to:

- rely less on exceptions
- use more idiomatic scala (reduce dependency on kotlin types)
- provide more detailed logs

We also simplify the `useEclairSigner` field in `BitcoinCoreClient`.
The complexity of handling the case where there was an on-chain key
manager but for a different wallet than the one configured isn't
something that should be used, so it wasn't worth supporting.

Some checks were inconsistent and are now unified:

- checking the exact `scriptPubKey` in our outputs in TODO and TODO
- we allow using `fundTransaction` with a tx that already includes a
  change output (which may happen when RBF-ing a transaction)
- `getP2wpkhPubkeyHashForChange` didn't verify the returned key

We completely separate the two cases in `signPsbt`, because otherwise
in the non eclair-backed case, we were calling bitcoind's `processpsbt`
twice for no good reason, which is bad for performance.

We also decouple the `OnChainKeyManager` from the `BitcoinCoreClient`.
This lets users keep running their eclair node with a bitcoin client that
owns the private key while configuring the on-chain key manager for a
future bitcoin client that will leverage this on-chain key manager.

Users can use the eclair APIs to get the master xpub and descriptors to
properly configure their next bitcoin core node, and switch to it once it
has synchronized the descriptors.

* Simplify replaceable tx funding

We were previously signing twice (with makes a call to `bitcoind`),
just to get the final weights and adjust the change outputs. This was
unnecessary, as we can adjust the weights before adding inputs.

We were also duplicating the checks where we verify that `bitcoind` is
malicious. We only need to check that once, during the final signing step.

---------

Co-authored-by: Bastien Teinturier <31281497+t-bast@users.noreply.github.com>
2023-09-21 15:54:28 +02:00
Bastien Teinturier
148fc673d4
Add RPC to bump local commit fees (#2743)
Node operators may disable automatic fee-bumping on their local commit if
they don't have anything at stake (no pending HTLCs), which saves fees in
most cases. A drawback in that case is that if the commitment doesn't
confirm quickly enough, the remote's funds are also locked.

This can be an issue for LSPs, where the remote peer doesn't have a good
ability to fee-bump commit txs. We give more control to the node operator
by letting them fee-bump local commit txs explicitly through the RPC to
unblock wallet users funds.
2023-09-14 17:07:06 +02:00
Bastien Teinturier
948b4b91db
Don't send splice_locked before tx_signatures (#2741)
When reconnecting in the middle of signing a splice, we must ensure that
splice_locked is sent *after* tx_signatures. Otherwise when using 0-conf
we may retransmit splice_locked before tx_signatures, which our peer will
ignore because they don't have a corresponding fully signed commitment.
2023-09-13 15:40:54 +02:00
Bastien Teinturier
404e3d5ea6
Set child splices as hints in watch-funding-spent (#2734)
We start watching funding outputs once the corresponding funding transaction
has been confirmed with 3 confirmations. We may have already spent that
transaction with a child splice transaction by that time: providing hints
with the corresponding txids to the `ZmqWatcher` improves the performance
when that happens.
2023-09-11 11:01:31 +02:00
Pierre-Marie Padiou
841a8d9b19
Ignore pre-generated shutdown script when possible (#2738)
This is a follow up to #2565, more precisely to the _caveat_ here: https://github.com/ACINQ/eclair/pull/2565#issuecomment-1397052582.

We now create a fresh shutdown script even if one was already generated at channel creation, if the channel doesn't have the mandatory `option_upfront_shutdown_script` negotiated.

The (reasonable) assumption is that other implementations will ignore our pre-generated script if they didn't support the `option_upfront_shutdown_script` feature.

This "on-the-fly" approach is simpler and safer than a db migration.
2023-09-07 21:48:44 +02:00
Fabrice Drouin
8d4205271d
Update kanela-agent version in starter scripts to match the version set in pom.xml (#2730) 2023-08-29 09:06:48 +02:00
Fabrice Drouin
3547f87f66
Use bitcoin-lib 0.29 (#2708) 2023-08-21 11:07:14 +02:00
Thomas HUET
ef25e3287a
Increase timeout for offer tests (#2725)
Increase timeout for tests that would sometime fail
2023-08-17 11:37:22 +02:00
Bastien Teinturier
42249d5ffa
Update to bitcoind 24.1 (#2711)
This lets us use the new `gettxspendingprevout` instead of fetching the
whole mempool when looking for txs spending one of our channels.

A new feature was added to bitcoind 24.1+ that tries to make the change
output indistinguishable from the payment output. This is a great for
privacy, but it adds randomness to coin selection and uses a non-minimal
set of inputs sometimes. We work around this in tests by updating the
amount of the output we want bitcoind to use to make sure it's sufficient to
pay for both the channel funding and the change output.

This shouldn't be too much of an issue for normal operation, where we'll
sometimes use two inputs instead of one, which costs more fees, but
increases privacy.

See https://github.com/bitcoin/bitcoin/pull/24494 for details.
2023-08-16 17:10:03 +02:00
Bastien Teinturier
c7e47ba751
Propagate next remote commit failed htlcs upstream (#2718)
When our peer fails HTLCs, we only propagate the failure upstream once
we've received their revocation for the previous commitment (because they
could otherwise publish the previous commitment and claim those HTLCs).

If they publish the new commitment without sending us their revocation,
we previously didn't propagate the failure upstream, which leads to an
unnecessary force-close. We now correctly handle this scenario.
2023-08-16 17:08:58 +02:00
Bastien Teinturier
4496ea77bc
Add more details to InvalidCommitmentSignatures (#2722)
This can be pretty useful when debugging splicing issues.

Fixes #2721
2023-08-10 12:23:50 +02:00
Richard Myers
47e0b83438
Add quiescence negotiation (#2680)
This change adds support for the quiescence negotiation protocol via the new `stfu` message. When a channel is quiescent, both sides will have the same set of signed htlc commitments and a splice can be performed without requiring the channel to be idle.

An additional PR is still required to update our splice implementation to properly account for in-flight htlcs. Quiescence should currently only be enabled for compatibility testing.

We send a warning and disconnect when a forbidden messages is received during quiescence; a disconnect ends quiescence. If an htlc is fulfilled/failed while quiescent, any preimage will be relayed immediately and the update will be replayed when quiescence ends.

We also send a warning and disconnect if both quiescence and splice negotiation are not complete before the quiescence timeout.

---------

Co-authored-by: t-bast <bastien@acinq.fr>
2023-07-27 11:43:31 +02:00
Bastien Teinturier
3e436114a4
Update dependencies (#2710)
* Update code dependencies

I also wanted to update logback, but I'm hitting issues because of our
custom logger in `FixtureSpec` (`LoggingEventAware` not found).

* Update build dependencies

We're now using mvn 3.9.2 to build eclair, which reports warnings in some
of the build plugins we use. Updating plugins fixes most of the warnings,
and the remaining warnings have to be fixed by the plugins themselves
to support mvn 4.x.
2023-07-13 12:41:45 +02:00
Bastien Teinturier
cf46b64905
Ignore commit_sig for aborted splice (#2709)
After exchanging `tx_complete`, we validate the splice transaction before
sending our `commit_sig`. If we consider the transaction invalid, we send
`tx_abort`. But if our peer thinks the transaction is valid, they will send
their `commit_sig`, which we must ignore until they've acked our `tx_abort`.
2023-07-10 10:39:17 +02:00
Fabrice Drouin
abf1dd3747
Fix AuditDb test (#2707)
Test assumes that payments inserted in the db will be returned in a deterministic order because they have different timestamps.
It may not always be the case if TimestampMilli.now() returns the save value twice.
So here we use explicitly different timestamps: now = TimestampMilli.now(), now + 1.milli, now + 2.milli ....
2023-07-06 10:19:18 +02:00
Bastien Teinturier
42164319a3
Use apache archives for mvn in Docker build (#2706)
The previous repository we used removed the binaries for mvn 3.9.2, which
broke our docker build. It looks like `archive.apache.org` keeps artifacts
longer and hopefully won't break our docker build again soon.
2023-07-04 16:47:19 +02:00
Bastien Teinturier
4c98e1c237
Correctly fail blinded payments after restart (#2704)
When restarting, we weren't checking whether it was using blinded paths.
If we were an intermediate node in the blinded path, we were incorrectly
returning a normal failure: it should be ok, since the introduction node
is supposed to translate those failures, but it's safer to assume that
they don't.
2023-07-03 17:29:12 +02:00
Thomas HUET
9db0063079
Record begin and end timestamps for relays (#2701)
For fighting jamming attempts, or even just to detect one, we need to know how fast relayed HTLCs are fulfilled. We now measure this and store it in the audit database. Previously the "IN" and "OUT" directions for the same HTLC were storing the same timestamp (corresponding to when the HTLC is fulfilled), we now use the timestamp at which we received the UpdateAddHtlc for the "IN" direction.
2023-06-23 13:00:23 +02:00
Pierre-Marie Padiou
1519dd07a4
Log requests for unknown channels as debug (#2700)
We can't do anything about it anyway.
2023-06-21 11:20:25 +02:00
Pierre-Marie Padiou
da98e19540
Simplify on-chain fee management (#2696)
Move away from the "block target" approach.

Get rid of the `FeeEstimator` abstraction and use an `AtomicReference` to store and update the current feerates, similar to the block count.
2023-06-20 11:56:24 +02:00
Thomas HUET
194f5dd2b8
Find route for messages (#2656)
When sending a message, the postman can now ask the router to find a route using channels only.
The same route is also used as a reply path when applicable.

The graph data structure has been updated to include both active and disabled edges.
The graph now contains features for vertices.
2023-06-19 17:01:15 +02:00
Bastien Teinturier
210b9198b3
Back to dev (#2694) 2023-06-19 11:08:09 +02:00
Bastien Teinturier
623f7e4866
Eclair v0.9.0 release (#2693) 2023-06-19 10:21:01 +02:00
Bastien Teinturier
3a351f4d5d
Never serialize ActorRef (#2697)
It turns out that #2688 broke the JSON serialization of the `channels`
API by introducing a new `ActorRef`. We never want to surface `ActorRef`
in JSON responses, so we're defining serializers to filter them out.

Co-authored-by: Fabrice Drouin <sstone@users.noreply.github.com>
2023-06-16 15:31:18 +02:00
Pierre-Marie Padiou
fe9f32bdf1
Minor updates on PeerReadyNotifier (#2695) 2023-06-14 17:06:05 +02:00
Bastien Teinturier
1105a0a7be
Update docker gradle checksum (#2692)
We're verifying the checksum of the gradle archive we fetch before building
the docker image with it. I forgot to update that checksum in #2690
2023-06-14 16:07:20 +02:00
Bastien Teinturier
878eb276b0
Update maven version (#2690)
We were previously relying on mvn 3.6.3 which has reached EOL.
2023-06-14 15:32:20 +02:00
Richard Myers
303c1d45e1
Fix failing test PendingChannelsRateLimiter and clarify other tests (#2691)
---------

Co-authored-by: t-bast <bastien@acinq.fr>
2023-06-14 15:28:36 +02:00
Richard Myers
f1843178b1
Fix problems and add tests for pending channels rate limiter (#2687)
- still needs another PR to make the tests more readable
2023-06-13 16:28:14 +02:00