Skip to content

Commit

Permalink
chore: minor refactoring
Browse files Browse the repository at this point in the history
1. Replace `reduce` in the `CriticalAlerts` service with for/of cycle.

2. Fix lint errors.
  • Loading branch information
AlexanderLukin committed Dec 19, 2024
1 parent 561972e commit 9fda51b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
9 changes: 4 additions & 5 deletions src/common/alertmanager/critical-alerts.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ export class CriticalAlertsService {
this.storage.getUserNodeOperatorsStats(epoch - 1),
]);

const alerts = moduleIndexes.reduce((totalAlerts, moduleIndex) => {
const alerts = [];
for (const moduleIndex of moduleIndexes) {
const nosStatsForModule = nosStats.filter((o) => +o.val_nos_module_id === moduleIndex);
const operatorsForModule = this.operators.filter((o) => o.module === moduleIndex);

totalAlerts.push(
alerts.push(
...[
new CriticalMissedAttestations(
this.config,
Expand All @@ -81,9 +82,7 @@ export class CriticalAlertsService {
new CriticalSlashing(this.config, this.storage, operatorsForModule, moduleIndex, nosStatsForModule, prevNosStats),
],
);

return totalAlerts;
}, []);
}

for (const alert of alerts) {
const toSend = await alert.toSend(epoch);
Expand Down
6 changes: 3 additions & 3 deletions src/common/consensus-provider/consensus-provider.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class ConsensusProviderService {
{
maxRetries: this.config.get('CL_API_GET_BLOCK_INFO_MAX_RETRIES'),
useFallbackOnResolved: (r) => {
if (this.workingMode === WorkingMode.Finalized && r.hasOwnProperty('finalized') && !r.finalized) {
if (this.workingMode === WorkingMode.Finalized && r.finalized != null && !r.finalized) {
this.logger.error(`getLatestBlockHeader: slot [${r.data.header.message.slot}] is not finalized`);
return true;
}
Expand Down Expand Up @@ -241,7 +241,7 @@ export class ConsensusProviderService {
{
maxRetries: this.config.get('CL_API_GET_BLOCK_INFO_MAX_RETRIES'),
useFallbackOnResolved: (r) => {
if (this.workingMode === WorkingMode.Finalized && blockId !== 'head' && r.hasOwnProperty('finalized') && !r.finalized) {
if (this.workingMode === WorkingMode.Finalized && blockId !== 'head' && r.finalized != null && !r.finalized) {
this.logger.error(`getBlockInfo: slot [${r.data.message.slot}] is not finalized`);
return true;
}
Expand Down Expand Up @@ -280,7 +280,7 @@ export class ConsensusProviderService {
public async getSyncCommitteeInfo(stateId: StateId, epoch: Epoch): Promise<SyncCommitteeInfo> {
return await this.retryRequest(async (apiURL: string) => this.apiGet(apiURL, this.endpoints.syncCommittee(stateId, epoch)), {
useFallbackOnResolved: (r) => {
if (this.workingMode === WorkingMode.Finalized && stateId !== 'head' && r.hasOwnProperty('finalized') && !r.finalized) {
if (this.workingMode === WorkingMode.Finalized && stateId !== 'head' && r.finalized != null && !r.finalized) {
this.logger.error(`getSyncCommitteeInfo: state ${stateId} for epoch ${epoch} is not finalized`);
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions src/common/functions/urljoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ function normalize(strArray: string[]) {

if (i > 0) {
// Removing the starting slashes for each component but the first.
component = component.replace(/^[\/]+/, '');
component = component.replace(/^[/]+/, '');
}
if (i < strArray.length - 1) {
// Removing the ending slashes for each component but the last.
component = component.replace(/[\/]+$/, '');
component = component.replace(/[/]+$/, '');
} else {
// For the last component we will combine multiple slashes to a single one.
component = component.replace(/[\/]+$/, '/');
component = component.replace(/[/]+$/, '/');
}

resultArray.push(component);
Expand Down

0 comments on commit 9fda51b

Please sign in to comment.