Skip to content

Commit

Permalink
Fixed unneeded reindex
Browse files Browse the repository at this point in the history
The condition checking if reindex was needed was broken because `-v`
switch of `grep` only inverts matched lines, not exit code. As a result
reindex was triggerred even when not needed.

As a part of this fix, the change contains two important improvements to
tests:

* Test that reindex is not triggerred when not needed
* Ability to switch from which repository to test update

Closes #108
  • Loading branch information
Kixunil committed Jan 5, 2021
1 parent 0f8088b commit 1b772c5
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 14 deletions.
15 changes: 8 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
MAINTAINER="Martin Habostiak <[email protected]>"

UPGRADE_REPO=experimental
SOURCE_DIR:=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))
BITCOIN_SOURCE_DIR=$(SOURCE_DIR)bitcoin/
# Forgetting to type this resulted in lot of time wasted.
Expand Down Expand Up @@ -48,7 +49,7 @@ test-here: test-here-all-basic test-here-all-nonconfict-upgrade
test-in-qubes-dvm: test-split-$(SPLIT_STRATEGY) $(addprefix test-in-qubes-dvm-multi-package-,$(TEST_MULTI_PACKAGE))

test-split-none:
$(SOURCE_DIR)/tests/qubes-tools/test-in-dispvm.sh "$(BUILD_DIR)" "$(SOURCE_DIR)" "TEST_ALL_PACKAGES=$(TEST_ALL_PACKAGES)" "DPKG_DEBUG_LEVEL=$(DPKG_DEBUG_LEVEL)" test-here
$(SOURCE_DIR)/tests/qubes-tools/test-in-dispvm.sh "$(BUILD_DIR)" "$(SOURCE_DIR)" "TEST_ALL_PACKAGES=$(TEST_ALL_PACKAGES)" "DPKG_DEBUG_LEVEL=$(DPKG_DEBUG_LEVEL)" "UPGRADE_REPO=$(UPGRADE_REPO)" test-here

test-split-upgrade: test-in-qubes-dvm-all-basic $(addprefix test-in-qubes-dvm-upgrade-,$(TEST_ALL_PACKAGES))

Expand All @@ -57,7 +58,7 @@ test-split-all: $(addprefix test-in-qubes-dvm-basic-,$(TEST_ALL_PACKAGES)) $(add
test-package-%: test-$(TEST_STRATEGY)-basic-%

test-in-qubes-dvm-multi-package-%: tests/multi-package/%.sh
$(SOURCE_DIR)/tests/qubes-tools/test-in-dispvm.sh "$(BUILD_DIR)" "$(SOURCE_DIR)" "TEST_MULTI_PACKAGE=$(TEST_MULTI_PACKAGE)" "DPKG_DEBUG_LEVEL=$(DPKG_DEBUG_LEVEL)" "test-here-multi-package-$*"
$(SOURCE_DIR)/tests/qubes-tools/test-in-dispvm.sh "$(BUILD_DIR)" "$(SOURCE_DIR)" "TEST_MULTI_PACKAGE=$(TEST_MULTI_PACKAGE)" "DPKG_DEBUG_LEVEL=$(DPKG_DEBUG_LEVEL)" "UPGRADE_REPO=$(UPGRADE_REPO)" "test-here-multi-package-$*"

test-here-multi-package-%: tests/multi-package/%.sh
$(SOURCE_DIR)/tests/prepare_machine.sh "$(BUILD_DIR)"
Expand All @@ -71,12 +72,12 @@ test-here-basic-%: test-here-prepare-machine
$(SOURCE_DIR)/tests/package_clean_install.sh "$(BUILD_DIR)" "$*"

test-here-upgrade-%: | $(UPGRADE_DEPS)
$(SOURCE_DIR)/tests/before_upgrade.sh "$(BUILD_DIR)" "$*"
$(SOURCE_DIR)/tests/before_upgrade.sh "$(BUILD_DIR)" "$(UPGRADE_REPO)" "$*"
$(SOURCE_DIR)/tests/prepare_machine.sh "$(BUILD_DIR)"
$(SOURCE_DIR)/tests/upgrade_package.sh "$(BUILD_DIR)" "$*"

test-here-prepare-all-nonconfict-upgrade: | $(UPGRADE_DEPS)
$(SOURCE_DIR)/tests/before_upgrade.sh "$(BUILD_DIR)" "$(TEST_ALL_PACKAGES_NON_CONFLICT)"
$(SOURCE_DIR)/tests/before_upgrade.sh "$(BUILD_DIR)" "$(UPGRADE_REPO)" "$(TEST_ALL_PACKAGES_NON_CONFLICT)"
$(SOURCE_DIR)/tests/prepare_machine.sh "$(BUILD_DIR)"

test-here-single-nonconfict-upgrade-%: test-here-prepare-all-nonconfict-upgrade | $(UPGRADE_DEPS)
Expand All @@ -88,10 +89,10 @@ test-here-prepare-machine:
$(SOURCE_DIR)/tests/prepare_machine.sh "$(BUILD_DIR)"

test-in-qubes-dvm-all-basic:
$(SOURCE_DIR)/tests/qubes-tools/test-in-dispvm.sh "$(BUILD_DIR)" "$(SOURCE_DIR)" "TEST_ALL_PACKAGES=$(TEST_ALL_PACKAGES)" "DPKG_DEBUG_LEVEL=$(DPKG_DEBUG_LEVEL)" test-here-all-basic
$(SOURCE_DIR)/tests/qubes-tools/test-in-dispvm.sh "$(BUILD_DIR)" "$(SOURCE_DIR)" "TEST_ALL_PACKAGES=$(TEST_ALL_PACKAGES)" "DPKG_DEBUG_LEVEL=$(DPKG_DEBUG_LEVEL)" "UPGRADE_REPO=$(UPGRADE_REPO)" test-here-all-basic

test-in-qubes-dvm-basic-%:
$(SOURCE_DIR)/tests/qubes-tools/test-in-dispvm.sh "$(BUILD_DIR)" "$(SOURCE_DIR)" "TEST_ALL_PACKAGES=$(TEST_ALL_PACKAGES)" "DPKG_DEBUG_LEVEL=$(DPKG_DEBUG_LEVEL)" "test-here-basic-$*"
$(SOURCE_DIR)/tests/qubes-tools/test-in-dispvm.sh "$(BUILD_DIR)" "$(SOURCE_DIR)" "TEST_ALL_PACKAGES=$(TEST_ALL_PACKAGES)" "DPKG_DEBUG_LEVEL=$(DPKG_DEBUG_LEVEL)" "UPGRADE_REPO=$(UPGRADE_REPO)" "test-here-basic-$*"

test-in-qubes-dvm-upgrade-%:
$(SOURCE_DIR)/tests/qubes-tools/test-in-dispvm.sh "$(BUILD_DIR)" "$(SOURCE_DIR)" SPLIT_STRATEGY=upgrade "TEST_ALL_PACKAGES=$(TEST_ALL_PACKAGES)" "DPKG_DEBUG_LEVEL=$(DPKG_DEBUG_LEVEL)" "test-here-upgrade-$*"
$(SOURCE_DIR)/tests/qubes-tools/test-in-dispvm.sh "$(BUILD_DIR)" "$(SOURCE_DIR)" SPLIT_STRATEGY=upgrade "TEST_ALL_PACKAGES=$(TEST_ALL_PACKAGES)" "DPKG_DEBUG_LEVEL=$(DPKG_DEBUG_LEVEL)" "UPGRADE_REPO=$(UPGRADE_REPO)" "test-here-upgrade-$*"
15 changes: 14 additions & 1 deletion bitcoin/check_needs_reindex.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,27 @@ fi

. /usr/share/bitcoind/definitions.sh || exit 1

function get_prune_value() {
local config_file
local prune_line
local prune_value

config_file="$1"
# we don't use pipe because we prefer to kill the script in case of a problem
prune_line="`grep '^ *prune *=' "$config_file"`" || exit 1
echo $prune_line | sed -e 's/^ *prune *= *//' -e 's/ *$//' || exit 1
}

if [ -d "$conf_dir" ];
then
# if the file doesn't exist it's first install
if [ -f "$prev_chain_mode_file" ];
then
prev_prune_value="`get_prune_value "$prev_chain_mode_file"`"
cur_prune_value="`get_prune_value "$chain_mode_file"`"
# If pruning was enabled (different from 0) previously and it's disabled (0) now, we need to reindex
# Note that txindex is handled by bitcoind, no need to check that.
if grep -qv '^ *prune *= *0 *$' "$prev_chain_mode_file" && grep -q '^ *prune *= *0 *$' "$chain_mode_file";
if [ "$prev_prune_value" != 0 ] && [ "$cur_prune_value" = 0 ];
then
echo "Info: The chain will be reindexed after restart" >&2
touch "$needs_reindex_marker_file"
Expand Down
2 changes: 1 addition & 1 deletion pkg_specs/[email protected]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "bitcoin-@variant"
bin_package = "bitcoind"
min_patch = "9"
min_patch = "10"
binary = "/usr/share/bitcoind/bitcoind"
conf_param = "-conf="
user = { group = true, create = { home = true } }
Expand Down
6 changes: 6 additions & 0 deletions pkg_specs/bitcoin.changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
bitcoin (0.20.0-10) buster; urgency=medium

* Fixed bug causing bitcoind to always reindex after upgrade/install

-- Martin Habovstiak <[email protected]> Tue, 5 Jan 2021 15:12:21 +0100

bitcoin (0.20.0-9) buster; urgency=medium

* Reindex when changing from pruned to non-pruned
Expand Down
7 changes: 4 additions & 3 deletions tests/before_upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ set -e

test_dir="`dirname "$0"`"
pkg_dir="$1"
packages="$2"
upgrade_from="$2"
packages="$3"

. "$test_dir/common.sh"

test -n "$DPKG_DEBUG_LEVEL" echo "debug $DPKG_DEBUG_LEVEL" | sudo tee /etc/dpkg/dpkg.cfg.d/cadr-test >/dev/null
test -n "$DPKG_DEBUG_LEVEL" && echo "debug $DPKG_DEBUG_LEVEL" | sudo tee /etc/dpkg/dpkg.cfg.d/cadr-test >/dev/null

"$test_dir/setup_deb_ln_ask_me.sh" "--internal-test"
"$test_dir/setup_deb_ln_ask_me.sh" "$upgrade_from" "--internal-test"

preload_config
sudo mkdir -p /etc/selfhost
Expand Down
1 change: 1 addition & 0 deletions tests/data/beta_apt.list
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deb https://deb.ln-ask.me/beta buster common local desktop
52 changes: 52 additions & 0 deletions tests/data/beta_key.gpg
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
-----BEGIN PGP PUBLIC KEY BLOCK-----

mQINBF8pkfsBEACbY/AFiCnCSOJZOBWHChLnf+5PqU6ANDWkD7FvnyKWgZqCI/Cm
7EEBioBY6IJNiD89UwRUhv8qgh/bobCqrEiyPWyDpVZXP66mDR7AZckC4oYVq6e7
PfRYEFyBxkw+r978F5l0NHpbQLbqqVU2P6x2kGBZRgrkqcJTBvXZEnpSdwIC/9ZD
UvRbOV60S+v2+IoX/e/RsEuLc+ptjXv+jLJ12cEpFk46SFKZxA3k08SV9p69HVA/
QMREAoN1r/QuEfYFhS/IyB60SBwMUEy6P0ftolZv1jadBltLq9T7EN2l6tNYM5jr
6z2dzQ+kK0K6Pdw0YKyif9z7l+qoToYvT6GEsYIgIypnn1JRVk0N8HsCeSciYZp0
pwo6GYw524lS2aNmMOJV69PrDeKH7kUT/cKA/xNmrPwGJ14h3FcYhHvNcVtnszwF
ee/sxoH0DCGHX6OQNL3dT+zJp17MWFjyMgvND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XjlsPTAYYGYgOxnVBshH
hfv9nSJNewcZNz4Jsgfn4NZ9BLCMMg2zXxzbfBecoCkswmf5ZXhzVPKLjWBmOZhN
N7KUeiF652jogMuJwtroXjFp7e4FuZWOr5gl7z97Ov75y2PbAyQO1mjQe8r+T9C3
vQ+Z8z9P2nR71XUAV+U7SkwxUA1rNBiKDmyOplWjHGUf01zaBYeHhvA8OKEKVT63
AB0Oqbe0tbxejcqR08Ju0xvHpVG+kN1dpYO97W+KHwTx6Qd7i7YjxCDFsj91uCiO
9TjAo5tZEibfq6LnrZ+dxANhikgBl4SwhKTfBluPudayI5vOh5hgUj3+m5Hf/bWA
tYCpXqb+pxPt4sTiBhe5BQKg9G7mE2TSDiz+Xe27/DMKbWff4+tnEmqFXDCJwW+w
HUnXcN+cNR3mcg6qTbqisEnu9xJo2RpxPWYH6rQBQvYIzdQg
=KcGD
-----END PGP PUBLIC KEY BLOCK-----
24 changes: 24 additions & 0 deletions tests/per-package/bitcoin-regtest/after_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

sleep 10

if ps aux | grep -v grep | grep -q 'bitcoind.*-reindex' || sudo journalctl --no-pager -u bitcoin-regtest | grep -q 'Reindexing';
then
echo "Error: unneeded reindex" >&2
exit 1
fi

if gen_addr="$(wget -O - --post-data='{"jsonrpc": "1.0", "id":"curltest0", "method": "getnewaddress", "params": [] }' --header 'content-type: text/plain;' --header 'Authorization: Basic '"`sudo cat /var/run/bitcoin-regtest/cookie | base64 | tr -d '\n'`" "http://127.0.0.1:`sudo grep '^rpcport=' /etc/bitcoin-regtest/bitcoin.conf | sed 's/^rpcport=//' | tr -d '\n'`" | sed 's/^.*"result" *: *"\([^"]*\)".*$/\1/')";
then
echo Generating 150 blocks to address "$gen_addr" >&2
if wget -O - --post-data='{"jsonrpc": "1.0", "id":"curltest1", "method": "generatetoaddress", "params": [150, "'"$gen_addr"'"] }' --header 'content-type: text/plain;' --header 'Authorization: Basic '"`sudo cat /var/run/bitcoin-regtest/cookie | base64 | tr -d '\n'`" "http://127.0.0.1:`sudo grep '^rpcport=' /etc/bitcoin-regtest/bitcoin.conf | sed 's/^rpcport=//' | tr -d '\n'`";
then
echo "Succcess generating 150 blocks" >&2
else
echo "Failed to generate blocks" >&2
exit 1
fi
else
echo "Failed to get an address for generating coins" >&2
exit 1
fi
7 changes: 7 additions & 0 deletions tests/per-package/bitcoin-regtest/after_upgrade.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

if ps aux | grep -v grep | grep -q 'bitcoind.*-reindex' || sudo journalctl --no-pager -u bitcoin-regtest | grep -q 'Reindexing';
then
echo "Error: unneeded reindex" >&2
exit 1
fi
6 changes: 4 additions & 2 deletions tests/setup_deb_ln_ask_me.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ test_dir="`dirname "$0"`"

. "$test_dir/common_vars.sh"

sudo cp "$test_data_dir/experimental_apt.list" /etc/apt/sources.list.d/cryptoanarchy-experimental.list
sudo apt-key add < "$test_data_dir/experimental_key.gpg"
repo="$1"

sudo cp "$test_data_dir/${repo}_apt.list" /etc/apt/sources.list.d/cryptoanarchy-experimental.list
sudo apt-key add < "$test_data_dir/${repo}_key.gpg"
sudo cp "$test_data_dir"/microsoft_apt.list /etc/apt/sources.list.d/microsoft.list
sudo apt-key add < "$test_data_dir"/microsoft_key.gpg
sudo apt update

0 comments on commit 1b772c5

Please sign in to comment.