60789431 2022-06-13 22:17:27 UTC
60803298 2022-06-14 02:08:34 UTC
60811493 2022-06-14 04:25:09 UTC
60817608 2022-06-14 06:07:04 UTC
60818935 2022-06-14 06:29:11 UTC
60824464 2022-06-14 08:01:20 UTC
60827224 2022-06-14 08:47:20 UTC
60856899 2022-06-14 17:01:55 UTC
60860277 2022-06-14 17:58:13 UTC
60862634 2022-06-14 18:37:30 UTC
60878191 2022-06-14 22:56:47 UTC
60890371 2022-06-15 02:19:47 UTC
60934967 2022-06-15 14:43:03 UTC
60965699 2022-06-15 23:15:15 UTC
60979778 2022-06-16 03:09:54 UTC
60995493 2022-06-16 07:31:49 UTC
61019400 2022-06-16 14:10:16 UTC
61082765 2022-06-17 07:46:21 UTC
61105585 2022-06-17 14:06:41 UTC
61175878 2022-06-18 09:38:14 UTC
61191064 2022-06-18 13:51:20 UTC
Notice that slot number is way larger than the number of slots in an epoch. Was it wrong? Or it means something different from slotno in an epoch?
Current testnet epoch is 211. Each epoch has 432000 slots. So the number for total slots would add up to something like 90M, not 60M. Still not quite right …
Also, is there a way to just display slot number within the block?
If you look at a recent block on testnet https://testnet.cardanoscan.io/block/3631097, the “Absolute Slot” is in the range of 60 million. The slots per epoch were changed at the beginning of Shelley on mainnet. I suppose, it’s the same on testnet.
Sorry, don’t know if there is a command for slot in epoch. But should be easy to calculate knowing one correspondence.
# we add slot in epoch and PDT time to each block
function addMoreInfo() {
local infile=$1
local outfile=$2
local count=1
echo -e " No.\t slot/slot in epoch\t\tPDT time" | tee $outfile
echo "-------------------------------------------------------------" | tee -a $outfile
while IFS="" read -r p || [ -n "$p" ]
do
if [[ ! "$p" =~ .*[0-9]" UTC" ]]; then
continue;
fi
set $p
local slot=$1
shift
local UTC_Time="$*"
slotInEpoch=$(($slot - $SHELLEY_SLOT_START - ($epoch_no - $SHELLEY_EPOCH_START)*$SLOTS_IN_EPOCH))
local utcTime=$(date -u -d "$UTC_Time" -I"seconds")
local pstTime=$(TZ='America/Los_Angeles' date -d "$UTC_Time" -I"seconds")
echo -e " $count\t$slot/$slotInEpoch\t\t$pstTime" | tee -a $outfile
count=$(($count + 1))
done < $infile
}
#!/bin/bash
set -e # exit on error
set -o pipefail # exit on pipeline error
set -u # treat unset variable as error
# current epoch or next?
if [[ $# > 0 ]] && [[ $1 == "--current" ]];then
EPOCH="--current"
else
EPOCH="--next"
fi
# which network are we on?
source ~/config-inc.sh
# set network magic
# on mainnet, Byron era has 208 (0-207) epoch with 21600 slots in each epoch
# (total byron slots 4,492,800)
# on testnet, Byron era has 74 (0-73) epoch with 21600 slots ineach epoch
# (total 1598400)
# Shelley era has 432,000 slots in each epoch
if [[ $NETWORK == "mainnet" ]]; then
NETWORK_MAGIC="--mainnet"
SHELLEY_EPOCH_START=208
SHELLEY_SLOT_START=4492800
elif [[ $NETWORK == "testnet" ]]; then
NETWORK_MAGIC="--testnet-magic 1097911063"
SHELLEY_EPOCH_START=74
SHELLEY_SLOT_START=1598400
else
echo "unknown network $NETWORK. quitting"
exit 1
fi
SLOTS_IN_EPOCH=432000
# other config variables
NODE_HOME=/home/ubuntu/cardano
STAKE_POOL_ID=$(cat $NODE_HOME/stake-pool-id.txt)
export CARDANO_NODE_SOCKET_PATH=$NODE_HOME/db/socket
CCLI=cardano-cli
# create logs directory
if [[ ! -d "$NODE_HOME/logs" ]]; then
mkdir $NODE_HOME/logs;
fi
# create a pid while we are running
PID_FILE=$NODE_HOME/logs/leaderScheduleCheck.pid
echo $$ > $PID_FILE
##########################################################################################
function myerror() {
echo -e "ERROR : $1"
echo
echo -e "QUITING ...."
rm -f $PID_FILE
exit 1
}
# Check that node is synced
function isSynced(){
isSynced=false
sync_progress=$($CCLI query tip $NETWORK_MAGIC | jq -r ".syncProgress")
if [[ $sync_progress == "100.00" ]]; then
isSynced=true
fi
echo $isSynced
}
# Get current epoch
function getCurrentEpoch(){
echo $($CCLI query tip $NETWORK_MAGIC | jq -r ".epoch")
}
# Get epoch start time based on current one
function getEpochStartTime(){
byron_genesis_start_time=${BYRON_GENESIS[0]}
byron_k=${BYRON_GENESIS[1]}
byron_epoch_length=$(( 10 * byron_k ))
byron_slot_length=${BYRON_GENESIS[2]}
echo $(( $byron_genesis_start_time + (($(getCurrentEpoch) * $byron_epoch_length * $byron_slot_length) / 1000) ))
}
# Get epoch end time based on the current one
function getEpochEndTime(){
#calculate currentEpoch Start time + 5 days of epoch duration
echo $(( $(getEpochStartTime)+(5*86400) ))
}
# Get current timestamp
function getCurrentTime(){
echo $(printf '%(%s)T\n' -1)
}
# Convert timestamps to UTC time
function timestampToUTC(){
timestamp=$1
echo $(date +"%D %T" -ud @$timestamp)
}
# Find the correct time to run the leaderslot check command
function getLeaderslotCheckTime(){
epochStartTime=$(getEpochStartTime)
epochEndTime=$(getEpochEndTime)
# epoch completion percent to check for --next epoch leaderslots
percentage=75
checkTimestamp=$(( $epochStartTime+($percentage*($epochEndTime-$epochStartTime)/100) ))
echo $checkTimestamp
}
# Check leaderschedule of next epoch
function checkLeadershipSchedule() {
epoch_no=$(getCurrentEpoch)
if [[ $EPOCH == "--next" ]]; then
epoch_no=$(( $epoch_no + 1 ))
fi
epoch_file="$NODE_HOME/logs/leaderSchedule_$epoch_no.txt"
if [[ -f $epoch_file ]]; then
echo
echo "epoch leader schedule already exist : $epoch_file"
echo
cat $epoch_file
else
echo
echo "creating epoch leader schedule: $epoch_file"
echo
$CCLI query leadership-schedule $NETWORK_MAGIC \
--genesis "$NODE_HOME/$NETWORK-shelley-genesis.json" \
--stake-pool-id $STAKE_POOL_ID \
--vrf-signing-key-file "$NODE_HOME/vrf.skey" \
$EPOCH > /tmp/junk
addMoreInfo /tmp/junk $epoch_file
fi
}
# we add slot in epoch and PDT time to each block
function addMoreInfo() {
local infile=$1
local outfile=$2
local count=1
echo -e " No.\t slot/slot in epoch\t\tPDT time" | tee $outfile
echo "-------------------------------------------------------------" | tee -a $outfile
while IFS="" read -r p || [ -n "$p" ]
do
if [[ ! "$p" =~ .*[0-9]" UTC" ]]; then
continue;
fi
set $p
local slot=$1
shift
local UTC_Time="$*"
slotInEpoch=$(($slot - $SHELLEY_SLOT_START - ($epoch_no - $SHELLEY_EPOCH_START)*$SLOTS_IN_EPOCH))
local utcTime=$(date -u -d "$UTC_Time" -I"seconds")
local pstTime=$(TZ='America/Los_Angeles' date -d "$UTC_Time" -I"seconds")
echo -e " $count\t$slot/$slotInEpoch\t\t$pstTime" | tee -a $outfile
count=$(($count + 1))
done < $infile
}
##########################################################################################
# fetch byron parameters
TEMP=$(jq -r '[ .startTime, .protocolConsts.k, .blockVersionData.slotDuration ] |@tsv' < $NODE_HOME/$NETWORK-byron-genesis.json)
read -ra BYRON_GENESIS <<< $TEMP
if [[ -z $BYRON_GENESIS ]]; then
myerror "BYRON GENESIS config file not loaded correctly"
fi
# checking sync'ing progress
if [ ! isSynced ];then
myerror "Node not fully synced."
fi
# now start by showing some info and times
echo "Pool name : $POOL_NAME"
echo "Pool ticker: $POOL_TICKER"
echo
echo "Current epoch: $(getCurrentEpoch)"
epochStartTimestamp=$(getEpochStartTime)
echo "Epoch start time: $(timestampToUTC $epochStartTimestamp) UTC"
epochEndTimestamp=$(getEpochEndTime)
echo "Epoch end time: $(timestampToUTC $epochEndTimestamp) UTC"
timestampCheckLeaders=$(getLeaderslotCheckTime)
echo "Check time for next: $(timestampToUTC $timestampCheckLeaders) UTC"
currentTime=$(getCurrentTime)
echo "Current execution time: $(timestampToUTC $currentTime) UTC"
timeDifference=$(( $timestampCheckLeaders-$currentTime ))
if [[ $timeDifference -gt 0 ]] && [[ $EPOCH == "--next" ]]; then
myerror "Too early to check for next epoch"
fi
# actually do the checking
checkLeadershipSchedule
# done
rm -f $PID_FILE
echo "Done!"