Skip to content

Commit 5b329b9

Browse files
danielmainnikolaglumacDaniel Main
authored
[DDW-780] Daedalus start impovement (#2716)
* [DDW-780] Added more checks before restarting cardano-node * [DDW-780] Added new entry in CHANGELOG * [DDW-780] Unused file * [DDW-780] Added try/catch on restart * [DDW-780] Extend the node exit/kill/update timeouts to 5 mins * [DDW-780] Fixed cardanoNode restart if diskspace problems happens at the first time * [DDW-780] Added code review suggestions * [DDW-780] Code refactoring * [DDW-780] Increase kill node timeout * [DDW-780] DISK_SPACE_REQUIRED back to original value * [DDW-780] Removed unused code * [DDW-780] handling errors like other places * [DDW-780] Refactoring * [DDW-780] Fix CardanoNode start * [DDW-780] Rebuilds menus after start-recovery * [DDW-780] Refactoring of logic depending on the situation * [DDW-780] Fix condition * [DDW-780] Added logs * [DDW-780] Fixed first cardano-node start * [DDW-780] Reorder menu build handlers * [DDW-780] removed logs * [DDW-780] removed more logs * [DDW-780] fixed prettier errors * [DDW-780] Fix state dir path channel Co-authored-by: Nikola Glumac <[email protected]> Co-authored-by: Daniel Main <[email protected]>
1 parent e9623ec commit 5b329b9

File tree

9 files changed

+167
-157
lines changed

9 files changed

+167
-157
lines changed

.nonsense

Lines changed: 0 additions & 3 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## vNext
44

55
### Features
6+
67
- Implemented "Catalyst Fund7" voting registration changes ([PR 2732](https://github.com/input-output-hk/daedalus/pull/2732))
78
- Added Over-saturation warning in delegation wizard ([PR 2733](https://github.com/input-output-hk/daedalus/pull/2733))
89
- Added Catalyst footer links ([PR 2721](https://github.com/input-output-hk/daedalus/pull/2721))
@@ -18,6 +19,7 @@
1819

1920
### Chores
2021

22+
- Improves the Daedalus startup by avoiding unnecessary cardano-node restarts ([PR 2716](https://github.com/input-output-hk/daedalus/pull/2716))
2123
- Updated `cardano-launcher` to version `0.20211105.1` and added Cardano Node RTS flags which improve resource usage ([PR 2734](https://github.com/input-output-hk/daedalus/pull/2734))
2224
- Updated README with solution steps for the nix SSL issue ([PR 2727](https://github.com/input-output-hk/daedalus/pull/2727))
2325
- Covered LedgerJS v4.0.0 breaking changes ([PR 2697](https://github.com/input-output-hk/daedalus/pull/2697))

source/common/types/no-disk-space.types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ export type CheckDiskSpaceResponse = {
55
diskSpaceMissing: string,
66
diskSpaceRecommended: string,
77
diskSpaceAvailable: string,
8+
hadNotEnoughSpaceLeft: boolean,
89
};

source/main/cardano/CardanoNode.js

Lines changed: 31 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,18 @@ export class CardanoNode {
240240
* @param log
241241
* @param actions
242242
* @param transitions
243+
* @param config {CardanoNodeConfig}
243244
*/
244-
constructor(log: Logger, actions: Actions, transitions: StateTransitions) {
245+
constructor(
246+
log: Logger,
247+
actions: Actions,
248+
transitions: StateTransitions,
249+
config: CardanoNodeConfig
250+
) {
245251
this._log = log;
246252
this._actions = actions;
247253
this._transitionListeners = transitions;
254+
this._config = config;
248255
}
249256

250257
/**
@@ -254,14 +261,10 @@ export class CardanoNode {
254261
* Asks the node to reply with the current port.
255262
* Transitions into STARTING state.
256263
*
257-
* @param config {CardanoNodeConfig}
258264
* @param isForced {boolean}
259265
* @returns {Promise<void>} resolves if the node could be started, rejects with error otherwise.
260266
*/
261-
start = async (
262-
config: CardanoNodeConfig,
263-
isForced: boolean = false
264-
): Promise<void> => {
267+
start = async (isForced: boolean = false): Promise<void> => {
265268
const { _log } = this;
266269

267270
// Guards
@@ -273,29 +276,13 @@ export class CardanoNode {
273276
});
274277
return Promise.reject(new Error('CardanoNode: Cannot be started'));
275278
}
276-
if (this._isUnrecoverable(config) && !isForced) {
279+
if (this._isUnrecoverable(this._config) && !isForced) {
277280
_log.error('CardanoNode#start: Too many startup retries', {
278281
startupTries: this._startupTries,
279282
});
280283
return Promise.reject(new Error('CardanoNode: Too many startup retries'));
281284
}
282285

283-
// Setup
284-
const {
285-
// startupTimeout,
286-
nodeConfig,
287-
stateDir,
288-
cluster,
289-
tlsPath,
290-
configPath,
291-
syncTolerance,
292-
cliBin,
293-
isStaging,
294-
metadataUrl,
295-
} = config;
296-
297-
this._config = config;
298-
299286
this._startupTries++;
300287
this._changeToState(CardanoNodeStates.STARTING);
301288
_log.info(
@@ -313,7 +300,7 @@ export class CardanoNode {
313300
},
314301
{
315302
size: '5M',
316-
path: config.logFilePath,
303+
path: this._config.logFilePath,
317304
maxFiles: 4,
318305
}
319306
);
@@ -328,7 +315,7 @@ export class CardanoNode {
328315
},
329316
{
330317
size: '5M',
331-
path: config.logFilePath,
318+
path: this._config.logFilePath,
332319
maxFiles: 4,
333320
}
334321
);
@@ -356,7 +343,7 @@ export class CardanoNode {
356343
{ error }
357344
);
358345
const { code, signal } = error || {};
359-
this._handleCardanoNodeError(code, signal);
346+
await this._handleCardanoNodeError(code, signal);
360347
reject(
361348
new Error(
362349
'CardanoNode#start: Unable to initialize cardano-launcher'
@@ -366,18 +353,10 @@ export class CardanoNode {
366353
} else {
367354
try {
368355
const node = await CardanoWalletLauncher({
356+
...this._config,
369357
nodeImplementation,
370-
nodeConfig,
371-
cluster,
372-
stateDir,
373-
tlsPath,
374-
configPath,
375-
syncTolerance,
376358
nodeLogFile,
377359
walletLogFile,
378-
cliBin,
379-
isStaging,
380-
metadataUrl,
381360
});
382361

383362
this._node = node;
@@ -424,15 +403,15 @@ export class CardanoNode {
424403
});
425404
resolve();
426405
})
427-
.catch((exitStatus) => {
406+
.catch(async (exitStatus) => {
428407
_log.error(
429408
'CardanoNode#start: Error while spawning cardano-node',
430409
{
431410
exitStatus,
432411
}
433412
);
434413
const { code, signal } = exitStatus.wallet || {};
435-
this._handleCardanoNodeError(code, signal);
414+
await this._handleCardanoNodeError(code, signal);
436415
reject(
437416
new Error(
438417
'CardanoNode#start: Error while spawning cardano-node'
@@ -447,7 +426,7 @@ export class CardanoNode {
447426
}
448427
);
449428
const { code, signal } = error || {};
450-
this._handleCardanoNodeError(code, signal);
429+
await this._handleCardanoNodeError(code, signal);
451430
reject(
452431
new Error(
453432
'CardanoNode#start: Unable to initialize cardano-launcher'
@@ -477,6 +456,7 @@ export class CardanoNode {
477456
if (_node) await _node.stop(_config.shutdownTimeout / 1000);
478457
await this._waitForNodeProcessToExit(_config.shutdownTimeout);
479458
await this._storeProcessStates();
459+
this._changeToState(CardanoNodeStates.STOPPED);
480460
this._reset();
481461
return Promise.resolve();
482462
} catch (error) {
@@ -529,7 +509,7 @@ export class CardanoNode {
529509
* @returns {Promise<void>} resolves if the node could be restarted, rejects with error otherwise.
530510
*/
531511
async restart(isForced: boolean = false): Promise<void> {
532-
const { _log, _config } = this;
512+
const { _log } = this;
533513
try {
534514
// Stop cardano nicely if it is still awake
535515
if (this._isConnected()) {
@@ -546,14 +526,13 @@ export class CardanoNode {
546526
});
547527
safeExitWithCode(0);
548528
} else {
549-
await this.start(_config, isForced);
529+
await this.start(isForced);
550530
}
551531
} catch (error) {
552-
_log.error('CardanoNode#restart: Could not restart cardano-node', {
553-
error,
554-
});
532+
_log.error('CardanoNode#restart: Could not restart cardano-node', error);
555533
if (this._state !== CardanoNodeStates.UNRECOVERABLE) {
556-
this._changeToState(CardanoNodeStates.ERRORED);
534+
const { code, signal } = error || {};
535+
this._changeToState(CardanoNodeStates.ERRORED, code, signal);
557536
}
558537
return Promise.reject(error);
559538
}
@@ -706,7 +685,12 @@ export class CardanoNode {
706685
} else {
707686
this._changeToState(CardanoNodeStates.ERRORED);
708687
this._transitionListeners.onError(code, signal);
709-
await this.restart();
688+
try {
689+
_log.info('CardanoNode: restarting');
690+
await this.restart();
691+
} catch (error) {
692+
_log.error('CardanoNode: cannot be restarted', error);
693+
}
710694
}
711695
};
712696

@@ -780,6 +764,8 @@ export class CardanoNode {
780764
return _transitionListeners.onUpdated();
781765
case CardanoNodeStates.CRASHED:
782766
return _transitionListeners.onCrashed(...args);
767+
case CardanoNodeStates.ERRORED:
768+
return _transitionListeners.onError(...args);
783769
case CardanoNodeStates.UNRECOVERABLE:
784770
return _transitionListeners.onUnrecoverable();
785771
default:

source/main/cardano/setup.js

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,25 @@ import {
3434
} from '../ipc/cardano.ipc';
3535
import { safeExitWithCode } from '../utils/safeExitWithCode';
3636

37-
const startCardanoNode = (
38-
node: CardanoNode,
39-
launcherConfig: LauncherConfig
40-
) => {
37+
const restartCardanoNode = async (node: CardanoNode) => {
38+
try {
39+
await node.restart();
40+
} catch (error) {
41+
logger.error('Could not restart CardanoNode', { error });
42+
}
43+
};
44+
45+
/**
46+
* Configures, starts and manages the CardanoNode responding to node
47+
* state changes, app events and IPC messages coming from the renderer.
48+
*
49+
* @param launcherConfig {LauncherConfig}
50+
* @param mainWindow
51+
*/
52+
export const setupCardanoNode = (
53+
launcherConfig: LauncherConfig,
54+
mainWindow: BrowserWindow
55+
): CardanoNode => {
4156
const {
4257
logsPrefix,
4358
nodeImplementation,
@@ -70,28 +85,7 @@ const startCardanoNode = (
7085
killTimeout: NODE_KILL_TIMEOUT,
7186
updateTimeout: NODE_UPDATE_TIMEOUT,
7287
};
73-
return node.start(config);
74-
};
75-
76-
const restartCardanoNode = async (node: CardanoNode) => {
77-
try {
78-
await node.restart();
79-
} catch (error) {
80-
logger.error('Could not restart CardanoNode', { error });
81-
}
82-
};
8388

84-
/**
85-
* Configures, starts and manages the CardanoNode responding to node
86-
* state changes, app events and IPC messages coming from the renderer.
87-
*
88-
* @param launcherConfig {LauncherConfig}
89-
* @param mainWindow
90-
*/
91-
export const setupCardanoNode = (
92-
launcherConfig: LauncherConfig,
93-
mainWindow: BrowserWindow
94-
): CardanoNode => {
9589
const cardanoNode = new CardanoNode(
9690
logger,
9791
{
@@ -100,9 +94,9 @@ export const setupCardanoNode = (
10094
exec,
10195
readFileSync,
10296
createWriteStream,
103-
broadcastTlsConfig: (config: ?TlsConfig) => {
97+
broadcastTlsConfig: (tlsConfig: ?TlsConfig) => {
10498
if (!mainWindow.isDestroyed())
105-
cardanoTlsConfigChannel.send(config, mainWindow);
99+
cardanoTlsConfigChannel.send(tlsConfig, mainWindow);
106100
},
107101
broadcastStateChange: (state: CardanoNodeState) => {
108102
if (!mainWindow.isDestroyed())
@@ -127,11 +121,10 @@ export const setupCardanoNode = (
127121
},
128122
onError: () => {},
129123
onUnrecoverable: () => {},
130-
}
124+
},
125+
config
131126
);
132127

133-
startCardanoNode(cardanoNode, launcherConfig);
134-
135128
getCachedCardanoStatusChannel.onRequest(() => {
136129
logger.info('ipcMain: Received request from renderer for cardano status', {
137130
status: cardanoNode.status,

source/main/config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ export const MAX_LAUNCHER_LOGS_ALLOWED = 3;
154154
// CardanoNode config
155155
export const NODE_STARTUP_TIMEOUT = 5000;
156156
export const NODE_STARTUP_MAX_RETRIES = 5;
157-
export const NODE_SHUTDOWN_TIMEOUT = isTest ? 5000 : 10000;
158-
export const NODE_KILL_TIMEOUT = isTest ? 5000 : 10000;
159-
export const NODE_UPDATE_TIMEOUT = isTest ? 10000 : 60000;
157+
export const NODE_SHUTDOWN_TIMEOUT = isTest ? 5000 : 5 * 60 * 1000; // 5 minutes | unit: milliseconds
158+
export const NODE_KILL_TIMEOUT = isTest ? 5000 : 5 * 60 * 1000; // 5 minutes | unit: milliseconds
159+
export const NODE_UPDATE_TIMEOUT = isTest ? 10000 : 5 * 60 * 1000; // 5 minutes | unit: milliseconds
160160

161161
export const DISK_SPACE_REQUIRED = 2 * 1073741274; // 2 GB | unit: bytes
162162
export const DISK_SPACE_REQUIRED_MARGIN_PERCENTAGE = 10; // 10% of the available disk space

0 commit comments

Comments
 (0)