Transaction storage and block execution method, device and storage medium
By calculating the difference between the packaging height and the block height of the transaction on the blockchain node according to the block consensus rules, the decentralized packaging of the transaction is achieved, solving the problem of throughput reduction caused by the specified height information of the transaction, and improving the blockchain Processing efficiency.
Patent Information
- Application Number
- CN202111456949.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-02
- Publication Date
- 2024-11-12
- Estimated Expiration
- 2041-12-02
AI Technical Summary
In the prior art, the specified height information contained in the transaction causes an increase in the block size, reducing the number of transactions that the block can store, thereby reducing throughput.
By calculating the block height on the blockchain node according to the pre-configured block consensus rules, receiving transactions and storing them to the appropriate queue to be packaged, the transaction packaging order is determined by using the difference in block heights, and the decentralized packaging of transactions is improved. Reduce the use of specified height information.
This improves the throughput of blockchain, avoids the problem of increasing block size caused by excessive transactions, and enhances the processing efficiency of blockchain network.
Smart Images

Figure CN114138906B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of blockchain technology, and specifically to a transaction storage and block execution method, device and storage medium. Background Art
[0002] In the patent application previously filed by the applicant (see CN2019106074995), the throughput is improved by processing transaction checks and block confirmations in parallel.
[0003] In the above mechanism, the specified height information included in the transaction will make tx1 huge, while the size of a block is constant. The above mechanism will reduce the number of transactions that can be stored in a block, and on the other hand reduce the throughput. Summary of the invention
[0004] In view of the above-mentioned defects or deficiencies in the prior art, it is desirable to provide a transaction storage and block execution method, device and storage medium that further improve the throughput.
[0005] In a first aspect, the present invention provides a transaction storage and block execution method applicable to a front-end processor, the method comprising:
[0006] Perform the following operations on each first blockchain node of the blockchain: calculate the height of each first block that the first blockchain node should participate in consensus according to a preconfigured block consensus rule; wherein the block consensus rule includes the first public information of the first blockchain node, and each first blockchain node also performs this step;
[0007] Receiving a first transaction; wherein the first transaction is generated by a client;
[0008] Calculating a second block height at which the first transaction should be packaged according to a preconfigured transaction packaging rule that matches the block consensus rule; wherein the transaction packaging rule includes second public information of the first transaction, and a difference between the first block height and the current block height is greater than a first value; and,
[0009] Storing the first transaction in a first to-be-packaged queue at a second block height;
[0010] When the difference between the third block height and the current block height is a second value, each second transaction in the second to-be-packaged queue of the third block height is sent to each second blockchain node that should participate in the consensus of the third block height, so that each second blockchain node:
[0011] When the third block at the third block height is packaged with the right, the third block is generated according to each second transaction and broadcasted to other blockchain nodes for other blockchain nodes to:
[0012] When the third block height is the block height that should participate in the consensus, determine whether the third block height is the block height that the second blockchain node that generates the third block should participate in the consensus:
[0013] If yes, then execute each second transaction to execute the third block;
[0014] Among them, the second value is less than the first value, receiving the first transaction to the first to-be-packaged queue that stores the first transaction in the second block height, and sending each second transaction in the second to-be-packaged queue of the third block height to each second blockchain node that should participate in the consensus of the third block height are executed in parallel.
[0015] In a second aspect, the present invention also provides a 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 transaction storage and block execution method provided according to various embodiments of the present invention.
[0016] In a third aspect, the present invention further provides a storage medium storing a computer program, wherein the computer program enables a computer to execute the transaction storage and block execution method provided according to various embodiments of the present invention.
[0017] The transaction storage and block execution method, device and storage medium provided by many embodiments of the present invention further improve the throughput by performing the following operations on each first blockchain node of the blockchain: calculating the first block heights that the first blockchain node should participate in the consensus according to the preconfigured block consensus rule; receiving the first transaction; calculating the second block height that the first transaction should be packaged according to the preconfigured transaction packaging rule that matches the block consensus rule; and storing the first transaction in the first queue to be packaged at the second block height; when the difference between the third block height and the current block height is a second value, sending each second transaction in the second queue to be packaged at the third block height to each second blockchain node that should participate in the consensus of the third block height. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] 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:
[0019] Figure 1 A flowchart of a transaction storage and block execution method provided by one embodiment of the present invention.
[0020] Figure 2 A schematic diagram of the structure of a device provided in one embodiment of the present invention. DETAILED DESCRIPTION
[0021] 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.
[0022] 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.
[0023] Figure 1 A flowchart of a transaction storage and block execution method provided by an embodiment of the present invention. Figure 1 As shown, in this embodiment, the present invention provides a transaction storage and block execution method applicable to a front-end processor, and the method includes:
[0024] S11: Perform the following operations on each first blockchain node of the blockchain: calculate the height of each first block that the first blockchain node should participate in consensus according to a pre-configured block consensus rule; wherein the block consensus rule includes the first public information of the first blockchain node, and each first blockchain node also performs this step;
[0025] S12: receiving a first transaction; wherein the first transaction is generated by a client;
[0026] S13: Calculating a second block height in which the first transaction should be packaged according to a preconfigured transaction packaging rule that matches the block consensus rule; wherein the transaction packaging rule includes the second public information of the first transaction, and the difference between the first block height and the current block height is greater than a first value; and,
[0027] S14: storing the first transaction in a first to-be-packaged queue at a second block height;
[0028] S15: When the difference between the third block height and the current block height is a second value, each second transaction in the second to-be-packaged queue of the third block height is sent to each second blockchain node that should participate in the consensus of the third block height, so that each second blockchain node:
[0029] When the third block at the third block height is packaged with the right, the third block is generated according to each second transaction and broadcasted to other blockchain nodes for other blockchain nodes to:
[0030] When the third block height is the block height that should participate in the consensus, determine whether the third block height is the block height that the second blockchain node that generates the third block should participate in the consensus:
[0031] If yes, then execute each second transaction to execute the third block;
[0032] Among them, the second value is less than the first value, receiving the first transaction to the first to-be-packaged queue that stores the first transaction in the second block height, and sending each second transaction in the second to-be-packaged queue of the third block height to each second blockchain node that should participate in the consensus of the third block height are executed in parallel.
[0033] Specifically, the first public information is the node hash of the first blockchain node, and the second public information is the first full hash of the first transaction. S11 includes "obtaining the first M bits of the node hash of the first blockchain node, and calculating the first N-ary number according to the first M bits; determining each fourth block height whose second N-ary number is the same as the first N-ary number as each first block height; wherein the calculation method of the second N-ary number is: (h mod N^M)===>>>(x2)2, (x2)2=(x1)2, h is the fourth block height, (x1)2 is the first N-ary number, and (x2)2 is the second N-ary number"; and S13 includes "obtaining the second M bits of the first full hash, and calculating the third N-ary number according to the second M bits; calculating the fifth block height; wherein the calculation method of the fifth block height is: min(h1)mod N^M===>>>(x3)2, min(h1)>current block height+first value+1, min(h1) is the fifth block height, (x3)2 is the third N-ary number; and, the fifth block height is determined as the second block height"; and, judging whether the third block height is the block height that the second blockchain node generating the third block should participate in the consensus includes "obtaining the first M-bit first N-ary number of the node hash of the second blockchain node generating the third block; calculating the fifth N-ary number; wherein the calculation method of the fifth N-ary number is: (h2 mod N^M)===>>>(x5)2, h2 is the third block height, (x5)2 is the fifth N-ary number; judging whether the first M-bit first N-ary number of the node hash of the second blockchain node generating the third block is the same as the fifth N-ary number" as an example;
[0034] Assume that the blockchain has nodes N1 to N24, the first value is 5, the second value is 3, M is the first 3, and N is 2; the first 3 binary digits of the node hash of N1 to N3 are 000, the first 3 binary digits of the node hash of N4 to N6 are 001, the first 3 binary digits of the node hash of N7 to N9 are 010... The first 3 binary digits of the node hash of N22 to N24 are 111; the front-end obtains tx1 and tx2 successively; the first 3 binary digits of the full hash of tx1 are 000, and the first 3 binary digits of the full hash of tx2 are 111; the current block height is 100, and the third block height is 112;
[0035] Take N1 as an example:
[0036] The front-end executes step S11, obtains the first 3 bits of N1's node hash, and calculates the binary number based on the first 3 bits, which is 000; since the remainder of 0, 8, 16, ... and 8 is 0, and the binary number of 0 is 000, 0, 8, 16, ... are the block heights that N1 should participate in the consensus;
[0037] Therefore, 0, 8, 16... are the block heights that N1~N3 should participate in the consensus, 1, 9, 17... are the block heights that N4~N6 should participate in the consensus, and 7, 15, 23... are the block heights that N22~N24 should participate in the consensus.
[0038] N1 to N24 also perform step S11;
[0039] For tx1:
[0040] The front-end executes step S12 and receives tx1;
[0041] The front-end executes step S13 to obtain the first 3 binary digits of the full hash of tx1, which is 000. The front-end calculates the block height that should be used to package tx1. The block height should be greater than 106, and the binary number of the remainder of the block height and 8 should also be 000 and is closest to 106, so the block height is 112.
[0042] The front-end executes step S14 and stores tx1 in the to-be-packaged queue at block height 112;
[0043] For tx2:
[0044] The front-end executes step S12 and receives tx2;
[0045] The front-end executes step S13 to obtain the first 3 binary digits of the full hash of tx2, which is 111. The front-end calculates the block height that should be used to package tx2. The block height should be greater than 106, and the binary number of the remainder of the block height and 8 should also be 111 and is closest to 106, so the block height is 111.
[0046] The front-end executes step S14 and stores tx2 in the to-be-packed queue at block height 111;
[0047] Assuming that the current block height is 109, at this time, the difference between 112 and 109 is 3, the front-end executes step S15 to send each transaction in the queue to be packaged at block height 112 (assuming tx1, tx3~tx10) to N1~N3;
[0048] Assuming that N1 has the packaging right for block(112), N1 generates block(112) based on tx1 and tx3~tx10, and broadcasts it to N2~N24;
[0049] Since only N2 and N3 should participate in the consensus of block height 112, N2 and N3 obtain the first binary number of N1, which is 000;
[0050] N2 and N3 calculate the fifth binary number, 112 mod 8 = 0, the binary number of 0 is 000;
[0051] Since both binary numbers are 000, N1 should participate in the consensus of 112;
[0052] N2 and N3 execute tx1 and tx3 to tx10 to execute block (112).
[0053] Among them, steps S12 to S14 are executed in parallel with step S15.
[0054] In more embodiments, the first value, the second value, M, and N can be configured according to actual needs to obtain the same technical effect. However, those skilled in the art should understand that as the performance of blockchain becomes stronger and stronger, the time required for steps such as block generation and consensus becomes shorter and shorter, and the first value should not be configured as a very small value. When the first value is configured as a very small value, it is easy to cause the problem that tx1 cannot be packaged in time.
[0055] In more embodiments, the first public information and the second public information may also be configured according to actual needs. For example, the first public information may be configured as a node public key, and the second public information may be configured as a transaction hash to achieve the same technical effect.
[0056] In more embodiments, S11 can also be configured according to actual needs, for example, configured to, for example, perform the following operations on each blockchain node: taking N1 as an example, convert the first public information of N1 into a decimal number, and obtain the last digit of the converted decimal number, for example, 9, then 9, 19, 29... are the block heights for which N1 should participate in the consensus; accordingly, the methods of S13 and S14 should also be configured. At this time, the front-end should also calculate the last digit of the decimal number converted from the second public information of tx1 (assuming it is also 9), so as to find the block height for which tx1 should be packaged, that is, find the block height with the smallest tail number of 9 greater than 106, that is, 109; assuming that block (109) is still generated by N1, and N2 and N3 are still blockchain nodes participating in the 109 consensus, then N2 and N3 still need to verify whether 109 is the block height for which N1 should participate in the consensus; the same technical effect can be achieved.
[0057] In more embodiments, S15 can also be configured according to actual needs. Assuming that there are a lot of blockchain nodes in the current blockchain, N1~N3, N31~N100 all need to participate in the consensus of block height 112, the front-end can first select a number of blockchain nodes of each transaction in the waiting queue for packaging that need to send block height 112 from N1~N3, N31~N100 according to the pre-configured node screening method according to actual needs. The above node screening method can also be configured according to actual needs. For example, it is configured to determine the blockchain nodes with d<=t / W from N1~N3, N31~N100 as the blockchain nodes that need to send block height 112. The blockchain nodes of each transaction in the queue to be packaged; where d is the ratio of the first hash value to 2^256, the calculation method of the first hash value is d=vrf(seed, height, sk), seed is the block hash of block(109), height is 112, sk is the private key held by N1~N3, N31~N100, t is the specific number of nodes to be selected, and W is the number of all tokens pledged by all nodes of the blockchain to participate in the consensus; assuming that the selected nodes are N31~N33, the front-end sends each transaction in the queue to be packaged at block height 112 to N31~N33. The above steps can further speed up the consensus efficiency of the block.
[0058] Those skilled in the art should understand that the above-mentioned front-end processor can be configured as one or more according to actual needs. When configured as multiple front-end processors, the transactions received by each front-end processor should be consistent.
[0059] Compared with the patent application previously filed by the applicant, the transactions in this application do not include specified height information, and the transactions can be packaged in different blocks in a dispersed manner, further improving the throughput.
[0060] Preferably, each first transaction is a first-type transaction that requires a specified block height, and a second-type transaction generated by a client that does not require a specified block height is cached in the transaction pool of each first blockchain node;
[0061] Generating a third block based on each second transaction and broadcasting it to other blockchain nodes includes:
[0062] A third block is generated based on each second transaction and a number of transactions in the transaction pool and broadcasted to other blockchain nodes.
[0063] The above embodiments and Figure 1 The difference between the illustrated embodiments is that the above embodiments also include instant packaged transactions, enriching the user experience.
[0064] Preferably, the front-end processor can also be configured to receive the second type of transactions according to actual needs. When the front-end processor receives the second type of transactions, it adds the received transactions to the instant packaging queue;
[0065] S15 includes:
[0066] When the difference between the third block height and the current block height is a second value, each second transaction in the second to-be-packaged queue of the third block height and a number of transactions in the immediate packaging queue are sent to each second blockchain node that should participate in the consensus of the third block height;
[0067] The second blockchain node that obtains the packaging right of the third block generates the third block according to the received second transactions and several transactions in the instant packaging queue.
[0068] The difference between the above embodiment and the previous preferred embodiment is that, in the previous preferred embodiment, the front-end processor is only responsible for the transaction storage of the first type of transactions, and the second type of transactions are directly stored by the blockchain node; while in the above embodiment, the front-end processor is responsible for the transaction storage of the first type of transactions and the second type of transactions; the performance requirement configuration of the front-end processor in the previous preferred embodiment is significantly lower than that of the front-end processor in the current embodiment; and the current embodiment can reduce the bandwidth required for blockchain nodes to broadcast transactions, so that blockchain nodes can use the bandwidth for other tasks such as block consensus.
[0069] Preferably, executing each second transaction to execute the third block includes:
[0070] The following steps are performed for each second transaction: determine whether the second transaction should be packaged at the third block height according to the transaction packaging rule: if not, the execution of the second transaction fails.
[0071] Specifically, N2 to N3 perform the following steps on tx1 and tx3 to tx10 respectively:
[0072] Take tx1 as an example;
[0073] Get the first 3 binary digits of the full hash of tx1, which is 000;
[0074] Calculate the remainder of the block height 112 and 8, the remainder is 0;
[0075] The binary number of 0 is also 000;
[0076] Since the two binary numbers are the same, the verification passes and tx1 is executed;
[0077] tx3~tx10 are similar to tx1 and will not be described here;
[0078] Assuming that the first three binary digits of the full hash of tx10 are not 000, N2 and N3 fail to execute tx10;
[0079] Those skilled in the art should understand that when it is found that the first 3 binary digits of the full hash of tx10 are not 000, the blockchain node can record the illegal behavior of the front-end, for example, increase the number of illegal behaviors of the front-end by one to update the number of illegal behaviors; when the number of illegal behaviors of the front-end reaches a certain threshold, a report transaction for reporting the front-end can be generated, and the report transaction can include the transaction hash of tx10. When the report transaction is successfully executed, the front-end will be deducted a certain fine. If multiple spare front-ends are configured, the administrator's terminal can also switch the front-end when monitoring the successful execution of the report transaction, that is, rotate the spare front-end to the front-end.
[0080] Further preferably, each second transaction is also used for each second blockchain node to pre-generate a first Merkle root according to each second transaction when receiving each second transaction;
[0081] The following steps are performed for each second transaction: according to the transaction packaging rule, it is determined whether the second transaction should be packaged at the third block height: if not, the failure to execute the second transaction includes:
[0082] Determine whether the second Merkle root of the third block is the same as the first Merkle root:
[0083] If yes, omit the following steps for each second transaction: determine whether the second transaction should be packaged at the third block height according to the transaction packaging rule; if no, execute the second transaction failure step.
[0084] Specifically, when the block height is 109, N1, N2, and N3 also need to pre-generate a Merkleroot (112) of block height 112 according to each second transaction;
[0085] When N2 and N3 receive block(112), if the Merkleroot(112)' of block(112) is the same as merkleroot(112), it means that the transaction and the execution result of the transaction are completely consistent, then N2 and N3 omit the step of "performing the following steps for each second transaction: judging whether the second transaction should be packaged at the third block height according to the transaction packaging rule: if not, executing the second transaction failure step";
[0086] If merkleroot(112)' is different from merkleroot(112), N2 and N3 still need to execute the step of "perform the following steps for each second transaction: determine whether the second transaction should be packaged at the third block height according to the transaction packaging rules: if not, execute the second transaction failure step".
[0087] The above embodiments further speed up the consensus efficiency of blocks.
[0088] Further preferably, the to-be-packaged queue of each blockchain node is configured with the same transaction sorting method, and each second transaction is also used for each second blockchain node to pre-generate a first Merkle root according to each second transaction when receiving each second transaction;
[0089] Generating a third block based on each second transaction and broadcasting it to other blockchain nodes includes:
[0090] Generate a third block according to each second transaction in the second to-be-packaged queue at the third block height;
[0091] Broadcasting the second Merkle root of the third block and the second transaction hash list including each second transaction to other blockchain nodes;
[0092] The following steps are performed for each second transaction: according to the transaction packaging rule, it is determined whether the second transaction should be packaged at the third block height: if not, the failure to execute the second transaction includes:
[0093] Determine whether the second Merkle root of the third block is the same as the first Merkle root:
[0094] If yes, omit the following steps for each second transaction: determine whether the second transaction should be packaged at the third block height according to the transaction packaging rule; if no, execute the second transaction failure step.
[0095] The difference between the above embodiment and the previous embodiment is that N1 broadcasts not block(112) but the transaction hash list of merkleroot(112)' and each transaction of block(112);
[0096] If the Merkleroot(112)' of block(112) is the same as merkleroot(112), it means that the transaction and the execution result of the transaction are completely consistent, and N2 and N3 omit the step of "performing the following steps for each second transaction: judging whether the second transaction should be packaged at the third block height according to the transaction packaging rule; if not, the execution of the second transaction fails";
[0097] Those skilled in the art should understand that the operation steps when merkleroot(112)' is different from merkleroot(112) can also be configured according to the file time requirement. For example, if merkleroot(112)' is different from merkleroot(112), N2 and N3 request the missing second transaction from N1. After receiving the missing second transaction, the following steps are performed for each requested second transaction: Determine whether the requested second transaction should be packaged at the third block height according to the transaction packaging rule: If not, the execution of the requested second transaction fails.
[0098] The above embodiment reduces the amount of data broadcast by N1 and further increases the throughput.
[0099] Preferably, executing each second transaction to execute the third block includes:
[0100] The following steps are performed for each second transaction: determine whether the second transaction should be packaged at the third block height according to the transaction packaging rule: if not, the execution of the second transaction fails.
[0101] Further preferably, each second transaction is also used for each second blockchain node to pre-generate a first Merkle root according to each second transaction when receiving each second transaction;
[0102] Generating a third block based on each second transaction and a number of transactions in the transaction pool and broadcasting it to other blockchain nodes includes:
[0103] generating a second Merkle root according to each of the second transactions, generating a third Merkle root according to the plurality of transactions, and generating a fourth Merkle root of the third block according to the second Merkle root and the third Merkle root;
[0104] The following steps are performed for each second transaction: according to the transaction packaging rule, it is determined whether the second transaction should be packaged at the third block height: if not, the failure to execute the second transaction includes:
[0105] Determine whether the second Merkle root in the third block is the same as the first Merkle root:
[0106] If yes, omit the following steps for each second transaction: determine whether the second transaction should be packaged at the third block height according to the transaction packaging rule; if no, execute the second transaction failure step.
[0107] Specifically, when the block height is 109, N1, N2, and N3 also need to pre-generate a Merkleroot (112) of block height 112 according to each second transaction;
[0108] N1 generates merkleroot(112-first-category transaction) according to each second transaction, generates merkleroot(112-second-category transaction) according to several transactions, and generates the merkleroot of block(112) according to merkleroot(112-first-category transaction) and merkleroot(112-second-category transaction);
[0109] When N2 and N3 receive block(112), if merkleroot(112-first type of transaction) is the same as merkleroot(112), it means that the transaction and the execution result of the transaction are completely consistent, then N2 and N3 omit the step of "performing the following steps for each second transaction: judging whether the second transaction should be packaged at the third block height according to the transaction packaging rule: if not, executing the second transaction failure step";
[0110] If merkleroot(112-first type of transaction) is different from merkleroot(112), N2 and N3 still need to execute the step of "perform the following steps for each second transaction: determine whether the second transaction should be packaged at the third block height according to the transaction packaging rules: if not, execute the second transaction failure step".
[0111] The above embodiments further speed up the consensus efficiency of blocks.
[0112] Further preferably, the to-be-packaged queue of each blockchain node is configured with the same transaction sorting method, and each second transaction is also used for each second blockchain node to pre-generate a first Merkle root according to each second transaction when receiving each second transaction;
[0113] Generating a third block based on each second transaction and a number of transactions in the transaction pool and broadcasting it to other blockchain nodes includes:
[0114] generating a second Merkle root according to each of the second transactions, generating a third Merkle root according to the plurality of transactions, and generating a fourth Merkle root of the third block according to the second Merkle root and the third Merkle root;
[0115] Broadcast the fourth Merkle Root, the third Merkle Root, the second Merkle Root, the second transaction hash list including each second transaction, and the plurality of transactions to other blockchain nodes;
[0116] The following steps are performed for each second transaction: according to the transaction packaging rule, it is determined whether the second transaction should be packaged at the third block height: if not, the failure to execute the second transaction includes:
[0117] Determine whether the second Merkle root of the third block is the same as the first Merkle root:
[0118] If yes, then generate a fifth Merkle Root based on several transactions. If the fifth Merkle Root is the same as the third Merkle Root, generate a sixth Merkle Root based on the fifth Merkle Root and the first Merkle Root, and determine whether the sixth Merkle Root is the same as the fourth Merkle Root:
[0119] If yes, omit the following steps for each second transaction: determine whether the second transaction should be packaged at the third block height according to the transaction packaging rule; if no, execute the second transaction failure step.
[0120] The difference between the above embodiment and the previous embodiment is that N1 broadcasts not block (112), but the merkle root of block (112), merkleroot (112-first type of transaction), merkleroot (112-second type of transaction), the transaction hash list of each second transaction of block (112), and several transactions;
[0121] N2 and N3 generate merkleroot(112-second type of transaction)' based on the above transactions, and generate the merkleroot' of block(112) based on merkleroot(112-second type of transaction)' and merkleroot(112). If the merkleroot' of block(112) is the same as the merkleroot of block(112), it means that the transaction and the execution result of the transaction are completely consistent, then N2 and N3 omit the step of "performing the following steps for each second transaction: judging whether the second transaction should be packaged at the third block height according to the transaction packaging rule: if not, the execution of the second transaction fails";
[0122] Those skilled in the art should understand that the operation steps when the Merkle root' of block(112) is different from the Merkle root of block(112) can also be configured according to the file time requirement, for example, the configuration is: if the Merkle root' of block(112) is different from the Merkle root of block(112), N2 and N3 request the missing second transaction from N1 according to the transaction hash list of each second transaction of block(112), and after receiving the missing second transaction, perform the following steps for each requested second transaction: determine whether the requested second transaction should be packaged at the third block height according to the transaction packaging rule: if not, the execution of the requested second transaction fails.
[0123] In the above embodiment, when there are both the first type of transactions and the second type of transactions in the blockchain, the amount of data broadcast by N1 is reduced, and the throughput is further increased.
[0124] Preferably, the blockchain includes consensus nodes and non-consensus nodes, wherein the non-consensus nodes do not participate in the block consensus;
[0125] Generating a third block according to each second transaction in the second to-be-packaged queue at the third block height and broadcasting it to other blockchain nodes includes:
[0126] Generate a third block according to each second transaction in the second to-be-packaged queue at the third block height and broadcast it to other consensus nodes;
[0127] The third block is also used by other consensus nodes:
[0128] When the third block height is a block height that should not participate in the consensus, delete the third block;
[0129] The third block reached through consensus is also used to be broadcasted by each second blockchain node to first blockchain nodes and non-consensus nodes that are not second blockchain nodes.
[0130] In more embodiments, the third block reached by consensus may not be broadcast to non-consensus nodes according to actual needs, so non-consensus nodes do not need to store blocks locally, which is more convenient.
[0131] Preferably, the above method further comprises:
[0132] receiving a third block, and storing block data of the third block;
[0133] The third block is also used for each blockchain node to delete the block data of the third block after a third period of time.
[0134] Specifically, the front-end receives block(112) and stores the block data of block(112);
[0135] The blockchain node deletes the block data of block(112) after a period of time, that is, only the status data of block(112) is retained.
[0136] The above embodiment enables block data and state data to be stored separately, thereby increasing the upper limit of state data storage of blockchain nodes.
[0137] Further preferably, generating a third block according to each second transaction and broadcasting it to other blockchain nodes includes:
[0138] Perform the following operations on each second transaction: verify the executability of the second transaction, and when it is determined to be unexecutable, cache the second transaction hash of the second transaction, and delete the second transaction;
[0139] Receiving the third block and storing the block data of the third block includes:
[0140] receiving a third block and a third transaction hash list generated according to the second transaction hash of each deleted second transaction;
[0141] Update each second transaction in the second to-be-packed queue according to the third transaction hash list;
[0142] Generate the seventh Merkle root according to each updated second transaction;
[0143] When the seventh Merkle root is identical to the Merkle root in the third block, the block data of the third block is stored.
[0144] Specifically, since the front-end processor has no status data, it cannot identify the executability of the transaction, and the front-end processor will also store the unexecutable transaction in the queue to be packaged;
[0145] When N1 generates the third block, it verifies the executability of each second transaction: Assuming that tx10 is an unexecutable transaction, N1 caches hash(tx10) and deletes tx10. In fact, N1 generates block(112) based on tx1 and tx3 to tx9.
[0146] N1 sends block(112) and hash(tx10) to the front-end.
[0147] The front-end deletes tx10 from the waiting-for-packaging queue of block(112) according to hash(tx10); at this time, the waiting-for-packaging queue of block(112) of the front-end is updated to tx1, tx3~tx9;
[0148] The front-end generates a Merkle root based on tx1 and tx3 to tx9. If the generated Merkle root is the same as the Merkle root of block (112), the front-end stores the block data of block (112).
[0149] The above embodiments reduce the amount of data transmission between the blockchain node and the front-end processor.
[0150] Those skilled in the art can understand that the above-mentioned receiving the third block and the third transaction hash list generated according to the second transaction hash of each deleted second transaction can also be configured as "receiving the block data of the third block and the third transaction hash list generated according to the second transaction hash of each deleted second transaction" according to actual needs; accordingly, when the seventh Merkle root is the same as the Merkle root in the third block, storing the block data of the third block should be configured as "when the seventh Merkle root is the same as the Merkle root in the block data of the third block, storing the block data of the third block", which can achieve the same technical effect and further reduce the amount of data transmission between the blockchain node and the front-end.
[0151] Those skilled in the art can understand that each blockchain node only caches the block data of the third block, solving the problem of slow IO storage.
[0152] Figure 2 A schematic diagram of the structure of a device provided in one embodiment of the present invention.
[0153] like Figure 2 As shown, as another aspect, the present application also provides a device 200, including one or more central processing units (CPU) 201, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 202 or the program loaded from the storage part 208 to the random access memory (RAM) 203. In the RAM 203, various programs and data required for the operation of the device 200 are also stored. The CPU 201, the ROM 202, and the RAM 203 are connected to each other through a bus 204. An input / output (I / O) interface 205 is also connected to the bus 204.
[0154] The following components are connected to the I / O interface 205: an input section 206 including a keyboard, a mouse, etc.; an output section 207 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 208 including a hard disk, etc.; and a communication section 209 including a network interface card such as a LAN card, a modem, etc. The communication section 209 performs communication processing via a network such as the Internet. A drive 210 is also connected to the I / O interface 205 as needed. A removable medium 211, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 210 as needed, so that a computer program read therefrom is installed into the storage section 208 as needed.
[0155] 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 209, and / or installed from the removable medium 211.
[0156] As another aspect, the present application also provides a computer-readable storage medium, which may be a computer-readable storage medium included in the apparatus of the above embodiment; or a computer-readable storage medium that exists independently and is not assembled into the 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.
[0157] 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.
[0158] 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.
[0159] 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 transaction storage and block execution method, characterized in that: The method is applicable to a front-end processor, and includes: Perform the following operations on each first blockchain node of the blockchain: calculate the height of each first block that the first blockchain node should participate in consensus according to a preconfigured block consensus rule; wherein the block consensus rule includes the first public information of the first blockchain node, and each first blockchain node also performs this step; Receiving a first transaction; wherein the first transaction is generated by a client; Calculating a second block height at which the first transaction should be packaged according to a preconfigured transaction packaging rule that matches the block consensus rule; wherein the transaction packaging rule includes second public information of the first transaction, and a difference between the first block height and the current block height is greater than a first value; and, Storing the first transaction in a first to-be-packaged queue at the second block height; When the difference between the third block height and the current block height is a second value, each second transaction in the second to-be-packaged queue of the third block height is sent to each second blockchain node that should participate in the consensus of the third block height, so that each second blockchain node: When the third block at the third block height is packaged with the right, the third block is generated according to each of the second transactions and broadcast to other blockchain nodes, so that other blockchain nodes: When the third block height is a block height that should participate in consensus, determine whether the third block height is a block height that the second blockchain node that generates the third block should participate in consensus: If yes, then execute each of the second transactions to execute the third block; Among them, the second value is less than the first value, and the step of receiving the first transaction to the first to-be-packaged queue storing the first transaction in the second block height and the step of sending each second transaction in the second to-be-packaged queue of the third block height to each second blockchain node that should participate in the consensus of the third block height are executed in parallel.
2. The method according to claim 1, characterized in that The first public information is a node hash of the first blockchain node, the second public information is a first full hash of the first transaction, and the calculating, according to the preconfigured block consensus rule, the heights of each first block that the first blockchain node should participate in the consensus includes: Obtain the first M bits of the node hash of the first blockchain node, and calculate a first N-ary number based on the first M bits; Determine each fourth block height whose second N-ary number is the same as the first N-ary number as the first block height; wherein the second N-ary number is calculated as follows: (hmod N^M) === >>> (x2)2, (x2)2 = (x1)2, h is the fourth block height, (x1)2 is the first N-ary number, and (x2)2 is the second N-ary number; The calculating the second block height at which the first transaction should be packaged according to the preconfigured transaction packaging rule matching the block consensus rule comprises: Obtain the second M bits of the first full hash, and calculate a third N-ary number according to the second M bits; Calculate the fifth block height; wherein the calculation method of the fifth block height is: min(h1)mod N^M===>>>(x3)2, min(h1)>current block height+first value+1, min(h1) is the fifth block height, (x3)2 is the third N-ary number; and, Determine the fifth block height as the second block height; The determining whether the third block height is a block height at which the second blockchain node generating the third block should participate in consensus includes: Obtain the first N-ary number of the first M digits of the node hash of the second blockchain node that generates the third block; Calculate the fifth N-ary number; wherein the calculation method of the fifth N-ary number is: (h2mod N^M)===>>>(x5)2, h2 is the third block height, (x5)2 is the fifth N-ary number; Determine whether the first N-ary number of the first M digits of the node hash of the second blockchain node that generates the third block is the same as the fifth N-ary number.
3. The method according to claim 1, characterized in that Each of the first transactions is a first-type transaction that requires a specified block height, and a second-type transaction generated by the client that does not require a specified block height is cached in the transaction pool of each of the first blockchain nodes; The generating the third block according to each of the second transactions and broadcasting it to other blockchain nodes comprises: A third block is generated based on each of the second transactions and a number of transactions in the transaction pool and broadcasted to other blockchain nodes.
4. The method according to claim 1, characterized in that: The executing each of the second transactions to execute the third block comprises: The following steps are performed for each of the second transactions: judging whether the second transaction should be packaged at the third block height according to the transaction packaging rule: if not, the execution of the second transaction fails.
5. The method according to claim 4, characterized in that Each of the second transactions is further used for each of the second blockchain nodes to pre-generate a first Merkle root according to each of the second transactions when receiving each of the second transactions; The following steps are performed on each of the second transactions: judging whether the second transaction should be packaged at the third block height according to the transaction packaging rule: if not, then the failure to execute the second transaction includes: Determine whether the second Merkle root of the third block is the same as the first Merkle root: If yes, the following steps are omitted for each second transaction: judging whether the second transaction should be packaged at the third block height according to the transaction packaging rule; if no, executing the second transaction failure step.
6. The method according to claim 4, characterized in that The to-be-packaged queue of each blockchain node is configured with the same transaction sorting method, and each second transaction is also used for each second blockchain node to pre-generate a first Merkle root according to each second transaction when receiving each second transaction; The generating the third block according to each of the second transactions and broadcasting it to other blockchain nodes comprises: Generate the third block according to each second transaction in the second to-be-packaged queue of the third block height; Broadcasting the second Merkle root of the third block and the second transaction hash list including each of the second transactions to other blockchain nodes; The following steps are performed on each of the second transactions: judging whether the second transaction should be packaged at the third block height according to the transaction packaging rule: if not, then the failure to execute the second transaction includes: Determine whether the second Merkle root of the third block is the same as the first Merkle root: If yes, the following steps are omitted for each second transaction: judging whether the second transaction should be packaged at the third block height according to the transaction packaging rule; if no, executing the second transaction failure step.
7. The method according to claim 3, characterized in that The executing each of the second transactions to execute the third block comprises: The following steps are performed for each of the second transactions: judging whether the second transaction should be packaged at the third block height according to the transaction packaging rule: if not, the execution of the second transaction fails.
8. The method according to claim 7, characterized in that Each of the second transactions is further used for each of the second blockchain nodes to pre-generate a first Merkle root according to each of the second transactions when receiving each of the second transactions; The generating of the third block according to each of the second transactions and the plurality of transactions in the transaction pool and broadcasting the third block to other blockchain nodes comprises: generating a second Merkle root according to each of the second transactions, generating a third Merkle root according to the plurality of transactions, and generating a fourth Merkle root of the third block according to the second Merkle root and the third Merkle root; The following steps are performed on each of the second transactions: judging whether the second transaction should be packaged at the third block height according to the transaction packaging rule: if not, then the failure to execute the second transaction includes: Determine whether the second Merkle root in the third block is the same as the first Merkle root: If yes, the following steps are omitted for each second transaction: judging whether the second transaction should be packaged at the third block height according to the transaction packaging rule; if no, executing the second transaction failure step.
9. The method according to claim 7, characterized in that: The to-be-packaged queue of each blockchain node is configured with the same transaction sorting method, and each second transaction is also used for each second blockchain node to pre-generate a first Merkle root according to each second transaction when receiving each second transaction; The generating of the third block according to each of the second transactions and the plurality of transactions in the transaction pool and broadcasting the third block to other blockchain nodes comprises: generating a second Merkle root according to each of the second transactions, generating a third Merkle root according to the plurality of transactions, and generating a fourth Merkle root of the third block according to the second Merkle root and the third Merkle root; Broadcasting the fourth Merkle Root, the third Merkle Root, the second Merkle Root, the second transaction hash list including each of the second transactions, and the plurality of transactions to other blockchain nodes; The following steps are performed on each of the second transactions: judging whether the second transaction should be packaged at the third block height according to the transaction packaging rule: if not, then the failure to execute the second transaction includes: Determine whether the second Merkle root of the third block is the same as the first Merkle root: If yes, a fifth Merkle Root is generated according to the plurality of transactions. When the fifth Merkle Root is the same as the third Merkle Root, a sixth Merkle Root is generated according to the fifth Merkle Root and the first Merkle Root, and it is determined whether the sixth Merkle Root is the same as the fourth Merkle Root: If yes, the following steps are omitted for each second transaction: judging whether the second transaction should be packaged at the third block height according to the transaction packaging rule; if no, executing the second transaction failure step.
10. The method according to any one of claims 1 to 9, characterized in that: The blockchain includes consensus nodes and non-consensus nodes, wherein the non-consensus nodes do not participate in the block consensus; The generating the third block according to each second transaction in the second to-be-packaged queue of the third block height and broadcasting it to other blockchain nodes includes: Generate the third block according to each second transaction in the second to-be-packaged queue of the third block height and broadcast it to other consensus nodes; The third block is also used by other consensus nodes to: When the third block height is a block height that should not participate in consensus, deleting the third block; The third block reached through consensus is also used to be broadcasted by each of the second blockchain nodes to the first blockchain nodes and non-consensus nodes that are not the second blockchain nodes.
11. The method according to claim 1, characterized in that: Also includes: receiving the third block, and storing block data of the third block; The third block is also used for each blockchain node to delete the block data of the third block after a third period of time.
12. The method according to claim 11, characterized in that The generating the third block according to each of the second transactions and broadcasting it to other blockchain nodes comprises: Perform the following operations on each of the second transactions: verify the executability of the second transaction, and when it is determined to be unexecutable, cache the second transaction hash of the second transaction, and delete the second transaction; The receiving the third block and storing the block data of the third block includes: receiving the third block, and a third transaction hash list generated according to the second transaction hash of each deleted second transaction; Update each second transaction in the second to-be-packed queue according to the third transaction hash list; generating a seventh Merkle root according to each of the updated second transactions; When the seventh Merkle root is identical to the Merkle root in the third block, the block data of the third block is stored.
13. A computer device, characterized in that: The device comprises: 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 12.
14. 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 12 is implemented.
