Smart Contract JIT Compilation for Blockchain Execution Speed
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Blockchain nodes in decentralized systems face challenges in executing smart contracts across different hardware configurations and software environments, leading to inconsistencies and inefficiencies due to the need for multiple machine code versions and reduced execution efficiency.
Innovation Solution
Implementing a method that uses Just-In-Time (JIT) compilation to identify and cache hotspot code within smart contracts, allowing for efficient execution on various nodes by marking critical code sections with a hotspot identifier and optimizing compilation to balance execution speed and memory usage.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Adaptability or versatility
If multiple machine code versions are maintained for different hardware configurations, then compatibility across diverse environments is improved, but device complexity and storage requirements increase
Solution Approach 1:
The patent uses virtual machine bytecode as a universal copy that can be executed across different hardware architectures. Instead of maintaining multiple native machine code versions, a single bytecode format is created that serves as a platform-independent copy, allowing the same code to run on diverse hardware through the virtual machine abstraction layer.
Solution Approach 2:
The virtual machine acts as an intermediary between the high-level bytecode and various hardware platforms. The virtual machine translates and executes the platform-independent bytecode into hardware-specific instructions at runtime, eliminating the need for pre-compiling multiple machine code versions for different hardware configurations.
2Speed
If full smart contract code is compiled and cached, then execution speed is improved, but storage overhead increases
Solution Approach 1:
The patent segments the smart contract code into two parts: the immutable bytecode stored on-chain and the executable machine code generated locally. Only the necessary bytecode is stored in the blockchain, while the machine code is generated on-demand during execution, reducing storage overhead while maintaining execution speed through local compilation caching.
Solution Approach 2:
The system performs preliminary compilation of the bytecode into machine code before execution, caching the compiled result for subsequent use. This preliminary action of compiling and caching the machine code enables fast execution speeds while avoiding the need to store the complete original code, thus reducing storage requirements.
Data Source
Figure 1
Figure 2~3
Figure 4~5
AI summary
The present specification provides a method, a blockchain node, and a node device for executing a smart contract. An embodiment of the method for executing a smart contract includes: receiving, by a blockchain node, a request for creating a smart contract, where the request includes code of the smart contract, and the code of the smart contract includes hotspot code marked by using a hotspot identifier; compiling, by the blockchain node, the code of the smart contract into machine code through Just-In-Time (JIT) compilation after deploying the smart contract, and storing the hotspot code marked by using the hotspot identifier; and executing, by the blockchain node when executing the deployed smart contract, the machine code if the machine code corresponding to the code of the smart contract is locally stored. In the embodiments of the present specification, the blockchain node can greatly increase the speed of executing the smart contract.