Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config changes #3268

Merged
merged 15 commits into from
Nov 23, 2019
Merged

Conversation

rustyrussell
Copy link
Contributor

  • Files now moved into bitcoin/testnet/regtest/etc subdir.
  • Config file still parsed in old location, but also network/config is parsed
  • Default for new installs in bitcoin, not testnet!

@rustyrussell rustyrussell added this to the 0.7.4 milestone Nov 18, 2019
@jb55
Copy link
Collaborator

jb55 commented Nov 18, 2019

this breaks my current system clightning system service with: network: not permitted in configuration files. since I had network=bitcoin in my config file, so now I will need to add it to the systemd service line. Not too big a deal but just giving a heads up.

@jb55
Copy link
Collaborator

jb55 commented Nov 18, 2019

Another thing that is a bit confusing is lightning-cli now shows this message when clightning isn't running:
lightning-cli: WARNING: default network changing in 2020: please set network=testnet in config!

@rustyrussell
Copy link
Contributor Author

Oops, this is a bug. Network should only be disallowed in the /config file. Should still be valid on the root config.

@rustyrussell
Copy link
Contributor Author

rustyrussell commented Nov 18, 2019

Thanks @jb55 ... and this time with tests!

BTW, you can restore with mv -i ~/.lightning/bitcoin/* ~/.lightning && rmdir ~/.lightning/bitcoin if you want to test again :)

@jb55
Copy link
Collaborator

jb55 commented Nov 19, 2019

hmm I was able to test it and the network=bitcoin in my config file worked without doing your mv and rmdir command, but then again my folder is ~/.lightning-bitcoin which I explicitly set as an argument to lightningd. I also explicitly set --conf

@rustyrussell rustyrussell force-pushed the guilt/config-changes branch 4 times, most recently from d2546ce to 9188e0d Compare November 21, 2019 05:53
Copy link
Member

@cdecker cdecker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a very painful upgrade, but honestly I don't see how we could make it less painful. Some general comments below:

  • We have no recursion depth, so circular includes can result in endless
    loops
  • Starting a node without a --network parameter may end up moving testnet
    files into the bitcoin directory and treating them like mainnet.

The latter is really what bothers me, we are moving things around without really knowing what network the config is for, but I also don't see how we could avoid that without reading the DB chain and then comparing with the chainparams.

if (all_args[i] == NULL)
continue;

if (!strstarts(all_args[i], "--")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me think we should make the all_args entries into a struct that carries a type with it. Something like this seems better for future extensibility:

enum ConfigLineType {
    CONFIG_COMMENT,
    CONFIG_ARGUMENT,
    CONFIG_INCLUDE,
};

struct ConfigEntry {
    ConfigLineType type;
    char *line;
    char *filename;
    size_t pos;
};

It can also be used to reconstruct the config from the in-memory representation and provide nicer error messages.

Copy link
Collaborator

@niftynei niftynei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could help people keep testnet/mainnet nodes running at the same time, so overall I'm a fan.

The includes capability is particularly nice.

As @cdecker mentioned, if we want to be super safe for the transition/upgrade path we could check the database for the chainhash. Not sure what our risk profile is though :)

void parse_include(const char *filename, bool must_exist, bool early)
{
char *contents, **lines;
char **all_args; /*For each line: either argument string or NULL*/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might also be a path to load for an includes

all_args = tal_arr_label(options_ctx, char *, tal_count(lines) - 1,
TAL_LABEL(options_array_notleak, ""));

for (i = 0; i < tal_count(lines) - 1; i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this skip the last line because the tal_strsplit above leaves the last line blank?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It NULL-terminates the array, yes.

config_basedir = base;

/* If it doesn't exist, it's not testnet. */
if (stat(base, &st) != 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think you might mean to be testing config_basedir here?

}

/* Does it have a bitcoin/ subdir and no testnet/ subdir? */
if (stat(path_join(base, config_basedir, "bitcoin"), &st) == 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok i'll admit i'm a bit confused here. at L255 we might have set config_basedir to be base; in that case we'd be joining the same path twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First arg is context: we're not relying on tmpctx here, so I'm abusing base as a per-function ctx. Will comment :)

@@ -972,7 +974,7 @@ void handle_early_opts(struct lightningd *ld, int argc, char *argv[])
ld->config_netdir);

/* Set default PID file name to be per-network */
ld->pidfile = tal_fmt(ld, "lightningd-%s.pid",
ld->pidfile = tal_fmt(ld, "../lightningd-%s.pid",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is going to change where 'custom set' lightning-directory PID files are located.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because they get parsed next.

However, this "../" is wrong (network/ may be a symlink): this code is left over from before I gave in and made basedir and netdir explicit. Will fix:

	/* Set default PID file name to be per-network (in base dir) */
	ld->pidfile = path_join(ld, ld->config_basedir,
				tal_fmt(tmpctx, "lightningd-%s.pid",
					chainparams->network_name));

'--lightning-dir={}'.format(l1.daemon.opts.get("lightning-dir"))],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
assert out.returncode == 1
assert "lightning-dir: not permitted in implicit configuration files" in out.stderr.decode('utf-8')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add test for PID location?

@rustyrussell
Copy link
Contributor Author

This might be a very painful upgrade, but honestly I don't see how we could make it less painful. Some general comments below:

* We have no recursion depth, so circular includes can result in endless
  loops

Yes, this I can fix quite easily.

* Starting a node without a `--network` parameter may end up moving `testnet`
  files into the `bitcoin` directory and treating them like mainnet.

That should not happen (unless they specify --allow-deprecated-apis=false): if nothing is specified, they get testnet on existing installs. I will add a test for this, however.

The latter is really what bothers me, we are moving things around without really knowing what network the config is for, but I also don't see how we could avoid that without reading the DB chain and then comparing with the chainparams.

@rustyrussell
Copy link
Contributor Author

As @cdecker mentioned, if we want to be super safe for the transition/upgrade path we could check the database for the chainhash. Not sure what our risk profile is though :)

Doing so is amazingly ugly, since we need to plumb though a lot of code to get the db open early. So I chose the simpler approach of leaving existing installs as testnet by default.

Copy link
Collaborator

@niftynei niftynei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 46e6b38

@rustyrussell rustyrussell force-pushed the guilt/config-changes branch 3 times, most recently from 1337d51 to 8eb7eee Compare November 23, 2019 00:23
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: Config: configuration files now support `include`.
…annel_start

With coming changes, this will segfault if we access it when param
code is trying to get usage from functions.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
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>
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.
…twork> 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>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
We're going to want this for changing the default network.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-changed: Default network (new installs) is now bitcoin, not testnet.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
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>
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>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Otherwise we don't print out the upgrading messages when we move things!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Don't spend too much effort on it, but this is better than running out
of memory and crashing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
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.
@rustyrussell
Copy link
Contributor Author

Trivial rebase to fold fixes.

Copy link
Collaborator

@darosior darosior left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK ee79dee

I noticed a nit while testing though: Creating configuration [...] Moving [...] ... would be shown two times when upgrading testnet old directories, but not regtest ones.

@rustyrussell
Copy link
Contributor Author

Yes, I can remove doubling in a separate patch, is a side effect of when we finally set up the log. Previously it was only for broken messages, which usually meant we exited before log setup anyway...

@rustyrussell rustyrussell merged commit 14997f6 into ElementsProject:master Nov 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants