Skip to content

Commit

Permalink
Merge pull request #9 from Cerebellum-Network/feature/devnet-runtime-…
Browse files Browse the repository at this point in the history
…v54114

Runtime v54114 support
  • Loading branch information
khssnv authored Aug 12, 2024
2 parents b63ac55 + 253d82d commit 8e5559b
Show file tree
Hide file tree
Showing 13 changed files with 5,486 additions and 7 deletions.
17 changes: 17 additions & 0 deletions db/migrations/1723441441325-Data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = class Data1723441441325 {
name = 'Data1723441441325'

async up(db) {
await db.query(`ALTER TABLE "ddc_node" ADD "transferred_bytes" numeric NOT NULL DEFAULT 0`)
await db.query(`ALTER TABLE "ddc_node" ADD "stored_bytes" numeric NOT NULL DEFAULT 0`)
await db.query(`ALTER TABLE "ddc_node" ADD "number_of_puts" numeric NOT NULL DEFAULT 0`)
await db.query(`ALTER TABLE "ddc_node" ADD "number_of_gets" numeric NOT NULL DEFAULT 0`)
}

async down(db) {
await db.query(`ALTER TABLE "ddc_node" DROP COLUMN "transferred_bytes"`)
await db.query(`ALTER TABLE "ddc_node" DROP COLUMN "stored_bytes"`)
await db.query(`ALTER TABLE "ddc_node" DROP COLUMN "number_of_puts"`)
await db.query(`ALTER TABLE "ddc_node" DROP COLUMN "number_of_gets"`)
}
}
5 changes: 5 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ type DdcNode @entity {
grpcPort: Int!
p2pPort: Int!
mode: DdcNodeMode!

transferredBytes: BigInt!
storedBytes: BigInt!
numberOfPuts: BigInt!
numberOfGets: BigInt!
}

enum DdcNodeMode {
Expand Down
3 changes: 0 additions & 3 deletions specs/devnet-0-5149484.jsonl

This file was deleted.

3 changes: 3 additions & 0 deletions specs/devnet-0-5190450.jsonl
Git LFS file not shown
4 changes: 4 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ processor.run(new TypeormDatabase({ supportHotBlocks: true }), async (ctx) => {
nodeEntity.grpcPort = node.grpcPort
nodeEntity.p2pPort = node.p2pPort
nodeEntity.mode = node.mode
nodeEntity.transferredBytes = node.transferredBytes
nodeEntity.storedBytes = node.storedBytes
nodeEntity.numberOfPuts = node.numberOfPuts
nodeEntity.numberOfGets = node.numberOfGets
ddcNodesMap.set(node.id, nodeEntity)
})
// add to cluster
Expand Down
14 changes: 13 additions & 1 deletion src/model/generated/ddcNode.model.ts
Original file line number Diff line number Diff line change
@@ -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_} from "@subsquid/typeorm-store"
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 {Account} from "./account.model"
import {DdcCluster} from "./ddcCluster.model"
import {DdcNodeMode} from "./_ddcNodeMode"
Expand Down Expand Up @@ -40,4 +40,16 @@ export class DdcNode {

@Column_("varchar", {length: 7, nullable: false})
mode!: DdcNodeMode

@BigIntColumn_({nullable: false})
transferredBytes!: bigint

@BigIntColumn_({nullable: false})
storedBytes!: bigint

@BigIntColumn_({nullable: false})
numberOfPuts!: bigint

@BigIntColumn_({nullable: false})
numberOfGets!: bigint
}
3 changes: 1 addition & 2 deletions src/processors/ddcClustersProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ export class DdcClustersProcessor extends BaseProcessor<State> {
clusterInfo.replicationTotal = cluster.props.replicationTotal
clusterInfo.status = DdcClusterStatus[cluster.status.__kind]
}
}
else {
} else {
throwUnsupportedStorageSpec(block)
}
if (clusterInfo) {
Expand Down
48 changes: 48 additions & 0 deletions src/processors/ddcNodesProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ interface DdcNodeInfo {
grpcPort: number
p2pPort: number
mode: DdcNodeMode

transferredBytes: bigint
storedBytes: bigint
numberOfPuts: bigint
numberOfGets: bigint
}

type State = {
Expand Down Expand Up @@ -60,6 +65,10 @@ export class DdcNodesProcessor extends BaseProcessor<State> {
grpcPort: 9090,
p2pPort: 9070,
mode: DdcNodeMode.Storage,
transferredBytes: 0n,
storedBytes: 0n,
numberOfPuts: 0n,
numberOfGets: 0n,
}
}
} else if (storage.ddcNodes.storageNodes.v48013.is(block)) {
Expand All @@ -79,6 +88,10 @@ export class DdcNodesProcessor extends BaseProcessor<State> {
grpcPort: node.props.grpcPort,
p2pPort: node.props.p2PPort,
mode: DdcNodeMode.Storage,
transferredBytes: 0n,
storedBytes: 0n,
numberOfPuts: 0n,
numberOfGets: 0n,
}
}
} else if (storage.ddcNodes.storageNodes.v48017.is(block)) {
Expand All @@ -98,6 +111,10 @@ export class DdcNodesProcessor extends BaseProcessor<State> {
grpcPort: node.props.grpcPort,
p2pPort: node.props.p2PPort,
mode: DdcNodeMode[node.props.mode.__kind],
transferredBytes: 0n,
storedBytes: 0n,
numberOfPuts: 0n,
numberOfGets: 0n,
}
}
} else if (storage.ddcNodes.storageNodes.v48400.is(block)) {
Expand All @@ -117,6 +134,10 @@ export class DdcNodesProcessor extends BaseProcessor<State> {
grpcPort: node.props.grpcPort,
p2pPort: node.props.p2PPort,
mode: DdcNodeMode[node.props.mode.__kind],
transferredBytes: 0n,
storedBytes: 0n,
numberOfPuts: 0n,
numberOfGets: 0n,
}
}
} else if (storage.ddcNodes.storageNodes.v54100.is(block)) {
Expand All @@ -136,6 +157,33 @@ export class DdcNodesProcessor extends BaseProcessor<State> {
grpcPort: node.props.grpcPort,
p2pPort: node.props.p2PPort,
mode: DdcNodeMode[node.props.mode.__kind],
transferredBytes: 0n,
storedBytes: 0n,
numberOfPuts: 0n,
numberOfGets: 0n,
}
}
} else if (storage.ddcNodes.storageNodes.v54113.is(block)) {
const node = await storage.ddcNodes.storageNodes.v54113.get(
block,
nodeId,
)
if (node) {
nodeInfo = {
id: nodeId,
providerId: node.providerId,
clusterId: node.clusterId,
host: node.props.host,
domain: node.props.domain,
ssl: node.props.ssl,
httpPort: node.props.httpPort,
grpcPort: node.props.grpcPort,
p2pPort: node.props.p2PPort,
mode: DdcNodeMode[node.props.mode.__kind],
transferredBytes: node.totalUsage?.transferredBytes ?? 0n,
storedBytes: node.totalUsage?.storedBytes ?? 0n,
numberOfPuts: node.totalUsage?.numberOfPuts ?? 0n,
numberOfGets: node.totalUsage?.numberOfGets ?? 0n,
}
}
} else {
Expand Down
16 changes: 16 additions & 0 deletions src/types/ddc-nodes/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import * as v48013 from '../v48013'
import * as v48017 from '../v48017'
import * as v48400 from '../v48400'
import * as v54100 from '../v54100'
import * as v54113 from '../v54113'

export const storageNodes = {
v48008: new StorageType('DdcNodes.StorageNodes', 'Optional', [v48008.AccountId32], v48008.StorageNode) as StorageNodesV48008,
v48013: new StorageType('DdcNodes.StorageNodes', 'Optional', [v48013.AccountId32], v48013.StorageNode) as StorageNodesV48013,
v48017: new StorageType('DdcNodes.StorageNodes', 'Optional', [v48017.AccountId32], v48017.StorageNode) as StorageNodesV48017,
v48400: new StorageType('DdcNodes.StorageNodes', 'Optional', [v48400.AccountId32], v48400.StorageNode) as StorageNodesV48400,
v54100: new StorageType('DdcNodes.StorageNodes', 'Optional', [v54100.AccountId32], v54100.StorageNode) as StorageNodesV54100,
v54113: new StorageType('DdcNodes.StorageNodes', 'Optional', [v54113.AccountId32], v54113.StorageNode) as StorageNodesV54113,
}

export interface StorageNodesV48008 {
Expand Down Expand Up @@ -83,6 +85,20 @@ export interface StorageNodesV54100 {
getPairsPaged(pageSize: number, block: Block, key: v54100.AccountId32): AsyncIterable<[k: v54100.AccountId32, v: (v54100.StorageNode | undefined)][]>
}

export interface StorageNodesV54113 {
is(block: RuntimeCtx): boolean
get(block: Block, key: v54113.AccountId32): Promise<(v54113.StorageNode | undefined)>
getMany(block: Block, keys: v54113.AccountId32[]): Promise<(v54113.StorageNode | undefined)[]>
getKeys(block: Block): Promise<v54113.AccountId32[]>
getKeys(block: Block, key: v54113.AccountId32): Promise<v54113.AccountId32[]>
getKeysPaged(pageSize: number, block: Block): AsyncIterable<v54113.AccountId32[]>
getKeysPaged(pageSize: number, block: Block, key: v54113.AccountId32): AsyncIterable<v54113.AccountId32[]>
getPairs(block: Block): Promise<[k: v54113.AccountId32, v: (v54113.StorageNode | undefined)][]>
getPairs(block: Block, key: v54113.AccountId32): Promise<[k: v54113.AccountId32, v: (v54113.StorageNode | undefined)][]>
getPairsPaged(pageSize: number, block: Block): AsyncIterable<[k: v54113.AccountId32, v: (v54113.StorageNode | undefined)][]>
getPairsPaged(pageSize: number, block: Block, key: v54113.AccountId32): AsyncIterable<[k: v54113.AccountId32, v: (v54113.StorageNode | undefined)][]>
}

export const cdnNodes = {
v48008: new StorageType('DdcNodes.CDNNodes', 'Optional', [v48008.AccountId32], v48008.CDNNode) as CdnNodesV48008,
v48013: new StorageType('DdcNodes.CDNNodes', 'Optional', [v48013.AccountId32], v48013.CDNNode) as CdnNodesV48013,
Expand Down
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export * as v53001 from './v53001'
export * as v54002 from './v54002'
export * as v54106 from './v54106'
export * as v54112 from './v54112'
export * as v54113 from './v54113'
export * as v53003 from './v53003'
export * as events from './events'
export * as constants from './constants'
Expand Down
26 changes: 26 additions & 0 deletions src/types/system/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import * as v54100 from '../v54100'
import * as v54105 from '../v54105'
import * as v54106 from '../v54106'
import * as v54112 from '../v54112'
import * as v54113 from '../v54113'

export const account = {
/**
Expand Down Expand Up @@ -766,6 +767,16 @@ export const events = {
* just in case someone still reads them from within the runtime.
*/
v54112: new StorageType('System.Events', 'Default', [], sts.array(() => v54112.EventRecord)) as EventsV54112,
/**
* Events deposited for the current block.
*
* NOTE: The item is unbound and should therefore never be read on chain.
* It could otherwise inflate the PoV size of a block.
*
* Events have a large in-memory size. Box the events to not go out-of-memory
* just in case someone still reads them from within the runtime.
*/
v54113: new StorageType('System.Events', 'Default', [], sts.array(() => v54113.EventRecord)) as EventsV54113,
}

/**
Expand Down Expand Up @@ -1431,6 +1442,21 @@ export interface EventsV54112 {
get(block: Block): Promise<(v54112.EventRecord[] | undefined)>
}

/**
* Events deposited for the current block.
*
* NOTE: The item is unbound and should therefore never be read on chain.
* It could otherwise inflate the PoV size of a block.
*
* Events have a large in-memory size. Box the events to not go out-of-memory
* just in case someone still reads them from within the runtime.
*/
export interface EventsV54113 {
is(block: RuntimeCtx): boolean
getDefault(block: Block): v54113.EventRecord[]
get(block: Block): Promise<(v54113.EventRecord[] | undefined)>
}

export const eventCount = {
/**
* The number of events in the `Events<T>` list.
Expand Down
Loading

0 comments on commit 8e5559b

Please sign in to comment.