Skip to content

Commit 0f124ca

Browse files
Merge pull request #131 from xai-foundation/develop
Develop
2 parents c195854 + 643c253 commit 0f124ca

File tree

1 file changed

+48
-13
lines changed

1 file changed

+48
-13
lines changed

packages/core/src/operator/operatorRuntime.ts

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import {
1616
submitMultipleAssertions,
1717
claimRewardsBulk,
1818
getUserInteractedPools,
19-
getUserStakedKeysOfPool
19+
getUserStakedKeysOfPool,
20+
checkKycStatus
2021
} from "../index.js";
2122
import { retry } from "../index.js";
2223
import axios from "axios";
@@ -64,7 +65,7 @@ let cachedSigner: ethers.Signer;
6465
let cachedLogger: (log: string) => void;
6566
let safeStatusCallback: () => void;
6667
let onAssertionMissMatchCb: (publicNodeData: PublicNodeBucketInformation | undefined, challenge: Challenge, message: string) => void;
67-
let nodeLicenseIds: bigint[] = [];
68+
const nodeLicenseIds: bigint[] = [];
6869
const mintTimestamps: { [nodeLicenseId: string]: bigint } = {};
6970
const nodeLicenseStatusMap: NodeLicenseStatusMap = new Map();
7071
const challengeNumberMap: { [challengeNumber: string]: boolean } = {};
@@ -436,11 +437,43 @@ async function processClosedChallenges(challengeId: bigint) {
436437
challengeCache[challengeId.toString()] = {};
437438
}
438439

440+
const beforeStatus: { [key: string]: string | undefined } = {}
441+
439442
for (const nodeLicenseId of nodeLicenseIds) {
440-
const beforeStatus = nodeLicenseStatusMap.get(nodeLicenseId)?.status;
443+
beforeStatus[nodeLicenseId.toString()] = nodeLicenseStatusMap.get(nodeLicenseId)?.status;
441444
updateNodeLicenseStatus(nodeLicenseId, NodeLicenseStatus.QUERYING_FOR_UNCLAIMED_SUBMISSIONS);
445+
safeStatusCallback();
446+
447+
cachedLogger(`Checking KYC status of '${nodeLicenseStatusMap.get(nodeLicenseId)?.ownerPublicKey}' for Sentry Key '${nodeLicenseId}'.`);
448+
updateNodeLicenseStatus(nodeLicenseId, `Checking KYC Status`);
449+
safeStatusCallback();
450+
let isKycApproved: boolean = isKYCMap[nodeLicenseId.toString()];
451+
if (!isKYCMap[nodeLicenseId.toString()]) {
452+
try {
453+
[{ isKycApproved }] = await retry(async () => await checkKycStatus([nodeLicenseStatusMap.get(nodeLicenseId)!.ownerPublicKey]));
454+
} catch (error: any) {
455+
cachedLogger(`Error checking KYC for Sentry Key ${nodeLicenseId} - ${error && error.message ? error.message : error}`);
456+
updateNodeLicenseStatus(nodeLicenseId, `Failed to check KYC status`);
457+
safeStatusCallback();
458+
continue;
459+
}
460+
}
461+
462+
if (!isKycApproved) {
463+
cachedLogger(`Checked KYC status of '${nodeLicenseStatusMap.get(nodeLicenseId)?.ownerPublicKey}' for Sentry Key '${nodeLicenseId}'. It was not KYC'd and not able to claim the reward.`);
464+
updateNodeLicenseStatus(nodeLicenseId, `Cannot Claim, Failed KYC`);
465+
safeStatusCallback();
466+
continue;
467+
468+
} else {
469+
isKYCMap[nodeLicenseId.toString().toString()] = true;
470+
cachedLogger(`Requesting esXAI reward for challenge '${challengeId}'.`);
471+
updateNodeLicenseStatus(nodeLicenseId, `Requesting esXAI reward for challenge '${challengeId}'.`);
472+
safeStatusCallback();
473+
}
442474

443475
try {
476+
444477
if (!challengeCache[challengeId.toString()][nodeLicenseId.toString()]) {
445478
cachedLogger(`Checking for unclaimed rewards on Sentry Key '${nodeLicenseId}'.`);
446479
const submissions = await getSubmissionsForChallenges([challengeId], nodeLicenseId);
@@ -457,7 +490,6 @@ async function processClosedChallenges(challengeId: bigint) {
457490
eligibleForPayout: false
458491
});
459492
}
460-
461493
}
462494

463495
let submissionStatus = challengeCache[challengeId.toString()][nodeLicenseId.toString()];
@@ -473,11 +505,6 @@ async function processClosedChallenges(challengeId: bigint) {
473505
} catch (error: any) {
474506
cachedLogger(`Error processing submissions for Sentry Key ${nodeLicenseId} - ${error && error.message ? error.message : error}`);
475507
}
476-
477-
if (beforeStatus) {
478-
updateNodeLicenseStatus(nodeLicenseId, beforeStatus);
479-
safeStatusCallback();
480-
}
481508
}
482509

483510
// Iterate over the map and call processClaimForChallenge for each challenge with its unique list of eligible nodeLicenseIds
@@ -491,17 +518,20 @@ async function processClosedChallenges(challengeId: bigint) {
491518
claimed: true,
492519
eligibleForPayout: true,
493520
});
494-
})
495521

522+
if (beforeStatus[key.toString()]) {
523+
updateNodeLicenseStatus(key, beforeStatus[key.toString()]!);
524+
}
525+
});
526+
527+
safeStatusCallback();
496528
}
497529
}
498530
}
499531

500532
// start a listener for new challenges
501533
async function listenForChallengesCallback(challengeNumber: bigint, challenge: Challenge, event?: any) {
502534

503-
//TODO on every submit and on every claim we need to check if the key is still in the pool
504-
505535
if (event && challenge.rollupUsed === config.rollupAddress) {
506536
compareWithCDN(challenge)
507537
.then(({ publicNodeBucket, error }) => {
@@ -663,7 +693,12 @@ export async function operatorRuntime(
663693
});
664694
});
665695

666-
nodeLicenseIds = [...nodeLicenseIds, ...licensesOfOwner];
696+
for (const licenseId of licensesOfOwner) {
697+
if (!nodeLicenseIds.includes(licenseId)) {
698+
nodeLicenseIds.push(licenseId);
699+
}
700+
}
701+
667702
logFunction(`Fetched ${licensesOfOwner.length} node licenses for owner ${owner}.`);
668703
}
669704

0 commit comments

Comments
 (0)