Skip to content

Commit 10222ac

Browse files
szymonmaslowskidanielmainrenanvalentin
authored
[DDW-964] Showing progress of all three sync types at once on loading screen (#2877)
Co-authored-by: Daniel Main <[email protected]> Co-authored-by: Renan Ferreira <[email protected]>
1 parent 996c582 commit 10222ac

37 files changed

+545
-180
lines changed

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"react/no-array-index-key": "warn",
7070
"react/no-unused-prop-types": "warn",
7171
"react/prefer-stateless-function": 0,
72-
"react/prop-types": "warn",
72+
"react/prop-types": 0,
7373
"react/require-default-props": 0,
7474
"react/jsx-first-prop-new-line": [1, "multiline-multiprop"],
7575
"@typescript-eslint/ban-ts-comment": 1,

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+
- Improve the syncing screen by showing syncing progress split into three stages ([PR 2877](https://github.com/input-output-hk/daedalus/pull/2877))
78
- Improved stake pool searchbar ([PR 2847](https://github.com/input-output-hk/daedalus/pull/2847))
89
- Implemented catalyst dynamic content ([PR 2856](https://github.com/input-output-hk/daedalus/pull/2856))
910

source/common/ipc/api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ export enum WalletSettingsStateEnum {
183183
disabled = 'disabled',
184184
enabled = 'enabled',
185185
}
186+
186187
export const REBUILD_APP_MENU_CHANNEL = 'REBUILD_APP_MENU_CHANNEL';
187188
export type RebuildAppMenuRendererRequest = {
188189
isNavigationEnabled: boolean;
@@ -451,7 +452,7 @@ export type IntrospectAddressMainResponse = IntrospectAddressResponse;
451452
/**
452453
* Channel for checking block replay progress
453454
*/
454-
export const GET_BLOCK_SYNC_STATUS_CHANNEL = 'GetBlockSyncProgressChannel';
455+
export const GET_BLOCK_SYNC_PROGRESS_CHANNEL = 'GetBlockSyncProgressChannel';
455456
export type GetBlockSyncProgressType = BlockSyncType;
456457
export type GetBlockSyncProgressRendererRequest = void;
457458
export type GetBlockSyncProgressMainResponse = {

source/common/types/cardano-node.types.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ export const NetworkMagics: {
159159
// Cardano Selfnode network magic
160160
[SELFNODE]: [1, null],
161161
};
162-
export type BlockSyncType =
163-
| 'validatingChunk'
164-
| 'pushingLedger'
165-
| 'replayedBlock';
162+
export enum BlockSyncType {
163+
pushingLedger = 'pushingLedger',
164+
replayedBlock = 'replayedBlock',
165+
validatingChunk = 'validatingChunk',
166+
}

source/main/ipc/get-block-sync-progress.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { MainIpcChannel } from './lib/MainIpcChannel';
2-
import { GET_BLOCK_SYNC_STATUS_CHANNEL } from '../../common/ipc/api';
2+
import { GET_BLOCK_SYNC_PROGRESS_CHANNEL } from '../../common/ipc/api';
33
import type {
44
GetBlockSyncProgressRendererRequest,
55
GetBlockSyncProgressMainResponse,
@@ -10,4 +10,4 @@ import type {
1010
export const getBlockSyncProgressChannel: MainIpcChannel<
1111
GetBlockSyncProgressRendererRequest,
1212
GetBlockSyncProgressMainResponse
13-
> = new MainIpcChannel(GET_BLOCK_SYNC_STATUS_CHANNEL);
13+
> = new MainIpcChannel(GET_BLOCK_SYNC_PROGRESS_CHANNEL);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import moment from 'moment';
2+
import { isItFreshLog } from './blockSyncProgressHelpers';
3+
4+
describe('blockSyncProgressHelpers', () => {
5+
it('should return true for newer logs', () => {
6+
const time = '2022-02-18 13:18:47.66';
7+
const applicationStartDate = moment.utc(time).add(-1, 'minute');
8+
const line = `[34m[XX-M:cardano.node.ChainDB:Info:30][0m [${time} UTC] Validating chunk no. 2256 out of 2256. Progress: 99.96%`;
9+
10+
expect(isItFreshLog(applicationStartDate, line)).toBe(true);
11+
});
12+
13+
it('should return false for logs of same time', () => {
14+
const time = '2022-02-18 13:18:47.66';
15+
const applicationStartDate = moment.utc(time);
16+
const line = `[34m[XX-M:cardano.node.ChainDB:Info:30][0m [${time} UTC] Validating chunk no. 2256 out of 2256. Progress: 99.96%`;
17+
18+
expect(isItFreshLog(applicationStartDate, line)).toBe(false);
19+
});
20+
21+
it('should return false for older logs', () => {
22+
const time = '2022-02-18 13:18:47.66';
23+
const applicationStartDate = moment.utc(time).add(1, 'minute');
24+
const line = `[34m[XX-M:cardano.node.ChainDB:Info:30][0m [${time} UTC] Validating chunk no. 2256 out of 2256. Progress: 99.96%`;
25+
26+
expect(isItFreshLog(applicationStartDate, line)).toBe(false);
27+
});
28+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import moment, { Moment } from 'moment';
2+
3+
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+
);
7+
return applicationStartDate.isBefore(moment.utc(logDate));
8+
}

source/main/utils/handleCheckBlockReplayProgress.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { BrowserWindow } from 'electron';
22
import fs from 'fs';
3+
import moment, { Moment } from 'moment';
34
import readline from 'readline';
45
import path from 'path';
56
import { getBlockSyncProgressChannel } from '../ipc/get-block-sync-progress';
67
import type { GetBlockSyncProgressType } from '../../common/ipc/api';
78
import { BLOCK_REPLAY_PROGRESS_CHECK_INTERVAL } from '../config';
9+
import { BlockSyncType } from '../../common/types/cardano-node.types';
10+
import { isItFreshLog } from './blockSyncProgressHelpers';
811

912
const blockKeyword = 'Replayed block';
1013
const validatingChunkKeyword = 'Validating chunk';
@@ -18,15 +21,11 @@ const progressKeywords = [
1821
ledgerKeyword,
1922
];
2023

21-
type KeywordTypeMap = {
22-
[name: string]: GetBlockSyncProgressType;
23-
};
24-
25-
const keywordTypeMap: KeywordTypeMap = {
26-
[blockKeyword]: 'replayedBlock',
27-
[validatingChunkKeyword]: 'validatingChunk',
28-
[validatedChunkKeyword]: 'validatingChunk',
29-
[ledgerKeyword]: 'pushingLedger',
24+
const keywordTypeMap: Record<string, GetBlockSyncProgressType> = {
25+
[blockKeyword]: BlockSyncType.replayedBlock,
26+
[validatingChunkKeyword]: BlockSyncType.validatingChunk,
27+
[validatedChunkKeyword]: BlockSyncType.validatingChunk,
28+
[ledgerKeyword]: BlockSyncType.pushingLedger,
3029
};
3130

3231
function containProgressKeywords(line: string) {
@@ -43,6 +42,8 @@ function getProgressType(line: string): GetBlockSyncProgressType | null {
4342
return keywordTypeMap[key];
4443
}
4544

45+
const applicationStartDate = moment.utc();
46+
4647
export const handleCheckBlockReplayProgress = (
4748
mainWindow: BrowserWindow,
4849
logsDirectoryPath: string
@@ -59,7 +60,10 @@ export const handleCheckBlockReplayProgress = (
5960
const progress = [];
6061

6162
for await (const line of rl) {
62-
if (containProgressKeywords(line)) {
63+
if (
64+
containProgressKeywords(line) &&
65+
isItFreshLog(applicationStartDate, line)
66+
) {
6367
progress.push(line);
6468
}
6569
}
Lines changed: 12 additions & 0 deletions
Loading
Lines changed: 12 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)