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

Merged
merged 26 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
99163a5
init coretime
filvecchiato Nov 11, 2024
2673c2b
prep for coretime support
filvecchiato Nov 22, 2024
59d7235
update coretime service:
filvecchiato Nov 27, 2024
8709dfb
feat: first iteration at coretime impl
filvecchiato Nov 29, 2024
b2d5d54
fix coretime service
filvecchiato Dec 9, 2024
b55f820
update blocks per timeslice
filvecchiato Dec 11, 2024
7e06e4b
impl registries kusama and coretime chain v1003003
filvecchiato Dec 13, 2024
14ee64b
housekeep for coretime tests
filvecchiato Dec 13, 2024
4e0775d
linting
filvecchiato Dec 13, 2024
8240c6a
tests passing for leases, renewals, regions
filvecchiato Dec 16, 2024
46ce0d3
passing reservations
filvecchiato Dec 16, 2024
fdf0498
passing tests cores info
filvecchiato Dec 16, 2024
9fe08da
tests for cores endpoint
filvecchiato Dec 18, 2024
99c0239
prep for api docs for coretime
filvecchiato Dec 19, 2024
e8a0808
coretime docs updated
filvecchiato Dec 19, 2024
2fc1636
reworked coretime/info endpoint to be more informative
filvecchiato Dec 20, 2024
a05d3e5
change endpoint from cores to overview
filvecchiato Dec 20, 2024
e4e995f
passing tests
filvecchiato Dec 20, 2024
4dcdf17
update docs
filvecchiato Dec 20, 2024
8c3a776
Delete .env
filvecchiato Dec 20, 2024
4a5b115
partial removal of typecasting
filvecchiato Dec 23, 2024
62523c1
removal artifact code
filvecchiato Dec 23, 2024
1c8dbe4
patches to coretime controllers
filvecchiato Jan 3, 2025
4c9e9eb
patches to coretime controllers
filvecchiato Jan 3, 2025
7cadd71
patches to coretime controllers
filvecchiato Jan 3, 2025
934aca2
patch docs
filvecchiato Jan 3, 2025
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
494 changes: 494 additions & 0 deletions docs/src/openapi-v1.yaml

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletions src/chains-config/coretimeControllers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2017-2024 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
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// 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 { ControllerConfig } from '../types/chains-config';
import { initLRUCache, QueryFeeDetailsCache } from './cache';

/**
* Polkadot configuration for Sidecar.
*/
export const coretimeControllers: ControllerConfig = {
controllers: [
'AccountsBalanceInfo',
'AccountsConvert',
'AccountsProxyInfo',
'Blocks',
'BlocksExtrinsics',
'BlocksTrace',
'BlocksRawExtrinsics',
'NodeNetwork',
'NodeVersion',
'PalletsConsts',
'PalletsErrors',
'PalletsEvents',
'PalletsNominationPools',
'PalletsOnGoingReferenda',
'PalletsStakingProgress',
'PalletsStakingValidators',
'PalletsStorage',
'RuntimeCode',
'RuntimeMetadata',
'RuntimeSpec',
'CoretimeGeneric',
'CoretimeChain',
],
options: {
finalizes: true,
minCalcFeeRuntime: 0,
blockStore: initLRUCache(),
hasQueryFeeApi: new QueryFeeDetailsCache(27, 28),
},
};
4 changes: 4 additions & 0 deletions src/chains-config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { astarControllers } from './astarControllers';
import { bifrostControllers } from './bifrostControllers';
import { bifrostPolkadotControllers } from './bifrostPolkadotControllers';
import { calamariControllers } from './calamariControllers';
import { coretimeControllers } from './coretimeControllers';
import { crustControllers } from './crustControllers';
import { defaultControllers } from './defaultControllers';
import { dockMainnetControllers } from './dockMainnetControllers';
Expand Down Expand Up @@ -77,6 +78,9 @@ const specToControllerMap: { [x: string]: ControllerConfig } = {
bifrost_polkadot: bifrostPolkadotControllers,
heiko: heikoControllers,
parallel: parallelControllers,
'coretime-westend': coretimeControllers,
'coretime-polkadot': coretimeControllers,
'coretime-kusama': coretimeControllers,
};

/**
Expand Down
1 change: 1 addition & 0 deletions src/chains-config/kusamaControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const kusamaControllers: ControllerConfig = {
'TransactionFeeEstimate',
'TransactionMaterial',
'TransactionSubmit',
'CoretimeGeneric',
],
options: {
finalizes: true,
Expand Down
1 change: 1 addition & 0 deletions src/chains-config/polkadotControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const polkadotControllers: ControllerConfig = {
'TransactionFeeEstimate',
'TransactionMaterial',
'TransactionSubmit',
'CoretimeGeneric',
filvecchiato marked this conversation as resolved.
Show resolved Hide resolved
],
options: {
finalizes: true,
Expand Down
1 change: 1 addition & 0 deletions src/chains-config/westendControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const westendControllers: ControllerConfig = {
'TransactionFeeEstimate',
'TransactionMaterial',
'TransactionSubmit',
'CoretimeGeneric',
],
options: {
finalizes: true,
Expand Down
78 changes: 78 additions & 0 deletions src/controllers/coretime/CoretimeChainController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Copyright 2017-2024 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
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// 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';
import { RequestHandler } from 'express';

import { CoretimeService } from '../../services';
import AbstractController from '../AbstractController';

export default class CoretimeChainController extends AbstractController<CoretimeService> {
constructor(api: ApiPromise) {
super(api, '/coretime', new CoretimeService(api));
this.initRoutes();
}
// TODO: check if its either coretime or relay chain, if neither error out
filvecchiato marked this conversation as resolved.
Show resolved Hide resolved
protected initRoutes(): void {
this.safeMountAsyncGetHandlers([
['/leases', this.getLeases], // :taskId
['/regions', this.getRegions],
['/renewals', this.getRenewals],
['/reservations', this.getReservations],
]);
}

private checkCoretimeModule = (): void => {
if (this.api.query.onDemandAssignmentProvider && this.api.query.coretimeAssignmentProvider) {
filvecchiato marked this conversation as resolved.
Show resolved Hide resolved
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));
};
}
60 changes: 60 additions & 0 deletions src/controllers/coretime/CoretimeGenericController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright 2017-2024 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
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// 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';
import { RequestHandler } from 'express';

import { CoretimeService } from '../../services';
import AbstractController from '../AbstractController';

export default class CoretimeGenericController extends AbstractController<CoretimeService> {
constructor(api: ApiPromise) {
super(api, '/coretime', new CoretimeService(api));
this.initRoutes();
}
// TODO: check if its either coretime or relay chain, if neither error out
filvecchiato marked this conversation as resolved.
Show resolved Hide resolved
protected initRoutes(): void {
this.safeMountAsyncGetHandlers([
['/info', this.getCoretimeOverview],
['/overview', this.getCoretimeCores],
]);
}

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 => {
filvecchiato marked this conversation as resolved.
Show resolved Hide resolved
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: 18 additions & 0 deletions src/controllers/coretime/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2017-2024 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
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

export { default as CoretimeChain } from './CoretimeChainController';
export { default as CoretimeGeneric } from './CoretimeGenericController';
3 changes: 3 additions & 0 deletions src/controllers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
} from './accounts';
import { Blocks, BlocksExtrinsics, BlocksRawExtrinsics, BlocksTrace } from './blocks';
import { ContractsInk } from './contracts';
import { CoretimeChain, CoretimeGeneric } from './coretime';
import { NodeNetwork, NodeTransactionPool, NodeVersion } from './node';
import {
PalletsAssetConversion,
Expand Down Expand Up @@ -89,4 +90,6 @@ export const controllers = {
TransactionMaterial,
TransactionSubmit,
Paras,
CoretimeGeneric,
CoretimeChain,
};
Loading
Loading