Skip to content

Commit 825764b

Browse files
authored
Merge pull request #6 from zelcash/development
2.5
2 parents f2e56cf + 7117475 commit 825764b

File tree

7 files changed

+185
-97
lines changed

7 files changed

+185
-97
lines changed

Dockerfile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
# --ulimit nofile=64000:64000
66

77
# BUILD PARAMTERS
8-
ARG UBUNTUVER=18.04
8+
ARG UBUNTUVER=20.04
99

1010
FROM ubuntu:${UBUNTUVER}
1111

12-
ARG REVISION=15111ad
13-
ARG GHCVER=8.8.4
12+
ARG REVISION=dfcc08b
13+
ARG GHCVER=8.10.3
1414
ARG UBUNTUVER
1515

1616
LABEL revision="$REVISION"
@@ -19,7 +19,7 @@ LABEL ubuntu="$UBUNTUVER"
1919

2020
# install prerequisites
2121
RUN apt-get update \
22-
&& apt-get install -y librocksdb-dev curl xxd openssl binutils \
22+
&& apt-get install -y librocksdb-dev curl xxd openssl binutils jq \
2323
&& rm -rf /var/lib/apt/lists/*
2424

2525
# Install chainweb applications
@@ -40,6 +40,7 @@ STOPSIGNAL SIGTERM
4040
EXPOSE 443
4141
EXPOSE 80
4242
EXPOSE 1789
43+
EXPOSE 1848
4344
HEALTHCHECK --start-period=10m --interval=1m --retries=5 --timeout=10s CMD ./check-health.sh
4445

4546
CMD ./run-chainweb-node.sh

README.md

Lines changed: 137 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
# Quick Setup
22

33
1. *(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

88
3. 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

1518
4. 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

2124
For 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
3651
public 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
3853
the 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+
4462
If you are running the node from a local network with NAT (network address
4563
translation), 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
5574
More options to configure the node are described at the bottom of this document.
@@ -66,20 +85,68 @@ in this document.
6685
6786
When the container is started for the first time it has to synchronize and
6887
rebuild 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
7089
connected data center.
7190
7291
The 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
78143
The following shell commands initializes a docker container with a database and
79144
creates 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
83150
docker commit `docker ps -a -f 'name=initialize-chainweb-db' -q` chainweb-node-with-db
84151
docker rm initialize-chainweb-db
85152
```
@@ -90,7 +157,8 @@ follows:
90157
```sh
91158
docker 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
106174
on 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
110182
docker 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
116189
docker 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
139213
docker 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
163238
docker 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

174254
TODO
@@ -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+
241331
Here is an example for how to use these settings:
242332

243333
```sh
244334
docker 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

chainweb.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ chainweb:
55
local: 0.1
66
mining: 2
77
global: 200.0
8-
putPeer: 21
8+
putPeer: 30
99
chainwebVersion: mainnet01
1010
mining:
1111
coordination:
@@ -29,7 +29,7 @@ chainweb:
2929
maxPeerCount: 100
3030
private: false
3131
ignoreBootstrapNodes: true
32-
maxSessionCount: 6
32+
maxSessionCount: 8
3333
sessionTimeout: 300
3434
peers:
3535
- address:
@@ -90,7 +90,7 @@ chainweb:
9090
enabled: true
9191
configuration:
9292
pollInterval: 30
93-
maxSessionCount: 5
93+
maxSessionCount: 6
9494
sessionTimeout: 300
9595
reintroTxs: true
9696
cuts:

check-health.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
#!/usr/bin/env bash
22

33
export CHAINWEB_NETWORK=${CHAINWEB_NETWORK:-mainnet01}
4-
export CHAINWEB_PORT=${CHAINWEB_PORT:-443}
4+
export CHAINWEB_P2P_PORT=${CHAINWEB_P2P_PORT:-1789}
55

6-
curl -fsLk "https://localhost:$CHAINWEB_PORT/chainweb/0.0/$CHAINWEB_NETWORK/cut" || exit 1
6+
DAYS_IN_SEC=86400
7+
CURRENT_TIME=$(date '+%s')
8+
BASE_TIME=1611710552
9+
BASE_HEIGHT=26212040
10+
TIME_DIFF=$((CURRENT_TIME-BASE_TIME))
11+
BLOCKS_PASSED_DIFF=$((TIME_DIFF/30*20))
12+
BLOCKS_TIMEFRAME=$((DAYS_IN_SEC/30*20))
13+
CURRENT_BLOCK_EST=$((BASE_HEIGHT+BLOCKS_PASSED_DIFF))
14+
MIN_ACCEPTED_HEIGHT=$((CURRENT_BLOCK_EST-BLOCKS_TIMEFRAME-200000))
15+
CURRENT_NODE_HEIGHT=$(curl -fsLk "https://localhost:$CHAINWEB_P2P_PORT/chainweb/0.0/$CHAINWEB_NETWORK/cut" | jq '.height')
716

17+
18+
if ((CURRENT_NODE_HEIGHT>MIN_ACCEPTED_HEIGHT)); then echo "Node is at block ${CURRENT_NODE_HEIGHT} and meets minimum height of ${MIN_ACCEPTED_HEIGHT}"; else exit 1; fi

check-reachability.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
HOST=$1
99
PORT=$2
1010

11-
CHAINWEB_NETWORK=${CHAINWEB_NETWORK:-testnet04}
12-
CHAINWEB_BOOTSTRAP_NODE=${CHAINWEB_BOOTSTRAP_NODE:-us1.testnet.chainweb.com}
11+
CHAINWEB_NETWORK=${CHAINWEB_NETWORK:-mainnet01}
12+
CHAINWEB_BOOTSTRAP_NODE=${CHAINWEB_BOOTSTRAP_NODE:-us-e1.chainweb.com}
1313

1414
# ############################################################################ #
1515
# Temporary files
@@ -69,4 +69,3 @@ curl "https://$CHAINWEB_BOOTSTRAP_NODE/chainweb/0.0/$CHAINWEB_NETWORK/cut/peer"
6969
-v \
7070
-d "$PEER_INFO" 2>&1 |
7171
grep -q "< HTTP/2 204\|missing X-Chainweb-Node-Version header"
72-

0 commit comments

Comments
 (0)