11# Quick Setup
22
331 . * (Skip this step if you run the Chainweb node in data center.)* Log into your
4- router and configure port forwarding for port 443 to your computer.
4+ router and configure port forwarding for port 1789 to your computer.
55
6- 2 . Make sure that your firewall allows incoming connection on port 443 .
6+ 2 . Make sure that your firewall allows incoming connection on port 1789 .
77
883 . Initialize database * (optional but saves several hours of db synchronization
99 on node startup.)* :
1010
11+ First you need a database snapshot URL. See below, how to obtain a database
12+ snapshot.
13+
1114 ``` sh
12- docker run -ti --rm -v chainweb-data:/data kadena/chainweb-node /chainweb/initialize-db.sh
15+ docker run -ti --rm -e DBURL=YOUR_DB_SNAPSHOT_URL - v chainweb-data:/data kadena/chainweb-node /chainweb/initialize-db.sh
1316 ```
1417
15184. Start Chainweb node:
1619
1720 ` ` ` sh
18- docker run -d -p 443:443 -v chainweb-data:/data kadena/chainweb-node
21+ docker run -d -p 1789:1789 -p 1848:1848 -v chainweb-data:/data kadena/chainweb-node
1922 ` ` `
2023
2124For explanations and additional configuration options (like, for instance, using
@@ -32,24 +35,40 @@ For instance AWS EC2 t3a.medium VMs with 50GB SSD root storage are known to work
3235
3336# Running a Chainweb Node as Docker Container
3437
38+ A Chainweb node serves two separate APIs:
39+
40+ 1. The P2P API includes all endpoints that are used for node-to-node
41+ communication. It is served via HTTPS and must be reachable from the public
42+ internet.
43+
44+ 2. The Service API includes all routes that off Kadena chainweb services to
45+ users and applications. It is served as plain (unencrypted) HTTP and can
46+ kept private. It is also possible to use this API with a reverse proxy.
47+
48+ More details about these APIs can be found further down in this document.
49+
3550** A Chainweb node must be reachable from the public internet** . It needs a
3651public IP address and port. If you run the node from a data center, usually, you
37- only have to ensure that it can be reached on the default port 443 . You can use
52+ only have to ensure that it can be reached on the default P2P port * 1789 * . You can use
3853the following shell command to start the node.
3954
4055` ` ` sh
41- docker run -d -p 443:443 kadena/chainweb-node
56+ docker run -d -p 1848:1848 -p 1789:1789 kadena/chainweb-node
4257` ` `
4358
59+ This exposes the P2P network on HTTPS port 1789 and the API services of chainweb
60+ node on HTTP port 1848.
61+
4462If you are running the node from a local network with NAT (network address
4563translation), which is the case for most home networks, you' ll have to configure
46- port forwarding in your router.
64+ port forwarding for the P2P port (1789) in your router.
4765
48- Using a different port is possible, too. For that the public port number must be
49- provided the Chainweb node in the environment.
66+ Using different ports is possible, too, as long as the internal and external
67+ port of the docker container match. For instance, the following command exposes
68+ the P2P network on port 443.
5069
5170```sh
52- docker run -d -p 1789:1789 - e "CHAINWEB_PORT=1789 " kadena/chainweb-node
71+ docker run -d -p 1848:1848 -p 443:443 - e "CHAINWEB_P2P_PORT=443 " kadena/chainweb-node
5372```
5473
5574More options to configure the node are described at the bottom of this document.
@@ -66,20 +85,68 @@ in this document.
6685
6786When the container is started for the first time it has to synchronize and
6887rebuild the Chainweb database from the P2P network. This can take a long time.
69- Currently, as of 2020-09 -17, this takes about 2-3 days for a node in a well
88+ Currently, as of 2021-02 -17, this takes about 2-3 days for a node in a well
7089connected data center.
7190
7291The container includes a script for synchronizing a pre-build database, which
73- currently, as of 2020-09-17, involves downloading about 10GB of data from an S3
74- container.
92+ currently, as of 2021-02-17, involves downloading about 15GB of data.
93+
94+ A database snapshot is just a gzipped tar archive of the Chainweb database,
95+ which contains the subdirectories `rocksDb` and `sqlite`. The URL can point to
96+ remote location or a local file. Any URL that curl understands is fine.
97+
98+ Database snapshots are available from different sources. Kadena offers an
99+ up-to-date snapshot at
100+ https://kadena-node-db.s3.us-east-2.amazonaws.com/db-chainweb-node-ubuntu.18.04-latest.tar.gz.
101+ This file is stored in a request-pays S3 bucket. In order to access it you need
102+ an AWS account and you must create and signed URL for authenticating with S3.
103+ Details about how to do this can be found here:
104+ https://docs.aws.amazon.com/AmazonS3/latest/userguide/ObjectsinRequesterPaysBuckets.html
105+
106+ With `node.js` you can create a signed URL for above snapshot URL as follows:
107+
108+ ```js
109+ // get-chainweb-image-url.js
110+ AWS = require("aws-sdk");
111+ const s3 = new AWS.S3({
112+ accessKeyId: AWS_ACCESS_KEY_ID, // Add your Access Key ID from IAM
113+ secretAccessKey: AWS_SECRET_ACCESS_KEY, // Add your Secret Access Key from IAM
114+ region: "us-east-2"
115+ })
116+ const params = {
117+ Bucket: ' kadena-node-db' ,
118+ Expires: 3600,
119+ Key: ' db-chainweb-node-ubuntu.18.04-latest.tar.gz' ,
120+ RequestPayer: ' requester'
121+ }
122+ // When ran, the script will output exclusively the signed url
123+ s3.getSignedUrl("getObject", params, (_err, res) => console.log(res))
124+ ```
125+
126+ With Python one can use the following code:
127+
128+ ```python
129+ import boto3
130+ client = boto3.client(' s3' )
131+ url = client.generate_presigned_url(
132+ "get_object",
133+ Params = {
134+ "Bucket":"kadena-node-db",
135+ "Key":"db-chainweb-node-ubuntu.18.04-latest.tar.gz",
136+ "RequestPayer":' requester'
137+ }
138+ )
139+ ```
75140
76141### Database within Chainweb node container
77142
78143The following shell commands initializes a docker container with a database and
79144creates a new image from it.
80145
81146```sh
82- docker run -ti --name initialize-chainweb-db kadena/chainweb-node /chainweb/initialize-db.sh
147+ npm install aws-sdk
148+ YOUR_DB_SNAPSHOT_URL=$(node get-chainweb-image-url.js) # assuming you use get-chainweb-image-url.js form above
149+ docker run -ti --name initialize-chainweb-db -e DBURL=$YOUR_DB_SNAPSHOT_URL kadena/chainweb-node /chainweb/initialize-db.sh
83150docker commit `docker ps -a -f ' name=initialize-chainweb-db' -q` chainweb-node-with-db
84151docker rm initialize-chainweb-db
85152```
@@ -90,7 +157,8 @@ follows:
90157```sh
91158docker run \
92159 --detach \
93- --publish 443:443 \
160+ --publish 1848:1848 \
161+ --publish 1789:1789 \
94162 --name chainweb-node \
95163 chainweb-node-with-db \
96164 /chainweb/run-chainweb-node.sh
@@ -106,16 +174,22 @@ It is therefore recommended to store the Chainweb database outside the container
106174on a docker volume (preferred method) or in the file system of the host system.
107175
108176```sh
109- # 1. Initialize a database that is persisted on a docker volume
177+ # 1. Get signed database snapshot URL (assuming you use get-chainweb-image-url.js form above)
178+ npm install aws-sdk
179+ YOUR_DB_SNAPSHOT_URL=$(node get-chainweb-image-url.js)
180+
181+ # 2. Initialize a database that is persisted on a docker volume
110182docker run -ti --rm \
111183 --mount type=volume,source=chainweb-data,target=/data \
184+ --env DBURL=$YOUR_DB_SNAPSHOT_URL \
112185 kadena/chainweb-node \
113186 /chainweb/initialize-db.sh
114187
115- # 2 . Use the database volume with a Chainweb node
188+ # 3 . Use the database volume with a Chainweb node
116189docker run \
117190 --detach \
118- --publish 443:443 \
191+ --publish 1848:1848 \
192+ --publish 1789:1789 \
119193 --name chainweb-node \
120194 --mount type=volume,source=chainweb-data,target=/data \
121195 kadena/chainweb-node
@@ -138,7 +212,8 @@ The following example provides a public miner key and an account name:
138212` ` ` sh
139213docker run \
140214 --detach \
141- --publish 443:443 \
215+ --publish 1848:1848 \
216+ --publish 1789:1789 \
142217 --env " MINER_KEY=26a9285cd8db34702cfef27a5339179b5a26373f03dd94e2096b0b3ba6c417da" \
143218 --env " MINER_ACCOUNT=merle" \
144219 --name chainweb-node \
@@ -162,13 +237,18 @@ by setting the `ROSETTA` environment variable to any non-empty value.
162237` ` ` sh
163238docker run \
164239 --detach \
165- --publish 443:443 \
240+ --publish 1848:1848 \
241+ --publish 1789:1789 \
166242 --env " ROSETTA=1" \
167243 --name chainweb-node \
168244 --mount type=volume,source=chainweb-data,target=/data \
169245 kadena/chainweb-node
170246` ` `
171247
248+ # API Overview
249+
250+ TODO
251+
172252# Verifying database consistency
173253
174254TODO
@@ -200,15 +280,20 @@ certificates using docker volumes.
200280
201281# ## File System
202282
203- * Database directory: ` /root/.local/share/ chainweb-node/mainnet01/0 `
204- * Chainweb configuration file: ` /chainweb/chainweb.yaml`
283+ * Database directory: ` /data/ chainweb-db `
284+ * Chainweb configuration file: ` /chainweb/chainweb.mainnet01. yaml`
205285
206286# ## Available Configuration Options
207287
208- * ` CHAINWEB_PORT` : the network port that is used by the Chainweb node.
209- The port that is used internally in the container * must* match the port that
210- is used publicly. A appropriate port mapping must be passed to the ` docker
211- run` command, e.g. ` -p 443:443` . (default: ` 443` )
288+ * ` CHAINWEB_P2P_PORT` : the network port that is used by the Chainweb P2P
289+ network. The port that is used internally in the container * must* match the
290+ port that is used publicly. A appropriate port mapping must be passed to the
291+ ` docker run` command, e.g. ` -p 443:443` . (default: ` 1789` )
292+
293+ * ` CHAINWEB_SERVICE_PORT` : the network port that is used by the Chainweb
294+ REST Service API. The port that is used internally in the container * must* match
295+ the port that is used publicly. A appropriate port mapping must be passed to
296+ the ` docker run` command, e.g. ` -p 8000:8000` . (default: ` 80` )
212297
213298* ` CHAINWEB_BOOTSTRAP_NODE` : a Chainweb node that is used to check the
214299 connectivity of the container before starting the node. (default:
@@ -219,7 +304,7 @@ certificates using docker volumes.
219304 The value ` debug` should be avoid during normal production.
220305 (default: ` warn` ).
221306
222- * ` CHAINWEB_HOST ` : the public IP address of the node. (default: automatically
307+ * ` CHAINWEB_P2P_HOST ` : the public IP address of the node. (default: automatically
223308 detected)
224309
225310* ` MINER_KEY` : the public key of the miner. If this is empty or unset
@@ -238,14 +323,21 @@ certificates using docker volumes.
238323 * option for enabled the header stream
239324 * explain how to overwrite the configuration file
240325
326+ Options for ` /chainweb/initialize-db.sh`
327+
328+ * ` DBURL` : The URL from where the database snapshot is downloaded. We
329+ recommend that users maintain there own database snapshots.
330+
241331Here is an example for how to use these settings:
242332
243333` ` ` sh
244334docker run \
245335 --detach \
336+ --publish 8000:8000 \
246337 --publish 1789:1789 \
247338 --name chainweb-node \
248- --env " CHAINWEB_PORT=1789" \
339+ --env " CHAINWEB_P2P_PORT=1789" \
340+ --env " CHAINWEB_SERVICE_PORT=8000" \
249341 --env " CHAINWEB_BOOTSTRAP_NODE=fr2.chainweb.com" \
250342 --env " LOGLEVEL=warn" \
251343 --env " MINER_KEY=774723b442c6ee660a0ac34747374fcd451591a123b35df5f4a69f1e9cb2cc75" \
@@ -255,3 +347,20 @@ docker run \
255347 kadena/chainweb-node
256348` ` `
257349
350+ # ## API Endpoints
351+
352+ P2P API (inter-node communication)
353+
354+ * cut endpoint
355+ * chain header endpoints
356+ * chain payload endpoints
357+ * chain mempool endpoints
358+
359+ Service API
360+
361+ * Pact endpoints
362+ * Mining endpoints
363+ * Rosetta endpoints
364+ * header-update-stream endpoint
365+ * info endpoint
366+ * health-check endpoint
0 commit comments