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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6f5d782
refactor: split into workspace
tomyrd Jun 28, 2024
83421cc
Update CHANGELOG
tomyrd Jun 28, 2024
6b37542
refactor: separate directories for binaries and crates
tomyrd Jun 28, 2024
4e07a0c
feat: add workspace dependencies
tomyrd Jun 28, 2024
8b5a8ec
refactor: enable integration tests as separate crate
tomyrd Jun 28, 2024
49ad991
fix: workspace features
tomyrd Jun 28, 2024
19fb973
fix: address suggestions
tomyrd Jun 28, 2024
c9a763c
fix: makefile descriptions
tomyrd Jun 28, 2024
6349fd6
fix: add build step before tests
tomyrd Jun 28, 2024
f715555
Rebase
igamigo Jun 30, 2024
23c8ede
fix: Integration tests
igamigo Jun 30, 2024
1131acf
fix: Go back to next for integration tests
igamigo Jul 1, 2024
6aaa2f9
Change docs make target
igamigo Jul 1, 2024
256128b
fix: address suggestions for miden-cli Cargo.toml
tomyrd Jul 1, 2024
a6d4a63
fix: remove unnecessary exports in miden-client
tomyrd Jul 1, 2024
be199e2
fix: remove unnecessary dependency from tests
tomyrd Jul 1, 2024
9183699
fix: remove patch versions from all dependencies
tomyrd Jul 1, 2024
72a1619
refactor: rename `miden-client` directory to `rust-client`
tomyrd Jul 1, 2024
a9661b9
refactor: create `commands` sub-module for miden-cli
tomyrd Jul 1, 2024
dacf7a6
refactor: distribute sections of workspace README to the crate/bin
tomyrd Jul 1, 2024
49b2c6e
fix: add general workspace information and links to READMEs
tomyrd Jul 1, 2024
44b268b
fix: cli name in README
tomyrd Jul 1, 2024
6a44628
fix: alphabetize dependencies in tests crate
tomyrd Jul 1, 2024
76e35e7
fix: improve miden-cli README
tomyrd Jul 1, 2024
e844b0d
fix: add more information about the rust-client features
tomyrd Jul 1, 2024
b8520ae
refactor: remove `client` sub-module
tomyrd Jul 1, 2024
afd268a
fix: tonic generated file builder
tomyrd Jul 2, 2024
c73d780
fix: remove optional dependencies in cli
tomyrd Jul 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Changelog

* [BREAKING] Split cli and client into workspace (#407).
* Note importing in client now uses the `NoteFile` type (#375).
* Added build script to import Miden node protobuf files to generate types for `tonic_client` and removed `miden-node-proto` dependency (#395).
* Implemented retrieval of executed transaction info (id, commit height, account_id) from sync state RPC endpoint (#387).
Expand Down
92 changes: 16 additions & 76 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,80 +1,20 @@
[package]
name = "miden-client"
version = "0.3.1"
description = "Client library that facilitates interaction with the Miden rollup"
authors = ["miden contributors"]
readme = "README.md"
license = "MIT"
repository = "https://github.com/0xPolygonMiden/miden-client"
documentation = "https://docs.rs/miden-client/0.3.1"
keywords = ["miden", "client"]
edition = "2021"
rust-version = "1.78"
default-run = "miden"

[lib]
crate-type = ["lib"]
[workspace]
resolver = "2"

[[bin]]
name = "miden"
path = "src/main.rs"
required-features = ["executable"]
members = [
"bin/miden-cli",
"crates/rust-client",
"tests"
]

[[test]]
name = "integration"
path = "tests/integration/main.rs"
required-features = ["integration"]

[features]
async = ["miden-tx/async"]
concurrent = ["miden-lib/concurrent", "miden-objects/concurrent", "miden-tx/concurrent", "std"]
default = ["std"]
executable = ["std", "sqlite", "tonic", "dep:clap", "dep:comfy-table", "dep:figment", "dep:tokio", "dep:toml"]
integration = ["concurrent", "executable", "testing"]
sqlite = ["dep:rusqlite", "dep:rusqlite_migration", "dep:lazy_static"]
std = ["miden-objects/std"]
testing = ["miden-objects/testing", "miden-lib/testing"]
tonic = ["dep:hex", "dep:prost","dep:tonic"]
[workspace.package]
edition = "2021"
rust-version = "1.78"
license = "MIT"
authors = ["miden contributors"]
repository = "https://github.com/0xPolygonMiden/miden-client"

[dependencies]
chrono = { version = "0.4", optional = false }
clap = { version = "4.3", features = ["derive"], optional = true }
comfy-table = { version = "7.1.0", optional = true }
figment = { version = "0.10", features = ["toml", "env"], optional = true }
hex = { version = "0.4" , optional = true}
lazy_static = { version = "1.4.0", optional = true }
miden-lib = { package = "miden-lib", git = "https://github.com/0xPolygonMiden/miden-base.git", branch = "next", default-features = false }
miden-tx = { package = "miden-tx", git = "https://github.com/0xPolygonMiden/miden-base.git", branch = "next", default-features = false }
miden-objects = { package = "miden-objects", git = "https://github.com/0xPolygonMiden/miden-base.git", branch = "next", default-features = false, features = ["serde"] }
prost = { version = "0.12", optional = true }
rand = { version = "0.8.5" }
rusqlite = { version = "0.30.0", features = ["vtab", "array", "bundled"], optional = true }
rusqlite_migration = { version = "1.0", optional = true }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", features = ["raw_value"] }
tokio = { version = "1.29", features = ["rt-multi-thread", "net", "macros"], optional = true }
tonic = { version = "0.11", optional = true }
toml = { version = "0.8", optional = true }
thiserror = { version = "1.0", optional = true }
[workspace.dependencies]
rand = { version = "0.8" }
tokio = { version = "1.29", features = ["rt-multi-thread", "net", "macros"] }
tracing = { version = "0.1" }
tracing-subscriber = { version = "0.3" }
winter-maybe-async = "0.10.0"

[target.'wasm32-unknown-unknown'.dependencies]
getrandom = { version = "0.2", features = ["js"] }

[dev-dependencies]
# To enable testing feature during tests
assert_cmd = { version = "2.0" }
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"] }
proptest = { version = "1.2" }
uuid = { version = "1.6.1", features = ["serde", "v4"] }

[build-dependencies]
miden-rpc-proto = { package = "miden-rpc-proto", git = "https://github.com/0xPolygonMiden/miden-node.git", branch = "next" }
miette = { version = "7.0", features = ["fancy"] }
prost = { version = "0.12" }
prost-build = { version = "0.12" }
protox = { version = "0.6" }
tonic-build = { version = "0.11" }
20 changes: 10 additions & 10 deletions Makefile
mFragaBA marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ help: ## Show description of all commands
# --- Variables -----------------------------------------------------------------------------------

FEATURES_INTEGRATION_TESTING="integration"
FEATURES_CLI="testing, executable, concurrent"
FEATURES_CLI="testing, concurrent"
NODE_FEATURES_TESTING="testing"
WARNINGS=RUSTDOCFLAGS="-D warnings"
NODE_BRANCH="polydez-future-notes"
NODE_BRANCH="next"

# --- Linting -------------------------------------------------------------------------------------

Expand Down Expand Up @@ -51,7 +51,7 @@ doc-serve: doc-deps ## Serve documentation site

.PHONY: doc
doc: ## Generates & checks rust documentation
$(WARNINGS) cargo doc --all-features --keep-going --release
$(WARNINGS) cargo doc --all-features --keep-going --release -p miden-client

# --- Testing -------------------------------------------------------------------------------------

Expand All @@ -62,11 +62,11 @@ test: ## Run tests
# --- Integration testing -------------------------------------------------------------------------

.PHONY: integration-test
integration-test: ## Run integration tests
integration-test: build ## Run integration tests
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

cargo nextest run --release --test=integration --features $(FEATURES_INTEGRATION_TESTING)
cargo nextest run --release --test=integration --features $(FEATURES_INTEGRATION_TESTING) --run-ignored ignored-only -- test_import_genesis_accounts_can_be_used_for_transactions

Expand All @@ -79,7 +79,7 @@ clean-node: ## Clean node directory
rm -rf miden-node

.PHONY: node
node: ## Setup node
node: ## Setup node directory
if [ -d miden-node ]; then cd miden-node ; else git clone https://github.com/0xPolygonMiden/miden-node.git && cd miden-node; fi
cd miden-node && git checkout $(NODE_BRANCH) && git pull origin $(NODE_BRANCH) && cargo update
cd miden-node && rm -rf miden-store.sqlite3*
Expand All @@ -91,13 +91,13 @@ start-node: ## Run node. This requires the node repo to be present at `miden-nod

# --- Installing ----------------------------------------------------------------------------------

install: ## Installs the CLI binary using the current dir
cargo install --features $(FEATURES_CLI) --path .
install: ## Installs the CLI binary
cargo install --features $(FEATURES_CLI) --path bin/miden-cli

# --- Building ------------------------------------------------------------------------------------

build: ## Builds the CLI binary and client library in release mode
cargo build --release --features $(FEATURES_CLI)

build-wasm: ## Builds the CLI binary for wasm32
cargo build --target wasm32-unknown-unknown --features async --no-default-features
build-wasm: ## Builds the client library for wasm32
cargo build --target wasm32-unknown-unknown --features async --no-default-features --package miden-client
50 changes: 8 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ The Miden client is still under heavy development and the project can be conside

The Miden client currently consists of two components:

- `miden-client` library, which can be used by other project to programmatically interact with the Miden rollup.
- `miden-client` binary which is a wrapper around the library exposing its functionality via a simple command-line interface (CLI).
- `miden-client` library, which can be used by other project to programmatically interact with the Miden rollup. You can find more information about the library in the [Rust Client Library](./crates/rust-client/README.md) section.
- _Miden CLI_, which is a wrapper around the library exposing its functionality via a simple command-line interface (CLI). You can find more information about the CLI in the [Miden Client CLI](./bin/miden-cli/README.md) section.

The client's main responsibility is to maintain a partial view of the blockchain which allows for locally executing and proving transactions. It keeps a local store of various entities that periodically get updated by syncing with the node.

Expand All @@ -27,50 +27,16 @@ For more info check:
- [Configuration](./docs/cli-config.md)
- [Online Documentation](https://docs.polygon.technology/miden/miden-client)

## Usage
## Workspace structure

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.

### Adding miden-client as a dependency

In order to utilize the `miden-client` library, you can add the dependency to your project's `Cargo.toml` file:

````toml
miden-client = { version = "0.3.1" }
````

By default, the library is `no_std` compatible.

#### Features

- `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`.

### Running `miden-client`'s CLI

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`.

Or you can install the CLI from crates-io with:

```bash
cargo install miden-client
```
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).
- The `tests` folder contains integration tests for the workspace crates.

### Makefile

As mentioned before, we use `make` to encapsulate some tasks, such as running lints and tests. You can check out [Makefile](./Makefile) for all available tasks or just run the following command:
We use `make` to encapsulate some tasks, such as running lints and tests. You can check out [Makefile](./Makefile) for all available tasks or just run the following command:

```bash
make
Expand Down
35 changes: 35 additions & 0 deletions bin/miden-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[package]
name = "miden-cli"
version = "0.3.1"
description = "CLI binary application that facilitates interaction with the Miden rollup"
readme = "README.md"
documentation = "https://docs.rs/miden-cli/0.3.1"
keywords = ["miden", "client", "cli"]
license.workspace = true
authors.workspace = true
repository.workspace = true
rust-version.workspace = true
edition.workspace = true

[[bin]]
name = "miden"
path = "src/main.rs"

[features]
default = []
testing = ["miden-client/testing"]
concurrent = ["miden-client/concurrent"]

[dependencies]
clap = { version = "4.3", features = ["derive"] }
comfy-table = { version = "7.1" }
figment = { version = "0.10", features = ["toml", "env"] }
miden-client = { path = "../../crates/rust-client", version = "0.3", features = ["sqlite", "tonic"] }
rand = { workspace = true }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", features = ["raw_value"] }
tokio = { workspace = true }
tonic = { version = "0.11" }
toml = { version = "0.8" }
tracing = { workspace = true }
tracing-subscriber = { version = "0.3" }
30 changes: 30 additions & 0 deletions bin/miden-cli/README.md
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).

Original file line number Diff line number Diff line change
@@ -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.


## Usage

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.

### Running `miden-client`'s CLI

You can either build from source with:

```bash
cargo build --release --features "testing, concurrent"
```

The `testing` and `concurrent` features are enabled to speed up account creation (for testing purposes) and optimize transaction execution and proving times respectively.

Once the binary is built, you can find it on `./target/release/miden`.

Or you can install the CLI from crates.io with:

```bash
cargo install --features "testing, concurrent" miden-cli
```

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.

44 changes: 10 additions & 34 deletions src/cli/account.rs → bin/miden-cli/src/commands/account.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
use clap::Parser;
use comfy_table::{presets, Attribute, Cell, ContentArrangement, Table};
use miden_client::{rpc::NodeRpcClient, store::Store, Client};
use miden_objects::{
accounts::{AccountId, AccountStorage, AccountType, AuthSecretKey, StorageSlotType},
use comfy_table::presets;
use miden_client::{
accounts::{AccountId, AccountStorage, AccountType, StorageSlotType},
assets::Asset,
crypto::{dsa::rpo_falcon512::SK_LEN, rand::FeltRng},
ZERO,
};
use miden_tx::{
auth::TransactionAuthenticator,
utils::{bytes_to_hex_string, Serializable},
crypto::FeltRng,
rpc::NodeRpcClient,
store::Store,
Client, ZERO,
};

use super::{
use crate::{
config::CliConfig,
create_dynamic_table,
utils::{load_config_file, parse_account_id, update_config},
CLIENT_BINARY_NAME,
};
use crate::cli::{create_dynamic_table, CLIENT_BINARY_NAME};

// ACCOUNT COMMAND
// ================================================================================================
Expand Down Expand Up @@ -202,29 +201,6 @@ pub fn show_account<N: NodeRpcClient, R: FeltRng, S: Store, A: TransactionAuthen
println!("{table}\n");
}

// Keys table
{
let auth_info = client.get_account_auth(account_id)?;

match auth_info {
AuthSecretKey::RpoFalcon512(key_pair) => {
let auth_info: [u8; SK_LEN] = key_pair
.to_bytes()
.try_into()
.expect("Array size is const and should always exactly fit SecretKey");

let mut table = Table::new();
table
.load_preset(presets::UTF8_HORIZONTAL_ONLY)
.set_content_arrangement(ContentArrangement::DynamicFullWidth)
.set_header(vec![Cell::new("Key Pair").add_attribute(Attribute::Bold)]);

table.add_row(vec![format!("0x{}\n", bytes_to_hex_string(auth_info))]);
println!("{table}\n");
},
};
}

// Code related table
{
let module = account.code().module();
Expand Down
10 changes: 5 additions & 5 deletions src/cli/export.rs → bin/miden-cli/src/commands/export.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::{fs::File, io::Write, path::PathBuf};

use miden_client::{rpc::NodeRpcClient, store::Store, Client};
use miden_objects::{crypto::rand::FeltRng, notes::NoteFile};
use miden_tx::{auth::TransactionAuthenticator, utils::Serializable};
use miden_client::{
auth::TransactionAuthenticator, crypto::FeltRng, notes::NoteFile, rpc::NodeRpcClient,
store::Store, utils::Serializable, Client,
};
use tracing::info;

use super::Parser;
use crate::cli::get_output_note_with_id_prefix;
use crate::{get_output_note_with_id_prefix, Parser};

#[derive(Debug, Parser, Clone)]
#[clap(about = "Export client output notes")]
Expand Down
Loading