Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DDW-780] Daedalus start impovement #2716

Merged
merged 27 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
08d8a75
[DDW-780] Added more checks before restarting cardano-node
danielmain Oct 20, 2021
5a55f9d
[DDW-780] Added new entry in CHANGELOG
danielmain Oct 20, 2021
ab89f05
[DDW-780] Unused file
danielmain Oct 20, 2021
fbee12d
[DDW-780] Added try/catch on restart
danielmain Oct 21, 2021
5db6339
[DDW-780] Extend the node exit/kill/update timeouts to 5 mins
nikolaglumac Oct 21, 2021
39e5c1a
Merge branch 'develop' into chore/ddw-780-improve-startup-diskspace-c…
danielmain Oct 21, 2021
d32b321
[DDW-780] Fixed cardanoNode restart if diskspace problems happens at …
danielmain Oct 22, 2021
32550a5
[DDW-780] Added code review suggestions
Oct 25, 2021
53691ab
[DDW-780] Code refactoring
Oct 25, 2021
0ee60f6
[DDW-780] Increase kill node timeout
nikolaglumac Oct 26, 2021
a816848
[DDW-780] DISK_SPACE_REQUIRED back to original value
Oct 26, 2021
20657b7
[DDW-780] Removed unused code
Oct 26, 2021
7f0bf03
[DDW-780] handling errors like other places
Oct 26, 2021
60d0670
[DDW-780] Refactoring
Oct 26, 2021
67790e9
[DDW-780] Fix CardanoNode start
Oct 28, 2021
ed0a7cc
Merge branch 'develop' into chore/ddw-780-improve-startup-diskspace-c…
Oct 28, 2021
a531688
[DDW-780] Rebuilds menus after start-recovery
Nov 9, 2021
fbe3a84
[DDW-780] Refactoring of logic depending on the situation
Nov 10, 2021
1c95ced
[DDW-780] Fix condition
Nov 10, 2021
5b12c55
[DDW-780] Added logs
Nov 10, 2021
219047a
[DDW-780] Fixed first cardano-node start
Nov 10, 2021
63c5ef7
[DDW-780] Reorder menu build handlers
nikolaglumac Nov 10, 2021
5a8246b
[DDW-780] removed logs
Nov 10, 2021
9d706c7
Merge branch 'develop' into chore/ddw-780-improve-startup-diskspace-c…
Nov 10, 2021
5438fcf
[DDW-780] removed more logs
Nov 10, 2021
a1ad446
[DDW-780] fixed prettier errors
Nov 10, 2021
fc85a37
[DDW-780] Fix state dir path channel
nikolaglumac Nov 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .nonsense

This file was deleted.

2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## vNext

### Features

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

### Chores

- Improves the Daedalus startup by avoiding unnecessary cardano-node restarts ([PR 2716](https://github.com/input-output-hk/daedalus/pull/2716))
- 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))
- Updated README with solution steps for the nix SSL issue ([PR 2727](https://github.com/input-output-hk/daedalus/pull/2727))
- Covered LedgerJS v4.0.0 breaking changes ([PR 2697](https://github.com/input-output-hk/daedalus/pull/2697))
Expand Down
1 change: 1 addition & 0 deletions source/common/types/no-disk-space.types.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export type CheckDiskSpaceResponse = {
diskSpaceMissing: string,
diskSpaceRecommended: string,
diskSpaceAvailable: string,
hadNotEnoughSpaceLeft: boolean,
};
76 changes: 31 additions & 45 deletions source/main/cardano/CardanoNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,18 @@ export class CardanoNode {
* @param log
* @param actions
* @param transitions
* @param config {CardanoNodeConfig}
*/
constructor(log: Logger, actions: Actions, transitions: StateTransitions) {
constructor(
log: Logger,
actions: Actions,
transitions: StateTransitions,
config: CardanoNodeConfig
) {
this._log = log;
this._actions = actions;
this._transitionListeners = transitions;
this._config = config;
}

/**
Expand All @@ -254,14 +261,10 @@ export class CardanoNode {
* Asks the node to reply with the current port.
* Transitions into STARTING state.
*
* @param config {CardanoNodeConfig}
* @param isForced {boolean}
* @returns {Promise<void>} resolves if the node could be started, rejects with error otherwise.
*/
start = async (
config: CardanoNodeConfig,
isForced: boolean = false
): Promise<void> => {
start = async (isForced: boolean = false): Promise<void> => {
const { _log } = this;

// Guards
Expand All @@ -273,29 +276,13 @@ export class CardanoNode {
});
return Promise.reject(new Error('CardanoNode: Cannot be started'));
}
if (this._isUnrecoverable(config) && !isForced) {
if (this._isUnrecoverable(this._config) && !isForced) {
_log.error('CardanoNode#start: Too many startup retries', {
startupTries: this._startupTries,
});
return Promise.reject(new Error('CardanoNode: Too many startup retries'));
}

// Setup
const {
// startupTimeout,
nodeConfig,
stateDir,
cluster,
tlsPath,
configPath,
syncTolerance,
cliBin,
isStaging,
metadataUrl,
} = config;

this._config = config;

this._startupTries++;
this._changeToState(CardanoNodeStates.STARTING);
_log.info(
Expand All @@ -313,7 +300,7 @@ export class CardanoNode {
},
{
size: '5M',
path: config.logFilePath,
path: this._config.logFilePath,
maxFiles: 4,
}
);
Expand All @@ -328,7 +315,7 @@ export class CardanoNode {
},
{
size: '5M',
path: config.logFilePath,
path: this._config.logFilePath,
maxFiles: 4,
}
);
Expand Down Expand Up @@ -356,7 +343,7 @@ export class CardanoNode {
{ error }
);
const { code, signal } = error || {};
this._handleCardanoNodeError(code, signal);
await this._handleCardanoNodeError(code, signal);
reject(
new Error(
'CardanoNode#start: Unable to initialize cardano-launcher'
Expand All @@ -366,18 +353,10 @@ export class CardanoNode {
} else {
try {
const node = await CardanoWalletLauncher({
...this._config,
nodeImplementation,
nodeConfig,
cluster,
stateDir,
tlsPath,
configPath,
syncTolerance,
nodeLogFile,
walletLogFile,
cliBin,
isStaging,
metadataUrl,
});

this._node = node;
Expand Down Expand Up @@ -424,15 +403,15 @@ export class CardanoNode {
});
resolve();
})
.catch((exitStatus) => {
.catch(async (exitStatus) => {
_log.error(
'CardanoNode#start: Error while spawning cardano-node',
{
exitStatus,
}
);
const { code, signal } = exitStatus.wallet || {};
this._handleCardanoNodeError(code, signal);
await this._handleCardanoNodeError(code, signal);
reject(
new Error(
'CardanoNode#start: Error while spawning cardano-node'
Expand All @@ -447,7 +426,7 @@ export class CardanoNode {
}
);
const { code, signal } = error || {};
this._handleCardanoNodeError(code, signal);
await this._handleCardanoNodeError(code, signal);
reject(
new Error(
'CardanoNode#start: Unable to initialize cardano-launcher'
Expand Down Expand Up @@ -477,6 +456,7 @@ export class CardanoNode {
if (_node) await _node.stop(_config.shutdownTimeout / 1000);
await this._waitForNodeProcessToExit(_config.shutdownTimeout);
await this._storeProcessStates();
this._changeToState(CardanoNodeStates.STOPPED);
this._reset();
return Promise.resolve();
} catch (error) {
Expand Down Expand Up @@ -529,7 +509,7 @@ export class CardanoNode {
* @returns {Promise<void>} resolves if the node could be restarted, rejects with error otherwise.
*/
async restart(isForced: boolean = false): Promise<void> {
const { _log, _config } = this;
const { _log } = this;
try {
// Stop cardano nicely if it is still awake
if (this._isConnected()) {
Expand All @@ -546,14 +526,13 @@ export class CardanoNode {
});
safeExitWithCode(0);
} else {
await this.start(_config, isForced);
await this.start(isForced);
}
} catch (error) {
_log.error('CardanoNode#restart: Could not restart cardano-node', {
error,
});
_log.error('CardanoNode#restart: Could not restart cardano-node', error);
if (this._state !== CardanoNodeStates.UNRECOVERABLE) {
this._changeToState(CardanoNodeStates.ERRORED);
const { code, signal } = error || {};
this._changeToState(CardanoNodeStates.ERRORED, code, signal);
}
return Promise.reject(error);
}
Expand Down Expand Up @@ -706,7 +685,12 @@ export class CardanoNode {
} else {
this._changeToState(CardanoNodeStates.ERRORED);
this._transitionListeners.onError(code, signal);
await this.restart();
try {
_log.info('CardanoNode: restarting');
await this.restart();
danielmain marked this conversation as resolved.
Show resolved Hide resolved
} catch (error) {
_log.error('CardanoNode: cannot be restarted', error);
}
}
};

Expand Down Expand Up @@ -780,6 +764,8 @@ export class CardanoNode {
return _transitionListeners.onUpdated();
case CardanoNodeStates.CRASHED:
return _transitionListeners.onCrashed(...args);
case CardanoNodeStates.ERRORED:
return _transitionListeners.onError(...args);
case CardanoNodeStates.UNRECOVERABLE:
return _transitionListeners.onUnrecoverable();
default:
Expand Down
53 changes: 23 additions & 30 deletions source/main/cardano/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,25 @@ import {
} from '../ipc/cardano.ipc';
import { safeExitWithCode } from '../utils/safeExitWithCode';

const startCardanoNode = (
node: CardanoNode,
launcherConfig: LauncherConfig
) => {
const restartCardanoNode = async (node: CardanoNode) => {
try {
await node.restart();
} catch (error) {
logger.error('Could not restart CardanoNode', { error });
}
};

/**
* Configures, starts and manages the CardanoNode responding to node
* state changes, app events and IPC messages coming from the renderer.
*
* @param launcherConfig {LauncherConfig}
* @param mainWindow
*/
export const setupCardanoNode = (
launcherConfig: LauncherConfig,
mainWindow: BrowserWindow
): CardanoNode => {
const {
logsPrefix,
nodeImplementation,
Expand Down Expand Up @@ -70,28 +85,7 @@ const startCardanoNode = (
killTimeout: NODE_KILL_TIMEOUT,
updateTimeout: NODE_UPDATE_TIMEOUT,
};
return node.start(config);
};

const restartCardanoNode = async (node: CardanoNode) => {
try {
await node.restart();
} catch (error) {
logger.error('Could not restart CardanoNode', { error });
}
};

/**
* Configures, starts and manages the CardanoNode responding to node
* state changes, app events and IPC messages coming from the renderer.
*
* @param launcherConfig {LauncherConfig}
* @param mainWindow
*/
export const setupCardanoNode = (
launcherConfig: LauncherConfig,
mainWindow: BrowserWindow
): CardanoNode => {
const cardanoNode = new CardanoNode(
logger,
{
Expand All @@ -100,9 +94,9 @@ export const setupCardanoNode = (
exec,
readFileSync,
createWriteStream,
broadcastTlsConfig: (config: ?TlsConfig) => {
broadcastTlsConfig: (tlsConfig: ?TlsConfig) => {
if (!mainWindow.isDestroyed())
cardanoTlsConfigChannel.send(config, mainWindow);
cardanoTlsConfigChannel.send(tlsConfig, mainWindow);
},
broadcastStateChange: (state: CardanoNodeState) => {
if (!mainWindow.isDestroyed())
Expand All @@ -127,11 +121,10 @@ export const setupCardanoNode = (
},
onError: () => {},
onUnrecoverable: () => {},
}
},
config
);

startCardanoNode(cardanoNode, launcherConfig);

getCachedCardanoStatusChannel.onRequest(() => {
logger.info('ipcMain: Received request from renderer for cardano status', {
status: cardanoNode.status,
Expand Down
6 changes: 3 additions & 3 deletions source/main/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ export const MAX_LAUNCHER_LOGS_ALLOWED = 3;
// CardanoNode config
export const NODE_STARTUP_TIMEOUT = 5000;
export const NODE_STARTUP_MAX_RETRIES = 5;
export const NODE_SHUTDOWN_TIMEOUT = isTest ? 5000 : 10000;
export const NODE_KILL_TIMEOUT = isTest ? 5000 : 10000;
export const NODE_UPDATE_TIMEOUT = isTest ? 10000 : 60000;
export const NODE_SHUTDOWN_TIMEOUT = isTest ? 5000 : 5 * 60 * 1000; // 5 minutes | unit: milliseconds
export const NODE_KILL_TIMEOUT = isTest ? 5000 : 5 * 60 * 1000; // 5 minutes | unit: milliseconds
export const NODE_UPDATE_TIMEOUT = isTest ? 10000 : 5 * 60 * 1000; // 5 minutes | unit: milliseconds

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