IP Library › Granted Patent US 11,385,917
Granted Patent B2
US 11,385,917 · App. 17/361,076 · Granted Jul 12, 2022

Method for executing smart contract and blockchain node

Inventors: Ying Yan (Zhejiang, CN); Qi Liu (Zhejiang, CN)
Assignee: Alipay (Hangzhou) Information Technology Co., Ltd.
G06F9/4552H04L9/0618H04L2209/38
View Patent ↗
Loading inventors, assignments & file history…
Monitor This Case
Get email alerts when status or documents change.
Order Certified Copies
Most orders are placed with the USPTO same day — all within 24 business hours.
Order via The Patent Place →
Pre-filled with this patent's details
Quick Facts
Patent No.
US 11,385,917
App. No.
17/361,076
Granted
Jul 12, 2022
Kind
B2
Abstract

The present specification provides a method for executing a smart contract and a blockchain node. An implementation of a method for executing a smart contract includes: receiving, by a blockchain node, a request for creating a smart contract, the request including a bytecode of the smart contract; starting, by the blockchain node after completing deployment of the smart contract, to compile the bytecode of the smart contract into a machine code by using just-in-time and storing the machine code; and in execution of the deployed smart contract, executing, by the blockchain node, the machine code corresponding to a bytecode of the smart contract in response to the machine code being locally stored. According to the above implementations of the present application, the blockchain node can greatly increase a speed of executing a smart contract.

Claims (61)

1. A method for executing a smart contract, comprising:

after a smart contract of bytecodes has been deployed in a blockchain network, determining that a bytecode of the bytecodes of the smart contract is a high-frequency type of bytecode or a low-frequency type of bytecode via a hotspot analysis;

starting, by a blockchain node of the blockchain network at a first time point when the smart contract is not in execution, to compile the high-frequency type of bytecode of the bytecodes of the smart contract into a first machine code by using just-in-time (JIT) compilation and storing the first machine code locally at the blockchain node;

at a second time point different from the first time point and in execution of the smart contract, interpreting the low-frequency type of bytecode into a second machine code, the second machine code not being stored locally at the blockchain node; and

in the execution of the smart contract, improving a speed of the execution by directly executing, by the blockchain node, the first machine code corresponding to the high-frequency type of bytecode of the smart contract in response to the first machine code being locally stored.

2. The method according to claim 1 , wherein the starting to compile the high-frequency type of bytecode of the smart contract into the first machine code by using JIT compilation includes:

starting, by the blockchain node right after the smart contract has been deployed in the blockchain network, JIT compilation on the high-frequency type of bytecode of the smart contract;

performing, by the blockchain node after the smart contract has been deployed in the blockchain network, JIT compilation on the high-frequency type of bytecode of the smart contract within a determined idle time period; or

performing, by the blockchain node, JIT compilation on the high-frequency type of bytecode of the smart contract after receiving a transaction request for invoking the smart contract.

3. The method according to claim 1 , wherein the determining that a bytecode of the bytecodes of the smart contract is the high-frequency type of bytecode includes identifying a bytecode of a hotspot of the bytecodes in a process of at least one of interpreting or executing the bytecodes of the smart contract; and

the compiling the high-frequency type of bytecode of the smart contract into the first machine code by using JIT compilation and storing the first machine code includes performing compilation and storage optimization in a process of at least one of interpreting or executing the bytecodes of the smart contract.

4. The method according to claim 3 , wherein a granularity level of the bytecode of the hotspot includes a function level or a code block level.

5. The method according to claim 1 , wherein the executing, by the blockchain node, the first machine code includes:

executing, by the blockchain node, the first machine code corresponding to an invoked function or a code block in the smart contract.

6. The method according to claim 1 , comprising:

interpreting and executing, by the blockchain node in executing the smart contract, a bytecode of the bytecodes of the smart contract in response to a machine code of the smart contract not being locally stored.

7. The method according to claim 6 , wherein the interpreting and executing, by the blockchain node, the bytecode of the smart contract includes:

interpreting and executing, by the blockchain node, the bytecode corresponding to an invoked function in the smart contract.

8. The method according to claim 6 , wherein the interpreting and executing, by the blockchain node in executing the smart contract, the bytecode of the smart contract in response to the machine code of the smart contract not being locally stored includes:

querying, by the blockchain node in executing the smart contract, a current JIT compilation status of the bytecode of the smart contract in response to the machine code of the smart contract not being locally stored;

in response to the bytecode being in JIT compilation, interpreting and executing the bytecode of the smart contract; and

in response to the bytecode not being in JIT compilation, starting JIT compilation to interpret and execute the bytecode of the smart contract.

9. The method according to claim 1 , wherein the storing is caching.

10. The method according to claim 1 , comprising:

receiving, by the blockchain node, a request for deploying the smart contract in the blockchain network, the request including the bytecodes of the smart contract; and

causing, by the blockchain node, deployment of the smart contract in the blockchain network.

11. A blockchain node for executing a smart contract, comprising:

one or more processors; and

one or more computer-readable memories coupled to the one or more processors and having executable instructions stored thereon that are executable by the one or more processors to perform acts including:

after a smart contract of bytecodes has been deployed in a blockchain network, determining that a bytecode of the bytecodes of the smart contract is a high-frequency type of bytecode or a low-frequency type of bytecode via a hotspot analysis;

starting, at a first time point when the smart contract is not in execution, to compile the high-frequency type of bytecode of the bytecodes of the smart contract into a first machine code by using just-in-time (JIT) compilation and storing the first machine code locally at a blockchain node of the blockchain network;

at a second time point different from the first time point and in execution of the smart contract, interpreting the low-frequency type of bytecode into a second machine code, the second machine code not being stored locally at the blockchain node; and

in the execution of the smart contract, improving a speed of the execution by directly executing the first machine code corresponding to the high-frequency type of bytecode of the smart contract in response to the first machine code being locally stored.

12. The blockchain node according to claim 11 , wherein the starting to compile the high-frequency type of bytecode of the smart contract into the first machine code by using JIT compilation includes:

starting, right after the smart contract has been deployed in the blockchain network, JIT compilation on the high-frequency type of bytecode of the smart contract;

performing, after the smart contract has been deployed in the blockchain network, JIT compilation on the high-frequency type of bytecode of the smart contract within a determined idle time period; or

performing, JIT compilation on the high-frequency type of bytecode of the smart contract after receiving a transaction request for invoking the smart contract.

13. The blockchain node according to claim 11 , wherein the determining that a bytecode of the bytecodes of the smart contract is the high-frequency type of bytecode includes identifying a bytecode of a hotspot of the bytecodes in a process of at least one of interpreting or executing the bytecodes of the smart contract; and

the compiling the high-frequency type of bytecode of the smart contract into the first machine code by using JIT compilation and storing the first machine code includes performing compilation and storage optimization in a process of at least one of interpreting or executing the bytecodes of the smart contract.

14. The blockchain node according to claim 11 , wherein the acts include:

interpreting and executing, in executing the smart contract, a bytecode of the bytecodes of the smart contract in response to a machine code of the smart contract not being locally stored.

15. The blockchain node according to claim 14 , wherein the interpreting and executing the bytecode of the smart contract includes:

interpreting and executing the bytecode corresponding to an invoked function in the smart contract.

16. The blockchain node according to claim 14 , wherein the interpreting and executing, in executing the smart contract, the bytecode of the smart contract in response to the machine code of the smart contract not being locally stored includes:

querying, in executing the smart contract, a current JIT compilation status of the bytecode of the smart contract in response to the machine code of the smart contract not being locally stored;

in response to the bytecode being in JIT compilation, interpreting and executing the bytecode of the smart contract; and

in response to the bytecode not being in JIT compilation, starting JIT compilation to interpret and execute the bytecode of the smart contract.

17. The blockchain node of claim 11 , wherein the acts include:

receiving a request for deploying the smart contract in the blockchain network, the request including the bytecodes of the smart contract; and

causing deployment of the smart contract in the blockchain network.

18. A non-transitory storage medium, the storage medium having executable instructions stored thereon that are executable by one or more processors to perform acts including:

after a smart contract of bytecodes has been deployed in a blockchain network, determining that a bytecode of the bytecodes of the smart contract is a high-frequency type of bytecode or a low-frequency type of bytecode via a hotspot analysis;

starting, at a first time point when the smart contract is not in execution, to compile the high-frequency type of bytecode of the bytecodes of the smart contract into a first machine code by using just-in-time (JIT) compilation and storing the first machine code locally at a blockchain node of the blockchain network;

at a second time point different from the first time point and in execution of the smart contract, interpreting the low-frequency type of bytecode into a second machine code, the second machine code not being stored locally at the blockchain node; and

in the execution of the smart contract, improving a speed of the execution by directly executing the first machine code corresponding to the high-frequency type of bytecode of the smart contract in response to the first machine code being locally stored.

19. The storage medium according to claim 18 , wherein the starting to compile the high-frequency type of bytecode of the smart contract into the first machine code by using JIT compilation includes:

starting, right after the smart contract has been deployed in the blockchain network, JIT compilation on the high-frequency type of bytecode of the smart contract;

performing, after the smart contract has been deployed in the blockchain network, JIT compilation on the high-frequency type of bytecode of the smart contract within a determined idle time period; or

performing, JIT compilation on the high-frequency type of bytecode of the smart contract after receiving a transaction request for invoking the smart contract.

20. The storage medium according to claim 18 , wherein the determining that a bytecode of the bytecodes of the smart contract is the high-frequency type of bytecode includes identifying a bytecode of a hotspot of the bytecodes in a process of at least one of interpreting or executing the bytecodes of the smart contract; and

the compiling the high-frequency type of bytecode of the smart contract into the first machine code by using JIT compilation and storing the first machine code includes performing compilation and storage optimization in a process of at least one of interpreting or executing the bytecodes of the smart contract.

Assignments (2)
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Mar 18, 2025
From: ALIPAY (HANGZHOU) INFORMATION TECHNOLOGY CO., LTD.
To: ANT BLOCKCHAIN TECHNOLOGY (SHANGHAI) CO., LTD.
Reel/Frame 070552/0207 →
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Jul 7, 2021
From: YAN, YING; LIU, QI
To: ALIPAY (HANGZHOU) INFORMATION TECHNOLOGY CO., LTD.
Reel/Frame 056779/0363 →
Priority Claims (1)
CN 202010899217.6 · Aug 31, 2020 · national
Continuity (1)
Related Publication 20220066803A1 · Mar 3, 2022