Data synchronization method and device based on block chain, and electronic equipment
By employing a blockchain-based data synchronization method, utilizing smart contracts and a two-phase commit protocol, and combining sliding window hash chains and distributed indexing technology, the problem of data synchronization accuracy in mixed data scenarios with host and distributed architectures is solved, achieving zero-error accounting of financial transactions and rapid breakpoint location and conflict repair.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- INDUSTRIAL AND COMMERCIAL BANK OF CHINA
- Filing Date
- 2025-12-15
- Publication Date
- 2026-04-17
AI Technical Summary
In scenarios involving a mix of host and distributed architectures, existing technologies suffer from low data synchronization accuracy, and real-time financial transaction synchronization is prone to interruption due to network latency, requiring manual intervention to locate breakpoints and affecting the accuracy of data synchronization.
A blockchain-based data synchronization method is adopted. By acquiring the historical full data and incremental transaction data of the host system, and using preset storage and verification strategies, the data is stored in the blockchain. The data is verified using smart contracts and a two-phase commit protocol, and a rollback instruction is triggered to ensure the atomicity and consistency of data synchronization. The sliding window hash chain and distributed index technology are combined to locate breakpoints, and greedy algorithms and cosine similarity algorithms are used to repair conflicting transactions.
It improves the accuracy and efficiency of data synchronization, reduces the data error rate, achieves zero-error accounting, ensures the reliability and consistency of financial transactions, and reduces the time for human intervention and potential errors.
Smart Images

Figure CN121880460A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of blockchain technology, and more specifically, to a data synchronization method, apparatus, and electronic device based on blockchain. Background Technology
[0002] In scenarios involving a mix of host and distributed architecture data, current financial institutions primarily store historical transaction records from the host into the consortium blockchain after hashing them as a whole. However, this only solves the problem of historical data storage and does not cover the synchronization of real-time financial transactions. Furthermore, the synchronization of real-time financial transactions is prone to interruption due to network latency. After an interruption occurs, manual intervention is required to locate the breakpoint, which affects the accuracy of data synchronization.
[0003] There is currently no effective solution to the above problems. Summary of the Invention
[0004] This invention provides a data synchronization method, apparatus, and electronic device based on blockchain, to at least solve the technical problem of low data synchronization accuracy in scenarios with mixed host and distributed architecture data in related technologies.
[0005] According to one aspect of the embodiments of this application, a data synchronization method based on blockchain is provided. The blockchain includes at least multiple distributed nodes. The data synchronization method includes: acquiring historical full data and current multiple incremental transaction data of the host system, and storing the historical full data and all incremental transaction data in the blockchain using a preset storage strategy; verifying each incremental transaction data using a preset verification strategy to obtain a verification result, wherein the preset verification strategy is constructed based on smart contracts and a two-phase commit protocol. The two-phase commit protocol is a transaction coordination mechanism for multiple distributed nodes. The verification result includes: the result of each distributed node and the host system executing local transactions based on each incremental transaction data; if the verification result indicates that any distributed node has failed to execute a local transaction, triggering a rollback instruction to control all distributed nodes and the host system to roll back the local transactions and complete data synchronization.
[0006] Furthermore, the step of storing historical full data and all incremental transaction data to the blockchain using a preset storage strategy includes: slicing the historical full data based on a preset time window to obtain multiple slice data; calculating the hash value of each slice data and transmitting all hash values to the blockchain for storage; calculating the incremental hash value of each incremental transaction data and broadcasting all incremental hash values to all distributed nodes, wherein the distributed nodes store all incremental hash values in their local queues and submit all incremental hash values in their local queues to the blockchain; concatenating all hash values with all incremental hash values to obtain the target hash value and storing the target hash value to the blockchain.
[0007] Furthermore, the steps of verifying each incremental transaction data using a preset verification strategy to obtain the verification result include: for each incremental transaction data, determining the transaction corresponding to the incremental transaction data, and verifying the transaction based on the smart contract; if the transaction verification passes, controlling each distributed node to execute a local transaction with the host system to obtain the verification result.
[0008] Furthermore, after calculating the incremental hash value of each incremental transaction data, the process also includes: generating a transaction sequence number for each transaction corresponding to each incremental transaction data; performing hash calculations on all incremental hash values within a preset window length to generate multiple window hash values, where each window hash value corresponds to a range of transaction sequence numbers; generating an index table based on all window hash values and the range of transaction sequence numbers corresponding to each window hash value; concatenating all window hash values based on a preset concatenation strategy to generate multiple hash chains; and transmitting the index table and all hash chains to the blockchain for storage.
[0009] Furthermore, after triggering the rollback instruction, the process also includes: monitoring the preset environment state when the rollback instruction is triggered; and, if the preset environment state indicates that there is a transaction data synchronization interruption, determining the interrupted transaction based on the index table and hash chain.
[0010] Furthermore, the steps for identifying interrupted transactions based on the index table and hash chains include: recalculating the incremental hash value of each incremental transaction data, and regenerating multiple hash chains based on all incremental hash values, representing each hash chain as a local hash chain; for each local hash chain, determining the corresponding hash chain in the blockchain, and comparing the local hash chain with the hash chain; in the case where the local hash chain differs from the hash chain, determining the local hash chain as the target hash chain; based on the target hash chain, determining the target window hash value, and identifying the interrupted transaction based on the target window hash value and the index table.
[0011] Furthermore, after triggering the rollback instruction, the process includes: determining whether conflicting transactions exist, where a conflicting transaction refers to a transaction for the same transaction account that has at least two different records on different distributed nodes at the same point in time, and the records are determined based on the execution results of local transactions; obtaining preset fields of the conflicting transactions and encoding the preset fields to obtain transaction feature vectors; obtaining historical transaction data of the transaction account and encoding the historical transaction data to obtain historical transaction feature vectors; generating preset weights for each transaction feature vector, and for each transaction feature vector, using a cosine similarity algorithm based on the preset weights to calculate the conflict value between the historical transaction feature vector and the transaction feature vector; determining the target transaction based on a greedy algorithm and all conflict values; determining the transactions in the conflicting transactions other than the target transaction and generating reverse compensation feature vectors for the transactions; and determining a repair strategy based on the reverse compensation feature vectors, where the repair strategy is a strategy to adjust the balance of the transaction account.
[0012] According to another aspect of the embodiments of this application, a blockchain-based data synchronization device is also provided. The blockchain includes at least multiple distributed nodes. The data synchronization device includes: an acquisition unit, used to acquire the historical full data and multiple current incremental transaction data of the host system, and to store the historical full data and all incremental transaction data in the blockchain using a preset storage strategy; a verification unit, used to verify each incremental transaction data using a preset verification strategy to obtain a verification result, wherein the preset verification strategy is constructed based on smart contracts and a two-phase commit protocol. The two-phase commit protocol is a transaction coordination mechanism for multiple distributed nodes, and the verification result includes: the result of each distributed node and the host system executing local transactions based on each incremental transaction data; and a triggering unit, used to trigger a rollback instruction when the verification result indicates that any distributed node has failed to execute a local transaction, so as to control all distributed nodes and the host system to roll back the local transactions and complete the data synchronization.
[0013] Furthermore, the acquisition unit includes: a first slicing module, used to slice the historical full data based on a preset time window to obtain multiple slice data; a first calculation module, used to calculate the hash value of each slice data and transmit all hash values to the blockchain for storage; a second calculation module, used to calculate the incremental hash value of each incremental transaction data and broadcast all incremental hash values to all distributed nodes, wherein the distributed nodes store all incremental hash values in their local queues and submit all incremental hash values in their local queues to the blockchain; and a first concatenation module, used to concatenate all hash values with all incremental hash values to obtain a target hash value and store the target hash value in the blockchain.
[0014] Furthermore, the verification unit includes: a first verification module, used to determine the transaction corresponding to each incremental transaction data and verify the transaction based on a smart contract; and a first control module, used to control each distributed node and the host system to execute local transactions and obtain verification results when the transaction verification is successful.
[0015] Furthermore, the blockchain-based data synchronization device also includes: a first generation module, used to generate a transaction sequence number for each incremental transaction data after calculating the incremental hash value of each incremental transaction data; a third calculation module, used to perform hash calculation on all incremental hash values within a preset window length to generate multiple window hash values, wherein each window hash value corresponds to a range of transaction sequence numbers; a second generation module, used to generate an index table based on all window hash values and the range of transaction sequence numbers corresponding to each window hash value; a second concatenation module, used to concatenate all window hash values based on a preset concatenation strategy to generate multiple hash chains; and a first transmission module, used to transmit the index table and all hash chains to the blockchain for storage.
[0016] Furthermore, the blockchain-based data synchronization device also includes: a first monitoring module, used to monitor the preset environment state when the rollback instruction is triggered after the rollback instruction is triggered; and a second determination module, used to determine the interrupted transaction based on the index table and hash chain when the preset environment state indicates that there is a transaction data synchronization interruption.
[0017] Further, the second determining module includes: a first calculation submodule, used to recalculate the incremental hash value of each incremental transaction data, and regenerate multiple hash chains based on all incremental hash values, representing the hash chains as local hash chains; a first comparison submodule, used to determine the corresponding hash chain in the blockchain for each local hash chain, and compare the local hash chain with the hash chain; a first determining submodule, used to determine the local hash chain as the target hash chain when there is a difference between the local hash chain and the hash chain; and a second determining submodule, used to determine the target window hash value based on the target hash chain, and determine the interrupted transactions based on the target window hash value and the index table.
[0018] Furthermore, the blockchain-based data synchronization device also includes: a first judgment module, used to determine whether conflicting transactions exist after triggering a rollback instruction, wherein a conflicting transaction refers to a transaction for the same transaction account with at least two different records on different distributed nodes at the same point in time, the records being determined based on the execution result of local transactions; a first encoding module, used to obtain preset fields of conflicting transactions and encode the preset fields to obtain transaction feature vectors; a second encoding module, used to obtain historical transaction data of the transaction account and encode the historical transaction data to obtain historical transaction feature vectors; a third generation module, used to generate preset weights for each transaction feature vector, and for each transaction feature vector, based on the preset weights, using a cosine similarity algorithm to calculate the conflict value between historical transaction feature vectors and transaction feature vectors; a third determination module, used to determine the target transaction based on a greedy algorithm and all conflict values; and a fourth generation module, used to determine transactions other than the target transaction in the conflicting transactions, and generate reverse compensation feature vectors for the transactions, and based on the reverse compensation feature vectors, determine a repair strategy, wherein the repair strategy is a strategy for adjusting the balance of the transaction account.
[0019] According to another aspect of the embodiments of this application, a computer program product is also provided, including a non-volatile computer-readable storage medium storing a computer program, which, when executed by a processor, implements any of the above-described blockchain-based data synchronization methods.
[0020] According to another aspect of the embodiments of this application, an electronic device is also provided, including one or more processors and a memory, the memory being used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors cause the one or more processors to implement any of the above-described blockchain-based data synchronization methods.
[0021] In this invention, the historical full data of the host system and multiple current incremental transaction data are obtained. A preset storage strategy is adopted to store the historical full data and all incremental transaction data in the blockchain. A preset verification strategy is adopted to verify each incremental transaction data and obtain the verification result. If the verification result indicates that any distributed node has failed to execute a local transaction, a rollback instruction is triggered to control all distributed nodes and the host system to roll back the local transaction and complete the data synchronization. This solves the technical problem of low data synchronization accuracy in scenarios with mixed data in host and distributed architectures in related technologies.
[0022] In this invention, the blockchain network consists of multiple distributed nodes. A preset storage strategy can be adopted to store the host system's historical full data and all incremental transaction data on the blockchain. Then, a preset verification strategy based on smart contracts and a two-phase commit protocol can be used to verify each incremental transaction. The smart contract can automatically verify the legality and rationality of the transaction, while the two-phase commit protocol serves as the cornerstone for transaction coordination among multiple distributed nodes. It can monitor the execution of local transactions by each distributed node and the host system, generating verification results. The verification results reflect the success or failure of each distributed node and host in executing local transactions based on the incremental transaction data. If the verification result indicates that any distributed node has failed to execute a local transaction, a rollback instruction is triggered to control all distributed nodes and the host system to roll back their local transactions, completing data synchronization. This ensures the atomicity and consistency of data synchronization, avoids the risk of data breakage or inconsistency, and improves the accuracy of data synchronization. Attached Figure Description
[0023] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this invention, illustrate exemplary embodiments of the invention and are used to explain the invention, but do not constitute an undue limitation of the invention. In the drawings:
[0024] Figure 1 A hardware structure block diagram of a computer terminal (or mobile device) for implementing a blockchain-based data synchronization method is shown.
[0025] Figure 2 This is a flowchart of a blockchain-based data synchronization method according to Embodiment 1 of this application;
[0026] Figure 3 This is a schematic diagram of an optional blockchain-based data synchronization system according to an embodiment of this application;
[0027] Figure 4 This is a schematic diagram of an optional blockchain-based data synchronization device according to an embodiment of this application;
[0028] Figure 5 This is a structural block diagram of an electronic device according to an embodiment of this application. Detailed Implementation
[0029] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0030] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0031] It should be noted that all related information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, and displayed data) collected and involved in this invention are information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, storage, use, processing, transmission, provision, disclosure, and application of related data all comply with the relevant laws, regulations, and standards of the relevant regions, and necessary confidentiality measures have been taken. These measures do not violate public order and good morals, and corresponding operation entry points are provided for users to choose to authorize or refuse. For example, this system has an interface with relevant users or organizations. Before obtaining relevant information, a request to obtain the information needs to be sent to the aforementioned user or organization through the interface. After receiving consent from the aforementioned user or organization, the relevant information is obtained. If the user chooses to refuse, the process proceeds to an expert decision-making process.
[0032] In this invention, a sliding window hash chain + distributed index technology can be used to replace the current single hash query, which can quickly locate the broken transaction. Furthermore, a vector space model and a greedy algorithm can be used to achieve pure data-driven conflict repair, which improves the speed and accuracy of breakpoint resume and conflict resolution during the synchronization process and ensures data consistency.
[0033] The present invention will now be described in detail with reference to various embodiments.
[0034] Example 1
[0035] According to an embodiment of this application, an embodiment of a data synchronization method based on blockchain is also provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0036] The method embodiment provided in Embodiment 1 of this application can be executed on a mobile terminal, computer terminal, or similar computing device. Figure 1 A hardware block diagram of a computer terminal (or mobile device) for implementing a blockchain-based data synchronization method is shown. Figure 1 As shown, computer terminal 10 (or mobile device) may include one or more ( Figure 1 The processor 102 (which may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.), a memory 104 for storing data, and a transmission device 106 for communication functions may also be included. In addition, it may include: a display, a keyboard, a cursor control device, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of a BUS bus), a network interface, a power supply, and / or a camera, wherein the network interface can be connected to wired and / or wireless networks. Those skilled in the art will understand that... Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the aforementioned electronic device. For example, computer terminal 10 may also include... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown.
[0037] It should be noted that the aforementioned one or more processors 102 and / or other data processing circuits are generally referred to herein as "data processing circuits". These data processing circuits may be embodied, in whole or in part, in software, hardware, firmware, or any other combination thereof. Furthermore, the data processing circuits may be a single, independent processing module, or may be integrated, in whole or in part, into any other element within the computer terminal 10 (or mobile device). As involved in the embodiments of this application, the data processing circuits serve as a processor control mechanism (e.g., selection of a variable resistor termination path connected to an interface).
[0038] The memory 104 can be used to store software programs and modules of application software, such as the program instructions / data storage device corresponding to the blockchain-based data synchronization method in this embodiment. The processor 102 executes various functional applications and data processing by running the software programs and modules stored in the memory 104, thereby realizing the aforementioned blockchain-based data synchronization method. The memory 104 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to the computer terminal 10 via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0039] The transmission device 106 is used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by the communication provider of the computer terminal 10. In one example, the transmission device 106 includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission device 106 may be a Radio Frequency (RF) module, used for wireless communication with the Internet.
[0040] The display may be, for example, a touchscreen liquid crystal display (LCD) that allows the user to interact with the user interface of the computer terminal 10 (or mobile device).
[0041] Under the aforementioned operating environment, this application provides the following: Figure 2 The data synchronization method based on blockchain is shown. Figure 2 This is a flowchart of a blockchain-based data synchronization method according to Embodiment 1 of this application, as follows: Figure 2 As shown, the method includes the following steps:
[0042] Step S201: Obtain the historical full data and current multiple incremental transaction data of the host system, and use a preset storage strategy to store the historical full data and all incremental transaction data in the blockchain.
[0043] In this embodiment of the invention, the historical full data is static data such as transaction records and customer information from previous years in the host system. It can be processed in the manner of "time window + hash slice" (e.g., one hash value is generated for every 10,000 transactions), generating the hash value of each slice, and storing it in the consortium blockchain notarization node to ensure that it is tamper-proof and traceable.
[0044] Incremental transaction data refers to real-time transaction data during migration (such as transfer requests). This data can be synchronized using a "producer-side switch broadcast + consumer-side multi-queue verification" mechanism. For example, when a transaction occurs, the producer broadcasts the transaction message data (including but not limited to transaction hashes) to all distributed nodes via the switch. The consumer controls the distributed nodes to receive the transaction hashes, store them in their local queues, and process them according to a first-in, first-out (FIFO) principle. After processing, the incremental hash (i.e., the transaction hash) is submitted to the blockchain. After synchronization, the incremental hash is concatenated with the historical hashes already stored on the chain (i.e., the hash values of all historical data) (e.g., historical hash + incremental hash) to generate a globally consistent verification value, which is then stored in the blockchain.
[0045] For example, migrating transaction data from 2020-2023 (historical full data) to real-time transactions in January 2024 (incremental data) can be achieved by generating a hash (e.g., H1, H2) for each quarterly historical transaction data and storing it in the consortium blockchain. The transaction hash of each real-time transaction (e.g., transfer request) can be broadcast to five distributed nodes via an exchange. After processing, the distributed nodes store the transaction hash (e.g., T1, T2) in their local queues and submit them to the blockchain sequentially. After the migration is complete, a global hash of "H1+H2+T1+T2" can be generated to ensure consistency between historical and incremental data.
[0046] Step S202: A preset verification strategy is adopted to verify each incremental transaction data and obtain the verification result. The preset verification strategy is built on smart contracts and a two-phase commit protocol. The two-phase commit protocol is a transaction coordination mechanism for multiple distributed nodes. The verification result includes the result of each distributed node and the host system executing local transactions based on each incremental transaction data.
[0047] In this embodiment of the invention, the preset verification strategy is to use smart contracts and a two-phase commit protocol to verify the legality and consistency of transactions. The two-phase commit protocol is a cross-node transaction coordination mechanism that ensures that all participants either complete the transaction or do not complete it, thereby maintaining data consistency.
[0048] By employing a preset verification strategy to verify each incremental transaction data, at least the results of each distributed node and the host system executing local transactions based on each incremental transaction data can be obtained (e.g., the balance of account A on the host is deducted, and the balance of account B on the node is increased to match the inflow of funds into account A).
[0049] Step S203: If the verification result indicates that any distributed node has failed to execute a local transaction, a rollback instruction is triggered to control all distributed nodes and the host system to roll back the local transaction and complete data synchronization.
[0050] In this embodiment of the invention, if any distributed node fails to execute a local transaction (e.g., due to a node network timeout leading to execution failure), the smart contract triggers a rollback instruction to roll back the local transaction and restore it to the previous state. Even if most distributed nodes execute successfully, the host and distributed nodes must synchronously revoke the local operation to avoid one-sided accounting and realize data migration and updates from the host system to the distributed architecture.
[0051] In summary, leveraging the immutability of blockchain, historical data can be stored through hash slicing, and real-time data can be verified and uploaded to the chain via broadcasting, ensuring data integrity and consistency. Furthermore, smart contracts automatically execute pre-verification and synchronous confirmation, and in conjunction with a two-phase commit protocol, a consistency adaptation mechanism for financial transactions is constructed. This mechanism can guarantee zero-error accounting in scenarios such as transfers and settlements, and achieve the correlation and synchronization of historical full data and real-time incremental data. This improves the efficiency and accuracy of data synchronization, reduces the data error rate, and thus solves the technical problem of low data synchronization accuracy in scenarios with mixed host and distributed architectures.
[0052] To accurately obtain the target hash value, the blockchain-based data synchronization method provided in Embodiment 1 of this application slices the historical full data based on a preset time window to obtain multiple slice data; calculates the hash value of each slice data and transmits all hash values to the blockchain for storage; calculates the incremental hash value of each incremental transaction data and broadcasts all incremental hash values to all distributed nodes, wherein the distributed nodes store all incremental hash values in their local queues and submit all incremental hash values in their local queues to the blockchain; and concatenates all hash values with all incremental hash values to obtain the target hash value, which is then stored in the blockchain.
[0053] In this embodiment of the invention, the historical full data in the host system can be decomposed into smaller segments that are easier to manage. For example, the transaction records of the past three years can be sliced according to a preset time window (e.g., each quarter as the window time). Each window data contains all transaction records within that time period. For example, the transaction records of the first quarter are sliced into the first data packet, and the following three time windows are processed in the same way. Each slice data will undergo subsequent hash calculation independently, that is, the hash value of each slice data will be calculated, and all hash values will be transmitted to the blockchain for storage.
[0054] For real-time incremental transaction data, such as currently ongoing transfer requests, different processing strategies are employed. On the production side, the incremental hash value of each incremental transaction is calculated, and all incremental hash values are broadcast to all distributed nodes. Upon receiving the incremental hash, the distributed nodes on the consumption side store it in their respective local queues to ensure orderly data processing. For example, when a transfer occurs, its transaction details and incremental hash value are broadcast to five distributed nodes, each storing the incremental hash value of this transaction. Each distributed node can submit these hash values to the blockchain and can concatenate the hash values of all historical data with the incremental hash values of all incremental transaction data to obtain a target hash value (i.e., a globally consistent verification value), which is then stored in the blockchain. These steps not only leverage the immutability of the blockchain to protect historical data but also employ efficient incremental data broadcasting and local queue processing strategies to ensure rapid response to real-time transactions. Furthermore, through hash concatenation and consistency verification, the integrity and consistency of data when migrating from the host system to the distributed architecture are improved, reducing the risk of data loss and enhancing the reliability of financial transactions.
[0055] In order to obtain accurate verification results, in the blockchain-based data synchronization method provided in Embodiment 1 of this application, for each incremental transaction data, the transaction corresponding to the incremental transaction data is determined, and the transaction is verified based on the smart contract; if the transaction verification is successful, each distributed node is controlled to execute local transactions with the host system to obtain the verification result.
[0056] In this embodiment of the invention, it is necessary to determine the transaction corresponding to the incremental transaction data (e.g., a new transfer request) (e.g., a transfer of 1000 yuan from account A to account B), and based on a smart contract, pre-verify the transaction to verify its legality, including: verifying whether account A has sufficient balance to pay 1000 yuan, whether account B exists, and whether the information of the two parties matches. The pre-set logic in the smart contract can automatically execute these checks without manual intervention, improving the efficiency and accuracy of transaction verification. If the transaction passes the smart contract verification, each distributed node and the host system are controlled to execute local transactions and obtain verification results (including successful and failed execution). Successful execution means that after all nodes have successfully executed the transaction, a "transaction confirmation" is submitted to the blockchain. Failed execution means that any node fails to execute the transaction (e.g., node network timeout), triggering a rollback instruction. The host and nodes synchronously revert their local operations, avoiding one-sided accounting.
[0057] To accurately locate interrupted transactions, an index table and hash chains need to be generated first. In the blockchain-based data synchronization method provided in Embodiment 1 of this application, a transaction sequence number is generated for each incremental transaction data; hash calculations are performed on all incremental hash values within a preset window length to generate multiple window hash values, where each window hash value corresponds to a range of transaction sequence numbers; an index table is generated based on all window hash values and the range of transaction sequence numbers corresponding to each window hash value; based on a preset concatenation strategy, all window hash values are concatenated to generate multiple hash chains; and the index table and all hash chains are transmitted to the blockchain for storage.
[0058] In this embodiment of the invention, for each incremental transaction data corresponding to a transaction, a unique transaction sequence number can be automatically assigned as the identifier of that transaction. Furthermore, incremental hash values can be aggregated using a preset window length (e.g., 100 transactions) to generate a single window hash value. This not only improves data processing efficiency but also reduces the storage burden on the blockchain. For example, all incremental hash values from transaction sequence numbers 1 to 100 can be calculated as a single window hash value H1, all incremental hash values from transaction sequence numbers 101 to 200 can be calculated as a single window hash value H2, and all incremental hash values from transaction sequence numbers 201 to 300 can be calculated as a single window hash value H3, and so on.
[0059] Based on all window hash values and the transaction sequence range corresponding to each window hash value, an index table can be constructed for quickly locating transactions or breakpoints. Then, based on a preset concatenation strategy, all window hash values are concatenated to generate multiple hash chains. For example, window 1 (transactions 1-100, H1), window 2 (101-200, H2), and window 3 (201-300, H3) form chain hash 1-3, where 1-3 = H1 + H2 + H3. Window 4 (301-400, H4), window 5 (401-500, H5), and window 6 (501-600, H6) form chain hash 4-6, where 4-6 = H4 + H5 + H6.
[0060] Optionally, the index table can use distributed storage (e.g., each node stores 1 / 5 of the data) to support parallel queries.
[0061] In order to accurately identify the interrupted transaction, the blockchain-based data synchronization method provided in Embodiment 1 of this application monitors the preset environment state when the rollback instruction is triggered; when the preset environment state indicates that there is an interruption in transaction data synchronization, the interrupted transaction is determined based on the index table and the hash chain.
[0062] In this embodiment of the invention, the preset environment state includes, but is not limited to, the state of the distributed nodes when the rollback instruction is triggered, the transaction sequence state, and the network status. By continuously monitoring the preset environment state, if the preset environment state indicates that there is a transaction data synchronization interruption (e.g., network interruption), the rollback mechanism is immediately initiated. Based on the index table and hash chain, the interrupted transaction can be determined. That is, by querying the matching degree of the hash chain, the window where the failure point is located (e.g., H2) can be quickly located. Then, the specific transaction sequence number (e.g., 150) can be retrieved by looking up the index table, thus achieving precise location of the breakpoint and avoiding the time required for manual intervention and potential human error.
[0063] To improve the accuracy of identifying interrupted transactions, the blockchain-based data synchronization method provided in Embodiment 1 of this application recalculates the incremental hash value of each incremental transaction data, and regenerates multiple hash chains based on all incremental hash values, representing each hash chain as a local hash chain. For each local hash chain, the corresponding hash chain in the blockchain is determined, and the local hash chain is compared with the target hash chain. If the local hash chain differs from the target hash chain, the local hash chain is determined as the target hash chain. Based on the target hash chain, the target window hash value is determined, and based on the target window hash value and the index table, the interrupted transaction is identified.
[0064] In this embodiment of the invention, after a data synchronization interruption is detected, the incremental hash value of each incremental transaction data needs to be recalculated. Based on all incremental hash values, multiple hash chains are regenerated and represented as local hash chains. Using an index table, the chain segment in the blockchain corresponding to the local hash chain can be quickly found and determined. It is then checked whether the local hash chain is consistent with the hash chain on the blockchain, thereby determining whether any transactions were missed or abnormally processed during the synchronization process. If the local hash chain differs from the original hash chain, the local hash chain is determined as the target hash chain. The target window hash value can be determined based on the position where the target hash chain differs from the original hash chain. For example, if the target chain hashes 4-6 (H4+H5+H6) are different, the window hash values (e.g., comparing H4, H5, and H6) are compared to determine the target window hash value (e.g., H4). The interrupted transaction range can be located using the transaction sequence number range corresponding to each window hash value in the index table. By comparing the incremental hash values corresponding to each transaction one by one, the specific transaction can be located, shortening the interruption recovery time.
[0065] To accurately determine the repair strategy, the blockchain-based data synchronization method provided in Embodiment 1 of this application determines whether conflicting transactions exist. A conflicting transaction refers to a transaction for the same transaction account where at least two different records exist on different distributed nodes at the same point in time, and the records are determined based on the execution results of local transactions. Preset fields of the conflicting transactions are obtained and encoded to obtain transaction feature vectors. Historical transaction data of the transaction account is obtained and encoded to obtain historical transaction feature vectors. Preset weights are generated for each transaction feature vector, and for each transaction feature vector, a cosine similarity algorithm is used to calculate the conflict value between the historical transaction feature vector and the transaction feature vector based on the preset weights. A target transaction is determined based on a greedy algorithm and all conflict values. Transactions other than the target transaction in the conflicting transactions are determined, and reverse compensation feature vectors for these transactions are generated. A repair strategy is determined based on the reverse compensation feature vectors, where the repair strategy is a strategy to adjust the balance of the transaction account.
[0066] In this embodiment of the invention, conflicting transactions can be determined by checking whether there are different transaction records for the same account on at least different distributed nodes at the same point in time. Here, different transaction records refer to differences in core fields such as transaction amount and counterparty account. If conflicting transactions exist, it means that at least two different transaction operations were performed on account A at the same time, which may lead to inconsistencies in the account balance. For example, transactions a and b are for the same customer account. Transaction a transfers out 1500 yuan, and transaction b receives 500 yuan. On distributed node A, both transactions a and b successfully execute their local transactions, and customer A's account balance decreases by 1000 yuan. However, on distributed node B, transaction a successfully executes its local transaction, while transaction b fails, and customer A's account balance decreases by 1500 yuan.
[0067] Obtain preset fields of conflicting transactions, such as transaction amount, timestamp, account ID, message length, etc., and encode the preset fields (e.g., convert the timestamp to a Unix (an operating system) timestamp value, and retain two decimal places for the amount) to obtain transaction feature vectors (e.g., conflicting transaction T1 and conflicting transaction T2, T1 vector = [1000.00, 1672531200, 001, 256], T2 vector = [500.00, 1672531200, 001, 256]). Preset weights can be set for each preset field, that is, the importance of the preset field in the consistency of past transactions. For example, the weight of the transaction amount can be set to 0.9, and the weight of the timestamp can be 0.1. Based on preset weights, a cosine similarity algorithm is used to calculate the conflict value between the feature vectors of historical transactions and the feature vectors of each conflicting transaction. The lower the conflict value, the closer the transaction is to the historical transaction pattern, and vice versa. The historical transaction feature vector is obtained by encoding the historical transaction data (e.g., historical transaction data within a certain time period) of the account involved in the conflicting transaction. Then, a greedy algorithm selects the transaction with the lowest conflict value from all conflicting transactions as the target transaction and retains it. For non-target transactions, a reverse compensation feature vector is generated. For example, if T2 is a non-target transaction, its reverse compensation vector is N2 = [-500.00, 1672531200, 001, 0]. Based on the reverse compensation feature vector, an adjustment strategy for the account balance is automatically generated, bringing key fields such as the account balance back to a state consistent with the target transaction. The above steps intelligently determine which transaction to retain based on quantitative characteristics and historical transaction patterns, and generate reverse compensation strategies for the remaining transactions, ultimately achieving data consistency restoration and improving the efficiency of conflict recovery.
[0068] Figure 3 This is a schematic diagram of an optional blockchain-based data synchronization system according to an embodiment of this application, such as... Figure 3As shown, the data synchronization system includes: a data input layer, a core processing layer, a blockchain support layer, and an output layer. Among them, the data input layer serves as the starting point, providing two types of core data: historical full data (including historical transaction records, customer information, etc.) and real-time incremental data (including real-time transaction messages such as transfers and settlements). The core processing layer can implement multiple functions, such as layered data on-chaining, financial transaction consistency adaptation, and breakpoint resumption and conflict transaction repair. Specifically, it achieves layered data on-chaining by separately processing historical full data and real-time incremental data. This involves slicing historical full data based on time windows, calculating the slice hash value of the sliced historical full data, and uploading the slice hash value to the blockchain. The producer broadcasts the incremental hash value of real-time incremental data, and the consumer queue receives the incremental hash value and uploads it to the blockchain. It also achieves financial transaction consistency adaptation through pre-verification based on smart contracts and synchronous confirmation using 2PC (Two-Phase Commit Protocol). If any distributed node fails to execute a local transaction, all distributed nodes perform an abnormal rollback. Finally, it enables breakpoint resumption and conflict transaction repair by using a sliding window hash chain + distributed index to locate breakpoints and employing a vector space model + greedy algorithm for conflict detection and automatic repair. The blockchain support layer serves as the trust hub of the entire system. It stores historical hash values, incremental hashes, and global verification values (such as the concatenation of historical and incremental hashes). It also hosts smart contracts (for transaction verification), providing global data support for breakpoint location and consistency verification. At the output layer, the distributed node cluster receives synchronized data and completes local transaction processing, achieving data alignment between the host and the distributed architecture. It can also output consistency verification reports (e.g., global verification values, error rates, and repair time), meeting regulatory and business auditing requirements.
[0069] The blockchain-based data synchronization method provided in this application can achieve rapid response and accurate repair when interruptions occur through breakpoint location technology that combines sliding window hash chains and distributed indexes. It can also provide zero-error accounting guarantee for financial transactions by using a hybrid protocol of "smart contracts + two-phase commit", especially in scenarios with strong consistency requirements such as transfers and clearing. At the same time, it uses a conflict repair mechanism that combines vector space models and greedy algorithms. By comparing the quantitative encoding of transaction feature vectors with historical transaction patterns, it automatically selects target transactions and generates reverse compensation strategies, which solves the conflict problem in the data synchronization process, improves the efficiency and reliability of data synchronization, reduces the data error rate, and strengthens the consistency and security of financial transaction data.
[0070] It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases the steps shown or described may be executed in a different order than that shown here.
[0071] Example 2
[0072] This application also provides a blockchain-based data synchronization device. It should be noted that the blockchain-based data synchronization device of this application can be used to execute the blockchain-based data synchronization method provided in this application. The following describes the blockchain-based data synchronization device provided in this application.
[0073] According to an embodiment of this application, an apparatus for implementing the above-described blockchain-based data synchronization method is also provided. Figure 4 This is a schematic diagram of an optional blockchain-based data synchronization device according to an embodiment of this application, such as... Figure 4 As shown, the blockchain-based data synchronization device may include: an acquisition unit 40, a verification unit 41, and a triggering unit 42.
[0074] Among them, the acquisition unit 40 is used to acquire the historical full data and current multiple incremental transaction data of the host system, and to store the historical full data and all incremental transaction data to the blockchain using a preset storage strategy.
[0075] Verification unit 41 is used to verify each incremental transaction data using a preset verification strategy and obtain the verification result. The preset verification strategy is built on smart contracts and a two-phase commit protocol. The two-phase commit protocol is a transaction coordination mechanism for multiple distributed nodes. The verification result includes the result of each distributed node and the host system executing local transactions based on each incremental transaction data.
[0076] Triggering unit 42 is used to trigger a rollback instruction when the verification result indicates that any distributed node has failed to execute a local transaction, so as to control all distributed nodes and the host system to roll back the local transaction and complete data synchronization.
[0077] The blockchain-based data synchronization device provided in this application embodiment can acquire the historical full data and multiple current incremental transaction data of the host system through the acquisition unit 40, and store the historical full data and all incremental transaction data in the blockchain using a preset storage strategy. The verification unit 41 can verify each incremental transaction data using a preset verification strategy to obtain the verification result. The triggering unit 42 can trigger a rollback instruction when the verification result indicates that any distributed node has failed to execute a local transaction, so as to control all distributed nodes and the host system to roll back the local transaction and complete the data synchronization.
[0078] Optionally, the acquisition unit 40 includes: a first slicing module, used to slice the historical full data based on a preset time window to obtain multiple slice data; a first calculation module, used to calculate the hash value of each slice data and transmit all hash values to the blockchain for storage; a second calculation module, used to calculate the incremental hash value of each incremental transaction data and broadcast all incremental hash values to all distributed nodes, wherein the distributed nodes store all incremental hash values in their local queues and submit all incremental hash values in their local queues to the blockchain; and a first concatenation module, used to concatenate all hash values with all incremental hash values to obtain a target hash value and store the target hash value in the blockchain.
[0079] Optionally, the verification unit 41 includes: a first verification module, used to determine the transaction corresponding to each incremental transaction data and verify the transaction based on a smart contract; and a first control module, used to control each distributed node and the host system to execute local transactions to obtain the verification result when the transaction verification is successful.
[0080] Optionally, the blockchain-based data synchronization device further includes: a first generation module, used to generate a transaction sequence number for each incremental transaction data after calculating the incremental hash value of each incremental transaction data; a third calculation module, used to perform hash calculation on all incremental hash values within a preset window length to generate multiple window hash values, wherein each window hash value corresponds to a range of transaction sequence numbers; a second generation module, used to generate an index table based on all window hash values and the range of transaction sequence numbers corresponding to each window hash value; a second concatenation module, used to concatenate all window hash values based on a preset concatenation strategy to generate multiple hash chains; and a first transmission module, used to transmit the index table and all hash chains to the blockchain for storage.
[0081] Optionally, the blockchain-based data synchronization device further includes: a first monitoring module, used to monitor the preset environment state when the rollback instruction is triggered after the rollback instruction is triggered; and a second determination module, used to determine the interrupted transaction based on the index table and hash chain when the preset environment state indicates that there is a transaction data synchronization interruption.
[0082] Optionally, the second determining module includes: a first calculation submodule, used to recalculate the incremental hash value of each incremental transaction data, and regenerate multiple hash chains based on all incremental hash values, representing the hash chains as local hash chains; a first comparison submodule, used to determine the corresponding hash chain in the blockchain for each local hash chain, and compare the local hash chain with the hash chain; a first determining submodule, used to determine the local hash chain as the target hash chain when there are differences between the local hash chain and the hash chain; and a second determining submodule, used to determine the target window hash value based on the target hash chain, and determine the interrupted transactions based on the target window hash value and the index table.
[0083] Optionally, the blockchain-based data synchronization device further includes: a first judgment module, used to determine whether there are conflicting transactions after triggering a rollback instruction, wherein a conflicting transaction refers to a transaction for the same transaction account that has at least two different records on different distributed nodes at the same point in time, and the records are determined based on the execution result of local transactions; a first encoding module, used to obtain preset fields of conflicting transactions and encode the preset fields to obtain transaction feature vectors; a second encoding module, used to obtain historical transaction data of the transaction account and encode the historical transaction data to obtain historical transaction feature vectors; a third generation module, used to generate preset weights for each transaction feature vector, and for each transaction feature vector, based on the preset weights, use a cosine similarity algorithm to calculate the conflict value between the historical transaction feature vector and the transaction feature vector; a third determination module, used to determine the target transaction based on a greedy algorithm and all conflict values; and a fourth generation module, used to determine the transactions other than the target transaction in the conflicting transactions, and generate reverse compensation feature vectors for the transactions, and determine a repair strategy based on the reverse compensation feature vectors, wherein the repair strategy is a strategy for adjusting the balance of the transaction account.
[0084] The aforementioned blockchain-based data synchronization device may also include a processor and a memory. The aforementioned acquisition unit 40, verification unit 41, triggering unit 42, etc., are all stored in the memory as program units, and the processor executes the aforementioned program units stored in the memory to realize the corresponding functions.
[0085] The aforementioned processor contains a kernel, which retrieves the corresponding program units from memory. One or more kernels can be configured, and by adjusting kernel parameters, a rollback instruction can be triggered if the verification result indicates that any distributed node has failed to execute a local transaction. This controls all distributed nodes and the host system to roll back their local transactions, thus completing data synchronization.
[0086] The aforementioned memory may include non-permanent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0087] It should be noted that the acquisition unit 40, verification unit 41, and triggering unit 42 mentioned above correspond to steps S201 to S203 in Embodiment 1. The instances and application scenarios implemented by the above units and corresponding steps are the same, but are not limited to the content disclosed in Embodiment 1. It should be noted that the above units can be hardware or software components stored in memory (e.g., memory 104) and processed by one or more processors (e.g., processors 102a, 102b, ..., 102n). The above units can also be part of the device and run in the computer terminal 10 provided in Embodiment 1.
[0088] Example 3
[0089] Embodiments of this application may provide a computer terminal, which may be any computer terminal device in a group of computer terminals. Optionally, in this embodiment, the aforementioned computer terminal may also be replaced with a mobile terminal or an electronic device, etc.
[0090] Optionally, in this embodiment, the computer terminal may be located in at least one of a plurality of network devices in a computer network.
[0091] In this embodiment, the aforementioned computer terminal can execute the program code for the following steps in the blockchain-based data synchronization method: acquiring the historical full data and current multiple incremental transaction data of the host system, and storing the historical full data and all incremental transaction data in the blockchain using a preset storage strategy; verifying each incremental transaction data using a preset verification strategy to obtain a verification result, wherein the preset verification strategy is built based on smart contracts and a two-phase commit protocol, the two-phase commit protocol is a transaction coordination mechanism for multiple distributed nodes, and the verification result includes: the result of each distributed node and the host system executing local transactions based on each incremental transaction data; if the verification result indicates that any distributed node has failed to execute a local transaction, triggering a rollback instruction to control all distributed nodes and the host system to roll back the local transactions and complete data synchronization.
[0092] Optionally, the aforementioned computer terminal can execute the following steps in the blockchain-based data synchronization method: slice the historical full data based on a preset time window to obtain multiple slice data; calculate the hash value of each slice data and transmit all hash values to the blockchain for storage; calculate the incremental hash value of each incremental transaction data and broadcast all incremental hash values to all distributed nodes, wherein the distributed nodes store all incremental hash values in their local queues and submit all incremental hash values in their local queues to the blockchain; concatenate all hash values with all incremental hash values to obtain the target hash value and store the target hash value in the blockchain.
[0093] Optionally, the aforementioned computer terminal can execute program code for the following steps in the blockchain-based data synchronization method: for each incremental transaction data, determine the transaction corresponding to the incremental transaction data, and verify the transaction based on a smart contract; if the transaction verification is successful, control each distributed node to execute local transactions with the host system to obtain the verification result.
[0094] Optionally, the aforementioned computer terminal can execute program code for the following steps in the blockchain-based data synchronization method: generating a transaction sequence number for each incremental transaction data corresponding to the transaction; performing hash calculations on all incremental hash values within a preset window length to generate multiple window hash values, wherein each window hash value corresponds to a range of transaction sequence numbers; generating an index table based on all window hash values and the range of transaction sequence numbers corresponding to each window hash value; concatenating all window hash values based on a preset concatenation strategy to generate multiple hash chains; and transmitting the index table and all hash chains to the blockchain for storage.
[0095] Optionally, the aforementioned computer terminal can execute program code for the following steps in the blockchain-based data synchronization method: monitoring the preset environment state when a rollback instruction is triggered; and, if the preset environment state indicates that transaction data synchronization is interrupted, determining the interrupted transaction based on the index table and hash chain.
[0096] Optionally, the aforementioned computer terminal may execute program code for the following steps in the blockchain-based data synchronization method: recalculating the incremental hash value of each incremental transaction data, and regenerating multiple hash chains based on all incremental hash values, representing the hash chains as local hash chains; for each local hash chain, determining the corresponding hash chain in the blockchain, and comparing the local hash chain with the hash chain; in the case where the local hash chain is different from the hash chain, determining the local hash chain as the target hash chain; based on the target hash chain, determining the target window hash value, and based on the target window hash value and the index table, determining the interrupted transactions.
[0097] Optionally, the aforementioned computer terminal can execute program code for the following steps in the blockchain-based data synchronization method: determining whether conflicting transactions exist, wherein a conflicting transaction refers to a transaction for the same transaction account that has at least two different records on different distributed nodes at the same point in time, the records being determined based on the execution result of local transactions; obtaining preset fields of the conflicting transactions and encoding the preset fields to obtain transaction feature vectors; obtaining historical transaction data of the transaction account and encoding the historical transaction data to obtain historical transaction feature vectors; generating preset weights for each transaction feature vector, and for each transaction feature vector, using a cosine similarity algorithm based on the preset weights to calculate the conflict value between the historical transaction feature vector and the transaction feature vector; determining the target transaction based on a greedy algorithm and all conflict values; determining the transactions other than the target transaction among the conflicting transactions and generating reverse compensation feature vectors for the transactions; and determining a repair strategy based on the reverse compensation feature vectors, wherein the repair strategy is a strategy for adjusting the balance of the transaction account.
[0098] Optionally, Figure 5 This is a structural block diagram of an electronic device according to an embodiment of this application. Figure 5 As shown, the electronic device may include: one or more ( Figure 5 (Only one is shown) processor 502, memory 504, memory controller, and peripheral interface, wherein the peripheral interface is connected to the radio frequency module, audio module and display.
[0099] The memory can be used to store software programs and modules, such as the program instructions / modules corresponding to the blockchain-based data synchronization method and apparatus in this application embodiment. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory, thereby realizing the aforementioned blockchain-based data synchronization method. The memory may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory may further include memory remotely located relative to the processor, and these remote memories can be connected to the terminal via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0100] The processor can access the information and applications stored in the memory via the transmission device to execute the steps described above in the blockchain-based data synchronization method.
[0101] The embodiments of this application provide a blockchain-based data synchronization method. By employing a data layering and on-chain strategy, a smart contract-assisted transaction consistency mechanism, and a conflict resolution technology using a sliding window hash chain and a vector space model, accurate and efficient synchronization of historical full data and real-time incremental data can be achieved in mixed data scenarios with host and distributed architectures. This achieves strong data consistency and high integrity, thereby solving the technical problem of low data synchronization accuracy in mixed data scenarios with host and distributed architectures in related technologies.
[0102] Those skilled in the art will understand that Figure 5 The structure shown is for illustrative purposes only. Electronic devices can also be terminal devices such as smartphones, tablets, PDAs, and mobile internet devices (MIDs). Figure 5 This does not limit the structure of the aforementioned electronic device. For example, electronic devices may also include components that are more... Figure 5 The more or fewer components shown (such as network interfaces, display devices, etc.), or having the same Figure 5 The different configurations shown.
[0103] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be implemented by a program instructing the hardware related to the terminal device. The program can be stored in a computer-readable storage medium, which may include: flash drive, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.
[0104] Example 4
[0105] Embodiments of this application also provide a storage medium. Optionally, in this embodiment, the storage medium can be used to store the program code executed by the blockchain-based data synchronization method provided in Embodiment 1.
[0106] Optionally, in this embodiment, the storage medium may be located in any computer terminal in a group of computer terminals in a computer network, or in any mobile terminal in a group of mobile terminals.
[0107] This application also provides a computer program product that, when executed on a data processing device, is suitable for performing steps of a blockchain-based data synchronization method.
[0108] The sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0109] In the above embodiments of this application, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0110] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. The device embodiments described above are merely illustrative; for example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual coupling, direct coupling, or communication connection may be through some interfaces; the indirect coupling or communication connection between units or modules may be electrical or other forms.
[0111] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0112] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0113] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard drive, magnetic disk, or optical disk.
[0114] The above description is only a preferred embodiment of this application. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of this application, and these improvements and modifications should also be considered within the scope of protection of this application.
Claims
1. A data synchronization method based on blockchain, characterized in that, The blockchain includes at least: multiple distributed nodes, and the data synchronization method includes: The system acquires all historical data and multiple current incremental transaction data from the host system, and uses a preset storage strategy to store the historical data and all incremental transaction data in the blockchain. A preset verification strategy is adopted to verify each incremental transaction data to obtain a verification result. The preset verification strategy is built on smart contracts and a two-phase commit protocol. The two-phase commit protocol is a transaction coordination mechanism for multiple distributed nodes. The verification result includes the result of each distributed node and the host system executing local transactions based on each incremental transaction data. If the verification result indicates that any of the distributed nodes has failed to execute the local transaction, a rollback instruction is triggered to control all the distributed nodes and the host system to roll back the local transaction and complete data synchronization.
2. The data synchronization method based on blockchain according to claim 1, characterized in that, The step of storing the historical full data and all incremental transaction data into the blockchain using a preset storage strategy includes: Based on a preset time window, the historical full data is sliced to obtain multiple slice data; Calculate the hash value for each slice of data and transmit all the hash values to the blockchain for storage; Calculate the incremental hash value for each incremental transaction data, and broadcast all the incremental hash values to all the distributed nodes, wherein the distributed nodes store all the incremental hash values in their local queues and submit all the incremental hash values in their local queues to the blockchain; All the hash values are concatenated with all the incremental hash values to obtain the target hash value, and the target hash value is stored in the blockchain.
3. The data synchronization method based on blockchain according to claim 1, characterized in that, The steps of verifying each incremental transaction data using a preset verification strategy and obtaining the verification result include: For each incremental transaction data, determine the transaction corresponding to the incremental transaction data, and verify the transaction based on the smart contract; If the transaction is verified, each of the distributed nodes is controlled to execute the local transaction with the host system to obtain the verification result.
4. The data synchronization method based on blockchain according to claim 2, characterized in that, After calculating the incremental hash value for each of the incremental transaction data, the process further includes: Generate a transaction sequence number for each transaction corresponding to the incremental transaction data; Hash calculations are performed on all incremental hash values within a preset window length to generate multiple window hash values, wherein each window hash value corresponds to a transaction sequence number range. An index table is generated based on all the window hash values and the transaction sequence number range corresponding to each window hash value; Based on a preset concatenation strategy, all the aforementioned window hash values are concatenated to generate multiple hash chains; The index table and all the hash chains are transferred to the blockchain for storage.
5. The data synchronization method based on blockchain according to claim 1, characterized in that, After the rollback instruction is triggered, the following is also included: Monitor the preset environment state when the rollback command is triggered; If the preset environment state indicates that there is a transaction data synchronization interruption, the interrupted transaction is determined based on the index table and hash chain.
6. The data synchronization method based on blockchain according to claim 5, characterized in that, Based on the index table and hash chain, the steps to determine the interrupted transaction include: The incremental hash value of each of the incremental transaction data is recalculated, and multiple hash chains are regenerated based on all the incremental hash values, and the hash chains are represented as local hash chains; For each local hash chain, the corresponding hash chain in the blockchain is determined, and the local hash chain is compared with the hash chain. If the local hash chain is different from the target hash chain, the local hash chain will be determined as the target hash chain. Based on the target hash chain, the target window hash value is determined, and based on the target window hash value and the index table, the interrupted transaction is determined.
7. The data synchronization method based on blockchain according to claim 1, characterized in that, After the rollback instruction is triggered, the following is also included: Determine whether conflicting transactions exist, wherein a conflicting transaction refers to a transaction for the same transaction account that has at least two different records on different distributed nodes at the same point in time, and the records are determined based on the execution result of the local transaction; Obtain the preset fields of the conflicting transactions and encode the preset fields to obtain the transaction feature vector; Obtain the historical transaction data of the transaction account and encode the historical transaction data to obtain a historical transaction feature vector; A preset weight is generated for each of the transaction feature vectors, and for each of the transaction feature vectors, a cosine similarity algorithm is used to calculate the conflict value between the historical transaction feature vector and the transaction feature vector based on the preset weight; The target transaction is determined based on a greedy algorithm and all the conflict values mentioned above; Identify the transactions in the conflicting transactions other than the target transaction, and generate a reverse compensation feature vector for the transactions. Based on the reverse compensation feature vector, determine a repair strategy, wherein the repair strategy is a strategy to adjust the balance of the transaction account.
8. A data synchronization device based on blockchain, characterized in that, The blockchain includes at least: multiple distributed nodes, and the data synchronization device includes: The acquisition unit is used to acquire the historical full data and multiple current incremental transaction data of the host system, and to store the historical full data and all the incremental transaction data in the blockchain using a preset storage strategy; The verification unit is used to verify each incremental transaction data using a preset verification strategy to obtain a verification result. The preset verification strategy is based on smart contracts and a two-phase commit protocol. The two-phase commit protocol is a transaction coordination mechanism for multiple distributed nodes. The verification result includes the result of each distributed node and the host system executing local transactions based on each incremental transaction data. The triggering unit is configured to trigger a rollback instruction if the verification result indicates that any of the distributed nodes has failed to execute the local transaction, so as to control all the distributed nodes and the host system to roll back the local transaction and complete data synchronization.
9. A computer program product, characterized in that, The method includes a non-volatile computer-readable storage medium storing a computer program that, when executed by a processor, implements the blockchain-based data synchronization method according to any one of claims 1 to 7.
10. An electronic device, characterized in that, It includes one or more processors and a memory, the memory being used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors cause the one or more processors to implement the blockchain-based data synchronization method according to any one of claims 1 to 7.