Staking on miners and sharders

0Chain miner smart contract allows staking on the miner and sharder nodes to validate transactions and earn rewards. To start staking on miner and sharder nodes, miner and sharder ID's are required which can be fetched using below commands.

Listing all miners

./zwallet ls-miners list the miners retrieved using the Miner smart contract. Parameters can be viewed using ./zwallet ls-miners --help flag.

Get list of all active miners from Miner SC

Usage:
  zwallet ls-miners [flags]

Flags:
  -h, --help   help for ls-miners
      --json   as JSON

--jsonflag can be passed to retrieve miners as JSON data.

Command:

./zwallet ls-miners

Sample Output:

- ID:         cdb9b5a29cb5f48b350481694c4645c2db24500e3af210e22e2d10477a68bad2
- Host:       one.devnet-0chain.net
- Port:       31203
- ID:         3d9a10dac6fb3903d4a5283a42ae07b29d8e5d228afcce9bfc14e3e9dbc82748
- Host:       one.devnet-0chain.net
- Port:       31201
- ID:         aaa721d5fbf4ca83e20c8c40874ebcb144b86f57173633ff1702968677c2fa98
- Host:       one.devnet-0chain.net
- Port:       31202

Listing all sharders

./zwallet ls-sharders list the sharders retrieved using the Miner smart contract. Parameters can be viewed using ./zwallet ls-sharders --help flag.

Get list of all active sharders from Miner SC

Usage:
  zwallet ls-sharders [flags]

Flags:
      --all    include all registered sharders
  -h, --help   help for ls-sharders
      --json   as JSON

--all flag can be passed to retrieve all the available sharders where as --jsonflag will retrieve sharders as JSON data.

Command:

./zwallet ls-sharders

Sample output:

MagicBlock Sharders
ID: 5421a8d0c9302af3cc79ac7e79d0c35eb09e7a25cb555fb3d6de9ab9dfcbc21c
  - N2NHost: five.devnet-0chain.net
  - Host: five.devnet-0chain.net
  - Port: 31102
ID: d438037cd4ca7acf3d7e40823a661a747a3fe1724921a98b4d90657d5a056195
  - N2NHost: five.devnet-0chain.net
  - Host: five.devnet-0chain.net
  - Port: 31101

Get the staking configuration

To find out the number of delegates and the minimum and maximum tokens that can be staked, query the config using ./zwallet mn-config command.

./zwallet mn-config command displays the configuration and current requirements for staking.

Command:

./zwallet mn-config

Response:

view_change:           0
max_n:                 8
min_n:                 2
max_s:                 3
min_s:                 1
t_percent:             0.51
k_percent:             0.75
last_round:            4758531
max_stake:             100
min_stake:             0
interest_rate:         5.55e-07
reward_rate:           1
share_ratio:           0.8
block_reward:          0.21
max_charge:            0.5
epoch:                 15000000
reward_decline_rate:   0.1
interest_decline_rate: 0.1
max_mint:              4000000
minted:                999303.9977045408
max_delegates:         200

According to the response the max delegates allowed are 200, where as the minimum and maximum number of tokens that can be staked are 0 and 100.

Get the miner or sharder info for staking

./zwallet mn-info command can be used to get staking info for a particular sharder or miner.

Parameters for mn-info command can be viewed using ./zwallet mn-info --help

Usage:
  zwallet mn-info [flags]

Flags:
  -h, --help        help for mn-info
      --id string   miner/sharder ID to get info for

Here,--id flag requires a particular miner and sharder ID which can be fetched using the ls-minersor ls-sharders command. For demonstration we are using a particular miner id fetched using ls-miners command.

Command:

./zwallet mn-info --id 68ed8f16e1d50e3217425b3e98fb7a39e5d7201fe4b1dccfe8477b5c54761b24

Response:

{
  "simple_miner":{
    "id":"68ed8f16e1d50e3217425b3e98fb7a39e5d7201fe4b1dccfe8477b5c54761b24",
    "n2n_host":"five.devnet-0chain.net",
    "host":"five.devnet-0chain.net",
    "port":31102,
    "path":"sharder02",
    "public_key":"458170c28496333426f9866989f7b335564d13d00f50db503275e7ec50a008031764ba5df42c20c85d76e7fe7eda43f39afdb650b8ffa9ed340e6fc50c35ae22",
    "short_name":"localhost.s02",
    "build_tag":"50fb047353c4c3d268c0e0ebfd8e63f1d10c6813",
    "total_stake":0,
    "delegate_wallet":"68ed8f16e1d50e3217425b3e98fb7a39e5d7201fe4b1dccfe8477b5c54761b24",
    "service_charge":0.1,
    "number_of_delegates":10,
    "min_stake":0,
    "max_stake":1000000000000,
    "stat":{
      "sharder_rewards":1160553450000000
    },
    "node_type":"sharder",
    "last_health_check":1619554377
  },
  "pending":{
    "01978379a586de2882638345e215baaf8382093609d910da5ac1a833e2814f6f":{
      "stats":{
        "delegate_id":"133807913c66ec0b4342612f23fecd1852b456152433b8380cd2abcd411d4c07",
        "high":0,
        "low":-1,
        "interest_paid":0,
        "reward_paid":0,
        "number_rounds":0,
        "status":"PENDING"
      },
      "pool":{
        "pool":{
          "id":"01978379a586de2882638345e215baaf8382093609d910da5ac1a833e2814f6f",
          "balance":10000000000
        },
        "lock":{
          "delete_view_change_set":false,
          "delete_after_view_change":0,
          "owner":"ff12c78ee4a985b4fc2ac52ec8a24e9df2bd912636da15437b0eb7707b99abf4"
        }
      }
    }
  }
}

Locking a stake on a node

Staking tokens on a miner or sharder nodes helps earning additional tokens over time. Tokens locked for staking can be unlocked anytime but you have to wait for the next view change cycle.

Note: If a node becomes offline, all stake pools are automatically unlocked and tokens are returned to wallets.

Stalking tokens can be locked using the ./zwallet mn-lock command. Parameters for locking the tokens can be viewed using the ./zwallet mn-lock --help.

Flags:
  -h, --help           help for mn-lock
      --id string      miner/sharder ID to lock stake for
      --tokens float   tokens to lock

Here, miner /sharder id with the required number of tokens to be locked are required.

Command for locking 0.2 tokens:

./zwallet mn-lock --id cdb9b5a29cb5f48b350481694c4645c2db24500e3af210e22e2d10477a68bad2 --tokens 0.2

Response:

locked with: b488738546d84aed9d3dcb2bbe24c161bc4338638669e64e814631efd430fd85

Note: If the locking of stakes is failing, verify the following.

  1. Wallet has enough tokens

  2. Node ID is valid

  3. Node has available delegates

Getting the stake pools of a wallet

A stake pool allows multiple stakeholders (miners/sharders) to contribute to a blockchain in a manner that it increase their chances of earning staking rewards. Every stakeholder stakes tokens through its wallet in the stake pool.

To get the stake pool information of a particular wallet,./zwallet mn-user-info command can be used. Parameters for the ./zwallet mn-user-infocan be viewed using the --help tag.

Flags:
      --client_id string   get info for user, if empty, current user used, optional
  -h, --help               help for mn-user-info
      --json               as JSON

Here, Client ID for a particular user is required which can be fetched from the wallet located in the .zcn directory. As mentioned above --client_id flag is optional and if you do not specify a particular wallet client_id. It will find the stake pool related to wallet config in default wallet.json file.

Command:

./zwallet mn-user-info 

Response:

- node: 110b07984a6592ae67f1830366f47c835f6f5f262be19ee4aedd1b9acf870aee (miner)
  - pool_id:        77f7006f3ef89b5bc88016fbf9bc636cdb9c38425fa0e88940e4f99ddcf5be57
    balance:        0.2
    interests paid: 0.000000444
    rewards paid:   59.5728
    status:         active
    stake %:        100 %

On a successful response, you will see the staked miner/sharder nodes and the amount of tokens locked with that particular wallet. The response output can also be formatted in JSON data using the --json flag.

Getting the stake pool info

./zwallet mn-pool-info command can be used to get stake pool info for a particular miner/sharder. Parameters can be viewed using the ./zwallet mn-pool-info --help

Flags:
  -h, --help             help for mn-pool-info
      --id string        miner/sharder ID to get info for
      --pool_id string   pool ID to get info for

--id flag requires miner/sharder ID which can be fetched using ls-miners or ls-sharders command,pool_id is generated when you lock stake tokens for a miner/sharder node, you can copy the pool_id from the response text or can view it using mn-user-info command.

Command:

./zwallet mn-pool-info --id 110b07984a6592ae67f1830366f47c835f6f5f262be19ee4aedd1b9acf870aee --pool_id 77f7006f3ef89b5bc88016fbf9bc636cdb9c38425fa0e88940e4f99ddcf5be57

Formatted Response:

{
   "stats":{
      "delegate_id":"822700aa95b6719281999c66d49764e6a258ff3bf259b83a62353615fd904829",
      "high":0,
      "low":-1,
      "interest_paid":0,
      "reward_paid":0,
      "number_rounds":0,
      "status":"PENDING"
   },
   "pool":{
      "pool":{
         "id":"b488738546d84aed9d3dcb2bbe24c161bc4338638669e64e814631efd430fd85",
         "balance":10000000000
      },
      "lock":{
         "delete_view_change_set":false,
         "delete_after_view_change":0,
         "owner":"822700aa95b6719281999c66d49764e6a258ff3bf259b83a62353615fd904829"
      }
    }
  }

Unlocking a stake on node

Staking tokens can be unlocked using the ./zwallet mn-unlock command. Parameters for locking the tokens can be viewed using the ./zwallet mn-unlock --help

Usage:
  zwallet mn-unlock [flags]

Flags:
  -h, --help             help for mn-unlock
      --id string        miner/sharder ID to unlock pool of
      --pool_id string   pool ID to unlock

Here, miner /sharder id with the pool ID to unlock the stake are required. Miner/sharder id can be fetched using ls-miners or ls-sharders command whereaspool_id is generated when you lock stake tokens for a miner/sharder node ,you can view it using mn-user-info command.

Command for unlocking would be:

./zwallet mn-unlock --id 110b07984a6592ae67f1830366f47c835f6f5f262be19ee4aedd1b9acf870aee --pool_id 77f7006f3ef89b5bc88016fbf9bc636cdb9c38425fa0e88940e4f99ddcf5be57

Output:

tokens will be unlocked next VC

Note: Tokens are released on the next view change cycle or at the next reward round.

Updating staking config of a node

./zwallet mn-update-settings command is used to update the staking config of a node. Parameters for the command can be viewed using --help flag.

Flags:
  -h, --help                help for mn-update-settings
      --id string           miner/sharder ID to update
      --max_stake float     max stake allowed
      --min_stake float     min stake allowed
      --num_delegates int   max number of delegate pools

Miner/Sharder ID of the node is a required flag and can be fetched using ls-minersor ls-sharders command. Variables that can be updated are max stake, min stake and number of delegate pools.

Before updating the configuration lets get the default staking configuration for miner/sharder node using :

./zwallet mn-info --id 110b07984a6592ae67f1830366f47c835f6f5f262be19ee4aedd1b9acf870aee

Response:

{
   "simple_miner":{
      "id":"110b07984a6592ae67f1830366f47c835f6f5f262be19ee4aedd1b9acf870aee",
      "n2n_host":"five.devnet-0chain.net",
      "host":"five.devnet-0chain.net",
      "port":31202,
      "path":"miner02",
      "public_key":"7f7a0515ae68eadee6eac5915519802911c7c7341d1ef23d913728aed47dc8090548a56031732d16916e203c4e41c2a32d022fe56758ba3956cc73b112f0961c",
      "short_name":"localhost.m02",
      "build_tag":"40058cb8b6aeeb95e61229702f29de4c7118ebaf",
      "total_stake":0,
      "delegate_wallet":"110b07984a6592ae67f1830366f47c835f6f5f262be19ee4aedd1b9acf870aee",
      "service_charge":0.1,
      "number_of_delegates":10,
      "min_stake":0,
      "max_stake":1000000000000,
      "stat":{
         "generator_rewards":187795440000000
      },
      "node_type":"miner",
      "last_health_check":1620947267
   }
}

In the above configuration min stake, max stake, number of delegate pools are 0,1000000000000 and 10 respectively. Lets update the miner/sharder node for 25 delegate pools, min and max stake for 1000,100000 using mn-update-settings.

./zwallet mn-update-settings --id 110b07984a6592ae67f1830366f47c835f6f5f262be19ee4aedd1b9acf870aee --max_stake 100000  --min_stake 1000 --num_delegates 5

Note: Staking config can only be updated by the node's delegate wallet.

Last updated