Specific embodiment
It should be noted that transaction (transaction) described in this specification, refers to that user passes through block chain
Client creation, and need finally to be distributed to data in the distributed data base of block chain.
That is, the transaction in block chain, there are points of the transaction of narrow sense and the transaction of broad sense.The transaction of narrow sense is
Refer to the value Transfer that user issues to block chain;For example, transaction can be use in traditional bit coin block chain network
Initiate in block chain one of family transfers accounts.And the transaction of broad sense refers to that one that user issues to block chain there is business to be intended to
Business datum;For example, operator can build alliance's chain based on actual business demand, alliance's chain deployment one is relied on
A bit it is unrelated with value Transfer it is other types of line service (for example, business of renting a house, vehicle scheduling business, settlement of insurance claim business,
Credit services, medical services etc.), and in this kind of alliance's chain, transaction, which can be one that user issues in alliance's chain, to be had
The service message or service request that business is intended to.
In the following, by taking this block chain agreement in ether mill as an example, to the prior art using the transaction executive mode serialized
Reason is described in detail.It is emphasized that in other block chain agreements in addition to ether mill, using the friendship of serialization
The reason of easy executive mode is also similar.
In ether mill, there are points of external account and contract account.External account is for storing the ether that user possesses
Coin remaining sum, external account are substantially the storage address for being stored with balance information.Contract account is for storing the intelligence that user founds
Energy contract, contract account is substantially to be stored with the storage address of intelligent contract code.
In ether mill, general there are two types of the transaction of type, i.e. external account (can be external account to other accounts
Can be contract account) money transfer transactions and external account creation contract account contract creation transaction.
The execution of money transfer transactions can generally be updated the information stored in more than one storage address.Specifically,
The execution of one money transfer transactions, it will usually change the remaining sum (i.e. the balance information stored on two account addresses) of two accounts,
Transfer amounts are deducted from the remaining sum of transfer account, increase transfer amounts into the remaining sum of receipt on account account.One money transfer transactions
Executable premise is the remaining sum of transfer account not less than transfer amounts.
Transfer account in practical application, in a certain money transfer transactions (being denoted as money transfer transactions A), it may be possible to before another
Receipt on account user in one money transfer transactions (being denoted as money transfer transactions B).If the sequence not being initiated according to transaction after arriving first by holding
Row transaction, it would be possible that there is following situation, i.e. money transfer transactions B is not carried out, and the transfer account in money transfer transactions A is caused not fill
The remaining sum of foot is transferred accounts.Exactly because in this way, all block chain application scenarios for being related to money transfer transactions, all have to using string
The transaction executive mode of rowization, to guarantee that transaction can be executed smoothly.
And the execution of contract creation transaction is actually to create a contract account, that is, founds a storage address, and will
Intelligent contract code is stored in the storage address founded.Obviously, the execution of contract creation transaction only will affect a storage address.
In addition, block chain application scenarios be it is diversified, under the block chain application scenarios having, ether mill can be based on
It is extended, develops the transaction of new type, the execution of this transaction may also only will affect a storage address.For example, sharp
With block chain carry out in store card.One is deposited the execution of card transaction, is substantially to found a storage address, will be deposited the interior of card
It stores into the storage address founded.
Based on the above, the invention proposes a kind of methods that parallelization executes the transaction of block chain, specifically for certain class one zone
Block chain application scenarios, under this kind of block chain scene, the implementing result of every transaction only will affect a storage address.
In order to make those skilled in the art more fully understand the technical solution in this specification embodiment, below in conjunction with this
Attached drawing in specification embodiment is described in detail the technical solution in this specification embodiment, it is clear that described
Embodiment is only a part of the embodiment of this specification, instead of all the embodiments.The embodiment of base in this manual,
Those of ordinary skill in the art's every other embodiment obtained, all should belong to the range of protection.
Below in conjunction with attached drawing, the technical solution that each embodiment of this specification provides is described in detail.
Fig. 1 is the flow diagram for the method that a kind of parallelization that this specification embodiment provides executes the transaction of block chain,
The following steps are included:
S100: for each node in block chain network, which obtains block to be written.
In this specification embodiment, after actually each node common recognition of the block to be written, it is packaged by accounting nodes
At block.The block to be written can be broadcast to other nodes by accounting nodes.It is well known that in block chain agreement, often
On the one hand a node needs to be implemented each transaction in block to be written, on the other hand need to be written into block and be written to block
Publicity is carried out in chain.The block to be written once be written block chain in, be equivalent to be written into each of block trade into
Publicity is gone.Whether publicity can correct for verifying corresponding transaction implementing result in the transaction on block chain, to have prevented
Node is done evil.
In the step s 100, for each node, if the node is accounting nodes, which obtains described to be written
The mode for entering block specifically can be fished for from the caching of itself it is several transaction be packaged into the block to be written;If the section
Point is not accounting nodes, then the mode that the node obtains the block to be written, which specifically can be, receives accounting nodes broadcast
The block to be written.
It is emphasized that the implementing result of the transaction is to found one for each transaction in the block to be written
A storage address is simultaneously stored in information, or update stored in a storage address information (to storage address deposit information or
Modify the information stored in a storage address).That is, the implementing result of each transaction in the block to be written,
A storage address can only be had an impact.
For example, creation contract account contract create transaction, be exactly implementing result be found a storage address and be stored in
The transaction of information.
For another example, under some block chain application scenarios, the record of the shopping to each user is needed to carry out depositing card.So,
Need to found the corresponding record storage address of each user in the database.When target user does shopping, one will be generated
Item shopping records, and any node in block chain network can deposit to demonstrate,prove and trade and broadcast based on shopping record building record.Then,
For each node, the node can (i.e. the record deposits card transaction and is packed into module to be written and is broadcast on suitable opportunity
When each node) execute the record deposit card transaction, i.e., the shopping story is recorded into the corresponding record storage address of target user.It is aobvious
So, target user carries out a plurality of shopping record caused by repeatedly shopping with being stored into the corresponding record storage of target user
Location.Therefore, above-mentioned record deposits card transaction, be exactly implementing result be the information trading that stores in one storage address of update.
S102: each transaction is read from the block to be written, and by each action organisation at N number of transaction queue.
In the prior art, each node generallys use the transaction executive mode of serialization to execute the block to be written
In each transaction.As shown in Fig. 2, the transaction executive mode of so-called serialization, refer to each node according to certain sequence on the offensive,
Each transaction in the block to be written is executed one by one.
And in this specification embodiment, each transaction in the block to be written can be split as N group, wherein N is big
In 1 natural number.Then, for each group, the transaction in this group is arranged in a transaction queue.This specification is to each
Putting in order for trading in transaction queue is not specifically limited.
S104: while it being directed to each transaction queue, by successively executing each transaction in the transaction queue after arriving first.
In step S104, actually start simultaneously at parallelization carries out transaction execution for each transaction queue.And
Specific to each transaction queue, actually serialization executes each transaction in the transaction queue.As shown in Figure 3.
So-called " simultaneously " refers to that node started to execute the transaction in each transaction queue in the same time.It is equivalent to node
N number of transaction executive process is founded in the same time, each transaction process is responsible for executing the transaction in a transaction queue.
Two kinds of transaction executive modes of comparison diagram 2 and Fig. 3, it is clear that use transaction executive mode shown in Fig. 3, Ke Yi
More transaction are executed in unit time.
S106: block chain is written into the block to be written.
In this specification embodiment, for each node, step S106 can be executed after executing step S104;
Step S106 can not also be just executed after executing step S104.
The method for executing the transaction of block chain by parallelization shown in FIG. 1, if each transaction in block to be written is all
It is not the transaction being updated to the information stored in more than one storage address, then, each node in block chain network
Each action organisation in block can be written into at least two transaction queues, then, start simultaneously at and execute each transaction team
Transaction in column.In this way, each node can execute greater number of transaction within the unit time, improves transaction and execute effect
Rate.
In addition, in this specification embodiment, the corresponding number of transaction of each transaction queue is (in i.e. each transaction queue
The quantity of transaction) it can be relatively.In this way, when carrying out transaction execution for each transaction queue while parallelization, each
The quantity of transaction performed by executive process is not in that the process having is left unused relatively, the feelings of some process overloads
Condition.This also means that node can execute transaction as much as possible within the unit time.
Specifically, the variance being calculated based on the corresponding number of transaction of each transaction queue can be set no more than specified
Threshold value.The variance being calculated based on the corresponding number of transaction of each transaction queue is smaller, the corresponding number of deals of each transaction queue
Amount is just closer.
In addition, can specifically use ether mill protocol construction block chain network in this specification embodiment.In ether mill
In, virtual machine program is installed on each node, for providing running environment for the realization of ether mill agreement.
In general, a virtual machine program is for executing a block chain process.And in this specification embodiment, due to needing
It to be directed to more than one transaction queue simultaneously, the execution more than one block chain process of parallelization, therefore, it is necessary in each node
Upper deployment more than one virtual machine program in advance.
Specifically, it is written into the action organisation in block if necessary into N number of transaction queue, then, it is necessary in advance
N number of virtual machine program is disposed on each node.
In this way, can establish between the N number of virtual machine program and N number of transaction queue disposed in advance in step S104
One-to-one relationship;Be directed to each transaction queue simultaneously, by the corresponding virtual machine program of the transaction queue, by after arriving first successively
Execute each transaction in the transaction queue.
In addition, in this specification embodiment, in general, the existing first kind transaction of transaction in block to be written, also there is the
The transaction of two classes.Wherein, first kind transaction refers to that implementing result is to update the transaction of the information stored in a storage address;The
The transaction of two classes refers to that implementing result is the transaction founded a storage address and be stored in information.
Obviously, there may be the trade fairs of the more than one first kind to storing in the same storage address in block to be written
Information is updated.And node generally requires first to access currently performed first kind friendship when executing the transaction of each first kind
Easily targeted storage address.In this case, node is when executing the transaction in block to be written, if can be to same storage
The corresponding all first kind transaction in address, which concentrate, to be executed in batches, then only needing to carry out for the same storage address primary
Access, this can be obviously improved the speed that node executes transaction.
Specifically, in step s 102, implementing result can be selected from each transaction to update in a storage address
The transaction of the information of storage is traded as the first kind, and, by other transaction conducts in each transaction in addition to first kind transaction
The transaction of second class;By in the transaction of each first kind, the identical first kind action organisation of corresponding storage address is at a sub- team of transaction
Column;With each transaction subqueue for a processing unit, also, a processing unit is considered as with the transaction of each second class;It will be each
Unit organization is handled into N number of transaction queue.
In this way, whole first kind transaction corresponding to any storage address can all be integrated one in the block to be written
A transaction subqueue, the transaction subqueue can be integrally put into some transaction queue.Node for the transaction queue into
When row transaction executes, once accessing the storage address, the corresponding whole first kind transaction of the storage address will be continuously performed.
Further, each processing unit organization can be such that at N number of transaction queue
It is descending that each processing unit is ranked up according to the corresponding number of transaction of each processing unit;Also, it is initial
Changing the corresponding number of transaction of each transaction queue is 0;According to ranking results, first processing unit is selected;By what is currently selected
Processing unit is added to the tail of the queue of minimum transaction queue, and updates the corresponding number of transaction of the minimum transaction queue;Minimum is handed over
Easy queue is the current corresponding the smallest transaction queue of number of transaction;Continue to select next processing unit, until all processing
Unit is added to transaction queue.
In this way, the corresponding number of transaction of each transaction queue can be made about the same.In this way, being based on
When the transaction that each transaction queue carries out parallelization executes, the workload on each executive process is also about the same, does not have some
The idle situation of executive process occurs, and can execute most transaction within the unit time in this way, be obviously improved the transaction of node
Execution efficiency.
Based on method shown in FIG. 1, this specification embodiment is also corresponding to provide a kind of parallelization execution block chain transaction
Device, described device be block chain network in any node, as shown in figure 4, described device includes:
Module 401 is obtained, block to be written is obtained;For each transaction in the block to be written, which is held
Row result is to found a storage address and be stored in information, or update the information stored in a storage address;
Molded tissue block 402 reads each transaction from the block to be written, and by each action organisation at N number of transaction queue;
N is greater than 1;
Execution module 403, while it being directed to each transaction queue, by successively executing each friendship in the transaction queue after arriving first
Easily;
Block chain is written in the block to be written by writing module 404.
It is not more than specified threshold based on the variance that the corresponding number of transaction of each transaction queue is calculated.
N number of virtual machine program is deployed in described device in advance;
The execution module 403 establishes a pair between the N number of virtual machine program and N number of transaction queue disposed in advance
It should be related to;It is directed to each transaction queue simultaneously, it, should by successively being executed after arriving first by the corresponding virtual machine program of the transaction queue
Each transaction in transaction queue.
The molded tissue block 402 is to update the letter stored in a storage address from implementing result is selected in each transaction
The transaction of breath is traded as the first kind, and, other transaction in each transaction in addition to first kind transaction are handed over as the second class
Easily;By in the transaction of each first kind, the identical first kind action organisation of corresponding storage address is at a transaction subqueue;With each
Transaction subqueue is a processing unit, also, is considered as a processing unit with the transaction of each second class;By each processing unit group
It is made into N number of transaction queue.
The molded tissue block 402, according to the corresponding number of transaction of each processing unit, it is descending to each processing unit into
Row sequence;Also, initializing the corresponding number of transaction of each transaction queue is 0;According to ranking results, select first processing single
Position;The processing unit currently selected is added to the tail of the queue of minimum transaction queue, and it is corresponding to update the minimum transaction queue
Number of transaction, the minimum transaction queue are the current corresponding the smallest transaction queues of number of transaction;Continue to select next place
Unit is managed, until all processing units are added to transaction queue.
Based on method shown in FIG. 1, this specification embodiment is also corresponding to provide a kind of parallelization execution block chain transaction
System, as shown in figure 5, including the block chain network being made of multiple nodes;
Any node in the block chain network, obtains block to be written;Each friendship is read from the block to be written
Easily, and by each action organisation at N number of transaction queue;N is greater than 1;It is directed to each transaction queue simultaneously, it should by successively being executed after arriving first
Each transaction in transaction queue;Block chain is written into the block to be written;
Wherein, for each transaction in the block to be written, the implementing result of the transaction is to found a storage ground
Location is simultaneously stored in information, or updates the information stored in a storage address.
This specification embodiment also provides a kind of computer equipment, includes at least memory, processor and is stored in
On reservoir and the computer program that can run on a processor, wherein processor realizes method shown in Fig. 1 when executing described program
Function.
Fig. 6 shows one kind provided by this specification embodiment and more specifically calculates device hardware structural schematic diagram,
The equipment may include: processor 1010, memory 1020, input/output interface 1030, communication interface 1040 and bus
1050.Wherein processor 1010, memory 1020, input/output interface 1030 and communication interface 1040 are real by bus 1050
The now communication connection inside equipment each other.
Processor 1010 can use general CPU (Central Processing Unit, central processing unit), micro- place
Reason device, application specific integrated circuit (Application Specific Integrated Circuit, ASIC) or one
Or the modes such as multiple integrated circuits are realized, for executing relative program, to realize technical side provided by this specification embodiment
Case.
Memory 1020 can use ROM (Read Only Memory, read-only memory), RAM (Random Access
Memory, random access memory), static storage device, the forms such as dynamic memory realize.Memory 1020 can store
Operating system and other applications are realizing technical solution provided by this specification embodiment by software or firmware
When, relevant program code is stored in memory 1020, and execution is called by processor 1010.
Input/output interface 1030 is for connecting input/output module, to realize information input and output.Input and output/
Module can be used as component Configuration (not shown) in a device, can also be external in equipment to provide corresponding function.Wherein
Input equipment may include keyboard, mouse, touch screen, microphone, various kinds of sensors etc., output equipment may include display,
Loudspeaker, vibrator, indicator light etc..
Communication interface 1040 is used for connection communication module (not shown), to realize the communication of this equipment and other equipment
Interaction.Wherein communication module can be realized by wired mode (such as USB, cable etc.) and be communicated, can also be wirelessly
(such as mobile network, WIFI, bluetooth etc.) realizes communication.
Bus 1050 include an access, equipment various components (such as processor 1010, memory 1020, input/it is defeated
Outgoing interface 1030 and communication interface 1040) between transmit information.
It should be noted that although above equipment illustrates only processor 1010, memory 1020, input/output interface
1030, communication interface 1040 and bus 1050, but in the specific implementation process, which can also include realizing normal fortune
Other assemblies necessary to row.In addition, it will be appreciated by those skilled in the art that, it can also be only comprising real in above equipment
Component necessary to existing this specification example scheme, without including all components shown in figure.
This specification embodiment also provides a kind of computer readable storage medium, is stored thereon with computer program, the journey
The function of method shown in Fig. 1 is realized when sequence is executed by processor.
Computer-readable medium includes permanent and non-permanent, removable and non-removable media can be by any method
Or technology come realize information store.Information can be computer readable instructions, data structure, the module of program or other data.
The example of the storage medium of computer includes, but are not limited to phase change memory (PRAM), static random access memory (SRAM), moves
State random access memory (DRAM), other kinds of random access memory (RAM), read-only memory (ROM), electric erasable
Programmable read only memory (EEPROM), flash memory or other memory techniques, read-only disc read only memory (CD-ROM) (CD-ROM),
Digital versatile disc (DVD) or other optical storage, magnetic cassettes, tape magnetic disk storage or other magnetic storage devices
Or any other non-transmission medium, can be used for storage can be accessed by a computing device information.As defined in this article, it calculates
Machine readable medium does not include temporary computer readable media (transitorymedia), such as the data-signal and carrier wave of modulation.
As seen through the above description of the embodiments, those skilled in the art can be understood that this specification
Embodiment can be realized by means of software and necessary general hardware platform.Based on this understanding, this specification is implemented
Substantially the part that contributes to existing technology can be embodied in the form of software products the technical solution of example in other words,
The computer software product can store in storage medium, such as ROM/RAM, magnetic disk, CD, including some instructions are to make
It is each to obtain computer equipment (can be personal computer, server or the network equipment etc.) execution this specification embodiment
Method described in certain parts of a embodiment or embodiment.
System, method, module or the unit that above-described embodiment illustrates can specifically realize by computer chip or entity,
Or it is realized by the product with certain function.A kind of typically to realize that equipment is computer, the concrete form of computer can
To be personal computer, laptop computer, cellular phone, camera phone, smart phone, personal digital assistant, media play
In device, navigation equipment, E-mail receiver/send equipment, game console, tablet computer, wearable device or these equipment
The combination of any several equipment.
All the embodiments in this specification are described in a progressive manner, same and similar portion between each embodiment
Dividing may refer to each other, and each embodiment focuses on the differences from other embodiments.Especially for device and
For apparatus embodiments, since it is substantially similar to the method embodiment, so describing fairly simple, related place is referring to method
The part of embodiment illustrates.Embodiment of the method described above is only schematical, wherein described be used as separation unit
The module that part illustrates may or may not be physically separated, can be when implementing this specification example scheme
The function of each module is realized in the same or multiple software and or hardware.It can also select according to the actual needs therein
Some or all of the modules achieves the purpose of the solution of this embodiment.Those of ordinary skill in the art are not making the creative labor
In the case where, it can it understands and implements.
The above is only the specific embodiment of this specification embodiment, it is noted that for the general of the art
For logical technical staff, under the premise of not departing from this specification embodiment principle, several improvements and modifications can also be made, this
A little improvements and modifications also should be regarded as the protection scope of this specification embodiment.