Skip to content

Commit 0cc7851

Browse files
committed
refactor(config): modularize node config editing logic
Split node config editing in start scripts into two dedicated functions: `edit_genesis_conf` and `edit_utxo_backend_conf`, now defined in `common.sh`. This improves maintainability and clarity by separating genesis and UTXO backend configuration logic. The start scripts now call these functions for each node config, reducing duplication and making future changes easier.
1 parent 00e51df commit 0cc7851

File tree

3 files changed

+78
-92
lines changed

3 files changed

+78
-92
lines changed

src/cardonnay_scripts/scripts/common/common-start-fast

Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,14 @@ get_genesis_data() {
202202

203203
edit_node_configs() {
204204
local live_tables_base="${STATE_CLUSTER_NAME}/lmdb"
205-
local conf fname node_name pool_num utxo_backend
205+
local conf conf_target fname node_name pool_num utxo_backend
206206

207207
for conf in "$SCRIPT_DIR"/config-*.json; do
208208
[ -e "$conf" ] || { echo "No config files found in ${SCRIPT_DIR}, line $LINENO in ${BASH_SOURCE[0]}" >&2; exit 1; }
209209
fname="${conf##*/}"
210210
node_name="${fname##config-}"
211211
node_name="${node_name%.json}"
212+
conf_target="${STATE_CLUSTER}/${fname}"
212213

213214
if [ "$fname" = "config-bft1.json" ]; then
214215
pool_num=""
@@ -217,58 +218,18 @@ edit_node_configs() {
217218
pool_num="${pool_num%.json}"
218219
fi
219220

220-
utxo_backend="${UTXO_BACKEND}"
221-
# Rotate through the mixed backends for block producing nodes, if set.
222-
if [ -n "$pool_num" ] && [ "${#UTXO_BACKENDS[@]}" -gt 0 ]; then
223-
index=$(( (pool_num - 1) % ${#UTXO_BACKENDS[@]} ))
224-
utxo_backend="${UTXO_BACKENDS[$index]}"
225-
fi
226-
if [ "$utxo_backend" = "empty" ]; then
227-
utxo_backend=""
228-
fi
229-
230221
jq \
231-
--arg byron_hash "$BYRON_GENESIS_HASH" \
232-
--arg shelley_hash "$SHELLEY_GENESIS_HASH" \
233-
--arg alonzo_hash "$ALONZO_GENESIS_HASH" \
234-
--arg conway_hash "$CONWAY_GENESIS_HASH" \
235-
--arg dijkstra_hash "$DIJKSTRA_GENESIS_HASH" \
236222
--argjson prot_ver "$PROTOCOL_VERSION" \
237-
--arg backend "$utxo_backend" \
238-
--arg live_tables_path "${live_tables_base}-${node_name}" \
239-
'.ByronGenesisHash = $byron_hash
240-
| .ShelleyGenesisHash = $shelley_hash
241-
| .AlonzoGenesisHash = $alonzo_hash
242-
| .ConwayGenesisHash = $conway_hash
243-
| if $dijkstra_hash != "" then
244-
(.DijkstraGenesisFile = "shelley/genesis.dijkstra.json"
245-
| .DijkstraGenesisHash = $dijkstra_hash
246-
| .ExperimentalHardForksEnabled = true)
247-
else
248-
.
249-
end
250-
| if $prot_ver >= 12 then
223+
' if $prot_ver >= 12 then
251224
.TestDijkstraHardForkAtEpoch = 0
252225
else
253226
.
254227
end
255228
| ."LastKnownBlockVersion-Major" = $prot_ver
256-
| if $backend == "mem" then
257-
(.LedgerDB.Backend = "V2InMemory"
258-
| .LedgerDB.SnapshotInterval = 216)
259-
elif $backend == "disk" then
260-
.LedgerDB.Backend = "V2LSM"
261-
elif $backend == "disklmdb" then
262-
(.LedgerDB.Backend = "V1LMDB"
263-
| .LedgerDB.LiveTablesPath = $live_tables_path
264-
| .LedgerDB.SnapshotInterval = 300)
265-
elif has("LedgerDB") then
266-
.LedgerDB |= del(.Backend)
267-
else
268-
.
269-
end
270-
| if (.LedgerDB? // {}) == {} then del(.LedgerDB) else . end
271-
' "$conf" > "${STATE_CLUSTER}/${fname}"
229+
' "$conf" > "$conf_target"
230+
231+
edit_genesis_conf "$conf_target"
232+
edit_utxo_backend_conf "$conf_target" "$node_name" "$pool_num"
272233
done
273234
}
274235

src/cardonnay_scripts/scripts/common/common-start-slow

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,14 @@ get_genesis_data() {
204204

205205
edit_node_configs() {
206206
local live_tables_base="${STATE_CLUSTER_NAME}/lmdb"
207-
local conf fname node_name pool_num utxo_backend
207+
local conf conf_target fname node_name pool_num utxo_backend
208208

209209
for conf in "$SCRIPT_DIR"/config-*.json; do
210210
[ -e "$conf" ] || { echo "No config files found in ${SCRIPT_DIR}, line $LINENO in ${BASH_SOURCE[0]}" >&2; exit 1; }
211211
fname="${conf##*/}"
212212
node_name="${fname##config-}"
213213
node_name="${node_name%.json}"
214+
conf_target="${STATE_CLUSTER}/${fname}"
214215

215216
if [ "$fname" = "config-bft1.json" ]; then
216217
pool_num=""
@@ -219,52 +220,10 @@ edit_node_configs() {
219220
pool_num="${pool_num%.json}"
220221
fi
221222

222-
utxo_backend="${UTXO_BACKEND}"
223-
# Rotate through the mixed backends for block producing nodes, if set.
224-
if [ -n "$pool_num" ] && [ "${#UTXO_BACKENDS[@]}" -gt 0 ]; then
225-
index=$(( (pool_num - 1) % ${#UTXO_BACKENDS[@]} ))
226-
utxo_backend="${UTXO_BACKENDS[$index]}"
227-
fi
228-
if [ "$utxo_backend" = "empty" ]; then
229-
utxo_backend=""
230-
fi
223+
cp "$conf" "$conf_target"
231224

232-
jq \
233-
--arg byron_hash "$BYRON_GENESIS_HASH" \
234-
--arg shelley_hash "$SHELLEY_GENESIS_HASH" \
235-
--arg alonzo_hash "$ALONZO_GENESIS_HASH" \
236-
--arg conway_hash "$CONWAY_GENESIS_HASH" \
237-
--arg dijkstra_hash "$DIJKSTRA_GENESIS_HASH" \
238-
--arg backend "$utxo_backend" \
239-
--arg live_tables_path "${live_tables_base}-${node_name}" \
240-
'.ByronGenesisHash = $byron_hash
241-
| .ShelleyGenesisHash = $shelley_hash
242-
| .AlonzoGenesisHash = $alonzo_hash
243-
| .ConwayGenesisHash = $conway_hash
244-
| if $dijkstra_hash != "" then
245-
(.DijkstraGenesisFile = "shelley/genesis.dijkstra.json"
246-
| .DijkstraGenesisHash = $dijkstra_hash
247-
| .ExperimentalProtocolsEnabled = true
248-
| .ExperimentalHardForksEnabled = true)
249-
else
250-
.
251-
end
252-
| if $backend == "mem" then
253-
(.LedgerDB.Backend = "V2InMemory"
254-
| .LedgerDB.SnapshotInterval = 216)
255-
elif $backend == "disk" then
256-
.LedgerDB.Backend = "V2LSM"
257-
elif $backend == "disklmdb" then
258-
(.LedgerDB.Backend = "V1LMDB"
259-
| .LedgerDB.LiveTablesPath = $live_tables_path
260-
| .LedgerDB.SnapshotInterval = 300)
261-
elif has("LedgerDB") then
262-
.LedgerDB |= del(.Backend)
263-
else
264-
.
265-
end
266-
| if (.LedgerDB? // {}) == {} then del(.LedgerDB) else . end
267-
' "$conf" > "${STATE_CLUSTER}/${fname}"
225+
edit_genesis_conf "$conf_target"
226+
edit_utxo_backend_conf "$conf_target" "$node_name" "$pool_num"
268227
done
269228
}
270229

src/cardonnay_scripts/scripts/common/common.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,3 +491,69 @@ create_committee_keys_in_genesis() {
491491
cat "${STATE_CLUSTER}/shelley/genesis.conway.json_jq" > "${STATE_CLUSTER}/shelley/genesis.conway.json"
492492
rm -f "${STATE_CLUSTER}/shelley/genesis.conway.json_jq"
493493
}
494+
495+
edit_genesis_conf() {
496+
local conf="${1:?"Missing node config file"}"
497+
498+
jq \
499+
--arg byron_hash "$BYRON_GENESIS_HASH" \
500+
--arg shelley_hash "$SHELLEY_GENESIS_HASH" \
501+
--arg alonzo_hash "$ALONZO_GENESIS_HASH" \
502+
--arg conway_hash "$CONWAY_GENESIS_HASH" \
503+
--arg dijkstra_hash "$DIJKSTRA_GENESIS_HASH" \
504+
'.ByronGenesisHash = $byron_hash
505+
| .ShelleyGenesisHash = $shelley_hash
506+
| .AlonzoGenesisHash = $alonzo_hash
507+
| .ConwayGenesisHash = $conway_hash
508+
| if $dijkstra_hash != "" then
509+
(.DijkstraGenesisFile = "shelley/genesis.dijkstra.json"
510+
| .DijkstraGenesisHash = $dijkstra_hash
511+
| .ExperimentalProtocolsEnabled = true
512+
| .ExperimentalHardForksEnabled = true)
513+
else
514+
.
515+
end
516+
' "$conf" > "${conf}.json_jq"
517+
cat "${conf}.json_jq" > "$conf"
518+
rm -f "${conf}.json_jq"
519+
}
520+
521+
edit_utxo_backend_conf() {
522+
local conf="${1:?"Missing node config file"}"
523+
local node_name="${2:?"Missing node name"}"
524+
local pool_num="${3:-}"
525+
local live_tables_base="${STATE_CLUSTER_NAME:?}/lmdb"
526+
local utxo_backend index
527+
528+
utxo_backend="${UTXO_BACKEND:-}"
529+
# Rotate through the mixed backends for block producing nodes, if set.
530+
if [ -n "$pool_num" ] && [ "${#UTXO_BACKENDS[@]}" -gt 0 ]; then
531+
index=$(( (pool_num - 1) % ${#UTXO_BACKENDS[@]} ))
532+
utxo_backend="${UTXO_BACKENDS[$index]}"
533+
fi
534+
if [ "$utxo_backend" = "empty" ]; then
535+
utxo_backend=""
536+
fi
537+
538+
jq \
539+
--arg backend "$utxo_backend" \
540+
--arg live_tables_path "${live_tables_base}-${node_name}" \
541+
' if $backend == "mem" then
542+
(.LedgerDB.Backend = "V2InMemory"
543+
| .LedgerDB.SnapshotInterval = 216)
544+
elif $backend == "disk" then
545+
.LedgerDB.Backend = "V2LSM"
546+
elif $backend == "disklmdb" then
547+
(.LedgerDB.Backend = "V1LMDB"
548+
| .LedgerDB.LiveTablesPath = $live_tables_path
549+
| .LedgerDB.SnapshotInterval = 300)
550+
elif has("LedgerDB") then
551+
.LedgerDB |= del(.Backend)
552+
else
553+
.
554+
end
555+
| if (.LedgerDB? // {}) == {} then del(.LedgerDB) else . end
556+
' "$conf" > "${conf}.json_jq"
557+
cat "${conf}.json_jq" > "$conf"
558+
rm -f "${conf}.json_jq"
559+
}

0 commit comments

Comments
 (0)