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

ADD: Fetching Validators for DVT Solutions #2099

Draft
wants to merge 7 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
493 changes: 182 additions & 311 deletions launcher/public/output.css

Large diffs are not rendered by default.

84 changes: 70 additions & 14 deletions launcher/src/backend/ValidatorAccountManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,23 +221,38 @@ export class ValidatorAccountManager {
this.nodeConnection.taskManager.otherTasksHandler(ref, `Listing Keys`);
try {
let client = await this.nodeConnection.readServiceConfiguration(serviceID);
const result = await this.keymanagerAPI(client, "GET", "/eth/v1/keystores");
let data = {};
if (client.service === "CharonService" || client.service === "SSVNetworkService") {
const keys = await this.getDVTKeys(serviceID);
data.data = keys.map((dv) => {
return {
validating_pubkey: client.service === "CharonService" ? dv.distributed_public_key : "0x" + dv.public_key,
derivation_path: "",
readonly: false,
dvt: true,
};
});
//Push successful task
this.nodeConnection.taskManager.otherTasksHandler(ref, `Get Keys`, true, JSON.stringify(data.data, null, 2));
} else {
const result = await this.keymanagerAPI(client, "GET", "/eth/v1/keystores");

//Error handling
if (SSHService.checkExecError(result) && result.stderr) throw SSHService.extractExecError(result);
if (!result.stdout)
throw `ReturnCode: ${result.rc}\nStderr: ${result.stderr}\nStdout: ${result.stdout}\nIs Your Consensus Client Running?`;
//Error handling
if (SSHService.checkExecError(result) && result.stderr) throw SSHService.extractExecError(result);
if (!result.stdout)
throw `ReturnCode: ${result.rc}\nStderr: ${result.stderr}\nStdout: ${result.stdout}\nIs Your Consensus Client Running?`;

const data = JSON.parse(result.stdout);
if (data.data === undefined) {
if (data.code === undefined || data.message === undefined) {
throw "Undexpected Error: " + result;
data = JSON.parse(result.stdout);
if (data.data === undefined) {
if (data.code === undefined || data.message === undefined) {
throw "Undexpected Error: " + result;
}
throw data.code + " " + data.message;
}
throw data.code + " " + data.message;
}

//Push successful task
this.nodeConnection.taskManager.otherTasksHandler(ref, `Get Keys`, true, result.stdout);
//Push successful task
this.nodeConnection.taskManager.otherTasksHandler(ref, `Get Keys`, true, result.stdout);
}

if (!data.data) data.data = [];
this.writeKeys(data.data.map((key) => key.validating_pubkey));
Expand Down Expand Up @@ -1068,7 +1083,7 @@ export class ValidatorAccountManager {
let charonClient = services.find((service) => service.service === "CharonService");
if (!charonClient) throw "Couldn't find CharonService";
const dataDir = path.posix.join(charonClient.getDataDir(), ".charon");
this.nodeConnection.sshService.exec(`rm -rf ${dataDir}`);
await this.nodeConnection.sshService.exec(`rm -rf ${dataDir}`);
const result = await this.nodeConnection.sshService.uploadDirectorySSH(path.normalize(localPath), dataDir);
if (result) {
log.info("Obol Backup uploaded from: ", localPath);
Expand All @@ -1077,4 +1092,45 @@ export class ValidatorAccountManager {
log.error("Error uploading Obol Backup: ", err);
}
}

async getDVTKeys(serviceID) {
const service = (await this.serviceManager.readServiceConfigurations()).find((s) => s.id === serviceID);
if (!service) throw new Error(`Service with id ${serviceID} not found`);
switch (service.service) {
case "CharonService": {
const result = await this.nodeConnection.sshService.exec(service.getReadClusterLockCommand());
const clusterLock = JSON.parse(result.stdout);
return clusterLock.distributed_validators;
}
case "SSVNetworkService": {
const ssvConfig = await this.nodeConnection.getSSVTotalConfig(serviceID);
//Get Operator ID
const response = await axios.get(
`https://api.ssv.network/api/v4/${service.network}/operators/public_key/` + ssvConfig.privateKeyFileData.publicKey
);
if (response.status !== 200 && !response?.data?.data?.id)
throw new Error(`Couldn't get Operator ID from SSV Network ${response.status} ${response.statusText}`);
const operatorID = response.data.data.id;

//get pagination info
let result = await axios.get(
`https://api.ssv.network/api/v4/${service.network}/validators/in_operator/${operatorID}?page=${1}&perPage=100`
);
if (result.status !== 200) throw new Error(`Couldn't get Validator Keys from SSV Network ${result.status} ${result.statusText}`);

//get all pages and concat them
for (let i = 1; i <= result.data.pagination.pages; i++) {
const page = await axios.get(
`https://api.ssv.network/api/v4/${service.network}/validators/in_operator/${operatorID}?page=${i}&perPage=100`
);
if (page.status !== 200) throw new Error(`Couldn't get Validator Keys from SSV Network ${page.status} ${page.statusText}`);
result.data.validators = result.data.validators.concat(page.data.validators);
}

return result.data.validators;
}
default:
throw new Error(`Service ${service.service} not supported`);
}
}
}
4 changes: 4 additions & 0 deletions launcher/src/backend/ethereum-services/CharonService.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ export class CharonService extends NodeService {
return `ls -1 -a ${this.getDataDir()}/.charon`;
}

getReadClusterLockCommand() {
return `cat ${this.getDataDir()}/.charon/cluster-lock.json`;
}

//definitionFile as URL or Path to file (default ".charon/cluster-definition.json" by dkg command)
getDKGCommand(definitionFile) {
return `docker run -u 0 --name "dkg-container" -d -v "${this.getDataDir()}:/opt/charon" ${this.image + ":" + this.imageVersion} dkg ${
Expand Down
Loading
Loading