Skip to content

Commit

Permalink
Misc changes
Browse files Browse the repository at this point in the history
- Improve notification on boot for shelley transition epoch calculation failure
- Return 0 in helper functions dependent on shelley transition epoch in calculation failed
- Add PROTOCOL check to timeUntilNextEpoch and shelley testnet calculation
- Return correct number of peers in peer analysis if none are found  (previously 1 skipped instead of 0)
- Continuously check node mode in case of boot/sync at startup
- Retry shelley transition epoch calculation & KES expiration until successful
- Change peer count order In<->Out to better match peer analysis section
- Correctly calculate KES expiration date based on how many slots are left of current KES period instead of subtracting a full KES period causing date to diff on each start
  • Loading branch information
Scitz0 committed Sep 14, 2020
1 parent eecfc65 commit 296f98e
Showing 1 changed file with 42 additions and 21 deletions.
63 changes: 42 additions & 21 deletions scripts/cnode-helper-scripts/gLiveView.sh
Expand Up @@ -282,7 +282,7 @@ timeLeft() {
printf '%02d:%02d:%02d' $H $M $S
}

# Command : getShelleyTransitionEpoch
# Command : getShelleyTransitionEpoch [1 = no user verification]
# Description: Calculate shelley transition epoch
getShelleyTransitionEpoch() {
calc_slot=0
Expand All @@ -297,13 +297,18 @@ getShelleyTransitionEpoch() {
if [[ "${nwmagic}" = "764824073" ]]; then
shelley_transition_epoch=208
elif [[ ${calc_slot} -ne ${slotnum} || ${shelley_epochs} -eq 0 ]]; then
clear
printf "\n ${style_status_3}Failed${NC} to calculate shelley transition epoch!"
printf "\n Calculations might not work correctly until Shelley era is reached."
printf "\n\n ${style_info}Press c to continue or any other key to quit${NC}"
read -r -n 1 -s -p "" answer
[[ "${answer}" != "c" ]] && myExit 1 "Guild LiveView terminated!"
shelley_transition_epoch=0
if [[ $1 -ne 1 ]]; then
clear
printf "\n ${style_status_3}Failed${NC} to get shelley transition epoch, calculations will not work correctly!"
printf "\n\n Possible causes:"
printf "\n - Node in startup mode"
printf "\n - Shelley era not reached"
printf "\n After successful node boot or when sync to shelley era has been reached, calculations will be correct"
printf "\n\n ${style_info}Press c to continue or any other key to quit${NC}"
read -r -n 1 -s -p "" answer
[[ "${answer}" != "c" ]] && myExit 1 "Guild LiveView terminated!"
fi
shelley_transition_epoch=-1
else
shelley_transition_epoch=${byron_epochs}
fi
Expand All @@ -314,6 +319,7 @@ getShelleyTransitionEpoch() {
getEpoch() {
current_time_sec=$(date -u +%s)
if [[ "${PROTOCOL}" = "Cardano" ]]; then
[[ shelley_transition_epoch -eq -1 ]] && echo 0 && return
byron_end_time=$(( byron_genesis_start_sec + ( shelley_transition_epoch * byron_epoch_length * byron_slot_length ) ))
echo $(( shelley_transition_epoch + ( (current_time_sec - byron_end_time) / slot_length / epoch_length ) ))
else
Expand All @@ -324,14 +330,21 @@ getEpoch() {
# Command : getTimeUntilNextEpoch
# Description: Offline calculation of time in seconds until next epoch
timeUntilNextEpoch() {
echo $(( (shelley_transition_epoch * byron_slot_length * byron_epoch_length) + ( ( $(getEpoch) + 1 - shelley_transition_epoch ) * slot_length * epoch_length ) - $(date -u +%s) + byron_genesis_start_sec ))
current_time_sec=$(date -u +%s)
if [[ "${PROTOCOL}" = "Cardano" ]]; then
[[ shelley_transition_epoch -eq -1 ]] && echo 0 && return
echo $(( (shelley_transition_epoch * byron_slot_length * byron_epoch_length) + ( ( $(getEpoch) + 1 - shelley_transition_epoch ) * slot_length * epoch_length ) - current_time_sec + byron_genesis_start_sec ))
else
echo $(( ( ( ( (current_time_sec - shelley_genesis_start_sec) / slot_length / epoch_length ) + 1 ) * slot_length * epoch_length ) - current_time_sec + shelley_genesis_start_sec ))
fi
}

# Command : getSlotTipRef
# Description: Get calculated slot number tip
getSlotTipRef() {
current_time_sec=$(date -u +%s)
if [[ "${PROTOCOL}" = "Cardano" ]]; then
[[ shelley_transition_epoch -eq -1 ]] && echo 0 && return
# Combinator network
byron_slots=$(( shelley_transition_epoch * byron_epoch_length )) # since this point will only be reached once we're in Shelley phase
byron_end_time=$(( byron_genesis_start_sec + ( shelley_transition_epoch * byron_epoch_length * byron_slot_length ) ))
Expand All @@ -352,7 +365,8 @@ getSlotTipRef() {
# Description: Calculate KES expiration
kesExpiration() {
current_time_sec=$(date -u +%s)
expiration_time_sec=$(( current_time_sec - ( slot_length * slots_per_kes_period ) + ( slot_length * slots_per_kes_period * remaining_kes_periods ) ))
tip_ref=$(getSlotTipRef)
expiration_time_sec=$(( current_time_sec - ( slot_length * (tip_ref % slots_per_kes_period) ) + ( slot_length * slots_per_kes_period * remaining_kes_periods ) ))
kes_expiration=$(date '+%F %T Z' --date=@${expiration_time_sec})
}

Expand Down Expand Up @@ -381,8 +395,10 @@ checkPeers() {
else
netstatPeers=$(ss -tnp state established 2>/dev/null | grep "${pid}," | awk -v port=":${CNODE_PORT}" '$3 ~ port {print $4}')
fi
[[ -z ${netstatPeers} ]] && return

netstatSorted=$(printf '%s\n' "${netstatPeers[@]}" | sort )
peerCNTABS=$(printf '%s\n' "${netstatPeers[@]}" | wc -l)
peerCNTABS=$(wc -w <<< ${netstatPeers})

# Sort/filter peers
lastpeerIP=""; lastpeerPORT=""
Expand Down Expand Up @@ -456,12 +472,10 @@ check_peers="false"
show_peers="false"
line_end=0
data=$(curl -s -H 'Accept: application/json' "http://${EKG_HOST}:${EKG_PORT}/" 2>/dev/null)
about_to_lead=$(jq '.cardano.node.metrics.Forge["forge-about-to-lead"].int.val //0' <<< "${data}")
epochnum=$(jq '.cardano.node.ChainDB.metrics.epoch.int.val //0' <<< "${data}")
slot_in_epoch=$(jq '.cardano.node.ChainDB.metrics.slotInEpoch.int.val //0' <<< "${data}")
slotnum=$(jq '.cardano.node.ChainDB.metrics.slotNum.int.val //0' <<< "${data}")
remaining_kes_periods=$(jq '.cardano.node.Forge.metrics.remainingKESPeriods.int.val //0' <<< "${data}")
[[ ${about_to_lead} -gt 0 ]] && nodemode="Core" || nodemode="Relay"

#####################################
# Static genesis variables #
Expand All @@ -486,11 +500,11 @@ if [[ "${PROTOCOL}" = "Cardano" ]]; then
byron_epoch_length=$(( 10 * byron_k ))
getShelleyTransitionEpoch
else
shelley_transition_epoch=-1
shelley_transition_epoch=-2
fi
#####################################
slot_interval=$(echo "(${slot_length} / ${active_slots_coeff} / ${decentralisation}) + 0.5" | bc -l | awk '{printf "%.0f\n", $1}')
kesExpiration # Static and wont change until KES rotation and node restart
kesExpiration
#####################################

clear
Expand Down Expand Up @@ -556,6 +570,13 @@ while true; do
forged=$(jq '.cardano.node.metrics.Forge.forged.int.val //0' <<< "${data}")
adopted=$(jq '.cardano.node.metrics.Forge.adopted.int.val //0' <<< "${data}")
didntadopt=$(jq '.cardano.node.metrics.Forge["didnt-adopt"].int.val //0' <<< "${data}")
about_to_lead=$(jq '.cardano.node.metrics.Forge["forge-about-to-lead"].int.val //0' <<< "${data}")

[[ ${about_to_lead} -gt 0 ]] && nodemode="Core" || nodemode="Relay"
if [[ "${PROTOCOL}" = "Cardano" && shelley_transition_epoch -eq -1 ]]; then # if Shelley transition epoch calc failed during start, try until successful
getShelleyTransitionEpoch 1
kesExpiration
fi

header_length=$(( ${#NODE_NAME} + ${#nodemode} + ${#node_version} + ${#node_rev} + 16 ))
[[ ${header_length} -gt ${width} ]] && header_padding=0 || header_padding=$(( (width - header_length) / 2 ))
Expand All @@ -579,7 +600,7 @@ while true; do
printf "${LVL}\n"
((line++))

if [[ ${shelley_transition_epoch} = -1 || ${epochnum} -ge ${shelley_transition_epoch} ]]; then
if [[ ${shelley_transition_epoch} -eq -2 || ${epochnum} -ge ${shelley_transition_epoch} ]]; then
epoch_progress=$(echo "(${slot_in_epoch}/${epoch_length})*100" | bc -l) # in Shelley era or Shelley only TestNet
else
epoch_progress=$(echo "(${slot_in_epoch}/${byron_epoch_length})*100" | bc -l) # in Byron era
Expand Down Expand Up @@ -611,11 +632,11 @@ while true; do
printf "${VL} Density : ${style_values_1}%s${NC}%%" "${density}"
tput cup ${line} ${second_col}
if [[ ${tip_diff} -le $(( slot_interval * 2 )) ]]; then
printf "Tip (diff) : ${style_status_1}%s${NC}" "-${tip_diff} :)"
printf "Tip (diff) : ${style_status_1}%s${NC}" "${tip_diff} :)"
elif [[ ${tip_diff} -le $(( slot_interval * 3 )) ]]; then
printf "Tip (diff) : ${style_status_2}%s${NC}" "-${tip_diff} :|"
printf "Tip (diff) : ${style_status_2}%s${NC}" "${tip_diff} :|"
else
printf "Tip (diff) : ${style_status_3}%s${NC}" "-${tip_diff} :("
printf "Tip (diff) : ${style_status_3}%s${NC}" "${tip_diff} :("
fi
endLine $((line++))

Expand All @@ -624,11 +645,11 @@ while true; do

printf "${VL} Processed TX : ${style_values_1}%s${NC}" "${tx_processed}"
tput cup ${line} $((second_col+7))
printf " In / Out"
printf " Out / In"
endLine $((line++))
printf "${VL} Mempool TX/Bytes : ${style_values_1}%s${NC} / ${style_values_1}%s${NC}" "${mempool_tx}" "${mempool_bytes}"
tput el; tput cup ${line} $((second_col+7))
printf "Peers : ${style_values_1}%s${NC} / ${style_values_1}%s${NC}" "${peers_in}" "${peers_out}"
printf "Peers : ${style_values_1}%s${NC} / ${style_values_1}%s${NC}" "${peers_out}" "${peers_in}"
endLine $((line++))

## Core section ##
Expand Down

0 comments on commit 296f98e

Please sign in to comment.