Skip to content

Commit

Permalink
Merge pull request input-output-hk#2892 from input-output-hk/feature/…
Browse files Browse the repository at this point in the history
…ddw-812-investigate-ipc-issues

[DDW-812] Investigate IPC Issues
  • Loading branch information
danielmain authored Mar 21, 2022
2 parents 77bcc54 + 7264457 commit 7096a23
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 46 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Features

- Improved IPC by reducing the amount of messages from periodic events ([PR 2892](https://github.com/input-output-hk/daedalus/pull/2892))
- Improved RTS flags splash screen message ([PR 2901](https://github.com/input-output-hk/daedalus/pull/2901))
- 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))

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@
"shasum": "1.0.2",
"source-map-support": "0.5.19",
"spectron-fake-dialog": "0.0.1",
"tail": "2.2.4",
"tcp-port-used": "1.0.1",
"trezor-connect": "8.2.4-extended",
"unorm": "1.6.0",
Expand Down
2 changes: 0 additions & 2 deletions source/main/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ export const DISK_SPACE_RECOMMENDED_PERCENTAGE = 15; // 15% of the total disk sp

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

export const BLOCK_REPLAY_PROGRESS_CHECK_INTERVAL = 1 * 1000; // 1 seconds | unit: milliseconds

// Used if token metadata server URL is not defined in launcher config
export const FALLBACK_TOKEN_METADATA_SERVER_URL =
'https://metadata.cardano-testnet.iohkdev.io';
Expand Down
2 changes: 1 addition & 1 deletion source/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ const onAppReady = async () => {
};

mainErrorHandler(onMainError);
await handleCheckBlockReplayProgress(mainWindow, launcherConfig.logsPrefix);
handleCheckBlockReplayProgress(mainWindow, launcherConfig.logsPrefix);
await handleCheckDiskSpace();

if (isWatchMode) {
Expand Down
10 changes: 7 additions & 3 deletions source/main/utils/blockSyncProgressHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import moment, { Moment } from 'moment';

export function isItFreshLog(applicationStartDate: Moment, line: string) {
const [, logDate] = line.match(
/\[(\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d+) UTC]/
);
const [, logDate] =
line.match(/\[(\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d+) UTC]/) || [];

if (!logDate) {
return false;
}

return applicationStartDate.isBefore(moment.utc(logDate));
}
52 changes: 17 additions & 35 deletions source/main/utils/handleCheckBlockReplayProgress.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { BrowserWindow } from 'electron';
import fs from 'fs';
import moment, { Moment } from 'moment';
import readline from 'readline';
import moment from 'moment';
import path from 'path';
import { Tail } from 'tail';
import { getBlockSyncProgressChannel } from '../ipc/get-block-sync-progress';
import type { GetBlockSyncProgressType } from '../../common/ipc/api';
import { BLOCK_REPLAY_PROGRESS_CHECK_INTERVAL } from '../config';
import { BlockSyncType } from '../../common/types/cardano-node.types';
import { isItFreshLog } from './blockSyncProgressHelpers';

Expand Down Expand Up @@ -48,30 +47,23 @@ export const handleCheckBlockReplayProgress = (
mainWindow: BrowserWindow,
logsDirectoryPath: string
) => {
const checkBlockReplayProgress = async () => {
const filename = 'node.log';
const logFilePath = `${logsDirectoryPath}/pub/`;
const filePath = path.join(logFilePath, filename);
if (!fs.existsSync(filePath)) return;
const fileStream = fs.createReadStream(filePath);
const rl = readline.createInterface({
input: fileStream,
});
const progress = [];
const filename = 'node.log';
const logFilePath = `${logsDirectoryPath}/pub/`;
const filePath = path.join(logFilePath, filename);
if (!fs.existsSync(filePath)) return;

for await (const line of rl) {
if (
containProgressKeywords(line) &&
isItFreshLog(applicationStartDate, line)
) {
progress.push(line);
}
const tail = new Tail(filePath);

tail.on('line', (line) => {
if (
!isItFreshLog(applicationStartDate, line) ||
!containProgressKeywords(line)
) {
return;
}

if (!progress.length) return;
const finalProgress = progress.slice(-1).pop();
const percentage = finalProgress.match(/Progress:([\s\d.,]+)%/)?.[1];
const progressType = getProgressType(finalProgress);
const percentage = line.match(/Progress:([\s\d.,]+)%/)?.[1];
const progressType = getProgressType(line);
if (!percentage || !progressType) {
return;
}
Expand All @@ -81,15 +73,5 @@ export const handleCheckBlockReplayProgress = (
{ progress: finalProgressPercentage, type: progressType },
mainWindow.webContents
);
};

const setBlockReplayProgressCheckingInterval = () => {
setInterval(async () => {
checkBlockReplayProgress();
}, BLOCK_REPLAY_PROGRESS_CHECK_INTERVAL);
};

// Start default interval
setBlockReplayProgressCheckingInterval();
return checkBlockReplayProgress;
});
};
9 changes: 4 additions & 5 deletions source/renderer/app/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,7 @@ export default class AdaApi {

getWallets = async (): Promise<Array<Wallet>> => {
logger.debug('AdaApi::getWallets called');
const {
getHardwareWalletLocalData,
getHardwareWalletsLocalData,
} = global.daedalus.api.localStorage;
const { getHardwareWalletsLocalData } = global.daedalus.api.localStorage;

try {
const wallets: Array<AdaWallet | LegacyAdaWallet> = await getWallets(
Expand Down Expand Up @@ -281,7 +278,9 @@ export default class AdaApi {
return await Promise.all(
wallets.map(async (wallet: AdaWallet) => {
const { id } = wallet;
const walletData = await getHardwareWalletLocalData(id);

const walletData = hwLocalData[id];

return _createWalletFromServerData({
...wallet,
isHardwareWallet:
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16456,6 +16456,10 @@ table@^6.0.1:
slice-ansi "^4.0.0"
string-width "^4.2.0"

[email protected]:
version "2.2.4"
resolved "https://registry.yarnpkg.com/tail/-/tail-2.2.4.tgz#90dd4c5a174a3fa39dcb65a1df1950a4a0093a41"

tapable@^0.1.8:
version "0.1.10"
resolved "https://registry.yarnpkg.com/tapable/-/tapable-0.1.10.tgz#29c35707c2b70e50d07482b5d202e8ed446dafd4"
Expand Down

0 comments on commit 7096a23

Please sign in to comment.