Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch indexes locally #252

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions packages/brain/src/calls/beaconchaApi.ts

This file was deleted.

11 changes: 8 additions & 3 deletions packages/brain/src/calls/getValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,18 @@ export async function getValidators(): Promise<CustomValidatorGetResponse[]> {
const validators: CustomValidatorGetResponse[] = [];
for (const [pubkey, { tag, feeRecipient }] of Object.entries(data)) {
let format: WithdrawalCredentialsFormat,
withdrawalAddress = "";
withdrawalAddress = "",
index = -1;
try {
withdrawalAddress = (
const beaconResponse = (
await beaconchainApi.getValidatorFromState({
state: "head",
pubkey,
})
).data.validator.withdrawal_credentials;
);

withdrawalAddress = beaconResponse.data.validator.withdrawal_credentials;
index = parseInt(beaconResponse.data.index);

format = isValidWithdrawableBlsAddress(withdrawalAddress)
? "ecdsa"
Expand All @@ -62,6 +66,7 @@ export async function getValidators(): Promise<CustomValidatorGetResponse[]> {

validators.push({
pubkey,
index,
tag,
feeRecipient,
withdrawalCredentials: {
Expand Down
4 changes: 0 additions & 4 deletions packages/brain/src/calls/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
export {
beaconchaFetchAllValidatorsInfo,
beaconchaFetchValidatorsInfo,
} from "./beaconchaApi.js";
export { deleteValidators } from "./deleteValidators.js";
export { exitValidators, getExitValidators } from "./exitValidators.js";
export { importValidators } from "./importValidators.js";
Expand Down
5 changes: 1 addition & 4 deletions packages/brain/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import logger from "./modules/logger/index.js";
import { loadStakerConfig } from "./modules/envs/index.js";
import { Web3SignerApi } from "./modules/apiClients/web3signer/index.js";
import { Beaconchain } from "./modules/apiClients/beaconchain/index.js";
import { BeaconchaApi } from "./modules/apiClients/beaconcha/index.js";
import { startUiServer } from "./modules/apiServers/ui/index.js";
import { startLaunchpadApi } from "./modules/apiServers/launchpad/index.js";
import { ValidatorApi } from "./modules/apiClients/validator/index.js";
Expand All @@ -28,7 +27,6 @@ export const {
consensusClient,
executionClientUrl,
validatorUrl,
beaconchaUrl,
beaconchainUrl,
signerUrl,
token,
Expand All @@ -37,7 +35,7 @@ export const {
tlsCert,
} = loadStakerConfig();
logger.debug(
`Loaded staker config:\n - Network: ${network}\n - Execution client: ${executionClient}\n - Consensus client: ${consensusClient}\n - Execution client url: ${executionClientUrl}\n - Validator url: ${validatorUrl}\n - Beaconcha url: ${beaconchaUrl}\n - Beaconchain url: ${beaconchainUrl}\n - Signer url: ${signerUrl}\n - Token: ${token}\n - Host: ${host}\n - Default fee recipient: ${defaultFeeRecipient}`
`Loaded staker config:\n - Network: ${network}\n - Execution client: ${executionClient}\n - Consensus client: ${consensusClient}\n - Execution client url: ${executionClientUrl}\n - Validator url: ${validatorUrl}\n - Beaconchain url: ${beaconchainUrl}\n - Signer url: ${signerUrl}\n - Token: ${token}\n - Host: ${host}\n - Default fee recipient: ${defaultFeeRecipient}`
);

// Create API instances. Must preceed db initialization
Expand All @@ -46,7 +44,6 @@ export const signerApi = new Web3SignerApi({
authToken: token,
host,
});
export const beaconchaApi = new BeaconchaApi({ baseUrl: beaconchaUrl });
export const validatorApi = new ValidatorApi({
baseUrl: validatorUrl,
authToken: token,
Expand Down
53 changes: 0 additions & 53 deletions packages/brain/src/modules/apiClients/beaconcha/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "chai";
import { ApiParams } from "@stakingbrain/common";
import { BeaconchaApi } from "../../../../src/modules/apiClients/beaconcha/index.js";
import { Beaconchain } from "../../../../src/modules/apiClients/beaconchain/index.js";

describe.skip("Test for fetching validator indexes in every available network", () => {
it("should return data corresponding to every validator PK", async () => {
Expand All @@ -9,21 +9,19 @@ describe.skip("Test for fetching validator indexes in every available network",
for (const network of networks) {
console.log("NETWORK: ", network);

const beaconchaApi = new BeaconchaApi(
beaconchaApiParamsMap.get(network)!
);
const beaconchainApi = new Beaconchain({ baseUrl: `http://` });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add this link


const allValidatorsInfo = await beaconchaApi.fetchAllValidatorsInfo({
pubkeys: [
networkTestMap.get(network)!.pubkeys[0],
networkTestMap.get(network)!.pubkeys[1],
],
});
const allValidatorsInfo = (await Promise.all(
networkTestMap.get(network)!.pubkeys.map(pk => beaconchainApi.getValidatorFromState({
state: "head",
pubkey: pk
}))
));

expect(allValidatorsInfo[0].data[0].validatorindex).to.equal(
expect(allValidatorsInfo[0].data.index).to.equal(
networkTestMap.get(network)!.indexes[0]
);
expect(allValidatorsInfo[0].data[1].validatorindex).to.equal(
expect(allValidatorsInfo[1].data.index).to.equal(
networkTestMap.get(network)!.indexes[1]
);
}
Expand Down Expand Up @@ -64,33 +62,4 @@ const networkTestMap = new Map<
indexes: [57102, 81200],
},
],
]);

// TODO: move below to common

const beaconchaApiParamsMap = new Map<string, ApiParams>([
[
"mainnet",
{
baseUrl: "https://beaconcha.in",
host: "brain.web3signer.dappnode",
apiPath: "/api/v1/",
},
],
[
"prater",
{
baseUrl: "https://prater.beaconcha.in",
host: "brain.web3signer-prater.dappnode",
apiPath: "/api/v1/",
},
],
[
"gnosis",
{
baseUrl: "https://gnosischa.in",
host: "brain.web3signer-gnosis.dappnode",
apiPath: "/api/v1/",
},
],
]);
]);
10 changes: 0 additions & 10 deletions packages/common/src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
Web3signerDeleteRequest,
Web3signerHealthcheckResponse,
CustomImportRequest,
BeaconchaGetResponse,
StakerConfig,
Network,
CustomValidatorGetResponse,
Expand All @@ -14,13 +13,6 @@ import {
} from "./index.js";

export interface Routes {
// BeaconchaApi
beaconchaFetchAllValidatorsInfo: (
pubkeys: string[]
) => Promise<BeaconchaGetResponse[]>;
beaconchaFetchValidatorsInfo: (
pubkeys: string[]
) => Promise<BeaconchaGetResponse>;
// Validators
importValidators: (
postRequest: CustomImportRequest
Expand Down Expand Up @@ -52,8 +44,6 @@ interface RouteData {
}

export const routesData: { [P in keyof Routes]: RouteData } = {
beaconchaFetchAllValidatorsInfo: { log: true },
beaconchaFetchValidatorsInfo: { log: true },
importValidators: { log: true },
updateValidators: { log: true },
deleteValidators: { log: true },
Expand Down
19 changes: 0 additions & 19 deletions packages/common/src/types/api/beaconcha/types.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/common/src/types/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from "./beaconcha/types.js";
export * from "./standard/types.js";
export * from "./validator/types.js";
export * from "./web3signer/types.js";
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/types/customValidators/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface CustomValidatorUpdateRequest {
export type WithdrawalCredentialsFormat = "ecdsa" | "bls" | "unknown" | "error";
export interface CustomValidatorGetResponse {
pubkey: string;
index: number;
tag: Tag;
feeRecipient: string;
withdrawalCredentials: {
Expand Down
33 changes: 18 additions & 15 deletions packages/ui/src/components/ValidatorList/KeystoresDataGrid.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { DataGrid, GridSelectionModel } from "@mui/x-data-grid";
import { useEffect, useState } from "react";
import { beaconchaApiParamsMap } from "../../params";
import {
BeaconchaGetResponse,
CustomValidatorGetResponse,
} from "@stakingbrain/common";
import { CustomValidatorGetResponse } from "@stakingbrain/common";
import { GridColDef } from "@mui/x-data-grid";
import LinkIcon from "@mui/icons-material/Link";
import DeleteIcon from "@mui/icons-material/Delete";
Expand All @@ -22,6 +18,7 @@ import { BeaconchaUrlBuildingStatus } from "../../types";
import { api } from "../../api";
import buildValidatorSummaryURL from "../../utils/buildValidatorSummaryURL";
import LogoutIcon from "@mui/icons-material/Logout";
import { beaconchaApiParamsMap } from "../../params";

export default function KeystoresDataGrid({
rows,
Expand Down Expand Up @@ -115,10 +112,10 @@ export default function KeystoresDataGrid({

const customRows = rows.map((row, index) => ({
pubkey: row.pubkey,
feeRecipient: row.feeRecipient,
beaconcha_url: beaconchaBaseUrl
? beaconchaBaseUrl + "/validator/" + row.pubkey
: "",
feeRecipient: row.feeRecipient,
tag: row.tag,
withdrawalCredentials: row.withdrawalCredentials,
pubkeyInValidator: row.validatorImported,
Expand Down Expand Up @@ -253,21 +250,27 @@ export default function KeystoresDataGrid({
);

async function getValidatorSummaryURL() {
if (!beaconchaApiParamsMap?.get(network)) {
setValidatorSummaryURL("");
setSummaryUrlBuildingStatus(BeaconchaUrlBuildingStatus.Error);
return;
}

let allValidatorsInfo: BeaconchaGetResponse[];
let allValidatorsInfo: CustomValidatorGetResponse[];

setSummaryUrlBuildingStatus(BeaconchaUrlBuildingStatus.InProgress);

try {
allValidatorsInfo = await api.beaconchaFetchAllValidatorsInfo(
selectedRows.map((row) => rows[row as number].pubkey)
allValidatorsInfo = await api.getValidators();

// Filter out validators that are not selected
const selectedPubkeys = selectedRows.map(
(row) => rows[row as number].pubkey
);
allValidatorsInfo = allValidatorsInfo.filter((validator) =>
selectedPubkeys.includes(validator.pubkey)
);
} catch (e) {
setSummaryUrlBuildingStatus(BeaconchaUrlBuildingStatus.Error);
setValidatorSummaryURL("");
return;
}

if (allValidatorsInfo.every((validator) => validator.index === -1)) {
setSummaryUrlBuildingStatus(BeaconchaUrlBuildingStatus.NoIndexes);
setValidatorSummaryURL("");
return;
Expand Down
8 changes: 4 additions & 4 deletions packages/ui/src/components/ValidatorList/ValidatorList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,9 @@ export default function ValidatorList({
sx={{ marginTop: 2 }}
variant="filled"
>
There was an error loading the dashboard. The number of API
calls allowed by the explorer might have been exceeded or the
network might be invalid. Please wait for a minute and refresh
the page.
There was an error loading the dashboard. The beacon chain of
your consensus client might not be synced or the network might
be invalid. Please wait for a while and refresh the page.
</Alert>
)}

Expand All @@ -130,6 +129,7 @@ export default function ValidatorList({
There was an error loading the dashboard. The explorer may not
be able to show a dashboard for all your validators or some of
them might not have been indexed yet. Have you done a deposit?
Are your clients synced?
</Alert>
)}

Expand Down
Loading
Loading