Skip to content

Commit

Permalink
wip: schemas for aggregated weights
Browse files Browse the repository at this point in the history
  • Loading branch information
steinerkelvin committed Oct 10, 2024
1 parent eac1377 commit bb05922
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
10 changes: 9 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" }]
}
4 changes: 3 additions & 1 deletion apps/commune-worker/src/workers/weight-aggregator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand Down Expand Up @@ -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;
}

Expand Down
32 changes: 32 additions & 0 deletions packages/db/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
});

0 comments on commit bb05922

Please sign in to comment.