Disclosure of Invention
The invention aims to provide a method, a device, an electronic device and a computer readable storage medium for a distributed storage area block chain account book, and mainly aims to solve the technical problem that the storage capacity of a single sub-node in a block chain cluster is easy to become the upper limit of the capacity of the whole block chain.
The purpose of the invention can be realized by the following technical method: a method for storing a block chain account book in a distributed mode comprises the following specific steps:
s1: the method comprises the steps of obtaining first storage data of each child node, and sending the first storage data of each child node to a centralized processing node, wherein the first storage data comprise used storage data and unused storage data of each child node;
s2: receiving and combining the first storage data of all the child nodes by using the centralized processing node to obtain second storage data, wherein the second storage data comprises used storage data and unused storage data in all the child nodes;
s3: setting unused storage data in the second storage data as a first weight, acquiring transaction request data through a first child node, and sending a request command to the centralized processing node by using the first child node according to the transaction request data;
s4: receiving the request command by using the centralized processing node, and performing storage proportion distribution on the first weight according to the request command to obtain a storage distribution result, wherein the storage distribution result comprises each child node and a distributed storage unit;
s5: respectively calculating a storage verification value of the storage distribution result and a verification weight value of the transaction request data, and comparing and verifying the storage verification value and the verification weight value to obtain a verification result;
s6: and distributing the transaction request data according to the storage distribution result by using the verification result.
Further, the allocating the storage proportion of the first weight according to the request command to obtain a storage allocation result includes:
s21: using formulas
Calculating a ratio of unused stored data of the child node in the first weight, resulting in a first ratio, wherein,
representing unused storage data of said child node,
the first weight is represented by a first value,
=1、……、
;
s22: arranging and combining a plurality of first proportion ratios in a descending order to obtain a proportion distribution set;
s23: carrying out proportion division on unused storage data in the first storage data by using the proportion distribution set to obtain memory division data;
s24: and combining the proportion allocation set and the memory division data to obtain a storage allocation result.
Further, the separately calculating a storage verification value of the storage allocation result and a verification weight value of the transaction request data includes:
s31: acquiring the distributed memory of each child node in the storage distribution result;
s32: using formulas
Calculating to obtain a first conversion value; wherein the content of the first and second substances,
indicating the allocated memory of each child node,
=1、……、
;
and
representing different preset scale factors;
representing a first correction factor, having a value of 0.23112;
s33: combining a plurality of first conversion values to obtain a storage verification value;
s34: acquiring a memory value of the transaction request data;
s35: using formulas
And calculating to obtain a verification weight value, wherein,
a memory value representing the transaction request data,
=1、……、
;
representing a second correction factor, and having a value of 0.46224.
Further, the comparing and verifying the stored verification value and the verification weight value to obtain a verification result includes:
if the compared storage verification value is the same as the verification weight value, a first identifier is obtained, the first identifier represents that the storage distribution result is normally distributed, and the next operation can be carried out;
if the compared storage verification value is different from the verification weight value, a second identifier is obtained, the second identifier represents that the distribution of the storage distribution result is abnormal, and the next operation is stopped; wherein the first identifier or the second identifier constitutes a verification result.
Further, the allocating the transaction request data according to the storage allocation result using the verification result includes:
s51: sending the storage allocation result to the first child node by using the verification result;
s52: carrying out proportion division on the transaction request data by utilizing the first child node according to the storage distribution result to obtain a transaction data division set;
s53: sending the transaction data partition set to a plurality of child nodes in the storage distribution result;
s54: the sub-nodes receive and store the transaction data partition sets and generate a plurality of storage results;
s55: updating the first storage data by using the storage result to obtain third storage data, and sending a plurality of third storage data to the centralized processing node;
s56: and updating the second storage data by using a plurality of third storage data to obtain fourth storage data, and setting unused storage data in the fourth storage data as a second weight.
The method comprises a distribution data statistics module, a transaction data acquisition module, a storage distribution module, a data verification module and a data distribution module;
the distributed data statistics module is used for acquiring first storage data of each child node, sending the first storage data of each child node to a centralized processing node, receiving and combining the first storage data of all child nodes by using the centralized processing node to obtain second storage data, wherein the first storage data comprises used storage data and unused storage data of all child nodes;
the transaction data acquisition module is used for setting unused storage data in the second storage data as a first weight, acquiring transaction request data through a first child node, and sending a request command to the centralized processing node by using the first child node according to the transaction request data;
the storage allocation module is used for receiving the request command by using the centralized processing node, and performing storage proportion allocation on the first weight according to the request command to obtain a storage allocation result, wherein the storage allocation result comprises each child node and an allocated storage unit;
the data verification module is used for respectively calculating a storage verification value of the storage distribution result and a verification weight value of the transaction request data, and comparing and verifying the storage verification value and the verification weight value to obtain a verification result;
the data distribution module is used for distributing the transaction request data according to the storage distribution result by using the verification result.
The invention has the beneficial effects that:
in each aspect disclosed by the invention, a distributed data statistical module is used for acquiring first storage data of each child node, the first storage data of each child node is sent to a centralized processing node, the first storage data comprises used storage data and unused storage data of each child node, the centralized processing node is used for receiving and combining the first storage data of all child nodes to obtain second storage data, and the second storage data comprises the used storage data and the unused storage data of all child nodes; through statistics and division of used storage data and unused storage data, support is provided for subsequent data distribution conveniently;
setting unused storage data in the second storage data as a first weight by using a transaction data acquisition module, acquiring transaction request data through a first child node, and sending a request command to the centralized processing node by using the first child node according to the transaction request data; the transaction request data is acquired through any child node, so that the processing efficiency of the block chain on the transaction data can be improved;
the storage allocation module is used for receiving the request command by using the centralized processing node, and performing storage proportion allocation on the first weight according to the request command to obtain a storage allocation result, wherein the storage allocation result comprises each child node and an allocated storage unit; through the preset first weight and the distribution of the storage proportion, the storage effect of each sub-node can be effectively improved, and the problem that the capacity upper limit is easy to appear due to the fact that the storage of each sub-node is different is solved;
respectively calculating a storage verification value of the storage distribution result and a verification weight value of the transaction request data by using a data verification module, and comparing and verifying the storage verification value and the verification weight value to obtain a verification result; the method can effectively eliminate the abnormity of the data in the transmission process, can process the abnormal data in time, and can effectively improve the integrity of the data;
the transaction request data is distributed according to the storage distribution result by the data distribution module by utilizing the verification result, so that the defect that the storage capacity of a single child node in a block chain cluster in the existing scheme is easy to become the capacity upper limit of the whole block chain is overcome.
Example 1
Referring to fig. 1-2, the present invention is a method for storing a block chain account book in a distributed storage area, which specifically includes the steps of:
s1: the method comprises the steps of obtaining first storage data of each child node, and sending the first storage data of each child node to a centralized processing node, wherein the first storage data comprise used storage data and unused storage data of each child node.
In the embodiment of the invention, the first storage data of each child node comprises used memory storage data and unused memory storage data, and the memory storage data of each child node is counted and summarized in the early stage, so that the subsequent account book data distribution is supported conveniently.
S2: and receiving and combining the first storage data of all the child nodes by using the centralized processing node to obtain second storage data, wherein the second storage data comprises used storage data and unused storage data in all the child nodes.
In the embodiment of the invention, the centralized processing node is used for collecting and counting the first storage data of the plurality of sub-nodes, verifying the data and reasonably distributing the data, so that the integrity and the sustainable distribution of the book data are improved.
S3: setting unused storage data in the second storage data as a first weight, acquiring transaction request data through a first child node, and sending a request command to the centralized processing node by using the first child node according to the transaction request data.
In the embodiment of the present invention, the first weight is used to reasonably distribute the plurality of child nodes according to the transaction request data, the transaction request data may be account book data, and the first child node may be any one of the plurality of child nodes.
S4: and receiving the request command by using the centralized processing node, and performing storage proportion distribution on the first weight according to the request command to obtain a storage distribution result, wherein the storage distribution result comprises each child node and a distributed storage unit. The method comprises the following steps:
using formulas
Calculating a ratio of unused stored data of the child node in the first weight, resulting in a first ratio, wherein,
representing unused storage data of said child node,
the first weight is represented by a first value,
=1、……、
;
arranging and combining a plurality of first proportion ratios in a descending order to obtain a proportion distribution set;
carrying out proportion division on unused storage data in the first storage data by using the proportion distribution set to obtain memory division data;
and combining the proportion allocation set and the memory division data to obtain a storage allocation result.
In the embodiment of the invention, the ratio of the rest unused storage data in each sub-node to all the unused storage data is obtained through calculation, and the accounting book data is subjected to proportion division by utilizing the ratio, so that the aim of distributed proportion storage is achieved, and the defect that the storage capacity of a single sub-node is easy to become the upper limit of the capacity of the whole block chain can be effectively overcome.
S5: and respectively calculating a storage verification value of the storage distribution result and a verification weight value of the transaction request data, and comparing and verifying the storage verification value and the verification weight value to obtain a verification result. The method comprises the following steps:
acquiring the distributed memory of each child node in the storage distribution result;
using formulas
Calculating to obtain a first conversion value; wherein the content of the first and second substances,
indicating the allocated memory of each child node,
=1、……、
;
and
representing different preset scale factors;
representing a first correction factor, having a value of 0.23112;
combining a plurality of first conversion values to obtain a storage verification value;
acquiring a memory value of the transaction request data;
using formulas
And calculating to obtain a verification weight value, wherein,
a memory value representing the transaction request data,
=1、……、
;
representing a second correction factor, and having a value of 0.46224.
Wherein:
if the compared storage verification value is the same as the verification weight value, a first identifier is obtained, the first identifier represents that the storage distribution result is normally distributed, and the next operation can be carried out;
if the compared storage verification value is different from the verification weight value, a second identifier is obtained, the second identifier represents that the distribution of the storage distribution result is abnormal, and the next operation is stopped; wherein the first identifier or the second identifier constitutes a verification result.
In the embodiment of the invention, the verification result is obtained by obtaining the storage verification value of the storage distribution result and the verification weight value of the transaction request data and comparing and verifying the verification values, and whether the distributed data is complete or not is judged by the verification result, so that the completeness of the data storage of the account book can be effectively improved, and the defect that the abnormal operation of the account book data in distributed storage is caused when the account book data is distributed and transmitted is avoided.
S6: and distributing the transaction request data according to the storage distribution result by using the verification result. The method comprises the following steps:
sending the storage allocation result to the first child node by using the verification result;
carrying out proportion division on the transaction request data by utilizing the first child node according to the storage distribution result to obtain a transaction data division set;
sending the transaction data partition set to a plurality of child nodes in the storage distribution result;
the sub-nodes receive and store the transaction data partition sets and generate a plurality of storage results;
updating the first storage data by using the storage result to obtain third storage data, and sending a plurality of third storage data to the centralized processing node;
and updating the second storage data by using a plurality of third storage data to obtain fourth storage data, and setting unused storage data in the fourth storage data as a second weight.
In the embodiment of the invention, after the account book data is reasonably distributed and safely verified, the storage data of each child node is updated in real time, so that each child node keeps the same storage degree.
The method comprises a distribution data statistics module, a transaction data acquisition module, a storage distribution module, a data verification module and a data distribution module;
the distributed data statistics module is used for acquiring first storage data of each child node, sending the first storage data of each child node to a centralized processing node, receiving and combining the first storage data of all child nodes by using the centralized processing node to obtain second storage data, wherein the first storage data comprises used storage data and unused storage data of all child nodes;
the transaction data acquisition module is used for setting unused storage data in the second storage data as a first weight, acquiring transaction request data through a first child node, and sending a request command to the centralized processing node by using the first child node according to the transaction request data;
the storage allocation module is used for receiving the request command by using the centralized processing node, and performing storage proportion allocation on the first weight according to the request command to obtain a storage allocation result, wherein the storage allocation result comprises each child node and an allocated storage unit;
the data verification module is used for respectively calculating a storage verification value of the storage distribution result and a verification weight value of the transaction request data, and comparing and verifying the storage verification value and the verification weight value to obtain a verification result;
the data distribution module is used for distributing the transaction request data according to the storage distribution result by using the verification result.
The working principle of the embodiment of the invention is as follows: acquiring first storage data of each child node by using a distribution data statistical module, sending the first storage data of each child node to a centralized processing node, receiving and combining the first storage data of all child nodes by using the centralized processing node to obtain second storage data, wherein the second storage data comprises used storage data and unused storage data of all child nodes;
the transaction data acquisition module is used for setting unused storage data in the second storage data as a first weight, acquiring transaction request data through a first child node, and sending a request command to the centralized processing node by using the first child node according to the transaction request data;
the storage allocation module is used for receiving the request command by using the centralized processing node, and performing storage proportion allocation on the first weight according to the request command to obtain a storage allocation result, wherein the storage allocation result comprises each child node and an allocated storage unit; the method comprises the following steps: using formulas
Calculating a ratio of unused stored data of the child node in the first weight, resulting in a first ratio, wherein,
representing unused storage data of said child node,
the first weight is represented by a first value,
=1、……、
(ii) a Arranging and combining a plurality of first proportion ratios in a descending order to obtain a proportion distribution set; carrying out proportion division on unused storage data in the first storage data by using the proportion distribution set to obtain memory division data; combining the proportion allocation set and the memory division data to obtain a storage allocation result;
the data verification module is used for respectively calculating a storage verification value of the storage distribution result and a verification weight value of the transaction request data, and the storage verification value and the verification weight value are compared and verified to obtain a verification result; the method comprises the following steps: obtaining the storage allocation resultAllocating memory of each child node; using formulas
Calculating to obtain a first conversion value; wherein the content of the first and second substances,
indicating the allocated memory of each child node,
=1、……、
;
and
representing different preset scale factors;
representing a first correction factor, having a value of 0.23112; combining a plurality of first conversion values to obtain a storage verification value; acquiring a memory value of the transaction request data; using formulas
And calculating to obtain a verification weight value, wherein,
a memory value representing the transaction request data,
=1、……、
;
representing a second correction factor, having a value of 0.46224; wherein the content of the first and second substances,
if the compared storage verification value is the same as the verification weight value, a first identifier is obtained, the first identifier represents that the storage distribution result is normally distributed, and the next operation can be carried out;
if the compared storage verification value is different from the verification weight value, a second identifier is obtained, the second identifier represents that the distribution of the storage distribution result is abnormal, and the next operation is stopped;
the data distribution module is used for distributing the transaction request data according to the storage distribution result by using the verification result; the method comprises the following steps: sending the storage allocation result to the first child node by using the verification result; carrying out proportion division on the transaction request data by utilizing the first child node according to the storage distribution result to obtain a transaction data division set; sending the transaction data partition set to a plurality of child nodes in the storage distribution result; the sub-nodes receive and store the transaction data partition sets and generate a plurality of storage results; updating the first storage data by using the storage result to obtain third storage data, and sending a plurality of third storage data to the centralized processing node; updating the second storage data by using a plurality of third storage data to obtain fourth storage data, and setting unused storage data in the fourth storage data as a second weight;
compared with the prior art, in each aspect disclosed by the invention, a distributed data statistics module is used for acquiring first storage data of each child node, the first storage data of each child node is sent to a centralized processing node, the first storage data comprises used storage data and unused storage data of each child node, the centralized processing node is used for receiving and combining the first storage data of all child nodes to obtain second storage data, and the second storage data comprises used storage data and unused storage data of all child nodes; through statistics and division of used storage data and unused storage data, support is provided for subsequent data distribution conveniently;
setting unused storage data in the second storage data as a first weight by using a transaction data acquisition module, acquiring transaction request data through a first child node, and sending a request command to the centralized processing node by using the first child node according to the transaction request data; the transaction request data is acquired through any child node, so that the processing efficiency of the block chain on the transaction data can be improved;
the storage allocation module is used for receiving the request command by using the centralized processing node, and performing storage proportion allocation on the first weight according to the request command to obtain a storage allocation result, wherein the storage allocation result comprises each child node and an allocated storage unit; through the preset first weight and the distribution of the storage proportion, the storage effect of each sub-node can be effectively improved, and the problem that the capacity upper limit is easy to appear due to the fact that the storage of each sub-node is different is solved;
respectively calculating a storage verification value of the storage distribution result and a verification weight value of the transaction request data by using a data verification module, and comparing and verifying the storage verification value and the verification weight value to obtain a verification result; the method can effectively eliminate the abnormity of the data in the transmission process, can process the abnormal data in time, and can effectively improve the integrity of the data;
the transaction request data is distributed according to the storage distribution result by the data distribution module by utilizing the verification result, so that the defect that the storage capacity of a single child node in a block chain cluster in the existing scheme is easy to become the capacity upper limit of the whole block chain is overcome.
Fig. 3 is a schematic structural diagram of an electronic device of an apparatus for implementing a distributed storage area blockchain ledger according to the present invention.
The electronic device 1 may include a processor 10, a memory 11 and a bus, and may further include a computer program stored in the memory 11 and executable on the processor 10, such as a program 12 of a distributed memory blockchain ledger.
The memory 11 includes at least one type of readable storage medium, which includes flash memory, removable hard disk, multimedia card, card-type memory (e.g., SD or DX memory, etc.), magnetic memory, magnetic disk, optical disk, etc. The memory 11 may in some embodiments be an internal storage unit of the electronic device 1, such as a removable hard disk of the electronic device 1. The memory 11 may also be an external storage device of the electronic device 1 in other embodiments, such as a plug-in mobile hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like, which are provided on the electronic device 1. Further, the memory 11 may also include both an internal storage unit and an external storage device of the electronic device 1. The memory 11 may be used to store not only application software installed in the electronic device 1 and various types of data, such as codes of a distributed storage area blockchain ledger, but also temporarily store data that has been output or is to be output.
The processor 10 may be composed of an integrated circuit in some embodiments, for example, a single packaged integrated circuit, or may be composed of a plurality of integrated circuits packaged with the same or different functions, including one or more Central Processing Units (CPUs), microprocessors, digital Processing chips, graphics processors, and combinations of various control chips. The processor 10 is a Control Unit (Control Unit) of the electronic device, connects various components of the whole electronic device by using various interfaces and lines, and executes various functions and processes data of the electronic device 1 by running or executing programs or modules (for example, executing a distributed memory block chain book, etc.) stored in the memory 11 and calling data stored in the memory 11.
The bus may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The bus may be divided into an address bus, a data bus, a control bus, etc. The bus is arranged to enable connection communication between the memory 11 and at least one processor 10 or the like.
Fig. 3 shows only an electronic device with components, and it will be understood by those skilled in the art that the structure shown in fig. 3 does not constitute a limitation of the electronic device 1, and may comprise fewer or more components than those shown, or some components may be combined, or a different arrangement of components.
For example, although not shown, the electronic device 1 may further include a power supply (such as a battery) for supplying power to each component, and preferably, the power supply may be logically connected to the at least one processor 10 through a power management device, so as to implement functions of charge management, discharge management, power consumption management, and the like through the power management device. The power supply may also include any component of one or more dc or ac power sources, recharging devices, power failure detection circuitry, power converters or inverters, power status indicators, and the like. The electronic device 1 may further include various sensors, a bluetooth module, a Wi-Fi module, and the like, which are not described herein again.
Further, the electronic device 1 may further include a network interface, and optionally, the network interface may include a wired interface and/or a wireless interface (such as a WI-FI interface, a bluetooth interface, etc.), which are generally used for establishing a communication connection between the electronic device 1 and other electronic devices.
Optionally, the electronic device 1 may further comprise a user interface, which may be a Display (Display), an input unit (such as a Keyboard), and optionally a standard wired interface, a wireless interface. Alternatively, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an OLED (Organic Light-Emitting Diode) touch device, or the like. The display, which may also be referred to as a display screen or display unit, is suitable for displaying information processed in the electronic device 1 and for displaying a visualized user interface, among other things.
It is to be understood that the described embodiments are for purposes of illustration only and that the scope of the appended claims is not limited to such structures.
The program 12 of the distributed storage block chain ledger stored by the memory 11 in the electronic device 1 is a combination of a plurality of instructions, which when run in the processor 10, may implement the steps in fig. 1.
Specifically, the specific implementation method of the processor 10 for the instruction may refer to the description of the relevant steps in the embodiment corresponding to fig. 1, which is not described herein again.
Further, the integrated modules/units of the electronic device 1, if implemented in the form of software functional units and sold or used as separate products, may be stored in a non-volatile computer-readable storage medium. The computer-readable medium may include: any entity or device capable of carrying said computer program code, recording medium, U-disk, removable hard disk, magnetic disk, optical disk, computer Memory, Read-Only Memory (ROM).
In the embodiments provided in the present invention, it should be understood that the disclosed apparatus, device and method can be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the modules is only one logical functional division, and other divisions may be realized in practice.
The modules described as separate parts may or may not be physically separate, and parts displayed as modules may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the method of the embodiment.
In addition, functional modules 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 can be realized in a form of hardware, or in a form of hardware plus a software functional module.
It will be evident to those skilled in the art that the invention is not limited to the details of the foregoing illustrative embodiments, and that the present invention may be embodied in other specific forms without departing from the spirit or essential attributes thereof.
The present embodiments are therefore to be considered in all respects as illustrative and not restrictive, the scope of the invention being indicated by the appended claims rather than by the foregoing description, and all changes which come within the meaning and range of equivalency of the claims are therefore intended to be embraced therein. Any reference signs in the claims shall not be construed as limiting the claim concerned.
Furthermore, it is obvious that the word "comprising" does not exclude other elements or steps, and the singular does not exclude the plural. A plurality of units or means recited in the system claims may also be implemented by one unit or means in software or hardware. The terms second, etc. are used to denote names, but not any particular order.
Finally, it should be noted that the above examples are only intended to illustrate the technical process of the present invention and not to limit the same, and although the present invention has been described in detail with reference to the preferred embodiments, it will be understood by those skilled in the art that modifications or equivalent substitutions may be made to the technical process of the present invention without departing from the spirit and scope of the technical process of the present invention.