Run a Mainnet Node on a Custom Subnet
Introduction
This article describes how to run a Mainnet node on a custom subnet. In this example we'll call the subnet DeFiKingdoms (DFK) It can be applied to any other Subnet, where the corresponding part of the Subnet info should be replaced.
Following necessary steps are needed to run your node on the DFK Subnet:
- Build the MetalGo binary and create the plugin build directory
- Build the plugin binary for the DFK Subnet-EVM
- Whitelist the DFK Subnet
- Connect to the DFK Subnet!
Just want the commands? Jump to the end!
Build MetalGo Binary and Create the Plugin Build Directory
First, you need to download and build MetalGo (handles the orchestration of running Custom VMs).
You can follow this comprehensive guide to complete
this step. For this tutorial, we recommend compiling from source instead of using the MetalGo Installer.
Build subnet-evm Binary
For the steps below, we will assume that you completed first step successfully and are now in your
MetalGo directory (within your $GOPATH).
Next, you will clone the TST Subnet-EVM repository:
cd $GOPATH/src/github.com
mkdir DeFiKingdoms
cd TDeFiKingdoms
git clone git@github.com:MetalBlockchain/subnet-evm.git
cd subnet-evm
Now that you are in the DeFiKingdoms/subnet-evm repository, you will build the binary and place it
directly into the MetalGo build/plugins directory. To do this, you will pass in the desired
path to place the plugin binary. You will want to place this binary into the plugins directory of
MetalGo, which was created when building MetalGo from source.
./scripts/build.sh $GOPATH/src/github.com/MetalBlockchain/metalgo/build/plugins/mDV3QWRXfwgKUWb9sggkv4vQxAQR4y2CyKrt5pLZ5SzQ7EHBv
The long string mDV3QWRXfwgKUWb9sggkv4vQxAQR4y2CyKrt5pLZ5SzQ7EHBv is the CB58 encoded VMID of the
DFK Subnet-EVM. AvalancheGo will use the name of this file to determine what VMs are available to
run from the plugins directory.
Whitelisting DFK Subnet and Restarting the Node
MetalGo will only validate the primary network by default. In order to add the DFK Subnet, you will need to add the DFK Subnet ID to the set of whitelisted Subnets in the node's config file or pass it through the command-line options of the node. Once the node's config file has been updated, you will need to start the Metal node (restart if already running).
Once you start the node, it will begin syncing the Primary Network. Once the node reaches the point in the Platform Chain where the DFK Subnet is created, it will begin syncing the DFK Subnet as well, and will start validating once it has fully bootstrapped.
Updating Config File
You can skip this section if you want to pass whitelisted Subnets through command-line flags.
You need to create a new config file or edit your existing one for your node. In this tutorial, you
will create a config file at: ~/.metalgo/config.json. Note: you can create a config file
anywhere on your file system, you will just need to specify its location via the flag
--config-file=<file path> when you start your node. See
this for more info on configuration
file and flags.
You will need to add the DFK Subnet ID to the whitelisted Subnets section of the config file:
{
<OTHER-CONFIGURATIONS>
"whitelisted-subnets": "Vn3aX6hNRstj5VHHm63TCgPNaeGnRSqCYXQqemSqDd2TQH4qJ"
}
Whitelisted Subnets is a comma separated list of Subnet IDs, so if you are validating more than one
Subnet, you can simply add a comma to the end of the list and append the DFK Subnet ID
Vn3aX6hNRstj5VHHm63TCgPNaeGnRSqCYXQqemSqDd2TQH4qJ.
Running the Node
First, make sure to shut down your node in case it is still running. Then, you will navigate back into the MetalGo directory:
cd $GOPATH/src/github.com/MetalBlockchain/metalgo
If you went through the steps to set up a config file, then you can launch your node by specifying the config file on the command line:
./build/metalgo --config-file ~/.metalgo/config.json
If you want to pass the whitelisted Subnets through the command-line flag. You can append the other
flags or even the --config-file flag as well, according to your need.
./build/metalgo --whitelisted-subnets Vn3aX6hNRstj5VHHm63TCgPNaeGnRSqCYXQqemSqDd2TQH4qJ
Just Want the Commands? We Got You
Run go version. It should be 1.18.1 or above. Run echo $GOPATH. It should not be empty.
cd $GOPATH
mkdir -p src/github.com/MetalBlockchain
cd src/github.com/MetalBlockchain
git clone git@github.com:MetalBlockchain/metalgo.git
cd metalgo
./scripts/build.sh
cd $GOPATH/src/github.com
mkdir DeFiKingdoms
cd DeFiKingdoms
git clone git@github.com:MetalBlockchain/subnet-evm.git
cd subnet-evm
./scripts/build.sh $GOPATH/src/github.com/MetalBlockchain/metalgo/build/plugins/mDV3QWRXfwgKUWb9sggkv4vQxAQR4y2CyKrt5pLZ5SzQ7EHBv
./build/metalgo --whitelisted-subnets Vn3aX6hNRstj5VHHm63TCgPNaeGnRSqCYXQqemSqDd2TQH4qJ