Block generation difficulty adjustment methods, devices, equipment and media in blockchain
By dynamically adjusting the block generation difficulty based on the logical clock line and the desired single-chain extension speed in a parallel multi-chain blockchain structure, the problem of inconsistent extension speeds of different sub-blockchains in the blockchain system is solved, thereby improving security and performance stability.
Patent Information
- Application Number
- CN202211007824.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-22
- Publication Date
- 2025-10-31
- Estimated Expiration
- 2042-08-22
AI Technical Summary
In a parallel multi-chain blockchain, the security of the blockchain system is difficult to guarantee due to the inconsistent extension speed of different sub-blockchains and the lack of an effective method for adjusting the difficulty of block generation, especially when the network size or computing power investment changes.
By selecting a bootstrap block based on the logical clock of the blocks in the local node's blockchain when generating new blocks, determining the logical clock line, and dynamically adjusting the block generation difficulty of the current difficulty adjustment cycle based on the expected single-chain extension speed and the block generation difficulty and speed of the previous difficulty adjustment cycle, the extension speed of the blockchain is made consistent with or tends to be consistent with the expected single-chain extension speed.
It improves the security of the blockchain system, avoids the adverse effects of excessively fast or slow block generation speed, and maintains the stable performance of the blockchain system.
Smart Images

Figure CN115422287B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of blockchain, and in particular relates to a method, device, equipment and medium for adjusting the difficulty of block generation in a blockchain. Background Technology
[0002] A blockchain system can include multiple nodes, each storing a portion of the blockchain data. The blockchains across different nodes must remain consistent. A blockchain is a chain of blocks, each containing information. Due to its tamper-proof and decentralized nature, blockchain technology is increasingly being adopted in various application areas.
[0003] In the scenario of a parallel multi-chain blockchain structure, which includes multiple sub-blockchains, the expansion speed of different sub-blockchains is not the same and there is a gradual divergence trend. There is a lack of methods to adjust the difficulty of block generation in the blockchain. When factors such as network size or computing power investment change, the security of the blockchain system is difficult to guarantee. Summary of the Invention
[0004] This application provides a method, apparatus, device, and medium for adjusting the difficulty of block generation in a blockchain, which can dynamically adjust the difficulty of block generation and improve the security of the blockchain.
[0005] In a first aspect, embodiments of this application provide a method for adjusting the difficulty of block generation in a blockchain, comprising: when generating a new block, selecting a pilot block for the new block based on the logical clock of the blocks in the blockchain of a local node, wherein the blockchain includes two or more sub-blockchains; determining the logical clock line where the new block is located based on the pilot pointing relationship between blocks in the blockchain, wherein the logical clock line is a path pointing to the genesis block along the pilot pointing relationship; determining the block generation difficulty corresponding to the current difficulty adjustment period to which the new block belongs based on the expected single-chain extension speed, the block generation difficulty corresponding to the previous difficulty adjustment period in the logical clock line, and the block generation speed; and generating a block according to the target block generation difficulty in the current difficulty adjustment period, wherein the target block generation difficulty is greater than or equal to the block generation difficulty corresponding to the current difficulty adjustment period.
[0006] Secondly, embodiments of this application provide a blockchain block generation difficulty adjustment device, comprising: a guiding block determination module, used to select a guiding block for a new block when generating a new block, based on the logical clock of the blocks in the blockchain of a local node, wherein the blockchain includes two or more sub-blockchains; a logical clock line determination module, used to determine the logical clock line where the new block is located based on the guiding pointing relationship between blocks in the blockchain, wherein the logical clock line is a path pointing to the genesis block along the guiding pointing relationship; a calculation module, used to determine the block generation difficulty corresponding to the current difficulty adjustment period to which the new block belongs, based on the expected single-chain extension speed, the block generation difficulty corresponding to the previous difficulty adjustment period in the logical clock line, and the block generation speed; and an execution module, used to generate a block according to the target block generation difficulty in the current difficulty adjustment period, wherein the target block generation difficulty is greater than or equal to the block generation difficulty corresponding to the current difficulty adjustment period.
[0007] Thirdly, embodiments of this application provide a node device, including: a processor and a memory storing computer program instructions; when the processor executes the computer program instructions, it implements the method for adjusting the difficulty of block generation in the blockchain according to the first aspect.
[0008] Fourthly, embodiments of this application provide a computer-readable storage medium storing computer program instructions, which, when executed by a processor, implement the block generation difficulty adjustment method in the blockchain of the first aspect.
[0009] This application provides a method, apparatus, device, and medium for adjusting block generation difficulty in a blockchain. When generating a new block, the logical clock line where the new block resides can be determined based on the guiding relationship between blocks in the local node's blockchain. By utilizing the desired single-chain extension speed, the block generation difficulty corresponding to the previous difficulty adjustment cycle in the logical clock line, and the block generation speed, the block generation difficulty corresponding to the current difficulty adjustment cycle to which the new block belongs can be determined. In the current difficulty adjustment cycle, blocks are generated with a target block generation difficulty greater than or equal to the block generation difficulty corresponding to the current difficulty adjustment cycle. The block generation difficulty and block generation speed within the same difficulty adjustment cycle are negatively correlated. By comparing the block generation speed corresponding to the previous difficulty adjustment cycle with the desired single-chain extension speed, it can be determined whether to increase or decrease the block generation difficulty based on the block generation difficulty corresponding to the previous difficulty adjustment cycle, thereby obtaining the block generation difficulty corresponding to the current difficulty adjustment cycle and compensating for the adverse effects of an excessively fast or slow block generation speed in the previous difficulty adjustment cycle. When factors such as network size or computing power investment change, the difficulty of block generation can be dynamically adjusted so that the extension speed of the blockchain can be consistent with or approach the expected extension speed of a single chain, thus keeping the difficulty of block generation within a safe range and improving the security of the blockchain system. Attached Figure Description
[0010] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments of this application will be briefly introduced below. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0011] Figure 1 A schematic diagram illustrating an example of a parallel multi-chain structure blockchain provided in an embodiment of this application;
[0012] Figure 2 A schematic diagram of another example of a parallel multi-chain structure blockchain provided in the embodiments of this application;
[0013] Figure 3 A flowchart of a method for adjusting the difficulty of block generation in a blockchain, provided as an embodiment of this application;
[0014] Figure 4 A schematic diagram illustrating an example of a logical clock line in a blockchain provided in this application embodiment;
[0015] Figure 5 A flowchart of a method for adjusting the difficulty of block generation in a blockchain, provided in another embodiment of this application;
[0016] Figure 6 A flowchart of a method for adjusting the difficulty of block generation in a blockchain, provided as another embodiment of this application;
[0017] Figure 7 A flowchart of a method for adjusting the difficulty of block generation in a blockchain, provided as another embodiment of this application;
[0018] Figure 8 A schematic diagram of a blockchain block generation difficulty adjustment device provided in an embodiment of this application;
[0019] Figure 9 This is a schematic diagram of the structure of a node device provided in an embodiment of this application. Detailed Implementation
[0020] The features and exemplary embodiments of various aspects of this application will be described in detail below. To make the objectives, technical solutions, and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only intended to explain this application and not to limit it. For those skilled in the art, this application can be implemented without some of these specific details. The following description of the embodiments is merely to provide a better understanding of this application by illustrating examples.
[0021] A blockchain system can include multiple nodes, each storing the blockchain data, and these blockchains across different nodes must remain consistent. A node can be implemented as one or more node devices; the number and type of node devices are not limited here. A blockchain is a chain of multiple blocks, each storing information. Due to its tamper-proof and decentralized characteristics, blockchain is gradually being adopted in various application areas. Blockchain structures are also diverse; for example, a parallel multi-chain structure can be included. A parallel multi-chain blockchain can include multiple sub-blockchains, each containing multiple blocks. Newly generated blocks can be randomly assigned to any of the sub-blockchains, resulting in varying expansion speeds across different sub-blockchains and a tendency for them to diverge. In this scenario, the lack of a method to adjust the difficulty of block generation makes it difficult to guarantee the security of the blockchain system when factors such as network size or computing power investment change, as the block generation difficulty cannot be adjusted.
[0022] The block generation difficulty adjustment method, apparatus, device, and medium provided in this application can be applied to scenarios involving parallel multi-chain blockchains. A parallel multi-chain blockchain may include multiple sub-blockchains. A parallel multi-chain blockchain may include one or more genesis blocks, where the genesis block is the earliest constructed block. Each sub-blockchain includes one genesis block. For example, Figure 1 A schematic diagram illustrating an example of a parallel multi-chain blockchain structure provided in this application embodiment, as shown below. Figure 1 As shown, this parallel multi-chain blockchain structure includes three sub-blockchains: sub-blockchain A1, sub-blockchain A2, and sub-blockchain A3. Sub-blockchains A1, A2, and A3 share a single genesis block G1. For example, Figure 2 A schematic diagram illustrating another example of a parallel multi-chain blockchain structure provided in this application embodiment, as shown below. Figure 2 As shown, this parallel multi-chain blockchain structure includes three sub-blockchains: sub-blockchain A4, sub-blockchain A5, and sub-blockchain A6. Sub-blockchains A4 and A5 share a genesis block G2, and sub-blockchain A6 includes a genesis block G3.
[0023] The method, apparatus, device, and medium for adjusting the block generation difficulty in a blockchain provided in this application can determine the logical clock line where a new block resides based on the guiding relationship between blocks in the local node's blockchain when generating a new block. By utilizing the desired single-chain extension speed, the block generation difficulty corresponding to the previous difficulty adjustment cycle in the logical clock line, and the block generation speed, the block generation difficulty corresponding to the current difficulty adjustment cycle to which the new block belongs can be determined. In the current difficulty adjustment cycle, blocks are generated according to a target block generation difficulty greater than or equal to the block generation difficulty corresponding to the current difficulty adjustment cycle. This allows for dynamic adjustment of the block generation difficulty even when factors such as network size or computing power investment change, ensuring that the blockchain extension speed is consistent with or approaches the desired single-chain extension speed, thereby improving the security of the blockchain system.
[0024] The following sections describe the methods, devices, equipment, and media for adjusting the difficulty of block generation in blockchain.
[0025] The first aspect of this application provides a method for adjusting the difficulty of block generation in a blockchain. This method can be executed by a device for adjusting the difficulty of block generation in a blockchain or a node device, etc., and is not limited thereto. Figure 3 A flowchart of a method for adjusting the difficulty of block generation in a blockchain provided in an embodiment of this application is shown below. Figure 3 As shown, the block generation difficulty adjustment method in this blockchain may include steps S101 to S104.
[0026] In step S101, when generating a new block, the bootstrap block of the new block is selected according to the logical clock of the blocks in the local node's blockchain.
[0027] A blockchain may consist of two or more sub-blockchains, and each sub-blockchain may include multiple blocks. For details, please refer to the relevant explanation above, which will not be repeated here.
[0028] A blockchain system may include multiple nodes. A local node can be the node that generates a new block; that is, when generating a new block, the node that generates the new block is considered a local node. The block generation difficulty adjustment method in the blockchain of this application embodiment can be executed by the local node. This application embodiment does not limit the way new blocks are generated. For example, a method based on proof-of-work, a method based on verifiable delay functions, a method based on other cryptographic primitives, or a combination of two or more methods can be used to generate new blocks, but it is not limited to these.
[0029] Logical clocks can be used in distributed systems to represent the order in which events occur. In this embodiment, a logical clock can distinguish the order in which blocks appear in a blockchain. Each block has a logical clock, which maintains a monotonically increasing number. Each time a new block appears, its logical clock is incremented by one based on the logical clock of the previous block.
[0030] Blocks in a blockchain have a bootstrapping relationship, which can be determined by a logical clock. Structurally, blockchain blocks can form a Directed Acyclic Graph (DAG). Within a local node, the most recent block preceding the new block can be the bootstrapping block of the new block; that is, the bootstrapping block of the new block is the most recent block in the local node preceding the new block. After a new block is generated, it can be randomly assigned to any one of multiple sub-blockchains, and the globally unified order of the blockchain can be determined according to the consensus rules of the blockchain system.
[0031] In some examples, the block with the largest logical clock in the main chain of each sub-blockchain of the blockchain can be selected as the bootstrap block for the new block. The local node can obtain the logical clocks of the blocks in the main chain of each sub-blockchain of the blockchain and select the block with the largest logical clock as the bootstrap block for the new block.
[0032] After selecting a bootstrap block for a new block, a bootstrap pointer relationship can be established between the new block and the bootstrap block. In some examples, the hash value of the bootstrap block of the new block can be calculated, and this hash value can be added as a pointer identifier to the block header field of the new block, forming a bootstrap pointer relationship between the new blocks. Specifically, the hash value of the block identifier of the bootstrap block of the new block can be used as the hash value of the bootstrap block, and this hash value can be written into the block header field of the new block. The bootstrap block of a block can be determined based on the hash value read from the block header field of a given block.
[0033] In step S102, the logical clock line where the new block is located is determined based on the guiding relationship between blocks in the blockchain.
[0034] The logic clock line represents the path leading to the genesis block along the bootstrap relationship. First, the bootstrap block of a new block is determined, then the bootstrap block of that new block is determined, and so on, until the genesis block is found. The logic clock of any block in the logic clock line can be represented by the number of blocks that block passes through along the bootstrap relationship to reach the genesis block. These blocks include the genesis module but not the current genesis block.
[0035] For example, Figure 4 This is a schematic diagram illustrating an example of a logical clock line in a blockchain provided in an embodiment of this application. For example... Figure 4 As shown, the blockchain comprises three sub-blockchains, each containing multiple blocks. Figure 4 Only a portion of the blocks are shown. Figure 4 The blocks shown include blocks b1 to b12, where the logic clock line of block b8 is shown. This logic clock line can be: b8→b12→b7→b3→b6→…→b9→G4.
[0036] In step S103, the block generation difficulty corresponding to the current difficulty adjustment period to which the new block belongs is determined based on the expected single-chain extension speed, the block generation difficulty corresponding to the previous difficulty adjustment period in the logic clock line, and the block generation speed.
[0037] The expected single-chain extension speed is the expected block extension speed of the main chain under a single sub-chain architecture. It can also be regarded as the expected block extension speed of the logical clock line. This expected single-chain extension speed can be set according to the scenario, needs, experience, etc., and is not limited here.
[0038] The difficulty adjustment cycle can be set according to the scenario, requirements, experience, etc., and is not limited here. The length of the difficulty adjustment cycle can be divided according to the number of blocks or time, but it must be ensured that at least one block is generated in each difficulty adjustment cycle. In some examples, a preset duration or a preset number of blocks can be set in advance, and the difficulty adjustment cycle is divided according to the preset duration or the preset number of blocks. The length of the difficulty adjustment cycle can be the preset duration or the preset number of blocks. At least one block must be generated within the preset duration, and the preset interval number must be greater than or equal to 1.
[0039] The current difficulty adjustment cycle is the difficulty adjustment period in which a block exists. The closest difficulty adjustment cycle before the current one is the previous difficulty adjustment cycle. Given the logical clock line where the new block is located, each difficulty adjustment cycle can be obtained within that line according to its length, thus revealing the previous difficulty adjustment cycle. The block generation rate of the previous difficulty adjustment cycle can be determined based on the time and quantity information of the blocks in that cycle. The ratio of the number of blocks generated in the previous difficulty adjustment cycle to the duration of that cycle is the block generation rate. For example, if the previous difficulty adjustment cycle lasts 10 seconds and generates 30 blocks, the block generation rate is 3 blocks per second. The block generation difficulty of the previous difficulty adjustment cycle can be directly obtained. Block generation difficulty can be considered a lower bound requirement for the difficulty of generating legitimate blocks in the consensus protocol of a blockchain system. In some examples, the reciprocal of the block's hash value can be used to measure the block generation difficulty.
[0040] The block generation difficulty of the current difficulty adjustment period corresponding to the new block ensures that the overall blockchain extension speed matches or is consistent with the expected single-chain extension speed. Within the same difficulty adjustment period, the block generation difficulty and block generation speed are negatively correlated; that is, within the same difficulty adjustment period, the higher the block generation difficulty, the slower the block generation speed, and vice versa. Therefore, by comparing the block generation speed of the previous difficulty adjustment period with the expected single-chain extension speed, we can determine whether to increase or decrease the block generation difficulty based on the block generation difficulty of the previous difficulty adjustment period. In other words, should the block generation difficulty of the current difficulty adjustment period be greater or less than that of the previous difficulty adjustment period to compensate for the adverse effects of an excessively fast or slow block generation speed in the previous period? Of course, if the block generation speed of the previous difficulty adjustment period was appropriate, the block generation difficulty of the current difficulty adjustment period can be consistent with that of the previous period.
[0041] In some examples, if the block generation speed of the previous difficulty adjustment period is less than the desired single-chain extension speed, the block generation speed can be reduced; that is, the block generation difficulty of the current difficulty adjustment period is less than the block generation difficulty of the previous difficulty adjustment period. Conversely, if the block generation speed of the previous difficulty adjustment period is greater than the desired single-chain extension speed, the block generation speed can be increased; that is, the block generation difficulty of the current difficulty adjustment period is greater than the block generation difficulty of the previous difficulty adjustment period.
[0042] In some examples, when the block generation speed corresponding to the previous difficulty adjustment cycle is less than the desired single-chain extension speed, the ratio of the first difficulty difference to the block generation difficulty corresponding to the previous difficulty adjustment cycle is less than the second preset ratio. The first difficulty difference is the difference between the block generation difficulty corresponding to the previous difficulty adjustment cycle and the block generation difficulty corresponding to the current difficulty adjustment cycle; that is, the first difficulty difference is the reduction in block generation difficulty in the current difficulty adjustment cycle relative to the previous difficulty adjustment cycle. Since a lower block generation difficulty increases the likelihood of network attacks, even when the block generation speed corresponding to the previous difficulty adjustment cycle is less than the desired single-chain extension speed, the reduction in block generation difficulty should not be too large. The reduction in block generation difficulty can be limited by the second preset ratio and the ratio of the first difficulty difference to the block generation difficulty corresponding to the previous difficulty adjustment cycle to prevent potential network attacks. The second preset ratio can be set according to the scenario, needs, experience, etc., and is not limited here. For example, the second preset ratio can be 30%.
[0043] In step S104, during the current difficulty adjustment cycle, blocks are generated according to the target block generation difficulty.
[0044] The block generation difficulty can be adjusted based on the current difficulty to obtain the target block generation difficulty. The target block generation difficulty must be greater than or equal to the block generation difficulty corresponding to the current difficulty adjustment period.
[0045] Each time a new block is generated on the blockchain, steps S101 to S104 above can be executed to dynamically adjust the block generation difficulty. It should be noted that since there is no previous difficulty adjustment cycle in the first difficulty adjustment cycle, the block generation speed corresponding to the first difficulty adjustment cycle can be set to the desired single-chain extension speed, and the block generation difficulty corresponding to the first difficulty adjustment cycle can be set to a preset difficulty, which can be determined according to the desired single-chain extension speed.
[0046] In this embodiment, when a new block is generated, the logical clock line where the new block resides can be determined based on the guiding relationship between blocks in the local node's blockchain. Using the expected single-chain extension speed, the block generation difficulty corresponding to the previous difficulty adjustment cycle in the logical clock line, and the block generation speed, the block generation difficulty corresponding to the current difficulty adjustment cycle to which the new block belongs can be determined. In the current difficulty adjustment cycle, blocks are generated with a target block generation difficulty greater than or equal to the block generation difficulty corresponding to the current difficulty adjustment cycle. The block generation difficulty and block generation speed within the same difficulty adjustment cycle are negatively correlated. By comparing the block generation speed corresponding to the previous difficulty adjustment cycle with the expected single-chain extension speed, it can be determined whether to increase or decrease the block generation difficulty based on the block generation difficulty corresponding to the previous difficulty adjustment cycle, thereby obtaining the block generation difficulty corresponding to the current difficulty adjustment cycle, to compensate for the adverse effects of an excessively fast or slow block generation speed in the previous difficulty adjustment cycle. When factors such as network size or computing power investment change, dynamically adjusting the block generation difficulty ensures that the blockchain's scaling speed matches or approaches the desired scaling speed of a single chain, keeping the block generation difficulty within a safe range and thus improving the security of the blockchain system. Furthermore, dynamically adjusting the block generation difficulty to match or approach the desired scaling speed of a single chain also prevents a decline in the performance of the blockchain system.
[0047] In some embodiments, in order to minimize unnecessary adjustments, the block generation difficulty can be adjusted only when the block generation speed corresponding to the previous difficulty adjustment cycle differs significantly from the expected single-chain extension speed, so as to save the resources occupied by dynamic adjustment of block generation difficulty. Figure 5 A flowchart of a method for adjusting the difficulty of block generation in a blockchain, provided as another embodiment of this application. Figure 5 and Figure 3 The difference is that, Figure 3 Step S103 can be further refined as follows: Figure 5 Step S1031, Figure 5 The block generation difficulty adjustment method shown in the blockchain may also include step S105.
[0048] In step S1031, if the ratio of the absolute value of the first speed to the expected single-chain extension speed is greater than the first preset ratio, the block generation difficulty corresponding to the current difficulty adjustment period is determined based on the expected single-chain extension speed, the block generation difficulty corresponding to the previous difficulty adjustment period, and the block generation speed.
[0049] The absolute value of the first speed is the absolute value of the difference between the block generation speed corresponding to the previous difficulty adjustment cycle and the expected single-chain extension speed. The ratio of the absolute value of the first speed to the expected single-chain extension speed indicates the extent to which the block generation speed corresponding to the previous difficulty adjustment cycle has increased or decreased compared to the expected single-chain extension speed. The first preset ratio is used to determine whether the increase or decrease in the block generation speed corresponding to the previous difficulty adjustment cycle compared to the expected single-chain extension speed exceeds the acceptable range. It can be set according to the scenario, needs, experience, etc., and is not limited here. If the ratio of the absolute value of the first speed to the expected single-chain extension speed is greater than the first preset ratio, it indicates that the increase or decrease in the block generation speed corresponding to the previous difficulty adjustment cycle compared to the expected single-chain extension speed exceeds the acceptable range, and the block generation difficulty needs to be adjusted.
[0050] In step S105, if the ratio of the absolute value of the first speed to the expected single-chain extension speed is less than or equal to the first preset ratio, the block generation difficulty corresponding to the previous difficulty adjustment cycle is determined as the block generation difficulty corresponding to the current difficulty adjustment cycle.
[0051] If the ratio of the absolute value of the first speed to the expected single-chain extension speed is less than or equal to the first preset ratio, it means that the increase or decrease in the block generation speed corresponding to the previous difficulty adjustment cycle compared to the expected single-chain extension speed is within an acceptable range, and there is no need to adjust the block generation difficulty; simply keep the block generation difficulty unchanged.
[0052] Block generation difficulty is adjusted only when the ratio of the absolute value of the first speed to the expected single-chain extension speed is greater than the first preset ratio. This can minimize unnecessary adjustments and save resources used for dynamic adjustment of block generation difficulty.
[0053] In some embodiments, the block generation difficulty can be increased or decreased proportionally based on the block generation difficulty corresponding to the previous difficulty adjustment cycle to obtain the block generation difficulty corresponding to the current difficulty adjustment cycle. Figure 6 A flowchart of a method for adjusting the difficulty of block generation in a blockchain, provided as another embodiment of this application. Figure 6 and Figure 3 The difference is that, Figure 3 Step S103 can be further refined as follows: Figure 6 Steps S1032 to S1034 in the process.
[0054] In step S1032, the adjustment ratio is calculated based on the desired single-chain extension speed and the block generation speed corresponding to the previous difficulty adjustment cycle.
[0055] Specifically, the adjustment ratio can be the ratio of the block generation speed corresponding to the previous difficulty adjustment cycle to the expected single-chain extension speed, which can be calculated as follows (1):
[0056]
[0057] Where d is the adjustment ratio; V1 is the block generation speed corresponding to the previous difficulty adjustment cycle; and V0 is the expected single-chain extension speed.
[0058] In step S1033, if the block generation speed corresponding to the previous difficulty adjustment cycle is less than the expected single-chain extension speed, the block generation difficulty corresponding to the previous difficulty adjustment cycle is reduced according to the adjustment ratio to obtain the block generation difficulty corresponding to the current difficulty adjustment cycle.
[0059] If the block generation speed of the previous difficulty adjustment cycle is less than the expected single-chain extension speed, it indicates that the block generation speed of the previous difficulty adjustment cycle was slow, and the block generation speed needs to be increased in the current difficulty adjustment cycle to compensate for the adverse effects of the slow block generation speed of the previous difficulty adjustment cycle. The block generation difficulty of the previous difficulty adjustment cycle can be proportionally reduced according to the adjustment ratio to obtain the block generation difficulty of the current difficulty adjustment cycle. The block generation difficulty of the current difficulty adjustment cycle is less than the block generation difficulty of the previous difficulty adjustment cycle. The block generation difficulty of the current difficulty adjustment cycle can be calculated according to the following formula (2):
[0060] E2=E1×d (2)
[0061] Where E2 is the block generation difficulty corresponding to the current difficulty adjustment cycle; E1 is the block generation difficulty corresponding to the previous difficulty adjustment cycle; d is the adjustment ratio, and the calculation of the adjustment ratio can be found in the above formula (1). When the block generation speed corresponding to the previous difficulty adjustment cycle is less than the expected single chain extension speed, the adjustment ratio d in the above formula (2) is less than 1.
[0062] In step S1034, if the block generation speed corresponding to the previous difficulty adjustment cycle is greater than the expected single-chain extension speed, the block generation difficulty corresponding to the previous difficulty adjustment cycle is increased according to the adjustment ratio to obtain the block generation difficulty corresponding to the current difficulty adjustment cycle.
[0063] If the block generation speed of the previous difficulty adjustment cycle is greater than the expected single-chain extension speed, it indicates that the block generation speed of the previous difficulty adjustment cycle is too fast. Therefore, the block generation speed needs to be reduced in the current difficulty adjustment cycle to compensate for the adverse effects of the excessively fast block generation speed of the previous difficulty adjustment cycle. The block generation difficulty of the previous difficulty adjustment cycle can be increased proportionally according to the adjustment ratio to obtain the block generation difficulty of the current difficulty adjustment cycle. The block generation difficulty of the current difficulty adjustment cycle is greater than the block generation difficulty of the previous difficulty adjustment cycle. The block generation difficulty of the current difficulty adjustment cycle can also be calculated according to the above formula (2). However, if the block generation speed of the previous difficulty adjustment cycle is greater than the expected single-chain extension speed, the adjustment ratio d in the above formula (2) is greater than 1.
[0064] Furthermore, if the block generation speed of the previous difficulty adjustment cycle is equal to the expected single-chain extension speed, the block generation difficulty of the current difficulty adjustment cycle can be kept the same as the block generation difficulty of the previous difficulty adjustment cycle, i.e., the block generation difficulty remains unchanged. In this case, the adjustment ratio can also be considered to be equal to 1.
[0065] In some embodiments, when a local node receives a block generated by another node, it can verify the block generation difficulty corresponding to the difficulty adjustment period to which the block generated by the other node belongs, in order to determine whether the block generated by the other node is legitimate. Figure 7 A flowchart of a method for adjusting the difficulty of block generation in a blockchain, provided as another embodiment of this application. Figure 7 and Figure 3 The difference is that, Figure 7 The block generation difficulty adjustment method in the blockchain shown may also include steps S106 to S109.
[0066] In step S106, upon receiving the first block, the actual block generation difficulty of the first block is calculated based on the clock logic line where the first block is located.
[0067] The first block includes blocks generated by non-local nodes. Non-local nodes include nodes other than the local node in the blockchain system. After a non-local node generates a new block, it needs to transmit the new block to the local node. Although the block generation difficulty adjustment method in the above embodiment incorporates the consensus rules of the blockchain system, and the local node can determine that the difficulty of the newly generated block is adjusted according to the block generation difficulty adjustment method in the above embodiment, the local node cannot determine whether the difficulty of blocks generated by non-local nodes is adjusted according to the block generation difficulty adjustment method in the above embodiment. Therefore, it is necessary to verify whether the difficulty adjustment of blocks generated by non-local nodes is adjusted according to the block generation difficulty adjustment method in the above embodiment.
[0068] The clock logic line containing the first block can be obtained based on the bootstrapping relationship between blocks in the blockchain. The clock logic line containing the first block is the path from the first block along the bootstrapping relationship to the genesis block.
[0069] Based on the clock logic line where the first block is located, relevant information about the block in that clock logic line can be obtained, thus revealing the actual block generation difficulty of the first block.
[0070] In step S107, it is determined whether the actual generation difficulty is less than the block generation difficulty corresponding to the difficulty adjustment period to which the first block belongs.
[0071] The block generation difficulty corresponding to the difficulty adjustment period to which the first block belongs can be determined based on the block generation difficulty, block generation speed, and expected single-chain extension speed of the block generation difficulty adjustment method in the blockchain described in the above embodiments.
[0072] By comparing the actual generation difficulty with the block generation difficulty corresponding to the difficulty adjustment period of the first block, it can be determined whether the block generation difficulty corresponding to the difficulty adjustment period of the first block is adjusted according to the block generation difficulty adjustment method in the blockchain in the above embodiment.
[0073] In step S108, if the actual generation difficulty is less than the block generation difficulty corresponding to the difficulty adjustment period to which the first block belongs, the block is refused to be allocated to the sub-blockchain of the local node.
[0074] If the actual generation difficulty is less than the block generation difficulty corresponding to the difficulty adjustment period to which the first block belongs, it means that the block generation difficulty corresponding to the difficulty adjustment period to which the first block belongs has not been adjusted according to the block generation difficulty adjustment method in the blockchain in the above embodiment. That is, the first block is an illegal block, and the illegal block is refused to be added to any sub-blockchain in the blockchain.
[0075] In step S109, if the actual generation difficulty is greater than or equal to the block generation difficulty corresponding to the difficulty adjustment period to which the first block belongs, the block is allocated to the sub-blockchain of the local node.
[0076] If the actual generation difficulty is greater than or equal to the block generation difficulty corresponding to the difficulty adjustment period to which the first block belongs, it means that the block generation difficulty corresponding to the difficulty adjustment period to which the first block belongs is adjusted according to the block generation difficulty adjustment method in the blockchain in the above embodiment. That is, the first block is a valid block, and the valid block is added to a certain sub-blockchain in the blockchain.
[0077] By verifying the block generation difficulty corresponding to the difficulty adjustment cycle of blocks generated by non-local nodes, illegal blocks can be avoided from being added to the blockchain, thus ensuring the security and reliability of the blockchain system.
[0078] It should be noted that the acquisition, storage, use, processing, and application of information and data in this embodiment are all authorized by the user or relevant organization and comply with the relevant provisions of national laws and regulations.
[0079] The second aspect of this application provides a device for adjusting the difficulty of block generation in a blockchain. Figure 8 This is a schematic diagram of a blockchain block generation difficulty adjustment device provided in an embodiment of this application. Figure 8 As shown, the block generation difficulty adjustment device 200 in the blockchain may include a guiding block determination module 201, a logic clock line determination module 202, a calculation module 203, and an execution module 204.
[0080] The bootstrap block determination module 201 can be used to select the bootstrap block of a new block when generating a new block, based on the logical clock of the blocks in the local node's blockchain.
[0081] A blockchain may consist of two or more sub-blockchains.
[0082] The logical clock line determination module 202 can be used to determine the logical clock line where a new block is located based on the guiding relationship between blocks in the blockchain.
[0083] The logical clock line is the path pointing to the genesis block along the bootstrap pointer relationship.
[0084] The calculation module 203 can be used to determine the block generation difficulty corresponding to the current difficulty adjustment period of the new block based on the expected single-chain extension speed, the block generation difficulty corresponding to the previous difficulty adjustment period in the logical clock line, and the block generation speed.
[0085] In some examples, the difficulty adjustment period is divided according to a preset duration or a preset number of blocks, with at least one block generated within the preset duration and a preset number of blocks greater than or equal to 1.
[0086] The execution module 204 can be used to generate blocks according to the target block generation difficulty in the current difficulty adjustment cycle, where the target block generation difficulty is greater than or equal to the block generation difficulty corresponding to the current difficulty adjustment cycle.
[0087] In this embodiment, when a new block is generated, the logical clock line where the new block resides can be determined based on the guiding relationship between blocks in the local node's blockchain. Using the expected single-chain extension speed, the block generation difficulty corresponding to the previous difficulty adjustment cycle in the logical clock line, and the block generation speed, the block generation difficulty corresponding to the current difficulty adjustment cycle to which the new block belongs can be determined. In the current difficulty adjustment cycle, blocks are generated with a target block generation difficulty greater than or equal to the block generation difficulty corresponding to the current difficulty adjustment cycle. The block generation difficulty and block generation speed within the same difficulty adjustment cycle are negatively correlated. By comparing the block generation speed corresponding to the previous difficulty adjustment cycle with the expected single-chain extension speed, it can be determined whether to increase or decrease the block generation difficulty based on the block generation difficulty corresponding to the previous difficulty adjustment cycle, thereby obtaining the block generation difficulty corresponding to the current difficulty adjustment cycle, to compensate for the adverse effects of an excessively fast or slow block generation speed in the previous difficulty adjustment cycle. When factors such as network size or computing power investment change, dynamically adjusting the block generation difficulty ensures that the blockchain's scaling speed matches or approaches the desired scaling speed of a single chain, keeping the block generation difficulty within a safe range and thus improving the security of the blockchain system. Furthermore, dynamically adjusting the block generation difficulty to match or approach the desired scaling speed of a single chain also prevents a decline in the performance of the blockchain system.
[0088] In some embodiments, the bootstrap block determination module 201 can be used to: select the block with the largest logical clock in the main chain of each sub-blockchain of the blockchain as the bootstrap block of the new block.
[0089] In some embodiments, the block generation difficulty adjustment device 200 in the blockchain described above may further include a guide pointing relationship establishment module. This guide pointing relationship establishment module can be used to: calculate the hash value of the guide block for a new block; add the hash value as a pointing identifier to the block header field of the new block, forming a guide pointing relationship between new blocks.
[0090] In some embodiments, the calculation module 203 may be used to: determine the block generation difficulty corresponding to the current difficulty adjustment period based on the expected single-chain extension speed, the block generation difficulty corresponding to the previous difficulty adjustment period, and the block generation speed when the ratio of the absolute value of the first speed to the expected single-chain extension speed is greater than a first preset ratio, wherein the absolute value of the first speed is the absolute value of the difference between the block generation speed corresponding to the previous difficulty adjustment period and the expected single-chain extension speed.
[0091] In some embodiments, the calculation module 203 can also be used to: determine the block generation difficulty corresponding to the previous difficulty adjustment period as the block generation difficulty corresponding to the current difficulty adjustment period when the ratio of the absolute value of the first speed to the expected single-chain extension speed is less than or equal to the first preset ratio.
[0092] In some embodiments, the calculation module 203 may be used to: calculate an adjustment ratio based on the desired single-chain extension speed and the block generation speed corresponding to the previous difficulty adjustment period; if the block generation speed corresponding to the previous difficulty adjustment period is less than the desired single-chain extension speed, reduce the block generation difficulty corresponding to the previous difficulty adjustment period according to the adjustment ratio to obtain the block generation difficulty corresponding to the current difficulty adjustment period; if the block generation speed corresponding to the previous difficulty adjustment period is greater than the desired single-chain extension speed, increase the block generation difficulty corresponding to the previous difficulty adjustment period according to the adjustment ratio to obtain the block generation difficulty corresponding to the current difficulty adjustment period.
[0093] In some examples, when the block generation speed of the previous difficulty adjustment period is less than the expected single-chain extension speed, the ratio of the first difficulty difference to the block generation difficulty of the previous difficulty adjustment period is less than a second preset ratio. Here, the first difficulty difference is the difference between the block generation difficulty of the previous difficulty adjustment period and the block generation difficulty of the current difficulty adjustment period.
[0094] In some embodiments, the block generation difficulty adjustment device 200 in the blockchain described above may further include a verification module. The verification module can be used to: upon receiving a first block, calculate the actual block generation difficulty of the first block based on the clock logic line where the first block is located, wherein the first block includes blocks generated by non-local nodes; determine whether the actual generation difficulty is less than the block generation difficulty corresponding to the difficulty adjustment period to which the first block belongs; and if the actual generation difficulty is less than the block generation difficulty corresponding to the difficulty adjustment period to which the first block belongs, refuse to allocate the block to the sub-blockchain of the local node.
[0095] A third aspect of this application also provides a node device. Figure 9 This is a schematic diagram of the structure of a node device provided in one embodiment of this application. Figure 9 As shown, the node device 300 includes a memory 301, a processor 302, and a computer program stored in the memory 301 and executable on the processor 302.
[0096] In some examples, the processor 302 described above may include a central processing unit (CPU), or an application-specific integrated circuit (ASIC), or one or more integrated circuits that may be configured to implement the embodiments of this application.
[0097] Memory 301 may include read-only memory (ROM), random access memory (RAM), disk storage media devices, optical storage media devices, flash memory devices, and electrical, optical, or other physical / tangible memory storage devices. Therefore, typically, memory includes one or more tangible (non-transitory) computer-readable storage media (e.g., memory devices) encoded with software including computer-executable instructions, and when the software is executed (e.g., by one or more processors), it is operable to perform the operations described with reference to the block generation difficulty adjustment method in a blockchain according to embodiments of this application.
[0098] The processor 302 reads the executable program code stored in the memory 301 to run the computer program corresponding to the executable program code, so as to implement the block generation difficulty adjustment method in the blockchain in the above embodiment.
[0099] In some examples, node device 300 may also include communication interface 303 and bus 304. For example, Figure 9 As shown, the memory 301, processor 302, and communication interface 303 are connected through bus 304 and complete communication with each other.
[0100] The communication interface 303 is mainly used to realize communication between various modules, devices, units and / or equipment in the embodiments of this application. Input devices and / or output devices can also be connected through the communication interface 303.
[0101] Bus 304 includes hardware, software, or both, that couples the components of node device 300 together. For example, and not limitingly, bus 304 may include an Accelerated Graphics Port (AGP) or other graphics bus, an Enhanced Industry Standard Architecture (EISA) bus, a Front Side Bus (FSB), a Hyper Transport (HT) interconnect, an Industry Standard Architecture (ISA) bus, an Infinite Bandwidth Interconnect, a Low Pin Count (LPC) bus, a memory bus, a Micro Channel Architecture (MCA) bus, a Peripheral Component Interconnect (PCI) bus, a PCI-Express (PCI-E) bus, a Serial Advanced Technology Attachment (SATA) bus, a Video Electronics Standards Association Local Bus (VLB) bus, or other suitable buses, or combinations of two or more of these. Where appropriate, bus 304 may include one or more buses. Although specific buses are described and illustrated in the embodiments of this application, this application considers any suitable bus or interconnection.
[0102] A fourth aspect of this application also provides a computer-readable storage medium storing computer program instructions. When executed by a processor, these instructions can implement the block generation difficulty adjustment method in the blockchain described in the above embodiments, achieving the same technical effect. To avoid repetition, further details are omitted here. The aforementioned computer-readable storage medium may include non-transitory computer-readable storage media, such as read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks, etc., and is not limited thereto.
[0103] This application provides a computer program product. When the instructions in the computer program product are executed by the processor of an electronic device, the electronic device can execute the block generation difficulty adjustment method in the blockchain described in the above embodiments and achieve the same technical effect. To avoid repetition, it will not be described again here.
[0104] It should be clarified that the various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. For the device embodiments, equipment embodiments, computer-readable storage medium embodiments, and computer program product embodiments, the relevant parts can be referred to the description section of the method embodiments. This application is not limited to the specific steps and structures described above and shown in the figures. Those skilled in the art can make various changes, modifications, and additions, or change the order of steps, after understanding the spirit of this application. Furthermore, for the sake of brevity, detailed descriptions of known methods and techniques are omitted here.
[0105] The aspects of this application have been described above with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It should be understood that each block in the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing apparatus to produce a machine such that these instructions, executable via the processor of the computer or other programmable data processing apparatus, enable the implementation of the functions / actions specified in one or more blocks of the flowchart illustrations and / or block diagrams. Such a processor can be, but is not limited to, a general-purpose processor, a special-purpose processor, a special application processor, or a field-programmable logic circuit. It is also understood that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can also be implemented by dedicated hardware performing the specified functions or actions, or can be implemented by a combination of dedicated hardware and computer instructions.
[0106] Those skilled in the art will understand that the above embodiments are exemplary and not restrictive. Different technical features appearing in different embodiments can be combined to achieve beneficial effects. Based on a study of the drawings, specification, and claims, those skilled in the art should be able to understand and implement other variations of the disclosed embodiments. In the claims, the term "comprising" does not exclude other means or steps; the quantifier "a" does not exclude a plurality; the terms "first" and "second" are used to identify names and not to indicate any particular order. No reference numerals in the claims should be construed as limiting the scope of protection. The functionality of multiple parts appearing in the claims can be implemented by a single hardware or software module. The appearance of certain technical features in different dependent claims does not mean that these technical features cannot be combined to achieve beneficial effects.
Claims
1. A method for adjusting the difficulty of block generation in a blockchain, characterized in that, include: When generating a new block, the pilot block of the new block is selected according to the logical clock of the blocks in the local node's blockchain, and the blockchain includes two or more sub-blockchains. Based on the guiding relationship between blocks in the blockchain, the logical clock line where the new block is located is determined. The logical clock line is the path pointing to the genesis block along the guiding relationship. Based on the expected single-chain extension speed, the block generation difficulty and block generation speed corresponding to the previous difficulty adjustment cycle in the logical clock line, the block generation difficulty corresponding to the current difficulty adjustment cycle to which the new block belongs is determined. In the current difficulty adjustment cycle, blocks are generated according to the target block generation difficulty, wherein the target block generation difficulty is greater than or equal to the block generation difficulty corresponding to the current difficulty adjustment cycle; The step of determining the block generation difficulty corresponding to the current difficulty adjustment period to which the new block belongs, based on the expected single-chain extension speed, the block generation difficulty corresponding to the previous difficulty adjustment period in the logical clock line, and the block generation speed, includes: The adjustment ratio is calculated based on the expected single-chain extension speed and the block generation speed corresponding to the previous difficulty adjustment cycle. If the block generation speed corresponding to the previous difficulty adjustment cycle is less than the expected single-chain extension speed, the block generation difficulty corresponding to the previous difficulty adjustment cycle is reduced according to the adjustment ratio to obtain the block generation difficulty corresponding to the current difficulty adjustment cycle. If the block generation speed corresponding to the previous difficulty adjustment cycle is greater than the expected single-chain extension speed, the block generation difficulty corresponding to the previous difficulty adjustment cycle is increased according to the adjustment ratio to obtain the block generation difficulty corresponding to the current difficulty adjustment cycle.
2. The method according to claim 1, characterized in that, The step of selecting the pilot block for the new block based on the logical clock of the blocks in the local node's blockchain includes: The block with the largest logical clock in the main chain of each sub-blockchain of the blockchain is selected as the pilot block of the new block.
3. The method according to claim 2, characterized in that, After selecting the bootstrap block for the new block based on the logical clock of the blocks in the local node's blockchain, the method further includes: Calculate the hash value of the bootstrap block of the new block; The hash value is added as a pointer identifier to the block header field of the new block, forming a bootstrap pointer relationship between the new blocks.
4. The method according to claim 1, characterized in that, The step of determining the block generation difficulty corresponding to the current difficulty adjustment period to which the new block belongs, based on the expected single-chain extension speed, the block generation difficulty corresponding to the previous difficulty adjustment period in the logical clock line, and the block generation speed, includes: If the ratio of the absolute value of the first speed to the expected single-chain extension speed is greater than a first preset ratio, the block generation difficulty corresponding to the current difficulty adjustment period is determined based on the expected single-chain extension speed, the block generation difficulty corresponding to the previous difficulty adjustment period, and the block generation speed. Wherein, the absolute value of the first speed is the absolute value of the difference between the block generation speed corresponding to the previous difficulty adjustment cycle and the expected single-chain extension speed.
5. The method according to claim 4, characterized in that, Also includes: If the ratio of the absolute value of the first speed to the expected single-chain extension speed is less than or equal to the first preset ratio, the block generation difficulty corresponding to the previous difficulty adjustment cycle is determined as the block generation difficulty corresponding to the current difficulty adjustment cycle.
6. The method according to claim 1, characterized in that, If the block generation speed corresponding to the previous difficulty adjustment cycle is less than the expected single-chain extension speed, the ratio of the first difficulty difference to the block generation difficulty corresponding to the previous difficulty adjustment cycle is less than the second preset ratio. The first difficulty difference is the difference between the block generation difficulty corresponding to the previous difficulty adjustment cycle and the block generation difficulty corresponding to the current difficulty adjustment cycle.
7. The method according to claim 1, characterized in that, Also includes: Upon receiving the first block, the actual block generation difficulty of the first block is calculated based on the clock logic line where the first block is located. The first block includes blocks generated by non-local nodes. Determine whether the actual generation difficulty is less than the block generation difficulty corresponding to the difficulty adjustment period to which the first block belongs; If the actual generation difficulty is less than the block generation difficulty corresponding to the difficulty adjustment period to which the first block belongs, the block will not be allocated to the sub-blockchain of the local node.
8. The method according to claim 1, characterized in that, The difficulty adjustment cycle is divided according to a preset duration or a preset number of blocks. At least one block must be generated within the preset time period. The number of preset blocks is greater than or equal to 1.
9. A device for adjusting the difficulty of block generation in a blockchain, characterized in that, include: The pilot block determination module is used to select the pilot block of the new block according to the logical clock of the blocks in the local node's blockchain when generating a new block, wherein the blockchain includes two or more sub-blockchains; The logical clock line determination module is used to determine the logical clock line where the new block is located based on the guiding relationship between blocks in the blockchain. The logical clock line is the path pointing to the genesis block along the guiding relationship. The calculation module is used to determine the block generation difficulty corresponding to the current difficulty adjustment period to which the new block belongs, based on the expected single-chain extension speed, the block generation difficulty corresponding to the previous difficulty adjustment period in the logical clock line, and the block generation speed. The execution module is used to generate blocks according to the target block generation difficulty in the current difficulty adjustment cycle, wherein the target block generation difficulty is greater than or equal to the block generation difficulty corresponding to the current difficulty adjustment cycle. The calculation module is used to: calculate the adjustment ratio based on the expected single-chain extension speed and the block generation speed corresponding to the previous difficulty adjustment cycle; and reduce the block generation difficulty corresponding to the previous difficulty adjustment cycle according to the adjustment ratio when the block generation speed corresponding to the previous difficulty adjustment cycle is less than the expected single-chain extension speed, so as to obtain the block generation difficulty corresponding to the current difficulty adjustment cycle. If the block generation speed corresponding to the previous difficulty adjustment cycle is greater than the expected single-chain extension speed, the block generation difficulty corresponding to the previous difficulty adjustment cycle is increased according to the adjustment ratio to obtain the block generation difficulty corresponding to the current difficulty adjustment cycle.
10. A node device, characterized in that, include: Processor and memory storing computer program instructions; When the processor executes the computer program instructions, it implements the method for adjusting the difficulty of block generation in a blockchain as described in any one of claims 1 to 8.
11. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer program instructions, which, when executed by a processor, implement the method for adjusting the difficulty of block generation in a blockchain as described in any one of claims 1 to 8.
Citation Information
Patent Citations
A block chain system of an isomorphic dual-mode main and auxiliary chain and a block production method thereof
CN109948003A
Electronic device for adjusting difficulty with respect to hash value in blockchain network, and operation method thereof
WO2021201564A1