A blockchain public chain resource competition behavior simulation system construction method and system
Patent Information
- Application Number
- CN202511608495.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-05
- Publication Date
- 2026-10-30
AI Technical Summary
然而,部分节点可能出于自身利益,采取自私行为(如拒绝共享资源或篡改数据),从而破坏系统的公平性和可靠性
(1)资源竞争行为模拟系统基于主流区块链公有链客户端进行二次开发实现,具有广泛代表性,能够模拟真实区块链公有链网络中的攻击行为;
Smart Images

Figure CN123020092A_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of blockchain technology, and in particular relates to a method and system for constructing a public blockchain resource competition behavior simulation system. Background Technology
[0002] A public blockchain system is a decentralized system developed based on blockchain technology. It utilizes a distributed network for management and verification, eliminating the need for a centralized institution. In a public blockchain system, numerous participants run specific public blockchain kernel programs, becoming nodes on the network. These nodes maintain a public record through a consensus algorithm, and all records are stored on the blockchain. The core characteristics of a public blockchain are decentralization and immutability. This means that there is no central figure controlling the network, and all records are public to all nodes and cannot be tampered with.
[0003] While the decentralized nature of public blockchain systems offers numerous advantages, creating a seemingly secure system through inter-node cooperation, certain security threats still exist. Because a public blockchain is a decentralized network, lacking a centralized institution to manage and protect the network's data, this inherent insecurity is inherent. Furthermore, the public transparency of the network, with all records publicly visible, makes it easier for attackers to identify targets and launch attacks. Additionally, many large nodes possess significant computing power, potentially leading to network centralization.
[0004] With the widespread application of blockchain technology in distributed data storage and verification, the collaborative and competitive behavior among nodes has an increasingly significant impact on system performance and security. However, some nodes may act selfishly for their own benefit (such as refusing to share resources or tampering with data), thereby undermining the fairness and reliability of the system. Therefore, constructing a blockchain public chain resource competition behavior simulation system has significant theoretical and practical value. Summary of the Invention
[0005] This application provides a method and system for constructing a blockchain public chain resource competition behavior simulation system to solve the above-mentioned technical problems.
[0006] Firstly, a method for constructing a blockchain public chain resource competition behavior simulation system is disclosed, the method comprising: Step S1: Obtain the open-source code of the public blockchain; construct selfish nodes and non-selfish nodes. A selfish node is a node that does not broadcast the acquisition of new resources to the public blockchain after acquiring them, or only broadcasts the acquisition of new resources to the public blockchain and all non-hidden selfish blockchains under preset conditions. A non-selfish node is a node that broadcasts the acquisition of new resources to the public blockchain after acquiring them; perform preliminary secondary development on the open-source code to enable selfish nodes to determine whether the resources they acquire are new resources, configure a dedicated selfish blockchain for each selfish node to store its acquired new resources, and maintain the selfish blockchain with the goal of replacing the public blockchain. Each block in the selfish blockchain is a new resource block corresponding to the new resources acquired by the selfish node through selfish behavior or a consensus block obtained through the public blockchain. Step S2: Based on the initial secondary development of open source code, a first processing logic module is set for each selfish node to obtain a further developed open source code; the further developed open source code enables the selfish node to verify the message when it receives a message broadcast by other nodes to the public blockchain that it has acquired new resources. After verification, the first processing logic module of the selfish node determines whether to broadcast the corresponding new resource block on the selfish blockchain or continue to hide the selfish blockchain based on the chain length of the selfish blockchain. Step S3: Modify the function for creating the genesis block in the redeveloped open-source code to reduce the block creation difficulty of each block in the public blockchain and the private blockchain, and obtain the open-source code to be compiled. Step S4: Encode the open-source code to be compiled and deploy multiple selfish nodes on the local area network; compile the open-source code of the public blockchain and deploy multiple non-selfish nodes on the local area network. Step S5: Build a public blockchain locally, and perform resource compression processing on each selfish node and non-selfish node deployed on the local area network to simulate resource competition in the public blockchain.
[0007] Preferably, step S1 involves preliminary secondary development of the open-source code to enable selfish nodes to determine whether the resources they acquire are new resources, and configuring a dedicated selfish blockchain for storing the new resources acquired by the selfish node, including: Step S11: Perform preliminary secondary development on the open source code so that selfish nodes can determine whether the resources they acquire are new resources; when the acquired resources are new resources, determine the data, workload, and timestamp corresponding to the new resources, establish a block corresponding to the new resources, and create an index for the block. Step S12: Create a vector array s_road. The array s_road is used to store a subset of all new resources obtained by selfish nodes through selfish behavior. This subset is a set of new resources obtained by selfish nodes through selfish behavior after obtaining a consensus block through the public blockchain. Each array element stores a new resource, that is, each element in the array s_road corresponds to a new resource block. Step S13: Create a vector array s_index, which is used to store the index of the new resource on the public blockchain. Step S14: Create a vector array h_road. The array h_road is used to store some resources on the public blockchain. These resources are the resources corresponding to the newly added blocks on the public blockchain after the selfish node obtains the consensus block through the public blockchain. Step S15: Set the global variable s_len to store the length of the selfish blockchain, and the global variable h_len to store the chain length of the public blockchain; Step S16: When the value of global variable s_len is 2 and the value of global variable h_len is 1, traverse the new resources stored in the s_road array in the order of block generation, and broadcast the block corresponding to the new resource to the public blockchain and all private blockchains in the non-hidden state; clear the arrays s_road, s_index, and h_road, and set s_len and h_len to 0; Step S17: Hide the block corresponding to the new resource.
[0008] Preferably, step S2: the first processing logic module of the selfish node verifies the message, and after successful verification, determines whether to broadcast the corresponding new resource block on the selfish blockchain or continue to hide the selfish blockchain based on the chain length of the selfish blockchain, including: Step S21: After the selfish node receives a message from another node that it has acquired new resources, it verifies whether the message is complete. If it is incomplete, it sends a corresponding request until it obtains the complete message that it has acquired new resources. After the data transaction legality check is passed, proceed to step S22. Step S22: The selfish node obtains the chain length s_len of the selfish blockchain and chooses one of the following operations: Operation 1: When variable s_len=0, it means that the selfish node has not yet successfully stored the new resource on the selfish blockchain. Then, verify the legality of the new resource corresponding to the message that the other nodes have obtained the new resource, broadcast the resource information of the new resource, and update the new resource as a consensus resource. Operation 2: When h_len=0, it means that the new resource corresponding to the message of the other node obtaining the new resource is the first resource generated by the other node based on the consensus algorithm, excluding the selfish node. After verifying the legality of the first resource, the first resource is added to the end of h_road, and the value of h_len is incremented by 1. When s_len-h_len=1, the selfish node traverses each element in the s_road array, broadcasts the resource information corresponding to the new resource block corresponding to each element in the s_road array, clears the contents stored in the arrays s_road, s_index and h_road, and sets s_len and h_len to 0; When s_len=1 and h_len=1 or s_len-h_len>1, selfish nodes and non-selfish nodes continue to compete for the next new resource without performing any operations; Operation 3: When h_len > 0, it indicates that both the selfish blockchain and the public blockchain corresponding to the selfish node have resource information for the new resource, and the competition between the selfish node and the non-selfish node has not ended. After verifying the legality of the new resource, add the new resource to the end of h_road, and increment the value of h_len by 1. If the relationship between s_len and h_len does not satisfy s_len - h_len = 1 at this time, then choose one of the following operations: When s_len=1 and h_len=2, it means that the chain length of the public blockchain is greater than the chain length of the selfish blockchain, the resource competition of the selfish node fails, the arrays s_road, s_index and h_road are cleared, and s_len and h_len are set to 0. When s_len-h_len>1, the selfish node and the normal node continue to compete for the next new resource without performing any operation.
[0009] Preferably, step S3: Modify the function for creating the genesis block in the redeveloped open-source code to reduce the block difficulty of each block in both the public and private blockchains, resulting in the open-source code to be compiled, including: Modify the function and related parameter values for creating the genesis block in the redeveloped open-source code to reduce the block creation difficulty in both public and private blockchains, and increase the value of the proof-of-work limit to reduce the difficulty of proof-of-work.
[0010] Preferably, step S4: encoding the open-source code to be compiled and deploying multiple selfish nodes on the local area network; encoding the open-source code of the public blockchain and deploying multiple non-selfish nodes on the local area network, includes: Compile the open-source code to be compiled and the open-source code of the public blockchain locally, install dependencies and the open-source software BFGMiner, create a self-interested node image based on the compiled open-source code to be compiled, create a non-self-interested node image based on the compiled open-source code of the public blockchain, and deploy multiple self-interested nodes and multiple non-self-interested nodes on the local area network.
[0011] Secondly, a system for constructing a blockchain public chain resource competition behavior simulation system is disclosed, the system comprising: Initialization module: Configured to obtain the open-source code of the public blockchain; construct selfish nodes and non-selfish nodes. A selfish node is a node that does not broadcast the acquired new resources to the public blockchain or only broadcasts the acquired new resources to the public blockchain and all non-hidden selfish blockchains under preset conditions. A non-selfish node is a node that broadcasts the acquired new resources to the public blockchain after acquiring them. The open-source code is initially modified to enable selfish nodes to determine whether the resources they acquire are new resources. A dedicated selfish blockchain is configured for each selfish node to store its acquired new resources. The goal of selfish nodes in maintaining their selfish blockchains is to replace the public blockchain. Each block in the selfish blockchain is a new resource block corresponding to the new resources acquired by the selfish node through selfish behavior or a consensus block obtained through the public blockchain. Broadcast module: Based on the initial secondary development of open source code, a first processing logic module is set for each selfish node to obtain a further developed open source code; the further developed open source code enables the selfish node to verify the message when it receives a message broadcast by other nodes to the public blockchain that it has acquired new resources. After verification, the first processing logic module of the selfish node determines whether to broadcast the corresponding new resource block on the selfish blockchain or continue to hide the selfish blockchain based on the chain length of the selfish blockchain. Compilation module: Configured to modify the function for creating the genesis block in the redeveloped open-source code, reducing the block creation difficulty of each block in both public and private blockchains, and obtaining the open-source code to be compiled; Deployment module: Configured to encode the open-source code to be compiled, deploying multiple selfish nodes on the local area network; and to compile the open-source code of the public blockchain, deploying multiple non-selfish nodes on the local area network. Simulation module: Configured to build a public blockchain locally, and perform resource compression processing on each selfish node and non-selfish node deployed on the local area network, thereby simulating resource competition in the public blockchain.
[0012] Thirdly, an electronic device is disclosed, the electronic device comprising: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method as described above.
[0013] Fourthly, a non-transitory computer-readable storage medium storing computer instructions for causing the computer to perform the method described above is disclosed.
[0014] This application proposes a method and system for constructing a blockchain public chain resource competition behavior simulation system. It uses mainstream blockchain public chain clients and adds selfish node behavior logic through secondary development of the source code, thereby realizing a blockchain public chain resource competition behavior simulation system in a local area network.
[0015] This application has the following technical advantages: (1) The resource competition behavior simulation system is based on the secondary development of mainstream blockchain public chain clients. It has broad representativeness and can simulate attack behavior in real blockchain public chain networks. (2) The difficulty of acquiring new resources has been modified, which reduces resource consumption and improves system operating efficiency; (3) Real blockchain public chain networks, whether mainnet or testnet, require huge computing power to launch attacks. This application provides a simple and easy-to-use simulation system, making it possible to simulate attack behavior. Attached Figure Description
[0016] Figure 1 A flowchart illustrating the construction method of a simulation system for resource competition behavior in a public blockchain. Figure 2 A schematic diagram of a blockchain public chain resource competition behavior simulation system; Figure 3 A schematic diagram of the system structure for simulating resource competition behavior in a public blockchain. Detailed Implementation
[0017] The embodiments of this application will be described in detail below with reference to the accompanying drawings.
[0018] like Figures 1-2 As shown, this application provides a method for constructing a blockchain public chain resource competition behavior simulation system, the method including: Step S1: Obtain the open-source code of the public blockchain; construct selfish nodes and non-selfish nodes. A selfish node is a node that does not broadcast the acquisition of new resources to the public blockchain after acquiring them, or only broadcasts the acquisition of new resources to the public blockchain and all non-hidden selfish blockchains under preset conditions. A non-selfish node is a node that broadcasts the acquisition of new resources to the public blockchain after acquiring them; perform preliminary secondary development on the open-source code to enable selfish nodes to determine whether the resources they acquire are new resources, configure a dedicated selfish blockchain for each selfish node to store its acquired new resources, and maintain the selfish blockchain with the goal of replacing the public blockchain. Each block in the selfish blockchain is a new resource block corresponding to the new resources acquired by the selfish node through selfish behavior or a consensus block obtained through the public blockchain. Step S2: Based on the initial secondary development of open source code, a first processing logic module is set for each selfish node to obtain a further developed open source code; the further developed open source code enables the selfish node to verify the message when it receives a message broadcast by other nodes to the public blockchain that it has acquired new resources. After verification, the first processing logic module of the selfish node determines whether to broadcast the corresponding new resource block on the selfish blockchain or continue to hide the selfish blockchain based on the chain length of the selfish blockchain. Step S3: Modify the function for creating the genesis block in the redeveloped open-source code to reduce the block creation difficulty of each block in the public blockchain and the private blockchain, and obtain the open-source code to be compiled. Step S4: Encode the open-source code to be compiled and deploy multiple selfish nodes on the local area network; compile the open-source code of the public blockchain and deploy multiple non-selfish nodes on the local area network. Step S5: Build a public blockchain locally, and perform resource compression processing on each selfish node and non-selfish node deployed on the local area network to simulate resource competition in the public blockchain.
[0019] Furthermore, the open-source software is Bitcoin Core v22.0.
[0020] Step S1 involves preliminary secondary development of the open-source code to enable selfish nodes to determine whether the resources they acquire are new resources, and configuring a dedicated selfish blockchain for each selfish node to store the new resources it acquires, including: Step S11: Perform preliminary secondary development on the open source code so that selfish nodes can determine whether the resources they acquire are new resources; when the acquired resources are new resources, determine the data, workload, and timestamp corresponding to the new resources, establish a block corresponding to the new resources, and create an index for the block. Step S12: Create a vector array s_road. The array s_road is used to store a subset of all new resources obtained by selfish nodes through selfish behavior. This subset is a set of new resources obtained by selfish nodes through selfish behavior after obtaining a consensus block through the public blockchain. Each array element stores a new resource, that is, each element in the array s_road corresponds to a new resource block. Step S13: Create a vector array s_index, which is used to store the index of the new resource on the public blockchain. Step S14: Create a vector array h_road. The array h_road is used to store some resources on the public blockchain. These resources are the resources corresponding to the newly added blocks on the public blockchain after the selfish node obtains the consensus block through the public blockchain. Step S15: Set the global variable s_len to store the length of the selfish blockchain, and the global variable h_len to store the chain length of the public blockchain; Step S16: When the value of global variable s_len is 2 and the value of global variable h_len is 1, traverse the new resources stored in the s_road array in the order of block generation, and broadcast the block corresponding to the new resource to the public blockchain and all private blockchains in the non-hidden state; clear the arrays s_road, s_index, and h_road, and set s_len and h_len to 0; Step S17: Hide the block corresponding to the new resource.
[0021] Step S2: The first processing logic module of the selfish node verifies the message. After successful verification, it determines whether to broadcast the corresponding new resource block on the selfish blockchain or continue to hide the selfish blockchain based on the chain length of the selfish blockchain, including: Step S21: After the selfish node receives a message from another node that it has acquired new resources, it verifies whether the message is complete. If it is incomplete, it sends a corresponding request until it obtains the complete message that it has acquired new resources. After the data transaction legality check is passed, proceed to step S22. Step S22: The selfish node obtains the chain length s_len of the selfish blockchain and chooses one of the following operations: Operation 1: When variable s_len=0, it means that the selfish node has not yet successfully stored the new resource on the selfish blockchain. Then, verify the legality of the new resource corresponding to the message that the other nodes have obtained the new resource, broadcast the resource information of the new resource, and update the new resource as a consensus resource. Operation 2: When h_len=0, it means that the new resource corresponding to the message of the other node obtaining the new resource is the first resource generated by the other node based on the consensus algorithm, excluding the selfish node. After verifying the legality of the first resource, the first resource is added to the end of h_road, and the value of h_len is incremented by 1. When s_len-h_len=1, the selfish node traverses each element in the s_road array, broadcasts the resource information corresponding to the new resource block corresponding to each element in the s_road array, clears the contents stored in the arrays s_road, s_index and h_road, and sets s_len and h_len to 0; When s_len=1 and h_len=1 or s_len-h_len>1, selfish nodes and non-selfish nodes continue to compete for the next new resource without performing any operations; Operation 3: When h_len > 0, it indicates that both the selfish blockchain and the public blockchain corresponding to the selfish node have resource information for the new resource, and the competition between the selfish node and the non-selfish node has not ended. After verifying the legality of the new resource, add the new resource to the end of h_road, and increment the value of h_len by 1. If the relationship between s_len and h_len does not satisfy s_len - h_len = 1 at this time, then choose one of the following operations: When s_len=1 and h_len=2, it means that the chain length of the public blockchain is greater than the chain length of the selfish blockchain, the resource competition of the selfish node fails, the arrays s_road, s_index and h_road are cleared, and s_len and h_len are set to 0. When s_len-h_len>1, the selfish node and the normal node continue to compete for the next new resource without performing any operation.
[0022] Step S3: Modify the function for creating the genesis block in the redeveloped open-source code to reduce the block difficulty of each block in both the public and private blockchains, resulting in the open-source code to be compiled, including: Modify the function and related parameter values for creating the genesis block in the redeveloped open-source code to reduce the block creation difficulty in both public and private blockchains, and increase the value of the proof-of-work limit to reduce the difficulty of proof-of-work.
[0023] In this application, the function call for creating the genesis block in the redeveloped open-source code is modified as follows: This reduces the difficulty of block production, improving system efficiency while reducing resource consumption, with negligible resource consumption for block packaging. Increasing the POW limit further reduces the difficulty of proof-of-work.
[0024] Further, step S4: encoding the open-source code to be compiled and deploying multiple selfish nodes on the local area network; encoding the open-source code of the public blockchain and deploying multiple non-selfish nodes on the local area network, including: Compile the open-source code to be compiled and the open-source code of the public blockchain locally, install dependencies and the open-source software BFGMiner, create a self-interested node image based on the compiled open-source code to be compiled, create a non-self-interested node image based on the compiled open-source code of the public blockchain, and deploy multiple self-interested nodes and multiple non-self-interested nodes on the local area network.
[0025] In this application, the open-source code to be compiled is compiled, dependencies and the open-source software BFGMiner are installed, and a selfish node client image is created; the open-source code of the public blockchain, namely the original Bitcoin Core v22.0 version code, is compiled, dependencies and the open-source software BFGMiner are installed, and a normal node client image is created; and Docker containers are run to run non-selfish nodes and selfish nodes.
[0026] Step S5: Build a public blockchain locally, and perform resource compression processing on each selfish and non-selfish node deployed on the local area network to simulate resource competition in the public blockchain, including: A public blockchain is built locally, and BFGMiner is used to perform resource compression processing on each selfish and non-selfish node deployed on the local area network, thereby simulating resource competition in the public blockchain.
[0027] In this application, selfish nodes and non-selfish nodes respectively execute the bitcoin-cli addnode command to add other nodes as their peers and build a public blockchain network; BFGMiner is started in the containers of selfish nodes and non-selfish nodes respectively to generate blocks; selfish nodes begin to simulate resource competition behavior against non-selfish nodes.
[0028] like Figure 3 As shown, this application provides a system for constructing a blockchain public chain resource competition behavior simulation system, the system comprising: Initialization module: Configured to obtain the open-source code of the public blockchain; construct selfish nodes and non-selfish nodes. A selfish node is a node that does not broadcast the acquired new resources to the public blockchain or only broadcasts the acquired new resources to the public blockchain and all non-hidden selfish blockchains under preset conditions. A non-selfish node is a node that broadcasts the acquired new resources to the public blockchain after acquiring them. The open-source code is initially modified to enable selfish nodes to determine whether the resources they acquire are new resources. A dedicated selfish blockchain is configured for each selfish node to store its acquired new resources. The goal of selfish nodes in maintaining their selfish blockchains is to replace the public blockchain. Each block in the selfish blockchain is a new resource block corresponding to the new resources acquired by the selfish node through selfish behavior or a consensus block obtained through the public blockchain. Broadcast module: Based on the initial secondary development of open source code, a first processing logic module is set for each selfish node to obtain a further developed open source code; the further developed open source code enables the selfish node to verify the message when it receives a message broadcast by other nodes to the public blockchain that it has acquired new resources. After verification, the first processing logic module of the selfish node determines whether to broadcast the corresponding new resource block on the selfish blockchain or continue to hide the selfish blockchain based on the chain length of the selfish blockchain. Compilation module: Configured to modify the function for creating the genesis block in the redeveloped open-source code, reducing the block creation difficulty of each block in both public and private blockchains, and obtaining the open-source code to be compiled; Deployment module: Configured to encode the open-source code to be compiled, deploying multiple selfish nodes on the local area network; and to compile the open-source code of the public blockchain, deploying multiple non-selfish nodes on the local area network. Simulation module: Configured to build a public blockchain locally, and perform resource compression processing on each selfish node and non-selfish node deployed on the local area network, thereby simulating resource competition in the public blockchain.
[0029] The above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit it. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein, and such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.
Claims
1. A method for constructing a blockchain public chain resource competition behavior simulation system, characterized in that, The methods include: Step S1: Obtain the open-source code of the public blockchain; Selfish and non-selfish nodes are constructed. A selfish node is a node that, after acquiring new resources, does not broadcast them to the public blockchain or only broadcasts them to the public blockchain and all non-hidden selfish blockchains under preset conditions. A non-selfish node is a node that, after acquiring new resources, broadcasts them to the public blockchain. The open-source code is initially modified to enable selfish nodes to determine whether the resources they acquire are new resources. A dedicated selfish blockchain is configured for each selfish node to store its acquired new resources. The goal of selfish nodes in maintaining their selfish blockchains is to replace the public blockchain. Each block in the selfish blockchain is either a new resource block corresponding to the new resources acquired by the selfish node through selfish behavior or a consensus block obtained through the public blockchain. Step S2: Based on the initial secondary development of the open-source code, all selfish nodes are assigned the first processing logic module to obtain the further developed open-source code; The redeveloped open-source code enables selfish nodes to verify messages broadcast by other nodes to the public blockchain indicating that they have acquired new resources. Once verified, the selfish node's first processing logic module determines whether to broadcast the corresponding new resource block on the selfish blockchain or continue to hide the selfish blockchain based on the chain length of the selfish blockchain. Step S3: Modify the function for creating the genesis block in the redeveloped open-source code to reduce the block creation difficulty of each block in the public blockchain and the private blockchain, and obtain the open-source code to be compiled. Step S4: Encode the open-source code to be compiled and deploy multiple selfish nodes on the local area network; Compile the open-source code of a public blockchain and deploy multiple non-selfish nodes on the local area network; Step S5: Build a public blockchain locally, and perform resource compression processing on each selfish node and non-selfish node deployed on the local area network to simulate resource competition in the public blockchain.
2. The method as described in claim 1, characterized in that, Step S1 involves preliminary secondary development of the open-source code to enable selfish nodes to determine whether the resources they acquire are new resources, and configuring a dedicated selfish blockchain for each selfish node to store the new resources it acquires, including: Step S11: Perform preliminary secondary development on the open source code so that selfish nodes can determine whether the resources they acquire are new resources; when the acquired resources are new resources, determine the data, workload, and timestamp corresponding to the new resources, establish a block corresponding to the new resources, and create an index for the block. Step S12: Create a vector array s_road. The array s_road is used to store a subset of all new resources obtained by selfish nodes through selfish behavior. This subset is a set of new resources obtained by selfish nodes through selfish behavior after obtaining a consensus block through the public blockchain. Each array element stores a new resource, that is, each element in the array s_road corresponds to a new resource block. Step S13: Create a vector array s_index, which is used to store the index of the new resource on the public blockchain. Step S14: Create a vector array h_road. The array h_road is used to store some resources on the public blockchain. These resources are the resources corresponding to the newly added blocks on the public blockchain after the selfish node obtains the consensus block through the public blockchain. Step S15: Set the global variable s_len to store the length of the selfish blockchain, and the global variable h_len to store the chain length of the public blockchain; Step S16: When the value of global variable s_len is 2 and the value of global variable h_len is 1, traverse the new resources stored in the s_road array in the order of block generation, and broadcast the block corresponding to the new resource to the public blockchain and all private blockchains in the non-hidden state; clear the arrays s_road, s_index, and h_road, and set s_len and h_len to 0; Step S17: Hide the block corresponding to the new resource.
3. The method as described in claim 2, characterized in that, Step S2: The first processing logic module of the selfish node verifies the message. After successful verification, it determines whether to broadcast the corresponding new resource block on the selfish blockchain or continue to hide the selfish blockchain based on the chain length of the selfish blockchain, including: Step S21: After the selfish node receives a message from another node that it has acquired new resources, it verifies whether the message is complete. If it is incomplete, it sends a corresponding request until it obtains the complete message that it has acquired new resources. After the data transaction legality check is passed, proceed to step S22. Step S22: The selfish node obtains the chain length s_len of the selfish blockchain and chooses one of the following operations: Operation 1: When variable s_len=0, it means that the selfish node has not yet successfully stored the new resource on the selfish blockchain. Then, verify the legality of the new resource corresponding to the message that the other nodes have obtained the new resource, broadcast the resource information of the new resource, and update the new resource as a consensus resource. Operation 2: When h_len=0, it means that the new resource corresponding to the message of the other node obtaining the new resource is the first resource generated by the other node based on the consensus algorithm, excluding the selfish node. After verifying the legality of the first resource, the first resource is added to the end of h_road, and the value of h_len is incremented by 1. When s_len-h_len=1, the selfish node traverses each element in the s_road array, broadcasts the resource information corresponding to the new resource block corresponding to each element in the s_road array, clears the contents stored in the arrays s_road, s_index and h_road, and sets s_len and h_len to 0; When s_len=1 and h_len=1 or s_len-h_len>1, selfish nodes and non-selfish nodes continue to compete for the next new resource without performing any operations; Operation 3: When h_len > 0, it indicates that both the selfish blockchain and the public blockchain corresponding to the selfish node have resource information for the new resource, and the competition between the selfish node and the non-selfish node has not ended. After verifying the legality of the new resource, add the new resource to the end of h_road, and increment the value of h_len by 1. If the relationship between s_len and h_len does not satisfy s_len - h_len = 1 at this time, then choose one of the following operations: When s_len=1 and h_len=2, it means that the chain length of the public blockchain is greater than the chain length of the selfish blockchain, the resource competition of the selfish node fails, the arrays s_road, s_index and h_road are cleared, and s_len and h_len are set to 0. When s_len-h_len>1, the selfish node and the normal node continue to compete for the next new resource without performing any operation.
4. The method as described in claim 1, characterized in that, Step S3: Modify the function for creating the genesis block in the redeveloped open-source code to reduce the block difficulty of each block in both the public and private blockchains, resulting in the open-source code to be compiled, including: Modify the function and related parameter values for creating the genesis block in the redeveloped open-source code to reduce the block creation difficulty in both public and private blockchains, and increase the value of the proof-of-work limit to reduce the difficulty of proof-of-work.
5. The method as described in claim 4, characterized in that, Step S4: Encode the open-source code to be compiled and deploy multiple selfish nodes on the local area network; The open-source code for a public blockchain is used to deploy multiple non-selfish nodes on a local area network, including: Compile the open-source code to be compiled and the open-source code of the public blockchain locally, install dependencies and the open-source software BFGMiner, create a self-interested node image based on the compiled open-source code to be compiled, create a non-self-interested node image based on the compiled open-source code of the public blockchain, and deploy multiple self-interested nodes and multiple non-self-interested nodes on the local area network.
6. A system for constructing a blockchain public chain resource competition behavior simulation system, characterized in that, The system includes: Initialization module: Configured to obtain the open-source code of a public blockchain; Selfish and non-selfish nodes are constructed. A selfish node is a node that, after acquiring new resources, does not broadcast them to the public blockchain or only broadcasts them to the public blockchain and all non-hidden selfish blockchains under preset conditions. A non-selfish node is a node that, after acquiring new resources, broadcasts them to the public blockchain. The open-source code is initially modified to enable selfish nodes to determine whether the resources they acquire are new resources. A dedicated selfish blockchain is configured for each selfish node to store its acquired new resources. The goal of selfish nodes in maintaining their selfish blockchains is to replace the public blockchain. Each block in the selfish blockchain is either a new resource block corresponding to the new resources acquired by the selfish node through selfish behavior or a consensus block obtained through the public blockchain. Broadcast module: Configured to set selfish nodes as the first processing logic module based on the initial secondary development open source code, resulting in further developed open source code; The redeveloped open-source code enables selfish nodes to verify messages broadcast by other nodes to the public blockchain indicating that they have acquired new resources. Once verified, the selfish node's first processing logic module determines whether to broadcast the corresponding new resource block on the selfish blockchain or continue to hide the selfish blockchain based on the chain length of the selfish blockchain. Compilation module: Configured to modify the function for creating the genesis block in the redeveloped open-source code, reducing the block creation difficulty of each block in both public and private blockchains, and obtaining the open-source code to be compiled; Deployment module: Configured to encode the open-source code to be compiled and deploy multiple selfish nodes on the local area network; Compile the open-source code of a public blockchain and deploy multiple non-selfish nodes on the local area network; Simulation module: Configured to build a public blockchain locally, and perform resource compression processing on each selfish node and non-selfish node deployed on the local area network, thereby simulating resource competition in the public blockchain.
7. An electronic device, characterized in that, The device includes: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method as described in any one of claims 1-5.
8. A non-transitory computer-readable storage medium storing computer instructions, characterized in that, The computer instructions are used to cause the computer to perform the method as described in any one of claims 1-5.
