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

Unify configuration structure for Lurk library and CLI #706

Merged
merged 1 commit into from
Oct 25, 2023

Conversation

samuelburnham
Copy link
Contributor

@samuelburnham samuelburnham commented Sep 26, 2023

  • Moves the LURK_DIRS global variable to config.rs as LURK_CONFIG: OnceCell<Settings>. This enables the configuration of the public parameter cache location in the following ways:

    • Lurk as a library:
      • Add public_params_dir = "/path/to/public_params" into the config file located at $HOME/.lurk/lurk.toml or a configurable location (lowest priority)
      • Set the LURK_PUBLIC_PARAMS_DIR env var (higher priority)
    • Lurk CLI:
      • Pass the --public-params-dir /path/to/public_params arg to the lurk binary to override the env var and config file (highest priority).
  • The CLI mirrors the above settings in its own CLI_CONFIG: OnceCell<CliSettings>, while sharing the lurk.toml config file for now:

    • Config file key: proofs_dir, commits_dir, circom_dir
    • Env var: LURK_PROOFS_DIR, LURK_COMMITS_DIR, LURK_CIRCOM_DIR
    • CLI args: --proofs-dir, --commits-dir, --circom-dir
  • Removes the cache path arg from the public_params function in favor of the new config

  • Refactors the CLI's set_lurk_dirs() function to lurk_config() and cli_config(), which use the OnceCell::get_or_init() function to remove the prior reliance on function call order.

  • Disambiguate/merge configs with the preexisting src/config.rs concerning parallelism. If merged, the configs would all be contained in $HOME/.lurk/lurk.toml with the source in src/config.rs

  • Add doc comments, particularly regarding the config options explained above

Fixes #621

@samuelburnham samuelburnham marked this pull request as ready for review September 26, 2023 20:55
@samuelburnham samuelburnham requested review from a team as code owners September 26, 2023 20:55
@huitseeker
Copy link
Contributor

Note, even if I haven't had the time to give this a review: @samuelburnham and @winston-h-zhang have some overlap between this and #648

@winston-h-zhang
Copy link
Contributor

@samuelburnham what is the status of this PR? I agree with your comment that the Lurk config should be merged into config.rs. Otherwise, I think this PR looks good and we should stabilize these changes. I think it's likely that more changes will be required as the needs of devex grows, but we can deal with that as it comes.

@samuelburnham samuelburnham force-pushed the config-public-params branch 2 times, most recently from e7579c6 to feb4f03 Compare October 13, 2023 23:52
Copy link
Contributor

@arthurpaulino arthurpaulino left a comment

Choose a reason for hiding this comment

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

I like the general direction this is heading towards. Tyvm!

I wonder if the default config file should live in .config or .lurk. I usually like it when applications populate a single folder on my machine by default, but that's a subjective taste.

src/cli/field.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@arthurpaulino arthurpaulino left a comment

Choose a reason for hiding this comment

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

Some streamlined comments about the utils crate. I believe it's too simple to deserve its own crate right now. Especially because everything here seems to have a better home

utils/src/lib.rs Outdated Show resolved Hide resolved
utils/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@arthurpaulino arthurpaulino left a comment

Choose a reason for hiding this comment

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

More comments from a third pass, now focusing on nitty gritty details

src/public_parameters/disk_cache.rs Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
src/cli/mod.rs Show resolved Hide resolved
src/cli/config.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@winston-h-zhang winston-h-zhang 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 PR is headed in the right direction. There are a few remaining complexities I'd like to iron out:

  • Preferably, I would like everything to be in one global config (merging CLI_CONFIG into config::LURK_CONFIG here), although I'm not strongly attached to the idea. Another reason is that we should be against the CLI having "ownership" over any part of the config (see pq's comment in the notion).
  • In the same way the CLI should not have any privilege to any particular config, the CLI should not have any privilege to modify environment variables. As we currently have it passing CLI arguments works by first overwriting the env vars of the corresponding arguments, and then propagating that change up to the config. This is really unpredictable; you might have default env vars, then accidentally overwrite everything by copy pasting someone else's CLI command.
  • Documentation in config.rs detailing the behavior of the config. Is the config.toml initialized to default values or does the user have to create one manually? Does the config.toml stay in sync with the env vars, and/or are there any other automatic changes done which the user should be aware of? If I want to permanently change the default public params directory, do I have to manually edit public_params_default_dir(), is it safe to do so, etc?

Addressing each of these points:

  • Merge CLI_CONFIG into config::LURK_CONFIG.
  • We should find some way to directly mutate the config from the CLI without taking a detour through env vars. Naively, I just want to make this a mutable static global, but @huitseeker definitely knows the better conventions here.
  • I think these questions are more iffy and could warrant more discussion, so any ideas are welcome!

src/cli/config.rs Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
benches/common/mod.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@arthurpaulino arthurpaulino left a comment

Choose a reason for hiding this comment

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

This is amazing work 🙏🏼

Earlier in the (short) call we had you mentioned that the user would be able to use a custom config file but I don't see this signaled in the CLI help menu nor anywhere else for the user to know. How do you think the user should become aware of that feature? Or is it not implemented yet?

benches/common/mod.rs Outdated Show resolved Hide resolved
@samuelburnham
Copy link
Contributor Author

@arthurpaulino the config file itself can't be customized, but its location can be configured by the --config CLI arg that already exists, or by the methods documented here: https://github.com/lurk-lab/lurk-rs/blob/ef9ebd6e5bf2fa268f5992f3920ad8dd82ea0eb6/src/config.rs#L42

arthurpaulino
arthurpaulino previously approved these changes Oct 24, 2023
Copy link
Contributor

@arthurpaulino arthurpaulino left a comment

Choose a reason for hiding this comment

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

I tested it and it seems to be fine. Maybe others can test it too

@samuelburnham samuelburnham changed the title fix: Move public param cache config to src/public_parameters/disk_cache Unify configuration structure for Lurk library and CLI Oct 24, 2023
@samuelburnham samuelburnham linked an issue Oct 24, 2023 that may be closed by this pull request
Copy link
Contributor

@huitseeker huitseeker left a comment

Choose a reason for hiding this comment

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

This looks good to me globally, with some comments left inline.

src/config.rs Show resolved Hide resolved
benches/common/mod.rs Outdated Show resolved Hide resolved
src/cli/config.rs Show resolved Hide resolved
Unify public param config with config.rs, spin out CLI config

Address feedback and refactor CLI overrides

Simplify global initialization

Add configurable config file location
Copy link
Contributor

@huitseeker huitseeker left a comment

Choose a reason for hiding this comment

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

Thanks a ton!

@samuelburnham samuelburnham added this pull request to the merge queue Oct 25, 2023
Merged via the queue into lurk-lab:master with commit aa67bdb Oct 25, 2023
10 of 12 checks passed
@samuelburnham samuelburnham deleted the config-public-params branch October 25, 2023 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants