Skip to content

Commit

Permalink
- Move node version check to be earlier ( to avoid CLI reporting inva…
Browse files Browse the repository at this point in the history
…lid 'latest' argument in previous version)

- Move function definitions to be earlier than statements
  • Loading branch information
rdlrt committed Jan 20, 2024
1 parent 358567d commit 38c92df
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 30 deletions.
59 changes: 30 additions & 29 deletions scripts/cnode-helper-scripts/env
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ is_dir() {

# Description : Check higher of two versions
# : $1=minimal_needed_version
# : $2=current_node_version
# : $2=current_version
versionCheck() {
[[ ${STRICT_VERSION_CHECK} = N ]] && return 0
w_ver=${1//v/}; w_ver_dots=${w_ver//[^.]}; [[ ${#w_ver_dots} -gt 1 && ${w_ver} =~ ^([0-9]+.[0-9]) ]] && w_ver=${BASH_REMATCH[1]}
Expand Down Expand Up @@ -448,6 +448,7 @@ getPassword() {
fi
done
}
readPassword() {
read_password=""
prompt="$1: "
Expand Down Expand Up @@ -853,6 +854,27 @@ set_default_vars() {
NC='\e[0m'
}
read_genesis() {
read -ra SHGENESIS <<< "$(jq -r '[ .networkMagic, .systemStart, .epochLength, .slotLength, .activeSlotsCoeff, .slotsPerKESPeriod, .maxKESEvolutions ] |@tsv' < ${GENESIS_JSON})"
read -ra BYGENESIS <<< "$(jq -r '[ .startTime, .protocolConsts.k, .blockVersionData.slotDuration ] |@tsv' < ${BYRON_GENESIS_JSON})"
NWMAGIC=${SHGENESIS[0]}
SHELLEY_GENESIS_START_SEC=$(date --date="${SHGENESIS[1]}" +%s)
EPOCH_LENGTH=${SHGENESIS[2]}
SLOT_LENGTH=${SHGENESIS[3]}
ACTIVE_SLOTS_COEFF=${SHGENESIS[4]}
SLOTS_PER_KES_PERIOD=${SHGENESIS[5]}
MAX_KES_EVOLUTIONS=${SHGENESIS[6]}
BYRON_GENESIS_START_SEC=${BYGENESIS[0]}
BYRON_K=${BYGENESIS[1]}
BYRON_SLOT_LENGTH=${BYGENESIS[2]}
BYRON_EPOCH_LENGTH=$(( 10 * BYRON_K ))
}
test_koios() {
# make sure KOIOS_API is reachable, else fall back to cli
[[ ${ENABLE_KOIOS} = 'Y' && -n ${KOIOS_API} && $(curl -sfk -o /dev/null -w "%{http_code}" -m 5 ${KOIOS_API}/tip | awk '{print $1}') = "200" ]] || unset KOIOS_API
}
[[ ${0} != '-bash' ]] && PARENT=$(dirname $0) || PARENT="$(pwd)" # If sourcing at terminal, $0 would be "-bash" , which is invalid. Thus, fallback to present working directory
# Initialise/Set offline mode prior to calling functions
OFFLINE_MODE='N'
Expand Down Expand Up @@ -889,6 +911,13 @@ if [[ -z "${CNCLI}" ]]; then
CNCLI=$(command -v cncli) || CNCLI="${HOME}/.local/bin/cncli"
fi
node_version="$(${CNODEBIN} version | head -1 | cut -d' ' -f2)"
cli_version="$(${CCLI} version | head -1 | cut -d' ' -f2)"
if ! versionCheck "8.7.3" "${node_version}" || ! versionCheck "8.17.0.0" "${cli_version}"; then
echo -e "\nKoios scripts have now been upgraded to support cardano-node 8.7.x ('${node_version}' found) / cardano-cli 8.17.x.x ('${cli_version}' found).\nPlease update cardano-node binaries (ensure to read release notes and update various configs using guild-deploy (use appropriate options to download/install/overwrite parts you need) or use tagged branches for older node version (eg: ./<script>.sh -b node-8.1.2 to switch scripts to an older branch).\n\n"
return 1
fi
[[ -f /usr/local/lib/libsodium.so ]] && export LD_LIBRARY_PATH=/usr/local/lib:"${LD_LIBRARY_PATH}" && PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:"${PKG_CONFIG_PATH}"
if [[ -z "${SOCKET}" ]]; then
Expand Down Expand Up @@ -1029,29 +1058,6 @@ if [[ -n "${CNODE_PID}" ]]; then
fi
fi
node_version="$(${CNODEBIN} version | head -1 | cut -d' ' -f2)"
cli_version="$(${CCLI} version | head -1 | cut -d' ' -f2)"
if ! versionCheck "8.7.3" "${node_version}" || ! versionCheck "8.17.0.0" "${cli_version}"; then
echo -e "\nKoios scripts has now been upgraded to support cardano-node 8.7.3 or higher (${node_version} found).\nPlease update cardano-node (note that you should ideally update your config too) or use tagged branches for older node version (eg: ./<script>.sh -b node-8.1.2 to switch scripts to an older branch).\n\n"
return 1
fi
read_genesis() {
read -ra SHGENESIS <<< "$(jq -r '[ .networkMagic, .systemStart, .epochLength, .slotLength, .activeSlotsCoeff, .slotsPerKESPeriod, .maxKESEvolutions ] |@tsv' < ${GENESIS_JSON})"
read -ra BYGENESIS <<< "$(jq -r '[ .startTime, .protocolConsts.k, .blockVersionData.slotDuration ] |@tsv' < ${BYRON_GENESIS_JSON})"
NWMAGIC=${SHGENESIS[0]}
SHELLEY_GENESIS_START_SEC=$(date --date="${SHGENESIS[1]}" +%s)
EPOCH_LENGTH=${SHGENESIS[2]}
SLOT_LENGTH=${SHGENESIS[3]}
ACTIVE_SLOTS_COEFF=${SHGENESIS[4]}
SLOTS_PER_KES_PERIOD=${SHGENESIS[5]}
MAX_KES_EVOLUTIONS=${SHGENESIS[6]}
BYRON_GENESIS_START_SEC=${BYGENESIS[0]}
BYRON_K=${BYGENESIS[1]}
BYRON_SLOT_LENGTH=${BYGENESIS[2]}
BYRON_EPOCH_LENGTH=$(( 10 * BYRON_K ))
}
read_genesis
[[ ${NWMAGIC} == "764824073" ]] && NETWORK_IDENTIFIER="--mainnet" || NETWORK_IDENTIFIER="--testnet-magic ${NWMAGIC}"
Expand Down Expand Up @@ -1080,11 +1086,6 @@ case ${NWMAGIC} in
[[ -z ${SHELLEY_TRANS_EPOCH} ]] && SHELLEY_TRANS_EPOCH=0
esac
test_koios() {
# make sure KOIOS_API is reachable, else fall back to cli
[[ ${ENABLE_KOIOS} = 'Y' && -n ${KOIOS_API} && $(curl -sfk -o /dev/null -w "%{http_code}" -m 5 ${KOIOS_API}/tip | awk '{print $1}') = "200" ]] || unset KOIOS_API
}
[[ ${OFFLINE_MODE} = "N" && ${SHELLEY_TRANS_EPOCH} -eq -1 ]] && getNodeMetrics && getShelleyTransitionEpoch
# Return code 2 is used for scripts that want to source env but not fail due to a starting node
Expand Down
2 changes: 1 addition & 1 deletion scripts/grest-helper-scripts/setup-grest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ SGVERSION=v1.1.1
set_cron_variables "stake-distribution-update"
# Special condition for guild network (NWMAGIC=141) where activity and entries are minimal, and epoch duration is 1 hour
([[ ${NWMAGIC} -eq 141 ]] && install_cron_job "stake-distribution-update" "*/10 * * * *") ||
install_cron_job "stake-distribution-update" "*/120 * * * *"
install_cron_job "stake-distribution-update" "15 */2 * * *"

get_cron_job_executable "stake-distribution-new-accounts-update"
set_cron_variables "stake-distribution-new-accounts-update"
Expand Down

0 comments on commit 38c92df

Please sign in to comment.