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: chainSpec based controller config; Types from apps-config #351

Merged
merged 27 commits into from
Dec 9, 2020

Conversation

emostov
Copy link
Contributor

@emostov emostov commented Nov 24, 2020

Closes #334

Overview

This PR introduces the foundations of allowing Sidecar to work smoothly with FRAME based chains. It accomplishes this by

  1. including type definitions from @polkadot/apps-config which are injected into the API
  2. Creating a way to specify which controllers to mount based on a chains specName and hard coded config that aligns with the specName.

These changes will allow most FRAME chain builders to use Sidecar by just specifying end points their chain supports in the controllers config and keeping there chain types up to date in @polkadot/apps-config.

In this PR I also include controller configuration for Kulupu since it was requested in an issue (#350) and makes sense to have a live example to try out the setup.

Would be nice to get this through in the near future, since it will be a blocker for meaningful work in this repo.

Changes

Chain types

  • Include chains types from @polkadot/apps-config and use the in ApiPromise

Controller config

  • Controller configuration object that allows to specify the controllers to use (see ControllerConfig in src/types/chains-config)
  • Mandala controller config (read down for more about controller configs)
  • controller config for Kulupu to close /blocks/head return error #350
  • Create default controller config (primarily for Polkadot and Kusama)
  • Dynamically instantiate controllers base on specified controller config (see getControllersForSpec and getControllersFromConfig from src/chains-config/index.ts)
  • src/controllers/index.ts now exports a concrete controllers object so we can have better type safety when dynamically creating the controllers with getControllersFromConfig in src/chains-config/index.ts
  • finalizes filed that is used to decide if the getFinalizedHead should be used in the blocks controller
    finalized === 'false' || !this.finalizes

Endpoints (services/ controllers)

  • Creation of KulupuBlocksController which has new /kulupuBlocks/{head, :number} endpoint. I had to do this because there is no notion of finalized blocks since it is a simple PoW consensus (someone please correct if I am wrong). In the new controller only a couple lines here taken out to remove the ?finalized=boolean query param, but I created an entire other controller with a new endpoint name to keep things simple; However I am certainly open to other ideas, I just don't want the controllers to scale with a huge amount of conditionals as we add more chains.
  • accounts/{accountId}/balance-info
    • now supports a token query param that allows the user to specify tokens from ORML tokens pallet
    • tokenSymbol field in the response to reduce ambiguity on the token of the balances represented
    • Openapi docs updated to reflect changes
  • BlocksService is updated so it does not break when it encounters chains that do not have all the components to support CalcFee.from_params

Other changes

How to try out the PR

Follow the instructions in the README: https://github.com/paritytech/substrate-api-sidecar#source-code-installation-and-usage and then start the service against Kulupu or Mandala by running SAS_SUBSTRATE_WS_URL=wss://rpc.kulupu.corepaper.org/ws yarn start. You can then discover the available endpoints by visiting GET http://127.0.0.1:8080/

Follow up work

  • Test to see if the user configurable CUSTOM_TYPES still works and see if there is a better solution
  • More testing against Kulupu and Mandala (e.g. submitting transactions etc.)
  • Token identifier verification middleware (Token identifier verification #360)

@emostov emostov requested review from ewang8 and removed request for ewang8 December 2, 2020 04:56
Copy link
Contributor

@dvdplm dvdplm left a comment

Choose a reason for hiding this comment

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

I'll have to tinker with this a bit before I leave a proper review.

@emostov
Copy link
Contributor Author

emostov commented Dec 3, 2020

Added a CHAIN_INTEGRATION.md guide that @joepetrowski may be interested in reviewing


##### Basic balance transfer support

In order to support traditional balance transfers the chain's Sidecar endpoints should support account balance lookup, transaction submission, transaction material retrieval, and block queries.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice. Even if we haven't decided the exact token standard, good to start somewhere.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could be good to link to examples of how each of these look like.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dvdplm - what exactly do you have in mind for examples? My idea here was essentially to say "make sure to add the relevant controllers for these endpoints".

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah maybe it's dumb but my thinking was to link to example implementations of the existing Polkadot/Kusama endpoints; a dev adding sidecar for their chain might want to peek at how you did those endpoints as theirs will likely be fairly similar?

emostov and others added 2 commits December 4, 2020 10:02
Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>

##### Basic balance transfer support

In order to support traditional balance transfers the chain's Sidecar endpoints should support account balance lookup, transaction submission, transaction material retrieval, and block queries.
Copy link
Contributor

Choose a reason for hiding this comment

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

Could be good to link to examples of how each of these look like.

acc.push(
new controllers[controllerName](api, config.options.finalizes)
);
acc.push(new controllers[controllerName](api, config.options));
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@maciejhirsz maciejhirsz left a comment

Choose a reason for hiding this comment

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

Minor grumbles and comments

boolean
][];

return controllersToInclude.reduce((acc, [controllerName, shouldMount]) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

One day JavaScript will get filterMap on arrays, one day... :)

@emostov
Copy link
Contributor Author

emostov commented Dec 9, 2020

Responded to all comments. I think it is is looking pretty good.

Copy link
Contributor

@maciejhirsz maciejhirsz left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@dvdplm dvdplm left a comment

Choose a reason for hiding this comment

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

One tiny nit left!

Comment on lines 1 to 36
Skip to content
Search or jump to…

Pull requests
Issues
Marketplace
Explore

@emostov
paritytech
/
substrate - api - sidecar
12
56
29
Code
Issues
20
Pull requests
1
Actions
Security
4
Insights
Settings
substrate - api - sidecar / src / services / accounts / AccountsBalanceInfoService.ts /
@emostov
emostov Initial reply david review
Latest commit be66056 6 days ago
History
2 contributors
@emostov @joepetrowski
We found potential security vulnerabilities in your dependencies.
You can see this message because you have been granted access to Dependabot alerts for this repository.

95 lines(87 sloc) 2.38 KB
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting glitch in the matrix here. :D

Co-authored-by: David <dvdplm@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants