Skip to content

Commit

Permalink
WIP CAD-2726 supervisord: genesis caching from 'cardano-ops'
Browse files Browse the repository at this point in the history
  • Loading branch information
deepfire committed Mar 3, 2021
1 parent 648b61f commit 484bc94
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
5 changes: 4 additions & 1 deletion nix/supervisord-cluster/default.nix
Expand Up @@ -3,6 +3,7 @@
, bech32
, basePort ? 30000
, stateDir ? "./state-cluster"
, cacheDir ? "./.cache"
, extraSupervisorConfig ? {}
, useCabalRun ? false
##
Expand Down Expand Up @@ -45,7 +46,7 @@ let
mkGenesisBash = pkgs.callPackage ./genesis.nix
{ inherit
lib
stateDir
cacheDir stateDir
baseEnvConfig
basePort
profile;
Expand Down Expand Up @@ -73,6 +74,8 @@ let
--trace | --debug ) set -x;;
* ) break;; esac; shift; done
mkdir -p ${cacheDir}
if [ -f ${stateDir}/supervisord.pid ]
then
echo "Cluster already running. Please run `stop-cluster` first!"
Expand Down
22 changes: 18 additions & 4 deletions nix/supervisord-cluster/genesis.nix
Expand Up @@ -3,6 +3,7 @@
, writeText
##
, path
, cacheDir
, stateDir
, baseEnvConfig
, basePort
Expand All @@ -17,7 +18,7 @@ let
''
system_start_epoch=$(date +%s --date="${genesis.genesis_future_offset}")
system_start_human=$(date --utc +"%Y-%m-%dT%H:%M:%SZ" --date=@$system_start_epoch)
'';;
'';
byronGenesis =
''
cli_args=(
Expand Down Expand Up @@ -58,7 +59,16 @@ let
}
' --null-input > ${stateDir}/byron-protocol-params.json
cli byron genesis genesis ''${cli_args[@]}
'';;
'';
shelleyGenesisCache =
genesisParams:
''
genesis_params_hash=$(jq . --sort-keys <<<'${genesisParams}' |
sha1sum | cut -c-7)
genesis_cache_id=$(jq <<<$genesis_params \
'"k\(.n_pools)-d\(.dense_pool_density)-\(.delegators / 1000)kD-\(.utxo / 1000)kU-\(params_hash)"
' --arg params_hash "$genesis_params_hash" --raw-output)
'';
shelleyGenesisSpec =
''
cli genesis create --genesis-dir ${stateDir}/shelley/ \
Expand Down Expand Up @@ -271,13 +281,17 @@ let
--tx-body-file "${stateDir}/shelley/transfer-register-delegate-tx.txbody" \
--out-file "${stateDir}/shelley/transfer-register-delegate-tx.tx"
'';

genesisCacheDir = "${cacheDir}/genesis";
in
''
PATH=$PATH:${path}
mkdir -p ${stateDir}/{shelley,webserver}
mkdir -p ${stateDir}/{shelley,webserver} ${genesisCacheDir}
${shelleyGenesisCache (__toJSON genesis)}
cat <<EOF
Generating genesis for ${name}:
Generating genesis for ${name} (cache id $genesis_cache_id):
- BFT hosts: ${toString composition.n_bft_hosts}
- pool hosts: ${toString (composition.n_hosts - composition.n_bft_hosts)}
- pools: ${toString composition.n_pools}, of them:
Expand Down

0 comments on commit 484bc94

Please sign in to comment.