CN112118289B - Self-adaptive synchronization method and system for intelligent contract - Google Patents

Self-adaptive synchronization method and system for intelligent contract Download PDF

Info

Publication number
CN112118289B
CN112118289B CN202010808928.8A CN202010808928A CN112118289B CN 112118289 B CN112118289 B CN 112118289B CN 202010808928 A CN202010808928 A CN 202010808928A CN 112118289 B CN112118289 B CN 112118289B
Authority
CN
China
Prior art keywords
node
intelligent contract
execution
contract
record
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
CN202010808928.8A
Other languages
Chinese (zh)
Other versions
CN112118289A (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.)
Peking University
Original Assignee
Peking University
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 Peking University filed Critical Peking University
Priority to CN202010808928.8A priority Critical patent/CN112118289B/en
Publication of CN112118289A publication Critical patent/CN112118289A/en
Application granted granted Critical
Publication of CN112118289B publication Critical patent/CN112118289B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • H04L67/1095Replication or mirroring of data, e.g. scheduling or transport for data synchronisation between network nodes
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • H04L67/104Peer-to-peer [P2P] networks
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/133Protocols for remote procedure calls [RPC]

Abstract

The embodiment of the invention provides a self-adaptive synchronization method and a self-adaptive synchronization system for an intelligent contract, which relate to the technical field of block chains, and can greatly improve the execution efficiency of trusted computing by randomly selecting a preset number of nodes in a P2P network through a request node so as to synchronously call the intelligent contract by the preset number of nodes; and simultaneously, a contract state synchronization mechanism is provided, the contract execution is recorded in the multi-node synchronous calling process, and when synchronization is needed, the required contract calling execution record is obtained from the node in the latest state and is played back locally, so that the random multi-node state can be quickly recovered when the random multi-node state is asynchronous, high availability is realized, and a data analysis scene with low response time can be met.

Description

Self-adaptive synchronization method and system for intelligent contract
Technical Field
The invention relates to the technical field of block chains, in particular to an adaptive synchronization method and an adaptive synchronization system for an intelligent contract.
Background
The blockchain is originated from the bitcoin of the Chinese intelligence, and is essentially a technical scheme for collectively maintaining a reliable database in a decentralized and distrust manner. The method depends on cryptography and a distributed algorithm with skillful mathematics, so that participants can achieve consensus and complete reliable transmission of trust and value on the Internet without any trust center on which a trust relationship cannot be established. The program running on the blockchain, namely the intelligent contract, provides the service of trusted computing by a redundant computing mode.
Public-chain-based blockchain platforms are typical blockchain platforms that provide trusted computing, which has three implications: 1) input to the computation is to be trusted; 2) the process of calculation is to be trusted; 3) the result of the calculation is to be trusted. Firstly, all input forms are contract calls, the contract calls are recorded on an account book, and the contract calls comprise method names and parameter instances. By using the data on the credible account book as input, the Ethenhouse realizes the credibility of calculation input. Secondly, the code logic of the contract is also recorded on the trusted account book, so that each node can know what kind of computing logic should be executed, and the computing process is trusted. Finally, the Ethengfang ensures that the same output result can be generated under the same contract code, the same initial state and the same input through the contract language specification, thereby ensuring the credible calculation result. However, this consensus execution model of the etherhouse is computationally expensive — only contract code and contract calls after consensus of all nodes are considered to be "executed" state, and therefore, this execution model of the etherhouse is not suitable for data analysis scenarios requiring low response time.
Disclosure of Invention
In view of the above problems, embodiments of the present invention are proposed to provide an adaptive synchronization method for intelligent contracts and a corresponding adaptive synchronization system for intelligent contracts, which overcome or at least partially solve the above problems.
According to one aspect of the invention, the embodiment of the invention discloses an adaptive synchronization method for intelligent contracts, which comprises the following steps:
when any node in a pre-constructed P2P network receives an execution request aiming at the intelligent contract sent by a user side, the node is used as a request node to randomly select a preset number of nodes in the P2P network so as to enable the preset number of nodes to synchronously call the intelligent contract;
the node records the execution of the intelligent contract according to a predetermined contract execution recording strategy in the intelligent contract calling process;
when any node in the preset number of nodes fails or the intelligent contract cannot be synchronously called, determining a target node in the current latest state in the preset number of nodes, and acquiring an execution record of the target node on the intelligent contract;
recording the execution of the target node on the intelligent contract in a new node or a node incapable of synchronously calling the intelligent contract for playback; wherein the new node is a node randomly selected in the P2P network except for the preset number of nodes.
Optionally, the number of the intelligent contracts is multiple, each node stores an execution record list, and the execution record list records execution records of multiple intelligent contracts;
when any node in the preset number of nodes fails or cannot synchronously call the intelligent contract, determining a target node in the current latest state in the preset number of nodes, and acquiring an execution record of the target node on the intelligent contract, wherein the execution record comprises:
when any node in the preset number of nodes fails or can not synchronously call a certain target intelligent contract, determining a target node in the current latest state in the preset number of nodes, and searching an execution record of the target node on the target intelligent contract in an execution record list of the target node;
and extracting the execution record of the target node on the target intelligent contract from the execution record list.
Optionally, when the contract execution recording policy is a transaction-based contract execution recording policy, a transaction recording file is set in each node;
the node records the execution of the intelligent contract according to a predetermined contract execution recording strategy in the intelligent contract calling process, and the method comprises the following steps:
the node judges whether a new transaction request exists in the intelligent contract calling process;
when a new transaction request exists, the node marks the transaction corresponding to the transaction request, and writes the parameters and the input and output I/O data used in the execution of the transaction into the transaction record file as transaction records.
Optionally, recording the execution of the target node on the intelligent contract in a new node or a node which cannot synchronously invoke the intelligent contract for playback, where the recording includes:
the new node or the node which can not synchronously call the intelligent contract receives the transaction record file of the target node and judges whether the next transaction record exists in the transaction record file of the target node;
and when a next transaction record exists, the new node or the node which can not synchronously call the intelligent contract judges whether the transaction record is written into a local transaction record file or not, and executes the transaction according to the transaction record.
Optionally, when the contract execution recording policy is a contract execution recording policy based on heap operation, a heap operation recording file is set in each node;
the node records the execution of the intelligent contract according to a predetermined contract execution recording strategy in the intelligent contract calling process, and the method comprises the following steps:
the node judges whether a new transaction request exists in the intelligent contract calling process;
when no new transaction request exists, deleting the repeated assignment operation in the recorded heap operation by the node, and writing the rest recorded heap operation into the heap operation record file;
when a new transaction request exists, the node executes the following steps:
judging whether a new stack operation is generated;
when a new heap operation is generated, judging whether the heap operation is an operation on a local variable;
and when the heap operation is not the operation on the local variable, recording the heap operation, and continuously judging whether a new heap operation is generated.
Optionally, recording the execution of the target node on the intelligent contract in a new node or a node which cannot synchronously invoke the intelligent contract for playback, where the recording includes:
the new node or the node which can not synchronously call the intelligent contract receives the heap operation record file of the target node, and judges whether the next heap operation record exists in the heap operation record file of the target node;
and when the next heap operation record exists, the new node or the node which cannot synchronously call the intelligent contract analyzes the heap operation record, and executes an analysis result.
Optionally, when the contract execution recording policy is a heap dump-based contract execution recording policy, a heap dump recording file is set in the node;
the node records the execution of the intelligent contract according to a predetermined contract execution recording strategy in the intelligent contract calling process, and the method comprises the following steps:
the node creates a Map, and the Map is used for storing objects in the intelligent contract;
the node acquires all objects in the intelligent contract at the current moment after the intelligent contract is executed, and judges whether the objects in the intelligent contract at the current moment have unresolved objects or not;
when all objects in the intelligent contract at the current moment have no unresolved objects, the node writes all the objects in the intelligent contract at the current moment into the heap dump record file;
when all the objects in the intelligent contract have the unresolved objects at the current moment, the node executes the following steps:
the node judges whether the object has an unresolved attribute;
when the object has the unresolved attribute, the node resolves the object and the attribute thereof, and stores the object and the attribute thereof into the Map after the resolution;
and when the object has no unresolved attribute, the node stores the object into the Map.
Optionally, recording the execution of the target node on the intelligent contract in a new node or a node which cannot synchronously invoke the intelligent contract for playback, where the recording includes:
the new node or the node which can not synchronously call the intelligent contract receives a heap dump record file of the target node;
the new node or the node which can not synchronously call the intelligent contract analyzes the heap dump record file of the target node, and stores the content in the heap dump record file of the target node into a Map which is created in advance;
the new node or the node which can not synchronously call the intelligent contract judges whether an unrecovered object exists in the Map or not;
when an unrecovered object exists in the Map, the new node or the node which cannot synchronously call the intelligent contract creates the object;
and when the Map has no unrecovered object, the new node or the node which cannot synchronously call the intelligent contract judges whether the Map has an object with unrecovered attribute, and when the Map has the object with unrecovered attribute, the new node or the node which cannot synchronously call the intelligent contract recovers the attribute of the object.
Based on the same inventive concept, according to one aspect of the present invention, the embodiment of the present invention discloses an adaptive synchronization system for intelligent contracts, the system comprising:
the synchronous node selection module is configured in a request node, the request node is any node in a P2P network which is constructed in advance, and the synchronous node selection module is used for randomly selecting a preset number of nodes in the P2P network when receiving an execution request which is sent by a user side and aims at the intelligent contract, so that the preset number of nodes synchronously call the intelligent contract;
a contract execution recording module configured in the node, configured to record execution of the intelligent contract according to a predetermined contract execution recording policy in the process of invoking the intelligent contract;
an execution record obtaining module, configured to determine a target node currently in a latest state in the preset number of nodes when any node in the preset number of nodes fails or the intelligent contract cannot be synchronously called, and obtain an execution record of the target node on the intelligent contract;
the execution recording playback module is used for recording the execution of the target node on the intelligent contract in a new node or a node which can not synchronously call the intelligent contract for playback; wherein the new node is a node randomly selected in the P2P network except for the preset number of nodes.
Optionally, the number of the intelligent contracts is multiple, each node stores an execution record list, and the execution record list records execution records of multiple intelligent contracts; the execution record obtaining module includes:
the execution record searching submodule is used for determining a target node which is currently in the latest state in the preset number of nodes when any node in the preset number of nodes fails or the intelligent contract cannot be synchronously called, and searching an execution record of the target node on the target intelligent contract in an execution record list of the target node;
and the execution record extraction submodule is used for extracting the execution record of the target node on the target intelligent contract from the execution record list.
The embodiment of the invention has the following advantages:
in the embodiment of the invention, any node in a pre-constructed P2P network is used as a request node to randomly select a preset number of nodes in the P2P network, so that the preset number of nodes synchronously call the intelligent contract, and the execution efficiency of trusted computing can be greatly improved through synchronous execution of random multiple points.
The embodiment of the invention also provides a contract state synchronization mechanism, which records the execution of the contract in the multi-node synchronous calling process, acquires the required execution record of the contract calling from the node in the latest state and plays the record locally when the synchronization is needed, thereby ensuring the copy number, rapidly recovering the random multi-node state when the random multi-node state is asynchronous, realizing high availability and meeting the data analysis scene with low response time.
Drawings
FIG. 1 is a flow chart of the steps of an adaptive synchronization method for intelligent contracts according to an embodiment of the present invention;
FIG. 2(a) is an execution logging flow diagram of a transaction-based contract execution logging policy according to an embodiment of the invention;
FIG. 2(b) is a diagram of a transaction-based contract execution playback flow according to an embodiment of the present invention;
FIG. 3(a) is a flow diagram of contract execution record based on heap operations according to an embodiment of the invention
FIG. 3(b) is a diagram of a contract execution playback flow based on heap operations according to an embodiment of the present invention;
FIG. 4(a) is a flow diagram of a contract execution record based on heap dump according to an embodiment of the present invention;
FIG. 4(b) is a diagram of a contract execution playback flow based on heap dump according to an embodiment of the present invention;
FIG. 5 is a schematic diagram of the memory footprint of the TimeCalculator contract using different policies;
FIG. 6 is a schematic diagram of the playback time for the TimeCalculator contract using different policies;
FIG. 7 is a schematic diagram of memory usage for a BDPoint smart contract using different policies;
FIG. 8 is a schematic illustration of playback of a BDPoint smart contract using different policies;
FIG. 9 is a schematic diagram of memory usage for ImageMatcher smart contracts using different policies;
FIG. 10 is a schematic illustration of the use of playback by an ImageMatcher smart contract using different policies;
fig. 11 is a schematic structural diagram of an adaptive synchronization system for an intelligent contract according to an embodiment of the present invention.
Detailed Description
In order to make the aforementioned objects, features and advantages of the present invention comprehensible, embodiments accompanied with figures are described in further detail below.
Aiming at the technical problem of the embodiment of the invention, the embodiment of the invention provides a scheme for randomly selecting a plurality of nodes in a network to synchronously call an intelligent contract and execute data analysis logic based on a block chain platform of trusted computing, and the execution efficiency of the trusted computing can be greatly improved. Meanwhile, in consideration of the fact that factors such as network partitioning and node downtime influence the synchronous execution of the multi-node state, the embodiment of the invention also provides a contract state synchronization mechanism, and by recording the execution of contracts in the multi-node synchronous calling process, when synchronization is needed, the required execution record of the contract calling is obtained from the node in the latest state and is played back locally, so that the copy number is ensured, the random multi-node state can be quickly recovered when the random multi-node state is asynchronous, high availability is realized, and a data analysis scene with low response time is met.
Referring to fig. 1, a flow chart illustrating steps of an adaptive synchronization method for intelligent contracts according to an embodiment of the present invention is shown, the method including the steps that may include:
step S101, when any node in a pre-constructed P2P network receives an execution request aiming at the intelligent contract sent by a user side, the node is used as a request node to randomly select a preset number of nodes in the P2P network so as to enable the preset number of nodes to synchronously call the intelligent contract;
in the embodiment of the invention, firstly, various participants (including data providers, node providers and data users) are connected through a P2P network to form a distributed peer-to-peer computing network, and each node in the network corresponds to a common personal computer or a virtual machine. Data access intelligence contracts and data analysis intelligence contracts run on top of nodes in this network.
The embodiment of the invention is improved based on the existing trusted computing platform of the intelligent contract, and the trusted computing process can refer to the related prior art, and the embodiment of the invention is not repeated herein. For example, nodes participating in the P2P network can issue tasks and receive tasks, and task receivers provide services of trusted computing. In the network, the task correctness verification can adopt a simple redundant calculation mode, namely the task is sent to two persons, the results are mutually verified, and if the results are the same, the verification is passed. Compared with the prior art, the method has the advantages that any node randomly selected by the user side in the P2P network is used as the request node, the request node initiates synchronous calling of the multi-point intelligent contract, and the execution efficiency of the intelligent contract can be effectively improved. The number of nodes selected (the preset number) may be selected according to the user's needs.
Because the nodes in the network are ordinary personal computers or virtual machines, the nodes have the possibility of downtime and network failure in the actual synchronization process. Therefore, the embodiment of the present invention provides a self-adaptive synchronization algorithm (i.e., a contract state synchronization mechanism), the implementation steps refer to step S102 to step S104, and by using the algorithm, state transition when local contract state transition and states between nodes are not synchronized can be implemented, and when problems such as network partitioning and node downtime occur, a preset number of nodes can be maintained to run the same contract and implement quick response of contract execution, which is a main way for improving node reliability. That is, for a certain node in the block chain, the shorter the failure recovery time of a single node is, the higher the reliability and availability of the framework is.
Step S102, the node records the execution of the intelligent contract according to a predetermined contract execution recording strategy in the intelligent contract calling process;
step S103, when any node in the preset number of nodes fails or the intelligent contract cannot be synchronously called, determining a target node in the current latest state in the preset number of nodes, and acquiring an execution record of the target node on the intelligent contract;
step S104, recording the execution of the target node on the intelligent contract in a new node or a node which can not synchronously call the intelligent contract for playback; wherein the new node is a node randomly selected in the P2P network except for the preset number of nodes.
In an embodiment of the invention, the adaptive synchronization algorithm is implemented by "record-playback". The main flow of the algorithm is to record the execution of the contract during each contract invocation. When synchronization is required, an execution record of the required contract invocation is retrieved from the node in the latest state and played back locally. In actual execution, the number of the intelligent contracts which can be executed by each node is multiple, that is, each node stores an execution record list in which the execution records of multiple intelligent contracts are recorded. Step S103 may comprise the following sub-steps:
when any node in the preset number of nodes fails or can not synchronously call a certain target intelligent contract, determining a target node in the current latest state in the preset number of nodes, and searching an execution record of the target node on the target intelligent contract in an execution record list of the target node;
and extracting the execution record of the target node on the target intelligent contract from the execution record list.
The failed node means that the node cannot execute any more execution for the intelligent contract, that is, cannot invoke the intelligent contract, and the node is not available, and at this time, a node needs to be reselected in the P2P network to replace the node, that is, a new node according to the embodiment of the present invention. A node that is unable to invoke the intelligent contracts synchronously refers to a node that may suddenly experience a brief downtime, but is still able to continue invoking intelligent contracts.
The intelligent contract can be different types of contracts such as IO intensive contracts, CPU intensive contracts and memory intensive contracts, execution records of the intelligent contracts recorded by execution record lists of different nodes are possibly partially different, new nodes or nodes which cannot synchronously call the intelligent contract take intelligent contracts which need to be synchronized as target intelligent contracts, then the execution records of the target nodes on the target intelligent contracts are searched in the execution record lists of the target nodes, and corresponding execution records are extracted.
Before each contract call, the self-adaptive synchronization algorithm selects the contract execution recording strategy called this time according to the context environment before execution. The contract execution recording strategy provided by the embodiment of the invention comprises three strategies: a transaction-based contract execution record, a heap-operation-based contract execution record, and a heap-dump-based contract execution record. Each strategy has different characteristics and is suitable for different types of intelligent contracts.
In an optional embodiment of the present invention, when the contract execution logging policy is a transaction-based contract execution logging policy, a transaction logging file is set in each node; step S102 may include:
the node judges whether a new transaction request exists in the intelligent contract calling process;
when a new transaction request exists, the node marks the transaction corresponding to the transaction request, and writes the parameters and the input and output I/O data used in the execution of the transaction into the transaction record file as transaction records. Referring to FIG. 2(a), an execution logging flow diagram for a transaction-based contract execution logging policy is shown.
The execution recording based on the policy, i.e., step S104, may include the following playback steps:
the new node or the node which can not synchronously call the intelligent contract receives the transaction record file of the target node and judges whether the next transaction record exists in the transaction record file of the target node;
and when a next transaction record exists, the new node or the node which can not synchronously call the intelligent contract judges whether the transaction record is written into a local transaction record file or not, and executes the transaction according to the transaction record. Referring to FIG. 2(b), a transaction-based contract execution playback flow diagram is shown.
In an optional embodiment of the present invention, when the contract execution logging policy is a heap operation-based contract execution logging policy, a heap operation logging file is set in each node; step S102 may include the following recording steps:
the node judges whether a new transaction request exists in the intelligent contract calling process;
when no new transaction request exists, deleting the repeated assignment operation in the recorded heap operation by the node, and writing the rest recorded heap operation into the heap operation record file;
when a new transaction request exists, the node executes the following steps:
judging whether a new stack operation is generated;
when a new heap operation is generated, judging whether the heap operation is an operation on a local variable;
and when the heap operation is not the operation on the local variable, recording the heap operation, and continuously judging whether a new heap operation is generated. Referring to FIG. 3(a), a contract execution logging flow diagram based on heap operations is shown.
When performing contract state synchronization using a heap operation based state synchronization algorithm, step S104 may include the following playback steps:
the new node or the node which can not synchronously call the intelligent contract receives the heap operation record file of the target node, and judges whether the next heap operation record exists in the heap operation record file of the target node;
and when the next heap operation record exists, the new node or the node which cannot synchronously call the intelligent contract analyzes the heap operation record, and executes an analysis result. Referring to FIG. 3(b), a contract execution playback flow diagram based on heap operations is shown.
In an optional embodiment of the present invention, when the contract execution recording policy is a heap dump based contract execution recording policy, a heap dump recording file is set in the node; a heap dump based synchronization algorithm will record the current state of a contract after its execution is complete. The state of the contract at the current time is recorded through the corresponding object and the attribute thereof. Step S102 may include the following recording steps:
the node creates a Map, and the Map is used for storing objects in the intelligent contract;
the node acquires all objects in the intelligent contract at the current moment after the intelligent contract is executed, and judges whether the objects in the intelligent contract at the current moment have unresolved objects or not;
when all objects in the intelligent contract at the current moment have no unresolved objects, the node writes all the objects in the intelligent contract at the current moment into the heap dump record file;
when all the objects in the intelligent contract have the unresolved objects at the current moment, the node executes the following steps:
the node judges whether the object has an unresolved attribute;
when the object has the unresolved attribute, the node resolves the object and the attribute thereof, and stores the object and the attribute thereof into the Map after the resolution;
and when the object has no unresolved attribute, the node stores the object into the Map. Referring to FIG. 4(a), a contract execution recording flow diagram based on heap dump is shown.
The synchronization algorithm based on heap dump is divided into two stages when carrying out contract state synchronization: and restoring each object in the contract, and restoring the attribute of the object with the attribute. Step S104 may include the following playback steps:
the new node or the node which can not synchronously call the intelligent contract receives a heap dump record file of the target node;
the new node or the node which can not synchronously call the intelligent contract analyzes the heap dump record file of the target node, and stores the content in the heap dump record file of the target node into a Map which is created in advance;
the new node or the node which can not synchronously call the intelligent contract judges whether an unrecovered object exists in the Map or not;
when an unrecovered object exists in the Map, the new node or the node which cannot synchronously call the intelligent contract creates the object;
and when the Map has no unrecovered object, the new node or the node which cannot synchronously call the intelligent contract judges whether the Map has an object with unrecovered attribute, and when the Map has the object with unrecovered attribute, the new node or the node which cannot synchronously call the intelligent contract recovers the attribute of the object. Referring to FIG. 4(b), a contract execution playback flow based on heap dump is shown.
And (3) effect evaluation:
the embodiment of the invention evaluates three different algorithms of state synchronization in different types of contracts respectively. The size of the storage space required by the synchronization algorithm based on the transaction to carry out state synchronization is represented by the file size of the contract transaction recorded by the algorithm, the size of the storage space required by the synchronization algorithm based on the heap dump to carry out contract state synchronization is represented by the file size of the contract state recorded by the algorithm, and the size of the storage space required by the synchronization algorithm based on the heap operation to carry out state synchronization is represented by the file size of the contract heap operation recorded by the algorithm. The embodiment of the invention selects typical intelligent contracts such as a currency-sending contract BDCoin meeting the ERC-20(ERC-20, 2020) specification, a Tensorflow-based picture recognition contract ImageMatcher and the like, covers typical intelligent contract types such as a memory intensive type and a CPU intensive type, and carries out the following evaluation, wherein the intelligent contracts used in the evaluation are shown in a table 1.
TABLE 1
Figure BDA0002630201210000111
Simple type intelligent contract
The embodiment of the invention uses the TimeCalculator contract for evaluation. The contract accepts any parameter and returns the total called times, and belongs to a contract which is not CPU intensive and has a small memory occupied by contract variables. As the number of transactions increases, the storage space required by the three strategies is shown in FIG. 5.
The time required for the three strategies as the number of transactions increases is shown in figure 6. It can be seen from fig. 6 that the storage space required by the heap dump based policy is the largest when the number of transactions is small. As the number of transactions increases, the amount of storage space required by heap operation based policies increases rapidly, and the amount of storage space required by both heap operation based synchronization algorithms and transaction based synchronization algorithms may exceed the amount of storage space required by heap dump based synchronization algorithms. Although state synchronization by a heap operation based synchronization algorithm is faster than a transaction based synchronization algorithm, the heap operation based synchronization algorithm requires much more memory than the transaction based synchronization algorithm. Therefore, for contracts which are not CPU-intensive and have small memory occupied by contract variables, the state synchronization based on the heap dump algorithm is better.
(II) memory intensive contract
Embodiments of the present invention use bdjoin smart contracts for evaluation. The memory usage of the smart contract increases with the number of created accounts. The storage space occupation of these three strategies is shown in fig. 7.
As the number of transactions increases, the time required for playback of the three strategies is shown in fig. 8. As can be seen from the data in FIG. 8, for this type of contract, the storage space occupied by the heap dump based synchronization algorithm is no longer minimal. When the transaction amount is small, the storage space required by the synchronization algorithm based on heap operation and the synchronization algorithm based on transaction is small, wherein the synchronization algorithm based on heap operation is shorter than the synchronization algorithm based on transaction, so that the synchronization by the synchronization algorithm based on heap operation can be adopted. When the transaction amount increases, the required memory space is larger, although the heap operation-based synchronization algorithm takes shorter than the transaction-based synchronization algorithm. Thus, a transaction-based synchronization algorithm or a heap dump-based synchronization algorithm may be employed for state synchronization for memory-intensive contracts.
(III) CPU intensive contract
The embodiment of the invention uses the ImageMatch intelligent contract for evaluation, and the storage space required by the three algorithms is shown in FIG. 9 along with the increase of the number of the transactions.
As the number of transactions increases, the time required for synchronization of the three algorithms is shown in FIG. 10, and for this type of contract, the state synchronization using a synchronization algorithm based on heap dump and a synchronization algorithm based on heap operation are not very different and are both much smaller than using a synchronization algorithm based on transactions. While a synchronization algorithm based on heap operations occupies less storage space than a synchronization algorithm based on heap dumps. Thus, for CPU-intensive contracts, it is preferable to use a synchronization algorithm based on heap operations and a synchronization algorithm based on heap dumps. Through the comparison analysis of two dimensions of time and space of the three state synchronization algorithms under the scenes of different types of contracts, the most suitable algorithm is selected for state synchronization of the contracts of different types, so that the space and time cost can be better saved.
The result shows that the synchronization efficiency can reach the minute level for different types of intelligent contracts.
It should be noted that, for simplicity of description, the method embodiments are described as a series of acts or combination of acts, but those skilled in the art will recognize that the present invention is not limited by the illustrated order of acts, as some steps may occur in other orders or concurrently in accordance with the embodiments of the present invention. Further, those skilled in the art will appreciate that the embodiments described in the specification are presently preferred and that no particular act is required to implement the invention.
Referring to fig. 11, a schematic structural diagram of an adaptive synchronization system for an intelligent contract according to an embodiment of the present invention is shown, where the system may include:
a synchronous node selection module 1101, configured to randomly select a preset number of nodes in a P2P network that is constructed in advance, so that the preset number of nodes synchronously invoke an intelligent contract;
a contract execution recording module 1102 configured in the node, configured to record, according to a predetermined contract execution recording policy, execution of the intelligent contract in the process of invoking the intelligent contract;
an execution record obtaining module 1103, configured to determine, when any node in the preset number of nodes fails or cannot synchronously invoke the intelligent contract, a target node currently in a latest state in the preset number of nodes, and obtain an execution record of the target node on the intelligent contract;
an execution recording playback module 1104, configured to record, for playback, the execution of the intelligent contract by the target node in a new node or a node that cannot synchronously invoke the intelligent contract; wherein the new node is a node randomly selected in the P2P network except for the preset number of nodes.
In an optional embodiment of the present invention, when there are a plurality of intelligent contracts, each node stores an execution record list, and the execution record list records execution records of the plurality of intelligent contracts;
the execution record obtaining module 1103 includes the following sub-modules:
the execution record searching submodule is used for determining a target node which is currently in the latest state in the preset number of nodes when any node in the preset number of nodes fails or the intelligent contract cannot be synchronously called, and searching an execution record of the target node on the target intelligent contract in an execution record list of the target node;
and the execution record extraction submodule is used for extracting the execution record of the target node on the target intelligent contract from the execution record list.
In an optional embodiment of the present invention, when the contract execution logging policy is a transaction-based contract execution logging policy, a transaction logging file is set in each node;
the contract execution recording module 1102 may include the following sub-modules:
the transaction request judging submodule is used for judging whether a new transaction request exists in the intelligent contract calling process;
and the transaction record writing sub-module is used for labeling the transaction corresponding to the transaction request when a new transaction request exists, and writing parameters and input/output (I/O) data used during the execution of the transaction into the transaction record file as transaction records.
In an optional embodiment of the present invention, the execution record playback module 1104 may include the following sub-modules:
the transaction record file receiving submodule is configured in the new node or the node which can not synchronously call the intelligent contract and is used for receiving the transaction record file of the target node and judging whether the next transaction record exists in the transaction record file of the target node;
and the transaction record execution sub-module is configured in the new node or the node which can not synchronously call the intelligent contract and is used for judging whether the transaction record is written into a local transaction record file or not when the next transaction record exists and executing the transaction according to the transaction record.
In an optional embodiment of the present invention, when the contract execution logging policy is a heap operation-based contract execution logging policy, a heap operation logging file is set in each node;
the contract execution recording module 1102 may include the following sub-modules:
the transaction request judging submodule is used for judging whether a new transaction request exists in the intelligent contract calling process;
the heap operation duplication removing sub-module is used for deleting the operation of repeated assignment in the recorded heap operations when no new transaction request exists, and then writing the residual recorded heap operations into the heap operation recording file;
the transaction request operation submodule is used for executing the following steps when a new transaction request exists:
judging whether a new stack operation is generated;
when a new heap operation is generated, judging whether the heap operation is an operation on a local variable;
and when the heap operation is not the operation on the local variable, recording the heap operation, and continuously judging whether a new heap operation is generated.
In an optional embodiment of the present invention, the execution record playback module 1104 may include the following sub-modules:
the heap operation record judging submodule is configured in the new node or the node which can not synchronously call the intelligent contract and is used for receiving the heap operation record file of the target node and judging whether the next heap operation record exists in the heap operation record file of the target node;
and the heap operation record analysis submodule is configured in the new node or the node which can not synchronously call the intelligent contract and is used for analyzing the heap operation record and executing an analysis result when the next heap operation record exists.
In an optional embodiment of the present invention, when the contract execution recording policy is a heap dump based contract execution recording policy, a heap dump recording file is set in the node; the contract execution recording module 1102 may include the following sub-modules:
the Map creating submodule is used for creating a Map, and the Map is used for storing the objects in the intelligent contract;
the object acquisition submodule is used for acquiring all objects in the intelligent contract at the current moment after the execution of the intelligent contract is finished, and judging whether the objects in the intelligent contract at the current moment have unresolved objects or not;
the object writing submodule is used for writing all the objects in the intelligent contract at the current moment into the heap dump record file by the node when no unresolved object exists in all the objects in the intelligent contract at the current moment;
an object analysis submodule, configured to, when an unresolved object exists in all objects in the intelligent contract at the current time, execute, by the node, the following steps:
judging whether the object has an unresolved attribute;
when the object has the unresolved attribute, analyzing the object and the attribute thereof, and storing the object and the attribute thereof into the Map after the object and the attribute thereof are analyzed;
and when the object has no unresolved attribute, the node stores the object into the Map.
In an optional embodiment of the present invention, the execution record playback module 1104 may include the following sub-modules:
the heap dump record file receiving submodule is configured in the new node or the node which can not synchronously call the intelligent contract and is used for receiving the heap dump record file of the target node;
the heap dump record file analysis sub-module is configured in the new node or the node which can not synchronously call the intelligent contract, and is used for analyzing the heap dump record file of the target node and storing the content in the heap dump record file of the target node into a Map created in advance;
the Map judging submodule is configured in the new node or the node which can not synchronously call the intelligent contract and is used for judging whether an unrecovered object exists in the Map or not;
the object creating submodule is configured in the new node or the node which can not synchronously call the intelligent contract and is used for creating an unrecovered object when the object is in the Map;
and the object recovery sub-module is configured in the new node or the node which can not synchronously call the intelligent contract, and is used for judging whether an object with an unrecovered attribute exists in the Map or not when the object with the unrecovered attribute does not exist in the Map, and recovering the attribute of the object when the object with the unrecovered attribute exists.
For the system embodiment, since it is basically similar to the method embodiment, the description is simple, and for the relevant points, refer to the partial description of the method embodiment.
The embodiments in the present specification are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other.
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, embodiments of 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, embodiments of 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.
Embodiments of the present invention are described with reference to flowchart illustrations and/or block diagrams of methods, terminal devices (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 terminal to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal, 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 terminal 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 terminal to cause a series of operational steps to be performed on the computer or other programmable terminal to produce a computer implemented process such that the instructions which execute on the computer or other programmable terminal provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While preferred embodiments of the present invention have been described, additional variations and modifications of these embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all such alterations and modifications as fall within the scope of the embodiments of the invention.
Finally, it should also be noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or terminal 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 terminal. 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 terminal that comprises the element.
The foregoing describes in detail a self-adaptive synchronization method for an intelligent contract and a self-adaptive synchronization system for an intelligent contract, and a specific example is applied in the present document to explain the principle and the implementation of the present invention, and the description of the foregoing embodiments is only used to help understand the method and the core idea of the present invention; meanwhile, for a person skilled in the art, according to the idea of the present invention, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present invention.

Claims (10)

1. An adaptive synchronization method for intelligent contracts, the method comprising:
when any node in a pre-constructed P2P network receives an execution request aiming at the intelligent contract sent by a user side, the node is used as a request node to randomly select a preset number of nodes in the P2P network so as to enable the preset number of nodes to synchronously call the intelligent contract;
the node records the execution of the intelligent contract according to a predetermined contract execution recording strategy in the intelligent contract calling process;
when any node in the preset number of nodes fails or the intelligent contract cannot be synchronously called, determining a target node in the current latest state in the preset number of nodes, and acquiring an execution record of the target node on the intelligent contract;
recording the execution of the target node on the intelligent contract in a new node or a node incapable of synchronously calling the intelligent contract for playback; wherein the new node is a node randomly selected in the P2P network except for the preset number of nodes.
2. The method according to claim 1, wherein the intelligent contract is a plurality of intelligent contracts, each node stores an execution record list, and the execution record list records execution records of the plurality of intelligent contracts;
when any node in the preset number of nodes fails or cannot synchronously call the intelligent contract, determining a target node in the current latest state in the preset number of nodes, and acquiring an execution record of the target node on the intelligent contract, wherein the execution record comprises:
when any node in the preset number of nodes fails or can not synchronously call a certain target intelligent contract, determining a target node in the current latest state in the preset number of nodes, and searching an execution record of the target node on the target intelligent contract in an execution record list of the target node;
and extracting the execution record of the target node on the target intelligent contract from the execution record list.
3. The method of claim 1, wherein when the contract execution logging policy is a transaction-based contract execution logging policy, a transaction logging file is provided in each node;
the node records the execution of the intelligent contract according to a predetermined contract execution recording strategy in the intelligent contract calling process, and the method comprises the following steps:
the node judges whether a new transaction request exists in the intelligent contract calling process;
when a new transaction request exists, the node marks the transaction corresponding to the transaction request, and writes the parameters and the input and output I/O data used in the execution of the transaction into the transaction record file as transaction records.
4. The method of claim 3, wherein recording the execution of the intelligent contract by the target node for playback in a new node or a node that cannot synchronously invoke the intelligent contract comprises:
the new node or the node which can not synchronously call the intelligent contract receives the transaction record file of the target node and judges whether the next transaction record exists in the transaction record file of the target node;
and when a next transaction record exists, the new node or the node which can not synchronously call the intelligent contract judges whether the transaction record is written into a local transaction record file or not, and executes the transaction according to the transaction record.
5. The method according to claim 1, wherein when the contract execution logging policy is a heap operation based contract execution logging policy, a heap operation logging file is provided in each node;
the node records the execution of the intelligent contract according to a predetermined contract execution recording strategy in the intelligent contract calling process, and the method comprises the following steps:
the node judges whether a new transaction request exists in the intelligent contract calling process;
when no new transaction request exists, deleting the repeated assignment operation in the recorded heap operation by the node, and writing the rest recorded heap operation into the heap operation record file;
when a new transaction request exists, the node executes the following steps:
judging whether a new stack operation is generated;
when a new heap operation is generated, judging whether the heap operation is an operation on a local variable;
and when the heap operation is not the operation on the local variable, recording the heap operation, and continuously judging whether a new heap operation is generated.
6. The method of claim 5, wherein recording the execution of the intelligent contract by the target node for playback in a new node or a node that cannot synchronously invoke the intelligent contract comprises:
the new node or the node which can not synchronously call the intelligent contract receives the heap operation record file of the target node, and judges whether the next heap operation record exists in the heap operation record file of the target node;
and when the next heap operation record exists, the new node or the node which cannot synchronously call the intelligent contract analyzes the heap operation record, and executes an analysis result.
7. The method according to claim 1, wherein when the contract execution recording strategy is a heap dump based contract execution recording strategy, a heap dump recording file is arranged in the node;
the node records the execution of the intelligent contract according to a predetermined contract execution recording strategy in the intelligent contract calling process, and the method comprises the following steps:
the node creates a Map, and the Map is used for storing objects in the intelligent contract;
the node acquires all objects in the intelligent contract at the current moment after the intelligent contract is executed, and judges whether the objects in the intelligent contract at the current moment have unresolved objects or not;
when all objects in the intelligent contract at the current moment have no unresolved objects, the node writes all the objects in the intelligent contract at the current moment into the heap dump record file;
when all the objects in the intelligent contract have the unresolved objects at the current moment, the node executes the following steps:
the node judges whether the object has an unresolved attribute;
when the object has the unresolved attribute, the node resolves the object and the attribute thereof, and stores the object and the attribute thereof into the Map after the resolution;
and when the object has no unresolved attribute, the node stores the object into the Map.
8. The method of claim 7, wherein recording the execution of the intelligent contract by the target node for playback in a new node or a node that cannot synchronously invoke the intelligent contract comprises:
the new node or the node which can not synchronously call the intelligent contract receives a heap dump record file of the target node;
the new node or the node which can not synchronously call the intelligent contract analyzes the heap dump record file of the target node, and stores the content in the heap dump record file of the target node into a Map which is created in advance;
the new node or the node which can not synchronously call the intelligent contract judges whether an unrecovered object exists in the Map or not;
when an unrecovered object exists in the Map, the new node or the node which cannot synchronously call the intelligent contract creates the object;
and when the Map has no unrecovered object, the new node or the node which cannot synchronously call the intelligent contract judges whether the Map has an object with unrecovered attribute, and when the Map has the object with unrecovered attribute, the new node or the node which cannot synchronously call the intelligent contract recovers the attribute of the object.
9. An adaptive synchronization system for intelligent contracts, the system comprising:
the synchronous node selection module is configured in a request node, the request node is any node in a P2P network which is constructed in advance, and the synchronous node selection module is used for randomly selecting a preset number of nodes in the P2P network when receiving an execution request which is sent by a user side and aims at the intelligent contract, so that the preset number of nodes synchronously call the intelligent contract;
a contract execution recording module configured in the node, configured to record execution of the intelligent contract according to a predetermined contract execution recording policy in the process of invoking the intelligent contract;
an execution record obtaining module, configured to determine a target node currently in a latest state in the preset number of nodes when any node in the preset number of nodes fails or the intelligent contract cannot be synchronously called, and obtain an execution record of the target node on the intelligent contract;
the execution recording playback module is used for recording the execution of the target node on the intelligent contract in a new node or a node which can not synchronously call the intelligent contract for playback; wherein the new node is a node randomly selected in the P2P network except for the preset number of nodes.
10. The system according to claim 9, wherein the intelligent contract is a plurality of intelligent contracts, each node stores an execution record list, and the execution record list records execution records of the plurality of intelligent contracts; the execution record obtaining module includes:
the execution record searching submodule is used for determining a target node which is currently in the latest state in the preset number of nodes when any node in the preset number of nodes fails or the intelligent contract cannot be synchronously called, and searching an execution record of the target node on the target intelligent contract in an execution record list of the target node;
and the execution record extraction submodule is used for extracting the execution record of the target node on the target intelligent contract from the execution record list.
CN202010808928.8A 2020-08-12 2020-08-12 Self-adaptive synchronization method and system for intelligent contract Active CN112118289B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010808928.8A CN112118289B (en) 2020-08-12 2020-08-12 Self-adaptive synchronization method and system for intelligent contract

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010808928.8A CN112118289B (en) 2020-08-12 2020-08-12 Self-adaptive synchronization method and system for intelligent contract

Publications (2)

Publication Number Publication Date
CN112118289A CN112118289A (en) 2020-12-22
CN112118289B true CN112118289B (en) 2021-10-01

Family

ID=73804095

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010808928.8A Active CN112118289B (en) 2020-08-12 2020-08-12 Self-adaptive synchronization method and system for intelligent contract

Country Status (1)

Country Link
CN (1) CN112118289B (en)

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107103473A (en) * 2017-04-27 2017-08-29 电子科技大学 A kind of intelligent contract implementation method based on block chain
CN111161006A (en) * 2018-11-08 2020-05-15 北京京东尚科信息技术有限公司 Block chain credit service method, system and storage medium

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107819848A (en) * 2017-11-08 2018-03-20 济南浪潮高新科技投资发展有限公司 A kind of internet of things equipment autonomy interconnected method based on block chain
CN108510389B (en) * 2018-03-30 2020-12-18 深圳前海微众银行股份有限公司 Intelligent contract calling method and device based on block chain and readable storage medium
US20190303879A1 (en) * 2018-04-02 2019-10-03 Ca, Inc. Meeting recording software
CN108830632A (en) * 2018-04-24 2018-11-16 深圳市轱辘车联数据技术有限公司 A kind of integration managing method, block chain node device and client
US11488160B2 (en) * 2018-07-30 2022-11-01 Hewlett Packard Enterprise Development Lp Systems and methods for using captured time series of secured representations of distributed ledger addresses and smart contract deployed on distributed ledger network to prove compliance
CN109271810A (en) * 2018-08-01 2019-01-25 冼钇冰 A kind of exam information record system and exam information recording method based on block chain
CN110009498A (en) * 2019-03-29 2019-07-12 阿里巴巴集团控股有限公司 Resource allocation methods and device based on block chain

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107103473A (en) * 2017-04-27 2017-08-29 电子科技大学 A kind of intelligent contract implementation method based on block chain
CN111161006A (en) * 2018-11-08 2020-05-15 北京京东尚科信息技术有限公司 Block chain credit service method, system and storage medium

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
《SmartPipe: Towards Interoperability of Industrial Applications via Computational Reflection》;Huaqian Cai;《Springer》;20200117;161-178 *

Also Published As

Publication number Publication date
CN112118289A (en) 2020-12-22

Similar Documents

Publication Publication Date Title
EP3934165B1 (en) Consensus method of consortium blockchain, and consortium blockchain system
CN112118107B (en) Self-adaptive execution method for realizing data credibility
WO2021022875A1 (en) Distributed data storage method and system
CN107580032B (en) Data processing method, device and equipment
CN113568981B (en) Transaction data processing method, device, equipment and medium
JP6373489B2 (en) Compress cascading style sheet files
CN106899654A (en) A kind of sequence value generation method, apparatus and system
CN109271545A (en) A kind of characteristic key method and device, storage medium and computer equipment
CN115705255A (en) Learning causal relationships
CN110784498B (en) Personalized data disaster tolerance method and device
CN108897858B (en) Distributed cluster index fragmentation evaluation method and device and electronic equipment
CN110806913A (en) Webpage screenshot method, device and equipment
CN112118289B (en) Self-adaptive synchronization method and system for intelligent contract
CN109324867A (en) A kind of virtual machine temporary storage method, restoration methods and device
CN109389271B (en) Application performance management method and system
WO2021257195A1 (en) Topic graph-based comment generation
CN111241380B (en) Method and apparatus for generating recommendations
CN114356512A (en) Data processing method, data processing equipment and computer readable storage medium
CN111479140A (en) Data acquisition method, data acquisition device, computer device and storage medium
CN111770080A (en) Method and device for recovering device fingerprint
CN112950378B (en) Method and device for executing intelligent contract in block chain
CN116701410B (en) Method and system for storing memory state data for data language of digital networking
CN115576503B (en) Data storage method, device, storage medium and storage equipment
CN117093146A (en) Data processing method and device
CN115858686A (en) Tree data synchronization method and synchronization flow model, electronic device and medium thereof

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