Skip to content

Commit 7096a23

Browse files
authored
Merge pull request #2892 from input-output-hk/feature/ddw-812-investigate-ipc-issues
[DDW-812] Investigate IPC Issues
2 parents 77bcc54 + 7264457 commit 7096a23

File tree

8 files changed

+35
-46
lines changed

8 files changed

+35
-46
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Features
66

7+
- Improved IPC by reducing the amount of messages from periodic events ([PR 2892](https://github.com/input-output-hk/daedalus/pull/2892))
78
- Improved RTS flags splash screen message ([PR 2901](https://github.com/input-output-hk/daedalus/pull/2901))
89
- Implemented error message when trying to leave wallet without enough ada to support tokens ([PR 2783](https://github.com/input-output-hk/daedalus/pull/2783))
910

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@
271271
"shasum": "1.0.2",
272272
"source-map-support": "0.5.19",
273273
"spectron-fake-dialog": "0.0.1",
274+
"tail": "2.2.4",
274275
"tcp-port-used": "1.0.1",
275276
"trezor-connect": "8.2.4-extended",
276277
"unorm": "1.6.0",

source/main/config.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,6 @@ export const DISK_SPACE_RECOMMENDED_PERCENTAGE = 15; // 15% of the total disk sp
172172

173173
export const DISK_SPACE_CHECK_TIMEOUT = 9 * 1000; // Timeout for checking disks pace
174174

175-
export const BLOCK_REPLAY_PROGRESS_CHECK_INTERVAL = 1 * 1000; // 1 seconds | unit: milliseconds
176-
177175
// Used if token metadata server URL is not defined in launcher config
178176
export const FALLBACK_TOKEN_METADATA_SERVER_URL =
179177
'https://metadata.cardano-testnet.iohkdev.io';

source/main/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ const onAppReady = async () => {
248248
};
249249

250250
mainErrorHandler(onMainError);
251-
await handleCheckBlockReplayProgress(mainWindow, launcherConfig.logsPrefix);
251+
handleCheckBlockReplayProgress(mainWindow, launcherConfig.logsPrefix);
252252
await handleCheckDiskSpace();
253253

254254
if (isWatchMode) {
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import moment, { Moment } from 'moment';
22

33
export function isItFreshLog(applicationStartDate: Moment, line: string) {
4-
const [, logDate] = line.match(
5-
/\[(\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d+) UTC]/
6-
);
4+
const [, logDate] =
5+
line.match(/\[(\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d+) UTC]/) || [];
6+
7+
if (!logDate) {
8+
return false;
9+
}
10+
711
return applicationStartDate.isBefore(moment.utc(logDate));
812
}

source/main/utils/handleCheckBlockReplayProgress.ts

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { BrowserWindow } from 'electron';
22
import fs from 'fs';
3-
import moment, { Moment } from 'moment';
4-
import readline from 'readline';
3+
import moment from 'moment';
54
import path from 'path';
5+
import { Tail } from 'tail';
66
import { getBlockSyncProgressChannel } from '../ipc/get-block-sync-progress';
77
import type { GetBlockSyncProgressType } from '../../common/ipc/api';
8-
import { BLOCK_REPLAY_PROGRESS_CHECK_INTERVAL } from '../config';
98
import { BlockSyncType } from '../../common/types/cardano-node.types';
109
import { isItFreshLog } from './blockSyncProgressHelpers';
1110

@@ -48,30 +47,23 @@ export const handleCheckBlockReplayProgress = (
4847
mainWindow: BrowserWindow,
4948
logsDirectoryPath: string
5049
) => {
51-
const checkBlockReplayProgress = async () => {
52-
const filename = 'node.log';
53-
const logFilePath = `${logsDirectoryPath}/pub/`;
54-
const filePath = path.join(logFilePath, filename);
55-
if (!fs.existsSync(filePath)) return;
56-
const fileStream = fs.createReadStream(filePath);
57-
const rl = readline.createInterface({
58-
input: fileStream,
59-
});
60-
const progress = [];
50+
const filename = 'node.log';
51+
const logFilePath = `${logsDirectoryPath}/pub/`;
52+
const filePath = path.join(logFilePath, filename);
53+
if (!fs.existsSync(filePath)) return;
6154

62-
for await (const line of rl) {
63-
if (
64-
containProgressKeywords(line) &&
65-
isItFreshLog(applicationStartDate, line)
66-
) {
67-
progress.push(line);
68-
}
55+
const tail = new Tail(filePath);
56+
57+
tail.on('line', (line) => {
58+
if (
59+
!isItFreshLog(applicationStartDate, line) ||
60+
!containProgressKeywords(line)
61+
) {
62+
return;
6963
}
7064

71-
if (!progress.length) return;
72-
const finalProgress = progress.slice(-1).pop();
73-
const percentage = finalProgress.match(/Progress:([\s\d.,]+)%/)?.[1];
74-
const progressType = getProgressType(finalProgress);
65+
const percentage = line.match(/Progress:([\s\d.,]+)%/)?.[1];
66+
const progressType = getProgressType(line);
7567
if (!percentage || !progressType) {
7668
return;
7769
}
@@ -81,15 +73,5 @@ export const handleCheckBlockReplayProgress = (
8173
{ progress: finalProgressPercentage, type: progressType },
8274
mainWindow.webContents
8375
);
84-
};
85-
86-
const setBlockReplayProgressCheckingInterval = () => {
87-
setInterval(async () => {
88-
checkBlockReplayProgress();
89-
}, BLOCK_REPLAY_PROGRESS_CHECK_INTERVAL);
90-
};
91-
92-
// Start default interval
93-
setBlockReplayProgressCheckingInterval();
94-
return checkBlockReplayProgress;
76+
});
9577
};

source/renderer/app/api/api.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,7 @@ export default class AdaApi {
246246

247247
getWallets = async (): Promise<Array<Wallet>> => {
248248
logger.debug('AdaApi::getWallets called');
249-
const {
250-
getHardwareWalletLocalData,
251-
getHardwareWalletsLocalData,
252-
} = global.daedalus.api.localStorage;
249+
const { getHardwareWalletsLocalData } = global.daedalus.api.localStorage;
253250

254251
try {
255252
const wallets: Array<AdaWallet | LegacyAdaWallet> = await getWallets(
@@ -281,7 +278,9 @@ export default class AdaApi {
281278
return await Promise.all(
282279
wallets.map(async (wallet: AdaWallet) => {
283280
const { id } = wallet;
284-
const walletData = await getHardwareWalletLocalData(id);
281+
282+
const walletData = hwLocalData[id];
283+
285284
return _createWalletFromServerData({
286285
...wallet,
287286
isHardwareWallet:

yarn.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16456,6 +16456,10 @@ table@^6.0.1:
1645616456
slice-ansi "^4.0.0"
1645716457
string-width "^4.2.0"
1645816458

16459+
16460+
version "2.2.4"
16461+
resolved "https://registry.yarnpkg.com/tail/-/tail-2.2.4.tgz#90dd4c5a174a3fa39dcb65a1df1950a4a0093a41"
16462+
1645916463
tapable@^0.1.8:
1646016464
version "0.1.10"
1646116465
resolved "https://registry.yarnpkg.com/tapable/-/tapable-0.1.10.tgz#29c35707c2b70e50d07482b5d202e8ed446dafd4"

0 commit comments

Comments
 (0)