# Node Status

<figure><img src="https://3714373443-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MRCF092Z3_9ouKsNgIF-3369173170%2Fuploads%2F8A9YbixAkAC48ieoCpaW%2F536668240951535477.jpg?alt=media&#x26;token=2d62bf31-0e40-4799-b62e-046b8be3e73a" alt=""><figcaption></figcaption></figure>

## How to check if your node is still running?

Attach to your server, and run the 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
```

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

if you want to check the main chain:

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

if you want to check the subchain:

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

it will return the latest block on your node, and then check if the height is the same as our [Monitor](https://monitor.pchain.org/).

## 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](https://github.com/pchain-org/pchain/releases).

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.

## How to check if your node is syncing?

if you want to check the main chain:

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

if you want to check the subchain:

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

if it returns true, your node is syncing now. Also, you can type `pi.blockNumber` every min to check if the height is growing continuously. If so, your node is syncing.

If your node has not synchronized block until 10 minutes, please have a try:

```
admin.addPeer("enode://f80cbf2d54224f7f36baab85cf3ac121086b032ac3e8ac743c3064697e014bad205321ab5ec6623bc55a0cf85b697c326aa471d8e4db84a6faaac51ca8e7e447@44.228.45.164:30308")
admin.addPeer("enode://0e6d8da2ee8701601c75970cb1690f6255ec6c6ae97251c8e4c55051cf1d59a2bf9b2dc9cbc83a4f51deaa798d1d9406c8c342a506fb9f431e4ee14659b1f18d@15.207.188.58:30308")
admin.addPeer("enode://2490cf0f0cdc18ef363f846ca7565664512f46a5b875c5ad654a9f569ce91eb29369723f6639dd416f5fb41b8f1270e8dab94db65be0a056f7cf9d1f816ec12f@13.49.131.60:30308")
```

## How to check if my node is validating blocks?

Go to [piscan](https://piscan.pchain.org/miner.html), 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.

## 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”.

## What are the hardware requirements to run a node on Pchain?

[Server Requirement](https://pchaindoc.readthedocs.io/en/latest/pchainclient/requirement.html#requirement)

## Can I run the main chain and subchain on one machine?

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

## How to migrate my Pchain to another computer?

If you want to migrate your pchain to another computer, just install pchain on your new computer, and copy priv\_validator.json and the nodekey to your new computer.

## How to check if my node is 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.

## How to check your node status when running on Pchain?

[Flow and FAQ of becoming a validator](flow-and-faq-on-becoming-a-validator)

## How many tokens do I need to run a node on Pchain?

You need to 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.

## How to resync pchain from block 0?

If you run into bad block issue then you should 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 subchain, 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 initialize subchain 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
```

## What should I do if I got bad blocks often?

pchain supplies 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 subchain 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 subchain 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 subchain 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
```

## How to resolve handle crash on subchain?

If you got the error on the subchain like the following two screens, it means the handle crashed due to the number of handles increased. Please follow the steps below to recover it.&#x20;

![](https://pchaindoc.readthedocs.io/en/latest/_images/handlecrash1.png)

![](https://pchaindoc.readthedocs.io/en/latest/_images/handlecrash2.png)

Run &#x20;

```
cat /proc/sys/fs/file-max 
```

&#x20;to check the maximum number of files.

Run&#x20;

```
sudo vi /etc/security/limits.conf
```

&#x20;to set file number (should be less than or equal to the max number of files above).

* soft nofile 512000
* hard nofile 512000

Run&#x20;

```
sudo vi /etc/pam.d/common-session
```

and enter `session required pam_limits.so`

Run&#x20;

```
sudo vi /etc/profile 
```

and enter `ulimit -SHn 512000 ulimit -v unlimited`

Click this [link](https://medium.com/@muhammadtriwibowo/set-permanently-ulimit-n-open-files-in-ubuntu-4d61064429a) for Reference for Ubuntu system on setting the number of files to recover the handle crash.
