Skip to content

Instantly share code, notes, and snippets.

@gotjoshua
Created February 11, 2021 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gotjoshua/2cf63e6841a2a2eea04b678b49003258 to your computer and use it in GitHub Desktop.
Save gotjoshua/2cf63e6841a2a2eea04b678b49003258 to your computer and use it in GitHub Desktop.
Steady batched txs
#!/bin/bash
# usage tasks.sh BATCHES MaxWalletNumber MinWalletNumber PrefixOfExistingKeys SigningKeyName ToWhatAddress
read -e -s -p "Keyring pass?" PP
BATCHES=${1:-10}
MAX_WALLET=${2:-400}
MIN_WALLET=${3:-0}
BATCH_SIZE=$(( (MAX_WALLET-MIN_WALLET) / BATCHES))
PREFIX=${3:-begreenXtra}
SIGNER=${4:-begreen}
# using send to self stfategy instead
#TO=${5:-regen:1ky56h2ndwrgcxxr3s3g4uzseaj2mhthznheqhw} #PoSFreak
rm -f multi.tx
rm -f signed.tx
rm -f broadcast-async.tx
rm -f merged.tx
touch merged.tx
## from: ###############
# https://stackoverflow.com/questions/1455695/forking-multi-threaded-processes-bash
declare -a pids
waitPids() {
while [ ${#pids[@]} -ne 0 ]; do
# echo "Waiting for pids: ${pids[@]}"
local range=$(eval echo {0..$((${#pids[@]}-1))})
local i
for i in $range; do
if ! kill -0 ${pids[$i]} 2> /dev/null; then
echo -n "Done -- ${pids[$i]}"
unset pids[$i]
fi
done
pids=("${pids[@]}") # Expunge nulls created by unset.
sleep 1
done
echo "DoneDone!"
}
addPid() {
local desc=$1
local pid=$2
echo -n "$desc-$pid ... "
pids=(${pids[@]} $pid)
}
NODE=""
for ever in {0..1000000}; do
echo "---------- Loop $ever --------------"
for j in $(eval echo {0..$((BATCHES - 1))}); do
# outer loop
START=$((MIN_WALLET + j * BATCH_SIZE))
END=$((START + BATCH_SIZE))
RANGE=$(eval echo {$START..$END})
echo "================ Starting Loop $START..$END $(date)==============="
for i in $RANGE; do
whichWallet="begreenXtra${i}"
# echo $whichWallet
eachAddress=$(echo $PP | regen keys show $whichWallet -a)
sendCmd="regen tx bank send $eachAddress $eachAddress 10utree --chain-id aplikigo-1 --memo $whichWallet --gas-prices 0.025utree -y --generate-only"
# echo $sendCmd
$sendCmd > ${BATCHES}obo${i}.tx
cat ${BATCHES}obo${i}.tx >> multi.tx
echo $PP | regen tx sign ${BATCHES}obo${i}.tx --chain-id aplikigo-1 --from $whichWallet > ${BATCHES}obosigned${i}.tx &
addPid "$whichWallet" $!
# add each to signed file
cat ${BATCHES}obosigned${i}.tx >> signed.tx
done
waitPids #signing
for i in $RANGE; do
#alternate nodes
# NODE=$([ $((i % 2)) == 0 ] && echo "--node http://161.35.51.84:26657" || echo "") # "--node http://localhost:26657"
# Fork the broadcasts
BRCMD="regen tx broadcast ${BATCHES}obosigned${i}.tx $NODE -b async"
# echo $BRCMD
echo $PP | $BRCMD &
# addPid "bc$i" $! # broadcast for ${BATCHES}obosigned${i}.tx
done
# waitPids & #broadcasting
echo
echo
echo
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment