Skip to content

Commit

Permalink
Merge pull request #37 from klayrHQ/validator-sync
Browse files Browse the repository at this point in the history
validator sync
  • Loading branch information
Theezr authored Aug 26, 2024
2 parents 3231b8d + 1f22fcd commit f24d029
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/validator/validator.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export class ValidatorService {
// TODO: Locking to avoid race conditions. Might change to seperate service if needed
private lockStore = new Map<string, boolean>();
private logger = new Logger(ValidatorService.name);
// TODO: Testing if this solves the validator syncing and stil gives correct ranks
private isUpdatingValidators = false;

constructor(
private readonly state: StateService,
Expand Down Expand Up @@ -127,6 +129,9 @@ export class ValidatorService {

public async updateValidatorRanks() {
this.logger.log('Updating validator ranks');
if (this.isUpdatingValidators) return this.logger.log('Already updating validators');
this.isUpdatingValidators = true;

const validators = await this.validatorRepoService.getAllValidators();

// Sorting validators with the same weight by address(bytes)
Expand All @@ -149,6 +154,8 @@ export class ValidatorService {
data: { rank: validator.rank, status: validatorStatus },
});
}

this.isUpdatingValidators = false;
}

@OnEvent(GatewayEvents.UPDATE_BLOCK_GENERATOR)
Expand Down

0 comments on commit f24d029

Please sign in to comment.