August 23, 2022

Near | Stake Wars III

1package

⠀Participate in Stake Wars III and join NEAR’s mission to bring «Chunk-Only Producers» to Mainnet.


Content


Server requirements

To the content

⠀Minimal (VPS/VDS/DS):
4 CPU, 8 GB RAM, 500 GB SSD, Ubuntu 20.04

⠀Suitable servers:


Challenge 001

To the content

Source page

Create a wallet.

⠀Enter you username and click the button.

⠀Choose the mnemonic phrase, click the button, save it in a safe place and pass the memory verification.

⠀Recover the created wallet.


Challenge 002

To the content

Source page

Start a node

⠀Check if your server has the right CPU features

lscpu | grep -P '(?=.*avx )(?=.*sse4.2 )(?=.*cx16 )(?=.*popcnt )' > /dev/null \
  && echo "Supported" \
  || echo "Not supported"

⠀Update packages

sudo apt update && sudo apt upgrade -y

⠀Install the required packages

sudo apt install wget jq bc build-essential -y

⠀Install Rust

. <(wget -qO- https://raw.githubusercontent.com/SecorD0/utils/main/installers/rust.sh)

⠀Clone the repo

git clone https://github.com/near/nearcore

⠀Go to the project folder

cd $HOME/nearcore

⠀Switch to the latest commit

git checkout `wget -qO- https://raw.githubusercontent.com/near/stakewars-iii/main/commit.md`

⠀Check the current branch

git branch

⠀Build the binary

cargo build -p neard --release --features shardnet

⠀Move binary to the folder with all binaries

mv $HOME/nearcore/target/release/neard /usr/bin/

⠀Leave the project folder

cd

⠀Initialize the node

neard --home $HOME/.near init --chain-id shardnet --download-genesis

Save the file

echo $HOME/.near/node_key.json

⠀Download the config file

wget -O $HOME/.near/config.json https://s3-us-west-1.amazonaws.com/build.nearprotocol.com/nearcore-deploy/shardnet/config.json

⠀Edit the config

sed -i -e 's%"archive": false%"archive": true%' $HOME/.near/config.json

⠀Create a service file

printf "[Unit]
Description=Near node
After=network-online.target

[Service]
User=$USER
ExecStart=`which neard` --home $HOME/.near run
Restart=on-failure
RestartSec=3
LimitNOFILE=65535

[Install]
WantedBy=multi-user.target" > /etc/systemd/system/neard.service

⠀Start the service file

sudo systemctl daemon-reload
sudo systemctl enable neard
sudo systemctl restart neard

⠀Add a command to view a log of the node in the system as a variable

. <(wget -qO- https://raw.githubusercontent.com/SecorD0/utils/main/miscellaneous/insert_variable.sh) -n near_log -v "sudo journalctl -fn 100 -u neard" -a

Becoming a Validator

⠀Install Node.js

. <(wget -qO- https://raw.githubusercontent.com/SecorD0/utils/main/installers/nodejs.sh)

⠀Install npm

sudo apt install npm -y

⠀Install near-cli

sudo npm install -g near-cli

⠀Insert variable with network name

. <(wget -qO- https://raw.githubusercontent.com/SecorD0/utils/main/miscellaneous/insert_variable.sh) \
-n NEAR_ENV -v "shardnet"

⠀Login

near login

⠀Answer n.

⠀Go to the link through the browser on your PC

⠀And grant access

⠀Enter an address of the connected account.

⠀Add a wallet Account ID in the system as a variable

. <(wget -qO- https://raw.githubusercontent.com/SecorD0/utils/main/miscellaneous/insert_variable.sh) -n near_account_id

⠀Check if the file exists

cat $HOME/.near/validator_key.json

⠀If doesn't exist

⠀Create it

near generate-key "${near_account_id}.factory.shardnet.near"

Save the folder

echo $HOME/.near-credentials/shardnet/

⠀Copy the file generated to shardnet folder

cp "$HOME/.near-credentials/shardnet/${near_account_id}.shardnet.near.json" \
$HOME/.near/validator_key.json

⠀Edit it

sed -i -e "s%.shardnet.near%.factory.shardnet.near%; s%private_key%secret_key%" \
$HOME/.near/validator_key.json

⠀Restart the node

systemctl restart neard

Challenge 003

To the content

Source page

Staking pool

⠀Add a wallet Pool ID in the system as a variable

. <(wget -qO- https://raw.githubusercontent.com/SecorD0/utils/main/miscellaneous/insert_variable.sh) -n near_pool_id

⠀Create staking pool

near call factory.shardnet.near create_staking_pool '{"staking_pool_id": "'${near_pool_id}'", "owner_id": "'${near_account_id}'.shardnet.near", "stake_public_key": "'"`jq -r '.public_key' "/root/.near/validator_key.json"`"'", "reward_fee_fraction": {"numerator": 5, "denominator": 100}, "code_hash":"DD428g9eqLL8fWUxv8QSpVFzyHi1Qd16P8ephYCTmMSZ"}' --accountId  "${near_account_id}.shardnet.near" \
--amount 30 --gas 300000000000000

⠀Delegate more tokens

near call "${near_pool_id}.factory.shardnet.near" deposit_and_stake --accountId "${near_account_id}.shardnet.near" --gas 300000000000000 \
--amount 500

Pinging

⠀You should ping each epoch with the command below to keep reported rewards current

near call "${near_pool_id}.factory.shardnet.near" ping '{}' --accountId "${near_account_id}.shardnet.near" \
--gas 300000000000000

Challenge 004

To the content

Source page

⠀Add a command to view the information about the node in the system as a variable

. <(wget -qO- https://raw.githubusercontent.com/SecorD0/utils/main/miscellaneous/insert_variable.sh) -n near_node_info -v ". <(wget -qO- https://raw.githubusercontent.com/SecorD0/Near/main/node_info.sh) 2> /dev/null" -a

⠀Enter command to view the information

near_node_info

Updating

To the content

⠀Go to the project folder

cd $HOME/nearcore

⠀Create a branch with the source repository

git remote add upstream https://github.com/near/nearcore

⠀Update the local branch to the current branch

git fetch upstream

⠀Switch to the latest commit

git checkout `wget -qO- https://raw.githubusercontent.com/near/stakewars-iii/main/commit.md`

⠀Check the current branch

git branch

⠀Build the binary

cargo build -p neard --release --features shardnet

⠀Leave the project folder

cd

⠀Make backup of the config

cp $HOME/.near/config.json $HOME/.near/config.json.back

⠀Make backup of the previous binary

mv /usr/bin/neard $HOME

⠀Stop the node

sudo systemctl stop neard

⠀Move binary to the folder with all binaries

mv $HOME/nearcore/target/release/neard /usr/bin/

⠀Restart the node

sudo systemctl restart neard

⠀View the log to make sure the node is running

near_log

Hardforks

To the content

27.07.22

⠀Insert hardfork commit as a variable

commit="0d7f272afabc00f4a076b1c89a70ffc62466efe9"

⠀Follow the steps in the «Actions» subsection.

21.07.22

⠀Insert hardfork commit as a variable

commit="0f81dca95a55f975b6e54fe6f311a71792e21698"

⠀Follow the steps in the «Actions» subsection.

Actions

⠀Go to the project folder

cd $HOME/nearcore

⠀Create a branch with the source repository

git remote add upstream https://github.com/near/nearcore

⠀Update the local branch to the current branch

git fetch upstream

⠀Switch to the special commit

git checkout $commit

⠀Check the current branch

git branch

⠀Build the binary

cargo build -p neard --release --features shardnet

⠀Make backup of the previous binary

mv /usr/bin/neard $HOME

⠀Stop the node

sudo systemctl stop neard

⠀Move binary to the folder with all binaries

mv $HOME/nearcore/target/release/neard /usr/bin/

⠀Delete previous data

rm -rf $HOME/.near/{data,genesis.json}

⠀Download the genesis file

wget -O $HOME/.near/genesis.json https://s3-us-west-1.amazonaws.com/build.nearprotocol.com/nearcore-deploy/shardnet/genesis.json

⠀Download the config file

wget -O $HOME/.near/config.json https://s3-us-west-1.amazonaws.com/build.nearprotocol.com/nearcore-deploy/shardnet/config.json

⠀Edit the config

sed -i -e 's%"archive": false%"archive": true%' $HOME/.near/config.json

⠀Restart the node

sudo systemctl restart neard

⠀View the log to make sure the node is running

near_log

Useful commands

To the content

⠀To view the node's log

near_log
sudo journalctl -fn 100 -u neard

⠀To view the information about the node

near_node_info

⠀To view validators in the current epoch

near validators current
near validators current | grep "$near_pool_id"

⠀To view validators in the next epoch

near validators next
near validators next | grep "$near_pool_id"

⠀To ping

near call "${near_pool_id}.factory.shardnet.near" ping '{}' --accountId "${near_account_id}.shardnet.near" \
--gas 300000000000000

⠀To restart the node

systemctl restart neard

Useful links

To the content

Event website | GitHub binary | GitHub challenges

Wallet | Explorer


1package

To the content

Telegram (RU) | Chat (RU) | Discord (RU) | Twitter | Learning | Admitix


Acknowledgments

To the content

1package team — writing the article