A blockchain multi-copy distribution and storage method based on genetic algorithm

Through the multi-copy allocation and storage method based on genetic algorithm, the storage and query efficiency of the blockchain system is optimized, and the problem of excessive storage space caused by the full replica mechanism is solved, and the expansion and efficiency of the blockchain system is improved.

CN113934374BInactive Publication Date: 2024-12-03BEIJING INST OF TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111193595.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Priority Date
2021-09-28
Filing Date
2021-10-13
Publication Date
2024-12-03
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

The full replica mechanism in the blockchain system causes excessive storage space burden on nodes, which increases the entry threshold for nodes, and has higher storage space requirements in the alliance chain. How to generate the optimal allocation plan for blocks under multi-resource constraints Reduce storage space requirements and communication costs.

Method used

Using a multi-copy allocation and storage method based on genetic algorithm, the cross operator and mutation operator of the screening table of elite system and storage nodes are set to optimize the block allocation and storage location, generate an approximate optimal allocation scheme, and reduce the blockchain The overall energy loss and query efficiency of the system.

Benefits of technology

It effectively reduces the storage space requirements of blockchain systems, improves the scalability and query efficiency of blockchain systems, avoids local optimal solutions, is faster iteration speed, and has a higher probability of obtaining an approximate optimal solution.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113934374B_ABST
    Figure CN113934374B_ABST
Patent Text Reader

Abstract

The invention discloses a method for allocating and storing multiple copies of a blockchain based on a genetic algorithm, and belongs to the technical field of blockchain systems. The implementation method of the invention is as follows: by using a multiple copy mechanism to allocate and store blocks, the storage space requirement threshold for new nodes to join the blockchain is reduced, so that the storage space required for the overall blockchain system is reduced; and using a multiple copy allocation and storage optimization algorithm based on a genetic algorithm, under the condition of multiple resource constraints, the optimal allocation and storage location is generated for all blocks on the blockchain; by setting an elite system and a crossover operator and a mutation operator based on a storage node screening table, the genetic algorithm obtains a nearly optimal allocation and storage scheme, and after the allocation scheme is generated, the corresponding node is responsible for the actual storage work, thereby reducing the overall energy loss of the blockchain system; the blockchain system will regularly use a genetic optimization algorithm to adjust the allocation position of the block according to the global state, which can effectively improve the efficiency of block query events in the blockchain.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a blockchain multi-copy distribution and storage method based on a genetic algorithm, and belongs to the technical field of blockchain systems. Background Art

[0002] The blockchain ledger is tamper-proof, so the data stored in the blockchain ledger cannot be modified or deleted, and subsequent blocks can only be gradually added to the blockchain ledger. However, the full copy mechanism, that is, each node needs to store the complete blockchain ledger, brings a huge storage space burden to the node, raising the entry threshold of nodes in the blockchain system. This storage problem is more prominent in the alliance chain, because the alliance chain usually adopts a practical Byzantine fault-tolerant protocol with a higher throughput, generates blocks faster, and requires higher storage space for nodes. In order to improve the scalability of the blockchain system, it is divided into the following types from the perspective of technical implementation: lightning network, side chain technology, sharding technology and multi-copy mechanism.

[0003] The core idea of ​​the Lightning Network is to establish a micropayment channel for the transacting parties, separating small transactions from large transactions. The Lightning Network allows two nodes to lock a sum of money on the chain to open a payment channel, and then the two parties can conduct fast and instant confirmation transactions off-chain, that is, without transmitting the transaction to the chain, as long as the total amount of each transaction is less than the locked value. The advantage of this technology is that it greatly reduces the handling fee and confirmation time, but its disadvantage is that there is an upper limit on the channel, which may expose the user's Bitcoin wallet funds.

[0004] The core idea of ​​sidechain technology is that a group of validators submit the latest state of a chain to a smart contract on the main chain. These latest state checkpoints can be used by bridge contracts to support user deposits and withdrawals. Asset transfers between the main chain and the side chain must be atomic operations, that is, either all or nothing happens. The advantage of this technology is that it allows users to access a large number of new services, which means that Bitcoin can circulate on other blockchains. Its disadvantage is that the side chain needs to have sufficient computing power or other mechanisms to ensure the reliability and security of the side chain.

[0005] Sharding technology is a technical solution proposed to solve the Ethereum expansion problem. Blockchain sharding technology refers to the secondary expansion of the original single blockchain, thereby breaking through the computing power limitations of a single node. The core idea of ​​sharding technology is to divide the state, history, and transactions into multiple partitions, namely shards. State sharding means that transactions within a shard are limited to the state of that shard. History sharding means that each shard has its own transaction history. Transaction sharding means that different shards are responsible for storing different parts of the blockchain ledger, but the nodes within the shard jointly maintain the ledger owned by the shard. The advantage of sharding technology is that it effectively improves the scalability of the blockchain system, but its disadvantage is that the security of transactions across shards cannot be effectively guaranteed.

[0006] The core idea of ​​the multi-copy mechanism is that each block has only multiple copies, rather than the number of copies equal to the number of nodes. Therefore, each node only needs to store part of the data in the entire blockchain ledger, which can effectively reduce the storage burden of the node, thereby improving the scalability of the blockchain system. However, the multi-copy mechanism has at least the following two key challenges. The first is how to comprehensively consider and generate the best block allocation plan in the current state based on the global state of the current blockchain system, such as the communication cost between nodes, the query frequency of each block in each node, the size of the block, and the storage space margin of the node. The second is that finding the best block allocation plan is a computationally difficult problem. When the number of blocks and the number of nodes are growing exponentially, how to generate an approximate solution within an acceptable time is a major challenge. Summary of the invention

[0007] The present invention discloses a method for allocating and storing multiple copies of a blockchain based on a genetic algorithm, which mainly solves the following technical problems: by allocating and storing blocks using a multiple copy mechanism, the storage space requirement threshold for new nodes added to the blockchain is lowered, so that the storage space required for the overall blockchain system is reduced; and by using a multiple copy allocation and storage optimization algorithm based on a genetic algorithm, the optimal allocation and storage locations are generated for all blocks on the blockchain under the condition of multiple resource constraints; by setting an elite system and a crossover operator and a mutation operator based on a storage node screening table, the genetic algorithm obtains a nearly optimal allocation and storage solution, and after the allocation solution is generated, the corresponding node is responsible for the actual storage work, thereby reducing the overall energy loss of the blockchain system; the blockchain system will regularly use a genetic optimization algorithm to adjust the allocation location of blocks according to the global state, which can effectively improve the efficiency of block query events in the blockchain.

[0008] In order to achieve the above object, the present invention adopts the following technical scheme.

[0009] The present invention discloses a method for distributing and storing multiple copies of a blockchain based on a genetic algorithm, based on the following definition:

[0010] Definition 1: Blockchain ledger refers to the infrastructure used to store block data. It is essentially a distributed database that integrates peer-to-peer transmission, consensus mechanism, and cryptographic algorithm.

[0011] Definition 2: A channel refers to a private broadcast domain divided and managed by consensus nodes. The purpose is to isolate the information within the channel to ensure the privacy of transactions.

[0012] Definition 3: A consensus node is the actual manager of each channel. This node is responsible for reaching consensus on transactions collected from other nodes, forming a consistent sort, and packaging several transactions into blocks and sending them to the leader node.

[0013] Definition 4: Leader node refers to the manager generated by mandatory setting or dynamic election in each organization. This node is responsible for sending the received batch blocks to other nodes in the organization;

[0014] Definition 5: Follower nodes refer to other nodes in each organization except the leader node. The node is responsible for storing blocks in the local ledger for block query and verification;

[0015] Definition 6: Client refers to a terminal device that can initiate transaction proposals or query block requests to any follower node;

[0016] Definition 7: Block cache refers to the storage device used by each follower node to store the most recently queried blocks. If the block is stored in the block cache, the follower node can return the block directly to the client.

[0017] Definition 8: The multi-copy mechanism refers to a storage mechanism that is different from the full-copy mechanism in the traditional blockchain system. Each block only needs to be stored by several follower nodes in the blockchain system.

[0018] The present invention discloses a method for distributing and storing multiple copies of a blockchain based on a genetic algorithm, comprising the following steps:

[0019] Step 1: By using a multi-copy mechanism to allocate and store blocks, a multi-copy mechanism blockchain system allocation and storage model is established to lower the storage space requirement threshold for new nodes to join the blockchain, thereby reducing the storage space required for the overall blockchain system.

[0020] First, determine the objective function in the block allocation problem and set the communication cost in the entire blockchain system as the objective function. The ultimate goal of the block allocation problem is to obtain a block allocation and storage solution that minimizes the total communication cost under the condition of multiple resource constraints. The objective function is as follows:

[0021]

[0022]

[0023]

[0024] In the formula, x is the block allocation node vector, y is the block allocation set vector, Q(x, y) is the function for calculating the communication cost in the entire blockchain system; m is the number of blocks, n is the number of nodes, r is the number of copies of each block, K is the number of nodes that make up a set of size r; i represents the i-th block, j represents the j-th node, N k represents the kth set; pik represents the communication cost when the i-th block is assigned to the k-th set; x ij The values ​​of are only 0 and 1. 1 means that the i-th block is allocated to the j-th node, and 0 means no allocation; n″ represents the nodes in the k-th set, and n′ represents all nodes in the system except n″; c n′n″ represents the communication cost between nodes n′ and n″, f in′ represents the query frequency of the ith block on the n′th node, s in′ Indicates the space occupied by the i-th block stored on the n′th node.

[0025] In addition, the generated node allocation and storage scheme needs to satisfy the following constraints.

[0026] Block allocation constraint: x ij It can only take Boolean values, i.e. 0 or 1. And each block is assigned to r non-repeated nodes.

[0027] Set constraint: Each block can only be assigned to a set of size r.

[0028] Storage space constraint: The total size of blocks stored by each node does not exceed its own storage space limit.

[0029] Step 2: Based on the genetic algorithm, the allocation and storage model of the multi-copy mechanism blockchain system established in step 1 is optimized to generate approximately optimal allocation and storage locations for all blocks on the blockchain; by setting up an elite system and crossover operators and mutation operators based on the storage node screening table, the genetic algorithm obtains an approximately optimal allocation and storage solution. After the solution is generated, the corresponding nodes are responsible for the actual storage work, thereby reducing the total communication cost of the blockchain system.

[0030] Step 2.1: Randomly generate the initial population. The initial population consists of P chromosomes. Each chromosome represents a block allocation and storage scheme, represented by an r×m allocation and storage matrix. Each row in the matrix consists of m genes. Each gene represents the allocation and storage location of a block, and its value range is 0 to n-1. First, randomly generate allocation and storage locations for each node and represent them in the form of chromosomes. If the generated scheme does not meet the constraints in step one, repeat the random selection steps until the constraints are met.

[0031] Step 2.2: Calculate the fitness of each chromosome according to the total communication cost function Q(x, y) defined in step 1. The smaller the fitness, the better the allocation and storage scheme, and the higher the probability of being selected in step 2.3. Conversely, the worse the generated allocation and storage scheme, the lower the probability of being selected. In addition, the chromosomes are sorted from low to high according to the fitness value, the first E chromosomes are set as the elite group, the next PE chromosomes are set as the ordinary group, and the remaining chromosomes are eliminated.

[0032] Step 2.3: Use the Roulette Wheel Selection algorithm to randomly select a chromosome a and b from the elite group and the ordinary group for crossover operation. First, generate a storage node screening table based on the latest storage surplus status of all nodes. Then use chromosome a as the parent chromosome and select the m genes on it in turn with a preset probability p. c Select and pass it to the offspring chromosome o1. According to the block allocation position represented by the selected gene minus the storage space of the corresponding node in the storage node screening table, the node with a remaining capacity greater than 0 is the node that has been successfully screened, and the remaining nodes are eliminated as failed screening. The remaining genes on chromosome b will be allocated to the nodes that have been successfully screened. Exchange the roles of chromosomes a and b, generate another offspring chromosome o2 according to the above steps, and add chromosomes o1 and o2 to the next generation population. The method disclosed in the present invention can avoid repeated crossover operations and avoid falling into the dilemma of being unable to generate a correct block allocation and storage plan, thereby improving the generation efficiency of block allocation and storage plans.

[0033] Step 2.4: Randomly select a chromosome p1 in the current common population, and then randomly select a gene m1 in chromosome p1. Generate the storage node screening table described in step 2.2 based on the storage and allocation scheme represented by the chromosome, and subtract the storage space required for the m1th block represented by the gene from the (value of m1)th item in the table. Nodes with remaining capacity greater than 0 are nodes that can be selected for mutation, and one node is selected from these nodes as the allocation location of the m1th block. By using the storage node screening table, it is ensured that the mutation operation only needs to be run once, thereby improving the efficiency of block allocation and storage scheme generation.

[0034] Step 2.5: Repeat steps 2.2 to 2.4 until one of the following two conditions is met. Condition 1: The number of cycles reaches the preset maximum number of iterations maxIter; Condition 2: The best storage and allocation scheme has not changed after Q generations, that is, the fitness value difference of the best scheme in each generation of population is within 10 -4 Inside.

[0035] Step 2.6: According to the optimal block allocation and storage scheme obtained in the above steps, the blocks represented by each gene are allocated to the corresponding nodes for storage, so that the total query cost of the entire blockchain system is minimized.

[0036] Step 3: In the process of optimizing the allocation and storage model of the multi-copy mechanism blockchain system established in step 1 based on the genetic algorithm, the blockchain system regularly uses the genetic optimization algorithm to adjust the allocation position of blocks according to the global state, which can effectively improve the efficiency of block query events in the blockchain.

[0037] The specific execution process of the query event is as follows:

[0038] Step 3.1: The client initiates a query request for block b1 to any follower node, assuming that the follower node is n1.

[0039] Step 3.2: If a copy of block b1 is stored in the local ledger or block cache of follower node n1, node n1 directly returns block b1 to the client. The query frequency of block b1 on node n1 increases accordingly, which will affect the distribution of block b1 in the next round.

[0040] Step 3.3: If the local ledger and block cache of follower node n1 do not store block b1, node n1 will find r storage locations by querying the block storage table, and then select node n2 with the lowest communication cost with node n1 from these r locations. Node n1 pulls block b1 from the local ledger of node n2 and caches it in the block cache and returns the block to the client. The next time the client initiates a query request for block b1 to node n1 again, node n1 can directly return block b1 to the client. And the query frequency of block b1 on node n1 increases accordingly, which will affect the distribution of block b1 in the next round.

[0041] In order to improve the success rate of generating a better block allocation and storage solution, as a preferred method, an elite system is implemented in step 2.2, that is, chromosomes with high fitness in some parent populations are directly added to the child population as elites of the parent population, which can ensure that chromosomes and their genes with better performance in each generation of the parent population can be passed on to the next generation of the population, thereby improving the success rate of generating a better block allocation and storage solution.

[0042] In order to improve the efficiency of generating block allocation and storage solutions, as a preferred method, a storage node screening table is used in steps 2.3 and 2.4, that is, a storage node screening table is generated according to the storage space margin of each node in the blockchain system and the genes that do not need to be changed, and the nodes with remaining capacity greater than 0 are the nodes that can be selected by crossover operation or mutation operation. Through this method, it is possible to ensure that a block allocation and storage solution that meets the constraints in step 1 is successfully generated once, thereby improving the efficiency of generating block allocation and storage solutions.

[0043] In order to further reduce the total communication cost of the block allocation and storage solution, as a preferred embodiment, a block cache is used in step 3, that is, each block pulled from other nodes is cached in the block cache. The read and write efficiency of the block cache is higher than that of the memory. Therefore, when the client still requests the block from the node next time, the node can directly return the block to the client from the block cache. The communication cost of the query block event is 0, thereby further reducing the total communication cost of the block allocation and storage solution.

[0044] Beneficial effects:

[0045] 1. The present invention discloses a method for allocating and storing multiple copies of a blockchain based on a genetic algorithm. By allocating and storing blocks using a multiple copy mechanism, the storage space threshold required for new nodes to join the blockchain system is reduced, so that the storage space required for the entire blockchain system is reduced, storage redundancy is reduced, and a larger number of blocks can be accommodated with the same capacity.

[0046] 2. The present invention discloses a method for allocating and storing multiple copies of a blockchain based on a genetic algorithm. Through a multiple copy allocation and storage optimization algorithm based on a genetic algorithm, the optimal allocation and storage location is generated for all blocks on the blockchain under the condition of multiple resource constraints. With the linear growth of the number of blocks or the number of nodes, the time complexity of solving the problem grows exponentially. Therefore, the problem to be solved belongs to an NP-hard problem and the optimal solution cannot be obtained within polynomial time. The present invention uses a genetic algorithm to find the optimal block allocation and storage solution. Compared with the greedy algorithm and the discrete particle swarm algorithm, it can effectively avoid falling into the local optimal solution, always looking for solutions within the global scope, with faster iteration speed, more randomness, and a higher probability of obtaining a near-optimal solution.

[0047] 3. The present invention discloses a method for allocating and storing multiple copies of blockchains based on a genetic algorithm. By using a crossover operator and a mutation operator based on a storage node screening table, it is possible to directly and successfully generate a block allocation and storage scheme that meets the constraints in step 1, thereby avoiding unnecessary repeated operations and improving the generation efficiency of block allocation and storage schemes. This method can also reduce the search space for approximate optimal solutions and increase the probability of obtaining approximate optimal solutions. BRIEF DESCRIPTION OF THE DRAWINGS

[0048] Figure 1 This is a flow chart of the genetic algorithm used in step 2 of the present invention.

[0049] Figure 2 It is a schematic diagram of the block query event in step 3 of the present invention. DETAILED DESCRIPTION

[0050] In order to better illustrate the purpose and advantages of the present invention, the invention is further described below with reference to the accompanying drawings and examples.

[0051] Embodiment 1:

[0052] This embodiment discloses a method for allocating and storing multiple copies of a blockchain based on a genetic algorithm. The use case includes 10 blocks to be allocated and 10 optional nodes. The size of each block is set to be evenly distributed, all 1MB, and the storage space of each node is set to 5MB. If a full copy mechanism is used, the entire blockchain system requires a total of 100MB of storage space, while using a multi-copy mechanism with r=3, only 30MB of space is required, saving 70% of the storage space. The communication cost between nodes is shown in Table 1 below, with a value range of 0 to 99, in MB / s. If it is 0, it means that there is no direct communication line between the two nodes. The query frequency of blocks at each node is shown in Table 2 below, with a value range of 0 to 99, in times / day. For ease of display, the final calculated total communication cost is divided by 10000.

[0053] Table 1 Inter-node communication cost table

[0054] Node 0 Node 1 Node 2 Node 3 Node 4 Node 5 Node 6 Node 7 Node 8 Node 9 Node 0 0 83 16 90 97 41 49 0 32 19 Node 1 83 0 35 84 10 21 41 12 0 6 Node 2 16 35 0 60 28 42 81 94 93 5 Node 3 90 84 60 0 45 39 3 12 72 8 Node 4 97 10 28 45 0 76 27 37 8 79 Node 5 41 21 42 39 76 0 76 31 21 61 Node 6 49 41 81 3 27 76 0 51 41 52 Node 7 0 12 94 12 37 31 51 0 90 37 Node 8 32 0 93 72 8 21 41 90 0 12 Node 9 19 6 5 8 79 61 52 37 12 0

[0055] Table 2 Block query frequency table

[0056]

[0057]

[0058] like Figure 1 As shown, this embodiment discloses a method for allocating and storing multiple copies of a blockchain based on a genetic algorithm, and the specific implementation steps are as follows:

[0059] Step 1: First, determine the objective function in the block allocation problem and set the communication cost in the entire blockchain system as the objective function. The ultimate goal of the block allocation problem is to obtain a block allocation and storage solution that minimizes the total communication cost under the condition of multiple resource constraints. The objective function is as follows:

[0060]

[0061]

[0062]

[0063] Where x is the block allocation node vector, y is the block allocation set vector, Q(x, y) is the function for calculating the communication cost in the entire blockchain system; m is the number of blocks, n is the number of nodes, r is the number of copies of each block, K is the number of nodes that form a set of size r; i represents the i-th block, j represents the j-th node, and Nk represents the k-th set; p ik represents the communication cost when the i-th block is assigned to the k-th set; x ij The values ​​of are only 0 and 1. 1 means that the i-th block is allocated to the j-th node, and 0 means no allocation; n″ represents the nodes in the k-th set, and n′ represents all nodes in the system except n″; c n′n″ represents the communication cost between nodes n′ and n″, f in′ represents the query frequency of the ith block on the n′th node, s in′ Indicates the space occupied by the i-th block stored on the n′th node.

[0064] In addition, the generated node allocation and storage scheme needs to satisfy the following constraints.

[0065] Block allocation constraint: x ij It can only take Boolean values, i.e. 0 or 1. And each block is assigned to r non-repeated nodes.

[0066] Set constraint: Each block can only be assigned to a set of size r.

[0067] Storage space constraint: The total size of blocks stored by each node does not exceed its own storage space limit.

[0068] Step 2: The genetic algorithm flow chart for optimizing block allocation and storage scheme is as follows: Figure 1 shown.

[0069] Step 2.1: Randomly generate the initial population. The initial population consists of 50 chromosomes. Each chromosome represents a block allocation and storage scheme, represented by a 3×10 allocation and storage matrix. Each row in the matrix consists of 10 genes. Each gene represents the allocation and storage location of a block, and its value range is 0 to 9. First, randomly generate allocation and storage locations for each node and represent them in the form of chromosomes. If the generated solution does not meet the constraints in step 1, repeat the random selection step until the constraints are met.

[0070] The optimal allocation and storage scheme in the generated first generation initial population is shown in Table 3 below.

[0071] Table 3 Optimal allocation and storage scheme for the initial population

[0072]

[0073]

[0074] The total communication cost required for the allocation and storage scheme represented in Table 3 is 3.96s.

[0075] Step 2.2: Calculate the fitness of each chromosome according to the total communication cost function Q(x, y) defined in step 1. The smaller the fitness, the better the allocation and storage scheme, and the higher the probability of being selected in step 2.3. Conversely, the worse the generated allocation and storage scheme, the lower the probability of being selected. In addition, the chromosomes are sorted from low to high according to the fitness value, the first 15 chromosomes are set as the elite group, the next 35 chromosomes are set as the ordinary group, and the remaining chromosomes are eliminated.

[0076] Step 2.3: Use the Roulette Wheel Selection algorithm to randomly select a chromosome a and b from the elite group and the ordinary group for crossover operation. Assume that the scheme represented by chromosome a is shown in Table 4, and the scheme represented by chromosome b is shown in Table 5.

[0077] Table 4 Chromosome a

[0078]

[0079] Table 5 Chromosome b

[0080]

[0081] The allocation and storage schemes represented by chromosome a and chromosome b can obtain an initial storage node screening table, as shown in Table 6 below.

[0082] Table 6 Initial storage node screening table

[0083]

[0084] Assuming that the genes represented by the gray shadows in chromosome a and chromosome b are all selected, and block j has not yet selected an allocation plan, it can be seen from the latest storage node screening table 7 that the allocation plan of block j cannot be directly inherited from chromosome b, because the remaining capacity of node 1 is 0 and the screening fails. Nodes 0, 4, 5, 6, 7, 8, and 9 are all successfully screened nodes, and 3 of them can be randomly selected as the allocation plan for block j.

[0085] Table 7 Updated storage node screening table

[0086]

[0087] Finally, swap the roles of chromosomes a and b and follow the above steps to generate another offspring chromosome.

[0088] Step 2.4: Randomly select a chromosome in the current common population, and then randomly select a gene m1 in the chromosome p1. Generate the storage node filter table described in step 2.2 based on the storage and allocation scheme represented by the chromosome, and subtract the storage volume of the m1th block represented by the gene from the (value of m1)th item in the table. Nodes with remaining capacity greater than 0 are nodes that can be selected for mutation, and one node is selected from these nodes as the allocation location of the m1th block. By using the storage node filter table, it can be ensured that the mutation operation only needs to be run once, thereby improving the efficiency of block allocation and storage scheme generation.

[0089] Step 2.5: Repeat steps 2.2 to 2.4 until one of the following two conditions is met: Condition 1: The number of cycles reaches the preset maximum number of iterations of 500; Condition 2: The best storage and allocation scheme has not changed after 100 generations, that is, the fitness value difference of the best scheme in each generation of the population is within 10 -4 Inside.

[0090] Step 2.6: According to the optimal block allocation and storage scheme obtained in the above steps, the blocks represented by each gene are allocated to the corresponding nodes for storage, so that the total query cost of the entire blockchain system is minimized.

[0091] The optimal allocation and storage solution generated is shown in Table 8. Its total communication cost is 3.22s, which is 18.7% better than the solution generated by the first generation, 18% less than the discrete particle swarm optimization algorithm, and 3.6% less than the greedy algorithm. Compared with the full copy mechanism, it saves 70% of storage space.

[0092] Table 8 Optimal allocation and storage solutions

[0093] Block a Block b Block c Block d Block e Block f Block g Blockh Block 1 Block j Copy 1 9 9 2 9 5 1 1 3 5 1 Copy 2 3 0 4 5 9 0 0 4 6 5 Instance 3 7 7 3 4 0 6 3 2 0 7

[0094] Step 3: In the process of optimizing the allocation and storage model of the multi-copy mechanism blockchain system established in step 1 based on the genetic algorithm, the blockchain system regularly uses the genetic optimization algorithm to adjust the allocation position of blocks according to the global state, which can effectively improve the efficiency of block query events in the blockchain. The specific execution process of the query event is as follows, and combined with Figure 2 illustrate:

[0095] Step 3.1: The client initiates a query request for block b1 to any follower node, assuming that the follower node is n1.

[0096] Step 3.2: If a copy of block b1 is stored in the local ledger or block cache of follower node n1, node n1 directly returns block b1 to the client. The query frequency of block b1 on node n1 increases accordingly, which will affect the distribution of block b1 in the next round.

[0097] Step 3.3: If the local ledger and block cache of follower node n1 do not store block b1, node n1 queries the block storage table to find 3 storage locations, and then selects node n2 with the lowest communication cost with node n1 from these 3 locations. Node n1 pulls block b1 from the local ledger of node n2 and caches it in the block cache and returns the block to the client. The next time the client initiates a query request for block b1 to node n1 again, node n1 can directly return block b1 to the client. And the query frequency of block b1 on node n1 increases accordingly, which will affect the distribution of block b1 in the next round.

[0098] The above is only a preferred embodiment of the present invention, and the present invention should not be limited to the contents disclosed in the embodiment and the drawings. Any equivalent or modification completed without departing from the spirit disclosed in the present invention shall fall within the protection scope of the present invention.

Claims

1. A method for distributing and storing multiple copies of blockchain based on genetic algorithm, based on the following definition: Definition 1: Blockchain ledger refers to the infrastructure used to store block data. It is essentially a distributed database that integrates peer-to-peer transmission, consensus mechanism, and cryptographic algorithm. Definition 2: A channel refers to a private broadcast domain divided and managed by consensus nodes. The purpose is to isolate the information within the channel to ensure the privacy of transactions. Definition 3: A consensus node is the actual manager of each channel. This node is responsible for reaching consensus on transactions collected from other nodes, forming a consistent sort, and packaging several transactions into blocks and sending them to the leader node. Definition 4: Leader node refers to the manager generated by mandatory setting or dynamic election in each organization. This node is responsible for sending the received batch blocks to other nodes in the organization; Definition 5: Follower nodes refer to other nodes in each organization except the leader node. The node is responsible for storing blocks in the local ledger for block query and verification; Definition 6: Client refers to a terminal device that can initiate transaction proposals or query block requests to any follower node; Definition 7: Block cache refers to the storage device used by each follower node to store the most recently queried blocks. If the block is stored in the block cache, the follower node can return the block directly to the client. Definition 8: The multi-copy mechanism refers to a storage mechanism that is different from the full copy mechanism in the traditional blockchain system. Each block only needs to be stored by a number of follower nodes in the blockchain system. Features: The following steps are included: Step 1: By using a multi-copy mechanism to allocate and store blocks, a multi-copy mechanism blockchain system allocation and storage model is established to lower the storage space requirement threshold for new nodes to join the blockchain, thereby reducing the storage space required for the overall blockchain system; The implementation method of step one is: First, determine the objective function in the block allocation problem, and set the total communication cost in the entire blockchain system as the objective function; the ultimate goal of the block allocation problem is to obtain a block allocation and storage solution that minimizes the total communication cost under the condition of multiple resource constraints. The objective function is as follows: In the formula, x is the block allocation node vector, y is the block allocation set vector, Q(x,y) is the function for calculating the communication cost in the entire blockchain system; m is the number of blocks, n is the number of nodes, r is the number of copies of each block, K is the number of nodes that make up a set of size r; i represents the i-th block, j represents the j-th node, N k represents the kth set; p ik represents the communication cost when the i-th block is assigned to the k-th set; x ij The values ​​of are only 0 and 1. 1 means that the i-th block is allocated to the j-th node, and 0 means no allocation; n" represents the nodes in the k-th set, and n' represents all nodes in the system except n"; c n'n” represents the communication cost between nodes n' and n", f in' represents the query frequency of the ith block on the nth node, s in' Indicates the space occupied by the i-th block stored on the n'th node; In addition, the generated node allocation and storage scheme needs to meet the following constraints; Block allocation constraint: x ij It can only take Boolean values, i.e. 0 or 1; and each block is assigned to r non-duplicate nodes; Set constraint: Each block can only be assigned to a set of size r; Storage space constraint: The total size of blocks stored by each node does not exceed its own storage space limit; Step 2: Based on the genetic algorithm, the allocation and storage model of the multi-copy mechanism blockchain system established in step 1 is optimized to generate approximately optimal allocation and storage locations for all blocks on the blockchain; by setting up an elite system and crossover operators and mutation operators based on the storage node screening table, the genetic algorithm obtains an approximately optimal allocation and storage solution. After the solution is generated, the corresponding nodes are responsible for the actual storage work, thereby reducing the total communication cost of the blockchain system; The implementation method of step 2 is: Step 2.1: Randomly generate the initial population; the initial population consists of P chromosomes; each chromosome represents a block allocation and storage scheme, represented by an r×m allocation and storage matrix; each row in the matrix consists of m genes; each gene represents the allocation and storage location of a block, and its value range is 0 to n-1; first randomly generate allocation and storage locations for each node, and represent them in the form of chromosomes; if the generated scheme does not meet the constraints in step 1, repeat the random selection steps until the constraints are met; Step 2.2: Calculate the fitness of each chromosome according to the total communication cost function Q(x,y) defined in step 1; the smaller the fitness, the better the allocation and storage scheme, and the higher the probability of being selected in step 2.3; conversely, the worse the generated allocation and storage scheme, the lower the probability of being selected; in addition, sort the chromosomes from low to high according to the fitness value, set the first E chromosomes as the elite group, the next PE chromosomes as the ordinary group, and the remaining chromosomes are eliminated; Step 2.3: Use the RouletteWheel Selection algorithm to randomly select a chromosome a and b from the elite group and the ordinary group for crossover operation; first generate a storage node screening table based on the latest storage surplus status of all nodes; then use chromosome a as the parent chromosome and sequentially select the m genes on it with a preset probability p. c Select and pass it to the offspring chromosome o1; according to the block allocation position represented by the selected gene minus the storage space of the corresponding node in the storage node screening table, the node with a remaining capacity greater than 0 is the node that has been successfully screened, and the remaining nodes are eliminated as failed screening; the remaining genes on chromosome b will be allocated to the nodes that have been successfully screened; exchange the roles of chromosomes a and b, generate another offspring chromosome o2 according to the above steps, and add chromosomes o1 and o2 to the next generation population; this method can avoid repeated crossover operations and avoid falling into the dilemma of being unable to generate a correct block allocation and storage plan, thereby improving the generation efficiency of block allocation and storage plans; Step 2.4: Randomly select a chromosome p1 in the current common population, and then randomly select a gene m1 in chromosome p1; generate the storage node screening table described in step 2.2 according to the storage and allocation scheme represented by the chromosome, and subtract the storage space required for the m1th block represented by the gene from the (value of m1)th item in the table; the nodes with remaining capacity greater than 0 are the nodes that can be selected for mutation, and one node is selected from these nodes as the allocation location of the m1th block; by using the storage node screening table, it is ensured that the mutation operation only needs to be run once, thereby improving the efficiency of generating block allocation and storage schemes; Step 2.5: Repeat steps 2.2 to 2.4 until one of the following two conditions is met; Condition 1: The number of cycles reaches the preset maximum number of iterations maxIter; Condition 2: The optimal storage and allocation scheme has not changed after Q generations, that is, the fitness value difference of the best scheme in each generation of population is within 10 -4 Inside; Step 2.6: According to the optimal block allocation and storage scheme obtained in the above steps, the blocks represented by each gene are allocated to the corresponding nodes for storage, so that the total query cost of the entire blockchain system is minimized; Step 3: In the process of optimizing the allocation and storage model of the multi-copy mechanism blockchain system established in step 1 based on the genetic algorithm, the blockchain system regularly uses the genetic optimization algorithm to adjust the allocation position of the block according to the global state, which can effectively improve the efficiency of block query events in the blockchain; In step three, The specific execution process of the query event is as follows: Step 3.1: The client sends a query request for block b1 to any follower node, assuming that the follower node is n1; Step 3.2: If a copy of block b1 is stored in the local ledger or block cache of follower node n1, node n1 directly returns block b1 to the client; and the query frequency of block b1 on node n1 increases accordingly, which will affect the distribution of block b1 in the next round; Step 3.3: If block b1 is not stored in the local ledger and block cache of follower node n1, node n1 finds r storage locations by querying the block storage table, and then selects node n2 with the lowest communication cost with node n1 from these r locations. Node n1 pulls block b1 from the local ledger of node n2 and caches it in the block cache and returns the block to the client; when the client initiates a query request for block b1 to node n1 again next time, node n1 can directly return block b1 to the client; and the query frequency of block b1 on node n1 increases accordingly, which will affect the distribution of block b1 in the next round.

2. A method for distributing and storing multiple copies of a blockchain based on a genetic algorithm as claimed in claim 1, characterized in that: In order to improve the success rate of generating a better block allocation and storage solution, an elite system is implemented in step 2.2, that is, chromosomes with high fitness in some parent populations are directly added to the child population as elites of the parent population. This can ensure that chromosomes and their genes with better performance in each generation of the parent population can be passed on to the next generation of the population, thereby improving the success rate of generating a better block allocation and storage solution.

3. A method for allocating and storing multiple copies of a blockchain based on a genetic algorithm as claimed in claim 1, characterized in that: In order to improve the efficiency of generating block allocation and storage schemes, a storage node screening table is used in steps 2.3 and 2.4, that is, a storage node screening table is generated according to the storage space margin of each node in the blockchain system and the genes that do not need to be changed. The nodes with remaining capacity greater than 0 are the nodes that can be selected by crossover operation or mutation operation. Through this method, it can ensure that a block allocation and storage scheme that meets the constraints in step 1 is successfully generated once, thereby improving the efficiency of generating block allocation and storage schemes.

4. A method for distributing and storing multiple copies of a blockchain based on a genetic algorithm as claimed in claim 1, characterized in that: In order to further reduce the total communication cost of the block allocation and storage solution, a block cache is used in step 3, that is, each block pulled from other nodes is cached in the block cache. The read and write efficiency of the block cache is higher than that of the memory. Therefore, when the client still requests the block from the node next time, the node can directly return the block to the client from the block cache. The communication cost of the query block event is 0, thereby further reducing the total communication cost of the block allocation and storage solution.