CN118740851A - Blockchain data processing method, device, electronic device and storage medium - Google Patents
Blockchain data processing method, device, electronic device and storage medium Download PDFInfo
- Publication number
- CN118740851A CN118740851A CN202310365386.5A CN202310365386A CN118740851A CN 118740851 A CN118740851 A CN 118740851A CN 202310365386 A CN202310365386 A CN 202310365386A CN 118740851 A CN118740851 A CN 118740851A
- Authority
- CN
- China
- Prior art keywords
- transaction
- target
- data
- transaction data
- target transaction
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06Q—INFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
- G06Q40/00—Finance; Insurance; Tax strategies; Processing of corporate or income taxes
- G06Q40/04—Trading; Exchange, e.g. stocks, commodities, derivatives or currency exchange
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L63/00—Network architectures or network communication protocols for network security
- H04L63/08—Network architectures or network communication protocols for network security for authentication of entities
- H04L63/0823—Network architectures or network communication protocols for network security for authentication of entities using certificates
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/10—Protocols in which an application is distributed across nodes in the network
- H04L67/104—Peer-to-peer [P2P] networks
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/10—Protocols in which an application is distributed across nodes in the network
- H04L67/1095—Replication or mirroring of data, e.g. scheduling or transport for data synchronisation between network nodes
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/50—Network services
- H04L67/56—Provisioning of proxy services
- H04L67/568—Storing data temporarily at an intermediate stage, e.g. caching
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L9/00—Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
- H04L9/32—Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials
- H04L9/3247—Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials involving digital signatures
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Business, Economics & Management (AREA)
- Computer Security & Cryptography (AREA)
- Finance (AREA)
- Accounting & Taxation (AREA)
- Development Economics (AREA)
- Technology Law (AREA)
- Computing Systems (AREA)
- Computer Hardware Design (AREA)
- Economics (AREA)
- Marketing (AREA)
- Strategic Management (AREA)
- General Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Business, Economics & Management (AREA)
- General Physics & Mathematics (AREA)
- Theoretical Computer Science (AREA)
- Financial Or Insurance-Related Operations Such As Payment And Settlement (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
本申请实施例公开了一种区块链数据处理方法、装置、电子设备及存储介质,通过从所述目标区块中提取出所述目标交易的目标交易标识,访问存储有第一数据对的缓存服务,根据所述目标交易标识从所述缓存服务中获取所述目标交易关联的第二交易数据,通过引入缓存服务,使得在第二交易数据不需要进行上链操作的情况下,也能够根据目标交易标识获取到目标交易关联的第二交易数据,从而在跨服务器共享交易数据的场景下提升交易数据的安全性,在此基础上,能够根据所述第一交易数据和所述第二交易数据得到目标交易数据,从而在提升交易数据的安全性的基础上,提升本地数据库中的交易数据的完整性,可广泛应用于区块链、云技术、支付等技术领域。
The embodiments of the present application disclose a blockchain data processing method, device, electronic device and storage medium. The method extracts the target transaction identifier of the target transaction from the target block, accesses the cache service storing the first data pair, and obtains the second transaction data associated with the target transaction from the cache service according to the target transaction identifier. By introducing the cache service, the second transaction data associated with the target transaction can be obtained according to the target transaction identifier even when the second transaction data does not need to be uploaded to the chain, thereby improving the security of transaction data in the scenario of sharing transaction data across servers. On this basis, the target transaction data can be obtained according to the first transaction data and the second transaction data, thereby improving the integrity of the transaction data in the local database on the basis of improving the security of the transaction data. The method can be widely used in technical fields such as blockchain, cloud technology, and payment.
Description
技术领域Technical Field
本申请涉及区块链技术领域,特别是涉及一种区块链数据处理方法、装置、电子设备及存储介质。The present application relates to the field of blockchain technology, and in particular to a blockchain data processing method, device, electronic device and storage medium.
背景技术Background Art
随着区块链技术的发展,基于区块链的应用变得越来越广泛。在区块链的应用过程中,交易会产生一些关键的交易数据,这些交易数据一般会被进行上链操作,进而存储到区块链上,以达到交易数据不可篡改和可溯源的效果。With the development of blockchain technology, blockchain-based applications are becoming more and more widespread. In the application process of blockchain, transactions will generate some key transaction data, which will generally be uploaded to the blockchain and then stored on the blockchain to achieve the effect that the transaction data cannot be tampered with and can be traced.
相关技术中,通常会将上链的交易数据同步至本地数据库中,然而,这种方式只能从区块链网络中同步部分关键的交易数据,导致本地数据库同步得到的交易数据并不是完整的,若将交易数据全部存储到区块链上,虽然可以提升从区块链同步得到的交易数据的完整性,但却会降低了部分需要保密的交易数据的安全性,可见,如何同时提升本地数据库中的交易数据的完整性以及安全性是一个亟待解决的问题。In related technologies, transaction data on the chain is usually synchronized to the local database. However, this method can only synchronize some key transaction data from the blockchain network, resulting in incomplete transaction data synchronized from the local database. If all transaction data is stored on the blockchain, although the integrity of the transaction data synchronized from the blockchain can be improved, it will reduce the security of some transaction data that needs to be kept confidential. It can be seen that how to simultaneously improve the integrity and security of transaction data in the local database is a problem that needs to be solved urgently.
发明内容Summary of the invention
以下是对本申请详细描述的主题的概述。本概述并非是为了限制权利要求的保护范围。The following is a summary of the subject matter described in detail in this application. This summary is not intended to limit the scope of the claims.
本申请实施例提供了一种区块链数据处理方法、装置、电子设备及存储介质,能够同时提升本地数据库中的交易数据的完整性以及安全性。The embodiments of the present application provide a blockchain data processing method, device, electronic device and storage medium, which can simultaneously improve the integrity and security of transaction data in a local database.
一方面,本申请实施例提供了一种区块链数据处理方法,包括:On the one hand, an embodiment of the present application provides a blockchain data processing method, including:
当目标区块被区块链网络共识通过时,接收所述区块链网络发送的所述目标区块,其中,所述目标区块包括至少一个目标交易;When the target block is approved by the blockchain network consensus, receiving the target block sent by the blockchain network, wherein the target block includes at least one target transaction;
从所述目标区块中提取出所述目标交易的目标交易标识,以及所述目标交易关联的第一交易数据;Extracting a target transaction identifier of the target transaction and first transaction data associated with the target transaction from the target block;
访问存储有第一数据对的缓存服务,根据所述目标交易标识从所述缓存服务的所述第一数据对中获取所述目标交易关联的第二交易数据,其中,所述第一数据对基于交易标识和交易数据构建得到,所述第一数据对中的交易标识是由所述区块链网络在接收到异步发送的交易请求后返回的;Accessing a cache service storing a first data pair, and obtaining second transaction data associated with the target transaction from the first data pair of the cache service according to the target transaction identifier, wherein the first data pair is constructed based on the transaction identifier and the transaction data, and the transaction identifier in the first data pair is returned by the blockchain network after receiving the asynchronously sent transaction request;
根据所述第一交易数据和所述第二交易数据得到目标交易数据,将所述目标交易数据存储至目标数据库。Target transaction data is obtained according to the first transaction data and the second transaction data, and the target transaction data is stored in a target database.
另一方面,本申请实施例还提供了一种区块链数据处理方法,包括:On the other hand, the embodiment of the present application also provides a blockchain data processing method, including:
向区块链网络异步发送目标交易的交易请求,接收所述区块链网络返回的所述目标交易的目标交易标识;Asynchronously sending a transaction request for a target transaction to a blockchain network, and receiving a target transaction identifier of the target transaction returned by the blockchain network;
获取所述目标交易关联的第二交易数据,根据所述目标交易标识和所述第二交易数据构建第一数据对;Acquire second transaction data associated with the target transaction, and construct a first data pair according to the target transaction identifier and the second transaction data;
将所述第一数据对存储至缓存服务中,以供检测服务在所述目标交易对应的目标区块被所述区块链网络共识通过时,从所述目标区块中提取出所述目标交易标识以及所述目标交易关联的第一交易数据,访问所述缓存服务,根据所述目标交易标识从所述缓存服务的所述第一数据对中获取所述第二交易数据,根据所述第一交易数据和所述第二交易数据得到目标交易数据,将所述目标交易数据存储至目标数据库。The first data pair is stored in the cache service so that when the target block corresponding to the target transaction is passed by the blockchain network consensus, the detection service extracts the target transaction identifier and the first transaction data associated with the target transaction from the target block, accesses the cache service, obtains the second transaction data from the first data pair of the cache service according to the target transaction identifier, obtains the target transaction data according to the first transaction data and the second transaction data, and stores the target transaction data in the target database.
另一方面,本申请实施例还提供了一种区块链数据处理装置,包括:On the other hand, the embodiment of the present application also provides a blockchain data processing device, including:
区块接收模块,用于当目标区块被区块链网络共识通过时,接收所述区块链网络发送的所述目标区块,其中,所述目标区块包括至少一个目标交易;A block receiving module, configured to receive the target block sent by the blockchain network when the target block is approved by the blockchain network consensus, wherein the target block includes at least one target transaction;
区块处理模块,用于从所述目标区块中提取出所述目标交易的目标交易标识,以及所述目标交易关联的第一交易数据;A block processing module, configured to extract a target transaction identifier of the target transaction and first transaction data associated with the target transaction from the target block;
访问模块,用于访问存储有第一数据对的缓存服务,根据所述目标交易标识从所述缓存服务的所述第一数据对中获取所述目标交易关联的第二交易数据,其中,所述第一数据对基于交易标识和交易数据构建得到,所述第一数据对中的交易标识是由所述区块链网络在接收到异步发送的交易请求后生成的;an access module, configured to access a cache service storing a first data pair, and obtain second transaction data associated with the target transaction from the first data pair of the cache service according to the target transaction identifier, wherein the first data pair is constructed based on the transaction identifier and the transaction data, and the transaction identifier in the first data pair is generated by the blockchain network after receiving an asynchronously sent transaction request;
存储模块,用于根据所述第一交易数据和所述第二交易数据得到目标交易数据,将所述目标交易数据存储至目标数据库。The storage module is used to obtain target transaction data according to the first transaction data and the second transaction data, and store the target transaction data in a target database.
进一步,区块接收模块具体用于:Furthermore, the block receiving module is specifically used for:
根据预设的区块号区间生成区块订阅请求,将所述区块订阅请求发送至所述区块链网络;Generate a block subscription request according to a preset block number interval, and send the block subscription request to the blockchain network;
每当位于所述区块号区间内的目标区块被区块链网络共识通过时,接收所述区块链网络响应所述区块订阅请求发送的所述目标区块。Whenever a target block within the block number interval is approved by the blockchain network consensus, the target block sent by the blockchain network in response to the block subscription request is received.
进一步,存储模块还用于:Furthermore, the storage module is also used for:
生成所述目标交易数据的存储结果信息,其中,所述存储结果信息用于指示所述目标交易数据已成功存储至所述目标数据库或者未成功存储至所述目标数据库;generating storage result information of the target transaction data, wherein the storage result information is used to indicate whether the target transaction data has been successfully stored in the target database or has not been successfully stored in the target database;
基于所述目标交易标识和所述存储结果信息构建第二数据对,将所述第二数据对存储至所述缓存服务中。A second data pair is constructed based on the target transaction identifier and the storage result information, and the second data pair is stored in the cache service.
进一步,存储模块还用于:Furthermore, the storage module is also used for:
当所述目标交易数据已成功存储至所述目标数据库时,确定所述目标区块的区块号以及当前的所述目标交易在所述目标区块中的交易序号,记录所述区块号以及所述交易序号;When the target transaction data has been successfully stored in the target database, determine the block number of the target block and the transaction sequence number of the current target transaction in the target block, and record the block number and the transaction sequence number;
在重新启动后,加载所述区块号以及所述交易序号,根据所述区块号以及所述交易序号确定下一个所述目标交易。After restarting, the block number and the transaction sequence number are loaded, and the next target transaction is determined according to the block number and the transaction sequence number.
进一步,存储模块还用于:Furthermore, the storage module is also used for:
若所述目标交易的交易类型为链配置类型时,从所述目标区块中提取出目标服务器的服务器属性信息,以及所述区块链网络为所述目标服务器分配的服务器交易证书,其中,所述目标服务器为所述目标交易配置的服务器;If the transaction type of the target transaction is a chain configuration type, extracting server attribute information of the target server from the target block, and a server transaction certificate assigned to the target server by the blockchain network, wherein the target server is a server configured for the target transaction;
将所述服务器属性信息和所述服务器交易证书存储至所述目标数据库。The server attribute information and the server transaction certificate are stored in the target database.
进一步,存储模块具体用于:Furthermore, the storage module is specifically used for:
从所述目标区块中提取出对所述目标交易进行签名时使用的目标交易证书;Extracting a target transaction certificate used to sign the target transaction from the target block;
将所述目标交易证书与所述服务器交易证书进行匹配,根据匹配结果从所述目标数据库中获取所述目标交易对应的所述服务器属性信息;Matching the target transaction certificate with the server transaction certificate, and acquiring the server attribute information corresponding to the target transaction from the target database according to the matching result;
将所述第一交易数据、所述第二交易数据、所述服务器属性信息和所述目标交易证书合并为目标交易数据。The first transaction data, the second transaction data, the server attribute information and the target transaction certificate are combined into target transaction data.
进一步,访问模块具体用于:Furthermore, the access module is specifically used to:
从所述目标区块中提取出在对所述目标交易进行签名时使用的目标交易证书;Extracting a target transaction certificate used when signing the target transaction from the target block;
获取在启动时加载的所述服务器交易证书,将在启动时加载的所述服务器交易证书与所述目标交易证书进行比较;Obtaining the server transaction certificate loaded at startup, and comparing the server transaction certificate loaded at startup with the target transaction certificate;
当比较结果为在启动时加载的所述服务器交易证书与所述目标交易证书相一致时,访问存储有第一数据对的缓存服务。When the comparison result is that the server transaction certificate loaded at startup is consistent with the target transaction certificate, a cache service storing the first data pair is accessed.
进一步,存储模块还用于:Furthermore, the storage module is also used for:
当比较结果为在启动时加载的所述服务器交易证书与所述目标交易证书不一致时,将所述第一交易数据作为目标交易数据,将所述目标交易数据存储至目标数据库;When the comparison result shows that the server transaction certificate loaded at startup is inconsistent with the target transaction certificate, taking the first transaction data as the target transaction data, and storing the target transaction data in the target database;
或者,当比较结果为在启动时加载的所述服务器交易证书与所述目标交易证书不一致时,访问所述缓存服务,根据所述第一数据对从所述缓存服务中获取所述目标交易标识对应的加密交易数据,获取预先存储的解密信息,根据所述解密信息对所述加密交易数据进行解密处理,得到所述目标交易标识对应的第二交易数据,根据所述第一交易数据和所述第二交易数据得到目标交易数据,将所述目标交易数据存储至目标数据库,其中,所述解密信息是由构建所述第一数据对的目标服务器生成的。Alternatively, when the comparison result is that the server transaction certificate loaded at startup is inconsistent with the target transaction certificate, the cache service is accessed, and the encrypted transaction data corresponding to the target transaction identifier is obtained from the cache service according to the first data pair, and the pre-stored decryption information is obtained. The encrypted transaction data is decrypted according to the decryption information to obtain the second transaction data corresponding to the target transaction identifier, and the target transaction data is obtained according to the first transaction data and the second transaction data, and the target transaction data is stored in the target database, wherein the decryption information is generated by the target server that constructs the first data pair.
进一步,数据对构建模块具体用于:Furthermore, the data pair building module is specifically used for:
对所述第二交易数据进行加密,得到加密交易数据,将所述加密交易数据对应的解密信息发送至所述检测服务;Encrypting the second transaction data to obtain encrypted transaction data, and sending decryption information corresponding to the encrypted transaction data to the detection service;
根据所述目标交易标识和所述加密交易数据构建第一数据对。A first data pair is constructed according to the target transaction identifier and the encrypted transaction data.
另一方面,本申请实施例还提供了一种区块链数据处理装置,包括:On the other hand, the embodiment of the present application also provides a blockchain data processing device, including:
请求模块,用于向区块链网络异步发送目标交易的交易请求,接收所述区块链网络返回的所述目标交易的目标交易标识;A request module, used to asynchronously send a transaction request of a target transaction to a blockchain network, and receive a target transaction identifier of the target transaction returned by the blockchain network;
数据对构建模块,用于获取所述目标交易关联的第二交易数据,根据所述目标交易标识和所述第二交易数据构建第一数据对;a data pair construction module, configured to obtain second transaction data associated with the target transaction, and construct a first data pair according to the target transaction identifier and the second transaction data;
缓存模块,用于将所述第一数据对存储至缓存服务中,以供检测服务在所述目标交易对应的目标区块被所述区块链网络共识通过时,从所述目标区块中提取出所述目标交易标识以及所述目标交易关联的第一交易数据,访问所述缓存服务,根据所述目标交易标识从所述缓存服务的所述第一数据对中获取所述第二交易数据,根据所述第一交易数据和所述第二交易数据得到目标交易数据,将所述目标交易数据存储至目标数据库。A cache module is used to store the first data pair in a cache service so that when the target block corresponding to the target transaction is passed by the blockchain network consensus, the detection service extracts the target transaction identifier and the first transaction data associated with the target transaction from the target block, accesses the cache service, obtains the second transaction data from the first data pair of the cache service according to the target transaction identifier, obtains the target transaction data according to the first transaction data and the second transaction data, and stores the target transaction data in a target database.
进一步,区块链数据处理装置还包括消息发送模块,消息发送模块用于:Furthermore, the blockchain data processing device also includes a message sending module, which is used to:
根据所述目标交易标识从所述缓存服务的所述第二数据对中获取所述目标交易对应的所述存储结果信息,根据所述存储结果信息生成用于指示所述目标交易的交易结果的第一通知消息;Acquire the storage result information corresponding to the target transaction from the second data pair of the cache service according to the target transaction identifier, and generate a first notification message indicating a transaction result of the target transaction according to the storage result information;
将所述第一通知消息发送至发起所述目标交易的账户。The first notification message is sent to the account that initiates the target transaction.
进一步,消息发送模块具体用于:Furthermore, the message sending module is specifically used for:
基于预设的时间间隔,持续根据所述目标交易标识从所述缓存服务的所述第二数据对中获取所述目标交易对应的所述存储结果信息;Based on a preset time interval, continuously obtaining the storage result information corresponding to the target transaction from the second data pair of the cache service according to the target transaction identifier;
当获取到所述存储结果信息时,根据所述存储结果信息生成用于指示所述目标交易的交易结果的第一通知消息;或者,当请求所述存储结果信息的持续时长超过预设的时长阈值时,生成用于指示超时的第二通知消息,将所述第二通知消息发送至发起所述目标交易的账户。When the storage result information is obtained, a first notification message indicating the transaction result of the target transaction is generated according to the storage result information; or, when the duration of requesting the storage result information exceeds a preset duration threshold, a second notification message indicating a timeout is generated, and the second notification message is sent to the account that initiated the target transaction.
另一方面,本申请实施例还提供了一种电子设备,包括存储器和处理器,所述存储器存储有计算机程序,所述处理器执行所述计算机程序时实现上述的区块链数据处理方法。On the other hand, an embodiment of the present application further provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the above-mentioned blockchain data processing method when executing the computer program.
另一方面,本申请实施例还提供了一种计算机可读存储介质,所述存储介质存储有计算机程序,所述计算机程序被处理器执行实现上述的区块链数据处理方法。On the other hand, an embodiment of the present application further provides a computer-readable storage medium, wherein the storage medium stores a computer program, and the computer program is executed by a processor to implement the above-mentioned blockchain data processing method.
另一方面,本申请实施例还提供了一种计算机程序产品,该计算机程序产品包括计算机程序,该计算机程序存储在计算机可读存介质中。计算机设备的处理器从计算机可读存储介质读取该计算机程序,处理器执行该计算机程序,使得该计算机设备执行实现上述的区块链数据处理方法。On the other hand, the embodiment of the present application further provides a computer program product, which includes a computer program, and the computer program is stored in a computer-readable storage medium. The processor of the computer device reads the computer program from the computer-readable storage medium, and the processor executes the computer program, so that the computer device executes the above-mentioned blockchain data processing method.
本申请实施例至少包括以下有益效果:通过当目标区块被区块链网络共识通过时,接收所述区块链网络发送的所述目标区块,从所述目标区块中提取出目标交易关联的第一交易数据,在多个不同的服务器参与区块链业务系统的场景下,不同的服务器均可以同步获取到其他服务器在区块链中的交易数据,从而实现交易数据的跨服务器共享,并且,通过从所述目标区块中提取出所述目标交易的目标交易标识,访问存储有第一数据对的缓存服务,根据所述目标交易标识从所述缓存服务的所述第一数据对中获取所述目标交易关联的第二交易数据,由于所述第一数据对基于交易标识和交易数据构建得到,因此通过引入缓存服务,使得在第二交易数据不需要进行上链操作的情况下,也能够根据目标交易标识获取到目标交易关联的第二交易数据,从而在跨服务器共享交易数据的场景下提升交易数据的安全性,在此基础上,能够根据所述第一交易数据和所述第二交易数据得到目标交易数据,将所述目标交易数据存储至目标数据库,使得目标数据库中既可以存储有区块链中的第一交易数据,也可以存储有不在区块链中的第二交易数据,从而在提升交易数据的安全性的基础上,提升本地数据库中的交易数据的完整性。The embodiments of the present application include at least the following beneficial effects: when the target block is approved by the blockchain network consensus, the target block sent by the blockchain network is received, and the first transaction data associated with the target transaction is extracted from the target block. In a scenario where multiple different servers participate in the blockchain business system, different servers can synchronously obtain the transaction data of other servers in the blockchain, thereby realizing cross-server sharing of transaction data, and by extracting the target transaction identifier of the target transaction from the target block, accessing the cache service storing the first data pair, and obtaining the second transaction data associated with the target transaction from the first data pair of the cache service according to the target transaction identifier. Since the first The data pair is constructed based on the transaction identifier and the transaction data. Therefore, by introducing the cache service, the second transaction data associated with the target transaction can be obtained according to the target transaction identifier without the need for the second transaction data to be on-chain, thereby improving the security of transaction data in the scenario of sharing transaction data across servers. On this basis, the target transaction data can be obtained according to the first transaction data and the second transaction data, and the target transaction data can be stored in the target database, so that the target database can store both the first transaction data in the blockchain and the second transaction data that is not in the blockchain, thereby improving the integrity of the transaction data in the local database while improving the security of the transaction data.
本申请的其他特征和优点将在随后的说明书中阐述,并且,部分地从说明书中变得显而易见,或者通过实施本申请而了解。Other features and advantages of the present application will be set forth in the following description, and in part will become apparent from the description, or may be understood by practicing the present application.
附图说明BRIEF DESCRIPTION OF THE DRAWINGS
附图用来提供对本申请技术方案的进一步理解,并且构成说明书的一部分,与本申请的实施例一起用于解释本申请的技术方案,并不构成对本申请技术方案的限制。The accompanying drawings are used to provide further understanding of the technical solution of the present application and constitute a part of the specification. Together with the embodiments of the present application, they are used to explain the technical solution of the present application and do not constitute a limitation on the technical solution of the present application.
图1为本申请实施例提供的一种可选的区块链数据的处理架构示意图;FIG1 is a schematic diagram of an optional blockchain data processing architecture provided in an embodiment of the present application;
图2为本申请实施例提供的一种可选的实施环境的示意图;FIG2 is a schematic diagram of an optional implementation environment provided in an embodiment of the present application;
图3为本申请实施例提供的服务器的一种可选的内部架构示意图;FIG3 is a schematic diagram of an optional internal architecture of a server provided in an embodiment of the present application;
图4为本申请实施例提供的区块链数据处理方法的一种可选的流程示意图;FIG4 is a schematic diagram of an optional flow chart of a blockchain data processing method provided in an embodiment of the present application;
图5为本申请实施例提供的确定目标交易标识对应的第二交易数据的一种可选的流程示意图;FIG5 is a schematic diagram of an optional process for determining second transaction data corresponding to a target transaction identifier according to an embodiment of the present application;
图6为本申请实施例提供的后端服务与缓存服务基于第二数据对的交互流程示意图;6 is a schematic diagram of the interaction process between the backend service and the cache service based on the second data pair provided in an embodiment of the present application;
图7为本申请实施例提供的目标数据库不可用时的一种可选的处理流程示意图;FIG7 is a schematic diagram of an optional processing flow when the target database is unavailable provided in an embodiment of the present application;
图8为本申请实施例提供的多个目标服务器共用缓存服务时一种可选的数据交互示意图;FIG8 is a schematic diagram of an optional data interaction when multiple target servers share a cache service according to an embodiment of the present application;
图9为本申请实施例提供的检测服务的一种可选的详细处理流程示意图;FIG9 is a schematic diagram of an optional detailed processing flow of the detection service provided in an embodiment of the present application;
图10为本申请实施例提供的区块链数据处理方法的另一种可选的流程示意图;FIG10 is another optional flowchart of the blockchain data processing method provided in an embodiment of the present application;
图11为本申请实施例提供的后端服务的一种可选的详细处理流程示意图;FIG11 is a schematic diagram of an optional detailed processing flow of a backend service provided in an embodiment of the present application;
图12为本申请实施例提供的检测服务和后端服务的一种可选的交互流程示意图;FIG12 is a schematic diagram of an optional interaction process between the detection service and the backend service provided in an embodiment of the present application;
图13为本申请实施例提供的区块链数据处理方法的一种可选的总体交互流程示意图;FIG13 is a schematic diagram of an optional overall interaction flow of the blockchain data processing method provided in an embodiment of the present application;
图14为本申请实施例提供的区块链数据处理方法的另一种可选的总体交互流程示意图;FIG14 is another optional overall interaction flow diagram of the blockchain data processing method provided in an embodiment of the present application;
图15为本申请实施例提供的第一区块链数据处理装置的一种可选的机构示意图;FIG15 is a schematic diagram of an optional structure of a first blockchain data processing device provided in an embodiment of the present application;
图16为本申请实施例提供的第二区块链数据处理装置的一种可选的机构示意图;FIG16 is a schematic diagram of an optional structure of a second blockchain data processing device provided in an embodiment of the present application;
图17为本申请实施例提供的终端的部分结构框图;FIG17 is a partial structural block diagram of a terminal provided in an embodiment of the present application;
图18为本申请实施例提供的服务器的部分结构框图。FIG18 is a partial structural block diagram of the server provided in an embodiment of the present application.
具体实施方式DETAILED DESCRIPTION
为了使本申请的目的、技术方案及优点更加清楚明白,以下结合附图及实施例,对本申请进行进一步详细说明。应当理解,此处所描述的具体实施例仅用以解释本申请,并不用于限定本申请。In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
需要说明的是,在本申请的各个具体实施方式中,当涉及到需要根据目标对象属性信息或属性信息集合等与目标对象特性相关的数据进行相关处理时,都会先获得目标对象的许可或者同意,而且,对这些数据的收集、使用和处理等,都会遵守相关国家和地区的相关法律法规和标准。其中,目标对象可以是用户。此外,当本申请实施例需要获取目标对象属性信息时,会通过弹窗或者跳转到确认页面等方式获得目标对象的单独许可或者单独同意,在明确获得目标对象的单独许可或者单独同意之后,再获取用于使本申请实施例能够正常运行的必要的目标对象相关数据。It should be noted that in each specific embodiment of the present application, when it comes to the need to perform relevant processing based on data related to the characteristics of the target object such as target object attribute information or attribute information set, the permission or consent of the target object will be obtained first, and the collection, use and processing of these data will comply with the relevant laws, regulations and standards of the relevant countries and regions. Among them, the target object can be a user. In addition, when the embodiment of the present application needs to obtain the target object attribute information, the separate permission or separate consent of the target object will be obtained by means of a pop-up window or jumping to a confirmation page, and after the separate permission or separate consent of the target object is clearly obtained, the necessary target object-related data for enabling the normal operation of the embodiment of the present application will be obtained.
为便于理解本申请实施例提供的技术方案,这里先对本申请实施例使用的一些关键名词进行解释:To facilitate understanding of the technical solutions provided in the embodiments of the present application, some key terms used in the embodiments of the present application are explained here:
区块链(Blockchain)是分布式数据存储、点对点传输、共识机制、加密算法等计算机技术的新型应用模式。区块链,本质上是一个去中心化的数据库,是一串使用密码学方法相关联产生的数据块,每一个数据块中包含了一批次网络交易的信息,用于验证其信息的有效性(防伪)和生成下一个区块。区块链可以包括区块链底层平台、平台产品服务层以及应用服务层。区块链底层平台可以包括用户管理、基础服务、智能合约以及运营检测等处理模块。其中,用户管理模块负责所有区块链参与者的身份信息管理,包括维护公私钥生成(账户管理)、密钥管理以及用户真实身份和区块链地址对应关系维护(权限管理)等,并且在授权的情况下,监管和审计某些真实身份的交易情况,提供风险控制的规则配置(风控审计);基础服务模块部署在所有区块链节点设备上,用来验证业务请求的有效性,并对有效请求完成共识后记录到存储上,对于一个新的业务请求,基础服务先对接口适配解析和鉴权处理(接口适配),然后通过共识算法将业务信息加密(共识管理),在加密之后完整一致的传输至共享账本上(网络通信),并进行记录存储;智能合约模块负责合约的注册发行以及合约触发和合约执行,开发人员可以通过某种编程语言定义合约逻辑,发布到区块链上(合约注册),根据合约条款的逻辑,调用密钥或者其它的事件触发执行,完成合约逻辑,同时还提供对合约升级注销的功能;运营检测模块主要负责产品发布过程中的部署、配置的修改、合约设置、云适配以及产品运行中的实时状态的可视化输出,例如:告警、检测网络情况、检测节点设备健康状态等。平台产品服务层提供典型应用的基本能力和实现框架,开发人员可以基于这些基本能力,叠加业务的特性,完成业务逻辑的区块链实现。应用服务层提供基于区块链方案的应用服务给业务参与方进行使用。Blockchain is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, and encryption algorithm. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block 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, platform product service layer, and application service layer. The underlying blockchain platform can include processing modules such as user management, basic services, smart contracts, and operation detection. Among them, the user management module is responsible for the identity information management of all blockchain participants, including maintaining the generation of public and private keys (account management), key management, and the maintenance of the corresponding relationship between the user's real identity and the blockchain address (authority management), 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 record the valid requests to the storage after consensus is reached. For a new business request, the basic service first adapts the interface to parse and authenticate (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, 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 event trigger execution is called to complete the contract logic. At the same time, 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. The platform product service layer provides the basic capabilities and implementation framework of typical applications. Developers can complete the blockchain implementation of business logic based on these basic capabilities and superimpose business characteristics. The application service layer provides application services based on blockchain solutions for business participants to use.
云技术(Cloud technology)基于云计算商业模式应用的网络技术、信息技术、整合技术、管理平台技术、应用技术等的总称,可以组成资源池,按需所用,灵活便利。云计算技术将变成重要支撑。技术网络系统的后台服务需要大量的计算、存储资源,如视频网站、图片类网站和更多的门户网站。伴随着互联网行业的高度发展和应用,将来每个物品都有可能存在自己的识别标志,都需要传输到后台系统进行逻辑处理,不同程度级别的数据将会分开处理,各类行业数据皆需要强大的系统后盾支撑,只能通过云计算来实现。Cloud technology is a general term for network technology, information technology, integration technology, management platform technology, application technology, etc. based on the cloud computing business model. It can form a resource pool, which can be used on demand and is flexible and convenient. Cloud computing technology will become an important support. The backend services of the technical network system require a large amount of computing and storage resources, such as video websites, picture websites and more portal websites. With the rapid development and application of the Internet industry, in the future, each item may have its own identification mark, which needs to be transmitted to the backend system for logical processing. Data of different levels will be processed separately. All kinds of industry data need strong system backing support, which can only be achieved through cloud computing.
参照图1,图1为本申请实施例提供的一种可选的区块链数据的处理架构示意图,在多方参与的基于区块链的业务系统中,包括第一业务服务器和第二业务服务器,第一业务服务器和第二业务服务器可以为部署在两个不同地域的服务器,第一业务服务器和第二业务服务器均运行有各自的后端服务和本地数据库,第一业务服务器在区块链网络中对应第一区块链节点,第二业务服务器在区块链网络中对应第一区块链节点,第二业务服务器在区块链网络中对应第二区块链节点,相应地,第一区块链节点和第二区块链节点分别为两个不同地域的区块链节点。Referring to Figure 1, Figure 1 is a schematic diagram of an optional blockchain data processing architecture provided in an embodiment of the present application. In a blockchain-based business system involving multiple parties, it includes a first business server and a second business server. The first business server and the second business server can be servers deployed in two different regions. The first business server and the second business server both run their own back-end services and local databases. The first business server corresponds to a first blockchain node in the blockchain network, the second business server corresponds to a first blockchain node in the blockchain network, and the second business server corresponds to a second blockchain node in the blockchain network. Accordingly, the first blockchain node and the second blockchain node are blockchain nodes in two different regions respectively.
基于图1所示的架构,终端A向第一业务服务器的后端服务发起交易请求,向第一业务服务器提供交易信息,第一业务服务器的后端服务提取关键的交易信息进行上链;Based on the architecture shown in Figure 1, terminal A initiates a transaction request to the backend service of the first business server, provides transaction information to the first business server, and the backend service of the first business server extracts key transaction information and uploads it to the chain;
后端服务通过SDK(Software Development Kit,软件开发工具包)客户端以同步的方式将交易请求发送至第一区块链节点,采用同步的方式意味着SDK客户端会一直同步等待交易的执行结果;The backend service sends the transaction request to the first blockchain node in a synchronous manner through the SDK (Software Development Kit) client. The synchronous method means that the SDK client will always wait for the execution result of the transaction synchronously.
待第一区块链节点和第二区块链节点对交易的执行达成共识以后,SDK客户端将同步获取到交易的执行结果,以及交易执行后返回的交易数据,将交易数据存储至本地数据库中。After the first blockchain node and the second blockchain node reach a consensus on the execution of the transaction, the SDK client will synchronously obtain the execution result of the transaction and the transaction data returned after the transaction is executed, and store the transaction data in the local database.
类似地,终端B也是采用类似的方式向第二业务服务器的后端服务发起请求,最终第二业务服务器通过SDK客户端将交易数据存储至第二业务服务器的本地数据库中。Similarly, terminal B also initiates a request to the backend service of the second business server in a similar manner, and finally the second business server stores the transaction data in the local database of the second business server through the SDK client.
在上述架构中,第一业务服务器和第二业务服务器均只能分别同步终端A和终端B的交易数据,无法实现跨服务器的数据共享,并且,只能从区块链网络中同步部分关键的交易数据,导致本地数据库同步得到的交易数据并不是完整的,若将交易数据全部存储到区块链上,虽然可以提升从区块链同步得到的交易数据的完整性,但却会降低了部分需要保密的交易数据的安全性。In the above architecture, the first business server and the second business server can only synchronize the transaction data of terminal A and terminal B respectively, and cannot realize cross-server data sharing. In addition, only some key transaction data can be synchronized from the blockchain network, resulting in incomplete transaction data synchronized from the local database. If all transaction data are stored on the blockchain, although the integrity of the transaction data synchronized from the blockchain can be improved, it will reduce the security of some transaction data that needs to be kept confidential.
基于此,本申请实施例提供了一种区块链数据处理方法、装置、电子设备及存储介质,能够同时提升本地数据库中的交易数据的完整性以及安全性。Based on this, the embodiments of the present application provide a blockchain data processing method, device, electronic device and storage medium, which can simultaneously improve the integrity and security of transaction data in the local database.
本申请实施例提供的方法可应用于不同的技术领域,包括但不限于区块链、云技术、支付等技术领域。The method provided in the embodiments of the present application can be applied to different technical fields, including but not limited to blockchain, cloud technology, payment and other technical fields.
参照图2,图2为本申请实施例提供的一种可选的实施环境的示意图,该实施环境包括终端201和服务器202,其中,终端201和服务器202之间通过通信网络连接。Referring to FIG. 2 , FIG. 2 is a schematic diagram of an optional implementation environment provided in an embodiment of the present application, wherein the implementation environment includes a terminal 201 and a server 202 , wherein the terminal 201 and the server 202 are connected via a communication network.
服务器202可以是独立的物理服务器,也可以是多个物理服务器构成的服务器集群或者分布式系统,还可以是提供云服务、云数据库、云计算、云函数、云存储、网络服务、云通信、中间件服务、域名服务、安全服务、CDN(Content Delivery Network,内容分发网络)、以及大数据和人工智能平台等基础云计算服务的云服务器。另外,服务器202还可以是区块链网络中的一个节点服务器。Server 202 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, CDN (Content Delivery Network), and big data and artificial intelligence platforms. In addition, server 202 can also be a node server in a blockchain network.
终端201可以是智能手机、平板电脑、笔记本电脑、台式计算机、智能音箱、智能手表、车载终端等,但并不局限于此。终端201以及服务器202可以通过有线或无线通信方式进行直接或间接地连接,本申请实施例在此不做限制。The terminal 201 may be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch, a vehicle-mounted terminal, etc., but is not limited thereto. The terminal 201 and the server 202 may be directly or indirectly connected via wired or wireless communication, which is not limited in the present embodiment.
在一种可能的实现方式中,参照图3,图3为本申请实施例提供的服务器的一种可选的内部架构示意图,其中,服务器可以部署有后端服务、缓存服务、检测服务和目标数据库,其中,终端可以向后端服务发送交易请求,后端服务可以构造目标交易后向区块链网络异步发送目标交易的交易请求,接收区块链网络返回的目标交易的目标交易标识,获取目标交易关联的第二交易数据,根据目标交易标识和第二交易数据构建第一数据对,将第一数据对存储至缓存服务中;当目标交易对应的目标区块被区块链网络共识通过时,检测服务接收区块链网络发送的目标区块,从目标区块中提取出目标交易的目标交易标识,以及目标交易关联的第一交易数据;访问存储有第一数据对的缓存服务,根据目标交易标识从缓存服务的第一数据对中获取目标交易关联的第二交易数据,根据第一交易数据和第二交易数据得到目标交易数据,将目标交易数据存储至目标数据库。In a possible implementation, referring to FIG3 , FIG3 is a schematic diagram of an optional internal architecture of a server provided in an embodiment of the present application, wherein the server may be deployed with a backend service, a cache service, a detection service, and a target database, wherein the terminal may send a transaction request to the backend service, and the backend service may construct a target transaction and then asynchronously send a transaction request for the target transaction to the blockchain network, receive a target transaction identifier of the target transaction returned by the blockchain network, obtain second transaction data associated with the target transaction, construct a first data pair based on the target transaction identifier and the second transaction data, and store the first data pair in the cache service; when the target block corresponding to the target transaction is passed by the consensus of the blockchain network, the detection service receives the target block sent by the blockchain network, extracts the target transaction identifier of the target transaction and the first transaction data associated with the target transaction from the target block; accesses the cache service storing the first data pair, obtains the second transaction data associated with the target transaction from the first data pair of the cache service based on the target transaction identifier, obtains the target transaction data based on the first transaction data and the second transaction data, and stores the target transaction data in the target database.
通过当目标区块被区块链网络共识通过时,接收区块链网络发送的目标区块,从目标区块中提取出目标交易关联的第一交易数据,在多个不同的服务器参与区块链业务系统的场景下,不同的服务器均可以同步获取到其他服务器在区块链中的交易数据,从而实现交易数据的跨服务器共享,并且,通过从目标区块中提取出目标交易的目标交易标识,访问存储有第一数据对的缓存服务,根据目标交易标识从缓存服务的第一数据对中获取目标交易关联的第二交易数据,由于第一数据对基于交易标识和交易数据构建得到,因此通过引入缓存服务,使得在第二交易数据不需要进行上链操作的情况下,也能够根据目标交易标识获取到目标交易关联的第二交易数据,从而在跨服务器共享交易数据的场景下提升交易数据的安全性,在此基础上,能够根据第一交易数据和第二交易数据得到目标交易数据,将目标交易数据存储至目标数据库,使得目标数据库中既可以存储有区块链中的第一交易数据,也可以存储有不在区块链中的第二交易数据,从而在提升交易数据的安全性的基础上,提升本地数据库中的交易数据的完整性。When the target block is passed by the consensus of the blockchain network, the target block sent by the blockchain network is received, and the first transaction data associated with the target transaction is extracted from the target block. In the scenario where multiple different servers participate in the blockchain business system, different servers can synchronously obtain the transaction data of other servers in the blockchain, thereby realizing cross-server sharing of transaction data. In addition, by extracting the target transaction identifier of the target transaction from the target block, accessing the cache service storing the first data pair, and obtaining the second transaction data associated with the target transaction from the first data pair of the cache service according to the target transaction identifier, since the first data pair is constructed based on the transaction identifier and the transaction data, by introducing the cache service, the second transaction data associated with the target transaction can be obtained according to the target transaction identifier even when the second transaction data does not need to be uploaded to the chain, thereby improving the security of transaction data in the scenario of cross-server sharing of transaction data. On this basis, the target transaction data can be obtained according to the first transaction data and the second transaction data, and the target transaction data can be stored in the target database, so that the target database can store both the first transaction data in the blockchain and the second transaction data not in the blockchain, thereby improving the integrity of the transaction data in the local database on the basis of improving the security of the transaction data.
可以理解的是,图3所示的后端服务、缓存服务、检测服务和数据库均集成于同一个服务器中,除此以外,后端服务、缓存服务、检测服务和数据库中的至少一个也可以采用分立的方式进行部署,本申请实施例不做限定。It can be understood that the back-end service, cache service, detection service and database shown in Figure 3 are all integrated into the same server. In addition, at least one of the back-end service, cache service, detection service and database can also be deployed in a discrete manner, which is not limited to the embodiments of the present application.
基于图2和图3所示的实施环境,参照图4,图4为本申请实施例提供的区块链数据处理方法的一种可选的流程示意图,该区块链数据处理方法的至少一部分流程可以由服务器执行,或者由终端执行,或者由终端和服务器配合执行,该区块链数据处理方法包括但不限于以下步骤401至步骤404。Based on the implementation environment shown in Figures 2 and 3, refer to Figure 4, which is an optional flow chart of the blockchain data processing method provided in an embodiment of the present application. At least a part of the process of the blockchain data processing method can be executed by the server, or by the terminal, or by the terminal and the server in cooperation. The blockchain data processing method includes but is not limited to the following steps 401 to 404.
步骤401:当目标区块被区块链网络共识通过时,接收区块链网络发送的目标区块。Step 401: When the target block is approved by the blockchain network consensus, the target block sent by the blockchain network is received.
其中,目标区块为区块链网络接收到目标交易后将目标交易打包后生成的,目标区块包括至少一个目标交易,即目标区块可以由一个或者多个目标交易打包而成。区块链网络在生成目标区块以后,区块链网络中的区块链节点会对该目标区块进行共识,当目标区块被区块链网络共识通过时,表明区块链网络认可该目标交易,目标区块会被存储至区块链上,即对目标区块进行“上链操作”。目标区块被区块链网络共识通过后,区块链网络会将目标区块发送至检测服务,即检测服务会接收到区块链网络发送的目标区块,其中,区块链网络的发送动作可以是针对每一个新的目标区块的,即每当有一个目标区块被区块链网络共识通过时,区块链网络就会将该目标区块发送至检测服务,在联盟链的场景下,不同的区块链节点生成的目标区块都会被添加至区块链中,换言之,检测服务除了可以接收到自身服务器对应的目标区块以外,还可以接收到其他服务器对应的目标区块,因此,不同的服务器均可以同步获取到其他服务器在区块链中的交易数据,从而实现交易数据的跨服务器共享。Among them, the target block is generated after the blockchain network receives the target transaction and packages the target transaction. The target block includes at least one target transaction, that is, the target block can be packaged by one or more target transactions. After the blockchain network generates the target block, the blockchain nodes in the blockchain network will reach a consensus on the target block. When the target block is passed by the blockchain network consensus, it indicates that the blockchain network recognizes the target transaction, and the target block will be stored on the blockchain, that is, the target block is "on-chained". After the target block is passed by the blockchain network consensus, the blockchain network will send the target block to the detection service, that is, the detection service will receive the target block sent by the blockchain network, where the sending action of the blockchain network can be for each new target block, that is, whenever a target block is passed by the blockchain network consensus, the blockchain network will send the target block to the detection service. In the scenario of the alliance chain, the target blocks generated by different blockchain nodes will be added to the blockchain. In other words, in addition to receiving the target block corresponding to its own server, the detection service can also receive the target blocks corresponding to other servers. Therefore, different servers can synchronously obtain the transaction data of other servers in the blockchain, thereby realizing cross-server sharing of transaction data.
在一种可能的实现方式中,当目标区块被区块链网络共识通过时,接收区块链网络发送的目标区块,具体可以是根据预设的区块号区间生成区块订阅请求,将区块订阅请求发送至区块链网络,每当位于区块号区间内的目标区块被区块链网络共识通过时,接收区块链网络响应区块订阅请求发送的目标区块。In one possible implementation, when the target block is approved by the blockchain network consensus, the target block sent by the blockchain network is received. Specifically, a block subscription request can be generated according to a preset block number interval, and the block subscription request can be sent to the blockchain network. Whenever the target block within the block number interval is approved by the blockchain network consensus, the target block sent by the blockchain network in response to the block subscription request is received.
其中,区块订阅请求用于向区块链网络订阅新区块事件,新区块事件用于在每当有新的目标区块被共识通过时向目标对象发送该目标区块,区块号区间用于指示检测服务的检测范围,即检测服务接收到的目标区块的区块号均位于区块号区间中。Among them, the block subscription request is used to subscribe to new block events from the blockchain network. The new block event is used to send the target block to the target object whenever a new target block is passed by consensus. The block number interval is used to indicate the detection range of the detection service, that is, the block numbers of the target blocks received by the detection service are all within the block number interval.
例如,区块号区间可以表示为[startBlockNumber,endBlockNumber],其中,startBlockNumber表示区间起始区块号,endBlockNumber表示区间结束区块号。另外,可以将endBlockNumber设置为负值,用以指示检测服务持续对新的目标区块进行检测。For example, the block number interval can be expressed as [startBlockNumber, endBlockNumber], where startBlockNumber represents the starting block number of the interval, and endBlockNumber represents the ending block number of the interval. In addition, endBlockNumber can be set to a negative value to instruct the detection service to continue detecting new target blocks.
通过向区块链网络发送区块订阅请求,能够使得检测服务与区块链网络之间建立自动的检测连接,使得每当位于区块号区间内的目标区块被区块链网络共识通过时,检测服务可以自动、连续地接收到新的目标区块,避免遗漏目标区块,同时,检测服务无须频繁地向区块链网络请求获取新的目标区块,可以提升检测服务与区块链网络之间的交互效率。By sending a block subscription request to the blockchain network, an automatic detection connection can be established between the detection service and the blockchain network, so that whenever a target block within the block number interval is approved by the blockchain network consensus, the detection service can automatically and continuously receive the new target block to avoid missing the target block. At the same time, the detection service does not need to frequently request the blockchain network to obtain new target blocks, which can improve the interaction efficiency between the detection service and the blockchain network.
步骤402:从目标区块中提取出目标交易的目标交易标识,以及目标交易关联的第一交易数据。Step 402: extracting a target transaction identifier of a target transaction and first transaction data associated with the target transaction from the target block.
其中,目标交易标识用于唯一标识目标交易,第一交易数据为存储在区块链上的交易数据,第一交易数据即链上交易数据,至少包括目标交易被执行后产生的数据,例如,以账户注册为例,第一交易数据可以包括后端服务在交易请求中提供的信息,例如账户标识、姓名、公钥等等,在此基础上,第一交易数据还可以包括链上地址,链上地址是目标区块被共识通过后区块链网络分配至对应的账户的,即链上地址是目标交易被执行后产生的数据。Among them, the target transaction identifier is used to uniquely identify the target transaction, and the first transaction data is the transaction data stored on the blockchain. The first transaction data is the on-chain transaction data, which at least includes the data generated after the target transaction is executed. For example, taking account registration as an example, the first transaction data may include the information provided by the back-end service in the transaction request, such as account identifier, name, public key, etc. On this basis, the first transaction data may also include the on-chain address. The on-chain address is assigned to the corresponding account by the blockchain network after the target block is passed by consensus, that is, the on-chain address is the data generated after the target transaction is executed.
在一种可能的实现方式中,当目标区块中包括多个目标交易时,检测服务可以遍历目标区块中的多个目标交易,针对每个目标交易进行解析,进而提取出目标交易的目标交易标识,以及目标交易关联的第一交易数据,从而不遗漏每一个目标交易。In one possible implementation, when the target block includes multiple target transactions, the detection service can traverse the multiple target transactions in the target block, parse each target transaction, and then extract the target transaction identifier of the target transaction and the first transaction data associated with the target transaction, so as not to miss any target transaction.
步骤403:访问存储有第一数据对的缓存服务,根据目标交易标识从缓存服务的第一数据对中获取目标交易关联的第二交易数据。Step 403: access the cache service storing the first data pair, and obtain the second transaction data associated with the target transaction from the first data pair of the cache service according to the target transaction identifier.
其中,缓存服务为检测服务以外的另外一个服务,主要用于存储第一数据对,在一种可能的实现方式中,缓存服务可以基于Redis(Remote Dictionary Server,远程字典服务)实现,基于Redis的缓存服务具备高吞吐量、高稳定性等优点。Among them, the cache service is another service besides the detection service, which is mainly used to store the first data pair. In a possible implementation, the cache service can be implemented based on Redis (Remote Dictionary Server). The cache service based on Redis has the advantages of high throughput, high stability, etc.
在一种可能的实现方式中,第一数据对基于交易标识和交易数据构建得到,即第一数据对用于存储交易标识和交易数据之间的关联关系,第一数据对可以为键值对,相对应地,键值对的键可以基于交易标识构建得到,键值对的值可以基于交易数据构建得到。由于交易数据由后端服务进行管理,因此,第一数据对可以由后端服务进行构建并存储至缓存服务中。In a possible implementation, the first data pair is constructed based on the transaction identifier and the transaction data, that is, the first data pair is used to store the association relationship between the transaction identifier and the transaction data, and the first data pair can be a key-value pair. Correspondingly, the key of the key-value pair can be constructed based on the transaction identifier, and the value of the key-value pair can be constructed based on the transaction data. Since the transaction data is managed by the backend service, the first data pair can be constructed by the backend service and stored in the cache service.
其中,第一数据对中的交易标识是由区块链网络在接收到异步发送的交易请求后返回的,交易请求为用于发起目标交易的请求,交易请求可以由后端服务异步发送至区块链网络,区块链网络在接收到交易请求以后,生成目标交易对应的目标交易标识,并作为交易请求的回复消息返回至后端服务,因此,后端服务可以得到目标交易对应的目标交易标识,并且,由于检测服务与区块链网络建立了连接,后端服务在向区块链网络发送了交易请求以后,并不需要等待交易请求被打包成目标区块以及目标区块被共识通过,只需要接收区块链网络立即返回的目标交易标识即可,换言之,后端服务可以基于异步的方式向区块链网络发送交易请求,相比于采用同步的方式向区块链网络发送交易请求(即向区块链网络发送交易请求后等待交易请求的执行结果才能进行后续的动作),能够显著地提升后端服务与区块链网络之间的交互效率。并且,在此架构下,后端服务也无须接收后续目标区块被共识通过后目标交易的交易结果,有利于降低后端服务的资源占用。Among them, the transaction identifier in the first data pair is returned by the blockchain network after receiving the asynchronously sent transaction request. The transaction request is a request for initiating a target transaction. The transaction request can be sent asynchronously by the back-end service to the blockchain network. After receiving the transaction request, the blockchain network generates a target transaction identifier corresponding to the target transaction and returns it to the back-end service as a reply message of the transaction request. Therefore, the back-end service can obtain the target transaction identifier corresponding to the target transaction. In addition, since the detection service has established a connection with the blockchain network, after the back-end service sends the transaction request to the blockchain network, it does not need to wait for the transaction request to be packaged into the target block and the target block to be passed by consensus. It only needs to receive the target transaction identifier returned immediately by the blockchain network. In other words, the back-end service can send the transaction request to the blockchain network based on an asynchronous method. Compared with sending the transaction request to the blockchain network in a synchronous manner (i.e., waiting for the execution result of the transaction request after sending the transaction request to the blockchain network before performing subsequent actions), it can significantly improve the interaction efficiency between the back-end service and the blockchain network. Moreover, under this architecture, the back-end service does not need to receive the transaction result of the target transaction after the subsequent target block is passed by consensus, which is conducive to reducing the resource occupation of the back-end service.
在一种可能的实现方式中,第一数据对的数量可以为多个,不同的第一数据对分别对应不同的交易标识。由于缓存服务的存储空间是有限的,因此,可以为每个第一数据对配置对应的有效时长,当第一数据对存储至缓存服务的时长达到有效时长以后,缓存服务可以将第一数据对进行删除,以释放缓存服务的存储空间,防止缓存服务数据膨胀。除此以外,当缓存服务的存储空间的占用比例达到预设的比例阈值时,可以根据存储时间由早到晚或者由晚到早的顺序对第一数据对进行排序,将排序在预设的排名阈值之前或者之后的第一数据对删除,以释放缓存服务的存储空间,防止缓存服务数据膨胀。In one possible implementation, the number of first data pairs can be multiple, and different first data pairs correspond to different transaction identifiers. Since the storage space of the cache service is limited, a corresponding effective time can be configured for each first data pair. When the time for which the first data pair is stored in the cache service reaches the effective time, the cache service can delete the first data pair to release the storage space of the cache service and prevent the cache service data from expanding. In addition, when the occupancy ratio of the storage space of the cache service reaches a preset ratio threshold, the first data pairs can be sorted according to the storage time from early to late or from late to early, and the first data pairs sorted before or after the preset ranking threshold can be deleted to release the storage space of the cache service and prevent the cache service data from expanding.
其中,第二交易数据即不上链交易数据,一般存储在本地,例如一些需要保密的交易数据(住址、登录次数等)。检测服务在从目标区块中解析出目标交易标识以后,可以根据目标交易标识与各个第一数据对中的交易标识进行匹配,进而确定目标交易标识对应的第二交易数据。例如,参照图5,图5为本申请实施例提供的确定目标交易标识对应的第二交易数据的一种可选的流程示意图,假设缓存服务中存储有三个第一数据对,分别为[TxId1,AAA]、[TxId2,BBB]和[TxId3,CCC],当目标交易标识为TxId2时,可以确定对应的第二交易数据为BBB。Among them, the second transaction data is transaction data that is not on the chain, and is generally stored locally, such as some transaction data that needs to be kept confidential (address, number of logins, etc.). After the detection service parses the target transaction identifier from the target block, it can match the target transaction identifier with the transaction identifier in each first data pair, and then determine the second transaction data corresponding to the target transaction identifier. For example, referring to Figure 5, Figure 5 is an optional flow chart for determining the second transaction data corresponding to the target transaction identifier provided in an embodiment of the present application. Assuming that three first data pairs are stored in the cache service, namely [TxId1, AAA], [TxId2, BBB] and [TxId3, CCC], when the target transaction identifier is TxId2, it can be determined that the corresponding second transaction data is BBB.
在一种可能的实现方式中,后端服务在基于交易标识构建键值对的键时,可以在交易标识的基础上增加前缀信息,前缀信息用于将交易标识与不同类型的数据构建为数据对,不同的前缀信息可以与交易标识组成键值对中不同的键。例如,在构建第一数据对时,可以在目标交易标识TxId1前增加“txid/req”,此时第一数据对可以为[txid/req/TxId1,AAA],从而能够将用于获取第二交易数据的第一数据对与其他数据对进行区分。In a possible implementation, when the backend service constructs the key of the key-value pair based on the transaction identifier, prefix information may be added on the basis of the transaction identifier. The prefix information is used to construct the transaction identifier and different types of data into a data pair, and different prefix information may form different keys in the key-value pair with the transaction identifier. For example, when constructing the first data pair, "txid/req" may be added before the target transaction identifier TxId1. In this case, the first data pair may be [txid/req/TxId1, AAA], so that the first data pair used to obtain the second transaction data can be distinguished from other data pairs.
由于第一数据对基于交易标识和交易数据构建得到,因此通过引入缓存服务,使得在第二交易数据不需要进行上链操作的情况下,也能够根据目标交易标识获取到目标交易关联的第二交易数据,从而在跨服务器共享交易数据的场景下提升交易数据的安全性。Since the first data pair is constructed based on the transaction identifier and the transaction data, by introducing the cache service, the second transaction data associated with the target transaction can be obtained according to the target transaction identifier without the need for the second transaction data to be uploaded to the chain, thereby improving the security of the transaction data in the scenario of sharing transaction data across servers.
步骤404:根据第一交易数据和第二交易数据得到目标交易数据,将目标交易数据存储至目标数据库。Step 404: Obtain target transaction data according to the first transaction data and the second transaction data, and store the target transaction data in a target database.
在一种可能的实现方式中,根据第一交易数据和第二交易数据得到目标交易数据,具体可以是将第一交易数据和第二交易数据合并得到目标交易数据。In a possible implementation manner, the target transaction data is obtained according to the first transaction data and the second transaction data. Specifically, the first transaction data and the second transaction data may be combined to obtain the target transaction data.
其中,目标数据库可以为服务器本地的数据库,可以理解的是,服务器本地的数据库,可以是部署在服务器中的数据库,也可以是与服务器建立通信连接的数据库。The target database may be a local database of the server. It is understandable that the local database of the server may be a database deployed in the server or a database that establishes a communication connection with the server.
检测服务通过根据第一交易数据和第二交易数据得到目标交易数据,将目标交易数据存储至目标数据库,使得目标数据库中既可以存储有区块链中的第一交易数据,也可以存储有不在区块链中的第二交易数据,提升本地数据库中的交易数据的完整性。The detection service obtains the target transaction data based on the first transaction data and the second transaction data, and stores the target transaction data in the target database, so that the target database can store both the first transaction data in the blockchain and the second transaction data that is not in the blockchain, thereby improving the integrity of the transaction data in the local database.
可见,检测服务通过当目标区块被区块链网络共识通过时,接收区块链网络发送的目标区块,从目标区块中提取出目标交易关联的第一交易数据,在多个不同的服务器参与区块链业务系统的场景下,不同的服务器均可以同步获取到其他服务器在区块链中的交易数据,从而实现交易数据的跨服务器共享,并且,通过从目标区块中提取出目标交易的目标交易标识,访问存储有第一数据对的缓存服务,根据目标交易标识从缓存服务的第一数据对中获取目标交易关联的第二交易数据,由于第一数据对基于交易标识和交易数据构建得到,因此通过引入缓存服务,使得在第二交易数据不需要进行上链操作的情况下,也能够根据目标交易标识获取到目标交易关联的第二交易数据,从而在跨服务器共享交易数据的场景下提升交易数据的安全性,在此基础上,能够根据第一交易数据和第二交易数据得到目标交易数据,将目标交易数据存储至目标数据库,使得目标数据库中既可以存储有区块链中的第一交易数据,也可以存储有不在区块链中的第二交易数据,从而在提升交易数据的安全性的基础上,提升本地数据库中的交易数据的完整性。It can be seen that the detection service receives the target block sent by the blockchain network when the target block is passed by the blockchain network consensus, and extracts the first transaction data associated with the target transaction from the target block. In the scenario where multiple different servers participate in the blockchain business system, different servers can synchronously obtain the transaction data of other servers in the blockchain, thereby realizing cross-server sharing of transaction data, and by extracting the target transaction identifier of the target transaction from the target block, accessing the cache service storing the first data pair, and obtaining the second transaction data associated with the target transaction from the first data pair of the cache service according to the target transaction identifier. Since the first data pair is constructed based on the transaction identifier and the transaction data, by introducing the cache service, the second transaction data associated with the target transaction can be obtained according to the target transaction identifier when the second transaction data does not need to be on-chained, thereby improving the security of transaction data in the scenario of cross-server sharing of transaction data. On this basis, the target transaction data can be obtained according to the first transaction data and the second transaction data, and the target transaction data can be stored in the target database, so that the target database can store both the first transaction data in the blockchain and the second transaction data that is not in the blockchain, thereby improving the integrity of the transaction data in the local database on the basis of improving the security of the transaction data.
在一种可能的实现方式中,检测服务还可以进一步生成目标交易数据的存储结果信息,基于目标交易标识和存储结果信息构建第二数据对,将第二数据对存储至缓存服务中。In a possible implementation, the detection service may further generate storage result information of the target transaction data, construct a second data pair based on the target transaction identifier and the storage result information, and store the second data pair in the cache service.
其中,存储结果信息用于指示目标交易数据已成功存储至目标数据库或者未成功存储至目标数据库,第二数据对是由检测服务基于目标交易标识和存储结果信息构建的,与第一数据对结构类似,第二数据对同样可以采用键值对的形式,目标交易标识作为键值对的键,存储结果信息作为键值对的值。参见前面的解释,由于第二数据对同样是基于目标交易标识构建的,因此,在基于目标交易标识构建键值对的键时,同样可以在目标交易标识的基础上增加前缀信息,例如,在构建第二数据对时,可以在目标交易标识TxId1前增加“txid/resp”,此时第二数据对可以为[txid/resp/TxId1,AAA],从而能够将第二数据对与第一数据对进行区分。Among them, the storage result information is used to indicate that the target transaction data has been successfully stored in the target database or has not been successfully stored in the target database. The second data pair is constructed by the detection service based on the target transaction identifier and the storage result information. Similar to the structure of the first data pair, the second data pair can also be in the form of a key-value pair, with the target transaction identifier as the key of the key-value pair and the storage result information as the value of the key-value pair. Referring to the previous explanation, since the second data pair is also constructed based on the target transaction identifier, when constructing the key of the key-value pair based on the target transaction identifier, prefix information can also be added on the basis of the target transaction identifier. For example, when constructing the second data pair, "txid/resp" can be added before the target transaction identifier TxId1. At this time, the second data pair can be [txid/resp/TxId1, AAA], so that the second data pair can be distinguished from the first data pair.
在一种可能的实现方式中,存储结果信息可以包括目标交易数据的存储结果和目标交易数据,除此以外,存储结果信息也可以只包括目标交易数据的存储结果。In a possible implementation, the storage result information may include the storage result of the target transaction data and the target transaction data. In addition, the storage result information may also only include the storage result of the target transaction data.
例如,参照图6,图6为本申请实施例提供的后端服务与缓存服务基于第二数据对的交互流程示意图,以目标交易为账户注册作为例子,若目标交易数据未成功存储至目标数据库,则存储结果信息可以为{“错误信息”:写入失败;“账户信息”:“空”},此时,“错误信息”不为空,“账户信息”(即目标交易数据)为空,指示目标交易数据未成功存储至目标数据库;若目标交易数据成功存储至目标数据库,则存储结果信息可以为{“错误信息”:空;“账户信息”:“XXX”},此时,“错误信息”为空,“账户信息”不为空,指示目标交易数据成功存储至目标数据库。接着可以以“txid/resp/TxId1”作为键值对的键,以检测服务成功将目标交易数据存储至目标数据库作为例子,则第二数据对可以为[txid/resp/TxId1,{“错误信息”:空;“账户信息”:“XXX”}]。接下来,后端服务即可以基于区块链网络返回的目标交易标识构建键值对的键“txid/resp/TxId1”,从缓存服务中匹配得到键值对的值{“错误信息”:空;“账户信息”:“XXX”}。For example, referring to FIG6, FIG6 is a schematic diagram of the interaction process between the backend service and the cache service provided by the embodiment of the present application based on the second data pair. Taking the target transaction as an example of account registration, if the target transaction data is not successfully stored in the target database, the storage result information can be {"error information": write failure; "account information": "null"}, at this time, "error information" is not null, "account information" (i.e., target transaction data) is null, indicating that the target transaction data is not successfully stored in the target database; if the target transaction data is successfully stored in the target database, the storage result information can be {"error information": null; "account information": "XXX"}, at this time, "error information" is null, "account information" is not null, indicating that the target transaction data is successfully stored in the target database. Then, "txid/resp/TxId1" can be used as the key of the key-value pair, and the detection service successfully stores the target transaction data in the target database as an example, then the second data pair can be [txid/resp/TxId1, {"error information": null; "account information": "XXX"}]. Next, the backend service can construct the key "txid/resp/TxId1" of the key-value pair based on the target transaction identifier returned by the blockchain network, and match the value of the key-value pair {"error message": empty; "account information": "XXX"} from the cache service.
检测服务通过基于目标交易标识和存储结果信息构建第二数据对,将第二数据对存储至缓存服务中,便于后端服务可以从缓存服务中获取交易数据的存储结果,以便后端服务进行后续的处理,例如发送存储结果对应的通知消息等。并且,由于引入缓存服务,检测服务和后端服务之间无须进行同步通信,提升检测服务和后端服务之间的交互效率。The detection service constructs a second data pair based on the target transaction identifier and the storage result information, and stores the second data pair in the cache service, so that the backend service can obtain the storage result of the transaction data from the cache service, so that the backend service can perform subsequent processing, such as sending a notification message corresponding to the storage result. In addition, due to the introduction of the cache service, there is no need for synchronous communication between the detection service and the backend service, which improves the interaction efficiency between the detection service and the backend service.
在一种可能的实现方式中,检测服务还可以当目标交易数据已成功存储至目标数据库时,确定目标区块的区块号以及当前的目标交易在目标区块中的交易序号,记录区块号以及交易序号,在重新启动后,加载区块号以及交易序号,根据区块号以及交易序号确定下一个目标交易。In one possible implementation, the detection service can also determine the block number of the target block and the transaction sequence number of the current target transaction in the target block when the target transaction data has been successfully stored in the target database, record the block number and the transaction sequence number, load the block number and the transaction sequence number after restarting, and determine the next target transaction based on the block number and the transaction sequence number.
其中,区块号即目标区块在区块链中的编号,交易序号用于指示目标交易在目标区块中的位置顺序,例如,若交易序号为2,则该目标交易为目标区块中的第二个交易。在将目标交易数据存储至目标数据库的过程中,可能会存在目标数据库不可用的情况,造成目标交易数据无法成功存储至目标数据库,此时,由于交易数据已经存储至区块链上,从而出现链上数据与本地数据之间不一致的问题。在本申请实施例中,通过当目标交易数据已成功存储至目标数据库时,确定目标区块的区块号以及当前的目标交易在目标区块中的交易序号,对于下一个目标交易来说,若在将下一个目标交易对应的目标交易数据存储至目标数据库时,目标数据库出现了宕机,则检测服务并不会记录下一个目标交易对应的区块号和交易序号,此时检测服务记录的依然为上一个目标交易对应的区块号和交易序号,因此,检测服务可以基于预设的频率进行重启,在重新启动以后,若目标数据库的恢复正常,则检测服务可以加载上一个目标交易对应的区块号和交易序号,从上一个目标交易对应的区块号和交易序号开始重新尝试处理,直至成功将目标交易数据存储至目标数据库中,并更新区块号和交易序号的记录。The block number is the number of the target block in the blockchain, and the transaction number is used to indicate the position order of the target transaction in the target block. For example, if the transaction number is 2, the target transaction is the second transaction in the target block. In the process of storing the target transaction data in the target database, the target database may be unavailable, resulting in the failure to successfully store the target transaction data in the target database. At this time, since the transaction data has been stored on the blockchain, there will be inconsistencies between the on-chain data and the local data. In an embodiment of the present application, when the target transaction data has been successfully stored in the target database, the block number of the target block and the transaction sequence number of the current target transaction in the target block are determined. For the next target transaction, if the target database crashes when the target transaction data corresponding to the next target transaction is stored in the target database, the detection service will not record the block number and transaction sequence number corresponding to the next target transaction. At this time, the detection service still records the block number and transaction sequence number corresponding to the previous target transaction. Therefore, the detection service can be restarted based on a preset frequency. After restarting, if the target database recovers normally, the detection service can load the block number and transaction sequence number corresponding to the previous target transaction, and retry processing from the block number and transaction sequence number corresponding to the previous target transaction until the target transaction data is successfully stored in the target database and the records of the block number and transaction sequence number are updated.
可见,上述方式能够提升存储在区块链上的交易数据和存储在目标数据库中的交易数据之间的一致性,提升交易数据的可靠性。并且,通过记录区块号以及交易序号,检测服务不需要从第一个区块的第一个目标交易开始重新处理,减少了冗余的无用操作,显著地提升了交易数据的处理效率。另外,检测服务通过定期重启,不断地从上一个目标交易对应的区块号和交易序号开始重新尝试处理,此过程无须人工介入,也可以有效地提升交易数据的处理效率。It can be seen that the above method can improve the consistency between the transaction data stored on the blockchain and the transaction data stored in the target database, and improve the reliability of the transaction data. In addition, by recording the block number and transaction sequence number, the detection service does not need to reprocess from the first target transaction of the first block, reducing redundant useless operations and significantly improving the efficiency of transaction data processing. In addition, the detection service restarts regularly and continuously tries to process from the block number and transaction sequence number corresponding to the previous target transaction. This process does not require manual intervention and can also effectively improve the efficiency of transaction data processing.
例如,参照图7,图7为本申请实施例提供的目标数据库不可用时的一种可选的处理流程示意图,假设当前的目标区块的区块号为0,该目标区块中包括两个目标交易,交易序号分别为0和1,检测服务在接收到目标区块时,先对交易序号为0的目标交易进行处理,将交易序号为0的目标交易对应的目标交易数据存储至目标数据库中,此时,检测服务记录区块号0和交易序号0;接下来对交易序号为1的目标交易进行处理,此时,目标数据库出现了宕机,检测服务未能成功将交易序号为0的目标交易对应的目标交易数据存储至目标数据库中,因此并不会更新区块号0和交易序号0,而是基于预设的频率进行重启,在目标数据库恢复正常后,从区块号0和交易序号0的下一个目标交易开始进行处理,即从区块号0和交易序号1的目标交易开始进行处理,在将交易序号为1的目标交易对应的目标交易数据存储至目标数据库中后,检测服务将原本记录的“区块号0和交易序号0”更新为“区块号0和交易序号1”,如此往复,若处理下一个目标交易(例如是区块号为1、交易序号为0的目标交易)时目标数据库同样出现了宕机,则可以采用同样的方式成功将区块号为1、交易序号为0的目标交易对应的目标交易数据存储至目标数据库,从而保持链上交易数据和本地交易数据之间的一致性。For example, referring to FIG. 7 , FIG. 7 is a schematic diagram of an optional processing flow when the target database provided in an embodiment of the present application is unavailable. Assuming that the block number of the current target block is 0, the target block includes two target transactions with transaction numbers 0 and 1, respectively. When the detection service receives the target block, it first processes the target transaction with transaction number 0, and stores the target transaction data corresponding to the target transaction with transaction number 0 in the target database. At this time, the detection service records the block number 0 and the transaction number 0; then processes the target transaction with transaction number 1. At this time, the target database crashes, and the detection service fails to successfully store the target transaction data corresponding to the target transaction with transaction number 0 in the target database. Therefore, the block number 0 and the transaction number 0 are not updated, but based on the prediction It restarts at the set frequency. After the target database returns to normal, it starts processing from the next target transaction with block number 0 and transaction sequence number 0, that is, it starts processing from the target transaction with block number 0 and transaction sequence number 1. After storing the target transaction data corresponding to the target transaction with transaction sequence number 1 in the target database, the detection service updates the originally recorded "block number 0 and transaction sequence number 0" to "block number 0 and transaction sequence number 1", and so on. If the target database also crashes when processing the next target transaction (for example, the target transaction with block number 1 and transaction sequence number 0), the target transaction data corresponding to the target transaction with block number 1 and transaction sequence number 0 can be successfully stored in the target database in the same way, thereby maintaining the consistency between the on-chain transaction data and the local transaction data.
在一种可能的实现方式中,若目标交易的交易类型为链配置类型时,检测服务可以从目标区块中提取出目标服务器的服务器属性信息,以及区块链网络为目标服务器分配的服务器交易证书,将服务器属性信息和服务器交易证书存储至目标数据库。In one possible implementation, if the transaction type of the target transaction is a chain configuration type, the detection service can extract the server attribute information of the target server and the server transaction certificate assigned to the target server by the blockchain network from the target block, and store the server attribute information and the server transaction certificate in the target database.
其中,在联盟链的场景下,会有多个不同的业务提供方参与到区块链业务系统中,每个业务提供方对应一个目标服务器,目标服务器为目标交易配置的服务器,目标交易配置目标服务器,即将目标服务器对应的区块链节点添加至区块链网络中,在将目标服务器对应的区块链节点添加至区块链网络后,会给目标服务器分配一个服务器交易证书和服务器私钥,并且,目标服务器对应的区块链节点会将服务器属性信息和服务器交易证书打包成目标区块,在共识通过以后存储至区块链中。Among them, in the scenario of alliance chain, there will be multiple different business providers participating in the blockchain business system. Each business provider corresponds to a target server. The target server is the server configured for the target transaction. The target transaction configures the target server, that is, the blockchain node corresponding to the target server is added to the blockchain network. After the blockchain node corresponding to the target server is added to the blockchain network, a server transaction certificate and a server private key will be assigned to the target server. In addition, the blockchain node corresponding to the target server will package the server attribute information and the server transaction certificate into a target block, which will be stored in the blockchain after the consensus is passed.
其中,服务器属性信息用于指示服务器的属性,例如可以是UNI、APPI D(应用标识)等等。通过从目标区块中提取出目标服务器的服务器属性信息,以及区块链网络为目标服务器分配的服务器交易证书,并将服务器属性信息和服务器交易证书存储至目标数据库,在多个不同的业务提供方参与区块链业务系统的场景下,只要有新的目标服务器加入,其他服务器均可以获取到新加入的目标服务器的服务器属性信息和服务器交易证书,从而达到服务器属性信息和服务器交易证书的共享效果。Among them, the server attribute information is used to indicate the attributes of the server, such as UNI, APPID (application identification), etc. By extracting the server attribute information of the target server from the target block, and the server transaction certificate assigned to the target server by the blockchain network, and storing the server attribute information and the server transaction certificate in the target database, in the scenario where multiple different business providers participate in the blockchain business system, as long as a new target server joins, other servers can obtain the server attribute information and server transaction certificate of the newly joined target server, thereby achieving the sharing effect of server attribute information and server transaction certificate.
其中,服务器属性信息和服务器交易证书可以存储在目标交易数据对应的数据表以外的其他数据表中。The server attribute information and the server transaction certificate may be stored in other data tables other than the data table corresponding to the target transaction data.
例如,业务提供方G的目标服务器对应的区块链节点加入了区块链网络,会给该目标服务器分配一个服务器交易证书Cert-G和服务器私钥key-G,后续会将服务器交易证书Cert-G和该目标服务器的UNI-G、APPI D-G打包为链配置类型的目标区块,在该目标区块被共识通过以后,业务提供方G的目标服务器对应的检测服务会接收到该目标区块,将UNI-G、APPI D-G和Cert-G存储至目标数据库;同理,业务提供方B的目标服务器对应的区块链节点加入了区块链网络后,业务提供方B的目标服务器对应的检测服务同样可以从对应的目标区块中提取出UNI-B、APPI D-B和Cert-B并存储至目标数据库,此时,业务提供方G的目标服务器中的目标数据库则存储了自身的业务方数据“UNI-G、APPI D-G和Cert-G”,以及业务提供方B的业务方数据“UNI-B、APPI D-B和Cert-B”。类似地,对于业务提供方B的目标服务器来说,则从区块链中的第一个目标区块开始处理,同样可以将业务提供方G的业务方数据“UNI-G、APPI D-G和Cert-G”,以及自身的业务方数据“UNI-B、APPI D-B和Cert-B”存储至目标数据库,可见,业务提供方G的目标服务器和业务提供方B的目标服务器之间实现了业务方数据的共享。For example, the blockchain node corresponding to the target server of business provider G joins the blockchain network, and a server transaction certificate Cert-G and a server private key key-G are assigned to the target server. Subsequently, the server transaction certificate Cert-G and the UNI-G and APPI D-G of the target server are packaged into a target block of the chain configuration type. After the target block is passed by consensus, the detection service corresponding to the target server of business provider G receives the target block and stores UNI-G, APPI D-G and Cert-G in the target database. Similarly, after the blockchain node corresponding to the target server of business provider B joins the blockchain network, the detection service corresponding to the target server of business provider B can also extract UNI-B, APPI D-B and Cert-B from the corresponding target block and store them in the target database. At this time, the target database in the target server of business provider G stores its own business party data "UNI-G, APPI D-G and Cert-G", as well as the business party data "UNI-B, APPI D-B and Cert-B" of business provider B. Similarly, for the target server of business provider B, processing starts from the first target block in the blockchain, and the business party data "UNI-G, APPI D-G and Cert-G" of business provider G and its own business party data "UNI-B, APPI D-B and Cert-B" can also be stored in the target database. It can be seen that the business party data is shared between the target server of business provider G and the target server of business provider B.
当多个不同的业务提供方参与到区块链业务系统时,在一种可能的实现方式中,在根据第一交易数据和第二交易数据得到目标交易数据时,具体可以从目标区块中提取出对目标交易进行签名时使用的目标交易证书,将目标交易证书与服务器交易证书进行匹配,根据匹配结果从目标数据库中获取目标交易对应的服务器属性信息,将第一交易数据、第二交易数据、服务器属性信息和目标交易证书合并为目标交易数据。When multiple different business providers participate in the blockchain business system, in one possible implementation, when obtaining the target transaction data based on the first transaction data and the second transaction data, the target transaction certificate used to sign the target transaction can be extracted from the target block, the target transaction certificate can be matched with the server transaction certificate, and the server attribute information corresponding to the target transaction can be obtained from the target database based on the matching result, and the first transaction data, the second transaction data, the server attribute information and the target transaction certificate can be merged into the target transaction data.
其中,目标服务器的后端服务在发起目标交易的交易请求时会利用自身的目标交易证书对交易请求进行签名,并附上目标交易证书,因而可以从后续的目标区块中提取出该目标交易证书。Among them, when initiating a transaction request for a target transaction, the backend service of the target server will use its own target transaction certificate to sign the transaction request and attach the target transaction certificate, so that the target transaction certificate can be extracted from the subsequent target block.
另外,由于目标数据库中存储有多个不同的服务器属性信息和对应的服务器交易证书,因此,可以根据目标交易证书与服务器交易证书之间的匹配结果,确定目标交易证书对应的服务器属性信息,将第一交易数据、第二交易数据、服务器属性信息和目标交易证书合并为目标交易数据,因此,能够扩充目标交易数据的种类,提升目标交易数据的完整性。In addition, since the target database stores multiple different server attribute information and corresponding server transaction certificates, the server attribute information corresponding to the target transaction certificate can be determined based on the matching result between the target transaction certificate and the server transaction certificate, and the first transaction data, the second transaction data, the server attribute information and the target transaction certificate can be merged into the target transaction data. Therefore, the types of target transaction data can be expanded and the integrity of the target transaction data can be improved.
例如,若第一交易数据为“账户标识、姓名、公钥、链上地址”,第二交易数据为“住址、登录次数”,服务器属性信息为“UNI-G、APPI D-G”,目标交易证书为“Cert-G”,则目标交易数据为“账户标识、姓名、公钥、链上地址、住址、登录次数、UN I-G、APPI D-G、Cert-G”。For example, if the first transaction data is "account identification, name, public key, on-chain address", the second transaction data is "address, number of logins", the server attribute information is "UNI-G, APPI D-G", and the target transaction certificate is "Cert-G", then the target transaction data is "account identification, name, public key, on-chain address, address, number of logins, UN I-G, APPI D-G, Cert-G".
当多个不同的业务提供方参与到区块链业务系统时,在一种可能的实现方式中,访问存储有第一数据对的缓存服务,具体可以是从目标区块中提取出在对目标交易进行签名时使用的目标交易证书,获取在启动时加载的服务器交易证书,将在启动时加载的服务器交易证书与目标交易证书进行比较,当比较结果为在启动时加载的服务器交易证书与目标交易证书相一致时,访问存储有第一数据对的缓存服务。When multiple different business providers participate in the blockchain business system, in one possible implementation, accessing the cache service storing the first data pair can specifically include extracting a target transaction certificate used to sign the target transaction from the target block, obtaining a server transaction certificate loaded at startup, and comparing the server transaction certificate loaded at startup with the target transaction certificate. When the comparison result is that the server transaction certificate loaded at startup is consistent with the target transaction certificate, accessing the cache service storing the first data pair.
其中,检测服务在启动时,会加载检测服务所在的目标服务器的服务器交易证书,该服务器交易证书即目标服务器对应的区块链节点在加入区块链网络后,区块链网络为目标服务器分配的证书,由于服务器交易证书具备唯一性,即不同的目标服务器的服务器交易证书不相同,因此,可以通过比较服务器交易证书与目标交易证书是否相一致,来确定目标交易是本地发起的还是异地发起的,当目标交易证书与服务器交易证书相一致时,表明目标交易是本地发起的,当目标交易证书与服务器交易证书不一致时,表明目标交易是异地发起的。Among them, when the detection service is started, the server transaction certificate of the target server where the detection service is located will be loaded. The server transaction certificate is the certificate assigned to the target server by the blockchain network after the blockchain node corresponding to the target server joins the blockchain network. Since the server transaction certificate is unique, that is, the server transaction certificates of different target servers are different, therefore, by comparing whether the server transaction certificate is consistent with the target transaction certificate, it can be determined whether the target transaction is initiated locally or remotely. When the target transaction certificate is consistent with the server transaction certificate, it indicates that the target transaction is initiated locally. When the target transaction certificate is inconsistent with the server transaction certificate, it indicates that the target transaction is initiated remotely.
在一种可能的实现方式中,为了进一步提升交易数据的安全性,缓存服务可以是分别部署在各个目标服务器中的,相应地,缓存服务中可以只存储当前的目标服务器对应的第二交易数据,即本地的第二交易数据,由于当目标交易证书与服务器交易证书相一致时,表明目标交易是本地发起的,因此可以访问缓存服务,成功获取到对应的第二交易数据;而当目标交易证书与服务器交易证书不一致时,表明目标交易是异地发起的,因此缓存服务中也不会存在对应的第二交易数据,此时检测服务可以不访问缓存服务,即当比较结果为在启动时加载的服务器交易证书与目标交易证书不一致时,可以直接将第一交易数据作为目标交易数据,将目标交易数据存储至目标数据库,从而减少检测服务与缓存服务之间的冗余交互。In one possible implementation, in order to further improve the security of transaction data, the cache service can be deployed in each target server respectively. Accordingly, the cache service can only store the second transaction data corresponding to the current target server, that is, the local second transaction data. When the target transaction certificate is consistent with the server transaction certificate, it indicates that the target transaction is initiated locally. Therefore, the cache service can be accessed to successfully obtain the corresponding second transaction data; when the target transaction certificate is inconsistent with the server transaction certificate, it indicates that the target transaction is initiated remotely. Therefore, the corresponding second transaction data will not exist in the cache service. At this time, the detection service may not access the cache service, that is, when the comparison result is that the server transaction certificate loaded at startup is inconsistent with the target transaction certificate, the first transaction data can be directly used as the target transaction data, and the target transaction data can be stored in the target database, thereby reducing redundant interactions between the detection service and the cache service.
例如,承接前述的例子,业务提供方G的目标服务器的目标数据库中存储了“UNI-G、APPI D-G和Cert-G”和“UNI-B、APPI D-B和Cert-B”,若检测服务从目标区块中提取出的目标交易证书为“Cert-G”,即目标交易证书与服务器交易证书相一致,表明该目标交易是由业务提供方G的目标服务器的后端服务发起的,从而可以访问缓存服务,进而获取第二交易数据,否则不访问缓存服务。For example, following the previous example, the target database of the target server of the service provider G stores "UNI-G, APPI D-G and Cert-G" and "UNI-B, APPI D-B and Cert-B". If the target transaction certificate extracted by the detection service from the target block is "Cert-G", that is, the target transaction certificate is consistent with the server transaction certificate, it indicates that the target transaction is initiated by the back-end service of the target server of the service provider G, so that the cache service can be accessed to obtain the second transaction data, otherwise the cache service will not be accessed.
除此以外,缓存服务也可以是多个目标服务器共用的,在这种情况下,后端服务将第一数据对存储至缓存服务中时,可以对第一数据对中的第二交易数据进行加密,得到加密交易数据,同时,构建第一数据对的目标服务器中的后端服务生成加密交易数据对应的解密信息,并将加密交易数据对应的解密信息发送至各个目标服务器的检测服务(包括自身所在的目标服务器),因此,当比较结果为在启动时加载的服务器交易证书与目标交易证书不一致时,检测服务可以访问缓存服务,根据第一数据对从缓存服务中获取目标交易标识对应的加密交易数据,获取预先存储的解密信息,根据解密信息对加密交易数据进行解密处理,得到目标交易标识对应的第二交易数据,根据第一交易数据和第二交易数据得到目标交易数据,将目标交易数据存储至目标数据库。In addition, the cache service can also be shared by multiple target servers. In this case, when the back-end service stores the first data pair in the cache service, it can encrypt the second transaction data in the first data pair to obtain encrypted transaction data. At the same time, the back-end service in the target server that constructs the first data pair generates decryption information corresponding to the encrypted transaction data, and sends the decryption information corresponding to the encrypted transaction data to the detection service of each target server (including the target server where it is located). Therefore, when the comparison result is that the server transaction certificate loaded at startup is inconsistent with the target transaction certificate, the detection service can access the cache service, obtain the encrypted transaction data corresponding to the target transaction identifier from the cache service according to the first data pair, obtain the pre-stored decryption information, decrypt the encrypted transaction data according to the decryption information, obtain the second transaction data corresponding to the target transaction identifier, obtain the target transaction data based on the first transaction data and the second transaction data, and store the target transaction data in the target database.
并且,不同的第一数据对中的加密交易数据对应的解密信息不相同,即后端服务在构建不同的第一数据对时,均会更新对应的解密信息。同时,后端服务可以选择一个或者多个的其他目标服务器发送解密信息,只有接收到解密信息的目标服务器的检测服务能够成功解密出第二交易数据,能够接收解密信息的后端服务可以根据实际需求而定,本申请实施例不做限定。Furthermore, the decryption information corresponding to the encrypted transaction data in different first data pairs is different, that is, the backend service will update the corresponding decryption information when constructing different first data pairs. At the same time, the backend service can select one or more other target servers to send decryption information. Only the detection service of the target server that receives the decryption information can successfully decrypt the second transaction data. The backend service that can receive the decryption information can be determined according to actual needs, and the embodiments of this application do not limit it.
在一种可能的实现方式中,可以采用常用的加密算法对对第一数据对中的第二交易数据进行加密,例如对称加密算法、非对称加密算法、哈希算法等等,相应地,解密信息可以是解密密钥,本申请实施例不做限定。In one possible implementation, the second transaction data in the first data pair can be encrypted using a commonly used encryption algorithm, such as a symmetric encryption algorithm, an asymmetric encryption algorithm, a hash algorithm, etc. Correspondingly, the decryption information can be a decryption key, which is not limited in the embodiments of the present application.
例如,参照图8,图8为本申请实施例提供的多个目标服务器共用缓存服务时一种可选的数据交互示意图,业务提供方G的目标服务器和业务提供方B的目标服务器共用一个缓存服务,业务提供方B的目标服务器中的后端服务在构建第一数据对时对第二交易数据进行加密,再存储至缓存服务中,并且,将对应的解密信息发送至各个目标服务器的检测服务中,对于业务提供方B的目标服务器中的检测服务来说,基于目标交易标识从缓存服务中获取到加密的第一数据对以后,基于业务提供方B的目标服务器中的后端服务发送的解密信息对加密交易数据进行解密,进而将解密还原得到的第二交易数据和第一交易数据存储至业务提供方B的目标服务器中的目标数据库;类似地,对于业务提供方G的目标服务器中的检测服务来说,基于目标交易标识从缓存服务中获取到加密的第一数据对以后,基于业务提供方B的目标服务器中的后端服务发送的解密信息对加密交易数据进行解密,进而将解密还原得到的第二交易数据和第一交易数据存储至业务提供方G的目标服务器中的目标数据库。For example, referring to Figure 8, Figure 8 is an optional data interaction diagram when multiple target servers share a cache service provided in an embodiment of the present application. The target server of business provider G and the target server of business provider B share a cache service. The back-end service in the target server of business provider B encrypts the second transaction data when constructing the first data pair, and then stores it in the cache service, and sends the corresponding decryption information to the detection service of each target server. For the detection service in the target server of business provider B, after obtaining the encrypted first data pair from the cache service based on the target transaction identifier, the encrypted transaction data is decrypted based on the decryption information sent by the back-end service in the target server of business provider B, and then the second transaction data and the first transaction data obtained by decryption and restoration are stored in the target database in the target server of business provider B; similarly, for the detection service in the target server of business provider G, after obtaining the encrypted first data pair from the cache service based on the target transaction identifier, the encrypted transaction data is decrypted based on the decryption information sent by the back-end service in the target server of business provider B, and then the second transaction data and the first transaction data obtained by decryption and restoration are stored in the target database in the target server of business provider G.
通过多个目标服务器共用一个缓存服务,可以简化各个目标服务器的内部架构,并且,缓存服务中的第一数据对均被进行了加密,在多个目标服务器共用一个缓存服务的场景下,能够有效地提升交易数据的安全性。By having multiple target servers share one cache service, the internal architecture of each target server can be simplified, and the first data pairs in the cache service are all encrypted. In the scenario where multiple target servers share one cache service, the security of transaction data can be effectively improved.
下面说明本申请实施例中检测服务的详细处理流程,参照图9,图9为本申请实施例提供的检测服务的一种可选的详细处理流程示意图,具体可以包括以下步骤901至步骤907。The following describes a detailed processing flow of the detection service in an embodiment of the present application, with reference to FIG. 9 , which is a schematic diagram of an optional detailed processing flow of the detection service provided in an embodiment of the present application, and may specifically include the following steps 901 to 907 .
步骤901:检测服务向区块链网络发送区块订阅请求,当目标区块被区块链网络共识通过时,接收区块链网络发送的目标区块;Step 901: The detection service sends a block subscription request to the blockchain network. When the target block is approved by the blockchain network consensus, the detection service receives the target block sent by the blockchain network.
其中,区块订阅请求用于向区块链网络订阅新区块事件,新区块事件用于在每当有新的目标区块被共识通过时向目标对象发送该目标区块,区块号区间用于指示检测服务的检测范围,即检测服务接收到的目标区块的区块号均位于区块号区间中,通过向区块链网络发送区块订阅请求,能够使得检测服务与区块链网络之间建立自动的检测连接,使得每当位于区块号区间内的目标区块被区块链网络共识通过时,检测服务可以自动、连续地接收到新的目标区块,避免遗漏目标区块,同时,检测服务无须频繁地向区块链网络请求获取新的目标区块,可以提升检测服务与区块链网络之间的交互效率。Among them, the block subscription request is used to subscribe to new block events from the blockchain network. The new block event is used to send the target block to the target object whenever a new target block is passed by consensus. The block number interval is used to indicate the detection range of the detection service, that is, the block numbers of the target blocks received by the detection service are all within the block number interval. By sending a block subscription request to the blockchain network, an automatic detection connection can be established between the detection service and the blockchain network, so that whenever a target block within the block number interval is passed by the blockchain network consensus, the detection service can automatically and continuously receive the new target block to avoid missing the target block. At the same time, the detection service does not need to frequently request the blockchain network to obtain new target blocks, which can improve the interaction efficiency between the detection service and the blockchain network.
步骤902:当目标区块中的目标交易为链配置类型的交易时,检测服务从目标区块中提取出目标服务器的服务器属性信息,以及区块链网络为目标服务器分配的服务器交易证书,将服务器属性信息和服务器交易证书存储至目标数据库;Step 902: When the target transaction in the target block is a transaction of the chain configuration type, the detection service extracts the server attribute information of the target server and the server transaction certificate assigned to the target server by the blockchain network from the target block, and stores the server attribute information and the server transaction certificate in the target database;
其中,目标区块中的目标交易可以有多种类型,因此,检测服务在接收到目标区块后,会先判断该目标区块中目标交易的类型,不同的目标交易的类型检测服务会执行不同的动作,当目标区块中的目标交易为链配置类型的交易时,表明该目标区块是用于调整区块链配置的,例如可以是在区块链网络中新增区块链节点。新增的区块链节点的服务器属性信息和服务器交易证书会被打包成区块进行共识,因此,检测服务能够从目标区块中提取出目标服务器的服务器属性信息和服务器交易证书。通过从目标区块中提取出目标服务器的服务器属性信息,以及区块链网络为目标服务器分配的服务器交易证书,并将服务器属性信息和服务器交易证书存储至目标数据库,在多个不同的业务提供方参与区块链业务系统的场景下,只要有新的目标服务器加入,其他服务器均可以获取到新加入的目标服务器的服务器属性信息和服务器交易证书,从而达到服务器属性信息和服务器交易证书的共享效果。Among them, the target transaction in the target block can be of multiple types. Therefore, after receiving the target block, the detection service will first determine the type of the target transaction in the target block. The detection service will perform different actions for different target transaction types. When the target transaction in the target block is a chain configuration type transaction, it indicates that the target block is used to adjust the blockchain configuration, for example, it can be a new blockchain node in the blockchain network. The server attribute information and server transaction certificate of the newly added blockchain node will be packaged into a block for consensus. Therefore, the detection service can extract the server attribute information and server transaction certificate of the target server from the target block. By extracting the server attribute information of the target server from the target block, as well as the server transaction certificate assigned to the target server by the blockchain network, and storing the server attribute information and server transaction certificate in the target database, in the scenario where multiple different business providers participate in the blockchain business system, as long as a new target server joins, other servers can obtain the server attribute information and server transaction certificate of the newly added target server, thereby achieving the sharing effect of server attribute information and server transaction certificate.
步骤903:当目标区块中的目标交易不是链配置类型的交易时,检测服务从目标区块中提取出目标交易的目标交易标识,以及目标交易关联的第一交易数据;Step 903: When the target transaction in the target block is not a transaction of the chain configuration type, the detection service extracts the target transaction identifier of the target transaction and the first transaction data associated with the target transaction from the target block;
其中,当目标区块中的目标交易不是链配置类型的交易时,表明目标区块为区块链网络接收到后端服务异步发送的交易请求后将目标交易打包后生成的,该目标交易可以是账户注册、支付等。目标交易标识由区块链网络在接收到交易请求后生成的,用于唯一标识目标交易,第一交易数据为存储在区块链上的交易数据,第一交易数据即链上交易数据,至少包括目标交易被执行后产生的数据,具体地,第一交易数据可以包括基于交易请求得到的需要存储至区块链的交易数据,以及区块链网络在目标交易被执行后额外产生的交易数据,例如,以账户注册请求为例,交易请求中携带有姓名、公钥、住址、其他属性,则后端服务可以基于交易请求生成账户标识,从交易请求中提取需要存储至区块链的交易数据,本例子中为姓名、公钥,此时,需要存储至区块链的交易数据为账户标识、姓名和公钥。而目标交易被执行后,区块链网络会为账户分配一个链上地址,此时,在目标交易被执行后额外产生的交易数据为链上地址,因此,第一交易数据就可以包括账户标识、姓名、公钥和链上地址。Among them, when the target transaction in the target block is not a transaction of the chain configuration type, it indicates that the target block is generated after the blockchain network receives the transaction request sent asynchronously by the backend service and packages the target transaction. The target transaction can be account registration, payment, etc. The target transaction identifier is generated by the blockchain network after receiving the transaction request, and is used to uniquely identify the target transaction. The first transaction data is the transaction data stored on the blockchain. The first transaction data is the on-chain transaction data, which at least includes the data generated after the target transaction is executed. Specifically, the first transaction data may include the transaction data that needs to be stored in the blockchain based on the transaction request, and the transaction data additionally generated by the blockchain network after the target transaction is executed. For example, taking the account registration request as an example, the transaction request carries the name, public key, address, and other attributes. The backend service can generate an account identifier based on the transaction request, and extract the transaction data that needs to be stored in the blockchain from the transaction request. In this example, it is the name and public key. At this time, the transaction data that needs to be stored in the blockchain is the account identifier, name, and public key. After the target transaction is executed, the blockchain network will assign an on-chain address to the account. At this time, the additional transaction data generated after the target transaction is executed is the on-chain address. Therefore, the first transaction data can include the account ID, name, public key and on-chain address.
当目标区块中包括多个目标交易时,检测服务可以遍历目标区块中的多个目标交易,针对每个目标交易进行解析,进而提取出目标交易的目标交易标识,以及目标交易关联的第一交易数据,从而不遗漏每一个目标交易。When the target block includes multiple target transactions, the detection service can traverse the multiple target transactions in the target block, parse each target transaction, and then extract the target transaction identifier of the target transaction and the first transaction data associated with the target transaction, so as not to miss any target transaction.
步骤904:检测服务从目标区块中提取出在对目标交易进行签名时使用的目标交易证书,获取在启动时加载的服务器交易证书,当在启动时加载的服务器交易证书与目标交易证书相一致时,访问存储有第一数据对的缓存服务,根据目标交易标识从缓存服务的第一数据对中获取目标交易关联的第二交易数据;Step 904: the detection service extracts the target transaction certificate used to sign the target transaction from the target block, obtains the server transaction certificate loaded at startup, and when the server transaction certificate loaded at startup is consistent with the target transaction certificate, accesses the cache service storing the first data pair, and obtains the second transaction data associated with the target transaction from the first data pair of the cache service according to the target transaction identifier;
其中,后端服务在发起目标交易的交易请求时会利用自身的目标交易证书对交易请求进行签名,并附上目标交易证书,检测服务在启动时,会加载检测服务所在的目标服务器的服务器交易证书,该服务器交易证书即目标服务器对应的区块链节点在加入区块链网络后,区块链网络为目标服务器分配的证书,由于服务器交易证书具备唯一性,即不同的目标服务器的服务器交易证书不相同,因此,可以通过比较服务器交易证书与目标交易证书是否相一致,来确定目标交易是本地发起的还是异地发起的。Among them, when the back-end service initiates a transaction request for the target transaction, it will use its own target transaction certificate to sign the transaction request and attach the target transaction certificate. When the detection service is started, it will load the server transaction certificate of the target server where the detection service is located. The server transaction certificate is the certificate assigned to the target server by the blockchain network after the blockchain node corresponding to the target server joins the blockchain network. Since the server transaction certificate is unique, that is, the server transaction certificates of different target servers are different, therefore, by comparing whether the server transaction certificate is consistent with the target transaction certificate, it can be determined whether the target transaction is initiated locally or remotely.
当目标交易证书与服务器交易证书相一致时,表明目标交易是本地发起的,再次参照图5所示的例子,此时检测服务可以访问存储有第一数据对的缓存服务,根据目标交易标识从缓存服务的第一数据对中获取目标交易关联的第二交易数据,由于第一数据对基于交易标识和交易数据构建得到,因此通过引入缓存服务,使得在第二交易数据不需要进行上链操作的情况下,也能够根据目标交易标识获取到目标交易关联的第二交易数据,从而在跨服务器共享交易数据的场景下提升交易数据的安全性。When the target transaction certificate is consistent with the server transaction certificate, it indicates that the target transaction is initiated locally. Referring again to the example shown in Figure 5, the detection service can access the cache service that stores the first data pair, and obtain the second transaction data associated with the target transaction from the first data pair of the cache service according to the target transaction identifier. Since the first data pair is constructed based on the transaction identifier and the transaction data, by introducing the cache service, the second transaction data associated with the target transaction can be obtained according to the target transaction identifier without the need for the second transaction data to be uploaded to the chain, thereby improving the security of transaction data in the scenario of sharing transaction data across servers.
步骤905:检测服务将第一交易数据、第二交易数据、服务器属性信息和目标交易证书合并为目标交易数据,将目标交易数据存储至目标数据库;Step 905: The detection service combines the first transaction data, the second transaction data, the server attribute information and the target transaction certificate into target transaction data, and stores the target transaction data in the target database;
其中,通过根据第一交易数据和第二交易数据得到目标交易数据,将目标交易数据存储至目标数据库,使得目标数据库中既可以存储有区块链中的第一交易数据,也可以存储有不在区块链中的第二交易数据,从而在提升交易数据的安全性的基础上,提升本地数据库中的交易数据的完整性。在此基础上,进一步引入服务器属性信息和目标交易证书作为目标交易数据,能够扩充目标交易数据的种类,提升目标交易数据的完整性。Among them, by obtaining the target transaction data according to the first transaction data and the second transaction data, the target transaction data is stored in the target database, so that the target database can store both the first transaction data in the blockchain and the second transaction data not in the blockchain, thereby improving the integrity of the transaction data in the local database on the basis of improving the security of the transaction data. On this basis, further introducing server attribute information and target transaction certificates as target transaction data can expand the types of target transaction data and improve the integrity of the target transaction data.
步骤906:检测服务生成目标交易数据的存储结果信息,基于目标交易标识和存储结果信息构建第二数据对,将第二数据对存储至缓存服务中,并确定目标区块的区块号以及当前的目标交易在目标区块中的交易序号,记录区块号以及交易序号;Step 906: The detection service generates storage result information of the target transaction data, constructs a second data pair based on the target transaction identifier and the storage result information, stores the second data pair in the cache service, determines the block number of the target block and the transaction sequence number of the current target transaction in the target block, and records the block number and the transaction sequence number;
其中,再次参照图6所述的例子,通过将第二数据对存储至缓存服务中,以便后端服务根据目标交易标识从缓存服务的第二数据对中获取目标交易对应的存储结果信息,根据存储结果信息生成用于指示目标交易的交易结果的第一通知消息,将第一通知消息发送至发起目标交易的账户。后端服务具体可以基于预设的时间间隔,持续根据目标交易标识从缓存服务的第二数据对中获取目标交易对应的存储结果信息,当获取到存储结果信息时,根据存储结果信息生成用于指示目标交易的交易结果的第一通知消息,从而达到向发起目标交易的账户便捷地进行通知的效果,提升人机交互效率。Here, referring again to the example described in FIG. 6 , the second data pair is stored in the cache service so that the backend service obtains the storage result information corresponding to the target transaction from the second data pair of the cache service according to the target transaction identifier, generates a first notification message indicating the transaction result of the target transaction according to the storage result information, and sends the first notification message to the account that initiated the target transaction. The backend service can specifically obtain the storage result information corresponding to the target transaction from the second data pair of the cache service according to the target transaction identifier based on a preset time interval, and when the storage result information is obtained, generates a first notification message indicating the transaction result of the target transaction according to the storage result information, thereby achieving the effect of conveniently notifying the account that initiated the target transaction and improving the efficiency of human-computer interaction.
步骤907:当下一个目标交易数据未成功存储至目标数据库时,检测服务基于预设的频率重新启动,在重新启动后,加载记录的区块号以及交易序号,根据区块号以及交易序号确定下一个目标交易,直至区块链网络中所有目标区块中的交易数据存储完毕。Step 907: When the next target transaction data is not successfully stored in the target database, the detection service restarts based on the preset frequency. After restarting, the recorded block number and transaction sequence number are loaded, and the next target transaction is determined based on the block number and transaction sequence number until the transaction data in all target blocks in the blockchain network are stored.
其中,再次参照图7所示的例子,检测服务在将目标交易数据存储至目标数据库时,是会确定目标交易数据是否能够成功存储至目标数据库的,若当前的目标交易数据成功存储至目标数据库,则会记录当前的目标交易数据对应的区块号以及交易序号,再接着处理下一个目标交易数据,而当下一个目标交易数据未成功存储至目标数据库时,检测服务重新启动后,此时并不知道处理到哪一个目标交易,此时,就可以重新加载前面记录的区块号以及交易序号,确定下一个目标交易,不需要从第一个区块的第一个目标交易开始重新处理,减少了冗余的无用操作,显著地提升了交易数据的处理效率,并且,能够提升存储在区块链上的交易数据和存储在目标数据库中的交易数据之间的一致性。另外,检测服务通过定期重启,不断地从上一个目标交易对应的区块号和交易序号开始重新尝试处理,此过程无须人工介入,也可以有效地提升交易数据的处理效率。Among them, referring to the example shown in Figure 7 again, when the detection service stores the target transaction data in the target database, it will determine whether the target transaction data can be successfully stored in the target database. If the current target transaction data is successfully stored in the target database, the block number and transaction sequence number corresponding to the current target transaction data will be recorded, and then the next target transaction data will be processed. When the next target transaction data is not successfully stored in the target database, after the detection service is restarted, it does not know which target transaction is processed. At this time, the block number and transaction sequence number recorded previously can be reloaded to determine the next target transaction. There is no need to reprocess from the first target transaction of the first block, which reduces redundant useless operations, significantly improves the processing efficiency of transaction data, and can improve the consistency between the transaction data stored on the blockchain and the transaction data stored in the target database. In addition, the detection service restarts regularly and continuously tries to process from the block number and transaction sequence number corresponding to the previous target transaction. This process does not require manual intervention and can also effectively improve the processing efficiency of transaction data.
上述步骤901至步骤907,通过引入缓存服务,使得在第二交易数据不需要进行上链操作的情况下,也能够根据目标交易标识获取到目标交易关联的第二交易数据,从而在跨服务器共享交易数据的场景下提升交易数据的安全性,在此基础上,能够根据第一交易数据、第二交易数据、服务器属性信息和目标交易证书得到目标交易数据,将目标交易数据存储至目标数据库,使得目标数据库中能够存储较为完整的交易数据。并且,通过在当目标交易数据已成功存储至目标数据库时,记录目标区块的区块号以及当前的目标交易在目标区块中的交易序号,能够实现交易数据处理的断点重续,提升链上链下的交易数据的一致性。因此,能够同时实现存储交易数据时的互通性、完整性、安全性和一致性。In the above steps 901 to 907, by introducing a cache service, even when the second transaction data does not need to be put on the chain, the second transaction data associated with the target transaction can be obtained according to the target transaction identifier, thereby improving the security of transaction data in the scenario of cross-server sharing of transaction data. On this basis, the target transaction data can be obtained according to the first transaction data, the second transaction data, the server attribute information and the target transaction certificate, and the target transaction data is stored in the target database, so that relatively complete transaction data can be stored in the target database. In addition, by recording the block number of the target block and the transaction sequence number of the current target transaction in the target block when the target transaction data has been successfully stored in the target database, the breakpoint resumption of transaction data processing can be achieved, and the consistency of transaction data on and off the chain can be improved. Therefore, interoperability, integrity, security and consistency when storing transaction data can be achieved at the same time.
另外,参照图10,图10为本申请实施例提供的区块链数据处理方法的另一种可选的流程示意图,该区块链数据处理方法的至少一部分流程可以由服务器执行,或者由终端执行,或者由终端和服务器配合执行,该区块链数据处理方法包括但不限于以下步骤1001至步骤1003。In addition, referring to Figure 10, Figure 10 is another optional flow chart of the blockchain data processing method provided in an embodiment of the present application. At least a part of the process of the blockchain data processing method can be executed by the server, or by the terminal, or by the terminal and the server in cooperation. The blockchain data processing method includes but is not limited to the following steps 1001 to 1003.
步骤1001:向区块链网络异步发送目标交易的交易请求,接收区块链网络返回的目标交易的目标交易标识。Step 1001: asynchronously send a transaction request for a target transaction to the blockchain network, and receive a target transaction identifier of the target transaction returned by the blockchain network.
在一种可能的实现方式中,后端服务可以接收来自终端的交易请求,再根据终端的交易请求生成目标交易的交易请求,例如,以账户注册为例,终端可以向后端服务申请注册一个链上账户,并向后端服务提供姓名、住址等信息,后端服务可以为该终端生成一个唯一的账号标识,此时,需要存储至区块链的数据为姓名、账号标识、公钥等,不存储至区块链的数据为住址。接着后端服务会利用SDK客户端,基于姓名、账号标识、公钥等构造目标交易的元数据,利用所在的目标服务器的私钥进行签名后,生成目标交易的交易请求并发送至区块链网络。In a possible implementation, the backend service can receive a transaction request from a terminal, and then generate a transaction request for the target transaction based on the transaction request from the terminal. For example, taking account registration as an example, the terminal can apply to the backend service to register an on-chain account, and provide the backend service with information such as name and address. The backend service can generate a unique account ID for the terminal. At this time, the data that needs to be stored in the blockchain is the name, account ID, public key, etc., and the data that is not stored in the blockchain is the address. Then the backend service will use the SDK client to construct the metadata of the target transaction based on the name, account ID, public key, etc., and after signing with the private key of the target server, generate a transaction request for the target transaction and send it to the blockchain network.
其中,后端服务是基于异步的方式向区块链网络发送目标交易的交易请求的,意味着SDK客户端不会一直等待目标交易的执行结果,而是接收到区块链网络返回的目标交易标识以后立即进行下一步的处理,相比于采用同步的方式向区块链网络发送交易请求(即向区块链网络发送交易请求后等待交易请求的执行结果才能进行后续的动作),能够显著地提升后端服务与区块链网络之间的交互效率。并且,在此架构下,后端服务也无须接收后续目标区块被共识通过后目标交易的交易结果,有利于降低后端服务的资源占用。Among them, the backend service sends the transaction request of the target transaction to the blockchain network in an asynchronous manner, which means that the SDK client will not wait for the execution result of the target transaction, but will immediately proceed to the next step after receiving the target transaction identifier returned by the blockchain network. Compared with sending transaction requests to the blockchain network in a synchronous manner (i.e., waiting for the execution result of the transaction request after sending the transaction request to the blockchain network before taking subsequent actions), it can significantly improve the interaction efficiency between the backend service and the blockchain network. Moreover, under this architecture, the backend service does not need to receive the transaction result of the target transaction after the subsequent target block is passed by consensus, which is conducive to reducing the resource usage of the backend service.
步骤1002:获取目标交易关联的第二交易数据,根据目标交易标识和第二交易数据构建第一数据对;Step 1002: Acquire second transaction data associated with the target transaction, and construct a first data pair according to the target transaction identifier and the second transaction data;
其中,后端服务在接收到区块链网络返回的目标交易标识以后,可以根据目标交易标识和终端发送的不存储至区块链的数据(即第二交易数据)构建第一数据对,第一数据对用于存储交易标识和交易数据之间的关联关系,第一数据对可以为键值对,相对应地,键值对的键可以基于交易标识构建得到,键值对的值可以基于交易数据构建得到。由于交易数据由后端服务进行管理,因此,第一数据对可以由后端服务进行构建并存储至缓存服务中。Among them, after receiving the target transaction identifier returned by the blockchain network, the backend service can construct a first data pair based on the target transaction identifier and the data sent by the terminal that is not stored in the blockchain (i.e., the second transaction data). The first data pair is used to store the association relationship between the transaction identifier and the transaction data. The first data pair can be a key-value pair. Correspondingly, the key of the key-value pair can be constructed based on the transaction identifier, and the value of the key-value pair can be constructed based on the transaction data. Since the transaction data is managed by the backend service, the first data pair can be constructed by the backend service and stored in the cache service.
步骤1003:将第一数据对存储至缓存服务中,以供检测服务在目标交易对应的目标区块被区块链网络共识通过时,从目标区块中提取出目标交易标识以及目标交易关联的第一交易数据,访问缓存服务,根据目标交易标识从缓存服务的第一数据对中获取第二交易数据,根据第一交易数据和第二交易数据得到目标交易数据,将目标交易数据存储至目标数据库。Step 1003: The first data pair is stored in the cache service so that when the target block corresponding to the target transaction is approved by the blockchain network consensus, the detection service extracts the target transaction identifier and the first transaction data associated with the target transaction from the target block, accesses the cache service, obtains the second transaction data from the first data pair of the cache service according to the target transaction identifier, obtains the target transaction data according to the first transaction data and the second transaction data, and stores the target transaction data in the target database.
其中,后端服务通过将第一数据对存储至缓存服务中,使得当目标区块被区块链网络共识通过时,检测服务可以接收区块链网络发送的目标区块,从目标区块中提取出目标交易关联的第一交易数据,在多个不同的服务器参与区块链业务系统的场景下,不同的服务器均可以同步获取到其他服务器在区块链中的交易数据,从而实现交易数据的跨服务器共享,并且,通过从目标区块中提取出目标交易的目标交易标识,访问存储有第一数据对的缓存服务,根据目标交易标识从缓存服务的第一数据对中获取目标交易关联的第二交易数据,由于第一数据对基于交易标识和交易数据构建得到,因此通过引入缓存服务,使得在第二交易数据不需要进行上链操作的情况下,也能够根据目标交易标识获取到目标交易关联的第二交易数据,从而在跨服务器共享交易数据的场景下提升交易数据的安全性,在此基础上,能够根据第一交易数据和第二交易数据得到目标交易数据,将目标交易数据存储至目标数据库,使得目标数据库中既可以存储有区块链中的第一交易数据,也可以存储有不在区块链中的第二交易数据,从而在提升交易数据的安全性的基础上,提升本地数据库中的交易数据的完整性。Among them, the back-end service stores the first data pair in the cache service, so that when the target block is passed by the blockchain network consensus, the detection service can receive the target block sent by the blockchain network, and extract the first transaction data associated with the target transaction from the target block. In the scenario where multiple different servers participate in the blockchain business system, different servers can synchronously obtain the transaction data of other servers in the blockchain, thereby realizing cross-server sharing of transaction data, and by extracting the target transaction identifier of the target transaction from the target block, accessing the cache service storing the first data pair, and obtaining the second transaction data associated with the target transaction from the first data pair of the cache service according to the target transaction identifier. Since the first The data pair is constructed based on the transaction identifier and the transaction data. Therefore, by introducing the cache service, the second transaction data associated with the target transaction can be obtained according to the target transaction identifier without the need for the second transaction data to be on-chain, thereby improving the security of transaction data in the scenario of sharing transaction data across servers. On this basis, the target transaction data can be obtained according to the first transaction data and the second transaction data, and the target transaction data can be stored in the target database, so that the target database can store both the first transaction data in the blockchain and the second transaction data that is not in the blockchain, thereby improving the integrity of the transaction data in the local database while improving the security of the transaction data.
参见前面的解释,由于缓存服务中还可以存储有由交易标识和存储结果信息构建的第二数据对,相应地,后端服务还可以根据目标交易标识从缓存服务的第二数据对中获取目标交易对应的存储结果信息,根据存储结果信息生成用于指示目标交易的交易结果的第一通知消息,将第一通知消息发送至发起目标交易的账户。Referring to the previous explanation, since the cache service can also store a second data pair constructed by a transaction identifier and storage result information, the back-end service can also obtain the storage result information corresponding to the target transaction from the second data pair of the cache service according to the target transaction identifier, generate a first notification message indicating the transaction result of the target transaction according to the storage result information, and send the first notification message to the account that initiated the target transaction.
例如,第二数据对可以为[txid/resp/TxId1,{“错误信息”:空;“账户信息”:“XXX”}],若区块链网络返回的目标交易标识为TxI d1,则后端服务可以基于该目标交易标识构建键值对的键“txid/resp/TxId1”,从缓存服务中匹配得到存储结果信息{“错误信息”:空;“账户信息”:“XXX”},进而根据存储结果信息生成第一通知消息。在该例子中,可以从账户信息中获取账户标识,基于账户标识生成注册成功的第一通知信息并返回至终端,例如生成的第一通知消息可以为“注册成功,账户标识为XX”。若从缓存服务中匹配得到存储结果信息{“错误信息”:写入失败;“账户信息”:“空”},则生成的第一通知消息可以为“注册失败”。For example, the second data pair may be [txid/resp/TxId1, {"error information": empty; "account information": "XXX"}], if the target transaction identifier returned by the blockchain network is TxI d1, the backend service may construct the key "txid/resp/TxId1" of the key-value pair based on the target transaction identifier, match the storage result information {"error information": empty; "account information": "XXX"} from the cache service, and then generate the first notification message according to the storage result information. In this example, the account identifier may be obtained from the account information, and the first notification message of successful registration may be generated based on the account identifier and returned to the terminal, for example, the generated first notification message may be "registration successful, account identifier is XX". If the storage result information {"error information": write failure; "account information": "empty"} is matched from the cache service, the generated first notification message may be "registration failed".
在一种可能的实现方式中,后端服务在根据目标交易标识从缓存服务的第二数据对中获取目标交易对应的存储结果信息时,具体可以基于预设的时间间隔,持续根据目标交易标识从缓存服务的第二数据对中获取目标交易对应的存储结果信息,当获取到存储结果信息时,根据存储结果信息生成用于指示目标交易的交易结果的第一通知消息。In one possible implementation, when the back-end service obtains the storage result information corresponding to the target transaction from the second data pair of the cache service according to the target transaction identifier, it can specifically continue to obtain the storage result information corresponding to the target transaction from the second data pair of the cache service according to the target transaction identifier based on a preset time interval, and when the storage result information is obtained, generate a first notification message indicating the transaction result of the target transaction according to the storage result information.
其中,预设的时间间隔用于指示后端服务访问缓存服务的频率。预设的时间间隔可以根据实际需求设定,例如可以为50毫秒、60毫秒等等,本申请实施例不做限定。后端服务通过持续访问缓存服务来获取存储结果信息,检测服务和后端服务之间无须进行同步通信,提升检测服务和后端服务之间的交互效率。Among them, the preset time interval is used to indicate the frequency of the backend service accessing the cache service. The preset time interval can be set according to actual needs, for example, it can be 50 milliseconds, 60 milliseconds, etc., which is not limited in the embodiment of the present application. The backend service obtains the storage result information by continuously accessing the cache service, and there is no need for synchronous communication between the detection service and the backend service, thereby improving the interaction efficiency between the detection service and the backend service.
而当请求存储结果信息的持续时长超过预设的时长阈值时,后端服务可以生成用于指示超时的第二通知消息,将第二通知消息发送至发起目标交易的账户。When the duration of requesting to store the result information exceeds a preset duration threshold, the backend service may generate a second notification message indicating a timeout, and send the second notification message to the account that initiated the target transaction.
其中,时长阈值可以根据实际需求设定,例如可以为1秒、1.1秒等等,本申请实施例不做限定。示例性地,第二通知消息可以为“访问超时”、“处理超时”等等。当请求存储结果信息的持续时长超过预设的时长阈值时,后端服务可以通过第二通知消息通知发起目标交易的账户,以提升人机交互的效率。同时,后端服务可以停止访问缓存服务获取该目标交易标识对应的存储结果信息,接着处理下一个目标交易标识,以释放后端服务的处理资源。Among them, the duration threshold can be set according to actual needs, for example, it can be 1 second, 1.1 seconds, etc., and the embodiments of the present application are not limited. Exemplarily, the second notification message can be "access timeout", "processing timeout", etc. When the duration of the request to store the result information exceeds the preset duration threshold, the back-end service can notify the account that initiated the target transaction through the second notification message to improve the efficiency of human-computer interaction. At the same time, the back-end service can stop accessing the cache service to obtain the storage result information corresponding to the target transaction identifier, and then process the next target transaction identifier to release the processing resources of the back-end service.
在一种可能的实现方式中,在多个目标服务器共用一个缓存服务的情况下,后端服务在根据目标交易标识和第二交易数据构建第一数据对时,具体可以对第二交易数据进行加密,得到加密交易数据,将加密交易数据对应的解密信息发送至检测服务,根据目标交易标识和加密交易数据构建第一数据对。In one possible implementation, when multiple target servers share a cache service, when the back-end service constructs a first data pair based on the target transaction identifier and the second transaction data, it can specifically encrypt the second transaction data to obtain encrypted transaction data, send the decryption information corresponding to the encrypted transaction data to the detection service, and construct the first data pair based on the target transaction identifier and the encrypted transaction data.
其中,后端服务在接收到区块链网络返回的目标交易的目标交易标识以后,可以对目标交易中的第二交易数据进行加密,得到加密交易数据,根据目标交易标识和加密交易数据构建第一数据对并存储至缓存服务中。并且,后端服务将加密交易数据对应的解密信息发送至各个目标服务器(包括自身所在的目标服务器)的检测服务,以供各个目标服务器的检测服务在从缓存服务中获取了加密交易数据后,利用解密信息进行解密以还原得到第二交易数据,从而能够有效地提升交易数据的安全性。After receiving the target transaction identifier of the target transaction returned by the blockchain network, the backend service can encrypt the second transaction data in the target transaction to obtain the encrypted transaction data, construct the first data pair according to the target transaction identifier and the encrypted transaction data, and store it in the cache service. In addition, the backend service sends the decryption information corresponding to the encrypted transaction data to the detection service of each target server (including the target server where the backend service is located), so that the detection service of each target server can use the decryption information to decrypt and restore the second transaction data after obtaining the encrypted transaction data from the cache service, thereby effectively improving the security of the transaction data.
下面说明本申请实施例中后端服务的详细处理流程,参照图11,图11为本申请实施例提供的后端服务的一种可选的详细处理流程示意图,具体可以包括以下步骤1101至步骤1105。The following describes the detailed processing flow of the backend service in an embodiment of the present application, with reference to FIG11 . FIG11 is a schematic diagram of an optional detailed processing flow of the backend service provided in an embodiment of the present application, which may specifically include the following steps 1101 to 1105 .
步骤1101:后端服务接收终端发送的交易请求,生成目标交易的交易请求,将目标交易的交易请求基于异步的方式发送至区块链网络;Step 1101: The backend service receives the transaction request sent by the terminal, generates a transaction request for the target transaction, and sends the transaction request for the target transaction to the blockchain network in an asynchronous manner;
其中,终端发送的交易请求可以是账户注册请求、支付请求等,由于检测服务与区块链网络建立了连接,后端服务在向区块链网络发送了交易请求以后,并不需要等待交易请求被打包成目标区块以及目标区块被共识通过,只需要接收区块链网络立即返回的目标交易标识即可,换言之,后端服务可以基于异步的方式向区块链网络发送交易请求,相比于采用同步的方式向区块链网络发送交易请求(即向区块链网络发送交易请求后等待交易请求的执行结果才能进行后续的动作),能够显著地提升后端服务与区块链网络之间的交互效率。并且,在此架构下,后端服务也无须接收后续目标区块被共识通过后目标交易的交易结果,有利于降低后端服务的资源占用。Among them, the transaction request sent by the terminal can be an account registration request, a payment request, etc. Since the detection service has established a connection with the blockchain network, after the back-end service sends the transaction request to the blockchain network, it does not need to wait for the transaction request to be packaged into the target block and the target block to be passed by consensus. It only needs to receive the target transaction identifier returned immediately by the blockchain network. In other words, the back-end service can send a transaction request to the blockchain network based on an asynchronous method. Compared with sending a transaction request to the blockchain network in a synchronous manner (i.e., after sending a transaction request to the blockchain network, waiting for the execution result of the transaction request before performing subsequent actions), it can significantly improve the interaction efficiency between the back-end service and the blockchain network. Moreover, under this architecture, the back-end service does not need to receive the transaction result of the target transaction after the subsequent target block is passed by consensus, which is conducive to reducing the resource occupation of the back-end service.
步骤1102:后端服务接收区块链网络基于交易请求返回的目标交易的目标交易标识,获取不存储至区块链的第二交易数据,根据目标交易标识和第二交易数据构建第一数据对,将第一数据对存储至缓存服务;Step 1102: The backend service receives the target transaction identifier of the target transaction returned by the blockchain network based on the transaction request, obtains the second transaction data that is not stored in the blockchain, constructs a first data pair according to the target transaction identifier and the second transaction data, and stores the first data pair in the cache service;
其中,不存储至区块链的第二交易数据可以存储在后端服务中,例如,后端服务在接收到终端发送的账户注册请求时,可以从账户注册请求中提取出第二交易数据进行缓存,若账户注册请求中携带有姓名、公钥、住址、其他属性,则第二交易数据可以为住址、其他属性。后端服务根据目标交易标识和第二交易数据构建第一数据对,将第一数据对存储至缓存服务,由于后端服务在发起目标交易的交易请求时会利用自身的目标交易证书对交易请求进行签名,并附上目标交易证书,使得检测服务可以在启动时加载检测服务所在的目标服务器的服务器交易证书,通过比较服务器交易证书与目标交易证书是否相一致,来确定目标交易是本地发起的还是异地发起的。当目标交易证书与服务器交易证书相一致时,表明目标交易是本地发起的,再次参照图5所示的例子,此时检测服务可以访问存储有第一数据对的缓存服务,根据目标交易标识从缓存服务的第一数据对中获取目标交易关联的第二交易数据,由于第一数据对基于交易标识和交易数据构建得到,因此通过引入缓存服务,使得在第二交易数据不需要进行上链操作的情况下,也能够根据目标交易标识获取到目标交易关联的第二交易数据,从而在跨服务器共享交易数据的场景下提升交易数据的安全性。Among them, the second transaction data not stored in the blockchain can be stored in the backend service. For example, when the backend service receives the account registration request sent by the terminal, it can extract the second transaction data from the account registration request for caching. If the account registration request carries the name, public key, address, and other attributes, the second transaction data can be the address and other attributes. The backend service constructs a first data pair based on the target transaction identifier and the second transaction data, and stores the first data pair in the cache service. Since the backend service will use its own target transaction certificate to sign the transaction request when initiating the transaction request of the target transaction, and attach the target transaction certificate, the detection service can load the server transaction certificate of the target server where the detection service is located at startup, and determine whether the target transaction is initiated locally or remotely by comparing whether the server transaction certificate is consistent with the target transaction certificate. When the target transaction certificate is consistent with the server transaction certificate, it indicates that the target transaction is initiated locally. Referring again to the example shown in Figure 5, the detection service can access the cache service that stores the first data pair, and obtain the second transaction data associated with the target transaction from the first data pair of the cache service according to the target transaction identifier. Since the first data pair is constructed based on the transaction identifier and the transaction data, by introducing the cache service, the second transaction data associated with the target transaction can be obtained according to the target transaction identifier without the need for the second transaction data to be uploaded to the chain, thereby improving the security of transaction data in the scenario of sharing transaction data across servers.
步骤1103:后端服务基于预设的时间间隔,持续根据目标交易标识从缓存服务的第二数据对中获取目标交易对应的存储结果信息;Step 1103: the backend service continuously obtains storage result information corresponding to the target transaction from the second data pair of the cache service according to the target transaction identifier based on a preset time interval;
其中,再次参照图6,后端服务在将第一数据对存储至缓存服务后,检测服务会在将目标交易数据成功存储至目标数据库后,生成目标交易数据的存储结果信息,基于目标交易标识和存储结果信息构建第二数据对,将第二数据对存储至缓存服务中,此时,后端服务可以根据目标交易标识从缓存服务的第二数据对中获取目标交易对应的存储结果信息,无须与后端服务直接通信。Among them, referring to Figure 6 again, after the backend service stores the first data pair in the cache service, the detection service will generate storage result information of the target transaction data after successfully storing the target transaction data in the target database, and construct a second data pair based on the target transaction identifier and the storage result information, and store the second data pair in the cache service. At this time, the backend service can obtain the storage result information corresponding to the target transaction from the second data pair of the cache service according to the target transaction identifier without directly communicating with the backend service.
步骤1104:当后端服务获取到存储结果信息时,根据存储结果信息生成用于指示目标交易的交易结果的第一通知消息,将第一通知消息发送至终端;Step 1104: when the backend service obtains the storage result information, it generates a first notification message indicating the transaction result of the target transaction according to the storage result information, and sends the first notification message to the terminal;
其中,后端服务具体可以基于预设的时间间隔,持续根据目标交易标识从缓存服务的第二数据对中获取目标交易对应的存储结果信息,当获取到存储结果信息时,根据存储结果信息生成用于指示目标交易的交易结果的第一通知消息,从而达到向发起目标交易的账户便捷地进行通知的效果,提升人机交互效率。Specifically, the back-end service can continuously obtain the storage result information corresponding to the target transaction from the second data pair of the cache service according to the target transaction identifier based on a preset time interval; when the storage result information is obtained, a first notification message indicating the transaction result of the target transaction is generated according to the storage result information, thereby achieving the effect of conveniently notifying the account that initiated the target transaction and improving the efficiency of human-computer interaction.
步骤1105:当后端服务请求存储结果信息的持续时长超过预设的时长阈值时,生成用于指示超时的第二通知消息,将第二通知消息发送至发起目标交易的账户。Step 1105: When the duration of the backend service request to store the result information exceeds a preset duration threshold, a second notification message indicating a timeout is generated, and the second notification message is sent to the account that initiated the target transaction.
其中,当后端服务请求存储结果信息的持续时长超过预设的时长阈值时,表明目标交易数据可能没有成功存储,后端服务可以停止访问缓存服务获取该目标交易标识对应的存储结果信息,接着处理下一个目标交易标识,以释放后端服务的处理资源。并且,由于终端通过第二通知消息获知了这个情况,也可以进行交易请求的重试等操作,提升交易的可靠性。Among them, when the duration of the backend service requesting the storage result information exceeds the preset duration threshold, it indicates that the target transaction data may not be successfully stored, and the backend service can stop accessing the cache service to obtain the storage result information corresponding to the target transaction identifier, and then process the next target transaction identifier to release the processing resources of the backend service. In addition, since the terminal is informed of this situation through the second notification message, it can also perform operations such as retrying the transaction request to improve the reliability of the transaction.
上述步骤1101至步骤1105,通过引入缓存服务,使得在第二交易数据不需要进行上链操作的情况下,也能够根据目标交易标识获取到目标交易关联的第二交易数据,从而在跨服务器共享交易数据的场景下提升交易数据的安全性,在此基础上,能够便于检测服务根据第一交易数据、第二交易数据、服务器属性信息和目标交易证书得到目标交易数据,将目标交易数据存储至目标数据库,使得目标数据库中能够存储较为完整的交易数据。In the above steps 1101 to 1105, by introducing a cache service, it is possible to obtain the second transaction data associated with the target transaction according to the target transaction identifier even when the second transaction data does not need to be uploaded to the chain, thereby improving the security of transaction data in the scenario of sharing transaction data across servers. On this basis, it is convenient for the detection service to obtain the target transaction data according to the first transaction data, the second transaction data, the server attribute information and the target transaction certificate, and store the target transaction data in the target database, so that relatively complete transaction data can be stored in the target database.
下面说明本申请实施例中检测服务和后端服务之间的交互流程,参照图12,图12为本申请实施例提供的检测服务和后端服务的一种可选的交互流程示意图,具体可以包括以下步骤1201至步骤1209。The following describes the interaction process between the detection service and the backend service in an embodiment of the present application, with reference to FIG12 . FIG12 is a schematic diagram of an optional interaction process between the detection service and the backend service provided in an embodiment of the present application, which may specifically include the following steps 1201 to 1209 .
步骤1201:检测服务向区块链网络发送区块订阅请求;Step 1201: The detection service sends a block subscription request to the blockchain network;
其中,区块订阅请求用于向区块链网络订阅新区块事件,新区块事件用于在每当有新的目标区块被共识通过时向目标对象发送该目标区块,区块号区间用于指示检测服务的检测范围,即检测服务接收到的目标区块的区块号均位于区块号区间中,通过向区块链网络发送区块订阅请求,能够使得检测服务与区块链网络之间建立自动的检测连接,使得每当位于区块号区间内的目标区块被区块链网络共识通过时,检测服务可以自动、连续地接收到新的目标区块,避免遗漏目标区块,同时,检测服务无须频繁地向区块链网络请求获取新的目标区块,可以提升检测服务与区块链网络之间的交互效率。Among them, the block subscription request is used to subscribe to new block events from the blockchain network. The new block event is used to send the target block to the target object whenever a new target block is passed by consensus. The block number interval is used to indicate the detection range of the detection service, that is, the block numbers of the target blocks received by the detection service are all within the block number interval. By sending a block subscription request to the blockchain network, an automatic detection connection can be established between the detection service and the blockchain network, so that whenever a target block within the block number interval is passed by the blockchain network consensus, the detection service can automatically and continuously receive the new target block to avoid missing the target block. At the same time, the detection service does not need to frequently request the blockchain network to obtain new target blocks, which can improve the interaction efficiency between the detection service and the blockchain network.
步骤1202:当链配置类型的目标区块被区块链网络共识通过时,检测服务接收区块链网络发送的目标区块,从目标区块中提取出目标服务器的服务器属性信息,以及区块链网络为目标服务器分配的服务器交易证书,将服务器属性信息和服务器交易证书存储至目标数据库;Step 1202: When the target block of the chain configuration type is passed by the blockchain network consensus, the detection service receives the target block sent by the blockchain network, extracts the server attribute information of the target server and the server transaction certificate assigned by the blockchain network to the target server from the target block, and stores the server attribute information and the server transaction certificate in the target database;
其中,由于检测服务是持续向区块链网络订阅目标区块的,因此,检测服务也可以接收到包含链配置类型的目标区块,当然,同一个目标区块中的目标交易可以有多种类型,因此,在步骤1202中,也可以是当包含链配置类型的目标交易的目标区块被区块链网络共识通过,检测服务在接收到目标区块后,会先判断该目标区块中目标交易的类型,不同的目标交易的类型检测服务会执行不同的动作,当目标区块中的目标交易为链配置类型的交易时,表明该目标区块是用于调整区块链配置的,例如可以是在区块链网络中新增区块链节点。新增的区块链节点的服务器属性信息和服务器交易证书会被打包成区块进行共识,因此,检测服务能够从目标区块中提取出目标服务器的服务器属性信息和服务器交易证书。通过从目标区块中提取出目标服务器的服务器属性信息,以及区块链网络为目标服务器分配的服务器交易证书,并将服务器属性信息和服务器交易证书存储至目标数据库,在多个不同的业务提供方参与区块链业务系统的场景下,只要有新的目标服务器加入,其他服务器均可以获取到新加入的目标服务器的服务器属性信息和服务器交易证书,从而达到服务器属性信息和服务器交易证书的共享效果。Among them, since the detection service continuously subscribes to the target block from the blockchain network, the detection service can also receive the target block containing the chain configuration type. Of course, there can be multiple types of target transactions in the same target block. Therefore, in step 1202, it can also be that when the target block containing the target transaction of the chain configuration type is passed by the blockchain network consensus, the detection service will first determine the type of target transaction in the target block after receiving the target block. The detection service will perform different actions for different target transaction types. When the target transaction in the target block is a transaction of the chain configuration type, it indicates that the target block is used to adjust the blockchain configuration, for example, it can be to add a new blockchain node in the blockchain network. The server attribute information and server transaction certificate of the newly added blockchain node will be packaged into a block for consensus. Therefore, the detection service can extract the server attribute information and server transaction certificate of the target server from the target block. By extracting the server attribute information of the target server and the server transaction certificate assigned to the target server by the blockchain network from the target block, and storing the server attribute information and the server transaction certificate in the target database, in the scenario where multiple different business providers participate in the blockchain business system, as long as a new target server joins, other servers can obtain the server attribute information and server transaction certificate of the newly joined target server, thereby achieving the sharing effect of server attribute information and server transaction certificate.
步骤1203:后端服务响应于终端发送的交易请求,生成目标交易的交易请求,将目标交易的交易请求基于异步的方式发送至区块链网络;Step 1203: The backend service generates a transaction request for the target transaction in response to the transaction request sent by the terminal, and sends the transaction request for the target transaction to the blockchain network in an asynchronous manner;
其中,终端发送的交易请求可以是账户注册请求、支付请求等,由于检测服务与区块链网络建立了连接,后端服务在向区块链网络发送了交易请求以后,并不需要等待交易请求被打包成目标区块以及目标区块被共识通过,只需要接收区块链网络立即返回的目标交易标识即可,换言之,后端服务可以基于异步的方式向区块链网络发送交易请求,相比于采用同步的方式向区块链网络发送交易请求(即向区块链网络发送交易请求后等待交易请求的执行结果才能进行后续的动作),能够显著地提升后端服务与区块链网络之间的交互效率。并且,在此架构下,后端服务也无须接收后续目标区块被共识通过后目标交易的交易结果,有利于降低后端服务的资源占用。Among them, the transaction request sent by the terminal can be an account registration request, a payment request, etc. Since the detection service has established a connection with the blockchain network, after the back-end service sends the transaction request to the blockchain network, it does not need to wait for the transaction request to be packaged into the target block and the target block to be passed by consensus. It only needs to receive the target transaction identifier returned immediately by the blockchain network. In other words, the back-end service can send a transaction request to the blockchain network based on an asynchronous method. Compared with sending a transaction request to the blockchain network in a synchronous manner (i.e., after sending a transaction request to the blockchain network, waiting for the execution result of the transaction request before performing subsequent actions), it can significantly improve the interaction efficiency between the back-end service and the blockchain network. Moreover, under this architecture, the back-end service does not need to receive the transaction result of the target transaction after the subsequent target block is passed by consensus, which is conducive to reducing the resource occupation of the back-end service.
步骤1204:后端服务接收区块链网络基于交易请求返回的目标交易的目标交易标识,获取不存储至区块链的第二交易数据,根据目标交易标识和第二交易数据构建第一数据对,将第一数据对存储至缓存服务,基于预设的时间间隔,持续根据目标交易标识从缓存服务的第二数据对中获取目标交易对应的存储结果信息;Step 1204: The backend service receives the target transaction identifier of the target transaction returned by the blockchain network based on the transaction request, obtains the second transaction data that is not stored in the blockchain, constructs a first data pair according to the target transaction identifier and the second transaction data, stores the first data pair in the cache service, and continuously obtains the storage result information corresponding to the target transaction from the second data pair of the cache service according to the target transaction identifier based on a preset time interval;
其中,不存储至区块链的第二交易数据可以存储在后端服务中,例如,后端服务在接收到终端发送的账户注册请求时,可以从账户注册请求中提取出第二交易数据进行缓存,若账户注册请求中携带有姓名、公钥、住址、其他属性,则第二交易数据可以为住址、其他属性。后端服务根据目标交易标识和第二交易数据构建第一数据对,将第一数据对存储至缓存服务,由于后端服务在发起目标交易的交易请求时会利用自身的目标交易证书对交易请求进行签名,并附上目标交易证书,使得检测服务可以在启动时加载检测服务所在的目标服务器的服务器交易证书,通过比较服务器交易证书与目标交易证书是否相一致,来确定目标交易是本地发起的还是异地发起的。当目标交易证书与服务器交易证书相一致时,表明目标交易是本地发起的,再次参照图5所示的例子,此时检测服务可以访问存储有第一数据对的缓存服务,根据目标交易标识从缓存服务的第一数据对中获取目标交易关联的第二交易数据,由于第一数据对基于交易标识和交易数据构建得到,因此通过引入缓存服务,使得在第二交易数据不需要进行上链操作的情况下,也能够根据目标交易标识获取到目标交易关联的第二交易数据,从而在跨服务器共享交易数据的场景下提升交易数据的安全性。Among them, the second transaction data not stored in the blockchain can be stored in the backend service. For example, when the backend service receives the account registration request sent by the terminal, it can extract the second transaction data from the account registration request for caching. If the account registration request carries the name, public key, address, and other attributes, the second transaction data can be the address and other attributes. The backend service constructs a first data pair based on the target transaction identifier and the second transaction data, and stores the first data pair in the cache service. Since the backend service will use its own target transaction certificate to sign the transaction request when initiating the transaction request of the target transaction, and attach the target transaction certificate, the detection service can load the server transaction certificate of the target server where the detection service is located at startup, and determine whether the target transaction is initiated locally or remotely by comparing whether the server transaction certificate is consistent with the target transaction certificate. When the target transaction certificate is consistent with the server transaction certificate, it indicates that the target transaction is initiated locally. Referring again to the example shown in Figure 5, the detection service can access the cache service that stores the first data pair, and obtain the second transaction data associated with the target transaction from the first data pair of the cache service according to the target transaction identifier. Since the first data pair is constructed based on the transaction identifier and the transaction data, by introducing the cache service, the second transaction data associated with the target transaction can be obtained according to the target transaction identifier without the need for the second transaction data to be uploaded to the chain, thereby improving the security of transaction data in the scenario of sharing transaction data across servers.
再次参照图6,后端服务在将第一数据对存储至缓存服务后,检测服务会在将目标交易数据成功存储至目标数据库后,生成目标交易数据的存储结果信息,基于目标交易标识和存储结果信息构建第二数据对,将第二数据对存储至缓存服务中,此时,后端服务可以根据目标交易标识从缓存服务的第二数据对中获取目标交易对应的存储结果信息,无须与后端服务直接通信。Referring to Figure 6 again, after the backend service stores the first data pair in the cache service, the detection service will generate storage result information of the target transaction data after successfully storing the target transaction data in the target database, construct a second data pair based on the target transaction identifier and the storage result information, and store the second data pair in the cache service. At this time, the backend service can obtain the storage result information corresponding to the target transaction from the second data pair of the cache service according to the target transaction identifier without directly communicating with the backend service.
步骤1205:当目标交易对应的目标区块被区块链网络共识通过时,检测服务接收区块链网络发送的目标区块,检测服务从目标区块中提取出目标交易的目标交易标识,以及目标交易关联的第一交易数据;Step 1205: When the target block corresponding to the target transaction is approved by the blockchain network consensus, the detection service receives the target block sent by the blockchain network, and the detection service extracts the target transaction identifier of the target transaction and the first transaction data associated with the target transaction from the target block;
其中,在步骤1205中,目标交易不是链配置类型的交易,表明目标区块为区块链网络接收到后端服务异步发送的交易请求后将目标交易打包后生成的,该目标交易可以是账户注册、支付等。目标交易标识由区块链网络在接收到交易请求后生成的,用于唯一标识目标交易,第一交易数据为存储在区块链上的交易数据,第一交易数据即链上交易数据,至少包括目标交易被执行后产生的数据,具体地,第一交易数据可以包括基于交易请求得到的需要存储至区块链的交易数据,以及区块链网络在目标交易被执行后额外产生的交易数据,例如,以账户注册请求为例,交易请求中携带有姓名、公钥、住址、其他属性,则后端服务可以基于交易请求生成账户标识,从交易请求中提取需要存储至区块链的交易数据,本例子中为姓名、公钥,此时,需要存储至区块链的交易数据为账户标识、姓名和公钥。而目标交易被执行后,区块链网络会为账户分配一个链上地址,此时,在目标交易被执行后额外产生的交易数据为链上地址,因此,第一交易数据就可以包括账户标识、姓名、公钥和链上地址。Among them, in step 1205, the target transaction is not a transaction of the chain configuration type, indicating that the target block is generated after the blockchain network receives the transaction request sent asynchronously by the backend service and packages the target transaction. The target transaction can be account registration, payment, etc. The target transaction identifier is generated by the blockchain network after receiving the transaction request, and is used to uniquely identify the target transaction. The first transaction data is the transaction data stored on the blockchain. The first transaction data is the on-chain transaction data, which at least includes the data generated after the target transaction is executed. Specifically, the first transaction data may include the transaction data that needs to be stored in the blockchain based on the transaction request, and the transaction data additionally generated by the blockchain network after the target transaction is executed. For example, taking the account registration request as an example, the transaction request carries the name, public key, address, and other attributes. The backend service can generate an account identifier based on the transaction request, and extract the transaction data that needs to be stored in the blockchain from the transaction request. In this example, it is the name and public key. At this time, the transaction data that needs to be stored in the blockchain is the account identifier, name, and public key. After the target transaction is executed, the blockchain network will assign an on-chain address to the account. At this time, the additional transaction data generated after the target transaction is executed is the on-chain address. Therefore, the first transaction data can include the account ID, name, public key and on-chain address.
当目标区块中包括多个目标交易时,检测服务可以遍历目标区块中的多个目标交易,针对每个目标交易进行解析,进而提取出目标交易的目标交易标识,以及目标交易关联的第一交易数据,从而不遗漏每一个目标交易。When the target block includes multiple target transactions, the detection service can traverse the multiple target transactions in the target block, parse each target transaction, and then extract the target transaction identifier of the target transaction and the first transaction data associated with the target transaction, so as not to miss any target transaction.
步骤1206:检测服务从目标区块中提取出在对目标交易进行签名时使用的目标交易证书,获取在启动时加载的服务器交易证书,当在启动时加载的服务器交易证书与目标交易证书相一致时,访问存储有第一数据对的缓存服务,根据目标交易标识从缓存服务的第一数据对中获取目标交易关联的第二交易数据;Step 1206: the detection service extracts the target transaction certificate used to sign the target transaction from the target block, obtains the server transaction certificate loaded at startup, and when the server transaction certificate loaded at startup is consistent with the target transaction certificate, accesses the cache service storing the first data pair, and obtains the second transaction data associated with the target transaction from the first data pair of the cache service according to the target transaction identifier;
其中,后端服务在发起目标交易的交易请求时会利用自身的目标交易证书对交易请求进行签名,并附上目标交易证书,检测服务在启动时,会加载检测服务所在的目标服务器的服务器交易证书,该服务器交易证书即目标服务器对应的区块链节点在加入区块链网络后,区块链网络为目标服务器分配的证书,由于服务器交易证书具备唯一性,即不同的目标服务器的服务器交易证书不相同,因此,可以通过比较服务器交易证书与目标交易证书是否相一致,来确定目标交易是本地发起的还是异地发起的。Among them, when the back-end service initiates a transaction request for the target transaction, it will use its own target transaction certificate to sign the transaction request and attach the target transaction certificate. When the detection service is started, it will load the server transaction certificate of the target server where the detection service is located. The server transaction certificate is the certificate assigned to the target server by the blockchain network after the blockchain node corresponding to the target server joins the blockchain network. Since the server transaction certificate is unique, that is, the server transaction certificates of different target servers are different, therefore, by comparing whether the server transaction certificate is consistent with the target transaction certificate, it can be determined whether the target transaction is initiated locally or remotely.
当目标交易证书与服务器交易证书相一致时,表明目标交易是本地发起的,再次参照图5所示的例子,此时检测服务可以访问存储有第一数据对的缓存服务,根据目标交易标识从缓存服务的第一数据对中获取目标交易关联的第二交易数据,由于第一数据对基于交易标识和交易数据构建得到,因此通过引入缓存服务,使得在第二交易数据不需要进行上链操作的情况下,也能够根据目标交易标识获取到目标交易关联的第二交易数据,从而在跨服务器共享交易数据的场景下提升交易数据的安全性。When the target transaction certificate is consistent with the server transaction certificate, it indicates that the target transaction is initiated locally. Referring again to the example shown in Figure 5, the detection service can access the cache service that stores the first data pair, and obtain the second transaction data associated with the target transaction from the first data pair of the cache service according to the target transaction identifier. Since the first data pair is constructed based on the transaction identifier and the transaction data, by introducing the cache service, the second transaction data associated with the target transaction can be obtained according to the target transaction identifier without the need for the second transaction data to be uploaded to the chain, thereby improving the security of transaction data in the scenario of sharing transaction data across servers.
步骤1207:检测服务将第一交易数据、第二交易数据、服务器属性信息和目标交易证书合并为目标交易数据,将目标交易数据存储至目标数据库;Step 1207: The detection service combines the first transaction data, the second transaction data, the server attribute information and the target transaction certificate into target transaction data, and stores the target transaction data in the target database;
其中,通过根据第一交易数据和第二交易数据得到目标交易数据,将目标交易数据存储至目标数据库,使得目标数据库中既可以存储有区块链中的第一交易数据,也可以存储有不在区块链中的第二交易数据,从而在提升交易数据的安全性的基础上,提升本地数据库中的交易数据的完整性。在此基础上,进一步引入服务器属性信息和目标交易证书作为目标交易数据,能够扩充目标交易数据的种类,提升目标交易数据的完整性。Among them, by obtaining the target transaction data according to the first transaction data and the second transaction data, the target transaction data is stored in the target database, so that the target database can store both the first transaction data in the blockchain and the second transaction data not in the blockchain, thereby improving the integrity of the transaction data in the local database on the basis of improving the security of the transaction data. On this basis, further introducing server attribute information and target transaction certificates as target transaction data can expand the types of target transaction data and improve the integrity of the target transaction data.
步骤1208:当目标交易数据未成功存储至目标数据库时,检测服务加载上一个目标交易对应的区块号和交易序号,从上一个目标交易对应的区块号和交易序号开始重新尝试处理,直至成功将目标交易数据存储至目标数据库中,更新区块号和交易序号的记录,生成目标交易数据的存储结果信息,基于目标交易标识和存储结果信息构建第二数据对,将第二数据对存储至缓存服务中;Step 1208: When the target transaction data is not successfully stored in the target database, the detection service loads the block number and transaction sequence number corresponding to the previous target transaction, and tries to process again from the block number and transaction sequence number corresponding to the previous target transaction until the target transaction data is successfully stored in the target database, updates the record of the block number and transaction sequence number, generates storage result information of the target transaction data, constructs a second data pair based on the target transaction identifier and the storage result information, and stores the second data pair in the cache service;
其中,与步骤907原理相类似,再次参照图7所示的例子,检测服务在将目标交易数据存储至目标数据库时,是会确定目标交易数据是否能够成功存储至目标数据库的,若当前的目标交易数据成功存储至目标数据库,则会记录当前的目标交易数据对应的区块号以及交易序号,再接着处理下一个目标交易数据,因此,若当前的目标交易数据未成功存储至目标数据库时,检测服务重新启动后,此时并不知道处理到哪一个目标交易,此时,就可以重新加载上一个目标交易记录的区块号以及交易序号,进而确定当前目标交易,不需要从第一个区块的第一个目标交易开始重新处理,减少了冗余的无用操作,显著地提升了交易数据的处理效率,并且,能够提升存储在区块链上的交易数据和存储在目标数据库中的交易数据之间的一致性。另外,检测服务通过定期重启,不断地从上一个目标交易对应的区块号和交易序号开始重新尝试处理,此过程无须人工介入,也可以有效地提升交易数据的处理效率。Among them, similar to the principle of step 907, referring to the example shown in Figure 7 again, when the detection service stores the target transaction data in the target database, it will determine whether the target transaction data can be successfully stored in the target database. If the current target transaction data is successfully stored in the target database, the block number and transaction sequence number corresponding to the current target transaction data will be recorded, and then the next target transaction data will be processed. Therefore, if the current target transaction data is not successfully stored in the target database, after the detection service is restarted, it is not known which target transaction is processed at this time. At this time, the block number and transaction sequence number of the previous target transaction record can be reloaded to determine the current target transaction. There is no need to reprocess from the first target transaction of the first block, which reduces redundant useless operations, significantly improves the processing efficiency of transaction data, and can improve the consistency between the transaction data stored on the blockchain and the transaction data stored in the target database. In addition, the detection service restarts regularly and continuously tries to process from the block number and transaction sequence number corresponding to the previous target transaction. This process does not require manual intervention and can also effectively improve the processing efficiency of transaction data.
其中,再次参照图6所述的例子,通过将第二数据对存储至缓存服务中,以便后端服务根据目标交易标识从缓存服务的第二数据对中获取目标交易对应的存储结果信息,根据存储结果信息生成用于指示目标交易的交易结果的第一通知消息,将第一通知消息发送至发起目标交易的账户。后端服务具体可以基于预设的时间间隔,持续根据目标交易标识从缓存服务的第二数据对中获取目标交易对应的存储结果信息,当获取到存储结果信息时,根据存储结果信息生成用于指示目标交易的交易结果的第一通知消息,从而达到向发起目标交易的账户便捷地进行通知的效果,提升人机交互效率。Here, referring again to the example described in FIG. 6 , the second data pair is stored in the cache service so that the backend service obtains the storage result information corresponding to the target transaction from the second data pair of the cache service according to the target transaction identifier, generates a first notification message indicating the transaction result of the target transaction according to the storage result information, and sends the first notification message to the account that initiated the target transaction. The backend service can specifically obtain the storage result information corresponding to the target transaction from the second data pair of the cache service according to the target transaction identifier based on a preset time interval, and when the storage result information is obtained, generates a first notification message indicating the transaction result of the target transaction according to the storage result information, thereby achieving the effect of conveniently notifying the account that initiated the target transaction and improving the efficiency of human-computer interaction.
步骤1209:后端服务根据目标交易标识从缓存服务的第二数据对中获取到目标交易对应的存储结果信息,根据存储结果信息生成用于指示目标交易的交易结果的第一通知消息,将第一通知消息发送至终端。Step 1209: the backend service obtains the storage result information corresponding to the target transaction from the second data pair of the cache service according to the target transaction identifier, generates a first notification message indicating the transaction result of the target transaction according to the storage result information, and sends the first notification message to the terminal.
其中,后端服务具体可以基于预设的时间间隔,持续根据目标交易标识从缓存服务的第二数据对中获取目标交易对应的存储结果信息,当获取到存储结果信息时,根据存储结果信息生成用于指示目标交易的交易结果的第一通知消息,从而达到向发起目标交易的账户便捷地进行通知的效果,提升人机交互效率。Specifically, the back-end service can continuously obtain the storage result information corresponding to the target transaction from the second data pair of the cache service according to the target transaction identifier based on a preset time interval; when the storage result information is obtained, a first notification message indicating the transaction result of the target transaction is generated according to the storage result information, thereby achieving the effect of conveniently notifying the account that initiated the target transaction and improving the efficiency of human-computer interaction.
上述步骤1201至步骤1209,通过引入缓存服务,使得在第二交易数据不需要进行上链操作的情况下,也能够根据目标交易标识获取到目标交易关联的第二交易数据,从而在跨服务器共享交易数据的场景下提升交易数据的安全性,在此基础上,能够根据第一交易数据、第二交易数据、服务器属性信息和目标交易证书得到目标交易数据,将目标交易数据存储至目标数据库,使得目标数据库中能够存储较为完整的交易数据。并且,通过在当目标交易数据已成功存储至目标数据库时,记录目标区块的区块号以及当前的目标交易在目标区块中的交易序号,能够实现交易数据处理的断点重续,提升链上链下的交易数据的一致性。因此,能够同时实现存储交易数据时的互通性、完整性、安全性和一致性。In the above steps 1201 to 1209, by introducing a cache service, even when the second transaction data does not need to be put on the chain, the second transaction data associated with the target transaction can be obtained according to the target transaction identifier, thereby improving the security of transaction data in the scenario of cross-server sharing of transaction data. On this basis, the target transaction data can be obtained according to the first transaction data, the second transaction data, the server attribute information and the target transaction certificate, and the target transaction data is stored in the target database, so that relatively complete transaction data can be stored in the target database. In addition, by recording the block number of the target block and the transaction sequence number of the current target transaction in the target block when the target transaction data has been successfully stored in the target database, the breakpoint resumption of transaction data processing can be achieved, and the consistency of transaction data on and off the chain can be improved. Therefore, interoperability, integrity, security and consistency when storing transaction data can be achieved at the same time.
下面以账号注册作为例子说明本申请实施例提供的区块链数据处理方法的原理。The following uses account registration as an example to illustrate the principle of the blockchain data processing method provided in the embodiment of the present application.
参照图13,图13为本申请实施例提供的区块链数据处理方法的一种可选的总体交互流程示意图,在本例子中,业务提供方B的目标服务器(对应地域B)和业务提供方G的目标服务器(对应地域G)均部署有后端服务、检测服务、目标数据库和缓存服务,在业务提供方B的目标服务器和业务提供方G的目标服务器加入到网络时,所有服务均会被启动,检测器以区块0和交易0开始检测:Referring to FIG. 13 , FIG. 13 is a schematic diagram of an optional overall interaction flow of the blockchain data processing method provided in an embodiment of the present application. In this example, the target server of business provider B (corresponding to region B) and the target server of business provider G (corresponding to region G) are both deployed with backend services, detection services, target databases, and cache services. When the target servers of business provider B and business provider G are added to the network, all services will be started, and the detector starts detection with block 0 and transaction 0:
(1)加入区块链网络,分配证书:假设业务提供方G的目标服务器加入区块链网络,区块链网络会给业务提供方G的目标服务器分配一个证书Cert-G和私钥Key-G(用于后续签名发起交易),同时将Cert-G和业务提供方G的目标服务器的UNI-G、APPID-G进行上链;类似地,当业务提供方B的目标服务器加入到区块链网络时,也会被分配一个证书Cert-B,且业务提供方B的目标服务器的Cert-B以及UNI-B、APPID-B也会被以类似的形式上链。在[UNI-G、APPID-G、Cert-G]上链后(即对应的目标区块被共识通过),业务提供方G的目标服务器中的检测服务能够通过区块链网络的新区块事件订阅获取到对应的目标区块,在相应的交易中获取到[UNI-G、APPID-G、Cert-G]写入到本地的目标数据库的数据表Tablecert中,同理,业务提供方G的目标服务器中的检测服务也能够将[UNI-B、APPID-B、Cert-B]写入到本地的目标数据库的数据表Tablecert中。而业务提供方B的目标服务器中的检测服务在业务提供方B的目标服务器加入到网络时,开始启动,以(区块0和交易0)为记号开始检测,同样能够检测到上述交易,因此也会把[UNI-G、APPID-G、Cert-G]和[UNI-B、APPID-B、Cert-B]插入到本地的目标数据库的数据表Tablecert中,至此,业务提供方B的目标服务器和业务提供方G的目标服务器本地的目标数据库的数据表Tablecert中均有完整的业务方信息:(1) Joining the blockchain network and allocating certificates: Assuming that the target server of service provider G joins the blockchain network, the blockchain network will allocate a certificate Cert-G and a private key Key-G (for subsequent signature initiation transactions) to the target server of service provider G, and at the same time upload Cert-G and the UNI-G and APPID-G of the target server of service provider G to the blockchain; similarly, when the target server of service provider B joins the blockchain network, it will also be allocated a certificate Cert-B, and the Cert-B, UNI-B, and APPID-B of the target server of service provider B will also be uploaded to the blockchain in a similar manner. After [UNI-G, APPID-G, Cert-G] is uploaded to the chain (that is, the corresponding target block is approved by consensus), the detection service in the target server of business provider G can obtain the corresponding target block through the new block event subscription of the blockchain network, and obtain [UNI-G, APPID-G, Cert-G] in the corresponding transaction and write it to the data table Table cert of the local target database. Similarly, the detection service in the target server of business provider G can also write [UNI-B, APPID-B, Cert-B] to the data table Table cert of the local target database. The detection service in the target server of business provider B starts when the target server of business provider B joins the network, and starts detection with (block 0 and transaction 0) as the mark. It can also detect the above transactions, so it will also insert [UNI-G, APPID-G, Cert-G] and [UNI-B, APPID-B, Cert-B] into the data table Table cert of the local target database. So far, the data table Table cert of the local target database of the target server of business provider B and the target server of business provider G both have complete business party information:
[UNI-G、APPID-G、证书G][UNI-G, APPID-G, Certificate G]
[UNI-B、APPID-B、证书B][UNI-B, APPID-B, Certificate B]
同时,只要有新的业务提供方的目标服务器加入,当前网络中各个业务提供方的目标服务器中的检测服务均能检测到这类链配置交易,将业务方信息更新到本地的目标数据库的数据表Tablecert中。At the same time, as long as a new service provider's target server is added, the detection service in the target server of each service provider in the current network can detect this type of chain configuration transaction and update the service provider information to the data table Table cert of the local target database.
(2)终端发起请求:终端UE1向业务提供方G的目标服务器中的后端服务发起账户注册请求,申请注册一个链上账户,提供的信息包括(姓名、公钥、住址、其他属性等),后端服务会先利用一定策略生成唯一的账户标识,结合后续从终端UE1提供的信息中提取一些关键或者重要的属性,例如姓名、公钥,将账户标识、姓名和公钥进行上链。(2) Terminal initiates request: Terminal UE1 initiates an account registration request to the backend service in the target server of service provider G, applying to register an on-chain account. The information provided includes (name, public key, address, other attributes, etc.). The backend service will first use a certain strategy to generate a unique account identifier, and then extract some key or important attributes such as name and public key from the information provided by terminal UE1, and upload the account identifier, name and public key to the chain.
(3)后端服务异步发起交易请求:业务提供方G的目标服务器中的后端服务,会利用业务提供方G的目标服务器本地存储的证书Cert-G和区块链网络分配的私钥Key-G,使用相应的SDK客户端,利用账户标识、姓名和公钥先构造交易元数据,后用私钥Key-G进行签名,最后附上证书Cert-G生成目标交易的交易请求,将交易请求以异步的方式发送到业务提供方G对应的区块链节点中,异步的方式意味着SDK客户端不会一直等待目标交易的执行结果,而是接收区块链节点返回的目标交易标识TxId。(3) The backend service asynchronously initiates a transaction request: The backend service in the target server of the service provider G uses the certificate Cert-G stored locally on the target server of the service provider G and the private key Key-G assigned by the blockchain network, and uses the corresponding SDK client to construct the transaction metadata using the account ID, name, and public key, then signs it with the private key Key-G, and finally attaches the certificate Cert-G to generate a transaction request for the target transaction. The transaction request is sent asynchronously to the blockchain node corresponding to the service provider G. The asynchronous method means that the SDK client will not wait for the execution result of the target transaction, but will receive the target transaction identifier TxId returned by the blockchain node.
可以理解的是,如果是终端UE2向业务提供方B的目标服务器中的后端服务发起请求,再构造交易请求时,则使用业务提供方B的目标服务器本地存储的证书Cert-B和区块链网络分配的私钥Key-B。It can be understood that if the terminal UE2 initiates a request to the backend service in the target server of the service provider B, when constructing the transaction request, the certificate Cert-B stored locally in the target server of the service provider B and the private key Key-B assigned by the blockchain network are used.
(4)后端服务向缓存服务设置键值对并等待:业务提供方G的目标服务器中的后端服务,从SDK客户端拿到TxId后,会将不上链的信息构造成一个JSON字符串,作为这次交易请求的上下文Context,如下所示:(4) The backend service sets the key-value pair to the cache service and waits: After the backend service in the target server of the service provider G obtains the TxId from the SDK client, it constructs the information that is not on the chain into a JSON string as the context of this transaction request, as shown below:
Context={"address":"住址","other":"其他属性"}Context={"address":"address","other":"other attributes"}
之后,以"txid/req/TxId"作为完整的Key(键),Context为Value(值),插入到缓存服务中,例如可以用缓存服务提供的Set接口,为了防止缓存服务数据膨胀,数据时效可以设置为1小时或者更短,即:After that, insert it into the cache service with "txid/req/TxId" as the complete Key and Context as the Value. For example, you can use the Set interface provided by the cache service. To prevent the cache service data from expanding, the data validity period can be set to 1 hour or shorter, that is:
Set(txid/req/TxId,Context,1hour)Set(txid/req/TxId,Context,1hour)
之后,后端服务会进入等待阶段,等待检测服务的通知;后端服务会不断以"txid/resp/TxId"为完成的key,调用缓存服务的Get接口,获取对应的Value,获取检测服务放置进缓存服务的返回值Resp;After that, the backend service will enter the waiting stage, waiting for the notification of the detection service; the backend service will continue to call the Get interface of the cache service with "txid/resp/TxId" as the completion key, obtain the corresponding Value, and obtain the return value Resp placed in the cache service by the detection service;
Resp=Get(txid/resp/TxId)Resp=Get(txid/resp/TxId)
后端服务会以一定时间间隔(例如50毫秒)向缓存服务获取对应key的值,直到获取到,或者达到设置的时长阈值(例如1秒),若获取得到,则会对Resp进一步处理;若超时,则直接向终端UE1发送错误消息。The backend service will obtain the value of the corresponding key from the cache service at a certain time interval (for example, 50 milliseconds) until it is obtained or the set time threshold (for example, 1 second) is reached. If it is obtained, Resp will be further processed; if it times out, an error message will be directly sent to the terminal UE1.
(5)共识:业务提供方G对应的区块链节点会对目标交易进行打包,构造一个新的目标区块并执行其中的目标交易,最后在多方节点(业务提供方G对应的区块链节点和业务提供方B对应的区块链节点)对目标区块达成共识后,目标区块会被落盘,即存储至区块链上,即业务提供方G对应的区块链节点和业务提供方B对应的区块链节点,均能够获取该新目标区块,并通知到各自对应的检测服务。(5) Consensus: The blockchain node corresponding to business provider G will package the target transaction, construct a new target block and execute the target transaction therein. Finally, after multiple nodes (the blockchain node corresponding to business provider G and the blockchain node corresponding to business provider B) reach a consensus on the target block, the target block will be written to the disk, that is, stored on the blockchain. That is, the blockchain node corresponding to business provider G and the blockchain node corresponding to business provider B can both obtain the new target block and notify their respective detection services.
(6)检测服务处理目标区块和目标交易:每当区块链节点有新的目标区块诞生时,订阅区块链节点的新区块事件的检测服务会接收到该目标区块,当检测服务接收到新的目标区块时,检测服务会遍历该目标区块中的每一笔目标交易,首先从目标交易中获取证书T,根据证书T比对查询目标数据库的数据表Tablecert,获取业务方信息,例如获取到:(6) The detection service processes the target block and target transaction: Whenever a new target block is generated by a blockchain node, the detection service that subscribes to the new block event of the blockchain node will receive the target block. When the detection service receives the new target block, it will traverse each target transaction in the target block. First, it will obtain the certificate T from the target transaction, and then query the data table Table cert of the target database based on the certificate T to obtain the business party information. For example, it will obtain:
[UNI-G、APPID-G、证书G][UNI-G, APPID-G, Certificate G]
则可以确定该终端是与哪个目标服务器通信的,并能够获取到对应的目标服务器的业务方信息;同时,将证书T与本地存储的证书进行比较,如果一致,则代表这笔交易为本业务方发起的,如果不一致,则为其他业务方发起的。It can then be determined which target server the terminal is communicating with, and the business party information of the corresponding target server can be obtained; at the same time, the certificate T is compared with the locally stored certificate. If they are consistent, it means that the transaction was initiated by this business party. If they are inconsistent, it means that it was initiated by other business parties.
具体来说,以步骤(3)终端UE1向业务提供方G的目标服务器中的后端服务发起请求,并发起目标交易为例:Specifically, take step (3) where the terminal UE1 initiates a request to the backend service in the target server of the service provider G and initiates a target transaction as an example:
一种情况是,业务提供方G的目标服务器中的后端服务会认为这笔目标交易是本地发起的,因此会解析目标区块获得链上的交易数据,即(账户标识、姓名、公钥和链上地址),同时,以txid/req/TxId作为完整的key,调用缓存服务的Get接口,获取后端服务以同样的key存储到缓存服务的Value:In one case, the backend service in the target server of business provider G will think that the target transaction is initiated locally, so it will parse the target block to obtain the transaction data on the chain, that is, (account ID, name, public key and address on the chain), and at the same time, use txid/req/TxId as the complete key to call the Get interface of the cache service to obtain the Value stored in the cache service by the backend service with the same key:
Context=Get("txid/req/TxId")={"address":"住址","others":"其他属性"}Context=Get("txid/req/TxId")={"address":"address","others":"other attributes"}
之后,利用Context和获取到的[UNI-G、APPID-G],和链上的交易数据合并为完整的目标交易数据,并存储至目标数据库中,其中加入[UNI-G、APPID-G]有助于后续从服务器维度进行数据统计。Afterwards, the Context and the obtained [UNI-G, APPID-G] are combined with the transaction data on the chain to form the complete target transaction data and stored in the target database. The addition of [UNI-G, APPID-G] will help with subsequent data statistics from the server dimension.
目标交易数据可以表示为:The target transaction data can be expressed as:
Info-G=(账户标识、姓名、公钥、链上地址、住址、其他属性、UNI-G、APPID-G)Info-G = (account ID, name, public key, on-chain address, address, other attributes, UNI-G, APPID-G)
其中,只有当目标交易数据写入成功后,中间不会出现任何错误,业务提供方G的目标服务器中的检测服务才会将当前(区块号BN,交易号TN)更新到目标数据库中,以表示当前检测服务成功处理到哪些目标交易;当由于意外崩溃,例如数据库不可用,则检测服务在重启的时候会从区块号BN开始检测,并从目标区块BN的第TN笔目标交易开始处理,因此,可以确保链上交易数据可以完整的同步到目标数据库中,避免数据丢失。Among them, only when the target transaction data is written successfully without any errors in the middle, the detection service in the target server of the service provider G will update the current (block number BN, transaction number TN) to the target database to indicate which target transactions the current detection service has successfully processed; when due to an unexpected crash, such as database unavailability, the detection service will start detection from block number BN when it restarts, and start processing from the TNth target transaction of the target block BN. Therefore, it can ensure that the on-chain transaction data can be fully synchronized to the target database to avoid data loss.
最后,业务提供方G的目标服务器中的检测服务会调用缓存服务的Set接口,以"txid/resp/TxId"为完整的key,将以下存储状态信息Resp写入到缓存服务中,以便通知业务提供方G的目标服务器中的后端服务:Finally, the detection service in the target server of service provider G calls the Set interface of the cache service, uses "txid/resp/TxId" as the complete key, and writes the following storage status information Resp to the cache service to notify the backend service in the target server of service provider G:
Set("txid/resp/TxId",Resp,1hour)Set("txid/resp/TxId",Resp,1hour)
Resp={"error":"错误信息","user":"目标交易数据"}Resp={"error":"error information","user":"target transaction data"}
另一种情况是,业务提供方B的目标服务器中的检测服务会认为这笔目标交易不是本地发起的,因此会解析交易获得链上数据,即(账户标识、姓名、公钥和链上地址),结合从目标数据库中匹配获取到的[UNI-G、APPID-G],合并为完整的目标交易数据,并存储至目标数据库中:In another case, the detection service in the target server of business provider B will think that the target transaction is not initiated locally, so it will parse the transaction to obtain the on-chain data, namely (account ID, name, public key and on-chain address), and combine it with the [UNI-G, APPID-G] obtained from the target database to merge into the complete target transaction data and store it in the target database:
Info-B=(账户标识、姓名、公钥、链上地址、UNI-G、APPID-G)Info-B = (account ID, name, public key, on-chain address, UNI-G, APPID-G)
虽然只有部分信息,但已经可以满足业务提供方B的目标服务器的一些统计分析的需求,例如获取账户总数;同时,由于住址、其他属性并没有上链存储,因此业务提供方B的目标服务器无法获取这些交易数据,从而能够提升交易数据的安全性,可以理解的是,这种情况下业务提供方B的目标服务器的检测服务无须与缓存服务进行交互。Although there is only partial information, it can already meet some statistical analysis needs of the target server of business provider B, such as obtaining the total number of accounts. At the same time, since the address and other attributes are not stored on the chain, the target server of business provider B cannot obtain these transaction data, thereby improving the security of transaction data. It is understandable that in this case, the detection service of the target server of business provider B does not need to interact with the cache service.
类似地,当目标交易数据写入成功后,业务提供方B的目标服务器中的检测服务才会将当前(区块号BN,交易号TN)更新到目标数据库中,以表示当前检测服务成功处理到哪些目标交易;当由于意外崩溃,例如数据库不可用,则检测服务在重启的时候会从区块号BN开始检测,并从目标区块BN的第TN笔目标交易开始处理,因此,可以确保链上交易数据可以完整的同步到目标数据库中,避免数据丢失。Similarly, when the target transaction data is written successfully, the detection service in the target server of business provider B will update the current (block number BN, transaction number TN) to the target database to indicate which target transactions the current detection service has successfully processed; when there is an unexpected crash, such as database unavailability, the detection service will start detection from block number BN when it restarts, and start processing from the TNth target transaction of the target block BN. Therefore, it can ensure that the on-chain transaction data can be fully synchronized to the target database to avoid data loss.
至此,业务提供方G的目标服务器和业务提供方B的目标服务器的数据均有完整的交易数据,可以满足一些复杂查询、或一些数据统计分析的任务;同时,借助检测服务和(区块号BN,交易号TN)为记号的技术手段,可以提升链上交易数据和链下交易数据之间的一致性,交易数据不丢失。At this point, the target servers of business provider G and business provider B have complete transaction data, which can meet some complex queries or some data statistical analysis tasks; at the same time, with the help of detection services and technical means of (block number BN, transaction number TN) as markers, the consistency between on-chain transaction data and off-chain transaction data can be improved, and transaction data will not be lost.
(7)后端服务获取结果:在步骤(4)业务提供方G的目标服务器中的后端服务,会借助缓存服务获取检测服务设置的结果,即步骤(6)存储至缓存服务中的Resp:(7) Backend service acquisition result: In step (4), the backend service in the target server of the service provider G will use the cache service to obtain the result of the detection service setting, that is, the Resp stored in the cache service in step (6):
Resp={"error":"错误信息","user":"目标交易数据"}Resp={"error":"error information","user":"target transaction data"}
若error中存在错误,则返回相关的错误信息给终端UE1;否则,从user中取出账户标识,返回给终端UE1,表示账户注册成功,且在当前业务中的账户标识具体是什么,方便进行后续操作。If there is an error in error, the relevant error information is returned to the terminal UE1; otherwise, the account identifier is taken out from the user and returned to the terminal UE1, indicating that the account registration is successful, and the specific account identifier in the current business is what it is, to facilitate subsequent operations.
可见,本申请实施例提供的区块链数据处理方法具备以下优点:It can be seen that the blockchain data processing method provided in the embodiment of the present application has the following advantages:
通过记录区块号和交易序号,检测服务保证只有成功处理链上的目标交易,将目标交易数据存储至目标数据库后,才会去更新记录的区块号和交易序号,同时检测服务每次启动均会从记录的区块号和交易序号开始继续检查并处理目标交易,保证链上的交易数据可以可靠地写入到目标数据库,确保交易数据不会丢失,链上与链下的交易数据相一致。By recording the block number and transaction sequence number, the detection service ensures that the recorded block number and transaction sequence number will be updated only after the target transaction on the chain is successfully processed and the target transaction data is stored in the target database. At the same time, each time the detection service is started, it will continue to check and process the target transaction starting from the recorded block number and transaction sequence number, ensuring that the transaction data on the chain can be reliably written to the target database, ensuring that the transaction data will not be lost, and that the transaction data on the chain is consistent with that off the chain.
通过以缓存服务作为中转媒介,使得检测服务在获取到链上的交易数据后,可以借助缓存服务安全可靠的获取到后端服务缓存的上下文(即不上链的交易数据),进而构造完整的目标交易数据,既可以确保本地的目标交易数据完整地写入目标数据库,也能够获取到其他业务方对应的服务器中的至少部分交易数据,实现跨服务器的交易数据互通。By using the cache service as a transit medium, after obtaining the transaction data on the chain, the detection service can use the cache service to safely and reliably obtain the context of the backend service cache (that is, the transaction data that is not on the chain), and then construct the complete target transaction data. This can not only ensure that the local target transaction data is completely written to the target database, but also obtain at least part of the transaction data in the servers corresponding to other business parties, thereby realizing cross-server transaction data interoperability.
通过以交易证书为匹配基准,在新的目标服务器加入到区块链网络时,分配交易证书并上链,使得不同业务方的目标服务器都可以通过检测服务获取到其他业务方的目标服务器的服务器属性信息并存进数据库,之后检测服务处理目标交易时,可以识别不同业务方的目标服务器发起的目标交易,并对应进行不同的处理,实现跨服务器交易数据的互通的同时,方便进行基于服务器属性信息的数据统计分析。By using the transaction certificate as the matching basis, when a new target server joins the blockchain network, the transaction certificate is allocated and uploaded to the chain, so that the target servers of different business parties can obtain the server attribute information of the target servers of other business parties through the detection service and store it in the database. When the detection service processes the target transaction, it can identify the target transactions initiated by the target servers of different business parties and perform different processing accordingly, thereby achieving interoperability of cross-server transaction data and facilitating data statistical analysis based on server attribute information.
另外,参照图14,图14为本申请实施例提供的区块链数据处理方法的另一种可选的总体交互流程示意图,与图13所示的例子的区别在于,业务提供方B的目标服务器(对应地域B)和业务提供方G的目标服务器(对应地域G)均部署有后端服务、检测服务和目标数据库,并且,缓存服务部署在另外的独立的服务器,业务提供方B的目标服务器和业务提供方G的目标服务器共用同一个缓存服务。In addition, referring to Figure 14, Figure 14 is another optional overall interaction flow diagram of the blockchain data processing method provided in an embodiment of the present application. The difference from the example shown in Figure 13 is that the target server of business provider B (corresponding to region B) and the target server of business provider G (corresponding to region G) are both deployed with back-end services, detection services and target databases, and the cache service is deployed on another independent server, and the target server of business provider B and the target server of business provider G share the same cache service.
在此架构下,业务提供方G的目标服务器中的后端服务向缓存服务设置键值对时,会对不上链的交易数据(即前述的Context)进行加密,再存储至缓存服务中,同时,在本例子中,不上链的交易数据不希望向业务提供方B的目标服务器分享,因此只将对应的加密信息发送至业务提供方G的目标服务器中的检测服务。Under this architecture, when the backend service in the target server of business provider G sets a key-value pair to the cache service, the transaction data that is not on the chain (i.e., the aforementioned Context) will be encrypted and then stored in the cache service. At the same time, in this example, the transaction data that is not on the chain does not want to be shared with the target server of business provider B, so only the corresponding encrypted information is sent to the detection service in the target server of business provider G.
对于业务提供方G的目标服务器中的检测服务来说,在从缓存服务中提取出Context后,即可根据解密信息对Context进行解密,进而还原出原来的交易数据,进而得到目标交易数据:For the detection service in the target server of the business provider G, after extracting the Context from the cache service, the Context can be decrypted according to the decryption information, and then the original transaction data can be restored, and then the target transaction data can be obtained:
Info-G=(账户标识、姓名、公钥、链上地址、住址、其他属性、UNI-G、APPID-G)Info-G = (account ID, name, public key, on-chain address, address, other attributes, UNI-G, APPID-G)
而对于业务提供方B的目标服务器中的检测服务来说,同样会从缓存服务中提取出Context,但由于业务提供方G的目标服务器中的检测服务没有对应的解密信息,因此解密失败,最终只得到目标交易数据:For the detection service in the target server of business provider B, the Context is also extracted from the cache service. However, since the detection service in the target server of business provider G does not have the corresponding decryption information, the decryption fails and only the target transaction data is obtained:
Info-B=(账户标识、姓名、公钥、链上地址、UNI-G、APPID-G)Info-B = (account ID, name, public key, on-chain address, UNI-G, APPID-G)
可见,本例子可以有效对网络架构进行简化,同时,通过对Context进行加密,能够在对网络架构进行简化的同时,不影响交易数据的安全性。It can be seen that this example can effectively simplify the network architecture. At the same time, by encrypting the Context, the network architecture can be simplified without affecting the security of transaction data.
另外,在此架构下,业务提供方G的目标服务器中的检测服务在向缓存服务写入存储状态信息Resp时,可以在key里进一步增加服务器标识G,例如以"G/txid/resp/TxId"为完整的key,从而便于后端服务从缓存服务中获取存储状态信息Resp时,能够根据服务器标识来识别出当前所在的目标服务器的存储状态信息Resp。In addition, under this architecture, when the detection service in the target server of the service provider G writes the storage status information Resp to the cache service, it can further add the server identifier G in the key, for example, using "G/txid/resp/TxId" as the complete key, so that when the backend service obtains the storage status information Resp from the cache service, it can identify the storage status information Resp of the current target server according to the server identifier.
另外,若不上链的交易数据需要向业务提供方B的目标服务器分享,此时可以将对应的加密信息发送至业务提供方G的目标服务器中的检测服务,以及业务提供方B的目标服务器中的检测服务,则对于业务提供方B的目标服务器中的检测服务来说,也能够根据解密信息对Context进行解密,进而还原出原来的交易数据。In addition, if the transaction data that is not on the chain needs to be shared with the target server of business provider B, the corresponding encrypted information can be sent to the detection service in the target server of business provider G and the detection service in the target server of business provider B. The detection service in the target server of business provider B can also decrypt the Context according to the decryption information, and then restore the original transaction data.
可以理解的是,虽然上述各个流程图中的各个步骤按照箭头的指示依次显示,但是这些步骤并不是必然按照箭头指示的顺序依次执行。除非本实施例中有明确的说明,这些步骤的执行并没有严格的顺序限制,这些步骤可以以其它的顺序执行。而且,上述流程图中的至少一部分步骤可以包括多个步骤或者多个阶段,这些步骤或者阶段并不必然是在同一时间执行完成,而是可以在不同的时间执行,这些步骤或者阶段的执行顺序也不必然是依次进行,而是可以与其它步骤或者其它步骤中的步骤或者阶段的至少一部分轮流或者交替地执行。It is to be understood that, although each step in the above-mentioned each flow chart is shown in turn according to the indication of the arrow, these steps are not necessarily performed in turn according to the order indicated by the arrow. Unless there is a clear explanation in the present embodiment, the execution of these steps does not have a strict order restriction, and these steps can be performed in other orders. Moreover, at least a portion of the steps in the above-mentioned flow chart can include a plurality of steps or a plurality of stages, and these steps or stages are not necessarily performed at the same time, but can be performed at different times, and the execution order of these steps or stages is not necessarily performed in turn, but can be performed in turn or alternately with at least a portion of the steps or stages in other steps or other steps.
另一方面,参照图15,图15为本申请实施例提供的第一区块链数据处理装置的一种可选的机构示意图,该第一区块链数据处理装置1500包括:On the other hand, referring to FIG. 15 , FIG. 15 is an optional schematic diagram of the structure of the first blockchain data processing device provided in an embodiment of the present application, and the first blockchain data processing device 1500 includes:
区块接收模块1501,用于当目标区块被区块链网络共识通过时,接收区块链网络发送的目标区块,其中,目标区块包括至少一个目标交易;The block receiving module 1501 is used to receive the target block sent by the blockchain network when the target block is approved by the blockchain network consensus, wherein the target block includes at least one target transaction;
区块处理模块1502,用于从目标区块中提取出目标交易的目标交易标识,以及目标交易关联的第一交易数据;The block processing module 1502 is used to extract the target transaction identifier of the target transaction and the first transaction data associated with the target transaction from the target block;
访问模块1503,用于访问存储有第一数据对的缓存服务,根据目标交易标识从缓存服务的第一数据对中获取目标交易关联的第二交易数据,其中,第一数据对基于交易标识和交易数据构建得到,第一数据对中的交易标识是由区块链网络在接收到异步发送的交易请求后生成的;An access module 1503 is used to access a cache service storing a first data pair, and obtain second transaction data associated with a target transaction from the first data pair of the cache service according to a target transaction identifier, wherein the first data pair is constructed based on the transaction identifier and the transaction data, and the transaction identifier in the first data pair is generated by the blockchain network after receiving an asynchronously sent transaction request;
存储模块1504,用于根据第一交易数据和第二交易数据得到目标交易数据,将目标交易数据存储至目标数据库。The storage module 1504 is used to obtain target transaction data according to the first transaction data and the second transaction data, and store the target transaction data in a target database.
进一步,区块接收模块1501具体用于:Furthermore, the block receiving module 1501 is specifically used for:
根据预设的区块号区间生成区块订阅请求,将区块订阅请求发送至区块链网络;Generate a block subscription request according to the preset block number range, and send the block subscription request to the blockchain network;
每当位于区块号区间内的目标区块被区块链网络共识通过时,接收区块链网络响应区块订阅请求发送的目标区块。Whenever the target block in the block number interval is approved by the blockchain network consensus, the target block sent by the blockchain network in response to the block subscription request is received.
进一步,存储模块1504还用于:Furthermore, the storage module 1504 is also used for:
生成目标交易数据的存储结果信息,其中,存储结果信息用于指示目标交易数据已成功存储至目标数据库或者未成功存储至目标数据库;Generate storage result information of the target transaction data, wherein the storage result information is used to indicate whether the target transaction data has been successfully stored in the target database or has not been successfully stored in the target database;
基于目标交易标识和存储结果信息构建第二数据对,将第二数据对存储至缓存服务中。A second data pair is constructed based on the target transaction identifier and the storage result information, and the second data pair is stored in the cache service.
进一步,存储模块1504还用于:Furthermore, the storage module 1504 is also used for:
当目标交易数据已成功存储至目标数据库时,确定目标区块的区块号以及当前的目标交易在目标区块中的交易序号,记录区块号以及交易序号;When the target transaction data has been successfully stored in the target database, determine the block number of the target block and the transaction sequence number of the current target transaction in the target block, and record the block number and transaction sequence number;
在重新启动后,加载区块号以及交易序号,根据区块号以及交易序号确定下一个目标交易。After restarting, the block number and transaction sequence number are loaded, and the next target transaction is determined based on the block number and transaction sequence number.
进一步,存储模块1504还用于:Furthermore, the storage module 1504 is also used for:
若目标交易的交易类型为链配置类型时,从目标区块中提取出目标服务器的服务器属性信息,以及区块链网络为目标服务器分配的服务器交易证书,其中,目标服务器为目标交易配置的服务器;If the transaction type of the target transaction is a chain configuration type, extract the server attribute information of the target server from the target block, and the server transaction certificate assigned to the target server by the blockchain network, wherein the target server is the server configured for the target transaction;
将服务器属性信息和服务器交易证书存储至目标数据库。The server attribute information and the server transaction certificate are stored in the target database.
进一步,存储模块1504具体用于:Further, the storage module 1504 is specifically used for:
从目标区块中提取出对目标交易进行签名时使用的目标交易证书;Extract the target transaction certificate used to sign the target transaction from the target block;
将目标交易证书与服务器交易证书进行匹配,根据匹配结果从目标数据库中获取目标交易对应的服务器属性信息;Match the target transaction certificate with the server transaction certificate, and obtain the server attribute information corresponding to the target transaction from the target database according to the matching result;
将第一交易数据、第二交易数据、服务器属性信息和目标交易证书合并为目标交易数据。The first transaction data, the second transaction data, the server attribute information and the target transaction certificate are combined into the target transaction data.
进一步,访问模块1503具体用于:Further, the access module 1503 is specifically used for:
从目标区块中提取出在对目标交易进行签名时使用的目标交易证书;Extracting the target transaction certificate used to sign the target transaction from the target block;
获取在启动时加载的服务器交易证书,将在启动时加载的服务器交易证书与目标交易证书进行比较;Obtain the server transaction certificate loaded at startup, and compare the server transaction certificate loaded at startup with the target transaction certificate;
当比较结果为在启动时加载的服务器交易证书与目标交易证书相一致时,访问存储有第一数据对的缓存服务。When the comparison result is that the server transaction certificate loaded at startup is consistent with the target transaction certificate, a cache service storing the first data pair is accessed.
进一步,存储模块1503还用于:Further, the storage module 1503 is also used for:
当比较结果为在启动时加载的服务器交易证书与目标交易证书不一致时,将第一交易数据作为目标交易数据,将目标交易数据存储至目标数据库;When the comparison result is that the server transaction certificate loaded at startup is inconsistent with the target transaction certificate, the first transaction data is used as the target transaction data, and the target transaction data is stored in the target database;
或者,当比较结果为在启动时加载的服务器交易证书与目标交易证书不一致时,访问缓存服务,根据第一数据对从缓存服务中获取目标交易标识对应的加密交易数据,获取预先存储的解密信息,根据解密信息对加密交易数据进行解密处理,得到目标交易标识对应的第二交易数据,根据第一交易数据和第二交易数据得到目标交易数据,将目标交易数据存储至目标数据库,其中,解密信息是由构建第一数据对的目标服务器生成的。Alternatively, when the comparison result is that the server transaction certificate loaded at startup is inconsistent with the target transaction certificate, the cache service is accessed, and the encrypted transaction data corresponding to the target transaction identifier is obtained from the cache service according to the first data pair, and the pre-stored decryption information is obtained. The encrypted transaction data is decrypted according to the decryption information to obtain the second transaction data corresponding to the target transaction identifier, and the target transaction data is obtained according to the first transaction data and the second transaction data, and the target transaction data is stored in the target database, wherein the decryption information is generated by the target server that constructs the first data pair.
上述第一区块链数据处理装置1500与图4所示的区块链数据处理方法基于相同的发明构思,通过当目标区块被区块链网络共识通过时,接收区块链网络发送的目标区块,从目标区块中提取出目标交易关联的第一交易数据,在多个不同的服务器参与区块链业务系统的场景下,不同的服务器均可以同步获取到其他服务器在区块链中的交易数据,从而实现交易数据的跨服务器共享,并且,通过从目标区块中提取出目标交易的目标交易标识,访问存储有第一数据对的缓存服务,根据目标交易标识从缓存服务的第一数据对中获取目标交易关联的第二交易数据,由于第一数据对基于交易标识和交易数据构建得到,因此通过引入缓存服务,使得在第二交易数据不需要进行上链操作的情况下,也能够根据目标交易标识获取到目标交易关联的第二交易数据,从而在跨服务器共享交易数据的场景下提升交易数据的安全性,在此基础上,能够根据第一交易数据和第二交易数据得到目标交易数据,将目标交易数据存储至目标数据库,使得目标数据库中既可以存储有区块链中的第一交易数据,也可以存储有不在区块链中的第二交易数据,从而在提升交易数据的安全性的基础上,提升本地数据库中的交易数据的完整性。The first blockchain data processing device 1500 and the blockchain data processing method shown in FIG4 are based on the same inventive concept. When the target block is passed by the blockchain network consensus, the target block sent by the blockchain network is received, and the first transaction data associated with the target transaction is extracted from the target block. In the scenario where multiple different servers participate in the blockchain business system, different servers can synchronously obtain the transaction data of other servers in the blockchain, thereby realizing cross-server sharing of transaction data, and by extracting the target transaction identifier of the target transaction from the target block, accessing the cache service storing the first data pair, and obtaining the second transaction data associated with the target transaction from the first data pair of the cache service according to the target transaction identifier. According to the invention, since the first data pair is constructed based on the transaction identifier and the transaction data, by introducing the cache service, the second transaction data associated with the target transaction can be obtained according to the target transaction identifier without the need for the second transaction data to be uploaded to the chain, thereby improving the security of the transaction data in the scenario of sharing transaction data across servers. On this basis, the target transaction data can be obtained according to the first transaction data and the second transaction data, and the target transaction data can be stored in the target database, so that the target database can store both the first transaction data in the blockchain and the second transaction data that is not in the blockchain, thereby improving the integrity of the transaction data in the local database on the basis of improving the security of the transaction data.
另一方面,参照图16,图16为本申请实施例提供的第二区块链数据处理装置的一种可选的机构示意图,该第二区块链数据处理装置1600包括:On the other hand, referring to FIG. 16 , FIG. 16 is an optional schematic diagram of the mechanism of the second blockchain data processing device provided in an embodiment of the present application, and the second blockchain data processing device 1600 includes:
请求模块1601,用于向区块链网络异步发送目标交易的交易请求,接收区块链网络返回的目标交易的目标交易标识;Request module 1601, used to asynchronously send a transaction request of a target transaction to the blockchain network, and receive a target transaction identifier of the target transaction returned by the blockchain network;
数据对构建模块1602,用于获取目标交易关联的第二交易数据,根据目标交易标识和第二交易数据构建第一数据对;A data pair construction module 1602 is used to obtain second transaction data associated with a target transaction, and to construct a first data pair according to the target transaction identifier and the second transaction data;
缓存模块1603,用于将第一数据对存储至缓存服务中,以供检测服务在目标交易对应的目标区块被区块链网络共识通过时,从目标区块中提取出目标交易标识以及目标交易关联的第一交易数据,访问缓存服务,根据目标交易标识从缓存服务的第一数据对中获取第二交易数据,根据第一交易数据和第二交易数据得到目标交易数据,将目标交易数据存储至目标数据库。The cache module 1603 is used to store the first data pair in the cache service so that when the target block corresponding to the target transaction is approved by the blockchain network consensus, the detection service extracts the target transaction identifier and the first transaction data associated with the target transaction from the target block, accesses the cache service, obtains the second transaction data from the first data pair of the cache service according to the target transaction identifier, obtains the target transaction data according to the first transaction data and the second transaction data, and stores the target transaction data in the target database.
进一步,区块链数据处理装置还包括消息发送模块1604,消息发送模块1604用于:Furthermore, the blockchain data processing device further includes a message sending module 1604, which is used to:
根据目标交易标识从缓存服务的第二数据对中获取目标交易对应的存储结果信息,根据存储结果信息生成用于指示目标交易的交易结果的第一通知消息;Acquire storage result information corresponding to the target transaction from the second data pair of the cache service according to the target transaction identifier, and generate a first notification message indicating a transaction result of the target transaction according to the storage result information;
将第一通知消息发送至发起目标交易的账户。The first notification message is sent to the account that initiated the target transaction.
进一步,消息发送模块1604具体用于:Further, the message sending module 1604 is specifically used for:
基于预设的时间间隔,持续根据目标交易标识从缓存服务的第二数据对中获取目标交易对应的存储结果信息;Based on a preset time interval, continuously obtaining storage result information corresponding to the target transaction from the second data pair of the cache service according to the target transaction identifier;
当获取到存储结果信息时,根据存储结果信息生成用于指示目标交易的交易结果的第一通知消息;或者,当请求存储结果信息的持续时长超过预设的时长阈值时,生成用于指示超时的第二通知消息,将第二通知消息发送至发起目标交易的账户。When the storage result information is obtained, a first notification message indicating the transaction result of the target transaction is generated according to the storage result information; or, when the duration of the request for storage result information exceeds a preset duration threshold, a second notification message indicating a timeout is generated and sent to the account that initiated the target transaction.
进一步,数据对构建模块1602具体用于:Further, the data pair construction module 1602 is specifically used for:
对第二交易数据进行加密,得到加密交易数据,将加密交易数据对应的解密信息发送至检测服务;Encrypting the second transaction data to obtain encrypted transaction data, and sending decryption information corresponding to the encrypted transaction data to the detection service;
根据目标交易标识和加密交易数据构建第一数据对。A first data pair is constructed according to the target transaction identifier and the encrypted transaction data.
上述第二区块链数据处理装置1600与图10所示的区块链数据处理方法基于相同的发明构思,通过将第一数据对存储至缓存服务中,使得当目标区块被区块链网络共识通过时,检测服务可以接收区块链网络发送的目标区块,从目标区块中提取出目标交易关联的第一交易数据,在多个不同的服务器参与区块链业务系统的场景下,不同的服务器均可以同步获取到其他服务器在区块链中的交易数据,从而实现交易数据的跨服务器共享,并且,通过从目标区块中提取出目标交易的目标交易标识,访问存储有第一数据对的缓存服务,根据目标交易标识从缓存服务的第一数据对中获取目标交易关联的第二交易数据,由于第一数据对基于交易标识和交易数据构建得到,因此通过引入缓存服务,使得在第二交易数据不需要进行上链操作的情况下,也能够根据目标交易标识获取到目标交易关联的第二交易数据,从而在跨服务器共享交易数据的场景下提升交易数据的安全性,在此基础上,能够根据第一交易数据和第二交易数据得到目标交易数据,将目标交易数据存储至目标数据库,使得目标数据库中既可以存储有区块链中的第一交易数据,也可以存储有不在区块链中的第二交易数据,从而在提升交易数据的安全性的基础上,提升本地数据库中的交易数据的完整性。The above-mentioned second blockchain data processing device 1600 and the blockchain data processing method shown in FIG10 are based on the same inventive concept. By storing the first data pair in the cache service, when the target block is passed by the blockchain network consensus, the detection service can receive the target block sent by the blockchain network, and extract the first transaction data associated with the target transaction from the target block. In the scenario where multiple different servers participate in the blockchain business system, different servers can synchronously obtain the transaction data of other servers in the blockchain, thereby realizing cross-server sharing of transaction data, and by extracting the target transaction identifier of the target transaction from the target block, accessing the cache service storing the first data pair, and obtaining the target transaction identifier from the first data pair of the cache service according to the target transaction identifier. The second transaction data associated with the target transaction is constructed based on the transaction identifier and the transaction data. Therefore, by introducing a cache service, the second transaction data associated with the target transaction can be obtained according to the target transaction identifier without the need for the second transaction data to be uploaded to the chain. This improves the security of transaction data in the scenario of sharing transaction data across servers. On this basis, the target transaction data can be obtained based on the first transaction data and the second transaction data, and the target transaction data can be stored in the target database. The target database can store both the first transaction data in the blockchain and the second transaction data that is not in the blockchain. This improves the integrity of the transaction data in the local database while improving the security of the transaction data.
本申请实施例提供的用于执行上述区块链数据处理方法的电子设备可以是终端,参照图17,图17为本申请实施例提供的终端的部分结构框图,该终端包括:摄像头组件1710、存储器1720、输入单元1730、显示单元1740、传感器1750、音频电路1760、无线保真(wireless fidelity,简称WiFi)模块1770、处理器1780、以及电源1790等部件。本领域技术人员可以理解,图17中示出的终端结构并不构成对终端的限定,可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件布置。The electronic device for executing the above-mentioned blockchain data processing method provided in the embodiment of the present application may be a terminal. Referring to FIG. 17, FIG. 17 is a partial structural block diagram of the terminal provided in the embodiment of the present application, and the terminal includes: a camera assembly 1710, a memory 1720, an input unit 1730, a display unit 1740, a sensor 1750, an audio circuit 1760, a wireless fidelity (WiFi) module 1770, a processor 1780, and a power supply 1790. It can be understood by those skilled in the art that the terminal structure shown in FIG. 17 does not constitute a limitation on the terminal, and may include more or fewer components than shown in the figure, or combine certain components, or arrange components differently.
摄像头组件1710可用于采集图像或视频。可选地,摄像头组件1710包括前置摄像头和后置摄像头。通常,前置摄像头设置在终端的前面板,后置摄像头设置在终端的背面。在一些实施例中,后置摄像头为至少两个,分别为主摄像头、景深摄像头、广角摄像头、长焦摄像头中的任意一种,以实现主摄像头和景深摄像头融合实现背景虚化功能、主摄像头和广角摄像头融合实现全景拍摄以及VR(Virtual Reality,虚拟现实)拍摄功能或者其它融合拍摄功能。The camera assembly 1710 can be used to capture images or videos. Optionally, the camera assembly 1710 includes a front camera and a rear camera. Typically, the front camera is disposed on the front panel of the terminal, and the rear camera is disposed on the back of the terminal. In some embodiments, there are at least two rear cameras, which are any one of a main camera, a depth of field camera, a wide-angle camera, and a telephoto camera, so as to realize the fusion of the main camera and the depth of field camera to realize the background blur function, the fusion of the main camera and the wide-angle camera to realize the panoramic shooting and the VR (Virtual Reality) shooting function or other fusion shooting functions.
存储器1720可用于存储软件程序以及模块,处理器1780通过运行存储在存储器1720的软件程序以及模块,从而执行终端的各种功能应用以及数据处理。The memory 1720 may be used to store software programs and modules. The processor 1780 executes various functional applications and data processing of the terminal by running the software programs and modules stored in the memory 1720 .
输入单元1730可用于接收输入的数字或字符信息,以及产生与终端的设置以及功能控制有关的键信号输入。具体地,输入单元1730可包括触摸面板1731以及其他输入装置1732。The input unit 1730 may be used to receive input digital or character information and generate key signal input related to the terminal's settings and function control. Specifically, the input unit 1730 may include a touch panel 1731 and other input devices 1732 .
显示单元1740可用于显示输入的信息或提供的信息以及终端的各种菜单。显示单元1740可包括显示面板1741。The display unit 1740 may be used to display input information or provided information and various menus of the terminal. The display unit 1740 may include a display panel 1741 .
音频电路1760、扬声器1761,传声器1762可提供音频接口。The audio circuit 1760, the speaker 1761, and the microphone 1762 may provide an audio interface.
电源1790可以是交流电、直流电、一次性电池或可充电电池。The power source 1790 may be alternating current, direct current, a disposable battery, or a rechargeable battery.
传感器1750的数量可以为一个或者多个,该一个或多个传感器1750包括但不限于:加速度传感器、陀螺仪传感器、压力传感器、光学传感器等等。其中:The number of sensors 1750 may be one or more, and the one or more sensors 1750 include but are not limited to: acceleration sensors, gyroscope sensors, pressure sensors, optical sensors, etc. Among them:
加速度传感器可以检测以终端建立的坐标系的三个坐标轴上的加速度大小。比如,加速度传感器可以用于检测重力加速度在三个坐标轴上的分量。处理器1780可以根据加速度传感器采集的重力加速度信号,控制显示单元1740以横向视图或纵向视图进行用户界面的显示。加速度传感器还可以用于游戏或者用户的运动数据的采集。The acceleration sensor can detect the magnitude of acceleration on the three coordinate axes of the coordinate system established by the terminal. For example, the acceleration sensor can be used to detect the components of gravity acceleration on the three coordinate axes. The processor 1780 can control the display unit 1740 to display the user interface in a horizontal view or a vertical view according to the gravity acceleration signal collected by the acceleration sensor. The acceleration sensor can also be used for collecting game or user motion data.
陀螺仪传感器可以检测终端的机体方向及转动角度,陀螺仪传感器可以与加速度传感器协同采集用户对终端的3D动作。处理器1780根据陀螺仪传感器采集的数据,可以实现如下功能:动作感应(比如根据用户的倾斜操作来改变UI)、拍摄时的图像稳定、游戏控制以及惯性导航。The gyroscope sensor can detect the body direction and rotation angle of the terminal, and the gyroscope sensor can cooperate with the acceleration sensor to collect the user's 3D actions on the terminal. The processor 1780 can implement the following functions based on the data collected by the gyroscope sensor: motion sensing (such as changing the UI according to the user's tilt operation), image stabilization during shooting, game control, and inertial navigation.
压力传感器可以设置在终端的侧边框和/或显示单元1740的下层。当压力传感器设置在终端的侧边框时,可以检测用户对终端的握持信号,由处理器1780根据压力传感器采集的握持信号进行左右手识别或快捷操作。当压力传感器设置在显示单元1740的下层时,由处理器1780根据用户对显示单元1740的压力操作,实现对UI界面上的可操作性控件进行控制。可操作性控件包括按钮控件、滚动条控件、图标控件、菜单控件中的至少一种。The pressure sensor can be set in the side frame of the terminal and/or the lower layer of the display unit 1740. When the pressure sensor is set in the side frame of the terminal, the user's holding signal of the terminal can be detected, and the processor 1780 performs left and right hand recognition or shortcut operation according to the holding signal collected by the pressure sensor. When the pressure sensor is set in the lower layer of the display unit 1740, the processor 1780 controls the operability controls on the UI interface according to the user's pressure operation on the display unit 1740. The operability control includes at least one of a button control, a scroll bar control, an icon control, and a menu control.
光学传感器用于采集环境光强度。在一个实施例中,处理器1780可以根据光学传感器采集的环境光强度,控制显示单元1740的显示亮度。具体地,当环境光强度较高时,调高显示单元1740的显示亮度;当环境光强度较低时,调低显示单元1740的显示亮度。在另一个实施例中,处理器1780还可以根据光学传感器采集的环境光强度,动态调整摄像头组件1710的拍摄参数。The optical sensor is used to collect the ambient light intensity. In one embodiment, the processor 1780 can control the display brightness of the display unit 1740 according to the ambient light intensity collected by the optical sensor. Specifically, when the ambient light intensity is high, the display brightness of the display unit 1740 is increased; when the ambient light intensity is low, the display brightness of the display unit 1740 is decreased. In another embodiment, the processor 1780 can also dynamically adjust the shooting parameters of the camera assembly 1710 according to the ambient light intensity collected by the optical sensor.
在本实施例中,该终端所包括的处理器1780可以执行前面实施例的区块链数据处理方法。In this embodiment, the processor 1780 included in the terminal can execute the blockchain data processing method of the previous embodiment.
本申请实施例提供的用于执行上述区块链数据处理方法的电子设备也可以是服务器,参照图18,图18为本申请实施例提供的服务器的部分结构框图,服务器1800可因配置或性能不同而产生比较大的差异,可以包括一个或一个以上中央处理器(CentralProcessing Units,简称CPU)1822(例如,一个或一个以上处理器)和存储器1832,一个或一个以上存储应用程序1842或数据1844的存储介质1830(例如一个或一个以上海量存储装置)。其中,存储器1832和存储介质1830可以是短暂存储或持久存储。存储在存储介质1830的程序可以包括一个或一个以上模块(图示没标出),每个模块可以包括对服务器1800中的一系列指令操作。更进一步地,中央处理器1822可以设置为与存储介质1830通信,在服务器1800上执行存储介质1830中的一系列指令操作。The electronic device for executing the above-mentioned blockchain data processing method provided in the embodiment of the present application can also be a server. Referring to FIG. 18, FIG. 18 is a partial structural block diagram of the server provided in the embodiment of the present application. The server 1800 may have relatively large differences due to different configurations or performances, and may include one or more central processing units (CPU) 1822 (for example, one or more processors) and memory 1832, and one or more storage media 1830 (for example, one or more mass storage devices) storing application programs 1842 or data 1844. Among them, the memory 1832 and the storage medium 1830 can be short-term storage or permanent storage. The program stored in the storage medium 1830 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the server 1800. Furthermore, the central processor 1822 can be configured to communicate with the storage medium 1830 and execute a series of instruction operations in the storage medium 1830 on the server 1800.
服务器1800还可以包括一个或一个以上电源1826,一个或一个以上有线或无线网络接口1850,一个或一个以上输入输出接口1858,和/或,一个或一个以上操作系统1841,例如Windows ServerTM,Mac OS XTM,UnixTM,LinuxTM,FreeBSDTM等等。The server 1800 may also include one or more power supplies 1826, one or more wired or wireless network interfaces 1850, one or more input and output interfaces 1858, and/or, one or more operating systems 1841, such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, etc.
服务器1800中的处理器可以用于执行区块链数据处理方法。The processor in server 1800 can be used to execute the blockchain data processing method.
本申请实施例还提供一种计算机可读存储介质,计算机可读存储介质用于存储程序代码,程序代码用于执行前述各个实施例的区块链数据处理方法。An embodiment of the present application also provides a computer-readable storage medium, which is used to store program code, and the program code is used to execute the blockchain data processing method of each of the aforementioned embodiments.
本申请实施例还提供了一种计算机程序产品,该计算机程序产品包括计算机程序,该计算机程序存储在计算机可读存介质中。计算机设备的处理器从计算机可读存储介质读取该计算机程序,处理器执行该计算机程序,使得该计算机设备执行实现上述的区块链数据处理方法。The embodiment of the present application also provides a computer program product, which includes a computer program, and the computer program is stored in a computer-readable storage medium. The processor of the computer device reads the computer program from the computer-readable storage medium, and the processor executes the computer program, so that the computer device executes the above-mentioned blockchain data processing method.
本申请的说明书及上述附图中的术语“第一”、“第二”、“第三”、“第四”等(如果存在)是用于区别类似的对象,而不必用于描述特定的顺序或先后次序。应该理解这样使用的数据在适当情况下可以互换,以便描述本申请的实施例,例如能够以除了在这里图示或描述的那些以外的顺序实施。此外,术语“包括”和“具有”以及他们的任何变形,意图在于覆盖不排他的包含,例如,包含了一系列步骤或单元的过程、方法、系统、产品或装置不必限于清楚地列出的那些步骤或单元,而是可包括没有清楚地列出的或对于这些过程、方法、产品或装置固有的其它步骤或单元。The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate to describe the embodiments of the present application, for example, it can be implemented in an order other than those illustrated or described here. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
应当理解,在本申请中,“至少一个(项)”是指一个或者多个,“多个”是指两个或两个以上。“和/或”,用于描述关联对象的关联关系,表示可以存在三种关系,例如,“A和/或B”可以表示:只存在A,只存在B以及同时存在A和B三种情况,其中A,B可以是单数或者复数。字符“/”一般表示前后关联对象是一种“或”的关系。“以下至少一项(个)”或其类似表达,是指这些项中的任意组合,包括单项(个)或复数项(个)的任意组合。例如,a,b或c中的至少一项(个),可以表示:a,b,c,“a和b”,“a和c”,“b和c”,或“a和b和c”,其中a,b,c可以是单个,也可以是多个。It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And/or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and/or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character "/" generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.
应了解,在本申请实施例的描述中,多个(或多项)的含义是两个以上,大于、小于、超过等理解为不包括本数,以上、以下、以内等理解为包括本数。It should be understood that in the description of the embodiments of the present application, the meaning of multiple (or multiple items) is more than two, greater than, less than, exceed, etc. are understood to not include the number, and above, below, within, etc. are understood to include the number.
在本申请所提供的几个实施例中,应该理解到,所揭露的系统,装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机装置(可以是个人计算机,服务器,或者网络装置等)执行本申请各个实施例方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(Read-On ly Memory,简称ROM)、随机存取存储器(Random Access Memory,简称RAM)、磁碟或者光盘等各种可以存储程序代码的介质。If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM), disk or optical disk and other media that can store program codes.
还应了解,本申请实施例提供的各种实施方式可以任意进行组合,以实现不同的技术效果。It should also be understood that the various implementation methods provided in the embodiments of the present application can be combined arbitrarily to achieve different technical effects.
以上是对本申请的较佳实施进行了具体说明,但本申请并不局限于上述实施方式,熟悉本领域的技术人员在不违背本申请精神的共享条件下还可作出种种等同的变形或替换,这些等同的变形或替换均包括在本申请权利要求所限定的范围内。The above is a specific description of the preferred implementation of the present application, but the present application is not limited to the above implementation mode. Technical personnel familiar with the field can also make various equivalent modifications or substitutions under the shared conditions without violating the spirit of the present application. These equivalent modifications or substitutions are all included in the scope defined by the claims of the present application.
Claims (17)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310365386.5A CN118740851A (en) | 2023-03-30 | 2023-03-30 | Blockchain data processing method, device, electronic device and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310365386.5A CN118740851A (en) | 2023-03-30 | 2023-03-30 | Blockchain data processing method, device, electronic device and storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN118740851A true CN118740851A (en) | 2024-10-01 |
Family
ID=92864999
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202310365386.5A Pending CN118740851A (en) | 2023-03-30 | 2023-03-30 | Blockchain data processing method, device, electronic device and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN118740851A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN119622032A (en) * | 2024-11-26 | 2025-03-14 | 中国民航信息网络股份有限公司 | Subscription data processing method, device and electronic device |
-
2023
- 2023-03-30 CN CN202310365386.5A patent/CN118740851A/en active Pending
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN119622032A (en) * | 2024-11-26 | 2025-03-14 | 中国民航信息网络股份有限公司 | Subscription data processing method, device and electronic device |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US12001404B2 (en) | Techniques for replication checkpointing during disaster recovery | |
US10795778B2 (en) | Shared data recovery method and apparatus, computer device, and storage medium | |
US11934541B2 (en) | Securely sharing selected fields in a blockchain with runtime access determination | |
US20230037932A1 (en) | Data processing method and apparatus based on blockchain network, and computer device | |
JP2021131870A (en) | Cross-blockchain authentication method and apparatus | |
KR20200084009A (en) | Asset management method and apparatus, and electronic device | |
EP4348933B1 (en) | Managing keys across a series of nodes, based on snapshots of logged client key modifications | |
CN111340482B (en) | Conflict detection method, device, node equipment and storage medium | |
US9264414B2 (en) | Retry and snapshot enabled cross-platform synchronized communication queue | |
CN115098537B (en) | Transaction execution method and device, computing equipment and storage medium | |
US9930063B2 (en) | Random identifier generation for offline database | |
CN110826103A (en) | Block chain-based document authority processing method, device, equipment and storage medium | |
CN111339181B (en) | Block storage method, block storage device, node equipment and storage medium | |
CN113010498B (en) | Data synchronization method, device, computer equipment and storage medium | |
CN118740851A (en) | Blockchain data processing method, device, electronic device and storage medium | |
WO2018050055A1 (en) | Data request processing method and system, access device, and storage device therefor | |
CN111327680B (en) | Authentication data synchronization method, device, system, computer equipment and storage medium | |
US10341420B1 (en) | Approaches for preparing and delivering bulk data to clients | |
WO2023244491A1 (en) | Techniques for replication checkpointing during disaster recovery | |
CN113297233B (en) | Data processing method, device and server | |
CN116527337A (en) | Cluster data information access method, device, equipment and storage medium | |
CN113986915A (en) | Data storage method and device | |
CN113778359A (en) | Wireless screen projection method and device, wearable device and storage medium | |
CN115113994B (en) | Request processing method, device, computing device and storage medium | |
CN118838961A (en) | Block chain transaction data processing method and device, electronic equipment and storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication |