Skip to content

Commit ccd7ded

Browse files
authored
Feat/229 add mithril support (#232)
* feat: added mithril into the docker file * foundation for Mithril functionality * foundations for Mithril * feat: added mithril to dockerfile * feat: dockerfile now includes mithril * feat: added mithril syncing to the eentrypoint.sh * chore: added controlled stopping of background processes * chore: added wait for mithril-client to finish downloading before continuing * feat: added mithril to docker-compose * fix: fixed slow start of cardano node. Killing it ungracefully leads to a broken starting routine * fix: artillery test --------- Co-authored-by: Michiel <michiel.bellengmail.com>
1 parent e06fd58 commit ccd7ded

File tree

11 files changed

+313
-16
lines changed

11 files changed

+313
-16
lines changed

.env.IntegrationTest

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,18 @@ CARDANO_NODE_PORT=3001
2929
CARDANO_NODE_SUBMIT_HOST=yaci-cli
3030
NODE_SUBMIT_API_PORT=8090
3131
CARDANO_NODE_VERSION=0.0.0
32-
CARDANO_NODE_SOCKET_DIR=/node
33-
CARDANO_NODE_SOCKET_PATH=${CARDANO_NODE_SOCKET_DIR}/node.socket
34-
CARDANO_NODE_DB=/node/db
32+
CARDANO_NODE_DIR=/node
33+
CARDANO_NODE_SOCKET_PATH=${CARDANO_NODE_DIR}/node.socket
34+
CARDANO_NODE_DB=${CARDANO_NODE_DIR}/db
3535
CARDANO_CONFIG=./config/${NETWORK}
3636

37+
MITHRIL_SYNC=true
38+
SNAPSHOT_DIGEST=latest
39+
# if not set standard values will be used
40+
AGGREGATOR_ENDPOINT=
41+
# if not set standard values will be used
42+
GENESIS_VERIFICATION_KEY=
43+
3744
## Api env
3845
API_DOCKER_IMAGE_TAG=main
3946
API_SPRING_PROFILES_ACTIVE=dev

.env.docker-compose

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,19 @@ CARDANO_NODE_PORT=3001
2727
CARDANO_NODE_VERSION=8.9.3
2828
CARDANO_NODE_SUBMIT_HOST=cardano-submit-api
2929
NODE_SUBMIT_API_PORT=8090
30-
CARDANO_NODE_SOCKET_DIR=/node
31-
CARDANO_NODE_SOCKET_PATH=${CARDANO_NODE_SOCKET_DIR}/node.socket
32-
CARDANO_NODE_DB=/node/db
30+
CARDANO_NODE_DIR=/node
31+
CARDANO_NODE_SOCKET_PATH=${CARDANO_NODE_DIR}/node.socket
32+
CARDANO_NODE_DB=${CARDANO_NODE_DIR}/db
3333
CARDANO_CONFIG=./config/${NETWORK}
3434

35+
## Mithril
36+
MITHRIL_SYNC=true
37+
SNAPSHOT_DIGEST=latest
38+
# if not set standard values will be used
39+
AGGREGATOR_ENDPOINT=
40+
# if not set standard values will be used
41+
GENESIS_VERIFICATION_KEY=
42+
3543
## Api env
3644
API_DOCKER_IMAGE_TAG=main
3745
API_SPRING_PROFILES_ACTIVE=dev

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ Depending on using a snapshot feature or not, this will take X amount of time. Y
5555
```bash
5656
docker exec rosetta tail -f /logs/node.log
5757
```
58+
- Access indexer logs:
59+
```bash
60+
docker exec rosetta tail -f /logs/indexer.log
61+
```
5862
- Interactive access to container:
5963
```bash
6064
docker exec -it rosetta bash # direct bash access within the container

docker-api-indexer.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ services:
2828
DEVKIT_PORT: ${DEVKIT_PORT}
2929
volumes:
3030
- ${CARDANO_CONFIG}:/config
31-
- ${CARDANO_NODE_SOCKET_DIR}:${CARDANO_NODE_SOCKET_DIR}
31+
- ${CARDANO_NODE_DIR}:${CARDANO_NODE_DIR}
3232
healthcheck:
3333
test: [ "CMD-SHELL", "curl --fail http://localhost:${API_PORT}/network/options -H 'Content-Type: application/json' --data '{\"network_identifier\": {\"blockchain\": \"cardano\",\"network\": \"${NETWORK}\"},\"metadata\": {}}' -X POST" ]
3434
interval: 30s

docker-node.yaml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,40 @@
11
version: '3.8'
22
services:
3+
mithril:
4+
build:
5+
context: ./docker/dockerfiles/mithril
6+
environment:
7+
- NETWORK=${NETWORK}
8+
- MITHRIL_SYNC=${MITHRIL_SYNC}
9+
- SNAPSHOT_DIGEST=${SNAPSHOT_DIGEST}
10+
- AGGREGATOR_ENDPOINT=${AGGREGATOR_ENDPOINT}
11+
- GENESIS_VERIFICATION_KEY=${GENESIS_VERIFICATION_KEY}
12+
volumes:
13+
- ${CARDANO_NODE_DIR}:/node
314
cardano-node:
15+
build:
16+
context: ./docker/dockerfiles/node
417
image: ghcr.io/intersectmbo/cardano-node:${CARDANO_NODE_VERSION}
518
environment:
619
- NETWORK=${NETWORK}
720
volumes:
8-
- ${CARDANO_NODE_SOCKET_DIR}:${CARDANO_NODE_SOCKET_DIR}
21+
- ${CARDANO_NODE_DIR}:/node/
922
- ${CARDANO_NODE_DB}:/node/db
1023
- ${CARDANO_CONFIG}:/config
1124
ports:
1225
- ${CARDANO_NODE_PORT}:${CARDANO_NODE_PORT}
13-
entrypoint: cardano-node run --database-path /node/db --port ${CARDANO_NODE_PORT} --socket-path ${CARDANO_NODE_SOCKET_PATH} --topology /config/topology.json --config /config/config.json
14-
26+
entrypoint: cardano-node run --database-path /node/db --port ${CARDANO_NODE_PORT} --socket-path /node/node.socket --topology /config/topology.json --config /config/config.json
27+
depends_on:
28+
mithril:
29+
condition: service_completed_successfully
1530
cardano-submit-api:
1631
image: ghcr.io/intersectmbo/cardano-submit-api:${CARDANO_NODE_VERSION}
1732
environment:
1833
- NETWORK=${NETWORK}
1934
depends_on:
2035
- cardano-node
2136
volumes:
22-
- ${CARDANO_NODE_SOCKET_DIR}:/node-ipc
37+
- ${CARDANO_NODE_DIR}:/node-ipc
2338
ports:
2439
- ${NODE_SUBMIT_API_PORT}:8090
2540
restart: on-failure
@@ -29,6 +44,7 @@ services:
2944
max-size: "200k"
3045
max-file: "10"
3146

47+
3248
networks:
3349
default:
3450
name: cardano-rosetta-java-${NETWORK}

docker/.env.dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ PROTOCOL_MAGIC=764824073
99
SYNC=true
1010
VERIFICATION=true
1111

12+
# Mithril snapshots
13+
MITHRIL_SYNC=true
14+
SNAPSHOT_DIGEST=latest
15+
# if not set standard values will be used
16+
AGGREGATOR_ENDPOINT=
17+
# if not set standard values will be used
18+
GENESIS_VERIFICATION_KEY=
19+
1220
## Postgres variables
1321
DB_NAME=rosetta-java
1422
DB_USER=rosetta_db_admin

docker/Dockerfile

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,24 @@ ARG GHC_VERSION=8.10.7
2929
RUN bash -c "ghcup install ghc ${GHC_VERSION}"
3030
RUN bash -c "ghcup set ghc ${GHC_VERSION}"
3131

32+
33+
# Mithril setup
34+
ARG MITHRIL_VERSION=2423.0
35+
# Install dependencies
36+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash -s -- -y \
37+
&& apt update --fix-missing \
38+
&& apt install -y --no-install-recommends \
39+
build-essential m4 libssl-dev docker jq git cargo \
40+
&& apt-get clean
41+
RUN git clone https://github.com/input-output-hk/mithril.git \
42+
&& cd mithril \
43+
&& git checkout $MITHRIL_VERSION \
44+
&& cd mithril-client-cli \
45+
&& make build \
46+
&& mkdir -p /root/.local/bin \
47+
&& cp mithril-client /root/.local/bin/
48+
49+
3250
# Cardano node version
3351
ARG CARDANO_NODE_VERSION=8.9.4
3452

@@ -121,6 +139,7 @@ RUN mkdir -p /root/.local/bin \
121139
&& cp -p "$(./scripts/bin-path.sh cardano-cli)" /root/.local/bin/ \
122140
&& cp -p "$(./scripts/bin-path.sh cardano-submit-api)" /root/.local/bin/
123141

142+
124143
# Compile java applications
125144
FROM ubuntu:22.04 AS java-builder
126145

@@ -173,6 +192,7 @@ RUN apt install -y --no-install-recommends openjdk-21-jdk jq bc sudo curl \
173192
# Copy cardano node
174193
COPY --from=cardano-builder /usr/local/lib /usr/local/lib
175194
COPY --from=cardano-builder /root/.local/bin/cardano-* /usr/local/bin/
195+
COPY --from=cardano-builder /root/.local/bin/mithril-client /usr/local/bin/
176196
COPY --from=cardano-builder /root/src/cardano-node/cardano-submit-api/config/tx-submit-mainnet-config.yaml /cardano-submit-api-config/cardano-submit-api.yaml
177197
ENV LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
178198
ENV PATH=/usr/local/lib/:$PATH
@@ -197,5 +217,3 @@ RUN chmod +x /sbin/entrypoint.sh
197217
EXPOSE 8082
198218

199219
ENTRYPOINT ["/sbin/entrypoint.sh"]
200-
201-
CMD ["tail", "-f", "-n", "+1", "/logs/*.log"]

docker/dockerfiles/mithril/Dockerfile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
FROM ubuntu:22.04 AS cardano-builder
2+
3+
WORKDIR /root/src
4+
5+
# Mithril setup
6+
ARG MITHRIL_VERSION=2423.0
7+
# Install dependencies
8+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash -s -- -y \
9+
&& apt update --fix-missing \
10+
&& apt install -y --no-install-recommends \
11+
build-essential m4 libssl-dev docker jq git cargo ca-certificates wget \
12+
&& apt-get clean
13+
RUN git clone https://github.com/input-output-hk/mithril.git \
14+
&& cd mithril \
15+
&& git checkout $MITHRIL_VERSION \
16+
&& cd mithril-client-cli \
17+
&& make build \
18+
&& mkdir -p /root/.local/bin \
19+
&& cp mithril-client /root/.local/bin/
20+
21+
22+
FROM ubuntu:22.04 AS mithril-runner
23+
24+
COPY --from=cardano-builder /root/.local/bin/mithril-client /usr/local/bin
25+
RUN apt update --fix-missing \
26+
&& apt install -y wget
27+
COPY entrypoint.sh /sbin/entrypoint.sh
28+
RUN chmod +x /sbin/entrypoint.sh
29+
30+
CMD ["/sbin/entrypoint.sh"]
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
download_mithril_snapshot(){
4+
echo "Downloading Mithril Snapshot..."
5+
export CARDANO_NETWORK=$NETWORK
6+
case $NETWORK in
7+
mainnet)
8+
AGGREGATOR_ENDPOINT=${AGGREGATOR_ENDPOINT:-https://aggregator.release-mainnet.api.mithril.network/aggregator}
9+
GENESIS_VERIFICATION_KEY=${GENESIS_VERIFICATION_KEY:-$(wget -q -O - https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration/release-mainnet/genesis.vkey)}
10+
;;
11+
preprod)
12+
AGGREGATOR_ENDPOINT=${AGGREGATOR_ENDPOINT:-https://aggregator.release-preprod.api.mithril.network/aggregator}
13+
GENESIS_VERIFICATION_KEY=${GENESIS_VERIFICATION_KEY:-$(wget -q -O - https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration/release-preprod/genesis.vkey)}
14+
;;
15+
preview)
16+
AGGREGATOR_ENDPOINT=${AGGREGATOR_ENDPOINT:-https://aggregator.pre-release-preview.api.mithril.network/aggregator}
17+
GENESIS_VERIFICATION_KEY=${GENESIS_VERIFICATION_KEY:-$(wget -q -O - https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration/pre-release-preview/genesis.vkey)}
18+
;;
19+
sanchonet)
20+
AGGREGATOR_ENDPOINT=${AGGREGATOR_ENDPOINT:-https://aggregator.testing-sanchonet.api.mithril.network/aggregator}
21+
GENESIS_VERIFICATION_KEY=${GENESIS_VERIFICATION_KEY:-$(wget -q -O - https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration/testing-sanchonet/genesis.vkey)}
22+
;;
23+
esac
24+
mithril-client cardano-db download latest --download-dir /node &
25+
MITHRIL_PID=$!
26+
wait $MITHRIL_PID
27+
echo "Done downloading Mithril Snapshot"
28+
}
29+
echo $NETWORK
30+
if [ "${MITHRIL_SYNC}" == "true" ]; then
31+
download_mithril_snapshot
32+
fi
33+
34+
exit

docker/dockerfiles/node/Dockerfile

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
FROM ubuntu:22.04 AS cardano-builder
2+
3+
WORKDIR /root/src
4+
5+
# Install dependencies
6+
RUN apt update --fix-missing \
7+
&& apt install -y --no-install-recommends \
8+
automake build-essential pkg-config libffi-dev libgmp-dev libssl-dev libncurses-dev libsystemd-dev zlib1g-dev make \
9+
g++ tmux git jq wget libncursesw5-dev libtool autoconf liblmdb-dev curl ca-certificates \
10+
&& apt-get clean
11+
12+
13+
# Install ghcup
14+
ENV BOOTSTRAP_HASKELL_NONINTERACTIVE=1
15+
RUN bash -c "curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh"
16+
17+
ENV PATH=/root/.local/bin:/root/.ghcup/bin:/root/.cabal/bin:${PATH}
18+
19+
# Install cabal
20+
ARG CABAL_VERSION=3.8.1.0
21+
22+
RUN bash -c "ghcup install cabal ${CABAL_VERSION}"
23+
RUN bash -c "ghcup set cabal ${CABAL_VERSION}"
24+
25+
# Install GHC
26+
ARG GHC_VERSION=8.10.7
27+
28+
RUN bash -c "ghcup install ghc ${GHC_VERSION}"
29+
RUN bash -c "ghcup set ghc ${GHC_VERSION}"
30+
31+
# Cardano node version
32+
ARG CARDANO_NODE_VERSION=8.9.4
33+
34+
# Install sodium
35+
RUN export IOHKNIX_VERSION=$(curl https://raw.githubusercontent.com/IntersectMBO/cardano-node/${CARDANO_NODE_VERSION}/flake.lock | jq -r '.nodes.iohkNix.locked.rev') \
36+
&& echo "iohk-nix version: $IOHKNIX_VERSION" \
37+
&& export SODIUM_VERSION=$(curl https://raw.githubusercontent.com/input-output-hk/iohk-nix/${IOHKNIX_VERSION}/flake.lock | jq -r '.nodes.sodium.original.rev') \
38+
&& echo "Using sodium version: $SODIUM_VERSION" \
39+
&& git clone https://github.com/intersectmbo/libsodium \
40+
&& cd libsodium \
41+
&& git checkout ${SODIUM_VERSION} \
42+
&& ./autogen.sh \
43+
&& ./configure \
44+
&& make \
45+
&& make check \
46+
&& make install
47+
48+
ENV LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
49+
ENV PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
50+
51+
# Install libsodium
52+
RUN apt install -y --no-install-recommends libsodium-dev \
53+
&& apt-get clean
54+
55+
# Install secp256k1
56+
RUN export IOHKNIX_VERSION=$(curl https://raw.githubusercontent.com/IntersectMBO/cardano-node/${CARDANO_NODE_VERSION}/flake.lock | jq -r '.nodes.iohkNix.locked.rev') \
57+
&& echo "iohk-nix version: ${IOHKNIX_VERSION}" \
58+
&& export SECP256K1_VERSION=$(curl https://raw.githubusercontent.com/input-output-hk/iohk-nix/${IOHKNIX_VERSION}/flake.lock | jq -r '.nodes.secp256k1.original.ref') \
59+
&& echo "Using secp256k1 version:${SECP256K1_VERSION}" \
60+
&& git clone --depth 1 --branch ${SECP256K1_VERSION} https://github.com/bitcoin-core/secp256k1 \
61+
&& cd secp256k1 \
62+
&& ./autogen.sh \
63+
&& ./configure --enable-module-schnorrsig --enable-experimental \
64+
&& make \
65+
&& make check \
66+
&& make install
67+
68+
# Install blst
69+
RUN export BLST_VERSION=$(curl https://raw.githubusercontent.com/input-output-hk/iohk-nix/master/flake.lock | jq -r '.nodes.blst.original.ref') \
70+
&& git clone --depth 1 --branch ${BLST_VERSION} https://github.com/supranational/blst \
71+
&& cd blst \
72+
&& ./build.sh \
73+
&& echo "prefix=/usr/local" >> libblst.pc \
74+
&& echo "exec_prefix=\${prefix}" >> libblst.pc \
75+
&& echo "libdir=\${exec_prefix}/lib" >> libblst.pc \
76+
&& echo "includedir=\${prefix}/include" >> libblst.pc \
77+
&& echo "" >> libblst.pc \
78+
&& echo "Name: libblst" >> libblst.pc \
79+
&& echo "Description: Multilingual BLS12-381 signature library" >> libblst.pc \
80+
&& echo "URL: https://github.com/supranational/blst" >> libblst.pc \
81+
&& echo "Version: ${BLST_VERSION#v}" >> libblst.pc \
82+
&& echo "Cflags: -I\${includedir}" >> libblst.pc \
83+
&& echo "Libs: -L\${libdir} -lblst" >> libblst.pc \
84+
&& cp libblst.pc /usr/local/lib/pkgconfig/ \
85+
&& cp bindings/blst_aux.h bindings/blst.h bindings/blst.hpp /usr/local/include/ \
86+
&& cp libblst.a /usr/local/lib \
87+
&& bash -c "chmod u=rw,go=r /usr/local/{lib/{libblst.a,pkgconfig/libblst.pc},include/{blst.{h,hpp},blst_aux.h}}"
88+
89+
RUN apt install -y --no-install-recommends libsecp256k1-dev \
90+
&& apt-get clean
91+
92+
# Install node
93+
RUN git clone https://github.com/intersectmbo/cardano-node.git \
94+
&& cd cardano-node \
95+
&& git checkout tags/${CARDANO_NODE_VERSION} \
96+
&& echo "with-compiler: ghc-${GHC_VERSION}" >> cabal.project.local \
97+
&& echo "" >> cabal.project.local \
98+
&& echo "package cardano-crypto-praos" >> cabal.project.local \
99+
&& echo " flags: -external-libsodium-vrf" >> cabal.project.local \
100+
&& echo "" >> cabal.project.local \
101+
&& echo "package trace-dispatcher" >> cabal.project.local \
102+
&& echo " ghc-options: -Wwarn" >> cabal.project.local \
103+
&& echo "" >> cabal.project.local \
104+
&& echo "package HsOpenSSL" >> cabal.project.local \
105+
&& echo " flags: -homebrew-openssl" >> cabal.project.local \
106+
&& echo "" >> cabal.project.local \
107+
&& mkdir -p /usr/local/opt/openssl \
108+
&& ln -s /opt/homebrew/opt/openssl@3/lib /usr/local/opt/openssl/lib \
109+
&& ln -s /opt/homebrew/opt/openssl@3/include /usr/local/opt/openssl/include
110+
111+
WORKDIR /root/src/cardano-node
112+
113+
RUN bash -c "cabal update"
114+
RUN bash -c "cabal build all"
115+
RUN bash -c "cabal build cardano-cli"
116+
RUN bash -c "cabal build cardano-submit-api"
117+
118+
RUN mkdir -p /root/.local/bin \
119+
&& cp -p "$(./scripts/bin-path.sh cardano-node)" /root/.local/bin/ \
120+
&& cp -p "$(./scripts/bin-path.sh cardano-cli)" /root/.local/bin/ \
121+
&& cp -p "$(./scripts/bin-path.sh cardano-submit-api)" /root/.local/bin/
122+
123+
124+
FROM ubuntu:22.04 AS node-runner
125+
COPY --from=cardano-builder /root/.local/bin/cardano-* /usr/local/bin/

0 commit comments

Comments
 (0)