diff --git a/.vscode/settings.json b/.vscode/settings.json index 1ae2cbe7..e129c337 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -16,6 +16,14 @@ "package", "tooling" ], - "cSpell.words": ["comrads", "netuid", "polkadot", "uid", "uids"], + "cSpell.words": [ + "comrads", + "nanos", + "netuid", + "perc", + "polkadot", + "uid", + "uids" + ], "eslint.rules.customizations": [{ "rule": "*", "severity": "warn" }] } diff --git a/apps/commune-worker/src/workers/weight-aggregator.ts b/apps/commune-worker/src/workers/weight-aggregator.ts index 2987a1aa..6e8c7293 100644 --- a/apps/commune-worker/src/workers/weight-aggregator.ts +++ b/apps/commune-worker/src/workers/weight-aggregator.ts @@ -42,6 +42,8 @@ export async function weightCompilerTask(api: ApiPromise) { const finalWeights = calcFinalWeights(stakeOutMap, weightMap); const normalizedWeights = normalizeModuleWeights(finalWeights); + // TODO: normalize weights with (sum(weights) == 100%) for DB + console.log(normalizedWeights); const uids: number[] = []; @@ -70,7 +72,7 @@ function setWeights( assert(api.tx.subspaceModule != undefined); assert(api.tx.subspaceModule.setWeights != undefined); const tx = api.tx.subspaceModule.setWeights(netuid, uids, weights); - // TODO + // TODO: send weights to chain return tx; } diff --git a/packages/db/src/schema.ts b/packages/db/src/schema.ts index a86fe961..920b7805 100644 --- a/packages/db/src/schema.ts +++ b/packages/db/src/schema.ts @@ -387,3 +387,35 @@ export const governanceNotificationSchema = createTable( notifiedAt: timestamp("notified_at").defaultNow(), }, ); + +export const computedModuleWeights = createTable("computed_weights", { + id: serial("id").primaryKey(), + + atBlock: integer("at_block").notNull(), + + moduleKey: ss58Address("module_key") + .notNull() + .references(() => moduleData.moduleKey), + + // Aggregated weights measured in nanos + stakeWeight: bigint("stake_weight", { mode: "bigint" }).notNull(), + // Normalized aggregated weights (100% sum) + percWeight: real("perc_weight").notNull(), + + createdAt: timestamp("created_at").defaultNow().notNull(), +}); + +export const computedSubnetWeights = createTable("computed_subnet_weights", { + id: serial("id").primaryKey(), + + atBlock: integer("at_block").notNull(), + + netuid: integer("netuid").notNull().references(() => subnetDataSchema.netuid), + + // Aggregated weights measured in nanos + stakeWeight: integer("stake_weight").notNull(), + // Normalized aggregated weights (100% sum) + percWeight: real("perc_weight").notNull(), + + createdAt: timestamp("created_at").defaultNow().notNull(), +});