Skip to content

Commit

Permalink
V1 hot fix (#208)
Browse files Browse the repository at this point in the history
* fixing logs and changing performance to summary

* fixing edgecase for log

* fixing the dashboard display for initialized keys

* fixing linting

* fixing tests
  • Loading branch information
james-prysm authored Nov 4, 2021
1 parent ad34028 commit 3862400
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 26 deletions.
6 changes: 3 additions & 3 deletions src/app/modules/core/mocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import {
ChainHead,
ValidatorParticipationResponse,
ValidatorPerformanceResponse,
ValidatorSummaryResponse,
ValidatorQueue,
Validators,
Validators_ValidatorContainer,
Expand Down Expand Up @@ -537,7 +537,7 @@ export const Mocks: IMocks = {
votedEther: '1136975000000000',
} as ValidatorParticipation,
} as ValidatorParticipationResponse,
'/v2/validator/beacon/performance': {
'/v2/validator/beacon/summary': {
currentEffectiveBalances: ['31000000000', '31000000000', '31000000000'],
correctlyVotedHead: [true, true, false],
correctlyVotedSource: [true, true, false],
Expand All @@ -553,7 +553,7 @@ export const Mocks: IMocks = {
balancesAfterEpochTransition: ['31200823019', '31216596259', '31204412779'],
publicKeys: mockPublicKeys,
missingValidators: [],
} as ValidatorPerformanceResponse,
} as ValidatorSummaryResponse,
'/v2/validator/beacon/queue': {
churnLimit: 4,
activationPublicKeys: [mockPublicKeys[0], mockPublicKeys[1]],
Expand Down
8 changes: 4 additions & 4 deletions src/app/modules/core/services/logs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class LogsService {

validatorLogs(): Observable<string> {
// Use mock data in development mode.
if (!this.environmenter.env.production) {
if (this.environmenter.env.mockInterceptor) {
const data = mockValidatorLogs.split('\n').map((v, _) => v);
return of(data).pipe(
mergeAll(),
Expand All @@ -27,14 +27,14 @@ export class LogsService {
);
}
return stream(`${this.apiUrl}/health/logs/validator/stream`).pipe(
map((obj: any) => obj.result.logs),
map((obj: any) => obj ? obj.logs : ''),
mergeAll(),
);
}

beaconLogs(): Observable<string> {
// Use mock data in development mode.
if (!this.environmenter.env.production) {
if (this.environmenter.env.mockInterceptor) {
const data = mockBeaconLogs.split('\n').map((v, _) => v);
return of(data).pipe(
mergeAll(),
Expand All @@ -44,7 +44,7 @@ export class LogsService {
);
}
return stream(`${this.apiUrl}/health/logs/beacon/stream`).pipe(
map((obj: any) => obj.result.logs),
map((obj: any) => obj ? obj.logs : ''),
mergeAll(),
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/app/modules/core/services/validator.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import range from 'src/app/modules/core/utils/range';
import { WalletService } from './wallet.service';

import {
ValidatorBalances, ValidatorPerformanceResponse, Validators,
ValidatorBalances, ValidatorSummaryResponse, Validators,
} from 'src/app/proto/eth/v1alpha1/beacon_chain';
import { ListAccountsResponse, LogsEndpointResponse, VersionResponse } from 'src/app/proto/validator/accounts/v2/web_api';
import { EnvironmenterService } from './environmenter.service';
Expand All @@ -30,14 +30,14 @@ export class ValidatorService {
share(),
);

performance$: Observable<ValidatorPerformanceResponse & ValidatorBalances> = this.walletService.validatingPublicKeys$.pipe(
performance$: Observable<ValidatorSummaryResponse & ValidatorBalances> = this.walletService.validatingPublicKeys$.pipe(
switchMap((publicKeys: string[]) => {
let params = `?publicKeys=`;
publicKeys.forEach((key, _) => {
params += `${this.encodePublicKey(key)}&publicKeys=`;
});
const balances = this.balances(publicKeys, 0, publicKeys.length);
const httpReq = this.http.get<ValidatorPerformanceResponse>(`${this.apiUrl}/beacon/performance${params}`);
const httpReq = this.http.get<ValidatorSummaryResponse>(`${this.apiUrl}/beacon/summary${params}`);
return zip(httpReq, balances).pipe(
map(([perf, bals]) => {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { MockService } from 'ng-mocks';
import { SharedModule } from '../../../shared/shared.module';
import {
ValidatorBalances,
ValidatorPerformanceResponse,
ValidatorSummaryResponse,
} from 'src/app/proto/eth/v1alpha1/beacon_chain';
import { ValidatorPerformanceListComponent } from './validator-performance-list.component';
import { of } from 'rxjs';
Expand All @@ -30,7 +30,7 @@ describe('ValidatorListComponent', () => {
balances: [],
nextPageToken: '',
totalSize: 0,
} as ValidatorPerformanceResponse & ValidatorBalances);
} as ValidatorSummaryResponse & ValidatorBalances);
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { MatSort } from '@angular/material/sort';
import { MatTableDataSource } from '@angular/material/table';

import { BigNumber } from 'ethers';
import { ValidatorPerformanceResponse } from 'src/app/proto/eth/v1alpha1/beacon_chain';
import { ValidatorSummaryResponse } from 'src/app/proto/eth/v1alpha1/beacon_chain';
import { throwError } from 'rxjs';
import { catchError, map, take, tap, takeUntil, filter } from 'rxjs/operators';
import { ValidatorService } from '../../../core/services/validator.service';
Expand Down Expand Up @@ -57,7 +57,7 @@ export class ValidatorPerformanceListComponent
super();
this.validatorService.performance$
.pipe(
map((performance: ValidatorPerformanceResponse) => {
map((performance: ValidatorSummaryResponse) => {
const list: ValidatorListItem[] = [];
if (performance) {
for (let i = 0; i < performance.publicKeys.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</mat-icon>
</div>
<div class="text-primary font-semibold text-2xl mt-2">
{{perf.totalBalance | number: '1.4-4'}} ETH
{{perf.totalBalance ? (perf.totalBalance | number: '1.4-4')+'ETH' : 'N/A'}}
</div>
</div>
<div>
Expand Down Expand Up @@ -53,7 +53,7 @@
</mat-icon>
</div>
<div class="text-primary font-semibold text-2xl mt-2">
{{perf.correctlyVotedHeadPercent | number: '1.2-2'}}%
{{perf.correctlyVotedHeadPercent ? (perf.correctlyVotedHeadPercent | number: '1.2-2')+'%' : 'N/A'}}
</div>
</div>
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ValidatorPerformanceSummaryComponent, PerformanceData } from './validat
import { ValidatorService } from 'src/app/modules/core/services/validator.service';
import { MockService } from 'ng-mocks';
import { of } from 'rxjs';
import { ValidatorBalances, ValidatorPerformanceResponse } from 'src/app/proto/eth/v1alpha1/beacon_chain';
import { ValidatorBalances, ValidatorSummaryResponse } from 'src/app/proto/eth/v1alpha1/beacon_chain';
import { SharedModule } from 'src/app/modules/shared/shared.module';
import { WalletService } from 'src/app/modules/core/services/wallet.service';
import { BeaconNodeService } from 'src/app/modules/core/services/beacon-node.service';
Expand All @@ -30,13 +30,23 @@ describe('ValidatorPerformanceSummaryComponent', () => {
balancesBeforeEpochTransition: ['31000000000', '31000000000'],
balancesAfterEpochTransition: ['32000000000', '32000000000'],
epoch: '',
balances: [],
balances: [{

publicKey: '0xa2b5aaad9c6efefe7bb9b1243a043404f3362937cfb6b31833929833173f476630ea2cfeb0d9ddf15f97ca8685948820',


index: 0,

balance: '2000000000',

status: ''
}],
nextPageToken: '',
totalSize: 0,
inclusionSlots: [],
publicKeys: [],
missingValidators: [],
} as ValidatorPerformanceResponse & ValidatorBalances;
} as ValidatorSummaryResponse & ValidatorBalances;

service['performance$'] = of(defaultPerformanceData);
walletService['validatingPublicKeys$'] = of([] as string[]);
Expand Down Expand Up @@ -75,7 +85,7 @@ describe('ValidatorPerformanceSummaryComponent', () => {

describe('transformPerformanceData', () => {
it('should properly determine average effective balance', () => {
expect(transformedData.totalBalance).toEqual('0.0');
expect(transformedData.totalBalance).toEqual('2.0');
});
it('should properly determine average inclusion distance', () => {
expect(transformedData.averageInclusionDistance).toEqual(1.5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { formatEther, formatUnits, parseUnits } from 'ethers/lib/utils';

import { GWEI_PER_ETHER, FAR_FUTURE_EPOCH } from 'src/app/modules/core/constants';
import { BeaconNodeService } from 'src/app/modules/core/services/beacon-node.service';
import { ValidatorBalances, ValidatorPerformanceResponse } from 'src/app/proto/eth/v1alpha1/beacon_chain';
import { ValidatorBalances, ValidatorSummaryResponse } from 'src/app/proto/eth/v1alpha1/beacon_chain';
import { WalletService } from 'src/app/modules/core/services/wallet.service';

export interface PerformanceData {
Expand Down Expand Up @@ -59,7 +59,7 @@ export class ValidatorPerformanceSummaryComponent {
map(this.transformPerformanceData.bind(this)),
);

private transformPerformanceData(perf: ValidatorPerformanceResponse & ValidatorBalances): PerformanceData {
private transformPerformanceData(perf: ValidatorSummaryResponse & ValidatorBalances): PerformanceData {
const totalBalance = perf.balances.reduce(
(prev, curr) => {
if (curr && curr.balance) {
Expand Down Expand Up @@ -100,10 +100,10 @@ export class ValidatorPerformanceSummaryComponent {
this.loading = false;
return {
averageInclusionDistance,
correctlyVotedHeadPercent: (votedHeadPercentage * 100),
correctlyVotedHeadPercent: votedHeadPercentage !== -1 ? (votedHeadPercentage * 100) : null,
overallScore,
recentEpochGains,
totalBalance: formatUnits(totalBalance, 'gwei').toString(),
totalBalance: perf.balances && perf.balances.length !== 0 ? formatUnits(totalBalance, 'gwei').toString() : null,
} as PerformanceData;
}

Expand Down
4 changes: 2 additions & 2 deletions src/app/proto/eth/v1alpha1/beacon_chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ export interface ActiveSetChanges {
ejectedIndices: number[];
}

export interface ValidatorPerformanceRequest {
export interface ValidatorSummaryRequest {
/**
* A list of 48 byte validator public keys.
*/
Expand All @@ -473,7 +473,7 @@ export interface ValidatorPerformanceRequest {
indices: number[];
}

export interface ValidatorPerformanceResponse {
export interface ValidatorSummaryResponse {
/**
* A list of validator effective balances mapped 1-to-1 with the request's
* public keys.
Expand Down

0 comments on commit 3862400

Please sign in to comment.