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 RPC node #32

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 33 additions & 45 deletions infrastructure/general/setup-rpc.md
Original file line number Diff line number Diff line change
@@ -1,78 +1,66 @@
---
title: Set up an RPC node
description: Learn how to configure set up, secure, and maintain an RPC node in an archival or pruned state (and know the difference between the two).
title: Set Up an RPC Node
description: Learn how to securely configure, connect to, and maintain a Polkadot SDK-based RPC node in an archival or pruned state.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description: Learn how to securely configure, connect to, and maintain a Polkadot SDK-based RPC node in an archival or pruned state.
description: Learn how to securely configure, connect to, and maintain an RPC node for a Polkadot SDK-based blockchain in an archival or pruned state.

This was a tad bit short

---

The RPC server (included in all Polkadot SDK node implementations) can be accessed over the WebSocket protocol, which can be used to access the underlying network and/or validator node. By default, you can access your node's RPC
server from `localhost` (for example, to rotate keys or do other maintenance). To access it from
another server or an applications UI (such as [Polkadot.js](https://polkadot.js.org/apps){target=_blank}) it is
recommended to enable access to the RPC node over an SSL connection and encrypt the connection
between the end user and the RPC server. This can be achieved by setting up a secure proxy. Many
browsers, such as Google Chrome, will block non-secure WS endpoints if they come from a different
origin.
# Set Up an RPC Node

## Introduction

Setting up an RPC node is crucial for accessing and interacting with the Polkadot network. This tutorial will guide you through configuring, securing, and maintaining an RPC node in an archival or pruned state. An RPC node allows you to query blockchain data, interact with dApps, or manage network tasks remotely. You'll learn about the differences between archive and pruned nodes, how to secure the WebSocket connection, and the steps necessary to safely expose and maintain your node's RPC server for external access.

All Polkadot SDK node implementations include the RPC server, which are accessed over the WebSocket protocol and used to connect to the underlying network or validator node. By default, you can access your node's RPC server from `localhost` (for example, to rotate keys or do other maintenance). You should set up a secure proxy when accessing your RPC server from another server or [Polkadot.js](https://polkadot.js.org/apps){target=\_blank} and only enable access to the RPC node over an encrypted, SSL connection between the end user and the RPC server. Many browsers, such as Google Chrome, will block non-secure WS endpoints if they come from a different origin.

!!!warning
Enabling remote access to your validator node shouldn't be necessary and isn't suggested, as it
can often lead to security problems. Learn more about node security in [Secure Your Validator](todo:link).

## Set Up a Node

Setting up any Polkadot SDK-based node relies on a similar process. For example, by default, they will
all share the same WebSocket connection at port 9944 on localhost. In this example, you'll set up a
Polkadot sync node on a Debian-flavored server (such as Ubuntu 22.04). Create a new server on your
provider of choice or locally at home. See [Set up a Full Node](todo:link){target=_blank} for additional
instructions. You can install from the default apt repository or build from scratch. The startup
options in the setup process provide various settings that can be modified.
Setting up a Polkadot SDK-based node follows a straightforward process. By default, all nodes use port 9944 on localhost for the WebSocket connection. In this guide, you'll set up a Polkadot sync node on a Debian-based server (e.g., Ubuntu 22.04). You can either create a server with your preferred provider or set one up locally. Check out [Set up a Full Node](TODO: add path){target=\_blank} for detailed instructions on installation.

To make the node externally accessible as an archive or pruned RPC node, use the following commands:

A typical setting for an externally accessible Polkadot archive RPC node would be:
For an externally accessible Polkadot archive RPC node:

```config
polkadot --chain polkadot --name myrpc --state-pruning archive --blocks-pruning archive --rpc-max-connections 100 --rpc-cors all --rpc-methods Safe --rpc-port 9944
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
polkadot --chain polkadot --name myrpc --state-pruning archive --blocks-pruning archive --rpc-max-connections 100 --rpc-cors all --rpc-methods Safe --rpc-port 9944
polkadot --chain polkadot \
--name INSERT_YOUR_NODE_NAME \
--state-pruning archive \
--blocks-pruning archive \
--rpc-cors all \
--rpc-methods safe

I just removed the few that were set to default values

```

Or for a Polkadot pruned RPC node:
For a Polkadot pruned RPC node:

```config
polkadot --chain polkadot --name myrpc --state-pruning 1000 --blocks-pruning archive --rpc-max-connections 100 --rpc-cors all --rpc-methods Safe --rpc-port 9944
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
polkadot --chain polkadot --name myrpc --state-pruning 1000 --blocks-pruning archive --rpc-max-connections 100 --rpc-cors all --rpc-methods Safe --rpc-port 9944
polkadot --chain polkadot \
--name INSERT_YOUR_NODE_NAME \
--state-pruning 1000 \
--blocks-pruning archive \
--rpc-cors all \
--rpc-methods safe

```

The specified flag options are outlined in greater detail below.
The options and flags will be explained in the following sections.

### Archive Node vs. Pruned Node
### Pruned Node vs. Archive Node

A pruned node only keeps a limited number of finalized blocks of the network, not its full history.
Most frequently required actions can be completed with a pruned node, such as displaying account
balances, making transfers, setting up session keys, staking, etc. An archive node has the full
history (database) of the network. It can be queried in various ways, such as providing historical
information regarding transfers, balance histories, and more advanced queries involving past events.
A pruned node only keeps a limited number of finalized blocks of the network, not its full history. State and block pruning are two ways of removing old blocks from a system. State pruning removes the states of old blocks while preserving block headers, allowing you to query against headers and hashes but not key-value pairs from the state trie. Block pruning removes the block bodies of old blocks while retaining block headers, allowing you to query against block headers and hashes but not the block body. You can complete many frequently required actions with a pruned node, such as displaying account balances, making transfers, setting up session keys, and staking.
dawnkelly09 marked this conversation as resolved.
Show resolved Hide resolved

An archive node requires a lot more disk space. At the start of April 2023, Polkadot disk usage was
160 GB for a pruned node and 1 TB for an archive node. This value will increase with time. For an
archive node, you need the options `--state-pruning archive --blocks-pruning archive` in your
startup settings.
An archive node has the entire history, or database, of the network. You can query it in various ways, such as looking for historical information regarding transfers, balance histories, and more advanced queries involving past events. An archive node requires a lot more disk space than a pruned node. As of April 2023, Polkadot disk usage was 160 GB for a pruned node and 1 TB for an archive node. Disk usage needs can be expected to increase over time. An archive node requires including the options `--state-pruning archive --blocks-pruning archive` in your startup settings.

### Secure the RPC Server
## Secure the RPC Server

The node startup settings allow you to choose _what_ to expose, _how many_ connections to expose
and from where access should be granted through the RPC server.
The node startup settings allow you to choose what to expose, how many connections to expose and which systems should be granted access through the RPC server.

- _How many_ - You can set your maximum connections through `--rpc-max-connections`, for example
`--rpc-max-connections 100`
- _From where_ - by default, localhost and Polkadot.js can access the RPC server. You can change this by setting `--rpc-cors`, to allow access from everywhere you need `--rpc-cors all`
- _What_ - You can limit the methods to use with `--rpc-methods`, an easy way to set this to a safe
- You can limit the methods to use with `--rpc-methods`, an easy way to set this to a safe
mode is `--rpc-methods Safe`
- You can set your maximum connections through `--rpc-max-connections`, for example
`--rpc-max-connections 100`
- By default, localhost and Polkadot.js can access the RPC server. You can change this by setting `--rpc-cors`. To allow access from everywhere you can use `--rpc-cors all`

### Secure the WebSocket Port
## Secure the WebSocket Port

To safely access your WebSocket (WS) connection over an SSL-enabled connection (needed for any SSL-enabled developer console), you
have to convert the WS connection to a secure (WSS) connection by using a proxy and an SSL
certificate, you can find instructions on [Setup Secure WebSockets](todo:link){target=_blank}.
To securely access your WebSocket (WS) connection over an SSL-enabled connection (necessary for SSL-enabled developer consoles), you'll need to convert the WS connection to a secure WSS connection. You can complete this conversion using a proxy and an SSL certificate. For detailed steps on setting this up, refer to the [Setup Secure WebSockets](TODO: add path){target=_blank} guide.

## Connecting to the Node
## Connect to the Node

Open [Polkadot.js](https://polkadot.js.org/apps){target=_blank} and click the logo in the top left to switch the
node. Activate the "Development" toggle and input your node's address - either the domain or the IP
address. Remember to prefix with `wss://`, and if you're using the 443 port, append `:443` like so:
`wss://example.com:443`.
Open [Polkadot.js](https://polkadot.js.org/apps){target=\_blank} and click the logo in the top left to switch the node. Activate the **Development** toggle and input your node's domain or IP address. Remember to prefix with `wss://`, and if you're using the 443 port, append `:443` as follows:

```bash
`wss://example.com:443`
```

![A sync-in-progress chain connected to Polkadot.js UI](/images/infrastructure/general/maintain-wss.webp)
![A sync-in-progress chain connected to Polkadot.js](/images/infrastructure/general/maintain-wss.webp)