Skip to content

Commit

Permalink
Merge pull request #2943 from w3f/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
ironoa authored May 22, 2024
2 parents 5bd8527 + d6a764f commit 193b10a
Show file tree
Hide file tree
Showing 14 changed files with 163 additions and 132 deletions.
2 changes: 1 addition & 1 deletion apps/1kv-backend/templates/kusama-otv-backend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spec:
source:
repoURL: https://w3f.github.io/helm-charts/
chart: otv-backend
targetRevision: v3.2.2
targetRevision: v3.3.0
plugin:
env:
- name: HELM_VALUES
Expand Down
2 changes: 1 addition & 1 deletion apps/1kv-backend/templates/polkadot-otv-backend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spec:
source:
repoURL: https://w3f.github.io/helm-charts/
chart: otv-backend
targetRevision: v3.2.2
targetRevision: v3.3.0
plugin:
env:
- name: HELM_VALUES
Expand Down
4 changes: 2 additions & 2 deletions charts/otv-backend/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
description: 1K Validators Backend
name: otv-backend
version: v3.2.2
appVersion: v3.2.2
version: v3.3.0
appVersion: v3.3.0
apiVersion: v2
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"@bull-board/koa": "^5.15.0",
"@koa/router": "^12.0.1",
"@octokit/rest": "^20.0.2",
"@polkadot/api": "^11.0.2",
"@polkadot/api": "^11.1.1",
"@polkadot/keyring": "^12.6.2",
"@types/cron": "^2.4.0",
"@types/jest": "^29.5.12",
Expand Down
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@1kv/common",
"version": "3.2.2",
"version": "3.3.0",
"description": "Services for running the Thousand Validator Program.",
"main": "build/index.js",
"types": "build/index.d.ts",
Expand Down
35 changes: 34 additions & 1 deletion packages/common/src/chaindata/chaindata.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ApiPromise } from "@polkadot/api";
import { ApiPromise, WsProvider } from "@polkadot/api";
import ApiHandler, { apiLabel } from "../ApiHandler/ApiHandler";
import logger from "../logger";
import { NumberResult } from "../types";
Expand Down Expand Up @@ -71,12 +71,45 @@ export const chaindataLabel = { label: "Chaindata" };
export class ChainData {
public handler: ApiHandler;
public api: ApiPromise | null;
public apiPeople: ApiPromise | null;

constructor(handler: ApiHandler) {
this.handler = handler;
this.api = handler.getApi();
this.setApiPeople();
}

setApiPeople = async (): Promise<void> => {
if (!(await this.api.rpc.system.chain()).toLowerCase().includes("kusama"))
return;

const provider = new WsProvider("wss://kusama-people-rpc.polkadot.io");
this.apiPeople = await ApiPromise.create({ provider: provider });
if (this.apiPeople) {
this.apiPeople.on("error", (error) => {
if (
error.toString().includes("FATAL") ||
JSON.stringify(error).includes("FATAL")
) {
logger.error("The API had a FATAL error... exiting!");
process.exit(1);
}
});
}
await this.apiPeople.isReadyOrError;

const [chain, nodeName, nodeVersion] = await Promise.all([
this.apiPeople.rpc.system.chain(),
this.apiPeople.rpc.system.name(),
this.apiPeople.rpc.system.version(),
]);
logger.info(
`You are connected to chain ${chain} using ${nodeName} v${nodeVersion}`,
apiLabel,
);
return;
};

checkApiConnection = async (retries = 0): Promise<boolean> => {
// Check if the API is already connected
if (this.handler.getApi()?.isConnected) {
Expand Down
48 changes: 23 additions & 25 deletions packages/common/src/chaindata/queries/Identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ export const hasIdentity = async (
account: string,
): Promise<[boolean, boolean]> => {
try {
if (!(await chaindata.checkApiConnection())) {
const api = chaindata.apiPeople ? chaindata.apiPeople : chaindata.api;

if (!api?.isConnected) {
return [false, false];
}
let identity = await chaindata.api?.query.identity.identityOf(account);
let identity = await api.query.identity.identityOf(account);
if (!identity || !identity.isSome) {
// check if it's a sub
const superOf = await chaindata.api?.query.identity.superOf(account);
const superOf = await api.query.identity.superOf(account);
if (superOf && superOf.isSome) {
identity = await chaindata.api?.query.identity.identityOf(
superOf.unwrap()[0],
);
identity = await api.query.identity.identityOf(superOf.unwrap()[0]);
}
}
const identityInfo = await chaindata.api?.derive.accounts.identity(account);
const identityInfo = await api.derive.accounts.identity(account);
if (!identityInfo) return null;
let verified = false;
if (identity && identity.isSome) {
Expand All @@ -33,7 +33,7 @@ export const hasIdentity = async (

return [identity ? identity.isSome : false, verified];
} catch (e) {
await handleError(chaindata, e, "hasIdentity");
if (!chaindata.apiPeople) await handleError(chaindata, e, "hasIdentity");
return [false, true];
}
};
Expand All @@ -43,26 +43,26 @@ export const getFormattedIdentity = async (
addr: string,
): Promise<Identity | null> => {
try {
if (!(await chaindata.checkApiConnection())) {
const api = chaindata.apiPeople ? chaindata.apiPeople : chaindata.api;
if (!api?.isConnected) {
return null;
}
let identity: Identity | null = null;
let verified = false;
const subAccounts: { name: string; address: string }[] = [];

const hasId = await chaindata.api?.derive.accounts.hasIdentity(addr);
const hasId = await api.derive.accounts.hasIdentity(addr);
if (!hasId || !hasId.hasIdentity) return null;

const identityInfo = await chaindata.api?.derive.accounts.identity(addr);
const identityInfo = await api.derive.accounts.identity(addr);
if (!identityInfo) return null;

const hasSubs = await chaindata.api?.query.identity.subsOf(addr);
const hasSubs = await api.query.identity.subsOf(addr);
if (hasSubs && hasSubs[1].length > 0) {
for (const subaccountAddress of hasSubs[1]) {
const subAccountIdentity =
await chaindata.api?.derive.accounts.identity(
subaccountAddress.toString(),
);
const subAccountIdentity = await api.derive.accounts.identity(
subaccountAddress.toString(),
);
if (subAccountIdentity) {
const subAccount: { name: string; address: string } = {
name: subAccountIdentity.display || "",
Expand Down Expand Up @@ -97,21 +97,18 @@ export const getFormattedIdentity = async (
}

if (parent) {
const superIdentity =
await chaindata.api?.derive.accounts.identity(parent);
const superIdentity = await api.derive.accounts.identity(parent);
if (superIdentity) {
const superAccount: { name: string; address: string } = {
name: superIdentity.display || "",
address: parent.toString(),
};
const subIdentities =
await chaindata.api?.query.identity.subsOf(parent);
const subIdentities = await api.query.identity.subsOf(parent);
if (subIdentities && subIdentities[1].length > 0) {
for (const subaccountAddress of subIdentities[1]) {
const subAccountIdentity =
await chaindata.api?.derive.accounts.identity(
subaccountAddress.toString(),
);
const subAccountIdentity = await api.derive.accounts.identity(
subaccountAddress.toString(),
);
if (subAccountIdentity) {
const subAccount: { name: string; address: string } = {
name: subAccountIdentity.display || "",
Expand Down Expand Up @@ -158,7 +155,8 @@ export const getFormattedIdentity = async (

return identity;
} catch (e) {
await handleError(chaindata, e, "getFormattedIdentity");
if (!chaindata.apiPeople)
await handleError(chaindata, e, "getFormattedIdentity");
return null;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const individualEraPointsJob = async (
const data = await chaindata.getTotalEraPoints(eraIndex);
if (
data &&
data.era &&
data.era == eraIndex &&
data.total &&
data.validators &&
data.validators.length > 0
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@1kv/core",
"version": "3.2.2",
"version": "3.3.0",
"description": "Services for running the Thousand Validator Program.",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/gateway/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@1kv/gateway",
"version": "3.2.2",
"version": "3.3.0",
"description": "Services for running the Thousand Validator Program.",
"main": "build/index.js",
"types": "build/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/scorekeeper-status-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@1kv/scorekeeper-status-ui",
"private": true,
"version": "3.2.2",
"version": "3.3.0",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
2 changes: 1 addition & 1 deletion packages/telemetry/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@1kv/telemetry",
"version": "3.2.2",
"version": "3.3.0",
"description": "Services for running the Thousand Validator Program.",
"main": "build/index.js",
"types": "build/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/worker/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@1kv/worker",
"version": "3.2.2",
"version": "3.3.0",
"description": "Services for running the Thousand Validator Program.",
"main": "build/index.js",
"types": "build/index.d.ts",
Expand Down
Loading

0 comments on commit 193b10a

Please sign in to comment.