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

2455 commits

Author SHA1 Message Date
Thomas HUET
df0e7121ef
Add offer manager (#2566)
Because offers are a very generic mechanism, handling them can require interacting with an inventory system (do we actually have the quantity that the payer is requesting) or other such systems which do not have their place inside eclair. For this reason offer handlers must be implemented as plugins that communicate with the offer manager.
On startup, the offer handlers must register their offers with the offer manager, the offer manager will then forward the invoice requests and blinded payments to the relevant offer handler for approval.
2023-03-27 18:37:14 +02:00
Richard Myers
732eb31681
Add limit for incoming connections from peers without channels (#2601) 2023-03-24 14:05:10 +01:00
Bastien Teinturier
e1cee96c12
Fix opportunistic zero-conf (#2616)
If we didn't plan on using zero-conf, but our peer sends us an early
channel_ready, we can opportunistically switch to zero-conf.

But we can only do that if we're sure that our peer cannot double-spend
the funding transaction. We previously checked their contribution to the
funding output, but that's not enough: they may add inputs to the funding
transaction even if they don't contribute to the funding output.

We were also setting duplicate `WatchPublished` in case we were already
using zero-conf, which is now fixed.

When our peer sends us channel_ready while we're still waiting for
confirmations, we may opportunistically switch to zero-conf, in which
case we have both a WatchPublished and a WatchConfirmed pending.
But it may not actually be a real switch to zero-conf: maybe the
transaction is confirmed, and they simply received the block slightly
before us. In that case, the WatchConfirmed may trigger first, and it
would be inefficient to let the WatchPublished override our funding
status: it will make us set a new WatchConfirmed that will instantly
trigger and rewrite the funding status again.
2023-03-23 18:50:35 +01:00
Fabrice Drouin
f4326f4b26
Use bitcoin-lib 0.27 (#2612) 2023-03-16 15:05:58 +01:00
Bastien Teinturier
a52a10a040
Update Bolt 3 tests (#2605)
Add latest changes from https://github.com/lightning/bolts/pull/1018
Add latest fixes from https://github.com/lightning/bolts/pull/1056
2023-02-28 15:17:43 +01:00
Richard Myers
1c9c694fb5
Add new command to fix flaky tests in PendingChannelsRateLimiterSpec (#2606) 2023-02-28 15:17:19 +01:00
Pierre-Marie Padiou
df590d8d30
Make updateLocalFundingStatus method return Either (#2602)
After calling this method, we perform actions at several places that
only make sense if the correct behavior happened. Instead of assuming
things went ok, we use proper typing and make the result explicit.
2023-02-20 17:32:08 +01:00
Bastien Teinturier
a3c6029e1d
Limit number of RBF attempts during dual funding (#2596)
Each RBF attempt adds more data that we need to store and process,
so we want to limit our peers to a reasonable use of RBF.

We send a warning to let them know that they are close to reaching the
limits.
2023-02-17 17:36:06 +01:00
Bastien Teinturier
1a79e75a63
Replace Commitments with MetaCommitments (#2599)
There are two possible strategies for MetaCommitments:

1. Move the duplication between every Commitment in a shared field
2. Access duplicated fields through the first Commitment

I initially wanted to go with solution 1., but it makes commitments really
hard to work with. The main reason is that the `CommitmentSpec` abstraction
is a very good abstraction to work with when updating commitments,
and it requires keeping the htlcs inside every commitment.

As long as we update commitments in a loop, there is no risk of common
values being desynchronized. Since they contain mostly pointers to shared
data, the memory overhead is negligible, as long as we make sure we don't
duplicate the data when serializing to disk. We're thus choosing solution 2.

We serialize htlcs separately and rebuild `CommitmentSpec` objects when
deserializing. We also only keep the main htlc fields during json serialization
to avoid performance issues when writing json fields to the DB. There was
no good reason to serialize everything as we previously did.
2023-02-17 16:57:53 +01:00
Bastien Teinturier
e3bba3d022
Remove reserve requirement on first commitment (#2597)
This requirement was always met for single-funded channels, but for dual
funded it may not be met if the non-initiator contributes a very large
amount (more than 100x what the initiator contributes). That scenario
could happen, and the funding attempt shouldn't fail as long as the
initiator's balance contains enough funds to pay the commit tx fees.
2023-02-17 13:37:27 +01:00
Bastien Teinturier
fcc52a84ca
Prepare InteractiveTxBuilder to support splicing (#2595)
Adding splicing to the InteractiveTxBuilder requires:

- adding a shared input (the current funding output)
- adding outputs (when splicing out)

The `localAmount` and `remoteAmount` provided are the amounts each peer
contributes to the new funding output. Those amounts should be computed
by the caller depending on what they intend to do (splice funds in/out).
This model allows batching operations: if the caller wants to do several
splices in and several splices out, this is easy to do by iterating over
these operations and updating the targeted `localAmount` accordingly,
the InteractiveTxFunder will take care of the rest.

Note that when splicing, we currently truncate previous balances to sats.
This results in 1 sat being given away to miners as fees, and a passive
participant losing up to 999 msat of their balance. This can be changed
in the future depending on the final spec choice, and shouldn't need a
codec update since the previous balances come from the commitment field
provided in the purpose.

When splicing, the tx_add_input message we send for the shared input
doesn't contain the previous transaction. There are two reasons for
that:

- it potentially doesn't fit into a lightning message (if > 65kB)
- we don't need it, we know it correctly uses segwit
2023-02-17 12:53:21 +01:00
Richard Myers
ddcb978ead
Add support for plugins that intercept open channel messages (#2552) 2023-02-17 08:56:51 +01:00
Thomas HUET
d4c32f99dd
Add support for paying offers (#2479)
Add a new actor paying an offer: sends an invoice request, wait for the invoice, retries if needed, pay the invoice
2023-02-16 18:57:43 +01:00
Bastien Teinturier
69042835a2
Handle next remote commit in ReplaceableTxPublisher (#2600)
The ReplaceableTxPublisher only looked at the remote commit and ignored
the case where our peer publishes their next commit. This created two
issues:

- eclair would keep trying to publish htlc transactions that had no chance
  of confirming, which is a waste of resources
- eclair would fail to RBF claim-htlc transactions: this had no impact today
  because we currently target the next 2 blocks so RBF isn't necessary,
  but it will become useful if we allow setting a more economical block
  target in the future
2023-02-16 17:37:41 +01:00
Pierre-Marie Padiou
202598d14e
Introduce a specific funding status for zeroconf (#2598)
We used to consider zero-conf funding txs as _confirmed_ as soon as they were _published_, but it was hacky. Before splices, it prevented RBF-ing zero-conf txs, which in theory make sense (we start using the channel without confirmations, but may still want to bump the fees later). After splices, it would prevent using a channel while a splice tx is pending confirmation (even if the channel isn't zero-conf).

What we are really doing is separating the state of the channel, from the state of the blockchain. As a consequence the management of the funding tx is more independent from the channel FSM, which is why we end up with catch-all handlers for `WatchPublishedTriggered`/`WatchFundingConfirmedTriggered`.

As a side effect, we also simplify how we put watchers: instead of putting them back at every connection, we do this once and for all (either when creating the channel, or at restart).

---------

Co-authored-by: t-bast <bastuc@hotmail.fr>
2023-02-16 11:23:32 +01:00
Bastien Teinturier
6483896b3b
Add ChannelAborted event (#2593)
That additional event lets subcribers know when a channel was closed
without ever being used.

The possible flows for a channel lifecycle are now:

- ChannelCreated -> ChannelOpened -> ChannelClosed
- ChannelCreated -> ChannelOpened -> ChannelAborted
- ChannelCreated -> ChannelAborted
- ChannelCreated -> ChannelClosed
- ChannelAborted

Co-authored-by: Richard Myers <remyers@yakshaver.org>
2023-02-03 14:11:56 +01:00
Bastien Teinturier
a54ae2200b
Remove unnecessary dust limit hack in interactive-tx (#2594)
We previously inflated the funding amount to always exceed the dust limit,
otherwise bitcoind would reject the funding attempt. It complicated the
code for a scenario that doesn't make sense in practice, so it's better
to just let the funding attempt fail in that case.

We also randomize the order of inputs and outputs, which is a common
privacy best practice.
2023-02-02 14:29:52 +01:00
Pierre-Marie Padiou
01ec73b1e3
Store fundingParams with the sharedTx (#2592)
It makes sense to store the params with each `rbf` attempt (as
opposed to the last one currently), and allows us to remove
`DATA_WAIT_FOR_DUAL_FUNDING_CONFIRMED.fundingParams`.
2023-01-31 15:38:23 +01:00
Bastien Teinturier
f23e2c5fc5
Clarify contribution guidelines around rebasing PRs (#2591)
It isn't obvious when a contributor should rebase a PR.
Hopefully the additional paragraph clarifies the rules around rebasing.
2023-01-31 13:28:12 +01:00
Thomas HUET
198fd934f3
Allow sending message to route that starts with us (#2585)
In case we are the introduction node of a message blinded route, we would not be able to send a message to that route. We now unwrap the first hop in case the route starts with us.
2023-01-30 17:43:58 +01:00
Richard Myers
f901aeac04
Fix ability for plugins to exchange custom Lightning Messages with other LN nodes (#2495)
Required for the PeerSwap plugin and other plugins that exchange custom Lightning messages
2023-01-27 19:57:11 +01:00
Thomas HUET
927e1c8ad4
Absolute priority to local channels (#2588)
Even when there is a path that is a lot cheaper, we still want to use the local channel.
2023-01-26 17:34:43 +01:00
Thomas HUET
2857994cf3
Equality for TlvStream (#2586)
The order of the elements in a TLV stream is an implementation detail that will disappear with serialization. Equality between TlvStream shouldn't depend on this order.
For that we use `Set`s instead of `Iterable`s.
2023-01-26 16:22:43 +01:00
Bastien Teinturier
46999fd3b6
Use MetaCommitments as much as possible (#2587)
This reduces our dependency on `Commitments`, and makes
it more obvious where we really need a specific commitment
(and thus need to be careful when we have multiple).

This doesn't contain any logic changes, it's purely a refactoring.
2023-01-26 13:19:51 +01:00
Fabrice Drouin
28072e8d69
Select final onchain address when closing (#2565)
* Add a finalScriptPubKey field to DATA_CLOSING (no functional changes)

* Add an explicit finalScriptPubKey parameter to helper methods (no functional changes)

* Rename LocalParams field defaultFinalScriptPubKey to upfrontShutdownScript_opt

`localParams.upfrontShutdownScript_opt` is now optional, and a new field has been added to DATA_CLOSING: finalScriptPubKey, which is the actual pubkey script onchain funds are sent to.

When reading DATA_CLOSING data serialized with older codecs, we rely on the fact that `localParams.upfrontShutdownScript_opt` was always present and was actually used as the final onchain
destination: it is safe to use `localParams.upfrontShutdownScript_opt.get` to populate DATA_CLOSING's finalScriptPubKey field.

* Update closing address when possible

When a channel gets closed, and when possible, we send all onchain funds to a recent onchain address and not
to an address that was generated when the channel was created.

This is possible for new channels in all cases except when mutual-closing a channel that sets `upfront-shutdown-script`.

Existing channels, which will keep sending onchain funds to addresses generated when they were created. Migration for existing channels will be handled in another PR.

Co-authored-by: Pierre-Marie Padiou <pm47@users.noreply.github.com>
2023-01-26 10:51:23 +01:00
Bastien Teinturier
e3e1ee5231
Refactor commitments and meta-commitments (#2579)
Move all the logic that was previously inside `Commitments` to `MetaCommitments`.
The code changes are quite minimal, with a few subtleties: we need to update the
local/remote commit indices separately of the commitments themselves, because
they're not in the same data structure (yet).

Some of these changes show where the current model doesn't work well:

- `remotePerCommitmentPoint` is duplicated across all remote commits:
  it's not obvious, but it has to be the same value
- htlcs should be shared between commitments
- the coupling between `remoteNextCommitInfo` and `nextRemoteCommit_opt`
  is really weird to work with (especially in `receiveRevocation`): this can be fixed
  by slightly re-working the model

The data model will be updated in future commits to fix these issues.
2023-01-24 18:24:54 +01:00
Pierre-Marie Padiou
9611f9e246
Improve InteractiveTxBuilder model (#2576)
We introduce a `Purpose` trait, which indicates what the operation is about. Currently there are two possibilities:
- `FundingTx`
- `FundingTxRbf`

This allows for some nice factoring, but more importantly it will be complemented by a third possibility for splices.

Note that this change preserves the original separation between two main concerns:
- creating the funding tx (in `InteractiveTxParams`)
- creating the commitment (in `InteractiveTxBuilder`).
2023-01-23 17:21:28 +01:00
Pierre-Marie Padiou
1d5af4df5e
Read channel db only once at restart (#2569)
Fixes #2478.

I tried to keep the changes minimal, but had to move the _read_ from `Setup` to `Setup.bootstrap`, otherwise we would have kept a reference of the initial channels list forever.

Checking the db now happens a bit further in the startup procedure, but it is still blocking, and before the actors are initiated.
2023-01-23 14:05:57 +01:00
Bastien Teinturier
d52e869a4d
Don't send payment secret when using keysend (#2574)
Apparently lnd rejects keysend payments that contain a payment secret,
instead of simply ignoring that field.

The blip doesn't mention this requirement:
https://github.com/lightning/blips/blob/master/blip-0003.md

But we don't have a strong reason to send it either, so let's remove that.
2023-01-23 12:00:40 +01:00
Florian Schmaus
8084f3c7fc
Properly quote urls in bash scripts (#2580)
To avoid bash interpreting '&' as background job metacharacter,
properly quote the string containing it.

Otherwise you get output like the following:
eclair-node[3517981]: No java installations was detected.
eclair-node[3518011]: Please go to https://adoptopenjdk.net/?variant=openjdk11
eclair-node[3518012]: /usr/bin/eclair-node: line 285: and: command not found
2023-01-23 11:38:44 +01:00
Richard Myers
9d4f2baedf
Add replyTo field to Router.GetNode (#2575) 2023-01-20 13:34:19 +01:00
Bastien Teinturier
06fcb1f632
Dual funding latest changes (#2536)
* Update `require_confirmed_inputs` tlv

It has been assigned tlv type 2 in the specification.

* Add second per-commitment point to dual funding

We can send the second per-commitment point right at the beginning of the
channel opening flow, to avoid the awkwardness of having to store an
invalid value in `remoteNextCommitInfo` until we receive `channel_ready`.

* Echo incoming tx_abort

When we receive tx_abort, we echo it back to let our peer know we've seen
their tx_abort and have reset our internal state accordingly.

Spec commit:
07cc0edc79
2023-01-20 13:25:05 +01:00
Pierre-Marie Padiou
c52bb694ea
Rework data model for splices (#2540)
This is a collection of independent changes in preparation for splices. We group them inside a single PR so we don't have to support multiple intermediate codecs versions:
- store the full funding tx inside `Commitments`
- store the local/remote status for the funding tx inside `Commitments`
- define a `MetaCommitments`, which is a list of `Commitments`
- split `Commitments` between `Params`/`Common`/`Commitment`.

⚠️ This PR includes a new db codec version, and restricts Eclair to `regtest` in order to be able to squash further codec changes before the next release, without having to support intermediate versions.

Co-authored-by: t-bast <bastuc@hotmail.fr>
2023-01-20 10:06:58 +01:00
Thomas HUET
204bc3e9b1
Build message inside Postman (#2570)
The postman now has a higher level API to send messages: the user provides the content and the paths to use and the postman takes care of building the message packet and sending it to the next node.
2023-01-19 16:41:28 +01:00
Bastien Teinturier
303799e6e9
Allow keysend payments without a payment secret (#2573)
Apparently lnd and cln don't send a payment secret when using keysend,
even when we advertize the feature as mandatory. This is ok though, we
don't actually need a payment secret to protect keysend payments as long
as the sender doesn't use MPP (which is their responsibility, not ours).

Since our codebase requires payment secrets to index payments, we simply
use the preimage as secret when receiving keysend payments.
2023-01-19 16:28:28 +01:00
Bastien Teinturier
b21085ddd6
Add ChannelOpened event (#2567)
* Add ChannelOpened event

Emit an event when a channel is opened and ready to process payments.
This event is distinct from the `ChannelCreated` event which is sent
earlier, once we think a funding transaction has been successfully created
(but cannot guarantee when we're not the initiator).

* Add event to websocket

This is a breaking change, but it should be ok since the previous event
wasn't reliable: it was emitted at a time where we couldn't guarantee
that the channel would really confirm.
2023-01-16 16:46:13 +01:00
Bastien Teinturier
6486449404
Add GetNode router API (#2568)
Add a new API to return information about a specific node: its announcement,
number of active channels and total capacity.
2023-01-16 15:13:09 +01:00
Barry G Becker
b2bde6367b
Use case classes for fee providers (#2454)
Instead of standard classes.
2023-01-16 15:03:27 +01:00
Pierre-Marie Padiou
1d68ccc46f
Make creation of first commit tx more generic (#2564)
In preparation for splices, we make `makeFirstCommitTxs` more generic:
- expose the `commitmentIndex`, which was hardcoded to `0`
- take the funding/push amounts arithmetic out

We rename the existing method to `makeCommitTxsWithoutHtlcs` and define a new `makeFirstCommitTxs` with the exact same signature as before, making the change transparent from the outside.
2023-01-13 18:05:50 +01:00
Bastien Teinturier
4dd48297d5
Move interactive-tx funding to a dedicated actor (#2561)
This commit refactors the funding steps of an interactive-tx to a separate
actor: it doesn't contain any business logic changes.
2023-01-12 16:29:45 +01:00
Pierre-Marie Padiou
f02d33dadd
Do not hardcode input index at signature (#2563)
Since we only sign one-input txs, the input index was hardcoded to `0`,
but with splices we will spend previous funding txs, which may have a
change. The change is trivial since we do have all the info to figure
out the output index.
2023-01-12 13:27:04 +01:00
Bastien Teinturier
20c9a58d40
Skip waiting for empty tx_signatures (#2560)
When our peer doesn't contribute to an interactive-tx session, we don't
need to wait for their `tx_signatures`: they will be empty anyway, so we
can create them locally and publish the transaction immediately.
2023-01-12 13:15:56 +01:00
Bastien Teinturier
6b6725e40d
Always lock utxos when funding transactions (#2559)
We must *always* lock inputs selected for funding, otherwise locking
wouldn't work at all, as the following scenario highlights:

- we fund a transaction for which we don't lock utxos
- we fund another unrelated transaction for which we lock utxos
 - the second transaction ends up using the same utxos as the first one
 - but the first transaction confirms, invalidating the second one

This would break the assumptions of the second transaction: its inputs
are locked,  so it doesn't expect to potentially be double-spent.

It's particularly dangerous if the node supports zero-conf, as this could
happen to a zero-conf transaction and completely break the channel.
2023-01-12 13:15:30 +01:00
Pierre-Marie Padiou
351666dbc9
Factor funding tx acceptance (#2557)
* homogenize WatchFundingConfirmedTriggered handlers

The handling is mostly the same in connected/disconnected states. This
does some refactoring to make them as similar as possible.

NB: we don't make a difference between previous/latest commitment being
confirmed.

* properly factor the pruning of commitments

This is a first glimpse of what will happen when we prune commitments
that have been overriden by a splice.

* prevent duplicate logs when funding tx confirms

At restart, we always put a `WatchFundingConfirmed` on all funding txs,
because this is how we detect force close in state disconnected (we only
put a `WatchSpent` on the funding tx output _after_ we detect that the
funding tx itself is confirmed).

With current code, this would result in a log indicating that the
funding tx has been confirmed at restart, for each channel in
`WAIT_FOR_DUAL_FUNDING_CONFIRMED` state. It can be quite spammy.

Instead, we now only log two cases:
- when we are disconnected, and there were alternative funding txs that
we discard;
- when we are connected (this can only happen once because we will
then transition to the next state).

* factor code for accepting the funding tx

There are 4 code paths:
- single/dual funding
- zero/non-zero conf

Besides the factorization, note that in the dual funding + non-zero conf case, we reverse the calling order between `pruneCommitments` and `acceptDualFundingTx`. This prepares a future change where we store the funding tx inside `Commitments`: it makes more sense then to first update the status of the funding tx in the corresponding commitment, and then prune the remaining commitments.
2023-01-10 17:59:37 +01:00
Bastien Teinturier
06587f9279
Wait for tx to be published for zero-conf (#2558)
When using zero-conf, we wait for the transaction to be published before
using a channel. This guarantees that the bitcoind wallet has successfully
recorded the transaction and won't double-spend it.

Otherwise if the transaction fails to publish and the utxos are unlocked,
or if bitcoind is restarted, we may accidentally double-spend it which
would break the channel and be very painful to recover.
2023-01-09 18:07:58 +01:00
Pierre-Marie Padiou
93ed6e8fc6
Factor funding spent handlers (#2556)
Factor and group all `WatchFundingSpentTriggered` handlers in `whenUnhandled`

Special cases (`NEGOTIATING`, `WAIT_FOR_FUTURE_`) are kept outside for readability.
2023-01-09 17:41:21 +01:00
Bastien Teinturier
c9c563892f
Add tlv stream to onion failures (#2455)
Extend every onion failure with an optional tlv stream.
Added to the specification by: https://github.com/lightning/bolts/pull/1021
2023-01-06 13:21:23 +01:00
rorp
92c27fe4a5
Increase blockchain watchdogs connection timeout (#2555)
From 30 seconds to 1 minute.
2023-01-05 08:51:50 +01:00
Bastien Teinturier
5967f72e64
Update to bitcoind 23.1 (#2551)
This bitcoind release contains a few bug fixes and improvements.
2023-01-04 14:27:46 +01:00
Thomas HUET
f95f087e0b
Updated offers spec (#2386)
- copy offer into invoice request and invoice request into invoice
- change signature calculation
2023-01-03 11:59:59 +01:00