Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: wait for bitcoind to accept RPC calls #76

Merged
merged 2 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ docker pull ghcr.io/joinmarket-webui/jam-standalone:latest
The following environment variables control the configuration
- `APP_USER` (optional; username used for basic authentication)
- `APP_PASSWORD` (optional, but required if `APP_USER` is provided; password used for basic authentication)
- `ENSURE_WALLET` (optional; create and load the wallet in bitcoin core on startup)
- `ENSURE_WALLET` (optional, defaults to `false`; create and load the wallet in bitcoin core on startup)
- `READY_FILE` (optional; wait for a file to be created before starting all services, e.g. to wait for chain synchronization)
- `REMOVE_LOCK_FILES` (optional; remove leftover lockfiles from possible unclean shutdowns on startup)
- `RESTORE_DEFAULT_CONFIG` (optional; overwrites any existing `joinmarket.cfg` file the container's default config on startup)
- `REMOVE_LOCK_FILES` (optional, defaults to `false`; remove leftover lockfiles from possible unclean shutdowns on startup)
- `RESTORE_DEFAULT_CONFIG` (optional, defaults to `false`; overwrites any existing `joinmarket.cfg` file with a default config)
- `WAIT_FOR_BITCOIND` (optional, defaults to `true`; wait for bitcoind to accept RPC request and report >= 100 blocks)

Variables starting with prefix `JM_` will be applied to `joinmarket.cfg` e.g.:
- `JM_GAPLIMIT: 2000` will set the `gaplimit` config value to `2000`
Expand Down Expand Up @@ -110,6 +111,7 @@ docker run --rm -it \
--env ENSURE_WALLET="true" \
--env REMOVE_LOCK_FILES="true" \
--env RESTORE_DEFAULT_CONFIG="true" \
--env WAIT_FOR_BITCOIND="true" \
--volume jmdatadir:/root/.joinmarket \
--publish "8080:80" \
joinmarket-webui/jam-standalone
Expand Down
2 changes: 1 addition & 1 deletion standalone/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ RUN addgroup --system tor \
&& apt-get update \
&& apt-get install -qq --no-install-recommends --no-install-suggests -y \
# image dependencies
tini iproute2 procps vim \
tini iproute2 procps vim jq \
# servers dependencies (see `install.sh`)
build-essential automake pkg-config libtool libltdl-dev python3-dev python3-setuptools python3-pip \
# tor
Expand Down
29 changes: 25 additions & 4 deletions standalone/jam-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,36 @@ done

# wait for a ready file to be created if necessary
if [ "${READY_FILE}" ] && [ "${READY_FILE}" != "false" ]; then
echo "Waiting for $READY_FILE to be created..."
echo "Waiting for file $READY_FILE to be created..."
while [ ! -f "$READY_FILE" ]; do sleep 1; done
echo "The chain is fully synched"
echo "Successfully waited for file $READY_FILE to be created."
fi

btcuser="${jmenv['rpc_user']}:${jmenv['rpc_password']}"
btchost="http://${jmenv['rpc_host']}:${jmenv['rpc_port']}"

# wait for bitcoind to accept RPC requests if necessary
if [ "${WAIT_FOR_BITCOIND}" != "false" ]; then
echo "Waiting for bitcoind to accept RPC requests..."
# use `getblockchaininfo` command here, as this is the first request JM is
# performing during initialization
getblockchaininfo_payload="{\
\"jsonrpc\":\"2.0\",\
\"id\":\"curl\",\
\"method\":\"getblockchaininfo\",\
\"params\":{}\
}"
# generally only testing for a non-error response would be enough, but
# waiting for blocks >= 100 is needed for regtest environments as well!
until curl --silent --show-error --user "${btcuser}" --data-binary "${getblockchaininfo_payload}" "${btchost}" 2>&1 | jq -e ".result.blocks >= 100" > /dev/null 2>&1
do
sleep 5
done
echo "Successfully waited for bitcoind to accept RPC requests."
fi

# ensure that a wallet exists and is loaded if necessary
if [ "${ENSURE_WALLET}" = "true" ]; then
btcuser="${jmenv['rpc_user']}:${jmenv['rpc_password']}"
btchost="http://${jmenv['rpc_host']}:${jmenv['rpc_port']}"
wallet_name="${jmenv['rpc_wallet_file']}"

echo "Creating wallet $wallet_name if missing..."
Expand Down