Detailed Description
A detailed description of one or more embodiments of the invention is provided below along with accompanying figures that illustrate the principles of the invention. The invention is described in connection with such embodiments, but the invention is not limited to any embodiment. The scope of the invention is limited only by the claims and the invention encompasses numerous alternatives, modifications and equivalents. In the following description, numerous specific details are set forth in order to provide a thorough understanding of the present invention. These details are provided for the purpose of example and the invention may be practiced according to the claims without some or all of these specific details.
An aspect of the present invention provides a block-based data synchronization method. Fig. 1 is a flowchart of a block-based data synchronization method according to an embodiment of the present invention.
The public chain system provided by the invention comprises a plurality of public chain nodes to form a decentralized system. When transaction data is written, any node in a plurality of nodes (T nodes) of the system is used as a head node to receive new block data; the first node stores the new block data into a new block cache of the first node and sends a transaction data updating request to other T-1 nodes; the transaction data updating request comprises the new block data; the transaction data updating request is used for indicating any node in other T-1 nodes to store the summary information of the new block data into the respective new block cache, namely for any node in other T-1 nodes, after receiving the transaction data updating request, acquiring the new block data therein and storing the new block data into the respective new block cache. Through the process, each public link node in the system receives the new block data.
Specifically, in the new block data writing process, for any one of the T nodes of the public link system:
1.1: acquiring N new block data; and respectively carrying out binary processing on the N new block data according to a preset binary rule to obtain N byte information respectively corresponding to the N new block data.
1.2: constructing a new block, wherein the new block comprises a transaction data packet and block metadata information; the block metadata information comprises a block metadata information abstract value of a preamble block in a public chain of the node; the preamble block is the most recently added block in the longest chain of the public chain. In the public chain system of the invention, T nodes respectively have a public chain in the node, and each block in the public chain in the node is connected in series by a pointer, namely a block metadata information abstract value of a preamble block.
1.3: and determining the consensus blocks meeting the consensus rule from the new blocks generated by the T nodes through a consensus algorithm and adding the consensus blocks into the public chain. Preferably, when the number of the summary information of the new block data in the new block cache of the node reaches a preset number, the step 1.1 is executed; preferably, step 1.1 is performed when a preset time is reached from the time interval of last constructing a new block.
The block metadata information also comprises metadata abstract values of N abstract information corresponding to N new block data respectively. Each new block data has its own abstract information, and the specific calculation process is to binarize the new block data to obtain byte information of the new block data, and then to perform hash operation on the byte information to obtain the abstract information of the new block data. The metadata digest value can be used to verify whether the transaction data packet of the block is tampered during the data synchronization verification.
Preferably, byte information of the new block data is stored in the node internal public chain, the block metadata information records the binarization type corresponding to the binarization rule, and the node of the public chain system obtains the original form of the data in the block according to the byte information and the binarization rule during data synchronization verification.
In order to ensure the consistency of the public chain in the system, the block metadata information further comprises a random verification code, and the random verification code is used for determining the consensus blocks in the consensus algorithm. After each node in the T nodes constructs a transaction data packet and other parts in the block metadata information, a plurality of random verification codes are tried, the change of the random verification codes directly causes the change of the block metadata information abstract value of a new block, and when the block metadata information abstract value of any block firstly meets the preset number of first n bits of 0, the node broadcasts the constructed new block as a common identification block to other nodes in the public chain system. And after receiving the broadcast of the consensus blocks, other nodes stop constructing the new block and add the consensus blocks into the public chain. Preferably, the preset number n is dynamically adjusted according to an average time consumption for generating a new block. After the consensus blocks are determined from the new blocks generated by the T nodes, aiming at any node in the T nodes, removing the N new block data corresponding to the N byte information included in the consensus blocks from the new block cache of the node, and preventing repeated writing.
Preferably, after determining that the consensus blocks meeting the consensus algorithm rule from the new blocks generated by the T nodes are added to the public chain, the method further comprises: aiming at each byte information in the common identification block, acquiring the summary information of the new block data corresponding to the byte information; storing the summary information of the new block data and the addressing information corresponding to the new block data in a local address base; the addressing information includes the location ID of the byte information corresponding to the new block data in the block. Each node in the public chain system stores the addressing information of the data in the block into a local address library, and a user only needs to provide summary information of new transaction data when performing data synchronization verification. Preferably, after the consensus block meeting the consensus algorithm rule is added into the public chain, whether the consensus block is the first node of any byte information in the consensus block can be judged, and if the consensus block is the first node of any byte information in the consensus block, the addressing information of the summary information is output to the user. When the user performs data synchronous verification, the user can provide summary information and addressing information of new transaction data at the same time, and the efficiency of data synchronous verification can be improved.
In order to avoid hash collision attack of a single algorithm, after respectively calculating the summary information of the N new block data according to the N byte information, the invention also comprises dividing the N summary information; calculating the abstract value of each partition to obtain secondary abstract values of N pieces of abstract information; and continuously dividing the secondary abstract values, and returning to the step of calculating the abstract value of each division until the metadata abstract value is obtained. When calculating the digest value of each partition, calculating an intermediate digest value of the partition according to a first hash rule; and calculating the digest value of the intermediate digest value as the partitioned digest value according to a second hash rule. By adopting the digest value calculation method provided by the preferred embodiment, the hash collision attack of a single algorithm can be prevented, and a digest value with a shorter length can be output.
According to the block data updating method provided in the foregoing embodiment, the following embodiments of the present invention further provide a data synchronization verification method corresponding to the above updating method, where the data synchronization verification method is performed on data written into a public link, and the method includes the following steps:
the synchronous verification initiating node acquires summary information of the new transaction data, and is any one of the T nodes;
determining whether each block contains byte information corresponding to the summary information from the public chain;
each tile in the public chain includes a transaction data packet and tile metadata information; the transaction data packet comprises byte information corresponding to each new transaction data; the block metadata information comprises a block metadata information summary value of a preamble block of the block;
and if the byte information corresponding to the summary information exists in the public chain, the new transaction data is confirmed to pass the synchronous verification.
Any node in the T nodes of the public chain system can be used as a synchronous verification initiating node to provide data synchronous verification service for the user. The summary information of the new transaction data acquired by the synchronous verification initiating node can be directly provided by the user or can be calculated and acquired according to the new transaction data provided by the user. And the synchronous verification initiating node traverses the summary information corresponding to the byte information contained in each block in the public chain, acquires a summary value and then compares the summary value with the summary information of the received new transaction data. More preferably, the synchronous verification initiating node stores a local address library in advance; the local address library comprises addressing information of summary information corresponding to the byte information in each block of the public chain, and the synchronous verification initiating node inquires whether the summary information corresponding to the byte information at the specific position of the public chain is consistent with the summary information of the new transaction data provided by the user through the addressing information. Then, determining byte information of new transaction data corresponding to the addressing information from the public chain; calculating summary information of the new transaction data according to the byte information of the new transaction data; and when the summary information of the new transaction data is consistent with the summary information of the new transaction data, determining that byte information corresponding to the summary information exists in the public chain.
When the synchronous verification initiating node provides the data synchronous verification service, the method further comprises the steps of creating the intelligent contract at the head node of the public chain, and setting other T-1 nodes to access the intelligent contract by the local address library, wherein the access permission comprises read permission and write permission. In this way, the private data may be managed by the smart contract, configuring the corresponding access permissions. The smart contract is then encrypted at the head-node using the public key and the encrypted smart contract is included in the chunk data at the head-node. And then may be sent to other nodes on the public chain. In this way, the intelligent contract is ensured to be stored on the public chain in a ciphertext mode, all nodes can be backed up, and the backup risk caused by the limitation of the number of the nodes does not exist.
The public key is distributed at the head node to the other T-1 nodes of the public chain according to the local address base, and then the block data is sent to the other T-1 nodes. Preferably, the public key and the chunk data are received at the other T-1 nodes, and the encrypted smart contract is decrypted from the chunk data using the public key to create a decrypted smart contract. Or to execute the transaction according to the decrypted smart contract.
In this way, after the intelligent contract is created at the head node and the encrypted intelligent contract is included in the block data at the head node, other nodes on the public chain can receive the block data, namely, all the nodes can be synchronized, but only the node which possesses the public key of the intelligent contract can decrypt and execute corresponding transaction, thereby realizing the function of protecting the data on the public chain.
In the above data consensus process, it is preferable to perform the transaction data digest formed from the block ID, the contract ID of the smart contract, and the historical transaction data of the smart contract. To obtain the block ID and the intelligent contract ID, the historical transaction data and the current state of each intelligent contract are logically isolated when stored. After executing any transaction, inserting a record with the block ID and the intelligent contract ID as key values into the logic database of the intelligent contract so as to be used for subsequent consensus completion. Accordingly, historical transaction data and a current state of the smart contract may be stored in logical isolation in a database, the current state of the smart contract being queried according to the block ID stored in the database and the smart contract ID of the smart contract.
After the synchronous verification result is obtained, if the block data in the public chain is determined to be in error, the following method is adopted for correction: receiving a data correction request aiming at the block data in the current public chain, wherein the data correction request comprises: the position information of the error data to be corrected in the public chain, and the replacement data after the error data is corrected. The error data is used as the data to be corrected, and the error data may be only the corrected data or a transaction data packet including the corrected data.
For convenience of data management, when receiving and processing data correction requests, the data correction requests are processed one by taking byte information in block data existing in a public chain as a unit, that is, each received data correction request only contains a data correction request aiming at one byte information.
Specifically, when the public chain manager needs to correct the block data of the block in the public chain, the location information of the error data to be corrected in the public chain may be input to the system, and the location information may specifically be the block ID where the error data is located and the data ID of the error data in the block data of the block. The correction of the transaction data in a byte of information is determined when data correction is decided, and when data correction is specifically performed, only the position information of the corrected data, namely error data, in the public chain needs to be locked.
Then, modifying error data in the public chain into replacement data; specifically, according to the position information of the error data in the public chain included in the data correction request, the data at the corresponding position is modified into the replacement data, and then the modification of the data can be realized. Generating a correction report according to the data correction request, wherein the correction report comprises position information of the error data in the public chain in the associated storage and replacement data after the error data are corrected; and the two information are related and stored to form a correction report. Optionally, the correction report may further include time information generated by the current correction report.
And storing the correction report for correcting the public chain each time, checking the public chain by combining the correction report when checking the transaction information recorded in the public chain, and forcibly verifying the consistency of the block modified by the data in the public chain according to the content of the correction report.
For block metadata, to prevent security issues due to the use of a single node to store metadata, assume that there is a transaction set SC={c1,c2,…,cmAnd e, summarizing set S corresponding to each transactionAbs={abs1,abs2,…,absm},SF={f1,f2,…,fmFor each transaction the data set to be stored, SP={pabs1,pabs2,…,pabsmPosition information of each abstract data stored in a public chain system can be obtained through a first node, and SV is { n ═ n }1 v,n2 v,n3 v,…,ns vAnd the synchronization verification initiating node is used as the synchronization verification initiating node. The process of storing metadata includes the steps of:
(1) calculating abstract of data to be stored to obtain data SF ═ tone<fabs1,abs1>,<fabs2,abs2>,…,<fabsm,absm>Store it in a public chain, where fabsiRepresenting a transaction ciSummarized data of which 0<i≤m。
(2) And sending the SF' to all synchronous verification initiating nodes SV, verifying the summary information of each transaction by the synchronous verification initiating nodes and verifying the broadcast messages bct of all nodes with the summary information. And other synchronous verification initiating nodes terminate the current verification process after receiving the bct and wait for the next verification. Meanwhile, the synchronous verification initiating node obtains a recording authority which is recorded as n'v。
(3)n'vObtaining the position information SP of all data in SF' from the head node, passing through the metadata SM={<abs1,pabs1>,<abs2,pabs2>,…,<absm,pabsm>Construct an element numberAnd writing the metadata block into the node internal public chain finally according to the data block MB.
(4)n'vThe MB is recorded to the global public chain. After successful recording, n'vAnd broadcasting a message bct to inform other synchronous verification initiating nodes of the internal public link state of the synchronous node.
Wherein all synchronous verification initiating nodes SVSimultaneously collecting summary information S of all transactions in a given time periodAbsAnd data copy information, in the process of verifying the abstract, the node which completes the verification of all the transaction abstract information firstly can obtain the recording authority, and the other nodes are informed by broadcasting information. If the synchronous verification initiating node of the recording authority is not obtained, the current operation is terminated, and the request in the next time period is waited.
Based on the anti-tampering characteristic of the public chain, after the metadata is stored in the public chain, the transaction party sends a verification request to the synchronous verification initiating node at any time to verify the integrity of the data. In addition, if the head node makes an error, the metadata can also be recovered by reading the global public chain. The metadata verification process queries the metadata public chain through the transaction abstract by the following steps:
(1) extract information abscAnd sending the data to all the synchronous verification initiating nodes SV.
(2) Each synchronization verification initiating node niv, where i ∈ [1, s ]]Firstly, whether the local metadata public link state is consistent with the global state is checked, if so, the position information p corresponding to the abstract information absc is inquired in the node public linkfabsc(ii) a Otherwise, if the states are not consistent, the internal public link of the node is updated first and then the query is carried out.
(3) When more than half of the synchronous verification initiating nodes inquire the same result, the verification result is returned to the transaction party, meanwhile, a message bct is broadcasted, and other synchronous verification initiating nodes which do not finish the inquiry terminate the current inquiry process after receiving the bct.
In the metadata verification stage, all synchronous verification initiating nodes are also in a cooperative relationship, namely the synchronous verification initiating node which inquires the position information firstly returns the result to the transaction party.
In order to realize the inter-node authentication of a transaction party, a root contract in an intelligent contract is added into a public chain after being approved. And the root contract added into the public chain is used as a node to self-generate a root contract public chain certificate, and the hash value of the intelligent contract is recorded into the public chain and is used as a trust certificate. And inquiring and verifying the trust certificate stored on the public chain by the synchronous verification initiating node. The public chain certificate is self-generated by a root contract that permits multiple domains to join the public chain and is posted to the public chain. Preferably, the name of the transactor type and the creator type is added to the digital certificate. After the transaction party realizes the inter-node authentication, the authentication type root contract generates a certificate for the transaction party requesting the authentication and transmits the certificate to the user, and the certificate is recorded into a public chain in a hash value mode, so that the quick authentication is provided when the user accesses again. The synchronous verification initiating node replaces the process of verifying the intelligent contract by checking multiple types of trusted certificates in the public chain. According to the trust model, the system architecture and the public chain certificate, before the inter-node authentication based on the public chain is started, the hash value and the write state of each type of root contract are already stored in the block of the public chain.
In summary, the present invention provides a data synchronization method based on blocks, which utilizes a public link system to implement data synchronization verification between blocks and quickly correct errors in block data.
It will be apparent to those skilled in the art that the modules or steps of the invention described above may be implemented in a general purpose computing system, centralized on a single computing system, or distributed across a network of computing systems, and optionally implemented in program code that is executable by the computing system, such that the program code is stored in a storage system and executed by the computing system. Thus, the present invention is not limited to any specific combination of hardware and software.
It is to be understood that the above-described embodiments of the present invention are merely illustrative of or explaining the principles of the invention and are not to be construed as limiting the invention. Therefore, any modification, equivalent replacement, improvement and the like made without departing from the spirit and scope of the present invention should be included in the protection scope of the present invention. Further, it is intended that the appended claims cover all such variations and modifications as fall within the scope and boundaries of the appended claims or the equivalents of such scope and boundaries.