Blockchain-based method and apparatus for scheduled task execution

By recording a list of planned tasks in the state database of blockchain nodes, nodes automatically query and execute tasks that meet the conditions, thus solving the problems of single point of failure and low security of planned tasks in blockchain and achieving higher security and resource protection.

CN117076553BActive Publication Date: 2025-11-21TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210505462.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-05-10
Publication Date
2025-11-21
Estimated Expiration
2042-05-10

AI Technical Summary

Technical Problem

When executing planned tasks in a blockchain, there are risks of single point of failure, low security, and theft of billing resources, which existing technologies have not been able to effectively address.

Method used

The node state database in the blockchain records a list of planned tasks. When a node produces a new block, it automatically queries and executes tasks that meet the conditions, and packages the transaction records into the block to avoid off-chain triggering and private key leakage.

Benefits of technology

It improves the security of scheduled task execution, avoids the risk of single points of failure and theft of billing resources, and ensures the automation and security of scheduled tasks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117076553B_ABST
    Figure CN117076553B_ABST
Patent Text Reader

Abstract

The application discloses a kind of plan task execution method and device based on blockchain.Therein, the method includes: when the first node in target blockchain needs to produce new first target block, query the plan task list in the state database of the first node, wherein the nodes in target blockchain include target node set, the nodes in target node set are set to allow to produce new block;In the case where it is found that there is target plan task meeting target execution condition in the query plan task list, execute target plan task on the first node, wherein target execution condition, target smart contract called, target execution parameter of target smart contract are specified in target plan task;First transaction record generated by executing target plan task is packed into first target block on the first node.The present application solves the technical problem of low security in the process of executing plan task in the related art.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of blockchain transaction, in particular to a plan task execution method and device based on blockchain. BACKGROUND

[0002] In the related art, the specific way of implementing a plan task in a blockchain is as follows: an account with a public-private key is set, and the account is given a specific role or sufficient billing resources (Gas), then a timing task is set by an operating system or other timing program, and when the condition is met, the execution program of the plan task is triggered, and a transaction is initiated by the account, so as to implement the plan task on the blockchain.

[0003] However, since the triggering of the plan task is performed outside the blockchain, and is mainly triggered by the operating system or other timing program, if the node triggering the plan task is down, the plan task may stop triggering, thereby causing a single point failure problem.

[0004] In addition, in the above process of implementing the plan task, since the content of the plan task is off-chain, the content of the plan task can be tampered with by humans. At the same time, since a private key needs to be used to sign every time a blockchain transaction is initiated, the private key must be saved in the triggering node of the plan task, that is, the private key is saved in the triggering node outside the blockchain, which may cause the triggering account of the plan task to be stolen, thereby causing the technical problem of low security in the process of executing the plan task. Furthermore, for the blockchain network with the above billing resource limitation, the triggering account of the task must be given sufficient billing resources in advance, which also has the risk of billing resource theft.

[0005] At present, no effective solution has been proposed for the above problems. SUMMARY

[0006] The embodiments of the present application provide a plan task execution method and device based on blockchain, to at least solve the technical problem of low security in the process of executing the plan task.

[0007] According to an aspect of some embodiments of the present application, a method for executing a scheduled task based on a blockchain is provided. The method comprises: when a first node in a target blockchain needs to produce a new first target block, querying a scheduled task list in a state database of the first node, wherein the nodes in the target blockchain comprise a target node set, the nodes in the target node set are configured to allow production of a new block, the target node set comprises the first node, the scheduled task list records scheduled tasks to be executed, and each scheduled task is configured with a corresponding execution condition; when it is found that the scheduled task list contains a target scheduled task that meets a target execution condition, executing the target scheduled task on the first node, wherein the target execution condition, a target smart contract to be invoked, and target execution parameters of the target smart contract are specified in the target scheduled task; and packaging a first transaction record generated by executing the target scheduled task into the first target block on the first node.

[0008] Optionally, before the querying of the scheduled task list in the state database of the first node, the method further comprises: obtaining, on a second node in the target blockchain, a target scheduled task created by a target account; and synchronizing the target scheduled task obtained on the second node and the target account to the state databases on the nodes in the target node set.

[0009] Optionally, after the obtaining of the target scheduled task created by the target account on the third node in the target blockchain, the method further comprises: obtaining, on a second node in the target blockchain, an editing operation on the target scheduled task by the target account to obtain a target editing result, wherein the editing operation on the target scheduled task comprises one of a deletion operation on the target scheduled task and a modification operation on the target scheduled task; and synchronizing the target editing result to the state databases on the nodes in the target node set.

[0010] Optionally, the executing of the target scheduled task on the first node comprises: executing the target smart contract according to the target execution parameters on the first node; and the packaging of the first transaction record generated by executing the target scheduled task into the first target block on the first node comprises: packaging information indicating the target scheduled task and an execution result of the target scheduled task into the first target block on the first node, wherein the first transaction record comprises the information indicating the target scheduled task and the execution result of the target scheduled task, and the execution result of the target scheduled task comprises a result obtained by executing the target smart contract according to the target execution parameters.

[0011] Optionally, the method further comprises: in a case where the packaging of the first transaction record generated by executing the target plan task on the first node into the first target block fails, executing the target plan task on the second node, and packaging the second transaction record generated by executing the target plan task on the second node into a new second target block produced by the second node, wherein the target node set comprises the second node, and the second node is a node that produces a new block after the first node.

[0012] Optionally, the method further comprises: in a case where the packaging of the first transaction record generated by executing the target plan task on the first node into the first target block fails, deducting the first quantity of virtual resources from the first node.

[0013] Optionally, the method further comprises: in a case where the packaging of the first transaction record generated by executing the target plan task on the first node into the first target block fails, deducting the first quantity of virtual resources from the first node.

[0014] Optionally, the method further comprises: in a case where the packaging of the first transaction record generated by executing the target plan task on the first node into the first target block fails, deducting the first quantity of virtual resources from the first node.

[0015] Optionally, the method further comprises: in a case where the packaging of the first transaction record generated by executing the target plan task on the first node into the first target block fails, deducting the first quantity of virtual resources from the first node.

[0016] Optionally, the method further comprises: in a case where the packaging of the first transaction record generated by executing the target plan task on the first node into the first target block fails, deducting the first quantity of virtual resources from the first node.

[0017] According to another aspect of the embodiments of the present application, a blockchain-based scheduled task execution apparatus is also provided, which comprises: a first processing unit configured to query a scheduled task list in a state database of a first node in a target blockchain when the first node needs to produce a new first target block, wherein the nodes in the target blockchain comprise a target node set, the nodes in the target node set are configured to allow the production of new blocks, the target node set comprises the first node, the scheduled task list records scheduled tasks to be executed, and each scheduled task is provided with a corresponding execution condition; an execution unit configured to execute a target scheduled task on the first node when it is found that the target scheduled task meeting the target execution condition exists in the scheduled task list, wherein the target scheduled task is provided with the target execution condition, a target smart contract to be invoked, and target execution parameters of the target smart contract; and a second processing unit configured to pack a first transaction record generated by executing the target scheduled task into the first target block on the first node.

[0018] Optionally, the apparatus further comprises: an acquisition unit configured to acquire a target scheduled task created by a target account on a second node in the target blockchain; and a third processing unit configured to synchronize the target scheduled task acquired on the second node and the target account to the state databases on the nodes in the target node set.

[0019] According to still another aspect of the embodiments of the present application, a computer readable storage medium is also provided, which stores a computer program, wherein the computer program is configured to execute the above-described blockchain-based scheduled task execution method when running.

[0020] According to still another aspect of the embodiments of the present application, a computer program product is also provided, which comprises computer programs / instructions, and the computer programs / instructions are configured to implement the steps of the above-described method when executed by a processor.

[0021] According to still another aspect of the embodiments of the present application, an electronic device is also provided, which comprises a memory and a processor, the memory stores a computer program, and the processor is configured to execute the above-described blockchain-based scheduled task execution method through the computer program.

[0022] In the embodiment of the present application, the created plan task list is recorded in the state database of the node in the blockchain in advance, so that when the block node in the blockchain produces a new block, the above-mentioned plan task list is queried, if the plan task meeting the execution condition is queried, the plan task is executed by the node in the blockchain, and the transaction record produced by executing the plan task is packaged into the newly produced block. In other words, by configuring the plan task on the node in the blockchain, when a new block is produced, the node in the blockchain can automatically query whether the execution condition of the plan task is met, and automatically execute the plan task when the execution condition is met, and package the corresponding transaction record into the newly produced block, without triggering the execution of the above-mentioned plan task by the trigger node outside the blockchain, avoiding the tampering of the plan task and the leakage of the private key signature, solving the technical problem of low security in the process of executing the plan task in the related art, and improving the security in the process of executing the plan task.

[0023] In addition, in the embodiment of the present application, the node in the blockchain triggers the execution of the plan task and the packaging of the chain according to the plan task recorded on the node in the blockchain, without using the trigger node outside the blockchain, thereby avoiding the problem that the trigger node outside the blockchain cannot normally trigger the execution of the above-mentioned plan task due to the failure of the trigger node outside the blockchain. Furthermore, since it is not necessary to set sufficient billing resources for the plan task on the trigger node outside the blockchain in advance, the risk of billing resource theft can also be avoided. BRIEF DESCRIPTION OF DRAWINGS

[0024] The accompanying drawings, which are included to provide a further understanding of the present application and are incorporated in and constitute a part of this application, illustrate embodiments of the present application and together with the description serve to explain the present application. In the drawings:

[0025] Figure 1 is a schematic diagram of an optional plan task execution method based on a blockchain according to an embodiment of the present application;

[0026] Figure 2 is a flowchart of an optional plan task execution method based on a blockchain according to an embodiment of the present application;

[0027] Figure 3 is a schematic diagram of the structure of a target blockchain according to an embodiment of the present application;

[0028] Figure 4 is a schematic diagram of another optional plan task execution method based on a blockchain according to an embodiment of the present application;

[0029] Figure 5 is a schematic diagram of a target plan task according to an embodiment of the present application;

[0030] Figure 6 is a whole flow chart of an optional blockchain-based scheduled task execution method according to an embodiment of the present application;

[0031] Figure 7 is a schematic diagram of an optional creation and editing of a scheduled task according to an embodiment of the present application;

[0032] Figure 8 is a schematic diagram of an optional packaging method of a transaction record according to an embodiment of the present application;

[0033] Figure 9 is a schematic diagram of an optional verification process of a transaction record according to an embodiment of the present application;

[0034] Figure 10 is a schematic diagram of an optional processing process of a packaging failure of a block node according to an embodiment of the present application;

[0035] Figure 11 is a structural schematic diagram of an optional blockchain-based scheduled task execution device according to an embodiment of the present application;

[0036] Figure 12 is a structural schematic diagram of an optional electronic device according to an embodiment of the present application. DETAILED DESCRIPTION

[0037] In order to make the person skilled in the art better understand the present application, the technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, but not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by the person skilled in the art without creative labor should belong to the protection scope of the present application.

[0038] Firstly, the terms used in the embodiments of the present application or related to the embodiments of the present application are described as follows. It can be understood that the following description is one explanation of the terms but not the only explanation:

[0039] Scheduled task: the scheduled task is a common function of the system. By using the task scheduling function, any script, program or document can be arranged to run at a most convenient time. The task scheduling is started at each system startup and runs in the background.

[0040] When it is needed to perform some repetitive events on the server at a certain time, the prepared script, batch folder, program or command can be run at a certain time by using the scheduled task program.

[0041] Crontab: Linux system is controlled by cron (crond) system service to control the timing task. Users can use crontab to let Linux execute commands to execute programs periodically. The crond command will check whether there is work to be executed every minute, and if there is work to be executed, the work will be automatically executed.

[0042] Smart contract: In short, it is a set of digitally defined commitments, including the agreement that contract participants can execute these commitments on it. The program running on the blockchain is usually called a smart contract (Smart Contract).

[0043] Gas: It is a kind of billing (or billing resource) for users to consume computing resources and storage resources when executing smart contracts. The user specifies the maximum gas consumption when initiating contract invocation, and the gas is deducted according to the execution steps when the transaction is packaged and the contract is executed. If the contract has not been executed after reaching the maximum gas consumption, the contract execution will be forcibly terminated, thereby effectively preventing the execution of malicious contracts.

[0044] Consensus node: In the blockchain, the generation of new blocks is responsible for multiple nodes, which collect unpacked transactions, pack them into new blocks, and generate new blocks by a certain rule. The generated new block must be agreed by the majority of other consensus nodes to complete the consensus, and the new block is valid; The node allowed to produce new blocks is called block-producing node, and the consensus node (or consensus node set) includes multiple block-producing nodes.

[0045] It should be noted that the terms "first", "second", and the like in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and do not necessarily describe a specific order or sequence. It should be understood that the data used in this way can be interchanged under appropriate circumstances, so that the embodiments of the application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion, for example, a process, method, system, product or device including a series of steps or units does not necessarily limit to those steps or units clearly listed, but can include other steps or units not clearly listed or inherent to these processes, methods, products or devices.

[0046] According to an aspect of an embodiment of the present application, a blockchain-based scheduled task execution method is provided. As an optional implementation, the above-mentioned blockchain-based scheduled task execution method can be implemented by using the schematic diagram as shown in Figure 1 Specifically, as shown in Figure 1As shown, it is assumed that there are 8 nodes in total in the target blockchain, wherein the node can be understood as a terminal device with data processing capability in the blockchain network, such as a computer, a mobile phone, a mining machine, etc. Part of the nodes are selected as consensus nodes from the 8 nodes according to a preset strategy, for producing new blocks, executing planned tasks, and packaging transaction records, etc.

[0047] In this embodiment, it is assumed that nodes 1 to 4 are selected as consensus nodes of the target blockchain, and a block node with the ability to produce a new block is determined from the consensus nodes under the condition that a preset condition is met. For example, node 1 in the consensus nodes is determined as the block node in a polling manner, the planned task list in the state database of node 1 is queried, and it is judged that there is a target planned task meeting the execution condition in the planned task list. Then, the target planned task is executed on node 1, and the generated transaction record is packaged into block 1 generated by node 1.

[0048] As an optional implementation manner, in the case that the transaction record is successfully packaged into block 1 on node 1, the target execution condition specified in the target planned task and the execution result of the target planned task are verified by using other nodes (nodes 2 to 4) in the consensus nodes except node 1. In the case that the verification is passed, block 1 is written into the local ledger of nodes 2 to 4 through network 100, and block 1 is broadcasted to nodes 5 to 8.

[0049] It should be noted that the implementation process of writing block 1 into nodes 2 to 4 and broadcasting block 1 to nodes 5 to 8 is not limited, for example, the newly produced block 1 is sent to network 100 through node 1, and then block 1 is broadcasted to nodes 2 to 8 through network 100; or block 1 is transmitted from node 1 to nodes 2 to 8 respectively.

[0050] The specific process is as follows: step S102, when a first node in a target blockchain needs to produce a new first target block, a planned task list is queried in a state database of the first node, wherein the nodes in the target blockchain include a target node set, the nodes in the target node set are set to allow production of a new block, the target node set includes the first node, the planned task list records planned tasks to be executed, and each planned task is provided with a corresponding execution condition; step S104, in the case that a target planned task meeting a target execution condition is found in the queried planned task list, the target planned task is executed on the first node, wherein the target execution condition, a called target smart contract, and a target execution parameter of the target smart contract are specified in the target planned task; and step S106, a first transaction record generated by executing the target planned task is packaged into the first target block on the first node.

[0051] By the above manner, the created plan task list is recorded in the state database of the node in the blockchain in advance, so that when a block node in the blockchain produces a new block, the plan task list is queried, if a plan task meeting the execution condition is queried, the plan task is executed by the node in the blockchain, and the transaction record produced by executing the plan task is packaged into the newly produced block. In other words, by configuring the plan task in the blockchain ledger in advance, when a new block is produced, the node in the blockchain can automatically query whether the execution condition of the plan task is met, and automatically execute the plan task when the execution condition is met, and package the corresponding transaction record into the newly produced block, without triggering the execution of the plan task by the trigger node outside the blockchain, avoiding tampering of the plan task and leakage of the private key signature, solving the technical problem of low security in the process of executing the plan task in the related art, and improving the security in the process of executing the plan task.

[0052] In addition, in the embodiment of the application, the node in the blockchain triggers the execution of the plan task and the on-chain packaging according to the plan task recorded on the ledger in the blockchain, without using the trigger node outside the blockchain, thereby avoiding the problem that the trigger node outside the blockchain cannot normally trigger the execution of the plan task due to failure. Furthermore, since it is not necessary to set sufficient billing resources for the plan task on the trigger node outside the blockchain in advance, the risk of billing resource theft can also be avoided.

[0053] According to an aspect of an embodiment of the application, a blockchain-based plan task execution method is provided, Figure 2 is a flowchart of the blockchain-based plan task execution method according to the embodiment of the application, and the flowchart includes the following steps:

[0054] Step S202, when a first node in a target blockchain needs to produce a new first target block, querying a plan task list in a state database of the first node, wherein the nodes in the target blockchain include a target node set, the nodes in the target node set are set to allow production of a new block, the target node set includes the first node, the plan task list records plan tasks to be executed, and each plan task is set with a corresponding execution condition;

[0055] In order to better understand the embodiment of the application, first, the basic concept of blockchain is briefly introduced. The so-called blockchain is a kind of decentralized shared ledger which combines data blocks in the form of chain according to time sequence, and uses cryptography to ensure that it is tamper-proof and unforgeable, which can safely store simple, sequential and verifiable data within the system.

[0056] Generally, the blockchain is a distributed data storage structure without a central node, and therefore the same block information is stored on all nodes. As an optional example, as shown in FIG. 1, it is assumed that there are 8 nodes in the target blockchain, and the number of blocks in each node and the structure and content of the blocks are the same. For example, each of the nodes 1-8 includes N blocks, and the N blocks are distributed in order from small to large block numbers, and the structure and content of the blocks with the same number in the nodes 1-8 are the same. Figure 3

[0057] As an optional example, a number of nodes in the target blockchain are selected as consensus nodes according to a preset strategy, as shown in FIG. 2, nodes 1-4 are selected as consensus nodes from the target blockchain, and the set of nodes 1-4 is denoted as a target node set. The consensus node can be understood as being related to the packaging of the transaction record of the execution plan task, and the consensus mechanism (for example, different voting principles) is used to realize the packaging of the block data. Figure 4

[0058] As an optional implementation, it is assumed that one node is determined from the nodes 1-4 in the target node set as a block-producing node in a round-robin manner, for example, node 1 is determined as the block-producing node at the current time according to a preset time interval, and then the state plan task list is queried in the state database of the node 1, wherein each plan task T1, T2…T m is provided with a corresponding execution condition Q1, Q2…Q m .

[0059] It should be noted that when node 1 is determined as a block-producing node, it means that node 1 has the right to produce a new block at the current time, but it does not mean that node 1 has produced a new block. Whether node 1 produces a new block depends on whether there is a transaction to be packaged or a plan task to be executed, and whether the plan task to be executed meets the corresponding execution condition.

[0060] For example, in the case of detecting that account A transfers funds to account B, a new block needs to be generated, for example, the block-producing node 1, to package the transaction record of the fund transfer from account A to account B on the chain.

[0061] In step S204, when it is detected that there is a target plan task that meets the target execution condition in the plan task list, the target plan task is executed on the first node, wherein the target execution condition, the called target smart contract, and the target execution parameter of the target smart contract are specified in the target plan task.

[0062] ​​As an optional example, the execution conditions in steps S202 and S204 can be set by, but not limited to, the definition rules shown in Table 1, for example, the corresponding execution conditions are set by one or more of the fields of "minute", "hour", "date", "month", "week", and "block height" in Table 1. Figure 5 Figure 5

[0063] The following describes each field in Table 1: Figure 5

[0064] 1) "*" represents all the numbers in the value range, for example, if the month field is *, it means 1 to 12 months;

[0065] 2) " / " represents a certain time interval, for example, if the minute field is * / 10, it means executing once every 10 minutes. If the block height field is * / 100, it means executing once every 100 blocks (the block height is divisible by 100).

[0066] 3) "-" represents a certain interval range, which is a closed interval. For example, "2-5" means "2, 3, 4, 5", and 0-23 / 2 in the hour field means executing once every 2 hours in the range of 0-23.

[0067] 4) "," represents scattered numbers (not necessarily consecutive), for example, 1, 2, 3, 4, 7, and 9.

[0068] For example, when it is found that there is a to-be-executed scheduled task T1 in the state database of node 1, and the corresponding execution condition Q1 of the to-be-executed scheduled task T1 is configured as "minute field * / 10", it is determined whether the current time is an integer multiple of 10 minutes, for example, 1:10, 3:20, etc. If the current time is an integer multiple of 10 minutes, it is determined that the execution condition Q1 is met, and the scheduled task T1 is executed on node 1.

[0069] For another example, when the corresponding execution condition Q1 of the to-be-executed scheduled task T1 is configured as "minute field * / 10" and "block height field * / 100", it is determined whether the current time is an integer multiple of 10 minutes, and whether the number of the block currently produced by node 1 is an integer multiple of 100. If the current time is an integer multiple of 10 minutes, and the number of the block currently produced by node 1 is an integer multiple of 100, it is determined that the execution condition Q1 is met, and the scheduled task T1 is executed on node 1.

[0070] As an optional example, when the block height field is used to query the scheduled task list to determine whether the execution condition Q1 is met, the specific process of querying the scheduled task list includes:

[0071] ​​​In a case where the target execution condition includes a target block height, and the target block height indicates that the target plan task is executed once every N blocks, it is detected whether the number of the first target block to be produced is MxN, where N is a positive integer greater than or equal to 2, and M is a positive integer greater than or equal to 1.

[0072] In a case where it is detected that the number of the first target block to be produced is MxN, it is determined that the target plan task satisfying the target execution condition is found in the plan task list.

[0073] As shown in Figure 4 , it is assumed that the target execution condition Q1 includes a field of "target block height * / 100". When it is detected that the number of the first target block to be produced by the node 1 (the current block production node) is 201, since 201 cannot be divided by 100, it is determined that the target plan task T1 does not satisfy the execution condition Q1. Conversely, when it is detected that the number of the first target block to be produced by the node 1 is 200, since 200 can be divided by 100, it is determined that the target plan task T1 satisfies the execution condition Q1.

[0074] As an optional example, when the block production node 1 produces the first target block N+1, the plan task list is queried by the above implementation manner, and when it is determined that the plan task T1 satisfying the execution condition Q1 exists, the specific manner of executing the plan task T1 needs to be determined according to the creator of the plan task T1, the target execution parameter of the target smart contract, and the like.

[0075] Specifically, from Figure 5 , it can be seen that in the plan task defined by the creator through a syntax similar to cromtaba, two parts of content are included. One part is the execution condition of the plan task, and the other part is used to determine the specific execution manner of the plan task, mainly including the called smart contract, the called method, the method parameter list, and the like.

[0076] For example, when the plan task T1 is a draw task, the draw manner includes manner 1, manner 2, …, and manner N, such as red envelope, mobile phone number contest, double-color ball, and the like. For the manner 1, three different prize categories P1, P2, and P3 are set, and the winning number of the prizes P1, P2, and P3 is C1, C2, and C3, respectively. Then, the parameters used to represent the above draw manner, the parameters used to represent the above prize categories, and the parameters used to represent the above winning number, and the like are included in the smart contract.

[0077] The target execution parameter of the target smart contract in the plan task can be used (for example, including the Figure 5The called method and the method parameter list shown) to assign parameters in the target smart contract, for example, the drawing method in the above smart contract is assigned by the called method in the scheduled task, and the prize categories and the winning numbers in the above smart contract are respectively assigned by the method parameter list in the scheduled task, for example, the drawing method (method 1) in the above smart contract is determined as double-color ball, the prize categories (P1, P2, P3) in the above smart contract are determined as first prize, second prize and third prize respectively, and the winning numbers (C1, C2, C3) corresponding to each prize category in the above smart contract are respectively determined as 2, 10, 100, etc. When the scheduled task T1 is executed, the target smart contract is executed according to the target execution parameters (for example, including the drawing method, the prize categories, the winning numbers (of course, the account set participating in the drawing can also be included), etc.), that is, the drawing is executed according to the assigned drawing method, the prize categories, the winning numbers, and the first transaction record is generated, wherein the first transaction record can be but not limited to the result of the drawing, for example, account 1 and account 2 win the first prize, account 10 to account 20 win the second prize, etc. Figure 5 The called method and the method parameter list shown) to assign parameters in the target smart contract, for example, the drawing method in the above smart contract is assigned by the called method in the scheduled task, and the prize categories and the winning numbers in the above smart contract are respectively assigned by the method parameter list in the scheduled task, for example, the drawing method (method 1) in the above smart contract is determined as double-color ball, the prize categories (P1, P2, P3) in the above smart contract are determined as first prize, second prize and third prize respectively, and the winning numbers (C1, C2, C3) corresponding to each prize category in the above smart contract are respectively determined as 2, 10, 100, etc. When the scheduled task T1 is executed, the target smart contract is executed according to the target execution parameters (for example, including the drawing method, the prize categories, the winning numbers (of course, the account set participating in the drawing can also be included), etc.), that is, the drawing is executed according to the assigned drawing method, the prize categories, the winning numbers, and the first transaction record is generated, wherein the first transaction record can be but not limited to the result of the drawing, for example, account 1 and account 2 win the first prize, account 10 to account 20 win the second prize, etc.

[0078] It should be noted that when the scheduled task T1 is created, the target execution condition, the called target smart contract and the target execution parameters of the target smart contract have been pre-specified in the T1. That is, when the scheduled task T1 is created, the drawing method is double-color ball, the winning number of the first prize is 2, the winning number of the second prize is 10, and the winning number of the third prize is 100.

[0079] It can be understood that the above smart contract, target execution parameters and first transaction record are only an example and are not limited thereto.

[0080] Step S206: The first transaction record generated by executing the target scheduled task on the first node is packaged into the first target block.

[0081] As an example, the results of the drawing, for example, account 1 and account 2 win the first prize, account 10 to account 20 win the second prize, etc. are packaged into the first target block N+1.

[0082] From the above analysis, it can be seen that when the scheduled task is created, the execution condition (for example, minutes, hours, dates, months, weeks, block height, etc.) triggering the execution of the scheduled task, and the contract name, function name and parameter list of the specific contract to be executed after triggering the scheduled task are pre-configured in the scheduled task, so that the triggering of the scheduled task is realized inside the target blockchain, avoiding the single point failure problem in the off-chain triggering process, and reducing the risk of theft of the target scheduled task triggering account, thereby achieving the technical effect of improving the security of executing the scheduled task on the blockchain.

[0083] In order to more clearly understand the above-mentioned execution method of the plan task based on the blockchain, the following will be further described in combination with Figure 6 Specifically, the method comprises the following steps:

[0084] S602, the main consensus node needs to produce a new first target block;

[0085] Wherein, the main consensus node can be but not limited to node 1 in Figure 4 For example, it can also be node 2, node 3 and node 4 in the target node set, etc.

[0086] S604, query the plan task list in the state database in node 1;

[0087] When the target plan task meeting the execution condition is queried, return the query result from the state database of node 1 to node 1, and attach the target plan task to node 1.

[0088] It should be noted that the target execution condition, the called target smart contract and the target execution parameter of the target smart contract have been specified in the target plan task.

[0089] S606, execute the smart contract in the target plan task in node 1;

[0090] As described in the above-mentioned embodiment, when the target execution condition Q1 is met, execute the target plan task T1 according to the target execution parameter in the target smart contract, and attach the execution result to the transaction record list to be packaged.

[0091] S608, use the key signature to initiate the target block for packaging the above-mentioned transaction record;

[0092] Wherein, the key signature is saved in the trigger node of the plan task (i.e. the above-mentioned node 1), that is, the key signature is saved in the target blockchain, which reduces the risk of key theft.

[0093] Using the key signature, find the node 1 where the target account associated with the target plan task is located, then produce the first target block (block N+1) in node 1, and package the execution result and the information representing the target plan task T1 into the first target block.

[0094] It should be noted that when the target account creates a new plan task and edits the plan task (modifies, deletes, etc.), the corresponding transaction record will also be generated, therefore, in addition to packaging the first transaction record generated by executing the target plan task into the first target block, it is also necessary to package part of the transaction record generated by creating and editing the plan task into the first target block.

[0095] S610, broadcast the proposal block (first target block) to the target node set;

[0096] After the first transaction record is packaged through the above step S608, the first target block is broadcast to the other consensus nodes in the target node set except node 1, so as to realize the verification of the execution result and the received first target block.

[0097] S612, consensus voting;

[0098] The consensus voting includes a new block of a planned task, consensus reaching, state database updating, light broadcasting of a new block, etc.

[0099] Specifically, after the other consensus nodes (for example, node 2, node 3 and node 4) receive the first target block of the proposal, the block and the first transaction record are verified, wherein the verification contents include but are not limited to confirming whether the execution condition of the corresponding planned task is met, whether the target execution result is correct, etc.

[0100] For example, when the execution condition to be met is to conduct a draw at 8 o'clock in the morning every day, and the actual draw time is 9 o'clock, it is considered that the verification fails; when the number of winning persons of the first prize in the target execution parameter is 2, and the actual number of winning persons is 3, it is considered that the verification fails.

[0101] It is easy to understand that in the process of verifying the execution condition and the target execution result of the above planned task, if there is a failure (one of the execution condition and the target execution result fails, or both fail) in the verification result, it is considered that the consensus is not reached, that is, the verification fails.

[0102] S614-1, in the case of passing the verification, the result of passing the verification is broadcast to the other consensus nodes (for example, node 2 to node 4 in the target node set) in the target node set except node 1, and the state database of node 2 to node 4 is updated; Figure 4

[0103] Optionally, the above updating the state database of node 2 to node 4 can include updating the execution plan state in the state database of node 2 to node 4, for example, increasing the execution times in the execution plan state of the target planned task by 1, and / or adding the execution time of the current time in the execution plan state of the target planned task.

[0104] S614-2, at the same time, in the case of passing the verification, the first target block is written into the local ledger of the main consensus node (for example, as shown in the local ledger including block 1, block 2,..., block N, area N+1); Figure 4

[0105] ​​S616, the other consensus nodes in the target node set except node 1 write the first target block into the local account books respectively.

[0106] Optionally, in the case of passing the verification, the first target block can also be broadcast to the nodes in the target blockchain except the target node set (for example, nodes 5-8 in the target blockchain). Figure 3

[0107] As an optional implementation, before querying the planned task list in the state database of the first node, the method further includes:

[0108] Obtaining the target planned task created by the target account on the second node in the target blockchain;

[0109] Synchronizing the target planned task and the target account obtained on the second node to the state database on each node in the target node set.

[0110] Specifically, as shown in (a) of Figure 7 the implementation process of creating a new planned task in the target blockchain includes:

[0111] S71, selecting the "create" button in the user interface of the target account to realize the creation of a new planned task;

[0112] S72, obtaining the new planned task T3 created by the target account on the second node (node 2) in the target blockchain;

[0113] It should be noted that in this embodiment, assuming that the planned tasks T1 and T2 are currently recorded in the planned task list in the state database, then after the target account creates a new planned task T3 and is packaged into a new block, the planned task T3 is newly recorded in the planned task list in the state database of each node.

[0114] It can be understood that since the target account creates a new planned task and edits (modifies, deletes, etc.) the planned task, a corresponding transaction record is also generated. Therefore, after packaging this part of the transaction record into a new block, the state database of each node is also updated, for example, the planned task T3 is newly recorded in the planned task list in the state database of each node.

[0115] S73, synchronizing the planned task T3 obtained by packaging the new block on node 2 and the target account to nodes 1, 3 and 4.

[0116] As shown in Figure 7 ​As shown in (a), when the new scheduled task T3 is created, the virtual resource Gas-3 required for executing the scheduled task T3 is also configured, wherein the virtual resource Gas-3 is bound with the smart contract invoked when the scheduled task T3 is executed, and the virtual resource Gas-3 is charged into the smart contract when the scheduled task T3 is created.

[0117] After the scheduled task T3 and the target account are synchronized into the state databases on the node 1, the node 3 and the node 4, the state databases on the node 1 to the node 4 all include the three scheduled tasks T1, T2 and T3, and the virtual resources Gas corresponding to the scheduled tasks.

[0118] It can be understood that the virtual resource Gas-3 is a charging resource of the computing resource and the storage resource consumed when the scheduled task T3 is executed on the node 2, for example, the Gas-3 consumed when the scheduled task T3 is executed is 100, and the Gas-1 consumed when the scheduled task T1 is executed is 200. When the scheduled task T3 is actually executed, it is necessary to ensure that the number of the remaining Gas in T3 must be greater than or equal to 100, otherwise the scheduled task T3 cannot be executed on the node 2.

[0119] As an important aspect in the process of creating a new scheduled task, the second node in the embodiment can be but is not limited to the node 2 in the consensus nodes, for example, can also be the node 1, the node 3 and the node 4 in the consensus nodes, and can also be one of the node 5 to the node 8 in the target blockchain. That is, the target scheduled task created by the target account can be obtained on any node in the target blockchain.

[0120] In the above manner, the target scheduled task created by the target account is obtained on any node in the target blockchain, and the obtained target scheduled task and the target account are synchronized into the state databases on other consensus nodes, so as to ensure the consistency of the state databases of all consensus nodes.

[0121] As an optional example, the target account can create, modify and delete the scheduled tasks in the state databases of the consensus nodes by initiating a transaction of invoking the smart contract, specifically including:

[0122] Obtaining the editing operation of the target account on the target scheduled task on the third node in the target blockchain to obtain a target editing result, wherein the editing operation on the target scheduled task includes one of the following: a deletion operation on the target scheduled task, a modification operation on the target scheduled task;

[0123] Synchronizing the target editing result into the state databases on each node in the target node set.

[0124] The above synchronized process can be, but is not limited to, the following process: the information corresponding to the editing process is taken as a transaction record, and the transaction record is packaged into a new block, wherein the information corresponding to the editing process is used to indicate that the target account performs the editing operation on the target plan task and the target editing result obtained; the target editing result is synchronized to the state database on each node in the target node set through synchronization of the new block.

[0125] As shown in (b) of FIG. 10, assuming that the editing operation of the target account on the target plan task is obtained on the node 5 in the target blockchain, as an optional example, the "edit" button is selected on the display interface of the target account, and then the target plan tasks T1, T2 and T3 can be modified, paused or deleted. Figure 7

[0126] Assuming that the editing operation of the target account on the target plan task is to delete the plan task T3, after deleting T3, the target plan task after deletion is synchronized to the state database on all nodes, as shown in (b) of FIG. 11. Figure 7

[0127] Assuming that the editing operation of the target account on the target plan task is to modify the plan task T3, for example, the target execution condition is modified from every Friday morning 9 o'clock to every Saturday morning 9 o'clock, or the target execution parameter is modified from double-color ball to red packet grabbing, etc. Then after completing the modification operation, the plan task T3 is converted to T3', and the modified result is synchronized to the state database on all consensus nodes, as shown in (b) of FIG. 12. Figure 7

[0128] Obviously, it is easy to understand that before performing the editing operation on the target plan tasks T1, T2 and T3, the target account can, but is not limited to, query the existing plan tasks in the current target blockchain through the smart contract, that is, the target plan tasks T1, T2 and T3 are queried.

[0129] It should be noted that in addition to the above editing operation mode, the editing operation on the target plan task can also be the modification of the execution times of the target plan task. For example, the target plan task T3 needs to be executed 10 times in the smart contract, and through the above editing operation, the execution times of the target plan task T3 can be modified from 10 to 2, 1, etc.

[0130] Further, when editing (modifying, deleting, etc.) the above plan task, a corresponding transaction record is also generated, and this part of the transaction record is packaged into a new block.​​​

[0131] For the gasless blockchain, the number of execution times of the target plan task is an optional item. If the user does not set the number of times in advance, the target plan task will be executed once under the condition of meeting the target execution condition. Unless the target account is modified, suspended or deleted, the target plan task will be executed all the time.

[0132] As an optional example, the third node in the embodiment can be, but is not limited to, node 5, and can also be node 1, node 2 or other nodes in the target blockchain.

[0133] Through the above embodiments provided in the application, the editing operation on the target plan task is acquired on the third node in the target blockchain, and the target editing result is synchronized to the state database on each node in the consensus node. Not only the consistency of the state database of all the consensus nodes is ensured, but also the flexibility of executing the target plan task is improved.

[0134] As an optional example, the above method further includes:

[0135] The target plan task is executed on the first node, including: executing the target smart contract according to the target execution parameter on the first node;

[0136] The first transaction record generated by executing the target plan task is packaged into the first target block on the first node, including: packaging the information for indicating the target plan task and the execution result of the target plan task into the first target block on the first node, wherein the first transaction record includes the information for indicating the target plan task and the execution result of the target plan task, and the execution result of the target plan task includes the result obtained by executing the target smart contract according to the target execution parameter.

[0137] With reference to the implementation manner of executing the target plan task in the above embodiments, when it is queried that there is the target plan task meeting the target execution condition in the plan task list, the target smart contract is executed according to the target execution parameter on the first node.

[0138] Still taking the above prize draw as an example, when the target plan task T1 is the prize draw, the target execution parameter corresponding to the target plan task T1 is searched from the method parameter list according to the target account and the target plan task T1 to draw the prize, for example, 10 lucky spectators are drawn at an interval of 10 minutes according to the target execution parameter: the first lucky spectator drawn can obtain a 100-yuan red packet, the second and third lucky spectators drawn can obtain a 50-yuan red packet, and the fourth to tenth lucky spectators drawn can obtain a 10-yuan red packet.

[0139] As Figure 8As shown, the first transaction record generated by executing the target plan task T1 is packaged into the block N+1 generated by the first node, where the first transaction record can be but is not limited to the result of the lottery, for example, account 1 obtains a 100-yuan red packet, and accounts 3 and 4 obtain a 50-yuan red packet. In addition, the first transaction record can also include information for representing the target plan task T1, such as the target account number for creating the target plan task T1, the target execution condition of the target plan task T1, and the like.

[0140] It should be noted that the information for representing the target plan task T1 and the execution result are packaged into the block N+1, so as to find the target plan task T1 in other consensus nodes in the target blockchain through the target account number, and to check the target execution condition and the like. The checking process of the target execution condition will be described in detail in the following embodiments.

[0141] As an optional example, the first transaction record generated by executing the target plan task on the first node is packaged into the first target block, where the execution result includes two cases of packaging success or packaging failure. The following will explain the processing mode for the two different execution results.

[0142] (I) Packaging success

[0143] In the case that the first transaction record is successfully packaged into the first target block on the first node, the second quantity of virtual resources consumed by executing the target plan task is transferred to the first node, where the target plan task is pre-configured with a target quantity of virtual resources allowed to be transferred, and the target quantity is greater than the second quantity.

[0144] When the target account number creates the target plan task, in addition to pre-specifying the target execution condition, the called target smart contract, and the target execution parameter of the target smart contract, the target account also needs to transfer the second quantity of virtual resources Gas consumed by executing the target plan task to the smart contract as a prepayment, which is deducted from the prepayment when executing the target plan task.

[0145] In addition, when creating the target plan task, not only the quantity of virtual resources Gas consumed by executing the target plan task once needs to be configured in the smart contract, but also the target number of times of executing the target plan task and the total quantity of virtual resources Gas consumed by executing the target number of times need to be configured. For example, when the number of times of executing the target plan task is 10 times, and the quantity of Gas consumed by executing once is 100, the total quantity of Gas consumed by executing 10 times is 10*100.

[0146] For example, as shown in FIG. 4, the target plan task T1 is created by the target account number 1, and the target execution condition of the target plan task T1 is that the account number 1 has a balance of 100 yuan, and the target smart contract is the smart contract C1. Figure 7As shown in (a), it is assumed that a new target scheduled task T3 is created on node 2, and the target account transfers a second number of virtual resources Gas consumed by the target scheduled task to the smart contract of the target scheduled task T3, for example, 100 Gas to the smart contract of the target scheduled task T3. In the case that the target scheduled task T3 is executed on node 2 and the corresponding transaction record is successfully packaged into the first target block, the smart contract of the target scheduled task T3 transfers 100 Gas to node 2. It can be seen that the smart contract is used to be responsible for calling the Gas management contract, pre-deducting Gas to the target account of the smart contract, and accounting in the state database.

[0147] In the above manner, the target account needs to transfer the Gas consumed by the transaction to be initiated in the future to the contract when enabling the scheduled task, and the corresponding number of Gas is automatically deducted each time the scheduled task is triggered, thereby preventing the case of theft of Gas or corresponding account keys, and achieving the technical effect of improving the security of executing the scheduled task.

[0148] It can be understood that when the target scheduled task T3 is executed on node 2, it also needs to determine whether the remaining number of virtual resources configured by the target scheduled task T3 meets a preset condition, specifically including:

[0149] Detecting whether the remaining number of virtual resources configured by the target scheduled task is greater than the second number;

[0150] In the case that the remaining number is greater than or equal to the second number, executing the target scheduled task on the first node.

[0151] As an optional example, it is assumed that the remaining number of virtual resources configured in the target scheduled task is 200, and the number of virtual resources consumed by executing the target scheduled task T3 once is 100 Gas. Since node 2 needs to pre-deduct 100 Gas from the smart contract of the target scheduled task T3 when executing the target scheduled task T3, and the remaining number of virtual resources in the smart contract of the target scheduled task T3 is 200 Gas, that is, 200> 100, the target scheduled task T3 can be executed on node 2.

[0152] On the contrary, if the remaining number of virtual resources in the smart contract of the target scheduled task T3 is 50 Gas, that is, 50<100, the target scheduled task T3 cannot be executed on node 2.

[0153] That is, when actually executing the target scheduled task, the remaining number of virtual resources configured by the target scheduled task needs to be used as part of the target execution condition, and only in the case that the preset condition is met, the target scheduled task can be executed.

[0154] In order to keep the local account books of all nodes in the blockchain consistent, a consensus mechanism is usually used to verify the target execution condition and execution result specified in the target planning task, and the specific implementation is as follows:

[0155] In the case that the first transaction record is successfully packaged into the first target block on the first node, the first target block produced by the first node is sent to the nodes other than the first node in the target node set, wherein the nodes other than the first node are used to verify the target execution condition specified in the target planning task and the execution result of the target planning task, and in the case that the verification is passed, the first target block is written into the local account book of the node other than the first node, and the first target block is broadcast to the nodes other than the target node set in the target blockchain.

[0156] As shown in Figure 8 and Figure 9 , it is assumed that the target planning task T1 is executed on node 1, i.e., the above-mentioned lottery, and the transaction record of the lottery is packaged into block N+1, which means that block N+1 is added to the local account book of node 1. In order to keep the local account books of all nodes in the target blockchain consistent, block N+1 will be synchronized to other consensus nodes (e.g., nodes 2-4) other than node 1 and other nodes (e.g., nodes 5-8) other than the consensus nodes in the target blockchain in different ways.

[0157] As shown in Figure 9 , the specific implementation includes:

[0158] S1, block N+1 is sent to the consensus nodes 2-4;

[0159] S2, after receiving the new block N+1, the consensus nodes 2-4 verify the transaction record saved in the block N+1;

[0160] As an example, when the transaction is a transaction of a planning task, the contents to be verified can include but are not limited to whether the execution condition of the planning task is accurate, whether the execution result is correct, etc.

[0161] For example, when the execution condition to be met for executing the target planning task T1 is to perform the lottery at 8 o'clock in the morning every day, and the actual lottery time is 9 o'clock, it is considered that the verification fails; when the number of winning persons of the first prize in the target execution parameter is 2, and the actual number of winning persons in the execution result is 3, it is considered that the verification fails.

[0162] It is easy to understand that in the process of checking the execution condition and the target execution result of the above-mentioned planned task, if there is a failure in the checking result (one of the execution condition and the target execution result fails, or both fail), it is considered that consensus has not been reached, that is, the checking fails.

[0163] S3, when the nodes 2-4 verify the entire blockchain and all transaction records, consensus voting is performed, consensus is reached, and the block N+1 is synchronized to other nodes in the target blockchain.

[0164] In the case of passing the verification, the block N+1 can be written into the local ledger of the consensus nodes 2-4, and the block N+1 can be broadcast to the nodes 5-8.

[0165] It should be noted that the way of synchronizing the block N+1 to other nodes can refer to the synchronization process of the block 1 in Figure 1 , for example, the node 1 sends the produced block N+1 to the network 100, writes the block N+1 into the nodes 2-4 through the network 100, and broadcasts the block N+1 to the nodes 5-8 through the network 100.

[0166] The above technical scheme uses other consensus nodes to verify the entire blockchain and all transaction records, and in the case of passing the verification, the first target block is written or broadcast to other nodes in the target blockchain, which realizes the technical effects of improving the effectiveness of the first target block and ensuring that the local ledgers of all nodes are consistent.

[0167] (2) Packaging failure

[0168] In the case that the execution of the first transaction record is failed to be packaged into the first target block on the first node, the target planned task is executed on the second node, and the second transaction record generated by the execution of the target planned task is packaged into the new second target block produced by the second node, wherein the target node set includes the second node, and the second node is a node that produces a new block after the first node.

[0169] As shown in (a) of Figure 10 , it is assumed that under the condition of meeting the specified time interval, (consensus) nodes 1-4 take turns to produce new blocks, that is, under the condition of the specified time interval, one of the nodes 1-4 is taken as a block node in turn, wherein the generation interval of the block node can be but not limited to seconds.

[0170] It should be noted that when the time interval t1 is met, the node 1 is taken as a block node, but at this time the node 1 only has the right to produce a new block, but actually has not produced a new block.

[0171] Referring to the specific process of executing the target planned task described above, when Node 1 has the authority to produce a new first target block, it first needs to query the planned task list in Node 1's state database to determine whether there are any transaction records to be packaged or target planned tasks that meet the target execution conditions. If there are any transaction records to be packaged or target execution tasks that meet the target execution conditions, a new block is generated on Node 1, and the generated first transaction record is packaged into the new block.

[0172] However, during the process of packaging the first transaction record into the block N+1 to be produced on node 1, the packaging of the first transaction record may fail. The reasons for the packaging failure may include, but are not limited to, the following two situations:

[0173] (1) Node 1 executed the target plan task, but did not produce a new block N+1;

[0174] (2) Node 1 executed the target plan task and produced a new block N+1, but did not package the first transaction record into block N+1.

[0175] In the case where the execution of packaging the first transaction record into the first target block fails on node 1, the transaction record corresponding to the target scheduled task will be packaged by another node when packaging the next block.

[0176] like Figure 10 As shown in (a), assuming that the node that produces a new block after node 1 is node 2, if the execution of packaging the first transaction record into block N+1 on node 1 fails, the second transaction record generated by the target plan task will be packaged into the new second target block produced by the second node on node 2.

[0177] Corresponding to the two situations mentioned above that caused the packaging failure of node 1, the packaging of the second transaction record generated by executing the target scheduled task into the new second target block on node 2 can also be done in the following two situations, but not limited to:

[0178] (1) If node 1 has not produced block N+1, node 2 will package the second transaction record into the new second target block it produces, wherein the number of the second target block is the same as the number of the block N+1 mentioned above.

[0179] (2) If node 1 produces block N+1 but fails to successfully package the first transaction record into block N+1, node 2 will package the second transaction record into the second target block it produces, wherein the second target block is numbered as block N+2.

[0180] Through the above-mentioned embodiments provided in the present application, the execution of the target plan task is jointly supervised by multiple nodes participating in consensus. If the block-producing node does not package the transaction corresponding to the plan task into a block due to various reasons after the execution condition of the plan task is reached, the transaction corresponding to the plan task will be packaged by another node when the next block is packaged, thereby reducing the risk of plan task failure due to single point failure.

[0181] As an optional example, the above-mentioned manner further includes:

[0182] In the case that the first transaction record generated by executing the target plan task fails to be packaged into the first target block on the first node, the first amount of virtual resources is deducted from the first node.

[0183] As Figure 10 As shown in (b) of the figure, when there is a target execution task satisfying the target execution condition on the block-producing node 1, if the block-producing node 1 does not execute the target plan task or fails to package the first transaction record generated by executing the target plan task, the first amount of virtual resources is deducted from the node 1.

[0184] That is, the block-producing node can obtain a Gas benefit by packaging the target plan task transaction into a new block, and can also increase the penalty measure. For the DPOS type consensus mode, the consensus node pays a margin, and if the node is malicious and intentionally excludes the target plan task satisfying the condition from the block when producing the block, the margin will be deducted as a penalty in the subsequent. Effectively avoid the situation that the transaction record generated by executing the target plan task is not packaged after the target plan task reaches the execution condition, and improve the security of executing the plan task on the block chain.

[0185] It should be noted that, for the foregoing method embodiments, in order to simply describe, they are all expressed as a series of action combinations, but those skilled in the art should know that the present application is not limited to the action sequence described, because according to the present application, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should know that the embodiments described in the specification all belong to preferred embodiments, and the actions and modules involved are not necessarily necessary for the present application.

[0186] According to another aspect of the embodiments of the present application, a plan task execution device based on a block chain is also provided, as shown in Figure 11 The device comprises:

[0187] The first processing unit 1102 is configured to query a planned task list in a state database of a first node when the first node in a target blockchain needs to produce a new target block, wherein the nodes in the target blockchain include a target node set, the nodes in the target node set are set to allow production of a new block, the target node set includes the first node, the planned task list records planned tasks to be executed, and each planned task is provided with a corresponding execution condition;

[0188] In order to better understand the embodiments of the present application, first, the basic concept of the blockchain is briefly introduced. The so-called blockchain is a kind of decentralized shared ledger which combines data blocks in the form of chain according to time sequence, and uses cryptography to ensure that it is tamper-proof and unforgeable, and can safely store simple, sequential and verifiable data in the system.

[0189] Generally, the blockchain is a kind of distributed data storage structure without a central node, therefore, the same block information is saved on all nodes, as an optional example, as shown in Figure 3 , it is assumed that the target blockchain includes 8 nodes in total, and the number of blocks in each node and the structure and content of the blocks are the same. For example, N blocks are included in node 1-node 8, and the N blocks are distributed in order of block number from small to large, and the structure and content of the blocks with the same number in node 1-node 8 are the same.

[0190] As an optional example, a plurality of nodes are selected as consensus nodes from the nodes in the target blockchain according to a preset strategy, as shown in Figure 4 , nodes 1-node 4 are selected as consensus nodes from the target blockchain, and the set composed of nodes 1-node 4 is recorded as a target node set. Among them, the consensus node can be understood as being related to the packaging of the transaction record of the execution plan, and the consensus mechanism (for example, different voting principles) is used to realize the packaging processing of the block data.

[0191] As an optional implementation, it is assumed that one node is determined from nodes 1-node 4 in the target node set as a block node in a round-robin manner, for example, node 1 is determined as the block node at the current time according to a preset time interval, and then a state planned task list is queried in the state database of node 1, wherein each planned task T1, T2…T m is provided with a corresponding execution condition Q1, Q2…Q m .

[0192] It should be noted that when node 1 is identified as a block-producing node, it means that node 1 currently has the authority to produce new blocks, but it does not mean that node 1 has already produced a new block. Whether node 1 produces a new block depends on whether there are transactions to be packaged or planned tasks to be executed, and whether the planned tasks to be executed meet the corresponding execution conditions.

[0193] For example, if a transfer of funds from account A to account B is detected, a new block needs to be generated, such as the aforementioned block-producing node 1, to package and upload the transaction record of the transfer of funds from account A to account B onto the blockchain.

[0194] Execution unit 1104 is used to execute the target planned task on the first node when a target planned task that meets the target execution conditions is found in the list of planned tasks. The target planned task specifies the target execution conditions, the target smart contract to be called, and the target execution parameters of the target smart contract.

[0195] As an optional example, the execution conditions in steps S202 and S204 can be, but are not limited to, by means of... Figure 5 The definition rules shown are used to set it, for example, through Figure 5 Use one or more of the fields “minutes”, “hours”, “dates”, “months”, “weekdays”, and “block height” to set the corresponding execution conditions.

[0196] The following is about Figure 5 The fields in the document are explained as follows:

[0197] 1) "*" represents all numbers within the range of values. For example, if the month field is "*", it means months 1 to 12.

[0198] 2) " / " represents a fixed time interval. For example, if the minutes field is * / 10, it means that it will be executed once every 10 minutes. If the block height field is * / 100, it means that it will be executed once every 100 blocks (the block height is divisible by 100).

[0199] 3) "-" represents a range of intervals, which are closed intervals. For example, "2-5" means "2,3,4,5". In the hour field, 0-23 / 2 means that it is executed once every 2 hours within the range of 0 to 23.

[0200] 4)","Dispersed numbers (not necessarily consecutive), such as 1,2,3,4,7,9.

[0201] For example, when it is found in the state database of node 1 that there is a to-be-executed scheduled task T1, and the to-be-executed scheduled task T1 is configured with a corresponding execution condition Q1 of “minute field * / 10”, it is determined whether the current time is an integer multiple of 10 minutes, for example, 1:10, 3:20, etc. If the current time is an integer multiple of 10 minutes, it is determined that the execution condition Q1 is met, and the scheduled task T1 is executed on node 1.

[0202] For example, when the to-be-executed scheduled task T1 is configured with a corresponding execution condition Q1 of “minute field * / 10” and “block height field is * / 100”, it is determined whether the current time is an integer multiple of 10 minutes, and whether the number of the block currently produced by node 1 is an integer multiple of 100. If the current time is an integer multiple of 10 minutes, and the number of the block currently produced by node 1 is an integer multiple of 100, it is determined that the execution condition Q1 is met, and the scheduled task T1 is executed on node 1.

[0203] The second processing unit 1106 is configured to package the first transaction record generated by the execution target scheduled task into the first target block on the first node.

[0204] As an example, the results of the above-mentioned draw, for example, account 1 and account 2 won the first prize, and account 10 to account 20 won the second prize, etc. are packaged into the first target block N+1.

[0205] From the above analysis, it can be seen that when creating a scheduled task, the execution condition for triggering the scheduled task (for example, minute, hour, date, month, week, block height, etc.) and the specific contract name, function name and parameter list for executing after triggering the scheduled task are pre-configured in the scheduled task, so that the triggering of the scheduled task is realized inside the target blockchain, avoiding the single point failure problem in the off-chain triggering process, and reducing the risk of theft of the target scheduled task triggering account, thereby achieving the technical effect of improving the security of executing the scheduled task on the blockchain.

[0206] In order to more clearly understand the above-mentioned execution method of the scheduled task based on the blockchain, the following will be further described in combination with Figure 6 The specific steps include the following steps:

[0207] S602, the main consensus node needs to produce a new first target block;

[0208] The main consensus node can be, but is not limited to, node 1 in the Figure 4 For example, it can also be node 2, node 3 and node 4 in the target node set, etc.

[0209] S604, querying the scheduled task list in the state database in node 1;

[0210] When the target plan task meeting the execution condition is queried, the query result is returned from the state database of node 1 to node 1, and the target plan task is attached to node 1.

[0211] It should be noted that the target execution condition, the called target smart contract and the target execution parameter of the target smart contract have been specified in the target plan task.

[0212] S606, executing the smart contract in the target plan task in node 1;

[0213] As described in the above embodiment, when the target execution condition Q1 is met, the target plan task T1 is executed according to the target execution parameter in the target smart contract, and the execution result is attached to the transaction record list to be packaged.

[0214] S608, using the key signature, initiating the target new block of the above transaction record to the blockchain;

[0215] The key signature is saved in the trigger node of the plan task (i.e. node 1), that is, the key signature is saved in the target blockchain, which reduces the risk of key theft.

[0216] Using the key signature, the node 1 where the target account associated with the target plan task is located is found, and then the first target block (block N+1) is produced in node 1, and the execution result and information representing the target plan task T1 are packaged into the first target block.

[0217] It should be noted that when the target account creates a new plan task and edits (modifies, deletes, etc.) the plan task, corresponding transaction records will also be generated, so in addition to packaging the first transaction record generated by executing the target plan task into the first target block, part of the transaction records generated by creating and editing the plan task also need to be packaged into the first target block.

[0218] S610, broadcasting the proposal block (the first target block);

[0219] After the first transaction record is packaged through the above step S608, the first target block is broadcast to the other consensus nodes in the target node set except node 1, so as to realize the verification of the execution result and the received first target block.

[0220] S612, consensus voting;

[0221] The consensus voting includes the new block of the plan task, consensus, updating the state database, broadcasting the new block, etc.

[0222] Specifically, the first target block and the first transaction record are checked by other consensus nodes (e.g., node 2, node 3, and node 4) after the first target block is received by the proposal, and the checking includes but is not limited to confirming whether the execution condition of the corresponding plan task is met, whether the target execution result is correct, and the like.

[0223] For example, when the execution condition to be met is to conduct the draw at 8:00 am every day, and the actual draw time is 9:00 am, it is considered that the checking fails; when the number of winners of the first prize in the target execution parameter is 2, and the actual number of winners is 3, it is considered that the checking fails.

[0224] It is easy to understand that, in the process of checking the execution condition and the target execution result of the plan task, if there is a failure in the checking result (one of the execution condition and the target execution result fails, or both fail), it is considered that consensus is not reached, that is, the checking fails.

[0225] S614-1, in the case where the checking passes, the result of the passing checking is broadcast to other consensus nodes (e.g., node 2 to node 4 in FIG. 6B) in the target node set except node 1, and the state database of node 2 to node 4 is updated. Figure 4

[0226] Optionally, the updating of the state database of node 2 to node 4 can include updating the execution plan state in the state database of node 2 to node 4, for example, increasing the execution times in the execution plan state of the target plan task by 1, and / or adding the execution time of the current execution in the execution plan state of the target plan task.

[0227] S614-2, at the same time, in the case where the checking passes, the first target block is written into the local ledger of the main consensus node (e.g., as shown in FIG. 6B, the local ledger includes block 1, block 2, …, block N, and area N+1); Figure 4

[0228] S616, other consensus nodes in the target node set except node 1 write the first target block into their respective local ledgers.

[0229] Optionally, in the case where the checking passes, the first target block can also be broadcast to nodes (e.g., node 5 to node 8 in FIG. 6B) in the target blockchain except the target node set. Figure 3

[0230] ​​​By using the above device to configure a scheduled task on a node in a blockchain, when a new block is produced, the node in the blockchain can automatically query whether the execution condition of the scheduled task is met, and automatically execute the scheduled task when the execution condition is met, and package the corresponding transaction record into the newly produced block, without triggering the execution of the scheduled task by a trigger node outside the blockchain, avoiding tampering with the scheduled task and leakage of the private key signature, solving the technical problem of low security in the related art in the process of executing the scheduled task, and improving the security in the process of executing the scheduled task.

[0231] Optionally, the device further comprises:

[0232] a first obtaining unit configured to obtain, on a second node in a target blockchain, a target scheduled task created by a target account;

[0233] a third processing unit configured to synchronize the target scheduled task obtained on the second node and the target account to a state database on each node in a target node set.

[0234] Specifically, as shown in (a) of the method, the implementation process of creating a new scheduled task in the target blockchain includes: Figure 7 S71, selecting a "create" button in a user interface of the target account to implement creation of a new scheduled task;

[0235] S72, obtaining, on a second node (node 2) in the target blockchain, a new scheduled task T3 created by the target account;

[0236] It should be noted that in this embodiment, it is assumed that the scheduled tasks T1 and T2 are currently recorded in the scheduled task list in the state database, and then after the target account creates a new scheduled task T3 and is packaged into a new block, the scheduled task T3 is newly recorded in the scheduled task list in the state database of each node.

[0237] It can be understood that when the target account creates a new scheduled task and edits (modifies, deletes, etc.) the scheduled task, a corresponding transaction record is also generated. Therefore, after packaging this part of the transaction record into a new block, the state database of each node is also updated, for example, the scheduled task T3 is newly recorded in the scheduled task list in the state database of each node.

[0238] S73, synchronizing the scheduled task T3 obtained by packaging the new block on the node 2 and the target account to the node 1, the node 3 and the node 4.

[0239] As shown in (b) of the method,

[0240] Figure 7 ​As shown in (a), when the new scheduled task T3 is created, the virtual resource Gas-3 required for executing the scheduled task T3 is also configured, wherein the virtual resource Gas-3 is bound with the smart contract invoked when the scheduled task T3 is executed, and the virtual resource Gas-3 is charged into the smart contract when the scheduled task T3 is created.

[0241] After the scheduled task T3 and the target account are synchronized into the state databases on the node 1, the node 3 and the node 4, the state databases on the node 1 to the node 4 all include the three scheduled tasks T1, T2 and T3, and the virtual resources Gas corresponding to the scheduled tasks.

[0242] It can be understood that the virtual resource Gas-3 is a charging resource of the computing resource and the storage resource consumed when the scheduled task T3 is executed on the node 2, for example, the Gas-3 consumed when the scheduled task T3 is executed is 100, and the Gas-1 consumed when the scheduled task T1 is executed is 200. When the scheduled task T3 is actually executed, it is necessary to ensure that the number of the remaining Gas in T3 must be greater than or equal to 100, otherwise the scheduled task T3 cannot be executed on the node 2.

[0243] As an important aspect in the process of creating a new scheduled task, the second node in the embodiment can be but is not limited to the node 2 in the consensus node, for example, can also be the node 1, the node 3 and the node 4 in the consensus node, and can also be one of the node 5 to the node 8 in the target blockchain. That is, the target scheduled task created by the target account can be obtained on any node in the target blockchain.

[0244] In the above manner, the target scheduled task created by the target account is obtained on any node in the target blockchain, and the obtained target scheduled task and the target account are synchronized into the state databases on other consensus nodes, so as to ensure the consistency of the state databases of all the consensus nodes.

[0245] Optionally, after the target scheduled task created by the target account is obtained on the third node in the target blockchain, the apparatus further includes:

[0246] The fourth processing unit is configured to obtain an editing operation on the target scheduled task by the target account on the second node in the target blockchain to obtain a target editing result, wherein the editing operation on the target scheduled task includes one of the following: a deletion operation on the target scheduled task, a modification operation on the target scheduled task; and synchronize the target editing result into the state databases on the nodes in the target node set.

[0247] The synchronization process described above may include, but is not limited to, the following: the information corresponding to the editing process is used as a transaction record, and the transaction record is packaged into a new block. The information corresponding to the editing process is used to instruct the target account to perform the above-mentioned editing operation on the target scheduled task and to obtain the target editing result. The target editing result is synchronized to the state database of each node in the target node set through the synchronization of the new block.

[0248] like Figure 7 As shown in (b), assuming that the editing operation of the target account on the target planned task is obtained on node 5 in the target blockchain, as an optional example, if the "Edit" button is selected on the display interface of the target account, the target planned tasks T1, T2 and T3 can be modified, paused or deleted.

[0249] Assuming the target account's edit operation on the target scheduled task is to delete scheduled task T3, after deleting T3, the deleted target scheduled task will be synchronized to the status database on all nodes, such as... Figure 7 As shown in (b), the target planned tasks in the state database of nodes 1 to 4 are changed from T1, T2 and T3 to T1 and T2.

[0250] Suppose the target account's edit operation on the target scheduled task is to modify scheduled task T3, for example, changing the target execution condition from 9 AM every Friday to 9 AM every Saturday, or changing the target execution parameters from lottery to red envelope giveaway, etc. After the modification operation is completed, scheduled task T3 is converted to T3', and the modified result is synchronized to the state database on all consensus nodes, such as... Figure 7 As shown in (b), the target planned tasks in the state database of nodes 1 to 4 are transformed from T1, T2 and T3 to T1, T2 and T3'.

[0251] Obviously, it is easy to understand that before performing editing operations on target planned tasks T1, T2, and T3, the target account can, but is not limited to, query the existing planned tasks in the current target blockchain through smart contracts, that is, query the target planned tasks T1, T2, and T3.

[0252] It should be noted that, in addition to the editing operations described above, editing the target scheduled task can also involve modifying the number of times the target scheduled task is executed. For example, if the smart contract is pre-configured to require target scheduled task T3 to be executed 10 times, the above editing operations can be used to change the number of executions of target scheduled task T3 from 10 to 2, 1, etc.

[0253] Furthermore, when editing (modifying, deleting, etc.) the above-mentioned planned tasks, corresponding transaction records will be generated, and these transaction records will be packaged into a new block.

[0254] For gas-free blockchains, the number of times a target scheduled task is executed is optional. If the user does not pre-set this number, the task will be executed once if the target execution conditions are met. Unless the scheduled task is modified, paused, or deleted by the target account, it will continue to be executed.

[0255] As an optional example, the third node in this embodiment may be, but is not limited to, node 5, or may be node 1, node 2, or other nodes in the target blockchain.

[0256] Optionally, the above-mentioned device further includes:

[0257] The fifth processing unit is used to execute the target smart contract on the first node according to the target execution parameters; and to package the information representing the target planned task and the execution result of the target planned task into the first target block on the first node, wherein the first transaction record includes the information representing the target planned task and the execution result of the target planned task, and the execution result of the target planned task includes the result obtained by executing the target smart contract according to the target execution parameters.

[0258] Referring to the implementation method of executing the target planned task in the above embodiments, if a target planned task that meets the target execution conditions is found in the list of planned tasks, the target smart contract is executed on the first node according to the target execution parameters.

[0259] Taking the lottery as an example again, when the target task T1 is a lottery, the lottery is performed by searching for the target execution parameters corresponding to the target task T1 from the method parameter list according to the target account and the target task T1. For example, according to the target execution parameters: 10 lucky viewers are drawn at intervals of 10 branches. The first lucky viewer can get a red envelope of 100 yuan, the second and third lucky viewers can get a red envelope of 50 yuan, and the fourth to tenth lucky viewers can get a red envelope of 10 yuan.

[0260] like Figure 8 As shown, the first transaction record generated by executing the target scheduled task T1 is packaged into block N+1 generated by node 1. This first transaction record can include, but is not limited to, the result of a lottery draw; for example, account 1 receives a 100 yuan red envelope, and accounts 3 and 4 receive 50 yuan red envelopes. In addition, the first transaction record can also include information representing the target scheduled task T1, such as the target account for creating the target scheduled task T1 and the target execution conditions for the target scheduled task T1.

[0261] It should be noted that the purpose of packaging the information representing the target task T1 along with the execution result into block N+1 is to locate the target task T1 among other consensus nodes in the target blockchain using the target account, and to verify the target execution conditions. The verification process of the target execution conditions will be described in detail in the following embodiments.

[0262] Optionally, the above-mentioned device further includes:

[0263] The sixth processing unit is used to execute the target plan task on the second node if the execution of the first transaction record into the first target block fails on the first node, and to package the second transaction record generated by the execution of the target plan task into the new second target block produced by the second node on the second node. The target node set includes the second node, which is the node that produces the new block after the first node.

[0264] like Figure 10 As shown in (a), it is assumed that under the condition of satisfying a specified time interval, (consensus) nodes 1 to 4 take turns producing new blocks. That is, under the condition of a specified time interval, one of nodes 1 to 4 is taken as the block producing node in turn. The generation interval of the block producing node can be, but is not limited to, seconds.

[0265] It should be noted that when the time interval t1 is met, node 1 is designated as the block-producing node. However, at this time, node 1 only has the authority to produce new blocks, but has not actually produced any new blocks.

[0266] Referring to the specific process of executing the target planned task described above, when Node 1 has the authority to produce a new first target block, it first needs to query the planned task list in Node 1's state database to determine whether there are any transaction records to be packaged or target planned tasks that meet the target execution conditions. If there are any transaction records to be packaged or target execution tasks that meet the target execution conditions, a new block is generated on Node 1, and the generated first transaction record is packaged into the new block.

[0267] However, during the process of packaging the first transaction record into the block N+1 to be produced on node 1, the packaging of the first transaction record may fail. The reasons for the packaging failure may include, but are not limited to, the following two situations:

[0268] (3) Node 1 executed the target plan task, but did not produce a new block N+1;

[0269] (4) Node 1 executed the target plan task and produced a new block N+1, but did not package the first transaction record into block N+1.

[0270] In the case that the first transaction record fails to be packaged into the first target block on the node 1, the second transaction record generated by the target planning task is packaged into a new second target block produced by another node when the next block is packaged.

[0271] As shown in (a) of FIG. 6, assuming that the node 2 produces a new block after the node 1, in the case that the first transaction record fails to be packaged into the block N+1 on the node 1, the second transaction record generated by the target planning task is packaged into a new second target block produced by the node 2. Figure 10

[0272] Corresponding to the two cases of the above reasons causing the packaging failure of the node 1, the second transaction record generated by the target planning task is packaged into a new second target block on the node 2, which can be but is not limited to the following two cases:

[0273] (3) In the case that the node 1 does not produce the block N+1, the node 2 packages the second transaction record into a new second target block produced by the node 2, wherein the number of the second target block is the same as the number of the block N+1;

[0274] (4) In the case that the node 1 produces the block N+1 but fails to package the first transaction record into the block N+1, the node 2 packages the second transaction record into a second target block produced by the node 2, wherein the number of the second target block is the block N+2.

[0275] Through the above embodiments provided in the present application, the execution of the target planning task is supervised and executed by multiple nodes participating in consensus, and if the block producing node fails to package the transaction corresponding to the planning task due to various reasons after the execution condition of the planning task is reached, the transaction corresponding to the planning task is packaged by another node when the next block is packaged, thereby reducing the risk of planning task failure caused by single point failure.

[0276] Optionally, the apparatus further includes:

[0277] The seventh processing unit is configured to, in the case that the first transaction record generated by the target planning task fails to be packaged into the first target block on the first node, deduct the first amount of virtual resources from the first node.

[0278] As shown in (b) of FIG. 6, in the case that the block producing node 1 has a target execution task satisfying the target execution condition, if the block producing node 1 does not execute the target planning task or fails to package the first transaction record generated by the execution of the target planning task, the first amount of virtual resources is deducted from the node 1. Figure 10

[0279] ​​That is, the block-producing node can obtain a gas reward by packaging the target plan task transaction into a new block, and can also increase the punishment measure. For the DPOS type consensus mode, the consensus node pays a margin, and if the node is malicious, the target plan task that meets the condition is deliberately excluded from the block during block production, and is not packaged. The margin will be deducted as a penalty in the subsequent. Effectively avoid the situation that the transaction record generated by executing the target plan task is not packaged after the target plan task reaches the execution condition, and improve the security of executing the plan task on the blockchain.

[0280] Optionally, the apparatus further comprises:

[0281] The eighth processing unit is configured to, in a case where the first node successfully packages the first transaction record into the first target block, transfer the second quantity of virtual resources consumed by executing the target plan task to the first node, wherein the target plan task is pre-configured with a target quantity of virtual resources allowed to be transferred, and the target quantity is greater than the second quantity.

[0282] When the target account creates the target plan task, in addition to pre-specifying the target execution condition, the called target smart contract, and the target execution parameter of the target smart contract, the target account also needs to transfer the second quantity of virtual resources Gas consumed by executing the target plan task to the smart contract as a prepayment of virtual resources Gas, which is deducted from the prepayment when executing the target plan task.

[0283] In addition, when creating the target plan task, not only the quantity of virtual resources Gas consumed by executing the target plan task once needs to be configured in the smart contract, but also the target number of times of executing the target plan task and the total quantity of virtual resources Gas consumed by executing the target number of times need to be configured. For example, when the number of times of executing the target plan task is 10 times, and the quantity of Gas consumed by executing once is 100, the total quantity of Gas consumed by executing 10 times is 10*100.

[0284] For example, as shown in (a) of Figure 7 For example, as shown in (a) of

[0285] By the above manner, the target account needs to transfer the gas consumed by the future transaction to be initiated to the contract when enabling the scheduled task, and the corresponding amount of gas is automatically deducted each time the scheduled task is triggered, thereby preventing the gas or the corresponding account key from being stolen, and achieving the technical effect of improving the security of executing the scheduled task.

[0286] Optionally, the executing the target scheduled task on the first node comprises:

[0287] detecting whether the remaining quantity of the virtual resource configured in the target scheduled task is greater than the second quantity;

[0288] the ninth processing unit is configured to execute the target scheduled task on the first node in a case where the remaining quantity is greater than or equal to the second quantity.

[0289] As an optional example, it is assumed that the remaining quantity of the virtual resource configured in the target scheduled task is 200, and the quantity of the virtual resource consumed by executing the target scheduled task T3 is 100 gas. Since the node 2 needs to deduct 100 gas from the smart contract of the target scheduled task T3 when executing the target scheduled task T3, and the remaining quantity of the virtual resource in the smart contract of the target scheduled task T3 is 200 gas, i.e., 200>100, the target scheduled task T3 can be executed on the node 2.

[0290] On the contrary, if the remaining quantity of the virtual resource in the smart contract of the target scheduled task T3 is 50 gas, i.e., 50<100, the target scheduled task T3 cannot be executed on the node 2.

[0291] That is, when actually executing the target scheduled task, the remaining quantity of the virtual resource configured in the target scheduled task needs to be taken as part of the target execution condition, and the target scheduled task can be executed only when the preset condition is met.

[0292] Optionally, the apparatus further comprises:

[0293] the tenth processing unit is configured to, in a case where the packing of the first transaction record into the first target block on the first node is successful, send the first target block produced by the first node to the nodes other than the first node in the target node set, wherein the nodes other than the first node are used to verify the target execution condition specified in the target scheduled task and the execution result of the target scheduled task, and in a case where the verification is passed, write the first target block into the local ledger of the nodes other than the first node, and broadcast the first target block to the nodes other than the target node set in the target block chain.

[0294] As Figure 8 and Figure 9As shown, assuming that the target plan task T1 is executed on node 1, such as the draw in the above embodiment, and the transaction record of the draw is packaged into the block N+1, it means that the block N+1 is added to the local ledger of node 1. In order to keep the local ledgers of all nodes in the target blockchain consistent, the block N+1 is synchronized to the other consensus nodes (for example, nodes 2-4) except node 1 and the other nodes (for example, nodes 5-8) in the target blockchain in different ways.

[0295] As shown in Figure 9 the specific implementation includes:

[0296] S1, sending the block N+1 to the consensus nodes 2-4;

[0297] S2, after receiving the new block N+1, the consensus nodes 2-4 verify the transaction record saved in the block N+1.

[0298] As an example, when the transaction is a plan task transaction, the contents to be verified can include but are not limited to whether the execution condition of the plan task is accurate, whether the execution result is correct, etc.

[0299] For example, when the execution condition to be met for executing the target plan task T1 is to draw at 8 o'clock in the morning every day, and the actual draw time is 9 o'clock, it is considered that the verification fails; when the number of winners of the first prize in the target execution parameter is 2, and the actual number of winners in the execution result is 3, it is considered that the verification fails.

[0300] It is easy to understand that in the process of verifying the execution condition and the target execution result of the above plan task, if there is a failure in the verification result (one of the execution condition and the target execution result fails, or both fail), it is considered that consensus is not reached, that is, the verification fails.

[0301] S3, when the nodes 2-4 verify the entire blockchain and all transaction records, consensus voting is performed, consensus is reached, and the block N+1 is synchronized to the other nodes in the target blockchain.

[0302] Among them, in the case of passing the verification, the block N+1 can be written into the local ledger of the consensus nodes 2-4, and the block N+1 is broadcast to the nodes 5-8.

[0303] It should be noted that the way of synchronizing the block N+1 to other nodes can refer to Figure 1In the synchronization process of block 1, for example, node 1 sends the produced block N+1 to the network 100, writes the block N+1 to nodes 2-4 through the network 100, and broadcasts the block N+1 to nodes 5-8 through the network 100.

[0304] By using the above technical solution, the entire blockchain and all transaction records are verified by other consensus nodes, and the first target block is written or broadcast to other nodes in the target blockchain under the condition that the verification is passed, thereby achieving the technical effects of improving the effectiveness of the first target block and ensuring that the local ledgers of all nodes remain consistent.

[0305] Optionally, the first processing unit described above further includes:

[0306] The detection module is configured to, in a case where the target execution condition includes a target block height, and the target block height indicates that a target plan task is executed once every N blocks, detect whether a number of the first target block to be produced is M*N, where N is a positive integer greater than or equal to 2, and M is a positive integer greater than or equal to 1.

[0307] The determination module is configured to, in a case where it is detected that the number of the first target block to be produced is M*N, determine that the target plan task that meets the target execution condition exists in the plan task list.

[0308] By applying the above device to the part of the target smart contract as the plan task, the triggering of the target plan task is realized within the target blockchain, avoiding the single point failure problem in the off-chain triggering process, and reducing the risk of theft of the target plan task triggering account, thereby achieving the technical effect of improving the security of executing the plan task on the blockchain.

[0309] It should be noted that the embodiments of the plan task execution device based on the blockchain can refer to the embodiments of the plan task execution method based on the blockchain described above, which will not be described here.

[0310] According to another aspect of the embodiments of the present application, an electronic device for implementing the above-mentioned plan task execution method based on the blockchain is also provided, which can be Figure 12 The terminal device as shown. This embodiment takes the electronic device as the background device as an example to illustrate. As Figure 12 shown, the electronic device includes a memory 1202 and a processor 1204, the memory 1202 stores a computer program, and the processor 1204 is configured to execute the steps in any of the method embodiments described above through the computer program.

[0311] Optionally, in this embodiment, the electronic device described above can be located in at least one of the plurality of network devices in the computer network.

[0312] Optionally, in the embodiment, the processor can be configured to execute the following steps by means of a computer program:

[0313] S1, when a first node in a target blockchain needs to produce a new first target block, querying a scheduled task list in a state database of the first node, wherein the nodes in the target blockchain include a target node set, the nodes in the target node set are configured to allow the production of a new block, the target node set includes the first node, the scheduled task list records scheduled tasks to be executed, and each scheduled task is configured with a corresponding execution condition;

[0314] S2, in the case where it is queried that there is a target scheduled task meeting a target execution condition in the scheduled task list, executing the target scheduled task on the first node, wherein the target execution condition, a target smart contract to be called, and a target execution parameter of the target smart contract are specified in the target scheduled task;

[0315] S3, packaging a first transaction record generated by executing the target scheduled task into the first target block on the first node.

[0316] Optionally, those skilled in the art can understand that, Figure 12 The structure shown is only schematic, and the electronic device can also be a smart phone (such as an Android phone, an iOS phone, etc.), a tablet computer, a palm computer, a Mobile Internet Device (MID), a PAD, or the like. Figure 12 It does not limit the structure of the electronic device. For example, the electronic device can include more or fewer components (such as a network interface, etc.) than those shown in Figure 12 , or have a different configuration from Figure 12 .

[0317] The memory 1202 can be used to store software programs and modules, such as program instructions / modules corresponding to the plan task execution method and device based on a blockchain in the embodiments of the present application. The processor 1204 can execute various functions and data processing, i.e., implement the plan task execution method based on a blockchain by running the software programs and modules stored in the memory 1202. The memory 1202 can include a high-speed random access memory, and can further include a non-volatile memory, such as one or more magnetic storage devices, flash memories, or other non-volatile solid-state memories. In some examples, the memory 1202 can further include a memory remotely arranged with respect to the processor 1204, which can be connected to the terminal through a network. Examples of the network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and a combination thereof. Specifically, the memory 1202 can be used to store, but is not limited to, a local ledger of each node in a target blockchain, block information of each block, a plan task list, and the like. As an example, as shown in FIG. 17, the memory 1202 can include, but is not limited to, the first processing unit 1102, the execution unit 1104, and the second processing unit 1106 in the plan task execution device based on a blockchain. In addition, other module units in the plan task execution device based on a blockchain can also be included, which will not be described herein. Figure 12

[0318] Optionally, the transmission device 1206 is configured to receive or send data via a network. Specific examples of the network can include wired networks and wireless networks. In an example, the transmission device 1206 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices and routers through a network cable to communicate with the Internet or a local area network. In an example, the transmission device 1206 is a radio frequency (Radio Frequency, RF) module, which is configured to communicate with the Internet in a wireless manner.

[0319] In addition, the electronic device further includes a display 1208 configured to display the allowed push media resource, and a connection bus 1210 configured to connect various module components in the electronic device.

[0320] ​In other embodiments, the target terminal or server described above can be a node in a distributed system, where the distributed system can be a blockchain system, which can be a distributed system formed by the plurality of nodes connected through network communication. Among them, nodes can form a peer-to-peer (P2P, Peer To Peer) network, and any form of computing device, such as a server, terminal, and other electronic devices, can become a node in the blockchain system by joining the peer-to-peer network.

[0321] According to an aspect of the present application, a computer program product or computer program is provided, which includes computer instructions stored in a computer readable storage medium. The processor of the computer device reads the computer instructions from the computer readable storage medium, and the processor executes the computer instructions to make the computer device execute the blockchain-based scheduled task execution method provided in various optional implementation manners of the above-mentioned server verification processing and the like, wherein the computer program is set to execute the steps in any of the method embodiments when running.

[0322] Optionally, in the present embodiment, the computer readable storage medium described above can be set to store a computer program for executing the following steps:

[0323] S1, when a first node in a target blockchain needs to produce a new first target block, querying a scheduled task list in a state database of the first node, wherein the nodes in the target blockchain include a target node set, the nodes in the target node set are set to allow the production of a new block, the target node set includes the first node, the scheduled task list records scheduled tasks to be executed, and each scheduled task is set with a corresponding execution condition;

[0324] S2, in the case where it is queried that there is a target scheduled task meeting a target execution condition in the scheduled task list, executing the target scheduled task on the first node, wherein the target execution condition, a target smart contract called, and a target execution parameter of the target smart contract are specified in the target scheduled task;

[0325] S3, packaging a first transaction record generated by executing the target scheduled task on the first node into the first target block.

[0326] Optionally, in the embodiment, all or part of the steps in the various methods of the above embodiments can be understood by those of ordinary skill in the art that the program can instruct the hardware related to the target terminal to complete, and the program can be stored in a computer readable storage medium, and the storage medium can include a flash disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.

[0327] The serial numbers of the embodiments of the present application are only for description, and do not represent the advantages and disadvantages of the embodiments.

[0328] The integrated units in the above embodiments, if realized in the form of software function units and sold or used as independent products, can be stored in the above computer readable storage medium. Based on such understanding, the technical solutions of the present application or the whole or part of the technical solutions that essentially contribute to the prior art can be embodied in the form of a software product, and the computer software product stored in the storage medium includes a plurality of instructions for causing one or more computer devices (which can be personal computers, servers or network devices, etc.) to execute all or part of the steps of the embodiment methods.

[0329] In the above embodiments of the present application, the description of each embodiment has its own focus, and the parts not described in detail in a certain embodiment can be referred to the related description of other embodiments.

[0330] In several embodiments provided in the present application, it should be understood that the disclosed client can be implemented by other ways. Among them, the above described device embodiments are only schematic, for example, the division of units is only a logical function division, and actual implementation can have another division manner, for example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the displayed or discussed each other can be through some interface, indirect coupling or communication connection between units or modules, which can be electrical or other forms.

[0331] The units described as separate components can or can not be physically separated, and the components displayed as units can or can not be physical units, that is, they can be located in one place, or can be distributed on multiple network units. According to actual needs, part or all of the units can be selected to achieve the purpose of the embodiment scheme.

[0332] In addition, each function unit in each embodiment of the present application can be integrated in one processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of a software function unit.

[0333] The above is only the preferred embodiment of the present application, and it should be noted that, for those skilled in the art, without departing from the principles of the present application, a number of improvements and refinements can be made, and these improvements and refinements should also be considered as the protection scope of the present application.

Claims

1. A blockchain-based method for executing scheduled tasks, characterized in that, include: When the first node in the target blockchain needs to produce a new first target block, the planned task list is queried in the state database of the first node. The nodes in the target blockchain include a set of target nodes, and the nodes in the set of target nodes are set to allow the production of new blocks. The set of target nodes includes the first node. The planned task list records the planned tasks to be executed, and each planned task is set with corresponding execution conditions. If a target scheduled task that meets the target execution conditions is found in the list of scheduled tasks, the target scheduled task is executed on the first node, wherein the target scheduled task specifies the target execution conditions, the target smart contract to be invoked, and the target execution parameters of the target smart contract; On the first node, the first transaction record generated by executing the target plan task is packaged into the first target block; The method further includes: if the execution of the first transaction record is successfully packaged into the first target block on the first node, the first target block produced by the first node is sent to nodes other than the first node in the target node set, wherein the nodes other than the first node are used to verify the target execution conditions specified in the target planned task and the execution result of the target planned task. If the verification passes, the first target block is written into the local ledger of the nodes other than the first node, and the first target block is broadcast to the nodes other than the target node set in the target blockchain.

2. The method according to claim 1, characterized in that, Before querying the planned task list in the status database of the first node, the method further includes: Obtain the target planned task created by the target account on the second node of the target blockchain; The target planned task and the target account obtained on the second node are synchronized to the status database of each node in the target node set.

3. The method according to claim 2, characterized in that, After retrieving the target scheduled task created by the target account on the second node in the target blockchain, the method further includes: On the third node of the target blockchain, obtain the editing operation of the target account on the target planned task to obtain the target editing result, wherein the editing operation on the target planned task includes one of the following: deletion operation on the target planned task, modification operation on the target planned task; The target editing results are synchronized to the status database of each node in the target node set.

4. The method according to claim 1, characterized in that, The step of executing the target planned task on the first node includes: executing the target smart contract on the first node according to the target execution parameters; The step of packaging the first transaction record generated by executing the target planned task into the first target block on the first node includes: packaging information representing the target planned task and the execution result of the target planned task into the first target block on the first node, wherein the first transaction record includes information representing the target planned task and the execution result of the target planned task, and the execution result of the target planned task includes the result obtained by executing the target smart contract according to the target execution parameters.

5. The method according to claim 1, characterized in that, The method further includes: If the execution of the first transaction record into the first target block fails at the first node, the target planned task is executed at the second node, and the second transaction record generated by the execution of the target planned task is packaged into the new second target block produced by the second node. The target node set includes the second node, which is the node that produces the new block after the first node.

6. The method according to claim 5, characterized in that, The method further includes: If the first transaction record generated by executing the target task fails to be packaged into the first target block on the first node, a first amount of virtual resources shall be deducted from the first node.

7. The method according to claim 1, characterized in that, The method further includes: If the execution of the first transaction record is successfully packaged into the first target block on the first node, the second number of virtual resources consumed in executing the target scheduled task are transferred to the first node, wherein the target scheduled task is pre-configured with a target number of virtual resources that can be transferred, and the target number is greater than the second number.

8. The method according to claim 7, characterized in that, Executing the target planned task on the first node includes: Detect whether the remaining quantity of the virtual resources configured in the target scheduled task is greater than the second quantity; If the remaining quantity is greater than or equal to the second quantity, the target planned task is executed on the first node.

9. The method according to any one of claims 1 to 8, characterized in that, The query schedule task list also includes: When the target execution conditions include the target block height, and the target block height represents the execution of the target planned task once every N blocks, it is detected whether the number of the first target block to be produced is M×N, where N is a positive integer greater than or equal to 2, and M is a positive integer greater than or equal to 1. If the number of the first target block to be produced is detected to be M×N, it is determined that there is a target planned task in the list of planned tasks that meets the target execution conditions.

10. A blockchain-based scheduled task execution device, characterized in that, include: The first processing unit is used to query the planned task list in the state database of the first node when the first node in the target blockchain needs to produce a new first target block. The nodes in the target blockchain include a target node set, the nodes in the target node set are set to allow the production of new blocks, the target node set includes the first node, and the planned task list records planned tasks to be executed, each planned task is set with corresponding execution conditions. An execution unit is configured to execute the target planned task on the first node when a target planned task that meets the target execution conditions is found in the list of planned tasks. The target planned task specifies the target execution conditions, the target smart contract to be invoked, and the target execution parameters of the target smart contract. The second processing unit is used to package the first transaction record generated by executing the target plan task into the first target block on the first node; The device is further configured to, upon successful packaging of the execution record of the first transaction into the first target block on the first node, send the first target block produced by the first node to nodes other than the first node in the target node set, wherein the nodes other than the first node are configured to verify the target execution conditions specified in the target planned task and the execution result of the target planned task, and if the verification passes, write the first target block into the local ledger of the nodes other than the first node, and broadcast the first target block to nodes in the target blockchain other than the target node set.

11. The apparatus according to claim 10, characterized in that, The device further includes: The acquisition unit is used to acquire the target planned task created by the target account on the second node in the target blockchain; The third processing unit is used to synchronize the target planned task and the target account obtained on the second node to the status database of each node in the target node set.

12. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored program, wherein the program is executed by a processor to perform the method of any one of claims 1 to 9.

13. A computer program product comprising a computer program / instructions, characterized in that, When the computer program / instructions are executed by the processor, they implement the steps of the method described in any one of claims 1 to 9.

14. An electronic device comprising a memory and a processor, characterized in that, The memory stores a computer program, and the processor is configured to execute the method of any one of claims 1 to 9 through the computer program.

Citation Information

Patent Citations

  • Task execution method and device based on smart contract

    CN113098983A