Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 9 additions & 2 deletions packages/daemon/src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ import {
} from '../db';
import getConfig from '../config';
import logger from '../logger';
import { invokeOnTxPushNotificationRequestedLambda } from '../utils';
import { invokeOnTxPushNotificationRequestedLambda, getDaemonUptime } from '../utils';
import { addAlert, Severity } from '@wallet-service/common';
import { JSONBigInt } from '@hathor/wallet-lib/lib/utils/bigint';

Expand All @@ -92,6 +92,8 @@ export const METADATA_DIFF_EVENT_TYPES = {
TX_FIRST_BLOCK: 'TX_FIRST_BLOCK',
};

const DUPLICATE_TX_ALERT_GRACE_PERIOD = 10; // seconds

export const metadataDiff = async (_context: Context, event: Event) => {
const mysql = await getDbConnection();

Expand Down Expand Up @@ -223,7 +225,12 @@ export const handleVertexAccepted = async (context: Context, _event: Event) => {
const dbTx: DbTransaction | null = await getTransactionById(mysql, hash);

if (dbTx) {
logger.error(`Transaction ${hash} already in the database, this should only happen if the service has been recently restarted`);
const daemonUptime = getDaemonUptime();
// We do not log if the daemon has just started, because it's expected that
// we receive an initial duplicate transaction from the fullnode in this case.
if (daemonUptime < DUPLICATE_TX_ALERT_GRACE_PERIOD) return;

logger.error(`Transaction ${hash} already in the database and the daemon has not been recently restarted (uptime of ${daemonUptime} seconds). This is unexpected.`);

// This might happen if the service has been recently restarted,
// so we should raise the alert and just ignore the tx
Expand Down
12 changes: 12 additions & 0 deletions packages/daemon/src/utils/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,15 @@
export const getUnixTimestamp = (): number => (
Math.round((new Date()).getTime() / 1000)
);


const daemonStartTime = getUnixTimestamp();

/**
* Get the daemon uptime in seconds
*
* @returns The daemon uptime in seconds
*/
export const getDaemonUptime = (): number => (
getUnixTimestamp() - daemonStartTime
);