Disclosure of Invention
In order to solve the above problem, the present application provides a transaction reconciliation method based on a mercker tree, including:
the account checking parties generate a hash value corresponding to each transaction according to a preset hash algorithm, transaction data and account checking initiation time; the hash value is a leaf node of the Mercker tree corresponding to the transaction time period;
carrying out hash operation on the hash values of the two leaf nodes to generate a hash value corresponding to a middle node of the Mercker tree, and carrying out hash operation on the hash values of the two middle nodes to generate a hash value corresponding to a root node of the Mercker tree;
comparing the hash values corresponding to the nodes of the Mercker trees generated by the two reconciliation parties, and if the comparison result is consistent, the reconciliation result is a flat accounting; if the comparison result is inconsistent, comparing the hash values of the leaf nodes corresponding to the Merckel trees of the account checking parties to obtain the hash values of the leaf nodes with inconsistent comparison results; acquiring corresponding transaction data according to the leaf node hash value; and the account checking parties carry out transaction account checking according to the transaction data.
Preferably, the two reconciliation parties generate a hash value corresponding to each transaction according to a preset hash algorithm, transaction data and reconciliation initiation time, and the method comprises the following steps:
selecting any one hash algorithm of MD5, sha1, sha256, crc32 and hash as a preset hash algorithm for both reconciliation parties;
and operating the transaction data and the account checking initiation time through the hash algorithm to generate a hash value corresponding to each transaction.
Preferably, the transaction data comprises: payee, payer, transaction amount, transaction status, transaction type, transaction time, transaction voucher number.
Preferably, the hash values of the two leaf nodes are subjected to hash operation to generate a hash value corresponding to an intermediate node of the mercker tree, and the hash values of the two intermediate nodes are subjected to hash operation to form a hash value corresponding to a root node of the mercker tree, including:
pairing two adjacent leaf nodes, and performing hash operation on the hash values of the two adjacent leaf nodes to generate a hash value corresponding to a middle node of the Mercker tree;
if the number of the intermediate nodes is more than two, the two adjacent intermediate nodes are paired, and hash values of the two adjacent intermediate nodes are subjected to hash operation to generate a hash value corresponding to a new intermediate node of the Mercker tree until the hash value generated by the intermediate node is unique; the node corresponding to the unique hash value is the root node of the merkel tree.
Preferably, the method further comprises the following steps:
and if the leaf nodes or the intermediate nodes cannot be matched, performing hash operation on the preset default hash value and the leaf nodes or the intermediate nodes.
Preferably, the reconciliation parties perform transaction reconciliation according to the transaction data, and the method comprises the following steps:
and the account checking party confirms and performs account checking processing on the place where the transaction data are inconsistent.
The application also provides a transaction reconciliation system based on the Mercker tree, which comprises:
the leaf node generation module is used for generating a hash value corresponding to each transaction by the account checking parties according to a preset hash algorithm, transaction data and account checking initiation time; the hash value is a leaf node of the Mercker tree corresponding to the transaction time period;
the merkel tree generation module is used for carrying out hash operation on the hash values of the two leaf nodes to generate a hash value corresponding to an intermediate node of the merkel tree, and carrying out hash operation on the hash values of the two intermediate nodes to generate a hash value corresponding to a root node of the merkel tree;
the reconciliation module is used for comparing the hash values corresponding to the nodes of the Mercker trees generated by the reconciliation parties, and if the comparison result is consistent, the reconciliation result is a flat ledger; if the comparison result is inconsistent, comparing the hash values of the leaf nodes corresponding to the Merckel trees of the account checking parties to obtain the hash values of the leaf nodes with inconsistent comparison results; acquiring corresponding transaction data according to the leaf node hash value; and the account checking parties carry out transaction account checking according to the transaction data.
Preferably, the mercker tree generating module includes:
the leaf node pairing submodule is used for pairing two adjacent leaf nodes and carrying out hash operation on the hash values of the two adjacent leaf nodes to generate a hash value corresponding to a middle node of the Mercker tree;
the intermediate node pairing submodule is used for pairing two adjacent intermediate nodes if the number of the intermediate nodes is more than two, and performing hash operation on the hash values of the two adjacent intermediate nodes to generate a hash value corresponding to a new intermediate node of the Mercker tree until the hash value generated by the intermediate node is unique; the node corresponding to the unique hash value is the root node of the merkel tree.
Preferably, the method further comprises the following steps:
and the default pairing submodule is used for carrying out hash operation on the leaf node or the intermediate node by a preset default hash value if the leaf node or the intermediate node cannot be paired.
Preferably, the reconciliation module comprises:
and the processing sub-module is used for confirming and reconciling the inconsistent place of the transaction data of the reconciliation parties.
Detailed Description
In the following description, numerous specific details are set forth in order to provide a thorough understanding of the present application. This application is capable of implementation in many different ways than those herein set forth and of similar import by those skilled in the art without departing from the spirit of this application and is therefore not limited to the specific implementations disclosed below.
Fig. 1 is a schematic flow chart of a transaction reconciliation method based on a mercker tree, which is described in detail below with reference to fig. 1.
Step S101, generating a hash value corresponding to each transaction by both reconciliation parties according to a preset hash algorithm, transaction data and reconciliation initiation time; the hash value is a leaf node of the Mercker tree corresponding to the transaction time period.
The Merck tree is also called Hash tree, and its essence is a tree-like data structure, consisting of data block, leaf node, intermediate node and root node, and its any father node is equal to the Hash result obtained by adding the data of left and right child nodes, and its top-most node is called Merck tree root, and is a binary tree, and has the characteristics of determinacy, irreversibility, uniform length and high-efficiency retrieval and comparison, etc. Hash (hash) is a function that maps data of arbitrary length to data of fixed length, including but not limited to MD5, sha1, sha256, crc32, hash, etc., and the hash value will change greatly if the original data changes arbitrarily.
Selecting any one hash algorithm of MD5, sha1, sha256, crc32 and hash by the two reconciliation parties as the two reconciliation parties according to a preset hash algorithm; and operating the transaction data and the account checking initiation time through the hash algorithm to generate a hash value corresponding to each transaction. The hash value is a leaf node of the Mercker tree corresponding to the transaction time period. Transaction data, comprising: payee, payer, transaction amount, transaction status, transaction type, transaction time, transaction voucher number.
And step S102, carrying out hash operation on the hash values of the two leaf nodes to generate a hash value corresponding to the intermediate node of the Mercker tree, and carrying out hash operation on the hash values of the two intermediate nodes to generate a hash value corresponding to the root node of the Mercker tree.
Pairing two adjacent leaf nodes, and performing hash operation on the hash values of the two adjacent leaf nodes to generate a hash value corresponding to a middle node of the Mercker tree; if the number of the intermediate nodes is more than two, the two adjacent intermediate nodes are paired, and hash values of the two adjacent intermediate nodes are subjected to hash operation to generate a hash value corresponding to a new intermediate node of the Mercker tree until the hash value generated by the intermediate node is unique; the node corresponding to the unique hash value is the root node of the merkel tree.
And if the leaf nodes or the intermediate nodes cannot be matched, performing hash operation on the preset default hash value and the leaf nodes or the intermediate nodes.
Step S103, comparing the hash values corresponding to the nodes of the Mercker trees generated by the two reconciliation parties, and if the comparison results are consistent, the reconciliation result is a flat ledger; if the comparison result is inconsistent, comparing the hash values of the leaf nodes corresponding to the Merckel trees of the account checking parties to obtain the hash values of the leaf nodes with inconsistent comparison results; acquiring corresponding transaction data according to the leaf node hash value; the account checking parties carry out transaction account checking according to the transaction data
And when the comparison result is inconsistent, confirming and reconciling the inconsistent place of the transaction data by the reconciliation parties according to the acquired corresponding transaction data.
Specific examples of applications are as follows:
the method has the main functions of account checking setting, hash generation, account checking hash tree generation and account checking execution. The reconciliation setting is used for setting transaction fields for generating the hash value, and comprises the settings of reconciliation types, field names, field sequences, dictionary value conversion, connectors, hash default values, reconciliation time and the like, and can be customized according to the dimensions of the transaction types, the transaction states, the reconciliation time and the like, so that the centralized standardized management of reconciliation of different services is realized. The hash generation module is triggered at the set reconciliation time point, and performs hash calculation on the corresponding transaction record according to the rules set for reconciliation to obtain the corresponding hash value of each transaction. And performing hash calculation on the generated hash values pairwise, pairing the transaction hashes which cannot be paired pairwise by using a hash default value set by the system, and finally generating a hash tree containing the whole account-checking transaction, namely the account-checking hash tree. And the downstream mechanism acquires the reconciliation hash tree generated by the upstream mechanism, firstly acquires the root node and judges whether the root node is consistent with the root node of the reconciliation hash tree generated by the mechanism. According to the certainty and irreversibility of the Mercker tree, if the two are consistent, the transaction information of the two parties is consistent, and the account checking work is finished. If the transaction information is inconsistent with the transaction information, inconsistent transaction information is indicated, and account balancing is required. And then performing subsequent traversal on the account checking hash trees of the two parties, comparing the traversal results, outputting leaf nodes corresponding to inconsistent hash values, further matching transaction information records corresponding to the leaf nodes hash, triggering a manual processing flow, and finishing the account checking work.
The account checking setting function flow specifically comprises the following steps:
and clicking a system function page to add a reconciliation setting record, and setting and storing the information such as the reconciliation type, the field name, the field sequence, the dictionary value conversion, the connector, the hash default value, the hash algorithm, the reconciliation time and the like. When the reconciliation record is selected and set to be effective, the system background records the setting and generates a timing task according to the recorded reconciliation time. And when the reconciliation record is selected and set to be invalid, the background of the system does not generate a timing task and only records the setting.
The hash generation functional process specifically comprises:
after a timing task generated by the reconciliation setting module is started at a specific reconciliation time point, selective and sequential splicing is carried out on transaction information according to field items set by the reconciliation, after the splicing is completed, batch processing is carried out through an agreed hash algorithm, a transaction hash value corresponding to each transaction is generated and stored in a computer, and the storage position comprises a memory, a cache, a database, a file and the like.
The generation functional flow of the account checking hash tree specifically comprises the following steps:
every two adjacent transaction hash values are paired, and the default hash value set by the account checking is paired when the two transaction hash values are not paired. And after pairing connection, performing hash again. And (4) taking the adjacent transaction hash as a leaf node, and taking the result obtained by the hash again as a parent node of the leaf node to create the Mercker tree. And pairwise matching and connecting the father nodes, and taking the result of the hash again as a new father node. And repeating the steps to finally obtain the reconciliation hash tree, which is detailed in an attached figure 2.
The account checking execution function flow specifically comprises the following steps:
and the downstream reconciliation mechanism acquires the data file or the character string containing the reconciliation hash tree in an online or offline mode through network requests, mailbox notifications and the like. Analyzing a reconciliation hash tree data file or a character string, converting the reconciliation hash tree data file or the character string into a program object of a tree structure, reading a root node, judging whether the reconciliation hash tree data file or the character string is consistent with the root node of the reconciliation hash tree generated by the mechanism, if so, outputting a reconciliation result as a tie account, and finishing the execution of the reconciliation; and if the two-dimensional account checking hash trees are inconsistent, traversing the account checking hash tree in a sequential traversal mode, comparing the account checking hash tree with the account checking hash tree of the mechanism, eliminating intermediate nodes, and outputting inconsistent leaf node transaction hashes in the account checking hash tree of the mechanism. And inquiring and summarizing the corresponding specific transaction detail record according to the transaction hash, outputting an account checking result and the corresponding detail record, and finishing the account checking execution.
According to the embodiment, when two transaction parties perform transactions, the transaction systems of the two transaction parties splice key transaction information such as a payee, a payer, a transaction amount, a transaction state, a transaction type, a transaction time, a transaction certificate number and the like according to a transaction data item and a data dictionary agreed in advance, and then perform hash operation in real time to obtain the unique hash value of the transaction. And then carrying out pairwise hash operation on the transaction hashes, and generating the Mercker tree of the transaction information hashes in a certain period according to the creating rule of the Mercker tree. If the transaction data of the two transaction parties are completely consistent in the transaction period, namely the hash value of each transaction data is consistent, the finally generated Mercker tree root of the time period is necessarily consistent. According to the certainty and irreversibility of the Mercker tree, if the finally generated Mercker tree roots are inconsistent, the transaction data of both transaction parties can be shown to have error account. Then, traversing the Mercker trees of both parties, retrieving and comparing branches with inconsistent transaction hashes, then traversing the branches, determining the specific transaction data hashes related to the branches, further locking a specific error transaction, and triggering the automatic or manual tie account to solve the occurring transaction error account.
According to the transaction reconciliation method, the complicated and huge transaction reconciliation files are converted into the compact and safe binary tree data format with unified format and open standard, the processes of transmission, analysis, comparison and the like are greatly improved, the network dependence is reduced, less computing resources are consumed, the standardized analysis enables the upstream and downstream docking to be more convenient, more convenient and more efficient, and due to the application of the certainty and the irreversibility of the hash value, the data is guaranteed not to be falsified, and the data reconciliation processing is safer and more accurate.
Based on the same inventive concept, the present application also provides a mercker tree-basedtransaction reconciliation system 300, as shown in fig. 3, comprising:
the leafnode generating module 310 is configured to generate a hash value corresponding to each transaction by the two reconciliation parties according to a preset hash algorithm, the transaction data and the reconciliation initiation time; the hash value is a leaf node of the Mercker tree corresponding to the transaction time period;
the merkeltree generating module 320 is configured to perform hash operation on the hash values of the two leaf nodes to generate a hash value corresponding to an intermediate node of the merkel tree, perform hash operation on the hash values of the two intermediate nodes to generate a hash value corresponding to a root node of the merkel tree;
thereconciliation module 330 is configured to compare hash values corresponding to the nodes of the tacler trees generated by the reconciliation parties, and if the comparison result is consistent, the reconciliation result is a flat accounting; if the comparison result is inconsistent, comparing the hash values of the leaf nodes corresponding to the Merckel trees of the account checking parties to obtain the hash values of the leaf nodes with inconsistent comparison results; acquiring corresponding transaction data according to the leaf node hash value; and the account checking parties carry out transaction account checking according to the transaction data.
Preferably, the mercker tree generating module includes:
the leaf node pairing submodule is used for pairing two adjacent leaf nodes and carrying out hash operation on the hash values of the two adjacent leaf nodes to generate a hash value corresponding to a middle node of the Mercker tree;
the intermediate node pairing submodule is used for pairing two adjacent intermediate nodes if the number of the intermediate nodes is more than two, and performing hash operation on the hash values of the two adjacent intermediate nodes to generate a hash value corresponding to a new intermediate node of the Mercker tree until the hash value generated by the intermediate node is unique; the node corresponding to the unique hash value is the root node of the merkel tree.
Preferably, the method further comprises the following steps:
and the default pairing submodule is used for carrying out hash operation on the leaf node or the intermediate node by a preset default hash value if the leaf node or the intermediate node cannot be paired.
Preferably, the reconciliation module comprises:
and the processing sub-module is used for confirming and reconciling the inconsistent place of the transaction data of the reconciliation parties.
Finally, it should be noted that: although the present invention has been described in detail with reference to the above embodiments, it should be understood by those skilled in the art that various changes may be made and equivalents may be substituted for elements thereof without departing from the spirit and scope of the invention.