CN112882744A - 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
CN112882744A
CN112882744A CN202110324100.XA CN202110324100A CN112882744A CN 112882744 A CN112882744 A CN 112882744A CN 202110324100 A CN202110324100 A CN 202110324100A CN 112882744 A CN112882744 A CN 112882744A
Authority
CN
China
Prior art keywords
contract
transaction
module
intelligent contract
intelligent
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.)
Granted
Application number
CN202110324100.XA
Other languages
Chinese (zh)
Other versions
CN112882744B (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

Images

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 block chain system, which relate to the field of block chains 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 the intelligent contract codes in the installation transaction request to construct a corresponding intelligent contract mirror image; registering and generating a contract record according to the intelligent contract mirror image and the hash value; and monitoring the contract state on the block chain, calling a corresponding intelligent contract mirror image according to the contract record to start a contract container when the contract state is updated, and performing 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, can be applied to the financial field and other fields, and particularly relates 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 blockchain service, the service application writes service logic through the intelligent contract, and the data is subjected to contract processing and then linked up, so that the intelligent contract has high activity and is frequently required to be upgraded. In addition, intelligent contracts involve the processing of uplink data, each transaction produces data related to the contract, and after the contract is upgraded, due to the change of the data structure, the problem of incompatibility of old contract data exists, and the commonly adopted solution is transaction replay or data migration, but the two methods are very inefficient and time-consuming and need to be performed additionally.
Disclosure of Invention
The invention aims to provide an intelligent contract upgrading and compatible method and system applied to a block chain system aiming at the problems of upgrading of the current containerized deployment intelligent contract and heterogeneous data compatibility, so that the intelligent contract upgrading can be completed quickly, efficiently and fully automatically without influencing the normal operation of the system, and meanwhile, the upgraded intelligent contract can be compatible with the old contract data automatically, so that seamless access is realized.
To achieve the above object, the method for upgrading and compatible with an intelligent contract of a blockchain system provided by the present invention specifically comprises: 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 the intelligent contract codes in the installation transaction request to construct a corresponding intelligent contract mirror image; registering and generating a contract record according to the intelligent contract mirror image and the hash value; and monitoring the contract state on the block chain, calling a corresponding intelligent contract mirror image according to the contract record to start a contract container when the contract state is updated, and performing transaction processing on the associated intelligent contract through the contract container.
In the above method for upgrading and compatible with intelligent contracts of a blockchain system, preferably, the method further comprises: and generating a voting result after the received contract deployment voting is checked according to a preset rule, and feeding the voting result back to a contract deployment voting initiator.
In the foregoing method for upgrading and compatible with an intelligent contract of a blockchain system, preferably, invoking a corresponding intelligent contract image to start a contract container includes: and calling the intelligent contract image in the corresponding contract record according to the updated hash value in the contract state.
In the foregoing method for upgrading and compatible upgrading an intelligent contract of a blockchain system, preferably, generating a contract record according to the intelligent contract image and the hash value registration further includes: and when a contract container is operated under the contract with the same name of the contract record, updating the contract container operation record according to the contract record.
In the foregoing method for upgrading and compatible upgrading intelligent contracts of a blockchain system, preferably, monitoring contract states on a blockchain, and when the contract states are updated, invoking corresponding intelligent contract images to start a contract container includes: and monitoring contract states on the block chain, and stopping transmitting cache transactions to the intelligent contracts deployed at the current nodes and acquiring the current contract container state when the contract states are updated.
In the foregoing method for upgrading and compatible with an intelligent contract of a blockchain system, preferably, invoking a corresponding intelligent contract image to start a contract container includes: searching and obtaining a corresponding contract record and a contract container state according to the updated contract state; 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 transactions or not when the comparison result is inconsistent; and when no unfinished transaction exists, stopping running the contract container and starting the contract container according to the intelligent contract mirror image corresponding to the updated contract record.
The invention also provides a block chain system suitable for the method, wherein the block chain system comprises a client, a sequencing node, a plurality of endorsement nodes, a plurality of intelligent contracts and a plurality of verification nodes; the endorsement node is arranged at a predetermined 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; according to the received hash value, contract deployment voting is initiated to the endorsement nodes with the preset number in the block chain system, and the received voting result is sent to the sorting node; and initiating contract deployment confirmation requests to a predetermined number of endorsement nodes in the block chain system, and feeding back the received endorsement results to the sequencing node; the endorsement node 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 the intelligent contract codes in the installation transaction request to construct a corresponding intelligent contract mirror image; registering and generating a contract record according to the intelligent contract mirror image and the hash value; after the contract deployment voting launched by the client is audited according to a preset rule, generating a voting result and feeding the voting result back to the client; monitoring contract states on the block chain, calling corresponding intelligent contract images according to the contract records to start a contract container when the contract states are updated, and carrying out transaction processing on the associated intelligent contracts through the contract container; the sorting node is used for sorting and identifying according to the voting result to generate a block; and generating a block by sequencing consensus 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 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 an 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 above blockchain system, preferably, the endorsement node includes a transaction endorsement module, a contract mirroring module, a contract daemon module, and a transaction cache module; the transaction endorsement module is used for endorsement signing on a transaction execution result returned by the associated intelligent contract; 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 execution processing.
In the above blockchain system, preferably, the transaction cache 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 execution processing and registering a transaction state; the conditional lock module is used for monitoring contract states on the block chain, and controlling the transaction message list to stop transmitting the transaction data to the intelligent contract when the contract states are updated; and when the transaction execution in the intelligent contract is completed, recovering the transaction message list and transmitting the transaction data to the intelligent contract.
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 carrying out validity verification and endorsement signature verification on the transaction on the sequencing node; the contract state detection module is used for detecting the contract state on the block chain 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 started, stopped or upgraded.
In the above blockchain system, preferably, the intelligent contract includes a data structure conversion module and a transaction execution module; the data structure conversion module is used for calling the 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 the 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, wherein the processor implements the 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 invention has the beneficial technical effects that: the intelligent contract life cycle design mode is efficient and rapid, automatic upgrading of intelligent contracts in a containerized deployment mode is achieved through a contract daemon process, contract state updating detection and a contract container state machine, and normal transaction execution is not affected. The middle dynamic data structure based on the reflection technology is utilized to realize the compatible use of heterogeneous data, so that new and old contract data can be accessed and read compatibly 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 embodiment(s) of the invention and together with the description serve to explain the principles of the invention. In the drawings:
fig. 1A is a schematic flowchart of an intelligent contract upgrading and compatibility method for a blockchain system according to an embodiment of the present invention;
fig. 1B is a schematic structural diagram of a block chain system according to an embodiment of the present invention;
fig. 2 is a schematic structural diagram of a client according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of a transaction initiation device according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram of an endorsement node according to an embodiment of the present invention;
fig. 5 is a schematic structural diagram of a transaction caching 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 structural diagram of a verification node according to an embodiment of the present invention;
FIG. 8 is a schematic flow chart of intelligent contract deployment provided by an embodiment of the present invention;
FIG. 9 is a schematic flow chart of an intelligent contract upgrade provided by an embodiment of the present invention;
FIG. 10 is a schematic diagram of a reflection-transformed 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 present invention.
Detailed Description
The following detailed description of the embodiments of the present invention will be provided with reference to the drawings and examples, so that how to apply the technical means to solve the technical problems and achieve the technical effects can be fully understood and implemented. It should be noted that, unless otherwise specified, the embodiments and features of the embodiments of the present invention may be combined with each other, and the technical solutions formed are within the scope of the present invention.
Additionally, the steps illustrated in the flow charts 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 flow charts, in some cases, the steps illustrated or described may be performed in an order different than here.
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 the intelligent contract codes in the installation transaction request to construct a corresponding intelligent contract mirror image;
s103, generating a contract record according to the intelligent contract mirror image and the hash value registration;
s104, monitoring the contract state on the block chain, calling a corresponding intelligent contract mirror image according to the contract record to start a contract container when the contract state is updated, and carrying out transaction processing on the related intelligent contract through the contract container.
Therefore, contract deployment can be rapidly and conveniently and intelligently completed in a contract state detection and updating mode.
In an embodiment of the present invention, the method may further include: and generating a voting result after the received contract deployment voting is checked according to a preset rule, and feeding the voting result back to a contract deployment voting initiator. Specifically, in the actual work, a plurality of organizations can be set, the organizations are enterprises or organizations in the actual business activity, each organization joins in the blockchain system by maintaining one or more nodes, the organization is an important role in the blockchain system, all blockchain transactions related to the organization need to be validated through endorsement signatures of the organization, and in the embodiment, whether the intelligent contract is continuously deployed or not is determined by using voting results of each structure.
In an embodiment of the present invention, when the intelligent contract needs to be upgraded, the generating a contract record according to the intelligent contract image and the hash value registration in step S103 may further include: and when a contract container is operated under the contract with the same name of the contract record, updating the contract container operation record according to the contract record. Thus, the contract state on the block chain is monitored in the subsequent step S104, and when the contract state is updated, invoking the corresponding intelligent contract image to start the contract container comprises: and monitoring contract states on the block chain, and stopping transmitting cache transactions to the intelligent contracts deployed at the current nodes and acquiring the current contract container state when the contract states are updated. Further, invoking a corresponding intelligent contract image to start the contract container may include: and calling the intelligent contract image in the corresponding contract record according to the updated hash value in the contract state.
In the above embodiment, invoking the corresponding intelligent contract mirror to start the contract container may include: searching and obtaining a corresponding contract record and a contract container state according to the updated contract state; 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 transactions or not when the comparison result is inconsistent; and when no unfinished transaction exists, stopping running the contract container and starting the contract container according to the intelligent contract mirror image corresponding to the updated contract record.
Referring to fig. 1B, the present invention further provides a blockchain system suitable for the 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 predetermined 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; according to the received hash value, contract deployment voting is initiated to a predetermined number of endorsement nodes 2 in the block chain system, and the received voting result is sent to the sorting node 4; and initiating contract deployment confirmation requests to a predetermined number of endorsement nodes 2 in the block chain system, and feeding back the received endorsement results to the sequencing 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 the intelligent contract codes in the installation transaction request to construct a corresponding intelligent contract mirror image; registering and generating a contract record according to the intelligent contract mirror image and the hash value; after the contract deployment voting initiated by the client 1 is audited according to a preset rule, generating a voting result and feeding the voting result back to the client 1; monitoring contract states on the block chain, calling corresponding intelligent contract images according to the contract records to start a contract container when the contract states are updated, and carrying out transaction processing on the associated intelligent contracts 3 through the contract container; the sorting node 4 is used for sorting and identifying according to the voting result to generate a block; and generating a block by sequencing consensus according to the endorsement result; the verification node 5 is configured to pull the block and perform uplink persistence on the block.
In actual work, the client 1 is used as an important medium for connection and interaction between the outside and a blockchain system and is mainly responsible for sending any type of transaction and related requests, the interactive requests for the blockchain are all initiated by using the client 1, and the initiating objects are endorsement nodes 2 and sequencing nodes 4; in the scheme of the invention, a block chain system is provided with a plurality of mechanisms, the mechanisms are enterprises or organizations in actual business activities, each mechanism is added into the block chain system by maintaining one or more endorsement nodes 2, the mechanisms are important roles in the block chain system, block chain transactions related to the mechanisms need to be validated through the endorsement signatures of the mechanisms, the endorsement nodes 2 are responsible for doing the things, the transactions can be sent to the endorsement nodes 2 and can be set according to the actual business endorsement requirements, and besides, intelligent contracts 3 are deployed on the block chain and also need to be agreed by the mechanisms; the intelligent contract 3 is a core module for executing the transaction, is deployed on the endorsement node 2, sends the transaction to the intelligent contract 3 by the endorsement node 2, and returns the result to the endorsement node 2 for endorsement and signature after the execution is finished; the endorsement result is returned to the client 1, and then is packaged and sent to the sequencing node 4 by the client 1, the sequencing node 4 is mainly responsible for sequencing and identifying the transaction, and finally is packaged to generate a block to be distributed to the verification node 5, and an organization can also require to deploy the sequencing node 4 but not necessarily; the verification node 5 mainly performs block verification including transaction state, endorsement signature accuracy and the like, and the blocks passing the verification are finally written into a block chain account book to complete persistence.
Next, the specific functional components inside 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 issuing, installation and deployment of the intelligent contract are both regarded as a type of blockchain transaction, and both need to be initiated by the client 1, and then the transaction flow described above is completed.
In an embodiment of the present invention, 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. 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 an 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, the client 1 mainly includes a transaction initiating device 11 as shown in fig. 2, and the transaction request types include normal transaction, intelligent contract deployment, ordered transaction (request sent to the ordering node 4), and the like. The client 1 assembles the parameters of the transaction request or message via the transaction initiating device 11 and then designates the transaction recipient (endorsement node 2 or ordering node 4). As shown in fig. 3, the transaction initiation apparatus 11 mainly includes a transaction certificate module 111, a transaction configuration module 112, a contract code packaging module 113, and a communication module 114, where the transaction certificate module 111 is an important certificate of node identity, and generally all operations interacting with the blockchain system need to use a certificate; the transaction configuration module 112 mainly relates to the configuration of some transaction-related parameters, such as transaction type, endorsement node to which to send, etc.; the contract code packaging module 113 is mainly responsible for packaging intelligent contract codes, and the packaged contract code packages are needed to be used in the intelligent contract deployment process; the communication module 114 is responsible for sending the final transaction request to the designated place.
In an embodiment of the invention, the endorsement node comprises a transaction endorsement module, a contract mirror module, a contract daemon module and a transaction cache module; the transaction endorsement module is used for endorsement signing on a transaction execution result returned by the associated intelligent contract; 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 execution processing. Specifically referring to fig. 4, in practical operation, the endorsement node 2 mainly includes five modules: the system comprises a transaction endorsement module 21, a contract mirror image module 22, a contract daemon module 23, a communication module 24 and a transaction cache module 25, wherein the transaction endorsement module 21 is mainly used for endorsement signature on 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 process which continuously and circularly detects running, and is a daemon process of the contract life cycle, wherein a container state machine device is provided and is responsible for starting, stopping and upgrading the 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 is mainly used for caching transactions, and can perform high concurrent transaction caching processing, and in addition, an important module, namely a conditional lock, is also used, and when the conditional lock is triggered, the cached transactions stop being transmitted to the intelligent contracts 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 execution processing and registering a transaction state; the conditional lock module is used for monitoring contract states on the block chain, and controlling the transaction message list to stop transmitting the transaction data to the intelligent contract when the contract states are updated; and when the transaction execution in the intelligent contract is completed, recovering the transaction message list and transmitting the transaction data to the intelligent contract. In actual practice, the transaction caching module 25 is mainly provided with a transaction message list 251 and a conditional lock module 252 as shown in fig. 5, and a transaction received by the endorsement node 2 first enters the transaction message list 251 and registers the transaction status (waiting, executing and completing). Under normal conditions, according to the actual processing conditions of the system, the transaction is automatically sent to the intelligent contract 3 through the communication module 24, when contract state updating is detected, the conditional lock module 252 is triggered, at this moment, the transaction message list 251 stops transmitting the transaction to the intelligent contract 3, the conditional lock is released after the transaction which has entered the intelligent contract 3 is executed, and the cache transaction execution is recovered.
In one embodiment of the invention, the intelligent contract comprises a data structure conversion module and a transaction execution module; the data structure conversion module is used for calling the 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 the transaction data provided by the endorsement node. In actual operation, the intelligent contract 3 is shown in fig. 6, and mainly includes a data structure conversion module 31, a transaction execution module 32, and a communication module 33; 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 of the endorsement node 3.
In one embodiment of the invention, the verification node comprises a transaction verification module and a contract state detection module; the transaction verification module is used for carrying out validity verification and endorsement signature verification on the transaction on the sequencing node; the contract state detection module is used for detecting the contract state on the block chain 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 started, stopped or upgraded. In actual work, the verification node 5 is shown in fig. 7 and includes a transaction verification module 51 and a contract state detection module 52, the transaction verification module 51 is mainly responsible for performing legitimacy verification, endorsement signature verification, and the like on a transaction, the contract state detection module 52 is mainly used for detecting state updates related to a contract life cycle, and the contract deployment and upgrade are all sent to a blockchain system in a transaction form, so that the contract state updates can be found through transaction state detection at the verification node, and a contract management and control mechanism of the contract daemon module 23 is triggered.
In order to make the specific application of the blockchain system provided by the present invention more clearly understood, the following takes the intelligent contract deployment process and the intelligent contract upgrade process in actual work as examples to further explain the above mechanism modules, and it should be understood by those skilled in the art that the examples are only for facilitating understanding of the Juin application of the blockchain system provided by the present invention, and do not limit the application in any way.
Referring to fig. 8, the intelligent contract deployment process is as follows:
s801, packaging an intelligent contract code by a client 1;
s802, the client 1 assembles an intelligent contract installation transaction request by using the contract package obtained by packaging in S801 and sends the intelligent contract installation transaction 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 endorsement node 2 uses contract mirror image module 22 to compile contract package and construct the intelligent contract mirror image, contract daemon module 23 uses the unique hash value of the contract and the contract mirror image information to register a contract record, and starts to circularly monitor the contract container state (whether starting or stopping is needed);
and S804, the client 1 initiates the contract deployment vote to the endorsement node 2 by using the contract unique hash value obtained in S802, and the Sequence is required to be designated as 1, and is incremented once after the subsequent contract is upgraded. Generally, a general organization can deploy the intelligent contract only by agreeing, so that more than half of endorsement nodes 2 need to be sent with a voting request, and the endorsement nodes 2 return voting results to the client 1;
s805 the client 1 sends the collected voting endorsement results to the sorting node 4, and generates a block after finishing sorting consensus;
s806 the verification node 5 pulls the block to the sorting node 4 and verifies the block, and finally persists the block;
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 the contract deployment transaction;
s808, the client 1 sends the collected intelligent contract confirmation deployment endorsement result to the sequencing node 4, and generates a block after finishing sequencing consensus;
s809 verifying the block pulled by the node 5 to the sorting node 4 and verifying;
s810 the contract state monitoring module monitors that the contract state is updated (actually, it detects that the Sequence has changed, for the purpose of generalization of system design, the initial setting of the Sequence is 0, the contract is first deployed and the parameter is 1, and the Sequence has changed, thus triggering the contract state monitoring mechanism of the contract daemon module 23), the contract daemon module 23 is notified when the contract deployment is allowed, the contract daemon module 23 checks the contract state, finds that the contract container is not started, and then acquires the contract image information, starts the contract container (the process uses the unique contract hash value for retrieval), and registers the operation record of the contract container in the contract daemon module 23.
At this point, the contract may begin normal transaction execution.
Referring to fig. 9, the intelligent contract upgrading process is as follows:
s901, the client 1 packages the updated intelligent contract codes;
s902, the client 1 assembles an intelligent contract installation transaction request by using a new contract package obtained by packaging in S901, and sends the intelligent contract installation transaction 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 a contract package and constructs the intelligent contract new image by using the contract image module 22, the contract daemon 23 uses the contract unique hash value and the contract image information to register a contract record and update the contract container running record (namely, a contract container is run under the current contract with the same name, but two code package hash values are arranged under the contract name), and starts to circularly monitor the contract container state (whether to start or stop or not);
s904, the client 1 initiates the contract deployment vote to the endorsement node 2 by using the new contract unique hash value obtained in S902, and it is noted that Sequence +1 needs to be specified here, that is, an upgrade operation is performed. Generally, a general organization can deploy the intelligent contract only by agreeing, so that more than half of endorsement nodes 2 need to be sent with a voting request, and the endorsement nodes 2 return voting results to the client 1;
s905 the client 1 sends the collected voting endorsement results to the sorting node 4, and generates a block after finishing sorting consensus;
s906 the verification node 5 pulls the block to the sorting node 4 and verifies the block, and finally persists the block;
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 the contract deployment transaction;
s908, the client 1 sends the collected intelligent contract confirmation deployment endorsement result to the sequencing node 4, and generates a block after finishing sequencing consensus;
s909 verifying node 5 pulling the block to sorting node 4 and verifying;
s910, when monitoring that the contract state is updated (Sequence changes by + 1), the contract state monitoring module triggers the conditional lock module 252 in the transaction cache module 25, and the transaction starts 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 the container running record corresponding to the contract name;
s912, the contract daemon module 23 determines whether the Sequence is increased by 1, compares the hash of the contract whose state is updated with the hash of the current contract running container, and sets the state of the contract running container to a stoppable state if the hash of the current contract running container is not consistent with the hash of the current contract running container;
s913 detecting that the container is in a stoppable state by the container state machine in the contract daemon module 23, and detecting whether there is an unfinished transaction in the transaction message list 251;
s914 has no incomplete transaction, 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 as bootable dynamic;
the container state machine in the S915 contract daemon module 23 detects that the contract container is bootable, and then performs the startup of the contract container by using the mirror image corresponding to the new contract hash constructed in S903.
The transaction in the transaction cache module 25 can be normally transmitted to the intelligent contract 3 for execution, and the contract container is an updated and upgraded contract container. When the contract is automatically upgraded, the normal operation of system transaction is not influenced, and in the whole upgrading process, the contract state is quickly switched, so that the upgrading is efficient and quick.
After the contract is upgraded, the new and old contract data can be compatible for use without migration, and for this reason, the present invention further provides a dynamic data structure based on reflection technology, and details of the technical scheme are described in detail below.
Reflection, which is to dynamically acquire information about an object, dynamically executes the method of the object, because it is sometimes unknown during operation what type and what attributes and methods the object is specifically. Such as heterogeneous data for new and old contracts, data for new contracts does not know the type and properties of the old contract data objects, and so on. The specific steps of the heterogeneous data compatible technical scheme are as follows:
1. for a data structure in a contract, mapping the data structure into an intermediate data structure through a reflection technology, wherein each field in the contract data structure is converted into a piece of record data in the intermediate data structure;
2. for each field record, splicing key attributes (field names, types, lengths and the like) in the intermediate data structure to calculate hash;
3. taking each hash obtained by calculation in the step 2 as a key value of a world state of the blockchain, taking a real original value of the field as a corresponding value of the key, and storing the value into a blockchain account book (the contract data is subjected to data storage in the mode);
4. when accessing heterogeneous data, similarly, a reflection method is adopted to convert the intermediate data structure of the new data structure, and the hash value of the field to be accessed is calculated according to the step 2 to obtain the account book key value of the field;
5. and (4) accessing the block chain account book by using the key value obtained in the step (4) to obtain the value of the field stored on the block chain, and storing new field data in the same way as in the steps (2) and (3).
6. By means of the reflection conversion intermediate dynamic data structure and the mode of storing the book (k, v) pair forms, seamless connection and smooth compatibility of heterogeneous data can be achieved, and the method is shown in fig. 10.
Therefore, the block chain system provided by the invention can access and update new and old contract data under the normal operation of the system, and can automatically support heterogeneous data compatibility while upgrading the contract, thereby greatly reducing the cost of data migration.
The invention has the beneficial technical effects that: the intelligent contract life cycle design mode is efficient and rapid, automatic upgrading of intelligent contracts in a containerized deployment mode is achieved through a contract daemon process, contract state updating detection and a contract container state machine, and normal transaction execution is not affected. The middle dynamic data structure based on the reflection technology is utilized to realize the compatible use of heterogeneous data, so that new and old contract data can be accessed and read compatibly 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, wherein the processor implements the 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: communication module 110, input unit 120, audio processing unit 130, display 160, power supply 170. It is noted that the electronic device 600 does not necessarily include all of the components shown in FIG. 11; furthermore, the electronic device 600 may also comprise components not shown in fig. 11, which may be referred to in the prior art.
As shown in fig. 11, the central processor 100, sometimes referred to as a controller or operational control, may include a microprocessor or other processor device and/or logic device, the central processor 100 receiving input and controlling 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 relating to the failure may be stored, and a program for executing the information may be stored. And the central processing unit 100 may execute the program stored in the memory 140 to realize information storage or processing, etc.
The input unit 120 provides input to the cpu 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 to display an object to be displayed, such as an image or a character. The display may be, for example, an LCD display, but is not limited thereto.
The memory 140 may be a solid state memory such as Read Only Memory (ROM), Random Access Memory (RAM), a SIM card, or the like. There may also be a memory that holds information even when power is off, can be selectively erased, and is provided with more data, an example of which is sometimes called an EPROM or the like. The memory 140 may also be some other type of device. Memory 140 includes buffer memory 141 (sometimes referred to as a buffer). The memory 140 may include an application/function storage section 142, and the application/function storage section 142 is used to store application programs and function programs or a flow for executing the operation of the electronic device 600 by the central processing unit 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 portion 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 application, address book application, etc.).
The communication module 110 is a transmitter/receiver 110 that transmits and receives signals via an antenna 111. The 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, 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 receive audio input from the microphone 132 to implement general telecommunications functions. Audio processor 130 may include any suitable buffers, decoders, amplifiers and so forth. In addition, an audio processor 130 is also coupled to the central processor 100, so that recording on the local can be enabled through a microphone 132, and so that sound stored on the local can be played through a speaker 131.
As will be appreciated by one skilled in the art, 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 flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
The above-mentioned embodiments are intended to illustrate the objects, technical solutions and advantages of the present invention in further detail, and it should be understood that the above-mentioned embodiments are only exemplary embodiments of the present invention, and are not intended to limit the scope of the present invention, and any modifications, equivalent substitutions, improvements and the like made within the spirit and principle of the present invention should be included in the scope of the present invention.

Claims (15)

1. A method for intelligent contract upgrade and compatibility for blockchain systems, 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 the intelligent contract codes in the installation transaction request to construct a corresponding intelligent contract mirror image;
registering and generating a contract record according to the intelligent contract mirror image and the hash value;
and monitoring the contract state on the block chain, calling a corresponding intelligent contract mirror image according to the contract record to start a contract container when the contract state is updated, and performing transaction processing on the associated intelligent contract through the contract container.
2. The method for intelligent contract upgrade and compatibility with a blockchain system according to claim 1, wherein said method further comprises:
and generating a voting result after the received contract deployment voting is checked according to a preset rule, and feeding the voting result back to a contract deployment voting initiator.
3. The method of intelligent contract upgrade and compatibility for a blockchain system according to claim 1, wherein invoking the corresponding intelligent contract image to launch the contract container comprises: and calling the intelligent contract image in the corresponding contract record according to the updated hash value in the contract state.
4. The method for intelligent contract upgrade and compatibility for a blockchain system according to claim 1, wherein generating a contract record according to the intelligent contract image and the hash value registration further comprises:
and when a contract container is operated under the contract with the same name of the contract record, updating the contract container operation record according to the contract record.
5. The method for intelligent contract upgrading and compatibility of a blockchain system according to claim 4, wherein contract states on a blockchain are monitored, and when the contract states are updated, invoking corresponding intelligent contract images to start a contract container comprises:
and monitoring contract states on the block chain, and stopping transmitting cache transactions to the intelligent contracts deployed at the current nodes and acquiring the current contract container state when the contract states are updated.
6. The method of intelligent contract upgrade and compatibility for a blockchain system according to claim 5, wherein invoking the corresponding intelligent contract image to launch the contract container comprises:
searching and obtaining a corresponding contract record and a contract container state according to the updated contract state;
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 transactions or not when the comparison result is inconsistent;
and when no unfinished transaction exists, stopping running the contract container and starting the contract container according to the intelligent contract mirror image corresponding to the updated contract record.
7. A blockchain system suitable for use in the intelligent contract upgrading and compatible method of the blockchain system of any one of claims 1 to 6, wherein the blockchain system comprises 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 predetermined 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; according to the received hash value, contract deployment voting is initiated to the endorsement nodes with the preset number in the block chain system, and the received voting result is sent to the sorting node; and initiating contract deployment confirmation requests to a predetermined number of endorsement nodes in the block chain system, and feeding back the received endorsement results to the sequencing node;
the endorsement node 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 the intelligent contract codes in the installation transaction request to construct a corresponding intelligent contract mirror image; registering and generating a contract record according to the intelligent contract mirror image and the hash value; after the contract deployment voting launched by the client is audited according to a preset rule, generating a voting result and feeding the voting result back to the client; monitoring contract states on the block chain, calling corresponding intelligent contract images according to the contract records to start a contract container when the contract states are updated, and carrying out transaction processing on the associated intelligent contracts through the contract container;
the sorting node is used for sorting and identifying according to the voting result to generate a block; and generating a block by sequencing consensus according to the endorsement result;
the verification node is used for pulling the block and performing uplink persistence processing on the block.
8. The blockchain system of claim 7, wherein the client includes a transaction initiating device configured to assemble transaction requests or message parameters and send the assembled transaction requests or parameters to designated transaction recipients.
9. The blockchain system of claim 8, 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 an 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.
10. The blockchain system of claim 7, wherein the endorsement node comprises a transaction endorsement module, a contract mirroring module, a contract daemon module, and a transaction caching module;
the transaction endorsement module is used for endorsement signing on a transaction execution result returned by the associated intelligent contract;
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 execution processing.
11. The blockchain system of claim 10, 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 execution processing and registering a transaction state;
the conditional lock module is used for monitoring contract states on the block chain, and controlling the transaction message list to stop transmitting the transaction data to the intelligent contract when the contract states are updated; and when the transaction execution in the intelligent contract is completed, recovering the transaction message list and transmitting the transaction data to the intelligent contract.
12. The blockchain system of claim 10, wherein the validation node includes a transaction validation module and a contract status detection module;
the transaction verification module is used for carrying out validity verification and endorsement signature verification on the transaction on the sequencing node;
the contract state detection module is used for detecting the contract state on the block chain 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 started, stopped or upgraded.
13. The blockchain system of claim 7, wherein the smart contract includes a data structure conversion module and a transaction execution module;
the data structure conversion module is used for calling the 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 the transaction data provided by the endorsement node.
14. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor implements the method of any of claims 1 to 6 when executing the computer program.
15. 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 6 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 true CN112882744A (en) 2021-06-01
CN112882744B 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 (5)

* 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
US20190361917A1 (en) * 2018-05-25 2019-11-28 Bao Tran Smart device
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

Patent Citations (5)

* 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
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
CN112882744B (en) 2024-03-26

Similar Documents

Publication Publication Date Title
US20160048391A1 (en) Systems and methods for incremental software development
CN110390525B (en) Direct access method for block chain world state and block chain node
CN109697071B (en) Installation package synthesis method, device, terminal and storage medium
US20190384749A1 (en) Deployment of applications conforming to application data sharing and decision service platform schema
CN111538521B (en) Intelligent contract deployment and transaction method and device
CN111813601B (en) Micro-service rollback method and device for stateful distributed cluster
US6308326B1 (en) Run-time modules for dynamically adjusting computer operation
CN111142899A (en) Database script execution method and device, storage medium and electronic equipment
EP3732564A1 (en) Asynchronous c -js data binding bridge
WO2022148390A1 (en) Methods for deploying, updating and calling smart contract in blockchain
CN109002320A (en) For the update method of software development kit, system, electronic equipment and storage medium
WO2019238563A1 (en) System and methods with reduced complexity in the integration of exposed information models with applications
CN111897738A (en) Automatic testing method and device based on atomic service
CN111507694A (en) Block chain cross-chain interaction method and system
CN110442601A (en) A kind of method and apparatus that Openstack mirror image data accelerates parallel
CN112565369B (en) Intelligent contract implementation method, application service node, storage medium and system
CN113448643A (en) Configuration data management system and method
CN112882744B (en) Intelligent contract upgrading and compatible method and system applied to block chain system
CN113760308A (en) DSP system construction method and device, electronic equipment and storage medium
CN111930843A (en) Database-based data system and processing method
CN113268272B (en) Application delivery method, device and system based on private cloud
JP2022189744A (en) Method and apparatus for starting up blockchain system, device, and storage medium
CN114493493A (en) Decision engine and decision engine implementation method
CN112711602B (en) Method and device for running stored procedure, database system and storage medium
CN113377385A (en) Client automatic deployment 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