Skip to content

Instantly share code, notes, and snippets.

@plowsof
Last active May 27, 2025 14:01
Show Gist options
  • Save plowsof/666afafce9ecdf0764960821ecc8b675 to your computer and use it in GitHub Desktop.
Save plowsof/666afafce9ecdf0764960821ecc8b675 to your computer and use it in GitHub Desktop.
get wallet sync height over time
#!/bin/bash
#run this script first then:
# wallet rpc ran with commands (deleting the cache first):
#rm wallet_with_height_0
#./monero-wallet-rpc --wallet-file wallet_with_height_0 --password "" --disable-rpc-login --rpc-bind-port 18084 --daemon-address node3.monerodevs.org:18089 --no-initial-sync --log-level 1 --trusted-daemon
#to just get_height and ignore the setup/start background sync , remove line 62, comment out 51 and uncomment 50
RPC_PORT=18084
OUTPUT_DIR="test_sync_times"
ATTEMPT_NUMBER=1 # manually change this each run.. append to same file and parse later probably better
TARGET_HEIGHT=300000
OUTPUT_FILE="${OUTPUT_DIR}/attempt_${ATTEMPT_NUMBER}.txt"
mkdir -p "$OUTPUT_DIR"
setup_background_sync() {
curl -s -X POST "http://127.0.0.1:${RPC_PORT}/json_rpc" \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":"0","method":"setup_background_sync","params":{"background_sync_type":"reuse-wallet-password","wallet_password":"","background_cache_password":""}}'
}
start_background_sync() {
curl -s -X POST "http://127.0.0.1:${RPC_PORT}/json_rpc" \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":"0","method":"start_background_sync"}'
}
get_height() {
curl -s -X POST "http://127.0.0.1:${RPC_PORT}/json_rpc" \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":"0","method":"get_height"}' | jq -r '.result.height'
}
# i cant find a 'set restore height'ish rpc call on getmonero - didnt look in the src yet
# so rescan_blockchain effectively resets the wallets height to 0
# issue: rpc does not respond to any get_height calls , but appears to be busy doing things in log 4
rescan_blockchain() {
curl -s -X POST "http://127.0.0.1:${RPC_PORT}/json_rpc" \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":"0","method":"rescan_blockchain"}'
}
# looping until the rpc wallet is online / available to calls as we start the script first.
# then blindly assuming the following rpc calls just work D:
while true; do
#RESULT=$(rescan_blockchain) # does not respond to curls ignore
#RESULT=$(get_height) #the loop will wait for rpc to come online but get_height returns a number. ignore the jq error.
RESULT=$(setup_background_sync)
if echo "$RESULT" | jq -e '.error' > /dev/null; then
echo "wallet rpc offline or call failed, retrying in 1s......."
else
echo "rpc online / setup successful"
break
fi
sleep 1
done
start_background_sync
START_TIME=$(date +%s)
echo "time(s) | height"
while true; do
HEIGHT=$(get_height)
NOW=$(date +%s)
ELAPSED=$((NOW - START_TIME))
# echo to stdout and append to file
echo "$ELAPSED $HEIGHT" | tee -a "$OUTPUT_FILE"
if [[ "$HEIGHT" -ge "$TARGET_HEIGHT" ]]; then
echo "Reached target height: $HEIGHT"
break
fi
sleep 10
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment