Skip to content

Commit

Permalink
Fix prev epoch argument and node 1.35 jq filters (#35)
Browse files Browse the repository at this point in the history
* Fix prev epoch argument and node 1.35 jq filters

* Use python instead of jq for snapshot processing

* Send slots to PoolTool on epoch start

* Update documentation for leaderlog

* Use grep instead of python for processing snapshot json
  • Loading branch information
happystaking authored Aug 14, 2023
1 parent b607793 commit 7bb25dd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
8 changes: 4 additions & 4 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ CNCLI ```sync```, ```sendtip``` and ```leaderlog``` can be easily enabled as ```

- ```sync``` will continuously keep the ```cncli.db``` database synchronized.
- ```sendtip``` will continuously send your stake pool ```tip``` to PoolTool.
- ```leaderlog``` will run every day at 09:45 UTC and can be configured to run all or any of the following tasks:
- on day 1 of the epoch send the assigned slots for the current and previous epoch to PoolTool and
- on day 4 of the epoch calculate the leaderlog for the next epoch and mail it and/or write a slots.csv file.
- ```leaderlog``` will run twice per day and can be configured to run all or any of the following tasks:
- on beginning of the epoch send the assigned slots for the current and previous epoch to PoolTool and
- on day 4 of the epoch calculate the leaderlog for the next epoch, mail it and/or write a slots.csv file.

To set up ```systemd```:

Expand Down Expand Up @@ -316,7 +316,7 @@ WantedBy=multi-user.target
Description=CNCLI Leaderlog
[Timer]
OnCalendar=*-*-* 09:45:00 UTC
OnCalendar=*-*-* 09,21:50:00 UTC
Unit=cncli-leaderlog.service
[Install]
Expand Down
23 changes: 13 additions & 10 deletions scripts/cncli-leaderlog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#
# Depending on the day of the epoch we are in (1 to 5) this script will run one
# or more of the tasks above.
# On day 1: send slots for the current and previous epoch to PoolTool.
# On day 4: calculate and mail next epoch leaderlog and write slots.csv.
# On epoch start: send slots for the current and previous epoch to PoolTool.
# On epoch day 4: calculate next epoch leaderlog, mail it and/or write slots.csv.
#
# Usage: Via systemd timer or ./cncli-leaderlog.sh
# Author: Leon • HAPPY Staking Pool
Expand All @@ -29,6 +29,7 @@ shelleyGenesisFile="/etc/cardano/mainnet/shelley-genesis.json"
byronGenesisFile="/etc/cardano/mainnet/byron-genesis.json"
binCardanoCli="/usr/local/bin/cardano-cli"
binCnCli="/usr/local/bin/cncli"
binPython3="/usr/bin/python3"
dbCnCli="/var/local/cncli/db.sqlite"

# Script internal variables
Expand Down Expand Up @@ -62,19 +63,19 @@ calculateLeaderLog ()

if [[ $binCardanoCliMajorVersion -eq 1 ]];
then
poolTotalStake=$(echo "$poolSnapshot" | jq -r .poolStakeMark)
poolActiveStake=$(echo "$poolSnapshot" | jq -r .activeStakeMark)
poolTotalStake=$(echo "$poolSnapshot" | grep -oP "(?<= \"pool${3^}\": )\d+(?=,?)")
poolActiveStake=$(echo "$poolSnapshot" | grep -oP "(?<= \"active${3^}\": )\d+(?=,?)")
else
poolTotalStake=$(echo "$poolSnapshot" | jq -r .pools.${hexStakePool}.$3)
poolActiveStake=$(echo "$poolSnapshot" | jq -r .total.$3)
stakeNumbers=$(echo "$poolSnapshot" | grep -oP "(?<= \"$3\": )\d+(?=,?)")
poolTotalStake=$(echo $stakeNumbers | cut -d' ' -f1)
poolActiveStake=$(echo $stakeNumbers | cut -d' ' -f2)
fi

$binCnCli leaderlog \
--db $dbCnCli --pool-id $hexStakePool --pool-vrf-skey $vrfSigningKeyFile \
--byron-genesis $byronGenesisFile --shelley-genesis $shelleyGenesisFile \
--pool-stake $poolTotalStake --active-stake $poolActiveStake \
--tz $timezone --ledger-set ${1} > /tmp/leaderlog

else
echo "The VRF signing key file is not readable."
exit 1
Expand Down Expand Up @@ -126,14 +127,16 @@ writeLeaderSlots ()
fi
}

if [[ $dayOfEpoch -eq 1 ]];
# Run within 10 minutes of epoch start
if [[ $dayOfEpoch -eq 0 && $secondsLeftInEpoch -lt 432000 && $secondsLeftInEpoch -gt 431400 ]];
then
calculateLeaderLog prev $(($currentEpoch-1)) stakeSet
calculateLeaderLog prev $(($currentEpoch-1)) stakeGo
calculateLeaderLog current $currentEpoch stakeSet
sendPoolToolSlots
fi

if [[ $dayOfEpoch -eq 4 && $secondsLeftInEpoch -le 129600 && $secondsLeftInEpoch -gt 84600 ]];
# Run as soon as the leaderlog is available
if [[ $dayOfEpoch -eq 4 && $secondsLeftInEpoch -le 129600 && $secondsLeftInEpoch -gt 129000 ]];
then
calculateLeaderLog next $(($currentEpoch+1)) stakeMark
mailLeaderLog next $(($currentEpoch+1))
Expand Down

0 comments on commit 7bb25dd

Please sign in to comment.