-
Notifications
You must be signed in to change notification settings - Fork 8
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
Cli integration #380
Cli integration #380
Conversation
WalkthroughThe project underwent significant restructuring with the introduction of new CLI modules Changes
Poem
Note Summarized by CodeRabbit FreeYour organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://coderabbit.ai TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
calimero-node = { path = "../node" } | ||
calimero-network = { path = "../network" } | ||
calimero-application = { path = "../application" } | ||
calimero-node-primitives = { path = "../node-primitives" } | ||
calimero-primitives = { path = "../primitives" } | ||
calimero-server = { path = "../server", features = ["jsonrpc", "websocket", "admin"] } | ||
calimero-store = { path = "../store" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't depend on all these crates IMO. CLI should be as small as possible and know as little as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of them are unneeded probably, will clean up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I'm constructing the config struct to run the node (NodeConfig
), I am using other structs from these crates.
Is there a way to get around that?
} | ||
|
||
let config = ConfigFile::load(&root_args.home)?; | ||
let config = ConfigFile::load(&path)?; | ||
|
||
calimero_node::start(calimero_node::NodeConfig { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CLI should start a node binary, not invoke the start method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also CLI should keep track of all started binaries, so the user can stop/interact with any of the running nodes.
|
||
/// Force initialization even if the directory already exists | ||
#[clap(short, long)] | ||
pub force: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would the user want to init node again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Someone mentioned that it would be nice to restart the node, so Xabi mentioned that deleting the keys would block users to rejoin the context. So I kept it like this.
Can remove if needed
dad0c20
to
8548123
Compare
8548123
to
8fc5f48
Compare
/// Name of node | ||
#[arg(short, long, value_name = "NAME")] | ||
pub node_name: camino::Utf8PathBuf, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this also need to be part of the RootArgs
to prevent duplication?
pub struct InitFile { | ||
#[serde(with = "calimero_primitives::identity::serde_identity")] | ||
pub identity: identity::Keypair, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems mostly useless imo
- init will happen once, in the lifetime of a node
- this will be a file with one thing.. identity
- if you want to define your own custom keypair, then init with the random one and change it
not convinced we need a special file just for initialization
and if we need to provide some way to dynamically rotate keys, consider how IPFS's kubo has it implemented
$ jq '.Identity' ~/.ipfs/config
{
"PeerID": "12D3KooWLJmoNJAbxeMW6uX7VPAmNSEUhXzNmxyk1DbFvFkS9oVB",
"PrivKey": "CAESQFPkkrc3fZvD2FQC0ek4QyAAI/v20C1AeSdCUdNxp1lnm9vaIWptv079wdl8tYgDzMWmGr6rdXpeiKlDEm4Kooo="
}
$ ipfs key rotate
generating ED25519 keypair...done
peer identity: 12D3KooWQ1WCd1To5qN7QYxjYbawPuEfqQaejkRF7kskATmsw2Z8
$ jq '.Identity' ~/.ipfs/config
{
"PeerID": "12D3KooWQ1WCd1To5qN7QYxjYbawPuEfqQaejkRF7kskATmsw2Z8",
"PrivKey": "CAESQG4zbb2YW2chk+NgNu0Ag0CdzG76V5qAeh3NuaN6jtWk0t4WjUgdE3nAhYRF+TH0IkZquffMtOL/hqkxGqAouXs="
}
pub home: camino::Utf8PathBuf, | ||
} | ||
|
||
impl RootCommand { | ||
pub async fn run(self) -> eyre::Result<()> { | ||
let _c = RootCommand::parse(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let _c = RootCommand::parse(); |
pub version: String, | ||
} | ||
|
||
fn validate_version(v: &str) -> Result<String, String> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
semver::Version
didn't work?
|
||
/// Setup symlink to application in the node | ||
#[derive(Debug, Parser)] | ||
pub struct LinkCommand { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be simple and we want to override the application for the context, not the application itself:
And I believe it makes sense to scope things out under an initial context
subcommand:
$ calimero context <context-id> install <resource>
where
resource := (application-spec[@version]) {OR} (file-path)
application-spec := (scoped-spec) {OR} (unique-spec)
scoped-spec := (<user-name>/<package-name>)
unique-spec := (bs58-encoded-unique-32-byte-application-id)
file-path := (relative-path) {OR} (absolute-path)
for example:
-
Download the latest version of the application from the registry
$ calimero context 33ovekjBBk2GxfZUueMPKMUe5ofqfp2AoEcXpAM71aAQ install petar/only-peers
-
Download version
0.2.0
of the application from the registry$ calimero context 33ovekjBBk2GxfZUueMPKMUe5ofqfp2AoEcXpAM71aAQ install petar/[email protected]
-
Download the latest version of the application from the registry
$ calimero context 33ovekjBBk2GxfZUueMPKMUe5ofqfp2AoEcXpAM71aAQ install 4TdrU3ruw6VquHforZ1ojjQ46dmnRwSP3faKB8evjviB
-
Download version
0.3.4
of the application from the registry$ calimero context 33ovekjBBk2GxfZUueMPKMUe5ofqfp2AoEcXpAM71aAQ install [email protected]
-
Installs the specified wasm file (copied to the apps folder)
$ calimero context 33ovekjBBk2GxfZUueMPKMUe5ofqfp2AoEcXpAM71aAQ install ./path/to/binary.wasm
-
Installs the specified wasm file (linked into the apps folder)
$ calimero context 33ovekjBBk2GxfZUueMPKMUe5ofqfp2AoEcXpAM71aAQ install --link ./path/to/binary.wasm
match symlink(self.path, app_path.join("binary.wasm")) { | ||
Ok(_) => {} | ||
Err(err) => eyre::bail!("Symlinking failed: {}", err), | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
match symlink(self.path, app_path.join("binary.wasm")) { | |
Ok(_) => {} | |
Err(err) => eyre::bail!("Symlinking failed: {}", err), | |
} | |
if let Err(err) = symlink(self.path, app_path.join("binary.wasm")) { | |
eyre::bail!("Symlinking failed: {}", err); | |
} |
self.node_name, | ||
app_path.join("binary.wasm") | ||
); | ||
return Ok(()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this to the end of the function
} else { | ||
eyre::bail!("You have to initialize the node first \nRun command node init -n <NAME>"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this to the top
if !ConfigFile::exists(..) {
eyre::bail!(..);
}
// at this point the file exists
should help flatten out the indentation
calimero_store::Store::open(&calimero_store::config::StoreConfig { | ||
path: path.join(config_new.store.path), | ||
})?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the db should've been initialized on init
|
||
/// Initialize node configuration | ||
#[derive(Debug, Parser)] | ||
pub struct SetupCommand { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this pattern was supposed to go away, since we can't exhaustively define all the options
core/crates/node/src/cli/init.rs
Lines 16 to 19 in 25a6cf5
// todo! simplify this, by splitting the steps | |
// todo! $ calimero node init | |
// todo! $ calimero node config 'swarm.listen:=["", ""]' discovery.mdns:=false | |
// todo! $ calimero node config discovery.mdns |
IPFS's kubo uses this design, we can learn from it
CLI short description
A new CLI to use for setting up and running nodes.
Summary
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
Fixes # (Add Jira tickets related to this change)
Test plan
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce.
Please also list any relevant details for your test configuration. Add screenshots or videos for changes in the user-interface.
Checklist
Summary by CodeRabbit
cli
module with various commands (InitCommand
,LinkCommand
,RunCommand
,SetupCommand
) for node configuration and management.cli
module for improved functionality.config.rs
file.config
in themain.rs
file.config
module from the public scope in thelib.rs
file.