WO2019001139A1 - 运行智能合约的方法和装置 - Google Patents

运行智能合约的方法和装置 Download PDF

Info

Publication number
WO2019001139A1
WO2019001139A1 PCT/CN2018/085748 CN2018085748W WO2019001139A1 WO 2019001139 A1 WO2019001139 A1 WO 2019001139A1 CN 2018085748 W CN2018085748 W CN 2018085748W WO 2019001139 A1 WO2019001139 A1 WO 2019001139A1
Authority
WO
WIPO (PCT)
Prior art keywords
smart contract
running
endorsement
node
client
Prior art date
Application number
PCT/CN2018/085748
Other languages
English (en)
French (fr)
Inventor
姜耀国
蒋飞虎
谢军安
胡瑞丰
丁海洋
Original Assignee
华为技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Priority to EP18824895.9A priority Critical patent/EP3629272B1/en
Publication of WO2019001139A1 publication Critical patent/WO2019001139A1/zh
Priority to US16/727,633 priority patent/US20200134613A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/60Protecting data
    • G06F21/64Protecting data integrity, e.g. using checksums, certificates or signatures
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q20/00Payment architectures, schemes or protocols
    • G06Q20/38Payment protocols; Details thereof
    • G06Q20/389Keeping log of transactions for guaranteeing non-repudiation of a transaction
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q20/00Payment architectures, schemes or protocols
    • G06Q20/38Payment protocols; Details thereof
    • G06Q20/382Payment protocols; Details thereof insuring higher security of transaction
    • G06Q20/3825Use of electronic signatures
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/18File system types
    • G06F16/1805Append-only file systems, e.g. using logs or journals to store data
    • G06F16/1815Journaling file systems
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/18File system types
    • G06F16/182Distributed file systems
    • G06F16/1824Distributed file systems implemented using Network-attached Storage [NAS] architecture
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/18File system types
    • G06F16/182Distributed file systems
    • G06F16/1834Distributed file systems implemented based on peer-to-peer networks, e.g. gnutella

Definitions

  • the embodiments of the present application relate to the field of information technology, and in particular, to a method and apparatus for running a smart contract in the field of information technology.
  • the blockchain is a distributed book, a decentralized database that requires all nodes in the blockchain network to be collectively maintained. These nodes, which are capable of processing the ledger data, are treated nodes. It contains multiple blocks, each block consists of several transaction records, and contains the hash value of the previous block, so that all the blocks are connected in sequence to form a blockchain.
  • Chaincode is an important concept in blockchain technology.
  • An intelligent contract is an event-driven, stateful program that runs on a replicated, shared ledger and manages the data on the ledger.
  • the smart contract looks like a normal computer execution program.
  • the code content of the smart contract specifies the rules and logic of the transaction.
  • the user signing the smart contract means that the contract content will be executed and the result of the execution will be written into the book. .
  • the processing nodes in the blockchain network do not trust each other, there may be malicious lying nodes, and the consensus algorithm can solve the problem well. This problem. Although each processing node in a blockchain network may be a malicious lying node, but many nodes are clustered into one network, the result of their consensus is a credible result.
  • the main role of the consensus algorithm is to have all processing nodes in the blockchain network record the same valid transaction block content.
  • PoE proof of endorse
  • the endorsement node also belongs to the processing node, which is a part of the processing node with endorsement function.
  • the plurality of endorsement nodes run the smart contract, sign the running result and return it to the client (referred to herein as "endorsement"), and the client then puts the plurality of endorsement nodes according to the blockchain message format.
  • the running results are encapsulated into transaction messages, sent to the consensus service node, and broadcasted to all processing nodes (including the above-mentioned plurality of endorsement nodes) in the blockchain network by the consensus service node in units of blocks, the block
  • the processing node in the chain network verifies the received transaction, and the transaction that satisfies the verification strategy is considered to be a valid transaction, and then the data is modified, and the updated data is written into the blockchain.
  • the user can set a plurality of endorsement nodes to be trusted by the smart contract according to the actual needs of the client, and set the verification policy for the plurality of endorsement nodes.
  • the endorsement node of the user A can be three
  • the user A's Client A sends a request to simulate the running of the smart contract to the three endorsement nodes, and receives the corresponding three running results.
  • the verification strategy may be that the content of the three running results must be consistent, or may be the content of at least two running results. Consistent.
  • the entire blockchain network is distributed, and each processing node in the blockchain network maintains a complete book data of the blockchain.
  • the data synchronization has a sequence
  • the blockchain data accessed by the endorsement node when running the smart contract of a transaction is written to the local ledger on each processing node in the blockchain network.
  • the data at the time is likely to be inconsistent, making the endorsement of the endorsement node invalid. Therefore, some mechanism is needed to prevent the endorsement transaction from being written into the ledger.
  • the prior art sets an auto-increment version number for each data of the smart contract, and the version number is modified once each time the data is updated (for example, the version number plus one).
  • the endorsement node runs the smart contract, if it needs to access the data stored in the blockchain by the smart contract, it records the version number of the data that needs to be accessed. The version number of the data contained in the running result returned by the endorsement node to the client.
  • all the processing nodes in the blockchain network perform verification, it is necessary to verify whether the version number of the data in the transaction is consistent with the version number of the local ledger data, and in the case of consistency, confirm that the transaction is a valid transaction, local to The book data is updated.
  • the data version number in the local ledger of the endorsement node when the smart contract is run, and the transaction are broadcasted to the blockchain through the consensus service node.
  • the data version numbers of the processing nodes are likely to be inconsistent, resulting in invalidation of the transaction.
  • the client has to re-initiate the transaction until the transaction is legally written to the ledger after the data version number is consistent. Therefore, the success rate of existing method transactions written into the ledger is low.
  • the method and apparatus for running a smart contract provided by the embodiment of the present application are beneficial to improving the success rate of writing a transaction into a ledger, thereby facilitating improvement of the overall performance of the system.
  • a method for operating a smart contract for use in a distributed network, the method comprising: a processing node in the distributed network receiving a transaction sent by a consensus service node, the transaction being included in a smart contract a plurality of operational results generated during the endorsement process; the processing node checking whether the plurality of operational results satisfy a verification policy, the checking comprising, among the plurality of operational results, by a qualification condition other than the smart contract Checking of data and version numbers generated by other programs, the qualifications being used to indicate conditions that the ledger data in the distributed network needs to meet when running the smart contract; the verification is satisfied in the plurality of operational results
  • the processing node identifies a qualification condition in the smart contract, determines whether the local book data satisfies the qualification condition; and if the local book data satisfies the qualification condition, the processing node accepts The transaction.
  • the code that defines the condition is generally a code that needs to satisfy a certain condition corresponding to the data that is modified frequently in the smart contract, and the multiple running results received by the processing node can be divided into two cases:
  • the plurality of running results are the result of running all the programs of the smart contract, that is, the plurality of running results include data and version numbers generated by the program running the qualification condition of the smart contract, In the case that the processing node can ignore the data and version number associated with the qualification condition among the plurality of operation results, and only check data and version numbers generated by programs other than the qualification condition;
  • the plurality of operation results are data and version numbers generated by running other programs than the above-defined conditions, in which case the processing node can directly check the plurality of operation results.
  • the processing node needs to check only the data generated by the program other than the qualification condition when performing the inspection. version number.
  • the processing node in the distributed network verifies the multiple running results of the transaction according to the verification policy, the verification of the qualified condition corresponding to the data with more frequent changes is ignored, and the limited conditions are included in the multiple running results.
  • the external data and version number satisfy the verification policy, it is verified whether the local ledger data satisfies the qualification condition, and the local account book data is accepted if the local account book data meets the qualification condition.
  • the method for running a smart contract in the embodiment of the present application after verifying the qualification condition corresponding to the data with more frequent changes, after the data and the version number other than the limited condition satisfy the verification policy in the multiple running results of the transaction Then, verifying whether the local ledger data meets the qualification condition is beneficial to improving the success rate of writing the transaction into the ledger, thereby contributing to improving the overall performance of the system.
  • the processing node is an endorsement node
  • the method further includes: the processing node pairing the smart The contract is endorsed to obtain the running result of the endorsement; the processing node sends the running result of the endorsement to the client or the client node of the client that needs to use the running result of the endorsement in the transaction. .
  • the processing node endorses the smart contract, and obtains an operation result of the endorsement, including: the processing The node receives a request sent by the client or the proxy node of the client to simulate running the smart contract, the request includes identification information of the smart contract; and the processing node identifies the identifier according to the identification information of the smart contract The qualifying condition in the smart contract; the processing node runs a program other than the defined condition in the smart contract based on the local ledger data and performs a signature to obtain an operation result of the endorsement.
  • the processing node may identify a qualification condition of the smart contract, and run a program other than the limited condition in the smart contract based on the local account book data of the processing node and perform a signature to obtain an operation result of the endorsement; It should be understood that the processing node may run all the programs in the smart contract, or may only run other programs in the smart contract except the qualified condition, which is not limited by the embodiment of the present application.
  • the method further includes: receiving, by the processing node, a program of the smart contract sent by the client or a proxy node of the client; the processing node parsing a program of the smart contract, obtaining a program for defining the condition; The processing node sends the defined procedure to the client or the proxy node of the client.
  • the client or the proxy node of the client may send a program of the smart contract to the endorsement node; the endorsement node receives the program of the smart contract, and the program of the smart contract Parsing and sending the code of the qualification condition of the smart contract to the client or the proxy node; the client or the proxy node receives the code of the qualification condition, and sends the code of the qualification condition of the smart contract to the All processing nodes in a distributed network. It should be understood that it is a prior art to record a piece of code into all processing nodes through a transaction, and therefore will not be described in detail herein.
  • the processing node is a proxy node, and before the processing node receives the transaction sent by the consensus service node, the method is The method further includes: the processing node transmitting, to a plurality of endorsement nodes in the distributed network, a request to simulate running the smart contract, the request including identification information of the smart contract; and the processing node receiving the plurality of a respective operation result sent by the endorsement node according to the request; the processing node checks whether the received plurality of operation results satisfy the verification policy, and the checking includes: deleting the plurality of operation results Checking data and version numbers generated by other programs than the defined conditions; in a case where the plurality of running results satisfy the verification policy, the processing node transmits the plurality of running results to the client.
  • the processing node may first determine whether the number of valid running results of the two running results exceeds a preset value (ie, verify the validity of the running result), and then pass the legality verification.
  • a preset value ie, verify the validity of the running result
  • the processing node may first determine whether the number of valid running results of the two running results exceeds a preset value (ie, verify the validity of the running result), and then pass the legality verification.
  • the running result it is determined whether the number of running results with the same data and version number exceeds the preset value (that is, the consistency of the remaining running results is verified).
  • the processing node may detect whether the signature of the running result is legal every time a running result is received, and if the signature of the running result is legal, record the data and version number of the running result. If the signature verification is illegal, it will not be recorded. When the number of running results of the same data and the version number exceeds the preset value in the legal result of the signature received by the processing node, the processing node determines that the running result satisfies the verification policy.
  • the processing node sends, to the multiple endorsement nodes in the distributed network, a simulated operation of the smart contract Before the request, the method further includes: the processing node transmitting the program of the smart contract to the plurality of endorsement nodes; the processing node receiving the sending by the plurality of endorsement nodes according to a program of the smart contract a qualifying program; the processing node transmitting the defined condition program to all processing nodes in the distributed network.
  • the qualification condition of the smart contract is that the endorsement node pre-resolves according to the code of the smart contract, and the endorsement node sends the code of the qualified condition to the client or the proxy node, and then the qualified node or the client The code is recorded through transactions to all processing nodes in the distributed network.
  • a method for running a smart contract comprising: a client sending a request to simulate a running smart contract to a plurality of endorsement nodes in a distributed network, the request including identification information of the smart contract; The client receives a respective running result sent by the multiple endorsement nodes according to the request; the client checks whether the received multiple running results meet the verification policy, and the checking includes the plurality of running results A check of data and a version number generated by a program other than the qualification condition of the smart contract, the qualification condition being used to indicate a condition that the book data in the distributed network needs to be satisfied when the smart contract is run; In a case that the plurality of running results satisfy the verification policy, the client sends a transaction including the plurality of running results to the consensus service node.
  • the method before the client sends a request for simulating running a smart contract to multiple endorsement nodes in the distributed network, the method further includes: the client Transmitting, by the plurality of endorsement nodes, a program for transmitting the smart contract; the client receiving a program of the qualification condition that is sent by the plurality of endorsement nodes according to a program of the smart contract; the client is to the distributed network All of the processing nodes in the program send the program of the qualification.
  • an apparatus for operating a smart contract for performing the method of any of the first aspect or the first aspect of the first aspect.
  • the apparatus comprises means for performing the method of any of the above-described first aspect or any of the possible implementations of the first aspect.
  • the apparatus comprises means for performing the method of any of the above-described second aspect or any of the possible implementations of the second aspect.
  • an apparatus for operating a smart contract comprising: a transceiver, a memory, and a processor.
  • the transceiver, the memory and the processor are in communication with each other via an internal connection path for storing instructions for executing instructions stored in the memory to control the receiver to receive signals and to control the transmitter to transmit signals
  • the processor executes the instructions stored by the memory the executing causes the processor to perform the method of the first aspect or any of the possible implementations of the first aspect.
  • an apparatus for operating a smart contract comprising: a transceiver, a memory, and a processor.
  • the transceiver, the memory and the processor are in communication with each other via an internal connection path for storing instructions for executing instructions stored in the memory to control the receiver to receive signals and to control the transmitter to transmit signals
  • the processor executes the instructions stored by the memory the executing causes the processor to perform the method of any of the possible implementations of the second aspect or the second aspect.
  • a seventh aspect a computer readable medium for storing a computer program, the computer program comprising instructions for performing the method of the first aspect or any of the possible implementations of the first aspect.
  • a computer readable medium for storing a computer program comprising instructions for performing the method of the second aspect or any of the possible implementations of the second aspect.
  • FIG. 1 shows a schematic diagram of a network architecture of an embodiment of the present application.
  • FIG. 2 shows a schematic flow chart of a method of running a smart contract according to an embodiment of the present application.
  • FIG. 3 shows a schematic flow chart of another method of running a smart contract according to an embodiment of the present application.
  • FIG. 4 shows a schematic flow chart of another method of running a smart contract according to an embodiment of the present application.
  • FIG. 5 shows a schematic block diagram of an apparatus for operating a smart contract in accordance with an embodiment of the present application.
  • FIG. 6 shows a schematic block diagram of another apparatus for operating a smart contract in accordance with an embodiment of the present application.
  • FIG. 7 shows a schematic block diagram of another apparatus for operating a smart contract in accordance with an embodiment of the present application.
  • FIG. 8 shows a schematic block diagram of another apparatus for operating a smart contract in accordance with an embodiment of the present application.
  • Blockchain technology The blockchain is first of all a distributed system. Based on the principle of cryptography, it can reach a direct payment between the two parties without the participation of third-party intermediaries.
  • a blockchain is a distributed ledger, a decentralized database that requires all processing nodes in a blockchain network to be collectively maintained. It contains multiple blocks, each block consists of several transaction records, and contains the hash value of the previous block, so that all the blocks are connected in sequence to form a blockchain.
  • Smart Contracts are event-driven, stateful programs that run on a replicated, shared ledger and can manage data on the ledger.
  • the smart contract looks like a normal computer executive.
  • the code content specifies the rules and logic of the transaction.
  • the user signing the smart contract means that the contract content will be executed and the result of the execution will be written into the ledger.
  • the client will issue a transaction calling the BuyOneAsset smart contract function.
  • the smart contract will read the balance of the purchaser's funds and the remaining amount of the owner's assets from the data stored in the blockchain. After the trading conditions, the transaction is executed, and the purchaser's fund balance and the owner's remaining assets are modified. After the transaction is written into the account, the user's purchase of the asset is successful.
  • the consensus algorithm solves the process of agreeing on multiple proposals for multiple nodes. Since the blockchain is a decentralized, de-trusted distributed ledger, the processing nodes in the blockchain network do not trust each other, there may be malicious lying nodes, and the consensus algorithm can solve the problem well. This problem. Although each processing node in the blockchain network may be a malicious lying node, but many processing nodes are clustered into one network, the result of their consensus is a credible result.
  • the main role of the consensus algorithm is to have all processing nodes in the blockchain network record the same valid transaction block content. Commonly used consensus algorithms include practical byzantine fault tolerance (PBFT) algorithm, proof of work (PoW) algorithm, POE (proof of endorse) algorithm and so on.
  • PBFT practical byzantine fault tolerance
  • PoW proof of work
  • POE proof of endorse
  • the client may first send a request for simulating running a smart contract to a plurality of endorsement nodes, simulating running the smart contract, and the plurality of endorsement nodes running the smart contract, for the self.
  • the running result is signed and returned to the client (referred to herein as "endorsement"), and the client then encapsulates the multiple running results of the multiple endorsement nodes into the transaction message according to the blockchain message format, and sends the result to the consensus service.
  • the node broadcasts to the processing nodes (including the plurality of endorsement nodes) in the blockchain network by the consensus service node in units of blocks, and the processing nodes in the blockchain network perform the check on the received transactions.
  • the transaction that satisfies the verification strategy will be considered as a valid transaction, and then the data will be modified to write the updated data to the blockchain.
  • the user can set a plurality of endorsement nodes to be trusted by the smart contract according to the actual needs of the client, and set the verification policy for the plurality of endorsement nodes.
  • the endorsement node of the user A can be three
  • the user A's Client A sends a request to simulate the running of the smart contract to the three endorsement nodes, and receives the corresponding three running results.
  • the verification strategy may be that the content of the three running results must be consistent, or may be the content of at least two running results. Consistent. It should be understood that the user's authentication policy needs to be broadcast in advance to all processing nodes in the blockchain network.
  • the entire blockchain network is distributed, and each processing node in the blockchain network maintains a complete book data of the blockchain.
  • the data synchronization has a sequence
  • the blockchain data accessed by the endorsement node when running the smart contract of a transaction is written to the local ledger on each processing node in the blockchain network.
  • the data at the time is likely to be inconsistent, making the endorsement of the endorsement node invalid. Therefore, some mechanism is needed to prevent the endorsement transaction from being written into the ledger.
  • the prior art sets an auto-increment version number for each data of the smart contract, and the version number is modified each time the data is updated (for example, the version number plus one).
  • the endorsement node runs the smart contract, if it needs to access the data stored in the blockchain by the smart contract, it records the version number of the data that needs to be accessed.
  • the version number of the data contained in the running result returned by the endorsement node to the client.
  • the transaction message broadcast by the client through the consensus service node also contains the version number of the corresponding data.
  • all the processing nodes in the blockchain network verify the transaction, it is necessary to verify whether the version number of the data in the transaction is The version number of the local ledger data is the same. If the transaction is confirmed as a valid transaction, the local ledger data is updated.
  • the embodiment of the present application proposes a new method for running a smart contract.
  • FIG. 1 shows a network architecture 100 of an embodiment of the present application.
  • the network architecture 100 includes a client and a network side, and the network side is a distributed network.
  • the distributed network is a peer-to-peer (P2P) network composed of multiple nodes, and the network is distributed. Nodes with different terminals in different locations are connected to each other. Any node in the network is connected to at least two lines. When any one line fails, communication can be completed through other links, which has high reliability and is easy to expand.
  • the above-mentioned client can communicate with the network side through nodes in the distributed network, thereby realizing corresponding business requirements.
  • P2P peer-to-peer
  • nodes In the process of the communication between the client and the network, different nodes can be assigned different roles according to the functions of the node.
  • the client and the network side node involved in the embodiment of the present application are first introduced.
  • the client can send a request to simulate the running of the smart contract to the user's endorsement node according to the user's needs, receive the running result sent by the endorsement node, and verify the running result.
  • Processing node The basic node in the distributed network, which stores a complete account book data of the blockchain and manages the locally stored book data. It should be understood that a piece of ledger data typically requires multiple processing nodes to perform maintenance together. Specifically, the processing node may receive the transaction set broadcast by the consensus service node, verify the legality of the transaction, and modify the local accounting data under the premise that the transaction is legal.
  • Proxy node a processing node with proxy function.
  • the proxy node can send a request to the endorsement node to simulate running the smart contract, and the proxy client receives the running result sent by the endorsement node, and verifies the running result.
  • the running result is verified, the running result that satisfies the verification policy is sent to the client.
  • Endorsement node A processing node with endorsement function.
  • the endorsement node is generally a node operated by some credible institutions (for example, government, banks, large companies, etc.).
  • the endorsement node can receive a request sent by the client or the proxy node to simulate running the smart contract, run the smart contract, and “endend” the running result of the smart contract, and then return the running result of the smart contract to the client or the agent. node.
  • the “endorsement” means that the endorsement node signs the content of the running result of its own smart contract to ensure the legality of the running result.
  • Consensus service node a consensus service for performing block, the main function is to receive the transaction sent by the client or the proxy node, and determine the set of transactions that should be included in a certain block according to certain rules (not for the transaction) Legitimacy is verified) and the order of multiple transactions in the transaction set is determined, and then the transaction set is broadcast to all nodes (including endorsement nodes) in the distributed network.
  • the consensus service node may be a node or a cluster composed of multiple nodes.
  • FIG. 1 exemplarily shows two clients and nodes in a distributed network, including: client 110, client 120, processing node 130 - processing node 180, and consensus service node 190.
  • the distributed network may be a blockchain network, but the embodiment of the present application does not limit this.
  • processing node 130 the processing node 140, and the processing node 150 are endorsed nodes
  • processing node 160 is a proxy node of the client 120 as an example.
  • the nodes that the user uses as their own endorsement node may be preset by the user through the client.
  • the endorsement node of the client 110 is the processing node 130 and the processing node 140
  • the endorsement node of the client 120 is the processing node 130.
  • the processing node 150 is not limited in this embodiment of the present application.
  • the processing node 160 is a proxy node of the client 120, and the client 110 does not have a proxy node. The embodiment does not limit this.
  • FIG. 1 exemplarily shows two clients and a part processing node.
  • the network architecture 100 may include other numbers of clients and other numbers of processing nodes. Make a limit.
  • the programs of the various processing nodes in the network architecture 100 described above are basically the same, and are divided into different kinds of nodes only because of different roles at runtime.
  • the processing node in the network architecture 100 can be used to enable or disable the corresponding module according to the role, which is not limited in this embodiment of the present application.
  • the client may first send a request to simulate a running smart contract to a plurality of endorsement nodes, simulate running the smart contract, and the plurality of endorsement nodes run the smart contract, and endorse the result of the operation and return
  • the client encapsulates the multiple running results of the multiple endorsement nodes into the transaction message according to the blockchain message format, and sends the result to the consensus service node, and broadcasts the block to the consensus service node in units of blocks. All processing nodes in the distributed network, the processing nodes in the distributed network check the received transactions, and the transactions satisfying the verification strategy are considered to be valid transactions, and then the data is modified, and the updated data will be updated. Data is written to the blockchain.
  • the client has to re-initiate the transaction until the transaction is legally written to the ledger after the data version number is consistent.
  • qualification part of the code logic commonly used in smart contracts (herein referred to as qualification) needs to read the data stored in the blockchain, and then based on the data and the part of the code logic of the smart contract for conditional judgment. These data are generally preconditions for determining that a smart contract can execute normally. If these data changes more frequently, invalid transactions or retry will often occur. Therefore, the main idea of the present application is to provide a mechanism for arbitrarily modifying data in a blockchain (ie, data corresponding to a qualification condition), so that multiple endorsement nodes ignore this part of the data when running the blockchain, thereby It is easier to agree on multiple running results.
  • the processing node in the network verifies the transaction and finally writes the transaction to the ledger, it checks the data according to the local ledger data of the processing node. If the transaction is satisfied, It is still acceptable to modify the data of the transaction, that is, to set the judgment logic of the qualification condition, thereby improving the write success rate of the transaction when the data changes frequently, and improving the overall performance of the system.
  • FIG. 2 shows a schematic flow chart 200 of a method of running a smart contract in an embodiment of the present application.
  • the method 200 can be applied to the network architecture 100 shown in FIG. 1, but the embodiment of the present application is not limited thereto.
  • running a smart contract generally includes an endorsement phase and a transaction phase.
  • S201-S206 is an endorsement stage, including:
  • the client 110 sends a request for simulating running a smart contract to a plurality of processing nodes (endorsed nodes), where the request includes identification information of the smart contract; and correspondingly, the plurality of processing nodes (endorsed nodes) respectively receive the request;
  • the client 110 has only two endorsement nodes (the processing node 130 and the processing node 140) as an example.
  • S201 may include S201a and S201b, S201a and S201b. This may be performed separately or in the same manner, which is not limited by the embodiment of the present application.
  • the processing node 130 runs the smart contract according to the request, and endorses the running result, and obtains the running result of the endorsement;
  • the processing node 130 may identify the qualification condition of the smart contract, and run a program other than the limited condition in the smart contract based on the local ledger data of the processing node 130 and perform signature to obtain the operation of the endorsement. As a result, it should be understood that the processing node 130 may run all the programs in the smart contract, or may only run other programs in the smart contract except the qualified condition, which is not limited by the embodiment of the present application.
  • the processing node 140 runs the smart contract according to the request, and endorses the running result, and obtains the running result of the endorsement;
  • the processing node 140 may identify the qualification condition of the smart contract, and run a program other than the qualified condition in the smart contract based on the local ledger data of the processing node 140 and perform signature to obtain the operation of the endorsement. As a result, it should be understood that the processing node 140 may run all the programs in the smart contract, or may only run other programs in the smart contract except the qualified condition, which is not limited by the embodiment of the present application.
  • the multiple processing nodes (including the processing node 130 and the processing node 140) send a plurality of running results of the current endorsement to the client 110. Then, the client 110 receives the endorsement sent by the multiple processing nodes. Running result;
  • S204 may include S204a and S204b. Since the processing speed of the smart contract is different for each endorsement node, the execution of S204a and S204b may be in any order, which is not limited by the embodiment of the present application.
  • S205-S211 is the trading stage and includes:
  • the client 110 determines whether the multiple running results meet the verification policy, and encapsulates the running result that satisfies the verification policy into the transaction.
  • the client 110 may use multiple verification methods for verifying the multiple running results.
  • the client 110 may first determine whether the number of valid running results of the multiple running results exceeds a preset value (ie, verify the validity of the running result), and then pass the legality. Whether the number of running results with the same data and version number exceeds the preset value in the verified running result (that is, verifying the consistency of the remaining running results);
  • the client 110 can detect whether the signature of the running result is legal every time a running result is received, and if the signature of the running result is legal, record the data and version number of the running result. If the signature verification is illegal, it will not be recorded. When the number of running results of the same data and version number exceeds a preset value in the legal result of the signature received by the client 110, the client 110 determines that the running result satisfies the verification policy.
  • the client 110 sends the transaction to the consensus service node 190; correspondingly, the consensus service node 190 receives the transaction;
  • the consensus service node 190 packages the plurality of transactions including the transaction A accumulated in a period of time into a transaction set according to a certain rule.
  • the consensus service node 190 broadcasts the foregoing transaction set to all processing nodes in the distributed network.
  • FIG. 2 only shows a partial processing node, but this should not constitute any limitation to the embodiments of the present application.
  • S208 may include S208a, S208b, S208c, and S208d, and correspondingly, processing node 130 receives the transaction set, processing node 140 receives the transaction set, processing node 170 receives the transaction set, and processing node 180 receives the transaction. set.
  • processing node 170 in the distributed network taking the processing node 170 in the distributed network as an example, it should be understood that other processing nodes except the processing node 170 of the above processing nodes are as follows for the transaction. The processing steps are the same as the processing node 170, and are not described herein again.
  • the processing node 170 checks whether a plurality of running results in the transaction meet the verification policy, where the check refers to data and a version generated by a program other than the qualification condition of the smart contract among the plurality of running results.
  • the check of the number which is used to indicate the condition that the book data in the distributed network needs to be met when the smart contract is run;
  • the code that defines the condition is generally a code that needs to meet certain conditions corresponding to the data that is modified frequently in the smart contract, and the multiple running results received by the processing node 170 can be divided into two cases:
  • the plurality of running results are the result of running all the programs of the smart contract, that is, the plurality of running results include data and version numbers generated by the program running the qualification condition of the smart contract,
  • the processing node 170 may ignore the data and version number associated with the qualification condition among the plurality of operation results, and only check data and version numbers generated by programs other than the qualification condition;
  • the plurality of operation results are data and version numbers generated by running other programs than the above-defined conditions, in which case the processing node 170 can directly check the plurality of operation results.
  • the processing node 170 needs to check only the data generated by the program other than the qualification condition when performing the inspection. And version number.
  • the user can set a plurality of endorsement nodes to be trusted by the smart contract according to the actual needs of the user, and set a verification policy for the plurality of endorsement nodes, and the verification strategy may include consistency on multiple running results. verification.
  • the consistency verification may be that when the number of running results with the same data and version number meets the preset value, the multiple running results are considered to pass the consistency verification.
  • the number of endorsement nodes preset by the client is three
  • the corresponding verification policy may be that the data and the version number of the three running results must be the same, or the data and the version number of the at least two running results may be the same. This example does not limit this.
  • the verifying may further include verifying the legality of the multiple running results.
  • the legality verification may be that the number of the legal running results of the multiple running results meets the preset value, that is, the multiple running results are considered to be verified by the legality, but the embodiment of the present application does not limit this.
  • the processing node 170 generally needs to verify the validity of the multiple running results, and then verify the consistency of the multiple running results in the remaining running result of the signature, but the embodiment of the present application does not limit this.
  • the processing node 170 identifies the qualification condition in the smart contract, and determines whether the local book data meets the qualification condition;
  • the processing node 170 may determine a qualification condition in the smart contract if the multiple running results satisfy the verification policy (ie, through legality verification and consistency verification), and then determine whether the local book data meets the limit. condition. It should be understood that if the multiple running results do not satisfy the above verification strategy, the processing node 170 may directly consider the transaction to be an invalid transaction and refuse to modify the local ledger data.
  • the verification policy ie, through legality verification and consistency verification
  • the qualification condition of the smart contract is that the endorsement node pre-resolves according to the code of the smart contract, and the endorsement node sends the code of the qualified condition to the client or the proxy node, and then the qualified node or the client The code is logged to all nodes in the distributed network through transactions. Therefore, the processing node 170 can identify the qualification conditions of the smart contract.
  • the processing node 170 may task the transaction as a valid transaction if the local accounting data meets the qualification condition. Further, the processing node 170 may modify the local accounting data of the processing node 170 according to the multiple running results. . It should be understood that if the local ledger data of the processing node 170 does not satisfy the above defined conditions, the processing node 170 may determine that the transaction is an invalid transaction and refuse to modify the local ledger data.
  • processing node 170 receives the set of transactions and processes them sequentially in the order of the plurality of transactions. Since each transaction in the plurality of transactions is processed in the same manner as one transaction in S209-S211, it will not be described here.
  • the method further includes: a program for the client 110 to send a smart contract to the plurality of endorsement nodes (ie, the processing node 130 and the processing node 140); the plurality of endorsement nodes receiving the a smart contract program that parses the program of the smart contract and sends a code of the qualification condition of the smart contract to the client 110; the client 110 receives the code of the qualification condition, and the smart contract is processed by a transaction
  • the qualified code is sent to all processing nodes in the distributed network. It should be understood that it is a prior art to record a piece of code into all processing nodes through a transaction, and therefore will not be described in detail herein.
  • the verification of the qualified conditions corresponding to the data with more frequent changes is ignored, and the multiple running results are performed.
  • the data and the version number other than the qualification condition satisfy the verification policy, it is verified whether the local account book data satisfies the qualification condition, and the local account book data is accepted if the local account book data meets the qualification condition. Because the data in the distributed network changes frequently, for a certain transaction, the data and version number in the local ledger of the endorsement node when the smart contract is run, and the transaction are broadcast to the distributed network through the consensus service node.
  • the data and the version number of each node are likely to be inconsistent when all the processing nodes in the verification are performed.
  • the client has to re-initiate the transaction, and the method in the embodiment of the present application avoids the customer due to frequent data modification. The situation is constantly being retried.
  • the method for running the smart contract in the embodiment of the present application satisfies the verification of the qualified condition corresponding to the data with more frequent changes, and the data and the version number other than the qualified condition are satisfied in the multiple running results of the transaction.
  • verifying whether the local ledger data meets the qualification condition is beneficial to improving the success rate of writing the transaction into the ledger, thereby contributing to improving the overall performance of the system.
  • the client node 120 has a proxy node (ie, processing node 160) as an example for description.
  • FIG. 3 shows a schematic flowchart 300 of another method of running a smart contract in an embodiment of the present application.
  • the method 300 can be applied to the network architecture 100 shown in FIG. 1, but the embodiment of the present application is not limited thereto.
  • the client 120 sends a request to the processing node 160 to simulate running a smart contract, where the request includes the identification information of the smart contract; and correspondingly, the processing node 160 receives the request;
  • the processing node 160 respectively sends a request for simulating running a smart contract to a plurality of processing nodes (endorsed nodes); correspondingly, the plurality of processing nodes (endorsed nodes) respectively receive the request;
  • the client 120 has only two endorsement nodes (the processing node 130 and the processing node 150) as an example.
  • S302 may include S302a and S302b, S302a and S302b. This may be performed separately or in the same manner, which is not limited by the embodiment of the present application.
  • the processing node 130 runs the smart contract according to the request, and endorses the running result, and obtains the running result of the endorsement;
  • the processing node 130 may identify the qualification condition of the smart contract, and run a program other than the limited condition in the smart contract based on the local ledger data of the processing node 130 and perform signature to obtain the operation of the endorsement. As a result, it should be understood that the processing node 130 may run all the programs in the smart contract, or may only run other programs in the smart contract except the qualified condition, which is not limited by the embodiment of the present application.
  • the processing node 140 runs the smart contract according to the request, and endorses the running result, and obtains the running result of the endorsement;
  • the processing node 140 may identify the qualification condition of the smart contract, and run a program other than the qualified condition in the smart contract based on the local ledger data of the processing node 140 and perform signature to obtain the operation of the endorsement. As a result, it should be understood that the processing node 140 may run all the programs in the smart contract, or may only run other programs in the smart contract except the qualified condition, which is not limited by the embodiment of the present application.
  • the foregoing multiple processing nodes (including the processing node 130 and the processing node 150) respectively send the running result of the endorsement to the processing node 160; correspondingly, the processing node 160 receives multiple running results;
  • S305 may include S305a and S305b. Since the processing speed of the smart contract is different for each endorsement node, the execution of S305a and S305b may be in any order, which is not limited by the embodiment of the present application.
  • the processing node 160 verifies the received multiple running results, and determines whether the multiple running results meet the verification policy.
  • the processing node 160 may use multiple verification methods for verifying the multiple running results.
  • the processing node 160 may first determine whether the number of valid running results of the multiple running results exceeds a preset value (ie, verify the validity of the running result), and then pass the legality. Whether the number of running results with the same data and version number exceeds the preset value in the verified running result (that is, verifying the consistency of the remaining running results);
  • the processing node 160 may detect whether the signature of the running result is legal every time a running result is received, and if the signature of the running result is legal, record the data and version number of the running result. If the signature verification is illegal, it will not be recorded. When the number of running results of the same data and version number exceeds a preset value in the legal result of the signature received by the processing node 160, the processing node 160 determines that the running result satisfies the verification policy.
  • the processing node 160 sends the running result that satisfies the verification policy to the client 120; correspondingly, the client 120 receives the running result that satisfies the verification policy;
  • the client 120 encapsulates the running result satisfying the verification policy into a transaction (for example, transaction A);
  • the client 120 sends the transaction to the processing node 160; correspondingly, the processing node 160 receives the transaction;
  • the processing node 160 sends the transaction to the consensus service node 190; correspondingly, the consensus service node 190 receives the transaction;
  • the consensus service node 190 packages the plurality of transactions including the transaction A accumulated in a period of time into a transaction set according to a certain rule;
  • the consensus service node 190 broadcasts the foregoing transaction set to all processing nodes in the distributed network;
  • FIG. 3 only shows a partial processing node, but this should not constitute any limitation to the embodiments of the present application.
  • S312 may include S312a, S312b, S312c, S312d, and S312e, and correspondingly, processing node 160 receives the transaction set, processing node 130 receives the transaction set, processing node 150 receives the transaction set, and processing node 170 receives The transaction set, processing node 180 receives the transaction set.
  • the method for running a smart contract in the embodiment of the present application after verifying the qualification condition corresponding to the data with more frequent changes, after the data and the version number other than the limited condition satisfy the verification policy in the multiple running results of the transaction Then, verifying whether the local ledger data meets the qualification condition is beneficial to improving the success rate of writing the transaction into the ledger, thereby contributing to improving the overall performance of the system.
  • the method further includes: the client 120 may send a program of the smart contract to its proxy node (ie, the processing node 160); the proxy node receives the program of the smart contract and sends it to the a plurality of endorsement nodes (ie, processing node 130 and processing node 150); the plurality of endorsement nodes receive the program of the smart contract, parse the program of the smart contract, and send the code of the qualification condition of the smart contract to the proxy node
  • the proxy node receives the code of the qualification condition and returns it to the client 120; the client 120 receives the code of the qualification condition, and then sends the code of the qualification condition of the smart contract to the distributed network through a transaction. All processing nodes. It should be understood that it is a prior art to record a piece of code into all nodes through a transaction, and therefore will not be described in detail herein.
  • the method for running a smart contract in the embodiment of the present application after verifying the qualification condition corresponding to the data with more frequent changes, after the data and the version number other than the limited condition satisfy the verification policy in the multiple running results of the transaction Then, verifying whether the local ledger data meets the qualification condition is beneficial to improving the success rate of writing the transaction into the ledger, thereby contributing to improving the overall performance of the system.
  • the smart contract of the sales item includes a qualification interface IfStateCondition, and the input in the IfStateCondition is a conditional judgment on the data stored in the blockchain.
  • IfStateCondition checks whether the fund balance of the buyer's buyer is sufficient to purchase the asset, and checks whether the remaining quantity of the owner's owner asset is available for sale. If the data in the blockchain satisfies the above conditions, the asset purchase process in the smart contract. Can be executed, if not satisfied, the asset purchase operation cannot be performed.
  • the administrator or smart contract provider sends a transaction to the multiple endorsement nodes through the client to run the above smart contract.
  • the plurality of endorsement nodes respectively parse the code of the smart contract, and obtain the IfStateCondition function of the smart contract, that is, the code of the qualification interface of the smart contract (stub.Get("BuyerId", “Money”)>1&&stub.Get("OwnerID” , "Asset_account”) > 100).
  • the plurality of endorsement nodes respectively return the code of the qualified interface to the client, and the client records the code of the smart contract and the code of the qualified condition interface of the smart contract into all the blockchain network through a transaction In the node. It should be understood that it is a prior art to record a piece of code into all nodes through a transaction, and therefore will not be described in detail herein.
  • user A When user A needs to invoke the BuyOneAsset function of the smart contract, user A sends a request to the endorsement node M and the endorsement node N to run the smart contract through client A, the request containing the smart contract requested by user A. ID and function name (BuyOneAsset). It should be understood that if the function that user A needs to call is a parameterized function, the parameter of the parameterized function should also be included in the request.
  • the endorsement node M and the endorsement node N respectively receive the request sent by the client to simulate running the above smart contract, and perform the following steps respectively:
  • the code of the smart contract from the blockchain ledger according to the ID of the smart contract, running the code of the smart contract in the case of ignoring the code of the constraint interface therein, and recording the data value accessed when executing the code of the smart contract And the version number.
  • the final running result may be other data than the tolerant data set and the version number, and the tolerant data set refers to the data and version number that need to be accessed when the code of the above-mentioned qualified interface is run, in the embodiment of the present application.
  • the tolerance data collection is BuyerId_Money and Owner_asset_account.
  • the endorsement node M returns the running result M to the client of the user A
  • the endorsement node N returns the running result N to the client of the user A.
  • the client After receiving the running result sent by all the endorsement nodes, the client encapsulates the received multiple running results into a transaction according to the blockchain message format and sends it to the consensus service node.
  • the client compares the data and the version number of the multiple running results, determines whether the multiple running results meet the verification policy, and encapsulates and sends the multiple running results when the verification result meets the verification policy.
  • the consensus service node the verification policy is set to be consistent with the running results returned by the endorsement node M and the endorsement node N, that is, the parameters in all the running results must be the same.
  • FIG. 4 is a schematic flowchart of another method for running a smart contract in the embodiment of the present application.
  • the consensus service node broadcasts a transaction set of client B to all nodes in the blockchain network.
  • the endorsement node M receives the transaction set of the client B
  • the endorsement node N receives the transaction set of the client B
  • S420 the client A sends a request to simulate the running smart contract to the endorsement node M and the endorsement node N respectively, as shown in FIG. 4, S420 includes S420a and S420b, and correspondingly, the endorsement node M receives the request, and is locally based according to the request.
  • the book data runs the smart contract, and the running result of the endorsement is obtained.
  • the endorsement node N receives the request, and runs the smart contract based on the local ledger data according to the request, and obtains the running result of the endorsement;
  • the endorsement node M and the endorsement node N respectively send the end result of the endorsement to the client A; correspondingly, the client A receives the running results of the plurality of endorsements.
  • the endorsement node M receives the transaction set of the client B, verifies the data in the transaction set, and modifies the local ledger data
  • the endorsement node N does not receive the transaction set of the client B. Therefore, the local ledger data used by the endorsement node M to run the client A's smart contract is inconsistent with the local ledger data used by the endorsement node N to run the client A's smart contract. Therefore, if the prior art is used, the data version numbers of the Owner_asset_account in the books of the endorsement node M and the endorsement node N are inconsistent, and the specific account data involved is as follows:
  • the collected data and version number are as follows:
  • the result is SUCCESS.
  • the client determines that the running result of the endorsement node M and the endorsement node N satisfies the verification policy, encapsulates it in a transaction message and sends it to the consensus service node.
  • the consensus service node collects transactions over a period of time to form a block, the block includes a set of transaction groups in sequence, and the consensus service node broadcasts the transaction set to all nodes in the blockchain network, each of all nodes Each node processes the transactions in the transaction set in order, one by one.
  • the processing node After receiving the broadcasted transaction set, the processing node processes the transaction one by one from the transaction set. Assume that the transaction set contains three transactions Tx1, Tx2, and Tx3 sent by different users A, C, and D at the same time, which are all transactions for purchasing assets, and because the time is the same, their running results are the same, that is, the transaction set. The following transactions are included in the order of the transactions:
  • the processing node When processing the Tx1, the processing node first determines whether the running results M and N satisfy the verification strategy, that is, whether the running result and the modification of the data in the endorsementM and endorsementN in Tx1 are the same.
  • the running results M and N are as shown in Table 3 and Table 4, and the verification strategy is satisfied.
  • the processing node checks whether the version number in the local ledger data is consistent with the data version number of Tx1 (ie, endorsementM and endorsementN of Tx1). After checking, the local ledger data is consistent with the data version number of Tx1.
  • the processing node obtains the code of the qualification interface of the smart contract according to the CCID, and the specific code is: stub.Get ("BuyerId”, “Money”)>1&&stub.Get("OwnerID", "Asset_account”)>100.
  • the processing node runs the code of the qualified interface of the smart contract according to the local ledger data, and the running result is true, accepts the modification of the data by Tx1, and increases the version number of the modified data by 1, and the related data and the version number become:
  • the processing node first determines whether the running results M and N satisfy the verification strategy, that is, whether the running result and the modification of the data in the endorsementM and endorsementN in Tx2 are the same.
  • the running results M and N are the same, and the verification policy is satisfied.
  • the processing node checks whether the version number in the local ledger data is consistent with the data version number of Tx2 (ie, endorsementM and endorsementN of Tx2). After checking, the local ledger data is consistent with the data version number of Tx2.
  • the processing node obtains the code of the qualification interface of the smart contract according to the CCID, and the specific code is: stub.Get ("BuyerId”, “Money”)>1&&stub.Get("OwnerID", "Asset_account”)>100.
  • the processing node runs the code of the qualified interface of the smart contract according to the local ledger data, and the running result is true, accepts the modification of the data by Tx2, and increases the version number of the modified data by 1, and the related data and the version number become:
  • Table 7 Account book data after accepting Tx2
  • the processing node first determines whether the running results M and N satisfy the verification strategy, that is, the running results in endorsementM and endorsementN in Tx3 and whether the modifications to the data are the same.
  • the running results M and N are the same, and the verification policy is satisfied.
  • the processing node checks whether the version number in the local ledger data is consistent with the data version number of Tx3 (ie, endorsementM and endorsementN of Tx3). After checking, the local ledger data is consistent with the data version number of Tx3.
  • the processing node obtains the code of the qualification interface of the smart contract according to the CCID, and the specific code is: stub.Get ("BuyerId”, “Money”)>1&&stub.Get("OwnerID", "Asset_account”)>100.
  • the processing node runs the code of the qualified interface of the smart contract according to the local ledger data. At this time, the Owner_asset_account is 0, so the transaction Tx3 cannot be verified by the qualified interface, and the processing node records Tx3 as an invalid transaction, and does not accept the pair. Modification of the data.
  • FIG. 5 is a schematic block diagram of an apparatus 500 for running a smart contract provided by an embodiment of the present application.
  • the apparatus 500 includes a receiving unit 510, an checking unit 520, a determining unit 530, and a processing unit 540.
  • the receiving unit 510 is configured to receive a transaction sent by the consensus service node, where the transaction includes multiple running results generated during an endorsement process of the smart contract;
  • the checking unit 520 is configured to check whether the plurality of running results meet the verification policy, and the checking includes data and a version number generated by a program other than the limited condition of the smart contract among the plurality of running results Checking, the qualification condition is used to indicate a condition that the book data in the distributed network needs to be satisfied when the smart contract is run;
  • a determining unit 530 configured to identify a qualification condition in the smart contract if the plurality of running results meet the verification policy, and determine whether the local book data meets the qualification condition;
  • the processing unit 540 is configured to accept the transaction if the local ledger data satisfies the qualification condition.
  • the device for running the smart contract in the embodiment of the present application after verifying the qualification condition corresponding to the data with more frequent changes, after the data and the version number other than the limited condition satisfy the verification policy in the multiple running results of the transaction Then, verifying whether the local ledger data meets the qualification condition is beneficial to improving the success rate of writing the transaction into the ledger, thereby contributing to improving the overall performance of the system.
  • the device 500 is an endorsement node, and the device 500 further includes: an endorsement unit, configured to endorse the smart contract before the transaction sent by the consensus service node, to obtain the operation of the endorsement
  • the first sending unit is configured to send the running result of the current endorsement to a client that needs to use the running result of the current endorsement in the transaction or a proxy node of the client.
  • the receiving unit 510 is further configured to: receive a request sent by the client or the proxy node of the client to simulate running the smart contract, where the request includes identifier information of the smart contract; the endorsement unit Before the receiving the transaction sent by the consensus service node, endoring the smart contract to obtain the running result of the endorsement, specifically: identifying, according to the identification information of the smart contract, the location in the smart contract Defining a condition; running a program other than the defined condition in the smart contract based on the local book data and signing, obtaining the running result of the endorsement.
  • the receiving unit 510 is further configured to: receive the smartware sent by the client or the proxy node of the client before the endorsement of the smart contract to obtain the running result of the endorsement a program of the contract; the apparatus 500 further includes: a parsing unit, configured to parse the program of the smart contract, to obtain the program for defining the condition; the first sending unit is further configured to: to the client or the The proxy node of the client sends the program of the qualification.
  • the apparatus 500 is a proxy node, and the apparatus 500 further includes: a second sending unit, configured to send, by the receiving the consensus service node, multiple endorsement nodes in the distributed network Sending a request to simulate the running of the smart contract, the request includes the identification information of the smart contract; the receiving unit 510 is further configured to: receive a respective running result sent by the multiple endorsement nodes according to the request; The checking unit 520 is further configured to: check whether the received plurality of running results meet the verification policy, and the checking includes: generating, by the other programs than the defined condition, the plurality of running results Checking the data and the version number; the second sending unit is further configured to: send the multiple running results to the client if the multiple running results satisfy the verification policy.
  • a second sending unit configured to send, by the receiving the consensus service node, multiple endorsement nodes in the distributed network Sending a request to simulate the running of the smart contract, the request includes the identification information of the smart contract
  • the receiving unit 510 is further configured to: receive a respective running result sent by the
  • the second sending unit is further configured to: after the sending, by the multiple endorsement nodes in the distributed network, a request to simulate running the smart contract, send the to the plurality of endorsement nodes a program of the smart contract; the receiving unit 510 is further configured to: receive the program of the qualification condition that is sent by the multiple endorsement nodes according to the program of the smart contract; the second sending unit is further configured to: All processing nodes in the distributed network send the program of the qualification.
  • the apparatus 500 herein is embodied in the form of a functional unit.
  • the term "unit” as used herein may refer to an application specific integrated circuit (ASIC), an electronic circuit, a processor (eg, a shared processor, a proprietary processor, or a group) for executing one or more software or firmware programs. Processors, etc.) and memory, merge logic, and/or other suitable components that support the described functionality.
  • ASIC application specific integrated circuit
  • processor eg, a shared processor, a proprietary processor, or a group
  • memory merge logic, and/or other suitable components that support the described functionality.
  • the apparatus 500 may be specifically a processing node in a distributed network in the foregoing method embodiment, and the apparatus 500 may be used in each of the processing nodes corresponding to the processing node of the foregoing method embodiment. Processes and/or steps, to avoid repetition, will not be repeated here.
  • FIG. 6 is a schematic block diagram of another apparatus 600 for running a smart contract provided by an embodiment of the present application. As shown in FIG. 6, the apparatus 600 includes a transmitting unit 610, a receiving unit 620, and an inspecting unit 630.
  • the sending unit 610 is configured to send, to the multiple endorsement nodes in the distributed network, a request for simulating running a smart contract, where the request includes identifier information of the smart contract;
  • the receiving unit 620 is configured to receive respective running results that are sent by the multiple endorsement nodes according to the request;
  • the checking unit 630 is configured to check whether the received plurality of running results meet the verification policy, and the checking includes data and a version of the plurality of running results generated by a program other than the qualification condition of the smart contract a check of the number used to indicate a condition that the ledger data in the distributed network needs to be satisfied when the smart contract is run;
  • the sending unit 610 is further configured to: when the multiple running results meet the verification policy, send a transaction including the multiple running results to the consensus service node.
  • the device for running the smart contract in the embodiment of the present application after verifying the qualification condition corresponding to the data with more frequent changes, after the data and the version number other than the limited condition satisfy the verification policy in the multiple running results of the transaction Then, verifying whether the local ledger data meets the qualification condition is beneficial to improving the success rate of writing the transaction into the ledger, thereby contributing to improving the overall performance of the system.
  • the sending unit 610 is further configured to: send the program of the smart contract to the multiple endorsement nodes before sending the request for simulating the running smart contract to the plurality of endorsement nodes in the distributed network;
  • the apparatus 600 herein is embodied in the form of a functional unit.
  • the term "unit” as used herein may refer to an application specific integrated circuit (ASIC), an electronic circuit, a processor (eg, a shared processor, a proprietary processor, or a group) for executing one or more software or firmware programs. Processors, etc.) and memory, merge logic, and/or other suitable components that support the described functionality.
  • ASIC application specific integrated circuit
  • processor eg, a shared processor, a proprietary processor, or a group
  • memory merge logic, and/or other suitable components that support the described functionality.
  • the device 600 may be specifically a client in the foregoing method embodiment, and the device 600 may be used in various processes and/or steps corresponding to the client executing the foregoing method embodiment. To avoid repetition, we will not repeat them here.
  • FIG. 7 is a schematic block diagram of another apparatus 700 for running a smart contract provided by an embodiment of the present application.
  • the apparatus 700 includes a processor 710, a transceiver 720, and a memory 730.
  • the processor 710, the transceiver 720, and the memory 730 communicate with each other through an internal connection path.
  • the memory 730 is configured to store instructions, and the processor 710 is configured to execute instructions stored in the memory 730 to control the transceiver 720 to send signals and / or receive signals.
  • the transceiver 720 is configured to receive a transaction sent by a consensus service node, where the transaction includes multiple running results generated in an endorsement process of the smart contract;
  • the processor 710 is configured to check whether the plurality of running results meet a verification policy, and the checking includes data and a version number generated by a program other than the defined condition of the smart contract among the plurality of running results Checking the condition for indicating that the book data in the distributed network needs to be satisfied when the smart contract is run; and identifying the smart if the plurality of running results satisfy the verification policy
  • a qualification condition in the contract determines whether the local ledger data satisfies the qualification condition; and if the local ledger data satisfies the qualification condition, accepts the transaction.
  • the apparatus 700 may be specifically a processing node in a distributed network in the foregoing method embodiment, and may be used to perform various steps and/or processes corresponding to the processing node in the foregoing method embodiment.
  • the memory 730 can include read only memory and random access memory and provide instructions and data to the processor. A portion of the memory may also include a non-volatile random access memory.
  • the memory can also store information of the device type.
  • the processor 710 can be configured to execute instructions stored in a memory, and when the processor 710 executes instructions stored in the memory, the processor 710 is configured to perform various steps and/or processes with the method embodiments described above.
  • FIG. 8 is a schematic block diagram of another apparatus 800 for running a smart contract provided by an embodiment of the present application.
  • the apparatus 800 includes a processor 810, a transceiver 820, and a memory 830.
  • the processor 810, the transceiver 820, and the memory 830 communicate with each other through an internal connection path.
  • the memory 830 is configured to store instructions, and the processor 810 is configured to execute instructions stored in the memory 830 to control the transceiver 820 to send signals and / or receive signals.
  • the transceiver 820 is configured to send a request for simulating running a smart contract to a plurality of endorsement nodes in a distributed network, where the request includes identification information of the smart contract; and receiving the multiple endorsement nodes to send according to the request The respective running results;
  • the processor 810 is configured to check whether the received plurality of running results meet the verification policy, and the checking includes data and a version generated by a program other than the qualification condition of the smart contract among the plurality of running results. a check of the number used to indicate a condition that the ledger data in the distributed network needs to be satisfied when the smart contract is run;
  • the transceiver 820 is further configured to: send the transaction including the multiple running results to the consensus service node if the multiple running results satisfy the verification policy.
  • the device 800 may be specifically a client in the foregoing method embodiment, and may be used to perform various steps and/or processes corresponding to the client of the foregoing method embodiment.
  • the memory 830 can include read only memory and random access memory and provide instructions and data to the processor. A portion of the memory may also include a non-volatile random access memory.
  • the memory can also store information of the device type.
  • the processor 810 can be configured to execute instructions stored in a memory, and when the processor 810 executes instructions stored in the memory, the processor 810 is configured to perform various steps and/or processes corresponding to the clients of the above-described embodiments. .
  • the processor of the foregoing device may be a central processing unit (CPU), and the processor may also be other general-purpose processors, digital signal processing (DSP).
  • DSP digital signal processing
  • the general purpose processor may be a microprocessor or the processor or any conventional processor or the like.
  • each step of the above method may be completed by an integrated logic circuit of hardware in a processor or an instruction in a form of software.
  • the steps of the method disclosed in the embodiments of the present application may be directly implemented as a hardware processor, or may be performed by a combination of hardware and software units in the processor.
  • the software unit can be located in a conventional storage medium such as random access memory, flash memory, read only memory, programmable read only memory or electrically erasable programmable memory, registers, and the like.
  • the storage medium is located in a memory, and the processor executes instructions in the memory, in combination with hardware to perform the steps of the above method. To avoid repetition, it will not be described in detail here.
  • system and “network” are used interchangeably herein.
  • the term “and/or” in this context is merely an association describing the associated object, indicating that there may be three relationships, for example, A and/or B, which may indicate that A exists separately, and both A and B exist, respectively. B these three situations.
  • the character "/" in this article generally indicates that the contextual object is an "or" relationship.
  • B corresponding to A means that B is associated with A, and B can be determined according to A.
  • determining B from A does not mean that B is only determined based on A, and that B can also be determined based on A and/or other information.
  • the disclosed systems, devices, and methods may be implemented in other manners.
  • the device embodiments described above are merely illustrative.
  • the division of cells is only a logical function division.
  • multiple units or components may be combined or integrated. Go to another system, or some features can be ignored or not executed.
  • the mutual coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some interface, device or unit, or an electrical, mechanical or other form of connection.
  • the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, may be located in one place, or may be distributed to multiple network units. Some or all of the units may be selected according to actual needs to achieve the objectives of the embodiments of the present application.
  • each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
  • the above integrated unit can be implemented in the form of hardware or in the form of a software functional unit.
  • the integrated unit if implemented in the form of a software functional unit and sold or used as a standalone product, may be stored in a computer readable storage medium.
  • the technical solution of the present application may be in essence or part of the contribution to the prior art, or all or part of the technical solution may be embodied in the form of a software product stored in a storage medium.
  • a number of instructions are included to cause a computer device (which may be a personal computer, server, or network device, etc.) to perform all or part of the steps of the methods described in various embodiments of the present application.
  • the foregoing storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, and the like, which can store program code. .

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Business, Economics & Management (AREA)
  • General Engineering & Computer Science (AREA)
  • Accounting & Taxation (AREA)
  • Databases & Information Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Computer Security & Cryptography (AREA)
  • Finance (AREA)
  • General Business, Economics & Management (AREA)
  • Strategic Management (AREA)
  • Health & Medical Sciences (AREA)
  • Bioethics (AREA)
  • General Health & Medical Sciences (AREA)
  • Computer Hardware Design (AREA)
  • Software Systems (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

本申请实施例提供了一种运行智能合约的方法和装置,应用于分布式网络中,该方法包括:该分布式网络中的处理节点接收共识服务节点发送的交易,该交易包括在智能合约的背书过程中产生的多个运行结果;该处理节点检查该多个运行结果是否满足验证策略,该检查包括对该多个运行结果中由除该智能合约的限定条件之外的其他程序产生的数据和版本号的检查;在该多个运行结果满足该验证策略的情况下,该处理节点识别该智能合约中的限定条件,确定本地账本数据是否满足该限定条件;在该本地账本数据满足该限定条件的情况下,该处理节点接受该交易。本申请实施例的运行智能合约的方法和装置,能够有利于提高交易写入账本的成功率,从而有利于提高***的整体性能。

Description

运行智能合约的方法和装置
本申请要求于2017年6月26日提交中国专利局、申请号为201710496967.7,发明名称为“运行智能合约的方法和装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请实施例涉及信息技术领域,特别涉及信息技术领域中的运行智能合约的方法和装置。
背景技术
互联网上的贸易,几乎都需要借助可信赖的第三方信用机构来处理,而区块链技术基于密码学原理,可以达成一致的双方直接支付,不需要第三方中介的参与。区块链是一个分布式的账本,是一种去中心化的数据库,需要区块链网络中的所有节点集体进行维护,本文称能够处理账本数据的这些节点为处理节点。它包含多个区块(block),每个区块包括若干条交易记录,同时包含了前一个区块的哈希值,这样所有的区块按顺序相连组成了区块链。智能合约(chaincode)是区块链技术中的一个重要概念,智能合约是由事件驱动的、具有状态的、运行在一个复制的、分享的账本之上的、且能够管理账本上数据的程序。智能合约看上去就是一段普通的计算机执行程序,智能合约的代码内容规定了交易的规则和逻辑,使用者签署调用智能合约就意味着合约内容将会被执行,并且执行的结果会被写入账本。
由于区块链是一种去中心化、去信任的分布式账本,因此,区块链网络中的处理节点相互之间并不信任,有可能存在恶意说谎节点,而共识算法可以很好地解决这一问题。虽然区块链网络中的每个处理节点都有可能是恶意说谎节点,但是众多节点聚到一个网络中,它们共识的结果就是一个可信的结果。共识算法的主要作用,就是让区块链网络中的所有处理节点记录相同的有效交易区块内容。在现有的一种共识机制PoE(proof of endorse)中,客户端在需要运行某一智能合约时,可以先向多个背书节点发送模拟运行智能合约的请求,模拟运行该智能合约。其中,背书节点也属于处理节点,是处理节点中具有背书功能的一部分节点。该多个背书节点运行该智能合约,对自身的运行结果进行签名后返回给客户端(本文称之为“背书”),该客户端再按照区块链消息格式把该多个背书节点的多个运行结果封装到交易消息中,发送给共识服务节点,通过共识服务节点以区块为单位将其广播到该区块链网络中的所有处理节点(包括上述多个背书节点),该区块链网络中的处理节点对接收到的交易进行校验,满足验证策略的交易才会被认为是有效交易,进而对数据进行修改,将更新后的数据写入区块链。这里,用户可以根据自己的实际需求通过客户端设置智能合约要信任的多个背书节点,并设置对该多个背书节点的验证策略,例如,用户A的背书节点可以为3个,用户A的客户端A向这3个背书节点发送模拟运行智能合约的请求,会收到对应的3个运行结果,验证策略可以为3个运行结果的内容必须一致,也可以为至少2个运行结果的内容一致。
实际运行过程中,整个区块链网络是分布式的,并且区块链网络中的每个处理节点都保存一份区块链的完整账本数据。但是由于数据同步会有先后顺序,背书节点在运行某个交易的智能合约时所访问的区块链数据,与该交易后续在该区块链网络中的每个处理节点上要写入本地账本时的数据很有可能会不一致,使得背书节点的背书失效,因此,需要一些机制来 防止背书失效的交易写入账本。
现有技术为智能合约的每一个数据设置了一个自增的版本号,每次对数据进行更新就修改一次版本号(例如,版本号加1)。背书节点在运行智能合约的时候,如果需要访问智能合约保存在区块链上的数据,就记录下需要访问的数据的版本号。该背书节点返回给客户端的运行结果中包含这些数据的版本号。该区块链网络中的所有处理节点在进行校验时,需要校验交易中数据的版本号是否与本地账本数据的版本号一致,在一致的情况下,确认该交易为有效交易,对本地账本数据进行更新。
但是,在区块链的数据变化比较频繁时,对于某个交易而言,背书节点在运行智能合约时的访问的本地账本中的数据版本号,与该交易通过共识服务节点广播到区块链网络中的所有处理节点进行验证时各个处理节点的数据版本号很有可能不一致,导致该交易无效。在这种情况下,客户端只好重新发起交易,直到数据版本号一致后交易合法写入账本为止。因此,现有的方法交易写入账本的成功率较低。
发明内容
本申请实施例提供的运行智能合约的方法和装置,有利于提高交易写入账本的成功率,从而有利于提高***的整体性能。
第一方面,提供了一种运行智能合约的方法,应用于分布式网络中,所述方法包括:所述分布式网络中的处理节点接收共识服务节点发送的交易,所述交易包括在智能合约的背书过程中产生的多个运行结果;所述处理节点检查所述多个运行结果是否满足验证策略,所述检查包括对所述多个运行结果中由除所述智能合约的限定条件之外的其他程序产生的数据和版本号的检查,所述限定条件用于表示运行所述智能合约时所述分布式网络中的账本数据需要满足的条件;在所述多个运行结果满足所述验证策略的情况下,所述处理节点识别所述智能合约中的限定条件,确定本地账本数据是否满足所述限定条件;在所述本地账本数据满足所述限定条件的情况下,所述处理节点接受所述交易。
具体地,限定条件的代码一般为智能合约中修改比较频繁的数据对应的需要满足某种条件的代码,该处理节点接收到的多个运行结果可以分为两种情况:
(1)该多个运行结果为该智能合约的所有程序被运行产生的结果,即该多个运行结果均包括了运行该智能合约的限定条件的程序所产生的数据和版本号,在这种情况下,该处理节点可以忽略该多个运行结果中与该限定条件相关的数据和版本号,仅检查除该限定条件之外的其他程序产生的数据和版本号;
(2)该多个运行结果为运行除上述限定条件之外的其他程序产生的数据和版本号,在这种情况下,该处理节点可以直接对该多个运行结果进行检查。
因此,无论该多个运行结果中是否包括运行上述限定条件的程序产生的数据和版本号,该处理节点在进行检查时,都需要仅仅检查由除该限定条件之外的其他程序产生的数据和版本号。
具体地,分布式网络中的处理节点在按照验证策略对交易的多个运行结果进行验证时,先忽略对变化较频繁的数据对应的限定条件的验证,在多个运行结果中除限定条件之外的数据和版本号满足验证策略之后,再验证本地账本数据是否满足限定条件,在本地账本数据满足限定条件的情况下,接受该交易。
本申请实施例的运行智能合约的方法,通过将变化较频繁的数据对应的限定条件的验证 后置,在交易的多个运行结果中除该限定条件之外的数据和版本号满足验证策略之后,再验证本地账本数据是否满足该限定条件,有利于提高交易写入账本的成功率,从而有利于提高***的整体性能。
在第一方面的第一种可能的实现方式中,所述处理节点为背书节点,在所述处理节点接收共识服务节点发送的交易之前,所述方法还包括:所述处理节点对所述智能合约进行背书,得到本次背书的运行结果;所述处理节点将所述本次背书的运行结果发送给需要在交易中使用所述本次背书的运行结果的客户端或所述客户端的代理节点。
结合第一方面的上述可能的实现方式,在第一方面的第二种可能的实现方式中,所述处理节点对所述智能合约进行背书,得到本次背书的运行结果,包括:所述处理节点接收客户端或所述客户端的代理节点发送的模拟运行所述智能合约的请求,所述请求包括所述智能合约的标识信息;所述处理节点根据所述智能合约的标识信息,识别所述智能合约中的所述限定条件;所述处理节点基于所述本地账本数据运行所述智能合约中除所述限定条件之外的其它程序并进行签名,得到所述本次背书的运行结果。
具体地,该处理节点可以识别该智能合约的限定条件,并基于该处理节点的本地账本数据运行该智能合约中除该限定条件之外的其它程序并进行签名,得到本次背书的运行结果;应理解,该处理节点可以运行该智能合约中的全部程序,也可以仅运行该智能合约中除该限定条件之外的其他程序,本申请实施例对此不作限定。
结合第一方面的上述可能的实现方式,在第一方面的第三种可能的实现方式中,在所述处理节点对所述智能合约进行背书,得到本次背书的运行结果之前,所述方法还包括:所述处理节点接收所述客户端或所述客户端的代理节点发送的所述智能合约的程序;所述处理节点解析所述智能合约的程序,获得所述限定条件的程序;所述处理节点向所述客户端或所述客户端的代理节点发送所述限定条件的程序。
具体地,在所述处理节点即为背书节点的情况下,客户端或该客户端的代理节点可以向背书节点发送智能合约的程序;该背书节点接收该智能合约的程序,对该智能合约的程序进行解析,并将该智能合约的限定条件的代码发送给该客户端或代理节点;该客户端或代理节点接收该限定条件的代码,通过一个交易将该智能合约的限定条件的代码发送给该分布式网络中的所有处理节点。应理解,通过一个交易将一段代码记入到所有处理节点中是现有技术,因此本文不再赘述。
结合第一方面的上述可能的实现方式,在第一方面的第四种可能的实现方式中,所述处理节点为代理节点,在所述处理节点接收共识服务节点发送的交易之前,所述方法还包括:所述处理节点向所述分布式网络中的多个背书节点发送模拟运行所述智能合约的请求,所述请求包括所述智能合约的标识信息;所述处理节点接收所述多个背书节点根据所述请求发送的各自的运行结果;所述处理节点检查接收到的所述多个运行结果是否满足所述验证策略,所述检查包括对所述多个运行结果中由除所述限定条件之外的其他程序产生的数据和版本号的检查;在所述多个运行结果满足所述验证策略的情况下,所述处理节点向客户端发送所述多个运行结果。
在一种可选的实施例中,该处理节点可以先确定上述两个运行结果中签名合法的运行结果的数量是否超过预设值(即验证运行结果的合法性),然后在通过合法性验证的运行结果中确定数据和版本号相同的运行结果的数量是否超过预设值(即验证剩余运行结果的一致性)。
在另一种可选的实施例中,该处理节点可以每收到一个运行结果就检测该运行结果的签名是否合法,如果该运行结果的签名合法,则记录该运行结果的数据和版本号,签名验证不合法则不记录。当该处理节点收到的签名合法的运行结果中,数据和版本号相同的运行结果的数量超过预设值时,该处理节点确定该运行结果满足验证策略。
结合第一方面的上述可能的实现方式,在第一方面的第五种可能的实现方式中,在所述处理节点向所述分布式网络中的多个背书节点发送模拟运行所述智能合约的请求之前,所述方法还包括:所述处理节点向所述多个背书节点发送所述智能合约的程序;所述处理节点接收所述多个背书节点根据所述智能合约的程序发送的所述限定条件的程序;所述处理节点向所述分布式网络中的所有处理节点发送所述限定条件的程序。
应理解,该智能合约的限定条件为背书节点根据智能合约的代码预先解析出来的,背书节点将该限定条件的代码发送给客户端或代理节点,再由代理节点或客户端将该限定条件的代码通过交易记录到分布式网络中的所有处理节点中。
第二方面,提供了另一种运行智能合约的方法,包括:客户端向分布式网络中的多个背书节点发送模拟运行智能合约的请求,所述请求包括所述智能合约的标识信息;所述客户端接收所述多个背书节点根据所述请求发送的各自的运行结果;所述客户端检查接收到的多个运行结果是否满足验证策略,所述检查包括对所述多个运行结果中由除所述智能合约的限定条件之外的其他程序产生的数据和版本号的检查,所述限定条件用于表示运行所述智能合约时所述分布式网络中的账本数据需要满足的条件;在所述多个运行结果满足所述验证策略的情况下,所述客户端向共识服务节点发送包括所述多个运行结果的交易。
在第二方面的第一种可能的实现方式中,在所述客户端向分布式网络中的多个背书节点发送模拟运行智能合约的请求之前,所述方法还包括:所述客户端向所述多个背书节点发送所述智能合约的程序;所述客户端接收所述多个背书节点根据所述智能合约的程序发送的所述限定条件的程序;所述客户端向所述分布式网络中的所有处理节点发送所述限定条件的程序。
第三方面,提供了一种运行智能合约的装置,用于执行上述第一方面或第一方面的任意可能的实现方式中的方法。具体地,该装置包括用于执行上述第一方面或第一方面的任意可能的实现方式中的方法的单元。
第四方面,提供了另一种运行智能合约的装置,用于执行上述第二方面或第二方面的任意可能的实现方式中的方法。具体地,该装置包括用于执行上述第二方面或第二方面的任意可能的实现方式中的方法的单元。
第五方面,提供了一种运行智能合约的装置,该装置包括:收发器、存储器和处理器。其中,该收发器、该存储器和该处理器通过内部连接通路互相通信,该存储器用于存储指令,该处理器用于执行该存储器存储的指令,以控制接收器接收信号,并控制发送器发送信号,并且当该处理器执行该存储器存储的指令时,该执行使得该处理器执行第一方面或第一方面的任一种可能的实现方式中的方法。
第六方面,提供了一种运行智能合约的装置,该装置包括:收发器、存储器和处理器。其中,该收发器、该存储器和该处理器通过内部连接通路互相通信,该存储器用于存储指令,该处理器用于执行该存储器存储的指令,以控制接收器接收信号,并控制发送器发送信号,并且当该处理器执行该存储器存储的指令时,该执行使得该处理器执行第二方面或第二方面的任一种可能的实现方式中的方法。
第七方面,提供了一种计算机可读介质,用于存储计算机程序,该计算机程序包括用于执行第一方面或第一方面的任意可能的实现方式中的方法的指令。
第八方面,提供了一种计算机可读介质,用于存储计算机程序,该计算机程序包括用于执行第二方面或第二方面的任意可能的实现方式中的方法的指令。
附图说明
图1示出了本申请实施例的网络架构的示意图。
图2示出了根据本申请实施例的运行智能合约的方法的示意性流程图。
图3示出了根据本申请实施例的另一运行智能合约的方法的示意性流程图。
图4示出了根据本申请实施例的另一运行智能合约的方法的示意性流程图。
图5示出了根据本申请实施例的运行智能合约的装置的示意性框图。
图6示出了根据本申请实施例的另一运行智能合约的装置的示意性框图。
图7示出了根据本申请实施例的另一运行智能合约的装置的示意性框图。
图8示出了根据本申请实施例的另一运行智能合约的装置的示意性框图。
具体实施方式
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行描述。
首先介绍一下本申请实施例所涉及的区块链技术以及智能合约。
区块链技术:区块链首先是一个分布式***,它基于密码学原理,可以达成一致的双方直接支付,不需要第三方中介的参与。区块链是一个分布式的账本,是一种去中心化的数据库,需要区块链网络中的所有处理节点集体进行维护。它包含多个区块(block),每个区块包括若干条交易记录,同时包含了前一个区块的哈希值,这样所有的区块按顺序相连组成了区块链。
智能合约:智能合约是由事件驱动的、具有状态的、运行在一个复制的、分享的账本之上的、且能够管理账本上数据的程序。智能合约看上去就是一段普通的计算机执行程序,其代码内容规定了交易的规则和逻辑,使用者签署调用智能合约就意味着合约内容将会被执行,执行的结果会被写入账本。
以用区块链及智能合约来实现资产交易为例,一个可能的智能合约伪码如下:
Figure PCTCN2018085748-appb-000001
Figure PCTCN2018085748-appb-000002
用户如果要购买资产,就会通过客户端发出一个调用BuyOneAsset这个智能合约函数的交易,智能合约会从区块链保存的数据中读取购买者的资金余额、拥有者的资产剩余数量,判断满***易条件后,执行交易,并修改购买者的资金余额及拥有者的资产剩余数量,当交易经过共识写入账本之后,用户购买资产的交易就成功了。
要保障网络满足不同程度的一致性,往往需要共识算法来达成。下面介绍一下本申请实施例所涉及的共识算法。
共识算法解决的是对某个提案,多个节点达成一致的过程。由于区块链是一种去中心化、去信任的分布式账本,因此,区块链网络中的处理节点相互之间并不信任,有可能存在恶意说谎节点,而共识算法可以很好地解决这一问题。虽然区块链网络中的每个处理节点都有可能是恶意说谎节点,但是众多处理节点聚到一个网络中,它们共识的结果就是一个可信的结果。共识算法的主要作用,就是让区块链网络中的所有处理节点记录相同的有效交易区块内容。常用的共识算法包括实用拜占庭容错(practical byzantine fault tolerance,PBFT)算法、工作量证明(proof of work,PoW)算法、POE(proof of endorse)算法等等。
在PoE算法中,客户端在需要运行某一智能合约时,可以先向多个背书节点发送模拟运行智能合约的请求,模拟运行该智能合约,该多个背书节点运行该智能合约,对自身的运行结果进行签名后返回给客户端(本文称之为“背书”),该客户端再按照区块链消息格式把该多个背书节点的多个运行结果封装到交易消息中,发送给共识服务节点,通过共识服务节点以区块为单位将其广播到该区块链网络中的所有处理节点(包括上述多个背书节点),该区块链网络中的处理节点对接收到的交易进行校验,满足验证策略的交易才会被认为是有效交易,进而对数据进行修改,将更新后的数据写入区块链。这里,用户可以根据自己的实际需求通过客户端设置智能合约要信任的多个背书节点,并设置对该多个背书节点的验证策略,例如,用户A的背书节点可以为3个,用户A的客户端A向这3个背书节点发送模拟运行智能合约的请求,会收到对应的3个运行结果,验证策略可以为3个运行结果的内容必须一致,也可以为至少2个运行结果的内容一致。应理解,用户的验证策略需要提前被广播到该区块链网络中的所有处理节点。
实际运行过程中,整个区块链网络是分布式的,并且区块链网络中的每个处理节点都保存一份区块链的完整账本数据。但是由于数据同步会有先后顺序,背书节点在运行某个交易的智能合约时所访问的区块链数据,与该交易后续在该区块链网络中的每个处理节点上要写入本地账本时的数据很有可能会不一致,使得背书节点的背书失效,因此,需要一些机制来防止背书失效的交易写入账本。
现有技术为智能合约的每一个数据设置了一个自增的版本号,每次对数据进行更新就修 改一次版本号(例如,版本号加1)。背书节点在运行智能合约的时候,如果需要访问智能合约保存在区块链上的数据,就记录下需要访问的数据的版本号。该背书节点返回给客户端的运行结果中包含这些数据的版本号。客户端通过共识服务节点广播的交易消息中也会包含对应的数据的版本号,该区块链网络中的所有处理节点在对交易进行校验时,需要校验交易中数据的版本号是否与本地账本数据的版本号一致,在一致的情况下,确认该交易为有效交易,对本地账本数据进行更新。
但是,在区块链的数据变化比较频繁时,对于某个交易而言,背书节点在运行智能合约时的访问的本地账本中的数据版本号,与该交易通过共识服务节点广播到区块链网络中的所有处理节点进行验证时各个处理节点的数据版本号很有可能不一致,导致该交易无效。在这种情况下,客户端只好重新发起交易,直到数据版本号一致后交易合法写入账本为止。有鉴于此,本申请实施例提出了一种新的运行智能合约的方法。
图1示出了本申请实施例的网络架构100。如图1所示,该网络架构100包括客户端和网络侧,网络侧为分布式网络,分布式网络是由多个节点组成的对等(peer to peer,p2p)网络,该网络是由分布在不同地点且具有多个终端的节点相互连接组成的。网络中任一节点均至少与两条线路相连,当任意一条线路发生故障时,通信可转经其他链路完成,具有较高的可靠性,同时易于扩充。上述客户端可以通过分布式网络中的节点与网络侧进行通信,从而实现相应的业务需求。
在客户端和网络侧进行通信的过程中,可以根据节点所具有的功能,为不同的节点赋予不同的角色,下面首先介绍一下本申请实施例中所涉及的客户端以及网络侧节点。
(1)客户端:客户端可以根据用户的需求,向用户的背书节点发送模拟运行智能合约的请求,接收背书节点发送的运行结果,并对运行结果进行验证。
(2)处理节点:分布式网络中的基本节点,保存有区块链的一份完整的账本数据,并对本地保存的账本数据进行管理。应理解,一份账本数据通常需要多个处理节点共同进行维护。具体地,处理节点可以接收共识服务节点广播的交易集合,验证交易合法性,在交易合法的前提下修改本地账本数据。
(2)代理节点:具有代理功能的处理节点,代理节点可以代理客户端向背书节点发送模拟运行智能合约的请求,并代理客户端接收背书节点发送的运行结果,并对运行结果进行验证,在运行结果通过验证的情况下,将满足验证策略的运行结果发送给客户端。
(3)背书节点:具有背书功能的处理节点,背书节点一般是一些具有公信力的机构(例如,政府、银行和大型公司等)运行的节点。该背书节点可以接收客户端或代理节点发送的模拟运行智能合约的请求,运行智能合约,并对该智能合约的运行结果进行“背书”,再将该智能合约的运行结果返回给客户端或代理节点。应理解,“背书”即背书节点对自身的智能合约的运行结果内容进行签名,保证该运行结果的合法性。
(4)共识服务节点:用于进行区块的共识服务,主要功能是接收客户端或代理节点发送的交易,根据一定的规则,确定某个区块中应该包含的交易集合(并不对交易的合法性做验证),并确定该交易集合中多个交易的顺序,然后广播该交易集合到该分布式网络中的所有节点(包括背书节点)。应理解,共识服务节点可以是一个节点,也可以是由多个节点组成的集群。
图1示例性地示出了两个客户端以及分布式网络中的节点,包括:客户端110、客户端120、处理节点130-处理节点180以及共识服务节点190。在一个可选的实施例中,该分布 式网络可以是区块链网络,但本申请实施例对此不作限定。
下面,以处理节点130、处理节点140和处理节点150为背书节点,处理节点160为客户端120的代理节点为例进行说明。
应理解,用户将哪些节点作为自己的背书节点可以是用户通过客户端提前预设的,例如,客户端110的背书节点为处理节点130和处理节点140,客户端120的背书节点为处理节点130和处理节点150,本申请实施例对此不作限定。对于一个客户端而言,可以具有代理节点,也可以没有代理节点,例如,在上述网络架构100中,处理节点160为客户端120的代理节点,而客户端110并不具有代理节点,本申请实施例对此也不作限定。
还应理解,图1示例性地示出了两个客户端和部分处理节点,可选地,该网络架构100可以包括其它数量的客户端以及其他数量的处理节点,本申请实施例对此不做限定。
上述网络架构100中的各种处理节点的程序基本一样,仅仅因为运行时的角色不同,被划分成不同种类的节点而已。该网络架构100中的处理节点可以根据角色的不同开启或关闭相应的模块,本申请实施例对此不作限定。
在运行某一智能合约时,客户端可以先向多个背书节点发送模拟运行智能合约的请求,模拟运行该智能合约,该多个背书节点运行该智能合约,对自身的运行结果进行背书后返回给客户端,该客户端再按照区块链消息格式把该多个背书节点的多个运行结果封装到交易消息中,发送给共识服务节点,通过共识服务节点以区块为单位将其广播到该分布式网络中的所有处理节点,该分布式网络中的处理节点对接收到的交易进行校验,满足验证策略的交易才会被认为是有效交易,进而对数据进行修改,将更新后的数据写入区块链。
正如前面所提到的,在区块链的数据变化比较频繁时,对于某个交易而言,背书节点在运行智能合约时的访问的本地账本中的数据版本号,与该交易通过共识服务节点广播到分布式网络中的所有处理节点进行验证时各个处理节点的数据版本号很有可能不一致,导致该交易无效。在这种情况下,客户端只好重新发起交易,直到数据版本号一致后交易合法写入账本为止。
由于智能合约中常用的一部分代码逻辑(本文称为限定条件)需要读取区块链中保存的数据,然后根据这些数据及智能合约的这部分代码逻辑进行条件判断。这些数据一般是判断智能合约能够正常执行的前置条件。如果这些数据变化比较频繁,经常会出现无效交易或者重试。因此,本申请的主要思路就是对于区块链中修改比较频繁的数据(即限定条件对应的数据),提供一种机制,使得多个背书节点在运行区块链时忽略这部分数据,从而使多个运行结果更容易达成一致,同时在网络中的处理节点验证交易并将交易最终写入账本之前,再根据该处理节点的本地账本数据来校验这部分数据,如果满***易成立条件的话,仍然可以接受交易对数据的修改,即将限定条件的判断逻辑后置,从而提高在数据变化比较频繁时,交易的写入成功率,提高***的整体性能。
下面结合图2和图3对本申请实施例进行详细地说明。
图2示出了本申请实施例的运行智能合约的方法的示意性流程图200。该方法200可以应用于图1所示的网络架构100,但本申请实施例不限于此。应理解,运行智能合约一般包括背书阶段和交易阶段。
具体地,S201-S206为背书阶段,包括:
S201,客户端110分别向多个处理节点(背书节点)发送模拟运行智能合约的请求,该请求中包括该智能合约的标识信息;则对应地,该多个处理节点(背书节点)分别接收该请 求;
具体地,以该客户端110仅具有两个背书节点(处理节点130和处理节点140)为例进行说明,在这种情况下,如图2所示,S201可以包括S201a和S201b,S201a和S201b可以分开执行,也可以同时执行,本申请实施例对此不作限定。
S202,处理节点130根据该请求,运行该智能合约并对运行结果进行背书,得到本次背书的运行结果;
具体地,该处理节点130可以识别该智能合约的限定条件,并基于该处理节点130的本地账本数据运行该智能合约中除该限定条件之外的其它程序并进行签名,得到本次背书的运行结果;应理解,该处理节点130可以运行该智能合约中的全部程序,也可以仅运行该智能合约中除该限定条件之外的其他程序,本申请实施例对此不作限定。
S203,处理节点140根据该请求,运行该智能合约并对运行结果进行背书,得到本次背书的运行结果;
具体地,该处理节点140可以识别该智能合约的限定条件,并基于该处理节点140的本地账本数据运行该智能合约中除该限定条件之外的其它程序并进行签名,得到本次背书的运行结果;应理解,该处理节点140可以运行该智能合约中的全部程序,也可以仅运行该智能合约中除该限定条件之外的其他程序,本申请实施例对此不作限定。
S204,上述多个处理节点(包括处理节点130和处理节点140)向客户端110发送多个本次背书的运行结果;则对应地,该客户端110接收该多个处理节点发送的本次背书的运行结果;
具体地,如图2所示,S204可以包括S204a和S204b,由于每个背书节点对智能合约的处理速度不同,S204a和S204b的执行可以按照任意顺序,本申请实施例对此不作限定。
S205-S211为交易阶段,包括:
S205,客户端110判断上述多个运行结果是否满足验证策略,并将满足验证策略的运行结果封装到交易中;
由于客户端110接收多个运行结果存在先后顺序,且该验证策略一般包括合法性验证和一致性验证,该客户端110对上述多个运行结果的验证可以采用多种验证方式。
在一种可选的实施例中,该客户端110可以先确定上述多个运行结果中签名合法的运行结果的数量是否超过预设值(即验证运行结果的合法性),然后在通过合法性验证的运行结果中确定数据和版本号相同的运行结果的数量是否超过预设值(即验证剩余运行结果的一致性);
在另一种可选的实施例中,该客户端110可以每收到一个运行结果就检测该运行结果的签名是否合法,如果该运行结果的签名合法,则记录该运行结果的数据和版本号,签名验证不合法则不记录。当该客户端110收到的签名合法的运行结果中,数据和版本号相同的运行结果的数量超过预设值时,该客户端110确定该运行结果满足验证策略。
S206,客户端110向共识服务节点190发送上述交易;则对应地,该共识服务节点190接收该交易;
S207,该共识服务节点190按照一定的规则,将一段时间内积累的包括交易A的多个交易按照顺序打包成一个交易集合;
S208,该共识服务节点190向分布式网络中的所有处理节点广播上述交易集合;
应理解,图2仅仅示出了部分处理节点,但这不应对本申请的实施例构成任何限定。在 图2中,S208可以包括S208a、S208b、S208c以及S208d,则对应地,处理节点130接收该交易集合,处理节点140接收该交易集合,处理节点170接收该交易集合,处理节点180接收该交易集合。
为了便于理解和说明,在本申请实施例中,以该分布式网络中的处理节点170为例,应理解,上述所有处理节点中除该处理节点170外的其他处理节点对该交易的下述处理步骤与该处理节点170相同,此处不再赘述。
S209,该处理节点170检查该交易中的多个运行结果是否满足验证策略,这里的检查是指对上述多个运行结果中由除该智能合约的限定条件之外的其他程序产生的数据和版本号的检查,该限定条件用于表示运行该智能合约时该分布式网络中的账本数据需要满足的条件;
具体地,限定条件的代码一般为智能合约中修改比较频繁的数据对应的需要满足某种条件的代码,该处理节点170接收到的多个运行结果可以分为两种情况:
(1)该多个运行结果为该智能合约的所有程序被运行产生的结果,即该多个运行结果均包括了运行该智能合约的限定条件的程序所产生的数据和版本号,在这种情况下,该处理节点170可以忽略该多个运行结果中与该限定条件相关的数据和版本号,仅检查除该限定条件之外的其他程序产生的数据和版本号;
(2)该多个运行结果为运行除上述限定条件之外的其他程序产生的数据和版本号,在这种情况下,该处理节点170可以直接对该多个运行结果进行检查。
因此,无论该多个运行结果中是否包括运行上述限定条件的程序产生的数据和版本号,该处理节点170在进行检查时,都需要仅仅检查由除该限定条件之外的其他程序产生的数据和版本号。
应理解,用户可以根据自己的实际需求通过客户端设置上述智能合约要信任的多个背书节点,并设置对该多个背书节点的验证策略,该验证策略可以包括对多个运行结果的一致性验证。一致性验证可以是在数据和版本号相同的运行结果的数量满足预设值时,认为该多个运行结果通过一致性验证。例如,上述客户端预设的背书节点为3个,对应的验证策略可以为3个运行结果的数据和版本号必须一致,也可以为至少2个运行结果的数据和版本号一致,本申请实施例对此不作限定。
可选地,由于上述多个运行结果是由背书节点进行签名之后生成的,上述验证还可以包括对多个运行结果的合法性进行验证。合法性验证可以是多个运行结果的签名合法的运行结果的数量满足预设值,即认为该多个运行结果通过合法性验证,但本申请实施例对此不作限定。此外,该处理节点170一般需要先对多个运行结果的合法性进行验证,在签名合法的剩余运行结果中再对多个运行结果的一致性进行验证,但本申请实施例对此不作限定。
S210,在上述多个运行结果满足验证策略的情况下,该处理节点170识别该智能合约中的限定条件,确定本地账本数据是否满足该限定条件;
具体地,该处理节点170可以在该多个运行结果满足验证策略(即通过合法性验证和一致性验证)的情况下,确定该智能合约中的限定条件,再确定本地账本数据是否满足该限定条件。应理解,若该多个运行结果不满足上述验证策略,该处理节点170可以直接认为该交易为无效交易,拒绝对本地账本数据进行修改。
应理解,该智能合约的限定条件为背书节点根据智能合约的代码预先解析出来的,背书节点将该限定条件的代码发送给客户端或代理节点,再由代理节点或客户端将该限定条件的 代码通过交易记录到分布式网络中的所有节点中。因此,处理节点170能够识别该智能合约的限定条件。
S211,在该处理节点170的本地账本数据满足该限定条件的情况下,该处理节点170接受该交易。
具体地,该处理节点170可以在本地账本数据满足限定条件的情况下,任务该交易为有效交易,进一步地,该处理节点170可以根据该多个运行结果,修改该处理节点170的本地账本数据。应理解,若该处理节点170的本地账本数据不满足上述限定条件,该处理节点170可以确定该交易为无效交易,拒绝对本地账本数据进行修改。
应理解,该处理节点170接收该交易集合,按照该多个交易的顺序,依次进行处理。由于该多个交易中每个交易的处理方式都与S209-S211中一个交易的处理方式相同,此处不再赘述。
作为一个可选的实施例,在S201之前,上述方法还包括:客户端110向所述多个背书节点(即处理节点130和处理节点140)发送智能合约的程序;该多个背书节点接收该智能合约的程序,对该智能合约的程序进行解析,并将该智能合约的限定条件的代码发送给该客户端110;该客户端110接收该限定条件的代码,通过一个交易将该智能合约的限定条件的代码发送给该分布式网络中的所有处理节点。应理解,通过一个交易将一段代码记入到所有处理节点中是现有技术,因此本文不再赘述。
在本申请实施例中,分布式网络中的所有处理节点在按照验证策略对交易的多个运行结果进行验证时,先忽略对变化较频繁的数据对应的限定条件的验证,在多个运行结果中除限定条件之外的数据和版本号满足验证策略之后,再验证本地账本数据是否满足限定条件,在本地账本数据满足限定条件的情况下,接受该交易。因为在分布式网络的数据变化比较频繁时,对于某个交易而言,背书节点在运行智能合约时的访问的本地账本中的数据和版本号,与该交易通过共识服务节点广播到分布式网络中的所有处理节点进行验证时各个节点的数据和版本号很有可能不一致,在这种情况下,客户端只好重新发起交易,而本申请实施例的方式,避免了由于数据修改比较频繁导致客户端不断重试的情况。
因此,本申请实施例的运行智能合约的方法,通过将变化较频繁的数据对应的限定条件的验证后置,在交易的多个运行结果中除该限定条件之外的数据和版本号满足验证策略之后,再验证本地账本数据是否满足该限定条件,有利于提高交易写入账本的成功率,从而有利于提高***的整体性能。
应理解,上述各过程的序号的大小并不意味着执行顺序的先后,各过程的执行顺序应以其功能和内在逻辑确定,而不应对本申请实施例的实施过程构成任何限定。
以下,为了便于理解和说明,不失一般性,以客户端120存在代理节点(即处理节点160)为例进行说明。
图3示出了本申请实施例的另一运行智能合约的方法的示意性流程图300。该方法300可以应用于图1所示的网络架构100,但本申请实施例不限于此。
S301,客户端120向处理节点160发送模拟运行智能合约的请求,该请求中包括该智能合约的标识信息;则对应地,该处理节点160接收该请求;
S302,该处理节点160分别向多个处理节点(背书节点)发送模拟运行智能合约的请求;则对应地,该多个处理节点(背书节点)分别接收该请求;
具体地,以该客户端120仅具有两个背书节点(处理节点130和处理节点150)为例进 行说明,在这种情况下,如图3所示,S302可以包括S302a和S302b,S302a和S302b可以分开执行,也可以同时执行,本申请实施例对此不作限定。
S303,该处理节点130根据该请求,运行该智能合约并对运行结果进行背书,得到本次背书的运行结果;
具体地,该处理节点130可以识别该智能合约的限定条件,并基于该处理节点130的本地账本数据运行该智能合约中除该限定条件之外的其它程序并进行签名,得到本次背书的运行结果;应理解,该处理节点130可以运行该智能合约中的全部程序,也可以仅运行该智能合约中除该限定条件之外的其他程序,本申请实施例对此不作限定。
S304,该处理节点140根据该请求,运行该智能合约并对运行结果进行背书,得到本次背书的运行结果;
具体地,该处理节点140可以识别该智能合约的限定条件,并基于该处理节点140的本地账本数据运行该智能合约中除该限定条件之外的其它程序并进行签名,得到本次背书的运行结果;应理解,该处理节点140可以运行该智能合约中的全部程序,也可以仅运行该智能合约中除该限定条件之外的其他程序,本申请实施例对此不作限定。
S305,上述多个处理节点(包括处理节点130和处理节点150)分别向处理节点160发送本次背书的运行结果;则对应地,该处理节点160接收多个运行结果;
具体地,如图3所示,S305可以包括S305a和S305b,由于每个背书节点对智能合约的处理速度不同,S305a和S305b的执行可以按照任意顺序,本申请实施例对此不作限定。
S306,处理节点160对收到的多个运行结果进行验证,判断多个运行结果是否满足验证策略;
由于处理节点160接收多个运行结果存在先后顺序,且该验证策略一般包括合法性验证和一致性验证,该处理节点160对上述多个运行结果的验证可以采用多种验证方式。
在一种可选的实施例中,该处理节点160可以先确定上述多个运行结果中签名合法的运行结果的数量是否超过预设值(即验证运行结果的合法性),然后在通过合法性验证的运行结果中确定数据和版本号相同的运行结果的数量是否超过预设值(即验证剩余运行结果的一致性);
在另一种可选的实施例中,该处理节点160可以每收到一个运行结果就检测该运行结果的签名是否合法,如果该运行结果的签名合法,则记录该运行结果的数据和版本号,签名验证不合法则不记录。当该处理节点160收到的签名合法的运行结果中,数据和版本号相同的运行结果的数量超过预设值时,该处理节点160确定该运行结果满足验证策略。
S307,在运行结果满足验证策略的情况下,该处理节点160向客户端120发送满足验证策略的运行结果;则对应地,该客户端120接收满足验证策略的运行结果;
S308,该客户端120将满足验证策略的运行结果封装成一个交易(例如交易A);
S309,该客户端120向处理节点160发送上述交易;则对应地,该处理节点160接收该交易;
S310,该处理节点160向共识服务节点190发送上述交易;则对应地,该共识服务节点190接收该交易;
S311,该共识服务节点190按照一定的规则,将一段时间内积累的包括交易A的多个交易按照顺序打包成一个交易集合;
S312,该共识服务节点190向分布式网络中的所有处理节点广播上述交易集合;
应理解,图3仅仅示出了部分处理节点,但这不应对本申请的实施例构成任何限定。在图3中,S312可以包括S312a、S312b、S312c、S312d以及S312e,则对应地,处理节点160接收该交易集合,处理节点130接收该交易集合,处理节点150接收该交易集合,处理节点170接收该交易集合,处理节点180接收该交易集合。
接下来,所有处理节点分别按顺序处理该交易集合中的多个交易,处理流程同S209-S211,此处不再赘述。
应理解,上述各过程的序号的大小并不意味着执行顺序的先后,各过程的执行顺序应以其功能和内在逻辑确定,而不应对本申请实施例的实施过程构成任何限定。
本申请实施例的运行智能合约的方法,通过将变化较频繁的数据对应的限定条件的验证后置,在交易的多个运行结果中除该限定条件之外的数据和版本号满足验证策略之后,再验证本地账本数据是否满足该限定条件,有利于提高交易写入账本的成功率,从而有利于提高***的整体性能。
作为一个可选的实施例,在S301之前,上述方法还包括:客户端120可以向其代理节点(即处理节点160)发送智能合约的程序;代理节点接收该智能合约的程序并将其发送给多个背书节点(即处理节点130和处理节点150);该多个背书节点接收该智能合约的程序,对该智能合约的程序进行解析,并将该智能合约的限定条件的代码发送给代理节点;该代理节点接收该限定条件的代码,将其返回给客户端120;该客户端120接收该限定条件的代码,再通过一个交易将该智能合约的限定条件的代码发送给该分布式网络中的所有处理节点。应理解,通过一个交易将一段代码记入到所有节点中是现有技术,因此本文不再赘述。
本申请实施例的运行智能合约的方法,通过将变化较频繁的数据对应的限定条件的验证后置,在交易的多个运行结果中除该限定条件之外的数据和版本号满足验证策略之后,再验证本地账本数据是否满足该限定条件,有利于提高交易写入账本的成功率,从而有利于提高***的整体性能。
应理解,在一种可能的实现方式中,本申请实施例的运行智能合约的上述方法具体可以应用于区块链网络,但本申请实施例对此不作限定。
下面以一个销售商品的智能合约为例对本申请实施例的运行智能合约的方法进行说明。该销售商品的智能合约中包括限定条件接口IfStateCondition,IfStateCondition中输入的是对保存在区块链中数据的条件判断。在本例中,IfStateCondition会检查购买者buyer的资金余额是否足够购买资产,检查拥有者owner资产的剩余数量是否可售,如果区块链中的数据满足上述条件,该智能合约中的资产购买过程才能够被执行,如果不满足,则无法执行资产购买操作。
本申请实施例中的智能合约伪码如下:
Figure PCTCN2018085748-appb-000003
Figure PCTCN2018085748-appb-000004
管理员或者智能合约提供方会通过客户端向多个背书节点发送一个运行上述智能合约的交易。该多个背书节点分别解析该智能合约的代码,获取智能合约的IfStateCondition函数,即智能合约的限定条件接口的代码(stub.Get(“BuyerId”,“Money”)>1&&stub.Get(“OwnerID”,“Asset_account”)>100)。该多个背书节点分别向该客户端返回上述限定条件接口的代码,该客户端将该智能合约的代码和该智能合约的限定条件接口的代码通过一个交易记入到该区块链网络的所有节点中。应理解,通过一个交易将一段代码记入到所有节点中是现有技术,因此本文不再赘述。
当用户A需要调用该智能合约的BuyOneAsset函数时,用户A通过客户端A向背书节点M和背书节点N发送模拟运行该智能合约的请求,该请求中包含了用户A请求调用的该智能合约的标识ID以及函数名(BuyOneAsset)。应理解,若用户A需要调用的函数为有参函数,该请求中还应该包括该有参函数的参数。
背书节点M和背书节点N分别收到该客户端发送的模拟运行上述智能合约的请求,并分别执行如下步骤:
根据该智能合约的ID从区块链账本中获取该智能合约的代码,在忽略其中的限制条件接口的代码的情况下运行该智能合约的代码,记录执行该智能合约的代码时访问的数据值以及版本号。应理解,最终的运行结果可以为不包含宽容数据集合之外的其他数据以及版本号,该宽容数据集合是指运行上述限定条件接口的代码时需要访问的数据及版本号,在本申请实施例中,宽容数据集合为BuyerId_Money和Owner_asset_account。
最终,背书节点M将运行结果M返回给用户A的客户端,背书节点N将运行结果N返回给用户A的客户端。
该客户端在收到所有背书节点发送来的运行结果之后,按照区块链消息格式把接收到的多个运行结果封装到一个交易中,并发送给共识服务节点。
可选的,该客户端可以对多个运行结果的数据及版本号进行对比,判断该多个运行结果是否满足验证策略,在该多个运行结果满足验证策略的情况下再将其封装并发送给共识服务节点。在本申请实施例中,验证策略设置为背书节点M和背书节点N返回的运行结果必须一致,即所有运行结果中的参数必须相同。
图4示出了本申请实施例的另一运行智能合约的方法的示意性流程图。
S410,共识服务节点向区块链网络中的所有节点广播客户端B的交易集合;
则对应地,背书节点M接收客户端B的交易集合,背书节点N接收客户端B的交易集合;
S420,客户端A分别向背书节点M和背书节点N发送模拟运行智能合约的请求,如图4所示,S420包括S420a和S420b,则对应地,背书节点M接收该请求,根据该请求基于本地账本数据运行该智能合约,得到本次背书的运行结果,背书节点N接收该请求,根据该请求基于本地账本数据运行该智能合约,得到本次背书的运行结果;
S430,该背书节点M和该背书节点N分别向客户端A发送本次背书的运行结果;则对应地,客户端A接收多个本次背书的运行结果。
由于网络有延迟,当背书节点M收到客户端B的交易集合,对该交易集合中的数据进行验证,并修改了本地账本数据时,背书节点N并未收到客户端B的交易集合。因此,背书节点M运行客户端A的智能合约所使用的本地账本数据与背书节点N运行客户端A的智能合约所使用的本地账本数据不一致。因此,若采用现有技术,背书节点M和背书节点N的账本中Owner_asset_account的数据版本号不一致,具体涉及到的账本数据如下:
表一:背书节点M的账本
Figure PCTCN2018085748-appb-000005
表二:背书节点N的账本
Figure PCTCN2018085748-appb-000006
这样,用户A的交易无效,客户端需要重新发起该笔交易。
而采用本申请的运行智能合约的方法,除去宽容数据集合(BuyerId_Money和Owner_asset_account)之外,收集到的数据及版本号如下:
表三:背书节点M的账本
Figure PCTCN2018085748-appb-000007
表四:背书节点N的账本
Figure PCTCN2018085748-appb-000008
Figure PCTCN2018085748-appb-000009
由于背书节点M的账本与背书节点N的账本相同,因此结果为SUCCESS。客户端确定背书节点M和背书节点N的运行结果满足验证策略,将其封装在一个交易消息中并发送给上述共识服务节点。
该共识服务节点收集一段时间内的交易,形成一个区块,该区块中包括按序组成交易集合,该共识服务节点广播该交易集合至区块链网络中的所有节点,所有节点中的每个节点分别对该交易集合中的交易按顺序逐条进行处理。
为了便于理解和说明,不失一般性,此处仍以区块链网络中的任一处理节点为例,处理节点接收到广播的交易集合后,从该交易集合中按顺序逐条处理交易。假设该交易集合中含有同一时刻不同用户A、C、D分别发送的三条交易Tx1、Tx2、Tx3,都是购买资产的交易,且因为时间相同,所以它们的运行结果也是相同的,即交易集合中按照交易的先后顺序包含如下交易:
表五:交易集合
Figure PCTCN2018085748-appb-000010
(1)处理Tx1
处理节点在处理Tx1时,首先判断运行结果M和N是否满足验证策略,即Tx1中的endorsementM和endorsementN中运行结果及对数据的修改是否相同。在本申请实施例中,运行结果M和N如表三和表四所示,满足验证策略。
然后,该处理节点查看本地账本数据中的版本号与Tx1(即Tx1的endorsementM和endorsementN)的数据版本号是否一致。经检查,本地账本数据与Tx1的数据版本号一致。
最后,该处理节点根据CCID获取该智能合约的限定条件接口的代码,具体代码为:stub.Get(“BuyerId”,“Money”)>1&&stub.Get(“OwnerID”,“Asset_account”)>100。该处理节点根据本地账本数据,运行该智能合约的限定条件接口的代码,运行结果为真,接受Tx1对数据的修改,并将修改的数据的版本号增1,相关数据及版本号变为:
表六:接受Tx1后的账本数据
Key Version Value
Owner_money 102 4400
Owner_asset_account 102 1
UserA_money 56 500
UserA_asset_account 2 1
UserC_money 30 900
UserC_asset_account 1 0
(2)处理Tx2
处理节点首先判断运行结果M和N是否满足验证策略,即Tx2中的endorsementM和endorsementN中运行结果及对数据的修改是否相同。在本申请实施例中,运行结果M和N相同,满足验证策略。
然后,该处理节点查看本地账本数据中的版本号与Tx2(即Tx2的endorsementM和endorsementN)的数据版本号是否一致。经检查,本地账本数据与Tx2的数据版本号一致。
最后,该处理节点根据CCID获取该智能合约的限定条件接口的代码,具体代码为:stub.Get(“BuyerId”,“Money”)>1&&stub.Get(“OwnerID”,“Asset_account”)>100。该处理节点根据本地账本数据,运行该智能合约的限定条件接口的代码,运行结果为真,接受Tx2对数据的修改,并将修改的数据的版本号增1,相关数据及版本号变为:
表七:接受Tx2后的账本数据
Key Version Value
Owner_money 103 4500
Owner_asset_account 103 0
UserA_money 56 500
UserA_asset_account 2 1
UserC_money 31 800
UserC_asset_account 2 1
(3)处理Tx3
处理节点首先判断运行结果M和N是否满足验证策略,即Tx3中的endorsementM和endorsementN中运行结果及对数据的修改是否相同。在本申请实施例中,运行结果M和N相同,满足验证策略。
然后,该处理节点查看本地账本数据中的版本号与Tx3(即Tx3的endorsementM和endorsementN)的数据版本号是否一致。经检查,本地账本数据与Tx3的数据版本号一致。
最后,该处理节点根据CCID获取该智能合约的限定条件接口的代码,具体代码为:stub.Get(“BuyerId”,“Money”)>1&&stub.Get(“OwnerID”,“Asset_account”)>100。该处理节点根据本地账本数据,运行该智能合约的限定条件接口的代码,此时Owner_asset_account为0,因此交易Tx3不能通过限定条件接口的验证,该处理节点将Tx3记录为无效交易,不接受其对数据的修改。
应理解,上述各过程的序号的大小并不意味着执行顺序的先后,各过程的执行顺序应以其功能和内在逻辑确定,而不应对本申请实施例的实施过程构成任何限定。
上文中结合图1至图4,详细描述了根据本申请实施例的运行智能合约的方法,下面将结合图5至图8,详细描述根据本申请实施例的运行智能合约的装置。
图5示出了本申请实施例提供的运行智能合约的装置500的示意性框图。如图5所示,该装置500包括:接收单元510、检查单元520、确定单元530以及处理单元540。
其中,接收单元510,用于接收共识服务节点发送的交易,所述交易包括在智能合约的背书过程中产生的多个运行结果;
检查单元520,用于检查所述多个运行结果是否满足验证策略,所述检查包括对所述多个运行结果中由除所述智能合约的限定条件之外的其他程序产生的数据和版本号的检查,所述限定条件用于表示运行所述智能合约时所述分布式网络中的账本数据需要满足的条件;
确定单元530,用于在所述多个运行结果满足所述验证策略的情况下,识别所述智能合约中的限定条件,确定本地账本数据是否满足所述限定条件;
处理单元540,用于在所述本地账本数据满足所述限定条件的情况下,接受所述交易。
本申请实施例的运行智能合约的装置,通过将变化较频繁的数据对应的限定条件的验证后置,在交易的多个运行结果中除该限定条件之外的数据和版本号满足验证策略之后,再验证本地账本数据是否满足该限定条件,有利于提高交易写入账本的成功率,从而有利于提高***的整体性能。
可选地,所述装置500为背书节点,所述装置500还包括:背书单元,用于在所述接收共识服务节点发送的交易之前,对所述智能合约进行背书,得到本次背书的运行结果;第一发送单元,用于将所述本次背书的运行结果发送给需要在交易中使用所述本次背书的运行结果的客户端或所述客户端的代理节点。
可选地,所述接收单元510还用于:接收客户端或所述客户端的代理节点发送的模拟运行所述智能合约的请求,所述请求包括所述智能合约的标识信息;所述背书单元用于在所述接收共识服务节点发送的交易之前,对所述智能合约进行背书,得到本次背书的运行结果,具体包括:根据所述智能合约的标识信息,识别所述智能合约中的所述限定条件;基于所述本地账本数据运行所述智能合约中除所述限定条件之外的其它程序并进行签名,得到所述本次背书的运行结果。
可选地,所述接收单元510还用于:在所述对所述智能合约进行背书,得到本次背书的运行结果之前,接收所述客户端或所述客户端的代理节点发送的所述智能合约的程序;所述装置500还包括:解析单元,用于解析所述智能合约的程序,获得所述限定条件的程序;所述第一发送单元还用于:向所述客户端或所述客户端的代理节点发送所述限定条件的程序。
可选地,所述装置500为代理节点,所述装置500还包括:第二发送单元,用于在所述接收共识服务节点发送的交易之前,向所述分布式网络中的多个背书节点发送模拟运行所述智能合约的请求,所述请求包括所述智能合约的标识信息;所述接收单元510还用于:接收所述多个背书节点根据所述请求发送的各自的运行结果;所述检查单元520还用于:检查接收到的所述多个运行结果是否满足所述验证策略,所述检查包括对所述多个运行结果中由除所述限定条件之外的其他程序产生的数据和版本号的检查;所述第二发送单元还用于:在所述多个运行结果满足所述验证策略的情况下,向客户端发送所述多个运行结果。
可选地,所述第二发送单元还用于:在所述向所述分布式网络中的多个背书节点发送模 拟运行所述智能合约的请求之前,向所述多个背书节点发送所述智能合约的程序;所述接收单元510还用于:接收所述多个背书节点根据所述智能合约的程序发送的所述限定条件的程序;所述第二发送单元还用于:向所述分布式网络中的所有处理节点发送所述限定条件的程序。
应理解,这里的装置500以功能单元的形式体现。这里的术语“单元”可以指应用特有集成电路(application specific integrated circuit,ASIC)、电子电路、用于执行一个或多个软件或固件程序的处理器(例如共享处理器、专有处理器或组处理器等)和存储器、合并逻辑电路和/或其它支持所描述的功能的合适组件。在一个可选例子中,本领域技术人员可以理解,装置500可以具体为上述方法实施例中的分布式网络中的处理节点,装置500可以用于与执行上述方法实施例的处理节点对应的各个流程和/或步骤,为避免重复,在此不再赘述。
图6示出了本申请实施例提供的另一运行智能合约的装置600的示意性框图。如图6所示,该装置600包括:发送单元610、接收单元620以及检查单元630。
其中,发送单元610,用于向分布式网络中的多个背书节点发送模拟运行智能合约的请求,所述请求包括所述智能合约的标识信息;
接收单元620,用于接收所述多个背书节点根据所述请求发送的各自的运行结果;
检查单元630,用于检查接收到的多个运行结果是否满足验证策略,所述检查包括对所述多个运行结果中由除所述智能合约的限定条件之外的其他程序产生的数据和版本号的检查,所述限定条件用于表示运行所述智能合约时所述分布式网络中的账本数据需要满足的条件;
所述发送单元610还用于:在所述多个运行结果满足所述验证策略的情况下,向共识服务节点发送包括所述多个运行结果的交易。
本申请实施例的运行智能合约的装置,通过将变化较频繁的数据对应的限定条件的验证后置,在交易的多个运行结果中除该限定条件之外的数据和版本号满足验证策略之后,再验证本地账本数据是否满足该限定条件,有利于提高交易写入账本的成功率,从而有利于提高***的整体性能。
可选地,所述发送单元610还用于:在所述向分布式网络中的多个背书节点发送模拟运行智能合约的请求之前,向所述多个背书节点发送所述智能合约的程序;所述接收单元620还用于:接收所述多个背书节点根据所述智能合约的程序发送的所述限定条件的程序;所述发送单元610还用于:向所述分布式网络中的所有处理节点发送所述限定条件的程序。
应理解,这里的装置600以功能单元的形式体现。这里的术语“单元”可以指应用特有集成电路(application specific integrated circuit,ASIC)、电子电路、用于执行一个或多个软件或固件程序的处理器(例如共享处理器、专有处理器或组处理器等)和存储器、合并逻辑电路和/或其它支持所描述的功能的合适组件。在一个可选例子中,本领域技术人员可以理解,装置600可以具体为上述方法实施例中的客户端,装置600可以用于与执行上述方法实施例的客户端对应的各个流程和/或步骤,为避免重复,在此不再赘述。
图7示出了本申请实施例提供的另一运行智能合约的装置700的示意性框图。该装置700包括处理器710、收发器720和存储器730。其中,处理器710、收发器720和存储器730通过内部连接通路互相通信,该存储器730用于存储指令,该处理器710用于执行该存储器730存储的指令,以控制该收发器720发送信号和/或接收信号。
其中,该收发器720用于接收共识服务节点发送的交易,所述交易包括在智能合约的背 书过程中产生的多个运行结果;
该处理器710用于检查所述多个运行结果是否满足验证策略,所述检查包括对所述多个运行结果中由除所述智能合约的限定条件之外的其他程序产生的数据和版本号的检查,所述限定条件用于表示运行所述智能合约时所述分布式网络中的账本数据需要满足的条件;在所述多个运行结果满足所述验证策略的情况下,识别所述智能合约中的限定条件,确定本地账本数据是否满足所述限定条件;在所述本地账本数据满足所述限定条件的情况下,接受所述交易。
应理解,装置700可以具体为上述方法实施例中的分布式网络中的处理节点,并且可以用于执行上述方法实施例中处理节点对应的各个步骤和/或流程。可选地,该存储器730可以包括只读存储器和随机存取存储器,并向处理器提供指令和数据。存储器的一部分还可以包括非易失性随机存取存储器。例如,存储器还可以存储设备类型的信息。该处理器710可以用于执行存储器中存储的指令,并且当该处理器710执行存储器中存储的指令时,该处理器710用于执行与上述方法实施例的各个步骤和/或流程。
图8示出了本申请实施例提供的另一运行智能合约的装置800的示意性框图。该装置800包括处理器810、收发器820和存储器830。其中,处理器810、收发器820和存储器830通过内部连接通路互相通信,该存储器830用于存储指令,该处理器810用于执行该存储器830存储的指令,以控制该收发器820发送信号和/或接收信号。
其中,该收发器820用于向分布式网络中的多个背书节点发送模拟运行智能合约的请求,所述请求包括所述智能合约的标识信息;接收所述多个背书节点根据所述请求发送的各自的运行结果;
该处理器810用于检查接收到的多个运行结果是否满足验证策略,所述检查包括对所述多个运行结果中由除所述智能合约的限定条件之外的其他程序产生的数据和版本号的检查,所述限定条件用于表示运行所述智能合约时所述分布式网络中的账本数据需要满足的条件;
该收发器820还用于:在所述多个运行结果满足所述验证策略的情况下,向共识服务节点发送包括所述多个运行结果的交易。
应理解,装置800可以具体为上述方法实施例中的客户端,并且可以用于执行上述方法实施例的客户端对应的各个步骤和/或流程。可选地,该存储器830可以包括只读存储器和随机存取存储器,并向处理器提供指令和数据。存储器的一部分还可以包括非易失性随机存取存储器。例如,存储器还可以存储设备类型的信息。该处理器810可以用于执行存储器中存储的指令,并且当该处理器810执行存储器中存储的指令时,该处理器810用于执行与上述实施例的客户端对应的各个步骤和/或流程。
应理解,在本申请实施例中,上述装置的处理器可以是中央处理单元(central processing unit,CPU),该处理器还可以是其他通用处理器、数字信号处理器(digital signal processing,DSP)、专用集成电路(application specific integrated circuit,ASIC)、现场可编程门阵列(field-programmable gate array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。
在实现过程中,上述方法的各步骤可以通过处理器中的硬件的集成逻辑电路或者软件形式的指令完成。结合本申请实施例所公开的方法的步骤可以直接体现为硬件处理器执行完成,或者用处理器中的硬件及软件单元组合执行完成。软件单元可以位于随机存储器,闪存、 只读存储器,可编程只读存储器或者电可擦写可编程存储器、寄存器等本领域成熟的存储介质中。该存储介质位于存储器,处理器执行存储器中的指令,结合其硬件完成上述方法的步骤。为避免重复,这里不再详细描述。
应理解,说明书通篇中提到的“一个实施例”或“一实施例”意味着与实施例有关的特定特征、结构或特性包括在本申请的至少一个实施例中。因此,在整个说明书各处出现的“在一个实施例中”或“在一实施例中”未必一定指相同的实施例。此外,这些特定的特征、结构或特性可以任意适合的方式结合在一个或多个实施例中。应理解,在本申请的各种实施例中,上述各过程的序号的大小并不意味着执行顺序的先后,各过程的执行顺序应以其功能和内在逻辑确定,而不应对本申请实施例的实施过程构成任何限定。
另外,本文中术语“***”和“网络”在本文中常被可互换使用。本文中术语“和/或”,仅仅是一种描述关联对象的关联关系,表示可以存在三种关系,例如,A和/或B,可以表示:单独存在A,同时存在A和B,单独存在B这三种情况。另外,本文中字符“/”,一般表示前后关联对象是一种“或”的关系。
应理解,在本申请实施例中,“与A相应的B”表示B与A相关联,根据A可以确定B。但还应理解,根据A确定B并不意味着仅仅根据A确定B,还可以根据A和/或其它信息确定B。
本领域普通技术人员可以意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、计算机软件或者二者的结合来实现,为了清楚地说明硬件和软件的可互换性,在上述说明中已经按照功能一般性地描述了各示例的组成及步骤。这些功能究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请的范围。
所属领域的技术人员可以清楚地了解到,为了描述的方便和简洁,上述描述的***、装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。
在本申请所提供的几个实施例中,应该理解到,所揭露的***、装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个***,或一些特征可以忽略,或不执行。另外,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口、装置或单元的间接耦合或通信连接,也可以是电的,机械的或其它的形式连接。
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本申请实施例方案的目的。
另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以是两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。
所述集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分,或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是 个人计算机,服务器,或者网络设备等)执行本申请各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(read-only memory,ROM)、随机存取存储器(random access memory,RAM)、磁碟或者光盘等各种可以存储程序代码的介质。
以上所述,仅为本申请的具体实施方式,但本申请的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本申请揭露的技术范围内,可轻易向到各种等效的修改或替换,这些修改或替换都应涵盖在本申请的保护范围之内。因此,本申请的保护范围应以权利要求的保护范围为准。

Claims (16)

  1. 一种运行智能合约的方法,其特征在于,应用于分布式网络中,所述方法包括:
    所述分布式网络中的处理节点接收共识服务节点发送的交易,所述交易包括在智能合约的背书过程中产生的多个运行结果;
    所述处理节点检查所述多个运行结果是否满足验证策略,所述检查包括对所述多个运行结果中由除所述智能合约的限定条件之外的其他程序产生的数据和版本号的检查,所述限定条件用于表示运行所述智能合约时所述分布式网络中的账本数据需要满足的条件;
    在所述多个运行结果满足所述验证策略的情况下,所述处理节点识别所述智能合约中的限定条件,确定本地账本数据是否满足所述限定条件;
    在所述本地账本数据满足所述限定条件的情况下,所述处理节点接受所述交易。
  2. 根据权利要求1所述的方法,其特征在于,所述处理节点为背书节点,在所述处理节点接收共识服务节点发送的交易之前,所述方法还包括:
    所述处理节点对所述智能合约进行背书,得到本次背书的运行结果;
    所述处理节点将所述本次背书的运行结果发送给需要在交易中使用所述本次背书的运行结果的客户端或所述客户端的代理节点。
  3. 根据权利要求2所述的方法,其特征在于,所述处理节点对所述智能合约进行背书,得到本次背书的运行结果,包括:
    所述处理节点接收客户端或所述客户端的代理节点发送的模拟运行所述智能合约的请求,所述请求包括所述智能合约的标识信息;
    所述处理节点根据所述智能合约的标识信息,识别所述智能合约中的所述限定条件;
    所述处理节点基于所述本地账本数据运行所述智能合约中除所述限定条件之外的其它程序并进行签名,得到所述本次背书的运行结果。
  4. 根据权利要求2或3所述的方法,其特征在于,在所述处理节点对所述智能合约进行背书,得到本次背书的运行结果之前,所述方法还包括:
    所述处理节点接收所述客户端或所述客户端的代理节点发送的所述智能合约的程序;
    所述处理节点解析所述智能合约的程序,获得所述限定条件的程序;
    所述处理节点向所述客户端或所述客户端的代理节点发送所述限定条件的程序。
  5. 根据权利要求1所述的方法,其特征在于,所述处理节点为代理节点,在所述处理节点接收共识服务节点发送的交易之前,所述方法还包括:
    所述处理节点向所述分布式网络中的多个背书节点发送模拟运行所述智能合约的请求,所述请求包括所述智能合约的标识信息;
    所述处理节点接收所述多个背书节点根据所述请求发送的各自的运行结果;
    所述处理节点检查接收到的所述多个运行结果是否满足所述验证策略,所述检查包括对所述多个运行结果中由除所述限定条件之外的其他程序产生的数据和版本号的检查;
    在所述多个运行结果满足所述验证策略的情况下,所述处理节点向客户端发送所述多个运行结果。
  6. 根据权利要求5所述的方法,其特征在于,在所述处理节点向所述分布式网络中的多个背书节点发送模拟运行所述智能合约的请求之前,所述方法还包括:
    所述处理节点向所述多个背书节点发送所述智能合约的程序;
    所述处理节点接收所述多个背书节点根据所述智能合约的程序发送的所述限定条件的 程序;
    所述处理节点向所述分布式网络中的所有处理节点发送所述限定条件的程序。
  7. 一种运行智能合约的方法,其特征在于,包括:
    客户端向分布式网络中的多个背书节点发送模拟运行智能合约的请求,所述请求包括所述智能合约的标识信息;
    所述客户端接收所述多个背书节点根据所述请求发送的各自的运行结果;
    所述客户端检查接收到的多个运行结果是否满足验证策略,所述检查包括对所述多个运行结果中由除所述智能合约的限定条件之外的其他程序产生的数据和版本号的检查,所述限定条件用于表示运行所述智能合约时所述分布式网络中的账本数据需要满足的条件;
    在所述多个运行结果满足所述验证策略的情况下,所述客户端向共识服务节点发送包括所述多个运行结果的交易。
  8. 根据权利要求7所述的方法,其特征在于,在所述客户端向分布式网络中的多个背书节点发送模拟运行智能合约的请求之前,所述方法还包括:
    所述客户端向所述多个背书节点发送所述智能合约的程序;
    所述客户端接收所述多个背书节点根据所述智能合约的程序发送的所述限定条件的程序;
    所述客户端向所述分布式网络中的所有处理节点发送所述限定条件的程序。
  9. 一种运行智能合约的装置,其特征在于,应用于分布式网络中,所述装置包括:
    接收单元,用于接收共识服务节点发送的交易,所述交易包括在智能合约的背书过程中产生的多个运行结果;
    检查单元,用于检查所述多个运行结果是否满足验证策略,所述检查包括对所述多个运行结果中由除所述智能合约的限定条件之外的其他程序产生的数据和版本号的检查,所述限定条件用于表示运行所述智能合约时所述分布式网络中的账本数据需要满足的条件;
    确定单元,用于在所述多个运行结果满足所述验证策略的情况下,识别所述智能合约中的限定条件,确定本地账本数据是否满足所述限定条件;
    处理单元,用于在所述本地账本数据满足所述限定条件的情况下,接受所述交易。
  10. 根据权利要求9所述的装置,其特征在于,所述装置为背书节点,所述装置还包括:
    背书单元,用于在所述接收共识服务节点发送的交易之前,对所述智能合约进行背书,得到本次背书的运行结果;
    第一发送单元,用于将所述本次背书的运行结果发送给需要在交易中使用所述本次背书的运行结果的客户端或所述客户端的代理节点。
  11. 根据权利要求10所述的装置,其特征在于,所述接收单元还用于:
    接收客户端或所述客户端的代理节点发送的模拟运行所述智能合约的请求,所述请求包括所述智能合约的标识信息;
    所述背书单元用于在所述接收共识服务节点发送的交易之前,对所述智能合约进行背书,得到本次背书的运行结果,具体包括:
    根据所述智能合约的标识信息,识别所述智能合约中的所述限定条件;
    基于所述本地账本数据运行所述智能合约中除所述限定条件之外的其它程序并进行签名,得到所述本次背书的运行结果。
  12. 根据权利要求10或11所述的装置,其特征在于,所述接收单元还用于:
    在所述对所述智能合约进行背书,得到本次背书的运行结果之前,接收所述客户端或所述客户端的代理节点发送的所述智能合约的程序;
    所述装置还包括:
    解析单元,用于解析所述智能合约的程序,获得所述限定条件的程序;
    所述第一发送单元还用于:
    向所述客户端或所述客户端的代理节点发送所述限定条件的程序。
  13. 根据权利要求9所述的装置,其特征在于,所述装置为代理节点,所述装置还包括:
    第二发送单元,用于在所述接收共识服务节点发送的交易之前,向所述分布式网络中的多个背书节点发送模拟运行所述智能合约的请求,所述请求包括所述智能合约的标识信息;
    所述接收单元还用于:
    接收所述多个背书节点根据所述请求发送的各自的运行结果;
    所述检查单元还用于:
    检查接收到的所述多个运行结果是否满足所述验证策略,所述检查包括对所述多个运行结果中由除所述限定条件之外的其他程序产生的数据和版本号的检查;
    所述第二发送单元还用于:
    在所述多个运行结果满足所述验证策略的情况下,向客户端发送所述多个运行结果。
  14. 根据权利要求13所述的装置,其特征在于,所述第二发送单元还用于:
    在所述向所述分布式网络中的多个背书节点发送模拟运行所述智能合约的请求之前,向所述多个背书节点发送所述智能合约的程序;
    所述接收单元还用于:
    接收所述多个背书节点根据所述智能合约的程序发送的所述限定条件的程序;
    所述第二发送单元还用于:
    向所述分布式网络中的所有处理节点发送所述限定条件的程序。
  15. 一种运行智能合约的装置,其特征在于,所述装置包括:
    发送单元,用于向分布式网络中的多个背书节点发送模拟运行智能合约的请求,所述请求包括所述智能合约的标识信息;
    接收单元,用于接收所述多个背书节点根据所述请求发送的各自的运行结果;
    检查单元,用于检查接收到的多个运行结果是否满足验证策略,所述检查包括对所述多个运行结果中由除所述智能合约的限定条件之外的其他程序产生的数据和版本号的检查,所述限定条件用于表示运行所述智能合约时所述分布式网络中的账本数据需要满足的条件;
    所述发送单元还用于:
    在所述多个运行结果满足所述验证策略的情况下,向共识服务节点发送包括所述多个运行结果的交易。
  16. 根据权利要求15所述的装置,其特征在于,所述发送单元还用于:
    在所述向分布式网络中的多个背书节点发送模拟运行智能合约的请求之前,向所述多个背书节点发送所述智能合约的程序;
    所述接收单元还用于:
    接收所述多个背书节点根据所述智能合约的程序发送的所述限定条件的程序;
    所述发送单元还用于:
    向所述分布式网络中的所有处理节点发送所述限定条件的程序。
PCT/CN2018/085748 2017-06-26 2018-05-05 运行智能合约的方法和装置 WO2019001139A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
EP18824895.9A EP3629272B1 (en) 2017-06-26 2018-05-05 Method and device for running chaincode
US16/727,633 US20200134613A1 (en) 2017-06-26 2019-12-26 Method and Apparatus for Running Smart Contract

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201710496967.7 2017-06-26
CN201710496967.7A CN109118214B (zh) 2017-06-26 2017-06-26 运行智能合约的方法和装置

Related Child Applications (1)

Application Number Title Priority Date Filing Date
US16/727,633 Continuation US20200134613A1 (en) 2017-06-26 2019-12-26 Method and Apparatus for Running Smart Contract

Publications (1)

Publication Number Publication Date
WO2019001139A1 true WO2019001139A1 (zh) 2019-01-03

Family

ID=64741014

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2018/085748 WO2019001139A1 (zh) 2017-06-26 2018-05-05 运行智能合约的方法和装置

Country Status (4)

Country Link
US (1) US20200134613A1 (zh)
EP (1) EP3629272B1 (zh)
CN (1) CN109118214B (zh)
WO (1) WO2019001139A1 (zh)

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110716719A (zh) * 2019-10-09 2020-01-21 民生科技有限责任公司 一种金融区块链联盟平台交易动态背书策略实现方法
CN111414413A (zh) * 2019-01-07 2020-07-14 国际商业机器公司 区块链背书验证
WO2020216280A1 (zh) * 2019-04-26 2020-10-29 腾讯科技(深圳)有限公司 一种区块处理方法和节点以及***
CN112417514A (zh) * 2020-10-30 2021-02-26 迅鳐成都科技有限公司 基于电子合约的多方数据协作方法、***及存储介质
CN112598525A (zh) * 2021-02-26 2021-04-02 北京全息智信科技有限公司 一种智能合约分簇并行的区块链实现方法及装置
CN112991069A (zh) * 2020-03-30 2021-06-18 腾讯科技(深圳)有限公司 资源处理方法、装置、设备及存储介质
WO2021135757A1 (zh) * 2020-01-02 2021-07-08 支付宝(杭州)信息技术有限公司 用于执行交易正确性验证的方法及装置
CN114047928A (zh) * 2022-01-12 2022-02-15 北京大学 一种适用于组合交易的智能合约形式化验证方法及***

Families Citing this family (25)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP3675087B1 (en) * 2017-08-22 2023-10-11 Nippon Telegraph And Telephone Corporation Agreement system, agreement apparatus, program, and recording medium
EP3534323A1 (en) * 2018-03-02 2019-09-04 Panasonic Intellectual Property Corporation of America Control method, controller, data structure, and power transaction system
US11188920B2 (en) * 2018-05-23 2021-11-30 International Business Machines Corporation Autocommit transaction management in a blockchain network
US11362805B2 (en) * 2018-11-01 2022-06-14 International Business Machines Corporation Database encryption layer
CN113330473A (zh) * 2019-01-22 2021-08-31 索尼集团公司 通信网络节点、方法和移动终端
EP3916607A4 (en) * 2019-01-23 2022-10-26 Scalar, Inc SYSTEM WITH TAMPERING DETECTIVITY
US11811769B2 (en) 2019-01-31 2023-11-07 Salesforce, Inc. Systems, methods, and apparatuses for implementing a declarative, metadata driven, cryptographically verifiable multi-network (multi-tenant) shared ledger
US11824864B2 (en) 2019-01-31 2023-11-21 Salesforce, Inc. Systems, methods, and apparatuses for implementing a declarative and metadata driven blockchain platform using distributed ledger technology (DLT)
US11899817B2 (en) 2019-01-31 2024-02-13 Salesforce, Inc. Systems, methods, and apparatuses for storing PII information via a metadata driven blockchain using distributed and decentralized storage for sensitive user information
US11790368B2 (en) * 2019-03-05 2023-10-17 International Business Machines Corporation Auto-evolving database endorsement policies
WO2020199177A1 (zh) * 2019-04-04 2020-10-08 华为技术有限公司 运行智能合约的方法和装置
CN109981679B (zh) * 2019-04-08 2021-08-10 上海点融信息科技有限责任公司 在区块链网络中执行事务的方法和装置
US11038771B2 (en) * 2019-04-26 2021-06-15 Salesforce.Com, Inc. Systems, methods, and apparatuses for implementing a metadata driven rules engine on blockchain using distributed ledger technology (DLT)
US11995647B2 (en) 2019-04-30 2024-05-28 Salesforce, Inc. System and method of providing interoperable distributed and decentralized ledgers using consensus on consensus and delegated consensus
US11551216B2 (en) * 2019-05-01 2023-01-10 Sony Corporation Transaction security on distributed-ledger based MaaS platform
CN110233823A (zh) * 2019-05-06 2019-09-13 深圳壹账通智能科技有限公司 区块链实现方法、***及存储介质
CN110224833B (zh) * 2019-05-20 2023-03-10 深圳壹账通智能科技有限公司 票据数据处理方法和***
CN110555769A (zh) * 2019-07-25 2019-12-10 深圳壹账通智能科技有限公司 区块链交易数据处理方法、装置、计算机设备和存储介质
CN110533429A (zh) * 2019-08-30 2019-12-03 北京金山云网络技术有限公司 区块链中的交易背书方法、装置和区块链网络
CN110706106B (zh) * 2019-09-26 2022-07-26 联想(北京)有限公司 一种信息处理方法及设备
US11687948B2 (en) * 2020-03-16 2023-06-27 Paypal, Inc. Adjusting weights of weighted consensus algorithms for blockchains
US11640392B2 (en) * 2020-12-04 2023-05-02 International Business Machines Corporation Blockchain endorsement agreement
CN113452521B (zh) * 2021-06-28 2022-11-04 杭州云象网络技术有限公司 区块链国密适配方法、国密适配器、***和装置
CN114511324A (zh) * 2022-04-18 2022-05-17 云账户技术(天津)有限公司 零工经济服务管理方法、***、网络设备和存储介质
CN115049061A (zh) * 2022-07-13 2022-09-13 卡奥斯工业智能研究院(青岛)有限公司 基于区块链的人工智能推理***

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106548349A (zh) * 2016-11-02 2017-03-29 江苏通付盾科技有限公司 交易信息验证方法及***
CN106603698A (zh) * 2016-12-28 2017-04-26 北京果仁宝科技有限公司 基于dpos的区块链共识方法和节点
US20170140408A1 (en) * 2015-11-16 2017-05-18 Bank Of America Corporation Transparent self-managing rewards program using blockchain and smart contracts

Family Cites Families (19)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20150379510A1 (en) * 2012-07-10 2015-12-31 Stanley Benjamin Smith Method and system to use a block chain infrastructure and Smart Contracts to monetize data transactions involving changes to data included into a data supply chain.
US20170011460A1 (en) * 2015-07-09 2017-01-12 Ouisa, LLC Systems and methods for trading, clearing and settling securities transactions using blockchain technology
US20170132625A1 (en) * 2015-11-05 2017-05-11 Mastercard International Incorporated Method and system for use of a blockchain in a transaction processing network
US20170132626A1 (en) * 2015-11-05 2017-05-11 Mastercard International Incorporated Method and system for processing of a blockchain transaction in a transaction processing network
US10013573B2 (en) * 2015-12-16 2018-07-03 International Business Machines Corporation Personal ledger blockchain
CA3011258A1 (en) * 2016-01-20 2017-07-27 Mezyad M. Al-Masoud Systems and methods for managing a talent based exchange
CN105719185B (zh) * 2016-01-22 2019-02-15 杭州复杂美科技有限公司 区块链的数据对比及共识方法
CN105893042A (zh) * 2016-03-31 2016-08-24 北京航空航天大学 一种基于区块链的智能合约的实现方法
US20180101846A1 (en) * 2016-10-11 2018-04-12 Fujitsu Limited Selective signature system
KR101849917B1 (ko) * 2016-10-13 2018-05-31 주식회사 코인플러그 스마트 컨트랙트 기반의 인증서 서비스를 제공하는 방법 및 이를 이용한 서버
CN106548330B (zh) * 2016-10-27 2018-03-16 上海亿账通区块链科技有限公司 基于区块链的交易验证方法及***
US20180183586A1 (en) * 2016-12-28 2018-06-28 Intel Corporation Assigning user identity awareness to a cryptographic key
WO2018129118A1 (en) * 2017-01-06 2018-07-12 FirstBlood Technologies, Inc. Decentralized competitive arbitration using digital ledgering
US10579368B2 (en) * 2017-03-10 2020-03-03 Salesforce.Com, Inc. Blockchain version control systems
WO2018170504A1 (en) * 2017-03-17 2018-09-20 Labyrinth Research Llc Unified control of privacy-impacting devices
WO2018175666A1 (en) * 2017-03-21 2018-09-27 Dappsters, LLC Blockchain systems and methods
US10176308B2 (en) * 2017-04-28 2019-01-08 Accenture Global Solutions Limited Entitlement management system
US20190303932A1 (en) * 2018-03-28 2019-10-03 NEC Laboratories Europe GmbH Method and system for verifying policy compliance of transactions in a blockchain executing smart contracts
US20190303623A1 (en) * 2018-04-02 2019-10-03 Ca, Inc. Promotion smart contracts for software development processes

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20170140408A1 (en) * 2015-11-16 2017-05-18 Bank Of America Corporation Transparent self-managing rewards program using blockchain and smart contracts
CN106548349A (zh) * 2016-11-02 2017-03-29 江苏通付盾科技有限公司 交易信息验证方法及***
CN106603698A (zh) * 2016-12-28 2017-04-26 北京果仁宝科技有限公司 基于dpos的区块链共识方法和节点

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
See also references of EP3629272A4

Cited By (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111414413A (zh) * 2019-01-07 2020-07-14 国际商业机器公司 区块链背书验证
CN111414413B (zh) * 2019-01-07 2023-09-29 国际商业机器公司 区块链背书验证
WO2020216280A1 (zh) * 2019-04-26 2020-10-29 腾讯科技(深圳)有限公司 一种区块处理方法和节点以及***
US12014204B2 (en) 2019-04-26 2024-06-18 Tencent Technology (Shenzhen) Company Limited Block processing method, node, and system
CN110716719A (zh) * 2019-10-09 2020-01-21 民生科技有限责任公司 一种金融区块链联盟平台交易动态背书策略实现方法
CN110716719B (zh) * 2019-10-09 2023-05-09 民生科技有限责任公司 一种金融区块链联盟平台交易动态背书策略实现方法
WO2021135757A1 (zh) * 2020-01-02 2021-07-08 支付宝(杭州)信息技术有限公司 用于执行交易正确性验证的方法及装置
CN112991069A (zh) * 2020-03-30 2021-06-18 腾讯科技(深圳)有限公司 资源处理方法、装置、设备及存储介质
CN112991069B (zh) * 2020-03-30 2023-08-15 腾讯科技(深圳)有限公司 资源处理方法、装置、设备及存储介质
CN112417514B (zh) * 2020-10-30 2024-04-05 迅鳐成都科技有限公司 基于电子合约的多方数据协作方法、***及存储介质
CN112417514A (zh) * 2020-10-30 2021-02-26 迅鳐成都科技有限公司 基于电子合约的多方数据协作方法、***及存储介质
CN112598525A (zh) * 2021-02-26 2021-04-02 北京全息智信科技有限公司 一种智能合约分簇并行的区块链实现方法及装置
CN114047928A (zh) * 2022-01-12 2022-02-15 北京大学 一种适用于组合交易的智能合约形式化验证方法及***
CN114047928B (zh) * 2022-01-12 2022-03-15 北京大学 一种适用于组合交易的智能合约形式化验证方法及***

Also Published As

Publication number Publication date
US20200134613A1 (en) 2020-04-30
CN109118214A (zh) 2019-01-01
CN109118214B (zh) 2020-11-17
EP3629272A1 (en) 2020-04-01
EP3629272A4 (en) 2020-06-17
EP3629272B1 (en) 2021-10-20

Similar Documents

Publication Publication Date Title
WO2019001139A1 (zh) 运行智能合约的方法和装置
US11321783B2 (en) Method and device for data processing based on blockchain
US10963400B2 (en) Smart contract creation and monitoring for event identification in a blockchain
US20190318351A1 (en) Concomitance of an asset and identity block of a blockchain
US20200013025A1 (en) Conditional deferred transactions for blockchain
WO2019121656A1 (en) Blockchain lifecycle management
US11270388B2 (en) Blockchain-based data processing method and apparatus
TW202008235A (zh) 基於中心化結算與區塊鏈存證的交易方法及系統
US11397960B2 (en) Direct marketing via chained interactions in a blockchain
US11106659B2 (en) Blockchain-based recording and querying operations
CN111309745A (zh) 虚拟资源处理方法、装置、电子设备及存储介质
WO2023207146A1 (zh) Esop***的服务模拟方法、装置、设备及存储介质
US20220027803A1 (en) Sustainable tokens for supply chain with privacy preserving protocol
US11550796B2 (en) Coexistence mediator for facilitating blockchain transactions
CN113706313A (zh) 基于区块链的融资方法、***及计算机可读存储介质
CN111209542B (zh) 一种权限管理方法、装置、存储介质及电子设备
US20150019293A1 (en) System and method for privacy compliant gis file format delivery system for payment data
CN109120411B (zh) 一种资产证券化基础资产数据收集方法及装置
CN116401270A (zh) 数据查询方法、装置、计算机设备和存储介质
CN112541765A (zh) 用于检测可疑交易的方法和装置
CN113835780A (zh) 一种事件响应方法及装置
CN110535664A (zh) 基于区块链的数据处理方法、装置、服务器及存储介质
WO2019205023A1 (zh) 一种基于区块链的数据管理方法及相关***
Zhang Scaling Blockchain Applications with Pub/Sub
CN111401840B (zh) 生成担保物信息的方法、装置、设备和计算机可读介质

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 18824895

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

ENP Entry into the national phase

Ref document number: 2018824895

Country of ref document: EP

Effective date: 20191223