@@ -16,7 +16,8 @@ import {
16
16
submitMultipleAssertions ,
17
17
claimRewardsBulk ,
18
18
getUserInteractedPools ,
19
- getUserStakedKeysOfPool
19
+ getUserStakedKeysOfPool ,
20
+ checkKycStatus
20
21
} from "../index.js" ;
21
22
import { retry } from "../index.js" ;
22
23
import axios from "axios" ;
@@ -64,7 +65,7 @@ let cachedSigner: ethers.Signer;
64
65
let cachedLogger : ( log : string ) => void ;
65
66
let safeStatusCallback : ( ) => void ;
66
67
let onAssertionMissMatchCb : ( publicNodeData : PublicNodeBucketInformation | undefined , challenge : Challenge , message : string ) => void ;
67
- let nodeLicenseIds : bigint [ ] = [ ] ;
68
+ const nodeLicenseIds : bigint [ ] = [ ] ;
68
69
const mintTimestamps : { [ nodeLicenseId : string ] : bigint } = { } ;
69
70
const nodeLicenseStatusMap : NodeLicenseStatusMap = new Map ( ) ;
70
71
const challengeNumberMap : { [ challengeNumber : string ] : boolean } = { } ;
@@ -436,11 +437,43 @@ async function processClosedChallenges(challengeId: bigint) {
436
437
challengeCache [ challengeId . toString ( ) ] = { } ;
437
438
}
438
439
440
+ const beforeStatus : { [ key : string ] : string | undefined } = { }
441
+
439
442
for ( const nodeLicenseId of nodeLicenseIds ) {
440
- const beforeStatus = nodeLicenseStatusMap . get ( nodeLicenseId ) ?. status ;
443
+ beforeStatus [ nodeLicenseId . toString ( ) ] = nodeLicenseStatusMap . get ( nodeLicenseId ) ?. status ;
441
444
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
+ }
442
474
443
475
try {
476
+
444
477
if ( ! challengeCache [ challengeId . toString ( ) ] [ nodeLicenseId . toString ( ) ] ) {
445
478
cachedLogger ( `Checking for unclaimed rewards on Sentry Key '${ nodeLicenseId } '.` ) ;
446
479
const submissions = await getSubmissionsForChallenges ( [ challengeId ] , nodeLicenseId ) ;
@@ -457,7 +490,6 @@ async function processClosedChallenges(challengeId: bigint) {
457
490
eligibleForPayout : false
458
491
} ) ;
459
492
}
460
-
461
493
}
462
494
463
495
let submissionStatus = challengeCache [ challengeId . toString ( ) ] [ nodeLicenseId . toString ( ) ] ;
@@ -473,11 +505,6 @@ async function processClosedChallenges(challengeId: bigint) {
473
505
} catch ( error : any ) {
474
506
cachedLogger ( `Error processing submissions for Sentry Key ${ nodeLicenseId } - ${ error && error . message ? error . message : error } ` ) ;
475
507
}
476
-
477
- if ( beforeStatus ) {
478
- updateNodeLicenseStatus ( nodeLicenseId , beforeStatus ) ;
479
- safeStatusCallback ( ) ;
480
- }
481
508
}
482
509
483
510
// 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) {
491
518
claimed : true ,
492
519
eligibleForPayout : true ,
493
520
} ) ;
494
- } )
495
521
522
+ if ( beforeStatus [ key . toString ( ) ] ) {
523
+ updateNodeLicenseStatus ( key , beforeStatus [ key . toString ( ) ] ! ) ;
524
+ }
525
+ } ) ;
526
+
527
+ safeStatusCallback ( ) ;
496
528
}
497
529
}
498
530
}
499
531
500
532
// start a listener for new challenges
501
533
async function listenForChallengesCallback ( challengeNumber : bigint , challenge : Challenge , event ?: any ) {
502
534
503
- //TODO on every submit and on every claim we need to check if the key is still in the pool
504
-
505
535
if ( event && challenge . rollupUsed === config . rollupAddress ) {
506
536
compareWithCDN ( challenge )
507
537
. then ( ( { publicNodeBucket, error } ) => {
@@ -663,7 +693,12 @@ export async function operatorRuntime(
663
693
} ) ;
664
694
} ) ;
665
695
666
- nodeLicenseIds = [ ...nodeLicenseIds , ...licensesOfOwner ] ;
696
+ for ( const licenseId of licensesOfOwner ) {
697
+ if ( ! nodeLicenseIds . includes ( licenseId ) ) {
698
+ nodeLicenseIds . push ( licenseId ) ;
699
+ }
700
+ }
701
+
667
702
logFunction ( `Fetched ${ licensesOfOwner . length } node licenses for owner ${ owner } .` ) ;
668
703
}
669
704
0 commit comments