WO2020133962A1 - 基于区块链的数据存储方法、相关设备及存储介质 - Google Patents

基于区块链的数据存储方法、相关设备及存储介质 Download PDF

Info

Publication number
WO2020133962A1
WO2020133962A1 PCT/CN2019/092086 CN2019092086W WO2020133962A1 WO 2020133962 A1 WO2020133962 A1 WO 2020133962A1 CN 2019092086 W CN2019092086 W CN 2019092086W WO 2020133962 A1 WO2020133962 A1 WO 2020133962A1
Authority
WO
WIPO (PCT)
Prior art keywords
block
target node
token
sequence number
seed
Prior art date
Application number
PCT/CN2019/092086
Other languages
English (en)
French (fr)
Inventor
唐银辉
Original Assignee
重庆小雨点小额贷款有限公司
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 重庆小雨点小额贷款有限公司 filed Critical 重庆小雨点小额贷款有限公司
Priority to US17/282,312 priority Critical patent/US20210382872A1/en
Publication of WO2020133962A1 publication Critical patent/WO2020133962A1/zh

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/23Updating
    • G06F16/2379Updates performed during online database operations; commit processing
    • 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

Definitions

  • the present invention relates to the field of computer technology, and in particular to a blockchain-based data storage method, related equipment, and storage media.
  • Embodiments of the present invention provide a blockchain-based data storage method, related equipment, and storage media, which can effectively relieve the data storage pressure of nodes.
  • an embodiment of the present invention provides a data storage method, which is applied to a blockchain system.
  • the blockchain system includes multiple nodes.
  • the method includes:
  • the target node obtains the sequence number of the newly generated first block broadcast in the blockchain system, wherein the target node is any one of the plurality of nodes, and the first block includes block data and A block header, the block header includes the serial number of the first block;
  • the target node obtains a first token seed, wherein the first token seed is generated according to the number of nodes of the blockchain system;
  • the target node determines the first sequence number range where the first block is located based on the first token seed and the sequence number of the first block;
  • the target node determines a block header to store the first block or store the first block based on the first sequence number range and the first token value of the target node.
  • the target node determines the first sequence number range where the first block is located based on the first token seed and the sequence number of the first block, including:
  • the target node determines the target block unit where the first block is located based on the serial number of the first block, where each of the block units includes the same number of blocks;
  • the target node divides the target block unit based on the first token seed to obtain a plurality of sequence number ranges, where different sequence number ranges correspond to different token values;
  • the target node determines the first sequence number range in which the first block is located within the plurality of sequence number ranges based on the sequence number of the first block.
  • the target node determines the block header to store the first block or store the first block based on the first sequence number range and the first token value of the target node, including :
  • the target node determines the value of the first token from the range of the plurality of sequence numbers, and determines a range of the target sequence number corresponding to the block that the target node needs to store;
  • the target node judges whether the first sequence number range is consistent with the target sequence number range
  • the target node stores the first block
  • the target node stores the block header of the first block.
  • the method further includes:
  • the target node When the token seed update time arrives, the target node obtains a second token seed, which is based on the current number of nodes in the blockchain system when the token seed update time arrives Generated;
  • the target node updates the first token value to obtain the second token value of the target node
  • the target node determines a second sequence number range in which the first block is based on the second token seed and the sequence number of the first block, and based on the second sequence number range and the second order
  • the card value updates the block stored by the target node.
  • the updating the block stored by the target node based on the second sequence number range and the second token value includes:
  • the target node determines the block to be stored and the block to be deleted according to the second sequence number range and the second token value
  • the target node stores the block to be stored and records the block to be deleted.
  • the target node storing the block to be stored includes:
  • the target node sends a block acquisition request to the first node, the block acquisition request includes a sequence number that the target node needs to store but does not store a block, and the first node is a token in the blockchain system Any one of the node sets whose value is different from the second token value;
  • the target node stores the blocks that need to be stored but not stored.
  • the method further includes:
  • the target node deletes the block data of the block that needs to be deleted recorded in the previous token period, and the token period is a time period between two token seed generations adjacent to each other.
  • the target node updates the first token value based on the second token seed to obtain the second token value of the target node, including:
  • the target node When the first token seed is greater than the second token seed, the target node performs according to the first token value of the first token seed, the second token seed, and the target node Calculate and determine the calculation result as the second token value of the target node;
  • the target node is determined according to the first token value of the first token seed, the second token seed, and the target node A value range of the second token value of the target node, and the second token value is determined within the value range.
  • the serial number of the genesis block included in the blockchain system is 0, and any node in the blockchain system stores the genesis block.
  • the value of the token seed satisfies 2 n , where n is a positive integer, and the token seed includes the first token seed and the second token seed.
  • an embodiment of the present invention provides a data storage device applied to a blockchain system.
  • the blockchain system includes multiple nodes, where the device includes:
  • An obtaining unit configured to obtain the sequence number of the newly generated first block broadcast in the blockchain system, wherein the target node is any one of the plurality of nodes, and the first block includes an area Block data and a block header, the block header including the sequence number of the first block;
  • the obtaining unit is also used to obtain a first token seed, wherein the first token seed is generated according to the number of nodes of the blockchain system;
  • a determining unit configured to determine the first sequence number range where the first block is located based on the first token seed and the sequence number of the first block;
  • the determining unit is further configured to determine a block header to store the first block or store the first block based on the first sequence number range and the first token value of the target node.
  • the determination unit is specifically used to:
  • each block unit includes the same number of blocks
  • the first sequence number range in which the first block is located is determined within the plurality of sequence number ranges based on the sequence number of the first block.
  • the determination unit is specifically used to:
  • the block header of the first block is stored.
  • the device further includes: an update unit.
  • the obtaining unit is also used to obtain a second token seed when the token seed update time arrives, the second token seed is based on the blockchain system when the token seed update time arrives Generated by the current number of nodes;
  • An updating unit configured to update the first token value based on the second token seed to obtain the second token value of the target node
  • the update unit is further configured to determine the second sequence number range where the first block is located based on the second token seed and the sequence number of the first block, and based on the second sequence number range and the location
  • the second token value updates the block stored by the target node.
  • the determination unit is specifically used to:
  • the determination unit is specifically used to:
  • the block acquisition request includes the serial number of the block that the target node needs to store but does not store
  • the first node is the token value in the blockchain system and the Any one of the set of nodes with different second token values
  • the device further includes a deletion unit.
  • the deleting unit is configured to delete the block data of the block that needs to be deleted recorded in the previous token period, and the token period is a time period between generating token seeds for two adjacent times.
  • the update unit is specifically used for:
  • the target node When the first token seed is less than the second token seed, determine the target node according to the first token seed, the second token seed, and the first token value of the target node The value range of the second token value, and determine the second token value within the value range.
  • an embodiment of the present invention provides a server.
  • the server includes a memory, a processor, and a network interface.
  • the memory stores a computer program.
  • the network interface is used to send and receive messages under the control of the processor.
  • the processor executes the computer program, the method according to any one of the first aspects is implemented.
  • an embodiment of the present invention provides a computer-readable storage medium, where the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, it is implemented as described in any one of the first aspects method.
  • the target node first obtains the sequence number of the newly generated first block broadcast in the blockchain system, and obtains the first token seed generated based on the number of nodes in the blockchain system, so that it can be based on
  • the first token seed and the sequence number of the first block determine the first sequence number range where the first block is located, so that it can be further determined based on the first sequence number range and the first token value of the target node
  • the storage of the first block or the block header of the first block can effectively relieve the data storage pressure of the target node, thereby reducing the problem of excessive network traffic in the blockchain system and also preventing the blockchain system
  • FIG. 1 is a schematic flowchart of a data storage method provided by an embodiment of the present invention.
  • FIG. 2 is a schematic flowchart of a data storage method according to another embodiment of the present invention.
  • FIG. 3 is a schematic block diagram of a data storage device according to an embodiment of the present invention.
  • FIG. 4 is a schematic block diagram of a server according to an embodiment of the present invention.
  • the current blockchain-based data storage method can also deploy an additional storage system on the basis of the public chain, so that the summary data of the storage block, such as the block header data of the storage block, can be used to alleviate each node’s Data storage pressure.
  • This method requires the deployment of a new storage system for data storage, it will increase the cost of investment, and this storage method is not used in public chain storage, so it cannot be applied to all blockchain storage systems.
  • This application proposes a new type of blockchain data storage method, which allows each node in the blockchain system to store only part of the block data without storing all the block data in the blockchain system. This can effectively reduce the data storage pressure of each node.
  • each node can also store the block header of its unstored block data.
  • Adopting the above-mentioned blockchain-based data storage method not only maintains a simple deployment solution for storage on the public chain, but also maintains the tamper-proof traceability of the blockchain, and can also solve the storage bottleneck of blockchain nodes and Reduce network traffic between nodes.
  • the target node obtains the sequence number of the newly generated first block broadcast in the blockchain system.
  • the target node is any one of a plurality of nodes in the blockchain system
  • the first block includes block data and a block header
  • the block header includes a serial number of the first block.
  • the blockchain when the blockchain generates each block, it generates a serial number corresponding to the block, and stores the generated serial number in the block header of the block.
  • the block serial number in the blockchain Starting with the genesis block, the sequence number of the genesis block is 0, and the sequence numbers of the blocks in the blockchain are different.
  • the block number determines the block header corresponding to the block number, so that the corresponding block can be determined according to the block header, and whether the block data of the block has changed can be determined by comparing the block header.
  • the block header also includes the summary data of the block (such as the first block), so that even if the node (such as the above-mentioned target node) only stores the block header of the block, it can prevent the block data corresponding to the serial number from being tampered with .
  • the node that generated the first block can broadcast to the blockchain system to inform other nodes in the blockchain system that the area
  • the first block is newly generated by the block chain system, and after the target node receives the broadcast, the serial number of the newly generated first block broadcast in the block chain system is obtained, so that it can be based on the first block obtained by the target node
  • the serial number of the block, the first token seed determined in step S102, and the first token value of the target node determine whether to store the first block in the target node.
  • the target node obtains a first token seed.
  • the first token seed (ie, the first token seed) is generated according to the number of nodes included in the blockchain system, and the first token seed is also each node in the blockchain system
  • the maximum value of the token value of, after the blockchain generates the first token seed according to the total number of nodes it includes, each node can generate the token value corresponding to the node based on the first token seed, such as the area
  • the target node in the blockchain system can generate the first token value of the target node according to the first token seed, that is, the first token value of the target node.
  • the token seed is generated by the blockchain system, specifically by a node in the blockchain system, for example, it may be generated by a node that generates a new block (such as the newly generated first block).
  • the node that generates the new block When the token seed update time arrives, the node that generates the new block generates a new token seed after generating the new block, and broadcasts the new block and the new token seed in the blockchain system.
  • each node in the blockchain system can generate a corresponding token value according to the first token seed, and the token value is a value used to mark the nodes in the blockchain, such as using the first order
  • the card value marks the target node.
  • the token value generated by each node is less than or equal to the first token seed.
  • the value of the token seed in the blockchain system satisfies 2 n , where n is a positive integer.
  • n takes an integer greater than or equal to 2, and the value of the token seed is much smaller than the block The number of nodes included in the chain system, so there are multiple nodes in the blockchain system corresponding to the same token seed.
  • step S102 and step S101 there is no necessary order of execution, you can first execute step S101, then execute step S102, you can also first execute step S102, then execute step S101, you can also perform steps S101 and Step S102, the embodiment of the present invention is not limited.
  • the target node determines the first sequence number range where the first block is located based on the first token seed and the sequence number of the first block.
  • the number of blocks included in the blockchain system changes.
  • the block The serial number of the blocks included in the chain system is divided, that is, the number of blocks included in the block system needs to be divided after the number of blocks changes, where the block chain system can divide the block system
  • the serial number of the block can be divided by a certain node in the blockchain system, for example, the target node can divide the serial number of the block in the blockchain system.
  • the target node may determine the target block unit where the first block is located, where each of the block units includes The same number of blocks; thus, the target node can divide the blocks included in the target block unit based on the first token seed to obtain multiple sequence number ranges, and combine any sequence number range with a token value
  • the first serial number range in which the first block is located can be determined within the multiple serial number ranges based on the serial number of the first block.
  • the 2 m blocks are divided into 2 n shares to obtain multiple sequence number ranges, where each The serial number range corresponds to a token value.
  • the block with a sequence number range of 0-2 mn -1 corresponds to a token value of 1
  • the block with a sequence number range of 2 mn -2 m-n+1 -1 corresponds to the order
  • the card value is 2, and so on, based on the first token seed and the serial number of the first block, the first serial number range in which the first block is located can be determined, so that step S104 can be turned to, the target node It may be determined that the first block or the block header of the first block is stored.
  • the target node determines the block header to store the first block or store the first block based on the first sequence number range and the first token value of the target node.
  • the target block when determining the block storing the first block or the block header storing the first block, the target block may first determine the first based on the value of the first token of the target node The token value needs to store the target sequence number range correspondingly, so that the target node can store the first block or the block header of the first block based on the first sequence number range and the target sequence number range. Among them, the target serial number range and the first serial number range can be compared.
  • the target serial number range and the first serial number range are consistent, it means that the target node needs to store the corresponding serial number range including the serial number of the first block, the The target node can store the first block; if the range of the target sequence number and the range of the first sequence number are inconsistent, it means that the range of sequence numbers that the target node needs to store correspondingly does not include the sequence number of the first block, then the target node stores The block header of the first block.
  • each block in the obtained multiple serial number ranges has 128 blocks, assuming that the first token value of the target node is 1, based on the partition result , Determine that the first token value is 1 corresponds to the target sequence number range of the block to be stored is 0-127, if the sequence number of the first block is 23, determine that the first sequence number range of the first block is 0 -127, because the range of the first sequence number where the first block is located is consistent with the range of the target sequence number determined according to the value of the first token, the target node stores the first block; if the sequence number of the first block Is 200, and the range of the first sequence number of the first block is determined to be 128-255. At this time, the range of the first sequence number of the first block is inconsistent with the range of the
  • the genesis block will be stored in all nodes of the blockchain system, that is, even if the target node needs to store the target according to the division result and the first token value of the target node
  • the serial number range does not include the serial number of the genesis block, and the target node will also store the genesis block.
  • the target node first obtains the sequence number of the newly generated first block broadcast in the blockchain system, and obtains the first token seed generated based on the number of nodes in the blockchain system, so that it can be based on
  • the first token seed and the sequence number of the first block determine the first sequence number range where the first block is located, so that it can be further determined based on the first sequence number range and the first token value of the target node
  • the storage of the first block or the block header of the first block can effectively relieve the data storage pressure of the target node, thereby reducing the problem of excessive network traffic in the blockchain system and also preventing the blockchain system
  • FIG. 2 is a schematic flowchart of a data storage method according to another embodiment of the present invention.
  • the method is applied to the above-mentioned blockchain system.
  • the blockchain system includes multiple nodes, as shown in FIG. 2 ,
  • the method may include:
  • the target node obtains the sequence number of the newly generated first block broadcast in the blockchain system.
  • the target node obtains a first token seed.
  • the target node determines the first sequence number range where the first block is located based on the first token seed and the sequence number of the first block.
  • steps S201-step S203 refer to the implementation manner of steps S101-step S103 in the foregoing embodiments, and details are not described herein again.
  • the target node determines the block header to store the first block or the first block based on the first sequence number range and the first token value of the target node.
  • the target node may first select the multiple sequence numbers A range of target serial numbers corresponding to the first token value is determined within the range, and the block corresponding to the serial number included in the range of the target serial number is a block that the target node needs to store.
  • the target node can determine the target serial number Whether the range is consistent with the first serial number range, when the target serial number range is consistent with the first serial number range, it means that the target node needs to store the block including the first block, and stores the first block, in When the target sequence number range and the first sequence number range are inconsistent, it means that the block to be stored by the target node does not include the first block, and then the block header of the first block is stored.
  • the second token seed when determining the second token seed, may be randomly generated based on the changed number of nodes in the blockchain system, or may be combined with the preset generation rule The first token seed and the number of nodes before the number of nodes in the blockchain system change to generate the second token seed.
  • the determined second token The seed when the number of nodes in the blockchain system increases, the determined second token The seed is greater than the first token seed, and when the number of nodes in the blockchain system decreases, the determined second token seed is less than the first token seed.
  • the target node can obtain the sequence number of the newly generated first block broadcast in the blockchain system, and obtain the first token seed, which can be based on the first token seed and the first area
  • the sequence number of the block determines the first sequence number range where the first block is located.
  • the determining unit 302 is specifically configured to:
  • the block header of the first block is stored.
  • the determining unit 302 is specifically configured to:
  • the block acquisition request includes the serial number of the block that the target node needs to store but does not store
  • the first node is the token value in the blockchain system and the Any one of the set of nodes with different second token values
  • the deleting unit 304 is configured to delete the block data of the block that needs to be deleted recorded in the previous token period, and the token period is a time period between the generation of token seeds for two adjacent times.
  • the target node determines the first sequence number range where the first block is located based on the first token seed and the sequence number of the first block;
  • the target node determines a block header to store the first block or store the first block based on the first sequence number range and the first token value of the target node.
  • the processor 401 is further configured to call the program instruction to execute:
  • the target node determines the target block unit where the first block is located based on the serial number of the first block, where each of the block units includes the same number of blocks;
  • the target node determines the first sequence number range in which the first block is located within the plurality of sequence number ranges based on the sequence number of the first block.
  • the processor 401 is further configured to call the program instruction to execute:
  • the target node judges whether the first sequence number range is consistent with the target sequence number range
  • the target node stores the first block
  • the target node stores the block header of the first block.
  • the target node When the token seed update time arrives, the target node obtains a second token seed, which is based on the current number of nodes in the blockchain system when the token seed update time arrives Generated;
  • the target node stores the block to be stored and records the block to be deleted.
  • the processor 401 is further configured to call the program instruction to execute:
  • the target node stores the blocks that need to be stored but not stored.
  • the processor 401 is further configured to call the program instruction to execute:
  • the target node deletes the block data of the block that needs to be deleted recorded in the previous token period, and the token period is a time period between two token seed generations adjacent to each other.
  • the processor 401 is further configured to call the program instruction to execute:
  • the target node When the first token seed is greater than the second token seed, the target node performs according to the first token value of the first token seed, the second token seed, and the target node Calculate and determine the calculation result as the second token value of the target node;
  • a computer-readable storage medium stores a computer program, and the computer program includes program instructions.
  • the program instructions are executed by a processor, the foregoing diagram is implemented. 1 and the method described in FIG. 2.

Abstract

一种基于区块链的数据存储方法、相关设备及存储介质,其中方法包括:目标节点获取该区块链系统中广播的新生成的第一区块的序号(S101),其中,该目标节点为该多个节点中的任一个,该第一区块包括区块数据和区块头,该区块头包括该第一区块的序号;该目标节点获取第一令牌种子(S102),其中,该第一令牌种子是根据该区块链系统的节点数量生成的;该目标节点基于该第一令牌种子和该第一区块的序号确定该第一区块所处的第一序号范围(S103);该目标节点基于该第一序号范围和该目标节点的第一令牌值,确定存储该第一区块或者存储该第一区块的区块头(S104),可有效缓解区块链系统中目标节点的数据存储压力。

Description

基于区块链的数据存储方法、相关设备及存储介质 技术领域
本发明涉及计算机技术领域,尤其涉及一种基于区块链的数据存储方法、相关设备及存储介质。
背景技术
当前的区块链存储技术大都采用直接在区块链上存储所有的区块数据,即区块链的所有节点存储有相同的区块数据,这种方法一般用于公链存储,但是,随着区块链运行时间的加长,区块链中的数据量会越来越大,特别是在大数据环境下,将会导致每个节点要求存储的数据量也越来越大,可见,采用上述常用的区块存储技术会给区块链中各节点带来较大的数据存储压力。
发明内容
本发明实施例提供了一种基于区块链的数据存储方法、相关设备及存储介质,可有效缓解节点的数据存储压力。
第一方面,本发明实施例提供了一种数据存储方法,应用于区块链系统,所述区块链系统包括多个节点,其中,该方法包括:
目标节点获取所述区块链系统中广播的新生成的第一区块的序号,其中,所述目标节点为所述多个节点中的任一个,所述第一区块包括区块数据和区块头,所述区块头包括所述第一区块的序号;
所述目标节点获取第一令牌种子,其中,所述第一令牌种子是根据所述区块链系统的节点数量生成的;
所述目标节点基于所述第一令牌种子和所述第一区块的序号确定所述第一区块所处的第一序号范围;
所述目标节点基于所述第一序号范围和所述目标节点的第一令牌值,确定存储所述第一区块或者存储所述第一区块的区块头。
在一个实施例中,所述目标节点基于所述第一令牌种子和所述第一区块的序号确定所述第一区块所处的第一序号范围,包括:
所述目标节点基于所述第一区块的序号确定所述第一区块所处的目标区块单位,其中,每个所述区块单位内包括相同数量的区块;
所述目标节点基于所述第一令牌种子对所述目标区块单位进行划分,得到多个序号范围,其中,不同序号范围对应不同令牌值;
所述目标节点基于所述第一区块的序号在所述多个序号范围内确定所述第一区块所处的第一序号范围。
在一个实施例中,所述目标节点基于所述第一序号范围和所述目标节点的第一令牌值,确定存储所述第一区块或者存储所述第一区块的区块头,包括:
所述目标节点从所述多个序号范围内确定与所述第一令牌值,确定所述目标节点需要存储的区块对应的目标序号范围;
所述目标节点判断所述第一序号范围与所述目标序号范围是否一致;
若一致,则所述目标节点存储所述第一区块;
若不一致,则所述目标节点存储所述第一区块的区块头。
在一个实施例中,所述方法还包括:
在令牌种子更新时间到达时,所述目标节点获取第二令牌种子,所述第二令牌种子是在所述令牌种子更新时间到达时,基于所述区块链系统当前的节点数量生成的;
所述目标节点基于所述第二令牌种子,对所述第一令牌值进行更新得到所述目标节点的第二令牌值;
所述目标节点基于所述第二令牌种子和所述第一区块的序号确定所述第一区块所处的第二序号范围,并基于所述第二序号范围和所述第二令牌值,更新所述目标节点存储的区块。
在一个实施例中,所述基于所述第二序号范围和所述第二令牌值,更新所述目标节点存储的区块,包括:
所述目标节点根据所述第二序号范围和所述第二令牌值,确定需要存储的区块和需要删除的区块;
所述目标节点对所述需要存储的区块进行存储,并对所述需要删除的区块进行记录。
在一个实施例中,所述目标节点对所述需要存储的区块进行存储,包括:
所述目标节点向第一节点发送区块获取请求,所述区块获取请求包括所述目标节点需要存储但未存储区块的序号,所述第一节点为所述区块链系统中令牌值与所述第二令牌值 不同的节点集合中的任一个;
所述目标节点接收所述第一节点基于所述区块获取请求发送的所述目标节点需要存储但未存储区块;
所述目标节点存储所述需要存储但未存储区块。
在一个实施例中,所述方法还包括:
所述目标节点将在上一个令牌周期内记录的需要删除的区块的区块数据进行删除,所述令牌周期为相邻两次生成令牌种子之间的时间段。
在一个实施例中,所述目标节点基于所述第二令牌种子,对所述第一令牌值进行更新得到所述目标节点的第二令牌值,包括:
在所述第一令牌种子大于所述第二令牌种子时,所述目标节点根据所述第一令牌种子、所述第二令牌种子和所述目标节点的第一令牌值进行计算,并将计算结果确定为所述目标节点的第二令牌值;
在所述第一令牌种子小于所述第二令牌种子时,所述目标节点根据所述第一令牌种子、所述第二令牌种子和所述目标节点的第一令牌值确定所述目标节点的第二令牌值的取值范围,并在所述取值范围内确定所述第二令牌值。
在一个实施例中,所述区块链系统包括的创世区块的序号为0,且所述区块链系统中的任一节点存储有所述创世区块。
在一个实施例中,令牌种子的取值满足2 n,其中,n为正整数,所述令牌种子包括所述第一令牌种子和所述第二令牌种子。
第二方面,本发明实施例提供了一种数据存储装置,应用于区块链系统,所述区块链系统包括多个节点,其中,该装置包括:
获取单元,用于获取所述区块链系统中广播的新生成的第一区块的序号,其中,所述目标节点为所述多个节点中的任一个,所述第一区块包括区块数据和区块头,所述区块头包括所述第一区块的序号;
所述获取单元,还用于获取第一令牌种子,其中,所述第一令牌种子是根据所述区块链系统的节点数量生成的;
确定单元,用于基于所述第一令牌种子和所述第一区块的序号确定所述第一区块所处的第一序号范围;
所述确定单元,还用于基于所述第一序号范围和所述目标节点的第一令牌值,确定存 储所述第一区块或者存储所述第一区块的区块头。
在一个实施例中,所述确定单元具体用于:
基于所述第一区块的序号确定所述第一区块所处的目标区块单位,其中,每个所述区块单位内包括相同数量的区块;
基于所述第一令牌种子对所述目标区块单位进行划分,得到多个序号范围,其中,不同序号范围对应不同令牌值;
基于所述第一区块的序号在所述多个序号范围内确定所述第一区块所处的第一序号范围。
在一个实施例中,所述确定单元具体用于:
从所述多个序号范围内确定与所述第一令牌值对应的目标序号范围;
判断所述第一序号范围与所述目标序号范围是否一致;
若一致,则存储所述第一区块;
若不一致,则存储所述第一区块的区块头。
在一个实施例中,所述装置还包括:更新单元。
所述获取单元,还用于在令牌种子更新时间到达时,获取第二令牌种子,所述第二令牌种子是在所述令牌种子更新时间到达时,基于所述区块链系统当前的节点数量生成的;
更新单元,用于基于所述第二令牌种子,对所述第一令牌值进行更新得到所述目标节点的第二令牌值;
所述更新单元,还用于基于所述第二令牌种子和所述第一区块的序号确定所述第一区块所处的第二序号范围,并基于所述第二序号范围和所述第二令牌值,更新所述目标节点存储的区块。
在一个实施例中,所述确定单元具体用于:
根据所述第二序号范围和所述第二令牌值,确定需要存储的区块和需要删除的区块;
对所述需要存储的区块进行存储,并对所述需要删除的区块进行记录。
在一个实施例中,所述确定单元具体用于:
向第一节点发送区块获取请求,所述区块获取请求包括所述目标节点需要存储但未存储区块的序号,所述第一节点为所述区块链系统中令牌值与所述第二令牌值不同的节点集合中的任一个;
接收所述第一节点基于所述区块获取请求发送的所述目标节点需要存储但未存储区 块;
存储所述需要存储但未存储区块。
在一个实施例中,所述装置还包括:删除单元。
所述删除单元,用于将在上一个令牌周期内记录的需要删除的区块的区块数据进行删除,所述令牌周期为相邻两次生成令牌种子之间的时间段。
在一个实施例中,所述更新单元具体用于:
在所述第一令牌种子大于所述第二令牌种子时,根据所述第一令牌种子、所述第二令牌种子和所述目标节点的第一令牌值进行计算,并将计算结果确定为所述目标节点的第二令牌值;
在所述第一令牌种子小于所述第二令牌种子时,根据所述第一令牌种子、所述第二令牌种子和所述目标节点的第一令牌值确定所述目标节点的第二令牌值的取值范围,并在所述取值范围内确定所述第二令牌值。
第三方面,本发明实施例提供了一种服务器,该服务器包括:存储器、处理器以及网络接口,所述存储器中存储有计算机程序,所述网络接口用于受所述处理器的控制收发消息,所述处理器执行所述计算机程序时实现如第一方面任一项所述的方法。
第四方面,本发明实施例提供了一种计算机可读存储介质,所述计算机可读存储介质存储包括计算机程序,所述计算机程序被处理器执行时实现如第一方面任一项所述的方法。
在本发明实施例中,目标节点先获取区块链系统中广播的新生成的第一区块的序号,并获取基于该区块链系统的节点数量生成的第一令牌种子,从而可基于该第一令牌种子和该第一区块的序号确定该第一区块所处的第一序号范围,从而可进一步地基于该第一序号范围和该目标节点的第一令牌值,确定存储该第一区块或者存储该第一区块的区块头,可有效缓解目标节点的数据存储压力,从而可降低区块链系统中网络流量过大的问题,还可同时防止区块链系统中的数据被恶意篡改。
附图说明
为了更清楚地说明本发明实施例技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。
图1是本发明实施例提供的一种数据存储方法的示意流程图;
图2是本发明另一实施例提供的一种数据存储方法的示意流程图;
图3是本发明实施例提供的一种数据存储装置的示意性框图;
图4是本发明实施例提供的一种服务器的示意性框图。
具体实施方式
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有付出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。
当前基于区块链的数据存储方法,还可在公链的基础上部署一套另外的存储系统,从而可通过存储区块的摘要数据,如存储区块的区块头数据,来缓解各节点的数据存储压力。但由于这种方法需要部署新的存储系统进行数据存储,会加大成本投入,而且这种存储方法也不使用于公链存储,因此并不能适用于所有的区块链存储系统,基于此,本申请提出了一种新型的区块链数据的存储方法,该方法使得区块链系统中的每一个节点只存储部分区块数据,而不用存储该区块链系统中的所有区块数据,从而可有效减轻各节点的数据存储压力,其次,为了防止区块数据被恶意篡改,各节点还可存储其未存储的区块数据的区块头。
采用上述的基于区块链的数据存储方法,即保持了公链上存储的简单部署方案,也保持了区块链的防篡改可追溯性,还可解决区块链节点的存储瓶颈,以及可降低节点间的网络流量。
S101,目标节点获取该区块链系统中广播的新生成的第一区块的序号。
在一个实施例中,该目标节点为该区块链系统中多个节点中的任一个,该第一区块包括区块数据和区块头,该区块头包括该第一区块的序号。在具体实现中,区块链在生成每一个区块时都会产生一个和该区块对应的序号,并将产生的序号对应存储在该区块的区块头中,区块链中的区块序号以创世区块开始递增,其中,该创世区块的序号为0,且区块链中的各区块序号均不相同,因此,任一节点在存储某一区块的序号后,可基于该区块序号确定出和该区块序号对应的区块头,从而可根据该区块头确定出对应的区块,并可通过比较区块头来确定区块的区块数据是否发生变化。其中,区块头中还包括区块(如该第一区块)的摘要数据,使得节点(如上述目标节点)即使只存储区块的区块头,也可防止该 序号对应的区块数据被篡改。
当区块链系统中的任一节点新生成第一区块时,生成该第一区块的节点可向该区块链系统进行广播,以告知该区块链系统中的其他节点,该区块链系统新生成了第一区块,目标节点接收到广播后,获取到该区块链系统中广播的新生成的第一区块的序号时,从而可基于该目标节点获取到的第一区块的序号,在步骤S102中确定的第一令牌种子,以及该目标节点的第一令牌值,确定是否在该目标节点中存储该第一区块。
S102,该目标节点获取第一令牌种子。
在一个实施例中,第一令牌种子(即第一token种子)是根据该区块链系统中包括的节点数量生成的,该第一令牌种子也即是该区块链系统中各节点的令牌值的最大值,在区块链根据其包括的节点的总数生成第一令牌种子之后,各节点可基于该第一令牌种子可生成该节点对应的令牌值,如该区块链系统中的目标节点可根据该第一令牌种子可生成该目标节点的第一令牌值,即该目标节点的第一token值。
需要说明的是,令牌种子由区块链系统生成,具体由区块链系统中的某一节点生成,例如可以是生成新区块(如上述新生成的第一区块)的节点生成的。在令牌种子更新时间到达时,生成新区块的节点在生成新区块后生成新的令牌种子,并将新区块和新的令牌种子在区块链系统中广播。
其中,该区块链系统中的每一个节点可根据该第一令牌种子生成对应的token值,该token值为用于对区块链中的节点进行标记的值,如用该第一令牌值对该目标节点进行标记,在该区块链系统中的每一个节点根据该第一令牌种子生成对应的token值时,该每一个节点生成的token值都小于等于该第一令牌种子。
具体地,该区块链系统中令牌种子的取值满足2 n,其中,n为正整数,一般情况下,n取大于等于2的整数,令牌种子的取值远远小于该区块链系统包括的节点数,所以在区块链系统中存在多个节点对应相同的令牌种子的情况。
其中,步骤S102的和步骤S101在具体实施中,没有必要的先后执行顺序,可先执行步骤S101,再执行步骤S102,也可先执行步骤S102,再执行步骤S101,也可同时执行步骤S101和步骤S102,本发明实施例不做限定。
S103,该目标节点基于该第一令牌种子和该第一区块的序号,确定该第一区块所处的第一序号范围。
在一个实施例中,在新生成该第一区块后,该区块链系统包括的区块数量发生变化, 为了确定该第一区块所处的第一序号范围,可先对该区块链系统包括的区块的序号进行划分,即需对该区块数量发生变化后该区块系统所包括的区块数量进行划分,其中,可由该区块链系统对该区块链系统中区块的序号进行划分,具体可由该区块链系统中的某一节点,如目标节点对该区块链系统中区块的序号进行划分。
在对该区块链系统包括的区块序号进行划分时,可先将该区块系统包括的所有区块先划分为多个区块单位,具体地,可先基于区块序号,对该区块链系统包括的区块进行排序,并按照预设数量对该区块链系统中包括的区块进行划分,如以2 m个区块为单位,将区块链系统中包括的区块进行划分,划分得到多个区块单位,得到的多个区块单位中的每个区块单位的区块的序号可按照区块的序号顺序进行排列,其中,得到的每个区块单位中包括至少一个区块,其中,m为大于等于n的整数,一般情况下,m的取值为10,也即将区块链系统中的区块进行划分后,得到的每个区块单位包括2 10=1024个区块。
在一个实施例中,在将该区块链系统划分为多个区块单位后,该目标节点可确定该第一区块所在的目标区块单位,其中,每个所述区块单位内包括相同数量的区块;从而该目标节点可基于该第一令牌种子,对该目标区块单位中包括的区块进行划分,得到多个序号范围,并将任一序号范围与一个令牌值进行对应,从而可基于该第一区块的序号,在该多个序号范围内确定该第一区块所处的第一序号范围。
具体地,假设该目标区块单位包括2 m个区块,该第一令牌种子为2 n,则将该2 m个区块划分为2 n份,得到多个序号范围,其中,每一个序号范围对应有一个令牌值,如序号范围为0-2 m-n-1的区块对应的令牌值为1,序号范围为2 m-n-2 m-n+1-1的区块对应的令牌值为2,以此类推,可基于该第一令牌种子和该第一区块的序号,确定该第一区块所处的第一序号范围,从而可转而执行步骤S104,目标节点可确定存储该第一区块或者该第一区块的区块头。
S104,该目标节点基于该第一序号范围和该目标节点的第一令牌值,确定存储该第一区块或者存储该第一区块的区块头。
在一个实施例中,该目标区块在确定存储该第一区块的区块或者存储该第一区块的区块头时,可先基于该目标节点的第一令牌值,确定该第一令牌值需要对应存储目标序号范围,从而可基于该第一序号范围和该目标序号范围,确定该目标节点存储该第一区块或者该第一区块的区块头。其中,可将该目标序号范围和该第一序号范围进行对比,如果该目标序号范围和该第一序号范围一致,说明该目标节点需要对应存储的序号范围包括该第一 区块的序号,该目标节点可将该第一区块进行存储;如果该目标序号范围和该第一序号范围不一致,说明该目标节点需要对应存储的序号范围不包括该第一区块的序号,则该目标节点存储该第一区块的区块头。
举例来说,假设m为10,n为3,那么每个区块单位内有2 10=1024个区块,第一令牌种子为2 3=8,则基于该第一令牌种子8对每个区块单位中包括区块的序号进行划分后,得到的多个序号范围中的每个序号范围有128个区块,假设该目标节点的第一令牌值为1,基于该划分结果,确定第一令牌值为1对应需要存储的区块的目标序号范围为0-127,如果该第一区块的序号为23,确定该第一区块所处的第一序号范围为0-127,由于该第一区块所处的第一序号范围和根据该第一令牌值确定的目标序号范围一致,则该目标节点存储该第一区块;如果该第一区块的序号为200,确定该第一区块所处的第一序号范围为128-255,此时该第一区块所处的第一序号范围和根据该第一令牌值确定的目标序号范围不一致,则该目标节点存储该第一区块的区块头。
需要说明的是,创世区块将存储在该区块链系统的所有节点中,也就是说,即使根据该划分结果和该目标节点的第一令牌值,确定该目标节点需要存储的目标序号范围不包括该创世区块的序号,该目标节点也将存储该创世区块。
在本发明实施例中,目标节点先获取区块链系统中广播的新生成的第一区块的序号,并获取基于该区块链系统的节点数量生成的第一令牌种子,从而可基于该第一令牌种子和该第一区块的序号确定该第一区块所处的第一序号范围,从而可进一步地基于该第一序号范围和该目标节点的第一令牌值,确定存储该第一区块或者存储该第一区块的区块头,可有效缓解目标节点的数据存储压力,从而可降低区块链系统中网络流量过大的问题,还可同时防止区块链系统中的数据被恶意篡改。
请参见图2,是本发明另一实施例提出的一种数据存储方法的示意流程图,该方法应用于上述的区块链系统,该区块链系统包括多个节点,如图2所示,该方法可包括:
S201,目标节点获取该区块链系统中广播的新生成的第一区块的序号。
S202,该目标节点获取第一令牌种子。
S203,该目标节点基于该第一令牌种子和该第一区块的序号确定该第一区块所处的第一序号范围。
在一个实施例中,步骤S201-步骤S203的具体实施方式可参见上述实施例中步骤S101- 步骤S103的实施方式,在此不再赘述。
S204,该目标节点基于该第一序号范围和该目标节点的第一令牌值,确定存储该第一区块或者存储该第一区块的区块头。
在该目标节点基于该第一序号范围和该目标节点的第一令牌值,确定存储该第一区块或者存储该第一区块的区块头时,该目标节点可先从该多个序号范围内确定与该第一令牌值对应的目标序号范围,该目标序号范围内包括的序号所对应的区块为该目标节点需要存储的区块,进一步地,该目标节点可判断该目标序号范围与该第一序号范围是否一致,在该目标序号范围和该第一序号范围一致时,说明该目标节点需要存储的区块中包括该第一区块,并存储该第一区块,在该目标序号范围和该第一序号范围不一致时,说明该目标节点需要存储的区块不包括该第一区块,则存储该第一区块的区块头。
S205,在令牌种子更新时间到达时,该目标节点获取第二令牌种子。
在一个实施例中,该第二令牌种子是在更新时间到达时,基于该区块链系统的当前的节点数量生成的,该令牌种子更新时间可以是预先设置的时间间隔,假设该预先设置的时间间隔为2周,则每隔两周目标节点获取一次第二令牌种子。或者,该令牌种子更新时间是基于更新周期设置的,该更新周期为相邻两次生成令牌种子之间的时间段,在根据该更新周期设置令牌种子更新时间时,可基于上一令牌周期,设置该令牌种子更新时间,设置的该令牌种子更新时间可能等于该上一令牌周期,也可不等于该上一令牌周期。
随着区块链系统运行时间的增长,该区块链系统的节点数量会发生变化,当该区块链系统加入新节点时,该区块链系统的节点数量增多,当该区块链系统有节点退出时,该区块链系统的节点数量减少,在该区块链系统的节点数量发生变化时,发生变化的节点将在区块链系统中进行广播,以使得该区块链系统中的其他节点确定该区块链系统中节点数量发生的变化,因此,在令牌种子更新时间到达时,该目标节点获取的第二令牌种子和该第一令牌种子可能相同,也可能不相同。
在一个实施例中,如果在令牌种子更新时间到达时,该区块链系统中包括的节点数量发生变化,可由该区块链系统基于变化后的节点数量生成该第二令牌种子,并将该第二令牌种子进行广播,以便于该目标节点从该区块链系统中获取到该第二令牌种子。具体地,该第二令牌种子也可以是由该区块链系统中的某一个节点生成的,例如生成该第一区块的节点。
在一个实施例中,在确定该第二令牌种子时,可基于该区块链系统中发生变化后的节 点数量随机生成第二令牌种子,也可按照预设的生成规则,并结合该第一令牌种子和该区块链系统的节点数量变化前的节点数,生成该第二令牌种子,一般来说,在区块链系统中的节点数量增多时,确定的第二令牌种子大于该第一令牌种子,在该区块链系统中的节点数量减少时,确定的第二令牌种子小于该第一令牌种子。
在该目标节点获取到第二令牌种子后,可执行步骤S206,以实现对该目标节点存储的区块的更新。
S206,该目标节点基于该第二令牌种子,对该第一令牌值进行更新得到该目标节点的第二令牌值。
在目标节点获取到第二令牌种子后,该区块链系统中的各节点将根据该第二令牌种子对该各节点对应的令牌值进行更新,具体地,该目标节点可以及该第二令牌种子,对该目标节点的第一令牌值进行更新,得到该目标节点的第二令牌值。
在目标节点基于该第二令牌种子,对该目标节点的第一令牌值进行更新时,可基于该更新得到的第二令牌种子对该目标节点的第一令牌值进行随机取值,以实现对该目标节点的第一令牌值的更新,并将该随机取值结果作为该目标节点的第二令牌值。
在一个实施例中,在对节点的令牌值进行更新时,为了减少该区块链系统中各节点在对令牌值进行更新后对节点中存储的数据的修改,即减少各节点在对令牌值进行更新后的在对应节点中存储增加的区块的操作和减少在对应节点中删除区块数据的操作,可按照预设的令牌值更新规则,对各节点的令牌值进行更新,从而得到各节点更新后的令牌值。
以目标节点为例,在对该目标节点的第一令牌值按照预设的令牌值更新规则进行更新时,可先将该第一令牌种子和该第二令牌种子进行对比,如果该第一令牌种子大于该第二令牌种子,则该目标节点可先根据该第一令牌种子、该第二令牌种子和该目标节点对应的第一令牌值进行计算,并将该计算结果确定为该目标节点的第二令牌值。
具体地,令该第一令牌种子为t1,更新后的第二令牌种子为t2,该区块链系统中目标节点的第一令牌值在更新前为t,如果t1>t2,则可基于更新后的第二令牌种子t2、该第一令牌种子t1,以及该目标节点更新前的第一令牌值t进行运算,从而可根据该计算结果确定该目标节点的第二令牌值k,在一个实施例中,基于第二令牌种子t2、该第一令牌种子t1,以及该目标节点更新前的第一令牌值t进行计算得到的计算结果为:t2*t/t1,也就是说,在t1>t2,对该目标节点的第一令牌值更新得到的第二令牌值k=t2*t/t1。
在一个实施例中,如果该第一令牌种子小于或等于该第二令牌种子,则该目标节点可 根据该第一令牌种子、该第二令牌种子以及该目标节点的第一令牌值确定该目标节点的第二令牌值的取值范围,从而可从该取值范围内确定该第二令牌值。
具体地,令该第一令牌种子为t1,更新后的第二令牌种子为t2,该区块链系统中目标节点的第一令牌值在更新前为t,如果t1≤t2,则可基于更新后的第二令牌种子t2、该第一令牌种子t1,以及该目标节点更新前的第一令牌值t计算该第二令牌值k的取值范围,在一个实施例中,基于更新后的第二令牌种子t2、该第一令牌种子t1,以及该目标节点更新前的第一令牌值t计算得到的第二令牌值k的取值范围可以为:t2*t/t1≤k<t2*(t+1)/t1,也就是说,在t1≤t2时,k的取值范围为:t2*t/t1≤k<t2*(t+1)/t1。
S207,该目标节点基于该第二令牌种子和该第一区块的序号确定该第一区块所处的第二序号范围,并基于该第二序号范围和该第二令牌值,更新该目标节点存储的区块。
在目标节点确定该第二令牌种子后,可结合该第一区块的序号,确定该第一区块所处的第二序号范围,在确定该第一区块所处的第二序号范围时,可先基于该第二令牌种子对该区块链系统中的节点进行重新划分,即该目标种子可先将该节点数量发生变化的区块链系统中的节点重新划分为多个单位区块,从而可基于该第二令牌种子将各单位区块划分为多个区块序号范围,从而可结合该第一区块的序号,确定出该第一区块所处的第二序号范围。在一个实施例中,在目标节点确定该第一区块所处的第二序号范围后,可根据该第二序号范围和该第二令牌值,更新该目标节点存储的区块。
具体地,在该目标节点基于第二序号范围和该第二令牌值,更新该目标节点存储的区块时,可首先根据该第二序号范围和该第二令牌值确定需要存储的区块和需要删除的区块,并将该需要存储的区块进行存储,对该需要删除的区块进行记录。
在一个实施例中,目标节点在将该需要存储的区块进行存储时,该目标节点可向该区块链系统包括的第一节点发送区块获取请求,其中,该数据获取请求包括该目标节点需要存储但未存储区块的序号,该第一节点为和该目标节点的第二令牌值不同的节点,在该第一节点接收到该目标节点发送的区块获取请求后,可根据该区块获取请求包括的该目标节点需要存储但未存储区块的序号,确定该目标节点需要存储的区块,从而将该目标节点需要存储但未存储的区块发送给目标节点,在该目标节点接收到该需要存储但未存储的区块后,将该需要存储但未存储的区块进行存储。
在具体实现中,区块链系统中的各节点会预先建立通信连接,并在建立通信连接时,将交换建立有通信连接的节点之间令牌值,因此,在目标节点需要存储该目标节点需要存 储但未存储的区块时,可向和该目标节点的第一令牌值不同的第一节点发送数据获取请求,从而获取到该需要存储但未存储的区块,或者,当该目标节点需要对区块链系统的数据实现遍历时,可通过查询和该令牌值不同的节点中存储的区块,实现对整个区块链数据的遍历。
在一个实施例中,由于目标节点是基于该目标节点的第一令牌值、该第一区块序号以及该第一令牌种子,确定的存储该第一区块或者该第一区块的区块头的,因此,该区块链系统中的任意两个对应有相同令牌值的节点所存储的区块是相同的,因此,在目标节点确定需要存储但未存储的区块时,需向和该目标节点对应有不同令牌值的节点发送数据获取请求,以得到该目标节点需要存储但未存储的区块。
在一个实施例中,如果检测到该区块链系统有节点退出,在该节点退出该区块链系统后,可对该区块链系统的节点的数量进行更新,并基于该区块链系统中更新后的节点的数量,对该第一令牌值进行更新得到第二令牌值,并基于该第二令牌值对该目标节点的第一令牌值进行更新,以得到该目标节点的第二令牌值,从而可根据该目标节点的第二令牌值,确定该目标节点需要删除的区块,并从该目标节点中将该需要删除的区块进行删除。其中,在目标节点对该需要删除的区块进行删除时,该目标节点可只删除该需要删除区块的区块数据,而依旧保留存储有该需要删除区块的区块头。
在目标节点将该需要删除的区块进行删除时,先根据该第一令牌种子和该第二令牌种子,确定该区块链系统对应的令牌周期(即token周期),并基于该令牌周期对该需要删除的区块进行删除,具体地,目标节点在确定需要删除的区块后,可先对该需要删除的区块进行记录,并在下一个令牌周期到来时,将该需要删除的区块的区块数据删除,并保留该需要删除的区块的区块头。
在本发明实施例中,目标节点可获取区块链系统中广播的新生成的第一区块的序号,并获取第一令牌种子,从而可基于该第一令牌种子和该第一区块的序号确定该第一区块所处的第一序号范围,进一步地,该目标节点可基于该第一序号范围和该目标节点的第一令牌值,确定存储该第一区块或者存储该第一区块的区块头,当令牌种子更新时间到达时,该目标节点获取该第二令牌种子,并基于该第二令牌种子对该目标节点的第一令牌值进行更新得到第二令牌值,并在基于该第二令牌种子和该第一区块的序号确定该第一区块所处的第二序号范围,从而可基于该第二序号范围和该第二令牌值,对该目标节点存储的区块进行更新,实现了对区块链系统中的节点存储的数据的及时更新,对于数据量较大的节点 而言,可有效降低网络流量,缓解数据存储和数据更新的压力。
本发明实施例还提供一种数据存储装置,该数据存储装置用于执行前述任一项所述的方法的单元。具体地,参见图3,是本发明实施例提供的一种数据存储装置的示意框图。本实施例的贷款审核装置包括获取单元301和确定单元302。
获取单元301,用于获取所述区块链系统中广播的新生成的第一区块的序号,其中,所述目标节点为所述多个节点中的任一个,所述第一区块包括区块数据和区块头,所述区块头包括所述第一区块的序号;
所述获取单元301,还用于获取第一令牌种子,其中,所述第一令牌种子是根据所述区块链系统的节点数量生成的;
确定单元302,用于基于所述第一令牌种子和所述第一区块的序号确定所述第一区块所处的第一序号范围;
所述确定单元302,用于基于所述第一序号范围和所述目标节点的第一令牌值,确定存储所述第一区块或者存储所述第一区块的区块头。
在一个实施例中,所述确定单元302具体用于:
基于所述第一区块的序号确定所述第一区块所处的目标区块单位,其中,每个所述区块单位内包括相同数量的区块;
基于所述第一令牌种子对所述目标区块单位进行划分,得到多个序号范围,其中,不同序号范围对应不同令牌值;
基于所述第一区块的序号在所述多个序号范围内确定所述第一区块所处的第一序号范围。
在一个实施例中,所述确定单元302具体用于:
从所述多个序号范围内确定与所述第一令牌值对应的目标序号范围;
判断所述第一序号范围与所述目标序号范围是否一致;
若一致,则存储所述第一区块;
若不一致,则存储所述第一区块的区块头。
在一个实施例中,所述装置还包括:更新单元303。
所述获取单元301,还用于在令牌种子更新时间到达时,获取第二令牌种子,所述第二令牌种子是在所述令牌种子更新时间到达时,基于所述区块链系统当前的节点数量生成 的;
更新单元303,用于基于所述第二令牌种子,对所述第一令牌值进行更新得到所述目标节点的第二令牌值;
所述更新单元303,还用于基于所述第二令牌种子和所述第一区块的序号确定所述第一区块所处的第二序号范围,并基于所述第二序号范围和所述第二令牌值,更新所述目标节点存储的区块。
在一个实施例中,所述确定单元302具体用于:
根据所述第二序号范围和所述第二令牌值,确定需要存储的区块和需要删除的区块;
对所述需要存储的区块进行存储,并对所述需要删除的区块进行记录。
在一个实施例中,所述确定单元302具体用于:
向第一节点发送区块获取请求,所述区块获取请求包括所述目标节点需要存储但未存储区块的序号,所述第一节点为所述区块链系统中令牌值与所述第二令牌值不同的节点集合中的任一个;
接收所述第一节点基于所述区块获取请求发送的所述目标节点需要存储但未存储区块;
存储所述需要存储但未存储区块。
在一个实施例中,所述装置还包括:删除单元304。
所述删除单元304,用于将在上一个令牌周期内记录的需要删除的区块的区块数据进行删除,所述令牌周期为相邻两次生成令牌种子之间的时间段。
在一个实施例中,所述更新单元303具体用于:
在所述第一令牌种子大于所述第二令牌种子时,根据所述第一令牌种子、所述第二令牌种子和所述目标节点的第一令牌值进行计算,并将计算结果确定为所述目标节点的第二令牌值;
在所述第一令牌种子小于所述第二令牌种子时,根据所述第一令牌种子、所述第二令牌种子和所述目标节点的第一令牌值确定所述目标节点的第二令牌值的取值范围,并在所述取值范围内确定所述第二令牌值。
在本发明实施例中,获取单元301先获取区块链系统中广播的新生成的第一区块的序号,并获取基于该区块链系统的节点数量生成的第一令牌种子,从而确定单元302可基于该第一令牌种子和该第一区块的序号确定该第一区块所处的第一序号范围,从而可进一步 地基于该第一序号范围和该目标节点的第一令牌值,确定存储该第一区块或者存储该第一区块的区块头,可有效缓解目标节点的数据存储压力,从而可降低区块链系统中网络流量过大的问题,还可同时防止区块链系统中的数据被恶意篡改。
参见图4,是本发明实施例提供的一种服务器的示意框图,该服务器用于实现上述方法实施例中提及的贷款平台。如图所示的本实施例中的服务器可以包括:一个或多个处理器401;一个或多个网络接口402,和存储器403。上述处理器401、网络接口402和存储器403通过总线404连接。存储器403用于存储计算机程序,所述计算机程序包括程序指令,处理器401用于执行存储器403存储的程序指令。其中,处理器401被配置用于调用所述程序指令执行:
目标节点获取所述区块链系统中广播的新生成的第一区块的序号,其中,所述目标节点为所述多个节点中的任一个,所述第一区块包括区块数据和区块头,所述区块头包括所述第一区块的序号;
所述目标节点获取第一令牌种子,其中,所述第一令牌种子是根据所述区块链系统的节点数量生成的;
所述目标节点基于所述第一令牌种子和所述第一区块的序号确定所述第一区块所处的第一序号范围;
所述目标节点基于所述第一序号范围和所述目标节点的第一令牌值,确定存储所述第一区块或者存储所述第一区块的区块头。
在一个实施例中,所述处理器401还被配置用于调用所述程序指令执行:
所述目标节点基于所述第一区块的序号确定所述第一区块所处的目标区块单位,其中,每个所述区块单位内包括相同数量的区块;
所述目标节点基于所述第一令牌种子对所述目标区块单位进行划分,得到多个序号范围,其中,不同序号范围对应不同令牌值;
所述目标节点基于所述第一区块的序号在所述多个序号范围内确定所述第一区块所处的第一序号范围。
在一个实施例中,所述处理器401还被配置用于调用所述程序指令执行:
所述目标节点从所述多个序号范围内确定与所述第一令牌值对应的目标序号范围;
所述目标节点判断所述第一序号范围与所述目标序号范围是否一致;
若一致,则所述目标节点存储所述第一区块;
若不一致,则所述目标节点存储所述第一区块的区块头。
在一个实施例中,所述处理器401还被配置用于调用所述程序指令执行:
在令牌种子更新时间到达时,所述目标节点获取第二令牌种子,所述第二令牌种子是在所述令牌种子更新时间到达时,基于所述区块链系统当前的节点数量生成的;
所述目标节点基于所述第二令牌种子,对所述第一令牌值进行更新得到所述目标节点的第二令牌值;
所述目标节点基于所述第二令牌种子和所述第一区块的序号确定所述第一区块所处的第二序号范围,并基于所述第二序号范围和所述第二令牌值,更新所述目标节点存储的区块。
在一个实施例中,所述处理器401还被配置用于调用所述程序指令执行:
所述目标节点根据所述第二序号范围和所述第二令牌值,确定需要存储的区块和需要删除的区块;
所述目标节点对所述需要存储的区块进行存储,并对所述需要删除的区块进行记录。
在一个实施例中,所述处理器401还被配置用于调用所述程序指令执行:
所述目标节点向第一节点发送区块获取请求,所述区块获取请求包括所述目标节点需要存储但未存储区块的序号,所述第一节点为所述区块链系统中令牌值与所述第二令牌值不同的节点集合中的任一个;
所述目标节点接收所述第一节点基于所述区块获取请求发送的所述目标节点需要存储但未存储区块;
所述目标节点存储所述需要存储但未存储区块。
在一个实施例中,所述处理器401还被配置用于调用所述程序指令执行:
所述目标节点将在上一个令牌周期内记录的需要删除的区块的区块数据进行删除,所述令牌周期为相邻两次生成令牌种子之间的时间段。
在一个实施例中,所述处理器401还被配置用于调用所述程序指令执行:
在所述第一令牌种子大于所述第二令牌种子时,所述目标节点根据所述第一令牌种子、所述第二令牌种子和所述目标节点的第一令牌值进行计算,并将计算结果确定为所述目标节点的第二令牌值;
在所述第一令牌种子小于所述第二令牌种子时,所述目标节点根据所述第一令牌种 子、所述第二令牌种子和所述目标节点的第一令牌值确定所述目标节点的第二令牌值的取值范围,并在所述取值范围内确定所述第二令牌值。
在本发明的另一实施例中提供一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,所述计算机程序包括程序指令,所述程序指令被处理器执行时实现上述图1和图2所述的方法。
以上所述,仅为本发明的具体实施方式,但本发明的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本发明揭露的技术范围内,可轻易想到各种等效的修改或替换,这些修改或替换都应涵盖在本发明的保护范围之内。因此,本发明的保护范围应以权利要求的保护范围为准。

Claims (11)

  1. 一种数据存储方法,应用于区块链存储系统,所述区块链系统包括多个节点,其特征在于,所述方法包括:
    目标节点获取所述区块链系统中广播的新生成的第一区块的序号,其中,所述目标节点为所述多个节点中的任一个,所述第一区块包括区块数据和区块头,所述区块头包括所述第一区块的序号;
    所述目标节点获取第一令牌种子,其中,所述第一令牌种子是根据所述区块链系统的节点数量生成的;
    所述目标节点基于所述第一令牌种子和所述第一区块的序号确定所述第一区块所处的第一序号范围;
    所述目标节点基于所述第一序号范围和所述目标节点的第一令牌值,确定存储所述第一区块或者存储所述第一区块的区块头。
  2. 根据权利要求1所述的方法,其特征在于,所述目标节点基于所述第一令牌种子和所述第一区块的序号确定所述第一区块所处的第一序号范围,包括:
    所述目标节点基于所述第一区块的序号确定所述第一区块所处的目标区块单位,其中,每个所述区块单位内包括相同数量的区块;
    所述目标节点基于所述第一令牌种子对所述目标区块单位进行划分,得到多个序号范围,其中,不同序号范围对应不同令牌值;
    所述目标节点基于所述第一区块的序号在所述多个序号范围内确定所述第一区块所处的第一序号范围。
  3. 根据权利要求2所述的方法,其特征在于,所述目标节点基于所述第一序号范围和所述目标节点的第一令牌值,确定存储所述第一区块或者存储所述第一区块的区块头,包括:
    所述目标节点从所述多个序号范围内确定与所述第一令牌值对应的目标序号范围;
    所述目标节点判断所述第一序号范围与所述目标序号范围是否一致;
    若一致,则所述目标节点存储所述第一区块;
    若不一致,则所述目标节点存储所述第一区块的区块头。
  4. 根据权利要求1-3任一项所述的方法,其特征在于,所述方法还包括:
    在令牌种子更新时间到达时,所述目标节点获取第二令牌种子,所述第二令牌种子是在所述令牌种子更新时间到达时,基于所述区块链系统当前的节点数量生成的;
    所述目标节点基于所述第二令牌种子,对所述第一令牌值进行更新得到所述目标节点的第二令牌值;
    所述目标节点基于所述第二令牌种子和所述第一区块的序号确定所述第一区块所处的第二序号范围,并基于所述第二序号范围和所述第二令牌值,更新所述目标节点存储的区块。
  5. 根据权利要求4所述的方法,其特征在于,所述基于所述第二序号范围和所述第二令牌值,更新所述目标节点存储的区块,包括:
    所述目标节点根据所述第二序号范围和所述第二令牌值,确定需要存储的区块和需要删除的区块;
    所述目标节点对所述需要存储的区块进行存储,并对所述需要删除的区块进行记录。
  6. 根据权利要求5所述的方法,其特征在于,所述目标节点对所述需要存储的区块进行存储,包括:
    所述目标节点向第一节点发送区块获取请求,所述区块获取请求包括所述目标节点需要存储但未存储区块的序号,所述第一节点为所述区块链系统中令牌值与所述第二令牌值不同的节点集合中的任一个;
    所述目标节点接收所述第一节点基于所述区块获取请求发送的所述目标节点需要存储但未存储区块;
    所述目标节点存储所述需要存储但未存储区块。
  7. 根据权利要求5所述的方法,其特征在于,所述方法还包括:
    所述目标节点将在上一个令牌周期内记录的需要删除的区块的区块数据进行删除,所述令牌周期为相邻两次生成令牌种子之间的时间段。
  8. 根据权利要求4所述的方法,其特征在于,所述目标节点基于所述第二令牌种子,对所述第一令牌值进行更新得到所述目标节点的第二令牌值,包括:
    在所述第一令牌种子大于所述第二令牌种子时,所述目标节点根据所述第一令牌种子、所述第二令牌种子和所述目标节点的第一令牌值进行计算,并将计算结果确定为所述目标节点的第二令牌值;
    在所述第一令牌种子小于所述第二令牌种子时,所述目标节点根据所述第一令牌种子、所述第二令牌种子和所述目标节点的第一令牌值确定所述目标节点的第二令牌值的取值范围,并在所述取值范围内确定所述第二令牌值。
  9. 一种数据存储装置,应用于区块链存储系统,所述区块链系统包括多个节点,其特征在于,所述装置包括:
    获取单元,用于获取所述区块链系统中广播的新生成的第一区块的序号,其中,所述目标节点为所述多个节点中的任一个,所述第一区块包括区块数据和区块头,所述区块头包括所述第一区块的序号;
    所述获取单元,还用于获取第一令牌种子,其中,所述第一令牌种子是根据所述区块链系统的节点数量生成的;
    确定单元,用于基于所述第一令牌种子和所述第一区块的序号确定所述第一区块所处的第一序号范围;
    所述确定单元,还用于基于所述第一序号范围和所述目标节点的第一令牌值,确定存储所述第一区块或者存储所述第一区块的区块头。
  10. 一种节点服务器,其特征在于,包括存储器、网络接口以及处理器,所述存储器中存储有计算机程序,所述网络接口用于受所述处理器的控制收发消息,所述处理器执行所述计算机程序时实现如权利要求1-8任一项所述的方法。
  11. 一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,其特征在于,所述计算机程序被处理器执行时实现如权利要求1-8任一项所述的方法。
PCT/CN2019/092086 2018-12-27 2019-06-20 基于区块链的数据存储方法、相关设备及存储介质 WO2020133962A1 (zh)

Priority Applications (1)

Application Number Priority Date Filing Date Title
US17/282,312 US20210382872A1 (en) 2018-12-27 2019-06-20 Blockchain-based Data Storage Method, Related Device and Storage Medium

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201811616630.6A CN109857805B (zh) 2018-12-27 2018-12-27 基于区块链的数据存储方法、相关设备及存储介质
CN201811616630.6 2018-12-27

Publications (1)

Publication Number Publication Date
WO2020133962A1 true WO2020133962A1 (zh) 2020-07-02

Family

ID=66892908

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2019/092086 WO2020133962A1 (zh) 2018-12-27 2019-06-20 基于区块链的数据存储方法、相关设备及存储介质

Country Status (3)

Country Link
US (1) US20210382872A1 (zh)
CN (1) CN109857805B (zh)
WO (1) WO2020133962A1 (zh)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109254726A (zh) * 2018-08-16 2019-01-22 华为技术有限公司 分布式存储系统中服务质量保障方法、控制节点及系统
CN109857805B (zh) * 2018-12-27 2020-10-02 重庆小雨点小额贷款有限公司 基于区块链的数据存储方法、相关设备及存储介质

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102402586A (zh) * 2011-10-24 2012-04-04 深圳华强电子交易网络有限公司 一种分布式数据存储方法
CN106506638A (zh) * 2016-11-04 2017-03-15 江苏通付盾科技有限公司 区块链中的区块存储方法及装置
CN107079059A (zh) * 2016-12-21 2017-08-18 深圳前海达闼云端智能科技有限公司 区块链存储方法、装置及节点设备
CN109756566A (zh) * 2018-12-27 2019-05-14 重庆小雨点小额贷款有限公司 基于区块链的数据存储方法、相关设备及存储介质
CN109857805A (zh) * 2018-12-27 2019-06-07 重庆小雨点小额贷款有限公司 基于区块链的数据存储方法、相关设备及存储介质

Family Cites Families (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2016200885A1 (en) * 2015-06-08 2016-12-15 Blockstream Corporation Cryptographically concealing amounts transacted on a ledger while preserving a network's ability to verify the transaction
EP3466137B1 (en) * 2016-05-25 2022-04-27 Nokia Technologies Oy Method, device and system for utilizing block chain to define trusted circle
US10491378B2 (en) * 2016-11-16 2019-11-26 StreamSpace, LLC Decentralized nodal network for providing security of files in distributed filesystems
US10176308B2 (en) * 2017-04-28 2019-01-08 Accenture Global Solutions Limited Entitlement management system
US11121870B2 (en) * 2017-10-12 2021-09-14 Mastercard International Incorporated Method and system for interacting public and private blockchains with controlled participation
KR102417067B1 (ko) * 2017-12-08 2022-07-05 한국전자통신연구원 블록 체인 네트워크의 노드에서 수행되는 블록 생성 방법 및 장치
US11423398B1 (en) * 2018-05-29 2022-08-23 Block, Inc. Recommending conditions for blockchain-enforced contracts
CN108769230B (zh) * 2018-06-06 2021-06-18 腾讯科技(深圳)有限公司 交易数据存储方法、装置、服务器及存储介质
CN108768665B (zh) * 2018-07-02 2021-06-08 上海达家迎信息科技有限公司 区块链生成方法、装置、计算机设备以及存储介质
CN108769264B (zh) * 2018-07-09 2021-06-04 中国联合网络通信集团有限公司 一种区块链分域方法
CN108920723A (zh) * 2018-08-01 2018-11-30 江苏恒宝智能系统技术有限公司 一种节点分层分区管理方法
CN108900364B (zh) * 2018-08-22 2021-11-26 泰康保险集团股份有限公司 区块链网络的管理方法、装置、介质及电子设备

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102402586A (zh) * 2011-10-24 2012-04-04 深圳华强电子交易网络有限公司 一种分布式数据存储方法
CN106506638A (zh) * 2016-11-04 2017-03-15 江苏通付盾科技有限公司 区块链中的区块存储方法及装置
CN107079059A (zh) * 2016-12-21 2017-08-18 深圳前海达闼云端智能科技有限公司 区块链存储方法、装置及节点设备
CN109756566A (zh) * 2018-12-27 2019-05-14 重庆小雨点小额贷款有限公司 基于区块链的数据存储方法、相关设备及存储介质
CN109857805A (zh) * 2018-12-27 2019-06-07 重庆小雨点小额贷款有限公司 基于区块链的数据存储方法、相关设备及存储介质

Also Published As

Publication number Publication date
US20210382872A1 (en) 2021-12-09
CN109857805A (zh) 2019-06-07
CN109857805B (zh) 2020-10-02

Similar Documents

Publication Publication Date Title
WO2020133963A1 (zh) 基于区块链的数据存储方法、相关设备及存储介质
CN110163006B (zh) 一种块链式账本中的签名验证方法、系统、装置及设备
CN106375404B (zh) 数据存储控制方法、数据存储方法、数据获取方法及装置
US11283622B2 (en) Signature verification for a blockchain ledger
CN113726751B (zh) 一种块链式账本中的权重管理方法、装置及设备
CN107104992A (zh) 一种视频云存储的存储资源分配方法和装置
US11379836B2 (en) Methods and systems for recording data based on plurality of blockchain networks
WO2020199711A1 (zh) 数据存储方法、系统、装置及设备
CN110674180A (zh) 一种业务数据处理方法、装置以及可读存储介质
WO2017143957A1 (zh) 一种数据重分布的方法及装置
US11050550B2 (en) Methods and systems for reading data based on plurality of blockchain networks
WO2020199713A1 (zh) 数据验证方法、系统、装置及设备
US11500861B2 (en) Methods and systems for recording data based on plurality of blockchain networks
WO2020133962A1 (zh) 基于区块链的数据存储方法、相关设备及存储介质
WO2020211493A1 (zh) 一种块链式账本中的数据验证方法、系统、装置及设备
US10698623B2 (en) Data processing method and apparatus and storage medium
CN109167819A (zh) 数据同步系统、方法、装置及存储介质
CN114969803A (zh) 一种数据存储方法、装置及存储介质
US11086849B2 (en) Methods and systems for reading data based on plurality of blockchain networks
CN105306545A (zh) 一种集群对外服务节点失效接管的方法及系统
CN114757777A (zh) 用于区块链的最优链路选择方法及装置和电子设备
CN110569231B (zh) 数据迁移方法、装置、设备和介质
CN117472297B (zh) 录像文件的保存时间延长方法、设备及存储介质
US20230104585A1 (en) Method and Apparatus for Monitoring Software License Information, and Server and Storage Medium
CN112291310B (zh) 一种统计连接数的方法及装置

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 19904556

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 19904556

Country of ref document: EP

Kind code of ref document: A1