How to be validator after staking upgrade

How to be validator after staking upgrade

After the staking upgrade, running a validator is different from before. This article describes all the tasks you’ll face when starting a validator.

Basic Concepts

Before we go to the details, let’s first discuss some important concepts.

Staking and Voting

Staking and voting are two different things on smartBCH. To become a validator on duty, a.k.a, an active validator, you need both of them: 1) you must stake at least 32 sBCH; 2) you must get enough votes from sBCH holders.

On some blockchains, staking and voting are combined, such as COSMOS. On COSMOS, If you vote for a validator, you also stake your coins to it. If the validator is slashed, you lost some of the staked coins, too.

We decided to seperate staking and voting on smartBCH, to make the voters safer. If a validator is slashed, its voters will not lose sBCH because of this.

Since staking and voting are seperated, they have a lot differences.

  1. The staking tasks are handled by the staking system contract, while the voting tasks are handled by the xhedge contract (a normal EVM-based contract, not system contract).

  2. The minimum amount of staked coins for a new validator is 32 sBCH, while the minimum vote for a new validator is 500 coin-days. Yes, the votes are counted in coin-days (sBCH*Day), instead of coins. You put your coins into the NFTs of the xhedge contract. When a NFT accumulates enough coin-days, you consume them to vote for a validator. You never lose your sBCH because of voting for validators, while a validator will lose its sBCH if it is slashed.

  3. The staked coins come from the validator. The voted coin-days come from anyone who supports this validator (including its self).

Consensus key-pair and EVM key-pair

SmartBCH uses tendermint as the consensus engine. Tendermint use the ED25519 curve’s key pair to sign blocks. Such key pairs are referred to as “consensus key”. A validator is identified by the ED25519 public key. Such key pairs are usually stored in files on hard disks. You must carefully store your consensus key. If it is lost, your validator cannot sign any block. If it is stolen, the attacker can double-sign blocks and your validator will be slashed. The consensus keys can only be recognized by the tendermint engine. You do not use them to sign smartBCH transactions and your EVM address has nothing to do with them.

EVM key pairs are based on the secp256k1 curve and stored in your wallets (MetaMask, TrustWallet, Rubby, etc). You sign transactions with them and your EVM addresses are calculated from them. A validator needs an EVM account to stake sBCH, so you also need a secp256k1 key pair. You must carefully store this key pair. If it is lost, your staked sBCH will stuck in the contract. If it is stolen, your staked sBCH will also be stolen.

Retiring and Slashing

If you do not want to run your validator any longer, you can send a “retire” transaction to the staking system contract. And your validator will not be elected as a validator in the next epoch, even if supporters vote for it through the xhedge contract. In the current epoch, your validator still has voting power and must sign blocks until the epoch’s end. This is the normal retiring flow.

If your validator is slashed because of double-signing or offline failure, it will also be forced to retire. This is the abnormal retiring flow. Slashing is always followed by a forced retiring. But initiative retiring has nothing to do with slashing.

In the next epoch after the retiring event happens, the validator is still recorded in the validator list, with votingpower=0 and retire=true. During this epoch, the validator is still possible to be slashed if it double-signs an old block, which is an obvious attacking behavior. Yes, a retiring validator can still be slashed because of double-signing. At the end of this epoch, the validator will be removed from the validator list and its staked coins will be returned. When you get the returned coins, you can use them to create a new validator.

Using the staking system contract

Here we introduce the steps related to the staking system contract. If you do not want to run a validator, and just want to vote for someone’s validator, you can skip this section.

Step 1: Generate validator consensus key

To run a smartbchd node for your validator, a consensus key pair must be added to the node. Using the following command to generate it:

./smartbchd generate-consensus-key-info | tee generate-consensus-key-info.txt

The output hex string is the ED25519 consensus pubkey which will be used in the commands below, and a file containing the consensus public and private key is generated under the current directory, named priv_validator_key.json.

Please copy the priv_validator_key.json to your node’s work dir: .smartbchd/config/. Then restart you smartbchd node.

To learn how to run a smartbchd node, please refer to: Mainnet - smartbch

Step 2: Register new validator through Web frontend

We suggest prepare a dedicated EVM account for your validator. Don’t use it in DEX or other DApps. You can use MetaMask or Rubby to store this EVM account’s key pair. A validator’s collected gas fee can be rewarded to another EVM address, which is referred to as the “RewardTo” address. It’s OK to set the “RewardTo” address to the validator’s address, i.e., not rewarding to another address.

You can register new validator through smartbch’s staking frontend. Go to smartBCH Staking Frontend , connect to this DApp with your validator’s EVM account through MetaMask:

In “Create Validator” box,enter “RewardTo” address, “Introduction” and “PubKey” , the “sBCH to Stake” must be at least 32 sBCH. The “PubKey” is just the ED25519 pubkey generated at step 1. Then click “Submit” button to finish the registration. Then, you can click “Refresh” button in “All Validators” box to see all validators. Your newlly registered validator should be listed:

Step 2a: supplement the staking sBCH

If you running a validator that was created before the staking upgrade, you need to supplement the sBCH to hit the 32 sBCH, which is required by the latest smartbchd nodes.

Go to smartBCH Staking Frontend , connect this app with your validator account through MetaMask:

In “Edit Validator” box,enter “RewardTo” address, “Introduction”, enter “More sBCH to Stake” the sBCH you want to supplement. After supplement, your staked coins must be at least 32 sBCH. Then click “Submit” button to finish the edit. Then, you can click “Refresh” button in “All Validators” box to find your validator staking information.

Vote using the xhedge smart contract

SmartBCH’s validators are shuffled in epochs. During an epoch, the sBCH holders votes for the validators. At the end of an epoch, the votes are counted and new validators are put on duty, i.e., activated.

There can be at most 50 active validators on duty. If there are more than 50 registered validators, then the top 50 validators with most voted coin-days will be activated. If there are no more than 50 registered validators, then all the validators with non-zero voted coin-days will activated. A new validator needs at least 500 voted coin-days to be activated for the first time.

After you register your validator, you need some voted coin-days to put it on duty. You can do this youself or ask some other sBCH holder to vote for you.

Please goto https://xhedge.cash/ to operate. Click the Create tag.

This is the create NFTs page. you can change the default data by yourself.

Please fill in the validator’s ED25519 public key generated in Step 1 and the BCH price oracle address. And change the Fixed USD Value in HedgeNFT to your target amount. We suggest to use 0xa1b0C0158b8602de44A291B563FAd733baE10Eeb as the BCH price oracle, which always asserts that one BCH values 350 USD.

Then click the Create! button. Note that the “Fixed USD Value in HedgeNFT” should not be too small, we recommend at least 3 BCH.

After the transaction is confirmed, click the Tokens tag. Click List tokens owned by myself to show NFTs just created in above operation.

The NFT token id can be found on first line in NFT content, copy it.

Click Operate tag.

Please fill in the NFT token id listed below and click Vote button. After the transction is confirmed, vote is done successfully. Then, you can click “Refresh” button in “All Validators” box at smartBCH Staking Frontend to find your validator XHedgeVotes information.

For more details about XHedge contract, please refer to: https://docs.smartbch.org/smartbch/developers-guide/xhedge-contract

Monitor your validator online status

After the staking upgrade, the validator’s online status will be monitored by the nodes. If a validator is offline for a long time, it will be slashed. For more details please refer to: More about the Staking Upgrade. We introduced smartBCH’s staking… | by smartBCH | Aug, 2023 | Medium

You can view the validators’ online status on smartBCH Staking Frontend. Click “Refresh” button in “All Validators” box to see your validator.

The “healthRate” row shows the health status of being online in current fix time window. Its score is in the range [0, 1]. When the score is close to zero, the validator is unhealthy and likely to be slashed. When the score is close to one, the validator is healthy. This row is colored to be green, yellow or red, which is a hint for you.

When it shows green, your validator is working well and signs blocks normally. When it shows yellow, your validator may have internet connection problems or is power-down. You must recover it immediately. When it shows red, your validator have missed many blocks and is very likely to be slashed. You’d better send the retire transaction immediately, which can prevent your staked coins from being slashed.

When it shows yellow and you have recovered your node, it will not turn back to green immediately. The score may continue to drop and the color may still turn to red. You should continue to watch the score and the color. If the color turns red, please send the retire transaction.

Connect this app with your validator account through MetaMask, and click the Submit button in Retire Validator Box to retire your validator to make sure it will not be slashed.

When you hover the mouse over the “Health Rate” field, you can see the following information:

  1. The start height and the end height of current fixed monitoring time window. In this example, the start height is 1129400 and the end height is 11308400.

  2. The validator’s signed block count in current window. In this example, the validator has signed 8298 blocks.

  3. The validator’s missed (unsigned) block count in current window. In this example, the validator has missed 0 blocks.

  4. The score. In this example, it is 1, which means very healthy.