WO2023160077A1 - Blockchain data recovery method and apparatus, and electronic device - Google Patents

Blockchain data recovery method and apparatus, and electronic device Download PDF

Info

Publication number
WO2023160077A1
WO2023160077A1 PCT/CN2022/135120 CN2022135120W WO2023160077A1 WO 2023160077 A1 WO2023160077 A1 WO 2023160077A1 CN 2022135120 W CN2022135120 W CN 2022135120W WO 2023160077 A1 WO2023160077 A1 WO 2023160077A1
Authority
WO
WIPO (PCT)
Prior art keywords
block
data
blockchain
transaction data
types
Prior art date
Application number
PCT/CN2022/135120
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 WO2023160077A1 publication Critical patent/WO2023160077A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1446Point-in-time backing up or restoration of persistent data
    • G06F11/1448Management of the data involved in backup or backup restore
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1446Point-in-time backing up or restoration of persistent data
    • G06F11/1458Management of the backup or restore process
    • G06F11/1469Backup restoration techniques
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/17Details of further file system functions
    • G06F16/1734Details of monitoring file system events, e.g. by the use of hooks, filter drivers, logs
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/18File system types
    • G06F16/1805Append-only file systems, e.g. using logs or journals to store data
    • G06F16/1815Journaling file systems

Definitions

  • One or more embodiments of this specification relate to the field of blockchain technology, and in particular, to a blockchain data recovery method and device, and electronic equipment.
  • Blockchain technology also known as distributed ledger technology, is an emerging technology in which several computing devices jointly participate in "bookkeeping" and jointly maintain a complete distributed database. Due to the characteristics of decentralization, openness and transparency, each computing device can participate in database records, and fast data synchronization between computing devices, blockchain technology has been widely used in many fields. to apply.
  • This specification proposes a blockchain data recovery method, which is applied to a node device; the node device is equipped with multiple storage systems for storing blockchain data.
  • the block chain data includes block transaction data and at least one other type of block chain data; the target storage system for storing the block transaction data in the plurality of storage systems supports the write-ahead log WAL model.
  • the method includes: reading a WAL log file corresponding to the block transaction data stored in the target storage system in response to the first event of recovering the other type of blockchain data; based on the WAL log The file restores the block transaction data, and executes the recovered block transaction data to generate the other types of block chain data; write the generated block chain data of other types into the Each of the multiple storage systems is used to store the other types of blockchain data.
  • the method further includes: determining whether the latest block number C among the block numbers corresponding to the other types of blockchain data stored in each storage system is smaller than the block number C stored in the target storage system The latest block number N among the block numbers corresponding to the block transaction data; if yes, the first event is generated.
  • the latest block number C is the minimum value of the latest block numbers corresponding to the other types of blockchain data stored in the storage systems; determine the other block numbers stored in the storage systems Whether the latest block number C corresponding to the type of blockchain data is less than the latest block number N corresponding to the block transaction data stored in the target storage system, it also includes: calculating the The minimum value of the latest block number corresponding to other types of blockchain data is used to obtain the latest block number C.
  • the data identification of the blockchain data stored in the plurality of storage systems includes a block number corresponding to the blockchain data.
  • the data identifiers of the blockchain data stored in the multiple storage systems adopt a unified data format.
  • the data identifier adopts the data format of the LSN log sequence number of the WAL log file.
  • reading the WAL log file corresponding to the block transaction data stored in the target storage system includes: respectively reading the blocks composed of the latest block number C and the latest block number N
  • the WAL log file corresponding to the block transaction data in the block represented by each block number in the number interval (C, N] restore the block transaction data based on the WAL log file, and execute the restored Block chain transactions to generate the other types of block chain data, including: corresponding to the block transaction data in the block represented by each block number in the block number interval (C, N] read WAL log file, restore the block transaction data in the block represented by each block number, and execute the recovered block transaction data to generate the block transaction data in the block represented by the block number
  • the other types of blockchain data corresponding to the block transaction data includes: respectively reading the blocks composed of the latest block number C and the latest block number N
  • the WAL log file corresponding to the block transaction data in the block represented by each block number in the number interval (C, N] restore the block transaction data based on the WAL log file, and execute the restored Block chain transactions
  • determine whether the latest block number C corresponding to the other types of blockchain data stored in each storage system is smaller than the latest block number N corresponding to the block transaction data stored in the target storage system Including: periodically determining whether the latest block number C corresponding to the other types of blockchain data stored in the storage systems is smaller than the latest block number N corresponding to the block transaction data stored in the target storage system; Or, in response to user-triggered instructions for restoring the other types of blockchain data, determine whether the latest block number C corresponding to the other types of blockchain data stored in the storage systems is less than the specified The latest block number N corresponding to the block transaction data stored in the target storage system.
  • the other types of blockchain data include a combination of one or more of the following: the block header data of the block corresponding to the block transaction data; the block header data corresponding to the block transaction data The transaction receipt; after the block transaction data is executed, the account status data corresponding to the block chain account in the block chain.
  • the method further includes: in response to the second event of restoring the block transaction data, restoring the block transaction data based on the WAL log file, and restoring the block transaction data data, written to the target storage system.
  • the method further includes: determining whether the number of files or the storage capacity of the WAL log files corresponding to the block transaction data stored in the target storage system reaches a threshold; if so, generating the second event.
  • determining whether the number of files or the storage capacity of the WAL log files corresponding to the block transaction data stored in the target storage system reaches a threshold includes: periodically determining the block transaction data stored in the target storage system Whether the number of files or the storage capacity of the WAL log file corresponding to the data reaches the threshold; or, in response to an instruction triggered by the user to restore the block transaction data, determine that the block transaction data corresponding to the target storage system Whether the number of files or storage capacity of WAL log files reaches the threshold.
  • This specification also proposes a blockchain data recovery device, which is applied to node equipment; the node equipment is equipped with multiple storage systems for storing blockchain data.
  • the block chain data includes block transaction data and at least one other type of block chain data; the target storage system for storing the block transaction data in the plurality of storage systems supports the write-ahead log WAL model.
  • the device includes: a reading module, which reads the WAL log file corresponding to the block transaction data stored in the target storage system in response to the first event of restoring the other types of blockchain data; Module, restores the block transaction data based on the WAL log file, and executes the recovered block transaction data to generate the other types of block chain data; writes the module, and generates the other types of block chain data
  • the block chain data are respectively written into each storage system used to store the other types of block chain data in the plurality of storage systems.
  • the device further includes: a first determining module, which determines whether the latest block number C among the block numbers corresponding to the other types of blockchain data stored in the storage systems is smaller than the target The latest block number N among the block numbers corresponding to the block transaction data stored in the storage system; if yes, the first event is generated.
  • a first determining module which determines whether the latest block number C among the block numbers corresponding to the other types of blockchain data stored in the storage systems is smaller than the target The latest block number N among the block numbers corresponding to the block transaction data stored in the storage system; if yes, the first event is generated.
  • the latest block number C is the minimum value of the latest block numbers corresponding to the other types of blockchain data stored in each storage system.
  • the determination module further: after determining whether the latest block number C corresponding to the other types of blockchain data stored in the storage systems is smaller than the latest block number C corresponding to the block transaction data stored in the target storage system Before number N, calculate the minimum value of the latest block numbers corresponding to the other types of blockchain data stored in each storage system to obtain the latest block number C.
  • the data identification of the blockchain data stored in the plurality of storage systems includes a block number corresponding to the blockchain data.
  • the data identifiers of the blockchain data stored in the multiple storage systems adopt a unified data format.
  • the data identifier adopts the data format of the LSN log sequence number of the WAL log file.
  • the reading module respectively read the blocks represented by the block numbers in the block number interval (C, N] formed by the latest block number C and the latest block number N]
  • the WAL log file corresponding to the block transaction data in the block the recovery module: based on the block transaction data corresponding to the block in the block represented by each block number in the block number interval (C, N] read WAL log file, restore the block transaction data in the blocks represented by the block numbers, and execute the recovered block transaction data to generate the block transaction data in the blocks represented by the block numbers
  • the other types of blockchain data corresponding to the block transaction data are examples of the block transaction data.
  • the first determining module periodically determine whether the latest block number C corresponding to the other types of blockchain data stored in each storage system is smaller than the block transaction stored in the target storage system The latest block number N corresponding to the data; or, in response to the user-triggered instruction for restoring the other types of blockchain data, determine the corresponding block number of the other types of blockchain data stored in the storage systems Whether the latest block number C is smaller than the latest block number N corresponding to the block transaction data stored in the target storage system.
  • the other types of blockchain data include a combination of one or more of the following: the block header data of the block corresponding to the block transaction data; the block header data corresponding to the block transaction data The transaction receipt; after the block transaction data is executed, the account status data corresponding to the block chain account in the block chain.
  • the writing module further: in response to the second event of restoring the block transaction data, restore the block transaction data based on the WAL log file, and restore the block transaction data The transaction data is written into the target storage system.
  • the device further includes: a second determining module, determining whether the number of files or the storage capacity of the WAL log files corresponding to the block transaction data stored in the target storage system reaches a threshold; if so, generating the second event.
  • a second determining module determining whether the number of files or the storage capacity of the WAL log files corresponding to the block transaction data stored in the target storage system reaches a threshold; if so, generating the second event.
  • the second determination module periodically determines whether the number of files or the storage capacity of the WAL log files corresponding to the block transaction data stored in the target storage system reaches a threshold; or, in response to user-triggered targeting The instruction for recovering the block transaction data determines whether the number of files or the storage capacity of the WAL log files corresponding to the block transaction data stored in the target storage system reaches a threshold.
  • Fig. 1 is a flow chart of a method for recovering blockchain data provided by an exemplary embodiment
  • Fig. 2 is a schematic structural diagram of an electronic device provided by an exemplary embodiment
  • Fig. 3 is a block diagram of a block chain data recovery device provided by an exemplary embodiment.
  • the steps of the corresponding methods are not necessarily performed in the order shown and described in this specification.
  • the method may include more or less steps than those described in this specification.
  • a single step described in this specification may be decomposed into multiple steps for description in other embodiments; multiple steps described in this specification may also be combined into a single step in other embodiments describe.
  • Blockchains are generally divided into three types: Public Blockchain, Private Blockchain and Consortium Blockchain.
  • Public Blockchain Private Blockchain
  • Consortium Blockchain there can be a combination of the above types, such as private chain + alliance chain, alliance chain + public chain, etc.
  • the public chain has the highest degree of decentralization. Participants joining the public chain (also known as nodes in the blockchain) can read data records on the chain, participate in transactions, and compete for the accounting rights of new blocks. Moreover, each node is free to join or exit the network and perform related operations.
  • the private chain the write permission of the network is controlled by an organization or institution, and the data read permission is regulated by the organization.
  • a private chain can be a weakly centralized system with strict restrictions on nodes and a small number of nodes. This type of blockchain is more suitable for internal use by specific institutions.
  • the alliance chain is a blockchain between the public chain and the private chain, which can realize "partial decentralization".
  • Each node in the consortium chain usually has a corresponding entity or organization; nodes join the network through authorization and form an alliance of stakeholders to jointly maintain the operation of the blockchain.
  • the blockchain is usually composed of several blocks. Time stamps corresponding to the creation time of the block are respectively recorded in these blocks, and all blocks form a time-ordered data chain in strict accordance with the time stamps recorded in the block.
  • the real data generated in the physical world it can be constructed into a standard transaction format supported by the blockchain, and then published to the blockchain, and the node devices in the blockchain will perform consensus processing on the received transactions , and after a consensus is reached, the node device in the blockchain as the bookkeeping node will package the transaction into a block and store the certificate persistently in the blockchain.
  • the consensus algorithms supported in the blockchain can include: the first type of consensus algorithm, that is, the consensus algorithm that node devices need to compete for the accounting rights of each round of accounting cycle, for example, proof of work (Proof of Work, POW ), proof of equity (Proof of Stake, POS), delegated proof of equity (Delegated Proof of Stake, DPOS) and other consensus algorithms; the second type of consensus algorithm is to pre-elect accounting nodes for each round of accounting cycle (no need to compete Bookkeeping rights) consensus algorithms; for example, consensus algorithms such as Practical Byzantine Fault Tolerance (PBFT).
  • PBFT Practical Byzantine Fault Tolerance
  • the node devices competing for the bookkeeping right can execute the transaction after receiving the transaction.
  • the node devices competing for bookkeeping rights there may be a node device that wins the current round of competition for bookkeeping rights and becomes a bookkeeping node.
  • the accounting node can package the received transaction with other transactions to generate the latest block, and send the generated latest block or the block header of the latest block to other node devices for consensus.
  • the node equipment with bookkeeping rights has been agreed before the current round of bookkeeping. Therefore, after the node device receives the transaction, if it is not the accounting node of the current round, it can send the transaction to the accounting node. For the bookkeeping nodes of this round, the transaction can be executed during or before the process of packaging the transaction with other transactions to generate the latest block. After the accounting node generates the latest block, it can send the latest block or the block header of the latest block to other node devices for consensus.
  • the bookkeeping nodes of this round can package the received transactions to generate the latest block, and will generate the latest block or the latest block
  • the block header is sent to other node devices for consensus verification. If other node devices receive the latest block or the block header of the latest block and verify that there is no problem, the latest block can be appended to the end of the original blockchain to complete the accounting process of the blockchain. In the process of verifying the new block or block header sent by the bookkeeping node, other nodes can also execute the transactions contained in the block.
  • Account In the field of blockchain, an important concept is account (Account); taking Ethereum as an example, Ethereum usually divides accounts into two types: external accounts and contract accounts; external accounts are accounts directly controlled by users, also known as It is a user account; while a contract account is an account created by a user through an external account and contains a contract code (that is, a smart contract).
  • External accounts are accounts directly controlled by users, also known as It is a user account
  • a contract account is an account created by a user through an external account and contains a contract code (that is, a smart contract).
  • a structure is usually used to maintain the account status of the account.
  • the state of the account associated with the transaction in the blockchain usually also changes.
  • the account structure usually includes fields such as Balance, Nonce, Code, and Storage. in:
  • the Balance field is used to maintain the current account balance of the account
  • the Nonce field is used to maintain the number of transactions of the account; it is a counter used to ensure that each transaction can only be processed once, effectively avoiding replay attacks;
  • the Code field is used to maintain the contract code of the account; in practical applications, only the hash value of the contract code is usually maintained in the Code field; therefore, the Code field is usually also called the Codehash field.
  • the Storage field is used to maintain the storage content of the account (the default field value is empty); for the contract account, an independent storage space is usually allocated to store the storage content of the contract account; the independent storage space is usually It is called the account storage of the contract account.
  • the storage content of the contract account is usually built into a data structure of MPT (Merkle Patricia Trie) tree and stored in the above-mentioned independent storage space; among them, the MPT tree constructed based on the storage content of the contract account is usually also called the Storage tree .
  • the Storage field usually only maintains the hash value of the root node of the Storage tree; therefore, the Storage field is usually also called the Storage Root hash field.
  • the field values of the Code field and the Storage field shown above are all null values.
  • the data structure of the Merkle tree is usually used; or, the data structure based on the Merkle tree is used to store and maintain the blockchain data.
  • the blockchain data that needs to be stored and maintained usually includes block data, account status data corresponding to the blockchain account in the blockchain; and the block data further includes block header data, The block transaction data in the block, and the transaction receipt corresponding to the block transaction data in the block, and so on. It should be noted that in practical applications, in addition to storing and maintaining blockchain data, node devices also need to store and maintain index data corresponding to blockchain data.
  • the MPT tree is a Merkle tree variant that combines the tree structure of the Trie dictionary tree.
  • Ethereum has designed three MPT trees, namely the MPT state tree, MPT transaction tree and MPT receipt tree. Among them, in addition to the above three MPT trees, there is actually a Storage tree built based on the storage content of the contract account.
  • the MPT state tree is an MPT tree organized by the account state (state) data of all accounts in the blockchain;
  • the MPT transaction tree is an MPT tree organized by the transaction (transaction) data in the blockchain;
  • the MPT receipt tree is the MPT tree organized by the transaction (receipt) receipt corresponding to each transaction generated after the transaction in the block is executed.
  • the hash values of the root nodes of the MPT state tree, MPT transaction tree and MPT receipt tree shown above will eventually be added to the block header of the corresponding block.
  • the MPT transaction tree and MPT receipt tree correspond to blocks, that is, each block has its own MPT transaction tree and MPT receipt tree.
  • the MPT state tree is a global MPT tree, which does not correspond to a specific block, but covers the account state data of all accounts in the blockchain.
  • the account status of the accounts (which can be external accounts or contract accounts) related to these executed transactions in the blockchain, usually It will also change accordingly.
  • the balances of the transfer-out account and transfer-in account related to the "transfer transaction” (that is, the field value of the Balance field of these accounts) are usually also Will change accordingly.
  • the node device After the transaction of the node device in the latest block generated by the blockchain is completed, because the account status in the current blockchain has changed, the node device needs to use the current account status data of all accounts in the blockchain. Build an MPT state tree to maintain the latest state of all accounts in the blockchain.
  • the node device needs to be based on all accounts in the blockchain
  • the latest account status data rebuilds an MPT status tree.
  • each block in the blockchain has a corresponding MPT state tree; the MPT state tree maintains all accounts in the blockchain after the transactions in the block are executed. account status.
  • the blockchain usually connects with various business systems outside the chain for multi-party data and workflow collaboration (independent of business); for example, a business system A connected to the blockchain, Relevant business data can be published to the blockchain to drive another business system B that is connected to the blockchain to perform further business processing based on the business data; and for different types of blockchain data, the multi-party data
  • the actual functions may be different from each other; when node devices store and maintain blockchain data, they usually carry multiple storage systems and store different types of blockchain data in the in different storage systems.
  • the node device can be equipped with three different storage systems, which store block data, state data (that is, the above account status data), and index data corresponding to the above two types of data (such as the hash of the above two types of data) value), which are stored in different storage systems.
  • state data that is, the above account status data
  • index data corresponding to the above two types of data such as the hash of the above two types of data
  • WAL copies of WAL are examples respectively.
  • the node device can combine block header data, block transaction data, transaction receipts corresponding to block transaction data, state data (that is, the above-mentioned account status data), and index data corresponding to the above four types of data (such as The hash values of the above 4 kinds of data) are stored in different storage systems; in this case, the node device can be equipped with 5 different storage systems, which respectively store block header data, block transaction The transaction receipt, state data corresponding to the data, and the index data corresponding to the above four types of data are stored in these five different storage systems.
  • each storage system can enable WAL (write ahead logging, pre-written log) mode.
  • the WAL mode is an efficient log algorithm.
  • all data modification for the storage system will be written into the WAL log file before being submitted to the storage system; then, through the checkpoint event triggered periodically or manually by the user, the The data stored in the WAL log file is modified and written to the storage system.
  • the blockchain ledger stored by the node device By enabling the WAL mode for the storage system on the node device, although data loss due to unwritten data can be prevented, the blockchain ledger stored by the node device often contains many different types of blockchain data. Stored in different storage systems; therefore, storing multiple WAL log files will increase the storage overhead of the node device; moreover, when the node device restores the data modification stored in multiple WAL log files to the storage system, it needs multiple times Executing the related recovery process will also increase the performance overhead of the node device.
  • this manual proposes a technical solution for recovering various blockchain data by using a WAL log file stored in the node device and corresponding to the blockchain transaction data.
  • the node device of the blockchain can be equipped with multiple storage systems for storing blockchain data.
  • the aforementioned block chain data may include block transaction data and at least one type of block chain data with other types;
  • the target storage system used to store the block transaction data in the above-mentioned multiple storage systems may support the write-ahead log WAL model.
  • the node device responds to the first event of recovering the above-mentioned other types of blockchain data, it can read the WAL log file corresponding to the block transaction data stored in the target storage system; then based on the read WAL The log file restores the above-mentioned block transaction data.
  • the restored block transaction data is further executed to generate the above-mentioned other types of block chain data; then, the generated above-mentioned other Types of blockchain data are respectively written into the storage systems used to store the other types of blockchain data in the above-mentioned multiple storage systems.
  • FIG. 1 is a flow chart of a blockchain data recovery method provided by an exemplary embodiment.
  • the method is applied to a block chain node device; wherein, the block chain data includes block transaction data and at least one other type of block chain data corresponding to the block transaction data; the plurality of stored
  • the target storage system used to store the block transaction data in the system supports the write-ahead log WAL mode.
  • the method comprises the steps of:
  • Step 102 in response to the first event of recovering the other types of blockchain data, read the WAL log file corresponding to the block transaction data stored in the target storage system;
  • Step 104 recovering the block transaction data based on the WAL log file, and executing the recovered block transaction data to generate the other types of blockchain data;
  • Step 106 writing the generated blockchain data of other types into storage systems for storing the blockchain data of other types among the multiple storage systems.
  • the blockchain ledger stored by the node device usually includes various types of blockchain data.
  • the various types of blockchain data mentioned above may generally include block data, account status data corresponding to blockchain accounts in the blockchain, and so on.
  • the block data usually includes block header data and block body data; the above block body data further includes block transaction data in the block, and transaction receipts corresponding to the block transaction data in the block, etc. wait.
  • node devices in addition to the blockchain data listed above, node devices usually need to store and maintain index data corresponding to the above-mentioned various blockchain data.
  • the specific form of the above-mentioned index data is not particularly limited in this specification.
  • the content summary (such as hash value) of the above blockchain data can be used as the Index data, so that users can use the content summary of the above blockchain data as a query index to query and access related blockchain data in the blockchain ledger.
  • the data identifier (such as the data number) set by the blockchain system for the stored blockchain data can be specified.
  • the index data of the blockchain data users can use the data identification of the above blockchain data as a query index to query and access the relevant blockchain data in the blockchain ledger.
  • the node device can be equipped with multiple storage systems, and store different types of blockchain data in different storage systems.
  • the above-mentioned storage system can specifically include any form of storage system for persistent storage of blockchain data in the blockchain ledger; for example, in practical applications, the above-mentioned storage system can specifically be a node device carrying The database, file system, etc., are not particularly limited in this specification.
  • the above-mentioned block transaction data can be used as the "root data" of other types of blockchain data; when the node device stores the various types of blockchain data shown above, the above-mentioned block can be Transaction data and other types of blockchain data are stored in separate storage systems.
  • the node device can be equipped with five different storage systems, which respectively store the block transaction data, the block header data of the block corresponding to the block transaction data, the transaction receipt corresponding to the block transaction data, The state data and the index data corresponding to the above four types of data are stored in these five different storage systems.
  • the target storage system used to store "root data” (that is, block transaction data) in each storage system can open WAL model. After the WAL mode is turned on, all data modifications (such as writing new block transaction data) for the target storage system will be written to the target storage system in the form of a WAL log file before being submitted to the target storage system.
  • the WAL log buffer corresponding to the target storage system can also be a persistent storage; then, when the blockchain system triggers a checkpoint event corresponding to the above target storage system, the node device can respond to the checkpoint Event, and then modify the above "root data” data stored in the WAL log file, and restore it to the target storage system.
  • the above-mentioned checkpoint event refers to an event of performing data recovery on the blockchain data stored in the storage system based on the WAL log file.
  • the WAL mode may not be enabled, but cross-storage based on the WAL log files corresponding to the above-mentioned target storage systems.
  • Data recovery of the storage system that is, a storage system that does not enable the WAL mode can also perform data recovery through the corresponding WAL log files of other storage systems that enable the WAL mode.
  • the blockchain system can also checkpoint events of the above-mentioned other storage systems that have not opened the WAL mode; and when the blockchain system triggers the checkpoint events corresponding to the above-mentioned other storage systems, the node device can In response to the checkpoint event, read the WAL log file corresponding to the above-mentioned target storage system for data recovery calculation, and then based on the calculation results of the data recovery calculation, cross-storage system data for other types of blockchain data stored in the other storage systems mentioned above data recovery.
  • the process for the node device to recover the block transaction data stored in the above-mentioned target storage system, and the process for recovering other types of blockchain data stored in the above-mentioned other storage systems can be two
  • the procedures that are independent of each other are not particularly limited in the execution sequence of the two in this specification.
  • the node device can first perform the process of recovering the block transaction data stored in the above-mentioned target storage system, and then perform recovery of other types of blockchain data stored in the above-mentioned other storage systems
  • the process of recovering other types of blockchain data stored in the above-mentioned other storage systems can also be performed first, and then the process of recovering the block transaction data stored in the above-mentioned target storage system can be performed.
  • the process of recovering the block transaction data stored in the above-mentioned target storage system is also completed based on the WAL log file corresponding to the above-mentioned block transaction data; therefore, if the node device first executes the above-mentioned target The process of recovering the block transaction data stored in the storage system needs to temporarily not delete the WAL log file corresponding to the above block transaction data stored in the log buffer after the above block transaction data is restored; when the node device starts Execute the process of recovering other types of blockchain data stored in the above-mentioned other storage systems, and continue to restore other types of blockchain data stored in the above-mentioned other storage systems based on the above-mentioned WAL log files, and in After recovery is complete, delete the WAL log file from the log buffer.
  • the checkpoint event triggered by the blockchain system and corresponding to the above-mentioned other storage systems will be called “the first event”; the checkpoint event triggered by the blockchain system and corresponding to the above-mentioned target storage system , which will be referred to as the "second event”.
  • the trigger condition of the above-mentioned first event may generally include that the number of WAL log files corresponding to the block transaction data stored in the above-mentioned target storage system reaches a threshold ; Or, the storage capacity of the WAL log file corresponding to the block transaction data stored in the above target storage system reaches a threshold.
  • the threshold can trigger the blockchain system to generate the above-mentioned first event.
  • the trigger condition of the above-mentioned second event may specifically include that the latest block number C among the block numbers corresponding to the above-mentioned other types of blockchain data stored in the above-mentioned other storage systems is smaller than the block transaction data stored in the above-mentioned target storage system The latest block number N in the corresponding block number.
  • the latest block number C in the block numbers corresponding to the above-mentioned other types of blockchain data stored in the above-mentioned other storage systems is smaller than the block number C in the block number corresponding to the block transaction data stored in the above-mentioned target storage system
  • the latest block number N can trigger the blockchain system to generate the above-mentioned second event.
  • the following will use a specific embodiment to trigger the above-mentioned first event based on the blockchain system for the node device, and restore the other types of blockchain data stored in the above-mentioned other storage systems; and, the node device triggers the process based on the system
  • the process of recovering the block transaction data stored in the above-mentioned target storage system for the above-mentioned second event is described separately.
  • the node device when the node device restores other types of blockchain data stored in the above-mentioned other storage systems, it can periodically determine the above-mentioned other types of blocks stored in the above-mentioned other storage systems Whether the latest block number C corresponding to the chain data is smaller than the latest block number N corresponding to the block transaction data stored in the above-mentioned target storage system; if yes, the generation of the above-mentioned first event can be triggered.
  • the node device may preset a check period T of the checkpiont event, and then periodically check whether the above-mentioned other storage systems meet the triggering condition of the above-mentioned checkpiont event based on the period T.
  • the node device when the node device restores other types of blockchain data stored in the above-mentioned other storage systems, it can also respond to user-triggered Data recovery instructions to determine whether the latest block number C corresponding to the above-mentioned other types of blockchain data stored in the above-mentioned other storage systems is smaller than the latest block number N corresponding to the block transaction data stored in the above-mentioned target storage system ; If yes, it may trigger to generate the above-mentioned first event.
  • the user in addition to periodically checking whether the above-mentioned other storage systems meet the trigger conditions of the above-mentioned checkpiont event, the user can also trigger the node device to check the above-mentioned other storage systems by manually inputting recovery instructions.
  • the user may need to perform a data rollback operation on the above-mentioned other types of blockchain data stored in the above-mentioned other storage systems, and restore the data stored in the above-mentioned other storage systems
  • the above-mentioned other types of blockchain data are restored to the data version corresponding to a certain historical block; in this scenario, the user can trigger the node device to check whether the above-mentioned other storage systems meet the above-mentioned checkpoint by manually inputting the recovery command.
  • the trigger condition for the event is
  • the latest block number C corresponding to the above-mentioned other types of blockchain data stored in the above-mentioned other storage systems may specifically be the latest block number C corresponding to the above-mentioned other types of blockchain data stored in the above-mentioned other storage systems
  • the node device can first calculate the minimum value of the latest block number corresponding to the above-mentioned other types of blockchain data stored in the above-mentioned other storage systems, and obtain the above-mentioned latest block number C, It is further determined whether the above latest block number C is smaller than the latest block number N corresponding to the block transaction data stored in the target storage system.
  • the data identification of the blockchain data stored in each storage system may specifically include the above-mentioned The block number corresponding to the blockchain data; that is, the block number corresponding to the blockchain data can be directly added to the data identifier of the blockchain data; or, in the data identifier of the blockchain data, Add information indicating the block number to which the blockchain data corresponds.
  • the data identification of the blockchain data stored in each storage system carried by the node device can specifically adopt a unified data format, and in the unified data format adopted, carry the data corresponding to the blockchain data.
  • Block number or information indicating the block number corresponding to the blockchain data.
  • the above-mentioned data format is not particularly limited in this specification; for example, in one example, the data identification of the blockchain data stored in each storage system carried by the node device can uniformly use the LSN (Log Sequence Number, the data format of the log sequence number), and carry the block number corresponding to the blockchain data in the LSN of the WAL log file; or indicate the information of the block number corresponding to the blockchain data.
  • LSN Log Sequence Number, the data format of the log sequence number
  • the node device can respond to the first event by reading the above-mentioned latest block number C and the above-mentioned latest block number C from the log buffer corresponding to the above-mentioned target storage system respectively.
  • the recovered block transaction data can be further executed, and by re-executing the transaction, generate The above-mentioned other types of blockchain data corresponding to the block transaction data in the block represented by each block number in the above-mentioned block number interval (C, N].
  • the node device is equipped with five different storage systems, which respectively store the block transaction data, the block header data of the block corresponding to the block transaction data, the transaction receipt corresponding to the block transaction data,
  • the state data and the index data corresponding to the above four types of data are stored in these five different storage systems; among them, the target storage system that stores the above block transaction data has turned on the WAL mode; then for the above other types of blocks
  • the target storage system that stores the above block transaction data has turned on the WAL mode; then for the above other types of blocks
  • C, N block number in the above block number interval
  • the corresponding state data and corresponding index data are restored separately.
  • the node device when the node device restores the block transaction data stored in the above target storage system, it can periodically determine the WAL log file corresponding to the block transaction data stored in the above target storage system Whether the number of files or the storage capacity reaches the threshold; if yes, the above-mentioned second event may be triggered to be generated.
  • the node device when the node device recovers the block transaction data stored in the target storage system, it may also respond to an instruction manually triggered by the user to restore the above block transaction data to determine Whether the number of files or the storage capacity of the WAL log files corresponding to the block transaction data stored in the target storage system reaches a threshold; if yes, the generation of the second event above may be triggered.
  • the user in addition to periodically checking whether the above-mentioned target storage system meets the trigger conditions of the above-mentioned checkpoint event, the user can also trigger the node device to check whether the above-mentioned target storage system meets The trigger condition of the above checkpiont event; for example, in some recovery scenarios, the user may need to perform a data rollback operation on the blockchain transaction data stored in the above target storage system, and restore the block transaction data stored in the above target storage system to a certain The data version corresponding to a historical block. In this scenario, the user may manually input a recovery command to trigger the node device to check whether the target storage system satisfies the trigger condition of the checkpiont event.
  • the node device can respond to the second event and read the WAL log file corresponding to the block transaction data stored in the log buffer from the log buffer corresponding to the above-mentioned target storage system; and then , based on the read WAL log file, restore the block transaction data, and then write the restored block transaction data into the above target storage system.
  • the present application also provides device embodiments.
  • this specification also provides an embodiment of a block chain data recovery device.
  • the embodiment of the blockchain data recovery device in this specification can be applied to electronic equipment.
  • the device embodiment can be implemented by software, or by hardware or a combination of software and hardware. Taking software implementation as an example, as a device in a logical sense, it is formed by reading the corresponding computer program instructions in the non-volatile memory into the memory for operation by the processor of the electronic device where it is located.
  • FIG. 2 it is a hardware structure diagram of the electronic equipment where the blockchain data recovery device in this manual is located, except for the processor, memory, network interface, and non-volatile memory shown in Figure 2
  • the electronic device where the device in the embodiment is located usually may also include other hardware according to the actual function of the electronic device, which will not be repeated here.
  • Fig. 3 is a block diagram of a block chain data recovery device shown in an exemplary embodiment of this specification.
  • the block chain data recovery device 30 can be applied in the aforementioned electronic equipment shown in FIG. 2, and the node device is equipped with multiple storage systems for storing block chain data; wherein, the The block chain data includes block transaction data and at least one other type of block chain data; the target storage system for storing the block transaction data in the plurality of storage systems supports the write-ahead log WAL mode; the The device 30 includes: a reading module 301, which reads the WAL log file corresponding to the block transaction data stored in the target storage system in response to the first event of restoring the other types of blockchain data; Module 302, restore the block transaction data based on the WAL log file, and execute the recovered block transaction data to generate the other types of block chain data; write module 303, the generated Other types of blockchain data are respectively written into the storage systems used to store the other types of blockchain data among the plurality of storage systems.
  • the device 30 further includes: a first determination module 304 (not shown in FIG. 3 ), which determines the number of block numbers corresponding to the other types of blockchain data stored in each storage system. Whether the latest block number C of the target storage system is smaller than the latest block number N in the block numbers corresponding to the block transaction data stored in the target storage system; if yes, the first event is generated.
  • a first determination module 304 (not shown in FIG. 3 ), which determines the number of block numbers corresponding to the other types of blockchain data stored in each storage system. Whether the latest block number C of the target storage system is smaller than the latest block number N in the block numbers corresponding to the block transaction data stored in the target storage system; if yes, the first event is generated.
  • the latest block number C is the minimum value of the latest block numbers corresponding to the other types of blockchain data stored in the storage systems.
  • the first determination module 304 further: after determining whether the latest block number C corresponding to the other types of blockchain data stored in the storage systems is smaller than the block number C corresponding to the block transaction data stored in the target storage system Before the latest block number N, calculate the minimum value of the latest block numbers corresponding to the other types of blockchain data stored in the storage systems to obtain the latest block number C.
  • the data identification of the blockchain data stored in the multiple storage systems includes the block number corresponding to the blockchain data.
  • the data identifiers of the blockchain data stored in the multiple storage systems adopt a unified data format.
  • the data identifier adopts the data format of the LSN log sequence number of the WAL log file.
  • the reading module 301 respectively reads the block number represented by each block number in the block number interval (C, N] formed by the latest block number C and the latest block number N]
  • the WAL log file corresponding to the block transaction data in the block The recovery module 302: based on the block in the block represented by each block number in the block number interval (C, N] read
  • the WAL log file corresponding to the transaction data restores the block transaction data in the blocks represented by the block numbers, and executes the recovered block transaction data to generate the block transaction data represented by the block numbers.
  • the other types of blockchain data corresponding to the block transaction data in the block are examples of the block transaction data in the block.
  • the first determination module 304 (not shown in FIG. 3 ): periodically determine the latest block number C corresponding to the other types of blockchain data stored in each storage system, whether is less than the latest block number N corresponding to the block transaction data stored in the target storage system; or, in response to the instruction triggered by the user to restore the other types of blockchain data, determine the Whether the latest block number C corresponding to the other types of blockchain data is smaller than the latest block number N corresponding to the block transaction data stored in the target storage system.
  • the other types of blockchain data include a combination of one or more of the following: block header data of the block corresponding to the block transaction data; The transaction receipt corresponding to the data; after the block transaction data is executed, the account status data corresponding to the block chain account in the block chain.
  • the writing module 303 further: in response to the second event of restoring the block transaction data, restore the block transaction data based on the WAL log file, and restore all The block transaction data is written into the target storage system.
  • the device 30 further includes: a second determination module 305 (not shown in FIG. 3 ), which determines the number of WAL log files corresponding to the block transaction data stored in the target storage system or Whether the storage capacity reaches a threshold; if so, generating the second event.
  • a second determination module 305 (not shown in FIG. 3 ), which determines the number of WAL log files corresponding to the block transaction data stored in the target storage system or Whether the storage capacity reaches a threshold; if so, generating the second event.
  • the second determination module 305 periodically determines whether the number of files or the storage capacity of the WAL log files corresponding to the block transaction data stored in the target storage system reaches a threshold; or, in response to the user
  • the triggered instruction for recovering the block transaction data determines whether the number of files or the storage capacity of the WAL log files corresponding to the block transaction data stored in the target storage system reaches a threshold.
  • a typical implementing device is a computer, which may take the form of a personal computer, laptop computer, cellular phone, camera phone, smart phone, personal digital assistant, media player, navigation device, e-mail device, game control device, etc. desktops, tablets, wearables, or any combination of these.
  • a computer includes one or more processors (CPUs), input/output interfaces, network interfaces and memory.
  • processors CPUs
  • input/output interfaces network interfaces
  • memory volatile and non-volatile memory
  • Memory may include non-permanent storage in computer readable media, in the form of random access memory (RAM) and/or nonvolatile memory such as read-only memory (ROM) or flash RAM. Memory is an example of computer readable media.
  • RAM random access memory
  • ROM read-only memory
  • flash RAM flash random access memory
  • Computer-readable media including both permanent and non-permanent, removable and non-removable media, can be implemented by any method or technology for storage of information.
  • Information may be computer readable instructions, data structures, modules of a program, or other data.
  • Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read only memory (ROM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Flash memory or other memory technology, Compact Disc Read-Only Memory (CD-ROM), Digital Versatile Disc (DVD) or other optical storage, Magnetic cassettes, disk storage, quantum memory, graphene-based storage media or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by computing devices.
  • computer-readable media excludes transitory computer-readable media, such as modulated data signals and carrier waves.
  • first, second, third, etc. may be used in one or more embodiments of the present specification to describe various information, the information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, without departing from the scope of one or more embodiments of the present specification, first information may also be called second information, and similarly, second information may also be called first information. Depending on the context, the word “if” as used herein may be interpreted as “at” or "when” or "in response to a determination.”

Abstract

A blockchain data recovery method, applied to a node device. The node device carries a plurality of storage systems for storing blockchain data, wherein the blockchain data comprises block transaction data and at least one of other types of blockchain data, and a target storage system, used for storing the block transaction data, among the plurality of storage systems supports a write ahead logging (WAL) mode. The method comprises: in response to a first event for recovering other types of blockchain data, reading a WAL log file corresponding to block transaction data stored in a target storage system; recovering the block transaction data on the basis of the WAL log file, and executing the recovered block transaction data to generate the other types of blockchain data; and respectively writing the other types of generated blockchain data into each storage system, used for storing the other types of blockchain data, among the plurality of storage systems.

Description

区块链数据恢复方法及装置、电子设备Block chain data recovery method and device, electronic equipment 技术领域technical field
本说明书一个或多个实施例涉及区块链技术领域,尤其涉及一种区块链数据恢复方法及装置、电子设备。One or more embodiments of this specification relate to the field of blockchain technology, and in particular, to a blockchain data recovery method and device, and electronic equipment.
背景技术Background technique
区块链技术,也被称之为分布式账本技术,是一种由若干台计算设备共同参与“记账”,共同维护一份完整的分布式数据库的新兴技术。由于区块链技术具有去中心化、公开透明、每台计算设备可以参与数据库记录、并且各计算设备之间可以快速的进行数据同步的特性,使得区块链技术已在众多的领域中广泛的进行应用。Blockchain technology, also known as distributed ledger technology, is an emerging technology in which several computing devices jointly participate in "bookkeeping" and jointly maintain a complete distributed database. Due to the characteristics of decentralization, openness and transparency, each computing device can participate in database records, and fast data synchronization between computing devices, blockchain technology has been widely used in many fields. to apply.
发明内容Contents of the invention
本说明书提出一种区块链数据恢复方法,应用于节点设备;所述节点设备搭载了用于存储区块链数据的多个存储系统。其中,所述区块链数据包括区块交易数据和至少一种其它类型的区块链数据;所述多个存储系统中用于存储所述区块交易数据的目标存储系统支持预写日志WAL模式。所述方法包括:响应于针对所述其它类型的区块链数据进行恢复的第一事件,读取与所述目标存储系统中存储的区块交易数据对应的WAL日志文件;基于所述WAL日志文件恢复所述区块交易数据,并执行恢复出的所述区块交易数据以生成所述其它类型的区块链数据;将生成的所述其它类型的区块链数据,分别写入所述多个存储系统中用于存储所述其它类型的区块链数据的各存储系统。This specification proposes a blockchain data recovery method, which is applied to a node device; the node device is equipped with multiple storage systems for storing blockchain data. Wherein, the block chain data includes block transaction data and at least one other type of block chain data; the target storage system for storing the block transaction data in the plurality of storage systems supports the write-ahead log WAL model. The method includes: reading a WAL log file corresponding to the block transaction data stored in the target storage system in response to the first event of recovering the other type of blockchain data; based on the WAL log The file restores the block transaction data, and executes the recovered block transaction data to generate the other types of block chain data; write the generated block chain data of other types into the Each of the multiple storage systems is used to store the other types of blockchain data.
可选的,所述方法还包括:确定所述各存储系统存储的所述其它类型的区块链数据对应的区块号中的最新区块号C,是否小于所述目标存储系统存储的区块交易数据对应的区块号中的最新区块号N;如果是,生成所述第一事件。Optionally, the method further includes: determining whether the latest block number C among the block numbers corresponding to the other types of blockchain data stored in each storage system is smaller than the block number C stored in the target storage system The latest block number N among the block numbers corresponding to the block transaction data; if yes, the first event is generated.
可选的,所述最新区块号C为所述各存储系统中存储的所述其它类型的区块链数据对应的最新区块号的最小值;确定所述各存储系统存储的所述其它类型的区块链数据对应的最新区块号C,是否小于所述目标存储系统存储的区块交易数据对应的最新区块号N之前,还包括:计算所述各存储系统中存储的所述其它类型的区块链数据对应的最新区块号的最小值,得到所述最新区块号C。Optionally, the latest block number C is the minimum value of the latest block numbers corresponding to the other types of blockchain data stored in the storage systems; determine the other block numbers stored in the storage systems Whether the latest block number C corresponding to the type of blockchain data is less than the latest block number N corresponding to the block transaction data stored in the target storage system, it also includes: calculating the The minimum value of the latest block number corresponding to other types of blockchain data is used to obtain the latest block number C.
可选的,所述多个存储系统存储的区块链数据的数据标识,包括所述区块链数据对应的区块号。Optionally, the data identification of the blockchain data stored in the plurality of storage systems includes a block number corresponding to the blockchain data.
可选的,所述多个存储系统存储的区块链数据的数据标识,采用了统一的数据格式。Optionally, the data identifiers of the blockchain data stored in the multiple storage systems adopt a unified data format.
可选的,所述数据标识采用了WAL日志文件的LSN日志序列编号的数据格式。Optionally, the data identifier adopts the data format of the LSN log sequence number of the WAL log file.
可选的,读取与所述目标存储系统中存储的区块交易数据对应的WAL日志文件,包括:分别读取由所述最新区块号C和所述最新区块号N构成的区块号区间(C,N]中的各区块号所表示的区块中的区块交易数据对应的WAL日志文件;基于所述WAL日志文件恢复所述区块交易数据,并执行恢复出的所述区块链交易以生成所述其它类型的区块链数据,包括:基于读取到的所述区块号区间(C,N]中的各区块号表示的区块中的区块交易数据对应的WAL日志文件,恢复与所述各区块号所表示的区块中的区块交易数据,并执行恢复出的所述区块交易数据,以生成与所述各区块号所表示的区块中的区块交易数据对应的所述其它类型的区块链数据。Optionally, reading the WAL log file corresponding to the block transaction data stored in the target storage system includes: respectively reading the blocks composed of the latest block number C and the latest block number N The WAL log file corresponding to the block transaction data in the block represented by each block number in the number interval (C, N]; restore the block transaction data based on the WAL log file, and execute the restored Block chain transactions to generate the other types of block chain data, including: corresponding to the block transaction data in the block represented by each block number in the block number interval (C, N] read WAL log file, restore the block transaction data in the block represented by each block number, and execute the recovered block transaction data to generate the block transaction data in the block represented by the block number The other types of blockchain data corresponding to the block transaction data.
可选的,确定所述各存储系统存储的所述其它类型的区块链数据对应的最新区块号C,是否小于所述目标存储系统存储的区块交易数据对应的最新区块号N,包括:周期性确定所述各存储系统存储的所述其它类型的区块链数据对应的最新区块号C,是否小于所述目标存储系统存储的区块交易数据对应的最新区块号N;或者,响应于用户触发的针对所述其它类型的区块链数据进行恢复的指令,确定所述各存储系统存储的所述其它类型的区块链数据对应的最新区块号C,是否小于所述目标存储系统存储的区块交易数据对应的最新区块号N。Optionally, determine whether the latest block number C corresponding to the other types of blockchain data stored in each storage system is smaller than the latest block number N corresponding to the block transaction data stored in the target storage system, Including: periodically determining whether the latest block number C corresponding to the other types of blockchain data stored in the storage systems is smaller than the latest block number N corresponding to the block transaction data stored in the target storage system; Or, in response to user-triggered instructions for restoring the other types of blockchain data, determine whether the latest block number C corresponding to the other types of blockchain data stored in the storage systems is less than the specified The latest block number N corresponding to the block transaction data stored in the target storage system.
可选的,所述其它类型的区块链数据,包括以下示出的一个或者多个的组合:与所述区块交易数据对应的区块的区块头数据;与所述区块交易数据对应的交易收据;在所述区块交易数据执行完毕后,与所述区块链中的区块链账户对应的账户状态数据。Optionally, the other types of blockchain data include a combination of one or more of the following: the block header data of the block corresponding to the block transaction data; the block header data corresponding to the block transaction data The transaction receipt; after the block transaction data is executed, the account status data corresponding to the block chain account in the block chain.
可选的,所述方法还包括:响应于对所述区块交易数据进行恢复的第二事件,基于所述WAL日志文件恢复所述区块交易数据,并将恢复出的所述区块交易数据,写入所述目标存储系统。Optionally, the method further includes: in response to the second event of restoring the block transaction data, restoring the block transaction data based on the WAL log file, and restoring the block transaction data data, written to the target storage system.
可选的,所述方法还包括:确定与所述目标存储系统中存储的区块交易数据对应的WAL日志文件的文件数量或者存储容量是否达到阈值;如果是,生成所述第 二事件。Optionally, the method further includes: determining whether the number of files or the storage capacity of the WAL log files corresponding to the block transaction data stored in the target storage system reaches a threshold; if so, generating the second event.
可选的,确定与所述目标存储系统中存储的区块交易数据对应的WAL日志文件的文件数量或者存储容量是否达到阈值,包括:周期性确定与所述目标存储系统中存储的区块交易数据对应的WAL日志文件的文件数量或者存储容量是否达到阈值;或者,响应于用户触发的针对所述区块交易数据进行恢复的指令,确定与所述目标存储系统中存储的区块交易数据对应的WAL日志文件的文件数量或者存储容量是否达到阈值。Optionally, determining whether the number of files or the storage capacity of the WAL log files corresponding to the block transaction data stored in the target storage system reaches a threshold includes: periodically determining the block transaction data stored in the target storage system Whether the number of files or the storage capacity of the WAL log file corresponding to the data reaches the threshold; or, in response to an instruction triggered by the user to restore the block transaction data, determine that the block transaction data corresponding to the target storage system Whether the number of files or storage capacity of WAL log files reaches the threshold.
本说明书还提出一种区块链数据恢复装置,应用于节点设备;所述节点设备搭载了用于存储区块链数据的多个存储系统。其中,所述区块链数据包括区块交易数据和至少一种其它类型的区块链数据;所述多个存储系统中用于存储所述区块交易数据的目标存储系统支持预写日志WAL模式。所述装置包括:读取模块,响应于针对所述其它类型的区块链数据进行恢复的第一事件,读取与所述目标存储系统中存储的区块交易数据对应的WAL日志文件;恢复模块,基于所述WAL日志文件恢复所述区块交易数据,并执行恢复出的所述区块交易数据以生成所述其它类型的区块链数据;写入模块,将生成的所述其它类型的区块链数据,分别写入所述多个存储系统中用于存储所述其它类型的区块链数据的各存储系统。This specification also proposes a blockchain data recovery device, which is applied to node equipment; the node equipment is equipped with multiple storage systems for storing blockchain data. Wherein, the block chain data includes block transaction data and at least one other type of block chain data; the target storage system for storing the block transaction data in the plurality of storage systems supports the write-ahead log WAL model. The device includes: a reading module, which reads the WAL log file corresponding to the block transaction data stored in the target storage system in response to the first event of restoring the other types of blockchain data; Module, restores the block transaction data based on the WAL log file, and executes the recovered block transaction data to generate the other types of block chain data; writes the module, and generates the other types of block chain data The block chain data are respectively written into each storage system used to store the other types of block chain data in the plurality of storage systems.
可选的,所述装置还包括:第一确定模块,确定所述各存储系统存储的所述其它类型的区块链数据对应的区块号中的最新区块号C,是否小于所述目标存储系统存储的区块交易数据对应的区块号中的最新区块号N;如果是,生成所述第一事件。Optionally, the device further includes: a first determining module, which determines whether the latest block number C among the block numbers corresponding to the other types of blockchain data stored in the storage systems is smaller than the target The latest block number N among the block numbers corresponding to the block transaction data stored in the storage system; if yes, the first event is generated.
可选的,所述最新区块号C为所述各存储系统中存储的所述其它类型的区块链数据对应的最新区块号的最小值。所述确定模块进一步:在确定所述各存储系统存储的所述其它类型的区块链数据对应的最新区块号C,是否小于所述目标存储系统存储的区块交易数据对应的最新区块号N之前,计算所述各存储系统中存储的所述其它类型的区块链数据对应的最新区块号的最小值,得到所述最新区块号C。Optionally, the latest block number C is the minimum value of the latest block numbers corresponding to the other types of blockchain data stored in each storage system. The determination module further: after determining whether the latest block number C corresponding to the other types of blockchain data stored in the storage systems is smaller than the latest block number C corresponding to the block transaction data stored in the target storage system Before number N, calculate the minimum value of the latest block numbers corresponding to the other types of blockchain data stored in each storage system to obtain the latest block number C.
可选的,所述多个存储系统存储的区块链数据的数据标识,包括所述区块链数据对应的区块号。Optionally, the data identification of the blockchain data stored in the plurality of storage systems includes a block number corresponding to the blockchain data.
可选的,所述多个存储系统存储的区块链数据的数据标识,采用了统一的数据格式。Optionally, the data identifiers of the blockchain data stored in the multiple storage systems adopt a unified data format.
可选的,所述数据标识采用了WAL日志文件的LSN日志序列编号的数据格式。Optionally, the data identifier adopts the data format of the LSN log sequence number of the WAL log file.
可选的,所述读取模块:分别读取由所述最新区块号C和所述最新区块号N构成的区块号区间(C,N]中的各区块号所表示的区块中的区块交易数据对应的WAL日志文件;所述恢复模块:基于读取到的所述区块号区间(C,N]中的各区块号表示的区块中的区块交易数据对应的WAL日志文件,恢复与所述各区块号所表示的区块中的区块交易数据,并执行恢复出的所述区块交易数据,以生成与所述各区块号所表示的区块中的区块交易数据对应的所述其它类型的区块链数据。Optionally, the reading module: respectively read the blocks represented by the block numbers in the block number interval (C, N] formed by the latest block number C and the latest block number N] The WAL log file corresponding to the block transaction data in the block; the recovery module: based on the block transaction data corresponding to the block in the block represented by each block number in the block number interval (C, N] read WAL log file, restore the block transaction data in the blocks represented by the block numbers, and execute the recovered block transaction data to generate the block transaction data in the blocks represented by the block numbers The other types of blockchain data corresponding to the block transaction data.
可选的,所述第一确定模块:周期性确定所述各存储系统存储的所述其它类型的区块链数据对应的最新区块号C,是否小于所述目标存储系统存储的区块交易数据对应的最新区块号N;或者,响应于用户触发的针对所述其它类型的区块链数据进行恢复的指令,确定所述各存储系统存储的所述其它类型的区块链数据对应的最新区块号C,是否小于所述目标存储系统存储的区块交易数据对应的最新区块号N。Optionally, the first determining module: periodically determine whether the latest block number C corresponding to the other types of blockchain data stored in each storage system is smaller than the block transaction stored in the target storage system The latest block number N corresponding to the data; or, in response to the user-triggered instruction for restoring the other types of blockchain data, determine the corresponding block number of the other types of blockchain data stored in the storage systems Whether the latest block number C is smaller than the latest block number N corresponding to the block transaction data stored in the target storage system.
可选的,所述其它类型的区块链数据,包括以下示出的一个或者多个的组合:与所述区块交易数据对应的区块的区块头数据;与所述区块交易数据对应的交易收据;在所述区块交易数据执行完毕后,与所述区块链中的区块链账户对应的账户状态数据。Optionally, the other types of blockchain data include a combination of one or more of the following: the block header data of the block corresponding to the block transaction data; the block header data corresponding to the block transaction data The transaction receipt; after the block transaction data is executed, the account status data corresponding to the block chain account in the block chain.
可选的,所述写入模块进一步:响应于对所述区块交易数据进行恢复的第二事件,基于所述WAL日志文件恢复所述区块交易数据,并将恢复出的所述区块交易数据,写入所述目标存储系统。Optionally, the writing module further: in response to the second event of restoring the block transaction data, restore the block transaction data based on the WAL log file, and restore the block transaction data The transaction data is written into the target storage system.
可选的,所述装置还包括:第二确定模块,确定与所述目标存储系统中存储的区块交易数据对应的WAL日志文件的文件数量或者存储容量是否达到阈值;如果是,生成所述第二事件。Optionally, the device further includes: a second determining module, determining whether the number of files or the storage capacity of the WAL log files corresponding to the block transaction data stored in the target storage system reaches a threshold; if so, generating the second event.
可选的,所述第二确定模块:周期性确定与所述目标存储系统中存储的区块交易数据对应的WAL日志文件的文件数量或者存储容量是否达到阈值;或者,响应于用户触发的针对所述区块交易数据进行恢复的指令,确定与所述目标存储系统中存储的区块交易数据对应的WAL日志文件的文件数量或者存储容量是否达到阈值。Optionally, the second determination module: periodically determines whether the number of files or the storage capacity of the WAL log files corresponding to the block transaction data stored in the target storage system reaches a threshold; or, in response to user-triggered targeting The instruction for recovering the block transaction data determines whether the number of files or the storage capacity of the WAL log files corresponding to the block transaction data stored in the target storage system reaches a threshold.
以上技术方案中,一方面,由于区块链搭载的多个存储系统中,可以只有用于存储区块交易数据的目标存储系统支持预写日志WAL模式,而用于存储与该区块交易数据对应的其它类型的区块链数据的存储系统则可以不必重复启用WAL模式。因此,对于搭载多个存储系统的节点设备而言,可以只存储和维护一份与区块交易 数据对应的WAL日志文件即可,不再需要在存储和维护多份WAL日志文件,可以显著降低节点设备在存储多种区块链数据时的存储开销。Among the above technical solutions, on the one hand, due to the multiple storage systems carried by the blockchain, only the target storage system used to store the transaction data of the block supports the write-ahead log WAL mode, and is used to store the transaction data related to the block Corresponding storage systems for other types of blockchain data do not need to repeatedly enable the WAL mode. Therefore, for a node device equipped with multiple storage systems, only one WAL log file corresponding to the block transaction data can be stored and maintained, and it is no longer necessary to store and maintain multiple WAL log files, which can significantly reduce The storage overhead of node devices when storing various blockchain data.
另一方面,由于节点设备存储的与该区块交易数据对应的其它类型的区块链数据,是基于与区块交易数据对应的WAL日志文件来进行统一恢复;对于搭载多个存储系统的节点设备而言,可以不再需要基于各个存储系统对应的WAL日志文件来分别进行数据恢复;因此,可以显著降低节点设备在恢复多种区块链数据时的性能开销。On the other hand, because other types of blockchain data corresponding to the block transaction data stored by the node device are restored in a unified manner based on the WAL log file corresponding to the block transaction data; for nodes equipped with multiple storage systems As far as the device is concerned, it is no longer necessary to perform data recovery based on the WAL log files corresponding to each storage system; therefore, the performance overhead of node devices when restoring multiple blockchain data can be significantly reduced.
附图说明Description of drawings
图1是一示例性实施例提供的一种区块链数据恢复方法的流程图;Fig. 1 is a flow chart of a method for recovering blockchain data provided by an exemplary embodiment;
图2是一示例性实施例提供的一种电子设备的结构示意图;Fig. 2 is a schematic structural diagram of an electronic device provided by an exemplary embodiment;
图3是一示例性实施例提供的一种区块链数据恢复装置的框图。Fig. 3 is a block diagram of a block chain data recovery device provided by an exemplary embodiment.
具体实施方式Detailed ways
这里将详细地对示例性实施例进行说明,其示例表示在附图中。下面的描述涉及附图时,除非另有表示,不同附图中的相同数字表示相同或相似的要素。以下示例性实施例中所描述的实施方式并不代表与本说明书一个或多个实施例相一致的所有实施方式。相反,它们仅是与如所附权利要求书中所详述的、本说明书一个或多个实施例的一些方面相一致的装置和方法的例子。Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, the same numerals in different drawings refer to the same or similar elements unless otherwise indicated. Implementations described in the following exemplary embodiments do not represent all implementations consistent with one or more embodiments of this specification. Rather, they are merely examples of apparatuses and methods consistent with aspects of one or more embodiments of the present specification as recited in the appended claims.
需要说明的是:在其他实施例中并不一定按照本说明书示出和描述的顺序来执行相应方法的步骤。在一些其他实施例中,其方法所包括的步骤可以比本说明书所描述的更多或更少。此外,本说明书中所描述的单个步骤,在其他实施例中可能被分解为多个步骤进行描述;而本说明书中所描述的多个步骤,在其他实施例中也可能被合并为单个步骤进行描述。It should be noted that in other embodiments, the steps of the corresponding methods are not necessarily performed in the order shown and described in this specification. In some other embodiments, the method may include more or less steps than those described in this specification. In addition, a single step described in this specification may be decomposed into multiple steps for description in other embodiments; multiple steps described in this specification may also be combined into a single step in other embodiments describe.
区块链一般被划分为三种类型:公有链(Public Blockchain),私有链(Private Blockchain)和联盟链(Consortium Blockchain)。此外,还可以有上述多种类型的结合,比如私有链+联盟链、联盟链+公有链等。Blockchains are generally divided into three types: Public Blockchain, Private Blockchain and Consortium Blockchain. In addition, there can be a combination of the above types, such as private chain + alliance chain, alliance chain + public chain, etc.
其中,去中心化程度最高的是公有链。加入公有链的参与者(也可称为区块链中的节点)可以读取链上的数据记录、参与交易、以及竞争新区块的记账权等。而 且,各节点可自由加入或者退出网络,并进行相关操作。Among them, the public chain has the highest degree of decentralization. Participants joining the public chain (also known as nodes in the blockchain) can read data records on the chain, participate in transactions, and compete for the accounting rights of new blocks. Moreover, each node is free to join or exit the network and perform related operations.
私有链则相反,该网络的写入权限由某个组织或者机构控制,数据读取权限受组织规定。简单来说,私有链可以为一个弱中心化系统,其对节点具有严格限制且节点数量较少。这种类型的区块链更适合于特定机构内部使用。On the contrary, the private chain, the write permission of the network is controlled by an organization or institution, and the data read permission is regulated by the organization. In simple terms, a private chain can be a weakly centralized system with strict restrictions on nodes and a small number of nodes. This type of blockchain is more suitable for internal use by specific institutions.
联盟链则是介于公有链以及私有链之间的区块链,可实现“部分去中心化”。联盟链中各个节点通常有与之相对应的实体机构或者组织;节点通过授权加入网络并组成利益相关联盟,共同维护区块链运行。The alliance chain is a blockchain between the public chain and the private chain, which can realize "partial decentralization". Each node in the consortium chain usually has a corresponding entity or organization; nodes join the network through authorization and form an alliance of stakeholders to jointly maintain the operation of the blockchain.
基于区块链的基本特性,区块链通常是由若干个区块构成。在这些区块中分别记录有与该区块的创建时刻对应的时间戳,所有的区块严格按照区块中记录的时间戳,构成一条在时间上有序的数据链条。Based on the basic characteristics of the blockchain, the blockchain is usually composed of several blocks. Time stamps corresponding to the creation time of the block are respectively recorded in these blocks, and all blocks form a time-ordered data chain in strict accordance with the time stamps recorded in the block.
对于物理世界产生的真实数据,可以将其构建成区块链所支持的标准的交易(transaction)格式,然后发布至区块链,由区块链中的节点设备对收到的交易进行共识处理,并在达成共识后,由区块链中作为记账节点的节点设备,将这笔交易打包进区块,在区块链中进行持久化存证。For the real data generated in the physical world, it can be constructed into a standard transaction format supported by the blockchain, and then published to the blockchain, and the node devices in the blockchain will perform consensus processing on the received transactions , and after a consensus is reached, the node device in the blockchain as the bookkeeping node will package the transaction into a block and store the certificate persistently in the blockchain.
其中,区块链中支持的共识算法可以包括:第一类共识算法,即节点设备需要争夺每一轮的记账周期的记账权的共识算法,例如,工作量证明(Proof of Work,POW)、股权证明(Proof of Stake,POS)、委任权益证明(Delegated Proof of Stake,DPOS)等共识算法;第二类共识算法,即预先为每一轮记账周期选举记账节点(不需要争夺记账权)的共识算法;例如,实用拜占庭容错(Practical Byzantine Fault Tolerance,PBFT)等共识算法。Among them, the consensus algorithms supported in the blockchain can include: the first type of consensus algorithm, that is, the consensus algorithm that node devices need to compete for the accounting rights of each round of accounting cycle, for example, proof of work (Proof of Work, POW ), proof of equity (Proof of Stake, POS), delegated proof of equity (Delegated Proof of Stake, DPOS) and other consensus algorithms; the second type of consensus algorithm is to pre-elect accounting nodes for each round of accounting cycle (no need to compete Bookkeeping rights) consensus algorithms; for example, consensus algorithms such as Practical Byzantine Fault Tolerance (PBFT).
在采用第一类共识算法的区块链网络中,争夺记账权的节点设备,都可以在接收到交易后执行该笔交易。争夺记账权的节点设备中可能有一个节点设备在本轮争夺记账权的过程中胜出,成为记账节点。记账节点可以将收到的交易与其它交易一起打包以生成最新区块,并将生成的最新区块或者该最新区块的区块头发送至其它节点设备进行共识。In the blockchain network using the first type of consensus algorithm, the node devices competing for the bookkeeping right can execute the transaction after receiving the transaction. Among the node devices competing for bookkeeping rights, there may be a node device that wins the current round of competition for bookkeeping rights and becomes a bookkeeping node. The accounting node can package the received transaction with other transactions to generate the latest block, and send the generated latest block or the block header of the latest block to other node devices for consensus.
在采用第二类共识算法的区块链网络中,具有记账权的节点设备在本轮记账前已经商定好。因此,节点设备在接收到交易后,如果自身不是本轮的记账节点,则可以将该交易发送至记账节点。对于本轮的记账节点,在将该交易与其它交易一起打包以生成最新区块的过程中或者之前,可以执行该交易。记账节点在生成最新区 块后,可以将该最新区块或者该最新区块的区块头发送至其它节点设备进行共识。In the blockchain network using the second type of consensus algorithm, the node equipment with bookkeeping rights has been agreed before the current round of bookkeeping. Therefore, after the node device receives the transaction, if it is not the accounting node of the current round, it can send the transaction to the accounting node. For the bookkeeping nodes of this round, the transaction can be executed during or before the process of packaging the transaction with other transactions to generate the latest block. After the accounting node generates the latest block, it can send the latest block or the block header of the latest block to other node devices for consensus.
如上所述,无论区块链采用以上示出的哪种共识算法,本轮的记账节点都可以将接收到的交易打包以生成最新区块,并将生成的最新区块或者该最新区块的区块头发送至其它节点设备进行共识验证。如果其它节点设备接收到最新区块或者该最新区块的区块头后,经验证没有问题,可以将该最新区块追加到原有的区块链末尾,从而完成区块链的记账过程。其它节点验证记账节点发来的新的区块或区块头的过程中,也可以执行该区块中的包含的交易。As mentioned above, no matter which consensus algorithm the blockchain adopts, the bookkeeping nodes of this round can package the received transactions to generate the latest block, and will generate the latest block or the latest block The block header is sent to other node devices for consensus verification. If other node devices receive the latest block or the block header of the latest block and verify that there is no problem, the latest block can be appended to the end of the original blockchain to complete the accounting process of the blockchain. In the process of verifying the new block or block header sent by the bookkeeping node, other nodes can also execute the transactions contained in the block.
在区块链领域,有一个重要的概念就是账户(Account);以以太坊为例,以太坊通常将账户划分为外部账户和合约账户两类;外部账户就是由用户直接控制的账户,也称之为用户账户;而合约账户则是由用户通过外部账户创建的,包含合约代码的账户(即智能合约)。In the field of blockchain, an important concept is account (Account); taking Ethereum as an example, Ethereum usually divides accounts into two types: external accounts and contract accounts; external accounts are accounts directly controlled by users, also known as It is a user account; while a contract account is an account created by a user through an external account and contains a contract code (that is, a smart contract).
当然,对于一些基于以太坊的架构而衍生出的区块链模型(比如蚂蚁区块链),还可以对区块链支持的账户类型,进行进一步的扩展,在本说明书中不进行特别限定。Of course, for some blockchain models derived from the Ethereum-based architecture (such as Ant Blockchain), the account types supported by the blockchain can also be further expanded, which is not specifically limited in this manual.
对于区块链中的账户而言,通常会通过一个结构体,来维护账户的账户状态。当区块中的交易被执行后,区块链中与该交易相关的账户的状态通常也会发生变化。For accounts in the blockchain, a structure is usually used to maintain the account status of the account. When a transaction in a block is executed, the state of the account associated with the transaction in the blockchain usually also changes.
以以太坊为例,账户的结构体通常包括Balance,Nonce,Code和Storage等字段。其中:Taking Ethereum as an example, the account structure usually includes fields such as Balance, Nonce, Code, and Storage. in:
Balance字段,用于维护账户目前的账户余额;The Balance field is used to maintain the current account balance of the account;
Nonce字段,用于维护该账户的交易次数;它是用于保障每笔交易能且只能被处理一次的计数器,有效避免重放攻击;The Nonce field is used to maintain the number of transactions of the account; it is a counter used to ensure that each transaction can only be processed once, effectively avoiding replay attacks;
Code字段,用于维护该账户的合约代码;在实际应用中,Code字段中通常仅维护合约代码的hash值;因而,Code字段通常也称之为Codehash字段。The Code field is used to maintain the contract code of the account; in practical applications, only the hash value of the contract code is usually maintained in the Code field; therefore, the Code field is usually also called the Codehash field.
Storage字段,用于维护该账户的存储内容(默认字段值为空);对于合约账户而言,通常会分配一个独立的存储空间,用以存储该合约账户的存储内容;该独立的存储空间通常称之为该合约账户的账户存储。合约账户的存储内容通常会构建成MPT(Merkle Patricia Trie)树的数据结构存储在上述独立的存储空间之中;其中,基于合约账户的存储内容构建成的MPT树,通常也称之为Storage树。而Storage 字段通常仅维护该Storage树的根节点的hash值;因此,Storage字段通常也称之为Storage Root hash字段。其中,对于外部账户而言,以上示出的Code字段和Storage字段的字段值均为空值。The Storage field is used to maintain the storage content of the account (the default field value is empty); for the contract account, an independent storage space is usually allocated to store the storage content of the contract account; the independent storage space is usually It is called the account storage of the contract account. The storage content of the contract account is usually built into a data structure of MPT (Merkle Patricia Trie) tree and stored in the above-mentioned independent storage space; among them, the MPT tree constructed based on the storage content of the contract account is usually also called the Storage tree . The Storage field usually only maintains the hash value of the root node of the Storage tree; therefore, the Storage field is usually also called the Storage Root hash field. Wherein, for the external account, the field values of the Code field and the Storage field shown above are all null values.
对于大多数区块链模型,通常都会使用Merkle树的数据结构;或者,基于Merkle树的数据结构,来存储和维护区块链数据。For most blockchain models, the data structure of the Merkle tree is usually used; or, the data structure based on the Merkle tree is used to store and maintain the blockchain data.
其中,对于节点设备来说,需要存储和维护的区块链数据,通常包括区块数据、区块链中的区块链账户对应的账户状态数据;而区块数据又进一步包括区块头数据、区块中的区块交易数据、以及与区块中的区块交易数据对应的交易收据,等等。需要说明的是,在实际应用中,节点设备除了需要存储和维护区块链数据以外,也需要存储和维护与区块链数据对应的索引数据。Among them, for node devices, the blockchain data that needs to be stored and maintained usually includes block data, account status data corresponding to the blockchain account in the blockchain; and the block data further includes block header data, The block transaction data in the block, and the transaction receipt corresponding to the block transaction data in the block, and so on. It should be noted that in practical applications, in addition to storing and maintaining blockchain data, node devices also need to store and maintain index data corresponding to blockchain data.
例如,以以太坊为例,以太坊使用了MPT树,作为数据组织形式,用来组织和管理账户状态、交易信息等重要数据。其中,MPT树是一种融合了Trie字典树的树形结构的Merkle树变种。For example, taking Ethereum as an example, Ethereum uses the MPT tree as a form of data organization to organize and manage important data such as account status and transaction information. Among them, the MPT tree is a Merkle tree variant that combines the tree structure of the Trie dictionary tree.
以太坊针对区块链中需要存储和维护的区块链数据,设计了三棵MPT树,分别是MPT状态树、MPT交易树和MPT收据树。其中,除了以上三棵MPT树以外,实际上还存在一棵基于合约账户的存储内容构建的Storage树。For the blockchain data that needs to be stored and maintained in the blockchain, Ethereum has designed three MPT trees, namely the MPT state tree, MPT transaction tree and MPT receipt tree. Among them, in addition to the above three MPT trees, there is actually a Storage tree built based on the storage content of the contract account.
MPT状态树,是由区块链中所有账户的账户状态(state)数据组织成的MPT树;MPT交易树,是由区块链中的交易(transaction)数据组织成的MPT树;MPT收据树,是区块中的交易在执行完毕后生成的与每笔交易对应的交易(receipt)收据组织成的MPT树。以上示出的MPT状态树、MPT交易树和MPT收据树的根节点的hash值,最终都会被添加至对应区块的区块头中。The MPT state tree is an MPT tree organized by the account state (state) data of all accounts in the blockchain; the MPT transaction tree is an MPT tree organized by the transaction (transaction) data in the blockchain; the MPT receipt tree , is the MPT tree organized by the transaction (receipt) receipt corresponding to each transaction generated after the transaction in the block is executed. The hash values of the root nodes of the MPT state tree, MPT transaction tree and MPT receipt tree shown above will eventually be added to the block header of the corresponding block.
其中,MPT交易树和MPT收据树均与区块相对应,即每一个区块都有自己的MPT交易树和MPT收据树。而MPT状态树是一个全局的MPT树,并不与某一个特定的区块相对应,而是涵盖了区块链中所有账户的账户状态数据。Among them, the MPT transaction tree and MPT receipt tree correspond to blocks, that is, each block has its own MPT transaction tree and MPT receipt tree. The MPT state tree is a global MPT tree, which does not correspond to a specific block, but covers the account state data of all accounts in the blockchain.
以下以MPT状态树为例进行举例说明。The following uses the MPT state tree as an example for illustration.
区块链每产生一个最新区块,则在该最新区块中的交易被执行之后,区块链中这些被执行交易的相关账户(可以是外部账户也可以是合约账户)的账户状态,通常也会随之发生变化。例如,当区块中的一笔“转账交易”执行完毕后,与该“转账交易”相关的转出方账户和转入方账户的余额(即这些账户的Balance字段的字段值), 通常也会随之发生变化。Every time the blockchain generates the latest block, after the transactions in the latest block are executed, the account status of the accounts (which can be external accounts or contract accounts) related to these executed transactions in the blockchain, usually It will also change accordingly. For example, when a "transfer transaction" in a block is executed, the balances of the transfer-out account and transfer-in account related to the "transfer transaction" (that is, the field value of the Balance field of these accounts) are usually also Will change accordingly.
而节点设备在区块链产生的最新区块中的交易执行完毕后,由于当前区块链中的账户状态发生了变化,因此节点设备需要根据区块链中所有账户当前的账户状态数据,来构建MPT状态树,用于维护区块链中所有账户的最新状态。After the transaction of the node device in the latest block generated by the blockchain is completed, because the account status in the current blockchain has changed, the node device needs to use the current account status data of all accounts in the blockchain. Build an MPT state tree to maintain the latest state of all accounts in the blockchain.
也即,每当区块链中产生一个最新区块,并且该最新区块中的交易执行完毕后,导致区块链中的账户状态发生了变化,节点设备都需要基于区块链中所有账户最新的账户状态数据,重新构建一棵MPT状态树。That is, whenever a latest block is generated in the blockchain, and after the transaction in the latest block is executed, the account status in the blockchain changes, the node device needs to be based on all accounts in the blockchain The latest account status data rebuilds an MPT status tree.
换句话说,区块链中每一个区块,都有一颗与之对应的MPT状态树;该MPT状态树,维护了在该区块中的交易在执行完毕后,区块链中所有账户最新的账户状态。In other words, each block in the blockchain has a corresponding MPT state tree; the MPT state tree maintains all accounts in the blockchain after the transactions in the block are executed. account status.
在实际应用中,由于区块链通常会与链外的各种业务系进行对接,来进行多方的数据和工作流协作(跟业务无关);例如,一个与区块链对接的业务系统A,可以将相关的业务数据发布到区块链上,来驱动另一个与区块链对接的业务系统B,基于该业务数据执行进一步的业务处理;而不同类型的区块链数据,在多方的数据和工作流协作的过程中,实际起到的作用可能互不相同;节点设备在存储和维护区块链数据时,通常会搭载多个存储系统,并将不同类型的区块链数据分别存储到不同的存储系统中。In practical applications, since the blockchain usually connects with various business systems outside the chain for multi-party data and workflow collaboration (independent of business); for example, a business system A connected to the blockchain, Relevant business data can be published to the blockchain to drive another business system B that is connected to the blockchain to perform further business processing based on the business data; and for different types of blockchain data, the multi-party data In the process of cooperating with the workflow, the actual functions may be different from each other; when node devices store and maintain blockchain data, they usually carry multiple storage systems and store different types of blockchain data in the in different storage systems.
例如,在一个例子中,节点设备可以搭载3个不同的存储系统,将区块数据、state数据(即上述账户状态数据)、以及上述2种数据对应的索引数据(比如以上两种数据的hash值),分别存储在不同的存储系统中。(5份WAL分别举例)。For example, in one example, the node device can be equipped with three different storage systems, which store block data, state data (that is, the above account status data), and index data corresponding to the above two types of data (such as the hash of the above two types of data) value), which are stored in different storage systems. (5 copies of WAL are examples respectively).
在另一个例子中,节点设备可以将区块头数据、区块交易数据、与区块交易数据对应的交易收据、state数据(即上述账户状态数据)、以及上述4种数据对应的索引数据(比如以上4种数据的hash值),分别存储在不同的存储系统中;在这种情况下,节点设备可以搭载5个不同的存储系统,分别将区块头数据、区块交易数据、与区块交易数据对应的交易收据、state数据、以及上述4种数据对应的索引数据,分别存储在这5个不同的存储系统中。In another example, the node device can combine block header data, block transaction data, transaction receipts corresponding to block transaction data, state data (that is, the above-mentioned account status data), and index data corresponding to the above four types of data (such as The hash values of the above 4 kinds of data) are stored in different storage systems; in this case, the node device can be equipped with 5 different storage systems, which respectively store block header data, block transaction The transaction receipt, state data corresponding to the data, and the index data corresponding to the above four types of data are stored in these five different storage systems.
节点设备在将不同类型的区块链数据,分别存储到在搭载的不同的存储系统中时,为了防止由于数据未写入造成的数据丢失,各个存储系统可以开启WAL(write ahead logging,预写日志)模式。When node devices store different types of blockchain data in different storage systems, in order to prevent data loss due to unwritten data, each storage system can enable WAL (write ahead logging, pre-written log) mode.
其中,WAL模式,是一种高效的日志算法。在开启WAL模式的存储系统中,所有针对存储系统的数据修改,在提交到存储系统中之前,都会先写入WAL日志文件中;然后,再通过周期性触发或者用户手动触发的checkpoint事件,将WAL日志文件中存储的数据修改,写入到存储系统中。Among them, the WAL mode is an efficient log algorithm. In the storage system with WAL mode enabled, all data modification for the storage system will be written into the WAL log file before being submitted to the storage system; then, through the checkpoint event triggered periodically or manually by the user, the The data stored in the WAL log file is modified and written to the storage system.
通过为节点设备搭载的存储系统开启WAL模式,虽然可以防止由于数据未写入造成的数据丢失,但对于节点设备存储的区块链账本中,往往包含多种不同类型的区块链数据,需要存储在不同的存储系统中;因此,存储多分多份WAL日志文件会增加节点设备的存储开销;而且,节点设备在将多份WAL日志文件中存储的数据修改恢复到存储系统时,需要多次执行相关的恢复流程,也会增加节点设备的性能开销。By enabling the WAL mode for the storage system on the node device, although data loss due to unwritten data can be prevented, the blockchain ledger stored by the node device often contains many different types of blockchain data. Stored in different storage systems; therefore, storing multiple WAL log files will increase the storage overhead of the node device; moreover, when the node device restores the data modification stored in multiple WAL log files to the storage system, it needs multiple times Executing the related recovery process will also increase the performance overhead of the node device.
有鉴于此,本说明书提出一种利用节点设备存储的一份与区块链交易数据对应的WAL日志文件,对多种区块链数据进行恢复的技术方案。In view of this, this manual proposes a technical solution for recovering various blockchain data by using a WAL log file stored in the node device and corresponding to the blockchain transaction data.
在实现时,区块链的节点设备可以搭载用于存储区块链数据的多个存储系统。其中,上述区块链数据可以包括区块交易数据和至少一种与其它类型的区块链数据;上述多个存储系统中用于存储该区块交易数据的目标存储系统可以支持预写日志WAL模式。当节点设备响应于针对上述其它类型的区块链数据进行恢复的第一事件时,可以读取与该目标存储系统中存储的区块交易数据对应的WAL日志文件;再基于读取到的WAL日志文件恢复上述区块交易数据,当上述区块交易数据恢复完成后,再进一步执行恢复出的该区块交易数据,以生成上述其它类型的区块链数据;然后,再将生成的上述其它类型的区块链数据,分别写入上述多个存储系统中用于存储上述其它类型的区块链数据的各存储系统。When implemented, the node device of the blockchain can be equipped with multiple storage systems for storing blockchain data. Wherein, the aforementioned block chain data may include block transaction data and at least one type of block chain data with other types; the target storage system used to store the block transaction data in the above-mentioned multiple storage systems may support the write-ahead log WAL model. When the node device responds to the first event of recovering the above-mentioned other types of blockchain data, it can read the WAL log file corresponding to the block transaction data stored in the target storage system; then based on the read WAL The log file restores the above-mentioned block transaction data. After the above-mentioned block transaction data is restored, the restored block transaction data is further executed to generate the above-mentioned other types of block chain data; then, the generated above-mentioned other Types of blockchain data are respectively written into the storage systems used to store the other types of blockchain data in the above-mentioned multiple storage systems.
在以上技术方案中,以上技术方案中,一方面,由于区块链搭载的多个存储系统中,可以只有用于存储区块交易数据的目标存储系统支持预写日志WAL模式,而用于存储与该区块交易数据对应的其它类型的区块链数据的存储系统则可以不必重复启用WAL模式。因此,对于搭载多个存储系统的节点设备而言,可以只存储和维护一份与区块交易数据对应的WAL日志文件即可,不再需要在存储和维护多份WAL日志文件,可以显著降低节点设备在存储多种区块链数据时的存储开销。In the above technical solutions, on the one hand, due to the multiple storage systems carried by the blockchain, only the target storage system for storing block transaction data supports the write-ahead log WAL mode, and for storing The storage system of other types of blockchain data corresponding to the block transaction data does not need to repeatedly enable the WAL mode. Therefore, for a node device equipped with multiple storage systems, only one WAL log file corresponding to the block transaction data can be stored and maintained, and it is no longer necessary to store and maintain multiple WAL log files, which can significantly reduce The storage overhead of node devices when storing various blockchain data.
另一方面,由于节点设备存储的与该区块交易数据对应的其它类型的区块链数据,是基于与区块交易数据对应的WAL日志文件来进行统一恢复;对于搭载多个存储系统的节点设备而言,可以不再需要基于各个存储系统对应的WAL日志文件 来分别进行数据恢复;因此,可以显著降低节点设备在恢复多种区块链数据时的性能开销。On the other hand, because other types of blockchain data corresponding to the block transaction data stored by the node device are restored in a unified manner based on the WAL log file corresponding to the block transaction data; for nodes equipped with multiple storage systems As far as the device is concerned, it is no longer necessary to perform data recovery based on the WAL log files corresponding to each storage system; therefore, the performance overhead of node devices when restoring multiple blockchain data can be significantly reduced.
请参见图1,图1是一示例性实施例提供的一种区块链数据恢复方法的流程图。所述方法应用于区块链节点设备;其中,所述区块链数据包括区块交易数据和至少一种与所述区块交易数据对应的其它类型的区块链数据;所述多个存储系统中用于存储所述区块交易数据的目标存储系统支持预写日志WAL模式。所述方法包括以下步骤:Please refer to FIG. 1, which is a flow chart of a blockchain data recovery method provided by an exemplary embodiment. The method is applied to a block chain node device; wherein, the block chain data includes block transaction data and at least one other type of block chain data corresponding to the block transaction data; the plurality of stored The target storage system used to store the block transaction data in the system supports the write-ahead log WAL mode. The method comprises the steps of:
步骤102,响应于针对所述其它类型的区块链数据进行恢复的第一事件,读取与所述目标存储系统中存储的区块交易数据对应的WAL日志文件; Step 102, in response to the first event of recovering the other types of blockchain data, read the WAL log file corresponding to the block transaction data stored in the target storage system;
步骤104,基于所述WAL日志文件恢复所述区块交易数据,并执行恢复出的所述区块交易数据以生成所述其它类型的区块链数据; Step 104, recovering the block transaction data based on the WAL log file, and executing the recovered block transaction data to generate the other types of blockchain data;
步骤106,将生成的所述其它类型的区块链数据,分别写入所述多个存储系统中用于存储所述其它类型的区块链数据的各存储系统。 Step 106, writing the generated blockchain data of other types into storage systems for storing the blockchain data of other types among the multiple storage systems.
在本说明书中,节点设备存储的区块链账本中,通常会包括多种不同类型的区块链数据。而上述多种不同类型的区块链数据,通常可以包括区块数据、区块链中的区块链账户对应的账户状态数据,等等。其中,区块数据通常包括区块头数据和区块体数据;上述区块体数据,又进一步包括区块中的区块交易数据、以及与区块中的区块交易数据对应的交易收据,等等。In this specification, the blockchain ledger stored by the node device usually includes various types of blockchain data. The various types of blockchain data mentioned above may generally include block data, account status data corresponding to blockchain accounts in the blockchain, and so on. Among them, the block data usually includes block header data and block body data; the above block body data further includes block transaction data in the block, and transaction receipts corresponding to the block transaction data in the block, etc. wait.
在实际应用中,为便于对存储的区块链数据进行查询检索,除了以上列举的区块链数据以外,节点设备通常还需要存储和维护与上述各种区块链数据对应的索引数据。其中,上述索引数据的具体形式,在本说明书中不进行特别限定。In practical applications, in order to facilitate query and retrieval of stored blockchain data, in addition to the blockchain data listed above, node devices usually need to store and maintain index data corresponding to the above-mentioned various blockchain data. Wherein, the specific form of the above-mentioned index data is not particularly limited in this specification.
例如,对于支持对区块链账本中存储的区块链数据进行内容寻址的区块链系统,具体可以将上述区块链数据的内容摘要(比如hash值),作为该区块链数据的索引数据,从而使得用户可以将上述区块链数据的内容摘要作为查询索引,来查询和访问区块链账本中相关的区块链数据。For example, for a blockchain system that supports content addressing of the blockchain data stored in the blockchain ledger, specifically, the content summary (such as hash value) of the above blockchain data can be used as the Index data, so that users can use the content summary of the above blockchain data as a query index to query and access related blockchain data in the blockchain ledger.
对于不支持对区块链账户中存储的区块链数据进行内容寻址的区块链系统,则具体可以将由区块链系统为存储的区块链数据设置的数据标识(比如数据编号),作为该区块链数据的索引数据,从而使得用户可以将上述区块链数据的数据标识作为查询索引,来查询和访问区块链账本中相关的区块链数据。For a blockchain system that does not support content addressing of the blockchain data stored in the blockchain account, the data identifier (such as the data number) set by the blockchain system for the stored blockchain data can be specified, As the index data of the blockchain data, users can use the data identification of the above blockchain data as a query index to query and access the relevant blockchain data in the blockchain ledger.
节点设备在存储和维护以上列举的各种区块链数据时,可以搭载多个存储系统,并将不同类型的区块链数据分别存储到不同的存储系统中。其中,上述存储系统,具体可以包括任意形式的,用于对区块链账本中的区块链数据进行持久化存储的存储系统;例如,在实际应用中,上述存储系统具体可以是节点设备搭载的数据库、文件系统,等等,在本说明书中不进行特别限定。When storing and maintaining the various blockchain data listed above, the node device can be equipped with multiple storage systems, and store different types of blockchain data in different storage systems. Among them, the above-mentioned storage system can specifically include any form of storage system for persistent storage of blockchain data in the blockchain ledger; for example, in practical applications, the above-mentioned storage system can specifically be a node device carrying The database, file system, etc., are not particularly limited in this specification.
需要说明的是,由于区块头数据、与区块交易数据对应的交易收据、state数据(即上述账户状态数据)等数据;通常都可以通过重新执行区块中的区块交易(即交易重放)数据恢复出来;因此,上述区块交易数据可以作为其它类型的区块链数据的“根数据”;节点设备在存储以上示出的各种类型的区块链数据时,可以将上述区块交易数据与其它类型的区块链数据分别存储在不同的存储系统中。It should be noted that due to data such as block header data, transaction receipts corresponding to block transaction data, and state data (that is, the above-mentioned account state data); ) data is recovered; therefore, the above-mentioned block transaction data can be used as the "root data" of other types of blockchain data; when the node device stores the various types of blockchain data shown above, the above-mentioned block can be Transaction data and other types of blockchain data are stored in separate storage systems.
例如,在一个例子中,节点设备可以搭载5个不同的存储系统,分别将区块交易数据、以及与区块交易数据对应的区块的区块头数据、与区块交易数据对应的交易收据、state数据、以及上述4种数据对应的索引数据,分别存储在这5个不同的存储系统中。For example, in one example, the node device can be equipped with five different storage systems, which respectively store the block transaction data, the block header data of the block corresponding to the block transaction data, the transaction receipt corresponding to the block transaction data, The state data and the index data corresponding to the above four types of data are stored in these five different storage systems.
在本说明书中,为了防止由于上述“根数据”未写入造成的“根数据”丢失,各个存储系统中用于存储“根数据”(即区块交易数据)的目标存储系统,可以开启WAL模式。在开启WAL模式后,所有针对该目标存储系统的数据修改(比如写入新的区块交易数据),在提交到该目标存储系统中之前,都会以WAL日志文件的形式先写入到与该目标存储系统对应的WAL日志缓冲区;其中,日志缓冲区具体也可以是一个持久化存储;然后,当区块链系统触发了与上述目标存储系统对应的checkpoint事件时,节点设备可以响应该checkpoint事件,再将WAL日志文件中存储的对上述“根数据”数据修改,恢复到目标存储系统中。In this specification, in order to prevent the loss of "root data" caused by the above-mentioned "root data" not being written, the target storage system used to store "root data" (that is, block transaction data) in each storage system can open WAL model. After the WAL mode is turned on, all data modifications (such as writing new block transaction data) for the target storage system will be written to the target storage system in the form of a WAL log file before being submitted to the target storage system. The WAL log buffer corresponding to the target storage system; the log buffer can also be a persistent storage; then, when the blockchain system triggers a checkpoint event corresponding to the above target storage system, the node device can respond to the checkpoint Event, and then modify the above "root data" data stored in the WAL log file, and restore it to the target storage system.
其中,上述checkpoint事件是指基于WAL日志文件对存储系统中存储的区块链数据进行数据恢复的事件。Wherein, the above-mentioned checkpoint event refers to an event of performing data recovery on the blockchain data stored in the storage system based on the WAL log file.
而对于各个存储系统中用于存储“根数据”以外的其它类型的区块链数据的其它各存储系统,则可以不开启WAL模式,而是基于与上述目标存储系统对应的WAL日志文件进行跨存储系统的数据恢复;也即,未开启WAL模式的存储系统也可以通过其它开启WAL模式的存储系统对应的WAL日志文件进行数据恢复。For other storage systems used to store other types of blockchain data other than "root data" in each storage system, the WAL mode may not be enabled, but cross-storage based on the WAL log files corresponding to the above-mentioned target storage systems. Data recovery of the storage system; that is, a storage system that does not enable the WAL mode can also perform data recovery through the corresponding WAL log files of other storage systems that enable the WAL mode.
在这种情况下,区块链系统也可以对未开启WAL模式的上述其它各存储系统的 checkpoint事件;而当区块链系统触发了与上述其它各存储系统对应的checkpoint事件时,节点设备可以响应该checkpoint事件,读取上述目标存储系统对应的WAL日志文件进行数据恢复计算,再基于数据恢复计算的计算结果,对上述其它各存储系统中存储的其它类型的区块链数据进行跨存储系统的数据恢复。In this case, the blockchain system can also checkpoint events of the above-mentioned other storage systems that have not opened the WAL mode; and when the blockchain system triggers the checkpoint events corresponding to the above-mentioned other storage systems, the node device can In response to the checkpoint event, read the WAL log file corresponding to the above-mentioned target storage system for data recovery calculation, and then based on the calculation results of the data recovery calculation, cross-storage system data for other types of blockchain data stored in the other storage systems mentioned above data recovery.
在本说明书中,节点设备对上述目标存储系统中存储的区块交易数据进行恢复的流程,和对上述其它各存储系统中存储的其它类型的区块链数据进行恢复的流程,可以是两个互相独立的流程,在本说明书中不对二者的执行顺序进行特别的限定。In this specification, the process for the node device to recover the block transaction data stored in the above-mentioned target storage system, and the process for recovering other types of blockchain data stored in the above-mentioned other storage systems can be two The procedures that are independent of each other are not particularly limited in the execution sequence of the two in this specification.
也即,在实际应用中,节点设备可以先执行对上述目标存储系统中存储的区块交易数据进行恢复的流程,再执行对上述其它各存储系统中存储的其它类型的区块链数据进行恢复的流程;也可以先执行对上述其它各存储系统中存储的其它类型的区块链数据进行恢复的流程,再执行对上述目标存储系统中存储的区块交易数据进行恢复的流程定。That is to say, in practical applications, the node device can first perform the process of recovering the block transaction data stored in the above-mentioned target storage system, and then perform recovery of other types of blockchain data stored in the above-mentioned other storage systems The process of recovering other types of blockchain data stored in the above-mentioned other storage systems can also be performed first, and then the process of recovering the block transaction data stored in the above-mentioned target storage system can be performed.
需要说明的是,由于对上述目标存储系统中存储的区块交易数据进行恢复的流程,也是基于与上述区块交易数据对应的WAL日志文件来完成的;因此,如果节点设备先执行对上述目标存储系统中存储的区块交易数据进行恢复的流程,则需要在上述区块交易数据恢复完毕后,暂时不删除日志缓冲区存储的与上述区块交易数据对应的WAL日志文件;当节点设备开始执行对上述其它各存储系统中存储的其它类型的区块链数据进行恢复的流程,可以继续基于上述WAL日志文件对上述其它各存储系统中存储的其它类型的区块链数据进行恢复,并在恢复完成后再将该WAL日志文件从日志缓冲区删除。It should be noted that the process of recovering the block transaction data stored in the above-mentioned target storage system is also completed based on the WAL log file corresponding to the above-mentioned block transaction data; therefore, if the node device first executes the above-mentioned target The process of recovering the block transaction data stored in the storage system needs to temporarily not delete the WAL log file corresponding to the above block transaction data stored in the log buffer after the above block transaction data is restored; when the node device starts Execute the process of recovering other types of blockchain data stored in the above-mentioned other storage systems, and continue to restore other types of blockchain data stored in the above-mentioned other storage systems based on the above-mentioned WAL log files, and in After recovery is complete, delete the WAL log file from the log buffer.
其中,还需要说明的是,由于节点设备对上述目标存储系统中存储的区块交易数据进行恢复的流程,和对上述其它各存储系统中存储的其它类型的区块链数据进行恢复的流程,是两个互相独立的流程;因此,区块链系统触发的与上述目标存储系统对应的checkpoint事件,和区块链系统触发的与上述其它各存储系统对应的checkpoint事件对应的触发条件,也可以互不相同。Among them, it also needs to be explained that due to the process of the node device recovering the block transaction data stored in the above-mentioned target storage system, and the process of recovering other types of blockchain data stored in the above-mentioned other storage systems, are two mutually independent processes; therefore, the checkpoint event triggered by the blockchain system corresponding to the above target storage system, and the trigger condition corresponding to the checkpoint event triggered by the blockchain system corresponding to the other storage systems above can also be different from each other.
其中,为了便于描述,对于区块链系统触发的与上述其它各存储系统对应的checkpoint事件,将称之为“第一事件”;对于区块链系统触发的与上述目标存储系统对应的checkpoint事件,将称之为“第二事件”。Among them, for the convenience of description, the checkpoint event triggered by the blockchain system and corresponding to the above-mentioned other storage systems will be called "the first event"; the checkpoint event triggered by the blockchain system and corresponding to the above-mentioned target storage system , which will be referred to as the "second event".
在示出的一种实施方式中,基于WAL的数据恢复机制,上述第一事件的触发条件,通常可以包括与上述目标存储系统中存储的区块交易数据对应的WAL日志文件的文件数量达到阈值;或者,与上述目标存储系统中存储的区块交易数据对应的WAL日志文件的存储容量达到阈值。In one embodiment shown, in the WAL-based data recovery mechanism, the trigger condition of the above-mentioned first event may generally include that the number of WAL log files corresponding to the block transaction data stored in the above-mentioned target storage system reaches a threshold ; Or, the storage capacity of the WAL log file corresponding to the block transaction data stored in the above target storage system reaches a threshold.
也即,当与上述目标存储系统中存储的区块交易数据对应的WAL日志文件的文件数量达到阈值;或者,与上述目标存储系统中存储的区块交易数据对应的WAL日志文件的存储容量达到阈值,可以触发区块链系统生成上述第一事件。That is, when the number of WAL log files corresponding to the block transaction data stored in the above-mentioned target storage system reaches a threshold; or, the storage capacity of the WAL log files corresponding to the block transaction data stored in the above-mentioned target storage system reaches The threshold can trigger the blockchain system to generate the above-mentioned first event.
在示出的另一种实施方式中,由于对上述其它各存储系统中存储的其它类型的区块链数据的数据恢复,是基于与上述目标存储系统对应的WAL日志文件进行的跨存储系统的数据恢复,与基于WAL日志文件对上述目标存储系统存储的区块交易数据进行本地数据恢复有所不同;因此,上述第二事件的触发条件,可以与基于WAL的数据恢复机制的checkpoint事件的触发条件存在差异。上述第二事件的触发条件,具体可以包括上述其它各存储系统存储的上述其它类型的区块链数据对应的区块号中的最新区块号C,小于上述目标存储系统存储的区块交易数据对应的区块号中的最新区块号N。In another embodiment shown, due to the data recovery of other types of blockchain data stored in the above-mentioned other storage systems, it is based on the WAL log files corresponding to the above-mentioned target storage systems. Data recovery is different from the local data recovery of the block transaction data stored in the target storage system based on the WAL log file; therefore, the triggering condition of the second event above can be the same as the triggering of the checkpoint event of the WAL-based data recovery mechanism Conditions vary. The trigger condition of the above-mentioned second event may specifically include that the latest block number C among the block numbers corresponding to the above-mentioned other types of blockchain data stored in the above-mentioned other storage systems is smaller than the block transaction data stored in the above-mentioned target storage system The latest block number N in the corresponding block number.
也即,当上述其它各存储系统存储的上述其它类型的区块链数据对应的区块号中的最新区块号C,小于上述目标存储系统存储的区块交易数据对应的区块号中的最新区块号N,可以触发区块链系统生成上述第二事件。That is, when the latest block number C in the block numbers corresponding to the above-mentioned other types of blockchain data stored in the above-mentioned other storage systems is smaller than the block number C in the block number corresponding to the block transaction data stored in the above-mentioned target storage system The latest block number N can trigger the blockchain system to generate the above-mentioned second event.
以下将通过具体的实施例,对节点设备基于区块链系统触发上述第一事件,对上述其它各存储系统中存储的其它类型的区块链数据进行恢复的流程;以及,节点设备基于系统触发的上述第二事件,对上述目标存储系统中存储的区块交易数据进行恢复的流程,分别进行描述。The following will use a specific embodiment to trigger the above-mentioned first event based on the blockchain system for the node device, and restore the other types of blockchain data stored in the above-mentioned other storage systems; and, the node device triggers the process based on the system The process of recovering the block transaction data stored in the above-mentioned target storage system for the above-mentioned second event is described separately.
在示出的一种实施方式中,节点设备在对上述其它各存储系统中存储的其它类型的区块链数据进行恢复时,可以周期性确定上述其它各存储系统存储的上述其它类型的区块链数据对应的最新区块号C,是否小于上述目标存储系统存储的区块交易数据对应的最新区块号N;如果是,可以触发生成上述第一事件。In one embodiment shown, when the node device restores other types of blockchain data stored in the above-mentioned other storage systems, it can periodically determine the above-mentioned other types of blocks stored in the above-mentioned other storage systems Whether the latest block number C corresponding to the chain data is smaller than the latest block number N corresponding to the block transaction data stored in the above-mentioned target storage system; if yes, the generation of the above-mentioned first event can be triggered.
例如,在实际应用中,节点设备可以预设一个checkpiont事件的检查周期T,然后基于该周期T,定时检查上述其它各存储系统是否满足上述checkpiont事件的触发条件。For example, in a practical application, the node device may preset a check period T of the checkpiont event, and then periodically check whether the above-mentioned other storage systems meet the triggering condition of the above-mentioned checkpiont event based on the period T.
在示出的另一种实施方式中,节点设备在对上述其它各存储系统中存储的其它类型的区块链数据进行恢复时,也可以响应于用户手动触发的针对上述其它类型的区块链数据进行恢复的指令,来确定上述其它各存储系统存储的上述其它类型的区块链数据对应的最新区块号C,是否小于上述目标存储系统存储的区块交易数据对应的最新区块号N;如果是,可以触发生成上述第一事件。In another embodiment shown, when the node device restores other types of blockchain data stored in the above-mentioned other storage systems, it can also respond to user-triggered Data recovery instructions to determine whether the latest block number C corresponding to the above-mentioned other types of blockchain data stored in the above-mentioned other storage systems is smaller than the latest block number N corresponding to the block transaction data stored in the above-mentioned target storage system ; If yes, it may trigger to generate the above-mentioned first event.
例如,在实际应用中,节点设备除了可以周期性检查上述其它各存储系统是否满足上述checkpiont事件的触发条件以外,用户也可以通过手动输入恢复指令的方式,来触发节点设备检查上述其它各存储系统是否满足上述checkpiont事件的触发条件;比如,在一些恢复场景中,用户可能需要对上述其它各存储系统存储的上述其它类型的区块链数据进行数据回滚操作,将上述其它各存储系统存储的上述其它类型的区块链数据恢复到某一个历史区块对应的数据版本;在这种场景中,用户可以通过手动输入恢复指令的方式,来触发节点设备检查上述其它各存储系统是否满足上述checkpiont事件的触发条件。For example, in practical applications, in addition to periodically checking whether the above-mentioned other storage systems meet the trigger conditions of the above-mentioned checkpiont event, the user can also trigger the node device to check the above-mentioned other storage systems by manually inputting recovery instructions. Whether the trigger conditions of the above checkpiont event are met; for example, in some recovery scenarios, the user may need to perform a data rollback operation on the above-mentioned other types of blockchain data stored in the above-mentioned other storage systems, and restore the data stored in the above-mentioned other storage systems The above-mentioned other types of blockchain data are restored to the data version corresponding to a certain historical block; in this scenario, the user can trigger the node device to check whether the above-mentioned other storage systems meet the above-mentioned checkpoint by manually inputting the recovery command. The trigger condition for the event.
其中,上述其它各存储系统存储的上述其它类型的区块链数据对应的最新区块号C,具体可以是上述其它各存储系统存储的上述其它类型的区块链数据对应的最新区块号中的最小值;在这种情况下,节点设备可以先计算出上述其它各存储系统中存储的上述其它类型的区块链数据对应的最新区块号的最小值,得到上述最新区块号C,再进一步确定上述最新区块号C,是否小于所述目标存储系统存储的区块交易数据对应的最新区块号N。Wherein, the latest block number C corresponding to the above-mentioned other types of blockchain data stored in the above-mentioned other storage systems may specifically be the latest block number C corresponding to the above-mentioned other types of blockchain data stored in the above-mentioned other storage systems In this case, the node device can first calculate the minimum value of the latest block number corresponding to the above-mentioned other types of blockchain data stored in the above-mentioned other storage systems, and obtain the above-mentioned latest block number C, It is further determined whether the above latest block number C is smaller than the latest block number N corresponding to the block transaction data stored in the target storage system.
在示出的一种实施方式中,为了便于确定节点设备搭载的各存储系统存储的区块链数据对应的区块号,各存储系统存储的区块链数据的数据标识中,具体可以包括上述区块链数据对应的区块号;也即,具体可以在区块链数据的数据标识中,直接添加该区块链数据对应的区块号;或者,在区块链数据的数据标识中,添加指示该区块链数据对应的区块号的信息。In one embodiment shown, in order to facilitate the determination of the block number corresponding to the blockchain data stored in each storage system carried by the node device, the data identification of the blockchain data stored in each storage system may specifically include the above-mentioned The block number corresponding to the blockchain data; that is, the block number corresponding to the blockchain data can be directly added to the data identifier of the blockchain data; or, in the data identifier of the blockchain data, Add information indicating the block number to which the blockchain data corresponds.
在一种实现方式中,节点设备搭载的各个存储系统存储的区块链数据的数据标识,具体可以采用统一的数据格式,并在采用的统一的数据格式中,携带该区块链数据对应的区块号;或者指示该区块链数据对应的区块号的信息。In one implementation, the data identification of the blockchain data stored in each storage system carried by the node device can specifically adopt a unified data format, and in the unified data format adopted, carry the data corresponding to the blockchain data. Block number; or information indicating the block number corresponding to the blockchain data.
其中,上述数据格式,在本说明书中不进行特别限定;例如,在一个例子中,节点设备搭载的各个存储系统存储的区块链数据的数据标识,可以统一采用WAL日志文件的LSN(Log Sequence Number,日志序列编号)的数据格式,并通过在 WAL日志文件的LSN中,携带该区块链数据对应的区块号;或者指示该区块链数据对应的区块号的信息。Among them, the above-mentioned data format is not particularly limited in this specification; for example, in one example, the data identification of the blockchain data stored in each storage system carried by the node device can uniformly use the LSN (Log Sequence Number, the data format of the log sequence number), and carry the block number corresponding to the blockchain data in the LSN of the WAL log file; or indicate the information of the block number corresponding to the blockchain data.
在本说明书中,当触发生成了上述第一事件,节点设备可以响应于该第一事件,从与上述目标存储系统对应的日志缓冲区,分别读取由上述最新区块号C和上述最新区块号N构成的区块号区间(C,N]中的各区块号所表示的区块中的区块交易数据对应的WAL日志文件;然后,基于读取到的WAL日志文件,恢复与上述区块号区间(C,N]中的各区块号所表示的区块中的区块交易数据。In this specification, when the above-mentioned first event is triggered, the node device can respond to the first event by reading the above-mentioned latest block number C and the above-mentioned latest block number C from the log buffer corresponding to the above-mentioned target storage system respectively. The WAL log file corresponding to the block transaction data in the block represented by each block number in the block number interval (C, N] formed by the block number N; then, based on the read WAL log file, restore the above-mentioned The block transaction data in the block represented by each block number in the block number interval (C, N].
当上述区块号区间(C,N]中的各区块号所表示的区块中的区块交易数据恢复出来后,可以进一步执行恢复出的区块交易数据,通过重新执行交易的方式,生成与上述区块号区间(C,N]中的各区块号所表示的区块中的区块交易数据对应的上述其它类型的区块链数据。When the block transaction data in the block represented by each block number in the above block number interval (C, N] is recovered, the recovered block transaction data can be further executed, and by re-executing the transaction, generate The above-mentioned other types of blockchain data corresponding to the block transaction data in the block represented by each block number in the above-mentioned block number interval (C, N].
例如,在一个例子中,假设节点设备搭载5个不同的存储系统,分别将区块交易数据、以及与区块交易数据对应的区块的区块头数据、与区块交易数据对应的交易收据、state数据、以及上述4种数据对应的索引数据,存储在这5个不同的存储系统中;其中,存储上述区块交易数据的目标存储系统开启了WAL模式;则在对上述其它类型的区块链数据进行恢复时,则可以在读取到上述区块号区间(C,N]中的各区块号所表示的区块中的区块交易数据对应的WAL日志文件后,基于该WAL日志文件先对上述区块交易数据进行恢复,并在上述区块交易数据恢复完成后,通过重新执行上述区块交易数据的方式,对与上述区块交易数据对应的区块头数据、对应的交易收据、对应的state数据以及对应的索引数据分别进行恢复。For example, in one example, assume that the node device is equipped with five different storage systems, which respectively store the block transaction data, the block header data of the block corresponding to the block transaction data, the transaction receipt corresponding to the block transaction data, The state data and the index data corresponding to the above four types of data are stored in these five different storage systems; among them, the target storage system that stores the above block transaction data has turned on the WAL mode; then for the above other types of blocks When recovering chain data, after reading the WAL log file corresponding to the block transaction data in the block represented by each block number in the above block number interval (C, N], based on the WAL log file First restore the above-mentioned block transaction data, and after the above-mentioned block transaction data is restored, by re-executing the above-mentioned block transaction data, the block header data corresponding to the above-mentioned block transaction data, the corresponding transaction receipt, The corresponding state data and corresponding index data are restored separately.
其中,通过重新执行区块中的交易数据,生成该区块的区块头数据、与上述交易数据对应的交易数据、对应的state数据、以及对应的索引数据的具体方式,为区块链领域的公知常识,在本说明书中不再进行详述,本领域技术人员在将本说明书的技术方案辅助实现时,可以参考相关技术中的记载。Among them, by re-executing the transaction data in the block, the specific way to generate the block header data of the block, the transaction data corresponding to the above transaction data, the corresponding state data, and the corresponding index data is the blockchain field. Common knowledge will not be described in detail in this specification, and those skilled in the art can refer to the records in related technologies when assisting in the realization of the technical solutions in this specification.
在示出的一种实施方式中,节点设备在对上述目标存储系统中存储的区块交易数据进行恢复时,可以周期性确定上述目标存储系统中存储的区块交易数据对应的WAL日志文件的文件数量或者存储容量是否达到阈值;如果是,可以触发生成上述第二事件。In one embodiment shown, when the node device restores the block transaction data stored in the above target storage system, it can periodically determine the WAL log file corresponding to the block transaction data stored in the above target storage system Whether the number of files or the storage capacity reaches the threshold; if yes, the above-mentioned second event may be triggered to be generated.
在示出的另一种实施方式中,节点设备在对目标存储系统中存储的区块交易数 据进行恢复时,也可以响应于用户手动触发的针对上述区块交易数据进行恢复的指令,来确定上述目标存储系统中存储的区块交易数据对应的WAL日志文件的文件数量或者存储容量是否达到阈值;如果是,可以触发生成上述第二事件。In another embodiment shown, when the node device recovers the block transaction data stored in the target storage system, it may also respond to an instruction manually triggered by the user to restore the above block transaction data to determine Whether the number of files or the storage capacity of the WAL log files corresponding to the block transaction data stored in the target storage system reaches a threshold; if yes, the generation of the second event above may be triggered.
例如,在实际应用中,节点设备除了可以周期性检查上述目标存储系统是否满足上述checkpiont事件的触发条件以外,用户也可以通过手动输入恢复指令的方式,来触发节点设备检查上述目标存储系统是否满足上述checkpiont事件的触发条件;比如,在一些恢复场景中,用户可能需要对上述目标存储系统存储的区块链交易数据进行数据回滚操作,将上述目标存储系统存储的区块交易数据恢复到某一个历史区块对应的数据版本。在这种场景中,用户可以通过手动输入恢复指令的方式,来触发节点设备检查上述目标存储系统是否满足上述checkpiont事件的触发条件。For example, in practical applications, in addition to periodically checking whether the above-mentioned target storage system meets the trigger conditions of the above-mentioned checkpoint event, the user can also trigger the node device to check whether the above-mentioned target storage system meets The trigger condition of the above checkpiont event; for example, in some recovery scenarios, the user may need to perform a data rollback operation on the blockchain transaction data stored in the above target storage system, and restore the block transaction data stored in the above target storage system to a certain The data version corresponding to a historical block. In this scenario, the user may manually input a recovery command to trigger the node device to check whether the target storage system satisfies the trigger condition of the checkpiont event.
当触发生成了上述第二事件,节点设备可以响应于该第二事件,从与上述目标存储系统对应的日志缓冲区,读取日志缓冲区中存储的区块交易数据对应的WAL日志文件;然后,基于读取到的WAL日志文件,恢复出与区块交易数据,再将恢复出的区块交易数据,写入上述目标存储系统。When the above-mentioned second event is triggered, the node device can respond to the second event and read the WAL log file corresponding to the block transaction data stored in the log buffer from the log buffer corresponding to the above-mentioned target storage system; and then , based on the read WAL log file, restore the block transaction data, and then write the restored block transaction data into the above target storage system.
以上技术方案中,一方面,由于区块链搭载的多个存储系统中,可以只有用于存储区块交易数据的目标存储系统支持预写日志WAL模式,而用于存储与该区块交易数据对应的其它类型的区块链数据的存储系统则可以不必重复启用WAL模式;因此,对于搭载多个存储系统的节点设备而言,可以只存储和维护一份与区块交易数据对应的WAL日志文件即可,不再需要在存储和维护多份WAL日志文件,可以显著降低节点设备在存储多种区块链数据时的存储开销;Among the above technical solutions, on the one hand, due to the multiple storage systems carried by the blockchain, only the target storage system used to store the transaction data of the block supports the write-ahead log WAL mode, and is used to store the transaction data related to the block Corresponding storage systems for other types of blockchain data do not need to repeatedly enable the WAL mode; therefore, for node devices equipped with multiple storage systems, only one WAL log corresponding to block transaction data can be stored and maintained It is no longer necessary to store and maintain multiple WAL log files, which can significantly reduce the storage overhead of node devices when storing various blockchain data;
另一方面,由于节点设备存储的与该区块交易数据对应的其它类型的区块链数据,是基于与区块交易数据对应的WAL日志文件来进行统一恢复;对于搭载多个存储系统的节点设备而言,可以不再需要基于各个存储系统对应的WAL日志文件来分别进行数据恢复;因此,可以显著降低节点设备在恢复多种区块链数据时的性能开销。On the other hand, because other types of blockchain data corresponding to the block transaction data stored by the node device are restored in a unified manner based on the WAL log file corresponding to the block transaction data; for nodes equipped with multiple storage systems As far as the device is concerned, it is no longer necessary to perform data recovery based on the WAL log files corresponding to each storage system; therefore, the performance overhead of node devices when restoring multiple blockchain data can be significantly reduced.
与上述方法实施例相对应,本申请还提供了装置的实施例。Corresponding to the foregoing method embodiments, the present application also provides device embodiments.
与上述方法实施例相对应,本说明书还提供了一种区块链数据恢复装置的实施例。Corresponding to the above method embodiments, this specification also provides an embodiment of a block chain data recovery device.
本说明书的区块链数据恢复装置的实施例可以应用在电子设备上。装置实施例 可以通过软件实现,也可以通过硬件或者软硬件结合的方式实现。以软件实现为例,作为一个逻辑意义上的装置,是通过其所在电子设备的处理器将非易失性存储器中对应的计算机程序指令读取到内存中运行形成的。The embodiment of the blockchain data recovery device in this specification can be applied to electronic equipment. The device embodiment can be implemented by software, or by hardware or a combination of software and hardware. Taking software implementation as an example, as a device in a logical sense, it is formed by reading the corresponding computer program instructions in the non-volatile memory into the memory for operation by the processor of the electronic device where it is located.
从硬件层面而言,如图2所示,为本说明书的区块链数据恢复装置所在电子设备的一种硬件结构图,除了图2所示的处理器、内存、网络接口、以及非易失性存储器之外,实施例中装置所在的电子设备通常根据该电子设备的实际功能,还可以包括其他硬件,对此不再赘述。From the hardware level, as shown in Figure 2, it is a hardware structure diagram of the electronic equipment where the blockchain data recovery device in this manual is located, except for the processor, memory, network interface, and non-volatile memory shown in Figure 2 In addition to the non-volatile memory, the electronic device where the device in the embodiment is located usually may also include other hardware according to the actual function of the electronic device, which will not be repeated here.
图3是本说明书一示例性实施例示出的一种区块链数据恢复装置的框图。Fig. 3 is a block diagram of a block chain data recovery device shown in an exemplary embodiment of this specification.
请参考图3,所述区块链数据恢复装置30可以应用在前述图2所示的电子设备中,所述节点设备搭载了用于存储区块链数据的多个存储系统;其中,所述区块链数据包括区块交易数据和至少一种其它类型的区块链数据;所述多个存储系统中用于存储所述区块交易数据的目标存储系统支持预写日志WAL模式;所述装置30包括:读取模块301,响应于针对所述其它类型的区块链数据进行恢复的第一事件,读取与所述目标存储系统中存储的区块交易数据对应的WAL日志文件;恢复模块302,基于所述WAL日志文件恢复所述区块交易数据,并执行恢复出的所述区块交易数据以生成所述其它类型的区块链数据;写入模块303,将生成的所述其它类型的区块链数据,分别写入所述多个存储系统中用于存储所述其它类型的区块链数据的各存储系统。Please refer to FIG. 3, the block chain data recovery device 30 can be applied in the aforementioned electronic equipment shown in FIG. 2, and the node device is equipped with multiple storage systems for storing block chain data; wherein, the The block chain data includes block transaction data and at least one other type of block chain data; the target storage system for storing the block transaction data in the plurality of storage systems supports the write-ahead log WAL mode; the The device 30 includes: a reading module 301, which reads the WAL log file corresponding to the block transaction data stored in the target storage system in response to the first event of restoring the other types of blockchain data; Module 302, restore the block transaction data based on the WAL log file, and execute the recovered block transaction data to generate the other types of block chain data; write module 303, the generated Other types of blockchain data are respectively written into the storage systems used to store the other types of blockchain data among the plurality of storage systems.
在本实施例中,所述装置30还包括:第一确定模块304(图3中未示出),确定所述各存储系统存储的所述其它类型的区块链数据对应的区块号中的最新区块号C,是否小于所述目标存储系统存储的区块交易数据对应的区块号中的最新区块号N;如果是,生成所述第一事件。In this embodiment, the device 30 further includes: a first determination module 304 (not shown in FIG. 3 ), which determines the number of block numbers corresponding to the other types of blockchain data stored in each storage system. Whether the latest block number C of the target storage system is smaller than the latest block number N in the block numbers corresponding to the block transaction data stored in the target storage system; if yes, the first event is generated.
在本实施例中,所述最新区块号C为所述各存储系统中存储的所述其它类型的区块链数据对应的最新区块号的最小值。所述第一确定模块304进一步:在确定所述各存储系统存储的所述其它类型的区块链数据对应的最新区块号C,是否小于所述目标存储系统存储的区块交易数据对应的最新区块号N之前,计算所述各存储系统中存储的所述其它类型的区块链数据对应的最新区块号的最小值,得到所述最新区块号C。In this embodiment, the latest block number C is the minimum value of the latest block numbers corresponding to the other types of blockchain data stored in the storage systems. The first determination module 304 further: after determining whether the latest block number C corresponding to the other types of blockchain data stored in the storage systems is smaller than the block number C corresponding to the block transaction data stored in the target storage system Before the latest block number N, calculate the minimum value of the latest block numbers corresponding to the other types of blockchain data stored in the storage systems to obtain the latest block number C.
在本实施例中,所述多个存储系统存储的区块链数据的数据标识,包括所述区 块链数据对应的区块号。In this embodiment, the data identification of the blockchain data stored in the multiple storage systems includes the block number corresponding to the blockchain data.
在本实施例中,所述多个存储系统存储的区块链数据的数据标识,采用了统一的数据格式。In this embodiment, the data identifiers of the blockchain data stored in the multiple storage systems adopt a unified data format.
在本实施例中,所述数据标识采用了WAL日志文件的LSN日志序列编号的数据格式。In this embodiment, the data identifier adopts the data format of the LSN log sequence number of the WAL log file.
在本实施例中,所述读取模块301:分别读取由所述最新区块号C和所述最新区块号N构成的区块号区间(C,N]中的各区块号所表示的区块中的区块交易数据对应的WAL日志文件。所述恢复模块302:基于读取到的所述区块号区间(C,N]中的各区块号表示的区块中的区块交易数据对应的WAL日志文件,恢复与所述各区块号所表示的区块中的区块交易数据,并执行恢复出的所述区块交易数据,以生成与所述各区块号所表示的区块中的区块交易数据对应的所述其它类型的区块链数据。In this embodiment, the reading module 301: respectively reads the block number represented by each block number in the block number interval (C, N] formed by the latest block number C and the latest block number N] The WAL log file corresponding to the block transaction data in the block.The recovery module 302: based on the block in the block represented by each block number in the block number interval (C, N] read The WAL log file corresponding to the transaction data restores the block transaction data in the blocks represented by the block numbers, and executes the recovered block transaction data to generate the block transaction data represented by the block numbers. The other types of blockchain data corresponding to the block transaction data in the block.
在本实施例中,所述第一确定模块304(图3中未示出):周期性确定所述各存储系统存储的所述其它类型的区块链数据对应的最新区块号C,是否小于所述目标存储系统存储的区块交易数据对应的最新区块号N;或者,响应于用户触发的针对所述其它类型的区块链数据进行恢复的指令,确定所述各存储系统存储的所述其它类型的区块链数据对应的最新区块号C,是否小于所述目标存储系统存储的区块交易数据对应的最新区块号N。In this embodiment, the first determination module 304 (not shown in FIG. 3 ): periodically determine the latest block number C corresponding to the other types of blockchain data stored in each storage system, whether is less than the latest block number N corresponding to the block transaction data stored in the target storage system; or, in response to the instruction triggered by the user to restore the other types of blockchain data, determine the Whether the latest block number C corresponding to the other types of blockchain data is smaller than the latest block number N corresponding to the block transaction data stored in the target storage system.
在本实施例中,所述其它类型的区块链数据,包括以下示出的一个或者多个的组合:与所述区块交易数据对应的区块的区块头数据;与所述区块交易数据对应的交易收据;在所述区块交易数据执行完毕后,与所述区块链中的区块链账户对应的账户状态数据。In this embodiment, the other types of blockchain data include a combination of one or more of the following: block header data of the block corresponding to the block transaction data; The transaction receipt corresponding to the data; after the block transaction data is executed, the account status data corresponding to the block chain account in the block chain.
在本实施例中,所述写入模块303进一步:响应于对所述区块交易数据进行恢复的第二事件,基于所述WAL日志文件恢复所述区块交易数据,并将恢复出的所述区块交易数据,写入所述目标存储系统。In this embodiment, the writing module 303 further: in response to the second event of restoring the block transaction data, restore the block transaction data based on the WAL log file, and restore all The block transaction data is written into the target storage system.
在本实施例中,所述装置30还包括:第二确定模块305(图3中未示出),确定与所述目标存储系统中存储的区块交易数据对应的WAL日志文件的文件数量或者存储容量是否达到阈值;如果是,生成所述第二事件。In this embodiment, the device 30 further includes: a second determination module 305 (not shown in FIG. 3 ), which determines the number of WAL log files corresponding to the block transaction data stored in the target storage system or Whether the storage capacity reaches a threshold; if so, generating the second event.
在本实施例中,所述第二确定模块305:周期性确定与所述目标存储系统中存 储的区块交易数据对应的WAL日志文件的文件数量或者存储容量是否达到阈值;或者,响应于用户触发的针对所述区块交易数据进行恢复的指令,确定与所述目标存储系统中存储的区块交易数据对应的WAL日志文件的文件数量或者存储容量是否达到阈值。In this embodiment, the second determination module 305: periodically determines whether the number of files or the storage capacity of the WAL log files corresponding to the block transaction data stored in the target storage system reaches a threshold; or, in response to the user The triggered instruction for recovering the block transaction data determines whether the number of files or the storage capacity of the WAL log files corresponding to the block transaction data stored in the target storage system reaches a threshold.
上述实施例阐明的系统、装置、模块或单元,具体可以由计算机芯片或实体实现,或者由具有某种功能的产品来实现。一种典型的实现设备为计算机,计算机的具体形式可以是个人计算机、膝上型计算机、蜂窝电话、相机电话、智能电话、个人数字助理、媒体播放器、导航设备、电子邮件收发设备、游戏控制台、平板计算机、可穿戴设备或者这些设备中的任意几种设备的组合。The systems, devices, modules, or units described in the above embodiments can be specifically implemented by computer chips or entities, or by products with certain functions. A typical implementing device is a computer, which may take the form of a personal computer, laptop computer, cellular phone, camera phone, smart phone, personal digital assistant, media player, navigation device, e-mail device, game control device, etc. desktops, tablets, wearables, or any combination of these.
在一个典型的配置中,计算机包括一个或多个处理器(CPU)、输入/输出接口、网络接口和内存。In a typical configuration, a computer includes one or more processors (CPUs), input/output interfaces, network interfaces and memory.
内存可能包括计算机可读介质中的非永久性存储器,随机存取存储器(RAM)和/或非易失性内存等形式,如只读存储器(ROM)或闪存(flash RAM)。内存是计算机可读介质的示例。Memory may include non-permanent storage in computer readable media, in the form of random access memory (RAM) and/or nonvolatile memory such as read-only memory (ROM) or flash RAM. Memory is an example of computer readable media.
计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。计算机的存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器(CD-ROM)、数字多功能光盘(DVD)或其他光学存储、磁盒式磁带、磁盘存储、量子存储器、基于石墨烯的存储介质或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。按照本文中的界定,计算机可读介质不包括暂存电脑可读媒体(transitory media),如调制的数据信号和载波。Computer-readable media, including both permanent and non-permanent, removable and non-removable media, can be implemented by any method or technology for storage of information. Information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read only memory (ROM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Flash memory or other memory technology, Compact Disc Read-Only Memory (CD-ROM), Digital Versatile Disc (DVD) or other optical storage, Magnetic cassettes, disk storage, quantum memory, graphene-based storage media or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by computing devices. As defined herein, computer-readable media excludes transitory computer-readable media, such as modulated data signals and carrier waves.
还需要说明的是,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、商品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、商品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、商品或者设备中还存在另外的相同要素。It should also be noted that the term "comprises", "comprises" or any other variation thereof is intended to cover a non-exclusive inclusion such that a process, method, article, or apparatus comprising a set of elements includes not only those elements, but also includes Other elements not expressly listed, or elements inherent in the process, method, commodity, or apparatus are also included. Without further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article or apparatus comprising said element.
上述对本说明书特定实施例进行了描述。其它实施例在所附权利要求书的范围内。在一些情况下,在权利要求书中记载的动作或步骤可以按照不同于实施例中的顺序来执行并且仍然可以实现期望的结果。另外,在附图中描绘的过程不一定要求示出的特定顺序或者连续顺序才能实现期望的结果。在某些实施方式中,多任务处理和并行处理也是可以的或者可能是有利的。The foregoing describes specific embodiments of this specification. Other implementations are within the scope of the following claims. In some cases, the actions or steps recited in the claims can be performed in an order different from that in the embodiments and still achieve desirable results. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. Multitasking and parallel processing are also possible or may be advantageous in certain embodiments.
在本说明书一个或多个实施例使用的术语是仅仅出于描述特定实施例的目的,而非旨在限制本说明书一个或多个实施例。在本说明书一个或多个实施例和所附权利要求书中所使用的单数形式的“一种”、“所述”和“该”也旨在包括多数形式,除非上下文清楚地表示其他含义。还应当理解,本文中使用的术语“和/或”是指并包含一个或多个相关联的列出项目的任何或所有可能组合。Terms used in one or more embodiments of the present specification are for the purpose of describing specific embodiments only, and are not intended to limit the one or more embodiments of the present specification. As used in one or more embodiments of this specification and the appended claims, the singular forms "a", "the", and "the" are also intended to include the plural forms unless the context clearly dictates otherwise. It should also be understood that the term "and/or" as used herein refers to and includes any and all possible combinations of one or more of the associated listed items.
应当理解,尽管在本说明书一个或多个实施例可能采用术语第一、第二、第三等来描述各种信息,但这些信息不应限于这些术语。这些术语仅用来将同一类型的信息彼此区分开。例如,在不脱离本说明书一个或多个实施例范围的情况下,第一信息也可以被称为第二信息,类似地,第二信息也可以被称为第一信息。取决于语境,如在此所使用的词语“如果”可以被解释成为“在……时”或“当……时”或“响应于确定”。It should be understood that although the terms first, second, third, etc. may be used in one or more embodiments of the present specification to describe various information, the information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, without departing from the scope of one or more embodiments of the present specification, first information may also be called second information, and similarly, second information may also be called first information. Depending on the context, the word "if" as used herein may be interpreted as "at" or "when" or "in response to a determination."
以上所述仅为本说明书一个或多个实施例的较佳实施例而已,并不用以限制本说明书一个或多个实施例,凡在本说明书一个或多个实施例的精神和原则之内,所做的任何修改、等同替换、改进等,均应包含在本说明书一个或多个实施例保护的范围之内。The above descriptions are only preferred embodiments of one or more embodiments of this specification, and are not intended to limit one or more embodiments of this specification. Within the spirit and principles of one or more embodiments of this specification, Any modification, equivalent replacement, improvement, etc. should be included in the scope of protection of one or more embodiments of this specification.

Claims (15)

  1. 一种区块链数据恢复方法,应用于节点设备;所述节点设备搭载了用于存储区块链数据的多个存储系统;其中,所述区块链数据包括区块交易数据和至少一种其它类型的区块链数据;所述多个存储系统中用于存储所述区块交易数据的目标存储系统支持预写日志WAL模式;所述方法包括:A blockchain data recovery method, applied to a node device; the node device is equipped with multiple storage systems for storing blockchain data; wherein, the blockchain data includes block transaction data and at least one Other types of block chain data; the target storage system for storing the block transaction data in the multiple storage systems supports the write-ahead log WAL mode; the method includes:
    响应于针对所述其它类型的区块链数据进行恢复的第一事件,读取与所述目标存储系统中存储的区块交易数据对应的WAL日志文件;reading a WAL log file corresponding to the block transaction data stored in the target storage system in response to the first event of recovering the other type of blockchain data;
    基于所述WAL日志文件恢复所述区块交易数据,并执行恢复出的所述区块交易数据以生成所述其它类型的区块链数据;Restoring the block transaction data based on the WAL log file, and executing the restored block transaction data to generate the other types of block chain data;
    将生成的所述其它类型的区块链数据,分别写入所述多个存储系统中用于存储所述其它类型的区块链数据的各存储系统。The generated blockchain data of other types are respectively written into each storage system used to store the blockchain data of other types among the plurality of storage systems.
  2. 根据权利要求1所述的方法,所述方法还包括:The method according to claim 1, said method further comprising:
    确定所述各存储系统存储的所述其它类型的区块链数据对应的区块号中的最新区块号C,是否小于所述目标存储系统存储的区块交易数据对应的区块号中的最新区块号N;如果是,生成所述第一事件。Determine whether the latest block number C in the block numbers corresponding to the other types of blockchain data stored in the storage systems is smaller than the block number C in the block number corresponding to the block transaction data stored in the target storage system The latest block number N; if yes, generate said first event.
  3. 根据权利要求2所述的方法,所述最新区块号C为所述各存储系统中存储的所述其它类型的区块链数据对应的最新区块号的最小值;According to the method according to claim 2, the latest block number C is the minimum value of the latest block numbers corresponding to the other types of blockchain data stored in the storage systems;
    确定所述各存储系统存储的所述其它类型的区块链数据对应的最新区块号C,是否小于所述目标存储系统存储的区块交易数据对应的最新区块号N之前,还包括:Before determining whether the latest block number C corresponding to the other types of blockchain data stored in each storage system is smaller than the latest block number N corresponding to the block transaction data stored in the target storage system, it also includes:
    计算所述各存储系统中存储的所述其它类型的区块链数据对应的最新区块号的最小值,得到所述最新区块号C。Calculating the minimum value of the latest block numbers corresponding to the other types of blockchain data stored in the storage systems to obtain the latest block number C.
  4. 根据权利要求3所述的方法,所述多个存储系统存储的区块链数据的数据标识,包括所述区块链数据对应的区块号。According to the method according to claim 3, the data identification of the blockchain data stored in the plurality of storage systems includes a block number corresponding to the blockchain data.
  5. 根据权利要求4所述的方法,所述多个存储系统存储的区块链数据的数据标识,采用了统一的数据格式。According to the method according to claim 4, the data identification of the blockchain data stored in the plurality of storage systems adopts a unified data format.
  6. 根据权利要求5所述的方法,所述数据标识采用了WAL日志文件的LSN日志序列编号的数据格式。According to the method according to claim 5, the data identification adopts the data format of the LSN log sequence number of the WAL log file.
  7. 根据权利要求2所述的方法,读取与所述目标存储系统中存储的区块交易数据对应的WAL日志文件,包括:According to the method according to claim 2, reading the WAL log file corresponding to the block transaction data stored in the target storage system includes:
    分别读取由所述最新区块号C和所述最新区块号N构成的区块号区间(C,N]中的各区块号所表示的区块中的区块交易数据对应的WAL日志文件;Read respectively the WAL log corresponding to the block transaction data in the block represented by each block number in the block number interval (C, N] formed by the latest block number C and the latest block number N document;
    基于所述WAL日志文件恢复所述区块交易数据,并执行恢复出的所述区块链交易以生成所述其它类型的区块链数据,包括:Restoring the block transaction data based on the WAL log file, and executing the recovered block chain transaction to generate the other types of block chain data, including:
    基于读取到的所述区块号区间(C,N]中的各区块号表示的区块中的区块交易数据对应的WAL日志文件,恢复与所述各区块号所表示的区块中的区块交易数据,并执行恢复出的所述区块交易数据,以生成与所述各区块号所表示的区块中的区块交易数据对应的所述其它类型的区块链数据。Based on the WAL log file corresponding to the block transaction data in the block represented by each block number in the read block number interval (C, N], restore the block corresponding to the block represented by each block number block transaction data, and execute the recovered block transaction data to generate the other types of block chain data corresponding to the block transaction data in the block represented by each block number.
  8. 根据权利要求2所述的方法,确定所述各存储系统存储的所述其它类型的区块链数据对应的最新区块号C,是否小于所述目标存储系统存储的区块交易数据对应的最新区块号N,包括:According to the method of claim 2, it is determined whether the latest block number C corresponding to the other types of blockchain data stored in each storage system is smaller than the latest block number C corresponding to the block transaction data stored in the target storage system. Block number N, including:
    周期性确定所述各存储系统存储的所述其它类型的区块链数据对应的最新区块号C,是否小于所述目标存储系统存储的区块交易数据对应的最新区块号N;或者,Periodically determine whether the latest block number C corresponding to the other types of blockchain data stored in each storage system is smaller than the latest block number N corresponding to the block transaction data stored in the target storage system; or,
    响应于用户触发的针对所述其它类型的区块链数据进行恢复的指令,确定所述各存储系统存储的所述其它类型的区块链数据对应的最新区块号C,是否小于所述目标存储系统存储的区块交易数据对应的最新区块号N。In response to user-triggered instructions for restoring the other types of blockchain data, determine whether the latest block number C corresponding to the other types of blockchain data stored in the storage systems is smaller than the target The latest block number N corresponding to the block transaction data stored in the storage system.
  9. 根据权利要求1或8所述的方法,所述其它类型的区块链数据,包括以下示出的一个或者多个的组合:According to the method according to claim 1 or 8, the other types of blockchain data include a combination of one or more of the following:
    与所述区块交易数据对应的区块的区块头数据;Block header data of a block corresponding to the block transaction data;
    与所述区块交易数据对应的交易收据;A transaction receipt corresponding to the block transaction data;
    在所述区块交易数据执行完毕后,与所述区块链中的区块链账户对应的账户状态数据。Account state data corresponding to the blockchain account in the blockchain after the execution of the block transaction data is completed.
  10. 根据权利要求1所述的方法,所述方法还包括:The method according to claim 1, said method further comprising:
    响应于对所述区块交易数据进行恢复的第二事件,基于所述WAL日志文件恢复所述区块交易数据,并将恢复出的所述区块交易数据,写入所述目标存储系统。In response to the second event of restoring the block transaction data, restore the block transaction data based on the WAL log file, and write the restored block transaction data into the target storage system.
  11. 根据权利要求10所述的方法,所述方法还包括:The method of claim 10, further comprising:
    确定与所述目标存储系统中存储的区块交易数据对应的WAL日志文件的文件数量或者存储容量是否达到阈值;如果是,生成所述第二事件。Determine whether the number of files or the storage capacity of the WAL log files corresponding to the block transaction data stored in the target storage system reaches a threshold; if yes, generate the second event.
  12. 根据权利要求11所述的方法,确定与所述目标存储系统中存储的区块交易数据对应的WAL日志文件的文件数量或者存储容量是否达到阈值,包括:The method according to claim 11, determining whether the number of files or the storage capacity of the WAL log file corresponding to the block transaction data stored in the target storage system reaches a threshold, comprising:
    周期性确定与所述目标存储系统中存储的区块交易数据对应的WAL日志文件的文件数量或者存储容量是否达到阈值;或者,Periodically determine whether the number of files or the storage capacity of the WAL log files corresponding to the block transaction data stored in the target storage system reaches a threshold; or,
    响应于用户触发的针对所述区块交易数据进行恢复的指令,确定与所述目标存储系 统中存储的区块交易数据对应的WAL日志文件的文件数量或者存储容量是否达到阈值。In response to the user-triggered instruction for recovering the block transaction data, determine whether the file quantity or storage capacity of the WAL log file corresponding to the block transaction data stored in the target storage system reaches a threshold.
  13. 一种区块链数据恢复装置,应用于节点设备;所述节点设备搭载了用于存储区块链数据的多个存储系统;其中,所述区块链数据包括区块交易数据和至少一种其它类型的区块链数据;所述多个存储系统中用于存储所述区块交易数据的目标存储系统支持预写日志WAL模式;所述装置包括:A block chain data recovery device, applied to a node device; the node device is equipped with multiple storage systems for storing block chain data; wherein, the block chain data includes block transaction data and at least one Other types of block chain data; the target storage system for storing the block transaction data in the multiple storage systems supports the write-ahead log WAL mode; the device includes:
    读取模块,响应于针对所述其它类型的区块链数据进行恢复的第一事件,读取与所述目标存储系统中存储的区块交易数据对应的WAL日志文件;The reading module reads the WAL log file corresponding to the block transaction data stored in the target storage system in response to the first event of recovering the other types of blockchain data;
    恢复模块,基于所述WAL日志文件恢复所述区块交易数据,并执行恢复出的所述区块交易数据以生成所述其它类型的区块链数据;A recovery module, recovering the block transaction data based on the WAL log file, and executing the recovered block transaction data to generate the other types of blockchain data;
    写入模块,将生成的所述其它类型的区块链数据,分别写入所述多个存储系统中用于存储所述其它类型的区块链数据的各存储系统。The writing module writes the generated blockchain data of other types into each storage system used to store the blockchain data of other types among the multiple storage systems.
  14. 一种电子设备,包括:An electronic device comprising:
    处理器;processor;
    用于存储处理器可执行指令的存储器;memory for storing processor-executable instructions;
    其中,所述处理器通过运行所述可执行指令以实现如权利要求1至12中任一项所述的方法。Wherein, the processor implements the method according to any one of claims 1 to 12 by running the executable instructions.
  15. 一种计算机可读存储介质,其上存储有计算机指令,其特征在于,该指令被处理器执行时实现如权利要求1至12中任一项所述方法的步骤。A computer-readable storage medium, on which computer instructions are stored, wherein the steps of the method according to any one of claims 1 to 12 are implemented when the instructions are executed by a processor.
PCT/CN2022/135120 2022-02-25 2022-11-29 Blockchain data recovery method and apparatus, and electronic device WO2023160077A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202210178105.0 2022-02-25
CN202210178105.0A CN114780285A (en) 2022-02-25 2022-02-25 Block chain data recovery method and device and electronic equipment

Publications (1)

Publication Number Publication Date
WO2023160077A1 true WO2023160077A1 (en) 2023-08-31

Family

ID=82423640

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/135120 WO2023160077A1 (en) 2022-02-25 2022-11-29 Blockchain data recovery method and apparatus, and electronic device

Country Status (2)

Country Link
CN (1) CN114780285A (en)
WO (1) WO2023160077A1 (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117056131A (en) * 2023-10-11 2023-11-14 腾讯科技(深圳)有限公司 Data processing method based on block chain network and related equipment
CN117670330A (en) * 2024-02-01 2024-03-08 中国信息通信研究院 Block chain-based transaction processing method and device, electronic equipment and storage medium

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114780285A (en) * 2022-02-25 2022-07-22 蚂蚁区块链科技(上海)有限公司 Block chain data recovery method and device and electronic equipment

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5485608A (en) * 1990-06-29 1996-01-16 Oracle Corporation Methods and apparatus for updating information in a computer system using logs and state identifiers
WO2017122060A1 (en) * 2016-08-25 2017-07-20 Huawei Technologies India Pvt. Ltd. Parallel recovery for shared-disk databases
CN111507720A (en) * 2020-04-22 2020-08-07 腾讯科技(深圳)有限公司 Data snapshot method and device based on block chain and computer readable storage medium
CN112597153A (en) * 2020-12-09 2021-04-02 杭州趣链科技有限公司 Data storage method and device based on block chain and storage medium
CN114780285A (en) * 2022-02-25 2022-07-22 蚂蚁区块链科技(上海)有限公司 Block chain data recovery method and device and electronic equipment

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5485608A (en) * 1990-06-29 1996-01-16 Oracle Corporation Methods and apparatus for updating information in a computer system using logs and state identifiers
WO2017122060A1 (en) * 2016-08-25 2017-07-20 Huawei Technologies India Pvt. Ltd. Parallel recovery for shared-disk databases
CN111507720A (en) * 2020-04-22 2020-08-07 腾讯科技(深圳)有限公司 Data snapshot method and device based on block chain and computer readable storage medium
CN112597153A (en) * 2020-12-09 2021-04-02 杭州趣链科技有限公司 Data storage method and device based on block chain and storage medium
CN114780285A (en) * 2022-02-25 2022-07-22 蚂蚁区块链科技(上海)有限公司 Block chain data recovery method and device and electronic equipment

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117056131A (en) * 2023-10-11 2023-11-14 腾讯科技(深圳)有限公司 Data processing method based on block chain network and related equipment
CN117056131B (en) * 2023-10-11 2024-01-26 腾讯科技(深圳)有限公司 Data processing method based on block chain network and related equipment
CN117670330A (en) * 2024-02-01 2024-03-08 中国信息通信研究院 Block chain-based transaction processing method and device, electronic equipment and storage medium

Also Published As

Publication number Publication date
CN114780285A (en) 2022-07-22

Similar Documents

Publication Publication Date Title
WO2021017421A1 (en) Blockchain state data recovery method and device, and electronic device
WO2021017436A1 (en) Blockchain state data synchronization method and apparatus, and electronic device
WO2021017435A1 (en) Blockchain state data storage method and apparatus, and electronic device
WO2023160077A1 (en) Blockchain data recovery method and apparatus, and electronic device
US20200167345A1 (en) Method and apparatus for storing blockchain state data and electronic device
US20200177519A1 (en) Allocating virtual resource based on block chain
TWI712976B (en) Asset management system, method and device, electronic equipment
US10956444B2 (en) Block chain state data synchronization method, apparatus, and electronic device
WO2021017438A1 (en) Blockchain-based electronic bill cancellation method and apparatus, and electronic device
WO2020029931A1 (en) Data query method and system, consensus method and system, device and storage medium
WO2020258853A1 (en) Blockchain-based hierarchical storage method and apparatus, and electronic device
CN111898139B (en) Data reading and writing method and device and electronic equipment
CN108804112A (en) A kind of block chain falls account processing method and system
US10761948B1 (en) Method, apparatus, and electronic device for restoring state data of blockchain
CN110032598B (en) Method and device for updating field and electronic equipment
WO2021017442A1 (en) Method and device for electronic negotiable instrument reimbursement based on blockchain, and electronic device
US11036720B2 (en) Blockchain-based hierarchical data storage
US11386054B2 (en) Blockchain-based hierarchical data storage
CN109300036A (en) The bifurcated homing method and device of block chain network
WO2022077186A1 (en) Execution method and apparatus for smart contract in blockchain, and electronic device
TWI724570B (en) Method, device, electronic equipment and storage medium for reading and updating data structure
US11288247B2 (en) Blockchain based hierarchical data storage
WO2023160094A1 (en) Blockchain-based transaction verification method and apparatus, and electronic device
WO2021017432A1 (en) Blockchain-based reimbursement expense segmentation method and apparatus, and electronic device
US11250438B2 (en) Blockchain-based reimbursement splitting

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

Country of ref document: EP

Kind code of ref document: A1