Skip to content

Commit

Permalink
fix(report): continue to use epochStartHeight for report naming conve…
Browse files Browse the repository at this point in the history
…ntion to avoid collisions. This is to be consistent with previous naming conventions for report filenames, but it is important to note the epochStartHeight is provided by the contract for the epoch and not computed by the observer
  • Loading branch information
dtfiedler committed Jun 7, 2024
1 parent b40c1d4 commit 2cd0e1d
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/store/fs-report-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@
import fs from 'node:fs';
import * as winston from 'winston';

import {
ObserverReport,
ReportInfo,
ReportSink,
ReportStore,
} from '../types.js';

Check failure on line 21 in src/store/fs-report-store.ts

View workflow job for this annotation

GitHub Actions / build (lint:check)

Replace `⏎⏎import·{·ObserverReport,·ReportInfo,·ReportSink,·ReportStore·}·from·'../types.js';⏎` with `import·{⏎··ObserverReport,⏎··ReportInfo,⏎··ReportSink,⏎··ReportStore,⏎}·from·'../types.js';`

import { ObserverReport, ReportInfo, ReportSink, ReportStore } from '../types.js';


export class FsReportStore implements ReportSink, ReportStore {
// Dependencies
Expand All @@ -44,9 +42,10 @@ export class FsReportStore implements ReportSink, ReportStore {
const log = this.log.child({
epochStartTimestamp: report.epochStartTimestamp,
epochIndex: report.epochIndex,
epochStartHeight: report.epochStartHeight,
});

const savedReport = await this.getReport(report.epochIndex);
const savedReport = await this.getReport(report.epochStartHeight);
if (savedReport !== null) {
log.info('Using previously saved report');
report = savedReport;
Expand All @@ -56,13 +55,13 @@ export class FsReportStore implements ReportSink, ReportStore {
};
}

const reportFile = `${this.baseDir}/${report.epochIndex}.json`;
const reportFile = `${this.baseDir}/${report.epochStartHeight}.json`;
log.info('Saving report...', {
reportFile,
});
if (!fs.existsSync(reportFile)) {
await fs.promises.writeFile(
`./data/reports/${report.epochIndex}.json`,
`./data/reports/${report.epochStartHeight}.json`,
JSON.stringify(report),
);
}
Expand All @@ -73,8 +72,8 @@ export class FsReportStore implements ReportSink, ReportStore {
return reportInfo;
}

async getReport(epochIndex: number): Promise<ObserverReport | null> {
const reportFile = `./data/reports/${epochIndex}.json`;
async getReport(epochStartHeight: number): Promise<ObserverReport | null> {
const reportFile = `./data/reports/${epochStartHeight}.json`;
if (!fs.existsSync(reportFile)) {
return null;
}
Expand Down

0 comments on commit 2cd0e1d

Please sign in to comment.