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 areaFailed transactions in block chain can be processed in time, and the transaction that averts failure brings loss to user, improves the efficiency of whole systemAnd 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 describedIt 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 retriesThe 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 transactionsGrade 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 successivelyIt is retransmitted to the block chain to carry out transaction and retry, wherein grade high ratio relatively transaction etc. of trading in the preset ratioThe 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 ratioLose transaction, further includes:
If the failed transactions lazy weight in a certain corresponding message queue of grade of trading, corresponding from next transaction gradeMessage 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 againSend 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 transactionsEasy 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 retriesThe 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 transactionsIn 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 successivelyIt is retransmitted to the block chain to carry out transaction and retry, wherein grade high ratio relatively transaction etc. of trading in the preset ratioThe 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 gradeMessage 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 realityNow 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 acquisitionThe Transaction Information of failed transactions in block chain, then obtains the transaction grade of failed transactions according to Transaction Information, then will unsuccessfully hand overIt is easily added in message queue, is retried with carrying out transaction according to transaction grade, to keep the failed transactions in block chain timelyIt 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 userLoss, 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, completeSite 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 onEmbodiment in the present invention, it is obtained by those of ordinary skill in the art without making creative efforts every otherEmbodiment 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 realityIt 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 asUnder:
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 itIt can there may be a large amount of failed transactions when power.Service system can obtain the transaction of failed transactions after judging Fail TransactionInformation, specifically, may include transaction content, transaction amount, transaction urgency level, aging etc. in Transaction Information, in addition, ifWhen 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 transactionThe 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 retryingPreferential processing.The transaction grade for obtaining failed transactions in the present embodiment according to Transaction Information can specifically pre-establish evaluation markStandard, such as evaluated according to transaction urgency level, aging etc., furthermore also retried in combination with transaction number of retries, namely transactionNumber is more, illustrates the failed transactions multiple Fail Transaction, does not avoid the body for extending period of reservation of number, influencing userIt 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 transactionsFailed 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 queueBreath is consumed, namely the high failed transactions of transaction grade are preferentially obtained from message queue, sends block for failed transactionsIt 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 predeterminedThe failed transactions that ratio obtains different transaction grades from message queue carry out transaction and retry, to guarantee the low mistake of grade of tradingIt 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 chainThen information obtains the transaction grade of failed transactions according to Transaction Information, then failed transactions is added in message queue, with basisTransaction grade carries out transaction and retries, to keep the failed transactions in block chain processed in time, retries guarantee by transactionFailed transactions can be successfully sent in block chain, and the transaction that averts failure brings loss to user, improve the efficiency of whole systemAnd user experience.
On the basis of the above embodiments, as shown in Fig. 2, determining the failure according to the Transaction Information described in S102The 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, whereinAbove-mentioned each information can carry in Transaction Information, can also be obtained according to Transaction Information from the storage unit for storing each information, orPerson 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 transactionNumber 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, fromAnd 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 assignedValue, 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 retriedNumber is divided into 5 grades, and to different transaction number of retries assignment, to obtain discretization numerical value namely coefficient c.WhenThe 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 indexIt 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 > 1As 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 timeFailed 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 5thGrade.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 toThe transaction grade of failed transactions retransmits the failed transactions to the block chain to carry out transaction and retry, and can specifically wrapIt includes:
The friendship with the failed transactions is added in the failed transactions by S1031, the transaction grade according to the failed transactionsIn 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 withThe 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 gradeTransaction be added in the corresponding message queue of transaction grade, specifically, as shown in figure 4, grade of trading has 5 grades, then settable 5The 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 tradingEasily 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 ratioTransaction, 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 overEasily, 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 acquisitionTransaction 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 gradeFailed 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 friendshipThe 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 queueLazy weight is then supplemented from next stage message queue, such as needs to obtain 5 failed transactions from 5 grades of message queues, but 5Currently there was only 3 failed transactions in grade message queue, then obtains 2 failed transactions from 4 grades of message queues as supplement;CertainlyThe 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 thatIf grade of trading and transaction number of retries are related, transaction grade needs to change when failed transactions fail again, then needsThe transaction grade of the failed transactions is reacquired, then failed transactions are added in message queue again, according to failed transactionsTransaction grade by failed transactions to block chain retransmit with carry out transaction retry;If trade grade and transaction number of retries withoutIf 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 teamIn 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 chainThen information obtains the transaction grade of failed transactions according to Transaction Information, then failed transactions is added in message queue, with basisTransaction grade carries out transaction and retries, to keep the failed transactions in block chain processed in time, retries guarantee by transactionFailed transactions can be successfully sent in block chain, and the transaction that averts failure brings loss to user, improve the efficiency of whole systemAnd 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 providesThe transaction based on block chain retry device can execute the transaction based on block chain retry embodiment of the method offer processing streamJourney, 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 transactionsTransaction 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 retriesThe 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 transactionsIn 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 successivelyIt is retransmitted to the block chain to carry out transaction and retry, wherein grade high ratio relatively transaction etc. of trading in the preset ratioThe 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 gradeMessage 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 instituteThe 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 chainThen information obtains the transaction grade of failed transactions according to Transaction Information, then failed transactions is added in message queue, with basisTransaction grade carries out transaction and retries, to keep the failed transactions in block chain processed in time, retries guarantee by transactionFailed transactions can be successfully sent in block chain, and the transaction that averts failure brings loss to user, improve the efficiency of whole systemAnd 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 instituteShow, the present embodiment provides a kind of transaction based on block chain to retry equipment, and the equipment includes: processor 42;Memory 43;WithAnd computer program.
Wherein, the computer program is stored in the memory 43, and is configured as being executed by the processor 42To 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 principleSimilar 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 42It 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 meterCalculation 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 itIts mode is realized.For example, the apparatus embodiments described above are merely exemplary, for example, the division of the unit, onlyOnly a kind of logical function partition, there may be another division manner in actual implementation, such as multiple units or components can be tiedAnother system is closed or is desirably integrated into, or some features can be ignored or not executed.Another point, it is shown or discussedMutual coupling, direct-coupling or communication connection can be through some interfaces, the INDIRECT COUPLING or logical of device or unitLetter 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 unitThe component shown may or may not be physical unit, it can and it is in one place, or may be distributed over multipleIn 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 unitIt is that each unit physically exists alone, can also be integrated in one unit with two or more units.Above-mentioned integrated listMember 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 oneIn storage media.Above-mentioned SFU software functional unit is stored in a storage medium, including some instructions are used so that a computerIt is each that equipment (can be personal computer, server or the network equipment etc.) or processor (processor) execute the present inventionThe 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 variousIt 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 moduleDivision progress for example, in practical application, can according to need and above-mentioned function distribution is complete by different functional modulesAt the internal structure of device being divided into different functional modules, to complete all or part of the functions described above.OnThe 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 extentPipe present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that: its according toSo be possible to modify the technical solutions described in the foregoing embodiments, or to some or all of the technical features intoRow 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 solutionThe range of scheme.