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

656 Commits

Author SHA1 Message Date
Fabrice Drouin
cd78c9ecdd
Electrum: update server list (#1022)
* Electrum: update server list

* Electrum: set client name to 3.3.6
2019-06-03 13:45:51 +02:00
Dominique
3e46475f9f Initialize global feerate with default from conf (#1019)
`Globals.feeratePerKB` is an atomic reference initialized to `null` and
is asynchronously set by the fee provider only once it's ready. This
means that it is possible to retrieve a null object from feeratePerKB,
scenario that must be handled separately to prevent any issues.

This commit now initialize `Globals.feeratePerKB` with the default
values set in the configuration file. This makes sure that the
feerate is always set to a meaningful value.
2019-06-03 09:44:06 +02:00
Pierre-Marie Padiou
c4b7ade038
Removed PaymentRequest.MAX_AMOUNT (#1018)
It was obsole since
068b0bccf9.

Note that we use a signed long, but it doesn't matter since 2^64
milli-satoshis is greater than the total number of bitcoins.
2019-05-28 14:14:17 +02:00
Pierre-Marie Padiou
b82d7211cc
Set handleCommandError to WARN (#1012)
Those are not fatal errors for channels.
2019-05-27 17:33:20 +02:00
Fabrice Drouin
648f57276a Electrum: consistently retrieve wallet transactions (#1010)
* Electrum: update mainnet and testnet servers list

* Electrum: request missing history transactions on reconnect

Upon connection/reconnection, ask for transactions that are included in our history but
which we don't have and don't have a pending request for.

* Electrum: add disconnect/reconnect tests

Simulate disconnections and check that wallet eventually gets it history and transactions.
2019-05-23 16:36:54 +02:00
Pierre-Marie Padiou
92e2d21eab
Make htlc-reaper a top-level actor (#1013)
The way we handle requests to `Switchboard` assume that all children are `Peer`s. This led the `peer` API request to timeout.
2019-05-21 17:36:29 +02:00
araspitzu
101bcd7c50
Send to route (#952)
* Add /sendtoroute API and functionality

* Do not use extractor pattern in PaymentLifecycle::SendPaymentToRoute

* /sendtoroute: support route parameter as comma separated list

* Add test for 'sendtoroute' in EclairImplSpec
2019-05-20 15:20:53 +02:00
araspitzu
cfaa5508eb
Increase Service and EclairImpl test coverage (#1004)
* /payinvoice: assert the override amount is being used in the invoice

* /updaterelayfee: assert the values passed through the API call are forwarder to EclairImpl

* 'receive' API: test for fallback address usage and parameters passing

* 'close' API: test for parameters handling

* 'networkFees': test for default parameters

* Add test dependency mockito-scala, rewrite a test using the mock framework

* Factor out query filter parsing in EclairImpl, Add test for networkFees/audit/allinvoice

* Move getDefaultTimestampFilters in companion object, group together EclairImpl-scoped classes
2019-05-20 14:22:09 +02:00
araspitzu
80340c1fbf
API: optionally use a user supplied preimage when creating invoices (#965)
* Add support for custom preimage in /createinvoice API

* Add test for using a custom preimage in payment request
2019-05-17 17:11:38 +02:00
Pierre-Marie Padiou
8718959164
Improved test coverage of io package (#996)
* improved test coverage of `NodeURI`

* improved test coverage of `Peer`
2019-05-10 19:53:50 +02:00
Fabrice Drouin
847d0999c8
Release v0.3 (#994)
* gui: include javafx native libraries for windows, mac, linux

* Release v0.3

* Set version to 0.3.1-SNAPSHOT
2019-05-10 11:02:08 +02:00
Pierre-Marie Padiou
081dec15ae
Updated license header (#992) 2019-05-09 16:40:37 +02:00
Fabrice Drouin
6cc1f87940
Use bitcoind fee estimator first (#987)
* use bitcoind fee provider first

* set default `smooth-feerate-window`=6

* Configuration: increase fee rate mismatch threshold

We wil accept fee rates that up to 8x bigger or smaller than our local fee rate
2019-05-09 15:19:25 +02:00
Pierre-Marie Padiou
e26c145e89
Accept commit_sig without changes (#988)
LND sometimes sends a new signature without any changes, which is a
(harmless) spec violation.

Note that the test was previously not failing because it wasn't specific
enough. The test now fails and has been ignored.
2019-05-09 13:57:57 +02:00
Pierre-Marie Padiou
50b4001853
Set tcp client timeout to 20s (#990)
So that it fails before the ask/api time out.
2019-05-09 11:41:05 +02:00
Fabrice Drouin
9f96b1b922 Set default chain to "mainnet" (#989)
Eclair is now configured to run on mainnet by default.
2019-05-09 11:30:26 +02:00
araspitzu
951bd0306b
Enrich test for internal eclair API implementation (fr.acinq.eclair.Eclair.scala) (#938)
* Add test to EclairImpl for `/send`, `/allupdates` and `/forceclose/`
2019-05-09 11:01:43 +02:00
Bastien Teinturier
03f4911e46 Wireshark dissector support (#981)
* Transport: add support for encryption key logging.
This is the format the wireshark lightning-dissector uses to be able to decrypt lightning messages.
2019-05-09 10:47:57 +02:00
Fabrice Drouin
ccdd42305e Replace UnknownPaymentHash and IncorrectPaymentAmount with IncorrectOrUnknownPaymentDetails (#984)
See https://github.com/lightningnetwork/lightning-rfc/pull/516 and https://github.com/lightningnetwork/lightning-rfc/pull/544
2019-05-09 10:03:04 +02:00
araspitzu
100cce1077 Update bash autocompletion for eclair-cli (#983)
* Update bash autocompletition file to suggest all the endpoints

* Update list of commands in eclair-cli help message
2019-05-09 09:45:47 +02:00
Pierre-Marie Padiou
7b874f23d2
Use proper closing type in ChannelClosed event (#977)
There was actually a change introduced by #944 where we used
`ClosingType.toString` instead of manually defining types, causing a
regression in the audit database.
2019-05-09 09:43:25 +02:00
Pierre-Marie Padiou
de5a7827bd
Fixed overflow issue with max duration (#975)
This is a regression caused by #971, because `Duration` has a max value of `Long.MaxValue` *nanoseconds*, not *seconds*.
2019-04-30 10:14:48 +02:00
Pierre-Marie Padiou
fb84dfb855
Smarter strategy for sending channel_updates (#950)
The goal is to prevent sending a lot of updates for flappy channels.

Instead of sending a disabled `channel_update` after each disconnection, 
we now wait for a payment to try to route through the channel and only 
then reply with a disabled `channel_update` and broadcast it on the
network.

The reason is that in case of a disconnection, if noone cares about that
channel then there is no reason to tell everyone about its current
(disconnected) state.

In addition to that, when switching from `SYNCING`->`NORMAL`, instead
of emitting a new `channel_update` with flag=enabled right away, we wait
a little bit and send it later. We also don't send a new `channel_update` if
it is identical to the previous one (except if the previous one is outdated).

This way, if a connection to a peer is unstable and we keep getting
disconnected/reconnected, we won't spam the network.

The extra delay allows us to remove the change made in #888, which was
a workaround in case we generated `channel_update` too quickly.

Also, increased refresh interval from 7 days to 10 days. There was no
need to be so conservative.

Note that on startup we still need to re-send `channel_update` for all 
channels in order to properly initialize the `Router` and the `Relayer`.
Otherwise they won't know about those channels, and e.g. the 
`Relayer` will return `UnknownNextPeer` errors.

But we don't need to create new `channel_update`s in most cases, so 
this should have little or no impact to gossip because our peers will
already know the updates and will filter them out.

On the other hand, if some global parameters (like relaying fees) are
changed, it will cause the creation a new `channel_update` for all
channels.
2019-04-29 16:39:59 +02:00
araspitzu
4ba4ce8096 API: Support query by channelId or shortChannelId everywhere (#969)
Add support for querying a channel information by its `shortChannelId`.
2019-04-26 17:45:59 +02:00
araspitzu
83dc8176a9 Various fix and improvements in time/timestamp handling (#971)
This PR standardizes the way we compute the current time as unix timestamp 

- Scala's Platform is used and the conversion is done via scala's concurrent.duration facilities
- Java's Instant has been replaced due to broken compatibility with android
- AuditDB events use milliseconds (fixes #970)
- PaymentDB events use milliseconds
- Query filters for AuditDB and PaymentDB use seconds
2019-04-26 17:10:30 +02:00
Pierre-Marie Padiou
65918ec0de
Rename eclair.bak to eclair.sqlite.bak (#968)
This removes any ambiguity about what the content of the file is about.
2019-04-25 16:34:05 +02:00
araspitzu
45a5b6f9a7
Fix flaky test in PaymentLifecycleSpec (#967)
* Use local random pamentHash for each test in paymentlifecyclespec, intercept the route request before the router.
2019-04-25 15:28:03 +02:00
Fabrice Drouin
650c5049d5
Better handling of closed channels (#944)
* Remove closed channels when application starts

If the app is stopped just after a channel has transition from CLOSING to CLOSED, when the  application starts again if will be restored as CLOSING. This commit checks channel data and remove closed channels instead of restoring them.

* Channels Database: tag closed channels but don't delete them

Instead we add a new `closed` column that we check when we restore channels.

* Document how we check and remove closed channels on startup
2019-04-24 17:32:53 +02:00
Fabrice Drouin
595c23c38c
Electrum: make debug logs shorter (#964) 2019-04-24 16:50:25 +02:00
Fabrice Drouin
a87a111c71
Channel: Log additional data (#943)
* Channel: Log additional data

Log local channel parameters, and our peer's open or accept message.
This should be enough to recompute keys needed to recover funds in case of unilateral close.
2019-04-24 16:47:34 +02:00
Dominique
159e6da21f
ElectrumWallet should not send ready if syncing (#963)
This commit is already embedded in version `0.2-android-beta22`.
2019-04-24 16:45:57 +02:00
araspitzu
aef27d8f9c
Print stack trace when crashing during boot sequence (#949)
* Print stack trace when crashing during boot sequence

* Use friendly message when db compatibility check fails
2019-04-24 10:23:57 +02:00
Fabrice Drouin
064ba7df91
Backup: explicitely specify move options (#960)
* Backup: explicitely specify move options

We now specify that we want to atomically overwrite the existing backup file with the new one (fixes
a potential issue on Windows).
We also publish a specific notification when the backup process has been completed.
2019-04-23 17:11:53 +02:00
Fabrice Drouin
bed47de5e3
Live channel database backup (#951)
* Backup running channel database when needed

Every time our channel database needs to be persisted, we create a backup which is always
safe to copy even when the system is busy.

* Upgrade sqlite-jdbc to 3.27.2.1

* BackupHandler: use a specific bounded mailbox

BackupHandler is now private, users have to call BackupHandler.props() which always
specifies our custom bounded maibox.

* BackupHandler: use a specific threadpool with a single thread

* Add backup notification script

Once a new backup has been created, call an optional user defined script.
2019-04-19 22:35:12 +02:00
Pierre-Marie Padiou
f563ca0897
Add channel errors in audit db (#955)
We now keep track of all local/remote channel errors in the audit db.
2019-04-19 16:28:02 +02:00
Pierre-Marie Padiou
44778a72c9
Set MAX_BUFFERED to 1,000,000 (#948)
Note that this doesn't mean that we will buffer 1M objects in memory:
those are just pointers to (mostly) network announcements that already
exist in our routing table.

Routing table has recently gone over 100K elements (nodes,
announcements, updates) and this causes the connection to be closed when
peer requests a full initial sync.
2019-04-19 14:18:57 +02:00
Pierre-Marie Padiou
84c0fab433
Added a timeout for channel open request (#928)
Until now, if the peer is unresponsive (typically doesn't respond to
`open_channel` or `funding_created`), we waited indefinitely, or until the
connection closed.

It translated to an API timeout for users, and uncertainty about the
state of the channel.

This PR:
- adds an optional `--openTimeoutSeconds` timeout to the `open` endpoint, that will
actively cancel the channel opening if it takes too long before reaching
state `WAIT_FOR_FUNDING_CONFIRMED`.
- makes the `ask` timeout configurable per request with a new `--timeoutSeconds`
- makes the akka http timeout slightly greater than the `ask` timeout

Ask timeout is set to 30s by default.
2019-04-18 18:30:51 +02:00
Fabrice Drouin
6afe28d147
Electrum: do not persist transaction locks (#953)
Locks held on utxos that are used in unpublished funding transactions should not be persisted.
If the app is stopped before the funding transaction has been published the channel is forgotten
and so should be locks on its funding tx utxos.
2019-04-17 19:10:14 +02:00
Pierre-Marie Padiou
9032da5326
Add a proper payments database (#885)
There is no unique identifier for payments in LN protocol. Critically,
we can't use `payment_hash` as a unique id because there is no way to
ensure unicity at the protocol level.

Also, the general case for a "payment" is to be associated to multiple
`update_add_htlc`s, because of automated retries. We also routinely
retry payments, which means that the same `payment_hash` will be
conceptually linked to a list of lists of `update_add_htlc`s.

In order to address this, we introduce a payment id, which uniquely
identifies a payment, as in a set of sequential `update_add_htlc`
managed by a single `PaymentLifecycle` that ends with a `PaymentSent` or
`PaymentFailed` outcome.

We can then query the api using either `payment_id` or `payment_hash`.
The former will return a single payment status, the latter will return a
set of payment statuses, each identified by their `payment_id`.

* Add a payment identifier

* Remove InvalidPaymentHash channel exception

* Remove unused 'close' from paymentsDb

* Introduce sent_payments in PaymentDB, bump db version

* Return the UUID of the ongoing payment in /send API

* Add api to query payments by ID

* Add 'fallbackAddress' in /receive API

* Expose /paymentinfo by paymentHash

* Add id column to audit.sent table, add test for db migration

* Add invoices to payment DB

* Add license header to ExtraDirective.scala

* Respond with HTTP 404 if the corresponding invoice/paymentHash was not found.

* Left-pad numeric bolt11 tagged fields to have a number of bits multiple of five (bech32 encoding).

* Add invoices API

* Remove CheckPayment message

* GUI: consume UUID reply from payment initiator

* API: reply with JSON encoded response if the queried element wasn't found

* Return a payment request object in /receive

* Remove limit of pending payment requests!

* Avoid printing "null" fields when serializing an invoice to json

* Add index on paymentDb.sent_payments.payment_hash

* Order results in descending order in listPaymentRequest
2019-04-16 17:03:21 +02:00
rorp
70d7db7f96 Set max payment attempts from configuration (#931)
With a default to `5`.
2019-04-15 15:19:39 +02:00
araspitzu
3eceb90fa0
Expose the websocket over HTTP GET to work properly with basic auth (#934)
* Expose the websocket over HTTP GET
* Add test for basic auth over websocket endpoint
2019-04-10 11:07:19 +02:00
Fabrice Drouin
a37fd38d65
API: fix fee rate conversion (#936)
Our `open` API calls expects an optional fee rate in satoshi/byte, which is the most widely
used unit, but failed to convert to satoshi/kiloweight which is the standard in LN.
We also check that the converted fee rate cannot go below 253 satoshi/kiloweight.
2019-04-09 11:32:12 +02:00
Pierre-Marie Padiou
fa5d0235cb
Make Electrum tests pass on windows (#932)
There was an obscure Docker error when trying to start an Electrum
server in tests. [1]

It appears that there is a conflict between Docker and Hyper-V on some
range of ports.

A workaround is to just change the port we were using.

[1] https://github.com/docker/for-win/issues/3171
2019-04-04 11:38:11 +02:00
araspitzu
2aa088e0e6 Fix eclair-cli to work with equal sign in arguments (#926)
* Fix eclair cli argument passing

* Modify eclair-cli to work with equals in arguments

* Eclair-cli: show usage when wrong params are received

* Remove deprecated call from eclair-cli help message [ci skip]
2019-04-03 19:19:56 +02:00
araspitzu
3a56ad9133
Send events when HTLCs settle on-chain (#884)
* send events when htlc settle on-chain

* send events when a payment is received/relayed/sent

* send events when a payment is failed

* Add test for websocket

* Use nicer custom type hints when serializing to json (websocket)

* Fix bech32 prefix for regtest

* Separate cases for bech32 testnet and regtest for BOLT11 fallback address
2019-04-03 11:41:08 +02:00
Fabrice Drouin
288aa75305
Electrum: update client name (#930)
* Electrum: use 3.3.4 as client name

* Electrum Pool: more specific message on disconnect

Specify wether we lost connection to our master server or to a backup server.
2019-04-03 10:58:26 +02:00
Andrea
e3f8d9b140
Formatting, remove unused param in comments 2019-04-03 10:29:41 +02:00
Fabrice Drouin
617ccf4d11
Minor API fixes (#929)
Move GetInfoResponse and AuditResponse out of the api package
Fix parameter handling for audit() and networkFees()
2019-04-02 16:23:49 +02:00
Pierre-Marie Padiou
933913de08
Add random delay to rebroadcast (#925)
* add random delay to rebroadcast

* ignore `BadMessage` while disconnected

* ignore `DelayedRebroadcast` while disconnected
2019-04-01 13:31:41 +02:00
Pierre-Marie Padiou
9c37448ebf
Rollback tx if disconnected in WAIT_FOR_FUNDING_SIGNED (#923) 2019-03-30 20:28:54 +01:00
Andrea
1b91609aec
Separate cases for bech32 testnet and regtest for BOLT11 fallback address 2019-03-29 19:02:43 +01:00
Andrea
77eb1de4f3
Merge remote-tracking branch 'origin/extended-api-pm' into extended-api-pm 2019-03-29 19:00:18 +01:00
Andrea
5e476fddc4
Fix bech32 prefix for regtest 2019-03-29 18:59:59 +01:00
Fabrice Drouin
c99026828c
Electrum: fixes and improvements (#924)
* Electrum: Update mainnet servers list

* Electrum: make pool address selection more readable

We connect to a random server we're not already connected to.

* Electrum Tests: increase "wait for ready" test timeout

If was a bit short and sometimes failed on travis.

* Electrum: better parsing of invalid responses

On testnet some Electrum servers are not compliant with the protocole version they advertise
and will return responses formatted with 1.0 rules.
2019-03-29 18:56:00 +01:00
pm47
dd52cdc61f
added tests 2019-03-29 18:16:44 +01:00
araspitzu
9624383f22
cleaner isSentByLocal
Co-Authored-By: pm47 <pm47@users.noreply.github.com>
2019-03-29 18:14:32 +01:00
Pierre-Marie Padiou
14da6d3c23
Update eclair-core/src/main/scala/fr/acinq/eclair/channel/Helpers.scala
Co-Authored-By: araspitzu <a.raspitzu@protonmail.com>
2019-03-29 17:26:11 +01:00
Andrea
008b2cad87
re-introduce dropTail strategy for websocket buffer, let the unhandled messages be handled by akka's default 2019-03-29 17:09:10 +01:00
Andrea
09618a8764
Log error with warn level in websocket actor, use backpressure strategy for websocket queue. 2019-03-29 16:57:59 +01:00
Andrea
52b17fe75f
Use nicer custom type hints when serializing to json (websocket) 2019-03-28 17:54:56 +01:00
Andrea
9a7e2158be
Add test for websocket 2019-03-28 16:07:51 +01:00
Andrea
c8d38871e9
remote println from test, 2019-03-28 15:21:04 +01:00
Andrea
5b423b1571
Remove 'fallbackAddress' from /receive API 2019-03-28 14:54:28 +01:00
Andrea
10bc4ab811
Reorganize specialized formats for the websocket 2019-03-28 14:51:21 +01:00
Andrea
cd703f2d4a
Merge branch 'master' into extended-api-pm 2019-03-28 11:24:12 +01:00
Andrea
c557f70af5
Finish merging master 2019-03-28 11:22:37 +01:00
Andrea
8ec8574d97
Merge branch 'master' into extended-api-pm
# Conflicts:
#	eclair-core/src/main/scala/fr/acinq/eclair/api/Service.scala
#	eclair-core/src/main/scala/fr/acinq/eclair/payment/PaymentEvents.scala
#	eclair-core/src/test/scala/fr/acinq/eclair/api/JsonSerializersSpec.scala
2019-03-28 10:44:24 +01:00
Fabrice Drouin
e2ff5c857b
Set version to 0.3-SNAPSHOT (#920)
We have enough major changes from the last release to justify switching to 0.3
2019-03-28 09:49:17 +01:00
araspitzu
2505e80283
Factor out nodeId API param, rename /channels API param to nodeId. (#919) 2019-03-27 15:49:22 +01:00
araspitzu
a4b94004e4 API: use form data instead of JSON-RPC (#894)
Port the existing API functionalities over a new structure of HTTP endpoints, with the biggest difference being the usage of **named parameters** for the requests (responses are unchanged). RPC methods have become endpoints and the parameters for each are now passed via form-params (clients must use the header "Content-Type" : "multipart/form-data"), this allows for a clearer interpretation of the parameters and results in more elegant parsing code on the server side. It is possible to still use the old API version via a configuration key.

Old API can be used by setting `eclair.api.use-old-api=true`.
2019-03-26 18:10:09 +01:00
araspitzu
89ddc52640 Deal with channels with fees=0 when computing a route (#905)
* Treat channels with fees=0 as if they had feeBase=1msat while we compute a route

* Add test to ensure we build the onion attaching no fees if they were not required by the channel_update
2019-03-26 14:00:15 +01:00
Pierre-Marie Padiou
57e43cc65d
Check WatchSpent in constant time (#916)
This is done with a secondary map that indexes watched utxos.
2019-03-25 18:09:30 +01:00
araspitzu
06b2337ed9
Rework database initialization (#911)
* Initialize the database outside the node param constructor
* Do not create folders during StartupSpec
* Simplify syntax for instantiating test Databases
* Rework parameter passing to database initialization
* Force UTF-8 file encoding on all platform.
2019-03-25 18:04:30 +01:00
Fabrice Drouin
3b7afd92d4
Use bitcoin-lib 0.11 which embeds libsecp256k1 (#907)
* Use bitcoin-lib 0.11, which embeds libsecp256k1

* Unit tests: generate dummy sig from 32 random bytes

We now use a version of bitcoin-lib which embeds JNI bindings for libsecp256k1,
and it will only sign data that is 32 bytes long (in Bitcoin and LN you always
sign data hashes, not the actual data).

* Use maven 3.6.0 and a different mirror

* RoutingSyncSpec: don't create databases at init time

We called nodeParams which created a new in-memory sqlite database everytime we created "fake" routing info
2019-03-25 14:42:06 +01:00
Pierre-Marie Padiou
8ea4bd0468
Don't send updates if no filter has been set (#912)
We mistakenly implemented `Peer.timestampInRange` as opt-out whereas it
should be opt-in.
2019-03-25 14:37:12 +01:00
araspitzu
3fda5ddede Remove unused param 'randomize' from SendPayment command (#910)
Cleanup of the SendPayment command in which there was a leftover field 'randomize' currently replaced by its analogous in the RouteParams.
2019-03-22 14:39:06 +01:00
Fabrice Drouin
32d8a08ad1 Improve unit tests (#908)
* Bitcoin tests: generate 150 blocks instead of 500

We don't need to generate 432 blocks to activate segwit but we still need to have
spendable coins and coinbase maturity is 100 blocks even on regtest.

* Electrum client: test against mainnet Electrum servers

Previous test against testnet servers was flaky because testnet Electrum
servers are unrelable. Here we test against our own server on mainnet (and
2 servers from our list for the pool test).
2019-03-22 13:26:55 +01:00
araspitzu
1c9ac1d62d Ensure the cost function in path-finding is monotonic (#904)
Make sure the cost function in path-finding is monotonic
2019-03-20 10:43:48 +01:00
Fabrice Drouin
4aa7a1ca9f Upgrade to bitcoin 0.17.1 (#826)
Bitcoin Core 0.18 is about to enter RC cycle and should be release soon (initial target was April). It is not compatible with 0.16 (some of the RPC calls that we use have been removed. They're still available in 0.17 but tagged as deprecated). 

With this PR, eclair will be compatible with 0.17 and the upcoming 0.18, but not with 0.16 any more so it will be a breaking change for some of our users. Supporting the last 2 versions is the right option and we should be ready before 0.18 is actually released (its initial target was April).
2019-03-19 14:57:03 +01:00
Pierre-Marie Padiou
cc3395a5bb
Better logic for sending channel_updates (#888)
* don't spam with channel_updates at startup

Previous logic was very simple but naive:
- every time a channel_update changed we would send it out
- we would always make a new channel_update with the disabled flag set
at startup.

In case our node was simply restarted, this resulted in us re-sending a
channel_update with the disabled flag set, then a second one with the
disabled flag unset a few seconds later, for each public channel.

On top of that, this opened way to a bug: if reconnection is very fast,
then the two successive channel_update will have the same timestamp,
causing the router to not send the second one, which means that the
channel would be considered disabled by the network, and excluded from
payments.

The new logic is as follows:
- when we do NORMAL->NORMAL or NORMAL->OFFLINE or OFFLINE->NORMAL, we
send out the new channel_update if it has changed
- in all other case (e.g. WAIT_FOR_INIT_INTERNAL->OFFLINE) we do nothing

As a side effect, if we were connected to a peer, then we shut down
eclair, then the peer goes down, then we restart eclair: we will make a
new channel_update with the disabled flag set but we won't broadcast it.
If someone tries to make a payment to that node, we will return the
new channel_update with disabled flag set (and maybe the payer will then
broadcast that channel_update). So even in that corner case we are good.

* quick reconnection: bump channel_update timestamp

In case of a disconnection-reconnection, we first generate a
channel_update with disabled bit set, then after we reconnect we
generate a second channel_update with disabled bit not set.

If this happens very quickly, then both channel_updates will have the
same timestamp, and the second one will get ignored by the network.

A simple fix is to bump the second timestamp in this case.

* set channel_update refresh timer at reconnection

We only care about this timer when connected anyway. We also cancel it
when disconnecting.

This has several advantages:
- having a static task resulted in unnecessary refresh if the channel
got disconnected/reconnected in between 2 weeks
- better repartition of the channel_update refresh over time because at
startup all channels were generated at the same time causing all refresh
tasks to be synchronized
- less overhead for the scheduler (because we cancel refresh task for
offline channels (minor, but still)
2019-03-18 14:39:29 +01:00
Fabrice Drouin
5519d0aa6a Minor fixes (dependencies, unit tests) (#901)
Use bitcoin-lib v0.10 which has finally been synced to maven central.
Fix transactions unit test (the check in the test was using the whole locktime and not
the last 24 bits).
2019-03-15 12:54:33 +01:00
Pierre-Marie Padiou
b681cfca47
Replace BinaryData by scodec.bits.ByteVector (#896)
See https://github.com/ACINQ/bitcoin-lib/pull/31.

We still have to use `Array[Byte]` for low-level cryptographic primitives, and `akka.util.ByteBuffer` for tcp connections. In order to reduce unnecessary copies, we used `ByteVector.view(...)` as much as possible.

Took the opportunity to do a project-wide optimize imports. We might as well do it now since pretty much all files have been touched already.

NB: temporarily use bitcoin-lib 0.10.1-SNAPSHOT because maven central is very slow and we can't access the recently release 0.10 for now.
2019-03-14 12:43:28 +01:00
araspitzu
889e86a908
Move the param 'randomize' from RouteRequest to RouteParams (#895)
* Move the param 'randomize' from RouteRequest to RouteParams
2019-03-13 18:58:55 +01:00
Pierre-Marie Padiou
2712e30504
Better error logs for socks5 proxy (#893) 2019-03-12 13:37:27 +01:00
Fabrice Drouin
abba9f77ec NetworkDb: remove stale channels in batch (#886)
Add methods to delete channels and tags channels as pruned in batch which is much
more efficient in sqlite.

* Network db: minor changes in unit tests

Test pruning a few 1000s channels at once.

* NetworkDb API: use Iterators and not Seq

It's more consistent with our code base.
2019-03-12 13:34:40 +01:00
pm47
85df143c64
send events when htlc settle on-chain
This is a simpler alternative to #867, with the following limitations:
- no `OnChainRefundsDb` and associated API calls
- `PaymentSettlingOnChain` event will be sent exactly once per payment
and have less information
- we don't touch `HtlcTimeoutTx`
- use json4s type hints instead of manual attributes to case classes
2019-03-07 11:07:43 +01:00
Pierre-Marie Padiou
70397962b6
Clean channels with unexisting funding tx (#714)
There are several separate but related changes in this PR:

(a) Fast close on scenarii where we have nothing at stake (instead of going to `CLOSING` state). The previous process was not only slower (we had to wait for confirmations), but it never resolved when the funding tx hadn't been confirmed. Note that there is still an edge case where the funding tx never gets confirmed, we are fundee and we have something at stake (`push_msat` > 0).

(b) When *fundee*: after a timeout (5 days), if the funding tx hasn't reached `min_depth`, we cancel the channel.

(c) When *funder*: there is no timeout on the funding tx: however on restart, if we detect that our funding tx was doublespent, then we cancel the channel. Just because there is a doublespend doesn't mean that something malicious is going on: e.g. fee was to low, the tx was eventually removed from mempools and we just spent the inputs on something else).

Commits:

* set proper channelid in logs on restore

* fast close if we have nothing at stake

* added fundingTx and timestamp to DATA_WAIT_FOR_FUNDING_CONFIRMED

Also added migration codecs and tests

* implemented funding timeout for fundee

After a given delay, fundee will consider that the funding tx will never
confirm and cancels the channel.

Note that this doesn't apply to the funder, because our implementation
guarantees that we have sent out a funding tx, and the only way to be
sure that it will never be confirmed is that we double spend it. We just
can't rely on a timeout if we want to be safe.

* Electrum: detect if a wallet transaction has been double-spent

If it's in the mempool, or if it's been confirmed, then it's not double spent.
If it's not confirmed and not the mempool, we check if we have a transaction in
our wallet that sspends one of the inputs of our tx. If we find one, then it's been
double spent.
This will work with our funding txs, but not with their funding txs.

* fix regression with dataloss protection

The fast close causes a regression with dataloss protection, because
if we have nothing at stake we won't publish anything in case of
error (even if our peer asks us to).

This fixes #854.
2019-03-06 11:10:40 +01:00
Pierre-Marie Padiou
f9ead30b5c
Set default to-remote-delay-blocks to 720 (#879)
It sounds like a more reasonable default value, 144 was too short.

Keep using 144 blocks for our integration tests.
2019-02-25 18:00:17 +01:00
araspitzu
fe31f2d9d2 Routing heuristics (#821)
* Add route-weight-ratios to SendPayment/RouteRequest

* Update test channel_update with real world fee values

* Add maxFeeBase and maxFeePct to SendCommand, use high fee tolerance in integration test

* Expose randomized route selection feature in SendPayment, used in integration test too

* Add maxCltv to SendPayment/RouteRequest

* Implement boundaries for graph searching with cost, cltv, and size

* Enable searching for routes with size/CLTV/fee limits

* Expose RouteParams in RouteRequest and SendPayment

* If we couldn't find a route on the first attempt, retry relaxing the restriction on the route size

* Avoid returning an empty path, collapse the route not found cases into one

* When retrying to search for a route, relax 'maxCltv'

* Group search params configurations into a block

* Use the returning edges in 'ignoredEdges' when looking for a spur path

* Log path-finding params when receiving a route request

* Enforce weight ratios to be between (0,1]

* Make path-finding heuristics optional
2019-02-22 18:43:20 +01:00
Dominique
32d0500ef9 Use ypub prefix for Electrum xpub (#875)
* Updated prefix of electrum xpub to upub/ypub
2019-02-21 16:25:54 +01:00
Pierre-Marie Padiou
3db7b176d3
Update jeromq dependency (#852)
* jeromq 0.4.0->0.5.0
2019-02-21 16:02:39 +01:00
Fabrice Drouin
34e51c19cc
Use OpenJDK 11 as default JDK (#846)
* Upgrade to JDK11

Eclair can be built and used on Oracle JDK 1.8 or OpenJDK 11.
JavaFX is now embedded in eclair-node-gui and does not need to be installed separately.

* Install: update java download links

OpenJDK 11 is now our recommendation. Tell users to download java from https://jdk.java.net/11

* README: Rewrite installation instructions
2019-02-21 15:11:44 +01:00
Fabrice Drouin
c0af665990 Electrum fixes and improvements (#873)
* Electrum: don't ask for merkle proofs for unconfirmed txs

* Electrum: clear status when we get disconnected and still have pending history transactions

When we get disconnected and have script hashes for which we still have pending connections,
clear the script hash status. When we reconnect we will ask for its history again, this way we
won't miss anything. Since we rotate keys it should not result in heavy traffic (script hashes have
few history items).

* Electrum: represent and persist block heights as 32 bits signed ints

Int.MaxValue is about 40,000 years of block which should be enough, and it will fix the encoding
problem users on testnet when there's a reorg and one of their txs has a height of -1.

Side-note: changing the wallet codec can be done easily: if we cannot read and decode persisted data
we just start with an empty wallet and retrieve all wallet data from electrum servers, and once it's
ready it will be encoded with the new codec and saved.

* Electrum persistence: include a version number

It provides a clean way, when upgrading the app, of choosing whether to keep the same version and start from the
last persisted wallet (if the persistence format has not been changed or is compatible with the old one), or to
change the version and force starting from an empty wallet and downloading all wallet items from Electrum servers.

* ElectrumClient: remove useless buffer
2019-02-19 11:06:36 +01:00
Pierre-Marie Padiou
aeb4360464
Fixed computation of available balance (#868)
There was a unit mismatch. Added a test.
2019-02-18 18:48:01 +01:00
Pierre-Marie Padiou
7ae083ae29
Faster gui startup (#863)
The GUI took a very long time to startup because nodes and channels were
stored in javafx `ObervableList` which doesn't allow random access. We
can't easily use `ObservableMap` because `TableView` do not support
them.

As a workaround, created an `IndexedObservableList` which keeps track of
indices in `ObservableList` so that we can still have fast random
access.

Also, now grouping announcements in `NetworkEvent` instead of sending
them one by one.
2019-02-14 15:01:19 +01:00
Pierre-Marie Padiou
57a9e6ed86
Support all-uppercase payment requests (#862) 2019-02-12 20:37:53 +01:00
araspitzu
efa42f5967 Make sure the path-finding algorithm can't use a channel twice in a route (#857)
* Make sure the path-finding algo can't go backward when searching
2019-02-12 15:49:19 +00:00
araspitzu
94c1c36252 Fix discrepancy between config keys (#860) 2019-02-12 10:39:23 +00:00
Pierre-Marie Padiou
884812ade0
Reimplemented BOLT 11 with scodec (#856) 2019-02-11 19:45:56 +01:00
araspitzu
4291bef88d Parametric route search (#844)
* Enable searching for routes with size/CLTV/fee limits

* Expose the RouteParams in RouteRequest

* Expose the RouteParams in SendPayment

* Rename DEFAULT_ROUTE_MAX_LENGTH

* If we couldn't find a route on the first attempt, retry relaxing the restriction on the route size

* Avoid returning an empty path, collapse the route not found cases into one

* When retrying to search for a route, relax 'maxCltv'

* Move the default params for route searching in the conf, refactor together router params into a config class

* Remove max-payment-fee in favor of router.search-max-fee-pct

* Group search params configurations into a block

* Rename config keys for router path-finding
2019-02-11 17:30:04 +00:00
Dominique
b29874ea70 Increased max-to-local-delay-blocks to 2016 (#853)
Max CLTV of 2016 agreed in 2018 Adelaide's meeting for 1.1 specs.
2019-02-08 15:11:21 +01:00
Pierre-Marie Padiou
fe48e5540c
Stop disconnected peer when it has no channels (#840)
When we are disconnected and we don't have any channel with that peer,
we can stop it and remove its address from db.

We also need to handle the case where we are in `DISCONNECTED` or
`INITIALIZING` state and we are notified that the last channel we had
with that peer just got closed.

Note that this opens a race condition in the switchboard, if we receive
an incoming connection from that same peer right after we stopped it,
and before the switchboard received the `Terminated` event. If that
happens, then `Peer.Connect` or `Peer.OpenChannel` will timeout. We
could also have the switchboard listens to deadletter events, but that
seems a bit over the top.

Also, removed switchboard's map of peers. Instead, we use the actor's 
children list, and access peers using the recommended `child()` method.
Now the 'peers request only returns an `Iterable` instead of a `Map`. This 
removes the need to watch child actors, and thus removes the race
condition when peers were stopped. As a trade-off, peer lookup is now
in O(log(N)) instead of O(1) (with N being the number of peers), but this
seems acceptable.
2019-02-08 13:29:46 +01:00
Fabrice Drouin
9f6d07ae44 Improve Electrum start-up time (#848)
Persist a partial view of our wallet to enable faster startup time.

Users will be able to create transactions as soon as we've checked that we're connected to a "good" electrum server. In the unlikely event where they were able to create and try to publish a transaction during the few seconds it took to finish syncing and their utxo was spent (because they were trying to use an unconfirmed utxo that got double spent, or if they spent their utxo themselves from another wallet initialized with the same seed  while his one was offline), publishing the tx will fail. 

* Electrum: persist wallet state

Wallet state is persisted and reloaded on startup.

* Electrum wallet: fix handling of headers chunk

When we receive a tx that is older than our checkpoints, we download and check
the header chunk that it's in, check it and connect it to our chain.

* Electrum: advertise wallet transactions

Send notifications for all wallet transactions once we're connected and synced

* Electrum: add timestamp to wallet events

Add an optional timestamp to TransactionReceived and TransactionConfidenceChanged, which is the timestamp of the block the tx was confirmed in (if any).

* Electrum client: use a Close message

This will fix concurrency issues where handlers are called when the actor
is already stopped.
2019-02-08 11:28:38 +01:00
Dominique
267037a937
Add balance and channel lifecycle events to the audit db (#827)
Note that balance events are logged at most once every 30s, and only when
the balance actually changes (e.g. won't log if a payment is failed).

Also, only send `AvailableBalanceChanged` when needed.

We were sending this event everytime we sent a `commit_sig`, which is
incorrect because our balance doesn't change if, say, we are signing an
incoming htlc.

Note that we only send this event in `NORMAL` state, not in `SHUTDOWN`
state, because the balance is not really _available_ in the latter.
2019-02-08 10:41:09 +01:00
rorp
808bf14d20 Support for Tor onion services (#736)
This includes support for hosting onion services, and connecting to them, which are two separate things:
- Opening an onion service implie interacting with the tor daemon controller, which requires authentication. We support both `SAFECOOKIE` and `HASHEDPASSWORD` authentication mechanisms, with a default to `SAFECOOKIE`. We support v2 and v3 services, with a default to v3 as recommended by the tor project.
- Connecting to onion services requires tunnelling through tor's local SOCKS5 proxy.

Incoming and outgoing tor connections are thus separate matters that needs to be configured independently. A specific documentation has been added to guide users through these steps.

Big thanks to @rorp for doing the heavy lifting on all this!
2019-02-08 10:18:59 +01:00
araspitzu
968961248e
Allow to disable route randomization via configuration (#851)
* Allow to enable/disable the route randomization feature from the configuration

* Move router related configuration keys in router block.
2019-02-05 17:35:47 +01:00
araspitzu
3165f5dc36
(Router) Always select direct channel if there is one to the target (#850)
During route searching, bypass the route randomization to always select the direct channel if there is one to the target.
2019-02-05 14:00:31 +01:00
Pierre-Marie Padiou
1da0017311
Proper handling of gossiped channels being spent (#838)
While it makes sense to exclude from the routing table channels for
which there is a spending tx in the mempool, we shouldn't blame our
peers for considering the channel still opened if the spending tx hasn't
yet been confirmed.

Also, reworked `ValidateResult` with better types. It appears that the
`NonexistingChannel` error wasn't really useful (a malicious peer would
probably point to an existing funding tx, so there is no real difference
between "txid not found" and "invalid script"), so it was replaced by
`InvalidAnnouncement` error which is a more serious offense (punished
by a disconnection, and probably a ban when we implement that sort of
things).
2019-01-31 16:03:01 +01:00
araspitzu
4db9c8daf7 Optional route randomization (#842)
* Make route randomization optional (enabled by default), option is exposed in SendPayment/RouteRequest

* Fix non deterministic behavior in IntegrationTest
2019-01-30 15:21:22 +01:00
Pierre-Marie Padiou
7ff694c711
Ignore reconnections requests to the same peer with the same address (#835)
* ignore reconnections requests to the same address

* don't wait 1s before connecting on restart
2019-01-29 18:38:41 +01:00
rorp
a91cd631e8 Replace initialization futures Future[Boolean] by Future[Done] (#836)
Fixes #772.
2019-01-29 10:25:11 +01:00
Pierre-Marie Padiou
3954e39bf8
Set timestamp filter lower bound to current time (#837)
We previously assumed that the `gossip_timestamp_filter` only applied to
future messages, so we set `first_timestamp` to 0 in order to have a
pass-all filter.

But BOLT 7 actually says that the remote peer:
> SHOULD send all gossip messages whose timestamp is greater or equal to
first_timestamp, and less than first_timestamp plus timestamp_range

Which means that the way our filter was set, the remote peer would dump
the entire routing table on us.

By setting `first_timestamp` to the current time, we achieve what we
want. The synchronization of older messages is done by sending a
`query_channel_range` and then one or several `query_short_channel_ids`.
2019-01-28 15:58:35 +01:00
pm47
a331a69406
Merge branch 'master' into audit-extended 2019-01-24 10:25:39 +01:00
Fabrice Drouin
629cb22192
ChannelSelectionSpec: use akka.event.NoLogging (#834)
akka.http.impl.util.DefaultNoLogging is not available in akka 2.3 which we use on Android.
2019-01-23 21:18:48 +01:00
araspitzu
3953bc400e Fix flaky test in IntegrationSpec (#832) 2019-01-22 17:49:11 +01:00
pm47
e7415a2a7c
Merge branch 'master' into audit-extended 2019-01-22 10:52:08 +01:00
Pierre-Marie Padiou
3aa5754490
Relay to channel with lowest possible balance (#784)
* relay to channel with lowest possible balance

Our current channel selection is very simplistic: we relay to the
channel with the largest balance. As time goes by, this leads to all
channels having the same balance.

A better strategy is to relay to the channel which has the smallest
balance but has enough to process the payment. This way we save larger
channels for larger payments, and also on average channels get depleted
one after the other.

* added tests...

...and found bugs!

Note that there is something fishy in BOLT 4, filed a PR:
https://github.com/lightningnetwork/lightning-rfc/pull/538

Also, first try of softwaremill's quicklens lib (in scope test for now)

* minor: fixed typo (h/t @btcontract)
2019-01-21 22:08:58 +01:00
pm47
3279226902
Merge branch 'relay-to-smaller-channel' into audit-extended 2019-01-21 19:14:47 +01:00
sstone
3f72b441d8
Set version to 0.2-SNAPSHOT 2019-01-18 20:15:04 +01:00
sstone
eb0e45a8b1
set version to 0.2-beta9 2019-01-18 19:01:59 +01:00
Pierre-Marie Padiou
a52acdcaf1
Auto probing of local channels (#762)
This is a simple mechanism to test our direct peers by sending fake
small payments to them. A probe is considered successful if the peer
replies with an `UnknownPaymentHash` error.

Probing is configurable and disabled by default.
2019-01-18 14:39:06 +01:00
araspitzu
d5fe47572c Compute k-shortest routes (#813)
We use Yen's algorithm to find the k-shortest (loopless) paths in a graph, and dijkstra as search algo.

We then pick a random route up among the cheapest ones.
2019-01-17 21:15:51 +01:00
Fabrice Drouin
74d454d904
Electrum: improve error handling (#825)
* Electrum: always stop clients when there's an error

We will automatically connect to another server, and it's much cleaner
that restarting right away

* Electrum: improve handling of server errors

* Electrum Pool: don't switch to our current master

In regtest (and probably testnet too) it may seem that our master server went
straight to current height + 2 when blocks are created very quickly, so
check first that the server is not already our master before we switch.
2019-01-17 20:59:06 +01:00
araspitzu
67dc37c525 Impose a max length of 32 bytes on UTF-8 encoded aliases (#828)
Co-Authored-By: araspitzu <a.raspitzu@protonmail.com>
2019-01-17 19:23:08 +01:00
n1bor
6438c65ad9 Add JSON serializer for PaymentRequest (#798)
Also, renamed `checkinvoice` to `parseinvoice`. `checkinvoice` still works but is deprecated.
2019-01-17 15:46:02 +01:00
araspitzu
6d638e9941
Fix findroute documentation (#817)
* Fix the README and help message about the 'findroute' API parameters
2019-01-16 18:35:53 +01:00
pm47
b7745470b5
fixup: we want to compare with the original balance before the first event 2019-01-15 19:44:31 +01:00
pm47
5b9858934f
throttle logging of balance update events 2019-01-15 19:30:53 +01:00
pm47
0c9cd1620b
minor: fixed typo (h/t @btcontract) 2019-01-14 19:14:06 +01:00
Dominique
e3b2992934
Readibility improvements in GUI (#801)
* Improved amounts readability (fixes #542) and added the Bits unit 
denomination in the documentation

* Improved channel panel UI layout

* Added a confirmation dialog when closing a channel, with a short summary 
of the channel to be closed

The balance bar has been shrunk in size so that it should not be mistaken as 
a separator element between channels. The channel's balance, capacity and 
peer node id are now more visible. Also added the short channel id to the 
channel's pane.

fixes #690

* Added node's aggregated balance in the status bar

fixes #775
2019-01-14 16:53:52 +01:00
pm47
1df3455a72
only send AvailableBalanceChanged when needed
We were sending this event everytime we sent a `commit_sig`, which is
incorrect because our balance doesn't change if, say, we are signing an
incoming htlc.

Note that we only send this event in `NORMAL` state, not in `SHUTDOWN`
state, because the balance is not really *available* in the latter.
2019-01-14 11:31:56 +01:00
pm47
4005720a78
Merge branch 'master' into audit-extended 2019-01-14 10:57:42 +01:00
Pierre-Marie Padiou
10ea7bdc23
Make ping less aggressive (#782)
* send pings only after there is less activity

* make disconnect-on-ping configurable
2019-01-11 19:16:37 +01:00
araspitzu
fd3ff9184e Compute routes backward (#797)
* Support searching backward from the target

* Use the amount+fees with testing for min/max htlc value of edges

* Build the adjacency list graph with incoming edges instead of outgoing

* Make sure we don't find routes longer than the max allowed by the spec

* Remove default amount msat, enhance 'findroute' API

* Optimize tests for ignored edges in Dijkstra

* Enhance test for max route length, fix the length to 20 channels

* Add test for routing to a target that is not in the graph (assisted routes)
2019-01-11 17:20:01 +01:00
araspitzu
83b464cfcc Fix short_channel_id parsing and add RPC API test (#815)
* Correctly parse short channel id

* Add test for RPC APIs

* Put akka.http.version in parent project pom

Co-Authored-By: araspitzu <a.raspitzu@protonmail.com>
2019-01-11 14:59:33 +01:00
Fabrice Drouin
e082d89a3b
Electrum: download, verify and store headers (#776)
* Implement "GetHeaders" RPC call

* Add checkpoints and pow verification

* Don't resolve server address too soon

* Add testnet checkpoints

* Store headers in a sqlite wallet db

* Use 1.4 protocol

Request protocol version 1.4 (this is the default setting in Electrum wallet).
Retrieve and store all headers as binary blobs in bitcoin format.

* Insert headers in batch

* Optimize headers sync and persistence

We assume that there won't be a reorg of more that 2016 blocks (which
could be handled by publishing a new checkpoint) and persist our headers
except for the last 2016 we have received: when we restart, we will ask
our server for at least 2016 headers.

* Persists transactions

Transactions are persisted only when they've been verified (i.e. we've receive
a valid Merkle proof)

* Disable difficulty check on testnet and regtest

On testnet there can be difficulty adjustements even within a re-targeting window.

* Update checkpoints

* Use proper Ping message

`version` can not longer be sent as a ping as we did before.

* Don't ask for Merkle proofs for unconfirmed transactions

* Improve startup time

We now store a new checkpoint and headers up to that checkpoint as soon as our
best chain is 2016 + 500 blocks long

* Properly detect connection loss

* Update electrum mainnet servers list

Using the list from Electrum 3.3.2

* Don't open multiple connection to the same Electrum servers

We want to keep connection to 3 different servers, but when we have less than 3 different
addresses it's pointless to attempt to keep maintain 3 connections.
2019-01-11 14:08:46 +01:00
pm47
3eaf5a628a
added handler for AvailableBalanceChanged 2019-01-10 20:21:43 +01:00
pm47
fc680690ef
make auditor ignore unrelevant ChannelStateChanged events 2019-01-10 19:59:43 +01:00
pm47
7af05b3eee
added balance_updated and channel_events tables 2019-01-10 19:42:52 +01:00
pm47
c75082954b
added tests...
...and found bugs!

Note that there is something fishy in BOLT 4, filed a PR:
https://github.com/lightningnetwork/lightning-rfc/pull/538

Also, first try of softwaremill's quicklens lib (in scope test for now)
2019-01-06 00:15:20 +01:00
pm47
405759f52c
relay to channel with lowest possible balance
Our current channel selection is very simplistic: we relay to the
channel with the largest balance. As time goes by, this leads to all
channels having the same balance.

A better strategy is to relay to the channel which has the smallest
balance but has enough to process the payment. This way we save larger
channels for larger payments, and also on average channels get depleted
one after the other.
2019-01-05 17:29:03 +01:00
Pierre-Marie Padiou
52f671384e
Detect broken HTLC links at startup (#757)
If we have stopped eclair while it was forwarding HTLCs, it is possible
that we are in a state were an incoming HTLC
was committed by both sides, but we didn't have time to send
and/or sign the corresponding HTLC to the downstream node.

In that case, if we do nothing, the incoming HTLC will
eventually expire and we won't lose money, but the channel
will get closed, which is a major inconvenience.

This check will detect this and will allow us
to fast-fail HTLCs and thus preserve channels.
2019-01-04 17:34:50 +01:00
araspitzu
75a18e2446 Set a max value of 2016 blocks for to_self_delay (#795)
This will be a hard requirement in BOLT 1.1
2019-01-03 16:59:26 +01:00
Pierre-Marie Padiou
ad31d89e54
Disable local channels below reserve (#763)
The goal is to reduce attempts from other nodes in the network to use
channels that are unbalanced and can't be used to relay payments.

This leaks information about the current balance and is a privacy
tradeoff, particularly in this simplistic implementation. A better way
would be to add some kind of hysteresis in order to prevent trivial
probing of channels.
2019-01-03 14:02:39 +01:00
Pierre-Marie Padiou
9da330478a
Add exclusive locks to channels sqlite db (#781)
* added an exclusive write lock to channels sqlite db

* added close() method in db traits
2019-01-03 11:01:53 +01:00
Pierre-Marie Padiou
8887ac2043
Relay fail message *after* it is cross-signed (#754)
We were previously handling `UpdateFailHtlc` and
`UpdateFailMalformedHtlc` similarly to `UpdateFulfillHtlc`, but that is
wrong:
- a fulfill needs to be propagated as soon as possible, because it
allows us to pull funds from upstream
- a fail needs to be cross-signed downstream (=irrevocably confirmed)
before forwarding it upstream, because it means that we won't
be able to pull funds anymore. In other words we need to be absolutely
sure that the htlc won't be fulfilled downstream if we fail it upstream,
otherwise we risk losing money.

Also added tests.
2019-01-02 16:44:05 +01:00
araspitzu
7f3b101426 Use BOLT specific formatting for short channel id (#793) 2019-01-02 14:40:24 +01:00
araspitzu
255c280bd0 Routing: use custom implementation for the shortest path algorithm and the graph (#779)
* Consider htlc_minimum/maximum_msat when computing a route

* Compare shortChannelIds first as it is less costly than comparing the pubkeys

* Remove export to dot functionality

* Remove dependency jgraph

* Add optimized constructor to build the graph faster

* Use fibonacci heaps from jheaps.org

* Use Set instead of Seq for extraEdges, remove redundant publishing of channel updates

* Use Set for ignored edges
2018-12-20 16:52:42 +01:00
Dominique
be5d188a38
Tweak parameters to optimize ElectrumClient connections (#788)
* use TCP_NODELAY and PooledByteBufAllocator

* added reference to interesting slidedeck
2018-12-20 14:14:23 +01:00
Dominique
a80ff1f6d9 Cleaned up mainnet electrum servers list (#786) 2018-12-18 17:21:28 +01:00
Dominique
521aa8adcd Share NioEventLoopGroup across Electrum clients (#783)
`NioEventLoopGroup` is expensive to create and should be shared with all clients. This also prevents issues when several event loop groups are created and are not shutdown correctly.
2018-12-14 11:44:11 +01:00
Pierre-Marie Padiou
723d0deed2
Optional per-node features in conf (#778)
Allow setting specific `globalfeatures` and `localfeatures` for given nodes.
2018-12-12 16:02:51 +01:00
Anton Kumaigorodski
4573d8a1e0 Make maxHtlcValueInFlight checks directional when sending and receiving HTLCs (#768) 2018-12-12 15:59:31 +01:00
Pierre-Marie Padiou
b5c96f0439
Update connection-level features at reconnection (#765)
Previously we weren't updating them since the channel creation, which
was wrong: both local and remote features may change after a
reconnection.
2018-12-12 15:12:17 +01:00
Pierre-Marie Padiou
ff588b578f
Use netty to connect to Electrum servers (#774)
* replaced akka.io by netty in electrum client and enabled ssl support

* updated docker-testkit to 0.9.8 so that electrum tests pass on windows

* use ssl port on testnet/mainnet

* removed experimental warning on electrum
2018-12-11 18:13:38 +01:00
Pierre-Marie Padiou
99566f525c
Disconnect peer after a timeout when waiting for revocation (#761)
* added a revocation timeout

If a peer doesn't quickly reply to a `commit_sig`, we assume that it is
experiencing technical issues, and we disconnect. This will make pending
(unsigned) `update_add_htlc` to be fast-failed and will hopefully limit
the number of htlc that time out in the network.

By default we wait 20 seconds, configurable with
`eclair.revocation-timeout`.

This fixes #745.
2018-12-07 14:49:51 +01:00
rorp
fadfabfd33 Wait for Router to be initialized at startup (#769) 2018-12-04 15:37:52 +01:00
Pierre-Marie Padiou
1c0e24a909
Watch future remote commit on restore (#766)
We need to put back watches on restart in "future remote commit published" scenarii, otherwise we will never consider the channel closed if we restart before the "claim main output" tx is confirmed. Note that there was no risk of losing funds, but the channel would have lingered forever.
2018-11-23 16:38:07 +01:00
Pierre-Marie Padiou
fa1b2e4c00
Switch sttp backend async-http-client -> okhttp (#764)
Okhttp works better on Android.
2018-11-23 11:58:23 +01:00
Anton Kumaigorodski
65a854caf3 Disconnect peer if it does not reply to pings (#755)
* Also ignore invalid pings
2018-11-20 14:03:46 +01:00
n1bor
738b4fa8e9 Reject received payments where PaymentRequest Expiry Tag time has been exceeded. (#749)
This fixes #748.

Also renamed htlc `expiry` to `cltvExpiry`. This removes confusion between different types of expiries and is how the spec is written.
2018-11-15 14:08:27 +01:00
Jens Schendel
93464aa7fb Updated readme.md and eclair-cli (#750)
* Minor changes. Typos and grammar corrected.

* Added check for curl and hint ift not installed
2018-11-13 17:35:16 +01:00
Pierre-Marie Padiou
2de7c6b07d
Use sttp lib instead of akka-http-client (#720)
Also updated json4s-jackson to 3.6.0
2018-10-25 16:45:27 +02:00
Fabrice Drouin
5141cd7d4d
Use different ZMQ block and tx subscriptions
Fixes #733
2018-10-25 14:28:28 +02:00
Dominique
3a221e7e98
Support for custom Electrum server (#739)
We can now use the `overrideDefaults` parameter in `Setup` to programmatically 
provide a custom electrum address when starting eclair, by setting the 
`eclair.electrum.host` and `eclair.electrum.port` entries in the configuration.

When these entries are set, eclair-core will always try to connect to this server
instead of relying on a random server picked from the preset lists.
2018-10-23 19:07:20 +02:00
Pierre-Marie Padiou
2bdf258c78
Always add 1 block to the finalCltvExpiry (#742)
This fixes #651.
2018-10-23 17:31:22 +02:00
sstone
4e0702a923
set version to 0.2-SNAPSHOT 2018-10-20 21:38:16 +02:00
sstone
52821b8664
set version to 0.2-beta8 2018-10-20 21:34:34 +02:00
Fabrice Drouin
6126ed4b9e
Fix encoding of FinalIncorrectHtlcAmount error message (#740) 2018-10-19 17:58:20 +02:00
Pierre-Marie Padiou
c77c276c77
Add htlcMaximumMsat field to ChannelUpdate message (#738)
* Add `htlcMaximumMsat` field to `ChannelUpdate` message

* added compatibility test with c-lightning
2018-10-19 17:47:13 +02:00
sstone
b0305b0551
set version to 0.2-SNAPSHOT 2018-10-15 17:00:40 +02:00
sstone
c564f51d24
set version to 0.2-beta7 2018-10-15 16:48:13 +02:00
Pierre-Marie Padiou
22b6bfb0ab
Only persist trimmed htlcs (#724)
We persist htlc data in order to be able to claim htlc outputs in
case a revoked tx is published by our counterparty, so only htlcs
above remote's `dust_limit` matter.

Removed the TODO because we need data to be indexed by commit number so
it is ok to write the same htlc data for every commitment it is included
in.
2018-10-15 14:46:51 +02:00
Pierre-Marie Padiou
892770b1ed
Update scalatest and remove junit runner (#728)
* updated to scalatest 3.0.5

* use scalatest runner instead of junit

Output is far more readable, and makes console (incl. travis) reports
actually usable.

Turned off test logs as error reporting is enough to figure out what
happens.

The only downside is that we can't use junit's categories to group
tests, like we did for docker related tests. We	could use nested suites,
but that seems to be overkill so I just removed the categories. Users
will only have the possibility to either skip/run all tests.

* update scala-maven-plugin to 3.4.2

NB: This requires maven 3.5.4, which means that we currently need to
manually install maven on travis.

Also updated Docker java version to 8u181 (8u171 for compiling).
2018-10-11 19:01:41 +02:00
Fabrice Drouin
d490480b7e
Simplify bitcoind version check (#731)
Bitcoind returns version as MMmmrr (major, minor, revision), use an int representation
and compare it to our minimum version target.
2018-10-11 18:54:12 +02:00
sstone
997aceea82
set version back to 0.2-SNAPSHOT 2018-09-26 14:05:57 +02:00
sstone
3fc5da0a7b
set version to 0.2-beta6 2018-09-26 14:04:38 +02:00
Fabrice Drouin
b07bb2a39e
Logging: use a rolling file appender (#721)
* Logging: use a rolling file appender

Use one file per day, keep 90 days of logs with a total maximum size
capped at 5 Gb

* Router: log routing broadcast in debug level only
2018-09-24 20:00:36 +02:00
Pierre-Marie Padiou
f38748c0b6
Fixed regression caused by 7a4f175 (#722)
When updating relay fee in state OFFLINE, the new channel_update must
have the disabled flag on.

This caused tests to be flaky, added necessary checks to always make
them fail in case that kind of regression happens again.
2018-09-24 19:41:27 +02:00
Pierre-Marie Padiou
7a4f175f2f
Handle update relay fee in OFFLINE state (#719)
Previously it was only possible to update relay fee in NORMAL state,
which is not very convenient because most of the time there are always
some channels in OFFLINE state.

This works like the NORMAL case, except that the new `channel_update`
won't be broadcast immediately. It will be sent out next time the
channel goes back to NORMAL, in the same `channel_update` that sets the
`enable` flag to true.

Also added a default handler that properly rejects the
CMD_UPDATE_RELAY_FEE command in all other states.
2018-09-24 13:59:01 +02:00
Pierre-Marie Padiou
83b00e37f4
Improved eclair-cli (#718)
This fixes #695, and also adds the channel point in the default channel output.

```bash
$ ./eclair-cli channel 00fd4d56d94af93765561bb6cb081f519b9627d3f455eba3215a7846a1af0e46
{
  "nodeId": "0232e20e7b68b9b673fb25f48322b151a93186bffe4550045040673797ceca43cf",
  "shortChannelId": "845230006070001",
  "channelId": "00fd4d56d94af93765561bb6cb081f519b9627d3f455eba3215a7846a1af0e46",
  "state": "NORMAL",
  "balanceSat": 9858759,
  "capacitySat": 10000000,
  "channelPoint": "470eafa146785a21a3eb55f4d327969b511f08cbb61b566537f94ad9564dfd00:1"
}
```
2018-09-24 11:49:05 +02:00
Pierre-Marie Padiou
8160e793e7
Make publishTransaction idempotent (#711)
Bitcoin core returns an error `missing inputs (code: -25)` if the tx that we want to publish has already been published and its output have been spent. When we receive this error, we try to get the tx, in order to know if it is in the blockchain, or if its inputs were spent by another tx.

Note: If the outputs of the tx were still unspent, bitcoin core would return "transaction already in block chain (code: -27)" and this is already handled.
2018-09-20 17:22:38 +02:00
Fabrice Drouin
6f2a74e030
Tests: use bitcoind 0.16.3 (#715)
Bitcoind 0.16.0 is no longer available
2018-09-20 16:37:57 +02:00
Pierre-Marie Padiou
8d2ec18557
Replace update_fee in commitments (#709)
This is a simple optimisation, we don't have to keep all `update_fee`, just the last one.

cf BOLT 2:
> An update_fee message is sent by the node which is paying the Bitcoin fee. Like any update, it's first committed to the receiver's commitment transaction and then (once acknowledged) committed to the sender's. Unlike an HTLC, update_fee is never closed but simply replaced.
2018-09-20 16:18:17 +02:00
Fabrice Drouin
f3d11cf098
Fix handling of born again channels (#717)
* Fix handling of born again channels

When we receive a recent update for a channel that we had marked as stale we
must send a query to the underlying transport, not the origin of the update (which
would send the query back to the router)
2018-09-20 16:17:15 +02:00
Pierre-Marie Padiou
9178b5aa38
Ignore 'origin htlc not found' in CLOSING (#708)
If we don't have the origin, it means that we already have forwarded the fulfill so that's not a big deal.

This can happen if they send a signature containing the fulfill, then fail the channel before we have time to sign it.
2018-09-20 16:12:38 +02:00
Fabrice Drouin
512c9823b4
Routing sync fixes (#712)
* Router: reset sync state on reconnection

When we're reconnected to a peer we will start a new sync process and should reset our sync
state with that peer.
2018-09-19 17:35:21 +02:00
Pierre-Marie Padiou
b56f0359fe
Fixed regression in rebroadcast (#713)
Fixed regression caused by 2c1811d: we now don't force sending a
channel_update at the same time with channel_announcement.
This greatly simplifies the rebroadcast logic, and is what caused the
integration test to fail.

Added proper test on Peer, testing the actor, not only static methods.
2018-09-19 16:42:09 +02:00
Pierre-Marie Padiou
448a1e4a82
Set default max-htlc-value-in-flight-msat=50mBTC (#707) 2018-09-18 17:04:11 +02:00
Pierre-Marie Padiou
db96c17fd2
Improve integration tests (#710)
* added more logs and improved integration test

* make travis cache maven data
2018-09-18 17:03:49 +02:00
Pierre-Marie Padiou
2c1811d18f
Remember pruned channels (#706)
Currently we don't remember channels that we have pruned, so we will happily revalidate the same channels again if a node re-sends them to us, and prune them again, a.k.a. the "zombie churn".

Before channel queries, rejecting a stale channel without validating it wasn't trivial,  because nodes sent us the `channel_announcement` before `channel_update`s, and only after receiving the `channel_update` could we know if the channel was still stale. Since we had no way of requesting the `channel_announcement` for one particular channel, we would have to buffer it, which would lead to potential DOS issues. 

But now that we have channel queries, we can now be much more efficient. Process goes like this:
(1) channel x is detected as stale gets pruned, and its id is added to the pruned db
(2) later on we receive a `channel_announcement` from Eve, we ignore it because the channel is in the pruned db
(3) we also receive old `channel_update`s from Eve nodes, just ignore them because we don't know the channel
(4) then one day some other node George sends us the `channel_announcement`, we still ignore it because the channel is still in the pruned db
(5) but then George sends us recent `channel_update`s, and we know that the channel is back from the dead. We ignore those `channel_update`s, but we aldo remove the channel id from the pruned db, and we request announcements for that node from George
(6) George sends us the `channel_announcement` again, we validate it
(7) George then sends us the `channel_update`s again, we process them
(8) done!

This also allows removing the pruning code that we were doing on-the-fly when answering to routing table sync requests.

Needless to say that this leads to a huge reduction in CPU/bandwidth usage on well-connected nodes.

Fixes #623, #624.
2018-09-17 18:30:10 +02:00
Pierre-Marie Padiou
52b161f5e9
Ignore bad announcements sent by peers (#705)
Nodes currently receive tons of bogus channel_announcements, mainly with unexisting or long-spent funding transactions. Of course those don't pass the validation and are rejected, but that takes a significant amount of resources: bandwidth, multiple calls to bitcoind, etc.

On top of that, we forget those announcements as soon as we have rejected them, and will happily revalidate them next time we receive them. As a result, a typical node on mainnet will validate 10s of thousands of useless announcements every day.

As far as we know, this is apparently due to bug in another implementation, but that may very well be used as a DOS attack vector in the future.

This PR adds a simple mechanism to react to misbehaving peer and handle three types of misbehaviors:
(a) bad announcement sigs: that is a serious offense, for now we just close the connection, but in the future we will ban the peer for that kind of things (the same way bitcoin core does)
(b) funding tx already spent: peer send us channel_announcement, but the channel has been closed (funding tx already spent); if we receive too many of those, we will ignore future announcements from this peer for a given time
(c) same as (b), but the channel doesn't even exist (funding tx not found). That may be due to reorgs on testnet.

Needless to say that this leads to a huge reduction in CPU/bandwidth usage on well-connected nodes.
2018-09-17 17:12:41 +02:00
Pierre-Marie Padiou
1ce486ad20
Added LocalCommitConfirmed event (#701)
This event includes the block height at which we will be able to claim
our main output, which comes in handy for user interfaces.
2018-09-17 17:09:50 +02:00
rorp
a85b6d6175 Improve startup error handling (#696)
* Improve startup error handling

* minor changes to ZMQACtor

Scheduler now sends messages instead of directly calling our checkXX methods.
It will work the same but should fix the NPE we sometimes get when we stop the app.
2018-09-17 15:29:43 +02:00
Fabrice Drouin
8c075ee73a
Correctly handle multiple channel_range_replies (#704)
* Correctly handle multiple channel_range_replies

The scheme we use to keep tracks of channel queries with each peer would forget about
missing data when several channel_range_replies are sent back for a single channel_range_queries.

* RoutingSync: remove peer entry properly

* Remove peer entry on our sync map only when we've received a `reply_short_channel_ids_end` message.
* Make routing sync test more explicit

* Routing Sync: rename Sync.count to Sync.totalMissingCount
2018-09-17 15:25:39 +02:00
Pierre-Marie Padiou
c9184146d5
Added catch-all handler for local commit (minor) (#699) 2018-09-12 20:25:22 +02:00
Pierre-Marie Padiou
8645038943
Switched commitment log level to info (minor) (#700)
* switched commitment log level to info

* reduced test log level

* attempt at fixing tests timeout
2018-09-12 19:13:39 +02:00
Pierre-Marie Padiou
b60183628f
Handle overriden htlcs in remote close scenario (#697)
When we just signed an outgoing htlc, it is only present in the next
remote commit (which will become the remote commit once the current one
is revoked).

If we unilaterally close the channel, and our commitment is confirmed,
then the htlc will never reach the chain, it has been "overriden" and
should be failed ASAP. This is correctly handled since
6d5ec8c4fa.

But if remote unilaterally close the channel with its *current*
commitment (that doesn't contain the htlc), then the same thing happens:
the htlc is also "overriden", and we should fail it.

This fixes #691.
2018-09-12 18:24:18 +02:00
Pierre-Marie Padiou
f5a5985205
Multiple fixes in payment lifecycle (#693)
* permissive codec for failure messages

Some implementations were including/ommitting the message type when
including a `channel_update` in failure messages.

We now use a codec that supports both versions for decoding, and
will encode *with* the message type.

* make router handle updates from failure messages

This is a regression caused by 9f708acf04,
which made the `Peer` class encapsulates network announcements inside
`PeerRoutingMessage`, in order to preserve the origin of the messages.

But when we get channel updates as part of failure messages when making
payments, they weren't encapsulated and were ignored by the router.

Re-enabled a non-regression test in `IntegrationSpec` which will prevent
this from happening in the future.

* improve handling of `Update` payment failures

Exclude nodes that send us multiple `Update` failures for the same
payment (they may be bad actors)
2018-09-11 18:07:24 +02:00
Pierre-Marie Padiou
6e0d087c5f
Fixed htlc absolute expiry checks (#687)
There are two different expiry checks:
(a) relative checks: when relaying an htlc, we need to be sure that
the difference of expiries between the outgoing htlc and the incoming
htlc is equal to the `cltv_expiry_delta` that we advertise in the
`channel_update` for the outgoing channel;
(b) absolute checks: we need to make sure that those values are not too
early or too far compared to the current "blockchain time".

The check for (a) needs to be done in the `Relayer`, which is the case
currently. This means that we will check the expiry delta *after* having
signed the incoming htlc, and we will fail the htlc (not the channel) if
the delta is incorrect.

The check for (b) was done in the `Commitments.receiveAdd` method. This
seems to make sense, because we would want to make sure as early as
possible that an incoming htlc has correct expiries, but it is actually
incorrect: the spec tells us to accept (=cross-sign) the htlc, and only
then to fail it before relaying it to the next node.

Indeed there is no risk in accepting an htlc that has an expiry in the
past, or an expiry very far in the future, because this only affects the
counterparty's balance. We just don't want to sign that kind of outgoing
htlcs.

Moving the check to the `sendAdd` will result in an error being return
to the relayer, which will then fail the corresponding incoming htlc.
2018-09-03 17:49:36 +02:00
Pierre-Marie Padiou
15c73273b6
Removed max body size in http client (#686)
* removed max body size in http client

This is required because since f3676c6497
we retrieve multiple full blocks in parallel.

* trivial: removed unused code

* trivial: added log

* trivial: more unused code removal
2018-08-31 15:46:41 +02:00
Fabrice Drouin
f0f8f0c24a
Add a "smooth" fee provider (#684)
* Add a "smooth" fee provider

It will return the moving average of fee estimates provided by
its internal fee provider, within a user defined window that can
be set with eclair.smooth-feerate-window. 

* Use a default fee rate smoothing window of 3

This should smooth our fee rate when there is a sudden change in
onchain fees and prevent channels with c-lightning node from getting
closed because they disagree with our fee rate.
2018-08-30 17:46:17 +02:00
rorp
e62f6ccdfd Use user-provided fee rate for funding tx (fixes #639)
Use user-provided fee rate for funding tx
2018-08-27 16:25:44 +02:00
Pierre-Marie Padiou
82973cdb76
Fixed some logs and added ChannelPersisted event (#674)
* ignore answers to CMD_UPDATE_FEE

* ignore BITCOIN_FUNDING_DEPTHOK in OFFLINE/SYNCING

* ignore BITCOIN_FUNDING_DEEPLYBURIED in OFFLINE/SYNCING

* improvements in eclair-cli:
   - Made default `channel`/`channels` outputs more useful.
   - Added support for timestamp filtering to `audit` and `networkfees`.

* added `ChannelPersisted` event
2018-08-15 14:39:19 +02:00
Pierre-Marie Padiou
952f94c2a8
Send query_short_channel_ids sequentially (#672)
and add a event to follow the synchronization progress.
2018-08-15 14:34:45 +02:00
Pierre-Marie Padiou
24db529d8b
Handle unknown remote commit in recovery logic (#667)
Our recovery logic didn't handle the case were our local commit is
up-to-date, but we don't know their local commit (probably because we
just lost the last state were we sent them a new `commit_sig`).

Also, process all cases in the same `channel_reestablish` handler, like we do
everywhere else.

Moved the sync tests in `Helpers` so that they are more understandable.
2018-08-10 12:27:09 +02:00
Pierre-Marie Padiou
f3676c6497
Get full blocks when looking for spending tx (#666)
* get full blocks when looking for spending tx

With a verbosity of `0`, `getblock` returns the raw serialized
block. It saves us from calling `getrawtransaction` for each transaction
in the block.

Fixes #664.
2018-08-03 12:17:09 +02:00
Pierre-Marie Padiou
6d5ec8c4fa
Fail unsigned outgoing htlcs at CLOSING (#660)
This can happen in an unilateral close scenario, when local commit
"wins" the race to the blockchain, and some outgoing htlcs weren't yet
signed by remote.

This fixes #649.
2018-07-31 16:04:55 +02:00
Pierre-Marie Padiou
75d23cf1b3
Audit: Keep track of sent/received/relayed payments and relay/network fees (#654)
Added a new `AuditDb` which keeps tracks of:
- every single payment (received/sent/relayed)
- every single network fee paid to the miners (funding, closing, and all commit/htlc transactions)

Note that network fees are considered paid when the corresponding tx has reached `min_depth`, it makes sense and allows us to compute the fee in one single place in the `CLOSING` handler. There is an exception for the funding tx, for which we consider the fee paid when the tx has successfully been published to the network. It simplifies the implementation and the tradeoff seems acceptable.

Three new functions have been added to the json-rpc api:
- `audit`: returns all individual payments, with optional filtering on timestamp.
- `networkfees`: returns every single fee paid to the miners, by type (`funding`, `mutual`, `revoked-commit`, etc.) and by channel, with optional filtering on timestamp.
- `channelstats`: maybe the most useful method; it returns a number of information per channel, including the `relayFee` (earned) and the `networkFee` (paid).

The `channels` method now returns details information about channels. It makes it far easier to compute aggregate information about channels using the command line.

Also added a new `ChannelFailed` event that allows e.g. the mobile app to know why a channel got closed.
2018-07-25 16:47:38 +02:00
rorp
924efeabe3 Fix Bitcoin JSON RPC client's rounding errors (#616)
* Fix Bitcoin JSON RPC client's rounding errors

* FundTransactionResponse fee field type is now Satoshi, fix Electrum tests

* BitcoinCoreFeeProvider: rework error handling code
2018-07-24 18:43:35 +02:00
Pierre-Marie Padiou
633deb5c0b
Send an event when an error occurs in a channel (#663)
This allows e.g. the mobile app to know why a channel got closed.
Depending on whether the error is local or remote, a
`Throwable`/`wire.Error` will be attached to the event.
2018-07-18 14:45:12 +02:00
Chris Stewart
fe82641e92 Clean up ExecutionContext/ActorSystem (#652)
This allows for a user of the library to implicitly pass the `ActorSystem` to the eclair node. Although if you are running multiple eclair instances on the same machine you need to make sure the `ActorSystems` that are passed implicitly are unique.
2018-07-16 14:25:20 +02:00
Fabrice Drouin
fef0df7607
Use "unsigned long" comparison for short channel ids (#656) 2018-07-16 12:18:38 +02:00
Fabrice Drouin
9f708acf04
Improve initial routing sync (#453)
* Implement new 'routing sync' messages

* add a new feature bit for channel queries

when we receive their init message and check their features:
- if they set `initial_routing_sync` and `channel_range_queries` we do nothing, we should receive a
range query shorly
- if they support channel range queries we send a range query

* Modify query_short_channel_id to ask for a range of ids

And not just a single id

* use `SortedMap` to store channel announcements

* don't send prune channels with channel range queries

* update range queries type to match BOLT PR

* add timestamp-based filters for gossip messages

each peer can speficy a `timestamp range` to filter gossip messages against.

* don't preserve order in `decodeShortChannelIds`

It is not needed and allows us to return a `Set`, which is better suited
to how we use the result.

* channel range queries: handle multi-message responses

Handle case where there are too many short ids to fit in a single message.

* channel range queries: use zlib instead of gzip

but detect when a message was encoded with gzip and reply with gzip in that case.

* router: add more channel range queries logs

* Channel range queries: correctly set firstBlockNum and numberOfBlocks fields

* channel range queries: properly handle case where there is no data

we will just receive on byte (compression format)

* channel range queries: use their compression format to query channels

when we query channels with `query_short_channel_ids`, we now use the same compression
format as in their `repy_channel_range` message. So we should be able to communicate
with peers that have not implemented all compression formats.

* router: make sure that channel ids are sorted

For channel range queries to work properly, channel ids need to be sorted.
It is then much more efficient to use a sorted map in our router state.

* always use `keySet` instead of `keys`

`SortedMap`.`keySet` returns a `SortedSet`, whereas `SortedMap`.`keys`
returns an `Iterable`. This is a critical difference because channel
range queries has requirements on ordering of channel ids.

Using the former allows us to rely on type guarantees instead of on
assumptions that the `Iterable` is sorted in `ChannelRangeQueries`.

There is no cost difference as internally the `Iterator` is actually a
`SortedSet`.

Also, explicitely specified the type instead of relying on comments in
`Router`.

* publish channel update event on router startup

* channel range queries: use uint32 for 4-byte integers (and not int32)

* channel range queries: make sure we send at least one reply to `query_channel_range`

reply to `query_channel_range` messages for which we have no matching channel ids
with a single `reply_channel_range` that contains no channel ids.

* channel range queries: handle `query_channel_range` cleanly

add an explicit test when we have no matching channel ids and send back a reply with an
empty (uncompressed) channel ids payload

* channel range queries: rename GossipTimeRange to GossipTimestampFilter

* channel range queries: add gossip filtering test

* peer: forward all routing messages to the router

and not just channel range queries. this should not break anything and if
it does it would reveal a problem

* peer: add remote node id to messages sent to the router

this will improve logging and debugging and will help if we implement
banning strategies for mis-behaving peers

* router: filter messages with a wrong chainHash more cleanly

* channel range queries: set a "pass-all" timestamp filter

* router: remove useless pattern match

ChannelUpdates are wapped in a PeerRoutingMessage now

* Peer: fit typo in comment

* Peer: optimize our timestamp filter

* Router: use mdc to log remote node id when possible

* fix typos and improve log message formatting

* Peer: rephrase scala doc comment that breaks travis

* Peer: improve timestamp filtering + minor fixes

* Electrum tests: properly stop actor system at the end of the test

* Peer: filter out node announcements against our peer's timestamp

But we don't prune node annoucements for which we don't have a matching
channel in the same "rebroadcast" message
2018-07-12 21:36:57 +02:00
Pierre-Marie Padiou
5ea623ae8c
Relay payments to channel with highest balance (#648)
* relay htlcs to channels with the highest balance

In order to reduce unnecessary back-and-forth in case an outgoing
channel doesn't have enough capacity but another one has, the relayer
can now forward a payment to a different channel that the one specified
in the onion (to the same node of course).

If this preferred channel returns an error, then we will retry to the original
requested channel, this way if it fails again, the sender will always receive 
an error for the channel she requested.
2018-07-09 12:36:11 +02:00
nayuta-gondo
5ad65063a0 Set MIN_CLTV_EXPIRY to 9 as per BOLT 11 (#650) 2018-07-09 11:17:32 +02:00
Pierre-Marie Padiou
86e91f76fc
Added context to logs (#638)
* improved logs on sig sent/received

* put 'sent announcements' log in debug

* added logging of IN/OUT wire messages

* added mdc support to IO classes

* reduced package length to 24 chars in logs
2018-07-02 18:25:19 +02:00
Fabrice Drouin
923d8661f8
Electrum: add wallet and watcher tests (via Docker) (#592)
* add basic electrum wallet test

our wallet connects to a dockerized electrumx server

* electrum: clean up tests, and add watcher docker tests

* electrum wallet: fix balance computation issue

when different keys produced the exact same confirmed + unconfirmed balances, we
would compute an invalid balance because these duplicates would be pruned.

* electrum: rename wallet test

* electrum: add a specific test with identical outputs

* electrum: change scripthash balance logging level to debug

* electrum: make docker tests run on windows/mac

Our electrumx docker container needs to contains to bitcoind that is running on the host.
On linux we use the host network mode, which is not available on windows/osx
On windows/osx we use host.docker.internal, which is not available on linux. This
requires docker 18.03 or higher.
2018-06-27 14:34:02 +02:00
sstone
a74a62b359
Revert "electrum: make docker tests run on windows/mac"
This reverts commit eecddcb340.
2018-06-27 14:26:00 +02:00
sstone
eecddcb340
electrum: make docker tests run on windows/mac
Our electrumx docker container needs to contains to bitcoind that
    is running on the host.
    On linux we use the host network mode, which is not available on windows/osx
    On windows/osx we use host.docker.internal, which is not available on linux. This
    requires docker 18.03 or higher.

    electrum: change scripthash balance logging level to debug

    electrum: add a specific test with identical outputs

    electrum: rename wallet test

    electrum wallet: fix balance computation issue

    when different keys produced the exact same confirmed + unconfirmed balances, we
    would compute an invalid balance because these duplicates would be pruned.

    electrum: clean up tests, and add watcher docker tests

    add basic electrum wallet test

    our wallet connects to a dockerized electrumx server
2018-06-26 23:12:48 +02:00
Dominique
2d829d40eb
Can generate payment request with extra routing information (#637)
* `ReceivePayment` now accepts additional routing info, which is useful for nodes that are not announced on the network but still want to receive funds.
2018-06-26 18:35:22 +02:00
rorp
71e50520ec Proper parsing of public-ips config parameter
* Fix scala.NotImplementedError when public-ips config parameter contains invalid values

* more comprehensive validations

* fix unit tests

This fixes #630
2018-06-26 18:15:01 +02:00
sstone
cd6524e25b
set version to 0.2-SNAPSHOT 2018-06-20 09:45:09 +02:00
sstone
8aa51f4e02
set version to 0.2-beta5 2018-06-20 09:21:05 +02:00
Pierre-Marie Padiou
a9348f0774
Check when relay fee is insufficient (#634)
We should return a `FeeInsufficient` error when an incoming htlc doesn't
pay us what we require in our latest `channel_update`.

Note that the spec encourages us to being a bit more lax than that (BOLT
7):

> SHOULD accept HTLCs that pay an older fee, for some reasonable time
after sending channel_update.

>    Note: this allows for any propagation delay.
2018-06-19 16:58:40 +02:00
n1bor
b7b9f4929a Add api call to update channel relay fees (#620)
* add api call to update channel relay fees

* fixed bug in GUI, as channel can had different fees in each direction!

* fire transitions on `TickRefreshChannelUpdate` (fixes #621)

* make router publish `channel_update`s on startup

* (gui) Channel info fees are now options and case where channels have no known fees data is now properly handled.
2018-06-19 14:09:37 +02:00
n1bor
b3731adabd Adding ability to set expiry when creating a new invoice (#632) 2018-06-19 13:13:07 +02:00
Fabrice Drouin
5afd9fa035
Add missing BOLT 2 checks (fixes #613) (#618)
* rename InvalidDustLimit to DustLimitTooSmall
* make sure that our reserve is above our dust limit
* check that their accept message is valid

see BOLT 2:
- their channel reserve must be above their dust limit
- their channel reserve must be above our dust limit
- their dust limit must be below our reserve

* channel: check to_local and to_remote amounts againt channel_reserve_satoshis

see BOLT 2: The receiving node MUST fail the channel if both to_local and to_remote amounts for
the initial commitment transaction are less than or equal to channel_reserve_satoshis (see BOLT 3).

* channel: check that their open.max_accepted_htlcs is valid
2018-06-18 19:06:14 +02:00
Fabrice Drouin
3a38c734ed
Routing: remove final CLTV expiry check on outgoing HTLCs (#627)
Checking the final CLTV expiry makes sense when we receive a payment, but
not when we're sending one
2018-06-14 10:28:45 +02:00
sstone
a85ba9ceef
set version to 0.2-SNAPSHOT 2018-05-30 19:15:06 +02:00
sstone
e6fe077582
set version to 0.2-beta4 2018-05-30 19:11:44 +02:00
Dominique
e1b884c58d Add server address in ElectrumReady object (#556)
* Added server address in ElectrumReady object

* Assigned remote address to variable to improve readability

* Checking that the master address exists in the addresses map
2018-05-30 18:53:07 +02:00
Anton Kumaigorodski
d75788039a Inform clients about incoming payments via websocket connection (#610) 2018-05-30 15:20:55 +02:00
Fabrice Drouin
3bf8db3f26
Set a minimum feerate-per-kw of 253 (fixes #602) (#608)
* set a minimum feerate-per-kw of 253 (fixes #602)

why 253 and not 250 since feerate-per-kw is feerate-per-kb / 250 and the minimum relay fee rate is 1000 satoshi/Kb ?

because bitcoin core uses neither the actual tx size in bytes or the tx weight to check fees, but a "virtual size" which is (3 * weight) / 4 ...

so we want :
fee > 1000 * virtual size
feerate-per-kw * weight > 1000 * (3 * weight / 4)
feerate_per-kw > 250 + 3000 / (4 * weight)

with a conservative minimum weight of 400, we get a minimum feerate_per-kw of 253

* set minimum fee rate to 2 satoshi/byte

users can still change it to 1 satoshi/byte

* use better weight estimations when computing fees

* test that tx fees are above min-relay-fee

* check that remote fee updates are above acceptable minimum

we need to check that their fee rate is always above our absolute minimum threshold
or we will end up with unrelayable txs

* fix ClaimHtlcSuccessTx weight computation

* channel tests: use actual minimum fee rate

test with our absolute minimum fee rate (253), it should be valid and anything below
sould be invalid and trigger and specific error
2018-05-30 13:38:40 +02:00
Fabrice Drouin
7b5b665fe9
Update electrum testnet server list, and fix flaky client pool tests (#609)
* electrum: update testnet server list

* electrum: filter out onion addresses

* electrum pool test: wait until we have a stable master server
2018-05-25 11:47:23 +02:00
araspitzu
db43747d2b Filter out non-spendable outputs from bitcoind 'listunspent' call during setup (#605)
Fixes #599
2018-05-22 12:36:01 +02:00
pm47
644b4a2a98
back to SNAPSHOT 2018-05-18 15:53:02 +02:00
pm47
1dd8aa5aab
set version to 0.2-beta3 2018-05-18 15:14:52 +02:00
Fabrice Drouin
75437cbe81
electrum wallet: fix balance computation issue (#600)
Electrum wallet: fix balance computation issue
2018-05-18 12:58:48 +02:00
Gustavo Fernandes
f983160288 Increase startup timeout (#577) (#590) 2018-05-18 11:55:53 +02:00
Fabrice Drouin
3058ce343d
Update Sphinx test vectors (#593)
We were still using payloads with 32 bits amounts instead of 64 bits.
See https://github.com/lightningnetwork/lightning-rfc/pull/372
2018-05-18 11:55:31 +02:00
Anton Kumaigorodski
588eae93a9 Enforce min feerate per byte on regtest (#595) 2018-05-18 11:55:11 +02:00
Pierre-Marie Padiou
d95cdc5ebe
Fixed conversion: 1 BTC = 1e8 satoshis (#589)
Fixes #585
2018-05-04 18:16:30 +02:00
Pierre-Marie Padiou
d9f69bd563
Cache serialized network announcements (#588)
Because we keep sending them over and over.

Using `CacheBuilder.weakKeys` will cause the serialized messages to be
cleaned up when messages are garbage collected, hence there is no need
to set a maximum size.
2018-05-04 17:32:03 +02:00
Fabrice Drouin
d3244c8499
electrum wallet: export xpub (#586) 2018-05-04 15:06:27 +02:00
Pierre-Marie Padiou
7c12a7fecf
Check if closing tx is known before handling it (#587)
If the closing tx is already in `mutualClosePublished`, it means that we
already know about it and don't need to re-handle it again. Everytime we
succesfully negotiate a mutual close, we end up publishing ourselves the
closing tx, and right after that we are notified of this tx by the
watcher. We always ended up with duplicates in the
`mutualClosePublished`field.

This fixes #568.
2018-05-04 14:46:36 +02:00
rorp
30155f3262 Remove utxo lock when call to signrawtransaction fails (#579)
Also add `timefactor`=3 in tests.

This fixes #567.
2018-05-04 14:14:01 +02:00
Anton Kumaigorodski
e05cb6d928 Use fallbackAddress tag in PaymentRequest builder (#581) 2018-05-04 11:30:54 +02:00
Anton Kumaigorodski
96e6df9df2 Add configurable min funding satoshis limit (#580)
* Add configurable min funding satoshis limit

* Update parameters
2018-05-03 14:56:07 +02:00
Fabrice Drouin
2d0564b9f8
Update bitcoin-lib to 0.9.17 (#582)
* use bitcoin-lib 0.9.17

* use Long values in BIP32 key path
2018-05-03 14:53:59 +02:00