Credible block chain on-chain and off-chain data synchronization method and system and medium
By integrating oracle and chain SDK, combined with block subscription and database triggers, efficient and reliable data synchronization on-chain and off-chain data synchronization is achieved, solving the problems of cumbersome and slow synchronization process in the existing technology, and improving data synchronization efficiency and credibility.
Patent Information
- Application Number
- CN202510448749.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-10
- Publication Date
- 2025-07-11
AI Technical Summary
The lack of a mature and trusted chain on-chain data synchronization system in the prior art has resulted in a cumbersome data synchronization process and slow response speed.
By integrating oracle and chain SDK, using the block subscription function of the chain SDK, oracle contracts are deployed on the blockchain, oracle services are developed and deployed outside the blockchain, and database triggers are created in the off-chain database to realize forward synchronization on-chain and reverse synchronization off-chain to on-chain.
The efficiency of data synchronization on and off-chain is improved, data consistency and credibility are ensured, human intervention is eliminated, and operation atomicity is guaranteed through the rollback mechanism.
Smart Images

Figure CN120296094A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of blockchain technology, and in particular to a blockchain data synchronization method. Background Art
[0002] Currently, as the data support of web systems, blockchain is difficult to meet multi-condition queries or complex statistical queries. Usually, an off-chain cache database is used to synchronize on-chain data to meet business requirements. However, the cache database is often in a centralized and controllable form, and there is a risk of data tampering during the on-chain and off-chain data synchronization process.
[0003] Prior Art One: An on-chain and off-chain hybrid storage method based on a blockchain distributed ledger and a database, with the publication number CN114020797A, discloses an on-chain and off-chain hybrid storage method based on a blockchain distributed ledger and a database. By constructing an on-chain and off-chain hybrid storage mechanism based on a blockchain distributed ledger and a database, it helps data providers avoid large-scale data being uploaded to the chain and solve the problem that data of types such as pictures cannot be uploaded to the chain, and helps data users use and access the data stored in the off-chain database more conveniently through the blockchain platform; among them, Hyperledger Fabric used can provide features such as immutability and traceability for this invention, while openGauss provides a solution to meet enterprise-level scenario requirements for data providers. This invention proposes a more secure and reliable data usage solution for data users and data providers.
[0004] Prior Art Two: A data interaction method based on on-chain and off-chain collaboration of a blockchain, with the publication number CN110673966A, relates to the field of computer blockchain technology and provides a data interaction method based on on-chain and off-chain collaboration of a blockchain. First, construct an on-chain and off-chain collaborative interaction framework; when a user requests to write / update data, write / modify the original data in the off-chain data center, extract the data digest from the original data / to-be-modified data and sign it, select a primary node to construct a block and connect it to the blockchain, and then notify other nodes to synchronize; when a user requests to query data, send a signature to the verification node, the verification node queries the on-chain data and broadcasts the data. When more than half of the verification nodes query the same data, select a primary node. The primary node queries the original data from the off-chain data center and extracts the data digest, and compares the on-chain data with the off-chain data. If they are consistent, return the user's query permission; if they are inconsistent, notify the user that the data is damaged. This invention can ensure data security and integrity, and is fast when performing large-scale data interactions.
[0005] Most of the existing technologies introduce a data support system of blockchain + database, such as the first existing technology. Under this data support system, there is no complete and reliable data synchronization method. As described in the second existing technology, it takes blockchain as the leading factor, extracts data digests, completes data mutual recognition through steps such as consensus and broadcasting, and then compares the off-chain data. The process is cumbersome and the reaction speed is slow. Summary of the Invention
[0006] This application provides a method, system and medium for trusted on-chain and off-chain data synchronization of blockchain, aiming to solve the problem that there is no mature and trusted on-chain and off-chain data synchronization system in the existing technology.
[0007] In the first aspect, a method for trusted on-chain and off-chain data synchronization of blockchain is provided. The method is based on integrating an oracle and a chain SDK for the blockchain additionally, using the chain SDK to implement the block subscription function, deploying an oracle contract on the blockchain, developing and deploying an oracle service outside the blockchain, and creating a database trigger in the off-chain database. The method includes: forward synchronization from on-chain to off-chain of the blockchain and reverse synchronization from off-chain to on-chain.
[0008] The forward synchronization includes:
[0009] The user initiates a data update operation on the blockchain through the user contract, and the updated data is stored on the blockchain in the data structure form of key-value pairs; wherein, the value contains a unique association number.
[0010] The user contract calls the oracle contract to request synchronizing the updated data to the off-chain database.
[0011] The oracle contract verifies the corresponding parameters and sends the corresponding chain event.
[0012] The chain SDK subscribes to the chain event through the block subscription function, obtains the data update type to which the chain event belongs, and parses the chain event parameters; wherein, the data to which the chain event belongs contains a unique association number.
[0013] The middleware synchronizes the data update situation to the database according to the unique association number.
[0014] The reverse synchronization includes:
[0015] When the data in the database changes, the database trigger monitors the data change and responds; wherein, the database table structure contains a unique association number.
[0016] The oracle service detects the notification from the database trigger, obtains the data update situation, and executes the oracle contract for data synchronization.
[0017] The oracle contract notifies the user contract through a callback that the data has been retrieved. The user contract receives the data and updates the on-chain storage in the form of a key-value data structure based on the unique correlation number.
[0018] In the above solution, optionally, creating a database trigger in the off-chain database includes:
[0019] Create a trigger function in PostgreSQL that will send a notification when data is inserted or updated;
[0020] Implement listening for the notifications sent by the trigger function in PostgreSQL through a database driver.
[0021] In the above solution, optionally, creating a database trigger in the off-chain database includes:
[0022] When the database does not support the LISTEN / NOTIFY notification mechanism, set up a message queue;
[0023] Configure the database trigger to set up an intermediate layer to forward trigger events to the message queue. Specifically: use the database trigger to insert event information into an intermediate table, and then use an external process to monitor the intermediate table and forward the event to the message queue; among them, write a Go language program to forward the event;
[0024] Configure a message queue listener in the Go application to receive and process messages when an event occurs.
[0025] In the above solution, further optionally, the message queue is RabbitMQ or Kafka.
[0026] In the above solution, optionally, it further includes:
[0027] Set up a rollback mechanism for the blockchain to ensure the atomicity of the operation of on-chain and off-chain data synchronization of the blockchain.
[0028] In the above solution, further optionally, it further includes:
[0029] When forward synchronization or reverse synchronization fails, perform a failure retry for a preset number of times. If it still fails, execute the failure rollback mechanism.
[0030] In the above solution, optionally, the off-chain database has no external interface throughout the process. The business is only initiated from the chain side, and data synchronization is also initiated from the chain side.
[0031] In a second aspect, a system for trusted on-chain and off-chain data synchronization of a blockchain is provided. The system includes:
[0032] A blockchain is used to deploy user contracts and oracle contracts, and store data in the form of a key-value data structure, where the value contains a unique association number;
[0033] An oracle service is deployed outside the blockchain, used to detect notifications of database triggers, obtain data updates of the off-chain database, and execute oracle contracts for data synchronization operations;
[0034] A chain SDK is integrated into the blockchain platform, with a block subscription function, capable of subscribing to chain events and parsing chain event parameters;
[0035] Middleware synchronizes the on-chain data update situation to the off-chain database according to the unique association number included in the chain event;
[0036] An off-chain database is used to store data, and when the data changes, it monitors the data change through a database trigger and issues a notification. The database table structure contains a unique association number;
[0037] Among them, the system realizes the forward synchronization from the blockchain on-chain to off-chain and the reverse synchronization from off-chain to on-chain;
[0038] The forward synchronization process is as follows: The user initiates a data update operation on the blockchain through a user contract. The user contract calls the oracle contract to request synchronizing the updated data to the off-chain database. The oracle contract verifies the parameters and sends a chain event. The chain SDK subscribes to the chain event and synchronizes the data update situation to the off-chain database according to the unique association number;
[0039] The reverse synchronization process is as follows: When the data in the off-chain database changes, the database trigger monitors the data change and responds. The oracle service detects the database trigger notification, obtains the data update situation, and executes the oracle contract for data synchronization. The oracle contract informs the user that the data has been retrieved by calling back the user contract. The user contract receives the data and updates the on-chain storage in the form of a key-value data structure according to the unique association number.
[0040] In a third aspect, a computer device is provided, including a memory, a processor, and a computer program stored on the memory. The processor executes the computer program to implement the steps of the above method.
[0041] In a fourth aspect, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above method are implemented.
[0042] Compared with the prior art, the present application has at least the following beneficial effects:
[0043] This application is based on further analysis and research on the lack of a mature and reliable on-chain and off-chain data synchronization system in existing blockchain data synchronization technologies, and realizes the need for an efficient and reliable two-way data synchronization mechanism to solve these problems. By integrating an oracle and a chain SDK, using the block subscription function of the chain SDK, deploying an oracle contract on the blockchain, developing and deploying an oracle service outside the blockchain, and creating a database trigger in the off-chain database, forward synchronization from the blockchain on-chain to off-chain and reverse synchronization from off-chain to on-chain are achieved. In forward synchronization, the user initiates a data update operation through a user contract, the user contract calls the oracle contract to request synchronization, the chain SDK subscribes to chain events, and the middleware synchronizes the data update situation to the database according to the unique association number; in reverse synchronization, the database trigger monitors data changes, the oracle service executes the oracle contract for data synchronization after detecting the notification, and updates the on-chain storage by calling back the user contract. Thus, the effects of improving the efficiency of on-chain and off-chain data synchronization of the blockchain, ensuring data consistency, and enhancing the reliability of data interaction are achieved.
[0044] This application automatically realizes data synchronization through mechanisms such as block subscription and database triggers, cancels manual intervention, and ensures the atomicity of operations through a rollback mechanism.
[0045] This application provides a method for trusted on-chain and off-chain data synchronization of a blockchain, expands the solution for on-chain and off-chain data synchronization, improves the data synchronization efficiency, and enhances the data trust level; this application also designs a system accordingly, which automatically realizes data synchronization through mechanisms such as block subscription and database triggers, cancels manual intervention, and improves the data trust level. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] Figure 1 It is a schematic flowchart of a method for trusted on-chain and off-chain data synchronization of a blockchain provided by an embodiment of this application.
[0047] Figure 2 It is a schematic overall flowchart of the working principle of an oracle provided by an embodiment of this application.
[0048] Figure 3 It is a schematic flowchart of data synchronization initiated by the chain end provided by an embodiment of this application.
[0049] Figure 4 It is a schematic flowchart of data synchronization initiated by the database end provided by an embodiment of this application. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0050] In order to make the objectives, technical solutions, and advantages of this application clearer, the following further elaborates on this application in combination with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain this application and are not used to limit this application.
[0051] In the description of the present application: Unless otherwise specified, expressions such as "including", "comprising", "having", etc. also mean "not limited to" (certain units, components, materials, steps, etc.).
[0052] At present, as the data support of the web system, the blockchain is difficult to meet multi-condition queries or complex statistical queries. Usually, the blockchain is combined with an off-chain cache database to meet the requirements. And at present, there is no mature on-chain and off-chain data synchronization system. The main technical problem to be solved by this invention patent is: to propose a method and design a set of systems accordingly. The system monitors the on-chain and off-chain data changes by subscribing to blockchain transactions and database trigger mechanisms, and uses blockchain oracle technology to update the on-chain and off-chain data. It provides a new solution to the problem of the lack of a mature and reliable on-chain and off-chain data synchronization.
[0053] The purpose of the present application is: to solve the problems raised in the above background technology, to provide a method and system for reliable on-chain and off-chain data synchronization of the blockchain. By integrating components such as blockchain oracles and database triggers, a complete two-way data synchronization solution is provided. Although the system cannot handle all on-chain and off-chain data synchronization anomalies, it can be used as a preferred solution and applied in many scenarios to improve the on-chain and off-chain data synchronization efficiency and the data credibility.
[0054] In one embodiment, as Figure 1 shown, a method for reliable on-chain and off-chain data synchronization of the blockchain is provided. The method is based on integrating an oracle and a chain SDK for the blockchain, using the chain SDK to implement the block subscription function, deploying an oracle contract on the blockchain, developing and deploying an oracle service outside the blockchain, and creating a database trigger in the off-chain database. The method includes: forward synchronization from the blockchain on-chain to off-chain and reverse synchronization from the off-chain to on-chain;
[0055] The forward synchronization includes:
[0056] The user initiates a data update operation on the blockchain through the user contract, and the updated data is stored on the blockchain in the form of a key-value pair data structure; wherein, the value contains a unique association number;
[0057] The user contract calls the oracle contract to request synchronizing the updated data to the off-chain database;
[0058] The oracle contract verifies the corresponding parameters and sends the corresponding chain event;
[0059] The chain SDK subscribes to chain events through the block subscription function, obtains the data update type to which the chain events belong, and parses the chain event parameters; among them, the data to which the chain events belong contains a unique association number;
[0060] The middleware synchronizes the data update situation to the database according to the unique association number;
[0061] Reverse synchronization includes:
[0062] When the data in the database changes, the database trigger monitors the data change and responds; among them, the database table structure contains a unique association number;
[0063] The oracle service detects the notification from the database trigger, obtains the data update situation, and executes the oracle contract for data synchronization;
[0064] The oracle contract notifies the user contract through a callback that the data has been obtained, and the user contract receives the data and updates the on-chain storage in the form of a key-value pair data structure according to the unique association number;
[0065] In Figure 1 the dotted arrow represents the forward synchronization process, and the solid arrow represents the reverse synchronization process.
[0066] In this embodiment, the present application discloses a method and system for synchronizing data on and off the chain of a trusted blockchain, which automatically realizes data synchronization through mechanisms such as block subscription and database triggers, cancels manual intervention, and ensures the atomicity of operations through a rollback mechanism. The system implementation: stipulate the on-chain key-value pair data structure and database table structure in the smart contract, and at the same time set up a database trigger to monitor data changes. Taking the chain-side data as the synchronization initiator, when new data is uploaded to the chain, the system perceives the data addition / update situation in the form of subscribing to transactions through the chain sdk, and updates the data in the database (including the failure retry and failure rollback mechanisms). At the same time, it supports the reverse data synchronization form: in some special cases, when the data update is initiated by modifying the data in the database, the system monitors the database trigger through the chain-side oracle component and initiates a new data upload request (including the failure retry and failure rollback mechanisms).
[0067] The key points of the present application are:
[0068] Provide a method for synchronizing data on and off the chain of a trusted blockchain, expand the solution for synchronizing data on and off the chain, improve the data synchronization efficiency, and improve the data trust level;
[0069] Accordingly, a set of systems is designed. This system automatically realizes data synchronization through mechanisms such as block subscription and database triggers, cancels manual intervention, and improves the data trust level;
[0070] The system provides a complete two-way data synchronization solution. Although it cannot handle all on-chain and off-chain data synchronization anomalies, it can be considered as a preferred solution.
[0071] In the data support system of blockchain + off-chain database, a unique associated number (bzId) is required to associate on-chain and off-chain data. The general storage form of on-chain data is in key-value form. Taking bzId = 12345678 as an example, the on-chain data structure of the present invention is shown in Table 1 below:
[0072] Table 1
[0073]
[0074] The database table structure is shown in Table 2 below:
[0075] Table 2
[0076] id bzId userId age Data type string string string string Sample data 111 12345678 112233 21
[0077] The following is the working principle of the oracle. Refer to Figure 2 , the reverse synchronization of this application uses half of the process of the oracle function. Among them, the overall process of the chain-side oracle is as follows:
[0078] The user calls the data fetching method in the oracle smart contract in the smart contract. The oracle smart contract verifies the corresponding parameters and sends the corresponding chain event;
[0079] The oracle service listens to the on-chain data fetching event and obtains the data according to the data fetching configuration specified in the contract;
[0080] The oracle service passes the fetched data back by calling the oracle smart contract method. The oracle smart contract notifies the user that the data has been fetched by calling back the user smart contract, and the user contract can perform corresponding business processing.
[0081] In one embodiment, creating a database trigger in the off-chain database includes:
[0082] Create a trigger function in PostgreSQL, and this trigger function will send a notification when data is inserted or updated;
[0083] Implement listening to the notifications sent by the trigger function in PostgreSQL through the database driver.
[0084] In one embodiment, the database driver is the github.com / lib / pq driver in the Go language. In specific implementations, corresponding drivers in other computer languages can also be used according to actual situations, and the present application does not make specific limitations.
[0085] Specific implementation 1 of database - side trigger (PostgreSQL):
[0086] 1. Set up PostgreSQL triggers and functions.
[0087] First, a trigger function needs to be created in PostgreSQL, which will send notifications when data is inserted or updated.
[0088]
[0089] 2. Listen for notifications in Go.
[0090] Use the github.com / lib / pq driver in Go to listen for PostgreSQL notifications.
[0091]
[0092]
[0093] In one embodiment, creating a database trigger in an off - chain database includes:
[0094] When the database does not support the LISTEN / NOTIFY notification mechanism, set up a message queue;
[0095] Configure the database trigger, set up an intermediate layer to forward trigger events to the message queue. Specifically: use the database trigger to insert event information into an intermediate table, and then use an external process to monitor the intermediate table and forward the event to the message queue; among them, write a Go language program to forward the event;
[0096] Configure a message queue listener in the Go application to receive and process messages when an event occurs.
[0097] In one embodiment, the message queue is RabbitMQ or Kafka. In this embodiment, the message queue can also be other message queue systems, such as ActiveMQ, RocketMQ, Redis, and the present application does not make specific restrictions.
[0098] In this embodiment, specific implementation 2 of database - side trigger (MySQL):
[0099] Since MySQL itself does not support a notification mechanism like PostgreSQL's LISTEN / NOTIFY, similar functions can be implemented in other ways. For example, use a trigger to insert messages into a message queue (such as RabbitMQ, Kafka), and then listen for these messages in the Go application.
[0100] 1. Set up a message queue;
[0101] 2. Configure MySQL triggers;
[0102] Set up an intermediate layer to forward trigger events to the message queue. For example, use a trigger to insert event information into an intermediate table, and then use an external process to monitor this table and forward the events to the message queue.
[0103]
[0104] 3. Write a Go program to forward events;
[0105]
[0106]
[0107]
[0108] 4. Listen for messages in the Go application.
[0109]
[0110]
[0111]
[0112] In one embodiment, it further includes: setting up a rollback mechanism for the blockchain to ensure the atomicity of the operation of data synchronization between the on-chain and off-chain of the blockchain.
[0113] In one embodiment, it further includes: when the forward synchronization or reverse synchronization fails, perform a failure retry. If the retry reaches the preset number of times and still fails, then execute the failure rollback mechanism.
[0114] In one embodiment, the off-chain database has no external interface throughout the process. The business is only initiated from the chain side, and the data synchronization is also initiated from the chain side.
[0115] In this embodiment, the principles and processes of data synchronization between the trusted on-chain and off-chain of the blockchain are as follows:
[0116] Reference Figure 3 , forward synchronization: that is, the off-chain database has no external interface throughout the process. The business is only initiated from the chain side, and the data synchronization is also initiated from the chain side. The system of the present invention encapsulates the chain sdk, obtains the latest transactions of the blockchain in the form of subscribing to transactions, senses the addition / modification of data, and can complete the data update in the off-chain database.
[0117] Reference Figure 4, Reverse synchronization: That is, in some special cases, developers need to directly adjust the data in the database. When the data in the database is adjusted, the trigger component of the database will be automatically triggered by the system of the present invention. At the same time, the oracle component on the blockchain side will perceive the trigger component of the database in real time, obtain the data update situation, and automatically execute the smart contract for data synchronization.
[0118] In one embodiment, a system for trusted on-chain and off-chain data synchronization of a blockchain is further provided. The system includes:
[0119] A blockchain, used to deploy user contracts and oracle contracts, and store data in the form of a key-value key-value pair data structure, where the value contains a unique association number;
[0120] An oracle service, deployed outside the blockchain, used to detect notifications from the database trigger, obtain data update situations of the off-chain database, and execute the oracle contract for data synchronization operations;
[0121] A chain SDK, integrated into the blockchain platform, with a block subscription function, capable of subscribing to chain events and parsing chain event parameters;
[0122] A middleware, which synchronizes the on-chain data update situation to the off-chain database according to the unique association number included in the chain event;
[0123] An off-chain database, used to store data, and when the data changes, it monitors the data change through the database trigger and issues a notification. The database table structure contains a unique association number;
[0124] Among them, the system realizes the forward synchronization from the blockchain on-chain to the off-chain and the reverse synchronization from the off-chain to the on-chain;
[0125] The forward synchronization process is as follows: The user initiates a data update operation on the blockchain through the user contract. The user contract calls the oracle contract to request to synchronize the updated data to the off-chain database. The oracle contract verifies the parameters and sends a chain event. The chain SDK subscribes to the chain event and synchronizes the data update situation to the off-chain database according to the unique association number;
[0126] The reverse synchronization process is as follows: When the data in the off-chain database changes, the database trigger monitors the data change and responds. The oracle service detects the database trigger notification, obtains the data update situation, and executes the oracle contract for data synchronization. The oracle contract notifies the user that the data has been obtained by calling back the user contract. The user contract receives the data and updates the on-chain storage in the form of a key-value key-value pair data structure according to the unique association number.
[0127] In one embodiment, a computer device is further provided, including a memory, a processor, and a computer program stored on the memory, where the processor executes the computer program to implement the steps of the method in the above embodiment.
[0128] In one embodiment, a computer-readable storage medium is further provided, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the method in the above embodiment are implemented.
[0129] The technical features of the above embodiments can be combined arbitrarily. For the sake of concise description, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, it should be considered as the scope recorded in this specification.
Claims
1. A method for synchronizing on-chain and off-chain data of a trusted blockchain, characterized in that, The method is based on integrating an oracle and a chain SDK for the blockchain additionally, using the chain SDK to implement the block subscription function, deploying an oracle contract on the blockchain, developing and deploying an oracle service outside the blockchain, and creating a database trigger in the off-chain database. The method includes: forward synchronization from the blockchain on-chain to off-chain, and reverse synchronization from off-chain to on-chain; The forward synchronization includes: The user initiates a data update operation on the blockchain through a user contract, and the updated data is stored on the blockchain in the data structure form of key-value pairs; wherein, the value contains a unique association number; The user contract calls the oracle contract to request synchronizing the updated data to the off-chain database; The oracle contract verifies the corresponding parameters and sends a corresponding chain event; The chain SDK subscribes to the chain event through the block subscription function, obtains the data update type to which the chain event belongs, and parses the chain event parameters; wherein, the data to which the chain event belongs contains a unique association number; The middleware synchronizes the data update situation to the database according to the unique association number; The reverse synchronization includes: When the data in the database changes, the database trigger monitors the data change and responds; wherein, the database table structure contains a unique association number; The oracle service detects the notification from the database trigger, obtains the data update situation, and executes the oracle contract for data synchronization; The oracle contract notifies the user that the data has been obtained by calling back the user contract, and the user contract receives the data and updates the on-chain storage in the data structure form of key-value pairs according to the unique association number; 2. The method for synchronizing on-chain and off-chain data of a trusted blockchain according to claim 1, wherein The creating a database trigger in the off-chain database includes: Create a trigger function in PostgreSQL, and this trigger function will send a notification when data is inserted or updated; Implement listening to the notification sent by the trigger function in PostgreSQL through a database driver; 3. The method for synchronizing on-chain and off-chain data of a trusted blockchain according to claim 1, characterized in that, The creating a database trigger in the off-chain database includes: When the database does not support the LISTEN / NOTIFY notification mechanism, set up a message queue; Configure the database trigger, and set up an intermediate layer to forward the trigger event to the message queue. Specifically: use the database trigger to insert event information into an intermediate table, and then use an external process to monitor the intermediate table and forward the event to the message queue; wherein, write a Go language program to forward the event; Configure a message queue listener in the Go application to receive and process messages when an event occurs; 4. The method for synchronizing on-chain and off-chain data of a trusted blockchain according to claim 3, wherein The message queue is RabbitMQ or Kafka; 5. The method for synchronizing on-chain and off-chain data of a trusted blockchain according to claim 1, wherein, It also includes: Set up a rollback mechanism for the blockchain to ensure the atomicity of the operation of on-chain and off-chain data synchronization of the blockchain; 6. The method for synchronizing on-chain and off-chain data of a trusted blockchain according to claim 5, wherein It also includes: When the forward synchronization or the reverse synchronization fails, perform a failure retry for a preset number of times. If it still fails, execute the failure rollback mechanism; 7. The method for synchronizing on-chain and off-chain data of a trusted blockchain according to claim 1, wherein The off-chain database has no external interface throughout the process, the service is only initiated from the chain end, and the data synchronization is also initiated from the chain end; 8. A system for synchronizing data on and off the chain of a trusted blockchain, characterized in that, The system includes: A blockchain, used to deploy user contracts and oracle contracts, and store data in the form of a key-value data structure, where the value contains a unique association number; An oracle service, deployed outside the blockchain, used to detect notifications of database triggers, obtain data update situations of off-chain databases, and execute oracle contracts for data synchronization operations; A chain SDK, integrated into the blockchain platform, with a block subscription function, capable of subscribing to chain events and parsing chain event parameters; Middleware, which synchronizes the on-chain data update situation to the off-chain database according to the unique association number included in the chain event; An off-chain database, used to store data, and when the data changes, it monitors the data change through a database trigger and issues a notification. The database table structure contains a unique association number; Among them, the system realizes the forward synchronization from the blockchain on-chain to off-chain and the reverse synchronization from off-chain to on-chain; The forward synchronization process is as follows: The user initiates a data update operation on the blockchain through a user contract. The user contract calls the oracle contract to request synchronizing the updated data to the off-chain database. The oracle contract verifies the parameters and sends a chain event. The chain SDK subscribes to the chain event and synchronizes the data update situation to the off-chain database according to the unique association number; The reverse synchronization process is as follows: When the data in the off-chain database changes, the database trigger monitors the data change and responds. The oracle service detects the database trigger notification, obtains the data update situation, and executes the oracle contract for data synchronization. The oracle contract informs the user that the data has been retrieved by calling back the user contract. The user contract receives the data and updates the on-chain storage in the form of a key-value data structure according to the unique association number.
9. A computer device, comprising a memory, a processor, and a computer program stored on the memory, characterized in that, The processor executes the computer program to implement the steps of the method described in claim 1.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the method described in claim 1.
Citation Information
Patent Citations
Data interaction method based on block chain on-chain and off-chain collaboration
CN110673966A
On-chain and off-chain hybrid storage method based on block chain distributed account book and database
CN114020797A
Cited By
Block chain-based blood safety whole-course tracing system and method
CN120895187A
Data synchronization method and device of heterogeneous block chain, medium and equipment
CN121681667A