Smart contract version management method, device and storage medium
By searching the historical transaction records of smart contracts in the blockchain, determining the latest version information and generating new version information, it solves the problem of cumbersome operation of the smart contract version management mechanism, realizes automated version management, and improves operational convenience.
Patent Information
- Application Number
- CN202011009162.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-09-23
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2040-09-23
AI Technical Summary
The existing smart contract version management mechanism is cumbersome to operate, and users need to additionally maintain the correspondence between class names and versions, making maintenance difficult.
By searching the historical transaction records of smart contracts in the blockchain, determine the latest version information, generate new version information and transaction records, and store them in the blockchain ledger database to achieve automated version management.
It improves the operational convenience of smart contract version management, reduces the need for users to maintain class names and version relationships, and realizes an automated version management process.
Smart Images

Figure CN112148794B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a version management method, device and storage medium for a smart contract. Background Art
[0002] In related technologies, version management tools are usually used to manage the versions of smart contracts. For example, blockchains such as Fabric and Corda have their own version management mechanisms. In Fabric's version management mechanism, when updating smart contracts, users need to install modules such as InstallPackage and UpdateCC to update smart contracts. For Corda's version management mechanism, when maintaining smart contracts, each version corresponds to a new class name. Summary of the invention
[0003] After analysis, the inventor found that the user operation of the related technology is cumbersome and difficult to maintain. Taking Corda's version management mechanism as an example, different class names must be generated for different versions of the same smart contract, which requires users to additionally maintain the correspondence between class names and versions.
[0004] A technical problem to be solved by the embodiments of the present invention is to improve the operational convenience of smart contract version management.
[0005] According to a first aspect of some embodiments of the present invention, a method for version management of a smart contract is provided, comprising: in a case where the published smart contract is an updated smart contract, based on the basic information of the updated smart contract, searching the blockchain for transaction records of historical versions of the updated smart contract, wherein different versions of the same smart contract have the same basic information; determining the latest version information in the found transaction records; determining the version information of the updated smart contract based on the latest version information; generating a transaction record including the version information and basic information of the updated smart contract, and storing the transaction record in the ledger database of the blockchain.
[0006] In some embodiments, the version information is a version number; determining the maximum version number in the found transaction records; and determining the version number of the updated smart contract by incrementing the maximum version number.
[0007] In some embodiments, the version management method also includes: when the published smart contract is a brand new smart contract, determining the version information of the brand new smart contract as the preset initial information; generating a transaction record including the version information and basic information of the brand new smart contract, and storing the transaction record in the ledger database of the blockchain.
[0008] In some embodiments, the version management method also includes: obtaining an execution request for a smart contract, wherein the execution request includes an identifier of the smart contract, and different versions of the same smart contract have the same identifier; searching for corresponding transaction records from a ledger database of the blockchain based on basic information corresponding to the identifier of the smart contract; determining the latest version of the smart contract based on the version information in the found transaction records; and executing the latest version of the smart contract.
[0009] In some embodiments, the basic information in the transaction record is the storage address of the smart contract, and executing the latest version of the smart contract includes: caching the latest version of the smart contract into the memory according to the storage address of the smart contract in the transaction record found; and executing the smart contract in the memory.
[0010] In some embodiments, the version management method also includes: generating a transaction record of the smart contract execution, wherein the transaction record of the smart contract execution includes execution information, an identifier of the executed smart contract, and version information.
[0011] In some embodiments, the version management method also includes: obtaining a transaction replay request, wherein the transaction replay request includes a transaction identifier; searching for a transaction record to be replayed from a ledger database of the blockchain based on the transaction identifier; obtaining a corresponding version of the smart contract based on the identifier and version information of the smart contract executed in the transaction record to be replayed; and executing the corresponding version of the smart contract based on the execution information in the transaction record to be replayed to perform transaction replay.
[0012] In some embodiments, the transaction record also includes the release time of the smart contract, and the version management method also includes: obtaining a transaction replay request, wherein the transaction replay request includes a transaction identifier; searching for the transaction record to be replayed from the ledger database of the blockchain according to the transaction identifier; determining the identifier of the smart contract involved in the transaction and the transaction time from the transaction record to be replayed; searching for the corresponding transaction record from the ledger database of the blockchain according to the basic information corresponding to the identifier of the smart contract; determining the version information of the smart contract used in the transaction record to be replayed according to the release time of the smart contract in the transaction record corresponding to the identifier of the smart contract; and executing the version of the smart contract used in the transaction record to be replayed based on the execution information in the transaction record to be replayed to perform transaction replay.
[0013] In some embodiments, the transaction record also includes a byte array corresponding to the updated smart contract.
[0014] In some embodiments, the basic information is the storage address of the updated smart contract.
[0015] In some embodiments, storing transaction records in the ledger database of the blockchain includes: generating one or more leaf nodes according to the hash values of one or more transaction records corresponding to the block to be packaged; constructing a Merkle tree according to the leaf nodes; generating a block header of the block according to the root hash value of the Merkle tree and the root hash value corresponding to the last packaged block, and generating a block body of the block according to the one or more transaction records; and storing the block in the ledger database of the blockchain.
[0016] According to a second aspect of some embodiments of the present invention, there is provided a version management device for a smart contract, comprising: a transaction record search module, configured to, when the published smart contract is an updated smart contract, search the transaction records of the historical version of the updated smart contract from the blockchain according to the basic information of the updated smart contract, wherein different versions of the same smart contract have the same basic information; a historical version determination module, configured to determine the latest version information in the found transaction records; a version information determination module, configured to determine the version information of the updated smart contract based on the latest version information; a transaction record generation module, configured to generate a transaction record including the version information and basic information of the updated smart contract, and store the transaction record in the ledger database of the blockchain.
[0017] According to a third aspect of some embodiments of the present invention, there is provided a version management device for a smart contract, comprising: a memory; and a processor coupled to the memory, wherein the processor is configured to execute any one of the aforementioned version management methods for a smart contract based on instructions stored in the memory.
[0018] According to a fourth aspect of some embodiments of the present invention, a version management system for a smart contract is provided, comprising: any one of the aforementioned version management devices for a smart contract; and a blockchain system.
[0019] According to a fifth aspect of some embodiments of the present invention, there is provided a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements any one of the aforementioned smart contract version management methods.
[0020] Some embodiments of the above invention have the following advantages or beneficial effects: through the method of the embodiment of the present invention, when the smart contract is updated, the existing latest version information can be determined by querying the transaction record, and new version information and transaction records can be generated for the updated smart contract. Thus, the version management process can be automatically implemented, and users do not need to perform additional records and maintenance, which improves the operational convenience of version management.
[0021] Further features and advantages of the present invention will become apparent from the following detailed description of exemplary embodiments of the present invention with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0023] Figure 1 A flow chart of a method for managing a smart contract version according to some embodiments of the present invention is shown.
[0024] Figure 2 A flow chart of a smart contract execution method according to some embodiments of the present invention is shown.
[0025] Figure 3 A flow chart of a transaction replay method according to some embodiments of the present invention is shown.
[0026] Figure 4 A schematic flow chart of a transaction replay method according to some other embodiments of the present invention is shown.
[0027] Figure 5 A schematic diagram of the structure of a version management device for a smart contract according to some embodiments of the present invention is shown.
[0028] Figure 6 A schematic diagram of the structure of a smart contract version management system according to some embodiments of the present invention is shown.
[0029] Figure 7 A schematic structural diagram of a smart contract version management device according to some other embodiments of the present invention is shown.
[0030] Figure 8 A schematic structural diagram of a smart contract version management device according to some further embodiments of the present invention is shown. DETAILED DESCRIPTION
[0031] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. The following description of at least one exemplary embodiment is actually only illustrative and is by no means intended to limit the present invention and its application or use. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0032] The relative arrangement of components and steps, the numerical expressions and numerical values set forth in these embodiments do not limit the scope of the present invention unless specifically stated otherwise.
[0033] At the same time, it should be understood that for the convenience of description, the sizes of the various parts shown in the drawings are not drawn according to the actual proportional relationship.
[0034] Technologies, methods, and apparatus known to ordinary technicians in the relevant field may not be discussed in detail, but where appropriate, such technologies, methods, and apparatus should be considered part of the authorization specification.
[0035] In all examples shown and discussed herein, any specific values should be interpreted as merely exemplary and not as limiting. Therefore, other examples of the exemplary embodiments may have different values.
[0036] It should be noted that like reference numerals and letters refer to similar items in the following figures, and therefore, once an item is defined in one figure, it need not be further discussed in subsequent figures.
[0037] In an embodiment of the present invention, the transaction records of the blockchain are used to manage the version of the smart contract. The transaction records in the blockchain store the basic information and version information of the smart contract. The basic information is, for example, the name, identifier, storage address, etc. of the smart contract, and the version information is, for example, the version number, release time, etc. Figure 1 An embodiment of the version management method of the smart contract of the present invention is described.
[0038] Figure 1 FIG. 1 is a flow chart showing a method for managing the version of a smart contract according to some embodiments of the present invention. Figure 1 As shown, the version management method of the smart contract in this embodiment includes steps S102 to S108.
[0039] In step S102, when the published smart contract is an updated smart contract, the transaction record of the historical version of the updated smart contract is searched from the blockchain based on the basic information of the updated smart contract, wherein different versions of the same smart contract have the same basic information.
[0040] In some embodiments, a version management request triggered in response to the release of a smart contract is obtained, where the version management request includes basic information of the smart contract and an identification of whether the released smart contract is an updated smart contract or a completely new smart contract.
[0041] In some embodiments, the version management request includes basic information of the smart contract. Then, the transaction record is searched in the blockchain based on the basic information. If the result can be found, it means that the smart contract released is an updated smart contract; if the result cannot be found, it means that the smart contract released is a brand new smart contract.
[0042] In some embodiments, the transaction record stores<key,value,version> The structure information, where key represents the basic information of the smart contract, value represents the byte array corresponding to the smart contract, and version represents the version information of the smart contract.
[0043] In some embodiments, the transaction record also includes the file name used when the smart contract file is stored, so as to distinguish different versions of the smart contract when different versions of the same smart contract are stored at the same address.
[0044] In some embodiments, before the smart contract is released, it is also possible to verify whether the smart contract complies with the writing specifications. If it is not compliant, uploading and publishing are not allowed.
[0045] In step S104, the latest version information in the found transaction record is determined.
[0046] In some embodiments, the version information is a version number, and thus the latest version information in the found transaction records is determined by determining the maximum version number in the found transaction records.
[0047] In some embodiments, the version information is a release time, and thus the latest version information in the found transaction record is determined by determining the latest time in the found transaction record.
[0048] In step S106, based on the latest version information, the version information of the updated smart contract is determined.
[0049] In some embodiments, the version information of the updated smart contract is determined according to a preset update strategy. For example, when the version information is a version number, the version number of the updated smart contract is obtained by incrementing the maximum version number in the found transaction record.
[0050] In step S108, a transaction record including the updated version information and basic information of the smart contract is generated, and the transaction record is stored in the blockchain ledger database. Thus, when the same smart contract is updated again, the next version of the version information is generated based on the version information determined this time.
[0051] In some embodiments, the transaction record also includes a byte array corresponding to the updated smart contract to facilitate verification that the information stored in the blockchain corresponds to the actual smart contract.
[0052] In some embodiments, the transaction is packaged as follows: one or more leaf nodes are generated according to the hash value of one or more transaction records corresponding to the block to be packaged; a Merkle tree is constructed according to the leaf nodes; a block header of the block is generated according to the root hash value of the Merkle tree and the root hash value corresponding to the last packaged block, and a block body of the block is generated according to one or more transaction records; and the block is stored in the ledger database of the blockchain. Thus, the transaction content can be prevented from being tampered with.
[0053] In some embodiments, when the smart contract released is a brand new smart contract, the version information of the brand new smart contract is determined as the preset initial information, a transaction record including the version information and basic information of the brand new smart contract is generated, and the transaction record is stored in the ledger database of the blockchain. For example, the version number is set to 0 or 1.0.
[0054] Through the method of the above embodiment, when the smart contract is updated, the existing latest version information can be determined by querying the transaction record, and new version information and transaction records can be generated for the updated smart contract. Thus, the version management process can be automatically implemented, and users do not need to make additional records and maintenance, which improves the operational convenience of version management.
[0055] In some embodiments, when a smart contract needs to be executed, the latest version is directly queried from the blockchain. Figure 2 An embodiment of the smart contract execution method of the present invention is described.
[0056] Figure 2 A schematic diagram of a process flow of a smart contract execution method according to some embodiments of the present invention is shown. Figure 2 As shown, the smart contract execution method of this embodiment includes steps S202 to S208.
[0057] In step S202, an execution request of a smart contract is obtained, wherein the execution request includes an identifier of the smart contract, and different versions of the same smart contract have the same identifier. That is, the requester only needs to specify the smart contract to be used, without specifying the version to be used.
[0058] In step S204, the corresponding transaction record is searched from the ledger database of the blockchain according to the basic information corresponding to the identifier of the smart contract.
[0059] In step S206, the latest version of the smart contract is determined based on the version information in the found transaction record. For example, the maximum version number in the found transaction record is determined.
[0060] In step S208, the latest version of the smart contract is executed.
[0061] In some embodiments, the basic information in the transaction record is the storage address of the smart contract. During execution, the latest version of the smart contract is cached in the memory according to the storage address of the smart contract in the transaction record found, and the smart contract in the memory is executed.
[0062] Through the method of the above embodiment, the requester of smart contract execution does not need to pay attention to the version information, file name and other details of the latest version of the smart contract, but only needs to specify which smart contract to execute. By looking up the version information in the transaction record in the blockchain, the latest version of the smart contract can be automatically determined and executed, which improves the convenience of operation.
[0063] In some embodiments, the smart contract execution method also includes step S210.
[0064] In step S210, a transaction record of the smart contract execution is generated.
[0065] In some embodiments, the transaction record of the smart contract execution includes execution information, the identification and version information of the executed smart contract. For example, when the two parties to a transaction execute a smart contract for automatic deduction, the execution information includes the identification of the two parties to the transaction, the amount of deduction, the time, and other information.
[0066] By generating a transaction record including the version information of the smart contract after executing the smart contract, the execution status can be recorded more accurately and accurate transaction replay can be facilitated. Figure 3 An embodiment of the transaction replay method of the present invention is described.
[0067] Figure 3 FIG. 2 is a flow chart showing a transaction replay method according to some embodiments of the present invention. Figure 3 As shown, the transaction replay method of this embodiment includes steps S302 to S308.
[0068] In step S302, a transaction replay request is obtained, wherein the transaction replay request includes a transaction identifier.
[0069] In step S304, the transaction record to be replayed is searched from the ledger database of the blockchain according to the transaction identifier.
[0070] In step S306, the corresponding version of the smart contract is obtained according to the identification and version information of the smart contract executed in the transaction record to be replayed.
[0071] In step S308, the corresponding version of the smart contract is executed based on the execution information in the transaction record to be replayed to perform transaction replay.
[0072] Through the method of the above embodiment, when the two parties to the transaction have disputes over historical transactions, or when the nodes in the blockchain have power outages and other problems causing the block height to lag behind, the transaction can be replayed through the above embodiment, so that the replayed transaction uses the correct smart contract version, thereby improving the accuracy and convenience of transaction replay.
[0073] In some embodiments, when the transaction record of the smart contract execution does not include version information, the smart contract version used in the transaction can also be determined by the release time of the smart contract.
[0074] Figure 4 FIG. 2 shows a flow chart of a transaction replay method according to some other embodiments of the present invention. Figure 4 As shown, the transaction replay method of this embodiment includes steps S402 to S412.
[0075] In step S402, a transaction replay request is obtained, wherein the transaction replay request includes a transaction identifier.
[0076] In step S404, the transaction record to be replayed is searched from the ledger database of the blockchain according to the transaction identifier.
[0077] In step S406, the identifier of the smart contract involved in the transaction and the transaction time are determined from the transaction record to be replayed.
[0078] In step S408, the corresponding transaction record is searched from the blockchain account database according to the basic information corresponding to the smart contract identifier. The transaction record used to store the version information and basic information of the smart contract also includes the release time of the smart contract.
[0079] In step S410, the version information of the smart contract used in the transaction record to be replayed is determined according to the release time of the smart contract in the transaction record corresponding to the identifier of the smart contract.
[0080] In some embodiments, the latest smart contract among the smart contracts whose publishing time is before the transaction time is determined as the smart contract used in the transaction record to be replayed.
[0081] In step S412, based on the execution information in the transaction record to be replayed, the version of the smart contract used in the transaction record to be replayed is executed to perform transaction replay.
[0082] The method of the above embodiment determines the version of the smart contract used in the historical transaction by comparing the release time and the transaction time, so that the replayed transaction uses the correct smart contract version, thereby improving the accuracy and convenience of transaction replay.
[0083] In addition, since user transactions and smart contract version information are stored in the blockchain, version management, transaction management and other functions can be achieved through a blockchain system without the need for cross-system interaction. Moreover, both user transaction records and transaction records of smart contract version information can be achieved through a query interface, which reduces the difficulty of deploying the version management mechanism and has wide applicability.
[0084] Reference below Figure 5 An embodiment of a version management device for a smart contract of the present invention is described.
[0085] Figure 5 FIG. 1 is a schematic diagram showing a structure of a version management device for a smart contract according to some embodiments of the present invention. Figure 5 As shown, the version management device 500 of the smart contract of this embodiment includes: a transaction record search module 5100, which is configured to search for transaction records of historical versions of the updated smart contract from the blockchain according to the basic information of the updated smart contract when the published smart contract is an updated smart contract, wherein different versions of the same smart contract have the same basic information; a historical version determination module 5200, which is configured to determine the latest version information in the found transaction record; a version information determination module 5300, which is configured to determine the version information of the updated smart contract based on the latest version information; a transaction record generation module 5400, which is configured to generate a transaction record including the version information and basic information of the updated smart contract, and store the transaction record in the ledger database of the blockchain.
[0086] In some embodiments, the version information is a version number; the historical version determination module 5200 is further configured to determine the maximum version number in the found transaction record; the version information determination module 5300 is further configured to determine the version number of the updated smart contract by incrementing the maximum version number.
[0087] In some embodiments, the transaction record generation module 5400 is further configured to, when the published smart contract is a brand new smart contract, determine the version information of the brand new smart contract as the preset initial information; generate a transaction record including the version information and basic information of the brand new smart contract, and store the transaction record in the ledger database of the blockchain.
[0088] In some embodiments, the version management device 500 also includes: an execution module 5500, which is configured to obtain an execution request for a smart contract, wherein the execution request includes an identifier of the smart contract, and different versions of the same smart contract have the same identifier; according to the basic information corresponding to the identifier of the smart contract, searching for corresponding transaction records from the ledger database of the blockchain; determining the latest version of the smart contract based on the version information in the found transaction record; and executing the latest version of the smart contract.
[0089] In some embodiments, the basic information in the transaction record is the storage address of the smart contract, and the execution module 5500 is further configured to cache the latest version of the smart contract into the memory according to the storage address of the smart contract in the found transaction record; and execute the smart contract in the memory.
[0090] In some embodiments, the transaction record generation module 5400 is further configured to generate a transaction record of the smart contract execution, wherein the transaction record of the smart contract execution includes execution information, an identifier and version information of the executed smart contract.
[0091] In some embodiments, the version management device 500 also includes: a replay module 5500, configured to obtain a transaction replay request, wherein the transaction replay request includes a transaction identifier; based on the transaction identifier, searching for the transaction record to be replayed from the ledger database of the blockchain; based on the identifier and version information of the smart contract executed in the transaction record to be replayed, obtaining the corresponding version of the smart contract; and executing the corresponding version of the smart contract based on the execution information in the transaction record to be replayed to perform transaction replay.
[0092] In some embodiments, the transaction record also includes the release time of the smart contract, and the replay module 5500 is further configured to obtain a transaction replay request, wherein the transaction replay request includes a transaction identifier; based on the transaction identifier, search for the transaction record to be replayed from the ledger database of the blockchain; determine the identifier of the smart contract involved in the transaction and the transaction time from the transaction record to be replayed; based on the basic information corresponding to the identifier of the smart contract, search for the corresponding transaction record from the ledger database of the blockchain; based on the release time of the smart contract in the transaction record corresponding to the identifier of the smart contract, determine the version information of the smart contract used in the transaction record to be replayed; and based on the execution information in the transaction record to be replayed, execute the version of the smart contract used in the transaction record to be replayed to perform transaction replay.
[0093] In some embodiments, the transaction record also includes a byte array corresponding to the updated smart contract.
[0094] In some embodiments, the basic information is the storage address of the updated smart contract.
[0095] In some embodiments, the transaction record generation module 5400 is further configured to generate one or more leaf nodes according to the hash values of one or more transaction records corresponding to the block to be packaged; construct a Merkle tree according to the leaf nodes; generate a block header of the block according to the root hash value of the Merkle tree and the root hash value corresponding to the last packaged block, and generate a block body of the block according to one or more transaction records; and store the block in the ledger database of the blockchain.
[0096] Reference below Figure 6 An embodiment of a version management system for smart contracts of the present invention is described.
[0097] Figure 6 FIG. 1 is a schematic diagram showing a structure of a version management system for a smart contract according to some embodiments of the present invention. Figure 6 As shown, the version management system 60 of the smart contract of this embodiment includes: a version management device 610 of the smart contract, the specific implementation of which can refer to any of the aforementioned version management devices 500 of the smart contract; and a blockchain system 620.
[0098] Figure 7 FIG. 2 shows a schematic diagram of a smart contract version management device according to some other embodiments of the present invention. Figure 7 As shown, the version management device 70 of the smart contract of this embodiment includes: a memory 710 and a processor 720 coupled to the memory 710, and the processor 720 is configured to execute the version management method of the smart contract in any one of the aforementioned embodiments based on the instructions stored in the memory 710.
[0099] The memory 710 may include, for example, a system memory, a fixed non-volatile storage medium, etc. The system memory may store, for example, an operating system, an application program, a boot loader, and other programs.
[0100] Figure 8 FIG. 2 shows a schematic diagram of a smart contract version management device according to some other embodiments of the present invention. Figure 8 As shown, the version management device 80 of the smart contract of this embodiment includes: a memory 810 and a processor 820, and may also include an input and output interface 830, a network interface 840, a storage interface 850, etc. These interfaces 830, 840, 850 and the memory 810 and the processor 820 can be connected, for example, through a bus 860. Among them, the input and output interface 830 provides a connection interface for input and output devices such as a display, a mouse, a keyboard, and a touch screen. The network interface 840 provides a connection interface for various networked devices. The storage interface 850 provides a connection interface for external storage devices such as SD cards and U disks.
[0101] An embodiment of the present invention also provides a computer-readable storage medium having a computer program stored thereon, characterized in that when the program is executed by a processor, it implements any of the aforementioned smart contract version management methods.
[0102] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable non-transient storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0103] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0104] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0105] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0106] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A version management method for a smart contract, comprising: Obtaining a version management request triggered in response to the release of a smart contract, and in the case where the released smart contract is an updated smart contract, searching the blockchain for transaction records of historical versions of the updated smart contract according to basic information of the updated smart contract, wherein the version management request includes basic information of the smart contract, and different versions of the same smart contract have the same basic information; Determining the latest existing version information in the found transaction record, including: determining the latest version information in the found transaction record by determining the largest version number in the found transaction record, or determining the latest version information in the found transaction record by determining the latest time in the found transaction record; Based on the latest version information, determine the updated version information of the smart contract; Generate a transaction record including the version information and basic information of the updated smart contract, and store the transaction record in the ledger database of the blockchain.
2. The version management method according to claim 1, wherein: The version information is the version number; Determine the maximum version number among the found transaction records; The version number of the updated smart contract is determined by incrementing the maximum version number.
3. The version management method according to claim 1, further comprising: In the case where the published smart contract is a brand new smart contract, the version information of the brand new smart contract is determined as the preset initial information; Generate a transaction record including version information and basic information of the new smart contract, and store the transaction record in the ledger database of the blockchain.
4. The version management method according to claim 1, further comprising: Obtaining an execution request for a smart contract, wherein the execution request includes an identifier of the smart contract, and different versions of the same smart contract have the same identifier; According to the basic information corresponding to the identifier of the smart contract, the corresponding transaction record is searched from the ledger database of the blockchain; Determine the latest version of the smart contract based on the version information in the found transaction record; Execute the latest version of the smart contract.
5. The version management method according to claim 4, wherein: The basic information in the transaction record is the storage address of the smart contract. The execution of the latest version of the smart contract includes: caching the latest version of the smart contract into the memory according to the storage address of the smart contract in the found transaction record; and Execute smart contracts in memory.
6. The version management method according to claim 1 or 4, further comprising: Generate a transaction record of the smart contract execution, wherein the transaction record of the smart contract execution includes execution information, an identifier of the executed smart contract, and version information.
7. The version management method according to claim 6, further comprising: Obtaining a transaction replay request, wherein the transaction replay request includes a transaction identifier; According to the transaction identifier, searching for the transaction record to be replayed from the ledger database of the blockchain; Obtaining a corresponding version of the smart contract according to the identifier and version information of the smart contract executed in the transaction record to be replayed; The corresponding version of the smart contract is executed based on the execution information in the transaction record to be replayed to perform transaction replay.
8. The version management method according to claim 1, wherein: The transaction record also includes the release time of the smart contract, and the version management method also includes: Obtaining a transaction replay request, wherein the transaction replay request includes a transaction identifier; According to the transaction identifier, searching for the transaction record to be replayed from the ledger database of the blockchain; Determining the identifier of the smart contract involved in the transaction and the transaction time from the transaction record to be replayed; According to the basic information corresponding to the identifier of the smart contract, the corresponding transaction record is searched from the ledger database of the blockchain; Determining the version information of the smart contract used in the transaction record to be replayed according to the release time of the smart contract in the transaction record corresponding to the identifier of the smart contract; and Based on the execution information in the transaction record to be replayed, the version of the smart contract used in the transaction record to be replayed is executed to perform transaction replay.
9. The version management method according to claim 1, wherein: The transaction record also includes a byte array corresponding to the updated smart contract.
10. The version management method according to claim 1, wherein: The basic information is the storage address of the updated smart contract.
11. The version management method according to claim 1, wherein: The storing of the transaction record in the ledger database of the blockchain includes: Generate one or more leaf nodes according to the hash values of one or more transaction records corresponding to the block to be packaged; Constructing a Merkle tree according to the leaf nodes; Generate a block header of the block according to the root hash value of the Merkle tree and the root hash value corresponding to the last packaged block, and generate a block body of the block according to the one or more transaction records; and The blocks are stored in the ledger database of the blockchain.
12. A version management device for a smart contract, comprising: a transaction record search module, configured to obtain a version management request triggered in response to the release of a smart contract, and in the case where the released smart contract is an updated smart contract, search the blockchain for transaction records of a historical version of the updated smart contract according to basic information of the updated smart contract, wherein the version management request includes basic information of the smart contract, and different versions of the same smart contract have the same basic information; The historical version determination module is configured to determine the latest existing version information in the found transaction record, including: determining the latest version information in the found transaction record by determining the maximum version number in the found transaction record, or determining the latest version information in the found transaction record by determining the latest time in the found transaction record; A version information determination module, configured to determine the version information of the updated smart contract based on the latest version information; and The transaction record generation module is configured to generate a transaction record including version information and basic information of the updated smart contract, and store the transaction record in the ledger database of the blockchain.
13. A version management device for a smart contract, comprising: Memory; as well as A processor coupled to the memory, the processor being configured to execute the version management method of the smart contract as described in any one of claims 1 to 11 based on instructions stored in the memory.
14. A version management system for smart contracts, comprising: The version management device of the smart contract according to claim 12 or 13; as well as Blockchain system.
15. A computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the version management method of the smart contract described in any one of claims 1 to 11.
