AlveyChain Documents
  • Alveychain Docs
  • Get-Started
    • Alveychain
    • Installation
    • Local Setup
    • Cloud Setup
    • Full Node
    • CLI Commands
    • JSON RPC Commands
    • Performance Reports
  • Configuration
    • Manage private keys
    • Set up Hashicorp Vault
    • Enable Prometheus metrics
  • Working-With-Node
    • Query JSON RPC endpoints
    • Query operator information
    • Backup/restore node instance
  • Consensus
    • Proof of Authority (PoA)
    • Proof of Stake
    • Set up and use Proof of Stake (PoS)
    • Migration from PoA to PoS
  • Additional Features
    • Alveycoin bridge
    • Network stress testing
    • Blockscout
  • Architecture
    • Architecture Overview
    • modules
      • Blockchain
      • Consensus
      • JSON RPC
      • Minimal
      • Networking
      • Other modules
      • Protocol
      • Sealer
      • State
      • Storage
      • TxPool
      • Types
  • Concepts
    • State in Ethereum
  • Community
    • Propose a new feature
    • Report an issue
  • Docs
    • Server Config File
    • how-tos
      • How to set up and use Proof of Stake (PoS)
Powered by GitBook
On this page
  • Overview
  • ValidatorSet Smart Contract
  • Setting up an N node cluster
  • Setting the length of an epoch
  • Using the ValidatorSet Smart Contract scripts
  1. Consensus

Set up and use Proof of Stake (PoS)

PreviousProof of StakeNextMigration from PoA to PoS

Last updated 2 years ago

Overview

This guide goes into detail on how to set up a Proof of Stake network with the alveychain, how to stake funds for nodes to become validators and how to unstake funds.

It highly encouraged to read and go through the / sections, before going along with this PoS guide. These sections outline the steps needed to start a Proof of Authority (PoA) cluster with the alveychain.

Currently, there is no limit to the number of validators that can stake funds on the ValidatorSet Smart Contract.

ValidatorSet Smart Contract

The repo for the ValidatorSet Smart Contract is located .

It holds the necessary testing scripts, ABI files and most importantly the ValidatorSet Smart Contract itself.

Setting up an N node cluster

Setting up a network with the alveychain is covered in the / sections.

The only difference between setting up a PoS and PoA cluster is in the genesis generation part.

When generating the genesis file for a PoS cluster, an additional flag is needed --pos:

alveychain genesis --pos ...

Setting the length of an epoch

Epochs are covered in detail in the section.

To set the size of an epoch for a cluster (in blocks), when generating the genesis file, an additional flag is specified --epoch-size:

alveychain genesis --epoch-size 50

This value specified in the genesis file that the epoch size should be 50 blocks.

The default value for the size of an epoch (in blocks) is 100000.

The default epoch length in blocks (100000) may be a long time to way for validator set updates. Considering that new blocks are added ~2s, it would take ~55.5h for the validator set to possibly change.

Setting a lower value for the epoch length ensures that the validator set is updated more frequently. :::

Using the ValidatorSet Smart Contract scripts

Prerequisites

The ValidatorSet Smart Contract repo is a Hardhat project, which requires NPM.

To initialize it correctly, in the main directory run:

npm install

Setting up the provided helper scripts

Create an .env file with the following parameters in the Smart Contracts repo location:

JSONRPC_URL=http://localhost:10002
PRIVATE_KEYS=0x0454f3ec51e7d6971fc345998bb2ba483a8d9d30d46ad890434e6f88ecb97544
VALIDATOR_CONTRACT_ADDRESS=0x0000000000000000000000000000000000001001

Where the parameters are:

  • JSONRPC_URL - the JSON-RPC endpoint for the running node

  • PRIVATE_KEYS - private keys of the staker address

  • VALIDATOR_CONTRACT_ADDRESS - the address of the ValidatorSet smart contract ( default 0x0000000000000000000000000000000000001001)

Staking funds

:::info ValidatorSet address The ValidatorSet Smart Contract is pre-deployed at address 0x0000000000000000000000000000000000001001.

Any kind of interaction with the staking mechanism is done through the ValidatorSet Smart Contract at the specified address.

In order to become part of the validator set, an address needs to stake a certain amount of funds above a threshold.

Currently, the default threshold for becoming part of the validator set is 10000000 ALV.

ValidatorSet can be initiated by calling the stake method of the ValidatorSet Smart Contract, and specifying a value >= 10000000 ALV.

npm run stake

The stake Hardhat script stakes a default amount of 1000000 Alveycoin, which can be changed by modifying the scripts/stake.ts file.

If the funds being staked are >= 1000000 Alveycoin, the validator set on the ValidatorSet Smart Contract is updated, and the address will be part of the validator set starting from the next epoch.

Unstaking funds

Addresses that have a stake can only unstake all of their funds at once.

npm run unstake

Fetching the list of stakers

All addresses that stake funds are saved to the ValidatorSet Smart Contract.

npm run info

:::info Lowering the epoch length As outlined in the section, epoch blocks are used to update the validator sets for nodes.

Scripts for interacting with the deployed ValidatorSet Smart Contract are located on the .

To learn more about the ValidatorSet Smart Contract, please visit the section. :::

After the .env file mentioned in the has been set up, and a chain has been started in PoS mode, staking can be done with the following command in the ValidatorSet Smart Contract repo:

After the .env file mentioned in the has been set up, and a chain has been started in PoS mode, unstaking can be done with the following command in the ValidatorSet Smart Contract repo:

After the .env file mentioned in the has been set up, and a chain has been started in PoS mode, fetching the list of validators can be done with the following command in the ValidatorSet Smart Contract repo:

Local Setup
Cloud Setup
here
Local Setup
Cloud Setup
Epoch Blocks
Epoch Blocks
ValidatorSet Smart Contract repo
ValidatorSet Smart Contract
previous section
previous section
previous section