CN113434599A - Block chain account book synchronization method and device based on half nodes - Google Patents

Block chain account book synchronization method and device based on half nodes Download PDF

Info

Publication number
CN113434599A
CN113434599A CN202110725554.8A CN202110725554A CN113434599A CN 113434599 A CN113434599 A CN 113434599A CN 202110725554 A CN202110725554 A CN 202110725554A CN 113434599 A CN113434599 A CN 113434599A
Authority
CN
China
Prior art keywords
block
node
data
initial
synchronized
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
CN202110725554.8A
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.)
Beijing Big Data Center
University of Science and Technology Beijing USTB
Original Assignee
Beijing Big Data Center
University of Science and Technology Beijing USTB
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 Beijing Big Data Center, University of Science and Technology Beijing USTB filed Critical Beijing Big Data Center
Priority to CN202110725554.8A priority Critical patent/CN113434599A/en
Publication of CN113434599A publication Critical patent/CN113434599A/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/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/60Protecting data
    • G06F21/64Protecting data integrity, e.g. using checksums, certificates or signatures

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Computing Systems (AREA)
  • Health & Medical Sciences (AREA)
  • Bioethics (AREA)
  • General Health & Medical Sciences (AREA)
  • Computer Hardware Design (AREA)
  • Software Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention relates to the technical field of block chains, in particular to a block chain account book synchronization method and device based on half nodes, wherein the method comprises the following steps: creating a half-node; synchronizing all block header data from the best node to the half nodes; if the content of the block header data is verified to be correct, storing the block header data in a local account book; calculating the total space used by the saved block heads, and calculating the available space of the initial block; judging whether the block body data corresponding to the synchronous block number exists or not according to the block number of the block, the available space of the initial block body, the random number, the current total block number, the size of the memory occupied by the average block body and the number of the synchronous blocks; and verifying whether the synchronized block volume data is correct, and synchronizing the block volume data into a local account book if the synchronized block volume data is correct. According to the invention, the half-node selectively stores part of the block data body, so that the problems that the storage resources of the whole node are insufficient to store all data and the storage resources of the light node are insufficient are solved.

Description

Block chain account book synchronization method and device based on half nodes
Technical Field
The invention relates to the technical field of block chains, in particular to a block chain account book synchronization method and device based on half nodes.
Background
The blockchain is a novel information field technology utilizing cryptography and a distributed account book, and the distributed account book which is commonly maintained by a large number of nodes realizes data falsification prevention, traceability and decentralization. Since 2008, after the inventor proposes the blockchain technology and the specification in the white paper, the blockchain technology is widely concerned and has a great deal of technical research, in recent years, the blockchain has a great deal of application research in the fields of medical data, agricultural product traceability, scientific and technological application data and the like by virtue of the characteristics of non-falsification and traceability, the most successful is also the most widely applied to the financial field, the bitcoin is the application of the blockchain with the highest maturity at present, the bitcoin stimulates each account node user to create a new node and account in a mode of giving the bitcoin as excitation, and stabilizes the generation speed of the bitcoin new blockis ten minutes by adopting a workload proving mode, the nodes solve the complex mathematical problems through a great amount of calculation to obtain the values meeting the specification and broadcast the values to other nodes for verification, and the other nodes broadcast the confirmation information to the whole network after O (1) time complexity verification, the new block completes the uplink operation and synchronizes the record to the ledger of all nodes.
The distributed account book is a core guarantee for realizing non-tampering of the block chain, the mode of recording a centralized database of the traditional Internet is changed by using the distributed account book, the problems that the centralized database can be tampered and cannot be restored after being destroyed are avoided, and decentralized data storage is realized. Each node has the right of accounting, and once a new transaction occurs, the node immediately broadcasts the new transaction information to all nodes, and each node adds the new transaction information into the blockchain. Due to the particularity of the block chain, data synchronization of all nodes is required, and once new transaction information is generated, the transaction information is immediately sent to other nodes in a global broadcast mode to complete data synchronization.
The normal operation of the block chain depends on the unification of the distributed account book, but due to the popularization of the application of the block chain technology, data stored in a mature block chain are gradually increased, so that more and more data are needed to be recorded by the account book node, but the physical storage resource of a single common node is limited, the physical cost of the block chain accounting node is difficult to face to the greater and greater storage pressure, and the physical cost of the block chain accounting node is improved to a certain extent.
The current mainstream solution is that, in a partial block chain network, nodes are divided into full nodes and light nodes, so that some physical resources are not enough to support the nodes which store all data and can be added into a block chain at an opportunity, and the light nodes only store a block head header and do not store a block body, which results in insufficient storage of the block data.
Disclosure of Invention
The embodiment of the invention provides a block chain account book synchronization method and device based on half nodes. The technical scheme is as follows:
on one hand, a block chain account book synchronization method based on half nodes is provided, and the method is realized by a block chain management node and comprises the following steps:
s1, creating a half node and completing the deployment of the half node, initializing the half node, creating an initial storage space of the half node, and setting an initial maximum storage space;
s2, finding an optimal node, wherein the optimal node is a full node adjacent to the half node;
s3, synchronizing all the block header data from the best node to the half nodes;
s4, verifying whether the synchronized block header data is correct, and if the content of the block header data is verified to be correct, storing the block header data in a local account book of the half node;
s5, calculating a total space used by the block head saved in the local account book, and calculating an available space of an initial block, where the available space of the initial block is a difference between the initial maximum storage space and the total space used by the block head;
s6, judging whether to synchronize block data corresponding to the block number according to the block number of any block, the available space of the initial block, the random number, the current total block number, the memory occupied by the average block, and the number of blocks synchronized at the same time;
s7, if the block data corresponding to the block number is judged to be synchronized, verifying whether the synchronized block data is correct, and if the synchronized block data is verified to be correct, synchronizing the block data into the local account book;
s8, repeating S6-S7 until determining whether the block data of all blocks are synchronized, and completing the block chain account book synchronization operation.
Optionally, after verifying whether the synchronized block header data is correct, the method further includes:
if the content of the block header data is verified to be incorrect, discarding the block header data synchronized from the optimal node, and initiating an optimal node verification request to other nodes;
when the best node verification reply message of the other node is received, the jump is performed to S3.
Optionally, the calculating a total space used by the saved block headers in the local ledger and calculating an available space of the initial block includes:
the available space for the initial zone mass is calculated according to the following equation (1):
M=Msum-Mheader……(1)
where M denotes the available space for the initial zone mass, MsumRepresenting the initial maximum storage space, MheaderRepresenting the total space used by the block headers already stored in the local ledger.
Optionally, the determining whether to synchronize block volume data corresponding to the block number according to the block number of any block, the available space of the initial block volume, the random number, the current total block volume, the size of the memory occupied by the average block volume, and the number of blocks synchronized at the same time includes:
calculating whether the following inequality (2) holds:
Figure BDA0003137531710000031
wherein the content of the first and second substances,
Figure BDA0003137531710000032
wherein lrandomIs a random number which is uniformly distributed between 0 and 1, n is the current total block number, i is the judged block number, a is the size of the memory occupied by the average block, and u is the number of blocks which are synchronous at the same time;
if the inequality (2) is established, judging to synchronize the block volume data corresponding to the block number;
and if the inequality (2) does not hold, judging that the block volume data corresponding to the block number is not synchronized.
Optionally, the synchronizing the block volume data corresponding to the block number includes:
synchronous block number imin+u×(imin-1) to i0+u×imin-1 block volume data, wherein iminThe minimum of all block numbers.
Optionally, after verifying whether the synchronized block volume data is correct, the method further includes:
if the verification is incorrect, discarding the block head data and the block data synchronized from the optimal node, and initiating an optimal node verification request to other nodes;
when the best node verification reply message of the other node is received, the jump is performed to S3.
On the other hand, a device for synchronizing block chain accounts based on half nodes is provided, and the device is applied to a method for synchronizing block chain accounts based on half nodes, and the device comprises:
the system comprises a creating module, a storage module and a processing module, wherein the creating module is used for creating a half node and finishing the deployment of the half node, initializing the half node, creating an initial storage space of the half node and setting an initial maximum storage space;
the searching module is used for searching an optimal node, wherein the optimal node is a full node adjacent to the half nodes;
a synchronization module for synchronizing all block header data from the best node to the half nodes;
the verification module is used for verifying whether the synchronous block header data is correct or not, and storing the block header data in a local account book of the half node if the content of the block header data is verified to be correct;
a calculation module, configured to calculate a total space used by a block header that has been saved in the local account book, and calculate an available space of an initial block, where the available space of the initial block is a difference between the initial maximum storage space and the total space used by the block header;
the judging module is used for judging whether to synchronize the block data corresponding to the block number according to the block number of any block, the available space of the initial block, the random number, the current total block number, the memory occupied by the average block and the synchronous block number;
the verification module is used for verifying whether the synchronous block data is correct or not if the block data corresponding to the block number is judged to be synchronous, and synchronizing the block data into the local account book if the synchronous block data is correct;
and a repeat execution module for repeatedly executing S6-S7 until the block body data of all blocks are determined to be synchronous, and completing the block chain account book synchronization operation.
Optionally, the verification module is further configured to:
after verifying whether the synchronous block head data is correct or not, if verifying that the content of the block head data is incorrect, discarding the block head data synchronized from the optimal node, and initiating an optimal node verification request to other nodes;
when the best node verification reply message of the other node is received, the jump is performed to S3.
Optionally, the computing module is configured to:
the available space for the initial zone mass is calculated according to the following equation (1):
M=Msum-Mheader……(1)
where M denotes the available space for the initial zone mass, MsumRepresenting the initial maximum storage space, MheaderRepresenting the total space used by the block headers already stored in the local ledger.
Optionally, the determining module is configured to:
calculating whether the following inequality (2) holds:
Figure BDA0003137531710000051
wherein the content of the first and second substances,
Figure BDA0003137531710000052
wherein lrandomIs a random number which is uniformly distributed between 0 and 1, n is the current total block number, i is the judged block number, a is the size of the memory occupied by the average block, and u is the number of blocks which are synchronous at the same time;
if the inequality (2) is established, judging to synchronize the block volume data corresponding to the block number;
and if the inequality (2) does not hold, judging that the block volume data corresponding to the block number is not synchronized.
Optionally, the determining module is configured to:
synchronous block number imin+u×(imin-1) to i0+u×imin-1 block volume data, wherein iminThe minimum of all block numbers.
Optionally, the verification module is further configured to:
after verifying whether the synchronous block data is correct or not, if the synchronous block data is incorrect, discarding the synchronous block head data and the synchronous block data from the optimal node, and initiating an optimal node verification request to other nodes;
when the best node verification reply message of the other node is received, the jump is performed to S3.
In another aspect, a blockchain management node is provided, where the blockchain management node includes a processor and a memory, where the memory stores at least one instruction, and the at least one instruction is loaded and executed by the processor to implement the above half-node based blockchain ledger synchronization method.
In another aspect, a computer-readable storage medium is provided, where at least one instruction is stored, and the at least one instruction is loaded and executed by a processor to implement the above-mentioned half-node based blockchain ledger synchronization method.
The technical scheme provided by the embodiment of the invention has the beneficial effects that at least:
in the scheme, by introducing a half-node concept, the data body of a part of the blocks is selectively stored outside the head of the storage block, so that the problem that part of the node storage resources are insufficient to store all data is solved. Moreover, a random factor under the intervention of the block number is introduced, and the historical blocks are considered under the condition that the storage space is fixed and the newer blocks take precedence. In addition, the synchronization process takes the adjacent N blocks as a block group, so that whether the random number synchronizes the block group is calculated, and the communication pressure of continuously requesting data in the synchronization process is reduced.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed to be used in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the following description are only 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 flowchart of a block chain ledger synchronization method based on half nodes according to an embodiment of the present invention;
fig. 2 is a flowchart of a block chain ledger synchronization method based on half nodes according to an embodiment of the present invention;
fig. 3 is a schematic diagram of a node type and topology according to an embodiment of the present invention;
FIG. 4 is a block chain block structure and Merkel tree according to an embodiment of the present invention;
fig. 5 is a block diagram of a block chain ledger synchronization apparatus based on half nodes according to an embodiment of the present invention;
fig. 6 is a schematic structural diagram of a blockchain management node according to an embodiment of the present invention.
Detailed Description
In order to make the technical problems, technical solutions and advantages of the present invention more apparent, the following detailed description is given with reference to the accompanying drawings and specific embodiments.
The embodiment of the invention provides a block chain account book synchronization method based on half nodes, which can be realized by a block chain management node, wherein the block chain management node can be a terminal or a server. As shown in fig. 1, a flow chart of a block chain ledger synchronization method based on half nodes may include the following steps:
s101, creating a half node, completing deployment of the half node, initializing the half node, creating an initial storage space of the half node, and setting an initial maximum storage space;
s102, searching an optimal node, wherein the optimal node is a full node adjacent to a half node;
s103, synchronizing all block header data from the optimal node to the half node;
s104, verifying whether the synchronous block header data is correct or not, and storing the block header data in a local account book of the half node if the content of the block header data is verified to be correct;
s105, calculating the total space used by the block head stored in the local account book, and calculating the available space of the initial block, wherein the available space of the initial block is the difference value between the initial maximum storage space and the total space used by the block head;
s106, judging whether block data corresponding to synchronous block numbers exist or not according to the block numbers of any block, the available space of the initial block, the random number, the current total block number, the size of the memory occupied by the average block and the number of blocks which are synchronous at the same time;
s107, if the block data corresponding to the synchronous block number is judged, whether the synchronous block data is correct is verified, and if the synchronous block data is correct, the block data is synchronized into a local account book;
and S108, repeatedly executing S106-S107 until the block body data of all the blocks are judged to be synchronous, and finishing the block chain account book synchronization operation.
Optionally, after verifying whether the synchronized block header data is correct, the method further includes:
if the content of the verification block header data is incorrect, discarding the block header data synchronized from the optimal node, and initiating an optimal node verification request to other nodes;
when the best node verification reply message of the other node is received, the jump is performed S103.
Optionally, calculating the total space used by the block headers saved in the local ledger, and calculating the available space of the initial block, includes:
the available space for the initial zone mass is calculated according to the following equation (1):
M=Msum-Mheader……(1)
where M denotes the available space for the initial zone mass, MsumRepresenting the initial maximum storage space, MheaderRepresenting the total space used by the block header already stored in the local ledger.
Optionally, judging whether to synchronize block volume data corresponding to the block number according to the block number of any block, the available space of the initial block, the random number, the current total block number, the size of the memory occupied by the average block, and the number of blocks synchronized at the same time, includes:
calculating whether the following inequality (2) holds:
Figure BDA0003137531710000071
wherein the content of the first and second substances,
Figure BDA0003137531710000081
wherein lrandomIs a random number which is uniformly distributed between 0 and 1, n is the current total block number, i is the judged block number, a is the size of the memory occupied by the average block, and u is the number of blocks which are synchronous at the same time;
if the inequality (2) is established, judging the block volume data corresponding to the synchronous block number;
and if the inequality (2) does not hold, judging the block data corresponding to the asynchronous block number.
Optionally, the block volume data corresponding to the synchronization block number includes:
synchronous block number imin+u×(imin-1) to i0+u×imin-1 block volume data, wherein iminThe minimum of all block numbers.
Optionally, after verifying whether the synchronized block volume data is correct, the method further includes:
if the verification is incorrect, discarding block head data and block data synchronized from the optimal node, and initiating an optimal node verification request to other nodes;
when the best node verification reply message of the other node is received, the jump is performed S103.
In the embodiment of the invention, by introducing a half-node concept, the data body of a part of blocks is selectively stored outside the head of the storage block, so that the problem that part of node storage resources are insufficient to store all data is solved. Moreover, a random factor under the intervention of the block number is introduced, and the historical blocks are considered under the condition that the storage space is fixed and the newer blocks take precedence. In addition, the synchronization process takes the adjacent N blocks as a block group, so that whether the random number synchronizes the block group is calculated, and the communication pressure of continuously requesting data in the synchronization process is reduced.
The embodiment of the invention provides a block chain account book synchronization method based on half nodes, which can be realized by a block chain management node, wherein the block chain management node can be a terminal or a server. As shown in fig. 2, the processing flow of the method for synchronizing the blockchain ledger based on the half-node may include the following steps:
s201, creating a half node, completing deployment of the half node, initializing the half node, creating an initial storage space of the half node, and setting an initial maximum storage space.
In one possible implementation, in some prior art partition chain networks, nodes are divided into full nodes and light nodes, so that some nodes whose physical resources are insufficient to support them to store all data can have an opportunity to join the partition chain, and the light nodes only store the header headers and do not store the body of the partition. The invention introduces a half-node concept, the positioning of the half-node concept is between a full node and a light node, except for storing a whole chain header, a certain amount of block data is selectively stored according to the storage capacity of the self physical resource, and the problem that part of the node storage resources are not enough to store all data is solved. The network topology and the function positioning of the three types of nodes are shown in fig. 3, all the nodes can communicate with each other, the overall network topology structure is formed, the ratio of the total number of the nodes to the half number of the nodes is close, and the light nodes are only used for local verification, so that the influence on a whole block chain is less, any number of the light nodes can be provided, and most of the light nodes are PC terminals.
S202, searching an optimal node, wherein the optimal node is a full node adjacent to a half node.
And S203, synchronizing all the block header data from the optimal node to the half node.
The structure of a single block of the blockchain is generally divided into a header (header) and a body (body), wherein the blockchain is connected by the header, and the body stores transaction or data.
S204, verifying whether the synchronous block header data is correct or not, and storing the block header data in a local account book of the half node if the content of the block header data is correct.
In a possible implementation, as shown in fig. 4, taking the structure of a single bitcoin block as an example, the block header includes several parts, such as a version number, a previous block Hash value, a timestamp, a difficulty, a random number, and a Merkel root, where the Merkel root performs Hash operations on two adjacent transactions of the block and connects the two adjacent transactions, and the Hash results are continuously calculated in the same manner, and a final Hash256 value is formed as the Merkel root through continuous iterative calculation. The "last block Hash value" is a value obtained by performing Hash256 operation twice on all data of the block header of the previous block, and also includes the Merkel root of the previous block, so that once data is packed and linked up, if it is desired to modify transaction data of a certain block, all data of the Merkel tree of the block must be modified in sequence.
Meanwhile, according to the block structure, it can be known that the block chain must have a complete block head to ensure the integrity of the block chain, but if only the verification function is performed, it can be directly verified whether the block transaction or data in the block is not modified through the Merkel root value, rather than having complete transaction or data information.
Therefore, in the embodiment of the present invention, the block header data of the best node is verified in such a way that all the block header data of the best node is synchronized to the half nodes.
S205, if the content of the verification block header data is incorrect, discarding the block header data synchronized from the optimal node, and initiating an optimal node verification request to other nodes.
S206, when receiving the best node verification reply message of other nodes, skipping and executing S203.
S207, calculating a total space used by the block head stored in the local account book, and calculating an available space of the initial block, where the available space of the initial block is a difference between the initial maximum storage space and the total space used by the block head.
In one possible embodiment, the available space for the initial zone mass is calculated according to the following equation (1):
M=Msum-Mheader……(1)
where M denotes the available space for the initial zone mass, MsumRepresenting the initial maximum storage space, MheaderRepresenting the total space used by the block header already stored in the local ledger.
S208, judging whether the block data corresponding to the synchronous block number exists or not according to the block number of any block, the available space of the initial block, the random number, the current total block number, the memory occupied by the average block and the synchronous block number.
In one possible embodiment, the principle of the synchronization decision algorithm is as follows:
the number of blocks is n, the average block occupation of each block is stored as a, the total storage which can be stored is planned to be M, then M blocks can be expected to be synchronized, and the threshold value is a constant related to a, n and M.
Figure BDA0003137531710000101
Where i is the block number of a block, n is the total number of blocks, lrandomIs a random number with 0-1 uniform distribution.
Let the expected number of synchronization blocks be m:
Figure BDA0003137531710000102
Figure BDA0003137531710000103
Figure BDA0003137531710000104
due to the fact that
Figure BDA0003137531710000105
For harmonic series, without fixed summation formula, according to Euler's lawFormula (II)
Figure BDA0003137531710000106
(wherein C ≈ 0.577)
The following can be obtained:
Figure BDA0003137531710000111
Figure BDA0003137531710000112
Figure BDA0003137531710000113
therefore, to determine whether each block is synchronous, first, a random number l of 0-1 needs to be generatedrandomThen calculate
Figure BDA0003137531710000114
If yes, the block body of the block is synchronized.
However, since each synchronization needs to send a synchronization application signal to other nodes, the communication resource waste is easily caused by too many times of interaction, and the time from creation to application of a new node is long due to delay superposition, each u blocks are regarded as one block for judgment, so that new n and i can be set as:
Figure BDA0003137531710000115
wherein the content of the first and second substances,
Figure BDA0003137531710000118
indicating a ceiling operation.
Therefore, the synchronization judging method may be as follows:
calculating whether the following inequality (2) holds:
Figure BDA0003137531710000116
wherein the content of the first and second substances,
Figure BDA0003137531710000117
wherein lrandomIs a random number of 0-1 evenly distributed, n is the current total block number, i is the judged block number, a is the size of the memory occupied by the average block, and u is the number of blocks synchronized simultaneously.
If the inequality (2) is satisfied, the number of the synchronization block is judged to be imin+u×(imin-1) to i0+u×imin-1 block volume data, wherein iminThe minimum of all block numbers.
If the inequality (2) is not satisfied, judging that the number of the asynchronous block is imin+u×(imin-1) to i0+u×imin-1 block volume data.
In this way, by introducing the random factor under the intervention of the block number, the historical blocks are considered under the condition that the storage space is fixed and the newer blocks are prioritized, and the synchronization process takes the adjacent N blocks as the block group, so that whether the random number synchronizes the block group is calculated, and the communication pressure of continuously requesting data in the synchronization process is reduced.
S209, if the block volume data corresponding to the synchronous block number is judged, whether the synchronous block volume data is correct is verified, and if the synchronous block volume data is correct, the block volume data is synchronized into a local account book.
S210, if the verification is incorrect, discarding the block head data and the block data synchronized from the optimal node, and initiating an optimal node verification request to other nodes.
S211, when receiving the best node verification reply message of other nodes, jumping to execute S203.
S212, repeating S208-S211 until determining whether the block data of all blocks are synchronized, and completing the block chain account book synchronization operation.
In the embodiment of the invention, by introducing a half-node concept, the data body of a part of blocks is selectively stored outside the head of the storage block, so that the problem that part of node storage resources are insufficient to store all data is solved. Moreover, a random factor under the intervention of the block number is introduced, and the historical blocks are considered under the condition that the storage space is fixed and the newer blocks take precedence. In addition, the synchronization process takes the adjacent N blocks as a block group, so that whether the random number synchronizes the block group is calculated, and the communication pressure of continuously requesting data in the synchronization process is reduced.
Fig. 5 is a block diagram illustrating a half-node based blockchain ledger synchronization apparatus, according to an example embodiment. Referring to fig. 5, the apparatus includes:
a creating module 510, configured to create a half node and complete deployment of the half node, initialize the half node, create an initial storage space of the half node, and set an initial maximum storage space;
a searching module 520, configured to search for an optimal node, where the optimal node is a full node adjacent to the half node;
a synchronization module 530 for synchronizing all block header data from the best node to the half nodes;
a verification module 540, configured to verify whether the synchronized block header data is correct, and if the content of the block header data is verified to be correct, store the block header data in a local book of the half node;
a calculating module 550, configured to calculate a total space used by the block head that has been saved in the local ledger, and calculate an available space of an initial block, where the available space of the initial block is a difference between the initial maximum storage space and the total space used by the block head;
a judging module 560, configured to judge whether to synchronize block data corresponding to the block number according to the block number of any block, the available space of the initial block, a random number, the current total block number, the size of the memory occupied by the average block, and the number of blocks synchronized at the same time;
a verification module 540, configured to verify whether the synchronized block volume data is correct if it is determined that the block volume data corresponding to the block number is synchronized, and synchronize the block volume data into the local ledger if the synchronized block volume data is correct;
the repeated execution module 570 is configured to repeatedly execute S6-S7 until the synchronization of the blockchain ledger is completed after determining whether the block data of all the blocks are synchronized.
Optionally, the verification module 540 is further configured to:
after verifying whether the synchronous block head data is correct or not, if verifying that the content of the block head data is incorrect, discarding the block head data synchronized from the optimal node, and initiating an optimal node verification request to other nodes;
when the best node verification reply message of the other node is received, the jump is performed to S3.
Optionally, the calculating module 550 is configured to:
the available space for the initial zone mass is calculated according to the following equation (1):
M=Msum-Mheader……(1)
where M denotes the available space for the initial zone mass, MsumRepresenting the initial maximum storage space, MheaderRepresenting the total space used by the block headers already stored in the local ledger.
Optionally, the determining module 560 is configured to:
calculating whether the following inequality (2) holds:
Figure BDA0003137531710000131
wherein the content of the first and second substances,
Figure BDA0003137531710000132
wherein lrandomIs 0-1 random number uniformly distributed, n is the total current block number, i is the judged block number, a is the memory size occupied by the average block, u is the synchronous blockThe number of the particles;
if the inequality (2) is established, judging to synchronize the block volume data corresponding to the block number;
and if the inequality (2) does not hold, judging that the block volume data corresponding to the block number is not synchronized.
Optionally, the determining module 560 is configured to:
synchronous block number imin+u×(imin-1) to i0+u×imin-1 block volume data, wherein iminThe minimum of all block numbers.
Optionally, the verification module 540 is further configured to:
after verifying whether the synchronous block data is correct or not, if the synchronous block data is incorrect, discarding the synchronous block head data and the synchronous block data from the optimal node, and initiating an optimal node verification request to other nodes;
when the best node verification reply message of the other node is received, the jump is performed to S3.
In the embodiment of the invention, by introducing a half-node concept, the data body of a part of blocks is selectively stored outside the head of the storage block, so that the problem that part of node storage resources are insufficient to store all data is solved. Moreover, a random factor under the intervention of the block number is introduced, and the historical blocks are considered under the condition that the storage space is fixed and the newer blocks take precedence. In addition, the synchronization process takes the adjacent N blocks as a block group, so that whether the random number synchronizes the block group is calculated, and the communication pressure of continuously requesting data in the synchronization process is reduced.
Fig. 6 is a schematic structural diagram of a blockchain management node 600 according to an embodiment of the present invention, where the blockchain management node 600 may generate relatively large differences due to different configurations or performances, and may include one or more processors (CPUs) 601 and one or more memories 602, where the memories 602 store at least one instruction, and the at least one instruction is loaded and executed by the processors 601 to implement the steps of the half-node-based blockchain ledger synchronization method.
In an exemplary embodiment, a computer-readable storage medium, such as a memory, is also provided that includes instructions executable by a processor in a terminal to perform the half-node based blockchain ledger synchronization method described above. For example, the computer readable storage medium may be a ROM, a Random Access Memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, and the like.
It will be understood by those skilled in the art that all or part of the steps for implementing the above embodiments may be implemented by hardware, or may be implemented by a program instructing relevant hardware, where the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a magnetic disk or an optical disk, etc.
The above description is only for the purpose of illustrating the preferred embodiments of the present invention and is not to be construed as limiting the invention, and any modifications, equivalents, improvements and the like that fall within the spirit and principle of the present invention are intended to be included therein.

Claims (10)

1. A block chain account book synchronization method based on half nodes is characterized by comprising the following steps:
s1, creating a half node and completing the deployment of the half node, initializing the half node, creating an initial storage space of the half node, and setting an initial maximum storage space;
s2, finding an optimal node, wherein the optimal node is a full node adjacent to the half node;
s3, synchronizing all the block header data from the best node to the half nodes;
s4, verifying whether the synchronized block header data is correct, and if the content of the block header data is verified to be correct, storing the block header data in a local account book of the half node;
s5, calculating a total space used by the block head saved in the local account book, and calculating an available space of an initial block, where the available space of the initial block is a difference between the initial maximum storage space and the total space used by the block head;
s6, judging whether to synchronize block data corresponding to the block number according to the block number of any block, the available space of the initial block, the random number, the current total block number, the memory occupied by the average block, and the number of blocks synchronized at the same time;
s7, if the block data corresponding to the block number is judged to be synchronized, verifying whether the synchronized block data is correct, and if the synchronized block data is verified to be correct, synchronizing the block data into the local account book;
s8, repeating S6-S7 until determining whether the block data of all blocks are synchronized, and completing the block chain account book synchronization operation.
2. The method of claim 1, wherein after verifying whether the synchronized block header data is correct, the method further comprises:
if the content of the block header data is verified to be incorrect, discarding the block header data synchronized from the optimal node, and initiating an optimal node verification request to other nodes;
when the best node verification reply message of the other node is received, the jump is performed to S3.
3. The method of claim 1, wherein calculating the total space used for the block headers already stored in the local ledger, calculating the available space for the initial block, comprises:
the available space for the initial zone mass is calculated according to the following equation (1):
M=Msum-Mheader……(1)
where M denotes the available space for the initial zone mass, MsumRepresenting the initial maximum storage space, MheaderRepresenting the total space used by the block headers already stored in the local ledger.
4. The method according to claim 3, wherein the determining whether to synchronize the block data corresponding to the block number according to the block number of any block, the available space of the initial block, the random number, the current total block number, the average block occupied memory size, and the number of blocks synchronized at the same time comprises:
calculating whether the following inequality (2) holds:
Figure FDA0003137531700000021
wherein the content of the first and second substances,
Figure FDA0003137531700000022
wherein lrandomIs a random number which is uniformly distributed between 0 and 1, n is the current total block number, i is the judged block number, a is the size of the memory occupied by the average block, and u is the number of blocks which are synchronous at the same time;
if the inequality (2) is established, judging to synchronize the block volume data corresponding to the block number;
and if the inequality (2) does not hold, judging that the block volume data corresponding to the block number is not synchronized.
5. The method according to claim 4, wherein the synchronizing the block volume data corresponding to the block number comprises:
synchronous block number imin+u×(imin-1) to i0+u×imin-1 block volume data, wherein iminThe minimum of all block numbers.
6. The method of claim 1, wherein after verifying whether the synchronized block data is correct, further comprising:
if the verification is incorrect, discarding the block head data and the block data synchronized from the optimal node, and initiating an optimal node verification request to other nodes;
when the best node verification reply message of the other node is received, the jump is performed to S3.
7. A block chain account book synchronization device based on half nodes is characterized in that the device comprises:
the system comprises a creating module, a storage module and a processing module, wherein the creating module is used for creating a half node and finishing the deployment of the half node, initializing the half node, creating an initial storage space of the half node and setting an initial maximum storage space;
the searching module is used for searching an optimal node, wherein the optimal node is a full node adjacent to the half nodes;
a synchronization module for synchronizing all block header data from the best node to the half nodes;
the verification module is used for verifying whether the synchronous block header data is correct or not, and storing the block header data in a local account book of the half node if the content of the block header data is verified to be correct;
a calculating module, configured to calculate a total space used by the block head that has been saved in the local ledger, and calculate an available space of an initial block, where the available space of the initial block is a difference between the initial maximum storage space and the total space used by the block head:
the judging module is used for judging whether to synchronize the block data corresponding to the block number according to the block number of any block, the available space of the initial block, the random number, the current total block number, the memory occupied by the average block and the synchronous block number;
the verification module is used for verifying whether the synchronous block data is correct or not if the block data corresponding to the block number is judged to be synchronous, and synchronizing the block data into the local account book if the synchronous block data is correct;
and a repeat execution module for repeatedly executing S6-S7 until the block body data of all blocks are determined to be synchronous, and completing the block chain account book synchronization operation.
8. The apparatus of claim 7, wherein the verification module is further configured to:
after verifying whether the synchronous block head data is correct or not, if verifying that the content of the block head data is incorrect, discarding the block head data synchronized from the optimal node, and initiating an optimal node verification request to other nodes;
when the best node verification reply message of the other node is received, the jump is performed to S3.
9. The apparatus of claim 7, wherein the computing module is configured to:
the available space for the initial zone mass is calculated according to the following equation (1):
M=Msum-Mheader……(1)
where M denotes the available space for the initial zone mass, MsumRepresenting the initial maximum storage space, MheaderRepresenting the total space used by the block headers already stored in the local ledger.
10. The apparatus of claim 9, wherein the determining module is configured to:
calculating whether the following inequality (2) holds:
Figure FDA0003137531700000031
wherein the content of the first and second substances,
Figure FDA0003137531700000041
wherein lrandomIs a random number which is uniformly distributed between 0 and 1, n is the current total block number, i is the judged block number, a is the size of the memory occupied by the average block, and u is the number of blocks which are synchronous at the same time;
if the inequality (2) is established, judging to synchronize the block volume data corresponding to the block number;
and if the inequality (2) does not hold, judging that the block volume data corresponding to the block number is not synchronized.
CN202110725554.8A 2021-06-29 2021-06-29 Block chain account book synchronization method and device based on half nodes Pending CN113434599A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110725554.8A CN113434599A (en) 2021-06-29 2021-06-29 Block chain account book synchronization method and device based on half nodes

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110725554.8A CN113434599A (en) 2021-06-29 2021-06-29 Block chain account book synchronization method and device based on half nodes

Publications (1)

Publication Number Publication Date
CN113434599A true CN113434599A (en) 2021-09-24

Family

ID=77757786

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110725554.8A Pending CN113434599A (en) 2021-06-29 2021-06-29 Block chain account book synchronization method and device based on half nodes

Country Status (1)

Country Link
CN (1) CN113434599A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114219477A (en) * 2021-11-03 2022-03-22 重庆邮电大学 Block chain data storage expansion method based on-chain storage

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114219477A (en) * 2021-11-03 2022-03-22 重庆邮电大学 Block chain data storage expansion method based on-chain storage
CN114219477B (en) * 2021-11-03 2022-09-16 重庆邮电大学 Block chain data storage expansion method based on-chain storage

Similar Documents

Publication Publication Date Title
EP3678346B1 (en) Blockchain smart contract verification method and apparatus, and storage medium
TWI737165B (en) Method and device for sending resources across chains
TWI836988B (en) Computer-implemented method, system, and computer-readable storage medium for maintaining blocks of a blockchain in a partitioned blockchain network
CN110737664B (en) Method and device for synchronizing block chain link points
CN109165945B (en) Representative node device election method and device, computer device and storage medium
CN111008201B (en) Method and apparatus for parallel modification and reading of state trees
CN113329031A (en) Method and device for generating state tree of block
CN109146490B (en) Block generation method, device and system
KR102337760B1 (en) Apparatus and method for adaptively managing sharded blockchain network based on Deep Q Network
CN109961364B (en) Transaction method and system based on directed acyclic graph
CN111061735B (en) Capacity expansion method and device based on single-chain blockchain
CN111800274B (en) Verifiable calculation energy consumption optimization method based on block chain
CN113452747B (en) Extensible and safe consensus method, system, storage medium and intelligent terminal
CN111818185A (en) Method and device for starting intelligent contract, electronic equipment and storage medium
CN111698094A (en) Consensus method based on block chain system and block chain system
CN113434599A (en) Block chain account book synchronization method and device based on half nodes
CN111640018A (en) Block chain transaction existence verification method and device
CN114529415A (en) Transaction verification method and device based on block chain and electronic equipment
CN112711633B (en) Block chain-based BIM drawing multi-person collaborative creation method and system
CN115988001A (en) Consensus voting processing method, device, equipment and medium for block chain system
CN113034137A (en) Data processing method and device based on block chain and related equipment
CN112069259B (en) Multi-cloud environment data storage system and method based on blockchain
CN113157450A (en) Method and apparatus for performing blocks in a blockchain system
CN109544329B (en) Method, device and system for matching
CN111177262A (en) Block chain consensus method, related device and system

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