From 419bb0c772ee0b36eb884d8485b444eb2a4cd3a1 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Fri, 27 Sep 2024 11:34:11 +0200 Subject: [PATCH 1/8] Fix missing .env error --- src/bin/mina_mesh.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/mina_mesh.rs b/src/bin/mina_mesh.rs index 2f1d944..b43b0bb 100644 --- a/src/bin/mina_mesh.rs +++ b/src/bin/mina_mesh.rs @@ -14,7 +14,7 @@ enum Command { #[tokio::main] async fn main() -> Result<()> { - dotenv::dotenv()?; + dotenv::dotenv().ok(); match Command::parse() { Command::Serve(cmd) => cmd.run().await, Command::FetchGenesisBlockIdentifier(cmd) => cmd.run().await, From 7b3462c35ea1d0e2aa6af79fdee2da49f5d15d68 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Fri, 27 Sep 2024 12:25:24 +0200 Subject: [PATCH 2/8] update readme with details on running and playground --- README.md | 67 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index e65b187..d0f30e1 100644 --- a/README.md +++ b/README.md @@ -22,24 +22,71 @@ The binary will be available at: target/debug/mina_mesh ``` -## Testing +## Running + +Mina Mesh requires access to a PostgreSQL Archive database and a Mina GraphQL endpoint. By default, +the configuration points to the mainnet, making it easy to get started. You can override the +configuration by either passing arguments or setting environment variables via a `.env` file (an +example is provided as `.env.example`). + +### Quick Start with Mainnet + +1. **Set up the PostgreSQL Archive Database** + +Use the predefined `just` commands to set up and start the PostgreSQL database: + +```bash +just setup-archive-db +``` + +> Note: This process sets up the PosrgreSQL docker using the latest mainnet archive database. + +2. **Run the Mina Mesh Server** + +To start the server with default settings (mainnet configuration): + +```bash +target/debug/mina_mesh serve +``` + +The server will listen on `0.0.0.0:3000` by default. + +### Playground Mode + +You can enable a playground mode, which provides a simplified testing interface, by adding the +`--playground` flag: + +```bash +target/debug/mina_mesh serve --playground +``` + +When enabled, you can access the playground at the root URL (`/`). -### Setup PostgreSQL with Latest Mainnet Archive DB +### Configuration -To set up the testing environment with a working PostgreSQL database, use the predefined `just` -steps: +Mina Mesh can be configured through command-line options or by using environment variables. For +convenience, you can use a `.env` file. To get started, copy the provided `.env.example`: ```bash -just get-mainnet-archive-db -just pg -just wait-for-pg +cp .env.example .env ``` -> Note: This process sets up the environment using the latest mainnet archive database. +Then modify the `.env` file to suit your environment. The available configurations include: -### Run Tests +- **Mina GraphQL Endpoint**: `MINA_PROXY_URL` (default: + `https://mainnet.minaprotocol.network/graphql`) +- **PostgreSQL Archive Database URL**: `MINA_ARCHIVE_DATABASE_URL` (default: + `postgres://mina:whatever@localhost:5432/archive`) +- **Genesis Block Identifier**: `MINA_GENESIS_BLOCK_IDENTIFIER_HEIGHT`, + `MINA_GENESIS_BLOCK_IDENTIFIER_STATE_HASH` + +> You can also pass these options as arguments to `mina_mesh serve` to override the defaults. + +## Testing -Once the setup is complete, run the tests with: +Running the tests requires having Archive database available [see: +[Quick Start with Mainnet](#quick-start-with-mainnet)]. Once the setup is complete you can run tests +using: ```bash just test From 513b2e7f6e716ffbc85e9e8f14e7c2c7cd5f4b02 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Fri, 27 Sep 2024 12:25:35 +0200 Subject: [PATCH 3/8] update Justfile --- Justfile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Justfile b/Justfile index b97956c..acb06a2 100644 --- a/Justfile +++ b/Justfile @@ -1,5 +1,5 @@ pg: - docker run -d --name mina-archive-db -p 5432:5432 -v $(pwd)/sql_scripts:/docker-entrypoint-initdb.d -e POSTGRES_PASSWORD=whatever -e POSTGRES_USER=mina postgres + docker run -d --name mina-archive-db -p 5555:5432 -v $(pwd)/sql_scripts:/docker-entrypoint-initdb.d -e POSTGRES_PASSWORD=whatever -e POSTGRES_USER=mina postgres pg-up: docker start mina-archive-db @@ -17,4 +17,9 @@ wait-for-pg: ./scripts/wait_for_pg.sh test: - SNAP_CHECK=1 cargo test \ No newline at end of file + SNAP_CHECK=1 cargo test + +setup-archive-db: + just get-mainnet-archive-db + just pg + just wait-for-pg \ No newline at end of file From 8ac261f7cc30360f310a8ea6d257fc6bd2ed4cf0 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Fri, 27 Sep 2024 12:25:56 +0200 Subject: [PATCH 4/8] remove rust_env arg from cli --- src/commands/serve.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/commands/serve.rs b/src/commands/serve.rs index 10029a9..796fb36 100644 --- a/src/commands/serve.rs +++ b/src/commands/serve.rs @@ -23,10 +23,9 @@ pub struct ServeCommand { host: String, #[arg(default_value = "3000")] port: u16, - #[arg(env, long)] + /// Whether to enable the playground. + #[arg(env = "PLAYGROUND", long)] playground: bool, - #[arg(env = "RUST_ENV", long)] - rust_env: String, } impl ServeCommand { @@ -52,8 +51,9 @@ impl ServeCommand { .route("/network/options", post(handle_network_options)) .route("/network/status", post(handle_network_status)) .with_state(Arc::new(mina_mesh)); - if self.rust_env == "development" || self.playground { + if self.playground { router = router.route("/", get(handle_playground)); + tracing::info!("playground enabled"); } let listener = TcpListener::bind(format!("{}:{}", self.host, self.port)).await?; tracing::info!("listening on http://{}", listener.local_addr()?); From 34f69c3450051e64e51d98cb129059c831dbb0d8 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Fri, 27 Sep 2024 12:32:24 +0200 Subject: [PATCH 5/8] fixup: typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d0f30e1..7d9085d 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ Use the predefined `just` commands to set up and start the PostgreSQL database: just setup-archive-db ``` -> Note: This process sets up the PosrgreSQL docker using the latest mainnet archive database. +> Note: This process sets up the PostgreSQL docker using the latest mainnet archive database. 2. **Run the Mina Mesh Server** From b86913b673b6a92c0c4cc917ba2007bac17dda80 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Fri, 27 Sep 2024 12:44:58 +0200 Subject: [PATCH 6/8] fixup: pg port --- Justfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Justfile b/Justfile index acb06a2..784511e 100644 --- a/Justfile +++ b/Justfile @@ -1,5 +1,5 @@ pg: - docker run -d --name mina-archive-db -p 5555:5432 -v $(pwd)/sql_scripts:/docker-entrypoint-initdb.d -e POSTGRES_PASSWORD=whatever -e POSTGRES_USER=mina postgres + docker run -d --name mina-archive-db -p 5432:5432 -v $(pwd)/sql_scripts:/docker-entrypoint-initdb.d -e POSTGRES_PASSWORD=whatever -e POSTGRES_USER=mina postgres pg-up: docker start mina-archive-db From 25dbb12e68b553dee27be76d2bcc6657d8e5af80 Mon Sep 17 00:00:00 2001 From: piotr-iohk <42900201+piotr-iohk@users.noreply.github.com> Date: Fri, 27 Sep 2024 14:35:05 +0200 Subject: [PATCH 7/8] Update README.md Co-authored-by: Harry Solovay --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7d9085d..9b59b58 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ You can enable a playground mode, which provides a simplified testing interface, `--playground` flag: ```bash -target/debug/mina_mesh serve --playground +cargo run -- serve --playground ``` When enabled, you can access the playground at the root URL (`/`). From 3cd1ecaf5315dbfd185cc0cd6ab073b6cd0a1ce5 Mon Sep 17 00:00:00 2001 From: piotr-iohk <42900201+piotr-iohk@users.noreply.github.com> Date: Fri, 27 Sep 2024 14:35:47 +0200 Subject: [PATCH 8/8] remove playground enabled log Co-authored-by: Harry Solovay --- src/commands/serve.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/commands/serve.rs b/src/commands/serve.rs index 796fb36..e858273 100644 --- a/src/commands/serve.rs +++ b/src/commands/serve.rs @@ -53,7 +53,6 @@ impl ServeCommand { .with_state(Arc::new(mina_mesh)); if self.playground { router = router.route("/", get(handle_playground)); - tracing::info!("playground enabled"); } let listener = TcpListener::bind(format!("{}:{}", self.host, self.port)).await?; tracing::info!("listening on http://{}", listener.local_addr()?);