WO2022233274A1 - Block chain data storage method and apparatus, and electronic device - Google Patents

Block chain data storage method and apparatus, and electronic device Download PDF

Info

Publication number
WO2022233274A1
WO2022233274A1 PCT/CN2022/090294 CN2022090294W WO2022233274A1 WO 2022233274 A1 WO2022233274 A1 WO 2022233274A1 CN 2022090294 W CN2022090294 W CN 2022090294W WO 2022233274 A1 WO2022233274 A1 WO 2022233274A1
Authority
WO
WIPO (PCT)
Prior art keywords
node
data
tree
key
value
Prior art date
Application number
PCT/CN2022/090294
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 WO2022233274A1 publication Critical patent/WO2022233274A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures

Definitions

  • One or more embodiments of this specification relate to the field of blockchain technology, and in particular, to a method and apparatus for storing blockchain data, and electronic equipment.
  • Blockchain technology also known as distributed ledger technology, is an emerging technology in which several node devices jointly participate in “bookkeeping” and jointly store and maintain a complete distributed database.
  • the blockchain data that needs to be stored and maintained usually includes the block data and the account status data corresponding to the blockchain account in the blockchain; and the block data can further include the block data.
  • the various blockchain data can usually be organized into a Merkle tree in the form of key-value pairs and stored in the database.
  • the data can be efficiently queried by traversing the above-mentioned Merkle tree by using the key of the above-mentioned various blockchain data as a query index.
  • This specification proposes a method for storing data in a blockchain, including: obtaining a key-value key-value pair of the blockchain data to be stored; converting the key-value key-value pair of the blockchain data to be stored
  • the root node, the intermediate node and the leaf node on the logical tree structure; the root node and the intermediate node include a plurality of positions for storing the characters in the key of the blockchain data, and each position includes multiple positions.
  • a slot for storing the characters in the key of the blockchain data is used to store the hash value of the next-layer node linked to the node; the root node, the intermediate node and the leaf node are The key-value key-value pair is stored in the database; in the key-value key-value pair of the leaf node, the intermediate node and the root node, the value is the storage content of the node, and the key is the hash of the storage content of the node value.
  • This specification also proposes a device for storing data in a blockchain, comprising: an acquisition module, which acquires a key-value pair of blockchain data to be stored; a conversion module, which converts the data of the blockchain data to be stored.
  • the key-value key-value pair is converted into a root node, an intermediate node and a leaf node on a logical tree structure;
  • the root node and the intermediate node include a plurality of positions for storing characters in the key of the blockchain data , each position includes a plurality of slots for storing characters in the key of the blockchain data; the slots are used to store the hash value of the next layer node linked to the node;
  • the storage module the The key-value key-value pairs of the root node, the intermediate node and the leaf node are stored in the database; in the key-value key-value pairs of the leaf node, the intermediate node and the root node, the value is the storage of the node Content, the key is the hash value of the node's storage
  • each root node and intermediate node in the logical tree structure include multiple positions representing different characters respectively; and each position further includes multiple slots representing different characters respectively Therefore, through this design, each root node and intermediate node will have a larger data storage capacity and data carrying capacity, so that the root node and intermediate node in the above-mentioned logical tree structure are written into the database.
  • the data storage capacity of the root node and the intermediate node can be compared with the single IO read and write of the storage medium carrying the above database.
  • the capacity of the above-mentioned database is more suitable, so that the IO read and write capabilities of the storage medium carrying the above database can be fully utilized to improve the efficiency of data read and write; moreover, the data storage capacity and data carrying capacity of the nodes on the above-mentioned logical tree structure are improved.
  • the number of layers of intermediate nodes is always in a relatively stable state; thirdly, due to this design, each root node and intermediate node will have greater data storage capacity and data carrying capacity; and, the above-mentioned logical tree
  • the number of layers of root nodes and intermediate nodes contained in the tree-like structure will be in a relatively stable state; therefore, the improvement of the storage capacity of the root nodes and intermediate nodes and the relative stability of the layers of the root nodes and intermediate nodes, in To some extent, it can be ensured that the root node and intermediate node of the above-mentioned logical tree structure will have fewer layers; thus, the root node and intermediate node have greater data storage capacity and data carrying capacity, and the above logical
  • the root node and intermediate nodes of the tree structure have fewer layers, when the system performs a cold start, it is necessary to convert the root nodes of the first N layers of the above logical tree structure from the storage medium carrying the above database.
  • FIG. 1 is a schematic diagram of organizing account state data of a blockchain into an MPT state tree provided by an exemplary embodiment
  • FIG. 2 is a schematic diagram of organizing contract data stored in a storage space corresponding to a contract account into an MPT storage tree provided by an exemplary embodiment
  • FIG. 3 is a flowchart of a method for storing blockchain data provided by an exemplary embodiment
  • FIG. 4 is a tree structure diagram of a FDMT tree provided by an exemplary embodiment
  • FIG. 5 is a tree structure diagram of another FDMT tree provided by an exemplary embodiment
  • Fig. 6 is the structure diagram of a kind of Tree node provided by an exemplary embodiment
  • FIG. 7 is a structural diagram of a bucket data bucket provided by an exemplary embodiment
  • FIG. 8 is a schematic diagram of setting a node ID for a node on an FDMT tree provided by an exemplary embodiment
  • FIG. 9 is a schematic diagram of writing account status data into an FDMT tree provided by an exemplary embodiment
  • FIG. 10 is a schematic structural diagram of an electronic device provided by an exemplary embodiment
  • FIG. 11 is a block diagram of a blockchain data storage device provided by an exemplary embodiment.
  • Blockchains are generally divided into three types: Public Blockchain, Private Blockchain and Consortium Blockchain.
  • the most decentralized is the public chain.
  • Participants who join 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.
  • each node can freely join or leave the network and perform related operations.
  • the private chain is on the contrary, 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 within a specific institution.
  • the consortium chain is a blockchain between the public chain and the private chain, which can achieve "partial decentralization".
  • Each node in the alliance chain usually has a corresponding entity or organization; the node joins the network through authorization and forms a stakeholder alliance to jointly maintain the operation of the blockchain.
  • the blockchain is usually composed of several blocks. Timestamps corresponding to the creation time of the blocks are respectively recorded in these blocks, and all blocks form a time-ordered data chain strictly according to the timestamps recorded in the blocks.
  • the data generated outside the chain it can be constructed into a standard transaction format supported by the blockchain, and then published to the blockchain. After the consensus, the node device in the blockchain as the accounting node will package the transaction into the block and store the certificate persistently in the blockchain.
  • a structure is usually used to maintain the account state of the account.
  • the state of the account associated with that transaction in the blockchain usually changes as well.
  • the structure of the account usually includes fields such as Balance, Nonce, Code and Storage.
  • 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 be processed only once, effectively avoiding replay attacks
  • the Code field is used to maintain the contract code of the account; in practical applications, the Code field usually only maintains the hash value of the contract code; therefore, the Code field is usually also called the Codehash field.
  • the Storage field is used to maintain the storage content of the account; for the contract account, an independent persistent storage space is usually allocated to store the contract data stored in the storage space corresponding to the contract account; the independent storage The space is usually referred to as the account storage of the contract account.
  • the storage content of the contract account is usually stored in the above-mentioned independent storage space in the form of a key-value key-value pair constructed as an MPT (Merkle Patricia Trie) tree data structure.
  • MPT tree is a logical tree structure used to store and maintain blockchain data in the blockchain field. This tree structure usually includes root nodes, intermediate nodes, and leaf nodes.
  • the MPT tree constructed based on the storage content of the contract account is also commonly referred to as 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.
  • a Merkle tree is usually used; or a logical tree structure such as a Merkle tree variant based on the data structure of the Merkle tree is used to store and maintain data.
  • the MPT tree is a Merkle tree variant that combines the tree structure of the Trie dictionary tree for storing and maintaining blockchain data.
  • the contract data stored in the storage space corresponding to the contract account is usually constructed as an MTP Storage tree (hereinafter referred to as the Storage tree).
  • the hash value of the root node of the Storage tree will be added to the Storage field in the above structure of the contract account corresponding to the Storage tree.
  • the MPT state tree is an MPT tree organized by the account state data of all accounts (including external accounts and contract accounts) in the blockchain in the form of key-value pairs; the MPT transaction tree is composed of The transaction data in the block chain is an MPT tree organized in the form of key-value key-value pairs; the MPT receipt tree is the transaction corresponding to each transaction generated after the transaction in the block is executed. ) receipt, an MPT tree organized in the form of key-value pairs.
  • 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.
  • both the MPT transaction tree and the 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 node device executes the transaction in the latest block generated by the blockchain, since the account status in the current blockchain has changed, the node device needs to construct the current account status data based on the current account status data of all accounts in the blockchain.
  • the MPT state tree is used to maintain the latest state of all accounts in the blockchain.
  • each block in the blockchain has a corresponding MPT state tree; the MPT state tree maintains that after the transaction in the block is executed, all accounts in the blockchain are up-to-date. account status.
  • FIG. 1 is a schematic diagram of organizing the account status data of each blockchain account in the blockchain into an MPT state tree in the form of key-value pairs.
  • MPT tree is a more traditional and improved variant of Merkle tree, which combines the advantages of two tree structures of Merkle tree and Trie dictionary tree (also called prefix tree).
  • the root node of the MPT tree can usually be an extension node; the middle node of the MPT tree can usually be a branch node or other extension nodes.
  • the extension nodes and branch nodes may be collectively referred to as character nodes, which are used to store the character prefix part of the character string corresponding to the key (ie the account address) of the account status data; wherein, for the MPT tree, the above character prefix part usually refers to Shared character prefix; the shared character prefix refers to a prefix composed of the same one or more characters that the keys of all account status data (ie, blockchain account addresses) have.
  • the above leaf nodes are used to store the character suffix part of the character string corresponding to the key of the blockchain data and the Value (that is, the specific account status data).
  • the extension node is used to store one or more characters in the shared character prefix of the account address (that is, the shared nibble shown in Figure 1), and the hash value of the node in the next layer linked to the extension node (that is, the one shown in Figure 1).
  • Next node containing 17 slots, the first 16 slots correspond to the 16 possible hexadecimal characters in the key, one character corresponds to a nibble (nibble), each of the first 16 slots Bits, which respectively represent a character in the shared character prefix of an account address, and these slots are used to fill the hash value of the node of the next layer linked by the branch node.
  • the last slot is the value slot, which is usually an empty value.
  • the leaf node is used to store the character suffix of the account address (that is, the key-end shown in FIG. 1 ), and the value of the account status data (that is, the structure of the account described above); wherein, the character suffix of the account address and the account address are The shared character prefix of , together forms a complete account address; the character suffix refers to the suffix composed of the last one or more characters except the shared character prefix of the account address.
  • the blockchain account corresponding to the account address in the first three lines is an external account, and the fields of Codehash and Storage root are empty.
  • the blockchain account corresponding to the account address in line 4 is the contract account.
  • the Codehash field maintains the hash value of the contract code corresponding to the contract account;
  • the Storage root field maintains the root node of the Storage tree composed of the storage content of the contract account. hash value.
  • the MPT state tree is organized according to the account state data in Table 1, as shown in Figure 1; the MPT state tree consists of 4 leaf nodes, 2 branch nodes, and 2 extension nodes (one of which is the extension node as the root). node) composition.
  • the prefix field is a prefix field shared by the extension node and the leaf node.
  • Different field values of the prefix field can be used to represent different node types.
  • the value of the prefix field is 0, indicating an extension node containing an even number of nibbles; as mentioned above, a nibble represents a nibble, which is composed of 4-bit binary, and a nibble can correspond to a character that constitutes an account address.
  • the value of the prefix field is 1, which means that the extension node contains an odd number of nibble(s); the value of the prefix field is 2, which means that the leaf node contains an even number of nibbles; the value of the prefix field is 3, which means that it contains an odd number of nibbles. (s) leaf nodes.
  • the branch node because it is a parallel single nibble character node, does not have the above prefix field.
  • the Shared nibble field in the extension node corresponds to the key value of the key-value pair contained in the extension node, indicating the common character prefix between account addresses; for example, all account addresses in the above table have a common character prefix a7.
  • the Next Node field is filled with the hash value (hash pointer) of the next node.
  • the hexadecimal character 0 ⁇ f field in the branch node corresponds to the key value of the key-value pair contained in the branch node; if the branch node is an intermediate node on the search path of the account address in the MPT tree, the branch node
  • the Value field can be null.
  • the Key-end in the leaf node corresponds to the key value of the key-value pair contained in the leaf node, and represents the last few characters of the account address (the character suffix of the account address).
  • the key value of each node on the search path from the root node to the leaf node constitutes a complete account address.
  • the Value field of the leaf node is filled with the account status data corresponding to the account address; for example, the structure composed of the fields such as Balance, Nonce, Code, and storage can be encoded, and then filled into the Value field of the leaf node.
  • the nodes on the MPT state tree shown in Figure 1 are ultimately stored in the database in the form of Key-Value key-value pairs; among them, when the nodes on the MPT state tree are stored in the database, the MPT state
  • the key in the key-value pair of the node on the tree can be the hash value of the data content contained in the node; the value in the key-value pair of the node on the MPT state tree is the data content contained in the node.
  • the hash value of the data content contained in the node can be calculated (that is, the hash calculation is performed on the entire node), and the calculated hash value can be used as the key.
  • the content of the data is used as value, and a Key-Value key-value pair is generated; then, the generated Key-Value key-value pair is stored in the database.
  • the key can be the hash value of the data content contained in the node, and the value can be the data content contained in the node; therefore, when you need to query When a node on the MPT state tree is used, content addressing can usually be performed based on the hash value of the data content contained in the node as a key.
  • FIG. 2 is a schematic diagram of organizing the contract data stored in the storage space corresponding to the contract account into an MPT storage tree shown in this specification.
  • the account whose account address is "a77d397" shown in Table 1 is a contract account, so the contract data stored in the storage space corresponding to the contract account will be organized into a storage tree; among them, the storage tree The hash value S1 of the root node will be added to the storage root field in the leaf node corresponding to the contract account in the MTP state tree shown in Figure 1.
  • the contract data stored in the storage space of the contract account can usually be in the form of state variables; when storing, the state variable names can be organized into a storage tree as shown in Figure 2 in the form of key-value pairs for storage .
  • the account address of the contract account and the hash value of the storage location of the state variable in the account storage of the contract account can be used as the key, and the variable value corresponding to the state variable can be used as the value.
  • the branch node can store one of the characters in the shared character prefixes of all account addresses; and the extension node can store the shared character prefixes of all account addresses. one or more characters in .
  • the character length of the shared character prefix of the keys of all data stored in the MPT tree is usually not fixed; moreover, when the newly added data is written to the MPT tree, the characters of the above shared character prefix may be caused
  • the length will also change accordingly; therefore, this may cause the expansion node on the MPT tree to split and split into new branch nodes; that is, the split condition of the nodes on the MPT tree is that the above-mentioned shared character prefix
  • the character length changes; for example, taking the MPT state tree shown in Figure 1 as an example, assuming that the above-mentioned MPT state tree adds an account state data of an account address whose first two characters of the account address are "a8", then the figure
  • the shared character prefix stored in the "Shared nible" field of the extended node as the root node shown in 1 will be changed from "a7" to "a”; according to the splitting conditions of the nodes of the MPT state tree, this is used as the root node.
  • the number of node layers in the MPT tree may also change, resulting in an unstable number of nodes in the MPT tree. Because the character length of the shared character prefix of the keys of all the data stored in the above-mentioned MPT tree will frequently change as new data is written into the above-mentioned MPT tree; therefore, according to the node splitting method shown above, there will be This causes frequent splitting of nodes, which in turn affects the data storage efficiency when writing new data to the MPT tree.
  • this specification proposes a new logical tree structure design solution.
  • the above-mentioned logical tree structure may still include a root node, an intermediate node and a leaf node; wherein, the above-mentioned root node and intermediate node are used to store characters in the key of the blockchain data; the above-mentioned leaf node is used for the storage area The value of the blockchain data.
  • the above-mentioned root node and intermediate node may include multiple locations for storing characters in the key of blockchain data, and each location may further include multiple locations for storing blockchain data.
  • the slot of the character in the key; the above slot can be used to store the hash value of the next layer node linked to the node.
  • the node device in the blockchain can obtain the key-value key-value pair of the blockchain data to be stored, and then convert the blockchain data to be stored into the above-mentioned logical tree structure
  • the root node, the intermediate node and the leaf node on the node then, the key-value key-value pairs of the above-mentioned root node, the intermediate node and the leaf node are further stored in the database; the above-mentioned leaf node, the intermediate node and the root node are further stored in the database;
  • the value can be the storage content of the node, and the key can be the hash value of the storage content of the node.
  • each root node and intermediate node in the logical tree structure include multiple positions representing different characters respectively; and each position further includes multiple positions representing different characters respectively. slot; therefore, through this design, each root node and intermediate node will have a larger data storage capacity and data carrying capacity, so that the root node and intermediate node in the above-mentioned logical tree structure will be written into the database.
  • the data storage capacity of the root node and the intermediate node can be compared with the single IO read of the storage medium carrying the above-mentioned database.
  • the write capacity is more suitable, so that the IO read and write capabilities of the storage medium carrying the above database can be fully utilized to improve the data read and write efficiency; moreover, the data storage capacity and data carrying capacity of the nodes in the above-mentioned logical tree structure are improved.
  • each root node and intermediate nodes will have larger data storage capacity and data carrying capacity; and, the above logic
  • the number of layers of the root node and intermediate node contained in the tree structure of the tree structure will be in a relatively stable state; therefore, the storage capacity of the root node and the intermediate node is improved and the number of layers of the root node and the intermediate node is relatively stable,
  • the root node and intermediate nodes of the above-mentioned logical tree structure will have fewer layers; thus, the root node and intermediate nodes have greater data storage capacity and data carrying capacity, and the above logic
  • the root node and intermediate nodes of the tree structure have fewer layers, when the system performs a cold start, it is necessary to transfer the roots of the first N layers of the above logical tree structure from the storage medium carrying the above database.
  • the number of IO reads when the root nodes and intermediate nodes of the top N layers stored in the above storage medium are read into the memory can be significantly reduced, and The overall read time when the root nodes and intermediate nodes of the first N layers of the logical tree structure are loaded into the memory, thereby fundamentally shortening the startup delay when the system is cold-started.
  • FIG. 3 is a flowchart of a method for storing blockchain data provided by an exemplary embodiment.
  • the method is applied to a block chain node device; the method includes the following steps: step 302, obtaining a key-value key-value pair of the block chain data to be stored; step 304, storing the block chain data to be stored
  • the key-value key-value pair is converted into a root node, an intermediate node and a leaf node on a logical tree structure; the root node and the intermediate node include a plurality of characters used to store the characters in the key of the blockchain data.
  • each location includes a plurality of slots for storing characters in the key of the blockchain data; the slots are used to store the hash value of the next-layer node linked to the node; Step 306,
  • the key-value key-value pairs of the root node, the intermediate node and the leaf node are stored in the database; in the key-value key-value pairs of the leaf node, the intermediate node and the root node, the value is the value of the node.
  • Storage content the key is the hash value of the storage content of the node.
  • the so-called logical tree structure means that in the underlying physical storage of the database, there is no physical storage structure completely corresponding to the tree structure, but only the physical data of each node on the above tree structure is stored in the database. and link relationship data between each node, so that the above tree structure can be restored on a logical level based on the physical data and link relationship data of each node stored in the database.
  • the above-mentioned logical tree-like structure may specifically include a root node, an intermediate node and a leaf node; wherein, the nodes on the above-mentioned logical tree-like structure may be linked with the nodes of the upper layer through their own hash values.
  • the above-mentioned root node and intermediate node are specifically used to store at least one character in the key in the key-value key-value pair of the blockchain data; the above-mentioned leaf nodes are specifically used to store the value of the blockchain data (that is, the blockchain data specific content).
  • the number of layers of the intermediate nodes may be one or more layers, and is not particularly limited in this specification.
  • the key of the above blockchain data can still include a character prefix part (Shared nibble) and a character suffix part (key-end); in this case, the root node and intermediate nodes can be used for storage The characters in the above character prefixes; and the above leaf nodes can be used to store the above character suffixes and the value of blockchain data.
  • a character prefix part Shared nibble
  • a character suffix part key-end
  • the above-mentioned logical tree structure can store the characters in the key of the blockchain data; therefore, the above-mentioned logical tree structure has the characteristics of Trie dictionary tree; on the other hand, the above-mentioned The nodes on the logical tree structure can be linked with the nodes of the upper layer through their own hash values; therefore, the above logical tree structure also has the characteristics of Merkle tree.
  • the logical tree structure described in this specification is actually a Merkle tree variant similar to the MPT tree that incorporates the tree structure of the Trie dictionary tree.
  • Fig. 4 is a tree structure diagram of a FDMT (Fixed Depth Merkle Tree) tree shown in this specification.
  • the above FDMT tree is a Merkle tree variant incorporating the tree structure of the Trie dictionary tree.
  • the tree structure of the FDMT tree shown in this specification includes the Tree nodes of the first N layers (the three layers shown in FIG. 4 are only illustrative), and the Leaf of the last layer. node (ie leaf node).
  • the first layer is the Tree node as the root node
  • the other layers are the Tree node as the intermediate node.
  • each Tree node that is, the root node and the intermediate node in the first N layers of the above-mentioned FDMT tree will adopt a unified data structure, so that each Tree node in the first N layers of the above-mentioned FDMT tree will be , node splitting can no longer occur because the length of stored characters changes due to newly written data.
  • the tree nodes of the first N layers on the above-mentioned FDMT tree may include multiple blocks representing different characters respectively; the above-mentioned blocks are the "positions" of the characters in the key used to store the blockchain data. And each block may further include a plurality of slots representing different characters; the above slots are also used to store the characters in the key of the blockchain data.
  • each Tree node includes N blocks; each block further includes N slots.
  • the method of filling the hash value (hash pointer) of the node of the next layer in the node of the upper layer can still be used to carry out the link between the nodes. That is, the nodes in the above-mentioned FDMT tree are linked to the nodes of the upper layer through their own hash values.
  • the above slot can be specifically used to fill the hash value of the next layer node linked by the current Tree node.
  • the next-level node of the Tree node can still be a Tree node or a Leaf node.
  • the above-mentioned Tree node can specifically adopt the data structure of the main block (ie the main position) and multiple sub-blocks (ie the sub-positions).
  • FIG. 5 is a tree structure diagram of another FDMT tree shown in this specification.
  • the tree structure of the FDMT tree shown in this specification still includes the Tree nodes of the first N layers and the leaf nodes of the last layer.
  • the tree nodes of the first N layers on the above-mentioned FDMT tree shown in FIG. 5 may include the main block (that is, the root shown in FIG. 5 ). block) and a plurality of sub-blocks representing different characters respectively; and each block may further include a plurality of slots; for example, as shown in FIG. 5, each Tree node includes a main block and N sub-blocks; and each sub-block The block further includes N slots.
  • the functions of the slots included in the above-mentioned main block and sub-blocks may be different; as shown in FIG. 5 , for the main block, it may include a plurality of slots corresponding to each sub-block, and each slot Specifically, it can be used to fill the hash of the data content stored in the corresponding sub-block; for example, when calculating the hash of any sub-block, the hash values filled in each slot in the sub-block can be spliced together, and then spliced together The hash of the sub-block performs a secondary hash calculation to obtain the hash of the sub-block.
  • the sub-block can contain multiple slots representing different characters, and each slot can be used to fill the hash value of the next-level node linked by the tree node.
  • the hash value of the main block in the Tree node can be used to represent the hash value of the Tree node; thus, in this case, when the above-mentioned FDMT tree After the hash value filled in the slot in any sub-block in the tree node above is updated, when recalculating the hash value of the tree node, it is only necessary to update the data in each slot in the sub-block.
  • the filled hash value is spliced, and the spliced hash value is used as a calculation parameter to re-hash calculation, and then the calculated hash value is filled into the slot corresponding to the sub-block in the main block in the tree node, and then The hash of each slot in the main block is spliced, and the spliced hash value is used as a calculation parameter to re-calculate the hash to obtain the hash of the tree node.
  • the hash value filled in each slot in other sub-blocks without data update will no longer need to be spliced and used as a calculation parameter to participate in the hash calculation, which can reduce the time when the hash value of the tree node is recalculated.
  • the hash calculation amount and calculation time are improved, and the calculation efficiency of hash calculation is improved.
  • Each tree node on the above-mentioned FDMT tree shown in Fig. 4 and Fig. 5 can be used to store at least some characters in the key of the above-mentioned blockchain data.
  • the characters actually stored can be specifically the characters represented by blocks in the Tree node (that is, at least one slot is filled with a non-empty block with a hash value), A string generated by splicing with the character represented by the slot filled with the hash value (ie, the non-empty slot) in the block.
  • the characters actually stored can be specifically the characters represented by the sub-blocks in the Tree node, and the characters represented by the slots filled with hash values in the block. character, the string generated by concatenation.
  • each block in the Tree node can only represent one character; that is, based on the storage format of the Tree node shown in Figures 4 and 5, the above-mentioned blockchain actually stored by each Tree node Part of the characters in the character prefix of the key of the data is a string of 2 characters in length.
  • FIG. 6 is a structural diagram of a Tree node shown in this specification; as shown in FIG. 6, the Tree node contains 16 sub-blocks representing different hexadecimal characters; each sub-block It further includes 16 slots that represent different hexadecimal characters respectively (only 16 slots included in block6 are shown in Figure 6); it is assumed that the sub-block6 (representing the hexadecimal character 6) in the tree node is not Empty block, slot4 (representing the hexadecimal character 4), slot6 (representing the hexadecimal character 6) and slot9 (representing the hexadecimal character 9) in the sub-block are filled with the next tree node link
  • the number of sub-blocks contained in the above-mentioned Tree node, and the number of slots contained in each sub-block are not particularly limited in this specification;
  • the number of sub-blocks contained in the above-mentioned tree node and the number of slots contained in the above-mentioned sub-blocks can be kept the same; for example, in an example, the characters corresponding to the keys of the above-mentioned blockchain data are used
  • the string is a hexadecimal string as an example.
  • the above-mentioned tree nodes of the first N layers can each include 16 sub-blocks representing different hexadecimal characters; and each sub-block can further include 16 sub-blocks. Slots representing different hexadecimal characters.
  • the Tree node on the FDMT tree shown in Figure 4 is relative to Figure 1. In terms of the nodes used to store character prefixes on the MPT tree, it will have a larger storage capacity.
  • the number of sub-blocks contained in the above-mentioned tree node may be different from the number of slots contained in the above-mentioned sub-blocks;
  • the character string corresponding to the key of the above-mentioned blockchain data can also be a character string composed of two different base characters; for example, the character string corresponding to the key of the above-mentioned blockchain data can be is a string composed of a mixture of hexadecimal characters and hexadecimal characters.
  • the above-mentioned tree nodes of the first N layers can each include 16 sub-blocks representing different hexadecimal characters; and Each sub-block may further include 10 slots representing different decimal characters; or, the above-mentioned tree nodes of the first N layers may include 10 sub-blocks representing different decimal characters respectively; and each The sub-block may further include 16 slots representing different hexadecimal characters.
  • the number of layers of Tree nodes included in the above-mentioned FDMT tree may be a fixed value; in practical applications, the value of the above-mentioned N may be an integer greater than or equal to 1; or That is, the above-mentioned FDMT tree may specifically be a Merkle tree including at least one layer of Tree nodes, and the number of layers of the included Tree nodes is relatively fixed.
  • the first 6 address characters of the blockchain account address can be used as the character prefix of the blockchain account address; moreover, since the length of the characters in the character prefix of the blockchain account address stored by the Tree node is 2-bit character; therefore, the above FDMT tree can be designed as a tree structure containing three levels of Tree nodes.
  • each Tree node in the FDMT tree includes a plurality of blocks representing different characters respectively; and each block further includes a plurality of Slots representing different characters respectively; therefore, through this design, each Tree node will have a larger data storage capacity and data carrying capacity, so that when the Tree node in the above FDMT tree is written into the database for storage;
  • the data storage capacity of the Tree node can be more adapted to the capacity of a single IO read and write of the storage medium carrying the above-mentioned database, so that the bearing capacity can be fully utilized.
  • the IO read and write capability of the storage medium of the above-mentioned database improves the efficiency of data read and write; moreover, the improvement of the data storage capacity and data carrying capacity of a single tree node on the above-mentioned FDMT tree will inevitably lead to the overall data storage capacity of the above-mentioned FDMT tree. and the improvement of data carrying capacity, so that more blockchain data can be stored on the above FDMT tree; for example, taking the storage medium carrying the above database as a disk with a single physical sector of 4KB as an example, it is assumed that the disk has a single IO
  • the capacity of reading and writing is 4kb (one sector).
  • each Tree node in the tree structure of FDMT shown in Figure 4 and Figure 5 is more suitable for the single IO read and write capacity of the above-mentioned disk, and can make full use of the IO of the disk itself. Read and write ability, improve data read and write efficiency.
  • each Tree node in FDMT adopts a unified data structure; for the Tree nodes of each layer in the above-mentioned FDMT, the character length of the character prefix of the key of the actually stored blockchain data will also remain unchanged. Fixed; therefore, through this design, frequent splitting of nodes caused by the fact that the length of characters actually stored in each layer of Tree nodes is not fixed can be avoided, thereby ensuring the number of layers of Tree nodes contained in the tree structure of FDMT. , is always in a relatively stable state.
  • each Tree node will have greater data storage capacity and data carrying capacity; and, the number of layers of Tree nodes contained in the tree structure of the FDMT will be in a relatively stable state. Therefore, the improvement of the storage capacity of the Tree node and the number of layers of the Tree node are relatively stable, to some extent, it can be ensured that the Tree node of the above FDMT will have fewer layers; thus, the Tree node has a larger data storage On the basis of the capacity and data carrying capacity, and the tree node of the above FDMT has fewer layers, the system needs to use the tree node of the first N layers of the above FDMT from the storage medium carrying the above database as the cold start.
  • the data that needs to be read frequently When the data that needs to be read frequently is loaded into the memory, it can significantly reduce the number of IO reads when reading the tree nodes of the first N layers stored in the above storage medium into the memory, and the tree nodes of the first N layers of the FDMT can be read into the memory.
  • the overall read time when the node is loaded into memory thereby fundamentally shortening the startup delay when the system is cold started.
  • the FDMT shown in Fig. 4 and Fig. 5 is fixed as a 3-layer Tree node, and the Tree node of each layer includes 16 blocks representing different hexadecimal characters; each block further includes 16 blocks representing different hexadecimal characters.
  • Has a larger number of layers for example, the MPT tree can reach up to 64 layers, which is much larger than 3 layers).
  • the storage capacity of a single Branch Node node on the MPT tree is 512 bytes, only the single physical sector carrying the above database is one-eighth of 4KB, and the reading efficiency is very low; therefore, even according to the MPT tree and The FDMT tree shown in Figures 4 and 5 stores the same data, and the number of IO reads for the MPT tree during the cold start of the system may be at least 8 times the number of IO reads for the FDMT tree shown in Figures 4 and 5 times.
  • the character string corresponding to the key of the above-mentioned blockchain data may still include character prefixes and character suffixes; in this case, the above-mentioned Tree node can be used to store the The character in the character prefix of the key; the leaf node can be used to store the character suffix of the key of the blockchain data and the Value of the blockchain data.
  • the data actually stored by the above-mentioned leaf nodes usually has a larger data capacity than the above-mentioned Tree nodes; for example, the value of the above-mentioned blockchain data actually stored by the above-mentioned leaf nodes is usually the above-mentioned blockchain data.
  • the original content of the above-mentioned blockchain data also occupies a larger storage space; therefore, in this specification, in order to ensure that the above-mentioned leaf nodes can have more For large data capacity, the above leaf nodes can specifically store data in the form of large data blocks.
  • the above-mentioned leaf node may specifically be in the form of a bucket data bucket; wherein, the above-mentioned bucket data bucket specifically Can be a container or storage space for storing data.
  • FIG. 7 is a structural diagram of a bucket data bucket shown in this specification; as shown in FIG. 7 , the above-mentioned bucket data bucket (ie, the bucket node shown in FIG. 7 ) may include several Data records; wherein, the above-mentioned several data records contained in the above-mentioned bucket data buckets may not logically be a whole, but logically separated several different data records.
  • Each data record corresponds to a piece of blockchain data, which is used to store the value of the above-mentioned blockchain data; that is, a data record refers to a storage record whose data content includes the value of the blockchain data. .
  • each data record can correspond to an independent query key value (key), so that the query key of each data record can be based on value, to perform precise query for each data record in the above bucket data bucket, instead of reading all the data records stored in the above bucket data bucket as a whole.
  • key independent query key value
  • the specific form and specific content of the query key value corresponding to each data record are not particularly limited in this specification, and can be any form of character string that can be used as a query index for each data record.
  • the query key value corresponding to each data record may specifically be the hash value of the data content contained in each data record;
  • the above-mentioned data record contained in the above-mentioned bucket data bucket may specifically include the following: A key-value key-value pair formed by the hash value of the value of the above blockchain data and the data content corresponding to the value of the above blockchain data.
  • the query key value corresponding to each data record may also be a string other than the hash value that can be used as the query index of each data record, which is not particularly limited in this description; for example, , in an example, the query key value corresponding to each data record may also be a unique identifier (such as a serial number) respectively set by the node device for each data record.
  • the above-mentioned Tree node is used to store the characters in the character prefix of the key of the above-mentioned blockchain data; then the above-mentioned leaf node is used to store the character suffix of the key of the above-mentioned blockchain data and the above-mentioned
  • the value of the blockchain data correspondingly, the above data records contained in the above bucket data buckets may specifically be the data content corresponding to the character suffix in the key of the above blockchain data and the value of the above blockchain data as a whole.
  • the hash value obtained by the hash calculation is a key-value key-value pair formed by the character suffix of the key of the above-mentioned blockchain data and the data content corresponding to the value of the above-mentioned blockchain data.
  • the above data records may also be other types of data forms other than key-value pairs, which will not be listed one by one in this specification.
  • the above FDMT since several data records contained in the leaf nodes in the FDMT tree are no longer a whole logically, they are logically separated several key-value pairs; therefore, the above FDMT
  • the data contained in the leaf nodes in the tree will no longer be accessed as a whole access unit in the database, and each key-value pair contained in the above leaf nodes will be used as an independent access unit, so that the data access to the above-mentioned database will be more flexible;
  • the value of the above-mentioned blockchain data is the latest account status data corresponding to the blockchain account in the blockchain
  • the value of the above-mentioned blockchain data is
  • the key is the blockchain account address.
  • the key of the key-value key-value pair corresponding to the above data record contained in the above bucket data bucket can be the character suffix of the blockchain account address and the corresponding The hash value of the two parts of the account status data; the value of the key-value pair can be the character suffix of the blockchain account address and the data content of the corresponding account status data.
  • the state data can construct a key-value key-value pair, and write the key-value key-value pair into the above bucket data bucket; or, based on the character suffix of the specific account address and the corresponding account status data two parts of the data content
  • the hash value of the account address perform content addressing in the database, find the corresponding key-value key-value pair, and then write the updated account status data corresponding to the specific account address, and the original key-value key-value pair. value can be updated.
  • the number of data records contained in the above-mentioned bucket data bucket is not particularly limited in this specification; in the illustrated implementation manner, the number of data records contained in the above-mentioned bucket data bucket may specifically be Custom configuration by the user.
  • the above blockchain data is the latest account status data corresponding to the blockchain account in the blockchain, and the key of the above blockchain data is the blockchain account address.
  • the above bucket data Each data record in the bucket corresponds to the account status of a blockchain account; the number of data records in the above bucket data bucket actually represents that the bucket data bucket can accommodate the account bearer of the blockchain account Therefore, by customizing the number of data records that the above bucket data bucket can hold, the user can flexibly customize the account carrying capacity of the above bucket data bucket; for example, in an example, the above bucket data bucket
  • the number of data records contained in it can be configured by the user to be 16 or 64, so that a single bucket can carry the status data of 16 or 64 blockchain accounts.
  • the total storage capacity of the data records stored in the above bucket data bucket is not particularly limited in this specification; in an implementation manner shown, the total storage capacity of the data records stored in the above bucket data bucket Capacity, which can be customized by the user.
  • the storage medium carrying the above-mentioned database is a disk with a single physical sector of 4KB. It is set to 4KB; or an integer multiple of 4KB, so that the maximum storage capacity of the bucket data bucket can be adapted to the storage capacity of a single physical sector of the storage medium.
  • each Tree node of the first N layers on the above-mentioned FDMT tree adopts a unified data structure; therefore, each Tree node of the first N layers on the above-mentioned FDMT tree will no longer be split. .
  • the leaf nodes on the above-mentioned FDMT tree can still perform node splitting when certain splitting conditions are met.
  • the leaf nodes on the above-mentioned FDMT tree when they are split, they can no longer be split according to the change of the character length of the shared character prefix, but according to the storage capacity of the leaf node. split.
  • an intermediate node ie, the Extend node shown in FIG. 5
  • the split intermediate node is the upper-level node of the above leaf node. For the same leaf node, multiple splits can be performed.
  • the above-mentioned node splitting condition may include any form of condition related to the storage capacity of the above-mentioned leaf node, which is not particularly limited in this specification; in the illustrated embodiment, the above-mentioned node splitting condition may specifically be: Condition 1 and Condition 2 shown below; or a combination of Condition 1 and Condition 2 shown below: Condition 1: The total number of data records stored in the above leaf nodes is greater than the threshold; Condition 2: The total storage capacity of the data records stored in the above leaf nodes is greater than the threshold.
  • the above-mentioned node splitting condition may be set as, when the total number of data records stored in the above-mentioned leaf nodes is greater than 64; and/or, the total storage capacity of the data records stored in the above-mentioned leaf nodes is greater than 4KB , the intermediate node is split from the leaf node.
  • the above-mentioned Extend node which is also the intermediate node of the above-mentioned FDMT tree, can adopt the exact same data structure as the above-described Tree node, and is specifically used to store the characters split from the character suffixes stored in the above-mentioned leaf nodes; for example , please refer to Figure 4 and Figure 5, the Extend node split from the leaf node may also include multiple blocks representing different characters; and each block may further include multiple slots representing different characters; the slot The bit can be used to fill in the hash value of the next layer node linked by this node.
  • the next-layer node is the above-mentioned leaf node; therefore, the slot contained in the block in the Extend node can be used to fill the hash value of the next-layer leaf node linked by the Extend node.
  • an Extend node split from the above-mentioned leaf nodes it may also be merged with the lower-level leaf nodes linked to the Extend node according to the storage capacity of the Extend node.
  • the Extend node can be merged into the lower-level leaf node linked to it.
  • merging the Extend node into the lower-level leaf node linked to it means that the character stored in the Extend node is used as the above-mentioned character suffix and written into one or more leaf nodes of the lower layer linked with the Extend node.
  • the above-mentioned node merging condition may also include any form of condition related to the storage capacity of the above-mentioned Extend node, which is not particularly limited in this specification; in the illustrated embodiment, the above-mentioned node merging condition may specifically be is any one of Condition 3 and Condition 4 shown below; or, it can also be a combination of Condition 3 and Condition 3 shown below: Condition 1: The total number of characters stored in the Extend node above is less than or equal to the threshold ; That is, the total number of non-empty slots (that is, slots filled with hash values) in each block in the Extend node above; Condition 2: The total storage capacity of the characters stored in the Extend node above is less than or equal to the threshold.
  • the above node merging condition can be set as, when the total number of characters stored in the Extend node above Less than or equal to 1; and/or, when the total storage capacity of the characters stored in the Extend node is less than or equal to 1KB, the characters stored in the Extend node are used as character suffixes, and are written into one of the lower layers of the Extend node link or multiple leaf nodes.
  • the Extend node described in this specification can be a dynamically scalable intermediate node on the above-mentioned FDMT tree; when the storage capacity of any leaf node on the above-mentioned FDMT tree satisfies the node splitting condition, it can be used from the leaf node. At least one Extend node and at least one leaf node are split in the middle; when the storage capacity of any Extend node satisfies the node merging condition, the Extend node can be merged into the lower-level leaf node linked to it.
  • the blockchain data to be stored may specifically include at least the following four types of data: transactions included in the block; Transaction receipt; after the transaction in the block is executed, the latest account status data corresponding to the blockchain account in the blockchain; the storage content of the smart contract account;
  • the above-mentioned FDMT tree may also specifically include: A transaction tree used to store transactions included in the block; a receipt tree used to store transaction receipts corresponding to transactions included in the block; used to store the latest account corresponding to the blockchain account in the blockchain A state tree for state data; a storage tree for storing the storage content of smart contract accounts.
  • the tree structure of the above FDMT tree can be used to store some types of data in the above four types of data; for example, only the above FDMT tree can be used to store the latest account status corresponding to the above blockchain account Data, other types of data can be stored using other forms of binary trees (such as MPT or other forms of binary trees).
  • the hash value of the root node of the above transaction tree, receipt tree and state tree can be stored in the block header; the hash value of the root node of the above storage tree can be stored in the structure of the contract account corresponding to the storage tree. in the Storage field.
  • the key of the above-mentioned blockchain data may specifically refer to the corresponding search key value of the blockchain data in the database; correspondingly, the value of the above-mentioned blockchain data may specifically be the original content of the above-mentioned blockchain data; wherein, In practical applications, the above-mentioned search key may be a string corresponding to the blockchain data; when the above-mentioned blockchain data is of different types, the corresponding keys will also be different; for example, when the above-mentioned blockchain data is of different types
  • the above blockchain data is the transaction included in the block; or, after the transaction in the block is executed, when the transaction receipt corresponding to the transaction included in the block is the transaction receipt, the key corresponding to the blockchain data at this time , which can be the sequence number of the transaction in the block; or, a transaction identifier in other forms.
  • the key corresponding to the blockchain data at this time can be specifically The account address of the blockchain account.
  • the key corresponding to the blockchain data at this time may specifically be the account address of the contract account and the storage location of the above-mentioned storage content in the account storage of the contract account.
  • Hash value for example, in an example, the above storage content can usually be a state variable, then the account address of the contract account and the hash value of the storage location of the state variable in the account storage of the contract account can be used as the key.
  • the node device in the blockchain when it is storing blockchain data, it can first obtain the key-value pair of the blockchain data to be stored; for example, in an example, the node device can be stored in the When the blockchain data to be stored is obtained, the blockchain data is processed into key-value key-value pairs; after the key-value key-value pairs of the blockchain data to be stored are obtained, the to-be-stored blockchain data can be The key-value key-value pair of the blockchain data is converted into the root node, intermediate node and leaf node on the above-mentioned logical tree structure; for example, in an example, the above-mentioned node device can carry a corresponding FDMT tree.
  • the storage interface or storage service can specifically be used to convert the key-value key-value pair of the blockchain data to be stored into a node on the FDMT tree; After the key-value key-value pair of the blockchain data, the key-value of the blockchain data to be stored can be stored according to the tree structure of the FDMT tree shown in Figure 4 or Figure 5 by calling the storage interface or storage service. The value key-value pair is converted into the root node, intermediate node and leaf node in Figure 4 or Figure 5.
  • the key-value pair is stored in the database; for example, the above-mentioned database is usually stored in a persistent storage medium (such as a storage disk) carried on the above-mentioned node device; the above-mentioned storage medium is the physical storage corresponding to the above-mentioned database;
  • the above-mentioned FDMT tree is stored in the database, specifically, by executing the commit command, the nodes on the above-mentioned FDMT tree can be further written into the storage carrying the above-mentioned database from the memory of the node device in the form of a Key-Value key-value pair. medium.
  • the specific type of the above-mentioned database is not particularly limited in this specification, and those skilled in the art can flexibly choose based on actual needs; in an implementation manner, the above-mentioned database can be specifically a Key-Value type database;
  • the above database may be a LevelDB database using a multi-layer storage structure; or, a database based on a LevelDB architecture; for example, a Rocksdb database is a typical database based on a LevelDB database architecture.
  • the key of the above-mentioned Key-Value key-value pair may specifically be the node ID of the node on the above-mentioned FDMT tree; wherein, The above-mentioned node ID may specifically include identification information that can uniquely identify the node on the above-mentioned FDMT tree; for example, in an implementation manner, the above-mentioned node ID may specifically be the hash value of the data content contained in the node on the above-mentioned FDMT tree; in this In this case, when a node on the FDMT tree needs to be queried, content addressing can be performed based on the hash value of the data content contained in the node as a key.
  • the node ID may specifically include path information of the node on the FDMT tree in the FDMT tree; that is, the path information of the node on the FDMT tree in the FDMT tree is used as the The node ID of the node; wherein, the above-mentioned path information may specifically include information in any form that can describe the link relationship between the node and other nodes, and the position of the node on the above-mentioned FDMT tree; for example, please refer to FIG. 8, FIG.
  • FIG. 8 A schematic diagram of setting a node ID for a node on the FDMT tree shown in this specification; for a FDMT tree containing a three-layer Tree node as shown in Figure 8, it is assumed that the node ID of the tree node as the root node is represented by 0x00, then The node ID of the bucket node shown in Figure 8 can be represented as 0x00123456.
  • 0x00 is the node ID of the root node; 123456 refers to the path information of the above bucket node from the root node to the bucket node in the FDMT tree; 12 refers to the second slot of the first block of the first layer tree node; 34 represents the 4th slot of the 3rd block of the second-level tree node; 56 represents the 6th slot of the 5th block of the third-level tree node.
  • the link relationship between the bucket node and other nodes can be clarified, as well as the specific location of the bucket node on the above FDMT tree; for example, based on the node ID, it can be clarified that the bucket node is linked to the third-level tree
  • the sixth slot of the fifth block of the node; and the tree node of the third layer is linked to the fourth slot of the third block of the second layer of the tree node; the tree node of the second layer is further linked in
  • the first layer is the second slot of the first block of the tree node of the root node.
  • the specific slot in the FDMT tree where the node is located can be precisely located.
  • the node ID may specifically include the relative position of the node on the FDMT tree in the FDMT tree, and the hash value of the data content contained in the node (at this time, the node ID can also be used as The hash identifier of the node); that is, the relative position of the node on the FDMT tree in the FDMT tree and the hash value of the data content contained in the node are used as the node ID of the node.
  • the relative position of the node in the above-mentioned FDMT tree and the hash value of the data content contained in the node can be concatenated with the generated string as the node ID of the node; of course, in practical applications, in In the process of splicing, other types of information other than the above-mentioned relative position and the above-mentioned hash value can also be further introduced to generate a node ID; they will not be listed one by one in this specification.
  • the node ID when the node ID is used to retrieve the node stored in the FDMT tree, the node can be precisely located in the FDMT The specific slot on the tree.
  • the storage medium used to carry the above-mentioned database on the above-mentioned node device may specifically be a persistent storage medium; for example, it may be a disk, memory or other forms of storage medium capable of persistently storing data, which is not described in this specification. List them one by one.
  • the nodes on the FDMT tree can also be encoded in advance, and then the key of the encoded node can be encoded. -value key-value pairs are stored in the database.
  • both the Tree node and Extend node on the above-mentioned FDMT tree contain multiple blocks, and each block further includes a data structure of multiple slots; therefore, in this specification, coding is performed for the above-mentioned FDMT tree.
  • bitmap encoding can be performed for the blocks in the Tree node and Extend node on the above FDMT tree.
  • bitmap encoding Information which can be a hexadecimal string used to identify whether each slot in the block is filled with a hash value; it is assumed that the block to be encoded (can be a main block or a sub-block) contains a total of 16 slots ; The 0th, 8th, 9th, 10th, and 11th bits in the 16 slots are filled with hash values respectively; then whether each slot in the block is filled with the hash statistics, you can use The binary string 0000 1111 0000 0001 represents; the leftmost of the binary string is the highest 15th bit, and the rightmost is the lowest 0th bit; finally, the binary string can be converted into a hexadecimal string 0x0f01; At this time, the hexadecimal string 0x
  • bitmap encoding when bitmap encoding is performed on the blocks in the Tree node and Extend node on the above-mentioned FDMT tree, whether it is the main block or the sub-block, the bitmap encoding process is exactly the same.
  • the blocks contained in the Tree node and Extend node in the encoded FDMT tree are added, it can indicate whether each slot in the block is filled with bitmap encoding information of the hash value;
  • the non-empty slot in the block can be determined through the bitmap encoding information in the block, and there is no need to traverse each slot in the block. , which can improve the search efficiency.
  • the leaf nodes on the above-mentioned FDMT tree use a completely different data structure from the Tree node and Extend node; therefore, when encoding the leaf nodes on the above-mentioned FDMT tree, it can also be completely different from the above-mentioned Tree node and Extend node. different encodings.
  • RLP Recursive Length Prefix, recursive length prefix encoding
  • the encoding method used when encoding the leaf nodes on the above-mentioned FDMT tree may also be encoding methods other than RLP encoding. In practical applications, it can be flexibly selected. will not be listed one by one.
  • the key-value pairs of the nodes on the FDMT tree may be stored in the database.
  • the encoded bitmap information is added to the block in the Tree node and Extend node after encoding to determine the empty slots in the block that are not filled with hash values, and then delete the determined empty slots from the block.
  • bitmap encoding information contained in the encoded block and the hash value filled with the non-empty character slot can be used as a whole for hash calculation; of course, you can also Exclude bitmap encoding information.
  • leaf nodes used to store the character suffix and value of the blockchain data have not been split, it is only necessary to change the leaf nodes of the character suffix and value used to store the blockchain data on the above FDMT tree, and The tree node of the character prefix of the key used to store the blockchain data can be updated separately.
  • the node device can search the above-mentioned database for the node corresponding to the above-mentioned blockchain data that needs to be updated; wherein, the specific search method will not be repeated; and then read the found node from the above-mentioned database to In the memory, these nodes are modified and updated in the memory, and then the updated nodes are further written into the above database to update the original updated nodes.
  • updating the leaf node on the FDMT tree whose data is updated may specifically include updating the value of the blockchain data stored in the leaf node.
  • the hash value of the leaf node can be recalculated, and based on the hash value, it can be re-linked with the nodes in the upper layer of the node.
  • updating the Extend node or Tree node on the upper layer of the leaf node where the data update occurs on the above-mentioned FDMT tree may specifically include updating the slot in the Extend node or Tree node filled with the hash value of the leaf node; After completion, you can recalculate the hash value of the Extend node or Tree node, and continue to re-link with the node on the layer above the node based on the hash value.
  • the hash value of the leaf node can be recalculated, and based on the hash value and the previous leaf node
  • the node of the layer (which can be a Tree node or an Extend node) is re-linked.
  • the node device can determine whether the leaf node on the above-mentioned FDMT tree is updated with data, and if any leaf node on the above-mentioned FDMT tree is updated with data, the node device can recalculate the hash value of the leaf node, And based on the hash value, before relinking with the Tree node or Extend node on the upper layer of the leaf node, further determine whether the storage capacity of the leaf node meets the node splitting condition; if the storage capacity of the leaf node meets the node splitting condition, you can further from The leaf node is split into at least one Extend node.
  • the leaf node when the storage capacity of the leaf node satisfies the node splitting condition, in order to rapidly reduce the storage capacity of the leaf node, the leaf node may be split into one Extend node and multiple leaf nodes.
  • the splitting strategy for splitting the Extend node from the above-mentioned leaf nodes is not particularly limited in this specification. In practical applications, users can customize settings according to specific splitting requirements; in the one shown in the In an embodiment, the above-mentioned splitting strategy may specifically include: splitting the latest data record written into the leaf node in the current block cycle, splitting it from the leaf node, and additionally creating an Extend node and a leaf based on the latest data. node.
  • the latest data records written to the target leaf node in the current block cycle can be determined; Delete the node from the node, and split the character prefix from the character suffix contained in these latest data records; for example, in one example, the first two digits of these latest data records can be split by default; or, in these latest data records If there is a shared character prefix in the character suffix included in the data record, and when the length of the shared character prefix reaches two digits, the shared character prefix is split.
  • At least one Extend node for storing the split character prefix and at least one leaf node for storing the latest data record after splitting the character prefix are further created.
  • At least one Extend node and At least one leaf node is used as a split node; therefore, for the target leaf node, after the node split is performed, the data records actually stored by the target leaf node will be the same as the data records stored by the target leaf node in the previous block cycle.
  • the data records are completely consistent; the hash value of the target leaf node will not change from the previous block cycle.
  • the target leaf node when the target leaf node writes new blockchain data in the current block cycle, so that the storage capacity of the target leaf node satisfies the node splitting condition, it only needs to split the newly written data record and re-create it. It is enough to create additional Extend nodes and leaf nodes, and it is no longer necessary to recalculate the hash value of the target leaf node and relink the nodes of the previous layer; through this splitting method, not only the leaves that meet the node splitting conditions can be guaranteed The hash value of the node is in a stable state, and the number of times of recalculating the hash value of the leaf node can be reduced.
  • the splitting strategy may specifically include: splitting the shared character prefixes between the character suffixes included in several data records stored by the leaf node from the leaf node, and splitting the shared character prefixes from the leaf node based on the Shared character prefixes to additionally create Extend nodes.
  • the target leaf node when splitting any target leaf node, it can be determined whether there is a shared character prefix between the character suffixes contained in several data records stored by the target leaf node; If there is a shared character prefix between the character suffixes included in a data record, the shared character prefix can be deleted from the above-mentioned several data records, and at least one Extend node for storing the shared character prefix is created.
  • the characters stored in the above Extend node can also be the characters represented by the block and the slot filled with the hash value in the block.
  • a character string with a length of two digits then there is a shared character prefix among the character suffixes contained in several data records stored in the target leaf node, and when the length of the shared character prefix reaches two digits, the shared character prefix can be changed from The above-mentioned several data records are split out.
  • the hash value of the Extend node can also be recalculated, and based on the hash value and the Extend node on the The nodes of the layer undergo a relinking phase to complete.
  • the node device can determine whether the data update occurs on the Extend node on the FDMT tree. If the data update occurs on any Extend node split from the leaf node on the FDMY tree, the node device recalculates the data update.
  • the leaf node of the next layer of the link of the Extend node can be determined first; for example, the lower node of the link of the Extend node can be determined according to the hash value filled in the non-empty slot in the block contained in the Extend node. A leaf node of one layer; then, the character stored by the Extend node can be used as part of the above character suffix, and written to the determined leaf node of the next layer of the Extend node link.
  • the leaf node when a leaf node is split multiple times, the leaf node can be split into multiple layers of Extend nodes; in this case, when any Extend node satisfies the node merging condition, if its lower nodes still is an Extend node, not a leaf node, the Extend node cannot be merged temporarily; in this case, you can wait for the lower Extend node and the lower leaf node to complete the merge to form a new leaf node, and then merge with the lower layer. The new leaf node is merged twice, and the specific merging method will not be described again.
  • the following takes the above blockchain data as the latest account status data corresponding to the blockchain account, and the key of the above blockchain data is the blockchain account address as an example.
  • Form the writing adopts the specific process of the FDMT tree as shown in Figure 4 and Figure 5, which will be described in detail.
  • the user client connected to the blockchain can package the transaction data into a standard transaction format supported by the blockchain, and then publish it to the blockchain; while the node devices in the blockchain can be based on the The consensus algorithm and other node devices, together with other node devices, agree on these transactions published by the user client to the blockchain, so as to generate the latest block for the blockchain; the specific consensus process will not be repeated.
  • the account status of the target account related to the executed transaction in the blockchain usually changes accordingly; therefore, the node device in the target After the transaction in the block is executed, the latest account status data of the target account after account update (that is, the account status after the transaction in the target block is executed) can be obtained, and the obtained latest account status of the target account can be obtained.
  • the data is processed into key-value key-value pairs; wherein, the key of the key-value key-value pair is the account address of the target account; the value of the key-value key-value pair is the latest account status of the target account.
  • the key-value key-value pairs can be converted into Tree node, Extend node and Leaf node on the above FDMT tree, and the The key-value pairs of the above Tree node, Extend node and Leaf node are stored in the database.
  • Fig. 9 is a schematic diagram of writing account state data into the FDMT state tree shown in this specification; in the above-mentioned FDMT state tree shown in Fig. 9, the first three layers are Tree nodes, and the last layer is Leaf node; wherein, the above-mentioned leaf node may adopt the storage structure of the bucket data bucket described above.
  • the tree nodes of each layer include a main block and 16 sub-blocks representing different hexadecimal characters 1-f respectively; and each sub-block further includes 16 slots representing different hexadecimal characters 1-f respectively .
  • the Tree node as the root node on the FDMT tree can be located in the database (for example, according to The hash of the root node filled in the block header is used to locate the root node); if the data is written for the first time and the root node has not been created, the root node can be created at this time; then start from the root node Tree node1 of the first layer, and in turn in the third layer Determine the character slot corresponding to the character prefix "a71135" of the account address in the Tree node.
  • the character slot corresponding to the character prefix "a71135" of the account address specifically includes: the 8th slot (representing character 7) in the 11th sub-block (representing character a) of Tree node1; The second slot (representing character 1) in the second sub-block of Tree node2 (representing character 1); the sixth slot (representing character 5) in the fourth sub-block (representing character 3) of Tree node3.
  • the data record consisting of the character suffix "125" and the state data "state1" can be written in the bucket node linked by the sixth slot of the fourth sub-block of Tree node3; of course, if There is already a data record corresponding to the character suffix "125" in the bucket node, indicating that the value corresponding to the historical account status data of the above account address "a71135125" has been written to the FMDT tree; at this time, the value stored in the data record can be updated It can be "state1".
  • the hash value of the data content contained in the bucket node can be recalculated, and the hash value can be filled into the sixth slot of the fourth block of Tree node3, and the original hash value of the slot to update.
  • the original hash value of the slot is updated.
  • the original hash value of the slot is updated.
  • the hash value of the data content contained in the main block of the root node Tree node1 is recalculated, and based on the hash value The value updates the hash value of the root node of the FDMT state tree stored in the block header.
  • the hash value of the root node of the FDMT state tree stored in the block header is updated, and the update of the FDMT state tree is completed at this time, the key- The value key-value pair is successfully written to the FDMT state tree.
  • the present application also provides device embodiments.
  • this specification also provides an embodiment of a blockchain data storage device.
  • the embodiments of the blockchain data storage device of this specification can be applied to electronic devices.
  • the apparatus embodiment may be implemented by software, or may be implemented by hardware or a combination of software and hardware.
  • a device in a logical sense 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 the device is located.
  • FIG. 10 it is a hardware structure diagram of the electronic equipment where the blockchain data storage device of this specification is located, except for the processor, memory, network interface, and non-volatile shown in FIG. 10.
  • the electronic device in which the apparatus 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. 11 is a block diagram of a blockchain data storage device shown in an exemplary embodiment of the present specification.
  • the blockchain data storage device 110 can be applied to the electronic equipment shown in the aforementioned FIG. 10 , and the device 110 includes: an acquisition module 1101 for acquiring the key-value key of the blockchain data to be stored value pair; the conversion module 1102 converts the key-value key-value pair of the blockchain data to be stored into a root node, an intermediate node and a leaf node on a logical tree structure; the root node and the intermediate node include A plurality of positions for storing characters in the key of the blockchain data, and each position includes a plurality of slots for storing characters in the key of the blockchain data; the slots are used for Store the hash value of the next layer node linked to the node; the storage module 1103 stores the key-value pairs of the root node, the intermediate node and the leaf node in the database; the leaf node, the intermediate node In the key-value key-value pair with the root node, the value is the storage content of the node, and the key is the hash value of the storage
  • the number of layers of the root node and the intermediate node is a fixed value.
  • the root node and the intermediate node are used to store at least part of the characters in the key of the blockchain data; the at least part of the characters stored by the root node and the intermediate node are the root node ,
  • the character string represented by the position in the intermediate node is spliced with the character represented by the slot filled with the hash value in the position.
  • the leaf node is a bucket data bucket; the bucket data bucket contains several data records; the data content stored in the data record includes the value of the blockchain data.
  • the character string corresponding to the key of the blockchain data includes a character prefix and a character suffix;
  • the root node and the intermediate node include a plurality of locations for storing the characters in the character prefix, each The location includes a plurality of slots for storing characters in the character prefix;
  • the data content stored in the data record includes the character suffix and the value of the blockchain data.
  • the number of the positions included in the root node and the intermediate node is the same as the number of slots included in the positions.
  • the root node and the intermediate node include 16 positions that respectively represent different hexadecimal characters; the positions include 16 slots that respectively represent different hexadecimal characters.
  • the blockchain data includes any one of the following: transactions included in the block; transaction receipts corresponding to transactions included in the block; The latest account status data corresponding to the blockchain account; the storage content of the smart contract account.
  • the logical tree structure includes any one of the following: a transaction tree for storing transactions included in the block; a receipt for storing transaction receipts corresponding to transactions included in the block tree; a state tree used to store the latest account state data corresponding to the blockchain account in the blockchain; a storage tree used to store the storage content of the smart contract account.
  • a typical implementing device is a computer, which may be in the form of a personal computer, laptop computer, cellular phone, camera phone, smart phone, personal digital assistant, media player, navigation device, email sending and receiving device, game control desktop, tablet, wearable device, or a combination of any of these devices.
  • 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 forms of non-persistent memory, random access memory (RAM) and/or non-volatile memory in computer readable media, such as read only memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium.
  • RAM random access memory
  • ROM read only memory
  • flash RAM flash memory
  • Computer-readable media includes both persistent and non-permanent, removable and non-removable media, and storage of information may be implemented by any method or technology.
  • Information may be computer readable instructions, data structures, modules of programs, 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 tape cartridges, disk storage, quantum memory, graphene-based storage media or other magnetic storage devices or any other non-transmission media can be used to store information that can be accessed by computing devices.
  • computer-readable media does not include transitory computer-readable media, such as modulated data signals and carrier waves.
  • first, second, third, etc. may be used in this specification to describe various information, such information should not be limited by these terms. These terms are only used to distinguish the same type of information from each other.
  • first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information without departing from the scope of one or more embodiments of the present specification.
  • word "if” as used herein can be interpreted as "at the time of" or "when” or "in response to determining.”

Abstract

A block chain data storage method and apparatus, and an electronic device. The method comprises: obtaining key-value pairs of blockchain data to be stored; converting the key-value pairs of said blockchain data into a root node, an intermediate node, and a leaf node on a logical tree structure, the root node and the intermediate node comprising a plurality of positions for storing characters in keys of the blockchain data, the positions each comprising a plurality of slots for storing characters in the keys of the blockchain data, and the slots being used for storing hash values of the next layer of nodes linked to the corresponding node; and storing in a database the key-value pairs of the root node, the intermediate node, and the leaf node, in the key-value pairs of the leaf node, the intermediate node, and the root node, values being the storage content of the nodes, and the keys being the hash values of the storage content of the nodes.

Description

区块链数据存储方法及装置、电子设备Blockchain data storage method and device, electronic device 技术领域technical field
本说明书一个或多个实施例涉及区块链技术领域,尤其涉及一种区块链数据存储方法及装置、电子设备。One or more embodiments of this specification relate to the field of blockchain technology, and in particular, to a method and apparatus for storing blockchain data, and electronic equipment.
背景技术Background technique
区块链技术,也被称之为分布式账本技术,是一种由若干台节点设备共同参与“记账”,共同存储和维护一份完整的分布式数据库的新兴技术。Blockchain technology, also known as distributed ledger technology, is an emerging technology in which several node devices jointly participate in "bookkeeping" and jointly store and maintain a complete distributed database.
对于区块链的节点设备来说,需要存储和维护的区块链数据,通常包括区块数据、区块链中的区块链账户对应的账户状态数据;而区块数据又可以进一步包括区块头数据、区块中的区块交易数据、以及与区块中的区块交易数据对应的交易收据,等等。For the node device of the blockchain, the blockchain data that needs to be stored and maintained usually includes the block data and the account status data corresponding to the blockchain account in the blockchain; and the block data can further include the block data. Block header data, block transaction data in the block, and transaction receipts corresponding to the block transaction data in the block, etc.
区块链的节点设备在存储以上示出的各种区块链数据时,通常可以将上述各种区块链数据以key-value键值对的形式,组织成Merkle树在数据库中存储。当需要查询节点设备存储的上述各种区块链数据时,可以通过将上述各种区块链数据的key作为查询索引,遍历上述Merkle树来高效的查询数据。When the node device of the blockchain stores the various blockchain data shown above, the various blockchain data can usually be organized into a Merkle tree in the form of key-value pairs and stored in the database. When it is necessary to query the above-mentioned various blockchain data stored in the node device, the data can be efficiently queried by traversing the above-mentioned Merkle tree by using the key of the above-mentioned various blockchain data as a query index.
发明内容SUMMARY OF THE INVENTION
本说明书提出一种区块链中存储数据的方法,包括:获取待存储的区块链数据的key-value键值对;将所述待存储的区块链数据的key-value键值对转换成逻辑的树形结构上的根节点、中间节点和叶子节点;所述根节点、中间节点包括多个用于存放所述区块链数据的key中的字符的位置,每个位置中包括多个用于存放所述区块链数据的key中的字符的槽位;所述槽位用于存储与该节点链接的下一层节点的hash值;将所述根节点、中间节点和叶子节点的key-value键值对存储在数据库中;所述叶子节点、所述中间节点和所述根节点的key-value键值对中,value为节点的存储内容,key为节点的存储内容的hash值。This specification proposes a method for storing data in a blockchain, including: obtaining a key-value key-value pair of the blockchain data to be stored; converting the key-value key-value pair of the blockchain data to be stored The root node, the intermediate node and the leaf node on the logical tree structure; the root node and the intermediate node include a plurality of positions for storing the characters in the key of the blockchain data, and each position includes multiple positions. a slot for storing the characters in the key of the blockchain data; the slot is used to store the hash value of the next-layer node linked to the node; the root node, the intermediate node and the leaf node are The key-value key-value pair is stored in the database; in the key-value key-value pair of the leaf node, the intermediate node and the root node, the value is the storage content of the node, and the key is the hash of the storage content of the node value.
本说明书还提出一种区块链中存储数据的装置,包括:获取模块,获取待存储的区块链数据的key-value键值对;转换模块,将所述待存储的区块链数据的key-value键值对转换成逻辑的树形结构上的根节点、中间节点和叶子节点;所述根节点、中间节点包括多个用于存放所述区块链数据的key中的字符的位置,每个位置中包括多个用于存放所述区块链数据的key中的字符的槽位;所述槽位用于存储与该节点链接的下一层节点的hash值;存储模块,将所述根节点、中间节点和叶子节点的key-value键值对存储在数据库中;所述叶子节点、所述中间节点和所述根节点的key-value键值对中,value为节点的存储内容,key为节点的存储内容的hash值。This specification also proposes a device for storing data in a blockchain, comprising: an acquisition module, which acquires a key-value pair of blockchain data to be stored; a conversion module, which converts the data of the blockchain data to be stored. The key-value key-value pair is converted into a root node, an intermediate node and a leaf node on a logical tree structure; the root node and the intermediate node include a plurality of positions for storing characters in the key of the blockchain data , each position includes a plurality of slots for storing characters in the key of the blockchain data; the slots are used to store the hash value of the next layer node linked to the node; the storage module, the The key-value key-value pairs of the root node, the intermediate node and the leaf node are stored in the database; in the key-value key-value pairs of the leaf node, the intermediate node and the root node, the value is the storage of the node Content, the key is the hash value of the node's storage content.
以上技术方案中,一方面,由于逻辑的树形结构中的每一个根节点和中间节点,均包括分别代表不同字符的多个位置;并且,各位置又进一步包括多个分别代表不同字符的槽位;因此,通过这种设计,使得每一个根节点和中间节点将具有更大的数据存储容量和数据承载能力,从而在将上述逻辑的树形结构中的根节点和中间节点写入数据库进行存储时;或者,在访问数据库中存储的逻辑的树形结构中的根节点和中间节点时,可以使得根节点和中间节点的数据存储容量,与承载上述数据库的存储介质的单次IO读写的容量更加适配,从而可以充分利用承载上述数据库的存储介质自身的IO读写能力,提升数据读写效率;而且,上述逻辑的树形结构上节点的数据存储容量和数据承载能力的提升,势必也会导致上述逻辑的树形结构整体的数据存储容量和数据承载能力的提升,使得上述逻辑的树形结构上可以存储更多的区块链数据;第二方面,由于逻辑的树形结构中的每一个根节点和中间节点均采用统一的数据结构;对于逻辑的树形结构中的根节点和中间节点来说,其实际存储的区块链数据的key的字符前缀的字符长度也将保持固定;因此,通过这种设计,可以避免由于根节点和中间节点其实际存储的字符长度不固定,而导致的节点的频繁分裂,从而可以确保逻辑的树形结构中所包含的根节点和中间节点的层数,始终处于一个相对稳定的状态;第三方面,由于通过这种设计,每一个根节点和中间节点将具有更大的数据存储容量和数据承载能力;并且,上述逻辑的树形结 构的树形结构中包含的根节点和中间节点的层数,将处于一个相对稳定的状态;因此,根节点和中间节点存储容量的提升和根节点和中间节点的层数相对稳定,在某种程度上可以确保上述逻辑的树形结构的根节点和中间节点将具有更少的层数;从而,在根节点和中间节点具有更大的数据存储容量和数据承载能力,以及上述逻辑的树形结构的根节点和中间节点具有更少的层数的基础之上,系统在进行冷启动,需要从承载上述数据库的存储介质中,将上述逻辑的树形结构的前N层的根节点和中间节点作为需要频繁读取的数据加载到内存中时,则可以显著降低将上述存储介质存储的上述前N层的根节点和中间节点读取到内存中时的IO读取次数,以及将逻辑的树形结构的前N层的根节点和中间节点加载到内存时的整体读取时长,进而从根本上缩短系统冷启动时的启动时延。In the above technical solution, on the one hand, each root node and intermediate node in the logical tree structure include multiple positions representing different characters respectively; and each position further includes multiple slots representing different characters respectively Therefore, through this design, each root node and intermediate node will have a larger data storage capacity and data carrying capacity, so that the root node and intermediate node in the above-mentioned logical tree structure are written into the database. When storing; or, when accessing the root node and intermediate node in the logical tree structure stored in the database, the data storage capacity of the root node and the intermediate node can be compared with the single IO read and write of the storage medium carrying the above database. The capacity of the above-mentioned database is more suitable, so that the IO read and write capabilities of the storage medium carrying the above database can be fully utilized to improve the efficiency of data read and write; moreover, the data storage capacity and data carrying capacity of the nodes on the above-mentioned logical tree structure are improved. It will inevitably lead to the improvement of the overall data storage capacity and data carrying capacity of the above-mentioned logical tree structure, so that more blockchain data can be stored in the above-mentioned logical tree structure; secondly, due to the logical tree structure Each root node and intermediate node in the data structure adopts a unified data structure; for the root node and intermediate node in the logical tree structure, the character length of the character prefix of the key of the actually stored blockchain data will also be It is kept fixed; therefore, through this design, frequent splitting of nodes caused by the fact that the actual length of characters stored in the root node and intermediate nodes is not fixed, so as to ensure that the root node and the root node contained in the logical tree structure are guaranteed. The number of layers of intermediate nodes is always in a relatively stable state; thirdly, due to this design, each root node and intermediate node will have greater data storage capacity and data carrying capacity; and, the above-mentioned logical tree The number of layers of root nodes and intermediate nodes contained in the tree-like structure will be in a relatively stable state; therefore, the improvement of the storage capacity of the root nodes and intermediate nodes and the relative stability of the layers of the root nodes and intermediate nodes, in To some extent, it can be ensured that the root node and intermediate node of the above-mentioned logical tree structure will have fewer layers; thus, the root node and intermediate node have greater data storage capacity and data carrying capacity, and the above logical On the basis that the root node and intermediate nodes of the tree structure have fewer layers, when the system performs a cold start, it is necessary to convert the root nodes of the first N layers of the above logical tree structure from the storage medium carrying the above database. and intermediate nodes are loaded into the memory as data that needs to be read frequently, it can significantly reduce the number of IO reads when the root nodes and intermediate nodes of the first N layers stored in the above storage medium are read into the memory, and the The overall reading time when the root nodes and intermediate nodes of the top N layers of the logical tree structure are loaded into the memory, thereby fundamentally shortening the startup delay when the system is cold started.
附图说明Description of drawings
图1是一示例性实施例提供的一种将区块链的账户状态数据组织成MPT状态树的示意图;FIG. 1 is a schematic diagram of organizing account state data of a blockchain into an MPT state tree provided by an exemplary embodiment;
图2是一示例性实施例提供的一种将合约账户对应的存储空间中存储的合约数据组织成MPT storage树的示意图;2 is a schematic diagram of organizing contract data stored in a storage space corresponding to a contract account into an MPT storage tree provided by an exemplary embodiment;
图3是一示例性实施例提供的一种区块链数据存储方法的流程图;3 is a flowchart of a method for storing blockchain data provided by an exemplary embodiment;
图4是一示例性实施例提供的一种FDMT树的树形结构图;4 is a tree structure diagram of a FDMT tree provided by an exemplary embodiment;
图5是一示例性实施例提供的另一种FDMT树的树形结构图;5 is a tree structure diagram of another FDMT tree provided by an exemplary embodiment;
图6是一示例性实施例提供的一种Tree node的结构图;Fig. 6 is the structure diagram of a kind of Tree node provided by an exemplary embodiment;
图7是一示例性实施例提供的一种bucket数据桶的结构图;7 is a structural diagram of a bucket data bucket provided by an exemplary embodiment;
图8是一示例性实施例提供的一种为FDMT树上的节点设置节点ID的示意图;8 is a schematic diagram of setting a node ID for a node on an FDMT tree provided by an exemplary embodiment;
图9是一示例性实施例提供的一种将账户状态数据写入FDMT树的示意图;9 is a schematic diagram of writing account status data into an FDMT tree provided by an exemplary embodiment;
图10是一示例性实施例提供的一种电子设备的结构示意图;10 is a schematic structural diagram of an electronic device provided by an exemplary embodiment;
图11是一示例性实施例提供的一种区块链数据存储装置的框图。FIG. 11 is a block diagram of a blockchain data storage device provided by an exemplary embodiment.
具体实施方式Detailed ways
区块链一般被划分为三种类型:公有链(Public Blockchain),私有链(Private Blockchain)和联盟链(Consortium Blockchain)。此外,还可以有上述多种类型的结合,比如私有链+联盟链、联盟链+公有链等。其中,去中心化程度最高的是公有链。加入公有链的参与者(也可称为区块链中的节点)可以读取链上的数据记录、参与交易、以及竞争新区块的记账权等。而且,各节点可自由加入或者退出网络,并进行相关操作。Blockchains are generally divided into three types: Public Blockchain, Private Blockchain and Consortium Blockchain. In addition, there can also be a combination of the above-mentioned types, such as private chain + alliance chain, alliance chain + public chain, etc. Among them, the most decentralized is the public chain. Participants who join 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 can freely join or leave the network and perform related operations.
私有链则相反,该网络的写入权限由某个组织或者机构控制,数据读取权限受组织规定。简单来说,私有链可以为一个弱中心化系统,其对节点具有严格限制且节点数量较少。这种类型的区块链更适合于特定机构内部使用。The private chain is on the contrary, 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 within a specific institution.
联盟链则是介于公有链以及私有链之间的区块链,可实现“部分去中心化”。联盟链中各个节点通常有与之相对应的实体机构或者组织;节点通过授权加入网络并组成利益相关联盟,共同维护区块链运行。The consortium chain is a blockchain between the public chain and the private chain, which can achieve "partial decentralization". Each node in the alliance chain usually has a corresponding entity or organization; the node joins the network through authorization and forms a stakeholder alliance to jointly maintain the operation of the blockchain.
基于区块链的基本特性,区块链通常是由若干个区块构成。在这些区块中分别记录有与该区块的创建时刻对应的时间戳,所有的区块严格按照区块中记录的时间戳,构成一条在时间上有序的数据链条。Based on the basic characteristics of the blockchain, the blockchain is usually composed of several blocks. Timestamps corresponding to the creation time of the blocks are respectively recorded in these blocks, and all blocks form a time-ordered data chain strictly according to the timestamps recorded in the blocks.
对于链外产生的数据,可以将其构建成区块链所支持的标准的交易(transaction)格式,然后发布至区块链,由区块链中的节点设备对该交易进行共识,并在达成共识后,由区块链中作为记账节点的节点设备,将这笔交易打包进区块,在区块链中进行持久化存证。For the data generated outside the chain, it can be constructed into a standard transaction format supported by the blockchain, and then published to the blockchain. After the consensus, the node device in the blockchain as the accounting node will package the transaction into the block and store the certificate persistently in the blockchain.
在区块链领域,有一个重要的概念就是账户(Account);在实际应用中,通常可以将账户划分为外部账户和合约账户两类;外部账户就是由用户直接控制的账户,也称之 为用户账户;而合约账户则是由用户通过外部账户创建的,包含合约代码的账户(即智能合约)。In the field of blockchain, an important concept is Account; in practical applications, accounts can usually be divided into external accounts and contract accounts; external accounts are accounts directly controlled by users, also known as User accounts; while contract accounts are created by users through external accounts and contain contract code accounts (ie, smart contracts).
对于区块链中的账户而言,通常会通过一个结构体,来维护账户的账户状态。当区块中的交易被执行后,区块链中与该交易相关的账户的状态通常也会发生变化。For an account in the blockchain, a structure is usually used to maintain the account state of the account. When a transaction in a block is executed, the state of the account associated with that transaction in the blockchain usually changes as well.
在一个例子中,账户的结构体通常包括Balance,Nonce,Code和Storage等字段。其中:Balance字段,用于维护账户目前的账户余额;Nonce字段,用于维护该账户的交易次数;它是用于保障每笔交易能且只能被处理一次的计数器,有效避免重放攻击;Code字段,用于维护该账户的合约代码;在实际应用中,Code字段中通常仅维护合约代码的hash值;因而,Code字段通常也称之为Codehash字段。In one example, the structure of the account usually includes fields such as Balance, Nonce, Code and Storage. Among them: 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 be processed only once, effectively avoiding replay attacks; The Code field is used to maintain the contract code of the account; in practical applications, the Code field usually only maintains the hash value of the contract code; therefore, the Code field is usually also called the Codehash field.
Storage字段,用于维护该账户的存储内容;对于合约账户而言,通常会分配一个独立的持久化的存储空间,用以存储该合约账户对应的存储空间中存储的合约数据;该独立的存储空间通常称之为该合约账户的账户存储。The Storage field is used to maintain the storage content of the account; for the contract account, an independent persistent storage space is usually allocated to store the contract data stored in the storage space corresponding to the contract account; the independent storage The space is usually referred to as the account storage of the contract account.
合约账户的存储内容通常会以key-value键值对的形式被构建成MPT(Merkle Patricia Trie)树的数据结构存储在上述独立的存储空间之中。MPT树是区块链领域用于存储和维护区块链数据的一种逻辑的树形结构,在这种树形结构中通常包括根节点、中间节点、叶子节点。The storage content of the contract account is usually stored in the above-mentioned independent storage space in the form of a key-value key-value pair constructed as an MPT (Merkle Patricia Trie) tree data structure. MPT tree is a logical tree structure used to store and maintain blockchain data in the blockchain field. This tree structure usually includes root nodes, intermediate nodes, and leaf nodes.
其中,基于合约账户的存储内容构建成的MPT树,通常也称之为Storage树。而Storage字段通常仅维护该Storage树的根节点的hash值;因此,Storage字段通常也称之为Storage Root hash字段。其中,对于外部账户而言,以上示出的Code字段和Storage字段的字段值均为空值。Among them, the MPT tree constructed based on the storage content of the contract account is also commonly referred to as 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树的数据结构的Merkle树变种等逻辑的树形结构,来存储和维护数据。例如,MPT树,就是一种用来存储和维护区块链数据的,融合了Trie字典树的树形结构的Merkle树变种。For most blockchain models, a Merkle tree is usually used; or a logical tree structure such as a Merkle tree variant based on the data structure of the Merkle tree is used to store and maintain data. For example, the MPT tree is a Merkle tree variant that combines the tree structure of the Trie dictionary tree for storing and maintaining blockchain data.
以下以使用MPT树,来存储区块链数据为例进行说明;在一个例子中,区块链中需要存储和维护的区块链数据,通常包括账户状态(state)数据、交易数据和收据数据;因此,在实际应用中,可以分别将上述账户状态数据、交易数据和收据数据以key-value键值对的形式,组织成MPT状态树(即world state)、MPT交易树和MPT收据树等三棵MPT树,分别进行存储和维护。The following uses the MPT tree to store blockchain data as an example to illustrate; in an example, the blockchain data that needs to be stored and maintained in the blockchain usually includes account state data, transaction data and receipt data ; Therefore, in practical applications, the above account status data, transaction data and receipt data can be organized into MPT state tree (ie world state), MPT transaction tree and MPT receipt tree in the form of key-value pairs. Three MPT trees are stored and maintained separately.
其中,除了以上三棵MPT树以外,合约账户对应的存储空间中存储的合约数据,通常也会被构建成为一棵MTP Storage树(以下简称为Storage树)。该Storage树的根节点的hash值,会被添加到与该Storage树对应的合约账户的上述结构体中的Storage字段。Among them, in addition to the above three MPT trees, the contract data stored in the storage space corresponding to the contract account is usually constructed as an MTP Storage tree (hereinafter referred to as the Storage tree). The hash value of the root node of the Storage tree will be added to the Storage field in the above structure of the contract account corresponding to the Storage tree.
MPT状态树,是由区块链中所有账户(包括外部账户和合约账户)的账户状态(state)数据,以key-value键值对的形式组织成的MPT树;MPT交易树,是由区块链中的交易(transaction)数据,以key-value键值对的形式组织成的MPT树;MPT收据树,是区块中的交易在执行完毕后生成的与每笔交易对应的交易(receipt)收据,以key-value键值对的形式组织成的MPT树。The MPT state tree is an MPT tree organized by the account state data of all accounts (including external accounts and contract accounts) in the blockchain in the form of key-value pairs; the MPT transaction tree is composed of The transaction data in the block chain is an MPT tree organized in the form of key-value key-value pairs; the MPT receipt tree is the transaction corresponding to each transaction generated after the transaction in the block is executed. ) receipt, an MPT tree organized in the form of key-value pairs.
以上示出的MPT状态树、MPT交易树和MPT收据树的根节点的hash值,最终都会被添加至对应区块的区块头中。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, both the MPT transaction tree and the 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. Each time the blockchain generates a newest block, after the transactions in the latest block are executed, the account status of the relevant accounts (which can be external accounts or contract accounts) of the executed transactions in the blockchain, usually will change accordingly.
例如,当区块中的一笔“转账交易”执行完毕后,与该“转账交易”相关的转出方账户和转入方账户的余额(即这些账户的Balance字段的字段值),通常也会随之发生变化。节点设备在区块链产生的最新区块中的交易执行完毕后,由于当前区块链中的账户状态发生了变化,因此节点设备需要根据区块链中所有账户当前的账户状态数据,来构建MPT状态树,用于维护区块链中所有账户的最新状态。For example, when a "transfer transaction" in the block is executed, the balances of the sender's account and the transferer's account related to the "transfer transaction" (that is, the field value of the Balance field of these accounts) are usually also will change accordingly. After the node device executes the transaction in the latest block generated by the blockchain, since the account status in the current blockchain has changed, the node device needs to construct the current account status data based on the current account status data of all accounts in the blockchain. The MPT state tree is used to maintain the latest state of all accounts in the blockchain.
也即,每当区块链中产生一个最新区块,并且该最新区块中的交易执行完毕后,导致区块链中的部分账户的账户状态发生了变化,节点设备需要基于区块链中所有账户最新的账户状态数据,重新构建一棵MPT状态树。换句话说,区块链中每一个区块,都有一个与之对应的MPT状态树;该MPT状态树,维护了在该区块中的交易在执行完毕后,区块链中所有账户最新的账户状态。That is, whenever a newest block is generated in the blockchain and the transaction in the latest block is executed, the account status of some accounts in the blockchain changes, and the node device needs to be based on the The latest account status data of all accounts, and rebuild an MPT status tree. In other words, each block in the blockchain has a corresponding MPT state tree; the MPT state tree maintains that after the transaction in the block is executed, all accounts in the blockchain are up-to-date. account status.
请参见图1,图1为本说明书示出的一种将区块链中的各个区块链账户的账户状态数据以key-value键值对的形式组织成MPT状态树的示意图。Please refer to FIG. 1. FIG. 1 is a schematic diagram of organizing the account status data of each blockchain account in the blockchain into an MPT state tree in the form of key-value pairs.
MPT树,是一种较为传统的经过改良的Merkle树变种,其融合了Merkle树和Trie字典树(也称之为前缀树)两种树形结构的优点。MPT tree is a more traditional and improved variant of Merkle tree, which combines the advantages of two tree structures of Merkle tree and Trie dictionary tree (also called prefix tree).
在MPT树中通常包括三种节点,分别为叶子节点(leaf node),扩展节点(extension node)和分支节点(branch node)。其中,MPT树的根节点通常可以是扩展节点;MPT树的中间节点通常可以是分支节点或者其它的扩展节点。There are usually three kinds of nodes in the MPT tree, namely leaf node, extension node and branch node. Wherein, the root node of the MPT tree can usually be an extension node; the middle node of the MPT tree can usually be a branch node or other extension nodes.
其中,扩展节点和分支节点可以统称为字符节点,用于存储账户状态数据的key(即账户地址)对应的字符串的字符前缀部分;其中,对于MPT树而言,上述字符前缀部分通常是指共享字符前缀;所述共享字符前缀,是指所有账户状态数据的key(即区块链账户地址)所具有的相同的一个或者多个字符组成的前缀。而上述叶子节点,用于存储区块链数据的key对应的字符串的字符后缀部分和Value(即具体的账户状态数据)。The extension nodes and branch nodes may be collectively referred to as character nodes, which are used to store the character prefix part of the character string corresponding to the key (ie the account address) of the account status data; wherein, for the MPT tree, the above character prefix part usually refers to Shared character prefix; the shared character prefix refers to a prefix composed of the same one or more characters that the keys of all account status data (ie, blockchain account addresses) have. The above leaf nodes are used to store the character suffix part of the character string corresponding to the key of the blockchain data and the Value (that is, the specific account status data).
扩展节点,用于存储账户地址的共享字符前缀中一个或者多个字符(即图1示出的shared nibble),和该扩展节点链接的下一层的节点的hash值(即图1示出的Next node)。分支节点,包含17个槽位,前16个槽位对应着key中的16个可能的十六进制字符,一个字符对应一个nibble(半字节),前16个槽位中的每一个槽位,分别表示一个账户地址的共享字符前缀中的一个字符,这些槽位用于填充该分支节点链接的下一层的节点的hash值。最后一个槽位为value槽位,一般为空值。The extension node is used to store one or more characters in the shared character prefix of the account address (that is, the shared nibble shown in Figure 1), and the hash value of the node in the next layer linked to the extension node (that is, the one shown in Figure 1). Next node). Branch node, containing 17 slots, the first 16 slots correspond to the 16 possible hexadecimal characters in the key, one character corresponds to a nibble (nibble), each of the first 16 slots Bits, which respectively represent a character in the shared character prefix of an account address, and these slots are used to fill the hash value of the node of the next layer linked by the branch node. The last slot is the value slot, which is usually an empty value.
叶子节点,用于存储账户地址的字符后缀(即图1示出的key-end),和账户状态数据的value(即以上描述的账户的结构体);其中,账户地址的字符后缀和账户地址的共享字符前缀共同组成了一个完整的账户地址;所述字符后缀,是指除了账户地址的共享字符前缀以外的最后一个或者多个字符组成的后缀。The leaf node is used to store the character suffix of the account address (that is, the key-end shown in FIG. 1 ), and the value of the account status data (that is, the structure of the account described above); wherein, the character suffix of the account address and the account address are The shared character prefix of , together forms a complete account address; the character suffix refers to the suffix composed of the last one or more characters except the shared character prefix of the account address.
假设需要组织成MTP状态树的账户状态数据如下表1所示:Assume that the account state data that needs to be organized into an MTP state tree is shown in Table 1 below:
Figure PCTCN2022090294-appb-000001
Figure PCTCN2022090294-appb-000001
表1Table 1
其中,在表1中,前三行的账户地址对应的区块链账户为外部账户,Codehash和Storage root字段为空值。第4行的账户地址对应的区块链账户为合约账户,Codehash字段维护了该合约账户对应的合约代码的hash值;Storage root字段维护了该合约账户的存储内容构成的Storage树的根节点的hash值。最终按照表1中的账户状态数据组织成的MPT状态树,如图1所示;该MPT状态树是由4个叶子节点,2个分支节点,和2个扩展节点(其中一个扩展节点作为根节点)构成。Among them, in Table 1, the blockchain account corresponding to the account address in the first three lines is an external account, and the fields of Codehash and Storage root are empty. The blockchain account corresponding to the account address in line 4 is the contract account. The Codehash field maintains the hash value of the contract code corresponding to the contract account; the Storage root field maintains the root node of the Storage tree composed of the storage content of the contract account. hash value. Finally, the MPT state tree is organized according to the account state data in Table 1, as shown in Figure 1; the MPT state tree consists of 4 leaf nodes, 2 branch nodes, and 2 extension nodes (one of which is the extension node as the root). node) composition.
在图1中,prefix字段为扩展节点和叶子节点共同具有的前缀字段。该prefix字段的不同字段值可以用于表示不同的节点类型。例如,prefix字段的取值为0,表示包含偶数个nibbles的扩展节点;如前所述,nibble表示半字节,由4位二进制组成,一个nibble可以对应一个组成账户地址的字符。prefix字段的取值为1,表示包含奇数个nibble(s)的扩展节点;prefix字段的取值为2,表示包含偶数个nibbles的叶子节点;prefix字段的取值为3,表示包含奇数个nibble(s)的叶子节点。In FIG. 1 , the prefix field is a prefix field shared by the extension node and the leaf node. Different field values of the prefix field can be used to represent different node types. For example, the value of the prefix field is 0, indicating an extension node containing an even number of nibbles; as mentioned above, a nibble represents a nibble, which is composed of 4-bit binary, and a nibble can correspond to a character that constitutes an account address. The value of the prefix field is 1, which means that the extension node contains an odd number of nibble(s); the value of the prefix field is 2, which means that the leaf node contains an even number of nibbles; the value of the prefix field is 3, which means that it contains an odd number of nibbles. (s) leaf nodes.
而分支节点,由于其是并列单nibble的字符节点,因此分支节点不具有上述prefix字段。The branch node, because it is a parallel single nibble character node, does not have the above prefix field.
扩展节点中的Shared nibble字段,对应该扩展节点所包含的键值对的key值,表示账户地址之间的共同字符前缀;比如,上表中的所有账户地址均具有共同的字符前缀a7。Next Node字段中填充下一个节点的hash值(hash指针)。The Shared nibble field in the extension node corresponds to the key value of the key-value pair contained in the extension node, indicating the common character prefix between account addresses; for example, all account addresses in the above table have a common character prefix a7. The Next Node field is filled with the hash value (hash pointer) of the next node.
分支节点中的16进制字符0~f字段,对应该分支节点所包含的键值对的key值;如果该分支节点为账户地址在MPT树上的搜索路径上的中间节点,则该分支节点的Value字段可以为空值。0~f字段中用于填充下一层节点的hash值。The hexadecimal character 0~f field in the branch node corresponds to the key value of the key-value pair contained in the branch node; if the branch node is an intermediate node on the search path of the account address in the MPT tree, the branch node The Value field can be null. The hash value used to fill the next layer of nodes in the 0~f field.
叶子节点中的Key-end,对应该叶子节点所包含的键值对的key值,表示账户地址的最后几个字符(账户地址的字符后缀)。从根节点搜索到叶子节点的搜索路径上的各个节点的key值,构成了一个完整的账户地址。该叶子节点的Value字段填充账户地址对应的账户状态数据;例如,可以对上述Balance,Nonce,Code和storage等字段构成的结构体进行编码后,填充至叶子节点的Value字段。The Key-end in the leaf node corresponds to the key value of the key-value pair contained in the leaf node, and represents the last few characters of the account address (the character suffix of the account address). The key value of each node on the search path from the root node to the leaf node constitutes a complete account address. The Value field of the leaf node is filled with the account status data corresponding to the account address; for example, the structure composed of the fields such as Balance, Nonce, Code, and storage can be encoded, and then filled into the Value field of the leaf node.
进一步的,如图1所示的MPT状态树上的node,最终也是以Key-Value键值对的形式存储在数据库中;其中,当MPT状态树上的node在数据库中进行存储时,MPT状态树上的node的键值对中的key,可以为node所包含的数据内容的hash值;MPT状态树上的node的键值对中的Value,为node所包含的数据内容。Further, the nodes on the MPT state tree shown in Figure 1 are ultimately stored in the database in the form of Key-Value key-value pairs; among them, when the nodes on the MPT state tree are stored in the database, the MPT state The key in the key-value pair of the node on the tree can be the hash value of the data content contained in the node; the value in the key-value pair of the node on the MPT state tree is the data content contained in the node.
在将MPT状态树上的node存储至数据库时,可以计算该node所包含的数据内容的hash值(即对node整体进行hash计算),并将计算出的hash值作为key,将该node所包含的数据内容作为value,生成Key-Value键值对;然后,将生成的Key-Value键值对存储至数据库中。When the node on the MPT state tree is stored in the database, the hash value of the data content contained in the node can be calculated (that is, the hash calculation is performed on the entire node), and the calculated hash value can be used as the key. The content of the data is used as value, and a Key-Value key-value pair is generated; then, the generated Key-Value key-value pair is stored in the database.
由于MPT状态树上的node,以Key-value键值对的形式进行存储;其中,Key可以是node所包含的数据内容的hash值,Value可以是node所包含的数据内容;因此,在需要查询MPT状态树上的node时,通常可以基于node所包含的数据内容的hash值作为key来进行内容寻址。Because the nodes on the MPT state tree are stored in the form of key-value pairs; among them, the key can be the hash value of the data content contained in the node, and the value can be the data content contained in the node; therefore, when you need to query When a node on the MPT state tree is used, content addressing can usually be performed based on the hash value of the data content contained in the node as a key.
请参见图2,图2为本说明书示出的一种将合约账户对应的存储空间中存储的合约数据组织成MPT storage树的示意图。Please refer to FIG. 2, which is a schematic diagram of organizing the contract data stored in the storage space corresponding to the contract account into an MPT storage tree shown in this specification.
请继续参见表1,表1中示出的账户地址为“a77d397”的账户为合约账户,因此该合约账户对应的存储空间中存储的合约数据会被组织成一颗storage树;其中,该storage树的根节点的hash值S1,会被添加到图1示出的MTP状态树中与该合约账户对应的叶子节点中的storage root字段里。Please continue to refer to Table 1. The account whose account address is "a77d397" shown in Table 1 is a contract account, so the contract data stored in the storage space corresponding to the contract account will be organized into a storage tree; among them, the storage tree The hash value S1 of the root node will be added to the storage root field in the leaf node corresponding to the contract account in the MTP state tree shown in Figure 1.
假设该合约账户的存储空间中存储的合约数据如下表2所示:Assume that the contract data stored in the storage space of the contract account is shown in Table 2 below:
Figure PCTCN2022090294-appb-000002
Figure PCTCN2022090294-appb-000002
表2Table 2
合约账户的存储空间中存储的合约数据,通常可为状态变量的形式;在进行存储时,可将状态变量名以key-value键值对的形式组织成如图2所示的storage树进行存储。The contract data stored in the storage space of the contract account can usually be in the form of state variables; when storing, the state variable names can be organized into a storage tree as shown in Figure 2 in the form of key-value pairs for storage .
例如,在一个例子中,可以将合约账户的账户地址和状态变量在合约账户的账户存储中的存储位置的hash值作为key,将状态变量对应的变量取值作为value。For example, in one example, the account address of the contract account and the hash value of the storage location of the state variable in the account storage of the contract account can be used as the key, and the variable value corresponding to the state variable can be used as the value.
其中,图2示出的storage树的基本结构与图1示出的MTP状态树相似,在本说明书中不再赘述。通过上述图1和图2的描述可知,基于MPT树的树形结构设计,分支节点可以存储所有账户地址的共享字符前缀中的其中一个字符;而扩展节点则可以存储 所有账户地址的共享字符前缀中的一个或者多个字符。The basic structure of the storage tree shown in FIG. 2 is similar to the MTP state tree shown in FIG. 1 , and will not be repeated in this specification. As can be seen from the descriptions of Figures 1 and 2 above, based on the tree structure design of the MPT tree, the branch node can store one of the characters in the shared character prefixes of all account addresses; and the extension node can store the shared character prefixes of all account addresses. one or more characters in .
在实际应用中,MPT树上存储的所有数据的key的共享字符前缀的字符长度,通常并不固定;而且,当MPT树上写入了新增的数据之后,可能导致上述共享字符前缀的字符长度,也会随之发生变化;因此,这就可能会导致MPT树上的扩展节点发生分裂,分裂出新的分支节点;也即,MPT树上的节点的分裂条件是,上述共享字符前缀的字符长度发生变化;例如,以图1示出的MPT状态树为例,假设上述MPT状态树上新增了一个账户地址的前两位字符为“a8”的账户地址的账户状态数据,那么图1中示出的作为根节点的扩展节点的“Shared nible”字段存储的共享字符前缀,就会由“a7”,改变为“a”;按照MPT状态树的节点的分裂条件,这个作为根节点的扩展节点,会分裂成一个存储的共享字符前缀为“a”的扩展节点;和一个字符“8”被占用的分支节点。In practical applications, the character length of the shared character prefix of the keys of all data stored in the MPT tree is usually not fixed; moreover, when the newly added data is written to the MPT tree, the characters of the above shared character prefix may be caused The length will also change accordingly; therefore, this may cause the expansion node on the MPT tree to split and split into new branch nodes; that is, the split condition of the nodes on the MPT tree is that the above-mentioned shared character prefix The character length changes; for example, taking the MPT state tree shown in Figure 1 as an example, assuming that the above-mentioned MPT state tree adds an account state data of an account address whose first two characters of the account address are "a8", then the figure The shared character prefix stored in the "Shared nible" field of the extended node as the root node shown in 1 will be changed from "a7" to "a"; according to the splitting conditions of the nodes of the MPT state tree, this is used as the root node. The extension node of , will be split into an extension node with a stored shared character prefixed with "a"; and a branch node with the character "8" occupied.
一旦MPT树上的扩展节点发生分裂,可能会导致MPT树的节点层数也会发生变化,造成MPT树的节点层数不够稳定。由于上述MPT树上存储的所有数据的key的共享字符前缀的字符长度,会随着上述MPT树写入了新的数据,而频繁的发生变化;因此,按照以上示出的节点分裂方式,会造成节点的频繁分裂,进而会影响向MPT树写入新的数据时的数据存储效率。Once an extended node on the MPT tree is split, the number of node layers in the MPT tree may also change, resulting in an unstable number of nodes in the MPT tree. Because the character length of the shared character prefix of the keys of all the data stored in the above-mentioned MPT tree will frequently change as new data is written into the above-mentioned MPT tree; therefore, according to the node splitting method shown above, there will be This causes frequent splitting of nodes, which in turn affects the data storage efficiency when writing new data to the MPT tree.
有鉴于此,本说明书提出一种新的逻辑的树形结构设计方案。In view of this, this specification proposes a new logical tree structure design solution.
在实现时,上述逻辑的树形结构仍然可以包括根节点、中间节点和叶子节点;其中,上述根节点、中间节点用于存储区块链数据的key中的字符;上述叶子节点用于存储区块链数据的value。During implementation, the above-mentioned logical tree structure may still include a root node, an intermediate node and a leaf node; wherein, the above-mentioned root node and intermediate node are used to store characters in the key of the blockchain data; the above-mentioned leaf node is used for the storage area The value of the blockchain data.
与上述MPT树不同的是,上述根节点、中间节点可以包括多个用于存放区块链数据的key中的字符的位置,每个位置中可以进一步包括多个用于存放区块链数据的key中的字符的槽位;而上述槽位则可以用于存储与该节点链接的下一层节点的hash值。Different from the above-mentioned MPT tree, the above-mentioned root node and intermediate node may include multiple locations for storing characters in the key of blockchain data, and each location may further include multiple locations for storing blockchain data. The slot of the character in the key; the above slot can be used to store the hash value of the next layer node linked to the node.
区块链中的节点设备在存储区块链数据时,可以获取待存储的区块链数据的key-value键值对,再将该待存储的区块链数据转换成上述逻辑的树形结构上的根节点、中间节点和叶子节点;然后,将上述根节点、中间节点和叶子节点的key-value键值对再进一步存储在数据库中;上述叶子节点、所述中间节点和所述根节点的key-value键值对中,value可以为节点的存储内容,key可以为节点的存储内容的hash值。When storing the blockchain data, the node device in the blockchain can obtain the key-value key-value pair of the blockchain data to be stored, and then convert the blockchain data to be stored into the above-mentioned logical tree structure The root node, the intermediate node and the leaf node on the node; then, the key-value key-value pairs of the above-mentioned root node, the intermediate node and the leaf node are further stored in the database; the above-mentioned leaf node, the intermediate node and the root node are further stored in the database; In the key-value key-value pair, the value can be the storage content of the node, and the key can be the hash value of the storage content of the node.
在以上技术方案中,一方面,由于逻辑的树形结构中的每一个根节点和中间节点,均包括分别代表不同字符的多个位置;并且,各位置又进一步包括多个分别代表不同字符的槽位;因此,通过这种设计,使得每一个根节点和中间节点将具有更大的数据存储容量和数据承载能力,从而在将上述逻辑的树形结构中的根节点和中间节点写入数据库进行存储时;或者,在访问数据库中存储的逻辑的树形结构中的根节点和中间节点时,可以使得根节点和中间节点的数据存储容量,与承载上述数据库的存储介质的单次IO读写的容量更加适配,从而可以充分利用承载上述数据库的存储介质自身的IO读写能力,提升数据读写效率;而且,上述逻辑的树形结构上节点的数据存储容量和数据承载能力的提升,势必也会导致上述逻辑的树形结构整体的数据存储容量和数据承载能力的提升,使得上述逻辑的树形结构上可以存储更多的区块链数据;第二方面,由于逻辑的树形结构中的每一个根节点和中间节点均采用统一的数据结构;对于逻辑的树形结构中的根节点和中间节点来说,其实际存储的区块链数据的key的字符前缀的字符长度也将保持固定;因此,通过这种设计,可以避免由于根节点和中间节点其实际存储的字符长度不固定,而导致的节点的频繁分裂,从而可以确保逻辑的树形结构中所包含的根节点和中间节点的层数,始终处于一个相对稳定的状态;第三方面,由于通过这种设计,每一个根节点和中间节点将具有更大的数据存储容量和数据承载能力;并且,上述逻辑的树形结构的树形结构中包含的根节点和中间节点的层数,将处于一个相对稳定的状态;因此,根节点和中间节点存储容量的提升和根节点和中间节点的层数相对稳定,在某种程度上可以确保上述逻辑的树形结构的根节点和中间节点将具有更少的层数;从而,在根节点和中间节点具有更大的数据存储容量和数据承载能力,以及上述逻辑的树形结构的根节点和中间节点具有更少的层数的基础之上,系统在进行冷启动,需要从承载上述数据库的存储介质中,将上述逻辑的树形结构的前N层的根节点和中间节点作为需要频繁读取的数据加载到内存中时,则可以显著降低将上述存储介质存储的上述前N层的根节点和中间节点读取到内存中时的IO读取次数,以及将逻辑的树形结构的前N层的根 节点和中间节点加载到内存时的整体读取时长,进而从根本上缩短系统冷启动时的启动时延。In the above technical solution, on the one hand, each root node and intermediate node in the logical tree structure include multiple positions representing different characters respectively; and each position further includes multiple positions representing different characters respectively. slot; therefore, through this design, each root node and intermediate node will have a larger data storage capacity and data carrying capacity, so that the root node and intermediate node in the above-mentioned logical tree structure will be written into the database. When storing; or, when accessing the root node and the intermediate node in the logical tree structure stored in the database, the data storage capacity of the root node and the intermediate node can be compared with the single IO read of the storage medium carrying the above-mentioned database. The write capacity is more suitable, so that the IO read and write capabilities of the storage medium carrying the above database can be fully utilized to improve the data read and write efficiency; moreover, the data storage capacity and data carrying capacity of the nodes in the above-mentioned logical tree structure are improved. , it will inevitably lead to the improvement of the overall data storage capacity and data carrying capacity of the above-mentioned logical tree structure, so that more blockchain data can be stored in the above-mentioned logical tree structure; secondly, due to the logical tree structure Each root node and intermediate node in the structure adopts a unified data structure; for the root node and intermediate node in the logical tree structure, the character length of the character prefix of the key of the actually stored blockchain data is also will remain fixed; therefore, through this design, frequent splitting of nodes can be avoided due to the fact that the actual length of characters stored in the root node and intermediate nodes is not fixed, so that the root node contained in the logical tree structure can be guaranteed. and the number of layers of intermediate nodes are always in a relatively stable state; thirdly, due to this design, each root node and intermediate nodes will have larger data storage capacity and data carrying capacity; and, the above logic The number of layers of the root node and intermediate node contained in the tree structure of the tree structure will be in a relatively stable state; therefore, the storage capacity of the root node and the intermediate node is improved and the number of layers of the root node and the intermediate node is relatively stable, To a certain extent, it can be ensured that the root node and intermediate nodes of the above-mentioned logical tree structure will have fewer layers; thus, the root node and intermediate nodes have greater data storage capacity and data carrying capacity, and the above logic On the basis that the root node and intermediate nodes of the tree structure have fewer layers, when the system performs a cold start, it is necessary to transfer the roots of the first N layers of the above logical tree structure from the storage medium carrying the above database. When the nodes and intermediate nodes are loaded into the memory as data that needs to be read frequently, the number of IO reads when the root nodes and intermediate nodes of the top N layers stored in the above storage medium are read into the memory can be significantly reduced, and The overall read time when the root nodes and intermediate nodes of the first N layers of the logical tree structure are loaded into the memory, thereby fundamentally shortening the startup delay when the system is cold-started.
请参见图3,图3是一示例性实施例提供的一种区块链数据存储方法的流程图。所述方法应用于区块链节点设备;所述方法包括以下步骤:步骤302,获取待存储的区块链数据的key-value键值对;步骤304,将所述待存储的区块链数据的key-value键值对转换成逻辑的树形结构上的根节点、中间节点和叶子节点;所述根节点、中间节点包括多个用于存放所述区块链数据的key中的字符的位置,每个位置中包括多个用于存放所述区块链数据的key中的字符的槽位;所述槽位用于存储与该节点链接的下一层节点的hash值;步骤306,将所述根节点、中间节点和叶子节点的key-value键值对存储在数据库中;所述叶子节点、所述中间节点和所述根节点的key-value键值对中,value为节点的存储内容,key为节点的存储内容的hash值。Please refer to FIG. 3 , which is a flowchart of a method for storing blockchain data provided by an exemplary embodiment. The method is applied to a block chain node device; the method includes the following steps: step 302, obtaining a key-value key-value pair of the block chain data to be stored; step 304, storing the block chain data to be stored The key-value key-value pair is converted into a root node, an intermediate node and a leaf node on a logical tree structure; the root node and the intermediate node include a plurality of characters used to store the characters in the key of the blockchain data. location, each location includes a plurality of slots for storing characters in the key of the blockchain data; the slots are used to store the hash value of the next-layer node linked to the node; Step 306, The key-value key-value pairs of the root node, the intermediate node and the leaf node are stored in the database; in the key-value key-value pairs of the leaf node, the intermediate node and the root node, the value is the value of the node. Storage content, the key is the hash value of the storage content of the node.
在本说明书中,为了避免节点频繁发生分裂,提出一种前N层的用于存储区块链数据的key中的字符节点的层数固定的逻辑的树状结构。In this specification, in order to avoid frequent splitting of nodes, a logical tree structure with a fixed number of layers of character nodes in the key for storing blockchain data in the first N layers is proposed.
其中,所谓逻辑的树形结构,是指在数据库的底层物理存储中,并不存在与树形结构完全对应的物理存储结构,而仅在数据库中存储上述树形结构上的各个节点的物理数据以及各个节点之间的链接关系数据,从而可以基于数据库中存储的各个节点的物理数据和链接关系数据,在逻辑层面上还原出上述树形结构。Among them, the so-called logical tree structure means that in the underlying physical storage of the database, there is no physical storage structure completely corresponding to the tree structure, but only the physical data of each node on the above tree structure is stored in the database. and link relationship data between each node, so that the above tree structure can be restored on a logical level based on the physical data and link relationship data of each node stored in the database.
上述逻辑的树状结构,具体可以包括根节点、中间节点和叶子节点;其中,上述逻辑的树状结构上的节点,可以通过其自身的hash值与上一层的节点进行链接。上述根节点和中间节点,具体用于存储区块链数据的key-value键值对中的key中的至少一个字符;上述叶子节点具体用于存储区块链数据的value(即区块链数据的具体内容)。中间节点的层数可以为一层也可以为多层,在本说明书中不进行特别限定。The above-mentioned logical tree-like structure may specifically include a root node, an intermediate node and a leaf node; wherein, the nodes on the above-mentioned logical tree-like structure may be linked with the nodes of the upper layer through their own hash values. The above-mentioned root node and intermediate node are specifically used to store at least one character in the key in the key-value key-value pair of the blockchain data; the above-mentioned leaf nodes are specifically used to store the value of the blockchain data (that is, the blockchain data specific content). The number of layers of the intermediate nodes may be one or more layers, and is not particularly limited in this specification.
例如,在一个例子中,上述区块链数据的key,仍然可以包括字符前缀部分(Shared nibble)和字符后缀部分(key-end);在这种情况下,根节点和中间节点可以用于存储上述字符前缀中的字符;而上述叶子节点则可以用于存储上述字符后缀和区块链数据的value。For example, in an example, the key of the above blockchain data can still include a character prefix part (Shared nibble) and a character suffix part (key-end); in this case, the root node and intermediate nodes can be used for storage The characters in the above character prefixes; and the above leaf nodes can be used to store the above character suffixes and the value of blockchain data.
一方面,由于上述逻辑的树形结构中的根节点和中间节点,可以存放区块链数据的key中的字符;因此,上述逻辑的树形结构具有Trie字典树的特点;另一方面,上述逻辑的树状结构上的节点,可以通过其自身的hash值与上一层的节点进行链接;因此,上述逻辑的树形结构也具有Merkle树的特点。综上,本说明书描述的逻辑的树形结构,实际上是一种类似于MPT树的融合了Trie字典树的树形结构的Merkle树变种。On the one hand, since the root node and intermediate nodes in the above-mentioned logical tree structure can store the characters in the key of the blockchain data; therefore, the above-mentioned logical tree structure has the characteristics of Trie dictionary tree; on the other hand, the above-mentioned The nodes on the logical tree structure can be linked with the nodes of the upper layer through their own hash values; therefore, the above logical tree structure also has the characteristics of Merkle tree. To sum up, the logical tree structure described in this specification is actually a Merkle tree variant similar to the MPT tree that incorporates the tree structure of the Trie dictionary tree.
请参见图4,图4为本说明书示出的一种FDMT(Fixed Depth Merkle Tree)树的树形结构图。上述FDMT树是一种融合了Trie字典树的树形结构的Merkle树变种。Please refer to Fig. 4, Fig. 4 is a tree structure diagram of a FDMT (Fixed Depth Merkle Tree) tree shown in this specification. The above FDMT tree is a Merkle tree variant incorporating the tree structure of the Trie dictionary tree.
如图4所示,在本说明书示出的FDMT树的树形结构中,包含前N层(图4示出的为3层,仅为示意性的)的Tree node,和最后一层的Leaf node(即叶子节点)。其中,在前N层的Tree node中,第一层为作为根节点的Tree node,其它层为作为中间节点的Tree node。As shown in FIG. 4 , in the tree structure of the FDMT tree shown in this specification, it includes the Tree nodes of the first N layers (the three layers shown in FIG. 4 are only illustrative), and the Leaf of the last layer. node (ie leaf node). Among them, in the Tree node of the first N layers, the first layer is the Tree node as the root node, and the other layers are the Tree node as the intermediate node.
其中,与以上描述的MPT树不同的是,上述FDMT树前N层的各个Tree node(即根节点和中间节点),将采用统一的数据结构,从而使得上述FDMT树前N层的各个Tree node,可以不再因为新写入了数据导致存储的字符的长度发生变化而发生节点分裂。Wherein, unlike the MPT tree described above, each Tree node (that is, the root node and the intermediate node) in the first N layers of the above-mentioned FDMT tree will adopt a unified data structure, so that each Tree node in the first N layers of the above-mentioned FDMT tree will be , node splitting can no longer occur because the length of stored characters changes due to newly written data.
如图4所示,上述FDMT树上的前N层的Tree node,均可以包括分别代表不同字符的多个block;上述block为用于存放区块链数据的key中的字符的“位置”。而每一个block可以进一步包括多个分别代表不同字符的槽位;上述槽位也用于存放区块链数据的key中的字符。As shown in Figure 4, the tree nodes of the first N layers on the above-mentioned FDMT tree may include multiple blocks representing different characters respectively; the above-mentioned blocks are the "positions" of the characters in the key used to store the blockchain data. And each block may further include a plurality of slots representing different characters; the above slots are also used to store the characters in the key of the blockchain data.
例如,图4示出的为每一个Tree node包括N个block;每个block进一步包括N个slot。其中,上述FDMT树上各层的节点之间,仍然可以采用在上一层的节点中填充下一层的节点的hash值(hash指针)的方式,来进行节点间的链接。也即,上述FDMT树中的节点,通过其自身的hash值,链接至上一层的节点。相应的,上述槽位具体可以用于填充当前的Tree node所链接的下一层节点的hash值。Tree node的下一层节点,具体仍然可以是Tree node,也可以是Leaf node。For example, Figure 4 shows that each Tree node includes N blocks; each block further includes N slots. Wherein, among the nodes of each layer on the above-mentioned FDMT tree, the method of filling the hash value (hash pointer) of the node of the next layer in the node of the upper layer can still be used to carry out the link between the nodes. That is, the nodes in the above-mentioned FDMT tree are linked to the nodes of the upper layer through their own hash values. Correspondingly, the above slot can be specifically used to fill the hash value of the next layer node linked by the current Tree node. The next-level node of the Tree node can still be a Tree node or a Leaf node.
其中,在实际应用中,当上述FDMT树上的Tree node中的任一block中的任一槽位填充的hash值发生更新后,通常需要重新计算该Tree node的hash值,并根据计算出的该hash值与上一层的节点重新进行链接。Among them, in practical applications, when the hash value filled in any slot in any block in the tree node on the above FDMT tree is updated, it is usually necessary to recalculate the hash value of the tree node, and according to the calculated hash value The hash value is re-linked with the node in the previous layer.
而在计算该Tree node的hash值时,通常需要将Tree node中填充的所有数据都作为计算参数进行hash计算;因此,在Tree node采用了如图4所示的数据结构的情况下,如果需要计算该Tree node的hash值,则需要先计算出该Tree node包含的各个block的hash,再将各block的hash拼接起来,再针对拼接起来的hash执行二次的hash计算。When calculating the hash value of the tree node, it is usually necessary to use all the data filled in the tree node as calculation parameters for hash calculation; therefore, when the tree node adopts the data structure shown in Figure 4, if necessary To calculate the hash value of the tree node, you need to first calculate the hash of each block contained in the tree node, then splicing the hash of each block, and then perform a second hash calculation for the spliced hash.
通过这种方式,当上述FDMT树上的Tree node中的任一block中的任一槽位填充的hash值发生更新,在重新计算该Tree node的hash值时,即便该Tree node中其它的各个block未发生数据更新,也仍然需要作为计算参数参与hash计算,显然存在hash计算的计算量较大的问题。In this way, when the hash value filled in any slot in any block in the Tree node on the above-mentioned FDMT tree is updated, when the hash value of the Tree node is recalculated, even if the other each other in the Tree node is recalculated There is no data update in the block, and it still needs to be used as a calculation parameter to participate in the hash calculation. Obviously, there is a problem of a large amount of calculation in the hash calculation.
基于此,在本说明书中,为了降低在计算Tree node的hash时的计算量,上述Tree node具体可以采用主block(即主位置)和多个子block(即子位置)的数据结构。Based on this, in this specification, in order to reduce the amount of calculation when calculating the hash of the Tree node, the above-mentioned Tree node can specifically adopt the data structure of the main block (ie the main position) and multiple sub-blocks (ie the sub-positions).
请参见图5,图5为本说明书示出的另一种FDMT树的树形结构图。Please refer to FIG. 5, which is a tree structure diagram of another FDMT tree shown in this specification.
如图5所示,在本说明书示出的FDMT树的树形结构中,仍然包含前N层的Tree node,和最后一层的叶子节点。As shown in FIG. 5 , the tree structure of the FDMT tree shown in this specification still includes the Tree nodes of the first N layers and the leaf nodes of the last layer.
其中,与图4示出的上述FDMT树的结构不同的是,如图5中示出的上述FDMT树上的前N层的Tree node,均可以包括主block(即图5中示出的root block)和分别代表不同字符的多个子block;而每一个block还可以进一步包括多个槽位;例如,图5示出的为每一个Tree node均包括一个主block和N个子block;而每个子block又进一步包括N个slot。Wherein, what is different from the structure of the above-mentioned FDMT tree shown in FIG. 4 is that the tree nodes of the first N layers on the above-mentioned FDMT tree shown in FIG. 5 may include the main block (that is, the root shown in FIG. 5 ). block) and a plurality of sub-blocks representing different characters respectively; and each block may further include a plurality of slots; for example, as shown in FIG. 5, each Tree node includes a main block and N sub-blocks; and each sub-block The block further includes N slots.
其中,上述主block和子block包含的槽位的功能,具体可以有所不同;如图5所示,对于主block而言,可以包含分别与各子block对应的多个槽位,每一个槽位具体可以用于填充对应的子block中存储的数据内容的hash;例如,在计算任一子block的hash时,具体可以将该子block中各槽位填充的hash值拼接起来,再针对拼接起来的hash执行二次的hash计算,得到该子block的hash。Among them, the functions of the slots included in the above-mentioned main block and sub-blocks may be different; as shown in FIG. 5 , for the main block, it may include a plurality of slots corresponding to each sub-block, and each slot Specifically, it can be used to fill the hash of the data content stored in the corresponding sub-block; for example, when calculating the hash of any sub-block, the hash values filled in each slot in the sub-block can be spliced together, and then spliced together The hash of the sub-block performs a secondary hash calculation to obtain the hash of the sub-block.
而对于子block而言,可以包含分别代表不同的字符的多个槽位,每一个槽位具体可以用于填充该Tree node链接的下一层节点的hash值。As for the sub-block, it can contain multiple slots representing different characters, and each slot can be used to fill the hash value of the next-level node linked by the tree node.
在本说明书中,按照图5示出的Tree node的结构,则可以用该Tree node中的主block的hash值来表示该Tree node的hash值;从而,在这种情况下,当上述FDMT树上的Tree node中的任一子block中的槽位填充的hash值发生更新后,则在重新计算该Tree node的hash值时,只需要将该发生数据更新的该子block中各个槽位中填充的hash值进行拼接,并将拼接出的hash值作为计算参数重新进行hash计算,再将计算出的hash值填充至该Tree node中的主block中与该子block对应的槽位,然后再对主block中的各槽位填充的hash进行拼接,再将拼接出的hash值作为计算参数重新进行hash计算即可得到该Tree node的hash。In this specification, according to the structure of the Tree node shown in Figure 5, the hash value of the main block in the Tree node can be used to represent the hash value of the Tree node; thus, in this case, when the above-mentioned FDMT tree After the hash value filled in the slot in any sub-block in the tree node above is updated, when recalculating the hash value of the tree node, it is only necessary to update the data in each slot in the sub-block. The filled hash value is spliced, and the spliced hash value is used as a calculation parameter to re-hash calculation, and then the calculated hash value is filled into the slot corresponding to the sub-block in the main block in the tree node, and then The hash of each slot in the main block is spliced, and the spliced hash value is used as a calculation parameter to re-calculate the hash to obtain the hash of the tree node.
在整个过程中,对于未发生数据更新的其它子block中各个槽位填充的hash值,将不再需要进行拼接后作为计算参数参与hash计算,从而可降低在重新计算该Tree node的hash值时的hash计算量和计算时长,提升hash计算的计算效率。In the whole process, the hash value filled in each slot in other sub-blocks without data update will no longer need to be spliced and used as a calculation parameter to participate in the hash calculation, which can reduce the time when the hash value of the tree node is recalculated. The hash calculation amount and calculation time are improved, and the calculation efficiency of hash calculation is improved.
需要解释的是,图4和图5中示出的上述FDMT树上各层的节点之间的链接关系仅为示意性的,并不是指对上述FDMT树上各层的节点之间的链接关系的一种特殊限定。It should be explained that the link relationship between the nodes of each layer on the above-mentioned FDMT tree shown in FIG. 4 and FIG. 5 is only schematic, and does not refer to the link relationship between the nodes of each layer on the above-mentioned FDMT tree. a special limitation of .
请继续参见图4和图5,图4和图5示出的上述FDMT树上的各Tree node,均可以用于存储上述区块链数据的key中的至少部分字符。Please continue to refer to Fig. 4 and Fig. 5. Each tree node on the above-mentioned FDMT tree shown in Fig. 4 and Fig. 5 can be used to store at least some characters in the key of the above-mentioned blockchain data.
对于图4示出的上述FDMT树上的各Tree node,实际存储的字符,具体可为该Tree node中的block(即至少有一个槽位填充了hash值的非空block)所代表的字符,与该block中填充了hash值的槽位(即非空槽位)所代表的字符,进行拼接生成的字符串。For each Tree node on the above-mentioned FDMT tree shown in FIG. 4, the characters actually stored can be specifically the characters represented by blocks in the Tree node (that is, at least one slot is filled with a non-empty block with a hash value), A string generated by splicing with the character represented by the slot filled with the hash value (ie, the non-empty slot) in the block.
而对于图5示出的上述FDMT树上的各Tree node,实际存储的字符,具体可以是该Tree node中的子block所代表的字符,与该block中填充了hash值的槽位所代表的 字符,进行拼接生成的字符串。And for each Tree node on the above-mentioned FDMT tree shown in FIG. 5, the characters actually stored can be specifically the characters represented by the sub-blocks in the Tree node, and the characters represented by the slots filled with hash values in the block. character, the string generated by concatenation.
其中,在实际应用中,Tree node中的每一个block,可以仅代表一位字符;也即,基于图4和5示出的Tree node的存储格式,每一个Tree node实际存储的上述区块链数据的key的字符前缀中的部分字符,为长度是2位字符的字符串。Among them, in practical applications, each block in the Tree node can only represent one character; that is, based on the storage format of the Tree node shown in Figures 4 and 5, the above-mentioned blockchain actually stored by each Tree node Part of the characters in the character prefix of the key of the data is a string of 2 characters in length.
例如,请参见图6,图6为本说明书示出的一种Tree node的结构图;如图6所示,该Tree node包含16个代表不同的16进制字符的子block;每一个子block进一步包括16个分别代表不同的16进制字符的slot(图6中只示出了block6包含的16个槽位);假设该Tree node中的子block6(代表了16进制字符6)为非空block,该子block中的slot4(代表了16进制字符4)、slot6(代表了16进制字符6)和slot9(代表了16进制字符9)为填充了该Tree node链接的下一层节点的hash值的非空slot;则该Tree node存储的上述区块链数据的key的字符前缀中的部分字符,分别为16进制字符串“64”、“66”和“69”。For example, please refer to FIG. 6, which is a structural diagram of a Tree node shown in this specification; as shown in FIG. 6, the Tree node contains 16 sub-blocks representing different hexadecimal characters; each sub-block It further includes 16 slots that represent different hexadecimal characters respectively (only 16 slots included in block6 are shown in Figure 6); it is assumed that the sub-block6 (representing the hexadecimal character 6) in the tree node is not Empty block, slot4 (representing the hexadecimal character 4), slot6 (representing the hexadecimal character 6) and slot9 (representing the hexadecimal character 9) in the sub-block are filled with the next tree node link The non-empty slot of the hash value of the layer node; then some characters in the character prefix of the key of the above blockchain data stored by the tree node are the hexadecimal strings "64", "66" and "69" respectively.
其中,上述Tree node中所包含的子block的数量,以及每一个子block所包含的槽位的数量,在本说明书中不进行特别限定;在实际应用中,可以基于上述区块链数据的key对应的字符串所包含的字符元素的类型数,来确定上述Tree node所包含的子block的数量;以及,子block所包含的槽位的数量;例如,假设上述区块链数据对应的key为16进制字符串,此时上述区块链数据的key对应的字符串所包含的字符元素的类型数为16;则上述Tree node中所包含的子block的数量,以及每一个子block所包含的槽位的数量都可以为16。Among them, the number of sub-blocks contained in the above-mentioned Tree node, and the number of slots contained in each sub-block are not particularly limited in this specification; The number of types of character elements contained in the corresponding string to determine the number of sub-blocks contained in the above-mentioned Tree node; and the number of slots contained in the sub-blocks; for example, assume that the key corresponding to the above blockchain data is Hexadecimal string. At this time, the number of character elements contained in the string corresponding to the key of the above blockchain data is 16; then the number of sub-blocks contained in the above tree node, and the number of sub-blocks contained in each sub-block The number of slots can be 16.
在实际应用中,上述Tree node所包含的子block的数量,和上述子block所包含的槽位的数量,可以保持相同;例如,在一个例子中,以上述区块链数据的key对应的字符串为16进制字符串为例,在这种情况下,上述前N层的Tree node可以均包括16个分别代表不同的16进制字符的子block;而每一个子block可以进一步包括16个分别代表不同的16进制字符的槽位。In practical applications, the number of sub-blocks contained in the above-mentioned tree node and the number of slots contained in the above-mentioned sub-blocks can be kept the same; for example, in an example, the characters corresponding to the keys of the above-mentioned blockchain data are used The string is a hexadecimal string as an example. In this case, the above-mentioned tree nodes of the first N layers can each include 16 sub-blocks representing different hexadecimal characters; and each sub-block can further include 16 sub-blocks. Slots representing different hexadecimal characters.
通过这种方式,则上述FDMT树树前N层每一层中的单个Tree node,可以具有16*16=256个槽位,显然图4示出的FDMT树上的Tree node相对于图1示出的MPT树上用于存储字符前缀的节点而言,将具有更大的存储容量。In this way, a single Tree node in each layer of the first N layers of the above-mentioned FDMT tree tree can have 16*16=256 slots. Obviously, the Tree node on the FDMT tree shown in Figure 4 is relative to Figure 1. In terms of the nodes used to store character prefixes on the MPT tree, it will have a larger storage capacity.
当前,在实际应用中,上述Tree node所包含的子block的数量,和上述子block所包含的槽位的数量,具体也可以不相同;Currently, in practical applications, the number of sub-blocks contained in the above-mentioned tree node may be different from the number of slots contained in the above-mentioned sub-blocks;
例如,在实际应用中,上述区块链数据的key对应的字符串,具体也可以是由两种不同进制字符构成的字符串;比如,上述区块链数据的key对应的字符串具体可以是由16进制的字符和10进制的字符混合构成的字符串,在这种情况下,上述前N层的Tree node可以均包括16个分别代表不同的16进制字符的子block;而每一个子block可以进一步包括10个分别代表不同的10进制字符的槽位;或者,上述前N层的Tree node可以均包括10个分别代表不同的10进制字符的子block;而每一个子block可以进一步包括16个分别代表不同的16进制字符的槽位。For example, in practical applications, the character string corresponding to the key of the above-mentioned blockchain data can also be a character string composed of two different base characters; for example, the character string corresponding to the key of the above-mentioned blockchain data can be is a string composed of a mixture of hexadecimal characters and hexadecimal characters. In this case, the above-mentioned tree nodes of the first N layers can each include 16 sub-blocks representing different hexadecimal characters; and Each sub-block may further include 10 slots representing different decimal characters; or, the above-mentioned tree nodes of the first N layers may include 10 sub-blocks representing different decimal characters respectively; and each The sub-block may further include 16 slots representing different hexadecimal characters.
在示出的一种实施方式中,上述FDMT树包含的Tree node的层数,具体可以是一个固定值;在实际应用中,上述N的取值具体可以是一个大于或者等于1的整数;也即,上述FDMT树具体可以是一棵包含至少一层Tree node,并且包含的Tree node的层数相对固定的Merkle树。In the illustrated embodiment, the number of layers of Tree nodes included in the above-mentioned FDMT tree may be a fixed value; in practical applications, the value of the above-mentioned N may be an integer greater than or equal to 1; or That is, the above-mentioned FDMT tree may specifically be a Merkle tree including at least one layer of Tree nodes, and the number of layers of the included Tree nodes is relatively fixed.
例如,在一个例子中,以上述区块链数据的key为区块链账户地址为例,假设区块链系统支持的区块链账户地址被设计为,前6位地址字符可以相同,那么在这种情况下,可以将区块链账户地址前6位的地址字符,作为区块链账户地址的字符前缀;而且,由于Tree node存储的区块链账户地址的字符前缀中的字符的长度为2位字符;因此,上述FDMT树可以被设计成包含三层Tree node的树状结构。For example, in an example, taking the key of the above blockchain data as the blockchain account address as an example, assuming that the blockchain account address supported by the blockchain system is designed so that the first 6 address characters can be the same, then in In this case, the first 6 address characters of the blockchain account address can be used as the character prefix of the blockchain account address; moreover, since the length of the characters in the character prefix of the blockchain account address stored by the Tree node is 2-bit character; therefore, the above FDMT tree can be designed as a tree structure containing three levels of Tree nodes.
基于图4和图5示出的FDMT树的树形结构设计,一方面,由于FDMT树中的每一个Tree node,均包括分别代表不同字符的多个block;并且,各block又进一步包括多个分别代表不同字符的槽位;因此,通过这种设计,使得每一个Tree node将具有更大的数据存储容量和数据承载能力,从而在将上述FDMT树中的Tree node写入数据库进行存储时;或者,在访问数据库中存储的上述FDMT树中的Tree node时,可以使得 Tree node的数据存储容量,与承载上述数据库的存储介质的单次IO读写的容量更加适配,从而可以充分利用承载上述数据库的存储介质自身的IO读写能力,提升数据读写效率;而且,上述FDMT树上单个Tree node的数据存储容量和数据承载能力的提升,势必也会导致上述FDMT树整体的数据存储容量和数据承载能力的提升,使得上述FDMT树上可以存储更多的区块链数据;例如,以承载上述数据库的存储介质为单个物理扇区为4KB大小的磁盘为例,假设该磁盘单次IO读写的容量为4kb(一个扇区),对于图1描述的MPT树上的1个Branch node而言,假设Branch node包含的16个字段均填充了32byte的hash值,则该Branch Node的数据存储容量是32字节*16=512byte左右;显然针对Branch node的一次IO读取的容量最大只能是512byte左右,远小于该磁盘一次IO读取最大可以读取到4Kb的读取能力,这显然无法充分利用磁盘的IO读取能力,存在严重的性能浪费。Based on the tree structure design of the FDMT tree shown in Figure 4 and Figure 5, on the one hand, because each Tree node in the FDMT tree includes a plurality of blocks representing different characters respectively; and each block further includes a plurality of Slots representing different characters respectively; therefore, through this design, each Tree node will have a larger data storage capacity and data carrying capacity, so that when the Tree node in the above FDMT tree is written into the database for storage; Alternatively, when accessing the Tree node in the above-mentioned FDMT tree stored in the database, the data storage capacity of the Tree node can be more adapted to the capacity of a single IO read and write of the storage medium carrying the above-mentioned database, so that the bearing capacity can be fully utilized. The IO read and write capability of the storage medium of the above-mentioned database improves the efficiency of data read and write; moreover, the improvement of the data storage capacity and data carrying capacity of a single tree node on the above-mentioned FDMT tree will inevitably lead to the overall data storage capacity of the above-mentioned FDMT tree. and the improvement of data carrying capacity, so that more blockchain data can be stored on the above FDMT tree; for example, taking the storage medium carrying the above database as a disk with a single physical sector of 4KB as an example, it is assumed that the disk has a single IO The capacity of reading and writing is 4kb (one sector). For a Branch node on the MPT tree described in Figure 1, assuming that the 16 fields contained in the Branch node are filled with a 32byte hash value, the data of the Branch Node is The storage capacity is about 32 bytes*16=512 bytes; obviously, the maximum capacity of one IO read for Branch node can only be about 512 bytes, which is far less than the maximum read capacity of 4Kb that can be read by one IO read of the disk. Obviously, the IO read capability of the disk cannot be fully utilized, and there is a serious performance waste.
但是,如果采用如图4和图5所示出的FDMT树的树形结构设计,假设上述前N层的Tree node可以均包括16个分别代表不同的16进制字符的block;每一个block可以进一步包括16个分别代表不同的16进制字符的槽位,则上述FDMT前N层每一层中的单个Tree node,可以具有16*16=256个槽位;假设每一个槽位填充的是32byte的hash值,则在所有槽位满负荷的情况下,一个Tree node的最大存储容量则是256*32byte=8192byte=8kb,刚好是两个扇区的容量。显而易见的,图4和图5示出的FDMT的树形结构中的每一个Tree node的数据存储容量,与上述磁盘的单次IO读写的容量更加适配,可以充分利用该磁盘自身的IO读写能力,提升数据读写效率。However, if the tree structure design of the FDMT tree as shown in Figure 4 and Figure 5 is adopted, it is assumed that the above-mentioned tree nodes of the first N layers can each include 16 blocks representing different hexadecimal characters; each block can Further including 16 slots representing different hexadecimal characters, then a single tree node in each layer of the first N layers of the above FDMT can have 16*16=256 slots; assuming that each slot is filled with With a hash value of 32 bytes, when all slots are fully loaded, the maximum storage capacity of a tree node is 256*32byte=8192byte=8kb, which is exactly the capacity of two sectors. Obviously, the data storage capacity of each Tree node in the tree structure of FDMT shown in Figure 4 and Figure 5 is more suitable for the single IO read and write capacity of the above-mentioned disk, and can make full use of the IO of the disk itself. Read and write ability, improve data read and write efficiency.
而且,上述FDMT上单个Tree node的数据存储容量和数据承载能力的提升,势必也会导致上述FDMT整体的数据存储容量和数据承载能力的提升,使得上述FDMT上可以存储更多的区块链数据;例如,假设图4和图5示出的FDMT的树形结构包含3层Tree node,每一层的Tree node可以均包括16个分别代表不同的16进制字符的子block;每一个block可以进一步包括16个分别代表不同的16进制字符的槽位;那么,每一层中的单个Tree node,可以具有16*16=256个槽位;则三层Tree node共计可以承载256*256*256=16.77M个字符组合,共计可以链接16.77M个bucket数据块;假设用户定义每一个bucket数据块可以承载16条数据记录,则整棵FDMT树最多可以承载16.77M*16条区块链数据;显而易见的,相较于图1示出的MPT树,图4和图5示出的上述FDMT可以存储更多的区块链数据,具有更大的数据承载能力。Moreover, the improvement of the data storage capacity and data carrying capacity of a single tree node on the above-mentioned FDMT will inevitably lead to the improvement of the overall data storage capacity and data carrying capacity of the above-mentioned FDMT, so that more blockchain data can be stored on the above-mentioned FDMT. For example, suppose that the tree structure of the FDMT shown in Figure 4 and Figure 5 includes 3 layers of Tree nodes, and the Tree nodes of each layer can include 16 sub-blocks representing different hexadecimal characters respectively; each block can It further includes 16 slots representing different hexadecimal characters; then, a single tree node in each layer can have 16*16=256 slots; then the three-layer tree node can carry a total of 256*256* 256=16.77M character combination, a total of 16.77M bucket data blocks can be linked; assuming that each bucket data block can be defined by the user to carry 16 data records, the entire FDMT tree can carry up to 16.77M*16 blockchain data Obviously, compared with the MPT tree shown in FIG. 1, the above-mentioned FDMT shown in FIG. 4 and FIG. 5 can store more blockchain data and has a larger data carrying capacity.
第二方面,由于FDMT中的每一个Tree node均采用统一的数据结构;对于上述FDMT中各层的Tree node来说,其实际存储的区块链数据的key的字符前缀的字符长度也将保持固定;因此,通过这种设计,可以避免由于各层Tree node其实际存储的字符长度不固定,而导致的节点的频繁分裂,从而可以确保FDMT的树形结构中所包含的Tree node的层数,始终处于一个相对稳定的状态。In the second aspect, since each Tree node in FDMT adopts a unified data structure; for the Tree nodes of each layer in the above-mentioned FDMT, the character length of the character prefix of the key of the actually stored blockchain data will also remain unchanged. Fixed; therefore, through this design, frequent splitting of nodes caused by the fact that the length of characters actually stored in each layer of Tree nodes is not fixed can be avoided, thereby ensuring the number of layers of Tree nodes contained in the tree structure of FDMT. , is always in a relatively stable state.
第三方面,由于通过这种设计,每一个Tree node将具有更大的数据存储容量和数据承载能力;并且,上述FDMT的树形结构中包含的Tree node的层数,将处于一个相对稳定的状态;因此,Tree node存储容量的提升和Tree node的层数相对稳定,在某种程度上可以确保上述FDMT的Tree node将具有更少的层数;从而,在Tree node具有更大的数据存储容量和数据承载能力,以及上述FDMT的Tree node具有更少的层数的基础之上,系统在进行冷启动,需要从承载上述数据库的存储介质中,将上述FDMT的前N层的Tree node作为需要频繁读取的数据加载到内存中时,则可以显著降低将上述存储介质存储的上述前N层的Tree node读取到内存中时的IO读取次数,以及将FDMT的前N层的Tree node加载到内存时的整体读取时长,进而从根本上缩短系统冷启动时的启动时延。Thirdly, due to this design, each Tree node will have greater data storage capacity and data carrying capacity; and, the number of layers of Tree nodes contained in the tree structure of the FDMT will be in a relatively stable state. Therefore, the improvement of the storage capacity of the Tree node and the number of layers of the Tree node are relatively stable, to some extent, it can be ensured that the Tree node of the above FDMT will have fewer layers; thus, the Tree node has a larger data storage On the basis of the capacity and data carrying capacity, and the tree node of the above FDMT has fewer layers, the system needs to use the tree node of the first N layers of the above FDMT from the storage medium carrying the above database as the cold start. When the data that needs to be read frequently is loaded into the memory, it can significantly reduce the number of IO reads when reading the tree nodes of the first N layers stored in the above storage medium into the memory, and the tree nodes of the first N layers of the FDMT can be read into the memory. The overall read time when the node is loaded into memory, thereby fundamentally shortening the startup delay when the system is cold started.
例如,以图4和图5示出的FDMT为3层Tree node固定,且每一层的Tree node包括16个分别代表不同的16进制字符的block;每一个block进一步包括16个分别代表不同的16进制字符的槽位为例,在所有槽位满负荷的情况下,一个Tree node的最大存储容量则是256*32byte=8192byte=8kb;对于图1示出的MPT树而言,由于其需要进行频繁的节点分裂,MPT树的层数不固定;而且,由于其单个Branch Node节点的存储容量512byte,远小于图4和图5示出的FDMT树上的Tree node;势必造成MPT树具有更大的层数(比如MPT树最大可以达到64层,远大于3层)。而系统在冷启动,将FDMT树前N层读取到内存时,通常是一层一层读取的;因此,基于图1示出的MPT 树,显然需要更多的读取次数。For example, the FDMT shown in Fig. 4 and Fig. 5 is fixed as a 3-layer Tree node, and the Tree node of each layer includes 16 blocks representing different hexadecimal characters; each block further includes 16 blocks representing different hexadecimal characters. Take the slot of hexadecimal characters as an example, when all the slots are fully loaded, the maximum storage capacity of a Tree node is 256*32byte=8192byte=8kb; for the MPT tree shown in Figure 1, due to It needs frequent node splitting, and the number of layers of the MPT tree is not fixed; moreover, because the storage capacity of its single Branch Node node is 512 bytes, it is much smaller than the Tree node on the FDMT tree shown in Figure 4 and Figure 5; it will inevitably cause the MPT tree. Has a larger number of layers (for example, the MPT tree can reach up to 64 layers, which is much larger than 3 layers). When the system is cold-started, when the first N layers of the FDMT tree are read into the memory, they are usually read layer by layer; therefore, based on the MPT tree shown in Figure 1, obviously more reads are required.
而且,由于MPT树上的单个Branch Node节点的存储容量512byte,仅为承载上述数据库的单个物理扇区为4KB的八分之一,读取效率很低;因此,即便按照图1的MPT树和图4和图5示出的FDMT树存储同样的数据,系统在冷启动针对MPT树的IO读取次数,也可能是针对图4和图5示出的FDMT树的IO读取次数的至少8倍。Moreover, since the storage capacity of a single Branch Node node on the MPT tree is 512 bytes, only the single physical sector carrying the above database is one-eighth of 4KB, and the reading efficiency is very low; therefore, even according to the MPT tree and The FDMT tree shown in Figures 4 and 5 stores the same data, and the number of IO reads for the MPT tree during the cold start of the system may be at least 8 times the number of IO reads for the FDMT tree shown in Figures 4 and 5 times.
显而易见的,系统在冷启动时,针对图4和图5示出的上述FDMT树的IO读取次数,将远小于针对图1示出的MPT树的IO读取次数;因此,图4和图5示出的上述FDMT树的树形结构设计对系统冷启动将更加友好。Obviously, when the system is cold-started, the number of IO reads for the above FDMT tree shown in Figures 4 and 5 will be much smaller than the number of IO reads for the MPT tree shown in Figure 1; therefore, Figures 4 and 5 The tree structure design of the above FDMT tree shown in 5 will be more friendly to the cold start of the system.
在示出的一种实施方式中,上述区块链数据的key对应的字符串仍然可以包括字符前缀和字符后缀;在这种情况下,上述Tree node可以用于存储所述区块链数据的key的字符前缀中的字符;上述叶子节点可以用于存储所述区块链数据的key的字符后缀和上述区块链数据的Value。In the illustrated embodiment, the character string corresponding to the key of the above-mentioned blockchain data may still include character prefixes and character suffixes; in this case, the above-mentioned Tree node can be used to store the The character in the character prefix of the key; the leaf node can be used to store the character suffix of the key of the blockchain data and the Value of the blockchain data.
其中,由于上述叶子节点实际存储的数据,相对于上述Tree node来说,通常具有更大的数据容量;比如,上述叶子节点实际存储的上述区块链数据的value,通常为上述区块链数据的原始内容,上述区块链数据的原始内容相对于上述区块链数据的字符前缀而言,其所占用的存储空间也更大;因此,在本说明书中,为了确保上述叶子节点能够具有更大的数据容量,上述叶子节点具体可以采用大数据块的形式来存储数据。Among them, the data actually stored by the above-mentioned leaf nodes usually has a larger data capacity than the above-mentioned Tree nodes; for example, the value of the above-mentioned blockchain data actually stored by the above-mentioned leaf nodes is usually the above-mentioned blockchain data. Compared with the character prefix of the above blockchain data, the original content of the above-mentioned blockchain data also occupies a larger storage space; therefore, in this specification, in order to ensure that the above-mentioned leaf nodes can have more For large data capacity, the above leaf nodes can specifically store data in the form of large data blocks.
其中,上述数据块的具体形式以及存储结构,在本说明书中不进行特别限定;在示出的一种实施方式中,上述叶子节点具体可以是bucket数据桶的形式;其中,上述bucket数据桶具体可以是用于存储数据的容器或者存储空间。The specific form and storage structure of the above-mentioned data block are not particularly limited in this specification; in the illustrated embodiment, the above-mentioned leaf node may specifically be in the form of a bucket data bucket; wherein, the above-mentioned bucket data bucket specifically Can be a container or storage space for storing data.
请参见图7,图7为本说明书示出的一种bucket数据桶的结构图;如图7所示,在上述bucket数据桶(即图7中示出的bucker node)中,可以包括若干条数据记录;其中,上述bucket数据桶中包含的上述若干条数据记录,在逻辑上可以不是一个整体,而是在逻辑上分离的若干条不同的数据记录。每一条数据记录都分别对应一条区块链数据,用于存储上述区块链数据的value;也即,一条数据记录,是指一条存储的数据内容包括所述区块链数据的value的存储记录。Please refer to FIG. 7 , which is a structural diagram of a bucket data bucket shown in this specification; as shown in FIG. 7 , the above-mentioned bucket data bucket (ie, the bucket node shown in FIG. 7 ) may include several Data records; wherein, the above-mentioned several data records contained in the above-mentioned bucket data buckets may not logically be a whole, but logically separated several different data records. Each data record corresponds to a piece of blockchain data, which is used to store the value of the above-mentioned blockchain data; that is, a data record refers to a storage record whose data content includes the value of the blockchain data. .
上述bucket数据桶中包含的上述若干条数据记录,在逻辑上不是一个整体,是指各条数据记录都可以分别对应一个独立的查询键值(key),从而可以基于各条数据记录的查询键值,来针对上述bucket数据桶中的各条数据记录分别进行精确查询,而并不要对上述bucket数据桶中存储的所有的数据记录进行整体的读取。The above-mentioned several data records contained in the above-mentioned bucket data bucket are not logically a whole, which means that each data record can correspond to an independent query key value (key), so that the query key of each data record can be based on value, to perform precise query for each data record in the above bucket data bucket, instead of reading all the data records stored in the above bucket data bucket as a whole.
其中,各条数据记录分别对应的查询键值的具体形式和具体内容,在本说明书中不进行特别限定,可以是任意形式的能够作为各条数据记录的查询索引的字符串。The specific form and specific content of the query key value corresponding to each data record are not particularly limited in this specification, and can be any form of character string that can be used as a query index for each data record.
在示出的一种实施方式中,各条数据记录对应的查询键值具体可以是各条数据记录包含的数据内容的hash值;上述bucket数据桶中包含的上述数据记录,则具体可以包括由上述区块链数据的value的hash值,和上述区块链数据的value对应的数据内容构成的key-value键值对。In the illustrated embodiment, the query key value corresponding to each data record may specifically be the hash value of the data content contained in each data record; the above-mentioned data record contained in the above-mentioned bucket data bucket may specifically include the following: A key-value key-value pair formed by the hash value of the value of the above blockchain data and the data content corresponding to the value of the above blockchain data.
当然,在实际应用中,各条数据记录对应的查询键值也可以是hash值以外的其它形式的能够作为各条数据记录的查询索引的字符串,在本说明中不进行特别的限定;例如,在一个例子中,各条数据记录对应的查询键值具体也可以是由节点设备为各条数据记录分别设置的一个唯一的标识(比如编号)。Of course, in practical applications, the query key value corresponding to each data record may also be a string other than the hash value that can be used as the query index of each data record, which is not particularly limited in this description; for example, , in an example, the query key value corresponding to each data record may also be a unique identifier (such as a serial number) respectively set by the node device for each data record.
在示出的一种实施方式中,如果上述Tree node用于存储上述区块链数据的key的字符前缀中的字符;则上述叶子节点用于存储上述区块链数据的key的字符后缀和上述区块链数据的Value;相应的,上述bucket数据桶中包含的上述数据记录,具体可以是将上述区块链数据的key中的字符后缀和上述区块链数据的value对应的数据内容整体进行hash计算得到的hash值,和上述区块链数据的key的字符后缀和上述区块链数据的value对应的数据内容构成的key-value键值对。In the illustrated embodiment, if the above-mentioned Tree node is used to store the characters in the character prefix of the key of the above-mentioned blockchain data; then the above-mentioned leaf node is used to store the character suffix of the key of the above-mentioned blockchain data and the above-mentioned The value of the blockchain data; correspondingly, the above data records contained in the above bucket data buckets may specifically be the data content corresponding to the character suffix in the key of the above blockchain data and the value of the above blockchain data as a whole. The hash value obtained by the hash calculation is a key-value key-value pair formed by the character suffix of the key of the above-mentioned blockchain data and the data content corresponding to the value of the above-mentioned blockchain data.
在实际应用中,上述数据记录具体也可以是key-value键值对以外的其它类型的数据形式,在本说明书中不再进行一一列举。In practical applications, the above data records may also be other types of data forms other than key-value pairs, which will not be listed one by one in this specification.
通过以上实施方式,由于FDMT树中的叶子节点中所包含的若干条数据记录,在 逻辑上不再是一个整体,而是在逻辑上分离的若干条key-value键值对;因此,上述FDMT树中的叶子节点所包含的数据,将不再作为数据库中的一个整体的存取单位进行整体存取,上述叶子节点所包含的每一条key-value键值对将作为数据库中的一个独立的存取单位,从而使得针对上述数据库的数据存取将更加灵活;例如,以上述区块链数据的value为区块链中的区块链账户对应的最新账户状态数据,上述区块链数据的key为区块链账户地址为例,在这种情况下,上述bucket数据桶中包含的上述数据记录对应的key-value键值对的key,可以是区块链账户地址的字符后缀和对应的账户状态数据两部分数据内容的hash值;该key-value键值对的value,可以是区块链账户地址的字符后缀和对应的账户状态数据两部分的数据内容。Through the above implementation, since several data records contained in the leaf nodes in the FDMT tree are no longer a whole logically, they are logically separated several key-value pairs; therefore, the above FDMT The data contained in the leaf nodes in the tree will no longer be accessed as a whole access unit in the database, and each key-value pair contained in the above leaf nodes will be used as an independent access unit, so that the data access to the above-mentioned database will be more flexible; for example, the value of the above-mentioned blockchain data is the latest account status data corresponding to the blockchain account in the blockchain, and the value of the above-mentioned blockchain data is For example, the key is the blockchain account address. In this case, the key of the key-value key-value pair corresponding to the above data record contained in the above bucket data bucket can be the character suffix of the blockchain account address and the corresponding The hash value of the two parts of the account status data; the value of the key-value pair can be the character suffix of the blockchain account address and the data content of the corresponding account status data.
假设需要读取上述bucket数据桶中包含的某一个特定的账户地址的字符后缀和对应的账户状态数据,由于上述bucket数据桶中的各条key-value键值对都是一个独立的存取单位;因此,只需要基于该特定的账户地址的字符后缀和对应的账户状态数据这两部分数据内容的hash值,在数据库进行内容寻址即可,而不再需要从数据库中将该叶子节点中所包含的所有数据内容,整体读取到内存中,再在内存中进一步查找需要读取的账户地址的字符后缀和对应的账户状态数据;相应的,如果需要向上述bucket数据桶写入一个新的账户地址的字符后缀和对应的账户状态数据,或者对上述bucket数据桶中包含的一个特定的账户地址对应的账户状态数据进行更新,则可以直接根据新的账户地址的字符后缀和对应的账户状态数据构建key-value键值对,并将该key-value键值对写入上述bucket数据桶即可;或者,基于该特定的账户地址的字符后缀和对应的账户状态数据这两部分数据内容的hash值,在数据库进行内容寻址,查找到对应的key-value键值对,然后写入该特定的账户地址对应的更新后的账户状态数据,对该key-value键值对原有的value进行更新即可。Suppose you need to read the character suffix of a specific account address and the corresponding account status data contained in the above bucket data bucket, because each key-value pair in the above bucket data bucket is an independent access unit ; Therefore, it is only necessary to perform content addressing in the database based on the character suffix of the specific account address and the hash value of the corresponding account status data of the two parts of the data content, and it is no longer necessary to retrieve the leaf node from the database. All the data contained in it are read into the memory as a whole, and then the character suffix of the account address to be read and the corresponding account status data are further searched in the memory; accordingly, if it is necessary to write a new The character suffix of the account address and the corresponding account status data, or to update the account status data corresponding to a specific account address contained in the above bucket data bucket, it can be directly based on the character suffix of the new account address and the corresponding account. The state data can construct a key-value key-value pair, and write the key-value key-value pair into the above bucket data bucket; or, based on the character suffix of the specific account address and the corresponding account status data two parts of the data content The hash value of the account address, perform content addressing in the database, find the corresponding key-value key-value pair, and then write the updated account status data corresponding to the specific account address, and the original key-value key-value pair. value can be updated.
其中,上述bucket数据桶中所包含的数据记录的条数,在本说明书中不进行特别限定;在示出的一种实现方式中,上述bucket数据桶中包含的数据记录的条数,具体可以由用户进行自定义配置。The number of data records contained in the above-mentioned bucket data bucket is not particularly limited in this specification; in the illustrated implementation manner, the number of data records contained in the above-mentioned bucket data bucket may specifically be Custom configuration by the user.
例如,以上述区块链数据为区块链中的区块链账户对应的最新账户状态数据,上述区块链数据的key为区块链账户地址为例,在这种情况下,上述bucket数据桶中的每一条数据记录,分别与一个区块链账户的账户状态相对应;上述bucket数据桶中的数据记录的条数,实际上代表着该bucket数据桶可以容纳区块链账户的账户承载能力;因此,用户通过对上述bucket数据桶能够容纳的数据记录的条数进行自定义,可以实现对上述bucket数据桶的账户承载能力进行灵活的定制;比如,在一个例子中,上述bucket数据桶中包含的数据记录的条数可以由用户配置为16条或者64条,从而使得单个bucket数据桶可以承载16或者64个区块链账户的状态数据。For example, the above blockchain data is the latest account status data corresponding to the blockchain account in the blockchain, and the key of the above blockchain data is the blockchain account address. In this case, the above bucket data Each data record in the bucket corresponds to the account status of a blockchain account; the number of data records in the above bucket data bucket actually represents that the bucket data bucket can accommodate the account bearer of the blockchain account Therefore, by customizing the number of data records that the above bucket data bucket can hold, the user can flexibly customize the account carrying capacity of the above bucket data bucket; for example, in an example, the above bucket data bucket The number of data records contained in it can be configured by the user to be 16 or 64, so that a single bucket can carry the status data of 16 or 64 blockchain accounts.
其中,上述bucket数据桶中所存储的数据记录的总存储容量,在本说明书中也不进行特别限定;在示出的一种实现方式中,上述bucket数据桶中所存储的数据记录的总存储容量,具体可以由用户进行自定义配置。Wherein, the total storage capacity of the data records stored in the above bucket data bucket is not particularly limited in this specification; in an implementation manner shown, the total storage capacity of the data records stored in the above bucket data bucket Capacity, which can be customized by the user.
例如,在实现时,以承载上述数据库的存储介质为单个物理扇区为4KB大小的磁盘为例,在这种情况下,用户可以将上述bucket数据桶中所存储的数据记录的最大存储容量,设置为4KB;或者,4KB的整数倍,以使上述bucket数据桶的最大存储容量,能够与上述存储介质的单个物理扇区的存储容量相适配。For example, in the implementation, it is assumed that the storage medium carrying the above-mentioned database is a disk with a single physical sector of 4KB. It is set to 4KB; or an integer multiple of 4KB, so that the maximum storage capacity of the bucket data bucket can be adapted to the storage capacity of a single physical sector of the storage medium.
在本说明书中,如前所述,上述FDMT树上前N层的各Tree node,由于其采用统一的数据结构;因此,上述FDMT树上前N层的各Tree node,将不再发生节点分裂。而上述FDMT树上的叶子节点,仍然可以在满足一定的分裂条件时进行节点分裂。In this specification, as mentioned above, each Tree node of the first N layers on the above-mentioned FDMT tree adopts a unified data structure; therefore, each Tree node of the first N layers on the above-mentioned FDMT tree will no longer be split. . However, the leaf nodes on the above-mentioned FDMT tree can still perform node splitting when certain splitting conditions are met.
与上述MPT树不同的是,在本说明书中,上述FDMT树上的叶子节点在进行节点分裂时,可以不再按照共享字符前缀的字符长度发生变化来进行分裂,而是按照叶子节点的存储容量进行分裂。当上述FDMT树上的叶子节点的存储容量满足节点分裂条件时,再从该叶子节点中分裂出中间节点(即图5中示出的Extend node)。分裂出的中间节点,为上述叶子节点的上层节点。对同一个叶子节点而言,可以进行多次分裂。Different from the above-mentioned MPT tree, in this specification, when the leaf nodes on the above-mentioned FDMT tree are split, they can no longer be split according to the change of the character length of the shared character prefix, but according to the storage capacity of the leaf node. split. When the storage capacity of the leaf node on the above-mentioned FDMT tree satisfies the node splitting condition, an intermediate node (ie, the Extend node shown in FIG. 5 ) is split from the leaf node. The split intermediate node is the upper-level node of the above leaf node. For the same leaf node, multiple splits can be performed.
其中,上述节点分裂条件,可以包含与上述叶子节点的存储容量相关的任意形式的条件,在本说明书中不进行特别限定;在示出的一种实施方式中,上述节点分裂条件,具体可以是以下示出的条件1和条件2中的任意一个;或者,也可以是以下示出的条件 1和条件2中的组合:条件1:上述叶子节点中存储的数据记录的总数量大于阈值;条件2:上述叶子节点中存储的数据记录的总存储容量大于阈值。The above-mentioned node splitting condition may include any form of condition related to the storage capacity of the above-mentioned leaf node, which is not particularly limited in this specification; in the illustrated embodiment, the above-mentioned node splitting condition may specifically be: Condition 1 and Condition 2 shown below; or a combination of Condition 1 and Condition 2 shown below: Condition 1: The total number of data records stored in the above leaf nodes is greater than the threshold; Condition 2: The total storage capacity of the data records stored in the above leaf nodes is greater than the threshold.
例如,在一个例子中,可以将上述节点分裂条件设置为,当上述叶子节点中存储的数据记录的总数量大于64条;和/或,上述叶子节点中存储的数据记录的总存储容量大于4KB时,则从该叶子节点中分裂出中间节点。For example, in one example, the above-mentioned node splitting condition may be set as, when the total number of data records stored in the above-mentioned leaf nodes is greater than 64; and/or, the total storage capacity of the data records stored in the above-mentioned leaf nodes is greater than 4KB , the intermediate node is split from the leaf node.
在本说明书中,上述Extend node,也是上述FDMT树的中间节点,可以采用与以上描述的Tree node完全相同的数据结构,具体用于存储从上述叶子节点存储的字符后缀中分裂出的字符;例如,请参见图4和图5,从叶子节点中分裂出的Extend node,也可以包括分别代表不同字符的多个block;而每一个block可以进一步包括多个分别代表不同字符的槽位;该槽位具体可以用于填充该节点链接的下一层节点的hash值。比如,对于Extend node而言,其下一层节点为上述叶子节点;因此,Extend node中的block所包含的槽位中,可以用于填充该Extend node链接的下一层叶子节点的hash值。In this specification, the above-mentioned Extend node, which is also the intermediate node of the above-mentioned FDMT tree, can adopt the exact same data structure as the above-described Tree node, and is specifically used to store the characters split from the character suffixes stored in the above-mentioned leaf nodes; for example , please refer to Figure 4 and Figure 5, the Extend node split from the leaf node may also include multiple blocks representing different characters; and each block may further include multiple slots representing different characters; the slot The bit can be used to fill in the hash value of the next layer node linked by this node. For example, for an Extend node, the next-layer node is the above-mentioned leaf node; therefore, the slot contained in the block in the Extend node can be used to fill the hash value of the next-layer leaf node linked by the Extend node.
在本说明书中,对于从上述叶子节点中分裂出的Extend node而言,还可以按照Extend node的存储容量与其链接的下层的叶子节点进行合并。当上述FDMT树上的Extend node的存储容量满足节点合并条件时,可以将该Extend node合并至与其链接的下层的叶子节点。In this specification, for an Extend node split from the above-mentioned leaf nodes, it may also be merged with the lower-level leaf nodes linked to the Extend node according to the storage capacity of the Extend node. When the storage capacity of the Extend node on the above FDMT tree satisfies the node merging condition, the Extend node can be merged into the lower-level leaf node linked to it.
其中,将Extend node合并至与其链接的下层的叶子节点,是指将该Extend node中存储的字符作为上述字符后缀,写入与该Extend node链接的下层的一个或者多个叶子节点。Wherein, merging the Extend node into the lower-level leaf node linked to it means that the character stored in the Extend node is used as the above-mentioned character suffix and written into one or more leaf nodes of the lower layer linked with the Extend node.
其中,上述节点合并条件,也可以包含与上述Extend node的存储容量相关的任意形式的条件,在本说明书中不进行特别限定;在示出的一种实施方式中,上述节点合并条件,具体可以是以下示出的条件3和条件4中的任意一个;或者,也可以是以下示出的条件3和条件3中的组合:条件1:上述Extend node中存储的字符的总数量小于或等于阈值;也即,上述Extend node中各个block中非空slot(即填充了hash值的slot)的总数量;条件2:上述Extend node中存储的字符的总存储容量小于或等于阈值。也即,上述Extend node中各个block中非空slot中填充的hash值的总存储容量;例如,在一个例子中,可以将上述节点合并条件设置为,当上述Extend node中存储的字符的总数量小于或者等于1条;和/或,上述Extend node中存储的字符的总存储容量小于或者等于1KB时,则将该Extend node存储的字符作为字符后缀,写入该Extend node链接的下层的一个或者多个叶子节点。The above-mentioned node merging condition may also include any form of condition related to the storage capacity of the above-mentioned Extend node, which is not particularly limited in this specification; in the illustrated embodiment, the above-mentioned node merging condition may specifically be is any one of Condition 3 and Condition 4 shown below; or, it can also be a combination of Condition 3 and Condition 3 shown below: Condition 1: The total number of characters stored in the Extend node above is less than or equal to the threshold ; That is, the total number of non-empty slots (that is, slots filled with hash values) in each block in the Extend node above; Condition 2: The total storage capacity of the characters stored in the Extend node above is less than or equal to the threshold. That is, the total storage capacity of the hash values filled in the non-empty slots in each block in the Extend node above; for example, in an example, the above node merging condition can be set as, when the total number of characters stored in the Extend node above Less than or equal to 1; and/or, when the total storage capacity of the characters stored in the Extend node is less than or equal to 1KB, the characters stored in the Extend node are used as character suffixes, and are written into one of the lower layers of the Extend node link or multiple leaf nodes.
通过以上描述可知,本说明书中描述的Extend node,可以是上述FDMT树上动态可伸缩的中间节点;当上述FDMT树上的任一叶子节点的存储容量满足节点分裂条件时,可以从该叶子节点中分裂出至少一个Extend node,以及至少一个叶子节点;当任一Extend node的存储容量满足节点合并条件时,可以将该Extend node合并至与其链接的下层的叶子节点。As can be seen from the above description, the Extend node described in this specification can be a dynamically scalable intermediate node on the above-mentioned FDMT tree; when the storage capacity of any leaf node on the above-mentioned FDMT tree satisfies the node splitting condition, it can be used from the leaf node. At least one Extend node and at least one leaf node are split in the middle; when the storage capacity of any Extend node satisfies the node merging condition, the Extend node can be merged into the lower-level leaf node linked to it.
在本说明书中,待存储的区块链数据,具体可以包括至少以下四类数据:区块中收录的交易;在区块中的交易执行完毕后,与所述区块中收录的交易对应的交易收据;在区块中的交易执行完毕后,与所述区块链中的区块链账户对应的最新账户状态数据;智能合约账户的存储内容;相应的,上述FDMT树具体也可以包括:用于存储区块中收录的交易的交易树;用于存储与区块中收录的交易对应的交易收据的收据树;用于存储与所述区块链中的区块链账户对应的最新账户状态数据的状态树;用于存储智能合约账户的存储内容的存储树。In this specification, the blockchain data to be stored may specifically include at least the following four types of data: transactions included in the block; Transaction receipt; after the transaction in the block is executed, the latest account status data corresponding to the blockchain account in the blockchain; the storage content of the smart contract account; Correspondingly, the above-mentioned FDMT tree may also specifically include: A transaction tree used to store transactions included in the block; a receipt tree used to store transaction receipts corresponding to transactions included in the block; used to store the latest account corresponding to the blockchain account in the blockchain A state tree for state data; a storage tree for storing the storage content of smart contract accounts.
当然,在实际应用中,也可以只利用上述FDMT树的树形结构来存储上述四种数据中的部分类型的数据;比如,只利用上述FDMT树来存储上述区块链账户对应的最新账户状态数据,其他类型的数据可以利用其他形式的二叉树来存储(比如MPT或者其它形式的二叉树)。Of course, in practical applications, only the tree structure of the above FDMT tree can be used to store some types of data in the above four types of data; for example, only the above FDMT tree can be used to store the latest account status corresponding to the above blockchain account Data, other types of data can be stored using other forms of binary trees (such as MPT or other forms of binary trees).
其中,上述交易树、收据树和状态树的根节点的hash值,可以存储在区块头中;上述存储树的根节点的hash值,可以存储在与该存储树对应的合约账户的结构体中的Storage字段中。The hash value of the root node of the above transaction tree, receipt tree and state tree can be stored in the block header; the hash value of the root node of the above storage tree can be stored in the structure of the contract account corresponding to the storage tree. in the Storage field.
上述区块链数据的key,具体可以是指区块链数据在数据库中对应的查找键值;相 应的,上述区块链数据的Value,具体可以是上述区块链数据的原始内容;其中,在实际应用中,上述查找键值具体可以是一个与区块链数据对应的字符串;当上述区块链数据为不同类型的数据时,其对应的key也会存在一定的差异;例如,当上述区块链数据为区块中收录的交易;或者,在区块中的交易执行完毕后,与该区块中收录的交易对应的交易收据时,此时与该区块链数据对应的key,具体可以是交易在区块中的序号;或者,其它形式的交易标识。The key of the above-mentioned blockchain data may specifically refer to the corresponding search key value of the blockchain data in the database; correspondingly, the value of the above-mentioned blockchain data may specifically be the original content of the above-mentioned blockchain data; wherein, In practical applications, the above-mentioned search key may be a string corresponding to the blockchain data; when the above-mentioned blockchain data is of different types, the corresponding keys will also be different; for example, when the above-mentioned blockchain data is of different types The above blockchain data is the transaction included in the block; or, after the transaction in the block is executed, when the transaction receipt corresponding to the transaction included in the block is the transaction receipt, the key corresponding to the blockchain data at this time , which can be the sequence number of the transaction in the block; or, a transaction identifier in other forms.
当上述区块链数据为在区块中的交易执行完毕后,与区块链中的区块链账户对应的最新账户状态数据时,此时与该区块链数据对应的key,具体可以是区块链账户的账户地址。When the above blockchain data is the latest account status data corresponding to the blockchain account in the blockchain after the transaction in the block is completed, the key corresponding to the blockchain data at this time can be specifically The account address of the blockchain account.
当上述区块链数据为智能合约账户的存储内容时,此时与该区块链数据对应的key,具体可以是合约账户的账户地址和上述存储内容在合约账户的账户存储中的存储位置的hash值;比如,在一个例子中,上述存储内容通常可以是状态变量,则可以将合约账户的账户地址和状态变量在合约账户的账户存储中的存储位置的hash值作为key。When the above-mentioned blockchain data is the storage content of the smart contract account, the key corresponding to the blockchain data at this time may specifically be the account address of the contract account and the storage location of the above-mentioned storage content in the account storage of the contract account. Hash value; for example, in an example, the above storage content can usually be a state variable, then the account address of the contract account and the hash value of the storage location of the state variable in the account storage of the contract account can be used as the key.
在本说明书中,当区块链中的节点设备在存储区块链数据时,可以先获取待存储的区块链数据的key-value键值对;例如,在一个例子中,节点设备可以在获取到待存储的区块链数据时,将该区块链数据处理成key-value键值对;在获取到待存储的区块链数据的key-value键值对之后,可以将该待存储的区块链数据的key-value键值对转换成上述逻辑的树形结构上的根节点、中间节点和叶子节点;例如,在一个例子中,上述节点设备可以搭载一个与上述FDMT树对应的存储接口或者存储服务,该存储接口或者存储服务具体可以用于将待存储的区块链数据的key-value键值对,转换成为FDMT树上的节点;则该节点设备在获取到待存储的区块链数据的key-value键值对之后,可以通过调用该存储接口或者存储服务,按照图4或者图5示出的FDMT树的树形结构,将待存储的区块链数据的key-value键值对,转换成为图4或者图5上的根节点、中间节点和叶子节点。In this specification, when the node device in the blockchain is storing blockchain data, it can first obtain the key-value pair of the blockchain data to be stored; for example, in an example, the node device can be stored in the When the blockchain data to be stored is obtained, the blockchain data is processed into key-value key-value pairs; after the key-value key-value pairs of the blockchain data to be stored are obtained, the to-be-stored blockchain data can be The key-value key-value pair of the blockchain data is converted into the root node, intermediate node and leaf node on the above-mentioned logical tree structure; for example, in an example, the above-mentioned node device can carry a corresponding FDMT tree. Storage interface or storage service, the storage interface or storage service can specifically be used to convert the key-value key-value pair of the blockchain data to be stored into a node on the FDMT tree; After the key-value key-value pair of the blockchain data, the key-value of the blockchain data to be stored can be stored according to the tree structure of the FDMT tree shown in Figure 4 or Figure 5 by calling the storage interface or storage service. The value key-value pair is converted into the root node, intermediate node and leaf node in Figure 4 or Figure 5.
在将存储的区块链数据的key-value键值对转换成上述逻辑的树形结构上的根节点、中间节点和叶子节点之后,可以将这些根节点、中间节点和叶子节点以key-value键值对的形式存储在数据库中;例如,上述数据库通常是存储在上述节点设备上搭载的持久化存储介质(比如存储磁盘)中的;上述存储介质为与上述数据库对应的物理存储;在将上述FDMT树在数据库中进行存储时,具体可以通过执行commit命令,将上述FDMT树上的节点,以Key-Value键值对的形式,从节点设备的内存中,进一步写入承载上述数据库的存储介质。After the key-value key-value pairs of the stored blockchain data are converted into the root nodes, intermediate nodes and leaf nodes on the above-mentioned logical tree structure, these root nodes, intermediate nodes and leaf nodes can be converted into key-value The key-value pair is stored in the database; for example, the above-mentioned database is usually stored in a persistent storage medium (such as a storage disk) carried on the above-mentioned node device; the above-mentioned storage medium is the physical storage corresponding to the above-mentioned database; When the above-mentioned FDMT tree is stored in the database, specifically, by executing the commit command, the nodes on the above-mentioned FDMT tree can be further written into the storage carrying the above-mentioned database from the memory of the node device in the form of a Key-Value key-value pair. medium.
其中,上述数据库的具体类型,在本说明书中不进行特别限定,本领域技术人员可以基于实际的需求进行灵活的选择;在一种实现方式中,上述数据库,具体可以是Key-Value型数据库;例如,在一个例子中,上述数据库可以为采用多层存储结构的LevelDB数据库;或者,基于LevelDB架构的数据库;比如,Rocksdb数据库就是一种典型的基于LevelDB数据库架构的数据库。Wherein, the specific type of the above-mentioned database is not particularly limited in this specification, and those skilled in the art can flexibly choose based on actual needs; in an implementation manner, the above-mentioned database can be specifically a Key-Value type database; For example, in one example, the above database may be a LevelDB database using a multi-layer storage structure; or, a database based on a LevelDB architecture; for example, a Rocksdb database is a typical database based on a LevelDB database architecture.
上述FDMT树上的节点,在以Key-Value键值对的形式在上述数据库中进行存储时,上述Key-Value键值对的key,具体可以是上述FDMT树上的节点的节点ID;其中,上述节点ID具体可以包括能够唯一标识上述FDMT树上的节点的标识信息;例如,在一种实现方式中,上述节点ID具体可以是上述FDMT树上的节点包含的数据内容的hash值;在这种情况下,在需要查询上述FDMT树上的节点时,可以基于节点所包含的数据内容的hash值作为key来进行内容寻址。When the node on the above-mentioned FDMT tree is stored in the above-mentioned database in the form of a Key-Value key-value pair, the key of the above-mentioned Key-Value key-value pair may specifically be the node ID of the node on the above-mentioned FDMT tree; wherein, The above-mentioned node ID may specifically include identification information that can uniquely identify the node on the above-mentioned FDMT tree; for example, in an implementation manner, the above-mentioned node ID may specifically be the hash value of the data content contained in the node on the above-mentioned FDMT tree; in this In this case, when a node on the FDMT tree needs to be queried, content addressing can be performed based on the hash value of the data content contained in the node as a key.
在另一种实现方式中,上述节点ID具体也可以包括上述FDMT树上的节点在上述FDMT树中的路径信息;也即,将上述FDMT树上的节点在上述FDMT树中的路径信息作为该节点的节点ID;其中,上述路径信息具体可以包括,能够描述节点与其它节点之间的链接关系,以及节点在上述FDMT树上的位置的任意形式的信息;例如,请参见图8,图8为本说明书示出的一种为FDMT树上的节点设置节点ID的示意图;对于如图8所示包含三层Tree node的FDMT树,假设作为根节点的tree node的节点ID用0x00表示,那么图8示出的bucket node的节点ID,可以表示成0x00123456。In another implementation manner, the node ID may specifically include path information of the node on the FDMT tree in the FDMT tree; that is, the path information of the node on the FDMT tree in the FDMT tree is used as the The node ID of the node; wherein, the above-mentioned path information may specifically include information in any form that can describe the link relationship between the node and other nodes, and the position of the node on the above-mentioned FDMT tree; for example, please refer to FIG. 8, FIG. 8 A schematic diagram of setting a node ID for a node on the FDMT tree shown in this specification; for a FDMT tree containing a three-layer Tree node as shown in Figure 8, it is assumed that the node ID of the tree node as the root node is represented by 0x00, then The node ID of the bucket node shown in Figure 8 can be represented as 0x00123456.
其中,0x00为根节点的节点ID;123456是指上述bucket node在FDMT树上从根节点到该bucket node的路径信息;12表示第一层tree node的第一个block的第2个槽 位;34表示第二层tree node的第3个block的第4个槽位;56表示第三层tree node的第5个block的第6个槽位。Among them, 0x00 is the node ID of the root node; 123456 refers to the path information of the above bucket node from the root node to the bucket node in the FDMT tree; 12 refers to the second slot of the first block of the first layer tree node; 34 represents the 4th slot of the 3rd block of the second-level tree node; 56 represents the 6th slot of the 5th block of the third-level tree node.
基于该节点ID,可以明确该bucket node与其它node之间的链接关系,以及该bucket node在上述FDMT树上的具体位置;比如,基于该节点ID,可以明确该bucket node链接在第三层tree node的第5个block的第6个槽位;而第三层的tree node又链接在第二层tree node的第3个block的第4个槽位;第二层的tree node又进一步链接在第一层作为根节点的tree node的第1个block的第2个槽位。Based on the node ID, the link relationship between the bucket node and other nodes can be clarified, as well as the specific location of the bucket node on the above FDMT tree; for example, based on the node ID, it can be clarified that the bucket node is linked to the third-level tree The sixth slot of the fifth block of the node; and the tree node of the third layer is linked to the fourth slot of the third block of the second layer of the tree node; the tree node of the second layer is further linked in The first layer is the second slot of the first block of the tree node of the root node.
通过这种方式,可以在使用节点ID来检索FDMT树上存储的节点时,可以精确定位到该节点在FDMT树上所在的具体槽位。In this way, when a node stored in the FDMT tree is retrieved by using the node ID, the specific slot in the FDMT tree where the node is located can be precisely located.
在另一种实现方式中,上述节点ID具体也可以包括上述FDMT树上的节点在上述FDMT树中的相对位置,和该节点所包含的数据内容的hash值(此时该节点ID也可以作为该节点的hash标识);也即,将上述FDMT树上的节点在上述FDMT树中的相对位置,和该节点所包含的数据内容的hash值作为该节点的节点ID。In another implementation manner, the node ID may specifically include the relative position of the node on the FDMT tree in the FDMT tree, and the hash value of the data content contained in the node (at this time, the node ID can also be used as The hash identifier of the node); that is, the relative position of the node on the FDMT tree in the FDMT tree and the hash value of the data content contained in the node are used as the node ID of the node.
例如,在实现时,可以将节点在上述FDMT树中的相对位置,和该节点所包含的数据内容的hash值拼接生成的字符串,作为该节点的节点ID;当然,在实际应用中,在进行拼接的过程中,也可以进一步引入上述相对位置和上述hash值以外的其它类型的信息来生成节点ID;在本说明书中不再一一列举。For example, during implementation, the relative position of the node in the above-mentioned FDMT tree and the hash value of the data content contained in the node can be concatenated with the generated string as the node ID of the node; of course, in practical applications, in In the process of splicing, other types of information other than the above-mentioned relative position and the above-mentioned hash value can also be further introduced to generate a node ID; they will not be listed one by one in this specification.
通过这种方式,除了可以基于节点所包含的数据内容的hash值作为key来进行内容寻址以外,还可以在使用节点ID来检索FDMT树上存储的节点时,可以精确定位到该节点在FDMT树上所在的具体槽位。In this way, in addition to the content addressing based on the hash value of the data content contained in the node as the key, when the node ID is used to retrieve the node stored in the FDMT tree, the node can be precisely located in the FDMT The specific slot on the tree.
其中,上述节点设备上用于承载上述数据库的存储介质,具体可以是持久性存储介质;例如,可以是能够对数据进行持久性存储的磁盘、内存或者其它形式的存储介质,在本说明书中不再进行一一列举。Wherein, the storage medium used to carry the above-mentioned database on the above-mentioned node device may specifically be a persistent storage medium; for example, it may be a disk, memory or other forms of storage medium capable of persistently storing data, which is not described in this specification. List them one by one.
在本说明书中,在将上述FDMT树上的节点的key-value键值对分别写入上述数据库之前,还可以预先对上述FDMT树上的节点进行编码处理,然后将编码处理后的节点的key-value键值对在数据库中进行存储。In this specification, before the key-value pairs of the nodes on the FDMT tree are written into the database respectively, the nodes on the FDMT tree can also be encoded in advance, and then the key of the encoded node can be encoded. -value key-value pairs are stored in the database.
其中,由于上述FDMT树上的Tree node和Extend node均采用了,包含多个block,每一个block又进一步包含多个槽位的数据结构;因此,在本说明书中,在针对上述FDMT树进行编码时,可以针对上述FDMT树上的Tree node和Extend node中的block执行bitmap编码。Among them, since both the Tree node and Extend node on the above-mentioned FDMT tree are adopted, they contain multiple blocks, and each block further includes a data structure of multiple slots; therefore, in this specification, coding is performed for the above-mentioned FDMT tree. , bitmap encoding can be performed for the blocks in the Tree node and Extend node on the above FDMT tree.
在针对上述FDMT树上的Tree node和Extend node中的block(可以包括主block和子block)执行bitmap编码时,具体可以统计出该Tree node和Extend node中的block中的各槽位是否填充了hash值,然后再将统计结果利用特殊的编码字符表示出来得到bitmap编码信息,最后再将该bitmap编码信息添加至block中,完成针对该block的bitmap编码过程;例如,在一个例子中,上述bitmap编码信息,具体可以是一个用于标识block中的各槽位是否填充了hash值的16进制字符串;假设待编码的block(可以是主block,也可以是子block)共计包含16个槽位;在这16个槽位中第0位、第8位、第9位、第10位、第11位分别填充了hash值;则该block中各个槽位是否填充了hash的统计结果,可以用二进制字符串0000 1111 0000 0001表示;其中,该二进制字符串最左边是最高位第15位,最右边是最低位第0位;最后,可以将该二进制字符串转换成为16进制字符串0x0f01;此时该16进制字符串0x0f01即为该block的bitmap编码信息。When bitmap coding is performed on the blocks in the Tree node and Extend node (which may include main block and sub-block) on the above FDMT tree, it can be specifically calculated whether each slot in the block in the Tree node and Extend node is filled with hash. value, and then express the statistical results with special encoding characters to obtain bitmap encoding information, and finally add the bitmap encoding information to the block to complete the bitmap encoding process for the block; for example, in an example, the above bitmap encoding Information, which can be a hexadecimal string used to identify whether each slot in the block is filled with a hash value; it is assumed that the block to be encoded (can be a main block or a sub-block) contains a total of 16 slots ; The 0th, 8th, 9th, 10th, and 11th bits in the 16 slots are filled with hash values respectively; then whether each slot in the block is filled with the hash statistics, you can use The binary string 0000 1111 0000 0001 represents; the leftmost of the binary string is the highest 15th bit, and the rightmost is the lowest 0th bit; finally, the binary string can be converted into a hexadecimal string 0x0f01; At this time, the hexadecimal string 0x0f01 is the bitmap encoding information of the block.
其中,在针对上述FDMT树上的Tree node和Extend node中的block执行bitmap编码时,无论是主block还是子block,采用bitmap编码处理过程是完全相同的。Among them, when bitmap encoding is performed on the blocks in the Tree node and Extend node on the above-mentioned FDMT tree, whether it is the main block or the sub-block, the bitmap encoding process is exactly the same.
通过这种方式,由于编码后的上述FDMT树中的Tree node和Extend node包含的block中被添加了,能够指示该block中的各槽位是否填充了hash值的bitmap编码信息;因此,在需要查询数据库中存储的各Tree node中的block里填充的数据时,通过该block中的bitmap编码信息,就可以确定该block里的非空槽位,而不再需要遍历该block中的各个槽位,从而可以提升查找效率。In this way, since the blocks contained in the Tree node and Extend node in the encoded FDMT tree are added, it can indicate whether each slot in the block is filled with bitmap encoding information of the hash value; When querying the data filled in the block in each tree node stored in the database, the non-empty slot in the block can be determined through the bitmap encoding information in the block, and there is no need to traverse each slot in the block. , which can improve the search efficiency.
其中,由于上述FDMT树上的叶子节点采用了与Tree node和Extend node完全不 同的数据结构;因此,在对上述FDMT树上的叶子节点进行编码时,也可以采用与上述Tree node和Extend node完全不同的编码方式。Among them, because the leaf nodes on the above-mentioned FDMT tree use a completely different data structure from the Tree node and Extend node; therefore, when encoding the leaf nodes on the above-mentioned FDMT tree, it can also be completely different from the above-mentioned Tree node and Extend node. different encodings.
在示出的一种实施方式中,在针对上述FDMT树上的叶子节点进行编码时,具体仍然可以采用RLP(Recursive Length Prefix,递归长度前缀编码)编码;其中,RLP编码是如图1示出的MPT树常用的一种编码方式,其具体的编码过程,在本说明书中不再进行详述。In the illustrated embodiment, when encoding the leaf nodes on the above-mentioned FDMT tree, RLP (Recursive Length Prefix, recursive length prefix encoding) encoding can still be used; wherein, the RLP encoding is as shown in FIG. 1 . The MPT tree is a commonly used encoding method, and its specific encoding process will not be described in detail in this specification.
当然,在实际应用中,针对上述FDMT树上的叶子节点进行编码时所采用的编码方式,也可以是RLP编码以外的其它形式的编码方式,在实际应用中,可以灵活的选择,在本说明书中不再进行一一列举。Of course, in practical applications, the encoding method used when encoding the leaf nodes on the above-mentioned FDMT tree may also be encoding methods other than RLP encoding. In practical applications, it can be flexibly selected. will not be listed one by one.
在本说明书中,在针对上述FDMT树上的节点编码完成后,可以将上述FDMT树上的节点的key-value键值对存储至上述数据库。In this specification, after the encoding of the nodes on the FDMT tree is completed, the key-value pairs of the nodes on the FDMT tree may be stored in the database.
其中,在示出的一种实施方式中,对于上述FDMT树上的Tree node和Extend node而言,在将编码完成的Tree node和Extend node的key-value键值对存储到数据库之前,可以根据编码处理后的Tree node和Extend node中的block被添加的bitmap编码信息,来确定该block中未填充hash值的空槽位,然后将确定出的空槽位从该block中删除。Wherein, in the illustrated embodiment, for the Tree node and Extend node on the above-mentioned FDMT tree, before storing the encoded key-value key-value pair of the Tree node and Extend node in the database, it can be determined according to the The encoded bitmap information is added to the block in the Tree node and Extend node after encoding to determine the empty slots in the block that are not filled with hash values, and then delete the determined empty slots from the block.
通过这种方式,可以在将各Tree node和Extend nodekey-value键值对存储至数据库中时,删除各block中的空槽位,可以进一步节约将各Tree node和各Extend node存储至数据库时所占用的存储空间,提升存储效率。In this way, when the key-value pairs of each Tree node and Extend node are stored in the database, the empty slots in each block can be deleted, which can further save the time required for storing each Tree node and each Extend node in the database. Take up storage space and improve storage efficiency.
其中,对于编码后的block,在计算该block的hash值时,可以将编码后的block所包含的bitmap编码信息和非空字符槽位填充的hash值作为一个整体进行hash计算;当然,也可以将bitmap编码信息排除在外。Among them, for the encoded block, when calculating the hash value of the block, the bitmap encoding information contained in the encoded block and the hash value filled with the non-empty character slot can be used as a whole for hash calculation; of course, you can also Exclude bitmap encoding information.
在本说明书中,在将上述FDMT树上的节点key-value键值对分别写入上述数据库之后,如果上述FDMT树上写入的某一条区块链数据对应的value发生更新,此时可能需要对上述FDMT树上用于存储该区块链数据的字符后缀和value的叶子节点,从该叶子节点中分裂出的Extend node,以及用于存储该区块链数据的key的字符前缀的Tree node分别进行更新。In this specification, after the node key-value pairs on the above FDMT tree are written into the above database, if the value corresponding to a certain block chain data written in the above FDMT tree is updated, it may be necessary to For the leaf node on the above FDMT tree used to store the character suffix and value of the blockchain data, the Extend node split from the leaf node, and the tree node used to store the character prefix of the key of the blockchain data Update separately.
当然,如果用于存储该区块链数据的字符后缀和value的叶子节点没有发生过分裂,可以只需要对上述FDMT树上用于存储该区块链数据的字符后缀和value的叶子节点,以及用于存储该区块链数据的key的字符前缀的Tree node分别进行更新即可。Of course, if the leaf nodes used to store the character suffix and value of the blockchain data have not been split, it is only necessary to change the leaf nodes of the character suffix and value used to store the blockchain data on the above FDMT tree, and The tree node of the character prefix of the key used to store the blockchain data can be updated separately.
在这种情况下,节点设备可以在上述数据库中查找与上述需要数据更新的区块链数据对应的节点;其中,具体的查找方式不再赘述;再将查找到的节点从上述数据库读取到内存中,在内存中对这些节点进行修改更新,然后再将更新后的节点,进一步写入上述数据库对原有的更新节点进行更新。In this case, the node device can search the above-mentioned database for the node corresponding to the above-mentioned blockchain data that needs to be updated; wherein, the specific search method will not be repeated; and then read the found node from the above-mentioned database to In the memory, these nodes are modified and updated in the memory, and then the updated nodes are further written into the above database to update the original updated nodes.
例如,对上述FDMT树上发生数据更新的叶子节点进行更新,具体可以包括对该叶子节点中存储的上述区块链数据的value进行更新。在更新完成后,可以再重新计算该叶子节点的hash值,并基于该hash值与该节点上一层的节点进行重新链接。For example, updating the leaf node on the FDMT tree whose data is updated may specifically include updating the value of the blockchain data stored in the leaf node. After the update is completed, the hash value of the leaf node can be recalculated, and based on the hash value, it can be re-linked with the nodes in the upper layer of the node.
而对上述FDMT树上发生数据更新的叶子节点的上层的Extend node或者Tree node进行更新,具体可以包括对该Extend node或者Tree node中填充了该叶子节点的hash值的槽位进行更新;在更新完成后,可以再重新计算Extend node或者Tree node的hash值,并基于该hash值与该节点上一层的节点继续进行重新链接。And updating the Extend node or Tree node on the upper layer of the leaf node where the data update occurs on the above-mentioned FDMT tree may specifically include updating the slot in the Extend node or Tree node filled with the hash value of the leaf node; After completion, you can recalculate the hash value of the Extend node or Tree node, and continue to re-link with the node on the layer above the node based on the hash value.
在示出的一种实施方式中,针对上述FDMT树上的叶子节点的分裂判断及具体的节点分裂操作,可在重新计算该叶子节点的hash值,并基于该hash值与该叶子节点上一层的节点(可以是Tree node,也可以是Extend node)进行重新链接的阶段来完成。In the illustrated embodiment, for the splitting judgment of the leaf node on the FDMT tree and the specific node splitting operation, the hash value of the leaf node can be recalculated, and based on the hash value and the previous leaf node The node of the layer (which can be a Tree node or an Extend node) is re-linked.
在这种情况下,节点设备可以确定上述FDMT树上的叶子节点是否发生数据更新,如果上述FDMT树上的任一叶子节点发生数据更新,则节点设备可以在重新计算该叶子节点的hash值,并基于该hash值与该叶子节点上层的Tree node或者Extend node进行重新链接之前,进一步确定该叶子节点的存储容量是否满足节点分裂条件;如果该叶子节点的存储容量满足节点分裂条件,可以进一步从该叶子节点分裂出至少一个Extend node。In this case, the node device can determine whether the leaf node on the above-mentioned FDMT tree is updated with data, and if any leaf node on the above-mentioned FDMT tree is updated with data, the node device can recalculate the hash value of the leaf node, And based on the hash value, before relinking with the Tree node or Extend node on the upper layer of the leaf node, further determine whether the storage capacity of the leaf node meets the node splitting condition; if the storage capacity of the leaf node meets the node splitting condition, you can further from The leaf node is split into at least one Extend node.
例如,在一个例子中,在叶子节点的存储容量满足节点分裂条件时,为了快速降低叶子节点的存储容量,可以将该叶子节点分裂为,一个Extend node和多个叶子节点。For example, in an example, when the storage capacity of the leaf node satisfies the node splitting condition, in order to rapidly reduce the storage capacity of the leaf node, the leaf node may be split into one Extend node and multiple leaf nodes.
其中,从上述叶子节点中分裂出Extend node的分裂策略,在本说明书中也不进行特别限定,在实际应用中,用户可以根据具体的分裂需求,来进行自定义设置;在示出的一种实施方式中,上述分裂策略具体可以包括:将在当前的成块周期内写入叶子节点的最新的数据记录,从该叶子节点中分裂出去,并基于该最新的数据来额外创建Extend node和叶子节点。Among them, the splitting strategy for splitting the Extend node from the above-mentioned leaf nodes is not particularly limited in this specification. In practical applications, users can customize settings according to specific splitting requirements; in the one shown in the In an embodiment, the above-mentioned splitting strategy may specifically include: splitting the latest data record written into the leaf node in the current block cycle, splitting it from the leaf node, and additionally creating an Extend node and a leaf based on the latest data. node.
在这种情况下,在对任一目标叶子节点进行节点分裂时,可以确定在当前的成块周期内写入该目标叶子节点的最新的数据记录;再将这些最新的数据记录从该目标数据节点中删除,并从这些最新的数据记录所包含的字符后缀中分裂出字符前缀;例如,在一个例子中,默认可以将这些最新的数据记录的前两位分裂出去;或者,在这些最新的数据记录包含的字符后缀中存在共享字符前缀,并且该共享字符前缀的长度达到两位时,将该共享字符前缀分裂出去。In this case, when node splitting is performed on any target leaf node, the latest data records written to the target leaf node in the current block cycle can be determined; Delete the node from the node, and split the character prefix from the character suffix contained in these latest data records; for example, in one example, the first two digits of these latest data records can be split by default; or, in these latest data records If there is a shared character prefix in the character suffix included in the data record, and when the length of the shared character prefix reaches two digits, the shared character prefix is split.
然后,再进一步创建用于存储分裂出的该字符前缀的至少一Extend node,以及用于存储分裂出所述字符前缀之后的所述最新的数据记录的至少一叶子节点。Then, at least one Extend node for storing the split character prefix and at least one leaf node for storing the latest data record after splitting the character prefix are further created.
通过这种方式,由于可以将当前的成块周期内写入该目标叶子节点的最新的数据记录,从该目标叶子节点中删除,并基于这些删除的最新的数据记录重新创建至少一个Extend node和至少一个叶子节点作为分裂出去的节点;因此,对于该目标叶子节点而言,在其进行节点分裂之后,该目标叶子节点实际存储的数据记录,将与上一个成块周期该目标叶子节点存储的数据记录完全一致;该目标叶子节点的hash值相对于上一个成块周期不会发生任何变化。从而,当该目标叶子节点在当前的成块周期写入了新的区块链数据,导致该目标叶子节点的存储容量满足了节点分裂条件时,只需要将新写入的数据记录分裂出去重新创建额外的Extend node和叶子节点即可,而不再需要重新计算该目标叶子节点的hash值与上一层的节点重新进行重新链接;通过这种分裂方式,不仅可以保证满足节点分裂条件的叶子节点的hash值处于一个稳定的状态,而且可以减少重新计算该叶子节点的hash值的计算次数。In this way, since the latest data records written to the target leaf node in the current block cycle can be deleted from the target leaf node, and based on these deleted latest data records, at least one Extend node and At least one leaf node is used as a split node; therefore, for the target leaf node, after the node split is performed, the data records actually stored by the target leaf node will be the same as the data records stored by the target leaf node in the previous block cycle. The data records are completely consistent; the hash value of the target leaf node will not change from the previous block cycle. Therefore, when the target leaf node writes new blockchain data in the current block cycle, so that the storage capacity of the target leaf node satisfies the node splitting condition, it only needs to split the newly written data record and re-create it. It is enough to create additional Extend nodes and leaf nodes, and it is no longer necessary to recalculate the hash value of the target leaf node and relink the nodes of the previous layer; through this splitting method, not only the leaves that meet the node splitting conditions can be guaranteed The hash value of the node is in a stable state, and the number of times of recalculating the hash value of the leaf node can be reduced.
在示出的另一种实施方式中,上述分裂策略具体可以包括:将叶子节点存储的若干条数据记录所包含的字符后缀之间的共享字符前缀,从该叶子节点中分裂出去,并基于该共享字符前缀来额外创建Extend node。In another illustrated embodiment, the splitting strategy may specifically include: splitting the shared character prefixes between the character suffixes included in several data records stored by the leaf node from the leaf node, and splitting the shared character prefixes from the leaf node based on the Shared character prefixes to additionally create Extend nodes.
在这种情况下,在对任一目标叶子节点进行节点分裂时,可确定目标叶子节点存储的若干条数据记录所包含的字符后缀之间是否存在共享字符前缀;如果该目标叶子节点存储的若干条数据记录所包含的字符后缀之间存在共享字符前缀,可将该共享字符前缀从上述若干条数据记录中删除,并创建用于存储该共享字符前缀的至少一Extend node。In this case, when splitting any target leaf node, it can be determined whether there is a shared character prefix between the character suffixes contained in several data records stored by the target leaf node; If there is a shared character prefix between the character suffixes included in a data record, the shared character prefix can be deleted from the above-mentioned several data records, and at least one Extend node for storing the shared character prefix is created.
例如,由于上述Extend node也可以采用与Tree node相同的数据结构;因此,上述Extend node存储的字符,也可以是block代表的字符和block中填充了hash值的slot所代表的字符拼接起来的,长度为两位的字符串;则在目标叶子节点存储的若干条数据记录所包含的字符后缀之间存在共享字符前缀,并且该共享字符前缀的长度达到两位时,可以将该共享字符前缀从上述若干条数据记录中分裂出去。For example, since the above Extend node can also use the same data structure as the Tree node; therefore, the characters stored in the above Extend node can also be the characters represented by the block and the slot filled with the hash value in the block. A character string with a length of two digits; then there is a shared character prefix among the character suffixes contained in several data records stored in the target leaf node, and when the length of the shared character prefix reaches two digits, the shared character prefix can be changed from The above-mentioned several data records are split out.
在示出的一种实施方式中,针对上述FDMT上的Extend node的合并判断以及具体的节点合并操作,也可以在重新计算该Extend node的hash值,并基于该hash值与该Extend node上一层的节点进行重新链接的阶段来完成。In the illustrated embodiment, for the merging judgment of the Extend node on the above-mentioned FDMT and the specific node merging operation, the hash value of the Extend node can also be recalculated, and based on the hash value and the Extend node on the The nodes of the layer undergo a relinking phase to complete.
在这种情况下,节点设备可以确定上述FDMT树上的Extend node是否发生数据更新,如果上述FDMY树上的任一从叶子节点中分裂出的Extend node发生数据更新,则节点设备在重新计算该Extend node的hash值,并基于该hash值与该Extend node上层的节点进行重新链接之前,可以进一步确定该Extend node的存储容量是否满足节点合并条件;如果该Extend node的存储容量满足节点分裂条件,可以进一步将该Extend node,合并至与该Extend node链接的下一层的叶子节点。In this case, the node device can determine whether the data update occurs on the Extend node on the FDMT tree. If the data update occurs on any Extend node split from the leaf node on the FDMY tree, the node device recalculates the data update. The hash value of the Extend node, and before re-linking with the node on the upper layer of the Extend node based on the hash value, it can be further determined whether the storage capacity of the Extend node satisfies the node merging condition; if the storage capacity of the Extend node satisfies the node splitting condition, The Extend node can be further merged into the leaf node of the next layer linked with the Extend node.
例如,在实现时,首先可以确定该Extend node链接的下一层的叶子节点;比如,可以根据该Extend node包含的block中的非空slot中填充的hash值,来确定该Extend node链接的下一层的叶子节点;然后,可以将该Extend node存储的字符作为上述字符 后缀的一部分,写入确定出的该Extend node链接的下一层的叶子节点。For example, during implementation, the leaf node of the next layer of the link of the Extend node can be determined first; for example, the lower node of the link of the Extend node can be determined according to the hash value filled in the non-empty slot in the block contained in the Extend node. A leaf node of one layer; then, the character stored by the Extend node can be used as part of the above character suffix, and written to the determined leaf node of the next layer of the Extend node link.
在实际应用中,当一个叶子节点发生多次节点分裂时,此时该叶子节点可分裂出多层Extend node;在这种情况下,当任一Extend node满足节点合并条件,如果其下层节点仍然是Extend node,不是叶子节点,则该Extend node暂时无法进行节点合并;在这种情况下,可等待其下层的Extend node与更下层的叶子节点完成合并形成新的叶子节点之后,再与下层的该新的叶子节点进行二次合并,具体的合并方式不再赘述。In practical applications, when a leaf node is split multiple times, the leaf node can be split into multiple layers of Extend nodes; in this case, when any Extend node satisfies the node merging condition, if its lower nodes still is an Extend node, not a leaf node, the Extend node cannot be merged temporarily; in this case, you can wait for the lower Extend node and the lower leaf node to complete the merge to form a new leaf node, and then merge with the lower layer. The new leaf node is merged twice, and the specific merging method will not be described again.
以下以上述区块链数据为区块链账户对应的最新账户状态数据,上述区块链数据的key为区块链账户地址为例,对将上述区块链数据以key-value键值对的形式,写入采用如图4和图5所示的FDMT树的具体过程,进行详细描述。The following takes the above blockchain data as the latest account status data corresponding to the blockchain account, and the key of the above blockchain data is the blockchain account address as an example. Form, the writing adopts the specific process of the FDMT tree as shown in Figure 4 and Figure 5, which will be described in detail.
在实现时,接入区块链的用户客户端,可以将交易数据打包成区块链所支持的标准的交易格式,然后发布至区块链;而区块链中的节点设备,可以基于搭载的共识算法与其它节点设备一起,对用户客户端发布至区块链的这些交易进行共识,以此来为区块链产生最新区块;其中,具体的共识过程不再赘述。During implementation, the user client connected to the blockchain can package the transaction data into a standard transaction format supported by the blockchain, and then publish it to the blockchain; while the node devices in the blockchain can be based on the The consensus algorithm and other node devices, together with other node devices, agree on these transactions published by the user client to the blockchain, so as to generate the latest block for the blockchain; the specific consensus process will not be repeated.
区块链中的节点设备在执行了目标区块中的交易之后,区块链中与这些被执行的交易相关的目标账户的账户状态,通常也会随之发生变化;因此,节点设备在目标区块中的交易执行完毕后,可以获取上述目标账户发生账户更新后的最新账户状态数据(即目标区块中的交易执行后的账户状态),并将获取到的上述目标账户的最新账户状态数据处理成key-value键值对;其中,该key-value键值对的key为该目标账户的账户地址;该key-value键值对的value为该目标账户的最新账户状态。After the node device in the blockchain executes the transaction in the target block, the account status of the target account related to the executed transaction in the blockchain usually changes accordingly; therefore, the node device in the target After the transaction in the block is executed, the latest account status data of the target account after account update (that is, the account status after the transaction in the target block is executed) can be obtained, and the obtained latest account status of the target account can be obtained. The data is processed into key-value key-value pairs; wherein, the key of the key-value key-value pair is the account address of the target account; the value of the key-value key-value pair is the latest account status of the target account.
当将获取到的上述目标账户的最新账户状态数据处理成key-value键值对之后,可以将该key-value键值对转换成为上述FDMT树上的Tree node、Extend node和Leaf node,并将上述Tree node、Extend node和Leaf node的key-value键值对在数据库中进行存储。After the obtained latest account status data of the target account is processed into key-value key-value pairs, the key-value key-value pairs can be converted into Tree node, Extend node and Leaf node on the above FDMT tree, and the The key-value pairs of the above Tree node, Extend node and Leaf node are stored in the database.
请参见图9,图9为本说明书示出的一种将账户状态数据写入FDMT状态树的示意图;在图9示出的上述FDMT状态树中,前三层为Tree node,最后一层为叶子节点;其中,上述叶子节点可以采用以上描述的bucket数据桶的存储结构。各层的Tree node均包括主block和16个分别代表不同的16进制字符1~f的子block;并且,各子block进一步包括16个分别代表不同的16进制字符1~f的槽位。Please refer to Fig. 9, Fig. 9 is a schematic diagram of writing account state data into the FDMT state tree shown in this specification; in the above-mentioned FDMT state tree shown in Fig. 9, the first three layers are Tree nodes, and the last layer is Leaf node; wherein, the above-mentioned leaf node may adopt the storage structure of the bucket data bucket described above. The tree nodes of each layer include a main block and 16 sub-blocks representing different hexadecimal characters 1-f respectively; and each sub-block further includes 16 slots representing different hexadecimal characters 1-f respectively .
假设上述目标账户的账户地址为“a71135125”,最新的账户状态数据为“state1”;此时,该账户地址的字符前缀(Shared nibble)为“a71135”;字符后缀(key-end)为“125”。Suppose the account address of the above target account is "a71135125", and the latest account status data is "state1"; at this time, the character prefix (Shared nibble) of the account address is "a71135"; the character suffix (key-end) is "125" ".
在将该账户地址“a71135125”的账户状态数据“state1”以key-value键值对的形式写入上述FDMT树时,首先可以在数据库中定位该FDMT树上作为根节点的Tree node(比如根据区块头中填充的根节点的hash来定位根节点);如果是首次数据写入,根节点尚未创建,此时可以创建根节点;再从第一层的根节点Tree node1开始,依次在三层Tree node中确定与该账户地址的字符前缀“a71135”对应的字符槽位。如图9所示,与该账户地址的字符前缀“a71135”对应的字符槽位,具体包括:Tree node1的第11个子block(代表字符a)中的第8个槽位(代表字符7);Tree node2的第2个子block(代表字符1)中的第2个槽位(代表字符1);Tree node3的第4个子block(代表字符3)中的第6个槽位(代表字符5)。When the account state data "state1" of the account address "a71135125" is written into the above-mentioned FDMT tree in the form of key-value key-value pairs, the Tree node as the root node on the FDMT tree can be located in the database (for example, according to The hash of the root node filled in the block header is used to locate the root node); if the data is written for the first time and the root node has not been created, the root node can be created at this time; then start from the root node Tree node1 of the first layer, and in turn in the third layer Determine the character slot corresponding to the character prefix "a71135" of the account address in the Tree node. As shown in Figure 9, the character slot corresponding to the character prefix "a71135" of the account address specifically includes: the 8th slot (representing character 7) in the 11th sub-block (representing character a) of Tree node1; The second slot (representing character 1) in the second sub-block of Tree node2 (representing character 1); the sixth slot (representing character 5) in the fourth sub-block (representing character 3) of Tree node3.
在确定以上槽位后,可以在Tree node3的第4个子block的第6个槽位链接的bucket node中,写入由字符后缀“125”和状态数据“state1”构成的数据记录;当然,如果bucket node中已经存在与字符后缀“125”对应的数据记录,表明FMDT树上写入过上述账户地址“a71135125”的历史账户状态数据对应的value;此时可以将该数据记录中存储的Value更新为“state1”即可。After the above slots are determined, the data record consisting of the character suffix "125" and the state data "state1" can be written in the bucket node linked by the sixth slot of the fourth sub-block of Tree node3; of course, if There is already a data record corresponding to the character suffix "125" in the bucket node, indicating that the value corresponding to the historical account status data of the above account address "a71135125" has been written to the FMDT tree; at this time, the value stored in the data record can be updated It can be "state1".
数据写入完成后,可重新计算该bucket node包含的数据内容的hash值,将该hash值填充到Tree node3的第4个block的第6个槽位中,对该槽位原有的hash值进行更新。After the data writing is completed, the hash value of the data content contained in the bucket node can be recalculated, and the hash value can be filled into the sixth slot of the fourth block of Tree node3, and the original hash value of the slot to update.
进一步的,在将Tree node3的第4个block的第6个槽位中原有的hash值进行更新之后,再重新计算Tree node3的主block包含的数据内容的hash值,将该hash值填充到Tree node2的第2个block的第2个槽位,对该槽位原有的hash值进行更新。Further, after updating the original hash value in the sixth slot of the fourth block of Tree node3, recalculate the hash value of the data content contained in the main block of Tree node3, and fill the hash value into the Tree. In the second slot of the second block of node2, the original hash value of the slot is updated.
然后,在将Tree node2的第2个block的第2个槽位原有的hash值进行更新之后, 再重新计算Tree node2的主block包含的数据内容的hash值,将该hash值继续填充到Tree node1(即根节点)的第11个block的第8个槽位,对该槽位原有hash值进行更新。Then, after updating the original hash value of the second slot of the second block of Tree node2, recalculate the hash value of the data content contained in the main block of Tree node2, and continue to fill the hash value into the Tree. In the 8th slot of the 11th block of node1 (that is, the root node), the original hash value of the slot is updated.
当根节点Tree node1的第11个block的第8个槽位原有的hash值也更新完成后,此时再重新计算根节点Tree node1的主block包含的数据内容的hash值,并基于该hash值对区块头里存储的FDMT状态树的根节点的hash值进行更新。当区块头里存储的该FDMT状态树的根节点的hash值更新完成后,此时针对该FDMT状态树的更新完成,上述账户地址“a71135512”和对应的账户状态数据“state1”构成的key-value键值对,成功写入到FDMT状态树。When the original hash value of the 8th slot of the 11th block of the root node Tree node1 is also updated, the hash value of the data content contained in the main block of the root node Tree node1 is recalculated, and based on the hash value The value updates the hash value of the root node of the FDMT state tree stored in the block header. When the hash value of the root node of the FDMT state tree stored in the block header is updated, and the update of the FDMT state tree is completed at this time, the key- The value key-value pair is successfully written to the FDMT state tree.
以上述区块链数据为区块链账户对应的最新账户状态数据为例,仅为示例性的;在实际应用中,当上述区块链数据为以上描述的4种区块链数据的其它类型的区块链数据时,将其写入相应的FDMT树的具体过程,与以上述描述的实现过程类似,在本说明书中不再进行一一赘述。Taking the above-mentioned blockchain data as the latest account status data corresponding to the blockchain account as an example, it is only exemplary; in practical applications, when the above-mentioned blockchain data is other types of the four types of blockchain data described above When the block chain data is stored, the specific process of writing it into the corresponding FDMT tree is similar to the implementation process described above, and will not be repeated in this specification.
与上述方法实施例相对应,本申请还提供了装置的实施例。Corresponding to the above method embodiments, the present application also provides device embodiments.
与上述方法实施例相对应,本说明书还提供了一种区块链数据存储装置的实施例。Corresponding to the above method embodiments, this specification also provides an embodiment of a blockchain data storage device.
本说明书的区块链数据存储装置的实施例可以应用在电子设备上。装置实施例可以通过软件实现,也可以通过硬件或者软硬件结合的方式实现。以软件实现为例,作为一个逻辑意义上的装置,是通过其所在电子设备的处理器将非易失性存储器中对应的计算机程序指令读取到内存中运行形成的。The embodiments of the blockchain data storage device of this specification can be applied to electronic devices. The apparatus embodiment may be implemented by software, or may be implemented by hardware or a combination of software and hardware. Taking software implementation as an example, a device in a logical sense 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 the device is located.
从硬件层面而言,如图10所示,为本说明书的区块链数据存储装置所在电子设备的一种硬件结构图,除了图10所示的处理器、内存、网络接口、以及非易失性存储器之外,实施例中装置所在的电子设备通常根据该电子设备的实际功能,还可以包括其他硬件,对此不再赘述。From the perspective of hardware, as shown in FIG. 10, it is a hardware structure diagram of the electronic equipment where the blockchain data storage device of this specification is located, except for the processor, memory, network interface, and non-volatile shown in FIG. 10. In addition to the non-volatile memory, the electronic device in which the apparatus 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.
图11是本说明书一示例性实施例示出的一种区块链数据存储装置的框图。FIG. 11 is a block diagram of a blockchain data storage device shown in an exemplary embodiment of the present specification.
请参考图11,所述区块链数据存储装置110可以应用在前述图10所示的电子设备中,所述装置110包括:获取模块1101,获取待存储的区块链数据的key-value键值对;转换模块1102,将所述待存储的区块链数据的key-value键值对转换成逻辑的树形结构上的根节点、中间节点和叶子节点;所述根节点、中间节点包括多个用于存放所述区块链数据的key中的字符的位置,每个位置中包括多个用于存放所述区块链数据的key中的字符的槽位;所述槽位用于存储与该节点链接的下一层节点的hash值;存储模块1103,将所述根节点、中间节点和叶子节点的key-value键值对存储在数据库中;所述叶子节点、所述中间节点和所述根节点的key-value键值对中,value为节点的存储内容,key为节点的存储内容的hash值。Please refer to FIG. 11 , the blockchain data storage device 110 can be applied to the electronic equipment shown in the aforementioned FIG. 10 , and the device 110 includes: an acquisition module 1101 for acquiring the key-value key of the blockchain data to be stored value pair; the conversion module 1102 converts the key-value key-value pair of the blockchain data to be stored into a root node, an intermediate node and a leaf node on a logical tree structure; the root node and the intermediate node include A plurality of positions for storing characters in the key of the blockchain data, and each position includes a plurality of slots for storing characters in the key of the blockchain data; the slots are used for Store the hash value of the next layer node linked to the node; the storage module 1103 stores the key-value pairs of the root node, the intermediate node and the leaf node in the database; the leaf node, the intermediate node In the key-value key-value pair with the root node, the value is the storage content of the node, and the key is the hash value of the storage content of the node.
在本实施例中,所述根节点、中间节点的层数为固定值。In this embodiment, the number of layers of the root node and the intermediate node is a fixed value.
在本实施例中,所述根节点、中间节点用于存储所述区块链数据的key中的至少部分字符;所述根节点、中间节点存储的所述至少部分字符,为所述根节点、中间节点中的所述位置所代表的字符,与所述位置中填充了hash值的槽位所代表的字符,进行拼接生成的字符串。In this embodiment, the root node and the intermediate node are used to store at least part of the characters in the key of the blockchain data; the at least part of the characters stored by the root node and the intermediate node are the root node , The character string represented by the position in the intermediate node is spliced with the character represented by the slot filled with the hash value in the position.
在本实施例中,所述叶子节点为bucket数据桶;所述bucket数据桶包含若干条数据记录;所述数据记录中存储的数据内容包括所述区块链数据的value。In this embodiment, the leaf node is a bucket data bucket; the bucket data bucket contains several data records; the data content stored in the data record includes the value of the blockchain data.
在本实施例中,所述区块链数据的key对应的字符串包括字符前缀和字符后缀;所述根节点、中间节点包括多个用于存放所述字符前缀中的字符的位置,每个位置中包括多个用于存放所述字符前缀中的字符的槽位;所述数据记录中存储的数据内容包括所述字符后缀和所述区块链数据的value。In this embodiment, the character string corresponding to the key of the blockchain data includes a character prefix and a character suffix; the root node and the intermediate node include a plurality of locations for storing the characters in the character prefix, each The location includes a plurality of slots for storing characters in the character prefix; the data content stored in the data record includes the character suffix and the value of the blockchain data.
在本实施例中,所述根节点、中间节点包括的所述位置的数量,与所述位置包括的槽位的数量相同。In this embodiment, the number of the positions included in the root node and the intermediate node is the same as the number of slots included in the positions.
在本实施例中,所述根节点、中间节点包括分别代表不同的16进制字符的16个位置;所述位置包括16个分别代表不同的16进制字符的槽位。In this embodiment, the root node and the intermediate node include 16 positions that respectively represent different hexadecimal characters; the positions include 16 slots that respectively represent different hexadecimal characters.
在本实施例中,所述区块链数据包括以下示出的任一:区块中收录的交易;与所 述区块中收录的交易对应的交易收据;与所述区块链中的区块链账户对应的最新账户状态数据;智能合约账户的存储内容。In this embodiment, the blockchain data includes any one of the following: transactions included in the block; transaction receipts corresponding to transactions included in the block; The latest account status data corresponding to the blockchain account; the storage content of the smart contract account.
在本实施例中,所述逻辑的树形结构包括以下示出的任一:用于存储区块中收录的交易的交易树;用于存储与区块中收录的交易对应的交易收据的收据树;用于存储与所述区块链中的区块链账户对应的最新账户状态数据的状态树;用于存储智能合约账户的存储内容的存储树。In this embodiment, the logical tree structure includes any one of the following: a transaction tree for storing transactions included in the block; a receipt for storing transaction receipts corresponding to transactions included in the block tree; a state tree used to store the latest account state data corresponding to the blockchain account in the blockchain; a storage tree used to store the storage content of the smart contract account.
上述实施例阐明的系统、装置、模块或单元,具体可以由计算机芯片或实体实现,或者由具有某种功能的产品来实现。一种典型的实现设备为计算机,计算机的具体形式可以是个人计算机、膝上型计算机、蜂窝电话、相机电话、智能电话、个人数字助理、媒体播放器、导航设备、电子邮件收发设备、游戏控制台、平板计算机、可穿戴设备或者这些设备中的任意几种设备的组合。The systems, devices, modules or units described in the above embodiments may be specifically implemented by computer chips or entities, or by products with certain functions. A typical implementing device is a computer, which may be in the form of a personal computer, laptop computer, cellular phone, camera phone, smart phone, personal digital assistant, media player, navigation device, email sending and receiving device, game control desktop, tablet, wearable device, or a combination of any of these devices.
在一个典型的配置中,计算机包括一个或多个处理器(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 forms of non-persistent memory, random access memory (RAM) and/or non-volatile memory in computer readable media, such as read only memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium.
计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。计算机的存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器(CD-ROM)、数字多功能光盘(DVD)或其他光学存储、磁盒式磁带、磁盘存储、量子存储器、基于石墨烯的存储介质或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。按照本文中的界定,计算机可读介质不包括暂存电脑可读媒体(transitory media),如调制的数据信号和载波。Computer-readable media includes both persistent and non-permanent, removable and non-removable media, and storage of information may be implemented by any method or technology. Information may be computer readable instructions, data structures, modules of programs, 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 tape cartridges, disk storage, quantum memory, graphene-based storage media or other magnetic storage devices or any other non-transmission media can be used to store information that can be accessed by computing devices. As defined herein, computer-readable media does not include transitory computer-readable media, such as modulated data signals and carrier waves.
术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、商品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、商品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、商品或者设备中还存在另外的相同要素。The terms "comprising", "comprising" or any other variation thereof are intended to encompass non-exclusive inclusion such that a process, method, article or device comprising a list of elements includes not only those elements, but also other not expressly listed elements, or also include elements inherent to such a process, method, commodity or device. Without further limitation, an element qualified by the phrase "comprising a..." does not preclude the presence of additional identical elements in the process, method, article of manufacture, or device that includes the element.
上述对本说明书特定实施例进行了描述。其它实施例在所附权利要求书的范围内。在一些情况下,在权利要求书中记载的动作或步骤可以按照不同于实施例中的顺序来执行并且仍然可以实现期望的结果。另外,在附图中描绘的过程不一定要求示出的特定顺序或者连续顺序才能实现期望的结果。在某些实施方式中,多任务处理和并行处理也是可以的或者可能是有利的。The foregoing describes specific embodiments of the present specification. Other embodiments are within the scope of the appended 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. Additionally, the processes depicted in the figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
在本说明书一个或多个实施例使用的术语是仅仅出于描述特定实施例的目的,而非旨在限制本说明书一个或多个实施例。在本说明书一个或多个实施例和所附权利要求书中所使用的单数形式的“一种”、“所述”和“该”也旨在包括多数形式,除非上下文清楚地表示其他含义。还应当理解,本文中使用的术语“和/或”是指并包含一个或多个相关联的列出项目的任何或所有可能组合。The terminology used in one or more embodiments of this specification is for the purpose of describing a particular embodiment only and is not intended to limit the one or more embodiments of this specification. As used in the specification or embodiments and the appended claims, the singular forms "a," "the," and "the" are intended to include the plural forms as well, unless the context clearly dictates otherwise. It will 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 will be understood that although the terms first, second, third, etc. may be used in this specification to describe various information, such information should not be limited by these terms. These terms are only used to distinguish the same type of information from each other. For example, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information without departing from the scope of one or more embodiments of the present specification. Depending on the context, the word "if" as used herein can be interpreted as "at the time of" or "when" or "in response to determining."
以上所述仅为本说明书一个或多个实施例的较佳实施例而已,并不用以限制本说明书一个或多个实施例,凡在本说明书一个或多个实施例的精神和原则之内,所做的任何修改、等同替换、改进等,均应包含在本说明书一个或多个实施例保护的范围之内。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. All within the spirit and principles of one or more embodiments of this specification, Any modifications, equivalent replacements, improvements, etc. made should be included within the protection scope of one or more embodiments of this specification.

Claims (20)

  1. 一种区块链中存储数据的方法,包括:A method of storing data in a blockchain, comprising:
    获取待存储的区块链数据的key-value键值对;Obtain the key-value key-value pair of the blockchain data to be stored;
    将所述待存储的区块链数据的key-value键值对转换成逻辑的树形结构上的根节点、中间节点和叶子节点;所述根节点、中间节点包括多个用于存放所述区块链数据的key中的字符的位置,每个位置中包括多个用于存放所述区块链数据的key中的字符的槽位;所述槽位用于存储与该节点链接的下一层节点的hash值;Convert the key-value key-value pair of the blockchain data to be stored into a root node, an intermediate node and a leaf node on a logical tree structure; the root node and the intermediate node include a plurality of nodes for storing the The position of the characters in the key of the blockchain data, and each position includes a plurality of slots for storing the characters in the key of the blockchain data; The hash value of a layer of nodes;
    将所述根节点、中间节点和叶子节点的key-value键值对存储在数据库中;所述叶子节点、所述中间节点和所述根节点的key-value键值对中,value为节点的存储内容,key为节点的存储内容的hash值。The key-value key-value pairs of the root node, the intermediate node and the leaf node are stored in the database; in the key-value key-value pairs of the leaf node, the intermediate node and the root node, the value is the value of the node. Storage content, the key is the hash value of the storage content of the node.
  2. 根据权利要求1所述的方法,所述根节点、中间节点的层数为固定值。The method according to claim 1, wherein the number of layers of the root node and the intermediate node is a fixed value.
  3. 根据权利要求1所述的方法,所述根节点、中间节点用于存储所述区块链数据的key中的至少部分字符;所述根节点、中间节点存储的所述至少部分字符,为所述根节点、中间节点中的所述位置所代表的字符,与所述位置中填充了hash值的槽位所代表的字符,进行拼接生成的字符串。The method according to claim 1, wherein the root node and the intermediate node are used to store at least part of the characters in the key of the blockchain data; the at least part of the characters stored by the root node and the intermediate node are the The character string represented by the position in the root node and the intermediate node and the character represented by the slot filled with the hash value in the position are spliced to generate a string.
  4. 根据权利要求3所述的方法,所述叶子节点为bucket数据桶;所述bucket数据桶包含若干条数据记录;所述数据记录中存储的数据内容包括所述区块链数据的value。The method according to claim 3, wherein the leaf node is a bucket data bucket; the bucket data bucket contains several data records; and the data content stored in the data record includes the value of the blockchain data.
  5. 根据权利要求4所述的方法,所述区块链数据的key对应的字符串包括字符前缀和字符后缀;所述根节点、中间节点包括多个用于存放所述字符前缀中的字符的位置,每个位置中包括多个用于存放所述字符前缀中的字符的槽位;所述数据记录中存储的数据内容包括所述字符后缀和所述区块链数据的value。The method according to claim 4, wherein the character string corresponding to the key of the blockchain data includes a character prefix and a character suffix; the root node and the intermediate node include a plurality of positions for storing the characters in the character prefix , each position includes a plurality of slots for storing the characters in the character prefix; the data content stored in the data record includes the character suffix and the value of the blockchain data.
  6. 根据权利要求1所述的方法,所述根节点、中间节点包括的所述位置的数量,与所述位置包括的槽位的数量相同。The method according to claim 1, wherein the number of the positions included in the root node and the intermediate node is the same as the number of slots included in the positions.
  7. 根据权利要求6所述的方法,所述根节点、中间节点包括分别代表不同的16进制字符的16个位置;所述位置包括16个分别代表不同的16进制字符的槽位。The method according to claim 6, wherein the root node and the intermediate node comprise 16 positions respectively representing different hexadecimal characters; the positions comprise 16 slots respectively representing different hexadecimal characters.
  8. 根据权利要求1所述的方法,所述区块链数据包括以下示出的任一:The method of claim 1, the blockchain data comprising any of the following:
    区块中收录的交易;Transactions included in the block;
    与所述区块中收录的交易对应的交易收据;A transaction receipt corresponding to the transaction recorded in the block;
    与所述区块链中的区块链账户对应的最新账户状态数据;the latest account status data corresponding to the blockchain account in the blockchain;
    智能合约账户的存储内容。The storage content of the smart contract account.
  9. 根据权利要求8所述的方法,所述逻辑的树形结构包括以下示出的任一:The method of claim 8, the logical tree structure comprising any of the following:
    用于存储区块中收录的交易的交易树;The transaction tree used to store the transactions included in the block;
    用于存储与区块中收录的交易对应的交易收据的收据树;A receipt tree for storing transaction receipts corresponding to transactions included in the block;
    用于存储与所述区块链中的区块链账户对应的最新账户状态数据的状态树;A state tree for storing the latest account state data corresponding to the blockchain account in the blockchain;
    用于存储智能合约账户的存储内容的存储树。The storage tree used to store the storage contents of smart contract accounts.
  10. 一种区块链中存储数据的装置,包括:A device for storing data in a blockchain, comprising:
    获取模块,获取待存储的区块链数据的key-value键值对;The acquisition module obtains the key-value key-value pair of the blockchain data to be stored;
    转换模块,将所述待存储的区块链数据的key-value键值对转换成逻辑的树形结构上的根节点、中间节点和叶子节点;所述根节点、中间节点包括多个用于存放所述区块链数据的key中的字符的位置,每个位置中包括多个用于存放所述区块链数据的key中的字符的槽位;所述槽位用于存储与该节点链接的下一层节点的hash值;A conversion module, which converts the key-value key-value pair of the blockchain data to be stored into a root node, an intermediate node and a leaf node on a logical tree structure; the root node and the intermediate node include a plurality of The positions of the characters in the keys of the blockchain data, each of which includes a plurality of slots for storing the characters in the keys of the blockchain data; the slots are used to store the The hash value of the next layer node of the link;
    存储模块,将所述根节点、中间节点和叶子节点的key-value键值对存储在数据库中;所述叶子节点、所述中间节点和所述根节点的key-value键值对中,value为节点的存储内容,key为节点的存储内容的hash值。The storage module stores the key-value key-value pairs of the root node, the intermediate node and the leaf node in the database; in the key-value key-value pairs of the leaf node, the intermediate node and the root node, value is the storage content of the node, and the key is the hash value of the storage content of the node.
  11. 根据权利要求10所述的装置,所述根节点、中间节点的层数为固定值。The device according to claim 10, wherein the number of layers of the root node and the intermediate node is a fixed value.
  12. 根据权利要求10所述的装置,所述根节点、中间节点用于存储所述区块链数据的key中的至少部分字符;所述根节点、中间节点存储的所述至少部分字符,为所述根节点、中间节点中的所述位置所代表的字符,与所述位置中填充了hash值的槽位所代表的字符,进行拼接生成的字符串。The device according to claim 10, wherein the root node and the intermediate node are used to store at least part of the characters in the key of the blockchain data; the at least part of the characters stored by the root node and the intermediate node are the The character string represented by the position in the root node and the intermediate node and the character represented by the slot filled with the hash value in the position are spliced together to generate a character string.
  13. 根据权利要求12所述的装置,所述叶子节点为bucket数据桶;所述bucket数据桶包含若干条数据记录;所述数据记录中存储的数据内容包括所述区块链数据的value。The device according to claim 12, wherein the leaf node is a bucket data bucket; the bucket data bucket contains several data records; and the data content stored in the data record includes the value of the blockchain data.
  14. 根据权利要求13所述的装置,所述区块链数据的key对应的字符串包括字符前缀和字符后缀;所述根节点、中间节点包括多个用于存放所述字符前缀中的字符的位置,每个位置中包括多个用于存放所述字符前缀中的字符的槽位;所述数据记录中存储的数据内容包括所述字符后缀和所述区块链数据的value。The device according to claim 13, wherein the character string corresponding to the key of the blockchain data includes a character prefix and a character suffix; the root node and the intermediate node include a plurality of locations for storing characters in the character prefix , each position includes a plurality of slots for storing the characters in the character prefix; the data content stored in the data record includes the character suffix and the value of the blockchain data.
  15. 根据权利要求10所述的装置,所述根节点、中间节点包括的所述位置的数量,与所述位置包括的槽位的数量相同。The device according to claim 10, wherein the number of the positions included in the root node and the intermediate node is the same as the number of slots included in the positions.
  16. 根据权利要求15所述的装置,所述根节点、中间节点包括分别代表不同的16进制字符的16个位置;所述位置包括16个分别代表不同的16进制字符的槽位。The device according to claim 15, wherein the root node and the intermediate node comprise 16 positions respectively representing different hexadecimal characters; the positions comprise 16 slots respectively representing different hexadecimal characters.
  17. 根据权利要求10所述的装置,所述区块链数据包括以下示出的任一:The apparatus of claim 10, the blockchain data comprising any of the following:
    区块中收录的交易;Transactions included in the block;
    与所述区块中收录的交易对应的交易收据;A transaction receipt corresponding to the transaction recorded in the block;
    与所述区块链中的区块链账户对应的最新账户状态数据;the latest account status data corresponding to the blockchain account in the blockchain;
    智能合约账户的存储内容。The storage content of the smart contract account.
  18. 根据权利要求17所述的装置,所述逻辑的树形结构包括以下示出的任一:The apparatus of claim 17, the logical tree structure comprising any of the following:
    用于存储区块中收录的交易的交易树;The transaction tree used to store the transactions included in the block;
    用于存储与区块中收录的交易对应的交易收据的收据树;A receipt tree for storing transaction receipts corresponding to transactions included in the block;
    用于存储与所述区块链中的区块链账户对应的最新账户状态数据的状态树;A state tree for storing the latest account state data corresponding to the blockchain account in the blockchain;
    用于存储智能合约账户的存储内容的存储树。The storage tree used to store the storage contents of smart contract accounts.
  19. 一种电子设备,包括:An electronic device comprising:
    处理器;processor;
    用于存储处理器可执行指令的存储器;memory for storing processor-executable instructions;
    其中,所述处理器通过运行所述可执行指令以实现如权利要求1-9中任一项所述的方法。Wherein, the processor implements the method of any one of claims 1-9 by executing the executable instructions.
  20. 一种计算机可读存储介质,其上存储有计算机指令,该指令被处理器执行时实现如权利要求1-9中任一项所述方法的步骤。A computer-readable storage medium having computer instructions stored thereon which, when executed by a processor, implement the steps of the method of any one of claims 1-9.
PCT/CN2022/090294 2021-05-07 2022-04-29 Block chain data storage method and apparatus, and electronic device WO2022233274A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202110495070.9A CN112988910B (en) 2021-05-07 2021-05-07 Block chain data storage method and device and electronic equipment
CN202110495070.9 2021-05-07

Publications (1)

Publication Number Publication Date
WO2022233274A1 true WO2022233274A1 (en) 2022-11-10

Family

ID=76337213

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/090294 WO2022233274A1 (en) 2021-05-07 2022-04-29 Block chain data storage method and apparatus, and electronic device

Country Status (2)

Country Link
CN (1) CN112988910B (en)
WO (1) WO2022233274A1 (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112988910B (en) * 2021-05-07 2021-09-24 支付宝(杭州)信息技术有限公司 Block chain data storage method and device and electronic equipment

Citations (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20160335299A1 (en) * 2015-05-11 2016-11-17 Apple Inc. Hierarchical Data Storage
CN110334154A (en) * 2019-06-28 2019-10-15 阿里巴巴集团控股有限公司 Based on the classification storage method and device of block chain, electronic equipment
CN111488614A (en) * 2020-04-08 2020-08-04 北京瑞策科技有限公司 Digital identity storage method and device based on service data block chain
CN111837115A (en) * 2019-07-11 2020-10-27 创新先进技术有限公司 Shared blockchain data storage
CN112905607A (en) * 2021-05-07 2021-06-04 支付宝(杭州)信息技术有限公司 Block chain data storage method and device and electronic equipment
CN112988761A (en) * 2021-05-07 2021-06-18 支付宝(杭州)信息技术有限公司 Block chain data storage method and device and electronic equipment
CN112988911A (en) * 2021-05-07 2021-06-18 支付宝(杭州)信息技术有限公司 Block chain data storage method and device and electronic equipment
CN112988908A (en) * 2021-05-07 2021-06-18 支付宝(杭州)信息技术有限公司 Block chain data storage method and device and electronic equipment
CN112988910A (en) * 2021-05-07 2021-06-18 支付宝(杭州)信息技术有限公司 Block chain data storage method and device and electronic equipment
CN112988909A (en) * 2021-05-07 2021-06-18 支付宝(杭州)信息技术有限公司 Block chain data storage method and device and electronic equipment
CN112988912A (en) * 2021-05-07 2021-06-18 支付宝(杭州)信息技术有限公司 Block chain data storage method and device and electronic equipment
CN113220685A (en) * 2021-05-11 2021-08-06 支付宝(杭州)信息技术有限公司 Traversal method and device for intelligent contract storage content and electronic equipment

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108446376B (en) * 2018-03-16 2022-04-08 众安信息技术服务有限公司 Data storage method and device
JP6830549B2 (en) * 2019-03-04 2021-02-17 アドバンスド ニュー テクノロジーズ カンパニー リミテッド Blockchain World State Markle Patricia Trie (WORLD STATE MERKLE PATRICIA TRIE) Subtsu
CN110275884B (en) * 2019-05-31 2020-08-04 阿里巴巴集团控股有限公司 Data storage method and node
CN112102840A (en) * 2020-09-09 2020-12-18 中移(杭州)信息技术有限公司 Semantic recognition method, device, terminal and storage medium
CN112632077A (en) * 2020-12-28 2021-04-09 深圳壹账通智能科技有限公司 Data storage method, device, equipment and storage medium based on redis

Patent Citations (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20160335299A1 (en) * 2015-05-11 2016-11-17 Apple Inc. Hierarchical Data Storage
CN110334154A (en) * 2019-06-28 2019-10-15 阿里巴巴集团控股有限公司 Based on the classification storage method and device of block chain, electronic equipment
CN111837115A (en) * 2019-07-11 2020-10-27 创新先进技术有限公司 Shared blockchain data storage
CN111488614A (en) * 2020-04-08 2020-08-04 北京瑞策科技有限公司 Digital identity storage method and device based on service data block chain
CN112988911A (en) * 2021-05-07 2021-06-18 支付宝(杭州)信息技术有限公司 Block chain data storage method and device and electronic equipment
CN112988761A (en) * 2021-05-07 2021-06-18 支付宝(杭州)信息技术有限公司 Block chain data storage method and device and electronic equipment
CN112905607A (en) * 2021-05-07 2021-06-04 支付宝(杭州)信息技术有限公司 Block chain data storage method and device and electronic equipment
CN112988908A (en) * 2021-05-07 2021-06-18 支付宝(杭州)信息技术有限公司 Block chain data storage method and device and electronic equipment
CN112988910A (en) * 2021-05-07 2021-06-18 支付宝(杭州)信息技术有限公司 Block chain data storage method and device and electronic equipment
CN112988909A (en) * 2021-05-07 2021-06-18 支付宝(杭州)信息技术有限公司 Block chain data storage method and device and electronic equipment
CN112988912A (en) * 2021-05-07 2021-06-18 支付宝(杭州)信息技术有限公司 Block chain data storage method and device and electronic equipment
CN114153848A (en) * 2021-05-07 2022-03-08 支付宝(杭州)信息技术有限公司 Block chain data storage method and device and electronic equipment
CN113220685A (en) * 2021-05-11 2021-08-06 支付宝(杭州)信息技术有限公司 Traversal method and device for intelligent contract storage content and electronic equipment

Also Published As

Publication number Publication date
CN112988910A (en) 2021-06-18
CN112988910B (en) 2021-09-24

Similar Documents

Publication Publication Date Title
TWI731595B (en) Block chain state data storage method and device, and electronic equipment
TWI732463B (en) Block chain state data recovery method and device, and electronic equipment
TWI737157B (en) Block chain-based hierarchical storage method and device, and electronic equipment
WO2021017436A1 (en) Blockchain state data synchronization method and apparatus, and electronic device
TWI737152B (en) Block chain-based hierarchical storage method and device, and electronic equipment
US11113272B2 (en) Method and apparatus for storing blockchain state data and electronic device
WO2022237596A1 (en) Traversal method and apparatus for smart contract storage content, and electronic device
WO2020258856A1 (en) Hierarchical storage method and apparatus based on blockchain, and electronic device
CN112988912B (en) Block chain data storage method and device and electronic equipment
CN112988761B (en) Block chain data storage method and device and electronic equipment
CN112988909B (en) Block chain data storage method and device and electronic equipment
CN112988908B (en) Block chain data storage method and device and electronic equipment
WO2022233274A1 (en) Block chain data storage method and apparatus, and electronic device
CN114706848A (en) Block chain data storage, updating and reading method and device and electronic equipment
WO2024021419A1 (en) Blockchain data storage method and apparatus, and electronic device
CN112988911B (en) Block chain data storage method and device and electronic equipment
CN112905607B (en) Block chain data storage method and device and electronic equipment
CN111488607A (en) Data processing method and device for service data block chain
CN106407345A (en) Method and apparatus for updating dirty data
CN111695136A (en) Method and system for realizing service data block chain
CN115982781A (en) Method for creating account in block chain and block chain link point
CN116188160A (en) Method and block link point for executing transaction in block chain system

Legal Events

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

Ref document number: 22798615

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE