-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Perform accelerated initial blockchain download as a systemd service
Reduces the time spent in and amount of stuff done during provisioning. Allows a future dashboard / admin page to monitor progress. Only use the expedited IBD script if there is a big disk present.
- Loading branch information
Showing
13 changed files
with
161 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[Path] | ||
PathExists=/home/bitcoin/.ibd_service_finished |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[Path] | ||
PathExists=/home/bitcoin/.ibd_service_requests_shutdown |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[Unit] | ||
Description=Shutdown after expedited IBD to allow downgrade | ||
After=network.target | ||
ConditionPathExists=/home/bitcoin/.ibd_service_requests_shutdown | ||
|
||
[Service] | ||
ExecStartPre=/usr/bin/rm /home/bitcoin/.ibd_service_requests_shutdown | ||
ExecStartPre=/bin/systemctl disable ibd-shutdown.service | ||
ExecStartPost=/usr/bin/rm /usr/lib/systemd/system/ibd-shutdown.service | ||
ExecStartPost=/usr/bin/rm /usr/lib/systemd/system/ibd-shutdown.path | ||
ExecStart=/sbin/shutdown | ||
|
||
User=root | ||
Type=oneshot | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
[Unit] | ||
Description=Check if initial blockchain download has done and if we're on a special machine. | ||
After=network.target | ||
ConditionPathExists=!/home/bitcoin/.ibd_service_finished | ||
# Newer versions of systemd (>~ october 2017) | ||
# StartLimitIntervalSec=10 | ||
# StartLimitBurst=1 | ||
# RestartSec=60 | ||
[Service] | ||
ExecStart=/usr/local/src/matreon/vendor/bitcoin/initial_blockchain_download_and_prune.sh | ||
WorkingDirectory=/home/bitcoin | ||
User=bitcoin | ||
Type=simple | ||
Restart=on-failure | ||
StartLimitInterval=10 | ||
StartLimitBurst=1 | ||
RestartSec=60 | ||
# Hardening measures | ||
#################### | ||
# Provide a private /tmp and /var/tmp. | ||
PrivateTmp=true | ||
# Mount /usr, /boot/ and /etc read-only for the process. | ||
ProtectSystem=full | ||
# Disallow the process and all of its children to gain | ||
# new privileges through execve(). | ||
NoNewPrivileges=true | ||
# Use a new /dev namespace only populated with API pseudo devices | ||
# such as /dev/null, /dev/zero and /dev/random. | ||
PrivateDevices=true | ||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/bin/bash | ||
|
||
# Skip if no big disk is available: | ||
if [ ! -L /home/bitcoin/big-disk ]; then | ||
touch /home/bitcoin/.ibd_service_finished | ||
exit 0 | ||
fi | ||
|
||
# Skip if IBD has already been done: | ||
if [ -f /home/bitcoin/.ibd_service_finished ]; then exit 0; fi | ||
|
||
# /home/bitcoin/big-disk needs to be symlink pointing a big drive | ||
export OPTS="-conf=/etc/bitcoin/bitcoin.conf -datadir=/home/bitcoin/big-disk" | ||
|
||
# Start bitcoind with manual pruning and a large enough dbcache. | ||
echo "Start bitcoind as a daemon..." | ||
bitcoind $OPTS -dbcache=20000 -prune=1 -daemon | ||
|
||
set -o pipefail | ||
while sleep 60 | ||
do | ||
if bitcoin-cli $OPTS getblockchaininfo | jq -e '.initialblockdownload==false'; then | ||
# Prune to slightly before (a lot on testnet) the first Lightning block: | ||
bitcoin-cli $OPTS pruneblockchain 504500 | ||
bitcoin-cli $OPTS stop | ||
while sleep 10 | ||
do # Wait for shutdown | ||
if [ ! -f /home/bitcoin/big-disk/bitcoind.pid ] && [ ! -f /home/bitcoin/big-disk/testnet3/bitcoind.pid ]; then | ||
break | ||
fi | ||
done | ||
break | ||
fi | ||
done | ||
|
||
# Move pruned blocks to /home/bitcoin/.bitcoin | ||
if ! cat /etc/bitcoin/bitcoin.conf | grep '^testnet=1'; then | ||
mv /home/bitcoin/big-disk/blocks/*.dat /home/bitcoin/.bitcoin/blocks | ||
mv /home/bitcoin/big-disk/blocks/index/* /home/bitcoin/.bitcoin/blocks/index | ||
mv /home/bitcoin/big-disk/chainstate /home/bitcoin/.bitcoin | ||
else | ||
mv /home/bitcoin/big-disk/testnet3/blocks/*.dat /home/bitcoin/.bitcoin/testnet3/blocks | ||
mv /home/bitcoin/big-disk/testnet3/blocks/index/* /home/bitcoin/.bitcoin/testnet3/blocks/index | ||
mv /home/bitcoin/big-disk/testnet3/chainstate /home/bitcoin/.bitcoin/testnet3 | ||
fi | ||
|
||
# Remove big disk symlink | ||
rm /home/bitcoin/big-disk | ||
|
||
# Mark IBD as done: | ||
touch /home/bitcoin/.ibd_service_finished | ||
touch /home/bitcoin/.ibd_service_requests_shutdown |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[Path] | ||
PathExists=/home/bitcoin/.ibd_service_finished |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[Path] | ||
PathExists=/home/bitcoin/.ibd_service_finished |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters