From ec66e603df8bdac94cb38913d97577efd1078356 Mon Sep 17 00:00:00 2001 From: barriebyron Date: Wed, 12 Jul 2023 12:27:28 -0400 Subject: [PATCH] update archive node for style --- docs/node-operators/archive-node.mdx | 144 +++++++++++++++------------ 1 file changed, 80 insertions(+), 64 deletions(-) diff --git a/docs/node-operators/archive-node.mdx b/docs/node-operators/archive-node.mdx index df048fc5b..35db09786 100644 --- a/docs/node-operators/archive-node.mdx +++ b/docs/node-operators/archive-node.mdx @@ -1,18 +1,26 @@ --- -title: Archive Node -hide_title: true +title: Overview +description: Mina archive nodes maintain historical information about the network, block, and transactions. A zkApp can retrieve events and actions from one or more Mina archive nodes. +keywords: + - mina archive node + - mina historical information + - events and actions + - archive process + - postgres --- +# Archive Node Overview + :::note A new version of Mina Docs is coming soon! This page will be rewritten. ::: -# Archive Node -Mina nodes are succinct by default, meaning they don't need to maintain historical information about the network, block, or transactions. -For some usecases, it is useful to maintain this historical data, which you can do by running an **Archive Node.** +Mina nodes are succinct by default, so they don't need to maintain historical information about the network, block, or transactions. + +For some use cases, it is useful to maintain this historical data on an archive node. :::tip @@ -20,19 +28,21 @@ A zkApp can retrieve events and actions from one or more Mina archive nodes. If ::: -An **Archive Node** is just a regular mina daemon that is connected to a running archive process. -The daemon will regularly send blockchain data to the archive process, -which will store it in a [Postgres](https://www.postgresql.org/) database. +An archive node is a regular mina daemon that is connected to a running archive process. + +The daemon regularly sends blockchain data to the archive process that stores it in a [PostgreSQL](https://www.postgresql.org/) database. + +Running an archive node requires some knowledge of managing a PostgreSQL database instance. You must set up a database, run the archive node, connect it to a daemon, and run queries on the data. + +## Install Mina, PostgreSQL, and the archive node package + +1. Install the latest version of Mina. -Running an archive node therefore requires some knowledge of managing a Postgres database instance. -In this section, we'll set up a database, run the Archive Node, connect it to a daemon, and try some queries on the data. -Let's get started by installing what we need. + You must upgrade to the latest version of the daemon. Follow the steps in [Getting Started](getting-started). -## Installation +1. Download and install [PostgreSQL](https://www.postgresql.org/download/). -1. Install the latest version of mina. If you haven't upgraded to the latest version of the daemon, head [back to the docs](./getting-started) to get the latest version. You can run `mina -help` to check if the installation succeeded. -2. Install [Postgres](https://www.postgresql.org/download/). -3. Install the archive node package. +1. Install the archive node package. - Ubuntu/Debian: @@ -41,64 +51,70 @@ Let's get started by installing what we need. ``` - Docker: + ``` minaprotocol/mina-archive:1.3.0-9b0369c-bullseye ``` -## Setup - -Below are some basic instructions on how to set up everything required to get an archive node running locally. These will be slightly different if you're connecting to a cloud instance of postgres, if your deployment uses docker, or if you want to run these processes on different machines. - -:::note +## Set up the archive node -Note: Some of these instructions may depend on how your operating system installs postgres (and assume that it is installed in the first place). +These steps might be different for your operating system, if you're connecting to a cloud instance of PostgreSQL, if your deployment uses Docker, or if you want to run these processes on different machines. -::: +For production, run the archive database in the background, use your operating system service manager (like systemd) to run it for you, or use a postgres service hosted by a cloud provider. -1. Start a local postgres server. This will just run it in the foreground for testing, you will likely want to run it in the background or use your OS's service manager (like systemd) to run it for you. Alternatively, you may use a postgres service hosted by a cloud provider. +To run a local archive node to run it in the foreground for testing: -``` -postgres -p 5432 -D /usr/local/var/postgres -``` +1. Start a local postgres server and connect to port 5432: -For macOS, run `brew services start postgres` to start a local postgres server. + ```sh + postgres -p 5432 -D /usr/local/var/postgres + ``` -2. Create database (here called `archive`) on server and load the schema into it. This will only need to be done the first time the archive node is set up. + For macOS: + + ```sh + brew services start postgres + ``` -``` -createdb -h localhost -p 5432 -e archive +1. Create a local postgres database called `archive`: -psql -h localhost -p 5432 -d archive -f <(curl -Ls https://raw.githubusercontent.com/MinaProtocol/mina/master/src/app/archive/create_schema.sql) -``` + ```sh + createdb -h localhost -p 5432 -e archive + ``` -3. Start archive process on port 3086, connecting to the postgres database we started on port 5432 in step 1. +1. Load the mina archive schema into the archive database: -``` -mina-archive run \ - --postgres-uri postgres://localhost:5432/archive \ - --server-port 3086 -``` + ```sh + psql -h localhost -p 5432 -d archive -f <(curl -Ls https://raw.githubusercontent.com/MinaProtocol/mina/master/src/app/archive/create_schema.sql) + ``` -4. Start the daemon, connecting it to the archive process that we just started on port 3086. If you want to connect to an archive process on another machine, you can specify a hostname as well, like `localhost:3086`. +1. Start the archive process on port 3086 and connect to the postgres database that runs on port 5432: -``` -mina daemon \ - ..... - --archive-address 3086\ -``` + ```sh + mina-archive run \ + --postgres-uri postgres://localhost:5432/archive \ + --server-port 3086 + ``` -## Upgrading/Repairing the Archive Data +4. Start the mina daemon and connect it to the archive process that you started on port 3086: -Due to a bug in the originally released archive node version 1.1.5, some early transactions may not be represented properly in your database. See [here](https://gist.github.com/lk86/22b07d3b3f91c765f34e4e4398a84701) for complete instructions on migrating your archive database. + ``` + mina daemon \ + ..... + --archive-address 3086\ + ``` + + To connect to an archive process on another machine, specify a hostname with `localhost:3086`. ## Using the Archive Node -Now that we've got the archive node running, let's take a look at the tables in the database. +Take a look at the tables in the database. + +To list the tables, run the `\dt` command in psql. -To list the tables in the database, you can run the `\dt` command, in psql. -View the full schema of the tables [here](https://github.com/minaProtocol/mina/blob/master/src/app/archive/create_schema.sql). +Review the full schema at [/archive/create_schema.sql](https://github.com/minaProtocol/mina/blob/master/src/app/archive/create_schema.sql). -Below are some notable fields in each table. +Notable fields in each table: ### Table 1: user_commands @@ -106,7 +122,7 @@ Below are some notable fields in each table. This table keeps track of transactions made on the network. -``` +```text ... user_command_type Type of transaction being made Possible values: `'payment', 'delegation' @@ -119,9 +135,9 @@ This table keeps track of transactions made on the network. ### Table 2: internal_commands -This table keeps track of rewards earned from snark work or block producing. +This table keeps track of rewards earned from SNARK work or block producing. -``` +```text ... internal_command_type represents whether the command is a `fee_transfer` from snark work or a `coinbase` reward from block producing. Use this field for information about block rewards and snark rewards (there is also an extra fee_transfer added to support sending all the transaction fees summed together to the block_creator) @@ -132,7 +148,7 @@ This table keeps track of rewards earned from snark work or block producing. ### Table 3: blocks -``` +```text ... id parent_id ID of the previous block in the blockchain @@ -142,9 +158,9 @@ This table keeps track of rewards earned from snark work or block producing. ### Join tables -There are two join tables in the archive database, which links blocks to transactions. -By linking the block table and command tables, these tables allow you to identify -specific transactions within blocks. +Two join tables in the archive database link blocks to transactions. + +By linking the block table and command tables, these tables allow you to identify specific transactions within blocks. #### Join table 1: blocks_user_commands @@ -165,11 +181,11 @@ sequence_no 0-based order of the internal command among the blo secondary_sequence_no 0-based order of a fee transfer within a coinbase internal command ``` -## Try a query +## Query the database -Now that we've taken a look at the structure of the data, let's try a query. +Now that you know the structure of the data, try a query. -**Example 1:** Find all blocks that have been created by your public key +**Example 1:** Find all blocks that were created by your public key: ``` SELECT * @@ -178,7 +194,7 @@ INNER JOIN public_keys AS pk1 ON b.creator_id = pk1.id WHERE value = 'MY_PK' ``` -**Example 2:** Find all payments you’ve received by your public key +**Example 2:** Find all payments received by your public key: ``` SELECT * @@ -189,7 +205,7 @@ WHERE value = 'MY_PK' AND type = 'payment' ``` -**Example 3:** Find the block at height 12 on the canonical chain +**Example 3:** Find the block at height 12 on the canonical chain: ``` WITH RECURSIVE chain AS ( @@ -208,7 +224,7 @@ WITH RECURSIVE chain AS ( WHERE c.height = 12 ``` -**Example 3:** List the counts of blocks created by each public key and sort them in descending order +**Example 3:** List the counts of blocks created by each public key and sort them in descending order" ``` SELECT p.value, COUNT(*) FROM blocks @@ -217,7 +233,7 @@ GROUP BY p.value ORDER BY count DESC; ``` -**Example 4:** List the counts of applied payments created by each public key and sort them in descending order +**Example 4:** List the counts of applied payments created by each public key and sort them in descending order: ``` SELECT p.value, COUNT(*) FROM user_commands