Skip to content

Commit

Permalink
fix(report): update report generator to use epoch start and end heigh…
Browse files Browse the repository at this point in the history
…t based on values from contract

These are hard coded so they do not match the contract. Updates interfaces to specifically provide on for epoch purposes
  • Loading branch information
dtfiedler authored and djwhitt committed Jan 10, 2024
1 parent 1977c84 commit f7deecb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
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

0 comments on commit f7deecb

Please sign in to comment.