Forkless Upgrade
Runtime upgrade
Forkless upgrade is a defining feature in Substrate used for blockchain development. The ability to update Runtime logic without forking the code base enables the blockchain to evolve and improve over time. This functionality can be achieved by defining Runtime (runtime WebAssembly blob) as part of the state of the blockchain.
Because Runtime is a part of the blockchain state, network maintainers can leverage the functionality of blockchain to achieve trustless, decentralized consensus and enhance Runtime security.
In the Runtime development framework, the system library uses set_code
calls to upgrade Runtime definitions. In the tutorial of upgrading running network, two methods to upgrade Runtime without shutting down nodes or interrupting operations are demonstrated. However, both upgrades in this tutorial demonstrate adding functionality to Runtime instead of updating the existing Runtime state. If the Runtime upgrade requires changing the existing state, it is likely that date migration is required.
Runtime version
During the process of Runtime version control, compiling nodes will generate platform native binaries and WebAssembly binaries. You can control which binaries to use at different points in the block production process with different command-line policy options. The components that choose Runtime execution environment to communicate with are called executors. Although you can override the default execution strategy for custom scenarios, in most cases, the execution program selects the appropriate binary file to use by evaluating the following information for both native and WebAssembly runtime binaries:
spec_ name
spec_ version
authoring_ version
To provide these information to the executor, Runtime has the following version structure:
Forkless runtime upgrade
Traditional blockchains require hard forking when upgrading their chain's state transition logic function. Hard fork requires all node operators to stop their nodes and manually upgrade to the latest executable. For distributed production networks, coordinating hard fork upgrades can be a complex process.
RuntimeVersion control attribute enables Substrate based blockchains to upgrade runtime logic in real-time without causing network forks.
In order to perform a forkless Runtime upgrade, Substrate use the existing Runtime logic to update the Wasm runtime stored on the blockchain to a new consensus breaking version with new logic. As part of the consensus process, this upgrade is pushed to all full nodes on the network.