Blockchain Node Smart Contract JIT Compilation
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
In the context of blockchain 2.0, executing smart contracts efficiently across diverse hardware and software environments is challenging due to differences in CPU instruction sets and operating systems, leading to potential blockchain forks and reduced scalability.
Innovation Solution
Implementing Just-In-Time (JIT) compilation on blockchain nodes to convert smart contract bytecode into machine code, allowing for local execution when a predetermined number of nodes store the machine code, ensuring stability and speed by avoiding interpretation execution and caching frequently executed code.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Adaptability or versatility
If blockchain nodes interpret and execute bytecode of smart contracts, then compatibility across different hardware and software environments is maintained, but execution speed is reduced
Solution Approach 1:
The patent applies preliminary action by pre-compiling bytecode to machine code in advance and caching it locally on blockchain nodes. When a smart contract is first executed, the node performs JIT compilation to convert bytecode to machine code and stores it locally. Subsequent executions directly use the cached machine code, eliminating the need for repeated interpretation and significantly improving execution speed while maintaining cross-platform compatibility.
2Speed
If blockchain nodes use JIT compilation to convert bytecode to machine code for local execution, then execution speed is improved, but device complexity increases
Solution Approach 1:
The patent applies copying by creating and storing copies of machine code locally on blockchain nodes. Instead of requiring each node to independently interpret bytecode every time, the system compiles bytecode to machine code once and creates local copies that can be executed directly. This copying mechanism reduces the computational complexity of each execution while maintaining execution speed improvements.
3Speed
If different blockchain nodes execute smart contracts using different CPU instruction sets, then local execution speed is maximized, but blockchain forks may occur
Solution Approach 1:
The patent applies homogeneity by ensuring that all blockchain nodes execute the same machine code for smart contracts. By compiling bytecode to a standardized machine code representation and caching it locally across all nodes, the system ensures consistent execution results regardless of the underlying hardware architecture. This homogenization of execution logic prevents blockchain forks while still allowing nodes to benefit from local execution speed.
Data Source
Figure 1
Figure 2
Figure 3
AI summary
Provided in one or more embodiments of the present specification is a method, a blockchain node and a storage medium for executing a smart contract. Embodiments of a method of executing a smart contract include: receiving, by a blockchain node, a request for creating a smart contract, wherein the request includes a bytecode of the smart contract; starting, by the blockchain node when the blockchain node completes deployment of the smart contract, to turn a bytecode of the smart contract into a machine code through Just-In-Time JIT compilation and store the machine code; and when the blockchain node is to execute the smart contract deployed, the machine code of the smart contract is stored locally and a number of blockchain nodes storing the machine code of the smart contract in a blockchain network is not less than a predetermined number, executing, by the blockchain node, the machine code. With the above embodiments of the present specification, the blockchain node can greatly improve the speed of executing smart contracts.