Commit Graph

218 Commits

Author SHA1 Message Date
Rusty Russell 9b9e830780 lightningd: attach plugins natively to the command which started it.
This will let us unify the startup and runtime-started infrastructure.

Note that there are two kinds of notifications:
1. Starting a single plugin (i.e. `plugin start`)
2. Starting multiple plugins (i.e. `plugin rescan` or `plugin startdir`).

In the latter case, we want the command to complete only once *all*
the plugins are dead/finished.

We also call plugin_kill() in all cases, and correctly return afterwards
(it matters once we use the same paths for dynamic plugins, which don't
cause a fatal error if they don't startup).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-05-05 13:45:17 +09:30
Rusty Russell 2f1502abf4 cleanup: make 'u8 *features' and 'struct feature_set *fset' more explicit.
It's almost always "their_features" and "our_features" respectively, so
make those names clear.

Suggested-by: @cdecker
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-04-03 13:13:21 +10:30
Rusty Russell 07a281faf8 lightningd: add large-channels / wumbo option.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-added: `large-channels` option to negotiate opening larger channels.
2020-04-03 13:13:21 +10:30
Rusty Russell cf43e44378 common/features: don't use internal global.
Turns out that unnecessary: all callers can access the feature_set,
so make it much more like a normal primitive.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-04-03 13:13:21 +10:30
Rusty Russell c95e58ad4b subdaemons: initialize feature routines with explicit feature_set.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-03-31 13:36:02 +02:00
Rusty Russell afb76392e4 common/features: use bitmaps internally, have explicit init function.
This is to prepare for dynamic features, including making plugins first
class citizens at setting them.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-03-31 13:36:02 +02: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
lisa neigut 42cce55b45 plugins: add 'flag' type for plugin options
Updates the plugin docs to include more detailed info about how options
work.

Changelog-Added: Plugins: 'flag'-type option now available.
2020-03-21 16:29:52 +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
Ken Sedgwick 5fd0ed79f4
lightningd: Added --subdaemon command to allow alternate subdaemons.
Changelog-Added: lightningd: Added --subdaemon command to allow alternate subdaemons.

[ Wow, that was mammoth; 44 comments over 12 commits. Feels almost unfair to squash it into one commit, so I wanted to note @ksedgwic's perseverence here! --RR ]
2020-02-04 10:44:13 +10:30
Rusty Russell c11212bb52 pytest: test that we handle WIRE_UPDATE_FAIL_MALFORMED_HTLC correctly.
We could use sendonion to do this, but it actually takes a different path through
pay, and I wanted to test all of it, so I made a new dev flag.

We currently get upset with the response:

	lightningd/pay.c:556: payment_failed: Assertion `!hout->failcode' failed.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-01-29 21:15:25 +01:00
Rusty Russell e379528254 lightningd: fix memleak false positive.
json_listconfigs() returns in the middle; the name0 is not always freed.

It will be freed later with the response, but our memleak detection doesn't
know that, and Travis caught it:

           Global errors:
E            - Node /tmp/ltests-5mfrzh5v/test_hsmtool_secret_decryption_1/lightning-1/ has memory leaks: [
E               {
E                   "backtrace": [
E                       "ccan/ccan/tal/tal.c:437 (tal_alloc_)",
E                       "ccan/ccan/tal/tal.c:466 (tal_alloc_arr_)",
E                       "ccan/ccan/tal/tal.c:794 (tal_dup_)",
E                       "ccan/ccan/tal/str/str.c:32 (tal_strndup_)",
E                       "lightningd/options.c:1122 (add_config)",
E                       "lightningd/options.c:1282 (json_listconfigs)",
E                       "lightningd/jsonrpc.c:588 (command_exec)",
E                       "lightningd/jsonrpc.c:679 (rpc_command_hook_callback)",
E                       "lightningd/plugin_hook.c:123 (plugin_hook_call_)",
E                       "lightningd/jsonrpc.c:729 (plugin_hook_call_rpc_command)",
E                       "lightningd/jsonrpc.c:736 (call_rpc_command_hook)",
E                       "common/timeout.c:39 (timer_expired)",
E                       "lightningd/io_loop_with_timers.c:32 (io_loop_with_timers)",
E                       "lightningd/lightningd.c:871 (main)"
E                   ],
E                   "label": "lightningd/options.c:1122:char[]",
E                   "parents": [
E                       "lightningd/json_stream.c:49:struct json_stream",
E                       "ccan/ccan/io/io.c:91:struct io_conn",
E                       "lightningd/lightningd.c:104:struct lightningd"
E                   ],
E                   "value": "0x5569ada057a8"
E               }
E           ]

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-01-28 13:13:12 +01:00
Rusty Russell 387cd400d4 lightningd: remove lightning-rpc file on migration.
Fixes: #3378
Closes: #3379
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-01-28 13:12:19 +01:00
nicolas.dorier 06c5663f75 Do not move the socket file on migration 2020-01-28 13:12:19 +01:00
ZmnSCPxj jxPCSnmZ 7f4ed54b46 lightningd/jsonrpc.c: Set JSON-RPC socket permissions by command line.
Changelog-Added: Can now set the permissions on the JSON-RPC socket by `--rpc-file-mode`.
2020-01-27 21:11:57 +01:00
Vasil Dimov 2ea91f834c Add the missing space between "if" and "("
Changelog-None
2020-01-06 12:57:59 +01:00
Saibato f6006f43a9 Init commit to be able to create a tor static service on the fly.
We  want to have a static Tor service created from a blob bound to
our node on cmdline

Changelog-added: persistent Tor address support
Changelog-added: allow the Tor inbound service port differ from 9735

Signed-off-by: Saibato <saibato.naga@pm.me>

Add base64 encode/decode to common

We need this to encode the blob for the tor service

Signed-off-by: Saibato <saibato.naga@pm.me>
2019-12-03 23:35:18 +01:00
Rusty Russell 7f36a4e3dd lightningd: fix reference to out-of-scope var.
cppcheck found this:

	[lightningd/options.c:1137] -> [lightningd/options.c:1120] -> [lightningd/options.c:1193]: (error) Using pointer to local variable 'buf' that is out of scope.

Indeed, answer can point into buf, which is no longer in scope at the end.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-12-02 09:44:39 +01:00
Christian Decker c84473f82c hsm: Stabilize the hsm encryption and decryption tests
We were using sleeps to hope we catch the password prompt. This makes the test
flaky. So I added a help text followed by a `fflush` to make sure we catcht he
right moment, instead of guessing. The `fflush` is also useful for debugging
if a user ever pipes the output to a file it'd get buffered and the user would
wait forever. The same applies for automated systems such as `expect` or
`pexpect` based scripts that enter the password on prompt.
2019-11-29 15:06:39 +01:00
Rusty Russell 14997f6237 lightningd: fix handling of truncated config options.
Do the same thing '--help' does with them; append `...`.

Valgrind noticed that we weren't NUL-terminarting if answer was over
78 characters.

Changelog-Fixed: JSONRPC: listconfigs appends '...' to truncated config options.
2019-11-23 22:42:34 +00:00
Rusty Russell 747bb99575 lightningd: keep pid files in top-level config dir.
They're already qualified with network name, and there's little point
moving them; it might even be dangerous if multiple are running.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-11-23 22:42:34 +00:00
Rusty Russell e3dbd78536 config: explicitly disallow nonsensical options.
1. "conf" can't be specified in a configuration file.
2. "lightning-dir" can't be specified in a configuration file unless the file
   was explicitly set with --conf=.
3. "network" options can't be set in a per-network configuration file.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-11-23 22:42:34 +00:00
Rusty Russell a56f2b25b0 common: parse --allow-deprecated-apis extremely early.
We're going to want this for changing the default network.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-11-23 22:42:34 +00:00
Rusty Russell d512bcb85f lightningd: automatically move files for existing deployments.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-11-23 22:42:34 +00:00
Rusty Russell aab83e729b lightningd: change config-dir from plugin / wallet / hsm POV into <network> subdir
Changelog-changed: .lightningd plugins and files moved into <network>/ subdir
Changelog-changed: WARNING: If you don't have a config file, you now may need to specify the network to lightning-cli
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-11-23 22:42:34 +00:00
Rusty Russell dc23c308e4 config: Read both top-level and network-subdir config files.
This lets you have a default, but also a network-specific config.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-changed: Options: `config` and <network>/`config` read by default.
2019-11-23 22:42:34 +00:00
Rusty Russell 8b1aa3ef8b lightningd: move basic parameter parsing into common/configdir
lightning-cli is going to need to know what network we're on, so
it will need to parse the config files.  Move the code which does
the initial bootstrap parsing into common, as well as the config
file parsing core.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-11-23 22:42:34 +00:00
Rusty Russell 34c89cb226 config: Add include directive support.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Config: configuration files now support `include`.
2019-11-23 22:42:34 +00:00
Rusty Russell 0607f998d1 options: allow --log-level <level>:<prefix> for finegrained log control.
This allows finegrained logging control of particular subdaemons or
subsystems.

To do this, we defer setting the logging levels for each log object
until after early argument parsing (since e.g. "bitcoind" log object
is created early).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-changed: Options: log-level can now specify different levels for different subsystems.
2019-11-18 04:50:22 +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 323e4f6288 dev: add option to prevent HTLC timeouts.
This is required for the protocol tests, which can be slow.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-11-14 10:19:01 +01:00
lisa neigut 28cdccfb11 dev: add option flag for specifying temporary channel id
--dev-force-tmp-channel-id flag takes a 64-character hex string
to use as the temporary channel id. Useful for spec tests

[ Fixed crash in non-DEVELOPER mode --RR ]
Changelog-None
2019-11-13 05:51:02 +00:00
gorazdko 122fc1f26f config file: fix line count in error message 2019-11-08 00:22:03 +00:00
darosior f89d7c1d74 hsm encryption: correct salt length 2019-10-17 15:51:55 +02:00
darosior 3c038e4171 hsm encryption: don't include '\n' when deriving the encryption key 2019-10-17 15:51:55 +02:00
darosior a698395bf0 lightningd: '--encrypted-hsm', a new startup option
Add a new startup option which will, if set, prompt the user for a
password to derive a key from. This key will later be used to encrypt
and/or decrypt `hsm_secret`.

This was made a noarg option even if it would have been preferable to
let the user the choice of how to specify the password. Since we have
to chose, better to not let the password in the commands history.
2019-10-09 22:00:38 -05:00
darosior 65479ab308 config: make config_dir absolute
This makes it easier for DB drivers and plugins
2019-10-08 22:43:30 +00:00
Saibato b3a6279392 Allow --announce-addr to work also with autotor: prefix
Make --announce-addr with autotor: also
a meaningful use case.
The option  --announce-addr=autotor: is more
intuitive than to use the --addr=autotor: option

Signed-off-by: Saibato <saibato.naga@pm.me>

Declare opt_add_addr at top of option.c

We we use opt_add_addr and opt_announce_addr vice versa.
To make compiler happy, we declare it at top.

Signed-off-by: Saibato <saibato.naga@pm.me>
2019-10-03 06:08:09 +00:00
Christian Decker d5f0c08a88 elements: Remove global is_elements variable in favor of chainparams
No need to keep duplicate globals.
2019-10-03 04:32:57 +00:00
Christian Decker ef7a63d8f8 elements: Move from a global is_elements to a global chainparams
We now have a pointer to chainparams, that fails valgrind if we do anything
chain-specific before setting it.

Suggested-by: Rusty Russell <@rustyrussell>
2019-10-03 04:32:57 +00:00
Christian Decker a300dea7e6 elements: Global variable whether we are running on elements
Using a global variable is a bit lazy, but weaving the network type through
the entire stack is a daunting task. Maybe we can make that happen at a later
stage.

Most of the changes in `chainparams.c` are just formatting the
`genesis_blockhash` a bit nicer (`clang-format` to the rescue).

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-10-03 04:32:57 +00:00
Saibato 1b9cec8e91 Don't exit w/ INTERNAL_ERROR, if --addr or --bind-addr is used with an .onion address
The Fairy Tail version of .onion option calls on cmdline
reroute the call to --announce-addr or just drop it in case of bind.

Signed-off-by: Saibato <saibato.naga@pm.me>
2019-09-30 00:35:22 +00:00
Saibato 0f9ba53581 Add enable-autotor-v2 config variable
With enable-autotor-v2 defined in cmdline the default behavior to create
v3 onions with the tor service call, is set to v2 onions.

Signed-off-by: Saibato <saibato.naga@pm.me>
2019-09-28 00:31:02 +02:00
Rusty Russell d24c850899 gossipd: restore a flag for fast pruning
I was seeing some accidental pruning under load / Travis, and in
particular we stopped accepting channel_updates because they were 103
seconds old.  But making it too long makes the prune test untenable,
so restore a separate flag that this test can use.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-09-27 00:01:34 +00:00
Christian Decker 5953a5051c cli: Add command line option to specify the wallet location
Will be demuxed into starting the selected DB backend in one of the next
commits. Defaults to the old database location.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-09-22 02:03:43 +00:00
Rusty Russell 147eaced2e developer: consolidiate gossip timing options into one --dev-fast-gossip.
It's generally clearer to have simple hardcoded numbers with an
#if DEVELOPER around it, than apparent variables which aren't, really.

Interestingly, our pruning test was always kinda broken: we have to pass
two cycles, since l2 will refresh the channel once to avoid pruning.

Do the more obvious thing, and cut the network in half and check that
l1 and l3 time out.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-09-20 06:55:00 +00:00
Rusty Russell a988ded3fa lightningd: fix case where config file overrides lightning-dir.
The simplest case is to explicitly load it when we see it's been
set.

This involves neatening the default config setup, to remove it from
opt_parse_from_config() and into the caller.  It also seems we don't
need to call it anymore before parsing early options: none of them
need ld->config set.

Closes: #3030
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-09-12 19:08:24 -05:00
Rusty Russell 6901732ee0 lightningd: create --list-features-only which lists what features we support.
This allows the lightning-rfc protocol tests to automatically query what
features we support.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-08-29 09:01:48 +02:00
Rene Pickhardt 8e7428da53 Added possibility to configure max_concurrent_htlcs value for our channels. Eclaire has a default of 30 and I thought why not going with their value and while doing so make it configureable. 2019-08-09 05:45:06 +00:00
Rusty Russell 979fbeb3b0 lightningd: simplify --daemon.
Dumb programs which have a --daemon option call fork() early.  This is
terrible UX since startup errors get lost: the program exits with
"success" immediately then you discover via the logs that it didn't
start at all.

However, forking late introduced a heap of problems with changing
pids.  Instead, fork early but keep stderr and the parent around: if
we fail early on, the parent fails with us.  We release our parent
with an explicit action just before the main loop.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-08-04 21:29:03 +02:00