Webux Lab - Blog
Webux Lab Logo

Webux Lab

By Studio Webux

Search

By Tommy Gingras

Last update 2023-09-02

Blockchain

Testing Mina Protocol and block producer

I know I need staking ...

But I wanted to experiment and compare with Cardano Network the infrastrucutre aspect of it.

Here are the commands I ran to setup Everything.

Prepare directory:

sudo mkdir /srv/mina
mkdir /srv/mina/{keys,.mina-config}
ls -alp /srv/mina

chmod 700 /srv/mina/keys

Create Wallet and keys (private and public):

docker run \
    -it \
    --rm \
    -v /srv/mina/keys:/keys \
    minaprotocol/mina-generate-keypair:1.3.1-3e3abec \
        --privkey-path /keys/my-wallet
sudo chmod 600 /srv/mina/keys/my-wallet
ls -al /srv/mina/keys/

Validate Key:

docker run \
    -it \
    --rm \
    --entrypoint=mina-validate-keypair \
    -v /srv/mina/keys:/keys \
    minaprotocol/mina-generate-keypair:1.3.1-3e3abec \
        --privkey-path /keys/my-wallet

Create the env file:

export MINA_PRIVKEY_PASS="__YOUR_SECURE_PASSWORD__"
export BLOCK_PRODUCER_KEY_PATH="/keys/my-wallet"
export MINA_PUBLIC_KEY="B62qpawLEW6N9v4PoZ4jVpPMbMnCN2Vd8qWEd1EFQSVt8wM7itfuzHw"
cat <<EOF > /srv/mina/.mina-env
export MINA_PRIVKEY_PASS="$MINA_PRIVKEY_PASS"
LOG_LEVEL=Info
FILE_LOG_LEVEL=Debug
EXTRA_FLAGS=" --block-producer-key $BLOCK_PRODUCER_KEY_PATH --open-limited-graphql-port --limited-graphql-port 3095 --uptime-submitter-key $BLOCK_PRODUCER_KEY_PATH --uptime-url https://uptime-backend.minaprotocol.com/v1/submit --run-snark-worker $MINA_PUBLIC_KEY --snark-worker-fee 0.01 --libp2p-metrics-port 3395 --metrics-port 3396 --archive-address host.docker.internal:3086"
PEER_LIST_URL=https://storage.googleapis.com/seed-lists/mainnet_seeds.txt
UPTIME_PRIVKEY_PASS="$MINA_PRIVKEY_PASS"
EOF

Using this option : --insecure-rest-server Exposes you to a risk., you should not do this unless you know what you are doing.

Start the Node:

docker network create mina-network
docker run --name mina -d \
    -p 8302:8302 \
    -p 3095:3095 \
    -p 3085:3085 \
    -p 3395:3395 \
    -p 3396:3396 \
    --restart=always \
    --network mina-network \
    --add-host=host.docker.internal:host-gateway \
    -v /srv/mina/.mina-env:/entrypoint.d/mina-env:ro \
    -v /srv/mina/keys:/keys:ro \
    -v /srv/mina/.mina-config:/root/.mina-config \
    --log-driver syslog \
    --log-opt syslog-address="udp://localhost:5514" \
    --log-opt syslog-format="rfc3164" \
    --log-opt tag="mina" \
    minaprotocol/mina-daemon:1.4.0-c980ba8-bullseye-mainnet \
        daemon

DO NOT EXPOSE THE 3095, 3395, 3396 to public or unsecure network. It represents a risk to do so.

Start the sidecar:

cat <<EOF > /srv/mina/mina-sidecar-config.json
{
  "uploadURL": "https://us-central1-mina-mainnet-303900.cloudfunctions.net/block-producer-stats-ingest/?token=72941420a9595e1f4006e2f3565881b5",
  "nodeURL": "http://mina:3095"
}
EOF
docker run \
     -d \
    --name mina-sidecar \
    --network mina-network \
    --link mina:mina \
    --restart=always \
    --log-driver syslog \
    --log-opt syslog-address="udp://localhost:5514" \
    --log-opt syslog-format="rfc3164" \
    --log-opt tag="mina" \
    -v /srv/mina/mina-sidecar-config.json:/etc/mina-sidecar.json \
    minaprotocol/mina-bp-stats-sidecar:latest
docker logs -f mina-sidecar

Monitor the node:

docker logs mina -f
docker stats mina
docker exec -it mina mina client status

Other steps and notes:

  • Open the port 8302 in your Router (and firewall)
  • Status: Bootstrap to Catchup (around 23 minutes) to Synced (around 30 minutes)

Troubleshooting:

docker run --name mina-debug -it --rm \
    -v /srv/mina/.mina-env:/entrypoint.d/mina-env:ro \
    -v /srv/mina/keys:/keys:ro \
    -v /srv/mina/.mina-config:/root/.mina-config \
    --entrypoint /bin/bash \
    minaprotocol/mina-daemon:1.4.0-c980ba8-bullseye-mainnet

The public key I have is : B62qpawLEW6N9v4PoZ4jVpPMbMnCN2Vd8qWEd1EFQSVt8wM7itfuzHw

Conclusion

That was quite easy to setup using docker !

I followed the official documentation, it is good but not linear (like the next page at the bottom doesn't match with the next step mentionned on the current step).


Mina SNARK fees

You can use this page to determine the fee : https://minaexplorer.com/snark-fees

docker exec -it mina mina client status | grep "SNARK work fee" | xargs
docker exec -it mina mina client set-snark-work-fee 0.001

I published some nodejs code to collect metrics about the SNARK, the end goal is to use those metrics to trigger a webhook in order to dynamically setup the fee. (Not done yet)

Link to the prometheus SNARK Metrics: https://github.com/studiowebux/mina-snark-metrics


Archive Node

sudo mkdir -p /srv/mina/postgres-data/
sudo chown 1000:1000 /srv/mina/postgres-data/

sudo mkdir -p /srv/mina/archive
sudo chown 1000:1000 /srv/mina/archive
cd /srv/mina/archive
curl -O https://webuxlab.com/content/devops/mina-protocol/docker-compose.yml

# Don't forget to review and update the docker-compose.yml file

docker compose up -d

docker exec -it archive-postgres-1 createdb -U postgres archive
curl -Ls https://raw.githubusercontent.com/MinaProtocol/mina/master/src/app/archive/create_schema.sql | docker exec -i postgres psql -U postgres -d archive

docker compose logs -f

Graphql

Port 3095 has the information about blocks and daemonStatus, there is NO mutations. It returns the data similar to the mina cli commands (mina client status)

Port 3085 has mutations and queries, you can do everything using this graphql endpoint. Be careful because it gives access to the node to anybody who can access it as well!