This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
contracts: Allow ChainExtension::call()
to access &mut self
#11874
Merged
Conversation
This file contains 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
athei
added
A0-please_review
Pull request needs code review.
B7-runtimenoteworthy
C1-low
PR touches the given topic and has a low impact on builders.
D2-notlive 💤
PR contains changes in a runtime directory that is not deployed to a chain that requires an audit.
labels
Jul 20, 2022
cmichi
reviewed
Jul 21, 2022
cmichi
approved these changes
Jul 21, 2022
HCastano
reviewed
Jul 22, 2022
Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>
HCastano
approved these changes
Jul 22, 2022
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.
Good stuff! Also, I ❤️ the porting guide
bot merge |
Waiting for commit status. |
kvinwang
reviewed
Aug 5, 2022
/// It returns the two least significant bytes of the `id` passed by a contract as the other | ||
/// two bytes represent the chain extension itself (the code which is calling this function). | ||
pub fn func_id(&self) -> u16 { | ||
(self.inner.id & 0x00FF) as u16 |
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.
Shouldn't it be 0xFFFF?
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.
Oops. You are right. This just masks the last byte. Do you are to open a PR? Would be good to modify one of the tests to actually catch that (change one of the function ids to use the second byte, too).
DaviRain-Su
pushed a commit
to octopus-network/substrate
that referenced
this pull request
Aug 23, 2022
…tytech#11874) * Give chain extensions the ability to store some temporary values * Update frame/contracts/src/wasm/runtime.rs Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com> * Rename func_id -> id * Replace `id` param by two functions on `env` Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>
2 tasks
ark0f
pushed a commit
to gear-tech/substrate
that referenced
this pull request
Feb 27, 2023
…tytech#11874) * Give chain extensions the ability to store some temporary values * Update frame/contracts/src/wasm/runtime.rs Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com> * Rename func_id -> id * Replace `id` param by two functions on `env` Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
A0-please_review
Pull request needs code review.
C1-low
PR touches the given topic and has a low impact on builders.
D2-notlive 💤
PR contains changes in a runtime directory that is not deployed to a chain that requires an audit.
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.
Previously,
ChainExtension:call()
didn't had access toself
. Mainly because it wasn't clear what the lifetime (when is it created and droped) of such a value would be.Turned out that a useful lifetime for this value is per-call (not per call stack). This allows chain extensions to hold some temporary values within a single call. The need for this came up during implementation of an XCM chain extension. This PR therefore introduces two changes:
Porting Guide
This PR changes the interface of
ChainExtension
and hence it will break the build of existing extensions. Extensions authors need to be aware of the following changes:ChainExtension:call()
now takes&mut self
instead of noself
at allJust add
mut &self
to your existing chain extensions'call
functions. This is all that needs to be done.ChainExtension
need to implementDefault
because they need to be initialized during contract executionPre-existing chain extensions are probably unit structs and hence a simple
#[derive(Default)]
on this struct will be enough to resolve the situation.The
func_id
parameter was removed fromcall
It is replaced by an associated function on the
Environment
. The id can be fetched by callingenv.func_id()
. This is a drive-by followup fix for #11816.