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

Global cast configuration #2689

Open
wants to merge 34 commits into
base: master
Choose a base branch
from

Conversation

kkawula
Copy link
Collaborator

@kkawula kkawula commented Nov 19, 2024

Closes #2221

Introduced changes

  • Added global config implementation
  • Update show-config command
  • Update snfoundry.toml docs

Checklist

  • Linked relevant issue
  • Updated relevant documentation
  • Added relevant tests
  • Performed self-review of the code
  • Added changes to CHANGELOG.md

@kkawula kkawula changed the title Neque porro quisquam est qui dolorem Global cast configuration Nov 19, 2024
@kkawula kkawula force-pushed the kkawula/2221-global-cast-configuration branch from 3d2e58e to 65830c0 Compare November 21, 2024 11:40
@kkawula kkawula marked this pull request as ready for review November 21, 2024 13:35
crates/sncast/src/helpers/global_config.rs Outdated Show resolved Hide resolved
crates/sncast/src/main.rs Show resolved Hide resolved
crates/sncast/tests/e2e/main_tests.rs Show resolved Hide resolved
docs/src/projects/configuration.md Outdated Show resolved Hide resolved
Comment on lines 123 to 129
#### Interaction between Local and Global profiles

Interaction between global and local config is based on the overriding mechanism, the local config will be used to override
the global profile of the same name or in case it is not defined to override the default global profile.

If `--profile` is not provided, the default profile from the local (if present) and global configuration will be used.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if we can add a little example, just to have a better illustration of how this mechanism works? Wdyt?

crates/sncast/Cargo.toml Outdated Show resolved Hide resolved
crates/sncast/src/helpers/configuration.rs Show resolved Hide resolved
crates/sncast/src/helpers/global_config.rs Outdated Show resolved Hide resolved
Comment on lines 25 to 27
if !global_config_dir.exists() {
fs::create_dir_all(&global_config_dir)?;
}
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should be recursively creating this path. Let's only created a dir for starknet-foundry and if home/config dir is missing let's throw an error.

So use https://doc.rust-lang.org/beta/std/fs/fn.create_dir.html instead

Copy link
Collaborator Author

@kkawula kkawula Nov 21, 2024

Choose a reason for hiding this comment

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

Why not? I suppose that .config dir is intended for use by tools, and we should create it if is not present

Copy link
Member

Choose a reason for hiding this comment

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

Seems bit weird to me to create those.

But cc @THenry14 to verify

Copy link
Contributor

Choose a reason for hiding this comment

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

my understading is that create_dir_all corresponds to mkdir -p, which should be used in our case 👍

crates/sncast/src/main.rs Show resolved Hide resolved
Comment on lines 108 to 111
### Global configuration

Since version 0.34.0 `sncast` will use the global configuration to combine configuration from local configs.
Global configuration file is usual [`snfoundry.toml`](https://foundry-rs.github.io/starknet-foundry/appendix/snfoundry-toml.html), but placed in specific directory.
Copy link
Member

Choose a reason for hiding this comment

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

We don't need this, these are the docs for latest version.

docs/src/projects/configuration.md Outdated Show resolved Hide resolved
docs/src/projects/configuration.md Show resolved Hide resolved
docs/src/projects/configuration.md Show resolved Hide resolved
Comment on lines 123 to 128
#### Interaction between Local and Global profiles

Interaction between global and local config is based on the overriding mechanism, the local config will be used to override
the global profile of the same name or in case it is not defined to override the default global profile.

If `--profile` is not provided, the default profile from the local (if present) and global configuration will be used.
Copy link
Member

Choose a reason for hiding this comment

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

This needs to be written in simpler terms, so it's obvious what overrides what and in which cases.

CHANGELOG.md Outdated Show resolved Hide resolved
@@ -1,3 +1,4 @@
pub const EXPECTED_RPC_VERSION: &str = "0.7.0";
pub const RPC_URL_VERSION: &str = "v0_7";
pub const SNFORGE_TEST_FILTER: &str = "SNFORGE_TEST_FILTER";
pub const FREE_RPC_PROVIDER_URL: &str = "https://free-rpc.nethermind.io/sepolia-juno/v0_7";
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Do we really want to hardcode a link to an external node in the template? This might require updates in the future. I suggest sticking with the previous devnet address http://127.0.0.1:5050.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I suppose that it will be convenient for the user to have ready sepolia URL defined.

Copy link
Contributor

Choose a reason for hiding this comment

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

Although it might be convenient for some users I still don't think we should include it in the template. If you add it here you are kind of responsible for it to work, which means extra effort to maintain it and potentially dealing with related support questions.

crates/sncast/src/helpers/global_config.rs Outdated Show resolved Hide resolved
crates/sncast/src/helpers/global_config.rs Outdated Show resolved Hide resolved
crates/sncast/src/main.rs Show resolved Hide resolved
Comment on lines +71 to +79
macro_rules! clone_field {
($global_config:expr, $local_config:expr, $default_config:expr, $field:ident) => {
if $local_config.$field != $default_config.$field {
$local_config.$field.clone()
} else {
$global_config.$field.clone()
}
};
}
Copy link
Member

Choose a reason for hiding this comment

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

I like having new macros, however in this case I think it just could be a function :ccc

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do we really want to introduce such an ugly function instead of this beautiful macro?

fn clone_filed<T: PartialEq + Clone>(global: &T, local: &T, default: &T) -> T {
    if *local != *default {
        local.clone()
    } else {
        global.clone()
    }
}

crates/sncast/src/main.rs Outdated Show resolved Hide resolved
Comment on lines +145 to +156
**Glossary:**

- **A:** Global configuration file containing the profiles `default` and `testnet`.
- **B:** Local configuration file containing the profiles `default` and `mainnet`.

In any directory in the file system, a user can run the `sncast` command using the `default` and `testnet` profiles,
because they are located in global config.
If no profiles are explicitly specified, the `default` profile from the global configuration file will be used.

When running `sncast` from the `opus magnum` directory, there is a configuration file in the parent directory (B).
This setup allows for the use of the following profiles: `default`, `testnet`, and `mainnet`. If the `mainnet` profile is specified,
the configuration from the local file will be used to override the global `default` profile, as the `mainnet` profile does not exist in the global configuration.
Copy link
Member

Choose a reason for hiding this comment

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

It's a nice example but maybe show a shortened contents of A and B instead?

docs/src/projects/configuration.md Outdated Show resolved Hide resolved
docs/src/projects/configuration.md Outdated Show resolved Hide resolved
docs/src/projects/configuration.md Outdated Show resolved Hide resolved
Copy link
Contributor

@ddoktorski ddoktorski left a comment

Choose a reason for hiding this comment

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

In the commands account add and account import there is --add-profile flag. After introducing the global config it would be nice to explicitly mention that the created profile will be added to a local config if exists, or to change this logic. This can be done in this PR or a separate one, but it should be completed before the next release.

@@ -24,6 +24,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- You can skip `--name` flag when using `account import` - a default name will be generated.
- Addresses outputted when calling `sncast account create`, `sncast deploy` and `sncast declare` are now padded to 64 characters length and prefixed with `0x0`
- Globally available configuration to store profiles to share between projects.
- Missing fields in `show-config` command, `block_explorer` and `show_explorer_links`.
- Default free sepolia testnet RPC URL for any `sncast` command.
Copy link
Contributor

Choose a reason for hiding this comment

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

Even if we decide to add it, which I am strongly against, what is the point of mentioning this in the changelog?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I suppose that it is a significant change. It changes the expected behavior from the older version. Isn't it proper to mention here?

Copy link
Contributor

Choose a reason for hiding this comment

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

I see now that this also applies to the default CastConfig. I thought it was only for the template. That makes it even worse, but in such a case it should be added to the changelog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Global cast configuration
5 participants