IP Library › Granted Patent US 12,210,892
Granted Patent B2
US 12,210,892 · App. 17/348,979 · Granted Jan 28, 2025

Method for implementing smart contract based on blockchain

Inventor: Wei Xiao (Beijing, CN)
Assignee: BAIDU ONLINE NETWORK TECHNOLOGY (BEIJING) CO., LTD.
G06F9/45558G06F9/5016G06F9/5027
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 12,210,892
App. No.
17/348,979
Granted
Jan 28, 2025
Kind
B2
Abstract

A method for implementing a smart contract based on a blockchain, a device, and a medium are provided. The detailed implementation includes: creating a resident process for a resident smart contract and creating a virtual machine by the resident process when achieving an enable condition of the resident smart contract; loading codes of the resident smart contract into a memory through the virtual machine; receiving a data access request generated by a normal smart contract within a block generation cycle through an across-contract calling interface of the virtual machine; and executing the resident smart contract through the virtual machine to process the data access request and returning a data access result to the normal smart contract.

Claims (57)

1. A method for implementing a smart contract based on a blockchain, applied to a blockchain node, and comprising:

creating a resident process for a resident smart contract and creating a virtual machine by the resident process in response to achieving an enable condition of the resident smart contract;

loading codes of the resident smart contract into a memory through the virtual machine;

receiving a data access request generated by a normal smart contract within a block generation cycle through an across-contract calling interface of the virtual machine;

executing the resident smart contract through the virtual machine to process the data access request and returning a data access result to the normal smart contract; and

in response to achieving a disable condition of the resident smart contract, solidifying data stored by the resident smart contract in the memory, writing the data into a disk, and killing a process allocated to the virtual machine and clearing a memory space allocated to the virtual machine of the resident smart contract;

wherein a life cycle of a process of the normal smart contract in the memory is one block generation cycle, and a life cycle of the resident process of the resident smart contract in the memory is greater than one block generation cycle.

2. The method of claim 1 , wherein achieving the enable condition of the resident smart contract comprises at least one of:

achieving the enable condition of the resident smart contract when a blockchain system is started at a local blockchain node; and

achieving the enable condition of the resident smart contract when the resident smart contract is called for the first time.

3. The method of claim 1 , wherein achieving the disable condition of the resident smart contract comprises at least one of:

achieving the disable condition of the resident smart contract when a blockchain system is turned off at a local blockchain node; and

achieving the disable condition of the resident smart contract when a degradation requirement is generated for a running resource of the local blockchain node, wherein the running resource comprises at least one of a memory resource and a computing resource.

4. The method of claim 1 , further comprising:

in response to achieving a suspension condition of the resident smart contract, reserving a process handle for the resident process, writing data stored by the resident smart contract in the memory into a temporary storage area in the disk, and killing a process allocated to the virtual machine and clearing a memory space allocated to the virtual machine of the resident smart contract.

5. The method of claim 1 , wherein the across-contract calling interface is implemented based on an inter-process communication protocol.

6. The method of claim 1 , further comprising:

in response to starting processing of a current block, transmitting block dependent data of the current block to the resident process to update data in a memory space of the resident process to be consistent with data in the current block.

7. The method of claim 1 , further comprising:

obtaining block dependent data transmitted by the normal smart contract through the across-contract calling interface, and updating the block dependent data to a memory space of the resident process to maintain data in the memory space of the resident smart contract be consistent with data in the current block.

8. The method of claim 1 , wherein an access object of the data access request comprises blockchain account information, a transaction request count value, a block count value, and across-block data.

9. The method of claim 1 , further comprising one of following:

in response to occurring a block rollback event, notifying the resident process by a main program of a blockchain system to perform a rollback operation based on at least one transaction request of a rollback block to update data in a memory space of the resident intelligent contract; and

in response to occurring a block rollback event, notifying, by the main program of the blockchain system, the resident process to be closed and restarted, to reload rolled-back block data from a disk.

10. An electronic device, comprising:

at least one processor; and

a memory, communicatively coupled to the at least one processor,

wherein the memory is configured to store instructions executable by the at least one processor, and when the instructions are executed by the at least one processor, the at least one processor is caused to execute the method for implementing a smart contract based on a blockchain comprising:

creating a resident process for a resident smart contract and creating a virtual machine by the resident process in response to achieving an enable condition of the resident smart contract;

loading codes of the resident smart contract into a memory through the virtual machine;

receiving a data access request generated by a normal smart contract within a block generation cycle through an across-contract calling interface of the virtual machine; and

executing the resident smart contract through the virtual machine to process the data access request and returning a data access result to the normal smart contract; and

in response to achieving a disable condition of the resident smart contract, solidifying data stored by the resident smart contract in the memory, writing the data into a disk, and killing a process allocated to the virtual machine and clearing a memory space allocated to the virtual machine of the resident smart contract,

wherein a life cycle of a process of the normal smart contract in the memory is one block generation cycle, and a life cycle of the resident process of the resident smart contract in the memory is greater than one block generation cycle.

11. The electronic device of claim 10 , wherein achieving the enable condition of the resident smart contract comprises at least one of:

achieving the enable condition of the resident smart contract when a blockchain system is started at a local blockchain node; and

achieving the enable condition of the resident smart contract when the resident smart contract is called for the first time.

12. The electronic device of claim 10 , wherein achieving the disable condition of the resident smart contract comprises at least one of:

achieving the disable condition of the resident smart contract when a blockchain system is turned off at a local blockchain node; and

achieving the disable condition of the resident smart contract when a degradation requirement is generated for a running resource of the local blockchain node, wherein the running resource comprises a memory resource or a computing resource.

13. The electronic device of claim 10 , wherein the method further comprises:

in response to achieving a suspension condition of the resident smart contract, reserving a process handle for the resident process, writing data stored by the resident smart contract in the memory into a temporary storage area in the disk, and killing a process allocated to the virtual machine and clearing a memory space allocated to the virtual machine of the resident smart contract.

14. The electronic device of claim 10 , wherein the across-contract calling interface is implemented based on an inter-process communication protocol.

15. The electronic device of claim 10 , wherein the method further comprises:

in response to starting processing of a current block, transmitting block dependent data of the current block to the resident process to update data in a memory space of the resident process to be consistent with data in the current block.

16. The electronic device of claim 10 , wherein the method further comprises:

obtaining block dependent data transmitted by the normal smart contract through the across-contract calling interface, and updating the block dependent data to a memory space of the resident process to maintain data in the memory space of the resident smart contract be consistent with data in the current block.

17. The electronic device of claim 10 , wherein the method further comprises:

in response to occurring a block rollback event, notifying the resident process by a main program of a blockchain system to perform a rollback operation based on at least one transaction request of a rollback block to update data in a memory space of the resident intelligent contract; or

in response to occurring a block rollback event, notifying, by the main program of the blockchain system, the resident process to be closed and restarted, to reload rolled-back block data from a disk.

18. A non-transitory computer readable storage medium having computer instructions stored thereon, wherein the computer instructions are configured to cause a computer to execute the method for implementing a smart contract based on a blockchain comprising:

creating a resident process for a resident smart contract and creating a virtual machine by the resident process in response to achieving an enable condition of the resident smart contract;

loading codes of the resident smart contract into a memory through the virtual machine;

receiving a data access request generated by a normal smart contract within a block generation cycle through an across-contract calling interface of the virtual machine; and

executing the resident smart contract through the virtual machine to process the data access request and returning a data access result to the normal smart contract; and

in response to achieving a disable condition of the resident smart contract, solidifying data stored by the resident smart contract in the memory, writing the data into a disk, and killing a process allocated to the virtual machine and clearing a memory space allocated to the virtual machine of the resident smart contract;

wherein a life cycle of a process of the normal smart contract in the memory is one block generation cycle, and a life cycle of the resident process of the resident smart contract in the memory is greater than one block generation cycle.

Assignments (1)
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Jul 1, 2022
From: XIAO, WEI
To: BAIDU ONLINE NETWORK TECHNOLOGY (BEIJING) CO., LTD.
Reel/Frame 060425/0900 →
Priority Claims (1)
CN 202010677698.6 · Jul 15, 2020 · national
Continuity (1)
Related Publication 20210311770A1 · Oct 7, 2021
References Cited (12)
US 10425230B1 · Tang et al. · 2019 [cited by examiner]
US 20170353309A1 · Gray · 2017 [cited by applicant]
US 20180060836A1 · Castagna · 2018 [cited by examiner]
US 20190379754A1 · Krishnaswamy · 2019 [cited by examiner]
CN 108734464A · 2018 [cited by applicant]
CN 109032706A · 2018 [cited by applicant]
CN 110096338A · 2019 [cited by applicant]
CN 110309024A · 2019 [cited by applicant]
KR 20190015287A · 2019 [cited by applicant]
Search Report for EP application 21179669.3 dated Dec. 1, 2021. [cited by applicant]
CN Office Action in Application 202010677698.6 dated Aug. 31, 2020. [cited by applicant]
KR Office Action in Application No. 10-2021-0045059 Dated Jun. 24, 2022. [cited by applicant]