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

194 Commits

Author SHA1 Message Date
Fabrice Drouin
717eaa799f
Electrum: fix signature bug (#524)
Regression caused signature to use wrong utxo amount which means it would not be valid, and the
funding tx could not be published.
2018-03-29 20:20:39 +02:00
pm47
b2178ade30
back to SNAPSHOT 2018-03-28 21:27:55 +02:00
pm47
c39ce692f8
setting version to 0.2-beta1 2018-03-28 20:46:40 +02:00
Pierre-Marie Padiou
242f69fd6f
Add support for mainnet (#513)
* add support for mainnet final pubkeyscript

* electrum: add addresses of electrumx servers on mainnet

* electrum: use chain hash to compute addresses and HD key paths

* store db files in a subdirectory of datadir

* add a 'catchall' around deserialization

* use chain-specific key derivation paths for channel keys

* fixed intermittently failing test (we were comparing timestamps...)

* parameters:
- set default `router-broadcast-interval` to 60s
- set default `mindepth-blocks` to 3 blocks
- removed deprecated setting `router-validate-interval`
- reduce fees: block target 1->2
- reduce `MIN_CLTV_EXPIRY` from 9 to 7
Default value in BOLT11 was indeed 9 blocks, but the absolute minimum
value computed in BOLT2 is 7 blocks.
- remove unused `default-feerate-per-kb`
- set default `max-htlc-value-in-flight-msat`=10mBTC
- set default `max-to-local-delay-blocks` to 2000 blocks

* Update README with instructions for mainnet

* Upgrade to bitcoin-lib 0.9.15 (#516)

* use fees from provider, not default ones
2018-03-28 20:21:19 +02:00
Pierre-Marie Padiou
be4cf6b694
Extend penalty to stealing HTLC outputs (#517)
Previously we were only stealing the remote's main output when they publish a revoked commit, and were relying on a sufficiently high `channel_reserve` do deincentivize cheating.

In order to also steal the htlc outputs, we need to handle both cases:
- they only publish their revoked commit tx => we claim the htlc outputs directly from the commit tx
- they publish their revoked commit tx, and their 2nd-stage HTLCSuccessTx and HtlcTimeout txes => we claim the output of these htlcs tx

To do that, we need to be able to reconstruct htlc scripts (`htlcOffered` and `htlcReceived`), therefore we need to store `paymentHash` and `cltvExpiry` for each htlc we sign. Note that this won't be needed in the future when we have MAST.

* store `paymentHash` and `cltvExpiry` for each signed htlc

* spend htlc outputs with penalty txs

* added full integration tests on revoked scenario
2018-03-28 18:18:42 +02:00
Dominique
a767aa17f3
Added json serializers to handle payment failures (#515)
Added a serializer for Throwable (local failures), and a serializer for FailureMessage (remote failures)
2018-03-27 14:06:52 +02:00
Fabrice Drouin
2a02461bcc
Upgrade to Bitcoin Core 0.16 (#514)
* switch to bitcoin core 0.16.0

* check that we are using bitcoin core 0.16

and check that there are no p2pkh UTXOs

* update readme [ci skip]
2018-03-26 20:56:51 +02:00
Pierre-Marie Padiou
e44e6b4431
Updated akka/http/json dependencies (#512) 2018-03-26 17:36:33 +02:00
Pierre-Marie Padiou
64c15b4c4d
Fixed race condition in ElectrumClient (#509)
This regression caused in 438d8e3 is what caused flaky tests during the past few days.

Calling `sender()` inside a `Props()` leads to undefined behavior.
2018-03-24 11:37:15 +01:00
n1bor
1a8cb2a694 Addition of API calls checkinvoice and findroute (#475)
* Add api call to check invoice/paymentRequest and return details in json

* Adding in API call to allow user to check route before making send call

* Added a serializer for route response

* Update README to include new checkinvoice and findroute API calls
2018-03-24 10:51:15 +01:00
Fabrice Drouin
ae936d56ea Use lnbcrt prefix for regtest (#508)
see https://github.com/lightningnetwork/lightning-rfc/pull/397
fixes #474
2018-03-23 22:51:02 +01:00
Fabrice Drouin
fff669662c
Use a pool of Electrum servers (#500)
add electrum router, which manages a set of client

primary client is the one on the longest chain, when a secondary client
has a chain that is longer than master + 2 it becomes the new master.
this will allow us to move away from "dead" electrum servers that are not
up to date with the blockchain.

electrum client: add 'get header' method

electrum: maintain a chain of headers for each client

and switch to the one with the longest chain

electrum: handle case when received header connects to our first header

it can happen when we connect to a server and ask for the last N headers

electrum: automatic reconnection

when we lose connection to our master client, we consider that we are
disconnected.
when we lose connection to a secondary client, we try to find an address
that is not used and connect to it. If there is no such address we wait
a bit and try to reconnect to the failing client

electrum: check that incoming header proof of work is valid

electrum router: migrate to Akka's FSM

electrum: fix match error for `ready` message

add missing copyright headers

move Blockchain to electrum package

electrum: simplify router

electrum client: fix handling of dead subscribers

electrum: move blockchain validation into electrum client

client will now send `ready` notifications and subscriptions messages only when it has a valid and
long enough blockchain

pass execution context as argument

reworked `ElectrumRouter` following
3dc1c2b61c82debeaed8d0d92238c0b5ee5c49c8

renamed `ElectrumRouter` -> `ElectrumMultiClient`

reformat

`var` -> `val`

 electrum: rename multiclient -> pool + cleanup
2018-03-23 20:41:28 +01:00
Pierre-Marie Padiou
1a37ab5613 Cleanup some TODOs (#507)
* remove useless hex methods for bitcoin tx

* re-enabled test

* `BinaryData("") -> `BinaryData.empty`

* removed invalid comment
2018-03-23 20:25:09 +01:00
Pierre-Marie Padiou
f3e32b887c
Track version of each logical database (#495) 2018-03-23 20:07:08 +01:00
Pierre-Marie Padiou
9f8cd3b580
Add json serializers to the API (#504)
* added a serializer for `UInt64` class

* added a serializer for `OutPoint` class

* use `txid` instead of `txhash` when serializing `OutPoint`

* added a simple serializer for class `InputInfo`
2018-03-23 19:33:18 +01:00
Pierre-Marie Padiou
4ef11e7e38
Added a 1s delay when API password check fails (#498) 2018-03-23 19:26:24 +01:00
Fabrice Drouin
c1777e2885 Electrum: add a send all balance method (#506) 2018-03-23 16:10:20 +01:00
Pierre-Marie Padiou
c882034f77
Set a configurable maxPaymentFee as safety (#493)
* set a configurable `maxPaymentFee` as safety

Sending a payment will not be attempted if the cheapest route found is
more expensive than this value. Default value is 3%.

This is meant as a protection mechanism, to protect against an
intermediate well-connected node to set outrageous fees.

* reduced default `fee-base-msat` to 1 sat

* (gui) using max fee from node params when sending payment from ui
2018-03-22 19:17:16 +01:00
Pierre-Marie Padiou
d38f227b42
Added copyright notice to all files (#497)
* added copyright notice to all files

* updated date in LICENSE
2018-03-21 16:29:42 +01:00
Pierre-Marie Padiou
438d8e3d4b throttle TCP writes to electrum servers (#485) 2018-03-21 10:17:05 +01:00
Pierre-Marie Padiou
e31ba2b63a
Simplified blacklisting of nodes in case of payment failures (#489)
* simplified blacklisting of nodes in case of payment failures and fixed `transformForUser`

* Add a test for PaymentLifeCycle.transformForUser()
2018-03-19 19:49:36 +01:00
Pierre-Marie Padiou
ea9c005fe8
Close channel on BITCOIN_FUNDING_PUBLISH_FAILED (#487)
Implementation should guarantee that in case of a
`BITCOIN_FUNDING_PUBLISH_FAILED` event, the funding tx will *never* be
published (see `commit` method in trait `EclairWallet`).

With that in mind, there is no need for a `ERR_FUNDING_PUBLISH_FAILED`
state, instead we can just permanently close the channel. Note that the
user will receive an error "couldn't publish funding tx".
2018-03-19 12:59:48 +01:00
Pierre-Marie Padiou
4a91c1cdf8
Proper clean up of private channels (#488)
Private channels need specific handling because we can't rely on
`WatchEventSpentBasic` event for tracking whether they are still up.
2018-03-19 12:55:40 +01:00
pm47
1754bf0933
back to SNAPSHOT 2018-03-16 17:05:58 +01:00
pm47
dbb4f5b467
set version to 0.2-alpha11 2018-03-15 19:41:53 +01:00
Dominique
3d48ec871e
Improved handling of timeouts in API and GUI (#484)
Both the GUI and the API should handle AskTimeoutException failures as
specific cases: GUI should ignore them, API should print a pretty
response. Increased ask timeout to 60s.

Akka http server responses with the same format as other errors.
Fixes #414 where eclair-cli would fail to parse the server
timeout response.
2018-03-15 19:33:12 +01:00
Pierre-Marie Padiou
dceb6b9b06 Better handling of force-closing of channels (#483)
As soon as we receive a valid closing signature, we will publish the
resulting closing tx instead of our commitment tx if we need to
immediately close the channel (before end of negotiation, e.g. in case
of errors, or in case the counterparty goes OFFLINE).

When the closing signature didn't correspond to one we sent ourselves, we
weren't properly recognizing the publishing tx and went into
`ERR_INFORMATION_LEAK` state.

CMD_CLOSE is now split it to commands: 
* `CMD_CLOSE`: this command will succeed only if the current
channel state is in NORMAL, or if the channel hasn't yet been created.
* `CMD_FORCECLOSE`: the channel will publish its current local
commitment (or its best signed closing tx if it has one).

Using `CMD_FORCECLOSE` is more expensive and it incurs a delay before
funds are spendable, but this can be useful in some situations, for
example when the counterparty isn't responding anymore.

Added a new `forceclose` method to the API and a force close button in 
the GUI.
2018-03-15 18:53:14 +01:00
Pierre-Marie Padiou
49cbad1590 Use default seed for electrum if none is provided (#482) 2018-03-15 11:29:08 +01:00
Fabrice Drouin
454535dd68 Restore node id key path (#481)
(this fixes a regression caused by 24dadff625)

* restore the old node key path

use the same path as before the change in key management so node id will
remain the same after an upgrade

* add a non-regression test

we check that if the seed does not change, then the node id won't change
either, which could be a problem during a node upgrade.
2018-03-14 18:15:07 +01:00
Pierre-Marie Padiou
1ca7321d53
Created a type for short channel id, and other minor improvements (#480)
* type-ified `ShortChannelId`

* removed unused `listUnspent` method and test

* updated sqlite version to 3.21.0.1

* ignore `ReadAck` in `PaymentLifecycle`
2018-03-13 12:09:28 +01:00
Pierre-Marie Padiou
b061ea5efc Fixed bug in ignored channel computation (#472)
Also, renamed `getBlacklistedChannels` to `getIgnoredUpdates` and added
test.
2018-03-02 18:49:51 +01:00
Pierre-Marie Padiou
f0a877c78b Use bitgo API v2 to get network fees (#473)
Supports mainnet/testnet fees according to the configured chain.
2018-03-02 18:49:27 +01:00
Pierre-Marie Padiou
bb1d0e96cf added check on to_self_delay parameter (#470) 2018-03-02 11:25:03 +01:00
Fabrice Drouin
24dadff625 Improve key management (#372)
* generate all channel keys and secrets from the node key and channel number

* use a key manager
the key manager does not export private keys or secrets.
It exports public keys, and points, and provide methods to sign
transaction.
There is just one exception: it does export revocation secrets, since
we need to send them back when we receive a commitment signature.

* key management: cache private keys and public keys

* add key manager to node parameters

* create an interface for key manager
and an implementation which keeps private keys locally

* generate a new BIP32 key path for each new channel

When we create a new channel we generate a new random BIP32 key path
with 128 bits of entropy
2018-03-01 20:37:39 +01:00
Pierre-Marie Padiou
42fb9a90c1
Reworked routing algorithm (#461)
* use a `DirectedWeightedPseudograph`

Because we want a directed graph with multiple weighted edges between two
vertices, and loops allowed.

See discussion in [1] for more details.

* take node fee into account when finding route

Fees vary depending on the amount we want to send, so as a simplification
we use a default `DEFAULT_AMOUNT_MSAT`=`10000000` to compute edges weight.

This fixes #310.

* reuse the same graph for all payments

In `findRoute`, if we have specific updates to add/remove, we don't mutate
the main graph and create a copy instead.


[1]
http://jgrapht-users.107614.n3.nabble.com/Difference-between-a-directed-multigraph-and-a-directed-pseudograph-td4024788.html
2018-03-01 19:42:23 +01:00
Pierre-Marie Padiou
85592de0e5
Proper management of expiry-related errors (#469)
Make `Commitment` return `ExpiryTooSmall` and `ExpiryTooBig` when
appropriate, and don't do the check in the `Relayer`.

Be more restrictive when sending HTLCs, so that counterparty doesn't
close the channel when a block just appeared and there is temporarily a
1-block discrepancy between two peers.

Proper management of `FinalExpiryTooSoon` in the payment handler.

On top of that, added more tests and simplified some.
2018-03-01 18:48:54 +01:00
Pierre-Marie Padiou
203288c415
Rebroadcast only valid channel_update, always attach channel_announcements (#464) 2018-03-01 17:57:52 +01:00
Pierre-Marie Padiou
d510d08190 Publish a ChannelSignatureSent for each outgoing commitment sig (#467) 2018-03-01 13:53:14 +01:00
Pierre-Marie Padiou
8d387cee90 PaymentSucceeded adds fee in amountMsat, and contains paymentHash (#466) 2018-02-28 17:26:28 +01:00
Pierre-Marie Padiou
43128636ce Improvements & fixes (#459)
* moved CoinUtils to eclair-core to expose conversion methods

Parsing and converting string amount to BtcAmount objects, and
displaying BtcAmount as well formatted string is a common use case.
Methods that were developed for the gui module should be exposed from
eclair-core so that they can be reused elsewhere.

* increased timeouts in integration tests

* have bitcoin wallet and watcher use a separate client

* return more information on channel opening

* removed `storedChannels` from `Peer` constructor

1) so that they can be garbage-collected
2) that was a memory leak because closed channel would stay forever

* OpenChannel now accepts a feerate param for the funding Tx

User should be able to override the fee rate of the funding tx that he
sends when he opens a channel. This custom fee is entered as a fee rate
in satoshi per byte, and converted to a fee rate per kw.

The default value of this fee rate does not change, and still aims for
the funding tx to be included in a block within the next 6 blocks,
estimation which is made through the FeeProvider class.

* reworked payment events

and made sure we send events even when `PaymentLifecycle` disappeared, e.g.
when we restart right after having sent a payment.
2018-02-27 19:36:56 +01:00
Dominique
288dec3c00
Add detailed message to remote failures (#431)
A `FailureMessage` should include a detailed description. A `transformForUser` 
static method is also added to streamline the list of failures associated to a 
`PaymentFailure`.

In the GUI, the payment notification shows a message for each failed attempts
2018-02-27 17:28:46 +01:00
Pierre-Marie Padiou
3b5355bbf2
Prune on initial_routing_sync (#455)
* announcements are pruned before they are sent for `initial_routing_sync` (this was removed by #422)
* is now considered stale a channel that is older than 2 weeks and hasn't any `channel_update` younger than two weeks (again, before #422 we were more lax because of pre-validation pruning)
* pruning was rewritten without use of very expensive `exists` function
* we don't prune anymore on startup
* removed `ThrottleForwarder` and `WriteAckSender`, and handle both TCP read/write backpressure at the `TransportHandler` level, which is much more efficient (e.g. we don't serialize/encrypt outgoing data if OS buffer is already full, which saves RAM and CPU)
* added a simple priority management that reduces priority of routing announcements so that they don't block channel messages on `initial_routing_sync`
2018-02-26 15:22:44 +01:00
Pierre-Marie Padiou
7aca967e91
Better closing tx management (#423)
* call `doPublish` in `handleMutualClose`

That's more consistent with other closing scenarii, and we weren't
putting a `WatchConfirmed` in case of unexpected closing tx.

* store the unsigned closing tx along with sent `closing_signed`

So that we can identify txes based on txid when they are published,
instead of on their (malleable) signature.

* don't log publish error when tx is already in blockchain

* store the last signed closing tx during negotiation

And use it instead of our local commitment if channel fails before end of
negotiation.

* fixed `SYNCING`->`NEGOTIATING` transition

There were three bugs:
(1) we weren't re-sending our `shutdown`
(2) we were re-sending all previous `closing_signed` instead of restarting
  the negotiation
(3) there was even a bug in (2) since
1aee6e8c21

On top of that, had to implement changes as per
https://github.com/lightningnetwork/lightning-rfc/pull/36.

Note that this is unfinished, as there is a corner case where fundee
reuses previous `closing_signed` to compute its next closing fee, even if
it was just disconnected for possibly a long time and network fees have
changed a lot in the meantime.

* watch for closing tx published in `OFFLINE` and `SYNCING`

* added a tx json serializer

* use a separate list for each attempted negotiation

This allow us to properly handle restarting a negotiation after a
reconnect.
2018-02-26 13:23:04 +01:00
Anton Kumaigorodski
a065ae757f Added support for data loss protection option (#410)
* This is based on the `option-data-loss-protect` feature defined in BOLT 9.

* At reconnection, when the counterparty proves us that our commitment is outdated, we politely ask them to publish their commitment. This is done by adding a new state `WAIT_FOR_REMOTE_PUBLISH_FUTURE_COMMITMENT`, and introducing a new "future" remote commitment type, in addition to existing "current" and "next".

* Slightly changed the signature of `Helpers`.`claimRemoteCommitMainOutput` so that current/next/future commitments are all handled the same way.

* Made sure that we never publish our local commitment when we know it is outdated, as it would be a cheating attempt and would result in a total loss of funds.

* Support both optional/required modes for option `option_data_loss_protect`
2018-02-23 15:46:05 +01:00
Pierre-Marie Padiou
226aeb56d8
Minor fixes (#452)
* removed unused `WAITING_FOR_VALIDATION` state

* unwatch connection when peer is dequeued from `initial_routing_sync` waitlist

* Updated testnet electrum servers list

* Added error log in supervisor when throwable is caught

The default error logging does not log the stack.

* filter updates in one pass

* filter stale channels in one pass

* added `strategy` to supervisor logs

* add the downstream htlc to `Forward*` messages
2018-02-20 18:02:28 +01:00
Pierre-Marie Padiou
6b837ecbae
Better data structures (#451)
* make `listPeers` return a `Map`

* use `Seq` instead of `List` in db trait, and implement using `Queue`s
Append is a O(1) in `Queue` and O(n) in `List`.

* use a `Map` to store unacked incoming messages

* used `Vector` instead of `List` in decryption
2018-02-20 16:42:06 +01:00
Dominique
8684fb238b Removed BitcoinJ watcher (#447)
Added guava dependency which was previously bundled with bitcoinj.
2018-02-20 14:26:38 +01:00
pm47
1b247ae613 back to SNAPSHOT 2018-02-16 18:10:35 +01:00
pm47
0beca13b23 set version to 0.2-alpha10 2018-02-16 17:28:01 +01:00
Pierre-Marie Padiou
82803cab1d
Ignore 'tx already in block chain' errors when publishing a tx (#441)
And set more reasonable log levels in `ZmqWatcher`.
2018-02-16 17:22:03 +01:00