IP Library › Granted Patent US 11,803,447
Granted Patent B2
US 11,803,447 · App. 17/347,139 · Granted Oct 31, 2023

Transaction processing method, apparatus, and electronic device for blockchain

Inventors: Kang Li (Hangzhou, CN); Fuxi Deng (Hangzhou, CN)
Assignee: ALIPAY (HANGZHOU) INFORMATION TECHNOLOGY CO., LTD.
G06F11/1438G06F9/3851G06F11/1425H04L9/3236H04L9/50
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,803,447
App. No.
17/347,139
Granted
Oct 31, 2023
Kind
B2
Abstract

Embodiments of this specification provide a transaction processing method, apparatus, and electronic device for a blockchain. The method includes: executing, by a blockchain node in the blockchain, a consensus protocol for an N-th round of consensus, wherein the consensus protocol comprises reaching a consensus on a blockchain transaction of the N-th round of consensus and upon the consensus being reached, executing the blockchain transaction of the N-th round of consensus; writing, by the blockchain node after the execution of the blockchain transaction, a block comprising the blockchain transaction of the N-th round of consensus into the blockchain; and concurrently with the writing of the block, executing, by the blockchain node, the consensus protocol for an (N+1)-th round of consensus in the blockchain.

Claims (55)

1. A transaction processing method for a blockchain, comprising:

creating, by a blockchain node in the blockchain, a first thread, a second thread, and a third thread;

executing, by the blockchain node in the blockchain using the first thread, a consensus protocol for an N-th round of consensus, wherein N is a positive integer, and the consensus protocol comprises reaching a consensus on a blockchain transaction of the N-th round of consensus and upon the N-th round of consensus being reached, executing the blockchain transaction of the N-th round of consensus;

writing, by the blockchain node after the execution of the blockchain transaction using the second thread, a block comprising the blockchain transaction of the N-th round of consensus into the blockchain;

monitoring, by the blockchain node using the third thread, the second thread for detecting a completion of the writing of the block comprising the blockchain transaction of the N-th round of consensus in the second thread;

concurrently with the writing of the block comprising the blockchain transaction of the N-th round of consensus into the blockchain in the second thread, executing, by the blockchain node using the first thread, the consensus protocol for an (N+1)-th round of consensus in the blockchain and upon the (N+1)-th round of consensus being reached, executing, by the blockchain node using the first thread, a blockchain transaction of the (N+1)-th round of consensus in the blockchain;

in response to the third thread detecting the completion of the writing of the block comprising the blockchain transaction of the N-th round of consensus, adding a task of writing a block comprising the blockchain transaction of the (N+1)-th round of consensus into the second thread; and

after both (1) the adding of the task of writing of the block comprising the blockchain transaction of the (N+1)-th round of consensus into the blockchain into the second thread and (2) the executing of the blockchain transaction of the (N+1)-th round of consensus in the blockchain in the first thread, concurrently executing, in the second thread, the task of writing the block comprising the blockchain transaction of the (N+1)-th round of consensus into the blockchain and executing, in the first thread, the consensus protocol for an (N+2)-th round of consensus in the blockchain.

2. The transaction processing method according to claim 1 , further comprising:

creating, by the blockchain node for the first thread and the second thread, a thread lock for accessing blockchain variables shared by different blockchain transactions, and in the first thread and the second thread, a thread corresponding to a preceding consensus round requests a usage right of the thread lock before a thread corresponding to a post consensus round.

3. The transaction processing method according to claim 1 , further comprising:

if the blockchain node crashes when performing the writing of the block comprising the transaction of the N-th round of consensus, obtaining, by the blockchain node from another blockchain node after being restarted and recovered, information of a block in which the transaction of the N-th round of consensus is written; and

performing the writing of the block again for the transaction of the N-th round of consensus based on the information of the block, wherein the block is generated by the another blockchain node by completing a block write operation for the transaction of the N-th round of consensus.

4. The transaction processing method according to claim 3 , further comprising:

if the blockchain node fails to obtain, from the another blockchain node after being restarted and recovered, the information of the block in which the transaction of the N-th round of consensus is written, simulating, by the blockchain node, the N-th round of consensus based on a consensus execution log, to re-determine the transaction of the N-th round of consensus; and

performing the writing of the block again for the re-determined transaction of the N-th round of consensus.

5. The transaction processing method according to claim 1 , wherein

the (N+1)-th round of consensus is initiated by a target blockchain node in the blockchain when the writing of the block comprising the transaction of the N-th round of consensus is performed, and the target blockchain node serves as a consensus master node of the blockchain.

6. The transaction processing method according to claim 1 , wherein the executing the consensus protocol for the (N+1)-th round of consensus in the blockchain comprises:

reaching a consensus on a blockchain transaction of the (N+1)-th round of consensus;

upon the consensus being reached, executing the blockchain transaction of the (N+1)-th round of consensus; and

adjusting a tree structure of the blockchain by submitting a commit operation before writing a block comprising the blockchain transaction of the (N+1)-th round of consensus into the blockchain;

wherein the commit operation is submitted after the writing of the block comprising the blockchain transaction of the N-th round of consensus into the blockchain.

7. A system of a blockchain node in a blockchain, comprising one or more processors and one or more non-transitory computer-readable memories storing instructions that, when executed by the one or more processors, cause the system to perform operations comprising:

creating, by the blockchain node in the blockchain, a first thread, a second thread, and a third thread;

executing, by the blockchain node in the blockchain using the first thread, a consensus protocol for an N-th round of consensus, wherein N is a positive integer, and the consensus protocol comprises reaching a consensus on a blockchain transaction of the N-th round of consensus and upon the N-th round of consensus being reached, executing the blockchain transaction of the N-th round of consensus;

writing, by the blockchain node after the execution of the blockchain transaction using the second thread, a block comprising the blockchain transaction of the N-th round of consensus into the blockchain;

monitoring, by the blockchain node using the third thread, the second thread for detecting a completion of the writing of the block comprising the blockchain transaction of the N-th round of consensus in the second thread;

concurrently with the writing of the block comprising the blockchain transaction of the N-th round of consensus into the blockchain in the second thread, executing, by the blockchain node using the first thread, the consensus protocol for an (N+1)-th round of consensus in the blockchain and upon the (N+1)-th round of consensus being reached, executing, by the blockchain node using the first thread, a blockchain transaction of the (N+1)-th round of consensus in the blockchain;

in response to the third thread detecting the completion of the writing of the block comprising the blockchain transaction of the N-th round of consensus, adding a task of writing a block comprising the blockchain transaction of the (N+1)-th round of consensus into the second thread; and

after both (1) the adding of the task of writing of the block comprising the blockchain transaction of the (N+1)-th round of consensus into the blockchain into the second thread and (2) the executing of the blockchain transaction of the (N+1)-th round of consensus in the blockchain in the first thread, concurrently executing, in the second thread, the task of writing the block comprising the blockchain transaction of the (N+1)-th round of consensus into the blockchain and executing, in the first thread, the consensus protocol for an (N+2)-th round of consensus in the blockchain.

8. The system of claim 7 , wherein the operations further comprise:

creating, by the blockchain node for the first thread and the second thread, a thread lock for accessing blockchain variables shared by different blockchain transactions, and in the first thread and the second thread, a thread corresponding to a preceding consensus round requests a usage right of the thread lock before a thread corresponding to a post consensus round.

9. The system of claim 7 , wherein the operations further comprise:

if the blockchain node crashes when performing the writing of the block comprising the transaction of the N-th round of consensus, obtaining, by the blockchain node from another blockchain node after being restarted and recovered, information of a block in which the transaction of the N-th round of consensus is written; and

performing the writing of the block again for the transaction of the N-th round of consensus based on the information of the block, wherein the block is generated by the another blockchain node by completing a block write operation for the transaction of the N-th round of consensus.

10. The system of claim 9 , wherein the operations further comprise:

if the blockchain node fails to obtain, from the another blockchain node after being restarted and recovered, the information of the block in which the transaction of the N-th round of consensus is written, simulating, by the blockchain node, the N-th round of consensus based on a consensus execution log, to re-determine the transaction of the N-th round of consensus; and

performing the writing of the block again for the re-determined transaction of the N-th round of consensus.

11. A non-transitory computer-readable storage medium of a blockchain node in a blockchain, storing instructions that, when executed by one or more processors, cause the one or more processors to perform operations comprising:

creating, by the blockchain node in the blockchain, a first thread, a second thread, and a third thread;

executing, by the blockchain node in the blockchain using the first thread, a consensus protocol for an N-th round of consensus, wherein N is a positive integer, and the consensus protocol comprises reaching a consensus on a blockchain transaction of the N-th round of consensus and upon the N-th round of consensus being reached, executing the blockchain transaction of the N-th round of consensus;

writing, by the blockchain node after the execution of the blockchain transaction using the second thread, a block comprising the blockchain transaction of the N-th round of consensus into the blockchain;

monitoring, by the blockchain node using the third thread, the second thread for detecting a completion of the writing of the block comprising the blockchain transaction of the N-th round of consensus in the second thread;

concurrently with the writing of the block comprising the blockchain transaction of the N-th round of consensus into the blockchain in the second thread, executing, by the blockchain node using the first thread, the consensus protocol for an (N+1)-th round of consensus in the blockchain and upon the (N+1)-th round of consensus being reached, executing, by the blockchain node using the first thread, a blockchain transaction of the (N+1)-th round of consensus in the blockchain;

in response to the third thread detecting the completion of the writing of the block comprising the blockchain transaction of the N-th round of consensus, adding a task of writing a block comprising the blockchain transaction of the (N+1)-th round of consensus into the second thread; and

after both (1) the adding of the task of writing of the block comprising the blockchain transaction of the (N+1)-th round of consensus into the blockchain into the second thread and (2) the executing of the blockchain transaction of the (N+1)-th round of consensus in the blockchain in the first thread, concurrently executing, in the second thread, the task of writing the block comprising the blockchain transaction of the (N+1)-th round of consensus into the blockchain and executing, in the first thread, the consensus protocol for an (N+2)-th round of consensus in the blockchain.

12. The non-transitory computer-readable storage medium of claim 11 , wherein the (N+1)-th round of consensus is initiated by a target blockchain node in the blockchain when the block write operation is performed for the transaction of the N-th round of consensus, and the target blockchain node serves as a consensus master node of the blockchain.

13. The non-transitory computer-readable storage medium of claim 11 , wherein the executing the consensus protocol for the (N+1)-th round of consensus in the blockchain comprises:

reaching a consensus on a blockchain transaction of the (N+1)-th round of consensus;

upon the consensus being reached, executing the blockchain transaction of the (N+1)-th round of consensus; and

adjusting a tree structure of the blockchain by submitting a commit operation before writing a block comprising the blockchain transaction of the (N+1)-th round of consensus into the blockchain;

wherein the commit operation is submitted after the writing of the block comprising the blockchain transaction of the N-th round of consensus into the blockchain.

14. The non-transitory computer-readable storage medium of claim 11 , wherein the operations further comprise:

creating, by the blockchain node for the first thread and the second thread, a thread lock for accessing blockchain variables shared by different blockchain transactions, and in the first thread and the second thread, a thread corresponding to a preceding consensus round requests a usage right of the thread lock before a thread corresponding to a post consensus round.

Assignments (1)
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Jun 30, 2021
From: LI, KANG; DENG, FUXI
To: ALIPAY (HANGZHOU) INFORMATION TECHNOLOGY CO., LTD.
Reel/Frame 056716/0786 →
Priority Claims (1)
CN 202010629721.4 · Jul 3, 2020 · national
Continuity (1)
Related Publication 20210303403A1 · Sep 30, 2021