Blockchain data processing method and device
By adding data acquisition instructions and operation logic to the virtual machine of the blockchain node, and using the smart contract interface code to obtain the hash value and key field information of historical transaction data, it solves the problem of smart contracts obtaining historical transaction data in the blockchain. It overcomes the difficulties and realizes the transparent transmission and execution of transaction data.
Patent Information
- Application Number
- CN202111590915.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-07-06
- Publication Date
- 2024-09-13
- Estimated Expiration
- 2041-07-06
AI Technical Summary
In blockchain technology, it is difficult for smart contracts to effectively obtain historical transaction data when executing transactions, resulting in the problem that related transactions cannot be executed through the blockchain.
Add data acquisition instructions in the virtual machine of the blockchain node and deploy the data acquisition operation logic. Obtain the transaction hash value and key field information of the historical transaction data through the interface code in the smart contract, so as to obtain the transaction hash value and key field information in the historical area of the blockchain. Query the corresponding data in the block.
It realizes that smart contracts can obtain historical transaction data from the historical blocks of the blockchain, avoiding the problem of transactions being unable to be executed due to smart contract restrictions.
Smart Images

Figure CN114327759B
Abstract
Description
[0001] This patent application is a divisional application of the Chinese patent application with application number: 202110763101.4, application date: July 6, 2021, and invention name “Blockchain data processing method and device”. Technical Field
[0002] The present application relates to the field of blockchain technology, and in particular to a method and device for processing blockchain data. Background Art
[0003] Blockchain technology is a new distributed infrastructure and computing paradigm built on a peer-to-peer network that uses chain data structures to verify and store data, distributed node consensus algorithms to generate and update data, cryptography to ensure the security of data transmission and access, and smart contracts composed of automated scripts to program and operate data.
[0004] A smart contract is a computer program that runs on a blockchain and can be used to execute transactions on the blockchain. In some cases, when executing certain transactions through smart contracts, it may be necessary to involve certain historical transaction data stored in the historical blocks of the blockchain. Therefore, it is necessary to propose a technical solution to obtain the historical transaction data required to execute transactions from the historical blocks. Summary of the invention
[0005] The embodiment of this specification provides a method for processing blockchain data. The method includes receiving an instruction to execute a target transaction on a blockchain node. According to the target transaction, the corresponding smart contract deployed on the blockchain node is called by the virtual machine of the blockchain node. Among them, the smart contract contains an interface code for obtaining historical transaction data involved in the target transaction. The transaction hash value of the historical transaction to which the historical transaction data belongs and the key field information of the historical transaction data to be queried are obtained from the interface code. The data content corresponding to the transaction hash value and the key field information is queried from the historical block of the blockchain according to the operation logic deployed in the virtual machine.
[0006] The embodiments of this specification also provide a device for processing blockchain data. The device includes a receiving module that receives an instruction to execute a target transaction on a blockchain node. The device also includes a calling module that calls the corresponding smart contract deployed on the blockchain node through the virtual machine of the blockchain node according to the target transaction. Among them, the smart contract contains an interface code for obtaining historical transaction data involved in the target transaction. The device also includes an execution module, which includes an acquisition unit and a query unit. The acquisition unit obtains the transaction hash value of the historical transaction to which the historical transaction data belongs and the key field information of the historical transaction data to be queried from the interface code. The query unit queries the data content corresponding to the transaction hash value and the key field information from the historical block of the blockchain according to the operation logic deployed in the virtual machine.
[0007] The embodiments of this specification also provide a device for processing blockchain data. The device includes: a processor and a memory arranged to store computer executable instructions, and when the executable instructions are executed, the processor receives instructions to execute a target transaction at a blockchain node. According to the target transaction, the corresponding smart contract deployed on the blockchain node is called by the virtual machine of the blockchain node. Among them, the smart contract contains an interface code for obtaining historical transaction data involved in the target transaction. The transaction hash value of the historical transaction to which the historical transaction data belongs and the key field information of the historical transaction data to be queried are obtained from the interface code. According to the operation logic deployed in the virtual machine, the data content corresponding to the transaction hash value and the key field information is queried from the historical block of the blockchain.
[0008] The embodiments of this specification also provide a storage medium. The storage medium is used to store computer executable instructions, and the executable instructions implement the following process when executed: receiving instructions to execute a target transaction on a blockchain node. According to the target transaction, the corresponding smart contract deployed on the blockchain node is called through the virtual machine of the blockchain node. Among them, the smart contract contains an interface code for obtaining historical transaction data involved in the target transaction. The transaction hash value of the historical transaction to which the historical transaction data belongs and the key field information of the historical transaction data to be queried are obtained from the interface code. According to the operation logic deployed in the virtual machine, the data content corresponding to the transaction hash value and the key field information is queried from the historical blocks of the blockchain. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] In order to more clearly illustrate the embodiments of this specification 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 recorded in this application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0010] Figure 1 A schematic diagram of the code inside the smart contract provided in the embodiment of this specification obtaining data from the historical blocks of the blockchain;
[0011] Figure 2 A schematic diagram of a first process of a method for processing blockchain data provided in an embodiment of this specification;
[0012] Figure 3 A second flow chart of the method for processing blockchain data provided in the embodiments of this specification;
[0013] Figure 4 A third flow chart of the method for processing blockchain data provided in the embodiments of this specification;
[0014] Figure 5 A schematic diagram of the module composition of a blockchain data processing device provided in an embodiment of this specification;
[0015] Figure 6 A schematic diagram of the structure of a blockchain data processing device provided in an embodiment of this specification. DETAILED DESCRIPTION
[0016] In order to enable those skilled in the art to better understand the technical solutions in this application, the technical solutions in the embodiments of this specification will be clearly and completely described below in conjunction with the drawings in the embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this application.
[0017] The idea of the embodiments of this specification is to include an interface code for obtaining the historical transaction data stored in the historical blocks involved in the transaction in the smart contract used to execute the transaction, and to add a data acquisition instruction for the historical block data and the operation logic of the acquisition operation corresponding to the data acquisition instruction to the instruction set of the virtual machine of the blockchain node; in this way, when the corresponding transaction is executed through the smart contract, when the interface code related content in the smart contract is executed, the data acquisition instruction deployed on the virtual machine is triggered to execute, so that the operation logic corresponding to the data acquisition instruction is used to query the historical transaction data involved in the transaction from the historical blocks of the blockchain node, thereby realizing that the internal code of the smart contract can obtain the historical transaction data involved in the transaction from the historical blocks of the blockchain. Based on this, the embodiments of this specification provide a method, device, equipment and storage medium for processing blockchain data.
[0018] The data in the blockchain is stored in each block in the blockchain. Therefore, when using a smart contract to execute a transaction, if the transaction involves some data of historical transactions related to the transaction, it is necessary to obtain the corresponding historical transaction data from the historical blocks of the blockchain. In a specific implementation of the embodiment of this specification, the code inside the smart contract obtains the historical transaction data from the historical blocks of the blockchain as shown in the following figure. Figure 1 shown.
[0019] The method for processing blockchain data provided in the embodiments of this specification is applied to a blockchain node, that is, the executor of the method is a blockchain node. Specifically, the executor of the method is a blockchain data processing device on the blockchain node.
[0020] Figure 2 A first flowchart of a method for processing blockchain data provided in an embodiment of this specification is provided. Figure 2 The method shown comprises at least the following steps:
[0021] Step 202, receiving an instruction to execute a target transaction at a blockchain node; wherein the execution of the target transaction involves historical transaction data stored in historical blocks of the blockchain, the instruction set of the virtual machine of the blockchain node includes a data acquisition instruction for the historical block data, and the operation logic of the data acquisition operation corresponding to the data acquisition instruction is deployed in the virtual machine.
[0022] Step 204: According to the target transaction, the corresponding smart contract deployed on the blockchain node is called through the virtual machine of the blockchain node; wherein the smart contract contains an interface code for obtaining the historical transaction data involved in the target transaction.
[0023] Step 206, triggering the execution of the data acquisition instruction deployed on the virtual machine according to the interface code in the smart contract, and using the operation logic corresponding to the data acquisition instruction to query the historical transaction data involved in the target transaction from the historical blocks of the blockchain.
[0024] It should be noted that, in the embodiments of this specification, the smart contract corresponding to the target exchange is used to execute the target transaction, and the smart contract is executed by a virtual machine. In general, when a virtual machine is required to perform certain operations, corresponding instructions need to be added to the virtual machine in advance so that the virtual machine has the corresponding functions. Therefore, an instruction set is provided on the virtual machine, which contains operation instructions corresponding to a variety of operations, and an operation logic for implementing each operation instruction is also deployed in the virtual machine. Among them, a possible form of the mapping relationship between the operation instructions and the operation logic maintained in the virtual machine is shown in Table 1.
[0025] Table 1
[0026] Instruction 1 Operation logic 1 Instruction 2 Operation logic 2 Directive 3 Operation logic 3 … … Instruction N Operation logic N
[0027] Among them, in Table 1, the operation logic corresponding to instruction 1 is operation logic 1, the operation logic corresponding to instruction 2 is operation logic 2, and the operation logic corresponding to instruction N is operation logic N. That is, the instruction content corresponding to instruction 1 can be implemented by executing operation logic 1, the instruction content corresponding to instruction 2 can be implemented by executing operation logic 2, and the instruction content corresponding to instruction N can be implemented by operation logic N. That is, in the embodiments of this specification, the operation logic is actually a specific implementation means of the instruction to which it corresponds. Among them, N in Table 1 is an arbitrary positive integer, and the above Table 1 only exemplifies a possible storage form of instructions and corresponding operation logics in a virtual machine, and does not constitute a limitation on the embodiments of this specification.
[0028] In the embodiments of this specification, in order to enable the internal code of the smart contract to obtain historical transaction data from the historical blockchain of the blockchain when it is executed, it is necessary to enable the virtual machine that executes the smart contract to have the function of obtaining data from the historical block. In specific implementation, in order to enable the virtual machine to have the function of obtaining data from the historical block of the blockchain, a data acquisition instruction for the historical block data is added to the instruction set of the virtual machine, and the operation logic of the data acquisition operation corresponding to the data acquisition instruction is deployed in the virtual machine. In this way, when the smart contract is executed through the virtual machine, the internal code of the smart contract can obtain the historical block data of the blockchain, so that some transactions involving the data of historical transactions in the historical blockchain of the blockchain can be executed through the blockchain.
[0029] In addition, in addition to adding the data acquisition instruction of the historical block data in the instruction set of the virtual machine and deploying the operation logic of the data acquisition operation corresponding to the data acquisition instruction in the virtual machine, that is, in addition to giving the virtual machine the function of acquiring historical block data, it is also necessary to define the interface code of the historical transaction data involved in the target exchange in the smart contract corresponding to the target exchange, and the interface code contains the relevant parameters for querying the historical transaction data involved in the target exchange, such as the transaction hash value of the historical transaction data involved in the target exchange and the key field information of the historical transaction data involved in the interface code. For example, in a specific implementation, the execution of the target transaction needs to rely on the time information of the last transaction with relevance. When executing the target transaction through the smart contract, the smart contract needs to obtain the time information of the last transaction with relevance from the historical block of the blockchain; accordingly, the interface code contained in the smart contract needs to carry the transaction hash value and time field of the last transaction with relevance.
[0030] It should be noted that the method provided in the embodiments of this specification can be applied to any type of smart contracts, such as Ethereum smart contracts, WASM smart contracts, and Native smart contracts.
[0031] The method for processing blockchain data provided in the embodiments of the present specification pre-incorporates into the smart contract used to execute the transaction an interface code for obtaining the historical transaction data stored in the historical blocks involved in the transaction, and adds a data acquisition instruction for the historical block data and the operation logic of the acquisition operation corresponding to the data acquisition instruction to the instruction set of the virtual machine of the blockchain node; in this way, when the corresponding transaction is executed through the smart contract, when the relevant content of the interface code in the smart contract is executed, the data acquisition instruction deployed on the virtual machine is triggered to execute, so that the operation logic corresponding to the data acquisition instruction is used to query the historical transaction data involved in the transaction from the historical blocks of the blockchain node, thereby realizing that the internal code of the smart contract can obtain the historical transaction data involved in the transaction from the historical blocks of the blockchain, that is, the smart contract can obtain the historical transaction data from the historical blockchain, avoiding the problem of being unable to execute related transactions through the blockchain due to the inability to obtain data in the historical blocks due to the limitation of the smart contract.
[0032] Therefore, in the embodiment of this specification, in order to enable the smart contract to obtain the historical transaction data involved in the target transaction from the historical blocks of the blockchain, before executing the method provided in the embodiment of this specification, the corresponding interface code needs to be compiled into the smart contract. That is, before executing the above step 202 and receiving the instruction to execute the target transaction on the blockchain node, the method provided in the embodiment of this specification also includes the following steps:
[0033] When compiling the smart contract corresponding to the target exchange, the interface code is compiled into the smart contract.
[0034] Optionally, after the smart contract obtains the historical transaction data involved in the target transaction through the method provided in the embodiments of this specification, the blockchain node executes the interface code to perform execution processing of the target transaction, such as consensus processing, thereby realizing the transparent transmission of historical transaction data stored in the historical blocks of the blockchain.
[0035] To facilitate understanding of the method provided in the embodiments of this specification, the above scheme will be described in detail below.
[0036] Optionally, in a specific implementation, the above step 206 triggers the execution of a data acquisition instruction deployed on the virtual machine according to the interface code in the smart contract, and uses the operation logic corresponding to the data acquisition instruction to query the historical transaction data involved in the target transaction from the historical blocks of the blockchain, specifically including the following process:
[0037] Obtain the transaction hash value of the historical transaction to which the historical transaction data belongs and the key field information of the historical transaction data to be queried from the interface code; based on the above transaction hash value and key field information, query the data content corresponding to the above transaction hash value and key field information from the historical block of the blockchain according to the above operation logic.
[0038] It should be noted that when the target transaction is executed, it may only involve one or several parameter data in the historical transaction data associated with it, rather than all the historical transaction data of the historical transaction. For example, when the target transaction is executed, it may only involve the transaction party, transaction timestamp and other information in the historical transaction data associated with it; therefore, in order to enable the internal code of the smart contract to accurately obtain the data required by the target transaction when the target transaction is executed through the smart contract, the interface code defined in the smart contract needs to contain the transaction hash value corresponding to the historical transaction data involved in the target transaction and the specific key field information required to be queried. In this way, based on the transaction hash value and key field information contained in the interface code, the corresponding data content is queried from the historical block of the blockchain according to the operation logic corresponding to the data acquisition instruction deployed on the virtual machine.
[0039] Optionally, in some specific implementations, based on the transaction hash value and the key field information, querying the data content corresponding to the transaction hash value and the key field information from the historical blocks of the blockchain according to the above operation logic can be specifically implemented by the following steps:
[0040] Find out whether the target block number corresponding to the above transaction hash value exists in the pre-established mapping relationship between each hash value and block number; if so, check whether the target block number is within the preset queryable block range; if so, search the block data corresponding to the target block number for the data content corresponding to the above transaction hash value and key field information.
[0041] The block number may specifically be a block number, a block identifier, etc.
[0042] Optionally, in the embodiments of the present specification, a mapping relationship between the hash value corresponding to each historical transaction and the block where the corresponding historical transaction data is located can be established in advance. A possible form is shown in Table 2.
[0043] Table 2
[0044] Hash value Block number Hash1 Block 2 Hash2 Block 3 Hash3 Block 1 Hash 4 Block 2
[0045] Among them, the mapping relationship between each hash value and the corresponding block number is stored in the above mapping relationship, which can actually be understood as the transaction data of the transaction corresponding to the hash value is stored in the corresponding block. As shown in Table 2, it indicates that the transaction data of the transaction corresponding to Hash1 is stored in block 2, the transaction data of the transaction corresponding to Hash2 is stored in block 3, and so on. For example, for the scheme provided in the embodiment of this specification, when it is implemented, after obtaining the transaction hash value corresponding to the target exchange from the interface code contained in the smart contract corresponding to the target exchange, the obtained transaction hash value is matched with the above Table 2, and firstly, it is checked whether there is a transaction hash value consistent with the transaction hash value in the above Table 2. If there is, the block number corresponding to the transaction hash value is determined, and it is judged whether the block number is within the queryable block number range. If so, the transaction content to be queried is searched from the block corresponding to the block number based on the transaction hash value and the key field information.
[0046] Optionally, in a specific implementation, the execution of the above-mentioned target transaction involves historical transaction data of historical transactions stored in historical blocks of the blockchain and having the same transaction type as the target transaction;
[0047] Accordingly, in this case, based on the transaction hash value and key field information, the data content corresponding to the transaction hash value and key field information is queried from the historical blocks of the blockchain according to the above operation logic, which can be specifically implemented through the following steps:
[0048] Find out whether the target block number corresponding to the above transaction hash value exists in the pre-established mapping relationship between each hash value and the block number; if so, check whether the target block number is within the preset queryable block range; if so, search the historical transaction data of the historical transaction that matches the transaction type of the target transaction from the block data of the block corresponding to the target block number; determine the data content corresponding to the above transaction hash value and key field information from the matching historical transaction data.
[0049] Among them, in the embodiment of the present specification, the block corresponding to the target block number may store historical transaction data corresponding to multiple historical exchanges. Therefore, in order to further narrow the scope of data query based on transaction hash value and key field information and reduce the workload of data query, after determining that the target block number is within the preset queryable block range, the historical transaction data in the block corresponding to the target block number can be screened based on the transaction type. Specifically, the historical transaction data corresponding to the historical exchange with the same transaction type as the target transaction can be found from the block data of the block corresponding to the target block number. In this way, when determining the content of the queried data based on the transaction hash value and key field information, it is only necessary to query the data from the historical transaction data with the same transaction type as the target transaction in the block corresponding to the target block number.
[0050] Optionally, in a specific implementation, the above transaction types can be divided based on the object of the transaction, or based on the business type involved in the transaction, such as transactions generated by processing business and executed on the blockchain. If the businesses corresponding to the two exchanges have the same business type, such as both are goods trading business, or both are product leasing business, then the transaction types of the two transactions can be considered to be the same. Of course, the transaction types can also be divided based on the attributes of the transaction, such as transactions involving resource transfers on the blockchain can be considered to have the same transaction type. The embodiments of this specification do not limit this.
[0051] Generally, relevant personnel will archive the data stored in the blockchain regularly or irregularly, and the archived data cannot be queried. Therefore, the above-mentioned preset queryable block range can actually be understood as the block that has not been archived. Therefore, in a specific implementation, the above-mentioned verification of whether the target block number is within the preset queryable block range can be implemented in the following way:
[0052] Verify whether the block corresponding to the target block number is a block for which block data has been archived; if so, determine that the target block number exceeds the queryable block range; otherwise, determine that the target block number is within the queryable block range.
[0053] Optionally, when it is implemented, the block number of the block that has been archived may be pre-recorded, the target block number is matched with the block number that has been archived, and it is verified whether the target block number exists in the block number that has been archived. If the target block number exists in the block number that has been archived, it is determined that the block corresponding to the target block number is a block that has been archived. At this time, it can be determined that the target block number has exceeded the queryable block range; if the verification result indicates that the target block number does not exist in the block number that has been archived, it is determined that the block corresponding to the target block number is a block that has not been archived. In this case, it can be determined that the target block number is within the queryable block range.
[0054] Of course, in addition to the above verification method, in the embodiment of this specification, the queryable transaction time range can also be divided based on the transaction time, and the target block number can be verified based on the queryable transaction time range. Therefore, in a specific implementation, it is also possible to verify whether the target block number is within the preset queryable block range through the following process:
[0055] Verify whether the timestamp of the block data of the block corresponding to the target block number is within the timestamp range corresponding to the queryable historical exchange; if so, determine that the target block number is within the queryable block range.
[0056] That is, in a specific implementation, the queryable block range can be delineated based on the timestamps corresponding to the historical exchanges. For example, the timestamp range corresponding to the historical exchanges that have completed consensus in the blockchain and have not been archived can be determined as the queryable timestamp range; if the timestamp of the block data in the block corresponding to the target block number is within the queryable timestamp range, it can be determined that the target block number is within the queryable block range; otherwise, it is determined that the target block number exceeds the queryable block range.
[0057] In addition, in the embodiment of this specification, the data query status corresponding to each historical exchange can also be set, and then the historical transaction data involved in the target exchange can be queried according to the data query status corresponding to each historical exchange; therefore, in a specific implementation, the method provided in the embodiment of this specification also includes the following steps:
[0058] Determine the historical transactions that have been executed and completed in the blockchain node and whose transaction status is valid, and set the data query status information corresponding to the historical transactions to the queryable status;
[0059] Accordingly, in this case, the above-mentioned searching for the data content corresponding to the transaction hash value and the key field information from the block data of the block corresponding to the target block number specifically includes the following process:
[0060] Search the historical transaction data of the historical transaction corresponding to the above transaction hash value from the block data of the block corresponding to the target block number; verify whether the data query status information corresponding to the historical transaction is in a queryable state; if so, query the data content corresponding to the above key field information from the historical transaction data.
[0061] It should be noted that, in the embodiments of this specification, the data query status information corresponding to the historical exchange can be represented in the form of a status value. For example, when the status value is 1, it indicates that the historical transaction data corresponding to the historical exchange is in a queryable state, and when the status value is 0, it indicates that the historical transaction data corresponding to the historical exchange is in a non-queryable state.
[0062] Optionally, since the blockchain has the property that data cannot be tampered with, in a specific implementation, when the data query status information corresponding to the historical exchange needs to be changed, the new data query status information and change time corresponding to the historical exchange can be directly recorded in the blockchain. In this way, when performing data query, the data query status corresponding to the most recent change time of the historical transaction is used as the data query status corresponding to the historical exchange. For example, the data query status corresponding to historical transaction A is: 18:06:25 on November 3, 2020, the data query status value is 0; 19:08:27 on November 3, 2020, the data query status value is 1; therefore, when performing data query, the data query status 1 is used as the data query status information corresponding to historical transaction A.
[0063] In addition, it should be noted that in the embodiments of this specification, the above key field information includes one or more of the following field information:
[0064] Transaction sender, transaction receiver, transaction timestamp, transaction data, and storage location information.
[0065] Optionally, in specific implementation, the above transaction data can be understood as the transaction content of the transaction, such as transaction amount, transaction location, transaction object, etc.
[0066] To facilitate understanding of the method provided in the embodiments of this specification, the method provided in the embodiments of this specification will be introduced below using the historical transaction data involved in the target transaction as the transaction sender as an example. Figure 3 A second flow chart of the blockchain data processing method provided in the embodiment of this specification, Figure 3 The method shown comprises at least the following steps:
[0067] Step 302, receiving an instruction to execute a target transaction on a blockchain node.
[0068] Step 304: Call the corresponding smart contract deployed on the blockchain node through the virtual machine of the blockchain node.
[0069] Step 306, executing the above-mentioned smart contract through a virtual machine, and obtaining the transaction hash value and key field information of the historical transaction to which the historical transaction data involved in the target transaction belongs from the interface code contained in the smart contract.
[0070] Step 308, based on the pre-established mapping relationship between hash values and block numbers, check whether there is a target block number corresponding to the transaction hash value; if so, execute step 310; otherwise, end.
[0071] Step 310, check whether the target block number is within the preset queryable block range; if so, execute step 312, otherwise, end.
[0072] Step 312: query the corresponding data content in the block corresponding to the block number based on the transaction hash value and key field information.
[0073] Step 314, executing the target transaction based on the queried data content.
[0074] Figure 4 A third flow chart of the blockchain data processing method provided in the embodiment of this specification is shown. Figure 4 In the flowchart shown, the historical transaction data involved in the target transaction is taken as an example of the transaction recipient to introduce the method provided in the embodiment of this specification. Figure 4 The method shown comprises at least the following steps:
[0075] Step 402, receiving an instruction to execute a target transaction on a blockchain node.
[0076] Step 404: Call the corresponding smart contract deployed on the blockchain node through the virtual machine of the blockchain node.
[0077] Step 406, executing the above-mentioned smart contract through a virtual machine, and obtaining the transaction hash value and key field information of the historical transaction to which the historical transaction data involved in the target transaction belongs from the interface code contained in the smart contract.
[0078] Step 408, based on the pre-established mapping relationship between hash values and block numbers, check whether there is a target block number corresponding to the transaction hash value; if so, execute step 410; otherwise, end.
[0079] Step 410 , checking whether the block corresponding to the target block number is a block for which data has been archived; if so, the process ends; otherwise, executing step 412 .
[0080] Step 412: Search the block data of the block corresponding to the target block number for historical transaction data corresponding to the historical transaction that matches the transaction type of the target transaction.
[0081] Step 414: query corresponding data content in the above-mentioned matching historical transaction data based on the above-mentioned transaction hash value and key field information.
[0082] Step 416, executing the target transaction based on the queried data content.
[0083] The method for processing blockchain data provided in the embodiments of this specification incorporates an interface code for obtaining historical transaction data involved in the transaction into a smart contract, and adds a data acquisition instruction for historical block data and an operation logic for the acquisition operation corresponding to the data acquisition instruction to the instruction set of the virtual machine of the blockchain node; in this way, when a transaction is executed through a blockchain node, the smart contract corresponding to the target exchange is called, and when the relevant content of the interface code in the smart contract is executed, the data acquisition instruction deployed on the virtual machine is triggered to execute, thereby using the operation logic corresponding to the data acquisition instruction to query the historical transaction data involved in the transaction from the historical block of the blockchain node, that is, the smart contract can obtain historical transaction data from the historical blockchain, which solves the problem that the relevant transactions cannot be executed through the blockchain due to the limitation of the smart contract, which makes it impossible to obtain data in the historical block within the smart contract.
[0084] Corresponding to the blockchain data processing method provided in the embodiments of this specification, based on the same idea, the embodiments of this specification also provide a blockchain data processing device for executing the blockchain data processing method provided in the embodiments of this specification. Figure 5 A schematic diagram of the module composition of the blockchain data processing device provided in the embodiment of this specification, Figure 5 The device shown includes:
[0085] A receiving module 502 receives an instruction to execute a target transaction in a blockchain node; wherein the execution of the target transaction involves historical transaction data stored in a historical block of the blockchain; the instruction set of the virtual machine of the blockchain node includes a data acquisition instruction for the historical block data, and the operation logic of the data acquisition operation corresponding to the data acquisition instruction is deployed in the virtual machine;
[0086] A calling module 504, according to the target transaction, calls the corresponding smart contract deployed on the blockchain node through the virtual machine of the blockchain node; wherein the smart contract contains an interface code for obtaining the historical transaction data involved in the target transaction;
[0087] The execution module 506 triggers the execution of the data acquisition instruction deployed on the virtual machine according to the interface code in the smart contract, and uses the operation logic corresponding to the data acquisition instruction to query the historical transaction data involved in the target transaction from the historical blocks of the blockchain.
[0088] Among them, the blockchain data processing device provided in the embodiments of this specification can realize Figure 1-Figure 4 All the steps of the method for processing blockchain data provided by the illustrated embodiment will not be repeated here.
[0089] The blockchain data processing device provided in the embodiments of the present specification incorporates an interface code for obtaining the historical transaction data involved in the transaction into the smart contract, and adds a data acquisition instruction for the historical block data and the operation logic of the acquisition operation corresponding to the data acquisition instruction to the instruction set of the virtual machine of the blockchain node; in this way, when executing a transaction through the blockchain node, the smart contract corresponding to the target exchange is called, and when the relevant content of the interface code in the smart contract is executed, the data acquisition instruction deployed on the virtual machine is triggered to execute, so that the operation logic corresponding to the data acquisition instruction is used to query the historical transaction data involved in the transaction from the historical block of the blockchain node, that is, the smart contract can obtain the historical transaction data from the historical blockchain, which solves the problem that the relevant transactions cannot be executed through the blockchain due to the limitation of the smart contract, which makes it impossible to obtain the data in the historical block within the smart contract.
[0090] Furthermore, based on the above Figures 1 to 4 The method shown in this specification also provides a blockchain data processing device, such as Figure 6 shown.
[0091] The processing device of blockchain data may have relatively large differences due to different configurations or performances, and may include one or more processors 601 and memory 602, and the memory 602 may store one or more storage applications or data. Among them, the memory 602 may be a short-term storage or a persistent storage. The application stored in the memory 602 may include one or more modules (not shown in the figure), and each module may include a series of computer executable instruction information in the processing device of blockchain data. Furthermore, the processor 601 may be configured to communicate with the memory 602, and execute a series of computer executable instruction information in the memory 602 on the processing device of blockchain data. The processing device of blockchain data may also include one or more power supplies 603, one or more wired or wireless network interfaces 604, one or more input and output interfaces 605, one or more keyboards 606, etc.
[0092] In a specific embodiment, a blockchain data processing device includes a memory and one or more programs, wherein the one or more programs are stored in the memory, and the one or more programs may include one or more modules, and each module may include a series of computer executable instruction information in the blockchain data processing device, and the one or more programs are configured to be executed by one or more processors, including computer executable instruction information for performing the following:
[0093] Receiving an instruction to execute a target transaction at a blockchain node; wherein the execution of the target transaction involves historical transaction data stored in a historical block of the blockchain; the instruction set of the virtual machine of the blockchain node includes a data acquisition instruction for the historical block data, and the operation logic of the data acquisition operation corresponding to the data acquisition instruction is deployed in the virtual machine;
[0094] According to the target transaction, the corresponding smart contract deployed on the blockchain node is called by the virtual machine of the blockchain node; wherein the smart contract contains an interface code for obtaining the historical transaction data involved in the target transaction;
[0095] The data acquisition instruction deployed on the virtual machine is executed according to the interface code in the smart contract, and the operation logic corresponding to the data acquisition instruction is used to query the historical transaction data involved in the target transaction from the historical blocks of the blockchain.
[0096] Among them, the blockchain data processing device provided in the embodiments of this specification can realize Figure 1-Figure 4 All the steps of the method for processing blockchain data provided by the illustrated embodiment will not be repeated here.
[0097] The blockchain data processing device provided in the embodiments of the present specification incorporates an interface code for obtaining the historical transaction data involved in the transaction into the smart contract, and adds a data acquisition instruction for the historical block data and the operation logic of the acquisition operation corresponding to the data acquisition instruction to the instruction set of the virtual machine of the blockchain node; in this way, when executing a transaction through the blockchain node, the smart contract corresponding to the target exchange is called, and when the relevant content of the interface code in the smart contract is executed, the data acquisition instruction deployed on the virtual machine is triggered to execute, so as to use the operation logic corresponding to the data acquisition instruction to query the historical transaction data involved in the transaction from the historical block of the blockchain node, that is, the smart contract can obtain the historical transaction data from the historical blockchain, which solves the problem that the relevant transactions cannot be executed through the blockchain due to the limitation of the smart contract, which makes it impossible to obtain the data in the historical block within the smart contract.
[0098] Furthermore, based on the above Figures 1 to 4 The method shown in the specification also provides a storage medium for storing computer executable instruction information. In a specific embodiment, the storage medium can be a USB flash drive, an optical disk, a hard disk, etc. When the computer executable instruction information stored in the storage medium is executed by the processor, the following process can be implemented:
[0099] Receiving an instruction to execute a target transaction at a blockchain node; wherein the execution of the target transaction involves historical transaction data stored in a historical block of the blockchain; the instruction set of the virtual machine of the blockchain node includes a data acquisition instruction for the historical block data, and the operation logic of the data acquisition operation corresponding to the data acquisition instruction is deployed in the virtual machine;
[0100] According to the target transaction, the corresponding smart contract deployed on the blockchain node is called by the virtual machine of the blockchain node; wherein the smart contract contains an interface code for obtaining the historical transaction data involved in the target transaction;
[0101] The data acquisition instruction deployed on the virtual machine is executed according to the interface code in the smart contract, and the operation logic corresponding to the data acquisition instruction is used to query the historical transaction data involved in the target transaction from the historical blocks of the blockchain.
[0102] The computer executable instruction information stored in the storage medium provided in the embodiments of this specification can be implemented when executed by the processor. Figure 1-Figure 4 All the method steps of the illustrated embodiment will not be repeated here.
[0103] When the computer executable instruction information stored in the storage medium provided in the embodiments of this specification is executed by the processor, an interface code for obtaining the historical transaction data involved in the transaction is compiled into the smart contract, and a data acquisition instruction for the historical block data and the operation logic of the acquisition operation corresponding to the data acquisition instruction are added to the instruction set of the virtual machine of the blockchain node; in this way, when the transaction is executed through the blockchain node, the smart contract corresponding to the target exchange is called, and when the relevant content of the interface code in the smart contract is executed, the data acquisition instruction deployed on the virtual machine is triggered to execute, so that the operation logic corresponding to the data acquisition instruction is used to query the historical transaction data involved in the transaction from the historical block of the blockchain node, that is, the smart contract can obtain the historical transaction data from the historical blockchain, which solves the problem that the smart contract cannot obtain the data in the historical block due to the limitation of the smart contract, so that the relevant transaction cannot be executed through the blockchain.
[0104] In the 1990s, improvements to a technology could be clearly distinguished as hardware improvements (for example, improvements to the circuit structure of diodes, transistors, switches, etc.) or software improvements (improvements to the method flow). However, with the development of technology, many improvements to the method flow today can be regarded as direct improvements to the hardware circuit structure. Designers almost always obtain the corresponding hardware circuit structure by programming the improved method flow into the hardware circuit. Therefore, it cannot be said that an improvement in a method flow cannot be implemented using a hardware entity module. For example, a programmable logic device (PLD) (such as a field programmable gate array (FPGA)) is such an integrated circuit whose logical function is determined by the user's programming of the device. Designers can "integrate" a digital system on a PLD by programming it themselves, without having to ask a chip manufacturer to design and produce a dedicated integrated circuit chip. Moreover, nowadays, instead of manually making integrated circuit chips, this kind of programming is mostly implemented by "logic compiler" software, which is similar to the software compiler used when developing and writing programs, and the original code before compilation must also be written in a specific programming language, which is called hardware description language (HDL). There is not only one HDL, but many kinds, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, RHDL (Ruby Hardware Description Language), etc. The most commonly used ones are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should also know that it is only necessary to program the method flow slightly in the above-mentioned hardware description languages and program it into the integrated circuit, and then it is easy to obtain the hardware circuit that implements the logic method flow.
[0105] The controller can be implemented in any appropriate manner, for example, the controller can take the form of a microprocessor or processor and a computer-readable medium storing a computer-readable program code (such as software or firmware) that can be executed by the (micro)processor, a logic gate, a switch, an application-specific integrated circuit (ASIC), a programmable logic controller, and an embedded microcontroller. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320. The memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art also know that in addition to implementing the controller in a purely computer-readable program code manner, the controller can be implemented in the form of a logic gate, a switch, an application-specific integrated circuit, a programmable logic controller, and an embedded microcontroller by logically programming the method steps. Therefore, this controller can be considered as a hardware component, and the devices included therein for implementing various functions can also be regarded as structures within the hardware component. Or even, the devices for implementing various functions can be regarded as both software modules for implementing the method and structures within the hardware component.
[0106] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, the computer may be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
[0107] For the convenience of description, the above device is described in terms of functions and is described separately in various units. Of course, when implementing the present application, the functions of each unit can be implemented in the same or multiple software and / or hardware.
[0108] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0109] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present specification. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instruction information. These computer program instruction information 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 instruction information executed by the processor of the computer or other programmable data processing device generates a method for implementing the process in the flowchart. 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.
[0110] These computer program instruction information can also be stored in a computer readable memory that can guide a computer or other programmable data processing device to work in a specific manner, so that the instruction information stored in the computer readable memory produces a manufactured product including an instruction information 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.
[0111] These computer program instruction information can also be loaded into a computer or other programmable data processing device so that a series of operation steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instruction information executed on the computer or other programmable device for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0112] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0113] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0114] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instruction information, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0115] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0116] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0117] The present application may be described in the general context of computer-executable instruction information executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules may be located in local and remote computer storage media, including storage devices.
[0118] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0119] The above is only an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.
Claims
1. A method for processing blockchain data, include: Receive instructions to execute target transactions on blockchain nodes; According to the target transaction, the corresponding smart contract deployed on the blockchain node is called by the virtual machine of the blockchain node; wherein the smart contract contains an interface code for obtaining historical transaction data involved in the target transaction; Acquire the transaction hash value of the historical transaction to which the historical transaction data belongs and the key field information of the historical transaction data to be queried from the interface code; The data acquisition instruction deployed on the virtual machine is executed according to the interface code trigger, and the data content corresponding to the transaction hash value and the key field information is queried from the historical blocks of the blockchain using the operation logic corresponding to the data acquisition instruction.
2. The method according to claim 1, wherein the data content corresponding to the transaction hash value and the key field information is queried from the historical blocks of the blockchain, include: Find out whether the target block number corresponding to the transaction hash value exists in the pre-established mapping relationship between each hash value and the block number; If so, check whether the target block number is within the preset queryable block range; If so, search the block data of the block corresponding to the target block number for the data content corresponding to the transaction hash value and the key field information.
3. The method of claim 1, wherein the execution of the target transaction involves historical transaction data of historical transactions stored in historical blocks of the blockchain and having the same transaction type as the target transaction; Accordingly, the data content corresponding to the transaction hash value and the key field information is queried from the historical blocks of the blockchain according to the operation logic deployed in the virtual machine. include: Find out whether the target block number corresponding to the transaction hash value exists in the pre-established mapping relationship between each hash value and the block number; If so, check whether the target block number is within the preset queryable block range; If yes, searching the block data of the block corresponding to the target block number for historical transaction data of a historical transaction matching the transaction type of the target transaction; The data content corresponding to the transaction hash value and the key field information is determined from the matching historical transaction data.
4. The method according to claim 2 or 3, wherein the step of checking whether the target block number is within a preset queryable block range is: include: Verify whether the block corresponding to the target block number is a block for which block data has been archived; If yes, it is determined that the target block number exceeds the queryable block range; Otherwise, it is determined that the target block number is within the queryable block range.
5. The method according to claim 2 or 3, wherein the method further comprises: include: Determine the historical transactions that have been executed and completed in the blockchain node and whose transaction status is valid, and set the data query status information corresponding to the historical transactions to a queryable state; The searching the data content corresponding to the transaction hash value and the key field information from the block data of the block corresponding to the target block number includes: Searching for historical transaction data of the historical transaction corresponding to the transaction hash value from the block data of the block corresponding to the target block number; Verify whether the data query status information corresponding to the historical transaction is in a queryable state; If so, the data content corresponding to the key field information is queried from the historical transaction data.
6. The method according to claim 2 or 3, wherein the step of checking whether the target block number is within a preset queryable block range is: include: Verify whether the timestamp of the block data of the block corresponding to the target block number is within the timestamp range corresponding to the queryable historical exchange; If yes, it is determined that the target block number is within the queryable block range.
7. The method according to claim 1, wherein the key field information includes one or more of the following field information: Transaction sender, transaction receiver, transaction timestamp, transaction data, and storage location information.
8. The method of claim 1, wherein before receiving the instruction to execute the target transaction at the blockchain node, the method further comprises: include: When compiling the smart contract corresponding to the target exchange, the interface code is compiled into the smart contract.
9. A blockchain data processing device, include: A receiving module receives instructions for executing a target transaction on a blockchain node; A calling module, according to the target transaction, calls the corresponding smart contract deployed on the blockchain node through the virtual machine of the blockchain node; wherein the smart contract contains an interface code for obtaining the historical transaction data involved in the target transaction; The execution module includes an acquisition unit and a query unit; the acquisition unit acquires the transaction hash value of the historical transaction to which the historical transaction data belongs and the key field information of the historical transaction data to be queried from the interface code; the query unit triggers the execution of the data acquisition instruction deployed on the virtual machine according to the interface code, and uses the operation logic corresponding to the data acquisition instruction to query the data content corresponding to the transaction hash value and the key field information from the historical blocks of the blockchain.
10. The device according to claim 9, wherein the query unit is specifically configured to: Find out whether the target block number corresponding to the transaction hash value exists in the pre-established mapping relationship between each hash value and the block number; if so, check whether the target block number is within the preset queryable block range; if so, search the block data of the block corresponding to the target block number for the data content corresponding to the transaction hash value and the key field information.
11. The apparatus of claim 9, wherein the execution of the target transaction involves historical transaction data of historical transactions stored in historical blocks of a blockchain and having the same transaction type as the target transaction; Accordingly, the query unit is further specifically used for: Find out whether the target block number corresponding to the transaction hash value exists in the pre-established mapping relationship between each hash value and the block number; if so, check whether the target block number is within a preset queryable block range; if so, search for historical transaction data of historical transactions matching the transaction type of the target transaction from the block data of the block corresponding to the target block number; determine the data content corresponding to the transaction hash value and the key field information from the matching historical transaction data.
12. The device according to claim 10 or 11, wherein the query unit is further configured to: Verify whether the block corresponding to the target block number is a block for which block data has been archived; If yes, it is determined that the target block number is beyond the queryable block range; otherwise, it is determined that the target block number is within the queryable block range.
13. The device according to claim 10 or 11, wherein the device further comprises: include: A setting module is used to determine the historical transactions that have been executed and completed in the blockchain node and whose transaction status is valid, and set the data query status information corresponding to the historical transactions to a queryable state; Accordingly, the query unit is further specifically used for: Search the historical transaction data of the historical transaction corresponding to the transaction hash value from the block data of the block corresponding to the target block number; verify whether the data query status information corresponding to the historical transaction is in a queryable state; if so, query the data content corresponding to the key field information from the historical transaction data.
14. The device according to claim 10 or 11, wherein the query unit is further configured to: Verify whether the timestamp corresponding to the block data of the block corresponding to the target block number is within the timestamp range corresponding to the queryable historical exchange; if so, determine that the target block number is within the queryable block range.
15. The apparatus according to claim 9, wherein the key field information comprises one or more of the following field information: Transaction sender, transaction receiver, transaction timestamp, transaction data, and storage location information.
16. The device according to claim 9, further comprising: include: The compiling module compiles the interface code into the smart contract when compiling the smart contract corresponding to the target exchange.
17. A blockchain data processing device, include: processor; as well as a memory arranged to store computer executable instructions which, when executed, cause the processor to: Receive instructions to execute target transactions on blockchain nodes; According to the target transaction, the corresponding smart contract deployed on the blockchain node is called by the virtual machine of the blockchain node; wherein the smart contract contains an interface code for obtaining historical transaction data involved in the target transaction; Acquire the transaction hash value of the historical transaction to which the historical transaction data belongs and the key field information of the historical transaction data to be queried from the interface code; The data acquisition instruction deployed on the virtual machine is executed according to the interface code trigger, and the data content corresponding to the transaction hash value and the key field information is queried from the historical blocks of the blockchain using the operation logic corresponding to the data acquisition instruction.
18. A storage medium for storing computer executable instructions, wherein the executable instructions implement the following process when executed: Receive instructions to execute target transactions on blockchain nodes; According to the target transaction, the corresponding smart contract deployed on the blockchain node is called by the virtual machine of the blockchain node; wherein the smart contract contains an interface code for obtaining historical transaction data involved in the target transaction; Acquire the transaction hash value of the historical transaction to which the historical transaction data belongs and the key field information of the historical transaction data to be queried from the interface code; The data acquisition instruction deployed on the virtual machine is executed according to the interface code trigger, and the data content corresponding to the transaction hash value and the key field information is queried from the historical blocks of the blockchain using the operation logic corresponding to the data acquisition instruction.
