Changeset View
Changeset View
Standalone View
Standalone View
contrib/seeds/collect-and-update-seeds.sh
- This file was added.
Property | Old Value | New Value |
---|---|---|
File Mode | null | 100755 |
#!/usr/bin/env bash | |||||
set -e | |||||
if [ -z "$1" ]; then | |||||
echo "$0 expects one argument: <URL to seeder data host>" | |||||
echo "Where the host provides \`/seeds_main.txt\` and \`/seeds_test.txt\`" | |||||
echo "Example: $0 seederdump.bitframe.org" | |||||
exit 1 | |||||
fi | |||||
TOPLEVEL=`git rev-parse --show-toplevel` | |||||
cd "${TOPLEVEL}/contrib/seeds/" | |||||
# Arguments: seeder_host chain min_good_nodes | |||||
fetch_and_make_seeds() { | |||||
SEEDS_INPUT="seeds_${2}.txt" | |||||
SEEDS_OUTPUT="nodes_${2}.txt" | |||||
echo "Fetching ${2}net seed dump file..." | |||||
curl "${1}/${SEEDS_INPUT}" > "$SEEDS_INPUT" || { echo "Curl exited with code: $?"; return 1; } | |||||
echo "Sanity checking $SEEDS_INPUT..." | |||||
# More than just a few good ABC nodes with 100% uptime over the past 24 hours | |||||
UPTIME_PATTERN="100.00% 100.00% 100.00%" | |||||
GOOD_NODES_PATTERN=".*:[0-9]*[ ]*[1] .*${UPTIME_PATTERN}.*Bitcoin ABC" | |||||
if [ "$(cat "$SEEDS_INPUT" | grep "$GOOD_NODES_PATTERN" | wc -l)" -lt "$3" ]; then | |||||
echo "Error: ${2}net seed dump file should have at least $3 good ABC nodes!" | |||||
return 1 | |||||
fi | |||||
echo "Processing ${2}net seeds..." | |||||
python3 makeseeds.py < "$SEEDS_INPUT" > $SEEDS_OUTPUT | |||||
Fabien: After the call to `makeseeds.py` you can remove the `$SEEDS_INPUT` files. | |||||
} | |||||
skip_seeds() { | |||||
echo "Skipping ${1}net seeds due to an error." | |||||
# Checkout last good nodes file incase anything was written to it. | |||||
git checkout HEAD ":/contrib/seeds/nodes_${1}.txt" | |||||
FabienUnsubmitted Not Done Inline Actionsgit checkout HEAD -- ":/contrib/seeds/nodes_${1}.txt" Fabien: `git checkout HEAD -- ":/contrib/seeds/nodes_${1}.txt"` | |||||
} | |||||
fetch_and_make_seeds $1 "main" 100 || skip_seeds "main" | |||||
fetch_and_make_seeds $1 "test" 10 || skip_seeds "test" | |||||
FabienUnsubmitted Not Done Inline ActionsThe generate-seeds.py script expects both file to be here, or fails. If you can't get both you should bail, or eventually create an empty nodes_xxx.txt. Fabien: The `generate-seeds.py` script expects both file to be here, or fails. If you can't get both… | |||||
jasonbcoxAuthorUnsubmitted Done Inline ActionsThe nodes_* files are tracked by source control, so they should always be there. jasonbcox: The nodes_* files are tracked by source control, so they should always be there. | |||||
echo "Generating seeds patch..." | |||||
python3 generate-seeds.py . > ../../src/chainparamsseeds.h | |||||
echo "Sanity checking the resulting patch..." | |||||
DIFF_LINE_PATTERN="^[+-][^+-|$]" | |||||
NUM_MAINNET_DIFFS=`git diff nodes_main.txt | grep "$DIFF_LINE_PATTERN" | wc -l` | |||||
NUM_TESTNET_DIFFS=`git diff nodes_test.txt | grep "$DIFF_LINE_PATTERN" | wc -l` | |||||
NUM_CHAINPARAMS_DIFFS=`git diff ../../src/chainparamsseeds.h | grep "$DIFF_LINE_PATTERN" | wc -l` | |||||
if [ $((NUM_MAINNET_DIFFS + NUM_TESTNET_DIFFS)) != "$NUM_CHAINPARAMS_DIFFS" ]; then | |||||
echo "Error: Number of diff lines in src/chainparamsseeds.h do not match the input seed dump files!" | |||||
echo "Diff lines in nodes_main.txt: $NUM_MAINNET_DIFFS" | |||||
echo "Diff lines in nodes_test.txt: $NUM_TESTNET_DIFFS" | |||||
echo "Diff lines in src/chainparamsseeds.h: $NUM_CHAINPARAMS_DIFFS" | |||||
# Checkout last good state for all seeds files | |||||
git checkout HEAD ":/contrib/seeds/nodes_main.txt" | |||||
FabienUnsubmitted Not Done Inline ActionsDito, use -- before the path for all the git checkout calls. Fabien: Dito, use `--` before the path for all the `git checkout` calls. | |||||
git checkout HEAD ":/contrib/seeds/nodes_test.txt" | |||||
git checkout HEAD ":/src/chainparamsseeds.h" | |||||
exit 1 | |||||
fi | |||||
echo "Done." |
After the call to makeseeds.py you can remove the $SEEDS_INPUT files.