Skip to content

Commit 8aebc3a

Browse files
committed
feat: mithril client and restore support
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent 461ed31 commit 8aebc3a

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ COPY --from=cardano-node-build /usr/local/lib/ /usr/local/lib/
3030
COPY --from=cardano-node-build /usr/local/include/ /usr/local/include/
3131
COPY --from=cardano-node-build /root/.local/bin/cardano-* /usr/local/bin/
3232
COPY --from=ghcr.io/blinklabs-io/nview:0.1.0 /usr/local/bin/nview /usr/local/bin/
33+
COPY --from=ghcr.io/input-output-hk/mithril-client:2335.0-a6caa1c /app/bin/mithril-client /usr/local/bin/
3334
COPY bin/ /usr/local/bin/
3435
COPY config/ /opt/cardano/config/
3536
RUN apt-get update -y && \
@@ -50,6 +51,8 @@ RUN apt-get update -y && \
5051
netbase \
5152
pkg-config \
5253
procps \
54+
sqlite3 \
55+
wget \
5356
zlib1g && \
5457
rm -rf /var/lib/apt/lists/*
5558
RUN curl -sLo /usr/local/bin/gLiveView.sh \

bin/run-network

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,23 @@ case ${NETWORK} in
1212
*) echo "[Error] Managed configuration for network ${NETWORK} does not exist"; exit 1 ;;
1313
esac
1414

15+
# Mithril
16+
if ! test -e /data/db; then
17+
if [[ ${NETWORK} != preview ]]; then
18+
__base=https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration
19+
__url=${__base}/release-${NETWORK}
20+
export GENESIS_VERIFICATION_KEY=$(curl ${__url}/genesis.vkey 2> /dev/null)
21+
export AGGREGATOR_ENDPOINT=https://aggregator.release-${NETWORK}.api.mithril.network/aggregator
22+
export SNAPSHOT_DIGEST=$(mithril-client snapshot list --json | jq -r '.[0].digest')
23+
mkdir -p /data
24+
cd /data
25+
echo "Starting: /usr/local/bin/mithril-client snapshot download ${SNAPSHOT_DIGEST}"
26+
mithril-client snapshot download ${SNAPSHOT_DIGEST}
27+
else
28+
echo "Mithril not supported on preview... skipping"
29+
fi
30+
fi
31+
1532
echo "Starting: /usr/local/bin/cardano-node run"
1633
echo "--config /opt/cardano/config/${NETWORK}/config.json"
1734
echo "--database-path /data/db"

bin/run-node

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ CARDANO_PORT=${CARDANO_PORT:-3001}
4242
CARDANO_RTS_OPTS=${CARDANO_RTS_OPTS:--N2 -A64m -I0 -qg -qb --disable-delayed-os-memory-return}
4343
CARDANO_SOCKET_PATH=${CARDANO_SOCKET_PATH:-/opt/cardano/ipc/socket}
4444
CARDANO_TOPOLOGY=${CARDANO_TOPOLOGY:-${CARDANO_CONFIG_BASE}/${CARDANO_NETWORK}/topology.json}
45+
# mithril
46+
AGGREGATOR_ENDPOINT=${AGGREGATOR_ENDPOINT:-https://aggregator.release-${CARDANO_NETWORK}.api.mithril.network/aggregator}
47+
GENESIS_VERIFICATION_KEY=${GENESIS_VERIFICATION_KEY:-$(<${CARDANO_CONFIG_BASE}/${CARDANO_NETWORK}/genesis.vkey)}
48+
SNAPSHOT_DIGEST=${SNAPSHOT_DIGEST:-latest}
49+
RESTORE_SNAPSHOT=${RESTORE_SNAPSHOT:-true}
4550

4651
echo CARDANO_BIND_ADDR=${CARDANO_BIND_ADDR}
4752
echo CARDANO_BLOCK_PRODUCER=${CARDANO_BLOCK_PRODUCER}
@@ -64,8 +69,37 @@ if [[ ${CARDANO_BLOCK_PRODUCER} == true ]]; then
6469
echo CARDANO_SHELLEY_OPERATIONAL_CERTIFICATE=${CARDANO_SHELLEY_OPERATIONAL_CERTIFICATE}
6570
fi
6671

72+
if [[ ${CARDANO_NETWORK} == preview ]]; then
73+
if [[ ${RESTORE_SNAPSHOT} == true ]]; then
74+
echo "Mithril not supported on preview... skipping"
75+
fi
76+
RESTORE_SNAPSHOT=false
77+
fi
78+
79+
echo AGGREGATOR_ENDPOINT=${AGGREGATOR_ENDPOINT}
80+
echo GENESIS_VERIFICATION_KEY=${GENESIS_VERIFICATION_KEY}
81+
echo SNAPSHOT_DIGEST=${SNAPSHOT_DIGEST}
82+
echo RESTORE_SNAPSHOT=${RESTORE_SNAPSHOT}
83+
6784
mkdir -p $(dirname ${CARDANO_SOCKET_PATH})
6885

86+
# Mithril
87+
if ! test -e ${CARDANO_DATABASE_PATH}/protocolMagicId; then
88+
echo "Detected empty ${CARDANO_DATABASE_PATH}"
89+
if [[ ${RESTORE_SNAPSHOT} == true ]]; then
90+
mkdir -p ${CARDANO_DATABASE_PATH}
91+
cd $(dirname ${CARDANO_DATABASE_PATH})
92+
export AGGREGATOR_ENDPOINT GENESIS_VERIFICATION_KEY SNAPSHOT_DIGEST
93+
echo "Starting: /usr/local/bin/mithril-client snapshot download ${SNAPSHOT_DIGEST}"
94+
mithril-client snapshot download ${SNAPSHOT_DIGEST}
95+
if [[ $(cd ${CARDANO_DATABASE_PATH}; pwd -P) != $(pwd -P)/db ]]; then
96+
mv -f db/* ${CARDANO_DATABASE_PATH}/
97+
fi
98+
fi
99+
elif [[ ${RESTORE_SNAPSHOT} == true ]]; then
100+
echo "Detected populated ${CARDANO_DATABASE_PATH}... skipping restore"
101+
fi
102+
69103
if [[ ${CARDANO_BLOCK_PRODUCER} == true ]]; then
70104
effopts=(--config ${CARDANO_CONFIG} \
71105
--database-path ${CARDANO_DATABASE_PATH} \

config/mainnet/genesis.vkey

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5b3139312c36362c3134302c3138352c3133382c31312c3233372c3230372c3235302c3134342c32372c322c3138382c33302c31322c38312c3135352c3230342c31302c3137392c37352c32332c3133382c3139362c3231372c352c31342c32302c35372c37392c33392c3137365d

config/preprod/genesis.vkey

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5b3132372c37332c3132342c3136312c362c3133372c3133312c3231332c3230372c3131372c3139382c38352c3137362c3139392c3136322c3234312c36382c3132332c3131392c3134352c31332c3233322c3234332c34392c3232392c322c3234392c3230352c3230352c33392c3233352c34345d

0 commit comments

Comments
 (0)