CN111026711A - Block chain based data storage method and device, computer equipment and storage medium - Google Patents

Block chain based data storage method and device, computer equipment and storage medium Download PDF

Info

Publication number
CN111026711A
CN111026711A CN201911283950.9A CN201911283950A CN111026711A CN 111026711 A CN111026711 A CN 111026711A CN 201911283950 A CN201911283950 A CN 201911283950A CN 111026711 A CN111026711 A CN 111026711A
Authority
CN
China
Prior art keywords
block
stored
storage condition
data
index
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.)
Pending
Application number
CN201911283950.9A
Other languages
Chinese (zh)
Inventor
黄细健
冯思博
贺亚光
卢德恩
李楠
张亮
李如先
蔡剑戈
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen Qianhai Huanrong Lianyi Information Technology Service Co Ltd
Original Assignee
Shenzhen Qianhai Huanrong Lianyi Information Technology Service Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Shenzhen Qianhai Huanrong Lianyi Information Technology Service Co Ltd filed Critical Shenzhen Qianhai Huanrong Lianyi Information Technology Service Co Ltd
Priority to CN201911283950.9A priority Critical patent/CN111026711A/en
Publication of CN111026711A publication Critical patent/CN111026711A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/13File access structures, e.g. distributed indices
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/17Details of further file system functions
    • G06F16/172Caching, prefetching or hoarding of files
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION 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
    • G06Q20/00Payment architectures, schemes or protocols
    • G06Q20/38Payment protocols; Details thereof
    • G06Q20/389Keeping log of transactions for guaranteeing non-repudiation of a transaction
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L9/00Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
    • H04L9/50Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols using hash chains, e.g. blockchains or hash trees

Abstract

The embodiment of the invention discloses a block chain based data storage method and device, computer equipment and a storage medium. The method comprises the following steps: if a storage request of a block to be stored is received, judging whether the block to be stored meets a preset storage condition; if the block to be stored meets the preset storage condition, establishing an index corresponding to the block to be stored, wherein the index comprises a state index, a historical state index and a block index; writing the block to be stored into a block file and updating block chain information; and if the block to be stored does not meet the preset storage condition, restoring the block file to the state before writing. By implementing the method of the embodiment of the invention, the query response speed of the data can be improved, the query and the management of the data are more convenient, the storage performance of the block chain data is increased, and the network performance and the transaction processing performance of the system under the condition of high concurrency are improved.

Description

Block chain based data storage method and device, computer equipment and storage medium
Technical Field
The present invention relates to the field of blockchain technologies, and in particular, to a method and an apparatus for storing data based on a blockchain, a computer device, and a storage medium.
Background
The block chain is a decentralized technical system with data transparency and privacy security, data on the block chain is stored in a local system in a file form, the block chain is public and transparent for organizations of all parties, and a user can conveniently inquire and check the data on the chain to ensure the authenticity and the effectiveness of the data. Most of the existing block chain platforms adopt a single chain and a single account book storage mode, so that all services and data exist in the single chain, and the data are not isolated. Moreover, most of the data of the account book is stored in a local file system in a leveldb form, and data query and management are extremely inconvenient. Therefore, the existing private chain and public chain account book data mainly have the following problems: most of the data are stored in a local file form, so that data query and management are inconvenient, and data are easy to lose; the privacy of public chain data is weak, anyone can directly read the ledger data, and non-participant organization members are likely to forge and falsify the ledger data.
Disclosure of Invention
The embodiment of the invention provides a data storage method and device based on a block chain, computer equipment and a storage medium, and aims to solve the problems that data in the block chain is inconvenient to query and manage and is easy to lose.
In a first aspect, an embodiment of the present invention provides a block chain-based data storage method, including: if a storage request of a block to be stored is received, judging whether the block to be stored meets a preset storage condition; if the block to be stored meets the preset storage condition, establishing an index corresponding to the block to be stored, wherein the index comprises a state index, a historical state index and a block index; writing the block to be stored into a block file and updating block chain information; and if the block to be stored does not meet the preset storage condition, restoring the block file to the state before writing.
In a second aspect, an embodiment of the present invention further provides a block chain-based data storage device, which includes: the device comprises a judging unit, a judging unit and a judging unit, wherein the judging unit is used for judging whether a block to be stored meets a preset storage condition or not if a storage request of the block to be stored is received; the establishing unit is used for establishing an index corresponding to the block to be stored if the block to be stored meets a preset storage condition, wherein the index comprises a state index, a historical state index and a block index; the writing unit is used for writing the block to be stored into a block file and updating block chain information; and the restoring unit is used for restoring the block file to the state before writing if the block to be stored does not meet the preset storage condition.
In a third aspect, an embodiment of the present invention further provides a computer device, which includes a memory and a processor, where the memory stores a computer program, and the processor implements the above method when executing the computer program.
In a fourth aspect, the present invention also provides a computer-readable storage medium, which stores a computer program, the computer program including program instructions, which when executed by a processor, implement the above method.
The embodiment of the invention provides a data storage method and device based on a block chain, computer equipment and a storage medium. Wherein the method comprises the following steps: if a storage request of a block to be stored is received, judging whether the block to be stored meets a preset storage condition; if the block to be stored meets the preset storage condition, establishing an index corresponding to the block to be stored, wherein the index comprises a state index, a historical state index and a block index; writing the block to be stored into a block file and updating block chain information; and if the block to be stored does not meet the preset storage condition, restoring the block file to the state before writing. According to the embodiment of the invention, by judging whether the block to be stored meets the preset storage condition, under the condition that the preset storage condition is met, the state index, the historical state index and the block index of the block to be stored are established, and the block to be stored is written into the block file; under the condition that the preset storage condition is not met, the block file is restored to the state before writing, the query response speed of the data can be improved, the query and management of the data are more convenient, the storage performance of the block chain data is improved, and the network performance and the transaction processing performance of the system under the condition of high concurrency are improved.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
Fig. 1 is a schematic flowchart illustrating a method for storing data based on a block chain according to an embodiment of the present invention;
FIG. 2 is a sub-flowchart of a method for storing data based on a block chain according to an embodiment of the present invention;
FIG. 3 is a sub-flowchart of a method for storing data based on a block chain according to an embodiment of the present invention;
FIG. 4 is a flowchart illustrating a method for storing data based on a blockchain according to another embodiment of the present invention;
FIG. 5 is a sub-flowchart of a method for storing data based on a block chain according to an embodiment of the present invention;
FIG. 6 is a sub-flowchart of a method for storing data based on a block chain according to an embodiment of the present invention;
FIG. 7 is a schematic block diagram of a blockchain-based data storage device provided by an embodiment of the present invention;
FIG. 8 is a schematic block diagram of a specific unit of a blockchain-based data storage device according to an embodiment of the present invention;
FIG. 9 is a schematic block diagram of a first judging subunit of the block chain-based data storage device according to the embodiment of the present invention;
FIG. 10 is a schematic block diagram of a second judging subunit of the block chain-based data storage device according to the embodiment of the present invention;
FIG. 11 is a schematic block diagram of a computer device provided by an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
It will be understood that the terms "comprises" and/or "comprising," when used in this specification and the appended claims, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
It is also to be understood that the terminology used in the description of the invention herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. As used in the specification of the present invention and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise.
It should be further understood that the term "and/or" as used in this specification and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.
Referring to fig. 1, fig. 1 is a schematic flow chart of a block chain based data storage method according to an embodiment of the present invention. The blockchain-based data storage is applied in a server.
Fig. 1 is a flowchart illustrating a method for storing data based on a block chain according to an embodiment of the present invention. As shown, the method includes the following steps S110-S140.
S110, if a storage request of the block to be stored is received, whether the block to be stored meets a preset storage condition is judged.
In one embodiment, the blockchain is a globally shared distributed account book, a distributed trust mechanism is established in a self-verifying and clearing mode, and the blockchain has the characteristics of decentralization, high public trust, data non-falsification and the like. The block chain system stores data in units of data blocks, i.e., blocks, and different blocks are connected by an algorithm in a time sequence to form a block chain. The blockchain in this embodiment is a federation chain, where a plurality of preselected nodes are specified as bookers in the federation chain only for members of a certain group and limited third parties, the generation of each block is determined by all the preselected nodes, other access nodes may participate in transactions without asking about the billing process, and other third parties may make limited queries through an API opened in the blockchain. Compared with the public chain, the data privacy is weak, anyone can directly read the book data, non-participant organization members are likely to forge and tamper the book data, the alliance chain only allows authorized nodes to join the network, information can be checked according to the authority, and the privacy protection is better. In this embodiment, a k8s mode is used to deploy a federation chain, and k8s is a docker container management tool, and the federation chain is deployed in a k8s mode, so that application deployment can be simplified, the utilization rate of hardware resources is improved, health check and self-repair are performed, capacity expansion and capacity reduction are performed automatically, and service discovery and load balancing are performed. When the nodes generate data to form a block to be stored, each node receives a storage request of the block to be stored, and first needs to judge whether the block to be stored meets a preset storage condition, wherein the preset storage condition is a series of rules of a block write chain. And under the condition of meeting the preset storage condition, storing the block to be stored into the local file system.
In one embodiment, as shown in FIG. 2, the step S110 may include steps S111-S113.
And S111, judging whether the data size of the block to be stored meets a first storage condition.
S112, if the data size of the block to be stored meets the first storage condition, judging whether the data content of the block to be stored meets the second storage condition.
S113, if the data content of the block to be stored meets a second storage condition, judging that the block to be stored meets a preset storage condition.
In an embodiment, the preset storage condition mainly includes a first storage condition and a second storage condition, where the first storage condition is used to determine whether the size of the to-be-stored block meets the requirement, and the second storage condition is used to determine whether the content of the to-be-stored block meets the requirement. And only when the first storage condition and the second storage condition are met, judging that the block to be stored meets the preset storage condition, and judging that the block to be stored does not meet the preset storage condition as long as one item is not met.
In one embodiment, as shown in FIG. 3, the step S111 may include steps S1111-S1113.
S1111, judging whether the data size of the block to be stored exceeds the residual capacity of the block file.
S1112, if the data size of the block to be stored does not exceed the remaining capacity of the block file, determining that the size of the block to be stored satisfies a first storage condition.
S1113, if the data size of the block to be stored exceeds the residual capacity of the block file, determining that the size of the block to be stored does not satisfy the first storage condition.
In an embodiment, when determining whether the block to be stored satisfies the first storage condition, specifically, the size of the block to be stored is compared with the remaining capacity of the block file, and the data length of the block to be stored can be compared with the remaining capacity of the block file. If the size of the block to be stored does not exceed the residual capacity of the block file, the block file is indicated to have enough data of a storage space storage block, and the block to be stored is judged to meet a first storage condition; if the size of the block to be stored exceeds the residual capacity of the block file, the block file does not have enough storage space to store the data of the block, and the block to be stored is judged not to meet the first storage condition.
In an embodiment, as shown in fig. 4, after the step S1113, a step S1114 is further included.
And S1114, creating a new block file to meet the first storage condition for storing the block to be stored.
In one embodiment, in the case that the block to be stored does not satisfy the first storage condition, a new block file is created, and the new block file has sufficient capacity to store the block to be stored, so that the block to be stored satisfies the first storage condition.
In one embodiment, as shown in FIG. 5, the step S112 may include steps S1121-S1123.
S1121, verifying the validity of the data content of the block to be stored.
S1122, if the validity of the data content of the block to be stored passes the verification, determining that the data content of the block to be stored satisfies a second storage condition.
S1123, if the validity verification of the data content of the block to be stored does not pass, determining that the data content of the block to be stored does not satisfy the second storage condition.
In an embodiment, the second storage condition is mainly to judge the validity of the data content of the block to be stored, and the validity verification of the data content of the block to be stored includes but is not limited to that the hash value of the block head meets the current target value (workload certification; tree root obtained by reconstructing a Merkle tree is consistent with the hash MerklerRoot value in the block head (verifying whether the MerkLeRoot is obtained by transaction in the block), the first transaction must be a coinbase transaction, all transactions in the block are traversed, each transaction is checked, and the like.
S120, if the block to be stored meets the preset storage condition, establishing an index corresponding to the block to be stored, wherein the index comprises a state index, a historical state index and a block index.
In one embodiment, the state data records are the result of transaction execution, the latest state represents the latest value of all keys on the channel, and in order to improve the efficiency of chain code execution, the latest value of all keys is stored in a state database in couchdb, and a state index is set for the state database, so that the query of the support key, the query of the combination key and the query of the key range are facilitated. The historical data records the historical information of each state data, the historical information is stored in a leveldb database, and each historical information is represented by a quadruple, wherein: namespace actually represents a different chaincondeid; a key to write data; the block number where the data to be written is located; the tranNo is to write the transaction number in the block in which the data is located, starting from 0. The block index is used for quickly finding the block, and comprises a block number, a block hash, a transaction number and the like. Under the condition that the to-be-stored block meets the preset storage condition, when the to-be-stored block is stored, the data can be quickly inquired by establishing the index, and the management is more convenient.
And S130, writing the block to be stored into the block file and updating the block chain information.
In one embodiment, after the index is established, the block to be stored is written into the block file, i.e., the uplink of the block, and the newly generated block is connected to the previous block through an algorithm. In the embodiment, the storage of the to-be-stored block is stored in the form of a persistent storage mount of PV/PVC. Persistentvolume (PV) is a section of network storage in the cluster that is configured by an administrator, which is a resource in the cluster as if the node were a cluster resource. PV is a capacity insert, such as Volumes, but its life cycle is independent of any single pod using PV. This API object captures the details of the storage implementation, including NFS, iSCSI, or cloud provider specific storage systems. PersistentVolumeClaim (PVC) is a request for storage by a user. It is similar to pod. Pod consumes node resources and PVC consumes PV resources. The Pod may request a particular level of resources (CPU and memory). A claim may request a particular size and access mode (e.g., may be read/write once or read only multiple times). PVC and PV are in one-to-one correspondence, and persistent storage is realized through the PVC and the PV. And writing the block to be stored into the block file, updating block chain information, updating state data and historical information data, synchronously updating check point information when updating the block information, wherein the stored contents are the latest block height and the largest transaction sequence number, and the check point information is used for judging whether the state of the historical information is the latest.
And S140, if the block to be stored does not meet the preset storage condition, restoring the block file to the state before writing.
In one embodiment, when the block to be stored does not satisfy the preset storage condition, the block file is restored to the state before the block to be stored is written, so as to ensure the self-synchronization of the block and the consistency of the data.
In an embodiment, as shown in fig. 6, the step S140 may include a step S141.
And S141, restoring the block file to a state before writing according to the offset in the block index.
In one embodiment, there are file operations and database operations during the storage of the blocks to be stored, so that an error or an interruption may occur at any step. In the recovery process, according to the block information and the state data recorded by the ledger data, the check points of the historical information data are compared, the block information after the check points is resubmitted, and the consistency of the ledger data is kept. Specifically, the recovery can be realized by the offset in the block index, the identifier adopted for locating the block data in the block index is the file name and the offset, and the block file is recovered by locating the block data by using the offset.
It should be noted that the foregoing embodiment is a method for storing blockchain data of a single ledger, where a local file system is used to store ledger data, and each ledger data is stored in a binary file form in a different directory. In another embodiment, the local file system comprises a plurality of accounts, and the data of each account is stored separately, so that multiple channels of data isolation are realized.
In one embodiment, the state index is stored in a CouchDB database, and the historical state index and the chunk index are stored in a levelDB database. CouchDB is a document type database, an API operation database document of the ultrafast RESTful, supports the operation of a native JSON byte array, and can support complex query based on the operation of JSON. The level DB is a high-performance embedded database written by C + +, but does not support complex query. Therefore, the CouchDB database is adopted to store the state index, so that complex queries such as condition query and the like can be supported, and the data query is more convenient and faster.
The block chain-based data storage method disclosed by the embodiment of the invention is characterized in that a state index, a historical state index and a block index of a block to be stored are established by judging whether the block to be stored meets a preset storage condition or not under the condition that the preset storage condition is met, and the block to be stored is written into a block file; under the condition that the preset storage condition is not met, the block file is restored to the state before writing, the query response speed of the data can be improved, the query and management of the data are more convenient, the storage performance of the block chain data is improved, and the network performance and the transaction processing performance of the system under the condition of high concurrency are improved.
Fig. 7 is a schematic block diagram of a block chain-based data storage device 200 according to an embodiment of the present invention. As shown in fig. 7, the present invention also provides a device 200 for storing data based on a block chain, corresponding to the above method for storing data based on a block chain. The blockchain-based data storage apparatus 200 includes a unit for performing the above-described blockchain-based data storage method, and the apparatus may be configured in a server. Specifically, referring to fig. 7, the block chain-based data storage device 200 includes a determining unit 210, a establishing unit 220, a writing unit 230, and a recovering unit 240.
The determining unit 210 is configured to determine whether the block to be stored meets a preset storage condition if a storage request of the block to be stored is received.
In one embodiment, as shown in fig. 8, the determining unit 210 includes a first determining subunit 211, a second determining subunit 212, and a first determining subunit 213.
The first determining subunit 211 is configured to determine whether the data size of the block to be stored satisfies a first storage condition.
The second determining subunit 212 is configured to determine whether the data content of the to-be-stored block meets a second storage condition if the data size of the to-be-stored block meets the first storage condition.
A first determining subunit 213, configured to determine that the block to be stored satisfies a preset storage condition if the data content of the block to be stored satisfies a second storage condition.
In one embodiment, as shown in fig. 9, the first determining sub-unit 211 includes a comparing unit 2111, a second determining sub-unit 2112 and a third determining sub-unit 2113.
A comparing unit 2111, configured to determine whether the data size of the to-be-stored block exceeds the remaining capacity of the block file.
A second determining subunit 2112, configured to determine that the size of the to-be-stored block meets the first storage condition if the data size of the to-be-stored block does not exceed the remaining capacity of the block file.
A third determining subunit 2113, configured to determine that the size of the to-be-stored block does not satisfy the first storage condition if the data size of the to-be-stored block exceeds the remaining capacity of the block file.
In an embodiment, as shown in fig. 9, the first determining subunit 211 further includes a creating unit 2114.
A creating unit 2114, configured to create a new chunk file to satisfy a first storage condition for storing the to-be-stored chunk.
In one embodiment, as shown in fig. 10, the second determining subunit 212 includes a verifying unit 2121, a fourth determining subunit 2122, and a fifth determining subunit 2123.
The verifying unit 2121 is configured to verify the validity of the data content of the block to be stored.
A fourth determining subunit 2122, configured to determine that the data content of the to-be-stored block satisfies the second storage condition if the validity verification of the data content of the to-be-stored block passes.
A fifth determining subunit 2123, configured to determine that the data content of the to-be-stored block does not satisfy the second storage condition if the validity verification of the data content of the to-be-stored block fails.
The establishing unit 220 is configured to establish an index corresponding to the block to be stored if the block to be stored meets a preset storage condition, where the index includes a state index, a historical state index, and a block index.
A writing unit 230, configured to write the block to be stored into the block file and update the block chain information.
The recovering unit 240 is configured to recover the block file to a state before writing if the block to be stored does not satisfy the preset storage condition.
In one embodiment, as shown in fig. 8, the first recovery unit 240 includes a recovery sub-unit 241
A restoring subunit 241, configured to restore the chunk file to a state before writing according to the offset in the chunk index.
It should be noted that, as can be clearly understood by those skilled in the art, the specific implementation process of the above-mentioned data storage device 200 based on the blockchain and each unit may refer to the corresponding description in the foregoing method embodiment, and for convenience and brevity of description, no further description is provided herein.
The above-described blockchain-based data storage may be implemented in the form of a computer program that can be run on a computer device as shown in fig. 11.
Referring to fig. 11, fig. 11 is a schematic block diagram of a computer device according to an embodiment of the present application. The computer device 500 may be a server, which may be an independent server or a server cluster composed of a plurality of servers.
Referring to fig. 11, the computer device 500 includes a processor 502, memory, and a network interface 505 connected by a system bus 501, where the memory may include a non-volatile storage medium 503 and an internal memory 504.
The non-volatile storage medium 503 may store an operating system 5031 and a computer program 5032. The computer programs 5032 include program instructions that, when executed, cause the processor 502 to perform a blockchain-based data storage method.
The processor 502 is used to provide computing and control capabilities to support the operation of the overall computer device 500.
The memory 504 provides an environment for the execution of the computer program 5032 in the non-volatile storage medium 503, and when the computer program 5032 is executed by the processor 502, the processor 502 can be enabled to execute a blockchain-based data storage method.
The network interface 505 is used for network communication with other devices. Those skilled in the art will appreciate that the configuration shown in fig. 11 is a block diagram of only a portion of the configuration associated with the present application and does not constitute a limitation of the computer device 500 to which the present application may be applied, and that a particular computer device 500 may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.
Wherein the processor 502 is configured to run the computer program 5032 stored in the memory to implement the following steps: if a storage request of a block to be stored is received, judging whether the block to be stored meets a preset storage condition; if the block to be stored meets the preset storage condition, establishing an index corresponding to the block to be stored, wherein the index comprises a state index, a historical state index and a block index; writing the block to be stored into a block file and updating block chain information; and if the block to be stored does not meet the preset storage condition, restoring the block file to the state before writing.
In an embodiment, when the step of determining whether the block to be stored meets the preset storage condition is implemented by the processor 502, the following steps are implemented: judging whether the data size of the block to be stored meets a first storage condition or not; if the data size of the block to be stored meets a first storage condition, judging whether the data content of the block to be stored meets a second storage condition; and if the data content of the block to be stored meets a second storage condition, judging that the block to be stored meets a preset storage condition.
In an embodiment, when the step of determining whether the size of the to-be-stored block satisfies the first storage condition is implemented by the processor 502, the following steps are specifically implemented: judging whether the data size of the block to be stored exceeds the residual capacity of the block file; if the data size of the block to be stored does not exceed the residual capacity of the block file, judging that the size of the block to be stored meets a first storage condition; and if the data size of the block to be stored exceeds the residual capacity of the block file, judging that the size of the block to be stored does not meet a first storage condition.
In an embodiment, after the step of determining that the size of the block to be stored does not satisfy the first storage condition, the processor 502 further performs the following steps: and creating a new block file to meet a first storage condition for storing the block to be stored.
In an embodiment, when the step of determining whether the data content of the block to be stored satisfies the second storage condition is implemented by the processor 502, the following steps are specifically implemented: verifying the legality of the data content of the block to be stored; if the validity of the data content of the block to be stored passes the verification, judging that the data content of the block to be stored meets a second storage condition; and if the validity verification of the data content of the block to be stored is not passed, judging that the data content of the block to be stored does not meet a second storage condition.
In an embodiment, when the processor 502 implements the step of restoring the state of the block file before writing, the following steps are implemented: and restoring the block file to a state before writing according to the offset in the block index.
It should be understood that, in the embodiment of the present Application, the Processor 502 may be a Central Processing Unit (CPU), and the Processor 502 may also be other general purpose processors, Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field-Programmable gate arrays (FPGAs) or other Programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, and the like. Wherein a general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
It will be understood by those skilled in the art that all or part of the flow of the method implementing the above embodiments may be implemented by a computer program instructing associated hardware. The computer program includes program instructions, and the computer program may be stored in a storage medium, which is a computer-readable storage medium. The program instructions are executed by at least one processor in the computer system to implement the flow steps of the embodiments of the method described above.
Accordingly, the present invention also provides a storage medium. The storage medium may be a computer-readable storage medium. The storage medium stores a computer program, wherein the computer program comprises program instructions. The program instructions, when executed by the processor, cause the processor to perform the steps of: if a storage request of a block to be stored is received, judging whether the block to be stored meets a preset storage condition; if the block to be stored meets the preset storage condition, establishing an index corresponding to the block to be stored, wherein the index comprises a state index, a historical state index and a block index; writing the block to be stored into a block file and updating block chain information; and if the block to be stored does not meet the preset storage condition, restoring the block file to the state before writing.
In an embodiment, when the processor executes the program instruction to determine whether the block to be stored satisfies the predetermined storage condition, the following steps are specifically implemented: judging whether the data size of the block to be stored meets a first storage condition or not; if the data size of the block to be stored meets a first storage condition, judging whether the data content of the block to be stored meets a second storage condition; and if the data content of the block to be stored meets a second storage condition, judging that the block to be stored meets a preset storage condition.
In an embodiment, when the processor executes the program instructions to implement the step of determining whether the size of the to-be-stored block satisfies the first storage condition, the following steps are specifically implemented: judging whether the data size of the block to be stored exceeds the residual capacity of the block file; if the data size of the block to be stored does not exceed the residual capacity of the block file, judging that the size of the block to be stored meets a first storage condition; and if the data size of the block to be stored exceeds the residual capacity of the block file, judging that the size of the block to be stored does not meet a first storage condition.
In an embodiment, after the step of determining that the size of the block to be stored does not satisfy the first storage condition is realized by executing the program instructions, the processor further realizes the following steps: and creating a new block file to meet a first storage condition for storing the block to be stored.
In an embodiment, when the processor executes the program instructions to implement the step of determining whether the data content of the to-be-stored block satisfies the second storage condition, the following steps are specifically implemented: verifying the legality of the data content of the block to be stored; if the validity of the data content of the block to be stored passes the verification, judging that the data content of the block to be stored meets a second storage condition; and if the validity verification of the data content of the block to be stored is not passed, judging that the data content of the block to be stored does not meet a second storage condition.
In an embodiment, when the processor executes the program instructions to implement the step of restoring the state of the block file before writing, the following steps are specifically implemented: and restoring the block file to a state before writing according to the offset in the block index.
The storage medium may be a usb disk, a removable hard disk, a Read-Only Memory (ROM), a magnetic disk, or an optical disk, which can store various computer readable storage media.
Those of ordinary skill in the art will appreciate that the elements and algorithm steps of the examples described in connection with the embodiments disclosed herein may be embodied in electronic hardware, computer software, or combinations of both, and that the components and steps of the examples have been described in a functional general in the foregoing description for the purpose of illustrating clearly the interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
In the embodiments provided in the present invention, it should be understood that the disclosed apparatus and method may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative. For example, the division of each unit is only one logic function division, and there may be another division manner in actual implementation. For example, various elements or components may be combined or may be integrated into another system, or some features may be omitted, or not implemented.
The steps in the method of the embodiment of the invention can be sequentially adjusted, combined and deleted according to actual needs. The units in the device of the embodiment of the invention can be merged, divided and deleted according to actual needs. In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a storage medium. Based on such understanding, the technical solution of the present invention essentially or partially contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a terminal, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention.
While the invention has been described with reference to specific embodiments, the invention is not limited thereto, and various equivalent modifications and substitutions can be easily made by those skilled in the art within the technical scope of the invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims (10)

1. A method for storing data based on a block chain, comprising:
if a storage request of a block to be stored is received, judging whether the block to be stored meets a preset storage condition;
if the block to be stored meets the preset storage condition, establishing an index corresponding to the block to be stored, wherein the index comprises a state index, a historical state index and a block index;
writing the block to be stored into a block file and updating block chain information;
and if the block to be stored does not meet the preset storage condition, restoring the block file to the state before writing.
2. The method according to claim 1, wherein the determining whether the block to be stored satisfies a predetermined storage condition includes:
judging whether the data size of the block to be stored meets a first storage condition or not;
if the data size of the block to be stored meets a first storage condition, judging whether the data content of the block to be stored meets a second storage condition;
and if the data content of the block to be stored meets a second storage condition, judging that the block to be stored meets a preset storage condition.
3. The method as claimed in claim 2, wherein said determining whether the size of the block to be stored satisfies a first storage condition comprises:
judging whether the data size of the block to be stored exceeds the residual capacity of the block file;
if the data size of the block to be stored does not exceed the residual capacity of the block file, judging that the size of the block to be stored meets a first storage condition;
and if the data size of the block to be stored exceeds the residual capacity of the block file, judging that the size of the block to be stored does not meet a first storage condition.
4. The method of claim 3, wherein after determining that the size of the block to be stored does not satisfy the first storage condition, further comprising
And creating a new block file to meet a first storage condition for storing the block to be stored.
5. The method according to claim 2, wherein said determining whether the data content of the block to be stored satisfies a second storage condition comprises:
verifying the legality of the data content of the block to be stored;
if the validity of the data content of the block to be stored passes the verification, judging that the data content of the block to be stored meets a second storage condition;
and if the validity verification of the data content of the block to be stored is not passed, judging that the data content of the block to be stored does not meet a second storage condition.
6. The method according to claim 1, wherein restoring the block file to the pre-write state comprises:
and restoring the block file to a state before writing according to the offset in the block index.
7. The blockchain-based data storage method according to any one of claims 1 to 6, wherein the state index is stored in a CouchDB database, and the historical state index and the blockchain index are stored in a levelDB database.
8. A block chain based data storage device, comprising:
the device comprises a judging unit, a judging unit and a judging unit, wherein the judging unit is used for judging whether a block to be stored meets a preset storage condition or not if a storage request of the block to be stored is received;
the establishing unit is used for establishing an index corresponding to the block to be stored if the block to be stored meets a preset storage condition, wherein the index comprises a state index, a historical state index and a block index;
the writing unit is used for writing the block to be stored into a block file and updating block chain information;
and the restoring unit is used for restoring the block file to the state before writing if the block to be stored does not meet the preset storage condition.
9. A computer arrangement, characterized in that the computer arrangement comprises a memory having stored thereon a computer program and a processor implementing the method according to any of claims 1-7 when executing the computer program.
10. A computer-readable storage medium, characterized in that the storage medium stores a computer program which, when executed by a processor, implements the method according to any one of claims 1-7.
CN201911283950.9A 2019-12-13 2019-12-13 Block chain based data storage method and device, computer equipment and storage medium Pending CN111026711A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911283950.9A CN111026711A (en) 2019-12-13 2019-12-13 Block chain based data storage method and device, computer equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911283950.9A CN111026711A (en) 2019-12-13 2019-12-13 Block chain based data storage method and device, computer equipment and storage medium

Publications (1)

Publication Number Publication Date
CN111026711A true CN111026711A (en) 2020-04-17

Family

ID=70209072

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911283950.9A Pending CN111026711A (en) 2019-12-13 2019-12-13 Block chain based data storage method and device, computer equipment and storage medium

Country Status (1)

Country Link
CN (1) CN111026711A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111782647A (en) * 2020-05-29 2020-10-16 易联众信息技术股份有限公司 Block data storage method, system, medium and equipment of EOS network
CN112131228A (en) * 2020-09-29 2020-12-25 上海卓钢链科技有限公司 FABRIC-based alliance chain system convenient for data retrieval
CN112463880A (en) * 2020-11-06 2021-03-09 苏州浪潮智能科技有限公司 Block chain data storage method and related device

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108829772A (en) * 2018-05-29 2018-11-16 杭州趣链科技有限公司 A kind of block chain block file-based storage and read method
CN110399373A (en) * 2019-06-26 2019-11-01 杭州慧牧科技有限公司 A kind of block chain account book storage system, storage querying method and delet method

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108829772A (en) * 2018-05-29 2018-11-16 杭州趣链科技有限公司 A kind of block chain block file-based storage and read method
CN110399373A (en) * 2019-06-26 2019-11-01 杭州慧牧科技有限公司 A kind of block chain account book storage system, storage querying method and delet method

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111782647A (en) * 2020-05-29 2020-10-16 易联众信息技术股份有限公司 Block data storage method, system, medium and equipment of EOS network
CN112131228A (en) * 2020-09-29 2020-12-25 上海卓钢链科技有限公司 FABRIC-based alliance chain system convenient for data retrieval
CN112131228B (en) * 2020-09-29 2023-12-19 上海卓钢链科技有限公司 FABRIC-based alliance chain system convenient for data retrieval
CN112463880A (en) * 2020-11-06 2021-03-09 苏州浪潮智能科技有限公司 Block chain data storage method and related device
CN112463880B (en) * 2020-11-06 2023-01-10 苏州浪潮智能科技有限公司 Block chain data storage method and related device

Similar Documents

Publication Publication Date Title
CN109831487B (en) Fragmented file verification method and terminal equipment
CN108923932B (en) Decentralized collaborative verification system and verification method
CN110489059B (en) Data cluster storage method and device and computer equipment
CN111090645B (en) Cloud storage-based data transmission method and device and computer equipment
WO2019114097A1 (en) Blockchain-based distributed storage method
CN109656873B (en) Block chain-based data archiving method and device and terminal equipment
CN108710681B (en) File acquisition method, device, equipment and storage medium
CN111026711A (en) Block chain based data storage method and device, computer equipment and storage medium
CN110445822B (en) Object storage method and device
US20170212925A1 (en) Utilizing a hierarchical index in a dispersed storage network
CN102170440A (en) Method suitable for safely migrating data between storage clouds
CN103944988A (en) Repeating data deleting system and method applicable to cloud storage
WO2017215646A1 (en) Data transmission method and apparatus
CN110163009B (en) Method and device for safety verification and repair of HDFS storage platform
CN112069169A (en) Block data storage method and device, electronic equipment and readable storage medium
CN111311254A (en) Service processing method, device and system based on block chain
CN111339551B (en) Data verification method and related device and equipment
CN112650812A (en) Data fragment storage method and device, computer equipment and storage medium
EP3349416B1 (en) Relationship chain processing method and system, and storage medium
CN112116348A (en) Access control method for node resource
CN115935414A (en) Block chain based data verification method and device, electronic equipment and storage medium
GB2565932B (en) Storing data in dispersed storage network with consistency
CN115563073A (en) Method and device for data processing of distributed metadata and electronic equipment
US10091298B2 (en) Enhancing performance of data storage in a dispersed storage network
CN116107801A (en) Transaction processing method and related product

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination