如何在AIT3中构建一个Aptos的公共完整节点

Aptos有Validator Nodes, Validator Full Nodes, 和 Public Full Nodes。公共全节点是用户用来读/写等的,我们的节点是基于Rest API的。大多数行业都使用RPC,所以你会经常听到人们称这些为RPC节点,但在Aptos避免这么说,因为它的意思是不同的。验证器全节点直接连接到验证器节点,作为公共全节点和验证器之间的交汇点。它们有助于扩展性(通过允许更多的PFN连接到它们,从而获得对Aptos网络的低延迟访问)和DDoS缓解。

只是为了让人更加困惑,我们确实有另一种特殊的节点,它确实使用RPC,但更多的是在另一个时间 :)

首先,请确保你有:

-为Aptos预设电脑
-为GCP预设你的电脑
-确保您使用的是正确的CLI v0.3.2。你可以用以下方式更新。

$ git fetch 
$ git checkout b2228f286b5fe7631dee62690ae5d1087017e20d
$ cargo run -p aptos

一,点击 "新项目",创建一个项目。

二,通过你的终端登录到你的gcp帐户。

$ gcloud auth login — update-adc

三,创建一个工作空间名称,创建一个文件夹,并创建一个桶。

$ export WORKSPACE=fullnode-ait3
$ mkdir -p ~/$WORKSPACE
$ gsutil mb gs://fullnode-ait3-wintertoro

所以现在你要进入你的工作目录,并创建一个terraform文件。

四,编辑你的main.tf文件

在终端之外,进入包含main.tf文件的文件夹,用你的Atom编辑器打开。它将让你像编辑word文件一样编辑该文件。这比vim编辑要容易得多。

terraform {
  required_version = "~> 1.2.0"
  backend "gcs" {
    bucket = "fullnode-ait3-wintertoro" # bucket name created in step 2
    prefix = "state/fullnode"
  }
}module "fullnode" {
  # download Terraform module from aptos-labs/aptos-core repo
  source        = "github.com/aptos-labs/aptos-core.git//terraform/aptos-node/gcp?ref=testnet"
  region        = "us-central1"  # Specify the region
  zone          = "c"            # Specify the zone suffix
  project       = "ait3-project" # Specify your GCP project ID
  era           = 1              # bump era number to wipe the chain
  chain_id      = 47             # Specify AIT3 chain_id
  machine_type  = "c2-standard-16" # I like to increase machine size here, default is a bit smaller
  image_tag     = "testnet_b2228f286b5fe7631dee62690ae5d1087017e20d" # Specify the docker image tag to use. This often changes as the team puts out new releases, so you gotta checking announcements
}

五,得到terraform building.

$ terraform init
$ terraform workspace new $WORKSPACE
$ terraform apply

必须在这里等待20分钟的时间,因为它正在形成。

六,配置你的Kubernetes客户端以访问你刚刚部署的集群

$ gcloud container clusters get-credentials aptos-$WORKSPACE --zone us-central1-c --project ait3-project

七,检查一切是否正常

kubectl get pods -n aptos

八,获取你的节点IP信息

$ kubectl get svc -o custom-columns=IP:status.loadBalancer.ingress -n aptos
IP [map[ip:34.121.188.233]]
$ curl http://34.121.188.233/v1
{"chain_id":47,"epoch":"49","ledger_version":"120072804","oldest_ledger_version":"0","ledger_timestamp":"1662133291729445","node_role":"full_node","oldest_block_height":"0","block_height":"665984"}%

要用一个静态身份来配置你的节点

$aptos key generate --key-type x25519 --output-file private-key.txt
"Result": {
"PrivateKey Path": "private-key.txt",
"PublicKey Path": "private-key.txt.pub"
}
$ aptos key extract-peer  --private-key-file private-key.txt  \
--output-file peer-info.yaml # extract peer id
---
B881EA2C174D8211C123E5A91D86227DB116A44BB345A6E66874F83D8993F813:
  addresses: []
  keys:
    - "0xB881EA2C174D8211C123E5A91D86227DB116A44BB345A6E66874F83D8993F813"
role: Upstream

peer_id

B881EA2C174D8211C123E5A91D86227DB116A44BB345A6E66874F83D8993F813

key

0xB881EA2C174D8211C123E5A91D86227DB116A44BB345A6E66874F83D8993F813

修改main.tf,在fullnode_helm_values中添加fullnode_identity,这将配置fullnode的键。

terraform {
  required_version = "~> 1.2.0"
  backend "gcs" {
    bucket = "ait3-fullnode" # bucket name created in step 2
    prefix = "state/fullnode"
  }
}
module "fullnode" {
  # download Terraform module from aptos-labs/aptos-core repo
  source        = "github.com/aptos-labs/aptos-core.git//terraform/fullnode/gcp?ref=testnet"
  region        = "us-central1"  # Specify the region
  zone          = "c"            # Specify the zone suffix
  project       = "ait3-project" # Specify your GCP project ID
  era           = 1             # bump era number to wipe the chai
  chain_id      = 47             # Specify AIT3 chain_id
  machine_type  = "c2-standard-16" # I like to increase machine size here, default is a bit smaller
  image_tag     = "testnet_4219d75c57115805f0faf0ad07c17becf6580202" # Specify the docker image tag to use
fullnode_helm_values = {
    # create fullnode from this identity config, so it will always have same peer id and address
    fullnode_identity = {
      type = "from_config"
      key = "B8BD811A91D8E6E0C6DAC991009F189337378760B55F3AD05580235325615C74"
      peer_id = "ca3579457555c80fc7bb39964eb298c414fd60f81a2f8eedb0244ec07a26e575"
      }
    }
}
$ terraform apply

现在检查你的节点是否在工作

$cat /tmp/nhc_out | jq
{
"evaluation_results": [
{
"headline": "Chain ID reported by baseline and target match",
"score": 100,
"explanation": "The node under investigation reported the same Chain ID 47 as is reported by the baseline node.",
"evaluator_name": "node_identity",
"category": "api",
"links": []
},
{
"headline": "Role Type reported by baseline and target match",
"score": 100,
"explanation": "The node under investigation reported the same Role Type full_node as is reported by the baseline node.",
"evaluator_name": "node_identity",
"category": "api",
"links": []
},
{
"headline": "Average API latency is good",
"score": 100,
"explanation": "The average API latency was 79ms, which is below the maximum allowed latency of 750ms. Note, this latency is not the same as standard ping latency, see the attached link.",
"evaluator_name": "latency",
"category": "api",
"links": [
"https://aptos.dev/nodes/node-health-checker-faq#how-does-the-latency-evaluator-work"
]
},
{
"headline": "Target node produced valid recent transaction",
"score": 100,
"explanation": "We were able to pull the same transaction (version: 119898649) from both your node and the baseline node. Great! This implies that your node is keeping up with other nodes in the network.",
"evaluator_name": "transaction_availability",
"category": "api",
"links": []
}
],
"summary_score": 100,
"summary_explanation": "100: Awesome!"

原文链接:https://medium.com/@wintertoro/building-an-aptos-public-full-node-in-ait3-cc9f07218071