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

refactor: split cli and client into workspace #407

Merged
merged 28 commits into from
Jul 2, 2024

Conversation

tomyrd
Copy link
Collaborator

@tomyrd tomyrd commented Jun 28, 2024

This PR restructures the repo to separate the client and cli in separate crates sharing a workspace.

@tomyrd tomyrd force-pushed the tomyrd-workspace-refactor branch from ca7cef7 to 27c4a59 Compare June 28, 2024 19:54
Cargo.toml Outdated Show resolved Hide resolved
miden-cli/Cargo.toml Outdated Show resolved Hide resolved
@bobbinth
Copy link
Contributor

btw, how is this PR different from #400?

@igamigo
Copy link
Collaborator

igamigo commented Jun 28, 2024

btw, how is this PR different from #400?

It's not, that PR was originally @mFragaBA's attempt which was behind in the commit history. Eventually it was decided that it was better to start from a fresh branch off of next which resulted in this other PR. I closed that first one.

@tomyrd tomyrd force-pushed the tomyrd-workspace-refactor branch from 27c4a59 to 40e4b6a Compare June 28, 2024 20:20
@tomyrd tomyrd force-pushed the tomyrd-workspace-refactor branch from b673fcb to 8b5a8ec Compare June 28, 2024 21:06
@tomyrd tomyrd marked this pull request as ready for review June 28, 2024 21:10
Copy link
Collaborator

@mFragaBA mFragaBA left a comment

Choose a reason for hiding this comment

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

Awesome work! Left tiny fixes and with that I think we're ok to merge

bin/miden-cli/Cargo.toml Outdated Show resolved Hide resolved
crates/miden-client/Cargo.toml Outdated Show resolved Hide resolved
Makefile Show resolved Hide resolved
@mFragaBA
Copy link
Collaborator

mFragaBA commented Jun 28, 2024

We debugged offline for a while on why the integration tests were failing (assert_cmd wasn't finding the CLI binary). We noticed the CLI binary was not being built. As a fast fix we noticed that you can just run make build before the tests and that'd be enough. Now we're seeing if adding the CLI as a dev-dependency also forces the build on the CLI and it gets found.

UPDATE: including it as a dependency didn't work so we'll go with building before running the test

Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you. I left a few comments inline.

Also, we should update the docs to make sure they are up to date.

bin/miden-cli/src/cli/account.rs Outdated Show resolved Hide resolved
bin/miden-cli/Cargo.toml Outdated Show resolved Hide resolved
bin/miden-cli/src/cli/mod.rs Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to above comments, I'm not sure we need the client submodule any more. Contents of this file should probably go into lib.rs and all other files brought up one level.

bin/miden-cli/Cargo.toml Outdated Show resolved Hide resolved
@igamigo igamigo force-pushed the tomyrd-workspace-refactor branch from ced1195 to 23c8ede Compare July 1, 2024 01:56
Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

I left a few more comments inline. Also, a couple of additional comments:

  • We should rename crates/miden-client into crates/rust-client.
  • we should create README.md files for each crate (i.e., bin/miden-cli/README.md and crates/rust-client/README.md).
  • Looking at files in bin/miden-cli/src now, it seems like we've made the structure "too flat". Maybe we should have commands sub-module to contain one file per command (e.g., bin/miden-cli/src/commands/account.rs).

bin/miden-cli/Cargo.toml Outdated Show resolved Hide resolved
bin/miden-cli/Cargo.toml Outdated Show resolved Hide resolved
bin/miden-cli/Cargo.toml Outdated Show resolved Hide resolved
Comment on lines 3 to 10
pub use miden_objects::{
accounts::AccountId, crypto::merkle::MmrError, notes::NoteId, AccountError, AssetError,
AssetVaultError, Digest, NoteError, TransactionScriptError, Word,
};
use miden_tx::{
pub use miden_tx::{
utils::{DeserializationError, HexParseError},
DataStoreError, TransactionExecutorError, TransactionProverError,
};
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need to re-export things like AccountId, NoteId, Word, and Digest from here.

Also, Some error are re-exports from other places too - e.g., DataStoreError, TransactionExecutorError, and DeserializationError exported from sub-modules defined at the root. We should have a consistent methodology and either export all errors from here - or all errors from corresponding sub-modules.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would leave re-exports from other crates in lib.rs. Also, in #374 I move around errors a bit maybe I can rebase once we merge this PR and deal with inconsistencies then

tests/Cargo.toml Outdated Show resolved Hide resolved
bin/miden-cli/src/account.rs Outdated Show resolved Hide resolved
bin/miden-cli/Cargo.toml Outdated Show resolved Hide resolved
cargo nextest run --release --test=integration --features $(FEATURES_INTEGRATION_TESTING) --no-default-features

.PHONY: integration-test-full
integration-test-full: ## Run the integration test binary with ignored tests included
integration-test-full: build ## Run the integration test binary with ignored tests included
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's create an issue to move the CLI integration tests to the CLI crate

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done, created issue #411

README.md Outdated Show resolved Hide resolved
README.md Outdated
```
The workspace is organized as follows:
- The `bin` folder contains crates that are meant to be compiled into binaries (like the CLI).
- The `crates` folder contains the library crates that are meant to be used as dependencies (like the rust client library).
Copy link
Collaborator

@igamigo igamigo Jul 1, 2024

Choose a reason for hiding this comment

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

nit:

Suggested change
- The `crates` folder contains the library crates that are meant to be used as dependencies (like the rust client library).
- The `crates` folder contains the library crates that are meant to be used as dependencies (like the Rust client library).

tests/Cargo.toml Outdated
figment = { version = "0.10", features = ["toml", "env"] }
miden-client = { path = "../crates/rust-client", features = ["testing"] }
miden-objects = { package = "miden-objects", git = "https://github.com/0xPolygonMiden/miden-base.git", branch = "next", default-features = false, features = ["serde"] }
assert_cmd = { version = "2.0" }
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: let's make sure these are sorted in alphabetical order.

Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you. I left a few more comments inline.

Also, I think e should still get rid of the client sub-module in miden-client.

Comment on lines 7 to 9
Before you can use the Miden client, you'll need to make sure you have both
[Rust](https://www.rust-lang.org/tools/install) and sqlite3 installed. Miden
client requires rust version **1.78** or higher.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: we usually don't manually wrap lines in markdown files.

Comment on lines 13 to 19
You can either build from source with:

```bash
cargo build --release
```

Once the binary is built, you can find it on `./target/release/miden-client`.
Copy link
Contributor

Choose a reason for hiding this comment

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

We should mention building with testing feature enabled.

Also, is the target directory correct here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed, the target directory is ok but the binary name isn't

Comment on lines 23 to 25
```bash
cargo install miden-client
```
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be miden-cli, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, this is the old binary name

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add a "License" section to this file (as we have in the main file).

@@ -0,0 +1,27 @@
# Miden Client CLI

This binary is a wrapper around the library exposing its functionality via a simple command-line interface (CLI).
Copy link
Contributor

Choose a reason for hiding this comment

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

I would make this description a bit more informative (i.e., that this is for interacting with the Miden rollup). This fill will be the main file on crates.io for the miden-cli crate.

miden-lib = { package = "miden-lib", git = "https://github.com/0xPolygonMiden/miden-base.git", branch = "next", default-features = false, features = ["testing"] }
miden-objects = { package = "miden-objects", git = "https://github.com/0xPolygonMiden/miden-base.git", branch = "next", default-features = false, features = ["serde", "testing"] }
uuid = { version = "1.6", features = ["serde", "v4"] }
miden-client = { path = ".", features = ["testing", "concurrent", "sqlite", "tonic", "tokio"]}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: let's alphabetize this list.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add the "License" section to this file.

Comment on lines 17 to 22
- `concurrent`: used to enable concurrency during execution and proof generation.
- `testing`: useful feature that lowers PoW difficulty when enabled, meant to be used during development and not on production.
- `sqlite`: includes `SqliteStore`, a SQLite implementation of the `Store` trait that can be used as a component of `Client`.
- `async`: enables async traits. Disabled by default.
- `tonic`: includes `TonicRpcClient`, a Tonic client to communicate with Miden node, that can be used as a component of `Client`.
- `executable`: builds the CLI, based on `SqliteStore` and `TonicRpcClient`.
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't have executable feature any more, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nice catch, we removed it and I forgot to delete it from the list

Comment on lines 13 to 15
By default, the library is `no_std` compatible.

### Features
Copy link
Contributor

Choose a reason for hiding this comment

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

I would try to do something more similar to how we describe features in other places (e.g., here.

For example, I would name the section "Crate features", would describe how to use --no-default-features flag etc.

@@ -47,16 +53,16 @@ pub mod crypto {
},
rand::{FeltRng, RpoRandomCoin},
},
Digest,
Digest, ONE, ZERO,
Copy link
Contributor

Choose a reason for hiding this comment

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

I would probably move ONE and ZERO exports to the root level (i.e., to line 60 below).

Co-authored-by: igamigo <ignacio.amigo@lambdaclass.com>
path = "src/main.rs"

[features]
default = ["dep:clap", "dep:comfy-table", "dep:figment", "dep:tokio", "dep:toml"]
Copy link
Collaborator

@igamigo igamigo Jul 2, 2024

Choose a reason for hiding this comment

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

I think we should be able to leave default as empty, and remove optional dependencies.

Copy link
Collaborator

@mFragaBA mFragaBA left a comment

Choose a reason for hiding this comment

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

Is it possible that tonic files are not being generated? I tried deleting the crates/rust-client/src/client/rpc/tonic_client directory and building and the files didn't get generated. Perhaps I'm missing something

we'll probably need to update the getting-started documentation in miden base.

edition.workspace = true

[features]
integration = ["miden-client/integration"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm. wondering if an integration feature is necessary in the client still. We don't have to change it in this PR, but I'd try removing it and checking if integration tests are not being ran during make test and the appropiate integration tests are being ran during make integration-test

Copy link
Collaborator

Choose a reason for hiding this comment

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

If we remove it we'll also need to update the readme

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 we should definitely be able to remove it on #411

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added a comment referencing this change in the issue

Copy link
Collaborator

@igamigo igamigo left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Collaborator

@mFragaBA mFragaBA left a comment

Choose a reason for hiding this comment

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

LGTM!

@mFragaBA mFragaBA merged commit 146a076 into next Jul 2, 2024
7 checks passed
@mFragaBA mFragaBA deleted the tomyrd-workspace-refactor branch July 2, 2024 14:58
Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

I know this PR has been merged already, but I left a few comments below. Would be good to address them in a follow-up PR.

These actions can also be executed when inside the repository via the Makefile with `make build` or `make install`.

## License
This project is [MIT licensed](./LICENSE).
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this link is broken. Probably should refer to the parent directory.

@@ -0,0 +1,30 @@
# Miden Client CLI

This binary allows the user to interact with the Miden rollup via a simple command-line interface (CLI). It's a wrapper around the Miden client library exposing its functionality in order to create accounts, create and consume notes, all executed and proved using the Miden VM.
Copy link
Contributor

Choose a reason for hiding this comment

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

I would make the "Miden client" reference in the second sentence a link to the miden-client crate on crates.io.

Copy link
Collaborator

Choose a reason for hiding this comment

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

do we need to release it first as miden-client?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can put in the link now assuming it will be published at the time miden-cli crate is published.

The `sqlite` and `tonic` features provide implementations for these traits using [Rusqlite](https://github.com/rusqlite/rusqlite) and [Tonic](https://github.com/hyperium/tonic) respectively.

## License
This project is [MIT licensed](./LICENSE).
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this link is broken. Probably should refer to the parent directory.

pub use miden_objects::assets::{Asset, AssetVault, FungibleAsset, TokenSymbol};
}

mod store_authenticator;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this line should probably be moved up to the top section of the file.

Comment on lines +3 to +11
pub mod accounts;
pub mod config;
pub mod errors;
pub(crate) mod note_screener;
pub mod notes;
pub mod rpc;
pub mod store;
pub mod sync;
pub mod transactions;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure any of these modules need to be pub any more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We moved the re-exports to each of the relevant submodules so we should make them (the modules) public for them to be accesible. I'll try moving the re-exports back to lib.rs and renaming the modules so that they dont cause conflicts.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should this and notes.rs file go into src/notes directory?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would probably move this file into its own directory (i.e., src/sync/mod.rs) and split it up into several files.

bobbinth pushed a commit that referenced this pull request Jul 5, 2024
* refactor: split into workspace

* Update CHANGELOG

* refactor: separate directories for binaries and crates

* feat: add workspace dependencies

* refactor: enable integration tests as separate crate

* fix: workspace features

* fix: address suggestions

* fix: makefile descriptions

* fix: add build step before tests

* fix: Integration tests

* fix: Go back to next for integration tests

* Change docs make target

* fix: address suggestions for miden-cli Cargo.toml

* fix: remove unnecessary exports in miden-client

* fix: remove unnecessary dependency from tests

* fix: remove patch versions from all dependencies

* refactor: rename `miden-client` directory to `rust-client`

* refactor: create `commands` sub-module for miden-cli

* refactor: distribute sections of workspace README to the crate/bin

* fix: add general workspace information and links to READMEs

* fix: cli name in README

Co-authored-by: igamigo <ignacio.amigo@lambdaclass.com>

* fix: alphabetize dependencies in tests crate

* fix: improve miden-cli README

* fix: add more information about the rust-client features

* refactor: remove `client` sub-module

* fix: tonic generated file builder

* fix: remove optional dependencies in cli

---------

Co-authored-by: Ignacio Amigo <ignacio.amigo@lambdaclass.com>
bobbinth pushed a commit that referenced this pull request Jul 5, 2024
* refactor: split into workspace

* Update CHANGELOG

* refactor: separate directories for binaries and crates

* feat: add workspace dependencies

* refactor: enable integration tests as separate crate

* fix: workspace features

* fix: address suggestions

* fix: makefile descriptions

* fix: add build step before tests

* fix: Integration tests

* fix: Go back to next for integration tests

* Change docs make target

* fix: address suggestions for miden-cli Cargo.toml

* fix: remove unnecessary exports in miden-client

* fix: remove unnecessary dependency from tests

* fix: remove patch versions from all dependencies

* refactor: rename `miden-client` directory to `rust-client`

* refactor: create `commands` sub-module for miden-cli

* refactor: distribute sections of workspace README to the crate/bin

* fix: add general workspace information and links to READMEs

* fix: cli name in README

Co-authored-by: igamigo <ignacio.amigo@lambdaclass.com>

* fix: alphabetize dependencies in tests crate

* fix: improve miden-cli README

* fix: add more information about the rust-client features

* refactor: remove `client` sub-module

* fix: tonic generated file builder

* fix: remove optional dependencies in cli

---------

Co-authored-by: Ignacio Amigo <ignacio.amigo@lambdaclass.com>
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.

None yet

4 participants