Skip to content

How To Become A Validator

liaoyd edited this page Apr 15, 2019 · 19 revisions

Pchain is a blockchain system based on the PDBFT consensus mechanism, which requires regular replacement of Validators to ensure system security.

EPOCH is the update cycle of the Validator, which is about 30 days on mainnet, 48 hours on testnet.

To become a Pchain's validator, you can participate by voting. The voting is divided into two phases: Vote and Reveal Vote.

EPOCH Phase Operation
75%~85% Vote
85%~95% Reveal Vote
95%~100% Rotation in order and determine the Validators for next Epoch
For more information, please check tdm_getEpoch to get the duration for vote.
Platform Default Datadir Directory
Linux ~/.pchain
Mac ~/Library/Pchain
Windows %APPDATA%\Pchain

Prepare information

In order to become a validator, you must have bls's pubkey and private key, you can use same bls keys both on main chain and child chain. Those information are included in file priv_validator.json, please copy it to <datadir>/<chain_id>/(eg. if you want to become child_0's validator, the file should copied to ~/pchain/.pchain/child_0/)

If you don't have an account, please follow the step:

./bin/pchain --datadir .pchain account new

If you don't have bls keys, please follow the step:

./bin/pchain --datadir .pchain gen_priv_validator youraddress

The file is look like this:

{
        "address": "4CACBCBF218679DCC9574A90A2061BCA4A8D8B6C",
        "consensus_priv_key": [
                4,
                "D8AF52E355CD070ED3401800CBC920B6E94F3C49B42808C3049BF7BDB1FA3B19"
        ],
        "consensus_pub_key": [
                4,
                "085586D41F70435700850E19B7DE54B3E793C5EC4C6EC502D19030EF4F2122823E5A765E56CBA7B4C57E50561F77B022313C39895CA303F3C95D7B7282412F334778B95ACE046A79AEA4DB148334527250C8895AC5DB80459BF5D367236B59AF2DB5C0254E30A6D8CD1FA10AB8A5D872F5EBD312D3160D3E4DD496973BDC75E0"
        ]
}

We will take this file for example to show you how to become a validator.

Prepare vote hash and vote

Attach to pchain's console, and follow the command below:

var from = "4CACBCBF218679DCC9574A90A2061BCA4A8D8B6C"; //this is your own account
var pubkey = "085586D41F70435700850E19B7DE54B3E793C5EC4C6EC502D19030EF4F2122823E5A765E56CBA7B4C57E50561F77B022313C39895CA303F3C95D7B7282412F334778B95ACE046A79AEA4DB148334527250C8895AC5DB80459BF5D367236B59AF2DB5C0254E30A6D8CD1FA10AB8A5D872F5EBD312D3160D3E4DD496973BDC75E0"; //this is the bls pubkey included in priv_validator.json
var amount = "0x152d02c7e14af7000000"; //this is the amount you wanna deposit
var salt = "ilovepchain"; //this string can be whatever you like
web3.getVoteHash(from,pubkey,amount,salt);
//"0x4dcb9f6e059051c58cc06ee0c038af4bffc18e85983540a72012bce56d2c37ec"

Now copy this return hash and remember all the parameters you set. When pchain enter the vote duration, you can sent your vote by RPC tdm_voteNextEpoch. Suppose you want to vote chain child_0, the rpc should look like this:

curl -X POST -H "Content-Type:application/json" --data '{"jsonrpc":"2.0","method":"tdm_voteNextEpoch","params":["0x4CACBCBF218679DCC9574A90A2061BCA4A8D8B6C", "0x4dcb9f6e059051c58cc06ee0c038af4bffc18e85983540a72012bce56d2c37ec"],"id":1}' localhost:6969/child_0

Remember the return hash and wait for pchain enter reveal vote duration.

reveal vote

Send chain_signAddress RPC to generate bls signature.

curl -X POST -H "Content-Type:application/json" --data '{"jsonrpc":"2.0","method":"chain_signAddress","params":["0x4CACBCBF218679DCC9574A90A2061BCA4A8D8B6C", "0xD8AF52E355CD070ED3401800CBC920B6E94F3C49B42808C3049BF7BDB1FA3B19"],"id":1}' localhost:6969/pchain
//"0x1214608bcdf2e464b2d37d19b1b671482253e275d33079264045253fbb18689385ac0d5b4128d0c593211588deafd9ea2507b4858bdd42aaef3999045c0407ae"

Remember the return hash. When pchain enter the vote duration, you can sent your vote by RPC tdm_revealvote.Suppose you want to vote chain child_0, the rpc should look like this:

curl -X POST -H "Content-Type:application/json" --data '{"jsonrpc":"2.0","method":"tdm_revealVote","params":["0x4CACBCBF218679DCC9574A90A2061BCA4A8D8B6C", "085586D41F70435700850E19B7DE54B3E793C5EC4C6EC502D19030EF4F2122823E5A765E56CBA7B4C57E50561F77B022313C39895CA303F3C95D7B7282412F334778B95ACE046A79AEA4DB148334527250C8895AC5DB80459BF5D367236B59AF2DB5C0254E30A6D8CD1FA10AB8A5D872F5EBD312D3160D3E4DD496973BDC75E0", "0x152d02c7e14af7000000", "ilovepchain", "0x1214608bcdf2e464b2d37d19b1b671482253e275d33079264045253fbb18689385ac0d5b4128d0c593211588deafd9ea2507b4858bdd42aaef3999045c0407ae"],"id":1}' localhost:6969/child_0

You can check transaction status By getTransactionReceipt

Get the next Epoch Validators(reveal_end_block <= currentBlockNumber <= end_block)

You can get the validators of the next epoch.

Get By RPC tdm_getnextepochvalidators

Get By IPC tdm.getNextEpochValidators

IPC Console
>tdm.getNextEpochValidators()
You can’t perform that action at this time.