Staking & Validators

Understanding Polkadot's Staking Mechanism and Validator System

Polkadot's Staking System

Polkadot uses a Nominated Proof-of-Stake (NPoS) consensus mechanism where validators secure the network and nominators support validators with their stake. This system ensures network security while allowing token holders to participate in consensus without running validator nodes.

NPoS Consensus

Nominated Proof-of-Stake is a variation of Proof-of-Stake that separates the roles of block production and stake delegation:

Validators

Validators are responsible for producing blocks, validating parachain blocks, and participating in consensus.

  • • Run full nodes
  • • Produce blocks
  • • Validate parachain blocks
  • • Participate in consensus
  • • Earn rewards and face slashing

Nominators

Nominators support validators by staking their tokens and share in the rewards and risks.

  • • Stake tokens to validators
  • • Share in validator rewards
  • • Face slashing risks
  • • Can change nominations
  • • No need to run nodes

Validator Selection

Polkadot uses a sophisticated algorithm to select validators that maximizes network security and decentralization:

Selection Criteria:

  • Stake Distribution: Algorithm tries to distribute stake evenly
  • Geographic Distribution: Prefers validators from different locations
  • Validator Performance: Considers historical performance
  • Nominator Preferences: Respects nominator choices
  • Minimum Stake: Validators must meet minimum stake requirements

Staking Operations

Let's explore the key staking operations using Polkadot.js API:

// Staking operations with Polkadot.js API
import { ApiPromise, WsProvider } from '@polkadot/api';
import { Keyring } from '@polkadot/keyring';

const api = await ApiPromise.create({ provider: new WsProvider('wss://rpc.polkadot.io') });
const keyring = new Keyring({ type: 'sr25519' });

// 1. Bond tokens for staking
const bondTx = api.tx.staking.bond(
  '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY', // controller account
  1000000000000, // amount to bond
  'Staked' // reward destination
);

// 2. Nominate validators
const nominateTx = api.tx.staking.nominate([
  '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY',
  '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty'
]);

// 3. Set controller account
const setControllerTx = api.tx.staking.setController(
  '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY'
);

// 4. Unbond tokens
const unbondTx = api.tx.staking.unbond(500000000000);

// 5. Withdraw unbonded tokens
const withdrawTx = api.tx.staking.withdrawUnbonded(0);

Rewards and Slashing

The staking system includes both rewards for good behavior and penalties for bad behavior:

Rewards

Validators and nominators earn rewards for participating in consensus:

  • • Block production rewards
  • • Parachain validation rewards
  • • Consensus participation rewards
  • • Inflation-based rewards
  • • Transaction fees

Slashing

Validators and nominators face penalties for malicious behavior:

  • • Double signing blocks
  • • Unavailability during validation
  • • Invalid parachain block validation
  • • Consensus rule violations

Era and Session Management

Polkadot uses eras and sessions to manage validator sets and reward distribution:

// Era and session information
// Get current era
const currentEra = await api.query.staking.currentEra();
console.log('Current era:', currentEra.toString());

// Get active validators for current era
const activeValidators = await api.query.session.validators();
console.log('Active validators:', activeValidators.toHuman());

// Get validator info
const validatorInfo = await api.query.staking.validators('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY');
console.log('Validator info:', validatorInfo.toHuman());

// Get nominator info
const nominatorInfo = await api.query.staking.nominators('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY');
console.log('Nominator info:', nominatorInfo.toHuman());

// Get staking rewards for an era
const rewards = await api.query.staking.erasRewardPoints(currentEra);
console.log('Era rewards:', rewards.toHuman());

Validator Economics

Understanding the economics of running a validator is crucial for network participants:

Validator Economics:

  • Hardware Costs: Servers, bandwidth, and maintenance
  • Stake Requirements: Minimum stake to become a validator
  • Commission: Percentage of rewards kept by validator
  • Slashing Risk: Potential loss of stake for bad behavior
  • Reward Distribution: How rewards are shared with nominators

Staking Best Practices

Staking Best Practices:

  • Diversify Nominations: Nominate multiple validators to reduce risk
  • Research Validators: Check validator performance and commission
  • Monitor Performance: Keep track of validator uptime and rewards
  • Understand Slashing: Be aware of slashing conditions and risks
  • Plan Unbonding: Consider unbonding periods when planning
  • Use Reliable Tools: Use trusted wallets and staking interfaces
  • Stay Updated: Keep up with network changes and updates

Summary

In this chapter, we've explored Polkadot's staking and validator system:

  • • NPoS separates validator and nominator roles
  • • Validators secure the network and earn rewards
  • • Nominators support validators and share in rewards
  • • Sophisticated algorithm selects validators for security
  • • Slashing provides economic incentives for good behavior
  • • Era and session management organize validator sets

In the next chapter, we'll explore Polkadot's governance system, learning how network participants can propose and vote on changes to the protocol.