Block chain data processing method and device and storage medium
By performing data broadcast operations in the blockchain system, pre-save transactions and metadata, and generating target blocks to be agreed upon based on the metadata, the network congestion caused by multiple rounds of information broadcasting is solved, and the throughput of blockchain is improved.
Patent Information
- Application Number
- CN202311550287.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-16
- Publication Date
- 2025-05-16
AI Technical Summary
In the blockchain system, when the Byzantine consensus algorithm is used to perform consensus processing on new blocks, multiple rounds of information broadcasting cause network congestion, reducing the speed and efficiency of consensus processing, and thus reducing the throughput of the blockchain.
Before generating the target block to be agreed upon, data broadcast operations are performed, including obtaining the target transaction, generating the metadata of the target transaction, and broadcasting in the blockchain, so that the nodes can save the transaction and metadata in advance. When the target transaction and metadata are saved by a preset number of consensus nodes, the target block to be consensus is generated based on the metadata and consensus processing is performed.
By reducing the amount of data in the target block, reducing the amount of information spreading in the network, reducing the probability of network congestion, improving the speed and efficiency of consensus processing, and thus improving the throughput of the blockchain.
Smart Images

Figure CN120017654A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of blockchain technology, and in particular to a blockchain data processing method, device and storage medium. Background Art
[0002] In the current blockchain system, after a proposal node generates a new block, the proposal node will broadcast the new block in the blockchain, so that the consensus nodes in the blockchain use, for example, the Byzantine consensus algorithm to process the new block. When the consensus nodes in the blockchain reach a consensus on the new block, the proposal node can add the new block to the blockchain. However, when the Byzantine consensus algorithm is used to process the new block, the consensus nodes in the blockchain need to go through multiple rounds of information broadcasting to process the new block. When the new block includes a large amount of transaction information, a large amount of transaction information will be propagated in the network during multiple rounds of information broadcasting, which can easily lead to network congestion, thereby reducing the speed and efficiency of consensus processing, and further reducing the throughput of the blockchain. Summary of the invention
[0003] The following is a summary of the subject matter described in detail herein. This summary is not intended to limit the scope of the claims.
[0004] The embodiments of the present application provide a blockchain data processing method, device, and storage medium, which can reduce the probability of network congestion, thereby improving the speed and efficiency of consensus processing, and further improving the throughput of the blockchain.
[0005] On the one hand, an embodiment of the present application provides a blockchain data processing method, comprising the following steps:
[0006] Performing a data broadcast operation, wherein the data broadcast operation includes an operation of obtaining a target transaction, an operation of generating metadata of the target transaction, and an operation of broadcasting the target transaction and the metadata in a blockchain;
[0007] When the target transaction and the metadata are saved by a preset number of consensus nodes in the blockchain, a target block to be agreed upon is generated according to the metadata, and the target block is broadcast to the plurality of consensus nodes for consensus processing;
[0008] When a plurality of the consensus nodes reach a consensus on the target block, the target block is added to the blockchain;
[0009] In response to querying the target transaction through the blockchain, reading the metadata in the target block;
[0010] The target transaction is queried locally according to the metadata.
[0011] On the other hand, the embodiment of the present application also provides a blockchain data processing device, including:
[0012] An operation execution unit, configured to execute a data broadcast operation, wherein the data broadcast operation includes an operation of acquiring a target transaction, an operation of generating metadata of the target transaction, and an operation of broadcasting the target transaction and the metadata in a blockchain;
[0013] A block consensus unit, configured to generate a target block to be consensus based on the metadata when the target transaction and the metadata are saved by a preset number of consensus nodes in the blockchain, and broadcast the target block to the plurality of consensus nodes for consensus processing;
[0014] A block chain unit, configured to add the target block to the blockchain when a plurality of the consensus nodes reach a consensus on the target block;
[0015] a data reading unit, configured to read the metadata in the target block in response to querying the target transaction through the blockchain;
[0016] A transaction query unit is used to query the target transaction locally according to the metadata.
[0017] Optionally, the operation execution unit is further used for:
[0018] Enable multiple worker threads;
[0019] The data broadcast operation is performed using a plurality of the working threads.
[0020] Optionally, the operation execution unit is further used for:
[0021] Using each of the plurality of working threads, perform the following steps:
[0022] Acquire the target transaction;
[0023] generating the metadata of the target transaction;
[0024] The target transaction and the metadata are broadcasted in the blockchain.
[0025] Optionally, the plurality of working threads include a first working thread, a second working thread and a third working thread, and the operation execution unit is further used for:
[0026] Using the first working thread to acquire the target transaction, and sending the target transaction to the second working thread through the first working thread;
[0027] using the second working thread to generate the metadata of the target transaction, and sending the target transaction and the metadata to the third working thread through the second working thread;
[0028] The third worker thread is used to broadcast the target transaction and the metadata in the blockchain.
[0029] Optionally, the operation execution unit is further used for:
[0030] The target transaction and the metadata are broadcasted synchronously or sequentially in the blockchain using the third working thread.
[0031] Optionally, the operation execution unit is further used for:
[0032] Using the first working thread to acquire a new target transaction;
[0033] The new target transaction is sent to the second working thread through the first working thread.
[0034] Optionally, the operation execution unit is further used for:
[0035] Using the second working thread to generate metadata of the new target transaction;
[0036] The new target transaction and metadata of the new target transaction are sent to the third working thread through the second working thread.
[0037] Optionally, the operation execution unit is further used for:
[0038] The third working thread is used to broadcast the new target transaction and metadata of the new target transaction in the blockchain.
[0039] Optionally, the block consensus unit is further used to:
[0040] Enable consensus thread;
[0041] The consensus thread is used to generate a target block to be agreed upon according to the metadata, and the target block is broadcast to a plurality of consensus nodes through the consensus thread for consensus processing;
[0042] Among them, the consensus thread and the working thread do not affect each other.
[0043] Optionally, the operation execution unit is further used for:
[0044] Detecting whether the quantity of the target transaction reaches a preset quantity value, or whether the acquisition time of the target transaction reaches a preset time value;
[0045] When the number of the target transactions reaches the preset number value, or the acquisition time of the target transactions reaches the preset time value, the acquired target transactions are taken as a target transaction set;
[0046] Generate metadata of the target transaction set.
[0047] Optionally, the blockchain data processing device further includes:
[0048] An information receiving unit, configured to receive transaction confirmation information sent by the consensus node according to the target transaction, and metadata confirmation information sent according to the metadata;
[0049] A first determining unit, configured to determine that the target transaction is saved by the preset number of consensus nodes when the received transaction confirmation information reaches the preset number;
[0050] The second determination unit is used to determine that the metadata is saved by the preset number of consensus nodes when the received metadata confirmation information reaches the preset number.
[0051] On the other hand, an embodiment of the present application further provides an electronic device, including:
[0052] at least one processor;
[0053] at least one memory for storing at least one program;
[0054] When at least one of the programs is executed by at least one of the processors, the blockchain data processing method as described above is implemented.
[0055] On the other hand, an embodiment of the present application further provides a computer-readable storage medium, which stores a computer program executable by a processor, and the processor-executable computer program is used to implement the blockchain data processing method as described above when executed by the processor.
[0056] On the other hand, an embodiment of the present application also provides a computer program product, including a computer program or computer instructions, wherein the computer program or the computer instructions are stored in a computer-readable storage medium, and a processor of an electronic device reads the computer program or the computer instructions from the computer-readable storage medium, and the processor executes the computer program or the computer instructions, so that the electronic device performs the blockchain data processing method as described above.
[0057] The embodiment of the present application includes at least the following beneficial effects: before generating the target block to be agreed upon, a data broadcast operation is performed first, wherein the data broadcast operation includes an operation of obtaining the target transaction, an operation of generating metadata of the target transaction, and an operation of broadcasting the target transaction and metadata in the blockchain, so that the nodes in the blockchain can pre-save the target transaction and the metadata of the target transaction; when the target transaction and metadata are saved by a preset number of consensus nodes in the blockchain, it can be considered that the target transaction and metadata have been reliably broadcasted, that is, it can be considered that the target transaction and metadata have been successfully received by all honest nodes, at this time, the target block to be agreed upon is generated according to the metadata of the target transaction, and then the target block is broadcast to multiple consensus nodes for consensus processing, and when multiple consensus nodes reach a consensus on the target block, the target block can be added to the blockchain, thereby completing the on-chain operation of the target transaction. Since the target block is generated according to the metadata of the target transaction and does not contain the complete content of the target transaction, the amount of data in the target block can be reduced, so that the amount of information propagated in the network during the consensus process can be greatly reduced, thereby reducing the probability of network congestion, improving the speed and efficiency of consensus processing, and thus improving the throughput of the blockchain. In addition, although the target block contains the metadata of the target transaction, since the target transaction and the metadata of the target transaction have been broadcasted in the blockchain, the nodes in the blockchain can pre-save the target transaction and the metadata of the target transaction. Therefore, when querying the target transaction through the blockchain, by reading the metadata in the target block, the target transaction can be queried locally according to the metadata read, so it will not affect the normal use of the blockchain. In addition, since the target transaction and the metadata of the target transaction are first broadcasted in the blockchain, and then the target block is generated according to the metadata of the target transaction and the consensus process of the target block is performed, the broadcast process of the transaction information and the consensus process of the block can be decoupled, so that the consensus algorithm can be updated, thereby optimizing the processing power of the blockchain system.
[0058] Other features and advantages of the present application will be described in the following description, and partly become apparent from the description, or understood by practicing the present application. The purpose and other advantages of the present application can be realized and obtained through the structures particularly pointed out in the description and the drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0059] 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.
[0060] Figure 1 It is a schematic diagram of an implementation environment provided by an embodiment of the present application;
[0061] Figure 2 It is a schematic diagram of an application scenario provided by an embodiment of the present application;
[0062] Figure 3 is a schematic diagram of another implementation environment provided by an embodiment of the present application;
[0063] Figure 4 is a schematic diagram of another application scenario provided by an embodiment of the present application;
[0064] Figure 5 It is a flowchart of a blockchain data processing method provided by an embodiment of the present application;
[0065] Figure 6 is a schematic diagram of generating metadata of a target transaction provided by an embodiment of the present application;
[0066] Figure 7 It is a schematic diagram of a process of performing a data broadcast operation in a pipeline working mode provided by an embodiment of the present application;
[0067] Figure 8 It is a schematic diagram of a process of performing a data broadcast operation in a parallel working mode provided by an embodiment of the present application;
[0068] Fig. 9 It is a schematic diagram of a system architecture for executing a blockchain data processing method provided by a specific example of the present application;
[0069] Fig.10 It is a specific flow chart of the blockchain data processing method provided by a specific example of this application;
[0070] Fig.11 It is a schematic diagram of a blockchain data processing device provided in an embodiment of the present application;
[0071] Fig.12 It is a schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0072] The present application is further described below in conjunction with the accompanying drawings and specific embodiments. The described embodiments should not be regarded as limiting the present application, and all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present application.
[0073] In the following description, reference is made to “some embodiments”, which describe a subset of all possible embodiments, but it will be understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0074] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.
[0075] Before further describing the embodiments of the present application in detail, the nouns and terms involved in the embodiments of the present application are explained. The nouns and terms involved in the embodiments of the present application are subject to the following interpretations.
[0076] 1) Blockchain is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each 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. Blockchain can include public chain, alliance chain and private chain. Among them, public chain refers to a blockchain that anyone can enter the blockchain network at any time to read data, send data or compete for accounting; alliance chain refers to a blockchain jointly managed by several organizations or institutions; private chain refers to a blockchain with certain centralized control. The write right of the private chain account book is controlled by a certain organization or institution, and the access and use of data are strictly managed by permissions.
[0077] 2) Mempool is a container used to store unconfirmed transaction data in a blockchain node, which is equivalent to a waiting room for transactions that are not included in the confirmed blocks.
[0078] 3) Byzantine Fault Tolerance is the ability of a computer system to continue to operate even if some nodes fail. For any distributed system with multiple nodes, Byzantine Fault Tolerance refers to the ability of the distributed system to continue to work even if some nodes in the distributed system go down or fail.
[0079] 4) Consensus, which means that most people agree on a decision. In a blockchain system, a consensus is reached to allow distributed nodes to agree on the generation of a block and ensure the consistency of the entire blockchain.
[0080] 5) Reliable Broadcast is a broadcast method that applies Byzantine fault tolerance. For example, a sending node broadcasts a data v to other nodes. When other nodes receive the data v, they will further broadcast the data v. If the sending node receives confirmation information ACK of the data v from more than nf nodes, it means that the data v has been successfully received by all honest nodes, where f is the number of Byzantine nodes and n is the total number of nodes, n=3f+1.
[0081] In the current blockchain system, when a proposal node generates a new block, the proposal node will broadcast the new block in the blockchain, so that the consensus nodes in the blockchain use, for example, the Byzantine consensus algorithm to process the new block. When the consensus nodes in the blockchain reach a consensus on the new block, the proposal node can add the new block to the blockchain.
[0082] In the currently commonly used Byzantine consensus algorithms, such as the PBFT (Practical Byzantine FaultTolerance) consensus algorithm or the HotStuff consensus algorithm, the consensus nodes in the blockchain generally need to perform multiple rounds (such as 2 or 3 rounds) of information broadcasting to reach consensus on the consensus block. Since the consensus block often includes a large amount of transaction information, for example, for a busy blockchain, the consensus block may contain tens of thousands of transaction information. Therefore, during the process of multiple rounds of information broadcasting, the amount of information transmitted during the consensus process will be further amplified. Excessive amount of information can easily lead to network congestion, thereby reducing the speed and efficiency of consensus processing, and further reducing the throughput of the blockchain. Especially when the network bandwidth is small, it may even cause serious packet loss problems.
[0083] In order to reduce the probability of network congestion and thus improve the speed and efficiency of consensus processing, thereby improving the throughput of the blockchain, the embodiments of the present application provide a blockchain data processing method, a blockchain data processing device, an electronic device, a computer-readable storage medium, and a computer program product. Before generating a target block to be agreed upon, a data broadcast operation is first performed, wherein the data broadcast operation includes an operation of obtaining a target transaction, an operation of generating metadata of the target transaction, and an operation of broadcasting the target transaction and the metadata in the blockchain, so that the nodes in the blockchain can pre-save the target transaction and the metadata of the target transaction; when the target transaction and the metadata are saved by a preset number of consensus nodes in the blockchain, it can be considered that the target transaction and the metadata have been reliably broadcasted, that is, it can be considered that the target transaction and the metadata have been successfully received by all honest nodes. At this time, a target block to be agreed upon is generated based on the metadata of the target transaction, and then the target block is broadcast to multiple consensus nodes for consensus processing. When multiple consensus nodes reach a consensus on the target block, the target block can be added to the blockchain, thereby completing the on-chain operation of the target transaction. Since the target block is generated based on the metadata of the target transaction and does not contain the complete content of the target transaction, the data volume of the target block can be reduced, so that the amount of information propagated in the network during the consensus process can be greatly reduced, thereby reducing the probability of network congestion, improving the speed and efficiency of consensus processing, and thus improving the throughput of the blockchain. In addition, although the target block contains the metadata of the target transaction, since the target transaction and the metadata of the target transaction have been broadcasted in the blockchain first, the nodes in the blockchain can pre-save the target transaction and the metadata of the target transaction. Therefore, when querying the target transaction through the blockchain, by reading the metadata in the target block, the target transaction can be queried locally according to the metadata read, so it will not affect the normal use of the blockchain. In addition, since the target transaction and the metadata of the target transaction are first broadcasted in the blockchain, and then the target block is generated according to the metadata of the target transaction and the consensus process of the target block is performed, the broadcast process of the transaction information and the consensus process of the block can be decoupled, so that the consensus algorithm can be updated, thereby optimizing the processing capacity of the blockchain system.
[0084] Figure 1 Schematic diagram of an implementation environment provided by an embodiment of the present application. Figure 1, the implementation environment includes a first user terminal 101, a first server 102, and multiple second servers 103. The first user terminal 101 and the first server 102 are directly or indirectly connected through wired or wireless communication, and the first server 102 and the multiple second servers 103 are directly or indirectly connected to each other through wired or wireless communication. Among them, the first server 102 and the multiple second servers 103 are nodes in the blockchain, and this embodiment does not specifically limit this.
[0085] The first user terminal 101 may include, but is not limited to, smart phones, computers, intelligent voice interaction devices, smart home appliances, vehicle-mounted terminals, aircraft and other smart devices. Optionally, the first user terminal 101 may be installed with a blockchain client, through which operations such as adding transaction information to the blockchain or querying transaction information in the blockchain may be performed.
[0086] The first server 102 and the second server 103 can both be independent physical servers, or a server cluster or distributed system composed of multiple physical servers. They can also be cloud servers that provide 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.
[0087] In one embodiment, the first server 102 and the second server 103 can both be consensus nodes or proposal nodes in the blockchain. For example, when the first server 102 is a proposal node, all second servers 103 are consensus nodes; when any second server 103 is a proposal node, the first server 102 and the remaining second servers 103 are consensus nodes. The first server 102 and each second server 103 can include a consensus thread and multiple work threads. The consensus thread and each work thread, as well as all work threads, are independent of each other and do not affect each other.
[0088] Reference Figure 2As shown, in an application scenario, it is assumed that the first user terminal 101 is a smart phone, and the first user terminal 101 is installed with a blockchain client, the first server 102 is a proposal node, and all second servers 103 are consensus nodes. When the user initiates the operation of adding transaction information to the blockchain through the blockchain client in the first user terminal 101, in response to receiving the target transaction sent by the first user terminal 101 through the blockchain client, the first server 102 first generates metadata for the target transaction, and then broadcasts the target transaction and its metadata in the blockchain. When the target transaction and its metadata are saved by most of the second servers 103, that is, when the first server 102 reliably broadcasts the target transaction and its metadata, the first server 102 will generate a target block to be agreed upon based on the metadata, and then broadcast the target block to all second servers 103 for consensus processing. When these second servers 103 reach a consensus on the target block, the first server 102 adds the target block to the blockchain, completing the user's operation of adding transaction information to the blockchain. After the first server 102 adds the target block to the blockchain, in response to the user querying the target transaction through the blockchain, the first server 102 first reads the metadata of the target transaction recorded in the target block, and then queries the target transaction locally based on the read metadata. When the target transaction is queried, the first server 102 sends the queried target transaction to the blockchain client of the first user terminal 101, so that the user can browse the queried target transaction through the blockchain client in the first user terminal 101.
[0089] Figure 3 Schematic diagram of another implementation environment provided by the embodiment of the present application. Figure 3 , the implementation environment includes a second user terminal 301, a data storage 302, a third server 303 and a plurality of fourth servers 304, wherein the data storage 302 can be used as a memory pool of the third server 303, for temporarily storing the transaction information sent by the second user terminal 301. The second user terminal 301, the data storage 302 and the third server 303 are directly or indirectly connected in turn through wired or wireless communication, and the third server 303 and the plurality of fourth servers 304 are directly or indirectly connected to each other through wired or wireless communication. Among them, the third server 303 and the plurality of fourth servers 304 are nodes in the blockchain, and this embodiment does not specifically limit this.
[0090] The second user terminal 301 may include, but is not limited to, smart phones, computers, intelligent voice interaction devices, smart home appliances, vehicle-mounted terminals, aircraft and other smart devices. Optionally, the second user terminal 301 may be installed with a blockchain client, through which operations such as adding transaction information to the blockchain or querying transaction information in the blockchain may be performed.
[0091] The third server 303 and the fourth server 304 can be independent physical servers, or server clusters or distributed systems composed of multiple physical servers, or cloud servers that provide 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 networks, and big data and artificial intelligence platforms. In the third server 303 and each of the fourth servers 304, there can be a consensus thread and multiple work threads, and the consensus thread and each work thread, as well as all the work threads, are independent of each other and do not affect each other.
[0092] In one embodiment, the third server 303 and the fourth server 304 can both be consensus nodes or proposal nodes in the blockchain. For example, when the third server 303 is a proposal node, all fourth servers 304 are consensus nodes; when any fourth server 304 is a proposal node, the third server 303 and the remaining fourth servers 304 are consensus nodes.
[0093] Reference Figure 4As shown, in another application scenario, it is assumed that the second user terminal 301 is a computer, and the second user terminal 301 is installed with a blockchain client, the third server 303 is a proposal node, the data storage 302 is used as a memory pool of the third server 303, and all fourth servers 304 are consensus nodes. When the user initiates the operation of adding transaction information to the blockchain through the blockchain client in the second user terminal 301, the blockchain client in the second user terminal 301 will first send the user's transaction information to the data storage 302 for temporary storage. When the third server 303 detects that the amount of transaction information stored in the data storage 302 reaches the preset amount threshold, the third server 303 will obtain the target transaction from the multiple transaction information stored in the data storage 302, and then generate metadata for the target transaction, and then broadcast the target transaction and its metadata in the blockchain. When the target transaction and its metadata are saved by most of the fourth servers 304, that is, when the third server 303 reliably broadcasts the target transaction and its metadata, the third server 303 will generate a target block to be agreed upon based on the metadata, and then broadcast the target block to all fourth servers 304 for consensus processing. When these fourth servers 304 reach a consensus on the target block, the third server 303 adds the target block to the blockchain, completing the user's operation of adding transaction information to the blockchain. After the third server 303 adds the target block to the blockchain, in response to the user querying the target transaction through the blockchain, the third server 303 first reads the metadata of the target transaction recorded in the target block, and then queries the target transaction locally based on the read metadata. When the target transaction is queried, the third server 303 sends the queried target transaction to the blockchain client of the second user terminal 301, so that the user can browse the queried target transaction through the blockchain client in the second user terminal 301.
[0094] It should be noted that in each specific implementation of the present application, when it comes to the need to perform relevant processing based on the attribute information or attribute information set of the target object (such as a user, etc.) and other data related to the characteristics of the target object, the permission or consent of the target object will be obtained first, and the collection, use and processing of these data will comply with relevant laws, regulations and standards. In addition, when the embodiment of the present application needs to obtain the attribute information of the target object, the separate permission or separate consent of the target object will be obtained through a pop-up window or jump to a confirmation page. After clearly obtaining the separate permission or separate consent of the target object, the relevant data of the target object necessary for the normal operation of the embodiment of the present application is obtained.
[0095] Figure 5: is a flowchart of a blockchain data processing method provided in an embodiment of the present application. The blockchain data processing method can be executed by a server or by a terminal and a server. In the embodiment of the present application, the method is executed by a server as an example for explanation. Figure 5 , the blockchain data processing method includes but is not limited to steps 510 to 550.
[0096] Step 510: Execute a data broadcast operation, wherein the data broadcast operation includes an operation of obtaining a target transaction, an operation of generating metadata of the target transaction, and an operation of broadcasting the target transaction and the metadata in the blockchain.
[0097] In one embodiment, when a user performs an on-chain operation on a target transaction through a blockchain client, the proposal node will first perform a corresponding data broadcast operation to broadcast the target transaction to other consensus nodes in the blockchain, so as to facilitate subsequent consensus processing for the target transaction. In the process of performing the data broadcast operation, the proposal node will first obtain the target transaction, then generate the metadata of the target transaction, and then broadcast the target transaction and metadata in the blockchain. By broadcasting the target transaction and its metadata in the blockchain first, the nodes in the blockchain can pre-save the target transaction and the metadata of the target transaction. Then, when the target block to be consensus is generated later, it is not necessary to add the complete content of the target transaction in the target block, and only the metadata of the target transaction can be added in the target block. In this way, the amount of data in the target block can be reduced, so that the amount of information propagated in the network during the consensus process can be greatly reduced, thereby reducing the probability of network congestion, improving the speed and efficiency of consensus processing, and thus improving the throughput of the blockchain.
[0098] In one embodiment, after the proposal node obtains the target transaction to be uploaded to the blockchain sent by the user through the blockchain client, the proposal node can first temporarily store the target transaction in the local memory pool. When the number of target transactions in the memory pool reaches a preset number value, or the acquisition time of the target transaction reaches a preset time value, the proposal node obtains this batch of target transactions from the memory pool, and then generates metadata for this batch of target transactions, and then broadcasts this batch of target transactions and metadata for this batch of target transactions in the blockchain. By generating metadata and broadcasting operations for batches of target transactions, the data processing frequency of the proposal node can be reduced, thereby reducing the data processing pressure of the proposal node.
[0099] In one embodiment, when generating metadata of a target transaction, the proposal node may first detect whether the number of target transactions reaches a preset number value, or whether the acquisition time of the target transaction reaches a preset time value. When either of these two conditions is met, that is, when it is detected that the number of target transactions reaches the preset number value, or when it is detected that the acquisition time of the target transaction reaches the preset time value, the proposal node may use the target transactions acquired in the memory pool as a target transaction set, and then generate metadata for the target transaction set. When generating metadata for the target transaction set, the proposal node may perform a hash calculation on the target transaction set to obtain a hash value of the target transaction set, and then use the hash value of the target transaction set as metadata for the target transaction set. For example, refer to Figure 6 As shown, assuming that the preset number value is 32 and the preset time value is 300 milliseconds, then, when generating the metadata of the target transaction, the proposal node first detects whether the number of target transactions 620 in the memory pool 610 has reached 32, or whether the acquisition time of the target transactions 620 in the memory pool 610 has continued to reach 300 milliseconds. When it is detected that the number of target transactions 620 in the memory pool 610 has reached 32, or when it is detected that the acquisition time of the target transactions 620 in the memory pool 610 has continued to reach 300 milliseconds, the proposal node can use the acquired target transactions 620 in the memory pool 610 as the target transaction set 630, and then perform hash calculation on the target transaction set 630 to obtain the hash value 640 of the target transaction set 630, and then use the hash value 640 of the target transaction set 630 as the metadata 650 of the target transaction set 630.
[0100] In one embodiment, each node in the blockchain can run multiple parallel work threads, which can be expanded horizontally. These work threads can independently perform operations such as processing client requests, batch broadcasting of transactions and metadata, and storage of transactions and metadata after reliable broadcasts, and these work threads do not affect each other. By performing horizontal expansion, the parallel processing capabilities of these work threads can be effectively improved. When the proposal node is performing a data broadcast operation, the proposal node can enable multiple work threads, and then use these multiple work threads to perform the data broadcast operation. Among them, these work threads can use a parallel working mode or a pipeline working mode to perform the data broadcast operation, and can be appropriately selected according to the actual operation situation, which is not specifically limited here.
[0101] In one embodiment, when these worker threads use a pipeline working mode to perform a data broadcast operation, the previous worker thread will pass its output result to the next worker thread, so that the next worker thread uses the output result of the previous worker thread as input content. For example, assuming that these multiple worker threads include a first worker thread, a second worker thread, and a third worker thread, then when the proposal node performs a data broadcast operation, it can first use the first worker thread to obtain the target transaction, and send the target transaction to the second worker thread through the first worker thread, and then use the second worker thread to generate metadata for the target transaction, and send the target transaction and metadata to the third worker thread through the second worker thread, and then use the third worker thread to broadcast the target transaction and metadata in the blockchain. In this way, these worker threads can sequentially perform the operations of obtaining the target transaction, generating metadata for the target transaction, and broadcasting the target transaction and metadata in the blockchain in a pipeline manner, thereby effectively improving the processing efficiency of the proposal node. For example Figure 7 As shown, assuming that the first worker thread 710, the second worker thread 720 and the third worker thread 730 are running in the proposal node, when the proposal node performs a data broadcast operation, the first worker thread 710 will first obtain the target transaction from the memory pool, and then forward the target transaction to the second worker thread 720; after the second worker thread 720 receives the target transaction, the second worker thread 720 performs a hash calculation on the target transaction to obtain the metadata of the target transaction, and then forwards the target transaction and its metadata to the third worker thread 730; when the third worker thread 730 receives the target transaction and its metadata, the third worker thread 730 broadcasts the target transaction and its metadata in the blockchain.
[0102] In one embodiment, when a third working thread is used to broadcast a target transaction and metadata in a blockchain, the third working thread may be used to broadcast the target transaction and metadata in the blockchain simultaneously or sequentially. For example, when a third working thread is used to broadcast a target transaction and metadata in a blockchain simultaneously, the third working thread may be used to send the target transaction and metadata simultaneously in one broadcast operation; when a third working thread is used to broadcast a target transaction and metadata in the blockchain sequentially, the third working thread may be used to first broadcast any one of the target transaction and metadata in the blockchain, and after the broadcast is completed, the remaining one of the target transaction and metadata may be broadcast in the blockchain.
[0103] In one embodiment, when the third worker thread includes a first sub-worker thread and a second sub-worker thread, when the third worker thread is used to broadcast the target transaction and metadata in the blockchain, the first sub-worker thread may be used to broadcast the target transaction in the blockchain at the first moment, and the second sub-worker thread may be used to broadcast the metadata in the blockchain at the first moment, that is, the first sub-worker thread and the second sub-worker thread are sub-worker threads running synchronously. Alternatively, the first sub-worker thread may be used to broadcast the target transaction in the blockchain at the first moment, and the second sub-worker thread may be used to broadcast the metadata in the blockchain at the second moment, that is, the first sub-worker thread and the second sub-worker thread are sub-worker threads running asynchronously.
[0104] In one embodiment, after the proposal node sends the target transaction to the second work thread through the first work thread, the proposal node can also use the first work thread to obtain a new target transaction, and then send the new target transaction to the second work thread through the first work thread. Similarly, after the proposal node sends the target transaction and metadata to the third work thread through the second work thread, the proposal node can also use the second work thread to generate metadata for the new target transaction, and then send the new target transaction and the metadata of the new target transaction to the third work thread through the second work thread; and after the proposal node uses the third work thread to broadcast the target transaction and metadata in the blockchain, the proposal node can also use the third work thread to broadcast the new target transaction and the metadata of the new target transaction in the blockchain. That is to say, after each work thread of the proposal node completes its current operation task, it can execute the next round of pipeline operations, and so on, so as to effectively improve the processing efficiency of the node.
[0105] In one embodiment, when these worker threads use the parallel working mode to perform data broadcast operations, each of these worker threads will independently perform the operations of obtaining the target transaction, generating metadata of the target transaction, and broadcasting the target transaction and metadata in the blockchain, thereby effectively improving the processing efficiency of the proposal node. Figure 8As shown, assuming that the fourth worker thread 810, the fifth worker thread 820 and the sixth worker thread 830 are running in the proposal node, wherein the fourth worker thread 810, the fifth worker thread 820 and the sixth worker thread 830 are running in parallel, then the fourth worker thread 810 can sequentially perform the operations of obtaining the target transaction, generating the metadata of the target transaction, and broadcasting the target transaction and the metadata in the blockchain at the first moment; the fifth worker thread 820 can sequentially perform the operations of obtaining the target transaction, generating the metadata of the target transaction, and broadcasting the target transaction and the metadata in the blockchain at the second moment; the sixth worker thread 830 can sequentially perform the operations of obtaining the target transaction, generating the metadata of the target transaction, and broadcasting the target transaction and the metadata in the blockchain at the third moment. The fourth worker thread 810, the fifth worker thread 820 and the sixth worker thread 830 are independent of each other and do not affect each other.
[0106] In one embodiment, when each of these worker threads is used to broadcast the target transaction and metadata in the blockchain, these worker threads can be used to broadcast the target transaction and metadata in the blockchain simultaneously or sequentially. For example, when these worker threads are used to broadcast the target transaction and metadata in the blockchain simultaneously, these worker threads can be used to send the target transaction and metadata simultaneously in one broadcast operation; when these worker threads are used to broadcast the target transaction and metadata in the blockchain sequentially, these worker threads can be used to first broadcast any one of the target transaction and metadata in the blockchain, and after completing the broadcast, the remaining one of the target transaction and metadata can be broadcast in the blockchain.
[0107] Step 520: When the target transaction and metadata are saved by a preset number of consensus nodes in the blockchain, a target block to be agreed upon is generated based on the metadata, and the target block is broadcast to multiple consensus nodes for consensus processing.
[0108] In one embodiment, after the proposal node performs the data broadcast operation, when the consensus node in the blockchain receives the target transaction and metadata broadcast by the proposal node, the consensus node will return the corresponding confirmation information to the proposal node, and the confirmation information is used to indicate that the consensus node has received the corresponding information. That is, when the proposal node receives the transaction confirmation information and metadata confirmation information returned by a consensus node, it can be confirmed that the consensus node has received and saved the target transaction and metadata. Therefore, by counting the confirmation information returned by the consensus node, the number of consensus nodes that have received and saved the target transaction and metadata can be determined. In this case, after determining that the target transaction and metadata have been saved by a preset number of consensus nodes in the blockchain, the proposal node can consider that the target transaction and metadata have been reliably broadcasted, that is, it can be considered that the target transaction and metadata have been successfully received by all honest nodes in the blockchain. At this time, the proposal node can generate a target block to be consensus based on the metadata, and then broadcast the target block to multiple consensus nodes for consensus processing.
[0109] In one embodiment, after the proposal node performs the data broadcast operation, the proposal node can receive transaction confirmation information sent by each consensus node in the blockchain based on the target transaction, and metadata confirmation information sent based on the metadata. When the received transaction confirmation information reaches a preset number, it can be determined that the target transaction has been saved by a preset number of consensus nodes; when the received metadata confirmation information reaches a preset number, it can be determined that the metadata has been saved by a preset number of consensus nodes.
[0110] In one embodiment, the preset number can be determined based on the number of all nodes in the blockchain and the number of Byzantine nodes in the blockchain. For example, assuming that the number of all nodes in the blockchain is n, the number of Byzantine nodes in the blockchain is f, where n=3f+1, then the preset number can be set to a number greater than nf and less than or equal to n. The preset number can be appropriately selected according to the actual application situation and is not specifically limited here. In this case, when it is determined that the target transaction and metadata are saved by the consensus nodes in the blockchain that are greater than nf and less than or equal to n, it can be considered that the target transaction and metadata have been reliably broadcast.
[0111] In one embodiment, when the proposal node generates the target block to be agreed upon according to the metadata and broadcasts the target block to multiple consensus nodes for consensus processing, the consensus thread can be enabled first, and then the consensus thread is used to generate the target block to be agreed upon according to the metadata, and the target block is broadcast to multiple consensus nodes for consensus processing through the consensus thread, wherein the consensus thread and the working thread do not affect each other, that is, the consensus thread and the working thread can be in a parallel running relationship with each other, when the consensus thread executes the generation of the target block and broadcasts the consensus, the working thread can synchronously execute operations such as obtaining the target transaction, generating the metadata of the target transaction, and broadcasting the target transaction and the metadata in the blockchain. In addition, since the target block is generated by the consensus thread according to the metadata of the target transaction, the target block does not contain the complete content of the target transaction, so the data volume of the target block can be reduced, so that the amount of information transmitted in the network during the consensus process can be greatly reduced, thereby reducing the probability of network congestion, improving the speed and efficiency of consensus processing, and thus improving the throughput of the blockchain.
[0112] Step 530: When multiple consensus nodes reach a consensus on the target block, the target block is added to the blockchain.
[0113] In one embodiment, when multiple consensus nodes in the blockchain reach a consensus on the target block, the proposal node will receive a notification message from the blockchain indicating that the target block has been accepted. At this time, the proposal node can add the target block to the blockchain, thereby realizing on-chain processing for the target transaction.
[0114] It should be noted that the proposal node and other consensus nodes in the blockchain will save a copy of the blockchain. When the blockchain reaches a consensus on the target block, the proposal node and other consensus nodes in the blockchain will add the target block to their saved copies of the blockchain to implement the operation of adding the target block to the blockchain. In this way, users can query the information in the blockchain through any node, thereby providing convenience for information query.
[0115] Step 540: In response to querying the target transaction through the blockchain, read the metadata in the target block.
[0116] In one embodiment, when the proposal node adds the target block to the blockchain, it saves the information in the target block to the corresponding database. Therefore, when the user queries the target transaction through the blockchain, in response to the user's query operation on the target transaction through the blockchain, the proposal node can read the metadata in the target block from the database, so that the subsequent steps can query the target transaction in the local database according to the metadata in the target block, thereby achieving the purpose of querying on-chain data.
[0117] It should be noted that although the target block contains the metadata of the target transaction, the target transaction and the metadata of the target transaction have been broadcasted in the blockchain by the proposal node, so that the nodes in the blockchain have pre-saved the target transaction and the metadata of the target transaction. Therefore, when the user queries the target transaction through the blockchain, by reading the metadata in the target block, the target transaction can be queried locally on the proposal node based on the metadata read, so it will not affect the normal use of the blockchain. In addition, since the target transaction and the metadata of the target transaction are first broadcasted in the blockchain, and then the target block is generated based on the metadata of the target transaction and the consensus process of the target block is performed, the broadcast process of the transaction information and the consensus process of the block can be decoupled, so that the consensus algorithm can be updated, thereby optimizing the processing power of the blockchain system.
[0118] In one embodiment, since each node in the blockchain pre-saves the target transaction broadcasted by the proposal node and the metadata of the target transaction, the user can query the target transaction through any node in the blockchain. When the user queries the target transaction through any node in the blockchain, the node can first search for the target block in the locally saved blockchain copy, then read the metadata in the target block, and then query the target transaction locally at the node based on the read metadata.
[0119] Step 550: Query the target transaction locally according to the metadata.
[0120] In one embodiment, when the proposal node finds the target block in its locally saved copy of the blockchain and reads the metadata of the target transaction in the target block, it can query the target transaction in the local database of the proposal node based on the metadata, thereby completing the user's query operation on the target transaction.
[0121] In this embodiment, by using the blockchain data processing method including the previous steps 510 to 550, before generating the target block to be agreed upon, a data broadcast operation is first performed, wherein the data broadcast operation includes an operation of obtaining the target transaction, an operation of generating metadata of the target transaction, and an operation of broadcasting the target transaction and metadata in the blockchain, so that the nodes in the blockchain can pre-save the target transaction and the metadata of the target transaction; when the target transaction and the metadata are saved by a preset number of consensus nodes in the blockchain, it can be considered that the target transaction and the metadata have been reliably broadcasted, that is, it can be considered that the target transaction and the metadata have been successfully received by all honest nodes. At this time, the target block to be agreed upon is generated based on the metadata of the target transaction, and then the target block is broadcast to multiple consensus nodes for consensus processing. When multiple consensus nodes reach a consensus on the target block, the target block can be added to the blockchain, thereby completing the on-chain operation of the target transaction. Since the target block is generated based on the metadata of the target transaction and does not contain the complete content of the target transaction, the data volume of the target block can be reduced, so that the amount of information propagated in the network during the consensus process can be greatly reduced, thereby reducing the probability of network congestion, improving the speed and efficiency of consensus processing, and thus improving the throughput of the blockchain. In addition, although the target block contains the metadata of the target transaction, since the target transaction and the metadata of the target transaction have been broadcasted in the blockchain first, the nodes in the blockchain can pre-save the target transaction and the metadata of the target transaction. Therefore, when querying the target transaction through the blockchain, by reading the metadata in the target block, the target transaction can be queried locally according to the metadata read, so it will not affect the normal use of the blockchain. In addition, since the target transaction and the metadata of the target transaction are first broadcasted in the blockchain, and then the target block is generated according to the metadata of the target transaction and the consensus process of the target block is performed, the broadcast process of the transaction information and the consensus process of the block can be decoupled, so that the consensus algorithm can be updated, thereby optimizing the processing capacity of the blockchain system.
[0122] The following is a detailed description of the blockchain data processing method provided in the embodiment of the present application with specific examples.
[0123] Reference Fig. 9 As shown, Fig. 9 This is a schematic diagram of the system architecture for executing a blockchain data processing method provided by a specific example of this application. Fig. 9In the system architecture, a plurality of user clients 910 and a blockchain system 920 are included, and any user client 910 can access the blockchain system 920. The blockchain system 920 includes a first node 921, a second node 922, a third node 923, and a fourth node 924, and the first node 921, the second node 922, the third node 923, and the fourth node 924 are interconnected. In the first node 921, the second node 922, the third node 923, and the fourth node 924, there is a consensus thread 930 and a plurality of work threads 940, and the consensus thread 930 and each work thread 940, and all the work threads 940, are independent of each other and do not affect each other.
[0124] When executing the blockchain data processing method provided in the embodiment of the present application, the system architecture mainly includes four processing parts: transaction reception, reliable broadcasting, consensus block generation and transaction query.
[0125] In the transaction receiving and processing part, each of the first node 921, the second node 922, the third node 923 and the fourth node 924 will detect whether the user client 910 has sent the transaction information. Specifically, each of the working threads 940 in these nodes will detect whether the user client 910 has sent the transaction information. When any working thread 940 detects that the user client 910 has sent the transaction information, the working thread 940 will temporarily store the transaction information in the local memory pool. At this time, other working threads 940 will also perform operations such as receiving the transaction information sent by the user client 910, temporarily storing the transaction information in the memory pool, generating metadata, broadcasting the transaction information and metadata without affecting each other, and the consensus thread 930 will also perform block consensus operations without affecting each other. When the transaction information temporarily stored in the memory pool reaches a preset number value (for example, 32, etc.), or the acquisition time of the target transaction reaches a preset time value (for example, 300 milliseconds, etc.), the worker thread 940 performs hash processing on this batch of transaction information (i.e., the target transaction), generates metadata for this batch of transaction information, and then signs and broadcasts this batch of transaction information and its metadata, so that this batch of transaction information and its metadata can be received and saved by other nodes. Among them, the preset number value and the preset time value can be appropriately selected according to the actual application situation. In addition, when a worker thread 940 in a node receives this batch of transaction information and its metadata, the worker thread 940 in the node will reply to the node that broadcasts this batch of transaction information and its metadata with corresponding confirmation information, and continue to broadcast this batch of transaction information and its metadata to the remaining other nodes.
[0126] In the reliable broadcast processing part, when the worker thread 940 broadcasts this batch of transaction information and its metadata to other nodes, the worker thread 940 will detect the confirmation information replied by the node that received this batch of transaction information and its metadata. When the worker thread 940 detects that nf confirmation messages have been received (n is the total number of nodes, f is the number of Byzantine nodes, n = 3f + 1), the worker thread 940 can consider that this batch of transaction information and its metadata have been reliably received by all honest nodes (i.e., consensus nodes that work normally), that is, each honest node has saved this batch of transaction information and its metadata. Among them, the sending node of this batch of transaction information and all honest nodes will save the reliably broadcast information (i.e., this batch of transaction information and its metadata) to their respective local databases (such as key-value pair storage databases, etc.).
[0127] In the consensus block processing part, when the worker thread 940 confirms that this batch of transaction information and its metadata have been reliably received by all honest nodes, the worker thread 940 will pass the metadata of this batch of transaction information to the local consensus thread 930. After the consensus thread 930 receives the metadata of this batch of transaction information, the consensus thread 930 first generates a blank block, and then fills the metadata of this batch of transaction information into the blank block to obtain the target block to be agreed upon. Then, the node signs the target block and broadcasts the signed target block to other nodes for consensus processing. At this time, the consensus threads 930 of other nodes will detect whether the target block is received. When the consensus threads 930 of other nodes receive the target block, these nodes will perform consensus voting on the target block through their own consensus threads 930. After 2 to 3 rounds of voting (the specific number of voting rounds and voting process are determined according to the specific consensus algorithm actually used, and are not specifically limited here), when these nodes reach a consensus on the target block, these nodes will reply block confirmation information to the proposal node that proposed the target block. When the proposal node receives the block confirmation information, it can be considered that the target block has been confirmed, so the proposal node can add the target block to the blockchain.
[0128] In the transaction query processing part, since the target block added to the blockchain only contains the metadata of this batch of transaction information, and does not contain the complete content of this batch of transaction information itself, but since this batch of transaction information and its metadata have been broadcast to other nodes for storage, when the user queries this batch of transaction information from the blockchain through a certain node, the metadata of this batch of transaction information can be read in the target block that has been added to the blockchain first, and then the batch of transaction information can be queried in the local database of the node based on the read metadata.
[0129] In addition, for multiple worker threads 940 in each node, these worker threads 940 can run in parallel, so that horizontal expansion can be performed, that is, these worker threads 940 can independently perform operations such as processing client requests, batch broadcasting of transactions and metadata, and storage of transactions and metadata after reliable broadcast, and these worker threads 940 do not affect each other. By performing horizontal expansion, the parallel processing capability of these worker threads 940 can be effectively improved.
[0130] Reference Fig.10 As shown, Fig.10 This is a specific flow chart of a blockchain data processing method provided by a specific example of this application. Fig.10 In the present invention, the blockchain data processing method may include but is not limited to steps 1001 to 1013.
[0131] Step 1001: In response to a user performing an operation of adding a target transaction to a blockchain, multiple working threads are enabled.
[0132] Step 1002: Determine whether these working threads are in parallel working mode or pipeline working mode. If these working threads are in parallel working mode, execute step 1003; if these working threads are in pipeline working mode, execute step 1004.
[0133] Step 1003: Use each of these working threads to perform operations of obtaining the target transaction, generating metadata of the target transaction, and broadcasting the target transaction and metadata in the blockchain, and then execute step 1007.
[0134] In one embodiment, when generating metadata of a target transaction, it is possible to first detect whether the number of target transactions reaches a preset number value, or whether the acquisition time of the target transactions reaches a preset time value. When the number of target transactions reaches the preset number value, or the acquisition time of the target transactions reaches the preset time value, the acquired target transactions are taken as a target transaction set, and then metadata of the target transaction set is generated.
[0135] In one embodiment, the operation of broadcasting the target transaction and metadata in the blockchain may be an operation of broadcasting the target transaction and metadata in the blockchain simultaneously, or an operation of broadcasting the target transaction and metadata in the blockchain sequentially, which is not specifically limited herein.
[0136] Step 1004: Use the first working thread to obtain the target transaction, and send the target transaction to the second working thread through the first working thread.
[0137] In one embodiment, after the target transaction is sent to the second working thread through the first working thread, the first working thread may also be used to obtain a new target transaction, and the new target transaction may be sent to the second working thread through the first working thread.
[0138] Step 1005: Generate metadata of the target transaction using the second working thread, and send the target transaction and the metadata to the third working thread through the second working thread.
[0139] In one embodiment, after sending the target transaction and metadata to the third working thread through the second working thread, the second working thread can also be used to generate metadata of a new target transaction, and the new target transaction and the metadata of the new target transaction can be sent to the third working thread through the second working thread.
[0140] Step 1006: Use a third working thread to broadcast the target transaction and metadata in the blockchain synchronously or sequentially, and then execute step 1007.
[0141] In one embodiment, after the target transaction and metadata are broadcasted in the blockchain by the third worker thread, the new target transaction and metadata of the new target transaction can also be broadcasted in the blockchain by the third worker thread. It should be noted that these worker threads are independent of each other and do not affect each other, so the parallel processing capability of these worker threads can be effectively improved, thereby improving the processing efficiency of the blockchain, and further improving the throughput of the blockchain.
[0142] Step 1007: Receive transaction confirmation information sent by the consensus node based on the target transaction, and metadata confirmation information sent based on the metadata.
[0143] Step 1008: When the received transaction confirmation information and metadata confirmation information reach a preset number, it is determined that the target transaction and its metadata are saved by a preset number of consensus nodes.
[0144] Step 1009: Enable the consensus thread, and use the consensus thread to generate a target block to be agreed upon based on the metadata.
[0145] In one embodiment, the consensus thread and the working thread are independent of each other and do not affect each other.
[0146] Step 1010: Broadcast the target block to multiple consensus nodes through the consensus thread for consensus processing.
[0147] Step 1011: When multiple consensus nodes reach a consensus on the target block, the target block is added to the blockchain.
[0148] Step 1012: In response to querying the target transaction through the blockchain, reading metadata in the target block.
[0149] Step 1013: Query the target transaction locally according to the metadata.
[0150] In this embodiment, through the blockchain data processing method of the above steps 1001 to 1013, before generating the target block to be agreed upon, a data broadcast operation is first performed, wherein the data broadcast operation includes an operation of obtaining a target transaction, an operation of generating metadata of the target transaction, and an operation of broadcasting the target transaction and metadata in the blockchain, so that the nodes in the blockchain can pre-save the target transaction and the metadata of the target transaction; when the target transaction and the metadata are saved by a preset number of consensus nodes in the blockchain, it can be considered that the target transaction and the metadata have been reliably broadcasted, that is, it can be considered that the target transaction and the metadata have been successfully received by all honest nodes. At this time, the target block to be agreed upon is generated according to the metadata of the target transaction, and then the target block is broadcast to multiple consensus nodes for consensus processing. When multiple consensus nodes reach a consensus on the target block, the target block can be added to the blockchain, thereby completing the on-chain operation of the target transaction. Since the target block is generated based on the metadata of the target transaction and does not contain the complete content of the target transaction, the data volume of the target block can be reduced, so that the amount of information propagated in the network during the consensus process can be greatly reduced, thereby reducing the probability of network congestion, improving the speed and efficiency of consensus processing, and thus improving the throughput of the blockchain. In addition, although the target block contains the metadata of the target transaction, since the target transaction and the metadata of the target transaction have been broadcasted in the blockchain first, the nodes in the blockchain can pre-save the target transaction and the metadata of the target transaction. Therefore, when querying the target transaction through the blockchain, by reading the metadata in the target block, the target transaction can be queried locally according to the metadata read, so it will not affect the normal use of the blockchain. In addition, since the target transaction and the metadata of the target transaction are first broadcasted in the blockchain, and then the target block is generated according to the metadata of the target transaction and the consensus process of the target block is performed, the broadcast process of the transaction information and the consensus process of the block can be decoupled, so that the consensus algorithm can be updated, thereby optimizing the processing capacity of the blockchain system.
[0151] The following are some practical examples to illustrate the application scenarios of the embodiments of the present application.
[0152] It should be noted that the blockchain data processing method provided in the embodiment of the present application can be applied to different application scenarios such as transaction processing for game resources or transaction processing for digital collections. The transaction processing scenarios for game resources and the transaction processing scenarios for digital collections are used as examples for explanation below.
[0153] Scene 1
[0154] The blockchain data processing method provided in the embodiment of the present application can be applied to the transaction processing scenario for game resources. For example, when player A and player B trade game resources, player A initiates the operation of transferring game resources to player B through the blockchain client. In response to receiving the target transaction for transferring game resources to player B sent by player A through the blockchain client, the game server first generates metadata for the target transaction, and then broadcasts the target transaction and its metadata in the blockchain. When the target transaction and its metadata are saved by most consensus nodes, that is, when the game server reliably broadcasts the target transaction and its metadata, the game server generates a target block to be agreed upon based on the metadata, and then broadcasts the target block to all consensus nodes for consensus processing. When these consensus nodes reach a consensus on the target block, the game server adds the target block to the blockchain, completing the operation of player A transferring game resources to player B. After the game server adds the target block to the blockchain, in response to player B's query of the target transaction through the blockchain, the game server first reads the metadata of the target transaction recorded in the target block, and then queries the target transaction locally based on the read metadata. When the target transaction is queried, the game server sends the queried target transaction to player B's blockchain client, so that player B can browse the queried target transaction through the blockchain client.
[0155] Scene 2
[0156] The blockchain data processing method provided in the embodiment of the present application can also be applied to the transaction processing scenario for digital collections. For example, when collector A and collector B trade digital collections, collector A initiates the operation of transferring the digital collection to collector B through the blockchain client. In response to receiving the target transaction for transferring the digital collection to collector B sent by collector A through the blockchain client, the collection server first generates metadata for the target transaction, and then broadcasts the target transaction and its metadata in the blockchain. When the target transaction and its metadata are saved by most consensus nodes, that is, when the collection server reliably broadcasts the target transaction and its metadata, the collection server generates a target block to be agreed upon based on the metadata, and then broadcasts the target block to all consensus nodes for consensus processing. When these consensus nodes reach a consensus on the target block, the collection server adds the target block to the blockchain, completing the operation of collector A transferring the digital collection to collector B. After the collection server adds the target block to the blockchain, in response to collector B's query of the target transaction through the blockchain, the collection server first reads the metadata of the target transaction recorded in the target block, and then queries the target transaction locally based on the read metadata. When the target transaction is queried, the collection server sends the queried target transaction to collector B's blockchain client, so that collector B can browse the queried target transaction through the blockchain client.
[0157] It is to be understood that, although the steps in the above-mentioned various flow charts are shown in sequence according to the indication of the arrows, these steps are not necessarily performed in sequence according to the order indicated by the arrows. 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 charts 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 sequence, but can be performed in turn or alternately with at least a portion of the steps or stages in other steps or other steps.
[0158] Reference Fig.11 The embodiment of the present application further discloses a blockchain data processing device, which can implement the blockchain data processing method in the previous embodiment. The blockchain data processing device 1100 includes:
[0159] An operation execution unit 1110, configured to execute a data broadcast operation, wherein the data broadcast operation includes an operation of acquiring a target transaction, an operation of generating metadata of the target transaction, and an operation of broadcasting the target transaction and the metadata in a blockchain;
[0160] The block consensus unit 1120 is used to generate a target block to be consensus based on the metadata when the target transaction and metadata are saved by a preset number of consensus nodes in the blockchain, and broadcast the target block to multiple consensus nodes for consensus processing;
[0161] The block chain unit 1130 is used to add the target block to the blockchain when multiple consensus nodes reach a consensus on the target block;
[0162] A data reading unit 1140 is used to read metadata in a target block in response to querying the target transaction through the blockchain;
[0163] The transaction query unit 1150 is used to query the target transaction locally according to the metadata.
[0164] In one embodiment, the operation execution unit 1110 is further configured to:
[0165] Enable multiple worker threads;
[0166] Multiple worker threads are used to perform data broadcast operations.
[0167] In one embodiment, the operation execution unit 1110 is further configured to:
[0168] With each of the multiple worker threads, perform the following steps:
[0169] Get the target transaction;
[0170] Generate metadata of the target transaction;
[0171] Broadcast the target transaction and metadata in the blockchain.
[0172] In one embodiment, the multiple working threads include a first working thread, a second working thread, and a third working thread, and the operation execution unit 1110 is further used to:
[0173] Using a first working thread to acquire a target transaction, and sending the target transaction to a second working thread through the first working thread;
[0174] Generate metadata of the target transaction using the second working thread, and send the target transaction and the metadata to the third working thread through the second working thread;
[0175] A third worker thread is used to broadcast the target transaction and metadata in the blockchain.
[0176] In one embodiment, the operation execution unit 1110 is further configured to:
[0177] A third working thread is used to broadcast the target transaction and metadata in the blockchain synchronously or sequentially.
[0178] In one embodiment, the operation execution unit 1110 is further configured to:
[0179] Using the first working thread to obtain a new target transaction;
[0180] The new target transaction is sent to the second working thread through the first working thread.
[0181] In one embodiment, the operation execution unit 1110 is further configured to:
[0182] Using a second working thread to generate metadata of a new target transaction;
[0183] The new target transaction and metadata of the new target transaction are sent to the third working thread through the second working thread.
[0184] In one embodiment, the operation execution unit 1110 is further configured to:
[0185] A third working thread is used to broadcast the new target transaction and metadata of the new target transaction in the blockchain.
[0186] In one embodiment, the block consensus unit 1120 is further used to:
[0187] Enable consensus thread;
[0188] The consensus thread is used to generate the target block to be agreed upon based on the metadata, and the target block is broadcast to multiple consensus nodes through the consensus thread for consensus processing;
[0189] Among them, the consensus thread and the working thread do not affect each other.
[0190] In one embodiment, the operation execution unit 1110 is further configured to:
[0191] Detecting whether the quantity of target transactions reaches a preset quantity value, or whether the acquisition time of the target transactions reaches a preset time value;
[0192] When the number of target transactions reaches a preset number value, or the acquisition time of the target transactions reaches a preset time value, the acquired target transactions are taken as a target transaction set;
[0193] Generate metadata for the target transaction collection.
[0194] In one embodiment, the blockchain data processing device 1100 further includes:
[0195] An information receiving unit, used to receive transaction confirmation information sent by the consensus node according to the target transaction, and metadata confirmation information sent according to the metadata;
[0196] A first determining unit, configured to determine that a target transaction is saved by a preset number of consensus nodes when the received transaction confirmation information reaches a preset number;
[0197] The second determination unit is used to determine that the metadata is saved by a preset number of consensus nodes when the received metadata confirmation information reaches a preset number.
[0198] It should be noted that since the blockchain data processing device 1100 of this embodiment can implement the blockchain data processing method of the previous embodiment, the blockchain data processing device 1100 of this embodiment and the blockchain data processing method of the previous embodiment have the same technical principles and the same beneficial effects. In order to avoid repetition of content, they will not be repeated here.
[0199] Reference Fig.12 The embodiment of the present application further discloses an electronic device, the electronic device 1200 comprising:
[0200] at least one processor 1201;
[0201] At least one memory 1202, used to store at least one program;
[0202] When at least one program is executed by at least one processor 1201, the blockchain data processing method as described above is implemented.
[0203] An embodiment of the present application also discloses a computer-readable storage medium, which stores a computer program executable by a processor. When the computer program executable by the processor is executed by the processor, it is used to implement the blockchain data processing method as described above.
[0204] An embodiment of the present application also discloses a computer program product, including a computer program or computer instructions, wherein the computer program or computer instructions are stored in a computer-readable storage medium, and a processor of an electronic device reads the computer program or computer instructions from the computer-readable storage medium, and the processor executes the computer program or computer instructions, so that the electronic device executes the blockchain data processing method as described above.
[0205] 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 interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein, for example. 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.
[0206] 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.
[0207] 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 merely schematic. For example, the division of the 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.
[0208] In the embodiments of the present application, the term "module" or "unit" refers to a computer program or a part of a computer program with a predetermined function, and works together with other related parts to achieve a predetermined goal, and can be implemented in whole or in part by using software, hardware (such as processing circuits or memories) or a combination thereof. Similarly, a processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be part of an overall module or unit that includes the function of the module or unit.
[0209] 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.
[0210] 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.
[0211] 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 method described in each embodiment 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.
[0212] The step numbers in the above method embodiment are only provided for the convenience of explanation and description, and no limitation is imposed on the order of the steps. The execution order of each step in the embodiment can be adaptively adjusted according to the understanding of those skilled in the art.
Claims
1. A blockchain data processing method, characterized in that: The following steps are involved: Performing a data broadcast operation, wherein the data broadcast operation includes an operation of obtaining a target transaction, an operation of generating metadata of the target transaction, and an operation of broadcasting the target transaction and the metadata in a blockchain; When the target transaction and the metadata are saved by a preset number of consensus nodes in the blockchain, a target block to be agreed upon is generated according to the metadata, and the target block is broadcast to the plurality of consensus nodes for consensus processing; When a plurality of the consensus nodes reach a consensus on the target block, the target block is added to the blockchain; In response to querying the target transaction through the blockchain, reading the metadata in the target block; The target transaction is queried locally according to the metadata.
2. The method according to claim 1, characterized in that The performing of the data broadcast operation comprises: Enable multiple worker threads; The data broadcast operation is performed using a plurality of the working threads.
3. The method according to claim 2, characterized in that The adopting a plurality of the working threads to perform the data broadcast operation comprises: Using each of the plurality of working threads, perform the following steps: Acquire the target transaction; generating the metadata of the target transaction; The target transaction and the metadata are broadcasted in the blockchain.
4. The method according to claim 2, characterized in that: The plurality of working threads include a first working thread, a second working thread, and a third working thread, and the using the plurality of working threads to perform the data broadcasting operation includes: Using the first working thread to acquire the target transaction, and sending the target transaction to the second working thread through the first working thread; using the second working thread to generate the metadata of the target transaction, and sending the target transaction and the metadata to the third working thread through the second working thread; The third worker thread is used to broadcast the target transaction and the metadata in the blockchain.
5. The method according to claim 4, characterized in that The adopting the third working thread to broadcast the target transaction and the metadata in the blockchain includes: The target transaction and the metadata are broadcasted synchronously or sequentially in the blockchain using the third working thread.
6. The method according to claim 4, characterized in that After sending the target transaction to the second working thread through the first working thread, the method further includes: Using the first working thread to acquire a new target transaction; The new target transaction is sent to the second working thread through the first working thread.
7. The method according to claim 6, characterized in that After sending the target transaction and the metadata to the third working thread through the second working thread, the method further includes: Using the second working thread to generate metadata of the new target transaction; The new target transaction and metadata of the new target transaction are sent to the third working thread through the second working thread.
8. The method according to claim 7, characterized in that After the third worker thread is used to broadcast the target transaction and the metadata in the blockchain, the method further includes: The third working thread is used to broadcast the new target transaction and metadata of the new target transaction in the blockchain.
9. The method according to claim 2, characterized in that: Generating a target block to be agreed upon according to the metadata, and broadcasting the target block to a plurality of consensus nodes for consensus processing, includes: Enable consensus thread; The consensus thread is used to generate a target block to be agreed upon according to the metadata, and the target block is broadcast to a plurality of consensus nodes through the consensus thread for consensus processing; Among them, the consensus thread and the working thread do not affect each other.
10. The method according to claim 1, characterized in that The generating metadata of the target transaction includes: Detecting whether the quantity of the target transaction reaches a preset quantity value, or whether the acquisition time of the target transaction reaches a preset time value; When the number of the target transactions reaches the preset number value, or the acquisition time of the target transactions reaches the preset time value, the acquired target transactions are taken as a target transaction set; Generate metadata of the target transaction set.
11. The method according to claim 1, characterized in that: After performing the data broadcast operation, the method further includes: Receive transaction confirmation information sent by the consensus node according to the target transaction, and metadata confirmation information sent according to the metadata; When the received transaction confirmation information reaches the preset number, determining that the target transaction is saved by the preset number of consensus nodes; When the received metadata confirmation information reaches the preset number, it is determined that the metadata is saved by the preset number of consensus nodes.
12. A blockchain data processing device, characterized in that: include: An operation execution unit, configured to execute a data broadcast operation, wherein the data broadcast operation includes an operation of acquiring a target transaction, an operation of generating metadata of the target transaction, and an operation of broadcasting the target transaction and the metadata in a blockchain; A block consensus unit, configured to generate a target block to be consensus based on the metadata when the target transaction and the metadata are saved by a preset number of consensus nodes in the blockchain, and broadcast the target block to the plurality of consensus nodes for consensus processing; A block chain unit, configured to add the target block to the blockchain when a plurality of the consensus nodes reach a consensus on the target block; a data reading unit, configured to read the metadata in the target block in response to querying the target transaction through the blockchain; A transaction query unit is used to query the target transaction locally according to the metadata.
13. An electronic device, characterized in that: include: at least one processor; at least one memory for storing at least one program; When at least one of the programs is executed by at least one of the processors, the blockchain data processing method according to any one of claims 1 to 11 is implemented.
14. A computer-readable storage medium, characterized in that: A computer program executable by a processor is stored therein, and when the computer program executable by the processor is executed by the processor, it is used to implement the blockchain data processing method as described in any one of claims 1 to 11.
15. A computer program product comprising a computer program or computer instructions, characterized in that The computer program or the computer instructions are stored in a computer-readable storage medium, and the processor of the electronic device reads the computer program or the computer instructions from the computer-readable storage medium. The processor executes the computer program or the computer instructions, so that the electronic device executes the blockchain data processing method as described in any one of claims 1 to 11.