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

Implement wildcard selector, add proxy example #1020

Merged
merged 42 commits into from
Nov 24, 2021

Conversation

cmichi
Copy link
Collaborator

@cmichi cmichi commented Nov 17, 2021

Closes #739.

This PR intentionally

  • …does not contain any wildcard selector trait support.
  • …does not contain an off-chain test for the new proxy example. Will be added later.

I'll add an E2E test for the ink-waterfall as a follow-up.

Pictures for the proxy/readme.md would also be nice, can also be done as a follow-up.

@cmichi cmichi requested a review from athei November 17, 2021 08:38
.set_tail_call(true),
)
.gas_limit(0)
.transferred_value(self.env().transferred_balance())
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We should unify this API to be just .transferred_balance everywhere.

Copy link
Collaborator

Choose a reason for hiding this comment

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

also for constructors with their endowment?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'd leave it there, but in this case I think it's clear that it should be streamlined.

@codecov-commenter
Copy link

codecov-commenter commented Nov 17, 2021

Codecov Report

Merging #1020 (c297f50) into master (b2256d9) will increase coverage by 13.58%.
The diff coverage is 67.40%.

❗ Current head c297f50 differs from pull request most recent head 21bb558. Consider uploading reports for the commit 21bb558 to get more accurate results
Impacted file tree graph

@@             Coverage Diff             @@
##           master    #1020       +/-   ##
===========================================
+ Coverage   63.52%   77.10%   +13.58%     
===========================================
  Files         246      248        +2     
  Lines        9260     9381      +121     
===========================================
+ Hits         5882     7233     +1351     
+ Misses       3378     2148     -1230     
Impacted Files Coverage Δ
crates/lang/ir/src/ir/trait_def/item/trait_item.rs 89.06% <0.00%> (+43.03%) ⬆️
...ests/ui/contract/pass/message-wildcard-selector.rs 12.50% <12.50%> (ø)
.../ui/contract/pass/constructor-wildcard-selector.rs 16.66% <16.66%> (ø)
crates/lang/codegen/src/generator/dispatch.rs 94.28% <50.00%> (+94.28%) ⬆️
crates/lang/ir/src/ir/attrs.rs 82.59% <74.50%> (+3.59%) ⬆️
crates/lang/ir/src/ir/item_mod.rs 89.71% <76.92%> (+29.98%) ⬆️
crates/lang/ir/src/ir/item_impl/callable.rs 91.91% <100.00%> (+14.59%) ⬆️
crates/lang/ir/src/ir/item_impl/constructor.rs 92.30% <100.00%> (+7.56%) ⬆️
crates/lang/ir/src/ir/item_impl/message.rs 92.13% <100.00%> (+16.23%) ⬆️
crates/lang/ir/src/ir/trait_def/item/mod.rs 90.16% <100.00%> (+5.03%) ⬆️
... and 58 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b2256d9...21bb558. Read the comment docs.

@paritytech-ci
Copy link

paritytech-ci commented Nov 17, 2021

🦑 📈 ink! Example Contracts ‒ Size Change Report 📉 🦑

These are the results of building the examples/* contracts from this branch with cargo-contract 0.15.0:

Link to the run | Last update: Wed Nov 24 07:31:18 CET 2021

examples/proxy/lib.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@HCastano HCastano left a comment

Choose a reason for hiding this comment

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

I only took a look at the example contract and UI tests. Will take a look at the codegen tomorrow. Looking good though 👍

examples/proxy/lib.rs Show resolved Hide resolved
examples/proxy/lib.rs Outdated Show resolved Hide resolved
examples/proxy/lib.rs Outdated Show resolved Hide resolved
examples/proxy/lib.rs Outdated Show resolved Hide resolved
examples/proxy/lib.rs Outdated Show resolved Hide resolved
examples/proxy/lib.rs Outdated Show resolved Hide resolved
examples/proxy/lib.rs Outdated Show resolved Hide resolved
@@ -1,4 +1,4 @@
error: #[ink(selector = ..)] attributes with string inputs are deprecated. use an integer instead, e.g. #[ink(selector = 1)] or #[ink(selector = 0xC0DECAFE)].
error: #[ink(selector = ..)] attributes with string inputs are deprecated (except for the wildcard selector "_"). use an integer instead, e.g. #[ink(selector = 1)] or #[ink(selector = 0xC0DECAFE)].
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a shame, would've be nice to have consistent syntax. Can you expand on the issue you mentioned in the PR description as to why we weren't able to have selector = _?

Copy link
Collaborator Author

@cmichi cmichi Nov 17, 2021

Choose a reason for hiding this comment

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

Yeah, so the issue is here. We would need access to _ there.

But the crate which we use for parsing attributes a la #[ink(key = "value")] does not support parsing verbatims such as _. Specifically the type syn::Meta::NameValue which we use as part of the syn::parse_meta return value does not support this.

I briefly looked into syn::parse_meta, but it was nothing trivial. Maybe we could also do some pre-processing, so that selector = _ is transformed into selector = "_" before passing it to syn::parse_meta, but I haven't looked into that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Or you can implement your own parse_meta=) You can copy the main logic from syn + add support of _=)

README.md Outdated Show resolved Hide resolved
RELEASES.md Outdated Show resolved Hide resolved
Michael Müller and others added 2 commits November 17, 2021 16:15
examples/proxy/lib.rs Outdated Show resolved Hide resolved
@Robbepop
Copy link
Collaborator

This PR intentionally

* …does not contain any wildcard selector trait support. I will create a follow-up issue for this.

This feature is highly unwanted since it would heavily interfere with trait modularity. We should make sure that traits never allow for wildcard selectors.

Copy link
Collaborator

@Robbepop Robbepop left a comment

Choose a reason for hiding this comment

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

Haven't reviewed the entire thing, yet, however, I have to say that this PR goes a very long way in making sure that a wildcard selector is something completely different from a selector whereas the beauty in the original design actually made a lot of sense from the fact that we can treat both as different kinds of selectors.
So instead of putting is_wildcard_selector everywhere it would probably a more elegant design to make ir::Selector an enum that can represent a concrete selector or a wildcard selector.

RELEASES.md Outdated Show resolved Hide resolved
crates/lang/codegen/src/generator/dispatch.rs Show resolved Hide resolved
crates/lang/ir/src/ir/item_impl/callable.rs Outdated Show resolved Hide resolved
crates/lang/ir/src/ir/item_impl/callable.rs Outdated Show resolved Hide resolved
crates/lang/ir/src/ir/item_impl/constructor.rs Outdated Show resolved Hide resolved
crates/lang/ir/src/ir/item_impl/constructor.rs Outdated Show resolved Hide resolved
crates/lang/ir/src/ir/item_impl/message.rs Outdated Show resolved Hide resolved
crates/lang/ir/src/ir/item_impl/message.rs Outdated Show resolved Hide resolved
crates/lang/ir/src/ir/item_impl/message.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@HCastano HCastano left a comment

Choose a reason for hiding this comment

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

Nice!

crates/lang/ir/src/ir/attrs.rs Outdated Show resolved Hide resolved
crates/lang/ir/src/ir/item_impl/constructor.rs Outdated Show resolved Hide resolved
crates/lang/ir/src/ir/item_impl/message.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@HCastano HCastano left a comment

Choose a reason for hiding this comment

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

I haven't looked at all the new changes just yet, will finish this up tomorrow

examples/proxy/lib.rs Outdated Show resolved Hide resolved
pub struct Contract {}

impl Contract {
#[ink(constructor, selector = _)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there any invariants around constructors only being able to be run once? If so, then we shouldn't allow this

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you elaborate on this please? I cannot follow.

crates/lang/ir/src/ir/attrs.rs Outdated Show resolved Hide resolved
crates/lang/ir/src/ir/attrs.rs Outdated Show resolved Hide resolved
crates/lang/ir/src/ir/attrs.rs Outdated Show resolved Hide resolved
crates/lang/ir/src/ir/attrs.rs Outdated Show resolved Hide resolved
crates/lang/ir/src/ir/attrs.rs Outdated Show resolved Hide resolved
pub fn change_forward_address(
&mut self,
new_address: AccountId,
) -> Result<(), NotAdminErr> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Robbepop While running the waterfall tests for this example, I found that since I switched from assert! to returning Result::Err the transaction is no longer reverted ‒ it always results in ExtrinsicFailed.

If you don't see anything that I missed I'll consider this a bug, revert to assert! and create a follow-up issue.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, I tested that on Europa 0.3.6 and it is reverted.
image

Another question, how the user can forward some data via polkadot-js?=) Because I can only read that=D
image

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, could be that substrate-contracts-node is somewhat outdated.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Found it, the UI doesn't reflect this yet: polkadot-js/apps#6465.

Another question, how the user can forward some data via polkadot-js?=) Because I can only read that=D

@xgreenx You have to switch the metadata of this contract to some other contract. This can be done by clicking the "Add an existing contract" button, entering the proxy smart contract address and upload a different .contract file there. The UI will then use the ABI of this contract to interact with the proxy.

This reverts commit 7698ad5.
This reverts commit fbc6097.
This reverts commit d55c84b.
@cmichi
Copy link
Collaborator Author

cmichi commented Nov 24, 2021

I've reverted returning an Err to the assert! for now, since the UI doesn't support displaying this yet and hence ink-waterfall can't test for it. Will add it back once the UI exposes it.

@cmichi cmichi merged commit d2f19d9 into master Nov 24, 2021
@cmichi cmichi deleted the cmichi-implement-wildcard-selector branch November 24, 2021 13:54
xgreenx pushed a commit to Supercolony-net/ink that referenced this pull request Feb 8, 2022
* Implement wildcard selector, add `proxy` example

* Minor code and text improvements

* Remove code

* Fix function name

* Add unit tests for lang parsing

* Clarify where state resides

* Apply suggestions from code review

Co-authored-by: Hernando Castano <[email protected]>

* Implement comments

* Apply suggestions from code review

Co-authored-by: Robin Freyler <[email protected]>
Co-authored-by: Hernando Castano <[email protected]>
Co-authored-by: Alexander Theißen <[email protected]>

* Pre-process `_` to `"_"`

* Update String error message

* Rename `is_wildcard_selector` to `has_wildcard_selector`

* Move `_` to `"_"` transformation to lower layer

* Update test fixtures

* Update error message

* Update test fixtures

* Migrate to enum `SelectorOrWildcard`

* Allow wildcard selectors for constructors

* Fix tests

* Include clippy suggestion

* Fix error output matching

* Apply suggestions from code review

Co-authored-by: Robin Freyler <[email protected]>

* Fix suggestions

* Implement reviewer suggestions

* Improve matching

* Include clippy suggestion

* Update test fixture

* Detect multiple wildcard selectors in constructors

* Apply suggestions from code review

Co-authored-by: Hernando Castano <[email protected]>

* Rename enum variant `Selector` to `UserProvided`

* Return `Result:Err` instead of asserting

* Implement suggestions

* Revert "Return `Result:Err` instead of asserting"

This reverts commit 00f360d.

* Apply `cargo fmt`

* Disable overflow checks for `proxy` example

* Return `Result:Err` instead of asserting

* Fix import path

* Fix import path

* Fix import path

* Revert "Return `Result:Err` instead of asserting"

This reverts commit 7698ad5.
This reverts commit fbc6097.
This reverts commit d55c84b.

Co-authored-by: Hernando Castano <[email protected]>
Co-authored-by: Robin Freyler <[email protected]>
Co-authored-by: Alexander Theißen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow fallback message and constructor handlers
7 participants