# Notes

Arrows will mark the places where your input is needed

# Update system

Update Your System: Before installing any new software,
it's a good practice to update your system's package list and
upgrade the existing packages to their latest versions.

```bash
sudo apt update
sudo apt upgrade
```

# Firewall

Install Ubuntu firewall
```bash
sudo apt install ufw
```

If you want to connect to your node-machine, allow connection to the SSH port
```bash
sudo ufw allow ssh
```
![images/img.png](images/img.png)

Enable firewall, confirm the operation
```bash
sudo ufw enable
```
![images/img_1.png](images/img_1.png)

Check firewall status. You should see `Status: active`
```bash
sudo ufw numbered
```
![images/img_2.png](images/img_2.png)

# SSH
## Install SSH

Once you have installed the proper Operating System on you machine
we recommend that you enable SSH. Most people have a Daily Driver machine.
GHOST requires a separate machine. Adding an extra machine to your life could be cumbersome.
Chances are you had to use an external monitor to install Ubuntu on GHOST Node,
the same screen regularly used by the Daily Driver machine.
SSH enables you to manage your GHOST Nodes remotely from the comfort of your Daily Driver.

Install OpenSSH Server: With your system updated, the next step is to install
the OpenSSH server package. This package contains the necessary software to run
an SSH server.

```bash
sudo apt install openssh-server
```

Start SSH Service using _systemctl_.

```bash
sudo systemctl start ssh
```

Enable SSH Service to Start on Boot: To ensure that the SSH service automatically
starts after a reboot, you need to enable it using _systemctl_.

```bash
sudo systemctl enable ssh
```

To check the status of the SSH service, run the following command:

```bash
sudo systemctl status ssh
```

You should be seeing something like this:

![images/img_3.png](images/img_3.png)

## Connect by SSH

With SSH enabled and the firewall configured, you can now connect
to your node machine from another computer using SSH.
You have to know your username and your local network ip

```bash
ssh [username]@[your_server_ip_OR_hostname]
```

# Install GHOST Application
## Allow Ports
Allow `port 30333` on GHOST Node:
```bash
sudo ufw allow 30333
```
![images/img_5.png](images/img_5.png)

To ensure that the ports are allowed, run the following command:
```bash
sudo ufw numbered
```
![images/img_6.png](images/img_6.png)

## Install Substrate Libraries
Click [here](https://docs.substrate.io/install/linux/) for a detailed Rust guide if you want to dive deep into the documentation. Otherwise let's proceed.

### Install Dependencies
Check the documentation for your operating system for information about
the packages that are installed and how to download and install
any additional packages you might need. For example,
if you use Debian/Ubuntu, you can use the Advanced Packaging Tool (apt)
to install packages:

```bash
sudo apt install -y build-essential clang curl git make libssl-dev protobuf-compiler llvm libudev-dev
```

### Rust Install

Download the rustup installation program and use it to install Rust by running the following command:
```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```

Press Enter for using default options:

![images/img_7.png](images/img_7.png)

Update your current shell to include Cargo by running the following command:
```bash
source $HOME/.cargo/env
```

Verify your installation by running the following command:
```bash
rustc --version
```

You should see something like this:

![images/img_8.png](images/img_8.png)

Configure the Rust toolchain to default to the latest stable version by running the following commands:
```bash
rustup default stable
```
```bash
rustup update
```

```bash
rustup target add wasm32-unknown-unknown --toolchain stable
```

Verify the configuration of your development environment by running
the following command:
```bash
rustup show
```

You should see something like this:

![images/img_9.png](images/img_9.png)
![images/img_10.png](images/img_10.png)

Now run:
```bash
rustup component add rust-src --toolchain stable
```

## Install GHOST

Check if Git is already installed:
```bash
git --version
```
![images/img_11.png](images/img_11.png)

Make a GHOST Directory and go to it:
```bash
mkdir ~/ghost && cd ~/ghost
```

Clone GHOST Node Git:
```bash
git clone https://git.ghostchain.io/ghostchain/ghost-node.git
```

Go to ghost-node directory:
```bash
cd ghost-node
```

Compile the node template by running the following command:
```bash
./scripts/starter.sh --release
```

The build can take up to 20 minutes depending on the specifications of your machine.

![images/img_12.png](images/img_12.png)


# Boot Node Qualification

## Boot Node Qualification Test

Becoming a Boot Node on GHOST Chain is an absolute MUST if we want the network
to be sufficiently decentralized. However, due to certain ISP limitations
some countries make it being a Boot Node easier than others.
Hence, the GHOST Dev team came up with a Boot Node Qualification Test.

First we should install TRACEROUTE:
```bash
sudo apt install traceroute
```

Then we must determine the public IP for your GHOST Node Machine.

```bash
curl -4 icanhazip.com
```
![images/img_13.png](images/img_13.png)

Then type the following command replacing `<YOUR_IP_FROM_PREVIOUS_STEP>` with an actual IP address from previous step:
```bash
traceroute <YOUR_IP_FROM_PREVIOUS_STEP>
```

If your GHOST Node is **not behind a NAT** your terminal window should look something like this:

![images/img_14.png](images/img_14.png)

If your GHOST Node is **behind NAT** your terminal window should look something like this:

![images/img_15.png](images/img_15.png)

If your GHOST Node is NOT behind the NAT then your node can be a Boot Node.
If your GHOST Node is behind the NAT then your node CANNOT be a Boot Node
and you will have to use some kind of proxy to rectify the situation.

Afterwards, post the screenshot of your terminal window in the Whales group.
Feel free to blur out your IP.

## Setting Proper Firewall Rules

You must enable `port 30333` on your router

Based on prior instructions you may have configured your firewall in way that is
no longer needed. For the purpose of GHOST Chain you should only
open `port 30333` and close other ports.

### Checking Firewall

Check the ports that are opened on your firewall:
```bash
sudo ufw numbered
```
![images/img_16.png](images/img_16.png)

If `port 9945` is opened then close it:
```bash
sudo ufw deny 9945
```

### Configuring Router

Enable port forwarding for port 30333 on your router. Be mindful that different networks and routers have different ways of setting this up. It is best to search for portforwarding instruction for the specific router model.

![images/img_17.png](images/img_17.png)

### Checking Ports
Simulate a broadcasting node by running a dummy GHOST Node launch command:
```bash
./target/release/ghost --port=30333 --rpc-port=9945 --chain=dev --node-key=0000000000000000000000000000000000000000000000000000000000000001 --base-path=/tmp/alice --alice --validator --unsafe-rpc-external --no-telemetry --state-pruning=archive
```

To check ports go to [Port Checker Website](https://dnschecker.org/port-scanner.php) and check following ports:
```
30333, 9945
```

Only `port 30333` should be opened.

![images/img_18.png](images/img_18.png)

Press _CTRL+C_ to stop the node.

# Launching GHOST TestNet

Switch to main GIT branch:
```bash
git switch main
```

Make sure `ghost-node` is up to date:
```bash
git pull origin main
```

## Generating keys
Create ghost configuration directory:
```bash
sudo mkdir /etc/ghost
```

Give the user permission to the directory:
```bash
sudo chown $(whoami) /etc/ghost
```

To generate the node key use the following command:
```bash
./target/release/ghost key generate-node-key --bin --file=/etc/ghost/node-key
```

Feel free to backup the file on a separate storage device.

## Build and start the ghost-node

Recompile `ghost-node` using `starter.sh` and `--release` flag.
Make `ghost-node` service being able to be started by default user
using `--make-global`:
```bash
./scripts/starter.sh --release --make-global
```

We need to recompile so type y and press Enter to proceed:

![images/img_20.png](images/img_20.png)

Recompiling will take some time!

The script needs higher permissions to write the ghost-node startup file, so it may ask for your user's password

![images/img_21.png](images/img_21.png)

![images/img_28.png](images/img_28.png)

Check the hash of the build:
```bash
sha256sum /etc/ghost/casper.json
```

You should see:
```
9da6045ed6d4fd844e3939573b31c013d0e564e542029330faa6d978cb4a915a
```

Create running `ghost-node` service that starts on system boot using `--unit-file` flag.
And we must set up the `ghost-node` launch command by setting arguments using
`--set-arguments` flag:
```bash
./scripts/starter.sh --unit-file --set-arguments
```

Only change the defaults if you are advanced otherwise press _Enter_ for
the following prompts.

If this is your first node simply press _Enter_ to proceed with the default.
If this is your second node you should type a different port here,
for example `30334`, and then you should open this port on your firewall
and create a dedicated port forwarding rule on your router as specified
in the Testing Connectivity Part:
```
specify p2p protocol TCP port (default: 30333): 30334
```

To choose default options press Enter here:

![images/img_30.png](images/img_30.png)

If you want to validate from this node press Enter:
```
disable validator mode? [y/N]: y
```
![images/img_31.png](images/img_31.png)

Press _Enter_ for reject enabling Prometheus:

![images/img_32.png](images/img_32.png)

For the following prompt:
```
list of bootnodes if any:
```

Paste one of available **Boot Node** addresses.

Official **Boot Node** addresses:
```
/dns/bootnode69.chain.ghostchain.io/tcp/30334/p2p/12D3KooWF9SWxz9dmy6vfndQhoxqCa7PESaoFWEiF8Jkqh4xKDRf
```
```
/dns/bootnode70.chain.ghostchain.io/tcp/30333/p2p/12D3KooWP3h5dSdqcpvsCr7fp1jyfqDj291QDZ68a4gY6VQ8T1nW
```

A full list of available **Boot Nodes** can be found on [the guide page](https://blog.ghostchain.io/launching-ghost-testnet-3-1/#Boot_Node).

![images/img_33.png](images/img_33.png)

Press _Enter_:

![images/img_34.png](images/img_34.png)

Changing `unit-file` name is optional, otherwise press _Enter_:

![images/img_35.png](images/img_35.png)

Type `y` and press _Enter_ for create dedicated user for running `ghost-node`:

![images/img_36.png](images/img_36.png)

**DO NOT start and DO NOT enable** `ghost-node.service` (press _Enter_):

![images/img_37.png](images/img_37.png)

Full Node:

![images/img_38.png](images/img_38.png)

Validator Node:

![images/img_39.png](images/img_39.png)

Start `ghost-node`:
```bash
sudo systemctl start ghost-node
```

Wait ~60 seconds!

Check node is started:
```bash
sudo systemctl status ghost-node
```
![images/img_40.png](images/img_40.png)

For exit press _CTRL+C_

Restart `ghost-node`:
```bash
sudo systemctl restart ghost-node
```

Enable `ghost-node`:
```bash
sudo systemctl enable ghost-node
```
![images/img_41.png](images/img_41.png)

To see the logs produced by your `ghost-node`:
```bash
journalctl -f -u ghost-node
```

To exit press _CTRL+C_.

Congratulations! You have an operational GHOST Node.
