Method and apparatus for querying data in a blockchain
By introducing a query log mechanism into the blockchain, the problem of inability to effectively record query behavior in the existing technology is solved, and the traceability and data security of query data behavior are realized.
Patent Information
- Application Number
- CN202210744768.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-28
- Publication Date
- 2025-05-27
- Estimated Expiration
- 2042-06-28
AI Technical Summary
When querying data, existing blockchain systems cannot effectively record query behavior, resulting in malicious queryers that may steal user privacy data.
By introducing a query log mechanism into the blockchain, the query party needs to send two transactions: the first transaction generates and goes on the chain, and the second transaction carries the query log index information to obtain the target data.
Record the behavior of querying data on the blockchain to ensure that the behavior is traceable and viewable, thereby preventing malicious queries from stealing user privacy data and improving the security of data in the blockchain.
Smart Images

Figure CN115114334B_ABST
Abstract
Description
Technical Field
[0001] One or more embodiments of this specification relate to the field of blockchain technology, and more particularly, to a method and apparatus for querying data in a blockchain. Background Art
[0002] Blockchain is a novel application model for computer technologies, including distributed data storage, peer-to-peer transmission, consensus mechanisms, and encryption algorithms. In a blockchain, data blocks are linked sequentially in chronological order to form a chain-like data structure, and cryptography is used to ensure that these blocks cannot be tampered with or forged. Due to its decentralized, tamper-proof, and autonomous nature, blockchain is gaining increasing attention and application.
[0003] Currently, the state data of some blockchains includes users' private data. The current blockchain system supports querying data through local transactions that do not affect the world state, so that the queryer's query behavior will not be recorded on the blockchain. This provides some malicious queryers with an opportunity to steal users' private data. Summary of the Invention
[0004] One or more embodiments of this specification provide a method and apparatus for querying data in a blockchain.
[0005] According to a first aspect, a method for querying data in a blockchain is provided, the method being performed by a node of the blockchain; the method comprising:
[0006] Receiving a first transaction sent by a querying party; the first transaction is used to query a first state value of a target variable;
[0007] generating a query log based on the first transaction, storing the query log in a state database of the blockchain, and returning index information of the query log to the querying party;
[0008] receiving a second transaction sent by the querying party, and obtaining the query log based on the second transaction, wherein the second transaction includes the index information;
[0009] Information carrying the first status value is returned to the querying party based on the query log.
[0010] According to a second aspect, a method for querying data in a blockchain is provided, the method being performed by a user device; the method comprising:
[0011] Initiating a first transaction to the blockchain, where the first transaction is used to query a first state value of a target variable; causing a node of the blockchain to generate a query log, and storing the query log in a state database of the blockchain;
[0012] Receiving index information of the query log returned by the blockchain;
[0013] Initiating a second transaction to the blockchain, the second transaction including the index information; so that a node of the blockchain obtains the query log based on the index information, and obtains the first state value based on the query log;
[0014] Receive information returned by the blockchain that carries the first state value.
[0015] According to a third aspect, a device for querying data in a blockchain is provided, which is deployed on a node of the blockchain; the device comprises:
[0016] A first receiving module is configured to receive a first transaction sent by a querying party, wherein the first transaction is used to query a first state value of a target variable;
[0017] a first execution module, configured to generate a query log based on the first transaction, store the query log in a state database of the blockchain, and return index information of the query log to the querying party;
[0018] a second receiving module, configured to receive a second transaction sent by the querying party, wherein the second transaction includes the index information;
[0019] The second execution module is configured to obtain the query log based on the second transaction, and return information carrying the first status value to the querying party based on the query log.
[0020] According to a fourth aspect, a device for querying data in a blockchain is provided, which is deployed on a user device; the device comprises:
[0021] a first sending module, configured to initiate a first transaction to the blockchain, wherein the first transaction is used to query a first state value of a target variable; so that a node of the blockchain generates a query log, and stores the query log in a state database of the blockchain;
[0022] A first receiving module, configured to receive index information of the query log returned by the blockchain;
[0023] a second sending module, configured to initiate a second transaction to the blockchain, wherein the second transaction includes the index information; so that a node of the blockchain obtains the query log based on the index information, and obtains the first state value based on the query log;
[0024] The second receiving module is used to receive the information carrying the first state value returned by the blockchain.
[0025] According to a fifth aspect, a computer-readable storage medium is provided, wherein the storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of the first aspect or the second aspect is implemented.
[0026] According to the sixth aspect, a computing device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method described in any one of the first and second aspects when executing the program.
[0027] The technical solutions provided by the embodiments of this specification may have the following beneficial effects:
[0028] The embodiments of this specification provide a method and apparatus for querying data in a blockchain, implementing data querying through two transactions. First, a blockchain node generates a query log by executing transaction Tx1 initiated by the queryer. Once the query log is successfully uploaded to the blockchain, the blockchain node returns the query log's index information to the queryer. The queryer then initiates transaction Tx2 to the blockchain. Transaction Tx2 carries the aforementioned index information, allowing the blockchain node to retrieve the data being queried by executing transaction Tx2 and return the data to the queryer. This allows the query to be recorded on the blockchain in the form of a query log, ensuring that the query can be traced and reviewed, preventing malicious inquirers from stealing users' private data, and improving the security of blockchain data.
[0029] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] In order to more clearly illustrate the technical solutions of the embodiments of this specification, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments recorded in this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0031] Figure 1 This is a diagram of the blockchain architecture used in the embodiments of this specification;
[0032] Figure 2 This is an interactive flow chart of a method for querying data in a blockchain according to an exemplary embodiment of this specification;
[0033] Figure 3 This is a flow chart of a method for querying data in a blockchain according to an exemplary embodiment of this specification;
[0034] Figure 4This is a block diagram of a device for querying data in a blockchain according to an exemplary embodiment of the present specification;
[0035] Figure 5 This is a block diagram of a device for querying data in a blockchain according to an exemplary embodiment of the present specification. DETAILED DESCRIPTION
[0036] To help those skilled in the art better understand the technical solutions in this specification, the following will provide a clear and complete description of the technical solutions in the embodiments of this specification, in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of this specification, not all of them. All other embodiments derived by those skilled in the art based on the embodiments in this specification without creative effort shall fall within the scope of protection of this specification.
[0037] like Figure 1 , which is a diagram of the blockchain architecture used in the embodiments of this specification.
[0038] Figure 1 In the example, the blockchain includes six nodes, Node 1 through Node 6. Each node can be implemented as any device, server, or cluster with computing and processing capabilities. The lines between the nodes schematically represent P2P (peer-to-peer) connections. These nodes store the full ledger, i.e., the state of all blocks and all accounts. Each node in the blockchain generates the same state by executing the same transactions, and each node in the blockchain stores the same state database. Each node is responsible for receiving transactions from clients and initiating a consensus proposal to other nodes. This consensus proposal includes, for example, multiple transactions in the block to be formed (e.g., block H1) and the order in which each transaction should be submitted. After the nodes in the blockchain successfully reach consensus on the consensus proposal, they execute the multiple transactions according to the submission order specified in the consensus proposal, thereby generating block H1.
[0039] I understand. Figure 1 The blockchain shown is only exemplary and the embodiments of this specification are not limited to application in Figure 1 The blockchain shown. In addition, Figure 1Although the blockchain is shown as including six nodes, the embodiments of this specification are not limited thereto and may include other numbers of nodes. Specifically, the nodes included in the blockchain can meet Byzantine Fault Tolerance (BFT) requirements. This Byzantine Fault Tolerance requirement can be understood as allowing Byzantine nodes to exist within the blockchain without externally displaying Byzantine behavior. Generally, some Byzantine Fault Tolerance algorithms require the number of nodes to be greater than 3f+1, where f is the number of Byzantine nodes, such as the Practical Byzantine Fault Tolerance (PBFT) algorithm.
[0040] A transaction in the blockchain field can refer to a task unit executed and recorded in the blockchain. A transaction typically includes a send field (From), a receive field (To), and a data field (Data). In the case of a transfer transaction, the From field indicates the account address initiating the transaction (i.e., initiating a transfer task to another account), the To field indicates the account address receiving the transaction (i.e., receiving the transfer), and the Data field includes the transfer amount. In the case of a transaction calling a smart contract in the blockchain, the From field indicates the account address initiating the transaction, the To field indicates the account address of the contract called by the exchange, and the Data field includes data such as the function name in the called contract and the parameters passed to the function, which are used to retrieve the function code from the blockchain and execute the function code when the transaction is executed.
[0041] Blockchains offer smart contract functionality. Smart contracts on blockchains are contracts that can be triggered and executed by transactions within the blockchain system. Smart contracts can be defined in code. Calling a smart contract on a blockchain involves initiating a transaction directed to the smart contract address, allowing the smart contract code to be distributed and executed on every node in the blockchain. It should be noted that in addition to user-created smart contracts, smart contracts can also be set up by the system in the genesis block. These contracts are generally referred to as genesis contracts. Genesis contracts typically define certain blockchain data structures, parameters, properties, and methods. Furthermore, accounts with system administrator privileges can create or modify system-level contracts (referred to as system contracts). These system contracts can be used to add data structures for different business operations to the blockchain.
[0042] In the scenario of deploying a contract, for example, Bob sends a transaction containing the information of creating a smart contract (ie deploying the contract) to Figure 1In the blockchain shown, the transaction's data field contains the code (such as bytecode or machine code) for the contract to be created. The transaction's to field is empty, indicating that the transaction is for deploying the contract. After the nodes reach consensus through the consensus mechanism, they determine the contract address "0x6f8ae93..." Each node adds a contract account corresponding to the smart contract's contract address to the state database, allocates state storage corresponding to the contract account, and saves the contract code in the contract's state storage, successfully creating the contract.
[0043] In the scenario of calling a contract, for example, Bob sends a transaction for calling a smart contract to Figure 1 In the blockchain shown, the transaction's "from" field is the account address of the initiator (Bob), the "to" field ("0x6f8ae93...") represents the address of the smart contract being called, and the transaction's "data" field contains the method and parameters for calling the smart contract. After consensus is reached on the transaction within the blockchain, each node in the blockchain can execute the transaction, thereby executing the contract and updating the state database based on the contract's execution.
[0044] Currently, some blockchain state data includes user privacy data. Current blockchain systems support data queries via local transactions that do not affect the world state. This prevents the queryer's data query from being recorded on the blockchain, creating an opportunity for malicious actors to steal user privacy data. The embodiments of this specification provide a solution for querying data on a blockchain, implementing data queries through two transactions. First, a blockchain node generates a query log by executing a first transaction initiated by the queryer. Once the query log is successfully uploaded to the blockchain, the blockchain node returns index information for the query log to the queryer. The queryer then initiates a second transaction on the blockchain, carrying the aforementioned index information. This transaction allows the blockchain node to retrieve the target data to be queried by executing the second transaction and return the target data to the queryer. This allows the data query to be recorded on the blockchain, ensuring that the query can be traced and reviewed, and preventing malicious actors from stealing user privacy data.
[0045] The solution provided in this specification will be described in detail below with reference to specific embodiments.
[0046] like Figure 2 As shown, Figure 2 This is an interactive flow chart illustrating a method for querying data in a blockchain, according to an exemplary embodiment. The method is executed by a blockchain node, which can be implemented as any device, platform, server, or device cluster with computing and processing capabilities. The method includes the following steps:
[0047] In step 201, the querying party sends a transaction Tx1 to a blockchain node via a user device. Transaction Tx1 is used to query the state value of a variable V. Transaction Tx1 may carry an identifier corresponding to variable V. Variable V may be the state of an external account (e.g., the account balance of an external account) or a state variable in a target smart contract.
[0048] In step 203, after receiving transaction Tx1, the blockchain node may first generate a query log by executing transaction Tx1. The query log may include identification information corresponding to the inquirer, such as the identification information of account C used by the inquirer to initiate transaction Tx1.
[0049] Optionally, in one implementation, the identifier Vk of the variable V may be recorded in the query log. In another implementation, before generating the query log, the blockchain node may also obtain the current state value Vm of the variable V and record the state value Vm in the query log.
[0050] Further optionally, before generating the query log, the blockchain node may also obtain the block number of the block B1 to which the transaction Tx1 belongs, and may also record the block number of the block B1 in the query log.
[0051] After executing transaction Tx1 and persisting block B1, the blockchain node can store the query log in the state database. Alternatively, if variable V is a state variable in the target smart contract, the query log can be stored in the contract state of the target smart contract's contract account in the state database. The blockchain node can then return an execution receipt for transaction Tx1 to the inquiring party. This receipt can include the query log's index in the state database. The inquiring party can then retrieve the query log's index in the state database from this receipt.
[0052] In step 205, the querying party sends transaction Tx2 to the blockchain node via its user device. Transaction Tx2 includes the index information of the query log in the state database. Furthermore, in step 207, the blockchain node executes transaction Tx2, retrieves the query log from the blockchain state database based on the index information included in transaction Tx2, and sends information containing the state value of variable V to the user device used by the querying party based on the query log.
[0053] Specifically, in one implementation, the query log includes the identifier Vk of variable V. Based on the identifier Vk, the blockchain node can query the blockchain for the state value of variable V and return information containing the state value to the querying party. In another implementation, the query log includes the state value Vm of variable V that was queried before the query log was generated. The blockchain node can obtain the state value Vm from the query log and return information containing the state value Vm to the querying party.
[0054] Optionally, the query log includes the identification information of the account C used by the queryer to initiate the transaction Tx1. Before returning the information carrying the status value of the variable V to the querying party, it is also possible to determine whether the query is valid based on at least the identification information of the account C included in the query log. If the query is determined to be valid, the information carrying the status value of the variable V is returned to the querying party. The specific process of determining whether the query is valid is described in Figure 3 Example.
[0055] Optionally, the transaction Tx2 initiated by the querying party may include an encryption key k1. After obtaining the state value of variable V, the blockchain node may first encrypt the state value of variable V using the encryption key k1 to obtain encrypted information ms. The encrypted information ms is then sent to the user device used by the querying party as information carrying the state value of variable V.
[0056] The method for querying data in a blockchain, provided in the above-described embodiments of this specification, implements data querying through two transactions. First, a blockchain node generates a query log by executing transaction Tx1 initiated by the queryer. Once the query log is successfully uploaded to the blockchain, the blockchain node returns index information for the query log to the queryer. The queryer then initiates transaction Tx2 to the blockchain. Transaction Tx2 carries the aforementioned index information, allowing the blockchain node to retrieve the data being queried by executing transaction Tx2 and return the data to the queryer. This allows the query to be recorded on the blockchain in the form of a query log, ensuring that the query can be traced and reviewed, preventing malicious queryers from stealing users' private data, and improving the security of blockchain data.
[0057] like Figure 3 As shown, Figure 3 According to an exemplary embodiment, a flowchart of a method for querying data in a blockchain is shown. This embodiment describes a process for determining whether a query is valid. The method is performed by a node of the blockchain and includes the following steps:
[0058] In step 301, it is determined whether the initiating account of transaction Tx2 is the same as the account included in the query log. In step 303, at least if the initiating account of transaction Tx2 is the same as the account included in the query log, it is determined that the query is valid.
[0059] In this embodiment, the query log contains the identification information of the initiating account C of transaction Tx1. After receiving transaction Tx2 and obtaining the query log, the blockchain node can first obtain the identification information of the initiating account C of transaction Tx1 from the query log and then determine whether the initiating account C of transaction Tx1 is the same as the initiating account of transaction Tx2. In one implementation, if the initiating account C of transaction Tx1 is the same as the initiating account of transaction Tx2, the query can be directly determined to be valid.
[0060] In another implementation, the blockchain node can also obtain the block number of block B1, to which transaction Tx1 belongs, and return this block number to the querying party. Before initiating transaction Tx2, the querying party can obtain the block data of block B1 from the blockchain based on this block number and, based on this block data, initiate transaction Tx2 containing this block data. The blockchain node can perform verification based on the block data included in transaction Tx2. If this verification is successful and the initiating account C of transaction Tx1 is the same as the initiating account of transaction Tx2, the query is deemed valid.
[0061] Specifically, if variable V is a state variable in the target smart contract, the target smart contract can include the public keys of each node in the blockchain. The blockchain nodes can obtain the public keys of each node from the target smart contract and use these keys to verify whether the block data of block B1 includes all signatures of each node and whether the signatures of each node are correct. If the signatures included in the block data are correct and complete, the verification is considered successful. Alternatively, the verification can be determined to include transaction Tx1. If the block data includes transaction Tx1 and the signatures included in the block data are correct and complete, the verification is considered successful.
[0062] In this embodiment, before returning information carrying the status value of the variable V to the inquiring party, the blockchain node first determines the validity of the query based on the query log, and only returns information carrying the status value of the variable V to the inquiring party if the query is valid. Therefore, it further avoids the situation where malicious inquirers maliciously steal the user's private data, and further improves the security of data in the blockchain.
[0063] It should be noted that although the operations of the methods of the embodiments of this specification are described in a specific order in the above embodiments, this does not require or imply that the operations must be performed in this specific order, or that all of the operations shown must be performed to achieve the desired results. On the contrary, the steps depicted in the flowcharts can be performed in a different order. Additionally or alternatively, certain steps can be omitted, multiple steps can be combined into one step, and / or a step can be broken down into multiple steps.
[0064] Corresponding to the aforementioned method embodiment for querying data in a blockchain, this specification also provides an embodiment of a device for querying data in a blockchain.
[0065] like Figure 4 As shown, Figure 4 This is a block diagram of a device for querying data in a blockchain according to an exemplary embodiment of this specification. The device is deployed on a node of the blockchain and may include: a first receiving module 401, a first execution module 402, a second receiving module 403 and a second execution module 404.
[0066] The first receiving module 401 is configured to receive a first transaction sent by a querying party, where the first transaction is used to query a first state value of a target variable.
[0067] The first execution module 402 is configured to generate a query log based on the first transaction, store the query log in a state database of the blockchain, and return index information of the query log to the querying party.
[0068] The second receiving module 403 is configured to receive a second transaction sent by the querying party, where the second transaction includes index information.
[0069] The second execution module 404 is configured to obtain a query log based on the second transaction, and return information carrying the first status value to the querying party based on the query log.
[0070] In some embodiments, the target variable is a state variable in the target smart contract. The second execution module 404 stores the query log in the state database of the blockchain in the following manner: the query log is stored in the contract state under the contract account of the target smart contract in the state database of the blockchain.
[0071] In other embodiments, the device may further include: an acquisition module (not shown in the figure).
[0072] The acquisition module is used to acquire the current state value of the target variable as the first state value before generating the query log.
[0073] The query log includes a first status value.
[0074] The second execution module 404 returns information carrying the first status value to the querying party based on the query log in the following manner: obtaining the first status value from the query log, and returning information carrying the first status value to the querying party.
[0075] In other embodiments, the first transaction is initiated by the querying party through the target account, and the query log includes information about the target account. The device may further include: a verification module and an indication module (not shown in the figure).
[0076] The verification module is configured to determine whether the query is valid based on at least the information of the target account included in the query log before returning the information carrying the first status value to the querying party.
[0077] The instructing module is configured to, when determining that the query is valid, instruct the second executing module to execute an operation of returning information carrying the first status value.
[0078] In other embodiments, the verification module may include: a judgment submodule and a determination submodule (not shown in the figure).
[0079] The judgment submodule is configured to determine whether the initiating account of the second transaction and the target account included in the query log are the same account.
[0080] The determination submodule is configured to determine that the query is valid at least when the initiating account and the target account of the second transaction are the same.
[0081] In some other embodiments, the second transaction also includes block data of the first block to which the first transaction belongs. The determination submodule is configured to perform verification based on the block data included in the second transaction. If the verification is successful and the initiating account of the second transaction is the same as the target account, the query is determined to be valid.
[0082] In other embodiments, the target variable is a state variable in a target smart contract, which includes the public keys of each node in the blockchain.
[0083] The determination submodule performs verification based on the block data included in the second transaction in the following manner: obtaining the public keys of each node of the blockchain from the target smart contract, and using the public keys of each node to verify whether the signatures included in the block data are correct and complete, and determining that the verification is successful at least when the signatures included in the block data are correct and complete.
[0084] In some other embodiments, the second transaction further includes an encryption key. The device may further include an encryption module (not shown in the figure).
[0085] The encryption module is used to encrypt the first state value using an encryption key to obtain encrypted information.
[0086] The information carrying the first state value includes encrypted information.
[0087] like Figure 5 As shown, Figure 5This is a block diagram of another device for querying data in a blockchain according to an exemplary embodiment of this specification. The device is deployed on a user device and may include: a first sending module 501, a first receiving module 502, a second sending module 503 and a second receiving module 504.
[0088] Among them, the first sending module 501 is used to initiate a first transaction to the blockchain, and the first transaction is used to query the first state value of the target variable, so that the node of the blockchain generates a query log and stores the query log in the state database of the blockchain.
[0089] The first receiving module 502 is used to receive the index information of the query log returned by the blockchain.
[0090] The second sending module 503 is used to initiate a second transaction to the blockchain, where the second transaction includes index information, so that the node of the blockchain obtains the query log based on the index information and obtains the first state value based on the query log.
[0091] The second receiving module 504 is configured to receive information carrying the first state value returned by the blockchain.
[0092] In some embodiments, the target variable is a state variable in the target smart contract.
[0093] In some other embodiments, the first sending module is configured to: initiate a first transaction to the blockchain through a target account.
[0094] The device may further include: a receiving module and an acquiring module (not shown in the figure).
[0095] The receiving module is configured to receive the block number of the first block to which the first transaction belongs, which is returned by the blockchain.
[0096] The acquisition module is configured to acquire block data of the first block based on the block number of the first block.
[0097] The second transaction also includes the block data of the first block.
[0098] In other embodiments, the second transaction further includes an encryption key.
[0099] The information carrying the first state value includes encrypted information, which is obtained by encrypting the first state value by a node of the blockchain using an encryption key.
[0100] The device may further include: a decryption module (not shown in the figure).
[0101] The decryption module is used to decrypt the encrypted information using a decryption key corresponding to the encryption key to obtain a first state value.
[0102] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can be referred to the partial description of the method embodiments. The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of one or more embodiments of this specification. A person of ordinary skill in the art can understand and implement them without paying any creative work.
[0103] One or more embodiments of this specification also provide a computer-readable storage medium, which stores a computer program that can be used to execute the above Figures 2 to 3 The method for querying data in a blockchain provided in any embodiment.
[0104] One or more embodiments of this specification further provide a computing device, including a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the above-mentioned Figures 2 to 3 The method for querying data in a blockchain provided in any embodiment.
[0105] In the 1990s, technological improvements could be clearly distinguished as either hardware improvements (for example, improvements to circuit structures like diodes, transistors, and switches) or software improvements (improvements to process flows). However, with the advancement of technology, many process flow improvements today can now be considered direct improvements to hardware circuit structures. Designers almost always create the corresponding hardware circuit structure by programming the improved process flow into the hardware circuit. Therefore, it cannot be said that a process flow improvement cannot be implemented using hardware modules. For example, a programmable logic device (PLD), such as a field programmable gate array (FPGA), is an integrated circuit whose logical function is determined by user programming. Designers can "integrate" a digital system on a PLD through their own programming, without having to hire a chip manufacturer to design and manufacture a dedicated integrated circuit chip. Moreover, nowadays, instead of manually fabricating integrated circuit chips, this programming is mostly done using "logic compiler" software. This is similar to the software compiler used when developing programs. Before compilation, the original code must also be written in a specific programming language, called a hardware description language (HDL). There is not just one HDL, but many, 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 will also understand that by simply programming the method flow in one of these hardware description languages and then programming it into an integrated circuit, a hardware circuit that implements the logic method flow can be easily obtained.
[0106] The controller can be implemented in any suitable manner. For example, the controller 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 Silicone Labs C8051F320. The memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art will also know that in addition to implementing the controller in a purely computer-readable program code format, the controller can be implemented in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers by logically programming the method steps. Therefore, such a controller can be considered a hardware component, and the devices included therein for implementing various functions can also be considered as structures within the hardware component. Or even, the devices for implementing various functions can be considered as both software modules that implement the method and structures within the hardware component.
[0107] 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 server system. Of course, this application does not exclude that with the future development of computer technology, the computer that implements the functions of the above embodiments may be, for example, a personal computer, a laptop computer, an in-vehicle human-computer interaction device, 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.
[0108] Although one or more embodiments of this specification provide method operation steps as described in the embodiments or flow charts, more or fewer operation steps may be included based on conventional or non-creative means. The order of steps listed in the embodiments is only one way of executing the order of many steps and does not represent the only execution order. When the device or terminal product in practice is executed, it can be executed in sequence or in parallel according to the method shown in the embodiments or the drawings (for example, a parallel processor or a multi-threaded processing environment, or even a distributed data processing environment). The term "comprise", "include" or any other variant thereof is intended to cover non-exclusive inclusion, so that the process, method, product or equipment including a series of elements includes not only those elements, but also includes other elements that are not clearly listed, or also includes elements inherent to such process, method, product or equipment. In the absence of more restrictions, it is not excluded that there are other identical or equivalent elements in the process, method, product or equipment including the elements. For example, if the words first, second, etc. are used to represent the name, they do not represent any particular order.
[0109] For the convenience of description, the above devices are described in terms of functions divided into various modules. Of course, when implementing one or more of the present specifications, the functions of each module can be implemented in the same or multiple software and / or hardware, or the module that implements the same function can be implemented by a combination of multiple sub-modules or sub-units, etc. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0110] The present invention is described with reference to flowcharts and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowcharts and / or block diagrams, as well as combinations of processes and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowcharts and / or block diagrams. 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.
[0111] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0112] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0113] In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.
[0114] 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. Memory is an example of a computer-readable medium.
[0115] 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 instructions, 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 disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage, graphene 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 transitory media such as modulated data signals and carrier waves.
[0116] Those skilled in the art will appreciate that one or more embodiments of this specification may be provided as a method, system, or computer program product. Thus, one or more embodiments of this specification may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. 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 magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0117] One or more embodiments of this specification may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, and the like that perform specific tasks or implement specific abstract data types. One or more embodiments of this specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communications network. In distributed computing environments, program modules may be located in local and remote computer storage media, including storage devices.
[0118] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between the various embodiments can be referenced across them. Each embodiment focuses on the differences from the other embodiments. In particular, since the system embodiments are generally similar to the method embodiments, their description is relatively simple. For relevant parts, reference can be made to the description of the method embodiments. Throughout this specification, reference to the terms "one embodiment," "some embodiments," "examples," "specific examples," or "some examples" means that the specific features, structures, materials, or characteristics described in conjunction with that embodiment or example are included in at least one embodiment or example of this specification. In this specification, the schematic representations of these terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples. Furthermore, those skilled in the art may combine and integrate the different embodiments or examples, and features of different embodiments or examples, described in this specification, without conflict.
[0119] The foregoing is merely an example of one or more embodiments of this specification and is not intended to limit the one or more embodiments of this specification. It will be apparent to those skilled in the art that various modifications and variations may be made to one or more embodiments of this specification. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of this specification shall be included within the scope of the claims.
Claims
1. A method for querying data in a blockchain, executed by a node of the blockchain; the method includes: Receiving a first transaction sent by a querying party; The first transaction is used to query the first status value of a target variable; Generating a query log based on the first transaction, storing the query log in the state database of the blockchain, and returning the index information of the query log to the querying party; Receiving a second transaction sent by the querying party, and obtaining the query log based on the second transaction; the second transaction includes the index information; Returning information carrying the first status value to the querying party based on the query log.
2. The method according to claim 1, wherein, The target variable is a status variable in a target smart contract; wherein, storing the query log in the state database of the blockchain includes: storing the query log in the contract state under the contract account of the target smart contract in the state database of the blockchain.
3. The method according to claim 1, wherein, Before generating the query log, it further includes: obtaining the current status value of the target variable as the first status value; wherein, the query log includes the first status value; wherein, returning information carrying the first status value to the querying party based on the query log includes: Obtaining the first status value from the query log, and returning information carrying the first status value to the querying party.
4. The method according to claim 1, wherein, The first transaction is initiated by the querying party through a target account; the query log includes information of the target account; wherein, before returning information carrying the first status value to the querying party, it further includes: Determining whether the query is valid at least based on the information of the target account included in the query log; Performing the operation of returning information carrying the first status value in the case of determining that the query is valid.
5. The method according to claim 4, wherein, The determining whether the query is valid at least based on the information of the target account included in the query log includes: Determining whether the initiating account of the second transaction is the same as the target account included in the query log; Determining that the query is valid at least in the case where the initiating account of the second transaction is the same as the target account.
6. The method according to claim 5, wherein, The second transaction further includes the block data of the first block to which the first transaction belongs; wherein, the determining that the query is valid at least in the case where the initiating account of the second transaction is the same as the target account includes: Verifying based on the block data included in the second transaction; Determining that the query is valid in the case where the verification passes and the initiating account of the second transaction is the same as the target account.
7. The method according to claim 6, before generating the query log, it further includes: Obtaining the block number of the first block to which the first transaction belongs; wherein, the query log further includes the block number of the first block; Wherein, the method further includes: returning the block number of the first block to the querying party, so that the querying party obtains the block data of the first block based on the block number of the first block.
8. The method according to claim 6, wherein, the target variable is a state variable in a target smart contract; the target smart contract includes the public keys of each node of the blockchain; wherein, the verifying based on the block data included in the second transaction includes: obtaining the public keys of each node of the blockchain from the target smart contract; verifying whether the signatures included in the block data are correct and complete by using the public keys of each node; determining that the verification is passed at least when the signatures included in the block data are correct and complete.
9. The method according to claim 8, wherein, the determining that the verification is passed at least when the signatures included in the block data are correct and complete includes: determining whether the first transaction is included in the block data; determining that the verification is passed when the first transaction is included in the block data and the signatures included in the block data are correct and complete.
10. The method according to claim 1, wherein, the second transaction further includes an encryption key; wherein, the method further includes: encrypting the first state value by using the encryption key to obtain encrypted information; wherein, the information carrying the first state value includes the encrypted information.
11. A method for querying data in a blockchain, which is executed by a user device; the method includes: initiating a first transaction to the blockchain, where the first transaction is used to query the first state value of a target variable; so that the nodes of the blockchain generate a query log and store the query log in the state database of the blockchain; receiving the index information of the query log returned by the blockchain; initiating a second transaction to the blockchain, where the second transaction includes the index information; so that the nodes of the blockchain obtain the query log based on the index information and obtain the first state value based on the query log; receiving the information carrying the first state value returned by the blockchain.
12. The method according to claim 11, wherein, the target variable is a state variable in a target smart contract.
13. The method according to claim 11, wherein, the initiating the first transaction to the blockchain includes: initiating the first transaction to the blockchain through a target account.
14. The method according to claim 11, wherein, the method further includes: receiving the block number of the first block to which the first transaction belongs returned by the blockchain; obtaining the block data of the first block based on the block number of the first block; wherein, the second transaction further includes the block data of the first block.
15. The method according to claim 11, wherein, the second transaction further includes an encryption key; wherein, the information carrying the first state value includes encrypted information; the encrypted information is obtained by the nodes of the blockchain encrypting the first state value by using the encryption key. Wherein, the method further includes: decrypting the encrypted information with the decryption key corresponding to the encryption key to obtain the first status value.
16. A device for querying data in a blockchain, deployed at a node of the blockchain; the device comprises: A first receiving module, configured to receive a first transaction sent by a querying party; The first transaction is used to query the first status value of a target variable; A first execution module, configured to generate a query log based on the first transaction, store the query log in the state database of the blockchain, and return index information of the query log to the querying party; A second receiving module, configured to receive a second transaction sent by the querying party, where the second transaction includes the index information; A second execution module, configured to obtain the query log based on the second transaction, and return information carrying the first status value to the querying party based on the query log.
17. The device according to claim 16, wherein, The target variable is a state variable in a target smart contract; Wherein, the second execution module stores the query log in the state database of the blockchain in the following manner: storing the query log in the contract state under the contract account of the target smart contract in the state database of the blockchain.
18. The device according to claim 16, wherein, further comprises: An acquisition module, configured to acquire the current status value of the target variable as the first status value before generating the query log; Wherein, the query log includes the first status value; Wherein, the second execution module returns information carrying the first status value to the querying party based on the query log in the following manner: Acquiring the first status value from the query log, and returning information carrying the first status value to the querying party.
19. The device according to claim 16, wherein, The first transaction is initiated by the querying party through a target account; the query log includes information of the target account; Wherein, the device further comprises: A verification module, configured to determine whether the query is valid at least based on the information of the target account included in the query log before returning information carrying the first status value to the querying party; An indication module, configured to indicate the second execution module to perform the operation of returning information carrying the first status value in the case of determining that the query is valid.
20. A device for querying data in a blockchain, deployed at a user device; the device comprises: A first sending module, configured to initiate a first transaction to the blockchain, where the first transaction is used to query the first status value of a target variable; So that a node of the blockchain generates a query log and stores the query log in the state database of the blockchain; A first receiving module, configured to receive index information of the query log returned by the blockchain; A second sending module, configured to initiate a second transaction to the blockchain, where the second transaction includes the index information; so that a node of the blockchain obtains the query log based on the index information and obtains the first status value based on the query log. A second receiving module, configured to receive the information carrying the first status value returned by the blockchain.
21. The apparatus according to claim 20, wherein, the first sending module is configured to: initiate the first transaction to the blockchain through a target account.
22. The apparatus according to claim 20, wherein, the apparatus further comprises: a receiving module, configured to receive the block number of the first block to which the first transaction belongs, returned by the blockchain; an obtaining module, configured to obtain the block data of the first block based on the block number of the first block; wherein the second transaction further comprises the block data of the first block.
23. The apparatus according to claim 20, wherein, the second transaction further comprises an encryption key; wherein the information carrying the first status value comprises encrypted information; the encrypted information is obtained by a node of the blockchain encrypting the first status value using the encryption key; wherein the apparatus further comprises: a decryption module, configured to decrypt the encrypted information using a decryption key corresponding to the encryption key to obtain the first status value.
24. A computer-readable storage medium, having stored thereon a computer program, which when executed on a computer, causes the computer to execute the method according to any one of claims 1-15.
25. A computing device, comprising a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the method according to any one of claims 1-15 is implemented.
Citation Information
Patent Citations
A method and system for data flow analysis based on block chain
CN109213790A