CN110489421B - Data storage method, apparatus, computer readable storage medium and computer device - Google Patents
Data storage method, apparatus, computer readable storage medium and computer device Download PDFInfo
- Publication number
- CN110489421B CN110489421B CN201910777476.9A CN201910777476A CN110489421B CN 110489421 B CN110489421 B CN 110489421B CN 201910777476 A CN201910777476 A CN 201910777476A CN 110489421 B CN110489421 B CN 110489421B
- Authority
- CN
- China
- Prior art keywords
- intelligent contract
- stored
- key
- target
- hash value
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
- 238000000034 method Methods 0.000 title claims abstract description 52
- 238000013500 data storage Methods 0.000 title claims abstract description 36
- 238000004590 computer program Methods 0.000 claims description 12
- 238000004364 calculation method Methods 0.000 claims description 5
- 238000010586 diagram Methods 0.000 description 20
- 230000006399 behavior Effects 0.000 description 5
- 238000005516 engineering process Methods 0.000 description 4
- 230000004048 modification Effects 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 230000001360 synchronised effect Effects 0.000 description 2
- 238000012795 verification Methods 0.000 description 2
- 230000008520 organization Effects 0.000 description 1
- 230000003068 static effect Effects 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/22—Indexing; Data structures therefor; Storage structures
- G06F16/2228—Indexing structures
- G06F16/2246—Trees, e.g. B+trees
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/27—Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/455—Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
- G06F9/45533—Hypervisors; Virtual machine monitors
- G06F9/45558—Hypervisor-specific management and integration aspects
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06Q—INFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
- G06Q40/00—Finance; Insurance; Tax strategies; Processing of corporate or income taxes
- G06Q40/04—Trading; Exchange, e.g. stocks, commodities, derivatives or currency exchange
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Software Systems (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Databases & Information Systems (AREA)
- General Engineering & Computer Science (AREA)
- Business, Economics & Management (AREA)
- Finance (AREA)
- Data Mining & Analysis (AREA)
- Accounting & Taxation (AREA)
- Computing Systems (AREA)
- Development Economics (AREA)
- Economics (AREA)
- Marketing (AREA)
- Strategic Management (AREA)
- Technology Law (AREA)
- General Business, Economics & Management (AREA)
- Management, Administration, Business Operations System, And Electronic Commerce (AREA)
Abstract
The application relates to a data storage method, a device, a storage medium and a computer apparatus, the method comprising: receiving a key value pair storage request sent by calling a first intelligent contract; invoking the proxy intelligent contract through the first intelligent contract according to the key value pair storage request; the agent intelligent contract calls a precompiled intelligent contract, the precompiled intelligent contract obtains a first intelligent contract address and a key value pair to be stored, the first intelligent contract address and the key to be stored are spliced to obtain a target key to be stored, the target key value pair to be stored is determined according to the target key to be stored and the key value pair to be stored corresponding to the key to be stored, and the target key value pair to be stored is stored in an external server database; precompiled intelligent contracts calculate target hash values of target key value pairs to be stored, and the target hash values are returned to the proxy intelligent contracts; the proxy intelligent contract updates the storage hash value according to the target hash value and writes the storage hash value into the block. The blockchain node server storage capacity can be increased.
Description
Technical Field
The present application relates to the field of computer technologies, and in particular, to a data storage method, apparatus, computer readable storage medium, and computer device.
Background
With the development of blockchain technology, intelligent contracts are increasingly being applied in blockchains, which are a type of computer protocol that aims to propagate, verify or execute contracts in an informative manner. Currently, smart contracts typically store contract data in a local hard disk of a node server where the virtual machine resides. When the mass data of the intelligent contract needs to be stored, the problem that the mass data cannot be stored exists because the storage capacity of the local hard disk of the node server where the virtual machine is located is limited.
Disclosure of Invention
Based on this, it is necessary to provide a data storage method, apparatus, computer-readable storage medium and computer device for the technical problem that the storage capacity of the local hard disk of the node server is limited.
A data storage method, comprising:
receiving a key value pair storage request, wherein the key value pair storage request is sent by calling a first intelligent contract;
invoking the proxy intelligent contract through the first intelligent contract according to the key value pair storage request;
Calling a precompiled intelligent contract through an agent intelligent contract, wherein the precompiled intelligent contract obtains a first intelligent contract address and a key value pair to be stored;
the precompiled intelligent contract splices the first intelligent contract address and the key to be stored in the key value pair to obtain a target key to be stored, determines a target key value pair to be stored according to the target key to be stored and the key to be stored corresponding to the key to be stored, and stores the target key value pair to be stored in an external server database;
precompiled intelligent contracts calculate target hash values of target key value pairs to be stored, and the target hash values are returned to the proxy intelligent contracts;
the proxy intelligent contract updates the storage hash value according to the target hash value and writes the storage hash value into the block.
A data storage device, comprising:
the request receiving module is used for receiving a key value pair storage request which is sent by calling a first intelligent contract;
the contract calling module is used for calling the proxy intelligent contract through the first intelligent contract according to the key value pair storage request;
the information acquisition module is used for calling a precompiled intelligent contract through an agent intelligent contract, and the precompiled intelligent contract acquires a first intelligent contract address and a key value pair to be stored;
The external storage module is used for pre-compiling the intelligent contract, splicing the first intelligent contract address and the key to be stored in the key value pair to obtain a target key to be stored, determining a target key value pair to be stored according to the target key to be stored and the key to be stored corresponding to the target key to be stored, and storing the target key value pair to be stored in the external server database;
the target hash value calculation module is used for precompiling the intelligent contract to calculate a target hash value of a target key value pair to be stored and returning the target hash value to the proxy intelligent contract;
and the storage hash value updating module is used for updating the storage hash value according to the target hash value by the proxy intelligent contract and writing the storage hash value into the block.
A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the following steps when executing the program:
receiving a key value pair storage request, wherein the key value pair storage request is sent by calling a first intelligent contract;
invoking the proxy intelligent contract through the first intelligent contract according to the key value pair storage request;
calling a precompiled intelligent contract through an agent intelligent contract, wherein the precompiled intelligent contract obtains a first intelligent contract address and a key value pair to be stored;
The precompiled intelligent contract splices the first intelligent contract address and the key to be stored in the key value pair to obtain a target key to be stored, determines a target key value pair to be stored according to the target key to be stored and the key to be stored corresponding to the key to be stored, and stores the target key value pair to be stored in an external server database;
precompiled intelligent contracts calculate target hash values of target key value pairs to be stored, and the target hash values are returned to the proxy intelligent contracts;
the proxy intelligent contract updates the storage hash value according to the target hash value and writes the storage hash value into the block.
A computer readable storage medium having stored thereon a computer program which, when executed by a processor, causes the processor to perform the steps of:
receiving a key value pair storage request, wherein the key value pair storage request is sent by calling a first intelligent contract;
invoking the proxy intelligent contract through the first intelligent contract according to the key value pair storage request;
calling a precompiled intelligent contract through an agent intelligent contract, wherein the precompiled intelligent contract obtains a first intelligent contract address and a key value pair to be stored;
the precompiled intelligent contract splices the first intelligent contract address and the key to be stored in the key value pair to obtain a target key to be stored, determines a target key value pair to be stored according to the target key to be stored and the key to be stored corresponding to the key to be stored, and stores the target key value pair to be stored in an external server database;
Precompiled intelligent contracts calculate target hash values of target key value pairs to be stored, and the target hash values are returned to the proxy intelligent contracts;
the proxy intelligent contract updates the storage hash value according to the target hash value and writes the storage hash value into the block.
According to the data storage method, the device, the computer readable storage medium and the computer equipment, the proxy intelligent contract is called through the first intelligent contract, the pre-compiling contract is called through the proxy intelligent contract, the key to be stored in the key value pair to be stored is spliced with the first intelligent contract address through the pre-compiling contract to obtain the target key to be stored, then the target key value pair to be stored is stored in the external server database, the storage capacity of the blockchain node server is expanded, and therefore the limit of the local storage capacity is broken through, and blockchain services needing a large amount of storage can be realized through the intelligent contract. And then, updating the storage hash value according to the target hash value by calculating the target hash value of the target key value pair to be stored and using the proxy intelligent contract to write the storage hash value into the block, so that the key value pair stored in the external server can be indirectly stored in the blockchain, and the consistency of the blockchain node data is ensured.
Drawings
FIG. 1 is a diagram of an application environment for a data storage method in one embodiment;
FIG. 2 is a flow diagram of a method of data storage in one embodiment;
FIG. 3 is a diagram of a traditional contract data store, in one embodiment;
FIG. 4 is a schematic diagram of a contract data store of the present application, in one embodiment;
FIG. 5 is a flow diagram of deploying a smart contract, according to one embodiment;
FIG. 6 is a flow diagram of serializing key-value pairs in one embodiment;
FIG. 7 is a flow diagram of updating a stored hash value in one embodiment;
FIG. 8 is a flow diagram of computing a root hash value in one embodiment;
FIG. 9 is a flow diagram of obtaining key-value pairs in one embodiment;
FIG. 10 is a flow chart of a method of data storage in one embodiment;
FIG. 11 is a schematic diagram of an agent contract in the embodiment of FIG. 10;
FIG. 12 is a schematic diagram of a precompiled contract in the embodiment of FIG. 10;
FIG. 13 is a block diagram of a data storage device in one embodiment;
FIG. 14 is a block diagram of a computer device in one embodiment.
Detailed Description
The present application will be described in further detail with reference to the drawings and examples, in order to make the objects, technical solutions and advantages of the present application more apparent. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the application.
FIG. 1 is a diagram of an application environment for a data storage method in one embodiment. Referring to fig. 1, the data storage method is applied to a data storage system. The data storage system includes a terminal 102 and a node server 104 in a blockchain. The terminal 102 and the node server 104 are connected through a network. The terminal 102 may be a desktop terminal or a mobile terminal, and the mobile terminal may be at least one of a mobile phone, a tablet computer, a notebook computer, and the like. The node server 104 may be implemented as a stand-alone server or as a server cluster of multiple servers.
Specifically, the node server 104 receives a key-value pair storage request sent by the terminal 102 by invoking the first smart contract. The node server 104 invokes the proxy smart contract through the first smart contract based on the key value pair storage request. The node server 104 invokes a precompiled smart contract via the proxy smart contract, the precompiled smart contract obtaining a first smart contract address and a key value pair to be stored. The precompiled intelligent contract splices the first intelligent contract address and the key to be stored in the key value pair to obtain a target key to be stored, determines the target key value pair to be stored according to the target key to be stored and the key to be stored corresponding to the key to be stored, and stores the target key value pair to be stored in an external server database. The precompiled intelligent contract calculates a target hash value of the target key value pair to be stored, and returns the target hash value to the proxy intelligent contract. The proxy intelligent contract updates the storage hash value according to the target hash value and writes the storage hash value into the block.
As shown in fig. 2, in one embodiment, a data storage method is provided. The present embodiment is mainly exemplified by the application of the method to the node server 104 in fig. 1. Referring to fig. 2, the data storage method specifically includes the steps of:
s202, a key value pair storage request is received, wherein the key value pair storage request is sent by calling a first intelligent contract.
Wherein the key-value pair storage is the simplest organization of the database, each key (key) in the key-value pair (key-value) is followed by a corresponding value (value), and when the corresponding key is pressed, a corresponding result is output. Such as "name=Zhang San", where the key position "name" in the key value pair is "Zhang San", for example. The first smart contract is a user-defined externally stored smart contract, which is a normal smart contract that cannot directly access externally stored data. For example, the first smart contract is a user-registered smart contract, and the data to be stored in the user-registered smart contract may be related information of user registration, including a user registration account, a registration name, a registration gender, and other registration information. And converting the related information registered by the user into a key value pair form, and sending a key value pair storage request.
Specifically, the user terminal calls the first intelligent contract to send a request for storing the first intelligent contract data, namely the key value pair, and the block link point server receives the request for storing the key value pair by calling the first intelligent contract.
S204, calling the proxy intelligent contract through the first intelligent contract according to the key value pair storage request.
Wherein the proxy smart contract is a proxy contract of a precompiled contract through which the precompiled smart contract can be invoked. The first smart contract inherits from the proxy smart contract.
Specifically, the block link point server invokes a method of storing key value pairs in the proxy smart contract through the first smart contract according to the key value pair storage request.
S206, calling a precompiled intelligent contract through the proxy intelligent contract, and acquiring a first intelligent contract address and a key value pair to be stored by the precompiled intelligent contract.
The precompiled intelligent contracts are used for storing contract data into an external database, and the precompiled intelligent contracts are built into the block link point server after precompiled and assigned precompiled contract addresses. The first smart contract address is used to identify a first smart contract from which the first smart contract may be found. The key value pair to be stored refers to key value pair data that the first smart contract needs to store to an external database.
Specifically, the blockchain node server invokes a method for storing key value pairs in a precompiled smart contract through an agent smart contract, and the precompiled smart contract obtains a first smart contract address and a key value pair to be stored.
S208, pre-compiling the intelligent contract, splicing the first intelligent contract address and the key to be stored in the key value pair to obtain a target key to be stored, determining a target key value pair to be stored according to the target key to be stored and the key to be stored corresponding to the key to be stored, and storing the target key value pair to be stored in an external server database.
The target key to be stored refers to a key (key) to be stored in an external server database, and the key is obtained by splicing a first intelligent contract address and a key value to be stored. For example, if the key to be stored is "01" and the first smart contract address is "10", the target key to be stored may be "1001". The target key value pair to be stored refers to a key value pair formed by the target key to be stored and the corresponding value to be stored. The external server refers to a server other than the node server, for example, the external server may be a cloud server, a distributed server, or the like.
In particular, the smart contracts are typically executed in node server virtual machines. The block chain node server executes the precompiled intelligent contract to splice the first intelligent contract address and the key to be stored in the key value pair to obtain a target key to be stored, the target key value pair to be stored is determined according to the target key to be stored and the key to be stored corresponding to the key to be stored, the node server sends a storage request of the target key value pair to an external server, the external server receives the storage request, and the target key value pair to be stored is stored in the database. The contract address splicing key to be stored is used as a target key to be stored, and then the target key value pair to be stored is stored in the database, so that when different intelligent contracts update the same key, the values are different in mutual coverage, and the universality of the key value pair storage is improved.
S210, the precompiled intelligent contract calculates a target hash value of the target key value pair to be stored, and the target hash value is returned to the proxy intelligent contract.
The target hash value refers to a hash value of a target key value pair to be stored. Each key value pair to be stored needs to be stored with a corresponding target hash value.
Specifically, the blockchain node server executes a precompiled smart contract, the precompiled smart contract calculates a target hash value of a target key value pair to be stored, and the target hash value is returned to the proxy smart contract.
S212, the agent intelligent contract updates the storage hash value according to the target hash value, and writes the storage hash value into the block.
Wherein the stored hash value is a hash value of all stored key-value pairs hash values, the stored hash value being only one. The proxy smart contract is also configured to update the stored hash value based on the target hash value.
Specifically, when the precompiled smart contract stores the target key value pair to be stored in the external server database, the precompiled smart contract returns the hash value of the calculated stored target key value pair to the proxy smart contract, and the proxy smart contract updates the stored hash value according to the target hash value and then writes the updated stored hash value into the block.
In the data storage method, the proxy intelligent contract is called through the first intelligent contract, the proxy intelligent contract calls the precompiled contract, the key to be stored in the key value pair to be stored is spliced with the first intelligent contract address through the precompiled contract to obtain the target key to be stored, then the target key value pair to be stored is stored in the external server database, and the storage capacity of the blockchain node server is expanded, so that the limitation of the local storage capacity is broken through, and blockchain business needing to be stored in a large amount can be realized by using the intelligent contract. And then, updating the storage hash value according to the target hash value by calculating the target hash value of the target key value pair to be stored and using the proxy intelligent contract to write the storage hash value into the block, so that the key value pair stored in the external server can be indirectly stored in the block chain, and the consistency of data in the block chain link point is ensured.
FIG. 3 is a diagram illustrating a conventional contract data store, in one embodiment. Obviously, in the traditional blockchain technology, the intelligent contract has the problem of limited storage capacity by storing contract data into a node server hard disk where the virtual machine is located, namely the node server hard disk. In one embodiment, the application expands the storage capacity of the node server, so that the contract data can be stored in the local storage database and the external storage database, and massive contract data can be stored, thereby greatly expanding the application scenario of the blockchain technology.
In one embodiment, as shown in fig. 5, before step S202, that is, before the receiving the key-value pair storage request, the key-value pair storage request is sent by calling the first smart contract, the method further includes the steps of:
s502, acquiring a first intelligent contract, an agent intelligent contract and a precompiled intelligent contract, and deploying the first intelligent contract and the agent intelligent contract into a blockchain.
Wherein the smart contract is executable code running in the blockchain,
specifically, the blockchain node server acquires a first intelligent contract and an agent intelligent contract, calls an intelligent contract editor to compile an intelligent contract code into a virtual machine byte code when the first intelligent contract and the agent intelligent contract are acquired, then sends the byte code to a blockchain network through an interface, and writes the byte code into the blockchain after full network verification.
S504, generating a first intelligent contract address and an address of the agent intelligent contract.
Wherein the address of the proxy smart contract is used to uniquely identify the proxy smart contract. The corresponding smart contract may be found using the address of the smart contract.
Specifically, the blockchain node server generates a first smart contract address and an address of the proxy smart contract.
In the above embodiment, by deploying the first smart contract and the proxy smart contract in the blockchain, it is ensured that the smart contract can be normally invoked.
In one embodiment, as shown in fig. 6, step S208, storing the target key-value pair to be stored in the external server database, includes:
s602, serializing the target key value pair to be stored to obtain the serialized target key value to be stored.
Serialization refers to a process of converting state information of an object into a form that can be stored or transmitted.
Specifically, the blockchain node server sequences the target key value pair to be stored to obtain a serialized target key value pair to be stored, wherein the serialized target key value pair to be stored
S604, storing the serialized target key value to be stored in an external server database.
Specifically, the blockchain node service sends a storage request of a target key value pair to be stored to an external server database, the storage request carries the serialized target key value pair to be stored, and after receiving the storage request, the external server stores the serialized target key value pair to be stored in the database.
In the above embodiment, the pair of target to-be-stored key values is serialized to obtain the serialized target to-be-stored key values, and the serialized target to-be-stored key values are stored in the external server database, so that any type of data structure can be saved, and the universality of the storage method is improved.
In one embodiment, as shown in fig. 7, step S212, that is, updating the stored hash value by the proxy smart contract according to the target hash value, includes the steps of:
s702, obtaining a historical storage hash value, and calculating the hash values of the historical storage hash value and the target hash value to obtain a storage hash value.
S704, storing the stored hash value in the local database.
Wherein the history stored hash value refers to a hash value of a key value pair for which history has been stored in the external server database. The local database refers to the database in the block link point server.
Specifically, the blockchain node server may obtain a historical stored hash value from a local database, calculate a hash value of the historical stored hash value and a target hash value, and obtain a stored hash value. The stored hash value is then stored in a local database. For example, if the historical stored hash value is "11" and the target hash value is "12", the obtained stored hash value is "1112". The hash value of "1112" is then stored in the local database.
In the above embodiment, the stored hash value is updated by calculating the hash values of the historical stored hash value and the target hash value, and the updated stored hash value is stored in the local database, so that the subsequent use is convenient.
In one embodiment, as shown in fig. 8, step S212, i.e. writing the stored hash value into the block, includes the steps of:
s802, obtaining block content and a stored hash value, and calculating a root hash value corresponding to the block content and the stored hash value.
S804, the root hash value is written into the block header.
The block content refers to the content to be written into a new block of the blockchain, and the root hash value is a hash value of a finger state tree root node. Each block contains such a state node, which facilitates the mutual verification of the states between nodes, ensuring that the states of all nodes are consistent throughout each block of transactions and at all times.
Specifically, the blockchain node acquires the blockcontents and the stored hash values, calculates root hash values corresponding to the blockcontents and the stored hash values, and then writes the root hash values into the blockhead.
In the above embodiment, by calculating the root hash value corresponding to the block content and the stored hash value, the root hash value is written into the block header, so that the key value stored externally is indirectly written into the blockchain, that is, the modification to the external storage is also commonly recognized, and the consistency of the blockchain node data can be ensured.
In one embodiment, as shown in fig. 9, the data storage method further includes the steps of:
S902, a key value pair acquisition request is received, wherein the key value pair acquisition request is sent by calling a first intelligent contract, and the key value pair acquisition request carries a key to be acquired.
The key to be acquired refers to a key corresponding to a key value pair to be acquired, for example, the key value pair is "name-Zhang San", and when the value "Zhang Sano" corresponding to the key "name" to be acquired is required to be acquired, a key value pair acquisition request is sent, and the key value pair acquisition request carries the key "name" to be acquired.
Specifically, the blockchain node server receives a key value pair acquisition request sent by the terminal, wherein the key value pair acquisition request is sent by calling a first intelligent contract, and the key value pair acquisition request carries a key to be acquired.
S904, calling a proxy intelligent contract through the first intelligent contract according to the key value pair acquisition request, and calling a precompiled intelligent contract through the proxy intelligent contract.
S906, the precompiled intelligent contract obtains a first intelligent contract address, and a target key to be obtained is determined according to the first intelligent contract address and the key to be obtained.
Specifically, the blockchain node calls an agent intelligent contract through a first intelligent contract according to a key value pair acquisition request, the agent intelligent contract calls a precompiled intelligent contract, the precompiled intelligent contract acquires a first intelligent contract address, and the precompiled intelligent contract splices a key to be acquired and the first intelligent contract address to obtain a target key to be acquired.
S908, sending a target value acquisition request to an external server, wherein the target value acquisition request carries a target key to be acquired, and the external server is used for searching a corresponding target value in a database according to the target key to be acquired.
Specifically, the blockchain node server sends a target value acquisition request to an external server, the target value acquisition request carries a target key to be acquired, the external server receives the target value acquisition request, analyzes the target key to be acquired, searches a target value corresponding to the target key to be acquired in a database, and returns the searched target value to the blockchain node server.
S910, obtaining a target value corresponding to the target key to be queried returned by the external server.
Specifically, the blockchain node server acquires a target value corresponding to a target key to be queried returned by the external server, obtains a key value pair according to the key to be acquired and the target value, and returns the obtained key value pair to a corresponding terminal for sending the key value pair acquisition request to display.
In the above embodiment, when a key value pair acquisition request is received, an agent intelligent contract is called through a first intelligent contract, a precompiled intelligent contract is called through the agent intelligent contract, then the precompiled intelligent contract determines a target key to be acquired, and a corresponding target value is acquired from an external server database according to the target key to be acquired, so that the key value pair is obtained. The data stored in the external server can be used, and the application scene is expanded.
In one particular embodiment, as shown in FIG. 10, a contract caller call (call) "custom external storage contract" initiates a save key pair request, the custom external storage contract call (call) agent contract's storage method. Fig. 11 is a schematic diagram of an agent contract, where the put method in the agent contract is used to store key value pairs. The proxy contract message call (call) precompiled contract precompileEstorage is a schematic diagram of precompiled smart contract precompileEstorage, as shown in FIG. 12. And splicing the address of the customized external storage contract with the keys in the key value pair to form a new key by the precompiled intelligent contract precompileEstorage, and then externally storing the new key and the corresponding value by using a Put method. And simultaneously calculating hash values of the new key and the corresponding value, returning the hash values of the new key and the corresponding value to the proxy contract Estorage, and updating the stored hash value storageHash by the proxy contract Estorage according to the hash values returned by the precompiled intelligent contract Precom Estorage. Namely, calculating the historical stored hash value and the hash value returned by the precompileEstorage to obtain an updated stored hash value storageHash, and then storing the updated stored hash value storageHash into a local database. And the updated stored hash value storageHash participates in the calculation of the fast root hash of the new region in the blockchain, and the calculated root hash is written into the block header of the new region of the blockchain.
In a specific embodiment, the customized external storage contract may be an external storage contract of the registration information, and then the key value pair to be stored is converted into the registration information, and then the key value pair of the registration information may be stored in an external server database.
In a specific embodiment, the customized external storage contract may be an external storage contract of hospital patient information, and then the key value pair to be stored is converted into patient information, and then the key value pair of patient information may be stored in an external server database.
In a specific embodiment, the customized external storage contract may be an external storage contract of an application log, and then the key value pair to be stored is converted into log information, and then the key value pair of the log information may be stored in an external server database.
In a specific embodiment, the customized external storage contract may be an external storage contract of the user behavior data, and then the key value pair to be stored is converted into the user behavior data, and then the key value pair of the user behavior data may be stored in an external server database. The user behavior data may be behavior data of accessing a website.
In one particular embodiment, a contract caller call (call) "custom external storage contract" initiates a key-value pair get request, which carries the key to be fetched. A data acquisition method of a custom external storage contract call (call) proxy contract in a blockchain node server. As shown in fig. 11, a schematic diagram of an agent contract is shown, the get method in the agent contract is used for calling the get method of the precompiled intelligent contract precompileissage, the get method of the precompileissage splices the self-defined external storage contract address and the key to be acquired into a new key, then the get method is used for acquiring a target value corresponding to the new key from an external server database, and finally the acquired target value and the key to be acquired are used as key values to be displayed on a terminal corresponding to a contract caller.
It should be understood that, although the steps in the flowcharts of fig. 5-9 are shown in order as indicated by the arrows, these steps are not necessarily performed in order as indicated by the arrows. The steps are not strictly limited to the order of execution unless explicitly recited herein, and the steps may be executed in other orders. Moreover, at least some of the steps in fig. 5-9 may include multiple sub-steps or stages that are not necessarily performed at the same time, but may be performed at different times, nor do the order in which the sub-steps or stages are performed necessarily occur sequentially, but may be performed alternately or alternately with at least a portion of the sub-steps or stages of other steps or steps.
In one embodiment, as shown in FIG. 13, there is provided a data storage device 1300 comprising:
a request receiving module 1302, configured to receive a key-value pair storage request, where the key-value pair storage request is sent by calling a first smart contract;
a contract invoking module 1304 for invoking the proxy smart contract through the first smart contract based on the key value pair storage request;
an information obtaining module 1306, configured to invoke a precompiled smart contract by using the proxy smart contract, where the precompiled smart contract obtains a first smart contract address and a key value pair to be stored;
the external storage module 1308 is configured to pre-compile the smart contract, splice the first smart contract address with the key to be stored in the key value pair to obtain a target key to be stored, determine a target key value pair to be stored according to the target key to be stored and the key to be stored corresponding to the target key to be stored, and store the target key value pair to an external server database;
a target hash value calculation module 1310, configured to precompiled the intelligent contract to calculate a target hash value of the target key value pair to be stored, and return the target hash value to the proxy intelligent contract;
the storage hash value updating module 1312 is configured to update the storage hash value according to the target hash value by the proxy intelligent contract, and write the storage hash value into the block.
In one embodiment, the data storage device 1300 further comprises:
the contract deployment module is used for acquiring the first intelligent contract, the proxy intelligent contract and the precompiled intelligent contract and deploying the first intelligent contract and the proxy intelligent contract into a blockchain;
and the address generation module is used for generating the address of the first intelligent contract and the address of the proxy intelligent contract.
In one embodiment, the external storage module 1308 is further configured to serialize the target key-value pair to be stored, and obtain a serialized target key-value to be stored; and storing the serialized target key value to be stored into the external server database.
In one embodiment, the stored hash value updating module 1312 is further configured to obtain a historical stored hash value, calculate a hash value of the historical stored hash value and the target hash value, and obtain the stored hash value; storing the stored hash value in a local database.
In one embodiment, the stored hash value updating module 1312 is further configured to obtain a block content and the stored hash value, and calculate a root hash value corresponding to the block content and the stored hash value; and writing the root hash value into a block head.
In one embodiment, the data storage device 1300 further comprises:
the acquisition request receiving module is used for receiving a key value pair acquisition request, wherein the key value pair acquisition request is sent by calling a first intelligent contract, and the key value pair acquisition request carries a key to be acquired;
the precompiled contract calling module is used for calling an agent intelligent contract through the first intelligent contract according to the key value pair acquisition request and calling a precompiled intelligent contract through the agent intelligent contract;
the target key determining module is used for acquiring the first intelligent contract address by the precompiled intelligent contract, and determining a target key to be acquired according to the first intelligent contract address and the key to be acquired;
the external server is used for searching a corresponding target value in a database according to the target key to be acquired;
and the target value acquisition module is used for acquiring the target value corresponding to the target key to be queried returned by the external server.
FIG. 14 illustrates an internal block diagram of a computer device in one embodiment. The computer device may be specifically the blockchain node server 104 of fig. 1. As shown in fig. 14, the internal structure thereof may be as shown in fig. 14. The computer device includes a processor, a memory, and a network interface connected by a system bus. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage media. The network interface of the computer device is used for communicating with an external terminal through a network connection. The computer program is executed by a processor to implement a data storage method.
It will be appreciated by those skilled in the art that the structure shown in fig. 14 is merely a block diagram of a portion of the structure associated with the present inventive arrangements and is not limiting of the computer device to which the present inventive arrangements are applied, and that a particular computer device may include more or fewer components than shown, or may combine certain components, or have a different arrangement of components.
In one embodiment, the data storage apparatus provided by the present application may be implemented in the form of a computer program that is executable on a computer device as shown in fig. 14. The memory of the computer device may store therein various program modules constituting the data storage device, such as a request receiving module 1302, a contract invoking module 1304, an information acquiring module 1306, an external storage module 1308, a target hash value calculating module 1310, and a stored hash value updating module 1312 shown in fig. 13. The computer program of each program module causes a processor to execute the steps of the data storage method of each embodiment of the present application described in the present specification.
For example, the computer apparatus shown in fig. 14 may perform step S202 through the request receiving module 1302 in the data storage device as shown in fig. 13. The computer device may perform step S204 through the contract invoking module 1304. The computer device may perform step S206 through the information acquisition module 1306. The computer device may perform step S208 through the external storage module 1308. The computer device may perform step S210 through the target hash value calculation module 1310. The computer device may perform step S212 by storing the hash value update module 1312.
In one embodiment, a computer device is provided comprising a memory and a processor, the memory storing a computer program that, when executed by the processor, causes the processor to perform the steps of the data storage method described above. The steps of the data storage method herein may be the steps in the data storage method of the above embodiments.
In one embodiment, a computer readable storage medium is provided, storing a computer program which, when executed by a processor, causes the processor to perform the steps of the data storage method described above. The steps of the data storage method herein may be the steps in the data storage method of the above embodiments.
Those skilled in the art will appreciate that all or part of the processes in the methods of the above embodiments may be implemented by a computer program for instructing relevant hardware, where the program may be stored in a non-volatile computer readable storage medium, and where the program, when executed, may include processes in the embodiments of the methods described above. Any reference to memory, storage, database, or other medium used in embodiments provided herein may include non-volatile and/or volatile memory. The nonvolatile memory can include Read Only Memory (ROM), programmable ROM (PROM), electrically Programmable ROM (EPROM), electrically Erasable Programmable ROM (EEPROM), or flash memory. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms such as Static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double Data Rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous Link DRAM (SLDRAM), memory bus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), among others.
The technical features of the above embodiments may be arbitrarily combined, and all possible combinations of the technical features in the above embodiments are not described for brevity of description, however, as long as there is no contradiction between the combinations of the technical features, they should be considered as the scope of the description.
The foregoing examples illustrate only a few embodiments of the application and are described in detail herein without thereby limiting the scope of the application. It should be noted that it will be apparent to those skilled in the art that several variations and modifications can be made without departing from the spirit of the application, which are all within the scope of the application. Accordingly, the scope of protection of the present application is to be determined by the appended claims.
Claims (14)
1. A data storage method, comprising:
receiving a key value pair storage request, wherein the key value pair storage request is sent by calling a first intelligent contract;
invoking a proxy smart contract through the first smart contract according to the key value pair storage request;
calling a precompiled intelligent contract through the proxy intelligent contract, wherein the precompiled intelligent contract obtains a first intelligent contract address and a key value pair to be stored;
The precompiled intelligent contract splices the first intelligent contract address and a key to be stored in the key value pair to obtain a target key to be stored, determines a target key value pair to be stored according to the target key to be stored and a value to be stored corresponding to the key to be stored, and stores the target key value pair to be stored in an external server database;
the pre-compiling intelligent contract calculates a target hash value of the target key value pair to be stored, and returns the target hash value to the proxy intelligent contract;
and the agent intelligent contract updates a storage hash value according to the target hash value and writes the storage hash value into a block.
2. The method of claim 1, wherein prior to the receiving a key-value pair storage request, the key-value pair storage request is sent by invoking a first smart contract, further comprising:
acquiring the first intelligent contract and the proxy intelligent contract, and deploying the first intelligent contract and the proxy intelligent contract in a blockchain;
and generating the address of the first intelligent contract and the address of the proxy intelligent contract.
3. The method of claim 1, wherein storing the target key-value pair to be stored in an external server database comprises:
Serializing the target key value pair to be stored to obtain a serialized target key value to be stored;
and storing the serialized target key value to be stored into the external server database.
4. The method of claim 1, wherein the proxy smart contract updates a stored hash value based on the target hash value, comprising:
acquiring a historical storage hash value, and calculating hash values of the historical storage hash value and the target hash value to obtain the storage hash value;
storing the stored hash value in a local database.
5. The method of claim 1, wherein writing the storage hash value into a block comprises:
acquiring block content and the storage hash value, and calculating a root hash value corresponding to the block content and the storage hash value;
and writing the root hash value into a block head.
6. The method according to claim 1, wherein the method further comprises:
receiving a key value pair acquisition request, wherein the key value pair acquisition request is sent by calling a first intelligent contract, and the key value pair acquisition request carries a key to be acquired;
invoking an agent intelligent contract through the first intelligent contract according to the key value pair acquisition request, and invoking a precompiled intelligent contract through the agent intelligent contract;
The precompiled intelligent contract obtains the first intelligent contract address, and a target key to be obtained is determined according to the first intelligent contract address and the key to be obtained;
sending a target value acquisition request to the external server, wherein the target value acquisition request carries the target key to be acquired, and the external server is used for searching a corresponding target value in a database according to the target key to be acquired;
and acquiring the target value corresponding to the target key to be acquired returned by the external server.
7. A data storage device, the device comprising:
the request receiving module is used for receiving a key value pair storage request which is sent by calling a first intelligent contract;
the contract calling module is used for calling an agent intelligent contract through the first intelligent contract according to the key value pair storage request;
the information acquisition module is used for calling a precompiled intelligent contract through the proxy intelligent contract, and the precompiled intelligent contract acquires a first intelligent contract address and a key value pair to be stored;
the external storage module is used for splicing the first intelligent contract address and the key to be stored in the key value pair to obtain a target key to be stored, determining a target key value pair to be stored according to the target key to be stored and the key to be stored corresponding to the target key to be stored, and storing the target key value pair to an external server database;
The target hash value calculation module is used for calculating a target hash value of the target key value pair to be stored by the precompiled intelligent contract, and returning the target hash value to the proxy intelligent contract;
and the storage hash value updating module is used for updating the storage hash value according to the target hash value by the proxy intelligent contract and writing the storage hash value into a block.
8. The apparatus of claim 7, wherein the apparatus further comprises:
the contract deployment module is used for acquiring the first intelligent contract, the proxy intelligent contract and the precompiled intelligent contract and deploying the first intelligent contract and the proxy intelligent contract into a blockchain;
and the address generation module is used for generating the address of the first intelligent contract and the address of the proxy intelligent contract.
9. The apparatus of claim 7, wherein the external storage module is further configured to serialize the target to-be-stored key value pair to obtain a serialized target to-be-stored key value; and storing the serialized target key value to be stored into the external server database.
10. The apparatus of claim 7, wherein the stored hash value update module is further configured to obtain a historical stored hash value, calculate hash values of the historical stored hash value and the target hash value, and obtain the stored hash value; storing the stored hash value in a local database.
11. The apparatus of claim 7, wherein the storage hash value update module is further configured to obtain block content and the storage hash value, and calculate a root hash value corresponding to the block content and the storage hash value; and writing the root hash value into a block head.
12. The apparatus of claim 7, wherein the apparatus further comprises:
the acquisition request receiving module is used for receiving a key value pair acquisition request, wherein the key value pair acquisition request is sent by calling a first intelligent contract, and the key value pair acquisition request carries a key to be acquired;
the precompiled contract calling module is used for calling an agent intelligent contract through the first intelligent contract according to the key value pair acquisition request and calling a precompiled intelligent contract through the agent intelligent contract;
the target key determining module is used for acquiring the first intelligent contract address by the precompiled intelligent contract, and determining a target key to be acquired according to the first intelligent contract address and the key to be acquired;
the external server is used for searching a corresponding target value in a database according to the target key to be acquired;
And the target value acquisition module is used for acquiring the target value corresponding to the target key to be acquired, which is returned by the external server.
13. A computer readable storage medium storing a computer program which, when executed by a processor, causes the processor to perform the steps of the method of any one of claims 1 to 6.
14. A computer device comprising a memory and a processor, the memory storing a computer program that, when executed by the processor, causes the processor to perform the steps of the method of any of claims 1 to 6.
Priority Applications (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910777476.9A CN110489421B (en) | 2019-08-22 | 2019-08-22 | Data storage method, apparatus, computer readable storage medium and computer device |
CN201910854777.7A CN110489429B (en) | 2019-08-22 | 2019-08-22 | Data acquisition method and device, computer readable storage medium and computer equipment |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910777476.9A CN110489421B (en) | 2019-08-22 | 2019-08-22 | Data storage method, apparatus, computer readable storage medium and computer device |
Related Child Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201910854777.7A Division CN110489429B (en) | 2019-08-22 | 2019-08-22 | Data acquisition method and device, computer readable storage medium and computer equipment |
Publications (2)
Publication Number | Publication Date |
---|---|
CN110489421A CN110489421A (en) | 2019-11-22 |
CN110489421B true CN110489421B (en) | 2023-11-14 |
Family
ID=68552820
Family Applications (2)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201910777476.9A Active CN110489421B (en) | 2019-08-22 | 2019-08-22 | Data storage method, apparatus, computer readable storage medium and computer device |
CN201910854777.7A Active CN110489429B (en) | 2019-08-22 | 2019-08-22 | Data acquisition method and device, computer readable storage medium and computer equipment |
Family Applications After (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201910854777.7A Active CN110489429B (en) | 2019-08-22 | 2019-08-22 | Data acquisition method and device, computer readable storage medium and computer equipment |
Country Status (1)
Country | Link |
---|---|
CN (2) | CN110489421B (en) |
Families Citing this family (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110930152B (en) * | 2019-12-04 | 2023-05-26 | 腾讯科技(深圳)有限公司 | Data processing method based on block chain and related equipment |
CN111596954B (en) * | 2020-05-12 | 2023-08-01 | 杭州溪塔科技有限公司 | Distributed version control method and system based on block chain |
CN111782732B (en) * | 2020-07-21 | 2024-09-10 | 深圳市腾讯网域计算机网络有限公司 | Data processing method, device and computer readable storage medium |
CN111737266B (en) * | 2020-07-31 | 2020-11-24 | 支付宝(杭州)信息技术有限公司 | Block data access method, block data storage method and device |
CN112215706B (en) * | 2020-09-17 | 2023-06-30 | 中国科学院计算技术研究所数字经济产业研究院 | Distributed intelligent contract system and implementation method |
CN112416940B (en) * | 2020-11-27 | 2024-05-28 | 深信服科技股份有限公司 | Key value pair storage method, device, terminal equipment and storage medium |
CN113179294B (en) * | 2021-03-15 | 2023-02-07 | 华东师范大学 | Schema unified access method based on intelligent contract |
CN113672632A (en) * | 2021-08-06 | 2021-11-19 | 戈尔特西斯科技(济南)有限公司 | Quick query and call method for change records of historical data on chain based on intelligent contract |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN109634932A (en) * | 2018-11-30 | 2019-04-16 | 北京瑞卓喜投科技发展有限公司 | A kind of intelligence contract storage method and storage system |
CN109670335A (en) * | 2018-12-20 | 2019-04-23 | 众安信息技术服务有限公司 | For in the method and device interacted between data outside block chain and chain |
CN109710694A (en) * | 2018-12-26 | 2019-05-03 | 深圳市网心科技有限公司 | Data processing method, equipment, storage medium and block catenary system |
CN109831298A (en) * | 2019-01-31 | 2019-05-31 | 阿里巴巴集团控股有限公司 | The method of security update key and node, storage medium in block chain |
CN109981679A (en) * | 2019-04-08 | 2019-07-05 | 上海点融信息科技有限责任公司 | The method and apparatus of affairs are executed in block chain network |
Family Cites Families (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US7539661B2 (en) * | 2005-06-02 | 2009-05-26 | Delphi Technologies, Inc. | Table look-up method with adaptive hashing |
CN107507005B (en) * | 2017-08-01 | 2020-09-11 | 众安信息技术服务有限公司 | Off-link data access method and system based on alliance chain |
EP3522088B1 (en) * | 2018-02-05 | 2022-03-16 | Nokia Technologies Oy | Securing blockchain access through a gateway |
CN108830720B (en) * | 2018-06-21 | 2021-04-30 | 北京京东尚科信息技术有限公司 | Intelligent contract running method, device, system and computer readable storage medium |
CN109377363B (en) * | 2018-09-26 | 2020-08-18 | 电子科技大学 | Block chain-based Internet of things data transaction architecture and transaction security method thereof |
CN109445820A (en) * | 2018-10-29 | 2019-03-08 | 深圳市元征科技股份有限公司 | A kind of intelligence contract upgrade method, system, equipment and computer storage medium |
CN109684333B (en) * | 2018-12-24 | 2021-02-09 | 杭州复杂美科技有限公司 | Data storage and cutting method, equipment and storage medium |
-
2019
- 2019-08-22 CN CN201910777476.9A patent/CN110489421B/en active Active
- 2019-08-22 CN CN201910854777.7A patent/CN110489429B/en active Active
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN109634932A (en) * | 2018-11-30 | 2019-04-16 | 北京瑞卓喜投科技发展有限公司 | A kind of intelligence contract storage method and storage system |
CN109670335A (en) * | 2018-12-20 | 2019-04-23 | 众安信息技术服务有限公司 | For in the method and device interacted between data outside block chain and chain |
CN109710694A (en) * | 2018-12-26 | 2019-05-03 | 深圳市网心科技有限公司 | Data processing method, equipment, storage medium and block catenary system |
CN109831298A (en) * | 2019-01-31 | 2019-05-31 | 阿里巴巴集团控股有限公司 | The method of security update key and node, storage medium in block chain |
CN109981679A (en) * | 2019-04-08 | 2019-07-05 | 上海点融信息科技有限责任公司 | The method and apparatus of affairs are executed in block chain network |
Non-Patent Citations (1)
Title |
---|
区块链技术综述;张亮等;《计算机工程》;第45卷(第05期);第1-12页 * |
Also Published As
Publication number | Publication date |
---|---|
CN110489421A (en) | 2019-11-22 |
CN110489429B (en) | 2021-03-16 |
CN110489429A (en) | 2019-11-22 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110489421B (en) | Data storage method, apparatus, computer readable storage medium and computer device | |
WO2020143852A2 (en) | Distributed blockchain data storage under account model | |
CN110866198B (en) | Static resource caching method, system, device, computer equipment and storage medium | |
CN109586948A (en) | Update method, apparatus, computer equipment and the storage medium of system configuration data | |
CN110555041A (en) | Data processing method, data processing device, computer equipment and storage medium | |
CN110781214A (en) | Database reading and writing method and device, computer equipment and storage medium | |
CN111475376A (en) | Method and device for processing test data, computer equipment and storage medium | |
WO2020155771A1 (en) | Spreadsheet data processing method and apparatus, computer device, and storage medium | |
CN111400246B (en) | Asynchronous file import method, device, computer equipment and storage medium | |
CN109361628B (en) | Message assembling method and device, computer equipment and storage medium | |
CN112256318B (en) | Construction method and equipment for dependent product | |
US11005648B2 (en) | Blockchain-type data storage | |
CN111831208A (en) | Information processing method and device, terminal equipment and storage medium | |
CN112615759A (en) | Full link voltage measurement assembly, full link voltage measurement method and device | |
CN112783866B (en) | Data reading method, device, computer equipment and storage medium | |
CN113779452A (en) | Data processing method, device, equipment and storage medium | |
CN116466884A (en) | Data writing method and device, computer equipment and storage medium | |
CN116644122A (en) | Data transaction processing method, device, computer equipment and storage medium | |
CN116208676A (en) | Data back-source method, device, computer equipment, storage medium and program product | |
CN115640471A (en) | Short link generation method and device, computer equipment and storage medium | |
CN114416689A (en) | Data migration method and device, computer equipment and storage medium | |
CN114218013A (en) | Searching method, searching device and electronic equipment storage medium | |
CN111538651A (en) | Interface testing method, device, server and storage medium | |
KR102433764B1 (en) | System and method for monitoring service | |
CN117708094B (en) | Data processing method, device, electronic equipment and storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
REG | Reference to a national code |
Ref country code: HK Ref legal event code: DE Ref document number: 40014941 Country of ref document: HK |
|
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |