From 2f317d803ec5b16b2cbeaadfd6abe5479262b8a7 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 20 Aug 2024 11:42:03 +0500 Subject: [PATCH 01/10] Add `createdAt` field to schemas --- schema.graphql | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/schema.graphql b/schema.graphql index bccc250..8da235f 100644 --- a/schema.graphql +++ b/schema.graphql @@ -12,6 +12,8 @@ type Account @entity { type DdcCluster @entity { id: ID! + createdAt: Int! + managerId: Account! @index treasuryShare: BigInt! @@ -41,6 +43,8 @@ enum DdcClusterStatus { type DdcNode @entity { id: ID! + createdAt: Int! + providerId: Account! @index clusterId: DdcCluster @@ -65,6 +69,8 @@ enum DdcNodeMode { type DdcBucket @entity { id: ID! + createdAt: Int! + ownerId: Account! @index clusterId: DdcCluster! @index From 79cc43d1526a7bf1517b99f1f8d92965d12114f5 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 20 Aug 2024 11:42:49 +0500 Subject: [PATCH 02/10] sqd codegen --- src/model/generated/ddcBucket.model.ts | 5 ++++- src/model/generated/ddcCluster.model.ts | 5 ++++- src/model/generated/ddcNode.model.ts | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/model/generated/ddcBucket.model.ts b/src/model/generated/ddcBucket.model.ts index c711714..a51a599 100644 --- a/src/model/generated/ddcBucket.model.ts +++ b/src/model/generated/ddcBucket.model.ts @@ -1,4 +1,4 @@ -import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_, ManyToOne as ManyToOne_, Index as Index_, BooleanColumn as BooleanColumn_, BigIntColumn as BigIntColumn_} from "@subsquid/typeorm-store" +import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_, IntColumn as IntColumn_, ManyToOne as ManyToOne_, Index as Index_, BooleanColumn as BooleanColumn_, BigIntColumn as BigIntColumn_} from "@subsquid/typeorm-store" import {Account} from "./account.model" import {DdcCluster} from "./ddcCluster.model" @@ -11,6 +11,9 @@ export class DdcBucket { @PrimaryColumn_() id!: string + @IntColumn_({nullable: false}) + createdAt!: number + @Index_() @ManyToOne_(() => Account, {nullable: true}) ownerId!: Account diff --git a/src/model/generated/ddcCluster.model.ts b/src/model/generated/ddcCluster.model.ts index e4c657c..2274c24 100644 --- a/src/model/generated/ddcCluster.model.ts +++ b/src/model/generated/ddcCluster.model.ts @@ -1,4 +1,4 @@ -import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_, ManyToOne as ManyToOne_, Index as Index_, BigIntColumn as BigIntColumn_, IntColumn as IntColumn_, OneToMany as OneToMany_} from "@subsquid/typeorm-store" +import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_, IntColumn as IntColumn_, ManyToOne as ManyToOne_, Index as Index_, BigIntColumn as BigIntColumn_, OneToMany as OneToMany_} from "@subsquid/typeorm-store" import {Account} from "./account.model" import {DdcClusterStatus} from "./_ddcClusterStatus" import {DdcBucket} from "./ddcBucket.model" @@ -13,6 +13,9 @@ export class DdcCluster { @PrimaryColumn_() id!: string + @IntColumn_({nullable: false}) + createdAt!: number + @Index_() @ManyToOne_(() => Account, {nullable: true}) managerId!: Account diff --git a/src/model/generated/ddcNode.model.ts b/src/model/generated/ddcNode.model.ts index 436c4eb..89b5fda 100644 --- a/src/model/generated/ddcNode.model.ts +++ b/src/model/generated/ddcNode.model.ts @@ -1,4 +1,4 @@ -import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_, ManyToOne as ManyToOne_, Index as Index_, StringColumn as StringColumn_, BooleanColumn as BooleanColumn_, IntColumn as IntColumn_, BigIntColumn as BigIntColumn_} from "@subsquid/typeorm-store" +import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_, IntColumn as IntColumn_, ManyToOne as ManyToOne_, Index as Index_, StringColumn as StringColumn_, BooleanColumn as BooleanColumn_, BigIntColumn as BigIntColumn_} from "@subsquid/typeorm-store" import {Account} from "./account.model" import {DdcCluster} from "./ddcCluster.model" import {DdcNodeMode} from "./_ddcNodeMode" @@ -12,6 +12,9 @@ export class DdcNode { @PrimaryColumn_() id!: string + @IntColumn_({nullable: false}) + createdAt!: number + @Index_() @ManyToOne_(() => Account, {nullable: true}) providerId!: Account From d08b2bfc7e727313ddeebba47736d74945e03b07 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 20 Aug 2024 12:16:27 +0500 Subject: [PATCH 03/10] Add `DB_USER` and `DB_HOST` to `.env` --- .env | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.env b/.env index 0be3a93..380a1ae 100644 --- a/.env +++ b/.env @@ -1,5 +1,7 @@ DB_NAME=squid +DB_USER=postgres DB_PASS=postgres +DB_HOST="127.0.0.1" DB_PORT=5432 GQL_PORT=4350 From c6dbbdb2b4881f06ed2e9ff2cc635a6517bbd6be Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 20 Aug 2024 12:20:49 +0500 Subject: [PATCH 04/10] Rename `.env` to `.env.example` --- .env => .env.example | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .env => .env.example (100%) diff --git a/.env b/.env.example similarity index 100% rename from .env rename to .env.example From f7e70c7abef28ad8a880877cb973b9fcb01216b4 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 20 Aug 2024 12:21:51 +0500 Subject: [PATCH 05/10] Add `.env` to `.gitignore` and `.dockerignore` --- .dockerignore | 2 ++ .gitignore | 3 +++ 2 files changed, 5 insertions(+) diff --git a/.dockerignore b/.dockerignore index 27c983b..ea20d19 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,3 +2,5 @@ /node_modules /lib /*Versions.jsonl +.env* +!.env.example diff --git a/.gitignore b/.gitignore index a8902fa..775d99b 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,6 @@ /.idea /data + +.env* +!.env.example From b15ba8b90a64918f8559e418d44b1c5fd525a073 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 20 Aug 2024 12:30:11 +0500 Subject: [PATCH 06/10] sqd migration:generate --- db/migrations/1724138300437-Data.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 db/migrations/1724138300437-Data.js diff --git a/db/migrations/1724138300437-Data.js b/db/migrations/1724138300437-Data.js new file mode 100644 index 0000000..7ef836d --- /dev/null +++ b/db/migrations/1724138300437-Data.js @@ -0,0 +1,15 @@ +module.exports = class Data1724138300437 { + name = 'Data1724138300437' + + async up(db) { + await db.query(`ALTER TABLE "ddc_node" ADD "created_at" integer NOT NULL DEFAULT -1`) + await db.query(`ALTER TABLE "ddc_cluster" ADD "created_at" integer NOT NULL DEFAULT -1`) + await db.query(`ALTER TABLE "ddc_bucket" ADD "created_at" integer NOT NULL DEFAULT -1`) + } + + async down(db) { + await db.query(`ALTER TABLE "ddc_node" DROP COLUMN "created_at"`) + await db.query(`ALTER TABLE "ddc_cluster" DROP COLUMN "created_at"`) + await db.query(`ALTER TABLE "ddc_bucket" DROP COLUMN "created_at"`) + } +} From 214fef1dcd98fcbedd18af7df7712e003256ca46 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 20 Aug 2024 12:11:18 +0500 Subject: [PATCH 07/10] Get and persist DDC bucket creation block --- src/main.ts | 1 + src/processors/ddcBucketsProcessor.ts | 30 ++++++++++++++++++--------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/main.ts b/src/main.ts index de0d684..0bc8b7f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -225,6 +225,7 @@ processor.run(new TypeormDatabase({ supportHotBlocks: true }), async (ctx) => { ddcBucketEntities.push( new DdcBucket({ id: bucket.bucketId.toString(), + createdAt: bucket.createdAt, ownerId: accounts.get(bucket.ownerId), clusterId: cluster, isPublic: bucket.isPublic, diff --git a/src/processors/ddcBucketsProcessor.ts b/src/processors/ddcBucketsProcessor.ts index 2a3bcf7..a452e3e 100644 --- a/src/processors/ddcBucketsProcessor.ts +++ b/src/processors/ddcBucketsProcessor.ts @@ -4,6 +4,7 @@ import { logEmptyStorage, logUnsupportedEventVersion, logUnsupportedStorageVersi import { BaseProcessor } from './processor' export interface DdcBucketInfo { + createdAt?: number ownerId: string clusterId: string bucketId: bigint @@ -22,7 +23,12 @@ export class DdcBucketsProcessor extends BaseProcessor { super(new Map()) } - private async processDdcBucketsEvents(bucketId: bigint, block: BlockHeader) { + private async processDdcBucketsEvents(bucketId: bigint, block: BlockHeader, event: Event) { + let createdAt; + if (event.name === events.ddcCustomers.bucketCreated.name) { + createdAt = block.height + } + // TODO(khssnv) // We can return to ascending versions check here and in the other processors when // https://github.com/subsquid/squid-sdk/issues/334 fixed, possibly with @@ -33,6 +39,7 @@ export class DdcBucketsProcessor extends BaseProcessor { const bucket = await storage.ddcCustomers.buckets.v54100.get(block, bucketId) if (bucket) { bucketInfo = { + createdAt, ownerId: bucket.ownerId, clusterId: bucket.clusterId, bucketId: bucketId, @@ -48,6 +55,7 @@ export class DdcBucketsProcessor extends BaseProcessor { const bucket = await storage.ddcCustomers.buckets.v50000.get(block, bucketId) if (bucket) { bucketInfo = { + createdAt, ownerId: bucket.ownerId, clusterId: bucket.clusterId, bucketId: bucketId, @@ -63,6 +71,7 @@ export class DdcBucketsProcessor extends BaseProcessor { const bucket = await storage.ddcCustomers.buckets.v48017.get(block, bucketId) if (bucket) { bucketInfo = { + createdAt, ownerId: bucket.ownerId, clusterId: bucket.clusterId, bucketId: bucketId, @@ -78,6 +87,7 @@ export class DdcBucketsProcessor extends BaseProcessor { const bucket = await storage.ddcCustomers.buckets.v48013.get(block, bucketId) if (bucket) { bucketInfo = { + createdAt, ownerId: bucket.ownerId, clusterId: bucket.clusterId, bucketId: bucketId, @@ -105,13 +115,13 @@ export class DdcBucketsProcessor extends BaseProcessor { case events.ddcCustomers.bucketCreated.name: { if (events.ddcCustomers.bucketCreated.v48013.is(event)) { const bucketId = events.ddcCustomers.bucketCreated.v48013.decode(event) - await this.processDdcBucketsEvents(bucketId, block) + await this.processDdcBucketsEvents(bucketId, block, event) } else if (events.ddcCustomers.bucketCreated.v48800.is(event)) { const bucketId = events.ddcCustomers.bucketCreated.v48800.decode(event).bucketId - await this.processDdcBucketsEvents(bucketId, block) + await this.processDdcBucketsEvents(bucketId, block, event) } else if (events.ddcCustomers.bucketCreated.v54100.is(event)) { const bucketId = events.ddcCustomers.bucketCreated.v54100.decode(event).bucketId - await this.processDdcBucketsEvents(bucketId, block) + await this.processDdcBucketsEvents(bucketId, block, event) } else { logUnsupportedEventVersion(event) } @@ -120,13 +130,13 @@ export class DdcBucketsProcessor extends BaseProcessor { case events.ddcCustomers.bucketUpdated.name: { if (events.ddcCustomers.bucketUpdated.v48017.is(event)) { const bucketId = events.ddcCustomers.bucketUpdated.v48017.decode(event) - await this.processDdcBucketsEvents(bucketId, block) + await this.processDdcBucketsEvents(bucketId, block, event) } else if (events.ddcCustomers.bucketUpdated.v48800.is(event)) { const bucketId = events.ddcCustomers.bucketUpdated.v48800.decode(event).bucketId - await this.processDdcBucketsEvents(bucketId, block) + await this.processDdcBucketsEvents(bucketId, block, event) } else if (events.ddcCustomers.bucketUpdated.v54100.is(event)) { const bucketId = events.ddcCustomers.bucketUpdated.v54100.decode(event).bucketId - await this.processDdcBucketsEvents(bucketId, block) + await this.processDdcBucketsEvents(bucketId, block, event) } else { logUnsupportedEventVersion(event) } @@ -135,7 +145,7 @@ export class DdcBucketsProcessor extends BaseProcessor { case events.ddcCustomers.bucketRemoved.name: { if (events.ddcCustomers.bucketRemoved.v50000.is(event)) { const bucketId = events.ddcCustomers.bucketRemoved.v50000.decode(event).bucketId - await this.processDdcBucketsEvents(bucketId, block) + await this.processDdcBucketsEvents(bucketId, block, event) } else { logUnsupportedEventVersion(event) } @@ -144,7 +154,7 @@ export class DdcBucketsProcessor extends BaseProcessor { case events.ddcCustomers.bucketTotalNodesUsageUpdated.name: { if (events.ddcCustomers.bucketTotalNodesUsageUpdated.v54100.is(event)) { const bucketId = events.ddcCustomers.bucketTotalNodesUsageUpdated.v54100.decode(event).bucketId - await this.processDdcBucketsEvents(bucketId, block) + await this.processDdcBucketsEvents(bucketId, block, event) } else { logUnsupportedEventVersion(event) } @@ -153,7 +163,7 @@ export class DdcBucketsProcessor extends BaseProcessor { case events.ddcCustomers.bucketTotalCustomersUsageUpdated.name: { if (events.ddcCustomers.bucketTotalCustomersUsageUpdated.v54100.is(event)) { const bucketId = events.ddcCustomers.bucketTotalCustomersUsageUpdated.v54100.decode(event).bucketId - await this.processDdcBucketsEvents(bucketId, block) + await this.processDdcBucketsEvents(bucketId, block, event) } else { logUnsupportedEventVersion(event) } From e53db9d5a49e08df78680ec8981d960d1864dae5 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 20 Aug 2024 12:12:07 +0500 Subject: [PATCH 08/10] Get and persist DDC node creation block --- src/main.ts | 1 + src/processors/ddcNodesProcessor.ts | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/main.ts b/src/main.ts index 0bc8b7f..1f5bdc4 100644 --- a/src/main.ts +++ b/src/main.ts @@ -168,6 +168,7 @@ processor.run(new TypeormDatabase({ supportHotBlocks: true }), async (ctx) => { ddcNodesMap.get(node.id) ?? new DdcNode({ id: node.id, + createdAt: node.createdAt, providerId: accounts.get(node.providerId), }) nodeEntity.host = node.host diff --git a/src/processors/ddcNodesProcessor.ts b/src/processors/ddcNodesProcessor.ts index 5e11f50..1935bda 100644 --- a/src/processors/ddcNodesProcessor.ts +++ b/src/processors/ddcNodesProcessor.ts @@ -17,6 +17,8 @@ const MaxDomainLen = 255 interface DdcNodeInfo { id: string + createdAt?: number + providerId: string clusterId: string | undefined @@ -51,13 +53,19 @@ export class DdcNodesProcessor extends BaseProcessor { }) } - private async processDdcNodesEvents(nodeId: string, block: BlockHeader) { + private async processDdcNodesEvents(nodeId: string, block: BlockHeader, event: Event) { + let createdAt + if (event.name === events.ddcNodes.nodeCreated.name) { + createdAt = block.height + } + let nodeInfo: DdcNodeInfo | undefined if (storage.ddcNodes.storageNodes.v54113.is(block)) { const node = await storage.ddcNodes.storageNodes.v54113.get(block, nodeId) if (node) { nodeInfo = { id: toCereAddress(node.pubKey), + createdAt, providerId: node.providerId, clusterId: node.clusterId, host: decodeAsciiStringFromScaleVecFixed(MaxHostLen, node.props.host as HexString), @@ -78,6 +86,7 @@ export class DdcNodesProcessor extends BaseProcessor { if (node) { nodeInfo = { id: toCereAddress(node.pubKey), + createdAt, providerId: node.providerId, clusterId: node.clusterId, host: decodeAsciiStringFromScaleVecFixed(MaxHostLen, node.props.host as HexString), @@ -98,6 +107,7 @@ export class DdcNodesProcessor extends BaseProcessor { if (node) { nodeInfo = { id: toCereAddress(node.pubKey), + createdAt, providerId: node.providerId, clusterId: node.clusterId, host: decodeAsciiStringFromScaleVecFixed(MaxHostLen, node.props.host as HexString), @@ -118,6 +128,7 @@ export class DdcNodesProcessor extends BaseProcessor { if (node) { nodeInfo = { id: toCereAddress(node.pubKey), + createdAt, providerId: node.providerId, clusterId: node.clusterId, host: decodeAsciiStringFromScaleVecFixed(MaxHostLen, node.props.host as HexString), @@ -138,6 +149,7 @@ export class DdcNodesProcessor extends BaseProcessor { if (node) { nodeInfo = { id: toCereAddress(node.pubKey), + createdAt, providerId: node.providerId, clusterId: node.clusterId, host: decodeAsciiStringFromScaleVecFixed(MaxHostLen, node.props.host as HexString), @@ -158,6 +170,7 @@ export class DdcNodesProcessor extends BaseProcessor { if (node) { nodeInfo = { id: toCereAddress(node.pubKey), + createdAt, providerId: node.providerId, clusterId: node.clusterId, host: 'localhost', @@ -222,10 +235,10 @@ export class DdcNodesProcessor extends BaseProcessor { case events.ddcNodes.nodeCreated.name: { if (events.ddcNodes.nodeCreated.v48008.is(event)) { const nodeId = events.ddcNodes.nodeCreated.v48008.decode(event).nodePubKey.value - await this.processDdcNodesEvents(nodeId, block) + await this.processDdcNodesEvents(nodeId, block, event) } else if (events.ddcNodes.nodeCreated.v48017.is(event)) { const nodeId = events.ddcNodes.nodeCreated.v48017.decode(event).nodePubKey.value - await this.processDdcNodesEvents(nodeId, block) + await this.processDdcNodesEvents(nodeId, block, event) } else { logUnsupportedEventVersion(event) } @@ -234,10 +247,10 @@ export class DdcNodesProcessor extends BaseProcessor { case events.ddcNodes.nodeParamsChanged.name: { if (events.ddcNodes.nodeParamsChanged.v48008.is(event)) { const nodeId = events.ddcNodes.nodeParamsChanged.v48008.decode(event).nodePubKey.value - await this.processDdcNodesEvents(nodeId, block) + await this.processDdcNodesEvents(nodeId, block, event) } else if (events.ddcNodes.nodeParamsChanged.v48017.is(event)) { const nodeId = events.ddcNodes.nodeParamsChanged.v48017.decode(event).nodePubKey.value - await this.processDdcNodesEvents(nodeId, block) + await this.processDdcNodesEvents(nodeId, block, event) } else { logUnsupportedEventVersion(event) } From 419e9a6cb4782c123467a85eeeaa154f6fd5c642 Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 20 Aug 2024 12:12:34 +0500 Subject: [PATCH 09/10] Get and persist DDC cluster creation block --- src/main.ts | 1 + src/processors/ddcClustersProcessor.ts | 43 ++++++++++++++++---------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/main.ts b/src/main.ts index 1f5bdc4..5043570 100644 --- a/src/main.ts +++ b/src/main.ts @@ -99,6 +99,7 @@ processor.run(new TypeormDatabase({ supportHotBlocks: true }), async (ctx) => { ddcClusterEntities.push( new DdcCluster({ id: c.id, + createdAt: c.createdAt, managerId: accounts.get(c.managerId), treasuryShare: c.treasuryShare, validatorsShare: c.validatorsShare, diff --git a/src/processors/ddcClustersProcessor.ts b/src/processors/ddcClustersProcessor.ts index 8e814df..7a067b3 100644 --- a/src/processors/ddcClustersProcessor.ts +++ b/src/processors/ddcClustersProcessor.ts @@ -6,6 +6,9 @@ import { BaseProcessor } from './processor' export interface DdcClusterInfo { id: string + + createdAt?: number + managerId: string treasuryShare: bigint @@ -33,9 +36,10 @@ export class DdcClustersProcessor extends BaseProcessor { super(new Map()) } - private newClusterInfo(clusterId: string, managerId: string): DdcClusterInfo { + private newClusterInfo(clusterId: string, managerId: string, createdAt: number | undefined): DdcClusterInfo { return { id: clusterId, + createdAt, managerId: managerId, clusterReserveShare: 0n, erasureCodingRequired: 0, @@ -54,12 +58,17 @@ export class DdcClustersProcessor extends BaseProcessor { } } - private async processDdcClustersEvents(clusterId: string, block: BlockHeader) { + private async processDdcClustersEvents(clusterId: string, block: BlockHeader, event: Event) { + let createdAt + if (event.name === events.ddcClusters.clusterCreated.name) { + createdAt = block.height + } + let clusterInfo: DdcClusterInfo | undefined if (storage.ddcClusters.clusters.v54105.is(block)) { const cluster = await storage.ddcClusters.clusters.v54105.get(block, clusterId) if (cluster) { - clusterInfo = this.newClusterInfo(clusterId, cluster.managerId) + clusterInfo = this.newClusterInfo(clusterId, cluster.managerId, createdAt) clusterInfo.erasureCodingRequired = cluster.props.erasureCodingRequired clusterInfo.erasureCodingTotal = cluster.props.erasureCodingTotal clusterInfo.replicationTotal = cluster.props.replicationTotal @@ -68,7 +77,7 @@ export class DdcClustersProcessor extends BaseProcessor { } else if (storage.ddcClusters.clusters.v54001.is(block)) { const cluster = await storage.ddcClusters.clusters.v54001.get(block, clusterId) if (cluster) { - clusterInfo = this.newClusterInfo(clusterId, cluster.managerId) + clusterInfo = this.newClusterInfo(clusterId, cluster.managerId, createdAt) clusterInfo.erasureCodingRequired = cluster.props.erasureCodingRequired clusterInfo.erasureCodingTotal = cluster.props.erasureCodingTotal clusterInfo.replicationTotal = cluster.props.replicationTotal @@ -77,7 +86,7 @@ export class DdcClustersProcessor extends BaseProcessor { } else if (storage.ddcClusters.clusters.v53003.is(block)) { const cluster = await storage.ddcClusters.clusters.v53003.get(block, clusterId) if (cluster) { - clusterInfo = this.newClusterInfo(clusterId, cluster.managerId) + clusterInfo = this.newClusterInfo(clusterId, cluster.managerId, createdAt) clusterInfo.erasureCodingRequired = cluster.props.erasureCodingRequired clusterInfo.erasureCodingTotal = cluster.props.erasureCodingTotal clusterInfo.replicationTotal = cluster.props.replicationTotal @@ -85,17 +94,17 @@ export class DdcClustersProcessor extends BaseProcessor { } else if (storage.ddcClusters.clusters.v48016.is(block)) { const cluster = await storage.ddcClusters.clusters.v48016.get(block, clusterId) if (cluster) { - clusterInfo = this.newClusterInfo(clusterId, cluster.managerId) + clusterInfo = this.newClusterInfo(clusterId, cluster.managerId, createdAt) } } else if (storage.ddcClusters.clusters.v48013.is(block)) { const cluster = await storage.ddcClusters.clusters.v48013.get(block, clusterId) if (cluster) { - clusterInfo = this.newClusterInfo(clusterId, cluster.managerId) + clusterInfo = this.newClusterInfo(clusterId, cluster.managerId, createdAt) } } else if (storage.ddcClusters.clusters.v48008.is(block)) { const cluster = await storage.ddcClusters.clusters.v48008.get(block, clusterId) if (cluster) { - clusterInfo = this.newClusterInfo(clusterId, cluster.managerId) + clusterInfo = this.newClusterInfo(clusterId, cluster.managerId, createdAt) } } else { logUnsupportedStorageVersion('DdcClusters.Clusters', block) @@ -137,7 +146,7 @@ export class DdcClustersProcessor extends BaseProcessor { case events.ddcClusters.clusterCreated.name: { if (events.ddcClusters.clusterCreated.v48008.is(event)) { const clusterId = events.ddcClusters.clusterCreated.v48008.decode(event).clusterId - await this.processDdcClustersEvents(clusterId, block) + await this.processDdcClustersEvents(clusterId, block, event) } else { logUnsupportedEventVersion(event) } @@ -146,7 +155,7 @@ export class DdcClustersProcessor extends BaseProcessor { case events.ddcClusters.clusterParamsSet.name: { if (events.ddcClusters.clusterParamsSet.v48008.is(event)) { const clusterId = events.ddcClusters.clusterParamsSet.v48008.decode(event).clusterId - await this.processDdcClustersEvents(clusterId, block) + await this.processDdcClustersEvents(clusterId, block, event) } else { logUnsupportedEventVersion(event) } @@ -155,7 +164,7 @@ export class DdcClustersProcessor extends BaseProcessor { case events.ddcClusters.clusterGovParamsSet.name: { if (events.ddcClusters.clusterGovParamsSet.v48013.is(event)) { const clusterId = events.ddcClusters.clusterGovParamsSet.v48013.decode(event).clusterId - await this.processDdcClustersEvents(clusterId, block) + await this.processDdcClustersEvents(clusterId, block, event) } else { logUnsupportedEventVersion(event) } @@ -164,7 +173,7 @@ export class DdcClustersProcessor extends BaseProcessor { case events.ddcClusters.clusterProtocolParamsSet.name: { if (events.ddcClusters.clusterProtocolParamsSet.v54001.is(event)) { const clusterId = events.ddcClusters.clusterProtocolParamsSet.v54001.decode(event).clusterId - await this.processDdcClustersEvents(clusterId, block) + await this.processDdcClustersEvents(clusterId, block, event) } else { logUnsupportedEventVersion(event) } @@ -173,7 +182,7 @@ export class DdcClustersProcessor extends BaseProcessor { case events.ddcClusters.clusterActivated.name: { if (events.ddcClusters.clusterActivated.v54001.is(event)) { const clusterId = events.ddcClusters.clusterActivated.v54001.decode(event).clusterId - await this.processDdcClustersEvents(clusterId, block) + await this.processDdcClustersEvents(clusterId, block, event) } else { logUnsupportedEventVersion(event) } @@ -182,7 +191,7 @@ export class DdcClustersProcessor extends BaseProcessor { case events.ddcClusters.clusterBonded.name: { if (events.ddcClusters.clusterBonded.v54001.is(event)) { const clusterId = events.ddcClusters.clusterBonded.v54001.decode(event).clusterId - await this.processDdcClustersEvents(clusterId, block) + await this.processDdcClustersEvents(clusterId, block, event) } else { logUnsupportedEventVersion(event) } @@ -191,7 +200,7 @@ export class DdcClustersProcessor extends BaseProcessor { case events.ddcClusters.clusterUnbonded.name: { if (events.ddcClusters.clusterUnbonded.v54001.is(event)) { const clusterId = events.ddcClusters.clusterUnbonded.v54001.decode(event).clusterId - await this.processDdcClustersEvents(clusterId, block) + await this.processDdcClustersEvents(clusterId, block, event) } else { logUnsupportedEventVersion(event) } @@ -200,7 +209,7 @@ export class DdcClustersProcessor extends BaseProcessor { case events.ddcClusters.clusterNodeValidated.name: { if (events.ddcClusters.clusterNodeValidated.v54001.is(event)) { const clusterId = events.ddcClusters.clusterNodeValidated.v54001.decode(event).clusterId - await this.processDdcClustersEvents(clusterId, block) + await this.processDdcClustersEvents(clusterId, block, event) } else { logUnsupportedEventVersion(event) } @@ -209,7 +218,7 @@ export class DdcClustersProcessor extends BaseProcessor { case events.ddcClusters.clusterUnbonding.name: { if (events.ddcClusters.clusterUnbonding.v54004.is(event)) { const clusterId = events.ddcClusters.clusterUnbonding.v54004.decode(event).clusterId - await this.processDdcClustersEvents(clusterId, block) + await this.processDdcClustersEvents(clusterId, block, event) } else { logUnsupportedEventVersion(event) } From f0e6a1c1fb5bc4db7587d123ab0d7f3a9099bb7e Mon Sep 17 00:00:00 2001 From: "Alisher A. Khassanov" Date: Tue, 20 Aug 2024 12:46:19 +0500 Subject: [PATCH 10/10] Specify entity creation time unit in a column name --- db/migrations/1724138300437-Data.js | 12 ++++++------ schema.graphql | 6 +++--- src/main.ts | 6 +++--- src/model/generated/ddcBucket.model.ts | 2 +- src/model/generated/ddcCluster.model.ts | 2 +- src/model/generated/ddcNode.model.ts | 2 +- src/processors/ddcBucketsProcessor.ts | 14 +++++++------- src/processors/ddcClustersProcessor.ts | 20 ++++++++++---------- src/processors/ddcNodesProcessor.ts | 18 +++++++++--------- 9 files changed, 41 insertions(+), 41 deletions(-) diff --git a/db/migrations/1724138300437-Data.js b/db/migrations/1724138300437-Data.js index 7ef836d..9c2fe64 100644 --- a/db/migrations/1724138300437-Data.js +++ b/db/migrations/1724138300437-Data.js @@ -2,14 +2,14 @@ module.exports = class Data1724138300437 { name = 'Data1724138300437' async up(db) { - await db.query(`ALTER TABLE "ddc_node" ADD "created_at" integer NOT NULL DEFAULT -1`) - await db.query(`ALTER TABLE "ddc_cluster" ADD "created_at" integer NOT NULL DEFAULT -1`) - await db.query(`ALTER TABLE "ddc_bucket" ADD "created_at" integer NOT NULL DEFAULT -1`) + await db.query(`ALTER TABLE "ddc_node" ADD "created_at_block_height" integer NOT NULL DEFAULT -1`) + await db.query(`ALTER TABLE "ddc_cluster" ADD "created_at_block_height" integer NOT NULL DEFAULT -1`) + await db.query(`ALTER TABLE "ddc_bucket" ADD "created_at_block_height" integer NOT NULL DEFAULT -1`) } async down(db) { - await db.query(`ALTER TABLE "ddc_node" DROP COLUMN "created_at"`) - await db.query(`ALTER TABLE "ddc_cluster" DROP COLUMN "created_at"`) - await db.query(`ALTER TABLE "ddc_bucket" DROP COLUMN "created_at"`) + await db.query(`ALTER TABLE "ddc_node" DROP COLUMN "created_at_block_height"`) + await db.query(`ALTER TABLE "ddc_cluster" DROP COLUMN "created_at_block_height"`) + await db.query(`ALTER TABLE "ddc_bucket" DROP COLUMN "created_at_block_height"`) } } diff --git a/schema.graphql b/schema.graphql index 8da235f..b27df9a 100644 --- a/schema.graphql +++ b/schema.graphql @@ -12,7 +12,7 @@ type Account @entity { type DdcCluster @entity { id: ID! - createdAt: Int! + createdAtBlockHeight: Int! managerId: Account! @index @@ -43,7 +43,7 @@ enum DdcClusterStatus { type DdcNode @entity { id: ID! - createdAt: Int! + createdAtBlockHeight: Int! providerId: Account! @index clusterId: DdcCluster @@ -69,7 +69,7 @@ enum DdcNodeMode { type DdcBucket @entity { id: ID! - createdAt: Int! + createdAtBlockHeight: Int! ownerId: Account! @index clusterId: DdcCluster! @index diff --git a/src/main.ts b/src/main.ts index 5043570..7b2f2b7 100644 --- a/src/main.ts +++ b/src/main.ts @@ -99,7 +99,7 @@ processor.run(new TypeormDatabase({ supportHotBlocks: true }), async (ctx) => { ddcClusterEntities.push( new DdcCluster({ id: c.id, - createdAt: c.createdAt, + createdAtBlockHeight: c.createdAtBlockHeight, managerId: accounts.get(c.managerId), treasuryShare: c.treasuryShare, validatorsShare: c.validatorsShare, @@ -169,7 +169,7 @@ processor.run(new TypeormDatabase({ supportHotBlocks: true }), async (ctx) => { ddcNodesMap.get(node.id) ?? new DdcNode({ id: node.id, - createdAt: node.createdAt, + createdAtBlockHeight: node.createdAtBlockHeight, providerId: accounts.get(node.providerId), }) nodeEntity.host = node.host @@ -227,7 +227,7 @@ processor.run(new TypeormDatabase({ supportHotBlocks: true }), async (ctx) => { ddcBucketEntities.push( new DdcBucket({ id: bucket.bucketId.toString(), - createdAt: bucket.createdAt, + createdAtBlockHeight: bucket.createdAtBlockHeight, ownerId: accounts.get(bucket.ownerId), clusterId: cluster, isPublic: bucket.isPublic, diff --git a/src/model/generated/ddcBucket.model.ts b/src/model/generated/ddcBucket.model.ts index a51a599..f16eb4d 100644 --- a/src/model/generated/ddcBucket.model.ts +++ b/src/model/generated/ddcBucket.model.ts @@ -12,7 +12,7 @@ export class DdcBucket { id!: string @IntColumn_({nullable: false}) - createdAt!: number + createdAtBlockHeight!: number @Index_() @ManyToOne_(() => Account, {nullable: true}) diff --git a/src/model/generated/ddcCluster.model.ts b/src/model/generated/ddcCluster.model.ts index 2274c24..c4af296 100644 --- a/src/model/generated/ddcCluster.model.ts +++ b/src/model/generated/ddcCluster.model.ts @@ -14,7 +14,7 @@ export class DdcCluster { id!: string @IntColumn_({nullable: false}) - createdAt!: number + createdAtBlockHeight!: number @Index_() @ManyToOne_(() => Account, {nullable: true}) diff --git a/src/model/generated/ddcNode.model.ts b/src/model/generated/ddcNode.model.ts index 89b5fda..8c4bb17 100644 --- a/src/model/generated/ddcNode.model.ts +++ b/src/model/generated/ddcNode.model.ts @@ -13,7 +13,7 @@ export class DdcNode { id!: string @IntColumn_({nullable: false}) - createdAt!: number + createdAtBlockHeight!: number @Index_() @ManyToOne_(() => Account, {nullable: true}) diff --git a/src/processors/ddcBucketsProcessor.ts b/src/processors/ddcBucketsProcessor.ts index a452e3e..46f38c7 100644 --- a/src/processors/ddcBucketsProcessor.ts +++ b/src/processors/ddcBucketsProcessor.ts @@ -4,7 +4,7 @@ import { logEmptyStorage, logUnsupportedEventVersion, logUnsupportedStorageVersi import { BaseProcessor } from './processor' export interface DdcBucketInfo { - createdAt?: number + createdAtBlockHeight?: number ownerId: string clusterId: string bucketId: bigint @@ -24,9 +24,9 @@ export class DdcBucketsProcessor extends BaseProcessor { } private async processDdcBucketsEvents(bucketId: bigint, block: BlockHeader, event: Event) { - let createdAt; + let createdAtBlockHeight; if (event.name === events.ddcCustomers.bucketCreated.name) { - createdAt = block.height + createdAtBlockHeight = block.height } // TODO(khssnv) @@ -39,7 +39,7 @@ export class DdcBucketsProcessor extends BaseProcessor { const bucket = await storage.ddcCustomers.buckets.v54100.get(block, bucketId) if (bucket) { bucketInfo = { - createdAt, + createdAtBlockHeight: createdAtBlockHeight, ownerId: bucket.ownerId, clusterId: bucket.clusterId, bucketId: bucketId, @@ -55,7 +55,7 @@ export class DdcBucketsProcessor extends BaseProcessor { const bucket = await storage.ddcCustomers.buckets.v50000.get(block, bucketId) if (bucket) { bucketInfo = { - createdAt, + createdAtBlockHeight: createdAtBlockHeight, ownerId: bucket.ownerId, clusterId: bucket.clusterId, bucketId: bucketId, @@ -71,7 +71,7 @@ export class DdcBucketsProcessor extends BaseProcessor { const bucket = await storage.ddcCustomers.buckets.v48017.get(block, bucketId) if (bucket) { bucketInfo = { - createdAt, + createdAtBlockHeight: createdAtBlockHeight, ownerId: bucket.ownerId, clusterId: bucket.clusterId, bucketId: bucketId, @@ -87,7 +87,7 @@ export class DdcBucketsProcessor extends BaseProcessor { const bucket = await storage.ddcCustomers.buckets.v48013.get(block, bucketId) if (bucket) { bucketInfo = { - createdAt, + createdAtBlockHeight: createdAtBlockHeight, ownerId: bucket.ownerId, clusterId: bucket.clusterId, bucketId: bucketId, diff --git a/src/processors/ddcClustersProcessor.ts b/src/processors/ddcClustersProcessor.ts index 7a067b3..95fb192 100644 --- a/src/processors/ddcClustersProcessor.ts +++ b/src/processors/ddcClustersProcessor.ts @@ -7,7 +7,7 @@ import { BaseProcessor } from './processor' export interface DdcClusterInfo { id: string - createdAt?: number + createdAtBlockHeight?: number managerId: string @@ -39,7 +39,7 @@ export class DdcClustersProcessor extends BaseProcessor { private newClusterInfo(clusterId: string, managerId: string, createdAt: number | undefined): DdcClusterInfo { return { id: clusterId, - createdAt, + createdAtBlockHeight: createdAt, managerId: managerId, clusterReserveShare: 0n, erasureCodingRequired: 0, @@ -59,16 +59,16 @@ export class DdcClustersProcessor extends BaseProcessor { } private async processDdcClustersEvents(clusterId: string, block: BlockHeader, event: Event) { - let createdAt + let createdAtBlockHeight if (event.name === events.ddcClusters.clusterCreated.name) { - createdAt = block.height + createdAtBlockHeight = block.height } let clusterInfo: DdcClusterInfo | undefined if (storage.ddcClusters.clusters.v54105.is(block)) { const cluster = await storage.ddcClusters.clusters.v54105.get(block, clusterId) if (cluster) { - clusterInfo = this.newClusterInfo(clusterId, cluster.managerId, createdAt) + clusterInfo = this.newClusterInfo(clusterId, cluster.managerId, createdAtBlockHeight) clusterInfo.erasureCodingRequired = cluster.props.erasureCodingRequired clusterInfo.erasureCodingTotal = cluster.props.erasureCodingTotal clusterInfo.replicationTotal = cluster.props.replicationTotal @@ -77,7 +77,7 @@ export class DdcClustersProcessor extends BaseProcessor { } else if (storage.ddcClusters.clusters.v54001.is(block)) { const cluster = await storage.ddcClusters.clusters.v54001.get(block, clusterId) if (cluster) { - clusterInfo = this.newClusterInfo(clusterId, cluster.managerId, createdAt) + clusterInfo = this.newClusterInfo(clusterId, cluster.managerId, createdAtBlockHeight) clusterInfo.erasureCodingRequired = cluster.props.erasureCodingRequired clusterInfo.erasureCodingTotal = cluster.props.erasureCodingTotal clusterInfo.replicationTotal = cluster.props.replicationTotal @@ -86,7 +86,7 @@ export class DdcClustersProcessor extends BaseProcessor { } else if (storage.ddcClusters.clusters.v53003.is(block)) { const cluster = await storage.ddcClusters.clusters.v53003.get(block, clusterId) if (cluster) { - clusterInfo = this.newClusterInfo(clusterId, cluster.managerId, createdAt) + clusterInfo = this.newClusterInfo(clusterId, cluster.managerId, createdAtBlockHeight) clusterInfo.erasureCodingRequired = cluster.props.erasureCodingRequired clusterInfo.erasureCodingTotal = cluster.props.erasureCodingTotal clusterInfo.replicationTotal = cluster.props.replicationTotal @@ -94,17 +94,17 @@ export class DdcClustersProcessor extends BaseProcessor { } else if (storage.ddcClusters.clusters.v48016.is(block)) { const cluster = await storage.ddcClusters.clusters.v48016.get(block, clusterId) if (cluster) { - clusterInfo = this.newClusterInfo(clusterId, cluster.managerId, createdAt) + clusterInfo = this.newClusterInfo(clusterId, cluster.managerId, createdAtBlockHeight) } } else if (storage.ddcClusters.clusters.v48013.is(block)) { const cluster = await storage.ddcClusters.clusters.v48013.get(block, clusterId) if (cluster) { - clusterInfo = this.newClusterInfo(clusterId, cluster.managerId, createdAt) + clusterInfo = this.newClusterInfo(clusterId, cluster.managerId, createdAtBlockHeight) } } else if (storage.ddcClusters.clusters.v48008.is(block)) { const cluster = await storage.ddcClusters.clusters.v48008.get(block, clusterId) if (cluster) { - clusterInfo = this.newClusterInfo(clusterId, cluster.managerId, createdAt) + clusterInfo = this.newClusterInfo(clusterId, cluster.managerId, createdAtBlockHeight) } } else { logUnsupportedStorageVersion('DdcClusters.Clusters', block) diff --git a/src/processors/ddcNodesProcessor.ts b/src/processors/ddcNodesProcessor.ts index 1935bda..962645f 100644 --- a/src/processors/ddcNodesProcessor.ts +++ b/src/processors/ddcNodesProcessor.ts @@ -17,7 +17,7 @@ const MaxDomainLen = 255 interface DdcNodeInfo { id: string - createdAt?: number + createdAtBlockHeight?: number providerId: string clusterId: string | undefined @@ -54,9 +54,9 @@ export class DdcNodesProcessor extends BaseProcessor { } private async processDdcNodesEvents(nodeId: string, block: BlockHeader, event: Event) { - let createdAt + let createdAtBlockHeight if (event.name === events.ddcNodes.nodeCreated.name) { - createdAt = block.height + createdAtBlockHeight = block.height } let nodeInfo: DdcNodeInfo | undefined @@ -65,7 +65,7 @@ export class DdcNodesProcessor extends BaseProcessor { if (node) { nodeInfo = { id: toCereAddress(node.pubKey), - createdAt, + createdAtBlockHeight: createdAtBlockHeight, providerId: node.providerId, clusterId: node.clusterId, host: decodeAsciiStringFromScaleVecFixed(MaxHostLen, node.props.host as HexString), @@ -86,7 +86,7 @@ export class DdcNodesProcessor extends BaseProcessor { if (node) { nodeInfo = { id: toCereAddress(node.pubKey), - createdAt, + createdAtBlockHeight: createdAtBlockHeight, providerId: node.providerId, clusterId: node.clusterId, host: decodeAsciiStringFromScaleVecFixed(MaxHostLen, node.props.host as HexString), @@ -107,7 +107,7 @@ export class DdcNodesProcessor extends BaseProcessor { if (node) { nodeInfo = { id: toCereAddress(node.pubKey), - createdAt, + createdAtBlockHeight: createdAtBlockHeight, providerId: node.providerId, clusterId: node.clusterId, host: decodeAsciiStringFromScaleVecFixed(MaxHostLen, node.props.host as HexString), @@ -128,7 +128,7 @@ export class DdcNodesProcessor extends BaseProcessor { if (node) { nodeInfo = { id: toCereAddress(node.pubKey), - createdAt, + createdAtBlockHeight: createdAtBlockHeight, providerId: node.providerId, clusterId: node.clusterId, host: decodeAsciiStringFromScaleVecFixed(MaxHostLen, node.props.host as HexString), @@ -149,7 +149,7 @@ export class DdcNodesProcessor extends BaseProcessor { if (node) { nodeInfo = { id: toCereAddress(node.pubKey), - createdAt, + createdAtBlockHeight: createdAtBlockHeight, providerId: node.providerId, clusterId: node.clusterId, host: decodeAsciiStringFromScaleVecFixed(MaxHostLen, node.props.host as HexString), @@ -170,7 +170,7 @@ export class DdcNodesProcessor extends BaseProcessor { if (node) { nodeInfo = { id: toCereAddress(node.pubKey), - createdAt, + createdAtBlockHeight: createdAtBlockHeight, providerId: node.providerId, clusterId: node.clusterId, host: 'localhost',