Skip to content

Instantly share code, notes, and snippets.

@d13co
Last active August 26, 2023 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d13co/1fe40467cfb8683a2e9fefab7771b719 to your computer and use it in GitHub Desktop.
Save d13co/1fe40467cfb8683a2e9fefab7771b719 to your computer and use it in GitHub Desktop.
algokey-gen.sh
#!/bin/bash
# Author: @D13_co
# Context: https://d13.co/posts/redundant-participation-nodes-on-algorand/
set -e
# first argument: address
address=$1
# second argument: duration in rounds, defaults to 650K
duration=$2
duration=${duration:-650000}
if [ "$address" == "" ]; then
echo "Usage: $0 <address> [<duration>]"
echo "address is mandatory. duration is optional"
exit 1
fi
# try to run goal node status and fail if it errors
if ! (algorun goal node status > /dev/null 2>&1 || goal node status > /dev/null 2>&1) then
echo "Failed to run: [algorun] goal node status"
echo "Please check that you are able to run this command and try again."
exit 2
fi
start=$((algorun goal node status 2> /dev/null || goal node status) | grep "Last committed block" | awk '{print $4}')
echo Current round: $start
# Start round is +10 from current round
start=$((start + 10))
echo "Start round: $start (+10)"
# End round calculation
end=$((start + duration))
echo "End round: $end (+$duration)"
# Dilution is square root of duration
# Using awk for portability
sqrt=`awk "BEGIN {printf \"%.0f\", sqrt($duration)}"`
echo "Dilution (sqrt(end-start)): $sqrt"
echo Execute this command to generate your key:
echo ""
echo "algokey part generate --parent $address --first $start --last $end --dilution $sqrt --keyfile $address-$start-$end.partkey"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment