-
Notifications
You must be signed in to change notification settings - Fork 156
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
base: master
Are you sure you want to change the base?
Conversation
744895d
to
6de3395
Compare
4efc743
to
f6e8a77
Compare
9ef9d68
to
e8a0808
Compare
142039d
to
4dcdf17
Compare
} | ||
|
||
private getChainType(specName: string): ChainType { | ||
const relay = ['polkadot', 'kusama', 'westend', 'rococo', 'paseo']; |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 => { |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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[]> => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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[]> => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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[]> => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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[]> => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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>[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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[]> => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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[]> => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused function?
There was a problem hiding this 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:
-
The typecasting can be removed. AFAIU the types are correctly passed down from PJS so you should be good.
-
For any imported types we can use
import type
.
Other than that the PR looks really great!
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.