From b794f4c9ca78577bdb85567d349972ff6889965c Mon Sep 17 00:00:00 2001 From: brusher_ru Date: Thu, 20 Jun 2024 11:08:37 +0300 Subject: [PATCH 1/2] fix: standalone config --- desktop/testMode.ts | 15 ++++----------- shared/types/node.ts | 1 + 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/desktop/testMode.ts b/desktop/testMode.ts index 5936f82a9..77e7f1c80 100644 --- a/desktop/testMode.ts +++ b/desktop/testMode.ts @@ -39,26 +39,19 @@ export const getTestModeNodeConfig = (): NodeConfig => ({ main: { 'layer-duration': '6s', 'layers-per-epoch': 10, - 'eligibility-confidence-param': 18, - 'tick-size': 67000, 'network-hrp': HRP.Standalone, }, - genesis: { - 'genesis-time': TEST_MODE_GENESIS_TIME, - 'genesis-extra-data': 'standalone', - }, poet: { - 'phase-shift': '30s', 'cycle-gap': '30s', - 'grace-period': '10s', }, post: { 'post-labels-per-unit': 128, 'post-max-numunits': 4, 'post-min-numunits': 1, - 'post-k1': 12, - 'post-k2': 4, - 'post-k3': 4, + }, + genesis: { + 'genesis-time': TEST_MODE_GENESIS_TIME, + 'genesis-extra-data': 'standalone', }, }); diff --git a/shared/types/node.ts b/shared/types/node.ts index c654c42ee..9c0a3a12a 100644 --- a/shared/types/node.ts +++ b/shared/types/node.ts @@ -102,6 +102,7 @@ export interface NodeConfig { post: { 'post-labels-per-unit': number; 'post-max-numunits': number; + 'post-min-numunits'?: number; }; } From cc03221f9a001d92b917e6263d2fbb913640ae6f Mon Sep 17 00:00:00 2001 From: brusher_ru Date: Mon, 24 Jun 2024 17:43:56 +0300 Subject: [PATCH 2/2] feat: export network info from settings page --- app/infra/eventsService/eventsService.ts | 2 + app/screens/settings/Settings.tsx | 11 ++++ app/vars/ipcConsts.ts | 1 + desktop/AdminService.ts | 18 ++++++ desktop/DebugService.ts | 28 +++++++++ desktop/main/reactions/handleExportInfoIPC.ts | 63 +++++++++++++++++++ desktop/main/startApp.ts | 2 + 7 files changed, 125 insertions(+) create mode 100644 desktop/DebugService.ts create mode 100644 desktop/main/reactions/handleExportInfoIPC.ts diff --git a/app/infra/eventsService/eventsService.ts b/app/infra/eventsService/eventsService.ts index c5791148b..c08e58fda 100644 --- a/app/infra/eventsService/eventsService.ts +++ b/app/infra/eventsService/eventsService.ts @@ -247,6 +247,8 @@ class EventsService { /** ************************************** MISC ***************************************** */ + static exportNetInfo = () => ipcRenderer.invoke(ipcConsts.EXPORT_NET_INFO); + static print = ({ content }: { content: string }) => ipcRenderer.send(ipcConsts.PRINT, { content }); diff --git a/app/screens/settings/Settings.tsx b/app/screens/settings/Settings.tsx index b45d9b072..c0180249c 100644 --- a/app/screens/settings/Settings.tsx +++ b/app/screens/settings/Settings.tsx @@ -491,6 +491,17 @@ class Settings extends Component { ))} + + } + rowName="" + /> + new Promise((resolve, reject) => { + if (!this.service) { + reject(new Error('Service is not started yet')); + return; + } + + const result: PeerInfo__Output[] = []; + const stream = this.service?.PeerInfoStream({}); + if (!stream) { + resolve([]); + return; + } + stream.on('data', (d) => result.push(d)); + stream.on('close', () => resolve(result)); + }); } export default AdminService; diff --git a/desktop/DebugService.ts b/desktop/DebugService.ts new file mode 100644 index 000000000..8cea69c26 --- /dev/null +++ b/desktop/DebugService.ts @@ -0,0 +1,28 @@ +import { ProtoGrpcType } from '../api/generated'; + +import Logger from './logger'; +import NetServiceFactory from './NetServiceFactory'; +import { getPrivateNodeConnectionConfig } from './main/utils'; + +const PROTO_PATH = 'vendor/api/spacemesh/v1/debug.proto'; + +class DebugService extends NetServiceFactory< + ProtoGrpcType, + 'v1', + 'DebugService' +> { + logger = Logger({ className: 'DebugService' }); + + createService = () => { + this.createNetService( + PROTO_PATH, + getPrivateNodeConnectionConfig(), + 'v1', + 'DebugService' + ); + }; + + getNetworkInfo = () => this.callService('NetworkInfo', {}); +} + +export default DebugService; diff --git a/desktop/main/reactions/handleExportInfoIPC.ts b/desktop/main/reactions/handleExportInfoIPC.ts new file mode 100644 index 000000000..e01ac6054 --- /dev/null +++ b/desktop/main/reactions/handleExportInfoIPC.ts @@ -0,0 +1,63 @@ +import { writeFile } from 'fs/promises'; +import { combineLatest, from, map, mergeMap, Observable } from 'rxjs'; +import { BrowserWindow, dialog } from 'electron'; +import { handleIPC, handlerResult, makeSubscription } from '../rx.utils'; +import { ipcConsts } from '../../../app/vars'; +import AdminService from '../../AdminService'; +import DebugService from '../../DebugService'; +import Logger from '../../logger'; + +const logger = Logger({ className: 'handleExportInfoIPC' }); + +const saveDialog = async ( + browser: BrowserWindow, + data: Record +) => { + const { canceled, filePath } = await dialog.showSaveDialog(browser, { + title: 'Export network info', + buttonLabel: 'Export', + defaultPath: 'netInfo.json', + }); + if (canceled || !filePath) { + return { filePath: null, data, canceled }; + } + return { filePath, data, canceled }; +}; + +const handleExportInfoIPC = ($mainWindow: Observable) => + makeSubscription( + handleIPC( + ipcConsts.EXPORT_NET_INFO, + () => { + const adminService = new AdminService(); + const debugService = new DebugService(); + debugService.createService(); + adminService.createService(); + + const netInfo = from(debugService.getNetworkInfo()); + const peerInfo = from(adminService.getPeerInfo()); + + return combineLatest([netInfo, peerInfo, $mainWindow]).pipe( + mergeMap(([netInfo, peerInfo, browser]) => + from(saveDialog(browser, { netInfo, peerInfo })) + ), + map(handlerResult) + ); + }, + (data) => data + ), + ({ filePath, data }) => { + if (filePath) { + writeFile(filePath, JSON.stringify(data, null, 2), 'utf-8') + // eslint-disable-next-line promise/always-return + .then(() => { + logger.log('Network data exported', { filePath, data }); + }) + .catch((err) => + logger.error('Cannot write file', err, { filePath, data }) + ); + } + } + ); + +export default handleExportInfoIPC; diff --git a/desktop/main/startApp.ts b/desktop/main/startApp.ts index 8dc8f2aa1..0a44b7636 100644 --- a/desktop/main/startApp.ts +++ b/desktop/main/startApp.ts @@ -49,6 +49,7 @@ import syncAutoStartAndConfig from './reactions/syncAutoStartAndConfig'; import restartNode from './reactions/restartNode'; import { updateConfigHash } from './configHash'; import { ensureConfigCacheDir } from './fallbackConfigs'; +import handleExportInfoIPC from './reactions/handleExportInfoIPC'; const positiveNum = (def: number, n: number) => (n > 0 ? n : def); @@ -271,6 +272,7 @@ const startApp = (): AppStore => { listenNodeConfigAndRestartNode($nodeConfig, $managers), handleBenchmarksIpc($mainWindow, $nodeConfig), syncAutoStartAndConfig($warnings), + handleExportInfoIPC($mainWindow), ]; return {