![]() The setCode function checks that the origin is Root. ![]() A Root origin call is dispatched to the setCode function.She is, so the rest of the function runs.The sudo function checks that “Alice” is the Sudo key.When this transaction is dispatched, the following logic is executed: Of which the input to setCode is the wasm file for our new runtime.The proposal we are making is the setCode function of the Consensus module.We are calling the sudo function of the Sudo module.We are making a transaction using “Alice”, who has been set as the Sudo key.Walking through the UI you will see that: ![]() Thus, when you use something like the Polkadot UI to do a runtime upgrade, it will look like this: This privileged function checks that the caller must have Root origin, thanks to the decl_module! macro, then it puts the Wasm bytecode into a well_known_key called CODE. This single line of logic is enough to power the entire “upgrade” feature of Substrate forkless runtime upgrades. This is what a privileged function look like: There is no way to produce a Root origin other than through internal runtime logic, and as such, we can treat functions that require this origin as privileged functions. The origin could be Signed as it was in the Sudo module, which represents a basic signed transaction, but Substrate also provides a Root origin which describes a call that comes from within the runtime itself. The origin of a call describes where the call has come from, and every dispatchable function should check at the beginning of the function that the call origin matches what is expected. Substrate has the concept of “Privileged Functions” which are functions which specifically require Root origin. The Sudo module wouldn’t do much unless there were also “sudo-able” functions, and that is precisely what we will talk about next.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |