Task execution method and device based on smart contract
By generating task allocation events and monitoring allocation events in smart contracts, it ensures that blockchain members execute contract tasks in an orderly manner, solves the problem of low resource allocation efficiency during smart contract execution, and achieves orderly execution of tasks and efficient resources. use.
Patent Information
- Application Number
- CN202111404766.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-06-02
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2041-06-02
AI Technical Summary
During the execution of smart contracts, how to effectively allocate blockchain members to participate in corresponding contract tasks to ensure orderly execution of tasks and efficient use of resources.
By responding to the workflow defined in the smart contract by the blockchain node instance, a task allocation event is generated, and the business instance executes the contract task after listening to the task allocation event and confirms that the task is allocated to the designated blockchain member, ensuring Orderly execution of contract tasks and efficient use of resources.
It achieves the orderly allocation and execution of smart contract tasks, improves the resource utilization of the blockchain network, reduces resource waste, and ensures the correct execution of contract tasks.
Smart Images

Figure CN114116166B_ABST
Abstract
Description
Technical Field
[0001] One or more embodiments of the present specification relate to the field of blockchain technology, and in particular, to a task execution method and device based on smart contracts. Background Art
[0002] Blockchain technology is built on top of a transmission network (e.g., a peer-to-peer network). Nodes in a blockchain network use a chain data structure to verify and store data, and a distributed node consensus algorithm to generate and update data. In some blockchain networks, some nodes sometimes need to implement small-scale transactions to prevent other nodes from obtaining these transactions and related data. Therefore, a blockchain subnet can be further established based on the blockchain mainnet.
[0003] Smart contracts deployed in the blockchain mainnet or blockchain subnet can define workflows, so that blockchain nodes can execute contract tasks corresponding to each task node in the workflow during the execution of smart contracts. However, multiple contract tasks corresponding to the same smart contract may require different blockchain members to participate in the execution. Therefore, when the above smart contracts are called, how to allocate blockchain members to participate in the execution of corresponding contract tasks in an orderly manner is an urgent problem to be solved in the execution of smart contracts. Summary of the invention
[0004] In view of this, one or more embodiments of the present specification provide a task execution method and device based on a smart contract.
[0005] To achieve the above objectives, one or more embodiments of this specification provide the following technical solutions:
[0006] According to a first aspect of one or more embodiments of this specification, a task execution method based on a smart contract is proposed, which is applied to a first node device deployed with a blockchain node instance and a business instance, and the method includes:
[0007] The blockchain node instance generates a task allocation event corresponding to the first task node in response to a first transaction that calls a workflow defined in the smart contract, when the processing progress of the workflow is before the first task node and the input parameter provided by the first transaction satisfies the execution condition of the first task node;
[0008] The business instance executes the first contract task when monitoring the task assignment event and determining that the first contract task contained in the task assignment event is assigned to the first blockchain member to which the first node device belongs.
[0009] According to a second aspect of one or more embodiments of this specification, a task execution device based on a smart contract is proposed, which is applied to a first node device deployed with a blockchain node instance and a business instance, and the device includes:
[0010] An event generating unit, causing the blockchain node instance to respond to a first transaction that calls a workflow defined in a smart contract, and generating a task allocation event corresponding to the first task node when the processing progress of the workflow is before the first task node and the input parameter provided by the first transaction satisfies the execution condition of the first task node;
[0011] The task execution unit enables the business instance to execute the first contract task when monitoring the task assignment event and determining that the first contract task contained in the task assignment event is assigned to the first blockchain member to which the first node device belongs.
[0012] According to a third aspect of one or more embodiments of this specification, an electronic device is provided, including:
[0013] processor;
[0014] a memory for storing processor-executable instructions;
[0015] The processor implements the method as described in the first aspect by running the executable instructions.
[0016] According to a fourth aspect of one or more embodiments of the present specification, a computer-readable storage medium is provided, on which computer instructions are stored, and when the instructions are executed by a processor, the steps of the method described in the first aspect are implemented. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 It is a schematic diagram of creating a smart contract provided by an exemplary embodiment.
[0018] Figure 2 This is a schematic diagram of calling a smart contract provided by an exemplary embodiment.
[0019] Figure 3 It is a schematic diagram of creating and calling a smart contract provided by an exemplary embodiment.
[0020] Figure 4 This is a schematic diagram of establishing a blockchain subnet based on a blockchain mainnet, provided by an exemplary embodiment.
[0021] Figure 5 It is a flowchart of a task execution method based on a smart contract provided by an exemplary embodiment.
[0022] Figure 6This is a workflow diagram of a smart contract provided by an exemplary embodiment.
[0023] Figure 7 It is a workflow state transition diagram of a smart contract provided by an exemplary embodiment.
[0024] Figure 8 It is a structural schematic diagram of a device provided by an exemplary embodiment.
[0025] Fig. 9 It is a block diagram of a task execution device based on a smart contract provided by an exemplary embodiment. DETAILED DESCRIPTION
[0026] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with one or more embodiments of this specification. Instead, they are merely examples of devices and methods consistent with some aspects of one or more embodiments of this specification as detailed in the appended claims.
[0027] It should be noted that: in other embodiments, the steps of the corresponding method are not necessarily performed in the order shown and described in this specification. In some other embodiments, the steps included in the method may be more or less than those described in this specification. In addition, a single step described in this specification may be decomposed into multiple steps for description in other embodiments; and multiple steps described in this specification may be combined into a single step for description in other embodiments.
[0028] Blockchain is generally divided into three types: public blockchain, private blockchain and consortium blockchain. In addition, there are many types of combinations, such as private blockchain + consortium blockchain, consortium blockchain + public blockchain and other different combinations. Among them, the public chain has the highest degree of decentralization. Public chains are represented by Bitcoin and Ethereum. Participants who join the public chain can read data records on the chain, participate in transactions, and compete for the right to record new blocks. Moreover, each participant (i.e., node) can freely join and exit the network and perform related operations. On the contrary, the private chain has the write permission of the network controlled by a certain organization or institution, and the data reading permission is stipulated by the organization. In simple terms, the private chain can be a weakly centralized system with strictly limited and few participating nodes. This type of blockchain is more suitable for use within a specific organization. The consortium chain is a blockchain between the public chain and the private chain, which can achieve "partial decentralization". Each node in the consortium chain usually has a corresponding entity or organization; participants join the network through authorization and form a stakeholder alliance to jointly maintain the operation of the blockchain.
[0029] Whether it is a public chain, a private chain or a consortium chain, it may provide the function of smart contracts. Smart contracts on the blockchain are contracts that can be triggered and executed by transactions on the blockchain system. Smart contracts can be defined in the form of code.
[0030] Taking Ethereum as an example, supporting users to create and call some complex logic in the Ethereum network is the biggest challenge that distinguishes Ethereum from Bitcoin blockchain technology. The core of Ethereum as a programmable blockchain is the Ethereum Virtual Machine (EVM), and each Ethereum node can run EVM. EVM is a Turing-complete virtual machine, which means that various complex logics can be implemented through it. Users publish and call smart contracts in Ethereum on EVM. In fact, the virtual machine directly runs the virtual machine code (virtual machine bytecode, hereinafter referred to as "bytecode"). Smart contracts deployed on the blockchain can be in the form of bytecode.
[0031] For example Figure 1 As shown in the figure, after Bob sends a transaction containing information about creating a smart contract to the Ethereum network, the EVM of node 1 can execute this transaction and generate the corresponding contract instance. Figure 1The "0x6f8ae93..." in the transaction represents the address of this contract. The data field of the transaction can store bytecode, and the to field of the transaction is empty. After the nodes reach an agreement through the consensus mechanism, the contract is successfully created and can be called in the subsequent process. After the contract is created, a contract account corresponding to the smart contract appears on the blockchain and has a specific address. The contract code will be saved in the contract account. The behavior of the smart contract is controlled by the contract code. In other words, the smart contract generates a virtual account on the blockchain that contains the contract code and account storage.
[0032] like Figure 2 As shown in the figure, still taking Ethereum as an example, after Bob sends a transaction for calling a smart contract to the Ethereum network, the EVM of a certain node can execute this transaction and generate a corresponding contract instance. Figure 2 The from field of the transaction is the address of the account of the transaction initiator (i.e. Bob), the "0x6f8ae93..." in the to field represents the address of the smart contract being called, the value field is the value of ether in Ethereum, and the data field of the transaction stores the method and parameters of calling the smart contract. After calling the smart contract, the value of balance may change. Later, a client can use a blockchain node (such as Figure 2 Node 6) in the blockchain network to check the current value of balance. Smart contracts are executed independently on each node in the blockchain network in a prescribed manner, and all execution records and data are stored on the blockchain. Therefore, when the transaction is completed, the blockchain stores transaction credentials that cannot be tampered with or lost.
[0033] The schematic diagram of creating and calling smart contracts is as follows: Figure 3 To create a smart contract in Ethereum, you need to go through the process of writing the smart contract, compiling it into bytecode, and deploying it to the blockchain. To call a smart contract in Ethereum is to initiate a transaction pointing to the smart contract address. The smart contract code runs in a distributed manner in the virtual machines of each node in the Ethereum network.
[0034] It should be noted that in addition to being able to be created by users, smart contracts can also be set by the system in the genesis block. This type of contract is generally called a genesis contract. Generally, some blockchain network data structures, parameters, properties, and methods can be set in the genesis contract. In addition, accounts with system administrator privileges can create system-level contracts or modify system-level contracts (referred to as system contracts). In addition to the EVM in Ethereum, different blockchain networks may also use various virtual machines, which are not limited here.
[0035] After executing a transaction that calls a smart contract, a node in the blockchain network will generate a corresponding receipt to record information related to the execution of the smart contract. In this way, you can query the transaction receipt to obtain relevant information about the contract execution result. The contract execution result can be expressed as an event in the receipt. The message mechanism can realize message transmission through the event in the receipt to trigger the blockchain node to perform corresponding processing. The structure of the event can be, for example:
[0036] Event:
[0037] [topic][data]
[0038] [topic][data] ......
[0040] In the above example, the number of events can be one or more, wherein each event includes fields such as topic and data. The blockchain node can monitor the topic of the event, and when a predefined topic is monitored, perform a preset process, or read relevant content from the data field of the corresponding event, and perform a preset process based on the read content.
[0041] In the above event mechanism, it is equivalent to having a client with a monitoring function at the listening party (such as a user with a monitoring demand), such as running an SDK for implementing the monitoring function on the client, and the client monitors the events generated by the blockchain node, and the blockchain node only needs to generate receipts normally. In addition to the above event mechanism, the disclosure of transaction information can also be achieved in other ways. For example, the listening code can be embedded in the blockchain platform code running on the blockchain node, so that the listening code can monitor one or more data such as the transaction content of the blockchain transaction, the contract status of the smart contract, and the receipt generated by the contract, and send the monitored data to the predefined listening party. Since the listening code is deployed in the blockchain platform code, rather than at the client of the listening party, this implementation method based on the listening code is relatively more active than the event mechanism. Among them, the above listening code can be added to the blockchain platform code by the developers of the blockchain platform during the development process, or it can be embedded by the listening party based on its own needs, and this specification does not limit this.
[0042] One of the decentralized features that distinguishes blockchain technology from traditional technologies is that it records accounts on each node, or distributed accounting, rather than traditional centralized accounting. In order for a blockchain system to become a decentralized, honest and trustworthy system that is difficult to break, public, and cannot be tampered with, it is necessary to make distributed data records secure, clear, and irreversible in the shortest possible time. In different types of blockchain networks, in order to maintain the consistency of the ledgers in each node that records the ledger, a consensus algorithm is usually used to ensure that it is the consensus mechanism mentioned above. For example, a consensus mechanism of block granularity can be implemented between blockchain nodes. For example, after a node (such as a unique node) generates a block, if the generated block is recognized by other nodes, other nodes record the same block. For another example, a consensus mechanism of transaction granularity can be implemented between blockchain nodes. For example, after a node (such as a unique node) obtains a blockchain transaction, if the blockchain transaction is recognized by other nodes, each node that recognizes the blockchain transaction can add the blockchain transaction to the latest block maintained by itself, and ultimately ensure that each node generates the same latest block. The consensus mechanism is a mechanism for blockchain nodes to reach a consensus on block information (or block data) across the entire network, which can ensure that the latest block is accurately added to the blockchain. The current mainstream consensus mechanisms include: Proof of Work (POW), Proof of Stake (POS), Delegated Proof of Stake (DPOS), Practical Byzantine Fault Tolerance (PBFT) algorithm, HoneyBadgerBFT algorithm, etc.
[0043] Due to the decentralized nature of the blockchain network, all blockchain nodes in the blockchain network will maintain the same block data, which cannot meet the special needs of some nodes. Taking the alliance chain as an example, all alliance members (i.e., node members within the alliance) can form a blockchain network. All alliance members have corresponding blockchain nodes in the blockchain network, and can obtain all transactions and related data occurring on the blockchain network through the corresponding blockchain nodes. However, in some cases, some alliance members may want to complete some transactions with confidentiality requirements. These alliance members hope that these transactions can be stored on the blockchain or with the help of other advantages of blockchain technology, and can avoid other alliance members from viewing these transactions and related data. Although these alliance members can form a new blockchain network in addition, the establishment method is similar to the above-mentioned blockchain network containing all alliance members, but it takes a lot of resources to establish a new blockchain network from scratch, and both the establishment process of the blockchain network and the configuration process after it is established are very time-consuming. The needs between alliance members are often temporary or have a certain timeliness, so that the newly established blockchain network will soon lose its meaning of existence due to the disappearance of needs, thereby further increasing the chain construction cost of the above-mentioned blockchain network. The needs of alliance members often change, and the alliance members corresponding to each need are often different. Therefore, whenever the alliance members change, it may be necessary to establish a new blockchain network, resulting in a huge waste of resources and time.
[0044] To this end, the established blockchain network can be used as the blockchain main network, and a blockchain subnet can be established on the basis of the blockchain main network. Then, in the above-mentioned alliance chain scenario, alliance members can establish the required blockchain subnet on the basis of the blockchain main network based on their own needs after participating in the blockchain main network. Since the blockchain subnet is established on the basis of the blockchain main network, the process of establishing the blockchain subnet greatly reduces the resources consumed and the time required compared to establishing a completely independent blockchain network, and is extremely flexible.
[0045] The process of quickly establishing a blockchain subnet based on the blockchain main network is as follows: each main network node in the blockchain main network obtains a transaction for establishing a blockchain subnet, and the transaction contains the configuration information of the blockchain subnet, and the configuration information includes the identity information of the node members. Then, each main network node in the blockchain main network executes the transaction respectively; wherein, when the first main network node belongs to the node member indicated by the configuration information, the node device deploying the first main network node generates a genesis block containing the configuration information based on the transaction and starts the first subnet node belonging to the blockchain subnet.
[0046] The transaction of establishing a blockchain subnet can be initiated by the administrator of the blockchain main network, that is, only the administrator is allowed to establish a blockchain subnet based on the blockchain main network, and avoid opening the establishment authority of the blockchain subnet to ordinary users to prevent security issues caused by this. In some cases, ordinary users of the blockchain main network can also be allowed to initiate the above-mentioned transaction of establishing a blockchain subnet to meet the networking needs of ordinary users, so that ordinary users can quickly establish a blockchain subnet even if it is inconvenient for the administrator to initiate the transaction.
[0047] by Figure 4 As shown in the example, the blockchain main network is subnet0, and the blockchain nodes contained in subnet0 are nodeA, nodeB, nodeC, nodeD, and nodeE. Assume that nodeA, nodeB, nodeC, and nodeD want to form a blockchain subnet: if nodeA is an administrator and only administrators are allowed to initiate transactions to form a blockchain subnet, then nodeA can initiate the above-mentioned transaction to form a blockchain subnet to subnet0; if nodeE is an administrator and only administrators are allowed to initiate transactions to form a blockchain subnet, then nodeA~nodeD needs to make a request to nodeE so that nodeE initiates the above-mentioned transaction to form a blockchain subnet to subnet0; if nodeE is an administrator but ordinary users are allowed to initiate transactions to form a blockchain subnet, then nodeA~nodeE can all initiate the above-mentioned transaction to form a blockchain subnet to subnet0. Of course, whether it is an administrator or an ordinary user, the blockchain node that initiates the transaction to form a blockchain subnet does not necessarily participate in the formed blockchain subnet. For example, although the blockchain subnet is ultimately formed by nodeA, nodeB, nodeC, and nodeD, nodeE can initiate the above-mentioned transaction to form a blockchain subnet to subnet0, and it is not necessarily nodeA~nodeD that initiate the transaction to form a blockchain subnet.
[0048] When a blockchain subnet is established on the basis of the blockchain mainnet, it is easy to understand that there will be a logical hierarchical relationship between the blockchain subnet and the blockchain mainnet. Figure 4 When the blockchain subnet subnet1 is built on subnet0 shown in the figure, it can be considered that subnet0 is in the first layer and subnet1 is in the second layer. Subnet0 is the parent network of subnet1, and subnet1 is the subnet of subnet0. And the blockchain subnet can also build a corresponding blockchain subnet. For example, Figure 4On the basis of subnet1, another blockchain subnet subnet3 is further established. At this time, it can be considered that subnet is in the third layer. Subnet1 is the parent network corresponding to subnet3, subnet3 is the subnet of subnet1, and subnet3 is the grandchild network of subnet0. Similarly, subnet3 can still establish a new blockchain subnet on its basis, so that each blockchain network forms this multi-level tree structure. In this specification, any blockchain network is managed by its corresponding parent network, that is, by the blockchain network that establishes any blockchain network. Therefore, in Figure 4 In this blockchain network tree system, which is composed of the blockchain main network as the root node (the root node has the lowest level) and each blockchain subnet as other nodes, the blockchain subnet represented by any node is managed by the blockchain network corresponding to its parent node. As a special case, when the blockchain main network is the underlying blockchain network, the blockchain main network is managed by the blockchain main network itself. The blockchain main network in this specification can be the underlying blockchain network. The underlying blockchain network refers to a blockchain subnet that is not established on the basis of other blockchain networks. Therefore, there is no other blockchain network other than the blockchain main network that can manage the blockchain main network, such as Figure 4 Subnet0 in the above can be considered as the main blockchain network of the underlying blockchain network type. Subnet0 manages subnet0 itself. Of course, the main blockchain network can also be a subnet of other blockchain networks. This manual does not impose any restrictions on this. The above blockchain network tree system realizes layer-by-layer management by managing the corresponding child nodes through the parent node, reducing the management pressure of the main blockchain network, while avoiding exposing the subnet information of the upper network to the lower network, thereby realizing the secret management of networks at all levels.
[0049] After the transaction for establishing the blockchain subnet is sent to the blockchain main network, the consensus nodes in the blockchain main network will reach a consensus, and after reaching a consensus, each main network node will execute the transaction to complete the establishment of the blockchain subnet. The consensus process depends on the consensus mechanism adopted, such as any of the consensus mechanisms described above, and this specification does not limit this.
[0050] By including configuration information in the transaction of forming a blockchain subnet, the configuration information can be used to configure the formed blockchain subnet so that the formed blockchain subnet meets the networking requirements. For example, by including the identity information of the node members in the configuration information, it is possible to specify which blockchain nodes are included in the formed blockchain subnet.
[0051] The identity information of the node member may include the public key of the node, or other information that can characterize the node identity, such as the node ID, which is not limited in this specification. Taking the public key as an example, each blockchain node has one or more corresponding public-private key pairs. The blockchain node holds the private key, while the public key is public and uniquely corresponds to the private key. Therefore, the identity of the corresponding blockchain node can be characterized by the public key. Therefore, for blockchain nodes that wish to be node members of a blockchain subnet, the public keys of these blockchain nodes can be added to the above-mentioned transaction for forming a blockchain subnet as the identity information of the above-mentioned node members.
[0052] The first main network node can be a blockchain node that is a node member indicated by the configuration information on the blockchain main network. When forming a blockchain subnet, the first main network node does not directly join the blockchain subnet and become its node member, but needs to be generated by the node device used to deploy the first main network node, and the first subnet node becomes a node member in the blockchain subnet. The first main network node and the first subnet node correspond to the same blockchain member, for example, in the alliance chain scenario, they correspond to the same alliance chain member, but the first main network node belongs to the blockchain main network and the first subnet node belongs to the blockchain subnet, so that the blockchain member can participate in the transactions of the blockchain main network and the blockchain subnet respectively; and, since the blockchain main network and the blockchain subnet belong to two independent blockchain networks, the blocks generated by the first main network node and the blocks generated by the first subnet node are respectively stored in different storages on the node devices (the storage used may be, for example, a database), thereby achieving mutual isolation between the storages used by the first main network node and the first subnet node respectively, and thus the data generated by the blockchain subnet will only be synchronized between the node members of the blockchain subnet, so that the blockchain members who only participate in the blockchain main network cannot obtain the data generated on the blockchain subnet, thereby achieving data isolation between the blockchain main network and the blockchain subnet, and meeting the transaction needs between some blockchain members (i.e., blockchain members participating in the blockchain subnet).
[0053] It can be seen that the first main network node and the first subnet node are logically divided blockchain nodes. From the perspective of physical devices, it is equivalent to the node devices that deploy the first main network node and the first subnet node participating in both the blockchain main network and the blockchain subnet. Since the blockchain main network and the blockchain subnet are independent of each other, the identity systems of the two blockchain networks are also independent of each other. Therefore, even if the first main network node and the first subnet node can use exactly the same public key, they should still be regarded as different blockchain nodes. For example, in Figure 4In the example, nodeA in subnet0 is equivalent to the first main network node, and the node device that deploys nodeA generates nodeA1 belonging to subnet1, which is equivalent to the first subnet node. It can be seen that since the identity systems are independent of each other, even if the public key used by the first subnet node is different from that of the first main network node, it does not affect the implementation of the solution in this specification.
[0054] Of course, the node members of the blockchain subnet are not necessarily only some of the node members of the blockchain main network. In some cases, the node members of the blockchain subnet can be completely consistent with the node members of the blockchain main network. At this time, all blockchain members can obtain data on the blockchain main network and the blockchain subnet, but the data generated by the blockchain main network and the blockchain subnet can still be isolated from each other. For example, one type of business can be implemented on the blockchain main network and another type of business can be implemented on the blockchain subnet, so that the business data generated by these two types of business can be isolated from each other.
[0055] In addition to the identity information of the node members mentioned above, the configuration information may also include at least one of the following: the network identifier of the blockchain subnet, the identity information of the administrator of the blockchain subnet, the attribute configuration for the blockchain platform code, etc., which is not limited in this specification. The network identifier is used to uniquely characterize the blockchain subnet, so the network identifier of the blockchain subnet should be different from the blockchain main network and other blockchain subnets established on the blockchain main network. The identity information of the administrator of the blockchain subnet can be, for example, the public key of the node member who is the administrator; wherein, the administrators of the blockchain main network and the blockchain subnet can be the same or different.
[0056] One of the advantages of forming a blockchain subnet through the blockchain mainnet is that since the first mainnet node has been deployed on the node device that generates the first subnet node, the blockchain platform code used by the first mainnet node can be reused on the first subnet node, eliminating the need for repeated deployment of the blockchain platform code, greatly improving the efficiency of forming the blockchain subnet. Then, if the configuration information does not contain the attribute configuration for the blockchain platform code, the first subnet node can reuse the attribute configuration used on the first mainnet node; if the configuration information contains the attribute configuration for the blockchain platform code, the first subnet node can use the attribute configuration, so that the attribute configuration used by the first subnet node is not limited to the attribute configuration of the first mainnet node and has nothing to do with the first mainnet node. The attribute configuration for the blockchain platform code may include at least one of the following: code version number, whether consensus is required, consensus algorithm type, block size, etc., and this manual does not limit this.
[0057] The transaction for forming a blockchain subnet includes a transaction for calling a contract. The transaction may specify the address of the smart contract being called, the calling method, and the parameters passed in. For example, the called contract may be the aforementioned genesis contract or system contract, the called method may be the method for forming a blockchain subnet, and the parameters passed in may include the aforementioned configuration information. In one embodiment, the transaction may include the following information:
[0058] from:Administrator
[0059] to:Subnet
[0060] method:AddSubnet(string)
[0061] string: genesis
[0062] Among them, the from field is the information of the initiator of the transaction, for example, Administrator indicates that the initiator is the administrator; the to field is the address of the called smart contract, for example, the smart contract can be a Subnet contract, then the to field is specifically the address of the Subnet contract; the method field is the calling method, for example, the method used to form a blockchain subnet in the Subnet contract can be AddSubnet(string), and string is the parameter in the AddSubnet() method. In the above example, the value of the parameter is represented by genesis, and the genesis is specifically the aforementioned configuration information.
[0063] Take the transaction in which nodes nodeA~nodeE on Subnet0 execute the AddSubnet() method in the Subnet contract as an example. After the transaction passes consensus, nodeA~nodeE respectively execute the AddSubnet() method and pass in the configuration information to obtain the corresponding execution results.
[0064] The execution result of the contract may include the configuration information. The execution result may be in the receipt mentioned above, which may include an event related to the execution of the AddSubnet() method, that is, a networking event. The topic of the networking event may include a predefined networking event identifier to distinguish it from other events. For example, in the event related to the execution of the AddSubnet() method, the content of the topic is the keyword subnet, and the keyword is different from the topic in the event generated by other methods. Then, nodeA~nodeE can determine that it has listened to the event related to the execution of the AddSubnet() method, that is, a networking event, by monitoring the topics contained in each event in the generated receipt when it monitors the topic containing the keyword subnet. For example, the event in the receipt is as follows:
[0065] Event:
[0066] [topic:other][data]
[0067] [topic:subnet][data] ......
[0069] Then, when nodeA~nodeE listens to the first event, since the content of the topic is other, it determines that the event is not related to the AddSubnet() method; and when nodeA~nodeE listens to the second event, since the content of the topic is subnet, it determines that the event is related to the AddSubnet() method, and then reads the data field corresponding to the event, which contains the above configuration information. Taking the configuration information including the public key of the node member of the blockchain subnet as an example, the content of the data field may include:
[0070] {subnet1;
[0071] nodeA's public key, nodeA's IP, nodeA's port number...;
[0072] nodeB's public key, nodeB's IP, nodeB's port number...;
[0073] Public key of nodeC, IP address of nodeC, port number of nodeC...;
[0074] nodeD's public key, nodeD's IP, nodeD's port number...;
[0075] }
[0076] Among them, subnet1 is the network identifier of the blockchain subnet you want to create. Each blockchain node in the blockchain main network can record the network identifiers of all blockchain subnets that have been created on the blockchain main network, or other information related to these blockchain subnets. This information can be maintained in the above-mentioned Subnet contract, and specifically can correspond to the value of one or more contract states contained in the Subnet contract. Then, nodeA~nodeE can determine whether the above-mentioned subnet1 already exists based on the network identifiers of all the blockchain subnets that have been created; if it does not exist, it means that subnet1 is a new blockchain subnet that needs to be created at present, and if it does exist, it means that subnet1 already exists.
[0077] In addition to using the network identifier of the new blockchain subnet you want to create, you can also use a predefined new network identifier, which indicates that the corresponding networking event is used to form a new blockchain subnet. For example, the above subnet1 can be replaced with newsubnet, which is a predefined new network identifier. When nodeA~nodeE recognizes that the data field contains newsubnet, it can be determined that the event containing newsubnet is a networking event and a new blockchain subnet needs to be created.
[0078] In addition to the network identifier subnet1, the above data field also contains the identity information of each node member and other content. The node device that deploys the first main network node can monitor the generated receipt, and when the networking event is monitored and the content of the networking event indicates that the first main network node belongs to the node member, the node device that deploys the first main network node obtains the configuration information or genesis block contained in the networking event. For example, when nodeA~nodeE determines that subnet1 is a blockchain subnet that needs to be newly established, it will further identify the identity information of the node members contained in the data field to determine its own processing method. For example, nodeA~nodeD will find that the data field contains its own public key, IP address, port number and other identity information. Assuming that nodeA~nodeD are deployed on node devices 1~4 respectively, taking nodeA and node device 1 as an example: nodeA will trigger node device 1, so that node device 1 obtains configuration information from the data field based on the above message mechanism and generates a genesis block containing the configuration information, and node device 1 will deploy nodeA1 locally, and nodeA1 will load the generated genesis block to become a subnet node of subnet1; similarly, nodeB will trigger node device 2 to generate nodeB1, nodeC will trigger node device 3 to generate nodeC1, and nodeD will trigger node device 4 to generate nodeD1. In addition, nodeE will find that the identity information contained in the data field does not match itself. Assuming that nodeE is deployed on node device 5, node device 5 will not generate a genesis block according to the configuration information in the data field, nor will it generate a node in subnet1.
[0079] As mentioned above, the first main network node and the first subnet node do not necessarily use the same identity information. Therefore, in the above embodiment, the data field may contain identity information pre-generated for nodeA1~nodeD1, and different from the identity information of nodeA~nodeD. Taking nodeA as an example, if nodeA finds the identity information of nodeA1 in the data field, nodeA will trigger node device 1 to generate a genesis block, deploy nodeA1, and nodeA1 will load the genesis block; the processing method of nodeB~nodeD is similar, which will not be repeated here.
[0080] In addition to configuration information, the execution result of the contract may include a genesis block. In other words, in addition to including configuration information in the data field, a genesis block containing configuration information can also be generated directly during the execution of the contract call, thereby including the genesis block in the data field. For the above-mentioned nodeA~nodeD, the corresponding node devices 1~4 can obtain the genesis block directly from the data field through the message mechanism without generating it themselves, which can improve the deployment efficiency of nodeA1~nodeD1.
[0081] In this specification, the transaction of forming a blockchain subnet may not be a transaction that calls a smart contract, so that a blockchain network that does not support smart contracts can also implement the technical solution of this specification, thereby quickly creating a blockchain subnet based on the blockchain main network. For example, a group of network transaction type identifiers can be pre-defined. When a transaction contains the network transaction type identifier, it indicates that the transaction is used to form a new blockchain subnet, that is, the transaction is a transaction for forming a blockchain subnet. The blockchain platform code can include relevant processing logic for forming a blockchain subnet, so that when the first main network node running the blockchain platform code executes a transaction, if it is found that the transaction contains the above-mentioned network transaction type identifier, and the first main network node belongs to the node member indicated by the configuration information in the transaction, it can trigger the node device that deploys the first main network node based on the above-mentioned processing logic to generate a genesis block containing the configuration information and start the first subnet node, and the first subnet node loads the genesis block to form a blockchain node in the blockchain subnet.
[0082] The node device starts a process and creates an instance in the process, and the instance runs the blockchain platform code, which is equivalent to deploying a blockchain node on the node device. For the first main network node, the node device creates a first instance in the above process, and the first instance runs the blockchain platform code. Similarly, for the first subnet node, the node device creates a second instance different from the first instance in the above process, and the second instance runs the blockchain platform code. When the first instance and the second instance are in the same process, since there is no cross-process interaction, the deployment difficulty of the first subnet node can be reduced and the deployment efficiency can be improved; of course, the second instance may also be in a different process on the node device from the first instance, and this specification does not limit this. In fact, each blockchain node deployed on any node device involved in the embodiments of this specification is a different blockchain instance running on any node device, and the blocks generated by each blockchain node deployed on any node device are respectively stored in different storage (such as a database) on any node device, and the storage used by each blockchain node deployed by any node device is isolated from each other.
[0083] Through the above method, a blockchain subnet can be created on the blockchain mainnet. Figure 4 For example, subnet0 originally includes nodeA~nodeE, and subnet1 can be formed on the basis of subnet0, which includes nodeA1~nodeD1, and nodeA and nodeA1, nodeB and nodeB1, nodeC and nodeC1, nodeD and nodeD1 are deployed on the same node device. Similarly, subnet2 or more blockchain subnets can be formed on subnet0, where subnet2 includes nodeA2, nodeB2, nodeC2 and nodeE2, and nodeA and nodeA1, nodeA2, nodeB and nodeB1, nodeB2, nodeC and nodeC1, nodeD and nodeD1, nodeE and nodeE2 are deployed on the same node device. In addition, subnet1, subnet2, etc. can be used as blockchain main networks, and blockchain subnets can be further established on this basis. For example, blockchain subnet subnet3 is established on the basis of subnet1. The process is similar to the establishment of subnet1 or subnet2, except that the blockchain main network is replaced with blockchain subnet subnet1. It will not be repeated here. Finally, subnet3 contains nodeA3, nodeB3 and nodeC3, so that nodeA and nodeA1, nodeA2, nodeA3, nodeB and nodeB1, nodeB2, nodeB3, nodeC and nodeC1, nodeC2, nodeC3 are deployed on the same node device respectively.
[0084] For any blockchain network established by the aforementioned method (such as the above-mentioned blockchain main network or blockchain subnet), a smart contract can be deployed thereon, and the contract code (such as bytecode) of the smart contract is distributed and runs in the virtual machines of each blockchain node constituting the blockchain network. The smart contract deployed in the blockchain network can define a workflow containing task nodes, and the contract tasks corresponding to each work node may have dependencies during the execution process. Among them, if there is a dependency between any two contract tasks, the two contract tasks are in a serial relationship; or, if there is no such dependency between any two contract tasks.
[0085] For smart contracts that define the above workflow, the process of executing the contract is the process of executing each contract task in the above workflow. In addition, because multiple contract tasks corresponding to the same smart contract may require different blockchain members to participate in the execution, in order to realize the preset functions of the above smart contracts, it is necessary to reasonably allocate blockchain members to participate in the execution of corresponding contract tasks in an orderly manner.
[0086] To this end, this specification proposes a task execution method based on smart contracts. When each contract task included in the workflow defined by the smart contract requires different blockchain members to participate in the execution, this method can accurately assign blockchain members to execute the corresponding contract tasks, thereby ensuring the correct execution of the smart contract to achieve the corresponding contract function. Figure 5 Describe the task execution plan of the smart contract in this manual.
[0087] See also Figure 5 , Figure 5 FIG. 1 is a flowchart of a task execution method based on a smart contract provided by an exemplary embodiment. Figure 5 As shown, the method is applied to a first node device deployed with a blockchain node instance and a business instance, and the method may include the following steps:
[0088] Step 502, the blockchain node instance responds to the first transaction of calling the workflow defined in the smart contract, and generates a task allocation event corresponding to the first task node when the processing progress of the workflow is before the first task node and the input parameters provided by the first transaction satisfy the execution condition of the first task node.
[0089] First of all, it should be noted that the node device described in this specification is deployed with a blockchain platform code, and a blockchain node instance is formed locally during the process of the node device running the platform code; in addition, a blockchain business code is also deployed in the node device, and a business instance is formed locally during the process of the node device running the business code. Among them, the blockchain network to which the blockchain node instance deployed in the node device belongs can be a blockchain main network or a blockchain subnet established in the aforementioned manner, and of course, it can also be applied to an independent blockchain network (that is, the blockchain network is not established based on other blockchain networks, and there are no other blockchain networks established based on the blockchain network). In other words, the task execution method based on smart contracts described in this specification can be applied to any blockchain network, and this specification does not limit the relationship between the blockchain network and other blockchain networks.
[0090] Among them, in the process of deploying the above-mentioned blockchain node instances and business instances, the node device can pull up multiple processes respectively, and run the above-mentioned blockchain platform code and blockchain business code in different processes respectively, so that the blockchain node instance and the business instance are deployed in different processes respectively. Correspondingly, the blockchain node instance and the business instance can realize data transmission through cross-process interaction. In this way, it is ensured that the blockchain node instance and the business instance generate as little interference as possible during operation, and fault isolation between different instances is realized. Alternatively, in order to reduce the delay that may be generated in the above-mentioned cross-process interaction process to ensure the task execution efficiency during the execution of the smart contract, the node device can also deploy the above-mentioned blockchain node instance and the business instance in the same process, and this manual does not limit this.
[0091] In addition, only one blockchain node instance belonging to the above-mentioned blockchain network can be deployed in the node device, or multiple blockchain node instances belonging to the same blockchain network can be deployed at the same time, or multiple blockchain node instances belonging to different blockchain networks can be deployed (of course, at this time, this solution only focuses on the execution process of the blockchain node instance belonging to a certain blockchain network for the smart contract deployed in the blockchain network). This specification does not limit the number of blockchain node instances deployed in the node device.
[0092] As mentioned above, the smart contract deployed in the blockchain network can be called and executed by the blockchain transaction issued by any blockchain node. Furthermore, multiple tasks may need to be executed during the execution of the smart contract, so the workflow corresponding to each task can be defined in the smart contract, wherein each task has a corresponding task node. The process of executing the smart contract is the process of sequentially executing each contract task defined in the workflow, and the execution of the contract task causes the working state of the smart contract to migrate between each task node according to the preset order of the workflow. Among them, the above-mentioned workflow can be called by the blockchain exchange, so that the blockchain node instance deployed in the node device can respond to the first transaction of calling the workflow defined in the smart contract, and generate a task allocation event corresponding to the first task node when the processing progress of the workflow is before the first task node and the input parameter provided by the first transaction satisfies the execution condition of the first task node.
[0093] by Figure 4Taking the blockchain network shown in the figure as an example, in the blockchain main network subnet0, the node devices where each blockchain node in the network is located belong to the corresponding blockchain members. For example, in the case where subnet0 is a consortium chain, blockchain node A, blockchain node B, blockchain node C, blockchain node D, and blockchain node E can correspond to different consortium chain members. The following takes the smart contract with a workflow defined and deployed in the blockchain main network subnet0 as an example to explain in detail the execution process of each contract task during the execution of the smart contract. The corresponding smart contract execution process can be found in Figure 6 .
[0094] Among them, the smart contract with a workflow definition can provide a calling method with a preset calling form to the outside world, such as:
[0095] void transit(Event ev)
[0096] The definition of event Event is as follows:
[0097]
[0098] Among them, event_type identifies the type of this event, and args is the parameter of this event. Therefore, the first transaction can call the above smart contract through the method transit, thereby realizing the call of the workflow.
[0099] like Figure 6 As shown in the figure, the workflow defined in the smart contract includes 4 contract tasks: contract task A, contract task B1, contract task B2 and contract task C. Among them, any task corresponds to a corresponding task node, and the task node corresponding to any contract task can be considered as the execution starting point of the contract task, such as Figure 6The task nodes A, B1, B2 and C in the table can be used as the execution starting points of contract tasks A, B1, B2 and C respectively. In addition, both contract tasks B1 and B2 need to take the execution result of contract task A as an input parameter, so there is a dependency relationship between contract tasks B1 and B2 on contract task A, that is, there is a serial relationship between contract tasks B1 and A, and between contract tasks B1 and A. However, there is no such dependency relationship between contract tasks B1 and B2, so there is a parallel relationship between contract tasks B1 and B2. It can be seen that in the execution process of the smart contract, only after the execution of contract task A is completed (after the execution result of contract task A is obtained), contract task B1 and contract task B2 will be executed; and the relative order of executing contract task B1 and contract task B2 is not restricted. After executing contract task A, you can either execute contract task B1 first and then contract task B2, or execute contract task B1 after restrictive contract task B2, or execute business instance 1 and contract task B2 at the same time. Among them, contract task A can be defined in the smart contract in the following way:
[0100]
[0101] In addition, the definition of contract tasks B1, B2 and C is similar to that of contract task A, and they are not listed one by one. Of course, this specification does not limit the number of contract tasks in a smart contract and the serial and parallel relationship between each contract task.
[0102] Because the smart contract is deployed in subnet0, each blockchain node in subnet0 will execute the workflow. In order to reduce the cost of contract execution, any of the above contract tasks can be assigned to some alliance chain members, so that the contract task can be executed by the node devices corresponding to some alliance chain members. The execution results of the corresponding contract tasks or smart contracts can be synchronized to other blockchain nodes in subnet0 to avoid resource waste caused by each node member repeatedly executing the contract tasks.
[0103] In one embodiment, the execution condition of the first task node may be that the data format of the input parameter provided by the first transaction meets the requirements. Figure 6In the described embodiment, it is assumed that the first transaction calls the workflow to start executing contract task A, that is, the first task node is task node A corresponding to contract task A, then the input parameter provided by the first transaction can be an event type type in the form of a string (String), and a parameter args in the form of bytes (Bytes). Thus, the node device can determine that the input parameter provided by the first transaction meets the execution condition when it is determined that the data format of the above event type and parameters conforms to the specified format of the called method. It can be seen that if the processing progress of the workflow at the current moment is before task node A (such as the starting point "START" of the workflow in the figure), then the execution condition is satisfied and can be used as a trigger condition for the node device to generate a task allocation event corresponding to task node A. For example, when the first transaction calls the aforementioned transit method of the contract, the parameter ev provided can be
[0104]
[0105]
[0106] Alternatively, the execution condition of the above-mentioned first task node can also be: the input parameter provided by the first transaction is the execution result of the second contract task corresponding to the second task node before the first task node in the workflow. For example, in the case where the first task node is the task node B1 corresponding to the contract task B1, the execution result of the contract task A can be used as the input parameter of the contract task B1, so that when the input parameter provided by the first transaction is the execution result of the contract task A (that is, indicating that the contract task A has been executed at the current moment), the corresponding blockchain node instance can determine that the input parameter provided by the first transaction meets the execution condition. It can be seen that if the processing progress of the workflow at the current moment is before the task node B1 (such as the output position of the contract task A in the figure), the execution condition is satisfied and can be used as a trigger condition for the node device to generate a task allocation event corresponding to the task node B1. Of course, the execution condition of the first task node can also include the above two at the same time, that is, the execution condition can be "the input parameter provided by the first transaction is the execution result of the second contract task corresponding to the second task node before the first task node in the workflow, and the data format of the execution result meets the requirements", so as to achieve more stringent management of the input parameters of any task in the workflow.
[0107] Furthermore, in the case where the first transaction is used to call different methods, the input parameters provided by the first transaction may also have different forms. For example, the first transaction may call a method in a smart contract for advancing a workflow, and the input parameters provided by the first transaction may be irrelevant to the second task node. Figure 6As described above, assuming that the execution process of contract task C does not require the execution results of contract task B1 and / or contract task B2, then when the first task node is task node C, the first transaction is only used to promote the workflow from contract task B1 to contract task C in sequence, so that only parameters related to the execution of contract task C need to be provided, so the parameter may be unrelated to contract task B1 and / or contract task B2 (at this time, task node B1 and / or task node B2 is the second task node).
[0108] For another example, after executing any task, the node device can return the execution result of the second contract task to the first task node through the task callback method in the smart contract. Therefore, when the first transaction calls the task callback method in the smart contract, it means that the input parameter provided by the first transaction is the execution result of the second contract task; wherein, after the task callback method is called, it can automatically trigger the method for advancing the workflow. The above callback process can be seen in Figure 6 The dotted line a2 corresponding to contract task A and the dotted line c2 corresponding to contract task C. For example, the smart contract can use the callback method corresponding to the above transit method to feed back the execution result of the first contract task to the first task node. Among them, the smart contract can provide the following callback method:
[0109]
[0110] In one embodiment, the execution condition of the first task node may include multiple execution sub-conditions, so that when the input parameters provided by the first transaction satisfy all the execution sub-conditions of the first task node, or satisfy some of the execution sub-conditions of the first task node and the remaining execution sub-conditions have been satisfied by the input parameters provided by the second transaction recorded by the blockchain node instance, the blockchain node instance can determine that the execution condition of the first task node is satisfied; and when the input parameters provided by the first transaction satisfy some of the execution sub-conditions of the first task node and there are execution sub-conditions that have not yet been satisfied, the blockchain node instance can record the input parameters provided by the first transaction and wait.
[0111] Still Figure 6As shown in the example, let's assume that the execution of the above-mentioned contract task C requires the execution results of both contract task B1 and contract task B2, that is, the execution conditions of task node C include "obtaining the execution result of contract task B1" and "obtaining the execution result of contract task B2". In the case where each contract task in the workflow is executed according to the dependency relationship between each other, contract task B1 and contract task B2 can be executed by the method called by the first transaction at the same time, so that the input parameters provided by the first transaction can include the execution results of contract task B1 and contract task B2, and the corresponding blockchain node instance can determine that the execution condition of the first task node is satisfied, and then quickly respond to the first transaction to execute contract task C. Alternatively, each contract task in the workflow can also be executed in response to the methods called by different transactions, so that the first transaction can be used to provide the execution result of contract task B1, and the second transaction different from the first transaction can be used to provide the execution result of contract task B2 before the execution of the first transaction ends, and then the blockchain node instance, when it has obtained the execution result of contract task B2 provided by the second transaction, if it further receives the execution result of contract task B1 provided by the first transaction, it can determine that the execution condition of the first task node is satisfied. Accordingly, when the execution result of the contract task B1 provided by the first transaction is obtained, if the execution result of the contract task B2 provided by the second transaction has not yet been obtained, the blockchain node instance can determine that the execution condition of the first task node has not been met, and thus can wait for the execution result of the contract task B2 provided by the second transaction until the result is obtained and the execution condition of the first task node is determined to be met. This method effectively ensures that the task allocation event corresponding to the first task node is generated only when all execution sub-conditions in the execution condition of the first task node are met.
[0112] Step 504: When the business instance monitors the task assignment event and determines that the first contract task contained in the task assignment event is assigned to the first blockchain member to which the first node device belongs, the business instance executes the first contract task.
[0113] For smart contracts deployed in a blockchain network, the blockchain node instances of each blockchain node in the blockchain network can generate the above-mentioned task allocation event, and after the business instances of each blockchain node respectively monitor the task allocation event, they determine whether the first contract task contained in the task allocation event is allocated to the first blockchain member to which the first node device belongs, and execute the first contract task if it is determined that the first contract task is allocated to the first blockchain member. The above-mentioned first contract task can be generated and published using the aforementioned event mechanism, such as Figure 6The dotted line a1 corresponding to contract task A and the dotted line c1 corresponding to contract task C. In the process corresponding to the dotted line a1, the task scheduling framework in node device 1 is used to monitor the task allocation event corresponding to the smart contract; in the process corresponding to the dotted line c1, the task scheduling framework in node device 2 is used to monitor the task allocation event corresponding to the smart contract. After any task scheduling framework monitors any task allocation event, it determines the computing unit that executes the corresponding contract task according to the task requirements or data requirements specified by the event, and schedules this part of the computing unit to complete the relevant computing process for the contract task in an orderly manner, thereby completing the execution process of the contract task. The specific process will not be repeated.
[0114] like Figure 6 As shown, for smart contracts deployed in the blockchain network, it is assumed that contract task A is assigned to blockchain member 1 described in node device 1, and contract task C is assigned to blockchain member 2 described in node device 2 (the execution process of contract task B1 and contract task B2 is not shown and will not be repeated). The business instance deployed in any node device may include a task scheduling framework, a task unit container, and a task unit managed by the task unit container, wherein the task scheduling framework is connected to at least one task unit container for managing task units, so as to realize the task distribution of contract tasks and the scheduling of computing resources during task execution; the task unit is used to execute specific contract tasks; and the blockchain node instances deployed in node devices 1 and 2 are not shown.
[0115] In one embodiment, the blockchain node instance may include the identity information of the blockchain member of the assignment object in the task assignment event, so that the business instance can determine that the first contract task contained in the task assignment event is assigned to the first blockchain member to which the first node device belongs, when the task assignment event includes the identity information of the first blockchain member, that is, determine that the business instance executes the first contract task. Among them, the above-mentioned identity information can be the member identifier of the blockchain member, or the device identifier of the node device (when only one blockchain node in the blockchain network is deployed in a node device), or the node public key or the summary of the node public key of the blockchain node corresponding to the blockchain member, etc., and this specification does not limit this. Alternatively, the corresponding task assignment conditions can also be specified in advance for the blockchain member, so that when the task content of the first contract task matches the task assignment condition corresponding to the first blockchain member, the business instance can determine that the first contract task contained in the task assignment event is assigned to the first blockchain member to which the first node device belongs, that is, determine that the business instance executes the first contract task.
[0116] Furthermore, when a business instance in any node device determines that it will execute the first contract task by itself, the business instance can execute the first contract task according to the input parameters carried in the task assignment event. In addition, when the processing progress of the workflow at the current moment is before the first task node and the input parameters provided by the first transaction satisfy the execution conditions of the first task node, the blockchain node instance can also update the processing progress of the workflow to after the first task node, thereby promoting the state migration of the workflow state corresponding to the smart contract. Figure 6 The workflow and task execution process in the smart contract can define the workflow status as follows:
[0117]
[0118] Correspondingly, the state transition diagram of the smart contract can be found in Figure 7 .like Figure 7 As shown, the smart contract starts to execute at the starting point of the workflow START. The workflow state of the smart contract is first "waiting for the input of task A". When the first transaction provides the input parameters of contract task A and the input parameters meet the execution conditions of contract task A, the business instance in the node device starts to execute contract task A, and the corresponding workflow state is updated to "waiting for the output of task A". After the contract task completes the execution of contract task A and obtains the execution result, the business instance in the corresponding node device starts to execute contract tasks B1 and B2, and the workflow state is correspondingly updated to "waiting for the results of tasks B1 and B2". Because the execution speed or execution order of contract tasks B1 and B2 is uncertain, it is possible that contract task B2 is executed first and gets the execution result, so the workflow status is updated to "waiting for the result of task B1", and then after contract task B1 is executed and gets the execution result, contract task C can be started and the workflow status is updated to "waiting for the result of task C"; it is also possible that contract task B1 is executed first and gets the execution result, so the workflow status is updated to "waiting for the result of task B2", and then after contract task B2 is executed and gets the execution result, contract task C is started and the workflow status is updated to "waiting for the result of task C". Finally, after contract task C is executed and gets the execution result, all contract tasks in the workflow are executed, that is, the smart contract is executed to the end point END of the workflow.
[0119] In one embodiment, the above-mentioned first contract task can be in the form of privacy computing, file system access, database access and other tasks. In addition, the business instance can also execute the first contract task in a variety of ways. For example, the business instance can call the computing resources deployed locally on the node device to execute the first contract task, such as the business instance in node device 1 can call the task unit managed by the task unit container 11 deployed locally on node device 1 to execute contract task A (at this time, contract task A is the first contract task). For another example, the business instance can also call the computing resources deployed outside the node device to execute the first contract task, such as the business instance in node device 2 can call the task unit managed by the task unit container 21 deployed locally on node device 2 and the off-chain computing resources deployed in other devices outside node device 2 to cooperate to execute contract task C (at this time, contract task C is the first contract task). Of course, the business instance in node device 1 can also call multiple computing resources deployed locally on the node device at the same time to execute contract task A, or the business instance in node device 2 can also only call off-chain computing resources to execute contract task C, and this specification does not limit this. In the practice of the solution, appropriate computing resources can be flexibly selected to execute the first contract task based on actual task requirements such as task type, computing resource consumption, and time requirements, thereby achieving more flexible solution practice and expanding the applicable scenarios of the method described in this specification.
[0120] In one embodiment, the business instance can feed back the corresponding execution result to the smart contract after executing the first contract task, so that the smart contract can execute subsequent tasks based on the execution result. For example, after the business instance in node device 1 executes contract task A, the execution result of contract task A can be fed back to the smart contract; after the business instance in node device 2 executes contract task C, the execution result of contract task C can also be fed back to the smart contract. Of course, the business instances corresponding to contract task B1 and contract task B2 can also feed back the corresponding execution results to the above-mentioned smart contract after executing them. In addition, in order to reduce the amount of data transmission and alleviate the network pressure of the blockchain network, only the final execution result of the smart contract can be returned to the smart contract after the execution of the smart contract is completed, which will not be repeated.
[0121] Furthermore, the above-mentioned task allocation event may simultaneously include a first contract task assigned to a first blockchain member to which the first node device belongs, and a second contract task assigned to a second blockchain member to which the second node device belongs, so that the above-mentioned first contract task is executed by the business instance in the first node device, and the second contract task is executed by the business instance in the second node device. Accordingly, the business instance that executes the first contract task can obtain the execution result of the second contract task (from the business instance that executes the second contract task), and feed the execution result back to the smart contract, thereby realizing one-time feedback of multiple execution results, reducing the number of calls to the smart contract callback method, and further improving the execution efficiency of the smart contract.
[0122] In another embodiment, the task assignment event may also include a contract task assigned to a blockchain member to which at least one other node device different from the first node device belongs. In this case, the business instance may send the execution result of the first contract task to a master node device determined from at least one other node device, so that the master node device can feed back the execution result to the above-mentioned smart contract. The task assignment event still includes the first contract task assigned to the first blockchain member to which the first node device belongs and the second contract task assigned to the second blockchain member to which the second node device belongs as an example for explanation.
[0123] like Figure 6As shown, assuming that the first contract task (i.e., contract task A) includes the first subtask A1 and the second subtask A2, and the first subtask A1 corresponding to the task node 1 is assigned to the first blockchain member to which the first node device belongs, and the second subtask A2 is assigned to the second blockchain member to which the second node device belongs, then the business instance in the node device 1 and the business instance in the node device 2 can respectively execute the first subtask A1 and the second subtask A2. In addition, the above-mentioned task allocation event can also specify any node device in the node device 1 and the node device 2 as the main node device, or the main node device can also be determined by the node device 1 and the node device 2 through negotiation. Therefore, after the business instance in the node device 2 completes the execution of the second subtask A2, the execution result can be sent to the above-mentioned main node device. Correspondingly, after the business instance in node device 1 completes the execution of the first subtask A1, it can check whether it has received the execution result of the second subtask A2 sent by the business instance in node device 2: if the execution result has been received, the business instance in node device 1 can feed back both execution results to the smart contract; if the execution result has not been received, it can wait for the business instance in node device 2 to complete the execution of the second subtask A2, and after receiving the corresponding execution result, feed back the result together with the execution result of its own execution of the first subtask A1 to the smart contract. In this way, when the task allocation event contains multiple contract tasks, all execution results can be fed back to the smart contract by only one node device, effectively reducing the multiple feedback of task execution results and improving the contract execution efficiency to a certain extent.
[0124] In the above embodiments, the blockchain network is used as Figure 4 The blockchain main network subnet0 shown in the figure is used as an example to illustrate. In fact, the task execution method based on smart contracts described in this specification can be applied to Figure 4 Any blockchain network: whether it is a blockchain main network or a blockchain subnet. Where applied to a blockchain subnet (i.e., the blockchain node instance belongs to a blockchain subnet managed by the blockchain main network), the business instance can also submit the execution result of the first contract task to the blockchain main network to store the execution result in the blockchain main network, thereby relying on a larger-scale blockchain main network to ensure that the execution result of the first contract task is difficult to be tampered with, and to achieve reliable storage of the execution result.
[0125] For example, when the above method is applied to Figure 4In the case of subnet1 (blockchain subnet) shown in the figure, after the business instance in node device 1 executes contract task A (i.e., the first contract task) and obtains the corresponding execution result, the execution result can be submitted to subnet1 (blockchain main network), so that the execution result is stored in subnet1. Of course, a variety of different submission methods can be used, such as submitting the complete execution result (content storage), submitting the summary of the execution result (hash storage), submitting the encrypted execution result (privacy storage), etc., which will not be repeated here.
[0126] Figure 8 is a schematic structural diagram of a device provided by an exemplary embodiment. Figure 8 , at the hardware level, the device includes a processor 802, an internal bus 804, a network interface 806, a memory 808, and a non-volatile memory 810, and may also include hardware required for other services. The processor 802 reads the corresponding computer program from the non-volatile memory 810 into the memory 808 and then runs it, forming a task execution device based on a smart contract at the logical level. Of course, in addition to the software implementation, one or more embodiments of this specification do not exclude other implementation methods, such as logic devices or a combination of software and hardware, etc., that is, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0127] Please refer to Fig. 9 In one embodiment, the task execution device based on the smart contract is applied to a first node device deployed with a blockchain node instance and a business instance, and the device may include:
[0128] The event generating unit 901 enables the blockchain node instance to respond to the first transaction of calling the workflow defined in the smart contract, and generate a task allocation event corresponding to the first task node when the processing progress of the workflow is before the first task node and the input parameter provided by the first transaction satisfies the execution condition of the first task node;
[0129] The task execution unit 902 enables the business instance to execute the first contract task when monitoring the task assignment event and determining that the first contract task contained in the task assignment event is assigned to the first blockchain member to which the first node device belongs.
[0130] Optionally, the execution condition includes at least one of the following:
[0131] The data format of the input parameter provided by the first transaction meets the requirements;
[0132] The input parameter provided by the first transaction is the execution result of the second contract task corresponding to the second task node before the first task node in the workflow.
[0133] Optional,
[0134] When the first transaction calls the device for advancing the workflow in the smart contract, it indicates that the entry is irrelevant to the second task node;
[0135] When the first transaction calls the task callback device in the smart contract, it indicates that the input parameter is the execution result of the second contract task; wherein, after the task callback device is called, the device for advancing the workflow is automatically triggered.
[0136] Optionally, the execution condition of the first task node includes a plurality of execution sub-conditions, and the device further includes:
[0137] The condition determination unit 903 enables the blockchain node instance to determine that the execution condition is satisfied when the input parameter provided by the first transaction satisfies all execution sub-conditions of the first task node, or satisfies some execution sub-conditions of the first task node and the remaining execution sub-conditions have been satisfied by the input parameter provided by the second transaction recorded by the blockchain node instance;
[0138] The parameter recording unit 904 enables the blockchain node instance to record the input parameters provided by the first transaction and wait when the input parameters provided by the first transaction meet some execution sub-conditions of the first task node and there are execution sub-conditions that have not been met.
[0139] Optionally, in any of the following cases, it is determined that the first contract task contained in the task allocation event is allocated to the first blockchain member to which the first node device belongs:
[0140] The task assignment event includes the identity information of the first blockchain member;
[0141] The task content of the first contract task matches the task allocation conditions corresponding to the first blockchain member.
[0142] Optionally, also include:
[0143] The node updating unit 905 enables the blockchain node instance to update the processing progress of the workflow to after the first task node when the processing progress of the workflow is before the first task node and the input parameters provided by the first transaction satisfy the execution condition of the first task node.
[0144] Optionally, the task execution unit 902 is further configured to:
[0145] enabling the service instance to call computing resources deployed locally on the node device to execute the first contract task; and / or,
[0146] The business instance calls computing resources deployed outside the node device to execute the first contract task.
[0147] Optionally, also include:
[0148] The self-feedback unit 906 enables the business instance to feed back the execution result of the first contract task to the smart contract.
[0149] Optionally, also include:
[0150] The first centralized feedback unit 907, when the task assignment event also includes a second contract task assigned to a second blockchain member to which the second node device belongs, enables the business instance to obtain an execution result of the second contract task and feeds back the execution result to the smart contract.
[0151] Optionally, also include:
[0152] The second centralized feedback unit 908 enables the business instance to send the execution result of the first contract task to the main node device determined from the at least one other node device, when the task assignment event also includes a contract task assigned to a blockchain member to which at least one other node device different from the first node device belongs, so that the main node device can feed back the execution result to the smart contract.
[0153] Optionally, the blockchain node instance belongs to a blockchain subnet, and the blockchain subnet is managed by a blockchain main network; the device further includes:
[0154] The result evidence storage unit 909 enables the business instance to submit the execution result of the first contract task to the blockchain main network to store the execution result in the blockchain main network.
[0155] Optionally, the blockchain node instance and the business instance are in different processes.
[0156] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, the computer may be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
[0157] For the convenience of description, the above device is described in various units according to their functions. Of course, when implementing this specification, the functions of each unit can be implemented in the same or multiple software and / or hardware.
[0158] Those skilled in the art will appreciate that the embodiments of this specification may be provided as methods, systems, or computer program products. Therefore, this specification may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, this specification may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0159] This specification is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of this specification. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0160] This specification may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. This specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules may be located in local and remote computer storage media, including storage devices.
[0161] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0162] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1In a typical configuration, a computer includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0163] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0164] Computer-readable media include permanent and non-permanent, removable and non-removable media that can be used to store information by any method or technology. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, disk storage, quantum memory, graphene-based storage media or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0165] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0166] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0167] The terms used in one or more embodiments of this specification are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of this specification. The singular forms of "a", "said" and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0168] It should be understood that although the terms first, second, third, etc. may be used to describe various information in one or more embodiments of this specification, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of this specification, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0169] The above description is merely a preferred embodiment of one or more embodiments of the present specification and is not intended to limit one or more embodiments of the present specification. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of one or more embodiments of the present specification shall be included in the scope of protection of one or more embodiments of the present specification.
Claims
1. A task execution method based on a smart contract, applied to a first node device deployed with a blockchain node instance and a business instance, wherein the blockchain node instance belongs to a blockchain subnet, and the blockchain subnet is managed by a blockchain main network; the method comprises: In the process of executing the smart contract in response to the first transaction that calls the workflow defined in the smart contract, if the processing progress of the workflow is before the first task node and the input parameter provided by the first transaction satisfies the execution condition of the first task node, a task allocation event corresponding to the first task node is generated; The business instance executes the first contract task when monitoring the task assignment event and determining that the first contract task contained in the task assignment event is assigned to the first blockchain member to which the first node device belongs.
2. The method according to claim 1, wherein the execution condition comprises at least one of the following: The data format of the input parameter provided by the first transaction meets the requirements; The input parameter provided by the first transaction is the execution result of the second contract task corresponding to the second task node before the first task node in the workflow.
3. The method according to claim 2, When the first transaction calls the method in the smart contract for advancing the workflow, it indicates that the input is irrelevant to the second task node; When the first transaction calls the task callback method in the smart contract, it indicates that the input parameter is the execution result of the second contract task; After the task callback method is called, a method for advancing the workflow is automatically triggered.
4. The method according to claim 1, wherein the execution condition of the first task node comprises a plurality of execution sub-conditions, and the method further comprises: The blockchain node instance determines that the execution condition is satisfied when the input parameter provided by the first transaction satisfies all execution sub-conditions of the first task node, or satisfies some execution sub-conditions of the first task node and the remaining execution sub-conditions have been satisfied by the input parameter provided by the second transaction recorded by the blockchain node instance; When the input parameters provided by the first transaction satisfy some execution sub-conditions of the first task node and there are execution sub-conditions that have not been satisfied, the blockchain node instance records the input parameters provided by the first transaction and waits.
5. According to the method of claim 1, in any of the following cases, determining that the first contract task contained in the task assignment event is assigned to the first blockchain member to which the first node device belongs: The task assignment event includes the identity information of the first blockchain member; The task content of the first contract task matches the task allocation conditions corresponding to the first blockchain member.
6. The method according to claim 1, further comprising: When the processing progress of the workflow is before the first task node and the input parameters provided by the first transaction satisfy the execution conditions of the first task node, the blockchain node instance updates the processing progress of the workflow to after the first task node.
7. The method according to claim 1, wherein the business instance executes the first contract task, comprising: The business instance calls the computing resources deployed locally on the node device to execute the first contract task; and / or, The business instance calls computing resources deployed outside the node device to execute the first contract task.
8. The method according to claim 1, further comprising: The business instance feeds back the execution result of the first contract task to the smart contract.
9. The method according to claim 8, further comprising: In a case where the task assignment event further includes a second contract task assigned to a second blockchain member to which the second node device belongs, the business instance obtains an execution result of the second contract task and feeds the execution result back to the smart contract.
10. The method according to claim 1, further comprising: In the case where the task assignment event also includes a contract task assigned to a blockchain member to which at least one other node device different from the first node device belongs, the business instance sends the execution result of the first contract task to a master node device determined from the at least one other node device, so that the master node device feeds back the execution result to the smart contract, wherein the master node device is specified by the task assignment event, or determined by negotiation between the first node device and the at least one other node device.
11. The method according to claim 1, further comprising: The business instance submits the execution result of the first contract task to the blockchain main network to store the execution result in the blockchain main network.
12. According to the method of claim 1, the blockchain node instance and the business instance are in different processes.
13. The method according to claim 1, wherein the service instance comprises at least one of the following: A task scheduling framework, a task unit container, and a task unit managed by the task unit container.
14. The method according to claim 1, wherein the first contract task comprises at least one of the following: Privacy computing, file system access, database access.
15. A task execution device based on a smart contract, applied to a first node device deployed with a blockchain node instance and a business instance, wherein the blockchain node instance belongs to a blockchain subnet, and the blockchain subnet is managed by a blockchain main network; the device comprises: An event generating unit, causing the blockchain node instance to generate a task allocation event corresponding to the first task node when executing the smart contract in response to a first transaction that calls a workflow defined in the smart contract, if the processing progress of the workflow is before the first task node and the input parameter provided by the first transaction satisfies the execution condition of the first task node; The task execution unit enables the business instance to execute the first contract task when monitoring the task assignment event and determining that the first contract task contained in the task assignment event is assigned to the first blockchain member to which the first node device belongs.
16. An electronic device, comprising: processor; a memory for storing processor-executable instructions; The processor implements the method according to any one of claims 1 to 14 by running the executable instructions.
17. A computer-readable storage medium having computer instructions stored thereon, which, when executed by a processor, implement the steps of the method according to any one of claims 1 to 14.
Citation Information
Patent Citations
Implementing a blockchain-based workflow
CN111066047A
Smart Contract-Based Task Execution Method and Device
CN113098983B
