Skip to content

Commit 156356d

Browse files
Merge pull request #1047 from cardano-foundation/chore/prepare-9.0.2
chore: prepare 9.0.2
2 parents 571f7d8 + 688ed5e commit 156356d

22 files changed

Lines changed: 132 additions & 80 deletions

File tree

.env.docker-compose

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ CARDANO_DB_SYNC_DIR=db-sync-data
3636

3737
## Hasura Variables
3838
HASURA_PORT=8090
39-
CARDANO_GRAPHQL_VERSION=9.0.1
39+
CARDANO_GRAPHQL_VERSION=9.0.2
4040

4141
## Token Registry Variables
4242
TOKEN_REGISTRY_VERSION=1.6.0
@@ -47,8 +47,10 @@ CIP_QUERY_PRIORITY=CIP_68,CIP_26
4747
## Background Variables
4848
LOGGER_MIN_SEVERITY=info
4949
METADATA_SERVER_URI=http://token-metadata-registry:${TOKEN_REGISTRY_PORT}
50+
ASSET_BACKFILL_BATCH_SIZE=500000
5051
## Server Variables
5152
API_PORT=3100
53+
POLLING_INTERVAL_ADA_SUPPLY=21600000
5254

5355
## Index Service Variables (requires 'indexes' in COMPOSE_PROFILES)
5456
# Minimum number of blocks to sync before creating indexes (default: 1000)

.env.docker-compose-preprod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ CARDANO_DB_SYNC_DIR=/opt/graph-ql-preprod/db-sync-data
3636

3737
## Hasura Variables
3838
HASURA_PORT=8091
39-
CARDANO_GRAPHQL_VERSION=9.0.1
39+
CARDANO_GRAPHQL_VERSION=9.0.2
4040

4141
## Token Registry Variables
4242
TOKEN_REGISTRY_VERSION=1.6.0
@@ -46,9 +46,10 @@ CIP_QUERY_PRIORITY=CIP_68,CIP_26
4646
## Background Variables
4747
LOGGER_MIN_SEVERITY=info
4848
METADATA_SERVER_URI=http://token-metadata-registry:${TOKEN_REGISTRY_PORT}
49-
49+
ASSET_BACKFILL_BATCH_SIZE=500000
5050
## Server Variables
5151
API_PORT=3101
52+
POLLING_INTERVAL_ADA_SUPPLY=21600000
5253

5354
## Index Service Variables (requires 'indexes' in COMPOSE_PROFILES)
5455
# Minimum number of blocks to sync before creating indexes (default: 1000)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Check the [releases] for the latest version.
4747
``` console
4848
git clone \
4949
--single-branch \
50-
--branch 9.0.1 \
50+
--branch 9.0.2 \
5151
--recurse-submodules \
5252
https://github.com/cardano-foundation/cardano-graphql.git \
5353
&& cd cardano-graphql

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ services:
172172
- LOGGER_MIN_SEVERITY=${LOGGER_MIN_SEVERITY}
173173
- METADATA_SERVER_URI=${METADATA_SERVER_URI}
174174
- POSTGRES_PORT=${POSTGRES_PORT}
175+
- ASSET_BACKFILL_BATCH_SIZE=${ASSET_BACKFILL_BATCH_SIZE}
175176
restart: on-failure
176177
secrets:
177178
- postgres_db
@@ -198,6 +199,7 @@ services:
198199
- CARDANO_SUBMIT_API_HOST=cardano-submit-api
199200
- LOGGER_MIN_SEVERITY=${LOGGER_MIN_SEVERITY}
200201
- NETWORK=${NETWORK}
202+
- POLLING_INTERVAL_ADA_SUPPLY=${POLLING_INTERVAL_ADA_SUPPLY}
201203
- POSTGRES_PORT=${POSTGRES_PORT}
202204
depends_on:
203205
cardano-submit-api:

dockerfiles/mithril/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash -s -- -y \
1919
build-essential m4 libssl-dev docker.io jq git pkg-config \
2020
&& apt-get clean
2121

22-
RUN git clone https://github.com/input-output-hk/mithril.git \
22+
RUN git clone https://github.com/IntersectMBO/mithril.git \
2323
&& export PATH="$HOME/.cargo/bin:$PATH" \
2424
&& cd mithril \
2525
&& git checkout $MITHRIL_VERSION \

dockerfiles/mithril/entrypoint.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ download_mithril_snapshot() {
66
case $NETWORK in
77
mainnet)
88
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-
ANCILLARY_VERIFICATION_KEY=${ANCILLARY_VERIFICATION_KEY:-$(wget -q -O - https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration/release-mainnet/ancillary.vkey)}
9+
GENESIS_VERIFICATION_KEY=${GENESIS_VERIFICATION_KEY:-$(wget -q -O - https://raw.githubusercontent.com/IntersectMBO/mithril/main/mithril-infra/configuration/release-mainnet/genesis.vkey)}
10+
ANCILLARY_VERIFICATION_KEY=${ANCILLARY_VERIFICATION_KEY:-$(wget -q -O - https://raw.githubusercontent.com/IntersectMBO/mithril/main/mithril-infra/configuration/release-mainnet/ancillary.vkey)}
1111
;;
1212
preprod)
1313
AGGREGATOR_ENDPOINT=${AGGREGATOR_ENDPOINT:-https://aggregator.release-preprod.api.mithril.network/aggregator}
14-
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)}
15-
ANCILLARY_VERIFICATION_KEY=${ANCILLARY_VERIFICATION_KEY:-$(wget -q -O - https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration/release-preprod/ancillary.vkey)}
14+
GENESIS_VERIFICATION_KEY=${GENESIS_VERIFICATION_KEY:-$(wget -q -O - https://raw.githubusercontent.com/IntersectMBO/mithril/main/mithril-infra/configuration/release-preprod/genesis.vkey)}
15+
ANCILLARY_VERIFICATION_KEY=${ANCILLARY_VERIFICATION_KEY:-$(wget -q -O - https://raw.githubusercontent.com/IntersectMBO/mithril/main/mithril-infra/configuration/release-preprod/ancillary.vkey)}
1616
;;
1717
preview)
1818
AGGREGATOR_ENDPOINT=${AGGREGATOR_ENDPOINT:-https://aggregator.pre-release-preview.api.mithril.network/aggregator}
19-
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)}
20-
ANCILLARY_VERIFICATION_KEY=${ANCILLARY_VERIFICATION_KEY:-$(wget -q -O - https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration/pre-release-preview/ancillary.vkey)}
19+
GENESIS_VERIFICATION_KEY=${GENESIS_VERIFICATION_KEY:-$(wget -q -O - https://raw.githubusercontent.com/IntersectMBO/mithril/main/mithril-infra/configuration/pre-release-preview/genesis.vkey)}
20+
ANCILLARY_VERIFICATION_KEY=${ANCILLARY_VERIFICATION_KEY:-$(wget -q -O - https://raw.githubusercontent.com/IntersectMBO/mithril/main/mithril-infra/configuration/pre-release-preview/ancillary.vkey)}
2121
;;
2222
esac
2323
echo "Listing content of /node dir:"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"engines": {
55
"node": ">=14.15.0"
66
},
7-
"version": "9.0.1",
7+
"version": "9.0.2",
88
"private": true,
99
"workspaces": [
1010
"packages/*"

packages/api-cardano-db-hasura/hasura/project/migrations/default/1589369664961_init/up.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CREATE OR REPLACE VIEW "AdaPots" AS
77
epoch_no AS "epochNo",
88
deposits_stake,
99
deposits_drep,
10-
deposits_proposal
10+
deposits_proposal,
1111
fees,
1212
reserves,
1313
rewards,

packages/api-cardano-db-hasura/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cardano-graphql/api-cardano-db-hasura",
3-
"version": "9.0.1",
3+
"version": "9.0.2",
44
"description": "Module for interfacing with the Cardano DB, populated by cardano-db-sync that utilises Hasura for a powerful query interface",
55
"main": "dist/index.js",
66
"typings": "dist/index.d.ts",
@@ -34,7 +34,7 @@
3434
"schema.graphql"
3535
],
3636
"dependencies": {
37-
"@cardano-graphql/util": "9.0.1",
37+
"@cardano-graphql/util": "9.0.2",
3838
"@cardanosolutions/json-bigint": "^1.0.0",
3939
"@emurgo/cip14-js": "^2.0.0",
4040
"@graphql-tools/delegate": "^6.2.4",
@@ -65,7 +65,7 @@
6565
"ts-log": "^2.2.3"
6666
},
6767
"devDependencies": {
68-
"@cardano-graphql/util-dev": "9.0.1",
68+
"@cardano-graphql/util-dev": "9.0.2",
6969
"@graphql-codegen/cli": "^1.21.8",
7070
"@graphql-codegen/typescript": "^1.23.0",
7171
"@graphql-codegen/typescript-graphql-files-modules": "^1.18.1",

packages/api-cardano-db-hasura/src/HasuraBackgroundClient.ts

Lines changed: 67 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import {
1616
const epochInformationNotYetAvailable =
1717
'Epoch information not yet available. This is expected during the initial chain-sync.'
1818

19+
const ASSET_BACKFILL_ADVISORY_LOCK_KEY = 4021991017
20+
const ASSET_BACKFILL_DEFAULT_BATCH_SIZE = 500000
21+
1922
const withHexPrefix = (value: string) =>
2023
`\\x${value !== undefined ? value : ''}`
2124

@@ -388,41 +391,74 @@ export class HasuraBackgroundClient {
388391
}
389392
}
390393

391-
public async backfillMissingAssets (dbConfig: DbConfig): Promise<string[]> {
394+
public async backfillMissingAssets (dbConfig: DbConfig, batchSize: number = ASSET_BACKFILL_DEFAULT_BATCH_SIZE): Promise<string[]> {
392395
const client = new Client(dbConfig)
393396
await client.connect()
394397
try {
395-
await client.query(`
396-
UPDATE "Asset" a
397-
SET fingerprint = ma.fingerprint
398-
FROM multi_asset ma
399-
WHERE a."assetId" = CAST(CONCAT(ma.policy, RIGHT(CONCAT(E'\\\\', ma.name), -3)) AS BYTEA)
400-
AND a.fingerprint IS NULL
401-
`)
402-
const result = await client.query(`
403-
INSERT INTO "Asset" ("assetId", "assetName", "policyId", "fingerprint", "firstAppearedInSlot")
404-
SELECT
405-
CAST(CONCAT(ma.policy, RIGHT(CONCAT(E'\\\\', ma.name), -3)) AS BYTEA),
406-
ma.name,
407-
ma.policy,
408-
ma.fingerprint,
409-
MIN(b.slot_no)
410-
FROM multi_asset ma
411-
JOIN ma_tx_mint mtm ON mtm.ident = ma.id
412-
JOIN tx ON tx.id = mtm.tx_id
413-
JOIN block b ON b.id = tx.block_id
414-
LEFT JOIN "Asset" a
415-
ON a."assetId" = CAST(CONCAT(ma.policy, RIGHT(CONCAT(E'\\\\', ma.name), -3)) AS BYTEA)
416-
WHERE a."assetId" IS NULL
417-
GROUP BY ma.id, ma.policy, ma.name, ma.fingerprint
418-
ON CONFLICT ("assetId") DO NOTHING
419-
RETURNING encode("assetId", 'hex') AS "assetId"
420-
`)
421-
this.logger.info(
422-
{ module: 'HasuraBackgroundClient', inserted: result.rowCount },
423-
'Backfilled missing assets from multi_asset'
398+
const lockResult = await client.query<{ locked: boolean }>(
399+
'SELECT pg_try_advisory_lock($1) AS locked',
400+
[ASSET_BACKFILL_ADVISORY_LOCK_KEY]
424401
)
425-
return result.rows.map((row: { assetId: string }) => row.assetId)
402+
if (!lockResult.rows[0].locked) {
403+
this.logger.warn(
404+
{ module: 'HasuraBackgroundClient' },
405+
'Asset backfill already in progress on another connection, skipping'
406+
)
407+
return []
408+
}
409+
try {
410+
await client.query(`
411+
UPDATE "Asset" a
412+
SET fingerprint = ma.fingerprint
413+
FROM multi_asset ma
414+
WHERE a."assetId" = CAST(CONCAT(ma.policy, RIGHT(CONCAT(E'\\\\', ma.name), -3)) AS BYTEA)
415+
AND a.fingerprint IS NULL
416+
`)
417+
const maxResult = await client.query<{ maxId: string }>(
418+
'SELECT COALESCE(MAX(id), 0) AS "maxId" FROM multi_asset'
419+
)
420+
const maxId = Number(maxResult.rows[0].maxId)
421+
const insertedAssetIds: string[] = []
422+
for (let cur = 0; cur < maxId; cur += batchSize) {
423+
const result = await client.query(`
424+
INSERT INTO "Asset" ("assetId", "assetName", "policyId", "fingerprint", "firstAppearedInSlot")
425+
SELECT
426+
CAST(CONCAT(ma.policy, RIGHT(CONCAT(E'\\\\', ma.name), -3)) AS BYTEA),
427+
ma.name,
428+
ma.policy,
429+
ma.fingerprint,
430+
MIN(b.slot_no)
431+
FROM multi_asset ma
432+
JOIN ma_tx_mint mtm ON mtm.ident = ma.id
433+
JOIN tx ON tx.id = mtm.tx_id
434+
JOIN block b ON b.id = tx.block_id
435+
LEFT JOIN "Asset" a
436+
ON a."assetId" = CAST(CONCAT(ma.policy, RIGHT(CONCAT(E'\\\\', ma.name), -3)) AS BYTEA)
437+
WHERE a."assetId" IS NULL
438+
AND ma.id > $1
439+
AND ma.id <= $2
440+
GROUP BY ma.id, ma.policy, ma.name, ma.fingerprint
441+
ON CONFLICT ("assetId") DO NOTHING
442+
RETURNING encode("assetId", 'hex') AS "assetId"
443+
`, [cur, cur + batchSize])
444+
if (result.rowCount > 0) {
445+
for (const row of result.rows as { assetId: string }[]) {
446+
insertedAssetIds.push(row.assetId)
447+
}
448+
this.logger.info(
449+
{ module: 'HasuraBackgroundClient', upToId: cur + batchSize, inserted: result.rowCount, total: insertedAssetIds.length },
450+
'Backfilled asset batch from multi_asset'
451+
)
452+
}
453+
}
454+
this.logger.info(
455+
{ module: 'HasuraBackgroundClient', inserted: insertedAssetIds.length },
456+
'Backfilled missing assets from multi_asset'
457+
)
458+
return insertedAssetIds
459+
} finally {
460+
await client.query('SELECT pg_advisory_unlock($1)', [ASSET_BACKFILL_ADVISORY_LOCK_KEY])
461+
}
426462
} finally {
427463
await client.end()
428464
}

0 commit comments

Comments
 (0)