-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-leaderlog.sh
51 lines (42 loc) · 2 KB
/
check-leaderlog.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
# Run this script 1.5 days before the end of the epoch to get the leaderlog details for the current or next epoch.
# Based on an example from https://github.com/AndrewWestberg/cncli/tree/develop/scripts
# Replace the placeholders in <...>
PORT=<YOUR_PORT> # can be found in your cnode env file
POOL_ID=<YOUR_POOL_ID> # can be found e.g. on pooltool.io
POOL_NAME="<YOUR_POOL_NAME>" # your pool name in cnode
LOC_VRF_SKEY="${CNODE_HOME}/priv/pool/${POOL_NAME}/vrf.skey"
BYRON_GENESIS="${CNODE_HOME}/files/byron-genesis.json"
SHELLEY_GENESIS="${CNODE_HOME}/files/shelley-genesis.json"
if [ "$1" == "-h" ]; then
echo "Usage: `basename $0` [current|next]"
exit 0
fi
if [ -z "$1" ]; then
echo "Usage: `basename $0` [current|next]"
exit 0
fi
LEDGER_SET="current"
POOL_STAKE_ATTR="poolStakeSet"
ACTIVE_STAKE_ATTR="activeStakeSet"
if [ "$1" == "next" ]; then
LEDGER_SET="next"
POOL_STAKE_ATTR="poolStakeMark"
ACTIVE_STAKE_ATTR="activeStakeMark"
fi
export CARDANO_NODE_SOCKET_PATH=${CNODE_HOME}/sockets/node0.socket
echo "Starting sync..."
"$HOME"/.cargo/bin/cncli sync --host 127.0.0.1 --port $PORT --no-service
echo "Getting snapshot..."
SNAPSHOT=$("$HOME"/.cabal/bin/cardano-cli query stake-snapshot --stake-pool-id $POOL_ID --mainnet)
POOL_STAKE=$(echo "$SNAPSHOT" | grep -oP "(?<= \"${POOL_STAKE_ATTR}\": )\d+(?=,?)")
ACTIVE_STAKE=$(echo "$SNAPSHOT" | grep -oP "(?<= \"$ACTIVE_STAKE_ATTR\": )\d+(?=,?)")
echo "active stake:" $ACTIVE_STAKE
echo "Getting leaderlog for $1 epoch..."
LEADER_LOG=`"$HOME"/.cargo/bin/cncli leaderlog --pool-id $POOL_ID --pool-vrf-skey $LOC_VRF_SKEY --byron-genesis $BYRON_GENESIS --shelley-genesis $SHELLEY_GENESIS --pool-stake $POOL_STAKE --active-stake $ACTIVE_STAKE --ledger-set $LEDGER_SET`
EPOCH=`jq .epoch <<< $LEADER_LOG`
echo "Epoch $EPOCH 🧙🔮:"
SLOTS=`jq .epochSlots <<< $LEADER_LOG`
IDEAL=`jq .epochSlotsIdeal <<< $LEADER_LOG`
PERFORMANCE=`jq .maxPerformance <<< $LEADER_LOG`
echo "Slots: $SLOTS 🎰, $PERFORMANCE% 🍀max, $IDEAL: 🧱ideal"