Node
Become An GEMNODE Node
Adding Subnet Validator
The newly created Subnet requires validators to validate the transactions on the Subnet's every blockchain. Now we will write the code in addSubnetValidator.js
to add validators to the Subnet. Only transactions signed by the threshold (here 1) number of Subnet owners will be accepted to add validators. The Subnet owners which will sign this transaction is passed as the subnetAuth
parameter. It is an array of indices, representing the Subnet owners from the array of addresses that we passed earlier in the createSubnetTx()
.
The arguments for the AvalancheJS API call for buildAddSubnetValidatorTx()
is explained with the help of comments. All the transaction calls of AvalancheJS starting with build
will return an unsigned transaction. We then have to sign it with our key chain and issue the signed transaction to the network.
const args = require("yargs").argv
const {
platform,
info,
pKeyChain,
pAddressStrings,
utxoSet,
BN,
} = require("./importAPI.js")
async function addSubnetValidator() {
let {
nodeID = await info.getNodeID(),
startTime,
endTime,
weight = 20,
subnetID,
} = args
const pAddresses = pKeyChain.getAddresses()
// Creating Subnet auth
const subnetAuth = [[0, pAddresses[0]]]
// Creating unsgined tx
const unsignedTx = await platform.buildAddSubnetValidatorTx(
await utxoSet(), // set of utxos this tx will consume
pAddressStrings, // from
pAddressStrings, // change
nodeID, // node id of the validator
new BN(startTime), // timestamp after which validation starts
new BN(endTime), // timestamp after which validation ends
new BN(weight), // weight of the validator
subnetID, // Subnet id for validation
undefined, // memo
undefined, // asOf
subnetAuth // Subnet owners' address indices signing this tx
)
// signing unsgined tx with pKeyChain
const tx = unsignedTx.sign(pKeyChain)
// issuing tx
const txId = await platform.issueTx(tx)
console.log("Tx ID: ", txId)
}
addSubnetValidator()
We have to pass command-line arguments like nodeID
, startTime
, endTime
, weight
and subnetID
while calling the command. If we do not pass any nodeID, then by default it will use ID corresponding to the URI in the config.js
by calling the info.getNodeID()
API from AvalancheJS. Similarly, the default weight will be 20, if not passed. You can run this program now with the following command.
node addSubnetValidator.js \
--subnetID <YOUR_SUBNET_ID> \
--startTime $(date -v +5M +%s) \
--endTime $(date -v +14d +%s)
We will keep the start time 5 minutes later than the current time. This $(date -v +5M +%s)
will help to achieve the same. But you can put any timestamp in seconds there, given it is 20s later than the current time.
Whitelisting Subnet from the Nodeβ
Subnet owners can add any node to their Subnet. That doesn't mean the nodes start validating their Subnet without any consent. If a node wants to validate the newly added Subnet, then it must restart its avalanchego
binary with the new Subnet being whitelisted.
avalanche-network-runner control restart-node \
--request-timeout=3m \
--endpoint="0.0.0.0:8080" \
--node-name node1 \
--avalanchego-path ${HOME}/subnet-evm-demo/avalanchego/build/avalanchego \
--whitelisted-subnets="<SUBNET_ID>"
Once the node has restarted, it will again be re-assigned to a random API port. We have to update the config.js
file with the new port.
Last updated