Skip to content

Commit

Permalink
Revert "Fix/non nullable field in token asset (#905)"
Browse files Browse the repository at this point in the history
This reverts commit 540b3aa.
  • Loading branch information
Kammerlo authored Nov 29, 2024
1 parent 540b3aa commit 4d60fa3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
17 changes: 5 additions & 12 deletions packages/api-cardano-db-hasura/src/ChainFollower.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import util, { assetFingerprint, errors, RunnableModuleState } from '@cardano-gr
import PgBoss from 'pg-boss'
import { dummyLogger, Logger } from 'ts-log'
import { createInteractionContextWithLogger } from './util'
import { PointOrOrigin, BlockPraos, BlockBFT, Tip, Origin } from '@cardano-ogmios/schema'
import { PointOrOrigin, BlockPraos, BlockBFT } from '@cardano-ogmios/schema'
import { HasuraBackgroundClient } from './HasuraBackgroundClient'
import { DbConfig } from './typeAliases'
import { ChainSynchronizationClient } from '@cardano-ogmios/client/dist/ChainSynchronization'
Expand Down Expand Up @@ -40,7 +40,6 @@ export class ChainFollower {
application_name: 'cardano-graphql',
...this.queueConfig
})
this.logger.info({ module: MODULE_NAME }, 'Connecting to queue')
await pRetry(async () => {
const context = await createInteractionContextWithLogger(ogmiosConfig, this.logger, MODULE_NAME, async () => {
await this.shutdown()
Expand All @@ -64,7 +63,7 @@ export class ChainFollower {
}
requestNext()
},
rollForward: async ({ block, tip }, requestNext) => {
rollForward: async ({ block }, requestNext) => {
try {
let b
switch (block.type) {
Expand All @@ -84,7 +83,7 @@ export class ChainFollower {
const policyId = entry[0]
const assetNames = Object.keys(entry[1])
for (const assetName of assetNames) {
await this.saveAsset(policyId, assetName, b, tip)
await this.saveAsset(policyId, assetName, b)
}
}
}
Expand All @@ -110,7 +109,7 @@ export class ChainFollower {
this.logger.info({ module: MODULE_NAME }, 'Initialized')
}

async saveAsset (policyId: string, assetName: string | undefined, b: BlockPraos | BlockBFT, tip: Tip | Origin) {
async saveAsset (policyId: string, assetName: string | undefined, b: BlockPraos | BlockBFT) {
const assetId = `${policyId}${assetName !== undefined ? assetName : ''}`
const asset = {
assetId,
Expand All @@ -122,13 +121,7 @@ export class ChainFollower {
// introducing a caching to speed things up. The GraphQL insertAssets takes a lot of time.
// Saving when > 1000 assets in the cache or every minute
this.cacheAssets.push(asset)
let isTip = false
try {
isTip = (tip as Tip).slot === b.slot
} catch (e) {
this.logger.debug({ module: MODULE_NAME }, 'Sync is not at tip. Using a cache to save Assets every minute to increase catching up speed.')
}
if (isTip || this.cacheAssets.length > 1000 || (Date.now() - this.cacheTimer) / 1000 > 60) {
if (this.cacheAssets.length > 1000 || (Date.now() - this.cacheTimer) / 1000 > 60) {
this.cacheTimer = Date.now() // resetting the timer
const response = await this.hasuraClient.insertAssets(this.cacheAssets)
this.cacheAssets = []
Expand Down
15 changes: 14 additions & 1 deletion packages/api-cardano-db-hasura/src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CustomError } from 'ts-custom-error'
import fs from 'fs-extra'
import { DbConfig } from './typeAliases'
import { PointOrOrigin } from '@cardano-ogmios/schema'
import { Schema } from '@cardano-ogmios/client'
// Todo: Hoist to util package next major version
export class MissingConfig extends CustomError {
public constructor (message: string) {
Expand Down Expand Up @@ -177,8 +178,20 @@ function filterAndTypecastEnvs (env: any) {
)
const db = new Db(config.db, logger)
const getChainSyncPoints = async (): Promise<PointOrOrigin[]> => {
const chainSyncPoint = (config.chainfollower) as Schema.Point
logger.info(chainSyncPoint)
const mostRecentPoint = await hasuraBackgroundClient.getMostRecentPointWithNewAsset()
return mostRecentPoint !== null ? [mostRecentPoint, 'origin'] : ['origin']
if (mostRecentPoint !== null) {
if (chainSyncPoint.slot && chainSyncPoint.slot > mostRecentPoint.slot) {
return [chainSyncPoint, 'origin']
} else {
return [mostRecentPoint, 'origin']
}
} else if (chainSyncPoint.slot && chainSyncPoint.id) {
return [chainSyncPoint, 'origin']
} else {
return ['origin']
}
}
await db.init({
onDbInit: () => hasuraBackgroundClient.shutdown(),
Expand Down

0 comments on commit 4d60fa3

Please sign in to comment.