Skip to content

Commit

Permalink
patches to coretime controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
filvecchiato committed Jan 3, 2025
1 parent 62523c1 commit 1c8dbe4
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 51 deletions.
6 changes: 3 additions & 3 deletions docs/src/openapi-v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3187,7 +3187,7 @@ components:
properties:
at:
$ref: '#/components/schemas/BlockIdentifiers'
regions:
leases:
type: array
items:
$ref: '#/components/schemas/CoretimeLease'
Expand All @@ -3196,7 +3196,7 @@ components:
properties:
at:
$ref: '#/components/schemas/BlockIdentifiers'
regions:
reservations:
type: array
items:
$ref: '#/components/schemas/CoretimeReservation'
Expand All @@ -3205,7 +3205,7 @@ components:
properties:
at:
$ref: '#/components/schemas/BlockIdentifiers'
regions:
renewals:
type: array
items:
$ref: '#/components/schemas/CoretimeRenewal'
Expand Down
1 change: 0 additions & 1 deletion src/chains-config/polkadotControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export const polkadotControllers: ControllerConfig = {
'TransactionFeeEstimate',
'TransactionMaterial',
'TransactionSubmit',
'CoretimeGeneric',
],
options: {
finalizes: true,
Expand Down
19 changes: 1 addition & 18 deletions src/controllers/coretime/CoretimeChainController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class CoretimeChainController extends AbstractController<Coretime
super(api, '/coretime', new CoretimeService(api));
this.initRoutes();
}
// TODO: check if its either coretime or relay chain, if neither error out

protected initRoutes(): void {
this.safeMountAsyncGetHandlers([
['/leases', this.getLeases], // :taskId
Expand All @@ -35,42 +35,25 @@ export default class CoretimeChainController extends AbstractController<Coretime
]);
}

private checkCoretimeModule = (): void => {
if (this.api.query.onDemandAssignmentProvider && this.api.query.coretimeAssignmentProvider) {
return;
} else if (this.api.query.broker) {
return;
}
throw new Error('One or more coretime modules are not available on this network.');
};

private getLeases: RequestHandler = async ({ query: { at } }, res): Promise<void> => {
this.checkCoretimeModule();

const hash = await this.getHashFromAt(at);

CoretimeChainController.sanitizedSend(res, await this.service.getCoretimeLeases(hash));
};

private getRegions: RequestHandler = async ({ query: { at } }, res): Promise<void> => {
this.checkCoretimeModule();

const hash = await this.getHashFromAt(at);

CoretimeChainController.sanitizedSend(res, await this.service.getCoretimeRegions(hash));
};

private getReservations: RequestHandler = async ({ query: { at } }, res): Promise<void> => {
this.checkCoretimeModule();

const hash = await this.getHashFromAt(at);

CoretimeChainController.sanitizedSend(res, await this.service.getCoretimeReservations(hash));
};

private getRenewals: RequestHandler = async ({ query: { at } }, res): Promise<void> => {
this.checkCoretimeModule();

const hash = await this.getHashFromAt(at);

CoretimeChainController.sanitizedSend(res, await this.service.getCoretimeRenewals(hash));
Expand Down
15 changes: 1 addition & 14 deletions src/controllers/coretime/CoretimeGenericController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class CoretimeGenericController extends AbstractController<Coreti
super(api, '/coretime', new CoretimeService(api));
this.initRoutes();
}
// TODO: check if its either coretime or relay chain, if neither error out

protected initRoutes(): void {
this.safeMountAsyncGetHandlers([
['/info', this.getCoretimeOverview],
Expand All @@ -34,27 +34,14 @@ export default class CoretimeGenericController extends AbstractController<Coreti
}

private getCoretimeOverview: RequestHandler = async ({ query: { at } }, res): Promise<void> => {
this.checkCoretimeModule();

const hash = await this.getHashFromAt(at);

CoretimeGenericController.sanitizedSend(res, await this.service.getCoretimeInfo(hash));
};

private getCoretimeCores: RequestHandler = async ({ query: { at } }, res): Promise<void> => {
this.checkCoretimeModule();

const hash = await this.getHashFromAt(at);

CoretimeGenericController.sanitizedSend(res, await this.service.getCoretimeCores(hash));
};

private checkCoretimeModule = (): void => {
if (this.api.query.onDemandAssignmentProvider && this.api.query.coretimeAssignmentProvider) {
return;
} else if (this.api.query.broker) {
return;
}
throw new Error('One or more coretime modules are not available on this network.');
};
}
18 changes: 3 additions & 15 deletions src/services/coretime/CoretimeService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-unsafe-call */
/* eslint-disable @typescript-eslint/no-unsafe-return */
// Copyright 2017-2024 Parity Technologies (UK) Ltd.
// Copyright 2017-2025 Parity Technologies (UK) Ltd.
// This file is part of Substrate API Sidecar.
//
// Substrate API Sidecar is free software: you can redistribute it and/or modify
Expand All @@ -21,15 +21,6 @@ import type { ApiDecoration, QueryableModuleStorage } from '@polkadot/api/types'
import type { Option, StorageKey, U32 } from '@polkadot/types';
import type { BlockHash, ParaId } from '@polkadot/types/interfaces';
import type {
// PalletBrokerConfigRecord,
// PalletBrokerLeaseRecordItem,
// PalletBrokerPotentialRenewalId,
// PalletBrokerPotentialRenewalRecord,
// PalletBrokerRegionId,
// PalletBrokerRegionRecord,
// PalletBrokerSaleInfoRecord,
// PalletBrokerScheduleItem,
// PalletBrokerStatusRecord,
PolkadotRuntimeParachainsAssignerCoretimeCoreDescriptor,
PolkadotRuntimeParachainsParasParaLifecycle,
} from '@polkadot/types/lookup';
Expand Down Expand Up @@ -269,7 +260,6 @@ export class CoretimeService extends AbstractService {
};
};

// both relay and coretime chain
async getCoretimeInfo(hash: BlockHash): Promise<ICoretimeRelayInfo | ICoretimeChainInfo> {
const { api } = this;

Expand Down Expand Up @@ -300,7 +290,6 @@ export class CoretimeService extends AbstractService {
maxHistoricalRevenue: maxHistoricalRevenue as unknown as number,
};
} else {
// coretime chain or parachain
this.assertCoretimeModule(historicApi, ChainType.Parachain);
const [config, saleInfo, timeslicePeriod, status] = await Promise.all([
this.getAndDecodeConfiguration(historicApi),
Expand Down Expand Up @@ -368,7 +357,6 @@ export class CoretimeService extends AbstractService {
if (this.getChainType(specName.toString()) === ChainType.Relay) {
throw new Error('This endpoint is only available on coretime chains.');
} else {
// coretime chain or parachain
this.assertCoretimeModule(historicApi, ChainType.Parachain);
const [leases, workload] = await Promise.all([
this.getAndDecodeLeases(historicApi),
Expand Down Expand Up @@ -410,7 +398,6 @@ export class CoretimeService extends AbstractService {
if (this.getChainType(specName.toString()) === ChainType.Relay) {
throw new Error('This endpoint is only available on coretime chains.');
} else {
// coretime chain or parachain
this.assertCoretimeModule(historicApi, ChainType.Parachain);

const regions = await this.getAndDecodeRegions(historicApi);
Expand Down Expand Up @@ -468,7 +455,6 @@ export class CoretimeService extends AbstractService {
if (this.getChainType(specName.toString()) === ChainType.Relay) {
throw new Error('This endpoint is only available on coretime chains.');
} else {
// coretime chain or parachain
this.assertCoretimeModule(historicApi, ChainType.Parachain);

const renewals = await this.getAndDecodePotentialRenewals(historicApi);
Expand All @@ -495,6 +481,7 @@ export class CoretimeService extends AbstractService {
const blockNumber = number.unwrap();

if (this.getChainType(specName.toString()) === ChainType.Relay) {
this.assertCoretimeModule(historicApi, ChainType.Relay);
const [parachains, schedules, descriptors] = await Promise.all([
this.getAndDecodeParachainsLifecycle(historicApi),
this.getAndDecodeCoreSchedules(historicApi),
Expand Down Expand Up @@ -524,6 +511,7 @@ export class CoretimeService extends AbstractService {
coreSchedules: schedules,
};
} else {
this.assertCoretimeModule(historicApi, ChainType.Parachain);
const [workload, workplan, leases, reservations, regions] = await Promise.all([
this.getAndDecodeWorkload(historicApi),
this.getAndDecodeWorkplan(historicApi),
Expand Down

0 comments on commit 1c8dbe4

Please sign in to comment.