Method, apparatus and blockchain node for querying data in a blockchain system
By deploying smart contracts in a blockchain system to generate and query audit logs, the problem of user query behavior not being recorded and audited is solved, data security is improved, and privacy data leakage is prevented.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ANT BLOCKCHAIN TECHNOLOGY (SHANGHAI) CO LTD
- Filing Date
- 2022-11-30
- Publication Date
- 2026-07-10
AI Technical Summary
In existing blockchain systems, user data query behavior cannot be recorded and audited, which may lead to the malicious querying or theft of private data, resulting in a lack of security.
By deploying smart contracts in the blockchain system, a first function is used to generate audit logs to record query behavior, and a second function is used to query the audit logs based on index information, ensuring that query behavior is traceable and auditable, and preventing the leakage of privacy data.
It enables traceability and auditing of user query behavior, improves the data security of the blockchain system, and prevents private data from being maliciously queried or stolen.
Smart Images

Figure CN116126966B_ABST
Abstract
Description
Technical Field
[0001] The embodiments in this specification pertain to the field of blockchain, and particularly relate to a method, apparatus, and blockchain node for querying data in a blockchain system. Background Technology
[0002] Blockchain is a novel application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanisms, and cryptographic algorithms. In a blockchain system, data blocks are sequentially linked together to form a chain-like data structure, and a distributed ledger is cryptographically guaranteed to be immutable and unforgeable. Due to its decentralized, immutable, and autonomous characteristics, blockchain is receiving increasing attention and application. Summary of the Invention
[0003] The purpose of this invention is to provide a method, apparatus, and blockchain node for querying data in a blockchain system.
[0004] Firstly, a method for querying data in a blockchain system is provided, wherein a smart contract is deployed in the blockchain system, the smart contract including a first function and a second function, and the method is executed by a blockchain node in the blockchain system. The method includes: receiving a first transaction for invoking the first function, the first transaction indicating a key to be queried; executing the first function according to the first transaction to: adding an audit log to the contract state of the smart contract, the audit log including a first account initiating the first transaction, the key to be queried, and the value of the key to be queried, and returning a transaction receipt of the first transaction to the user device that sent the first transaction, the transaction receipt including index information of the audit log; receiving a second transaction for invoking the second function, the second transaction including the index information; executing the second function according to the second transaction to: querying the audit log in the contract state of the smart contract according to the index information, and, if it is determined that the account initiating the second transaction is the first account included in the audit log, returning the value of the key to be queried included in the audit log to the user device that sent the first transaction.
[0005] Secondly, a method for querying data in a blockchain system is provided, wherein the blockchain system deploys a smart contract, the smart contract including a first function and a second function, and the method is executed by a user device. The method includes: sending a first transaction to the blockchain system for invoking the first function, the first transaction indicating the key to be queried, causing the blockchain system to add an audit log to the contract state of the smart contract, the audit log including a first account initiating the first transaction, the key to be queried, and the value of the key to be queried, and returning a transaction receipt of the first transaction, the transaction receipt including index information of the audit log; sending a second transaction to the blockchain system for invoking the second function, the second transaction including the index information, causing the blockchain system to query the audit log according to the index information, and, if it is determined that the account initiating the second transaction is the first account included in the audit log, returning the value of the key to be queried included in the audit log.
[0006] Thirdly, a blockchain node for a blockchain system is provided, wherein a smart contract is deployed in the blockchain system, the smart contract including a first function and a second function, and the blockchain node includes: a transaction receiving unit configured to receive a first transaction for calling the first function, the first transaction indicating a key to be queried; a transaction execution unit configured to execute the first function according to the first transaction, thereby: adding an audit log to the contract state of the smart contract, the audit log including a first account initiating the first transaction, the key to be queried, and the value of the key to be queried, and returning a transaction receipt of the first transaction to the user device that sent the first transaction, the transaction receipt including index information of the audit log; the transaction receiving unit is further configured to receive a second transaction for calling the second function, the second transaction including the index information; the transaction execution unit is further configured to execute the second function according to the second transaction, thereby: querying the audit log in the contract state of the smart contract according to the index information, and if it is determined that the account initiating the second transaction is the first account included in the audit log, returning the value of the key to be queried included in the audit log to the user device that sent the first transaction.
[0007] Fourthly, an apparatus for querying data in a blockchain system is provided, wherein a smart contract is deployed in the blockchain system, the smart contract including a first function and a second function, and the apparatus is deployed in a user device. The apparatus includes: a communication processing unit configured to send a first transaction to the blockchain system for calling the first function, the first transaction indicating a key to be queried, causing the blockchain system to add an audit log to the contract state of the smart contract, the audit log including a first account initiating the first transaction, the key to be queried, and the value of the key to be queried, and returning a transaction receipt of the first transaction, the transaction receipt including index information of the audit log; the communication processing unit is further configured to send a second transaction to the blockchain system for calling the second function, the second transaction including the index information, causing the blockchain system to query the audit log according to the index information, and, if it is determined that the account initiating the second transaction is the first account included in the audit log, returning the value of the key to be queried included in the audit log.
[0008] In the embodiments of this specification, when a user wants to query the value of a key from the blockchain system via a user device, they can use the user device to send a first transaction to the blockchain system to call a first function in a smart contract. This causes the blockchain system to generate an audit log corresponding to the first transaction in the smart contract's contract state. The audit log includes the user's registered account in the blockchain system used to initiate the first transaction, the key to be queried, and the value of the key. The system then returns a transaction receipt containing a log index to the user device. Next, the user can use the user device to initiate a second transaction to the blockchain system, containing the aforementioned index information and used to call a second function in the smart contract. This allows the blockchain system to query the corresponding audit log based on the index information. If, based on the audit log, it determines that the accounts initiating the first and second transactions are the same, the system returns the value of the key already recorded in the audit log to the user device. In this way, the user's data query behavior from the blockchain system can be recorded in the blockchain system in the form of an audit log, ensuring that the user's data query behavior can be traced and audited, preventing malicious querying / theft of private data in the blockchain system, and improving the security of data in the blockchain. Attached Figure Description
[0009] To more clearly illustrate the technical solutions of the embodiments in this specification, the drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this specification. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0010] Figure 1 This is an architecture diagram of a blockchain system provided in the embodiments of this specification;
[0011] Figure 2 This is a schematic diagram of the structure of blockchain data storage in related technologies;
[0012] Figure 3 This is a flowchart illustrating a method for querying data in a blockchain system, as provided in the embodiments of this specification.
[0013] Figure 4 This is a flowchart illustrating the method implemented by executing functions in a smart contract in the embodiments of this specification;
[0014] Figure 5 This is a schematic diagram of the structure of a blockchain node in a blockchain system provided in the embodiments of this specification;
[0015] Figure 6 This is a schematic diagram of a device for querying data in a blockchain system, as provided in the embodiments of this specification. Detailed Implementation
[0016] To enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this specification, and not all embodiments. Based on the embodiments in this specification, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of this specification.
[0017] Figure 1 This is an example architecture diagram of a blockchain system provided in the embodiments of this specification. Figure 1 In the architecture diagram of the blockchain system shown, blockchain system 100 may include, for example, N blockchain nodes, where Figure 1 The example shows eight blockchain nodes, numbered 1 through 8. The connections between the nodes schematically represent P2P (Peer-to-Peer) connections, which could be, for example, transmission control protocol (TCP) connections.
[0018] A transaction in a blockchain system refers to a task unit executed and recorded within the blockchain system. A transaction typically includes a From field, a To field, and a Data field. In the case of a transfer transaction, the From field represents the account address initiating the transaction (i.e., initiating a transfer task to another account), the To field represents the account address receiving the transaction (i.e., receiving the transfer), and the Data field includes the transfer amount.
[0019] Blockchain systems offer smart contract functionality. A smart contract on a blockchain is a contract that can be triggered and executed through transactions. Smart contracts can be defined in the form of code. Invoking a smart contract within a blockchain system involves initiating a transaction pointing to the smart contract's address, causing the smart contract code to run distributed across nodes within the blockchain system.
[0020] In a contract deployment scenario, for example, Bob sends a transaction containing information about creating a smart contract (i.e., deploying the contract) to a server such as... Figure 1 In the blockchain shown, the `data` field of the transaction includes the code (such as bytecode or machine code) of the contract to be created, and the `to` field of the transaction is empty, indicating that the transaction is used to deploy the contract. After the nodes reach a consensus through the consensus mechanism, they determine the contract address "0x6f8ae93…". Each node adds a contract account corresponding to the contract address of the smart contract to the state database, allocates state storage corresponding to the contract account, stores the contract code, and saves the hash value of the contract code in the contract's state storage, thus the contract is successfully created.
[0021] In scenarios where contracts are invoked, for example, Bob sends a transaction to invoke a smart contract, such as... Figure 1 In the blockchain shown, the `from` field of this transaction is the address of the account of the transaction initiator (i.e., Bob), and the `to` field, for example, is "0x6f8ae93…", which is the address of the smart contract being invoked. The `data` field of the transaction includes the method and parameters for invoking the smart contract. After consensus is reached on this transaction in the blockchain, each node in the blockchain can execute the transaction, thereby executing the contract separately, and updating the state database based on the execution of the contract.
[0022] One of the decentralized characteristics that distinguishes blockchain technology from traditional technologies is its distributed ledger system, where records are kept on multiple nodes, rather than a centralized system. For a blockchain system to become a robust, publicly accessible, and tamper-proof decentralized system of honest and trustworthy data records, it needs to ensure the security, clarity, and irreversibility of distributed data records in the shortest possible time. In different types of blockchain networks, consensus algorithms are typically used to maintain consistency across the nodes recording the ledger—the consensus mechanisms mentioned earlier. For example, blockchain nodes can implement block-level consensus mechanisms. Once a node (e.g., a unique node) generates a block, if this block is recognized by other nodes, those nodes can record the same block.
[0023] Figure 2 This is a schematic diagram of the data storage structure in blockchain technology. Figure 2 In the blockchain data storage shown, the block header of each block (e.g., block N) can include several fields, such as the previous block hash (prev_Hash in the diagram), a nonce (in some blockchain systems, this nonce is not random, or the nonce in the block header is not enabled in some blockchain systems), a timestamp, block height / block number (BlockNum), state root hash (State_Root), transaction root hash (Transaction_Root), and receipt root hash (Receipt_Root). Furthermore, the block header of block N can also include signatures of the block body of block N from multiple blockchain nodes in the blockchain system. These multiple blockchain nodes are the consensus nodes in the blockchain system that participate in executing the aforementioned consensus mechanism. The Prev Hash in the block header of the next block (e.g., block N+1) points to the previous block (e.g., block N), which is the block hash value of the previous block (i.e., the hash value of the block header). In this way, the blockchain achieves the locking of the previous block by the next block through the block header. In particular, as mentioned earlier, state_root is the hash value of the root of the state trie composed of the states of all accounts in the current block, such as an MPT tree (MerklePatricia Tree).
[0024] MPT trees are tree structures that combine Merkle trees and Patricia trees (compressed prefix trees, a more space-efficient trie tree). The Merkle tree algorithm calculates a hash value for each leaf node, then joins each node pairwise and calculates the hash again, continuing until the top-level Merkle root. Ethereum uses an improved MPT tree, which is, for example, a 16-ary tree structure.
[0025] The state tree contains key-value pairs representing the stored content for each account on the Ethereum network. Each key in the state tree can be a 160-bit identifier (the address of the Ethereum account), with the characters in this address distributed across nodes along the path from the root node to a leaf node. (See reference) Figure 2 As shown, the leaf nodes of the MPT state tree (e.g., nodes t4 and t5) also include the values for each account. Specifically, when the account is a user account (also known as an external account), for example... Figure 2 Account A in the context of the database has a Value that includes a Nonce and a Balance. When the account is a contractual account, for example... Figure 2 Account B in the context of the database has a Value that includes a Nonce, a Balance, a CodeHash, and a Storage_root hash. The Nonce represents the number of transactions sent from the account address for external accounts, and the number of contracts created by the account for contract accounts.
[0026] Once a smart contract is deployed on the blockchain, a corresponding contract account is created. This contract account typically has some state, which is defined by state variables within the smart contract and generates new values during the creation and execution of the smart contract. For example... Figure 2 As shown, the contract's relevant state is stored in a storage trie. Figure 2 The diagram illustrates the storage tree of the contract corresponding to account B. The hash value of the root node st1 is stored in the aforementioned storage_root, thus locking all states of the contract to the Value (i.e., account state) of that contract account in the state tree through the root hash. The storage tree can also have an MPT tree structure, where each node in the path from the root node to the leaf node can include characters used to address variable names, and the leaf nodes store the values of the variables, thus storing a key-value mapping from variable names (also called state addresses) to state values. For example, see reference... Figure 2The storage tree in the storage tree has leaf nodes st2 and st3, which include, for example, the value of variable a and the value of variable b. Taking variable a as an example, the characters included in each node in the node path from the root node to the leaf node st2 in the storage tree constitute the variable name of variable a. This variable name can be a key composed of hexadecimal characters.
[0027] Blockchain systems may store private data, such as the contract state of smart contracts. Holders or regulators of this private data may wish to use smart contracts to record other users' queries and usage of this data, preventing malicious access and theft. However, current blockchain systems may support data queries through local transactions that do not affect the world's state. This means that user data queries may not be recorded, providing intruders with opportunities to maliciously access and steal private data.
[0028] In view of the above problems, this specification provides at least one method, apparatus, and blockchain node for querying data in a blockchain system. When a user wants to query the value of a key from the blockchain system via a user device, the user can send a first transaction to the blockchain system to call a first function in a smart contract. This causes the blockchain system to generate an audit log corresponding to the first transaction in the smart contract's contract state. The audit log includes the user's registered account in the blockchain system used to initiate the first transaction, the key to be queried, and the value of the key. The system then returns a transaction receipt containing a log index to the user device. Next, the user can use the user device to initiate a second transaction to the blockchain system, containing the aforementioned index information and used to call a second function in the smart contract. This allows the blockchain system to query the corresponding audit log based on the index information. If the audit log determines that the accounts initiating the first and second transactions are the same, the system returns the value of the key already recorded in the audit log to the user device. In this way, the user's data query behavior is recorded in the blockchain system in the form of an audit log, ensuring that the user's data query behavior can be traced and audited, preventing users from stealing private data from the blockchain system.
[0029] Figure 3 This is a flowchart illustrating a method for querying data in a blockchain system, as provided in the embodiments of this specification. The blockchain system deploys a smart contract C1, which includes at least functions F1 and F2, and may also include function F3. The blockchain system may include multiple blockchain nodes, such as consensus nodes within the blockchain system. Figure 3The blockchain node N shown can be one of the multiple blockchain nodes that is directly connected to the user device. See also Figure 3 As shown, the method may include some or all of the following steps S31 to S39.
[0030] In step S31, blockchain node N receives transaction Tx1 for calling function F3 in smart contract C1. Transaction Tx1 includes the public keys of multiple blockchain nodes in the blockchain system.
[0031] In step S32, blockchain node N executes function F3 according to transaction Tx1 to add the public keys of multiple blockchain nodes in the blockchain system to the contract state of smart contract C1.
[0032] The aforementioned steps S31 and S32 enable the writing of the public keys of multiple blockchain nodes in the blockchain system into the internal storage of smart contract C1. It should be noted that steps S31 and S32 are optional, not mandatory. For example, the public keys of multiple blockchain nodes can also be directly written into the contract code of smart contract C1. Alternatively, smart contract C1 may not need to use the public keys of multiple blockchain nodes. Furthermore, when the public keys of multiple blockchain nodes are required, smart contract C1 can receive / obtain the public keys of multiple blockchain nodes from external sources through other means.
[0033] In step S33, the user equipment sends a transaction Tx2 to the blockchain system to call function F1 in smart contract C1, and the transaction Tx2 indicates the key to be queried.
[0034] The From field of transaction Tx2 can be, for example, account a1 registered in the blockchain system by user A who holds the user device; the To field can be, for example, the contract address of smart contract C1; and the Data field can include, for example, the identifier of function F1 and the key to be queried, where the key to be queried is the key of the data that user A expects to query, which can be a state variable in an external account or contract state.
[0035] Step S34: Blockchain node N executes function F1 according to transaction Tx2 to: add an audit log to the contract state of smart contract C1. The audit log includes the account a1 that initiated transaction Tx2, the key to be queried, and the value of the key to be queried. The transaction receipt of transaction Tx2 is returned to the user device that initiated transaction Tx2. The transaction receipt includes the index information of the audit log.
[0036] If the blockchain system supports returning the corresponding block to the smart contract according to the block height / block number, the audit log of transaction Tx2 can also include the block height of the target block to which transaction Tx2 belongs. In this case, the user equipment can directly execute the following step S37 based on the index information included in the transaction receipt of transaction Tx2, and then continue the subsequent process.
[0037] If the blockchain system does not support returning the corresponding block to the smart contract according to the block height / block number, the transaction receipt of transaction Tx2 may also include the block height of the target block to which transaction Tx2 belongs. In this case, the user device can execute the following step S35 based on the block height of the target block, and the blockchain node N can execute the following step S36, thus continuing the subsequent process.
[0038] In step S35, the user equipment sends transaction Tx3 to the blockchain system, and transaction Tx3 includes the block height of the target block.
[0039] In step S36, blockchain node N returns the target block to the user device based on transaction Tx3.
[0040] Step S37: The user equipment sends a transaction Tx4 to the blockchain system to call function F2 in smart contract C1. Transaction Tx4 includes at least the index information included in the transaction receipt of transaction Tx1.
[0041] The From field of transaction Tx4 can be account a1 registered in the blockchain system by user A, who holds the user device; the To field can be the contract address of smart contract C1; and the Data field can include, for example, the identifier of function F2 and the index information included in the transaction receipt of transaction Tx1. If the blockchain system does not support returning the corresponding block to the smart contract according to the block height, the Data field of transaction Tx4 can also include the target block returned by the blockchain system in the aforementioned step S36. In addition, transaction Tx4 can also include an encryption key used to encrypt the value of the key to be queried and / or the public keys of multiple blockchain nodes.
[0042] Step S38: Blockchain node N executes function F2 based on transaction Tx4 to: query the audit log in the contract state of the smart contract according to the index information, and determine whether the account that initiated transaction Tx4 is the same as the account a1 included in the queried audit log. If so, return the value of the key to be queried included in the audit log to the user device that sent transaction Tx4.
[0043] If the audit log corresponding to transaction Tx2 includes the block height of the target block to which transaction Tx2 belongs, or if transaction Tx4 includes the target block to which transaction Tx2 belongs, then when blockchain node N executes function F2 in smart contract C1 according to transaction Tx4 in the aforementioned step S38, it can specifically implement some or all of the following steps S381 to S387.
[0044] Step S381: Based on the index information in transaction Tx4, query the audit log in the contract status of smart contract C1.
[0045] If the audit log being queried includes the block height of the target block, execute step S382 to obtain the target block stored in blockchain node N based on the block height of the target block included in the queried audit log.
[0046] When transaction Tx4 includes the target block, the following steps can be executed directly: step S383.
[0047] Step S383: Obtain the signatures of multiple blockchain nodes on the block body of the target block from the block header of the target block.
[0048] If the number of blockchain nodes participating in the execution of the aforementioned consensus mechanism in the blockchain system is M, and during the execution of the aforementioned step S383, if the number of signatures of the target block obtained from the block header of the target block by the multiple blockchain nodes for the block body of the target block is less than M, then it can be directly determined that the block body of the target block is untrustworthy, and the execution of transaction Tx4 ends.
[0049] In step S384, the trustworthiness of the target block's block body is verified based on the signatures of the target block's block body by multiple blockchain nodes and the public keys of the multiple blockchain nodes.
[0050] If the signature of the target block's block body is verified by every blockchain node, or if the signature of the target block's block body is verified by a majority of blockchain nodes, then the integrity of the target block's block body is not compromised, and the target block's block body can be determined to be trustworthy, thus proceeding to the next step S385. If the integrity of the target block's block body is compromised, i.e., the target block's block body is untrustworthy, then the execution of transaction Tx4 can be terminated directly.
[0051] Step S385: Based on account a1 in the audit log, the key to be queried, and the index information in transaction Tx4, query whether the target block includes transaction Tx1 and the transaction receipt of transaction Tx1.
[0052] For example, you can first query the target block to see if there is a target transaction that meets the following conditions: the From field is account a1, the data field includes the key to be queried and the identifier of function F1, and the To field is the contract address of smart contract C1. If the target transaction exists, then continue to query the target block to see if there is a target transaction receipt corresponding to the target transaction. If there is a target transaction receipt and the index information included in the target transaction receipt is the same as the index information in transaction Tx2, then the aforementioned target transaction is transaction Tx1 and the aforementioned target transaction receipt is the transaction receipt of transaction Tx1.
[0053] If step S385 determines that the target block includes transaction Tx1 and its transaction receipt, then step S386 can be executed; otherwise, the execution of transaction Tx4 can be terminated.
[0054] In step 386, the value of the key to be queried in the audit log is encrypted using the encryption key included in transaction Tx4 to obtain the processing result.
[0055] In step 387, the processing result is returned to the user equipment that sent transaction Tx4.
[0056] It is understandable that when transaction Tx4 does not include the encryption key, blockchain node N can directly return the value of the key to be queried, which is included in the audit log, in plaintext to the user device that sent transaction Tx4. It should be noted that the user devices sending transactions Tx2, Tx3, and Tx4 can also be different user devices.
[0057] The aforementioned steps S381 to 387 are implemented by executing function F2 in smart contract C1 through the blockchain node, and the audit log being queried is recorded in the contract state of smart contract C1 through function F1. If blockchain node N is a malicious node, for example, an intruder could modify the code of blockchain node N itself to execute transaction Tx2 locally. This means that blockchain node N only persists the audit log generated by executing transaction Tx2 locally, and transaction Tx2 is not actually executed by the entire blockchain system and packaged into the corresponding block. Since function F2 needs to execute transaction Tx4 according to the process shown in steps S381 to 387, triggered by transaction Tx4, it needs to determine if transaction Tx2 has been actually executed by the blockchain system and packaged into the corresponding block before returning the value of the key to be queried, which is included in the audit log persisted in blockchain node N, to the user device that sent transaction Tx4. Otherwise, it will refuse to return the key to be queried, which is only persisted locally in the audit log of blockchain node N. This prevents malicious actions by blockchain node N itself from allowing users to escape auditing of data queries, further improving the security of the blockchain system.
[0058] Based on the same concept as the aforementioned method embodiments, this specification provides a blockchain node in a blockchain system, wherein a smart contract is deployed in the blockchain system, and the smart contract includes a first function and a second function. For example... Figure 5 As shown, the blockchain node includes: a transaction receiving unit 51, configured to receive a first transaction for calling the first function, wherein the first transaction indicates the key to be queried; a transaction execution unit 53, configured to execute the first function according to the first transaction, thereby: adding an audit log to the contract state of the smart contract, wherein the audit log includes the first account that initiated the first transaction, the key to be queried, and the value of the key to be queried, and returning a transaction receipt of the first transaction to the user device that sent the first transaction, wherein the transaction receipt includes the index information of the audit log; the transaction receiving unit 51 is further configured to receive a second transaction for calling the second function, wherein the second transaction includes the index information; the transaction execution unit 53 is further configured to execute the second function according to the second transaction, thereby: querying the audit log in the contract state of the smart contract according to the index information, and, if it is determined that the account that initiated the second transaction is the first account, returning the value of the key to be queried to the user device that sent the first transaction.
[0059] In one possible implementation, the second transaction further includes an encryption key; wherein, when the transaction execution unit 53 executes the second function according to the second transaction, it further implements: encrypting the value of the key to be queried using the encryption key to obtain a processing result; specifically, when the transaction execution unit 53 executes the second function according to the second transaction, it returns the processing result to the user equipment that sent the first transaction.
[0060] In one possible implementation, the audit log also includes the block height of the target block to which the first transaction belongs; wherein, when the transaction execution unit 53 executes the second function according to the second transaction, it further implements: obtaining the target block according to the block height of the target block, and querying whether the target block includes the first transaction and the transaction receipt according to the first account, the key to be queried and the index information.
[0061] In one possible implementation, the transaction receipt further includes the block height of the target block to which the first transaction belongs; wherein, the transaction receiving unit 51 is further configured to receive a third transaction, the third transaction including the block height of the target block; the transaction execution unit 53 is further configured to return the target block to the user equipment that sent the third transaction based on the third transaction; the second transaction also includes the target block; when the transaction execution unit 53 executes the second function based on the second transaction, it further implements: querying whether the target block includes the first transaction and the transaction receipt based on the first account, the key to be queried, and the index information.
[0062] In one possible implementation, the block header of the target block includes signatures of the block body of the target block from multiple blockchain nodes in the blockchain system; wherein, when the transaction execution unit 53 executes the second function according to the second transaction, it further implements: verifying whether the block body of the target block is trustworthy based on the signatures of the block body of the target block from the multiple blockchain nodes and the public keys of the multiple blockchain nodes.
[0063] In one possible implementation, the smart contract further includes a third function; wherein the transaction receiving unit 51 is further configured to receive a fourth transaction for calling the third function, the fourth transaction including the public keys of the plurality of blockchain nodes; the transaction execution unit 53 is further configured to execute the third function according to the fourth transaction, thereby adding the public keys of the plurality of blockchain nodes to the contract state of the smart contract.
[0064] Based on the same concept as the foregoing method embodiments, this specification also provides a device for querying data in a blockchain system, wherein a smart contract is deployed in the blockchain system, the smart contract including a first function and a second function, and the device is deployed in a user device. Figure 6 As shown, the device includes: a communication processing unit 61, configured to send a first transaction to the blockchain system for calling the first function, wherein the first transaction indicates the key to be queried, causing the blockchain system to add an audit log to the contract state of the smart contract, the audit log including the first account that initiated the first transaction, the key to be queried, and the value of the key to be queried, and returning a transaction receipt of the first transaction, wherein the transaction receipt includes index information of the audit log; the communication processing unit is further configured to send a second transaction to the blockchain system for calling the second function, wherein the second transaction includes the index information, causing the blockchain system to query the audit log according to the index information, and, if it is determined that the account that initiated the second transaction is the first account, return the value of the key to be queried.
[0065] In one possible implementation, the second transaction further includes an encryption key, enabling the blockchain system to return a processing result obtained by encrypting the value of the key to be queried using the encryption key; the device further includes a decryption processing unit 63, configured to decrypt the processing result using a decryption key corresponding to the encryption key to obtain the value of the key to be queried.
[0066] In one possible implementation, the transaction receipt further includes the block height of the target block to which the first transaction belongs; wherein, the communication processing unit is further configured to send a third transaction to the blockchain system, the third transaction including the block height of the target block, so that the blockchain system returns the target block; wherein, the second transaction further includes the target block.
[0067] This specification also provides a computer-readable storage medium storing a computer program that, when executed in a computer, causes the computer to perform the various method steps executed by the blockchain node N or the user device in the aforementioned method embodiments.
[0068] This specification also provides a computing device in the embodiments, including a memory and a processor. The memory stores executable code, and when the processor executes the executable code, it implements the various method steps executed by the blockchain node N or the user device in the aforementioned method embodiments.
[0069] In the 1990s, improvements to a technology could be clearly distinguished as either hardware improvements (e.g., improvements to the circuit structure of diodes, transistors, switches, etc.) or software improvements (improvements to the methodology). However, with technological advancements, many methodological improvements today can be considered direct improvements to the hardware circuit structure. Designers almost always obtain the corresponding hardware circuit structure by programming the improved methodology into the hardware circuit. Therefore, it cannot be said that a methodological improvement cannot be implemented using hardware physical modules. For example, a Programmable Logic Device (PLD) (such as a Field Programmable Gate Array (FPGA)) is such an integrated circuit whose logic function is determined by the user programming the device. Designers can program and "integrate" a digital system onto a PLD themselves, without needing chip manufacturers to design and manufacture dedicated integrated circuit chips. Furthermore, nowadays, instead of manually manufacturing integrated circuit chips, this programming is mostly implemented using "logic compiler" software. Similar to the software compiler used in program development, the original code before compilation must be written in a specific programming language, called a Hardware Description Language (HDL). There are many HDLs, 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, and RHDL (Ruby Hardware Description Language). Currently, the most commonly used are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should understand that by simply performing some logic programming on the method flow using one of these hardware description languages and programming it into an integrated circuit, the hardware circuit implementing the logical method flow can be easily obtained.
[0070] The controller can be implemented in any suitable manner. For example, it can take the form of a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro)processor, logic gates, switches, application-specific integrated circuits (ASICs), programmable logic controllers, and embedded microcontrollers. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicon Labs C8051F320. A memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art will also recognize that, in addition to implementing the controller in purely computer-readable program code form, the same functionality can be achieved by logically programming the method steps to make the controller take the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers. Therefore, such a controller can be considered a hardware component, and the means included therein for implementing various functions can also be considered as structures within the hardware component. Alternatively, the means for implementing various functions can be considered as both software modules implementing the method and structures within the hardware component.
[0071] The systems, devices, modules, or units described in the above embodiments can be implemented by computer chips or physical entities, or by products with certain functions. A typical implementation device is a server system. Of course, this application does not exclude the possibility that, with the future development of computer technology, the computer implementing the functions of the above embodiments can be, for example, a personal computer, a laptop computer, an in-vehicle human-machine interaction device, a cellular phone, a camera phone, a smartphone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or any combination of these devices.
[0072] While one or more embodiments of this specification provide the operational steps of the methods described in the embodiments or flowcharts, more or fewer operational steps may be included based on conventional or non-inventive means. The order of steps listed in the embodiments is merely one possible order of execution among many steps and does not represent the only possible order. In actual device or end product execution, the methods shown in the embodiments or drawings may be executed sequentially or in parallel (e.g., in a parallel processor or multi-threaded processing environment, or even a distributed data processing environment). The terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, product, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, product, or apparatus. Without further limitations, the presence of other identical or equivalent elements in the process, method, product, or apparatus that includes the elements is not excluded. For example, the use of terms such as "first," "second," etc., is to denote names and does not indicate any particular order.
[0073] For ease of description, the above devices are described in terms of function, divided into various modules. Of course, when implementing one or more of these specifications, the functions of each module can be implemented in one or more software and / or hardware components, or a module that performs the same function can be implemented by a combination of multiple sub-modules or sub-units. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division; in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces, indirect coupling or communication connection between devices or units, and may be electrical, mechanical, or other forms.
[0074] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0075] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0076] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the functions specified in one or more boxes. In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0077] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0078] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information by any method or technology. Information can be computer-readable instructions, data structures, modules of programs, 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 technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic disk storage, graphene storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0079] Those skilled in the art will understand that one or more embodiments of this specification can be provided as a method, system, or computer program product. Therefore, one or more embodiments of this specification may take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, one or more embodiments of this specification may take 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.) containing computer-usable program code.
[0080] One or more embodiments of this specification can be described in the general context of computer-executable instructions, such as program modules, that are executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform a particular task or implement a particular abstract data type. One or more embodiments of this specification can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.
[0081] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, system embodiments are basically similar to method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments. In the description of this specification, the terms "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., refer to specific features, structures, materials, or characteristics described in connection with that embodiment or example, which are included in at least one embodiment or example of this specification. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described can be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification and the features of different embodiments or examples.
[0082] The above description is merely an embodiment of one or more embodiments of this specification and is not intended to limit the scope of these embodiments. Various modifications and variations can be made to these embodiments by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this specification should be included within the scope of the claims.
Claims
1. A method for querying data in a blockchain system, wherein a smart contract is deployed in the blockchain system, the smart contract including a first function and a second function, the method being executed by a blockchain node in the blockchain system, comprising: Receive a first transaction for invoking the first function, wherein the first transaction indicates the key to be queried; The first function is executed according to the first transaction to achieve the following: an audit log is added to the contract state of the smart contract, the audit log includes the first account that initiated the first transaction, the key to be queried and the value of the key to be queried, and a transaction receipt of the first transaction is returned to the user device that sent the first transaction, the transaction receipt including the index information of the audit log; Receive a second transaction for invoking the second function, the second transaction including the index information; The second function is executed according to the second transaction to: query the audit log in the contract state of the smart contract according to the index information; query whether the target block includes the first transaction and the transaction receipt according to the first account, the key to be queried, and the index information; and if it is determined that the account initiating the second transaction is the first account and the target block includes the first transaction and the transaction receipt, return the value of the key to be queried to the user device that sent the first transaction; wherein the second transaction also includes the target block, or the target block is obtained based on the block height included in the audit log.
2. The method according to claim 1, wherein the second transaction further includes an encryption key; wherein, The execution of the second function based on the second transaction further includes: encrypting the value of the key to be queried using the encryption key to obtain the processing result; Returning the value of the key to be queried to the user equipment that sent the first transaction includes: returning the processing result to the user equipment that sent the first transaction.
3. The method according to claim 1, wherein the transaction receipt further includes the block height of the target block to which the first transaction belongs; wherein, The method further includes: receiving a third transaction, the third transaction including the block height of the target block; and returning the target block to the user equipment that sent the third transaction based on the third transaction.
4. The method according to claim 1 or 3, wherein the block header of the target block includes signatures of the block body of the target block from multiple blockchain nodes in the blockchain system; wherein, The execution of the second function based on the second transaction further includes: verifying whether the block body of the target block is trustworthy based on the signatures of the block body of the target block by the plurality of blockchain nodes and the public keys of the plurality of blockchain nodes.
5. The method according to claim 4, wherein the smart contract further includes a third function; wherein, The method further includes: receiving a fourth transaction for invoking the third function, the fourth transaction including the public keys of the plurality of blockchain nodes; executing the third function according to the fourth transaction to add the public keys of the plurality of blockchain nodes to the contract state of the smart contract.
6. A method for querying data in a blockchain system, wherein a smart contract is deployed in the blockchain system, the smart contract including a first function and a second function, the method being executed by a user device, the method comprising: Send a first transaction to the blockchain system to invoke the first function. The first transaction indicates the key to be queried. The blockchain system adds an audit log to the contract state of the smart contract. The audit log includes the first account that initiated the first transaction, the key to be queried, and the value of the key to be queried. The system also returns a transaction receipt for the first transaction. The transaction receipt includes the index information of the audit log. A second transaction is sent to the blockchain system to invoke the second function. The second transaction includes the index information, enabling the blockchain system to query the audit log based on the index information. The system then queries whether the target block contains the first transaction and the transaction receipt based on the first account, the key to be queried, and the index information. If it is determined that the account initiating the second transaction is the first account and the target block contains the first transaction and the transaction receipt, the system returns the value of the key to be queried. The second transaction may also include the target block, or the target block may be obtained based on the block height included in the audit log.
7. The method according to claim 6, wherein the second transaction further includes an encryption key, enabling the blockchain system to return a processing result obtained by encrypting the value of the key to be queried using the encryption key; in, The method further includes: decrypting the processing result using a decryption key corresponding to the encryption key to obtain the value of the key to be queried.
8. The method according to claim 6, wherein the transaction receipt further includes the block height of the target block to which the first transaction belongs; wherein, The method further includes: sending a third transaction to the blockchain system, the third transaction including the block height of the target block, causing the blockchain system to return the target block; the second transaction also includes the target block.
9. A blockchain node in a blockchain system, wherein a smart contract is deployed in the blockchain system, the smart contract including a first function and a second function, and the blockchain node comprises: A transaction receiving unit is configured to receive a first transaction for calling the first function, wherein the first transaction indicates the key to be queried; The transaction execution unit is configured to execute the first function according to the first transaction, and implement: adding an audit log to the contract state of the smart contract, the audit log including the first account that initiated the first transaction, the key to be queried and the value of the key to be queried, and returning a transaction receipt of the first transaction to the user device that sent the first transaction, the transaction receipt including the index information of the audit log; The transaction receiving unit is further configured to receive a second transaction for calling the second function, the second transaction including the index information; The transaction execution unit is further configured to execute the second function according to the second transaction, and to perform the following: querying the audit log in the contract state of the smart contract according to the index information; querying whether the target block includes the first transaction and the transaction receipt according to the first account, the key to be queried, and the index information; and, if it is determined that the account initiating the second transaction is the first account and the target block includes the first transaction and the transaction receipt, returning the value of the key to be queried to the user device that sent the first transaction; wherein the second transaction also includes the target block, or the target block is obtained based on the block height included in the audit log.
10. The blockchain node according to claim 9, wherein the second transaction further includes an encryption key; wherein, When the transaction execution unit executes the second function according to the second transaction, it also performs the following: encrypting the value of the key to be queried using the encryption key to obtain the processing result; When the transaction execution unit executes the second function according to the second transaction, it specifically returns the processing result to the user equipment that sent the first transaction.
11. The blockchain node according to claim 9, wherein the transaction receipt further includes the block height of the target block to which the first transaction belongs; wherein, The transaction receiving unit is further configured to receive a third transaction, the third transaction including the block height of the target block; the transaction execution unit is further configured to return the target block to the user equipment that sent the third transaction based on the third transaction.
12. The blockchain node according to claim 9 or 11, wherein the block header of the target block includes signatures of the block body of the target block from multiple blockchain nodes in the blockchain system; wherein, When the transaction execution unit executes the second function according to the second transaction, it also verifies whether the block body of the target block is trustworthy based on the signatures of the block body of the target block by the plurality of blockchain nodes and the public keys of the plurality of blockchain nodes.
13. The blockchain node according to claim 12, wherein the smart contract further includes a third function; wherein, The transaction receiving unit is further configured to receive a fourth transaction for calling the third function, the fourth transaction including the public keys of the plurality of blockchain nodes; the transaction execution unit is further configured to execute the third function according to the fourth transaction, thereby adding the public keys of the plurality of blockchain nodes to the contract state of the smart contract.
14. An apparatus for querying data in a blockchain system, wherein a smart contract is deployed in the blockchain system, the smart contract including a first function and a second function, the apparatus being deployed in a user device, the apparatus comprising: The communication processing unit is configured to send a first transaction to the blockchain system for calling the first function. The first transaction indicates the key to be queried, causing the blockchain system to add an audit log to the contract state of the smart contract. The audit log includes the first account initiating the first transaction, the key to be queried, and the value of the key. The system also returns a transaction receipt for the first transaction, which includes index information of the audit log. The communication processing unit is further configured to send a second transaction to the blockchain system for calling the second function. The second transaction includes the index information. The blockchain system queries the audit log based on the index information, checks whether the target block includes the first transaction and the transaction receipt based on the first account, the key to be queried, and the index information. If it is determined that the account initiating the second transaction is the first account and the target block includes the first transaction and the transaction receipt, the system returns the value of the key to be queried. The second transaction also includes the target block, or the target block is obtained based on the block height included in the audit log.
15. The apparatus of claim 14, wherein the second transaction further includes an encryption key, enabling the blockchain system to return a processing result obtained by encrypting the value of the key to be queried using the encryption key; The device further includes: The decryption processing unit is configured to decrypt the processing result using a decryption key corresponding to the encryption key to obtain the value of the key to be queried.
16. The apparatus according to claim 14, wherein the transaction receipt further includes the block height of the target block to which the first transaction belongs; wherein, The communication processing unit is further configured to send a third transaction to the blockchain system, the third transaction including the block height of the target block, so that the blockchain system returns the target block; wherein the second transaction also includes the target block.
17. A computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed in a computing device, the computing device performs the method of any one of claims 1-8.
18. A computing device comprising a memory and a processor, wherein the memory stores executable code, and the processor, when executing the executable code, implements the method of any one of claims 1-8.