1
0
Fork 0
mirror of https://github.com/ACINQ/eclair.git synced 2025-02-22 14:22:39 +01:00
Commit graph

2596 commits

Author SHA1 Message Date
Bastien Teinturier
36a3c8897c
More fine grained support for fee diff errors (#2815)
When there is a mismatch between the feerate of a channel and the
feerate we get from our estimator, we may want to force-close because
that could be exploited by our peer to steal HTLCs. But that's only the
case if the feerate is too low, not if it's too high. We previously
force-closed in both cases, whereas we only need to do it when the
feerate is too low.

This should avoid some unnecessary force-close that we've observed and
are due to buggy fee estimators (fee estimation is hard!), or to peers
who simply do some smoothing and slightly delay lowering the feerate of
our channels.
2024-02-27 13:52:01 +01:00
Bastien Teinturier
5d6a1db9fb
Skip anchor tx when remote commit has been evicted (#2830)
When we detect that the remote commit has been published, we spend our
anchor output from that commit if the fees are too low and we have funds
at risk. But if the remote commit is then evicted from our mempool, we
cannot publish our anchor tx and must instead skip it, since we don't
provide the fully signed remote commitment to the publisher.

We otherwise error when calling `fundrawtransaction`, where `bitcoind`
fails because it cannot find the external non-wallet utxo. This change
gets rid of those errors that can be quite confusing for node operators.
2024-02-22 09:21:13 +01:00
Bastien Teinturier
cd4d9fd4b0
Unlock non-wallet inputs (#2828)
When funding a transaction that contains inputs that are external to our
bitcoin wallet, bitcoin core will add a lock to those external inputs,
thinking that they may be wallet inputs that it doesn't know about yet.
In our case, those are never wallet inputs, they are instead:

- the current channel output, when creating a splice transaction
- an output of the commitment transaction, when force-closing

We previously explicitly filtered those inputs before calling `unlock`,
which was wrong. We now also unlock those utxos.
2024-02-22 09:20:27 +01:00
Bastien Teinturier
0393cfc275
Add require_confirmed_inputs to RBF messages (#2783)
This was missing from the spec, but is more flexible and clearer than
inheriting values from the previous attempt.

Fixes #2782
2024-02-21 17:50:12 +01:00
Pierre-Marie Padiou
e32044f05f
Unlock utxos on reconnect when signatures haven't been sent (#2827)
In the case where we have not sent our `TxSignatures`, and our peer replies with an error at reconnection, we can safely unlock our local inputs.
2024-02-20 15:00:23 +01:00
Thomas HUET
86c483708a
Relay onion messages to compact node id (#2821)
To save space, blinded routes may use a compact node id (scid + direction instead of public key) as an introduction node.
When using such a compact route, the sender must use it's knowledge of the network to convert that to a public key, however trampoline users don't have that knowledge, they must transmit the compact route to the trempoline provider.
We extend the spec to allow compact node ids in the `next_node_id` field.


Co-authored-by: t-bast <bastien@acinq.fr>
2024-02-19 16:25:00 +01:00
Pierre-Marie Padiou
62b739aa22
fixup! Asynchronously clean up obsolete HTLC info from DB (#2705) (#2824)
Fixes a regression caused by #2705 reported by @fishcakeday.
2024-02-15 15:43:19 +01:00
Bastien Teinturier
f41bd22d69
Asynchronously clean up obsolete HTLC info from DB (#2705)
When a channel is closed, we can forget the data from historical HTLCs
sent and received through that channel (which is otherwise required to
punish cheating attempts by our peer).

We previously synchronously removed that data from the DB when the closing
transaction confirmed. However, this could create performance issues as
the `htlc_infos` table can be very large for busy nodes and many concurrent
writes may be happening at the same time.

We don't need to get rid of this data immediately: we only want to remove
it to avoid degrading the performance of active channels that read and
write to the `htlc_infos` table. We now mark channels as closed in a
dedicated table, and run a background actor that deletes batches of
obsolete htlc data at regular intervals. This ensures that the table is
eventually cleaned up, without impacting the performance of active
channels.

When a splice transaction confirms, all the revoked commitment transactions
that only applied to the previous funding transaction cannot be published
anymore, because the previous funding output has already been spent.

We can thus forget all the historical HTLCs that were included in those
commitments, because we will never need to generate the corresponding
penalty transactions.

This ensures that the growth of our DB is bounded, and will shrink every
time a splice transaction is confirmed.

Fixes #2610, #2702 and #2740
2024-02-14 14:06:17 +01:00
Bastien Teinturier
599f9afa2c
Test bitcoind wallet behavior during mempool eviction (#2817)
* Test bitcoind wallet behavior during mempool eviction

When transactions are being evicted from the mempool, we want to make
sure that bitcoind keeps the corresponding wallet inputs locked to
avoid accidentally double-spending ourselves. We update our unit test
to be closer to common scenarios (chain of unconfirmed splice txs and
commit txs replaced by the remote version).

This test confirms that bitcoind keeps wallet inputs locked, and we
have to call `abandontransaction` to free up utxos used in txs that
have been permanently double-spent.

* Test bitcoind wallet behavior during double spend

When one of our wallet transactions is directly double-spent, the
bitcoin wallet detects that and automatically frees up wallet inputs
from the permanently double-spent wallet transaction. This is great,
that means we only need to manually call `abandontransaction` for
transactions that have been invalidated because one of their parents
has been double-spent.
2024-02-13 18:17:21 +01:00
Bastien Teinturier
b5e83a6092
Add closing test reconnect with 3rd-stage txs (#2820)
We had some cases where channels were staying stuck in the CLOSING state
without going to the CLOSED state in previous versions of eclair where
we published different versions of our 3rd-stage transactions after a
restart and a feerate increase.

This happened in two cases:

- when we published a different version of our claim-main, since we only
  store the latest (it's an `Option`, not a `Seq`) and put a watch on
  this specific `txid` instead of watching the corresponding output
- when we re-published 3rd-stage txs after receiving `CMD_FULFILL_HTLC`
  because we replaced the previous `claim-htlc-delayed` transactions

This was on my backlog for a while, and I wanted to take another look at
it after the splicing implementation. Fortunately, this was fixed as
part of the splicing changes, but it's worth having a test to ensure
that there's no regression from future changes.
2024-02-13 17:31:13 +01:00
Bastien Teinturier
3d8dc88089
Abandon transactions whose ancestors have been double spent (#2818)
When a transaction is directly double-spent, bitcoind is able to
automatically detect it and free up wallet inputs that are used
in double-spent transactions. However, when a transaction becomes
invalid because one of its ancestors is double-spent, bitcoind is
not able to detect it and will keep wallet inputs locked forever.

The only cases where this can happen are:

- splice transactions when a commitment transaction that is not
  based on the latest splice is confirmed
- anchor transactions in the above case, or when a different
  version of the commitment confirms (e.g. remote commit while
  we're trying to CPFP ou local commit)

When we detect that this happened, we abandon the corresponding
transactions, which ensures that we don't end up with unusable
liquidity in our wallet.

We also remove cases where we eagerly abandoned transactions,
which could lead us to double-spend ourselves inadvertently
because the abandoned transaction could still confirm while
we reused its inputs in another transaction (which is a real
issue when using 0-conf).
2024-02-07 15:50:12 +01:00
Bastien Teinturier
5b1c69cc84
Add configurable threshold on maximum anchor fee (#2816)
* Add configurable threshold on maximum anchor fee

We previously bumped up to 5% of our channel balance when no HTLCs were
at risk. For large channels, 5% is an unreasonably high value. In most
cases it doesn't matter, because the transaction confirms before we try
to bump it to unreasonable levels. But if the commitment transaction
was pruned and couldn't be relayed to miners, then eclair would keep
trying to bump until it reached that threshold. We now restrict this to
a value configurable by the node operator. Note that when HTLCs are at
risk, we still bump up to the HTLC amount, which may be higher than the
new configuration parameter: we want that behavior as a scorched earth
strategy against pinning attacks.

* Add feerate upper bound from fee estimator

We add a new limit to the feerate used for fee-bumping, based on the
fastest feerate returned by our fee estimator. It doesn't make sense
to use much higher values, since this feerate should guarantee that
the transaction is included in the next block.
2024-02-05 14:38:07 +01:00
Thomas HUET
aae16cf79f
Trampoline to blinded (#2811)
Allow trampoline to pay a list of blinded paths instead of a node id.
Only the last trampoline hop can target blinded paths, trampoline nodes are still reached with their node id, not with blinded paths.

Co-authored-by: t-bast <bastien@acinq.fr>
2024-01-25 18:24:34 +01:00
Thomas HUET
e66e6d2a14
Trampoline to blinded (types only) (#2813)
Add types needed for trampoline to pay a list of blinded paths instead of a node id.
2024-01-23 09:47:50 +01:00
Thomas HUET
5fb9fef978
Variable size for trampoline onion (#2810)
The size of trampoline onions was fixed at 400 bytes. We remove this limit, allowing larger trampoline onions when necessary.
The size of the trampoline onion is still constrained by the size of the standard onion (1300 bytes).

Co-authored-by: t-bast <bastien@acinq.fr>
2024-01-15 11:09:14 +01:00
Pierre-Marie Padiou
c37df26c7a
Add a funding fee budget (#2808)
When opening an important channel we may be willing to pay a high feerate that we wouldn't want to use when consolidating UTXOs. However because we delegate the transaction creation to bitcoin core, we can sometimes be surprised by funding transactions that are much bigger than expected. This PR protects us from such cases by refusing to open the channel if the transaction fee is too high.

Based on original work from @thomash-acinq.
2024-01-10 17:01:17 +01:00
Bastien Teinturier
3bd3d07369
Send batch_size on commit_sig retransmit (#2809)
If we get disconnected after sending `commit_sig`, we will retransmit
that message when reconnecting if our peer has not received it.

When we have multiple commitments, we need to retransmit one message
per commitment, and include the `batch_size` tlv.

We incorrectly stored `commit_sig` without the `batch_size` tlv in the
next remote commit field, and thus retransmitted without that tlv.
2024-01-10 15:05:40 +01:00
Richard Myers
a9b590365c
Fixes for quiescence back ported from lightning-kmp (#2779)
Fixes some issues we found while porting quiescence to lightning-kmp.
2024-01-10 10:38:58 +01:00
Bastien Teinturier
61f1e1f82e
Relay HTLC failure when inactive revoked commit confirms (#2801)
When an inactive revoked commitment containing outgoing HTLCs
is confirmed, we must consider the outgoing HTLC failed and relay that
failure upstream. Because of the alternative commit tx mechanism,
those inactive revoked commitments match the remote commit,
so we were waiting for tx confirmation before failing back upstream.
2024-01-02 16:19:24 +01:00
Pascal Grange
3a49f5dd43
FIX eclair-cli error code in case of HTTP problem (#2798)
Last command of eclair-cli is a curl piped to jq. In case of an
error with the curl command (for instance, eclair service is not
running) the error code was swallowed by the pipe wich will
return the exit code of the last command of the pipe (here, jq).

Setting `pipefail` ensures that the error code of curl is
preserve in case of HTTP issue.

This can come handy, for instance, to check that eclair is not
ok:

```
if eclair-cli getinfo
then
  echo eclair is answering
else
  echo problem communicating with eclair
fi
```
2024-01-02 10:39:07 +01:00
Thabokani
63a1d77baa
Fix typos in various comments (#2805) 2024-01-02 09:31:57 +01:00
Barry G Becker
e05ed03f2f
Fix some typos in CircularRebalancing documentation (#2804) 2024-01-02 09:13:03 +01:00
Fabrice Drouin
eced7b909a
Update bitcoin-lib (#2800)
bitcoin-lib 0.31 depends on secp256k1-kmp 0.12.0 which fixes a bug when parsing BOLT11 invoices with an invalid recovery id.
2023-12-18 18:04:02 +01:00
Bastien Teinturier
9c4aad0688
Dip into remote initiator reserve only for splices (#2797)
#2761 introduced the ability for the HTLC sender to let a remote initiator
dip into its reserve to unblock channels after a large splice. However, we
relaxed that condition for all channels, even those that don't use splice.
This creates compatibility issues with other implementations that are
stricter than what the specification requires, and will force-close in
those situations.
2023-12-08 10:38:54 +01:00
Bastien Teinturier
be4ed3c68b
Update logback-classic (#2796)
This version of logback fixes the following CVE:

"a potential denial of service attack on a centralized logback receiver
when a third party controlling a remote appender connects to said
receiver and could shut down or slow down logging of events."

Eclair isn't affected since we don't use logback receivers, but if there
are applications or plugins that depend on eclair and use logback
receivers, it's better to use the logback version containing the fix.
2023-12-06 15:09:11 +01:00
Bastien Teinturier
d4a498cdd6
Use bitcoinheaders.net v2 format (#2787)
The format used by bitcoinheaders.net is changing to use whole bytes
instead of nibles, which is easier to parse. We start using the v2 format
exclusively, which will allow deprecating the previous format.

Fixes #2786
2023-12-04 15:25:59 +01:00
Fabrice Drouin
f0cb58aed4
Add a txOut field to our InteractiveTxBuilder.Input interface (#2791)
* Add a txOut field to our InteractiveTxBuilder.Input interface

This will help us add support for taproot inputs: to create taproot signatures we need all prevouts (and not just prevouts for tx inputs that spend taproot outputs).
2023-12-04 13:40:04 +01:00
Bastien Teinturier
e73c1cf45c
Use typed TxId (#2742)
And explicitly encode/decode as a `tx_hash` for lightning messages.
2023-11-23 16:04:31 +01:00
Pierre-Marie Padiou
e20b736bf3
Add hints when features check fail (#2777)
This makes it much easier to diagnose incompatibilities.
2023-11-14 16:45:15 +01:00
Thomas HUET
772e2b20f8
Add support for sciddir_or_pubkey (#2752)
Offers (https://github.com/lightning/bolts/pull/798) allow nodes to be identified using either the public key or a pair channel id and direction.
The goal is to save bytes as channel id and direction only use 9 bytes instead of 33 for a public key.
2023-11-14 11:08:33 +01:00
Bastien Teinturier
7be7d5d524
Don't rebroadcast channel updates from update_fail_htlc (#2775)
When we receive a `channel_update` in `update_fail_htlc`, we should take
it into account to exclude channels or correctly retry with updated fees,
but we shouldn't apply it to our routing table.

If we did, that could be exploited to deanonymize our payments.
It shouldn't be necessary anyway, as honest nodes should broadcast
those `channel_update`s publicly, so we would receive them through the
normal gossip mechanism.

Fixes #2767
2023-11-10 16:51:24 +01:00
Bastien Teinturier
0a833a5578
Disable channel when closing (#2774)
As soon as a channel is transitioning to a closing state (mutual or
unilateral close), it cannot be used to relay HTLCs anymore. We should
notify the network by sending a disabled `channel_update`.

Fixes #2766
2023-11-10 16:22:38 +01:00
Pierre-Marie Padiou
5fa7d4b1bb
Nits (#2773)
* remove old arg doc

* reorg methods in Helper

* cleanup imports
2023-11-08 18:25:58 +01:00
Pierre-Marie Padiou
73a2578000
Fix wallet name in BitcoinCoreClientSpec (#2772)
`ByteVector.toString()` was meant to be `toHex()`, and there is a size limit on Windows.
2023-11-07 17:09:41 +01:00
Pierre-Marie Padiou
35e318e951
Remove reserve check if splice contribution is positive (#2771)
If remote has a positive contribution, we do not check their
post-splice reserve level, because they are improving their
situation, even if they stay below the requirement. Note that if
local splices-in some funds in the same operation, remote
post-splice reserve may actually be worse than before, but that's
not their fault.
2023-11-03 18:47:32 +01:00
Bastien Teinturier
830335f917
Avoid unusable channels after a large splice (#2761)
Splicing (and dual funding as well) introduce a new scenario that could
not happen before, where the channel initiator (who pays the fees for the
commit tx) can end up below the channel reserve, or right above it.

In that case it means that most of the channels funds are on the non
initiator side, so we should allow HTLCs from the non-initiator to the
initiator to move funds towards the initiator. We allow slightly dipping
into the channel reserve in that case, for at most 5 pending HTLCs.
2023-11-03 15:09:55 +01:00
Bastien Teinturier
12adf87bb9
Abort interactive-tx during funding (#2769)
If we abort the interactive-tx protocol while we're waiting for bitcoind
to fund the transaction, we must avoid sending an obsolete `tx_add_input`
for the funded transaction. There is a check in `Channel.scala` to only
send an outgoing interactive-tx message if we have an active interactive-tx
session, but this isn't sufficient in the following scenario:

- we disconnect and thus abort the interactive-tx session while bitcoind
  is funding
- we reconnect and restart another interactive-tx session
- bitcoind responds for the first interactive-tx session

In that scenario we would mix `tx_add_input` from the old and the new
interactive-tx session, which leads to a duplicate `serial_id`.
2023-11-03 14:29:39 +01:00
Bastien Teinturier
5a37059b5b
Fix tx_signatures ordering for splices (#2768)
We were incorrectly splitting the shared input amount based on each peer's
balance, but for the signing order the peer that adds the shared input
takes credit for the whole amount of that input.
2023-11-03 14:06:54 +01:00
Bastien Teinturier
5b11f76e00
Ignore duplicate dual-funding signatures (#2770)
If our peer sends us some `tx_signatures` that we already received, we
can safely ignore them.
2023-11-03 14:05:54 +01:00
Bastien Teinturier
a3d90ad18a
Use local dust limit in local commit fee computation (#2765)
Whenever we use the local commit, we must use the local dust limit to
trim HTLCs. Similarly, whenever we use the remote commit, we must use
the remote dust limit.
2023-11-03 13:24:42 +01:00
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