Data synchronization method and device, electronic equipment and storage medium

By querying the transaction processing status of the previous block when detecting a new block in the blockchain network and processing the unfinished transaction results, the data inconsistency caused by off-chain database downtime is solved, ensuring the successful execution of on-chain transactions.

CN119088810APending Publication Date: 2024-12-06TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310667446.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-06-06
Publication Date
2024-12-06

AI Technical Summary

Technical Problem

In a blockchain-based business system, off-chain databases may be inconsistent with on-chain data and off-chain data due to downtime or short-term unavailability, resulting in on-chain transaction failure.

Method used

By detecting the generation of a new block in the blockchain network, query the transaction processing status of the previous block. If it is an unfinished state, continue to process the transaction results in the previous block and store them in the database to ensure the data consistency.

Benefits of technology

It avoids the loss of off-chain database data, ensures the consistency of on-chain data and off-chain database data, and ensures successful execution of on-chain transactions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119088810A_ABST
    Figure CN119088810A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of block chains, in particular to a data synchronization method and device, electronic equipment and a storage medium. The method comprises the following steps: respectively detecting new blocks generated by each block chain node in a block chain network; when a new block generated by any block chain node is detected and before a transaction result in the new block is processed, querying a transaction processing state of a previous block of the new block from a database, the database being used for storing the transaction processing state of the processed block; and if it is queried that the transaction processing state of the previous block is an unfinished state, continuing to process the transaction result in the previous block until the obtained transaction return data and the corresponding business data are stored in the database, and updating the transaction processing state of the previous block in the database to a finished state. According to the application, the data consistency of the on-chain data and the off-chain database can be ensured, so that the on-chain transaction can be successfully executed.
Need to check novelty before this filing date? Find Prior Art

Description

Background Art

[0002] With the development of blockchain technology, blockchain-based applications are gradually being implemented. At present, in a blockchain-based business system, terminal devices can send business data to the business party's back-end service, and the back-end service will upload key data in the business data to the chain to ensure that the data cannot be tampered with. For example, taking the case of a terminal device applying to register an object on the chain, the business data sent by the terminal device to the back-end service can be object information.

[0003] The process of the back-end service uploading the above key data to the chain includes: using the locally stored certificate and private key for uploading to the chain, constructing the transaction metadata with the key data and signing it, and finally constructing the transaction and sending the transaction to the blockchain node; after the blockchain node packages the block and reaches a consensus on the execution of the transaction, wait for the result of the transaction execution and the return value of the transaction (which is the on-chain data). For example, the return value can be the object address, representing the identity of the object on the chain (stored in the blockchain); finally, the obtained on-chain data and the above business data are saved in the off-chain database for subsequent data query.

[0004] However, the above blockchain-based business system has the following problems:

[0005] After the backend service successfully uploads the key data of the business data to the chain, when it is preparing to insert the returned on-chain data and business data into the off-chain database, the off-chain database crashes or becomes unavailable for a short period of time, and the returned on-chain data and business data cannot be inserted into the off-chain database, causing the off-chain database to lose data, resulting in inconsistency between the on-chain data and the off-chain database. Some subsequent transactions initiated by the business party based on the data in the off-chain database may fail to execute on the chain. Summary of the invention

[0006] The embodiments of the present application provide a data synchronization method, device, electronic device and storage medium to ensure the data consistency between on-chain data and off-chain databases so that on-chain transactions can be successfully executed.

[0007] On the one hand, an embodiment of the present application provides a data synchronization method, the method comprising:

[0008] Respectively detecting new blocks generated by each blockchain node in the blockchain network, each of the new blocks being used to store transaction results of transactions constructed based on business data;

[0009] When a new block generated by any of the blockchain nodes is detected, before processing the transaction result in the new block, query the transaction processing status of the previous block of the new block from the database; wherein the database is used to store the transaction processing status of the processed blocks;

[0010] If it is found that the transaction processing status of the previous block is in an unfinished state, the transaction results in the previous block will continue to be processed until the obtained transaction return data and the corresponding business data are stored in the database, and the transaction processing status of the previous block in the database is updated from an unfinished state to a completed state.

[0011] On the one hand, an embodiment of the present application provides a data synchronization device, the device comprising:

[0012] A detection module, used to respectively detect new blocks generated by each blockchain node in the blockchain network, each of which is used to store transaction results of transactions constructed based on business data;

[0013] A query module, configured to query the transaction processing status of the previous block of the new block from a database before processing the transaction result in the new block when a new block generated by any of the blockchain nodes is detected; wherein the database is used to store the transaction processing status of the processed blocks;

[0014] The first processing module is used to continue processing the transaction results in the previous block if the transaction processing status of the previous block is in an unfinished state, until the obtained transaction return data and corresponding business data are stored in the database, and the transaction processing status of the previous block in the database is updated from an unfinished state to a completed state.

[0015] Optionally, the device further comprises:

[0016] A second processing module is used for starting to process the transaction result in the new block if the transaction processing status of the previous block is in a completed state, and setting the transaction processing status of the new block to an uncompleted state and saving it in the database;

[0017] The storage module is used to store the obtained transaction return data and corresponding business data in the database when the transaction result processing in the new block is completed, and to update the transaction processing status of the new block in the database from an unfinished state to a completed state.

[0018] Optionally, the new block has a corresponding block tag, and the new block includes multiple transaction results, each transaction result has a corresponding transaction tag, and the transaction processing status of the new block includes: the processing status of each of the multiple transaction results including the block tag and the transaction tag;

[0019] The second processing module is specifically used for:

[0020] Whenever a transaction result in the new block is processed, the processing status of the transaction result is set to an unfinished state, and the processing status of the transaction result is saved in the database;

[0021] The storage module is specifically used for:

[0022] Whenever a transaction result in the new block is processed, the transaction return data and corresponding business data of the transaction result are stored in the database, and the processing status of the transaction result in the database is updated from an unfinished state to a completed state.

[0023] Optionally, the previous block has a corresponding block tag, and the previous block includes multiple transaction results, each transaction result has a corresponding transaction tag, and the transaction processing status of the previous block includes: the processing status of each of the multiple transaction results including the block tag and the transaction tag;

[0024] The first processing module is specifically used for:

[0025] If the transaction processing status in the previous block is in an unfinished state, then continue to perform the following operations in sequence for at least one transaction result that has not been processed in the previous block:

[0026] When processing a transaction result in the previous block, setting the processing status of the transaction result to an unfinished state, and saving the processing status of the transaction result to the database;

[0027] When the processing of the transaction result is completed, the transaction return data and corresponding business data of the transaction result are stored in the database, and the processing status of the transaction result in the database is updated from an unfinished state to a completed state.

[0028] Optionally, the detection module is specifically used for:

[0029] Using a plurality of detectors, respectively detecting the new blocks generated by each of the blockchain nodes; wherein each blockchain node corresponds to at least one detector;

[0030] The query module is specifically used for:

[0031] When new blocks generated by corresponding blockchain nodes are detected respectively by the multiple detectors, before the transaction results in the new blocks are processed by any of the multiple detectors, the transaction processing status of the previous block of the new block is queried from the database.

[0032] Optionally, the query module specifically includes:

[0033] A calling submodule, used to call the designated commands of the remote dictionary service Redis respectively through the multiple detectors; wherein the designated command is used to cache the block mark of the new block in the Redis;

[0034] A cache submodule, configured to cache the block mark of the new block to the Redis after successfully calling a specified command of the Redis through a target detector among the multiple detectors;

[0035] The query submodule is used to query the transaction processing status of the previous block of the new block from the database before processing the transaction result in the new block through the target detector.

[0036] Optionally, the calling submodule is further used for:

[0037] Continue to call the specified command of Redis at a first set time interval through other detectors among the multiple detectors except the target detector;

[0038] The device also includes:

[0039] The first return module is used to return call failure information to the other detector through Redis each time the specified command of the Redis is called through the other detector, if it is determined through the Redis that the block mark of the new block is cached.

[0040] Optionally, the device further comprises:

[0041] A deletion module, used for deleting the block mark of the cached new block through the Redis after a second set time period;

[0042] A second returning module is used for, when continuing to call the specified command of the Redis through other detectors except the target detector among the multiple detectors, determining through the Redis that the block mark of the new block is not cached, and returning a call success message to any detector among the other detectors;

[0043] The third processing module is used to obtain the transaction processing status of the new block from the database through any detector among the other detectors, and when it is determined that the transaction processing status of the new block is in an unfinished state, continue to process the transaction result in the new block.

[0044] Optionally, the device further comprises:

[0045] A sending module, used to construct key data in the business data into corresponding transactions through the business service module, and send the transaction to any blockchain node among the blockchain nodes, so that any blockchain node constructs a new block to save the transaction result obtained by executing the transaction;

[0046] A construction module, used to obtain the transaction identifier of the transaction result through the business service module, construct non-critical data in the business data as context data, and cache the context data and the transaction identifier in the Redis in correspondence;

[0047] The storage module is also used for:

[0048] When the target detector completes processing of the transaction result in the new block, the context data is obtained from the Redis based on the transaction identifier, and the obtained transaction return data and the context data are stored in the database.

[0049] Optionally, the device further comprises:

[0050] A cache module, used to cache the acquired transaction return data into the context data in the Redis through the target detector to obtain complete business data;

[0051] The third return module is used to obtain the complete business data from the Redis based on the transaction identifier through the business service module, and process the complete business data.

[0052] Optionally, the device further comprises:

[0053] an acquisition module, configured to acquire the transaction processing status of the new block from the database through the target detector if the target detector is restarted during the process of processing the transaction result in the new block through the target detector;

[0054] The fourth processing module is used to continue processing the transaction result in the new block when the target detector determines that the transaction processing status of the new block is an unfinished state.

[0055] An electronic device provided in an embodiment of the present application includes a processor and a memory, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of any one of the above-mentioned data synchronization methods.

[0056] An embodiment of the present application provides a computer-readable storage medium, which includes a computer program. When the computer program is executed on an electronic device, the computer program is used to enable the electronic device to execute the steps of any one of the above-mentioned data synchronization methods.

[0057] An embodiment of the present application provides a computer program product, which includes a computer program, and the computer program is stored in a computer-readable storage medium; when a processor of an electronic device reads the computer program from the computer-readable storage medium, the processor executes the computer program, so that the electronic device performs the steps of any one of the above-mentioned data synchronization methods.

[0058] The present application adopts the above technical solution, which has at least the following beneficial effects:

[0059] The embodiment of the present application provides a data synchronization method, device, electronic device and storage medium. When a new block is detected in any blockchain node in the blockchain network, before processing the transaction results in the new block, the transaction processing status of the previous block of the new block is first queried from the database. If the transaction processing status is in an unfinished state, the transaction results in the previous block are continued to be processed. When the processing is completed, the obtained transaction return data and the corresponding business data are stored in the database, and the transaction processing status of the previous block is updated to a completed state. In this way, each time a new block is detected, it is ensured that the transaction result processing of the previous block is completed and the corresponding data is stored in the database, which can avoid data loss in the database and ensure the data consistency between the on-chain data and the off-chain database, so that the on-chain transaction is successfully executed.

[0060] Other features and advantages of the present application will be described in the following description, and partly become apparent from the description, or be understood by practicing the present application. The purpose and other advantages of the present application can be realized and obtained by the structures specifically pointed out in the written description, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0061] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0062] Figure 1 This is a structural diagram of a distributed system applied to a blockchain system in an embodiment of the present application;

[0063] Figure 2 A schematic diagram of a block structure in an embodiment of the present application;

[0064] Figure 3This is a schematic diagram of the architecture of a blockchain-based business system in an embodiment of the present application;

[0065] Figure 4 A schematic diagram of an application scenario of a data synchronization method in an embodiment of the present application;

[0066] Figure 5 A flowchart of a data synchronization method in an embodiment of the present application;

[0067] Figure 6 A schematic diagram of the transaction processing status of each block in a database in an embodiment of the present application;

[0068] Figure 7 This is a flowchart of another data synchronization method in an embodiment of the present application;

[0069] Figure 8 A logical diagram of a data synchronization method in an embodiment of the present application;

[0070] Fig. 9 A schematic diagram of a multi-detector detection in an embodiment of the present application;

[0071] Fig.10 This is a schematic diagram of the architecture of a business party server in an embodiment of the present application;

[0072] Fig.11 This is a schematic diagram of the architecture of a blockchain-based business system in an embodiment of the present application;

[0073] Fig.12 This is a schematic diagram of the architecture of another blockchain-based business system in an embodiment of the present application;

[0074] Fig.13 A structural block diagram of a data synchronization device in an embodiment of the present application;

[0075] Fig.14 is a structural block diagram of another data synchronization device in an embodiment of the present application;

[0076] Fig.15 A schematic diagram of the hardware structure of an electronic device to which the present invention is applied;

[0077] Fig.16 The present invention is a schematic diagram of the hardware structure of another electronic device to which the embodiments of the present application are applied. DETAILED DESCRIPTION

[0078] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the technical solution of the present application, rather than all of the embodiments. Based on the embodiments recorded in the application documents, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the technical solution of the present application.

[0079] The following is an introduction to some concepts involved in the embodiments of the present application.

[0080] Blockchain: A data structure consisting of several blocks connected by hash values. Each block consists of transactions generated within a period of time, packaged by computer nodes that have obtained the right to record accounts, and independently verified by each computer node.

[0081] On-chain data: On-chain data is data generated directly or indirectly by blockchain consensus and is also data stored on the blockchain. Generally speaking, businesses using blockchain will store some key business data access on the blockchain, which has achieved the characteristics of data that cannot be tampered with and can be traced.

[0082] Business data: Generally speaking, business data is some data closely related to the business generated by the object. These big data are mainly stored in mainstream relational databases, such as MySQL databases. In some blockchain-based business systems, the business party will select some key attributes from the business data, and perform on-chain operations and store them in the blockchain to ensure that these key data cannot be tampered with. In addition, some business data also comes from on-chain data. For example, a contract for object registration often records the total number of registered objects. After the business party goes on-chain, it often obtains this data from the chain and records it in the local MySQL database. Therefore, generally speaking: business data includes on-chain data and some data that is not on-chain (non-key attributes). On-chain data is a subset of business data.

[0083] Detector: After an object or business party initiates a transaction to a blockchain node, the transaction is not immediately packaged by the blockchain node, that is, the transaction is not immediately successful. Therefore, in an embodiment of the present application, the object or business party can use a detector to subscribe to the blockchain node, for example, to subscribe to the occurrence of new blocks (or transactions or events) of the blockchain node to determine whether its own transaction has been packaged into a certain block, and then determine whether the transaction has been successful. The detector is an important component of the blockchain-based business system of an embodiment of the present application, which is used to detect the occurrence of on-chain data (blocks, transactions) to ensure that business data is successfully uploaded to the chain.

[0084] Remote Dictionary Server (Redis): is an open source, network-based, memory-based, and persistent log-based, Key-Value database written in ANSI C, and provides APIs (Application Programming Interface) in multiple languages.

[0085] The word “exemplary” is used hereinafter to mean “serving as an example, example, or illustration.” Any embodiment described as “exemplary” is not necessarily to be construed as preferred or advantageous over other embodiments.

[0086] The terms "first" and "second" in this document are used for descriptive purposes only and should not be understood as explicitly or implicitly indicating relative importance or implicitly indicating the number of technical features indicated. Therefore, features defined as "first" and "second" may explicitly or implicitly include one or more of the features, and in the description of the embodiments of this application, unless otherwise specified, "plurality" means two or more.

[0087] The embodiments of the present application relate to blockchain technology. Blockchain is a new application mode of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods, each of which contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, the platform product service layer, and the application service layer.

[0088] The underlying blockchain platform can include processing modules such as object management, basic services, smart contracts, and operational detection. Among them, the object management module is responsible for the identity information management of all blockchain participants, including maintaining public and private key generation (account management), key management, and maintaining the correspondence between the object's real identity and the blockchain address (authority management), etc., and, under authorization, supervises and audits the transactions of certain real identities and provides risk control rule configuration (risk control audit); the basic service module is deployed on all blockchain node devices to verify the validity of business requests, and records valid requests to storage after consensus is reached. For a new business request, the basic service first performs interface adaptation analysis and authentication processing (interface adaptation), and then encrypts the business information through the consensus algorithm (consensus management). The smart contract module is responsible for the registration and issuance of contracts, as well as contract triggering and contract execution. Developers can define the contract logic in a programming language and publish it to the blockchain (contract registration). According to the logic of the contract terms, the key or other events are called to trigger the execution and complete the contract logic. It also provides the function of contract upgrade and cancellation. The operation detection module is mainly responsible for the deployment, configuration modification, contract setting, cloud adaptation and real-time status visualization output of the product during the product release process, such as alarm, network status detection, node equipment health status detection, etc.

[0089] The platform product service layer provides the basic capabilities and implementation framework of typical applications. Developers can superimpose business features based on these basic capabilities to complete the blockchain implementation of business logic. The application service layer provides application services based on blockchain solutions for business participants to use.

[0090] The system involved in the embodiments of the present application may be a distributed system formed by connecting a client and multiple nodes (any form of computing devices in an access network, such as a server and an object terminal device) through network communication.

[0091] Take the distributed system as the blockchain system as an example, see Figure 1 , Figure 1 This is an optional structural diagram of the distributed system 100 provided in the embodiment of the present application applied to the blockchain system, which is formed by multiple nodes (any form of computing devices in the access network, such as servers, object terminal devices) and clients, and the nodes form a peer-to-peer (P2P, PeerTo Peer) network. The P2P protocol is an application layer protocol running on the Transmission Control Protocol (TCP, Transmission Control Protocol) protocol. In a distributed system, any machine such as a server or a terminal device can join and become a node, and the node includes a hardware layer, an intermediate layer, an operating system layer, and an application layer.

[0092] See also Figure 1 The functions of each node in the blockchain system shown include:

[0093] 1) Routing: a basic function of a node, used to support communication between nodes.

[0094] In addition to the routing function, the node can also have the following functions:

[0095] 2) Applications are deployed in the blockchain to implement specific businesses based on actual business needs, record data related to the implementation of functions to form record data, carry digital signatures in the record data to indicate the source of the task data, and send the record data to other nodes in the blockchain system for other nodes to add the record data to a temporary block when they successfully verify the source and integrity of the record data.

[0096] 3) Blockchain, including a series of blocks that are connected to each other in the order of their generation. Once a new block is added to the blockchain, it will not be removed. The block records the record data submitted by the nodes in the blockchain system.

[0097] See also Figure 2 , Figure 2 This is an optional schematic diagram of the block structure provided by the embodiment of the present application. Each block includes the hash value of the transaction record stored in this block (the hash value of this block) and the hash value of the previous block. Each block is connected by the hash value to form a blockchain. In addition, the block can also include information such as the timestamp when the block was generated. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains relevant information for verifying the validity of its information (anti-counterfeiting) and generating the next block.

[0098] The design concept of the embodiments of the present application is introduced below.

[0099] With the development of blockchain technology, blockchain-based applications are gradually being implemented, and more and more objects are using blockchain applications. At present, in the business system based on blockchain, objects generally use a synchronous method to wait for the results of transactions when initiating transactions. Its architecture is as follows: Figure 3 As shown. Figure 3 In the business system shown, taking the registration of objects on the chain as an example, its operation flow mainly includes the following steps:

[0100] Step 1) Object U initiates a request to the business party's backend service to apply for registration of an on-chain object and provide object information, such as name, ID number, public key, address, gender, hobbies, and other attributes. The backend service first uses a certain strategy to generate a unique object ID (Identity document) for the object, and then extracts some key attributes or important attributes from the object information, such as the (object ID, name, ID number, public key) quadruple, and uploads this data to the chain.

[0101] Step 2) The backend service uses the locally stored certificate and private key for chain upload (in the consortium chain, the business party will be assigned a certificate and private key when joining a blockchain network for subsequent chain upload operations), uses the corresponding SDK (Software Development Kit) client, and uses the (object ID, name, ID number, public key) four-tuple to first construct the transaction metadata, then sign it, and finally call the contract to construct a transaction, and send the transaction to the blockchain node A (or B) in a synchronous manner. The synchronous method means that the SDK client will always wait for the execution result of the transaction synchronously.

[0102] Step 3) After blockchain node A packages the block and reaches a consensus with blockchain node B on the execution of the transaction, the SDK client will synchronously wait to obtain the execution result of the transaction and the transaction return value. For example, in a contract, an address is often calculated using the object public key to represent the identity of the object on the chain (stored in the blockchain).

[0103] Step 4) The backend service obtains the execution result and transaction return value (on-chain data) of the transaction through the SDK client, and integrates a complete object information, including all business attributes and object attributes (object ID, name, ID number, public key, address, gender, hobbies, address representing the identity on the chain, other attributes, etc.), and inserts it into the database. The key attributes of the object on the chain (object ID, name, ID number, public key) can ensure the immutability of the data, and store the complete object information in the off-chain database for subsequent convenient relational queries.

[0104] However, the above-mentioned blockchain-based business system has the following problems: after the back-end service successfully uploads the key data of the business data to the chain, when it is ready to insert the returned on-chain data and business data into the off-chain database, the off-chain database crashes or becomes unavailable for a short period of time, and the returned on-chain data and business data cannot be inserted into the off-chain database, causing the off-chain database to lose data, resulting in inconsistency between the on-chain data and the off-chain database. Some subsequent transactions initiated by the business party based on the data in the off-chain database may fail to execute on the chain.

[0105] In view of this, the embodiment of the present application proposes a data synchronization method, device, electronic device and storage medium, which respectively detect the new blocks generated by each blockchain node in the blockchain network. When any blockchain node is detected to generate a new block, before processing the transaction results in the new block, the transaction processing status of the previous block of the new block is first queried from the database. If it is in an unfinished state, the transaction results in the previous block are continued to be processed, so that the obtained transaction return data and the corresponding business data are stored in the database, and the transaction processing status of the previous block is updated to a completed state. In this way, the database can avoid data loss, ensure the data consistency of the on-chain data and the off-chain database, so that the on-chain transaction can be successfully executed.

[0106] The preferred embodiments of the present application are described below in conjunction with the drawings in the specification. It should be understood that the preferred embodiments described herein are only used to illustrate and explain the present application, and are not used to limit the present application. In addition, the embodiments and features in the embodiments of the present application may be combined with each other if there is no conflict.

[0107] like Figure 4 As shown, it is a schematic diagram of an application scenario of an embodiment of the present application. The application scenario diagram includes two terminal devices 110, a server 120 and a blockchain network 130, and the blockchain network 130 includes multiple blockchain nodes. The blockchain node is a computer in the blockchain network, including mobile phones, mining machines, servers, etc.

[0108] In the embodiment of the present application, the terminal device 110 includes but is not limited to mobile phones, tablet computers, laptops, desktop computers, e-book readers, intelligent voice interaction devices, smart home appliances, vehicle-mounted terminal devices and other devices; the server 120 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms.

[0109] In an optional implementation, the terminal device 110 and the server 120 may communicate via a communication network, and the server 120 and the blockchain nodes in the blockchain network 130 may communicate via a communication network. The communication network may be a wired network or a wireless network.

[0110] It should be noted that the data synchronization method in each embodiment of the present application can be executed by an electronic device, which may be a terminal device 110 or a server 120, that is, the method can be executed by the terminal device 110 or the server 120 alone, or can be executed jointly by the terminal device 110 and the server 120.

[0111] In some embodiments, taking the server 120 executing the data synchronization method as an example, the terminal device 110 sends business data to the server 120. For example, the business data can be object information for registering objects on the chain. The server 120 can construct key data in the business data as a transaction and upload it to any blockchain node in the blockchain network 130, so that the blockchain node constructs a new block and executes the transaction to obtain the transaction result, and then reaches a consensus with other blockchain nodes and synchronizes data. After that, the server 120 can execute the data synchronization method of the embodiment of the present application.

[0112] In other embodiments, taking the data synchronization method executed by the terminal device 110 as an example, the terminal device 110 can directly construct the key data in the business data into a transaction and upload it to any blockchain node in the blockchain network 130, so that the blockchain node constructs a new block and executes the transaction to obtain the transaction result, and then reaches a consensus with other blockchain nodes. After that, the terminal device 110 executes the data synchronization method of the embodiment of the present application.

[0113] It should be noted that Figure 4 The figure is only an example. In fact, the number of terminal devices and servers is not limited and is not specifically limited in the embodiments of the present application.

[0114] The following describes the data synchronization method provided by the exemplary embodiment of the present application in combination with the application scenario described above and with reference to the accompanying drawings. It should be noted that the above application scenario is only shown to facilitate understanding of the spirit and principles of the present application, and the implementation of the present application is not limited in this regard.

[0115] See also Figure 5 As shown, it is an implementation flow chart of a data synchronization method provided in an embodiment of the present application. Taking the server as the execution subject as an example, the specific implementation process of the method includes the following steps S501-S502:

[0116] Step S501, respectively detect the new blocks generated by each blockchain node in the blockchain network, each new block is used to store the transaction results of the transaction constructed based on the business data.

[0117] In the embodiment of the present application, when the business party joins the blockchain network, one or more blockchain nodes can be deployed to join the blockchain network. For example, the business party deploys three blockchain nodes: blockchain node A, blockchain node B, and blockchain node C to join the blockchain network, and the server of the business party detects the new blocks generated by these three blockchain nodes respectively. Specifically, when the server of the business party constructs the key data in the business data as a transaction and uploads it to any blockchain node in the blockchain network, the any blockchain node constructs a new block and executes the transaction to obtain the transaction result, which includes the transaction return value and the above-mentioned key data. For example, when the transaction is used to register an object on the chain, the transaction return value can be the address representing the identity of the object on the chain. Any blockchain node reaches a consensus with other blockchain nodes and synchronizes data, that is, other blockchain nodes also generate new blocks to save the transaction results.

[0118] Among them, the key data in the business data can be determined according to the specific business scenario. In order to prevent the key data from being tampered with, the business party can usually save the key data in the block of the blockchain node. For example, the business performed by the server of the business party is to register the object on the chain. The business data obtained can be the object information provided by the object. The object can refer to the user. The object information includes, for example, name, ID number, public key, address, gender, hobbies, other attributes, etc. The business service party can generate an object ID and use the object ID, name, ID number, and public key as key data.

[0119] Optionally, the business party's server can deploy multiple detectors to detect new blocks generated by each blockchain node. Each blockchain node can correspond to at least one detector.

[0120] Step S502, when a new block generated by any blockchain node among the blockchain nodes is detected, before processing the transaction result in the new block, query the transaction processing status of the previous block of the new block from the database; wherein the database is used to store the transaction processing status of the processed blocks.

[0121] Among them, when any blockchain node generates a new block, other blockchain nodes also generate new blocks. When a new block generated by any blockchain node is detected, a block mark is set for the new block. The block mark of each block in the blockchain node can be set according to a preset rule. For example, according to the order in which each block is generated, the block mark of each block is set to 1, 2, 3..., and there is no limitation on this.

[0122] When the above-mentioned new block is detected, before the transaction results in the new block are processed, in order to prevent the transaction results of the previous block of the new block from not being processed due to some reasons (such as database crash or short-term unavailability, etc.), the transaction processing status of the previous block can be queried from the data.

[0123] For the transaction results in each block generated by each blockchain node, when processing begins, the transaction processing status of the block can be set to an unfinished state and stored in the database, specifically in a designated database table. When the processing of the transaction results in the block is completed, the unfinished state is updated to a completed state.

[0124] It should be noted that the database can store the transaction processing status of each block generated by each blockchain node. In addition, in order to save the storage resources of the database, on the one hand, before each new block is detected, the database can only store the transaction processing status of the previous block of the new block, that is, the transaction processing status of the blocks in the database is constantly updated, and only the transaction processing status of the latest processed block is stored.

[0125] There can be one or more transaction results in each block, and the business party's server can construct a transaction result for each business data. When there are multiple transaction results, the transaction processing status of the previous block can include the processing status of multiple transaction results, and each transaction result can have a corresponding transaction tag. Generally, each block is generated at a time interval, such as one block per second. The number of transaction results in each block has an upper limit. Assuming that each block can save up to 100 transaction results, after a new block is generated, 105 transaction results are constructed within one second. 100 transaction results can be saved in the new block, and the remaining 5 transaction results will be saved to the next block.

[0126] Step S503, if it is found that the transaction processing status of the previous block is in an unfinished state, the transaction results in the previous block will continue to be processed until the obtained transaction return data and the corresponding business data are stored in the database, and the transaction processing status of the previous block in the database is updated from an unfinished state to a completed state.

[0127] Among them, for the unfinished transaction results in the previous block, the transaction results are parsed to obtain the transaction return data, which is on-chain data, including the transaction return value and key data in the business data. The key data in the business data is used to construct and initiate transactions. For example, when the business data is used to register an on-chain object, the key data for constructing the transaction includes the key attributes of the object: object ID, name, ID number, public key, and the transaction return value in the above transaction return data can be an address that generates an identity on the object chain. At this time, the on-chain data in the previous block includes the object ID, name, ID number, public key, and the address representing the identity on the object chain.

[0128] After obtaining the transaction return data, the transaction return data (i.e., on-chain data) and non-critical data in the business data can be integrated into complete business data and stored in the database. The business data in the embodiment of the present application can be data in any business scenario, without limitation.

[0129] In the embodiment of the present application, the new blocks generated by each blockchain node in the blockchain network are detected respectively. When any blockchain node is detected to generate a new block, before processing the transaction results in the new block, the transaction processing status of the previous block of the new block is queried first. If it is in an unfinished state, the transaction results in the previous block are processed continuously, so as to store the obtained transaction return data and the corresponding business data in the database, and update the transaction processing status of the previous block to a completed state. In this way, even if the database is down or not used for a short time, the database can avoid data loss, ensure the data consistency between the on-chain data and the off-chain database, so that the on-chain transaction can be successfully executed.

[0130] In some embodiments, considering that each block in a blockchain node may contain multiple transaction results, a transaction tag can be set for each transaction result in the block for each block. When recording the transaction processing status of each block in the database, the block tag of the block, the transaction tag and status of the transaction result can be combined to form the transaction processing status. In addition, the network ID of the blockchain network can be added to the transaction processing status. The network ID can identify the unique ID of the business party joining the blockchain network, such as the ID of Ethereum or a consortium chain, etc. The network ID can be used to query a specified database table in the database, which is used to store the transaction processing status of processed blocks.

[0131] The database table specified in the database may store the transaction processing status of each processed block, or may only store the transaction processing status of the most recently processed block.

[0132] For example, taking the example that the database table specified in the database only stores the transaction processing status of the latest processed block, the block mark can be block number 1, 2, 3..., and the transaction mark can be transaction number 1, 2, 3..., as an example. Figure 6As shown, assuming that the new block currently detected is block N (i.e., the block number is N), the database table specified by the database stores the transaction processing status of block N-1, for example, [network ID, block N-1, transaction 100, completed], indicating that there are a total of 100 transaction results in block N-1, and the processing status of the 100th transaction result is completed. At this time, the first transaction result in the new block can be processed, and the transaction processing status of block N-1 in the database table is updated to the transaction processing status of block N, for example, [network ID, block N-1, transaction 1, uncompleted]. In the process of processing the transaction results in the new block, the transaction number and processing status are continuously updated until all transaction results in block N are processed.

[0133] In some embodiments, the previous block has a corresponding block mark, which can be set as needed, for example, block number 1, 2, 3...; when the previous block includes multiple transaction results, each transaction result can have a corresponding transaction mark, which can be set as needed, for example, transaction number 1, 2, 3..., and the transaction processing status of the previous block includes: the processing status of each of the multiple transaction results including the block mark and the transaction mark, so that the block mark and the transaction mark can be used to determine which transaction result of which block has been successfully processed.

[0134] In the above step S503, if the transaction processing status of the previous block is in an unfinished state, the transaction results in the previous block are continuously processed until the obtained transaction return data and the corresponding business data are stored in the database, and the transaction processing status of the previous block in the database is updated from an unfinished state to a completed state, which may include the following steps A1:

[0135] A1. If the transaction processing status in the previous block is in an unfinished state, continue to perform the following steps A2-A3 in sequence for at least one transaction result that has not been processed in the previous block.

[0136] Among them, when storing the transaction processing status of the previous block in the database, the processing status of multiple transaction results of the previous block can be stored, or only the processing status of successfully processed transaction results can be stored. When the transaction processing status of the previous block is an unfinished state, at least one transaction result has not been processed. According to the processing status of multiple transaction results or the processing status of successfully processed transaction results, at least one transaction result that has not been processed in the previous block can be determined.

[0137] For example, when the database only stores the processing status of successfully processed transaction results, assuming that there are 100 transaction results in the previous block, and the 80th transaction result is successfully processed, it means that there are still 20 transaction results that have not been processed.

[0138] A2. When processing a transaction result in the previous block, the processing status of the transaction result is set to an unfinished state, and the processing status of the transaction result is saved in the database.

[0139] Among them, before processing a transaction result, the processing status of the previous transaction result of the transaction result is stored in the database. When processing the transaction result, the processing status of the previous transaction result in the database can be updated to the processing status of the transaction result, or the processing status of the transaction result can be inserted on the basis of retaining the processing status of the previous transaction result. There is no limitation on this.

[0140] A3. When a transaction result is processed, the transaction return data of the transaction result and the corresponding business data are stored in the database, and the processing status of the transaction result in the database is updated from an unfinished state to a completed state.

[0141] Among them, when processing each transaction result in the previous block, the processing status of the transaction result is first set to an unfinished state and stored in a database table specified in the database. When the processing of the transaction result is completed, the unfinished state is updated to a completed state.

[0142] In a specific implementation, the processing status of the transaction result may include the network ID, block mark, transaction mark, and status of the blockchain network, wherein the status may be indicated as unfinished or completed through a specified field, for example, 1 indicates completed and 0 indicates unfinished, and there is no limitation on this.

[0143] In an embodiment of the present application, before processing a new block, it is ensured that all transaction results of the previous block are processed, and the transaction processing status of the previous block is stored through the block mark and the transaction mark, which can facilitate the query of which transaction results have been successfully processed in the previous block, so as to continue to process these transaction results when some transaction results have not been processed.

[0144] In some embodiments, Figure 7 As shown, after the above step S502, the following steps S504-S505 may also be performed:

[0145] Step S504: If the transaction processing status of the previous block is completed, start processing the transaction results in the new block, set the transaction processing status of the new block to unfinished, and save it in the database.

[0146] Among them, when there are multiple transaction results in the previous block, when the processing status of multiple transaction results are all completed, the transaction processing status of the previous block is determined to be completed.

[0147] The transaction result in the new block may also be one or more. When there are multiple transaction results, the multiple transaction results may be processed in sequence. Specifically, each transaction result is parsed to obtain the corresponding transaction return data.

[0148] Step S505, when the transaction result processing in the new block is completed, the obtained transaction return data and the corresponding business data are stored in the database, and the transaction processing status of the new block in the database is updated from an unfinished state to a completed state.

[0149] Among them, when the transaction results in the new block include multiple ones, the transaction return data of each transaction result can be obtained, the transaction return data of each transaction result and the corresponding business data can be stored in the database, and the transaction processing status of each transaction result can be set to the completed status.

[0150] In an embodiment of the present application, when the transaction results in the new block are processed, the obtained transaction return data and the corresponding business data are stored in the database to ensure the consistency of the on-chain data and the data in the database, and at the same time record the transaction processing status of the new block for subsequent query.

[0151] In some embodiments, the new block has a corresponding block tag, and when the new block includes multiple transaction results, each transaction result has a corresponding transaction tag, and the transaction processing status of the new block includes: the processing status of each of the multiple transaction results including the block tag and the transaction tag;

[0152] In step S504 of the above embodiment of the present application, when starting to process the transaction results in the new block and setting the transaction processing status of the new block to an unfinished state and saving it in the database, the following steps may be specifically included:

[0153] Whenever a transaction result in a new block is processed, the processing status of the transaction result is set to an unfinished state, and the processing status of the transaction result is saved in the database.

[0154] In a specific implementation, the processing status of each transaction result may include the network ID, block tag, transaction tag, and status of the blockchain network, wherein the status may be indicated as unfinished or completed through a specified field, for example, 1 indicates completed and 0 indicates unfinished, without limitation. Optionally, the processing status of each transaction result may be saved in a specified database table in the database.

[0155] Furthermore, in step S505 of the above embodiment of the present application, when the transaction result processing in the new block is completed, the obtained transaction return data and the corresponding business data are stored in the database, and the transaction processing status of the new block is updated from an unfinished state to a completed state, which may specifically include the following steps:

[0156] Whenever a transaction result in a new block is processed, the transaction return data of the transaction result and the corresponding business data are stored in the database, and the processing status of the transaction result is updated from an unfinished state to a completed state.

[0157] In an embodiment of the present application, when processing each transaction result in a new block, its processing status is recorded as an unfinished state. In this way, when a transaction result has not been processed for some reason, it can be discovered in time by querying its transaction processing status, and then the transaction result can be continued to be processed. When a transaction result is processed, its processing status can be updated from an unfinished state to a completed state, so as to subsequently confirm that the new block has been processed.

[0158] It should be noted that after processing multiple transaction results in the new block, the processing status of each of the multiple transaction results can be stored in the database, or only the processing status of the successfully processed transaction results can be stored, that is, each time a transaction result is successfully processed, the processing status of the transaction result is updated to the processing status of the next transaction result.

[0159] Combine the following Figure 8 The overall logic of the data synchronization method of the embodiment of the present application is exemplarily introduced.

[0160] like Figure 8 As shown, assuming that the business party deploys blockchain node A, blockchain node B, and blockchain node C in the blockchain network, the business party's server detects the new blocks generated by the three blockchain nodes respectively. When a new block N is detected, the transaction processing status of the previous block N-1 of the new block N is first queried from the database. If the transaction processing status is in an unfinished state, the transaction result in the previous block N-1 is continued to be processed, and after the processing is completed, the transaction processing status in the database is updated to a completed state; if the transaction processing status is a completed state, the transaction result in the new block N is started to be processed, and the transaction processing status of the new block N is recorded in the database, and after the processing is completed, the transaction processing status of the new block N is set to a completed state.

[0161] In some embodiments, when executing step S501 of the above-mentioned embodiment of the present application, the server of the business party may respectively detect the new blocks generated by each blockchain node in the blockchain network through multiple detectors. Optionally, the new blocks generated by each blockchain node may be respectively detected through multiple detectors; wherein each blockchain node corresponds to at least one detector.

[0162] Among them, multiple detectors can be deployed on the same server or on different servers. When multiple detectors are deployed on different servers, the server of the business party can be a server cluster. Each of the multiple detectors can subscribe to one or more blockchain nodes, that is, detect new blocks generated by one or more blockchain nodes, and each blockchain node is subscribed by one or more detectors.

[0163] For example, Fig. 9 As shown, the business party has deployed three blockchain nodes in the blockchain network: blockchain node A, blockchain node B, and blockchain node C. Three detectors can be deployed: detection A, detection B, and detection C, and each detector detects a new block generated by a blockchain node. It should be noted that the embodiment of the present application does not limit the number of detectors, and each blockchain node can also correspond to multiple detectors.

[0164] In step S502 of the above embodiment of the present application, when a new block generated by any blockchain node among the blockchain nodes is detected, before processing the transaction result in the new block, querying the transaction processing status of the previous block of the new block from the database may specifically include:

[0165] When a new block generated by a corresponding blockchain node is detected by multiple detectors, before any of the multiple detectors processes the transaction result in the new block, the transaction processing status of the previous block of the new block is queried from the database.

[0166] Among them, when any blockchain node in each blockchain node generates a new block, it will reach a consensus with other blockchain nodes and synchronize data. Therefore, multiple detectors can detect the new blocks generated by the blockchain nodes respectively. At this time, any detector can be selected from multiple detectors to process the new block. Before processing the new block, the transaction processing status of the previous block is queried through any detector to ensure that the processing of the previous block is completed to avoid data loss in the database.

[0167] In some embodiments, when selecting any detector from multiple detectors, the selection can be made through the remote dictionary service Redis connected to the multiple detectors. Redis can be deployed on the same server as the detector or on a different server, without limitation. In addition, Redis can be set up as a master-slave replica to further improve the reliability of Redis.

[0168] Optionally, in the above embodiment, when a new block generated by a corresponding blockchain node is detected by multiple detectors respectively, before the transaction result in the new block is processed by any detector among the multiple detectors, the previous block of the new block is determined according to the block mark of the new block, and the transaction processing status of the previous block is queried from the database, which specifically includes the following steps B1-B3:

[0169] B1. Calling designated commands of the remote dictionary service Redis through multiple detectors respectively; wherein the designated command is used to cache the block mark of the new block in Redis.

[0170] Among them, after each detector is connected to redis, it can call the specified command provided by redis at a certain time interval (for example, 50ms). The specified command is an atomic command and can contain key and value. The key can contain a block mark. In addition, it can also include the above-mentioned network ID, that is, key = network ID + N, N represents the block mark, and value can be the block hash Hash. Only when the key does not exist in redis, the value will be set successfully. When the key exists, the detector will receive an error message returned by redis that the key already exists; the key has a validity period time in redis, that is, when the key cache time reaches the validity period, redis can delete the key. The validity period can be set according to needs, for example, 2 seconds, and there is no limit on this.

[0171] For example, the specified command may be a setnx command provided by redis, and the specific form is setnx(key, value, time).

[0172] B2. After successfully calling the specified command to Redis through the target detector among the multiple detectors, the block mark of the new block is cached to Redis.

[0173] For example, the specified command is setnx(key, value, time). When the target detector successfully calls the command, the key is set to network ID+N, where N represents the block mark of the new block. At this time, the target detector obtains the processing right of the new block. If other detectors continue to call the specified command of Redis, redis will return an error message that the key already exists (that is, the call failed information).

[0174] B3. Before processing the transaction results in the new block through the target detector, the previous block of the new block is determined according to the block mark of the new block, and the transaction processing status of the previous block is queried from the database.

[0175] In an embodiment of the present application, by connecting multiple detectors with high-reliability Redis, whenever a new block is detected, the target detector for executing the new block can be determined by calling the specified command of Redi, thereby efficiently processing the new block.

[0176] In some embodiments, after the target detector in the plurality of detectors successfully calls the specified command to Redis in step A2 of the above embodiment, the following steps C1-C2 may also be performed:

[0177] C1. Continue to call the specified command of Redis every first set time period through other detectors among the multiple detectors except the target detector.

[0178] The first set duration can be set as needed, for example, 50 ms, and there is no limitation on this.

[0179] C2. Each time a specified command of Redis is called through other detectors, if Redis determines that a block mark of a new block is cached, a call failure message is returned to other detectors through Redis.

[0180] Each time other detectors call a specified command of Redis, Redis determines that the cache has a block mark of a new block, indicating that the new block is being processed by the target detector and other detectors do not need to process the new block.

[0181] In an embodiment of the present application, after it is determined that the target detector processes the new block, other detectors can continue to call the specified command provided by redis at a time interval of the first set time length. In this way, when the target detector fails and fails to process the new block, it is convenient to hand over the processing rights of the new block to other detectors to ensure that the new block is successfully processed.

[0182] In addition, when Redis determines that there is no block marker for the new block in the cache, it may be that the target detector has not completed the processing of the new block due to a failure, or it may have completed the processing of the new block. At this time, Redis can return a call success message to any of the other detectors, and any detector can determine whether the processing of the new block is completed by querying the transaction processing status of the new block, and then determine whether it needs to continue processing the new block.

[0183] In some embodiments, after step A2 of the above embodiment caches the block mark of the new block to Redis, the following steps D1-D3 may also be performed:

[0184] D1. After the second set time period, the block mark of the cached new block is deleted through Redis.

[0185] Among them, the block mark of the new block has a cache validity period, that is, the second set time length. For example, the block mark of the new block is cached through the specified command setnx (key, value, time) in the above embodiment, and the block mark is used as the key, or the network ID + block mark is used as the key, and time is the second set time length, which can be set as needed, for example, 2 seconds, and there is no limitation on this.

[0186] D2. When the specified command of Redis continues to be called through other detectors except the target detector among the multiple detectors, the block mark of the new block that is not cached is determined through Redis, and the call success information is returned to any detector among the other detectors.

[0187] For example, when the specified command is setnx(key, value, time), when Redis determines that the key does not exist, that is, the block mark of the new block is not cached, any detector in the other detectors can successfully call the specified command to obtain the processing right of the new block.

[0188] D3. Obtain the transaction processing status of the new block from the database through any detector among the other detectors, and when it is determined that the transaction processing status of the new block is in an unfinished state, continue to process the transaction results in the new block.

[0189] Among them, when any of the other detectors obtains the processing right of the new block, it first queries the transaction processing status of the new block from the database. If it is in an unfinished state, it continues to process the new block, parses the transaction results in the new block, obtains the on-chain data (transaction return data), and stores the on-chain data and corresponding business data in the database; if the transaction processing status of the new block is a completed state, it does not need to process the new block, and continues to detect the generation of the new block.

[0190] In the embodiment of the present application, by detecting new blocks through multiple detectors and processing the transaction results in the new blocks, it is possible to ensure highly reliable processing and analysis of the transaction results of each block, and ultimately write the on-chain data into the database. Even if some blockchain nodes or detections of the blockchain network crash, as long as there is at least one available blockchain node and one detector left, the on-chain data can be synchronously stored in the database, thereby improving the reliability of data synchronization.

[0191] In some embodiments, before step S501 of the above embodiment detects the new blocks generated by each blockchain node in the blockchain network, the following steps E1-E2 may also be performed:

[0192] E1. The key data in the business data is constructed into corresponding transactions through the business service module, and the transactions are sent to any blockchain node in each blockchain node, so that any blockchain node constructs a new block to execute the transaction and obtain the corresponding transaction result.

[0193] Specifically, the business service module can be deployed in the same server as the detector, redis, and database, or in a different server. The business service module is used to execute corresponding businesses, such as receiving and processing business data sent by terminal devices. Key data in the business data can be saved in the blockchain network to ensure that the key data cannot be tampered with.

[0194] Taking the business of registering objects on the chain as an example, the implementation process of this business includes:

[0195] 1) Object initiates request: Object A initiates a request to the business service module to apply for registration of an on-chain object. The object information provided includes name, ID number, public key, address, gender, hobbies, and other attributes. The business service module first uses a certain strategy to generate a unique object ID, and then extracts some key attributes from the object information, such as (user ID, name, ID number, public key) four-tuple data, and uploads the four-tuple data to the chain.

[0196] 2) Asynchronously initiate transactions: The business service module uses the locally stored certificate and private key, uses the corresponding SDK client, and uses the four-tuple data (user ID, name, ID number, public key) to first construct the transaction metadata, then use the private key to sign, and finally call the contract to construct a transaction result, which is sent to any blockchain node in an asynchronous manner. The asynchronous method means that the SDK client will not wait for the execution result of the transaction, but will immediately return the transaction identifier.

[0197] 3) New block generation: Any blockchain node will package the transaction results, construct a new block to execute the transaction results, and reach consensus with other blockchain nodes. After the consensus is successful, the transaction results in the new block will be executed in each blockchain node and stored on the disk.

[0198] E2. Obtain the transaction identifier of the transaction result through the business service module, construct non-critical data in the business data into context data, and cache the context data and the transaction identifier in Redis accordingly.

[0199] Among them, the transaction identifier is used to uniquely identify the transaction result. The business service module can use the transaction identifier of the transaction result as the key, and the context data constructed by non-critical data in the business data as the Value, and use the corresponding interface provided by redis to cache (key, Value) in redis. For example, the corresponding interface can be a Set interface.

[0200] Specifically, after the business service module asynchronously initiates the transaction result, it can set the context data to redis, which includes the following process:

[0201] 1) After the business service module obtains the above transaction identifier, it can construct context data from non-critical data in the business data that is not on the chain, such as the address, gender, hobbies, and other attributes in the above object information, such as a JSON (JavaScript Object Notation) string. For example, the context data is represented as Context, as shown below:

[0202] Context={"address":"Address","sex":"Gender","hobby":"Hobbies","others":"Other attributes"}

[0203] 2) The business service module uses "txid / req / TxId" as the complete Key, txid / req indicates the blockchain network that the business party joins, TxId indicates the transaction identifier, and Context is the Value, which is cached in redis. For example, the above Key and Value can be cached in redis through the Set interface provided by redis. In order to prevent redis data from expanding, the data validity period can be set, for example, to 1 hour, and there is no limit on this, as shown below:

[0204] Set(txid / req / TxId,Context,1hour)

[0205] Furthermore, when the transaction result processing in the new block is completed through the target detector, context data is obtained from Redis based on the transaction identifier, and the obtained transaction return data and context data are stored in the database.

[0206] Specifically, after obtaining the processing rights of the new block, the target detector can process the transaction results in the new block; taking the processing of objects on the registration chain as an example, the target detector parses the transaction results to obtain transaction return data, such as object ID, name, ID number, public key, address representing the identity on the chain, etc. At the same time, the above context data is obtained from Redis based on the transaction identifier.

[0207] For example, the target detector uses "txid / req / TxId" as the key, calls the Redis Get interface, and obtains the context data that the business service module puts into Redis with the same key. For example, the context data is the following Context:

[0208] Context=Get("txid / req / TxId")={"address":"address","sex":"sex","hobby":"hobbies","others":"other attributes"}

[0209] Afterwards, the target detector integrates the obtained on-chain data and context data into complete business data and inserts it into the database. For example, the complete business data is the following User_Info:

[0210] User_Info = (user ID, name, ID number, public key, address, gender, hobbies, address representing the identity on the chain, and other attributes).

[0211] In an embodiment of the present application, through the high availability of redis, after the target detector obtains the transaction return data, it can safely and reliably obtain the context data constructed by the business service module, and then construct complete business data and store it in the database to ensure the consistency of on-chain data and database data.

[0212] In some embodiments, after the object detector obtains the context data from Redis based on the transaction identifier, the following steps F1-F2 may also be performed:

[0213] F1. Through the target detector, the acquired transaction return data is cached into the context data in Redis to obtain complete business data;

[0214] Specifically, the target detector can set transaction return data to redis, so that redis obtains complete business data based on the transaction return data and context data, so that the business service module obtains the complete business data from redis.

[0215] For example, the target detector calls the Set interface of Redis, takes the above "txid / resp / TxId" as the complete key, and writes the following JSON string into the Value corresponding to the key in Redis, for example, the value is Resp:

[0216] Resp = {"error":"error information","user":"complete business data"}

[0217] Set("txid / resp / TxId",Resp,1hour)

[0218] F2. Through the business service module, obtain complete business data from Redis based on the transaction identifier and process the complete business data.

[0219] Among them, the business service module can continuously obtain complete business data from Redis based on the transaction identifier. For example, it can continuously use "txid / resp / TxId" as the key to call the redis Get interface to obtain the corresponding value to obtain the transaction return data placed in redis by the target detector. For example, the value is the above Resp:

[0220] Resp=Get(txid / resp / TxId)

[0221] Specifically, the business service module obtains the value corresponding to the key from redis at a certain time interval (for example, 50ms) until the above-mentioned Resp is obtained, or the set time limit (for example, 1s) is reached. If the above-mentioned Resp is obtained, the Resp can be further processed, for example, the object Id in the complete business data in the Resp is returned to the terminal device; if it times out, an error is directly reported to the terminal device.

[0222] In the embodiment of the present application, different detectors, Redis, business service modules and databases can be deployed in the same server of the business party, or in different servers of the business party. Assume that there are three detectors in total: detector A, detector B, and detector C. Fig.10 The figure shows the situation where the three detectors, Redis, business service module and database are deployed in the same server of the business party, where each detector is connected to the Redis database respectively, and Redis is connected to the business service module. Through the high availability of Redis, after any of the multiple detectors obtains the transaction return data, it can safely and reliably obtain the context data constructed by the business service module, and then construct complete business data and store it in the database to ensure the consistency of on-chain data and database data.

[0223] In some embodiments, during the process of processing the transaction results in the new block by the target detector, if the target detector is restarted due to a failure, the transaction processing status of the new block can be queried to determine the unfinished transaction results before the restart, thereby continuing to process the transaction results in the new block.

[0224] Optionally, the following steps G1-G2 can also be performed by the target detector:

[0225] G1. During the process of processing the transaction results in the new block through the target detector, if the target detector is restarted, the transaction processing status of the new block is obtained from the database through the target detector.

[0226] G2. When the target detector determines that the transaction processing status of the new block is in an unfinished state, continue to process the transaction results in the new block.

[0227] Specifically, the transaction processing status of the new block may include the processing status of each transaction result, which may be marked by a block tag and a transaction tag. For example, 10 transaction results are saved in the new block. When the eighth transaction result is processed, the target detector is restarted. After the restart, the target detector may query through the block tag and the transaction tag that the processing status of the eighth transaction result is in an unfinished state, and then continue to process the eighth transaction result.

[0228] In an embodiment of the present application, when the target detector is restarted, the transaction results that have not been completed can be determined by querying the transaction processing status of the new block so that processing can continue, which can ensure that the transaction results in the new block are processed and avoid data loss in the database.

[0229] At the same time, by setting the block mark of the block, the target detector can detect the new block and process the transaction results starting from the specified block mark, and by setting the transaction mark of the transaction result, data can be recovered by replaying the transaction result when data is lost.

[0230] It should be noted that the data synchronization method of the embodiment of the present application can be applied to any business scenario, including but not limited to registering on-chain objects, digital collections, evidence storage, traceability and other scenarios.

[0231] The following is an introduction to a blockchain-based business system to which the data synchronization method of an embodiment of the present application is applied, with reference to specific examples.

[0232] The blockchain-based business system of the embodiment of the present application can realize the following two functions: (1) multi-detector detection function based on block tags and transaction tags; (2) transaction processing function based on block tags and transaction tags.

[0233] The following is an example in which the block mark is the block number and the transaction mark is the transaction number.

[0234] (I) Multi-detector detection function based on block number and transaction number tags

[0235] The implementation of multi-instance detector based on block number labeling is as follows Fig.11 As shown, compared with the prior art Figure 3 The architecture diagram shown here mainly adds two types of services: multiple detectors and a highly reliable redis service (master-slave replica setup). When the business party joins the blockchain network, all services will be started. The detector starts detection with the block number and transaction number (for example, block 1 and transaction 0) as the mark, which includes the following processes:

[0236] 1) Joining the blockchain network: In a consortium chain, when a business party joins a blockchain network, it can deploy blockchain nodes to join the blockchain network, for example Fig.11 , the business party deploys three blockchain nodes (including blockchain node A, blockchain node B, and blockchain node C) to join the blockchain network; at the same time, in an embodiment of the present application, the business party can simultaneously deploy multiple detectors, for example, three detectors, namely detector A, detector B, and detector C, which are responsible for detecting the generation of new blocks.

[0237] If the business party enters the blockchain network when it is first built, the block number of the current new block is 1; at this time, multiple detectors will start detecting the generation of subsequent new blocks from block 1. At the same time, the [network ID, block number, transaction number, status] tuple can be inserted into the table in the database. block , records which transaction result of which block the current detector successfully processes. Among them, for this blockchain network, you can find it in Table block Only one quadruple is stored in the block, and the block number, transaction number and status in the quadruple are continuously updated; in addition, one quadruple can also be stored in each block, and there is no limitation on this.

[0238] Network ID: a unique ID that identifies the business party joining the network, such as the ID of Ethereum or other consortium chains;

[0239] Block number: indicates the block number of the current new block when joining the blockchain network, for example, 1;

[0240] Transaction number: represents the transaction result in a block that the detector has processed;

[0241] Status: Indicates whether the detector has successfully processed all transactions in the current block, for example, 0 means unfinished and 1 means completed.

[0242] 2) Object initiates request: For example, object A and object B initiate requests to the back-end service (i.e., the business service module in the above embodiment of the present application), respectively apply to register an on-chain object, and respectively provide object information (including name, ID number, public key, address, gender, hobbies, other attributes, etc.). The back-end service first uses a certain strategy to generate unique object IDs for object A and object B respectively, and then extracts some key or important attributes, such as the (object ID, name, ID number, public key) quadruple, and puts these data on the chain.

[0243] 3) Asynchronous transaction initiation: The backend service uses the locally stored certificate and private key, uses the corresponding SDK client, and constructs the transaction metadata using (object ID, name, ID number, public key), then signs with private key G, and finally calls the contract to construct a transaction result, which is sent asynchronously to any blockchain node, such as blockchain node A. The asynchronous method means that the SDK client will not wait for the execution result of the transaction result, but immediately returns the transaction identifier, such as TxId. Among them, a total of two transactions are sent through the SDK client, namely object A registers the object on the chain and object B registers the object on the chain.

[0244] 4) New block generation: Blockchain node A packages the two transactions, constructs a new block to execute the two transactions, obtains the transaction results of the two transactions, and reaches consensus with blockchain nodes B and C. After the consensus is successful, the transactions in the new block will be executed in blockchain nodes A, B, and C, and stored on disk.

[0245] 5) Detecting a new block: Since the three detectors subscribe to the new block events of blockchain node A, blockchain node B, and blockchain node C respectively, the three detectors can detect the generation of a new block. For example, the block number of the new block is N, and the block hash is Hash. The three detectors first connect to the redis service and call the setnx command provided by redis at a certain time interval (for example, 50ms):

[0246] setnx(key,value,time)

[0247] The setnx command is an atomic command. The value will be set successfully only when the key does not exist in redis. Among them, key = network ID + N, value is Hash, and time is the validity period of the key in redis. It can be adjusted according to the latest return time of the object request, for example, set to 2 seconds. If the key exists, the detector will receive an error message from redis that the key already exists (i.e., the call failed).

[0248] 6) Processing new blocks: Assuming that detector A successfully calls the setnx command in step 5), detector A obtains the processing right of the new block and starts processing the transaction results in it. Detectors B and C continue to call the setnx command provided by redis at a certain time interval (for example, 50ms) and keep failing. Every time the setnx command fails, detectors B and C can query the table Table in the database through the network ID. block , to confirm whether the current new block N has been processed.

[0249] Before processing the transaction results in the new block, detector A first queries the table Table in the database through the network ID block , to confirm whether the previous block N-1 has been processed. If the block number N-1 in the four-tuple [network ID, block number, transaction number, status] is obtained and the status is 1, it means that the previous block N-1 has been processed. Then [network ID, N, 1, 0] is updated to the table Table in the database block , indicating that it is ready to start processing the first transaction result in the new block N.

[0250] Specifically, detector A traverses each transaction result in block N and processes them in turn. After each successful processing of a transaction result, [network ID, N, Tx, 1] is updated to table Table block , where Tx is the transaction number of the currently processed transaction result; and then the next transaction result is processed until the last transaction result is processed.

[0251] When detector A processes the transaction results in the new block N, there may be two situations:

[0252] Case 1: Detector A successfully processes the transaction results of the new block N, and finally updates [Network Id, N, Tx, 1] to Table block , while detectors B and C keep calling the setnx command and fail. In one of the calls, they query the table Table in the database through the network ID. block , and query [network ID, N, Tx, 1], it can be determined that the new block N has been processed; then detector B and detector C give up calling the setnx command and start detecting the next new block.

[0253] Case 2: Detector A only processes part of the transaction results of the new block N. Assume there are a total of Tx transactions, and detector A only processes Tx-2 of them, that is, only [network ID, N, Tx-2, 0] is updated to table Table block , it crashes. At this time, the key = network ID + N in redis will expire after time, while detectors B and C are still calling the setnx command and have a chance to succeed. Assuming that detector B finally successfully calls the setnx command, detector B will take over the unfinished work of detector A; at this time, detector B queries the table Table in the database through the network ID block , query [network ID, N, Tx-2, 0], and start processing from the Tx-1th transaction of block N until the new block N is processed, and update [network ID, N, Tx, 1] to table Table block .

[0254] In the embodiment of the present application, by setting up multiple detectors, it is possible to ensure high reliability in processing and parsing each transaction result of each block, and finally write the on-chain data into the database. Even if most of the blockchain nodes or detectors of each blockchain node of the blockchain network crash, as long as at least one available blockchain node and detector is ensured to remain, the synchronization of the on-chain data can be completed, that is, the on-chain data can be written into the database.

[0255] The processing process of each transaction result by the detector in the above embodiment is introduced in part (ii) of the following embodiment.

[0256] (II) Transaction processing function based on block number and transaction number tags

[0257] The following uses a single detector to introduce the process of using the redis service to integrate data with the backend service. It can use the on-chain data and combine it with the business data to synchronize the complete business data to the database with high reliability.

[0258] like Fig.12 As shown, in step 3) of part (I), after the backend service uses the SDK client to asynchronously initiate a transaction, the following steps can be performed:

[0259] 1) The backend service sets context data to redis and waits:

[0260] After the backend service obtains the transaction identifier (TxId) from the SDK client, it constructs the unchained object attributes in the object information into a JSON string as the context data of this request, for example, expressed as Context, as shown below:

[0261] Context={"address":"Address","sex":"Gender","hobby":"Hobbies","others":"Other attributes"}

[0262] Afterwards, the backend service uses "txid / req / TxId" as the complete Key and Context as the Value and inserts it into redis, for example, using the Set interface provided by redis. To prevent redis data from expanding, the data aging can be set to 1 hour or even shorter, as shown below:

[0263] Set(txid / req / TxId,Context,1hour)

[0264] After that, the backend service enters the waiting stage, waiting for the notification from detector A; the backend service will continue to use "txid / resp / TxId" as the key, call the redis Get interface, and obtain the corresponding value to obtain the transaction return data Resp placed by detector A in redis:

[0265] Resp=Get(txid / resp / TxId)

[0266] The backend service can obtain the value corresponding to the above key from redis at a certain time interval (for example, 50ms) until the value is obtained or the set time limit (for example, 1s) is reached. If the value is obtained, the Resp in the value will be further processed; if it times out, an error will be directly reported to the terminal device of the object.

[0267] 2) Detector A processes the transaction:

[0268] Assuming that in step 5) of part (I), that is, after calling the setnx command, detector A obtains the right to process the new block, then detector A processes at least one transaction result in the new block one by one; taking the processing of the registered on-chain object as an example, the transaction result is parsed to obtain the on-chain data, that is, (object ID, name, ID number, public key, address representing the on-chain identity), and at the same time, with "txid / req / TxId" as the complete key, the Redis Get interface is called to obtain the context data placed in redis by the backend service with the same key:

[0269] Context=Get("txid / req / TxId")={"address":"address","sex":"sex","hobby":"hobbies","others":"other attributes"}

[0270] Afterwards, detector A integrates the on-chain data (i.e., the transaction return data in the above embodiment of the present application) and the context data into a complete object information and inserts it into the object table Table of the database. user The information inserted is:

[0271] User Info =(object ID, name, ID number, public key, address, gender, hobbies, address representing the identity on the chain, other attributes)

[0272] 3) Detector A updates the block number and transaction number:

[0273] When the above complete object information User Info The object table Table that is successfully written to the database userAfter that, detector A will update (block number N, transaction number Tx) to the database to indicate that detector A has successfully processed a transaction result; when detector A crashes unexpectedly, detectors B and detectors can take over the unfinished work of detector A based on step 6 of part (I) to ensure that the remaining transaction results can be successfully processed and the complete object information can be written to the database with high reliability.

[0274] 4) Set the return value to redis: The detector will call the Set interface of Redis, use "txid / resp / TxId" as the complete key, and write the following JSON string to redis, with the value of Resp, to notify the backend service

[0275] Resp = {"error":"error information","user":"object complete information"}

[0276] Set("txid / resp / TxId",Resp,1hour)

[0277] 5) The backend service obtains the transaction return data Resp from redis:

[0278] The backend service obtains the transaction return data set by detector A through redis, that is, the Resp set to redis in step 4):

[0279] Resp = {"error":"error information","user":"complete object information"}

[0280] If Resp is error, indicating an error, the error information is returned to the object's terminal device; otherwise, the object ID is taken from the complete object information and returned to the object's terminal device, indicating that the object is successfully registered as an on-chain object, which is convenient for subsequent operations.

[0281] The embodiment of the present application deploys multiple detectors and uses block numbers and transaction numbers as markers to record a transaction result in a block that has been successfully processed by the detector. When a detector that is processing a block crashes, other detectors can take over the processing of the remaining transaction results and write the on-chain data into the database with high reliability to ensure that the data is not lost, thereby ensuring the consistency of the on-chain data and the database data.

[0282] Moreover, the embodiment of the present application uses redis as an intermediary. Through the high availability of redis, any detector can safely and reliably obtain the context data of the backend service after obtaining the on-chain data, construct complete business data and write it into the database. In addition, with the block number and transaction number as a marker, the detector can continue to process the unfinished transaction results before the restart after restarting, ensuring the consistency of the on-chain data and the database data; at the same time, the detector can process the transaction results from the specified block number and the specified transaction number, so as to recover the data by replaying the transaction results when the data is lost.

[0283] It should be noted that the blockchain-based business system of the embodiment of the present application can be applied to any business scenario, including but not limited to registering on-chain objects, digital collections, evidence storage, traceability and other scenarios.

[0284] Based on the same inventive concept, an embodiment of the present application also provides a data synchronization device, the principle of which is similar to the video processing method of the above embodiment. Therefore, the implementation of the device can refer to the implementation of the above method, and the repeated parts will not be repeated.

[0285] like Fig.13 As shown, it is a schematic diagram of the structure of a data synchronization device, which may include:

[0286] The detection module 131 is used to detect new blocks generated by each blockchain node in the blockchain network, each new block is used to store the transaction result of the transaction constructed based on the business data;

[0287] The query module 132 is used to query the transaction processing status of the previous block of the new block from the database before processing the transaction result in the new block when a new block generated by any blockchain node among the blockchain nodes is detected; wherein the database is used to store the transaction processing status of the processed blocks;

[0288] The first processing module 133 is used to continue processing the transaction results in the previous block if it is found that the transaction processing status of the previous block is in an unfinished state, until the obtained transaction return data and corresponding business data are stored in the database, and the transaction processing status of the previous block in the database is updated from an unfinished state to a completed state.

[0289] In the embodiment of the present application, the new blocks generated by each blockchain node in the blockchain network are detected respectively. When any blockchain node is detected to generate a new block, before processing the transaction result in the new block, the transaction processing status of the previous block of the new block is first queried from the database according to the block mark of the new block. If it is in an unfinished state, the transaction result in the previous block is continued to be processed, so that the obtained transaction return data and the corresponding business data are stored in the database, and the transaction processing status of the previous block is updated to a completed state. In this way, the database can avoid data loss, ensure the data consistency of the on-chain data and the off-chain database, so that the on-chain transaction is successfully executed.

[0290] Optional, such as Fig.14 As shown, the device also includes:

[0291] The second processing module 134 is used to start processing the transaction results in the new block if the transaction processing status of the previous block is completed, and set the transaction processing status of the new block to an uncompleted state and save it in the database;

[0292] The storage module 135 is used to store the obtained transaction return data and corresponding business data in the database when the transaction result processing in the new block is completed, and to update the transaction processing status of the new block in the database from an unfinished state to a completed state.

[0293] Optionally, the new block has a corresponding block tag, and the new block includes multiple transaction results, each transaction result has a corresponding transaction tag, and the transaction processing status of the new block includes: the processing status of each of the multiple transaction results including the block tag and the transaction tag;

[0294] The second processing module 134 is specifically used for:

[0295] Whenever a transaction result in a new block is processed, the processing status of the transaction result is set to an unfinished state, and the processing status of the transaction result is saved in the database;

[0296] The storage module 135 is specifically used for:

[0297] Whenever a transaction result in a new block is processed, the transaction return data of the transaction result and the corresponding business data are stored in the database, and the processing status of the transaction result in the database is updated from an unfinished state to a completed state.

[0298] Optionally, the previous block has a corresponding block tag, and the previous block includes multiple transaction results, each transaction result has a corresponding transaction tag, and the transaction processing status of the previous block includes: the processing status of each of the multiple transaction results including the block tag and the transaction tag;

[0299] The first processing module 133 is specifically used for:

[0300] If the transaction processing status in the previous block is incomplete, continue to perform the following operations on at least one transaction result that has not been processed in the previous block:

[0301] When processing a transaction result in the previous block, the processing status of the transaction result is set to an unfinished state, and the processing status of the transaction result is saved in the database;

[0302] When the processing of a transaction result is completed, the transaction return data of the transaction result and the corresponding business data are stored in the database, and the processing status of the transaction result in the database is updated from an unfinished state to a completed state.

[0303] Optionally, the detection module 131 is specifically used for:

[0304] Using multiple detectors to detect new blocks generated by each blockchain node, respectively; wherein each blockchain node corresponds to at least one detector;

[0305] The query module 132 is specifically used for:

[0306] When a new block generated by a corresponding blockchain node is detected by multiple detectors respectively, before the transaction result in the new block is processed by any of the multiple detectors, the previous block of the new block is determined according to the block mark of the new block, and the transaction processing status of the previous block is queried from the database.

[0307] Optionally, the query module 132 specifically includes:

[0308] A calling submodule is used to call the specified commands of the remote dictionary service Redis through multiple detectors respectively; wherein the specified commands are used to cache the block mark of the new block in Redis;

[0309] A cache submodule, for caching the block mark of a new block to Redis after successfully calling a specified command to Redis through a target detector among multiple detectors;

[0310] The query submodule is used to determine the previous block of the new block according to the block mark of the new block before processing the transaction results in the new block through the target detector, and query the transaction processing status of the previous block from the database.

[0311] Optionally, the submodule is also called to:

[0312] By using other detectors among the multiple detectors except the target detector, the specified command of Redis is continuously called at intervals of a first set time period;

[0313] The device also includes:

[0314] The first return module is used to return call failure information to other detectors through Redis each time the specified command of Redis is called through other detectors, if it is determined through Redis that a block mark of a new block is cached.

[0315] Optionally, the device further comprises:

[0316] A deletion module is used to delete the block mark of the cached new block after a second set time through Redis;

[0317] The second return module is used to determine the block mark of the uncached new block through Redis when the specified command of Redis is continued to be called through other detectors except the target detector among the multiple detectors, and return the call success information to any detector among the other detectors;

[0318] The third processing module is used to obtain the transaction processing status of the new block from the database through any detector in the other detectors, and when it is determined that the transaction processing status of the new block is in an unfinished state, continue to process the transaction results in the new block.

[0319] Optionally, the device further comprises:

[0320] A sending module, used to construct key data in the business data into corresponding transactions through the business service module, and send the transactions to any blockchain node among the blockchain nodes, so that any blockchain node constructs a new block to save the transaction results obtained by executing the transaction;

[0321] A construction module is used to obtain the transaction identifier of the transaction result through the business service module, construct non-critical data in the business data into context data, and cache the context data and the transaction identifier in Redis in correspondence;

[0322] The storage module 135 is also used for:

[0323] When the transaction results in the new block are processed by the target detector, the context data is obtained from Redis based on the transaction identifier, and the obtained transaction return data and context data are stored in the database.

[0324] Optionally, the device further comprises:

[0325] The cache module is used to cache the acquired transaction return data into the context data in Redis through the target detector to obtain complete business data;

[0326] The third return module is used to obtain complete business data from Redis based on the transaction identifier through the business service module and process the complete business data.

[0327] Optionally, the device further comprises:

[0328] An acquisition module, used for acquiring the transaction processing status of the new block from the database through the target detector if the target detector is restarted during the process of processing the transaction result in the new block through the target detector;

[0329] The fourth processing module is used to continue processing the transaction results in the new block when the target detector determines that the transaction processing status of the new block is in an unfinished state.

[0330] For the convenience of description, the above parts are divided into modules (or units) according to their functions and described separately. Of course, when implementing this application, the functions of each module (or unit) can be implemented in the same or multiple software or hardware.

[0331] After introducing the data synchronization method and device according to the exemplary embodiment of the present application, next, an electronic device according to another exemplary embodiment of the present application is introduced.

[0332] Those skilled in the art will appreciate that various aspects of the present application may be implemented as a system, method or program product. Therefore, various aspects of the present application may be specifically implemented in the following forms, namely: a complete hardware implementation, a complete software implementation (including firmware, microcode, etc.), or a combination of hardware and software, which may be collectively referred to as "circuit", "module" or "system" herein.

[0333] Based on the same inventive concept as the above method embodiment, an electronic device is also provided in the embodiment of the present application. In one embodiment, the electronic device may be a server, such as Figure 4 In this embodiment, the structure of the electronic device can be as follows: Fig.15 As shown, it includes a memory 1501 , a communication module 1503 and one or more processors 1502 .

[0334] The memory 1501 is used to store computer programs executed by the processor 1502. The memory 1501 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system and programs required for running the instant messaging function, etc.; the data storage area may store various instant messaging information and operation instruction sets, etc.

[0335] The memory 1501 may be a volatile memory, such as a random-access memory (RAM); the memory 1501 may also be a non-volatile memory, such as a read-only memory, a flash memory, a hard disk drive (HDD) or a solid-state drive (SSD); or the memory 1501 may be any other medium that can be used to carry or store a desired computer program in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory 1501 may be a combination of the above memories.

[0336] The processor 1502 may include one or more central processing units (CPU) or a digital processing unit, etc. The processor 1502 is used to implement the above data synchronization method when calling the computer program stored in the memory 1501 .

[0337] The communication module 1503 is used to communicate with terminal devices and other servers.

[0338] The specific connection medium between the memory 1501, the communication module 1503 and the processor 1502 is not limited in the embodiment of the present application. Fig.15 In the embodiment, the memory 1501 and the processor 1502 are connected via a bus 1504. The bus 1504 is connected to the processor 1502 via a bus 1504. Fig.15 The connections between the other components are described with bold lines, which are only for illustration and are not intended to be limiting. The bus 1504 can be divided into an address bus, a data bus, a control bus, etc. For ease of description, Fig.15 The diagram shows that only one thick line is used, but this does not mean that there is only one bus or only one type of bus.

[0339] The memory 1501 stores a computer storage medium, and the computer storage medium stores computer executable instructions, and the computer executable instructions are used to implement the data synchronization method of the embodiment of the present application. The processor 1502 is used to execute the above-mentioned data synchronization method, such as Figure 5 shown.

[0340] In an exemplary embodiment, the present application further provides a storage medium including a computer program, such as a memory 1501 including a computer program, and the computer program can be executed by a processor 1502 of an electronic device to complete the above data synchronization method. Optionally, the storage medium can be a non-temporary computer-readable storage medium, for example, the non-temporary computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.

[0341] In another embodiment, the electronic device may also be other electronic devices, such as Figure 4 The terminal device 110 shown in FIG. 1 is a terminal device 110 shown in FIG. 1 . In this embodiment, the structure of the electronic device can be as follows: Fig.16 As shown, it includes: a communication component 1610, a memory 1620, a display unit 1630, a camera 1640, a sensor 1650, an audio circuit 1660, a Bluetooth module 1670, a processor 1680 and other components.

[0342] The communication component 1610 is used to communicate with the server. In some embodiments, a wireless fidelity (WiFi) module may be included. The WiFi module belongs to a short-range wireless transmission technology. The electronic device can help the object to send and receive information through the WiFi module.

[0343] The memory 1620 can be used to store software programs and data. The processor 1680 executes various functions and data processing of the terminal device 110 by running the software programs or data stored in the memory 1620. The memory 1620 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage device. The memory 1620 stores an operating system that enables the terminal device 110 to run. In the present application, the memory 1620 can store an operating system and various application programs, and can also store a computer program for executing the data synchronization method of the embodiment of the present application.

[0344] The display unit 1630 may also be used to display information input by an object or information provided to an object and a graphical user interface (GUI) of various menus of the terminal device 110. Specifically, the display unit 1630 may include a display screen 1632 disposed on the front of the terminal device 110. The display screen 1632 may be configured in the form of a liquid crystal display, a light emitting diode, or the like.

[0345] The display unit 1630 can also be used to receive input digital or character information, and generate signal input related to the object setting and function control of the terminal device 110. Specifically, the display unit 1630 may include a touch screen 1631 arranged on the front of the terminal device 110, which can collect touch operations of objects on or near it, such as clicking a button, dragging a scroll box, etc.

[0346] The touch screen 1631 can be covered on the display screen 1632, or the touch screen 1631 and the display screen 1632 can be integrated to realize the input and output functions of the terminal device 110. The integrated touch screen can be referred to as a touch display screen. In this application, the display unit 1630 can display the application and the corresponding operation steps.

[0347] The camera 1640 can be used to capture static images, and the object can publish the image taken by the camera 1640 through the application. The camera 1640 can be one or more. The object generates an optical image through the lens and projects it onto the photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the optical signal into an electrical signal, and then passes the electrical signal to the processor 1680 to convert it into a digital image signal.

[0348] The terminal device may further include at least one sensor 1650, such as an acceleration sensor 1651, a distance sensor 1652, a fingerprint sensor 1653, and a temperature sensor 1654. The terminal device may also be configured with other sensors such as a gyroscope, a barometer, a hygrometer, a thermometer, an infrared sensor, a light sensor, and a motion sensor.

[0349] The audio circuit 1660, the speaker 1661, and the microphone 1662 can provide an audio interface between the object and the terminal device 110. The audio circuit 1660 can transmit the electrical signal converted from the received audio data to the speaker 1661, which is converted into a sound signal for output. The terminal device 110 can also be configured with a volume button for adjusting the volume of the sound signal. On the other hand, the microphone 1662 converts the collected sound signal into an electrical signal, which is received by the audio circuit 1660 and converted into audio data, and then the audio data is output to the communication component 1610 to be sent to, for example, another terminal device 110, or the audio data is output to the memory 1620 for further processing.

[0350] The Bluetooth module 1670 is used to exchange information with other Bluetooth devices having Bluetooth modules through the Bluetooth protocol. For example, the terminal device can establish a Bluetooth connection with a wearable electronic device (such as a smart watch) that also has a Bluetooth module through the Bluetooth module 1670 to exchange data.

[0351] The processor 1680 is the control center of the terminal device. It uses various interfaces and lines to connect various parts of the entire terminal device. It executes various functions of the terminal device and processes data by running or executing software programs stored in the memory 1620 and calling data stored in the memory 1620. In some embodiments, the processor 1680 may include one or more processing units; the processor 1680 may also integrate an application processor and a baseband processor, wherein the application processor mainly processes the operating system, object interface and application program, and the baseband processor mainly processes wireless communication. It is understandable that the above-mentioned baseband processor may not be integrated into the processor 1680. In the present application, the processor 1680 can run the operating system, application program, object interface display and touch response, and the data synchronization method of the embodiment of the present application. In addition, the processor 1680 is coupled to the display unit 1630.

[0352] In some possible implementations, various aspects of the data synchronization method provided by the present application may also be implemented in the form of a program product, which includes a computer program. When the program product is run on an electronic device, the computer program is used to enable the electronic device to execute the steps of the data synchronization method according to various exemplary implementations of the present application described above in this specification. For example, the electronic device may execute the following steps: Figure 5 Follow the steps shown in .

[0353] The program product may use any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of readable storage media (a non-exhaustive list) include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.

[0354] The program product of the embodiment of the present application may adopt a portable compact disk read-only memory (CD-ROM) and include a computer program, and can be run on an electronic device. However, the program product of the present application is not limited thereto, and in this document, a readable storage medium may be any tangible medium containing or storing a program, which can be used by or in combination with a command execution system, apparatus, or device.

[0355] A readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, wherein a readable computer program is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the foregoing. A readable signal medium may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with a command execution system, apparatus, or device.

[0356] The computer program embodied on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.

[0357] Computer programs for performing the operations of the present application may be written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Java, C++, etc., and conventional procedural programming languages ​​such as "C" or similar programming languages. The computer program may be executed entirely on the user electronic device, partially on the user electronic device, as a separate software package, partially on the user electronic device and partially on a remote electronic device, or entirely on a remote electronic device or server. In cases involving remote electronic devices, the remote electronic device may be connected to the subject electronic device via any type of network including a local area network (LAN) or a wide area network (WAN), or may be connected to an external electronic device (e.g., via the Internet using an Internet service provider).

[0358] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain a computer-usable computer program.

[0359] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of the present application.

[0360] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.

Claims

1. A data synchronization method, It is characterized in that The method comprises: Respectively detecting new blocks generated by each blockchain node in the blockchain network, each of the new blocks being used to store transaction results of transactions constructed based on business data; When a new block generated by any of the blockchain nodes is detected, before processing the transaction result in the new block, query the transaction processing status of the previous block of the new block from the database; wherein the database is used to store the transaction processing status of the processed blocks; If it is found that the transaction processing status of the previous block is in an unfinished state, the transaction results in the previous block will continue to be processed until the obtained transaction return data and the corresponding business data are stored in the database, and the transaction processing status of the previous block in the database is updated from an unfinished state to a completed state.

2. The method according to claim 1, It is characterized in that The method further comprises: If the transaction processing status of the previous block is in the completed state, start processing the transaction result in the new block, and set the transaction processing status of the new block to an uncompleted state and save it in the database; When the transaction result processing in the new block is completed, the obtained transaction return data and the corresponding business data are stored in the database, and the transaction processing status of the new block in the database is updated from an unfinished state to a completed state.

3. The method according to claim 2, It is characterized in that The new block has a corresponding block tag, and the new block includes multiple transaction results, each transaction result has a corresponding transaction tag, and the transaction processing status of the new block includes: the processing status of each of the multiple transaction results including the block tag and the transaction tag; The starting to process the transaction result in the new block, and setting the transaction processing status of the new block to an unfinished state and saving it in the database includes: Whenever a transaction result in the new block is processed, the processing status of the transaction result is set to an unfinished state, and the processing status of the transaction result is saved in the database; When the transaction result processing in the new block is completed, the obtained transaction return data and the corresponding business data are stored in the database, and the transaction processing status of the new block in the database is updated from an unfinished state to a completed state, including: Whenever a transaction result in the new block is processed, the transaction return data and corresponding business data of the transaction result are stored in the database, and the processing status of the transaction result in the database is updated from an unfinished state to a completed state.

4. The method according to claim 1, It is characterized in that The previous block has a corresponding block tag, and the previous block includes multiple transaction results, each transaction result has a corresponding transaction tag, and the transaction processing status of the previous block includes: the processing status of each of the multiple transaction results including the block tag and the transaction tag; If the transaction processing status of the previous block is in an unfinished state, continue to process the transaction results in the previous block until the obtained transaction return data and the corresponding business data are stored in the database, and the transaction processing status of the previous block in the database is updated from an unfinished state to a completed state, including: If the transaction processing status in the previous block is in an unfinished state, continue to perform the following operations in sequence for at least one transaction result that has not been processed in the previous block: When processing a transaction result in the previous block, setting the processing status of the transaction result to an unfinished state, and saving the processing status of the transaction result to the database; When the processing of the transaction result is completed, the transaction return data and corresponding business data of the transaction result are stored in the database, and the processing status of the transaction result in the database is updated from an unfinished state to a completed state.

5. The method according to any one of claims 1 to 4, It is characterized in that The respectively detecting new blocks generated by each blockchain node in the blockchain network includes: Using a plurality of detectors, respectively detecting the new blocks generated by each of the blockchain nodes; wherein each blockchain node corresponds to at least one detector; When a new block generated by any of the blockchain nodes is detected, before processing the transaction result in the new block, querying the transaction processing status of the previous block of the new block from the database includes: When new blocks generated by corresponding blockchain nodes are detected respectively by the multiple detectors, before the transaction results in the new blocks are processed by any of the multiple detectors, the transaction processing status of the previous block of the new block is queried from the database.

6. The method according to claim 5, It is characterized in that Before processing the transaction result in the new block by any detector among the multiple detectors, querying the transaction processing status of the previous block of the new block from the database includes: The multiple detectors are used to respectively call a specified command of a remote dictionary service Redis; wherein the specified command is used to cache a block mark of the new block in the Redis; After successfully calling the specified command of the Redis through the target detector among the multiple detectors, caching the block mark of the new block in the Redis; Before the target detector processes the transaction result in the new block, the transaction processing status of the previous block of the new block is queried from the database.

7. The method according to claim 6, It is characterized in that After successfully calling the specified command to the Redis through the target detector among the multiple detectors, the method further includes: Continue to call the specified command of Redis every first set time period through other detectors among the multiple detectors except the target detector; Each time the specified command of Redis is called by the other detector, if it is determined by Redis that the block mark of the new block is cached, call failure information is returned to the other detector by Redis.

8. The method according to claim 6, It is characterized in that After caching the block mark of the new block in the Redis, the method further includes: After a second set time period, the block mark of the cached new block is deleted by the Redis; When the specified command of the Redis is continuously called through other detectors among the multiple detectors except the target detector, the block mark of the new block is determined by the Redis and is not cached, and a call success message is returned to any detector among the other detectors; The transaction processing status of the new block is obtained from the database through any detector among the other detectors, and when it is determined that the transaction processing status of the new block is in an unfinished state, the transaction result in the new block continues to be processed.

9. The method according to claim 6, It is characterized in that Before respectively detecting the new blocks generated by each blockchain node in the blockchain network, the method further includes: Constructing key data in the business data into corresponding transactions through the business service module, and sending the transactions to any blockchain node among the blockchain nodes, so that any blockchain node constructs a new block to save the transaction results obtained by executing the transactions; Obtaining a transaction identifier of the transaction result through the business service module, constructing non-critical data in the business data as context data, and caching the context data and the transaction identifier in the Redis in correspondence; The method further comprises: When the target detector completes processing of the transaction result in the new block, the context data is obtained from the Redis based on the transaction identifier, and the obtained transaction return data and the context data are stored in the database.

10. The method according to claim 9, It is characterized in that After obtaining the context data from the Redis based on the transaction identifier, the method further includes: The acquired transaction return data is cached into the context data in the Redis through the target detector to obtain complete business data; Through the business service module, the complete business data is obtained from the Redis based on the transaction identifier, and the complete business data is processed.

11. The method according to claim 5, It is characterized in that The method further comprises: In the process of processing the transaction result in the new block by the target detector, if the target detector is restarted, the transaction processing status of the new block is obtained from the database by the target detector; When the target detector determines that the transaction processing status of the new block is an unfinished state, the transaction result in the new block continues to be processed.

12. A data synchronization device, It is characterized in that The device comprises: A detection module, used to respectively detect new blocks generated by each blockchain node in the blockchain network, each of which is used to store transaction results of transactions constructed based on business data; A query module, configured to query the transaction processing status of the previous block of the new block from a database before processing the transaction result in the new block when a new block generated by any of the blockchain nodes is detected; wherein the database is used to store the transaction processing status of the processed blocks; The first processing module is used to continue processing the transaction results in the previous block if the transaction processing status of the previous block is in an unfinished state, until the obtained transaction return data and corresponding business data are stored in the database, and the transaction processing status of the previous block in the database is updated from an unfinished state to a completed state.

13. An electronic device, It is characterized in that The method comprises a processor and a memory, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of any one of the methods of claims 1 to 11.

14. A computer-readable storage medium, It is characterized in that The method comprises a computer program. When the computer program is run on an electronic device, the computer program is used to enable the electronic device to execute the steps of any one of the methods of claims 1 to 11.

15. A computer program product, It is characterized in that The method comprises a computer program stored in a computer-readable storage medium; when a processor of an electronic device reads the computer program from the computer-readable storage medium, the processor executes the computer program, so that the electronic device executes the steps of any one of the methods described in claims 1 to 11.