Code Monkey home page Code Monkey logo

stakewars's Introduction

Hướng dẫn cài đặt tham gia Stake Wars III challenges

1. Mua VPS trên Google Cloud

a. Yêu cầu phần cứng của node:

image

b. Đăng ký mua VPS phù hợp

1. Tạo tài khoản Google cloud: https://console.cloud.google.com/

2. GCC đang có chương trình tặng 300$ trial miễn phí: lưu ý cần có thẻ tín dụng

3. Thiết lập Compute Engine API: enable và liên kết tài khoản bill

4. Tạo 1 VM instance với cấu hình tối thiểu: để setup, sau này tùy hiệu năng máy chủ và dung lượng mà mua thêm: chi phí tối thiểu 74$

image

5. Login vào VPS

2. Stake Wars: Episode III. Challenge 001

a. Tạo ví (wallet)

1. Cài đặt NEAR-CLI

#Cập nhật máy chủ linux

sudo apt update && sudo apt upgrade -y

#Cài đặt bộ công cụ lập trình, Node.js, and npm

curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -  
sudo apt install build-essential nodejs
PATH="$PATH"

#Cài đặt NEAR-CLI

sudo npm install -g near-cli

#Chọn mạng dùng cho Stakewars

export NEAR_ENV=shardnet
\\ hoặc
echo 'export NEAR_ENV=shardnet' >> ~/.bashrc

b. Một số câu lệnh NEAR-CLI

#Xem Proposal Validator

near proposals

image

#Xem Validators Current

near validators current

#Xem Validator next

image

3. Stake Wars: Episode III. Challenge 002

a. Chạy câu lệnh sau để xác định cấu hình phần cứng đáp ứng yêu cầu để chạy không:

lscpu | grep -P ‘(?=.*avx )(?=.*sse4.2 )(?=.*cx16 )(?=.*popcnt )’ > /dev/null
&& echo “Supported”
|| echo “Not supported”

=> Kết quả là “Supported” thì đáp ứng

b. Cài đặt các thành phần phụ thuộc khác

sudo apt install -y git binutils-dev libcurl4-openssl-dev zlib1g-dev libdw-dev libiberty-dev cmake gcc g++ python docker.io protobuf-compiler libssl-dev pkg-config clang llvm python3-pip

sudo apt-get install awscli -y

#xét cầu hinh

USER_BASE_BIN=$(python3 -m site — user-base)/bin
export PATH=”$USER_BASE_BIN:$PATH”

#Install Building env

sudo apt install clang build-essential make

#Install Rust & Cargo

curl --proto ‘=https’ -- tlsv1.2 -sSf https://sh.rustup.rs | sh

==> nhấn số 1)

image

#Source the environment

source $HOME/.cargo/env

c. Cài đặt nearcore project from GitHub

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

#lấy thông tin commit mới nhất: tại đây

git checkout <commit>

#Compile nearcore binary

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

#Initialize working directory

./target/release/neard --home ~/.near init --chain-id shardnet --download-genesis

image

#Replace the config.json

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

#Get latest snapshot: Quan trọng: NOT REQUIRED TO GET SNAPSHOT AFTER HARDFORK ON SHARDNET DURING 2022-07-18

cd ~/.near && wget https://s3-us-west-1.amazonaws.com/build.nearprotocol.com/nearcore-deploy/shardnet/genesis.json

image

#Run the node

cd ~/nearcore
./target/release/neard — home ~/.near run

d. Active node trở thành Validator:

#Authorize Wallet Locally

near login

image

#1 – Copy the link vào trình duyệt của bạn: với Account ID chính là tài khoản ví: VD: stakewarsnode1.shardnet.near

image

#2 – Gán quyền truy cập đến Near CLI:

image

#Nhập lại tên Account ID vào: VD: stakewarsthd1.shardnet.near

image

#==> Sẽ sinh ra file "stakewarsthd1.shardnet.near" tại thư mục "$HOME/.near-credentials/shardnet"

#Copy file và đổi tên theo câu lệnh:

cp $HOME/.near-credentials/shardnet/stakewarsthd1.shardnet.near.json $HOME/.near/validator_key.json

#Chỉnh sửa file validator_key.json

nano ~/.near/validator_key.json

a. Chỉnh “account_id” thêm chữ "factory" => stakewarsnode1.factory.shardnet.near

b. Thay chữ "private_key" => "secret_key"

image

#Setup Systemd Command

sudo nano /etc/systemd/system/neard.service

[Unit]
Description=NEARd Daemon Service

[Service]
Type=simple
User=ubuntu
#Group=near
WorkingDirectory=/home/ubuntu/.near
ExecStart=/home/ubuntu/nearcore/target/release/neard run
Restart=on-failure
RestartSec=30
KillSignal=SIGINT
TimeoutStopSec=45
KillMode=mixed

[Install]

WantedBy=multi-user.target

#Start Neard và kiểm tra log cho đồng bộ xong

sudo systemctl enable neard
&& sudo systemctl restart neard
&& sudo journalctl -n 100 -f -u neard

image

4. Stake Wars: Episode III. Challenge 003

a. Tạo Staking Pool Contract:

#Thông tin chung

near call factory.shardnet.near create_staking_pool ‘{“staking_pool_id”: “”, “owner_id”: “”, “stake_public_key”: “”, “reward_fee_fraction”: {“numerator”: 1, “denominator”: 100}, “code_hash”:”DD428g9eqLL8fWUxv8QSpVFzyHi1Qd16P8ephYCTmMSZ”}’ --accountId="” --amount=30 --gas=300000000000000

#pool_id:if you accountID is abc.shardnet.near,the pool_id is abc
#owner_id: you accountID is abc.shardnet.near,the accountId is abc.shardnet.near
#public key:field public_key field in validator_key.json
#accountId:The SHARDNET account deploying and signing the mount tx. Usually the same as the Owner ID.
#reward_fee_fraction:fee,1/100,1%

#VD: lưu ý những thông tin cần thay đổi theo thông tin các node riêng biệt

near call factory.shardnet.near create_staking_pool ‘{“staking_pool_id”: “stakewarsnode1”, “owner_id”: “stakewarsnode1.shardnet.near”, “stake_public_key”: “ed25519:24Fuo2ohHeszxHoUk4d7hFd1oWCKBdoUXsKQcjFV7sHP”, “reward_fee_fraction”: {“numerator”: 1, “denominator”: 100}, “code_hash”:"DD428g9eqLL8fWUxv8QSpVFzyHi1Qd16P8ephYCTmMSZ”}’ — accountId="stakewarsnode1.shardnet.near" --amount=30 --gas=300000000000000

image

b. Deposit and Stake NEAR

#câu lệnh chung

near call <staking_pool_id> deposit_and_stake --amount --accountId --gas=300000000000000

#VD:

near call stakewarsnode1.factory.shardnet.near deposit_and_stake --amount 110 --accountId stakewarsnode1.shardnet.near --gas=300000000000000

image

#Nếu tạo Staking pool contract mà sai thông tin thì có thể update lại theo câu lệnh sau:

  #Update staking pool key
  
    near call <POOL_ID> update_staking_key ‘{“stake_public_key”: “<PUBLIC_KEY>”}’ — accountId <ACCOUNT_ID>
    
  #To change the pool parameters, such as changing the amount of commission charged to 1%
  
    near call stakewarsthd1.factory.shardnet.near update_reward_fee_fraction ‘{“reward_fee_fraction”: {“numerator”: 1, “denominator”: 100}}’ --accountId stakewarsthd1.shardnet.near --gas=300000000000000

5. Stake Wars: Episode III. Challenge 004

#Trở thành người xác minh không hiển thị ngay lập tức. Sau khi tạo nhóm tham gia, trạng thái sẽ là đề xuất và được thêm vào:

image

#Monitor and make alerts

journalctl -n 100 -f -u neard | ccze -A

#RPC

sudo apt install curl jq

#Check your node version

curl -s http://127.0.0.1:3030/status | jq .version

#Check Delegators and Stake

near view <your pool>.factory.shardnet.near get_accounts '{"from_index": 0, "limit": 10}' --accountId <accountId>.shardnet.near

image

#Check Reason Validator Kicked

curl -s -d '{"jsonrpc": "2.0", "method": "validators", "id": "dontcare", "params": [null]}' -H 'Content-Type: application/json' 127.0.0.1:3030 | jq -c '.result.prev_epoch_kickout[] | select(.account_id | contains ("<POOL_ID>"))' | jq .reason

#Check Blocks Produced / Expected

curl -s -d '{"jsonrpc": "2.0", "method": "validators", "id": "dontcare", "params": [null]}' -H 'Content-Type: application/json' 127.0.0.1:3030 | jq -c '.result.current_validators[] | select(.account_id | contains ("POOL_ID"))'

#Dùng app mobile : UptimeRobot để mornitor port 3030

image

6. Stake Wars: Episode III. Challenge 006

#Tạo crontab trên máy chạy node validator cho phép ping đến network một cách tự động

nano /home/ubuntu/scripts/ping.sh

#Nội dung trong file ping.sh

	#!/bin/sh
	#Ping call to renew Proposal added to crontab
	export NEAR_ENV=shardnet
	export LOGS=/home/ubuntu/logs
	export POOLID=stakewarsnode1
	export ACCOUNTID=stakewarsnode1
	
	echo “ — -” >> $LOGS/all.log
	date >> $LOGS/all.log
	near call $POOLID.factory.shardnet.near ping ‘{}’ — accountId $ACCOUNTID.shardnet.near — gas=300000000000000 >> $LOGS/all.log
	near proposals | grep $POOLID >> $LOGS/all.log
	near validators current | grep $POOLID >> $LOGS/all.log
	near validators next | grep $POOLID >> $LOGS/all.log

#cấp quyền thực thi file

	chmod +x ~/scripts/ping.sh

#Tạo crontab

	crontab -e
	*/5 * * * * sh /home/ubuntu/scripts/ping.sh

#Kết quả nội dung trong file all.log

image

#Xem online

	https://explorer.shardnet.near.org/accounts/stakewarsthd1.shardnet.near

stakewars's People

Contributors

ionodeonline avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.