-
Notifications
You must be signed in to change notification settings - Fork 162
feat: coretime implementation #1558
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
Merged
Merged
Changes from 20 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
99163a5
init coretime
filvecchiato 2673c2b
prep for coretime support
filvecchiato 59d7235
update coretime service:
filvecchiato 8709dfb
feat: first iteration at coretime impl
filvecchiato b2d5d54
fix coretime service
filvecchiato b55f820
update blocks per timeslice
filvecchiato 7e06e4b
impl registries kusama and coretime chain v1003003
filvecchiato 14ee64b
housekeep for coretime tests
filvecchiato 4e0775d
linting
filvecchiato 8240c6a
tests passing for leases, renewals, regions
filvecchiato 46ce0d3
passing reservations
filvecchiato fdf0498
passing tests cores info
filvecchiato 9fe08da
tests for cores endpoint
filvecchiato 99c0239
prep for api docs for coretime
filvecchiato e8a0808
coretime docs updated
filvecchiato 2fc1636
reworked coretime/info endpoint to be more informative
filvecchiato a05d3e5
change endpoint from cores to overview
filvecchiato e4e995f
passing tests
filvecchiato 4dcdf17
update docs
filvecchiato 8c3a776
Delete .env
filvecchiato 4a5b115
partial removal of typecasting
filvecchiato 62523c1
removal artifact code
filvecchiato 1c8dbe4
patches to coretime controllers
filvecchiato 4c9e9eb
patches to coretime controllers
filvecchiato 7cadd71
patches to coretime controllers
filvecchiato 934aca2
patch docs
filvecchiato File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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), | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
Outdated
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.
Outdated
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)); | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
Outdated
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.
Outdated
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.'); | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.