Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(report): update report generator to use epoch start and end heigh… #19

Merged
merged 1 commit into from
Jan 10, 2024
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: 5 additions & 6 deletions src/observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ import got from 'got';
import crypto from 'node:crypto';
import pMap from 'p-map';

import * as protocol from './protocol.js';
import {
ArnsNameAssessment,
ArnsNameAssessments,
ArnsNamesSource,
EpochHeightSource,
GatewayAssessments,
GatewayHostsSource,
HeightSource,
ObserverReport,
OwnershipAssessment,
} from './types.js';
Expand Down Expand Up @@ -160,7 +159,7 @@ async function assessOwnership({
export class Observer {
private observerAddress: string;
private referenceGatewayHost: string;
private epochHeightSource: HeightSource;
private epochHeightSource: EpochHeightSource;
private observedGatewayHostList: GatewayHostsSource;
private prescribedNamesSource: ArnsNamesSource;
private chosenNamesSource: ArnsNamesSource;
Expand All @@ -179,7 +178,7 @@ export class Observer {
}: {
observerAddress: string;
referenceGatewayHost: string;
epochHeightSource: HeightSource;
epochHeightSource: EpochHeightSource;
observedGatewayHostList: GatewayHostsSource;
prescribedNamesSource: ArnsNamesSource;
chosenNamesSource: ArnsNamesSource;
Expand Down Expand Up @@ -291,8 +290,8 @@ export class Observer {
}

async generateReport(): Promise<ObserverReport> {
const epochStartHeight = await this.epochHeightSource.getHeight();
const epochEndHeight = epochStartHeight + protocol.EPOCH_BLOCK_LENGTH - 1;
const epochStartHeight = await this.epochHeightSource.getEpochStartHeight();
const epochEndHeight = await this.epochHeightSource.getEpochEndHeight();
const prescribedNames = await this.prescribedNamesSource.getNames({
height: epochStartHeight,
});
Expand Down
17 changes: 14 additions & 3 deletions src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { HeightSource } from './types.js';
import {
HeightSource,
EpochHeightSource as IEpochHeightSource,
} from './types.js';

export const START_HEIGHT = 0;
export const EPOCH_BLOCK_LENGTH = 5000;
Expand Down Expand Up @@ -66,7 +69,7 @@ interface EpochParams {
epochBlockLength: number;
}

export class EpochHeightSource implements HeightSource {
export class EpochHeightSource implements IEpochHeightSource {
private heightSource: HeightSource;
private epochParams: EpochParams;

Expand All @@ -84,11 +87,19 @@ export class EpochHeightSource implements HeightSource {
this.epochParams = epochParams;
}

async getHeight(): Promise<number> {
async getEpochStartHeight(): Promise<number> {
const height = await this.heightSource.getHeight();
return getEpochStart({
...this.epochParams,
height,
});
}

async getEpochEndHeight(): Promise<number> {
const height = await this.heightSource.getHeight();
return getEpochEnd({
...this.epochParams,
height,
});
}
}
5 changes: 5 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export interface HeightSource {
getHeight(): Promise<number>;
}

export interface EpochHeightSource {
getEpochStartHeight(): Promise<number>;
getEpochEndHeight(): Promise<number>;
}

//
// Name selection
//
Expand Down
Loading