Summary of the invention
The present invention provides a kind of transaction based on block chain and retries method, apparatus, equipment and readable storage medium storing program for executing, so that area
Failed transactions in block chain can be processed in time, and the transaction that averts failure brings loss to user, improves the efficiency of whole system
And user experience.
The first aspect of the present invention is to provide a kind of transaction based on block chain and retries method, which comprises
Obtain the Transaction Information of failed transactions in block chain;
The transaction grade of the failed transactions is determined according to the Transaction Information;
The failed transactions are added in message queue, unsuccessfully to be handed over according to the transaction grade of the failed transactions by described
It is easily retransmitted to the block chain to carry out transaction and retry.
Further, the transaction grade that the failed transactions are determined according to the Transaction Information, comprising:
Transaction urgency level, aging and transaction number of retries are determined according to the Transaction Information;
Sliding-model control, acquisition pair are carried out to the transaction urgency level, the aging and the transaction number of retries
The discretization numerical value answered;
The transaction grade of the failed transactions is obtained according to the discretization numerical value.
Further, described that the failed transactions are added in message queue, according to the transaction etc. of the failed transactions
Grade retransmits the failed transactions to the block chain to carry out transaction and retry, comprising:
The failed transactions are added in message queue corresponding with the transaction grade according to the transaction grade;
The failed transactions of preset quantity are obtained from the corresponding message queue of each transaction grade according to preset ratio, and successively
It is retransmitted to the block chain to carry out transaction and retry, wherein grade high ratio relatively transaction etc. of trading in the preset ratio
The low ratio of grade is big.
Further, the mistake for obtaining preset quantity from the corresponding message queue of each transaction grade according to preset ratio
Lose transaction, further includes:
If the failed transactions lazy weight in a certain corresponding message queue of grade of trading, corresponding from next transaction grade
Message queue in obtain respective numbers failed transactions to supplement the deficiency quantity.
Further, the transaction grade according to the failed transactions by the failed transactions to the block chain again
Send with carry out transaction retry after, further includes:
Judge to trade and whether succeed after transaction retries, transaction is re-started if unsuccessful and is retried.
The second aspect of the present invention is to provide a kind of transaction based on block chain and retries device, and described device includes:
Module is obtained, for obtaining the Transaction Information of failed transactions in block chain;
Rating module, for determining the transaction grade of the failed transactions according to the Transaction Information;
Transaction retries module, for the failed transactions to be added in message queue, according to the friendship of the failed transactions
Easy grade retransmits the failed transactions to the block chain to carry out transaction and retry.
Further, the rating module is specifically used for:
Transaction urgency level, aging and transaction number of retries are determined according to the Transaction Information;
Sliding-model control, acquisition pair are carried out to the transaction urgency level, the aging and the transaction number of retries
The discretization numerical value answered;
The transaction grade of the failed transactions is obtained according to the discretization numerical value.
Further, the transaction retries module and is specifically used for:
According to the transaction grade of the failed transactions, the transaction grade with the failed transactions is added in the failed transactions
In corresponding message queue;
The failed transactions of preset quantity are obtained from the corresponding message queue of each transaction grade according to preset ratio, and successively
It is retransmitted to the block chain to carry out transaction and retry, wherein grade high ratio relatively transaction etc. of trading in the preset ratio
The low ratio of grade is big.
Further, the transaction retries module and is also used to:
If the failed transactions lazy weight in a certain corresponding message queue of grade of trading, corresponding from next transaction grade
Message queue in obtain respective numbers failed transactions to supplement the deficiency quantity.
Further, the transaction retries module and is also used to:
Judge to trade and whether succeed after transaction retries, transaction is re-started if unsuccessful and is retried.
The third aspect of the present invention is to provide a kind of transaction based on block chain and retries equipment, and the equipment includes:
Memory;
Processor;And
Computer program;
Wherein, the computer program stores in the memory, and is configured as being executed by the processor with reality
Now method as described in relation to the first aspect.
The fourth aspect of the present invention is to provide a kind of computer readable storage medium, is stored thereon with computer program;
Method as described in relation to the first aspect is realized when the computer program is executed by processor.
Transaction provided by the invention based on block chain retries method, apparatus, equipment and readable storage medium storing program for executing, passes through acquisition
The Transaction Information of failed transactions in block chain, then obtains the transaction grade of failed transactions according to Transaction Information, then will unsuccessfully hand over
It is easily added in message queue, is retried with carrying out transaction according to transaction grade, to keep the failed transactions in block chain timely
It is processed, it is retried by transaction and guarantees that failed transactions can be successfully sent in block chain, the transaction that averts failure is brought to user
Loss, improves the efficiency and user experience of whole system.
Specific embodiment
Following will be combined with the drawings in the embodiments of the present invention, and technical solution in the embodiment of the present invention carries out clear, complete
Site preparation description, it is clear that described embodiments are only a part of the embodiments of the present invention, instead of all the embodiments.It is based on
Embodiment in the present invention, it is obtained by those of ordinary skill in the art without making creative efforts every other
Embodiment shall fall within the protection scope of the present invention.
Fig. 1 is that the transaction provided in an embodiment of the present invention based on block chain retries method flow diagram.As described in Figure 1, this reality
It applies example and provides a kind of transaction based on block chain and retry method, executing subject is service system, and this method specific steps are such as
Under:
S101, the Transaction Information for obtaining failed transactions in block chain.
In the present embodiment, block chain is sent for transaction by service system, when transaction concurrency handles energy beyond it
It can there may be a large amount of failed transactions when power.Service system can obtain the transaction of failed transactions after judging Fail Transaction
Information, specifically, may include transaction content, transaction amount, transaction urgency level, aging etc. in Transaction Information, in addition, if
When the Fail Transaction is multiple, transaction number of retries can be got.Certain Transaction Information is not limited to above-mentioned cited information,
Details are not described herein again for his information.
S102, the transaction grade that the failed transactions are determined according to the Transaction Information.
In the present embodiment, the transaction grade of failed transactions can characterize the significance level of the transaction, can be used as transaction
The priority of repeating transmission, namely transaction higher grade, illustrates that the significance level of the transaction is higher, needs more when carrying out transaction and retrying
Preferential processing.The transaction grade for obtaining failed transactions in the present embodiment according to Transaction Information can specifically pre-establish evaluation mark
Standard, such as evaluated according to transaction urgency level, aging etc., furthermore also retried in combination with transaction number of retries, namely transaction
Number is more, illustrates the failed transactions multiple Fail Transaction, does not avoid the body for extending period of reservation of number, influencing user
It tests, the more failed transactions of transaction number of retries are also required to preferentially carry out trading to retry, namely need to improve transaction grade.
S103, the failed transactions are added in message queue, with will be described according to the transaction grade of the failed transactions
Failed transactions are retransmitted to the block chain to carry out transaction and retry.
In the present embodiment, failed transactions are added in message queue, and according to transaction grade to disappearing in message queue
Breath is consumed, namely the high failed transactions of transaction grade are preferentially obtained from message queue, sends block for failed transactions
It is retried in chain with carrying out transaction.Certainly the failed transactions for not avoiding transaction grade low are constantly in wait state, can be with predetermined
The failed transactions that ratio obtains different transaction grades from message queue carry out transaction and retry, to guarantee the low mistake of grade of trading
It loses to trade also can timely carry out trading and retry.
Transaction provided in this embodiment based on block chain retries method, by the transaction for obtaining failed transactions in block chain
Then information obtains the transaction grade of failed transactions according to Transaction Information, then failed transactions is added in message queue, with basis
Transaction grade carries out transaction and retries, to keep the failed transactions in block chain processed in time, retries guarantee by transaction
Failed transactions can be successfully sent in block chain, and the transaction that averts failure brings loss to user, improve the efficiency of whole system
And user experience.
On the basis of the above embodiments, as shown in Fig. 2, determining the failure according to the Transaction Information described in S102
The transaction grade of transaction, it may include:
S1021, transaction urgency level, aging and transaction number of retries are determined according to the Transaction Information;
In the present embodiment, transaction urgency level, aging and transaction number of retries can be obtained according to Transaction Information, wherein
Above-mentioned each information can carry in Transaction Information, can also be obtained according to Transaction Information from the storage unit for storing each information, or
Person sends acquisition request to the user of the transaction, by each information of user feedback.
S1022, sliding-model control is carried out to the transaction urgency level, the aging and the transaction number of retries,
Obtain corresponding discretization numerical value;
In the present embodiment, the evaluation to transaction grade for convenience retries transaction urgency level, aging and transaction
Number carries out sliding-model control, specifically can carry out discretization by such as following table 1-3:
Table 1
Urgency level |
It is high |
In on |
In |
In under |
It is low |
Coefficient a |
10 |
8 |
6 |
2 |
1 |
Table 2
Table 3
As shown in table 1, urgency level can be divided into 5 grades by the present embodiment, and to different urgency level assignment, from
And obtain discretization numerical value namely coefficient a;As shown in table 2, aging can be drawn and is temporally divided into 5 stages, and the stage is assigned
Value, to obtain discretization numerical value namely coefficient b, wherein T1, T2, T3, T4, T5 are the empirical value that actual test is crossed, and T5
> T4 > T3 > T2 > T1 can be understood as being less than or equal to time T4 greater than time T5 greater than time T5 in the present embodiment,
I.e. aging is between time T4 and T5, in addition, coefficient b is denoted as 0 when being less than or equal to T5;As shown in figure 3, transaction can be retried
Number is divided into 5 grades, and to different transaction number of retries assignment, to obtain discretization numerical value namely coefficient c.When
The example above is not limited to transaction urgency level, aging and transaction number of retries discretization in right the present embodiment.
S1023, the transaction grade that the failed transactions are obtained according to the discretization numerical value.
In the present embodiment, based on above-mentioned citing, transaction grading index can be calculated using following formula:
After calculating transaction grading index, is divided in transaction grade, such as the present embodiment and drawn according to transaction grading index
It is divided into 5 transaction grades, regard 5 >=L > 4 as the 5th grade, 4 >=L > 3 is used as the 4th grade, and 3 >=L > 2 is used as 3rd level, 2 >=L > 1
As the 2nd grade, L≤1 is used as the 1st grade, for transaction urgency level be in upper, aging be greater than time T2 and transaction retries time
Failed transactions of the number more than 5 times, it is 4.25 that transaction grading index L can be calculated according to above-mentioned formula, to judge it for the 5th
Grade.Certainly it obtains transaction grade and is also not limited to the example above.
Further, as shown in figure 3, the failed transactions are added in message queue described in S103, according to
The transaction grade of failed transactions retransmits the failed transactions to the block chain to carry out transaction and retry, and can specifically wrap
It includes:
The friendship with the failed transactions is added in the failed transactions by S1031, the transaction grade according to the failed transactions
In the corresponding message queue of easy grade;
S1032, the failed transactions for obtaining preset quantity from the corresponding message queue of each transaction grade according to preset ratio,
And successively retransmit to the block chain to carry out transaction and retry, wherein trade in the preset ratio the high ratio of grade compared with
The low ratio of grade of trading is big.
In the present embodiment, settable multiple message queues, it is corresponding with transaction grade, it can will fail according to transaction grade
Transaction be added in the corresponding message queue of transaction grade, specifically, as shown in figure 4, grade of trading has 5 grades, then settable 5
The failed transactions that grade of trading is 5 grades are added in 5 grades of message queues by message queue, the failure friendship for being 4 grades by grade of trading
Easily be added in 4 grades of message queues, and so on, wherein in Fig. 4 transaction initiator namely the present embodiment in service system,
For sending transaction into block chain.When carry out transaction retry when, failure can be obtained from each message queue according to predetermined ratio
Transaction, such as predetermined ratio are 5:4:3:2:1, and preset quantity is 15, namely obtains 5 from 5 grades of message queues and unsuccessfully hand over
Easily, 4 failed transactions are obtained from 4 grades of message queues, and so on, the failure preferentially high to transaction grade after the completion of acquisition
Transaction is retried, so that the high failed transactions of grade of trading obtain priority processing, while it is low also to take into account transaction grade
Failed transactions, avoid transaction grade it is low the failed transactions waiting time it is too long.
Further, if failed transactions lazy weight in the corresponding message queue of a certain transaction grade, from next friendship
The failed transactions of respective numbers are obtained in the corresponding message queue of easy grade to supplement the deficiency quantity.
For example, according to the predetermined ratio and preset quantity of above-mentioned setting, if the failed transactions in certain level-one message queue
Lazy weight is then supplemented from next stage message queue, such as needs to obtain 5 failed transactions from 5 grades of message queues, but 5
Currently there was only 3 failed transactions in grade message queue, then obtains 2 failed transactions from 4 grades of message queues as supplement;Certainly
The message queue of intermediate level, such as 4 grades of message queues can also be supplemented from the corresponding message queue of upper transaction grade,
Namely it is supplemented from 5 grades of message queues;For 1 grade of message queue, can be supplemented from 2 grades of consumption queues, naturally it is also possible to wait.
On the basis of the above embodiments, after failed transactions are carried out with transaction and is retried, may also include that
Judge to trade and whether succeed after transaction retries, transaction is re-started if unsuccessful and is retried.
In the present embodiment, after failed transactions, which carry out transaction, to be retried, it is possible to occur the case where Fail Transaction again,
Therefore it needs to judge whether transaction succeeds after transaction retries, transaction is re-started if unsuccessful and is retried.It should be noted that
If grade of trading and transaction number of retries are related, transaction grade needs to change when failed transactions fail again, then needs
The transaction grade of the failed transactions is reacquired, then failed transactions are added in message queue again, according to failed transactions
Transaction grade by failed transactions to block chain retransmit with carry out transaction retry;If trade grade and transaction number of retries without
If pass, then directly failed transactions can be added in message queue, be retried with carrying out transaction according to the transaction grade previously obtained;
Certainly it also can determine whether transaction grade changes, then reacquire transaction grade if there is a change, add message team
In column, it is directly added into message queue if not changing.
Transaction provided in this embodiment based on block chain retries method, by the transaction for obtaining failed transactions in block chain
Then information obtains the transaction grade of failed transactions according to Transaction Information, then failed transactions is added in message queue, with basis
Transaction grade carries out transaction and retries, to keep the failed transactions in block chain processed in time, retries guarantee by transaction
Failed transactions can be successfully sent in block chain, and the transaction that averts failure brings loss to user, improve the efficiency of whole system
And user experience.
Fig. 5 is the structure chart that the transaction provided in an embodiment of the present invention based on block chain retries device.The present embodiment provides
The transaction based on block chain retry device can execute the transaction based on block chain retry embodiment of the method offer processing stream
Journey, as shown in figure 5, it includes obtaining module 31, rating module 32 and handing over that the transaction based on block chain, which retries device,
Easily retry module 33.
Wherein, module 31 is obtained, for obtaining the Transaction Information of failed transactions in block chain;
Rating module 32, for determining the transaction grade of the failed transactions according to the Transaction Information;
Transaction retries module 33, for the failed transactions to be added in message queue, according to the failed transactions
Transaction grade retransmits the failed transactions to the block chain to carry out transaction and retry.
Further, the rating module 32 is specifically used for:
Transaction urgency level, aging and transaction number of retries are determined according to the Transaction Information;
Sliding-model control, acquisition pair are carried out to the transaction urgency level, the aging and the transaction number of retries
The discretization numerical value answered;
The transaction grade of the failed transactions is obtained according to the discretization numerical value.
Further, the transaction retries module 33 and is specifically used for:
According to the transaction grade of the failed transactions, the transaction grade with the failed transactions is added in the failed transactions
In corresponding message queue;
The failed transactions of preset quantity are obtained from the corresponding message queue of each transaction grade according to preset ratio, and successively
It is retransmitted to the block chain to carry out transaction and retry, wherein grade high ratio relatively transaction etc. of trading in the preset ratio
The low ratio of grade is big.
Further, the transaction retries module 33 and is also used to:
If the failed transactions lazy weight in a certain corresponding message queue of grade of trading, corresponding from next transaction grade
Message queue in obtain respective numbers failed transactions to supplement the deficiency quantity.
Further, the transaction retries module 33 and is also used to:
Judge to trade and whether succeed after transaction retries, transaction is re-started if unsuccessful and is retried.
Transaction provided in an embodiment of the present invention based on block chain, which retries device, can be specifically used for executing above-mentioned Fig. 1-3 institute
The embodiment of the method for offer, details are not described herein again for concrete function.
Transaction provided in this embodiment based on block chain retries device, by the transaction for obtaining failed transactions in block chain
Then information obtains the transaction grade of failed transactions according to Transaction Information, then failed transactions is added in message queue, with basis
Transaction grade carries out transaction and retries, to keep the failed transactions in block chain processed in time, retries guarantee by transaction
Failed transactions can be successfully sent in block chain, and the transaction that averts failure brings loss to user, improve the efficiency of whole system
And user experience.
Fig. 6 be another embodiment of the present invention provides the transaction based on block chain retry the structure chart of equipment.Such as Fig. 6 institute
Show, the present embodiment provides a kind of transaction based on block chain to retry equipment, and the equipment includes: processor 42;Memory 43;With
And computer program.
Wherein, the computer program is stored in the memory 43, and is configured as being executed by the processor 42
To realize that the transaction as provided by Fig. 1-3 based on block chain retries the process flow of embodiment of the method offer, realization principle
Similar with technical effect, details are not described herein again.
More specifically, the equipment further includes receiver 40 and transmitter 41, receiver 40 and transmitter 41, processor 42
It is connected with memory 43 by bus.
In addition, the present embodiment also provides a kind of computer readable storage medium, it is stored thereon with computer program, the meter
Calculation machine program is executed by processor to realize that the transaction based on block chain described in above-described embodiment retries method.
In several embodiments provided by the present invention, it should be understood that disclosed device and method can pass through it
Its mode is realized.For example, the apparatus embodiments described above are merely exemplary, for example, the division of the unit, only
Only a kind of logical function partition, there may be another division manner in actual implementation, such as multiple units or components can be tied
Another system is closed or is desirably integrated into, or some features can be ignored or not executed.Another point, it is shown or discussed
Mutual coupling, direct-coupling or communication connection can be through some interfaces, the INDIRECT COUPLING or logical of device or unit
Letter connection can be electrical property, mechanical or other forms.
The unit as illustrated by the separation member may or may not be physically separated, aobvious as unit
The component shown may or may not be physical unit, it can and it is in one place, or may be distributed over multiple
In network unit.It can select some or all of unit therein according to the actual needs to realize the mesh of this embodiment scheme
's.
It, can also be in addition, the functional units in various embodiments of the present invention may be integrated into one processing unit
It is that each unit physically exists alone, can also be integrated in one unit with two or more units.Above-mentioned integrated list
Member both can take the form of hardware realization, can also realize in the form of hardware adds SFU software functional unit.
The above-mentioned integrated unit being realized in the form of SFU software functional unit can store and computer-readable deposit at one
In storage media.Above-mentioned SFU software functional unit is stored in a storage medium, including some instructions are used so that a computer
It is each that equipment (can be personal computer, server or the network equipment etc.) or processor (processor) execute the present invention
The part steps of embodiment the method.And storage medium above-mentioned includes: USB flash disk, mobile hard disk, read-only memory (Read-
Only Memory, ROM), random access memory (Random Access Memory, RAM), magnetic or disk etc. it is various
It can store the medium of program code.
Those skilled in the art can be understood that, for convenience and simplicity of description, only with above-mentioned each functional module
Division progress for example, in practical application, can according to need and above-mentioned function distribution is complete by different functional modules
At the internal structure of device being divided into different functional modules, to complete all or part of the functions described above.On
The specific work process for stating the device of description, can refer to corresponding processes in the foregoing method embodiment, and details are not described herein.
Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention., rather than its limitations;To the greatest extent
Pipe present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that: its according to
So be possible to modify the technical solutions described in the foregoing embodiments, or to some or all of the technical features into
Row equivalent replacement;And these are modified or replaceed, various embodiments of the present invention technology that it does not separate the essence of the corresponding technical solution
The range of scheme.