-
Notifications
You must be signed in to change notification settings - Fork 69
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
CW precompile support with Schema, updated precompile for DEX with full coverage #3722
Conversation
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.
Roughly speaking LGTM, but I need to have another pass to look closely at the actual logic.
@@ -51,6 +50,7 @@ pub mod governance; | |||
pub mod lending; | |||
pub mod liquidation; | |||
pub mod oracle; | |||
pub mod prelude; |
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.
Do we actually need it? Especially since this exports symbols from other crates which I’d argue shouldn’t be in prelodue. To be honest in general I think preludes should not exist in the first place.
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 need.
- you say that all preludes include only this crate items? all the time and this is default behavior of all preludes?
- parity has preludes for pallets and for core. rust team provides prelude for std.
- why you you think such?
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.
Well, preludes can always be replaced by importing specific symbols so are never really needed. I also cannot comment what all preludes do; I’m sure there are some which include symbols from various unrelated crates, however yes, I would argue that reexporting things from bunch of crates is somewhat surprising.
The problem with preludes, or more specifically with wildcard imports, is that it makes the code harder to read for someone who is unfamiliar with it. If I saw MaxEncodedLen
or TypeInfo
in the code I would have no idea what those types are and where to look for their documentation.
This is also true about Rust’s preludes and I’m not convinced they are good addition to the standard library, but at least there the prelude includes symbols which are known to anyone who knows basics of Rust.
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.
MaxEncodedLen - it allows to bound unbounded types like Vec or String. Parity likes bounds in storage and on the wire.
TypeInfo - it is like JsonSchema, but specifically for scale encoder.
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.
Each prelude include layer of new known by default preludes. Like if you are Substrate or CW integration (String/Vec/Json) you have you own well known layer. 100% preludes include what every knows in Substrate or CW or XCM, depending on what layer you are.
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 shared examples of parity preludes, so in this PR not 100% same, but kind of similar.
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.
Specific imports can always be replaced by preludes.
code/parachain/frame/composable-traits/schema/composable-traits.json
Outdated
Show resolved
Hide resolved
|
||
pub fn query(sender: &str, msg: QueryMsg) -> Result<QueryResponse, CosmwasmPrecompileError> { | ||
match msg { | ||
QueryMsg::Assets { pool_id } => { |
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.
Could you extract each arm to a separate method, something like:
pub fn query(sender: &str, msg: QueryMsg) -> Result<QueryResponse, CosmwasmPrecompileError> {
match msg {
QueryMsg::Assets { pool_id } => self.handle_query_assets(sender, pool_id),
QueryMsg::SpotPrice { pool_id, base_asset, quote_asset_id, calculate_with_fees } => {
handle_query_spot_price(sender, pool_id, base_asset, quote_asset_id, calculate_with_fees)
},
/* ... */
and same with execute
? The long functions and deep indentation
levels make the code less readable than it could be.
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.
handle_query_spot_price will require generics and will make more code.
and you are wrong, consider QueryMsg::SpotPrice
to be inline function. and block => { } to be its body.
Adding function is just noise. So your solution is opinionted, adds more noise, more code, harder to read.
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.
Why would it require generics? It would be no more generic than the query
method.
It adds noise because you have to define separate methods with arguments, but the point is that you end up with much shorter functions with cleaner control flow. The functions can also be properly documented with a comment.
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.
control flow is not cleaner. match = functions.
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.
functions are documented on query types. query case = function. match block = 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.
generic would be required on function declaration.
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.
control flow is not cleaner. match = functions.
I don’t know what you mean by ‘match = functions’.
functions are documented on query types.
Except the types aren’t documented either.
generic would be required on function declaration.
No, it would be method of Dex and as such would not need any additional generic arguments.
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.
each variant in CW enum is functions. So when you match, you do functions. And each functions has name (in match variant) and each block of match if function body. So it is same thing encoded other way.
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.
They documented as comments to CW people where needed.
@@ -51,6 +50,7 @@ pub mod governance; | |||
pub mod lending; | |||
pub mod liquidation; | |||
pub mod oracle; | |||
pub mod prelude; |
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.
Well, preludes can always be replaced by importing specific symbols so are never really needed. I also cannot comment what all preludes do; I’m sure there are some which include symbols from various unrelated crates, however yes, I would argue that reexporting things from bunch of crates is somewhat surprising.
The problem with preludes, or more specifically with wildcard imports, is that it makes the code harder to read for someone who is unfamiliar with it. If I saw MaxEncodedLen
or TypeInfo
in the code I would have no idea what those types are and where to look for their documentation.
This is also true about Rust’s preludes and I’m not convinced they are good addition to the standard library, but at least there the prelude includes symbols which are known to anyone who knows basics of Rust.
|
||
pub fn query(sender: &str, msg: QueryMsg) -> Result<QueryResponse, CosmwasmPrecompileError> { | ||
match msg { | ||
QueryMsg::Assets { pool_id } => { |
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.
Why would it require generics? It would be no more generic than the query
method.
It adds noise because you have to define separate methods with arguments, but the point is that you end up with much shorter functions with cleaner control flow. The functions can also be properly documented with a comment.
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.
LGTM sans the comments.
please write RFC for that or setup meeting with Blas and Parachain lead, OR take lead on collaboration with CW people. |
its lie, I do not get shorted |
@blasrodri, as per @dzmitry-lahoda’s request pinging you about this. The current state of parts of the codebase is subpar to put it mildly with many parts of the code completely undocumented. Seems to me we need to agree on some style guide which at minimum would enforce documenting new code. |
Let discuss preludes in Slack or on separate meeting, I used preludes a lot and Parity Uses. See https://github.com/paritytech/substrate/blob/dc3fb3d4cf9efb779a068cdc201babc7ae2d233c/frame/support/src/lib.rs#L1566 . May be style of coding was good in NEAR, ok with that. By I am for style of coding of Parity as wwe code in Substrate. Also you can see that most preludes are internal, so they will not surprise you if other crate, in this crate - you should be aware of crate. Also preludes are must for NO_STD and CW support - no other sane way. |
Let agree on next PRs so. If code requirement appeared after work was done and not critical to function, it is no part of this PR. Oh, i had dozen of times these discussion, in the end I can say - if CI works with that PR - PR is good :) You may not believe me, but I have seen dozens of projects - all are same. |
@blasrodri @mina86 refers to CW query/execute interface, my requirements from CW people was.
CW people never raised requirements about docs to me. As for CW docs, if @mina86 wants nice CW sandbox for him to work - he can take time and CP paste docs and improve form what we have to CW and learn Substrate API. I do not have time to hide that we have substrate API on docs level, I already hidden that on code level. Also I always open for propositions to take lead on Precompiles and CW people support and do whatever is best :) And any comprehensive non opinionated discussion for most objective way to get things. |
This is blatantly false. Code which is not readable and not maintainable isn’t good even if it works in the moment.
No, I’m referring to code as a whole. My comment regarding need for documentation isn’t limited to any specific part of the code base. If you’re writing undocumented code only for a single group of people than don’t expect me to review or work with it.
I’m sorry, but are you suggesting that wanting documentation is ‘opinionated’? |
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.
LGTM sans the comments.
Ah, forgot to approve.
@mina86 my code is not readable and not maintainable? :( |
@mina86 i tell there is process and definion of documentation. i adhere to that on what we have in composable. did you know that docs are not only /// and any such /// has a price? if you review and you are not clear on code, just ask in code comment. i will answer or add docs. so i expect people to read code with accepted level of docs and ask question. yes. feel free. ot to review anything. i am ok with that too) to be honest i do not expect people work at all, not only review. that is usual. feel free to work as you wish. |
I didn’t say that. I said CI passing is insufficient to call a PR good.
And lack of /// has a price as well. |
any more responses about this? I responded to preludes and docs, kind of:
|
…ll coverage (#3722) I have generated Schema for precompiles so these can be used to generate Rust again by CW people. DEX is fully covered by CW too, and also improved coding of precompiles. Cleaned up some garbage and useless comments. Main goal is to provide interface to CW people. I will test this precompile when will reach it with multichain XCVM swap. - [x] PR title is my best effort to provide summary of changes and has clear text to be part of release notes - [x] I marked PR by `misc` label if it should not be in release notes - [x] I have linked Zenhub/Github or any other reference item if one exists - [x] I was clear on what type of deployment required to release my changes (node, runtime, contract, indexer, on chain operation, frontend, infrastructure) if any in PR title or description - [ ] I waited and did best effort for `pr-workflow-check / draft-release-check` to finish with success(green check mark) with my changes - [x] I have added at least one reviewer in reviewers list - [x] I tagged(@) or used other form of notification of one person who I think can handle best review of this PR - [x] I have proved that PR has no general regressions of relevant features and processes required to release into production
I have generated Schema for precompiles so these can be used to generate Rust again by CW people.
DEX is fully covered by CW too, and also improved coding of precompiles.
Cleaned up some garbage and useless comments.
Main goal is to provide interface to CW people.
I will test this precompile when will reach it with multichain XCVM swap.
misc
label if it should not be in release notespr-workflow-check / draft-release-check
to finish with success(green check mark) with my changes