WO2021027529A1 - Block processing method and device, block consensus method and device and block synchronization method and device - Google Patents

Block processing method and device, block consensus method and device and block synchronization method and device Download PDF

Info

Publication number
WO2021027529A1
WO2021027529A1 PCT/CN2020/104618 CN2020104618W WO2021027529A1 WO 2021027529 A1 WO2021027529 A1 WO 2021027529A1 CN 2020104618 W CN2020104618 W CN 2020104618W WO 2021027529 A1 WO2021027529 A1 WO 2021027529A1
Authority
WO
WIPO (PCT)
Prior art keywords
block
empty
node
empty block
cache
Prior art date
Application number
PCT/CN2020/104618
Other languages
French (fr)
Chinese (zh)
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 深圳前海微众银行股份有限公司
Publication of WO2021027529A1 publication Critical patent/WO2021027529A1/en

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L49/00Packet switching elements
    • H04L49/90Buffering arrangements
    • H04L49/9015Buffering arrangements for supporting a linked list
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • H04L67/1095Replication or mirroring of data, e.g. scheduling or transport for data synchronisation between network nodes
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L9/00Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
    • H04L9/32Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials
    • H04L9/3236Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials using cryptographic hash functions
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L9/00Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
    • H04L9/50Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols using hash chains, e.g. blockchains or hash trees

Definitions

  • the present invention relates to the field of financial technology (Fintech), in particular to a block processing, block consensus and block synchronization method and device.
  • blockchain systems in order to ensure the timing of block generation, blockchain systems based on the consensus algorithm of proof of work (POW) and proof of stake (POS), such as Bitcoin, Ethereum, etc.
  • POW proof of work
  • POS proof of stake
  • the empty blocks are agreed and stored in the blockchain.
  • the blockchain system such as Algorand
  • PBFT practical byzantine fault tolerance
  • the present invention provides a block processing, block consensus, and block synchronization method and device, which are used to solve the problem that the storage of empty blocks on the blockchain in the prior art causes the empty blocks to occupy the disk storage space in the node, thereby improving the Disk utilization.
  • the present invention provides a block processing method, which is suitable for a blockchain system including a main consensus node and an auxiliary consensus node, and the blockchain system includes a blockchain and an empty block cache, Any block in the blockchain is not an empty block, and the empty block cache is used to store empty blocks.
  • the block processing method includes:
  • the master consensus node When determining that the i-th block to be generated is an empty block, the master consensus node first determines the empty block index value of the latest empty block and the hash value of the latest empty block from the empty block cache, and then generates The i-th block and the i-th block are broadcast to each auxiliary consensus node to perform consensus verification on the i-th block. If it is determined that the i-th block passes the consensus verification, then Store the i-th block in the empty block cache.
  • the empty block in the empty block cache is for the empty block generated after the mth block in the blockchain, and the empty block in the empty block cache is increased by the m+1th block in the blockchain When the block is cleared.
  • the empty block index value is used to indicate the order in which each empty block in the empty block cache is generated, and the i-th block includes the empty block index value and the parent empty block hash of the i-th block Value, the hash value of the parent empty block of the i-th block is the hash value of the latest empty block, and the empty block index value of the i-th block is based on the empty block index of the latest empty block The value is determined.
  • the blockchain system includes a blockchain and an empty block cache.
  • the blockchain is used for permanent storage of ledger data
  • the empty block cache is used for temporary storage of empty blocks.
  • the empty block in the current empty block cache will be emptied to save disk storage space in the node and improve disk utilization.
  • the empty block index value and the parent empty block hash value of the empty block are packaged into the empty block at the same time, which is beneficial to each consensus node according to the empty block index value and the parent empty block hash value.
  • the technical solution can also increase the utilization rate of the disk in each node, which helps to enable each node to store more ledger data.
  • generating the i-th block by the master consensus node includes: the master consensus node first obtains the block height and hash value of the highest block on the blockchain, Then add 1 to the block height of the highest block to determine the block height of the i-th block, and determine the hash value of the highest block as the parent block of the i-th block. Hope value, and finally the block height of the i-th block, the hash value of the parent block of the i-th block, the empty block index value of the i-th block and the i-th zone The hash value of the parent empty block of the block is packed into the i-th block.
  • the master consensus node when the master consensus node generates an empty block, it also determines the block height and the hash value of the parent block of the current empty block to be generated according to the block height and hash value of the highest block in the current blockchain. , Each consensus node can perform consensus verification on the empty block based on the block height of the empty block and the hash value of the parent block, combined with the locally stored blockchain, so as to further ensure the stability and security of the blockchain system.
  • the master consensus node determines that the i-th block to be generated is not an empty block, it can obtain the block height and hash value of the highest block on the blockchain , The block height of the highest block is increased by 1 to determine the block height of the i-th block, and the hash value of the highest block is determined as the parent block of the i-th block. Hope value, and then pack the block height of the i-th block and the hash value of the parent block of the i-th block into the i-th block.
  • the master consensus node when the master consensus node generates a non-empty block, it will also determine the block height and parent block hash of the current non-empty block to be generated according to the block height and hash value of the highest block in the current blockchain In this way, each consensus node can also perform consensus verification on the non-empty block based on the block height of the non-empty block and the hash value of the parent block in combination with the locally stored blockchain. Furthermore, when storing the non-empty block on the blockchain, all empty blocks in the current empty block cache can be cleared to further reduce the disk occupancy rate in the node.
  • the empty block cache includes the latest empty block index value
  • the latest empty block index value is the empty block index value of the latest empty block.
  • determining the empty block index value of the latest empty block and the hash value of the latest empty block by the master consensus node from the empty block cache includes: the master consensus node according to the latest empty block Index value, determining the latest empty block from the empty block cache, and obtaining the empty block index value of the latest empty block and the hash value of the latest empty block.
  • the master consensus node may also add 1 to the latest empty block index value.
  • the master consensus node can also generate an empty block according to the latest empty block index.
  • the block index value determines the empty block index value and hash value of the latest empty block from the empty block cache.
  • the present invention provides a block consensus method, which is applicable to a blockchain system including a main consensus node and an auxiliary consensus node, and the blockchain system includes a blockchain and an empty block cache, Any block in the blockchain is not an empty block, and the empty block cache is used to store empty blocks.
  • the empty block in the empty block cache is for the empty block generated after the mth block in the blockchain, and the empty block in the empty block cache is increased by the m+th block in the blockchain. 1 block is cleared, m is a positive integer, the empty block includes the empty block index value and the parent empty block hash value, the empty block index value is used to indicate the empty block in the empty block cache Successively.
  • the block consensus method includes:
  • the secondary consensus node After the secondary consensus node receives the i-th block broadcast by the main consensus node, it determines the empty block index value of the i-th block and the i-th block from the i-th block Determine the hash value of the first empty block and the empty block index value of the first empty block from the empty block cache of the auxiliary consensus node, and then perform consensus on the i-th block Verification: If it is determined that the i-th block passes the consensus verification, the i-th block is stored in the empty block cache of the auxiliary consensus node.
  • the first empty block is the latest empty block in the empty block cache of the auxiliary consensus node
  • the i-th block passing consensus verification includes: the empty block of the i-th block
  • the block index value and the empty block index value of the first empty block meet a preset requirement
  • the hash value of the parent empty block of the i-th block is equal to the hash value of the first empty block.
  • the blockchain system includes a blockchain and an empty block cache.
  • the blockchain is used for permanent storage of ledger data
  • the empty block cache is used for temporary storage of empty blocks.
  • the empty block in the current empty block cache will be cleared, which helps to save the disk storage space in the node and improve the utilization of the disk.
  • the secondary consensus node determines the empty block index value and parent empty block hash value of the i-th block from the i-th block, and combines the local empty block cache The empty block index value and hash value of the latest empty block in, perform consensus verification on the i-th block, which can ensure the stability and security of the blockchain system.
  • the auxiliary consensus node may also determine the block height of the i-th block and the parent block of the i-th block from the i-th block. Hope value, determine the block height of the highest block and the hash value of the highest block from the blockchain of the secondary consensus node, if the block height of the i-th block is equal to the highest block’s If the block height is increased by 1, and the hash value of the parent block of the i-th block is equal to the hash value of the highest block, the i-th block passes the consensus verification.
  • the block height of the i-th block and the hash value of the parent block are obtained through the auxiliary consensus node, and the block height of the i-th block and the hash value of the parent block are combined with the local blockchain.
  • the block height and hash value of the highest block of, and the consensus verification of the i-th block can further ensure the stability and security of the blockchain system.
  • the secondary consensus node determines from the i-th block that the empty block index value of the i-th block is a preset value, and the i-th zone If the hash value of the parent empty block of the block is a null value, the secondary consensus node determines the block height of the i-th block and the parent block of the i-th block from the i-th block Hash value, determine the block height of the highest block and the hash value of the highest block from the blockchain of the secondary consensus node, if it is determined that the block height of the i-th block is equal to the highest zone If the block height is increased by 1, and the hash value of the parent block of the i-th block is equal to the hash value of the highest block, it is determined that the i-th block passes the consensus verification, and The i-th block is stored in the empty block cache of the auxiliary consensus node.
  • the secondary consensus node determines that the index value of the empty block in the i-th block is a preset value, and the hash value of the parent block is empty, it can be determined that the i-th block is an empty block in the cache The first empty block.
  • the auxiliary consensus node performs consensus verification on the first empty block in the empty block cache, which can verify the block height of the first empty block and the hash value of the parent block, which helps to ensure the stability and security of the blockchain system Sex.
  • the present invention provides a block synchronization method, which is suitable for a block chain system including multiple nodes.
  • the block chain system includes a block chain and an empty block cache. Any block in the chain is not an empty block, and the empty block cache is used to store empty blocks.
  • the empty block in the empty block cache is for the empty block generated after the mth block in the blockchain, and the empty block in the empty block cache is increased by the m+th block in the blockchain. 1 block is cleared, m is a positive integer, the multiple nodes include a first node and a second node, the first node is any one of the multiple nodes, and the second node is all Any one of the plurality of nodes except the first node.
  • the block synchronization method includes:
  • the first node receives the state information broadcast by the second node, and obtains the empty block index value of the latest empty block in the empty block cache of the second node and the block of the second node from the state information
  • the block height of the highest block of the chain if it is determined that the block height of the highest block of the second node’s blockchain is equal to the block height of the highest block of the first node’s blockchain, and the second If the empty block index value of the latest empty block of the node is greater than the empty block index value of the latest empty block of the first node, the empty block to be synchronized is determined from the empty block cache of the second node, and the to-be-synchronized empty block is determined
  • the empty block is synchronized to the empty block cache of the first node.
  • the empty block to be synchronized is an empty block whose empty block index value in the empty block cache of the second node is greater than the empty block index value of the latest empty block of the first node.
  • the first node can obtain the empty block to be synchronized from the second node to ensure that all nodes in the blockchain system are up to date status.
  • the first node synchronizing the empty block to be synchronized to the empty block cache of the first node includes: the first node targets any empty block to be synchronized, Obtain the parent empty block hash value and the empty block index value of the empty block to be synchronized, if it is determined that the parent empty block hash value of the empty block to be synchronized is equal to the latest empty block in the empty block cache of the first node Hash value, and the empty block index value of the empty block to be synchronized is equal to the empty block index value of the latest empty block of the first node plus 1, then it is determined to synchronize the empty block to be synchronized to the first node The empty block is in the cache.
  • the empty block to be synchronized includes the hash value of the parent block.
  • the first node determines to synchronize the empty block to be synchronized to the first node Before the empty block is cached, it can also be determined whether the hash value of the parent block in the empty block to be synchronized is equal to the hash value of the highest block on the blockchain of the first node.
  • the first node considering that the first node will receive the state information broadcast by multiple nodes, that is, the first node can synchronize data to multiple nodes at the same time.
  • the first node can first perform repetitive verification on empty blocks to be synchronized, so that the first node does not synchronize data that has already been synchronized as much as possible.
  • the state information further includes the block height of the block chain of the second node.
  • the first node is in the empty block from the second node.
  • the cache determines the empty block to be synchronized, if it is determined that the block height of the highest block of the blockchain of the second node is greater than the block height of the highest block of the blockchain of the first node, synchronize the second After the blocks of the block chain of the node that are higher than the block chain of the first node are synchronized, the empty block cache of the first node is cleared.
  • the first node first synchronizes the non-empty blocks on the blockchain from the second node according to the block height of the highest block of the local blockchain and the block height of the highest block of the second node’s blockchain. , And after synchronizing to a non-empty block, clear the empty block in the local empty block cache.
  • the data synchronization in the first node can be realized with the least number of synchronizations.
  • the present invention provides a block processing device suitable for a block chain system including a main consensus node and an auxiliary consensus node.
  • the block chain system includes a block chain and an empty block cache.
  • the block chain None of the blocks is an empty block, and the empty block cache is used to store empty blocks.
  • the device includes:
  • the determining unit is configured to determine the empty block index value of the latest empty block and the hash value of the latest empty block from the empty block cache when it is determined that the i-th block to be generated is an empty block; where i , M is a positive integer; the empty block in the empty block cache is for the empty block generated after the mth block in the blockchain, and the empty block in the empty block cache is in the blockchain It is emptied when the m+1 th block is added, and the empty block index value is used to indicate the sequence in which the empty blocks in the empty block cache are generated;
  • a generating unit configured to generate the i-th block and broadcast the i-th block to each auxiliary consensus node; the i-th block includes the empty block index of the i-th block Value and the parent empty block hash value, the parent empty block hash value of the i-th block is the hash value of the latest empty block, and the empty block index value of the i-th block is based on the The empty block index value of the latest empty block is determined;
  • the storage unit is configured to store the i-th block in the empty block cache after determining that the i-th block passes the consensus verification.
  • the generating unit is specifically configured to: obtain the block height and hash value of the highest block on the blockchain, and determine that the block height of the highest block is increased by 1
  • the block height of the i-th block, the hash value of the highest block is determined as the parent block hash value of the i-th block, and the block height of the i-th block
  • the hash value of the parent block of the i-th block, the empty block index value of the i-th block and the hash value of the parent empty block of the i-th block are packed into the i-th zone Piece.
  • the generating unit is further configured to: when the determining unit determines that the i-th block to be generated is not an empty block, obtain the value of the highest block on the blockchain Block height and hash value, the block height of the highest block plus 1 is determined as the block height of the i-th block, and the hash value of the highest block is determined as the i-th zone
  • the hash value of the parent block of the block, the block height of the i-th block and the hash value of the parent block of the i-th block are packed into the i-th block.
  • the empty block cache includes the latest empty block index value
  • the latest empty block index value is the empty block index value of the latest empty block.
  • the determining unit is specifically configured to: determine the latest empty block from the empty block cache according to the latest empty block index value and obtain the empty block index value of the latest empty block and the hash value of the latest empty block. Hope value.
  • the storage unit is further configured to: after storing the i-th block in the empty block cache, add 1 to the latest empty block index value.
  • the present invention provides a block consensus device, which is suitable for a block chain system including a main consensus node and an auxiliary consensus node.
  • the block chain system includes a block chain and an empty block cache.
  • the block chain None of the blocks is an empty block, and the empty block cache is used to store empty blocks.
  • the empty block in the empty block cache is for the empty block generated after the mth block in the blockchain, and the empty block in the empty block cache is increased by the m+th block in the blockchain. 1 block is cleared, m is a positive integer, the empty block includes the empty block index value and the parent empty block hash value, the empty block index value is used to indicate the empty block in the empty block cache Priority.
  • the device includes:
  • the determining unit is configured to determine the empty block index value of the i-th block and the hash value of the parent empty block of the i-th block from the i-th block, and from the auxiliary consensus node Determining the hash value of the first empty block and the empty block index value of the first empty block in the empty block cache; the first empty block is the latest empty block in the empty block cache of the secondary consensus node;
  • a storage unit configured to store the i-th block in the empty block cache of the auxiliary consensus node if it is determined that the i-th block passes the consensus verification; the i-th block passes the consensus verification Including the empty block index value of the i-th block and the empty block index value of the first empty block meet the preset requirements, and it is determined that the hash value of the parent empty block of the i-th block is equal to the The hash value of an empty block.
  • the determining unit is further configured to: determine the block height of the i-th block and the parent block of the i-th block from the i-th block
  • the hash value determines the block height of the highest block and the hash value of the highest block from the blockchain of the auxiliary consensus node.
  • the i-th block passes the consensus verification, further comprising: the block height of the i-th block is equal to the block height of the highest block plus 1, and the parent area of the i-th block
  • the block hash value is equal to the hash value of the highest block.
  • the determining unit is further configured to: determine from the i-th block that the empty block index value of the i-th block is a preset value, and the i-th block
  • the hash value of the parent empty block of each block is a null value
  • the block height of the i-th block and the hash value of the parent block of the i-th block are determined from the i-th block, Determine the block height of the highest block and the hash value of the highest block from the blockchain of the secondary consensus node, if it is determined that the block height of the i-th block is equal to the block height of the highest block Plus 1, and the hash value of the parent block of the i-th block is equal to the hash value of the highest block, it is determined that the i-th block passes the consensus verification.
  • the present invention provides a block synchronization device, which is suitable for a block chain system including multiple nodes.
  • the block chain system includes a block chain and an empty block cache, and any block in the block chain All blocks are not empty blocks, and the empty block cache is used to store empty blocks.
  • the empty block in the empty block cache is for the empty block generated after the mth block in the blockchain, and the empty block in the empty block cache is increased by the m+th block in the blockchain. 1 block is cleared, m is a positive integer, the multiple nodes include a first node and a second node, the first node is any one of the multiple nodes, and the second node is all Any one of the plurality of nodes except the first node.
  • the device includes:
  • the receiving unit is configured to receive the state information broadcast by the second node;
  • the state information includes the empty block index value of the latest empty block in the empty block cache of the second node and the block chain value of the second node The block height of the highest block;
  • the determining unit is configured to determine that the block height of the highest block of the blockchain of the second node is equal to the block height of the highest block of the blockchain of the first node and the latest empty block of the second node If the empty block index value is greater than the empty block index value of the latest empty block of the first node, the empty block to be synchronized is determined from the empty block cache of the second node; the empty block to be synchronized is the second The empty block whose empty block index value is greater than the empty block index value of the latest empty block of the first node in the empty block cache of the node;
  • the synchronization unit is configured to synchronize the empty block to be synchronized to the empty block cache of the first node.
  • the synchronization unit is specifically configured to: for any empty block to be synchronized, obtain the parent empty block hash value and the empty block index value of the empty block to be synchronized, and if it is determined that the The hash value of the parent empty block of the empty block to be synchronized is equal to the hash value of the latest empty block in the empty block cache of the first node, and the empty block index value of the empty block to be synchronized is equal to the latest empty block of the first node
  • the empty block index value of the empty block is increased by 1, and it is determined to synchronize the empty block to be synchronized to the empty block cache of the first node.
  • the empty block to be synchronized includes the hash value of the parent block.
  • the synchronization unit before determining to synchronize the empty block to be synchronized to the empty block cache of the first node, the synchronization unit also determines whether the hash value of the parent block in the empty block to be synchronized is equal to all The hash value of the highest block on the blockchain of the first node.
  • the state information further includes the block height of the blockchain of the second node.
  • the synchronization unit determines the empty block to be synchronized from the empty block cache of the second node, if it is determined that the block height of the highest block of the blockchain of the second node is greater than the If the block height of the highest block of the blockchain of the first node is synchronized, the block of the blockchain of the second node that is higher than the block of the first node’s blockchain is synchronized, and is in the area of the first node. After the blocks of the block chain are synchronized, the empty block cache of the first node is cleared.
  • the present invention provides a computing device, including:
  • Memory used to store program instructions
  • the processor is configured to call the program instructions stored in the memory, and execute the block processing method, block consensus method, and block synchronization method described in any of the first to third aspects according to the obtained program.
  • the present invention provides a computer-readable non-volatile storage medium, including computer-readable instructions.
  • the computer reads and executes the computer-readable instructions, the computer executes the first to third aspects described above. Any of the block processing methods, block consensus methods, and block synchronization methods.
  • FIG. 1 is a schematic structural diagram of an empty block header provided by an embodiment of the present invention
  • FIG. 2 is a schematic flowchart of a block processing method provided by an embodiment of the present invention.
  • FIG. 3 is a schematic flowchart of another block processing method provided by an embodiment of the present invention.
  • FIG. 4 is a schematic flowchart of a block consensus method provided by an embodiment of the present invention.
  • FIG. 5 is a schematic flowchart of another block consensus method provided by an embodiment of the present invention.
  • FIG. 7 is a schematic flowchart of a block synchronization method provided by an embodiment of the present invention.
  • FIG. 8 is a schematic diagram of a second node broadcasting status information according to an embodiment of the present invention.
  • FIG. 9 is a schematic diagram of receiving state information of a first node according to an embodiment of the present invention.
  • FIG. 10 is a schematic structural diagram of a block processing apparatus provided by an embodiment of the present invention.
  • FIG. 11 is a schematic structural diagram of a block consensus device provided by an embodiment of the present invention.
  • FIG. 12 is a schematic structural diagram of a block synchronization device provided by an embodiment of the present invention.
  • Block The basic unit that constitutes the blockchain. It consists of a block header containing metadata and a block body containing transaction data.
  • the block header mainly includes the hash of the parent block.
  • a blockchain is a chain composed of a series of blocks. In addition to recording the data of the block, each block also records the hash value (Hash) of the previous block. In this way, a chain is formed.
  • Hash hash value
  • a block is composed of a block header and a block body.
  • the block header includes important fields such as the block height of the block and the parent block hash (prevHash), and the block body mainly stores transaction data.
  • Consensus algorithm Each node in the blockchain network confirms a batch of transactions through an algorithm, and ensures that all nodes have a consistent confirmation result for this batch of data.
  • This algorithm is the consensus algorithm of the blockchain, which is currently common Consensus algorithms include PBFT, replication and fault tolerance (Raft), POW, POS, etc.
  • Transaction pool The queue that stores all valid transactions initiated by the client is called the transaction pool.
  • the transactions that enter the transaction pool must meet the following conditions: (1) It does not overlap with existing transactions in the transaction pool; (2) It is the same as that recorded in the block. The transaction is not repeated; (3) The signature is valid.
  • Each participant in the blockchain network is a node, and the node participates in network formation and data exchange.
  • a node refers to a participant with a unique identity.
  • the node has a complete copy of the ledger and has the ability to participate in the consensus and maintenance of the blockchain network.
  • Consensus node A node that can participate in consensus block generation. Its main functions include: packaging transactions in the transaction pool into blocks; executing transactions; running consensus algorithms and writing consensus blocks into the ledger.
  • PBFT consensus algorithm It can reach a consensus in a few nodes doing evil (such as forging messages). It uses cryptographic algorithms such as signatures, signature verification, and hashing to ensure tamper-proof modification, anti-forgery, and non-repudiation in the process of message transmission. And optimize the previous work, reduce the complexity of the Byzantine fault-tolerant algorithm from exponential level to polynomial level, in a system composed of (3 ⁇ f+1) nodes, as long as there are no less than (2 ⁇ f+1) If non-malicious nodes work normally, the system can reach consistency. For example, in a 7-node system, 2 nodes are allowed to have Byzantine errors.
  • Empty block A block that does not contain any transactions.
  • Non-empty block corresponds to the empty block, including the transaction block.
  • QPS SQL Per Second
  • the number of requests per second The calculation consensus is the number of requests divided by time.
  • the present invention provides a block processing method, a block consensus method, and a block synchronization method, which are suitable for a block chain system.
  • the block chain system is the aforementioned block chain network.
  • the block chain system includes a block chain and Empty block cache, the blockchain is used to store non-empty blocks, that is, any block in the blockchain is not an empty block, the empty block cache is used to store empty blocks, and the empty blocks in the empty block cache are for the blockchain
  • the empty blocks generated after the mth block in the middle and empty blocks in the empty block cache are emptied when the m+1th block is added to the blockchain.
  • m is a positive integer.
  • the empty block upload in the present invention refers to storing the empty block in the empty block cache.
  • the empty block in the empty block cache will be emptied after the next non-empty block is uploaded (stored to the blockchain), that is, all empty blocks in the current empty block cache are deleted.
  • the block height is 100.
  • the first empty block is generated and stored in the empty block cache, and then the second empty block, the third empty block...the tenth empty block is generated and stored in the empty block cache.
  • no non-empty block will be generated from the first empty block to the tenth empty block.
  • the block height is 101, and the blockchain system deletes the 10 empty blocks currently cached in the empty block cache.
  • the blockchain system If the blockchain system generates an empty block again, it will be stored as the first empty block in the empty block cache again, and then the second empty block to the nth empty block may be stored in the empty block cache, but it will When the 102nd non-empty block is generated and stored on the blockchain by consensus, it is emptied again.
  • the header of the empty block can be set.
  • the header of an empty block includes multiple fields, which can include empty block index value, parent empty block hash value, parent block hash value (prevHash), block height (blockNumber), and sealer.
  • the index value of the empty block and the hash value of the parent empty block can be stored in an extended array (extraData).
  • FIG. 1 is a structure of an empty block header provided by an embodiment of the present invention. The following describes each field in the header of the empty block shown in FIG. 1.
  • Parent block hash the hash value of the highest non-empty block, that is, the hash value of the highest block on the blockchain;
  • Block height the block height of the highest non-empty block plus 1, that is, the block height of the highest block on the blockchain plus 1;
  • the index of the consensus node that generates the empty block which is equivalent to the index of the master consensus node.
  • the node identification number (Identification, ID) is very long, directly including the node ID field in the consensus message will consume part of the network bandwidth. Therefore, the blockchain system in the embodiment of the present invention introduces a node index.
  • a public node list can be set in the blockchain system, and the node index of each node is recorded in the public node list, and the node index is used to indicate the position of each node in the public node list.
  • Empty block index value the empty block index value generated based on the highest non-empty block, used to indicate the order of the empty blocks in the empty block cache, such as: the current empty block is the fifth generated based on the 10th non-empty block Empty block, the empty block index of the current empty block is 4.
  • Hash value of the parent empty block The hash value of the previous empty block can be obtained through the empty block cache.
  • the empty block cache can be understood as an empty block table consisting of multiple empty block arrangements. As shown in Table 1, it is an empty block table structure.
  • the nth empty block records the n-1th empty block Hash value, the index value of the empty block recorded in the nth empty block is (n-1).
  • the empty block table records the latest empty block index value (latestIdx) of the current empty block cache, that is, the empty block index value of the latest empty block.
  • the blockchain system will add 1 to the index value of the latest empty block and pack it into the header of the n+1th empty block.
  • the latest empty block index value is updated to n.
  • the blockchain system includes multiple nodes, and each node stores the above-mentioned blockchain and empty block cache locally.
  • the multiple nodes include a main consensus node and an auxiliary consensus node.
  • the main consensus node is used for packaging blocks and block consensus
  • the auxiliary consensus node is used for block consensus.
  • Figures 2 and 3 exemplarily show the flow of a block processing method provided by an embodiment of the present invention.
  • the flow can be executed by a block processing device, which can be located in a node of a blockchain network, for example, The master consensus node for packaging blocks.
  • the blockchain system periodically generates blocks.
  • the master consensus node When the master consensus node is generating blocks, it can first determine whether any transactions are packaged into the block when the current block is generated, that is, whether the block to be generated is an empty block .
  • the block to be generated is an empty block and a non-empty block, the corresponding operation steps are different, and the following descriptions are divided into situations.
  • the process includes:
  • Step 201 When determining that the i-th block to be generated is an empty block, the master consensus node determines the empty block index value of the latest empty block and the hash value of the latest empty block from the empty block cache;
  • Step 202 The main consensus node generates the i-th block and broadcasts the i-th block to each auxiliary consensus node;
  • step 203 after determining that the i-th block passes the consensus verification, the master consensus node stores the i-th block in the empty block cache.
  • i is a positive integer
  • at least one empty block is stored in the empty block cache
  • the master consensus node can determine the latest empty block from the empty block cache, that is, the last empty block stored in the empty block cache.
  • the master consensus node determines the empty block index value of the latest empty block and the hash value of the latest empty block according to the latest empty block, wherein the empty block index of the i-th block is determined according to the empty block index value of the latest empty block
  • the value can be the empty block index value of the i-th block determined by adding 1 to the empty block index value of the latest empty block, and the hash value of the latest empty block is determined as the parent empty block of the i-th block. Hope value, and generate the i-th block according to the empty block index value of the i-th block and the hash value of the parent empty block.
  • the i-th block may include the empty block index value and the parent empty block hash value of the i-th block, and may also include the block height of the i-th block and the i-th block.
  • the hash value of the parent block of each block can be the block height of the highest block on the current blockchain plus 1, or it can be equal to the highest block on the current blockchain.
  • the hash value of the parent block of the i-th block may be the hash value of the highest block on the current blockchain, for example, it may be the hash value of the block header of the highest block. In this situation:
  • the master consensus node can obtain the block height and hash value of the highest block from the blockchain, add 1 to the block height of the highest block to determine the block height of the i-th block, and The hash value of the highest block is determined as the hash value of the parent block of the i-th block, and then the block height of the i-th block, the hash value of the parent block of the i-th block, and the i-th block The empty block index value of the block and the hash value of the parent empty block of the i-th block are packed into the i-th block.
  • the latest empty block index value may be set in the empty block cache, and the latest empty block index value is the empty block index value of the latest empty block.
  • the master consensus node can determine the latest empty block index value from the empty block cache, and according to the latest empty block index value, determine the latest empty block from the empty block cache and obtain the empty block index value of the latest empty block and the latest empty block index value.
  • Hash value, and then hash the block height of the i-th block, the hash value of the parent block of the i-th block, the empty block index value of the i-th block and the parent empty block of the i-th block The value is packed into the i-th block. After storing the i-th block in the empty block cache, the master consensus node can increase the index value of the latest empty block by 1.
  • the master consensus node before the master consensus node generates the i-th block, if at least one empty block is stored in the empty block cache, the master consensus node can obtain the parent empty block of the i-th block. Hope value. If there is no empty block stored in the empty block cache, it is equivalent to the i-th block being the first empty block in the current empty block cache, and the master consensus node cannot obtain the parent empty block hash of the i-th block In this case, the master consensus node can set the hash value of the parent empty block of the i-th block to be empty.
  • the master consensus node can directly determine whether there are empty blocks stored in the current empty block cache before generating the i-th block, or read the latest empty block index value in the current empty block cache to determine Whether there are empty blocks stored in the current empty block cache, if the master consensus node reads that the latest empty block index value is a preset value, it can determine that there are no empty blocks stored in the current empty block cache.
  • the preset value can be -1 or 0 or other values, the preset value is used to indicate that there are no empty blocks in the current empty block cache.
  • the master consensus node sets the hash value of the parent empty block of the i-th block to empty, and sets the empty block index value of the i-th block Set to the preset value plus 1.
  • the master consensus node can obtain the latest empty block index value. If the latest empty block index value is -1, the block header of the highest non-empty block on the blockchain is obtained, and the block header of the highest non-empty block is hashed The value is determined as the hash value of the parent block of the current empty block, and 0 is determined as the empty block index value of the current empty block, and the block height of the highest non-empty block is added by 1 to determine the block height of the current empty block. If the index value of the latest empty block is greater than 0, read the block header of the latest empty block from the empty block cache, and determine the hash value of the latest empty block as the parent empty block hash value of the current empty block.
  • the latest empty block index value plus 1 is determined as the empty block index value of the current empty block, and the block header hash value of the highest non-empty block is determined as the parent block hash value of the current empty block, and the highest non-empty block The block height plus 1 is determined as the block height of the current empty block.
  • the process includes:
  • Step 301 When determining that the i-th block to be generated is not an empty block, the master consensus node obtains the block height and hash value of the highest block on the blockchain;
  • Step 302 The master consensus node adds 1 to the block height of the highest block to determine the block height of the i-th block, and determines the hash value of the highest block as the parent block hash value of the i-th block;
  • Step 303 The master consensus node packs the block height of the i-th block and the hash value of the parent block of the i-th block into the i-th block;
  • Step 304 the main consensus node broadcasts the i-th block to each auxiliary consensus node;
  • Step 305 After determining that the i-th block passes the consensus verification, the master consensus node stores the i-th block in the blockchain, and clears the empty block in the current empty block cache.
  • the i-th block is the m+1th block
  • storing the i-th block in the blockchain is equivalent to storing the m+1th block in the blockchain. That is, the empty block in the empty block cache is generated after the mth block in the blockchain, and will be deleted when the m+1th block is stored in the blockchain.
  • the master consensus node can generate an empty block or a non-empty block, and each consensus node can perform consensus verification on the empty block and the non-empty block respectively.
  • non-empty blocks include parent block hash value, block height, and master consensus node index.
  • Each consensus node can be based on the parent block hash value and block height of the non-empty block. , The index of the master consensus node, combined with the blockchain of this consensus node, to perform consensus verification on the non-empty block;
  • Each consensus node performs consensus verification on the empty block: the empty block generated by the master consensus node can be divided into whether it is the first empty block in the empty block cache. If it is not the first empty block in the empty block cache, the empty block The block includes the parent block hash value, block height, empty block index value, parent block hash value, and master consensus node index. When consensus is on the empty block, each consensus node can be based on the parent block in the empty block. Hope value, block height, empty block index value, parent empty block hash value, master consensus node index, combined with the consensus node's blockchain and empty block cache, perform consensus verification on the empty block.
  • the empty block includes the hash value of the parent block, the block height, the index value of the empty block, and the index of the master consensus node.
  • each consensus node can According to the parent block hash value, block height, empty block index value, master consensus node index in the empty block, combined with the consensus node's blockchain and empty block cache, consensus verification is performed on the empty block.
  • the present invention also provides a block consensus method.
  • the block consensus method is also applicable to the above-mentioned blockchain system, and may be after the master consensus node packs and broadcasts the i-th block, The process by which consensus nodes carry out consensus.
  • Each consensus node can agree on empty blocks, non-empty blocks, and in empty block consensus, it can be the consensus on the first empty block in the empty block cache, or the consensus on the first empty block in the empty block cache.
  • Empty block consensus is to verify the block height of the i-th block and the hash value of the parent block. The specific verification process will not be repeated, but the consensus node will determine that the i-th block has passed the consensus verification. After the empty blocks are stored on the blockchain, the empty blocks in the local empty block cache can be cleared.
  • auxiliary consensus nodes When the secondary consensus node receives the i-th block, it can determine whether there is a parent empty block hash value in the i-th block or can read the empty block index value in the i-th block to determine the Whether the i-th block is the first empty block in the empty block cache.
  • the auxiliary consensus node may execute the process of each step in the flowchart shown in FIG. 4, which includes :.
  • Step 401 the auxiliary consensus node receives the i-th block broadcast by the main consensus node;
  • Step 402 The auxiliary consensus node determines the empty block index value of the i-th block and the hash value of the parent empty block of the i-th block from the i-th block;
  • Step 403 The auxiliary consensus node determines the hash value of the first empty block and the empty block index value of the first empty block from the empty block cache of the auxiliary consensus node;
  • step 404 if the auxiliary consensus node determines that the i-th block passes the consensus verification, the i-th block is stored in the empty block cache of the auxiliary consensus node.
  • the auxiliary consensus node After the auxiliary consensus node receives the i-th block, it combines the blockchain of the auxiliary consensus node and the empty block cache to perform consensus verification on the empty block. Specifically, after determining that the latest empty block in the local empty block cache is the first empty block, the secondary consensus node determines the empty block index value of the first empty block and the hash value of the first empty block, and determines the i-th empty block Whether the empty block index value of the block and the empty block index value of the first empty block meet the preset requirements can be determined by judging whether the empty block index value of the i-th block is equal to the empty block index value of the first empty block plus 1. And judging whether the hash value of the parent empty block of the i-th block is equal to the hash value of the first empty block, and if the two judgments are equal, it is determined that the i-th block passes the consensus verification.
  • the auxiliary consensus node when it performs consensus verification on the i-th block, it may also include verification of the block height in the i-th block and the hash value of the parent block. Specifically, the secondary consensus node determines the block height of the i-th block and the hash value of the parent block of the i-th block from the i-th block, and determines the highest block from the blockchain of the secondary consensus node The block height of and the hash value of the highest block, and the consensus verification of the i-th block is performed according to the block height and the parent block hash.
  • consensus verification includes not only verifying whether the empty block index value of the i-th block and the empty block index value of the first empty block meet the preset requirements, but also verifying whether the hash value of the parent empty block is equal to that of the first empty block.
  • the hash value also includes: verifying whether the block height of the i-th block is equal to the block height of the highest block plus 1 and whether the hash value of the parent block of the i-th block is equal to the hash value of the highest block.
  • the auxiliary consensus node when the auxiliary consensus node determines that the i-th block is the first empty block, that is, the auxiliary consensus node determines that the empty block index value of the i-th block is a preset value, and If the hash value of the parent empty block of the i-th block is a null value, the auxiliary consensus node can execute the process of each step in the flowchart shown in FIG. 5, which includes:
  • Step 501 the auxiliary consensus node determines the block height of the i-th block and the hash value of the parent block of the i-th block from the i-th block;
  • Step 502 the auxiliary consensus node determines the block height of the highest block and the hash value of the highest block from the blockchain of the auxiliary consensus node;
  • Step 503 If the secondary consensus node determines that the block height of the i-th block is equal to the block height of the highest block plus 1, and the hash value of the parent block of the i-th block is equal to the hash value of the highest block, it determines The i-th block passes consensus verification;
  • the auxiliary consensus node stores the i-th block in the empty block cache of the auxiliary consensus node.
  • the PBFT consensus algorithm is taken as an example for specific description.
  • each consensus node signs the messages it sends during the PBFT consensus process, and verifies and signs the received message packets. Therefore, each node maintains a public and private key pair, and the private key is used to The sent message is signed, and the public key is used as the node ID to identify and verify the signature.
  • the node ID is the signature public key of the consensus node and the unique identification of the consensus node, which is generally a 64-byte binary string.
  • Other nodes use the node ID of the message packet sender to verify the message packet.
  • each consensus node maintains a public consensus node list.
  • the node index records the position of each consensus node ID in this list.
  • the node ID is indexed in the node list, and the message is verified and signed.
  • the node index is used to indicate the position of each consensus node ID in this public node ID list.
  • Consensus nodes can be divided into primary consensus nodes (Leader/Primary nodes) and replica nodes (Replica nodes, which are equivalent to secondary consensus nodes in the embodiment of the present invention).
  • the master consensus node is responsible for packaging transactions into blocks and block consensus. There is and only one master consensus node during each round of consensus. In order to prevent the master consensus node from forging blocks, after each round of PBFT consensus, the master will switch Consensus node.
  • the replica node is responsible for block consensus. There can be multiple replica nodes in each round of consensus, and the processing process of each replica node is similar.
  • the main consensus node in the current consensus process can be determined according to a preset algorithm. For example, assuming that the current system includes N consensus nodes, the latest block hash is blockHash, then the current main consensus node index Can be: blockHash%N.
  • the consensus node can also be divided into Byzantine nodes and non-Byzantine nodes.
  • Byzantine nodes are understood as malicious nodes and cannot normally participate in consensus. Assuming that the total number of system nodes is 3 ⁇ f+1, when the Byzantine nodes exceed f, the system cannot reach a normal consensus.
  • Non-Byzantine nodes are understood as honest nodes and can participate in the consensus normally. If the total number of system nodes is 3 ⁇ f+1, when the non-Byzantine nodes are not less than 2 ⁇ f+1, the system can agree normally.
  • the PBFT consensus algorithm uses a view to record the consensus state of each node, and the same view node maintains the same node list of the master consensus node and the replica node.
  • a view switch will occur. If the view switch is successful (for example, at least 2 ⁇ f+1 nodes reach the same view), a new master consensus node will be selected based on the new view, and the new master consensus node will start Generate a block, otherwise continue to switch views until most of the nodes in the entire network (greater than or equal to 2 ⁇ f+1) reach a consistent view.
  • Step 601 The master consensus node determines that the block to be generated is an empty block
  • Step 602 the master consensus node determines the latest empty block index value B:
  • Step 603 Determine that there are no empty blocks in the current empty block cache
  • Step 604 Determine that there are empty blocks in the current empty block cache
  • step 605 the master consensus node packs the empty block, encapsulates the empty block in a prepare package (Prepare package), and broadcasts it to all other consensus nodes;
  • Step 606 After receiving the preparation packet broadcast by the master consensus node, the auxiliary consensus node performs a first verification on the preparation packet, and if the verification is passed, it proceeds to step 607, otherwise it ends;
  • performing the first verification on the preparation package may specifically include: verifying whether the preparation package is generated by the master consensus node and whether it is a repeated package (that is, whether a repeated preparation package is received).
  • the first verification is passed, which may specifically include: the preparation package is generated by the master consensus node and is not a duplicate package.
  • Step 607 The auxiliary consensus node obtains the parent block hash value, packager index, empty block index value, and parent empty block hash value in the prepared package;
  • step 608 the secondary consensus node performs a second verification on the preparation packet, and if the verification is passed, it proceeds to step 609, otherwise it ends.
  • the second verification of the preparation package may specifically include: verifying whether the hash value of the parent block in the preparation package is the hash value of the highest block on the blockchain of the current node, and the block height in the preparation package Whether it is the block height of the highest block on the current node’s blockchain plus 1, whether the packager index in the prepared package is the packager index determined by the current node, and whether the empty block index value in the prepared package is the current node’s empty block
  • the index value of the latest empty block in the cache is increased by 1
  • the hash value of the parent empty block in the preparation package is the hash value of the latest empty block in the empty block cache of the current node.
  • the empty block in the preparation package is the first empty block in the empty block cache, only the verification of the packer index, the hash value of the parent block, the empty block index value, and the block height are performed.
  • the auxiliary consensus node determines that the package verification is passed, and then calculates the hash value of the empty block, and after signing the hash value, the hash value and the signature are encapsulated together to form a signature package (SignReq package), and broadcast To all other consensus nodes;
  • Step 610 the auxiliary consensus node collects the signature request.
  • Step 611 The auxiliary consensus node collects submission requests, and submits the empty block to the empty block cache.
  • the consensus node collects more than 2 ⁇ f+1 submission requests from different consensus nodes whose hash value is the hash value of the empty block
  • the empty block is submitted to the empty block cache. For example, it can insert a new entry in the empty block cache and update the latest empty block index value to B+1.
  • the secondary consensus node verifies the empty block index value, the parent empty block hash value, the block height, the parent block hash value, and the packager index in the received i-th block. Consensus verification when i blocks are empty. Furthermore, when a new non-empty block is stored on the blockchain, the empty block in the empty block cache will also be cleared, thereby reducing the storage space occupied by the empty block and improving disk utilization efficiency.
  • the blockchain system includes node 1 As with node 2, there are 10 empty blocks stored in node 1 and 5 empty blocks stored in node 2, so the data in the empty block caches of node 1 and node 2 are not synchronized. For another example, if there are 10 non-empty blocks stored in node 1 and 6 non-empty blocks are stored in node 2, the data in the blockchains of node 1 and node 2 are not synchronized. In this case, in order to ensure that the data in each node in the blockchain system is in the latest state, it is also necessary to perform synchronization operations on each node in the blockchain system.
  • the first node and the second node are set.
  • the first node is any one of the multiple nodes of the blockchain system
  • the second node is the first node among the multiple nodes of the blockchain system. Any one other than.
  • the data synchronization process between the first node and the second node can refer to the process shown in Fig. 7.
  • the execution subject in the process includes the first node and the second node, and the process includes:
  • Step 701 The second node periodically broadcasts the status information of its own node.
  • the status information includes the empty block index value of the latest empty block in the empty block cache of the second node and the block height of the highest block of the block chain of the second node.
  • the second node periodically broadcasts the status information of its own node, which is equivalent to the second node broadcasting the status information to all nodes in the blockchain system.
  • Each node will The status information of the second node determines whether data needs to be synchronized from the second node.
  • only the second node broadcasting status information to the first node is taken as an example for description.
  • Step 702 The first node receives the status information broadcast by the second node.
  • Step 703 If the first node determines that the block height of the highest block of the second node's blockchain is equal to the block height of the highest block of the first node's blockchain, and the empty block index of the latest empty block of the second node If the value is greater than the empty block index value of the latest empty block of the first node, the empty block to be synchronized is determined from the empty block cache of the second node.
  • the empty block to be synchronized refers to an empty block whose empty block index value in the empty block cache of the second node is greater than the empty block index value of the latest empty block of the first node.
  • the empty block cache of the second node stores 3 empty blocks
  • the empty block index values are 1, 2, and 3 respectively
  • the empty block cache of the first node stores 1 empty block
  • the empty block index value If it is 1, it can be determined that the empty block to be synchronized that the first node synchronizes from the second node is an empty block with an empty block index value of 2 and an empty block with an empty block index value of 3.
  • Step 704 The first node synchronizes the empty block to be synchronized into the empty block cache of the first node.
  • the first node will receive the status information broadcast by multiple nodes, that is, the first node can synchronize data to multiple nodes at the same time.
  • the first node can also perform repetitive verification according to the following steps when synchronizing data:
  • the first node obtains the parent empty block hash value and the empty block index value of the empty block to be synchronized, if it is determined that the parent empty block hash value of the empty block to be synchronized is equal to the empty block of the first node
  • the hash value of the latest empty block in the cache, and the empty block index value of the empty block to be synchronized is equal to the empty block index value of the latest empty block of the first node plus 1, then it is determined to synchronize the empty block to be synchronized to the empty block of the first node In the cache.
  • the consensus signature of the empty block to be synchronized can also be verified.
  • the first node may also verify the hash value of the parent block of the empty block to be synchronized when performing repeated verification, that is, the first node obtains the hash value of the parent block in the empty block to be synchronized , Determine whether the hash value of the parent block in the empty block to be synchronized is equal to the hash value of the highest block on the blockchain of the first node, and if so, further determine the hash value of the parent empty block and the index value of the empty block .
  • the premise of the above embodiment is that the block height of the highest block of the blockchain of the second node is equal to the block height of the highest block of the blockchain of the first node, that is, the first node only needs to synchronize the space from the second node. Piece.
  • the first node synchronizes non-empty blocks to the second node.
  • the step of synchronizing non-empty blocks is performed before the step of synchronizing empty blocks.
  • the first node determines that the block height of the highest block of the second node’s blockchain is greater than the block height of the highest block of the first node’s blockchain, then synchronize the second node’s blockchain to be higher than that of the first node Blocks of the blockchain, and the first node clears the empty block cache of the first node after the block is synchronized.
  • the first node receives the status information of the second node, and first determines whether the block height of the highest block of the second node's blockchain is greater than that of the highest block of the first node's blockchain. If the block is high, the first node first requests a non-empty block from the second node and clears the empty block cache. If the block height of the highest block of the blockchain of the second node is equal to the block height of the highest block of the blockchain of the first node, then it is determined whether the latest empty block index value of the empty block cache of the second node is greater than that of the first node. The latest empty block index value of the empty block cache of one node. If it is, the empty block is requested from the second node. At this time, the following four verifications are required:
  • the hash value of the parent empty block of the empty block to be synchronized is equal to the hash value of the latest empty block in the local empty block cache;
  • the empty block index value of the empty block to be synchronized is equal to the latest empty block index value in the local empty block cache plus 1;
  • the hash value of the parent block of the empty block to be synchronized is equal to the hash value of the highest block in the local blockchain
  • the blocks on the blockchain are not synchronized.
  • the first node determines that the latest empty block index value of the empty block cache of the second node is not greater than the latest empty block index value of the empty block cache of the first node, then the empty blocks in the empty block cache are not synchronized.
  • FIG. 10 exemplarily shows the structure of a block processing device provided by an embodiment of the present invention, and the device can execute the flow of the block processing method.
  • the device is suitable for a blockchain system including a master consensus node and an auxiliary consensus node.
  • the blockchain system includes a blockchain and an empty block cache, and any block in the blockchain is not an empty block,
  • the empty block cache is used to store empty blocks.
  • the device includes:
  • the determining unit 1001 is configured to determine the empty block index value of the latest empty block and the hash value of the latest empty block from the empty block cache when it is determined that the i-th block to be generated is an empty block; i, m is a positive integer, the empty block in the empty block cache is for the empty block generated after the mth block in the blockchain, and the empty block in the empty block cache is in the blockchain It is emptied when the m+1 th block is added; the empty block index value is used to indicate the generation sequence of each empty block in the empty block cache;
  • the generating unit 1002 is configured to generate the i-th block and broadcast the i-th block to each auxiliary consensus node; the i-th block includes the empty block index of the i-th block Value and the parent empty block hash value, the parent empty block hash value of the i-th block is the hash value of the latest empty block, and the empty block index value of the i-th block is based on the The empty block index value of the latest empty block is determined;
  • the storage unit 1003 is configured to store the i-th block in the empty block cache after determining that the i-th block passes the consensus verification.
  • the generating unit 1002 is specifically configured to: obtain the block height and hash value of the highest block on the blockchain, and determine the i-th block height after adding 1 to the block height of the highest block
  • the block height of the block, the hash value of the highest block is determined as the hash value of the parent block of the i-th block, the block height of the i-th block, the i-th block
  • the parent block hash value of the block, the empty block index value of the i-th block, and the parent empty block hash value of the i-th block are packed into the i-th block.
  • the generating unit 1002 is further configured to: obtain the block height and the block height of the highest block on the blockchain. Hope value, the block height of the highest block is added by 1 to determine the block height of the i-th block, and the hash value of the highest block is determined as the parent area of the i-th block.
  • the block hash value packs the block height of the i-th block and the parent block hash value of the i-th block into the i-th block.
  • the empty block cache includes the latest empty block index value
  • the latest empty block index value is the empty block index value of the latest empty block.
  • the determining unit 1001 is specifically configured to: determine the latest empty block from the empty block cache according to the latest empty block index value and obtain the empty block index value of the latest empty block and all State the hash value of the latest empty block.
  • the storage unit 1003 is further configured to: after storing the i-th block in the empty block cache, add 1 to the latest empty block index value.
  • FIG. 11 exemplarily shows the structure of a block consensus device provided by an embodiment of the present invention, which can execute the process of the block consensus method.
  • the device is suitable for a blockchain system including a master consensus node and an auxiliary consensus node.
  • the blockchain system includes a blockchain and an empty block cache, and any block in the blockchain is not an empty block,
  • the empty block cache is used to store empty blocks, the empty blocks in the empty block cache are for empty blocks generated after the mth block in the blockchain, and the empty blocks in the empty block cache are in all
  • the empty block includes an empty block index value and a parent empty block hash value, and the empty block index value is used to indicate each of the empty block caches
  • the sequence of empty blocks, m is a positive integer. As shown in Figure 11, the device includes:
  • the receiving unit 1101 is configured to receive the i-th block broadcast by the master consensus node; i is a positive integer;
  • the determining unit 1102 is configured to determine the empty block index value of the i-th block and the hash value of the parent empty block of the i-th block from the i-th block, and from the auxiliary consensus Determine the hash value of the first empty block and the empty block index value of the first empty block in the empty block cache of the node; the first empty block is the latest empty block in the empty block cache of the secondary consensus node;
  • the storage unit 1103 is configured to store the i-th block in the empty block cache of the auxiliary consensus node if it is determined that the i-th block passes the consensus verification; the i-th block passes the consensus Verify that the empty block index value of the i-th block and the empty block index value of the first empty block meet the preset requirements, and it is determined that the hash value of the parent empty block of the i-th block is equal to the The hash value of the first empty block.
  • the determining unit 1102 is further configured to determine the block height of the i-th block and the hash value of the parent block of the i-th block from the i-th block, from The block height of the highest block and the hash value of the highest block are determined in the blockchain of the auxiliary consensus node.
  • the i-th block passes the consensus verification, further comprising: the block height of the i-th block is equal to the block height of the highest block plus 1, and the parent area of the i-th block The block hash value is equal to the hash value of the highest block.
  • the determining unit 1102 is further configured to: determine from the i-th block that the empty block index value of the i-th block is a preset value, and the parent of the i-th block
  • the hash value of an empty block is a null value
  • the block height of the i-th block and the hash value of the parent block of the i-th block are determined from the i-th block
  • the auxiliary consensus Determine the block height of the highest block and the hash value of the highest block in the node’s blockchain, if it is determined that the block height of the i-th block is equal to the block height of the highest block plus 1, and so If the hash value of the parent block of the i-th block is equal to the hash value of the highest block, it is determined that the i-th block passes the consensus verification.
  • FIG. 12 exemplarily shows the structure of a block synchronization device provided by an embodiment of the present invention, and the device can execute the process of the block synchronization method.
  • the device is suitable for a blockchain system including multiple nodes.
  • the blockchain system includes a blockchain and an empty block cache.
  • any block in the blockchain is not an empty block, and the empty block
  • the cache is used to store empty blocks, the empty blocks in the empty block cache are for empty blocks generated after the mth block in the blockchain, and the empty blocks in the empty block cache are in the blockchain It is cleared when the m+1 th block is added to it, the multiple nodes include a first node and a second node, the first node is any one of the multiple nodes, and the second node is all For any one of the plurality of nodes except the first node, m is a positive integer.
  • the device includes:
  • the receiving unit 1201 is configured to receive status information broadcast by the second node; the status information includes the empty block index value of the latest empty block in the empty block cache of the second node and the blockchain of the second node The block height of the highest block;
  • the determining unit 1202 is configured to determine that the block height of the highest block of the blockchain of the second node is equal to the block height of the highest block of the blockchain of the first node and the latest free space of the second node If the empty block index value of the block is greater than the empty block index value of the latest empty block of the first node, the empty block to be synchronized is determined from the empty block cache of the second node; the empty block to be synchronized is the first An empty block whose empty block index value is greater than the empty block index value of the latest empty block of the first node in the empty block cache of the second node;
  • the synchronization unit 1203 is configured to synchronize the empty block to be synchronized to the empty block cache of the first node.
  • the synchronization unit 1203 is specifically configured to: for any empty block to be synchronized, obtain the parent empty block hash value and the empty block index value of the empty block to be synchronized, and if it is determined that the empty block to be synchronized is The hash value of the parent empty block is equal to the hash value of the latest empty block in the empty block cache of the first node, and the empty block index value of the empty block to be synchronized is equal to the empty block of the latest empty block of the first node When the index value is increased by 1, it is determined to synchronize the empty block to be synchronized to the empty block cache of the first node.
  • the empty block to be synchronized includes the hash value of the parent block.
  • the synchronization unit 1203 before determining to synchronize the empty block to be synchronized to the empty block cache of the first node, the synchronization unit 1203 is further configured to: determine the hash value of the parent block in the empty block to be synchronized Whether it is equal to the hash value of the highest block on the blockchain of the first node.
  • the status information further includes the block height of the blockchain of the second node.
  • the synchronization unit 1203 before determining the empty block to be synchronized from the empty block cache of the second node, is further configured to: if the block of the highest block of the blockchain of the second node is determined If the height is greater than the block height of the highest block of the blockchain of the first node, the block of the second node’s blockchain that is higher than the block of the first node’s blockchain will be synchronized in the first node’s blockchain. After the blocks of the node's blockchain are synchronized, the empty block cache of the first node is cleared.
  • an embodiment of the present invention also provides a computing device, including:
  • Memory used to store program instructions
  • the processor is configured to call the program instructions stored in the memory, and execute the block processing method, block consensus method, and block synchronization method described in any one of FIGS. 2 to 9 according to the obtained program.
  • embodiments of the present invention also provide a computer-readable non-volatile storage medium, including computer-readable instructions, when the computer reads and executes the computer-readable instructions, the computer executes To the block processing method, block consensus method, and block synchronization method described in any one of FIG. 9.
  • These computer program instructions can also be stored in a computer-readable memory that can guide a computer or other programmable data processing equipment to work in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture including the instruction device.
  • the device implements the functions specified in one process or multiple processes in the flowchart and/or one block or multiple blocks in the block diagram.
  • These computer program instructions can also be loaded on a computer or other programmable data processing equipment, so that a series of operation steps are executed on the computer or other programmable equipment to produce computer-implemented processing, so as to execute on the computer or other programmable equipment.
  • the instructions provide steps for implementing functions specified in a flow or multiple flows in the flowchart and/or a block or multiple blocks in the block diagram.

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computer Security & Cryptography (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Memory System Of A Hierarchy Structure (AREA)

Abstract

A block processing method and device, a block consensus method and device and a block synchronization method and device. The present invention is applicable to a blockchain system comprising a main consensus node and an auxiliary consensus node. The blockchain system comprises a blockchain and an empty block cache, wherein any block in the blockchain is not an empty block; the empty block cache is used for storing empty blocks, wherein the empty block in the empty block cache is an empty block generated after the mth block in the blockchain and is emptied when the (m+1)th block is added to the blockchain. The block processing method comprises: when determining that an ith block to be generated is an empty block, a main consensus node determining an empty block index value and a hash value of the latest empty block from an empty block cache, generating the ith block and broadcasting the ith block to each auxiliary consensus node, and storing the ith block in the empty block cache after it is determined that the ith block passes consensus verification. The technical solution can solve the problem that an empty block occupies a great deal of disk storage space in a node and improve the utilization of the disk in the node.

Description

一种区块处理、区块共识和区块同步方法及装置Method and device for block processing, block consensus and block synchronization
相关申请的交叉引用Cross references to related applications
本申请要求在2019年08月12日提交中国专利局、申请号为201910741064.X、申请名称为“一种区块处理、区块共识和区块同步方法及装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application requires the priority of a Chinese patent application filed with the Chinese Patent Office, the application number is 201910741064.X, and the application name is "a block processing, block consensus and block synchronization method and device" on August 12, 2019 , Its entire content is incorporated in this application by reference.
技术领域Technical field
本发明涉及金融科技(Fintech)领域,尤其涉及一种区块处理、区块共识和区块同步方法及装置。The present invention relates to the field of financial technology (Fintech), in particular to a block processing, block consensus and block synchronization method and device.
背景技术Background technique
随着计算机技术的发展,越来越多的技术(例如:区块链、云计算或大数据)应用在金融领域,传统金融业正在逐步向金融科技转变,区块链技术也不例外。但由于金融、支付行业的安全性、实时性要求,金融科技也对区块链技术提出了更高的要求。With the development of computer technology, more and more technologies (for example: blockchain, cloud computing or big data) are applied in the financial field. The traditional financial industry is gradually transforming to financial technology, and blockchain technology is no exception. However, due to the security and real-time requirements of the finance and payment industries, financial technology also puts forward higher requirements on blockchain technology.
在区块链系统中,为了保证定时出块,基于工作证明(proof of work,POW)和股权证明(proof of stake,POS)共识算法的区块链系统,例如比特币、以太坊等,均对空块进行共识后存储至区块链中。而为了保障区块链系统的正常运行,防止区块链系统中的节点作恶,基于实用拜占庭容错(practical byzantine fault tolerance,PBFT)共识算法的区块链系统(如Algorand)则会在没有交易的情况下产生空块,并对产生的空块进行共识验证,且在验证通过后存储至区块链中。In the blockchain system, in order to ensure the timing of block generation, blockchain systems based on the consensus algorithm of proof of work (POW) and proof of stake (POS), such as Bitcoin, Ethereum, etc. The empty blocks are agreed and stored in the blockchain. In order to ensure the normal operation of the blockchain system and prevent the nodes in the blockchain system from doing evil, the blockchain system (such as Algorand) based on the practical byzantine fault tolerance (PBFT) consensus algorithm will be used when there is no transaction. In this case, empty blocks are generated, and the generated empty blocks are verified by consensus, and stored in the blockchain after the verification is passed.
然而,上述方式均需要区块链系统将空块存储至区块链上,而空块会占用节点中大量的磁盘存储空间,降低节点中磁盘的利用率,进而影响到节点中可存储交易的数量。However, the above methods all require the blockchain system to store empty blocks on the blockchain, and empty blocks will occupy a large amount of disk storage space in the node, reduce the utilization of the disk in the node, and then affect the storage of transactions in the node. Quantity.
发明内容Summary of the invention
本发明提供一种区块处理、区块共识和区块同步方法及装置,用以解决现有技术将空块存储在区块链上导致空块占用节点中磁盘存储空间的问题,提高节点中磁盘的利用率。The present invention provides a block processing, block consensus, and block synchronization method and device, which are used to solve the problem that the storage of empty blocks on the blockchain in the prior art causes the empty blocks to occupy the disk storage space in the node, thereby improving the Disk utilization.
第一方面,本发明提供一种区块处理方法,该区块处理方法适用于包括主共识节点和辅共识节点的区块链系统,所述区块链系统包括区块链和空块缓存,所述区块链中的任一区块均不是空块,所述空块缓存用于存储空块。该区块处理方法包括:In the first aspect, the present invention provides a block processing method, which is suitable for a blockchain system including a main consensus node and an auxiliary consensus node, and the blockchain system includes a blockchain and an empty block cache, Any block in the blockchain is not an empty block, and the empty block cache is used to store empty blocks. The block processing method includes:
所述主共识节点在确定待生成的第i个区块为空块时,先从所述空块缓存中确定最新空块的空块索引值和所述最新空块的哈希值,再生成所述第i个区块并将所述第i个区块广播至各辅共识节点,以对所述第i个区块进行共识验证,若确定所述第i个区块通过共识验证,则将所述第i个区块存储至所述空块缓存中。When determining that the i-th block to be generated is an empty block, the master consensus node first determines the empty block index value of the latest empty block and the hash value of the latest empty block from the empty block cache, and then generates The i-th block and the i-th block are broadcast to each auxiliary consensus node to perform consensus verification on the i-th block. If it is determined that the i-th block passes the consensus verification, then Store the i-th block in the empty block cache.
其中,i、m为正整数。所述空块缓存中的空块是针对所述区块链中第m个区块之后生成的空块,且所述空块缓存中的空块在所述区块链中增加第m+1个区块时被清空。所述空块索引值用于指示所述空块缓存中各空块产生的先后顺序,所述第i个区块中包括所述第i个区块的空块索引值和父空块哈希值,所述第i个区块的父空块哈希值是所述最新空块的哈希值,所述第i个区块的空块索引值是根据所述最新空块的空块索引值确定的。Among them, i and m are positive integers. The empty block in the empty block cache is for the empty block generated after the mth block in the blockchain, and the empty block in the empty block cache is increased by the m+1th block in the blockchain When the block is cleared. The empty block index value is used to indicate the order in which each empty block in the empty block cache is generated, and the i-th block includes the empty block index value and the parent empty block hash of the i-th block Value, the hash value of the parent empty block of the i-th block is the hash value of the latest empty block, and the empty block index value of the i-th block is based on the empty block index of the latest empty block The value is determined.
上述技术方案中,区块链系统包括区块链和空块缓存,区块链用于对账本数据进行永久性存储,空块缓存用于对的空块进行暂时性存储,当区块链中有新的区块生成并存储至区块链上时,则当前空块缓存中的空块则会被清空,以节省节点中的磁盘存储空间,提高磁盘的利用率。而且,在生成空块时,通过将空块的空块索引值和父空块哈希值同时打包至空块,有利于各共识节点根据空块的空块索引值和父空块哈希值,结合本地的空块缓存对空块进行共识验证,从而有助于保障区块链系统的稳定性和安全性。由此可知,本技术方案在保障区块链系统安全性的前提下,还能提高各节点中磁盘的利用率,有助于使各节点可存储更多的账本数据。In the above technical scheme, the blockchain system includes a blockchain and an empty block cache. The blockchain is used for permanent storage of ledger data, and the empty block cache is used for temporary storage of empty blocks. When a new block is generated and stored on the blockchain, the empty block in the current empty block cache will be emptied to save disk storage space in the node and improve disk utilization. Moreover, when the empty block is generated, the empty block index value and the parent empty block hash value of the empty block are packaged into the empty block at the same time, which is beneficial to each consensus node according to the empty block index value and the parent empty block hash value. , Combined with the local empty block cache to perform consensus verification on empty blocks, which helps to ensure the stability and security of the blockchain system. It can be seen that, under the premise of ensuring the security of the blockchain system, the technical solution can also increase the utilization rate of the disk in each node, which helps to enable each node to store more ledger data.
在一种可选地技术方案中,所述主共识节点生成所述第i个区块,包括:所述主共识节点先获取所述区块链上最高区块的块高和哈希值,然后将所述最高区块的块高加1后确定为所述第i个区块的块高,将所述最高区块的哈希值确定为所述第i个区块的父区块哈希值,最后将所述第i个区块的块高、所述第i个区块的父区块哈希值、所述第i个区块的空块索引值和所述第i个区块的父空块哈希值打包至所述第i个区块。In an optional technical solution, generating the i-th block by the master consensus node includes: the master consensus node first obtains the block height and hash value of the highest block on the blockchain, Then add 1 to the block height of the highest block to determine the block height of the i-th block, and determine the hash value of the highest block as the parent block of the i-th block. Hope value, and finally the block height of the i-th block, the hash value of the parent block of the i-th block, the empty block index value of the i-th block and the i-th zone The hash value of the parent empty block of the block is packed into the i-th block.
上述技术方案中,主共识节点在生成空块时,还会根据当前区块链中最高区块的块高和哈希值确定当前待生成空块的块高和父区块哈希值,如此,各共识节点能够根据该空块的块高和父区块哈希值,结合本地存储的区块链对该空块进行共识验证,从而可以进一步保障区块链系统的稳定性和安全性。In the above technical solution, when the master consensus node generates an empty block, it also determines the block height and the hash value of the parent block of the current empty block to be generated according to the block height and hash value of the highest block in the current blockchain. , Each consensus node can perform consensus verification on the empty block based on the block height of the empty block and the hash value of the parent block, combined with the locally stored blockchain, so as to further ensure the stability and security of the blockchain system.
在一种可选地技术方案中,所述主共识节点若确定所述待生成的第i个区块不是空块,则可以获取所述区块链上最高区块的块高和哈希值,将所述最高区块的块高加1后确定为所述第i个区块的块高,将所述最高区块的哈希值确定为所述第i个区块的父区块哈希值,进而将所述第i个区块的块高、所述第i个区块的父区块哈希值打包至所述第i个区块。In an optional technical solution, if the master consensus node determines that the i-th block to be generated is not an empty block, it can obtain the block height and hash value of the highest block on the blockchain , The block height of the highest block is increased by 1 to determine the block height of the i-th block, and the hash value of the highest block is determined as the parent block of the i-th block. Hope value, and then pack the block height of the i-th block and the hash value of the parent block of the i-th block into the i-th block.
上述技术方案中,主共识节点在生成非空块时,同样会根据当前区块链中最高区块的块高和哈希值确定当前待生成的非空块的块高和父区块哈希值,如此,各共识节点还能够根据该非空块的块高和父区块哈希值,结合本地存储的区块链对该非空块进行共识验证。更进一步的,在将该非空块存储至区块链上时,还可以清空当前空块缓存中的所有空块,以进一步降低节点中磁盘的占用率。In the above technical solution, when the master consensus node generates a non-empty block, it will also determine the block height and parent block hash of the current non-empty block to be generated according to the block height and hash value of the highest block in the current blockchain In this way, each consensus node can also perform consensus verification on the non-empty block based on the block height of the non-empty block and the hash value of the parent block in combination with the locally stored blockchain. Furthermore, when storing the non-empty block on the blockchain, all empty blocks in the current empty block cache can be cleared to further reduce the disk occupancy rate in the node.
在一种可选地技术方案中,所述空块缓存中包括最新空块索引值,所述最新空块索引值为所述最新空块的空块索引值。这种情况下,所述主共识节点从所述空块缓存中确定最新空块的空块索引值和所述最新空块的哈希值,包括:所述主共识节点根据所述最新空块索引值,从所述空块缓存中确定所述最新空块,并获取所述最新空块的空块索引值和所述最新空块的哈希值。对应的,所述主共识节点在将所述第i个区块存储至所述空块缓存中之后,还可以将所述最新空块索引值加1。In an optional technical solution, the empty block cache includes the latest empty block index value, and the latest empty block index value is the empty block index value of the latest empty block. In this case, determining the empty block index value of the latest empty block and the hash value of the latest empty block by the master consensus node from the empty block cache includes: the master consensus node according to the latest empty block Index value, determining the latest empty block from the empty block cache, and obtaining the empty block index value of the latest empty block and the hash value of the latest empty block. Correspondingly, after storing the i-th block in the empty block cache, the master consensus node may also add 1 to the latest empty block index value.
上述技术方案中,通过在空块缓存中设置最新空块索引值(即当前空块缓存中最新空块的空块索引值),使得主共识节点在生成空块时,还能根据该最新空块索引值从空块缓存中确定出最新空块的空块索引值和哈希值。该技术方案无需主共识节点从空块缓存中查找最新空块,而是可以直接根据最新空块索引值来确定最新空块,从而能够提高主共识节点生成空块的效率。In the above technical solution, by setting the latest empty block index value in the empty block cache (that is, the empty block index value of the latest empty block in the current empty block cache), the master consensus node can also generate an empty block according to the latest empty block index. The block index value determines the empty block index value and hash value of the latest empty block from the empty block cache. This technical solution does not require the master consensus node to find the latest empty block from the empty block cache, but can directly determine the latest empty block according to the index value of the latest empty block, thereby improving the efficiency of the master consensus node generating empty blocks.
第二方面,本发明提供一种区块共识方法,该区块共识方法适用于包括主共识节点和辅共识节点的区块链系统,所述区块链系统包括区块链和空块缓存,所述区块链中任一区块均不是空块,所述空块缓存用于存储空块。其中,所述空块缓存中的空块是针对所述区 块链中第m个区块之后生成的空块且所述空块缓存中的空块在所述区块链中增加第m+1个区块时被清空,m为正整数,所述空块包括空块索引值和父空块哈希值,所述空块索引值用于指示所述空块缓存中各空块产生的先后。该区块共识方法包括:In a second aspect, the present invention provides a block consensus method, which is applicable to a blockchain system including a main consensus node and an auxiliary consensus node, and the blockchain system includes a blockchain and an empty block cache, Any block in the blockchain is not an empty block, and the empty block cache is used to store empty blocks. Wherein, the empty block in the empty block cache is for the empty block generated after the mth block in the blockchain, and the empty block in the empty block cache is increased by the m+th block in the blockchain. 1 block is cleared, m is a positive integer, the empty block includes the empty block index value and the parent empty block hash value, the empty block index value is used to indicate the empty block in the empty block cache Successively. The block consensus method includes:
所述辅共识节点接收所述主共识节点广播的第i个区块后,从所述第i个区块中确定所述第i个区块的空块索引值和所述第i个区块的父空块哈希值,从所述辅共识节点的空块缓存中确定第一空块的哈希值和所述第一空块的空块索引值,然后对第i个区块进行共识验证,若确定所述第i个区块通过共识验证,则将所述第i个区块存储至所述辅共识节点的空块缓存中。其中,i为正整数,所述第一空块是所述辅共识节点的空块缓存中的最新空块,所述第i个区块通过共识验证包括:所述第i个区块的空块索引值与所述第一空块的空块索引值符合预设要求,且所述第i个区块的父空块哈希值等于所述第一空块的哈希值。After the secondary consensus node receives the i-th block broadcast by the main consensus node, it determines the empty block index value of the i-th block and the i-th block from the i-th block Determine the hash value of the first empty block and the empty block index value of the first empty block from the empty block cache of the auxiliary consensus node, and then perform consensus on the i-th block Verification: If it is determined that the i-th block passes the consensus verification, the i-th block is stored in the empty block cache of the auxiliary consensus node. Wherein, i is a positive integer, the first empty block is the latest empty block in the empty block cache of the auxiliary consensus node, and the i-th block passing consensus verification includes: the empty block of the i-th block The block index value and the empty block index value of the first empty block meet a preset requirement, and the hash value of the parent empty block of the i-th block is equal to the hash value of the first empty block.
上述技术方案中,区块链系统包括区块链和空块缓存,区块链用于对账本数据进行永久性存储,空块缓存用于对的空块进行暂时性存储,当区块链中有新的区块生成并存储至区块链上时,当前空块缓存中的空块会被清空,从而有助于节省节点中的磁盘存储空间,提高磁盘的利用率。而且,辅共识节点在接收到第i个区块后,通过从该第i个区块中确定第i个区块的空块索引值和父空块哈希值,并结合本地的空块缓存中的最新空块的空块索引值和哈希值对第i个区块进行共识验证,能够保障区块链系统的稳定性和安全性。In the above technical scheme, the blockchain system includes a blockchain and an empty block cache. The blockchain is used for permanent storage of ledger data, and the empty block cache is used for temporary storage of empty blocks. When a new block is generated and stored on the blockchain, the empty block in the current empty block cache will be cleared, which helps to save the disk storage space in the node and improve the utilization of the disk. Moreover, after receiving the i-th block, the secondary consensus node determines the empty block index value and parent empty block hash value of the i-th block from the i-th block, and combines the local empty block cache The empty block index value and hash value of the latest empty block in, perform consensus verification on the i-th block, which can ensure the stability and security of the blockchain system.
在一种可选地技术方案中,所述辅共识节点还可以从所述第i个区块中确定所述第i个区块的块高和所述第i个区块的父区块哈希值,从所述辅共识节点的区块链中确定最高区块的块高和所述最高区块的哈希值,若所述第i个区块的块高等于所述最高区块的块高加1,且所述第i个区块的父区块哈希值等于所述最高区块的哈希值,则所述第i个区块通过共识验证。In an optional technical solution, the auxiliary consensus node may also determine the block height of the i-th block and the parent block of the i-th block from the i-th block. Hope value, determine the block height of the highest block and the hash value of the highest block from the blockchain of the secondary consensus node, if the block height of the i-th block is equal to the highest block’s If the block height is increased by 1, and the hash value of the parent block of the i-th block is equal to the hash value of the highest block, the i-th block passes the consensus verification.
上述技术方案中,通过辅共识节点获取第i个区块的块高和父区块哈希值,并根据第i个区块的块高和父区块哈希值,结合本地区块链中的最高区块的块高和哈希值,对第i个区块进行共识验证,能够进一步保障区块链系统的稳定性和安全性。In the above technical solution, the block height of the i-th block and the hash value of the parent block are obtained through the auxiliary consensus node, and the block height of the i-th block and the hash value of the parent block are combined with the local blockchain. The block height and hash value of the highest block of, and the consensus verification of the i-th block can further ensure the stability and security of the blockchain system.
在一种可选地技术方案中,当所述辅共识节点从所述第i个区块中确定所述第i个区块的空块索引值为预设值,且所述第i个区块的父空块哈希值为空值,则所述辅共识节点从所述第i个区块中确定所述第i个区块的块高和所述第i个区块的父区块哈希值,从所述辅共识节点的区块链中确定最高区块的块高和所述最高区块的哈希值,若确定所述第i个区块的块高等于所述最高区块的块高加1,且所述第i个区块的父区块哈希值等于所述最高区块的哈希值,则确定所述第i个区块通过所述共识验证,并将所述第i个区块存储至所述辅共识节点的空块缓存中。In an optional technical solution, when the secondary consensus node determines from the i-th block that the empty block index value of the i-th block is a preset value, and the i-th zone If the hash value of the parent empty block of the block is a null value, the secondary consensus node determines the block height of the i-th block and the parent block of the i-th block from the i-th block Hash value, determine the block height of the highest block and the hash value of the highest block from the blockchain of the secondary consensus node, if it is determined that the block height of the i-th block is equal to the highest zone If the block height is increased by 1, and the hash value of the parent block of the i-th block is equal to the hash value of the highest block, it is determined that the i-th block passes the consensus verification, and The i-th block is stored in the empty block cache of the auxiliary consensus node.
上述技术方案中,当辅共识节点确定第i个区块中的空块索引值为预设值,且父区块哈希值为空,则可以确定该第i个区块为空块缓存中的第一个空块。通过辅共识节点对空块缓存中的第一个空块进行共识验证,能够验证第一个空块的块高和父区块哈希值,有助于保障区块链系统的稳定性和安全性。In the above technical solution, when the secondary consensus node determines that the index value of the empty block in the i-th block is a preset value, and the hash value of the parent block is empty, it can be determined that the i-th block is an empty block in the cache The first empty block. The auxiliary consensus node performs consensus verification on the first empty block in the empty block cache, which can verify the block height of the first empty block and the hash value of the parent block, which helps to ensure the stability and security of the blockchain system Sex.
第三方面,本发明提供一种区块同步方法,该区块同步方法适用于包括多个节点的区块链系统,所述区块链系统包括区块链和空块缓存,所述区块链中任一区块均不是空块,所述空块缓存用于存储空块。其中,所述空块缓存中的空块是针对所述区块链中第m个区块之后生成的空块且所述空块缓存中的空块在所述区块链中增加第m+1个区块时被清空,m为正整数,所述多个节点包括第一节点和第二节点,所述第一节点是所述多个节点中的 任一个,所述第二节点是所述多个节点中除所述第一节点之外的任一个。该区块同步方法包括:In a third aspect, the present invention provides a block synchronization method, which is suitable for a block chain system including multiple nodes. The block chain system includes a block chain and an empty block cache. Any block in the chain is not an empty block, and the empty block cache is used to store empty blocks. Wherein, the empty block in the empty block cache is for the empty block generated after the mth block in the blockchain, and the empty block in the empty block cache is increased by the m+th block in the blockchain. 1 block is cleared, m is a positive integer, the multiple nodes include a first node and a second node, the first node is any one of the multiple nodes, and the second node is all Any one of the plurality of nodes except the first node. The block synchronization method includes:
所述第一节点接收所述第二节点广播的状态信息,从所述状态信息中获取所述第二节点的空块缓存中最新空块的空块索引值和所述第二节点的区块链的最高区块的块高,若确定所述第二节点的区块链的最高区块的块高等于所述第一节点的区块链的最高区块的块高,且所述第二节点的最新空块的空块索引值大于所述第一节点的最新空块的空块索引值,则从所述第二节点的空块缓存中确定待同步空块,并将所述待同步空块同步至所述第一节点的空块缓存中。其中,所述待同步空块是所述第二节点的空块缓存中空块索引值大于所述第一节点的最新空块的空块索引值的空块。The first node receives the state information broadcast by the second node, and obtains the empty block index value of the latest empty block in the empty block cache of the second node and the block of the second node from the state information The block height of the highest block of the chain, if it is determined that the block height of the highest block of the second node’s blockchain is equal to the block height of the highest block of the first node’s blockchain, and the second If the empty block index value of the latest empty block of the node is greater than the empty block index value of the latest empty block of the first node, the empty block to be synchronized is determined from the empty block cache of the second node, and the to-be-synchronized empty block is determined The empty block is synchronized to the empty block cache of the first node. The empty block to be synchronized is an empty block whose empty block index value in the empty block cache of the second node is greater than the empty block index value of the latest empty block of the first node.
上述技术方案中,考虑到如果区块链系统中各节点的性能不一,则可能存在区块链系统中节点的区块链或空块缓存中数据不同步的情况,因此若第一节点和第二节点的区块链中的数据同步,而空块缓存中的数据不同步,则第一节点可以从第二节点中获取待同步空块,以保证区块链系统中所有节点都处于最新状态。In the above technical solution, considering that if the performance of each node in the blockchain system is different, there may be cases in which the data in the blockchain or empty block cache of the nodes in the blockchain system is not synchronized. Therefore, if the first node and the The data in the blockchain of the second node is synchronized, and the data in the empty block cache is not synchronized, the first node can obtain the empty block to be synchronized from the second node to ensure that all nodes in the blockchain system are up to date status.
在一种可选地技术方案中,所述第一节点将所述待同步空块同步至所述第一节点的空块缓存中,包括:所述第一节点针对任一个待同步空块,获取所述待同步空块的父空块哈希值和空块索引值,若确定所述待同步空块的父空块哈希值等于所述第一节点的空块缓存中最新空块的哈希值,且所述待同步空块的空块索引值等于所述第一节点的最新空块的空块索引值加1,则确定同步所述待同步空块至所述第一节点的空块缓存中。In an optional technical solution, the first node synchronizing the empty block to be synchronized to the empty block cache of the first node includes: the first node targets any empty block to be synchronized, Obtain the parent empty block hash value and the empty block index value of the empty block to be synchronized, if it is determined that the parent empty block hash value of the empty block to be synchronized is equal to the latest empty block in the empty block cache of the first node Hash value, and the empty block index value of the empty block to be synchronized is equal to the empty block index value of the latest empty block of the first node plus 1, then it is determined to synchronize the empty block to be synchronized to the first node The empty block is in the cache.
在一种可选地技术方案中,所述待同步空块中包括父区块哈希值,这种情况下,所述第一节点确定同步所述待同步空块至所述第一节点的空块缓存中之前,还可以确定所述待同步空块中父区块哈希值是否等于所述第一节点的区块链上的最高区块的哈希值。In an optional technical solution, the empty block to be synchronized includes the hash value of the parent block. In this case, the first node determines to synchronize the empty block to be synchronized to the first node Before the empty block is cached, it can also be determined whether the hash value of the parent block in the empty block to be synchronized is equal to the hash value of the highest block on the blockchain of the first node.
上述技术方案中,考虑到第一节点会接收到多个节点广播的状态信息,也即第一节点可以同时向多个节点同步数据,为了避免第一节点向多个节点同步重复的数据,因此在第一节点同步数据时,可以先对待同步空块进行重复性验证,以使第一节点尽量不同步已经同步过的数据。In the above technical solution, considering that the first node will receive the state information broadcast by multiple nodes, that is, the first node can synchronize data to multiple nodes at the same time. In order to avoid the first node from synchronizing repeated data to multiple nodes, When the first node synchronizes data, it can first perform repetitive verification on empty blocks to be synchronized, so that the first node does not synchronize data that has already been synchronized as much as possible.
在一种可选地技术方案中,所述状态信息还包括所述第二节点的区块链的块高,在这种情况下,所述第一节点在从所述第二节点的空块缓存确定待同步空块之前,若确定所述第二节点的区块链的最高区块的块高大于所述第一节点的区块链的最高区块的块高,则同步所述第二节点的区块链中高于所述第一节点的区块链的区块,在所述第一节点的区块链的区块同步后,清空所述第一节点的空块缓存。In an optional technical solution, the state information further includes the block height of the block chain of the second node. In this case, the first node is in the empty block from the second node. Before the cache determines the empty block to be synchronized, if it is determined that the block height of the highest block of the blockchain of the second node is greater than the block height of the highest block of the blockchain of the first node, synchronize the second After the blocks of the block chain of the node that are higher than the block chain of the first node are synchronized, the empty block cache of the first node is cleared.
上述技术方案中,第一节点先根据本地区块链的最高区块的块高与第二节点的区块链的最高区块的块高从第二节点中同步区块链上的非空块,并在同步到非空块后,将本地空块缓存中的空块清除。采用先同步非空块再同步空块的方案,可以通过最少的同步次数实现第一节点中数据的同步。In the above technical solution, the first node first synchronizes the non-empty blocks on the blockchain from the second node according to the block height of the highest block of the local blockchain and the block height of the highest block of the second node’s blockchain. , And after synchronizing to a non-empty block, clear the empty block in the local empty block cache. By adopting the scheme of synchronizing the non-empty blocks first and then synchronizing the empty blocks, the data synchronization in the first node can be realized with the least number of synchronizations.
第四方面,本发明提供一种区块处理装置,适用于包括主共识节点和辅共识节点的区块链系统,所述区块链系统包括区块链和空块缓存,所述区块链中任一区块均不是空块,所述空块缓存用于存储空块。所述装置包括:In a fourth aspect, the present invention provides a block processing device suitable for a block chain system including a main consensus node and an auxiliary consensus node. The block chain system includes a block chain and an empty block cache. The block chain None of the blocks is an empty block, and the empty block cache is used to store empty blocks. The device includes:
确定单元,用于在确定待生成的第i个区块为空块时,从所述空块缓存中确定最新空块的空块索引值和所述最新空块的哈希值;其中,i、m为正整数;所述空块缓存中的空块是针对所述区块链中第m个区块之后生成的空块且所述空块缓存中的空块在所述区块链中增 加第m+1个区块时被清空,所述空块索引值用于指示所述空块缓存中各空块产生的先后顺序;The determining unit is configured to determine the empty block index value of the latest empty block and the hash value of the latest empty block from the empty block cache when it is determined that the i-th block to be generated is an empty block; where i , M is a positive integer; the empty block in the empty block cache is for the empty block generated after the mth block in the blockchain, and the empty block in the empty block cache is in the blockchain It is emptied when the m+1 th block is added, and the empty block index value is used to indicate the sequence in which the empty blocks in the empty block cache are generated;
生成单元,用于生成所述第i个区块,并将所述第i个区块广播至各辅共识节点;所述第i个区块中包括所述第i个区块的空块索引值和父空块哈希值,所述第i个区块的父空块哈希值是所述最新空块的哈希值,所述第i个区块的空块索引值是根据所述最新空块的空块索引值确定的;A generating unit, configured to generate the i-th block and broadcast the i-th block to each auxiliary consensus node; the i-th block includes the empty block index of the i-th block Value and the parent empty block hash value, the parent empty block hash value of the i-th block is the hash value of the latest empty block, and the empty block index value of the i-th block is based on the The empty block index value of the latest empty block is determined;
存储单元,用于在确定所述第i个区块通过共识验证后,将所述第i个区块存储至所述空块缓存中。The storage unit is configured to store the i-th block in the empty block cache after determining that the i-th block passes the consensus verification.
在一种可选地技术方案中,所述生成单元具体用于:获取所述区块链上最高区块的块高和哈希值,将所述最高区块的块高加1后确定为所述第i个区块的块高,将所述最高区块的哈希值确定为所述第i个区块的父区块哈希值,将所述第i个区块的块高、所述第i个区块的父区块哈希值、所述第i个区块的空块索引值和所述第i个区块的父空块哈希值打包至所述第i个区块。In an optional technical solution, the generating unit is specifically configured to: obtain the block height and hash value of the highest block on the blockchain, and determine that the block height of the highest block is increased by 1 The block height of the i-th block, the hash value of the highest block is determined as the parent block hash value of the i-th block, and the block height of the i-th block The hash value of the parent block of the i-th block, the empty block index value of the i-th block and the hash value of the parent empty block of the i-th block are packed into the i-th zone Piece.
在一种可选地技术方案中,所述生成单元还用于:当所述确定单元确定所述待生成的第i个区块不是空块,则获取所述区块链上最高区块的块高和哈希值,将所述最高区块的块高加1后确定为所述第i个区块的块高,将所述最高区块的哈希值确定为所述第i个区块的父区块哈希值,将所述第i个区块的块高、所述第i个区块的父区块哈希值打包至所述第i个区块。In an optional technical solution, the generating unit is further configured to: when the determining unit determines that the i-th block to be generated is not an empty block, obtain the value of the highest block on the blockchain Block height and hash value, the block height of the highest block plus 1 is determined as the block height of the i-th block, and the hash value of the highest block is determined as the i-th zone The hash value of the parent block of the block, the block height of the i-th block and the hash value of the parent block of the i-th block are packed into the i-th block.
在一种可选地技术方案中,所述空块缓存中包括最新空块索引值,所述最新空块索引值为所述最新空块的空块索引值。所述确定单元具体用于:根据所述最新空块索引值,从所述空块缓存中确定所述最新空块并获取所述最新空块的空块索引值和所述最新空块的哈希值。对应的,所述存储单元还用于:在将所述第i个区块存储至所述空块缓存中之后,将所述最新空块索引值加1。In an optional technical solution, the empty block cache includes the latest empty block index value, and the latest empty block index value is the empty block index value of the latest empty block. The determining unit is specifically configured to: determine the latest empty block from the empty block cache according to the latest empty block index value and obtain the empty block index value of the latest empty block and the hash value of the latest empty block. Hope value. Correspondingly, the storage unit is further configured to: after storing the i-th block in the empty block cache, add 1 to the latest empty block index value.
第五方面,本发明提供一种区块共识装置,适用于包括主共识节点和辅共识节点的区块链系统,所述区块链系统包括区块链和空块缓存,所述区块链中任一区块均不是空块,所述空块缓存用于存储空块。其中,所述空块缓存中的空块是针对所述区块链中第m个区块之后生成的空块且所述空块缓存中的空块在所述区块链中增加第m+1个区块时被清空,m为正整数,所述空块包括空块索引值和父空块哈希值,所述空块索引值用于指示所述空块缓存中各空块产生的先后顺序。所述装置包括:In a fifth aspect, the present invention provides a block consensus device, which is suitable for a block chain system including a main consensus node and an auxiliary consensus node. The block chain system includes a block chain and an empty block cache. The block chain None of the blocks is an empty block, and the empty block cache is used to store empty blocks. Wherein, the empty block in the empty block cache is for the empty block generated after the mth block in the blockchain, and the empty block in the empty block cache is increased by the m+th block in the blockchain. 1 block is cleared, m is a positive integer, the empty block includes the empty block index value and the parent empty block hash value, the empty block index value is used to indicate the empty block in the empty block cache Priority. The device includes:
接收单元,用于接收所述主共识节点广播的第i个区块;i为正整数;A receiving unit for receiving the i-th block broadcast by the master consensus node; i is a positive integer;
确定单元,用于从所述第i个区块中确定所述第i个区块的空块索引值和所述第i个区块的父空块哈希值,以及从所述辅共识节点的空块缓存中确定第一空块的哈希值和所述第一空块的空块索引值;所述第一空块是所述辅共识节点的空块缓存中的最新空块;The determining unit is configured to determine the empty block index value of the i-th block and the hash value of the parent empty block of the i-th block from the i-th block, and from the auxiliary consensus node Determining the hash value of the first empty block and the empty block index value of the first empty block in the empty block cache; the first empty block is the latest empty block in the empty block cache of the secondary consensus node;
存储单元,用于若确定所述第i个区块通过共识验证,则将所述第i个区块存储至所述辅共识节点的空块缓存中;所述第i个区块通过共识验证包括所述第i个区块的空块索引值与所述第一空块的空块索引值符合预设要求,且确定所述第i个区块的父空块哈希值等于所述第一空块的哈希值。A storage unit, configured to store the i-th block in the empty block cache of the auxiliary consensus node if it is determined that the i-th block passes the consensus verification; the i-th block passes the consensus verification Including the empty block index value of the i-th block and the empty block index value of the first empty block meet the preset requirements, and it is determined that the hash value of the parent empty block of the i-th block is equal to the The hash value of an empty block.
在一种可选地技术方案中,所述确定单元还用于:从所述第i个区块中确定所述第i个区块的块高和所述第i个区块的父区块哈希值,从所述辅共识节点的区块链中确定最高区块的块高和所述最高区块的哈希值。对应的,所述第i个区块通过共识验证,还包括:所述第 i个区块的块高等于所述最高区块的块高加1,且所述第i个区块的父区块哈希值等于所述最高区块的哈希值。In an optional technical solution, the determining unit is further configured to: determine the block height of the i-th block and the parent block of the i-th block from the i-th block The hash value determines the block height of the highest block and the hash value of the highest block from the blockchain of the auxiliary consensus node. Correspondingly, the i-th block passes the consensus verification, further comprising: the block height of the i-th block is equal to the block height of the highest block plus 1, and the parent area of the i-th block The block hash value is equal to the hash value of the highest block.
在一种可选地技术方案中,所述确定单元还用于:从所述第i个区块中确定所述第i个区块的空块索引值为预设值,且所述第i个区块的父空块哈希值为空值,从所述第i个区块中确定所述第i个区块的块高和所述第i个区块的父区块哈希值,从所述辅共识节点的区块链中确定最高区块的块高和所述最高区块的哈希值,若确定所述第i个区块的块高等于所述最高区块的块高加1,且所述第i个区块的父区块哈希值等于所述最高区块的哈希值,则确定所述第i个区块通过所述共识验证。In an optional technical solution, the determining unit is further configured to: determine from the i-th block that the empty block index value of the i-th block is a preset value, and the i-th block The hash value of the parent empty block of each block is a null value, and the block height of the i-th block and the hash value of the parent block of the i-th block are determined from the i-th block, Determine the block height of the highest block and the hash value of the highest block from the blockchain of the secondary consensus node, if it is determined that the block height of the i-th block is equal to the block height of the highest block Plus 1, and the hash value of the parent block of the i-th block is equal to the hash value of the highest block, it is determined that the i-th block passes the consensus verification.
第六方面,本发明提供一种区块同步装置,适用于包括多个节点的区块链系统,所述区块链系统包括区块链和空块缓存,所述区块链中任一区块均不是空块,所述空块缓存用于存储空块。其中,所述空块缓存中的空块是针对所述区块链中第m个区块之后生成的空块且所述空块缓存中的空块在所述区块链中增加第m+1个区块时被清空,m为正整数,所述多个节点包括第一节点和第二节点,所述第一节点是所述多个节点中的任一个,所述第二节点是所述多个节点中除所述第一节点之外的任一个。所述装置包括:In a sixth aspect, the present invention provides a block synchronization device, which is suitable for a block chain system including multiple nodes. The block chain system includes a block chain and an empty block cache, and any block in the block chain All blocks are not empty blocks, and the empty block cache is used to store empty blocks. Wherein, the empty block in the empty block cache is for the empty block generated after the mth block in the blockchain, and the empty block in the empty block cache is increased by the m+th block in the blockchain. 1 block is cleared, m is a positive integer, the multiple nodes include a first node and a second node, the first node is any one of the multiple nodes, and the second node is all Any one of the plurality of nodes except the first node. The device includes:
接收单元,用于接收所述第二节点广播的状态信息;所述状态信息包括所述第二节点的空块缓存中最新空块的空块索引值和所述第二节点的区块链的最高区块的块高;The receiving unit is configured to receive the state information broadcast by the second node; the state information includes the empty block index value of the latest empty block in the empty block cache of the second node and the block chain value of the second node The block height of the highest block;
确定单元,用于若确定所述第二节点的区块链的最高区块的块高等于所述第一节点的区块链的最高区块的块高且所述第二节点的最新空块的空块索引值大于所述第一节点的最新空块的空块索引值,则从所述第二节点的空块缓存中确定待同步空块;所述待同步空块是所述第二节点的空块缓存中空块索引值大于所述第一节点的最新空块的空块索引值的空块;The determining unit is configured to determine that the block height of the highest block of the blockchain of the second node is equal to the block height of the highest block of the blockchain of the first node and the latest empty block of the second node If the empty block index value is greater than the empty block index value of the latest empty block of the first node, the empty block to be synchronized is determined from the empty block cache of the second node; the empty block to be synchronized is the second The empty block whose empty block index value is greater than the empty block index value of the latest empty block of the first node in the empty block cache of the node;
同步单元,用于将所述待同步空块同步至所述第一节点的空块缓存中。The synchronization unit is configured to synchronize the empty block to be synchronized to the empty block cache of the first node.
在一种可选地技术方案中,所述同步单元具体用于:针对任一个待同步空块,获取所述待同步空块的父空块哈希值和空块索引值,若确定所述待同步空块的父空块哈希值等于所述第一节点的空块缓存中最新空块的哈希值,且所述待同步空块的空块索引值等于所述第一节点的最新空块的空块索引值加1,则确定同步所述待同步空块至所述第一节点的空块缓存中。In an optional technical solution, the synchronization unit is specifically configured to: for any empty block to be synchronized, obtain the parent empty block hash value and the empty block index value of the empty block to be synchronized, and if it is determined that the The hash value of the parent empty block of the empty block to be synchronized is equal to the hash value of the latest empty block in the empty block cache of the first node, and the empty block index value of the empty block to be synchronized is equal to the latest empty block of the first node The empty block index value of the empty block is increased by 1, and it is determined to synchronize the empty block to be synchronized to the empty block cache of the first node.
在一种可选地技术方案中,所述待同步空块中包括父区块哈希值。在这种情况下,所述同步单元在确定同步所述待同步空块至所述第一节点的空块缓存中之前,还确定所述待同步空块中父区块哈希值是否等于所述第一节点的区块链上的最高区块的哈希值。In an optional technical solution, the empty block to be synchronized includes the hash value of the parent block. In this case, before determining to synchronize the empty block to be synchronized to the empty block cache of the first node, the synchronization unit also determines whether the hash value of the parent block in the empty block to be synchronized is equal to all The hash value of the highest block on the blockchain of the first node.
在一种可选地技术方案中,所述状态信息还包括所述第二节点的区块链的块高。在这种情况下,所述同步单元在从所述第二节点的空块缓存中确定待同步空块之前,若确定所述第二节点的区块链的最高区块的块高大于所述第一节点的区块链的最高区块的块高,则同步所述第二节点的区块链中高于所述第一节点的区块链的区块,并在所述第一节点的区块链的区块同步后,清空所述第一节点的空块缓存。In an optional technical solution, the state information further includes the block height of the blockchain of the second node. In this case, before the synchronization unit determines the empty block to be synchronized from the empty block cache of the second node, if it is determined that the block height of the highest block of the blockchain of the second node is greater than the If the block height of the highest block of the blockchain of the first node is synchronized, the block of the blockchain of the second node that is higher than the block of the first node’s blockchain is synchronized, and is in the area of the first node. After the blocks of the block chain are synchronized, the empty block cache of the first node is cleared.
第七方面,本发明提供一种计算设备,包括:In a seventh aspect, the present invention provides a computing device, including:
存储器,用于存储程序指令;Memory, used to store program instructions;
处理器,用于调用所述存储器中存储的程序指令,按照获得的程序执行上述第一方面至第三方面任意所述的区块处理方法、区块共识方法、区块同步方法。The processor is configured to call the program instructions stored in the memory, and execute the block processing method, block consensus method, and block synchronization method described in any of the first to third aspects according to the obtained program.
第八方面,本发明提供一种计算机可读非易失性存储介质,包括计算机可读指令,当 计算机读取并执行所述计算机可读指令时,使得计算机执行上述第一方面至第三方面任意所述的区块处理方法、区块共识方法、区块同步方法。In an eighth aspect, the present invention provides a computer-readable non-volatile storage medium, including computer-readable instructions. When the computer reads and executes the computer-readable instructions, the computer executes the first to third aspects described above. Any of the block processing methods, block consensus methods, and block synchronization methods.
附图说明Description of the drawings
为了更清楚地说明本发明实施例中的技术方案,下面将对实施例描述中所需要使用的附图作简要介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域的普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly describe the technical solutions in the embodiments of the present invention, the following will briefly introduce the drawings needed in the description of the embodiments. Obviously, the drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, without creative work, other drawings can be obtained from these drawings.
图1为本发明实施例提供的一种空块块头的结构示意图;FIG. 1 is a schematic structural diagram of an empty block header provided by an embodiment of the present invention;
图2为本发明实施例提供的一种区块处理方法的流程示意图;2 is a schematic flowchart of a block processing method provided by an embodiment of the present invention;
图3为本发明实施例提供的另一种区块处理方法的流程示意图;FIG. 3 is a schematic flowchart of another block processing method provided by an embodiment of the present invention;
图4为本发明实施例提供的一种区块共识方法的流程示意图;4 is a schematic flowchart of a block consensus method provided by an embodiment of the present invention;
图5为本发明实施例提供的另一种区块共识方法的流程示意图;FIG. 5 is a schematic flowchart of another block consensus method provided by an embodiment of the present invention;
图6为本发明实施例提供的一种PBFT共识算法中空块处理、共识的流程;6 is a process of hollow block processing and consensus in a PBFT consensus algorithm provided by an embodiment of the present invention;
图7为本发明实施例提供的一种区块同步方法的流程示意图;FIG. 7 is a schematic flowchart of a block synchronization method provided by an embodiment of the present invention;
图8为本发明实施例提供的一种第二节点广播状态信息的示意图;FIG. 8 is a schematic diagram of a second node broadcasting status information according to an embodiment of the present invention;
图9为本发明实施例提供的一种第一节点接收状态信息的示意图;FIG. 9 is a schematic diagram of receiving state information of a first node according to an embodiment of the present invention;
图10为本发明实施例提供的一种区块处理装置的结构示意图;10 is a schematic structural diagram of a block processing apparatus provided by an embodiment of the present invention;
图11为本发明实施例提供的一种区块共识装置的结构示意图;FIG. 11 is a schematic structural diagram of a block consensus device provided by an embodiment of the present invention;
图12为本发明实施例提供的一种区块同步装置的结构示意图。FIG. 12 is a schematic structural diagram of a block synchronization device provided by an embodiment of the present invention.
具体实施方式detailed description
为了使本发明的目的、技术方案和优点更加清楚,下面将结合附图对本发明作进一步地详细描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其它实施例,都属于本发明保护的范围。In order to make the objectives, technical solutions and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all of them. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative work shall fall within the protection scope of the present invention.
为了更好的解释本发明,先对本发明实施例中所涉及的名词进行解释:To better explain the present invention, first explain the terms involved in the embodiments of the present invention:
区块:构成区块链的基本单元,由包含元数据的区块头和包含交易数据的区块体构成,区块头主要包括父区块的哈希。Block: The basic unit that constitutes the blockchain. It consists of a block header containing metadata and a block body containing transaction data. The block header mainly includes the hash of the parent block.
区块链:区块链是由一系列区块组成的一条链,每个块上除了记录本块的数据还会记录上一块的哈希值(Hash),通过这种方式组成一条链。区块链的核心理念有两个,一个是密码学技术,另一个是去中心化思想,基于这两个理念可以做到区块链上的历史信息无法被篡改。一个区块由块头和块体组成,其中块头包括该区块的区块高度、父区块哈希(prevHash)等重要字段,而块体主要存储交易数据。Blockchain: A blockchain is a chain composed of a series of blocks. In addition to recording the data of the block, each block also records the hash value (Hash) of the previous block. In this way, a chain is formed. There are two core concepts of the blockchain, one is cryptography and the other is decentralization. Based on these two concepts, the historical information on the blockchain cannot be tampered with. A block is composed of a block header and a block body. The block header includes important fields such as the block height of the block and the parent block hash (prevHash), and the block body mainly stores transaction data.
共识算法:区块链网络中的各个节点通过一种算法对一批交易进行确认,并确保所有节点对这批数据具有一致的确认结果,这种算法就是区块链的共识算法,目前常见的共识算法包括PBFT、副本容错(replication and fault tolerant,Raft)、POW、POS等。Consensus algorithm: Each node in the blockchain network confirms a batch of transactions through an algorithm, and ensures that all nodes have a consistent confirmation result for this batch of data. This algorithm is the consensus algorithm of the blockchain, which is currently common Consensus algorithms include PBFT, replication and fault tolerance (Raft), POW, POS, etc.
交易池:存储客户端发起的全部有效交易的队列称为交易池,进入交易池的交易必须满足以下条件:(1)与交易池内已有交易不重复;(2)与记录在区块内的交易不重复;(3)签名有效。Transaction pool: The queue that stores all valid transactions initiated by the client is called the transaction pool. The transactions that enter the transaction pool must meet the following conditions: (1) It does not overlap with existing transactions in the transaction pool; (2) It is the same as that recorded in the block. The transaction is not repeated; (3) The signature is valid.
节点:区块链网络中的每一个参与者就是一个节点,节点参与网络组建和数据交换。 在区块链网络中,一个节点是指一个具有唯一身份的参与者,该节点具有一份完整的账本拷贝,具有参与区块链网络共识和账本维护的能力。Node: Each participant in the blockchain network is a node, and the node participates in network formation and data exchange. In the blockchain network, a node refers to a participant with a unique identity. The node has a complete copy of the ledger and has the ability to participate in the consensus and maintenance of the blockchain network.
共识节点:可参与共识出块的节点,主要功能包括:将交易池内的交易打包成区块;执行交易;运行共识算法,并将达成共识的区块写入账本。Consensus node: A node that can participate in consensus block generation. Its main functions include: packaging transactions in the transaction pool into blocks; executing transactions; running consensus algorithms and writing consensus blocks into the ledger.
PBFT共识算法:可以在少数节点作恶(如伪造消息)场景中达成共识,它采用签名、签名验证、哈希等密码学算法确保消息传递过程中的防篡改性、防伪造性、不可抵赖性,并优化了前人工作,将拜占庭容错算法复杂度从指数级降低到多项式级别,在一个由(3×f+1)个节点构成的系统中,只要有不少于(2×f+1)非恶意节点正常工作,该系统就能达成一致性,如:7个节点的系统中允许2个节点出现拜占庭错误。PBFT consensus algorithm: It can reach a consensus in a few nodes doing evil (such as forging messages). It uses cryptographic algorithms such as signatures, signature verification, and hashing to ensure tamper-proof modification, anti-forgery, and non-repudiation in the process of message transmission. And optimize the previous work, reduce the complexity of the Byzantine fault-tolerant algorithm from exponential level to polynomial level, in a system composed of (3×f+1) nodes, as long as there are no less than (2×f+1) If non-malicious nodes work normally, the system can reach consistency. For example, in a 7-node system, 2 nodes are allowed to have Byzantine errors.
空块:不包含任何交易的区块。Empty block: A block that does not contain any transactions.
非空块:与空块相对应,包括交易的区块。Non-empty block: corresponds to the empty block, including the transaction block.
QPS(Query Per Second,每秒查询率):每秒请求数目,计算共识为请求数除以时间。QPS (Query Per Second): The number of requests per second. The calculation consensus is the number of requests divided by time.
本发明提供一种区块处理方法、区块共识方法和区块同步方法,适用于区块链系统,该区块链系统即上述的区块链网络,该区块链系统包括区块链和空块缓存,区块链用于存储非空块,即区块链中任一区块均不是空块,空块缓存用于存储空块,且空块缓存中的空块是针对区块链中第m个区块之后生成的空块且空块缓存中的空块在区块链中增加第m+1个区块时被清空。其中,m为正整数。The present invention provides a block processing method, a block consensus method, and a block synchronization method, which are suitable for a block chain system. The block chain system is the aforementioned block chain network. The block chain system includes a block chain and Empty block cache, the blockchain is used to store non-empty blocks, that is, any block in the blockchain is not an empty block, the empty block cache is used to store empty blocks, and the empty blocks in the empty block cache are for the blockchain The empty blocks generated after the mth block in the middle and empty blocks in the empty block cache are emptied when the m+1th block is added to the blockchain. Among them, m is a positive integer.
解释为,区块链系统中存在两种存储方式,一种是将非空块存储至区块链,一种是将空块存储至空块缓存。区块链系统生成空块的目的在于,防止区块链中恶意节点篡改数据,且区块链系统在生成空块后会被共识上链。本发明中的空块上链指的是将空块存储至空块缓存中。为了节省节点中的存储空间,空块缓存中的空块会在下一个非空块上链(存储至区块链)之后清空,即将当前的空块缓存中的所有空块删除。It is explained that there are two storage methods in the blockchain system, one is to store non-empty blocks in the blockchain, and the other is to store empty blocks in the empty block cache. The purpose of the block chain system to generate empty blocks is to prevent malicious nodes in the block chain from tampering with data, and the block chain system will be consensus on the chain after generating the empty blocks. The empty block upload in the present invention refers to storing the empty block in the empty block cache. In order to save storage space in the node, the empty block in the empty block cache will be emptied after the next non-empty block is uploaded (stored to the blockchain), that is, all empty blocks in the current empty block cache are deleted.
举例来说,当前区块链上有100个非空块,即块高为100。此时,生成了第1个空块并存储至空块缓存中,随后又生成了第2个空块、第3个空块……第10个空块并存储至空块缓存中,需要说明的是,第1个空块至第10个空块期间不会生成非空块。当区块链系统中生成第101个非空块并经共识后存储至区块链上时,块高为101,且区块链系统将空块缓存中当前缓存的10个空块删除。如果区块链系统再生成空块时,则作为第1个空块再次存储至空块缓存中,随后可能还会存储第2个空块至第n个空块至空块缓存中,但都会在第102个非空块生成并经共识存储至区块链上时,再次被清空。For example, there are 100 non-empty blocks on the current blockchain, that is, the block height is 100. At this point, the first empty block is generated and stored in the empty block cache, and then the second empty block, the third empty block...the tenth empty block is generated and stored in the empty block cache. However, no non-empty block will be generated from the first empty block to the tenth empty block. When the 101st non-empty block is generated in the blockchain system and stored on the blockchain after consensus, the block height is 101, and the blockchain system deletes the 10 empty blocks currently cached in the empty block cache. If the blockchain system generates an empty block again, it will be stored as the first empty block in the empty block cache again, and then the second empty block to the nth empty block may be stored in the empty block cache, but it will When the 102nd non-empty block is generated and stored on the blockchain by consensus, it is emptied again.
通过上述过程,可以在保障区块链系统中生成的所有空块和非空块都共识的前提下,将生成的所有空块清除,以降低空块在区块链系统中所占的存储空间,提升磁盘利用效率。Through the above process, all empty blocks and non-empty blocks generated in the blockchain system can be guaranteed to be agreed, so as to reduce the storage space occupied by empty blocks in the blockchain system. Improve disk utilization efficiency.
例如,某区块链系统1s即生成一个区块,1天有50%的时间没有交易,每个空块大小为1KB,若这些空块都存储至区块链上,则一天空块占据的磁盘空间为:3600s/h×24h×50%×1KB≈43.2MB,1年空块占据约为15.7GB磁盘空间。设平均每个交易大小为1KB,则15.7GB磁盘空间可用于存储15.7GB/1KB=15700笔交易。For example, a block chain system generates a block in 1 second. There are no transactions 50% of the time in a day. Each empty block is 1KB in size. If these empty blocks are stored on the blockchain, a sky block will occupy The disk space is: 3600s/h×24h×50%×1KB≈43.2MB, and one-year empty blocks occupy about 15.7GB of disk space. Assuming that the average transaction size is 1KB, then 15.7GB of disk space can be used to store 15.7GB/1KB=15700 transactions.
结合上述描述,为了实现空块共识,可以设置空块的块头。空块的块头中包括多个字段,可以有空块索引值、父空块哈希值、父区块哈希值(prevHash)、块高(blockNumber)和打包者(sealer)。其中,空块索引值和父空块哈希值可以存储至扩展数组(extraData)中,如图1为本发明实施例提供的一种空块块头的结构。下面对图1示意出的空块块头中的各个字段进行介绍。In combination with the above description, in order to realize the empty block consensus, the header of the empty block can be set. The header of an empty block includes multiple fields, which can include empty block index value, parent empty block hash value, parent block hash value (prevHash), block height (blockNumber), and sealer. Wherein, the index value of the empty block and the hash value of the parent empty block can be stored in an extended array (extraData). FIG. 1 is a structure of an empty block header provided by an embodiment of the present invention. The following describes each field in the header of the empty block shown in FIG. 1.
父区块哈希:最高非空块的哈希值,即区块链上最高区块的哈希值;Parent block hash: the hash value of the highest non-empty block, that is, the hash value of the highest block on the blockchain;
区块高度:最高非空块的块高加1,即区块链上最高区块的块高加1;Block height: the block height of the highest non-empty block plus 1, that is, the block height of the highest block on the blockchain plus 1;
打包者:产生空块的共识节点索引,相当于主共识节点的索引。考虑到节点身份标识号(Identification,ID)很长,在共识消息中直接包含节点ID字段会耗费部分网络带宽,因此,本发明实施例中的区块链系统引入了节点索引。区块链系统中可以设置公共节点列表,公共节点列表中记录有各节点的节点索引,节点索引用于指示每个节点在公共节点列表中的位置。发送网络消息包时,只需要带上节点索引,其他节点即可以从公共节点列表中索引出节点ID,进而对网络消息进行验证签名。Packager: The index of the consensus node that generates the empty block, which is equivalent to the index of the master consensus node. Considering that the node identification number (Identification, ID) is very long, directly including the node ID field in the consensus message will consume part of the network bandwidth. Therefore, the blockchain system in the embodiment of the present invention introduces a node index. A public node list can be set in the blockchain system, and the node index of each node is recorded in the public node list, and the node index is used to indicate the position of each node in the public node list. When sending a network message packet, you only need to bring the node index, and other nodes can index the node ID from the public node list, and then verify the signature of the network message.
空块索引值;基于最高非空块产生的空块索引值,用于指示空块缓存中各空块产生的先后顺序,如:当前空块是基于第10个非空块产生的第5个空块,则当前空块的空块索引为4。Empty block index value; the empty block index value generated based on the highest non-empty block, used to indicate the order of the empty blocks in the empty block cache, such as: the current empty block is the fifth generated based on the 10th non-empty block Empty block, the empty block index of the current empty block is 4.
父空块哈希值:前一个空块的哈希值,可通过空块缓存获取。Hash value of the parent empty block: The hash value of the previous empty block can be obtained through the empty block cache.
空块缓存可以理解成一个空块表,有多个空块排列组成,如表1所示,为一种空块表的结构,第n个空块中记录有第n-1个空块的哈希值,第n个空块中记录有空块索引值为(n-1)。空块表中记录有当前空块缓存的最新空块索引值(latestIdx),也即最新空块的空块索引值。当区块链系统中生成第n+1个空块时,区块链系统会将最新空块索引值加1后打包至第n+1个空块的块头中,且在第n+1个空块存储至空块缓存中时,最新空块索引值更新为n。The empty block cache can be understood as an empty block table consisting of multiple empty block arrangements. As shown in Table 1, it is an empty block table structure. The nth empty block records the n-1th empty block Hash value, the index value of the empty block recorded in the nth empty block is (n-1). The empty block table records the latest empty block index value (latestIdx) of the current empty block cache, that is, the empty block index value of the latest empty block. When the n+1th empty block is generated in the blockchain system, the blockchain system will add 1 to the index value of the latest empty block and pack it into the header of the n+1th empty block. When the empty block is stored in the empty block cache, the latest empty block index value is updated to n.
表1Table 1
KeyKey ValueValue
number_0number_0 emptyBlock_0emptyBlock_0
number_1number_1 emptyBlock_1emptyBlock_1
number_(n-1)number_(n-1) emptyBlock_(n-1)emptyBlock_(n-1)
latestIdxlatestIdx (n-1)(n-1)
进一步的,区块链系统中包括多个节点,各节点的本地存储有上述区块链和空块缓存。多个节点中包括主共识节点和辅共识节点,其中,主共识节点用于打包区块和区块共识,辅共识节点用于区块共识。每轮共识过程中有且仅有一个主共识节点,且在每轮共识之后,会切换主共识节点。Further, the blockchain system includes multiple nodes, and each node stores the above-mentioned blockchain and empty block cache locally. The multiple nodes include a main consensus node and an auxiliary consensus node. Among them, the main consensus node is used for packaging blocks and block consensus, and the auxiliary consensus node is used for block consensus. There is one and only one master consensus node in each round of consensus, and after each round of consensus, the master consensus node will be switched.
图2和图3示例性的示出了本发明实施例提供的区块处理方法的流程,该流程可以由区块处理装置执行,该装置可以位于区块链网络的节点中,例如可以是用于打包区块的主共识节点。本申请实施例中,区块链系统定时出块,当主共识节点在出块时,可以先判断当前出块时是否有交易被打包至区块,也即判断待生成的区块是否为空块。本发明实施例中,待生成的区块为空块和非空块时,所对应的操作步骤不同,下面分情况说明。Figures 2 and 3 exemplarily show the flow of a block processing method provided by an embodiment of the present invention. The flow can be executed by a block processing device, which can be located in a node of a blockchain network, for example, The master consensus node for packaging blocks. In the embodiment of this application, the blockchain system periodically generates blocks. When the master consensus node is generating blocks, it can first determine whether any transactions are packaged into the block when the current block is generated, that is, whether the block to be generated is an empty block . In the embodiment of the present invention, when the block to be generated is an empty block and a non-empty block, the corresponding operation steps are different, and the following descriptions are divided into situations.
如图2所示,为主共识节点确定待生成区块为空块时的具体流程,该流程包括:As shown in Figure 2, the specific process when the master consensus node determines that the block to be generated is an empty block, the process includes:
步骤201,主共识节点在确定待生成的第i个区块为空块时,从空块缓存中确定最新空块的空块索引值和最新空块的哈希值;Step 201: When determining that the i-th block to be generated is an empty block, the master consensus node determines the empty block index value of the latest empty block and the hash value of the latest empty block from the empty block cache;
步骤202,主共识节点生成第i个区块并将第i个区块广播至各辅共识节点;Step 202: The main consensus node generates the i-th block and broadcasts the i-th block to each auxiliary consensus node;
步骤203,主共识节点在确定第i个区块通过共识验证后,将第i个区块存储至空块缓存中。In step 203, after determining that the i-th block passes the consensus verification, the master consensus node stores the i-th block in the empty block cache.
其中,i为正整数,空块缓存中存储有至少一个空块,主共识节点可以从空块缓存中确定出最新空块,也即最后一个存储至空块缓存中空块。主共识节点根据该最新空块,确定该最新空块的空块索引值和最新空块的哈希值,其中,根据该最新空块的空块索引值确定第i个区块的空块索引值,可以是将最新空块的空块索引值加1后确定为第i个区块的空块索引值,以及将最新空块的哈希值确定为第i个区块的父空块哈希值,并根据第i个区块的空块索引值和父空块哈希值生成第i个区块。Among them, i is a positive integer, at least one empty block is stored in the empty block cache, and the master consensus node can determine the latest empty block from the empty block cache, that is, the last empty block stored in the empty block cache. The master consensus node determines the empty block index value of the latest empty block and the hash value of the latest empty block according to the latest empty block, wherein the empty block index of the i-th block is determined according to the empty block index value of the latest empty block The value can be the empty block index value of the i-th block determined by adding 1 to the empty block index value of the latest empty block, and the hash value of the latest empty block is determined as the parent empty block of the i-th block. Hope value, and generate the i-th block according to the empty block index value of the i-th block and the hash value of the parent empty block.
在一种可选地实施方式中,第i个区块中可以包括第i个区块的空块索引值和父空块哈希值,还可以包括第i个区块的块高和第i个区块的父区块哈希值。其中,第i个区块的块高可以为当前区块链上最高区块的块高加1,也可以等于当前区块链上最高区块。第i个区块的父区块哈希值可以为当前区块链上最高区块的哈希值,例如具体可以为最高区块的块头的哈希值。这种情况下:In an optional implementation manner, the i-th block may include the empty block index value and the parent empty block hash value of the i-th block, and may also include the block height of the i-th block and the i-th block. The hash value of the parent block of each block. Among them, the block height of the i-th block can be the block height of the highest block on the current blockchain plus 1, or it can be equal to the highest block on the current blockchain. The hash value of the parent block of the i-th block may be the hash value of the highest block on the current blockchain, for example, it may be the hash value of the block header of the highest block. In this situation:
一种实现方式中,主共识节点可以从区块链上获取最高区块的块高和哈希值,将最高区块的块高加1后确定为第i个区块的块高,以及将最高区块的哈希值确定为第i个区块的父区块哈希值,进而将第i个区块的块高、第i个区块的父区块哈希值、第i个区块的空块索引值和第i个区块的父空块哈希值打包至第i个区块。In one implementation, the master consensus node can obtain the block height and hash value of the highest block from the blockchain, add 1 to the block height of the highest block to determine the block height of the i-th block, and The hash value of the highest block is determined as the hash value of the parent block of the i-th block, and then the block height of the i-th block, the hash value of the parent block of the i-th block, and the i-th block The empty block index value of the block and the hash value of the parent empty block of the i-th block are packed into the i-th block.
另一种实现方式中,可以在空块缓存中设置最新空块索引值,最新空块索引值即为最新空块的空块索引值。如此,主共识节点可以从空块缓存中确定最新空块索引值,并根据最新空块索引值,从空块缓存中确定最新空块并获取最新空块的空块索引值和最新空块的哈希值,进而将第i个区块的块高、第i个区块的父区块哈希值、第i个区块的空块索引值和第i个区块的父空块哈希值打包至第i个区块,在将第i个区块存储至空块缓存中之后,主共识节点可以将最新空块索引值加1。In another implementation manner, the latest empty block index value may be set in the empty block cache, and the latest empty block index value is the empty block index value of the latest empty block. In this way, the master consensus node can determine the latest empty block index value from the empty block cache, and according to the latest empty block index value, determine the latest empty block from the empty block cache and obtain the empty block index value of the latest empty block and the latest empty block index value. Hash value, and then hash the block height of the i-th block, the hash value of the parent block of the i-th block, the empty block index value of the i-th block and the parent empty block of the i-th block The value is packed into the i-th block. After storing the i-th block in the empty block cache, the master consensus node can increase the index value of the latest empty block by 1.
需要说明的是,上述实施例中主共识节点在生成第i个区块前,若空块缓存中存储有至少一个空块,则主共识节点可以获取到第i个区块的父空块哈希值。若空块缓存中未存储有空块时,相当于第i个区块为当前空块缓存中的第一个空块,则主共识节点不能获取到第i个区块的父空块哈希值,这种情况下,主共识节点可以将第i个区块的父空块哈希值设置为空。本发明实施例中,主共识节点可以在生成第i个区块前,直接判断当前空块缓存中是否存储有空块,也可以读取当前空块缓存中的最新空块索引值,进而确定当前空块缓存中是否存储有空块,主共识节点若读取到该最新空块索引值为预设值时,则可以确定当前空块缓存中未存储有空块,该预设值可以为-1或0或者其它值,该预设值用于指示当前空块缓存中不存在空块。进一步的,主共识节点在确定当前空块缓存中未存储有空块之后,则将第i个区块的父空块哈希值设置为空,且将第i个区块的空块索引值设置为预设值加1。It should be noted that in the above embodiment, before the master consensus node generates the i-th block, if at least one empty block is stored in the empty block cache, the master consensus node can obtain the parent empty block of the i-th block. Hope value. If there is no empty block stored in the empty block cache, it is equivalent to the i-th block being the first empty block in the current empty block cache, and the master consensus node cannot obtain the parent empty block hash of the i-th block In this case, the master consensus node can set the hash value of the parent empty block of the i-th block to be empty. In the embodiment of the present invention, the master consensus node can directly determine whether there are empty blocks stored in the current empty block cache before generating the i-th block, or read the latest empty block index value in the current empty block cache to determine Whether there are empty blocks stored in the current empty block cache, if the master consensus node reads that the latest empty block index value is a preset value, it can determine that there are no empty blocks stored in the current empty block cache. The preset value can be -1 or 0 or other values, the preset value is used to indicate that there are no empty blocks in the current empty block cache. Further, after determining that no empty block is stored in the current empty block cache, the master consensus node sets the hash value of the parent empty block of the i-th block to empty, and sets the empty block index value of the i-th block Set to the preset value plus 1.
具体实现中,主共识节点可以获取最新空块索引值,若最新空块索引值为-1,则获取区块链上最高非空块的区块头,并将最高非空块的区块头哈希值确定为当前空块的父区块哈希值,以及将0确定为当前空块的空块索引值,将最高非空块的块高加1后确定为当前空块的块高。若最新空块索引值大于0,则从空块缓存中读取最新空块的区块头,并将最新空块的区块头的哈希值确定为当前空块的父空块哈希值,将最新空块索引值加1后确定为当前空块的空块索引值,以及将最高非空块的区块头哈希值确定为当前空块的父区块哈希值,将最高非空块的块高加1后确定为当前空块的块高。In specific implementation, the master consensus node can obtain the latest empty block index value. If the latest empty block index value is -1, the block header of the highest non-empty block on the blockchain is obtained, and the block header of the highest non-empty block is hashed The value is determined as the hash value of the parent block of the current empty block, and 0 is determined as the empty block index value of the current empty block, and the block height of the highest non-empty block is added by 1 to determine the block height of the current empty block. If the index value of the latest empty block is greater than 0, read the block header of the latest empty block from the empty block cache, and determine the hash value of the latest empty block as the parent empty block hash value of the current empty block. The latest empty block index value plus 1 is determined as the empty block index value of the current empty block, and the block header hash value of the highest non-empty block is determined as the parent block hash value of the current empty block, and the highest non-empty block The block height plus 1 is determined as the block height of the current empty block.
如图3所示,为主共识节点确定待生成区块为非空块时的具体流程,该流程包括:As shown in Figure 3, the specific process when the master consensus node determines that the block to be generated is a non-empty block, the process includes:
步骤301,主共识节点在确定待生成的第i个区块不是空块时,则获取区块链上最高区 块的块高和哈希值;Step 301: When determining that the i-th block to be generated is not an empty block, the master consensus node obtains the block height and hash value of the highest block on the blockchain;
步骤302,主共识节点将最高区块的块高加1后确定为第i个区块的块高,将最高区块的哈希值确定为第i个区块的父区块哈希值;Step 302: The master consensus node adds 1 to the block height of the highest block to determine the block height of the i-th block, and determines the hash value of the highest block as the parent block hash value of the i-th block;
步骤303,主共识节点将第i个区块的块高、第i个区块的父区块哈希值打包至第i个区块;Step 303: The master consensus node packs the block height of the i-th block and the hash value of the parent block of the i-th block into the i-th block;
步骤304,主共识节点将第i个区块广播至各辅共识节点; Step 304, the main consensus node broadcasts the i-th block to each auxiliary consensus node;
步骤305,主共识节点在确定第i个区块通过共识验证后,将第i个区块存储至区块链中,并清除当前空块缓存中的空块。Step 305: After determining that the i-th block passes the consensus verification, the master consensus node stores the i-th block in the blockchain, and clears the empty block in the current empty block cache.
这种情况下,第i个区块即为第m+1个区块,将第i个区块存储至区块链中相当于将第m+1个区块存储至区块链中,也即空块缓存中的空块是在区块链中第m个区块之后生成,且会在第m+1个区块存储至区块链时被删除。In this case, the i-th block is the m+1th block, and storing the i-th block in the blockchain is equivalent to storing the m+1th block in the blockchain. That is, the empty block in the empty block cache is generated after the mth block in the blockchain, and will be deleted when the m+1th block is stored in the blockchain.
上述实施例中,主共识节点可以生成空块或非空块,各共识节点可以分别对空块和非空块进行共识验证。具体的如下:In the foregoing embodiment, the master consensus node can generate an empty block or a non-empty block, and each consensus node can perform consensus verification on the empty block and the non-empty block respectively. The details are as follows:
各共识节点对非空块进行共识验证:非空块中包括父区块哈希值、块高、主共识节点索引,各共识节点可以根据该非空块的父区块哈希值、块高、主共识节点索引,并结合本共识节点的区块链,对该非空块进行共识验证;Each consensus node performs consensus verification on non-empty blocks: non-empty blocks include parent block hash value, block height, and master consensus node index. Each consensus node can be based on the parent block hash value and block height of the non-empty block. , The index of the master consensus node, combined with the blockchain of this consensus node, to perform consensus verification on the non-empty block;
各共识节点对空块进行共识验证:主共识节点生成的空块又可以分为是否为空块缓存中的第一个空块,如果不是空块缓存中的第一个空块,则该空块包括父区块哈希值、块高、空块索引值、父区块哈希值、主共识节点索引,在对空块进行共识时,各共识节点可以根据该空块中父区块哈希值、块高、空块索引值、父空块哈希值、主共识节点索引,并结合本共识节点的区块链和空块缓存,对该空块进行共识验证。如果是空块缓存中的第一个空块,则该空块包括父区块哈希值、块高、空块索引值、主共识节点索引,在对空块进行共识时,各共识节点可以根据该空块中父区块哈希值、块高、空块索引值、主共识节点索引,并结合本共识节点的区块链和空块缓存,对该空块进行共识验证。Each consensus node performs consensus verification on the empty block: the empty block generated by the master consensus node can be divided into whether it is the first empty block in the empty block cache. If it is not the first empty block in the empty block cache, the empty block The block includes the parent block hash value, block height, empty block index value, parent block hash value, and master consensus node index. When consensus is on the empty block, each consensus node can be based on the parent block in the empty block. Hope value, block height, empty block index value, parent empty block hash value, master consensus node index, combined with the consensus node's blockchain and empty block cache, perform consensus verification on the empty block. If it is the first empty block in the empty block cache, the empty block includes the hash value of the parent block, the block height, the index value of the empty block, and the index of the master consensus node. When consensus is reached on the empty block, each consensus node can According to the parent block hash value, block height, empty block index value, master consensus node index in the empty block, combined with the consensus node's blockchain and empty block cache, consensus verification is performed on the empty block.
由此可知,本发明实施例,区块链系统无论是生成空块还是非空块,都会对生成的空块或非空块进行共识验证,以确保区块链系统中节点的安全性。同时,还会将非空块存储至区块链中做永久性存储,将空块存储至空块缓存并在区块链中有新的区块上链时清除空块缓存,以节省磁盘存储空间,提高磁盘利用率。这种方式在保障区块链系统安全性的前提下,还能提高各节点中磁盘利用率,有助于使各节点可存储更多的账本数据。It can be seen from this that, in the embodiment of the present invention, whether the blockchain system generates empty blocks or non-empty blocks, consensus verification will be performed on the generated empty blocks or non-empty blocks to ensure the security of nodes in the blockchain system. At the same time, non-empty blocks will be stored in the blockchain for permanent storage, empty blocks will be stored in the empty block cache, and the empty block cache will be cleared when a new block is added to the blockchain to save disk storage Space to improve disk utilization. Under the premise of ensuring the security of the blockchain system, this method can also improve the utilization of disks in each node, which helps to enable each node to store more ledger data.
基于同一发明构思,本发明还提供一种区块共识方法,该区块共识的方法同样适用于上述区块链系统,且可以是在主共识节点将第i个区块进行打包并广播后,各共识节点进行共识的流程。各共识节点可以对空块共识、非空块共识,且在空块共识时可以是对空块缓存中的第一个空块共识,也可是对空块缓存中的第一个空块之后的空块共识。此处,非空块共识即验证第i个区块的块高和父区块哈希值,具体验证过程不做赘述,但共识节点在确定第i个区块通过共识验证后,将该非空块存储至区块链上之后,可以清空本地的空块缓存中的空块。Based on the same inventive concept, the present invention also provides a block consensus method. The block consensus method is also applicable to the above-mentioned blockchain system, and may be after the master consensus node packs and broadcasts the i-th block, The process by which consensus nodes carry out consensus. Each consensus node can agree on empty blocks, non-empty blocks, and in empty block consensus, it can be the consensus on the first empty block in the empty block cache, or the consensus on the first empty block in the empty block cache. Empty block consensus. Here, the consensus of a non-empty block is to verify the block height of the i-th block and the hash value of the parent block. The specific verification process will not be repeated, but the consensus node will determine that the i-th block has passed the consensus verification. After the empty blocks are stored on the blockchain, the empty blocks in the local empty block cache can be cleared.
下面具体描述共识节点对空块进行共识的具体实现方式,为方便描述,下文将用于共识的节点叫做辅共识节点。当辅共识节点接收到第i个区块时,可以确定出第i个区块中是否存在父空块哈希值或者可以读取该第i个区块中的空块索引值,进而确定该第i个区块是否为空块缓存中的第一个空块。The following specifically describes the specific implementation of consensus nodes on empty blocks. For the convenience of description, the nodes used for consensus are called auxiliary consensus nodes below. When the secondary consensus node receives the i-th block, it can determine whether there is a parent empty block hash value in the i-th block or can read the empty block index value in the i-th block to determine the Whether the i-th block is the first empty block in the empty block cache.
在一种可选地实施方式中,当辅共识节点确定第i个区块不是第一个空块时,辅共识节 点可以执行如图4示出的流程图中的各步骤流程,该流程包括:。In an optional implementation manner, when the auxiliary consensus node determines that the i-th block is not the first empty block, the auxiliary consensus node may execute the process of each step in the flowchart shown in FIG. 4, which includes :.
步骤401,辅共识节点接收主共识节点广播的第i个区块; Step 401, the auxiliary consensus node receives the i-th block broadcast by the main consensus node;
步骤402,辅共识节点从第i个区块中确定第i个区块的空块索引值和第i个区块的父空块哈希值;Step 402: The auxiliary consensus node determines the empty block index value of the i-th block and the hash value of the parent empty block of the i-th block from the i-th block;
步骤403,辅共识节点从辅共识节点的空块缓存中确定第一空块的哈希值和第一空块的空块索引值;Step 403: The auxiliary consensus node determines the hash value of the first empty block and the empty block index value of the first empty block from the empty block cache of the auxiliary consensus node;
步骤404,辅共识节点若确定第i个区块通过共识验证,则将第i个区块存储至辅共识节点的空块缓存中。In step 404, if the auxiliary consensus node determines that the i-th block passes the consensus verification, the i-th block is stored in the empty block cache of the auxiliary consensus node.
在该种实施方式中,辅共识节点在接收到第i个区块后,会结合本辅共识节点的区块链和空块缓存,对该空块进行共识验证。具体的,辅共识节点在确定本地的空块缓存中的最新空块为第一空块后,确定第一空块的空块索引值和第一空块的哈希值,并判断第i个区块的空块索引值与第一空块的空块索引值是否符合预设要求,可以是判断第i个区块的空块索引值是否等于第一空块的空块索引值加1,以及判断第i个区块的父空块哈希值是否等于第一空块的哈希值,若两次判断都是等于,则确定第i个区块通过共识验证。In this implementation manner, after the auxiliary consensus node receives the i-th block, it combines the blockchain of the auxiliary consensus node and the empty block cache to perform consensus verification on the empty block. Specifically, after determining that the latest empty block in the local empty block cache is the first empty block, the secondary consensus node determines the empty block index value of the first empty block and the hash value of the first empty block, and determines the i-th empty block Whether the empty block index value of the block and the empty block index value of the first empty block meet the preset requirements can be determined by judging whether the empty block index value of the i-th block is equal to the empty block index value of the first empty block plus 1. And judging whether the hash value of the parent empty block of the i-th block is equal to the hash value of the first empty block, and if the two judgments are equal, it is determined that the i-th block passes the consensus verification.
示例性地,辅共识节点在对第i个区块进行共识验证时,还可以包括对第i个区块中的块高和父区块哈希值进行验证。具体的,辅共识节点从第i个区块中确定第i个区块的块高和第i个区块的父区块哈希值,以及从辅共识节点的区块链中确定最高区块的块高和最高区块的哈希值,并根据区块高度、父区块哈希对第i个区块进行共识验证。也就是说,共识验证不仅包括验证第i个区块的空块索引值与第一空块的空块索引值是否符合预设要求,以及验证父空块哈希值是否等于第一空块的哈希值,还包括:验证第i个区块的块高是否等于最高区块的块高加1以及第i个区块的父区块哈希值是否等于最高区块的哈希值。Exemplarily, when the auxiliary consensus node performs consensus verification on the i-th block, it may also include verification of the block height in the i-th block and the hash value of the parent block. Specifically, the secondary consensus node determines the block height of the i-th block and the hash value of the parent block of the i-th block from the i-th block, and determines the highest block from the blockchain of the secondary consensus node The block height of and the hash value of the highest block, and the consensus verification of the i-th block is performed according to the block height and the parent block hash. In other words, consensus verification includes not only verifying whether the empty block index value of the i-th block and the empty block index value of the first empty block meet the preset requirements, but also verifying whether the hash value of the parent empty block is equal to that of the first empty block. The hash value also includes: verifying whether the block height of the i-th block is equal to the block height of the highest block plus 1 and whether the hash value of the parent block of the i-th block is equal to the hash value of the highest block.
在另一种可选地实施方式中,当辅共识节点确定第i个区块是第一个空块时,即辅共识节点确定第i个区块的空块索引值为预设值,且第i个区块的父空块哈希值为空值,则辅共识节点可以执行如图5示出的流程图中的各步骤流程,该流程包括:In another optional implementation, when the auxiliary consensus node determines that the i-th block is the first empty block, that is, the auxiliary consensus node determines that the empty block index value of the i-th block is a preset value, and If the hash value of the parent empty block of the i-th block is a null value, the auxiliary consensus node can execute the process of each step in the flowchart shown in FIG. 5, which includes:
步骤501,辅共识节点从第i个区块中确定第i个区块的块高和第i个区块的父区块哈希值; Step 501, the auxiliary consensus node determines the block height of the i-th block and the hash value of the parent block of the i-th block from the i-th block;
步骤502,辅共识节点从辅共识节点的区块链中确定最高区块的块高和最高区块的哈希值; Step 502, the auxiliary consensus node determines the block height of the highest block and the hash value of the highest block from the blockchain of the auxiliary consensus node;
步骤503,辅共识节点若确定第i个区块的块高等于最高区块的块高加1,且第i个区块的父区块哈希值等于最高区块的哈希值,则确定第i个区块通过共识验证;Step 503: If the secondary consensus node determines that the block height of the i-th block is equal to the block height of the highest block plus 1, and the hash value of the parent block of the i-th block is equal to the hash value of the highest block, it determines The i-th block passes consensus verification;
步骤504,辅共识节点将第i个区块存储至辅共识节点的空块缓存中。In step 504, the auxiliary consensus node stores the i-th block in the empty block cache of the auxiliary consensus node.
为了更好的解释本发明实施例,以PBFT共识算法为例具体说明。首先对PBFT共识算法所涉及到的相关概念进行解释:In order to better explain the embodiments of the present invention, the PBFT consensus algorithm is taken as an example for specific description. First, explain the related concepts involved in the PBFT consensus algorithm:
(1)节点ID、节点索引(1) Node ID, node index
为了防止节点作恶,每个共识节点在PBFT共识过程中均对其发送的消息进行签名,对收到的消息包进行验证签名,因此每个节点均维护一份公私钥对,私钥用于对发送的消息进行签名,公钥作为节点ID,用于标识和验证签名。节点ID为共识节点签名公钥和共识节点唯一标识,一般是64字节二进制串,其他节点使用消息包发送者的节点ID对消息包进行验签。In order to prevent nodes from doing evil, each consensus node signs the messages it sends during the PBFT consensus process, and verifies and signs the received message packets. Therefore, each node maintains a public and private key pair, and the private key is used to The sent message is signed, and the public key is used as the node ID to identify and verify the signature. The node ID is the signature public key of the consensus node and the unique identification of the consensus node, which is generally a 64-byte binary string. Other nodes use the node ID of the message packet sender to verify the message packet.
考虑到节点ID很长,在共识消息中直接包含该字段会耗费部分网络带宽,因此,本发明实施例引入了节点索引。每个共识节点维护一份公共的共识节点列表,节点索引记录了 每个共识节点ID在这个列表中的位置,发送网络消息包时,只需要带上节点索引,其他节点即可以从公共的共识节点列表中索引出节点的ID,进而对消息进行验证签名。节点索引用于指示每个共识节点ID在这个公共节点ID列表中的位置。Considering that the node ID is very long, including this field directly in the consensus message will consume part of the network bandwidth. Therefore, the embodiment of the present invention introduces a node index. Each consensus node maintains a public consensus node list. The node index records the position of each consensus node ID in this list. When sending network message packets, only the node index is required, and other nodes can get from the public consensus. The node ID is indexed in the node list, and the message is verified and signed. The node index is used to indicate the position of each consensus node ID in this public node ID list.
(2)PBFT共识算法中的节点类型(2) Node types in the PBFT consensus algorithm
共识节点可以分为主共识节点(Leader/Primary节点)和副本节点(Replica节点,相当于本发明实施例中的辅共识节点)。其中,主共识节点负责将交易打包成区块和区块共识,每轮共识过程中有且仅有一个主共识节点,为了防止主共识节点伪造区块,每轮PBFT共识后,均会切换主共识节点。副本节点负责区块共识,每轮共识过程中可以有多个副本节点,每个副本节点的处理过程类似。具体实施中,可以根据预设的算法确定当前共识过程中的主共识节点,示例性的,设当前系统中包括N个共识节点,最新区块哈希为blockHash,则当前的主共识节点的索引可以为:blockHash%N。Consensus nodes can be divided into primary consensus nodes (Leader/Primary nodes) and replica nodes (Replica nodes, which are equivalent to secondary consensus nodes in the embodiment of the present invention). Among them, the master consensus node is responsible for packaging transactions into blocks and block consensus. There is and only one master consensus node during each round of consensus. In order to prevent the master consensus node from forging blocks, after each round of PBFT consensus, the master will switch Consensus node. The replica node is responsible for block consensus. There can be multiple replica nodes in each round of consensus, and the processing process of each replica node is similar. In specific implementation, the main consensus node in the current consensus process can be determined according to a preset algorithm. For example, assuming that the current system includes N consensus nodes, the latest block hash is blockHash, then the current main consensus node index Can be: blockHash%N.
进一步的,根据共识节点是否为恶意节点,还可以将共识节点划分为拜占庭节点和非拜占庭节点。其中,拜占庭节点理解为恶意节点,不能正常参与共识。设系统节点总数为3×f+1,则当拜占庭节点超过f后,系统无法正常共识。非拜占庭节点理解为诚实节点,可正常参与共识,设系统节点总数为3×f+1,则当非拜占庭节点不小于2×f+1时,系统可正常共识。Further, according to whether the consensus node is a malicious node, the consensus node can also be divided into Byzantine nodes and non-Byzantine nodes. Among them, Byzantine nodes are understood as malicious nodes and cannot normally participate in consensus. Assuming that the total number of system nodes is 3×f+1, when the Byzantine nodes exceed f, the system cannot reach a normal consensus. Non-Byzantine nodes are understood as honest nodes and can participate in the consensus normally. If the total number of system nodes is 3×f+1, when the non-Byzantine nodes are not less than 2×f+1, the system can agree normally.
(3)视图(view)(3) View (view)
PBFT共识算法使用视图记录每个节点的共识状态,相同视图节点维护相同的主共识节点和副本节点的节点列表。当主共识节点出现故障,会发生视图切换,若视图切换成功(例如至少2×f+1个节点达到相同视图),则根据新的视图选出新的主共识节点,由新的主共识节点开始出块,否则继续进行视图切换,直至全网大部分节点(大于等于2×f+1)达到一致视图。The PBFT consensus algorithm uses a view to record the consensus state of each node, and the same view node maintains the same node list of the master consensus node and the replica node. When the master consensus node fails, a view switch will occur. If the view switch is successful (for example, at least 2×f+1 nodes reach the same view), a new master consensus node will be selected based on the new view, and the new master consensus node will start Generate a block, otherwise continue to switch views until most of the nodes in the entire network (greater than or equal to 2×f+1) reach a consistent view.
结合上述描述,假设区块链系统中共有3×f+1个共识节点,当前区块链上的最高区块的区块高度为A,最高区块的哈希值为Hash(A),空块缓存中的最新空块索引值为B。则PBFT共识算法中空块处理、空块共识的流程可以如图6所示。Combining the above description, assuming that there are 3×f+1 consensus nodes in the blockchain system, the block height of the highest block on the current blockchain is A, and the hash value of the highest block is Hash(A), empty The index value of the latest empty block in the block cache is B. The process of empty block processing and empty block consensus in the PBFT consensus algorithm can be shown in Figure 6.
步骤601,主共识节点确定待生成区块为空块;Step 601: The master consensus node determines that the block to be generated is an empty block;
步骤602,主共识节点确定最新空块索引值B: Step 602, the master consensus node determines the latest empty block index value B:
若B为-1,则转向步骤603;If B is -1, go to step 603;
若B大于等于0,则转向步骤604;If B is greater than or equal to 0, go to step 604;
步骤603,确定当前空块缓存中不存在空块;Step 603: Determine that there are no empty blocks in the current empty block cache;
这种情况下,还可以获取区块链上最高区块的区块头,将待生成空块的父区块哈希设置为最高区块的哈希值,将待生成空块的块高设置为最高区块的块高加1,然后将待生成空块的空块索引值设置为0。In this case, you can also get the block header of the highest block on the blockchain, set the hash of the parent block of the empty block to be generated to the hash value of the highest block, and set the block height of the empty block to be generated to The block height of the highest block is increased by 1, and then the empty block index value of the empty block to be generated is set to 0.
步骤604,确定当前空块缓存中存在空块;Step 604: Determine that there are empty blocks in the current empty block cache;
这种情况下,还可以从空块缓存中读取最新空块,并将待生成空块的父区块哈希设置为最高区块的哈希值,将待生成空块的块高设置为最高区块的块高加1,将待生成空块的空块索引值设置为B+1,然后将待生成空块的父空块哈希值设置为最新空块的哈希值;In this case, you can also read the latest empty block from the empty block cache, set the hash of the parent block of the empty block to be generated to the hash value of the highest block, and set the block height of the empty block to be generated to The block height of the highest block is increased by 1, the empty block index value of the empty block to be generated is set to B+1, and then the hash value of the parent empty block to be generated is set to the hash value of the latest empty block;
步骤605,主共识节点打包空块,并将空块封装到准备包(Prepare包)内,广播给所有其他共识节点;In step 605, the master consensus node packs the empty block, encapsulates the empty block in a prepare package (Prepare package), and broadcasts it to all other consensus nodes;
步骤606,辅共识节点收到主共识节点广播的准备包后,对该准备包进行第一验证, 若验证通过,则转向步骤607,否则结束;Step 606: After receiving the preparation packet broadcast by the master consensus node, the auxiliary consensus node performs a first verification on the preparation packet, and if the verification is passed, it proceeds to step 607, otherwise it ends;
其中,对该准备包进行第一验证,具体可以包括:验证该准备包是否由主共识节点产生、是否为重复包(即是否收到重复的准备包)。对应的,第一验证通过,具体可以包括:该准备包是由主共识节点产生,且不为重复包。Wherein, performing the first verification on the preparation package may specifically include: verifying whether the preparation package is generated by the master consensus node and whether it is a repeated package (that is, whether a repeated preparation package is received). Correspondingly, the first verification is passed, which may specifically include: the preparation package is generated by the master consensus node and is not a duplicate package.
步骤607,辅共识节点获取准备包中的父区块哈希值、打包者索引、空块索引值、父空块哈希值;Step 607: The auxiliary consensus node obtains the parent block hash value, packager index, empty block index value, and parent empty block hash value in the prepared package;
步骤608,辅共识节点对该准备包进行第二验证,若验证通过,则转向步骤609,否则结束。In step 608, the secondary consensus node performs a second verification on the preparation packet, and if the verification is passed, it proceeds to step 609, otherwise it ends.
其中,对该准备包进行第二验证,具体可以包括:验证该准备包中的父区块哈希值是否为当前节点的区块链上最高区块的哈希值,准备包中的块高是否为当前节点的区块链上最高区块的块高加1,准备包中的打包者索引是否为当前节点已经确定的打包者索引,准备包中的空块索引值是否为当前节点空块缓存中的最新空块索引值加1,准备包中的父空块哈希值是否为当前节点空块缓存中最新空块的哈希值。此处,若该准备包中的空块为空块缓存中的第一个空块,则仅执行打包者索引、父区块哈希值、空块索引值、块高的验证。The second verification of the preparation package may specifically include: verifying whether the hash value of the parent block in the preparation package is the hash value of the highest block on the blockchain of the current node, and the block height in the preparation package Whether it is the block height of the highest block on the current node’s blockchain plus 1, whether the packager index in the prepared package is the packager index determined by the current node, and whether the empty block index value in the prepared package is the current node’s empty block The index value of the latest empty block in the cache is increased by 1, and the hash value of the parent empty block in the preparation package is the hash value of the latest empty block in the empty block cache of the current node. Here, if the empty block in the preparation package is the first empty block in the empty block cache, only the verification of the packer index, the hash value of the parent block, the empty block index value, and the block height are performed.
步骤609,辅共识节点确定准备包验证通过,则计算该空块的哈希值,并对哈希值进行签名后,将哈希值和签名封装在一起,构成签名包(SignReq包),广播给所有其他共识节点;In step 609, the auxiliary consensus node determines that the package verification is passed, and then calculates the hash value of the empty block, and after signing the hash value, the hash value and the signature are encapsulated together to form a signature package (SignReq package), and broadcast To all other consensus nodes;
步骤610,辅共识节点收集签名请求。 Step 610, the auxiliary consensus node collects the signature request.
具体的,若收集到超过2×f+1个来自不同共识节点、哈希值为空块哈希值的签名包,则向所有共识节点广播提交请求(CommitReq)。Specifically, if more than 2×f+1 signature packets from different consensus nodes whose hash value is the hash value of an empty block are collected, a submission request (CommitReq) is broadcast to all consensus nodes.
步骤611,辅共识节点收集提交请求,并将空块提交至空块缓存。Step 611: The auxiliary consensus node collects submission requests, and submits the empty block to the empty block cache.
具体的,若共识节点收集到超过2×f+1个来自不同共识节点、哈希值为空块哈希值的提交请求,则将空块提交至空块缓存。例如可以是在空块缓存中插入新表项,并更新最新空块索引值为B+1。Specifically, if the consensus node collects more than 2×f+1 submission requests from different consensus nodes whose hash value is the hash value of the empty block, the empty block is submitted to the empty block cache. For example, it can insert a new entry in the empty block cache and update the latest empty block index value to B+1.
上述实施例中,辅共识节点对接收到的第i个区块中的空块索引值、父空块哈希值、块高、父区块哈希值、打包者索引进行验证,能够实现第i个区块为空块时的共识验证。更进一步的,在有新的非空块存储至区块链上时,还会清除空块缓存中的空块,从而能够降低空块所占存储空间,提升磁盘利用效率。In the above embodiment, the secondary consensus node verifies the empty block index value, the parent empty block hash value, the block height, the parent block hash value, and the packager index in the received i-th block. Consensus verification when i blocks are empty. Furthermore, when a new non-empty block is stored on the blockchain, the empty block in the empty block cache will also be cleared, thereby reducing the storage space occupied by the empty block and improving disk utilization efficiency.
考虑区块链系统中各节点的性能不一,因此还可能存在区块链系统中节点的区块链数据不同步或空块缓存中数据不同步的情况,例如区块链系统中包括节点1和节点2,节点1中存储有10个空块,节点2中存储有5个空块,则节点1和节点2的空块缓存中数据不同步。又如,节点1中存储有10个非空块,节点2中存储有6个非空块,则节点1和节点2的区块链中数据不同步。这种情况下,为保障区块链系统中各节点中数据处于最新状态,则还需要对区块链系统中各节点执行同步操作。Considering that the performance of each node in the blockchain system is different, there may also be cases where the blockchain data of the nodes in the blockchain system is not synchronized or the data in the empty block cache is not synchronized, for example, the blockchain system includes node 1 As with node 2, there are 10 empty blocks stored in node 1 and 5 empty blocks stored in node 2, so the data in the empty block caches of node 1 and node 2 are not synchronized. For another example, if there are 10 non-empty blocks stored in node 1 and 6 non-empty blocks are stored in node 2, the data in the blockchains of node 1 and node 2 are not synchronized. In this case, in order to ensure that the data in each node in the blockchain system is in the latest state, it is also necessary to perform synchronization operations on each node in the blockchain system.
本发明实施例中,设定第一节点和第二节点,第一节点是区块链系统的多个节点中的任一个,第二节点是区块链系统的多个节点中除第一节点之外的任一个。第一节点和第二节点之间的数据同步过程可以参照如图7示出的流程,该流程中的执行主体即包括第一节点和第二节点,该流程包括:In the embodiment of the present invention, the first node and the second node are set. The first node is any one of the multiple nodes of the blockchain system, and the second node is the first node among the multiple nodes of the blockchain system. Any one other than. The data synchronization process between the first node and the second node can refer to the process shown in Fig. 7. The execution subject in the process includes the first node and the second node, and the process includes:
步骤701,第二节点定期的广播自己节点的状态信息。Step 701: The second node periodically broadcasts the status information of its own node.
其中,状态信息中包括第二节点的空块缓存中最新空块的空块索引值和第二节点的区 块链的最高区块的块高。Wherein, the status information includes the empty block index value of the latest empty block in the empty block cache of the second node and the block height of the highest block of the block chain of the second node.
如图8所示,具体实现过程中,第二节点定期的广播自己节点的状态信息,相当于第二节点将状态信息广播给区块链系统中的所有节点,每个节点会根据接收到的第二节点的状态信息判断是否需要从第二节点中同步数据。本发明实施例中仅以第二节点向第一节点广播状态信息为例说明。As shown in Figure 8, in the specific implementation process, the second node periodically broadcasts the status information of its own node, which is equivalent to the second node broadcasting the status information to all nodes in the blockchain system. Each node will The status information of the second node determines whether data needs to be synchronized from the second node. In the embodiment of the present invention, only the second node broadcasting status information to the first node is taken as an example for description.
步骤702,第一节点接收第二节点广播的状态信息。Step 702: The first node receives the status information broadcast by the second node.
步骤703,第一节点若确定第二节点的区块链的最高区块的块高等于第一节点的区块链的最高区块的块高,且第二节点的最新空块的空块索引值大于第一节点的最新空块的空块索引值,则从第二节点的空块缓存确定待同步空块。Step 703: If the first node determines that the block height of the highest block of the second node's blockchain is equal to the block height of the highest block of the first node's blockchain, and the empty block index of the latest empty block of the second node If the value is greater than the empty block index value of the latest empty block of the first node, the empty block to be synchronized is determined from the empty block cache of the second node.
此处,待同步空块指的是第二节点的空块缓存中空块索引值大于第一节点的最新空块的空块索引值的空块。举例来说,第二节点的空块缓存中存储有3个空块,空块索引值分别是1、2、3,第一节点的空块缓存中存储有1个空块,空块索引值为1,则可以确定出第一节点从第二节点中同步的待同步空块为空块索引值2的空块和空块索引值3的空块。Here, the empty block to be synchronized refers to an empty block whose empty block index value in the empty block cache of the second node is greater than the empty block index value of the latest empty block of the first node. For example, the empty block cache of the second node stores 3 empty blocks, the empty block index values are 1, 2, and 3 respectively, and the empty block cache of the first node stores 1 empty block, and the empty block index value If it is 1, it can be determined that the empty block to be synchronized that the first node synchronizes from the second node is an empty block with an empty block index value of 2 and an empty block with an empty block index value of 3.
步骤704,第一节点将待同步空块同步至第一节点的空块缓存中。Step 704: The first node synchronizes the empty block to be synchronized into the empty block cache of the first node.
如图9所示,具体实现过程中,第一节点会接收到多个节点广播的状态信息,也即第一节点可以同时向多个节点同步数据。本发明实施例中仅以第一节点向第二节点同步为例说明。为了避免向多个节点同步重复的数据,第一节点在同步数据时,还可以根据以下步骤进行重复性验证:As shown in FIG. 9, in the specific implementation process, the first node will receive the status information broadcast by multiple nodes, that is, the first node can synchronize data to multiple nodes at the same time. In the embodiment of the present invention, only the synchronization of the first node to the second node is taken as an example for description. In order to avoid synchronizing repeated data to multiple nodes, the first node can also perform repetitive verification according to the following steps when synchronizing data:
第一节点针对任一个待同步空块,获取该待同步空块的父空块哈希值和空块索引值,若确定待同步空块的父空块哈希值等于第一节点的空块缓存中最新空块的哈希值,且待同步空块的空块索引值等于第一节点的最新空块的空块索引值加1,则确定同步待同步空块至第一节点的空块缓存中。且,还可以对待同步空块的共识签名进行验证。For any empty block to be synchronized, the first node obtains the parent empty block hash value and the empty block index value of the empty block to be synchronized, if it is determined that the parent empty block hash value of the empty block to be synchronized is equal to the empty block of the first node The hash value of the latest empty block in the cache, and the empty block index value of the empty block to be synchronized is equal to the empty block index value of the latest empty block of the first node plus 1, then it is determined to synchronize the empty block to be synchronized to the empty block of the first node In the cache. Moreover, the consensus signature of the empty block to be synchronized can also be verified.
这种实施方式中,第一节点在进行重复性验证时,还可以验证待同步空块的父区块哈希值,也即,第一节点获取待同步空块中的父区块哈希值,确定该待同步空块中的父区块哈希值是否等于第一节点的区块链上的最高区块的哈希值,若是,则进一步确定父空块哈希值和空块索引值。In this embodiment, the first node may also verify the hash value of the parent block of the empty block to be synchronized when performing repeated verification, that is, the first node obtains the hash value of the parent block in the empty block to be synchronized , Determine whether the hash value of the parent block in the empty block to be synchronized is equal to the hash value of the highest block on the blockchain of the first node, and if so, further determine the hash value of the parent empty block and the index value of the empty block .
上述实施例的前提是第二节点的区块链的最高区块的块高等于第一节点的区块链的最高区块的块高,也即第一节点仅需要从第二节点中同步空块。但是还可能存在第一节点向第二节点中同步非空块的可能性。可选的,同步非空块的步骤在同步空块的步骤之前执行。第一节点若确定第二节点的区块链的最高区块的块高大于第一节点的区块链的最高区块的块高,则同步第二节点的区块链中高于第一节点的区块链的区块,且第一节点在区块同步后,清空第一节点的空块缓存。The premise of the above embodiment is that the block height of the highest block of the blockchain of the second node is equal to the block height of the highest block of the blockchain of the first node, that is, the first node only needs to synchronize the space from the second node. Piece. However, there may also be a possibility that the first node synchronizes non-empty blocks to the second node. Optionally, the step of synchronizing non-empty blocks is performed before the step of synchronizing empty blocks. If the first node determines that the block height of the highest block of the second node’s blockchain is greater than the block height of the highest block of the first node’s blockchain, then synchronize the second node’s blockchain to be higher than that of the first node Blocks of the blockchain, and the first node clears the empty block cache of the first node after the block is synchronized.
一种可实现的方式中,第一节点接收到第二节点的状态信息,先判断第二节点的区块链的最高区块的块高是否大于第一节点的区块链的最高区块的块高,若是,则第一节点先向第二节点请求非空块,并清除空块缓存。若第二节点的区块链的最高区块的块高等于第一节点的区块链的最高区块的块高,则再判断第二节点的空块缓存的最新空块索引值是否大于第一节点的空块缓存的最新空块索引值,若是,则向第二节点请求空块,此时需要进行如下四个验证:In an achievable way, the first node receives the status information of the second node, and first determines whether the block height of the highest block of the second node's blockchain is greater than that of the highest block of the first node's blockchain. If the block is high, the first node first requests a non-empty block from the second node and clears the empty block cache. If the block height of the highest block of the blockchain of the second node is equal to the block height of the highest block of the blockchain of the first node, then it is determined whether the latest empty block index value of the empty block cache of the second node is greater than that of the first node. The latest empty block index value of the empty block cache of one node. If it is, the empty block is requested from the second node. At this time, the following four verifications are required:
(1)待同步空块的父空块哈希值等于本地空块缓存中最新空块的哈希值;(1) The hash value of the parent empty block of the empty block to be synchronized is equal to the hash value of the latest empty block in the local empty block cache;
(2)待同步空块的空块索引值等于本地空块缓存中最新空块索引值加1;(2) The empty block index value of the empty block to be synchronized is equal to the latest empty block index value in the local empty block cache plus 1;
(3)待同步空块的父区块哈希值等于本地区块链中最高区块的哈希值;(3) The hash value of the parent block of the empty block to be synchronized is equal to the hash value of the highest block in the local blockchain;
(4)待同步空块的共识签名信息。(4) The consensus signature information of the empty block to be synchronized.
此外,第一节点若确定第二节点的区块链的最高区块的块高不大于第一节点的区块链的最高区块的块高,则不同步区块链上的区块。或者,第一节点若确定第二节点的空块缓存的最新空块索引值不大于第一节点的空块缓存的最新空块索引值,则不同步空块缓存中的空块。In addition, if the first node determines that the block height of the highest block of the second node's blockchain is not greater than the block height of the highest block of the first node's blockchain, the blocks on the blockchain are not synchronized. Alternatively, if the first node determines that the latest empty block index value of the empty block cache of the second node is not greater than the latest empty block index value of the empty block cache of the first node, then the empty blocks in the empty block cache are not synchronized.
上述实施例中,考虑区块链系统中各节点的性能不一,导致可能存在区块链系统中节点的区块链数据不同步或空块缓存中数据不同步的情况,因此,本申请针对不同情况提供节点间数据同步的实现方式,从而能够保证区块链系统中所有节点处于最新状态。且,节点在同步到非空块时,还会清空本地空块缓存中的空块,从而还能够降低空块所占存储空间,提升磁盘利用效率。In the above-mentioned embodiment, considering that the performance of each node in the blockchain system is different, the blockchain data of the nodes in the blockchain system may not be synchronized or the data in the empty block cache may not be synchronized. Therefore, this application is aimed at Different situations provide implementation methods for data synchronization between nodes, so as to ensure that all nodes in the blockchain system are in the latest state. In addition, when the node synchronizes to a non-empty block, it will also clear the empty block in the local empty block cache, which can also reduce the storage space occupied by the empty block and improve disk utilization efficiency.
基于同一发明构思,图10示例性的示出了本发明实施例提供的一种区块处理装置的结构,该装置可以执行区块处理方法的流程。其中,该装置适用于包括主共识节点和辅共识节点的区块链系统,所述区块链系统包括区块链和空块缓存,所述区块链中任一区块均不是空块,所述空块缓存用于存储空块。如图10所示,该装置包括:Based on the same inventive concept, FIG. 10 exemplarily shows the structure of a block processing device provided by an embodiment of the present invention, and the device can execute the flow of the block processing method. Wherein, the device is suitable for a blockchain system including a master consensus node and an auxiliary consensus node. The blockchain system includes a blockchain and an empty block cache, and any block in the blockchain is not an empty block, The empty block cache is used to store empty blocks. As shown in Figure 10, the device includes:
确定单元1001,用于在确定待生成的第i个区块为空块时,从所述空块缓存中确定最新空块的空块索引值和所述最新空块的哈希值;i、m为正整数,所述空块缓存中的空块是针对所述区块链中第m个区块之后生成的空块,且所述空块缓存中的空块在所述区块链中增加第m+1个区块时被清空;所述空块索引值用于指示所述空块缓存中各空块产生的先后;The determining unit 1001 is configured to determine the empty block index value of the latest empty block and the hash value of the latest empty block from the empty block cache when it is determined that the i-th block to be generated is an empty block; i, m is a positive integer, the empty block in the empty block cache is for the empty block generated after the mth block in the blockchain, and the empty block in the empty block cache is in the blockchain It is emptied when the m+1 th block is added; the empty block index value is used to indicate the generation sequence of each empty block in the empty block cache;
生成单元1002,用于生成所述第i个区块并将所述第i个区块广播至各辅共识节点;所述第i个区块中包括所述第i个区块的空块索引值和父空块哈希值,所述第i个区块的父空块哈希值是所述最新空块的哈希值,所述第i个区块的空块索引值是根据所述最新空块的空块索引值确定的;The generating unit 1002 is configured to generate the i-th block and broadcast the i-th block to each auxiliary consensus node; the i-th block includes the empty block index of the i-th block Value and the parent empty block hash value, the parent empty block hash value of the i-th block is the hash value of the latest empty block, and the empty block index value of the i-th block is based on the The empty block index value of the latest empty block is determined;
存储单元1003,用于在确定所述第i个区块通过共识验证后,将所述第i个区块存储至所述空块缓存中。The storage unit 1003 is configured to store the i-th block in the empty block cache after determining that the i-th block passes the consensus verification.
可选的,所述生成单元1002具体用于:获取所述区块链上最高区块的块高和哈希值,将所述最高区块的块高加1后确定为所述第i个区块的块高,将所述最高区块的哈希值确定为所述第i个区块的父区块哈希值,将所述第i个区块的块高、所述第i个区块的父区块哈希值、所述第i个区块的空块索引值和所述第i个区块的父空块哈希值打包至所述第i个区块。Optionally, the generating unit 1002 is specifically configured to: obtain the block height and hash value of the highest block on the blockchain, and determine the i-th block height after adding 1 to the block height of the highest block The block height of the block, the hash value of the highest block is determined as the hash value of the parent block of the i-th block, the block height of the i-th block, the i-th block The parent block hash value of the block, the empty block index value of the i-th block, and the parent empty block hash value of the i-th block are packed into the i-th block.
可选的,所述生成单元1002在所述确定单元1001确定所述待生成的第i个区块不是空块时,还用于:获取所述区块链上最高区块的块高和哈希值,将所述最高区块的块高加1后确定为所述第i个区块的块高,将所述最高区块的哈希值确定为所述第i个区块的父区块哈希值,将所述第i个区块的块高、所述第i个区块的父区块哈希值打包至所述第i个区块。Optionally, when the determining unit 1001 determines that the i-th block to be generated is not an empty block, the generating unit 1002 is further configured to: obtain the block height and the block height of the highest block on the blockchain. Hope value, the block height of the highest block is added by 1 to determine the block height of the i-th block, and the hash value of the highest block is determined as the parent area of the i-th block The block hash value packs the block height of the i-th block and the parent block hash value of the i-th block into the i-th block.
可选的,所述空块缓存中包括最新空块索引值,所述最新空块索引值为所述最新空块的空块索引值。这种情况下,所述确定单元1001具体用于:根据所述最新空块索引值,从所述空块缓存中确定所述最新空块并获取所述最新空块的空块索引值和所述最新空块的哈希值。对应的,所述存储单元1003还用于:在将所述第i个区块存储至所述空块缓存中之后,将所述最新空块索引值加1。Optionally, the empty block cache includes the latest empty block index value, and the latest empty block index value is the empty block index value of the latest empty block. In this case, the determining unit 1001 is specifically configured to: determine the latest empty block from the empty block cache according to the latest empty block index value and obtain the empty block index value of the latest empty block and all State the hash value of the latest empty block. Correspondingly, the storage unit 1003 is further configured to: after storing the i-th block in the empty block cache, add 1 to the latest empty block index value.
基于同一发明构思,图11示例性的示出了本发明实施例提供的一种区块共识装置的结构,该装置可以执行区块共识方法的流程。其中,该装置适用于包括主共识节点和辅共识 节点的区块链系统,所述区块链系统包括区块链和空块缓存,所述区块链中任一区块均不是空块,所述空块缓存用于存储空块,所述空块缓存中的空块是针对所述区块链中第m个区块之后生成的空块且所述空块缓存中的空块在所述区块链中增加第m+1个区块时被清空,所述空块包括空块索引值和父空块哈希值,所述空块索引值用于指示所述空块缓存中各空块产生的先后,m为正整数。如图11所示,该装置包括:Based on the same inventive concept, FIG. 11 exemplarily shows the structure of a block consensus device provided by an embodiment of the present invention, which can execute the process of the block consensus method. Wherein, the device is suitable for a blockchain system including a master consensus node and an auxiliary consensus node. The blockchain system includes a blockchain and an empty block cache, and any block in the blockchain is not an empty block, The empty block cache is used to store empty blocks, the empty blocks in the empty block cache are for empty blocks generated after the mth block in the blockchain, and the empty blocks in the empty block cache are in all When the m+1 th block is added to the blockchain, the empty block includes an empty block index value and a parent empty block hash value, and the empty block index value is used to indicate each of the empty block caches The sequence of empty blocks, m is a positive integer. As shown in Figure 11, the device includes:
接收单元1101,用于接收所述主共识节点广播的第i个区块;i为正整数;The receiving unit 1101 is configured to receive the i-th block broadcast by the master consensus node; i is a positive integer;
确定单元1102,用于从所述第i个区块中确定所述第i个区块的空块索引值和所述第i个区块的父空块哈希值,以及从所述辅共识节点的空块缓存中确定第一空块的哈希值和所述第一空块的空块索引值;所述第一空块是所述辅共识节点的空块缓存中的最新空块;The determining unit 1102 is configured to determine the empty block index value of the i-th block and the hash value of the parent empty block of the i-th block from the i-th block, and from the auxiliary consensus Determine the hash value of the first empty block and the empty block index value of the first empty block in the empty block cache of the node; the first empty block is the latest empty block in the empty block cache of the secondary consensus node;
存储单元1103,用于若确定所述第i个区块通过共识验证,则将所述第i个区块存储至所述辅共识节点的空块缓存中;所述第i个区块通过共识验证包括所述第i个区块的空块索引值与所述第一空块的空块索引值符合预设要求,且确定所述第i个区块的父空块哈希值等于所述第一空块的哈希值。The storage unit 1103 is configured to store the i-th block in the empty block cache of the auxiliary consensus node if it is determined that the i-th block passes the consensus verification; the i-th block passes the consensus Verify that the empty block index value of the i-th block and the empty block index value of the first empty block meet the preset requirements, and it is determined that the hash value of the parent empty block of the i-th block is equal to the The hash value of the first empty block.
可选的,所述确定单元1102还用于:从所述第i个区块中确定所述第i个区块的块高和所述第i个区块的父区块哈希值,从所述辅共识节点的区块链中确定最高区块的块高和所述最高区块的哈希值。对应的,所述第i个区块通过共识验证,还包括:所述第i个区块的块高等于所述最高区块的块高加1,且所述第i个区块的父区块哈希值等于所述最高区块的哈希值。Optionally, the determining unit 1102 is further configured to determine the block height of the i-th block and the hash value of the parent block of the i-th block from the i-th block, from The block height of the highest block and the hash value of the highest block are determined in the blockchain of the auxiliary consensus node. Correspondingly, the i-th block passes the consensus verification, further comprising: the block height of the i-th block is equal to the block height of the highest block plus 1, and the parent area of the i-th block The block hash value is equal to the hash value of the highest block.
可选的,所述确定单元1102还用于:从所述第i个区块中确定所述第i个区块的空块索引值为预设值,且所述第i个区块的父空块哈希值为空值,从所述第i个区块中确定所述第i个区块的块高和所述第i个区块的父区块哈希值,从所述辅共识节点的区块链中确定最高区块的块高和所述最高区块的哈希值,若确定所述第i个区块的块高等于所述最高区块的块高加1,且所述第i个区块的父区块哈希值等于所述最高区块的哈希值,则确定所述第i个区块通过所述共识验证。Optionally, the determining unit 1102 is further configured to: determine from the i-th block that the empty block index value of the i-th block is a preset value, and the parent of the i-th block The hash value of an empty block is a null value, the block height of the i-th block and the hash value of the parent block of the i-th block are determined from the i-th block, and the auxiliary consensus Determine the block height of the highest block and the hash value of the highest block in the node’s blockchain, if it is determined that the block height of the i-th block is equal to the block height of the highest block plus 1, and so If the hash value of the parent block of the i-th block is equal to the hash value of the highest block, it is determined that the i-th block passes the consensus verification.
基于同一发明构思,图12示例性的示出了本发明实施例提供的一种区块同步装置的结构,该装置可以执行区块同步方法的流程。其中,该装置适用于包括多个节点的区块链系统,所述区块链系统包括区块链和空块缓存,所述区块链中任一区块均不是空块,所述空块缓存用于存储空块,所述空块缓存中的空块是针对所述区块链中第m个区块之后生成的空块且所述空块缓存中的空块在所述区块链中增加第m+1个区块时被清空,所述多个节点包括第一节点和第二节点,所述第一节点是所述多个节点中的任一个,所述第二节点是所述多个节点中除所述第一节点之外的任一个,m为正整数。如图12所示,该装置包括:Based on the same inventive concept, FIG. 12 exemplarily shows the structure of a block synchronization device provided by an embodiment of the present invention, and the device can execute the process of the block synchronization method. Wherein, the device is suitable for a blockchain system including multiple nodes. The blockchain system includes a blockchain and an empty block cache. Any block in the blockchain is not an empty block, and the empty block The cache is used to store empty blocks, the empty blocks in the empty block cache are for empty blocks generated after the mth block in the blockchain, and the empty blocks in the empty block cache are in the blockchain It is cleared when the m+1 th block is added to it, the multiple nodes include a first node and a second node, the first node is any one of the multiple nodes, and the second node is all For any one of the plurality of nodes except the first node, m is a positive integer. As shown in Figure 12, the device includes:
接收单元1201,用于接收所述第二节点广播的状态信息;所述状态信息包括所述第二节点的空块缓存中最新空块的空块索引值和所述第二节点的区块链的最高区块的块高;The receiving unit 1201 is configured to receive status information broadcast by the second node; the status information includes the empty block index value of the latest empty block in the empty block cache of the second node and the blockchain of the second node The block height of the highest block;
确定单元1202,用于若确定所述第二节点的区块链的最高区块的块高等于所述第一节点的区块链的最高区块的块高且所述第二节点的最新空块的空块索引值大于所述第一节点的最新空块的空块索引值,则从所述第二节点的空块缓存中确定待同步空块;所述待同步空块是所述第二节点的空块缓存中空块索引值大于所述第一节点的最新空块的空块索引值的空块;The determining unit 1202 is configured to determine that the block height of the highest block of the blockchain of the second node is equal to the block height of the highest block of the blockchain of the first node and the latest free space of the second node If the empty block index value of the block is greater than the empty block index value of the latest empty block of the first node, the empty block to be synchronized is determined from the empty block cache of the second node; the empty block to be synchronized is the first An empty block whose empty block index value is greater than the empty block index value of the latest empty block of the first node in the empty block cache of the second node;
同步单元1203,用于将所述待同步空块同步至所述第一节点的空块缓存中。The synchronization unit 1203 is configured to synchronize the empty block to be synchronized to the empty block cache of the first node.
可选的,所述同步单元1203具体用于:针对任一个待同步空块,获取所述待同步空块 的父空块哈希值和空块索引值,若确定所述待同步空块的父空块哈希值等于所述第一节点的空块缓存中最新空块的哈希值,且所述待同步空块的空块索引值等于所述第一节点的最新空块的空块索引值加1,则确定同步所述待同步空块至所述第一节点的空块缓存中。Optionally, the synchronization unit 1203 is specifically configured to: for any empty block to be synchronized, obtain the parent empty block hash value and the empty block index value of the empty block to be synchronized, and if it is determined that the empty block to be synchronized is The hash value of the parent empty block is equal to the hash value of the latest empty block in the empty block cache of the first node, and the empty block index value of the empty block to be synchronized is equal to the empty block of the latest empty block of the first node When the index value is increased by 1, it is determined to synchronize the empty block to be synchronized to the empty block cache of the first node.
可选的,所述待同步空块中包括父区块哈希值。这种情况下,所述同步单元1203在确定同步所述待同步空块至所述第一节点的空块缓存中之前,还用于:确定所述待同步空块中父区块哈希值是否等于所述第一节点的区块链上的最高区块的哈希值。Optionally, the empty block to be synchronized includes the hash value of the parent block. In this case, before determining to synchronize the empty block to be synchronized to the empty block cache of the first node, the synchronization unit 1203 is further configured to: determine the hash value of the parent block in the empty block to be synchronized Whether it is equal to the hash value of the highest block on the blockchain of the first node.
可选的,所述状态信息还包括所述第二节点的区块链的块高。这种情况下,所述同步单元1203在从所述第二节点的空块缓存中确定待同步空块之前,还用于:若确定所述第二节点的区块链的最高区块的块高大于所述第一节点的区块链的最高区块的块高,则同步所述第二节点的区块链中高于所述第一节点的区块链的区块,在所述第一节点的区块链的区块同步后,清空所述第一节点的空块缓存。Optionally, the status information further includes the block height of the blockchain of the second node. In this case, before determining the empty block to be synchronized from the empty block cache of the second node, the synchronization unit 1203 is further configured to: if the block of the highest block of the blockchain of the second node is determined If the height is greater than the block height of the highest block of the blockchain of the first node, the block of the second node’s blockchain that is higher than the block of the first node’s blockchain will be synchronized in the first node’s blockchain. After the blocks of the node's blockchain are synchronized, the empty block cache of the first node is cleared.
基于同一发明构思,本发明实施例还提供了一种计算设备,包括:Based on the same inventive concept, an embodiment of the present invention also provides a computing device, including:
存储器,用于存储程序指令;Memory, used to store program instructions;
处理器,用于调用所述存储器中存储的程序指令,按照获得的程序执行如图2至图9中任一项所述的区块处理方法、区块共识方法、区块同步方法。The processor is configured to call the program instructions stored in the memory, and execute the block processing method, block consensus method, and block synchronization method described in any one of FIGS. 2 to 9 according to the obtained program.
基于同一发明构思,本发明实施例还提供了一种计算机可读非易失性存储介质,包括计算机可读指令,当计算机读取并执行所述计算机可读指令时,使得计算机执行如图2至图9中任一项所述的区块处理方法、区块共识方法、区块同步方法。Based on the same inventive concept, embodiments of the present invention also provide a computer-readable non-volatile storage medium, including computer-readable instructions, when the computer reads and executes the computer-readable instructions, the computer executes To the block processing method, block consensus method, and block synchronization method described in any one of FIG. 9.
本发明是参照根据本发明实施例的方法、设备(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。The present invention is described with reference to flowcharts and/or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and/or block in the flowchart and/or block diagram, and the combination of processes and/or blocks in the flowchart and/or block diagram can be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing equipment to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing equipment are generated It is a device that realizes the functions specified in one process or multiple processes in the flowchart and/or one block or multiple blocks in the block diagram.
这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。These computer program instructions can also be stored in a computer-readable memory that can guide a computer or other programmable data processing equipment to work in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture including the instruction device. The device implements the functions specified in one process or multiple processes in the flowchart and/or one block or multiple blocks in the block diagram.
这些计算机程序指令也可装载到计算机或其他可编程数据处理设备上,使得在计算机或其他可编程设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。These computer program instructions can also be loaded on a computer or other programmable data processing equipment, so that a series of operation steps are executed on the computer or other programmable equipment to produce computer-implemented processing, so as to execute on the computer or other programmable equipment. The instructions provide steps for implementing functions specified in a flow or multiple flows in the flowchart and/or a block or multiple blocks in the block diagram.
尽管已描述了本发明的优选实施例,但本领域内的技术人员一旦得知了基本创造性概念,则可对这些实施例作出另外的变更和修改。所以,所附权利要求意欲解释为包括优选实施例以及落入本发明范围的所有变更和修改。Although the preferred embodiments of the present invention have been described, those skilled in the art can make additional changes and modifications to these embodiments once they learn the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of the present invention.
显然,本领域的技术人员可以对本发明进行各种改动和变型而不脱离本发明的精神和范围。这样,倘若本发明的这些修改和变型属于本发明权利要求及其等同技术的范围之内,则本发明也意图包含这些改动和变型在内。Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. In this way, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalent technologies, the present invention is also intended to include these modifications and variations.

Claims (24)

  1. 一种区块处理方法,其特征在于,适用于包括主共识节点和辅共识节点的区块链系统;所述区块链系统包括区块链和空块缓存;所述区块链中任一区块均不是空块;所述空块缓存用于存储空块;A block processing method, characterized in that it is suitable for a block chain system including a main consensus node and an auxiliary consensus node; the block chain system includes a block chain and an empty block cache; any one of the block chains None of the blocks are empty blocks; the empty block cache is used to store empty blocks;
    所述方法包括:The method includes:
    所述主共识节点在确定待生成的第i个区块为空块时,从所述空块缓存中确定最新空块的空块索引值和所述最新空块的哈希值;所述空块缓存中的空块是针对所述区块链中第m个区块之后生成的空块且所述空块缓存中的空块在所述区块链中增加第m+1个区块时被清空;所述空块索引值用于指示所述空块缓存中各空块产生的先后;i为正整数,m为正整数;When determining that the i-th block to be generated is an empty block, the master consensus node determines the empty block index value of the latest empty block and the hash value of the latest empty block from the empty block cache; The empty block in the block cache refers to the empty block generated after the mth block in the blockchain and the empty block in the empty block cache adds the m+1th block to the blockchain Is emptied; the empty block index value is used to indicate the sequence of each empty block in the empty block cache; i is a positive integer, and m is a positive integer;
    所述主共识节点生成所述第i个区块并将所述第i个区块广播至各辅共识节点,所述第i个区块中包括所述第i个区块的空块索引值和父空块哈希值,所述第i个区块的父空块哈希值是所述最新空块的哈希值;所述第i个区块的空块索引值是根据所述最新空块的空块索引值确定的;The main consensus node generates the i-th block and broadcasts the i-th block to each auxiliary consensus node, and the i-th block includes the empty block index value of the i-th block And the parent empty block hash value, the parent empty block hash value of the i-th block is the hash value of the latest empty block; the empty block index value of the i-th block is based on the latest The empty block index value of the empty block is determined;
    所述主共识节点在确定所述第i个区块通过共识验证后,将所述第i个区块存储至所述空块缓存中。After determining that the i-th block passes the consensus verification, the master consensus node stores the i-th block in the empty block cache.
  2. 如权利要求1所述的方法,其特征在于,所述主共识节点生成所述第i个区块,包括:The method according to claim 1, wherein said master consensus node generating said i-th block comprises:
    所述主共识节点获取所述区块链上最高区块的块高和哈希值;将所述最高区块的块高加1后确定为所述第i个区块的块高,将所述最高区块的哈希值确定为所述第i个区块的父区块哈希值;The master consensus node obtains the block height and hash value of the highest block on the blockchain; adds 1 to the block height of the highest block and determines it as the block height of the i-th block. The hash value of the highest block is determined to be the hash value of the parent block of the i-th block;
    所述主共识节点将所述第i个区块的块高、所述第i个区块的父区块哈希值、所述第i个区块的空块索引值和所述第i个区块的父空块哈希值打包至所述第i个区块。The master consensus node calculates the block height of the i-th block, the hash value of the parent block of the i-th block, the empty block index value of the i-th block, and the i-th block The hash value of the parent empty block of the block is packed into the i-th block.
  3. 如权利要求1所述的方法,其特征在于,还包括:The method of claim 1, further comprising:
    所述主共识节点在确定所述待生成的第i个区块不是空块时,则获取所述区块链上最高区块的块高和哈希值;将所述最高区块的块高加1后确定为所述第i个区块的块高,将所述最高区块的哈希值确定为所述第i个区块的父区块哈希值;When the master consensus node determines that the i-th block to be generated is not an empty block, it obtains the block height and hash value of the highest block on the blockchain; and the block height of the highest block After adding 1, it is determined as the block height of the i-th block, and the hash value of the highest block is determined as the hash value of the parent block of the i-th block;
    所述主共识节点将所述第i个区块的块高、所述第i个区块的父区块哈希值打包至所述第i个区块。The master consensus node packs the block height of the i-th block and the hash value of the parent block of the i-th block into the i-th block.
  4. 如权利要求1所述的方法,其特征在于,所述空块缓存中包括最新空块索引值,所述最新空块索引值为所述最新空块的空块索引值;The method according to claim 1, wherein the empty block cache includes a latest empty block index value, and the latest empty block index value is the empty block index value of the latest empty block;
    所述主共识节点从所述空块缓存中确定最新空块的空块索引值和所述最新空块的哈希值,包括:The master consensus node determining the empty block index value of the latest empty block and the hash value of the latest empty block from the empty block cache includes:
    所述主共识节点根据所述最新空块索引值,从所述空块缓存中确定所述最新空块并获取所述最新空块的空块索引值和所述最新空块的哈希值;The master consensus node determines the latest empty block from the empty block cache according to the latest empty block index value and obtains the empty block index value of the latest empty block and the hash value of the latest empty block;
    所述主共识节点在将所述第i个区块存储至所述空块缓存中之后,还包括:After the master consensus node stores the i-th block in the empty block cache, the method further includes:
    所述主共识节点将所述最新空块索引值加1。The master consensus node adds 1 to the index value of the latest empty block.
  5. 一种区块共识方法,其特征在于,适用于包括主共识节点和辅共识节点的区块链系统;所述区块链系统包括区块链和空块缓存;所述区块链中任一区块均不是空块;所述 空块缓存用于存储空块;所述空块缓存中的空块是针对所述区块链中第m个区块之后生成的空块且所述空块缓存中的空块在所述区块链中增加第m+1个区块时被清空;所述空块包括空块索引值和父空块哈希值;所述空块索引值用于指示所述空块缓存中各空块产生的先后;m为正整数;A block consensus method, characterized in that it is suitable for a block chain system including a main consensus node and an auxiliary consensus node; the block chain system includes a block chain and an empty block cache; any one of the block chains Blocks are not empty blocks; the empty block cache is used to store empty blocks; the empty block in the empty block cache is for the empty block generated after the mth block in the blockchain and the empty block The empty block in the cache is emptied when the m+1 th block is added to the blockchain; the empty block includes an empty block index value and a parent empty block hash value; the empty block index value is used to indicate The sequence of the generation of each empty block in the empty block cache; m is a positive integer;
    所述方法包括:The method includes:
    所述辅共识节点接收所述主共识节点广播的第i个区块;i为正整数;The secondary consensus node receives the i-th block broadcast by the main consensus node; i is a positive integer;
    所述辅共识节点从所述第i个区块中确定所述第i个区块的空块索引值和所述第i个区块的父空块哈希值;The secondary consensus node determines the empty block index value of the i-th block and the hash value of the parent empty block of the i-th block from the i-th block;
    所述辅共识节点从所述辅共识节点的空块缓存中确定第一空块的哈希值和所述第一空块的空块索引值;所述第一空块是所述辅共识节点的空块缓存中的最新空块;The auxiliary consensus node determines the hash value of the first empty block and the empty block index value of the first empty block from the empty block cache of the auxiliary consensus node; the first empty block is the auxiliary consensus node The latest empty block in the empty block cache;
    所述辅共识节点若确定所述第i个区块通过共识验证,则将所述第i个区块存储至所述辅共识节点的空块缓存中;所述第i个区块通过共识验证包括所述第i个区块的空块索引值与所述第一空块的空块索引值符合预设要求,且确定所述第i个区块的父空块哈希值等于所述第一空块的哈希值。If the auxiliary consensus node determines that the i-th block passes the consensus verification, the i-th block is stored in the empty block cache of the auxiliary consensus node; the i-th block passes the consensus verification Including the empty block index value of the i-th block and the empty block index value of the first empty block meet the preset requirements, and it is determined that the hash value of the parent empty block of the i-th block is equal to the The hash value of an empty block.
  6. 如权利要求5所述的方法,其特征在于,所述方法还包括:The method of claim 5, wherein the method further comprises:
    所述辅共识节点从所述第i个区块中确定所述第i个区块的块高和所述第i个区块的父区块哈希值;The auxiliary consensus node determines the block height of the i-th block and the hash value of the parent block of the i-th block from the i-th block;
    所述辅共识节点从所述辅共识节点的区块链中确定最高区块的块高和所述最高区块的哈希值;The auxiliary consensus node determines the block height of the highest block and the hash value of the highest block from the blockchain of the auxiliary consensus node;
    所述第i个区块通过共识验证,还包括:The i-th block passes consensus verification, and further includes:
    所述第i个区块的块高等于所述最高区块的块高加1,且所述第i个区块的父区块哈希值等于所述最高区块的哈希值。The block height of the i-th block is equal to the block height of the highest block plus 1, and the hash value of the parent block of the i-th block is equal to the hash value of the highest block.
  7. 如权利要求5所述的方法,其特征在于,所述方法还包括:The method of claim 5, wherein the method further comprises:
    所述辅共识节点从所述第i个区块中确定所述第i个区块的空块索引值为预设值,且所述第i个区块的父空块哈希值为空值;The secondary consensus node determines from the i-th block that the empty block index value of the i-th block is a preset value, and the hash value of the parent empty block of the i-th block is a null value ;
    所述辅共识节点从所述第i个区块中确定所述第i个区块的块高和所述第i个区块的父区块哈希值;The auxiliary consensus node determines the block height of the i-th block and the hash value of the parent block of the i-th block from the i-th block;
    所述辅共识节点从所述辅共识节点的区块链中确定最高区块的块高和所述最高区块的哈希值;The auxiliary consensus node determines the block height of the highest block and the hash value of the highest block from the blockchain of the auxiliary consensus node;
    所述辅共识节点若确定所述第i个区块的块高等于所述最高区块的块高加1,且所述第i个区块的父区块哈希值等于所述最高区块的哈希值,则确定所述第i个区块通过所述共识验证;If the secondary consensus node determines that the block height of the i-th block is equal to the block height of the highest block plus 1, and the hash value of the parent block of the i-th block is equal to the highest block The hash value of, it is determined that the i-th block passes the consensus verification;
    所述辅共识节点将所述第i个区块存储至所述辅共识节点的空块缓存中。The auxiliary consensus node stores the i-th block in the empty block cache of the auxiliary consensus node.
  8. 一种区块同步方法,其特征在于,适用于包括多个节点的区块链系统;所述区块链系统包括区块链和空块缓存;所述区块链中任一区块均不是空块;所述空块缓存用于存储空块;所述空块缓存中的空块是针对所述区块链中第m个区块之后生成的空块且所述空块缓存中的空块在所述区块链中增加第m+1个区块时被清空;所述多个节点包括第一节点和第二节点,所述第一节点是所述多个节点中的任一个,所述第二节点是所述多个节点中除所述第一节点之外的任一个;m为正整数;A block synchronization method, characterized in that it is suitable for a block chain system including multiple nodes; the block chain system includes a block chain and an empty block cache; any block in the block chain is not Empty blocks; the empty block cache is used to store empty blocks; the empty blocks in the empty block cache are for empty blocks generated after the mth block in the blockchain and the empty block cache is empty A block is emptied when the m+1 th block is added to the blockchain; the multiple nodes include a first node and a second node, and the first node is any one of the multiple nodes, The second node is any one of the plurality of nodes except the first node; m is a positive integer;
    所述方法包括:The method includes:
    所述第一节点接收所述第二节点广播的状态信息;所述状态信息包括所述第二节点的空块缓存中最新空块的空块索引值和所述第二节点的区块链的最高区块的块高;The first node receives the status information broadcast by the second node; the status information includes the empty block index value of the latest empty block in the empty block cache of the second node and the block chain value of the second node The block height of the highest block;
    所述第一节点若确定所述第二节点的区块链的最高区块的块高等于所述第一节点的区块链的最高区块的块高,且所述第二节点的最新空块的空块索引值大于所述第一节点的最新空块的空块索引值,则从所述第二节点的空块缓存中确定待同步空块;所述待同步空块是所述第二节点的空块缓存中空块索引值大于所述第一节点的最新空块的空块索引值的空块;If the first node determines that the block height of the highest block of the block chain of the second node is equal to the block height of the highest block of the block chain of the first node, and the latest empty block of the second node If the empty block index value of the block is greater than the empty block index value of the latest empty block of the first node, the empty block to be synchronized is determined from the empty block cache of the second node; the empty block to be synchronized is the first An empty block whose empty block index value is greater than the empty block index value of the latest empty block of the first node in the empty block cache of the second node;
    所述第一节点将所述待同步空块同步至所述第一节点的空块缓存中。The first node synchronizes the empty block to be synchronized into the empty block cache of the first node.
  9. 如权利要求8所述的方法,其特征在于,所述第一节点将所述待同步空块同步至所述第一节点的空块缓存中,包括:The method according to claim 8, wherein the first node synchronizing the empty block to be synchronized into the empty block cache of the first node comprises:
    所述第一节点针对任一个待同步空块,获取所述待同步空块的父空块哈希值和空块索引值;For any empty block to be synchronized, the first node obtains the hash value of the parent empty block and the empty block index value of the empty block to be synchronized;
    所述第一节点若确定所述待同步空块的父空块哈希值等于所述第一节点的空块缓存中最新空块的哈希值,且所述待同步空块的空块索引值等于所述第一节点的最新空块的空块索引值加1,则确定同步所述待同步空块至所述第一节点的空块缓存中。If the first node determines that the hash value of the parent empty block of the empty block to be synchronized is equal to the hash value of the latest empty block in the empty block cache of the first node, and the empty block index of the empty block to be synchronized If the value is equal to the empty block index value of the latest empty block of the first node plus 1, it is determined to synchronize the empty block to be synchronized to the empty block cache of the first node.
  10. 如权利要求9所述的方法,其特征在于,所述待同步空块中包括父区块哈希值;The method according to claim 9, wherein the empty block to be synchronized includes the hash value of the parent block;
    所述第一节点确定同步所述待同步空块至所述第一节点的空块缓存中之前,还包括:Before the first node determines to synchronize the empty block to be synchronized to the empty block cache of the first node, the method further includes:
    所述第一节点确定所述待同步空块中父区块哈希值是否等于所述第一节点的区块链上的最高区块的哈希值。The first node determines whether the hash value of the parent block in the empty block to be synchronized is equal to the hash value of the highest block on the blockchain of the first node.
  11. 如权利要求8所述的方法,其特征在于,所述状态信息还包括所述第二节点的区块链的块高;The method according to claim 8, wherein the state information further includes the block height of the block chain of the second node;
    所述第一节点在从所述第二节点的空块缓存确定待同步空块之前,还包括:Before the first node determines the empty block to be synchronized from the empty block cache of the second node, the method further includes:
    所述第一节点若确定所述第二节点的区块链的最高区块的块高大于所述第一节点的区块链的最高区块的块高,则同步所述第二节点的区块链中高于所述第一节点的区块链的区块;If the first node determines that the block height of the highest block of the blockchain of the second node is greater than the block height of the highest block of the blockchain of the first node, then synchronize the zone of the second node Blocks in the block chain that are higher than the block chain of the first node;
    所述第一节点在所述第一节点的区块链的区块同步后,清空所述第一节点的空块缓存。The first node clears the empty block cache of the first node after the blocks of the blockchain of the first node are synchronized.
  12. 一种区块处理装置,其特征在于,适用于包括主共识节点和辅共识节点的区块链系统;所述区块链系统包括区块链和空块缓存;所述区块链中任一区块均不是空块;所述空块缓存用于存储空块;A block processing device, characterized in that it is suitable for a block chain system including a main consensus node and an auxiliary consensus node; the block chain system includes a block chain and an empty block cache; any one of the block chains None of the blocks are empty blocks; the empty block cache is used to store empty blocks;
    所述装置包括:The device includes:
    确定单元,用于在确定待生成的第i个区块为空块时,从所述空块缓存中确定最新空块的空块索引值和所述最新空块的哈希值;所述空块缓存中的空块是针对所述区块链中第m个区块之后生成的空块且所述空块缓存中的空块在所述区块链中增加第m+1个区块时被清空;所述空块索引值用于指示所述空块缓存中各空块产生的先后;i为正整数,m为正整数;The determining unit is configured to determine the empty block index value of the latest empty block and the hash value of the latest empty block from the empty block cache when it is determined that the i-th block to be generated is an empty block; The empty block in the block cache refers to the empty block generated after the mth block in the blockchain and the empty block in the empty block cache adds the m+1th block to the blockchain Is emptied; the empty block index value is used to indicate the sequence of each empty block in the empty block cache; i is a positive integer, and m is a positive integer;
    生成单元,用于生成所述第i个区块并将所述第i个区块广播至各辅共识节点,所述第i个区块中包括所述第i个区块的空块索引值和父空块哈希值,所述第i个区块的父空块哈希值是所述最新空块的哈希值;所述第i个区块的空块索引值是根据所述最新空块的空块索引值确定的;A generating unit, configured to generate the i-th block and broadcast the i-th block to each auxiliary consensus node, and the i-th block includes the empty block index value of the i-th block And the parent empty block hash value, the parent empty block hash value of the i-th block is the hash value of the latest empty block; the empty block index value of the i-th block is based on the latest The empty block index value of the empty block is determined;
    存储单元,用于在确定所述第i个区块通过共识验证后,将所述第i个区块存储至所 述空块缓存中。The storage unit is configured to store the i-th block in the empty block cache after determining that the i-th block passes the consensus verification.
  13. 如权利要求12所述的装置,其特征在于,所述生成单元具体用于:The device according to claim 12, wherein the generating unit is specifically configured to:
    获取所述区块链上最高区块的块高和哈希值;将所述最高区块的块高加1后确定为所述第i个区块的块高,将所述最高区块的哈希值确定为所述第i个区块的父区块哈希值;Obtain the block height and hash value of the highest block on the blockchain; add 1 to the block height of the highest block and determine it as the block height of the i-th block. The hash value is determined as the hash value of the parent block of the i-th block;
    将所述第i个区块的块高、所述第i个区块的父区块哈希值、所述第i个区块的空块索引值和所述第i个区块的父空块哈希值打包至所述第i个区块。The block height of the i-th block, the hash value of the parent block of the i-th block, the empty block index value of the i-th block, and the parent empty of the i-th block The block hash value is packed into the i-th block.
  14. 如权利要求12所述的装置,其特征在于,所述生成单元还用于:The device according to claim 12, wherein the generating unit is further configured to:
    在所述确定单元确定所述待生成的第i个区块不是空块时,则获取所述区块链上最高区块的块高和哈希值;将所述最高区块的块高加1后确定为所述第i个区块的块高,将所述最高区块的哈希值确定为所述第i个区块的父区块哈希值;When the determining unit determines that the i-th block to be generated is not an empty block, obtain the block height and hash value of the highest block on the blockchain; add the block height of the highest block After 1, it is determined as the block height of the i-th block, and the hash value of the highest block is determined as the hash value of the parent block of the i-th block;
    将所述第i个区块的块高、所述第i个区块的父区块哈希值打包至所述第i个区块。Pack the block height of the i-th block and the hash value of the parent block of the i-th block into the i-th block.
  15. 如权利要求12所述的装置,其特征在于,所述空块缓存中包括最新空块索引值,所述最新空块索引值为所述最新空块的空块索引值;The apparatus according to claim 12, wherein the empty block cache includes a latest empty block index value, and the latest empty block index value is an empty block index value of the latest empty block;
    所述确定单元具体用于:The determining unit is specifically used for:
    根据所述最新空块索引值,从所述空块缓存中确定所述最新空块并获取所述最新空块的空块索引值和所述最新空块的哈希值;Determine the latest empty block from the empty block cache according to the latest empty block index value and obtain the empty block index value of the latest empty block and the hash value of the latest empty block;
    所述存储单元还用于:The storage unit is also used for:
    在将所述第i个区块存储至所述空块缓存中之后,将所述最新空块索引值加1。After storing the i-th block in the empty block cache, add 1 to the latest empty block index value.
  16. 一种区块共识装置,其特征在于,适用于包括主共识节点和辅共识节点的区块链系统;所述区块链系统包括区块链和空块缓存;所述区块链中任一区块均不是空块;所述空块缓存用于存储空块;所述空块缓存中的空块是针对所述区块链中第m个区块之后生成的空块且所述空块缓存中的空块在所述区块链中增加第m+1个区块时被清空;所述空块包括空块索引值和父空块哈希值;所述空块索引值用于指示所述空块缓存中各空块产生的先后;m为正整数;A block consensus device, characterized in that it is suitable for a block chain system including a main consensus node and an auxiliary consensus node; the block chain system includes a block chain and an empty block cache; any one of the block chains The blocks are not empty blocks; the empty block cache is used to store empty blocks; the empty block in the empty block cache is for the empty block generated after the mth block in the blockchain and the empty block The empty block in the cache is emptied when the m+1 th block is added to the blockchain; the empty block includes an empty block index value and a parent empty block hash value; the empty block index value is used to indicate The sequence of the generation of each empty block in the empty block cache; m is a positive integer;
    所述装置包括:The device includes:
    接收单元,用于接收所述主共识节点广播的第i个区块;i为正整数;A receiving unit for receiving the i-th block broadcast by the master consensus node; i is a positive integer;
    确定单元,用于从所述第i个区块中确定所述第i个区块的空块索引值和所述第i个区块的父空块哈希值;以及从所述辅共识节点的空块缓存中确定第一空块的哈希值和所述第一空块的空块索引值;所述第一空块是所述辅共识节点的空块缓存中的最新空块;A determining unit, configured to determine the empty block index value of the i-th block and the hash value of the parent empty block of the i-th block from the i-th block; and from the auxiliary consensus node Determining the hash value of the first empty block and the empty block index value of the first empty block in the empty block cache; the first empty block is the latest empty block in the empty block cache of the secondary consensus node;
    存储单元,用于若确定所述第i个区块通过共识验证,则将所述第i个区块存储至所述辅共识节点的空块缓存中;所述第i个区块通过共识验证包括所述第i个区块的空块索引值与所述第一空块的空块索引值符合预设要求,且确定所述第i个区块的父空块哈希值等于所述第一空块的哈希值。A storage unit, configured to store the i-th block in the empty block cache of the auxiliary consensus node if it is determined that the i-th block passes the consensus verification; the i-th block passes the consensus verification Including the empty block index value of the i-th block and the empty block index value of the first empty block meet the preset requirements, and it is determined that the hash value of the parent empty block of the i-th block is equal to the The hash value of an empty block.
  17. 如权利要求16所述的装置,其特征在于,所述确定单元还用于:The device according to claim 16, wherein the determining unit is further configured to:
    从所述第i个区块中确定所述第i个区块的块高和所述第i个区块的父区块哈希值;Determine the block height of the i-th block and the hash value of the parent block of the i-th block from the i-th block;
    从所述辅共识节点的区块链中确定最高区块的块高和所述最高区块的哈希值;Determine the block height of the highest block and the hash value of the highest block from the blockchain of the auxiliary consensus node;
    所述第i个区块通过共识验证,还包括:The i-th block passes consensus verification, and further includes:
    所述第i个区块的块高等于所述最高区块的块高加1,且所述第i个区块的父区块哈希值等于所述最高区块的哈希值。The block height of the i-th block is equal to the block height of the highest block plus 1, and the hash value of the parent block of the i-th block is equal to the hash value of the highest block.
  18. 如权利要求16所述的装置,其特征在于,所述确定单元还用于:The device according to claim 16, wherein the determining unit is further configured to:
    从所述第i个区块中确定所述第i个区块的空块索引值为预设值,且所述第i个区块的父空块哈希值为空值;Determining from the i-th block that the empty block index value of the i-th block is a preset value, and the hash value of the parent empty block of the i-th block is a null value;
    从所述第i个区块中确定所述第i个区块的块高和所述第i个区块的父区块哈希值;Determine the block height of the i-th block and the hash value of the parent block of the i-th block from the i-th block;
    从所述辅共识节点的区块链中确定最高区块的块高和所述最高区块的哈希值;Determine the block height of the highest block and the hash value of the highest block from the blockchain of the auxiliary consensus node;
    若确定所述第i个区块的块高等于所述最高区块的块高加1,且所述第i个区块的父区块哈希值等于所述最高区块的哈希值,则确定所述第i个区块通过所述共识验证。If it is determined that the block height of the i-th block is equal to the block height of the highest block plus 1, and the hash value of the parent block of the i-th block is equal to the hash value of the highest block, It is determined that the i-th block passes the consensus verification.
  19. 一种区块同步装置,其特征在于,适用于包括多个节点的区块链系统;所述区块链系统包括区块链和空块缓存;所述区块链中任一区块均不是空块;所述空块缓存用于存储空块;所述空块缓存中的空块是针对所述区块链中第m个区块之后生成的空块且所述空块缓存中的空块在所述区块链中增加第m+1个区块时被清空;所述多个节点包括第一节点和第二节点,所述第一节点是所述多个节点中的任一个,所述第二节点是所述多个节点中除所述第一节点之外的任一个;m为正整数;A block synchronization device is characterized in that it is suitable for a block chain system including multiple nodes; the block chain system includes a block chain and an empty block cache; any block in the block chain is not Empty blocks; the empty block cache is used to store empty blocks; the empty blocks in the empty block cache are for empty blocks generated after the mth block in the blockchain and the empty block cache is empty A block is emptied when the m+1 th block is added to the blockchain; the multiple nodes include a first node and a second node, and the first node is any one of the multiple nodes, The second node is any one of the plurality of nodes except the first node; m is a positive integer;
    所述装置包括:The device includes:
    接收单元,用于接收所述第二节点广播的状态信息;所述状态信息包括所述第二节点的空块缓存中最新空块的空块索引值和所述第二节点的区块链的最高区块的块高;The receiving unit is configured to receive the state information broadcast by the second node; the state information includes the empty block index value of the latest empty block in the empty block cache of the second node and the block chain value of the second node The block height of the highest block;
    确定单元,用于若确定所述第二节点的区块链的最高区块的块高等于所述第一节点的区块链的最高区块的块高,且所述第二节点的最新空块的空块索引值大于所述第一节点的最新空块的空块索引值,则从所述第二节点的空块缓存中确定待同步空块;所述待同步空块是所述第二节点的空块缓存中空块索引值大于所述第一节点的最新空块的空块索引值的空块;The determining unit is configured to determine if the block height of the highest block of the blockchain of the second node is equal to the block height of the highest block of the blockchain of the first node, and the latest empty of the second node If the empty block index value of the block is greater than the empty block index value of the latest empty block of the first node, the empty block to be synchronized is determined from the empty block cache of the second node; the empty block to be synchronized is the first An empty block whose empty block index value is greater than the empty block index value of the latest empty block of the first node in the empty block cache of the second node;
    同步单元,用于将所述待同步空块同步至所述第一节点的空块缓存中。The synchronization unit is configured to synchronize the empty block to be synchronized to the empty block cache of the first node.
  20. 如权利要求19所述的装置,其特征在于,所述同步单元具体用于:The device according to claim 19, wherein the synchronization unit is specifically configured to:
    针对任一个待同步空块,获取所述待同步空块的父空块哈希值和空块索引值;For any empty block to be synchronized, obtain the hash value of the parent empty block and the empty block index value of the empty block to be synchronized;
    若确定所述待同步空块的父空块哈希值等于所述第一节点的空块缓存中最新空块的哈希值,且所述待同步空块的空块索引值等于所述第一节点的最新空块的空块索引值加1,则确定同步所述待同步空块至所述第一节点的空块缓存中。If it is determined that the hash value of the parent empty block of the empty block to be synchronized is equal to the hash value of the latest empty block in the empty block cache of the first node, and the empty block index value of the empty block to be synchronized is equal to the first node The empty block index value of the latest empty block of a node is increased by 1, and it is determined to synchronize the empty block to be synchronized to the empty block cache of the first node.
  21. 如权利要求20所述的装置,其特征在于,所述待同步空块中包括父区块哈希值;The device of claim 20, wherein the empty block to be synchronized includes a parent block hash value;
    所述同步单元还用于:The synchronization unit is also used for:
    在确定同步所述待同步空块至所述第一节点的空块缓存中之前,还包括:Before determining to synchronize the empty block to be synchronized to the empty block cache of the first node, the method further includes:
    确定所述待同步空块中父区块哈希值是否等于所述第一节点的区块链上的最高区块的哈希值。Determine whether the hash value of the parent block in the empty block to be synchronized is equal to the hash value of the highest block on the blockchain of the first node.
  22. 如权利要求19所述的装置,其特征在于,所述状态信息还包括所述第二节点的区块链的块高;The device according to claim 19, wherein the state information further comprises the block height of the blockchain of the second node;
    所述同步单元还用于:The synchronization unit is also used for:
    在从所述第二节点的空块缓存中确定待同步空块之前,若确定所述第二节点的区块链的最高区块的块高大于所述第一节点的区块链的最高区块的块高,则同步所述第二节点的区块链中高于所述第一节点的区块链的区块;Before determining the empty block to be synchronized from the empty block cache of the second node, if it is determined that the block height of the highest block of the second node's blockchain is greater than the highest zone of the first node's blockchain If the block is high, the block in the block chain of the second node that is higher than the block chain of the first node is synchronized;
    在所述第一节点的区块链的区块同步后,清空所述第一节点的空块缓存。After the blocks of the blockchain of the first node are synchronized, the empty block cache of the first node is cleared.
  23. 一种计算设备,其特征在于,包括存储器和处理器,存储器用于存储程序指令,处理器用于调用所述存储器中存储的程序指令,按照获得的程序执行权利要求1至11任一 项所述的方法。A computing device, characterized by comprising a memory and a processor, the memory is used to store program instructions, the processor is used to call the program instructions stored in the memory, and execute any one of claims 1 to 11 according to the obtained program Methods.
  24. 一种计算机可读非易失性存储介质,其特征在于,包括计算机可读指令,当计算机读取并执行所述计算机可读指令时,使得计算机执行如权利要求1至11任一项所述的方法。A computer-readable non-volatile storage medium, characterized by comprising computer-readable instructions, when the computer reads and executes the computer-readable instructions, the computer is caused to execute any one of claims 1 to 11 Methods.
PCT/CN2020/104618 2019-08-12 2020-07-24 Block processing method and device, block consensus method and device and block synchronization method and device WO2021027529A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910741064.XA CN110493148B (en) 2019-08-12 2019-08-12 Block processing, block consensus and block synchronization method and device
CN201910741064.X 2019-08-12

Publications (1)

Publication Number Publication Date
WO2021027529A1 true WO2021027529A1 (en) 2021-02-18

Family

ID=68550558

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/104618 WO2021027529A1 (en) 2019-08-12 2020-07-24 Block processing method and device, block consensus method and device and block synchronization method and device

Country Status (2)

Country Link
CN (1) CN110493148B (en)
WO (1) WO2021027529A1 (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113037852A (en) * 2021-03-22 2021-06-25 中国人民银行数字货币研究所 Block chain link point synchronization method and device
CN114385647A (en) * 2021-12-15 2022-04-22 达闼科技(北京)有限公司 Alliance link-out block method and device, electronic equipment and medium
WO2022182303A1 (en) * 2021-02-26 2022-09-01 Cloudpeer Global Teknoloji A. S. A block chain system
CN115277733A (en) * 2022-07-29 2022-11-01 北京智融云河科技有限公司 Block header synchronization method and device, electronic equipment and storage medium

Families Citing this family (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110493148B (en) * 2019-08-12 2022-04-01 深圳前海微众银行股份有限公司 Block processing, block consensus and block synchronization method and device
CN110889729B (en) * 2019-11-29 2024-03-26 腾讯科技(深圳)有限公司 Data verification method and device based on blockchain network
CN111159289B (en) * 2019-12-17 2024-03-01 深圳前海微众银行股份有限公司 Method and device for synchronizing blocks
CN111277645B (en) * 2020-01-16 2023-02-10 深圳市迅雷网络技术有限公司 Hot switching method for main and standby nodes, block chain system, block chain node and medium
CN111507840B (en) * 2020-04-15 2024-03-26 财付通支付科技有限公司 Block chain consensus method, apparatus, computer and readable storage medium
CN111667371B (en) * 2020-06-30 2021-08-06 腾讯科技(深圳)有限公司 Resource aggregation method, system, device and storage medium based on block chain
CN112417038B (en) * 2020-11-10 2021-07-13 深圳百纳维科技有限公司 Asynchronous block construction method and device based on ocean transportation and storage medium
CN112202933B (en) * 2020-12-08 2021-03-05 腾讯科技(深圳)有限公司 Information processing method and device of block chain network and node equipment
CN112380149B (en) * 2021-01-18 2021-04-06 腾讯科技(深圳)有限公司 Data processing method, device, equipment and medium based on node memory

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106897353A (en) * 2016-12-29 2017-06-27 北京瑞卓喜投科技发展有限公司 The generation method and system of the block chain that centre type multidimensional is expanded
CN109447810A (en) * 2018-11-29 2019-03-08 杭州秘猿科技有限公司 Parallel block chain common recognition method, system, electronic equipment and computer readable storage medium
US20190081793A1 (en) * 2017-09-12 2019-03-14 Kadena, LLC Parallel-chain architecture for blockchain systems
CN109885258A (en) * 2019-02-01 2019-06-14 立旃(上海)科技有限公司 Data deletion apparatus and method based on block chain
CN110493148A (en) * 2019-08-12 2019-11-22 深圳前海微众银行股份有限公司 A kind of block processes, block common recognition and block synchronous method and device

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
GB201707296D0 (en) * 2017-05-08 2017-06-21 Nchain Holdings Ltd Computer-implemented system and method
CN107807951B (en) * 2017-09-18 2020-10-13 联动优势科技有限公司 Block chain generation method, data verification method, node and system
CN109213828B (en) * 2018-09-18 2021-08-20 百度在线网络技术(北京)有限公司 Block generation method, device, equipment and storage medium
CN109255057B (en) * 2018-09-18 2021-05-07 百度在线网络技术(北京)有限公司 Block generation method, device, equipment and storage medium

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106897353A (en) * 2016-12-29 2017-06-27 北京瑞卓喜投科技发展有限公司 The generation method and system of the block chain that centre type multidimensional is expanded
US20190081793A1 (en) * 2017-09-12 2019-03-14 Kadena, LLC Parallel-chain architecture for blockchain systems
CN109447810A (en) * 2018-11-29 2019-03-08 杭州秘猿科技有限公司 Parallel block chain common recognition method, system, electronic equipment and computer readable storage medium
CN109885258A (en) * 2019-02-01 2019-06-14 立旃(上海)科技有限公司 Data deletion apparatus and method based on block chain
CN110493148A (en) * 2019-08-12 2019-11-22 深圳前海微众银行股份有限公司 A kind of block processes, block common recognition and block synchronous method and device

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2022182303A1 (en) * 2021-02-26 2022-09-01 Cloudpeer Global Teknoloji A. S. A block chain system
CN113037852A (en) * 2021-03-22 2021-06-25 中国人民银行数字货币研究所 Block chain link point synchronization method and device
CN114385647A (en) * 2021-12-15 2022-04-22 达闼科技(北京)有限公司 Alliance link-out block method and device, electronic equipment and medium
CN114385647B (en) * 2021-12-15 2023-04-07 达闼科技(北京)有限公司 Alliance link-out block method, alliance link-out block device, electronic equipment and medium
CN115277733A (en) * 2022-07-29 2022-11-01 北京智融云河科技有限公司 Block header synchronization method and device, electronic equipment and storage medium
CN115277733B (en) * 2022-07-29 2024-02-20 北京智融云河科技有限公司 Block head synchronization method and device, electronic equipment and storage medium

Also Published As

Publication number Publication date
CN110493148A (en) 2019-11-22
CN110493148B (en) 2022-04-01

Similar Documents

Publication Publication Date Title
WO2021027529A1 (en) Block processing method and device, block consensus method and device and block synchronization method and device
US20200143366A1 (en) Methods for decentralized digital asset transfer and smart contract state transition
TWI705690B (en) System for changing master node in distributed network
EP3566392B1 (en) Achieving consensus among network nodes in a distributed system
CN113329031B (en) Method and device for generating state tree of block
US11095451B2 (en) Optimal data storage configuration in a blockchain
CN111902817B (en) Block chain data storage based on shared nodes and error correction coding
US20190319798A1 (en) Blockchain post-quantum signature scheme
CN109508982A (en) REPB common recognition based on the more subchains of block chain main chain adduction row
TWI729880B (en) Shared blockchain data storage based on error correction coding in trusted execution environments
TWI720918B (en) Consenus of shared blockchain data storage based on error correction code
KR102412024B1 (en) Indexing and recovery of encoded blockchain data
US9152649B2 (en) Maintaining order and fault-tolerance in a distributed hash table system
TWI749488B (en) Computer-implemented method, system, and non-transitory computer-readable storage medium for detecting disabling replay attacks
CN110400218B (en) Layered consensus method based on co-audition group system and block chain data processing system
Yanovich et al. Exonum: Byzantine fault tolerant protocol for blockchains
CN111095218B (en) Method, system and device for storing shared block chain data based on error correction coding
TW202111586A (en) Shared blockchain data storage based on error correction coding in trusted execution environments
CN111373378B (en) Data security for error correction code based shared blockchain data storage
CN111698094B (en) Common identification method based on block chain system and block chain system
CN108810112B (en) Node synchronization method and device for market supervision block chain system
TW202111585A (en) Log-structured storage systems
CN111095210A (en) Storing shared blockchain data based on error correction coding
TW202119243A (en) Prioritizing shared blockchain data storage
CN113064764B (en) Method and apparatus for executing blocks in a blockchain system

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: 20852473

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: 20852473

Country of ref document: EP

Kind code of ref document: A1

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 05/08/2022)

122 Ep: pct application non-entry in european phase

Ref document number: 20852473

Country of ref document: EP

Kind code of ref document: A1