Summary of the invention
In order to solve problems in the prior art, the embodiment of the invention provides a kind of method of commerce based on directed acyclic graph
And system, to overcome the transaction of the structure based on DAG in the prior art that a unordered state is presented, so as to cause consistency
The problems such as uncontrollable.
To solve said one or multiple technical problems, the technical solution adopted by the present invention is that:
On the one hand, a kind of method of commerce based on directed acyclic graph is provided, described method includes following steps:
S1: each node to participate in business sequentially is numbered, and sets up common recognition node in each node, and set common recognition
Time interval, common recognition number of transaction;
S2: each node participated in business be respectively transaction apply transaction number, the transaction number sequentially increase and
It is globally unique;
S3: according to selected first transaction of the time interval or the common recognition number of transaction, it will create that family friend is easy or previous pass
The end transaction in key path is to the path of first transaction as candidate critical path;
S4: the common recognition node confirms the critical path of the candidate, if the wound family friend is easy or previous key
The end transaction in path is identified to the All Activity between the second transaction, then chooses that the wound family friend is easy or previous critical path
The path of the end transaction of diameter to second transaction is this critical path;
S5: it determines the growing direction that this described critical path is main chain and broadcasts to each node participated in business and write
Enter the account book of consistency;
S6: time interval or common recognition number of transaction based on the common recognition repeat step S2 to S5.
Further, the step S2 includes:
Each node presses the number of transaction of the respective number size client of pre- first to file oneself in turn;
When the remaining quantity of the number of transaction of node application is lower than preset threshold, then next round application is initiated;
Each node is compared transaction content when transaction is submitted, and trades within the set time by content is identical
It filters, does not distribute transaction number;
The easy number of family friend will be created and be set as 0, the number of other transaction sequentially increases.
Further, the step S3 is specifically included:
S3.1: after the time interval or the common recognition number of transaction reach, selected number is n or common recognition number of transaction
Transaction be the first transaction, wherein n is the quantity traded in system;
S3.2: the common recognition node to it is described first transaction carry out common recognition ballot, if voting through, will wound family friend easily or
The end transaction of previous critical path is to the path of first transaction as candidate critical path.
Further, second transaction is any one transaction in the critical path of the candidate.
Further, the step S4 is specifically included:
S4.1: the common recognition node confirms the critical path of the candidate, if the critical path of the candidate
On transaction be not identified, then follow the steps S4.2 or step S4.3;
S4.2: the common recognition node carries out common recognition ballot to the transaction of all not confirmeds, described if voting through
The transaction of not confirmed is identified through, if ballot does not pass through, is carried out to the previous transaction of the transaction of the not confirmed
Common recognition ballot, circulate operation in critical path until finding the second transaction, from wound family friend is easy or the end of previous critical path
It trades to the All Activity between second transaction and is all identified;
S4.3: the common recognition node is checked from wound family friend in the critical path of the candidate easily to the transaction of not confirmed
Previous transaction, circulate operation until finding the second transaction in the critical path in the candidate, from wound family friend it is easy or previous
The end transaction of critical path is all identified to the All Activity between second transaction;
S4.4: choose that the wound family friend is easy or the path of end transaction to second transaction of previous critical path is this
Secondary critical path.
On the other hand, a kind of transaction system based on directed acyclic graph is provided, the system comprises:
Setup module, user are that each node participated in business sequentially is numbered, and common recognition node is set up in each node, and
Set time interval, the common recognition number of transaction of common recognition;
Number module is that respectively transaction number, the transaction number are applied in transaction for each node participated in business
Sequentially increase and globally unique;
First chooses module, for will create according to selected first transaction of the time interval or the common recognition number of transaction
Family friend is easy or critical path of the end transaction of previous critical path to the path of first transaction as candidate;
Second chooses module, confirms for the common recognition node to the critical path of the candidate, if the wound generation
The transaction of the end of transaction or previous critical path is identified to the All Activity between the second transaction, then chooses the wound family friend
The path of the end transaction of easy or previous critical path to second transaction is this critical path;
Broadcast module, for determining that growing direction and broadcast that this described critical path is main chain are participated in business to described
Each node write-in consistency account book.
Further, the number module includes:
Quantity application unit presses the friendship of the respective number size client of pre- first to file oneself in turn for each node
Easy quantity;
Whether judging unit, the remaining quantity of number of transaction for predicate node application are lower than preset threshold;
Filter element, each node is compared transaction content when submitting for trading, within the set time will be interior
Hold identical transaction to filter out, does not distribute transaction number;Numbered cell is set as 0 for will create the easy number of family friend, other friendships
Easy number sequentially increases.
Further, the first selection module includes:
Trade selection unit, for after the time interval or the common recognition number of transaction reach, it is selected number be n or
The transaction of common recognition number of transaction is the first transaction, and wherein n is the quantity traded in system;
Path candidate selection unit carries out common recognition ballot to first transaction for the common recognition node, if ballot is logical
Cross, then will create that family friend is easy or the end transaction of previous critical path to the path of first transaction as the critical path of candidate
Diameter.
Further, second transaction is any one transaction in the critical path of the candidate.
Further, the second selection module includes:
Confirmation unit confirms the critical path of the candidate for the common recognition node;
Common recognition unit, carries out common recognition ballot to the transaction of all not confirmeds for the common recognition node, if voting through
Then being identified through the transaction of the not confirmed, if ballot does not pass through, to the previous of the transaction of the not confirmed
Transaction carries out common recognition ballot, and circulate operation in critical path until finding the second transaction, from wound family friend is easy or previous critical path
The end transaction of diameter is all identified to the All Activity between second transaction;
Query unit is checked in the critical path of the candidate from wound family friend for the common recognition node easily to not true
The previous transaction for the transaction recognized, circulate operation is until finding the second transaction in the critical path in the candidate, from wound family friend
The end transaction of easy or previous critical path is all identified to the All Activity between second transaction;
Critical path selection unit, for choosing that the wound family friend is easy or the end transaction of previous critical path is to described the
The path of two transaction is this critical path.
Technical solution provided in an embodiment of the present invention has the benefit that
Method of commerce and system provided in an embodiment of the present invention based on directed acyclic graph carries out preliminery application to transaction and presses
Sequence distribution number, avoids transaction conflict, and devise the main chain generation method of directed acyclic graph, transaction has been determined by main chain
The consistency of account book among the nodes and successive succession of trading.
Specific embodiment
To make the object, technical solutions and advantages of the present invention clearer, below in conjunction with attached in the embodiment of the present invention
Figure, technical scheme in the embodiment of the invention is clearly and completely described, it is clear that described embodiment is only this
Invention a part of the embodiment, instead of all the embodiments.Based on the embodiments of the present invention, those of ordinary skill in the art exist
Every other embodiment obtained under the premise of creative work is not made, shall fall within the protection scope of the present invention.
Fig. 1 is the flow chart of the method for commerce shown according to an exemplary embodiment based on directed acyclic graph, referring to Fig.1
Shown, this method comprises the following steps:
S1: each node to participate in business sequentially is numbered, and sets up common recognition node in each node, and set common recognition
Time interval, common recognition number of transaction.
Specifically, sequentially numbered for each node for participating in business, in each node (including each block chain node participated in business
Or each system node) in set up common recognition node or witness's node, these common recognition nodes or witness's node can scheme DAG
Critical path, transaction on (directed acyclic graph) carry out common recognition confirmation.Referring to shown in 2, Fig. 2 is according to an exemplary embodiment
The schematic diagram of the directed acyclic graph shown.The time interval and common recognition number of deals known together for each node sets participated in business
Amount, each node of system can carry out time synchronization by Network Time Protocol (NTP).For example, node serial number can be
1,2 ... N, the time interval of common recognition are denoted as T, and common recognition number of transaction is denoted as TxNum.What needs to be explained here is that the present invention is implemented
In example, common recognition node is preferentially numbered, i.e., the number for node of knowing together preferentially is set as 1,2,3 ... etc., and known together and node or see
The quantity of card person's node is at least 4.
S2: each node participated in business be respectively transaction apply transaction number, the transaction number sequentially increase and
It is globally unique.
Specifically, user submits transaction by the client of each node, transaction number sequentially increases.In the embodiment of the present invention
In, it need to guarantee that the transaction number of All Activity is globally unique.
S3: according to selected first transaction of the time interval or the common recognition number of transaction, family friend will be created easily or arrived previous
The end transaction of critical path is to the path of first transaction as candidate critical path.
Specifically, selecting transaction (i.e. the when the time interval or common recognition number of transaction of common recognition reach the value of setting
One transaction), will create that family friend is easy or the end transaction of previous critical path to the path of the transaction (the i.e. first transaction) as candidate
Critical path.For example, it is assumed that wound generation transaction number is 0, first time critical path is that (40 be the transaction after confirmation from 0 to 40
Number, i.e., the number of the first transaction), second critical path number is then from 40 to N, i.e. second of critical path is from 40
Start, rather than since wound family friend is easily.
S4: the common recognition node confirms the critical path of the candidate, if the wound family friend is easy or previous key
The end transaction in path is identified to the All Activity between the second transaction, then chooses that the wound family friend is easy or previous critical path
The path of the end transaction of diameter to second transaction is this critical path.
Specifically, critical path refer to from wound family friend is easy or the end transaction of previous critical path to specified number friendship
With the path of maximum length between easily, the transaction in critical path is called crucial transaction.What needs to be explained here is that here
Confirmation refer to by 2 or 2 or more other trade confirmations.Based in directed acyclic graph (DAG) tactic pattern, generally by 2
The transaction that other trade confirmations are crossed can be by one of the candidate as the crucial transaction in critical path.Trade confirmation is traded
The common practice of DAG model, the process of confirmation are to approve that the content of cryptographic Hash and transaction including transaction is simultaneously to last time transaction
And its transaction confirmed can be linked.If a point is regarded in each transaction as, it is equivalent to by a certain transaction confirmation
An access is taken between two o'clock, such confirmation relationship is unidirectional.Such as transaction A confirmation transaction B:A.Confirm (transaction
B Hash, trade the source B account, trade B mesh account, transaction amount, other parameters) judge transaction it is whether reasonable.
S5: it determines the growing direction that this described critical path is main chain and broadcasts to each node participated in business and write
Enter the account book of consistency.
Specifically, selected critical path to be used as to the growing direction of main chain, and broadcast to it is described participate in business own
The account book of consistency is written in the information by node, all nodes.What needs to be explained here is that in embodiments of the present invention, new
Transaction can only confirm the transaction on existing main chain.
S6: time interval or common recognition number of transaction based on the common recognition repeat step S2 to S5.
Specifically, repeating the above steps S2 extremely when the time interval or common recognition number of transaction of common recognition reach the value of setting
S5 determines new critical path.What needs to be explained here is that subsequent critical path with the transaction of last Trail termination (i.e.
Trade the end of previous critical path) main chain is increased as starting transaction.
As a kind of preferably embodiment, in the embodiment of the present invention, the step S2 includes:
Each node presses the number of transaction of the respective number size client of pre- first to file oneself in turn;
When the remaining quantity of the number of transaction of node application is lower than preset threshold, then next round application is initiated;
Each node is compared transaction content when transaction is submitted, and trades within the set time by content is identical
It filters, does not distribute transaction number;
The easy number of family friend will be created and be set as 0, the number of other transaction sequentially increases.
Specifically, in the embodiment of the present invention, each node can preparatory Shen to guarantee that the transaction number of All Activity is globally unique
Please oneself client number of transaction, each node applied for that record is as follows: (system works as prosthomere by respective number size in turn
Maximum transaction number value, application round, node serial number, the Base Serial Number of this transaction application, this transaction Shen before point application
Finish number please).For example, (21,2,1,22,40), wherein 21 represent the maximum transaction number before system present node application
Be 21,2 represent present application round as second wheel, 1 be present node number, 22 and 40 respectively represent this transaction application rise
Begin number and finish number;(50,2,3,51,100), 50 to represent the maximum transaction number before system present node application be 50,
Transaction number value after representing the application of node 1 and node 2 is 50.
What needs to be explained here is that in embodiments of the present invention, the remaining number of number of transaction of node application can be set
When amount is lower than 40% (this value can be configured according to the demand of user), next round application is initiated.Transaction each section when submitting
Point is compared transaction content, and the identical transaction of (such as 20 seconds or 1 minute) content within the set time can be filtered,
Do not distribute transaction number.
In addition in embodiments of the present invention, it will preferably create the easy number of family friend and be set as 0, the number of other transaction is sequentially
Increase.But it is noted that the number of all transaction is globally unique, and within the set time, the identical trade fair of content
It is filtered, does not redistribute transaction number.
As a kind of preferably embodiment, in the embodiment of the present invention, the step S3 is specifically included:
S3.1: after the time interval or the common recognition number of transaction reach, selected number is n or common recognition number of transaction
Transaction be the first transaction, wherein n is the quantity traded in system.
Specifically, selecting number after the time interval or common recognition number of transaction of common recognition reach the value of setting and being equal to currently
The transaction for the quantity traded in system or common recognition number of transaction are the first transaction.For example, the time interval in common recognition reaches setting
Value after, and the quantity traded in current system be n, then choose number be n transaction as first transaction, alternatively, knowing together
After number of transaction reaches the value of setting, then chooses the transaction that number is common recognition number of transaction and trade as first.
What needs to be explained here is that selecting the first transaction in the manner described above, critical path can be maximized.Such as system
Number of transaction is 10000, because ensuring that transaction is sequentially to number in the step of before.So from a certain transaction A to 10000,
From A to 900, if A to 10000 is critical path, 900 to 10000 transaction is not had to consider further that.Model is reduced from big to small
It encloses confirmation critical path and reduces the time for determining key, improve efficiency.
S3.2: the common recognition node to it is described first transaction carry out common recognition ballot, if voting through, will wound family friend easily or
The end transaction of previous critical path is to the path of first transaction as candidate critical path.
Specifically, common recognition node carries out common recognition ballot to first transaction after the first transaction is selected, if voting through,
To then create that family friend is easy or the end transaction of previous critical path to the path of first transaction as the critical path of candidate.This
In it should be noted that in embodiments of the present invention, common recognition ballot follows BFT (Tendermint) or PBFT algorithm (N=3f+
1, N represents node total number, f representing fault node or malicious node).
As a kind of preferably embodiment, in the embodiment of the present invention, second transaction is the critical path of the candidate
Any one transaction on diameter.
Specifically, the second transaction can be first transaction itself that is, in embodiments of the present invention, it is also possible to
Any one transaction in candidate critical path, i.e., from wound family friend easily to any one transaction the first transaction.
As a kind of preferably embodiment, in the embodiment of the present invention, the step S4 is specifically included:
S4.1: the common recognition node confirms the critical path of the candidate, if the critical path of the candidate
On transaction be not identified, then follow the steps S4.2 or step S4.3.
Specifically, common recognition node is confirmed that (confirmation refers to by 2 or 2 or more other friendships to candidate critical path
Easily confirmation), if there is a transaction (the i.e. second transaction) in candidate critical path, from family friend is created easily to the transaction (i.e. the
Two transaction) between All Activity be identified that then choosing wound family friend and easily arriving the path of the transaction (the i.e. second transaction) is key
Path.If the transaction in candidate critical path is not identified, is then handled there are two types of mode, respectively refer to step S4.2
Or step S4.3.What needs to be explained here is that then selecting candidate pass if the transaction in candidate critical path is identified
Key path is critical path, and the second transaction at this time is the first transaction.
S4.2: the common recognition node carries out common recognition ballot to the transaction of all not confirmeds, described if voting through
The transaction of not confirmed is identified through, if ballot does not pass through, is carried out to the previous transaction of the transaction of the not confirmed
Common recognition ballot, circulate operation in critical path until finding the second transaction, from wound family friend is easy or the end of previous critical path
It trades to the All Activity between second transaction and is all identified.
Specifically, all common recognition nodes carry out common recognition ballot to the transaction of all not confirmeds, likewise, common recognition is thrown here
Ticket follows BFT (Tendermint) or PBFT algorithm, and (N=3f+1, N represent node total number, and f representing fault node or malice save
Point).If voting through, the confirmation number of the transaction of the not confirmed is denoted as 2, i.e., the trade confirmation of the not confirmed is led to
Cross, if otherwise ballot does not pass through, common recognition ballot carried out to the previous transaction of the transaction of not confirmed, circulate operation until
A transaction (i.e. second transaction) is found in critical path, from wound family friend is easy or the end transaction of previous critical path is to the transaction
All Activity between (the i.e. second transaction) is all identified.
S4.3: the common recognition node is checked from wound family friend in the critical path of the candidate easily to the transaction of not confirmed
Previous transaction, circulate operation until finding the second transaction in the critical path in the candidate, from wound family friend it is easy or previous
The end transaction of critical path is all identified to the All Activity between second transaction.
Specifically, all common recognition nodes do not carry out common recognition ballot to the transaction of not confirmed, but in candidate critical path
It is checked on diameter from whether wound family friend is easily identified to the previous transaction of the transaction of not confirmed, circulate operation, until in candidate
Critical path on find a transaction (i.e. second transaction), from wound family friend easily to all the transaction (the i.e. second transaction)
Transaction is all identified.
S4.4: choose that the wound family friend is easy or the path of end transaction to second transaction of previous critical path is this
Secondary critical path.
Specifically, from wound family friend is easy or the end transaction of previous critical path to the second transaction All Activity at this
In critical path, and creates family friend and be easily all identified to the All Activity between the second transaction.
Fig. 3 is the structural schematic diagram of the transaction system shown according to an exemplary embodiment based on directed acyclic graph, ginseng
According to shown in Fig. 3, which includes:
Setup module, user are that each node participated in business sequentially is numbered, and common recognition node is set up in each node, and
Set time interval, the common recognition number of transaction of common recognition;
Number module is that respectively transaction number, the transaction number are applied in transaction for each node participated in business
Sequentially increase and globally unique;
First chooses module, for will create according to selected first transaction of the time interval or the common recognition number of transaction
Family friend is easy or critical path of the end transaction of previous critical path to the path of first transaction as candidate;
Second chooses module, confirms for the common recognition node to the critical path of the candidate, if the wound generation
The transaction of the end of transaction or previous critical path is identified to the All Activity between the second transaction, then chooses the wound family friend
The path of the end transaction of easy or previous critical path to second transaction is this critical path;
Broadcast module, for determining that growing direction and broadcast that this described critical path is main chain are participated in business to described
Each node write-in consistency account book.
As a kind of preferably embodiment, in the embodiment of the present invention, the number module includes:
Quantity application unit presses the friendship of the respective number size client of pre- first to file oneself in turn for each node
Easy quantity;
Whether judging unit, the remaining quantity of number of transaction for predicate node application are lower than preset threshold;
Filter element, each node is compared transaction content when submitting for trading, within the set time will be interior
Hold identical transaction to filter out, does not distribute transaction number;
Numbered cell is set as 0 for will create the easy number of family friend, and the number of other transaction sequentially increases.
As a kind of preferably embodiment, in the embodiment of the present invention, the first selection module includes:
Trade selection unit, for after the time interval or the common recognition number of transaction reach, it is selected number be n or
The transaction of common recognition number of transaction is the first transaction, and wherein n is the quantity traded in system;
Path candidate selection unit carries out common recognition ballot to first transaction for the common recognition node, if ballot is logical
Cross, then will create that family friend is easy or the end transaction of previous critical path to the path of first transaction as the critical path of candidate
Diameter.
As a kind of preferably embodiment, in the embodiment of the present invention, second transaction is the critical path of the candidate
Any one transaction on diameter.
As a kind of preferably embodiment, in the embodiment of the present invention, the second selection module includes:
Confirmation unit confirms the critical path of the candidate for the common recognition node;
Common recognition unit, carries out common recognition ballot to the transaction of all not confirmeds for the common recognition node, if voting through
Then being identified through the transaction of the not confirmed, if ballot does not pass through, to the previous of the transaction of the not confirmed
Transaction carries out common recognition ballot, and circulate operation in critical path until finding the second transaction, from wound family friend is easy or previous critical path
The end transaction of diameter is all identified to the All Activity between second transaction;
Query unit is checked in the critical path of the candidate from wound family friend for the common recognition node easily to not true
The previous transaction for the transaction recognized, circulate operation is until finding the second transaction in the critical path in the candidate, from wound family friend
The end transaction of easy or previous critical path is all identified to the All Activity between second transaction;
Critical path selection unit, for choosing that the wound family friend is easy or the end transaction of previous critical path is to described the
The path of two transaction is this critical path.
In conclusion technical solution provided in an embodiment of the present invention has the benefit that
Method of commerce and system provided in an embodiment of the present invention based on directed acyclic graph carries out preliminery application to transaction and presses
Sequence distribution number, avoids transaction conflict, and devise the main chain generation method of directed acyclic graph, transaction has been determined by main chain
The consistency of account book among the nodes and successive succession of trading.
It should be understood that provided by the above embodiment triggering transaction business based on the transaction system of directed acyclic graph
When, only the example of the division of the above functional modules, in practical application, it can according to need and divide above-mentioned function
With being completed by different functional modules, i.e., the internal structure of system is divided into different functional modules, to complete above description
All or part of function.In addition, the transaction system provided by the above embodiment based on directed acyclic graph be based on oriented nothing
The method of commerce embodiment of ring figure belongs to same design, i.e. this method is based on the system, the specific implementation process side of being detailed in
Method embodiment, which is not described herein again.
Those of ordinary skill in the art will appreciate that realizing that all or part of the steps of above-described embodiment can pass through hardware
It completes, relevant hardware can also be instructed to complete by program, the program can store in a kind of computer-readable
In storage medium, storage medium mentioned above can be read-only memory, disk or CD etc..
The foregoing is merely presently preferred embodiments of the present invention, is not intended to limit the invention, it is all in spirit of the invention and
Within principle, any modification, equivalent replacement, improvement and so on be should all be included in the protection scope of the present invention.