CN112882744B - Intelligent contract upgrading and compatible method and system applied to block chain system - Google Patents

Intelligent contract upgrading and compatible method and system applied to block chain system Download PDF

Info

Publication number
CN112882744B
CN112882744B CN202110324100.XA CN202110324100A CN112882744B CN 112882744 B CN112882744 B CN 112882744B CN 202110324100 A CN202110324100 A CN 202110324100A CN 112882744 B CN112882744 B CN 112882744B
Authority
CN
China
Prior art keywords
contract
transaction
module
intelligent
intelligent contract
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
CN202110324100.XA
Other languages
Chinese (zh)
Other versions
CN112882744A (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.)
Industrial and Commercial Bank of China Ltd ICBC
Original Assignee
Industrial and Commercial Bank of China Ltd ICBC
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 Industrial and Commercial Bank of China Ltd ICBC filed Critical Industrial and Commercial Bank of China Ltd ICBC
Priority to CN202110324100.XA priority Critical patent/CN112882744B/en
Publication of CN112882744A publication Critical patent/CN112882744A/en
Application granted granted Critical
Publication of CN112882744B publication Critical patent/CN112882744B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/65Updates
    • G06F8/656Updates while running
    • 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

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Business, Economics & Management (AREA)
  • Accounting & Taxation (AREA)
  • Finance (AREA)
  • General Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • Development Economics (AREA)
  • Computer Security & Cryptography (AREA)
  • Economics (AREA)
  • Marketing (AREA)
  • Strategic Management (AREA)
  • Technology Law (AREA)
  • General Business, Economics & Management (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

The invention provides an intelligent contract upgrading and compatible method and system applied to a blockchain system, which relate to the blockchain field and can be applied to the financial field and other fields, wherein the method comprises the following steps: calculating and generating a hash value according to an intelligent contract code in an installation transaction request of an intelligent contract to be installed; compiling intelligent contract codes in the installation transaction request to construct corresponding intelligent contract images; generating a contract record according to the intelligent contract mirror image and the hash value registration; and monitoring the contract state on the blockchain, and when the contract state is updated, calling a corresponding intelligent contract mirror image according to the contract record to start a contract container, and carrying out transaction processing on the associated intelligent contract through the contract container.

Description

Intelligent contract upgrading and compatible method and system applied to block chain system
Technical Field
The invention relates to the field of blockchain, which can be applied to the financial field and other fields, in particular to an intelligent contract upgrading and compatible method and system applied to a blockchain system.
Background
The intelligent contract is an important module for outputting the block chain service, business application writes business logic through the intelligent contract, and the business logic is used for linking the data after contract processing, so that the activity of the intelligent contract is higher, the intelligent contract is frequently required to be upgraded, in a block chain system for deploying the contract in a container mode, the intelligent contract is usually required to restart an intelligent contract container, and an upgrade scheme is either complex in design and low in efficiency or is unfriendly to the application, and the normal operation of the system is influenced. In addition, smart contracts involve the processing of uplink data, each transaction produces contract-related data, and after a contract upgrade, there is a problem that old contract data is not compatible due to a change in a data structure, and a solution is generally adopted, namely, transaction replay or data migration, but both are very inefficient and time-consuming and require additional processing.
Disclosure of Invention
Aiming at the problems of upgrading and heterogeneous data compatibility of the existing containerized deployment intelligent contracts, the invention provides an intelligent contract upgrading and compatible method and system applied to a blockchain system, which can rapidly, efficiently and fully automatically complete intelligent contract upgrading without affecting normal operation of the system, and simultaneously, the upgraded intelligent contracts can automatically complete old contract data compatibility to realize seamless access.
In order to achieve the above objective, the intelligent contract upgrading and compatibility method of the blockchain system provided by the present invention specifically includes: calculating and generating a hash value according to an intelligent contract code in an installation transaction request of an intelligent contract to be installed; compiling intelligent contract codes in the installation transaction request to construct corresponding intelligent contract images; generating a contract record according to the intelligent contract mirror image and the hash value registration; and monitoring the contract state on the blockchain, and when the contract state is updated, calling a corresponding intelligent contract mirror image according to the contract record to start a contract container, and carrying out transaction processing on the associated intelligent contract through the contract container.
In the smart contract upgrading and compatibility method of the blockchain system, preferably, the method further includes: and generating a voting result after auditing the received contract deployment voting according to a preset rule, and feeding back the voting result to a contract deployment voting initiator.
In the above method for upgrading and compatible intelligent contracts in a blockchain system, preferably, the method for retrieving a corresponding intelligent contract image start contract container includes: and calling the intelligent contract mirror image in the corresponding contract record according to the updated hash value in the contract state.
In the above method for upgrading and compatibility of a smart contract in a blockchain system, preferably, generating a contract record according to the smart contract image and the hash value registration further includes: and updating the contract container running record according to the contract record when a contract container is already run under the same-name contract of the contract record.
In the above method for upgrading and compatibility of intelligent contracts in a blockchain system, preferably, monitoring a contract status on a blockchain, and when there is an update in the contract status, invoking a corresponding intelligent contract image start contract container includes: monitoring contract states on the blockchain, stopping transmitting cache transactions to intelligent contracts deployed at the current node and acquiring current contract container states when the contract states are updated.
In the above method for upgrading and compatible intelligent contracts in a blockchain system, preferably, the method for retrieving a corresponding intelligent contract image start contract container includes: searching and obtaining corresponding contract records and contract container states according to the updated contract states; comparing the updated contract hash of the contract state with the hash of the contract container, and detecting whether the intelligent contract deployed at the current node has unfinished transaction or not when the comparison results are inconsistent; and stopping operating the contract container and starting the contract container according to the intelligent contract image corresponding to the updated contract record when no transaction is not completed.
The invention also provides a blockchain system suitable for the method, which comprises a client, a sorting node, a plurality of endorsement nodes, a plurality of intelligent contracts and a plurality of verification nodes; the endorsement node is arranged at a preset mechanism, and the intelligent contract is deployed on the endorsement node; the client is used for acquiring an intelligent contract code to be uploaded and generating an installation transaction request according to the intelligent contract code; initiating contract deployment voting to a preset number of endorsement nodes in the blockchain system according to the received hash value, and sending a received voting result to the sequencing node; and initiating contract deployment confirmation requests to a predetermined number of endorsement nodes in the blockchain system, and feeding back received endorsement results to the ordering nodes; the endorsement node is used for calculating and generating a hash value according to an intelligent contract code in an installation transaction request of the intelligent contract to be installed; compiling intelligent contract codes in the installation transaction request to construct corresponding intelligent contract images; generating a contract record according to the intelligent contract mirror image and the hash value registration; after voting auditing is deployed on the contracts initiated by the client according to a preset rule, a voting result is generated and fed back to the client; and monitoring the contract state on the blockchain, when the contract state is updated, calling a corresponding intelligent contract mirror image according to the contract record to start a contract container, and carrying out transaction processing on the associated intelligent contract through the contract container; the sequencing node is used for sequencing and consensus generating blocks according to the voting results; and sequencing and consensus generating blocks according to the endorsement result; the verification node is used for pulling the block and performing uplink persistence processing on the block.
In the above blockchain system, preferably, the client includes a transaction initiating device, and the transaction initiating device is configured to assemble a transaction request or a message parameter, and send the assembled transaction request or parameter to a designated transaction recipient.
In the above blockchain system, preferably, the transaction initiating device includes a transaction certificate module, a transaction configuration module, and a contract code packaging module; the transaction certificate module is used for storing and providing the identity certificate of the current node; the transaction configuration module is used for configuring parameters related to transaction; the contract code packaging module is used for generating an installation transaction request according to the intelligent contract code.
In the blockchain system, preferably, the endorsement node includes a transaction endorsement module, a contract mirror module, a contract daemon module and a transaction caching module; the transaction endorsement module is used for endorsing and signing transaction execution results returned by the associated intelligent contracts; the contract mirror module is used for constructing an intelligent contract initial container mirror; the contract daemon module is used for circularly detecting the running state of a contract container and controlling the contract container to be started, stopped or upgraded; the transaction caching module is used for caching the transaction and transmitting the cached transaction to the intelligent contract for executing processing.
In the above blockchain system, preferably, the transaction caching module includes a transaction message list and a conditional lock module; the transaction message list is used for receiving transaction data received by the endorsement node, transmitting the transaction data to an intelligent contract for executing and processing and registering a transaction state; the conditional lock module is used for monitoring the contract state on the blockchain, and when the contract state is updated, the transaction message list is controlled to stop transmitting the transaction data to the intelligent contract; and restoring the transaction message list to transmit the transaction data to the smart contract after the transaction execution in the smart contract is completed.
In the above blockchain system, preferably, the verification node includes a transaction verification module and a contract status detection module; the transaction verification module is used for verifying the legitimacy and endorsement signature of the transaction on the ordering node; the contract state detection module is used for detecting the contract state on the blockchain system through the transaction state, and when the contract state is updated, the contract daemon module is triggered to control the contract container to be opened, stopped or upgraded.
In the above blockchain system, preferably, the smart contract includes a data structure conversion module and a transaction execution module; the data structure conversion module is used for calling transaction data provided by the endorsement node through an intermediate dynamic data structure of a reflection technology and providing the transaction data to the transaction execution device; the transaction execution device is used for executing and processing transaction data provided by the endorsement node.
The invention also provides an electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the above method when executing the computer program.
The present invention also provides a computer readable storage medium storing a computer program for executing the above method.
The beneficial technical effects of the invention are as follows: the intelligent contract life cycle design mode is efficient and quick, and achieves automatic upgrading of intelligent contracts in a containerized deployment mode through contract daemon, contract state update detection and contract container state machines, and normal transaction execution is not affected. The intermediate dynamic data structure based on the reflection technology is utilized to realize the compatible use of heterogeneous data, so that new contract data and old contract data can be compatible for access, read and write without additional migration.
Drawings
The accompanying drawings, which are included to provide a further understanding of the invention and are incorporated in and constitute a part of this application, illustrate and together with the description serve to explain the invention. In the drawings:
FIG. 1A is a flow chart of a method for intelligent contract upgrade and compatibility of a blockchain system according to an embodiment of the present invention;
FIG. 1B is a block chain system according to one embodiment of the present invention;
FIG. 2 is a schematic diagram of a client according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of a transaction initiating device according to an embodiment of the present invention;
FIG. 4 is a schematic diagram of an endorsement node according to an embodiment of the present invention;
FIG. 5 is a schematic diagram of a transaction buffer module according to an embodiment of the present invention;
FIG. 6 is a schematic diagram of a smart contract according to an embodiment of the present invention;
FIG. 7 is a schematic diagram of a verification node according to an embodiment of the present invention;
FIG. 8 is a flow chart of smart contract deployment according to an embodiment of the present invention;
FIG. 9 is a flow chart of smart contract upgrades provided by an embodiment of the present invention;
FIG. 10 is a schematic diagram of a reflective-conversion intermediate dynamic data structure according to an embodiment of the present invention;
fig. 11 is a schematic structural diagram of an electronic device according to an embodiment of the invention.
Detailed Description
The following will describe embodiments of the present invention in detail with reference to the drawings and examples, thereby solving the technical problems by applying technical means to the present invention, and realizing the technical effects can be fully understood and implemented accordingly. It should be noted that, as long as no conflict is formed, each embodiment of the present invention and each feature of each embodiment may be combined with each other, and the formed technical solutions are all within the protection scope of the present invention.
Additionally, the steps illustrated in the flowcharts of the figures may be performed in a computer system such as a set of computer executable instructions, and although a logical order is illustrated in the flowcharts, in some cases the steps illustrated or described may be performed in an order other than that herein.
Referring to fig. 1A, the method for upgrading and compatible intelligent contracts of a blockchain system provided by the present invention specifically includes:
s101, calculating and generating a hash value according to an intelligent contract code in an installation transaction request of an intelligent contract to be installed;
s102, compiling intelligent contract codes in the installation transaction request to construct corresponding intelligent contract images;
s103, generating a contract record according to the intelligent contract mirror image and the hash value registration;
s104, monitoring the contract state on the blockchain, and when the contract state is updated, calling the corresponding intelligent contract mirror image according to the contract record to start a contract container, and carrying out transaction processing on the associated intelligent contract through the contract container.
Therefore, the contract deployment is completed rapidly and conveniently through the contract state detection and update mode.
In an embodiment of the present invention, the method may further comprise: and generating a voting result after auditing the received contract deployment voting according to a preset rule, and feeding back the voting result to a contract deployment voting initiator. Specifically, in actual work, a plurality of institutions may be set, the institutions are enterprises or organizations in actual business activities, each institution joins the blockchain system by maintaining one or more nodes, the institutions are important roles in the blockchain system, and blockchain transactions related to the institutions all need to be validated through endorsement signatures of the institutions, in this embodiment, voting results of the structures are used to determine whether the intelligent contracts continue to be deployed.
In an embodiment of the present invention, when the smart contract needs to be upgraded, generating the contract record according to the smart contract image and the hash value registration in step S103 may further include: and updating the contract container running record according to the contract record when a contract container is already run under the same-name contract of the contract record. Thus, monitoring the contract status on the blockchain in step S104 described below, and when there is an update to the contract status, invoking the corresponding smart contract image launch contract container includes: monitoring contract states on the blockchain, stopping transmitting cache transactions to intelligent contracts deployed at the current node and acquiring current contract container states when the contract states are updated. Further, the invoking the corresponding smart contract image launch contract container may include: and calling the intelligent contract mirror image in the corresponding contract record according to the updated hash value in the contract state.
In the above embodiment, invoking the corresponding smart contract image launch contract container may include: searching and obtaining corresponding contract records and contract container states according to the updated contract states; comparing the updated contract hash of the contract state with the hash of the contract container, and detecting whether the intelligent contract deployed at the current node has unfinished transaction or not when the comparison results are inconsistent; and stopping operating the contract container and starting the contract container according to the intelligent contract image corresponding to the updated contract record when no transaction is not completed.
Referring to fig. 1B, the present invention further provides a blockchain system suitable for the above method, where the blockchain system includes a client 1, a sorting node 4, a plurality of endorsement nodes 2, a plurality of intelligent contracts 3, and a plurality of verification nodes 5; the endorsement node 2 is arranged at a preset mechanism, and the intelligent contract 3 is deployed on the endorsement node 2; the client 1 is used for acquiring an intelligent contract code to be uploaded and generating an installation transaction request according to the intelligent contract code; initiating contract deployment voting to a preset number of endorsement nodes 2 in the blockchain system according to the received hash value, and sending the received voting result to the sequencing node 4; and initiating contract deployment confirmation requests to a predetermined number of endorsement nodes 2 in the blockchain system, and feeding back received endorsement results to the ordering node 4; the endorsement node 2 is used for calculating and generating a hash value according to an intelligent contract code in an installation transaction request of an intelligent contract to be installed; compiling intelligent contract codes in the installation transaction request to construct corresponding intelligent contract images; generating a contract record according to the intelligent contract mirror image and the hash value registration; after voting auditing is deployed on the contracts initiated by the client 1 according to preset rules, a voting result is generated and fed back to the client 1; and monitoring the contract state on the blockchain, when the contract state is updated, calling a corresponding intelligent contract mirror image according to the contract record to start a contract container, and carrying out transaction processing on the associated intelligent contract 3 through the contract container; the sorting node 4 is used for sorting and consensus generating blocks according to the voting results; and sequencing and consensus generating blocks according to the endorsement result; the verification node 5 is configured to pull the block, and perform uplink persistence processing on the block.
In actual work, the client 1 is used as an important medium for connecting and interacting with a blockchain system outside, and is mainly responsible for sending any type of transaction and related requests, and the interactive requests of the blockchain are initiated by using the client 1, wherein the initiation objects are an endorsement node 2 and a sequencing node 4; in fig. 1B, the endorsement node 2 is actually an organization, in the scheme of the present invention, there are multiple organizations in the blockchain system, the organization is an enterprise or organization in actual business activity, each organization adds one or more endorsement nodes 2 into the blockchain system, the organization is an important role in the blockchain system, related blockchain transactions of the organization all need to be validated through endorsement signature of the organization, the endorsement node 2 is responsible for doing the matter, the transaction can be sent to multiple endorsement nodes 2, and can be set according to actual business endorsement requirements, besides, the deployment of intelligent contracts 3 on the blockchain also needs organization agreement; the intelligent contract 3 is a core module for executing the transaction, the core module is deployed on the endorsement node 2, the transaction is sent to the intelligent contract 3 by the endorsement node 2, and after the execution is completed, the result is returned to the endorsement node 2 for endorsement and signature; the endorsement result is returned to the client 1, and then the endorsement result is packaged by the client 1 and sent to the ordering node 4, the ordering node 4 is mainly responsible for ordering consensus of transactions, and finally the packaged block is distributed to the verification node 5, and the organization can also require the ordering node 4 to be deployed but not necessarily; the verification node 5 mainly performs block verification, including transaction status, endorsement signature accuracy, and the like, and the verified blocks can be finally written into a block chain account book to complete persistence.
Next, specific functional components of each module related to the technical solution of the present invention are described in detail, and it is noted that, in the blockchain system of the present invention, the release, installation and deployment of the intelligent contract are considered as one type of blockchain transaction, and all needs to be initiated by the client 1, and then the transaction flow described above is completed.
In one embodiment of the present invention, the client includes a transaction initiation device for assembling a transaction request or message parameter and transmitting the assembled transaction request or parameter to a designated transaction recipient. The transaction initiating device comprises a transaction certificate module, a transaction configuration module and a contract code packaging module; the transaction certificate module is used for storing and providing the identity certificate of the current node; the transaction configuration module is used for configuring parameters related to transaction; the contract code packaging module is used for generating an installation transaction request according to the intelligent contract code. In actual operation, as shown in fig. 2, the client 1 mainly includes a transaction initiating device 11, and the transaction request types include a normal transaction, an intelligent contract deployment, a sorting transaction (a request sent to the sorting node 4), and the like. The client 1 assembles parameters of the transaction request or message by the transaction initiating means 11 and then designates the transaction recipient (endorsement node 2 or ordering node 4). As shown in fig. 3, the transaction initiating device 11 mainly includes a transaction certificate module 111, a transaction configuration module 112, a contract code packaging module 113 and a communication module 114, wherein the transaction certificate module 111 is an important credential of a node identity, and generally, all operations of interacting with a blockchain system need to use certificates; the transaction configuration module 112 primarily relates to the configuration of a number of transaction related parameters, such as transaction type, which endorsement node to send to, etc.; the contract code packaging module 113 is mainly responsible for packaging intelligent contract codes, and the packaged contract code packages are required to be used in the intelligent contract deployment process; the communication module 114 is responsible for sending the final transaction request to the designated location.
In an embodiment of the present invention, the endorsement node includes a transaction endorsement module, a contract mirror module, a contract daemon module, and a transaction caching module; the transaction endorsement module is used for endorsing and signing transaction execution results returned by the associated intelligent contracts; the contract mirror module is used for constructing an intelligent contract initial container mirror; the contract daemon module is used for circularly detecting the running state of a contract container and controlling the contract container to be started, stopped or upgraded; the transaction caching module is used for caching the transaction and transmitting the cached transaction to the intelligent contract for executing processing. Referring specifically to fig. 4, in actual operation, the endorsement node 2 mainly includes five modules: the system comprises a transaction endorsement module 21, a contract mirror module 22, a contract daemon module 23, a communication module 24 and a transaction caching module 25, wherein the transaction endorsement module 21 mainly endorses and signs a transaction execution result returned by the intelligent contract 3; the contract mirror module 22 is used for constructing an intelligent contract initial container mirror; the contract daemon module 23 is an important module of the scheme of the invention, the contract daemon module 23 is a continuous cyclic detection running process and is a daemon of a contract life cycle, wherein a container state machine device is responsible for starting, stopping and upgrading a contract container; the communication module 24 is mainly responsible for communication interaction with the client 1 and the intelligent contract 3; the transaction caching module 25 mainly caches transactions, and can perform high concurrency transaction caching, and in addition, an important module, namely a conditional lock, is provided, and when the conditional lock triggers, the cached transactions stop being transmitted to the intelligent contract 3.
In the above embodiment, the transaction caching module includes a transaction message list and a conditional lock module; the transaction message list is used for receiving transaction data received by the endorsement node, transmitting the transaction data to an intelligent contract for executing and processing and registering a transaction state; the conditional lock module is used for monitoring the contract state on the blockchain, and when the contract state is updated, the transaction message list is controlled to stop transmitting the transaction data to the intelligent contract; and restoring the transaction message list to transmit the transaction data to the smart contract after the transaction execution in the smart contract is completed. In actual operation, as shown in fig. 5, the transaction caching module 25 mainly includes a transaction message list 251 and a conditional lock module 252, and the transaction received by the endorsement node 2 will first enter the transaction message list 251 and register the transaction status (wait, execute and complete). Normally, according to the actual processing situation of the system, the transaction will be automatically sent to the intelligent contract 3 through the communication module 24, when the contract status update is detected, the condition lock module 252 is triggered, at this time, the transaction message list 251 stops transmitting the transaction to the intelligent contract 3, and the condition lock is released after the transaction execution which has entered the intelligent contract 3 is waited to complete, and the cached transaction execution is resumed.
In one embodiment of the present invention, the smart contract includes a data structure conversion module and a transaction execution module; the data structure conversion module is used for calling transaction data provided by the endorsement node through an intermediate dynamic data structure of a reflection technology and providing the transaction data to the transaction execution device; the transaction execution device is used for executing and processing transaction data provided by the endorsement node. In actual operation, as shown in fig. 6, the smart contract 3 mainly includes a data structure conversion module 31, a transaction execution module 32, and a communication module 33; wherein, the data structure conversion module 31 uses a dynamic data structure technology to realize heterogeneous data compatibility; the transaction execution module 32 is primarily responsible for executing transactions; the communication module 33 mainly interacts with the communication traffic of the endorsement node 3.
In one embodiment of the present invention, the verification node includes a transaction verification module and a contract status detection module; the transaction verification module is used for verifying the legitimacy and endorsement signature of the transaction on the ordering node; the contract state detection module is used for detecting the contract state on the blockchain system through the transaction state, and when the contract state is updated, the contract daemon module is triggered to control the contract container to be opened, stopped or upgraded. In actual operation, the verification node 5 includes a transaction verification module 51 and a contract status detection module 52, where the transaction verification module 51 is mainly responsible for performing validity verification, endorsement signature verification, and the like on a transaction, and the contract status detection module 52 mainly detects status updates related to a contract lifecycle, and the foregoing description refers to that the contract deployment upgrades are all sent to the blockchain system in a transaction form, so that the contract status updates can be found through the transaction status detection at the verification node, thereby triggering a contract management mechanism of the contract daemon module 23.
In order to more clearly understand the specific application manner of the blockchain system provided by the present invention, the following further describes the above-mentioned mechanism modules by taking the intelligent contract deployment procedure and the intelligent contract upgrade procedure as examples in actual work, and those skilled in the art will know that this example is only a Juin application manner for facilitating understanding the blockchain system provided by the present invention, and does not limit the application manner in any way.
Referring to fig. 8, the smart contract deployment flow is as follows:
s801, the client 1 packages intelligent contract codes;
s802, the client 1 assembles an intelligent contract installation transaction request by using the contract package obtained by the packing in S801, and sends the request to the endorsement node 2, and the endorsement node 2 calculates a unique hash value according to the contract name and the contract package content and returns the unique hash value to the client 1;
s803 the endorsement node 2 compiles the contract package and constructs the intelligent contract image using the contract image module 22, the contract daemon module 23 registers a contract record using the contract unique hash value and the contract image information, and starts to cyclically monitor the contract container state (whether start or stop is required);
s804, the client 1 initiates the contract deployment vote to the endorsement node 2 using the contract unique hash value acquired in S802, and note that the Sequence needs to be designated as 1, and the Sequence is incremented once by subsequent contract upgrades. The intelligent contract can be deployed by generally requiring more than a general institution to agree, so more than half of endorsement nodes 2 need to be sent to voting requests, and the endorsement nodes 2 return voting results to the client 1;
S805, the client 1 sends the collected voting endorsement result to the ordering node 4, and generates a block after ordering consensus is completed;
s806, the verification node 5 pulls the blocks to the ordering node 4 and verifies the blocks, and finally persistence is achieved;
s807, the client 1 sends a contract deployment confirmation request to the endorsement node 2, and the endorsement node 2 returns an endorsement result for confirming contract deployment transaction;
s808, the client 1 sends the collected intelligent contract confirmation deployment endorsement result to the ordering node 4, and generates a block after ordering consensus is completed;
s809, the verification node 5 pulls blocks to the ordering node 4 and verifies the blocks;
s810 the contract state monitoring module monitors that the contract state is updated (actually, it detects that the Sequence is changed, for the generalization of the system design, the Sequence is initially set to 0, the parameter is 1 when the contract is deployed for the first time, the Sequence is changed, and thus the contract state monitoring mechanism of the contract daemon module 23 is triggered), the contract daemon module 23 is notified that the contract deployment has been allowed, the contract daemon module 23 checks the contract state, discovers that the contract container is not started, then obtains the contract image information, starts the contract container (the process is all searched by using the contract unique hash value), and registers the contract container operation record in the contract daemon module 23.
To this end, the contract may begin normal transaction execution.
Referring to fig. 9, the smart contract upgrade flow is as follows:
s901, the client 1 packages the updated intelligent contract code;
s902, the client 1 assembles an intelligent contract installation transaction request by using the new contract package obtained by packing in S901, and sends the request to the endorsement node 2, and the endorsement node 2 calculates a new unique hash value according to the contract name and the contract package content and returns the new unique hash value to the client 1;
s903 endorsement node 2 compiles the contract package and builds the new image of the intelligent contract using contract image module 22, contract daemon 23 registers a contract record and updates a contract container running record (i.e. a contract container has been run under the current same name contract, but there are two code package hash values under the contract name) using the unique hash value of the contract and the contract image information, and starts to monitor the contract container status (whether start or stop is needed) in a circulating way;
s904, the client 1 initiates the contract deployment vote to the endorsement node 2 using the new contract unique hash value acquired in S902, and note that here, it is required to specify sequence=sequence+1, i.e. an upgrade operation. The intelligent contract can be deployed by generally requiring more than a general institution to agree, so more than half of endorsement nodes 2 need to be sent to voting requests, and the endorsement nodes 2 return voting results to the client 1;
S905, the client 1 sends the collected voting endorsement result to the ordering node 4, and generates a block after ordering consensus is completed;
s906, the verification node 5 pulls the blocks to the ordering node 4 and verifies the blocks, and finally persistence is achieved;
s907, the client 1 sends a contract deployment confirmation request to the endorsement node 2, and the endorsement node 2 returns an endorsement result for confirming contract deployment transaction;
s908, the client 1 sends the collected intelligent contract confirmation deployment endorsement result to the ordering node 4, and generates a block after ordering consensus is completed;
s909, the verification node 5 pulls the blocks to the ordering node 4 and verifies the blocks;
s910, the contract state monitoring module monitors that the contract state is updated (Sequence is changed by +1), triggers the conditional lock module 252 in the transaction caching module 25, and starts the transaction to stop being transmitted to the intelligent contract 3;
the S911 contract daemon module 23 monitors the contract state update and finds the state record and container operation record corresponding to the contract name;
s912, the contract daemon module 23 judges whether the Sequence is increased by 1, compares the contract hash of the state update with the hash of the current contract running container, and sets the contract container state to a stoppable state if the contract hash is inconsistent with the hash of the current contract running container;
the container state machine in the contract daemon module 23 detects that the container is in a stoppable state and detects whether there is an unfinished transaction in the transaction message list 251;
S914 no outstanding transactions, the container state machine in the contract daemon module 23 stops running the current contract running container and releases the conditional lock in the conditional lock module 252 and sets the contract container state to a bootable state;
if the container state machine in the contract daemon module 23 detects that the contract container is a bootable state, the contract container is started by using the image corresponding to the new contract hash constructed in S903.
So far, the transaction in the transaction caching module 25 can be normally transmitted to the intelligent contract 3 for executing operation, and the contract container is updated and upgraded contract container. When the automatic upgrade of the contract is completed, the normal operation of the system transaction is not influenced, and in the whole upgrade process, the contract state is rapidly switched, so that the upgrade is efficient and rapid.
After the contract is upgraded, the new contract data and the old contract data can be used in a compatible mode without migration, and therefore the invention further provides a dynamic data structure based on the reflection technology, and details of the technical scheme are described in detail below.
Reflection, which is the dynamic acquisition of information about an object, dynamically performs the method of the object, because it is sometimes not known during operation what type, which properties and methods the object is specifically of. Such as heterogeneous data of new and old contracts, data of new contracts without knowledge of the type and properties of the old contract data objects, etc. The technical scheme for heterogeneous data compatibility comprises the following specific steps:
1. For the data structure in the contract, mapping the data structure into an intermediate data structure by reflection technology, wherein each field in the contract data structure is converted into one piece of record data in the intermediate data structure;
2. for each field record, key attributes (field names, types, lengths and the like) in the intermediate data structure are spliced to calculate hash;
3. each hash obtained in the step 2 is used as a key value of the world state of the blockchain, the true original value of the field is used as the corresponding value of the key, and the value is stored in the blockchain account book (contract data are all stored in the mode);
4. when accessing heterogeneous data, the new data structure is converted into an intermediate data structure by adopting a reflection method, and the hash value of a field to be accessed is calculated according to the step 2 to obtain the account key value of the field;
5. and (3) accessing the blockchain ledger by using the key value obtained in the step (4) to obtain the value of the field stored in the blockchain, and storing new field data in the same manner as in the step (2) and the step (3).
6. By means of the reflection conversion intermediate dynamic data structure and the form storage mode of the account book (k, v), seamless connection and smooth compatibility of heterogeneous data can be achieved, as shown in fig. 10.
Therefore, the blockchain system provided by the invention can access and update new and old contract data under normal operation of the system, and can automatically support heterogeneous data compatibility while upgrading the contract, so that the cost of data migration can be greatly reduced.
The beneficial technical effects of the invention are as follows: the intelligent contract life cycle design mode is efficient and quick, and achieves automatic upgrading of intelligent contracts in a containerized deployment mode through contract daemon, contract state update detection and contract container state machines, and normal transaction execution is not affected. The intermediate dynamic data structure based on the reflection technology is utilized to realize the compatible use of heterogeneous data, so that new contract data and old contract data can be compatible for access, read and write without additional migration.
The invention also provides an electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the above method when executing the computer program.
The present invention also provides a computer readable storage medium storing a computer program for executing the above method.
As shown in fig. 11, the electronic device 600 may further include: a communication module 110, an input unit 120, an audio processing unit 130, a display 160, a power supply 170. It is noted that the electronic device 600 need not include all of the components shown in FIG. 11; in addition, the electronic device 600 may further include components not shown in fig. 11, to which reference is made to the related art.
As shown in fig. 11, the central processor 100, also sometimes referred to as a controller or operational control, may include a microprocessor or other processor device and/or logic device that the central processor 100 receives inputs and controls the operation of the various components of the electronic device 600.
The memory 140 may be, for example, one or more of a buffer, a flash memory, a hard drive, a removable media, a volatile memory, a non-volatile memory, or other suitable device. The information about failure may be stored, and a program for executing the information may be stored. And the central processor 100 can execute the program stored in the memory 140 to realize information storage or processing, etc.
The input unit 120 provides an input to the central processor 100. The input unit 120 is, for example, a key or a touch input device. The power supply 170 is used to provide power to the electronic device 600. The display 160 is used for displaying display objects such as images and characters. The display may be, for example, but not limited to, an LCD display.
The memory 140 may be a solid state memory such as Read Only Memory (ROM), random Access Memory (RAM), SIM card, or the like. But also a memory which holds information even when powered down, can be selectively erased and provided with further data, an example of which is sometimes referred to as EPROM or the like. Memory 140 may also be some other type of device. Memory 140 includes a buffer memory 141 (sometimes referred to as a buffer). The memory 140 may include an application/function storage 142, the application/function storage 142 for storing application programs and function programs or a flow for executing operations of the electronic device 600 by the central processor 100.
The memory 140 may also include a data store 143, the data store 143 for storing data, such as contacts, digital data, pictures, sounds, and/or any other data used by the electronic device. The driver storage 144 of the memory 140 may include various drivers of the electronic device for communication functions and/or for performing other functions of the electronic device (e.g., messaging applications, address book applications, etc.).
The communication module 110 is a transmitter/receiver 110 that transmits and receives signals via an antenna 111. A communication module (transmitter/receiver) 110 is coupled to the central processor 100 to provide an input signal and receive an output signal, which may be the same as in the case of a conventional mobile communication terminal.
Based on different communication technologies, a plurality of communication modules 110, such as a cellular network module, a bluetooth module, and/or a wireless local area network module, etc., may be provided in the same electronic device. The communication module (transmitter/receiver) 110 is also coupled to a speaker 131 and a microphone 132 via an audio processor 130 to provide audio output via the speaker 131 and to receive audio input from the microphone 132 to implement usual telecommunication functions. The audio processor 130 may include any suitable buffers, decoders, amplifiers and so forth. In addition, the audio processor 130 is also coupled to the central processor 100 so that sound can be recorded locally through the microphone 132 and so that sound stored locally can be played through the speaker 131.
It will be appreciated by those skilled in the art that embodiments of the present invention may be provided as a method, system, 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 flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations 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.
The foregoing description of the embodiments has been provided for the purpose of illustrating the general principles of the invention, and is not meant to limit the scope of the invention, but to limit the invention to the particular embodiments, and any modifications, equivalents, improvements, etc. that fall within the spirit and principles of the invention are intended to be included within the scope of the invention.

Claims (14)

1. A method of intelligent contract upgrades and compatibility for a blockchain system, the method comprising:
calculating and generating a hash value according to an intelligent contract code in an installation transaction request of an intelligent contract to be installed;
compiling intelligent contract codes in the installation transaction request to construct corresponding intelligent contract images;
generating a contract record according to the intelligent contract mirror image and the hash value registration;
monitoring a contract state on a blockchain, and when the contract state is updated, calling a corresponding intelligent contract mirror image according to the contract record to start a contract container, and carrying out transaction processing on the associated intelligent contract through the contract container;
invoking the corresponding smart contract image launch contract container comprises:
searching and obtaining corresponding contract records and contract container states according to the updated contract states;
comparing the updated contract hash of the contract state with the hash of the contract container, and detecting whether the intelligent contract deployed at the current node has unfinished transaction or not when the comparison results are inconsistent;
and stopping operating the contract container and starting the contract container according to the intelligent contract image corresponding to the updated contract record when no transaction is not completed.
2. The intelligent contract upgrade and compatibility method for a blockchain system of claim 1, further comprising:
and generating a voting result after auditing the received contract deployment voting according to a preset rule, and feeding back the voting result to a contract deployment voting initiator.
3. The intelligent contract upgrade and compatibility method for a blockchain system of claim 1, wherein invoking the corresponding intelligent contract image launch contract container comprises: and calling the intelligent contract mirror image in the corresponding contract record according to the updated hash value in the contract state.
4. The intelligent contract upgrade and compatibility method of a blockchain system of claim 1, wherein generating a contract record from the intelligent contract image and the hash value registration further comprises:
and updating the contract container running record according to the contract record when a contract container is already run under the same-name contract of the contract record.
5. The intelligent contract upgrade and compatibility method for a blockchain system of claim 4, wherein monitoring contract states on blockchains, when there is an update to the contract states, invoking a corresponding intelligent contract image launch contract container comprises:
Monitoring contract states on the blockchain, stopping transmitting cache transactions to intelligent contracts deployed at the current node and acquiring current contract container states when the contract states are updated.
6. A blockchain system suitable for the intelligent contract upgrade and compatibility method of the blockchain system of any of claims 1-5, wherein the blockchain system includes a client, a sorting node, a plurality of endorsement nodes, a plurality of intelligent contracts, and a plurality of validation nodes;
the endorsement node is arranged at a preset mechanism, and the intelligent contract is deployed on the endorsement node;
the client is used for acquiring an intelligent contract code to be uploaded and generating an installation transaction request according to the intelligent contract code; initiating contract deployment voting to a preset number of endorsement nodes in the blockchain system according to the received hash value, and sending a received voting result to the sequencing node; and initiating contract deployment confirmation requests to a predetermined number of endorsement nodes in the blockchain system, and feeding back received endorsement results to the ordering nodes;
the endorsement node is used for calculating and generating a hash value according to an intelligent contract code in an installation transaction request of the intelligent contract to be installed; compiling intelligent contract codes in the installation transaction request to construct corresponding intelligent contract images; generating a contract record according to the intelligent contract mirror image and the hash value registration; after voting auditing is deployed on the contracts initiated by the client according to a preset rule, a voting result is generated and fed back to the client; and monitoring the contract state on the blockchain, when the contract state is updated, calling a corresponding intelligent contract mirror image according to the contract record to start a contract container, and carrying out transaction processing on the associated intelligent contract through the contract container;
The sequencing node is used for sequencing and consensus generating blocks according to the voting results; and sequencing and consensus generating blocks according to the endorsement result;
the verification node is used for pulling the block and performing uplink persistence processing on the block.
7. The blockchain system of claim 6, wherein the client includes a transaction initiating device for assembling the transaction request or message parameters and transmitting the assembled transaction request or parameters to a designated transaction recipient.
8. The blockchain system of claim 7, wherein the transaction initiating device includes a transaction certificate module, a transaction configuration module, and a contract code packaging module;
the transaction certificate module is used for storing and providing the identity certificate of the current node;
the transaction configuration module is used for configuring parameters related to transaction;
the contract code packaging module is used for generating an installation transaction request according to the intelligent contract code.
9. The blockchain system of claim 6, wherein the endorsement node includes a transaction endorsement module, a contract mirror module, a contract daemon module, and a transaction caching module;
The transaction endorsement module is used for endorsing and signing transaction execution results returned by the associated intelligent contracts;
the contract mirror module is used for constructing an intelligent contract initial container mirror;
the contract daemon module is used for circularly detecting the running state of a contract container and controlling the contract container to be started, stopped or upgraded;
the transaction caching module is used for caching the transaction and transmitting the cached transaction to the intelligent contract for executing processing.
10. The blockchain system of claim 9, wherein the transaction caching module includes a transaction message list and a conditional lock module;
the transaction message list is used for receiving transaction data received by the endorsement node, transmitting the transaction data to an intelligent contract for executing and processing and registering a transaction state;
the conditional lock module is used for monitoring the contract state on the blockchain, and when the contract state is updated, the transaction message list is controlled to stop transmitting the transaction data to the intelligent contract; and restoring the transaction message list to transmit the transaction data to the smart contract after the transaction execution in the smart contract is completed.
11. The blockchain system of claim 9, wherein the validation node includes a transaction validation module and a contract status detection module;
the transaction verification module is used for verifying the legitimacy and endorsement signature of the transaction on the ordering node;
the contract state detection module is used for detecting the contract state on the blockchain system through the transaction state, and when the contract state is updated, the contract daemon module is triggered to control the contract container to be opened, stopped or upgraded.
12. The blockchain system of claim 6, wherein the smart contract includes a data structure conversion module and a transaction execution module;
the data structure conversion module is used for calling transaction data provided by the endorsement node through an intermediate dynamic data structure of a reflection technology and providing the transaction data to the transaction execution module;
the transaction execution module is used for executing and processing transaction data provided by the endorsement node.
13. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the processor implements the method of any of claims 1 to 5 when executing the computer program.
14. A computer readable storage medium, characterized in that the computer readable storage medium stores a computer program for executing the method of any one of claims 1 to 5 by a computer.
CN202110324100.XA 2021-03-26 2021-03-26 Intelligent contract upgrading and compatible method and system applied to block chain system Active CN112882744B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110324100.XA CN112882744B (en) 2021-03-26 2021-03-26 Intelligent contract upgrading and compatible method and system applied to block chain system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110324100.XA CN112882744B (en) 2021-03-26 2021-03-26 Intelligent contract upgrading and compatible method and system applied to block chain system

Publications (2)

Publication Number Publication Date
CN112882744A CN112882744A (en) 2021-06-01
CN112882744B true CN112882744B (en) 2024-03-26

Family

ID=76042360

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110324100.XA Active CN112882744B (en) 2021-03-26 2021-03-26 Intelligent contract upgrading and compatible method and system applied to block chain system

Country Status (1)

Country Link
CN (1) CN112882744B (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108965468A (en) * 2018-08-16 2018-12-07 北京京东尚科信息技术有限公司 Block chain network service platform and its chain code installation method, storage medium
CN109087104A (en) * 2018-08-29 2018-12-25 北京京东尚科信息技术有限公司 Block chain intelligence contract administration method and system, computer readable storage medium
CN111355718A (en) * 2020-02-25 2020-06-30 中国工商银行股份有限公司 Block chain intelligent contract cloud deployment system and method
CN112199096A (en) * 2020-09-30 2021-01-08 深圳壹账通智能科技有限公司 Intelligent contract deployment detection method and device, node equipment and storage medium

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20190361917A1 (en) * 2018-05-25 2019-11-28 Bao Tran Smart device

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108965468A (en) * 2018-08-16 2018-12-07 北京京东尚科信息技术有限公司 Block chain network service platform and its chain code installation method, storage medium
CN109087104A (en) * 2018-08-29 2018-12-25 北京京东尚科信息技术有限公司 Block chain intelligence contract administration method and system, computer readable storage medium
CN111355718A (en) * 2020-02-25 2020-06-30 中国工商银行股份有限公司 Block chain intelligent contract cloud deployment system and method
CN112199096A (en) * 2020-09-30 2021-01-08 深圳壹账通智能科技有限公司 Intelligent contract deployment detection method and device, node equipment and storage medium

Also Published As

Publication number Publication date
CN112882744A (en) 2021-06-01

Similar Documents

Publication Publication Date Title
CN110442652B (en) Cross-chain data processing method and device based on block chain
CN110390525B (en) Direct access method for block chain world state and block chain node
WO2018137564A1 (en) Service processing method and apparatus
US9626675B2 (en) Updating a widget that was deployed to a secure wallet container on a mobile device
CN109697071B (en) Installation package synthesis method, device, terminal and storage medium
US8381181B2 (en) Updating a workflow when a user reaches an impasse in the workflow
US20160125386A1 (en) Multi-tiered secure mobile transactions enabling platform
WO2021073202A1 (en) Intelligent contract processing method, computer device and storage medium
US20140020068A1 (en) Limiting widget access of wallet, device, client applications, and network resources while providing access to issuer-specific and/or widget-specific issuer security domains in a multi-domain ecosystem for secure personalized transactions
CN112835688A (en) Distributed transaction processing method, device and storage medium
CN111352653B (en) System development method based on PaaS cloud platform server and server
KR20140047580A (en) Method and system for synchronization mechanism on multi-server reservation system
CN111813601B (en) Micro-service rollback method and device for stateful distributed cluster
CN111880866A (en) Cross-process callback execution method, device, equipment and storage medium
CN112328413A (en) Application service calling method, device and system
CN111897738A (en) Automatic testing method and device based on atomic service
CN110442601A (en) A kind of method and apparatus that Openstack mirror image data accelerates parallel
CN102197390B (en) Providing functionality to client services by implementing and binding contracts
CN112882744B (en) Intelligent contract upgrading and compatible method and system applied to block chain system
CN112565369B (en) Intelligent contract implementation method, application service node, storage medium and system
CN113268272B (en) Application delivery method, device and system based on private cloud
CN113709059B (en) Link traffic recording method and node
US11153388B2 (en) Workflow engine framework for cross-domain extension
CN114493493A (en) Decision engine and decision engine implementation method
CN113158259A (en) Block chain integrity verification method and device

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