# Install

## DN-focused Setup Guide&#x20;

### System Preparation

```bash
sudo apt update && sudo apt upgrade -y
sudo apt install -y \
  curl git make wget clang pkg-config libssl-dev build-essential \
  apt-transport-https gnupg cmake protobuf-compiler lz4
```

***

### Install Rust and Required Toolchains

```bash
curl https://sh.rustup.rs -sSf | sh -s -- -y
source $HOME/.cargo/env

rustup update
rustup component add rust-src
rustup target add wasm32-unknown-unknown

rustup install nightly-2024-01-21
rustup target add wasm32-unknown-unknown --toolchain nightly-2024-01-21
```

***

### Build Polkadot SDK

```bash
cd ~
git clone https://github.com/paritytech/polkadot-sdk.git
cd polkadot-sdk
git checkout polkadot-stable2509-2

cargo build --release
```

***

### Install Binaries

```bash
sudo mkdir -p /usr/lib/polkadot
sudo cp target/release/polkadot* /usr/lib/polkadot/
sudo ln -sf /usr/lib/polkadot/polkadot /usr/local/bin/polkadot
```

***

### Create Working Directory

```bash
mkdir -p $HOME/.polkadot
chown -R $(id -u):$(id -g) $HOME/.polkadot
```

***

### **Warp Sync for DN**

Warp Sync drastically speeds up initial boot:

**Required flag:**

```
--sync warp
```

**Recommended DB for DN:**

```
--database paritydb
```

ParityDB is more stable under DN workloads.

***

### Full Production-Ready systemd Service

```bash
current_user=$(whoami)
STARTNAME="DN_Node_Name"

sudo tee /etc/systemd/system/polkadot.service > /dev/null <<EOF
[Unit]
Description=Polkadot Dedicated Node (DN)
After=network.target
Wants=network-online.target

[Service]
Type=simple
User=$current_user
WorkingDirectory=$HOME/.polkadot
ExecStart=/usr/local/bin/polkadot \
  --validator \
  --name "$STARTNAME" \
  --chain polkadot \
  --database paritydb \
  --sync warp \
  --state-pruning 64 \
  --blocks-pruning 64 \
  --base-path $HOME/.polkadot \
  --public-addr /ip4/$(wget -qO- eth0.me)/tcp/30333 \
  --port 30333 \
  --rpc-port 9933 \
  --rpc-cors all \
  --rpc-methods Unsafe \
  --prometheus-external \
  --prometheus-port 9615 \
  --telemetry-url "wss://telemetry-backend.w3f.community/submit/ 1" \
  --telemetry-url "wss://telemetry.polkadot.io/submit/ 0" \
  --unsafe-force-node-key-generation
Restart=always
RestartSec=10
LimitNOFILE=1000000
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target
EOF
```

***

### Start & Verify

```bash
sudo systemctl daemon-reload
sudo systemctl enable polkadot
sudo systemctl restart polkadot
sudo journalctl -u polkadot -f
```

***

### **Safe Upgrades for DN (Atomic Upgrade Path)**

Never overwrite the binary directly.\
Use *Staged Atomic Upgrade*:

**Build new binary:**

```bash
cd ~/polkadot-sdk
git fetch --all
git checkout <new-tag>
cargo build --release
```

**Put new binaries in staging:**

```bash
sudo mkdir -p /usr/lib/polkadot-upgrade
sudo cp target/release/polkadot* /usr/lib/polkadot-upgrade/
```

**Validate new binary:**

```bash
/usr/lib/polkadot-upgrade/polkadot --version
```

**Atomic swap:**

```bash
sudo systemctl stop polkadot
sudo rsync -av --delete /usr/lib/polkadot-upgrade/ /usr/lib/polkadot/
sudo systemctl start polkadot
```

**Verify:**

```
sudo journalctl -u polkadot -n 150 --no-pager
```

***

### **High Availability (HA) DN Architecture**

### Minimal HA Design

```
             +----------------+
             |     RPC Node   |
             |   (Read-only)  |
             +-------+--------+
                     |
      +--------------+--------------+
      |                             |
+-----+--------+          +---------+-----+
|  Validator A |          | Validator B   |
|   (Primary)  |          |   (Backup)    |
+--------------+          +---------------+
       \          Sentry Nodes          /
        +------------+  +--------------+
```

#### Sentry node

```
--no-telemetry
--no-prometheus
--reserved-peers <validator-ip>
```

#### DN Failover Procedure:

Normally:

* Validator B runs with **--no-validate**
* If Validator A goes offline, B becomes active:

```
sudo systemctl stop polkadot   # on A
sudo systemctl restart polkadot --validator   # on B
```

Can be automated with keepalived or pacemaker.

***

## **Troubleshooting Guide**

#### Node not starting after upgrade

```
sudo journalctl -u polkadot -n 100
```

Try full sync:

```bash
polkadot --sync full --database paritydb
```

#### RocksDB corruption errors

Switch to ParityDB:

```
--database paritydb
```

#### Node not visible in Telemetry

Check external IP:

```bash
wget -qO- eth0.me
```

Open port:

```
sudo ufw allow 30333
```

#### Poor synchronization speed

Enable compiled WASM:

```
--wasm-execution compiled
```

#### Drop in peers

Increase limits:

```
--in-peers 500
--out-peers 500
```

***

#### Monitoring (Prometheus + Grafana)

Prometheus endpoint:

```
http://<node-ip>:9615/metrics
```

Key metrics:

* substrate\_block\_height
* substrate\_sync\_target
* substrate\_peers\_count
* substrate\_block\_import


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.chaindigital.tech/mainnets/polkadot/install.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
