Voting machine construction method and device based on preset contract and storage medium
Through the voting machine construction method based on preset contracts, the problem of low voting efficiency of smart contracts in the blockchain is solved, efficient voting process and contract management are achieved, and the consensus rate is improved.
Patent Information
- Application Number
- CN202411007313.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-25
- Publication Date
- 2024-10-01
AI Technical Summary
The frequent contract operations of smart contracts in the blockchain and the participation of multiple nodes lead to low voting efficiency.
A voting machine construction method based on a preset contract is adopted, including five steps: pre-deployment of the voting machine, generating contract proposal ID, obtaining the current proposal collection, current node voting and recording voting. By confirming the identity of the contract caller, the contract proposal is generated ID, determine voting status, obtain voting details, conduct voting and update voting records to ensure the efficiency and accuracy of the voting process.
It improves the efficiency of the voting process of smart contracts in the blockchain, ensures that the voting process is not restricted by access rights and the number of participating nodes, flexibly configures voting rules, and improves contract management efficiency and consensus rate.
Smart Images

Figure CN118740394A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of underlying blockchain technology, and in particular to a method for constructing a voting machine based on a preset contract. Background Art
[0002] All nodes in the blockchain maintain a public ledger, which is visible to any node on the storage block, thus ensuring that it cannot be forged or tampered with. Blockchains can usually be divided into public chains, private chains, and consortium chains based on access rights. A public chain refers to a blockchain that anyone can access and participate in consensus according to the protocol; a private chain refers to a blockchain where the authority is in an organization and is fully controlled by the organization; and a consortium chain refers to a blockchain where the consensus process is controlled by pre-selected nodes. A smart contract is a contract that can be automatically executed on a computer system when certain conditions are met. However, when managing the life cycle of a contract, frequent contract operations require an efficient voting mechanism. Summary of the invention
[0003] The present invention proposes a method for constructing a voting machine based on a preset contract, which can solve at least one of the above-mentioned technical problems.
[0004] To achieve the above object, the present invention adopts the following technical solutions:
[0005] A method for building a voting machine based on a preset contract, including five steps: pre-deployment of the voting machine, generation of a contract proposal ID, acquisition of the current proposal collection, current node voting, and recording of voting;
[0006] Among them, the contract caller identity includes confirming the contract caller type and the caller identity configuration;
[0007] Among them, generating a contract proposal ID includes obtaining a set of contract proposals being voted on and generating a contract proposal ID;
[0008] After the contract proposal ID is generated, the voting process begins; then the current proposal voting status is determined by obtaining the set of contract proposals being voted on; the current proposal voting details are obtained, and the voting opinions of this node are stored in the database;
[0009] Determine whether the voting is over based on the current proposal voting details, and record and update all votes.
[0010] Furthermore, the confirmation of the identity of the contract caller described in the present invention is specifically to determine whether the contract caller is a genesis node or a witness node. If the contract caller is a genesis node, it indicates that all votes can be passed or opposed by one vote of the genesis node; if the contract caller is a witness node, it indicates that all voting processes must have at least two-thirds of the witness nodes agree or one-third of the witness nodes oppose, and the voting process is considered to be completed.
[0011] Furthermore, the present invention generates a contract proposal ID and calls the process of generating a unique proposal ID by presetting a plan. First, the code returned by the contract operation type is passed into the contract address to obtain the request parameter code. Secondly, after obtaining the request parameter code, the presetting plan contract is called to generate a unique proposal ID for the contract, thereby entering the voting process.
[0012] Furthermore, the current proposal voting status of the present invention includes obtaining a set of contract proposals being voted on, and then determining the current proposal voting status;
[0013] The acquisition of the set of contract proposals being voted on is to acquire the set of contracts being voted on in the entire network at this time, including the address of the contract proposal being voted on, the proposal ID, and the life cycle stage of the contract;
[0014] The current proposal voting status is determined by the following: if the current proposal receives the approval of two-thirds of the witness nodes or the opposition of one-third of the witness nodes, the current contract proposal voting is completed; if the current proposal ID exists in the set of contract proposals being voted on, the current contract proposal voting is not completed, and the current node voting status continues to be determined.
[0015] Furthermore, the current node voting status of the present invention includes first obtaining the voting details of the current proposal, reading the database in the guard block, including the number of votes in favor and against, and then judging whether the current node has voted based on the voting record received for the current proposal, and finally the current node votes; if the current node has voted, there is no need to update the voting record; if the current node has not voted, the voting record needs to be updated;
[0016] Record and update all votes. If the current node is an approval vote, obtain the set of approval nodes and remove the votes that have been cast but the nodes are invalid. If the current node is an opposition vote, obtain the set of opposition nodes and remove the votes that have been cast but the nodes are invalid. After recording all votes, calculate the voting results and update the number of votes.
[0017] On the other hand, the present invention further discloses a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of the above method.
[0018] On the other hand, the present invention further discloses a computer-readable storage medium storing a computer program, wherein when the computer program is executed by a processor, the processor executes the steps of the above method.
[0019] It can be seen from the above technical solution that the method for constructing a voting machine based on a preset contract of the present invention is to solve the problem of low voting efficiency caused by frequent contract operations in the blockchain and a large number of participating nodes.
[0020] The present invention proposes a voting machine construction method based on preset contracts, which is not restricted by access rights and the number of participating nodes, and can flexibly and efficiently support the voting process of smart contracts in the blockchain, thereby improving the blockchain consensus rate.
[0021] Specifically, the present invention includes the following advantages:
[0022] 1. The present invention is not limited by access rights and the number of participating nodes, and can efficiently support the voting process of smart contracts in the blockchain.
[0023] 2. The present invention can flexibly cooperate with the frequent voting mechanism in the contract life cycle management process to improve the efficiency of contract management.
[0024] 3. The present invention flexibly configures voting rules through pre-set contracts. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] Figure 1 It is a structural schematic diagram of the present invention. DETAILED DESCRIPTION
[0026] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments.
[0027] like Figure 1 As shown, the method for constructing a voting machine based on a preset contract described in this embodiment includes five steps: pre-deployment of the voting machine, generation of a contract proposal ID, acquisition of the current proposal collection, current node voting, and recording of voting;
[0028] Among them, the pre-deployment of voting machines includes confirming the contract caller type and the caller identity configuration;
[0029] Among them, generating a contract proposal ID includes obtaining a set of contract proposals being voted on and generating a contract proposal ID;
[0030] The contract proposal set being voted on determines whether the current contract has an ongoing proposal ID. If the contract has an ongoing proposal ID, the next step is to generate a contract proposal ID.
[0031] The proposal ID calls the proposal contract (preset contract one) according to the contract address and contract operation type of the passed parameters, and queries the contract status version number (which volume performs this type of contract operation) and generates a contract proposal ID.
[0032] After the contract proposal ID is generated, the voting process begins; then the current proposal voting status is determined by obtaining the contract proposal set being voted on; the current proposal voting details are obtained, and the voting opinions of this node are stored in the database; based on the current proposal voting storage details, it is determined whether the voting is over, and all votes are recorded and updated.
[0033] The current node voting status includes obtaining the current proposal voting details and the current node passing in the voting opinion.
[0034] The current node voting stage obtains the voting details of the current proposal and determines whether the node has voted. If not, it starts to pass in the current node's voting opinion (agree or disagree) and calls the voting machine contract (preset contract 2) to vote on the unique contract proposal ID and store the voting opinion.
[0035] The voting record includes determining whether the voting is over and recording and updating all votes.
[0036] The rules for determining whether the voting is over are as follows:
[0037] If the proposal ID has received approval from 2 / 3 of the witness nodes or opposition from 1 / 3 of the nodes, the voting process for the contract proposal is completed, and it is deleted from the set of contracts being voted on; otherwise, other witness nodes continue the above voting process.
[0038] The confirmation of the identity of the contract caller is specifically to determine whether the contract caller is a genesis node or a witness node. If the contract caller is a genesis node, it indicates that all votes can be passed or opposed by one vote of the genesis node; if the contract caller is a witness node, it indicates that all voting processes must be agreed by at least two-thirds of the witness nodes or opposed by one-third of the witness nodes before the voting process is considered complete.
[0039] The contract proposal generates a proposal ID and calls the Generate Plan Preset Contract to generate a unique proposal ID. First, the code returned by the contract operation type is passed into the contract address to obtain the request parameter code. Then, after obtaining the request parameter code, the Generate Plan Preset Contract is called to generate a unique proposal ID for the contract, and finally the voting process is entered.
[0040] Get the set of contract proposals being voted on, get the set of contracts being voted on in the entire network at this time, including the contract proposal address being voted on, proposal ID, and the life cycle stage of the contract.
[0041] Determine the voting status of the current proposal. If the current proposal receives approval from two-thirds of the witness nodes or opposition from one-third of the witness nodes, the voting for the current contract proposal is completed. If the current proposal ID exists in the set of contract proposals being voted on, the voting for the current contract proposal is not completed, and continue to determine the voting status of the current node.
[0042] The current node votes, and needs to first obtain the current proposal voting details, read the database in the guardian block, including the number of votes in favor and against, and then determine whether the current node has voted based on the voting records received by the current proposal, and finally the current node votes. If the current node has voted, there is no need to update the voting record; if the current node has not voted, the voting record needs to be updated.
[0043] Record and update all votes. If the current node is an approval vote, obtain the approval node set and remove the votes that have been voted but the node is invalid. If the current node is an opposition vote, obtain the opposition node set and remove the votes that have been voted but the node is invalid. After recording all votes, calculate the voting results and update the votes.
[0044] Specifically, when the contract is deployed successfully during implementation, the contract address is returned. However, the contract caller can only call the contract after obtaining the consensus of other witness nodes through the voting machine. First, the code returned by the contract operation type (deployment, upgrade, freeze, thaw, revoke) is passed to the contract address to obtain the request parameter code. Secondly, after obtaining the request parameter code, the generated plan preset contract is called. After returning the unique proposal ID of the contract, the consensus stage is entered.
[0045] Find the details of the contract proposal that is currently being voted on from the database. If the contract address addr is an empty string, it means returning the details of all contracts that are currently being voted on. Each witness node needs to generate a voting code for the contract proposal that is currently being voted on, combining its own vote with the proposal ID of the contract proposal. The witness node calls the proposal voting contract (preset contract one), and passes the voting code to the voting contract for voting. After multiple verifications of the identity of each contract calling node, voting opinions, etc., the proposal contract that is currently being voted on stores the opinions. At the same time (in this case, the caller is the witness node), it calculates whether the number of nodes that agree is greater than 2 / 3 or whether the number of nodes that oppose is greater than 1 / 3. Once a certain standard is reached, the voting for the contract proposal is completed, and the state of the contract is changed accordingly (to achieve the transfer of contract state), and the vote ends.
[0046] Furthermore, it is necessary to determine whether the current node has voted based on the current proposal voting details: if the current proposal contract has reached the number of votes required to end the voting, the current contract proposal voting is completed; but if the current proposal ID exists in the voting contract proposal set, the current contract proposal voting is not completed, and the current node continues to determine whether it has voted for the current proposal contract. Other witness nodes repeat the above voting process until the voting ends, obtain the voting details of the current proposal contract, read the database in the guardian block, including the number of votes in favor and against, and then determine whether the current node has voted based on the voting records received for the current proposal, and finally the current node votes. If the current node has voted, there is no need to update the voting record; if the current node has not voted, the current node voting opinion is passed in to call the voting machine contract (preset contract 2) to vote for the unique contract proposal ID, and the voting opinion is stored in the database. Record and update all votes. If the current node is an approval vote, obtain the approval node set, and remove the votes that have voted but the node is invalid; if the current node is an opposition vote, obtain the opposition node set, and remove the votes that have voted but the node is invalid. After recording all votes, the voting results are calculated and the number of votes is updated. This is until the voting for the current proposal contract ends, the contract caller successfully calls the proposal contract, and makes corresponding changes to the contract status, that is, the contract deployment takes effect, thus realizing the contract status transfer.
[0047] In summary, the embodiment of the present invention proposes a method for constructing a voting machine based on a preset contract, which is not restricted by access rights and the number of participating nodes, and can flexibly and efficiently support the voting process of smart contracts in the blockchain, thereby improving the blockchain consensus rate.
[0048] In yet another aspect, the present invention further discloses a computer-readable storage medium storing a computer program, wherein when the computer program is executed by a processor, the processor executes the steps of any of the above methods.
[0049] On the other hand, the present invention further discloses a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of any of the above methods.
[0050] In another embodiment provided by the present application, a computer program product including instructions is also provided, which, when executed on a computer, enables the computer to execute the steps of any method in the above embodiments.
[0051] It is understandable that the system provided by the embodiment of the present invention corresponds to the method provided by the embodiment of the present invention, and the explanation, examples and beneficial effects of the relevant contents can refer to the corresponding parts in the above method.
[0052] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the program can be stored in a non-volatile computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0053] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0054] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for constructing a voting machine based on a preset contract, characterized in that: It includes five steps: confirming the identity of the contract caller, generating a contract proposal ID, obtaining a collection of proposals, voting at the current node, and recording the vote; Among them, the contract caller identity includes confirming the contract caller type and the caller identity configuration; Among them, generating a contract proposal ID includes obtaining a set of contract proposals being voted on and generating a contract proposal ID; After the contract proposal ID is generated, the voting process begins; then the current proposal voting status is determined by obtaining the set of contract proposals being voted on; the current proposal voting details are obtained, and the voting opinions of this node are stored in the database; Determine whether the voting is over based on the current proposal voting details, and record and update all votes.
2. The method for constructing a voting machine based on a pre-set contract according to claim 1, characterized in that: Confirming the identity of the contract caller is to determine whether the contract caller is a genesis node or a witness node. If the contract caller is a genesis node, it indicates that all votes can be passed or opposed by one vote of the genesis node; if the contract caller is a witness node, it indicates that all voting processes must be approved by at least two-thirds of the witness nodes or opposed by one-third of the witness nodes before the voting process is considered complete.
3. The method for constructing a voting machine based on a pre-set contract according to claim 1, characterized in that: The process of generating a contract proposal ID and calling the preset contract to generate a unique proposal ID is as follows: first, the code returned by the contract operation type is passed into the contract address to obtain the request parameter code, and then the preset contract is called after obtaining the request parameter code, thereby generating a unique proposal ID for the contract and entering the voting process.
4. The method for constructing a voting machine based on a pre-set contract according to claim 1, characterized in that: The current proposal voting status includes obtaining the set of contract proposals being voted on, and then determining the current proposal voting status; The acquisition of the set of contract proposals being voted on is to acquire the set of contracts being voted on in the entire network at this time, including the address of the contract proposal being voted on, the proposal ID, and the life cycle stage of the contract; The current proposal voting status is determined by the following: if the current proposal receives the approval of two-thirds of the witness nodes or the opposition of one-third of the witness nodes, the current contract proposal voting is completed; if the current proposal ID exists in the set of contract proposals being voted on, the current contract proposal voting is not completed, and the current node voting status continues to be determined.
5. The method for constructing a voting machine based on a preset contract according to claim 4, characterized in that: The current node voting status includes first obtaining the current proposal voting details, reading the database in the guardian block, including the number of votes in favor and against, and then judging whether the current node has voted based on the voting records received for the current proposal, and finally the current node votes; If the current node has voted, there is no need to update the voting record; if the current node has not voted, the voting record needs to be updated; Record and update all votes. If the current node is an approval vote, obtain the set of approval nodes and remove the votes that have been cast but the nodes are invalid. If the current node is an opposition vote, obtain the set of opposition nodes and remove the votes that have been cast but the nodes are invalid. After recording all votes, calculate the voting results and update the number of votes.
6. A computer device comprising a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of the method according to any one of claims 1 to 5.
7. A computer-readable storage medium storing a computer program, wherein when the computer program is executed by a processor, the processor is caused to perform the steps of the method according to any one of claims 1 to 5.
