A method and device for tracing change records of a blockchain smart contract
By obtaining query requests in the blockchain system and parsing the status tree and smart contract identifiers, positioning key fields, and generating changes records of smart contracts, the problem of the inability to trace the change records of smart contracts in the existing technology is solved, and efficient and authentic evidence storage information management is achieved.
Patent Information
- Application Number
- CN201910470438.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-05-31
- Publication Date
- 2025-06-27
- Estimated Expiration
- 2039-05-31
AI Technical Summary
In the existing blockchain system, the change records of smart contracts cannot be effectively traced, resulting in the inability to determine the authenticity of the evidence-stored information.
By obtaining query requests, the change records of smart contracts in the blockchain are determined, and the status tree root node and smart contract identifier are used to locate and parse key fields to generate changes records of smart contracts.
It realizes rapid and efficient acquisition of smart contract change records, ensures the authenticity of evidence storage information, avoids transaction records traversing the entire blockchain, and significantly improves traceability efficiency.
Smart Images

Figure CN110188112B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the field of financial technology (Fintech), and in particular, to a method and device for tracing the change records of a blockchain smart contract. Background Art
[0002] A blockchain is a chain composed of a series of blocks. Each block records the data of this block and the hash value of the previous block. All blocks are successively composed into a chain in this way. The cryptographic technology and decentralized concept based on the blockchain make the historical information on the chain impossible to be tampered with.
[0003] With the development of computer technology, more and more technologies are applied in the financial field. The traditional financial industry is gradually transforming into financial technology, and the blockchain transmission technology is no exception. However, due to the security and real-time requirements of the financial and payment industries, higher requirements are also put forward for the technology.
[0004] In the existing blockchain system, the evidence storage type smart contract provides an append interface for appending new evidence storage information to the smart contract. When storing evidence, this type of smart contract appends the new evidence storage information to the smart contract, and when the evidence storage information is needed, the evidence storage information can be directly read from the smart contract.
[0005] In the prior art, only reading the evidence storage information in the smart contract cannot determine the storage records of each evidence storage information in the smart contract, that is, the change records of the content in the smart contract cannot be traced, and further, the authenticity of the read evidence storage information cannot be guaranteed. Summary of the Invention
[0006] The embodiments of the present invention provide a method and device for tracing the change records of a blockchain smart contract, which can efficiently and quickly obtain the change records of the smart contract and ensure the authenticity of the evidence storage information in the smart contract according to the change records.
[0007] A method for tracing the change records of a blockchain smart contract provided by the embodiments of the present invention includes:
[0008] Obtaining a query request; the query request is used to indicate to determine the change records of the smart contract to be traced in the blockchain;
[0009] Determining a state tree corresponding to the state root node according to the state root node recorded in the block of the blockchain; and determining the key fields of the smart contract from the state tree according to the identifier of the smart contract; the key fields are used to represent the block height in the blockchain where the change information of the smart contract is stored;
[0010] Determine the change information of the smart contract according to the keyword fields, and generate a change record of the smart contract.
[0011] In the above technical solution, according to the state root node recorded in the block of the blockchain, determine the state tree corresponding to the state root node, and according to the identifier of the smart contract, determine the keyword fields of the smart contract from the state tree. The keyword fields of the smart contract are the heights of the blocks in the blockchain that record the change information of the smart contract. According to the keyword fields, parse the blocks corresponding to each keyword field, and then the change information can be determined, and a change record can be generated. This technical solution does not need to traverse the transaction records of each block in the entire blockchain, but directly locates the change information of the smart contract to a specific block, and then parses the specific block, so that the change record of the smart contract can be obtained quickly and efficiently. Further, according to the traced change record of the smart contract, the authenticity of the evidence information in the smart contract can be ensured.
[0012] Optionally, before obtaining the query request, it further includes:
[0013] Receive a creation request for the smart contract; according to the creation request, create the smart contract in the blockchain, generate a first block recording the transaction of creating the smart contract; and determine the height of the first block as the keyword field when the smart contract is created, and store it in the state tree corresponding to the state root node of the first block;
[0014] And receive an additional data request for the smart contract; according to the additional data request, write the data to be added in the additional data request into the smart contract, generate a second block recording the transaction of writing the data to be added into the smart contract; and determine the height of the second block as the keyword field when the smart contract adds data, and store it in the state tree corresponding to the state root node of the second block.
[0015] In the above technical solution, when the smart contract is created, the transaction of creating the smart contract is stored in the first block of the blockchain, and the height of the first block is used as the keyword field. And every time the smart contract changes, the change information of the current smart contract is stored in the second block of the blockchain, and the block height of the second block is used as the keyword field. The keyword field is stored in the state tree corresponding to the state root node of the corresponding block, which is used to quickly locate the change information to a specific block when querying the change information of the smart contract in the blockchain, so as to achieve the efficiency of tracing the change information.
[0016] Optionally, the step of determining the state tree corresponding to the state root node according to the state root node recorded in the block of the blockchain; and determining the keyword fields of the smart contract from the state tree according to the identifier of the smart contract includes:
[0017] Obtain the highest block of the blockchain and determine the highest block as the current block; determine the state tree corresponding to the state tree root node recorded in the current block; and determine the key fields when the smart contract appends data from the state tree according to the identifier of the smart contract.
[0018] Continue to determine the block corresponding to the key field when the smart contract appends data after subtracting 1 as the current block, and determine the state tree corresponding to the state tree root node recorded in the current block, and determine the key fields when the smart contract appends data from the state tree according to the identifier of the smart contract; until the key fields when the smart contract is created are determined.
[0019] In the above technical solution, starting from the highest block of the blockchain, determine the state tree corresponding to the highest block from the highest block, and determine the key fields when the smart contract appends data therefrom; further, starting from the block corresponding to the key field after subtracting 1, continue to determine the state tree and the key fields in the state tree, and repeat the above steps until the key fields when the smart contract is created are determined, that is, until all the change information of the smart contract is determined. Further, by the method of determining the state tree according to the block and then determining the key fields in the state tree in this technical solution, it is not necessary to traverse each block in the entire blockchain. For example, if the highest block height is 100, the key field can be determined to be 10 according to the highest block, and further, the block with a block height of 9 is used as the current block, and the key field is determined from the current block. As can be seen from the above, it is not necessary to query the blocks with block heights from 10 to 99 in this technical solution, which significantly improves the efficiency of tracing change records.
[0020] Optionally, the determining the change information of the smart contract according to the key fields and generating a change record of the smart contract includes:
[0021] Parse the blocks corresponding to each key field according to multiple key fields to obtain each change information of the smart contract;
[0022] After reversing each change information of the smart contract, determine it as the change record of the smart contract.
[0023] In the above technical solution, there can be multiple keyword fields in the smart contract. According to the multiple keyword fields, the blocks corresponding to each keyword field are parsed, and each change information of the smart contract is parsed from each block. Also, since the embodiments of the present invention obtain the keyword fields starting from the highest block of the blockchain, that is, the change information of each smart contract obtained above is in reverse order, it is necessary to perform a reverse operation on each change information of the smart contract and then determine it as the change record of the smart contract. The order of the change information after reverse is more in line with the viewing habit of personnel, improving the user experience.
[0024] Correspondingly, the embodiments of the present invention further provide a tracing device for the change record of a blockchain smart contract, including:
[0025] An acquisition unit, configured to acquire a query request; the query request is used to indicate to determine the change record of the smart contract to be traced in the blockchain.
[0026] A processing unit, configured to determine the state tree corresponding to the state tree root node recorded in the block of the blockchain; and determine the keyword field of the smart contract from the state tree according to the identifier of the smart contract; the keyword field is used to represent the height of the block in the blockchain where the change information of the smart contract is stored; and determine the change information of the smart contract according to the keyword field, and generate the change record of the smart contract.
[0027] Optionally, the processing unit is further configured to:
[0028] Before acquiring the query request, receive a creation request of the smart contract; create the smart contract in the blockchain according to the creation request, generate a first block recording the transaction of creating the smart contract; and determine the height of the first block as the keyword field when the smart contract is created, and store it in the state tree corresponding to the state tree root node of the first block.
[0029] And receive an additional data request of the smart contract; write the data to be added in the additional data request into the smart contract according to the additional data request, generate a second block recording the transaction of writing the data to be added into the smart contract; and determine the height of the second block as the keyword field when the smart contract adds data, and store it in the state tree corresponding to the state tree root node of the second block.
[0030] Optionally, the processing unit is specifically configured to:
[0031] Obtain the highest block of the blockchain, and determine the highest block as the current block; determine the state tree corresponding to the state tree root node according to the state tree root node recorded in the current block; and determine the key fields when the smart contract appends data from the state tree according to the identifier of the smart contract.
[0032] Continue to determine the block corresponding to the key field when the smart contract appends data after subtracting 1 as the current block, determine the state tree corresponding to the state tree root node according to the state tree root node recorded in the current block, and determine the key fields when the smart contract appends data from the state tree according to the identifier of the smart contract; until the key fields when the smart contract is created are determined.
[0033] Optionally, the processing unit is specifically configured to:
[0034] Parse the blocks corresponding to each key field according to multiple key fields to obtain each change information of the smart contract;
[0035] After reversing each change information of the smart contract, determine it as the change record of the smart contract.
[0036] Correspondingly, an embodiment of the present invention further provides a computing device, including:
[0037] A memory for storing program instructions;
[0038] A processor for calling the program instructions stored in the memory and executing the above-mentioned method for tracing the change record of the blockchain smart contract according to the obtained program.
[0039] Correspondingly, an embodiment of the present invention further provides a computer-readable non-volatile storage medium, including computer-readable instructions, when the computer reads and executes the computer-readable instructions, causing the computer to execute the above-mentioned method for tracing the change record of the blockchain smart contract. Description of the Drawings
[0040] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the following drawings are only some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0041] Figure 1 A schematic diagram of a system architecture provided by an embodiment of the present invention;
[0042] Figure 2Schematic flowchart of a method for tracing change records of a blockchain smart contract provided by an embodiment of the present invention;
[0043] Figure 3 Schematic structural diagram of a block header in a blockchain provided by an embodiment of the present invention;
[0044] Figure 4 Schematic flowchart of a method for determining key fields of a smart contract provided by an embodiment of the present invention;
[0045] Figure 5 Schematic structural diagram of a device for tracing change records of a blockchain smart contract provided by an embodiment of the present invention. Detailed implementation manners
[0046] In order to make the objectives, technical solutions and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all of the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0047] In a blockchain system, a proof storage smart contract can be deployed. This type of smart contract can provide an append interface for appending and writing new proof storage information into the smart contract, and will not provide a modification interface, thereby ensuring that this type of smart contract can only append and write proof storage information, but cannot change the proof storage information that has been stored in the smart contract.
[0048] When storing proof, the proof storage smart contract can write the proof storage information or the hash value of the proof storage information into the smart contract, and read the proof storage information or the hash value of the proof storage information in the smart contract for comparison and verification when taking evidence. In specific implementation, a hierarchical smart contract structure can be adopted in the blockchain: a factory contract and a proof storage contract. The factory contract is pre-agreed by all parties involved in the proof storage, stores the proof storage effective conditions, and manages the generation of the proof storage; the proof storage contract is generated by the factory contract, and stores the proof storage information, the identifier of the proof storage information, the hash value, and the signatures of all parties, etc.
[0049] Figure 1 Exemplarily shows the system architecture applicable to the method for tracing change records of a blockchain smart contract provided by an embodiment of the present invention. This system architecture may include a query server 100 and a blockchain system 200.
[0050] The query server 100 is used to send a query request to the blockchain system 200. The query request includes the identifier of the smart contract to be traced, and this query request is used to instruct the blockchain system 200 to determine the change records of the smart contract to be traced from the blockchain. Among them, the smart contract is a deposit-based smart contract. For the convenience of description, all the smart contracts mentioned below are contracts for storing evidence. The identifier of the smart contract can be the name, address, etc. of the smart contract.
[0051] After receiving the query request, the blockchain system 200 will determine the change information of the contract content in the smart contract from the blockchain according to the identifier of the smart contract to be traced in the query request, and form a change record. The blockchain system 200 feeds back the change record of the smart contract to the query server 100.
[0052] Based on the above description, Figure 2 Exemplarily shows the flow of a method for tracing the change records of a blockchain smart contract provided by an embodiment of the present invention. This flow can be executed by a device for tracing the change records of a blockchain smart contract. This device can be located in the blockchain system and can be the blockchain system itself. As Figure 2 shown, this flow specifically includes:
[0053] Step 201, obtain a query request.
[0054] This query request is the request sent by the query server to the blockchain system and records the identifier of the smart contract to be traced. This query request is used to instruct to determine the change records of the smart contract to be traced from the blockchain.
[0055] Step 202, determine the state tree corresponding to the state root node according to the state root node recorded in the block of the blockchain, and determine the key fields of the smart contract from the state tree according to the identifier of the smart contract.
[0056] Step 203, determine the change information of the smart contract according to the key fields, and generate the change record of the smart contract.
[0057] Exemplarily, the traceability process of a smart contract may involve three roles, namely, a user, an evidence depository institution, and an arbitration institution. For example, when a user borrows money from an evidence depository institution, the evidence depository institution can create a smart contract in the blockchain to record that "the user borrows 100 yuan from the evidence depository institution". Further, when the user repays the evidence depository institution each time, the evidence depository institution will generate evidence information based on the repayment information and store it in the smart contract. For example, generate evidence information "the user repays 10 yuan" and store it in the smart contract. If a dispute occurs between the user and the evidence depository institution during or after the user's repayment process, the arbitration institution can send a query request for the smart contract to the blockchain system through the query server, instructing the blockchain system to determine the change record of the smart contract according to the query request.
[0058] In an embodiment of the present invention, tracing the change record of a smart contract means determining each change information of the smart contract. For example, when storing the evidence information "the user repays 10 yuan" in the smart contract, the change information of the smart contract is "writing the evidence information 'the user repays 10 yuan' in the smart contract". Each change information of the smart contract is stored as a transaction information of the blockchain in a specific block of the blockchain. To ensure a faster and more efficient determination of the change record of the smart contract, it is necessary to determine the height of the specific block in the blockchain where each change information is stored for each change information.
[0059] Here, a brief description of the data storage structure of the application platform of the blockchain - Ethereum can be given first. In the block data on the Ethereum blockchain, there are nodes of three Merkle roots stored. Among them, the three Merkle trees are the state tree, the transaction tree, and the receipt tree. Storing the three Merkle trees can facilitate more queries for accounts. The state root node (State Root), the transaction tree node (Transaction Root), and the receipt root node (Receipt Root) can be understood as the state root hash value, the transaction root hash value, and the receipt root hash value respectively, and can be as Figure 3 shown. The state root node, the transaction tree node, and the receipt root node are stored in the block header. The block header may also include the hash value of the parent block (PrevHash), the hash value of the uncle block (Uncles Hash), the timestamp (Timestamp), and the nonce (Nonce).
[0060] In a feasible implementation manner, a keyword field can be added to the smart contract. This keyword field is used to represent the block height in the blockchain where the change information of the smart contract is stored. That is to say, every time the smart contract is changed, the change information of the current smart contract will be stored in a block of the blockchain, and the block height of this block will be stored as a keyword field in the smart contract. The block height can be understood as a specific identifier of a certain block on the blockchain, which can be the block height or the block number. In addition, when the blockchain creates a smart contract, it will also store the block height of the block recording the transaction of creating the smart contract in the smart contract. Further explanation, the state tree contains contract accounts. The contract accounts store the executable bytecode of the smart contract (after compilation, executed in the EVM (Environment Virtual Machine, Ethereum virtual machine)), and there is storage space. The smart contract can write information to the storage space of the contract account. Therefore, in the above description, storing the keyword field in the smart contract is equivalent to storing the keyword field in the state tree corresponding to the root node of the block's state tree. In addition, writing to the smart contract in the embodiments of the present invention is equivalent to writing to the storage space of the smart contract.
[0061] That is to say, before obtaining the query request in step 201, a creation request of the smart contract can be received. According to this creation request, a smart contract is created in the blockchain, and a first block recording the transaction of creating the smart contract is generated. Then, the height of the first block is determined as the keyword field when the smart contract is created and stored in the state tree corresponding to the root node of the state tree of the first block. And a request for appending data to the smart contract is received. According to the request for appending data, the data to be appended in the request for appending data is written to the smart contract, and a second block recording the transaction of writing the data to be appended to the smart contract is generated. Then, the height of the second block is determined as the keyword field when the smart contract appends data and stored in the state tree corresponding to the root node of the state tree of the second block. Here, the data to be appended can be stored in the smart contract multiple times. That is to say, there can be multiple second blocks, and there can also be multiple keyword fields when the smart contract appends data.
[0062] After obtaining the query request in step 201, the keyword fields of the smart contract when it is created and when data is appended can be determined from the blockchain according to the query request. In the embodiment of the present invention, the blockchain system can determine the corresponding state tree according to the state tree root node of the block in the blockchain, and determine the keyword fields of the smart contract from the state tree according to the identifier of the smart contract. Specifically, it can start from the highest block of the blockchain, that is, first obtain the highest block of the blockchain and determine the highest block as the current block. According to the state tree root node recorded in the current block, determine the state tree corresponding to the state tree root node, and determine the keyword fields of the smart contract when appending data from the state tree according to the identifier of the smart contract. Subsequently, the block corresponding to the keyword field of the smart contract when appending data determined minus 1 is continued to be determined as the current block, and according to the state tree root node recorded in the current block, determine the state tree corresponding to the state tree root node, and determine the keyword fields of the smart contract when appending data from the state tree until the keyword fields when the smart contract is created are determined. For a better understanding of the embodiments of the present invention, reference can be made to Figure 4 The flowchart of
[0063] Step 401, obtain the highest block of the blockchain and determine the highest block as the current block.
[0064] Step 402, determine the state tree corresponding to the state tree root node according to the state tree root node recorded in the current block.
[0065] Step 403, determine the keyword field M of the smart contract when appending data from the state tree according to the identifier of the smart contract, where M is greater than or equal to 2.
[0066] Step 404, subtract 1 from the determined keyword field M of the smart contract when appending data, and use the block corresponding to M - 1 as the current block.
[0067] Step 405, determine whether the keyword fields when the smart contract is created are determined. If so, end; otherwise, go to step 402.
[0068] After determining the keyword fields of the smart contract during creation and when appending data according to the above embodiments, in step 203, the change information of the smart contract can be determined based on the determined keyword fields, and a change record of the smart contract can be generated. Since there can be multiple keyword fields for the smart contract, each block corresponding to each keyword field can be parsed according to the multiple keyword fields, and each change information of the smart contract can be parsed from each block. Also, since the embodiments of the present invention obtain the keyword fields starting from the highest block of the blockchain, that is, the change information of each obtained smart contract is in reverse order, it is necessary to perform a reverse order operation on each change information of the smart contract and then determine it as the change record of the smart contract. For example, the change information recorded by the smart contract on May 30th is obtained for the first time (according to the highest block), the change information recorded on April 30th is obtained for the second time, and the change information recorded on March 30th is obtained for the third time. Therefore, it is necessary to perform a reverse order operation on the change information obtained three times to generate the final change record of the smart contract.
[0069] In the embodiments of the present invention, when parsing each block, the timestamp information of each block can be parsed for reference information during the traceability process of the smart contract, and at the same time, the timestamp information can be correspondingly recorded in the change information of the smart contract for personnel to view.
[0070] To better explain the embodiments of the present invention, the above example of a user borrowing money from a deposit and evidence institution is used for illustration.
[0071] In January 2019, the user borrowed money from the deposit and evidence institution, and the deposit and evidence institution created a smart contract in the blockchain. At this time, the content of the smart contract was "The user borrowed 100 yuan from the deposit and evidence institution". The transaction record of creating the smart contract was on the block with a block height of 1 in the blockchain.
[0072] In February 2019, the user repaid 10 yuan to the deposit and evidence institution, then the data appended to the smart contract was "The user repaid 10 yuan". At this time, the content of the smart contract was "The user borrowed 100 yuan from the deposit and evidence institution, and the user repaid 10 yuan". The transaction record of appending this data to the smart contract was on the block with a block height of 3 in the blockchain.
[0073] In March 2019, the user repaid 20 yuan to the deposit and evidence institution, then the data appended to the smart contract was "The user repaid 20 yuan". At this time, the content of the smart contract was "The user borrowed 100 yuan from the deposit and evidence institution, the user repaid 10 yuan, and the user repaid 20 yuan". The transaction record of appending this data to the smart contract was on the block with a block height of 10 in the blockchain.
[0074] In May 2019, a dispute occurred between the user and the evidence preservation institution. The arbitration institution sent a query request for this smart contract to the blockchain system through the query server. The height of the highest block in the blockchain of the blockchain system is 100. Then, the blockchain system first determines that the key field of the smart contract is 10 based on the highest block, that is, the transaction record of adding the data "the user repays 20 yuan" to the smart contract is on the block with a block height of 10 in the blockchain. Further, after subtracting 1 from the key field 10, the blockchain system determines the block with a block height of 9 and determines that the key field of the smart contract in it is 3, that is, the transaction record of adding the data "the user repays 10 yuan" to the smart contract is on the block with a block height of 3 in the blockchain. Finally, after subtracting 1 from the key field 3, the blockchain system determines the block with a block height of 2 and determines that the key field of the smart contract in it is 1, that is, the transaction record of creating the smart contract "the user borrows 100 yuan from the evidence preservation institution" is on the block with a block height of 1 in the blockchain. The change information of the smart contract is parsed from the blocks corresponding to the determined key fields as follows:
[0075] Change Information 1: The transaction information in block height 10 is "Add smart contract data, write 'The user borrows 100 yuan from the evidence preservation institution, the user repays 10 yuan, the user repays 20 yuan'".
[0076] Change Information 2: The transaction information in block height 3 is "Add smart contract data, write 'The user borrows 100 yuan from the evidence preservation institution, the user repays 10 yuan'".
[0077] Change Information 3: The transaction information in block height 1 is "Create a smart contract, write 'The user borrows 100 yuan from the evidence preservation institution'".
[0078] After performing the reverse operation on Change Information 1, Change Information 2, and Change Information 3, it is used as the change record of the smart contract and can be provided for personnel to view.
[0079] In the above embodiment, according to the state tree root node recorded in the block of the blockchain, the corresponding state tree of the state tree root node is determined, and according to the identifier of the smart contract, the key field of the smart contract is determined from the state tree. The key field of this smart contract is the height of the block in the blockchain that records the change information of the smart contract. According to the key field, each block corresponding to the key field is parsed, and then each change information can be determined to generate a change record. This technical solution does not need to traverse the transaction records of each block in the entire blockchain, but directly locates the change information of the smart contract to a specific block, and then parses this specific block, so that the change record of the smart contract can be obtained quickly and efficiently. Further, according to the traced change record of the smart contract, the authenticity of the evidence preservation information in the smart contract is ensured.
[0080] In addition, it should be noted that the method for tracing the change records of the smart contract provided by the embodiment of the present invention can effectively guarantee the authenticity of the evidence storage information in the smart contract. It is interpreted that in the prior art, when reading the data in the smart contract, for example, the information read is "the user borrowed 100 yuan from the evidence storage institution, the user repaid 10 yuan, and the user repaid 20 yuan", but only this data can be read, and it is determined that this data is written in the smart contract. However, in the prior art, it is not possible to determine the specific time when it was written. That is to say, the evidence storage institution can write this information at one time, or write it in three or two times. Therefore, it is necessary to trace the change records of the smart contract, so as to ensure the writing time, writing times, writing parameters, etc. of each written information in the smart contract, so as to ensure the authenticity of the evidence storage information in the smart contract.
[0081] Based on the same inventive concept, Figure 5 Exemplarily, the structure of a device for tracing the change records of a blockchain smart contract provided by the embodiment of the present invention is shown. The device can execute the process of the method for tracing the change records of the blockchain smart contract.
[0082] The device includes:
[0083] An acquisition unit 501, configured to acquire a query request; the query request is used to indicate to determine the change records of the smart contract to be traced in the query request from the blockchain;
[0084] A processing unit 502, configured to determine the state tree corresponding to the state tree root node recorded in the block of the blockchain according to the state tree root node; and determine the key fields of the smart contract from the state tree according to the identifier of the smart contract; the key fields are used to characterize the height of the block in the blockchain where the change information of the smart contract is stored; and according to the key fields, determine the change information of the smart contract and generate the change records of the smart contract.
[0085] Optionally, the processing unit 502 is further configured to:
[0086] Before acquiring the query request, receive a creation request of the smart contract; create the smart contract in the blockchain according to the creation request, generate a first block recording the transaction of creating the smart contract; and determine the height of the first block as the key field when the smart contract is created, and store it in the state tree corresponding to the state tree root node of the first block.
[0087] and receiving an additional data request for the smart contract; according to the additional data request, writing the data to be appended in the additional data request into the smart contract, generating a second block recording the transaction of writing the data to be appended into the smart contract; and determining the height of the second block as a key field when the smart contract appends data, and storing it into the state tree corresponding to the state tree root node of the second block.
[0088] Optionally, the processing unit 502 is specifically configured to:
[0089] Obtain the highest block of the blockchain, and determine the highest block as the current block; according to the state tree root node recorded in the current block, determine the state tree corresponding to the state tree root node; and according to the identifier of the smart contract, determine the key field when the smart contract appends data from the state tree;
[0090] Continue to determine the block corresponding to the key field when the smart contract appends data after subtracting 1 as the current block, and according to the state tree root node recorded in the current block, determine the state tree corresponding to the state tree root node, and according to the identifier of the smart contract, determine the key field when the smart contract appends data from the state tree; until the key field when the smart contract is created is determined.
[0091] Optionally, the processing unit 502 is specifically configured to:
[0092] Parse the blocks corresponding to each key field according to multiple key fields to obtain each change information of the smart contract;
[0093] After reversing each change information of the smart contract, determine it as the change record of the smart contract.
[0094] Based on the same inventive concept, an embodiment of the present invention further provides a computing device, including:
[0095] A memory for storing program instructions;
[0096] A processor for calling the program instructions stored in the memory and executing the above-mentioned method for tracing the change record of the blockchain smart contract according to the obtained program.
[0097] Based on the same inventive concept, an embodiment of the present invention further provides a computer-readable non-volatile storage medium, including computer-readable instructions, when the computer reads and executes the computer-readable instructions, the computer is caused to execute the above-mentioned method for tracing the change record of the blockchain smart contract.
[0098] The present invention is described with reference to the flowcharts and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the present invention. It should be understood that each flow and / or block in the flowcharts and / or block diagrams, as well as the combination of flows and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing devices to generate a machine, such that the instructions executed by the processor of the computer or other programmable data processing devices produce means for implementing the functions specified in one or more flows Figure 1 one or more flows and / or blocks Figure 1 or in one or more blocks.
[0099] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, such that the instructions stored in the computer-readable memory produce a manufacture including instruction means that implement the functions specified in one or more flows Figure 1 one or more flows and / or blocks Figure 1 or in one or more blocks.
[0100] These computer program instructions can also be loaded onto a computer or other programmable data processing device, such that a series of operational steps are executed on the computer or other programmable device to generate a computer-implemented process, so that the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one or more flows Figure 1 one or more flows and / or blocks Figure 1 or in one or more blocks.
[0101] Although the preferred embodiments of the present invention have been described, those skilled in the art can make additional changes and modifications once they learn the basic creative concepts. Therefore, the appended claims are intended to be construed to include the preferred embodiments as well as all changes and modifications falling within the scope of the present invention.
[0102] Obviously, those skilled in the art can make various changes and variations to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalent technologies, the present invention is also intended to include these modifications and variations.
Claims
1. A method for tracing the change records of a blockchain smart contract, characterized in that, including: obtaining a query request; the query request is used to indicate determining change records of a smart contract to be traced in the blockchain; determining a state tree corresponding to a state root node recorded in a block of the blockchain; and determining key fields of the smart contract from the state tree according to an identifier of the smart contract; the key fields are used to represent a height of a block in which change information of the smart contract is stored in the blockchain; determining change information of the smart contract according to the key fields, and generating a change record of the smart contract; wherein, before obtaining the query request, it further includes: receiving a creation request of the smart contract; creating the smart contract in the blockchain according to the creation request, generating a first block recording a transaction of creating the smart contract; and determining a height of the first block as a key field when the smart contract is created, and storing the key field in a state tree corresponding to a state root node of the first block; and receiving an additional data request of the smart contract; writing the data to be appended in the additional data request into the smart contract according to the additional data request, generating a second block recording a transaction of writing the data to be appended into the smart contract; and determining a height of the second block as a key field when the smart contract appends data, and storing the key field in a state tree corresponding to a state root node of the second block.
2. The method according to claim 1, wherein The determining a state tree corresponding to a state root node recorded in a block of the blockchain; and determining key fields of the smart contract from the state tree according to an identifier of the smart contract, includes: obtaining a highest block of the blockchain, determining the highest block as a current block; determining a state tree corresponding to a state root node recorded in the current block; and determining key fields of the smart contract when the smart contract appends data from the state tree according to an identifier of the smart contract; continuing to determine a block corresponding to the key field of the smart contract when appending data after subtracting 1 from the determined key field of the smart contract when appending data as the current block, and determining a state tree corresponding to a state root node recorded in the current block, and determining key fields of the smart contract when the smart contract appends data from the state tree according to an identifier of the smart contract; until key fields when the smart contract is created are determined.
3. The method according to any one of claims 1 to 2, characterized in that The determining change information of the smart contract according to the key fields, and generating a change record of the smart contract, includes: parsing blocks corresponding to respective key fields according to a plurality of key fields to obtain respective change information of the smart contract; after reversing the respective change information of the smart contract, determining the reversed change information as the change record of the smart contract.
4. A tracing device for change records of a blockchain smart contract, characterized in that, including: an obtaining unit, configured to obtain a query request; the query request is used to indicate determining change records of a smart contract to be traced in the blockchain; A processing unit, configured to determine a state tree corresponding to a state tree root node recorded in a block of the blockchain; and determine keyword fields of the smart contract from the state tree according to an identifier of the smart contract; the keyword fields are used to represent a block height in which change information of the smart contract is stored in the blockchain; and determine the change information of the smart contract according to the keyword fields, and generate a change record of the smart contract; wherein the processing unit is further configured to: before obtaining the query request, receive a creation request of the smart contract; create the smart contract in the blockchain according to the creation request, generate a first block recording a transaction for creating the smart contract; and determine a block height of the first block as a keyword field when the smart contract is created, and store it in the state tree corresponding to the state tree root node of the first block; and receive an additional data request of the smart contract; write the data to be appended in the additional data request into the smart contract according to the additional data request, generate a second block recording a transaction for writing the data to be appended into the smart contract; and determine a block height of the second block as a keyword field when the smart contract appends data, and store it in the state tree corresponding to the state tree root node of the second block.
5. The device according to claim 4, characterized in that, Specifically, the processing unit is configured to: obtain a highest block of the blockchain, and determine the highest block as a current block; determine a state tree corresponding to a state tree root node recorded in the current block; and determine a keyword field when the smart contract appends data from the state tree according to the identifier of the smart contract; continue to determine the block corresponding to the keyword field when the smart contract appends data after subtracting 1 as the current block, determine a state tree corresponding to a state tree root node recorded in the current block, and determine a keyword field when the smart contract appends data from the state tree according to the identifier of the smart contract; until the keyword field when the smart contract is created is determined.
6. The device according to any one of claims 4 to 5, characterized in that, Specifically, the processing unit is configured to: parse blocks corresponding to respective keyword fields according to a plurality of keyword fields to obtain respective change information of the smart contract; after reversing the respective change information of the smart contract, determine it as a change record of the smart contract.
7. A computing device, characterized in that, including: a memory, configured to store program instructions; a processor, configured to call the program instructions stored in the memory and execute the method according to any one of claims 1 to 3 according to the obtained program.
8. A computer-readable non-volatile storage medium, characterized in that, including computer-readable instructions, when a computer reads and executes the computer-readable instructions, the computer is caused to execute the method according to any one of claims 1 to 3.
Citation Information
Patent Citations
Data structure based on block chain
CN108615156A
Block-link data storage method, device, electronic device, and storage medium
CN109063016A