Block execution method, computer device and storage medium
By verifying the signature and storing the hash when receiving transactions on the blockchain node, judging the existence of the hash when receiving the block, avoiding repeated verification, the problem of the reduction of tps from the blockchain node is solved and processing efficiency is improved.
Patent Information
- Application Number
- CN202110028679.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-01-11
- Publication Date
- 2024-12-27
- Estimated Expiration
- 2041-01-11
AI Technical Summary
When a blockchain node executes a new block, it needs to perform signature verification on each transaction, resulting in repetitive check verification and reduce tps (transaction processing rate per second).
By verifying the signature information when receiving the transaction, and storing the transaction hash in the memory pool, it is determined whether the transaction hash exists when receiving the block. If it exists, the processing will be terminated. If it does not exist, the signature information will be verified to avoid repeated checks.
It effectively avoids repeated checks and verification, improves the TPS of blockchain nodes, and reduces the memory overhead required for transaction duplication checking.
Smart Images

Figure CN112712366B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of blockchain technology, and in particular to a block execution method, a computer device, and a storage medium. Background Art
[0002] When tx1 is sent to the memory pool, it needs to undergo basic checks, including transaction signature verification. When a new block is executed, since the new block may come from other nodes in the network, the above basic checks need to be performed on each transaction in the new block to verify the legitimacy of the entire block. If the new block includes tx1, the signature verification of tx1 is performed twice. The above mechanism leads to a decrease in the tps of blockchain nodes. Summary of the invention
[0003] In view of the above-mentioned defects or deficiencies in the prior art, it is desired to provide a block execution method, a computer device and a storage medium that can effectively avoid repetitive checks and verifications and improve the TPS of blockchain nodes.
[0004] In a first aspect, the present invention provides a block execution method applicable to a blockchain node, the method comprising:
[0005] Receive the first transaction, verify the first signature information of the first transaction, store the first transaction into the memory pool when the verification is passed, and store the first transaction hash of the first transaction;
[0006] Receive the first block, and perform the following operations on each second transaction in the first block:
[0007] Determine whether a transaction hash identical to the second transaction hash of the second transaction is stored:
[0008] If yes, then it ends;
[0009] If not, verify the second signature information of the second transaction.
[0010] In a second aspect, the present invention provides a block execution method applicable to a blockchain node, the method comprising:
[0011] Receive the first transaction and verify the first signature information of the first transaction:
[0012] When the verification is passed, the first transaction is stored in the memory pool, and a first data set of the first transaction is stored; wherein the first data set includes a first transaction hash of the first transaction and a verification pass identifier;
[0013] When the verification fails, the first transaction is deleted, and a second data set of the first transaction is stored; wherein the second data set includes a first transaction hash of the first transaction and a verification failure flag;
[0014] Receive the first block, and perform the following operations on each second transaction in the first block:
[0015] Determine whether a third transaction hash included in a third data set that is the same as the second transaction hash of the second transaction is stored:
[0016] If yes, then when the third data set includes the verification pass mark, the process ends;
[0017] When the third data set includes a verification failure indicator, not executing the second transaction;
[0018] If not, verify the second signature information of the second transaction.
[0019] In a third aspect, the present invention further provides a computer device, comprising one or more processors and a memory, wherein the memory contains instructions executable by the one or more processors so that the one or more processors execute the block execution method provided according to various embodiments of the present invention.
[0020] In a fourth aspect, the present invention further provides a storage medium storing a computer program, wherein the computer program enables a computer to execute the block execution method provided according to each embodiment of the present invention.
[0021] The block execution method, computer device and storage medium provided by many embodiments of the present invention receive a first transaction, verify the first signature information of the first transaction, store the first transaction in a memory pool when the verification is passed, and store the first transaction hash of the first transaction; receive a first block, and perform the following operations on each second transaction in the first block: determine whether a transaction hash identical to the second transaction hash of the second transaction is stored: if yes, end; if not, verify the second signature information of the second transaction. This method can effectively avoid repeated checks and verifications and improve the TPS of blockchain nodes. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Other features, objects and advantages of the present application will become more apparent by reading the detailed description of non-limiting embodiments made with reference to the following drawings:
[0023] Figure 1 The present invention provides a flowchart of a block execution method according to an embodiment of the present invention.
[0024] Figure 2 A flowchart of another block execution method provided by an embodiment of the present invention.
[0025] Figure 3 A schematic diagram of the structure of a computer device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0026] The present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the relevant invention, rather than to limit the invention. It is also necessary to explain that, for ease of description, only the parts related to the invention are shown in the accompanying drawings.
[0027] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0028] Figure 1 A flowchart of a block execution method provided by an embodiment of the present invention. Figure 1 As shown, in this embodiment, the present invention provides a block execution method applicable to a blockchain node, and the method includes:
[0029] S12: Receive the first transaction, verify the first signature information of the first transaction, store the first transaction into the memory pool when the verification is successful, and store the first transaction hash of the first transaction;
[0030] Receive the first block, and perform the following operations on each second transaction in the first block:
[0031] S141: Determine whether a transaction hash identical to the second transaction hash of the second transaction is stored:
[0032] If not, execute step S142: verify the second signature information of the second transaction.
[0033] Specifically, the blockchain node executes step S12, receives tx1, verifies the signature information of tx1, stores tx1 into the memory pool when the verification is passed, and stores hash(tx1);
[0034] Assume that at this time the blockchain node stores hash(tx10), hash(tx50), and hash(tx1); the received block block(100) includes transactions tx10 to tx20;
[0035] The blockchain node performs the following operations on tx10~tx20 respectively:
[0036] For tx10:
[0037] The blockchain node executes step S141 to determine whether hash(tx10) is stored:
[0038] Since hash(tx10) is stored, the blockchain node does not verify the signature information of tx10;
[0039] For tx11:
[0040] The blockchain node executes step S141 to determine whether hash(tx11) is stored:
[0041] Since hash(tx11) is not stored, step S142 is executed to verify the signature information of tx11;
[0042] tx12~tx20 are the same as tx11 and will not be described here.
[0043] Those skilled in the art should understand that the operation when tx1 fails verification can be configured according to actual needs, for example, it can be configured to delete tx1, and no specific limitation is made here.
[0044] The above embodiments can effectively avoid repeated checks and verifications and improve the TPS of blockchain nodes.
[0045] Preferably, storing the first transaction into the memory pool when the verification is passed, and storing the first transaction hash of the first transaction includes:
[0046] When the verification is passed, the first transaction is stored in the memory pool, and the first transaction hash of the first transaction is calculated;
[0047] Calculate a first number of first mapping bits of the first transaction hash, and set each first mapping bit of the Bloom filter to 1;
[0048] Determining whether a transaction hash identical to a second transaction hash of a second transaction is stored includes:
[0049] Calculate a first number of second mapping bits of a second transaction hash;
[0050] Determine whether all second mapping bits are 1.
[0051] Those skilled in the art should understand that in the current embodiment, when all second mapping bits are 1, it is impossible to determine whether a transaction hash identical to the second transaction hash of the second transaction is stored, and the second transaction should be checked for duplication using the existing technical solution.
[0052] The above embodiment reduces the memory overhead required for transaction duplication checking.
[0053] As the block height increases, more and more transaction mapping bits will be stored in the Bloom filter, and eventually the Bloom filter will be full, and a good query effect cannot be obtained. The mapping bits of some transactions that have been stored for a long time in the Bloom filter should be deleted, but the bits set to 1 in the Bloom filter cannot be set to 0 just because a transaction is deleted. Once a transaction needs to be deleted, the value of each mapping bit in the Bloom filter needs to be recalculated.
[0054] To solve the above problems, the following embodiments can be used.
[0055] Further preferably, after setting each first mapping bit of the Bloom filter to 1, the method further includes:
[0056] Incrementing the first counter of each first mapping bit by one to update the first counter;
[0057] The above method further includes:
[0058] When the storage duration of the first transaction hash reaches the first duration, the following operations are performed on each first mapping bit:
[0059] Determine whether the first counter of the first mapping bit is 1:
[0060] If yes, then update the first counter to 0 and set the first mapping position to 0;
[0061] If not, the first counter is reduced by one to update the first counter.
[0062] Specifically, take the first duration of 2 minutes as an example; assume that the mapping bits of hash(tx1) are 3, 8, and 9; when tx1 is not received, the value of the mapping bit 3 of the Bloom filter is 0, the values of the mapping bits 8 and 9 are 1, the counter of the mapping bit 3 is 0, the counter of the mapping bit 8 is 2, and the counter of the mapping bit 9 is 3;
[0063] The blockchain node receives tx1, verifies the signature information of tx1, stores tx1 into the memory pool when the signature passes, and calculates the mapping bits of hash(tx1). The calculated mapping bits are 3, 8, and 9.
[0064] The blockchain node sets mapping bits 3, 8, and 9 to all 1;
[0065] The blockchain node updates the counter of mapping bit 3 to 1, the counter of mapping bit 8 to 3, and the counter of mapping bit 9 to 4;
[0066] Assume that within 2 minutes, the values of mapping bits 3, 8, and 9 and the counter have not changed;
[0067] When the storage time of hash(tx1) reaches 2 minutes, the value of mapping bit 3 is set to 0, and its counter is updated to 0; the value of mapping bit 8 remains unchanged, and its counter is updated to 2; the value of mapping bit 9 remains unchanged, and its counter is updated to 3.
[0068] The above embodiment further reduces the memory overhead required for transaction duplication checking.
[0069] Figure 2 FIG. 1 is a flowchart of another block execution method provided by an embodiment of the present invention. Figure 2As shown, in this embodiment, the present invention provides a block execution method applicable to a blockchain node, and the method includes:
[0070] S22: Receive the first transaction and verify the first signature information of the first transaction:
[0071] When the verification is passed, the first transaction is stored in the memory pool, and a first data set of the first transaction is stored; wherein the first data set includes a first transaction hash of the first transaction and a verification pass identifier;
[0072] When the verification fails, the first transaction is deleted, and a second data set of the first transaction is stored; wherein the second data set includes a first transaction hash of the first transaction and a verification failure flag;
[0073] Receive the first block, and perform the following operations on each second transaction in the first block:
[0074] S2411: Determine whether a third transaction hash included in the third data set that is the same as the second transaction hash of the second transaction is stored:
[0075] If yes, then execute step S2412: when the third data set includes the verification pass mark, end;
[0076] S2413: when the third data set includes a verification failure indicator, not executing the second transaction;
[0077] If not, execute step S242: verify the second signature information of the second transaction.
[0078] Specifically, suppose the blockchain node receives tx2 and tx3 successively, the signature information verification of tx2 passes, but the signature information verification of tx3 fails;
[0079] For tx2:
[0080] The blockchain node executes step S22, receives tx2, and verifies the signature information of tx2. Since the signature information of tx2 is verified, tx2 is stored in the memory pool and the data set {hash(tx2),0} is stored; wherein 0 indicates verification passed and 1 indicates verification failed; in more embodiments, the verification passed flag and the verification failed flag can also be configured according to actual needs, for example, the verification passed flag is configured as s and the verification failed flag is configured as f, which can achieve the same technical effect.
[0081] For tx3:
[0082] The blockchain node executes step S22, receives tx3, verifies the signature information of tx3, and stores the data set {hash(tx3),1} because the signature information verification of tx3 fails.
[0083] Assume that at this time the blockchain node stores {hash(tx2),0}, {hash(tx3),1}, {hash(tx10),0}, {hash(tx11),1}; the received block block(100) includes transactions tx10~tx20;
[0084] The blockchain node performs the following operations on tx10~tx20 respectively:
[0085] For tx10:
[0086] The blockchain node executes step S2411 to determine whether a data set including hash(tx10) is stored:
[0087] Since {hash(tx10),0} is stored and its mark is verified, the blockchain node executes step S2412 and ends;
[0088] For tx11:
[0089] The blockchain node executes step S2411 to determine whether a data set including hash(tx11) is stored:
[0090] Since {hash(tx11),1} is stored and it is marked as verification failure, step S142 is executed and tx11 is not executed;
[0091] For tx12:
[0092] The blockchain node executes step S2411 to determine whether a data set including hash(tx12) is stored:
[0093] Since the data set including hash(tx12) is not stored, step S242 is executed to verify the signature data of tx12.
[0094] tx13~tx20 are the same as tx12 and will not be described here.
[0095] The above embodiments and Figure 1 The difference of the illustrated embodiment is that when a node executes a block, it can also simultaneously obtain verified transaction information that has already failed verification, so as to avoid secondary verification.
[0096] The above embodiments can effectively avoid repeated checks and verifications and improve the TPS of blockchain nodes.
[0097] Figure 3 The following is a schematic diagram of the structure of a computer device provided by an embodiment of the present invention. Figure 3As shown, as another aspect, the present application also provides a computer device, including one or more central processing units (CPU) 301, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 302 or the program loaded from the storage part 308 to the random access memory (RAM) 303. In RAM303, various programs and data required for the operation of the computer device are also stored. CPU301, ROM302 and RAM303 are connected to each other through a bus 304. An input / output (I / O) interface 305 is also connected to the bus 304.
[0098] The following components are connected to the I / O interface 305: an input section 306 including a keyboard, a mouse, etc.; an output section 307 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 308 including a hard disk, etc.; and a communication section 309 including a network interface card such as a LAN card, a modem, etc. The communication section 309 performs communication processing via a network such as the Internet. A drive 310 is also connected to the I / O interface 305 as needed. A removable medium 311, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 310 as needed, so that a computer program read therefrom is installed into the storage section 308 as needed.
[0099] In particular, according to an embodiment of the present disclosure, the method described in any of the above embodiments can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program tangibly contained on a machine-readable medium, and the computer program includes a program code for executing any of the above methods. In such an embodiment, the computer program can be downloaded and installed from a network through the communication part 309, and / or installed from a removable medium 311.
[0100] As another aspect, the present application also provides a computer-readable storage medium, which may be the computer-readable storage medium included in the apparatus of the above embodiment; or may be a computer-readable storage medium that exists independently and is not assembled into a computer device. The computer-readable storage medium stores one or more programs, which are used by one or more processors to execute the method described in the present application.
[0101] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be realized by a dedicated hardware-based system that performs a specified function or operation, or can be realized by a combination of dedicated hardware and computer instructions.
[0102] The units or modules involved in the embodiments described in the present application may be implemented by software or by hardware. The units or modules described may also be arranged in a processor. For example, each of the units may be a software program arranged in a computer or a mobile smart device, or may be a separately configured hardware device. The names of these units or modules do not, in some cases, constitute limitations on the units or modules themselves.
[0103] The above description is only a preferred embodiment of the present application and an explanation of the technical principles used. Those skilled in the art should understand that the scope of the invention involved in the present application is not limited to the technical solution formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the concept of the present application. For example, the above features are replaced with the technical features with similar functions disclosed in the present application (but not limited to) to form a technical solution.
Claims
1. A block execution method, characterized in that: Applicable to a blockchain node, the method includes: receiving a first transaction, verifying first signature information of the first transaction, storing the first transaction in a memory pool when the verification is passed, and storing a first transaction hash of the first transaction; Receive a first block, and perform the following operations on each second transaction in the first block: determine whether a transaction hash identical to the second transaction hash of the second transaction is stored; if not, verify the second signature information of the second transaction, wherein storing the first transaction into a memory pool when the verification is successful and storing the first transaction hash of the first transaction includes: storing the first transaction into a memory pool when the verification is successful and calculating the first transaction hash of the first transaction; Calculate a first number of first mapping bits of the first transaction hash, and set each of the first mapping bits of the Bloom filter to 1; The determining whether a transaction hash identical to the second transaction hash of the second transaction is stored comprises: calculating a first number of second mapping bits of the second transaction hash; It is determined whether all the second mapping bits are 1.
2. The method according to claim 1, characterized in that After setting each of the first mapping bits of the Bloom filter to 1, the method further includes: adding one to a first counter of each of the first mapping bits to update the first counter; The method further comprises: When the storage duration of the first transaction hash reaches a first duration, performing the following operations on each of the first mapping bits: determining whether the first counter of the first mapping bit is 1: if yes, updating the first counter to 0, and setting the first mapping bit to 0; If not, the first counter is reduced by one to update the first counter.
3. A block execution method, characterized in that: Applicable to a blockchain node, the method includes: receiving a first transaction, verifying first signature information of the first transaction; storing the first transaction in a memory pool when the verification is passed, and storing a first data set of the first transaction; wherein the first data set includes a first transaction hash and a verification pass identifier of the first transaction; When the verification fails, the first transaction is deleted, and a second data set of the first transaction is stored; wherein the second data set includes a first transaction hash of the first transaction and a verification failure flag; Receive a first block, and perform the following operations on each second transaction in the first block: determine whether a third transaction hash included in a third data set that is the same as the second transaction hash of the second transaction is stored: if yes, then end when the third data set includes a verification pass identifier; When the third data set includes a verification failure indicator, not executing the second transaction; If no, verify the second signature information of the second transaction.
4. A computer device, characterized in that: The device includes: one or more processors; a memory for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors are caused to perform the method according to any one of claims 1 to 3.
5. A storage medium storing a computer program, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 3 is implemented.