1
0
mirror of https://github.com/ACINQ/eclair.git synced 2024-11-20 02:27:32 +01:00
Commit Graph

650 Commits

Author SHA1 Message Date
araspitzu
7866be11c3
Use correct type for parameters in ExtendedBitcoinClient (#1248)
* Use correct type for parameters in ExtendedBitcoinClient
2020-04-07 09:55:41 +02:00
Fabrice Drouin
d5951aa819
Release 0.3.4 (#1368)
* Release 0.3.4

* Set version to 0.3.5-SNAPSHOT
2020-04-06 13:41:17 +02:00
Pierre-Marie Padiou
4be5c34ad2
fixup! Split the Peer in two (#1347) (#1365) 2020-04-02 16:07:30 +02:00
Pierre-Marie Padiou
0e260985e2
fixup! Harden requirements on htlc-minimum-msat (#1339) (#1363)
Update fuzzy tests to not use zero-value amounts.
2020-04-02 15:40:00 +02:00
Pierre-Marie Padiou
7b58d3e831
fixup! Harden requirements on htlc-minimum-msat (#1339) (#1362)
Just less repetition and a better comment.
2020-04-02 12:52:30 +02:00
Bastien Teinturier
f9789b711a
PostRestartHtlcCleaner handle channel closing (#1338)
* Add missing cases to PostRestart

When a channel is closed we want to remove its HTLCs from our
list of pending broken HTLCs (they are being resolved on-chain).

We should also ignore outgoing HTLCs that have already been
settled upstream (which can happen when downstream is closing).

* Watch for downstream HTLC resolved on-chain

When a downstream channel is closing, we can safely fail upstream the
HTLCs that were either timed out on-chain or not included in the
broadcast commit transaction.

Channels will not always raise events about those after a reboot, so we
need to inspect the channel state and detect such HTLCs.

* Add helper function to HTLC scripts

To extract the payment_hash or preimage from an HTLC script seen on-chain.

* Cleanup on-chain HTLC timeout handling for MPP

With MPP, it's possible that a channel contains multiple HTLCs for the
same payment hash, and potentially even for the same expiry and amount.

We add more fine-grained handling of HTLC timeouts that share the same
payment hash. This allows a cleaner handling after a restart, and makes
sure we correctly detect failure that should be propagated upstream.
Otherwise we wouldn't be losing any money, but some channels may be closed
that we can avoid.

* Handle out-of-order htlc-timeout txs

It may happen that a commit tx and some htlc-timeout txs end up in the
same block. In that case, there is no guarantee on the order we'll receive
the confirmation events.

If any tx in a local/remoteCommitPublished is confirmed, that implicitly
means that the commit tx is confirmed (because it spends from it).
So we can consider the closing type known and forward the failure upstream.
2020-04-01 17:51:42 +02:00
Pierre-Marie Padiou
4875d4c879
fixup! Use CLTV as tie-breaker for offered htlc output sorting (#790) (#1360)
* removed the `Direction` class

* improved the non-reg test for htlcs

- check actual content instead of only success and roundtrip
- use randomized data for all fields instead of all-zero
- check the remaining data, not only the decoded value (codecs are
chained so a regression here will cause the next codec to fail)

Co-Authored-By: Bastien Teinturier <31281497+t-bast@users.noreply.github.com>
2020-03-31 18:31:47 +02:00
Bastien Teinturier
e8dac7324f
Add wallet balance metric (#1355)
And small tweaks/refactorings to RPC metrics.
2020-03-30 13:41:55 +02:00
araspitzu
9711da21c6
Use CLTV as tie-breaker for offered htlc output sorting (#790)
* Sort commit transaction outputs using BIP69 + CLTV as tie-breaker for offered HTLCs

* Type DirectedHtlc:
We now use a small hierarchy of classes to represent HTLC directions.
There is also a type alias for a collection of commitment output links.
2020-03-30 12:15:15 +02:00
Pierre-Marie Padiou
90b7fed021
fixup! Split the Peer in two (#1347) (#1357) 2020-03-30 11:05:36 +02:00
Pierre-Marie Padiou
0064aaedc3
fixup! Support for Tor onion services (#736) (#1356) 2020-03-26 10:51:00 +01:00
Pierre-Marie Padiou
e544207dd9
Minor: removed unused code (#1353)
And fixed formatting in Channel.scala.

Those are leftover from #1347.
2020-03-24 12:24:06 +01:00
Pierre-Marie Padiou
66f06413f1
Split the Peer in two (#1347)
* front now handles ping/sync

Peer has been split in two and now handles only channel related stuff.

A new `PeerConnection` class is in charge of managing the BOLT 1 part
(init handshake, pings) and has the same lifetime as the underlying
connection.

Also, made `TransportHandler` be a child of `PeerConnection` by making
the `remoteNodeId` an attribute of the state of `PeerConnection` instead
of a constructor argument (since we cannot be sure of the remote nodeid
before the auth handshake is done). Now we don't need to worry about
cleaning up the underlying `TransportHandler` if the `PeerConnection`
dies.

* remove `Authenticator`

Instead of first authenticating a connection, then passing it to the
`PeerConnection` actor, we pass the connection directly to the
`PeerConnection` and let it handle the crypto handshake, before the LN
init. This removes a central point of management and makes things easier
to reason about. As a side effect, the `TransportHandler` actor is now a
child of `PeerConnection` which gives us a guarantee that it dies when
its parent dies.

* separated connection logic from `Peer`

The `ReconnectionTask` actor handles outgoing connections to a peer. The
goal is to free
the `Peer` actor from the reconnection logic and have it just react to
already established
connections, independently of whether those connections are incoming or
outgoing.

The base assumption is that the `Peer` will send its state transitions
to the `ReconnectionTask` actor.

This is more complicated than it seems and there are various corner
cases to consider:
- multiple available addresses
- concurrent outgoing connections and conflict between
automated/user-requested attempts
- concurrent incoming/outgoing connections and risk of reconnection
loops
- etc.

Co-Authored-By: Bastien Teinturier <31281497+t-bast@users.noreply.github.com>
2020-03-23 21:35:43 +01:00
Bastien Teinturier
eae113f098
Improve AddHtlcFailed (#1349)
* Refactor timed out HTLC helpers: directly take a DATA_CLOSING
and extract the relevant parts.

* ClosingStateSpec: test dust HTLCs

* Improve ClosingStateSpec

* Clean up usage of AddHtlcFailed

We were abusing AddHtlcFailed in some cases where an outgoing HTLC
was correctly added, but was later settled on-chain (fulfilled, timed
 out or overridden by a different commit transaction).

These cases are now specifically handled with new Relayer.ForwardMessage
dedicated to on-chain settling.

* Refactor Relayer's ForwardMessages

ForwardFail and ForwardFulfill are now traits.
Handle both on-chain and remote fail/fulfills.
2020-03-20 12:11:33 +01:00
Bastien Teinturier
68874c2d6d
Centralize metrics per package (#1350)
Centralize metrics to avoid bloating the business logic.
Also fixed some build warnings and flatten a Future[Future[Future[Unit]]].
2020-03-19 11:35:53 +01:00
Bastien Teinturier
2df07277bb
Harden requirements on htlc-minimum-msat (#1339)
We were allowing users to set htlc-minimum-msat to 0, which directly
contradicts the fact that we must never send an HTLC for 0 msat.
We now explicitly disallow that behavior: the minimum is 1 msat.

In case the remote side of a channel had set its htlc-minimum-msat to 0,
we would forward HTLC with a value of 0 msat if a sender crafted such a
payment. The spec disallows that, so we now explicitly check for that
lower bound.
2020-03-16 16:51:29 +01:00
Pierre-Marie Padiou
ab7b373d58
Minor: Reduced some log levels (#1348)
Also removed string interpolation for some of the more expensive debug
lines. It's a trade-off performance vs readability and is probably not
worth changing for info level logs, which will be enabled anyway.

Co-Authored-By: Bastien Teinturier <31281497+t-bast@users.noreply.github.com>
2020-03-16 14:39:42 +01:00
Bastien Teinturier
26a54b5953
Funder reserve for future fee increase (#1319)
See https://github.com/lightningnetwork/lightning-rfc/issues/728

Add an additional reserve on the funder to prevent emptying and then
being stuck with an unusable channel.

As fundee we don't verify funders comply with that change.
We may enforce it in the future when we're confident the network as a
whole enforces that.
2020-03-11 15:12:48 +01:00
Pierre-Marie Padiou
b5bd2f074a
Re-send ChannelUpdate on reconnection (fixes 8afc00d) (#1342)
Previous implementation in #1317 wasn't working because in a bug in the
transition. Added a test and fixed it.

Co-authored-by: Bastien Teinturier <31281497+t-bast@users.noreply.github.com>
2020-03-11 15:02:03 +01:00
araspitzu
65371cd03b
Add more information to GetInfoResponse (#1344)
Add version, color and features
2020-03-10 14:17:09 +01:00
araspitzu
8b64e238f2
Allow users to have multiple wallets in bitcoind (#1334)
* Change the bitcoind RPC URL to use the default wallet named ""
2020-03-09 10:32:52 +01:00
Bastien Teinturier
7867bfd9db
Payment metrics (#1312)
Refactor and improve payment metrics:

* Unify in a Monitoring object.
* Add helper functions and objects.
* Add more error metrics.
* Add more latency metrics.
* Add metrics to post-restart HTLC cleanup
* Add metrics to router path-finding
2020-03-05 13:42:40 +01:00
Pierre-Marie Padiou
3b5bba64a3
Send ping if no message received from peer for 30s (#1340)
As long as we receive messages from our peer, we consider it is
online and don't send ping requests. If we don't hear from the
peer, we send pings and expect timely answers, otherwise we'll
close the connection.

This is implemented by scheduling a ping request every 30 seconds,
and pushing it back every time we receive a message from the peer.
2020-03-05 13:07:56 +01:00
araspitzu
84edf645d0
Wumbo support (#1323)
* Support wumbo channels:

- use bits 18, 19
- compute the min depth for the funding transaction according to the channel size
- update routing heuristics for a wumbo world:
  - the lower bound is the 25th percentile of current channel capacity on the network
  - the higher bound is the most common capacity for wumbo channels
- add 'max-funding-satoshis' configuration key to allow to set the maximum channel size that will be accepted
2020-02-28 16:19:36 +01:00
Bastien Teinturier
35051d0535
Make UpfrontShutdownScript a TLV record (#1333)
Make DLP data mandatory in ChannelReestablish.
We make them mandatory to allow extending the message with TLVs.

Make upfront_shutdown_script a TLV record that we always include in
open_channel / accept_channel.

See https://github.com/lightningnetwork/lightning-rfc/pull/714.
2020-02-28 10:32:15 +01:00
Bastien Teinturier
e2b16302ea
Refactor MultiPartPaymentFSM (#1324)
Add an abstraction of a PaymentPart.
Remove unnecessary intermediary case classes.
This allows extending how payment parts can be received.
It's not limited to HTLCs (could be swaps, pay-to-opens, etc).
2020-02-27 18:33:08 +01:00
Bastien Teinturier
bb930cd8b0
Channel sends typed responses (#1321)
Instead of sending strings, channel now sends typed responses.
This is more future-proof when we want to add data to those responses.
2020-02-25 10:18:51 +01:00
Pierre-Marie Padiou
4012db5828
Make Commitments method return Try[] (#1311)
Currently, those methods throw exceptions, and we rely on `Channel` to
call them within a `Try(...)`. It puts more burden on `Channel` and
isn't very functional.

Some methods were returning an `Either[]`, which seem to play the role
of a `Try` but isn't used. It seems the idea was to not fail the channel
upon receiving a `fulfill`/`fail` for an unknown htlc, but it is not
fully wired, and isn't compliant (BOLT 2):

> A receiving node:
> if the id does not correspond to an HTLC in its current commitment
transaction:
>    MUST fail the channel.

For signature-related methods, I went with the minimal change of
encapsulating portions of the code inside a `Try {...}` to minimize risk
of regression. We could also make `CommitmentSpec` methods return
`Try[]` but I suspect that would be more complicated with little
benefit.

Note that if some part isn't covered by the `Try` and ends up throwing
an exception, that will be covered by the `handleException` handler of
`Channel`.

Fixes #1305.
2020-02-24 18:17:38 +01:00
Bastien Teinturier
1e12f6d105
Allow receiving non-standard payments (#1326) 2020-02-18 17:02:20 +01:00
Bastien Teinturier
4579462dfc
SendToRoute with routing hints (#1325)
SendToRoute previously didn't accept invoice routing hints.
This was a limitation when paying a wallet invoice.
Invoice hints are now correctly taken into account.
2020-02-18 10:52:43 +01:00
Bastien Teinturier
7490bf3222
Fix random trampoline test failure (#1318)
Writing the PaymentRelayed event to the DB is not atomic.
Each part is written independently of the others (one row per part).
This is fine as nothing relies on this event being written atomically.
However tests were expecting that and we would observe rare
test failures on travis.
2020-02-14 18:24:54 +01:00
Anton Kumaigorodski
8afc00d02f
Re-send ChannelUpdate to private channels (#1317)
When coming back online, re-send private channels' `channel_update`.
This makes sure it gets rebroadcast regularly in case it was missed.
Since it's a private channel, it won't spam the network.
2020-02-12 10:18:00 +01:00
Fabrice Drouin
b73030018c
Electrum: add support for socks5 proxies (#1315)
We use the socks5 proxy that is defined in the configuration and is typically used to connect to LN nodes running as TOR hidden services.
This should allow users to connect to Electrum servers that are running behind TOR.
2020-02-11 16:57:28 +01:00
Bastien Teinturier
bd05eb140e
Node relayer faster fulfill (#1306)
* Refactor payment errors

When sending payments, it makes it easier for a wallet to display
the correct localized error message to users.

* Faster Trampoline payments fulfill

We were previously waiting for the whole downstream payment
to be settled (all individual HTLCs).

We can do better and fulfill upstream as soon as we get the preimage
(which only needs one downstream fulfill).
2020-02-10 13:52:57 +01:00
Pierre-Marie Padiou
8ff7f4b03e
Payment request: ignore fields with invalid length (#1308)
* Ignore fields with invalid length

As per the spec:
> A reader:
>   * MUST skip over unknown fields, OR an f field with unknown version, OR p, h, s or n fields that do NOT have data_lengths of 52, 52, 52 or 53, respectively.

* Add more Bolt 11 tests

See https://github.com/lightningnetwork/lightning-rfc/pull/699
and https://github.com/lightningnetwork/lightning-rfc/pull/736

Co-authored-by: Bastien Teinturier <31281497+t-bast@users.noreply.github.com>
2020-02-10 13:37:23 +01:00
n1bor
13f5b0339a Fix networkstats API call (#1309)
Use the correct type in `networkstats` API.
2020-02-10 10:32:29 +01:00
Pierre-Marie Padiou
41f466c30e
Better logging for transport handler (#1303)
We currently rely on `require`, which is convenient, but doesn't allow
fine-grained exception control.

Also, in case of errors, logging is done at the supervisor level, where
we lose the remote `node_id`.

Instead, we type some crypto-related errors and log them in the
`TransportHandler`, which already has the correct MDC.
2020-02-07 14:56:38 +01:00
Bastien Teinturier
8bf94afae8
Fix AuditDb flaky test (#1304)
The DB ordering is not deterministic.
For multi-part payments, the first timestamp is taken.
This can vary depending on which record is listed first.
Using the same timestamp avoids a failed assertion.
2020-02-07 14:33:18 +01:00
Pierre-Marie Padiou
b36c5ad583
Notify change in balance when updating network fee (#1301)
Instead of emitting this event when we send a signature, we emit it when
our `availableBalanceForSend` actually changes. This happens:
- when we send a new `update_*`;
- when we receive a `commit_sig`, which may acknowledge one or several
`update_*` sent by our peer.

We choose to only emit this event in `NORMAL` state, because its goal is
to give information about what payments we can make, which can only
happen in that state.

NB: other events `ChannelSignatureSent` and `ChannelSignatureReceived` give
a different type of information, and are sent in all states where
signatures are exchanges, not only in `NORMAL`.

The field `localBalance` has been removed because it was ambiguous, and so is
the balance tracking in the database, which wasn't very useful.

Co-Authored-By: Bastien Teinturier <31281497+t-bast@users.noreply.github.com>
2020-02-03 17:58:30 +01:00
Fabrice Drouin
1734861930
Electrum: allow watcher to watch for mempool transactions (#1298)
* Electrum: allow watcher to watch for mempool transactions

Watcher now handles WatchConfirmed watches where min depth 
is set to 0: the watch event will be sent when the tx enters the 
mempool of the bitcoin node our Electrum server is connected to.

For 0-conf channel, use scids with a height of 0 and a tx index 
generated from the first 16 bytes of the funding txid. This gives us 
unique ids that can still be identified as 0-conf channel.
2020-02-03 14:43:58 +01:00
Fabrice Drouin
66e04265b3
Release 0.3.3 (#1300)
* Release 0.3.3

* Set version to 0.3.4-SNAPSHOT
2020-02-03 11:07:26 +01:00
Bastien Teinturier
212bc2ce12
Fix force-close next commit then fulfill (#1299)
Handle correctly the case where the remote peer force-closed,
and afterwards we received a preimage from downstream for
an HTLC in this channel.
2020-01-31 16:46:00 +01:00
Bastien Teinturier
48ad9b30e6
Trampoline/MPP API changes (#1297)
Let a sender manually split a payment and specify a trampoline route.

Fix two flaky tests where the order of payment parts could be
different, resulting in a failed equality test.

If we're relaying multiple HTLCs for the same payment_hash,
we need to list all of those.
The previous code only handled that when Trampoline was used.
2020-01-31 11:52:15 +01:00
Bastien Teinturier
d6d60f063f
Fix ChannelUpdate rebroadcast (#1294)
Comparing with the router ActorRef simply didn't work.
The reason is probably because Peers receive the router's supervisor ref
which doesn't match what `self` is inside `Router`.

Checking that the origin was the router felt brittle anyway.
We're now correctly typing the gossip origin.
2020-01-30 15:17:01 +01:00
Bastien Teinturier
49f72f09ad
UpfrontShutdownScript field (#1290)
We don't implement the upfront_shutdown_script feature.
However we update our encoding to always specify it.
This allows extending OpenChannel/AcceptChannel with tlv streams.

There is one caveat: Phoenix shipped with a version that's incompatible.
So we use a workaround to identify unpatched Phoenix versions
and send them the old encoding.
2020-01-29 15:44:10 +01:00
Bastien Teinturier
8d80d13d5f
Clarify ChannelsDb htlc info method (#1291)
The old name (addOrUpdateHtlcInfo) was misleading.
This method only adds, and can even handle adding duplicate lines.

Closes #1233
2020-01-29 14:30:38 +01:00
Bastien Teinturier
453a7c66b1
Trampoline/MPP DB changes (#1287)
With MPP and Trampoline (and particularly the combination of the two),
we need to keep track of multiple amounts, recipients and fees.
There's a trampoline fee and a fee to reach the first trampoline node.
The trampoline nodes must appear in the route, but not as payment recipients.

Adding new fields to payment events and DB structs lets us distinguish those.

We also relax the spec requirement about feature graph dependencies.
The requirement to include `var_onion_optin` in invoice feature bits
was added after the first Phoenix release.
Phoenix users will thus have non spec-compliant invoices in their
payment history.
We accept invoices that don't set this field; this is a harmless
spec violation (as long as we set it in new invoices).
2020-01-29 14:21:41 +01:00
Candle
16456bbce0
Turn off SSL when custom Electrum server address is a hidden service (#1278)
This will let users connect to their own custom Electrum servers that are running behind TOR (once we add proper socks5 proxy support).
2020-01-29 11:16:09 +01:00
Bastien Teinturier
0a66d3f45f
Fix availableForSend/Receive (#1293)
There was a rounding issue with the availableForSend/Receive calculation.
Because CommitTx fee and Htlc fee were computed separately,
but each was individually rounded down to Satoshis, we could
end up with an off-by-one error.

This resulted in an incapacity to send/receive the maximum amount available.
We now allow computing fees in msat, which removes rounding issues.
2020-01-28 14:20:05 +01:00
Fabrice Drouin
d5cdd6ac9b
Channel queries: Encode empty arrays as UNCOMPRESSED (#1292)
c-lightning fails to decode empty arrays of scids or timestamps with an encoding type set to COMPRESSED_ZLIB.
The spec is not specific enough on whether this is valid or not, so we'll set the encoding type of empty arrays to UNCOMPRESSED.
2020-01-28 13:25:49 +01:00