Skip to content

Commit 0312e6c

Browse files
authored
Merge pull request #103 from IntersectMBO/dry_edit_config
refactor(config): modularize node config editing logic
2 parents 00e51df + 9eca379 commit 0312e6c

File tree

3 files changed

+78
-94
lines changed

3 files changed

+78
-94
lines changed

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

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,14 @@ get_genesis_data() {
201201
}
202202

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

207206
for conf in "$SCRIPT_DIR"/config-*.json; do
208207
[ -e "$conf" ] || { echo "No config files found in ${SCRIPT_DIR}, line $LINENO in ${BASH_SOURCE[0]}" >&2; exit 1; }
209208
fname="${conf##*/}"
210209
node_name="${fname##config-}"
211210
node_name="${node_name%.json}"
211+
conf_target="${STATE_CLUSTER}/${fname}"
212212

213213
if [ "$fname" = "config-bft1.json" ]; then
214214
pool_num=""
@@ -217,58 +217,18 @@ edit_node_configs() {
217217
pool_num="${pool_num%.json}"
218218
fi
219219

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-
230220
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" \
236221
--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
222+
' if $prot_ver >= 12 then
251223
.TestDijkstraHardForkAtEpoch = 0
252224
else
253225
.
254226
end
255227
| ."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}"
228+
' "$conf" > "$conf_target"
229+
230+
edit_genesis_conf "$conf_target"
231+
edit_utxo_backend_conf "$conf_target" "$node_name" "$pool_num"
272232
done
273233
}
274234

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

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,14 @@ get_genesis_data() {
203203
}
204204

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

209208
for conf in "$SCRIPT_DIR"/config-*.json; do
210209
[ -e "$conf" ] || { echo "No config files found in ${SCRIPT_DIR}, line $LINENO in ${BASH_SOURCE[0]}" >&2; exit 1; }
211210
fname="${conf##*/}"
212211
node_name="${fname##config-}"
213212
node_name="${node_name%.json}"
213+
conf_target="${STATE_CLUSTER}/${fname}"
214214

215215
if [ "$fname" = "config-bft1.json" ]; then
216216
pool_num=""
@@ -219,52 +219,10 @@ edit_node_configs() {
219219
pool_num="${pool_num%.json}"
220220
fi
221221

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
222+
cp "$conf" "$conf_target"
231223

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}"
224+
edit_genesis_conf "$conf_target"
225+
edit_utxo_backend_conf "$conf_target" "$node_name" "$pool_num"
268226
done
269227
}
270228

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)