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

Fix ordering of message ids if the trait is implemented before the inherent section #1235

Merged
merged 6 commits into from
May 2, 2022

Conversation

xgreenx
Copy link
Collaborator

@xgreenx xgreenx commented Apr 26, 2022

Fixed the ordering of ids. Before it was sorted:
inherent_ids
traits_ids

Now the ordering is not changed. It is important for dispatching logic and wildcard. Dispatching takes the global index of the method but if the order is changed, it will use the wrong id. In the case of a wildcard, it breaks it at all if the trait was implemented before the inherent section.

inherent_ids
traits_ids

Now the ordering is not changed. It is important for dispatching logic and wildcard. Dispatching takes the global index of the method but if ordering is changed, it will use wrong id. In the case of wildcard it breaks it at all if trait was implemented before inherent section.
Copy link
Collaborator

@ascjones ascjones left a comment

Choose a reason for hiding this comment

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

Copy link
Collaborator

@ascjones ascjones left a comment

Choose a reason for hiding this comment

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

LGTM

@ascjones ascjones changed the title Wrong ordering of ids if the trait is implemented before the inherent section Fix ordering of message ids if the trait is implemented before the inherent section Apr 26, 2022
@xgreenx
Copy link
Collaborator Author

xgreenx commented Apr 26, 2022

CI can't pull my branch=(
image

@ascjones
Copy link
Collaborator

At a glance looks like it is not configured to pull from forks. Maybe we need to fix that. Anyway we can go ahead and merge if we get another approval since the waterfall is not a requirement for merge. @cmichi

@@ -34,7 +59,7 @@ fn main() {
>>::IDS[0]
},
>>::SELECTOR,
[0x5A, 0x6A, 0xC1, 0x5D],
[0xFB, 0xAB, 0x03, 0xCE],
Copy link
Collaborator

Choose a reason for hiding this comment

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

So this is a breaking change. Will require a minor release.

@@ -33,6 +33,30 @@ pub mod proxy {
admin: AccountId,
}

/// The trait provides information about `Proxy`
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the reason why you added this trait btw.?

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 added it to test the behavior of the wildcard in case of the trait is implemented before the inherent section.

But it was before I added the UI test=) So now it is not so actual but we can keep it to verify that the behavior is right during the e2e test.

Co-authored-by: Michael Müller <mich@elmueller.net>
Comment on lines 36 to 59
/// The trait provides information about the forward pattern used in this contract.
#[ink_lang::trait_definition]
pub trait Forwarder {
/// Returns the `AccountId` of the contract that calls are forward to.
#[ink(message)]
fn forward_to(&self) -> AccountId;

/// Returns the `AccountId` of the admin of the current contract.
#[ink(message)]
fn admin(&self) -> AccountId;
}

impl Forwarder for Proxy {
#[ink(message)]
fn forward_to(&self) -> AccountId {
self.forward_to
}

#[ink(message)]
fn admin(&self) -> AccountId {
self.admin
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
/// The trait provides information about the forward pattern used in this contract.
#[ink_lang::trait_definition]
pub trait Forwarder {
/// Returns the `AccountId` of the contract that calls are forward to.
#[ink(message)]
fn forward_to(&self) -> AccountId;
/// Returns the `AccountId` of the admin of the current contract.
#[ink(message)]
fn admin(&self) -> AccountId;
}
impl Forwarder for Proxy {
#[ink(message)]
fn forward_to(&self) -> AccountId {
self.forward_to
}
#[ink(message)]
fn admin(&self) -> AccountId {
self.admin
}
}

I would remove it, as it doesn't serve a function to the example. I'd like to keep the examples as minimal as possible to focus on illustrating the point (in this case how to build an upgradeable contract).

PR looks good besides that!

Copy link
Collaborator

@cmichi cmichi left a comment

Choose a reason for hiding this comment

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

Thank you!

@cmichi cmichi merged commit d4a372a into use-ink:master May 2, 2022
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.

3 participants