Skip to content

Commit

Permalink
Replaced create-shelley-genesis-and-keys and renew-kes-keys scrip…
Browse files Browse the repository at this point in the history
…ts in the

`shell.nix` file by external scripts. [skip ci]
  • Loading branch information
dnadales authored and jbgi committed Apr 6, 2021
1 parent ae960b0 commit fd60103
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 99 deletions.
4 changes: 3 additions & 1 deletion scripts/create-shelley-genesis-and-keys.sh
Expand Up @@ -73,4 +73,6 @@ for i in `seq $((${#BFT_NODES[@]}+1)) $TOTAL_NODES`; do
--signing-key-file node-vrf$i.skey
done

# ${renew-kes-keys}/bin/new-KES-keys-at-period 0
cd ../../

./scripts/renew-kes-keys.sh 0 ${#BFT_NODES[@]} $TOTAL_NODES
49 changes: 49 additions & 0 deletions scripts/renew-kes-keys.sh
@@ -0,0 +1,49 @@
#!/usr/bin/env bash
#
# This script assumes:
#
# - the kes period is passed as the first argument,
# - the number of bft nodes is passed as second argument,
# - the total number of nodes is passed as third argument,
# - the node keys are in a keys/node-keys directory, which must exist.
#
set -euo pipefail

[ -z ${1+x} ] && (echo "Missing KES period (must be passed as first argument)"; exit 1);
[ -z ${2+x} ] && (echo "Missing number of BFT nodes (must be passed as second argument)"; exit 1);
[ -z ${3+x} ] && (echo "Missing total number of nodes (must be passed as third argument)"; exit 1);

PERIOD=$1
NR_BFT_NODES=$2
TOTAL_NODES=$3
cd keys/node-keys

# Generate a KES key pair
for i in `seq 1 $TOTAL_NODES`; do
cardano-cli shelley node key-gen-KES \
--verification-key-file node-kes$i.vkey \
--signing-key-file node-kes$i.skey
done
# Genereate an operational certificate for the BFT nodes, using the delegate
# keys as cold signing key.
for i in `seq 1 $NR_BFT_NODES`; do
cardano-cli shelley node issue-op-cert \
--hot-kes-verification-key-file node-kes$i.vkey \
--cold-signing-key-file ../delegate-keys/delegate$i.skey \
--operational-certificate-issue-counter ../delegate-keys/delegate$i.counter \
--kes-period $PERIOD \
--out-file node$i.opcert
done
# For the pool nodes we need to generate the cold keys and the cold counter.
for i in `seq $((NR_BFT_NODES+1)) $TOTAL_NODES`; do
cardano-cli shelley node key-gen \
--cold-verification-key-file cold$i.vkey \
--cold-signing-key-file cold$i.skey \
--operational-certificate-issue-counter-file cold$i.counter
cardano-cli shelley node issue-op-cert \
--hot-kes-verification-key-file node-kes$i.vkey \
--cold-signing-key-file cold$i.skey \
--operational-certificate-issue-counter cold$i.counter \
--kes-period $PERIOD \
--out-file node$i.opcert
done
98 changes: 0 additions & 98 deletions shell.nix
Expand Up @@ -27,104 +27,6 @@ let
echo $hoursUntilNextEpoch
'';

var = 21;

foo =
writeShellScriptBin "foo" (import ./examples/shelley-testnet/scripts/hello.nix { inherit var pparams; });

# Protocol parameters
pparams =
rec { k = 10;
f = 0.1;
epoch-length= (10 * k) / f;
bftCoreNodes = map (x: x.name) globals.topology.bftCoreNodes;
stakePoolNodes = map (x: x.name) globals.topology.stakePoolNodes;
};

create-shelley-genesis-and-keys =
let nbCoreNodes = builtins.length globals.topology.coreNodes;
nbBFTNodes = builtins.length globals.topology.bftCoreNodes;
nbStakePoolNodes = builtins.length globals.topology.stakePoolNodes;
maxSupply = 20000000000000000 * nbCoreNodes;
in writeShellScriptBin "create-shelley-genesis-and-keys" ''
set -euxo pipefail
mkdir -p keys
cd ${toString ./keys}
cardano-cli shelley genesis create \
--genesis-dir . \
--supply ${toString maxSupply} \
--gen-genesis-keys ${toString nbBFTNodes} \
--gen-utxo-keys ${toString nbCoreNodes} \
--start-time `date -u -d "today + 10 minutes" +'%Y-%m-%dT%H:%M:%SZ'` \
--testnet-magic 42
# Customize the genesis file
#
# We should ensure that:
#
# 10 * securityParam / activeSlotsCoeff <= epochLength
K=10
F=0.1
SLOT_LENGTH=0.2
EPOCH_LENGTH=`perl -E "say ((10 * $K) / $F)"`
# jq will convert the big nunbers to scientific notation, and old versions of nix cannot handle this. Hence we need to use sed.
sed -Ei "s/^([[:blank:]]*\"updateQuorum\":)([[:blank:]]*[^,]*,)$/\1 ${toString nbBFTNodes},/" genesis.json
sed -Ei "s/^([[:blank:]]*\"epochLength\":)([[:blank:]]*[^,]*,)$/\1 $EPOCH_LENGTH,/" genesis.json
sed -Ei "s/^([[:blank:]]*\"slotLength\":)([[:blank:]]*[^,]*,)$/\1 $SLOT_LENGTH,/" genesis.json
sed -Ei "s/^([[:blank:]]*\"securityParam\":)([[:blank:]]*[^,]*)$/\1 $K/" genesis.json
sed -Ei "s/^([[:blank:]]*\"activeSlotsCoeff\":)([[:blank:]]*[^,]*,)$/\1 $F,/" genesis.json
cardano-cli shelley genesis hash --genesis genesis.json > GENHASH
mkdir -p node-keys
cd node-keys
# Create VRF keys for the BFT nodes.
for i in {1..${toString nbBFTNodes}}; do
ln -sf ../delegate-keys/delegate$i.vrf.skey node-vrf$i.skey
ln -sf ../delegate-keys/delegate$i.vrf.vkey node-vrf$i.vkey
done
# Create VRF keys for the pool nodes
for i in `seq $((${toString nbBFTNodes}+1)) ${toString nbCoreNodes}`; do
cardano-cli shelley node key-gen-VRF \
--verification-key-file node-vrf$i.vkey \
--signing-key-file node-vrf$i.skey
done
${renew-kes-keys}/bin/new-KES-keys-at-period 0
'';
renew-kes-keys =
let nbCoreNodes = builtins.length globals.topology.coreNodes;
nbBFTNodes = builtins.length globals.topology.bftCoreNodes;
in writeShellScriptBin "new-KES-keys-at-period" ''
set -euxo pipefail
PERIOD=$1
cd ${toString ./keys}/node-keys
# Generate a KES key pair
for i in {1..${toString nbCoreNodes}}; do
cardano-cli shelley node key-gen-KES \
--verification-key-file node-kes$i.vkey \
--signing-key-file node-kes$i.skey
done
# Genereate an operational certificate for the BFT nodes, using the delegate keys as cold signing key.
for i in {1..${toString nbBFTNodes}}; do
cardano-cli shelley node issue-op-cert \
--hot-kes-verification-key-file node-kes$i.vkey \
--cold-signing-key-file ../delegate-keys/delegate$i.skey \
--operational-certificate-issue-counter ../delegate-keys/delegate$i.counter \
--kes-period $PERIOD \
--out-file node$i.opcert
done
# For the pool nodes we need to generate the cold keys and the cold counter.
for i in `seq $((${toString nbBFTNodes}+1)) ${toString nbCoreNodes}`; do
cardano-cli shelley node key-gen \
--cold-verification-key-file cold$i.vkey \
--cold-signing-key-file cold$i.skey \
--operational-certificate-issue-counter-file cold$i.counter
cardano-cli shelley node issue-op-cert \
--hot-kes-verification-key-file node-kes$i.vkey \
--cold-signing-key-file cold$i.skey \
--operational-certificate-issue-counter cold$i.counter \
--kes-period $PERIOD \
--out-file node$i.opcert
done
'';
test-cronjob-script = writeShellScriptBin "test-cronjob-script" ''
set -euxo pipefail
PARAM=$1
Expand Down

0 comments on commit fd60103

Please sign in to comment.