Method and system for linking tree structures of blocks of different versions

By using n-ary tree structure and pointers to link different versions of blocks in the blockchain, the problem of the traditional B+ tree structure's non-unique tree shape and insufficient SPV verification capability is solved, and the steady-state storage and storage of blockchain data are realized. Decentralized management provides the ability for simple payment verification.

CN118568176APending Publication Date: 2024-08-30ANT BLOCKCHAIN TECHNOLOGY (SHANGHAI) CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202410707863.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-31
Publication Date
2024-08-30

AI Technical Summary

Technical Problem

The traditional B+ tree structure in the blockchain is not unique during insertion and deletion operations, cannot provide Simple Payment Verification (SPV) proof, and cannot effectively manage the decentralized nature of the blockchain.

Method used

Adopting an n-ary tree structure, the tree structure of different versions of blocks is linked through pointers to ensure tree stability, and state key-values ​​are inserted in leaf nodes in order, and non-leaf nodes are set according to characteristic values ​​to provide SPV verification capabilities.

Benefits of technology

It realizes the steady-state storage and SPV verification of blockchain data, improves the decentralized management capabilities of the blockchain, and ensures the uniqueness and verifiability of data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118568176A
    Figure CN118568176A
Patent Text Reader

Abstract

The method for linking the tree structures of the blocks of different versions comprises the step of linking the same tree nodes in the version updated to the value last time in the tree structure of the block of the next version by adopting a pointer in the tree structure of the block of the next version, wherein the tree nodes in the tree structure of the block of the next version are not changed relative to the tree nodes in the previous version. The tree structure is an n-way tree, the state key-value is inserted into leaf nodes of the bottommost layer of the n-way tree according to a key sequence, and non-leaf nodes are set according to feature values of the keys.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of this specification belong to the field of blockchain technology, and more particularly to a method and system for linking a tree structure of blocks of different versions. Background Art

[0002] Blockchain is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. In the blockchain system, data blocks are combined into a chain data structure in a sequential manner according to time sequence, and a distributed ledger that cannot be tampered with or forged is guaranteed by cryptography. Due to the characteristics of blockchain such as decentralization, information cannot be tampered with, and autonomy, blockchain has also received more and more attention and application. Summary of the invention

[0003] The object of the present invention is to provide a method and system for generating an n-ary tree, comprising:

[0004] A method for linking tree structures of different versions of blocks, comprising:

[0005] For tree nodes in the tree structure of the later version block that have not changed relative to the previous version, pointers are used in the tree structure of the later version block to link to the same tree nodes in the version that was last updated to that value;

[0006] The tree structure is an n-ary tree, and the state key-value is inserted into the leaf node at the bottom layer of the n-ary tree in the order of the key, and the non-leaf node is set according to the characteristic value of the key.

[0007] A system for generating an n-ary tree, comprising:

[0008] processor;

[0009] and a memory in which a program is stored, wherein when the processor executes the program, the operations of any one of claims 1 to 8 are performed.

[0010] A storage medium for storing a program, wherein when the program is executed, the operation of any one of claims 1 to 8 is performed.

[0011] In the above embodiment, since the characteristic value of the key obtained is certain, and the rule for setting the non-leaf node according to the characteristic value is certain, and the inserted key-value is inserted into the leaf node of the bottom layer 0 of the n-ary tree in the order of the key, these operations are not related to the order of insertion. Therefore, no matter what the insertion order is, the tree shape of the generated n-ary tree is certain and unique, that is, it has a steady state. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] In order to more clearly illustrate the technical solutions of the embodiments of this specification, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0013] Figure 1 is a schematic diagram of creating a smart contract in one embodiment;

[0014] Figure 2 is a schematic diagram of calling a smart contract in one embodiment;

[0015] Figure 3 is a schematic diagram of a blockchain structure in one embodiment;

[0016] Figure 4 is a flow chart of a blockchain structure in one embodiment;

[0017] Figure 5 is a schematic diagram of an MPT tree structure in one embodiment;

[0018] Figure 6 is a schematic diagram of an MPT tree structure in one embodiment;

[0019] Figure 7 is a schematic diagram of a simple payment verification principle in one embodiment;

[0020] Figure 8 is a schematic diagram of the underlying data structure of a B-tree in one embodiment;

[0021] Fig. 9 is a schematic diagram of the underlying data structure of a B-tree in one embodiment;

[0022] Fig.10 is a schematic diagram of the underlying data structure of a B+ tree in one embodiment;

[0023] Fig.11 is a schematic diagram illustrating a B+ tree steady state problem in one embodiment;

[0024] Fig.12 is a schematic diagram illustrating a B+ tree steady state problem in one embodiment;

[0025] Fig.13 is a flow chart of a method for generating an n-ary tree in one embodiment;

[0026] Fig.14 is a schematic diagram of a virtual machine executing a smart contract in one embodiment;

[0027] Fig.15 This is a structural diagram of a binary tree in one embodiment;

[0028] Fig.16 This is a structural diagram of a binary tree in one embodiment;

[0029] Fig.17 This is a structural diagram of a binary tree in one embodiment;

[0030] Fig.18 is a diagram of the Ethereum block structure in one embodiment;

[0031] Fig.19 This is a structural diagram of the link relationship between the previous and next version blocks in one embodiment;

[0032] Fig. 20 This is a structural diagram of the link relationship between the previous and next version blocks in one embodiment;

[0033] Fig.21 This is a structural diagram of the link relationship between multiple previous and next version blocks in one embodiment. DETAILED DESCRIPTION

[0034] In order to enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below in conjunction with the drawings in the embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this specification, not all of the embodiments. Based on the embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this specification.

[0035] Blockchain is generally divided into three types: public blockchain, private blockchain and consortium blockchain. In addition, there are many types of combinations, such as private blockchain + consortium blockchain, consortium blockchain + public blockchain and other different combinations. Among them, the public chain has the highest degree of decentralization. Public chains are represented by Bitcoin and Ethereum. Participants who join the public chain can read data records on the chain, participate in transactions, and compete for the right to record new blocks. Moreover, each participant (reflected as the participant's node on the blockchain) can freely join and exit the network and perform related operations. On the contrary, the private chain has the write permission of the network controlled by a certain organization or institution, and the data reading permission is stipulated by the organization. In short, the private chain can be a weakly centralized system with strictly limited and few participating nodes. This type of blockchain is more suitable for use within a specific organization. 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; participants join the network through authorization and form a stakeholder alliance to jointly maintain the operation of the blockchain.

[0036] Like public chains, private chains and consortium chains, in addition to supporting the transfer of native assets on the blockchain between accounts, such as the transfer of Bitcoin and Ethereum, some blockchains can also provide smart contract functions. Smart contracts on the blockchain are contracts that can be triggered and executed by transactions on the blockchain system. Smart contracts can be defined in the form of code.

[0037] Taking Ethereum as an example, supporting users to create and call some complex logic in the Ethereum network is the biggest challenge that distinguishes Ethereum from Bitcoin blockchain technology. The core of Ethereum as a programmable blockchain is the Ethereum Virtual Machine (EVM), and each Ethereum node can run EVM. EVM is a Turing-complete virtual machine, which means that various complex logics can be implemented through it. Users publish and call smart contracts in Ethereum on EVM. Through EVM, the differences in the hardware configuration and software environment of each node can be shielded to ensure that the process and results of executing smart contracts on each node are the same. In fact, the virtual machine directly runs the virtual machine code (virtual machine bytecode, hereinafter referred to as "bytecode"). Smart contracts deployed on the blockchain can be in the form of bytecode.

[0038] For example Figure 1 As shown in the figure, after Bob sends a transaction containing the information of creating a smart contract to the Ethereum network, the EVM of node 1 can execute this transaction and generate the corresponding contract instance. "0x6f8ae93..." in Figure 1 represents the address of this contract. The data field of the transaction can store bytecode, and the to field of the transaction is an empty account. After the nodes reach an agreement through the consensus mechanism, the contract is successfully created and subsequent users can call this contract.

[0039] After the contract is created, a contract account corresponding to the smart contract is generated on the blockchain, and has a specific address. The contract code and account storage will be saved in the contract account. The behavior of the smart contract is controlled by the contract code, and the account storage of the smart contract saves the state of the contract. In other words, the smart contract generates a virtual account on the blockchain that contains the contract code and account storage.

[0040] As mentioned above, the data field of the transaction that creates a smart contract can store the bytecode of the smart contract. The bytecode consists of a series of bytes, each of which can identify an operation. Based on development efficiency, readability and other considerations, developers can choose a high-level language to write smart contract code instead of writing bytecode directly. The smart contract code written in a high-level language is compiled by a compiler to generate bytecode, which can then be deployed on the blockchain. Ethereum supports many high-level languages, such as Solidity, Serpent, LLL, etc.

[0041] Taking Solidity as an example, contracts written in it are very similar to classes in object-oriented programming languages. Multiple members can be declared in a contract, including state variables, functions, function modifiers, events, etc. State variables are values ​​stored in the account storage of smart contracts and are used to save the state of the contract.

[0042] The following is a code example of a simple smart contract written in Solidity language 1:

[0043]

[0044] Code Example 1. SimpleStorage Code

[0045] In the above code example 1, line 2 declares a string state variable storedData. A state variable means that this value is stored on the blockchain and will be updated every time the contract state changes.

[0046] Line 3 declares the event storage, which contains the address of the initiator who called the contract (msg.sender) and the string s. In Solidity, events are the interface for contracts to communicate with the outside world, and are mainly used to notify client applications that monitor these events of changes in contract status.

[0047] Lines 4-7 define the set function. The input parameter is the string s. The "memory" keyword is used to specify the data location. The public function is used here so that the function can be called from outside the contract. The operations performed by the set function include setting the input parameter to the state variable storedData and generating an event through the keyword emit. The event can generally be defined by the contract developer to define the execution of a certain operation. The event content defined here includes the initiator address and the string s that call the contract.

[0048] As mentioned before, the state variables will eventually be stored in the database. The generated events are generally in the following form:

[0049] [topic1][topic2]...[topicn][data]

[0050] Here, the first topic, namely topic1, is generally the default value, for example, it is the identifier of the receipt, which can be a hash value obtained by sequentially concatenating the event name, event parameter type, etc. Whether each topic exists from topic2 to topicn depends on whether the Indexed modifier is added when defining the parameters. The value with this parameter will be a topic in the receipt, and the value without the Indexed modifier will generally be placed in the data. In the example in the above code example 1, when declaring the event in line 3, the two parameters address from and s do not have the Indexed modifier and are generally placed in the data. The code in line 6 sets the data content [msg.sender, s] in the event through the stored() event. In this way, for the event operated on line 6, the overall format is:

[0051] [topic1: event ID][data: msg.sender, s]

[0052] Lines 8-10 define a function called get, which returns the value currently stored in storedData. In Solidity, the view function modifier is used to indicate that the function does not modify the state variables, and the use of public here allows the function to be called from outside the contract. The return value needs to be specified as memory, because it is a string and the data location needs to be specified.

[0053] In addition, if Figure 2 As shown, still taking Ethereum as an example, after Bob sends a transaction containing information about calling a smart contract to the Ethereum network, the EVM of each node can execute this transaction and generate a corresponding contract instance. The from field of the transaction in Figure 2 is the address of the account that initiates the call to the smart contract, and the "0x6f8ae93..." in the to field represents the address of the smart contract being called. The data field of the transaction stores the method and parameters for calling the smart contract. Here, the data, for example, calls the set function, and the input parameter is "Hello". In addition, a value field can also be included to represent the value of the Ether in the transaction. After calling the smart contract, the value of storedData may change after the execution of the contract. Subsequently, a client can call a blockchain node (for example Figure 2 Node 6) in the storedData view, such as Figure 2 Alice in the example initiates the operation of calling the Get function in the SimpleStorage contract, which returns Hello.

[0054] Smart contracts can be executed independently on each node in the blockchain network in a prescribed manner, and all execution records and data are stored on the blockchain. Therefore, when such a transaction is completed, the blockchain stores transaction credentials that cannot be tampered with or lost.

[0055] As mentioned above, the storedData in the above example is a state variable, which is stored in the account storage of the smart contract. In various blockchain networks that introduce smart contracts, taking Ethereum as an example, accounts can usually be divided into two types:

[0056] Contract account: stores the executed smart contract code and the value of the state in the smart contract code, and can usually only be activated by calling an external account;

[0057] Externally owned account: A user's account, such as an Ethereum owner account.

[0058] The design of external accounts and contract accounts is actually a mapping from account addresses to account status. Account status usually includes fields such as Nonce, Balance, Storage root, CodeHash, etc. Nonce and Balance exist in both external accounts and contract accounts. CodeHash and Storage root properties are generally only valid on contract accounts.

[0059] Nonce: Transaction count. For external accounts, this number can represent the number of transactions sent from the account address; for contract accounts, it can be the number of contracts created by the account.

[0060] Balance: The amount of ether owned by this address.

[0061] Storage root: The hash of the root node of an MPT tree, which organizes the storage of state variables of the contract account.

[0062] CodeHash: The hash value of the smart contract code. For contract accounts, this is the hash value of the smart contract; for external accounts, since they do not include smart contracts, the CodeHash field can generally be an empty string / all-0 string.

[0063] MPT stands for Merkle Patricia Tree, which is a tree structure that combines Merkle Tree and PatriciaTree (compressed prefix tree, a more space-saving Trie tree, dictionary tree). Merkle Tree, the Merkle tree algorithm calculates a hash value for each transaction, and then connects two by two to calculate the hash again until the top Merkle root. Ethereum uses an improved MPT tree, such as a 16-way tree structure, which is usually referred to as MPT tree.

[0064] The data structure of the Ethereum MPT tree includes a state trie. The state trie contains key-value pairs (also written as key-value, abbreviated as kv or kv) of the storage content corresponding to each account in the Ethereum network. The "key" in the state trie can be a 160-bit identifier (the address of the Ethereum account), and this account address is distributed in the storage from the root node of the state trie to the leaf node. The "value" in the state trie is generated by encoding the information of the Ethereum account (for example, using the Recursive-Length Prefix encoding (RLP) method) and stored in the leaf node. As mentioned earlier, for external accounts, the values ​​include nonce and balance; for contract accounts, the values ​​include nonce, balance, codehash, and storageroot.

[0065] The contract account is used to store the states related to the smart contract. After the smart contract is deployed on the blockchain, a corresponding contract account will be generated. This contract account generally has some states, which are defined by the state variables in the smart contract and generate new values ​​when the smart contract is created / executed. The smart contract generally refers to a contract that can automatically execute clauses defined in the form of code in the blockchain environment. Once an event triggers the clauses in the contract (meets the execution conditions), the code can be automatically executed. In the blockchain, the relevant state of a contract is saved in its corresponding storage trie, and the hash value of the storage trie root node is stored in the above storageroot, so that all the states of the contract are locked to the contract account through hash. The storage trie is also an MPT tree structure that stores the key-value mapping from the state address to the state value. Part of the information from the root node to the leaf node of the storage trie tree is arranged in sequence to store the address of a state, and the leaf node stores the value of the state.

[0066] like Figure 3In some blockchain data storages shown, the block header of each block includes several fields, such as the previous block hash previous_Hash (Prev Hash in the figure), the random number Nonce (in some blockchain systems, this Nonce is not a random number, or in some blockchain systems, the Nonce in the block header is not enabled), the timestamp Timestamp, the block number Block Num, the state root hash State_Root, the transaction root hash Transaction_Root, the receipt root hash Receipt_Root, etc. Among them, the Prev Hash in the block header of the next block (such as block N+1) points to the previous block (such as block N), which is the hash value of the previous block. In this way, the next block on the blockchain is locked to the previous block through the block header. Among them, State_Root, Transaction_Root and Receipt_Root lock the state set, transaction set and receipt set respectively. The state set, transaction set and receipt set organize the state, transaction and receipt in the form of a tree respectively. Generally, it can be the same tree structure or different tree structures. For example, in Ethereum, the same MPT structure is used. In some tree structures including the state set of smart contracts such as Ethereum, there are two levels of MPT structures: the leaf nodes of the upper-level MPT structure include two types: external accounts and contract accounts; each contract account includes the MPT structure of the lower level, and the leaf nodes of the lower level include the value of the state in the contract account.

[0067] Figure 4 This is a schematic diagram of the structure of blockchain data storage. Taking Ethereum as an example, we can combine Figure 3As shown, state_root is the hash value of the root of the MPT tree composed of the states of all accounts in the current block, that is, the state trie pointing to state_root is a state tree in the form of MPT. The root node of this MPT tree is generally an extension node (Extension Node) or a branch node (Branch Node), and the hash value of this root node is generally stored in state_root. The root node can be connected to one or more layers of Extension Node / Branch Node below, and these multi-layer tree nodes can be collectively referred to as intermediate nodes (Internal Node). From the root node of this MPT to the leaf node, a part of the value in each node is connected in sequence to form an account address and serve as a key. The account information stored in the leaf node is the value corresponding to this account address, thus forming a key-value pair. Specifically, this key can be sha3(Address), that is, the hash value of the account address (the hash algorithm adopts the sha3 algorithm, for example), and the value stored can be rlp(Account), that is, the rlp encoding of the account information. The account information is a 4-tuple consisting of [nonce, balance, storageRoot, codeHash]. As mentioned above, for external accounts, there are generally only two items, nonce and balance, and the storageRoot and codeHash fields store empty strings / all zero strings by default. In other words, external accounts do not store contracts, nor do they store state variables generated after contract execution. Contract accounts generally include Nonce, Balance, Storage root, and CodeHash. Nonce is the transaction counter of the contract account; Balance is the account balance; Storage root corresponds to another MPT, through which the information on the state of the contract can be linked; CodeHash is the hash value of the contract code. Whether it is an external account or a contract account, its account information is generally located in a separate leaf node. From the Extension Node / Branch Node of the root node to the Leaf Node of each account, there may be several branch nodes and extension nodes in the middle.

[0068] It should be noted that, in general, for the world state, each account is a key-value pair that maps from an address to an account state. The key here refers to the address of the account, not the hash of the address. However, in the internal implementation, Ethereum uses a hash function (Keccak-256, Note: SHA-3 is based on the Keccak algorithm, but different parameter settings were used in the final standardization; this means that SHA-3 and Keccak-256 are not technically exactly the same, although their design basis is the same; the original Keccak-256 algorithm is actually used in Ethereum, not the SHA-3 version later standardized by NIST; but for simplicity, sha3 is used below) to construct the MPT, and the account address will be hashed in the process. Therefore, when talking about the key-value pair of an account, it usually refers to the direct mapping of the address to the account state. But at the implementation detail level, these addresses and storage data are hashed in order to efficiently query and verify the state, and to ensure that any data changes will be reflected in the root node of the Trie tree, supporting fast data integrity verification. In short, the key in the Ethereum world state is usually the account address itself, but in the underlying data structure (such as MPT), the address and other data may be stored and processed in the form of hashes.

[0069] The state trie can be a tree in the form of MPT, generally a 16-way tree, that is, each layer can have up to 16 child nodes. For Extension Node, it is used to store common prefixes, and it generally has 1 child node, which can be Branch Node. For Branch Node, it can have up to 16 child nodes, which may include ExtensionNode and / or Leaf Node.

[0070] Among them, for a contract account in the state trie, its storage_Root points to another tree in the form of MPT, which stores the data of the state variables involved in the contract execution. The MPT-style tree pointed to by this storage_Root is Storage Trie, that is, the hash value of the root node of Storage Trie. Generally, this Storage Trie tree also stores key-value pairs. The key indicates the address of the state variable, and its value can be the result obtained after the position of the state variable declaration in the contract (the value counting from 0) is processed by certain rules, such as sha3 (the position of the state variable declaration) or sha3 (the contract name + the position of the state variable declaration). The value is used to store the value of the state variable (for example, the value encoded by RLP). A part of the data stored on the path from the root node to the intermediate node to the leaf node is connected to form the key, and the value is stored in the leaf node. As mentioned above, the Storage trie can also be a tree in the form of MPT, which is generally a 16-way tree, that is, for a Branch Node, it can have up to 16 child nodes, which may include Extension Nodes and / or Leaf Nodes. For an ExtensionNode, it can generally have 1 child node, which can be a Branch Node or a Leaf Node.

[0071] For example Figure 4 The Leaf Node Account P of the state trie in the contract has its Storage Root locking all states in the contract storage. These states are organized into an MPT tree, and the tree structure is like the Storagetrie linked to the Storage Root. In this linked Storage trie, taking Leaf Node State Variable N as an example, for example, the value of storedData in the aforementioned contract code example, its key is sha3 (the declaration position of storedData), and its value is s (for simplicity, the encoding format of value is omitted here, such as RLP, which will be similar in the future and will not be repeated). Among them, the key values ​​are sequentially distributed from the root node to the leaf node (i.e., Leaf Node Variable N) of the storage trie.

[0072] For another example, Figure 4The Leaf Node Account C in the state Trie in , its key is sha3 (AddressC), that is, the hash value of the address of account C (the hash algorithm adopts the sha3 algorithm, for example), and its stored value value can be (Account), where the account information Account is a tuple consisting of [nonce, balance]. As mentioned above, since Account C is an external account, its account information is two items, nonce and balance. For example, an external account, its nonce is 20, and its balance is 4550, then the Leaf Node State Variable C, this leaf node, stores nonce = 20, balance = 4550. The address of Account C is the key, and its values ​​are sequentially distributed from the root node to the leaf node (i.e., Leaf Node Variable C) of the state Trie.

[0073] These states, including the kv of external accounts and the kv of contract accounts, are ultimately stored in the database. The storage in the database does not directly store the states of these accounts, that is, it does not directly store the kv of these accounts, but stores the kv value of each tree node itself.

[0074] like Figure 5As shown in the example, the upper part of the two parts divided by the long dashed line is the upper MPT, and the lower part is the lower MPT. In the upper MPT structure, for the leaf node A1, the key of the leaf node is composed of a7 of shared nibbles in the root node A8 (Extension Node) - slot 1 of the intermediate node A7 (Branch Node) - 1335 of key-end in the leaf node A1, which is a711335. Balance = 45.0ETH and Nonce = n1 are stored in the leaf node. For leaf node A2, the key of the leaf node is composed of a7 of shared nibbles in root node A8 (Extension Node), slot 7 of intermediate node A7 (Branch Node), d3 of shared nibbles in node A6 (Extension Node), slot 3 of intermediate node A5 (Branch Node), and 7 of key-end in leaf node A2, which is a77d337. Balance = 1.00WEI and Nonce = n2 are stored in the leaf node. For leaf node A3, the key of the leaf node is composed of a7 of shared nibbles in root node A8 (Extension Node), slot f of intermediate node A7 (BranchNode), and 9365 of key-end in leaf node A3, which is a7f9365. Balance = 1.1ETH and Nonce = n3 are stored in the leaf node. For leaf node A4, the key of the leaf node is composed of a7 of shared nibbles in root node A8 (Extension Node) - slot 7 of intermediate node A7 (Branch Node) - d3 of shared nibbles in node A6 (Extension Node) - slot 9 of intermediate node A5 (Branch Node) - 7 of key-end in leaf node A4, which is a77d397. Balance = 0.12ETH, Nonce = n4, CodeHash = c1, Storage root = s1 are stored in the leaf node. Among them, the leaf nodes of A1, A2 and A3 store the information of external accounts, and the leaf node of A4 stores the information of contract accounts. For contract accounts, it contains the next level MPT, forming a Storage Trie, which is used to store the state variables in the contract account.

[0075] like Figure 5As shown in the example, in the lower-level MPT structure, for leaf node A11, slot 3 in root node A10 (Branch Node) - 35b2e4 of key-end in leaf node A11 are sequentially combined to form the key of the leaf node, that is, 335b2e4, and "Zhang San_A = 20" is stored in the leaf node, for example, indicating that the share of type A digital assets defined in the contract belonging to Zhang San is 20, that is, the balance of Zhang San's type A assets is 20. For leaf node A12, slot 7 in root node A10 (Branch Node) - c25988 of key-end in leaf node A12 are sequentially combined to form the key of the leaf node, that is, 7c25988, and "Li Si_B = 20" is stored in the leaf node, for example, indicating that the share of type B digital assets defined in the contract belonging to Li Si is 50, that is, the balance of Li Si's type B assets is 50. For leaf node A15, the key of the leaf node is composed of slot f in root node A10 (Branch Node), a in shared nibbles in intermediate node A13 (Extension Node), slot 6 in intermediate node A14 (Branch Node), and be33 in key-end in leaf node A15, which is fa6be33. "storedData=s" is stored in the leaf node. For leaf node A16, the key of the leaf node is composed of slot f in root node A10 (Branch Node), a in shared nibbles in intermediate node A13 (Extension Node), slot 9 in intermediate node A14 (Branch Node), and 9365 in key-end in leaf node A16, which is fa99365. "Wang Wu_A=35" is stored in the leaf node, which means that the share of type A digital assets defined in the contract belonging to Wang Wu is 35, that is, the balance of Wang Wu's type A assets is 35.

[0076] In the node structure of the above MPT tree, the prefix prefix is ​​used to indicate the type of tree node, for example, 0 indicates an Extension Node containing an even number of shared nibbles, 1 indicates an Extension Node containing an odd number of shared nibbles(s), 2 indicates a Leaf Node containing an even number of nibbles, and 3 indicates a Leaf Node containing an odd number of nibbles(s). In the above diagram, the depths of leaf nodes at the same level may be different, such as A1, A2, A3, and A4 are all leaf nodes of accounts, but the depths (assuming A8 is the first depth level) are 3, 5, 5, and 3 respectively; for another example, A11, A12, A15, and A16 are all state storages of the same contract, but the depths are 7, 7, 9, and 9 respectively.

[0077] In the above node structure, the hash value of the entire content of the next tree node is filled in the corresponding position of the previous tree node. In the database, the key-value mapping of each tree node is actually stored, where the value includes the content stored in this tree node, and the corresponding key is the hash value of the entire content of this tree node. In this way, the tree node kv actually stored in the database is as follows:

[0078]

[0079]

[0080] Table 1. Tree node kv stored in the database

[0081] In the above table, H() is used to represent hash calculation. In this way, the hash value of the next tree node is anchored in the previous tree node. Through such layers of hashing, the root hash of the entire state trie tree is obtained, and the root hash is locked in the state root field of the block header.

[0082] The above-mentioned Ethereum MPT and the similar Libra SMT (Sparse Merkle Tree, similar to MPT) ultimately store the KV of the tree node in the underlying database in the form of the corresponding relationship in the above table. Most of the underlying databases use NoSQL Key-Value DB (DataBase, database) with LSM (Log-Structured Merge-Tree) structure, which is stored in a persistent storage medium (such as a disk). Specifically, the underlying database is, for example, Ethereum's levelDB and Libra's RocksDB. Both KVDBs are based on the LSM storage engine.

[0083] It should be noted that if the state kv of "fa99365: Wang Wu_A=35" is deleted, that is, the above Figure 5 The leaf node A16 in the MPT tree, the corresponding key—fa99365, also needs to be deleted from the lower-level MPT. Due to the characteristics of prefix compression, multiple nodes in the MPT tree may change, resulting in changes in the tree shape. For example, after A16 is deleted, Figure 5 The Extension Node of A13 and the Branch Node of A14 will also be deleted and become as follows Figure 6 As shown in the figure, the key-end in A15 becomes a6be33. Figure 5 The total depth of the 9th layer (assuming A8 is the 1st layer) becomes Figure 6 The total depth of the 7th layer. Figure 6 to Figure 5 , which can be regarded as Figure 6 Adding the state kv "fa99365: Wang Wu_A=35" on the basis will also affect the tree shape of the MPT tree. Similarly, for the upper-level MPT, adding or deleting accounts will also produce similar tree changes. From this, it can be seen that the depth of the same leaf node in the MPT is not fixed and may change with the insertion and deletion of other nodes. If only the value of the state is changed, and the key does not change, it will not cause the MPT tree shape to change. For example, if the value of Wang Wu_A changes from 35 to 45, its key will not change, so the MPT tree shape will not change. For adding states, such as adding accounts or adding contract states, it may cause changes in the MPT tree shape; for deleting states, such as deleting accounts or deleting contract states, it may also cause changes in the MPT tree shape. During the change process, the hash value of the next layer node will always be filled into the previous layer node.

[0084] Moreover, in the process of adding and deleting nodes, as long as the number of state keys and the value of each key are consistent, the shape of the tree is unique, regardless of the order of adding and deleting nodes. This is also called the tree having a "steady state".

[0085] The above characteristics of the MPT tree determine that the depth of the MPT tree is uncontrollable. As the number of accounts increases, the common prefixes become fewer, so the number of Branch Nodes will increase, and the overall depth of the upper-level MPT tree will become deeper; as the number of contract state variables increases, the common prefixes become fewer, so the number of Branch Nodes will increase, and the overall depth of the upper-level MPT tree will also become deeper.

[0086] To read the contents of an account storage or contract storage, for example, to read the corresponding value according to the key of the account address or state address, the root node of the tree is usually read first, that is, the key-value of the root node of the tree is read from the database and loaded into the memory. Further, the value part of the read root node is prefix matched with the key of the account address or state address to be found, and then the next intermediate node is found; until the last nibble of the key of the account address or state address is matched, that is, the leaf node is found, and the value content is read from the leaf node.

[0087] For example, to find the value content corresponding to the external account address a77d337, the key-value of the block header node A9 corresponding to block N can be read from the database and loaded into the memory. Since the value stored in the database is RLP encoded as mentioned above, it also involves a decoding process after loading into the memory to restore the account structure. For simplicity, this point is omitted later. From the value corresponding to the Key H(A9) in Table 1, Prev Hash:, Nonce:, Timestamp:, Block Num:, State Root: H(A8), Transaction Root:, Receipt Root:,… can be read. It can be determined that the Key in Table 1 corresponding to State Root is H(A8), that is, the root node of the tree is read. Then, according to H(A8), you can search in Table 1, further find the Key-Value corresponding to A8 and read it from the database and load it into the memory. From the value corresponding to the key H(A8) in Table 1, we read prefix:0, shared nibble(s):a7, next node:H(A7), where a7 in shared nibble(s) also matches the first two nibbles in the external account address a77d337 to be searched, so we can read the next level node H(A7) of the MPT tree. Then, we can search in Table 1 according to H(A7), further find the Key-Value corresponding to A7, read it from the database, and load it into the memory. From the value corresponding to the key H(A7) in Table 1, we read 0:, 1: H(A1), 2:, 3:, 4:, 5:, 6:, 7: H(A6), 8:, 9:, a:, b:, c:, d:, e:, f: H(A3), value:, where 7: H(A6)'s 7 matches the third nibble in the external account address a77d337 to be searched, so that the next level node H(A6) of the MPT tree can be read. Then, we can search in Table 1 according to H(A6), further find the Key-Value corresponding to A6, read it from the database, and load it into the memory. From the value corresponding to the key H(A6) in Table 1, we read value: prefix: 0, shared nibble(s): d3, next node: H(A5), where d3 of shared nibble(s): d3 matches the fourth and fifth nibbles in the external account address a77d337 to be searched, so we can read the next level node H(A5) of the MPT tree. Then, we can search in Table 1 according to H(A5), further find the Key-Value corresponding to A5, read it from the database, and load it into the memory.From the value corresponding to the key H(A5) in Table 1, we read 0:, 1:, 2:, 3: H(A2), 4:, 5:, 6:, 7:, 8:, 9: H(A4), a:, b:, c:, d:, e:, f:, value:, where 3: 3 in H(A2) matches the sixth nibble in the external account address a77d337 to be found, so that the next level node H(A2) of the MPT tree can be read. Then, we can search in Table 1 according to H(A2), further find the corresponding Key-Value, read it from the database, and load it into the memory. From the value corresponding to the key H(A2) in Table 1, we read prefix: 0, Key-end: 7, balance: 1.00WEI, nonce: n2, where 7 in Key-end: 7 matches the last nibble in the external account address a77d337 to be found, so that the nonce and balance values ​​of the account can be read.

[0088] It can be seen that reading the content of a leaf node is closely related to the depth of the leaf node in the MPT tree. Generally speaking, as the depth of the MPT increases, more I / O (Input / Output) times are required, which will bring greater delays.

[0089] One advantage of the above-mentioned MPT tree is that it can ensure the verifiability of the state, thereby providing Simple Payment Verification (SPV). Due to the distributed nature of blockchain, how to ensure that the account or state provided on a blockchain node is credible can be proved by SPV based on the difficult-to-forge feature of hash. For example, in order to promote blockchain, in addition to full blockchain nodes (referred to as full nodes) that store complete ledgers, there are also light nodes with relatively low performance and storage capacity suitable for mobile phones. The main difference between this type of light node and full node is that the light node does not participate in the consensus and execution of transactions in the blockchain network, and only saves the block header, but not the complete transaction, state, and receipt. Then, when the light node queries an account or state from a connected full node, based on the premise of mutual distrust of the blockchain, it cannot directly trust the value provided by the full node. SPV solves this problem. The following is a simplified SPV in Bitcoin to illustrate, and Ethereum is more complicated on this basis, but the overall principle is the same.

[0090] Assuming that the Bitcoin light node queries whether transaction K (TxK) is already on the chain, it can hash TxK and send the hash value H K To a full node. Figure 7As shown, the full node searches the local blockchain ledger and finds H K The 4 hash values ​​on the path to the Merkle root are returned to the light node: H L , H IJ , H MNOP , H ABCDEFGH The four hash values ​​returned to the light node are called Merkle Proof. Then, the light node can verify based on TxK and the four returned hash values. If the obtained Merkle root is the same as a Merkle root in the block header saved by itself, it proves that TxK is in the block corresponding to this Merkle root. The proof process includes: the light node verifies the hash value H of TxK. K With the returned H L Calculate the hash value H after splicing KL ; H KL With the returned H IJ Calculate the hash value H after splicing IJKL ; H IJKL With the returned H MNOP Calculate the hash value H after splicing IJKLMNOP ; H IJKLMNOP With the returned H ABCDEFGH Calculate the hash value H after splicing ABCDEFGHIJKLMNOP , that is, the Merkle root is obtained. Figure 7 H in the green box K It indicates that the light node itself is calculated through transaction K (TxK), the blue box indicates that it is obtained from the full node, and the red dotted box indicates that it is calculated by the hash value it already has and the hash value returned by the full node.

[0091] The above are typical MPT trees and SPV-related principles in blockchain.

[0092] In traditional relational databases, such as MySQL, the underlying structure is usually a B+ tree. Generally speaking, B-tree and B+ tree are commonly used multi-way balanced search trees and are data structures commonly used in the underlying database.

[0093] Assuming that a B-tree with degree = 3 (degree is the maximum number of forks) is used to store the contents of the above table, Figure 8 As shown. Figure 8 In the example, a disk block is 16KB. When dgree=3, a three-layer height can store up to 52 data. Similarly, when dgree=4, a three-layer height can store up to 63 data. Figure 8For example, if degree=3 in the tree, search for key=14, find the root node, load disk block 1 into memory; load disk block 2 into memory after comparison; load disk block 7 into memory after comparison. In this way, a total of 3 I / Os are required. However, the problem with this is that the amount of data that can be stored in a tree with a maximum height of three layers is too small.

[0094] Even if we use a B-tree with degree = 17, then Fig. 9 As shown, assuming that the pointer does not occupy storage space and one key:data occupies 1KB, then for dgree=17, that is, 16 data are stored in each node, a three-layer tree can store at most 6+16*16+16*16*16=16+256+4096=4368 records, and the total number that can be stored is still not enough.

[0095] If Fig.10 The height of the B+ tree shown is fixed, that is, the actual data (index + record) is stored in the leaf nodes, and the non-leaf nodes only store indexes. Still based on the calculation of a disk block of 16KB, assuming that 1 key + 1 pointer = 10Byte, then a node can store 16K / 10Byte = 1600 indexes and addresses, then a root node in the first layer can store 1600, and 16 nodes in the second layer can store a total of 1600*1600=2560000. The third layer stores key:data. Assuming that 1 key:data is 1KB, a node in the third layer can store 16K / 1K=16 data, and the third layer can store a total of 16*2560000=40960000≈40 million rows of data. In this way, using the B+ tree, with a total of three layers of height, the maximum amount of data that can be stored is much larger than the B-tree with the same maximum number of forks.

[0096] In addition, if the order of inserting and deleting leaf nodes is different, the shape of the tree is not unique under the same number and index of leaf nodes, that is, it does not have a "steady state". Fig.11 The B+ tree shown in the tree shape. If the same nodes are inserted in the order of 10, 5, 7, 6, 3, 8, 2, 1, 9, 4, the following is generated Fig.12 The final tree shapes of the two are obviously quite different, that is, they do not have a "steady state".

[0097] The advantage of using B+ tree is that it can support range query. For example Fig.10In the search for data corresponding to keys 10 to 26, since the index is set in the non-leaf node, the key in the underlying leaf node can be quickly searched, and the leaf nodes are sorted by key, so the range query can be completed quickly. The B-tree is similar and can support range queries, which will not be described in detail. In particular, a bidirectional linked list can also be used in the B+ tree, such as Fig.10 As shown by the blue arrow in the figure, the search speed can be further accelerated.

[0098] Based on the advantages of the B+ tree mentioned above, some experimenters have tried to introduce the B+ tree in MySQL into the blockchain to replace MPT and similar tree structures. However, there are two problems that need to be solved:

[0099] 1. Traditional B+ trees and similar tree structures do not have a steady state.

[0100] 2. Traditional B+ trees and similar tree structures cannot provide SPV proofs;

[0101] A paper titled "ForkBase: An Efficient Storage Engine for Blockchain and Forkable Applications" was published in the 2018 International Conference on Databases (VLDB). https: / / pdos.csail.mit.edu / ~benjie / papers / lbfs: sosp01.pdf ), provides a file content-based pattern cutting method, which solves the problem of unstable tree shape caused by different insertion orders. The idea of ​​Forkbase's pattern cutting based on file content is: for any key set, sort them from small to large to form an ordered byte stream, use a fixed-size sliding window to slide on the byte stream, and calculate the rolling hash (Rolling Hash) for the byte stream in the current sliding window. If the last N bits of the Rolling Hash are all 0, make a cut at the end of the current sliding window, and then continue to repeat the above steps for the remaining byte streams. After cutting, the key combination is divided into multiple subsets, and the maximum key of each subset is used as the parent node of the subset; the same cutting algorithm can be recursively applied to all parent nodes, and then a tree based on pattern cutting can be constructed.

[0102] However, the above idea is based on file content and is applicable to audio and video streams, but it is not applicable to the KV that needs to be stored in the underlying database of the blockchain. Although the paper mentions that it can be applied to the blockchain, it does not provide further details and does not provide an idea for verifying SPV.

[0103] This application provides an embodiment of a storage method in a blockchain. Fig.13As shown, this embodiment includes:

[0104] S131: Receive the status kv output after the virtual machine is executed.

[0105] The transaction that creates a smart contract is sent to the blockchain, and the nodes on the blockchain can execute this transaction. In particular, when there is a constructor in the contract, the transaction can be executed by the EVM / WASM virtual machine of the blockchain node. In some cases, the transaction that creates a smart contract can be deployed without being executed by the EVM / WASM virtual machine. This is usually the case when there is no constructor in the contract or the constructor is empty. However, the transaction that creates a smart contract is generally executed by the blockchain node, and the result of the execution includes the generation of a contract account. The contract account has an address, and the contract account generally includes a balance, a transaction count nonce, the codehash of the contract code, and the contract storage (i.e., the aforementioned storage, including the storage root). During the deployment of a smart contract, if the contract code contains a constructor, the function will be executed by the EVM / WASM virtual machine at the time of deployment. The constructor is generally logic that only needs to be run once when the contract is deployed, and is usually used to initialize the state variables of the contract. The results of the constructor execution (i.e., the initial values ​​of the state variables) will be permanently stored in the storage of the contract, and these values ​​can then be read and updated as needed during the life cycle of the contract. The constructor is usually executed once when the contract is created (deployed) and cannot be called again. Therefore, after the contract is deployed, the constructor code can actually be excluded from the contract code that is persistently stored on the blockchain in order to save space. In other words, the contract bytecode that does not contain the constructor is usually stored permanently on the Ethereum blockchain. In this way, the contract deployment is completed.

[0106] It should be noted that the underlying databases mentioned above are, for example, Ethereum's levelDB and Libra's RocksDB. Taking Ethereum as an example, its underlying layer actually uses three LevelDB databases. These three LevelDBs and their stored contents are as follows:

[0107] BlockDB: the main content of the block - block header + transaction;

[0108] StateDB: account status data;

[0109] ExtrasDB: receipts and other auxiliary information;

[0110] After the above contract deployment process is completed, the generated contract account and contract bytecode (excluding constructors) can be stored in StateDB. The codehash in the contract account can be used to retrieve the code associated with the contract account.

[0111] WebAssembly (also abbreviated as wasm) is a new format that is portable, small, fast to load, and compatible with the Web. It can be used as a compilation target for C / C++ / Rust / Java, etc. WebAssembly can be regarded as the general instruction set of x86 hardware for the Web platform. As an intermediate language, it connects to Java, Python, Go, Rust, C++, etc., so that these languages ​​can be compiled into a unified format for running on the Web platform. The WASM virtual machine was originally designed to solve the increasingly severe performance problems of Web programs. Due to its superior characteristics, it has been adopted by more and more non-Web projects, such as replacing the blockchain smart contract execution engine EVM. The contract code developed in high-level languages ​​such as Java, Python, Go, Rust, C++, etc. can be compiled by the compiler to obtain wasm bytecode, which can run on various platforms integrated with the wasm virtual machine. For simplicity, EVM will be used instead of EVM / WASM in the future.

[0112] As mentioned above, after the transaction of deploying the contract is executed, a contract account corresponding to the smart contract is generated on the blockchain, and has a specific address. The contract code and account storage can be saved in StateDB. Subsequently, the blockchain node can receive a transaction request to call the deployed smart contract. The transaction request may include the address of the called contract, the function in the called contract, and the input parameters. Generally, after the transaction request reaches a consensus, each node in the blockchain can independently execute the specified smart contract. Specifically, Fig.14As shown, the node can load the bytecode of the contract from the storage into the virtual machine (EVM / WASM) according to the address of the contract; then, the interpreter interprets and executes it, for example, including parsing the bytecode of the called contract to obtain the operation code (OPcode), and storing these OPcodes in the memory of the virtual machine, and also obtaining the address of the called function; after calculating the Gas required to execute the contract and the Gas is sufficient, jump to the corresponding address of the memory to obtain the OPcode of the called function and start execution, and calculate (Data Computation) the data operated by the OPcode of the called function, push / push the stack (Stack), etc., so as to complete the data calculation. In this process, some contract context information may also be required, such as the block number, the information of the initiator of the call contract, etc., which can be obtained from the Context (Get operation). Finally, the generated state is stored in the database storage (Storage) by calling the storage interface.

[0113] For Ethereum, EVM is the environment for executing smart contract code in the Ethereum blockchain platform. In the Ethereum ecosystem, EVM can be seen as an independent sandbox environment, providing an isolated execution space. For many other blockchain platforms that use virtual machines such as EVM and WASM as the execution environment for smart contract code, similarly, virtual machines such as EVM and WASM provide an environment for smart contract code execution, but EVM and WASM do not directly store states. When the contract is executed and a state that needs to be persistently stored is generated, EVM / WASM will interact with the storage module in the blockchain platform code and send the state that needs to be persistently stored to the API provided by the storage module in the blockchain platform code.

[0114] In this way, the storage module in the blockchain platform code can receive the state kv output after the virtual machine is executed.

[0115] S133: insert the state kv into the leaf node at the bottom layer of the n-ary tree in the order of k, take the eigenvalue of k, and set the non-leaf node according to the eigenvalue.

[0116] In order to increase the amount of data that can be stored under the premise of limited tree height like the B+ tree, the height of the tree is still set to be fixed here, and the actual data (index + record) is stored in the leaf nodes, while non-leaf nodes only store indexes but not records (this is relative to the leaf nodes storing indexes + records, and does not exclude the storage of other information).

[0117] The state kv is inserted into the leaf nodes at the bottom of the n-ary tree in the order of k, so that in the bottom of the n-ary tree, all key-value pairs are arranged in order according to the size of the key. At the same time, the characteristic value of k needs to be taken and the non-leaf nodes are set according to the characteristic value.

[0118] Inserting the state key-value into the leaf node at the bottom of the n-ary tree in the order of the key, taking the characteristic value of the key, and setting the non-leaf node according to the characteristic value, which may specifically include:

[0119] Take the eigenvalue of the key, determine the highest level of the tree where the key is located based on the eigenvalue, and:

[0120] If the characteristic value is greater than 0, the key is filled in from the highest tree node represented by the key to the second lowest tree node in sequence; in the process of filling the key in each tree node, the tree node splitting and / or merging is set according to the rules of the n-ary tree; and the state key-value is inserted into the leaf node of the bottom 0 layer of the n-ary tree in the order of the key;

[0121] If the characteristic value is equal to 0, the state key-value is inserted into the leaf node of the bottom layer 0 of the n-ary tree in the order of the keys.

[0122] Take the summary value of k, for example, calculate the summary value according to the hash algorithm such as SHA (Secure Hash Algorithm 3)2, SHA3. Hash algorithm is also called hash algorithm, which can map the original content into a sequence of fixed length, which is the hash value. SHA2 generally has hash algorithms such as SHA256, SHA384, and SHA512. The result of SHA256 is 256 bits, which can represent 2 to the power of 256 original contents. Similarly, the result of SHA384 is 384 bits, and the result of SHA512 is 512 bits. SHA3 is a newest hash algorithm, released in 2013. The SHA-3 algorithm has higher security and higher hash value length, and can resist known attacks. These hash algorithms can be used for original content with more content and larger volume, so the hash value can be relatively much smaller than the original content. A good hash algorithm can ensure that different original contents are mapped to different hash values ​​with a high probability. At the same time, this mapping is chaotic, that is, it is impossible to predict the correlation between the hash values ​​obtained from different original contents; and it is also resistant to inverse operations, that is, it is impossible to reverse the hash value to get the original content.

[0123] The characteristic value may be obtained according to a predetermined rule, which may be to calculate the summary value of the key, and to take a number of consecutive bits of a certain value starting from or ending with a header, a specific middle bit, or a number of consecutive bits of a specific value starting from or ending with a header, a specific middle bit, or to take a number of consecutive bits of 0 starting from or ending with a header, a specific middle bit, or to take a number of consecutive bits of 9 or 1 (of course, 2, 3, 4, etc. are also possible) starting from or ending with a header, a specific middle bit, or a number of consecutive bits of 9 or 1 (of course, 2, 3, 4, etc. are also possible) starting from or ending with a header, a specific middle bit, or a number of consecutive bits of 0.

[0124] The following is an example of taking a number of consecutive 0 bits at the end to illustrate.

[0125] like Fig.15 As shown, it is assumed that there is an n-ary tree constructed according to the rules in this application, where n is 2, that is, a binary tree. Each non-leaf node of this binary tree contains two pointer fields, two index values, and hash values ​​corresponding to the index values. For simplicity, the pointer field is omitted, and only the yellow arrows in the figure are used to represent the link relationship of the pointers. The construction rules of the tree can be reflected by describing the process of inserting a new node. Among them, the light green in this tree represents a key (the leaf node also includes the corresponding Value), and the blue background represents a logical page (Logic Page), which is also called a logical node here, similar to the aforementioned disk block. In this example, as mentioned above Fig. 9 , 10 Similarly, the actual data (index + record) is stored in the leaf nodes at the bottom level, and only the index is stored in the non-leaf nodes. This is the same as the aforementioned use of the B+ tree.

[0126] Fig.15 In the lower left leaf node (that is, the leftmost node in layer 0 in the figure), 00003 is a key with a corresponding value. The 00005 next to it is another key with a corresponding value. The key and value of 00003 and the key and value of 00005 together form a leaf node. The other leaf nodes are similar and will not be described one by one.

[0127] Fig.15 In the leaf nodes, the key:value are as follows:

[0128] 00003:<00003, Sarah, 950>

[0129] 00005:<00005, Michael, 680>

[0130] 00680:<00680, Emily, 360>

[0131] 00690: <00690, Jessica, 599>

[0132] 00883: <00883, David, 504>

[0133] 88483: <88483, James, 610>

[0134] 88484: <88484, Jennifer, 679>

[0135] 88485: <88485, Robert, 497>

[0136] In this example, the key is the ID, and the value is, for example, <ID, name, asset quantity>.

[0137] Fig.15 The 0, 1, 2, 3, etc. on the right side of the key in each leaf node are called eigenvalue here. This eigenvalue can be the result obtained according to a predetermined rule after taking the digest value of the key. For example, for the key of 00003, assuming the hash value is taken by sha3, the last four consecutive bits of binary are not 0 (four consecutive bits of binary, that is, the aforementioned nibble, half byte), that is, there are 0 consecutive four-bit binary 0s at the end, so the eigenvalue is marked as 0. For example, for the key of 00005, assuming the hash value is taken by sha3, there is 1 consecutive four-bit binary 0 at the end, so the eigenvalue is marked as 1. For example, for the key of 00883, assuming the hash value is taken by sha3, there are 3 consecutive four-bit binary 0s at the end, so the eigenvalue is marked as 3. It should be noted that here, taking four consecutive bits of binary 0 is just an example, and it can also be taking two consecutive bits of binary 0, eight consecutive bits of binary 0, four consecutive bits of binary 1, eight consecutive bits of binary 1, and so on.

[0138] It is possible to determine, according to the eigenvalue, the highest layer of the tree that a key can be located at in addition to the 0th layer. As Fig.15 shown:

[0139] For the key of 00003, its eigenvalue is 0, then this key is located at the 0th layer;

[0140] For the key of 00005, its eigenvalue is 1, then this key is located at the 0th layer and can be located at the highest layer of the 1st layer in addition;

[0141] For the key of 00883, its eigenvalue is 3, then this key is located at the 0th layer and can be located at the highest layer of the 3rd layer in addition.

[0142] Therefore, the intermediate nodes in the first layer contain the intermediate nodes composed of the key 00005 and the key 00883. Moreover, the intermediate nodes in the second layer contain the intermediate nodes composed of the key 00883. The root node in the third layer (root nodes and intermediate nodes can be collectively referred to as non-leaf nodes) contains the key 00883.

[0143] Fig.15 In the non-leaf nodes in the , the position of the linked next-level logical node is indicated by the pointer field. Moreover, the key in the next-level logical node pointed to by the pointer is less than or equal to the key value on the right side of the pointer field. In this way, for example, for 00883 in the third layer, the pointer on its left side points to the intermediate node 00883 in the second layer; similarly, for 00883 in the second layer, the pointer on its left side points to the intermediate node containing 00005 and 00883 in the first layer; similarly, for the intermediate node containing 00005 and 00883 in the first layer, the pointer on the left side of 00005 points to the leaf node containing 00003 and 00005 in the 0th layer, and the pointer on the left side of 00883 points to the leaf node containing 00680, 00690 and 00883 in the 0th layer.

[0144] Of course, the key in the next logical node pointed to by the pointer may be greater than or equal to the key value on the right side of the current pointer, or the key in the next logical node pointed to by the pointer may be greater than or equal to the key value on the left side of the current pointer, or the key in the next logical node pointed to by the pointer may be greater than or equal to the key value on the right side of the current pointer. The principles are the same and will not be repeated here.

[0145] A key located above the 0th layer means that this key constitutes a split key, that is, it has a splitting effect on the lower-level nodes. For example, the key 00005 on the 1st layer splits 00005 and its value and 00680 and its value on the 0th layer into two different leaf nodes. This is similar to the aforementioned B-tree and B+ tree, and will not be repeated here. In addition, the keys in non-leaf nodes belong to split keys, and these split keys can split the leaf nodes on the bottom layer 0.

[0146] like Fig.16 For example, suppose the newly inserted key:value is "00679:<00679,John,1000>"

[0147] sha3(00679)=Ox15ebf8bc375838735f1c2ed21c7dc500

[0148] The hash value is Ox15ebf8bc375838735f1c2ed21c7dc500, where 0x represents a hexadecimal number. The hash value ends with two consecutive hexadecimal 0s, which means that 8 bits are 0.

[0149] Assuming that every 4 consecutive bits represent a layer of height, 8 / 4=2, that is, the eigenvalue of the key is 2, which, as mentioned above, represents the highest level of the tree that can be located.

[0150] In this way, take the characteristic value of the key, and if the characteristic value of 00679 is greater than 0, then fill in the key in sequence from the highest tree node represented by the key to the second lowest tree node; in the process of filling the key into the tree node of each layer, set the splitting and / or merging of the tree nodes according to the rules of the n-ary tree; and insert the state key-value into the leaf node of the bottom 0 layer of the n-ary tree according to the order of the key.

[0151] The key 00679 has a characteristic value of 2. In addition to the leaf nodes at layer 0, the intermediate nodes at layer 1 include the intermediate nodes composed of the keys 00005 and 00679. Moreover, the intermediate nodes at layer 2 include the intermediate nodes composed of the keys 00679 and 00883.

[0152] Since the root node of the third layer has not changed, when the key 00679 is inserted into the second layer, the aforementioned pointer rule is followed, that is, 00679 is inserted into the intermediate node of the second layer that is less than or equal to 00883. However, there is already a logical node containing 00083 in the second layer, and the example here is a binary tree, and the leaf node that only contains 00883 currently has only one valid pointer, so 00679 is inserted into the logical node containing 00883, that is, the two keys 00679 and 00883 are located in the same intermediate node. In this way, the content of this intermediate node in the second layer has changed, and accordingly, the pointer field will also change. Specifically, the pointer field on the left side of 00679 points to the next layer of nodes with key values ​​less than or equal to 00679. Similarly, 00883 also points to the next layer of nodes composed of key values ​​less than or equal to 00883.

[0153] Since the intermediate nodes in the second layer have changed, the intermediate nodes in the first layer may also change. Specifically, the two keys 00005 and 00679 in the first layer are both less than or equal to 00679 in the second layer, so the pointer on the left of the key 00679 in the second layer points to an intermediate node in the first layer, which contains the two keys 00005 and 00679. The key 00883 in the first layer is less than or equal to 00883 in the second layer, so the pointer on the left of the key 00883 in the second layer points to an intermediate node in the first layer, which contains the key 00883.

[0154] Since the logical nodes in layer 1 have changed, the nodes in layer 0 may also change. Specifically, the two keys 00003 and 00005 in layer 0 are both less than or equal to 00005 in layer 1, so the pointer on the left of the key 00005 in layer 1 points to a leaf node in layer 0, which contains the two keys 00003 and 00005 and their corresponding values. The key 00679 in layer 0 is less than or equal to 00679 in layer 1, so the pointer on the left of the key 00679 in layer 1 points to a leaf node in layer 0, which contains the key 00679 and its corresponding value. Similarly, the three keys 00680, 00690 and 00883 in layer 0 are all less than or equal to 00883 in layer 1, so the pointer on the left of the key 00883 in layer 1 points to a leaf node in layer 0, which contains the three keys 00680, 00690 and 00883 and their corresponding values.

[0155] like Fig.17 For example, suppose the newly inserted key:value is "00002:<00002,Smith,310>".

[0156] Take the characteristic value of the key, assuming that the characteristic value of 00002 is equal to 0, then insert the state key-value into the leaf node of the bottom layer 0 of the n-ary tree according to the order of the key.

[0157] In this way, the key feature value of 00002 is 0 and is located in the leaf node of the 0th layer, then the state key-value is inserted into the leaf node of the bottom layer 0 of the n-ary tree in the order of the keys.

[0158] In the above example, the n-ary tree is a binary tree. In fact, n can be other values. For example, 16 in the B+ tree is a 16-ary tree. Of course, n can also be other values.

[0159] It should be noted that if Fig.15 , 16 The characteristic value in the tree node in 17 is only for better illustrating the solution of the present application, and the characteristic value must not be included in the tree structure. In the process of generating an n-ary tree, the characteristic value can be obtained by calculating the hash value and following a predetermined rule, such as taking a number of consecutive specific values ​​as mentioned above.

[0160] like Fig.15 , 16 In the example of 17, since the characteristic value of the key obtained is certain, and the rule for setting non-leaf nodes according to the characteristic value is certain, and the inserted key-value is inserted into the leaf node of the bottom layer 0 of the n-ary tree in the order of the key, these operations are not related to the order of insertion. Therefore, no matter what the insertion order is, the tree shape of the generated n-ary tree is certain and unique, that is, it has a steady state.

[0161] In the above embodiment, in addition to linking the lower tree nodes through pointers, the non-leaf nodes can also store the hash values ​​of the linked lower tree nodes in the non-leaf nodes. Specifically, the non-leaf nodes can store the hash values ​​of the linked lower tree nodes corresponding to each split key. Fig.15 As shown in the figure, for the non-leaf nodes 00005 and 00883 in the first layer, the pointer on the left of 00005 points to the leaf node in the 0th layer, which contains two Key-Values, 00003 and 00005 and their corresponding values. In this way, a hash value can be saved in the non-leaf nodes 00005 and 00883 in the first layer, for example Fig.15 The hash value below 00005 in the linked tree node can be the hash value obtained by concatenating 00003 and its value and 00005 and its value in the linked lower tree node. Similarly, for the non-leaf nodes 00005 and 00883 in the first layer, a hash value can be saved, for example Fig.15 The hash value below 00883 in the figure can be the hash value obtained by sequentially concatenating 00680 and its value, 00690 and its value, and 00883 and its value in the linked lower tree node. The other non-leaf nodes are similar and will not be repeated here.

[0162] In this way, SPV proofs can be provided similar to MPT, thereby providing verifiable properties of the state.

[0163] In addition, if Fig.15In the example above, for the key-value with the largest key value, no matter what the characteristic value of the key is, the key can be set in all non-leaf nodes. This is because, according to the above Fig.15 For example, all keys less than or equal to splitkey (and key-values ​​in leaf nodes) are set in the tree node pointed to by the pointer in the pointer field on the left side of the splitkey.

[0164] Of course, you can also adjust the rules to set the keys (and key-values ​​in leaf nodes) that are greater than or equal to the split key in the tree node pointed to by the pointer in the pointer field on the right side of the split key. In this case, for the key-value with the smallest key value, no matter what the characteristic value of its key is, you can set the key in all non-leaf nodes.

[0165] Therefore, the above rules for the minimum key or maximum key can be flexibly set, but the core is to insert the state key-value into the bottom-level leaf node of the n-ary tree in the order of the key, and set the non-leaf node according to the characteristic value of the key.

[0166] The above-mentioned method of setting non-leaf nodes is adopted, and the inserted key-value is inserted into the leaf node of the bottom layer 0 of the n-ary tree in the order of the key, and the hash value of the linked lower tree node is saved in the non-leaf node, so that such an n-ary tree can replace the MPT structure, provide SPV verification capability while maintaining the steady state of the tree shape, and can also provide range query capability.

[0167] Provides SPV verification capabilities, such as Fig.16The key:value "00679:<00679,John,1000>" inserted in the figure can provide 00005 and the corresponding hash in the first-layer intermediate node (i.e. the hash value under 00005 in the figure), 00883 and the corresponding hash in the second-layer intermediate node (i.e. the hash value under 00883 in the figure), 88485 and the corresponding hash in the third-layer root node (i.e. the hash value under 88485 in the figure), and the hash value of the root node. In this way, after receiving the returned hash values, the hash value can be calculated according to the key: value "00679:<00679, John, 1000>", and the hash value can be concatenated after 00005 and the corresponding hash to calculate the hash value of the concatenated content, and 00678 and the calculated hash value are sequentially concatenated with 00883 and the corresponding hash value to obtain the hash value of the concatenated content, and then 00883 and the calculated hash value are sequentially concatenated with 88485 and the corresponding hash value to calculate the hash value of the concatenated content, and then the hash value of the root node is obtained, and compared with the hash value of the root node in the returned hash value. If they are the same, it can be determined that the key: value "00679:<00679, John, 1000>" exists in the state of the contract. Furthermore, as mentioned above, if other information of the contract account such as balance, nonce, codehash, and hash values ​​of other external accounts and contract accounts are obtained, the hash value of the contract account can be calculated together with other information of the contract account such as balance, nonce, and codehash, thereby obtaining the hash value of the contract account. The state root in the block header can then be calculated together with the hash values ​​of other external accounts and contract accounts. Thus, the state root can be verified through the locally saved block header to see if it is consistent with the state root in the block header. No further details will be given.

[0168] The above description is for the state key-value output after the virtual machine is executed. Similarly, the same applies to transactions of non-smart contracts or other transactions that are not executed by virtual machines. For example, in the case of the state key-value of an account output after the blockchain platform executes a transaction, the state key-value can be inserted into the leaf node at the bottom of the n-ary tree in the order of the key, and the characteristic value of the key is taken, and the non-leaf node is set according to the characteristic value. Among them, the account can include external accounts and contract accounts. The specific implementation principle is similar to the above and will not be repeated.

[0169] People in this field know that the essence of blockchain is a chain structure composed of a series of data blocks (blocks) linked by hashes. Each block has a world state corresponding to the block, but each block does not necessarily contain a complete world state, but in most cases contains a reference to the previous world state. The following explains this:

[0170] In the block structure of Ethereum, when the value in a key-value changes, the content of the leaf node of the corresponding MPT tree changes. Accordingly, the relevant hash values ​​stored in a series of intermediate nodes and the root node above the leaf node will also change. In the structure shown in Table 1, the changed leaf nodes, intermediate nodes, and root nodes will also be added to the end of Table 1 in an appended manner. At the same time, the values ​​of more state variables in a contract storage may not change.

[0171] like Fig.18 The Ethereum block structure diagram shown in Fig.18 and Figure 3 The difference is that the references of the root nodes and intermediate nodes of the two-level Merkle tree under the State Root in block N+1 to the state variables that have not changed in block N are added. For example, in the contract storage of a contract, the value of the same state variable is changed from 29 in block N to 45 in block N+1. Assuming that other state variables have not changed, in block N+1, except for the leaf node that stores the value changed to 45 and the intermediate nodes and intermediate nodes related to it, the other leaf nodes and intermediate nodes that have not changed in block N+1 directly reference the same leaf nodes and intermediate nodes in block N. Two adjacent blocks N and N+1 are shown here. It can be understood that for the block structure of multiple consecutive blocks on the blockchain, the leaf nodes and intermediate nodes in block N+1 that have not changed relative to the previous blocks all reference the same leaf nodes and intermediate nodes that were last updated to the value in block N+1. The same leaf node and intermediate node that were last updated to the value, for example, the same leaf node and related intermediate node that were updated to the value in block N-1, the same leaf node and related intermediate node that were updated to the value in block 5, and so on. The different blocks here can also be called different versions, and the block number can be the version number. The reference here is achieved by recording the hash value of the lower node in the upper node. The benefit of this is obvious, that is, the leaf nodes and intermediate nodes that have not changed will not be repeatedly stored in the underlying database.

[0172] Here, we still use the change of the state in the same contract storage in version N+1 relative to version N as a simple explanation. For example, if the content of a tree node changes, its hash will change accordingly. MPT uses the hash as the index in the database, which means that for each value, there is a certain record in the database. MPT associates parent and child nodes based on the node hash. Therefore, whenever the content of a node changes, ultimately for the parent node, only a hash index value changes. The content of the parent node also changes, creating a new higher-level parent node, and recursively passing this impact to the root node. Ultimately, a change creates a new path from the modified node to the root node, and the old node can still be accessed through the old path based on the old root node.

[0173] like Fig.18 As shown in the figure, when the content of a node in MPT changes from 29 in version N to 45 in version N+1, assuming that the other states in the contract state have not changed in the previous and next two versions, the changed 45 in the world state of version N+1 will create a new path to the root node (Storage root) of this contract. In addition, the other leaf nodes and intermediate nodes that have not changed reuse the leaf nodes and / or intermediate nodes in the previous version (i.e. the version with block number N) through hash pointers, thereby constructing a new MPT tree for the storage of the contract in version N+1, while still retaining its old path. Fig.18 In the same contract storage, the leaf nodes / intermediate nodes whose values ​​in version N+1 have not changed relative to version N include V, U, T, S, etc. Therefore, in the storage of the contract in version N+1, in addition to creating a new path from 45 to the Storage root, the Storage root of version N+1 is indexed to V, U, T, S in version N through hash, but does not include the leaf node with a value of 29 and related intermediate nodes. Assuming that the contract is deployed in version N, CodeHash is similar. The contract code corresponding to CodeHash exists in the state database (StateDB) corresponding to version N, and CodeHash of version N+1 also points to the contract code in version N.

[0174] In addition to contract storage, other account storage (including storage of external accounts and contract accounts) can also adopt similar methods, such as Fig.18For the account storage that has not changed in version N, the State Root in the block header of N+1 points to the storage of external accounts or contract accounts such as L, M, N, P, Q, and R in version N. Only the leaf nodes and related intermediate nodes that have changed are stored in the account storage corresponding to version N+1, which will not be described one by one.

[0175] As mentioned above Fig.15 , 16 , 17, according to the implementation scheme of this application, the generated n-ary tree is stable, but this n-ary tree is viewed from a global perspective; all the states under the current block, in fact, many of them are likely to have been updated in a previous block, and have continued to the current block without change. This is similar to Ethereum, which is also called current state and is stored in currentDB. CurrentDB is used to store the latest "current state" data, such as the latest account status, contract code, and contract storage. Moreover, as the block grows, the data in currentDB can be continuously modified.

[0176] As mentioned above Figure 3 and above Fig.18 The content of the blockchain is very redundant. It is an efficient way to store data by referencing the same leaf node and intermediate node that were last updated to the same value in the previous block. Moreover, the state changed in each block is likely to be part of the global state. This is also similar to Ethereum, also known as history state, which is stored in historyDB. historyDB is used to store historical state data, thereby providing a complete historical view of the entire chain.

[0177] Generally speaking, currentDB is stored in memory and historyDB is stored on disk. In addition, in terms of data mutability, the data in currentDB is mutable, while the data in historyDB is immutable.

[0178] It should be noted that the terms currentDB and historyDB are not usually used in official Ethereum documents, but are used by technicians in this field in some discussions and third-party practices to conceptually distinguish different types of data and databases. In contrast, databases such as BlockDB, StateDB, and IndexDB are usually used to describe more specific, physically existing databases or data storage. In other words, currentDB and historyDB tend to represent logical distinctions of data rather than specific physical databases.

[0179] The MPT approach has been adopted Fig.18 As detailed in the example in the example, the hash indexing method is not applicable to the method of setting non-leaf nodes using the key feature value mentioned in the present application. This is because, for example, the aforementioned binary tree with n=2, Fig.15 In the example in , although the pointer field is omitted in the figure, it can be seen from the arrow starting from the left side of an index value in the non-leaf node that the pointer points to the leaf node / non-leaf node of the previous layer (the lower layer in the figure), and the hash value corresponding to the index value is not used to link the upper index with the lower non-leaf node / leaf node. This is because: ① The B+ tree finds the required data item within the time complexity of O(log n) by comparing keywords and following pointers. If the hash value of the lower leaf node / non-leaf node is used as the association, a traversable structure needs to be implemented to compare and retrieve data, which is usually not as efficient as direct pointer tracking; ② Calculating hash values ​​requires CPU resources; in the operation process of B+ tree, such as insertion and deletion, node splitting and merging are often involved; using pointers can quickly change the connection between nodes. If hash values ​​are used, it is necessary to recalculate the hash value and update the upper node after each modification operation, which increases the complexity of the operation; ③ In the B+ tree, data items can be modified directly; if hash values ​​are used to associate nodes, then any small modification of the data will result in a change in the hash value, and all upper nodes that reference this hash value need to be updated, which is inefficient in scenarios with frequent modification operations.

[0180] In this way, pointers provide direct access to memory or disk addresses, which is a necessary feature for databases and file systems, allowing data to be directly located and accessed. Here, "pointers provide direct access to memory or disk addresses" is a general but inaccurate statement. Those skilled in the art know that pointers are addresses in memory, which are concepts in memory and are only valid during program execution, so pointers can provide direct memory access. In contrast, disk is a persistent storage used to store data and remains unchanged even without power. In the process of storing data from memory to disk, pointers in memory are eliminated when serializing and saving to the file system or database, and are replaced by a reference method suitable for long-term storage (such as file path, database record identifier, etc.). This ensures that data can be persisted on disk and can be successfully retrieved and used in the future.

[0181] for Fig.18 In the latter version, the leaf nodes and intermediate nodes that have not changed relative to the previous version refer to the same leaf nodes and intermediate nodes in the version last updated to this value in the latter version. The reference here is achieved by recording the hash value of the lower node in the upper node. Similarly, this method is not applicable to the method of setting non-leaf nodes using the characteristic value of the key in the aforementioned application.

[0182] The present application provides a method for linking a tree structure of blocks of different versions, including:

[0183] The leaf nodes and intermediate nodes in the tree structure of the later version block that have not changed relative to the previous version use pointers in the tree structure of the later version block to link the same leaf nodes and / or intermediate nodes in the version last updated to that value.

[0184] The method in this application is directed to the Fig.15 , 16 , 17 and the corresponding n-ary tree described in the text part. Fig.19 As shown, for the block of version N+1, its n-ary tree structure contains non-leaf nodes with two index values ​​of 00883 and 88485, and the pointer field on the left of 88485 points to the non-leaf nodes with two index values ​​of 84088 and 88485 in the n-ary tree structure of the block of version N. This is because, for the non-leaf nodes with two index values ​​of 00883 and 88485, and the non-leaf nodes with 84088 in the lower layer of the figure, the non-leaf nodes with 88482 and 88485, and the leaf nodes at the bottom layer, there is no change. Therefore, in the n-ary tree structure of the block of version N+1, pointers are used to link the same leaf nodes and intermediate nodes in the version last updated to this value, without repeatedly recording these unchanged tree nodes in the block of version N+1. In the n-ary tree structure of the N+1 version block, the pointer field on the left of 00883 points to the non-leaf node in the N+1 version block that has changed relative to the N version block, and contains the two index values ​​00679 and 00883. In the N version block, it is a non-leaf node with the index value 00883. This is because, in the N+1 version block, the Key-Value of the Key 00002 and the Key-Value of the Key 00679 are added relative to the N version, which causes a series of changes in the tree structure, including the splitting and merging of logical nodes including non-leaf nodes and leaf nodes. The specific changes are as described above and will not be repeated here.

[0185] Similarly, the hash value of the linked lower tree node can also be saved in the non-leaf node. Fig.19 In the figure, there are two non-leaf nodes with index values ​​of 00883 and 88485. The hash value below the index value 88485 is the hash value of the non-leaf node pointed to by the pointer field on the left side of the index value 88485, that is, the n-ary tree structure of the Nth version block contains the hash value of the non-leaf nodes with index values ​​of 84088 and 88485 as a whole, and of course also includes the pointer field and the corresponding hash value.

[0186] For the leaf nodes and intermediate nodes in the tree structure of the later version of the block that have not changed compared to the previous version, including both leaf nodes and intermediate nodes, the same leaf nodes and intermediate nodes in the version where the link was last updated to this value also include the pointer link relationship between them.

[0187] The pointer is for searching in memory and disk. Preferably, the pointer may include the number and version number of the logical page. Generally speaking, the size of the logical page (also called node or block) of the B+ tree is not fixed, but is determined by the specific application scenario and system design. In different database systems and file systems, the node size of the B+ tree may be different. Common node sizes can be 4KB, 8KB, 16KB, etc., which usually correspond to the block size of the file system or the page size of the storage system. Choosing an appropriate page size is to balance the CPU and disk I / O performance. Larger pages can reduce the number of switches between nodes, which can improve the efficiency of large-scale scanning, but it also means that even access to a small amount of data may cause the entire larger node to be loaded into memory. On the other hand, smaller pages mean that more nodes participate in the tree structure, which may increase the height of the tree and increase the number of I / O operations for node search operations, but the amount of data read each time I / O is smaller, which is more beneficial for small-range queries. In many database management systems, such as MySQL's InnoDB storage engine, PostgreSQL, etc., the administrator of the database can configure the size of the B+ tree page to meet specific load and performance requirements.

[0188] In a traditional B+ tree, logical pages (also called nodes) are usually linked to each other in the form of references through specific pointers. These pointers can take several different forms:

[0189] Logical Page Numbers (Page IDs): Each logical page can be assigned a unique identifier or number that can be used as a "pointer" to the page. The pointer field within the node stores the page number of the child node. When the child node needs to be accessed, the page number can be used to locate and read the logical page.

[0190] File offset: Another approach is to use offsets within the file. The starting position of each logical page in the file can be used as a "pointer", and other pages can store these offsets to reference other pages. In many database systems, the size of a page is fixed, so the offset to a page is usually an integer multiple of the page size.

[0191] Memory pointers: When a logical page is loaded into memory, the connections between nodes may be represented by actual memory pointers. However, memory pointers are only useful at runtime, so they are not persisted to disk. Once the logical page needs to be persisted on disk, the relationship between nodes is converted into the corresponding page number or file offset.

[0192] Object references: In an object-oriented programming environment, such as a database implementation using Java or C#, pages may be represented as objects, and pointers between nodes may be object references. However, when these objects need to be persisted to disk, they still need to be converted into page numbers or other forms of persistent references on disk.

[0193] In general, logical page numbers and file offsets are the most commonly used methods because they remain valid after a system reboot or power outage. Memory pointers or object references are only valid in the process's memory space and cannot be used for long-term storage.

[0194] In the embodiments provided in this application, Fig. 20 As shown, each tree node is a logical page, and the logical pages can be linked by pointers, and considering the reference relationship of historical versions, the pointer can include the number and version number of the logical page. For example, in the process of the change of version N+1 relative to version N, two key-values ​​are added, namely 00002 and the corresponding value and 00679 and the corresponding value, then for example, two logical pages p11 and p12 are added, and the version number is after the colon. Since N+1 is relative to the p3:n non-leaf node and its child nodes and grandchild nodes in version N, as well as the p8:n leaf node, there is no change, so in version N+1, it is linked to the corresponding tree node of version N through a pointer, so as to avoid repeated storage of the same logical page in version N+1. Both nodes p11 and p12 are generated in version N+1 (specifically, they are generated by splitting), so the version number can be marked as N+1 after the colon of p11 and p12 respectively. Since version N+1 adds 00002 and its corresponding value and 00679 and its corresponding value, these two key-values ​​cause the contents of the logical pages p7, p4, p2, and p1 to change. Therefore, the version number corresponding to this change is added after the colon after the numbers of these logical pages, which is N+1.

[0195] This has the effect that, in memory and on the hard disk, after determining the referenced logical page through pointers and version numbers, the life cycle from the version number last updated to that value in the referenced logical page to the current version can also be determined.

[0196] The above is a case where version N+1 changes relative to version N. A person skilled in the art can know from the detailed description of the embodiments and the background provided in this application that, from an extended perspective, Fig.21 As shown, in the tree structure of the next version block, pointers are used to link the same leaf nodes and / or intermediate nodes in the version last updated to the value, which may span multiple versions.

[0197] The above solution can be applied not only to contract storage, but also to account storage. In this way, from a broader perspective, the root node of a tree may be the leaf node of another larger tree. For example, the root Storage Root of a contract storage tree is part of the contract account, and this contract account is a leaf node for the StateTree, and the State Root is the root node of this larger tree. Therefore, the leaf nodes and intermediate nodes in the tree structure of the later version block mentioned above that have not changed relative to the previous version, use pointers in the tree structure of the later version block to link the same leaf nodes and / or intermediate nodes in the version that was last updated to the value. This can be expanded to: the tree nodes in the tree structure of the later version block that have not changed relative to the previous version, use pointers in the tree structure of the later version block to link the same tree nodes in the version that was last updated to the value.

[0198] In the 1990s, improvements to a technology could be clearly distinguished as hardware improvements (for example, improvements to the circuit structure of diodes, transistors, switches, etc.) or software improvements (improvements to the method flow). However, with the development of technology, many improvements to the method flow today can be regarded as direct improvements to the hardware circuit structure. Designers almost always obtain the corresponding hardware circuit structure by programming the improved method flow into the hardware circuit. Therefore, it cannot be said that an improvement in a method flow cannot be implemented using a hardware entity module. For example, a programmable logic device (PLD) (such as a field programmable gate array (FPGA)) is such an integrated circuit whose logical function is determined by the user's programming of the device. Designers can "integrate" a digital system on a PLD by programming it themselves, without having to ask a chip manufacturer to design and produce a dedicated integrated circuit chip. Moreover, nowadays, instead of manually making integrated circuit chips, this kind of programming is mostly implemented by "logic compiler" software, which is similar to the software compiler used when developing and writing programs, and the original code before compilation must also be written in a specific programming language, which is called hardware description language (HDL). There is not only one HDL, but many kinds, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, RHDL (Ruby Hardware Description Language), etc. The most commonly used ones are VHDL (Very-High-Speed ​​Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should also know that it is only necessary to program the method flow slightly in the above-mentioned hardware description languages ​​and program it into the integrated circuit, and then it is easy to obtain the hardware circuit that implements the logic method flow.

[0199] The controller can be implemented in any appropriate manner, for example, the controller can take the form of a microprocessor or processor and a computer-readable medium storing a computer-readable program code (such as software or firmware) that can be executed by the (micro)processor, a logic gate, a switch, an application-specific integrated circuit (ASIC), a programmable logic controller, and an embedded microcontroller. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320. The memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art also know that in addition to implementing the controller in a purely computer-readable program code manner, the controller can be implemented in the form of a logic gate, a switch, an application-specific integrated circuit, a programmable logic controller, and an embedded microcontroller by logically programming the method steps. Therefore, this controller can be considered as a hardware component, and the devices included therein for implementing various functions can also be regarded as structures within the hardware component. Or even, the devices for implementing various functions can be regarded as both software modules for implementing the method and structures within the hardware component.

[0200] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a server system. Of course, the present application does not exclude that with the development of computer technology in the future, the computer that implements the functions of the above embodiments may be, for example, a personal computer, a laptop computer, a vehicle-mounted human-computer interaction device, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.

[0201] Although one or more embodiments of the present specification provide method operation steps as described in the embodiments or flow charts, more or less operation steps may be included based on conventional or non-creative means. The order of steps listed in the embodiments is only one way of executing the order of many steps, and does not represent the only execution order. When the device or terminal product in practice is executed, it can be executed in sequence or in parallel according to the method shown in the embodiments or the drawings (for example, a parallel processor or a multi-threaded processing environment, or even a distributed data processing environment). The term "include", "include" or any other variant thereof is intended to cover non-exclusive inclusion, so that the process, method, product or equipment including a series of elements includes not only those elements, but also includes other elements that are not explicitly listed, or also includes elements inherent to such a process, method, product or equipment. In the absence of more restrictions, it is not excluded that there are other identical or equivalent elements in the process, method, product or equipment including the elements. For example, if the words first, second, etc. are used to represent the name, they do not represent any specific order.

[0202] For the convenience of description, the above devices are described in various modules according to their functions. Of course, when implementing one or more of the present specification, the functions of each module can be implemented in the same or more software and / or hardware, or the module implementing the same function can be implemented by a combination of multiple sub-modules or sub-units, etc. The device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0203] The present invention is described with reference to flowcharts and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0204] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0205] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0206] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0207] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.

[0208] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules 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 disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage, graphene storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.

[0209] It should be understood by those skilled in the art that one or more embodiments of the present specification may be provided as a method, system or computer program product. Therefore, one or more embodiments of the present specification may take the form of a complete hardware embodiment, a complete software embodiment or an embodiment combining software and hardware. Moreover, one or more embodiments of the present specification may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0210] One or more embodiments of this specification may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. One or more embodiments of this specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules may be located in local and remote computer storage media, including storage devices.

[0211] Each embodiment in this specification is described in a progressive manner, and the same and similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment. In the description of this specification, the description of the reference terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of this specification. In this specification, the schematic representation of the above terms does not necessarily target the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art can combine and combine the different embodiments or examples described in this specification and the features of different embodiments or examples without contradiction.

[0212] The above description is only an example of one or more embodiments of this specification and is not intended to limit one or more embodiments of this specification. For those skilled in the art, one or more embodiments of this specification may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of this specification shall be included in the scope of the claims.

Claims

1. A method for linking a tree structure of blocks of different versions, comprising: For tree nodes in the tree structure of the later version block that have not changed relative to the previous version, pointers are used in the tree structure of the later version block to link to the same tree nodes in the version that was last updated to that value; The tree structure is an n-ary tree, and the state key-value is inserted into the leaf node at the bottom layer of the n-ary tree in the order of the key, and the non-leaf node is set according to the characteristic value of the key.

2. According to the method of claim 1, the characteristic value of the key is calculated in the following manner: The digest value of the key is calculated, and a number of consecutive bits of a specific value starting from the header, a specific middle bit, or the end of the calculated digest value are taken.

3. The method as claimed in claim 1 further links the lower-level tree nodes through pointers in non-leaf nodes.

4. The method as claimed in claim 1 further stores the hash value of the linked lower tree node in the non-leaf node.

5. The method as claimed in claim 1, for the leaf nodes and intermediate nodes in the tree structure of the later version block that have not changed compared with the previous version, including both leaf nodes and intermediate nodes, the same leaf nodes and intermediate nodes in the version of the link that was last updated to this value also include the pointer link relationship between them. The method of claim 1 , wherein the pointer comprises a number and a version number of the linked logical page.

7. The method of claim 1, wherein the height of the tree is determined.

8. The method as claimed in claim 1 stores indexes and records in leaf nodes, while non-leaf nodes only store indexes but not records.

9. A system for generating an n-ary tree, comprising: processor; and a memory in which a program is stored, wherein when the processor executes the program, the operations of any one of claims 1 to 8 are performed.

10. A storage medium for storing a program, wherein the program, when executed, performs the operations of any one of claims 1 to 8.

Citation Information

Cited By

  • Code-free platform development method based on closed-loop management

    CN121680804A

  • A closed-loop management-based no-code platform development method

    CN121680804B