Welcome to PCHAIN Documentation!

_images/logo.png

Introduction

What is Pchain

PCHAIN, the Super-Ethereum, is the largest scale native EVM multichain system in the world, which can support 256 child chains across continents with 180K TPS and confirm transaction in seconds. PCHAIN is the first public chain investment in Asia Pacific by Google incubator Plug & Play. It’s designed to make large scale blockchain applications possible. At present, PCHAIN has achieved strategic cooperation with many Fortune 500 companies.
PCHAIN was founded by renowned senior experts including the first inventor of international blockchain patent in China, a National “Thousand People Plan”professor, a Singapore Presidential Awards winner, a former IBM Greater China Blockchain Technical Leader. In total, the team has published 100 IEEE ACM papers and international patents. PCHAIN was granted 6 patents and the book named Ethereum Technology Details and Practices, which was openly recommended by Vitalik Buterin, the founder of Ethereum.
PCHAIN has received strategic investment from more than 40 top-level global funds such as FBG, Plug&Play, Node Capital, LD Capital, JRR, Block VC and LinkVC,etc. PCHAIN was ranked Top 2 on the World Blockchain Top List by multiple overseas blockchain rating institutions. PCHAIN also received the Silicon Valley’s“Most Promising Blockchain Foundation Platform 2018”award and was hailed as the“Best Blockchain Platform in 2018”by Bitcoinist. PCHAIN has board collaboration with over 30 blockchain partners such as North America Blockchain Association, IEEE, CFLP, etc.
The key innovative technologies include:
1. The 1st native EVM multichain enables the interoperability of child chain and main chain. It can support 256 child chains and more without pressure on main chain in testnet 1.0 with 1064 nodes globally. The peak TPS is 126K TPS and it can be scale linearly as the number of child chains increases.
2. The patented PDBFT algorithm greatly reduced communication cost from N^2 to N comparing with traditional BFT algorithm. It can effectively reduce the centralization problem as the number of nodes is limited.
3. A new Oracle mechanism based on the knowledge graph makes it easier to encapsulate smart contracts. W3C compliant smart data effectively addresses the issue of non-intelligence in smart contracts
4. Safe Delegation and Blind Bidding effectively avoid token transaction between delegators and candidates and avoid the risk of evil by candidates. Also, Blind Bidding mechanism enables the validator election more fair and secure in epoch switch.
5. Cross chain capability. The smart contracts of PCHAIN can be easily invoked with other nonnative tokens (BCH, ERC20) by using the provided toolkit.

PDBFT Consensus Algorithm

The early public chain systems primarily adopted consensus mechanisms based on proof of work (PoW). Under this mechanism, hardware performance directly determines the computing power, that is, the ability to successfully generate blocks. A consensus algorithm based on PoW requires a significant amount of computing power, resulting in a lower TPS (transactions per second) throughput, such as the 3 to 7 TPS provided by Bitcoin. The PoW algorithm is also vulnerable to 51% attacks, so users are forced to wait for several block confirmations before a transaction is processed.
In order to overcome these problems, PCHAIN adopted a new consensus mechanism - PDBFT which is based on proof of equity (PoE). In PDBFT, each validator needs to hold a certain number of tokens in advance to obtain voting rights, and consensus is reached by voting to generate new blocks. Compared with the more secure network environment of consortium blockchain, the validator in the public chain is more vulnerable to attack and may act maliciously. This is named a Byzantine node, displaying uncertain or unpredictable behavior. For example, it may propose illegitimate blocks, deliberately cast opposing votes, or send different votes to various nodes. Byzantine nodes may even work together in bad faith.
These behaviors affect the consensus of the blockchain network and present a major problem for the public chain. Currently, modified PBFT-based algorithms are widely used in the industry, such as Hyperledger Fabric 0.6, IstanbulBFT, and Tendermint. Although the PBFT protocol can solve issues of Byzantine fault tolerance, the following problems restrict its application in large-scale public chains:
  • PBFT assumes that the validator set remains unchanged, but in the public chain, the validator should be able to join and exit more freely.
  • PBFT will not actively change the leader and will only do that in the event of a timeout. On one hand, the leader is more vulnerable to attacks. On the other, the leader may selectively package some transactions so that the others cannot be executed.
  • In PBFT, votes of all validators need to be transmitted to all nodes through broadcasting, so the overall communication overhead is O(n2), which greatly limits its application in larger networks.
After long-term research and development, the PCHAIN team proposed a new consensus protocol called PDBFT which can successfully solve the above problems, making it suitable for large-scale public chains. Main features of this consensus mechanism include:
  • Regular replacement of validator set. This allows the validator to join and exit the mechanism more freely. Each validator can choose whether to participate in the validator set campaign for the next Epoch. All validators of the next Epoch are then determined through consensus. The new validator set takes effect after the current Epoch ends.
  • Active change of the leader. This makes it more difficult to attack the leader. After each round of PDBFT consensus, the leader will be changed regardless if consensus is reached or need to move to another consensus round. The leader of the new consensus round is randomly generated based on the consensus information of the previous block and can be verified by other validators. Since the generation of the new leader depends only on the consensus of the previous block and the state of current consensus, no node knows the next leader in advance. Thus, the probability of a successful attack is greatly reduced.
  • A reduction in the communication cost of broadcasting the votes from O(n2) to O(n). In contrast to voting by broadcasting to the whole network, each validator will send votes to the current leader. After receiving majority (2/3+) votes, the leader will aggregate them through the aggregate signature algorithm. The size of the aggregated signature is the same as that of a single signature, and each validator can verify whether majority nodes have voted correctly by verifying the aggregate signature. The leader will finally broadcast the aggregate to all validators, thus the communication overhead of the protocol is reduced to O(n). This greatly improves the extendibility of the protocol and makes large-scale applications possible.

Multi Chain

Multi-chain is the organization structure of co-existing chains in pchain, it contains one main chain and necessary number of parallel child chains.

responsibilities of different types of chain

Pchain has two types of chains, one is main chain, there is only one main chain in pchain; another is child-chain, there could be many, and they are identical and independent.
Main chain is responsible for balance record/transfer, and storage of child-chains’ data. Child is responsible for running smart contract. For both main chain and child chains, PAI(pchain’s token) is paid for their transaction execution. PAI in mains and child chains have the same value, and can be transferred between main chain and child chains.

design of multi-chain

  • every chain has its own stack(consensus, transaction, block, EVM)

    In pchain, main chain and child chains run their stacks individually, these stacks share same logic for most modules, such as consensus algorithm(PDBFT), receive and process of transaction, storage of block, execution of EVM, etc.

    The difference between main chain’s stack and child chain’s stack is: the stack of main chain limits deployment of smart contract; the stack of child chains does not issue their own token, main chain and child chains share one PAI.

  • rpc

    Pchain writes specific RPC logic for multi-chain, every child handles its own RPC requirements individually. When calling, it just needs adding chain id in url’s path to differentiate the chain. For example, when access child chain ‘childchain-0’, the url to POST is http://pchain-node/childchain-0.

  • p2p

    By taking advantage of design of ethereum’s P2P module, when initials and starts one chain, simply adding the mapping of chain and one sub protocol(just supplies a name) into ProtocolManager will make p2p messages are correctly routed within related chains.

  • chain manager and cross-chain helper

    There are 2 entities outside the stacks coordinating the chains. One is ChainManager, which holds all chain’s information such as epochs and their validators, and also manages the initialing/start process of all chain.

    Another is CrossChainHelper, which is injected into every chain’s stack. When main/child chain needs to retrieve cross-chain information or call cross-chain functions, CrossChainHelper will come in handy.

what multi-chain can supply

  • Easily create company’s own chain

    Any company has enough PAI and enough valitadors can create one child-chain in pchain. And this child chain would act as a normal public chain or consortium chain, the company will get all features blockchain technology supplies.

  • multi-chain can co-operate together to achieve large scale business logic

    Because every single chain has its own process power, when business modules can be split apart and independent to each other, then every module can be deployed in one chain. By this way, even very large business can run on pchain with collaborating its modules on different chains.

Staking

Welcome to PCHAIN staking.

PCHAIN is the 1st native EVM multichain enables the interoperability of child chain and main chain. Making large scale blockchain application possible.. We welcome more PCHAIN community members to run on PCHAIN and jointly make the mainnet stable with PCHAIN innovative PDBFT consensus algorithm, which can greatly reduce communication cost from N^2 to N comparing with traditional BFT algorithm and effectively reduce the centralization problem as the number of nodes is limited. Meanwhile, PCHAIN adopts Dynamic Bidding including voting and revealing vote and it enables the validator election more fair and secure in epoch switch. For the non-technicals, you can delegate PI via Safe Delegation, effectively avoiding the risk of evil by candidates. PCHAIN wallet has been released. It will help you participate in Validator competition more easier and quickly. Meanwhile, PCHAIN staking mechanism is the same on main chain and child chain.

Let’s check the details below.

Who can get POS mining reward

Before you staking on PCHAIN, please confirm which way you would like to take to participate in PoS Mining.

  • Candidate node without delegations

PCHAIN holders with a minimum of 100K+ PI and the required configuration set-up are directly eligible to vote for validator. Dynamic staking ranking at each voting round will then determine if selected to be a next Epoch Validator.

  • Candidate node with delegations

If PCHAIN holders want to get the supports from delegation, they should be with a minimum of 10k PI and the required configuration set-up, and should apply for candidate first. Then they can compete against those nodes without delegations for the validator via voting. Dynamic staking ranking at each voting round will then determine if selected to be a next Epoch Validator.

  • Delegator

PCHAIN holders with a minimum of 1K PI can delegate PI to candidate(s). Once his candidate succeed in voting for validator, he will get his PoS Mining reward based on his delegation percentage.

We will introduce how to do those step by step.

Preparation

Please make sure there is enough native PI in your account.

Delegation

First, we will introduce how to delegate to other candidates, since this is the easiest way to get staking reward and don’t request any technical background. All you need to do is

Once your candidate node succeed in voting for validator node, then you will get PoS Mining reward during next Epoch.

Staking

Before we introduce how to stake on PCHAIN as a Validator Node, you must know that being a validator node is a very interesting but complex thing. If you do not have any technical background or are new to blockchain, we recommend you to delegate to other candidate(s). Since once you become validator node, you have to spend some time to monitor your node and even send your node’s log to our team sometimes. But if you are determined to become pchain’s validator, we will help you as much as we can.

You must have done things below before bidding on any chains:

Stake on main chain:

Stake on child chain or both chains:

Now you have 2 options to stake:

  • Become validator Node as Candidate node without delegations
  • Become validator Node as Candidate node with delegations

The advantage to apply candidate node with delegations is you can earn the commission fee from delegators and the delegators’ staking will make you more competitive, but once you got delegations, you have the responsibility to keep your node healthy cause the delegators will take attention to their reward.

So we will first introduce how to apply candidate nodes with delegations, you can skip this section if you don’t wanna apply one.

How to apply candidate node with delegations

After you installed and synced pchain mainnet, you should also have at least 10k PI on your account. We provide 2 ways to apply candidate node with delegations:

Notice:
You can do this on both chain, but the RPC URL on main chain and child chain is different:
How to become validator

After you installed and synced pchain mainnet, you should also have at least 100k PI on your account. We provide 2 ways to bid for validator node:

Notice:
You can do this on both chain, the RPC URL on main chain and child chain is different:

Cancel delegation

Once you delegate successfully, you can cancel it before the Epoch reaches 75%. We provide 2 ways:

  1. If your candidate is validator in current Epoch, the cancelation will be effective immediately. Your PI will be automatically unlocked to your balance when the current Epoch reaches 100%.
  2. If your candidate is not validator in current Epoch, then the cancelation will take effect immediately and your PI will be automatically unlocked to your balance.

Cancel candidate submission

Once you apply candidate node with delegation successfully, you can cancel it before the Epoch reaches 75%. We provide 2 ways to cancel candidate:

Notice:
You can do this on both chain, the RPC URL on main chain and child chain is different:
  1. Canceling your submission after selected to be Validator: your staked PI will be unlocked and all the delegated tokens you received will be automatically returned to each delegator once the Epoch reaches 100% height.
  2. Canceling your submission after you failed being elected Validator: the cancelation will be effective immediately since there are no Validator duties to be completed, your staked PI will be unlocked, and all the delegated tokens you received automatically returned to each delegator balance.

Check your balance

There are 7 balance on PCHAIN. You can check it on PIWallet FullBalance page or PIScan .

Description of the various balance below:

  1. balance: total unlocked amount in current Epoch.
  2. delegateBalance: total amount you delegate to other address(es).
  3. depositBalance: the staked amount by yourself for Validator bidding.
  4. depositProxiedBalance: the delegated amount that you staked for Validator bidding.
  5. pendingRefundBalance: total pending refund amount which will be return to delegators at the end of Current Epoch.
  6. proxiedBalance: total delegated amount from other address(es).
  7. rewardBalance: total pending reward amount, it will be unlocked 1/12 at the end of each Epoch.

For more detail, please check What is FullBalance.

Native PI to PIBNB Token Swap

Reminders before you start swap PI to PIBNB on PIwallet.

  1. Update PCHAIN Wallet to the latest version. Click here to download PIWallet.
  2. Ensure that you keep the private key or keystore file or the mnemonic word of the BNB address well.
  3. The minimun PI swap amount is 1000PI/time and the commission fee of swap is 25PI/time, you should also have minimun of 0.0005PI left for transaction gas.
  4. After you send the swap transaction, you will receive your PIBNB within 2 business days at most, but the process will finished in several mins usually.

Step 1: Open the PIwallet and click ‘PI to PIBNB’ tab.

_images/0.jpg

Step 2: Create or import your BNB address to PIWallet.(After create or import make sure your address start with “bnb”, if not, update your PIWallet to the latest version)

You can import your BNB address by private key or wallet seed(mnemonic words) or you can just create a new address. We will take ‘create PIBNB’ as an example.

_images/1.jpg

Click ‘Create PIBNB ’, copy the wallet seed(mnemonic words). Set password and repeat it. Then click ‘Create’ to confirm.

Noticed: Please keep the mnemonic words and password well by yourself.
_images/2.jpg

After create or import your PIBNB address and PIBNB balance will show in ‘My PIBNB Account’.

Step 3: Swap native PI to PIBNB

Choose your native PI address, ensure the amount is larger than 1000PI. Choose your PIBNB address, fill the amount you wanna swap, and click ‘token swap’.

Notice: the amount you fill in should larger than 1000 and can’t have more than eight decimal places.
_images/3.jpg

Step 5: Check your balance.

After transaction finished, wait several mins and click the refresh icon to check your PIBNB balance.

_images/4.jpg _images/5.jpg

PIBNB to Native PI Token Swap

Reminders before you start swap on PIwallet.

  1. Update PCHAIN Wallet to the latest version. Click here to download PIwallet.
  2. Ensure that you keep the private key or wallet seed of the PIBNB address well.
  3. Ensure there is a minimum amount of BNB (~ 0.000375 BNB ) in your PIBNB address to cover the BNB fee.
  4. After you send the swap transaction, you will receive your native PI within 2 business days at most, but the process will be finished in around 2 mins usually.

Step1: Go to‘PI to PIBNB’page and click the ‘PIBNB to PI ’.

_images/1.png

Step2: Import PIBNB address via importing wallet seed/ private key. You will see the PIBNB balance there. Also, you can create new PIBNB address here and transfer PIBNB to this new one.

_images/2.png

Step3: Elect and confirm your native PI address. The default native PI address below is the latest one you created under ‘Wallet’ page. If you want to create new one, please go to ‘Wallet’ page again.

Step4: Enter the amount that you want to swap. Then Click ‘Token Swap’ . Enter the password of the PIBNB address and click ‘Confirm’ to continue. Please ensure there is enough BNB in your PIBNB address to cover BNB fee.

Confirm the swap info. Then click ‘Send Transaction’. It will go to Binance explorer website automatically, and please be patient to wait for the transaction to succeed.

_images/3.png _images/4.png

Step5: Click ‘Detail’ to check more swap transaction info.

_images/5.png

Reward Scheme

PCHAIN POS mining and incentive mechanisms

  • POS mining:

    315 million PCHAIN tokens are reserved for PoS mining, distributed over 24 years:

    80% will be allocated to PCHAIN main chain. The remaining 20% will be distributed on PCHAIN official child chains. The first 6 months will be dedicated to the official child chain 1 while the further distribution on the official child chains will be ultimately determined and announced by the PCHAIN Foundation.

  • Validators incentive mechanisms:

    • The PoS mining reward of each block belongs to its proposal (the Validator who generates the block), your chance to be a proposal equals the weight of your staked tokens. Important: you need to be online for a maximum of blocks otherwise your chances will decline.
    • The PoS mining reward of each block is locked until the Epoch reaches 100% height. (An Epoch is ~30 days on mainnet, based on block generations between two election rounds)
    • After each Epoch reaches 100% height, the PCHAIN reward system calculates the actual PoS mining reward of the Validators. Distribution is made in 12 Epochs.

When you are a Validator candidate and become Validator successfully, your PoS mining reward is automatically shared with all your delegators based on the percentage of delegation.

Pchain Client

Pchain client is the command line interface for running a full pchain node implemented in Go. By installing and running pchain, you can take part in the pchain frontier live network and:

  • mine PI
  • transfer funds between addresses
  • transfer funds cross chain
  • create contracts and send transactions
  • create child chain
  • and much much more

System Requirement

Here is details of the recommended system requirements of Validator as below.

According to the current cost of AWS, the total cost is estimated to be around $77 for the first month. And it will be increased probably during the following months based on the actual use. 1 . EC2 Rental Fee (US West 2 price depends on demand)

  vCPU Memory Monthly fee
t3.large 2 8GiB $62.4
  1. EBS Rental Fee (US West 2 price depends on actual use)
  1GB-month Estimated monthly usage Monthly fee Recommended capacity
SSD GP2 $0.1 Growing by 100GB per month Growing by $10 per month 2TB
  1. Network Bandwidth Fee (US West 2 price depends on actual use)
  GB | Estimated monthly usage Monthly fee Internet speed
AWS EC2 to internet $0.02, first GB free| 50GB $4.41 5Gbps
  1. Operating System

Recommend Ubuntu 18.04

Open Port 30308

Ensure that you have open 30308 port for both TCP and UDP on your server firewall so pchain’s other peers can connect to your node. Here is the example of AWS.

_images/30308.jpg

Sync and Run Mainnet

After you install pchain on your computer, you can run

pchain

to sync mainnet’s block and transactions, you should see some outputs look like this:

INFO [05-21|09:47:41.666] Starting PChain...
INFO [05-21|09:47:41.666] PChain supports large scale block-chain applications with multi-chain
INFO [05-21|09:47:41.667] Create peer-to-peer node                 instance=pchain/linux-amd64/go1.11.4
INFO [05-21|09:47:41.667] ethereum.MakeSystemNode
INFO [05-21|09:47:41.669] Allocated cache and file handles         database=/home/ubuntu/.pchain/pchain/geth/chaindata cache=768 handles=512
INFO [05-21|09:47:41.692] Writing default main-net genesis block
INFO [05-21|09:47:41.704] Persisted trie from memory database      nodes=182 size=48.66kB time=1.1982ms gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [05-21|09:47:41.705] Initialised chain configuration          config="{PChainId: pchain ChainID: 24160843454325667600331855523506733810605584168331177014437733538279768116753 Homestead: 0 DAO: <nil> DAOSupport: false EIP150: 0 EIP155: 0 EIP158: 0 Byzantium: 0 Constantinople: <nil> Engine: tendermint}"
INFO [05-21|09:47:41.720] Tendermint (backend) Protocol, add logic here
INFO [05-21|09:47:41.720] Initialising Ethereum protocol           versions=[64] network=1
INFO [05-21|09:47:41.720] Loaded most recent local header          number=0 hash=c6ade9…f2f8c3 td=1024
INFO [05-21|09:47:41.720] Loaded most recent local full block      number=0 hash=c6ade9…f2f8c3 td=1024
INFO [05-21|09:47:41.720] Loaded most recent local fast block      number=0 hash=c6ade9…f2f8c3 td=1024
INFO [05-21|09:47:41.721] Regenerated local transaction journal    transactions=0 accounts=0
INFO [05-21|09:47:41.721] Tendermint (backend) SetBroadcaster: 0xc0001e22d0
INFO [05-21|09:47:41.721] Tendermint (backend) Protocol, add logic here
INFO [05-21|09:47:41.732] Allocated cache and file handles         database=/home/ubuntu/.pchain/tx3cache              cache=16  handles=16
INFO [05-21|09:47:41.737] Starting P2P networking
INFO [05-21|09:47:43.846] UDP listener up                          self=enode://7b3f6226995c73acfb9f792b8aa73e8c2b1eb35656c9cd7d8c9287c34c0241c34c595d3bb6c7d0b0b7678bf5df0d1e8693bc735bd4a2311e50bd7f4a5d80fd7c@[::]:30308
INFO [05-21|09:47:43.846] Start Chain: pchain
INFO [05-21|09:47:43.846] StartChain()->utils.StartNode(stack)
INFO [05-21|09:47:43.849] RLPx listener up                         self=enode://7b3f6226995c73acfb9f792b8aa73e8c2b1eb35656c9cd7d8c9287c34c0241c34c595d3bb6c7d0b0b7678bf5df0d1e8693bc735bd4a2311e50bd7f4a5d80fd7c@[::]:30308
INFO [05-21|09:47:43.851] IPC endpoint opened                      url=/home/ubuntu/.pchain/pchain/pchain.ipc
INFO [05-21|09:47:43.851] Before Load Child Chains, childChainIds is [], len is 0
INFO [05-21|09:47:43.851] Number of Child Chain to be load - 0
INFO [05-21|09:47:43.851] Start to Load Child Chain - map[]
INFO [05-21|09:47:45.011] Block synchronisation started
...
It means the pchain running on your computer starts to sync.

If you wanna run it backend, you can run with this command

(./pchain --verbosity=0 &)

After start pchain, it will create a directory to store blockchain data under default datadir directory.

Platform Default Datadir Directory
Linux ~/.pchain
Mac ~/Library/Pchain
Windows %APPDATA%Pchain

You can also set datadir to wherever you like by flag –datadir.

The datadir’s structure will look like this:

datadir/
        -chaininfo.db/
        -config.toml
        -nodekey
        -nodes/
        -tx3cache/
        -pchain/
                -data/
                -geth/
                -pchain.ipc
                -priv_validator.json  //you may not have this file now
                -keystore/

Sync and Run Child Chain

Pchain have one child chain now and you can join to mining, the process is same with join the main chain’s validators. But at first you need to sync and run child chain.

Before you start to sync child chain, make sure you have install pchain and sync main chain.

First, you need to get child chain’s config file. There are three files in it :

ubuntu@ip-172-31-12-155:~/child_0_config$ ls
eth_genesis.json  genesis.json  run.sh

The two json file should copy to yourdatadir/.pchain/child_0/, you need to make the directory child_0 yourself.

mkdir -p yourdatadir/.pchain/child_0/
cp ~/child_0_config/*.json yourdatadir/.pchain/child_0/

Then you need to initialize child chain

pchain --datadir=yourdatadir init yourdatadir/child_0/eth_genesis.json child_0

You will see some output look like this:

INFO [05-23|10:12:51.743] init_eth_blockchain 0 with dbPath: .pchain/child_0/geth/chaindata
INFO [05-23|10:12:51.743] Allocated cache and file handles         database=.pchain/child_0/geth/chaindata cache=16 handles=16
INFO [05-23|10:12:51.748] init_eth_blockchain 1
INFO [05-23|10:12:51.748] init_eth_blockchain 2
INFO [05-23|10:12:51.748] Writing custom genesis block
INFO [05-23|10:12:51.749] Persisted trie from memory database      nodes=8 size=2.68kB time=54.136µs gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [05-23|10:12:51.749] init_eth_blockchain end
INFO [05-23|10:12:51.749] successfully wrote genesis block and/or chain rule set: 0bb3cd96500c814d39901c120ec2a78385781a58ce5bd6ed1a272b4ee5cb8435
INFO [05-23|10:12:51.749] Database closed                          database=.pchain/child_0/geth/chaindata
INFO [05-23|10:12:51.750] priv_validator_file not exist, probably you are running in non-mining mode

After this you should restart pchain and run pchain with flag –childChain=child_0 to sync child chain.

Now please check your datadir’s structure:

datadir/
        -chaininfo.db/
        -config.toml
        -nodekey
        -nodes/
        -tx3cache/
        -pchain/
                -data/
                -geth/
                -pchain.ipc
                -priv_validator.json //you may not have this file now
                -keystore/
        -child_0/
                -data/
                -geth/
                -pchain.ipc
                -priv_validator.json //you may not have this file now
                -keystore/

Create Your Account

After running pchain, sooner or later you will want to create your own account. If you wanna

  • transfer PI
  • delegate
  • create a child chain
  • deploy smart contrat
  • interact with smart contract

you will only need to generate an address.

pchain --datadir=yourdatadir account new

This command will generate a keystore file under your datadir, the file name usually start with “UTC”. We suggest you to keep this file on your local computer or import it to PIWallet.

If you wanna also

  • become a validator node to mining
  • apply candidate node with delegations

you will also need to generate bls keys for mining.

pchain --datadir=yourdatadir gen_priv_validator youraddress

This command will generate a priv_validator.json file under your datadir. This file should copy to the datadir/chainid/ if you wanna mining, and after that you should restart pchain.

Now please check your datadir’s structure:

datadir/
        -chaininfo.db/
        -config.toml
        -nodekey
        -nodes/
        -tx3cache/
        -pchain/
                -data/
                -geth/
                -pchain.ipc
                -priv_validator.json
                -keystore/

If you also run child chain and would like to mining on both main chain and child chain, your datadir’s structure should look like this:

datadir/
        -chaininfo.db/
        -config.toml
        -nodekey
        -nodes/
        -tx3cache/
        -pchain/
                -data/
                -geth/
                -pchain.ipc
                -priv_validator.json
                -keystore/
        -child_0/
                -data/
                -geth/
                -pchain.ipc
                -priv_validator.json
                -keystore/

How to Become Validator node

Before you vote to become validator, make sure you have done things below:

  • sync and run pchain
  • have an address and consensus keys
  • have at least 100k PI on your address

You can choose to apply candidate node with delegations first so you can let other users to delegate PI to you. This is an option, not necessity.

Pchain have 12 epochs per year, and in each epoch there are 4 phases.

Phase Block Number What you can do
0% ~ 75% start_block ~ vote_start_block - 1 apply candidates and delegate
75% ~ 85% vote_start_block ~ vote_end_block vote
85% ~ 95% reveal_start_block ~ reveal_end_block reveal vote
95% ~ 100% reveal_end_block + 1 ~ end_block check next epoch’s info

You can check the current stage by our Monitor, or by RPC tdm_getEpoch.

Now you can prepare the parameters which will be used during vote and reveal vote, you should have:

  • address
  • consensus public key //contains in priv_validator.json
  • consensus private key //contains in priv_validator.json
  • amount //should be at least 100k PI and equal or larger than total_depositProxiedBalance + total_proxiedBalance - total_pendingRefundBalance. The amount should keep the same when you vote and reveal vote.
  • salt

If you are not sure what amount should set, you can check your full balance by RPC eth_getFullBalance.

Note: you can also do the vote and reveal vote by PIWallet, it will make this process much easier.

Generate vote hash

Suppose you have a priv_validator.json look like this:

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

And you are voting for main chain’s validator, which means the chainid is “pchain” (And the child chain’s chainid is “child_0”). First, attach to pchain’s console

pchain attach yourdatadir/chainid/pchain.ipc

In this case, the command should be

pchain attach yourdatadir/pchain/pchain.ipc

and then type your parameters to generate the vote hash:

var address = "4CACBCBF218679DCC9574A90A2061BCA4A8D8B6C";
var pubkey = "085586D41F70435700850E19B7DE54B3E793C5EC4C6EC502D19030EF4F2122823E5A765E56CBA7B4C57E50561F77B022313C39895CA303F3C95D7B7282412F334778B95ACE046A79AEA4DB148334527250C8895AC5DB80459BF5D367236B59AF2DB5C0254E30A6D8CD1FA10AB8A5D872F5EBD312D3160D3E4DD496973BDC75E0";
var amount = "0x152d02c7e14af7000000";
var salt = "ilovepchain"; //this string can be whatever you like
web3.getVoteHash(address,pubkey,amount,salt);
//"0x4dcb9f6e059051c58cc06ee0c038af4bffc18e85983540a72012bce56d2c37ec"

Now you get the vote hash “0x4dcb9f6e059051c58cc06ee0c038af4bffc18e85983540a72012bce56d2c37ec”. Notice the amount is in hex, if you don’t know how to convert dec to hex, we suggest you do this by PIWallet, which will be much easier.

Note: 1gwei = 1000000000wei = 0x3B9ACA00

Vote

You can vote by RPC tdm_voteNextEpoch.

curl -X POST -H "Content-Type:application/json" --data '{"jsonrpc":"2.0","method":"tdm_voteNextEpoch","params":["address", "vote hash"],"id":1}' localhost:6969/chainid

In this case, the command should be:

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

Remember the return hash to check if this vote transaction succeed, and then wait for pchain enter reveal vote duration.

Note: you can vote many times during vote phase, the last one will prevail.

Reveal Vote

Before reveal vote, you need to generate a signature signed by your consensus private key. You can generate it by RPC chain_signAddress.

curl -X POST -H "Content-Type:application/json" --data '{"jsonrpc":"2.0","method":"chain_signAddress","params":["address", "consensus private key"],"id":1}' localhost:6969/pchain

In this case, the command should be:

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 to check if this transaction succeed.

Now you can receal vote by RPC tdm_revealvote.

curl -X POST -H "Content-Type:application/json" --data '{"jsonrpc":"2.0","method":"tdm_revealVote","params":["address", "consensus public key", "amount", "salt", "signature"],"id":1}' localhost:6969/chainid

In this case, the command should be:

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/pchain

Remember the return hash to check if this reveal vote transaction succeed, and then wait for pchain enter the last phase.

Check

Now you can check if you can become the next epoch’s validator by RPC tdm_getnextepochvalidators.

curl -X POST -H "Content-Type:application/json" --data '{"jsonrpc":"2.0","method":"tdm_getNextEpochValidators","params":[],"id":1}' localhost:6969/chainid

In this case, the command should be

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

How to quit validator

If you no longer want to be a validator, you can quit by yourself. You need also take part in 2 process of Vote voting and Reveal Vote revealing vote as the same above, just set the amount to 0. If you are also a candidate node with delegations, you need cancel candidate submission first.

How to Apply Candidate node with delegations

Before you apply candidate node with delegations, make sure you have done things below:

  • sync and run pchain
  • have an address and consensus keys
  • have at least 10k PI on your address

Pchain have 12 epochs per year, and in each epoch there are 4 phases. You can apply candidate node with delegations during the first phase.

Phase Block Number What you can do
0% ~ 75% start_block ~ vote_start_block - 1 apply candidates and delegate
75% ~ 85% vote_start_block ~ vote_end_block vote
85% ~ 95% reveal_start_block ~ reveal_end_block reveal vote
95% ~ 100% reveal_end_block + 1 ~ end_block check next epoch’s info

You can check the current stage by our Monitor, our by RPC tdm_getEpoch.

Now you can prepare the parameters will used later, you should have:

  • address
  • security deposit //amount of the security deposit PI (minimum 10k PI)
  • commission // the commission fee percentage of each Block Reward be charged from delegators when Candidate elected to be a Validator node (between 0 - 100)

Note: you can also apply candidate node with delegations by PIWallet, it will make this process much easier.

Apply candidate node with delegations

Now you can apply candidate node with delegations by RPC del_applycandidate.

curl -X POST -H "Content-Type:application/json" --data '{"jsonrpc":"2.0","method":"del_applyCandidate","params":["address", "security deposit", commission],"id":1}' localhost:6969/chainid

After this you can check by RPC del_checkcandidate.

Importantly Noticed: Please go to Join Candidate List to submit your introduction. Once your submission has been validated, you will be publicly listed on Recommended Candidates on PIWALLET. Detailed information increases your chances of convincing Delegators to support your candidacy.

Cancel candidates

Once you apply candidate node with delegations successfully, you can cancel it via calling for RPC or PCHAIN wallet PIwallet before the Epoch reaches 75%. 1) Canceling your submission after selected to be Validator: your staked PI will be unlocked and all the delegated tokens you received will be automatically returned to each delegator once the Epoch reaches 100% height. 2) Canceling your submission after you failed being elected Validator: the cancelation will be effective immediately since there are no Validator duties to be completed, your staked PI will be unlocked, and all the delegated tokens you received automatically returned to each delegator balance.

If you don’t want to be a Candidate node with delegations any longer , you can cancel by RPC del_cancelcandidate.

curl -X POST -H "Content-Type:application/json" --data '{"jsonrpc":"2.0","method":"del_cancelCandidate","params":["address"],"id":1}' localhost:6969/chainid

How to Delegate

Pchain have 12 epochs per year, and in each epoch there are 4 phases. You can delegate during the first phase.

Phase Block Number What you can do
0% ~ 75% start_block ~ vote_start_block - 1 apply candidates and delegate
75% ~ 85% vote_start_block ~ vote_end_block vote
85% ~ 95% reveal_start_block ~ reveal_end_block reveal vote
95% ~ 100% reveal_end_block + 1 ~ end_block check next epoch’s info

You can check the current stage by our Monitor, our by RPC tdm_getEpoch.

Delegate

You can delegate by RPC del_delegate.

curl -X POST -H "Content-Type:application/json" --data '{"jsonrpc":"2.0","method":"del_delegate","params":["your address","candidates address", "amount you wanna delegate"],"id":1}' localhost:6969/chainid

Cancel Delegation

  1. If your candidate is validator in current Epoch, the cancelation will be effective immediately. Your PI will be automatically unlocked to your balance when the current Epoch reaches 100%.
  2. If your candidate is not validator in current Epoch, then the cancelation will take effect immediately and your PI will be automatically unlocked to your balance.

You can cancel delegation by RPC del_canceldelegate.

curl -X POST -H "Content-Type:application/json" --data '{"jsonrpc":"2.0","method":"del_cancelDelegate","params":["your address","candidates address", "amount you wanna withdraw"],"id":1}' localhost:6969/chainid

What is FullBalance

Beside the normal Balance of each Account, PCHAIN design a list of Balance Amount for multipurpose reason, therefore we have the following RPC to allow you to view the overall balance under your account, you can also check your FullBalance on PIScan for an easier way.

FullBalance RPC

curl -X POST -H "Content-Type:application/json" --data '{"jsonrpc":"2.0","method":"eth_getFullBalance","params":["0x f92f0b506feb77693c51507eeea62c74869ff0f0", "0x175393", true],"id":1}'

Javascript Console

pi.getFullBalance("0xf92f0b506feb77693c51507eeea62c74869ff0f0", "0x175393", true)

Sample Result (JSON Format)

{
    "jsonrpc": "2.0",
    "id": 1,
    "result": {
        "balance": "0x1e4d26a8ca73c5c0e89c",
        "proxied_detail": {
            "0x29c6aaa742c98000f56b022bfdc68ac18070e0ab": {
                "ProxiedBalance": "0x0",
                "DepositProxiedBalance": "0x3017f94f218b846c4000",
                "PendingRefundBalance": "0x0"
            },
            "0x4e8d522e7d95690bb44f7c589067cf06ba3b4e34": {
                "ProxiedBalance": "0x0",
                "DepositProxiedBalance": "0x7c35cd23913e1218a78c",
                "PendingRefundBalance": "0x0"
            },
            "0x5078ffa5b2ea521a77c5069dd77fa88c3526a0d0": {
                "ProxiedBalance": "0x0",
                "DepositProxiedBalance": "0x567d0352bf3c82d00000",
                "PendingRefundBalance": "0x0"
            },
            "0x6a3c07fa2b7ed2d0a7d0151d123e0f0cdffa3dbb": {
                "ProxiedBalance": "0x0",
                "DepositProxiedBalance": "0x4870d737ed0ee3724000",
                "PendingRefundBalance": "0x0"
            },
            "0x75e4dbb9f429d6a3475e4f84a87ed8e4be748f6b": {
                "ProxiedBalance": "0x0",
                "DepositProxiedBalance": "0x34f0184982338e8a0000",
                "PendingRefundBalance": "0x0"
            },
            "0x981d9cd05117a9d84437958863374a9bc78ac988": {
                "ProxiedBalance": "0x0",
                "DepositProxiedBalance": "0x23ee4727743b014c33d4",
                "PendingRefundBalance": "0x0"
            },
            "0xac7ab60e2f28b137be99a9f960f0d01af01faad5": {
                "ProxiedBalance": "0x0",
                "DepositProxiedBalance": "0x1163ab378be4bf762000",
                "PendingRefundBalance": "0x0"
            },
            "0xb0534db09a8ad1fd6ee2e3ad6889a26799926ad8": {
                "ProxiedBalance": "0x0",
                "DepositProxiedBalance": "0x3b984991099043475706",
                "PendingRefundBalance": "0x0"
            },
            "0xc72f78ab2334a0a8acdbdc53c71186b07ee7580d": {
                "ProxiedBalance": "0x0",
                "DepositProxiedBalance": "0x3daaa47c278b400adaaa",
                "PendingRefundBalance": "0x0"
            },
            "0xe4da810f56e27ba24364621da2b0c3b571355f65": {
                "ProxiedBalance": "0x0",
                "DepositProxiedBalance": "0x1ad994e1723d21600000",
                "PendingRefundBalance": "0x0"
            }
        },
        "reward_detail": {
            "epoch_10": "0x38a4c99380b8546d96",
            "epoch_11": "0x38a4c99380b85511bb",
            "epoch_12": "0x28d7ce6d4796e16115",
            "epoch_13": "0xd20fa530790c92286",
            "epoch_2": "0x38a4c99380b854aeb8",
            "epoch_3": "0x38a4c99380b8546d96",
            "epoch_4": "0x38a4c99380b8546d96",
            "epoch_5": "0x38a4c99380b8546d96",
            "epoch_6": "0x38a4c99380b8546d96",
            "epoch_7": "0x38a4c99380b8546d96",
            "epoch_8": "0x38a4c99380b8546d96",
            "epoch_9": "0x38a4c99380b8546d96"
        },
        "total_delegateBalance": "0x0",
        "total_depositBalance": "0x784757798f05f3000000",
        "total_depositProxiedBalance": "0x2499a2e9484c0f0c5ad10",
        "total_pendingRefundBalance": "0x0",
        "total_proxiedBalance": "0x0",
        "total_rewardBalance": "0x26c68a883565af7b0be"
    }
}

Detail of FullBalance (natural unit: wei, 1 PI = 1,000,000,000,000,000,000 or 10^18 natural units)

1. balance This balance also call free balance, means you can do anything on PCHAIN with this balance (transfer, delegate, vote), your transaction Gas Fee (gas price * used gas) will be deduct from this balance

2. total_delegateBalance The total delegate balance amount. If you send delegate transaction to other address, the delegate amount will be moved from balance field to this delegate balance. If you delegate to multiple addresses, this field will sum the total delegation amount, you won’t able to see the detail of delegation on blockchain level, (for save storage reason, keep the on-chain data as minimum as possible), for detail delegate balance, you may need wallet or 3rd party dapp.

3. total_depositBalance The total staking balance amount, from your own address. If you want to become a validator, after you sending the hash/reveal vote, your staking amount will be locked from balance field to this deposit balance.

4. total_proxiedBalance The total balance that other addresses delegate their balance amount to your address. The balance takes no effect until you vote become a validator, it will move to the deposit proxied balance. Before that, the other address also able to revoke their delegation. For detail of each proxied balance, see proxied_detail field

5. total_depositProxiedBalance The total balance that other addresses delegate their balance amount to your address and become the part of total staking. Other addresses can not revoke their delegation until epoch reach its end. For detail of each deposit proxied balance, see proxied_detail field

6. total_pendingRefundBalance The total balance that other address delegate their balance amount to your address and wait for refund when other address revokes their delegation. The balance will refund when epoch reach its end. For detail of each pending refund balance, see proxied_detail field

7. total_rewardBalance The total balance that will reward to address in the future, after each epoch reaches its end, the reward balance of epoch will move to your balance field for free to use. Every time when the address produces a new Block, this address will be considered as the recipient of the reward. Below is how the reward being calculated

For Main Chain:

20% of block reward goes to Child Chain Foundation Address 0x991cf3cee2a55d06f9c7ba511bee3fad45a1bda7 80% of block reward belongs to the miners. If the block miner has delegation from other address, deduct the commission fee first if any, then the remaining rewards will be distributed by proportion.

For Child Chain:

The Block Reward, setup by Child Chain Owner, belongs to the miner. If the reward pool (address 0x000000000000000000000000000000000000064) doesn’t has sufficient balance, then no reward to miner. If the block miner has delegation from other address, deduct the commission fee first if any, then the remaining rewards will be distributed by proportion.

After each address receive their reward, the reward will be divided into 12 pieces, and allocate to 12 epochs. At each epoch ends, the reward will be move to free balance.

For detail of each reward balance, see reward_detail field

Example (Main Chain)

Block Reward = 100 wei
Miner reward = 100 * 80% = 80 wei
If the miner has delegation, Miner self delegation 50% staking, Other Account 50% staking, commission percentage 10%
Then, commission fee = 80 * 10% = 8 wei
Other Account reward = (80 – 8) * 50% = 36 wei
Miner reward = (80 – 8) * 50% + 8 = 44 wei

Miner Reward divide into 12 epochs = 44 / 12 = 3
From Epoch 0 – 10 = 3 wei each
Epoch 11 = 11 wei (remaining reward)

Sync and Run Testnet

After you install pchain on your computer, you can run

pchain --testnet

to sync testnet’s block and transactions, you should see some outputs look like this:

INFO [05-23|09:22:04.736] Starting PChain...
INFO [05-23|09:22:04.737] PChain supports large scale block-chain applications with multi-chain
INFO [05-23|09:22:04.738] Create peer-to-peer node                 instance=pchain/linux-amd64/go1.11.4
INFO [05-23|09:22:04.738] ethereum.MakeSystemNode
INFO [05-23|09:22:04.740] Allocated cache and file handles         database=/home/ubuntu/.pchain/testnet/geth/chaindata cache=768 handles=512
INFO [05-23|09:22:04.748] Writing default main-net genesis block
INFO [05-23|09:22:04.749] Persisted trie from memory database      nodes=11 size=3.35kB time=47.682µs gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [05-23|09:22:04.749] Initialised chain configuration          config="{PChainId: testnet ChainID: 98411113441374360242664033072086975431386585974419604025805951356851497696398 Homestead: 0 DAO: <nil> DAOSupport: false EIP150: 0 EIP155: 0 EIP158: 0 Byzantium: 0 Constantinople: <nil> Engine: tendermint}"
INFO [05-23|09:22:04.762] Tendermint (backend) Protocol, add logic here
INFO [05-23|09:22:04.762] Initialising Ethereum protocol           versions=[64] network=2
INFO [05-23|09:22:04.762] Loaded most recent local header          number=0 hash=b92288…40abe6 td=1024
INFO [05-23|09:22:04.762] Loaded most recent local full block      number=0 hash=b92288…40abe6 td=1024
INFO [05-23|09:22:04.762] Loaded most recent local fast block      number=0 hash=b92288…40abe6 td=1024
INFO [05-23|09:22:04.762] Regenerated local transaction journal    transactions=0 accounts=0
INFO [05-23|09:22:04.762] Tendermint (backend) SetBroadcaster: 0xc0002302d0
INFO [05-23|09:22:04.762] Tendermint (backend) Protocol, add logic here
INFO [05-23|09:22:04.764] Allocated cache and file handles         database=/home/ubuntu/.pchain/tx3cache               cache=16  handles=16
INFO [05-23|09:22:04.766] Starting P2P networking
INFO [05-23|09:22:06.901] UDP listener up                          self=enode://7b3f6226995c73acfb9f792b8aa73e8c2b1eb35656c9cd7d8c9287c34c0241c34c595d3bb6c7d0b0b7678bf5df0d1e8693bc735bd4a2311e50bd7f4a5d80fd7c@[::]:30308
INFO [05-23|09:22:06.902] Start Chain: testnet
INFO [05-23|09:22:06.902] StartChain()->utils.StartNode(stack)
INFO [05-23|09:22:06.907] IPC endpoint opened                      url=/home/ubuntu/.pchain/testnet/pchain.ipc
INFO [05-23|09:22:06.907] Before Load Child Chains, childChainIds is [child_0], len is 1
INFO [05-23|09:22:06.908] Number of Child Chain to be load - 0
INFO [05-23|09:22:06.908] Start to Load Child Chain - map[]
INFO [05-23|09:22:06.908] RLPx listener up                         self=enode://7b3f6226995c73acfb9f792b8aa73e8c2b1eb35656c9cd7d8c9287c34c0241c34c595d3bb6c7d0b0b7678bf5df0d1e8693bc735bd4a2311e50bd7f4a5d80fd7c@[::]:30308
INFO [05-23|09:22:16.908] Block synchronisation started
...
It means the pchain running on your computer starts to sync.

If you wanna run it backend, you can run with this command

(./pchain --testnet --verbosity=0 &)

After start pchain, it will create a directory to store blockchain data under default datadir directory.

Platform Default Datadir Directory
Linux ~/.pchain
Mac ~/Library/Pchain
Windows %APPDATA%Pchain

You can also set datadir to wherever you like by flag –datadir.

The datadir’s structure will look like this:

datadir/
        -chaininfo.db/
        -config.toml
        -nodekey
        -nodes/
        -tx3cache/
        -testnet/
                -data/
                -geth/
                -pchain.ipc
                -keystore/

Create your own child chain

Before you create your own child chain, make sure you have done things below:

  • sync and run pchain
  • have at least one address and one consensus keys
  • have at least 200k PI on your address

Here is an example of priv_validator.json which stores your address and consensus keys:

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

Notice: Dont create different child chain with same address. You can find this priv_validator.json file in the datadir/.pchain/pchain directory.

create child chain

Suppose you are gonna create a child chain which chain id is “mychain”, and you want your child chain to start with one validator with minimun 100k deposit PI.

You can create child chain by RPC chain_createChildChain.

curl -X POST -H "Content-Type:application/json" --data '{"jsonrpc":"2.0","method":"chain_createChildChain","params":["from","chainId", "minValidators", "minDepositAmount", "startBlock","endBlock"],"id":1}' localhost:6969/pchain

In this case, the command should be:

curl -X POST -H "Content-Type:application/json" --data '{"jsonrpc":"2.0","method":"chain_createChildChain","params":["0x4CACBCBF218679DCC9574A90A2061BCA4A8D8B6C","mychain", "0x1", "0x152D02C7E14AF6800000", "0x32","0x7D0"],"id":1}' localhost:6969/pchain

You can set parameter startBlock very small and set parameter endBlock very big to make sure you wont miss it. After this your account will deposit 100k PI on child chain. If you didnt finish second step, the deposit will be back to your account once main chain reachs the “endBlock” height.

Note: This is only the first step, you need to finish the second step or the chain wont start.

Join Child Chain

Before you join child chain, you need to generate a signature signed by your consensus private key. You can generate it by RPC chain_signAddress.

curl -X POST -H "Content-Type:application/json" --data '{"jsonrpc":"2.0","method":"chain_signAddress","params":["address", "consensus private key"],"id":1}' localhost:6969/pchain

In this case, the command should be:

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.

Now you need to join child chain, in this example, you need at least one validator with at least 100k deposit PI to let your child chain start. You can join child chain by RPC chain_joinChildChain.

curl -X POST -H "Content-Type:application/json" --data '{"jsonrpc":"2.0","method":"chain_createChildChain","params":["from","pubkey", "chainId", "depositAmount", "signature"],"id":1}' localhost:6969/pchain

In this case, the command should be:

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

After this transaction packed and main chain reaches “startBlock” height, your chain will start.

Check

Once your chain started, you will find a directory named with chain id under datadir/.pchain/, in this case, it should be datadir/.pchain/mychain, you can attach to it’s console by command

./bin/pchain attach .pchain/mychain/pchain.ipc

Data Reduction

1.Ensure you have updated pchain to at least v1.2.0

cd ~/pchain/
./bin/pchain version
1.2.0

If not, please update from our Release. Then, stop monitor and auto-update scripts.

crontab -e

Open it with your familiar editor, you will see something like this:

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

Comment out this two line with symbol ‘#’, and save file.

  1. Export chain data

While pchain is running, attach to the console, and run admin.exportChain(“filename”) to export the chain data. Chain data will be exported under the same directory where you started pchain.

If you wanna export main chain’s data, attach to main chain’s console and run admin.exportChain(“filename”). If you wanna export child chain’s data, attach to child chain’s console and run admin.exportChain(“filename”).

This step may take around 10 mins, please be patient.

  1. Delete files

Kill pchain first.

sudo killall pchain

Delete all files and directories under ~/pchain/.pchain except pchain/priv_validator.json, pchain/keystore, child_0/priv_validator.json, child_0/keystore, child_0/eth_genesis.json, child_0/genesis.json.

Your datadir should be like this after you delete files:

datadir/
-pchain/
        -priv_validator.json
        -keystore/
-child_0/(if you are not running child chain, please ignore this directory)
        -genesis.json
        -eth_genesis.json
        -priv_validator.json
        -keystore/
  1. Import chain data

Start pchain with command below:

./pchain --datadir=~/pchain/.pchain --gcmode=full --verbosity=0 --childChain=child_0 --maxpeers=0

Then attach to console, run admin.importChain(“filename”) to import chain data.

This step may take more than 10 hours, please be patient.

Note: If you are running both main chain and child chain, you must import main chain first. Before import child chain’s data, please init child chain first.

./bin/pchain --datadir=~/pchain/.pchain init ~/pchain/.pchain/child_0/eth_genesis.json child_0

After this step, your local database will store only 128 blocks’ state instead of all of the state.

5.Restart pchain

After step 4 finished, please restart pchain with command below:

~/pchain/bin/pchain --datadir=~/pchain/.pchain --rpc --rpcapi=eth,web3,admin,tdm,miner,personal,chain,txpool,del --gcmode=full --verbosity=0 --childChain=child_0 > /dev/null 2>&1 &

You can also use run.sh in the v1.2.0 release to run pchain.

Developer

JSON RPC

Pchain JSON RPC API

JSON is a lightweight data-interchange format. It can represent numbers, strings, ordered sequences of values, and collections of name/value pairs. JSON RPC is a stateless, light-weight remote procedure call (RPC) protocol. Primarily this specification defines several data structures and the rules around their processing. It is transport agnostic in that the concepts can be used within the same process, over sockets, over HTTP, or in many various message passing environments. It uses JSON (RFC 4627) as data format.

JavaScript API

To talk to an pchain node from inside a JavaScript application use the pweb3 library, which gives a convenient interface for the RPC methods. See the JavaScript API for more.

Java API

To talk to an pchain node from inside a Java application use the pweb3j library.

JSON RPC URL

Default JSON RPC URL

Chain Name Chain Id Default Datadir Directory
Main Chain pchain http://localhost:6969/pchain
Child Chain 1 child_0 http://localhost:6969/child_0
Your Chain your_chain_id http://localhost:6969/your_chain_id

How To Open RPC

You can start pchain with flag –rpc

pchain --rpc

After this, if you wanna check main chain’s current block number, the command will look like this:

curl -X POST --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' localhost:6969/pchain

Or if you wanna check child chain’s current block number, the command will look like this:

curl -X POST --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' localhost:6969/child_0

You can also send request by Postman, you will need to start pchain with flag “–rpc –rpcaddr=0.0.0.0”. But remember open your rpc to remote hosts is very dangerous if you keep your account unlocking.

You can check our api list from here.

PIWallet

PIWallet is wallet for PCHAIN. You can download it from here.
There are two mode in PIWallet, one is light mode, which can use to
  • transfer PI
  • delegate
  • create child chain
  • delpoy and interact with smart contract

The other mode is local node mode, which can do all things above and also can

  • vote for validator
  • apply for candidate

Light Wallet Mode

In light mode, you can transfer PI, deploy contract and delegate on our mainnet.

Create or import account

_images/account.png
If you don’t have an account, click the ‘Wallet–Create’ to create account and set password. The password will only saved on your local computer.
You can also import account if you already have its keystore file (file name usually start with UTC) or private key.

Transfer PI cross chain

_images/trasfercross.png
You can transfer PI between main chian and child chain or from one child chain to another child chain.

Transfer PI on same chain

You can transfer PI to another address by click ‘Send PI–Submit’.

_images/transfer.png

How to delegate

Pchain have 12 epochs per year, and in each epoch there are 4 phases.

Phase Block Number What you can do
0% ~ 75% start_block ~ vote_start_block - 1 apply candidates and delegate
75% ~ 85% vote_start_block ~ vote_end_block vote
85% ~ 95% reveal_start_block ~ reveal_end_block reveal vote
95% ~ 100% reveal_end_block + 1 ~ end_block check next epoch’s info
If you do not want to run node on PCHAIN yourself, you can delegate PI to one / several Validator candidate(s) with PI wallet (Light wallet) during first phase.
1.Click “Delegate” tab, you will see the Candidate list there. If you want to get more info about one Candidate, you can click “detail ”.
_images/delegate0.png
  1. Please make sure which chain and Candidate you want to delegate to. Then Click “Join”.

3. Fill in the delegate amount with at least 1,000 PI. Ensure there is at least 0.00021 PI left in your balance for paying the gas fee. The invite code is optional here, it’s designed for some programmes (not released now).

_images/delegate1.png
  1. Enter the password and confirm the transaction info again.
_images/delegate2.png _images/delegate3.png
  1. You can check the delegation details here.
_images/delegate4.png

DETAIL: You can check the daily pos mining reward that you get.

_images/delegate5.png

APPEND: You can delegate more PI to this Candidate before 75% of the Epoch height. CANCEL: You can cancel delegation before 75% of the Epoch height.

6. “Delegate balance” is the amount you delegated to Candidate(s) who are mining blocks for reward as Validator(s) with your delegation. “Delegate to ** Candidate nodes” means the number of Candidate node(s) as Validator(s) who are mining blocks for reward with your delegation. “Total pos mining reward” is the reward amount you got before 23:59:59 yesterday (UTC+8) . “The annual return” = the daily reward/ the delegated amount *365*100%

_images/delegate5.png

How to cancel delegation

You can cancel delegation before the current Epoch reaches 75%.

  1. If your candidate is validator in current Epoch, the cancelation will be effective immediately. Your PI will be automatically unlocked to your balance when the current Epoch reaches 100%.
  2. If your candidate is not validator in current Epoch, then the cancelation will take effect immediately and your PI will be automatically unlocked to your balance.
Choose the candidate that your want to cancel delegation to from the list. The default amount shows the total amount that you delegate to this address.
You can cancel with total delegation amount. Also, you can define the amount that you want to decrease but ensure the delegate balance to this address is equal or greater than 1,000 PI.

Noted: In general, the gas fee is about 0.00021 PI which will be directly paid from your balance.

How to extract mining rewards from rewardBalance

Noted:

  • After PCHAIN mainnet upgraded to V1.2.0, the mining reward need to be extracted by users ( Validator nodes/ delegators) instead of being released automatically.
  • After each epoch ends, you can extract the 1/12 mining reward at anytime.
  • You can’t define the extract amount. The amount is the total reward on one chain you can extract at that moment.

1. Go to PIwallet “Delegate”. Please ensure the address that you want to extract reward to. And then click “Extract Reward”.

_images/extract1.png
  1. Select the chain that you get the reward from.
_images/extract2.png
  1. Enter the password.
_images/extract3.png

Local Node Mode

Before using the local node mode of PIWallet, make sure you have done things bellow:

  • Installed pchain
  • Sync to the latest height (you can check by Monitor)
  • Create Your Account
  • opened rpc (run pchain with flag –rpc –rpcapi=eth,web3,admin,debug,tdm,miner,personal,chain,txpool,del –rpcaddr=0.0.0.0)
  • opened rpc port to your local ip
  • transport keystore file to your datadir

Important: Pchain RPC’s default port is 6969, remember open your port 6969 ONLY to your local ip and DO NOT keep your account unlock for long time (the keystore file should be copied to datadir/CHIAN_ID/keystore/ if you wanna send any transaction under local node mode)!!!

First, set the RPC URL in wallet. The RPC URL is http://yourserverip:rpcport/chainid, so suppose you are running pchain on a machine which ip is 111.222.333.444, and you open rpc with pchain default rpc port, and you wanna interact with main chain, the RPC URL should be http://111.222.333.444:6969/pchain. If you wanna interact with child chain which chain id is child_0, the RPC URL should be http://111.222.333.444:6969/child_0.

_images/seturl.jpg

After this, PIWallet will read the chain state to wallet.

Note: If you wanna send any transation by local node mode, you should transport your keystore to teh machine which running pchain, and your datadir should look like this:

datadir/
        -chaininfo.db/
        -config.toml
        -nodekey
        -nodes/
        -tx3cache/
        -pchain/
                -data/
                -geth/
                -pchain.ipc
                -priv_validator.json
                -keystore/   //you should put your keystore file under here
        -child_0/
                -data/
                -geth/
                -pchain.ipc
                -priv_validator.json
                -keystore/       //you should put your keystore file under here

How to become validator

Before you vote to become validator by PIWallet, make sure you have done things bellow:

  • set up the RPC URL
  • have at least 100k PI, which means “balance + total_depositProxiedBalance + total_proxiedBalance - total_pendingRefundBalance” > = 100K PI.
  • In general, the gas fee is about 0.00021 PI which will be directly paid from your balance.

You can choose to apply candidates first so you can let other delegate to you. This is an option, not neccessity.

Pchain have 12 epochs per year, and in each epoch there are 4 phases.

Phase Block Number What you can do
0% ~ 75% start_block ~ vote_start_block - 1 apply candidates and delegate
75% ~ 85% vote_start_block ~ vote_end_block vote
85% ~ 95% reveal_start_block ~ reveal_end_block reveal vote
95% ~ 100% reveal_end_block + 1 ~ end_block check next epoch’s info

You can check current phase in PIWallet Epoch page.

Now you can prepare the parameters will used during vote and reveal vote, you should have:

  • address
  • consensus public key //contains in priv_validator.json
  • consensus private key //contains in priv_validator.json
  • amount //should be at least 10k PI and equal or larger than total_depositProxiedBalance+total_proxiedBalance-total_pendingRefundBalance
  • salt

First of all, make sure you have bls’ key for consensus, thy are included in file priv_validator.json. (If you don’t have one, follow Create Your Account to generate). Here is an example.

{
        "address": "50CA5341DFE4B07C41854FF79BDB8AB4E11C996D",
        "consensus_priv_key": [
                4,
                "E0F8749A59EEF72347DDB1947A00292BD9D18D32B7C637692B98133A9A9D06D4"
        ],
        "consensus_pub_key": [
                4,
                "0939AD7B1543A37FB2803325EE6C385424D31E0A6A48B2913F425FE3ACBB56301282406B98C389D2D8DE95BB354ABAEF0C3CE7D4D985BE178B3B889B1859874D77C7EEB09146C1B66106FFB803D2884C0102B62A0FEF02D57B33AC286B41BD1183FDB55C8F25FA29859C4A370C9A19F077AB335D905CAB7E4E097C6BF31D3C5C"
        ]
}
Vote

Click the ‘Epoch–Vote Next Epoch’ and fill the information.

_images/vote.png
From: the address to receive mining reward
PubKey: bls public key included in priv_validator.json
Amount: the amount(PI) you wanna deposit(must equal or larger than (total_depositProxiedBalance + total_proxiedBalance - total_pendingRefundBalance.)
Salt: can be whatever you want

If you vote successfully, the wallet will return a transaction hash. You may cost 0.00021 PI for the gas fee from your balance. Please remember all parameters you set, which will be used in revealing vote process

_images/votehash.png
Reveal Vote

Click the ‘Epoch–Reveal Vote’ and fill the information

_images/reveal.png
From, PubKey, Amount and Salt must be the same with the value you set on vote.
BLS Private Key: bls private key included in priv_validator.json

If you vote successfully, the wallet will return a transaction hash. You may cost 0.00021 PI for the gas fee from your balance.

_images/revealhash.png

How to apply for a Candidate Node

Before you vote to become validator by PIWallet, make sure you have done things bellow:

  • set up the RPC URL
  • have at least 10k PI on your address for applying the candidate node
  • In general, the gas fee is about 0.00021 PI which will be directly paid from your balance.

First, unlock your account. (Please do not keep your account unlock for long time, we recommand set the ‘unlockDuration’ to 300. If you set it to 0, your account will unlock forever unless you lock it manually)

_images/unlock.png

Click ‘Candidate–Apply Candidate’ and fill your deposit amount with at least 10,000 PI and your expected commission(% profit sharing expected from being a Validator). Then click ‘Apply’. Noted: before “apply”, ensure there is at least 0.00021 PI left in your address balance for paying the gas fee.

_images/apply1.png

_images/apply2.png

_images/apply3.png

Go to Join Candidate List and submit your introduction. Detailed information increases your chances of convincing Delegators to support your candidacy.

_images/candidatelist.png

Once your submission has been validated in 2 business days, you will be publicly listed on Recommended Candidates on PIWALLET under Light wallet.

_images/search.png

Click ‘Delgate–Recommended Candidates’ and click your address from this list. Your information will show under the below.

_images/showlist.png

If your submission is rejected, PCHAIN team will inform you with email after 2 business days.

How to cancel Candidate

Once you apply candidate successfully, you can cancel it via calling for RPC or PCHAIN wallet before the Epoch reaches 75%.

  1. Canceling your submission after selected to be Validator: your staked PI will be unlocked and all the delegated tokens you received will be automatically returned to each delegator.once the Epoch reaches 100% height.
  2. Canceling your submission after you failed being elected Validator: the cancelation will be effective immediately since there are no Validator duties to be completed, your staked PI will be unlocked, and all the delegated tokens you received automatically returned to each delegator balance.

Noted: In general, the gas fee is about 0.00021 PI which will be directly paid from your balance.

You can cancel Candidate via PIwallet (Local node )or call for RPC before starting voting for next Epoch Validator.

Click ‘Developer–Wallet Mode–Local Node–Candidate–Cancel Candidate’.

_images/cancelcandidate.png

Confirm the candidate address that you want to cancel and click ‘Cancel’.

_images/clickcancelcandidate.png

How to deploy contract on pchain

We recommand use online compiler to compile smart contract.
If you wanna testing your smart contract, it’s better to deploy it on testnet first. You can run PCHAIN testnet first.
You can Get free tPI from our testnet.

Compile

Copy your code into it.

_images/contract.png

Click Details button.

_images/compile1.png

Copy the Byte Code and ABI/JSON Interface

_images/bytecode.png

Deploy

Note: You can only deploy smart contract on child chain.
Enter contract page
_images/contractpage.png

Copy your byte code and click ‘Contract–Deploy Contract’ button.

_images/deploy1.png

Enter your password and send the transaction.

_images/maketransaction.png

Wait for the contract address return and copy the address.

_images/address.png

Interact with Contract

Click ‘Contract–Interact with Contract’ button, copy your ABI/JSON Interface into it and click Access button.

_images/abi.png

PMetamask

PMetamask is a plug-in wallet.

Installation

First, download PMetamask installation package from here. Then open Chrome and input chrome://extensions/ to enter extensions page:

_images/chromeextension.png

Switch to Developer mode on top right of the explorer and drag the PMetamask installation package into it to install the plug-in.

_images/developermode.png

After create or import address by following the guide of PMetamask,you can see something look like this:

_images/pmetamaskehello.png

PCHAIN’s smart contract can only be deployed on child chain. We choose the child chain 1 on PCHAIN testnet to deploy smart contract. You can get free tPI on this child chain from here.

_images/choosenetwork.png

Connect Remix and PMetamask

Keep PMetamask opening,open Remix【http://remix.ethereum.org】 the page is look like this:

_images/remix.png

Under Remix’s ‘Run’ menu,select the Environment as ‘Injected Web3’:

_images/selectenv.png

Click ‘connect’ on the popup PMetamask Notification dialog

_images/connecttometamask.png

After that,the default account’s address in PMetamask will shown in ‘Account’ field automatically.

_images/shownaddress.png

Deploy and interact with smart contract

Edit smart contract in Remix,e.g:

pragma solidity ^ 0.4.23 ;
contract PCHAINTest{

  uint public value = 0;
  function inc(uint v) public {
    value += v;
  }
}

select the proper version to compile(here we take version 0.4.23 as an example):

_images/selectversion.png

compile smart contract

_images/compile.png

Click the ‘Deploy’ button under ‘Run’ menu to deploy the smart contract just complied

_images/deploy.png

After click the ‘deploy’ button,click the ‘confirm’ button on PMetamask Notification dialog:

_images/confirm.png

After deployed successfully, you can debug the contract

_images/interact1.png _images/interact2.png
If there are operations need to spend Gas, you may need confirm in the pop-up PMetamask dialog or in PMetamask directly.
If the transaction failed, you can try to resend it or change the gas fee according to the returned error.

简介

Pchain是什么

超级以太坊PCHAIN 是全球最大规模的原生多链系统,跨洲实测支持256条子链,TPS可达18万 ,秒级即时交易确认。由孵化了Google的Plug & Play 在亚太投资的第一条公链。它的设计使大规模的区块链应用成为可能。目前,PCHAIN已与多家世界500强企业达成战略合作。
创始团队包括中国第一个区块链国际专利发明人、新加坡总统奖获得者、国家千人计划教授,致力于使大规模区块链应用成为可能,该团队总共发表了100篇IEEE ACM论文和国际专利。PCHAIN获得6项专利,Ethereum创始人Vitalik Buterin公开推荐的《Ethereum Technology Details and Practices》一书。
投资机构包括FBG、Torque,QUESTCHAIN、节点资本、了得资本、JRR、BlockVC、Kosmos等40多家海外基金,PCHAIN被多个海外区块链评级机构评为全球区块链Top List的前2名。PCHAIN还获得了硅谷“2018年最具潜力区块链基础平台”奖,被誉为“2018年最佳区块链平台”。与北美区块链协会、IEEE、CFLP等30余家区块链合作伙伴建立了合作关系。
关键创新技术包括:
1. 第一个EVM多链实现了子链和主链的互操作性。在testnet1.0中,它可以支持256个子链和更多的子链,而不会对主链造成压力,全局节点数为1064个。TPS为126K TPS,可以随着子链数量的增加而线性伸缩。
2. 与传统的BFT算法相比,PDBFT算法大大降低了通信成本,从N^2降低到N。在节点数目有限的情况下,可以有效地减少集中化问题。
3.基于知识图的新的Oracle机制使得封装智能合约变得更加容易。W3C兼容的智能数据有效地解决了智能合约中的非智能问题
4. 安全委托和盲目竞价有效避免了委托方与候选人之间的象征性交易,避免了候选人作恶的风险。在epoch切换中,采用盲标机制使验证节点的选择更加公平和安全。
5. 跨链能力。通过使用提供的工具包,可以方便地使用其他非本机令牌(BCH、ERC20)调用PCHAIN的智能合约。

PDBFT共识算法

早期的公有链系统主要采用基于工作证明的共识机制。在这种机制下,硬件性能直接决定了计算能力,即成功生成块的能力。基于PoW的共识算法需要大量的计算能力,导致较低的TPS吞吐量,如Bitcoin提供的3到7个TPS。PoW算法也容易受到51%的攻击,因此用户在处理一个事务之前必须等待几个块确认。
为了克服这些问题,PCHAIN采用了一种新的共识机制——基于公平证明的PDBFT (proof of equity, PoE)。在PDBFT中,每个验证节点需要提前持有一定数量的令牌才能获得投票权,通过投票产生新的块来达成共识。与区块链联盟更安全的网络环境相比,公有链中的验证节点更容易受到攻击,可能会有恶意行为。这被称为拜占庭节点,表现出不确定或不可预测的行为。例如,它可能提出不合法的块,故意投反对票,或者向不同的节点发送不同的选票。拜占庭式的节点甚至可能在恶意的情况下协同工作。
这些行为影响了区块链网络的一致性,给公有链带来了很大的问题。目前,改进的基于PBFT的算法在行业中得到了广泛的应用,如Hyperledger Fabric 0.6、bulbft、Tendermint等。虽然PBFT协议可以解决拜占庭式容错问题,但以下问题限制了它在大型公有链中的应用:
  • PBFT假设验证节点集保持不变,但是在公有链中,验证节点应该能够更自由地加入和退出。
  • PBFT不会主动改变leader,只会在超时的情况下改变。一方面,领导者更容易受到攻击。另一方面,领导者可以有选择地打包一些事务,这样其他事务就无法执行。
  • 在PBFT中,所有验证节点的投票需要通过广播传输到所有节点,因此总的通信开销为O(n2),这极大地限制了它在较大网络中的应用。
经过长期的研究和开发,PCHAIN团队提出了一种新的共识协议PDBFT,能够成功解决上述问题,适用于大型公有链。这一协商一致机制的主要特点包括:
  • 定期替换验证节点集。这允许验证节点更自由地加入和退出机制。每个验证节点可以选择是否参加下一个纪元的验证节点集活动。所有下一个时代的确认者然后通过一致决定。新的验证节点集将在当前纪元结束后生效。
  • 这使得攻击者变得更加困难。每次PDBFT达成共识后,无论是否达成共识或是否需要进行下一轮的共识,都要更换leader。新共识轮的领导者是根据前一个块的共识信息随机生成的,可以由其他验证节点进行验证。由于新leader的产生仅仅依赖于前一个区块的共识和当前共识的状态,所以没有节点提前知道下一个leader。因此,成功攻击的概率大大降低。
  • 将选票从O(n2)传播到O(n)的通信成本降低。与向整个网络广播投票不同,每个验证节点将向当前领导人发送投票。在获得多数票(2/3+)后,领导者将通过聚合签名算法对它们进行聚合。聚合签名的大小与单个签名相同,并且每个验证节点都可以通过验证聚合签名来验证大多数节点是否正确投票。领导者最终将聚合广播给所有验证者,因此协议的通信开销减少到O(n)。这大大提高了协议的可扩展性,使大规模应用成为可能。

多链

多链是pchain中共存链的组织结构,它包含一个主链和若干个必要的并行子链。

不同链的功能

Pchain有两种类型的链,一种是主链;另一个是子链,可能有很多,它们是相同的和独立的。
主链负责余额记录/转移和子链数据的存储。子链负责运行智能合约。对于主链和子链,PI(pchain的令牌)都要为它们的事务执行付费。主链和子链中的PAI值相同,可以在主链和子链之间传递。

多链的设计

  • 每个链都有自己的栈(共识、事务、块、EVM)

    在pchain中,主链和子链分别运行各自的栈,这些栈在大多数模块中共享相同的逻辑,如协商一致算法(PDBFT)、事务的接收和处理、块的存储、EVM的执行等。

    主链栈与子链栈的区别是:主链栈限制了智能合约的部署;子链堆栈不发出自己的令牌,主链和子链共享一个PAI。

  • rpc

    Pchain为多链编写特定的RPC逻辑,每个子进程单独处理自己的RPC需求。当调用时,它只需要在url的路径中添加链id来区分链。例如,当访问子链“childchain-0”时,要发布的url是http://pchain-node/childchain-0。

  • p2p

    利用ethereum的P2P模块设计,当首字母启动一个链时,只需在ProtocolManager中添加链和一个子协议的映射(只提供一个名称),就可以使P2P消息在相关链中正确路由。

  • chain manager and cross-chain helper

    另一个是CrossChainHelper,它被注入到每个链的堆栈中。当主链或子链需要检索跨链信息或调用跨链函数时,CrossChainHelper将派上用场。

多链结构能带来什么

  • 轻松创建公司自己的链

    任何公司有足够的PAI和验证节点可以在pchain中创建一个子链。而这个子链将作为一个正常的公有链或联营链,该公司将获得所有功能的区块链技术供应。

  • 多链协作可以实现大规模的业务逻辑

    每个单独的链都有自己的处理能力,当业务模块可以被拆分并相互独立时,每个模块就可以部署在一个链中。通过这种方式,即使是非常大的企业也可以在pchain上运行,并在不同的链上协作其模块。

Token Swap

PCHAIN主网PI的映射,可通过官方PIWallet 和交易所这两种方式完成。

目前,支持PCHAIN主网PI的交易所有Coinsuper, Gate.io ,Upbit以及Bithumb,其他交易所如Bibox、Bittrex Global等都支持ERC 20 PI,因此,若您的ERC 20 PI在以上交易所,则您首先需提币。

若您的ERC 20 PI在ERC20钱包中,如MEW、Imtoken或者冷钱包,在使用PIWallet进行映射前,请确认您是否持有该地址的私钥或者keystore文件。若没有,则需要将该地址中的ERC20 PI转移至一个新的ERC20 地址,您可以通过PIWallet 来创建ERC20 地址。(创建ERC 20 地址)

  • 映射方式1: 交易所映射

Bithumb 可支持PCHAIN主网映射, 您可将ERC 20 PI充值到Bithumb 账户,就可以自动完成映射了。具体操作您可参考Bithumb 官方指南。 https://support.bithumb.pro/hc/en-us/articles/360033820673-Bithumb-Global-PI-Listing-Jul-31-2019

  • 映射方式2: PIwallet 钱包映射

PIwallet 仅支持主网PI,在PIwallet 上创建的地址与ERC 20地址兼容。

在PIwallet上开始映射之前的提醒:

  1. 将PCHAIN钱包更新到最新版本1.0.4, 点击 这里 下载PIwallet
  2. 确保您有ERC20 PI地址的私钥或keystore文件
  3. 确保ERC20 PI地址中有足够的ETH来支付gas费

第1步:打开PIwallet,然后点击‘Token Swap’

_images/tokenswap01.png

第2步:将您的ERC20 PI地址导入PCHAIN钱包。

方法1:点击‘Import Private Key ’,填写其私钥。 设置密码并重复确认。 然后单击“导入”进行确认。

注意:请自行保管好密码。

_images/tokenswap14.png

这里将显示你的ERC20 PI的地址和你的ERC20 PI的余额

_images/tokenswap21.png

方法2: 点击‘Import Keystore’,从你的电脑选择keystore文件

_images/tokenswap31.png _images/tokenswap41.png

输入密码然后点击‘Import’

_images/tokenswap51.png

然后你将看到ERC20 PI的地址和ERC20 PI的余额

_images/tokenswap61.png

步骤三:确认您的主网PI地址。 下面的默认主网PI地址是导入后的ERC20 PI地址。

_images/tokenswap71.png

如果要使用新地址接收主网PI,请单击“‘Create Wallet’。 设置密码并重复密码。 点击‘Create’进行确认

_images/tokenswap81.png

第4步:填写您要映射的金额。 然后单击‘Token Swap’。 输入密码,然后单击‘Confirm’继续。 请确保您的ERC20 PI地址中有足够的ETH来支付gas费。

_images/tokenswap91.png

确认映射信息,点击‘Send Transaction’.它将自动跳转到Etherscan,请耐心等待交易成功

_images/tokenswap101.png _images/tokenswap111.png

注意:如果Etherscan页面显示‘pending’状态 或者‘unable to locate this transaction Hash’状态很长时间(例如超过1小时),您可以返回到钱包,填写相同数量和更高的gas费,在nounce 值一致的情况下,您的前一笔交易可能会被这笔交易替换掉。

_images/tokenswap121.png

第5步:点击‘Wallet’检查你的余额

_images/tokenswap131.png

Pchain客户端

Pchain客户端是用来运行pchain节点的命令行可执行文件。

硬件和系统要求

以下PCHAIN运行共识节点所需的系统配置详情。 根据AWS目前的成本,第一个月的总成本估计在77美元左右,之后每月将根据实际使用情况,成本会有所增加。

  1. EC2租金(US West 2的价格根据实际需求而定)
  vCPU Memory Monthly fee
t3.large 2 8GiB $62.4
  1. EBS租用费用(US West 2的价格根据实际需求而定)
  1GB-month Estimated monthly usage Monthly fee Recommended capacity
SSD GP2 $0.1 Growing by 100GB per month Growing by $10 per month 2TB
  1. 网络带宽费(US West 2的价格根据实际需求而定)
  GB | Estimated monthly usage Monthly fee Internet speed
AWS EC2 to internet $0.02, first GB free| 50GB $4.41 5Gbps
  1. 操作系统

推荐 Ubuntu 16.04

打开30308端口

确保您在服务器防火墙上打开了30308端口tdp&upd,以使pchain的其他节点可以连接到您的节点。下面是AWS的例子。

_images/303081.jpg

安装

本教程将使用已经编译好的二进制文件,可快速让你完成并启动主网。 另外,你也可以通过源代码(github.)进行安装,这一方式可能会花费1个小时或更多的时间来完成,同时在这一过程中可能会遇到一些会问题。

关于系统的配置问题,可点此查看(硬件和软件要求)。你必须打开pchain 网络的30308 tcp&udp 端口。

Ubuntu

  • Install from release

如果你想成为共识节点,我们建议你通过 release 页面找到最新的版本后完成安装。点此可查看此方式的安装教程( guide ),同时也包含了设置自动升级脚本的步骤。

同步并运行主链

PCHAIN主网安装后,请执行

pchain

以此就可以同步主网的区块以及交易,您应该可以看到输出的内容如下方:

INFO [05-21|09:47:41.666] Starting PChain...
INFO [05-21|09:47:41.666] PChain supports large scale block-chain applications with multi-chain
INFO [05-21|09:47:41.667] Create peer-to-peer node                 instance=pchain/linux-amd64/go1.11.4
INFO [05-21|09:47:41.667] ethereum.MakeSystemNode
INFO [05-21|09:47:41.669] Allocated cache and file handles         database=/home/ubuntu/.pchain/pchain/geth/chaindata cache=768 handles=512
INFO [05-21|09:47:41.692] Writing default main-net genesis block
INFO [05-21|09:47:41.704] Persisted trie from memory database      nodes=182 size=48.66kB time=1.1982ms gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [05-21|09:47:41.705] Initialised chain configuration          config="{PChainId: pchain ChainID: 24160843454325667600331855523506733810605584168331177014437733538279768116753 Homestead: 0 DAO: <nil> DAOSupport: false EIP150: 0 EIP155: 0 EIP158: 0 Byzantium: 0 Constantinople: <nil> Engine: tendermint}"
INFO [05-21|09:47:41.720] Tendermint (backend) Protocol, add logic here
INFO [05-21|09:47:41.720] Initialising Ethereum protocol           versions=[64] network=1
INFO [05-21|09:47:41.720] Loaded most recent local header          number=0 hash=c6ade9…f2f8c3 td=1024
INFO [05-21|09:47:41.720] Loaded most recent local full block      number=0 hash=c6ade9…f2f8c3 td=1024
INFO [05-21|09:47:41.720] Loaded most recent local fast block      number=0 hash=c6ade9…f2f8c3 td=1024
INFO [05-21|09:47:41.721] Regenerated local transaction journal    transactions=0 accounts=0
INFO [05-21|09:47:41.721] Tendermint (backend) SetBroadcaster: 0xc0001e22d0
INFO [05-21|09:47:41.721] Tendermint (backend) Protocol, add logic here
INFO [05-21|09:47:41.732] Allocated cache and file handles         database=/home/ubuntu/.pchain/tx3cache              cache=16  handles=16
INFO [05-21|09:47:41.737] Starting P2P networking
INFO [05-21|09:47:43.846] UDP listener up                          self=enode://7b3f6226995c73acfb9f792b8aa73e8c2b1eb35656c9cd7d8c9287c34c0241c34c595d3bb6c7d0b0b7678bf5df0d1e8693bc735bd4a2311e50bd7f4a5d80fd7c@[::]:30308
INFO [05-21|09:47:43.846] Start Chain: pchain
INFO [05-21|09:47:43.846] StartChain()->utils.StartNode(stack)
INFO [05-21|09:47:43.849] RLPx listener up                         self=enode://7b3f6226995c73acfb9f792b8aa73e8c2b1eb35656c9cd7d8c9287c34c0241c34c595d3bb6c7d0b0b7678bf5df0d1e8693bc735bd4a2311e50bd7f4a5d80fd7c@[::]:30308
INFO [05-21|09:47:43.851] IPC endpoint opened                      url=/home/ubuntu/.pchain/pchain/pchain.ipc
INFO [05-21|09:47:43.851] Before Load Child Chains, childChainIds is [], len is 0
INFO [05-21|09:47:43.851] Number of Child Chain to be load - 0
INFO [05-21|09:47:43.851] Start to Load Child Chain - map[]
INFO [05-21|09:47:45.011] Block synchronisation started
...

以上就表示您所运行的pchain正开始在同步中了。 如果想让它在后端运行,可以通过以下命令:

(./pchain --verbosity=0 &)

Pchain启动之后,系统会在默认的数据目录下创建一个存储区块链数据的目录

Platform Default Datadir Directory
Linux ~/.pchain
Mac ~/Library/Pchain
Windows %APPDATA%Pchain

您也可以通过‘flag-datadir’将数据目录设置在其他地方 。 数据目录的结构如同下方:

datadir/
        -chaininfo.db/
        -config.toml
        -nodekey
        -nodes/
        -tx3cache/
        -pchain/
                -data/
                -geth/
                -pchain.ipc
                -priv_validator.json  //you may not have this file now
                -keystore/

同步并运行子链

PCHAIN目前有一条子链1,用户可参与挖矿。参与方式和参与主链的挖矿机制是一样的。但是在参与之前,需要先完成子链1 的同步和运行。

同时在开始运行子链之前,请先完成主链的同步与运行。

首先,你要获得子链的配置文件(config file),一共有3个文件:

ubuntu@ip-172-31-12-155:~/child_0_config$ ls
eth_genesis.json  genesis.json  run.sh

2个JSON 文件需要复制粘贴到你的数据目录下(yourdatadir/.pchain/child_0/), 您要自建一个child_0的目录。

mkdir -p yourdatadir/.pchain/child_0/
cp ~/child_0_config/*.json yourdatadir/.pchain/child_0/

然后,您需要将子链初始化

pchain --datadir=yourdatadir init yourdatadir/child_0/eth_genesis.json child_0

输出的结果如下:

INFO [05-23|10:12:51.743] init_eth_blockchain 0 with dbPath: .pchain/child_0/geth/chaindata
INFO [05-23|10:12:51.743] Allocated cache and file handles         database=.pchain/child_0/geth/chaindata cache=16 handles=16
INFO [05-23|10:12:51.748] init_eth_blockchain 1
INFO [05-23|10:12:51.748] init_eth_blockchain 2
INFO [05-23|10:12:51.748] Writing custom genesis block
INFO [05-23|10:12:51.749] Persisted trie from memory database      nodes=8 size=2.68kB time=54.136µs gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [05-23|10:12:51.749] init_eth_blockchain end
INFO [05-23|10:12:51.749] successfully wrote genesis block and/or chain rule set: 0bb3cd96500c814d39901c120ec2a78385781a58ce5bd6ed1a272b4ee5cb8435
INFO [05-23|10:12:51.749] Database closed                          database=.pchain/child_0/geth/chaindata
INFO [05-23|10:12:51.750] priv_validator_file not exist, probably you are running in non-mining mode

完成后,您通过flag-childChain=child_0重新启动并运行pchain ,以此来同步子链。

您可以再检查下您的数据目录结构

datadir/
        -chaininfo.db/
        -config.toml
        -nodekey
        -nodes/
        -tx3cache/
        -pchain/
                -data/
                -geth/
                -pchain.ipc
                -priv_validator.json //you may not have this file now
                -keystore/
        -child_0/
                -data/
                -geth/
                -pchain.ipc
                -priv_validator.json //you may not have this file now
                -keystore/

创建账户

在运行了PCHAIN之后,您可以创建自己的账户,同时您还可以:

  • 转账
  • 委托
  • 创建子链
  • 部署智能合约
  • 与智能合约交互

您可以通过以下命令创建账户地址:

pchain --datadir=yourdatadir account new

如果你还想

  • 成为验证节点挖矿
  • 申请成为候选人

你还需要生成bls公私钥对:

pchain --datadir=yourdatadir gen_priv_validator youraddress

这个命令会在您的数据目录下自动创建一个pri_validator.json文件。如果您想要挖矿,则需讲该文件复制粘贴到datadir/childid/。然后请重新启动PCHAIN.

最后,请检查下您的数据目录结构:

datadir/
        -chaininfo.db/
        -config.toml
        -nodekey
        -nodes/
        -tx3cache/
        -pchain/
                -data/
                -geth/
                -pchain.ipc
                -priv_validator.json
                -keystore/

如果你想在紫莲和主链上同时挖矿,你的目录结构应该是这样的:

datadir/
        -chaininfo.db/
        -config.toml
        -nodekey
        -nodes/
        -tx3cache/
        -pchain/
                -data/
                -geth/
                -pchain.ipc
                -priv_validator.json
                -keystore/
        -child_0/
                -data/
                -geth/
                -pchain.ipc
                -priv_validator.json
                -keystore/

如何成为验证节点

在投票竞标之前,请先确定已完成以下准备工作:

  • 同步并运行pchain
  • 持有一个账户地址和共识公私钥
  • 账户地址下至少有100K 数量的PI

您也可以选择先申请成为Candidate,让更多人委托给您,增加投票中标的机率。

PCHAIN主网以12个epoch为1年,每一个epoch中分为4个阶段:

您可以通过monitor来查看目前epoch的阶段情况 Monitor

现在,您可以准备以下几个将会在投票和揭标阶段使用到的参数。 - 账户地址 - 公钥 //存放在 priv_validator.json - 私钥 //存放在 priv_validator.json - 至少100K 数量的PI //total_depositProxiedBalance+total_proxiedBalance-total_pendingRefundBalance - salt

如果你不确定可投票的PI数量,可以通过RPC eth_getFullBalance 查看fullbalance。 RPC eth_getFullBalance.

注意:您也可以通过PIWALLET来完成投票和揭标,过程相对会比较简单。

生成暗标hash

假如你有这样的一个priv_validator.json

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

如果您是在主链上参与竞标,则chainid为‘pchain’,若在子链1上参与竞标,则chainid为‘child_0’。

首先,请先前往pchain的控制台。

pchain attach yourdatadir/chainid/pchain.ipc

在本例中, 指令为:

pchain attach yourdatadir/pchain/pchain.ipc

然后,请输入以下参数来创建投票hash:

var address = "4CACBCBF218679DCC9574A90A2061BCA4A8D8B6C";
var pubkey = "085586D41F70435700850E19B7DE54B3E793C5EC4C6EC502D19030EF4F2122823E5A765E56CBA7B4C57E50561F77B022313C39895CA303F3C95D7B7282412F334778B95ACE046A79AEA4DB148334527250C8895AC5DB80459BF5D367236B59AF2DB5C0254E30A6D8CD1FA10AB8A5D872F5EBD312D3160D3E4DD496973BDC75E0";
var amount = "0x152d02c7e14af7000000";
var salt = "ilovepchain"; //this string can be whatever you like
web3.getVoteHash(address,pubkey,amount,salt);
//"0x4dcb9f6e059051c58cc06ee0c038af4bffc18e85983540a72012bce56d2c37ec"

现在你获得了暗标hash“0x4dcb9f6e059051c58cc06ee0c038af4bffc18e85983540a72012bce56d2c37ec” 注意: 这里的数量是十六进制的,如果您不知道如何转化成十六进制,我们建议您通过PIWALLET来完成竞标的全部操作。

注意: 1gwei = 1000000000wei = 0x3B9ACA00

投暗标

你可以用此RPC投暗标 RPC tdm_voteNextEpoch.

curl -X POST -H "Content-Type:application/json" --data '{"jsonrpc":"2.0","method":"tdm_voteNextEpoch","params":["address", "vote hash"],"id":1}' localhost:6969/chainid

在本例中, 指令为:

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

请记住所返回的hash值并且等到主网进入明标阶段。

注意:您可以在投票阶段进行几次的投票操作,最终系统将会以最后一次为准。

投明标

在揭标之前,你需要通过你的私钥创建一个签名,你可以通过RPC chain_signAddress来完成。RPC chain_signAddress.

curl -X POST -H "Content-Type:application/json" --data '{"jsonrpc":"2.0","method":"chain_signAddress","params":["address", "consensus private key"],"id":1}' localhost:6969/pchain

在本例中, 指令为:

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

记录返回的hash.

现在你可以用此RPC来投明标 RPC tdm_revealvote.

curl -X POST -H "Content-Type:application/json" --data '{"jsonrpc":"2.0","method":"tdm_revealVote","params":["address", "consensus public key", "amount", "salt", "signature"],"id":1}' localhost:6969/chainid

在本例中, 指令为:

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/pchain

请记住返回的hash值,等待epoch进入到最后一个阶段。

查看结果

您可以通过RPC tdm_getnextepochvalidators 来查看自己是否成功竞标成为下个Epoch的共识节点 RPC tdm_getnextepochvalidators.

curl -X POST -H "Content-Type:application/json" --data '{"jsonrpc":"2.0","method":"tdm_getNextEpochValidators","params":[],"id":1}' localhost:6969/chainid

在本例中, 指令为:

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

如何退出验证节点

如果您不再继续作为一个共识节点,您可以自行退出。退出过程同样需要参与上述的投票和揭标,其中需将PI数量设置为0。如果您本身还是Candidate身份,那么还请先取消Candidate。

创建你自己的子链

在创建子链之前,请确保您已完成以下事项:

  • 同步并运行pchain 主网
  • 至少有一个账户地址以及对应的共识公私钥
  • 账户地址中至少有200K数量的PI

以下是关于存储您账户和共识公私钥的priv_validator.json 例子:

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

请注意:请不要使用同一个账户地址来创建多个子链。

创建子链

假设您所要创建的子链ID是mychain,并且以一个共识节点和100K数量的PI来启动运行子链。

您可以通过RPC chain_createChildChain来创建子链。RPC chain_createChildChain.

curl -X POST -H "Content-Type:application/json" --data '{"jsonrpc":"2.0","method":"chain_createChildChain","params":["from","chainId", "minValidators", "minDepositAmount", "startBlock","endBlock"],"id":1}' localhost:6969/pchain

在本例中, rpc指令为:

curl -X POST -H "Content-Type:application/json" --data '{"jsonrpc":"2.0","method":"chain_createChildChain","params":["0x4CACBCBF218679DCC9574A90A2061BCA4A8D8B6C","mychain", "0x1", "0x152D02C7E14AF6800000", "0x32","0x7D0"],"id":1}' localhost:6969/pchain

您可以设置一个很小的起始区块参数,以及一个较大的结束区块参数。您的账户将会抵押100K至子链上。如果您没有完成第二步,那么一旦主链达到结束区块高度,抵押数量将会返回至您的账户地址。

请注意:这仅仅是第一步,您必须完成第二步操作,才能正式启动链。

加入子链

在您加入子链之前,你需要使用私钥通过RPC chain_signAddress创建一个签名 RPC chain_signAddress.

curl -X POST -H "Content-Type:application/json" --data '{"jsonrpc":"2.0","method":"chain_signAddress","params":["address", "consensus private key"],"id":1}' localhost:6969/pchain

在本例中, rpc指令为:

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

记录返回的hash.

现在,以1个共识节点为例的情况下,您需要一个共识节点以100K抵押数量来加入该子链,并启动运行,您可以通过RPC chain_joinChildChain来加入子链。 RPC chain_joinChildChain.

curl -X POST -H "Content-Type:application/json" --data '{"jsonrpc":"2.0","method":"chain_createChildChain","params":["from","pubkey", "chainId", "depositAmount", "signature"],"id":1}' localhost:6969/pchain

在本例中, rpc指令为:

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

在该笔交易完成打包且主链达到起始区块高度后,您的子链就会启动。

检查

一旦您的子链启动后,会在datadir/.pchain/下生成一个以chain id为名的文件目录。如datadir/.pchain/mychain。您可以通过命令行进入其控制台。

./bin/pchain attach .pchain/mychain/pchain.ipc

压缩PCHAIN的旧数据

PCHAIN主网已于12月26日8点19分区块高度为9,383,000时成功硬分叉升级。 此次升级再次优化了Data Reduction,可进一步减少至少50% 以上的新增存储数据。对于之前所产生的旧数据,节点用户可根据以下步骤操作删减。

1. 更新到最新版pchain(v1.2.0以上)

cd ~/pchain/
./bin/pchain version
1.2.0

如果版本低于1.2.0,请从 `Release <https://github.com/pchain-org/pchain/releases>`_下载。将压缩包中的ochain替换至~/pchain/bin/下,然后取消crontab脚本

crontab -e

选择你熟悉的编译器,你会看到如下内容:

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

执行crontab -e 然后将文件中的内容用‘#’注释掉,保存之后退出

  1. 导出链数据

在pchain运行的情况下,进入console,执行admin.exportChain(“filename”)导出对应主/子链的全部区块信息 导出的文件会生成在启动pchain的目录下

若需导出主链,则连接到主链的console后执行admin.exportChain(“filename”) 若需导出子链,则连接到子链的console后执行admin.exportChain(“filename”)

导出所需时间大概在10分钟左右

  1. 删除文件

先将pchain进程杀死

sudo killall pchain

删除Datadir目录下除pchain/priv_validator.json, pchain/keystore, child_0/priv_validator.json, child_0/keystore, child_0/eth_genesis.json, child_0/genesis.json 以外的所有文件和文件夹。

删除后的目录结构是:

datadir/
-pchain/
        -priv_validator.json
        -keystore/
-child_0/(if you are not running child chain, please ignore this directory)
        -genesis.json
        -eth_genesis.json
        -priv_validator.json
        -keystore/
  1. 导入链数据

用以下命令启动pchain:

./pchain --datadir=~/pchain/.pchain --gcmode=full --verbosity=0 --childChain=child_0 --maxpeers=0

Then attach to console, run admin.importChain(“filename”) to import chain data.

这一步可能需要超过10个小时的时间, 请耐心等待。

如果同时跑主链和子链,一定要先导入主链再导入子链。 在导入子链数据前,需要先初始化子链。

./bin/pchain --datadir=~/pchain/.pchain init ~/pchain/.pchain/child_0/eth_genesis.json child_0

这一步完成后,你本地的数据只会保留最新128个块的状态。

  1. 重启pchain

以上四步完成以后,请用以下命令重启pchain:

~/pchain/bin/pchain --datadir=~/pchain/.pchain --rpc --rpcapi=eth,web3,admin,tdm,miner,personal,chain,txpool,del --gcmode=full --verbosity=0 --childChain=child_0 > /dev/null 2>&1 &

你也可以直接使用v1.2.0版本里的run.sh去启动pchain。

PMetamask(中文)

PMetamask是一个插件钱包

安装

首先,下载PMetamask安装包。然后打开Chrome并输入Chrome://extensions/进入扩展页面。 下载地址.

_images/chromeextension1.png

切换到资源管理器右上角的Developer模式,并将PMetamask安装包拖动到其中以安装插件。

_images/developermode1.png

根据PMetamask的指南创建或导入地址后,您可以看到如下内容:

_images/pmetamaskehello1.png

PCHAIN的smart contract只能部署在子链上我们选择PCHAIN testnet上的子链1来部署smart contract。获取免费的tPI.

_images/choosenetwork1.png

连接 Remix 和 PMetamask

保持PMetamask打开,打开Remix【http://remix.ethereum.org】页面如下:

_images/remix1.png

在Remix的“运行”菜单下,选择环境为“注入Web3”:

_images/selectenv1.png

在弹出的PMetamask通知对话框中单击“连接”

_images/connecttometamask1.png

之后,PMetamask中的默认帐户地址将自动显示在“account”字段中。

_images/shownaddress1.png

部署和调用智能合约

在Remix中编写好智能合约,比如:

pragma solidity ^ 0.4.23 ;
contract PCHAINTest{

  uint public value = 0;
  function inc(uint v) public {
    value += v;
  }
}

选择要编译的版本(这里我们以0.4.23版本为例):

_images/selectversion1.png

编译智能合约

_images/compile2.png

点击“运行”菜单下的“部署”按钮来部署刚刚编译好的智能合约

_images/deploy2.png

点击“部署”按钮后,点击PMetamask通知对话框中的“确认”按钮:

_images/confirm1.png

成功部署后,可以调试合约

_images/interact11.png _images/interact21.png
如果有操作需要花费精力,您可能需要在弹出的PMetamask对话框中或直接在PMetamask中进行确认。
如果交易失败,您可以尝试重新发送它或根据返回的错误更改GAS费用。

PIWallet(中文)

PIWallet 是pchain的钱包. 你可以从这里下载 PIWallet.

Local Node Mode

在使用PIWallet的本地local node mode之前,请确保您已完成以下操作:

  • 安装了pchain Installed pchain
  • 同步到最新高度(您可以通过监视器monitor检查)(Monitor)
  • 已创建帐户地址 创建账户
  • 已打开RPC (run pchain with flag –rpc –rpcapi=eth,web3,admin,debug,tdm,miner,personal,chain,txpool,del –rpcaddr=0.0.0.0)
  • 开放您本地IP的rpc端口
  • 将keystore文件传输到您的数据目录

请注意:Pchain RPC的默认端口是6969,因此只需将6969端口开放给您的本地IP即可。请不要将您的账户长时间处于解锁状态(如果您想在local node 模式下发送交易,请将keystore文件应该复制到datadir / CHIAN_ID / keystore /)!

首先,在钱包中设置RPC URL。RPC URL是 http://yourserverip:rpcport/chainid, 因此若你在一台ip为111.222.333.444的机器上运行pchain,用pchain默认的rpc端口打开rpc,此时与主链RPC进行交互的URL应为: http://111.222.333.444:6969/pchain。 若您想与链ID为child_0的子链进行交互,则RPC URL应为http://111.222.333.444:6969/child_0。

_images/seturl1.jpg

之后,PIwallet 会读链上的状态。

注意: 若您想通过local node 模式进行转账交易,请将keystore 传输至运行pchain 的机器上,且您的数据目录应类似于:

::
datadir/

-chaininfo.db/ -config.toml -nodekey -nodes/ -tx3cache/ -pchain/

-data/ -geth/ -pchain.ipc -priv_validator.json -keystore/ //you should put your keystore file under here
-child_0/
-data/ -geth/ -pchain.ipc -priv_validator.json -keystore/ //you should put your keystore file under here

如何成为验证节点

在投票竞标之前,请先确定已完成以下准备工作:

  • 同步并运行pchain
  • 持有一个账户地址和共识公私钥
  • 账户地址下至少有100K 数量的PI

您也可以选择先申请成为Candidate,让更多人委托给您,增加投票中标的机率。

PCHAIN主网以12个epoch为1年,每一个epoch中分为4个阶段:

您可以通过monitor来查看目前epoch的阶段情况。 Monitor

现在,您可以准备以下几个将会在投票和揭标阶段使用到的参数。 - 账户地址 - 公钥 //存放在 priv_validator.json - 私钥 //存放在 priv_validator.json - 至少100K 数量的PI //total_depositProxiedBalance+total_proxiedBalance-total_pendingRefundBalance - salt

如果你不确定可投票的PI数量,可以通过RPC eth_getFullBalance 查看fullbalance。 RPC eth_getFullBalance.

首先,请确认该账户您有对应的公钥和私钥,一般可以在priv_validator.json.文件中找到。(若您没有,可通过创建一个新账户地址:ref:`Create Your Account`来获取)。举例如下:

{
        "address": "50CA5341DFE4B07C41854FF79BDB8AB4E11C996D",
        "consensus_priv_key": [
                4,
                "E0F8749A59EEF72347DDB1947A00292BD9D18D32B7C637692B98133A9A9D06D4"
        ],
        "consensus_pub_key": [
                4,
                "0939AD7B1543A37FB2803325EE6C385424D31E0A6A48B2913F425FE3ACBB56301282406B98C389D2D8DE95BB354ABAEF0C3CE7D4D985BE178B3B889B1859874D77C7EEB09146C1B66106FFB803D2884C0102B62A0FEF02D57B33AC286B41BD1183FDB55C8F25FA29859C4A370C9A19F077AB335D905CAB7E4E097C6BF31D3C5C"
        ]
}
投暗标

请点击‘Epoch–Vote Next Epoch’ 并填写相关信息

zh/wallet/localnode/../../_static/wallet/localnode/vote.png
From: 获取挖矿奖励的账户地址
PubKey: 在priv_validator.json文件中的共识公钥
Amount: 您计划抵押的PI数量(抵押数量需大于等于total_depositProxiedBalance+total_proxiedBalance)
Salt: 任何参数

若您投票成功,将会返回一个交易hash。 上述4个所设置的参数请务必保存记录下来。

zh/wallet/localnode/../../_static/wallet/localnode/votehash.png
投明标

请点击“Epoch–Reveal Vote”,并填写相关信息

_images/reveal1.png

From, PubKey, Amount 以及 Salt 必须与您在投票时所设置的参数一致。 BLS Private Key: 在 priv_validator.json 中的共识私钥。 如果您投票成功,将会返回一个交易hash.

_images/revealhash1.png

开发者文档

JSON RPC

Pchain JSON RPC API

JSON 是一种轻量级的数据交换格式。它可以表示数字、字符串、有序的值序列和名称/值对的集合。 JSON RPC 是一个无状态的、轻量级的远程过程调用(RPC)协议。该规范主要定义了几个数据结构及其处理规则。它与传输无关,因为这些概念可以在相同的流程中、在套接字上、在HTTP上或在许多不同的消息传递环境中使用。它使用JSON (RFC 4627)作为数据格式。

JavaScript API

要从JavaScript应用程序内部与pchain节点通信,可以使用`pweb3 < https://github.com/pchorg/pweb3>`_ library,它为RPC方法提供了一个方便的接口。有关更多信息,请参见 `JavaScript API < https://github.com/pchorg/pweb3/wiki/javascript-api >`_

Java API

要从Java应用程序内部与pchain节点通信,可以使用 pweb3j library.

JSON RPC URL

默认JSON RPC URL

Chain Name Chain Id Default Datadir Directory
Main Chain pchain http://localhost:6969/pchain
Child Chain 1 child_0 http://localhost:6969/child_0
Your Chain your_chain_id http://localhost:6969/your_chain_id

如何开启RPC连接

你可以在启动命令行中加上 –rpc 来开启RPC连接

pchain --rpc

假如你想查看主链现在的高度,可以使用这样的命令:

curl -X POST --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' localhost:6969/pchain

假如你想查看子链现在的高度,可以使用这样的命令::

curl -X POST --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' localhost:6969/child_0

你也可以用`Postman <https://www.getpostman.com/>`_ 发送请求, 但你需要先将 “–rpc –rpcaddr=0.0.0.0” 加入到启动的命令中。

你可以在github上查看我们的RPC接口列表 RPC List.

用pchain搭建私链

备注:以下例子的步骤全都在privatetest文件夹下进行,例子中的datadir为privatetest/.pchain,pchain的可执行文件放在了privatetest/bin/下
注意:若不指定datadir,则默认~/.pchain为datadir,若指定了datadir,请保持所有指令的datadir一致

1. 生成eth_genesis.json 运行此步骤pchain会为用户生成一个随机地址的keystore和priv_validator.json,并用此随机地址生成eth_genesis.json.eth_genesis.json中是创世块的信息,包含了创世块中地址的初始余额和抵押。

命令:

ubuntu@ip-172-31-11-28:~/privatetest$ ./bin/pchain --datadir=.pchain init_eth_genesis "{10000000000000000000000000000,1000000000000000000000000}" //大括号中的第一个参数是该随机地址的初始余额,第二个参数是该随即地址的初始抵押
INFO [01-13|06:28:16.284] this is init_eth_genesis
INFO [01-13|06:28:17.386] createPriValidators                      account:=0x5C1Fac44C7827e55364543744556c13392c883a5 pwd:=pchain
ubuntu@ip-172-31-11-28:~/privatetest$ cd .pchain/
ubuntu@ip-172-31-11-28:~/privatetest/.pchain$ cd pchain/
ubuntu@ip-172-31-11-28:~/privatetest/.pchain/pchain$ ls //可以看到.pchain/pchain目录下生成了priv_validator.json和eth_genesis.json
data  eth_genesis.json  keystore  priv_validator.json
ubuntu@ip-172-31-11-28:~/privatetest/.pchain/pchain$ cat priv_validator.json
{
    "address": "5C1FAC44C7827E55364543744556C13392C883A5",
    "consensus_priv_key": [
            4,
            "C2AAB7E0D1C636133EB49AECCC9A390FD70AD615BAD2BDB6A8D2352F504DE682"
    ],
    "consensus_pub_key": [
            4,
            "6BA273E17A86146DA9A27B591F01724ABADC4F67EB8DFCAF70EF9A6CC858222D1EEAC8600842F5EA05A153B946479FA25A4C2410E78D002EED2F8736B003E1AA4F55311D1160C415DC21BEAC0994D4903A97A14731610F02F88CF2403B470EC98786B99230CC90771C9C63C92929C15280A8C23BD4280E22F77A26907E47140A"
    ]
}
ubuntu@ip-172-31-11-28:~/privatetest/.pchain/pchain$ ll keystore/ //可以看到keystore文件夹下生成的存储了私钥的加密文件,此加密文件的默认密码是“pchain”
total 16
drwx------ 2 ubuntu ubuntu 4096 Jan 13 06:28 ./
drwx------ 4 ubuntu ubuntu 4096 Jan 13 06:28 ../
-rw------- 1 ubuntu ubuntu  491 Jan 13 06:28 UTC--2020-01-13T06-28-16.285283099Z--5c1fac44c7827e55364543744556c13392c883a5

2. 生成genesis.json 运行此步骤pchain会根据第1步中生成的eth_genesis.json来生成genesis.json,该文件包含了pchain运行时初始的共识信息

命令:

ubuntu@ip-172-31-11-28:~/privatetest$ ./bin/pchain --datadir=.pchain init .pchain/pchain/eth_genesis.json
INFO [01-13|06:32:21.112] init_eth_blockchain 0 with dbPath: .pchain/pchain/geth/chaindata
INFO [01-13|06:32:21.112] Allocated cache and file handles         database=.pchain/pchain/geth/chaindata cache=16.78mB handles=16
INFO [01-13|06:32:21.125] init_eth_blockchain 1
INFO [01-13|06:32:21.125] init_eth_blockchain 2
INFO [01-13|06:32:21.127] Writing custom genesis block
INFO [01-13|06:32:21.127] Persisted trie from memory database      nodes=1 size=305.00B time=49.064µs gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [01-13|06:32:21.127] init_eth_blockchain end
INFO [01-13|06:32:21.127] successfully wrote genesis block and/or chain rule set: 665d8a99cdd69faf209bdb6a92efd498bf1a99e3b195b6d10478d393f02229f1
INFO [01-13|06:32:21.127] Database closed                          database=.pchain/pchain/geth/chaindata
INFO [01-13|06:32:21.128] checkAccount(), coinbase is 0000000000000000000000000000000000000000
INFO [01-13|06:32:21.128] checkAccount(), address is 5c1fac44c7827e55364543744556c13392c883a5, balance is 10000000000000000000000000000, amount is 1000000000000000000000000
ubuntu@ip-172-31-11-28:~/privatetest$ cd .pchain/pchain/
ubuntu@ip-172-31-11-28:~/privatetest/.pchain/pchain$ ls //可以看到genesis.json已经生成
data  eth_genesis.json  genesis.json  geth  keystore  priv_validator.json
ubuntu@ip-172-31-11-28:~/privatetest/.pchain/pchain$ cat genesis.json //可以看到genesis.json中的validator与第一步中的地址对应
{
        "chain_id": "pchain",
        "consensus": "pos",
        "genesis_time": "2020-01-13T06:32:21.128149875Z",
        "reward_scheme": {
                "total_reward": "0xfb0c9ff7abf3b85f800000",
                "reward_first_year": "0x1f6193fef57e770bf00000",
                "epoch_no_per_year": "0xc",
                "total_year": "0x17"
        },
        "current_epoch": {
                "number": "0x0",
                "reward_per_block": "0x10ed3d42c506b2bf",
                "start_block": "0x0",
                "end_block": "0xa0668",
                "validators": [
                        {
                                "address": "0x5c1fac44c7827e55364543744556c13392c883a5",
                                "pub_key": "0x6BA273E17A86146DA9A27B591F01724ABADC4F67EB8DFCAF70EF9A6CC858222D1EEAC8600842F5EA05A153B946479FA25A4C2410E78D002EED2F8736B003E1AA4F55311D1160C415DC21BEAC0994D4903A97A14731610F02F88CF2403B470EC98786B99230CC90771C9C63C92929C15280A8C23BD4280E22F77A26907E47140A",
                                "amount": "0xd3c21bcecceda1000000",
                                "name": "",
                                "epoch": "0x0"
                        }
                ]
        }
}

3. 启动pchain 编辑一个pchain启动脚本,将下面的内容复制到run.sh中,保存后退出。此文件应存放在privatetest目录下,注意networkid不要填写小于3的数字,否则将连接到pchain主网。

#!/bin/bash
~/privatetest/bin/pchain --datadir=~/privatetest/.pchain --rpc --rpcapi=eth,web3,admin,tdm,miner,personal,chain,txpool,del --gcmode=full --verbosity=0 --networkid=200 > /dev/null 2>&1 &

然后运行该脚本。

4. 连接至pchain的console 确认pchain启动以后,可以连接到pchain的console查看出块情况。 命令:

ubuntu@ip-172-31-11-28:~/privatetest$ ./bin/pchain attach .pchain/pchain/pchain.ipc
Welcome to the Pchain JavaScript console!

instance: pchain/linux-amd64/go1.10.3
coinbase: 0x5c1fac44c7827e55364543744556c13392c883a5
at block: 20 (Mon, 13 Jan 2020 06:35:22 UTC)
 datadir: /home/ubuntu/privatetest/.pchain/pchain
 modules: admin:1.0 chain:1.0 debug:1.0 del:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 pi:1.0 rpc:1.0 tdm:1.0 txpool:1.0 web3:1.0

> eth.blockNumber
24
> eth.blockNumber
26
> eth.blockNumber
28

如果看到blockNumber不断增长,说明pchain正在正常出块,可以进行后续操作。

FAQ

Check node status step by step

_images/nodecheck.jpg

We recommnd you to put the –ethstats=yournodename:pChain4EVER@stats.pchain.site:80 in run.sh so you can check your node’s status on http://stats.pchain.site/

1.How to check if your node is still running?

Attach to your server, and run command

ps ax|grep pchain

if it returns a string such as

6931 pts/0    Rl     0:01 /home/ubuntu/pchain/bin/pchain --datadir=~/pchain/.pchain --rpc --rpcapi=eth,web3,admin,tdm,miner,personal,chain,txpool,del --gcmode=archive --verbosity=0 --prune

your pchain is still running. If not, please run

sudo ./pchain/run.sh

2.How to check if your node is caught up to the latest block?

if you wanna check main chain:

cd ~/pchain
sudo ./bin/pchain attach .pchain/pchain/pchain.ipc
pi.blockNumber

if you wanna check child chain:

cd ~/pchain
sudo ./bin/pchain attach .pchain/child_0/pchain.ipc
pi.blockNumber

it will return the latest block on your node, and then to check if the height is same as our Monitor.

3.How to check pchain’s version?

::
cd ~/pchain ./bin/pchain version

it will return the version of pchain, you can check the latest version on our github.

Note: if the version of pchain is different from the version in file “~/pchain/version”, plz delete the file, the auto-update script will update pchain 10 mins later.

4.How to check if your node is syncing?

if you wanna check main chain:

cd ~/pchain
sudo ./bin/pchain attach .pchain/pchain/pchain.ipc
pi.syncing

if you wanna check child chain:

cd ~/pchain
sudo ./bin/pchain attach .pchain/child_0/pchain.ipc
pi.syncing

if it return true, your node is syncing now. Also you can type “pi.blockNumber” every min to check if the height is growing continiously. If so, your node is syncing.

5.How to check if my node is validating blocks?

Go to piscan, enter your address and search, you can check the last block you validated. Usually the last block you validate should be mined several mins ago.

6.How to collect logs?

Set verbosity=3 in file “run.sh” and restart pchain, there will be a “log” folder under the same directory you run the “run.sh”.

7. What’s the equipment requirement to run a node on PCHAIN ?

Server Requirement

8. Can I run main chain and child chain on one machine ?

Yes, currently Pchain’s mainnet has one main chain and one child chain, you can run and mine both chains on one machine.

9. How to migrate my pchain to another computer?

If you wanna migrate your pchain to another computer, just install pchain on your new computer, and copy priv_validator.json and nodekey to your new computer.

10. How to check if my node running correctly after setting up the node?

First, check if you are running the latest version, you can find the latest verison from our github. Then make sure the peers connected to your node is more than 2/3 validator number by RPC. And also check if you are syncing to the latest height, you can check the latest height on our Monitor.

11. How to check your node status when running on PCHAIN?

Flow and FAQ of become validatorFaqvalidator

12. How many tokens used to run on PCHAIN?

You need stake at least 100K PI to run alone on PCHAIN. If you want to run a node with others’ delegation, then you need 10K PI to apply for the Candidate node first.

13. How to resync pchain from block 0 ?

If you run into bad block issue then you should look the next question, here is how to re-sync pchain from block 0.

First, stop crontab and stop pchain as explained in steps 1 and 3 of question below, then delete the data except your priv_validator.json and nodekey, after delete, your datadir should look like this:

datadir/
-nodekey
-pchain/
        -priv_validator.json
        -keystore/

If you are running child chain, your datadir should look like this:

datadir/
-nodekey
-pchain/
        -priv_validator.json
        -keystore/
-child_0/
                -priv_validator.json
                -genesis.json
                -eth_genesis.json
                -keystore/

Make sure your datadir is excactly like above. Now you can re-sync blocks, if you are running child_0, remember init child chain first:

cd ~/pchain
./bin/pchain --datadir=~/pchain/.pchain init ~/pchain/.pchain/child_0/eth_genesis.json child_0
./run.sh

If you run main chain only, just run

cd ~/pchain
./run.sh

14. What should I do if I got bad block very often?

pchain supply an official data package,please back up your priv_validator.json and keystore file first, and follow the steps below:

1.stop crontab

crontab -e

Open it with your familiar editor, you will see something like this:

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

Comment out this two line with symbol ‘#’, and save file.

2.download the package

If you are running mainchain only please run:

cd ~/pchain
wget https://pchainblockdata.s3-us-west-2.amazonaws.com/blockData.tar.gz

If you are running main chain and child chain please run:

cd ~/pchain
wget https://pchainblockdata.s3-us-west-2.amazonaws.com/blockDataWithChild.tar.gz

3.stop pchain

killall pchain

4.delete your datadir and monitoring files(please make sure you already backed up your priv_validator.json and keystore file)

rm -r .pchain stuck_times epoch

5.replace datadir

If you are running mainchain only please run:

cd ~/pchain
tar -xzf blockData.tar.gz

If you are running main chain and child chain please run:

cd ~/pchain
tar -xzf blockDataWithChild.tar.gz

6.copy your priv_validator.json

If you are running mainchain only please run:

cp youpathway/priv_validator.json ~/pchain/.pchain/pchain/

If you are running main chain and child chain please run:

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

7.start pchain

./run.sh

8.check

./bin/pchain attach .pchain/pchain/pchain.ipc
>pi.blockNumber

9.set crontab

crontab -u yourusername ~/pchain/scripts/pchain.cron

Full Balance

1. Where can I find the node’s balance info and reward info

You can go to PIwallet/ PIscan under “fullbalance” tag, or via call for the FullBalance RPC.

2. What’s the meaning of each balance type there ?

balance: The total unlocked amount. This balance also call free balance, means you can do anything on PCHAIN with this balance e.g transfer, delegate, vote,etc. Your transaction Gas Fee (gas price * used gas) will be deduct from this balance.

delegateBalance: The total amount you delegate to other address(es). If you send delegate transaction to other address, the delegate amount will be locked from balance to this delegate balance. If you delegate to multiple address, this field will sum each delegation amount. For detailed delegate balance, you can go to PIwallet/ PIscan to check.

depositBalance: The staking amount you vote from your balance for Validator. If you want to become a validator, after you vote/reveal vote, your staking amount will be locked from balance field to this deposit balance.

depositProxiedBalance: The total amount that others delegate to you (You applied as a Candidate) and you vote for validator with these delegation amount. After 75% block height, the delegators are not able to revoke their delegation.

pendingRefundBalance: The total pending refund amount when delegator revoke delegation. Delegators revoke the delegate amount to you which is the part of total staking amount in current epoch before 75% block height. This pending refund balance will return to the delegators’ balance when the current epoch ends.

proxiedBalance: The total balance that other people delegate their balance amount to you. Before voting, delegators can also revoke their delegation. After becoming validator, proxied balance will move to the deposit proxied balance.

rewardBalance: The reward amount which will unlock to the free balance in next epochs. After each epoch reach its end, the reward balance will unlock 1/12 to your balance field for free to use.

Flow and FAQ of become validator

_images/validator.png

For more information please refers to How to become validator by PIWallet and How to become validator by RPC. There are some FAQ below:

1. Where to find the exact time to participate in staking correctly?

You can check stage on our Monitor. There are four stage in one epoch.

Stage Block Number What you can do
0% ~ 75% start_block ~ vote_start_block - 1 apply candidates and delegate
75% ~ 85% vote_start_block ~ vote_end_block vote
85% ~ 95% reveal_start_block ~ reveal_end_block reveal vote
95% ~ 100% reveal_end_block + 1 ~ end_block check next epoch’s info

2. The detailed operation to become validator via PIwallet

How to become validator by PIWallet

3. The detailed operation to become validator via RPC

How to become validator by RPC

4.Must I apply candidate?

No, you can compete validator by yourself. But if you apply candidate, you can get other’s deposit, which will make you more competitive.

5.How many PI should I deposit while vote stage?

The amount you deposit should be at least 100k PI and equal or larger than total_depositProxiedBalance+total_proxiedBalance-total_pendingRefundBalance. And the deposit number should be the same while reveal vote stage.

6.How many PI is needed to be elected for Validator node?

There is no a guaranteed amount, the number of new validator node depends on how many native PI voted and reveal voted. If your deposit amount ranking is ahead of No.(number of current epoch’s validator + number of next epoch’s new bidders / 2 ), then you will be next epoch’s validator. You can also check via tdm.getNextEpochValidators() to see if you are in the validator list.

e.g currently we have 79 validator nodes on main chain, and we got 5 Candidate nodes who participated in voting and revealing voting now, then the threshold ranking will be 79 + 5 / 2 = 81, which means the system will elect 81 Validator nodes for Next epoch based on each voting amount ranking.

7.How do I know if I can be next epoch’s validator or not?

If your deposit amount ranking is ahead of No.(number of current epoch’s validator + number of next epoch’s new bidders / 2 ), then you will be next epoch’s validator. You can also check via tdm.getNextEpochValidators() to see if you are in the validator list.

8.What is the minimun amount should I enter when I vote?

The amount should be at least 100k PI and equal or larger than total_depositProxiedBalance+total_proxiedBalance-total_pendingRefundBalance.

9.As validator, should I do the vote and the reveal vote for each epoch?

If you wanna keep the same deposit amount in next epoch, you don’t need to proceed it again. Otherwise you should participate in this process.

e.g your current deposit amount is A the deposit amount you wanna add is B then you should set the amount to A+B during vote and reveal vote

10.Can I update the commission fee as a candidate?

You need to cancel candidate first and then reapply candidate node (Noted that once you cancel,the delegation amount you received will return to delegators). After reapply, you can check on PIWallet if you are on the candidate list. If not, just wait for couple hours for PIWallet to refresh the commission fee.

Delegation

1. How many PI should I delegate to one candidate node?

You need to delegate at least 1K PI to one candidate.

2. When can I delegate token?

You can delegate PI before the epoch reaches 75% height.

3. I have sent tx to delegate PI, why does the Tx status still show “pending” under the PIWallet delegate tag?

When your candidate elected for next epoch validator successfully, then this Tx status will change to success, which also means you will start to get pos mining reward.

4. What does “Delegated to ** elected candidate node” mean?

It means the the number of your candidate which became the validator in current epoch.

5. Can I delegate more to the same candidate?

Yes. You can delegate again before the epoch reaches 75% block height.

6. After delegation, when can I get the reward?

If the candidate you delegate to elected to be the next epoch validator successfully, then you will get the reward when the new epoch starts.

7.Error: cancel amount greater than your Proxied Balance

This error occured because the PI amount you are cancelling is greater than you delegated. Please copy your candidate’s address and go to PIScan to check your candidate’s fullbalance. Find your address in your candidate’s Proxied detail, there are 3 value which we supposed is

ProxiedBalance  A PI
DepositProxiedBalance   B PI
PendingRefundBalance    C PI

The amount you cancel should lower or equal than A+B-C.

8.Error:delegation amount must be greater or equal to 1000PI

This error occured because you are cancel invalid amount.Please copy your candidate’s address and go to PIScan to check your candidate’s fullbalance. Find your address in your candidate’s Proxied detail, there are 3 value which we supposed is

ProxiedBalance  A PI
DepositProxiedBalance   B PI
PendingRefundBalance    C PI

If you don’t wanna cancel all your delegation, the amount you cancel should be lower or equal than A+B-C-1000. If you wanna cancel all your delegation, the amount you cancel must be equal to A+B-C.

9.Error: Replacement transaction underpriced

This error occured becaused the former transaction you made before are in processing. Suggest you to wait for a moment and retry. But if you wanna make this new transaction to cover the former one, you can increase the gas fee.

10. I didn’t get delegation tx hash, how can I ensure if my delegation is successful?

You can check the delegation history in PIwallet “Delegate” page, or go to ‘Wallet” page to check the account balance if it decreased.

11. Why did my delegation hash/ Cancellation hash fail?/ Why did it return “can’t delegate now”/ “Can’t cancel now”?

After the chain reached 75% block height, you’r not allowed to delegate or cancel delegation. Then, pls retry when next epoch starts.

Cancel node/ Candidate / delegation

As a candidate, can I update the commission fee?

You need to cancel candidate first and then reapply candidate node (Noted that once you cancel,the delegation amount you received will return to delegators). After reapply, you can check on PIWallet if you are on the candidate list. If not, just wait for couple hours for PIWallet to refresh the commission fee.

How to cancel candidate submission?

How to cancel candidate

How to cancel Validator node to unlock the staking amount?

After epoch reaches 75% height, you need to participate in the voting and revealing vote and set the staking amount to 0. Remember first make sure your node synced to the latest height. The voting and revealing vote process please refer to How to become validator by PIWallet and How to become validator by RPC Once cancellation succeed, the staking amount will be unlocked to your balance when the current epoch ends.

How to cancel delegation ?

Before the epoch reaches 75% height, you can cancel delegation. Guidance: How to cancel delegation

Error: cancel amount greater than your Proxied Balance

1. Mostly you have canceled this delegation before, so you will get this error when repeatly cancel it. Please make a copy of the candidate address and check its fullbalance at PIScan . Find if your account value show in the PendingRefundBalance in the candidate’s Proxied detail. If so, the cancellation succeed, the delegated PI will unlock to your balance when the current epoch ends. For example, the user A (0xa2535da0764e8a7c6e167fcfc22b9ec5b10661d1 ) delegated PI to the candidate B (0xf6a94ecd6347a051709f7f96061c6a0265b59181). Once canceled, user A can find the info like below.

_images/repeat1.png _images/repeat2.png

2.This error occured because the PI amount you are cancelling is greater than you delegated. Please copy your candidate’s address and go to PIScan to check your candidate’s fullbalance. Find your address in your candidate’s Proxied detail, there are 3 value which we supposed is

ProxiedBalance  A PI
DepositProxiedBalance   B PI
PendingRefundBalance    C PI

The amount you cancel should be lower or equal than A+B-C.

Error:delegation amount must be greater or equal to 1000PI

This error occured because you are cancel invalid amount.Please copy your candidate’s address and go to PIScan to check your candidate’s fullbalance. Find your address in your candidate’s Proxied detail, there are 3 value which we supposed is

ProxiedBalance  A PI
DepositProxiedBalance   B PI
PendingRefundBalance    C PI

If you don’t wanna cancel all your delegation, the amount you cancel should be lower or equal than A+B-C-1000. If you wanna cancel all your delegation, the amount you cancel must be equal to A+B-C.

When can I get my PI back after I cancel the delegation successfully?

If you delegated and wanna cancel in the same epoch before the chain reaches 75% height, the token will return back to balance immediately.

If you delegated in last epoch and your candidate failed to be validator in current epoch, once you cancel delegation before the chain reaches 75% height, the token will return back to balance immedidately.

If you delegated in last epoch and your candidate is elected to be validator successfully in current epoch, once you cancel delegation before the chain reaches 75% height, the token will return back to balance when the current epoch ends.

Staking Reward

1. How many total pos mining reward and what’s the distribution plan ?

PCHAIN total pos mining reward is 315,000,000 PI.

Distribution:
Year1~Year4 : 39,375,000 PI per year
Year5~Year8:19,687,500 PI per year
Year9~Year12:9,843,750 PI per year
Year13~Year16:4,921,875 PI per year
Year17~Year20:2,460,937.5 PI per year
Year21~Year24: 2,460,937. PI per year

2. How can I get staking reward?

You need to vote for the validator. If succeed, then you can get reward in next epoch. If you are the nun-tech people, you can delegate token to candidate. Once the candidate you delegated to vote for the validator successfully, then you can share the reward as well in next epoch.

3. I have delegated to one candidate for over 25 days, why haven’t I received any reward?

If you delegated in current epoch, you can get reward when new epoch starts once the candidate vote for the next epoch validator successfully. If you delegated in last epoch, it means the candidate failed in voting for the validator. So you won’t get rewards.

4. When will the reward unlock?

The reward you received in each epoch will be unlocked automatically in 12 epochs.

5. How many reward that I may receive in one epoch?

The PoS mining reward depends on your PI amount percentage of total staking amount in each epoch. PoS mining reward ≈ Your staking amount/ total staking amount * block reward * the number of epoch blocks If you are the delegator, then your reward ≈ (1- commission fee(%) ) * Your staking amount/ total staking amount * block reward * the number of epoch blocks

** commission fee will be released to the candidate.**

Monitor

1. What’s the PCHAIN monitor?

You can monitor the mining status of PCHAIN mainnet, also includes the epoch info, the validator info, block reward, the speed of the block mining, the block number, etc.

Monitor: monitor.pchain.org

PIScan

1. What’s the PIscan

That’s block explorer which allows you to search, view and analyze PCHAIN data like blocks, transactions, validators, etc.

2. How to ensure if the transaction succeed or not?

Option1: Go to https://piscan.pchain.org “explorer” page, search with the transaction hash. If it returns transaction details, it succeed. Sometimes it may delay due to the mainnet speed. Then please retry later. Option2: Go to console, enter pi.getTransactionReceipt(“hash”) , if status=”0x1”, it means success.

..Token Swap

1.How to swap from ERC 20 PI to native PI via PIwallet?

How to do token swap

2.Password error

Please enter your erc20 address’ password to do the swap.

PIwallet

1. How can I get listed in PIwallet Candidate list?

Please submit application at https://pchain.org/joinCandidate. You will get listed in 2 business days when we validated your submission.

2. What can I do when I find PIscan/ monitor stop updating any data or get error “Internet error, please refresh the page”/ “response rpc json” on PIwallet?

All these situations may happen because the wallet node down. Please contact PCHAIN team (op@pchain.org) or admin, we will fix with it as soon as possible.

Cross Chain Transaction

1. How to recover the abnormal cross-chain transaction?

Because of the consensus network, some people may get issue on cross-chain transaction that the balance didn’t increase after at least 5 minutes. Here are the detailed operation to help you make the transaction successful.

Open PIWallet, go to “ Wallet ” tab, find the transaction record and click “detail”.

_images/recover0.png
  • Situation1

Click “Check ”, if it returns “Successful transaction” on the page, it means this transaction is successful now. You can refresh the balance on main chain again.

_images/recover1.png
  • Situation 2

If you click “check” and it returns “Failed Transaction”, it means you need to resend PI to recover this transaction. Pls click “Resend” directly.

_images/recover2.png _images/recover3.png

Fill out your account’s password.

_images/recover4.png

Confirm the transaction info and click “Resend transaction”.

_images/recover5.png

If it returns with one transaction hash, it means resend successfully. You can check the balance within 2 minutes. If it returns “Error” like the picture below, pls click “Detail” of the first transaction record and make a copy of the transaction hash. Then send this Tx hash & your address to PCHAIN Team (op@pchain.org). PCHAIN team will help you make this transaction successful in 1~2 business day(s).

_images/recover6.png

Developer

1. How to migrate DApp from ethereum to pchain?

Pchain is compatible with EVM, so you just need to deploy your smart contract on pchain’s child chain. The process is same with ethereum. You can deploy smart contract by PMetamask.

How many reward will I get if I successful deposit on pchain?

Suppose your deposit amount is A, the total deposit of current epoch is B, the total block number of current block is C, the reward per block during current epoch is D, then your reward during current epoch will be about A/B*C*D.

How do I know if I can be next epoch’s validator or not?

First of all, make sure you vote and reveal vote correctly.This can be check via tdm.getNextEpochVote() in pchain’s console. If your deposit amount ranks before (number of current epoch’s validator + number of next epoch’s new bidders / 2 ), then you will be next epoch’s validator. You can also check via tdm.getNextEpochValidators() to see if you are in the validator list.

e.g currently we have 79 validators on main chain, and we got 5 bidder now, then the threshold ranking will be 79 + 5 / 2 = 81

Can I run main chain and child chain on one machine?

Yes, currently Pchain’s mainnet has one main chain and one child chain, you can run and mine both chain on one machine.

Why can’t I connect to my node from PIWallet?

If you are trying to use “local node mode” in PIWallet and get this error:

_images/walletcannotconnect.jpg

Make sure you have done things bellow:

  • install and run pchain on your remote node
  • run pchain with flag “–rpc –rpcaddr=0.0.0.0”
  • open port 6969 to your local ip

Here is an example which run PIWallet on PC to connect to pchain running on AWS EC2: On AWS EC2, we run pchain with this command:

~/pchain/bin/pchain --datadir=~/pchain/.pchain --rpc --rpcapi=eth,web3,admin,debug,tdm,miner,personal,chain,txpool,del --childChain=child_0 --rpcaddr=0.0.0.0

And then we open port 6969 to my PC in security group of my AWS EC2

_images/open6969.jpg

Why my PIWallet doesn’t show anything under local node mode?

If you are trying to use “local node mode” in PIWallet and connect to your node succesfully but can’t find any information shown in PIWallet, probably because you haven’t transport your keystore file to your node. If you wanna send any transactions by PIWallet local node mode, you should keep your keystore file under “yourdatadir/.pchain/chainid/keystore/”. So the structure of your datadir should look like this:

datadir/
        -chaininfo.db/
        -config.toml
        -nodekey
        -nodes/
        -tx3cache/
        -pchain/
                -data/
                -geth/
                -pchain.ipc
                -priv_validator.json
                -keystore/   //you should put your keystore file under here
        -child_0/
                -data/
                -geth/
                -pchain.ipc
                -priv_validator.json
                -keystore/       //you should put your keystore file under here

How to check if my node running correctly?

First, check if you are running the latest version, you can find the latest verison from our github. Then make sure the peers connected to your node is more than 2/3 validator number by RPC. And also check if you are syncing to the latest height, you can check the latest height on our Monitor.

How to migrate my pchain to another computer?

If you wanna migrate your pchain to another computer, just install pchain on your new computer, and copy priv_validator.json and nodekey to your new computer.

As validator, should I do the vote and the reveal vote for each epoch?

If you wanna keep the same deposit amount in next epoch, you don’t need to proceed it again. Otherwise you should participate in this process.

e.g your current deposit amount is A
the deposit amount you wanna add is B
then you should set the amount to A+B during vote and reveal vote
You need to cancel candidate and apply candidate on chain again(remember once you cancel your proxied amount will be return to delegators). And if you can cancel and apply on chain again very quickly, you may dont need to apply on website. After done things on chain you can check on PIWallet if you are still on the candidate list, if not please apply on website again, if you are still on, just wait for couple hours for PIWallet to refresh the commission fee.

What should I do if I accidently transfer ERC20 PI to native PI address?

please follow this video.

How to recover abnormal cross-chain transaction?

Because of the consensus network, some people may get issue on cross-chain transaction that the balance didn’t increase after at least 5 minutes. Here are the detailed operation to help you make the transaction successful.

Open PIWallet, go to “ Wallet ” tab, find the transaction record and click “detail”.

_images/recover0.png
  • Situation1

Click “Check ”, if it returns “Successful transaction” on the page, it means this transaction is successful now. You can refresh the balance on main chain again.

_images/recover1.png
  • Situation 2

If you click “check” and it returns “Failed Transaction”, it means you need to resend PI to recover this transaction. Pls click “Resend” directly.

_images/recover2.png _images/recover3.png

Fill out your account’s password.

_images/recover4.png

Confirm the transaction info and click “Resend transaction”.

_images/recover5.png

If it returns with one transaction hash, it means resend successfully. You can check the balance within 2 minutes. If it returns “Error” like the picture below, pls click “Detail” of the first transaction record and make a copy of the transaction hash. Then send this Tx hash & your address to PCHAIN Team (op@pchain.org). PCHAIN team will help you make this transaction successful in 1~2 business day(s).

_images/recover6.png

How to resolve handle crash on child chain?

If you got the error on child chain like following 2 pics, it means the handle crash due to the number of handles increased. Please follow the steps below to recover it.

_images/handlecrash1.png _images/handlecrash2.png

Run ” cat /proc/sys/fs/file-max ” to check the maximum number of files.

Run “sudo vi /etc/security/limits.conf“ to set file number ( should be less than or equal to the max number of files above).

  • soft nofile 512000
  • hard nofile 512000

Run “ sudo vi /etc/pam.d/common-session” session required pam_limits.so

Run “ sudo vi /etc/profile” ulimit -SHn 512000 ulimit -v unlimited

Click this link for Reference for Ubuntu system on setting the number of files to recover the handle crash.

FAQ(常见问题)

如何退出validator?

确保你的节点已经同步到最新的块。退出validtaor的操作与加入validator的操作一致,当epoch进入到75%-85%时,投出amount为0的暗标,当epoch进入到85%-95%时,投出相应的明标。你的抵押金额将会在当前epoch结束后返还。 详情请参考 https://pchaindoc.readthedocs.io/en/latest/zh/pchainclient/howtobecomevalidator_zh.htmlhttps://pchaindoc.readthedocs.io/en/latest/zh/wallet/localnode/Epoch_zh.html

如何取消委托 ?

Epoch进入75%之前,你都可以通过钱包取消委托。 Guidance: How to cancel delegation

如果我将PI抵押在了pchain上,我将获得多少收益?

你的奖励将由你抵押的金额决定。 计算公式:假设你抵押的金额为A,当前epoch总共抵押了B,你的的出块数量为C,上一个epoch的块奖励为D,则你的收益为:A / B * C * D。

怎么查看我是否成功被选为下一个epoch的validator?

首先请确保自己的暗标和明标都发送成功,你可以通过tdm.getNextEpochVote()在pchain console里查看。如果你投标的金额排在了(当前epoch的validator的数量 + 新竞标者数量/2 )之前,那么你将被选为下一个epoch的validator。在明标阶段你可以通过tdm.getNextEpochValidators()在pchain console中查看自己的地址是否在列表中。 比如:当前epoch有79个validator,并且有5个成功投标的bidder,那么你应该排在79+5/2=81名之前才能被选为下一轮的validator

我可以在同一台机器上跑子链和主链吗?

可以。

为什么我的PIWallet连不上我的pchain节点?

如果你在使用PIWallet的 “local node mode”时显示以下错误:

_images/walletcannotconnect1.jpg

请检查你是否做了下列事情:

  • 你的远程机器上pchain确实正在运行中
  • 你运行pchain时加上了 “–rpc –rpcaddr=0.0.0.0”这两个flag
  • 你把远程机器的6969端口打开了

假设你在个人电脑上运行了PIWallet, 你想用它连接你运行在aws机器上的pchain节点,那么你运行pchain时的命令应该是这样的:

“~/pchain/bin/pchain –datadir=~/pchain/.pchain –rpc –rpcapi=eth,web3,admin,debug,tdm,miner,personal,chain,txpool,del –childChain=child_0 –rpcaddr=0.0.0.0”

在aws ec2后台上要把6969端口打开给你的本地ip:

_images/open69691.jpg

为什么我的PIWallet什么内容都不显示?

如果你在使用PIWallet的local node mode并且已经成功连接了你的远程节点,但是钱包里没有显示任何信息,那么很有可能是因为你没有把你的keystore上传到你的远程机器上。如果你想在local node mode下发起任何交易,都需要你将keystore文件上传到你的远程节点,并放在 “yourdatadir/.pchain/chainid/keystore/”目录下。

我怎么知道我的pchain节点是否在正常运行?

首先,检查你是否运行了最新版本,你可以去我们的`github <https://github.com/pchain-org/pchain>`_ 查看最新版本.。然后请检查你的的节点是否连接了足够的peers,你的peers应该超过当前epoch validator个数的2/3,同时检查你的节点是否在最新的高度上,你可以通过我们的`Monitor <https://monitor.pchain.org/>`_ 查看。

怎么把我的pchain节点迁移到另一台机器?

如果你想把pchain迁移到另一台机器,可以直接在另一台机器上安装pchain,然后把 priv_validator.json和nodekey文件拷贝到你的新机器上即可。

作为一个validator,我需要在每个epoch重新投标吗?

如果你不想改变你抵押的金额,那么在切换epoch时什么都不用做。否则你需要重新投标。

比如: 你当前epoch的抵押金额为 A
你想加仓的金额为 B
那你在下个epoch投标的时候应该把金额设置成A+B

作为一个candidate,怎么修改我设置的commission fee?

你需要先在链上cancel candidate然后重新apply candidate(注意一旦你cancel,抵押给你的所有PI都会回到delegator的地址上)。在链上完成以后需要在钱包里查看你是否还在candidate列表里,如果不在了,需要在网页上重新提交申请candidate的表格。

如果不小心把erc20PI转到了PIWallet里的地址怎么办?

因为PIWallet 只能对native PI进行操作,所以你需要先将该地址的私钥导出,再去erc20钱包里操作。首先请打开PIWallet进入Wallet页面,选择你的地址,然后点击Export Private Key得到该地址的私钥

_images/0.png

然后用其他erc20钱包(比如MEW和ImToken等等),把私钥导入,然后把erc20转回到你原来的地址。

如何恢复不正常的跨链转账?

如果你在进行跨链转转账后的五分钟后依然没有收到PI,请根据下面的步骤操作。

打开PIWallet, 前往 “ Wallet ” 页面, 找到交易记录然后点击 “detail”.

_images/recover01.png
  • 情况1

点击“Check ”, 如果返回 “Successful transaction”, 说明这笔交易现在已经成功了。请再次检查你的PI余额。

_images/recover11.png
  • 情况 2

如果你点击“check”之后得到 “Failed Transaction”的返回, 说明你需要重新发送去恢复这条交易,请点击“Resend”。

_images/recover21.png _images/recover31.png

填入你的密码

_images/recover41.png

确认交易信息然后点击“Resend transaction”.

_images/recover51.png

如果返回了交易hash,说明resend成功了,你可以在两分钟后再次查看你的余额。

如果它返回了下图中的“Error”,请点击第一条交易记录的“Detail”并保存。将上述信息发送给我们(op@pchain.org)。我们将在1~2个工作日内会帮助你恢复这条交易。

_images/recover61.png

如何重新同步pchain?

如果你遇到了badblock的问题, 你需要重新同步块.

首先把除了priv_validator.json和nodekey之外的文件都删掉,删除之后你的datadir应该是这样的结构:

datadir/
-nodekey
-pchain/
        -priv_validator.json
        -keystore/

如果你同时还在跑子链,你的datadir应该时这样的结构:

datadir/
-nodekey
-pchain/
        -priv_validator.json
        -keystore/
-child_0/
                -priv_validator.json
                -genesis.json
                -eth_genesis.json
                -keystore/

确保你的目录结构如上所示以后,可以开始重新同步,如果你跑了子链,记得先初始化:

cd ~/pchain
./bin/pchain --datadir=~/pchain/.pchain init ~/pchain/.pchain/child_0/eth_genesis.json child_0
./run.sh

如果你只跑了主链,直接运行run.sh即可

cd ~/pchain
./run.sh

如果总是遇到bad block的问题该怎么办?

pchain官方提供了一个数据包,请备份好你的priv_validator.json和keystore文件后按照以下步骤操作:

1.暂停crontab

crontab -e

然后选择你熟悉的编辑器将文件中的两行内容用‘#’注释掉,像这样:

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

保存好以后退出。

2.下载官方数据包

如果你只跑了主链:

cd ~/pchain
wget https://pchainblockdata.s3-us-west-2.amazonaws.com/blockData.tar.gz

如果你跑了主链和子链:

cd ~/pchain
wget https://pchainblockdata.s3-us-west-2.amazonaws.com/blockDataWithChild.tar.gz

3.停止pchain进程

killall pchain

4.删除你的datadir(请务必确定你已备份好priv_validator.json和keystore文件)

rm -r .pchain

5.替换官方数据包

如果你只跑了主链:

cd ~/pchain
tar -xzf blockData.tar.gz

如果你跑了主链和子链:

cd ~/pchain
tar -xzf blockDataWithChild.tar.gz

6.放置你的priv_validator.json

如果你只跑了主链:

cp youpathway/priv_validator.json ~/pchain/.pchain/pchain/

如果你跑了主链和子链:

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

7.重启pchain

./run.sh

8.查看是否在继续同步

./bin/pchain attach .pchain/pchain/pchain.ipc
>pi.blockNumber

9.重新开启crontab

crontab -u yourusername ~/pchain/scripts/pchain.cron