This repository was archived by the owner on Nov 15, 2023. It is now read-only.
contracts: Allow ChainExtension::call() to access &mut self#11874
Merged
paritytech-processbot[bot] merged 7 commits intomasterfrom Jul 25, 2022
Merged
contracts: Allow ChainExtension::call() to access &mut self#11874paritytech-processbot[bot] merged 7 commits intomasterfrom
ChainExtension::call() to access &mut self#11874paritytech-processbot[bot] merged 7 commits intomasterfrom
Conversation
cmichi
reviewed
Jul 21, 2022
cmichi
approved these changes
Jul 21, 2022
HCastano
reviewed
Jul 22, 2022
HCastano
approved these changes
Jul 22, 2022
Contributor
HCastano
left a comment
There was a problem hiding this comment.
Good stuff! Also, I ❤️ the porting guide
Member
Author
|
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 |
Member
Author
There was a problem hiding this comment.
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 <[email protected]> * Rename func_id -> id * Replace `id` param by two functions on `env` Co-authored-by: Hernando Castano <[email protected]>
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 <[email protected]> * Rename func_id -> id * Replace `id` param by two functions on `env` Co-authored-by: Hernando Castano <[email protected]>
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
ChainExtensionand hence it will break the build of existing extensions. Extensions authors need to be aware of the following changes:ChainExtension:call()now takes&mut selfinstead of noselfat allJust add
mut &selfto your existing chain extensions'callfunctions. This is all that needs to be done.ChainExtensionneed to implementDefaultbecause 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_idparameter was removed fromcallIt 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.