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

REFACTOR: add support for ssv on holesky and bugfixes #1585

Merged
merged 3 commits into from
Dec 6, 2023
Merged
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
132 changes: 103 additions & 29 deletions launcher/src/backend/NodeConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,17 +336,17 @@ export class NodeConnection {
" ANSIBLE_LOAD_CALLBACK_PLUGINS=1\
ANSIBLE_STDOUT_CALLBACK=stereumjson\
ANSIBLE_LOG_FOLDER=/tmp/" +
playbookRunRef +
"\
playbookRunRef +
"\
ansible-playbook\
--connection=local\
--inventory 127.0.0.1,\
--extra-vars " +
StringUtils.escapeStringForShell(extraVarsJson) +
"\
StringUtils.escapeStringForShell(extraVarsJson) +
"\
" +
this.settings.stereum.settings.controls_install_path +
"/ansible/controls/genericPlaybook.yaml\
this.settings.stereum.settings.controls_install_path +
"/ansible/controls/genericPlaybook.yaml\
"
);
} catch (err) {
Expand Down Expand Up @@ -448,6 +448,83 @@ export class NodeConnection {
return serviceYAML.stdout;
}

async readSSVKeystoreConfig(serviceID) {
try {
const service = await this.readServiceConfiguration(serviceID);
let configPath = ServiceVolume.buildByConfig(
service.volumes.find((v) => v.split(":").slice(-1) == "/data")
).destinationPath;
if (configPath.endsWith("/")) configPath = configPath.slice(0, -1, ""); //if path ends with '/' remove it

let ssvNetworkConfig = await this.sshService.exec(`cat ${configPath}/config.yaml`);
if (SSHService.checkExecError(ssvNetworkConfig)) {
throw new Error(
"Failed reading SSV network config to get keystore keystore from service " +
serviceID +
": " +
SSHService.extractExecError(ssvNetworkConfig)
);
}
let ssvNetworkConfigParsed = YAML.parse(ssvNetworkConfig.stdout);

const regex = /^(\.\/|)data\//; // string starts with "./data/" or "data/"
let keyStorePasswordFile = ssvNetworkConfigParsed.KeyStore.PasswordFile;
if (regex.test(keyStorePasswordFile)) {
keyStorePasswordFile = configPath + "/" + keyStorePasswordFile.replace(regex, "");
}
let keyStorePrivateKeyFile = ssvNetworkConfigParsed.KeyStore.PrivateKeyFile;
if (regex.test(keyStorePrivateKeyFile)) {
keyStorePrivateKeyFile = configPath + "/" + keyStorePrivateKeyFile.replace(regex, "");
}

let keyStorePasswordFileRequest = await this.sshService.exec(`cat "${keyStorePasswordFile}"`);
if (SSHService.checkExecError(keyStorePasswordFileRequest) || keyStorePasswordFileRequest.rc) {
log.error(
"Can't read SSV keystore password file content from service " + serviceID,
keyStorePasswordFileRequest.stderr
);
throw new Error(
"Can't read SSV keystore password file content from service " +
serviceID +
": " +
keyStorePasswordFileRequest.stderr
);
}
let keyStorePasswordFileContent = keyStorePasswordFileRequest.stdout;

let keyStorePrivateKeyFileRequest = await this.sshService.exec(`cat "${keyStorePrivateKeyFile}"`);
if (SSHService.checkExecError(keyStorePrivateKeyFileRequest) || keyStorePrivateKeyFileRequest.rc) {
log.error(
"Can't read SSV keystore private key file content from service " + serviceID,
keyStorePrivateKeyFileRequest.stderr
);
throw new Error(
"Can't read SSV keystore private key file content from service " +
serviceID +
": " +
keyStorePrivateKeyFileRequest.stderr
);
}
let keyStorePrivateKeyFileContent = keyStorePrivateKeyFileRequest.stdout;

return {
passwordFilePath: keyStorePasswordFile,
passwordFileData: keyStorePasswordFileContent.trim(),
privateKeyFilePath: keyStorePrivateKeyFile,
privateKeyFileData: (() => {
try {
return JSON.parse(keyStorePrivateKeyFileContent);
} catch (e) {
return keyStorePrivateKeyFileContent;
}
})(),
};
} catch (err) {
log.error("Can't read SSV keystore from service " + serviceID, err);
throw new Error("Can't read SSV keystore from service " + serviceID + ": " + err);
}
}

async readSSVNetworkConfig(serviceID) {
let SSVNetworkConfig;
try {
Expand Down Expand Up @@ -593,10 +670,10 @@ export class NodeConnection {
}
configStatus = await this.sshService.exec(
"echo -e " +
StringUtils.escapeStringForShell(service.data.trim()) +
" > /etc/stereum/services/" +
service.id +
".yaml"
StringUtils.escapeStringForShell(service.data.trim()) +
" > /etc/stereum/services/" +
service.id +
".yaml"
);
} catch (err) {
this.taskManager.otherSubTasks.push({
Expand Down Expand Up @@ -642,10 +719,10 @@ export class NodeConnection {
try {
configStatus = await this.sshService.exec(
"echo -e " +
StringUtils.escapeStringForShell(YAML.stringify(serviceConfiguration)) +
" > /etc/stereum/services/" +
serviceConfiguration.id +
".yaml"
StringUtils.escapeStringForShell(YAML.stringify(serviceConfiguration)) +
" > /etc/stereum/services/" +
serviceConfiguration.id +
".yaml"
);
} catch (err) {
this.taskManager.otherSubTasks.push({
Expand All @@ -667,9 +744,9 @@ export class NodeConnection {
this.taskManager.finishedOtherTasks.push({ otherRunRef: ref });
throw new Error(
"Failed writing service configuration " +
serviceConfiguration.id +
": " +
SSHService.extractExecError(configStatus)
serviceConfiguration.id +
": " +
SSHService.extractExecError(configStatus)
);
}
this.taskManager.otherSubTasks.push({
Expand Down Expand Up @@ -1139,7 +1216,7 @@ export class NodeConnection {
log.info(" Could not connect.\n" + (retry.maxTries - retry.counter) + " tries left.");
}
}
log.info("OUT OF WHILE LOOP")
log.info("OUT OF WHILE LOOP");
if (retry.connected) {
await this.establish(this.taskManager);
this.taskManager.otherTasksHandler(ref, "Connected", true);
Expand Down Expand Up @@ -1238,13 +1315,14 @@ export class NodeConnection {
async dumpDockerLogs() {
try {
const services = await this.listServices();
log.info(services)
log.info(services);
const containerIds = services.map((service) => service.ID);


const logsPromises = containerIds.map(async (containerId) => {
try {
let jsonFilePathsResult = await this.sshService.exec(`ls /var/lib/docker/containers/${containerId}/${containerId}*`);
let jsonFilePathsResult = await this.sshService.exec(
`ls /var/lib/docker/containers/${containerId}/${containerId}*`
);

if (SSHService.checkExecError(jsonFilePathsResult)) {
throw new Error("Failed reading docker logs: " + SSHService.extractExecError(jsonFilePathsResult));
Expand All @@ -1253,25 +1331,21 @@ export class NodeConnection {
const jsonFilePaths = jsonFilePathsResult.stdout.split("\n").filter((i) => i);

for (const jsonFilePath of jsonFilePaths) {

const logs = await this.sshService.exec(`cat ${jsonFilePath}`);

return { containerId, logs };
}
} catch (err) {
log.error("Failed to dump Docker Logs: ", err)
return { containerId, logs: '' };
log.error("Failed to dump Docker Logs: ", err);
return { containerId, logs: "" };
}
});

const allLogs = await Promise.all(logsPromises);
return allLogs;

} catch (err) {
log.error("Failed to dump Docker Logs: ", err)
return [{ containerId: 'ERROR', logs: err }];
log.error("Failed to dump Docker Logs: ", err);
return [{ containerId: "ERROR", logs: err }];
}


}
}
3 changes: 2 additions & 1 deletion launcher/src/backend/ethereum-services/SSVNetworkService.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export class SSVNetworkService extends NodeService {
ssv:
# The SSV network to join to
# Mainnet = Network: mainnet (default)
# Testnet = Network: jato-v2
# Testnet (Goerli) = Network: jato-v2
# Testnet (Holesky) = Network: holesky
Network: ${network === "goerli" ? "jato-v2" : network}

ValidatorOptions:
Expand Down
4 changes: 4 additions & 0 deletions launcher/src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,10 @@ ipcMain.handle("restartServer", async () => {
return await nodeConnection.restartServer();
});

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

ipcMain.handle("readSSVNetworkConfig", async (event, args) => {
return await nodeConnection.readSSVNetworkConfig(args);
});
Expand Down
2 changes: 1 addition & 1 deletion launcher/src/components/UI/services-modal/SsvDashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default {
async getURL() {
const grafana = this.installedServices.find((service) => service.service === "GrafanaService");
this.ssvNetworkUrl.operatorUrl = `https://${
this.currentNetwork.network === "goerli" ? "goerli." : ""
["goerli", "holesky"].includes(this.currentNetwork.network) ? this.currentNetwork.network + "." : ""
}explorer.ssv.network/operators/${this.operatorData?.id ? this.operatorData?.id : ""}`;
this.ssvNetworkUrl.grafanaDashboardUrl = grafana.linkUrl
? grafana.linkUrl + "/d/QNiMrdoVz/node-dashboard?orgId=1"
Expand Down
6 changes: 6 additions & 0 deletions launcher/src/components/UI/services-modal/SsvModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ export default {
this.pubkey = ssvConfig.ssv_pk;

try {
if (!this.pubkey) {
let ssvKeystoreConfig = await ControlService.readSSVKeystoreConfig(ssv.config.serviceID);
if (ssvKeystoreConfig.privateKeyFileData.publicKey) {
this.pubkey = ssvKeystoreConfig.privateKeyFileData.publicKey;
}
}
let network = ssvConfig.network === "goerli" ? "prater" : ssvConfig.network;
let response = await axios.get(`https://api.ssv.network/api/v4/${network}/operators/public_key/` + this.pubkey);
if (!response.data.data)
Expand Down
6 changes: 5 additions & 1 deletion launcher/src/store/ControlService.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,10 @@ class ControlService extends EventEmitter {
return await this.promiseIpc.send("restartServer");
}

async readSSVKeystoreConfig(args) {
return await this.promiseIpc.send("readSSVKeystoreConfig", args);
}

async readSSVNetworkConfig(args) {
return await this.promiseIpc.send("readSSVNetworkConfig", args);
}
Expand Down Expand Up @@ -447,7 +451,7 @@ class ControlService extends EventEmitter {
async beaconchainMonitoringModification(args) {
return await this.promiseIpc.send("beaconchainMonitoringModification", args);
}

async removeBeaconchainMonitoring(args) {
return await this.promiseIpc.send("removeBeaconchainMonitoring", args);
}
Expand Down
2 changes: 1 addition & 1 deletion launcher/src/store/nodeManage.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export const useNodeManage = defineStore("nodeManage", {
icon: "/img/icon/click-installation/testnet-icon.png",
currencyIcon: "/img/icon/control/goETH_Currency_Symbol.png",
dataEndpoint: "https://holesky.beaconcha.in/api/v1",
support: ["staking", "stereum on arm", "mev boost"],
support: ["staking", "ssv.network", "stereum on arm", "mev boost"],
},
],
currentNetwork: {},
Expand Down
Loading