Skip to content

Instantly share code, notes, and snippets.

@Validatrium
Created March 13, 2023 13:46
Show Gist options
  • Save Validatrium/60008ece3f33ce3de92e318082c6b554 to your computer and use it in GitHub Desktop.
Save Validatrium/60008ece3f33ce3de92e318082c6b554 to your computer and use it in GitHub Desktop.
Setup C4E mainnet node

Prerequires

  • root access to the server
  • VPS:
    • CPU: 4 Cores
    • RAM: 16 GB
    • SSD: 300 GB

Install additional packages and binary

VERSION=v1.1.0 # actual version of binary

sudo apt update && sudo apt upgrade -y 
sudo apt install -y curl git jq lz4 build-essential

# Install GO:
wget https://go.dev/dl/go1.19.3.linux-amd64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.19.3.linux-amd64.tar.gz

echo 'export GOPATH=/usr/local/go' >> $HOME/.bashrc
echo 'export GOBIN=$GOPATH/bin' >> $HOME/.bashrc
echo 'export PATH=$PATH:$GOBIN' >> $HOME/.bashrc
source $HOME/.bashrc

# c4ed installation: 
git clone https://github.com/chain4energy/c4ed-chain.git && cd c4ed-chain
git checkout $VERSION
make install
# verify c4ed binary is installed
c4ed version

Create non-root user

addusr c4e
usermod -aG sudo c4e
su - c4e

c4ed configuration

# fill the temp variables. It will be erased after you disconnect from server 
ACCOUNT=<> # your node moniker
CHAIN=perun-1
RPC=https://rpc.c4e.nodestake.top:443
# init stride home directory
c4ed init $ACCOUNT --chain-id $CHAIN
# download genesis
curl $RPC/genesis | jq -r .result.genesis > ~/.c4e-chain/config/genesis.json
# set peers 
peers=$(curl -s $RPC/net_info | jq  -r '.result.peers[] | .node_info.id+"@"+.remote_ip+":"+(  .node_info.listen_addr| sub(".*:";"") )' | tr '\n' ',')
sed -i "s/persistent_peers =.*/persistent_peers = \"$peers\"/g" ~/.c4e-chain/config/config.toml

# configure state-sync
SNAP_RPC=$RPC

LATEST_HEIGHT=$(curl -s $SNAP_RPC/block | jq -r .result.block.header.height); \
BLOCK_HEIGHT=$((LATEST_HEIGHT - 2000)); \
TRUST_HASH=$(curl -s "$SNAP_RPC/block?height=$BLOCK_HEIGHT" | jq -r .result.block_id.hash)

echo $LATEST_HEIGHT $BLOCK_HEIGHT $TRUST_HASH

sed -i.bak -E "s|^(enable[[:space:]]+=[[:space:]]+).*$|\1true| ; \
s|^(rpc_servers[[:space:]]+=[[:space:]]+).*$|\1\"$SNAP_RPC,$SNAP_RPC\"| ; \
s|^(trust_height[[:space:]]+=[[:space:]]+).*$|\1$BLOCK_HEIGHT| ; \
s|^(trust_hash[[:space:]]+=[[:space:]]+).*$|\1\"$TRUST_HASH\"| ; \
s|^(seeds[[:space:]]+=[[:space:]]+).*$|\1\"\"|" .c4e-chain/config/config.toml

Run c4ed as a systemd service

sudo tee /etc/systemd/system/c4ed.service > /dev/null <<EOF 
[Unit]
Description=C4E Node
After=network-online.target 

[Service]
User=$USER
ExecStart=$(which c4ed) start
Restart=on-failure
RestartSec=3
LimitNOFILE=4096

[Install]
WantedBy=multi-user.target 
EOF

sudo systemctl enable c4ed 
sudo systemctl start c4ed
# you can see c4ed logs by running the command: 
journalctl -u c4ed -f 

Save some usefull variables

cat <<EOF >> ~/.bashrc

. <(c4ed completion)
# public rpc in case you will need it : ) 
export RPC=$RPC
export ACCOUNT=$ACCOUNT
export CHAIN=$CHAIN
EOF

source ~/.bashrc

Create Validator

c4ed tx staking create-validator \
  --commission-max-change-rate 0.01 \
  --commission-max-rate 0.20 \
  --commission-rate 0.05 \
  --amount 1000000uc4e\
  --pubkey $(c4ed tendermint show-validator) \
  --chain-id $CHAIN \
  --moniker $ACCOUNT \
  --min-self-delegation "1" \
  --gas-adjustment 1.5 \
  --gas auto \
  --fees 0uc4e \
  --from $ACCOUNT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment