Permalink
Browse files

[DDW-256] Prevent NTP force check polling while there is not enough d…

…isk-space, Fix failing acceptance tests
  • Loading branch information...
nikolaglumac committed Jan 11, 2019
2 parents 13bf4a6 + 948c8a5 commit 38553507053f4ca5e497c3bac792745fb0eb9d29
@@ -6,6 +6,7 @@ Changelog
### Features

- Implemented a better handling for "No disk space" error ([PR 1157](https://github.com/input-output-hk/daedalus/pull/1157))
- Improved the NTP check logic ([PR 1258](https://github.com/input-output-hk/daedalus/pull/1258))
- Added support for "frontend-only" mode ([PR 1241](https://github.com/input-output-hk/daedalus/pull/1241), [PR 1260](https://github.com/input-output-hk/daedalus/pull/1260))
- Improved the lock-file UX by replacing "Daedalus is already running" dialog with focusing of the already running Daedalus instance ([PR 1229](https://github.com/input-output-hk/daedalus/pull/1229))
- Replaced in-app support request with links to support page ([PR 1199](https://github.com/input-output-hk/daedalus/pull/1199))
@@ -17,7 +17,8 @@ export const handleDiskSpace = (
mainWindow: BrowserWindow,
onCheckDiskSpace?: Function,
) => {
const path = environment.isWindows ? 'C:' : '/';
const { isWindows, isTest } = environment;
const path = isWindows ? 'C:' : '/';
let diskSpaceCheckInterval;

const handleCheckDiskSpace = async (forceDiskSpaceRequired?: number) => {
@@ -31,7 +32,11 @@ export const handleDiskSpace = (

let isNotEnoughDiskSpace = false;
if (diskSpaceAvailable <= diskSpaceRequiredMargin) {
if (!isNotEnoughDiskSpace) setDiskSpaceIntervalChecking(DISK_SPACE_CHECK_SHORT_INTERVAL);
if (!isNotEnoughDiskSpace) {
setDiskSpaceIntervalChecking(
isTest ? 1000 : DISK_SPACE_CHECK_SHORT_INTERVAL
);
}
isNotEnoughDiskSpace = true;
} else if (diskSpaceAvailable >= diskSpaceRequired) {
if (isNotEnoughDiskSpace) setDiskSpaceIntervalChecking(DISK_SPACE_CHECK_LONG_INTERVAL);
@@ -234,7 +234,7 @@ export default class NetworkStatus extends Component<Props, State> {
</span> |&nbsp;
<button
onClick={() => onForceCheckLocalTimeDifference()}
disabled={isForceCheckingNodeTime}
disabled={isForceCheckingNodeTime || !isConnected}
>
{isForceCheckingNodeTime ? 'Checking...' : 'Check time'}
</button>
@@ -11,3 +11,4 @@ export const MAX_ALLOWED_STALL_DURATION = 2 * 60 * 1000; // 2 minutes | unit: mi
export const NETWORK_STATUS_REQUEST_TIMEOUT = 30 * 1000; // 30 seconds | unit: milliseconds
export const NETWORK_STATUS_POLL_INTERVAL = 2000; // 2 seconds | unit: milliseconds
export const NTP_FORCE_CHECK_POLL_INTERVAL = 30 * 60 * 1000; // 30 minutes | unit: milliseconds
export const NTP_IGNORE_CHECKS_GRACE_PERIOD = 30 * 1000; // 30 seconds | unit: milliseconds
@@ -10,6 +10,7 @@ import {
NETWORK_STATUS_REQUEST_TIMEOUT,
NETWORK_STATUS_POLL_INTERVAL,
NTP_FORCE_CHECK_POLL_INTERVAL,
NTP_IGNORE_CHECKS_GRACE_PERIOD,
} from '../config/timingConfig';
import { UNSYNCED_BLOCKS_ALLOWED } from '../config/numbersConfig';
import { Logger } from '../utils/logging';
@@ -82,6 +83,9 @@ export default class NetworkStatusStore extends Store {
setup() {
// ========== IPC CHANNELS =========== //

// Request node state
this._requestCardanoState();

// Request cached node status for fast bootstrapping of frontend
this._requestCardanoStatus();

@@ -95,17 +99,23 @@ export default class NetworkStatusStore extends Store {
// ========== MOBX REACTIONS =========== //

this.registerReactions([
this._updateNetworkStatusWhenConnected,
this._updateNetworkStatusWhenDisconnected,
this._updateNodeStatus,
]);

// Setup polling intervals
this._setNetworkStatusPollingInterval();
this._setForceCheckTimeDifferencePollingInterval();

// Forced time difference check polling interval
this._forceCheckTimeDifferencePollingInterval = setInterval(
this.forceCheckLocalTimeDifference, NTP_FORCE_CHECK_POLL_INTERVAL
// Ignore system time checks for the first 30 seconds:
this.ignoreSystemTimeChecks();
setTimeout(
() => this.ignoreSystemTimeChecks(false),
this.environment.isTest ? 1000 : NTP_IGNORE_CHECKS_GRACE_PERIOD
);

// Setup disk space checks
getDiskSpaceStatusChannel.onReceive(this._onCheckDiskSpace);
this._checkDiskSpace();
}
@@ -115,7 +125,14 @@ export default class NetworkStatusStore extends Store {
this._networkStatusPollingInterval = setInterval(
this._updateNetworkStatus, NETWORK_STATUS_POLL_INTERVAL
);
}
};

// Setup forced time difference check polling interval
_setForceCheckTimeDifferencePollingInterval = () => {
this._forceCheckTimeDifferencePollingInterval = setInterval(
this.forceCheckLocalTimeDifference, NTP_FORCE_CHECK_POLL_INTERVAL
);
};

async restartNode() {
try {
@@ -144,6 +161,13 @@ export default class NetworkStatusStore extends Store {
if (!this.isConnected) this._updateNetworkStatus();
};

_updateNetworkStatusWhenConnected = () => {
if (this.isConnected) {
Logger.info('NetworkStatusStore: Connected, forcing NTP check now...');
this._updateNetworkStatus({ force_ntp_check: true });
}
};

_updateNodeStatus = async () => {
if (!this.isConnected) return;
try {
@@ -164,11 +188,16 @@ export default class NetworkStatusStore extends Store {
getDiskSpaceStatusChannel.send(diskSpaceRequired);
}

_requestCardanoState = async () => {
Logger.info('NetworkStatusStore: requesting node state.');
const state = await cardanoStateChangeChannel.request();
Logger.info(`NetworkStatusStore: handling node state <${state}>.`);
await this._handleCardanoNodeStateChange(state);
};

_requestCardanoStatus = async () => {
try {
Logger.info('NetworkStatusStore: requesting node status.');
const state = await cardanoStateChangeChannel.request();
await this._handleCardanoNodeStateChange(state);
const status = await cardanoStatusChannel.request();
Logger.info(`NetworkStatusStore: received cached node status: ${JSON.stringify(status)}`);
if (status) runInAction('assigning node status', () => Object.assign(this, status));
@@ -443,12 +472,12 @@ export default class NetworkStatusStore extends Store {
}
};

@action ignoreSystemTimeChecks = () => {
this.isSystemTimeIgnored = true;
@action ignoreSystemTimeChecks = (flag: boolean = true) => {
this.isSystemTimeIgnored = flag;
};

forceCheckLocalTimeDifference = () => {
this._updateNetworkStatus({ force_ntp_check: true });
if (this.isConnected) this._updateNetworkStatus({ force_ntp_check: true });
};

@action _onCheckDiskSpace = (
@@ -469,8 +498,17 @@ export default class NetworkStatusStore extends Store {
clearInterval(this._networkStatusPollingInterval);
this._networkStatusPollingInterval = null;
}
} else if (!this._networkStatusPollingInterval) {
this._setNetworkStatusPollingInterval();
if (this._forceCheckTimeDifferencePollingInterval) {
clearInterval(this._forceCheckTimeDifferencePollingInterval);
this._forceCheckTimeDifferencePollingInterval = null;
}
} else {
if (!this._networkStatusPollingInterval) {
this._setNetworkStatusPollingInterval();
}
if (!this._forceCheckTimeDifferencePollingInterval) {
this._setForceCheckTimeDifferencePollingInterval();
}
}

return Promise.resolve();
@@ -538,8 +538,7 @@ export default class WalletsStore extends Store {
) => {
const locale = this.stores.profile.currentLocale;
const intl = i18nContext(locale);
const isMainnet = this.environment.isMainnet;
const buildLabel = this.environment.buildLabel;
const { isMainnet, buildLabel } = this.environment;
try {
await downloadPaperWalletCertificate({
address,

0 comments on commit 3855350

Please sign in to comment.