Coda 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.
An Archive Node is just a regular Coda 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 database.
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.
coda -helpto check if the installation succeeded.
brew install postgresql. That will give you both the Postgres server and the command line interface, psql.
brew install codaprotocol/coda/coda-archive
sudo apt-get install -t unstable coda-archive
codaprotocol/coda-daemon:0.0.16-beta5-master-fdc283b and coda-archive:0.0.16-beta5-master-fdc283b
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: Some of these instructions may depend on how your operating system installs postgres (and assume that it is installed in the first place).
postgres -p 5432 -D /usr/local/var/postgres
For macOS, run
brew services start postgres to start a local postgres server.
archiver) on server and load the schema into it. This will only need to be done the first time the archive node is set up.
createdb -h localhost -p 5432 -e archiver psql -h localhost -p 5432 -d archiver -f <(curl -Ls https://raw.githubusercontent.com/CodaProtocol/coda/master/src/app/archive/create_schema.sql)
coda-archive \ -postgres-uri postgres://localhost:5432/archiver \ -server-port 3086
coda daemon \ ..... -archive-address 3086\
Now that we've got the archive node running, let's take a look at the tables in the database.
To list the tables in the database, you can run the
\dt command, in psql.
View the full schema of the tables here.
Below are some notable fields in each table.
This table keeps track of transactions made on the network.
... user_command_type Type of transaction being made Possible values: `'payment', 'delegation', 'create_token', 'create_account', 'mint_tokens'` To see a specific type of transaction, i.e. payments or creating a token, specify this field in your queries. source_id public key of the sender receiver_id public key of the receiver amount amount being sent from the sender to the receiver token ID of a token **If you are querying for different type of token transactions, specify this field.**
This table keeps track of rewards earned from snark work or block producing.
... 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) receiver_id public key ID of the receiver fee amount being sent from the protocol to the receiver token ID of a token **If you are querying for different type of token transactions, specify this field.**
... id parent_id ID of the previous block in the blockchain 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) creator_id public key of the block creator
Now that we've taken a look at the structure of the data, let's try a query.
Example 1: Find all blocks that have been created by your public key
SELECT * FROM blocks AS b 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
SELECT * FROM user_commands AS uc JOIN blocks_user_commands AS buc ON uc.id = buc.user_command_id JOIN public_keys AS pk ON uc.receiver_id = pk.id WHERE value = 'MY_PK' AND type = 'payment'