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 | |||||
help_message() { | |||||
SCRIPT_NAME=`basename $0` | |||||
echo "$SCRIPT_NAME expects one argument: <URL to seeder data host>" | |||||
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 | |||||
deadalnix: You return and yet never check the return value. | |||||
fi | |||||
deadalnixUnsubmitted Not Done Inline ActionsSo if there isn't, we go for several weeks without update? That doesn't sound optimal. deadalnix: So if there isn't, we go for several weeks without update? That doesn't sound optimal. | |||||
echo "Processing ${2}net seeds..." | |||||
python3 makeseeds.py < "$SEEDS_INPUT" > $SEEDS_OUTPUT | |||||
deadalnixUnsubmitted Not Done Inline ActionsThis can fail. deadalnix: This can fail. | |||||
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 | |||||
deadalnixUnsubmitted Not Done Inline ActionsI'm pretty this could fail. deadalnix: I'm pretty this could fail. | |||||
echo "Sanity checking the resulting patch..." | |||||
DIFF_LINE_PATTERN="^[+-][^+-|$]" | |||||
NUM_MAINNET_DIFFS=`git diff nodes_main.txt | grep "$DIFF_LINE_PATTERN" | wc -l` | |||||
FabienUnsubmitted Not Done Inline ActionsOptimization: you can replace grep [...] | wc -l with grep -c [...] Fabien: Optimization: you can replace `grep [...] | wc -l` with `grep -c [...]` | |||||
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 | |||||
deadalnixUnsubmitted Not Done Inline ActionsThis rely on unchecked assumption - that rows comes in canonical order, and that the diff tool will chose to diff in a certain way. This is at best fragile and doesn't reall test what we want to test: that we have seed to bootstrap from. deadalnix: This rely on unchecked assumption - that rows comes in canonical order, and that the diff tool… | |||||
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" | |||||
deadalnixUnsubmitted Not Done Inline Actionsgit reset --hard But arguably, this is not up to this patch to decide what to cleanup. If things are fubared such as the script fails, then we shouldn't expect the script to work properly, which is an assumption you make by giving it the responsibility of cleaning up. deadalnix: git reset --hard
But arguably, this is not up to this patch to decide what to cleanup. If… | |||||
exit 1 | |||||
fi | |||||
echo "Done." |
You return and yet never check the return value.