zkapps-dashboard

by O(1) Labs

Helm chartv0.1.2App 1.16.2Verified publisher

A Helm chart for Mina zkapps metrics

About this chart

Mina zkApps Dashboard

  • Dashboard Architecture
  • Helm Chart Installation
    • Optional Configuration
  • Updating zkApp Queries
  • Connecting to Grafana
  • Future Work

Dashboard Architecture

The Mina zkApps dashboad is an auxiliary database that queries a Mina Archive DB on a schedule before saving the returned query results locally. This Helm chart installs the Mina protocol zkapps dashboard including the following components:

  • zkApp dashboard database (Postgresql)
  • Persistent storage volumes (PVC)
  • Scheduled zkapp archive node queries (Cron Job)
  • Kubernetes load balancer

The chart also has a dependency on the Bitnami/postgresql Helm chart. Bitnami postgres configuration parameters are here. A top-level diagram of the zkApps dashboard architecture and the data sources it connects to is shown below:

Helm Chart Installation

This Helm chart can be installed manually using Helm, or bundled as part of a network deployment using Terraform. By default, the chart has password values set to null, so both postgresql.primary.initdb.password and postgresql.auth.password are required values that must be set at the time of deployment. The following command is an example of installing this Helm chart using a local copy of the repository source:

helm install <deployment name> . -n <kubernetes namespace> \
    --set postgresql.primary.initdb.password=< secret password > \
    --set postgresql.auth.password=< secret password >

NOTE: Ensure that values passed using the --set option do not end in a special character. Terminating with a special character will cause errors during yaml parsing

Optional Configuration

The following table lists the configurable parameters of the zkapps-dashboard chart and its default values. These values are set within the values.yaml file within the helm chart.

ParameterDescriptionDefault
postgresql.primary.namename assigned to backend database used by the zkApps dashboarddashboard-db
postgresql.primary.service.typenetwork connection used to expose the zkApps dashboardLoadBalancer
postgresql.primary.persistence.enabledenable or disable persistent storagetrue
postgresql.primary.persistence.sizestorage disk size100Gi
postgresql.primary.persistence.storageClassstorage disk typessd-delete
postgresql.primary.initdb.userdefault database usermina
postgresql.primary.initdb.passworddefault database passwordnull
postgresql.primary.initdb.scriptsscript to initialize the zkApp dashboard database tablezkapp-table.sql : CREATE TABLE zkapps (time timestamp, unique_zkapps INT, total_zkapps INT, successful_txns INT, failed_txns INT, total_txns INT, successful_payments INT, failed_payments INT, total_payments INT, total_acct_updates INT);
postgresql.auth.usernamezkApps dashboard database usermina
postgresql.auth.passwordzkApps dashboard database passwordnull
postgresql.auth.databasethe database which allows access for the zkApps database userdashboard-db
postgresql.auth.enablePostgresUserenable or disable default postgresql userfalse
nodeSelector.preemptibleenable or disable the use of preemptible serversfalse
archive.namename of Mina archive node which the zkApps dashboard queriesarchive-1
archive.databasename of the Mina archive node databasearchive
archive.auth.usernameusername used to authenticate with the Mina archive nodemina
archive.auth.passwordpassword used to authenticate with the Mina archive nodezo3moong7moog4Iep7eNgo3iecaesahH

Updating zkApps Queries

Within this helm package, the db-cron.yaml holds the queries that are run. Queries can be added, removed, or updated by editing this file. At a high-level, all queries are done in two parts; the first part is the recursive query of the current chain state shown below:

RECURSIVE_CHAIN="WITH RECURSIVE chain AS (
SELECT id,state_hash,parent_id,parent_hash,creator_id,block_winner_id,snarked_ledger_hash_id,
staking_epoch_data_id,next_epoch_data_id,
min_window_density,total_currency,
ledger_hash,height,global_slot_since_hard_fork,global_slot_since_genesis,
timestamp,chain_status
FROM blocks b WHERE b.id =(select id from blocks where height = (select MAX(height) from blocks) LIMIT 1)
UNION ALL
SELECT b.id,b.state_hash,b.parent_id,b.parent_hash,b.creator_id,b.block_winner_id,b.snarked_ledger_hash_id,
b.staking_epoch_data_id,b.next_epoch_data_id,
b.min_window_density,b.total_currency,
b.ledger_hash,b.height,b.global_slot_since_hard_fork,b.global_slot_since_genesis,
b.timestamp,b.chain_status
FROM blocks b
INNER JOIN chain
ON b.id = chain.parent_id AND (chain.id <> 1 OR b.id = 1)
)";

Note that all queries run by the zkApps dashboard have a dependency on this recursive chain result that is returned. If the chain query returns bad data, or an incorrect value due to missing blocks within the Mina Archive DB, this will also be seen in query results.

The second part is a query of the recursive chain that was previous returned. An example query excerpted from db-cron.yaml is shown below:

TOTAL_PAYMENTS_QUERY="select count(*) from chain b left join blocks_user_commands bc on b.id = bc.block_id where bc.user_command_id is not null ;";

Again note that the above TOTAL_PAYMENTS_QUERY references table data coming from the recursive chain query. If data for an intended query is not existing in the recursive query, or if the Mina Archive database schema is changed, the root recursive chain query used here may also need to be updated.

Connecting to Grafana

The final destination of zkApp query data is typically a Mina zkApp Metrics Grafana dashboard. Once the zkapps-dashboard Helm chart has been installed to Kubernetes, it must be added as a "datasource" within Grafana before it can be queried and displayed within the dashboard. Instructions for adding a new postgresql database to Grafana can be found here. Note that Admin permissions are required to modify Grafana data sources.

When adding the new postgres datasource, as long as "zkapps" is included within the source name, it will be detected and become available as a dropdown choice within the existing Mina zkApps Metrics dashboard. The recommended convention for naming zkApps dashboard datasources is: <zkapps>-<network name here>. For example: zkapps-mainnet or zkapps-berkeley.

Future Work

The current iteration of the zkApps dashboard employs basic password security. It is possible to enable SSL encryption, certificate authentication, or further security as part of future work.

Deploy zkapps-dashboard with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has zkapps-dashboard on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartzkapps-dashboard is pinned at v0.1.2 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply