diff --git a/contrib/seeds/.gitignore b/contrib/seeds/.gitignore new file mode 100644 --- /dev/null +++ b/contrib/seeds/.gitignore @@ -0,0 +1 @@ +seeds_*.txt diff --git a/contrib/seeds/collect-and-update-seeds.sh b/contrib/seeds/collect-and-update-seeds.sh new file mode 100755 --- /dev/null +++ b/contrib/seeds/collect-and-update-seeds.sh @@ -0,0 +1,78 @@ +#!/usr/bin/env bash + +set -e + +help_message() { + SCRIPT_NAME=`basename $0` + echo "$SCRIPT_NAME expects one argument: " + echo "Where the host provides \`/seeds_main.txt\` and \`/seeds_test.txt\`" + echo "Example: $SCRIPT_NAME seederdump.bitframe.org" +} + +if [ -z "$1" ]; then + help_message + exit 1 +fi + +if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then + help_message + exit 0 +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 + rm "$SEEDS_INPUT" +} + +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" +} + +fetch_and_make_seeds $1 "main" 100 || skip_seeds "main" +fetch_and_make_seeds $1 "test" 10 || skip_seeds "test" + +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" + git checkout HEAD -- ":/contrib/seeds/nodes_test.txt" + git checkout HEAD -- ":/src/chainparamsseeds.h" + exit 1 +fi + +echo "Done."