CN109064325B - Intelligent contract implementation method and device based on block chain - Google Patents

Intelligent contract implementation method and device based on block chain Download PDF

Info

Publication number
CN109064325B
CN109064325B CN201810664409.1A CN201810664409A CN109064325B CN 109064325 B CN109064325 B CN 109064325B CN 201810664409 A CN201810664409 A CN 201810664409A CN 109064325 B CN109064325 B CN 109064325B
Authority
CN
China
Prior art keywords
transaction
state
type
intelligent contract
execution
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201810664409.1A
Other languages
Chinese (zh)
Other versions
CN109064325A (en
Inventor
范亮琴
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Guangzhou smart chain Future Technology Co.,Ltd.
Original Assignee
Zhejiang Ultrain Space Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Zhejiang Ultrain Space Technology Co ltd filed Critical Zhejiang Ultrain Space Technology Co ltd
Priority to CN201810664409.1A priority Critical patent/CN109064325B/en
Publication of CN109064325A publication Critical patent/CN109064325A/en
Application granted granted Critical
Publication of CN109064325B publication Critical patent/CN109064325B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q40/00Finance; Insurance; Tax strategies; Processing of corporate or income taxes
    • G06Q40/04Trading; Exchange, e.g. stocks, commodities, derivatives or currency exchange
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q20/00Payment architectures, schemes or protocols
    • G06Q20/38Payment protocols; Details thereof
    • G06Q20/382Payment protocols; Details thereof insuring higher security of transaction
    • G06Q20/3829Payment protocols; Details thereof insuring higher security of transaction involving key management

Abstract

The application discloses a block chain-based intelligent contract implementation method and device, relates to the field of computers, and can confirm transaction in the implementation process of an intelligent contract so as to achieve state consistency. The intelligent contract implementation method comprises the following steps: determining the type of the transaction based on the identification of the transaction driving the intelligent contract, wherein the type of the transaction comprises a first type of time length transaction, and the first type of time length transaction is a transaction with execution time length larger than a preset value; and when the transaction is the first-type duration transaction, performing transaction state management to decouple an intelligent contract operation period and a consensus period. The method and the device are used for realizing the intelligent contract based on the block chain.

Description

Intelligent contract implementation method and device based on block chain
Technical Field
The application relates to the technical field of computers, in particular to a block chain-based intelligent contract implementation method and device.
Background
The block chain is a chain data structure formed by combining data blocks in a sequential connection mode according to a time sequence, and is a distributed account book which is guaranteed in a cryptographic mode and cannot be tampered and forged.
The smart contract concept was first proposed by Nick Szabo in 1994, but prior to the advent of blockchain technology, smart contracts were not widely used due to the lack of a trusted execution environment. With the popularization of block chains, intelligent contract technology is rapidly developed. The block chain has the characteristics of decentralization, non-tampering and high availability, so that the intelligent contract is written into the block chain in a digitalized form, and the transparent tracking and non-tampering of the whole process of storing, reading and executing the intelligent contract can be guaranteed.
In the related art of the intelligent contract based on the block chain, the transaction which drives the intelligent contract to execute and appears in a consensus period must be executed within the time of the consensus period, so that each node on the block chain network confirms the execution result of the transaction, and the transaction which is not executed within the consensus period is forcibly quitted. However, executing a large number of transactions (e.g., thousands or even tens of thousands of transactions) within a short time (e.g., 15 seconds) inevitably results in many transactions being unable to be executed and being forcibly exited, thereby resulting in failure of transaction confirmation and further hindering implementation of the intelligent contract.
Disclosure of Invention
The embodiment of the application provides an intelligent contract implementation method and device based on a block chain, which can confirm transaction in the implementation process of an intelligent contract, so as to achieve state consistency.
On one hand, the embodiment of the present application further provides an intelligent contract implementation method based on a block chain, including:
determining the type of the transaction based on the identification of the transaction driving the intelligent contract, wherein the type of the transaction comprises a first type of time length transaction, and the first type of time length transaction is a transaction with execution time length larger than a preset value;
and when the transaction is the first-type duration transaction, performing transaction state management to decouple an intelligent contract operation period and a consensus period.
Optionally, in an embodiment, the performing transaction state management to achieve decoupling of the intelligent contract running period and the consensus period when the transaction is the first type duration transaction includes: when the transaction is the first type of time length transaction, acquiring the state of the transaction every other consensus period; if the transaction state is the ready state, packaging the transaction to obtain a block; and if the transaction state is a non-ready state, inhibiting packaging and block outputting operations of the transaction.
Optionally, in an embodiment, when the state of the transaction is a non-ready state, the non-ready state includes an execution state and a suspension state, and if the state of the transaction is the non-ready state, the inhibiting of the block packing out operation on the transaction includes: if the transaction state is a suspended state, converting the transaction state from the suspended state to an execution state; skipping the transaction when the state of the transaction is the execution state.
Optionally, in an embodiment, if the status of the transaction is a non-ready status, the inhibiting of packaging the transaction out of the block further includes: if the transaction in the execution state is executed in a time slice, converting the state of the transaction from the execution state to the ready state; if the transaction in the execution state is not executed in the time slice, the state of the transaction is converted from the execution state to the suspension state; and if the transaction in the execution state is abnormal or overtime in the execution process, converting the state of the transaction from the execution state to a rollback state.
Optionally, in one embodiment, the amount of fuel consumed increases linearly or exponentially with the length of time the smart contract is operated when the smart contract is driven by the first type of length transaction.
Optionally, in an embodiment, the type of the transaction further includes a second type of time-length transaction, where the second type of time-length transaction is a transaction whose execution time length is not greater than the preset value. The method further comprises the following steps: and when the transaction is the second type of time-length transaction, executing the second type of time-length transaction.
Optionally, in an embodiment, the preset value may be the consensus period, and the preset value may be configurable.
In another aspect, an apparatus for implementing intelligent contracts based on blockchains is provided, including:
the determining module is used for determining the type of the transaction based on the identification of the transaction driving the intelligent contract, wherein the type of the transaction comprises a first type of time length transaction, and the first type of time length transaction is a transaction with execution time length larger than a preset value;
and the management module is used for managing the transaction state when the transaction is the first type of time duration transaction so as to decouple the intelligent contract operation period from the consensus period.
Optionally, in an embodiment, the management module is specifically configured to: when the transaction is the first type of time length transaction, acquiring the state of the transaction every other consensus period; if the transaction state is the ready state, packaging the transaction to obtain a block; and if the transaction state is a non-ready state, inhibiting packaging and block outputting operations of the transaction.
Optionally, in an embodiment, the non-ready state includes an execution state and a suspension state, and the management module is specifically configured to: when the transaction state is a suspended state, converting the transaction state from the suspended state to an execution state; skipping the transaction when the state of the transaction is the execution state.
Optionally, in an embodiment, the management module is further configured to: if the transaction in the execution state is executed in a time slice, converting the state of the transaction from the execution state to the ready state; if the transaction in the execution state is not executed in the time slice, the state of the transaction is converted from the execution state to the suspension state; and if the transaction in the execution state is abnormal or overtime in the execution process, converting the state of the transaction from the execution state to a rollback state.
Optionally, in one embodiment, the amount of fuel consumed increases linearly or exponentially with the length of time the smart contract is operated when the smart contract is driven by the first type of length transaction.
Optionally, in an embodiment, the type of the transaction further includes a second type of time-length transaction, where the second type of time-length transaction is a transaction whose execution time length is not greater than the preset value, and the management module is further configured to: and when the transaction is the second type of time-length transaction, executing the second type of time-length transaction.
Optionally, in an embodiment, the preset value may be the consensus period, and the preset value is configurable.
In another aspect, a computer-readable storage medium having stored thereon computer instructions which, when executed, perform any of the above intelligent contract implementing methods is provided.
The embodiment of the application adopts at least one technical scheme which can achieve the following beneficial effects:
the transactions driving the intelligent contracts are classified according to the identifiers, when the execution duration of the transactions is longer than a preset value, the states of the transactions are managed, so that the decoupling of the running period and the consensus period of the intelligent contracts is realized, the transactions appearing in one consensus period do not need to be executed in the consensus period, but can be executed in a mode of spanning multiple consensus periods, the transaction confirmation failure caused by forced quitting of the transactions in the implementation process of the intelligent contracts can be avoided, and the state consistency is achieved.
Drawings
The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this application, illustrate embodiment(s) of the application and together with the description serve to explain the application and not to limit the application. In the drawings:
fig. 1 is a flowchart of a method for implementing an intelligent contract based on a blockchain according to an embodiment of the present application;
fig. 2 is a flowchart of a method for implementing an intelligent contract based on a blockchain according to an embodiment of the present application;
FIG. 3 is a schematic diagram of a transaction state change provided by an embodiment of the present application;
fig. 4 is a block diagram of an apparatus for implementing an intelligent contract based on a blockchain according to an embodiment of the present application.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the technical solutions of the present application will be described in detail and completely with reference to the following specific embodiments of the present application and the accompanying drawings. It should be apparent that the described embodiments are only some of the embodiments of the present application, and not all of the embodiments. 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 application.
Before describing embodiments of the present invention, some terms in this application will be explained.
Block chains: the method is a technology which can maintain a set of non-falsifiable account book records among non-trusted or weakly trusted participants without intermediary participation. A blockchain is a distributed system consisting of many nodes communicating with each other. The blockchain system is generally divided into a public chain, a federation chain and a private chain according to different application scenarios and design systems. Each node of the public chain can freely join and leave the network, participates in reading and writing of data on the chain, and is interconnected and intercommunicated in a flat topological structure during operation, and no centralized service end node exists in the network. The method for realizing the intelligent contract provided by the embodiment of the application can be based on a public chain.
The basic concepts of blockchains may include transactions (transactions), blocks (blocks), and chains (Chain). Wherein: a transaction may refer to an operation that results in a change in the state of the ledger, such as adding a record; the block records the transaction and state results occurring within a period of time, and is a common consensus on the current account book state; the chain is formed by connecting blocks in series according to the occurrence sequence and is a log record of the whole state change. If the blockchain is used as a state machine, each transaction is attempted to change state, and each consensus generated block is that the participant confirms the result of all transaction contents in the block that caused the state change.
And (3) node: a terminal (e.g., a computer) connected to a blockchain network may be considered a node in a blockchain.
Block chain consensus mechanism: may include POS (Proof of rights mechanism), POW (Proof of work), DPOS (delete Proof of rights mechanism) and PBFT (practical Byzantine factory Tolerance). From a probabilistic perspective, the PBFT series of algorithms is deterministic and irreversible once consensus is reached; the POW series algorithm is uncertain, and the probability of being overturned is smaller and smaller as time goes on. The POW guesses a value (nonce) repeatedly by calculation so that the result of adding a new transaction data hash (hash) based on the last block of the block chain satisfies a predetermined condition. Ensure that only a few legal proposals can appear in the system within a period of time. These few legal proposals are broadcast over the network and the receiving user, after authentication, continues to construct new blocks in this way based on the longest chain it considers to be.
Intelligent contract: contracts that are defined in digital form and that are capable of automatically executing terms, i.e., the contents of an intelligent contract, include program code by which automatic execution of contract terms can be achieved.
In the present application, the building and execution of the intelligent contract based on the block chain can be divided into the following steps: (1) multiple users participate in making an intelligent contract together; (2) intelligent contracts are spread and stored in block chains through peer-to-peer (P2P) networks; (3) the intelligent contracts constructed by the block chains are automatically executed.
The technical solutions provided by the embodiments of the present application are described in detail below with reference to the accompanying drawings.
Fig. 1 is a flowchart of a method for implementing an intelligent contract based on a blockchain according to an embodiment of the present disclosure. Referring to fig. 1, a method for implementing an intelligent contract based on a block chain according to an embodiment of the present application may include:
and step 12, determining the type of the transaction based on the identification of the transaction driving the intelligent contract, wherein the type of the transaction comprises a first type of time length transaction, and the first type of time length transaction is a transaction with execution time length larger than a preset value.
In other words, the first type of long-duration Transaction can be, for example, a long-duration Transaction (L ong-Range Transaction), and the second type of long-duration Transaction can be, for example, a Short-Range Transaction (Short-Range Transaction). the preset value can be configured according to actual needs in the embodiment of the present application.
In this embodiment, the first type of long-duration transaction may be a transaction requiring occupation of more resources, and the second type of long-duration transaction may be a transaction requiring occupation of less resources. The resources mentioned here may be, for example, CPU resources, memory resources, network resources, and the like.
In the embodiment of the application, each transaction driving the smart contract can be marked with a mark, and the mark can be in any form for playing a role of mark, such as a form of abbreviated letters, for example, a and B, wherein the abbreviated letter a can represent a first type of time duration transaction, and the abbreviated letter B can represent a second type of time duration transaction; such as one or more numbers, e.g., 11 and 22, where the number 11 may represent a first type of long transaction and the number 22 may represent a second type of long transaction; another example is in the form of a short piece of characters, such as abc and qwe, where abc may represent a first type of long transaction and qwe may represent a second type of long transaction. The identification in the embodiment of the present application may also take other forms, for example, a form in which at least two of numbers, letters, and special characters are mixed, and the like.
Of course, in the embodiment of the present application, a default type may also be set for the transaction. The second type of time-length transaction may be set as a default type, since the contract triggered by the transaction initiator for the second type of time-length transaction is expected to be completed with relatively fast execution. The default type of transaction may not set the identifier, and thus, whether the transaction is the first type of long-time transaction or the second type of long-time transaction may be determined by judging whether the transaction carries the identifier. That is, the transaction carrying the identifier is a first type of long-time transaction, and the transaction not carrying the identifier is a second type of long-time transaction. Of course, in the embodiment of the present application, the default type of transaction may also set the identification when needed.
In the embodiment of the application, the identification of the transaction can be preset by a programmer of the intelligent contract, so that the transaction can be determined to be of which type according to the identification carried in the transaction when being executed, and further, the follow-up processing is convenient to carry out.
In the embodiment of the application, the second type of long-time transaction can be executed in a consensus period, and can be accelerated by adopting a stand-alone parallel processing method or a network fragmentation method. For a second type of long-time transaction, if the transaction has not been executed within a specified run-time less than the consensus period, the transaction may be marked as a transaction failure and its state may be rolled back. In the embodiment of the present application, the first type of long transaction may execute a relatively complex application logic, and thus cannot be guaranteed to be completed in a very short time (e.g., a consensus period).
And 14, when the transaction is the first-type duration transaction, performing transaction state management to decouple an intelligent contract operation period and a consensus period.
The transaction status in the embodiments of the present application may include: at least one of a ready state, a suspend state, and an execute state. Decoupling of the smart contract run period and the consensus period may indicate that the smart contract run period is no longer dependent on the consensus period, i.e., the smart contract may execute across multiple consensus periods.
In one embodiment of the present application, the second type of time-long transaction may be executed when the transaction is the second type of time-long transaction. Therefore, the two types of transactions are distinguished and processed differently, so that the transactions of different types can be ensured to be processed properly, failure in transaction confirmation in the implementation process of the intelligent contract is avoided, and state consistency is achieved.
It should be understood that, the execution subjects of the steps of the intelligent contract implementation method based on a blockchain provided in the embodiment of the present application may all be the same device (for example, may be any node in a blockchain network), or the method may also be implemented by different devices. For example, the execution subject of step 12 may be device 1 (e.g., may be one node in a blockchain network), and the execution subject of step 14 may be device 2 (e.g., may be another node in the blockchain network).
Meanwhile, it should be understood that, in the implementation of the intelligent contract implementation method based on the blockchain in the embodiment of the present application, the process of determining the operation elements (e.g., time, random number, and data source) may be consistent with the prior art, and meanwhile, the operation environment may also be substantially consistent with the related art. Taking the determination of time as an example, the whole block chain can be regarded as a timestamp server, and a timestamp of when any block is constructed is obtained, so that the results returned by calling of each distributed node can be completely guaranteed to be consistent.
The method and the device have the advantages that the transactions driving the intelligent contracts are classified according to the identifiers, when the execution duration of the transactions is longer than the preset value, the states of the transactions are managed, the decoupling of the running period and the consensus period of the intelligent contracts is realized, the transactions appearing in the consensus period do not need to be executed in the consensus period, but can be executed in a mode of spanning multiple consensus periods, the transactions can be confirmed in the implementation process of the intelligent contracts, and accordingly state consistency is achieved.
Optionally, in an embodiment of the present application, in step 14, when the transaction is the first type duration transaction, performing transaction state management to decouple the smart contract running period and the consensus period may include: when the transaction is the first type of time length transaction, acquiring the state of the transaction every other consensus period; if the state of the transaction is the ready state, performing packaging block-out operation on the transaction; and if the transaction state is a non-ready state, inhibiting packaging and block outputting operations of the transaction.
As used herein, a "pack out block operation" may refer to packing a transaction into a block for execution by other nodes in the blockchain network to perform computation result validation. Under certain conditions, for example, if the calculation results of more than two thirds of nodes in the whole network are the same, the block nodes can be determined according to the calculation results, and the blocks output by the block nodes are put into the block chain.
When the first-class duration transaction is processed, the transaction state is acquired in each consensus period to determine whether the transaction state is a ready state, only the transaction in the ready state can be packaged to obtain the block, and the transactions in other states cannot be packaged to obtain the block in the current consensus period.
In an embodiment of the present application, the non-ready state includes an execution state and a suspension state, and if the state of the transaction is the non-ready state, the inhibiting of the packaging out of the block operation for the transaction may include: if the transaction state is a suspended state, converting the transaction state from the suspended state to an execution state; and if the state of the transaction is the execution state, skipping the transaction. When the first-type long-time transaction is processed, if the transaction state is determined to be the suspension state, the suspension state is converted into the execution state, and the transaction can be executed conveniently and subsequently.
Optionally, in an embodiment of the present application, for a transaction in an execution state, when the transaction in the execution state is executed within a time slice, the state of the transaction may be converted from the execution state to the ready state; when the transaction in the execution state is not executed within the time slice, the state of the transaction can be converted from the execution state to the suspension state; when the transaction in the execution state is abnormal or overtime in the execution process, the state of the transaction can be converted into a rollback state from the execution state. According to the embodiment of the application, the state switching is carried out on the transaction of the processing execution state based on the specific situation, and the state management of the first-class time length transaction can be better realized.
In addition to classification and lifecycle management by transaction, management of fuel (gas) may also be performed in the embodiments of the present application. Therefore, through the comprehensive management of the three above, the transaction confirmation in the implementation process of the intelligent contract can be better realized, so as to achieve the state consistency. For example, when the smart contract is driven by the first type of duration transaction, the amount of fuel consumed increases linearly or exponentially as the duration of operation of the smart contract increases. Therefore, the intelligent contract driven by the first-type time-length transaction can be managed and controlled on the economic cost, and the condition that a person is ill through the first-type time-length transaction, such as malicious long-term occupation of system computing resources, is ensured.
Fig. 2 is a flowchart of a method for implementing an intelligent contract based on a blockchain according to an embodiment of the present application. Referring to fig. 2, a method for implementing an intelligent contract based on a blockchain according to an embodiment of the present application may include:
and step 22, determining the type of the transaction based on the identification of the transaction driving the intelligent contract, wherein the type of the transaction comprises a first type of time length transaction and a second type of time length transaction.
The first type of time duration transaction is a transaction with the execution time duration being greater than a preset value, and the second type of time duration transaction is a transaction with the execution time duration being not greater than the preset value.
And 24, when the transaction is the first-type duration transaction, acquiring the state of the transaction every other consensus period to determine whether the state of the transaction is a ready state.
And 26, when the state of the transaction is the ready state, packaging the transaction to obtain a block.
And step 28, when the transaction state is a suspension state, converting the transaction state from the suspension state to the execution state.
And step 30, when the transaction state is the execution state, performing state conversion operation based on specific conditions. Step 30 may cover the following situations:
step 301, when the transaction in the execution state is executed in a time slice, converting the state of the transaction from the execution state to the ready state;
step 302, when the transaction in the execution state is not executed in the time slice, the state of the transaction is converted from the execution state to the suspension state;
step 303, when the transaction in the execution state is abnormal or overtime in the execution process, the state of the transaction is converted from the execution state to a rollback state.
And step 32, when the transaction is the second type of time-length transaction, directly executing the second type of time-length transaction.
It should be understood that the relevant contents of the steps shown in fig. 3 can refer to the foregoing description, and are not repeated herein.
The status switching process mentioned herein can also be referred to as shown in fig. 3, and as can be seen from fig. 3, assuming that transaction a is a first type duration transaction, transaction a may be in a suspended state after being accepted. During consensus period T1, transaction A, which is in a suspended state, may be scheduled to execute to transition from the suspended state to an executing state. If transaction A has not been executed within the time slice during the consensus period T1, it returns to the pending state and is ready to be executed again during the next consensus period T2. In the consensus period T2, if the transaction a is executed within the time slice, the execution state is switched to the ready state, and if an exception or timeout occurs during the execution process, the execution state is switched to the rollback state. In the Nth consensus period Tn, where N is greater than 2, if transaction A is ready, then a pack out block operation is performed on transaction A. It should be understood that the schematic diagram of fig. 3 is merely illustrative of one type of state management and is not intended to be limiting.
According to the intelligent contract implementation method based on the block chain, the transactions are classified through the identification, life cycle management of the first-class time duration transactions is achieved through state management, it can be guaranteed that the transactions of different types can be properly processed, failure of transaction confirmation in the implementation process of the intelligent contract is avoided, meanwhile, it can be guaranteed that the first-class time duration transactions can be executed in a mode of spanning multiple consensus cycles, transaction confirmation can be conducted in the implementation process of the intelligent contract, and accordingly state consistency is achieved.
It should also be appreciated that in the embodiments of the subject application, fuel (gas) management may be performed in addition to by classifying transactions and performing lifecycle management. Therefore, through the comprehensive management of the three above, the transaction confirmation in the implementation process of the intelligent contract can be better realized, so as to achieve the state consistency. For example, when the smart contract is driven by the first type of duration transaction, the amount of fuel consumed increases linearly or exponentially as the duration of operation of the smart contract increases. Therefore, the intelligent contract driven by the first-type time-length transaction can be managed and controlled on the economic cost, and the condition that a person is ill through the first-type time-length transaction, such as malicious long-term occupation of system computing resources, is ensured.
Fig. 4 is a block diagram of an apparatus for implementing an intelligent contract based on a blockchain according to an embodiment of the present application. Referring to fig. 4, the intelligent contract implementation apparatus 40 based on a blockchain provided in an embodiment of the present application may include: a determination module 41 and a management module 42. Wherein:
the determining module 41 is configured to determine, based on an identifier of a transaction driving an intelligent contract, a type of the transaction, where the type of the transaction includes a first-class time-length transaction, and the first-class time-length transaction is a transaction whose execution time length is greater than a preset value;
and the management module 42 is configured to perform transaction state management to decouple the intelligent contract running period and the consensus period when the transaction is the first type duration transaction.
Optionally, in an embodiment, the management module 42 is specifically configured to: when the transaction is the first type of time length transaction, acquiring the state of the transaction every other consensus period; if the transaction state is the ready state, packaging the transaction to obtain a block; and if the transaction state is a non-ready state, inhibiting packaging and block outputting operations of the transaction.
Optionally, in an embodiment, the non-ready state includes an execution state and a suspension state, and the management module 42 is specifically configured to: if the transaction state is a suspended state, converting the transaction state from the suspended state to an execution state; and if the state of the transaction is the execution state, skipping the transaction.
Optionally, in an embodiment, the management module 42 is further configured to: if the transaction in the execution state is executed in a time slice, converting the state of the transaction from the execution state to the ready state; if the transaction in the execution state is not executed in the time slice, the state of the transaction is converted from the execution state to the suspension state; and if the transaction in the execution state is abnormal or overtime in the execution process, converting the state of the transaction from the execution state to a rollback state.
Optionally, in one embodiment, the amount of fuel consumed increases linearly or exponentially with the length of time the smart contract is operated when the smart contract is driven by the first type of length transaction.
Optionally, in an embodiment, the type of the transaction further includes a second type of time-length transaction, where the second type of time-length transaction is a transaction whose execution time length is not greater than the preset value, and the management module 42 is further configured to: and when the transaction is the second type of time-length transaction, executing the second type of time-length transaction.
Optionally, in an embodiment, the preset value may be the consensus period, and the preset value is configurable.
The intelligent contract implementation device based on the block chain classifies the transactions driving the intelligent contracts according to the identifiers, and when the execution duration of the transactions is longer than the preset value, the states of the transactions are managed to realize the decoupling of the operation cycle and the consensus cycle of the intelligent contracts, so that the transactions appearing in one consensus cycle do not need to be executed in the consensus cycle, but can be executed by spanning multiple consensus cycles, and the transactions can be confirmed in the implementation process of the intelligent contracts, thereby achieving the state consistency.
In addition, embodiments of the present application may provide a computer-readable storage medium having stored thereon computer instructions, which, when executed, perform any of the above intelligent contract implementation methods.
The computer-readable storage medium provided by the embodiment of the application classifies the transactions driving the intelligent contracts according to the identifiers, and when the execution duration of the transactions is longer than the preset value, the states of the transactions are managed to realize the decoupling of the operation cycle and the consensus cycle of the intelligent contracts, so that the transactions appearing in one consensus cycle do not need to be executed in the consensus cycle, but can be executed across a plurality of consensus cycles, and the transactions can be confirmed in the realization process of the intelligent contracts, thereby achieving the state consistency.
In addition, the embodiments of the present application may also provide a block link node, which may be a computer or a server, for example, and may include a storage medium and a processor. Wherein the storage medium is adapted to store a plurality of instructions; the processor is adapted to execute various instructions stored on the storage medium. Any of the above-described blockchain-based intelligent contract implementation methods may be implemented when instructions stored on the storage medium are executed by a processor.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, apparatus, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
In a typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include forms of volatile memory in a computer readable medium, Random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer readable medium does not include a transitory computer readable medium such as a modulated data signal and a carrier wave.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The above description is only an example of the present application and is not intended to limit the present application. Various modifications and changes may occur to those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.

Claims (9)

1. An intelligent contract implementation method based on a block chain is characterized by comprising the following steps:
determining the type of the transaction based on the identification of the transaction driving the intelligent contract, wherein the type of the transaction comprises a first type of time length transaction, and the first type of time length transaction is a transaction with execution time length larger than a preset value;
if the transaction is the first type of time length transaction, transaction state management is carried out so as to realize decoupling of an intelligent contract operation period and a consensus period;
when the transaction is the first-type duration transaction, performing transaction state management to decouple an intelligent contract operation period and a consensus period comprises:
when the transaction is the first type of time length transaction, acquiring the state of the transaction every other consensus period;
if the transaction state is the ready state, packaging the transaction to obtain a block;
if the transaction state is a non-ready state, the transaction is prohibited from being packaged and subjected to block outputting operation;
wherein the non-ready state comprises an execution state and a suspension state, and if the transaction state is the non-ready state, the operation of inhibiting packaging and block outputting of the transaction comprises the following steps:
if the transaction state is a suspended state, converting the transaction state from the suspended state to an execution state;
skipping the transaction if the state of the transaction is the execution state;
if the transaction in the execution state is executed in a time slice, converting the state of the transaction from the execution state to the ready state;
if the transaction in the execution state is not executed in the time slice, the state of the transaction is converted from the execution state to the suspension state;
and if the transaction in the execution state is abnormal in the execution process, converting the state of the transaction from the execution state to a rollback state.
2. The intelligent contract implementing method according to claim 1,
when the intelligent contract is driven by the first type of time duration transaction, the consumed fuel amount increases linearly or exponentially with the increase of the running time duration of the intelligent contract.
3. The intelligent contract implementing method according to claim 1, wherein the types of transactions further include a second type of time-length transactions, the second type of time-length transactions being transactions whose execution time length is not greater than the preset value,
the method further comprises the following steps:
and if the transaction is the second type of time-length transaction, executing the second type of time-length transaction.
4. The intelligent contract implementing method according to claim 1, wherein the preset value is the consensus period, and the preset value is configurable.
5. An intelligent contract implementation device based on a block chain is characterized by comprising:
the determining module is used for determining the type of the transaction based on the identification of the transaction driving the intelligent contract, wherein the type of the transaction comprises a first type of time length transaction, and the first type of time length transaction is a transaction with execution time length larger than a preset value;
the management module is used for managing the transaction state if the transaction is the first type of time length transaction so as to decouple the intelligent contract operation period from the consensus period;
wherein the management module is specifically configured to:
when the transaction is the first type of time length transaction, acquiring the state of the transaction every other consensus period;
if the transaction state is the ready state, packaging the transaction to obtain a block;
if the transaction state is a non-ready state, the transaction is prohibited from being packaged and subjected to block outputting operation;
wherein the non-ready state includes an execution state and a suspend state, and the management module is specifically configured to:
when the transaction state is a suspended state, converting the transaction state from the suspended state to an execution state;
skipping the transaction if the state of the transaction is the execution state;
if the transaction in the execution state is executed in a time slice, converting the state of the transaction from the execution state to the ready state;
if the transaction in the execution state is not executed in the time slice, the state of the transaction is converted from the execution state to the suspension state;
and if the transaction in the execution state is abnormal in the execution process, converting the state of the transaction from the execution state to a rollback state.
6. The intelligent contract implementing apparatus according to claim 5,
when the intelligent contract is driven by the first type of time duration transaction, the consumed fuel amount increases linearly or exponentially with the increase of the running time duration of the intelligent contract.
7. The intelligent contract implementing apparatus according to claim 5, wherein the types of transactions further include a second type of time-length transactions, the second type of time-length transactions being transactions whose execution time length is not greater than the preset value,
the management module is further configured to:
and if the transaction is the second type of time-length transaction, executing the second type of time-length transaction.
8. The intelligent contract implementing apparatus according to claim 5, wherein the preset value is the consensus period, and the preset value is configurable.
9. A computer-readable storage medium having stored thereon computer instructions which, when executed, perform an intelligent contract implementation method according to any one of claims 1-4.
CN201810664409.1A 2018-06-25 2018-06-25 Intelligent contract implementation method and device based on block chain Active CN109064325B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810664409.1A CN109064325B (en) 2018-06-25 2018-06-25 Intelligent contract implementation method and device based on block chain

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810664409.1A CN109064325B (en) 2018-06-25 2018-06-25 Intelligent contract implementation method and device based on block chain

Publications (2)

Publication Number Publication Date
CN109064325A CN109064325A (en) 2018-12-21
CN109064325B true CN109064325B (en) 2020-07-24

Family

ID=64821489

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810664409.1A Active CN109064325B (en) 2018-06-25 2018-06-25 Intelligent contract implementation method and device based on block chain

Country Status (1)

Country Link
CN (1) CN109064325B (en)

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109710385A (en) * 2018-12-29 2019-05-03 杭州趣链科技有限公司 A kind of intelligent contract complexity method for limiting based on Java Virtual Machine
CN112529582A (en) * 2019-08-20 2021-03-19 厦门本能管家科技有限公司 Multistage transaction acceleration method and system for block chain
CN111274576B (en) * 2020-01-17 2022-08-02 山东浪潮科学研究院有限公司 Control method, system, equipment and medium for intelligent contract operating environment
US20210314139A1 (en) * 2020-04-01 2021-10-07 International Business Machines Corporation Noisy transaction for protection of data
CN111383018B (en) * 2020-05-28 2020-09-25 支付宝(杭州)信息技术有限公司 Node group creating method and node group-based transaction method in alliance chain network
CN111898766B (en) * 2020-07-31 2023-02-24 平安科技(深圳)有限公司 Ether house fuel limitation prediction method and device based on automatic machine learning
CN113094396B (en) * 2021-01-18 2022-07-26 腾讯科技(深圳)有限公司 Data processing method, device, equipment and medium based on node memory

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106559211A (en) * 2016-11-22 2017-04-05 中国电子科技集团公司第三十研究所 Secret protection intelligence contract method in a kind of block chain
CN107016611A (en) * 2017-03-29 2017-08-04 杭州秘猿科技有限公司 A kind of transaction manufacture timeout control method based on block chain
CN107239953A (en) * 2017-06-20 2017-10-10 无锡井通网络科技有限公司 Fast data store method and system based on block chain
CN107481011A (en) * 2017-08-11 2017-12-15 杭州秘猿科技有限公司 A kind of transaction rapid acknowledgment method based on license chain
CN107577694A (en) * 2017-07-14 2018-01-12 阿里巴巴集团控股有限公司 A kind of data processing method and equipment based on block chain

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106559211A (en) * 2016-11-22 2017-04-05 中国电子科技集团公司第三十研究所 Secret protection intelligence contract method in a kind of block chain
CN107016611A (en) * 2017-03-29 2017-08-04 杭州秘猿科技有限公司 A kind of transaction manufacture timeout control method based on block chain
CN107239953A (en) * 2017-06-20 2017-10-10 无锡井通网络科技有限公司 Fast data store method and system based on block chain
CN107577694A (en) * 2017-07-14 2018-01-12 阿里巴巴集团控股有限公司 A kind of data processing method and equipment based on block chain
CN107481011A (en) * 2017-08-11 2017-12-15 杭州秘猿科技有限公司 A kind of transaction rapid acknowledgment method based on license chain

Also Published As

Publication number Publication date
CN109064325A (en) 2018-12-21

Similar Documents

Publication Publication Date Title
CN109064325B (en) Intelligent contract implementation method and device based on block chain
US10929198B2 (en) Blockchain-based resource allocation method and apparatus
Guerraoui et al. The consensus number of a cryptocurrency
CN110471984B (en) Service processing method and device based on block chain and electronic equipment
CN108829350B (en) Data migration method and device based on block chain
WO2021197097A1 (en) Cross-chain data subscription
CN110162470B (en) Block chain testing method and device
EP3565219B1 (en) Service execution method and device
CN111898360A (en) Text similarity detection method and device based on block chain and electronic equipment
CN111478828B (en) Pressure testing method, device and system for block chain network
CN111488291B (en) Pressure testing method, device and system for block chain network
CN109032803B (en) Data processing method and device and client
CN110704438B (en) Method and device for generating bloom filter in blockchain
CN112560114B (en) Method and device for calling intelligent contract
CN113220717B (en) Block chain-based data verification method and device and electronic equipment
CN111245897B (en) Data processing method, device, system, storage medium and processor
CN111443894A (en) Random number generation method, device and medium based on block chain
CN112291321B (en) Service processing method, device and system
US20230409450A1 (en) Consensus processing method and apparatus for blockchain network
CN111679902B (en) Intelligent contract calling method and device based on block chain and electronic equipment
CN113327169B (en) Claims settlement method and device based on block chain and electronic equipment
CN116112507A (en) Hierarchical blockchain-based multitasking asynchronous execution method and device
CN113495927B (en) Block management method and device
CN114491662A (en) Block chain-based data asset auditing method, system and equipment
CN112925659A (en) Message processing method, device, equipment and computer storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
TR01 Transfer of patent right

Effective date of registration: 20200728

Address after: B1910, building 9, zone 2, Shenzhen Bay science and technology ecological park, 3609 Baishi Road, community, high tech Zone, Yuehai street, Nanshan District, Shenzhen City, Guangdong Province

Patentee after: Shenzhen smart chain Future Technology Co., Ltd

Address before: 310026 401 unit -1, 3 unit of Wen Yi Road 1218, Cang Qian Road, Yuhang District, Hangzhou, Zhejiang, China, 401

Patentee before: ZHEJIANG ULTRAIN SPACE TECHNOLOGY Co.,Ltd.

TR01 Transfer of patent right
CP03 Change of name, title or address

Address after: 518054 unit 201, 202, 203, 2nd floor, unit 301, 302, 303, 3rd floor, building A1, commercial plaza, 191 science Avenue, Huangpu District, Guangzhou City, Guangdong Province

Patentee after: Guangzhou smart chain Future Technology Co.,Ltd.

Address before: B1910, building 9, zone 2, Shenzhen Bay science and technology ecological park, 3609 Baishi Road, high tech Zone community, Yuehai street, Nanshan District, Shenzhen, Guangdong 518054

Patentee before: Shenzhen smart chain Future Technology Co., Ltd

CP03 Change of name, title or address