Skip to content

Commit

Permalink
begin
Browse files Browse the repository at this point in the history
  • Loading branch information
harrysolovay committed Oct 3, 2024
1 parent 9926781 commit 4c1f4a5
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 90 deletions.
28 changes: 28 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Contributing

## Testing

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

### Managing PostgreSQL

- **Stop PostgreSQL**: To stop the PostgreSQL instance:

```bash
just pg-down
```

- **Restart PostgreSQL**: To restart without reinitializing the database (useful if the database is
already set up):

```bash
just pg-up
```

> You only need to reinitialize the database if you want the latest data dump.
112 changes: 27 additions & 85 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,110 +1,52 @@
# Mina Mesh

[![checks](https://github.com/MinaFoundation/MinaMesh/actions/workflows/checks.yaml/badge.svg)](https://github.com/MinaFoundation/MinaMesh/actions/workflows/checks.yaml)

## Overview

Mina Mesh is an implementation of the
[Coinbase Mesh specification](https://docs.cdp.coinbase.com/mesh/docs/welcome) for the
[Mina blockchain](https://minaprotocol.com/).

## Building

To build the project:

```bash
cargo build
```

The binary will be available at:
> Note: Mina Mesh is WIP and should not yet be used in production.
```bash
target/debug/mina_mesh
```

## 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`).
## Installation

### Quick Start with Mainnet
```sh
# Install the mina-mesh executable
cargo install mina-mesh

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
# Confirm installation successful
mina-mesh --help
```

> Note: This process sets up the PostgreSQL docker using the latest mainnet archive database.
2. **Run the Mina Mesh Server**
## Fetch Genesis Block Identifier

To start the server with default settings (mainnet configuration):
Before running the server, we must first write genesis block identifier information to our `.env`
file.

```bash
target/debug/mina_mesh serve
```sh
mina-mesh fetch-genesis-block-identifier >> .env
```

The server will listen on `0.0.0.0:3000` by default.
> Note: this command utilizes a default GraphQL endpoint
> ("https://mainnet.minaprotocol.network/graphql"). You can override this default by specifying a
> `PROXY_URL` in your `.env` file.
### Playground Mode
## Instantiate the Server

You can enable a playground mode, which provides a simplified testing interface, by adding the
`--playground` flag:
Mina Mesh depends on a Postgres connection string for an archive database.

```bash
cargo run -- serve --playground
```

When enabled, you can access the playground at the root URL (`/`).

### Configuration
Ensure that you also specify an archive `DATABASE_URL` in your `.env`.

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
cp .env.example .env
```sh
mina-mesh serve --playground
```

Then modify the `.env` file to suit your environment. The available configurations include:

- **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.
> Note: you may want to exclude the `--playground` flag in production. This will disable the
> playground, which renders when the server's root `/` route receives a GET request.
## Testing
Alternatively, you can supply the archive database URL via the command line.

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
```sh
mina-mesh serve --playground --database-url postgres://mina:whatever@localhost:5432/archive
```

### Managing PostgreSQL

- **Stop PostgreSQL**: To stop the PostgreSQL instance:

```bash
just pg-down
```

- **Restart PostgreSQL**: To restart without reinitializing the database (useful if the database is
already set up):

```bash
just pg-up
```

> You only need to reinitialize the database if you want the latest data dump.
Then visit [`http://0.0.0.0:3000`](http://0.0.0.0:3000) for an interactive playground with which you
can explore and test endpoints.
7 changes: 2 additions & 5 deletions src/commands/fetch_genesis_block_identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@ use crate::graphql::QueryGenesisBlockIdentifier;
#[command(about = "Retrieve the genesis block identifier via a proxy node GraphQL endpoint.")]
pub struct FetchGenesisBlockIdentifierCommand {
#[arg(long, short = 'n', default_value = "https://mainnet.minaprotocol.network/graphql")]
proxy_node_graphql_endpoint: String,
proxy_url: String,
}

impl FetchGenesisBlockIdentifierCommand {
pub async fn run(&self) -> Result<()> {
let client = reqwest::Client::new();
let result = client
.post(self.proxy_node_graphql_endpoint.to_owned())
.run_graphql(QueryGenesisBlockIdentifier::build(()))
.await?;
let result = client.post(self.proxy_url.to_owned()).run_graphql(QueryGenesisBlockIdentifier::build(())).await?;
if let Some(inner) = result.data {
let genesis_block_hash = inner.genesis_block.state_hash.0;
let genesis_block_index = inner.genesis_block.protocol_state.consensus_state.block_height.0;
Expand Down

0 comments on commit 4c1f4a5

Please sign in to comment.