CodeChain Staking Guide

Kwang Yul Seo
CodeChain
Published in
7 min readMay 16, 2019

CodeChain is a proof-of-stake based network. Stakeholders elect validators by delegating their stakes to credible validator candidates. The elected validators perform consensus for the network to earn rewards. This guide explains how staking in CodeChain works.

https://www.pexels.com/photo/close-up-photography-of-yellow-green-red-and-brown-plastic-cones-on-white-lined-surface-163064/

Two Token Model

Before diving into the details of staking and delegation, you need to understand the token economy of the CodeChain network. CodeChain has two native tokens: a) Fee Token (CCC) and b) Stake Token (CCS). Let’s examine these two tokens in order.

CodeChain Fee Token (CCC)

CCCs are the native tokens of CodeChain, which is used for paying transaction fees. On the CodeChain network, anyone who signs a transaction pays the transaction fees. Transaction fees consist of a) minimum fees and b) express fees.

Minimum fees specify the minimum amount of CCC that must be paid for a transaction to be processed by the network. A transaction that does not meet the minimum fee requirement is rejected by validators.

But why would one pay higher transaction fees if any validator accepts a transaction with the minimum fee? Users pay extra transaction fees if they want their transactions to be processed more quickly. Validators pick transactions with higher fees because they can earn more rewards by including these high-priced transactions in the block. These extra fees (excluding minimum fees) are called express fees.

Then who are the beneficiaries of transaction fees? There are two beneficiaries: validators and stakeholders. Minimum fees are distributed to the network stakeholders who own stakes and express fees are given to the block author as described in the diagram below. Contrary to other popular PoS networks, CodeChain stakeholders earn transaction fees with no endeavor to delegate their stakes.

Note that each transaction type has a different minimum fee requirement. The minimum fee for each transaction type can be changed by the stakeholders’ votes (if more than 51% agree to the change). The minimum fee at genesis is defined as:

CodeChain Staking Token (CCS)

CCSs are the native staking tokens of CodeChain. CCSs represent two rights:

  1. Participate in consensus for CodeChain by delegating stakes to validators. Stakeholders have the right to choose validators in proportion to shares by delegating their stakes.
  2. Earn transaction fees paid to the network. Earnings are distributed to stakeholders on a pro-rata basis. If a stakeholder has 20% of the total CCS, he gets 20% of the transaction fees paid to the network. The fees are paid every block.

Now that you understand the token model of CodeChain, it’s time to learn how staking in CodeChain works. Let’s start the journey by explaining how one can participate in the CodeChain consensus by becoming a validator.

Nomination

Any node can nominate itself as a validator by depositing at least 10M CCC (MIN_DEPOSIT). The deposit is slashed when malicious behavior, such as double-signing of blocks, is reported.

CCSs are not required for nomination, but a node needs to get delegations of stakeholders to be elected as a validator. Depositing a large amount of CCC is a good signal to stakeholders because the deposit shows its willingness to be an honest validator.

Validator Election

CodeChain validator election algorithm picks 30 (MAX_NUM_OF_VALIDATORS) candidates in order of the amount of received delegations. The top 4 (MIN_NUM_OF_VALIDATORS) nodes become validators regardless of the amount of delegations because the Tendermint algorithm that CodeChain uses needs at least 4 validators to be functional.

The accounts that received less than 100,000 CCS (DELEGATION_THRESHOLD, 1% of total CCS) are dropped from the list of validators, even though they are a part of the top 30 validators. This prevents accounts with little delegations from becoming validators.

Here’s the formal procedure of the validator election:

  1. Pick 30 candidates in order of the amount of received delegations.
  2. Select the top 4 accounts; they become validators no matter what.
  3. Among the rest of them, drop the accounts that received less than 100,000 CCS; the remaining accounts become validators.

Validator Reward

Why would a node want to be a validator? What rewards does a node get by becoming a validator? As we briefly discussed in the token model, the block author gets the express fees of the blocks at the end of a term. These express fees have real value because validators can sell them on cryptocurrency exchanges and earn cash.

Most PoS-based blockchain networks, such as EOS, give block rewards to their validators by generating new tokens. In other words, staking rewards are created through inflation. This is pointless as described in the article by Ben Davenport:

If everyone holding a given crypto-asset is staking all their coins, then everyone gets (out of thin air) a new amount of coins each period exactly proportional to their existing ownership. So, at the end of every period, everyone’s ownership stake in the asset is exactly the same as it was previously

Validators can withdraw the reward after waiting for 1 hour. This withdrawal delay is mandatory because validator rewards are slashed when malicious behaviors such as a) double-votes or b) extended validator downtime are detected.

Punishment

The deposit made and the reward earned by the criminal validator are slashed if double-signing of blocks is detected. The slashed deposit and rewards are given to the informant reporting the double vote. Any validator of the committee at the given term can report malicious behavior.

Selfish validators who do not participate in signing the blocks proposed by other nodes are punished by incrementally slashing the rewards that the validator can claim at the end of the term. If a validator misses 1/3 of the blocks, the reward is decreased by 10%. If it misses more than 1/3 of the blocks, the reward decreases at a much more rapid rate, up to 90%. Finally, there is no reward at all if it misses more than 2/3 of the blocks.

Also to prevent some validators from rejecting other validators’ signatures to their proposal, CodeChain gives additional rewards to validators who diligently collected signatures. The reward algorithm is described in the “Validator Reward” section of the spec.

Note that on contrary to other PoS chains that slash both validator deposits and delegator funds, CodeChain only slashes the validator’s deposit in all cases. Stakeholders are risk-free and encouraged to change their delegations to another validator quickly to make the network stable.

Jail

A validator who doesn’t produce blocks is jailed for a while. It gives validators time to fix the nodes that they manage. The jailed account can nominate itself again after 24 hours (CUSTODY_PERIOD). There is no deposit slash because this situation can happen due to unforeseeable circumstances, such as network failure.

Validator Lifecycle

We can summarize the lifecycle of a validator we’ve discussed so far as follows:

  1. An eligible node becomes a candidate node by self-nomination.
  2. If there is no self-nomination during NOMINATE_EXPIRATION terms, the candidate node goes back to an eligible state.
  3. A candidate node is elected as a validator according to the election algorithm described below.
  4. A validator node goes back to a candidate node when the given term ends, and the validator did its work.
  5. A validator is jailed if it didn’t work properly.
  6. A validator who double-voted is banned permanently.
  7. A jailed validator becomes a candidate node again if it self-nominates after CUSTODY_PERIOD
  8. A jailed validator can’t get out of the jailed state if it self-nominates before CUSTODY_PERIOD
  9. A jailed validator goes back to an eligible state if there is self-nomination during RELEASE_PERIOD.

Validator Hardware Requirements

If you want to participate in the network as a validator, you must meet the minimum hardware requirements specified below:

CPU: Intel Core i7–6700 / AMD Ryzen 5 1600 and above

Memory: 16GiB+

Disk: 1TiB+ SSD

Network: 1Gbps+

If you plan to run a validator on Amazon AWS, we recommend c5.2xlarge instance.

Parameters

Currently, staking parameters are defined as follows. They are subject to change upon stakeholders’ voting.

Conclusion

This article is a guide to help validators understand the mechanism of CodeChain staking. If you would like to know the details of each rule, please refer to the specification.

--

--