Skip to content

Commit 9ab5577

Browse files
authored
feat: enable dynamic forging (#281)
* feat(dynamic-forging): include --start-as-non-producing-node flag for dynamic forging - update readme with new env var and usage Signed-off-by: Reza Rajan <[email protected]> * docs: fix typo Signed-off-by: Reza Rajan <[email protected]> * docs(readme): fix typo src -> srv Signed-off-by: Reza Rajan <[email protected]> * feat(entrypoint): include arg parsing for --start-as-non-producing-node Signed-off-by: Reza Rajan <[email protected]> --------- Signed-off-by: Reza Rajan <[email protected]>
1 parent 13298a6 commit 9ab5577

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed

README.md

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,22 +140,62 @@ docker run --detach \
140140
-e CARDANO_SHELLEY_KES_KEY=/opt/cardano/config/keys/kes.skey \
141141
-e CARDANO_SHELLEY_OPERATIONAL_CERTIFICATE=/opt/cardano/config/keys/node.cert \
142142
-e CARDANO_SHELLEY_VRF_KEY=/opt/cardano/config/keys/vrf.skey \
143-
-v /src/cardano/node-keys:/opt/cardano/config/keys \
143+
-v /srv/cardano/node-keys:/opt/cardano/config/keys \
144144
-v /srv/cardano/node-db:/data/db \
145145
-v /srv/cardano/node-ipc:/ipc \
146146
-p 3001:3001 \
147147
-p 12798:12798 \
148148
ghcr.io/blinklabs-io/cardano-node run
149149
```
150150

151+
##### Dynamic Block Forging
152+
153+
To start a block producer in non-producing mode initially (for dynamic block forging):
154+
155+
```bash
156+
docker run --detach \
157+
--name cardano-node \
158+
--restart unless-stopped \
159+
-e CARDANO_BLOCK_PRODUCER=true \
160+
-e START_AS_NON_PRODUCING=true \
161+
-e CARDANO_SHELLEY_KES_KEY=/opt/cardano/config/keys/kes.skey \
162+
-e CARDANO_SHELLEY_OPERATIONAL_CERTIFICATE=/opt/cardano/config/keys/node.cert \
163+
-e CARDANO_SHELLEY_VRF_KEY=/opt/cardano/config/keys/vrf.skey \
164+
-v /srv/cardano/node-keys:/opt/cardano/config/keys \
165+
-v /srv/cardano/node-db:/data/db \
166+
-v /srv/cardano/node-ipc:/ipc \
167+
-p 3001:3001 \
168+
-p 12798:12798 \
169+
ghcr.io/blinklabs-io/cardano-node run
170+
```
171+
172+
With dynamic block forging enabled, you can control block production without restarting the node:
173+
174+
- **Enable block forging**: Ensure credential files are present and send SIGHUP
175+
```bash
176+
docker exec cardano-node pkill -SIGHUP cardano-node
177+
```
178+
179+
- **Disable block forging**: Move/rename credential files and send SIGHUP
180+
```bash
181+
docker exec cardano-node mv /opt/cardano/config/keys/kes.skey /opt/cardano/config/keys/kes.skey.disabled
182+
docker exec cardano-node pkill -SIGHUP cardano-node
183+
```
184+
185+
- **Re-enable block forging**: Restore credential files and send SIGHUP
186+
```bash
187+
docker exec cardano-node mv /opt/cardano/config/keys/kes.skey.disabled /opt/cardano/config/keys/kes.skey
188+
docker exec cardano-node pkill -SIGHUP cardano-node
189+
```
190+
151191
The above uses Docker's built in supervisor to restart a container which fails
152192
for any reason. This will also cause the container to automatically restart
153193
after a host reboot, so long as Docker is configured to start on boot. We
154194
set variables to configure a block producer and pass the paths to the 3 keys
155195
we need. Our node's persistent data and client communication socket are mapped
156-
to `/src/cardano/node-db` and `/src/cardano/node-ipc` on the host,
196+
to `/srv/cardano/node-db` and `/srv/cardano/node-ipc` on the host,
157197
respectively. This allows for running applications directly on the host which
158-
may need access to these. We also map `/src/cardano/node-keys` on the host to
198+
may need access to these. We also map `/srv/cardano/node-keys` on the host to
159199
a path within the container to support running as a block producer. Last, we
160200
add mapping the host's port 12798 to the container 12798, which is the port for
161201
exposing the node's metrics in Prometheus format, for monitoring.
@@ -224,7 +264,12 @@ and operational certificate.
224264
`${CARDANO_CONFIG_BASE}/keys/vrf.skey`)
225265
- `CARDANO_SHELLEY_OPERATIONAL_CERTIFICATE`
226266
- Stake pool identity certificate (default:
227-
`${CARDANO_CONFIG_BASE}/keys/node.cert`
267+
`${CARDANO_CONFIG_BASE}/keys/node.cert`)
268+
- `START_AS_NON_PRODUCING`
269+
- Start block producer node in non-producing mode (default: `false`)
270+
- When set to `true`, adds the `--start-as-non-producing-node` flag
271+
- Only applies when `CARDANO_BLOCK_PRODUCER=true`
272+
- Enables dynamic block forging control via SIGHUP signals
228273

229274
#### Controlling Mithril snapshots
230275

bin/run-node

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ for i in ${!options[@]}; do
2424
--shelley-vrf-key) CARDANO_SHELLEY_VRF_KEY=${v}; found=true ;;
2525
--socket-path) CARDANO_SOCKET_PATH=${v}; found=true ;;
2626
--topology) CARDANO_TOPOLOGY=${v}; found=true ;;
27+
--start-as-non-producing-node) START_AS_NON_PRODUCING=${v}; found=true ;;
2728
esac
2829
if [[ ${found} == true ]]; then
2930
options[i]="";
@@ -44,6 +45,7 @@ CARDANO_PORT=${CARDANO_PORT:-3001}
4445
CARDANO_RTS_OPTS=${CARDANO_RTS_OPTS:--N2 -A64m -I0 -qg -qb --disable-delayed-os-memory-return}
4546
CARDANO_SOCKET_PATH=${CARDANO_SOCKET_PATH:-/ipc/node.socket}
4647
CARDANO_TOPOLOGY=${CARDANO_TOPOLOGY:-${CARDANO_CONFIG_BASE}/${CARDANO_NETWORK}/topology.json}
48+
START_AS_NON_PRODUCING=${START_AS_NON_PRODUCING:-false}
4749
# mithril and devnet
4850
case ${CARDANO_NETWORK} in
4951
mainnet|preprod) __path=release-${CARDANO_NETWORK} ;;
@@ -92,6 +94,7 @@ echo CARDANO_PORT=${CARDANO_PORT}
9294
echo CARDANO_RTS_OPTS=${CARDANO_RTS_OPTS}
9395
echo CARDANO_SOCKET_PATH=${CARDANO_SOCKET_PATH}
9496
echo CARDANO_TOPOLOGY=${CARDANO_TOPOLOGY}
97+
echo START_AS_NON_PRODUCING=${START_AS_NON_PRODUCING}
9598

9699
# block producer only
97100
if [[ ${CARDANO_BLOCK_PRODUCER} == true ]]; then
@@ -170,6 +173,10 @@ if [[ ${CARDANO_BLOCK_PRODUCER} == true ]]; then
170173
--shelley-vrf-key ${CARDANO_SHELLEY_VRF_KEY} \
171174
--socket-path ${CARDANO_SOCKET_PATH} \
172175
--topology ${CARDANO_TOPOLOGY})
176+
# Add --start-as-non-producing-node flag if START_AS_NON_PRODUCING is true
177+
if [[ ${START_AS_NON_PRODUCING} == true ]]; then
178+
effopts+=(--start-as-non-producing-node)
179+
fi
173180
else
174181
effopts=(--config ${CARDANO_CONFIG} \
175182
--database-path ${CARDANO_DATABASE_PATH} \

0 commit comments

Comments
 (0)