Skip to content

Commit

Permalink
feature: add AlonzoGenesis
Browse files Browse the repository at this point in the history
Includes a refactor to depreciate `{NETWORK}_GENESIS_FILE_PATH` config, as
we can read the paths from the node config file. Not a breaking change as continued
use will have no detrimental effect.
  • Loading branch information
rhyslbw committed Aug 11, 2021
1 parent 426ee20 commit d600dc0
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 38 deletions.
4 changes: 0 additions & 4 deletions Dockerfile
Expand Up @@ -46,8 +46,6 @@ COPY --from=downloader /usr/local/bin/hasura /usr/local/bin/hasura
ENV \
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 \
HASURA_CLI_PATH=/usr/local/bin/hasura \
HASURA_URI="http://hasura:8080" \
LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH" \
Expand All @@ -68,8 +66,6 @@ RUN curl --proto '=https' --tlsv1.2 -sSf -L https://www.postgresql.org/media/key
COPY --from=downloader /usr/local/bin/hasura /usr/local/bin/hasura
ENV \
CARDANO_NODE_CONFIG_PATH=/config/cardano-node/config.json \
GENESIS_FILE_BYRON=/config/genesis/byron.json \
GENESIS_FILE_SHELLEY=/config/genesis/shelley.json \
HASURA_CLI_PATH=/usr/local/bin/hasura \
HASURA_GRAPHQL_ENABLE_TELEMETRY=false \
HASURA_URI="http://hasura:8080" \
Expand Down
12 changes: 0 additions & 12 deletions nix/nixos/cardano-graphql-service.nix
Expand Up @@ -58,16 +58,6 @@ in {
default = null;
};

genesisByron = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
};

genesisShelley = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
};

hasuraIp = lib.mkOption {
type = lib.types.str;
default = "127.0.0.1";
Expand Down Expand Up @@ -156,8 +146,6 @@ in {
requires = [ "graphql-engine.service" ];
environment = lib.filterAttrs (k: v: v != null) {
CARDANO_NODE_CONFIG_PATH = cfg.cardanoNodeConfigPath;
GENESIS_FILE_BYRON = cfg.genesisByron;
GENESIS_FILE_SHELLEY = cfg.genesisShelley;
HASURA_CLI_PATH = hasura-cli + "/bin/hasura";
HASURA_GRAPHQL_ENABLE_TELEMETRY = toString false;
HASURA_URI = hasuraBaseUri;
Expand Down
26 changes: 26 additions & 0 deletions packages/api-cardano-db-hasura/schema.graphql
Expand Up @@ -303,6 +303,31 @@ type AdaPots {
utxo: String!
}

type AlonzoGenesis {
lovelacePerUTxOWord: Int!
executionPrices: ExecutionPrices!
maxTxExUnits: ExecutionUnits!
maxBlockExUnits: ExecutionUnits!
maxValueSize: Int!
collateralPercentage: Int!
maxCollateralInputs: Int!
}

type ExecutionPrices {
prSteps: ExecutionPrice!
prMem: ExecutionPrice!
}

type ExecutionPrice {
numerator: Int!
denominator: Int!
}

type ExecutionUnits {
exUnitsMem: BigInt!
exUnitsSteps: BigInt!
}

type Asset {
assetId: Hex!
assetName: Hex
Expand Down Expand Up @@ -477,6 +502,7 @@ type Delegation_aggregate_fields {
}

type Genesis {
alonzo: AlonzoGenesis
byron: ByronGenesis
shelley: ShelleyGenesis
}
Expand Down
4 changes: 0 additions & 4 deletions packages/api-cardano-db-hasura/src/Config.ts
Expand Up @@ -8,10 +8,6 @@ export interface Config {
port: number
user: string,
},
genesis: {
byronPath: string,
shelleyPath: string
},
hasuraCliPath: string,
hasuraUri: string,
metadataServerUri: string,
Expand Down
@@ -1,5 +1,29 @@
query keyNetworkInfo {
genesis {
alonzo {
lovelacePerUTxOWord
executionPrices {
prMem {
denominator
numerator
}
prSteps {
denominator
numerator
}
}
maxTxExUnits {
exUnitsMem
exUnitsSteps
}
maxBlockExUnits {
exUnitsMem
exUnitsSteps
}
maxValueSize
collateralPercentage
maxCollateralInputs
}
byron {
blockVersionData {
scriptVersion
Expand Down
Expand Up @@ -3,6 +3,30 @@
exports[`genesis Returns key information about the network genesis 1`] = `
Object {
"genesis": Object {
"alonzo": Object {
"collateralPercentage": 150,
"executionPrices": Object {
"prMem": Object {
"denominator": 1000,
"numerator": 5,
},
"prSteps": Object {
"denominator": 100,
"numerator": 1,
},
},
"lovelacePerUTxOWord": 34482,
"maxBlockExUnits": Object {
"exUnitsMem": 40000000000,
"exUnitsSteps": 40000000000,
},
"maxCollateralInputs": 3,
"maxTxExUnits": Object {
"exUnitsMem": 10000000000,
"exUnitsSteps": 10000000000,
},
"maxValueSize": 5000,
},
"byron": Object {
"blockVersionData": Object {
"maxBlockSize": 2000000,
Expand Down
9 changes: 0 additions & 9 deletions packages/server/src/config.ts
Expand Up @@ -20,9 +20,6 @@ export async function getConfig (): Promise<Config> {
if (!env.hasuraUri) {
throw new MissingConfig('HASURA_URI env not set')
}
if (!env.genesis.shelleyPath) {
throw new MissingConfig('GENESIS_FILE_SHELLEY env not set')
}
if (!env.postgres.dbFile && !env.postgres.db) {
throw new MissingConfig('POSTGRES_DB_FILE or POSTGRES_DB env not set')
}
Expand Down Expand Up @@ -79,8 +76,6 @@ function filterAndTypecastEnvs (env: any) {
ASSET_METADATA_UPDATE_INTERVAL,
CACHE_ENABLED,
CARDANO_NODE_CONFIG_PATH,
GENESIS_FILE_BYRON,
GENESIS_FILE_SHELLEY,
HASURA_CLI_PATH,
HASURA_URI,
LISTEN_ADDRESS,
Expand Down Expand Up @@ -109,10 +104,6 @@ function filterAndTypecastEnvs (env: any) {
apiPort: Number(API_PORT),
cacheEnabled: CACHE_ENABLED === 'true',
cardanoNodeConfigPath: CARDANO_NODE_CONFIG_PATH,
genesis: {
byronPath: GENESIS_FILE_BYRON,
shelleyPath: GENESIS_FILE_SHELLEY
},
hasuraCliPath: HASURA_CLI_PATH,
hasuraUri: HASURA_URI,
listenAddress: LISTEN_ADDRESS,
Expand Down
24 changes: 17 additions & 7 deletions packages/server/src/index.ts
Expand Up @@ -2,18 +2,21 @@ import { createLogger } from 'bunyan'
import { Point } from '@cardano-ogmios/schema'
import { getConfig } from './config'
import {
AlonzoGenesis,
buildSchema as buildCardanoDbHasuraSchema,
ByronGenesis,
CardanoNodeClient,
ChainFollower,
Db,
Genesis,
HasuraClient,
MetadataClient,
MetadataClient, ShelleyGenesis,
Worker
} from '@cardano-graphql/api-cardano-db-hasura'
import { errors } from '@cardano-graphql/util'
import onDeath from 'death'
import { GraphQLSchema } from 'graphql'
import path from 'path'
import { Logger } from 'ts-log'
import { Server } from './Server'

Expand All @@ -26,13 +29,20 @@ export * from './config'
level: config.loggerMinSeverity
})
try {
const loadGenesis = (eraName: string) =>
require(
path.resolve(
path.dirname(config.cardanoNodeConfigPath),
cardanoNodeConfig[`${eraName}GenesisFile`]
)
)

const schemas: GraphQLSchema[] = []
let genesis: Genesis
if (config.genesis.byronPath !== undefined || config.genesis.shelleyPath !== undefined) {
genesis = {
...config.genesis.byronPath !== undefined ? { byron: require(config.genesis.byronPath) } : {},
...config.genesis.shelleyPath !== undefined ? { shelley: require(config.genesis.shelleyPath) } : {}
}
const cardanoNodeConfig = require(config.cardanoNodeConfigPath)
const genesis: Genesis = {
alonzo: loadGenesis('Alonzo') as AlonzoGenesis,
byron: loadGenesis('Byron') as ByronGenesis,
shelley: loadGenesis('Shelley') as ShelleyGenesis
}
const lastConfiguredMajorVersion = require(config.cardanoNodeConfigPath)['LastKnownBlockVersion-Major']

Expand Down
2 changes: 0 additions & 2 deletions scripts/export_env.sh
Expand Up @@ -47,8 +47,6 @@ export API_PORT
export CARDANO_NODE_CONFIG_PATH=${CONFIG_DIR}/cardano-node/config.json
export COMPOSE_DOCKER_CLI_BUILD=1
export DOCKER_BUILDKIT=1
export GENESIS_FILE_BYRON=${CONFIG_DIR}/genesis/byron.json
export GENESIS_FILE_SHELLEY=${CONFIG_DIR}/genesis/shelley.json
export HASURA_CLI_PATH=${BIN_DIR}/hasura
export HASURA_PORT
export HASURA_URI=http://localhost:${HASURA_PORT}
Expand Down

0 comments on commit d600dc0

Please sign in to comment.