Cover photo

使用Azure架設Aptos區塊鏈驗證者節點(AIT-3)

使用Microsoft Azure及Ubuntu 20.04架設Aptos區塊鏈驗證者節點

什麼是Aptos區塊鏈?

Aptos是與以太坊、Solana一樣具有智能合約功能的全新Layer 1區塊鏈,可視為 Meta(原 Facebook)Libra(後更名 Diem)計劃擱淺後的續篇。Diem 被 Meta 出售後,一些核心成員出走,組建團隊基於 Diem 的開源代碼進行 Aptos 公鏈的開發。

Aptos 獲得了** a16z、FTX Ventures 、Coinbase Ventures 以及 Binance Labs **等頂級機構的投資。

Aptos區塊鏈有什麼特點?

Aptos 的最大特點在於採用了全新的開發語言 Move,這一語言原本是為 Diem 項目開發而設計的編程語言,注重區塊鏈的安全性、可擴展性和可升級性。

自2022年 3 月啟動測試網以來,Aptos 經歷了多輪測試,測試網路已有超過 2 萬個驗證節點。數據顯示,當前 Aptos 可實現每秒處理 1 萬筆以上的交易,理想狀態下,該公鏈未來每秒可處理16萬筆交易。

Aptos區塊鏈的發展進度?

2022/08/20官方公告,揭示激勵測試網 3(AIT-3)的註冊、時間表和激勵標準等細節。團隊表示,AIT-3 帶來了主網的最後一個主要交付功能:鏈上治理和升級。為了反映主網啟動的現實環境,AIT-3 參與者的數量將比照 AIT-2,大約有 225 名參與者。

參加Aptos測試網有什麼好處?

目前Aptos進行到激勵測試網3(AIT-3)滿足條件的用戶將獲得*** 800 枚 Aptos*** 代幣獎勵。

AIT-3 激勵條件

所有選定的參與者都應:

  • 訪問 Aptos 治理平台以註冊、質押和指定其運營者(與驗證者關聯的帳戶)

  • 在鏈上部署驗證者節點並註冊

  • 加入驗證者集

  • 對 3 個不同的治理提案進行投票

  • 在 AIT-3 的後期離開驗證者集

註、文件:有關這些主題的文檔發佈在此頁面

Aptos 表示,滿足以下條件的用戶將獲得 800 枚 Aptos 代幣獎勵:

  • 按時完成所有要求的目標

  • 滿足指標定義下推送數據 ≥ 95%的節點活躍度

  • 獲得的鏈上獎勵 ≥ 最大值的 80%

  • 成功參與 Aptos 創建的所有治理操作

此外,團隊將提供兩個額外獲得 200 Aptos 代幣的機會給那些使用開放的 REST API 運行驗證器全節點以進行負載測試並完成所有操作的用戶。

需注意的是,出於監管考慮,任何 Aptos 代幣只能提供給非美國的參與者。只有在主網成功啟動後,才會提供與激勵測試網相關的任何獎勵,且將至少有一年的鎖定期。

參考來源:

https://www.blocktempo.com/aptos-incentivized-testnet-3/

https://www.grenade.tw/blog/what-is-aptos-blockchain/

使用Microsoft Azure雲端服務架設驗證者節點

首先,在架設驗證者節點之前,有一些步驟需要做。

1. 確認您擁有Discord帳戶並已加入Aptos 伺服器。重要提示:您將被要求為 AIT-3 連接 Discord 帳戶。

2. 在Aptos社區網站上創建一個帳戶(或登錄您現有的帳戶)。

3. 出現提示時,提供您的電子郵件地址和用戶名,並確保確認您的電子郵件。

4. 按照此AIT-3 頁面上的步驟安裝和啟動驗證器節點,將節點設置為測試模式,並向 Aptos 社區提供驗證器詳細資訊。(本文詳細說明安裝步驟)

5. 下載並安裝 Petra 錢包,並在社區網站上註冊您的錢包地址。 (刪除以前版本的錢包)

6. 通過身份驗證和節點驗證流程。

Aptos官方設定手冊:https://aptos.dev/nodes/ait/steps-in-ait3

參考來源:https://mirror.xyz/jackmusk.eth/ALQAOZKj4l94tK37wu1vqEgaNLa0VsOpvEacEg8p1wQ

登入Microsoft Azure建立虛擬機

https://azure.microsoft.com/zh-tw/get-started/azure-portal/

post image

建立虛擬機。資源群組虛擬機器名稱區域依照自己的喜好選擇。

post image

依照官方手冊的節點要求,大小設定Standard_B8ms,影像選擇Ubuntu Server 20.04 LTS - Gen2(18.04也可,這裡選擇20.04),驗證類型選擇SSH公開金鑰較安全(你也可以使用密碼),使用者名稱可任意替換。

注意:以下此節點配置將產生大約每月300美金的費用(AIT-3僅持續到9/9日,所以費用可能更少),請評估自身的財務能力。若使用自家伺服器請參考節點需求設定。以下步驟是使用docker,所以即使換雲平台也是可行的。

post image

使用ssh進行連線,但等等會做一些防火牆限制存取。

post image

OS硬碟類型選擇標準SSD即可,剩下依照自身需求勾選。

post image

因Aptos驗證者節點所存放資料在/opt/aptos資料夾底下,可以在此額外新增資料磁碟來存放。以下範例將不使用資料磁碟,而是直接使用azure-cli擴充根目錄。

post image

虛擬網路子網路公用IP預設配置即可,NIC網路安全性群組選擇進階。

post image

負載平衡選項選無,剩下預設即可。

post image

以下設定均為預設選項。

post image
post image
post image
post image
post image
post image
post image

最後檢查配置是否正確。

post image
post image
post image

若使用金鑰連線方式,將提示下載金鑰,以下建立一資料夾名為testnet,存放在個人電腦中(切勿與別人分享)。

post image

等待虛擬機部署完成。

post image
post image

設定Azure防火牆連線到虛擬機

選擇網路,準備修改紅框處防火牆規則default-allow-ssh

post image

先查詢自己個人電腦的外部IP位置,可在瀏覽器內輸入”My IP Address”查詢。例如:查詢到的IPv4為123.123.123.123。

post image

在設定default-allow-ssh時,在來源IP位置填入,個人電腦的外部IP位置,例如填入123.123.123.123,設定只允許自己個人電腦連線。

post image

選擇儲存。

post image

如下圖,黑色部分則依照個人電腦的外部IP位置而有所不同。而虛擬機的NIC公用IP(紅框處),也各不相同,範例內是20.117.104.111,請將此替換成自己azure虛擬機的NIC公用IP。

post image

使用金鑰透過ssh連線至主機。

post image

在個人電腦打開終端機(console,若windows則是powershell),用終端機修改金鑰的權限 並連線到azure。

cd Desktop/testnet/ (進入到自己存放ssh金鑰的位置,範例是存在桌面)

chmod 400 aptos-testnet_key.cer

ssh -i aptos-testnet_key.cer azureuser@xxx.xxx.xxx.xxx

(將xxx替換為自己外部NIC公用IP)

post image

連線成功

post image

節點前置環境準備

切換成root,並更新ubuntu虛擬機。

sudo -i

apt update

post image

安裝網路工具查看port

apt install net-tools -y

post image

擴充根目錄硬碟空間

參考來源:https://learningsky.io/resizing-ubuntu-vm-root-disk-in-azure/

預設azure所建立的虛擬機根目錄空間只有30G,如下圖。上述的設定也沒有新增額外的資料磁碟,因此我們需要擴充根目錄(/dev/root)。

df -h

post image

首先切換到個人電腦,安裝azure cli,安裝完成之後,使用azure cli登入。

az login

輸入之後會跳出網頁登入

post image
post image

成功登入後,會顯示以下畫面。

post image

回到Azure網頁畫面,查詢ubuntu虛擬機名稱、資源群組、硬碟名稱,並將虛擬機停止(關機)。

post image
post image

回到個人電腦的azure cli,使用以上資訊擴充ubuntu虛擬機根目錄硬碟

az disk update --resource-group <資源群組名稱> --name <硬碟名稱> --size-gb <硬碟大小>

範例:

az disk update --resource-group TESTNET --name aptos-testnet_OsDisk_1_4ef6cda5243546ceb9bf4b3fa922b984 --size-gb 512
post image

如上圖,擴充完成後,顯示512GB,就可以使用azure cli再次把虛擬機開機。

az vm start --resource-group <資源群組名稱> --name <電腦名稱>

範例:

az vm start --resource-group TESTNET --name aptos-testnet
post image

再次遠端登入ubuntu虛擬機並檢查硬碟空間。

ssh -i aptos-testnet_key.cer azureuser@20.117.104.111

sudo -i

df -h

post image

可以看到硬碟已擴充。前置準備完成。

設定Aptos驗證者節點

步驟1.依照節點要求,安裝docker。參考docker官方步驟,建議直接從官方手冊複製指令,避免格式錯誤。

安裝相依性套件

sudo apt-get update

sudo apt-get install ca-certificates curl gnupg lsb-release

post image

設定docker repository

sudo mkdir -p /etc/apt/keyrings

# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg# echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
post image

更新docker repository及安裝docker-ce

sudo apt-get update

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin

post image

安裝完成後檢查docker服務是否正常

systemctl status docker

post image

安裝Aptos CLI,以下是使用easy mode,將aptos放入/bin底下。

到git hub頁面,https://github.com/aptos-labs/aptos-core/releases?q=cli&expanded=true

post image

選取aptos-cli-0.3.1-Ubuntu-x86_64.zip,點選右鍵複製連結網址

post image

回到ubuntu虛擬機內,使用wget下載aptos cli,存放在/tmp下。

cd /tmp

wget https://github.com/aptos-labs/aptos-core/releases/download/aptos-cli-v0.3.1/aptos-cli-0.3.1-Ubuntu-x86_64.zip

post image
post image

安裝解壓縮工具

apt-get install unzip

post image

解壓縮aptos cli安裝包,得到aptos檔案。

unzip /tmp/aptos-cli-0.3.1-Ubuntu-x86_64.zip

post image

將aptops搬移到/bin底下。

mv /tmp/aptos /bin

post image

檢查aptos權限是否為-rwx-r-x-r-x

ls -al /bin/ | grep aptos

post image

測試aptos cli指令。輸出為下圖代表成功。

aptos

post image

步驟2. 開始安裝aptos驗證者節點,設定變數WORKSPACE及USERNAME,並建立資料夾,並進入到WORKSPACE資料夾內。將USERNAME替換為自己喜歡的名稱,以下範例替換為kiralee123。

export WORKSPACE=testnetexport USERNAME=kiralee123mkdir ~/$WORKSPACEcd ~/$WORKSPACE

post image

步驟3.使用wget下載docker-compose.yaml及validator.yaml

wget https://raw.githubusercontent.com/aptos-labs/aptos-core/main/docker/compose/aptos-node/docker-compose.yamlwget https://raw.githubusercontent.com/aptos-labs/aptos-core/main/docker/compose/aptos-node/validator.yaml

post image

步驟4.使用aptos生成驗證者節點私鑰、公鑰、驗證者節點設定檔。產生的四個檔案在~/$WORKSPACE/keys底下。

aptos genesis generate-keys — output-dir ~/$WORKSPACE/keys

post image

(可選)備份private key,請勿將private key交給任何人,否則節點將被駭。

cp /root/testnet/keys/private-keys.yaml /tmp/

post image

更改private key權限(為了方便備份)

post image

退出ubuntu虛擬機

post image

回到個人電腦,使用scp指令,下載ubuntu虛擬機內的private key。

scp -i <連線ubuntu金鑰> azureuser@xxx.xxx.xxx.xxx:/tmp/private-keys.yaml <個人電腦存放路徑>

請將<>內替換為自己的路徑,將xxx.xxx.xxx.xxx替換為自己ubuntu虛擬機的NIC公用IP

範例:

scp -i /Users/mac/Desktop/testnet/aptos-testnet_key.cer azureuser@20.117.104.111:/tmp/private-keys.yaml /Users/mac/Desktop/testnet/

post image

此時個人電腦內就會多出private-keys.yaml。

aptos-testnet_key.cer 是用來連線azure的ubuntu虛擬機的連線金鑰。

private-keys.yaml則是ubuntu虛擬機內的aptos驗證者節點私鑰。

兩者需仔細保管不可外洩。

post image

回到ubuntu虛擬機內。以下參數自行替換

ssh -i aptos-testnet_key.cer azureuser@xxx.xxx.xxx.xxx

export WORKSPACE=testnet

export USERNAME=kiralee123

cd ~/$WORKSPACE

步驟5.使用aptos cli產生驗證者節點設定檔。將xxx.xxx.xxx.xxx替換為ubuntu虛擬機的NIC公用IP

# aptos genesis set-validator-configuration \
    --local-repository-dir ~/$WORKSPACE \
    --username $USERNAME \
    --owner-public-identity-file ~/$WORKSPACE/keys/public-keys.yaml \
    --validator-host xxx.xxx.xxx.xxx:6180 \
    --stake-amount 100000000000000
post image

上述步驟將在~/$WORKSPACE/$USERNAME底下產生兩個檔案,owner.yaml、operator.yaml

步驟6.透過aptos產生驗證者節點layout.yaml

aptos genesis generate-layout-template --output-file ~/$WORKSPACE/layout.yaml

使用vim編輯器,編輯layout.yaml

vim layout.yaml

post image

編輯前

post image

按下i 進入編輯模式,root_key,使用官方手冊所寫的root key

“D04470F43AB6AEAA4EB616B72128881EEF77346F2075FFE68E14BA7DEBD8095E”

將users 替換成自己的USERNAME

chain_id改為43

post image

編輯完成後按下ESC,並按下:wq 儲存離開。

post image
post image

步驟7. 使用wget下載framework.mrb到~/$WORKSPACE底下

wget https://github.com/aptos-labs/aptos-core/releases/download/aptos-framework-v0.3.0/framework.mrb -P ~/$WORKSPACE

post image

步驟8. 透過aptos編譯產生genesis.blob、waypoint.txt

aptos genesis generate-genesis --local-repository-dir ~/$WORKSPACE --output-dir ~/$WORKSPACE
post image

步驟9. 參考官方手冊檢查~/$WORKSPACE底下是否有這些檔案

步驟10. 使用docker compose up在背景模式啟動驗證者節點。

docker compose up -d

post image

檢查服務port是否成功監聽

netstat -tlnp

需有9101、6181、6180、80 port

post image

最後回到azure頁面,開放防火牆,對外部開通9101、6181、6180、80 port

post image

大功告成,驗證者節點設定完畢。

後續請完成,文章開頭所述。進行驗證者節點驗證、安裝錢包、及身份驗證。

4.按照此AIT-3 頁面上的步驟啟動驗證器節點,將節點設置為測試模式,並向 Aptos 社區提供驗證器詳細資訊。

5. 下載並安裝 Petra 錢包,並在社區網站上註冊您的錢包地址。 (刪除以前版本的錢包)

6. 通過身份驗證和節點驗證流程。

祝大家都能順利成功!!!