Skip to content

Commit

Permalink
CAD-2515 bench: record genesis cache key & params
Browse files Browse the repository at this point in the history
  • Loading branch information
deepfire committed Jan 20, 2021
1 parent 5b709bd commit 64318b6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
23 changes: 22 additions & 1 deletion bench/bench.sh
Expand Up @@ -194,7 +194,27 @@ main() {

genesis ) profile_genesis ${1:-$(params resolve-profile 'default')};;
genesis-info | gi ) genesis_info "$@";;

profile-genesis-cache | pgc )
prof=$(profgenjq "$1" .)
cache_id=$(genesis_cache_id "$prof")
dir=../geneses/$cache_id
cat <<EOF
Profile $1
Genesis cache entry: $(ls -d $dir 2>&1)
Genesis cache id: $cache_id
Genesis cache key:
$(genesis_params_cache_params "$prof")
EOF
;;
profile-genesis-cache-rehash | pgc-rehash )
cache_id=$1
dir=../geneses/$cache_id
test ! -f "$dir/genesis-meta.json" ||
fail "no genesis cache with id $cache_id"
prof=$(jq .profile --raw-output <<<$dir/genesis-meta.json)
genesis_params_cache_params "$(profgenjq "$prof" .)" > "$dir"/cache.params
genesis_cache_id "$(profgenjq "$prof" .)" > "$dir"/cache.params.id
;;
wait-for-empty-blocks | wait-empty | wait )
op_wait_for_empty_blocks "$@";;
stop ) op_stop "$@";;
Expand Down Expand Up @@ -469,6 +489,7 @@ EOF
{ meta:
{ tag: \"${tag}\"
, profile: \"${prof}\"
, genesis_cache_id: \"$(genesis_cache_id "$(profgenjq "$prof" .)")\"
, timestamp: ${stamp}
, date: \"${date}\"
, profile_content: $(profjq "${prof}" .)
Expand Down
28 changes: 21 additions & 7 deletions bench/lib-genesis.sh
Expand Up @@ -15,24 +15,36 @@ profile_genesis_future_offset() {
echo -n "$(profjq "$profile" .genesis.genesis_future_offset)"
}

genesis_cache_id()
genesis_params_cache_params()
{
jq '
del(.era) |
del(.genesis_future_offset) |
del(.byron)
' --sort-keys <<<$1
}

genesis_cache_params_cache_id()
{
local genesis_params=$1 params_hash
params_hash=$(jq '
del(.era)
' --sort-keys <<<$genesis_params |
sha1sum | cut -c-7)
params_hash=$(jq . --sort-keys <<<$genesis_params |
sha1sum | cut -c-7)
jq <<<$genesis_params \
'"k\(.n_pools)-d\(.dense_pool_density)-\(.delegators / 1000)kD-\(.utxo / 1000)kU-\($params_hash)"
' --arg params_hash "$params_hash" --raw-output
}

genesis_cache_id() {
genesis_cache_params_cache_id "$(genesis_params_cache_params "$1")"
}

profile_genesis() {
local profile=$1 genesis_dir=${2:-./keys}
local genesis_params cache_id cache_path genesis_future_offset
local genesis_params genesis_cache_params cache_id cache_path genesis_future_offset

genesis_params=$(profgenjq "$profile" .)
cache_id=$(genesis_cache_id "$genesis_params")
genesis_cache_params=$(genesis_params_cache_params "$genesis_params")
cache_id=$(genesis_cache_params_cache_id "$genesis_cache_params")
cache_path=$genesis_cache_root/$cache_id

if test -f "$cache_path"/genesis.json
Expand All @@ -44,6 +56,8 @@ profile_genesis() {
then oprint "generating genesis due to miss: $cache_id @$cache_path"
mkdir -p "$cache_path"
time profile_genesis_singleshot "$profile" "$cache_path"
cat <<<$genesis_cache_params > "$cache_path"/cache.params
cat <<<$cache_id > "$cache_path"/cache.params.id
fi
rm -f "$genesis_dir"
ln -s "$cache_path" "$genesis_dir"
Expand Down

0 comments on commit 64318b6

Please sign in to comment.