Skip to content

Commit a79b9b6

Browse files
author
Mostafa Farghaly
committed
deploy stacks miner node
1 parent ac933ae commit a79b9b6

File tree

1 file changed

+154
-0
lines changed

1 file changed

+154
-0
lines changed

stacks/miner.md

+154
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
Stacks node requires a Bitcoin node to connect to on the back-end for [Proof of Transfer](https://docs.stacks.co/understand-stacks/proof-of-transfer). You can deploy a Bitcoin node using Kotal operator like we did in this [guide](../bitcoin/rpc.md). In this tutorial, we will be using Bitcoin node hosted by Stacks Foundation.
2+
3+
{% hint style="warning" %}
4+
Make sure Bitcoin node is fully synced before deploying your Stacks node.
5+
{% endhint %}
6+
7+
## Generating Miner Private Key
8+
9+
{% hint style="warning" %}
10+
Don't use the following Miner private key in production!
11+
{% endhint %}
12+
13+
Generate Key chain using [Stacks CLI](https://github.com/hirosystems/stacks.js/tree/master/packages/cli) tool. Stacks CLI can be installed using:
14+
15+
```bash
16+
npm install -g @stacks/cli
17+
```
18+
19+
Generate key chain using:
20+
21+
```bash
22+
stx make_keychain
23+
```
24+
25+
It will return an output similar to the following
26+
27+
```json
28+
{
29+
"mnemonic": "blue news bid also tell vault blame tonight crumble history tribe anxiety arch stove usage eight stick firm weapon wet chapter gravity seat idle",
30+
"keyInfo": {
31+
"privateKey": "7a3ef70a4a3ff3c389818ac11abec24b20ffbe3fb2cf6f71e947367a4ddbec6601",
32+
"address": "SPQG93WFTVV6GA4AEDMS18ZCSTKMKFHWEHEXQAJJ",
33+
"btcAddress": "15HcDuW1W2TqEe9mVER9ceJYtqMAED26jp",
34+
"wif": "L1KLjY5xMGUSSV9cfE9VoKRdVt3D1zJxoJwPVLHfgRNS1ETGUSvr",
35+
"index": 0
36+
}
37+
}
38+
```
39+
40+
Store `privateKey` from the output above into a Kubernetes secret in data field called `key`:
41+
42+
```
43+
kubectl create secret generic seed-private-key --from-literal=key=7a3ef70a4a3ff3c389818ac11abec24b20ffbe3fb2cf6f71e947367a4ddbec6601
44+
```
45+
46+
## Bitcoin node JSON-RPC user password
47+
48+
Let's store Stacks Foundation Bitcoin node JSON-RPC password in a Kubernetes secret to be used by our node:
49+
50+
{% code title="bitcoin-node-rpc-password.yaml" %}
51+
```yaml
52+
apiVersion: v1
53+
kind: Secret
54+
metadata:
55+
name: bitcoin-node-rpc-password
56+
stringData:
57+
password: blockstacksystem
58+
```
59+
{% endcode %}
60+
61+
Apply `bitcoin-node-rpc-password.yaml` to create the password secret:
62+
63+
```bash
64+
kubectl apply -f bitcoin-node-rpc-password.yaml
65+
```
66+
67+
## Deploy Stacks Miner Node
68+
69+
The following manifest describes a Stacks node that syncs Stacks mainnet `network: mainnet`, and connects to the bitcoin node using configurations in `bitcoinNode: ...` for Proof of Transfer, and loading miner private key using `seedPrivateKeySecretName`:
70+
71+
{% code title="stacks.yaml" %}
72+
```yaml
73+
apiVersion: stacks.kotal.io/v1alpha1
74+
kind: Node
75+
metadata:
76+
name: stacks-node
77+
spec:
78+
network: mainnet
79+
seedPrivateKeySecretName: seed-private-key
80+
bitcoinNode:
81+
endpoint: bitcoin.blockstack.com
82+
rpcPort: 8332
83+
p2pPort: 8333
84+
rpcUsername: blockstack
85+
rpcPasswordSecretName: bitcoin-node-rpc-password
86+
```
87+
{% endcode %}
88+
89+
Apply `stacks.yaml` manifest:
90+
91+
```bash
92+
kubectl apply -f stacks.yaml
93+
```
94+
95+
Kotal operator will notice your `stacks-node` and will create all the necessary pods, persistent volumes, services, configmaps, and secrets neccessary.
96+
97+
You can fetch the deployed Stacks `Node` using:
98+
99+
```bash
100+
kubectl get nodes.stacks
101+
```
102+
103+
It will return an output similar to the following:
104+
105+
```bash
106+
NAME NETWORK CLIENT MINER
107+
stacks-node mainnet stacks true
108+
```
109+
110+
Note Miner is true in the previous output 🔥
111+
112+
## Fetch Node Logs
113+
114+
Get the pods that has been created by Kotal for the node:
115+
116+
```bash
117+
kubectl get pods
118+
```
119+
120+
It will return an output similar to the following:
121+
122+
```bash
123+
NAME READY STATUS RESTARTS AGE
124+
stacks-node-0 1/1 Running 0 1m
125+
```
126+
127+
Get the logs of the running node:
128+
129+
```bash
130+
kubectl logs -f stacks-node-0
131+
```
132+
133+
It will return node logs similar to the following:
134+
135+
```bash
136+
INFO [1649610683.233993] [testnet/stacks-node/src/main.rs:113] [main] Loading config at path /home/stacks/kotal-config/config.toml
137+
INFO [1649610683.795606] [testnet/stacks-node/src/run_loop/neon.rs:341] [main] Start syncing Bitcoin headers, feel free to grab a cup of coffee, this can take a while
138+
INFO [1649610686.606279] [src/burnchains/bitcoin/spv.rs:923] [main] Syncing Bitcoin headers: 0.3% (2000 out of 731294)
139+
INFO [1649610687.625014] [src/burnchains/bitcoin/spv.rs:923] [main] Syncing Bitcoin headers: 0.5% (4000 out of 731294)
140+
INFO [1649610688.634560] [src/burnchains/bitcoin/spv.rs:923] [main] Syncing Bitcoin headers: 0.8% (6000 out of 731294)
141+
INFO [1649610689.677533] [src/burnchains/bitcoin/spv.rs:923] [main] Syncing Bitcoin headers: 1.1% (8000 out of 731294)
142+
INFO [1649610690.737928] [src/burnchains/bitcoin/spv.rs:923] [main] Syncing Bitcoin headers: 1.4% (10000 out of 731294)
143+
INFO [1649610691.745002] [src/burnchains/bitcoin/spv.rs:923] [main] Syncing Bitcoin headers: 1.6% (12000 out of 731294)
144+
INFO [1649610692.789689] [src/burnchains/bitcoin/spv.rs:923] [main] Syncing Bitcoin headers: 1.9% (14000 out of 731294)
145+
...
146+
```
147+
148+
Finally you can delete the node by:
149+
150+
```bash
151+
kubectl delete -f stacks.yaml
152+
```
153+
154+
Kubernetes garbage collector will delete all the resources that has been created by Stacks `Node` controller.

0 commit comments

Comments
 (0)