Skip to content

Commit

Permalink
added a script to check the KES period
Browse files Browse the repository at this point in the history
  • Loading branch information
nilaysaha committed Jan 2, 2024
1 parent 43d22d2 commit 2731b60
Show file tree
Hide file tree
Showing 5 changed files with 628 additions and 112 deletions.
2 changes: 1 addition & 1 deletion exec/start_cw_local_node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ CONFIG_FILE="$HOME/projects/cardano-scripts/src/tconfig/mainnet/byron-genesis.js
DB_DIR="$HOME/wallets/db"
SOCKET="$HOME/projects/cardano-scripts/exec/state-node-shelly-mainnet/node.socket"

$CARDANO_WALLET serve --port 8090 --testnet $CONFIG_FILE --database $DB_DIR --node-socket $SOCKET
$CARDANO_WALLET serve --port 8090 --mainnet --database $DB_DIR --node-socket $SOCKET --token-metadata-server https://tokens.cardano.org --trace-wallet-db=debug
70 changes: 59 additions & 11 deletions src/cscripts/env
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ POOL_NAME="REIT" # Set the pool's name
#USESYSVARS="N" # Whether to use environment variable from shell session for TCONFIG_HOME
#POOL_HW_COLDKEY_SK_FILENAME="cold.hwsfile"
#CIP0094_POLL_URL="https://raw.githubusercontent.com/cardano-foundation/CIP-0094-polls/main/networks/polls.json" # URL for polls to vote against
#MITHRIL_DOWNLOAD="N" # (Y|N) Download latest Mithril snapshot

######################################
# Do NOT modify code below #
Expand Down Expand Up @@ -200,7 +201,8 @@ checkUpdate() {
if [[ $3 != Y ]] && grep -q "# Do NOT modify" "${dname}/${fname}"; then
printf '%s\n%s\n' "${NEW_STATIC}" "${GIT_TEMPL}" > "${dname}/${fname}".tmp
fi
cp "${dname}/${fname}" "${dname}/${fname}_bkp$(date +%s)"
[[ ! -d "${dname}"/archive ]] && mkdir "${dname}"/archive
cp "${dname}/${fname}" "${dname}/archive/${fname}_bkp$(date +%s)"
mv -f "${dname}/${fname}".tmp "${dname}/${fname}"
[[ ! "${fname}" == "env" ]] && chmod +x "${dname}/${fname}"
echo -e "\n${FG_YELLOW}${fname}${NC} update successfully applied!"
Expand Down Expand Up @@ -323,11 +325,14 @@ validateDecimalNbr() {
# Description : Pretty print Lovelace value
# : $1 = Amount in Lovelace
# : $2 = normal | pretty (default)
# : $3 = full | trim (default, removes trailing zeros from fraction)
formatLovelace() {
if isNumber $1; then
[[ $1 -eq 0 ]] && echo 0 && return
[[ $1 -le 999999 ]] && printf '0.%06d' "$1" && return
[[ -z $2 || $2 = 'pretty' ]] && printf '%s.%s' "$(sed ':a;s/\B[0-9]\{3\}\>/,&/;ta' <<< ${1::-6})" "${1: -6}" || printf '%s.%s' "${1::-6}" "${1: -6}"
[[ $1 -le 999999 ]] && printf '%s' "$(local frac=$(printf '%06d' "$1"); [[ -z $3 || $3 = 'trim' ]] && ([[ ${frac} =~ (^[0-9]*[1-9])?0*$ ]]; printf '0.%s' "${BASH_REMATCH[1]}") || printf '0.%s' "${frac}")" && return
[[ -z $3 || $3 = 'trim' ]] && fraction="$(local frac=${1: -6}; [[ ${frac} =~ (^[0-9]*[1-9])?0*$ ]]; printf '.%s' "${BASH_REMATCH[1]}")" || fraction=".${1: -6}"
[[ ${fraction} = '.' ]] && fraction=""
[[ -z $2 || $2 = 'pretty' ]] && printf '%s%s' "$(sed ':a;s/\B[0-9]\{3\}\>/,&/;ta' <<< ${1::-6})" "${fraction}" || printf '%s%s' "${1::-6}" "${fraction}"
else
printf "${FG_RED}ERROR${NC}: must be a valid integer number" 1>&2
return 1
Expand Down Expand Up @@ -656,6 +661,20 @@ timeLeft() {
printf '%02d:%02d:%02d' $H $M $S
}
# Description : Format number in compact format, ie thousand = k, millon = m etc, with variable precision
# Return : populates ${cn_value} & ${cn_suffix}
compactNumber() {
unset cn_value cn_suffix
if [[ $# -ne 1 ]] || ! isNumber $1; then return 1; fi
if [[ $1 -gt 100000000 ]]; then LC_NUMERIC=C printf -v cn_value "%.0f" "$(echo "$1/1000000" | bc -l)"; cn_suffix=M; return; fi
if [[ $1 -gt 10000000 ]]; then LC_NUMERIC=C printf -v cn_value "%.1f" "$(echo "$1/1000000" | bc -l)"; cn_suffix=M; return; fi
if [[ $1 -gt 1000000 ]]; then LC_NUMERIC=C printf -v cn_value "%.2f" "$(echo "$1/1000000" | bc -l)"; cn_suffix=M; return; fi
if [[ $1 -gt 100000 ]]; then LC_NUMERIC=C printf -v cn_value "%.0f" "$(echo "$1/1000" | bc -l)"; cn_suffix=k; return; fi
if [[ $1 -gt 10000 ]]; then LC_NUMERIC=C printf -v cn_value "%.1f" "$(echo "$1/1000" | bc -l)"; cn_suffix=k; return; fi
if [[ $1 -gt 1000 ]]; then LC_NUMERIC=C printf -v cn_value "%.2f" "$(echo "$1/1000" | bc -l)"; cn_suffix=k; return; fi
cn_value=$1
}
# Description : Get calculated slot number tip
getSlotTipRef() {
current_time_sec=$(printf '%(%s)T\n' -1)
Expand Down Expand Up @@ -693,6 +712,32 @@ kesExpiration() {
printf -v kes_expiration '%(%F %T %Z)T' ${expiration_time_sec}
}
# Description : create and save pool id in hex & bech32 encoded format
# Parameters : pool name > the name of the pool
# Return : populates ${pool_id} & ${pool_id_bech32}
getPoolID() {
local pool_dir
[[ -z "${1}" ]] && pool_dir="${POOL_DIR}" || pool_dir="${POOL_FOLDER}/${1}"
pool_id_file="${pool_dir}/${POOL_ID_FILENAME}"
pool_id_bech32_file="${pool_dir}/${POOL_ID_FILENAME}-bech32"
[[ -f ${pool_id_file} && -f ${pool_id_bech32_file} ]] && pool_id=$(cat ${pool_id_file}) && pool_id_bech32=$(cat ${pool_id_bech32_file}) && return 0
pool_id=""
pool_id_bech32=""
pool_coldkey_vk_file="${pool_dir}/${POOL_COLDKEY_VK_FILENAME}"
if [[ -f ${pool_coldkey_vk_file} ]]; then
println ACTION "${CCLI} stake-pool id --cold-verification-key-file ${pool_coldkey_vk_file} --output-format hex"
println ACTION "${CCLI} stake-pool id --cold-verification-key-file ${pool_coldkey_vk_file}"
if ! pool_id=$(${CCLI} stake-pool id --cold-verification-key-file "${pool_coldkey_vk_file}" --output-format hex 2>/dev/null) || \
! pool_id_bech32=$(${CCLI} stake-pool id --cold-verification-key-file "${pool_coldkey_vk_file}" 2>/dev/null); then
return 1
fi
echo ${pool_id} > "${pool_id_file}"
echo ${pool_id_bech32} > "${pool_id_bech32_file}"
return 0
fi
return 1
}
# Description : Calculate expected interval between blocks
slotInterval() {
if [[ -z ${DECENTRALISATION} || $(echo "${DECENTRALISATION} < 0.5" | bc) -eq 1 ]]; then d=0.5; else d=${DECENTRALISATION}; fi
Expand Down Expand Up @@ -735,7 +780,6 @@ set_default_vars() {
[[ -z ${G_ACCOUNT} ]] && G_ACCOUNT="cardano-community"
URL_RAW="https://raw.githubusercontent.com/${G_ACCOUNT}/guild-operators/${BRANCH}"
DB_SCRIPTS_URL="${URL_RAW}/scripts/grest-helper-scripts/db-scripts"
export LC_ALL=C.UTF-8
# special mapping of coreutils gdate to date for MacOS
if [[ $(uname) == Darwin ]]; then
Expand Down Expand Up @@ -794,6 +838,7 @@ set_default_vars() {
[[ -z ${ASSET_POLICY_SCRIPT_FILENAME} ]] && ASSET_POLICY_SCRIPT_FILENAME="policy.script"
[[ -z ${ASSET_POLICY_ID_FILENAME} ]] && ASSET_POLICY_ID_FILENAME="policy.id"
[[ -z ${CIP0094_POLL_URL} ]] && CIP0094_POLL_URL="https://raw.githubusercontent.com/cardano-foundation/CIP-0094-polls/main/networks/polls.json"
[[ -z ${MITHRIL_DOWNLOAD} ]] && MITHRIL_DOWNLOAD="N"
FG_BLACK='\e[30m'
FG_RED='\e[31m'
FG_GREEN='\e[32m'
Expand Down Expand Up @@ -887,19 +932,22 @@ if ! command -v "jq" &>/dev/null; then
return 1
fi
read -ra CONFIG_CONTENTS <<<"$(jq -r '[ .AlonzoGenesisFile //"null", .ByronGenesisFile //"null", .ShelleyGenesisFile //"null", .Protocol //"Cardano", .TraceChainDb //"null", .EnableP2P //"false"]| @tsv' "${CONFIG}" 2>/dev/null)"
read -ra CONFIG_CONTENTS <<<"$(jq -r '[ .AlonzoGenesisFile //"null", .ByronGenesisFile //"null", .ShelleyGenesisFile //"null", .Protocol //"Cardano", .TraceChainDb //"null", .EnableP2P //"false", .ConwayGenesisFile //"null"]| @tsv' "${CONFIG}" 2>/dev/null)"
if [[ ${CONFIG_CONTENTS[4]} != "true" ]]; then
echo "Could not find TraceChainDb when attempting to parse ${CONFIG} file in JSON format, please double-check the syntax of your config, or simply download it from guild-operators repository!"
return 1
else
CONWAY_GENESIS_JSON="${CONFIG_CONTENTS[6]}"
ALONZO_GENESIS_JSON="${CONFIG_CONTENTS[0]}"
BYRON_GENESIS_JSON="${CONFIG_CONTENTS[1]}"
GENESIS_JSON="${CONFIG_CONTENTS[2]}"
# if relative path is used, assume same parent dir as config
[[ ! ${CONWAY_GENESIS_JSON} =~ ^/ ]] && CONWAY_GENESIS_JSON="$(dirname "${CONFIG}")/${CONWAY_GENESIS_JSON}"
[[ ! ${ALONZO_GENESIS_JSON} =~ ^/ ]] && ALONZO_GENESIS_JSON="$(dirname "${CONFIG}")/${ALONZO_GENESIS_JSON}"
[[ ! ${BYRON_GENESIS_JSON} =~ ^/ ]] && BYRON_GENESIS_JSON="$(dirname "${CONFIG}")/${BYRON_GENESIS_JSON}"
[[ ! ${GENESIS_JSON} =~ ^/ ]] && GENESIS_JSON="$(dirname "${CONFIG}")/${GENESIS_JSON}"
# if genesis files not found, exit with rc 1
[[ ! -f "${CONWAY_GENESIS_JSON}" ]] && echo "Byron genesis file not found: ${CONWAY_GENESIS_JSON}" && return 1
[[ ! -f "${ALONZO_GENESIS_JSON}" ]] && echo "Byron genesis file not found: ${ALONZO_GENESIS_JSON}" && return 1
[[ ! -f "${BYRON_GENESIS_JSON}" ]] && echo "Byron genesis file not found: ${BYRON_GENESIS_JSON}" && return 1
[[ ! -f "${GENESIS_JSON}" ]] && echo "Shelley genesis file not found: ${GENESIS_JSON}" && return 1
Expand Down Expand Up @@ -982,7 +1030,7 @@ fi
node_version="$(${CCLI} version | head -1 | cut -d' ' -f2)"
if ! versionCheck "8.1.2" "${node_version}"; then
echo -e "\nKoios scripts has now been upgraded to support cardano-node 8.1.2 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.\n\n"
echo -e "\nKoios scripts has now been upgraded to support cardano-node 8.1.2 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-1.35.7 to switch scripts to an older branch).\n\n"
return 1
fi
Expand All @@ -1009,27 +1057,27 @@ case ${NWMAGIC} in
764824073)
NETWORK_NAME="Mainnet"
SHELLEY_TRANS_EPOCH=208
[[ -z ${KOIOS_API} ]] && KOIOS_API="https://api.koios.rest/api/v0" ;;
[[ -z ${KOIOS_API} ]] && KOIOS_API="https://api.koios.rest/api/v1" ;;
1)
NETWORK_NAME="PreProd"
SHELLEY_TRANS_EPOCH=4
[[ -z ${KOIOS_API} ]] && KOIOS_API="https://preprod.koios.rest/api/v0";;
[[ -z ${KOIOS_API} ]] && KOIOS_API="https://preprod.koios.rest/api/v1";;
141)
NETWORK_NAME="Guild"
SHELLEY_TRANS_EPOCH=2
[[ -z ${KOIOS_API} ]] && KOIOS_API="https://guild.koios.rest/api/v0" ;;
[[ -z ${KOIOS_API} ]] && KOIOS_API="https://guild.koios.rest/api/v1";;
2)
NETWORK_NAME="Preview"
SHELLEY_TRANS_EPOCH=0
[[ -z ${KOIOS_API} ]] && KOIOS_API="https://preview.koios.rest/api/v0" ;;
[[ -z ${KOIOS_API} ]] && KOIOS_API="https://preview.koios.rest/api/v1";;
*)
NETWORK_NAME="Custom"
[[ -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 -Isf -m 5 ${KOIOS_API}/tip | head -1) = *"200 OK"* ]] || unset KOIOS_API
[[ ${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
Expand Down
Loading

0 comments on commit 2731b60

Please sign in to comment.