Intelligent contract timing processing method, block chain node and storage medium
Technical Field
The invention relates to the technical field of block chains, in particular to an intelligent contract timing processing method, a block chain node and a storage medium.
Background
The intelligent contract is the most important component of the blockchain application, and can create credible, safe and verifiable computation depending on the implementation of the intelligent contract. Since the smart contracts satisfy the requirement of repeatable verification, it is required that any machine re-executes the smart contracts contained in all blocks at any time, and the obtained result is consistent with the results of other nodes, and further, the contract virtual machine is a deterministic execution environment, so that the virtual machine cannot actively access the external environment, including time and the like, because the data of the external environment is uncontrollable and the execution result may be influenced.
Therefore, there is a need to provide a block chain intelligent contract timing processing scheme to solve the technical problem that an intelligent contract cannot be automatically triggered on a block chain node, and a wallet or other intelligent contract is needed to trigger.
Disclosure of Invention
The invention mainly aims to provide a block chain intelligent contract timing processing method, a block chain node and a storage medium, and aims to solve the technical problem that a block chain intelligent contract cannot be automatically executed.
In order to achieve the above object, a first aspect of the present invention provides a method for processing block chain intelligent contracts at regular time, where the method includes:
receiving an intelligent contract transaction request;
checking whether the timer expires;
responding to an expired timer, calling a smart contract to execute a transaction according to the expired timer and generating a global state;
generating a new block according to the global state;
broadcasting the new block to other blockchain nodes in a blockchain network.
According to an alternative embodiment of the invention, the method further comprises:
monitoring a new block generation event in the block chain;
when the generation of a new block is monitored, whether a timer expired or not is checked according to the timestamp of the new block;
responding to an expired timer, calling a smart contract to execute a transaction according to the expired timer and generating a global state;
verifying whether the generated global state is consistent with the global state in the new block;
in response to the generated global state and the global state in the new tile being consistent, determining that the new tile is legitimate and voting for the new tile.
According to an optional embodiment of the present invention, said invoking the smart contract to execute the transaction and generate the global state according to the expired timer comprises:
determining a temporal order of the expired timers;
judging whether a plurality of expired timers exist at the same time;
responding to a timer which expires at the same time, executing the intelligent contract according to the time sequence of the expired timer and generating a global state;
and responding to a plurality of expired timers at the same time, executing the intelligent contract according to the time sequence of the expired timers and the arrangement sequence of the expired timers at the same time, and generating a global state.
According to an optional embodiment of the present invention, prior to the receiving the smart contract transaction request, the method further comprises:
receiving a timer set by a user and storing the timer;
broadcasting the timer to the other blockchain nodes.
According to an optional embodiment of the present invention, prior to the receiving the smart contract transaction request, the method further comprises:
a timer for receiving the other block link point broadcast;
and storing the timer.
According to an optional embodiment of the present invention, after the invoking the smart contract to execute the transaction and generate the global state according to the expired timer, the method further comprises:
identifying whether the expired timer is in a single-shot mode or a cycle-shot mode;
in response to the expired timer being the cycle trigger mode, storing the timer again.
According to an optional embodiment of the invention, after the receiving the smart contract transaction request, the method further comprises:
calculating a transaction commission fee according to the intelligent contract transaction request;
and acquiring the commission charge from the contract account corresponding to the intelligent contract transaction request.
According to an alternative embodiment of the invention, the method further comprises:
in response to the generated global state and the global state in the new tile not being consistent, determining that the new tile is illegal and discarding the new tile.
In order to achieve the above object, a second aspect of the present invention provides a block chain node, where the block chain node includes a memory and a processor, the memory stores a downloading program of a block chain intelligent contract timing processing method that is executable on the processor, and the downloading program of the block chain intelligent contract timing processing method implements the block chain intelligent contract timing processing method when executed by the processor.
In order to achieve the above object, a third aspect of the present invention provides a computer-readable storage medium, on which a downloading program of a block chain intelligent contract timing processing method is stored, where the downloading program of the block chain intelligent contract timing processing method is executable by one or more processors to implement the block chain intelligent contract timing processing method.
The block chain intelligent contract timing processing method, the block chain nodes and the storage medium are used as block chain link points of an proposing node or a block outlet node, when an intelligent contract transaction request is received, the virtual machine calls the intelligent contract to execute transaction according to an expired timer, a new block is generated and broadcasted, the requirement of the timer for programming the intelligent contract can be met, and the automatic calling of the intelligent contract is realized. And when a new block is monitored to be generated as a voting node or a non-block-out node, calling an intelligent contract to execute transaction according to the expired timer and generate a global state, and determining whether the new block is legal or not according to the global state. The running of the timer is performed by the trusted environment of the block chain, so that the timer requirement of the application for the programming of the contract can be met, and the verifiable consistency of any node of the block at any time later is realized.
Drawings
Fig. 1 is a schematic flow chart of a block chain intelligent contract timing processing method according to a first embodiment of the present invention;
FIG. 2 is a functional block diagram of a block chain intelligent contract timing processing apparatus according to a second embodiment of the present invention;
fig. 3 is a schematic structural diagram of a blockchain node according to a third embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The terms "first" and "second" in the description and claims of the present application and the above-described drawings are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It will be appreciated that the data so used may be interchanged under appropriate circumstances such that the embodiments described herein may be practiced otherwise than as specifically illustrated or described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
In addition, technical solutions between various embodiments may be combined with each other, but must be realized by a person skilled in the art, and when the technical solutions are contradictory or cannot be realized, such a combination should not be considered to exist, and is not within the protection scope of the present invention.
Example one
Fig. 1 is a flowchart illustrating a method for timing processing a blockchain intelligent contract according to a first embodiment of the present invention.
The block chain intelligent contract timing processing method can be applied to block chain nodes. The block chain intelligent contract timing processing method specifically comprises the following steps, the sequence of the steps in the flow chart can be changed according to different requirements, and certain steps can be omitted.
And S11, receiving the intelligent contract trading request.
The intelligent contract is a program on the block chain, is called by an external user, runs according to a preset program, and can perform repeated verification on all block chain link points.
The user can send an intelligent contract transaction request to a certain block chain node in the block chain network through the client device to request to execute the intelligent contract transaction. Such as money transfers, purchases, etc. Wherein the intelligent contract transaction request includes description information for executing a contract. The description information of the execution contract may include: input parameters for executing contracts, etc.
In an optional embodiment of the invention, prior to the receiving the smart contract transaction request, the method may further comprise:
receiving a timer set by a user and storing the timer;
broadcasting the timer to the other blockchain nodes.
Wherein the timer refers to a tool for issuing certain actions at a pre-designed point in time. The timer counts in the operation of the processor through a high-speed data bus, and the accuracy of the time sequence is ensured.
In this alternative embodiment, the user may preset the trigger mode of the timer, the trigger condition of the timer, and the execution action after triggering the timer. The trigger modes of the timer include a single trigger mode and a cycle trigger mode. The trigger conditions of the timer include, but are not limited to: triggering at a preset time point, triggering after the virtual machine is started for a preset time period, and triggering every other preset time period after the virtual machine is started. The action performed by the timer may be a function or functions. After the user sets the timer, the timer can be sent to the blockchain node through the client device. And after receiving the timer, the block chain link point stores the timer in a local timer queue and broadcasts the timer to other block chain link points in the block chain network.
In an optional embodiment of the invention, prior to the receiving the smart contract transaction request, the method may further comprise:
a timer for receiving the other block link point broadcast;
and storing the timer.
In this alternative embodiment, after the user sets the timer, the timer may be sent to any one of the blockchain nodes in the blockchain network through the client device. The any one block link point refers to any one node device in the other block link nodes. Any one of the blockchain nodes broadcasts the received timer to the blockchain network. Thus, the blockchain node receives timers broadcast by other blockchain nodes and stores the timers in a local timer queue.
It should be noted that, in this embodiment, the block chain node that executes the block chain intelligent contract timing processing method is referred to as a proposal node or a block node, and the other block chain nodes opposite to the proposal node or the block node are referred to as voting nodes or non-block nodes. Wherein the proposal node or the chunking node is responsible for collecting transaction, block packing and voting information verification. The voting node or the non-block-out node is responsible for verifying the block and voting for the valid block. When the blockchain system is in normal operation, one proposed node or one out-block node executes the process of packing blocks (out-blocks) in each round. The proposer of a block can be uniquely determined using common selection algorithms, e.g., taking blocks in turn using simple polling. That is, in a blockchain system, at any time, only one blockchain node is a proposal node or a block-out node, and other blockchain nodes are voting nodes or non-block-out nodes.
In an optional embodiment of the invention, after the receiving the smart contract transaction request, the method further comprises:
calculating a transaction commission fee according to the intelligent contract transaction request;
and acquiring the commission charge from the contract account corresponding to the intelligent contract transaction request.
In this alternative embodiment, in order to improve the enthusiasm of absenteeism on the blockchain and avoid wasting the computing resources of the blockchain, the intelligent contract adopts a Gas excitation mechanism. That is, when the smart contract is executed, a transaction commission needs to be paid.
The calculation of transaction fees is prior art and the invention will not be described in detail herein.
S12, check if the timer has expired.
When the virtual machine calls the intelligent contract to execute the transaction, whether the timer in the timer queue expires is detected.
And S13, responding to the expired timer, calling the intelligent contract to execute the transaction according to the expired timer and generating the global state.
Upon determining that there is an expired timer in the timer queue, the virtual machine executes a transaction in response to the expired timer and generates a series of contract states in the course of executing the transaction. Such as a member variable of the contract, a function entry address table of the contract, a global variable table, a static variable table, etc. The series of contract states eventually merge to produce a global state.
And S14, generating a new block according to the global state.
And after the block chain link point receives the global state returned by the virtual machine, a new block is generated according to the global state in a packaging mode. And meanwhile, updating the state of the asset of the initiating account of the intelligent contract transaction request according to the global state. For example, when the virtual machine calls the intelligent contract to execute the transfer transaction, the block chain node updates the balance in the initiating account of the intelligent contract transaction request according to the balance state returned by the virtual machine.
S15, broadcasting the new tile to other blockchain nodes in the blockchain network.
And after generating a new block, the block link point broadcasts the new block to a block link network so as to inform other block link points of carrying out validity verification on the new block.
In the above embodiment, because the virtual machine in the block chain cannot operate autonomously, as the block link point of the proposal node or the out-block node, when receiving the transaction request of the intelligent contract, the virtual machine invokes the intelligent contract according to the expired timer to execute the transaction, generates the new block and broadcasts the new block, which can meet the timer requirement for programming the intelligent contract, and realizes the automatic invocation of the intelligent contract.
In an optional embodiment of the invention, the method further comprises:
monitoring a new block generation event in the block chain;
when the generation of a new block is monitored, whether a timer expired or not is checked according to the timestamp of the new block;
responding to an expired timer, calling a smart contract to execute a transaction according to the expired timer and generating a global state;
verifying whether the generated global state is consistent with the global state in the new block;
in response to the generated global state and the global state in the new tile being consistent, determining that the new tile is legitimate and voting for the new tile;
in response to the generated global state and the global state in the new tile not being consistent, determining that the new tile is illegal and discarding the new tile.
In this alternative embodiment, when the blockchain node is changed from a proposal node or a block-out node to a voting node or a non-block-out node, a new blockgeneration event in the blockchain may be listened to in real time. And when the generation of a new block is monitored, acquiring information such as a timestamp and a global state in the new block. And meanwhile, calling an intelligent contract to execute transaction according to an expired timer and generating a global state so as to carry out validity verification on the new block.
And when the generated global state is consistent with the global state in the new block, indicating that the new block is legal. For a legal block, the blockchain node may vote and broadcast a verification result of verifying the validity to the blockchain network. When the generated global state is inconsistent with the global state in the new tile, indicating that the new tile is illegal. For an illegal block, the blockchain node may lose or not vote and broadcast a verification result of the illegal verification to the blockchain network.
And when the block chain link points exceeding the preset threshold in the block chain network verify that the new block is legal, the block chain network is indicated to agree with the new block, and the new block can be uploaded to the block chain network. And when the block chain link points exceeding the preset threshold in the block chain network verify the new block, the block chain network does not agree with the new block, and the new block cannot be uploaded to the block chain network. In different blockchain systems, the number of blockchain nodes required for the completion of consensus on a new block is different. For example, in the bitcoin system, the number of blockchain nodes that authenticate a new block reaches 51% of the entire blockchain nodes, and it can be considered that the consensus on the new block is completed. As another example, in a digital currency (DFT) system, the number of blockchain nodes that authenticate a new block to be legitimate reaches 2/3 of the entire blockchain nodes, and the consensus on the new block can be considered to be completed.
In the above embodiment, since the virtual machine in the block chain cannot operate autonomously, as a block link point of the voting node or the non-block-out node, when it is monitored that a new block is generated, the intelligent contract is invoked according to the expired timer to execute a transaction and generate a global state, and whether the new block is legal or not is determined according to the global state. The running of the timer is performed by the trusted environment of the block chain, so that the timer requirement of the application for the programming of the contract can be met, and the verifiable consistency of any node of the block at any time later is realized.
In an optional embodiment of the present invention, the invoking the smart contract to execute the transaction and generate the global state according to the expired timer comprises:
determining a temporal order of the expired timers;
judging whether a plurality of expired timers exist at the same time;
responding to a timer which expires at the same time, executing the intelligent contract according to the time sequence of the expired timer and generating a global state;
and responding to a plurality of expired timers at the same time, executing the intelligent contract according to the time sequence of the expired timers and the arrangement sequence of the expired timers at the same time, and generating a global state.
In this optional embodiment, the blockchain node locally stores a timer queue, and the timers are recorded in the timer queue according to a time sequence. The former timer is recorded at the head of the timer queue, and the latter timer is recorded at the tail of the timer queue. And recording the timer at the same time according to the identification number of the timer, wherein the smaller the identification number of the timer is, the timer is recorded before, and the larger the identification number of the timer is, the timer is recorded after. Alternatively, the larger the identification number, the timer is recorded before, and the smaller the identification number, the timer is recorded after.
For example, assuming that 4 timers expire when a new block is generated, the time of the timer T1 is T1, the time of the timer T2 is T2, the time of the timer T3 is T3, and the time of the timer T4 is T5, where T1< T2 ═ T3< T4, the blockchain node first calls the smart contract according to the timer T1. Then, since the timer T2 is recorded after the timer T3, the block link point calls the smart contract according to the timer T3, and then calls the smart contract according to the timer T2. And the last block chain node calls the intelligent contract to execute the transaction according to the timer T4.
In an optional embodiment of the present invention, after the invoking the smart contract to execute the transaction and generate the global state according to the expired timer, the method further comprises:
identifying whether the expired timer is in a single-shot mode or a cycle-shot mode;
in response to the expired timer being the cycle trigger mode, storing the timer again.
In this alternative embodiment, after the block node executes the transaction according to the expired timer, the trigger mode of the expired timer is also identified. And for the timer in the single-touch mode, the timing task is completed after the transaction is executed. And for the timer in the cycle trigger mode, after the transaction is executed, the timer is put back into the timer queue, so that the transaction is executed according to the expired timer in the cycle trigger mode when the timer in the cycle trigger mode expires.
According to the block chain intelligent contract timing processing method, when the block chain nodes serve as the proposal nodes or the exit nodes, when an intelligent contract transaction request is received, the virtual machine calls the intelligent contract to execute transaction according to the due timer, a new block is generated and broadcasted, the requirement of the timer for programming the intelligent contract can be met, and the automatic calling of the intelligent contract is realized. When the block link point is used as a voting node or a non-block-out node, and when the generation of a new block is monitored, the intelligent contract is called according to the expired timer to execute transaction and generate a global state, and whether the new block is legal or not is determined according to the global state. The running of the timer is performed by the trusted environment of the block chain, so that the timer requirement of the application for the programming of the contract can be met, and the verifiable consistency of any node of the block at any time later is realized.
Example two
Fig. 2 is a schematic diagram of functional modules of the device for processing intelligent contract timing of a block chain according to a second embodiment of the present invention.
In some embodiments, the blockchain intelligent contract timing processing apparatus 20 operates in blockchain link points. The block chain intelligent contract timing processing apparatus 20 may comprise a plurality of functional modules made up of program code segments. The program code of each program segment in the blockchain intelligent contract timing processing apparatus 20 may be stored in the memory of the blockchain node and executed by at least one processor to perform (see fig. 1 for details) timing processing of the blockchain intelligent contract.
In this embodiment, the block chain intelligent contract timing processing apparatus 20 may be divided into a plurality of functional modules according to the functions executed by the apparatus. The functional module may include: a receiving module 201, a broadcasting module 202, a storage module 203, a calculation module 204, a checking module 205, an execution module 206, a generation module 207, a listening module 208, a verification module 209, and a voting module 210. The module referred to herein is a series of computer program segments capable of being executed by at least one processor and capable of performing a fixed function and is stored in memory. In the present embodiment, the functions of the modules will be described in detail in the following embodiments.
The receiving module 201 is used for receiving an intelligent contract transaction request.
The intelligent contract is a program on the block chain, is called by an external user, runs according to a preset program, and can perform repeated verification on all block chain link points.
The user can send an intelligent contract transaction request to a certain block chain node in the block chain network through the client device to request to execute the intelligent contract transaction. Such as money transfers, purchases, etc. Wherein the intelligent contract transaction request includes description information for executing a contract. The description information of the execution contract may include: input parameters for executing contracts, etc.
The receiving module 201 is further configured to receive a timer set by a user and store the timer before the receiving of the intelligent contract transaction request.
The broadcasting module 202 is configured to broadcast the timer to the other blockchain nodes.
Wherein the timer refers to a tool for issuing certain actions at a pre-designed point in time. The timer counts in the operation of the processor through a high-speed data bus, and the accuracy of the time sequence is ensured.
In this alternative embodiment, the user may preset the trigger mode of the timer, the trigger condition of the timer, and the execution action after triggering the timer. The trigger modes of the timer include a single trigger mode and a cycle trigger mode. The trigger conditions of the timer include, but are not limited to: triggering at a preset time point, triggering after the virtual machine is started for a preset time period, and triggering every other preset time period after the virtual machine is started. The action performed by the timer may be a function or functions. After the user sets the timer, the timer can be sent to the blockchain node through the client device. And after receiving the timer, the block chain link point stores the timer in a local timer queue and broadcasts the timer to other block chain link points in the block chain network.
The receiving module 201 is further configured to receive a timer broadcasted by the other block nodes before the receiving of the intelligent contract transaction request.
The storage module 203 is configured to store the timer.
In this alternative embodiment, after the user sets the timer, the timer may be sent to any one of the blockchain nodes in the blockchain network through the client device. The any one block link point refers to any one node device in the other block link nodes. Any one of the blockchain nodes broadcasts the received timer to the blockchain network. Thus, the blockchain node receives timers broadcast by other blockchain nodes and stores the timers in a local timer queue.
It should be noted that, in this embodiment, the block chain node that performs the operation of the block chain intelligent contract timing processing is referred to as a proposal node or a block node, and the other block chain nodes opposite to the proposal node or the block node are referred to as voting nodes or non-block nodes. Wherein the proposal node or the chunking node is responsible for collecting transaction, block packing and voting information verification. The voting node or the non-block-out node is responsible for verifying the block and voting for the valid block. When the blockchain system is in normal operation, one proposed node or one out-block node executes the process of packing blocks (out-blocks) in each round. The proposer of a block can be uniquely determined using common selection algorithms, e.g., taking blocks in turn using simple polling. That is, in a blockchain system, at any time, only one blockchain node is a proposal node or a block-out node, and other blockchain nodes are voting nodes or non-block-out nodes.
The calculating module 204 is configured to calculate a transaction commission fee according to the intelligent contract transaction request after the receiving of the intelligent contract transaction request; and acquiring the commission charge from the contract account corresponding to the intelligent contract transaction request.
In this alternative embodiment, in order to improve the enthusiasm of absenteeism on the blockchain and avoid wasting the computing resources of the blockchain, the intelligent contract adopts a Gas excitation mechanism. That is, when the smart contract is executed, a transaction commission needs to be paid.
The calculation of transaction fees is prior art and the invention will not be described in detail herein.
The checking module 205 is configured to check whether the timer expires.
When the virtual machine calls the intelligent contract to execute the transaction, whether the timer in the timer queue expires is detected.
The execution module 206 is configured to, in response to the expired timer, invoke the smart contract to execute the transaction according to the expired timer and generate a global state.
Upon determining that there is an expired timer in the timer queue, the virtual machine executes a transaction in response to the expired timer and generates a series of contract states in the course of executing the transaction. Such as a member variable of the contract, a function entry address table of the contract, a global variable table, a static variable table, etc. The series of contract states eventually merge to produce a global state.
The generating module 207 is configured to generate a new block according to the global state.
And after the block chain link point receives the global state returned by the virtual machine, a new block is generated according to the global state in a packaging mode. And meanwhile, updating the state of the asset of the initiating account of the intelligent contract transaction request according to the global state. For example, when the virtual machine calls the intelligent contract to execute the transfer transaction, the block chain node updates the balance in the initiating account of the intelligent contract transaction request according to the balance state returned by the virtual machine.
The broadcasting module 202 is further configured to broadcast the new block to other blockchain nodes in a blockchain network.
And after generating a new block, the block link point broadcasts the new block to a block link network so as to inform other block link points of carrying out validity verification on the new block.
In the above embodiment, because the virtual machine in the block chain cannot operate autonomously, as the block link point of the proposal node or the out-block node, when receiving the transaction request of the intelligent contract, the virtual machine invokes the intelligent contract according to the expired timer to execute the transaction, generates the new block and broadcasts the new block, which can meet the timer requirement for programming the intelligent contract, and realizes the automatic invocation of the intelligent contract.
The monitoring module 208 is configured to monitor a new block generation event in the block chain.
The checking module 205 is configured to check whether there is an expired timer according to the timestamp of the new block when it is monitored that the new block is generated.
The execution module 206, configured to respond to an expired timer, invoke an intelligent contract to execute a transaction according to the expired timer, and generate a global state;
the verifying module 209 is configured to verify whether the generated global state is consistent with the global state in the new chunk.
The voting module 210 is configured to determine that the new block is legal and vote for the new block in response to the generated global state being consistent with the global state in the new block;
the voting module 210 is further configured to determine that the new tile is illegal and discard the new tile in response to the generated global state and the global state in the new tile being inconsistent.
In this alternative embodiment, when the blockchain node is changed from a proposal node or a block-out node to a voting node or a non-block-out node, a new blockgeneration event in the blockchain may be listened to in real time. And when the generation of a new block is monitored, acquiring information such as a timestamp and a global state in the new block. And meanwhile, calling an intelligent contract to execute transaction according to an expired timer and generating a global state so as to carry out validity verification on the new block.
And when the generated global state is consistent with the global state in the new block, indicating that the new block is legal. For a legal block, the blockchain node may vote and broadcast a verification result of verifying the validity to the blockchain network. When the generated global state is inconsistent with the global state in the new tile, indicating that the new tile is illegal. For an illegal block, the blockchain node may lose or not vote and broadcast a verification result of the illegal verification to the blockchain network.
And when the block chain link points exceeding the preset threshold in the block chain network verify that the new block is legal, the block chain network is indicated to agree with the new block, and the new block can be uploaded to the block chain network. And when the block chain link points exceeding the preset threshold in the block chain network verify the new block, the block chain network does not agree with the new block, and the new block cannot be uploaded to the block chain network. In different blockchain systems, the number of blockchain nodes required for the completion of consensus on a new block is different. For example, in the bitcoin system, the number of blockchain nodes that authenticate a new block reaches 51% of the entire blockchain nodes, and it can be considered that the consensus on the new block is completed. As another example, in a digital currency (DFT) system, the number of blockchain nodes that authenticate a new block to be legitimate reaches 2/3 of the entire blockchain nodes, and the consensus on the new block can be considered to be completed.
In the above embodiment, since the virtual machine in the block chain cannot operate autonomously, as a block link point of the voting node or the non-block-out node, when it is monitored that a new block is generated, the intelligent contract is invoked according to the expired timer to execute a transaction and generate a global state, and whether the new block is legal or not is determined according to the global state. The running of the timer is performed by the trusted environment of the block chain, so that the timer requirement of the application for the programming of the contract can be met, and the verifiable consistency of any node of the block at any time later is realized.
In an optional embodiment of the present invention, the executing module 206 invoking the smart contract to execute the transaction and generate the global state according to the expired timer comprises:
determining a temporal order of the expired timers;
judging whether a plurality of expired timers exist at the same time;
responding to a timer which expires at the same time, executing the intelligent contract according to the time sequence of the expired timer and generating a global state;
and responding to a plurality of expired timers at the same time, executing the intelligent contract according to the time sequence of the expired timers and the arrangement sequence of the expired timers at the same time, and generating a global state.
In this optional embodiment, the blockchain node locally stores a timer queue, and the timers are recorded in the timer queue according to a time sequence. The former timer is recorded at the head of the timer queue, and the latter timer is recorded at the tail of the timer queue. And recording the timer at the same time according to the identification number of the timer, wherein the smaller the identification number of the timer is, the timer is recorded before, and the larger the identification number of the timer is, the timer is recorded after. Alternatively, the larger the identification number, the timer is recorded before, and the smaller the identification number, the timer is recorded after.
For example, assuming that 4 timers expire when a new block is generated, the time of the timer T1 is T1, the time of the timer T2 is T2, the time of the timer T3 is T3, and the time of the timer T4 is T5, where T1< T2 ═ T3< T4, the blockchain node first calls the smart contract according to the timer T1. Then, since the timer T2 is recorded after the timer T3, the block link point calls the smart contract according to the timer T3, and then calls the smart contract according to the timer T2. And the last block chain node calls the intelligent contract to execute the transaction according to the timer T4.
In an optional embodiment of the present invention, the checking module 205 is further configured to identify whether the expired timer is in a single-trigger mode or a round-trip mode after the invoking of the smart contract to execute the transaction according to the expired timer and generate the global state.
The storage module 203 is further configured to store the timer again in response to the expired timer being the cycle trigger mode.
In this alternative embodiment, after the block node executes the transaction according to the expired timer, the trigger mode of the expired timer is also identified. And for the timer in the single-touch mode, the timing task is completed after the transaction is executed. And for the timer in the cycle trigger mode, after the transaction is executed, the timer is put back into the timer queue, so that the transaction is executed according to the expired timer in the cycle trigger mode when the timer in the cycle trigger mode expires.
According to the block chain intelligent contract timing processing device, when the block chain nodes serve as the proposal nodes or the exit nodes, when an intelligent contract transaction request is received, the virtual machine calls the intelligent contract to execute transaction according to the due timer, a new block is generated and broadcasted, the requirement of the timer for programming the intelligent contract can be met, and the intelligent contract can be automatically called. When the block link point is used as a voting node or a non-block-out node, and when the generation of a new block is monitored, the intelligent contract is called according to the expired timer to execute transaction and generate a global state, and whether the new block is legal or not is determined according to the global state. The running of the timer is performed by the trusted environment of the block chain, so that the timer requirement of the application for the programming of the contract can be met, and the verifiable consistency of any node of the block at any time later is realized.
EXAMPLE III
Fig. 3 is a schematic diagram of an internal structure of a blockchain node according to an embodiment of the present invention.
In this embodiment, the blockchain node 3 may include a memory 31, a processor 32, and a bus 33 and a transceiver 34.
The memory 31 includes at least one type of readable storage medium, which includes a flash memory, a hard disk, a multimedia card, a card type memory (e.g., SD or DX memory, etc.), a magnetic memory, a magnetic disk, an optical disk, and the like. The memory 31 may in some embodiments be an internal storage unit of the blockchain node 3, e.g. a hard disk of the blockchain node 3. The memory 31 may also be an external storage device of the blockchain node 3 in other embodiments, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like, which are provided on the blockchain node 3. Further, the memory 31 may also comprise both an internal memory unit of the blockchain node 3 and an external memory device. The memory 31 may be used not only to store the application program and various types of data installed in the blockchain node 3, such as the code of the blockchain intelligent contract timing processing apparatus 20 and the respective modules, but also to temporarily store data that has been output or is to be output.
Processor 32 may be, in some embodiments, a Central Processing Unit (CPU), controller, microcontroller, microprocessor or other data Processing chip for executing program codes stored in memory 31 or Processing data.
The bus 33 may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is shown in FIG. 3, but this does not mean only one bus or one type of bus.
Further, the blockchain node 3 may further comprise a network interface, which may optionally comprise a wired interface and/or a wireless interface (such as a WI-FI interface, a bluetooth interface, etc.), typically used for establishing a communication connection between the blockchain node 3 and other blockchain nodes.
Optionally, the block link point 3 may further include a user interface, which may include a Display (Display), an input unit such as a Keyboard (Keyboard), and optionally, a standard wired interface and a wireless interface. Alternatively, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an Organic Light-Emitting Diode (OLED) touch screen, or the like. Wherein the display, which may also be referred to as a display screen or display unit, is used for displaying messages processed in the blockchain node and for displaying a visualized user interface.
Fig. 3 shows only the blockchain node 3 with components 31-34, it being understood by a person skilled in the art that the structure shown in fig. 3 does not constitute a limitation of the blockchain node 3, and may be either a bus-type structure or a star-shaped structure, and that the blockchain node 3 may also comprise fewer or more components than shown, or combine certain components, or a different arrangement of components. Other electronic products, now existing or hereafter developed, that may be adapted to the present invention, are also included within the scope of the present invention and are hereby incorporated by reference.
In the above embodiments, all or part may be implemented by an application program, hardware, firmware, or any combination thereof. When implemented using an application program, may be implemented in whole or in part in the form of a computer program product.
The computer program product includes one or more computer instructions. When loaded and executed on a computer, cause the processes or functions described in accordance with the embodiments of the invention to occur, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a network of computers, or other programmable device. The computer instructions may be stored in a computer readable storage medium or transmitted from one computer readable storage medium to another, for example, from one website site, computer, server, or data center to another website site, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that a computer can store or a data storage device, such as a server, a data center, etc., that is integrated with one or more available media. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., Solid State Disk (SSD)), among others.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the several embodiments provided in the present application, it should be understood that the disclosed system, apparatus and method may be implemented in other manners. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the units is only one logical division, and other divisions may be realized in practice, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution in the embodiment.
In addition, functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of an application program functional unit.
The integrated unit, if implemented in the form of an application functional unit and sold or used as a stand-alone product, may be stored in a computer-readable storage medium. Based on such understanding, the technical solution of the present application may be embodied in the form of a computer program product, which is stored in a storage medium and includes instructions for causing a blockchain node (which may be a personal computer, a server, or a network device) to perform all or part of the steps of the method according to the embodiments of the present application. And the aforementioned storage medium includes: various media capable of storing program codes, such as a usb disk, a hard disk, a Read-only memory (ROM), a magnetic disk, or an optical disk.
It should be noted that the above-mentioned numbers of the embodiments of the present invention are merely for description, and do not represent the merits of the embodiments.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.