1
1

More than 1 year has passed since last update.

Algorand Node with Goracle【English & 日本語】

Last updated at Posted at 2023-04-10

Introduction

This article is about setting up an Algorand node on an existing Goracle node. This allows the Goracle node to use Algorand APIs and RPCs internally without relying on external services.

Furthermore, detailed explanations are provided to familiarize operators with Linux, blockchain, and oracles as much as possible. I hope that this will be helpful to everyone.

@Moon1215i

If you are interested in Goracle, please follow me on Twitter:
https://twitter.com/Moon1215i

【日本語】

この記事では、GoracleノードにAlgorandノードを統合することで、GoracleノードがAlgorandのAPIやRPCを外部に依存することなく自立的に使用できるようになることが述べられています。

またできるだけオペレーターがLinuxやブロックチェーン、オラクルに馴染んでいただくために、解説を詳しくしています。皆さんのお役に立てることを願っています。

@Moon1215i

もしGoracleに興味がある場合は、Twitterで私をフォローしてください。
https://twitter.com/Moon1215i

Official Recommended Site 公式推薦サイト

Official Site Reference 参照した公式サイト

Unofficial Site Reference 参照した非公式サイト

1. Install Required Packages on Ubuntu

1. Ubuntuに必要なパッケージをインストール

1
sudo apt update
sudo apt install -y gnupg2 curl software-properties-common

This command can be executed on Linux distributions such as Ubuntu and Debian. Here are the details:

  • Description: This is a command to install necessary packages.
  • Command name: sudo apt install
  • Options:
    • -y: Skips the package installation confirmation and automatically answers "Yes" to all questions.
  • Package names:
    • gnupg2: Version 2 of the GnuPG package. It is a toolset for encrypting and signing data using public-key cryptography.
    • curl: A tool for manipulating URLs from the command line.
    • software-properties-common: A tool for managing software repositories.
【日本語】

このコマンドはUbuntuやDebianなどのLinuxディストリビューションで実行することができます。以下のとおりです。

  • 説明:必要なパッケージをインストールするためのコマンドです。
  • コマンド名:sudo apt install
  • オプション:
    • -y:パッケージのインストール確認を省略し、全ての質問に自動的に"Yes"を答えます。
  • パッケージ名:
    • gnupg2GnuPGパッケージのバージョン2です。公開鍵暗号方式を利用して、データの暗号化や署名を行うためのツールセットです。
    • curl:コマンドラインからURLを操作するためのツールです。
    • software-properties-common:ソフトウェアのリポジトリを管理するためのツールです。

2. Acquiring Algorand Public Key

2. Algorand公開鍵の取得

2
curl -o - https://releases.algorand.com/key.pub | sudo tee /etc/apt/trusted.gpg.d/algorand.asc

This command downloads the GPG key from the official Algorand release and adds it to the system's list of trusted GPG keys. Specifically, it performs the following actions:

  1. Download Algorand's public key.
  2. Save the downloaded key to /etc/apt/trusted.gpg.d/algorand.asc.
  3. Add the key to the system's list of trusted GPG keys.

This command is used to obtain the Algorand public key. The Algorand public key is a key required to use the Algorand repository, and it needs to be added before installing.

This command downloads the Algorand public key from https://releases.algorand.com/key.pub and saves it to /etc/apt/trusted.gpg.d/algorand.asc using the sudo tee command. This allows the system to verify that packages from the Algorand repository are trustworthy. Additionally, GPG keys are used to verify the authenticity of software packages.

【日本語】

このコマンドは、Algorandの公式リリースからGPG鍵をダウンロードし、システムの信頼できるGPG鍵リストに追加します。具体的には、以下の処理を行います。

  1. Algorandの公開鍵をダウンロード
  2. ダウンロードした鍵を/etc/apt/trusted.gpg.d/algorand.ascに保存
  3. システムの信頼できるGPG鍵リストに追加

このコマンドは、Algorand公開鍵を取得するためのものです。Algorand公開鍵は、Algorandのリポジトリを使用するために必要な鍵であり、インストールする前にこの鍵を追加する必要があります。

このコマンドは、https://releases.algorand.com/key.pubからAlgorandパブリックキーをダウンロードし、sudo teeコマンドを使用して/etc/apt/trusted.gpg.d/algorand.ascに保存します。これにより、Algorandリポジトリのパッケージが信頼できるものであることをシステムが確認できるようになります。

Screenshot by Dropbox Capture.png

3. Add Algorand Repository to Ubuntu

3. AlgorandのリポジトリをUbuntuに追加

3
sudo add-apt-repository "deb [arch=amd64] https://releases.algorand.com/deb/ stable main"
sudo apt update

These two commands are used to add the Algorand repository to Ubuntu. The first command downloads and installs the GPG key associated with the Algorand repository. The second command updates the Ubuntu package list so that Ubuntu can download packages from the Algorand repository.

【日本語】

上記の2つのコマンドは、UbuntuにAlgorandのリポジトリを追加するために使用されます。最初のコマンドは、Algorandリポジトリに関連するGPG鍵をダウンロードしてインストールします。2番目のコマンドは、UbuntuがAlgorandリポジトリからパッケージをダウンロードできるように、Ubuntuパッケージリストを更新します。

Screenshot by Dropbox Capture.png

4. Install Algorand Development Tools

4. Algorand開発ツールのインストール

4
sudo apt install -y algorand-devtools

This command installs the development tools necessary to develop applications related to the Algorand blockchain. Before running this command, you need to add the Algorand repository first.

【日本語】

このコマンドは、Algorandブロックチェーンに関するアプリケーションを開発するために必要な開発ツールをインストールします。このコマンドを実行する前に、先にAlgorandリポジトリを追加する必要があります。

Screenshot by Dropbox Capture.png

5. Check Algorand node version

5. Algorand nodeのバージョン確認

5
algod -v

This command is used to check the version of the Algorand node. "algod" is the official node software of Algorand.

【日本語】

このコマンドは、Algorand nodeのバージョンを確認するために使用されます。"algod"は、Algorandの公式ノードソフトウェアです。

Screenshot by Dropbox Capture.png

These commands will install and configure algod as a service and place the algorand binaries in the /usr/bin directory. These binaries will be in the path so the algod and goal commands can be executed from anywhere. Additionally, every node has a data directory, in this case, it will be set to /var/lib/algorand.

This install defaults to the Algorand MainNet network. See switching networks for details on changing to another network.

【日本語】

これらのコマンドは、algodをサービスとしてインストールおよび構成し、algorandのバイナリを/usr/binディレクトリに配置します。これらのバイナリはパスに含まれるため、algodおよびgoalコマンドをどこからでも実行できます。さらに、各ノードにはデータディレクトリがあります。この場合、データディレクトリは/var/lib/algorandに設定されます。

6. Switch Algorand node to TestNet

6. Algorandノードのテストネットへの変更

In order for the Algorand blockchain network to function correctly when new nodes join, it is necessary to define the initial state of the blockchain. Algorand uses a Genesis file to define this initial state.

The Genesis file is a JSON file that defines the first block added to the Algorand network. It describes the initial state of the network, including the hash value of the first block added, the transactions and addresses contained in that block, and other details.

Algorand has multiple Genesis files, each for a different network, such as MainNet, TestNet, and Betanet. By switching between these Genesis files, nodes can join different networks.

Additionally, in Algorand, changing the Genesis file that defines the state of the network can cause a fork in the blockchain.

【日本語】

アルゴランドのブロックチェーンネットワークは、新しいノードが参加しても正しく動作するように、最初にブロックチェーンの状態を定義する必要があります。この初期の状態を定義するために、アルゴランドではGenesisファイルが使用されます。

Genesisファイルは、JSON形式で記述されたファイルで、アルゴランドのネットワークに参加する最初のブロックを定義します。つまり、最初に追加されるブロックのハッシュ値や、そのブロックに含まれるトランザクションやアドレスなど、ネットワークの最初の状態が記述されています。

アルゴランドでは、複数のGenesisファイルがあります。例えば、MainNetTestNetBetanetなど、それぞれ異なるネットワークのGenesisファイルが存在します。これらのGenesisファイルを切り替えることで、異なるネットワークに参加することができます。

また、アルゴランドでは、ネットワークの状態を定義するGenesisファイルを変更することで、ブロックチェーンのフォークを発生させることもできます。

Screenshot by Dropbox Capture.png

6
sudo systemctl stop algorand
sudo cp /var/lib/algorand/genesis/testnet/genesis.json /var/lib/algorand/

This command is used to switch the network of an Algorand node. If the Algorand node is already running, it needs to be stopped before switching the network. However, if the node is already stopped, you can skip this command. Next, the genesis.json file for the testnet is copied to the default directory of the Algorand node.

【日本語】

このコマンドは、Algorandノードの実行を停止するために使用されます。ネットワークを切り替える前に、Algorandノードを停止する必要があります。次に、テストネット用のgenesis.jsonファイルをAlgorandノードのデフォルトディレクトリにコピーします。

Screenshot by Dropbox Capture.png

7. Restarting Algorand Node on TestNet

7. テストネットでアルゴランドノードの再起動

7
sudo systemctl start algorand
goal node status -d /var/lib/algorand

This command is used to start an Algorand node that has been switched from the mainnet to the testnet, and to check its status. First, run sudo systemctl start algorand to start the Algorand node.

Then, run goal node status -d /var/lib/algorand to check the status of the node. This command allows you to confirm whether the node has started up successfully and is able to participate in the network.

【日本語】

このコマンドは、メインネットからテストネットへ切り替えたAlgorandノードを起動し、そのステータスを確認するために使用されます。まず、Algorandノードを起動するために、sudo systemctl start algorandを実行します。

次に、goal node status -d /var/lib/algorandを実行して、ノードのステータスを確認します。このコマンドを使用することで、ノードが正常に起動し、ネットワークに参加できているかどうかを確認することができます。

Screenshot by Dropbox Capture.png

8. Fast Sync Algorand Node to TestNet

8. アルゴランドノードのテストネットへの高速同期

Fast Sync is one of the methods for Algorand nodes to synchronize with the blockchain quickly and accurately. Instead of retrieving existing blockchain data, the node downloads the latest blockchain data from the network to speed up synchronization. This allows new nodes to join the network and reduces the node's startup time.

Please copy and paste the following command into your terminal and press Enter to execute it.

【日本語】

Fast Syncは、Algorandノードが高速で正確なブロックチェーン同期を行うための手法の一つです。ノードが既存のブロックチェーンデータを取得する代わりに、ネットワークから最新のブロックチェーンデータをダウンロードすることで同期を高速化します。これにより、新しいノードをネットワークに参加させることができ、ノードの起動時間を短縮することができます。

以下のコマンドをコピーしてターミナルに貼り付け、Enterキーを押して実行してください。

Fast Sync

8-1
printf "\n\033[0;33m=== Fast Sync Algorand Node to TestNet ===\033[0m\n\n" && \
goal node catchup $(curl -s https://algorand-catchpoints.s3.us-east-2.amazonaws.com/channel/testnet/latest.catchpoint) -d /var/lib/algorand/ && \
printf "Done.\n\n"

These commands are used to set up a local node that operates on Algorand's TestNet. First, the latest catchpoint is downloaded and the local Algorand node is synchronized.

【日本語】

これらのコマンドは、AlgorandのTestNetで動作するローカルノードを設定するために使用されます。最初に最新のキャッチポイントをダウンロードし、ローカルのAlgorandノードを同期させます。

A new option can facilitate a status watch, -w which takes a parameter of time, in milliseconds, between two successive status updates. This will eliminate the need to repeatedly issue a status manually. Press Control + C to exit the watch.

goal node status -w 1000 -d /var/lib/algorand
# Press `Control + C` to exit the watch

Screenshot by Dropbox Capture.png
Notice that the 5 Catchpoint status lines will disappear when completed, and then only a few more minutes are needed to sync from that point to the current block. Once there is a Sync Time of 0, the node is synced and if fully usable.

Configure and Display Status

8-2
ALGOD_TOKEN=$(cat /var/lib/algorand/algod.token) && \
ALGOD_NET="http://$(cat /var/lib/algorand/algod.net)" && \
printf "\n\033[0;33m==== Your algod.token ====\033[0m\n\n%s\n\n\033[0;33m==== Your algod.net ====\033[0m\n\n%s\n" "$ALGOD_TOKEN" "$ALGOD_NET" && \
cat ~/.goracle | jq -S > ~/.goracle_new && mv ~/.goracle_new ~/.goracle && \
sed -i '/"authKey":.*/d' ~/.goracle  && \
sed -i '/"authHeader":.*/d' ~/.goracle  && \
sed -i 's#"server":.*#"server": "'"$ALGOD_NET"'",#' ~/.goracle  && \
sed -i 's#"token":.*#"token": "'"$ALGOD_TOKEN"'"#' ~/.goracle && \
printf "\n\033[0;33m=== This is your current ~/.goracle file ===\033[0m\n\n$(cat ~/.goracle)\n" && \
printf "\n\033[0;33m=== Getting Algorand node status ===\033[0m\n\n$(goal node status -d /var/lib/algorand)\n\n"

Then, the token and node URL are read from the algod.token and algod.net files and set to their respective fields in the ~/.goracle file. The authKey and authHeader fields are then removed. Finally, the goal node status command is used to display the state of the local node.

【日本語】

次に、algod.tokenalgod.netファイルからトークンとノードのURLを読み取り、それらを~/.goracleファイルの該当するフィールドに設定します。そして、authKeyauthHeaderフィールドは削除されます。最後に、goal node statusコマンドを使用して、ローカルノードの状態を表示します。

Screenshot by Dropbox Capture.png

The algod.token and algod.net files are configuration files for the Algorand node software, specifically the algod component.

The algod.token file contains an authentication token that is used to access certain API endpoints on the algod server. This token is generated automatically by the algod software and is stored in this file.

The algod.net file specifies the network address and port number that the algod server will listen on for incoming API requests. In this case, the address is set to 127.0.0.1, which means that the algod server will only accept requests from the local machine, and the port number is set to 8080.

【日本語】

algod.tokenファイルとalgod.netファイルは、Algorandノードソフトウェアの構成ファイルであり、特にalgodコンポーネントに関連しています。

algod.tokenファイルには、algodサーバー上の特定のAPIエンドポイントにアクセスするために使用される認証トークンが含まれています。このトークンは、algodソフトウェアによって自動的に生成され、このファイルに保存されます。

algod.netファイルは、algodサーバーがAPIリクエストを受信するためにリッスンするネットワークアドレスとポート番号を指定します。この場合、アドレスは127.0.0.1に設定されており、これはalgodサーバーがローカルマシンからのリクエストのみを受け付けることを意味し、ポート番号は8080に設定されています。

9. Restarting Algorand Node

9. アルゴランドノードの再起動

9
sudo systemctl restart algorand && \
sleep 10 && \
goal node status -d /var/lib/algorand

The first command, sudo systemctl restart algorand, restarts the Algorand system service. This restarts the Algorand node and updates its configuration. The next command allows you to check whether the Algorand node has started properly and is synchronized.

Please confirm that the sync time is 0.0s. If it is not 0.0s, please run goal node status -d /var/lib/algorand occasionally and wait until it becomes 0.0s.

【日本語】

最初のコマンドsudo systemctl restart algorandは、Algorandのシステムサービスを再起動します。このコマンドにより、Algorandノードが再起動され、ノードの設定が更新されます。次のコマンドで、Algorandノードが正常に起動し、同期されているかどうかを確認できます。

Sync Time: 0.0sであることを確認してください。もし0.0sでない場合は、時々goal node status -d /var/lib/algorandを実行して、0.0sになるまで待ってください。

Screenshot by Dropbox Capture.png

10. Restarting Goracle Node

10. ゴラクルノードの再起動

10
#!/bin/bash

GORACLE="$HOME/goracle"
if [ ! -f "$GORACLE" ]; then
    cd ~/
    wget https://staging.dev.goracle.io/downloads/latest-staging/goracle
    chmod u+x "$GORACLE"
fi && \
sleep 5 && \
./goracle docker-stop && \
sleep 5 && \
./goracle docker-start --background && \
sleep 3 && \
docker logs -f goracle-nr

This command stops the Docker container by running ./goracle docker-stop, waits for 5 seconds, and then starts the container in the background by running ./goracle docker-start --background.

Then, it waits for 3 seconds and runs docker logs -f goracle-nr to display the logs of the specified Docker container in real-time. The && is used to execute the next command only if the previous command is successful. Each sleep command is used to wait for the specified number of seconds.

Additionally, if the goracle file does not exist in the $HOME directory, the script downloads it from https://staging.dev.goracle.io/downloads/latest-staging/goracle, saves it in $HOME/goracle, and grants it execution permission before executing the above commands.

【日本語】

このコマンドは、./goracle docker-stopを実行してDockerコンテナを停止し、5秒間待機してから./goracle docker-start --backgroundを実行します。その後、3秒待機してから、docker logs -f goracle-nrを実行します。

&&は、前のコマンドが成功した場合にのみ、次のコマンドを実行するために使用されます。それぞれのsleepコマンドは、指定された秒数だけ待機するために使用されます。

最後のdocker logs -f goracle-nrコマンドは、指定されたDockerコンテナのログをリアルタイムで表示するために使用されます。-fフラグは、ログの末尾を追跡するために使用されます。

また$HOMEディレクトリにgoracleが存在しない場合に、https://staging.dev.goracle.io/downloads/latest-staging/goracleからダウンロードし、$HOME/goracleに保存して実行権限を与え、上記のコマンドを実行します。

Screenshot by Dropbox Capture.png

11. Uninstall and Reinstall Algorand Node for Unstable Performance

11. Algorandノードが動作が不安定な時にするアンインストールと再インストール

If you encounter any issues with the operation of the Algorand node, you can uninstall and reinstall it.

Before uninstalling the Algorand node, it is important to stop the node. If the Algorand node is still running, it may be writing data. Stopping the node before uninstalling can prevent data corruption or loss. You can stop the node by using the following command:

11-1
sudo systemctl stop algorand

To completely remove the Algorand package and all associated files, settings, and data from the system, use the following command:

11-2
sudo apt purge algorand

Note that this is a powerful command and should be used with caution, as it will delete all data associated with the node.

To reinstall the Algorand package, use the following command:

11-3
sudo apt install algorand

This command will reinstall the Algorand node and create necessary files and settings. However, the node's configuration files may retain previous data and settings.

Once the installation is complete, proceed to Step 6 in the Switch Algorand Node to TestNet guide and execute the subsequent commands.

【日本語】

Algrandノードの動作に不具合があると思われる場合には、アルゴランドノードをアンインストールして、再インストールすることができます。

Algorandノードをアンインストールする前には、ノードを停止してから実行することが重要です。Algorandノードが実行されている場合、ノードがデータを書き込んでいる可能性があります。そのため、ノードを停止してからアンインストールを実行することで、データの破損や損失を防止することができます。ノードを停止する方法は、以下のコマンドを使用することで実行できます。

11-1
sudo systemctl stop algorand

次に、システムからAlgorandパッケージを完全に削除するために次のコマンドを実行します。

11-2
sudo apt purge algorand

このコマンドを実行すると、Algorandノードに関連するすべてのファイル、設定、およびデータが削除されます。注意してください、これは非常にパワフルなコマンドで、ノードのデータが完全に削除されるため、慎重に使用する必要があります。

そしてAlgorandパッケージを再インストールするために、次のコマンドを実行します。

11-3
sudo apt install algorand

このコマンドを実行すると、Algorandノードが再インストールされ、必要なファイルと設定が作成されます。ただし、ノードの設定ファイルによっては、以前のデータや設定が引き継がれることがあります。

インストールが終わったら、6.Switch Algorand node to TestNet に戻って以降のコマンドを実行してください。

Author

@Moon1215i

If you are interested in Goracle, please follow me on Twitter:

https://twitter.com/Moon1215i

It would be great if I could receive a comment on Twitter, even just a few words.

Screenshot by Dropbox Capture.png

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1