IntersectMBO / cardano-db-sync

A component that follows the Cardano chain and stores blocks and transactions in PostgreSQL
Apache License 2.0
290 stars 160 forks source link

Private network configuration setup #954

Closed harmangakhal closed 2 years ago

harmangakhal commented 2 years ago

I used a modified version of https://github.com/input-output-hk/cardano-node/blob/master/scripts/byron-to-alonzo/mkfiles.sh to generate a private network configuration ./scripts/byron-to-alonzo/mkfiles.sh alonzo

Modifications:

# added --start-time otherwise cardano-db-sync-extended did not start because of mismatch starttime between byron/shelley genesis.json
cardano-cli genesis create \
    --testnet-magic 42 \
    --genesis-dir shelley/ \
    --gen-genesis-keys ${NUM_BFT_NODES} \
    --gen-utxo-keys 1 \
    --start-time $(${DATE} -d @$START_TIME -u +"%Y-%m-%dT%H:%M:%SZ")
# added properties otherwise cardano-db-sync-extended did not start
echo "NetworkName: testnet" >> ${ROOT}/configuration.yaml
echo "NodeConfigFile: configuration.yaml" >> ${ROOT}/configuration.yaml
echo "ByronGenesisHash: $(cardano-cli byron genesis print-genesis-hash --genesis-json ${ROOT}/byron/genesis.json)" >> ${ROOT}/configuration.yaml
echo "ShelleyGenesisHash: $(cardano-cli genesis hash --genesis ${ROOT}/shelley/genesis.json)" >> ${ROOT}/configuration.yaml
echo "AlonzoGenesisHash: $(cardano-cli genesis hash --genesis ${ROOT}/shelley/genesis.alonzo.json)" >> ${ROOT}/configuration.yaml

I'm currently using a modified version of https://github.com/input-output-hk/cardano-graphql/blob/master/docker-compose.yml to get the cardano-graphql stack up and running,

version: "3.5"

services:
  postgres:
    image: postgres:11.5-alpine
    environment:
      - POSTGRES_LOGGING=true
      - POSTGRES_DB_FILE=/run/secrets/postgres_db
      - POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password
      - POSTGRES_USER_FILE=/run/secrets/postgres_user
    ports:
      - ${POSTGRES_PORT:-5432}:5432
    secrets:
      - postgres_db
      - postgres_password
      - postgres_user
    shm_size: '2gb'
    volumes:
      - postgres-data:/var/lib/postgresql/data
    restart: on-failure
    logging:
      driver: "json-file"
      options:
        max-size: "200k"
        max-file: "10"

  cardano-ogmios:
    command: [
      "--host", "0.0.0.0",
      "--node-socket", "/ipc/node.socket",
      "--node-config", "/config/configuration.yaml"
    ]
    image: cardanosolutions/ogmios:v4.1.0
    logging:
      driver: "json-file"
      options:
        max-size: "400k"
        max-file: "20"
    ports:
      - ${OGMIOS_PORT:-1337}:1337
    restart: on-failure
    volumes:
      - node-db:/db
      - node-ipc:/ipc
      - ./config:/config

  cardano-db-sync-extended:
    image: inputoutput/cardano-db-sync:master
    command: [
      "--config", "/config/configuration.yaml",
      "--socket-path", "/node-ipc/node.socket"
    ]
    environment:
      - EXTENDED=true
      - POSTGRES_HOST=postgres
      - POSTGRES_PORT=5432
      - RESTORE_SNAPSHOT=${RESTORE_SNAPSHOT:-}
      - RESTORE_RECREATE_DB=N
    secrets:
      - postgres_password
      - postgres_user
      - postgres_db
    volumes:
      - ./config:/config
      - db-sync-data:/var/lib/cdbsync
      - node-ipc:/node-ipc
    restart: on-failure
    logging:
      driver: "json-file"
      options:
        max-size: "200k"
        max-file: "10"

  hasura:
    image: inputoutput/cardano-graphql-hasura:6.0.0
    ports:
      - ${HASURA_PORT:-8090}:8080
    depends_on:
      - "postgres"
    restart: on-failure
    environment:
      - HASURA_GRAPHQL_ENABLE_CONSOLE=true
      - HASURA_GRAPHQL_CORS_DOMAIN=http://localhost:9695
    secrets:
      - postgres_db
      - postgres_password
      - postgres_user
    logging:
      driver: "json-file"
      options:
        max-size: "200k"
        max-file: "10"

  cardano-graphql:
    image: inputoutput/cardano-graphql:master
    environment:
#      - CARDANO_NODE_CONFIG_PATH=
      - HASURA_URI=http://hasura:8080
      - OGMIOS_HOST=cardano-ogmios
      - OGMIOS_PORT=1337
      - POSTGRES_HOST=postgres
      - POSTGRES_PORT=5432
      - POSTGRES_DB_FILE=/run/secrets/postgres_db
      - POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password
      - POSTGRES_USER_FILE=/run/secrets/postgres_user
      - ALLOW_INTROSPECTION=true
      - CACHE_ENABLED=true
      - LOGGER_MIN_SEVERITY=${LOGGER_MIN_SEVERITY:-debug}
    ports:
      - ${API_PORT:-11032}:3100
    restart: on-failure
    secrets:
      - postgres_db
      - postgres_password
      - postgres_user
    logging:
      driver: "json-file"
      options:
        max-size: "200k"
        max-file: "10"

  cardano-node:
    environment:
      - CARDANO_NODE_SOCKET_PATH=/ipc/node.socket # cardano-cli query tip --testnet-magic 42
    entrypoint: [
        "cardano-node",
        "run",
        "--config", "/config/configuration.yaml",
        "--topology", "/config/node-bft1/topology.json",
        "--database-path", "/data/db",
        "--socket-path", "/ipc/node.socket",
        "--shelley-kes-key", "/config/node-bft1/shelley/kes.skey",
        "--shelley-vrf-key", "/config/node-bft1/shelley/vrf.skey",
        "--shelley-operational-certificate", "/config/node-bft1/shelley/node.cert",
        "--port", "3001",
        "--delegation-certificate", "/config/node-bft1/byron/delegate.cert",
        "--signing-key", "/config/node-bft1/byron/delegate.key",
    ]
    image: inputoutput/cardano-node:1.31.0
    volumes:
      - ./config:/config
      - node-db:/data/db
      - node-ipc:/ipc
    logging:
      driver: "json-file"
      options:
        max-size: "200k"
        max-file: "10"

secrets:
  postgres_db:
    file: ./placeholder-secrets/postgres_db
  postgres_password:
    file: ./placeholder-secrets/postgres_password
  postgres_user:
    file: ./placeholder-secrets/postgres_user
volumes:
  db-sync-data:
  node-db:
  node-ipc:
  postgres-data:

Questions: If I take the node down for a short period of time and then try to restart it docker-compose up cardano-node,

cardano-node_1              | [2acee18d:cardano.node.LeadershipCheck:Info:34] [2021-10-29 22:28:58.80 UTC] {"kind":"TraceStartLeadershipCheck","chainDensity":3.3210333e-2,"slot":48698,"delegMapSize":0,"utxoSize":3,"credentials":"Cardano"}
cardano-node_1              | [2acee18d:cardano.node.Forge:Debug:34] [2021-10-29 22:28:58.80 UTC] fromList [("val",Object (fromList [("current slot",Number 48698.0),("kind",String "TraceBlockContext"),("tip",String "f0d1a1de948add5f77782f466c8ed2630ab201c7d7778b731c7ce9066d0386b4@46728"),("tipBlockNo",Number 1682.0)])),("credentials",String "Cardano")]
cardano-node_1              | [2acee18d:cardano.node.Forge:Debug:34] [2021-10-29 22:28:58.80 UTC] fromList [("val",Object (fromList [("kind",String "TraceLedgerState"),("slot",Number 48698.0)])),("credentials",String "Cardano")]
cardano-node_1              | [2acee18d:cardano.node.Forge:Error:34] [2021-10-29 22:28:58.80 UTC] fromList [("val",Object (fromList [("kind",String "TraceNoLedgerView"),("slot",Number 48698.0)])),("credentials",String "Cardano")]

it seems to stop working with the above error, why is that and can this be avoided?

cardano-graphql doesn't seem to start and I suspect it's because the sync is not working properly as noted by, Error: insertShelleyBlock(Alonzo)block hash 43617264616e6f2e446253796e632e4572612e5368656c6c65792e47656e657269632e426c6f636b2e626c6f636b5072657648617368, is this workflow possible? If so, what might be going wrong here?

cardano-db-sync-extended_1  | [db-sync-node.ChainSync:Debug:1786] [2021-10-29 22:25:24.50 UTC] fromList [("kind",String "Recv"),("msg",Object (fromList [("agency",String "ServerAgency TokNext TokCanAwait"),("kind",String "MsgRollForward")]))]
cardano-db-sync-extended_1  | [db-sync-node.Mux:Debug:1778] [2021-10-29 22:25:24.50 UTC] Bearer on ConnectionId {localAddress = LocalAddress "", remoteAddress = LocalAddress "/ipc/node.socket"} event: Bearer Receive End: length 8
cardano-db-sync-extended_1  | [db-sync-node.Mux:Debug:1778] [2021-10-29 22:25:24.50 UTC] Bearer on ConnectionId {localAddress = LocalAddress "", remoteAddress = LocalAddress "/ipc/node.socket"} event: Bearer Receive Header End: ts: 0xd515497e (MiniProtocolNum 5) ResponderDir len 12288
cardano-db-sync-extended_1  | [db-sync-node.Mux:Debug:1778] [2021-10-29 22:25:24.50 UTC] Bearer on ConnectionId {localAddress = LocalAddress "", remoteAddress = LocalAddress "/ipc/node.socket"} event: Bearer Receive Start: length 12288
cardano-db-sync-extended_1  | [db-sync-node.Mux:Debug:1778] [2021-10-29 22:25:24.50 UTC] Bearer on ConnectionId {localAddress = LocalAddress "", remoteAddress = LocalAddress "/ipc/node.socket"} event: Bearer Receive End: length 12288
cardano-db-sync-extended_1  | [db-sync-node.Mux:Debug:1778] [2021-10-29 22:25:24.50 UTC] Bearer on ConnectionId {localAddress = LocalAddress "", remoteAddress = LocalAddress "/ipc/node.socket"} event: Bearer Receive Header Start
cardano-db-sync-extended_1  | [db-sync-node.Mux:Debug:1778] [2021-10-29 22:25:24.50 UTC] Bearer on ConnectionId {localAddress = LocalAddress "", remoteAddress = LocalAddress "/ipc/node.socket"} event: Bearer Receive Start: length 8
cardano-db-sync-extended_1  | [db-sync-node.Mux:Debug:1778] [2021-10-29 22:25:24.50 UTC] Bearer on ConnectionId {localAddress = LocalAddress "", remoteAddress = LocalAddress "/ipc/node.socket"} event: Bearer Receive End: length 8
cardano-db-sync-extended_1  | [db-sync-node.ChainSync:Debug:1786] [2021-10-29 22:25:24.50 UTC] fromList [("kind",String "Recv"),("msg",Object (fromList [("agency",String "ServerAgency TokNext TokCanAwait"),("kind",String "MsgRollForward")]))]
cardano-db-sync-extended_1  | [db-sync-node.ChainSync:Debug:1786] [2021-10-29 22:25:24.50 UTC] fromList [("kind",String "Recv"),("msg",Object (fromList [("agency",String "ServerAgency TokNext TokCanAwait"),("kind",String "MsgRollForward")]))]
cardano-db-sync-extended_1  | [db-sync-node:Error:1784] [2021-10-29 22:25:24.50 UTC] Error: insertShelleyBlock(Alonzo)block hash 43617264616e6f2e446253796e632e4572612e5368656c6c65792e47656e657269632e426c6f636b2e626c6f636b5072657648617368
cardano-db-sync-extended_1  | [db-sync-node:Info:1784] [2021-10-29 22:25:24.50 UTC] Shutting down DB thread
rhyslbw commented 2 years ago

This is really out of context for this repo, so I'll transfer for more support. I would suggest omitting all of the cardano-graphql services to ensure cardano-node + cardano-db-sync + postgres is working as expected, then add back in the GraphQL services.

harmangakhal commented 2 years ago
  1. Resolved by remove containers/volumes and updating startTime / systemStart in genesis json files before restarting.
  2. Resolved in https://github.com/input-output-hk/cardano-db-sync/issues/953