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

2596 commits

Author SHA1 Message Date
Bastien Teinturier
c2eb357392
Add PeerReadyNotifier actor (#2464)
We add an actor that waits for a given peer to be connected and ready to
process payments. This is useful in the context of async payments for
the receiver's LSP.
2022-12-21 14:18:50 +01:00
Bastien Teinturier
5b19e58601
Improve payinvoice API response (#2525)
When sending an outgoing multi-part payment, we forward the preimage back
to the sender as soon as we receive the first `update_fulfill_htlc`.
This is particularly useful when relaying trampoline payments, to be able
to propagate the fulfill upstream as early as possible.

However this meant that callers of the HTTP API would receive this
preimage event instead of the final payment result, which was quite bad.
We now disable this first event when used with the `--blocking` argument,
which ensures that the API always returns the payment result.

Fixes #2389
2022-12-21 09:16:34 +01:00
Pierre-Marie Padiou
656812e8ca
Commitments clean-up (#2533)
* removed unused code

* remove WaitingForRevocation.reSignAsap

It was hacky and completely un-needed, we just need to check pending changes when we receive a revocation. Probably was a left over for when we batch-signed.

The codec change is more tricky than it may look:
- we keep writing 8 bits in order not to have to introduce a new version
- older codecs use 1 or 8 bits depending on version
2022-12-20 17:33:58 +01:00
Bastien Teinturier
bf087698cc
Update dependencies (#2537)
And move kamon-prometheus to eclair-node/eclair-front.
2022-12-20 16:55:31 +01:00
Bastien Teinturier
b5a2d3a665
Fix blinded route failure messages (#2490)
* Make totalAmount required in blinded final payloads

And update the reference test vector for blinded payments.

* Handle failures inside blinded routes

When a failure occurs inside a blinded route, we must avoid leaking any
information to upstream nodes.

We do that by returning `update_fail_malformed_htlc` with the
`invalid_onion_blinding` code whenever we are inside the blinded route,
and `update_fail_htlc` with the `invalid_onion_blinding` code when we are
the introduction node (and we add a delay).

When we are using only dummy hops or not using any blinded hop, we can
return normal errors.

We also fix an issue we had with `update_fail_malformed_htlc`: when we
received that kind of error from the downstream node, we also returned
an `update_fail_malformed_htlc` error upstream, whereas the specification
says we must convert it to an `update_fail_htlc`.

We also add many e2e tests for blinded payments.
2022-12-16 18:24:35 +01:00
Bastien Teinturier
83edd8c41d
Allow non segwit outputs in dual funding (#2528)
* Remove hard-coded minimum witness weight

The spec provided a value of 107WU for the minimum witness weight, but it
is incorrect: p2tr inputs have a smaller witness than that, and segwit
allows arbitrarily low witnesses.

We remove that hard-code value altogether and consider unsigned
transactions, as we simply cannot do better.

* Allow non segwit outputs

While we restrict inputs to be segwit-only, we can allow any type of
outputs in a dual-funded transaction.
2022-12-16 17:39:32 +01:00
Bastien Teinturier
74719b8b14
Send payments to blinded routes (#2482)
Since blinded routes have to be used from start to end and are somewhat
similar to Bolt 11 routing hints, we model them as an abstract single hop
during path-finding. This makes it trivial to reuse existing algorithms
without any modifications.

We then add support for paying blinded routes. We introduce a new type
of recipient for those payments, that uses blinded hops and creates
onion payloads accordingly. There is a subtlety in the case where we're
the introduction of the blinded route: when that happens we need to
decrypt the first payload to figure out where to send the payment.

When we receive a failure from a blinded route, we simply ignore it in
retries: we don't know what caused the issue so we assume it's permanent,
which makes sense in most cases since we cannot change the relaying
parameters (fees and expiry delta are chosen by the recipient).
2022-12-16 16:52:38 +01:00
Bastien Teinturier
a9146dda09
Fix flaky tests (#2520)
* mempooltxmonitor: no need to unsubscribe from event stream

Adapters are child actors that will die along with their parents, and
the eventstream watches all subscribers for termination:
a8ee6fa42b/akka-actor/src/main/scala/akka/event/EventStream.scala (L50).

* mempooltxmonitor: send block count to actor

This solves a race condition with event stream subscription.

* Fix failing NormalStateSpec test

The `recv CurrentBlockCount (fulfilled signed htlc ignored by upstream peer)`
test was sometimes failing because of an event stream concurrency
issue on busy/slow machines:

- the previous test emits a `LocalChannelDown` event
- the next test starts before this event was emitted and registers to the
  event stream
- then it receives the previous `LocalChannelDown` event before the
  `LocalChannelUpdate`s we expect

* Improve MinimalNodeFixture watcher autopilot

We create an alternative ZmqWatcher that waits for the channel funder
to publish funding transactions before triggering watches.

* Fix ZeroConfAliasIntegrationSpec

A test was added to verify that when building a route to self, we use the
correct scid-alias when available (remote alias instead of local).

This test sometimes failed because Carol hadn't received Alice's channel
update and couldn't build the Alice->Bob hop. The only thing that we meant
to test was the Bob->Carol hop, so we can simplify that and remove the
flakiness,

* Fix MempoolTxMonitorSpec

We use context.pipeToSelf when publishing the transaction, which creates
a race condition between the time when the tx is added to the mempool and
the time where we're ready to process `WrappedCurrentBlockHeight`.

If `WrappedCurrentBlockHeight` arrives before `PublishOk`, the test will
fail waiting for `TxInMempool`.

* Fix TxTimeLocksMonitorSpec

The usual race condition for registering to the event stream applies,
so we directly send the `WrappedCurrentBlockHeight` event.

* Fix ZmqWatcherSpec

Some tests are randomly failing because watches can be triggered several
times and new blocks from previous tests may trigger events in subsequent
tests. We fish for the specific messages we're interested in and ignore
others.
2022-12-16 14:54:36 +01:00
Bastien Teinturier
aa04402bc2
Add anchor outputs zero fee spec test vector (#2400)
As specified in https://github.com/lightning/bolts/pull/1018
2022-12-16 11:06:27 +01:00
Bastien Teinturier
04517f8215
Update title of v0.8.0 release notes (#2531) 2022-12-16 10:53:50 +01:00
Bastien Teinturier
ca831df241
Add a payment recipient abstraction (#2480)
We were previously directly creating onion payloads inside the various
payment state machines and manipulating tlv fields. This was a layering
violation that was somewhat ok because in most cases we only needed to
create the onion payload for the recipient at the beginning of the payment
flow and didn't need to modify it, except for a small change in the MPP
case.

This forced us to handle trampoline onions directly in the payment
initiator and will not work for blinded payments, where we can only build
the onion payload for the recipient after we've chosen the routes and how
to split the amount.

We clean this up by introducing payment recipients that abstract away the
creation of onion payloads. This makes it much easier to integrate blinded
payments. It also allows us to clean up the way we do trampoline payments
and potentially support splitting across multiple trampoline routes (not
included in this PR as this change isn't immediately needed).

It also lets us simplify the MultiPartPaymentLifecycle FSM, by moving the
logic of computing how much remains to be sent and what fee can be used
to the route calculation component.
2022-12-16 10:44:34 +01:00
Bastien Teinturier
7eb50679f0
Add mempool eviction tests (#2529)
When wallet transactions are evicted from the mempool (because their fee
is too low), we have a strong dependency on bitcoind's behavior: it must
not double-spend the inputs of the evicted transaction, otherwise it
could break 0-conf channels.

We verify that behavior in a unit test where we set the mempool to
5MB (the minimum authorized mempool size) and simulate this eviction
scenario.
2022-12-14 09:56:12 +01:00
Bastien Teinturier
8320964c54
Improve htlc_maximum_msat in channel updates (#2299)
* Improve htlc_maximum_msat in channel updates

We previously set the `htlc_maximum_msat` inside `channel_update` to the
channel's capacity, but that didn't make any sense: we will reject htlcs
that are above the local or remote `max_htlc_value_in_flight_msat`.

We now set this value to match the lowest `max_htlc_value_in_flight_msat`
of the channel, and properly type our local value to be a millisatoshi
amount instead of a more generic UInt64.

* Set max-htlc-in-flight based on channel capacity

We introduce a new parameter to set `max-htlc-value-in-flight` based on
the channel capacity, when it provides a lower value than the existing
`max-htlc-value-in-flight-msat` static value.

* Allow disabling max-htlc-value-in-flight-msat

When opening a channel to a mobile wallet user, we may want to set our
`max-htlc-value-in-flight-msat` to something greater than the funding
amount to allow the wallet user to empty their channels using a single
HTLC per channel.
2022-12-13 15:08:35 +01:00
Bastien Teinturier
683328dfe4
Close SQL statements during migrations (#2524)
We weren't correctly closing SQL statements when comparing DBs and
migrating them. All the DB handlers for normal operation (read/write
channels, payments, etc) are already correctly closed after execution.

Fixes #2425
2022-12-13 14:39:45 +01:00
Pierre-Marie Padiou
cdedbdf6b0
Streamline api extractor names (#2521) 2022-12-09 18:40:41 +01:00
rorp
2a7649de40
Add pagination on Audit API (#2487)
Fixes #2451
2022-12-09 08:44:47 +01:00
rorp
908d87fc1d
Switch embedded postgres library used in tests (#2518)
Switch from opentable to its updated fork by zonkyio.
This is necessary when running on Apple M1 chips.
2022-12-08 13:19:29 +01:00
Bastien Teinturier
a0b7a4958b
Remove compatibility code for waitingSince (#2338)
We used to store UNIX timestamps in the waitingSince field before moving
to block count. In order to ensure backward compatibility, we converted
from timestamps to blockheight based on the value.

This code has shipped more than a year ago, so we can safely remove that
compatibility code since it only applies during the channel open or close
period, which cannot last long anyway.

Fixes #2125
2022-12-05 11:58:57 +01:00
Thomas HUET
3b2eb964fd
Fix balance histogram (#2516)
The Kamon histogram was not created properly.
2022-12-01 18:33:38 +01:00
Bastien Teinturier
cd9ca57562
Back to Dev (#2515)
After the v0.8.0 release.
2022-12-01 15:18:59 +01:00
Bastien Teinturier
00774717f6
Eclair v0.8.0 release (#2470) 2022-12-01 14:52:59 +01:00
Bastien Teinturier
77b9aa080b
Remove warning for pruned local channel update (#2514)
When a channel is pruned, it is removed from our graph and thus isn't
found by `d.resolve()`, but it shouldn't create a warning in the logs.
2022-12-01 13:01:29 +01:00
Bastien Teinturier
a230395f5f
Test change address type generation (#2513)
Starting with bitcoind 23.0, a new `changetype` parameter was introduced.
If not specified, bitcoind will generate a change output with a type that
matches the main output to make it harder for chain analysis to detect
which output is the change.

The issue is that lightning requires segwit utxos: if an on-chain payment
is sent to a non-segwit address, we still want our change output to use
segwit, otherwise we won't be able to use it. We thus must set
`addresstype` and `changetype` in `bitcoin.conf` to ensure we never
generate legacy change addresses.
2022-11-30 15:44:40 +01:00
Bastien Teinturier
5b0aa35c8d
Create routes to self using remote alias (#2507)
The introduction of `scid-alias` broke the ability to create a valid route
to our own node using `FinalizeRoute` for private or unconfirmed channels
because we use our local alias as the shortChannelId of the graph edge in
both directions.

Using the same identifier for both directions makes sense, because it's a
stable identifier whereas the remote alias could be updated by our peer.
It's generally not an issue, except when we are building a route, because
our peer will not know how to route if we give them our local alias in a
payment onion (they expect their own local alias, which from our point of
view is the remote alias).

The only way to build routes to ourselves is by using `FinalizeRoute`, so
we fix the issue only in this handler by looking at our private channels
when we notice that we are the destination.
2022-11-30 14:24:17 +01:00
Bastien Teinturier
731a7eedf6
Implement correct ordering of tx_signatures (#2501)
* Implement correct ordering of `tx_signatures`

According to the dual funding specification, the peer that has contributed
the smaller amount of `tx_add_input` must sign first. We incorrectly used
the contributions to the funding output instead of the sum of the inputs
values.

This requirement guarantees that there can be no deadlocks when nodes
are batching multiple interactive-tx sessions.

* Send error instead tx_abort in interactive-tx

When building the first version of a dual-funded transaction, we should
use `error` instead of `tx_abort` if we encounter a failure. It makes it
more explicit to our peer that the channel should be closed at that point,
whereas `tx_abort` can be used in RBF attempts to abort a secondary
interactive-tx sessions without closing the channel.
2022-11-30 13:24:30 +01:00
Bastien Teinturier
8afcb46791
Fix closing channel state when nothing at stake (#2512)
This is a follow up to #2360 which was actually buggy: the channel actor
doesn't stop itself immediately after going into the CLOSED state, so it
received a `WatchFundingTxSpent` event that was handled in the global
`whenUnhandled` block, logged a warning and went back to the CLOSING
state.

We now go through the normal steps to close those channels, by waiting
for the commit tx to be confirmed before actually going to CLOSED.
2022-11-29 17:10:36 +01:00
Thomas HUET
6569eaf07d
Cancel previous LiftChannelExclusion (#2510)
Keep at most one scheduled `LiftChannelExclusion` by cancelling the previous one if the new ban lasts longer
2022-11-28 12:25:43 +01:00
Thomas HUET
e32697e798
Build Bolt12 invoices with provided intermediary nodes (#2499)
Allows creating arbitrary blinded routes for BOLT12 invoices.
2022-11-24 18:32:07 +01:00
Thomas HUET
6d3991bc74
Accept payments to zero-hop blinded route (#2500)
In case of a zero-hop blinded route, the final blinding point is not in the `UpdateAddHtlc` but in the payload itself.
2022-11-23 16:21:29 +01:00
Fabrice Drouin
1e252e56c7
Make eclair-cli -s display short channel ids correctly (#2488)
in "short/compact mode" (-s), eclair-cli was not getting short channel ids from the right place and they were always set to null.
2022-11-15 15:56:40 +01:00
Thomas HUET
37a3911015
Fix circular dependency (#2485)
Fixes a circular dependency between OfferCodecs and LightningMessageCodecs by putting feature codecs in CommonCodecs instead.
2022-11-15 14:10:29 +01:00
Bastien Teinturier
003aae053a
Explicitly request bech32 static remotekey (#2486)
When using `static_remotekey`, we ask `bitcoind` to generate a receiving
address and send the corresponding public key to our peer. We previously
assumed that `bitcoind` used `bech32`, which may change since #2466.

We need to explicitly tell `bitcoind` that we want to use a p2wpkh address
in that case, otherwise it may generate a `p2tr` address, we will use that
public key to get our funds back, but `bitcoind` will not detect that it
can spend this output (because it only expects this public key to be used
for a taproot address).
2022-11-14 18:34:41 +01:00
Bastien Teinturier
6eba3e76da
Fix static default from and to pagination (#2484)
The default values were generated once when the eclair node starts instead
of being recomputed for every request. Fixes #2475.

We also add pagination to the `listPendingInvoice` API as a follow-up for
#2474.
2022-11-14 16:03:40 +01:00
Bastien Teinturier
7dbaa41f39
Update to bitcoind 23.x (#2466)
This release of bitcoind contains several bug fixes that let us simplify
our fee bumping logic:

- fixed a bug where bitcoind dropped non-wallet signatures
- added an option to fund transactions containing non-wallet inputs

It also has support for Taproot, which we want in eclair.
2022-11-14 13:47:48 +01:00
rorp
8f1af2851d
Add pagination on listInvoices (#2474)
Add support for count/skip arguments to the `listInvoices` API.
Fixes #2450
2022-11-14 09:56:10 +01:00
Pierre-Marie Padiou
9ae4dea03e
Reduce diff with feature branch (#2476)
Those are minor changes that mostly touch tests.
2022-11-08 15:50:27 +01:00
Bastien Teinturier
090680403a
Support scid_alias and zero_conf for all commitment types (#2404)
We previously only supported `scid_alias` and `zero_conf` when used in
combination with `anchors_zero_fee_htlc_tx`, but we have no way of
advertising that to our peers, which leads to confusing failures when
opening channels.

Some nodes that don't have good access to a utxo pool may not migrate to
anchor outputs, but may still want to use `scid_alias` (and potentially
`zero_conf` as well).

Fixes #2394
2022-11-04 19:19:45 +01:00
Bastien Teinturier
a566d53a6e
Allow nodes to overshoot final htlc amount and expiry (#2468)
When nodes receive HTLCs, they verify that the contents of those HTLCs
match the intructions that the sender provided in the onion. It is
important to ensure that intermediate nodes and final nodes have similar
requirements, otherwise a malicious intermediate node could easily probe
whether the next node is the final recipient or not.

Unfortunately, the requirements for intermediate nodes were more lenient
than the requirements for final nodes. Intermediate nodes allowed overpaying
and increasing the CLTV expiry, whereas final nodes required a perfect
equality between the HTLC values and the onion values.

This provided a trivial way of probing: when relaying an HTLC, nodes could
relay 1 msat more than what the onion instructed (or increase the outgoing
expiry by 1). If the next node was an intermediate node, they would accept
this HTLC, but if the next node was the recipient, they would reject it.

We update those requirements to fix this probing attack vector.

See https://github.com/lightning/bolts/pull/1032
2022-11-04 18:57:47 +01:00
Bastien Teinturier
31f61c1ca5
Randomize final cltv expiry (#2469)
When sending outgoing payments, using an expiry that is very close to
the current block height makes it obvious to the next-to-last node
who the recipient is.

We add a random expiry to the amount we use to make it plausible
that the route contains more hops.
2022-11-04 18:37:24 +01:00
Bastien Teinturier
a8389a042a
Add private flag to channel updates (#2362)
Add a message flag to channel update to specify that an update is private
and should not be rebroadcast to other nodes.

We log an error if a private channel update gets into the rebroadcast list.

See https://github.com/lightning/bolts/pull/999
2022-11-04 15:56:21 +01:00
Bastien Teinturier
c385ca225f
Add support for arbitrary length onion errors (#2441)
The specification recommends using a length of 256 for onion errors, but
it doesn't say that we should reject errors that use a different length.

We may want to start creating errors with a bigger length than 256 if we
need to transmit more data to the sender. In order to prepare for this,
we keep creating 256-bytes onion errors, but allow receiving errors of
arbitrary length.

See the specification here: https://github.com/lightning/bolts/pull/1021

Fixes #2438
2022-11-04 12:14:46 +01:00
Bastien Teinturier
21c6278305
Only use txid in error messages (#2423)
We previously had a few error messages where we would send the complete
offending transaction instead of just its txid. This can be dangerous if
we accidentally send a signed transaction that our counterparty may
broadcast.

We are currently careful and avoid sending signed transaction when it may
be dangerous for us, but there's a risk that a refactoring changes that.
It's safer to only send the txid.
2022-11-04 10:49:48 +01:00
Fabrice Drouin
7c8bdb959b
Explain how and why we use bitcoin core (#2473)
* Explain how and why we use bitcoin core

Explain why we chose to delegate most on-chain tasks to bitcoin core (including on-chain wallet management), the additional requirements that it creates and also the benefits in terms of security.
2022-11-03 09:04:20 +01:00
Bastien Teinturier
a11984bf3f
Use tx_hash in dual funding and verify nSequence (#2463)
The `tx_signatures` message uses `tx_hash` instead of `txid`.
Thanks @niftynei for pointing this out.

Reject `tx_add_input` with an `nSequence` set to `0xfffffffe` or
`0xffffffff`. In theory we only need one of the inputs to have an
`nSequence` below `0xfffffffe`, but it's simpler to check all of them
to be able to fail early in the protocol.
2022-10-21 10:32:12 +02:00
Bastien Teinturier
5e85c7ce01
Fix pruned channels coming back online (#2456)
When a channel was pruned and we receive a valid channel update for it,
we need to wait until we're sure both sides of the channel are back
online: a channel that has only one side available will most likely not
be able to relay payments.

When both sides have created fresh, valid channel updates, we restore the
channel to our channels map and to the graph.

We remove the custom `pruned` table and instead directly use the data
from the channels table and cached data from the router.

Fixes #2388
2022-10-20 12:05:42 +02:00
Bastien Teinturier
1f32652465
Add tlv to require confirmed inputs for dual funding (#2461)
Add tlv to require confirmed inputs in dual funding: when that tlv is specified,
the peer must use confirmed inputs, otherwise the funding attempt will be
rejected. This ensures that we won't pay the fees for a low-feerate ancestor.

This can be configured at two levels:

- globally using `eclair.conf`
- on a per-channel basis by overriding the default in `Peer.OpenChannel`
2022-10-19 17:24:55 +02:00
Thomas HUET
dd3d694b60
Remove onion message size limit (#2459)
We used to drop onion messages above a certain size, but the onion message packet is already limited to 65536 bytes so we only keep this larger limit instead.
2022-10-19 15:07:52 +02:00
Bastien Teinturier
c1a925db11
Use 0-conf based on local features only (#2460)
If we have activated 0-conf support for a given peer, we send our
`channel_ready` early regardless of whether our peer has activated support
for 0-conf. If they also immediately send their `channel_ready` it's great,
if they don't it's ok, we'll just wait for confirmations, but it was worth
trying.
2022-10-19 11:57:20 +02:00
Thomas HUET
a0433aa0c0
Fix flaky CommitmentsSpec test (#2458)
In case feeRatePerKw is high and liquidity is low on the initiator side, the initiator can't send anything and the test would fail because we try to create a HTLC for an amount of 0.
2022-10-18 12:35:44 +02:00
Thomas HUET
3b12475794
Make payment secret not optional (#2457)
Payment secret is already required for doing anything but the code was still using an option.
2022-10-18 10:06:48 +02:00