Skip to content

Commit a9e90d3

Browse files
author
asteria
committed
updates to running a mainnet node
1 parent b6d9a0a commit a9e90d3

File tree

1 file changed

+68
-34
lines changed

1 file changed

+68
-34
lines changed

src/pages/understand-stacks/running-mainnet-node.md

+68-34
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,27 @@ images:
1313

1414
## Introduction
1515

16-
This procedure demonstrates how to run a local mainnet node using Docker images.
16+
This guide shows how to run a Stacks mainnet node using Docker images.
1717

18-
-> This procedure focuses on Unix-like operating systems (Linux and MacOS). This procedure has not been tested on
19-
Windows.
18+
It uses [Hiro's implementation](https://github.com/blockstack/stacks-blockchain) of a Stacks node, along with [Bitcoin Core](https://github.com/bitcoin/bitcoin).
19+
20+
-> This procedure focuses on Unix-like operating systems (Linux and MacOS). This procedure has not been tested on Windows.
2021

2122
## Prerequisites
2223

23-
Running a node has no specialized hardware requirements. Users have been successful in running nodes on Raspberry Pi
24-
boards and other system-on-chip architectures. In order to complete this procedure, you must have the following software
25-
installed on the node host machine:
24+
Running a node has no specialized hardware requirements. Users have been successful in running nodes on Raspberry Pi boards and other system-on-chip architectures. In order to complete this procedure, you must have the following software installed on the node host machine:
2625

2726
- [Docker](https://docs.docker.com/get-docker/)
2827
- [curl](https://curl.se/download.html)
2928
- [jq](https://stedolan.github.io/jq/download/)
3029

30+
You can use `brew install docker curl jq` for MacOS and usually `sudo apt-get install docker curl jq` for Linux. But this might not work for every system.
31+
32+
You'll need at minimum 500GB for the Bitcoin Core node and somewhere around 20GB (as of block `704197`). This will grow in size, so a 1TB or more drive is usually recommended for future-proofing.
33+
3134
### Firewall configuration
3235

33-
In order for the API node services to work correctly, you must configure any network firewall rules to allow traffic on
34-
the ports discussed in this section. The details of network and firewall configuration are highly specific to your
35-
machine and network, so a detailed example isn't provided.
36+
In order for the API node services to work correctly, you must configure any network firewall rules to allow traffic on the ports discussed in this section. The details of network and firewall configuration are specific to your setup and network, so we won't provide a detailed example.
3637

3738
The following ports must open on the host machine:
3839

@@ -59,53 +60,82 @@ persistent data from the services. Download and configure the Docker images with
5960
docker pull blockstack/stacks-blockchain
6061
```
6162

62-
Create a directory structure for the service data with the following command:
63+
Create some directories for the Stacks data with the following command:
6364

6465
```sh
6566
mkdir -p ./stacks-node/{persistent-data/stacks-blockchain/mainnet,config/mainnet} && cd stacks-node
6667
```
6768

68-
## Step 2: running Stacks blockchain
69+
## Step 2: running Bitcoin Core
70+
71+
Stacks finds its blocks by looking through the Bitcoin chain for anchor transactions that store the hashes of Stacks blocks. This is one of the things that makes Stacks so secure.
72+
73+
You'll need to be running an **unpruned** Bitcoin Core node for your Stacks node to sync from.
74+
75+
You'll want your Bitcoin node config to look something like this...
76+
77+
```toml
78+
# remove if you like, this lets the node use more threads
79+
par=512
80+
server=1
81+
txindex=1
82+
# comment this back in after the initial block download if you want to use TOR.
83+
# you'll need to add TOR and the config separately.
84+
# there are guides for this elsewhere :)
85+
# onlynet=onion
86+
daemon=1
87+
# hiro's implementation uses rpc v0
88+
rpcserialversion=0
89+
maxorphantx=1
90+
banscore=1
91+
bind=0.0.0.0:8333
92+
rpcbind=0.0.0.0:8332
93+
rpcport=8332
94+
```
95+
96+
There are plenty of guides on how to run a Bitcoin Core node. Do a search and you'll find more indepth info.
97+
98+
If you're on Linux, Bitcoin Core will load the config from `~/.bitcoin/bitcoin.conf` by default.
99+
100+
On MacOS, it loads from `~/Library/Application Support/Bitcoin/bitcoin.conf`.
101+
102+
-> Wait 'til your Bitcoin Core node is fully synced to the rest of the chain before proceeding to connect your Stacks node to it
103+
104+
## Step 3: running the Stacks node
69105

70-
First, create the `./config/Config.toml` file and add the following content to the
71-
file using a text editor:
106+
After Bitcoin Core has synced, create the `./config/Config.toml` file and add the following content to the file using a text editor:
72107

73108
```toml
109+
# stacks node config
74110
[node]
75-
working_dir = "/root/stacks-node/data"
111+
# where the node stores stacks chain data
112+
working_dir = "~/stacks-node/data"
76113
rpc_bind = "0.0.0.0:20443"
77114
p2p_bind = "0.0.0.0:20444"
115+
# the nodes used to bootstrap your node
116+
# these are hiro's nodes, but you can use any other nodes too
78117
bootstrap_node = "02da7a464ac770ae8337a343670778b93410f2f3fef6bea98dd1c3e9224459d36b@seed-0.mainnet.stacks.co:20444,02afeae522aab5f8c99a00ddf75fbcb4a641e052dd48836408d9cf437344b63516@seed-1.mainnet.stacks.co:20444,03652212ea76be0ed4cd83a25c06e57819993029a7b9999f7d63c36340b34a4e62@seed-2.mainnet.stacks.co:20444"
118+
119+
# time in ms to wait for a microblock
79120
wait_time_for_microblocks = 10000
80121

122+
# bitcoin rpc config
81123
[burnchain]
82124
chain = "bitcoin"
83125
mode = "mainnet"
84-
peer_host = "bitcoin.blockstack.com"
85-
username = "blockstack"
86-
password = "blockstacksystem"
126+
# host is usually `localhost` if you're running Bitcoin Core on the same machine
127+
peer_host = "<YOUR_BTC_CORE_HOST>"
128+
# leave as "" if you didn't set them in your Bitcoin config
129+
username = "<BTC_RPC_USERNAME>"
130+
password = "<BTC_RPC_PW>"
87131
rpc_port = 8332
88132
peer_port = 8333
89-
90-
[connection_options]
91-
read_only_call_limit_write_length = 0
92-
read_only_call_limit_read_length = 100000
93-
read_only_call_limit_write_count = 0
94-
read_only_call_limit_read_count = 30
95-
read_only_call_limit_runtime = 1000000000
96133
```
97134

98135
Start the [`stacks-blockchain`][] container with the following command:
99136

100137
```sh
101-
docker run -d --rm \
102-
--name stacks-blockchain \
103-
-v $(pwd)/persistent-data/stacks-blockchain/mainnet:/root/stacks-node/data \
104-
-v $(pwd)/config/mainnet:/src/stacks-node \
105-
-p 20443:20443 \
106-
-p 20444:20444 \
107-
blockstack/stacks-blockchain \
108-
/bin/stacks-node start --config /src/stacks-node/Config.toml
138+
docker run -d --name stacks-blockchain -v $(pwd)/persistent-data/stacks-blockchain/mainnet:/root/stacks-node/data -v $(pwd)/config/mainnet:/src/stacks-node -p 20443:20443 -p 20444:20444 blockstack/stacks-blockchain /bin/stacks-node start --config /src/stacks-node/Config.toml
109139
```
110140

111141
You can verify the running [`stacks-blockchain`][] container with the command:
@@ -114,6 +144,8 @@ You can verify the running [`stacks-blockchain`][] container with the command:
114144
docker ps --filter name=stacks-blockchain
115145
```
116146

147+
If you want more verbose output, you can add an environment variable to the container - `STACKS_LOG_DEBUG=1`
148+
117149
## Step 3: verifying the services
118150

119151
-> The initial burnchain header sync can take several minutes, until this is done the following commands will not work
@@ -132,13 +164,15 @@ INFO [1626290748.103291] [src/burnchains/bitcoin/spv.rs:926] [main] Syncing Bitc
132164
INFO [1626290776.956535] [src/burnchains/bitcoin/spv.rs:926] [main] Syncing Bitcoin headers: 1.7% (12000 out of 691034)
133165
```
134166

135-
To verify the [`stacks-blockchain`][] tip height is progressing use the following command:
167+
To verify the [`stacks-blockchain`][] tip height is progressing use the following command.
168+
169+
-> This normally will only work once all Bitcoin headers have been synced and it starts to pull the Stacks blocks from the chain
136170

137171
```sh
138172
curl -sL localhost:20443/v2/info | jq
139173
```
140174

141-
If the instance is running you should recieve terminal output similar to the following:
175+
You should get something like this back.
142176

143177
```json
144178
{

0 commit comments

Comments
 (0)