Block generation method, device and electronic device in blockchain
By determining the node type in the blockchain network and ensuring that the transaction information has been verified and saved locally, the problem of nodes giving up verification is solved and the normal operation of the blockchain network is achieved.
Patent Information
- Application Number
- CN202210505439.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-10
- Publication Date
- 2025-09-16
- Estimated Expiration
- 2042-05-10
AI Technical Summary
Nodes in the blockchain network are prone to giving up verifying transaction information in the blocks to be generated, causing the network to be unable to operate normally.
By determining the node type of the current node in the blockchain when the time interval between the current time and the transaction start time is greater than the time required to verify the transaction information, and determining the block time based on the node type, it ensures that the transaction information has been verified and saved locally, avoiding the node giving up verification before knowing its own type.
It ensures the effective verification of transaction information in the blockchain network, ensures the normal operation of the blockchain network, and prevents nodes from passive verification behavior.
Smart Images

Figure CN114826586B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of blockchain, and in particular to a method, device and electronic device for generating blocks in a blockchain. Background Art
[0002] With the continuous development of science and technology, blockchain technology has been widely adopted across various industries due to its immutable data and decentralized nature. Specifically, blockchain technology utilizes a block chain data structure to verify and store data, a distributed node consensus algorithm to generate and update data, and cryptography to ensure the security of data transmission and access, making the information recorded more authentic and reliable than traditional networks.
[0003] During the blockchain network's block generation process, nodes consume significant computational resources to verify transactions. To compensate for this computational resource consumption, the blockchain network allocates rewards to participating nodes. Under these circumstances, these nodes have an incentive not to verify transactions. Instead, they simply provide approved transaction signatures to facilitate block generation, thereby conserving computational resources and reaping rewards. This can cause the blockchain network to malfunction.
[0004] To address the above-mentioned problems, no effective solutions have been proposed so far. Summary of the Invention
[0005] Embodiments of the present invention provide a method, device, and electronic device for generating blocks in a blockchain, so as to at least solve the technical problem in the prior art that blockchain nodes easily give up verifying transaction information in the blocks to be generated, causing the blockchain network to fail to operate normally.
[0006] According to one aspect of an embodiment of the present invention, a method for generating a block in a blockchain is provided, comprising: obtaining a transaction start time corresponding to transaction information to be recorded; determining a time interval between a current time and the transaction start time; when the time interval is greater than or equal to a preset duration, determining a node type of a current node in the blockchain, wherein the preset duration is greater than a verification duration, the verification duration being the duration for the current node to complete a verification operation on the transaction information to be recorded, and the node type indicating whether the current node can generate a target block; and determining a block generation time of a target block corresponding to the transaction information to be recorded based on the node type.
[0007] Furthermore, the block generation method in the blockchain also includes: after determining the time interval between the current time and the transaction start time, obtaining the target transaction duration corresponding to the transaction information to be recorded; calculating the product of the target transaction duration and a preset threshold to obtain the preset duration, wherein the preset threshold is a value greater than 1.
[0008] Furthermore, the block generation method in the blockchain also includes: obtaining a random value and a public key and a private key corresponding to the current node; verifying the identity of the current node based on the random value, the public key and the private key; and determining the node type of the current node based on the identity of the current node.
[0009] Furthermore, the block generation method in the blockchain also includes: performing hash calculation on the private key and the random value to obtain a first result; performing signature processing on the private key and the random value to obtain a second result; and verifying the identity of the current node based on the public key, the random value, the first result, and the second result.
[0010] Furthermore, the block generation method in the blockchain also includes: after determining the block generation time of the target block corresponding to the transaction information to be recorded based on the node type, if it is determined that the current node can generate the target block, consensus processing is performed on the target block to obtain a consensus result; if the consensus result indicates that the consensus is successful, the target block is put on the chain.
[0011] Furthermore, the block generation method in the blockchain also includes: detecting the identity of the node that generates the target block to obtain a first detection result; detecting whether the transaction information corresponding to the target block is correct to obtain a second detection result; detecting whether the transaction time range corresponding to the transaction information to be recorded is the target time range to obtain a third detection result; and determining a consensus result based on the first detection result, the second detection result, and the third detection result.
[0012] According to another aspect of an embodiment of the present invention, a block generation device in a blockchain is further provided, including: an acquisition module for acquiring a transaction start time corresponding to the transaction information to be recorded; a first determination module for determining the time interval between the current time and the transaction start time; a second determination module for determining the node type of the current node in the blockchain when the time interval is greater than or equal to a preset duration, wherein the preset duration is greater than the verification duration, the verification duration is the duration for the current node to complete the verification operation of the transaction information to be recorded, and the node type indicates whether the current node can generate a target block; and a processing module for determining the block generation time of the target block corresponding to the transaction information to be recorded based on the node type.
[0013] According to another aspect of an embodiment of the present invention, a computer-readable storage medium is further provided, wherein a computer program is stored in the computer-readable storage medium, wherein the computer program is configured to execute the above-mentioned method for generating blocks in the blockchain when running.
[0014] According to another aspect of an embodiment of the present invention, an electronic device is further provided, comprising one or more processors; a memory for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors are enabled to run the programs, wherein the programs are configured to execute the above-mentioned method for generating blocks in the blockchain during operation.
[0015] According to another aspect of an embodiment of the present invention, a computer program product is also provided, including a computer program / instruction, which, when executed by a processor, implements the above-mentioned method for generating blocks in the blockchain.
[0016] In an embodiment of the present invention, when the time interval between the current time and the transaction start time is greater than the time required to verify the transaction information, the node type and block time of the current node in the blockchain are determined. This method obtains the transaction start time corresponding to the transaction information to be recorded, then determines the time interval between the current time and the transaction start time. When the time interval is greater than or equal to a preset time interval, the node type of the current node in the blockchain is determined. This determines the block time of the target block corresponding to the transaction information to be recorded based on the node type. The preset time interval is greater than the verification time interval, which is the time it takes for the current node to complete the verification operation on the transaction information to be recorded. The node type indicates whether the current node can generate the target block.
[0017] In the above process, when the time interval between the current time and the transaction start time of the transaction information to be recorded is greater than the time required to verify the transaction information to be recorded, the node type of the current node in the blockchain is determined. This ensures that when the block-producing node determines its own node type, the transactions required to be recorded on the chain have already been verified and saved locally. This avoids the problem in the prior art where the node lacks verification time before knowing its own node type, and after knowing that its own node type is only used to verify the block, it abandons verification of the transaction information in the block, ensuring that the block-producing node effectively verifies the transaction information to be recorded. Furthermore, after determining the node type, the target block for recording the transaction information to be recorded is produced, ensuring that the transaction information in the target block is transaction information that has passed valid verification, thereby ensuring the normal operation of the blockchain network.
[0018] It can be seen that the solution provided by the present application achieves the purpose of determining the node type and block time of the current node in the blockchain when the time interval between the current time and the transaction start time is greater than the time required to verify the transaction information, thereby achieving the technical effect of ensuring the normal operation of the blockchain network, and further solving the technical problem in the prior art that the blockchain network cannot operate normally due to the fact that the blockchain nodes easily give up verifying the transaction information in the block to be generated. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0020] Figure 1 is a schematic diagram of an optional current node according to an embodiment of the present invention;
[0021] Figure 2 is a schematic diagram of an optional method for generating blocks in a blockchain according to an embodiment of the present invention;
[0022] Figure 3 is a schematic diagram of an optional blockchain network according to an embodiment of the present invention;
[0023] Figure 4 is a schematic diagram of an optional relationship between a target block and time according to an embodiment of the present invention;
[0024] Figure 5 This is a flowchart of an optional method for generating a block in a blockchain according to an embodiment of the present invention;
[0025] Figure 6 1 is a schematic diagram of an optional block generation device in a blockchain according to an embodiment of the present invention;
[0026] Figure 7 is a schematic diagram of an optional electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0027] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of the present invention.
[0028] It should be noted that the terms "first", "second", etc. in the description and claims of the present invention 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 numbers used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof 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 clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0029] First, some nouns or terms that appear in the description of the embodiments of the present application are subject to the following interpretations:
[0030] Block production process: The so-called block production process refers to the consensus process in the blockchain network, the process in which nodes record transactions on the chain through consensus. The block-producing nodes form blocks and broadcast them to other nodes in the network. When most nodes in the network have recorded the blocks, it is considered that the network has reached a consensus and the blocks have been recorded on the chain.
[0031] Negative Verification: Since all nodes participating in the block generation process can be rewarded, even if they only verify transaction information, and transaction verification requires computing resources, in this environment, nodes have an incentive not to verify transaction information. In other words, they can save computing resources and defraud profits by directly providing a signature that confirms the transaction is passed to facilitate block generation. This behavior is defined as negative verification.
[0032] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for display, data for analysis, etc.) involved in this disclosure are all information and data authorized by the user or fully authorized by all parties.
[0033] Example 1
[0034] According to an embodiment of the present invention, an embodiment of a log file generation method is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0035] In this embodiment, if Figure 1As shown, the current node in the blockchain network is the execution entity, and the current node includes at least a consensus node selection module, a transaction verification module, a consensus module, and a chain interaction module. The consensus node selection module can perform calculations based on relevant algorithms and on-chain information to determine whether the node meets the conditions for participating in the current round of block production. The transaction verification module can use a preset verification scheme to verify transactions in the network and blocks that are about to be agreed upon. The consensus module can use a preset consensus algorithm to reach consensus on blocks in the network and add them to the chain. The chain interaction module is used for information exchange between the node and the chain, including querying on-chain information and adding new blocks to the chain.
[0036] Figure 2 is a schematic diagram of an optional block generation method in a blockchain according to an embodiment of the present invention, such as Figure 2 As shown, the method includes the following steps:
[0037] Step S101: Obtain the transaction start time corresponding to the transaction information to be recorded.
[0038] In step S101, the transaction information to be recorded represents information to be recorded in a block to be produced. Optionally, the current node can obtain the latest block on the chain through the chain interaction module, that is, obtain the previous block corresponding to the block to be produced, and then determine the transaction start time corresponding to the transaction information to be recorded based on the information in the latest block on the chain. The latest block on the chain at least stores the transaction information digest info corresponding to the transaction information recorded in the latest block, and the transaction information digest info at least includes the block production time Tstart of the latest block. In the block production process described in this embodiment, the transaction start time of the transaction information recorded in each block is the same as the block production time of the previous block. Therefore, the transaction start time corresponding to the aforementioned transaction information to be recorded is the same as the block production time of the aforementioned latest block, thereby achieving the acquisition of the aforementioned transaction start time.
[0039] Step S102: determining the time interval between the current time and the transaction start time.
[0040] In step S102, the time interval between the current time t and the transaction start time can be determined by the consensus node selection module to facilitate subsequent determination of whether to judge the node type of the current node.
[0041] Step S103: When the time interval is greater than or equal to the preset duration, the node type of the current node in the blockchain is determined. The preset duration is greater than the verification duration, which is the time it takes for the current node to complete the verification operation on the transaction information to be recorded. The node type indicates whether the current node can generate the target block.
[0042] Optionally, in this embodiment, after the current node obtains the transaction information to be recorded, the current node will verify the transaction information to be recorded and save it locally for subsequent block generation. The consensus node selection module can determine whether the current node has completed the verification process based on whether the time interval is greater than or equal to a preset time length. If the time interval is greater than or equal to the preset time length, the node type of the current node in the blockchain is determined to ensure that before determining the node type, the transaction information required to be recorded on the chain, that is, the aforementioned transaction information to be recorded, has been verified and saved locally on the current node. The preset time length is at least greater than the time required to verify the transaction information to be recorded.
[0043] Furthermore, when the consensus node selection module determines that the time interval is greater than or equal to a preset duration, the consensus node selection module may determine the node type of the current node based on the information recorded in the transaction information summary info. Conversely, if the consensus node selection module determines that the time interval is less than the preset duration, indicating that the current node has not yet completed verification of the transaction information to be recorded, the consensus node selection module may continuously determine the aforementioned time interval at a preset frequency until the time interval is greater than or equal to the preset duration, thereby entering the node type determination phase.
[0044] Optional, such as Figure 3 As shown, node types include the first node type and the second node type. The first node type indicates that the current node can generate the target block. All nodes of the first node type in the blockchain can form a consensus group. The consensus group is used to generate the target block through a certain node in the current round, and the other nodes in the consensus group reach consensus on the target block. The second node type indicates that the current node cannot generate the target block and cannot participate in the consensus.
[0045] It's important to note that by determining the node type of the current node in the blockchain at a time interval greater than the time required to verify the transaction information to be recorded, by the time the block-producing node determines its own node type, the transactions required to be recorded on the chain have already been verified and stored locally. This avoids the problem in existing technologies where nodes lack verification time before knowing their own node type, and then abandon verification of transactions in the block after learning that their node type is only used to verify the block. For example, in the block production process based on consensus schemes such as Proof of Work and Proof of Stake, nodes verify and store transactions generated in the network, calculate a hash value that meets the block production conditions, and form a block, which is then broadcast to other nodes in the network for verification. Nodes record the verified blocks on their own blockchain ledgers. When a majority of nodes in the network record a block in their ledgers, consensus is considered reached within the network, and the block is recorded on the chain. In the block generation process based on consensus schemes such as Paxos, Raft, and PBFT, the master node collects transaction information, other nodes verify transactions, and return verification information to the master node. The master node determines whether a consensus has been formed and broadcasts the consensus information to the entire network. For both of the aforementioned block generation processes, the speed of block generation is the main optimization direction, and the timeliness of transaction on-chain is high, which means that nodes lack verification time before knowing their own node type. At the same time, in the first scheme mentioned above, all nodes in the network must compete in computing power, and the final block formation is the result of the calculation of only one node. In other words, except for the node that generates the target block, the computing power of all other nodes is wasted. As a result, after the nodes in the blockchain know that their node type is only used to verify the block, they are likely to give up verifying the transaction information in the block. Therefore, this application ensures that the block generation node effectively verifies the transaction information.
[0046] Step S104: Determine the block generation time of the target block corresponding to the transaction information to be recorded based on the node type.
[0047] In step S104, after the current node has determined its node type, that is, after all nodes in the blockchain network have determined their node types, the node whose node type indicates that the node can generate the target block can start the block generation process, that is, each node in the blockchain network can determine the block generation time of the target block, wherein the target block is the aforementioned block that is about to be generated, thereby achieving delayed block generation of the target block.
[0048] It should be noted that since the time it takes to determine the node type is a certain distance away from the transaction start time, the target block is generated after the node type is determined, achieving delayed generation of the target block. This ensures that the transaction information in the target block is valid and verified, thereby ensuring the normal operation of the blockchain network.
[0049] Based on the scheme defined in steps S101 to S104 above, it can be seen that in an embodiment of the present invention, when the time interval between the current time and the transaction start time is greater than the time required to verify the transaction information, the node type and block time of the current node in the blockchain are determined. By obtaining the transaction start time corresponding to the transaction information to be recorded, and then determining the time interval between the current time and the transaction start time, and when the time interval is greater than or equal to the preset time, the node type of the current node in the blockchain is determined, thereby determining the block time of the target block corresponding to the transaction information to be recorded based on the node type. Among them, the preset time is greater than the verification time, the verification time is the time it takes for the current node to complete the verification operation on the transaction information to be recorded, and the node type indicates whether the current node can generate the target block.
[0050] It is easy to notice that in the above process, by determining the node type of the current node in the blockchain when the time interval between the current time and the transaction start time of the transaction information to be recorded is greater than the time required to verify the transaction information to be recorded, when the block-producing node determines its own node type, the transactions that need to be recorded on the chain have already been verified and saved locally, thereby avoiding the problem in the prior art that the node lacks verification time before knowing its own node type, and after knowing that its own node type is only used to verify the block, it abandons verification of the transaction information in the block, ensuring that the block-producing node effectively verifies the transaction information to be recorded. Furthermore, after determining the node type, the target block for recording the transaction information to be recorded is produced, ensuring that the transaction information in the target block is transaction information that has passed effective verification, thereby ensuring the normal operation of the blockchain network.
[0051] It can be seen that the solution provided by the present application achieves the purpose of determining the node type and block time of the current node in the blockchain when the time interval between the current time and the transaction start time is greater than the time required to verify the transaction information, thereby achieving the technical effect of ensuring the normal operation of the blockchain network, and further solving the technical problem in the prior art that the blockchain network cannot operate normally due to the fact that the blockchain nodes easily give up verifying the transaction information in the block to be generated.
[0052] In an optional embodiment, after determining the time interval between the current time and the transaction start time, the consensus node selection module can obtain the target transaction duration corresponding to the transaction information to be recorded, and calculate the product of the target transaction duration and a preset threshold to obtain the preset duration, where the preset threshold is a value greater than 1.
[0053] Optionally, in this embodiment, if Figure 4As shown, the transaction time interval length of each block is T, that is, the target transaction time length corresponding to the transaction time of the transaction information to be recorded is T. Therefore, the transaction time of the transaction information to be recorded is within the interval [Tstart, Tstart+T), where Tstart is the transaction start time.
[0054] Specifically, when the current block acquires transaction information to be recorded whose transaction time is within the interval [Tstart, Tstart+T), the current block can verify the transaction information to be recorded after the acquisition is completed, or it can begin verification of the transaction information to be recorded during the acquisition process. In either of the aforementioned verification methods, it can be seen that the verification end time will always be later than the completion time of the acquisition of the transaction information to be recorded by the current block. Therefore, the preset duration can be determined based on the target transaction duration.
[0055] Furthermore, the consensus node selection module determines the preset duration based on the product of the target transaction duration and the preset threshold, wherein the preset threshold is a value greater than 1, preferably, the preset threshold is 2. Figure 2 As shown, when the time interval between the current time t and the transaction start time Tstart is greater than or equal to 2 times the target transaction duration T, it is determined that the time interval is greater than or equal to the preset duration, and subsequent calculations are performed to extend the block generation.
[0056] It should be noted that by determining the preset duration based on the target transaction duration, it is ensured that the current node can complete the verification and preservation process of the transaction information to be recorded within the preset duration, thereby ensuring the normal operation of the blockchain network.
[0057] In an optional embodiment, in the process of determining the node type of the current node in the blockchain, the consensus node selection module can obtain a random value and a public key and a private key corresponding to the current node, and then verify the identity of the current node based on the random value, the public key, and the private key, thereby determining the node type of the current node based on the identity of the current node.
[0058] Optionally, in this embodiment, the consensus node selection module may obtain a random value based on the aforementioned transaction information digest (info) or other information. The random value is represented by a random seed in a verifiable random function (VRF). That is, the consensus node selection module may utilize the verifiable random function (VRF) to verify the identity of the current node based on the random value, public key, private key, and pre-set access conditions. Optionally, when verification succeeds, the current node's identity is characterized as authentic and meeting the access conditions. When verification fails, the current node's identity is characterized as false or failing to meet the access conditions. Thus, the node type of a node that meets the access conditions and is authentic can be determined as a node capable of generating a target block, i.e., the aforementioned first node type. The node type of a node that is false or failing to meet the access conditions can be determined as a node unable to generate a target block, i.e., the aforementioned second node type. A node with an authentic identity indicates that it is a node in the current blockchain, while a node with an false identity indicates that it is not a node in the current blockchain.
[0059] It should be noted that by determining the node type of the current node based on the random value, public key and private key, effective screening of nodes that can generate target blocks in the blockchain network is achieved, thereby reducing the number of nodes involved in the block production process and reducing the loss of computing power in the network.
[0060] In an optional embodiment, in the process of verifying the identity of the current node based on the random value, the public key and the private key, the consensus node selection module can perform a hash calculation on the private key and the random value to obtain a first result, and then sign the private key and the random value to obtain a second result, thereby verifying the identity of the current node based on the public key, the random value, the first result and the second result.
[0061] Optionally, a verifiable random function is a combination of a hash function and a cryptographic signature algorithm, used to generate random numbers that can be verified by other nodes.
[0062] The consensus node selection module can calculate the following formula based on the verifiable random function VRF:
[0063] result = VRF_HASH(SK,seed)
[0064] Among them, result represents the first result, VRF_HASH() represents the hash calculation, SK represents the private key corresponding to the current node, and seed represents the random value.
[0065] Furthermore, the consensus node selection module can also calculate the following formula based on the verifiable random function VRF:
[0066] proof = VRF_PROOF(SK,seed)
[0067] Among them, proof represents the second result, VRF_PROOF() represents the signature processing, SK represents the private key corresponding to the current node, and seed represents the random value.
[0068] Furthermore, the consensus node selection module can use the verification random function VRF to perform preliminary verification on the identity of the current node. The formula is as follows:
[0069] result==VRF_VERIFY(PK,seed,proof)
[0070] Here, result represents the first result, VRF_VERIFY() represents the verification function, PK represents the public key corresponding to the current node, seed represents the random value, and proof represents the second result. It should be noted that the first result, result, is calculated using the current node's private key and cannot be reproduced by other nodes. Due to the unpredictability of hash functions, the value of the first result, result, cannot be predicted until the random value seed is known.
[0071] Optionally, after initially verifying the identity of the current node based on the Verification Random Function (VRF) and confirming that the aforementioned equation holds true, i.e., confirming the authenticity of the current node's identity, the consensus node selection module can determine whether the generated first result (result) meets the access conditions based on the configured access rules, thereby determining the identity of the current node. If the current node meets the access conditions, the current node and other nodes that meet the conditions are determined to be the first node type to form a consensus group and participate in the current round of block production. Conversely, if the conditions are not met, the current node does not participate in the current round of block production and continues to compare the time interval with the preset conditions to determine whether it can participate in the next round of block production. The blockchain network can adjust the difficulty of the access conditions met by the first result (result) as needed to control the proportion of nodes participating in the block production process relative to the total number of nodes in the blockchain network.
[0072] It should be noted that by using a verifiable random function to determine the identity of the current node, in order to determine whether the current node can generate the target block, the randomness of the nodes participating in the block generation process is guaranteed, and the occurrence of node collusion is prevented.
[0073] In an optional embodiment, after determining the block time of the target block corresponding to the transaction information to be recorded based on the node type, the consensus module can perform consensus processing on the target block when it is determined that the current node can generate the target block, obtain a consensus result, and when the consensus result indicates that the consensus is successful, the target block is put on the chain.
[0074] Optionally, if it is determined that the current node is capable of generating the target block, the current node forms a consensus group with other nodes of the first node type. The nodes in the consensus group organize the transaction information to be recorded and packaged in the target block, and then generate the target block based on a preset consensus mechanism. Subsequently, the current node and other nodes in the consensus group, that is, all nodes in the consensus group, reach a consensus on the target block based on the consensus module. When all nodes reach consensus on the target block, a consensus result is generated. Based on the consensus result, it can be determined whether to put the target block on the chain. The consensus module can use different consensus algorithms depending on different scenarios.
[0075] Furthermore, when the consensus result indicates that the consensus is successful, the current node can use the chain interaction module to save the target block that has passed the consensus on the chain. The target block at least includes the transaction information summary info corresponding to the transaction information to be recorded, and the transaction information summary info corresponding to the transaction information to be recorded at least includes the block time of the target block. Other nodes in the blockchain network can also obtain the target block information through the chain interaction module, thereby completing this round of block generation.
[0076] It should be noted that by reaching a consensus on the target block and, if the consensus is successful, uploading the target block to the chain, the authenticity and validity of the information in the blockchain can be guaranteed, thereby improving the security of the blockchain.
[0077] In an optional embodiment, in the process of performing consensus processing on the target block and obtaining a consensus result, the transaction verification module can detect the identity of the node that generates the target block to obtain a first detection result, and detect whether the transaction information corresponding to the target block is correct to obtain a second detection result, and detect whether the transaction time range corresponding to the transaction information to be recorded is the target time range to obtain a third detection result, thereby determining the consensus result based on the first detection result, the second detection result, and the third detection result.
[0078] Optionally, the transaction verification module can use a verifiable random function to verify the identity of the node that generates the target block based on the aforementioned verification method for the identity of the current node to obtain a first detection result, so it will not be repeated here.
[0079] Furthermore, the transaction verification module can verify the transaction information corresponding to the target block, check the correctness of the transaction information in the target block, and obtain a second detection result.
[0080] Furthermore, the transaction verification module can verify the transaction time range based on the target time range, where the target time range is [t-2T, tT), where t represents the current time and T represents the target transaction duration, thereby obtaining a third detection result.
[0081] Afterwards, a consensus result is determined based on the first test result, the second test result, and the third test result. If the first test result indicates that the node generating the target block is a node with a real identity and meets the access conditions, and the second test result indicates that the transaction information in the target block is correct, and the third test result indicates that the transaction time range is the target time range, the consensus result is determined to indicate a consensus success; otherwise, the consensus result is determined to indicate a consensus failure.
[0082] It should be noted that the consensus result is determined by detecting the identity of the node that generated the target block, the transaction information corresponding to the target block, and the transaction time corresponding to the transaction information, thereby achieving effective consensus on the content of the target block.
[0083] like Figure 5 As shown, an optional working process of the present application is described. First, the block-producing node can obtain the transaction information summary info stored in the latest block on the chain through the chain interaction module to determine the transaction start time and determine whether the current time t satisfies t-Tstart>=2T, where Tstart represents the transaction start time and T represents the target transaction duration. If the above conditions are not met, the current node re-executes the above judgment process at a preset frequency. If they are met, the transaction information summary info, the current node's private key, and the public key are passed to the consensus node selection module for calculation to obtain the first result and the second result. Then, based on the first and second results, the identity of the current node and whether it meets the entry conditions are determined. If so, a consensus group is formed based on the current node and other nodes that meet the entry conditions, and a target block is generated for consensus processing. If consensus is successful, the block is produced and the target block is uploaded to the chain, completing this round of work. Conversely, if the first and second results do not meet the entry conditions, the current node re-executes the above judgment process for the current time t at a preset frequency. This completes a cycle, thereby ensuring the normal operation of the blockchain.
[0084] It should be noted that in the method provided in the present application, the consensus node group is randomly selected through a verifiable random function, which narrows the scope of nodes participating in the consensus and reduces the waste of computing power. Through the mechanism of delayed block generation, when the current node determines the node type of this node, the transaction information that needs to be recorded on the chain has been verified and saved locally on the current node, thereby eliminating the situation of negative node verification, and further ensuring that in the blockchain network, the nodes have no malicious motives, and can normally perform transaction verification and block generation on the basis of complying with the network operation rules, thereby solving the problem of the blockchain network not being able to operate normally in the existing technology.
[0085] It can be seen that the solution provided by the present application achieves the purpose of determining the node type and block time of the current node in the blockchain when the time interval between the current time and the transaction start time is greater than the time required to verify the transaction information, thereby achieving the technical effect of ensuring the normal operation of the blockchain network, and further solving the technical problem in the prior art that the blockchain network cannot operate normally due to the fact that the blockchain nodes easily give up verifying the transaction information in the block to be generated.
[0086] Example 2
[0087] According to an embodiment of the present invention, an embodiment of a block generation device in a blockchain is provided, wherein: Figure 6 is a schematic diagram of an optional block generation device in a blockchain according to an embodiment of the present invention, such as Figure 6 As shown, the device includes:
[0088] An acquisition module 601 is used to acquire the transaction start time corresponding to the transaction information to be recorded;
[0089] A first determining module 602 is configured to determine the time interval between the current time and the transaction start time;
[0090] A second determination module 603 is configured to determine the node type of the current node in the blockchain when the time interval is greater than or equal to a preset duration, wherein the preset duration is greater than a verification duration, the verification duration being the time it takes for the current node to complete a verification operation on the transaction information to be recorded, and the node type indicating whether the current node can generate a target block;
[0091] The processing module 604 is used to determine the block generation time of the target block corresponding to the transaction information to be recorded based on the node type.
[0092] It should be noted that the above-mentioned acquisition module 601, first determination module 602, second determination module 603 and processing module 604 correspond to steps S101 to S104 in the above-mentioned embodiment. The examples and application scenarios implemented by the three modules and the corresponding steps are the same, but are not limited to the contents disclosed in the above-mentioned embodiment 1.
[0093] Optionally, the block generation device in the blockchain also includes: a first sub-acquisition module, used to obtain the target transaction duration corresponding to the transaction information to be recorded; a first calculation module, used to calculate the product of the target transaction duration and a preset threshold to obtain the preset duration, wherein the preset threshold is a value greater than 1.
[0094] Optionally, the second determination module also includes: a second sub-acquisition module, used to obtain a random value and the public key and private key corresponding to the current node; a first verification module, used to verify the identity of the current node based on the random value, public key and private key; and a first sub-determination module, used to determine the node type of the current node based on the identity of the current node.
[0095] Optionally, the verification module also includes: a second calculation module, used to perform hash calculation on the private key and the random value to obtain a first result; a signature module, used to sign the private key and the random value to obtain a second result; and a second verification module, used to verify the identity of the current node based on the public key, the random value, the first result and the second result.
[0096] Optionally, the block generation device in the blockchain also includes: a consensus module, which is used to perform consensus processing on the target block and obtain a consensus result when it is determined that the current node can generate the target block; and a sub-processing module, which is used to perform on-chain processing on the target block when the consensus result indicates that the consensus is successful.
[0097] Optionally, the consensus module also includes: a first detection module, used to detect the identity of the node that generates the target block to obtain a first detection result; a second detection module, used to detect whether the transaction information corresponding to the target block is correct to obtain a second detection result; a third detection module, used to detect whether the transaction time range corresponding to the transaction information to be recorded is the target time range to obtain a third detection result; a second sub-determination module, used to determine the consensus result based on the first detection result, the second detection result, and the third detection result.
[0098] Example 3
[0099] According to another aspect of an embodiment of the present invention, a computer-readable storage medium is further provided, in which a computer program is stored. The computer program is configured to execute the above-mentioned method for generating blocks in the blockchain when running.
[0100] Example 4
[0101] According to another aspect of an embodiment of the present invention, an electronic device is provided, wherein: Figure 7 is a schematic diagram of an optional electronic device according to an embodiment of the present invention, such as Figure 7As shown, the electronic device includes one or more processors; a memory for storing one or more programs, which, when executed by the one or more processors, enables the one or more processors to run the programs, wherein the programs are configured to execute the block generation method in the above-mentioned blockchain when running.
[0102] Example 5
[0103] According to another aspect of an embodiment of the present invention, a computer program product is also provided, including a computer program / instruction, which, when executed by a processor, implements the above-mentioned method for generating blocks in the blockchain.
[0104] The serial numbers of the above embodiments of the present invention are for description only and do not represent the advantages or disadvantages of the embodiments.
[0105] In the above embodiments of the present invention, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0106] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only exemplary. For example, the division of units can be a logical function division. In actual implementation, there may be other division methods, 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 through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0107] Units described as separate components may or may not be physically separate, and components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple units. Some or all of the units may be selected to achieve the purpose of the present embodiment according to actual needs.
[0108] In addition, the functional units in the various embodiments of the present invention may be integrated into a single processing unit, each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0109] 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 invention, 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. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, server or network device, etc.) to execute all or part of the steps of the methods of each embodiment of the present invention. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, magnetic disk or optical disk, etc. Various media that can store program codes.
[0110] The above are only preferred embodiments of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A method for generating a block in a blockchain, characterized in that: include: Obtain the transaction start time corresponding to the transaction information to be recorded; Determining the time interval between the current time and the transaction start time; When the time interval is greater than or equal to a preset duration, determining the node type of the current node in the blockchain, wherein the preset duration is greater than a verification duration, the verification duration being the duration for the current node to complete a verification operation on the transaction information to be recorded, and the node type indicates whether the current node can generate a target block; Determining a block generation time of a target block corresponding to the transaction information to be recorded based on the node type; After determining the time interval between the current time and the transaction start time, the method further includes: Obtaining the target transaction duration corresponding to the transaction information to be recorded; Calculating the product of the target transaction duration and a preset threshold to obtain the preset duration, wherein the preset threshold is a value greater than 1; When the time interval is greater than or equal to a preset duration, determining the node type of the current node in the blockchain further includes: performing preliminary verification on the identity of the current node, and determining whether the identity of the node meets the access conditions according to preset access rules; if so, determining that the node participates in the block generation process of the target block; if not, determining that the node does not participate in the block generation process of the target block; wherein the blockchain adjusts the difficulty of the access conditions according to demand.
2. The method according to claim 1, characterized in that Determining a node type of a current node in a blockchain, the method comprising: Obtain a random value and the public key and private key corresponding to the current node; Verify the identity of the current node based on the random value, the public key, and the private key; A node type of the current node is determined based on the identity of the current node.
3. The method according to claim 2, characterized in that Verifying the identity of the current node based on the random value, the public key, and the private key includes: Performing a hash calculation on the private key and the random value to obtain a first result; Performing a signing process on the private key and the random value to obtain a second result; The identity of the current node is verified based on the public key, the random value, the first result, and the second result.
4. The method according to claim 2, characterized in that After determining the block generation time of the target block corresponding to the transaction information to be recorded based on the node type, the method further includes: When it is determined that the current node is capable of generating the target block, performing consensus processing on the target block to obtain a consensus result; When the consensus result indicates that the consensus is successful, the target block is put on the chain.
5. The method according to claim 4, characterized in that Performing consensus processing on the target block to obtain a consensus result, including: Detecting the identity of the node that generated the target block to obtain a first detection result; Detecting whether the transaction information corresponding to the target block is correct, and obtaining a second detection result; detecting whether a transaction time range corresponding to the transaction information to be recorded is a target time range, and obtaining a third detection result; The consensus result is determined based on the first detection result, the second detection result, and the third detection result.
6. A block generation device in a blockchain, characterized in that: include: An acquisition module is used to obtain the transaction start time corresponding to the transaction information to be recorded; A first determining module, configured to determine a time interval between the current time and the transaction start time; A second determination module is configured to determine a node type of a current node in the blockchain when the time interval is greater than or equal to a preset duration, wherein the preset duration is greater than a verification duration, the verification duration being the duration for the current node to complete a verification operation on the transaction information to be recorded, and the node type indicates whether the current node can generate a target block; A processing module, configured to determine, based on the node type, a block generation time of a target block corresponding to the transaction information to be recorded; The device further includes: a first sub-acquisition module, configured to acquire a target transaction duration corresponding to the transaction information to be recorded; a first calculation module, configured to calculate the product of the target transaction duration and a preset threshold value to obtain the preset duration, wherein the preset threshold value is a value greater than 1; The second determination module is further configured to perform preliminary verification on the identity of the current node and determine whether the identity of the node meets the access conditions according to preset access rules; if so, the node is determined to participate in the target block generation process; if not, the node is determined not to participate in the target block generation process; wherein the blockchain adjusts the access condition difficulty according to demand.
7. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, wherein the computer program is configured to execute the method for generating a block in a blockchain as described in any one of claims 1 to 5 when running.
8. An electronic device, characterized in that: The electronic device includes one or more processors; A memory for storing one or more programs, which, when executed by the one or more processors, enables the one or more processors to run the programs, wherein the programs are configured to execute the block generation method in the blockchain described in any one of claims 1 to 5 when running.
9. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, a method for producing a block in a blockchain according to any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
A method and system for block packing and verification of block chain based on node capability
CN109039646A