/
mkfiles.sh
executable file
·453 lines (363 loc) · 14.3 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
#!/usr/bin/env bash
set -e
#set -x
ROOT=example
BFT_NODES="node-bft1 node-bft2"
BFT_NODES_N="1 2"
NUM_BFT_NODES=2
POOL_NODES="node-pool1"
ALL_NODES="${BFT_NODES} ${POOL_NODES}"
NUM_UTXO_KEYS=1
MAX_SUPPLY=1000000000
INIT_SUPPLY=1000000000
NETWORK_MAGIC=42
SECURITY_PARAM=10
START_TIME=$(ghc -e 'fmap ((+30) . floor) Data.Time.Clock.POSIX.getPOSIXTime')
if ! mkdir "${ROOT}"; then
echo "The ${ROOT} directory already exists, please move or remove it"
exit
fi
# copy and tweak the configuration
cp configuration/defaults/byron-mainnet/configuration.yaml ${ROOT}/
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 's/RequiresNoMagic/RequiresMagic/'
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": 3002,
"valency": 1
}
, {
"addr": "127.0.0.1",
"port": 3003,
"valency": 1
}
]
}
EOF
echo 3001 > node-bft1/port
cat > node-bft2/topology.json <<EOF
{
"Producers": [
{
"addr": "127.0.0.1",
"port": 3001,
"valency": 1
}
, {
"addr": "127.0.0.1",
"port": 3003,
"valency": 1
}
]
}
EOF
echo 3002 > node-bft2/port
cat > node-pool1/topology.json <<EOF
{
"Producers": [
{
"addr": "127.0.0.1",
"port": 3001,
"valency": 1
}
, {
"addr": "127.0.0.1",
"port": 3002,
"valency": 1
}
]
}
EOF
echo 3003 > node-pool1/port
cat > byron.genesis.spec.json <<EOF
{
"heavyDelThd": "300000000000",
"maxBlockSize": "2000000",
"maxTxSize": "4096",
"maxHeaderSize": "2000000",
"maxProposalSize": "700",
"mpcThd": "20000000000000",
"scriptVersion": 0,
"slotDuration": "2000",
"softforkRule": {
"initThd": "900000000000000",
"minThd": "600000000000000",
"thdDecrement": "50000000000000"
},
"txFeePolicy": {
"multiplier": "43946000000",
"summand": "155381000000000"
},
"unlockStakeEpoch": "18446744073709551615",
"updateImplicit": "10000",
"updateProposalThd": "100000000000000",
"updateVoteThd": "1000000000000"
}
EOF
cardano-cli 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} \
--byron-formats \
--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
echo "====================================================================="
echo "Generated genesis keys and genesis files:"
echo
ls -1 byron/*
echo "====================================================================="
# Set up our template
mkdir shelley
cardano-cli shelley genesis create --testnet-magic 42 --genesis-dir shelley
# Then edit the 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.2/' \
-e 's/"activeSlotsCoeff": 5.0e-2/"activeSlotsCoeff": 0.1/' \
-e 's/"securityParam": 2160/"securityParam": 10/' \
-e 's/"epochLength": 432000/"epochLength": 1500/' \
-e 's/"maxLovelaceSupply": 0/"maxLovelaceSupply": 1000000000/' \
-e 's/"decentralisationParam": 1/"decentralisationParam": 0.7/'
# Now generate for real:
cardano-cli shelley genesis create \
--testnet-magic 42 \
--genesis-dir shelley/ \
--gen-genesis-keys ${NUM_BFT_NODES} \
--gen-utxo-keys 1
echo "====================================================================="
echo "Generated genesis keys and genesis files:"
echo
ls -1 shelley/*
echo "====================================================================="
echo "Generated genesis.json:"
echo
cat shelley/genesis.json
echo
echo "====================================================================="
echo "To start the nodes, in separate terminals use:"
echo
for NODE in ${ALL_NODES}; do
echo "cardano-node run \\"
echo " --config ${ROOT}/configuration.yaml \\"
echo " --topology ${ROOT}/${NODE}/topology.json \\"
echo " --database-path ${ROOT}/${NODE}/db \\"
echo " --socket-path ${ROOT}/${NODE}/node.sock \\"
if [ -f ${NODE}/byron/delegate.key ]; then
echo " --signing-key ${ROOT}/${NODE}/byron/delegate.key \\"
echo " --delegation-certificate ${ROOT}/${NODE}/byron/delegate.cert \\"
fi
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)"
done
# 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 shelley 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 shelley 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 shelley node key-gen-KES \
--verification-key-file ${NODE}/shelley/kes.vkey \
--signing-key-file ${NODE}/shelley/kes.skey
cardano-cli shelley 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
echo "Generated node operator keys (cold, hot) and operational certs:"
echo
ls -1 ${ALL_NODES}
echo "====================================================================="
# 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 shelley address key-gen \
--verification-key-file addresses/${ADDR}.vkey \
--signing-key-file addresses/${ADDR}.skey
# Stake address keys
cardano-cli shelley stake-address key-gen \
--verification-key-file addresses/${ADDR}-stake.vkey \
--signing-key-file addresses/${ADDR}-stake.skey
# Payment addresses
cardano-cli shelley address build \
--payment-verification-key-file addresses/${ADDR}.vkey \
--stake-verification-key-file addresses/${ADDR}-stake.vkey \
--testnet-magic 42 \
--out-file addresses/${ADDR}.addr
# Stake addresses
cardano-cli shelley stake-address build \
--stake-verification-key-file addresses/${ADDR}-stake.vkey \
--testnet-magic 42 \
--out-file addresses/${ADDR}-stake.addr
# Stake addresses registration certs
cardano-cli shelley 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 shelley 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
echo "Generated payment address keys, stake address keys,"
echo "stake address regitration certs, and stake address delegatation certs"
echo
ls -1 addresses/
echo "====================================================================="
# Next is to make the stake pool registration cert
for NODE in ${POOL_NODES}; do
cardano-cli shelley stake-pool registration-certificate \
--testnet-magic 42 \
--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 "Generated stake pool registration certs:"
ls -1 node-*/registration.cert
echo "====================================================================="
# Now we'll construct one whopper of a transaction that does everything
# just to show off that we can, and to make the script shorter
# We'll transfer all the funds to the user1, which delegates to pool1
# We'll register certs to:
# 1. register the pool-owner1 stake address
# 2. register the stake pool 1
# 3. register the user1 stake address
# 4. delegate from the user1 stake address to the stake pool
cardano-cli shelley transaction build-raw \
--ttl 1000 \
--fee 0 \
--tx-in $(cardano-cli shelley genesis initial-txin \
--testnet-magic 42 \
--verification-key-file shelley/utxo-keys/utxo1.vkey) \
--tx-out $(cat addresses/user1.addr)+${MAX_SUPPLY} \
--certificate-file addresses/pool-owner1-stake.reg.cert \
--certificate-file node-pool1/registration.cert \
--certificate-file addresses/user1-stake.reg.cert \
--certificate-file addresses/user1-stake.deleg.cert \
--out-file tx1.txbody
# So we'll need to sign this with a bunch of keys:
# 1. the initial utxo spending key, for the funds
# 2. the user1 stake address key, due to the delegatation cert
# 3. the pool1 owner key, due to the pool registration cert
# 3. the pool1 operator key, due to the pool registration cert
cardano-cli shelley transaction sign \
--signing-key-file shelley/utxo-keys/utxo1.skey \
--signing-key-file addresses/user1-stake.skey \
--signing-key-file node-pool1/owner.skey \
--signing-key-file node-pool1/shelley/operator.skey \
--testnet-magic 42 \
--tx-body-file tx1.txbody \
--out-file tx1.tx
echo "Generated a signed 'do it all' transaction:"
ls -1 tx1.tx
echo "====================================================================="
echo "So you can now do various things:"
echo " * Start the nodes"
echo " * Submit the initial 'do it all' transaction"
echo " * Query the node's ledger state"
echo
echo "To start the nodes, in separate terminals use:"
echo
for NODE in ${BFT_NODES}; do
echo "cardano-node run \\"
echo " --config ${ROOT}/configuration.yaml \\"
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"
done
for NODE in ${POOL_NODES}; do
echo "cardano-node run \\"
echo " --config ${ROOT}/configuration.yaml \\"
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)"
done
echo
echo "To submit the transaction"
echo
echo "CARDANO_NODE_SOCKET_PATH=${ROOT}/node-bft1/node.sock \\"
echo " cardano-cli shelley transaction submit \\"
echo " --tx-file ${ROOT}/tx1.tx \\"
echo " --testnet-magic 42"
echo
echo "Then wait until epoch #2 (counting from 0) starting at slot 3000"
echo "and query the stake distribution, and see if the pool node creates blocks"
echo
echo "CARDANO_NODE_SOCKET_PATH=example/node-bft1/node.sock \\"
echo " cardano-cli shelley query stake-distribution --testnet-magic 42"
echo
popd