Skip to content

Commit

Permalink
FIX: validator keys grouping, removing keys (#1536)
Browse files Browse the repository at this point in the history
  • Loading branch information
gbayasgalan authored Nov 6, 2023
1 parent 25351bb commit 1c15bcf
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 23 deletions.
61 changes: 43 additions & 18 deletions launcher/src/backend/ValidatorAccountManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export class ValidatorAccountManager {
this.nodeConnection = nodeConnection;
this.serviceManager = serviceManager;
this.batches = [];
this.callCount = 0;
this.storedKeys = [];
}

createBatch(files, password, slashingDB, chunkSize = 100) {
Expand Down Expand Up @@ -235,7 +237,7 @@ export class ValidatorAccountManager {
}
}

async listValidators(serviceID) {
async listValidators(serviceID, numRunningValidatorService) {
const ref = StringUtils.createRandomString();
this.nodeConnection.taskManager.otherTasksHandler(ref, `Listing Keys`);
try {
Expand All @@ -246,7 +248,7 @@ export class ValidatorAccountManager {

const data = JSON.parse(result.stdout);
if (!data.data) data.data = [];
await this.writeKeys(data.data.map((k) => k.validating_pubkey));
await this.storeKeys(data.data, numRunningValidatorService);

this.nodeConnection.taskManager.otherTasksHandler(ref, `Write Keys to keys.yaml`, true);
this.nodeConnection.taskManager.otherTasksHandler(ref);
Expand Down Expand Up @@ -523,31 +525,54 @@ export class ValidatorAccountManager {
}
}

async storeKeys(data, numRunningValidatorService) {
this.callCount++;
if (this.callCount % numRunningValidatorService !== 0 && !isNaN(this.callCount % numRunningValidatorService)) {
this.storedKeys.push(...data.map((k) => k.validating_pubkey));
} else if (this.callCount % numRunningValidatorService === 0) {
this.storedKeys.push(...data.map((k) => k.validating_pubkey));
await this.writeKeys(this.storedKeys);
this.storedKeys = [];
this.callCount = 0;
} else if (data.length === 0) {
await this.writeKeys(data);
this.callCount = 0;
}
}

async writeKeys(keys) {
let obj = keys;
console.log(obj);
if (Array.isArray(keys)) {
const existing = await this.readKeys();
obj = existing ? existing : {};
keys.forEach((key) => {
if (existing && existing[key]) {
if (typeof existing[key] === "string") {
if (existing) {
obj = existing;
if (Object.keys(existing).length !== 0) {
Object.keys(existing).forEach((key) => {
obj = !keys.includes(key) ? {} : obj;
});
}
keys.forEach((key) => {
if (existing[key]) {
if (typeof existing[key] === "string") {
obj[key] = {
keyName: existing[key],
groupName: "",
groupID: null,
};
} else {
obj[key] = existing[key];
}
} else {
obj[key] = {
keyName: existing[key],
keyName: "",
groupName: "",
groupID: null,
};
} else {
obj[key] = existing[key];
}
} else {
obj[key] = {
keyName: "",
groupName: "",
groupID: null,
};
}
});
});
} else {
obj = {};
}
}
await this.nodeConnection.sshService.exec(
"echo -e " + StringUtils.escapeStringForShell(YAML.stringify(obj)) + " > /etc/stereum/keys.yaml"
Expand Down
4 changes: 2 additions & 2 deletions launcher/src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ ipcMain.handle("deleteValidators", async (event, args) => {
});

ipcMain.handle("listValidators", async (event, args) => {
return await validatorAccountManager.listValidators(args);
return await validatorAccountManager.listValidators(args.serviceID, args.numRunningValidatorService);
});

ipcMain.handle("listServices", async () => {
Expand Down Expand Up @@ -479,7 +479,7 @@ ipcMain.handle("IpScanLan", async () => {
});

ipcMain.handle("beaconchainMonitoringModification", async (event, args) => {
return await serviceManager.beaconchainMonitoringModification(args)
return await serviceManager.beaconchainMonitoringModification(args);
});

// Scheme must be registered before the app is ready
Expand Down
9 changes: 8 additions & 1 deletion launcher/src/composables/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,27 @@ export async function useListKeys(forceRefresh) {
const serviceStore = useServices();
const nodeManageStore = useNodeManage();
const stakingStore = useStakingStore();
let numRunningValidatorService = 0;

let keyStats = [];
let clients = serviceStore.installedServices.filter(
(s) => s.category == "validator" && s.service != "CharonService" && s.service != "SSVNetworkService"
);
if (clients && clients.length > 0 && nodeManageStore.currentNetwork.network != "") {
for (let client of clients) {
if (client.state === "running" && client.service.includes("ValidatorService")) {
numRunningValidatorService++;
}
}

for (let client of clients) {
//if there is already a list of keys ()
if (
(client.config.keys === undefined || client.config.keys.length === 0 || forceRefresh) &&
client.state === "running"
) {
//refresh validaotr list
let result = await ControlService.listValidators(client.config.serviceID);
let result = await ControlService.listValidators(client.config.serviceID, numRunningValidatorService);
if (
!client.service.includes("Lighthouse") &&
!client.service.includes("Lodestar") &&
Expand Down
7 changes: 5 additions & 2 deletions launcher/src/store/ControlService.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,11 @@ class ControlService extends EventEmitter {
return await this.promiseIpc.send("deleteValidators", args);
}

async listValidators(args) {
return await this.promiseIpc.send("listValidators", args);
async listValidators(serviceID, numRunningValidatorService) {
return await this.promiseIpc.send("listValidators", {
serviceID: serviceID,
numRunningValidatorService: numRunningValidatorService,
});
}

async listServices() {
Expand Down

0 comments on commit 1c15bcf

Please sign in to comment.