Skip to content
Permalink
Browse files

[DDW-684] Improve NTP handling

  • Loading branch information...
daniloprates committed Jul 11, 2019
1 parent 5921385 commit 7a8ae15c865d67331bda42c6fc8ef3bbceb12a2f
@@ -12,3 +12,4 @@ export const SIMPLE_DECIMAL_PLACES_IN_ADA = 2;
export const UNSYNCED_BLOCKS_ALLOWED = 6;
export const TX_UNCONFIRMED_THRESHOLD = 6;
export const TX_AGE_POLLING_THRESHOLD = 15 * 60 * 1000; // 15 minutes | unit: milliseconds
export const NTP_CHECKS_BEFORE_ERROR_OVERLAY = 3;
@@ -15,6 +15,7 @@ export const MAX_ALLOWED_STALL_DURATION = isTest ? 15000 : 2 * 60 * 1000; // 2 m
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_IGNORE_CHECKS_GRACE_PERIOD = isTest ? 500 : 35 * 1000; // 35 seconds | unit: milliseconds
export const NTP_CHECKS_BEFORE_ERROR_OVERLAY_INTERVAL = 1 * 1000; // 1 second | unit: milliseconds;
export const BLOCK_CONSOLIDATION_IPC_REQUEST_INTERVAL = 10 * 1000; // 10 seconds | unit: milliseconds
export const BLOCK_CONSOLIDATION_API_REQUEST_INTERVAL = 30 * 1000; // 30 seconds | unit: milliseconds
export const WALLET_UTXO_API_REQUEST_INTERVAL = 5 * 1000; // 5 seconds | unit: milliseconds
@@ -10,8 +10,12 @@ import {
NETWORK_STATUS_REQUEST_TIMEOUT,
NETWORK_STATUS_POLL_INTERVAL,
NTP_IGNORE_CHECKS_GRACE_PERIOD,
NTP_CHECKS_BEFORE_ERROR_OVERLAY_INTERVAL,
} from '../config/timingConfig';
import { UNSYNCED_BLOCKS_ALLOWED } from '../config/numbersConfig';
import {
UNSYNCED_BLOCKS_ALLOWED,
NTP_CHECKS_BEFORE_ERROR_OVERLAY,
} from '../config/numbersConfig';
import { Logger } from '../utils/logging';
import {
cardanoStateChangeChannel,
@@ -54,6 +58,7 @@ const NODE_STOPPED_STATES = [
CardanoNodeStates.UPDATED,
CardanoNodeStates.UNRECOVERABLE,
];

// END CONSTANTS ----------------------------

export default class NetworkStatusStore extends Store {
@@ -71,11 +76,14 @@ export default class NetworkStatusStore extends Store {
@observable isNodeResponding = false; // Is 'true' as long we are receiving node Api responses
@observable isNodeSubscribed = false; // Is 'true' in case node is subscribed to the network
@observable isNodeSyncing = false; // Is 'true' in case we are receiving blocks and not stalling
@observable isNodeTimeCorrect = true; // Is 'true' in case local and global time are in sync
@observable isNodeInSync = false; // 'true' if syncing & local/network blocks diff within limit
@observable isNodeStopping = false; // 'true' if node is in `NODE_STOPPING_STATES` states
@observable isNodeStopped = false; // 'true' if node is in `NODE_STOPPED_STATES` states

// NTP
@observable isNodeTimeCorrect = true; // Is 'true' in case local and global time are in sync
@observable numberOfNTPChecks = 0; // Is 'true' in case local and global time are in sync

@observable hasBeenConnected = false;
@observable syncProgress = null;
@observable initialLocalHeight = null;
@@ -392,9 +400,24 @@ export default class NetworkStatusStore extends Store {
// Update localTimeDifference only in case NTP check status is not still pending
if (localTimeInformation.status !== 'pending') {
this.localTimeDifference = localTimeInformation.difference;
this.isNodeTimeCorrect =
const isNodeTimeCorrect =
this.localTimeDifference != null && // If we receive 'null' it means NTP check failed
this.localTimeDifference <= ALLOWED_TIME_DIFFERENCE;

if (
!isNodeTimeCorrect &&
this.isNodeTimeCorrect &&
this.numberOfNTPChecks < NTP_CHECKS_BEFORE_ERROR_OVERLAY
) {
this.numberOfNTPChecks++;
setTimeout(
this.forceCheckLocalTimeDifference,
NTP_CHECKS_BEFORE_ERROR_OVERLAY_INTERVAL
);
} else {
this.numberOfNTPChecks = 0;
this.isNodeTimeCorrect = isNodeTimeCorrect;
}
}
});

0 comments on commit 7a8ae15

Please sign in to comment.
You can’t perform that action at this time.