Skip to content

Commit

Permalink
fix bugs for auto config with a migration (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
elvece authored Sep 10, 2024
1 parent 5adba48 commit 141c4cb
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 26 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ RUN chown -R mysql:mysql /build/data /var/lib/mysql/data
ADD ./docker_entrypoint.sh /usr/local/bin/docker_entrypoint.sh
ADD assets/utils/*.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/*.sh
RUN mkdir -p /usr/local/bin/migrations
ADD ./scripts/migrations/*.sh /usr/local/bin/migrations
RUN chmod a+x /usr/local/bin/migrations/*

# remove to we can manually handle db initalization
RUN rm -rf /var/lib/mysql/
12 changes: 0 additions & 12 deletions docker_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,6 @@ _term() {
kill -TERM "$frontend_process" 2>/dev/null
}

# Record system memory info to read for bitcoin auto config
SYSTEM_MEM_INFO=$(awk '/MemTotal/{print $(NF-1)}' /proc/meminfo)
SYSTEM_MEM_FILE=/root/start9/system_mem_info

if [ -f "$SYSTEM_MEM_FILE" ]
then
echo "$SYSTEM_MEM_INFO" > "$SYSTEM_MEM_FILE"
else
touch /root/start9/system_mem_info
echo "$SYSTEM_MEM_INFO" > "$SYSTEM_MEM_FILE"
fi

# FRONTEND SETUP

LIGHTNING_DETECTED_PORT=9735
Expand Down
30 changes: 27 additions & 3 deletions manifest.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
id: mempool
title: Mempool
version: 3.0.0.2
version: 3.0.0.3
release-notes: |
* Sets bounds on RAM used for the mempool
* Update the latest pool data from the Mempool repository on startup
Expand Down Expand Up @@ -166,8 +166,32 @@ backup:
io-format: yaml
migrations:
from:
"*":
"<2.3.1.4":
type: script
">=2.3.1.4 <2.5.0":
type: script
">=2.5.0 <=3.0.0.2":
type: docker
image: main
system: false
entrypoint: /usr/local/bin/migrations/gt_2_5_0_lt_3_0_0_2.sh
args: ["from"]
io-format: json
mounts:
main: /root
inject: false
to:
"*":
"<2.3.1.4":
type: script
">=2.3.1.4 <2.5.0":
type: script
">=2.5.0 <3.0.0.2":
type: docker
image: main
system: false
entrypoint: /usr/local/bin/migrations/gt_2_5_0_lt_3_0_0_2.sh
args: ["to"]
io-format: json
mounts:
main: /root
inject: false
29 changes: 29 additions & 0 deletions scripts/migrations/gt_2_5_0_lt_3_0_0_2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

set -ea

# up migration
if [ $1 = "from" ]; then
# Record system memory info to read for bitcoin auto config
SYSTEM_MEM_INFO=$(awk '/MemTotal/{print $(NF-1)}' /proc/meminfo)
SYSTEM_MEM_FILE=/root/start9/system_mem_info

if [ -f "$SYSTEM_MEM_FILE" ]
then
echo "$SYSTEM_MEM_INFO" > "$SYSTEM_MEM_FILE"
else
touch /root/start9/system_mem_info
echo "$SYSTEM_MEM_INFO" > "$SYSTEM_MEM_FILE"
fi
echo '{"configured": true }'

exit 0
# down migration
elif [ $1 = "to" ]; then
rm /root/start9/system_mem_info
echo '{"configured": true }'
exit 0
else
echo "FATAL: Invalid argument: {from, to}. Migration failed." >&2
exit 1
fi
17 changes: 6 additions & 11 deletions scripts/procedures/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,15 @@ async function getSystemMemoryLimit(effects: T.Effects) {
// convert kb to mb
const memMB = parseInt(memdata) / 1000
return Math.round(memMB / 6)
} catch (e) {
effects.info(e)
// default recommended is 300MB
} catch (_e) {
// recommended default is 300MB
return 300
}
}

export const dependencies: T.ExpectedExports.dependencies = {
bitcoind: {
// deno-lint-ignore require-await
async check(effects, configInput) {
effects.info("check bitcoind");
const config = matchBitcoindConfig.unsafeCast(configInput);
if (!config.rpc.enable) {
return { error: "Must have RPC enabled" };
Expand All @@ -48,23 +45,21 @@ export const dependencies: T.ExpectedExports.dependencies = {
"Pruning must be disabled to use Bitcoin Core.",
};
}
const limit = await getSystemMemoryLimit(effects)
if (limit > 300 && config.advanced.mempool.maxmempool >= limit) {
const limit = await getSystemMemoryLimit(effects);
if (limit > 300 && config.advanced.mempool.maxmempool > limit) {
return {
error: "In order to safely run Mempool, Bitcoin Core's \"maxmempool\" size cannot exceed 1/6 of the system RAM"
}
}
return { result: null };
},
// deno-lint-ignore require-await
async autoConfigure(effects, configInput) {
effects.info("autoconfigure bitcoind");
const config = matchBitcoindConfig.unsafeCast(configInput);
config.rpc.enable = true;
config.txindex = true;
config.advanced.pruning.mode = "disabled";
const limit = await getSystemMemoryLimit(effects)
if (limit > 300 && config.advanced.mempool.maxmempool >= limit) {
const limit = await getSystemMemoryLimit(effects);
if (limit > 300 && config.advanced.mempool.maxmempool > limit) {
config.advanced.mempool.maxmempool = limit
}
return { result: config };
Expand Down

0 comments on commit 141c4cb

Please sign in to comment.