-
Notifications
You must be signed in to change notification settings - Fork 1
/
mkfiles.sh
executable file
·535 lines (441 loc) · 18.2 KB
/
mkfiles.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
#!/usr/bin/env bash
set -e
# Unofficial bash strict mode.
# See: http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -u
set -o pipefail
# This script sets up a cluster that starts out in Byron, and can transition to Mary.
#
# The script generates all the files needed for the setup, and prints commands
# to be run manually (to start the nodes, post transactions, etc.).
#
# There are three ways of triggering the transition to Shelley:
# 1. Trigger transition at protocol version 2.0.0 (as on mainnet)
# The system starts at 0.0.0, and we can only increase it by 1 in the major
# version, so this does require to
# a) post an update proposal and votes to transition to 1.0.0
# b) wait for the protocol to change (end of the epoch, or end of the last
# epoch if it's posted near the end of the epoch)
# c) change configuration.yaml to have 'LastKnownBlockVersion-Major: 2',
# and restart the nodes
# d) post an update proposal and votes to transition to 2.0.0
# This is what will happen on the mainnet, so it's vital to test this, but
# it does contain some manual steps.
# 2. Trigger transition at protocol version 2.0.0
# For testing purposes, we can also modify the system to do the transition to
# Shelley at protocol version 1.0.0, by uncommenting the line containing
# 'TestShelleyHardForkAtVersion' below. Then, we just need to execute step a)
# above in order to trigger the transition.
# This is still close to the procedure on the mainnet, and requires less
# manual steps.
# 3. Schedule transition in the configuration
# To do this, uncomment the line containing 'TestShelleyHardForkAtEpoch'
# below. It's good for a quick test, and does not rely on posting update
# proposals to the chain.
# This is quite convenient, but it does not test that we can do the
# transition by posting update proposals to the network. For even more convenience
# if you want to start a node in Shelley, Allegra or Mary from epoch 0, supply the script
# with a shelley, allegra or mary string argument. E.g mkfiles.sh mary.
ROOT=example
BFT_NODES="node-bft1"
BFT_NODES_N="1"
NUM_BFT_NODES=1
POOL_NODES="node-pool1"
ALL_NODES="${BFT_NODES} ${POOL_NODES}"
INIT_SUPPLY=45000000000000000
FUNDS_PER_GENESIS_ADDRESS=$((${INIT_SUPPLY} / ${NUM_BFT_NODES}))
FUNDS_PER_BYRON_ADDRESS=$((${FUNDS_PER_GENESIS_ADDRESS} - 1000000000000))
# We need to allow for a fee to transfer the funds out of the genesis.
# We don't care too much, 1 ada is more than enough.
NETWORK_MAGIC=141
SECURITY_PARAM=36
UNAME=$(uname -s) DATE=
case $UNAME in
Darwin ) DATE="gdate";;
Linux ) DATE="date";;
MINGW64_NT* ) UNAME="Windows_NT"
DATE="date";;
esac
START_TIME="$(${DATE} -d "now + 60 seconds" +%s)"
START_TIME_SHELLEY="$(TZ=UTC date --date=@${START_TIME} +%Y-%m-%dT%H:%M:%SZ)"
if ! mkdir "${ROOT}"; then
echo "The ${ROOT} directory already exists, please move or remove it"
exit
fi
# copy and tweak the configuration
cp config.json ${ROOT}/config.json
#sed -i ${ROOT}/configuration.yaml \
# -e 's/Protocol: RealPBFT/Protocol: Cardano/' \
# -e '/Protocol/ aPBftSignatureThreshold: 0.6' \
# -e 's/minSeverity: Info/minSeverity: Debug/' \
# -e 's|GenesisFile: genesis.json|ByronGenesisFile: byron/genesis.json|' \
# -e '/ByronGenesisFile/ aShelleyGenesisFile: shelley/genesis.json' \
# -e '/ByronGenesisFile/ aAlonzoGenesisFile: shelley/genesis.alonzo.json' \
# -e 's/RequiresNoMagic/RequiresMagic/' \
# -e 's/LastKnownBlockVersion-Major: 0/LastKnownBlockVersion-Major: 1/' \
# -e 's/LastKnownBlockVersion-Minor: 2/LastKnownBlockVersion-Minor: 0/'
# Options for making it easier to trigger the transition to Shelley
# If neither of those are used, we have to
# - post an update proposal + votes to go to protocol version 1
# - after that's activated, change the configuration to have
# 'LastKnownBlockVersion-Major: 2', and restart the nodes
# - post another proposal + vote to go to protocol version 2
#uncomment this for an automatic transition after the first epoch
# echo "TestShelleyHardForkAtEpoch: 1" >> ${ROOT}/configuration.yaml
#uncomment this to trigger the hardfork with protocol version 1
#echo "TestShelleyHardForkAtVersion: 1" >> ${ROOT}/configuration.yaml
pushd ${ROOT}
# create the node directories
for NODE in ${ALL_NODES}; do
mkdir "${NODE}" "${NODE}/byron" "${NODE}/shelley"
done
# Make topology files
#TODO generalise this over the N BFT nodes and pool nodes
cat > node-bft1/topology.json <<EOF
{
"Producers": [
{
"addr": "127.0.0.1",
"port": 3001,
"valency": 1
}
, {
"addr": "127.0.0.1",
"port": 3003,
"valency": 1
}
]
}
EOF
echo 3001 > node-bft1/port
cat > node-pool1/topology.json <<EOF
{
"Producers": [
{
"addr": "127.0.0.1",
"port": 3001,
"valency": 1
}
, {
"addr": "127.0.0.1",
"port": 300333,
"valency": 1
}
]
}
EOF
echo 3003 > node-pool1/port
cat > byron.genesis.spec.json <<EOF
{
"heavyDelThd": "300000",
"maxBlockSize": "641000",
"maxTxSize": "4096",
"maxHeaderSize": "200000",
"maxProposalSize": "700",
"mpcThd": "200000",
"scriptVersion": 0,
"slotDuration": "100",
"softforkRule": {
"initThd": "900000",
"minThd": "600000",
"thdDecrement": "100000"
},
"txFeePolicy": {
"multiplier": "439460",
"summand": "0"
},
"unlockStakeEpoch": "184467",
"updateImplicit": "10000",
"updateProposalThd": "100000",
"updateVoteThd": "100000"
}
EOF
cardano-cli byron genesis genesis \
--protocol-magic ${NETWORK_MAGIC} \
--start-time "${START_TIME}" \
--k ${SECURITY_PARAM} \
--n-poor-addresses 0 \
--n-delegate-addresses ${NUM_BFT_NODES} \
--total-balance ${INIT_SUPPLY} \
--delegate-share 1 \
--avvm-entry-count 0 \
--avvm-entry-balance 0 \
--protocol-parameters-file byron.genesis.spec.json \
--genesis-output-dir byron
mv byron.genesis.spec.json byron/genesis.spec.json
# Symlink the BFT operator keys from the genesis delegates, for uniformity
for N in ${BFT_NODES_N}; do
ln -s ../../byron/delegate-keys.00$((${N} - 1)).key "node-bft${N}/byron/delegate.key"
ln -s ../../byron/delegation-cert.00$((${N} - 1)).json "node-bft${N}/byron/delegate.cert"
done
# Create keys, addresses and transactions to withdraw the initial UTxO into
# regular addresses.
for N in ${BFT_NODES_N}; do
cardano-cli byron key keygen \
--secret byron/payment-keys.00$((${N} - 1)).key \
cardano-cli byron key signing-key-address \
--testnet-magic ${NETWORK_MAGIC} \
--secret byron/payment-keys.00$((${N} - 1)).key > byron/address-00$((${N} - 1))
cardano-cli byron key signing-key-address \
--testnet-magic ${NETWORK_MAGIC} \
--secret byron/genesis-keys.00$((${N} - 1)).key > byron/genesis-address-00$((${N} - 1))
cardano-cli byron transaction issue-genesis-utxo-expenditure \
--genesis-json byron/genesis.json \
--testnet-magic ${NETWORK_MAGIC} \
--tx tx$((${N} - 1)).tx \
--wallet-key byron/delegate-keys.00$((${N} - 1)).key \
--rich-addr-from "$(head -n 1 byron/genesis-address-00$((${N} - 1)))" \
--txout "(\"$(head -n 1 byron/address-00$((${N} - 1)))\", $FUNDS_PER_BYRON_ADDRESS)"
done
# Update Proposal and votes
cardano-cli byron governance create-update-proposal \
--filepath update-proposal \
--testnet-magic "${NETWORK_MAGIC}" \
--signing-key byron/delegate-keys.000.key \
--protocol-version-major 1 \
--protocol-version-minor 0 \
--protocol-version-alt 0 \
--application-name "cardano-sl" \
--software-version-num 1 \
--system-tag "linux" \
--installer-hash 0
for N in ${BFT_NODES_N}; do
cardano-cli byron governance create-proposal-vote \
--proposal-filepath update-proposal \
--testnet-magic ${NETWORK_MAGIC} \
--signing-key byron/delegate-keys.00$((${N} - 1)).key \
--vote-yes \
--output-filepath update-vote.00$((${N} - 1))
done
cardano-cli byron governance create-update-proposal \
--filepath update-proposal-1 \
--testnet-magic ${NETWORK_MAGIC} \
--signing-key byron/delegate-keys.000.key \
--protocol-version-major 2 \
--protocol-version-minor 0 \
--protocol-version-alt 0 \
--application-name "cardano-sl" \
--software-version-num 1 \
--system-tag "linux" \
--installer-hash 0
for N in ${BFT_NODES_N}; do
cardano-cli byron governance create-proposal-vote \
--proposal-filepath update-proposal-1 \
--testnet-magic ${NETWORK_MAGIC} \
--signing-key byron/delegate-keys.00$((${N} - 1)).key \
--vote-yes \
--output-filepath update-vote-1.00$((${N} - 1))
done
# Set up our template
mkdir shelley
cardano-cli genesis create --testnet-magic ${NETWORK_MAGIC} --genesis-dir shelley
# Then edit the genesis.spec.json ...
cp ../alonzo-genesis.json shelley/genesis.alonzo.spec.json
cp ../shelley-genesis.json shelley/genesis.spec.json
# We're going to use really quick epochs (300 seconds), by using short slots 0.2s
# and K=10, but we'll keep long KES periods so we don't have to bother
# cycling KES keys
#sed -i shelley/genesis.spec.json \
# -e 's/"slotLength": 1/"slotLength": 0.1/' \
# -e 's/"activeSlotsCoeff": 5.0e-2/"activeSlotsCoeff": 0.1/' \
# -e 's/"securityParam": 2160/"securityParam": 10/' \
# -e 's/"epochLength": 432000/"epochLength": 500/' \
# -e 's/"maxLovelaceSupply": 0/"maxLovelaceSupply": 1000000000000/' \
# -e 's/"minFeeA": 1/"minFeeA": 44/' \
# -e 's/"minFeeB": 0/"minFeeB": 155381/' \
# -e 's/"minUTxOValue": 0/"minUTxOValue": 1000000/' \
# -e 's/"decentralisationParam": 1.0/"decentralisationParam": 0.7/' \
# -e 's/"major": 0/"major": 5/' \
# -e 's/"rho": 0.0/"rho": 0.1/' \
# -e 's/"tau": 0.0/"tau": 0.1/' \
# -e 's/"updateQuorum": 5/"updateQuorum": 2/'
# Now generate for real:
cardano-cli genesis create \
--testnet-magic ${NETWORK_MAGIC} \
--genesis-dir shelley/ \
--gen-genesis-keys ${NUM_BFT_NODES} \
--gen-utxo-keys 0 \
--start-time ${START_TIME_SHELLEY}
cp ../alonzo-genesis.json shelley/genesis.alonzo.spec.json
# Make the pool operator cold keys
# This was done already for the BFT nodes as part of the genesis creation
for NODE in ${POOL_NODES}; do
cardano-cli node key-gen \
--cold-verification-key-file ${NODE}/shelley/operator.vkey \
--cold-signing-key-file ${NODE}/shelley/operator.skey \
--operational-certificate-issue-counter-file ${NODE}/shelley/operator.counter
cardano-cli node key-gen-VRF \
--verification-key-file ${NODE}/shelley/vrf.vkey \
--signing-key-file ${NODE}/shelley/vrf.skey
done
# Symlink the BFT operator keys from the genesis delegates, for uniformity
for N in ${BFT_NODES_N}; do
ln -s ../../shelley/delegate-keys/delegate${N}.skey node-bft${N}/shelley/operator.skey
ln -s ../../shelley/delegate-keys/delegate${N}.vkey node-bft${N}/shelley/operator.vkey
ln -s ../../shelley/delegate-keys/delegate${N}.counter node-bft${N}/shelley/operator.counter
ln -s ../../shelley/delegate-keys/delegate${N}.vrf.vkey node-bft${N}/shelley/vrf.vkey
ln -s ../../shelley/delegate-keys/delegate${N}.vrf.skey node-bft${N}/shelley/vrf.skey
done
# Make hot keys and for all nodes
for NODE in ${ALL_NODES}; do
cardano-cli node key-gen-KES \
--verification-key-file ${NODE}/shelley/kes.vkey \
--signing-key-file ${NODE}/shelley/kes.skey
cardano-cli node issue-op-cert \
--kes-period 0 \
--kes-verification-key-file ${NODE}/shelley/kes.vkey \
--cold-signing-key-file ${NODE}/shelley/operator.skey \
--operational-certificate-issue-counter-file ${NODE}/shelley/operator.counter \
--out-file ${NODE}/shelley/node.cert
done
# Make some payment and stake addresses
# user1..n: will own all the funds in the system, we'll set this up from
# initial utxo the
# pool-owner1..n: will be the owner of the pools and we'll use their reward
# account for pool rewards
USER_ADDRS="user1"
POOL_ADDRS="pool-owner1"
ADDRS="${USER_ADDRS} ${POOL_ADDRS}"
mkdir addresses
for ADDR in ${ADDRS}; do
# Payment address keys
cardano-cli address key-gen \
--verification-key-file addresses/${ADDR}.vkey \
--signing-key-file addresses/${ADDR}.skey
# Stake address keys
cardano-cli stake-address key-gen \
--verification-key-file addresses/${ADDR}-stake.vkey \
--signing-key-file addresses/${ADDR}-stake.skey
# Payment addresses
cardano-cli address build \
--payment-verification-key-file addresses/${ADDR}.vkey \
--stake-verification-key-file addresses/${ADDR}-stake.vkey \
--testnet-magic ${NETWORK_MAGIC} \
--out-file addresses/${ADDR}.addr
# Stake addresses
cardano-cli stake-address build \
--stake-verification-key-file addresses/${ADDR}-stake.vkey \
--testnet-magic ${NETWORK_MAGIC} \
--out-file addresses/${ADDR}-stake.addr
# Stake addresses registration certs
cardano-cli stake-address registration-certificate \
--stake-verification-key-file addresses/${ADDR}-stake.vkey \
--out-file addresses/${ADDR}-stake.reg.cert
done
# user N will delegate to pool N
USER_POOL_N="1"
for N in ${USER_POOL_N}; do
# Stake address delegation certs
cardano-cli stake-address delegation-certificate \
--stake-verification-key-file addresses/user${N}-stake.vkey \
--cold-verification-key-file node-pool${N}/shelley/operator.vkey \
--out-file addresses/user${N}-stake.deleg.cert
ln -s ../addresses/pool-owner${N}-stake.vkey node-pool${N}/owner.vkey
ln -s ../addresses/pool-owner${N}-stake.skey node-pool${N}/owner.skey
done
# Next is to make the stake pool registration cert
for NODE in ${POOL_NODES}; do
cardano-cli stake-pool registration-certificate \
--testnet-magic ${NETWORK_MAGIC} \
--pool-pledge 0 --pool-cost 0 --pool-margin 0 \
--cold-verification-key-file ${NODE}/shelley/operator.vkey \
--vrf-verification-key-file ${NODE}/shelley/vrf.vkey \
--reward-account-verification-key-file ${NODE}/owner.vkey \
--pool-owner-stake-verification-key-file ${NODE}/owner.vkey \
--out-file ${NODE}/registration.cert
done
echo "So you can now do various things:"
echo " * Start the nodes"
echo " * Initiate successive protocol updates"
echo " * Query the node's ledger state"
echo
echo "To start the nodes, in separate terminals use the following scripts:"
echo
mkdir -p run
for NODE in ${BFT_NODES}; do
(
echo "#!/usr/bin/env bash"
echo ""
echo "cardano-node run \\"
echo " --config ${ROOT}/config.json \\"
echo " --topology ${ROOT}/${NODE}/topology.json \\"
echo " --database-path ${ROOT}/${NODE}/db \\"
echo " --socket-path ${ROOT}/${NODE}/node.sock \\"
echo " --shelley-kes-key ${ROOT}/${NODE}/shelley/kes.skey \\"
echo " --shelley-vrf-key ${ROOT}/${NODE}/shelley/vrf.skey \\"
echo " --shelley-operational-certificate ${ROOT}/${NODE}/shelley/node.cert \\"
echo " --port $(cat ${NODE}/port) \\"
echo " --delegation-certificate ${ROOT}/${NODE}/byron/delegate.cert \\"
echo " --signing-key ${ROOT}/${NODE}/byron/delegate.key \\"
echo " | tee -a ${ROOT}/${NODE}/node.log"
) > run/${NODE}.sh
chmod a+x run/${NODE}.sh
echo $ROOT/run/${NODE}.sh
done
for NODE in ${POOL_NODES}; do
(
echo "#!/usr/bin/env bash"
echo ""
echo "cardano-node run \\"
echo " --config ${ROOT}/config.json \\"
echo " --topology ${ROOT}/${NODE}/topology.json \\"
echo " --database-path ${ROOT}/${NODE}/db \\"
echo " --socket-path ${ROOT}/${NODE}/node.sock \\"
echo " --shelley-kes-key ${ROOT}/${NODE}/shelley/kes.skey \\"
echo " --shelley-vrf-key ${ROOT}/${NODE}/shelley/vrf.skey \\"
echo " --shelley-operational-certificate ${ROOT}/${NODE}/shelley/node.cert \\"
echo " --port $(cat ${NODE}/port) \\"
echo " | tee -a ${ROOT}/${NODE}/node.log"
) > run/${NODE}.sh
chmod a+x run/${NODE}.sh
echo $ROOT/run/${NODE}.sh
done
echo "#!/usr/bin/env bash" > run/all.sh
echo "" >> run/all.sh
chmod a+x run/all.sh
for NODE in ${BFT_NODES}; do
echo "$ROOT/run/${NODE}.sh &" >> run/all.sh
done
for NODE in ${POOL_NODES}; do
echo "$ROOT/run/${NODE}.sh &" >> run/all.sh
done
echo "" >> run/all.sh
echo "wait" >> run/all.sh
chmod a+x run/all.sh
echo
echo "Alternatively, you can run all the nodes in one go:"
echo
echo "$ROOT/run/all.sh"
echo
echo "In order to do the protocol updates, proceed as follows:"
echo
echo " 0. wait for the nodes to start producing blocks"
echo " 1. invoke ./scripts/byron-to-alonzo/update-1.sh"
echo " wait for the next epoch for the update to take effect"
echo
echo " 2. invoke ./scripts/byron-to-alonzo/update-2.sh"
echo " 3. restart the nodes"
echo " wait for the next epoch for the update to take effect"
echo
echo " 4. invoke ./scripts/byron-to-alonzo/update-3.sh <N>"
echo " Here, <N> the current epoch (2 if you're quick)."
echo " If you provide the wrong epoch, you will see an error"
echo " that will tell you the current epoch, and can run"
echo " the script again."
echo " 5. restart the nodes"
echo " wait for the next epoch for the update to take effect"
echo " 6. invoke ./scripts/byron-to-alonzo/update-4.sh <N>"
echo " 7. restart the nodes"
echo
echo "You can observe the status of the updates by grepping the logs, via"
echo
echo " grep LedgerUpdate ${ROOT}/node-pool1/node.log"
echo
echo "When in Shelley (after 3, and before 4), you should be able "
echo "to look at the protocol parameters, or the ledger state, "
echo "using commands like"
echo
echo "CARDANO_NODE_SOCKET_PATH=${ROOT}/node-bft1/node.sock \\"
echo " cardano-cli query protocol-parameters --testnet-magic ${NETWORK_MAGIC}"
echo
popd