Skip to content

Commit

Permalink
If peers data is corrupted, move it. (bitcoin/bitcoin#26599)
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasDorier committed Jan 6, 2023
1 parent c94a3ec commit ba4e9c3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Bitcoin/24.0.1/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ if [[ "$1" == "bitcoin-cli" || "$1" == "bitcoin-tx" || "$1" == "bitcoind" || "$1
ln -sfn "$BITCOIN_DATA" /home/bitcoin/.bitcoin
chown -h bitcoin:bitcoin /home/bitcoin/.bitcoin
rm -f /home/bitcoin/.bitcoin/settings.json

# peers_dat is routinely corrupted, preventing bitcoind to start, see https://github.com/bitcoin/bitcoin/issues/26599
peers_dat="/home/bitcoin/.bitcoin/peers.dat"
peers_dat_corrupted="/home/bitcoin/.bitcoin/peers_corrupted.dat"
if [[ -f "${peers_dat}" ]]; then
actual_hash=$(head -c -32 "${peers_dat}" | sha256sum | cut -c1-64 | xxd -r -p | sha256sum | cut -c1-64)
expected_hash=$(tail -c 32 "${peers_dat}" | xxd -ps -c 32)
if [[ "${actual_hash}" != "${expected_hash}" ]]; then
echo "${peers_dat} is corrupted, moving it to ${peers_dat_corrupted}"
rm -f "${peers_dat_corrupted}"
mv "${peers_dat}" "${peers_dat_corrupted}"
fi
fi

exec gosu bitcoin "$@"
else
exec "$@"
Expand Down
3 changes: 3 additions & 0 deletions Bitcoin/24.0.1/linuxamd64.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ RUN set -ex \
FROM debian:bullseye-slim
COPY --from=builder "/tmp/bin" /usr/local/bin

RUN apt-get update && \
apt-get install -qq --no-install-recommends xxd && \
rm -rf /var/lib/apt/lists/*
RUN chmod +x /usr/local/bin/gosu && groupadd -r bitcoin && useradd -r -m -g bitcoin bitcoin

# create data directory
Expand Down
3 changes: 3 additions & 0 deletions Bitcoin/24.0.1/linuxarm32v7.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ FROM arm32v7/debian:bullseye-slim
COPY --from=builder "/tmp/bin" /usr/local/bin
COPY --from=builder /usr/bin/qemu-arm-static /usr/bin/qemu-arm-static

RUN apt-get update && \
apt-get install -qq --no-install-recommends xxd && \
rm -rf /var/lib/apt/lists/*
RUN chmod +x /usr/local/bin/gosu && groupadd -r bitcoin && useradd -r -m -g bitcoin bitcoin

# create data directory
Expand Down
3 changes: 3 additions & 0 deletions Bitcoin/24.0.1/linuxarm64v8.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ FROM arm64v8/debian:bullseye-slim
COPY --from=builder "/tmp/bin" /usr/local/bin
COPY --from=builder /usr/bin/qemu-aarch64-static /usr/bin/qemu-aarch64-static

RUN apt-get update && \
apt-get install -qq --no-install-recommends xxd && \
rm -rf /var/lib/apt/lists/*
RUN chmod +x /usr/local/bin/gosu && groupadd -r bitcoin && useradd -r -m -g bitcoin bitcoin

# create data directory
Expand Down

0 comments on commit ba4e9c3

Please sign in to comment.