Skip to content

Commit

Permalink
refactor: CardanoNodeClient.getTip() to getTipSlotNo()
Browse files Browse the repository at this point in the history
- Replaces cardano-cli with cardano-ogmios server and
@cardano-ogmios/client
- Config is optional as the client package uses default values
- Removes CompleteApiServer, hoisting init into index
- Adds a shutdown method to release the Ogmios client connections
- Adds onDeath handler to gracefully shutdown all modules
- Replaces block number with slot number to determine sync status
  • Loading branch information
rhyslbw committed May 13, 2021
1 parent 05b895a commit 723e763
Show file tree
Hide file tree
Showing 32 changed files with 185 additions and 435 deletions.
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "cardano-node"]
path = cardano-node
url = https://github.com/input-output-hk/cardano-node.git
[submodule "cardano-ogmios"]
path = cardano-ogmios
url = https://github.com/KtorZ/cardano-ogmios
69 changes: 3 additions & 66 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,62 +1,4 @@
ARG UBUNTU_VERSION=20.04
FROM ubuntu:${UBUNTU_VERSION} as haskell-builder
ARG CABAL_VERSION=3.2.0.0
ARG GHC_VERSION=8.10.2
ARG IOHK_LIBSODIUM_GIT_REV=66f017f16633f2060db25e17c170c2afa0f2a8a1
ENV DEBIAN_FRONTEND=nonintercative
RUN mkdir -p /app/src
WORKDIR /app
RUN apt-get update -y && apt-get install -y \
automake=1:1.16.* \
build-essential=12.* \
g++=4:9.3.* \
git=1:2.25.* \
jq \
libffi-dev=3.* \
libghc-postgresql-libpq-dev=0.9.4.* \
libgmp-dev=2:6.2.* \
libncursesw5=6.* \
libpq-dev=12.* \
libssl-dev=1.1.* \
libsystemd-dev=245.* \
libtinfo-dev=6.* \
libtool=2.4.* \
make=4.2.* \
pkg-config=0.29.* \
tmux=3.* \
wget=1.20.* \
zlib1g-dev=1:1.2.*
RUN wget --secure-protocol=TLSv1_2 \
https://downloads.haskell.org/~cabal/cabal-install-${CABAL_VERSION}/cabal-install-${CABAL_VERSION}-x86_64-unknown-linux.tar.xz &&\
tar -xf cabal-install-${CABAL_VERSION}-x86_64-unknown-linux.tar.xz &&\
rm cabal-install-${CABAL_VERSION}-x86_64-unknown-linux.tar.xz cabal.sig &&\
mv cabal /usr/local/bin/
RUN cabal update
WORKDIR /app/ghc
RUN wget --secure-protocol=TLSv1_2 \
https://downloads.haskell.org/~ghc/${GHC_VERSION}/ghc-${GHC_VERSION}-x86_64-deb9-linux.tar.xz &&\
tar -xf ghc-${GHC_VERSION}-x86_64-deb9-linux.tar.xz &&\
rm ghc-${GHC_VERSION}-x86_64-deb9-linux.tar.xz
WORKDIR /app/ghc/ghc-${GHC_VERSION}
RUN ./configure && make install
WORKDIR /app/src
RUN git clone https://github.com/input-output-hk/libsodium.git &&\
cd libsodium &&\
git fetch --all --tags &&\
git checkout ${IOHK_LIBSODIUM_GIT_REV}
WORKDIR /app/src/libsodium
RUN ./autogen.sh && ./configure && make && make install
ENV LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH"
ENV PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH"
WORKDIR /app/src
COPY /cardano-node /app/src/cardano-node
WORKDIR /app/src/cardano-node
RUN cabal install cardano-cli \
--install-method=copy \
--installdir=/usr/local/bin \
-f -systemd
# Cleanup for server copy of /usr/local/lib
RUN rm -rf /usr/local/lib/ghc-${GHC_VERSION} /usr/local/lib/pkgconfig

FROM ubuntu:${UBUNTU_VERSION} as ubuntu-nodejs
ARG NODEJS_MAJOR_VERSION=14
Expand Down Expand Up @@ -100,11 +42,8 @@ FROM nodejs-builder as dev
RUN apt-get update && apt-get install yarn -y
RUN mkdir src
RUN mkdir /node-ipc
COPY --from=haskell-builder /usr/local/lib /usr/local/lib
COPY --from=haskell-builder /usr/local/bin/cardano-cli /usr/local/bin/
COPY --from=downloader /usr/local/bin/hasura /usr/local/bin/hasura
ENV \
CARDANO_CLI_PATH=/usr/local/bin/cardano-cli \
CARDANO_NODE_CONFIG_PATH=/config/cardano-node/config.json \
CARDANO_NODE_SOCKET_PATH=/node-ipc/node.socket \
GENESIS_FILE_BYRON=/config/genesis/byron.json \
Expand All @@ -118,20 +57,17 @@ ENV \
POSTGRES_PORT=5432 \
POSTGRES_USER_FILE=/run/secrets/postgres_user
WORKDIR /src

FROM ubuntu-nodejs as server
ARG NETWORK=mainnet
ARG NETWORK=mainnet
ARG METADATA_SERVER_URI="https://tokens.cardano.org"
RUN curl --proto '=https' --tlsv1.2 -sSf -L https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - &&\
echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list &&\
apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
jq
COPY --from=haskell-builder /usr/local/lib /usr/local/lib
COPY --from=haskell-builder /usr/local/bin/cardano-cli /usr/local/bin/
COPY --from=downloader /usr/local/bin/hasura /usr/local/bin/hasura
ENV \
CARDANO_CLI_PATH=/usr/local/bin/cardano-cli \
CARDANO_NODE_CONFIG_PATH=/config/cardano-node/config.json \
CARDANO_NODE_SOCKET_PATH=/node-ipc/node.socket \
GENESIS_FILE_BYRON=/config/genesis/byron.json \
Expand All @@ -143,6 +79,7 @@ ENV \
LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH" \
METADATA_SERVER_URI=${METADATA_SERVER_URI} \
NETWORK=${NETWORK} \
OGMIOS_HOST="ogmios" \
POSTGRES_DB_FILE=/run/secrets/postgres_db \
POSTGRES_HOST=postgres \
POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password \
Expand Down
1 change: 0 additions & 1 deletion cardano-node
Submodule cardano-node deleted from 9a7331
1 change: 1 addition & 0 deletions cardano-ogmios
Submodule cardano-ogmios added at 6096ae
37 changes: 0 additions & 37 deletions config/ecosystem.config.js

This file was deleted.

92 changes: 0 additions & 92 deletions docker-compose.dev.yml

This file was deleted.

13 changes: 13 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ services:
options:
max-size: "200k"
max-file: "10"
ogmios:
build:
context: cardano-ogmios/server
cache_from:
- ktorz/ogmios:latest
- ktorz/ogmios:3.2.0
image: ktorz/ogmios:3.2.0
restart: on-failure
environment:
- OGMIOS_NETWORK=${NETWORK:-mainnet}
command: [ "--host", "0.0.0.0", "--node-socket", "/ipc/node.socket" ]
volumes:
- node-ipc:/ipc
cardano-graphql:
build:
context: .
Expand Down
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,14 @@
"dev:cleanup": "shx rm -rf ./state ./bin",
"mainnet:stack": "CONTEXT=$PWD NETWORK=mainnet . ./scripts/export_env.sh && docker-compose -p mainnet up --build -d",
"mainnet:up": "yarn mainnet:stack && docker-compose -p mainnet logs -f",
"mainnet:dev-up": "CONTEXT=$PWD NETWORK=mainnet . ./scripts/export_env.sh && pm2-runtime start ./config/ecosystem.config.js",
"mainnet:down": "docker-compose -p mainnet down --remove-orphans",
"mainnet:server": "CONTEXT=$PWD NETWORK=mainnet . ./scripts/export_env.sh && yarn workspace @cardano-graphql/server start",
"testnet:stack": "CONTEXT=$PWD NETWORK=testnet . ./scripts/export_env.sh && docker-compose -p testnet up --build -d",
"testnet:up": "yarn testnet:stack && docker-compose -p testnet logs -f",
"testnet:dev-up": "CONTEXT=$PWD NETWORK=testnet . ./scripts/export_env.sh && pm2-runtime start ./config/ecosystem.config.js",
"testnet:down": "docker-compose -p testnet down --remove-orphans",
"testnet:server": "CONTEXT=$PWD NETWORK=testnet . ./scripts/export_env.sh && yarn workspace @cardano-graphql/server start",
"shelley_qa:stack": "CONTEXT=$PWD NETWORK=shelley_qa . ./scripts/export_env.sh && docker-compose -p shelley_qa up --build -d",
"shelley_qa:up": "yarn shelley_qa:stack && docker-compose -p shelley_qa logs -f",
"shelley_qa:dev-up": "CONTEXT=$PWD NETWORK=shelley_qa . ./scripts/export_env.sh && pm2-runtime start ./config/ecosystem.config.js",
"shelley_qa:down": "docker-compose -p shelley_qa down --remove-orphans",
"shelley_qa:server": "CONTEXT=$PWD NETWORK=shelley_qa . ./scripts/export_env.sh && yarn workspace @cardano-graphql/server start",
"lint": "yarn workspaces run lint",
Expand Down
Binary file added packages-cache/@cardano-ogmios-client-3.2.0.tgz
Binary file not shown.
Binary file added packages-cache/@cardano-ogmios-schema-3.2.0.tgz
Binary file not shown.
Binary file added packages-cache/@types-death-1.1.1.tgz
Binary file not shown.
Binary file added packages-cache/death-1.1.0.tgz
Binary file not shown.
Binary file added packages-cache/isomorphic-ws-4.0.1.tgz
Binary file not shown.
Binary file added packages-cache/nanoid-3.1.22.tgz
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/api-cardano-db-hasura/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
],
"dependencies": {
"@cardano-graphql/util": "4.0.0",
"@cardano-ogmios/client": "^3.2.0",
"@emurgo/cardano-serialization-lib-nodejs": "^6.0.0",
"@emurgo/cip14-js": "^2.0.0",
"@graphql-tools/delegate": "^6.0.10",
Expand All @@ -57,7 +58,6 @@
"pg": "^8.5.1",
"pg-listen": "^1.6.0",
"set-interval-async": "^1.0.33",
"temp-write": "^4.0.0",
"ts-custom-error": "^3.2.0",
"ts-log": "^2.2.3"
},
Expand Down
85 changes: 0 additions & 85 deletions packages/api-cardano-db-hasura/src/CardanoCli.ts

This file was deleted.

Loading

0 comments on commit 723e763

Please sign in to comment.