Skip to content

Commit

Permalink
fix: use cardano-node config for lastConfiguredMajorVersion
Browse files Browse the repository at this point in the history
Last configured version was intended to be sourced from the
cardano-node config, yet it's currently coming from genesis.

Fixes #454
  • Loading branch information
rhyslbw committed Mar 18, 2021
1 parent 804d02b commit 5a621c2
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ 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 \
GENESIS_FILE_SHELLEY=/config/genesis/shelley.json \
Expand All @@ -131,6 +132,7 @@ 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 \
GENESIS_FILE_SHELLEY=/config/genesis/shelley.json \
Expand Down
7 changes: 6 additions & 1 deletion nix/nixos/cardano-graphql-service.nix
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ in {
default = 3100;
};

# Used if you tx submission is allowed
cardanoNodeConfigPath = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
};

cardanoNodeSocketPath = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
Expand Down Expand Up @@ -152,6 +156,7 @@ in {
requires = [ "graphql-engine.service" ];
environment = lib.filterAttrs (k: v: v != null) {
CARDANO_CLI_PATH = cfg.cardanoCliPackage + "/bin/cardano-cli";
CARDANO_NODE_CONFIG_PATH = cfg.cardanoNodeConfigPath;
CARDANO_NODE_SOCKET_PATH = cfg.cardanoNodeSocketPath;
GENESIS_FILE_BYRON = cfg.genesisByron;
GENESIS_FILE_SHELLEY = cfg.genesisShelley;
Expand Down
1 change: 1 addition & 0 deletions packages/api-cardano-db-hasura/src/Config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

export interface Config {
cardanoCliPath: string,
cardanoNodeConfigPath: string,
cardanoNodeSocketPath: string,
db: {
database: string,
Expand Down
5 changes: 4 additions & 1 deletion packages/server/src/CompleteApiServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,20 @@ export async function CompleteApiServer (
...config.genesis.shelleyPath !== undefined ? { shelley: require(config.genesis.shelleyPath) } : {}
}
}
const lastConfiguredMajorVersion = require(config.cardanoNodeConfigPath)['LastKnownBlockVersion-Major']

if (config.cardanoCliPath !== undefined) {
cardanoNodeClient = new CardanoNodeClient(
createCardanoCli(config.cardanoCliPath, genesis.shelley, config.jqPath),
genesis.shelley.protocolParams.protocolVersion.major,
lastConfiguredMajorVersion,
logger
)
}
const hasuraClient = new HasuraClient(
config.hasuraCliPath,
config.hasuraUri,
config.pollingInterval.adaSupply,
lastConfiguredMajorVersion,
logger
)
const db = new Db(config.db, logger)
Expand Down
5 changes: 5 additions & 0 deletions packages/server/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export async function getConfig (): Promise<Config> {
if (!env.cardanoNodeSocketPath) {
throw new MissingConfig('CARDANO_NODE_SOCKET_PATH env not set')
}
if (!env.cardanoNodeConfigPath) {
throw new MissingConfig('CARDANO_NODE_CONFIG_PATH env not set')
}
if (!env.hasuraCliPath) {
throw new MissingConfig('HASURA_CLI_PATH env not set')
}
Expand Down Expand Up @@ -82,6 +85,7 @@ function filterAndTypecastEnvs (env: any) {
API_PORT,
CACHE_ENABLED,
CARDANO_CLI_PATH,
CARDANO_NODE_CONFIG_PATH,
CARDANO_NODE_SOCKET_PATH,
GENESIS_FILE_BYRON,
GENESIS_FILE_SHELLEY,
Expand Down Expand Up @@ -113,6 +117,7 @@ function filterAndTypecastEnvs (env: any) {
apiPort: Number(API_PORT),
cacheEnabled: CACHE_ENABLED === 'true',
cardanoCliPath: CARDANO_CLI_PATH,
cardanoNodeConfigPath: CARDANO_NODE_CONFIG_PATH,
cardanoNodeSocketPath: CARDANO_NODE_SOCKET_PATH,
genesis: {
byronPath: GENESIS_FILE_BYRON,
Expand Down
1 change: 1 addition & 0 deletions scripts/export_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ esac
export ALLOW_INTROSPECTION=true
export API_PORT
export CARDANO_CLI_PATH=${BIN_DIR}/cardano-cli
export CARDANO_NODE_CONFIG_PATH=${CONFIG_DIR}/cardano-node/config.json
export CARDANO_NODE_SOCKET_PATH=${STATE_DIR}/node-ipc/node.socket
export GENESIS_FILE_BYRON=${CONFIG_DIR}/genesis/byron.json
export GENESIS_FILE_SHELLEY=${CONFIG_DIR}/genesis/shelley.json
Expand Down

0 comments on commit 5a621c2

Please sign in to comment.