-
Notifications
You must be signed in to change notification settings - Fork 2.6k
runtime-interface: Implement register_only
functions
#10640
runtime-interface: Implement register_only
functions
#10640
Conversation
The runtime interface supports versioning of functions. Currently, if you add a new function it will be used by the runtime automatically. This results in requiring all nodes of a network to upgrade before the runtime is upgraded, otherwise they will fail to instantiate the new runtime because of missing host functions. This pr introduces `register_only` functions. This can be used when a new runtime interface function should be introduced, but the actual usage can be deferred. This means that nodes will have the host function for this, but the runtime will still use the old version of the function when being compiled for wasm. However, when a runtime is enacted that uses the new host function, the "old nodes" will already have the host function and will continue to work.
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, I am not too sure how things will behave in practice. For instance if/when changing
substrate/primitives/io/src/lib.rs
Line 397 in fb24fda
#[version(2)] |
register_only
, runtime code will need to be patched back to _v1 prototype (without the version). But it also reduces the surface of code to patch, so looks good.
/// While this struct is only for parsing the inner parts inside the `()`. | ||
struct VersionAttribute { | ||
version: u32, | ||
register_only: Option<attributes::register_only>, |
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 be just bool? (also fine this 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.
Yeah, but I use this struct here directly for parsing. So, I decided to do it this way.
@@ -153,6 +153,22 @@ pub use sp_std; | |||
/// [17].to_vec() | |||
/// } | |||
/// | |||
/// /// Call function, different version and only being registered. | |||
/// /// | |||
/// /// This `register_only` version is only being registered, aka exposed to the runtime, |
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.
/// /// This `register_only` version is only being registered, aka exposed to the runtime, | |
/// /// `register_only` indicates version is only being registered, aka exposed to the runtime, |
/// /// nodes have the host functions available, because otherwise they fail at instantiation | ||
/// /// of the runtime. With `register_only` the function will not be used when compiling the | ||
/// /// runtime, but it will already be there for a future version of the runtime that will | ||
/// /// switch to using these host 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.
Just to be sure I catch the intent and implication.
So the switch will be done by removing register_only
and will require nodes updates (client hard fork).
So the PR makes it possible to stage some pending new function, but will still need a big update later.
The update may require some parachain to patch this flag until they do the client/node, can be a bit of work if some tests does need switching when removing the flag.
I feel like I am back in the situation where I would put this behind a feature (not a great idea I know).
Thinking twice, it feels good this way, the patch to retain register
would be very small and the client update would in most case need to happen soon (to get latest runtime changes).
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.
The whole point of this is the following. Let's imagine we want to add new host functions, like with your trie pr. Currently we only we add these functions and directly start using them from the runtime. This way, the moment a runtime using these new host functions is enacted, the node needs to have this host functions ready or it starts to fail importing new blocks. With parachains and the relay chain node currently being compiled into the parachain node it even means that parachain teams need to bring out a new node release on time as well just to have the host functions ready for the relay chain. This is really shitty.
With register_only
, we will be able to prepare the node side. Aka we will already be able to ship the new host functions now, but the runtime associated to the release or even the one after that don't use the new host functions. It will then be enabled at some later point when we are aware that most of the network has upgraded.
This can not be done by features, because using a feature would completely remove the host function and again we would not have it in the node. The feature itself could then be used to disable the runtime functionality and maybe for also making removing the register_only
when it is time.
@@ -123,6 +123,15 @@ pub trait TestApi { | |||
data == 42 |
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.
weird indent (may be github).
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.
Yeah that is github, it is fucking it up for me as well.
Co-authored-by: cheme <emericchevalier.pro@gmail.com>
Co-authored-by: cheme <emericchevalier.pro@gmail.com>
bot merge |
Bot will approve on the behalf of @bkchr, since they are a team lead, in an attempt to reach the minimum approval count |
) * runtime-interface: Implement `register_only` functions The runtime interface supports versioning of functions. Currently, if you add a new function it will be used by the runtime automatically. This results in requiring all nodes of a network to upgrade before the runtime is upgraded, otherwise they will fail to instantiate the new runtime because of missing host functions. This pr introduces `register_only` functions. This can be used when a new runtime interface function should be introduced, but the actual usage can be deferred. This means that nodes will have the host function for this, but the runtime will still use the old version of the function when being compiled for wasm. However, when a runtime is enacted that uses the new host function, the "old nodes" will already have the host function and will continue to work. * Update primitives/runtime-interface/src/lib.rs Co-authored-by: cheme <emericchevalier.pro@gmail.com> * Update primitives/runtime-interface/proc-macro/src/utils.rs Co-authored-by: cheme <emericchevalier.pro@gmail.com> * FMT Co-authored-by: cheme <emericchevalier.pro@gmail.com>
) * runtime-interface: Implement `register_only` functions The runtime interface supports versioning of functions. Currently, if you add a new function it will be used by the runtime automatically. This results in requiring all nodes of a network to upgrade before the runtime is upgraded, otherwise they will fail to instantiate the new runtime because of missing host functions. This pr introduces `register_only` functions. This can be used when a new runtime interface function should be introduced, but the actual usage can be deferred. This means that nodes will have the host function for this, but the runtime will still use the old version of the function when being compiled for wasm. However, when a runtime is enacted that uses the new host function, the "old nodes" will already have the host function and will continue to work. * Update primitives/runtime-interface/src/lib.rs Co-authored-by: cheme <emericchevalier.pro@gmail.com> * Update primitives/runtime-interface/proc-macro/src/utils.rs Co-authored-by: cheme <emericchevalier.pro@gmail.com> * FMT Co-authored-by: cheme <emericchevalier.pro@gmail.com>
The runtime interface supports versioning of functions. Currently, if you add a new function it will
be used by the runtime automatically. This results in requiring all nodes of a network to upgrade
before the runtime is upgraded, otherwise they will fail to instantiate the new runtime because of
missing host functions. This pr introduces
register_only
functions. This can be used when a newruntime interface function should be introduced, but the actual usage can be deferred. This means
that nodes will have the host function for this, but the runtime will still use the old version of
the function when being compiled for wasm. However, when a runtime is enacted that uses the new host
function, the "old nodes" will already have the host function and will continue to work.