Skip to content

Commit

Permalink
change timeseries input to seconds from ms
Browse files Browse the repository at this point in the history
  • Loading branch information
g11tech committed Aug 1, 2022
1 parent fbcf640 commit c5ea976
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
5 changes: 2 additions & 3 deletions packages/beacon-node/src/node/notifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export async function runNodeNotifier(modules: NodeNotifierModules): Promise<voi
const finalizedEpoch = headState.finalizedCheckpoint.epoch;
const finalizedRoot = headState.finalizedCheckpoint.root;
const headSlot = headInfo.slot;
headSlotTimeSeries.addPoint(headSlot, Date.now());
headSlotTimeSeries.addPoint(headSlot, Math.floor(Date.now() / 1000));

const peersRow = `peers: ${connectedPeerCount}`;
const finalizedCheckpointRow = `finalized: ${prettyBytes(finalizedRoot)}:${finalizedEpoch}`;
Expand All @@ -71,8 +71,7 @@ export async function runNodeNotifier(modules: NodeNotifierModules): Promise<voi
// Notifier log lines must be kept at a reasonable max width otherwise it's very hard to read
const tdProgress = chain.eth1.getTDProgress();
if (tdProgress !== null && !tdProgress.ttdHit) {
// TimeSeries accept time in Ms while timestamp is in Sec
tdTimeSeries.addPoint(tdProgress.tdDiffScaled, tdProgress.timestamp * 1000);
tdTimeSeries.addPoint(tdProgress.tdDiffScaled, tdProgress.timestamp);

const timestampTDD = tdTimeSeries.computeY0Point();
// It is possible to get ttd estimate with an error at imminent merge
Expand Down
4 changes: 2 additions & 2 deletions packages/beacon-node/src/util/timeSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ export class TimeSeries {
}

/** Add TimeSeries entry for value at current time */
addPoint(value: number, timeMs = Date.now()): void {
addPoint(value: number, timeSec = Math.floor(Date.now() / 1000)): void {
// Substract initial time so x values are not big and cause rounding errors
const time = timeMs / 1000 - this.startTimeSec;
const time = timeSec - this.startTimeSec;
this.points.push([time, value]);

// Limit length by removing old entries
Expand Down
8 changes: 4 additions & 4 deletions packages/beacon-node/test/unit/util/timeSeries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ describe.skip("util / TimeSeries", () => {
it("Should correctly compute a linear sequence", () => {
const timeSeries = new TimeSeries();

const startTime = 1610190386014;
const startTime = 1610190386;
for (let i = 0; i < 4; i++) {
timeSeries.addPoint(100 + i, startTime + i * 1000);
timeSeries.addPoint(100 + i, startTime + i);
}

const valuePerSec = timeSeries.computeLinearSpeed();
Expand All @@ -21,10 +21,10 @@ describe.skip("util / TimeSeries", () => {
it("Should correctly do a linear regression", () => {
const timeSeries = new TimeSeries();

const startTime = 1610190386014;
const startTime = 1610190386;
for (let i = 1; i < 10; i++) {
// Add +1 or -1 so points are not in a perfect line but a regression should return 1
timeSeries.addPoint(100 + i + Math.pow(-1, i), startTime + i * 1000);
timeSeries.addPoint(100 + i + Math.pow(-1, i), startTime + i);
}

const valuePerSec = timeSeries.computeLinearSpeed();
Expand Down

0 comments on commit c5ea976

Please sign in to comment.