Skip to content

Commit 2d37278

Browse files
authored
Merge pull request #17 from wileyj/chore/cleanup-wileyj
Chore/cleanup wileyj
2 parents 0398229 + eb99ce2 commit 2d37278

File tree

10 files changed

+860
-502
lines changed

10 files changed

+860
-502
lines changed

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

Makefile

Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1+
# List of binaries devnet needs to function properly
12
COMMANDS := sudo tar zstd getent stress
23
$(foreach bin,$(COMMANDS),\
34
$(if $(shell command -v $(bin) 2> /dev/null),$(info),$(error Missing required dependency: `$(bin)`)))
4-
55
TARGET := $(firstword $(MAKECMDGOALS))
66
PARAMS := $(filter-out $(TARGET),$(MAKECMDGOALS))
7+
# Hardcode the chainstate dir if we're booting from genesis
78
ifeq ($(TARGET),up-genesis)
89
export CHAINSTATE_DIR := $(PWD)/docker/chainstate/genesis
910
endif
1011
ifeq ($(TARGET),genesis)
1112
export CHAINSTATE_DIR := $(PWD)/docker/chainstate/genesis
1213
endif
1314

14-
15-
## UID and GID are not currently used, but will be in the near future
15+
# UID and GID are not currently used, but may be later to ensure consistent file permissions
1616
export UID := $(shell getent passwd $$(whoami) | cut -d":" -f 3)
1717
export GID := $(shell getent passwd $$(whoami) | cut -d":" -f 4)
1818
EPOCH := $(shell date +%s)
@@ -23,6 +23,7 @@ CHAINSTATE_ARCHIVE ?= $(PWD)/docker/chainstate.tar.zstd
2323
export CHAINSTATE_DIR ?= $(PWD)/docker/chainstate/$(EPOCH)
2424
export DOCKER_NETWORK ?= stacks
2525
SERVICES := $(shell CHAINSTATE_DIR="" docker compose -f docker/docker-compose.yml --profile=default config --services)
26+
# Pauses the bitcoin miner script. Default is set to nearly 1 trillion blocks
2627
PAUSE_HEIGHT ?= 999999999999
2728
# Used for the stress testing target. modifies how much cpu to consume for how long
2829
STRESS_CORES ?= $(shell cat /proc/cpuinfo | grep processor | wc -l)
@@ -43,56 +44,87 @@ $(CHAINSTATE_DIR): /usr/bin/tar /usr/bin/zstd
4344
fi
4445
fi
4546

46-
# Boot the network from the local chainstate archive
47+
# Build the images with a cache if present
48+
build: check-not-running
49+
COMPOSE_BAKE=true PWD=$(PWD) docker compose -f docker/docker-compose.yml --profile default -p $(PROJECT) build
50+
51+
# Build the images without a cache (default uses cache)
52+
build-no-cache: check-not-running
53+
COMPOSE_BAKE=true PWD=$(PWD) docker compose -f docker/docker-compose.yml --profile default -p $(PROJECT) build --no-cache
54+
55+
# Set env var of what the statically defined chainstate dir is
56+
current-chainstate-dir: | check-running
57+
$(eval ACTIVE_CHAINSTATE_DIR=$(shell cat .current-chainstate-dir))
58+
59+
# If the network is already running, we need to exit (ex: trying to start the network when it's already running)
60+
check-not-running:
61+
@if test `docker compose ls --filter name=$(PROJECT) -q`; then \
62+
echo ""; \
63+
echo "WARNING: Network appears to be running or was not properly shut down."; \
64+
echo "Current chainstate directory: $$(cat .current-chainstate-dir)"; \
65+
echo ""; \
66+
echo "To shut down: make down"; \
67+
echo ""; \
68+
exit 1; \
69+
fi
70+
71+
# If the network is not running, we need to exit (ex: trying to restart a container)
72+
check-running:
73+
@if test ! `docker compose ls --filter name=$(PROJECT) -q`; then \
74+
echo "Network not running. exiting"; \
75+
exit 1; \
76+
fi
77+
78+
# For targets that need an arg, check that *something* is provided. it not, exit
79+
check-params: | check-running
80+
@if [ ! "$(PARAMS)" ]; then \
81+
echo "No service defined. Exiting"; \
82+
exit 1; \
83+
fi
84+
85+
# Boot the network from a local chainstate archive
4786
up: check-not-running | build $(CHAINSTATE_DIR)
4887
@echo "Starting $(PROJECT) network from chainstate archive"
4988
@echo " Chainstate Dir: $(CHAINSTATE_DIR)"
5089
@echo " Chainstate Archive: $(CHAINSTATE_ARCHIVE)"
5190
echo "$(CHAINSTATE_DIR)" > .current-chainstate-dir
5291
docker compose -f docker/docker-compose.yml --profile default -p $(PROJECT) up -d
5392

54-
# Run the network from genesis
93+
# Boot the network from genesis
5594
genesis: check-not-running | build $(CHAINSTATE_DIR) /usr/bin/sudo
5695
@echo "Starting $(PROJECT) network from genesis"
57-
@if [ -d "$(CHAINSTATE_DIR)/logs" ]; then \
96+
@if [ -d "$(CHAINSTATE_DIR)" ]; then \
5897
echo " Removing existing genesis chainstate dir: $(CHAINSTATE_DIR)"; \
59-
rm -rf $(CHAINSTATE_DIR)/logs; \
98+
sudo rm -rf $(CHAINSTATE_DIR); \
6099
fi
61100
@echo " Chainstate Dir: $(CHAINSTATE_DIR)"
62101
mkdir -p "$(CHAINSTATE_DIR)"
63102
echo "$(CHAINSTATE_DIR)" > .current-chainstate-dir
64103
docker compose -f docker/docker-compose.yml --profile default -p $(PROJECT) up -d
65104

66-
# secondary name to run genesis network
105+
# Secondary name to boot the genesis network
67106
up-genesis: genesis
68-
# secondary name to bring down genesis network
69-
down-genesis: down
70107

71-
# Shut down the network (chainstate and logs will be preserved, but not logs)
108+
# Shut down the network (chainstate and logs will be preserved)
72109
down: backup-logs current-chainstate-dir
73110
@echo "Shutting down $(PROJECT) network"
74111
docker compose -f docker/docker-compose.yml --profile default -p $(PROJECT) down
75112
@if [ -f .current-chainstate-dir ]; then \
76113
rm -f .current-chainstate-dir
77114
fi
78115

79-
# if the network is in a weird state - this target will force kill (bypassing error checks)
116+
# Secondary name to bring down the genesis network
117+
down-genesis: down
118+
119+
# If the network is in an unexpected state - this target will force kill (bypassing error checks)
80120
down-force:
81121
@echo "Force Shutting down $(PROJECT) network"
82122
docker compose -f docker/docker-compose.yml --profile default -p $(PROJECT) down
83123
@if [ -f .current-chainstate-dir ]; then \
84124
rm -f .current-chainstate-dir
85125
fi
86126

87-
# Build the images with a cache if present
88-
build: check-not-running
89-
COMPOSE_BAKE=true PWD=$(PWD) docker compose -f docker/docker-compose.yml --profile default -p $(PROJECT) build
90-
91-
# Build the images without a cache (default uses cache)
92-
build-no-cache: check-not-running
93-
COMPOSE_BAKE=true PWD=$(PWD) docker compose -f docker/docker-compose.yml --profile default -p $(PROJECT) build --no-cache
94-
95-
# Stream specified service logs to STDOUT. does not validate if PARAMS is supplied
127+
# Stream specified service logs to STDOUT. Does not validate if PARAMS is supplied
96128
log: current-chainstate-dir
97129
@echo "Logs for service $(PARAMS)"
98130
docker compose -f docker/docker-compose.yml --profile default -p $(PROJECT) logs -t --no-log-prefix $(PARAMS) -f
@@ -118,11 +150,7 @@ backup-logs: current-chainstate-dir /usr/bin/sudo
118150
done; \
119151
fi
120152

121-
# set env var of what the statically defined chainstate dir is
122-
current-chainstate-dir: | check-running
123-
$(eval ACTIVE_CHAINSTATE_DIR=$(shell cat .current-chainstate-dir))
124-
125-
# replace the existing chainstate archive. will be used with target `up`
153+
# Replace the existing chainstate archive. Will be used with target `up`
126154
snapshot: current-chainstate-dir down
127155
@echo "Creating $(PROJECT) chainstate snapshot from $(ACTIVE_CHAINSTATE_DIR)"
128156
@if [ -d "$(ACTIVE_CHAINSTATE_DIR)/logs" ]; then \
@@ -132,85 +160,57 @@ snapshot: current-chainstate-dir down
132160
@echo "cd $(ACTIVE_CHAINSTATE_DIR); sudo tar --zstd -cf $(CHAINSTATE_ARCHIVE) *; cd $(PWD)"
133161
cd $(ACTIVE_CHAINSTATE_DIR); sudo tar --zstd -cf $(CHAINSTATE_ARCHIVE) *; cd $(PWD)
134162

135-
# pause all services in the network (netork is down, but recoverably with target 'unpause')
163+
# Pause all services in the network (netork is down, but recoverably with target 'unpause')
136164
pause:
137165
@echo "Pausing all services"
138166
docker compose -f docker/docker-compose.yml --profile default -p $(PROJECT) pause $(SERVICES)
139167

140-
# unpause all services in the network (only used after first using target 'pause')
168+
# Unpause all services in the network (only used after first using target 'pause')
141169
unpause:
142170
@echo "Unpausing all services"
143171
docker compose -f docker/docker-compose.yml --profile default -p $(PROJECT) unpause $(SERVICES)
144172

145-
# stop an individual service
173+
# Stop an individual service
146174
stop: check-params current-chainstate-dir | check-running
147175
@echo "Killing service $(PARAMS)"
148176
@echo " Chainstate Dir: $(ACTIVE_CHAINSTATE_DIR)"
149177
@echo " Target: $(TARGET)"
150178
@echo " Params: $(PARAMS)"
151179
CHAINSTATE_DIR=$(ACTIVE_CHAINSTATE_DIR) docker compose -f docker/docker-compose.yml --profile default -p $(PROJECT) down $(PARAMS)
152180

153-
# start an individual service
181+
# Start an individual service
154182
start: check-params current-chainstate-dir | check-running
155183
@echo "Resuming service $(PARAMS)"
156184
@echo " Chainstate Dir: $(ACTIVE_CHAINSTATE_DIR)"
157185
@echo " Target: $(TARGET)"
158186
@echo " Params: $(PARAMS)"
159187
CHAINSTATE_DIR=$(ACTIVE_CHAINSTATE_DIR) docker compose -f docker/docker-compose.yml --profile default -p $(PROJECT) up -d $(PARAMS)
160188

161-
# restart a service with a defined servicename/duration. called script will validate PARAMS
162-
# if no duration is provided, default of 30s shall be used
189+
# Restart a service with a defined servicename/duration - the script will validate PARAMS
190+
# If no duration is provided, a default of 30s shall be used
163191
restart: check-params | check-running
164192
@echo "Restarting service"
165193
@echo " Params: $(PARAMS)"
166194
./docker/tests/restart-container.sh $(PARAMS)
167195

168-
# use 'stress' binary to consume defined cpu over a specified time
196+
# Use 'stress' binary to consume defined cpu over a specified time
169197
stress:
170198
@echo "Stressing system CPU $(PARAMS)"
171199
@echo " Cores: $(STRESS_CORES)"
172200
@echo " Timeout: $(STRESS_TIMEOUT)"
173201
stress --cpu $(STRESS_CORES) --timeout $(STRESS_TIMEOUT)
174202

175-
# run the test script to verify the services are all load and operating as expected
203+
# Run the liveness script to verify the services are all loaded and operating as expected
176204
test:
177205
./docker/tests/devnet-liveness.sh
178206

179-
# run the chain monitor script (loops and curls /v2/info, parsing the output to show current heights of miners)
207+
# Run the chain monitor script (loops and curls /v2/info, parsing the output to show current heights of miners)
180208
monitor:
181209
./docker/tests/chain-monitor.sh
182210

183-
# if the network is already running, we need to exit (ex: trying to start the network when it's already running)
184-
check-not-running:
185-
@if test `docker compose ls --filter name=$(PROJECT) -q`; then \
186-
echo ""; \
187-
echo "WARNING: Network appears to be running or was not properly shut down."; \
188-
echo "Current chainstate directory: $$(cat .current-chainstate-dir)"; \
189-
echo ""; \
190-
echo "To backup logs first: make backup-logs"; \
191-
echo "To shut down: make down"; \
192-
echo ""; \
193-
exit 1; \
194-
fi
195-
196-
# if the network is not running, we need to exit (ex: trying to restart a container)
197-
check-running:
198-
@if test ! `docker compose ls --filter name=$(PROJECT) -q`; then \
199-
echo "Network not running. exiting"; \
200-
exit 1; \
201-
fi
202-
203-
# for targets that need an arg, check that *something* is provided. it not, exit
204-
check-params: | check-running
205-
@if [ ! "$(PARAMS)" ]; then \
206-
echo "No service defined. Exiting"; \
207-
exit 1; \
208-
fi
209-
210-
# force stop and remove any existing chainstates (leaving all docker images/layers)
211+
# Force stop and remove any existing chainstates (leaving all docker images/layers)
211212
clean: down-force
212213
sudo rm -rf ./docker/chainstate/*
213214

214-
215-
.PHONY: up genesis up-genesis down-genesis down down-force build build-no-cache log log-all backup-logs current-chainstate-dir snapshot pause unpause stop start restart stress test monitor check-not-running check-running check-params clean
215+
.PHONY: build build-no-cache current-chainstate-dir check-not-running check-running check-params up genesis up-genesis down down-genesis down-force log log-all backup-logs snapshot pause unpause stop start restart stress test monitor clean
216216
.ONESHELL: all-in-one-shell

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
# Devnet
2-
Modified from: https://github.com/stacks-sbtc/sbtc/tree/v1.0.2/docker, changes:
3-
4-
- Deleted services related to sBTC, mempool and grafana
52
- Configured for 3 stacks miners and signers
63
- bind-mounts a local filesystem for data persistence
74
- Uses a chainstate archive to boot the network quickly
@@ -33,11 +30,11 @@ make genesis
3330
```
3431

3532
### Stop the network
36-
*note*: `down-genesis` target calls `down`
3733
```sh
3834
make down
3935
```
4036

37+
## Full list of options
4138
### Logs
4239
`docker logs -f <service>` will work, along with some defined Makefile targets
4340

@@ -159,7 +156,6 @@ make clean
159156
- **postgres**: postgres DB used by stacks-api
160157
- **stacker**: stack for `stacks-signer-1`, `stacks-signer-2` and `stacks-signer-3`
161158
- **tx-broadcaster**: submits token transfer txs to ensure stacks block production during a sortition
162-
- **monitor**: monitors block details and tracks stacking calls
163159

164160
## Stacks Miner Accounts
165161

0 commit comments

Comments
 (0)