diff --git a/src/lib/nodes/ipfs/IpfsNode.ts b/src/lib/nodes/ipfs/IpfsNode.ts index c1953206a..5dd5a8cd1 100644 --- a/src/lib/nodes/ipfs/IpfsNode.ts +++ b/src/lib/nodes/ipfs/IpfsNode.ts @@ -3,6 +3,7 @@ import { NodeOfflineError } from '@/lib/nodes/utils/errors' import axios, { AxiosInstance, AxiosProgressEvent, AxiosRequestConfig, ResponseType } from 'axios' import { Node } from '@/lib/nodes/abstract.node' import { NODE_LABELS } from '@/lib/nodes/constants' +import { normalizeHeight } from './utils' type FetchNodeInfoResult = { availableSizeInMb: number @@ -117,9 +118,10 @@ export class IpfsNode extends Node { protected async checkHealth() { const time = Date.now() const { timestamp } = await this.fetchNodeInfo() + this.height = normalizeHeight(timestamp) return { - height: timestamp, + height: this.height, ping: Date.now() - time } } diff --git a/src/lib/nodes/ipfs/utils.ts b/src/lib/nodes/ipfs/utils.ts new file mode 100644 index 000000000..57fdcb9d8 --- /dev/null +++ b/src/lib/nodes/ipfs/utils.ts @@ -0,0 +1,14 @@ +/** + * Normalize the height to 8 digits. + * Rounds the timestamp to seconds and removes the first two digits. + * @param timestamp Timestamp in milliseconds + */ +export const normalizeHeight = (timestamp: number) => { + if (!timestamp) return 0 + + return Number( + Math.ceil(timestamp / 1000) + .toString() + .substring(2) + ) +}