Comprehensive Guide to Buidl Matic Counterstake Node on Home CPU - CS-2002 updated

in #node5 years ago (edited)

Hi guys how are you all? Happy New Years btw, so how's your vacation, i hope all got a great time with your Family and or your Friends, btw in this new year Matic Token will launch it's counterstake staking program around 8 January 2020, have all of you connected to their Testnet? If not i hope this Tutorial can help you to open a little knowledge about How to connect, When it's considered as connected, etc

Maybe i dedicated this to they who want to connect using their own Home Networking, but if you want to manage it remotely by rent some VPS, you can used this Tutorial too, the steps is same, but maybe the command will be differ because this is propose for buidl on Home CPU (virtual machine), you just have to seek the right command, and as long as you run the command in sequence and not skip the command pasted, u'll be on right Track, then u'll blast off, to the moon with Matic Token,,

Okay i assume you all have play your Virtualbox and your ubuntu has just running, and you have used one of Terminal program to submit command to the machine, so let's get it on, but if you still not make it, here video about how to Install your first Ubuntu on your windows PC/Laptop with Virtual Box;

Stop Press! Maybe you all have known that Matic Team have updated their GitBook (Doc.), before there were no additional blockchain added, but now it has updated twice from CS-2001 to CS-2002 (now), if you read this from my first time publishing it, and wanna seek for update or information, it's not changes very much, you'll not get confuse because in conclution the step are just;

  • Download and Install
  • Configure
  • Start the Node (Heimdall, Rest Server, Bridge & Bor)
  • Stake your Matic (TST) tokens

For optional way to install, they gave another method named Linux Package Installation, btw the way what we'll gonna Install was named the Binaries way

Other additional info; For participating on Phase 1, you need to fill below form to receives your Matic (TST) tokens;
https://forms.gle/P2JrXiTFuPvQadbv9

And let's get it on;
A. Separated Heimdall, Rest Server, Bridge & Bor to run on different shell.
I prefer to separated them using tmux, so if you just install the ubuntu, you still didn't have tmux, so just paste below sintax after '$;', in one order, don't separate it, and u'll be alright,,

#tmux
$; sudo apt-get update && sudo apt-get upgrade && sudo apt-get install tmux

after that start each of this tmux sessions;
$; tmux new-session -s Cs #for Heimdall
$; tmux new-session -s CsRs #for Rest Server
$; tmux new-session -s CsBrd #for Bridge
$; tmux new-session -s CsBor #for Bor

Don't forget guys, don't paste the 'dollar' symbol, but only the command after the '$;' and don't type/paste word after '#' also you can create your own name, just changes the input after '-s', eg. tmux new-session -s 'ur own name'

for get out of respective shell press & hold Ctrl +b and then press d,
and for get in again type;
$; tmux a -t Cs
$; tmux a -t CsRs
$; tmux a -t CsBrd
$; tmux a -t CsBor

or $; tmux a -t 'ur input'

and don't press Ctrl+c on terminal coz it'll stop all running command

B. Prepare the Counterstake Environment.
firstly you need to get in first to Cs shell so type $; tmux new-session -s Cs

And then just following below sintax after '$;', one by one in order, don't skip it, and u'll be alright;

#git
$; sudo apt install git curl -y

#go
$; curl https://gist.githubusercontent.com/vaibhavchellani/cbe0fa947dc0a6557cb9583d081ff8ce/raw/d47b3df14ccffdd7a965e44c39fb5ec235360166/new.sh > install_go.sh
$; bash install_go.sh

Remember guys don't paste the 'dollar' symbol, but only the command after the '$;'

#go-lang
$; sudo apt install golang-go

#Erlang
$; wget https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb
$; sudo dpkg -i erlang-solutions_1.0_all.deb
$; sudo apt-get update
$; sudo apt-get install erlang

#Check Erlang Status
$; erl

Ctrl+c 2x #for Quitting

#Rabbit
$; sudo sh -c 'echo "deb https://dl.bintray.com/rabbitmq/debian $(lsb_release -sc) main" >> /etc/apt/sources.list.d/rabbitmq.list'
$; wget -O- https://dl.bintray.com/rabbitmq/Keys/rabbitmq-release-signing-key.asc | sudo apt-key add -
$; wget -O- https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | sudo apt-key add -
$; sudo apt-get update && sudo apt-get install rabbitmq-server

#Run RabbitMQ Services
$; sudo service rabbitmq-server start

if you want to stop it; $; sudo service rabbitmq-server stop

#Check Rabbit Status
$; sudo service rabbitmq-server status

#Install Make
$; sudo apt-get install build-essential

#Clone Heimdall Directory
$; mkdir -p $GOPATH/src/github.com/maticnetwork
$; cd $GOPATH/src/github.com/maticnetwork
$; git clone https://github.com/maticnetwork/heimdall

#If you get stuck and didn't know what's will going on if you pasted all of this in your machines, or maybe you just want to make sure that you're on the right track, you can watch below video;

C. Run Heimdall.
Heimdall is one of Matic node, the other one named Bor, how we know the Heimdall node run properly is by pasting the last command of 'Run Heimdall section' below (#Start&Sync Heimdall), but before that please follow the sintax one by one, without skipping it

#Clone Public Testnet Directory
$; cd ~
$; git clone https://github.com/maticnetwork/public-testnets

Tips. Before using 'Make' sintax you must always 'checkout' first 'CS-2002' directory, first type $;
cd $GOPATH/src/github.com/maticnetwork/heimdall/

$; git checkout CS-2002
$; make install

Notice. when it 'prompt' you to input 'Yes', just type Y

$; heimdalld --help

$; heimdalld init

#write out the generated chain_id & node_id for further use

$; echo "export HEIMDALLDIR=~/.heimdalld" >> ~/.bashrc
$; source ~/.bashrc

#see configuration of your Heimdall;
$; sudo cat ~/.heimdalld/config/heimdall-config.toml

#Get Heimdall Genesis Config
$; cd ~
$; cd public-testnets/CS-2002
$; echo "export CONFIGPATH=$PWD" >> ~/.bashrc
$; source ~/.bashrc
$; cp $CONFIGPATH/heimdall/config/genesis.json $HEIMDALLDIR/config/genesis.json
$; cp $CONFIGPATH/heimdall/config/heimdall-config.toml $HEIMDALLDIR/config/heimdall-config.toml

#Generate API key using: https://ethereumico.io/knowledge-base/infura-api-key-guide ~after you get it;
$; cd ~/.heimdalld/config
$; nano heimdall-config.toml

paste your Infura API under "eth_RPC_URL" = "32-digit-of-alphanumeric"

#make sure your contract address is match for CS-2002 below;

Eth Chain Contracts

stakinginfo_contract = "0x4A77108eA2380217553dcc77C7Aa62f58C5b04a2"
stake_manager_contract = "0x228DF261D960d48bDBF50BDC8dc00ba20358aCea"
rootchain_contract = "0x12c1d34135bee2745AD930647F54D36c9dD6Cbe3"
state_sender_contract = "0x061b9fE56513BBa078d509C2377e3E5be9219FeB"
matic_token = "0x6bAA90c411945C2fE93f1D336fb5787b6531a67C"

#Configure peers for Heimdall
$; nano config.toml

paste below value, under "persistent_peers" =
"[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656"

#Try to find the peers your self
Refer to; heimdall-seeds.txt for peer info in your public-testnets folder.

Tips. command to find some folder or file, $; find / -xdev 2>/dev/null -name
ex. you want to find public-testnets, $; find / -xdev 2>/dev/null -name public-testnets

now find heimdall-seeds.txt directory (folder), $; find / -xdev 2>/dev/null -name heimdall-seeds.txt, open with nano and copy the persistent_peers, and then paste it on config.toml, or just type
$; cd ~
$; cd public-testnets/CS-2002/heimdall/
$; cat heimdall-seeds.txt = copy the result, and paste on config.toml

#Generate Heimdall private key
$; cd ~/.heimdalld/config
$; heimdallcli generate-validatorkey <your eth addr private key, that you register for this event>

Refer to; this registration form. https://forms.gle/P2JrXiTFuPvQadbv9

#This will create priv_validator_key.json in the same folder, make sure this file be on ~/.heimdalld/config directory.
If not move this validator key file to heimdall config folder;

$; mv ./priv_validator_key.json $HEIMDALLDIR/config

#Check Heimdall Status;
Do verify you are on the correct version by running

$ heimdallcli version --long on this directory $; cd ~/.heimdalld/config

Tips. you also can do this after you run the Heimdall, no problem

#Start&Sync Heimdall
$; cd ~/.heimdalld/config
$; heimdalld start

Tips. Always running Heimdall on heimdalld configuration directory, or type $; cd ~/.heimdalld/config, this directory is for start or restart the Heimdall Process

You're noticing if your Node has run by saw these words appear, "Executed block" and "Committed state"

and now just get out the shell by pressing ; Ctrl+b & d

D. Run Bor.
$; tmux new-session -s CsBor

$; cd $GOPATH/src/github.com/maticnetwork
$; git clone https://github.com/maticnetwork/bor
$; cd bor && git checkout CS-2002
$; make bor

#Initialise genesis block for Bor
$; cd ~
$; cd public-testnets/CS-2002
$; echo "export CONFIGPATH=$PWD" >> ~/.bashrc
$; source ~/.bashrc
$; cd $CONFIGPATH/bor
$; bash setup.sh
$; echo "export BORDIR=~/.bor" >> ~/.bashrc
$; source ~/.bashrc

This will create Bor home directory at ~/.bor and data directory at ~/.bor/dataDir

#Configure peers for Bor
$; cp static-nodes.json ~/.bor/dataDir/bor/

#Generate Bor keystore file
$; heimdallcli generate-keystore <your eth addr private key, that you register for this event>

This will create a keystore file in UTC format. For example:
UTC--2020-02-10T10-11-48.027180000Z--6c468cf8c9879006e22ec4029696e005c2319c9d

Now you will have to move the keystore file to bor data directory
$; sudo mv UTC--(time)-(address) ~/.bor/keystore/

#Add password.txt
Add the password that you entered as passphrase in the password.txt file

$; sudo nano ~/.bor/password.txt

#Start&Sync Bor
$; bash start.sh

Note. Make sure you are still on this directory; public-testnets/CS-2002/bor

#Check Bor Status;
$; cd $BORDIR/logs
$; tail -f bor.log

Tips. You're noticing if your Node has run by saw these words appear, "Proposer" and "Validators"

and now just get out the shell by pressing; Ctrl+b & d

E. Start&Sync Rest Server.
$; tmux new-session -s CsRs

$; cd ~/.heimdalld/config

$; heimdalld rest-server

and now just get out the shell by pressing; Ctrl+b & d

Note. The rest-server can be used by external services like explorer, faucets etc to connect to heimdall chain for fetching data and sending transactions.

F. Start&Sync Bridge.
#Bridge is a helper package that sends transactions to heimdall on behalf of validators. All interactions with other chains happens via this bridge, Bridge won't run without rabbitmq and rest-server so ensure they are running before trying to run bridge

$; tmux new-session -s CsBrd

$; cd ~/.heimdalld/config

$; bridge start --all

and now just get out the shell by pressing; Ctrl+b & d

#Btw i've made another video about how to Join the Counterstake Testnet, which is by successfully Running Heimdall, Bor, and Rest Server here;

G. Query data.
#To see examples on how to query your full node and get network status,
Refer to; https://api.matic.network/staking/cs1001/swagger-ui/

H1. Stop and Reset the Node.

#Stop Heimdall
$; tmux a -t Cs | Ctrl+c
$; pkill heimdalld
$; sudo rm -rf ~/.heimdall/

Ctrl+b d

Note. To be used only if you need to restart Heimdall and delete old data in the event of a crash or if there are changes in genesis files

#Stop Bor
$; tmux a -t CsBor | Ctrl+c
$; cd $CONFIGPATH/bor
$; bash clean.sh && bash stop.sh
$; sudo rm -rf ~/.bor

Ctrl+b d

#Stop Rest Server
$; tmux a -t CsRs | Ctrl+c

Ctrl+b d

#Stop Bridge
$; tmux a -t CsBrd | Ctrl+c
$; pkill heimdalld-bridge
$; sudo rm -rf $HEIMDALLDIR/bridge

Ctrl+b d

H2. Start the Node, (the staking time has come).

#Start&Sync Heimdall
$; tmux a -t Cs
$; cd ~/.heimdalld/config (if you're not on the config directory yet)
$; heimdalld start

Ctrl+b d

#Check Heimdall Status (you can skip it btw, if your Heimdall Node has run);
additional command to check whether your Heimdall Node were Sync or Not
$; curl http://localhost:26657/status

#Start&Sync Bor
$; tmux a -t CsBor
$; cd $CONFIGPATH/bor
$; bash start.sh

#Check Bor Status (you can skip it btw, if your Bor Node has run);
additional command to check whether your Bor Node were Sync or Not
$; cd $BORDIR/logs
$; tail -f bor.log

Ctrl+b d

#Start&Sync Rest Server
$; tmux new-session -s CsRs
$; cd ~/.heimdalld/config (if you're not on the config directory yet)
$; heimdalld rest-server

Ctrl+b d

#Check Rabbit-MQ Status
$; sudo service rabbitmq-server status (if it not active, apply below command)
$; sudo service rabbitmq-server start

#Start&Sync Bridge
$; tmux new-session -s CsBrd
$; cd ~/.heimdalld/config (if you're not on the config directory yet)
$; bridge start --all

and now just get out the shell by pressing; Ctrl+b & d

then

I. It's Staking Time.
Yess Congrat'z Gang'z you've just join the Matic testnet [CounterStake], and now it's time to stake your testnets token that you got after you're application has been chosen, there'll be 500 TST Token on your Ropsten Eth Address, if you didn't see on your metamask, see it on etherscan.io

#Approve#
The approve command will initiate your transaction towards staking on Matic

$; heimdallcli approve --staked-amount <stake-amount> --fee-amount <heimdall-fee-amount>

For example, to approve for stake amount 100 Matic (TST) Tokens and fee 20 tokens, (must be set 20 TST tokens);

$; heimdallcli approve --staked-amount 100000000000000000000 --fee-amount 20000000000000000000

Note. Stake amount and fee amount must be in 18 decimals, but for sending this tx you still need Eth Ropsten for gas fee, you can pay this fee by claim a Ropsten Faucet, u'll get about 1,5 Eth of Ropsten Testnet Tokens, (you must have this Ropsten Test Eth for being successing Approve & Stake your TST Token)

Once you run the approve command you should see the following response along with the transaction hash;
Sent approve tx sucessfully txHash=0x987aa9a319de34f61b768e4bbac160212055d8e5e9b813b2fc520dc650488943

#Stake#
Once approve transaction gets confirmed, send stake transaction on Ethereum

$; heimdallcli stake --staked-amount <stake-amount> --fee-amount <heimdall-fee-amount> --validator <validator-owner-address>

For example, to stake amount 100 Matic tokens and fee 20 tokens;
$; heimdallcli stake --staked-amount 100000000000000000000 --fee-amount 20000000000000000000 --validator 0xc40e52501d9969B6788C173C1cA6b23DE6f33943

You should see the following response once you run the above command;
Submitted stake sucessfully txHash=0x987aa9a319de34f61b768e4bbac160212055d8e5e9b813b2fc520dc650488943

#Validator join#
You must join Validator to be eligible increasing your TST stake token, you can join the network by running the following command;

$; heimdallcli tx staking validator-join --signer-pubkey <signer-pub-key> --tx-hash <stake-ethereum-tx-hash> --chain-id <chain-id>

You can view your pub-key by running this command;
$; heimdalld show-account

Note. The chain-id required here is the heimdall chain-id; heimdall-cs2002, and if you initiate a Validator Join, before you stake any tokens, it will lead you to got an error message

#Validator Information#
If you want to your Validator Information you can used below command;
$; heimdallcli query staking validator-info --validator=0x6c468cf8c9879006e22ec4029696e005c2319c9d --chain-id heimdall-cs2002

This command should display the following output;
{
"ID":1,
"startEpoch":0,
"endEpoch":0,
"power":10,
"pubKey":"0x04b12d8b2f6e3d45a7ace12c4b2158f79b95e4c28ebe5ad54c439be9431d7fc9dc1164210bf6a5c3b8523528b931e772c86a307e8cff4b725e6b4a77d21417bf19",
"signer":"0x6c468cf8c9879006e22ec4029696e005c2319c9d",
"last_updated":0,
"accum":0
}

#Balance#
After a day or two maybe you want to check your balance by;
$; heimdallcli query auth account <signer-address> --chain-id heimdall-cs2002

The following output should appear;
address: 0x6c468cf8c9879006e22ec4029696e005c2319c9d
coins:

  • denom: matic
    amount:
    i: "1000000000000000000000"
    accountnumber: 0
    sequence: 0

Note. You need to keep checking if your balance has been updated or not.

If there any issue that bug you, just go commenting below, and let see if i or other members can gave you a way out from your issue, and thank you for stopping by and reading my tutorial, i hope this article can clear one of your problem on how to Buidling and Running your Counterstake Node, Thank you very much and hope to see you join with me and other's on this Counterstake Phase One, See you there, Cheers

Coin Marketplace

STEEM 0.19
TRX 0.15
JST 0.029
BTC 63061.76
ETH 2602.70
USDT 1.00
SBD 2.75