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

feat: coretime implementation #1558

Open
wants to merge 20 commits into
base: master
Choose a base branch
from

Conversation

filvecchiato
Copy link
Contributor

@filvecchiato filvecchiato commented Nov 29, 2024

New Feature: Implements the coretime endpoints for relay chain and for coretime chain.

It includes basic endpoints for single information record recovery, and more advanced endpoints with precomputed calculations and information.

@filvecchiato filvecchiato force-pushed the filippo_coretime_implementation branch from 744895d to 6de3395 Compare November 29, 2024 15:52
@filvecchiato filvecchiato changed the title Filippo coretime implementation Feat: coretime implementation Nov 29, 2024
@filvecchiato filvecchiato force-pushed the filippo_coretime_implementation branch from 4efc743 to f6e8a77 Compare December 9, 2024 15:15
@filvecchiato filvecchiato changed the title Feat: coretime implementation feat: coretime implementation Dec 9, 2024
@filvecchiato filvecchiato force-pushed the filippo_coretime_implementation branch from 9ef9d68 to e8a0808 Compare December 19, 2024 15:59
@filvecchiato filvecchiato force-pushed the filippo_coretime_implementation branch from 142039d to 4dcdf17 Compare December 20, 2024 11:12
@filvecchiato filvecchiato marked this pull request as ready for review December 20, 2024 11:13
@filvecchiato filvecchiato requested a review from a team as a code owner December 20, 2024 11:13
}

private getChainType(specName: string): ChainType {
const relay = ['polkadot', 'kusama', 'westend', 'rococo', 'paseo'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove rococo from here.

}

private checkCoretimeModule = (): void => {
if (this.api.query.onDemandAssignmentProvider && this.api.query.coretimeAssignmentProvider) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if I understand this correct - either broker needs to exist or onDemandAssignmentProvider and coretimeAssignmentProvider?

Would there ever be a case where they all need to exists at once?

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

private checkCoretimeModule = (): void => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same sentiment as the comment in CoretimeChain

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import { ApiPromise } from '@polkadot/api';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import type for the types.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import { ApiDecoration, QueryableModuleStorage } from '@polkadot/api/types';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the types can have import type


const SCALE = new BN(10000);

export class CoretimeService extends AbstractService {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked locally, and all the types are correctly generated for all the storage queries so there isn't a need to typecast here. At least for me I had no errors building when removing all the typecasts.

const SCALE = new BN(10000);

export class CoretimeService extends AbstractService {
private getAndDecodeRegions = async (api: ApiDecoration<'promise'>): Promise<TRegionInfo[]> => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private getAndDecodeRegions = async (api: ApiDecoration<'promise'>): Promise<TRegionInfo[]> => {
private getAndDecodeRegions = async (api: ApiDecoration<'promise'>): Promise<TRegionInfo[]> => {
const regions = await api.query.broker.regions.entries();
const regionsInfo = regions.map((region) => {
return extractRegionInfo([region[0], region[1]]);
});
return regionsInfo;
};


private getAndDecodeLeases = async (api: ApiDecoration<'promise'>): Promise<TLeaseInfo[]> => {
const leases = await api.query.broker.leases();
return (leases as unknown as Vec<PalletBrokerLeaseRecordItem>).map((lease) => extractLeaseInfo(lease));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return (leases as unknown as Vec<PalletBrokerLeaseRecordItem>).map((lease) => extractLeaseInfo(lease));
return leases.map((lease) => extractLeaseInfo(lease));

return (leases as unknown as Vec<PalletBrokerLeaseRecordItem>).map((lease) => extractLeaseInfo(lease));
};

private getAndDecodeWorkload = async (api: ApiDecoration<'promise'>): Promise<TWorkloadInfo[]> => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private getAndDecodeWorkload = async (api: ApiDecoration<'promise'>): Promise<TWorkloadInfo[]> => {
private getAndDecodeWorkload = async (api: ApiDecoration<'promise'>): Promise<TWorkloadInfo[]> => {
const workloads = await api.query.broker.workload.entries();
return sortByCore(
workloads.map((workload) => {
return extractWorkloadInfo(workload[1], workload[0].args[0].toNumber());
}),
);
};

);
};

private getAndDecodeWorkplan = async (api: ApiDecoration<'promise'>): Promise<TWorkplanInfo[]> => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private getAndDecodeWorkplan = async (api: ApiDecoration<'promise'>): Promise<TWorkplanInfo[]> => {
private getAndDecodeWorkplan = async (api: ApiDecoration<'promise'>): Promise<TWorkplanInfo[]> => {
const workplans = await api.query.broker.workplan.entries();
const wplsInfo = sortByCore(
workplans.map(([key, val]) => {
const [timeslice, core] = key.args[0].toArray();
return extractWorkplanInfo(val, core, timeslice);
}),
);
return wplsInfo;
};

};

private getAndDecodeSaleInfo = async (api: ApiDecoration<'promise'>): Promise<TSaleInfo | null> => {
const saleInfo = (await api.query.broker.saleInfo()) as unknown as Option<PalletBrokerSaleInfoRecord>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const saleInfo = (await api.query.broker.saleInfo()) as unknown as Option<PalletBrokerSaleInfoRecord>;
const saleInfo = await api.query.broker.saleInfo();

private getAndDecodeStatus = async (api: ApiDecoration<'promise'>): Promise<TStatusInfo> => {
const status = await api.query.broker.status();

return extractStatusInfo(status as unknown as Option<PalletBrokerStatusRecord>);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return extractStatusInfo(status as unknown as Option<PalletBrokerStatusRecord>);
return extractStatusInfo(status);

private getAndDecodeConfiguration = async (api: ApiDecoration<'promise'>): Promise<TConfigInfo> => {
const configuration = await api.query.broker.configuration();

return extractConfigInfo(configuration as unknown as Option<PalletBrokerConfigRecord>);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return extractConfigInfo(configuration as unknown as Option<PalletBrokerConfigRecord>);
return extractConfigInfo(configuration);

return extractConfigInfo(configuration as unknown as Option<PalletBrokerConfigRecord>);
};

private getAndDecodePotentialRenewals = async (api: ApiDecoration<'promise'>): Promise<TPotentialRenewalInfo[]> => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private getAndDecodePotentialRenewals = async (api: ApiDecoration<'promise'>): Promise<TPotentialRenewalInfo[]> => {
private getAndDecodePotentialRenewals = async (api: ApiDecoration<'promise'>): Promise<TPotentialRenewalInfo[]> => {
const potentialRenewals = await api.query.broker.potentialRenewals.entries();
const potentialRenewalsInfo = sortByCore(
potentialRenewals.map((renewal) => extractPotentialRenewalInfo(renewal[1], renewal[0])),
);
return potentialRenewalsInfo;
};

private getAndDecodeReservations = async (api: ApiDecoration<'promise'>): Promise<TReservationInfo[]> => {
const reservations = await api.query.broker.reservations();

return (reservations as unknown as Vec<Vec<PalletBrokerScheduleItem>>).map((res) => extractReservationInfo(res));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return (reservations as unknown as Vec<Vec<PalletBrokerScheduleItem>>).map((res) => extractReservationInfo(res));
return reservations.map((res) => extractReservationInfo(res));


private getAndDecodeCoreSchedules = async (api: ApiDecoration<'promise'>): Promise<Record<string, unknown>[]> => {
const coreSchedules = await api.query.coretimeAssignmentProvider.coreSchedules.entries();
return coreSchedules as unknown as Record<string, unknown>[];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return coreSchedules as unknown as Record<string, unknown>[];
return coreSchedules;

return coreSchedules as unknown as Record<string, unknown>[];
};

private getAndDecodeCoreDescriptors = async (api: ApiDecoration<'promise'>): Promise<TCoreDescriptor[]> => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private getAndDecodeCoreDescriptors = async (api: ApiDecoration<'promise'>): Promise<TCoreDescriptor[]> => {
private getAndDecodeCoreDescriptors = async (api: ApiDecoration<'promise'>): Promise<TCoreDescriptor[]> => {
const coreDescriptors = await api.query.coretimeAssignmentProvider.coreDescriptors.entries();
return coreDescriptors.map((descriptor) => extractCoreDescriptorInfo(descriptor[0], descriptor[1]));
};

return descriptors.map((descriptor) => extractCoreDescriptorInfo(descriptor[0], descriptor[1]));
};

private getAndDecodeParachainsLifecycle = async (api: ApiDecoration<'promise'>): Promise<TParaLifecycle[]> => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private getAndDecodeParachainsLifecycle = async (api: ApiDecoration<'promise'>): Promise<TParaLifecycle[]> => {
private getAndDecodeParachainsLifecycle = async (api: ApiDecoration<'promise'>): Promise<TParaLifecycle[]> => {
const parachains = await api.query.paras.paraLifecycles.entries();
return parachains.map((para) =>
extractParachainLifecycleInfo(
para[0],
para[1],
),
);
};

};
}

export function extractCoreScheduleInfo() {}
Copy link
Member

@TarikGul TarikGul Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused function?

Copy link
Member

@TarikGul TarikGul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall amazing PR! I have a few nits:

  1. The typecasting can be removed. AFAIU the types are correctly passed down from PJS so you should be good.

  2. For any imported types we can use import type.

Other than that the PR looks really great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants