The present application is a divisional application of patent applications having an application number of "202110146211.6", an application date of "2021, 02/03", and an invention name of "transaction processing method, apparatus, and electronic device in block chain".
Detailed Description
In order to make the purpose, technical solutions and advantages of this document more clear, the technical solutions of this specification will be clearly and completely described below with reference to specific embodiments of this specification and the accompanying drawings. It is to be understood that the embodiments described are only a few embodiments of this document, and not all embodiments. All other embodiments obtained by a person skilled in the art without making any inventive step based on the embodiments in this description belong to the protection scope of this document.
The technical solutions provided by the embodiments of the present description are described in detail below with reference to the accompanying drawings.
One or more embodiments of the present specification provide a method for processing a transaction in a blockchain, where an implementation flow diagram is shown in fig. 3, and the method includes:
in step 310, the block node performs a transaction execution operation corresponding to the nth block.
The transaction corresponding to the nth block may be a transaction that has agreed in the blockchain system. Further, in step 310, the block link point may execute the transaction corresponding to the nth block that has been agreed upon.
The transaction execution operation may be processed by a transaction execution thread in a blockchain node. The above consensus operation may be handled by a consensus thread in a blockchain node.
As described in the background, the transaction processing in a blockchain typically includes four distinct operations, collecting transactions, transaction consensus, transaction execution, and writing blocks. As mentioned above, each consensus node may perform all the operations of the four phases, or some consensus nodes may perform the operations of the last three phases without performing the operation of collecting transactions. Thus, for a consensus node performing a collect transaction, this operation may also be performed by a separate thread in the consensus node, e.g., referred to as a transaction collect thread. Specifically, as shown in fig. 4, before the execution of the transaction execution operation corresponding to the nth block begins, the consensus node may query, through the transaction collection thread, whether the transactions collected in the transaction memory pool have satisfied the preset transaction collection condition. And if the preset transaction collection condition is met, the consensus node packs the transactions collected by the transaction memory pool through a transaction collection thread. In this way, the consensus node can get a proposal to be consensus. Further, the consensus node may perform the operation of the consensus phase through a consensus thread.
Specifically, when the consensus node is a consensus master node in the blockchain system adopting the master consensus algorithm, or the consensus node is a consensus node in the blockchain system adopting the masterless consensus algorithm, the consensus thread may obtain the transaction corresponding to the nth block from the collected transaction thread. Further, a consensus proposal may be initiated based on the transaction to perform a consensus phase operation, e.g., a consensus thread in a blockchain node may perform the consensus operation.
In addition, when the consensus node is a consensus non-master node in the blockchain system adopting the master consensus algorithm, the blockchain node responds to consensus proposals of transactions corresponding to the Nth block sent by other consensus nodes, and performs consensus operation based on the consensus proposals. The consensus operation may be performed, for example, by a consensus thread in a blockchain node. In this case, since the consensus node is in response to the sent consensus offer, and the sent consensus offer may include the transaction to be agreed upon, the consensus node may not perform the operation of collecting the transaction.
Since the consensus thread needs to acquire the transaction corresponding to the nth block from the collection transaction thread, the sequence of collection transaction → consensus can still be maintained for the processing flow of the transaction corresponding to the same block.
After the block link point completes the consensus operation on the transaction corresponding to the nth block, the transaction execution operation corresponding to the nth block in step 310 may be performed. The transaction execution operation may be performed, for example, by a transaction execution thread in a blockchain node.
Similarly, after the consensus operation of the nth block-corresponding transaction is completed, the consensus result is transmitted to the transaction execution thread of the block-linked node, so that the sequence of consensus → transaction execution can still be maintained for the processing flow of the same block-corresponding transaction.
In step 320, during the process of executing the transaction execution operation corresponding to the nth block, the block nodes execute the consensus operation corresponding to the (N +1) th block in parallel.
Similarly, before the consensus operation is performed on the transaction corresponding to the (N +1) th block, the consensus node may query, through the transaction collection thread, whether the transaction collected in the transaction memory pool has satisfied the preset transaction collection condition. And if the preset transaction collection condition is met, the consensus node packs the transactions collected by the transaction memory pool through a transaction collection thread, so that the transaction corresponding to the (N +1) th block is formed. In this way, the node can get a proposal to be agreed upon. Further, the consensus node may perform the operation of the consensus phase through the consensus thread, i.e., perform the consensus operation on the (N +1) th block corresponding transaction in step 320.
Specifically, when the consensus node is a consensus master node in the blockchain system adopting the master consensus algorithm, or the consensus node is a consensus node in the blockchain system adopting the masterless consensus algorithm, the consensus thread may obtain the transaction corresponding to the (N +1) th block from the collected transaction thread. Further, a consensus proposal may be initiated based on the transaction to enter into a consensus phase, e.g., a consensus thread in a blockchain node may perform the consensus operation.
When the consensus node is a consensus non-master node in the blockchain system using the master consensus algorithm, the blockchain node responds to consensus suggestions for the transaction corresponding to the (N +1) th block from other consensus nodes, and performs consensus operations based on the consensus suggestions, for example, the consensus operations may be performed by a consensus thread in the blockchain node. In this case, since the consensus node is in response to the sent consensus offer, and the sent consensus offer may include the transaction to be agreed upon, the consensus node may not perform the operation of collecting the transaction.
Since the consensus thread needs to acquire the transaction corresponding to the (N +1) th block from the collection transaction thread, the sequence of collection transaction → consensus can still be maintained for the processing flow of the transaction corresponding to the same block.
If the blockchain node performs the process of collecting the transaction corresponding to the nth block and performs the process of collecting the transaction corresponding to the (N +1) th block, the blockchain node collects the transaction corresponding to the (N +1) th block and then collects the transaction corresponding to the (N +1) th block. This is particularly true where only one gather transaction thread is assigned to a blockchain node. And, the blockchain node performs an operation of collecting the (N +1) th blockchain transaction in parallel in the process of consensus on the nth proposal.
The consensus operation of the block link point on the transaction corresponding to the (N +1) th block may be performed after the consensus on the transaction corresponding to the nth block is achieved. This is particularly true where only one consensus thread is assigned to a blockchain node.
It should be noted that the consensus proposal for the nth block and the consensus proposal for the (N +1) th block may be initiated by the same consensus node or by different consensus nodes. For example, the consensus operation for the block-linked point for the nth block may be initiated by the block-linked point as the consensus master, while the consensus operation for the (N +1) th block may be initiated by another block-linked point as the consensus master, or vice versa.
After the block link point completes the consensus operation on the transaction corresponding to the (N +1) th block, the transaction corresponding to the (N +1) th block may be executed. The transaction execution operation may be performed, for example, by a transaction execution thread in a blockchain node.
Similarly, after the consensus operation of the (N +1) th block-corresponding transaction is performed by the consensus thread, the consensus result is transmitted to the transaction execution thread of the block link point, so that the sequence of consensus → transaction execution can still be maintained for the processing flow of the same block-corresponding transaction.
As shown in fig. 4, after the block link point completes the operation of executing the transaction corresponding to the nth block, the block link point may also write the result of executing the transaction into the nth block of the block chain book, i.e., a block writing operation. Similarly, during the block link point executing the block writing operation corresponding to the nth block, the transaction executing operation corresponding to the (N +1) th block is executed in parallel.
The block link point may perform the operation on the transaction corresponding to the (N +1) th block after performing the operation on the transaction corresponding to the nth block. This is particularly true where only one transaction execution thread is assigned to a blockchain node.
As shown in fig. 4, after the block link point completes the operation of executing the transaction corresponding to the (N +1) th block, the block link point may also write the result of executing the transaction into the (N +1) th block of the block chain ledger. Similarly, the block link point may perform a write block operation on the N +1 th block after the write block operation on the nth block. This is particularly true where the blockchain node has only one write block thread assigned.
When the block chain node completes the collection transaction operation corresponding to the (N +1) th block, the consensus operation for the nth block may not be completed yet, and thus the consensus operation for the (N +1) th block cannot be started yet. At this time, the block link point may store the collected transaction corresponding to the (N +1) th block in the memory, extract the transaction corresponding to the (N +1) th block from the memory after the corresponding consensus operation of the nth block is completed, and start the consensus operation on the transaction corresponding to the (N +1) th block.
Similarly, when the block node completes the consensus operation corresponding to the (N +1) th block, the transaction execution operation of the nth block may not be completed, and thus the transaction execution operation of the (N +1) th block may not be started. At this time, the block link point may store the consensus result corresponding to the (N +1) th block in the memory, and after the transaction execution operation corresponding to the nth block is completed, extract the consensus result corresponding to the (N +1) th block from the memory, and start to execute the transaction execution operation corresponding to the (N +1) th block.
Similarly, when the transaction execution operation corresponding to the (N +1) th block is completed, the block writing operation for the nth block may not be completed, and thus the block writing operation for the (N +1) th block may not be started. At this time, the block chain node may store the transaction execution result corresponding to the (N +1) th block in the memory, and after the block writing operation corresponding to the nth block is completed, extract the transaction execution result corresponding to the (N +1) th block from the memory, and start to execute the block writing operation corresponding to the (N +1) th block.
By adopting the transaction processing method provided by the embodiment of the specification, when the transaction in the blockchain is processed, the blockchain link points can process different stages of the corresponding transaction of different blocks in parallel, the computing power of the multi-core CPU is utilized, the operation efficiency of the blockchain system is greatly improved, and the performance is improved.
Fig. 5 is a schematic structural diagram of an electronic device provided in an embodiment of the present specification. Referring to fig. 5, at a hardware level, the electronic device includes a processor, and optionally further includes an internal bus, a network interface, and a memory. The Memory may include a Memory, such as a Random-Access Memory (RAM), and may further include a non-volatile Memory, such as at least 1 disk Memory. Of course, the electronic device may also include hardware required for other services.
The processor, the network interface, and the memory may be connected to each other via an internal bus, which may be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus, an EISA (Extended Industry Standard Architecture) bus, or the like. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one double-headed arrow is shown in FIG. 5, but this does not indicate only one bus or one type of bus.
And the memory is used for storing programs. In particular, the program may include program code comprising computer operating instructions. The memory may include both memory and non-volatile storage and provides instructions and data to the processor.
The processor reads the corresponding computer program from the nonvolatile memory into the memory and then runs the computer program to form the transaction processing device on a logic level. The processor is used for executing the program stored in the memory and is specifically used for executing the following operations:
executing a transaction execution operation corresponding to an Nth block, wherein the transaction corresponding to the Nth block has reached a consensus in a blockchain system;
and in the process of executing the transaction execution operation corresponding to the Nth block, executing the consensus operation of the transaction corresponding to the (N +1) th block in parallel, wherein N is a positive integer.
Based on the electronic device shown in fig. 5, it can be known that, in the scheme of the embodiment of the present specification, when a transaction in a block chain is processed, block chain link points may process different stages of the transaction corresponding to different blocks in parallel, and the computing power of a multi-core CPU is utilized, so that the operating efficiency of the block chain system is greatly improved, and the performance is improved.
The transaction processing method in the blockchain disclosed in the embodiments of fig. 3 to 4 of the present specification can be applied to or implemented by a processor. The processor may be an integrated circuit chip having signal processing capabilities. In implementation, the steps of the above method may be performed by integrated logic circuits of hardware in a processor or instructions in the form of software. The Processor may be a general-purpose Processor, including a Central Processing Unit (CPU), a Network Processor (NP), and the like; but also Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field Programmable Gate Arrays (FPGAs) or other Programmable logic devices, discrete Gate or transistor logic devices, discrete hardware components. The various methods, steps and logic blocks disclosed in one or more embodiments of the present specification may be implemented or performed. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. The steps of a method disclosed in connection with one or more embodiments of the present disclosure may be embodied directly in hardware, in a software module executed by a hardware decoding processor, or in a combination of the hardware and software modules executed by a hardware decoding processor. The software module may be located in ram, flash memory, rom, prom, or eprom, registers, etc. storage media as is well known in the art. The storage medium is located in a memory, and a processor reads information in the memory and completes the steps of the method in combination with hardware of the processor.
The electronic device may further execute the transaction processing method in the block chain of fig. 3 to 4, which is not described herein again.
Of course, besides the software implementation, the electronic device in this specification does not exclude other implementations, such as logic devices or a combination of software and hardware, and the like, that is, the execution subject of the following processing flow is not limited to each logic unit, and may also be hardware or logic devices.
Embodiments of the present specification also provide a computer-readable storage medium storing one or more programs, the one or more programs including instructions, which when executed by a portable electronic device including a plurality of application programs, enable the portable electronic device to perform the method of the embodiments shown in fig. 3-4, and are specifically configured to:
executing a transaction execution operation corresponding to an Nth block, wherein the transaction corresponding to the Nth block has reached a consensus in a blockchain system;
and in the process of executing the transaction execution operation corresponding to the Nth block, executing the consensus operation of the transaction corresponding to the (N +1) th block in parallel, wherein N is a positive integer.
Fig. 6 is a schematic structural diagram of a transaction processing device 600 provided in an embodiment of the present specification. In a particular application, the transaction processing device 600 may be a blockchain node, or the transaction processing device may be deployed on a blockchain node. Referring to fig. 6, in one embodiment, the transaction processing device 600 includes:
a transaction executing module 603 configured to execute a transaction executing operation corresponding to an nth block, wherein the transaction corresponding to the nth block has been agreed in the blockchain system;
the consensus module 602, during the transaction execution module executing the transaction execution operation corresponding to the nth block, concurrently executes the consensus operation corresponding to the (N +1) th block.
Optionally, before the transaction executing module 603 executes the transaction executing operation of the nth block, the consensus module 602 performs consensus on the transaction corresponding to the nth block in the blockchain system.
Optionally, the transaction processing apparatus 600 further includes a transaction collection module 601, and before the consensus module 602 performs consensus on the transaction corresponding to the nth block in the blockchain system, the transaction collection module 601 collects the transaction corresponding to the nth block.
Optionally, the transaction processing apparatus 600 further includes a block writing module 604, and after the transaction executing module 603 completes the transaction executing operation corresponding to the nth block, the block writing module 604 writes the result of the transaction executing operation into the nth block of the block chain ledger.
Optionally, the consensus module 602 performs a consensus operation on the transaction corresponding to the (N +1) th block after agreeing on the transaction corresponding to the nth block.
Optionally, in the process that the consensus module 602 performs consensus on the transaction corresponding to the nth block, the transaction collection module 601 performs an operation of collecting transactions corresponding to the (N +1) th block in parallel.
Optionally, the transaction collection module 601 performs an operation of collecting transactions corresponding to the (N +1) th block after collecting transactions corresponding to the nth block.
Optionally, during the process that the write block module 604 performs the write block operation corresponding to the nth block, the transaction execution module 603 performs the transaction execution operation corresponding to the (N +1) th block in parallel.
Optionally, the transaction executing module 603 executes the transaction executing operation corresponding to the (N +1) th block after executing the transaction executing operation corresponding to the nth block.
Optionally, after the transaction executing module 603 completes the transaction executing operation corresponding to the (N +1) th block, the writing block module 604 writes the result of the transaction executing operation into the (N +1) th block of the block chain ledger.
Optionally, the write block module 604 performs a write block operation corresponding to the N +1 th block after performing the write block operation corresponding to the nth block.
Optionally, if the transaction collection module 601 finishes the operation of collecting the transaction corresponding to the nth +1 block, and the process of the consensus module 602 for the consensus corresponding to the nth block is not finished yet, the transaction collection module further stores the collected transaction corresponding to the nth +1 block in the memory.
Optionally, if the transaction execution module 603 has not finished executing the transaction corresponding to the nth block after the consensus operation corresponding to the (N +1) th block is finished by the consensus module 602, the consensus module further stores the consensus result of the (N +1) th block in the memory.
Optionally, if the transaction executing module 603 finishes executing the transaction executing operation corresponding to the (N +1) th block, the block writing module 604 does not finish the block writing process corresponding to the nth block, and the transaction executing module further stores the transaction executing result corresponding to the (N +1) th block in the memory.
Based on the transaction processing device 600 shown in fig. 6, it can be known that, in the scheme of the embodiment of the present specification, when a transaction in a blockchain is processed, the blockchain link points where the transaction processing device 600 is deployed can process different stages of the transaction corresponding to different blocks in parallel by using the computing power of the multi-core CPU, so that the operation efficiency of the blockchain system is greatly improved, and the performance is improved.
In short, the above description is only a preferred embodiment of the present disclosure, and is not intended to limit the scope of the present disclosure. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of one or more embodiments of the present disclosure should be included in the scope of protection of one or more embodiments of the present disclosure.
The systems, devices, modules or units illustrated in the above embodiments may be implemented by a computer chip or an entity, or by a product with certain functions. One typical implementation device is a computer. In particular, the computer may be, for example, a personal computer, a laptop computer, a cellular telephone, a camera phone, a smartphone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer readable medium does not include a transitory computer readable medium such as a modulated data signal and a carrier wave.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the system embodiment, since it is substantially similar to the method embodiment, the description is simple, and for the relevant points, reference may be made to the partial description of the method embodiment.