Execution method, node and blockchain system of smart contracts in blockchain

By introducing the partitions of control nodes and non -control nodes in the blockchain system, verifying and broadcast contract calling transaction requests, the problem of blockchain network paralysis caused by the incorrect or malicious code of the smart contract code, improved the implementation of security and fault tolerance. sex.

CN114078052BActive Publication Date: 2025-01-28CHINA TELECOM CORP LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202010824718.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-08-17
Publication Date
2025-01-28
Estimated Expiration
2040-08-17

AI Technical Summary

Technical Problem

In blockchain networks, errors or malicious codes in smart contract codes may cause a large number of nodes to be blocked or uncontrollable at the same time, resulting in a block chain network paralysis and transaction results errors, reducing transaction security.

Method used

By introducing the partitions of control nodes and non -control nodes in the blockchain system, control nodes to receive contract calls to call transaction requests, verify and broadcast to other nodes to execute to ensure that the results of the contract call transaction are matched with the expected results to prevent errors or malicious code. spread.

Benefits of technology

Improve the security of the execution of smart contracts and the fault tolerance of the blockchain system, and prevent nodes from paralyzing by errors or malicious code to ensure the accuracy and security of the transaction results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114078052B_ABST
    Figure CN114078052B_ABST
Patent Text Reader

Abstract

The present disclosure relates to an execution method, node and blockchain system of a smart contract in a blockchain, and to the field of computer technology. The method disclosed in the present disclosure includes: each of a plurality of control nodes receives a contract call transaction request sent by a service node, and the contract call transaction request includes: the expected result of contract execution; the contract call transaction request is sent to each non-control node, wherein the number of non-control nodes is less than the maximum number of allowed malicious nodes; the result of the contract call transaction returned by each non-control node is received, and it is verified whether the result of the contract call transaction returned by each non-control node matches the expected result of contract execution; when the result of the contract call transaction returned by each non-control node matches the expected result of contract execution, the contract call transaction request is broadcast to other nodes to execute the contract call transaction.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to a method for executing a smart contract in a blockchain, a node, and a blockchain system. Background Art

[0002] The data on the blockchain is open, transparent and tamper-proof, which improves the security of data storage. Smart contracts are programs stored on the blockchain and can be executed automatically.

[0003] Currently, when most blockchain networks execute a smart contract transaction, all or most of the nodes in the blockchain network need to execute the smart contract at the same time. Summary of the invention

[0004] The inventor found that if there is a problem with the smart contract code or malicious code exists, all nodes executing the smart contract will be affected. Too many nodes may be blocked or uncontrollable at the same time, which will cause the blockchain network to crash and may also cause errors in transaction results, reducing the security of the transaction process.

[0005] A technical problem to be solved by the present disclosure is: how to improve the security of smart contract execution and the fault tolerance of blockchain systems.

[0006] According to some embodiments of the present disclosure, a method for executing a smart contract in a blockchain is provided, comprising: each of a plurality of control nodes receives a contract call transaction request sent by a service node, the contract call transaction request comprising: an expected result of contract execution; sending the contract call transaction request to each non-control node, wherein the number of non-control nodes is less than a maximum allowed number of malicious nodes; receiving the result of the contract call transaction returned by each non-control node, and verifying whether the result of the contract call transaction returned by each non-control node matches the expected result of the contract execution; when the result of the contract call transaction returned by each non-control node matches the expected result of the contract execution, broadcasting the contract call transaction request to other nodes to execute the contract call transaction.

[0007] In some embodiments, sending a contract call transaction request to each non-control node includes: sending a contract call transaction request and a non-control node indication identifier to each non-control node, wherein the non-control node indication identifier is used to instruct each non-control node to execute a contract call transaction.

[0008] In some embodiments, receiving the results of the contract call transactions returned by each non-control node includes: receiving the results of the contract call transactions returned by each non-control node within a preset time.

[0009] In some embodiments, receiving a contract call transaction request sent by a service node includes: receiving a contract call transaction request sent by a service node, a control node indication identifier and identifiers of each control node; determining the identifiers of non-control nodes based on the identifiers of each control node; sending the contract call transaction request to each non-control node includes: sending the contract call transaction request to each non-control node based on the control node indication identifier and the identifier of the non-control node.

[0010] In some embodiments, the method further includes: discarding the contract call transaction request when the result of the contract call transaction returned by each non-control node does not match the expected result of the contract execution.

[0011] In some embodiments, the method also includes: the service node receives a transaction request initiated by a user; when the received transaction request includes a contract call transaction request, the service node uses the node as a control node and randomly selects a preset number of nodes as control nodes, wherein the preset number is greater than or equal to the maximum allowable number of malicious nodes; the service node sends the contract call transaction request to each control node.

[0012] In some embodiments, the method also includes: each of a plurality of non-control nodes receives a contract call transaction request sent by a control node; executes a contract call transaction according to the contract call transaction request, obtains a result of the contract call transaction and returns it to the control node; and stores the result of the contract call transaction.

[0013] In some embodiments, the method also includes: each of a plurality of non-control nodes, in response to receiving a contract call transaction request again, queries whether a result of a contract call transaction corresponding to the contract call transaction request is stored; if the result of the contract call transaction corresponding to the contract call transaction request has been stored, synchronously broadcasting the result of the contract call transaction.

[0014] In some embodiments, the method also includes: a node with the right to generate a block receives the results of the contract call transactions broadcast by each node, generates a block after completing the consensus verification of the results of the contract call transactions broadcast by each node, and synchronizes the block to other nodes, which are verified by other nodes and then written into the local ledger.

[0015] According to some other embodiments of the present disclosure, a node in a blockchain is provided, wherein, when the node is selected as a control node, the node comprises: a receiving module, used to receive a contract call transaction request sent by a service node, the contract call transaction request comprising: an expected result of contract execution; a sending module, used to send the contract call transaction request to each non-control node, wherein the number of non-control nodes is less than the maximum allowed number of malicious nodes; a verification module, used to receive the result of the contract call transaction returned by each non-control node, and to verify whether the result of the contract call transaction returned by each non-control node matches the expected result of the contract execution; and a broadcast module, used to broadcast the contract call transaction request to other nodes to execute the contract call transaction when the result of the contract call transaction returned by each non-control node matches the expected result of the contract execution.

[0016] In some embodiments, the sending module is used to send the contract call transaction request and the non-control node indication identifier to each non-control node, wherein the non-control node indication identifier is used to instruct each non-control node to execute the contract call transaction; or, the verification module is used to receive the result of the contract call transaction returned by each non-control node within a preset time; or, the receiving module is used to receive the contract call transaction request, the control node indication identifier and the identifier of each control node sent by the service node; determine the identifier of the non-control node according to the identifier of each control node; the sending module is used to send the contract call transaction request to each non-control node according to the control node indication identifier and the identifier of the non-control node; or, the broadcasting module is also used to discard the contract call transaction request when the result of the contract call transaction returned by each non-control node does not match the expected result of the contract execution.

[0017] In some embodiments, when the node acts as a service node, it also includes: a service module for receiving transaction requests initiated by users; when the received transaction requests include contract call transaction requests, the node is used as a control node, and a preset number of nodes are randomly selected as control nodes, where the preset number is greater than or equal to the maximum allowable number of malicious nodes; and the contract call transaction request is sent to each control node.

[0018] According to some further embodiments of the present disclosure, a blockchain system is provided, comprising: a node of any of the aforementioned embodiments, serving as a control node; and a plurality of non-control nodes; the non-control nodes are used to receive a contract call transaction request sent by the control node; execute a contract call transaction according to the contract call transaction request, obtain a result of the contract call transaction and return it to the control node; and store the result of the contract call transaction.

[0019] In some embodiments, the non-control node is used to query whether the result of the contract call transaction corresponding to the contract call transaction request is stored in response to receiving the contract call transaction request again; if the result of the contract call transaction corresponding to the contract call transaction request has been stored, the result of the contract call transaction is broadcast synchronously.

[0020] In some embodiments, when any node is a node with the right to generate blocks, it is used to receive the results of contract call transactions broadcast by each node, and after completing consensus verification on the results of contract call transactions broadcast by each node, it generates blocks and synchronizes the blocks to other nodes, which are verified by other nodes and then written into the local ledger.

[0021] According to some further embodiments of the present disclosure, an electronic device is provided, comprising: a processor; and a memory coupled to the processor, for storing instructions, wherein when the instructions are executed by the processor, the processor executes a method for executing a smart contract in a blockchain as in any of the aforementioned embodiments.

[0022] According to some further embodiments of the present disclosure, a non-transitory computer-readable storage medium is provided, on which a computer program is stored, wherein when the program is executed by a processor, the steps of the method for executing a smart contract in a blockchain of any of the aforementioned embodiments are implemented.

[0023] The nodes in the blockchain system disclosed in the present invention are divided into control nodes and non-control nodes, and the number of non-control nodes is less than the maximum allowable number of malicious nodes. The control node sends a contract call transaction request to each non-control node, and the non-control node first executes the contract call transaction. The control node verifies the result of the contract call transaction returned by the non-control node. If the verification passes, the contract call transaction request is broadcast to other nodes to execute the contract call transaction. Through the above process, it can be found whether there are errors or insecurities in the smart contract, and whether there are insecure factors in the node. And when the maximum allowable number of malicious nodes, that is, the number of malicious nodes is less than this number, it will not affect the operation and security of the blockchain system. Even if there are security risks in the non-control node or smart contract, it will not affect the performance of the entire blockchain system, thereby improving the security of smart contract execution and the fault tolerance of the blockchain system.

[0024] Other features and advantages of the present disclosure will become apparent from the following detailed description of exemplary embodiments of the present disclosure with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0025] In order to more clearly illustrate the embodiments of the present disclosure or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0026] Figure 1 A flowchart illustrating a method for executing a smart contract in a blockchain according to some embodiments of the present disclosure is shown.

[0027] Figure 2 A flowchart illustrating a method for executing a smart contract in a blockchain according to other embodiments of the present disclosure is shown.

[0028] Figure 3 A schematic diagram showing the structure of nodes in a blockchain according to some embodiments of the present disclosure.

[0029] Figure 4 A schematic diagram showing the structure of a blockchain system according to some embodiments of the present disclosure.

[0030] Figure 5 A schematic diagram showing the structure of an electronic device according to some embodiments of the present disclosure.

[0031] Figure 6 A schematic diagram showing the structure of an electronic device according to some other embodiments of the present disclosure. DETAILED DESCRIPTION

[0032] The technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only part of the embodiments of the present disclosure, rather than all of the embodiments. The following description of at least one exemplary embodiment is actually only illustrative and is by no means intended to limit the present disclosure and its application or use. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present disclosure.

[0033] This disclosure proposes a method for executing a smart contract in a blockchain. Figures 1-2 Give a description.

[0034] Figure 1 The following is a flowchart of some embodiments of the execution method of the smart contract in the blockchain disclosed in the present invention. Figure 1 As shown, the method of this embodiment includes: each of the multiple control nodes executes steps S102 to S108.

[0035] In step S102, a contract call transaction request sent by a service node is received.

[0036] Contract call transactions are transactions that require the execution of a specific contract. The control node can be randomly selected by the service node, and the service node itself can also be one of the control nodes. The number of control nodes excluding the service node is greater than or equal to the maximum number of allowed malicious nodes. The maximum number of allowed malicious nodes is determined according to the consensus algorithm. For example, the maximum number of allowed malicious nodes in the PoW (Proof of Work) consensus algorithm is 50% of the total number of nodes, etc., not limited to the examples given.

[0037] The contract call transaction request may include: the expected result of the contract execution. The expected result of the contract execution may be added by the user to the contract call transaction request and sent to the service node. The expected result of the contract execution may be a numerical value, a numerical range, True or False or other forms. The contract call transaction request may also include: the communication protocol version, the method in the contract to be called, the address of the caller, the input data required to execute the contract function, the contract address, etc., which can be referred to the existing technology and will not be repeated here.

[0038] In step S104, the contract call transaction request is sent to each non-control node.

[0039] The number of non-control nodes is less than the maximum number of allowed malicious nodes. In some embodiments, the control node receives the contract call transaction request, the control node indication identifier and the identifiers of each control node sent by the service node; determines the identifier of the non-control node according to the identifier of each control node, and sends the contract call transaction request to each non-control node according to the control node indication identifier and the identifier of the non-control node. The control node indication identifier is used to indicate that the node with the received identifier is a control node. For example, the control node indication identifier is represented as flag=ctrl. The control node can obtain the identifiers of all nodes in the entire network, and further based on the identifiers of each control node, the control node can be excluded from determining the identifiers of non-control nodes.

[0040] In some embodiments, the contract call transaction request and the non-control node indication identifier are sent to each non-control node. The node with the non-control node indication identifier is used to indicate the node receiving the identifier as a non-control node, and is used to instruct each non-control node to execute the contract call transaction. For example, the non-control node indication identifier is represented as flag=exec. The non-control node executes the contract call transaction according to the contract call transaction request and the non-control node indication identifier to obtain the result of the contract call transaction.

[0041] In step S106, the results of the contract call transactions returned by each non-control node are received, and it is verified whether the results of the contract call transactions returned by each non-control node match the expected results of the contract execution.

[0042] In some embodiments, the control node receives the results of the contract call transaction returned by each non-control node within a preset time. If the non-control node returns the result of the contract call transaction after the preset time, the control node may no longer consider the result of the contract call transaction. The control node compares the results of the contract call transaction returned by each non-control node with the expected results of the contract execution. If the results of the contract call transactions of each non-control node meet the expected results of the contract execution, the match is successful.

[0043] In step S108, when the result of the contract call transaction returned by each non-control node matches the expected result of the contract execution, the contract call transaction request is broadcast to other nodes to execute the contract call transaction.

[0044] After the control node verifies that the results of the contract call transactions returned by each non-control node match the expected results of the contract execution, it proves the security of the contract and also proves that each non-control node is not a malicious node.

[0045] In the above embodiment, the nodes in the blockchain system are divided into control nodes and non-control nodes, and the number of non-control nodes is less than the maximum allowable number of malicious nodes. The control node sends the contract call transaction request to each non-control node, and the non-control node first executes the contract call transaction. The control node verifies the result of the contract call transaction returned by the non-control node. If the verification passes, the contract call transaction request is broadcast to other nodes to execute the contract call transaction. Through the above process, it can be found whether there are errors or insecurities in the smart contract, and whether there are insecure factors in the node. And the maximum allowable number of malicious nodes, that is, the number of malicious nodes is less than this number, which will not affect the operation and security of the blockchain system. Even if there are security risks in the non-control node or smart contract, it will not affect the performance of the entire blockchain system, thereby improving the security of smart contract execution and the fault tolerance of the blockchain system.

[0046] Combine the following Figure 2 Other embodiments of the method for executing a smart contract in a blockchain of the present disclosure are described.

[0047] Figure 2 Flowcharts of other embodiments of the method for executing smart contracts in the blockchain disclosed in the present invention. Figure 2 As shown, the method of this embodiment includes: steps S202 to S222.

[0048] In step S202, the service node receives a transaction request initiated by a user.

[0049] For example, service node C1 receives a transaction request TX initiated by a user. Each service node collects the transaction request TX and aggregates them into a transaction request set {TX} iIf a user initiates a contract call transaction request, the expected result parameter {preresult} of the contract execution must be included.

[0050] In step S204, when the received transaction request includes a contract call transaction request, the service node uses the node as a control node and randomly selects a preset number of nodes as control nodes.

[0051] If {TX} i If the contract call transaction request TXq is included in the contract call transaction request TXq, the service node can use the random sampling algorithm to select M (the preset number is greater than or equal to the maximum allowed malicious node) nodes again as the control node {C} n ,n∈{1,2,3…M-1,M}.

[0052] In step S206, the service node sends the contract call transaction request to each control node, and correspondingly, the control node receives the contract call transaction request sent by the service node.

[0053] Service node C1 can send the contract call transaction request, control node indication flag = ctrl and the identifiers of each control node to the control node {C} n The service node continues to operate normally for other transactions.

[0054] In step S208, the control node sends the contract call transaction request to each non-control node, and correspondingly, each non-control node receives the contract call transaction request sent by the control node.

[0055] After receiving the contract call transaction and the control node indication flag = ctrl, the control node modifies the non-control node indication flag = exec from flag = ctrl and forwards it to the non-control node.

[0056] In step S210, the non-control node executes the contract call transaction according to the contract call transaction request, obtains the result of the contract call transaction and returns it to the control node, and stores the result of the contract call transaction.

[0057] Non-control nodes are contract pre-execution nodes {D} N-n After receiving it, the contract is pre-executed and the result is returned to the control node and cached.

[0058] In step S212, the control node receives the results of the contract call transactions returned by each non-control node within a preset time, and verifies whether the results of the contract call transactions returned by each non-control node match the expected results of the contract execution. If so, execute step S214, otherwise, execute step S213.

[0059] After receiving the result of the contract call transaction within the preset time, the control node verifies whether the result of the contract call transaction meets the preresult.

[0060] In step S213, the control node discards the contract call transaction request.

[0061] If the control node fails to verify, it discards the contract call transaction request and returns a failure to the service node.

[0062] In step S214, the control node broadcasts the contract call transaction request.

[0063] The other nodes can be all nodes or some nodes that receive the contract call transaction request.

[0064] In step S216, the node that receives the contract call transaction request queries whether the result of the contract call transaction corresponding to the contract call transaction request is stored. If so, step S218 is executed, otherwise step S217 is executed.

[0065] The node that receives the contract call transaction request TXq adds TXq to the transaction request set {TX} (i+k) If the node receiving the contract call transaction request includes a non-control node, then in response to receiving the contract call transaction request again, it queries whether the result of the contract call transaction corresponding to the contract call transaction request is stored; if the result of the contract call transaction corresponding to the contract call transaction request has been stored, the contract call transaction is no longer executed.

[0066] In step S217, the node that receives the contract call transaction request executes the contract call transaction and obtains the result of the contract call transaction.

[0067] In step S218, the node that receives the contract call transaction request synchronously broadcasts the result of the contract call transaction.

[0068] In step S220, the node with the right to generate blocks receives the results of the contract call transactions broadcast by each node, and after completing the consensus verification of the results of the contract call transactions broadcast by each node, generates a block and synchronizes the block to other nodes.

[0069] In step S222, each node verifies the block and writes it into the local ledger.

[0070] Each node can verify the hash value in the block, etc. For details, please refer to the existing technology first, and I will not go into details here.

[0071] The method of the above embodiment can detect whether there are errors or insecurities in the smart contract, and whether there are insecurities in the node. If the result of the contract call transaction does not meet the expected result, the contract call transaction is discarded, and it is not necessary for all nodes to execute the contract call transaction, which improves efficiency and improves the security of smart contract execution and the fault tolerance of the blockchain system.

[0072] The present disclosure also provides a node in a blockchain, Figure 3 Give a description.

[0073] Figure 3 Figure 1 is a structural diagram of some embodiments of nodes in the blockchain disclosed in the present invention. Figure 3 As shown, when the node 30 in the blockchain of this embodiment is selected as the control node, it includes: a receiving module 310, a sending module 320, a verification module 330, and a broadcasting module 340.

[0074] The receiving module 310 is used to receive a contract call transaction request sent by a service node, and the contract call transaction request includes: the expected result of the contract execution.

[0075] The sending module 320 is used to send the contract call transaction request to each non-control node, wherein the number of non-control nodes is less than the maximum allowed number of malicious nodes.

[0076] In some embodiments, the receiving module 310 is used to receive a contract call transaction request, a control node indication identifier and identifiers of each control node sent by a service node; determine the identifier of a non-control node based on the identifier of each control node; and the sending module 320 is used to send the contract call transaction request to each non-control node based on the control node indication identifier and the identifier of the non-control node.

[0077] In some embodiments, the sending module 320 is used to send the contract call transaction request and the non-control node indication identifier to each non-control node, wherein the non-control node indication identifier is used to instruct each non-control node to execute the contract call transaction.

[0078] The verification module 330 is used to receive the results of the contract call transactions returned by each non-control node, and to verify whether the results of the contract call transactions returned by each non-control node match the expected results of the contract execution.

[0079] In some embodiments, the verification module 330 is used to receive the results of the contract call transaction returned by each non-control node within a preset time.

[0080] The broadcast module 340 is used to broadcast the contract call transaction request to other nodes to execute the contract call transaction when the result of the contract call transaction returned by each non-control node matches the expected result of the contract execution.

[0081] In some embodiments, the broadcast module 340 is also used to discard the contract call transaction request when the result of the contract call transaction returned by each non-control node does not match the expected result of the contract execution.

[0082] In some embodiments, when the node acts as a service node, it also includes: a service module 350, which is used to receive transaction requests initiated by users; when the received transaction requests include contract call transaction requests, the node is used as a control node, and a preset number of nodes are randomly selected as control nodes, where the preset number is greater than or equal to the maximum allowable number of malicious nodes; and the contract call transaction request is sent to each control node.

[0083] The present disclosure also provides a blockchain system, Figure 4 Give a description.

[0084] Figure 4 Figure 1 is a structural diagram of some embodiments of the blockchain system disclosed in the present invention. Figure 4 As shown, the blockchain system 4 of this embodiment includes: a node 30 in the blockchain of any of the aforementioned embodiments, serving as a control node 30, and a plurality of non-control nodes 42;

[0085] The non-control node 42 is used to receive the contract call transaction request sent by the control node 30; execute the contract call transaction according to the contract call transaction request, obtain the result of the contract call transaction and return it to the control node 30; and store the result of the contract call transaction.

[0086] In some embodiments, the non-control node 42 is used to query whether the result of the contract call transaction corresponding to the contract call transaction request is stored in response to receiving the contract call transaction request again; if the result of the contract call transaction corresponding to the contract call transaction request has been stored, the result of the contract call transaction is broadcast synchronously.

[0087] In some embodiments, when any node is a node with the right to generate blocks, it is used to receive the results of contract call transactions broadcast by each node, and after completing consensus verification on the results of contract call transactions broadcast by each node, it generates blocks and synchronizes the blocks to other nodes, which are verified by other nodes and then written into the local ledger.

[0088] The electronic devices in the embodiments of the present disclosure, such as control nodes and non-control nodes in the blockchain, can be implemented by various computing devices or computer systems. Figure 5 as well as Figure 6 Give a description.

[0089] Figure 5FIG. 1 is a structural diagram of some embodiments of the electronic device disclosed in the present invention. Figure 5 As shown, the electronic device 50 of this embodiment includes: a memory 510 and a processor 520 coupled to the memory 510, and the processor 520 is configured to execute the steps of the method for executing a smart contract in a blockchain in any of some embodiments of the present disclosure based on the instructions stored in the memory 510.

[0090] The memory 510 may include, for example, a system memory, a fixed non-volatile storage medium, etc. The system memory may store, for example, an operating system, an application program, a boot loader, a database, and other programs.

[0091] Figure 6 FIG. 2 is a structural diagram of some other embodiments of the electronic device disclosed in the present invention. Figure 6 As shown, the electronic device 60 of this embodiment includes: a memory 610 and a processor 620, which are similar to the memory 510 and the processor 520 respectively. It can also include an input and output interface 630, a network interface 640, a storage interface 650, etc. These interfaces 630, 640, 650 and the memory 610 and the processor 620 can be connected, for example, through a bus 660. Among them, the input and output interface 630 provides a connection interface for input and output devices such as a display, a mouse, a keyboard, and a touch screen. The network interface 640 provides a connection interface for various networked devices, for example, it can be connected to a database server or a cloud storage server. The storage interface 650 provides a connection interface for external storage devices such as SD cards and USB flash drives.

[0092] Those skilled in the art will appreciate that the embodiments of the present disclosure may be provided as methods, systems, or computer program products. Therefore, the present disclosure may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present disclosure may take the form of a computer program product implemented on one or more computer-usable non-transient storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0093] The present disclosure is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present disclosure. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0094] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0095] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0096] The above description is only a preferred embodiment of the present disclosure and is not intended to limit the present disclosure. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present disclosure should be included in the protection scope of the present disclosure.

Claims

1. A method for executing a smart contract in a blockchain, comprising: Each of the plurality of control nodes, Receiving a contract call transaction request, a control node indication identifier, and identifiers of each control node sent by a service node, wherein the control node indication identifier is used to indicate that the node receiving the identifier is used as a control node, and the contract call transaction request includes: an expected result of contract execution; Determine the identifiers of non-control nodes according to the identifiers of each control node, wherein the number of the non-control nodes is less than the maximum allowed number of malicious nodes; According to the control node indication identifier and the identifier of the non-control node, the contract call transaction request and the non-control node indication identifier are sent to each non-control node, wherein the non-control node indication identifier is used to instruct each non-control node to execute the contract call transaction; Receive the results of the contract call transactions returned by each non-control node, and verify whether the results of the contract call transactions returned by each non-control node match the expected results of the contract execution; When the result of the contract call transaction returned by each non-control node matches the expected result of the contract execution, the contract call transaction request is broadcast to other nodes to execute the contract call transaction.

2. The execution method according to claim 1, wherein: The result of receiving the contract call transaction returned by each non-control node includes: Receive the results of the contract call transaction returned by each non-control node within the preset time.

3. The execution method according to claim 1, further comprising: In the event that the result of the contract call transaction returned by each non-control node does not match the expected result of the contract execution, the contract call transaction request will be discarded.

4. The execution method according to claim 1, further comprising: The service node receives the transaction request initiated by the user; When the received transaction request includes a contract call transaction request, the service node uses the node as a control node and randomly selects a preset number of nodes as control nodes, where the preset number is greater than or equal to the maximum number of allowed malicious nodes; The service node sends the contract call transaction request to each control node.

5. The execution method according to claim 1, further comprising: Each of the plurality of non-control nodes, Receiving the contract call transaction request sent by the control node; Execute the contract call transaction according to the contract call transaction request, obtain the result of the contract call transaction and return it to the control node; The result of the contract call transaction is stored.

6. The execution method according to claim 5, further comprising: Each of the plurality of non-control nodes, In response to receiving the contract call transaction request again, querying whether a result of the contract call transaction corresponding to the contract call transaction request is stored; When the result of the contract call transaction corresponding to the contract call transaction request has been stored, the result of the contract call transaction is synchronously broadcast.

7. The execution method according to claim 6, further comprising: The node with the right to generate blocks receives the results of the contract call transactions broadcast by each node, and after completing the consensus verification of the results of the contract call transactions broadcast by each node, generates a block and synchronizes the block to other nodes, which are then verified by other nodes and written into the local ledger.

8. A node in a blockchain, wherein: In the case where the node is selected as a control node, the method includes: A receiving module, configured to receive a contract call transaction request, a control node indication identifier, and identifiers of each control node sent by a service node, and determine the identifier of a non-control node according to the identifiers of each control node, wherein the control node indication identifier is used to indicate that the node with the received identifier is used as a control node, and the contract call transaction request includes: an expected result of contract execution; A sending module, configured to send the contract call transaction request and the non-control node indication identifier to each non-control node according to the control node indication identifier and the non-control node identifier, wherein the number of the non-control nodes is less than the maximum allowed number of malicious nodes, and the non-control node indication identifier is used to instruct each non-control node to execute the contract call transaction; A verification module, used to receive the results of the contract call transactions returned by each non-control node, and verify whether the results of the contract call transactions returned by each non-control node match the expected results of the contract execution; The broadcast module is used to broadcast the contract call transaction request to other nodes to execute the contract call transaction when the result of the contract call transaction returned by each non-control node matches the expected result of the contract execution.

9. A node in a blockchain according to claim 8, wherein: The verification module is used to receive the results of the contract call transaction returned by each non-control node within a preset time; Alternatively, the broadcast module is also used to discard the contract call transaction request when the result of the contract call transaction returned by each non-control node does not match the expected result of the contract execution.

10. The node in the blockchain according to claim 8, wherein: In the case where the node serves as a service node, the method further includes: The service module is used to receive transaction requests initiated by users; when the received transaction requests include contract call transaction requests, the node is used as a control node, and a preset number of nodes are randomly selected as control nodes, wherein the preset number is greater than or equal to the maximum allowed number of malicious nodes; and the contract call transaction request is sent to each control node.

11. A blockchain system, comprising: A plurality of nodes according to any one of claims 8 to 9, as control nodes; and multiple non-control nodes; The non-control node is used to receive the contract call transaction request sent by the control node; execute the contract call transaction according to the contract call transaction request, obtain the result of the contract call transaction and return it to the control node; The result of the contract call transaction is stored.

12. The blockchain system according to claim 11, wherein: The non-control node is used to query whether the result of the contract call transaction corresponding to the contract call transaction request is stored in response to receiving the contract call transaction request again; if the result of the contract call transaction corresponding to the contract call transaction request has been stored, the result of the contract call transaction is synchronously broadcast.

13. The blockchain system according to claim 11, wherein: When any node is a node with the right to generate blocks, it is used to receive the results of the contract call transactions broadcast by each node, and after completing the consensus verification of the results of the contract call transactions broadcast by each node, it generates a block and synchronizes the block to other nodes, which are then verified by other nodes and written into the local ledger.

14. An electronic device comprising: processor; as well as A memory coupled to the processor, for storing instructions, wherein when the instructions are executed by the processor, the processor executes the method for executing a smart contract in a blockchain as described in any one of claims 1 to 7.

15. A non-transitory computer-readable storage medium having a computer program stored thereon, wherein: When the program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Block chain implementation method and system and storage medium

    CN110233823A