Setting Up a Validator Node on PCHAIN

Grayblock
Grayblock
Jun 30, 2019 · 8 min read
Image for post
Image for post

There is ample documentation for PCHAIN here and here but in its completeness, it can be a little confusing. This is an effort to simplify it down to just what you need to know to get you through the process. This will be a living guide with details for each operating system coming, so if you have issues or questions, please let us know.

In general, we recommend a Ubuntu 16.04 foundation.

Linux — Ubuntu

Installing PCHAIN

sudo apt-get update && sudo apt-get upgrade

Now we will download pchain source (we assume here that v1.0.23 is the latest. If not, update the version number in the commands below.) and install it:

wget https://github.com/pchain-org/pchain/releases/download/v1.0.23/pchain_mainnet_v1.0.23.tar.gz -P ~
tar -zxf pchain_mainnet_v1.0.23.tar.gz
cd ~
mkdir -p pchain/log pchain/bin pchain/.pchain pchain/scripts
cp ~/pchain_mainnet_v1.0.23/pchain ~/pchain/bin/
cp ~/pchain_mainnet_v1.0.23/run.sh ~/pchain/

Now let’s set up an auto-update service so you don’t have to manually update when a new version is released. To do this:

sudo apt-get install jq
cd ~
cp ~/pchain_mainnet_v1.0.23/pchain.cron ~/pchain/scripts/
cp ~/pchain_mainnet_v1.0.23/scripts/* ~/pchain/scripts/
sudo crontab -u YourUserName ~/pchain/scripts/pchain.cron

where YourUserName is changed to the username that you are signed into.

If you are unsure, type:

whoami

to see your username.

Once this is done, lets check to make sure the cronjob is setup properly with:

crontab -l

if this returns:

*/10 * * * * ~/pchain/scripts/updatefile.sh > ~/pchain/scripts/update.log
*/2 * * * * ~/pchain/scripts/monitor.sh > ~/pchain/scripts/monitor.log

you are good to go!

Running PCHAIN

~/pchain/

This script has all the flags to start pchain with all the options you will need. To investigate these further you can check the help pages with:

~/pchain/bin/pchain --help

or at https://github.com/pchain-org/pchain/wiki/Command-Line-Options

For most users, the script will be plenty. To start pchain with this script, run:

~/pchain/run.sh

To make sure this is working, lets open up the pchain console with:

~/pchain/bin/pchain attach ~/pchain/.pchain/pchain/pchain.ipc

This should give you some details on instance, block, datadir and an input line:

>

Here we can issue commands to the console and check current block height with:

>pi.blockNumber

If you are syncing properly, this number should be increasing every time you issue the command. You can also check the sync state with pi.syncing which returns a true/false.

Here, you can issue transactions, create new addresses, and even create smart contracts in this environment.

The whole list of commands can be found here, https://github.com/pchain-org/pweb3/wiki/JavaScript-API

To exit the command line, type exit

Creating account and applying as a candidate node

To create an account, open up the console again with:

~/pchain/bin/pchain attach ~/pchain/.pchain/pchain/pchain.ipc

Then lets create a new address with:

personal.newAccount()

This will prompt you for a password. The keystore is stored in /pchain/.pchain/pchain/keystore/. Goes without saying, back that up.

Once this is done, lets check it is in the system with:

eth.accounts

That should print out your newly generated address. Exit console with exit and enter.

Now that we have that, lets create your corresponding BLS key for creating signatures:

~/pchain/bin/pchain gen_priv_validator youraddress

where youraddress is the address you created above. This creates a priv_validator.json BLS keyfile in ~/pchain/.pchain/pchain/ that has to also be copied into the child chain directory ~/pchain/.pchain/child_0/

cp ~/pchain/.pchain/pchain/priv_validator.json ~/pchain/.pchain/child_0/

If we look inside these key files, they look like this:

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

Once these have been created, we need to reinitialize PCHAIN to load the keys:

~/pchain/run.sh

These BLS keys are used to sign validated blocks. The brilliance in these signatures is their size and ability to be combined to create a joint signature of the same size. This allows blocks to be provably signed by all validators without having to interact with one another or store a list of all signatures for all validators, making consensus faster and blocks lighter.

At this point, there are two different paths to take. You can apply to be a self supported validator, a validator “bidder”, using your own stake of 100k+ PI to qualify as validator or put yourself forward as a candidate node for others to delegate their PI to.

Applying as a Candidate Node

You can apply as a candidate anytime between 0% and 75% of the epoch. To check where we are in the current epoch, check the Monitor.

To register as a candidate, we send your address, security deposit and commission rate in a transaction.

The security deposit needs to be in hex encoding. I found the easiest way to figure this out is to have your security deposit amount in your wallet and query the network for your full balance. On the command line:

curl -X POST -H “Content-Type:application/json” — data ‘{“jsonrpc”:”2.0",”method”:”eth_getFullBalance”,”params”:[“address”, “latest”, true],”id”:1}’ localhost:6969/pchain

where you replace address with your address, keeping the quotes.

This will return your full balance details. The number we are looking for is after “balance”:

“balance”:”0x21e19e0c9bab2400000"

0x21e19e0c9bab2400000is 10,000 in hex. Whatever your value is, save this for the application transaction.

Now to send the application transaction, open the console with:

~/pchain/bin/pchain attach ~/pchain/.pchain/pchain/pchain.ipc

You then need to unlock your account (this is like opening your wallet):

personal.unlockAccount(“address”, ”password”, 300)

Where address is your address and password is the password you set for your keystore and 300 is the amount of time it will be unlocked for in seconds. This will return true if successful.

Now we construct your application transaction:

var from = “address”;

each one of these will return undefined once executed. Then:

var securitydeposit = “0x21e19e0c9bab2400000”;

replace the value in hex with your balance. Then:

var commission = #;

replace # with your intended commission rate, with no quotes, which is what percentage of the block reward you will be sharing with those that delegate to you (e.g. 10 for sharing 90% of the block reward, 20 for sharing 80%, etc.).

and,

var gas = null;

Once we have defined all the variables, lets send the transaction:

web3.del.applyCandidate(from,securitydeposit,commission,gas);

If successful, this will return a transaction hash! And we are almost there.

In order for your address to show up in the PIWallet, you have to submit your application also through pchain.org. Here you enter in your email, address, username/organization, your BLS public key (listed above after "consensus_pub_key":[4,in the priv_validator.json file), and a brief introduction.

Image for post
Image for post

Once submitted, this will return with a verification of submittal hash and you will see your address in the PIWallet within a few business days.

Your node is now ready to gather delegates and prepare to bid to be a validator for the next epoch

Submitting Validator Vote

Whether you are using your own PI in your validator address or delegated PI from your candidacy, you must have at least 100k PI in your “Full Balance” at the time of vote participation.

Once the epoch has reached 75%, the voting time for the next epoch is opened. We can place our votes anytime from 75–85%.

Using the BLS key example from above, we will prepare the vote transaction.

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

First we will get the full balance again like above to use as our commitment value in our vote. This will include any stake you own and any stake delegated to you. The higher this is, the higher chance you will have of being chosen as validator.

curl -X POST -H “Content-Type:application/json” — data ‘{“jsonrpc”:”2.0",”method”:”eth_getFullBalance”,”params”:[“address”, “latest”, true],”id”:1}’ localhost:6969/pchain

where you replace address with your address, keeping the quotes.

Now lets build the vote transaction. Start the PCHAIN console again with:

~/pchain/bin/pchain attach ~/pchain/.pchain/pchain/pchain.ipc

Now lets set our variables:

var from = “4CACBCBF218679DCC9574A90A2061BCA4A8D8B6C”;

Replace 4CACBCBF218679DCC9574A90A2061BCA4A8D8B6C with the address shown in your BLS json.

var pubkey = “085586D41F70435700850E19B7DE54B3E793C5EC4C6EC502D19030EF4F2122823E5A765E56CBA7B4C57E50561F77B022313C39895CA303F3C95D7B7282412F334778B95ACE046A79AEA4DB148334527250C8895AC5DB80459BF5D367236B59AF2DB5C0254E30A6D8CD1FA10AB8A5D872F5EBD312D3160D3E4DD496973BDC75E0”;

Change this value with the pubkey in your json file.

var amount = “0x152d02c7e14af7000000”;

Change this to the balance shown in your full balance. And:

var salt = “vote4grayblock”;

The salt can be anything you want, but you must remember it. It is used as a blinding factor when hashing all the values together so no one can work out who’s hash is who’s. It’s kind of like the private key to the vote hash.

Lastly, lets generate the vote hash with all the variables:

web3.getVoteHash(from,pubkey,amount,salt);

This will return the vote hash if successful. Now save this hash and all parameters you set above for the vote reveal transaction.

Revealing Validator Vote

First we need to sign your address with your BLS private key to prove you are the owner of the BLS pubkey. To do this, start the PCHAIN console:

~/pchain/bin/pchain attach ~/pchain/.pchain/pchain/pchain.ipc

Unlock your wallet:

personal.unlockAccount(“address”, ”password”, 300)

Then set your variables:

var from = “address”;
var privateKey = “BLSprivatekey”;

Both the address and private key must be preceeded by an 0x. Then sign your address with the BLS private key:

web3.chain.signAddress(from,privateKey);

This will return a BLS signature. Save this for the next step. Now lets set the variables for the reveal transaction. All these values must be IDENTICAL from the vote transaction. If it doesn’t match, you will not be a valid candidate.

var from = “address”;
var pubkey = "blspubkey";
var amount = "amount";
var salt = "salt";
var sig = "BLSsignature";
var gas = null;

change all those variables above to those used in the vote transaction above with the BLS signature generated. Now lets generate the reveal transaction with:

web3.tdm.revealVote(from,pubkey,amount,salt,sig,gas);

If successful, this will generate the reveal transaction hash which can be seen on PIScan. You have now successfully voted and revealed your vote for validator candidacy.

Once the epoch has reached 95%+, the validator set has been determined and can be checked with web3.tdm.getNextEpochValidators() in the console.

If you have found this tutorial useful, please consider delegating some of your stake to the Grayblock Validator Candidate:

0x00000017f6f17ce18faa53d7010fa66acd0e1fb9

We use the proceeds to fund guides like these, technical articles and tools to enable adoption and make the technology easier to understand.

Image for post
Image for post

Coinmonks

Coinmonks is a non-profit Crypto educational publication.

Sign up for Coinmonks

By Coinmonks

A newsletter that brings you week's best crypto and blockchain stories and trending news directly in your inbox, by CoinCodeCap.com Take a look

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Grayblock

Written by

Grayblock

Blockchain and IoT Systems Integrators

Coinmonks

Coinmonks

Coinmonks is a non-profit Crypto educational publication. Follow us on Twitter @coinmonks Our other project — https://coincodecap.com

Grayblock

Written by

Grayblock

Blockchain and IoT Systems Integrators

Coinmonks

Coinmonks

Coinmonks is a non-profit Crypto educational publication. Follow us on Twitter @coinmonks Our other project — https://coincodecap.com

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store