A blockchain ledger synchronization method and device based on half-node

By introducing the concept of half-node and random factors under the intervention of block number, blockchain data is selectively stored, the problem of insufficient node storage resources is solved, communication pressure is reduced, and the synchronization efficiency of blockchain ledgers is improved.

CN113434599BActive Publication Date: 2025-04-04BEIJING BIG DATA CENT +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202110725554.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-06-29
Publication Date
2025-04-04
Estimated Expiration
2041-06-29

AI Technical Summary

Technical Problem

In blockchain networks, some nodes are unable to face the growing pressure on data storage due to insufficient storage resources, resulting in an increase in physical costs.

Method used

Introducing the concept of half-node, in addition to storing block headers, it also selectively stores the data body of some blocks, and prioritizes newer blocks in the storage space through random factors under block number intervention, while taking into account historical blocks. The synchronization process regards N adjacent blocks as block groups, and calculates whether the random number synchronizes the block group to reduce communication pressure.

Benefits of technology

It effectively solves the problem of insufficient node storage resources, reduces the communication pressure of the synchronization process, and improves the synchronization efficiency of the blockchain ledger.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113434599B_ABST
    Figure CN113434599B_ABST
Patent Text Reader

Abstract

The present invention relates to the field of blockchain technology, and in particular to a blockchain ledger synchronization method and device based on a half-node, the method comprising: creating a half-node; synchronizing all block header data from the best node to the half-node; if the content of the block header data is verified to be correct, the block header data is stored in a local ledger; the total space used by the saved block headers is calculated, and the available space of the initial block body is calculated; according to the block number of the block, the available space of the initial block body, the random number, the current total number of blocks, the average block body occupied memory size, and the number of blocks synchronized at the same time, it is determined whether the block body data corresponding to the block number is synchronized; verify whether the synchronized block body data is correct, and if the verification is correct, the block body data is synchronized to the local ledger. The present invention selectively stores part of the block data body through the half-node, so as to solve the problem that the storage resources of the full node are insufficient to store all the data and the light node storage data is insufficient.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of blockchain technology, and in particular to a blockchain ledger synchronization method and device based on a half-node. Background Art

[0002] Blockchain is a new information technology that uses cryptography and distributed ledgers. It achieves data immutability, traceability, and decentralization through distributed ledgers maintained by a large number of nodes. Since Satoshi Nakamoto proposed blockchain technology and specifications in his white paper in 2008, blockchain technology has received widespread attention and a large number of technical studies have been conducted. In recent years, blockchain has been widely used in the fields of medical data, agricultural product traceability, and scientific and technological application data due to its immutability and traceability. Among them, the most successful and widely used is in the financial field. Bitcoin is currently the most mature blockchain application. Bitcoin uses Bitcoin as an incentive to encourage each ledger node user to create new nodes and record accounts, and uses proof of work to stabilize the speed of generating new Bitcoin blocks to ten minutes. Nodes solve complex mathematical problems through a large number of calculations to obtain values ​​that meet the requirements, and broadcast them to other nodes for verification. After other nodes pass the verification with O(1) time complexity, they broadcast the confirmation information to the entire network. The new block completes the chain operation and synchronizes the record to the ledgers of all nodes.

[0003] Distributed ledgers are the core guarantee for blockchain to be tamper-proof. The use of distributed ledgers has changed the traditional Internet centralized database record mode, avoiding the problem that centralized databases can be tampered with and cannot be restored after being destroyed, and realizing the decentralization of data storage. Each node has the right to record accounts. Once a new transaction occurs, it will be broadcast to all nodes immediately. Each node will add the new transaction information to the blockchain. Due to the huge number of accounting nodes in the blockchain, if you want to tamper with a certain data, you must tamper with the ledgers of more than half of the nodes in the entire domain at the same time. This is impossible to do. Therefore, the blockchain can ensure that the data cannot be tampered with. Due to the particularity of the blockchain, it must rely on the data synchronization of all nodes. Once new transaction information is generated, it will be immediately sent to other nodes in the form of global broadcast to complete data synchronization.

[0004] The normal operation of the blockchain depends on the unification of distributed ledgers. However, due to the promotion of blockchain technology applications, the amount of data stored in a more mature blockchain is gradually increasing, so the data that the ledger nodes need to record is also increasing. However, the physical storage resources of a single ordinary node are limited, and it is difficult to cope with the increasing storage pressure. This has increased the physical cost of the blockchain accounting nodes to a certain extent.

[0005] The current mainstream solution is to divide nodes into full nodes and light nodes in some blockchain networks, so that some nodes whose physical resources are insufficient to support the storage of all data can have the opportunity to join the blockchain. Light nodes only save the block header but not the block body. This setting leads to insufficient storage of block data. Summary of the invention

[0006] The embodiment of the present invention provides a blockchain ledger synchronization method and device based on a half-node. The technical solution is as follows:

[0007] On the one hand, a blockchain ledger synchronization method based on a half node is provided, the method is implemented by a blockchain management node, and the method includes:

[0008] S1. Create a half node and complete the deployment of the half node, initialize the half node, create the initial storage space of the half node, and set the initial maximum storage space;

[0009] S2. Find the best node, where the best node is a full node adjacent to the half node;

[0010] S3. Synchronize all block header data from the best node to the half node;

[0011] S4. Verify whether the synchronized block header data is correct. If the content of the block header data is verified to be correct, store the block header data in the local ledger of the half node.

[0012] S5. Calculate the total space used by the saved block headers in the local account book, and calculate the available space of the initial block body, where the available space of the initial block body is the difference between the initial maximum storage space and the total space used by the block header;

[0013] S6. Determine 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 body, the random number, the current total number of blocks, the average memory size occupied by the block body, and the number of blocks synchronized at the same time;

[0014] S7. If it is determined that the block data corresponding to the block number is synchronized, verify whether the synchronized block data is correct. If the verification is correct, synchronize the block data to the local account book;

[0015] S8. Repeat S6-S7 until it is determined whether the block data of all blocks are synchronized, and the blockchain ledger synchronization operation is completed.

[0016] Optionally, after verifying whether the synchronized block header data is correct, the method further includes:

[0017] If the content of the block header data is verified to be incorrect, the block header data synchronized from the best node is discarded, and a best node verification request is initiated to other nodes;

[0018] When receiving the best node verification reply message from other nodes, jump to execute S3.

[0019] Optionally, calculating the total space used by the saved block headers in the local ledger and calculating the available space of the initial block body includes:

[0020] The available space of the initial block is calculated according to the following formula (1):

[0021] M=M sum -M header ……(1)

[0022] Among them, M represents the available space of the initial block, M sum Indicates the initial maximum storage space, M header Represents the total space used by saved block headers in the local ledger.

[0023] Optionally, judging whether to synchronize the block data corresponding to the block number of any block, based on the block number of the block, the available space of the initial block body, a random number, the current total number of blocks, the average memory size occupied by the block body, and the number of blocks synchronized simultaneously, includes:

[0024] Calculate whether the following inequality (2) holds:

[0025]

[0026] in,

[0027] Among them, l random is a random number uniformly distributed between 0 and 1, n is the total number of blocks at present, i is the block number to be judged, a is the average memory size occupied by the block body, and u is the number of blocks synchronized at the same time;

[0028] If the above inequality (2) holds, then determine to synchronize the block data corresponding to the block number;

[0029] If the above inequality (2) does not hold, it is determined that the block body data corresponding to the block number is not synchronized.

[0030] Optionally, synchronizing the block data corresponding to the block number includes:

[0031] The synchronization block number is i min +u×(i min -1) to i0+u×i min -1 block data, where imin The minimum value among all block numbers.

[0032] Optionally, after verifying whether the synchronized block data is correct, the process further includes:

[0033] If the verification is incorrect, the block header data and block body data synchronized from the best node are discarded, and a best node verification request is initiated to other nodes;

[0034] When receiving the best node verification reply message from other nodes, jump to execute S3.

[0035] On the other hand, a half-node-based blockchain ledger synchronization device is provided, which is applied to a half-node-based blockchain ledger synchronization method, and the device includes:

[0036] A creation module, used to create a half node and complete the deployment of the half node, initialize the half node, create the initial storage space of the half node, and set the initial maximum storage space;

[0037] A search module, used for searching for an optimal node, wherein the optimal node is a full node adjacent to the half node;

[0038] A synchronization module, used to synchronize all block header data from the best node to the half node;

[0039] A verification module, used to verify whether the synchronized block header data is correct. If the content of the block header data is verified to be correct, the block header data is stored in the local ledger of the half node;

[0040] A calculation module, used to calculate the total space used by the block headers saved in the local account book, and calculate the available space of the initial block body, where the available space of the initial block body is the difference between the initial maximum storage space and the total space used by the block headers;

[0041] A judgment module, used to judge whether to synchronize the block data corresponding to the block number of any block according to the block number of the block, the available space of the initial block body, the random number, the current total number of blocks, the average memory size occupied by the block body, and the number of blocks synchronized at the same time;

[0042] A verification module, for verifying whether the synchronized block data corresponding to the block number is correct if it is determined that the synchronized block data is correct, and if the verification is correct, synchronizing the block data to the local account book;

[0043] The repeated execution module is used to repeatedly execute S6-S7 until it is determined whether the block body data of all blocks are synchronized, thereby completing the blockchain ledger synchronization operation.

[0044] Optionally, the verification module is further used to:

[0045] After verifying whether the synchronized block header data is correct, if the content of the block header data is verified to be incorrect, the block header data synchronized from the best node is discarded, and a best node verification request is initiated to other nodes;

[0046] When receiving the best node verification reply message from other nodes, jump to execute S3.

[0047] Optionally, the computing module is used to:

[0048] The available space of the initial block is calculated according to the following formula (1):

[0049] M=M sum -M header ……(1)

[0050] Among them, M represents the available space of the initial block, M sum Indicates the initial maximum storage space, M header Represents the total space used by saved block headers in the local ledger.

[0051] Optionally, the judging module is used to:

[0052] Calculate whether the following inequality (2) holds:

[0053]

[0054] in,

[0055] Among them, l random is a random number uniformly distributed between 0 and 1, n is the total number of blocks at present, i is the block number to be judged, a is the average memory size occupied by the block body, and u is the number of blocks synchronized at the same time;

[0056] If the above inequality (2) holds, then determine to synchronize the block data corresponding to the block number;

[0057] If the above inequality (2) does not hold, it is determined that the block body data corresponding to the block number is not synchronized.

[0058] Optionally, the judging module is used to:

[0059] The synchronization block number is i min +u×(i min -1) to i0+u×i min -1 block data, where i min The minimum value among all block numbers.

[0060] Optionally, the verification module is further used to:

[0061] After verifying whether the synchronized block data is correct, if the verification is incorrect, the block header data and block data synchronized from the best node are discarded, and a best node verification request is initiated to other nodes;

[0062] When receiving the best node verification reply message from other nodes, jump to execute S3.

[0063] On the other hand, a blockchain management node is provided, comprising a processor and a memory, wherein the memory stores at least one instruction, and the at least one instruction is loaded and executed by the processor to implement the above-mentioned half-node-based blockchain ledger synchronization method.

[0064] On the other hand, a computer-readable storage medium is provided, wherein at least one instruction is stored in the storage medium, 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.

[0065] The beneficial effects brought about by the technical solution provided by the embodiment of the present invention include at least:

[0066] In the above scheme, by introducing the concept of half-node, in addition to storing the block header, the data body of some blocks is selectively stored to solve the problem that the storage resources of some nodes are insufficient to store all the data. In addition, by introducing the random factor under the intervention of the block number, when the storage space is fixed, the historical blocks are taken into account while the newer blocks are given priority. In addition, the synchronization process regards the adjacent N blocks as a block group, so as to calculate whether the random number synchronizes the block group, reducing the communication pressure of the synchronization process that continuously requests data. BRIEF DESCRIPTION OF THE DRAWINGS

[0067] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0068] Figure 1 This is a flow chart of a blockchain ledger synchronization method based on a half-node provided by an embodiment of the present invention;

[0069] Figure 2 This is a flow chart of a blockchain ledger synchronization method based on a half-node provided by an embodiment of the present invention;

[0070] Figure 3 It is a schematic diagram of node types and topology provided by an embodiment of the present invention;

[0071] Figure 4 It is a schematic diagram of a blockchain block structure and a Merkel tree provided by an embodiment of the present invention;

[0072] Figure 5 It is a block diagram of a blockchain ledger synchronization device based on a half node provided by an embodiment of the present invention;

[0073] Figure 6 It is a structural diagram of a blockchain management node provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0074] In order to make the technical problems, technical solutions and advantages to be solved by the present invention more clear, a detailed description will be given below with reference to the accompanying drawings and specific embodiments.

[0075] The embodiment of the present invention provides a blockchain ledger synchronization method based on a half-node, which can be implemented by a blockchain management node, which can be a terminal or a server. Figure 1 The flowchart of the blockchain ledger synchronization method based on a half-node is shown, and the processing flow of the method may include the following steps:

[0076] S101, creating a half node and completing the deployment of the half node, initializing the half node, creating the initial storage space of the half node, and setting the initial maximum storage space;

[0077] S102, searching for the best node, where the best node is a full node adjacent to the half node;

[0078] S103. Synchronize all block header data from the best node to the half node;

[0079] S104. Verify whether the synchronized block header data is correct. If the content of the block header data is verified to be correct, store the block header data in the local ledger of the half node.

[0080] S105. Calculate the total space used by the saved block headers in the local account book, and calculate the available space of the initial block body. The available space of the initial block body is the difference between the initial maximum storage space and the total space used by the block header.

[0081] S106, 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 body, the random number, the current total number of blocks, the average memory size occupied by the block body, and the number of blocks synchronized at the same time;

[0082] S107. If the block data corresponding to the synchronization block number is determined, verify whether the synchronized block data is correct. If the verification is correct, synchronize the block data to the local account book;

[0083] S108. Repeat S106-S107 until it is determined whether the block data of all blocks are synchronized, and the blockchain ledger synchronization operation is completed.

[0084] Optionally, after verifying whether the synchronized block header data is correct, the method further includes:

[0085] If the content of the verified block header data is incorrect, the block header data synchronized from the best node is discarded, and a best node verification request is initiated to other nodes;

[0086] When receiving the best node verification reply message from other nodes, jump to execute S103.

[0087] Optionally, calculate the total space used by the saved block headers in the local ledger and calculate the available space for the initial block body, including:

[0088] The available space of the initial block is calculated according to the following formula (1):

[0089] M=M sum -M header ……(1)

[0090] Among them, M represents the available space of the initial block, M sum Indicates the initial maximum storage space, M header Indicates the total space used by saved block headers in the local ledger.

[0091] Optionally, 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 body, the random number, the current total number of blocks, the average memory size occupied by the block body, and the number of blocks synchronized at the same time, includes:

[0092] Calculate whether the following inequality (2) holds:

[0093]

[0094] in,

[0095] Among them, l random is a random number uniformly distributed between 0 and 1, n is the total number of blocks at present, i is the block number to be judged, a is the average memory size occupied by the block body, and u is the number of blocks synchronized at the same time;

[0096] If the above inequality (2) holds, the block data corresponding to the synchronization block number is determined;

[0097] If the above inequality (2) does not hold, the block body data corresponding to the asynchronous block number is determined.

[0098] Optionally, the block body data corresponding to the synchronization block number includes:

[0099] The synchronization block number is i min +u×(i min -1) to i0+u×i min -1 block data, where i min The minimum value among all block numbers.

[0100] Optionally, after verifying whether the synchronized block data is correct, it also includes:

[0101] If the verification is incorrect, the block header data and block body data synchronized from the best node will be discarded, and a best node verification request will be sent to other nodes;

[0102] When receiving the best node verification reply message from other nodes, jump to execute S103.

[0103] In the embodiment of the present invention, by introducing the concept of half-node, in addition to storing the block header, the data body of some blocks is selectively stored to solve the problem that the storage resources of some nodes are insufficient to store all the data. In addition, by introducing the random factor under the intervention of the block number, historical blocks are taken into account while the newer blocks are given priority when the storage space is fixed. In addition, the synchronization process regards the adjacent N blocks as a block group, so as to calculate whether the random number synchronizes the block group, reducing the communication pressure of the synchronization process that continuously requests data.

[0104] The embodiment of the present invention provides a blockchain ledger synchronization method based on a half-node, which can be implemented by a blockchain management node, which can be a terminal or a server. Figure 2 The flowchart of the blockchain ledger synchronization method based on a half-node is shown, and the processing flow of the method may include the following steps:

[0105] S201. Create a half node and complete the deployment of the half node, initialize the half node, create the initial storage space of the half node, and set the initial maximum storage space.

[0106] In a feasible implementation, in some blockchain networks of the current prior art, nodes are divided into full nodes and light nodes, so that some nodes whose physical resources are insufficient to support the storage of all data can have the opportunity to join the blockchain. Light nodes only store the block header, not the block body. The present invention introduces the concept of half-nodes, which are positioned between full nodes and light nodes. In addition to storing the header of the entire chain, they selectively store a certain amount of block data based on the storage capacity of their own physical resources, solving the problem that the storage resources of some nodes are insufficient to store all data. The network topology and functional positioning of the three types of nodes are as follows: Figure 3As shown, all nodes can communicate with each other, and the overall topology is a mesh structure, in which the number of full nodes and half nodes are similar. Since light nodes are only used for local verification, they have little impact on the overall blockchain. There can be any number of light nodes, most of which are PC-side.

[0107] S202. Find the best node, which is a full node adjacent to the half node.

[0108] S203. Synchronize all block header data from the best node to the half node.

[0109] Among them, the structure of a single block in the blockchain is usually divided into two parts: the block header and the block body. The blockchain chain is connected by the block header, and the block body stores transactions or data.

[0110] S204: Verify whether the synchronized block header data is correct. If the content of the block header data is verified to be correct, store the block header data in the local ledger of the half node.

[0111] In a feasible implementation, Figure 4 As shown in the figure, taking the structure of a single Bitcoin block as an example, the block header includes the version number, the hash value of the previous block, the timestamp, the difficulty, the random number, and the Merkel root. The Merkel root is the hash operation of two adjacent transactions of the block and connected. The hash result continues to be calculated in the same way, and the final Hash256 value is formed as the Merkel root through continuous iterative calculation. The "previous block hash value" is the value of the previous block's block header after two Hash256 operations, and also includes the Merkel root of the previous block. Therefore, once the data is packaged and uploaded to the chain, if you want to modify the transaction data of a certain block, you must modify all the data of the Merkel tree of the block in sequence. Since the "previous block hash value" is designed for all the data of the previous block header, it is also necessary to modify the "previous block hash value" of all blocks after this block. For a distributed database with a large number of storage nodes, the modification cost is huge and basically difficult to achieve.

[0112] At the same time, according to the above block structure, it can be known that the blockchain must have a complete block header to ensure that the whole cannot be tampered with. However, if only the verification function is performed, the Merkel root value can be used to directly verify whether the block body transaction or data in the block has not been modified, instead of requiring complete transaction or data information.

[0113] Therefore, in the embodiment of the present invention, all the block header data of the best node are synchronized to the half node, so as to verify the block header data of the best node.

[0114] S205. If the content of the verified block header data is incorrect, the block header data synchronized from the best node is discarded, and a best node verification request is initiated to other nodes.

[0115] S206. When receiving the best node verification reply message from other nodes, jump to execute S203.

[0116] S207. Calculate the total space used by the saved block headers in the local account book, and calculate the available space of the initial block body. The available space of the initial block body is the difference between the initial maximum storage space and the total space used by the block header.

[0117] In a feasible implementation, the available space of the initial block is calculated according to the following formula (1):

[0118] M=M sum -M header ……(1)

[0119] Among them, M represents the available space of the initial block, M sum Indicates the initial maximum storage space, M header Indicates the total space used by saved block headers in the local ledger.

[0120] S208. Determine 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 body, the random number, the current total number of blocks, the average memory size occupied by the block body, and the number of blocks synchronized at the same time.

[0121] In a feasible implementation manner, the principle of the synchronization judgment algorithm is as follows:

[0122] There are n blocks in total, and the average storage occupied by each block is a. The total storage planned to be stored is M. It is expected that m blocks can be synchronized, and the threshold is a constant related to a, n, and m.

[0123]

[0124] Where i is the block number of a block, n is the total number of blocks, l random A random number uniformly distributed between 0 and 1.

[0125] Then let the expected number of synchronized blocks be m:

[0126]

[0127]

[0128]

[0129] because For harmonic series, there is no fixed summation formula. According to Euler's formula

[0130] (where C≈0.577)

[0131] We can get:

[0132]

[0133]

[0134]

[0135] Therefore, to determine whether each block is synchronized, you first need to generate a random number l between 0 and 1. random , then calculate Is it true? If so, synchronize the block body of the block.

[0136] However, since each synchronization needs to send a synchronization request signal to other nodes, too many interactions will easily lead to a waste of communication resources, and the delay superposition will cause a long time from the creation to the application of the new node. Therefore, each u blocks are regarded as a block for judgment. In this way, the new n and i can be set as:

[0137]

[0138] in, Indicates a round-up operation.

[0139] Therefore, the synchronization judgment method can be as follows:

[0140] Calculate whether the following inequality (2) holds:

[0141]

[0142] in,

[0143] Among them, l random It is a random number uniformly distributed between 0 and 1, n is the total number of blocks at present, i is the block number to be judged, a is the average memory size occupied by the block body, and u is the number of blocks synchronized at the same time.

[0144] If the above inequality (2) holds, then the synchronization block number is determined to be i min +u×(i min -1) to i0+u×i min -1 block data, where i min The minimum value among all block numbers.

[0145] If the above inequality (2) does not hold, then the asynchronous block number is determined to be imin +u×(i min -1) to i0+u×i min -1 chunk data.

[0146] In this way, by introducing a random factor under the intervention of the block number, when the storage space is fixed, historical blocks are taken into account while giving priority to newer blocks. Moreover, the synchronization process regards N adjacent blocks as a block group, so as to calculate whether the random number synchronizes the block group, reducing the communication pressure of the synchronization process constantly requesting data.

[0147] S209. If the block data corresponding to the synchronization block number is determined, verify whether the synchronized block data is correct. If the verification is correct, synchronize the block data to the local account book.

[0148] S210. If the verification is incorrect, the block header data and block body data synchronized from the best node are discarded, and a best node verification request is initiated to other nodes.

[0149] S211. When receiving the best node verification reply message from other nodes, jump to execute S203.

[0150] S212, repeatedly execute S208-S211 until it is determined whether the block body data of all blocks are synchronized, and the blockchain ledger synchronization operation is completed.

[0151] In the embodiment of the present invention, by introducing the concept of half-node, in addition to storing the block header, the data body of some blocks is selectively stored to solve the problem that the storage resources of some nodes are insufficient to store all the data. In addition, by introducing the random factor under the intervention of the block number, historical blocks are taken into account while the newer blocks are given priority when the storage space is fixed. In addition, the synchronization process regards the adjacent N blocks as a block group, so as to calculate whether the random number synchronizes the block group, reducing the communication pressure of the synchronization process that continuously requests data.

[0152] Figure 5 1 is a block diagram of a blockchain ledger synchronization device based on a half-node according to an exemplary embodiment. Figure 5 , the device comprises:

[0153] A creation module 510, used to create a half node and complete the deployment of the half node, initialize the half node, create an initial storage space for the half node, and set an initial maximum storage space;

[0154] A search module 520, configured to search for an optimal node, wherein the optimal node is a full node adjacent to the half node;

[0155] A synchronization module 530, used to synchronize all block header data from the best node to the half node;

[0156] A verification module 540 is used to verify whether the synchronized block header data is correct. If the content of the block header data is verified to be correct, the block header data is stored in the local ledger of the half node;

[0157] A calculation module 550 is used to calculate the total space used by the block headers saved in the local account book, and calculate the available space of the initial block body, where the available space of the initial block body is the difference between the initial maximum storage space and the total space used by the block headers;

[0158] The judgment module 560 is used to judge whether to synchronize the block data corresponding to the block number of any block according to the block number of the block, the available space of the initial block body, the random number, the current total number of blocks, the average memory size occupied by the block body, and the number of blocks synchronized at the same time;

[0159] The verification module 540 is used to verify whether the synchronized block data corresponding to the block number is correct if it is determined that the synchronized block data is correct. If the verification is correct, the synchronized block data is synchronized to the local account book;

[0160] The repetitive execution module 570 is used to repeatedly execute S6-S7 until it is determined whether the block body data of all blocks are synchronized, thereby completing the blockchain ledger synchronization operation.

[0161] Optionally, the verification module 540 is further configured to:

[0162] After verifying whether the synchronized block header data is correct, if the content of the block header data is verified to be incorrect, the block header data synchronized from the best node is discarded, and a best node verification request is initiated to other nodes;

[0163] When receiving the best node verification reply message from other nodes, jump to execute S3.

[0164] Optionally, the calculation module 550 is used to:

[0165] The available space of the initial block is calculated according to the following formula (1):

[0166] M=M sum -M header ……(1)

[0167] Among them, M represents the available space of the initial block, M sum Indicates the initial maximum storage space, M header Represents the total space used by saved block headers in the local ledger.

[0168] Optionally, the judging module 560 is configured to:

[0169] Calculate whether the following inequality (2) holds:

[0170]

[0171] in,

[0172] Among them, l random is a random number uniformly distributed between 0 and 1, n is the total number of blocks at present, i is the block number to be judged, a is the average memory size occupied by the block body, and u is the number of blocks synchronized at the same time;

[0173] If the above inequality (2) holds, then determine to synchronize the block data corresponding to the block number;

[0174] If the above inequality (2) does not hold, it is determined that the block body data corresponding to the block number is not synchronized.

[0175] Optionally, the judging module 560 is configured to:

[0176] The synchronization block number is i min +u×(i min -1) to i0+u×i min -1 block data, where i min The minimum value among all block numbers.

[0177] Optionally, the verification module 540 is further configured to:

[0178] After verifying whether the synchronized block data is correct, if the verification is incorrect, the block header data and block data synchronized from the best node are discarded, and a best node verification request is initiated to other nodes;

[0179] When receiving the best node verification reply message from other nodes, jump to execute S3.

[0180] In the embodiment of the present invention, by introducing the concept of half-node, in addition to storing the block header, the data body of some blocks is selectively stored to solve the problem that the storage resources of some nodes are insufficient to store all the data. In addition, by introducing the random factor under the intervention of the block number, historical blocks are taken into account while the newer blocks are given priority when the storage space is fixed. In addition, the synchronization process regards the adjacent N blocks as a block group, so as to calculate whether the random number synchronizes the block group, reducing the communication pressure of the synchronization process that continuously requests data.

[0181] Figure 6: is a schematic diagram of the structure of a blockchain management node 600 provided in an embodiment of the present invention. The blockchain management node 600 may have relatively large differences due to different configurations or performances, and may include one or more processors (central processing units, CPU) 601 and one or more memories 602, wherein the memory 602 stores at least one instruction, and the at least one instruction is loaded and executed by the processor 601 to implement the steps of the above-mentioned half-node-based blockchain ledger synchronization method.

[0182] In an exemplary embodiment, a computer-readable storage medium is also provided, such as a memory including instructions, which can be executed by a processor in a terminal to complete the above-mentioned half-node-based blockchain ledger synchronization method. For example, the computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a tape, a floppy disk, an optical data storage device, etc.

[0183] A person skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware or by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a disk or an optical disk, etc.

[0184] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims

1. A blockchain ledger synchronization method based on a half-node, characterized in that: The method comprises: S1. Create a half node and complete the deployment of the half node, initialize the half node, create the initial storage space of the half node, and set the initial maximum storage space; S2. Find the best node, where the best node is a full node adjacent to the half node; S3. Synchronize all block header data from the best node to the half node; S4. Verify whether the synchronized block header data is correct. If the content of the block header data is verified to be correct, store the block header data in the local ledger of the half node. S5. Calculate the total space used by the saved block headers in the local account book, and calculate the available space of the initial block body, where the available space of the initial block body is the difference between the initial maximum storage space and the total space used by the block header; S6. Determine 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 body, the random number, the current total number of blocks, the average memory size occupied by the block body, and the number of blocks synchronized at the same time; S7. If it is determined that the block data corresponding to the block number is synchronized, verify whether the synchronized block data is correct. If the verification is correct, synchronize the block data to the local account book; S8, repeat S6-S7 until it is determined whether the block data of all blocks are synchronized, and the blockchain ledger synchronization operation is completed; The step of calculating the total space used by the saved block headers in the local ledger and calculating the available space of the initial block body includes: The available space of the initial block is calculated according to the following formula (1): M=M sum -M header ……(1) Among them, M represents the available space of the initial block, M sum Indicates the initial maximum storage space, M header Indicates the total space used by the saved block headers in the local ledger; The step of determining whether to synchronize the block data corresponding to the block number of any block, based on the block number of the block, the available space of the initial block, the random number, the current total number of blocks, the average memory size occupied by the block, and the number of blocks synchronized simultaneously, includes: Calculate whether the following inequality (2) holds: in, Among them, l random is a random number uniformly distributed between 0 and 1, n is the total number of blocks at present, i is the block number to be judged, a is the average memory size occupied by the block body, and u is the number of blocks synchronized at the same time; If the above inequality (2) holds, then determine to synchronize the block data corresponding to the block number; If the above inequality (2) does not hold, it is determined that the block body data corresponding to the block number is not synchronized.

2. The method according to claim 1, characterized in that 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, the block header data synchronized from the best node is discarded, and a best node verification request is initiated to other nodes; When receiving the best node verification reply message from other nodes, jump to execute S3.

3. The method according to claim 1, characterized in that: The synchronizing the block data corresponding to the block number includes: The synchronization block number is i min +u×(i min -1) to i0+u×i min -1 block data, where i min The minimum value among all block numbers.

4. The method according to claim 1, characterized in that After verifying whether the synchronized block data is correct, it also includes: If the verification is incorrect, the block header data and block body data synchronized from the best node are discarded, and a best node verification request is initiated to other nodes; When receiving the best node verification reply message from other nodes, jump to execute S3.

5. A blockchain ledger synchronization device based on a half-node, characterized in that: The device comprises: A creation module, used to create a half node and complete the deployment of the half node, initialize the half node, create the initial storage space of the half node, and set the initial maximum storage space; A search module, used for searching for an optimal node, wherein the optimal node is a full node adjacent to the half node; A synchronization module, used to synchronize all block header data from the best node to the half node; A verification module, used to verify whether the synchronized block header data is correct. If the content of the block header data is verified to be correct, the block header data is stored in the local ledger of the half node; A calculation module, used to calculate the total space used by the block headers saved in the local account book, and calculate the available space of the initial block body, where the available space of the initial block body is the difference between the initial maximum storage space and the total space used by the block headers; A judgment module, used to judge whether to synchronize the block data corresponding to the block number of any block according to the block number of the block, the available space of the initial block body, the random number, the current total number of blocks, the average memory size occupied by the block body, and the number of blocks synchronized at the same time; A verification module, for verifying whether the synchronized block data corresponding to the block number is correct if it is determined that the synchronized block data is correct, and if the verification is correct, synchronizing the block data to the local account book; A repeat execution module is used to repeatedly execute S6-S7 until it is determined whether the block body data of all blocks are synchronized, thereby completing the blockchain ledger synchronization operation; The available space of the initial block is calculated according to the following formula (1): M=M sum -M header ……(1) Among them, M represents the available space of the initial block, M sum Indicates the initial maximum storage space, M header Indicates the total space used by the saved block headers in the local ledger; Wherein, the judging module is used to: Calculate whether the following inequality (2) holds: in, Among them, l random is a random number uniformly distributed between 0 and 1, n is the total number of blocks at present, i is the block number to be judged, a is the average memory size occupied by the block body, and u is the number of blocks synchronized at the same time; If the above inequality (2) holds, then determine to synchronize the block data corresponding to the block number; If the above inequality (2) does not hold, it is determined that the block body data corresponding to the block number is not synchronized.

6. The device according to claim 5, characterized in that The verification module is further used for: After verifying whether the synchronized block header data is correct, if the content of the block header data is verified to be incorrect, the block header data synchronized from the best node is discarded, and a best node verification request is initiated to other nodes; When receiving the best node verification reply message from other nodes, jump to execute S3.

Citation Information

Patent Citations

  • An account book synchronization method for a block chain

    CN109886690A

  • Block data segmented storage method, terminal and medium

    CN110245190A