Commit Graph

110 Commits

Author SHA1 Message Date
Rusty Russell 30faf96efb lightningd: don't complain about unable to estimate fees if not mainnet.
'force-feerates' already bypasses this logic, but we should still suppres

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-07-09 07:26:09 +09:30
Rusty Russell adab9eb301 lightningd: add force-feerates option.
Useful for regtest and testnet.  Sure, you shouldn't use this on mainnet,
but I haven't restricted it because our users are usually pretty clever.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Fixes: #1806
Changelog-Added: config: `force_feerates` option to allow overriding feerate estimates (mainly for regtest).
2021-07-09 07:26:09 +09:30
Jan Sarenik 1b02d15695 typo: information is an uncountable mass noun
See https://en.wikipedia.org/wiki/Information

In libplugin.c also the word "details" was added (without removing
the 'information').

Changelog-None
2021-03-16 10:45:40 +10:30
Rusty Russell 5eb209f57a bitcoind: remove v0.9.0-compat for rejecting sendrawtransaction arg.
Changelog-Removed: `bcli` replacements must allow `allowhighfees` argument (deprecated 0.9.1).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-02-01 09:57:35 +10:30
Rusty Russell 3b7d0e7a62 common/json: make json_scan return an error string.
This makes for more useful errors.  It prints where it was up to in
the guide, but doesn't print the entire JSON it's scanning.

Suggested-by: Christian Decker
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-01-07 19:32:47 +01:00
Rusty Russell 53582a0f81 lightningd/bitcoind: use json_scan.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-01-07 19:32:47 +01:00
Rusty Russell 9f687d60d9 lightningd: forward notifications from plugins if enabled.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-10-23 13:53:16 +10:30
Moller40 4d672077e1 Avoid compile error on macos mojave
Fixing the following error by changing 'enum feerate' to int.

lightningd/bitcoind.c:183:29: error: result of comparison of constant
8 with expression of type 'enum feerate' is always true [-Werror,
-Wtautological-constant-out-of-range-compare]
        for (enum feerate f = 0; f < NUM_FEERATES; f++) {

Changelog-Fixed: compile error on macos
2020-09-09 20:43:27 +09:30
ZmnSCPxj jxPCSnmZ ee276bcb86 plugins/bcli.c: `sendrawtransaction` now has a required `allowhighfees` argument.
Changelog-Deprecated: plugin: `bcli` replacements should note that `sendrawtransaction` now has a second required Boolean argument, `allowhighfees`, which if `true`, means ignore any fee limits and just broadcast the transaction. Use `--deprecated-apis` to use older `bcli` replacement plugins that only support a single argument.
2020-09-09 12:38:19 +09:30
Rusty Russell b592d6fd8f lightningd: fix race where we do rescan before all plugins finish init.
The symptom (under heavy load and valgrind) in test_plugin_command:

	lightningd: common/json_stream.c:237: json_stream_output_: Assertion `!js->reader' failed.

This is because we try to call `getmanifest` again on `pay` which has not yet
responded to init.

The minimal fix for this is to keep proper state, so we can tell the
difference between "not yet called getmanifest" and "not yet finished
init".

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-05-05 13:45:17 +09:30
Sebastian Falbesoner 01c8942581 lightningd/bitcoind: remove unused BITCOIN_INIT_TIMEOUT
The define is a leftover from the init fixed timeout hack that was
removed recently (commit 678591d851).
2020-05-04 10:47:24 +09:30
Antoine Poinsot 678591d851 lightningd/bitcoind: always die if the Bitcoin backend died
This in addition removes the init fixed timeout hack.

Changelog-fixed: We now *always* die if our Bitcoin backend failed unexpectedly.
Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
2020-04-30 19:27:54 -05:00
Antoine Poinsot 7ea1a8a182 lightningd/bitcoind: remove an outdated comment
Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
2020-04-30 19:27:54 -05:00
darosior 610aa0b8e3 bcli: register --dev-max-fee-multiplier on our side
That way we pass the real min_acceptable (SLOW/2) and max_acceptable
(URGENT * 10) feerates to lightningd.
2020-03-30 20:17:18 +10:30
darosior d4fe4073a4 lightning/bitcoind: adapt and batch fees estimations
This adapts our fee estimations requests to the Bitcoin backend to the
new semantic, and batch the requests.

This makes our request for fees much simpler, and leaves some more
flexibility for a plugin to do something smart (it could still lie before
but now it's explicit, at least.) as we don't explicitly request
estimation for a specific mode and a target.

Changelog-Changed: We now batch the requests for fee estimation to our Bitcoin backend.
Changelog-Changed: We now get more fine-grained fee estimation from our Bitcoin backend.
2020-03-30 20:17:18 +10:30
darosior 06e9a9f31f bitcoind: check that Bitcoin plugin is alive before requesting 2020-03-11 16:01:36 -05:00
darosior 1fd45a061b bitcoind: timeout if the Bitcoin plugin never completes the handshake
Reported-by: Vasil Dimov <@vasild>
2020-03-05 15:06:38 -06:00
darosior a47fd8cf3e pytest: test Bitcoin plugin registration and the bcli plugin 2020-02-12 11:45:07 +10:30
darosior 580556b1d0 lightningd/bitcoind: remove all bitcoin-cli specific code
Changelog-Added: pluggable backends for Bitcoin data queries, default still bitcoind (using bitcoin-cli).
2020-02-12 11:45:07 +10:30
darosior ced444a605 lightningd/bitcoind: use the Bitcoin plugin for fee estimates
And remove bitcoin-cli interaction code, now unused.
2020-02-12 11:45:07 +10:30
darosior c79ab0f1b0 lightningd/bitcoind: use the Bitcoin plugin for getutxout 2020-02-12 11:45:07 +10:30
darosior 78cb921b80 lightningd/bitcoind: use getrawblockatheight for getfilteredblock
This avoids the getblockhash+getblock, and more importantly that was the
last functionality making use of bitcoind_getrawblock() and bitcoin_getblockhash(),
so we can also get rid of them.
2020-02-12 11:45:07 +10:30
darosior 947f5ddde1 lightningd/bitcoind: use the Bitcoin plugin to send transactions
This restrains the informations we get about how the sending went to
an errmsg as we cant rely on bitcoin-cli specific output nor its exit code.
2020-02-12 11:45:07 +10:30
darosior 7b18b24e39 lightningd/chaintopology: use plugin backend to setup topology
This adds `getchaininfo` and `getrawblockbyheight` handling lightningd-side,
and use them in setup_topology().

We then remove legacy bitcoind_getblockcount() (we already get the count in
`getchaininfo`), bitcoind_getblockchaininfo() (it was only used in setup_topology()),
and wait_for_bitcoind() (this was specific to bitcoin-core and we assume our Bitcoin
backend to be functional if the plugin responds to `init`).
2020-02-12 11:45:07 +10:30
darosior 2b75a46a6c chaintopology: dont check bitcoin-core version at startup
The Bitcoin backend is generalized through the Bitcoin plugin and this
was specific to core.
2020-02-12 11:45:07 +10:30
darosior 3e8a782da7 bitcoind: initialize Bitcoin-backend plugin early
We need our Bitcoin backend to be initialized, but the plugins have not yet been
started at this point.
2020-02-12 11:45:07 +10:30
darosior c4ff960b74 bitcoind: allow commands to be registered by different plugins
An strmap is convenient to get a plugin given a method. Populate it
while checking commands.
2020-02-12 11:45:07 +10:30
darosior ae249a2294 chaintopology: check bitcoin plugin commands at startup
Exit early if we won't be able to fully communicate with our Bitcoin
backend.
2020-02-12 11:45:07 +10:30
Vasil Dimov 2ea91f834c Add the missing space between "if" and "("
Changelog-None
2020-01-06 12:57:59 +01:00
darosior 5baf39e7dc lightningd/bitcoind: remove unused 'get_output' function
Along with its callbacks.
2020-01-02 17:20:43 +01:00
Rusty Russell 654faa6174 lightningd: don't start if bitcoind is behind.
This leads to all sorts of problems; in particular it's incredibly
slow (days, weeks!)  if bitcoind is a long way back.  This also changes
the behaviour of a rescan argument referring to a future block: we will
also refuse to start in that case, which I think is the correct behavior.

We already ignore bitcoind if it goes backwards while we're running.

Also cover a false positive memleak.

Changelog-Fixed: If bitcoind goes backwards (e.g. reindex) refuse to start (unless forced with --rescan).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-11-21 05:18:29 +00:00
darosior f075b87137 bitcoind: remove the chainparams member
We now have a global constant, prefer to use it instead of having
two variables with the same utility.
2019-11-15 13:14:08 +01:00
Rusty Russell f4d888ec7e lightningd: obscure sensitive bitcoin args when bitcoind unreachable.
It's less helpful, sure, but it's far better than someone
sending me their output and leaking this information.

Fixes: #3242
Reported-by: @JavierRSobrino
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-11-05 16:47:52 +01:00
Christian Decker 7283efa5b5 elements: Add amount_asset to support more than just plain satoshis
Currently the only source for amount_asset is the value getter on a tx output,
and we don't hand it too far around (mainly ignoring it if it isn't the
chain's main currency). Eventually we could bubble them up to the wallet, use
them to select outputs or actually support assets in the channels.

Since we don't hand them around too widely I thought it was ok for them to be
pass-by-value rather than having to allocate them and pass them around by
reference. They're just 41 bytes currently so the overhead should be ok.

Signed-off-by: Christian Decker <@cdecker>
2019-10-03 04:32:57 +00:00
Christian Decker 8b8538024d bitcoind: Defer initialization of filteredblock_call->result
During sync it is highly likely that we can coalesce multiple calls and share
results among them. We also report back failures for non-existing blocks early
on, so we don't run into issues with blocks that our bitcoind doesn't have
yet.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-08-20 00:07:38 +00:00
Rusty Russell faded9a9cf bitcoind: detect when it's still syncing, add field to getinfo.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-08-10 22:09:09 +02:00
Rusty Russell 69b7ef1508 lightningd: fix up typesafe-cb bitcoind_getfilteredblock
`const struct filteredblock *` everywhere, as the typesafe_cb_preargs
macro required.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-08-09 02:31:51 +00:00
Rusty Russell 99236f86f9 lightningd: rename 'satoshis' to 'amount' to avoid confusing check-source.
The type is enough (it's a struct amount_sat) to avoid confusion with
btc or msats.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-08-09 02:31:51 +00:00
Christian Decker 95d891ebf1 bitcoind: Queue up calls to getfilteredblock and dispatch results
Instead of allowing all calls to `getfilteredblock` to be scheduled on the
`bitcoind` queue right away we instead add them in a separate queue, and
process a single call at a time. This limits the concurrency and avoids
thrashing `bitcoind`. At the  same time we dispatch incoming results back to
all calls that were queued for that particular blockheight, reducing the
overall number of calls and an increase in overall speed.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-08-09 02:31:51 +00:00
Christian Decker 040cda2875 bitcoind: Initialize filteredblock->outpoints with filteredblock
We will be calling the callback out of order once we fan out the results of a
single lookip to multiple calls, so being sure that everything is allocated
ahead of time is necessary.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-08-09 02:31:51 +00:00
Christian Decker 43b3eea783 bitcoind: Don't log when a transaction output is detected as spent
Since we now check all P2WSH outputs in a block, this is getting quite a
common occurence, so logging just produces lots of noise.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-08-09 02:31:51 +00:00
Christian Decker f4e434d8e1 bitcoind: Add a multi-step getfilteredblock method
This will eventually replace the multi-step `getblockhash` + `getblock` +
`gettxout` mechanism, and return entire filtered blocks which can be added to
the DB, and represent the full set of P2WSH UTXOs.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-08-09 02:31:51 +00:00
Christian Decker d14bd286ba bitcoin: Add chainparams to transactions from blocks
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-07-31 23:22:54 +00:00
trueptolemy 130bf20516 lightningd: check bitcoind version when `setup_topology` 2019-07-30 17:38:54 +08:00
Rusty Russell 57b2fe5890 lightningd: fix fatal error on startup if bitcoind isn't ready.
At the moment we simply get a crypto log line on exit:

  bitcoin-cli getblockchaininfo: invalid response

Fixes: 6deed77d88
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-07-26 10:27:01 +00:00
ZmnSCPxj bb301040e4 lightningd/options.c: Add option for setting how long to keep trying bitcoin-cli command. 2019-07-18 18:59:11 +02:00
trueptolemy 6deed77d88 bitcoind: confirm chain with bitcoin-cli at the beginning
At the beginning of the lightningd, we use "echo" command to check if bitcoin-cli is running.
Now we raplace "echo" with "getblockchaininfo" for this check, and also check whether the "chain" field in response is same as the blockchain that  lightningd is on.
"getblockchaininfo" is also valid for litecoin-cli.
2019-07-04 16:13:09 +02:00
trueptolemy a594196c7c bitcoin-cli: rename bcli_args() to bcli_args_direct(), and also warp it in bcli_args()
1. bcli_args_direct() will be used in wait_for_bitcoind;
At the beginning, we check if bitcoin-cli is running by "echo" command
whitout any bitcoin_cli struction. If this first command fails, we need
present the agrs gathered, like "-rpcuser", like "-rpcpassword".
Related changes include:
  i) rename bcli_args() to bcli_args_direct(), and use 'const char **'
      as the paramater for bcli_args_direct();
  ii) add a new function bcli_args() warpped on bcli_args_direct(), this
      warpping can reduce the large number of changes later in the file;
2. bcli_args() warpping on bcli_args_direct() is used like original.
2019-07-04 16:13:09 +02:00
Rusty Russell d5bd1682f5 lightningd: free timers on shutdown.
Direct leak of 1024 byte(s) in 2 object(s) allocated from:
    #0 0x7f4c84ce4448 in malloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10c448)
    #1 0x55d11b782c96 in timer_default_alloc ccan/ccan/timer/timer.c:16
    #2 0x55d11b7832b7 in add_level ccan/ccan/timer/timer.c:166
    #3 0x55d11b783864 in timer_fast_forward ccan/ccan/timer/timer.c:334
    #4 0x55d11b78396a in timers_expire ccan/ccan/timer/timer.c:359
    #5 0x55d11b774993 in io_loop ccan/ccan/io/poll.c:395
    #6 0x55d11b72322f in plugins_init lightningd/plugin.c:1013
    #7 0x55d11b7060ea in main lightningd/lightningd.c:664
    #8 0x7f4c84696b6a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x26b6a)

To fix this, we actually make 'ld->timers' a pointer, so we can clean
it up last of all.  We can't free it before ld, because that causes
timers to be destroyed.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-06-30 16:41:30 +09:30
Jeff Vandrew Jr 1130100f67 Remove Sensitive RPC Data from Logs (#2520)
Fixes: #2424
2019-04-03 03:06:06 +00:00