Setting up Aptos Full Node on devnet using GCP

wintertoro
4 min readAug 31, 2022

--

As of 08/30/22

I also want to preface this with the fact that I have no development experience, so a lot of things that might have been taken for granted by a more experienced developer, I spent hours on :(

I’m running this on a Macbook Pro M1 chip.

Link to the official guide:

First get your computer set-up for Aptos nodes on GCP — Follow the steps here

So with all that out of the way:

  1. Click on New Project and Create a project.

2. Login to your gcp account via your terminal

$ gcloud auth login — update-adc

3. Create a workspace name, and create a folder.

Note: The “devnet” here is just a placeholder name for the workspace. you can call it whatever you want

$ export WORKSPACE=devnet
$ mkdir -p ~/$WORKSPACE
$ gsutil mb gs://wintertoro_bucket

Here the “wintertoro_bucket” is jut a name I have chosen for my gcp bucket. you can call it whatever you want. The gsutil command basically creates a storage bucket in your cloud acc.

4. So now you want to go into your working directory, and create a terraform file.

$ cd ~/$WORKSPACE
$ touch main.tf

Outside of the terminal, go to the folder which contains the main.tf file, and open with your Atom editor. It will let you edit the file the way you do a word file. Much much easier than vim edits.

terraform {
required_version = "~> 1.2.0"
backend "gcs" {
bucket = "wintertoro_bucket" # 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=main"
region = "us-central1" # Specify the region
zone = "c" # Specify the zone suffix
project = "wintertoro" # Specify your GCP project name
era = 1 # bump era number to wipe the chain
image_tag = "devnet_8399cd1c7b9662d3a6a09c28363c5f66f0839c41" # Specify the docker image tag to use
}

The bits I bolded above are the parts you need to change. The rest you can leave it as is. The GCP project name is the name of the project you created in your google account earlier on. Remember this step?

For image tag, go check docker hub for the latest image with tag devnet, and copy the latest one.

Save (cmd+s) and Exit (just close the file).

Now go make sure your terminal is still in the right directory, with the main.tf file.

Run your Terraform

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

What the second steps does, is that it creates a new terraform workspace automatically named after the name you defined $WORKSPACE as. You did this earlier here. So in this case the new terraform workspace is called devnet cause that’s what $WORKSPACE points to. But honestly you can just rename it whatever you want at this point. You can terraform workspace new oranges, or terraform workspace new apples etc. But make sure you are pointing to the right workspace you want. You can do that using

terraform workspace select <workspace name>

so like if you have multiple workspaces, which you can check by

terraform workspace list

you can do

terraform workspace select apples

to pick the one you want.

If you screw up, just do

terraform destroy

to clean up the workspace you are currently in. Or switch to a different workspace using select and press

terraform workspace delete oranges

Oranges being the name of your workspace. Insert the right name there.

Validation

Once Terraform apply finished, you can follow this section to validate your deployment.

  1. Configure your Kubernetes client to access the cluster you just deployed:
gcloud container clusters get-credentials aptos-$WORKSPACE — zone us-central1-c --project wintertoro

Check that your fullnode pods are now running (this may take a few minutes):

$ kubectl get pods -n aptos 

You will get this:

NAME                       READY   STATUS    RESTARTS   AGEdevnet0-aptos-fullnode-0   1/1     Running   0          56s

Get your fullnode IP:

$ kubectl get svc -o custom-columns=IP:status.loadBalancer.ingress -n aptos 

You will get this:

IP[map[ip:104.198.36.142]]

Check REST API, make sure the ledge version is increasing.

$ curl http://104.198.36.142/v1{"chain_id":25,"epoch":"22","ledger_version":"9019844","oldest_ledger_version":"0","ledger_timestamp":"1661620200131348","node_role":"full_node","oldest_block_height":"0","block_height":"1825467"}%

To get the metrics logged, set up the port-forwarding to the aptos-fullnode pod. Use kubectl get pods -n aptos to get the name of the pod

$ kubectl port-forward -n aptos <pod-name> 9101:9101# for example:
$ kubectl port-forward -n aptos devnet0-aptos-fullnode-0 9101:9101

Open a new ssh terminal. Execute the following curl calls to verify the correctness

$curl -v http://0:9101/metrics 2> /dev/null | grep "aptos_state_sync_version{type=\"synced\"}"# aptos_state_sync_version{type="synced"} 5313083$curl -v http://0:9101/metrics 2> /dev/null | grep "aptos_connections{direction=\"outbound\""#aptos_connections{direction="outbound",network_id="Public",peer_id="72556764",role_type="full_node"} 4

Exit port-forwarding when you are done by entering control-c in the terminal

Update Fullnode With New Releases

There could be two types of releasees, one comes with a data wipe to startover the blockchain, one is just a software update.

You can increase the era number in main.tf to trigger a new data volume creation, which will start the node on a new DB → Ignore if you don’t want to wipe data. Otherwise:

  1. Update image_tag in main.tf (if you use devnet tag you can skip this step)
  2. Update Terraform module for fullnode, run this in the same directory of your main.tf file, and
$ terraform get -update
$ terraform apply

--

--