Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Polkadot Wiki Migration] Set up a Bootnode #34

Merged
merged 10 commits into from
Oct 9, 2024
1 change: 1 addition & 0 deletions infrastructure/general/.pages
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
title: General Infrastructure
nav:
- index.md
- setup-bootnode.md
94 changes: 94 additions & 0 deletions infrastructure/general/setup-bootnode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
---
title: Set up a Boot Node
description: Instructions on setting up, testing, maintaining, and testing a boot node.
eshaben marked this conversation as resolved.
Show resolved Hide resolved
---

!!!note
eshaben marked this conversation as resolved.
Show resolved Hide resolved
When you first start a node, it has to find a way to find other nodes in the network. For that
purpose, you need "bootnodes". After the first bootnode is found, it can use that node’s connections
to continue expanding and play its role in the network, like participating as a validator.

<!-- TODO: link wss guide wherever applicable. -->

## Accessing the Bootnode
dawnkelly09 marked this conversation as resolved.
Show resolved Hide resolved

The consensus is that bootnodes have to be accessible in three ways:

- **P2P**: the p2p port, which can be set by `--listen-addr /ip4/0.0.0.0/tcp/<port>`. This port is
not automatically set on a non-validator node (for example, an archive RPC node)
- **P2P/WS**: the WebSocket version, which can be set by `--listen-addr /ip4/0.0.0.0/tcp/<port>/ws`
- **P2P/WSS**: the _secure_ websocket version. An SSL-secured connection to the p2p/ws port must be
dawnkelly09 marked this conversation as resolved.
Show resolved Hide resolved
CrackTheCode016 marked this conversation as resolved.
Show resolved Hide resolved
dawnkelly09 marked this conversation as resolved.
Show resolved Hide resolved
achieved by a proxy since the node cannot include certificates. It is needed for light clients.

## Network Key

Starting a node creates its node key in the `chains/<chain>/network/secret_ed25519` file. You can
CrackTheCode016 marked this conversation as resolved.
Show resolved Hide resolved
also create a node-key by `polkadot key generate-node-key` and use that node-key in the startup
command line.

It is essential you backup the node key, especially if it gets included in the polkadot binary
CrackTheCode016 marked this conversation as resolved.
Show resolved Hide resolved
because it gets hardcoded in the binary and needs to be recompiled to change.
dawnkelly09 marked this conversation as resolved.
Show resolved Hide resolved
dawnkelly09 marked this conversation as resolved.
Show resolved Hide resolved

## Running the Bootnode
dawnkelly09 marked this conversation as resolved.
Show resolved Hide resolved

Say we are running a Polkadot node with:
CrackTheCode016 marked this conversation as resolved.
Show resolved Hide resolved
dawnkelly09 marked this conversation as resolved.
Show resolved Hide resolved

```
polkadot --chain polkadot --name dot-bootnode --listen-addr /ip4/0.0.0.0/tcp/30310 --listen-addr /ip4/0.0.0.0/tcp/30311/ws
```

You would have the p2p on port 30310 and p2p/ws on port 30311. For the p2p/wss port, we need to
dawnkelly09 marked this conversation as resolved.
Show resolved Hide resolved
CrackTheCode016 marked this conversation as resolved.
Show resolved Hide resolved
set up a proxy, a DNS name, and a corresponding certificate. These concepts and example setups are
dawnkelly09 marked this conversation as resolved.
Show resolved Hide resolved
described here. The following example is for the popular nginx server and enables p2p/wss on port 30312 by proxying the p2p/ws
dawnkelly09 marked this conversation as resolved.
Show resolved Hide resolved
dawnkelly09 marked this conversation as resolved.
Show resolved Hide resolved
dawnkelly09 marked this conversation as resolved.
Show resolved Hide resolved
dawnkelly09 marked this conversation as resolved.
Show resolved Hide resolved
port 30311:

_/etc/nginx/sites-enabled/dot-bootnode_

```
server {
listen 30312 ssl http2 default_server;
server_name dot-bootnode.stakeworld.io;
root /var/www/html;

ssl_certificate "<your_cert";
ssl_certificate_key "<your_key>";

location / {
proxy_buffers 16 4k;
proxy_buffer_size 2k;
proxy_pass http://localhost:30311;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
}

}
```
eshaben marked this conversation as resolved.
Show resolved Hide resolved

## Testing Bootnode Connection
dawnkelly09 marked this conversation as resolved.
Show resolved Hide resolved

If we have the above node running with DNS name `dot-bootnode.stakeworld.io`, proxied with a valid
CrackTheCode016 marked this conversation as resolved.
Show resolved Hide resolved
dawnkelly09 marked this conversation as resolved.
Show resolved Hide resolved
CrackTheCode016 marked this conversation as resolved.
Show resolved Hide resolved
dawnkelly09 marked this conversation as resolved.
Show resolved Hide resolved
dawnkelly09 marked this conversation as resolved.
Show resolved Hide resolved
dawnkelly09 marked this conversation as resolved.
Show resolved Hide resolved
certificate and node-id `12D3KooWAb5MyC1UJiEQJk4Hg4B2Vi3AJdqSUhTGYUqSnEqCFMFg` then the following
commands should give you a: "syncing 1 peers".
CrackTheCode016 marked this conversation as resolved.
Show resolved Hide resolved

!!!tip
You can add `-lsub-libp2p=trace` on the end to get libp2p trace logging for debugging purposes.

### P2P

```bash
polkadot --chain polkadot --base-path /tmp/node --name "Bootnode testnode" --reserved-only --reserved-nodes "/dns/dot-bootnode.stakeworld.io/tcp/30310/p2p/12D3KooWAb5MyC1UJiEQJk4Hg4B2Vi3AJdqSUhTGYUqSnEqCFMFg" --no-hardware-benchmarks
eshaben marked this conversation as resolved.
Show resolved Hide resolved
```

### P2P/WS

```bash
polkadot --chain polkadot --base-path /tmp/node --name "Bootnode testnode" --reserved-only --reserved-nodes "/dns/dot-bootnode.stakeworld.io/tcp/30311/ws/p2p/12D3KooWAb5MyC1UJiEQJk4Hg4B2Vi3AJdqSUhTGYUqSnEqCFMFg" --no-hardware-benchmarks
eshaben marked this conversation as resolved.
Show resolved Hide resolved
```

### P2P/WSS
dawnkelly09 marked this conversation as resolved.
Show resolved Hide resolved

```bash
polkadot --chain polkadot --base-path /tmp/node --name "Bootnode testnode" --reserved-only --reserved-nodes "/dns/dot-bootnode.stakeworld.io/tcp/30312/wss/p2p/12D3KooWAb5MyC1UJiEQJk4Hg4B2Vi3AJdqSUhTGYUqSnEqCFMFg" --no-hardware-benchmarks
eshaben marked this conversation as resolved.
Show resolved Hide resolved
```
Loading