WO2023160040A1 - 基于区块链的数据处理方法、装置、设备及可读存储介质 - Google Patents

基于区块链的数据处理方法、装置、设备及可读存储介质 Download PDF

Info

Publication number
WO2023160040A1
WO2023160040A1 PCT/CN2022/132559 CN2022132559W WO2023160040A1 WO 2023160040 A1 WO2023160040 A1 WO 2023160040A1 CN 2022132559 W CN2022132559 W CN 2022132559W WO 2023160040 A1 WO2023160040 A1 WO 2023160040A1
Authority
WO
WIPO (PCT)
Prior art keywords
state
account
world
world state
chain
Prior art date
Application number
PCT/CN2022/132559
Other languages
English (en)
French (fr)
Inventor
冯浩铭
颜喆明
屠海涛
何立宝
陈家宝
Original Assignee
腾讯科技(深圳)有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 腾讯科技(深圳)有限公司 filed Critical 腾讯科技(深圳)有限公司
Priority to EP22928300.7A priority Critical patent/EP4394619A1/en
Priority to US18/218,841 priority patent/US20230353393A1/en
Publication of WO2023160040A1 publication Critical patent/WO2023160040A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/2365Ensuring data consistency and integrity
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L9/00Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
    • H04L9/50Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols using hash chains, e.g. blockchains or hash trees
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2246Trees, e.g. B+trees
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2255Hash tables
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/2379Updates performed during online database operations; commit processing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L9/00Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
    • H04L9/08Key distribution or management, e.g. generation, sharing or updating, of cryptographic keys or passwords
    • H04L9/0891Revocation or update of secret information, e.g. encryption key update or rekeying
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L2209/00Additional information or applications relating to cryptographic mechanisms or cryptographic arrangements for secret or secure communication H04L9/00
    • H04L2209/46Secure multiparty computation, e.g. millionaire problem
    • H04L2209/463Electronic voting
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Definitions

  • the present application relates to the field of computer technology, and in particular to a blockchain-based data processing method, device, device, and readable storage medium.
  • the blockchain system is a blockchain network composed of multiple blockchain nodes, and each blockchain node will store the latest on-chain world state corresponding to the blockchain network, that is, the maximum block height in the blockchain After the block is on the chain, the state data of each account in the blockchain network is composed of the state of the world.
  • the embodiment of the present application provides a data processing method, device, device, and readable storage medium, which can maintain the world state of multiple blocks to be uploaded to the chain, and ensure the consistency of the state data of the block chain system.
  • an embodiment of the present application provides a blockchain-based data processing method, which is executed by a computer device, including:
  • the first world state has a chain relationship pointing to the second world state
  • the second world state is the world state corresponding to the parent block of the initial block
  • the first world state The world state and the second world state exist in the world state chain; if the parent block is the block with the largest block height among the chained blocks, the second world state is the consensus root world state; the world state chain in the world state
  • the first world state is the latest on-chain world state; the consensus root world state has a chain relationship pointing to the latest on-chain world state; the latest on-chain world state is used to record the latest world state corresponding to the on-chain block;
  • the consensus result is the result of passing the consensus
  • write the block to be uploaded into the blockchain submit the updated first world state to the latest on-chain world state step by step through the world state chain, and update the updated first world state.
  • the world state is determined as the new consensus root world state, and the new consensus root world state has a chain relationship pointing to the latest on-chain world state after submission.
  • an embodiment of the present application provides a blockchain-based data processing device, which is deployed on computer equipment, including:
  • the initialization module is used to generate the initial block
  • the state creation module is used to create the first world state corresponding to the initial block; the first world state has a chain relationship pointing to the second world state, and the second world state is the world state corresponding to the parent block of the initial block;
  • the first world state and the second world state exist in the world state chain; if the parent block is the block with the largest block height among the chained blocks, the second world state is the consensus root world state; the world state chain
  • the first world state of the chain is the latest on-chain world state;
  • the consensus root world state has a chain relationship pointing to the latest on-chain world state;
  • the latest on-chain world state is used to record the latest world state corresponding to the on-chain block;
  • the first state update module is used to update the first world state according to the transactions in the initial block to obtain the initial update state;
  • the second state update module is used to construct a clean state tree for the initial update state according to the world state chain, and obtain an updated first world state, which includes a clean current world state tree;
  • the consensus module is used to write the first world state root corresponding to the clean current world state tree into the initial block, obtain the block to be uploaded, and send the consensus block to the consensus node, so that the consensus node is based on the first world state root Consensus processing is carried out on the block to be uploaded to the chain, and the consensus result is obtained;
  • the state submission module is used to write the block to be linked into the block chain if the consensus result is the result of passing the consensus, and submit the updated first world state step by step to the latest state of the chained world through the world state chain.
  • the updated first world state is determined as the new consensus root world state, and the new consensus root world state has a chain relationship pointing to the latest on-chain world state after submission.
  • An embodiment of the present application provides a computer device, including: a processor, a memory, and a network interface;
  • the above-mentioned processor is connected to the above-mentioned memory and the above-mentioned network interface, wherein the above-mentioned network interface is used to provide data communication network elements, the above-mentioned memory is used to store computer programs, and the above-mentioned processor is used to call the above-mentioned computer programs to execute the method.
  • the embodiments of the present application provide a computer-readable storage medium, where a computer program is stored in the computer-readable storage medium, and the computer program is adapted to be loaded by a processor and execute the method in the embodiment of the present application.
  • Embodiments of the present application provide a computer program product on the one hand, where the computer program product includes computer programs/instructions, the computer programs/instructions are stored in a computer-readable storage medium, and a processor of a computer device reads from the computer-readable storage medium The computer program/instruction is fetched, and the processor executes the computer program/instruction, so that the computer device executes the method in the embodiment of the present application.
  • a world state chain by constructing a world state chain, it is possible to support maintaining the world state of different block heights or different branches of the same block height at the same time, that is, every time a new block is created, a world state will be created for the new block.
  • the first world state in the world state chain is the latest on-chain world state after the execution of the transaction in the latest block that has been on the chain.
  • the second world state in the world state chain The state is the consensus root world state confirmed by the consensus last time, and the subsequent world state is the world state corresponding to the block that is being consensused.
  • the consensus root world state has a chain relationship pointing to the latest on-chain world state, and is in consensus
  • the world state corresponding to the block of the block has a chain relationship pointing to the world state corresponding to its parent block. If its parent block is an on-chain block, it has a chain relationship pointing to the consensus root world state. Through each The chain relationship of the world state forms a chain structure of the world state chain. Therefore, it can be guaranteed that no matter how many blocks are consensused at the same time, after the block consensus is passed, its corresponding world state will be submitted to the latest on-chain world state step by step according to the chain structure of the world state chain, ensuring the state data of the blockchain system consistency.
  • Fig. 1 is a schematic structural diagram of a block chain node system provided by the embodiment of the present application.
  • Fig. 2a is a schematic structural diagram of a world state provided by an embodiment of the present application.
  • Fig. 2b is a schematic structural diagram of an account state provided by an embodiment of the present application.
  • Fig. 2c is a schematic diagram of a scene of world state management provided by the embodiment of the present application.
  • Fig. 2d is a schematic structural diagram of a world state chain provided by an embodiment of the present application.
  • Fig. 3 is a schematic flow diagram of a blockchain-based data processing method provided by an embodiment of the present application.
  • Figure 4a- Figure 4c is a schematic diagram of a blockchain-based data processing scenario provided by the embodiment of the present application.
  • Fig. 5 is a schematic flowchart of a transaction-based first world status update method provided by the embodiment of the present application.
  • FIG. 6 is a schematic flowchart of a method for constructing a clean world state tree provided by an embodiment of the present application
  • FIG. 7 is a schematic structural diagram of a blockchain-based data processing device provided by an embodiment of the present application.
  • Fig. 8 is a schematic structural diagram of a computer device provided by an embodiment of the present application.
  • Blockchain is a new application mode of computer technology such as distributed data storage, point-to-point transmission, consensus mechanism and encryption algorithm. It can be tampered with and forged, and at the same time, data can be verified, stored and updated.
  • the blockchain is essentially a decentralized database, each node in the database stores the same blockchain, and the blockchain network can distinguish nodes into consensus nodes and business nodes, where consensus nodes are responsible for block The consensus of the entire network.
  • the process of writing transaction data into the ledger in the blockchain network can be as follows: the client sends the transaction data to the business node, and then the transaction data is passed between the business nodes in the blockchain network in the form of a baton until the consensus node After receiving the transaction data, the consensus node will package the transaction data into a block and carry out consensus with other consensus nodes. After the consensus is passed, the block carrying the transaction data will be written into the ledger.
  • Block It is a data packet that carries transaction data (that is, transaction business) on the blockchain network. It is a data structure marked with a timestamp and the hash value of the previous block. The block passes through the consensus mechanism of the network Validate and finalize the transactions in the block.
  • Hash value Also known as information feature value or feature value, the hash value is generated by converting input data of any length into a password through a hash algorithm and performing a fixed output. The original input data cannot be retrieved by decrypting the hash value , which is a one-way encryption function.
  • each block (except the initial block) contains the hash value of the previous block, which is called the parent block of the current block.
  • Hash is the core underlying and most important aspect of potential in blockchain technology, which preserves the authenticity of recorded and viewed data, and the integrity of the blockchain as a whole.
  • a transaction sent by a blockchain account which contains a transaction hash as a unique identifier, including the account address identifying the blockchain account that sent the transaction.
  • State snapshot It represents a snapshot of all state data within a certain range, and a fixed-length hash value. As long as there is any change in any state data, the state snapshot will change, so that the integrity of all state data can be judged.
  • Blockchain account which contains the account address as the unique identifier, and contains the balance as the digital asset of the account in the current world state.
  • Each account has several state data, and the account contains the account state root as the state of all state data snapshot.
  • Status data The data of accounts stored in the blockchain, such as storing how many assets an account has, or data that other smart contracts need to read or update. Each status data is expressed in the form of key-value pairs.
  • On-chain Each block contains several transactions. When a block is inserted into the blockchain data structure of each blockchain node through consensus, it is called on-chain.
  • World state a view composed of the persistent data owned by each account in the blockchain. Since the execution of the transaction itself will modify some of the persistent data of several accounts, each transaction in each block will have A new world state. After each block is chained, the world state of each blockchain node will be updated. After the same block is chained, the world state of each blockchain node must be consistent.
  • MPT Merkle Patricia Trie, Merkle Patricia tree, a tree structure that organizes state data, contains three types of nodes: data nodes, expansion nodes, and branch nodes.
  • the state data includes a state data key and a state data value.
  • the tree data node is the leaf node of the tree structure, which will only appear at the bottom of the MPT, storing the actual state data value;
  • the extension node is the parent node with only one child node, containing a string of any length representing the state data key Part of the tree node, and another tree node hash pointing to the child node;
  • the branch node can have a parent node with 1 to 16 child nodes, and has a hash value array with a capacity of 16, and the 16 positions in the array correspond to 16 entries 0-9-a-f under the system, and each may be used as a tree node hash to point to a child node.
  • the tree node hash is the hash value of the child node in the MPT,
  • State tree The embodiment of this application includes an account state tree and a world state tree, both of which use MPT as the data structure for organizing the state data of the blockchain, and can provide the following operations:
  • the state data value can be queried from the state tree.
  • the tree node query source is a data structure that helps the state tree to quickly find the tree node based on the tree node hash.
  • Each tree node in the state tree is stored in the form of a key-value pair in the database, the storage key is the hash value of the tree node, and the storage value is the tree node, so the tree can be quickly searched from the database according to the tree node hash node.
  • each parent node in the state tree contains the tree node hashes of all its child nodes, all child nodes can be expanded from the database by the parent node.
  • the state data value can be updated to the state tree according to the state data key.
  • each tree node of the state tree is stored in the form of a key-value pair in the database, the storage key is the hash value of the tree node, and the storage value is the tree node. Therefore, when the state tree performs a submit operation, it needs a data structure that uses the tree node hash as the key and the tree node as the value to receive and store key-value pairs. This data structure is called the tree node update cache.
  • FIG. 1 is a schematic structural diagram of a blockchain node system provided by an embodiment of the present application.
  • the blockchain node system shown in FIG. 1 may correspond to a blockchain network, which may include but not limited to a blockchain network corresponding to a consortium chain.
  • the blockchain node system refers to a system for data sharing between blockchain nodes and blockchain nodes.
  • the blockchain node system can include multiple blockchain nodes, and multiple blockchain nodes can specifically Including blockchain node 10a, blockchain node 10b, blockchain node 10c, blockchain node 10d, ..., blockchain node 10n.
  • each blockchain node can receive data sent by the outside world during normal work, and perform block chain processing based on the received data, and can also send data to the outside world.
  • each blockchain node there may be a data connection between each blockchain node, for example, there is a data connection between the blockchain node 10a and the blockchain node 10b, and the blockchain node 10a and the blockchain node 10b There is a data connection between the blockchain nodes 10c, and there is a data connection between the blockchain node 10b and the blockchain node 10c.
  • the blockchain network can realize the data connection between the blockchain nodes based on the node identification.
  • each blockchain node in the blockchain network it has its corresponding node identification, and each of the above blockchain nodes has It can store the node IDs of other blockchain nodes that are connected to itself, so that the obtained data or generated blocks can be broadcast to other blockchain nodes based on the node IDs of other blockchain nodes, such as block A node identification list as shown in Table 1 can be maintained in the chain node 10a, which stores the node names and node identifications of other nodes:
  • the node identification can be the Internet Protocol (IP) address between the networks and any other information that can be used to identify the nodes in the blockchain network.
  • IP Internet Protocol
  • Table 1 only uses the IP address as an example for illustration.
  • blockchain node 10a can send information (e.g., a block) to blockchain node 10b through node identifier 117.116.189.145, and blockchain node 10b can determine through node identifier 117.114.151.174 that the information is provided by blockchain node 10b. sent by node 10a.
  • block chain node 10a, block chain node 10b, block chain node 10c and block chain node 10d can be used as the consensus in the block chain node system node.
  • Consensus nodes in the blockchain node system participate in consensus, that is, consensus on blocks (including a batch of transactions), including generating blocks and voting on blocks; non-consensus nodes do not participate in consensus, but will help spread the consensus Block and voting messages, and mutual synchronization state, etc.
  • the blockchain node can contain the following modules:
  • Each block chain node will receive the transaction sent by the user and cache it in the transaction pool. According to the consensus mechanism, when a block chain node is selected as a block node, the block chain node will be created in memory Create a new block, and pack the transactions in the transaction pool into the new block.
  • Consensus module Pack transactions to generate candidate blocks, and reach a consensus based on the consensus mechanism among various blockchain nodes to generate new blocks.
  • Smart contract container During the execution of the consensus mechanism, each transaction in the block needs to be executed. The essence is the process of executing the smart contract in the transaction. During the execution of the smart contract, it may be necessary to read or update the status data. This module provides execution environment.
  • World state management responsible for maintaining and managing the world state of each block in the consensus.
  • Key-value database persistently store data in the form of key-value pairs, and can quickly find values according to the key.
  • it is responsible for persistently storing the data of each block and tree node storage.
  • Tree node storage refers to each block of the state tree. The hash value of the tree node is the key, and each tree node is the value, so the tree node can be quickly looked up according to the tree node hash.
  • connection method can be directly or indirectly connected through wired communication, or can be directly or indirectly connected through wireless communication, or through other connection methods.
  • connection methods can be directly or indirectly connected through wired communication, or can be directly or indirectly connected through wireless communication, or through other connection methods.
  • the data processing method provided by the embodiment of the present application can be executed by computer equipment, and the computer equipment includes but is not limited to the above-mentioned blockchain nodes (which may be servers or terminals).
  • the above-mentioned server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, and can also provide cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, Cloud servers for basic cloud computing services such as middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms.
  • the above-mentioned terminal may be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch, etc., but is not limited thereto.
  • embodiments of the present application can be applied to various scenarios, including but not limited to scenarios such as cloud technology, artificial intelligence, intelligent transportation, and assisted driving.
  • the block producing node in the blockchain network for example, the blockchain node 10a in the above blockchain node system, after generating the initial block, can create the first world corresponding to the initial block state, the first world state has a chain relationship pointing to the second world state, and the second world state is the world state corresponding to the parent block of the initial block.
  • the first world state and the second world state exist in the world state chain.
  • the parent block is the block with the largest block height among the chained blocks
  • the second world state is the consensus root world state
  • the consensus The root world state has a chain relationship pointing to the latest on-chain world state.
  • the latest on-chain world state is the first world state in the world state chain.
  • the latest on-chain world state is used to record the latest world state corresponding to the on-chain block ; Then, update the first world state according to the transaction in the initial block to obtain the initial update state, construct a clean state tree for the initial update state according to the world state chain, and obtain the updated first world including the clean current world state tree State; write the first world state root corresponding to the clean current world state tree into the initial block, get the block to be linked, and send the consensus block to the consensus node, so that the consensus node treats the chain based on the first world state root
  • the block is processed by consensus to obtain the consensus result; if the consensus result is the consensus result, the block to be linked will be written into the block chain, and the updated first world state will be submitted to the latest uploaded state step by step through the world state chain.
  • the state of the chain world determines the updated first world state as the new consensus root world state, and the new consensus root world state has a chain relationship pointing to the latest on-chain world state after submission.
  • FIG. 2a is a schematic structural diagram of a world state provided by an embodiment of the present application.
  • the world state 20 may include the previous world state pointer 201 , dirty account address set 202 , account state map 203 , world state tree 204 , and tree node cache 205 .
  • the previous world state pointer 201 points to the previous world state of the world state 20, and the previous world state of the world state 20 can be located in the memory through the previous world state pointer 201, and the previous world state pointer of the latest on-chain world state is empty.
  • the dirty account address set 202 refers to a set of account addresses that have been updated in the world state 20 but have not been updated to the account state in the world state tree 204 .
  • the account status mapping 203 refers to the mapping structure from the account address to the account status. In the account status mapping 203, the account status can be quickly searched according to the account address.
  • the world state tree 204 refers to an MPT data structure organized with the account address as the key and the account state root as the value.
  • the account state root refers to the hash value of the root of the account state tree included in the account state corresponding to the account address.
  • the tree node cache 205 includes the previous tree node cache pointer 2051 and the tree node mapping 2052, the previous tree node cache pointer 2051 points to the tree node cache of the previous world state of the world state 20, and the tree node cache of the latest on-chain world state
  • the previous tree node cache pointer points to the tree node storage in the key-value database
  • the tree node mapping 2052 is a mapping structure mapped from tree node hash to tree node, and in the tree node mapping 2052, the tree node can be quickly searched according to the tree node hash.
  • the tree node cache 205 will serve as the tree node query source of the world state tree 204 of the world state 20 and the account state tree of each account state in the account state map 203.
  • the world state tree 204 and the account state tree of each account state can be based on
  • the tree node hash looks up the tree node from the tree node mapping of the tree node cache. When the tree node cannot be found, it will locate the previous tree node cache in the memory according to the previous tree node cache pointer, and continue to use the tree node hash from the previous tree Look up the tree node in the tree node map of the node cache, if it still cannot find it, continue to move forward, and so on, until the previous tree node cache pointer of the most front tree node cache is stored as a tree node pointing to the key-value database, then continue according to the tree node
  • the node hash looks up a tree node from the tree node store.
  • the tree node cache 205 will also be used as the tree node update cache of the account state tree of each account state in the world state tree 204 and account state mapping 203.
  • the world state tree 204 and the account state tree can be submitted, that is, the tree node ha
  • the key and the value of the tree node are updated to the tree node map of the tree node cache.
  • FIG. 2b is a schematic structural diagram of an account status provided by an embodiment of the present application.
  • the account state 21 may include an account address 211 , an account state root 212 , a dirty state data key set 213 , a state data map 214 and an account state tree 215 .
  • the account address 211 is the unique identifier of the account.
  • the account status root 212 is the status tree root of the account status tree 215, that is, the hash value of the root.
  • the dirty state data key set 213 refers to a set of state data keys that have been updated in the account state 21 but have not been updated in the account state tree 215 .
  • the state data mapping 214 refers to a mapping structure from state data keys to state data values, in which the state data values can be quickly searched according to the state data keys.
  • the account status tree 214 is an MPT data structure organized with status data keys as keys and status data values as values.
  • FIG. 2c is a schematic diagram of a world state management scenario provided by an embodiment of the present application.
  • the key-value database 23 of the block node 22 (which can be any blockchain node in the blockchain node system shown in Figure 1, such as the blockchain node 10b) stores the uploaded
  • the block chain data structure 231 of the chain, the block chain data structure 231 contains all blocks that have been on the chain.
  • the key-value database 23 also includes a tree node storage 232.
  • the account status tree corresponding to each account in the blockchain network and the latest Each tree node and its hash value in the world state tree corresponding to the state of the chain are stored.
  • the latest on-chain world state refers to the world state after the execution of the transaction in the latest block that has been on-chain.
  • the block producing node can maintain several blocks of different heights in the consensus in the memory 24, for example, block n+1 with block height n+1, and block with block height n+2 (n+2)a and so on.
  • block n+1 with block height n+1
  • block with block height n+2 n+2 (n+2)a and so on.
  • branch different blocks at the same height, for example, block (n+2)a and block (n+2)b with block height n+2, but in the end only
  • One of the branches forms a consensus in the blockchain nodes of the blockchain network and completes the uplink operation to enter the key-value database 21 .
  • different world states are maintained in the memory 21.
  • the consensus root world state refers to the world state corresponding to the block confirmed by the consensus last time; the world state corresponding to the block under consensus, as the name implies, is that for each block in the consensus, a corresponding world will be created for it State, which represents the query source and update cache of the state data during and after the execution of the transaction in the block.
  • the world state corresponding to the block being consensus has a chain relationship pointing to the world state corresponding to its parent block
  • the block producing node has a chain relationship through the world state corresponding to a block being consensus
  • the world state corresponding to its parent block can be obtained, and then according to the chain relationship of the world state corresponding to its parent block, it can continue to obtain the world state corresponding to the parent block of its parent block.
  • the world state (n+2)a corresponding to the block (n+2)a has a chain relationship pointing to the world state n+1 corresponding to its parent block n+1, and the block producing node 20 obtains the block (n+2) After the world state (n+2)a corresponding to +2)a, the chain relationship of the world state (n+2)a can be obtained, and then the world state n+1 can be obtained according to the chain relationship.
  • the parent block of the consensus block is the block passed by the previous round of consensus
  • the chain relationship of the world state of the consensus block will point to the consensus root world state, so the world of the consensus block
  • the state must be created by directly or indirectly extending the consensus root world state.
  • the consensus root world state there is a chain relationship pointing to the latest on-chain world state. It can be understood that after the new block is consensused, the world state corresponding to the new block will be determined as the consensus root world state, and the original consensus root world state can be cleared, but after the new block is on the chain, only the The latest on-chain world state is updated to obtain the new latest on-chain world state, and its storage address in memory does not need to be changed.
  • FIG. 2d is a schematic structural diagram of a world state chain provided by an embodiment of the present application.
  • the first world state is the latest on-chain world state
  • the latest on-chain world state has no previous world state
  • the previous world state pointer of the latest on-chain world state is empty.
  • the previous tree node cache pointer of the latest on-chain world state cannot point to the tree node cache of the previous world state, but the previous tree node cache pointer of the latest on-chain world state will point to the tree node storage (for example, as shown in Figure 2c above Tree node store 232).
  • the second world state in the world state chain is the consensus root world state
  • the previous world state of the consensus root world state is the latest on-chain world state
  • the previous tree node cache pointer of its tree node cache points to the tree of the latest on-chain world state Node cache.
  • the world state chain starts from the third world state, which is the world state corresponding to the block in the consensus. Its previous world state pointer and the previous tree node cache pointer of the tree node cache point to the world state of the parent block of the block respectively. and a tree node cache of the world state of the parent block.
  • previous world state pointer and the previous tree node cache pointer of the block s world state in two different consensuses point to the same previous world state and the tree node cache within it.
  • the world state chain can branch after the consensus root world state.
  • FIG. 3 is a blockchain-based data processing provided by the embodiment of the application Schematic flow chart of the method.
  • the method may be executed by a block producing node (for example, any blockchain node in the blockchain node system 10 in the above-mentioned embodiment corresponding to FIG. 1 ).
  • the following will take this method executed by a block producing node as an example, wherein the blockchain-based data processing method may at least include the following S101-S104:
  • Each blockchain node can receive transactions, and then cache the transactions in the transaction pool.
  • the block node can be selected according to the consensus mechanism.
  • a block chain node is selected as the block node, a new block will be created in the memory, and the new block contains the hash value of its parent block.
  • you can find its parent block you can find its parent block, and then the block producing node can pack the transactions in the transaction pool into the new block, and get the initial block.
  • the block producing node can create the first world state corresponding to the initial block.
  • the process of creating the first world state corresponding to the initial block can be that the block producing node first obtains the second world state corresponding to its parent block, and then based on the second world state of its parent block To initialize the world state and get the first world state.
  • the parent block of the initial block can only be the latest block in the blockchain.
  • the second world state corresponding to the block is the world state passed by the previous round of consensus, that is, the second world state corresponding to the parent block at this time is the consensus root world state shown in Figure 2c above; if the parent block of the initial block It has not yet been written into the blockchain data structure.
  • the parent block of the initial block should be in consensus, and its corresponding world state is the world state corresponding to the block in consensus shown in Figure 2c above, for example , world state n+1.
  • the first world state in the world state chain is the latest on-chain world state, and the latest on-chain world state is used to record the corresponding blocks of the on-chain The latest world state;
  • the second consensus root world state is the consensus root world state, and the consensus root world state has a chain relationship pointing to the latest on-chain world state.
  • the second world state may be the second in the world state chain
  • the world state, and possibly the world state after the second world state, the first world state is located immediately after the second world state in the world state chain.
  • a feasible implementation method for creating the first world state corresponding to the initial block is: creating the initial world state corresponding to the initial block, the initial world state includes the first previous world state pointer and the first A tree node cache, the first tree node cache contains the first previous tree node cache pointer; then, the first previous world state pointer points to the second world state corresponding to the parent block of the initial block, and the first previous tree node cache The node cache pointer points to the second tree node cache included in the second world state, and the first world state corresponding to the initial block is obtained. It should be noted that the structural composition of the first world state at this time can still refer to the world state 20 shown in Figure 2a above.
  • the block producing node only initializes the first world state pointer and the first Structures such as tree node cache pointer, dirty account address set, account state map, world state tree, and tree node map can be initialized as empty sets first, or can be added to the first world state during subsequent use.
  • first Structures such as tree node cache pointer, dirty account address set, account state map, world state tree, and tree node map can be initialized as empty sets first, or can be added to the first world state during subsequent use.
  • the embodiment of this application is here No restrictions.
  • the world state will be generated according to the world state structure shown in Figure 2a when the world state is created. If there is no corresponding data, it will be created as an empty set by default for example.
  • S102 Update the first world state according to the transactions in the initial block to obtain an initial update state, and construct a clean state tree for the initial update state according to the world state chain to obtain an updated first world state,
  • the updated first world state includes a clean current world state tree.
  • the transaction execution in the initial block will modify some of the state data contained in several accounts in the blockchain.
  • the block producing node can gradually execute each transaction in the initial block, and determine the state data that needs to be modified after each transaction is executed, as The data to be updated, and then update the first world state according to the data to be updated, and finally obtain the initial update state.
  • the account status mapping of the initial update status will contain the account address of the account to be updated and the updated account status. There is a mapping relationship between the account address of the same account and its updated account status.
  • the dirty account address set of the initial update state will include the account address of the account whose state data is updated after the transaction in the initial block is executed.
  • the dirty account address set and account state mapping of the initial update state it is possible to build a clean world state tree corresponding to the initial update state.
  • the world state tree in the initial update state is empty, that is to say, the world state tree in the initial update state has not yet been constructed.
  • the block producing node will find it according to the first previous world state pointer in the initial update state.
  • the second world state first obtain the clean world state tree of the second world state as the clean world state tree, and then construct the second world state tree corresponding to the initial update state according to the first tree node cache and the current state tree root, Add the second-world state tree to the initial update state to obtain the transitional initial update state; submit the full-chain dirty account state to the transitional initial update state to obtain the updated first-world state.
  • the first world state root corresponding to the clean current world state tree refers to the hash value of the tree root of the clean current world state tree.
  • the first world state root can be used as the initial block executed by all accounts in the blockchain network.
  • the block producer will pass the block to be uploaded to the chain through P2P (Peer to Peer, point-to-point) network to the consensus node in the blockchain network, and then the consensus node can first construct the world state corresponding to the block to be uploaded, and then perform the above-mentioned process from S102 to S103 on the constructed world state to obtain the constructed
  • the clean current world state tree corresponding to the state of the world, and then obtain the hash value of its tree root as the verification world state root
  • the consensus node will verify the world state root and the first world state root in the block to be linked Comparison, if they are the same, the verification will pass; if they are different, the verification will fail, and the consensus of the block to be uploaded will fail.
  • the chain world state determines the updated first world state as a new consensus root world state, and the new consensus root world state has a chain relationship pointing to the latest on-chain world state after submission.
  • the block producing node and other blockchain nodes in the blockchain network will write the block to be uploaded into the blockchain.
  • the latest on-chain world state will also be updated.
  • the block producing node needs to submit the updated first world state to the latest on-chain world state step by step according to the order of the world state chain. After the submission is completed, the updated first world state will be determined as the new consensus root world state.
  • the first pre-world state pointer in the new consensus root world state will point to the world state corresponding to its parent block
  • the first pre-tree node cache pointer in the new consensus root world state will also point to the previous tree node cache in the latest on-chain world state.
  • the block producing node 22 can submit the world state n+1 to the consensus root world state after block n+1 consensus is passed, and then submit the consensus root world state Submit to the latest on-chain world state, and get the latest on-chain world state after submission.
  • the world state n+1 will be confirmed as the new consensus root world state, and the original chain relationship pointing to the consensus root world state will be updated to the chain relationship pointing to the latest on-chain world state after submission .
  • the storage address of the latest on-chain world state after submission is still the same as the latest on-chain world state, and the latest on-chain world state after submission is used to represent the world state after the execution of the transaction in block n+1.
  • the original consensus root world state can be deleted.
  • the block producing node when the updated first world state is finally submitted to the latest on-chain world state, the block producing node also needs to submit the submitted latest on-chain world state to the tree node storage, because the tree The node storage belongs to the key-value database, so it can also be considered as submitting to the tree node database.
  • the specific process can be as follows: submit the status of the whole chain dirty account to the latest on-chain world state after submission, and get the clean and latest on-chain world state.
  • the tree node cache in the latest on-chain world state includes the first tree node mapping; update the tree node hash and tree node contained in the first tree node mapping to the tree node database; clear the dirty account in the latest on-chain world state Address set, account status map and first tree node map.
  • FIG. 4a-FIG. 4c is a schematic diagram of a blockchain-based data processing scenario provided by the embodiment of the present application.
  • the block 41 is the latest block in the blockchain 42
  • the latest on-chain world state 400 records the view of the state data corresponding to all accounts in the blockchain network after block 42 is on-chain.
  • the latest on-chain world state 400 except that the previous world state pointer is empty, the dirty account address collection and account state mapping And the tree node mapping is an empty set.
  • the world state tree in the latest on-chain world state 400 is the world state tree corresponding to all the state data of the blockchain at this time.
  • the previous tree node cache pointer of the latest on-chain world state 400 points to the tree
  • the node storage 43 can be understood that each tree node in the world state tree of the latest chained world state 400 and the tree node hash corresponding to the tree node are stored in the tree node storage 43 .
  • the memory of the block producing node 40 also contains the consensus root world state 402, which is actually the corresponding world state after the block 41 consensus is submitted, and the previous world state is the latest on-chain world state 400. It can be seen from Fig. 4a that the previous world state pointer of the consensus root world state 402 points to the latest on-chain world state 400, and the previous tree node cache pointer of the consensus root world state 402 points to the tree node cache 4005.
  • the block producing node 40 After the block producing node 40 receives the block producing command, it will generate a new block 420 with block 41 as the parent block, and the parent hash contained in the new block 420 is the hash value of block 41, and then produce The block node 40 packs part of the transactions in the transaction pool into the new block 420 in order to obtain the initial block 421. Then, the block node 40 can construct the first world state 402 corresponding to the initial block 421.
  • the first world state in the world state 402 will point to the second world state corresponding to the parent block of the initial block 421, because the parent block of the initial block 421 is a chained block, so its corresponding second world state In fact, it is the consensus root world state 401, so the first previous world state pointer of the first world state 402 points to the consensus root world state 401, and the first previous tree node cache pointer points to the tree node cache of the consensus root world state 401.
  • the first Other components of a world state 402, such as the dirty account address set, the world state tree, etc. are all empty sets.
  • the block producing node 40 will execute the transaction in the initial block 421, and then in the process of executing the transaction in the initial block 421, update the first world state 402 to obtain the initial update state 403, wherein the update refers to Write the account address of the account to be updated and the updated account status into the account status mapping of the first world state 402 , and add the account address of the account to be updated to the dirty account address set of the first world state 402 .
  • the state data of account A will be changed, so the account state of account A will be updated accordingly.
  • the block producing node 40 will transfer the account address A corresponding to account A to Write to the dirty account address set of the first world state 402, and then add the mapping relationship between account address A and account state A to the account state mapping of the first world state 402.
  • the initial updated state 403 is obtained.
  • the world state tree of the initial update state 403 has not been constructed yet, and then the block producing node 40 will construct the initial update state 403 to carry out the construction process of the clean world state tree, and obtain a clean current world state tree.
  • the block producing node will clean the current state tree
  • the state tree root corresponding to the world state tree is used as the first world state root and added to the initial block 421 to obtain the block 422 to be linked.
  • the block producing node can send the block 422 to be uploaded to the consensus node in the blockchain network, so that the consensus node can perform consensus on the block 22 to be uploaded based on the first world state root, and obtain the consensus result.
  • the world state corresponding to the block 422 to be uploaded in the block producing node 40 is the updated first world state 404 including the clean current world state tree, and the block producing node 40 will gradually submit the updated first world state 404 to the latest on-chain world state, that is, the updated first world state 404 will be submitted to the consensus root world state 401 first, and then the submitted consensus root world state will be submitted to the latest On-chain world state 400, and finally submit the latest on-chain world state after submission to the tree node storage 43, and the block 422 to be on-chain will also be written into the blockchain 42, becoming the latest on-chain block.
  • the block producing node 40 When updating the first target time state 404 will be used as the new consensus root world state, the block producing node 40 will point its first previous world state pointer to the latest on-chain world state after submission, and set its first previous tree node cache pointer A tree node cache pointing to the latest on-chain world state after submission.
  • FIG. 5 is a schematic flowchart of a transaction-based first-world status update method provided by an embodiment of the present application.
  • the update method is a feasible implementation method of updating the first world state according to the transaction in the initial block described in S102 in the embodiment corresponding to the above-mentioned FIG. 3 to obtain the initial update state.
  • the method can also be executed by a block producing node (for example, any blockchain node in the blockchain node system 10 in the above-mentioned embodiment corresponding to FIG. 1 ).
  • the following will take this method executed by a block producing node as an example, where the first world state update method may at least include the following S201-S205:
  • the block producing node will traverse the initial block, obtain the first transaction in sequence, then execute the first transaction, and then update the first world state according to the execution result of the first transaction , get the first submitted world state, and then get the second transaction, execute the second transaction, and then update the first submitted world state according to the execution result of the second transaction, get the second submitted world state, to By analogy, until all transactions in the initial block are processed, the initial update status is obtained.
  • the processing of the kth transaction is taken as an example for illustration.
  • the block producing node will first create the kth transaction world state corresponding to the kth transaction.
  • its previous world state is the k-1th submitted world state.
  • the kth transaction For the creation of the world state refer to the creation process of the first world state in S101 above, which will not be repeated here.
  • the kth transaction world state has a chain relationship pointing to the k-1th commit world state. It can be understood that for the first transaction, the previous world state is the first world state.
  • the kth transaction world state can contain the account state map and the dirty account address set, but at this time the account state map and the dirty account address set of the kth transaction world state are both Is empty.
  • the block producing node may need to read or update the status data of an account when executing the smart contract in the transaction. At this time, the block producing node will determine the data to be queried or updated.
  • the data to be queried may include the address of the account to be queried and the key of the status data to be queried; the data to be updated may include the address of the account to be updated, the key of the status data to be updated and the value of the status data to be updated.
  • the block producing node can update the state of the k-th transaction world based on the data to be updated, or query the k-th transaction world state based on the data to be queried.
  • the kth transaction is executed, and the kth transaction world state is updated during the execution of the kth transaction.
  • a feasible implementation process for the kth transaction world state update is as follows: : Execute the kth transaction, determine the data to be updated corresponding to the kth transaction during the execution of the kth transaction, that is, the above-mentioned account address to be updated, the status data key to be updated, and the status data value to be updated, and then Obtain the account status corresponding to the account address to be updated according to the state of the kth transaction world, as the account status to be updated; update the mapping relationship between the status data key to be updated and the status data value to be updated to the status data map to be updated, and the status to be updated
  • the state data key is inserted into the set of dirty state data keys to be updated to obtain the current account state; the mapping relationship between the account address to be updated and the current account state is updated to the account state map contained in the kth transaction world state, and the account to be updated
  • the address
  • the account status corresponding to the account address to be updated is obtained according to the kth transaction world status
  • a feasible implementation process of the account status to be updated is: according to the kth transaction world status according to the account address to be updated
  • the account status of the mapping relationship is used as the account status to be updated; if the account status that has a mapping relationship with the account address to be updated is not retrieved during the sequence retrieval of the account status mapping, the status to be updated will be obtained according to the world status tree in the latest on-chain world status.
  • the method for the block producing node to obtain the status of the account to be updated according to the status of the k-th trading world is to first find out whether there is a mapping relationship with the address of the account to be updated in the mapping of the account status of the k-th trading world status. If the account status exists, use the account status as the account status to be updated, and stop subsequent query retrieval; if it does not exist, obtain the previous status of the k-th trading world status according to the previous world status pointer of the k-th trading world status.
  • the world state that is, the k-1th submission of the world state
  • the block producing node continues to search for the account state mapping of the k-1th submission of the world state to see if there is an account state that has a mapping relationship with the account address to be updated.
  • the latest state of the world on the chain does not have the state of the previous world.
  • the status tree retrieve the account status root corresponding to the address to be updated, then create a new account status in memory, initialize the account address of the newly created account status to the account address to be updated, and initialize the account status root of the newly created account status to retrieved account status root, and then use the initialized new account status as the account status to be updated.
  • the kth transaction is executed, and a feasible implementation process for querying the world state of the kth transaction during the execution of the kth transaction is: execute the kth transaction, the kth transaction During the execution of a transaction, determine the data to be queried corresponding to the kth transaction, that is, the account address to be queried and the data key to be queried, and then, according to the account address to be queried, the account status in the kth transaction world state Search in the mapping. If the account status corresponding to the account address to be queried is retrieved, continue to search in the retrieved account status according to the state data key to be queried.
  • the state data value corresponding to the state data key to be queried is retrieved, the The state data value is returned as a result, and no subsequent retrieval is performed; if the state data value corresponding to the state data key to be queried cannot be retrieved, or the account address corresponding to the account address to be queried is not found in the account state map of the kth transaction world state According to the previous world state pointer of the kth transaction world state, it is judged whether there is a previous world state.
  • the previous world state pointer of the kth transaction world state exists, obtain the kth transaction world state according to the previous world state pointer, that is, the k-1th submitted world state above, and then continue according to the address to be queried and the state data to be queried key to retrieve the k-1th submitted world state, if the state data value corresponding to the state data key to be queried is retrieved in the k-1th submitted world state, the subsequent retrieval will be stopped; if the k-1th submitted world state If the state data value corresponding to the state data key to be queried cannot be retrieved in the submitted world state, continue to judge whether there is a previous world state according to the world state pointer before the k-1 submitted world state.
  • the world state of the latest on-chain world state In the status tree retrieve the account status root corresponding to the address to be updated, then create a new account status in memory, initialize the account address of the newly created account status to the account address to be updated, and initialize the account status root of the newly created account status to retrieved account status root, and then use the newly created account status after initialization as the account status to be queried.
  • the account state root of the account state to be queried is empty, it is determined that the state data value corresponding to the state data key to be queried is empty, and subsequent retrieval is stopped. If the account state root of the account state to be queried is not empty, but the account state tree of the account state to be queried is empty, the tree node cache of the latest on-chain world state is used as the tree node query source, and the account state of the account state to be queried As the root of the state tree, create a new account state tree in memory and add it to the account state to be queried; then retrieve the state data value from the account state tree of the account state to be queried according to the state data key to be queried, and the retrieval ends.
  • the kth updated transaction world state is submitted to the k-1th submitted world state, and a feasible implementation process of the kth submitted world state is obtained It is: traverse the account addresses in the dirty account address set included in the kth update transaction world state, and obtain the jth account address in sequence; j is a positive integer less than or equal to I; I is the address included in the kth update transaction world state The total number of account addresses in the dirty account address set; obtain the current account state corresponding to the j-th account address from the account state map contained in the k-th updated transaction world state; obtain the j-th account address according to the k-1th submitted world state The previous account state of the account address; submit the current account state corresponding to the jth account address to the previous account state of the jth account address, and insert the jth account address into the dirty state contained in the k-1th submitted world state Set the account address set to get the jth transition submission world state; when
  • the process of obtaining the previous account state of the j-th account address according to the k-1th submitted world state can be: according to the j-th account address, search in the account state map in the k-1th submitted world state , if the account state that has a mapping relationship with the jth account address is retrieved, it will be used as the reference account state, and then a new account state will be created in the memory, and the newly created account state will be initialized according to the account address of the reference account state and the account state root
  • the account address and account status root of the account status of the account status, and the newly created account status is used as the previous account status of the jth account address; if no account status that has a mapping relationship with the jth account address is retrieved, continue to -1 Submit the account state mapping of the previous world state to retrieve the world state, continue the above retrieval process, if the account state mapping of the latest on-chain world state has been retrieved, no mapping relationship with the jth account address can be retrieved
  • the current account state corresponding to the jth account address includes the first state data mapping
  • the previous account state of the jth account address includes the second state data mapping
  • the jth account address corresponding to Submit the current account state to the previous account state of the jth account address insert the jth account address into the set of dirty account addresses contained in the k-1th submitted world state, and obtain a feasible implementation of the jth transitional submitted world state
  • the process is: update the mapping relationship between the state data key and the state data value in the first state data mapping to the second state data mapping; insert the state data key in the first state data mapping into the jth account address In the dirty state data key set contained in the previous account state, the world state of the jth transition submission is obtained.
  • the initial update state will include the account address that needs to be updated after all transactions in the initial block are executed and the account state after the account address is updated.
  • the dirty account address set in the initial update state will contain all the required Updated account address.
  • FIG. 6 is a schematic flowchart of a method for constructing a clean world state tree provided by an embodiment of the present application.
  • the method for constructing the clean world state tree is the process of constructing the clean state tree according to the initial update state of the world state chain described in S102 in the embodiment corresponding to FIG. A possible implementation of the world state.
  • the method can also be executed by a block producing node (for example, any blockchain node in the blockchain node system 10 in the above-mentioned embodiment corresponding to FIG. 1 ).
  • the following will take this method to be executed by a block producing node as an example, where the clean world state tree construction method may at least include the following S301-S306:
  • All world states managed by block producing nodes can build a corresponding clean world state tree.
  • This clean world state tree construction method is applicable to all world states, and some world states may already contain world state trees. Therefore, in the clean world state tree construction method, it is first necessary to determine whether the world state tree needs to be constructed in the world state tree. When the block producing node constructs a clean world state tree for the initial update state, the block producing node will query the world state tree for the initial update state.
  • the block producing node will directly submit the full chain dirty account state to the initial update state, and obtain the updated first world state including the clean current world state tree.
  • the submitting process reference may be made to the following S306, and no further description will be given here.
  • the block producing node can query forward one by one according to the world state chain, relying on the clean world state of the previous world state in the world state chain to build the second world of the initial update state state tree.
  • the block producing node will first obtain the previous world state of the initial update state according to the first previous world state pointer, that is, the second world state, and then first obtain the clean current world state tree corresponding to the second world state, and use it as a clean The previous world state tree.
  • S304 Construct a clean state tree for the second world state according to the world state chain to obtain a pre-clean world state tree, and use the root of the previous state tree of the pre-clean world state tree as the root of the current state tree.
  • the block producing node will build a clean state tree for the second world state, that is, perform S301-S306 processing on the second world state to obtain a clean current world state tree corresponding to the second world state, and then use it as the initial update state A clean pre-world state tree. Then, the block producing node will use the previous state tree root of the clean world state tree as the current state tree root.
  • S305 Construct a second world state tree corresponding to the initial update state according to the first tree node cache and the current state tree root, and add the second world state tree to the initial update state to obtain a transitional initial update state. .
  • the block producing node will use the first tree node cache as the tree node query source, and then build the second world state tree corresponding to the initial update state based on the current state tree root.
  • the account address in the dirty account address set of the initial update state corresponds to The update account status has not been submitted yet, so it needs to be submitted to get a clean second world state tree, that is, a clean current world state tree.
  • the block producing node will submit the state of the dirty account of the whole chain.
  • the block producing node will sequentially traverse the world state chain to obtain the dirty account address set contained in the xth world state as the xth dirty account address set; x is less than Or a positive integer equal to Z; Z is the sequence number of the transition initial update state in the world state chain; traverse the account addresses in the xth dirty account address set, and obtain the mth account address in sequence; m is less than or equal to the xth account address A positive integer of the total number of account addresses in the set of dirty account addresses; obtain the current account status and previous account status corresponding to the m-th account address; calculate the current account of the m-th account address according to the previous account status of the m-th account address Submit the account dirty state data; when the current account status of each dirty account address
  • a feasible implementation process for submitting account dirty state data to the current account state of the m-th account address according to the previous account state of the m-th account address is: Check the account status tree for the current account status; if the current account status of the m-th account address does not contain an account status tree, or the account status root of the current account status of the m-th account address is not equal to the previous account of the m-th account address The account state root of the state, then establish the specified account state tree according to the tree node cache of the current account state of the m-th account address and the account state root of the previous account state of the m-th account address, and add the specified account state tree to the m-th The current account state of the account address, update the account state root of the current account state of the m-th account address to the account state root of the previous account state of the m-th account address, and obtain the specified account state; if the m-th account address The current account state contains an account state tree, and the account
  • the block producing node can use the transition initial update state as the current world state, and then execute the method of "submitting the state data of the dirty account of the whole chain" for the current world state,
  • the specific steps of this method are: judge whether there is a previous world state according to the previous world state pointer of the current world state, and if there is a previous world state, treat the previous world state as the current world state and continue to execute "submit the state data of the dirty account of the whole chain” method, use the obtained full-chain dirty account address set as the initial full-chain dirty account address set; if there is no previous world state, create an empty initial full-chain dirty account address set in memory.
  • the block producing node can traverse the dirty account address set in the current world state. For each account address, perform the following operations: retrieve the account state from the account state map according to the account address, as Current account state; judge whether there is a previous world state according to the previous world state pointer of the current world state, if there is a previous world state, obtain the previous account state in the previous world state according to the account address, and if there is no previous world state, save the current account state At the same time as the previous account status; take the account status root of the previous account status as the previous account status root, and cache the current account status as the specified account status according to the tree node cache of the current world status; execute the method of "submitting the status data of a single account”; then Insert the account address into the collection of dirty account addresses in the whole chain; when all the account addresses in the dirty account address collection have completed the above operations, the collection of dirty account addresses in the whole chain and the transitional initial update state after submission will be obtained.
  • the account state root of the previous account state is used as the root of the previous account state, and according to the tree node cache of the current world state, the current account state is used as the specified account state to execute the "submit the state data of a single account"
  • the specific steps of the method are: if the account state tree of the specified account state is not empty and the account state root of the specified account state is equal to the previous account state root, skip this step; otherwise, the tree node cache is used as the tree node query source, and the previous account state As the root of the state tree, create a new account state tree in memory, add it to the specified account state, and then update the account state root of the specified account state to the root of the previous account state, and continue the following steps; if the first dirty state of the specified account state If the data key set is empty, return and this process ends.
  • first dirty state data key set of the specified account state is not empty, continue the following steps; traverse the first dirty state data key set of the specified account state, according to each state data Key, retrieve the state data value from the state data map of the specified account state, update each pair of state data key and state data value to the account state tree of the specified account state, continue the following steps; use the tree node cache as the tree node update cache , submit the account state tree of the specified account state, and continue with the following steps; obtain the state root of the account state tree of the specified account state, and update to the account state root of the specified account state; clear the first dirty state data of the specified account state collection of keys.
  • FIG. 7 is a schematic structural diagram of a blockchain-based data processing device provided by an embodiment of the present application.
  • the data processing device may be a computer program (including program code) running on a computer device, for example, the data processing device is an application software; the device may be used to execute the corresponding steps in the data processing method provided by the embodiment of the present application.
  • the data processing device 1 may include: an initialization module 11 , a state creation module 12 , a first state update module 13 , a second state update module 14 , a consensus module 15 and a state submission module 16 .
  • the initialization module 11 is used to generate the initial block
  • the state creation module 12 is used to create the first world state corresponding to the initial block; the first world state has a chain relationship pointing to the second world state, and the second world state is the world state corresponding to the parent block of the initial block; The first world state and the second world state exist in the world state chain; if the parent block is the block with the largest block height among the chained blocks, the second world state is the consensus root world state; the world state chain The first world state in is the latest on-chain world state; the consensus root world state has a chain relationship pointing to the latest on-chain world state; the latest on-chain world state is used to record the latest world state corresponding to the on-chain block;
  • the first state update module 13 is used to update the first world state according to the transaction in the initial block to obtain the initial update state;
  • the second state update module 14 is used to construct a clean state tree for the initial update state according to the world state chain to obtain an updated first world state, which includes a clean current world state tree;
  • Consensus module 15 used to write the first world state root corresponding to the clean current world state tree into the initial block, obtain the block to be uploaded, and send the consensus block to the consensus node, so that the consensus node is based on the first world state
  • the root performs consensus processing on the block to be uploaded to the chain, and obtains the consensus result
  • the state submission module 16 is used to write the block to be chained into the block chain if the consensus result is the result of passing the consensus, and submit the updated first world state step by step to the latest chained world state through the world state chain , determine the updated first world state as the new consensus root world state, and the new consensus root world state has a chain relationship pointing to the latest on-chain world state after submission.
  • the specific implementation of the initialization module 11, the state creation module 12, the first state update module 13, the second state update module 14, the consensus module 15 and the state submission module 16 can refer to the above-mentioned S101- The description of S104 will not be repeated here.
  • the state creation module 12 includes: a creation unit 121 and a pointing unit 122 .
  • the creation unit 121 is used to create an initial world state corresponding to the initial block;
  • the initial world state includes a first previous world state pointer and a first tree node cache;
  • the first tree node cache includes a first previous tree node cache pointer;
  • the pointing unit 122 is used to point the first previous world state pointer to the second world state corresponding to the parent block of the initial block, point the first previous tree node cache pointer to the second tree node cache contained in the second world state, and obtain The first world state corresponding to the initial block.
  • the first status update module 13 includes: a first transaction acquisition unit 131 , a transaction status creation unit 132 , a transaction status update unit 133 , a transaction status submission unit 134 and a world status determination unit 135 .
  • the first transaction acquisition unit 131 is used to sequentially traverse the transactions in the initial block to obtain the kth transaction in the initial block; k is a positive integer less than or equal to H; H is the total number of transactions in the initial block ;
  • the transaction state creation unit 132 is used to create the kth transaction world state corresponding to the kth transaction; the kth transaction world state has a chain relationship pointing to the k-1th submitted world state; when k is 1, the kth transaction world state -1 submit world state as first world state;
  • the transaction state update unit 133 is used to execute the kth transaction, and perform state update processing on the kth transaction world state during the execution of the kth transaction to obtain the kth updated transaction world state;
  • the transaction state submission unit 134 is used to submit the kth updated transaction world state to the k-1th submitted world state to obtain the kth submitted world state if the kth transaction is executed successfully;
  • the world state determination unit 135 is configured to use the Hth submitted world state as the initial update state when k is equal to H.
  • the specific implementation of the first transaction acquisition unit 131, transaction status creation unit 132, transaction status update unit 133, transaction status submission unit 134 and world status determination unit 135 can refer to the pair of S201-S205 in the above-mentioned embodiment corresponding to FIG. 5 description, which will not be repeated here.
  • the kth transaction world state contains account state mapping and dirty account address set
  • the transaction status updating unit 133 includes: an execution subunit 1331 , an account status acquisition subunit 1332 , a first mapping updating subunit 1333 and a second mapping updating unit 1334 .
  • the execution subunit 1331 is used to execute the kth transaction, and determine the data to be updated corresponding to the kth transaction during the execution of the kth transaction; the data to be updated includes the account address to be updated, the status data key to be updated and the data to be updated state data value;
  • the account state acquisition subunit 1332 is used to obtain the account state corresponding to the account address to be updated according to the kth transaction world state as the account state to be updated; the account state to be updated includes the state data map to be updated and the dirty state data key set to be updated ;
  • the first mapping update subunit 1333 is used to update the mapping relationship between the status data key to be updated and the status data value to be updated in the status data mapping to be updated, and insert the status data key to be updated into the set of dirty status data keys to be updated , get the current account status;
  • the second mapping update unit 1334 is used to update the mapping relationship between the account address to be updated and the current account state to the account state mapping contained in the kth transaction world state, and insert the account address to be updated into the kth transaction world state contains In the set of dirty account addresses in , get the kth updated transaction world state.
  • the account state acquisition subunit 1332 is specifically used to search the account state mapping sequence from the kth transaction world state to the latest on-chain world state according to the account address to be updated; If the account status to be updated has a mapping relationship with the account address to be updated, the first retrieved account status that has a mapping relationship with the account address to be updated will be used as the account status to be updated; To update the account status whose account address has a mapping relationship, obtain the root of the state tree to be updated corresponding to the account address to be updated according to the world state tree in the latest on-chain world state, and establish the account to be updated according to the address of the account to be updated and the root of the state tree to be updated state.
  • the specific implementation of the execution subunit 1331, the account status acquisition subunit 1332, the first mapping update subunit 1333 and the second mapping update unit 1334 can refer to the description of S203 in the embodiment corresponding to FIG. to repeat.
  • the transaction status submission unit 134 includes: an address acquisition subunit 1341 , a current account status acquisition subunit 1342 , a previous account status acquisition subunit 1343 , a world status submission subunit 1344 and a world status determination subunit 1345 .
  • the address acquisition subunit 1341 is used to traverse the account addresses in the dirty account address set included in the kth updated transaction world state, and sequentially acquire the jth account address; j is a positive integer less than or equal to 1; I is the kth Update the total number of account addresses in the dirty account address set contained in the transaction world state;
  • the current account state acquisition subunit 1342 is used to obtain the current account state corresponding to the jth account address from the account state map contained in the kth updated transaction world state;
  • the previous account status acquisition subunit 1343 is used to acquire the previous account status of the jth account address according to the k-1th submitted world status;
  • the world state submission subunit 1344 is used to submit the current account state corresponding to the jth account address to the previous account state of the jth account address, and insert the jth account address into the k-1th submitted world state. Dirty account address collection, get the jth transition submission world state;
  • the world state determination subunit 1345 is used to clear the dirty account address set and account state mapping contained in the kth updated transaction world state when j is equal to 1, and submit the Ith transitional world state as the kth submitted world state.
  • the current account state corresponding to the jth account address includes the first state data mapping
  • the previous account state of the jth account address includes the second state data mapping
  • the world state submitting subunit 1345 is specifically used to transfer the first state data to
  • the mapping relationship between state data key and state data value in the mapping is updated to the second state data mapping;
  • the state data key in the first state data mapping is inserted into the dirty state data key contained in the previous account state of the jth account address In the set, get the jth transition submission world state.
  • the specific implementation of the address acquisition subunit 1341, the current account status acquisition subunit 1342, the previous account status acquisition subunit 1343, the world status submission subunit 1344, and the world status determination subunit 1345 can refer to the above-mentioned embodiment corresponding to FIG. 5
  • the description of S204 in will not be repeated here.
  • the second status update module 14 includes: a tree query unit 141 , a first query processing unit 142 , a second query processing unit 143 , a first tree construction unit 144 and a second tree construction unit 145 .
  • a tree query unit 141 configured to perform a world state tree query on the initial update state
  • the first query processing unit 142 is configured to, if the initial update state includes the first world state tree, submit the full chain dirty account state to the initial update state to obtain the updated first world state;
  • the second query processing unit 143 is configured to search for the second world state according to the first previous world state pointer if the initial update state does not contain the first world state tree;
  • the first tree construction unit 144 is configured to construct a clean state tree for the second world state according to the world state chain, and obtain a world state tree before cleaning;
  • the second tree construction unit 145 is used to use the previous state tree root of the clean previous world state tree as the current state tree root;
  • the second tree construction unit 145 is further configured to construct a second world state tree corresponding to the initial update state according to the first tree node cache and the root of the current state tree, and add the second world state tree to the initial update state to obtain a transitional initial update state ;
  • the dirty state submission unit 146 is used to submit the state of the whole chain dirty account to the transitional initial update state to obtain the updated first world state.
  • the dirty state submission unit 146 includes: a dirty data submission subunit 1461 , a root acquisition subunit 1462 , a tree update subunit 1463 and a tree submission subunit 1464 .
  • the dirty data submission subunit 1461 is used to submit the dirty state data of the whole chain to the transitional initial update state, and obtain the submitted transitional initial update state and the set of dirty account addresses of the whole chain;
  • the root acquisition subunit 1462 is used to acquire the account status root corresponding to each full-chain dirty account address in the full-chain dirty account address set according to the submitted transitional initial update state;
  • the tree update subunit 1463 is used to update each full-chain dirty account address and the account state root corresponding to each full-chain dirty account address to the second world state tree to obtain a clean current world state tree;
  • the tree submission subunit 1464 is used to store the updated tree node hash of the clean current world state tree and the association relationship of the updated tree node into the tree node map of the tree node cache in the transitional initial update state after submission, and obtain the updated first world state.
  • the dirty data submission subunit 1461 is specifically used to sequentially traverse the world state chain, and obtain the dirty account address set contained in the xth world state as the xth dirty account address set; x is a positive integer less than or equal to Z; Z is the sequence number of the transition initial update state in the world state chain; traverse the account addresses in the xth dirty account address set, and obtain the mth account address in sequence; m is less than or equal to the xth dirty account address set A positive integer of the total number of account addresses; obtain the current account status and previous account status corresponding to the m-th account address; perform account dirty status data on the current account status of the m-th account address according to the previous account status of the m-th account address Submit processing; when the current account status of each dirty account address in the xth dirty account address set is submitted for account dirty state data, the world state after the xth submission is obtained; the xth dirty account address set Each dirty account address is added to the x-1th dirty account address set on the
  • the dirty data submitting subunit 1461 is also specifically used to query the account status tree of the current account status of the m-th account address; if the current account status of the m-th account address does not contain an account status tree, or the m-th account address If the account state root of the current account state of the account address is not equal to the account state root of the previous account state of the mth account address, then according to the tree node cache of the current account state of the mth account address and the previous account of the mth account address The account state root of the state establishes the specified account state tree, adds the specified account state tree to the current account state of the m-th account address, and updates the account state root of the current account state of the m-th account address to the account state of the m-th account address The account state root of the previous account state, to get the specified account state; if the current account state of the mth account address contains an account state tree, and the account state root of the current account state of the mth account address is
  • the specific implementation manners of the dirty data submission subunit 1461, the root acquisition subunit 1462, the tree update subunit 1463, and the tree submission subunit 1464 can refer to the description of S306 in the above-mentioned embodiment corresponding to FIG. 3 , and will not be repeated here. .
  • the above-mentioned data processing device 1 further includes: a submitting module 17 , an updating module 18 and a clearing module 19 .
  • the submission module 17 is used to submit the state of the dirty account on the whole chain to the latest on-chain world state after submission, to obtain the clean and latest on-chain world state, and the tree node cache in the clean and latest on-chain world state includes the first tree node mapping ;
  • An update module 18 configured to update the tree node hash and the tree node contained in the first tree node mapping to the tree node database;
  • the clearing module 19 is used to clear the dirty account address set, account state map and first tree node map in the latest on-chain world state.
  • FIG. 8 is a schematic structural diagram of a computer device provided by an embodiment of the present application.
  • the data processing apparatus 1 in the embodiment corresponding to the above-mentioned FIG. It may also include: a user interface 1003 , and at least one communication bus 1002 .
  • the communication bus 1002 is used to realize connection and communication between these components.
  • the user interface 1003 may include a display screen (Display) and a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface.
  • the network interface 1004 may include a standard wired interface and a wireless interface (such as a WI-FI interface).
  • the memory 1005 can be a high-speed RAM memory, or a non-volatile memory, such as at least one disk memory.
  • the memory 1005 may also be at least one storage device located away from the aforementioned processor 1001 .
  • the memory 1005 as a computer-readable storage medium may include an operating system, a network communication module, a user interface module, and a device control application program.
  • the network interface 1004 can provide network communication elements; the user interface 1003 is mainly used to provide an input interface for the user; and the processor 1001 can be used to call the device control stored in the memory 1005 application to:
  • the first world state has a chain relationship pointing to the second world state
  • the second world state is the world state corresponding to the parent block of the initial block
  • the first world state The world state and the second world state exist in the world state chain; if the parent block is the block with the largest block height among the chained blocks, the second world state is the consensus root world state; the world state chain in the world state
  • the first world state is the latest on-chain world state; the consensus root world state has a chain relationship pointing to the latest on-chain world state; the latest on-chain world state is used to record the latest world state corresponding to the on-chain block;
  • the consensus result is the result of passing the consensus
  • write the block to be uploaded into the blockchain submit the updated first world state to the latest on-chain world state step by step through the world state chain, and update the updated first world state.
  • the world state is determined as the new consensus root world state, and the new consensus root world state has a chain relationship pointing to the latest on-chain world state after submission.
  • the computer device 1000 described in the embodiment of the present application can execute the description of the data processing method in any one of the embodiments corresponding to FIG. 3 above, and details are not repeated here.
  • the description of the beneficial effect of adopting the same method will not be repeated here.
  • the embodiment of the present application also provides a computer-readable storage medium, and the above-mentioned computer-readable storage medium stores the computer program executed by the aforementioned data processing device 1, and the above-mentioned computer
  • the program includes program instructions.
  • the above-mentioned processor executes the above-mentioned program instructions, it can execute the description of the above-mentioned data processing method in any one of the embodiments corresponding to FIG. 3 above, so details will not be repeated here.
  • the description of the beneficial effect of adopting the same method will not be repeated here.
  • the above-mentioned computer-readable storage medium may be the data processing apparatus provided in any one of the foregoing embodiments or an internal storage unit of the above-mentioned computer equipment, such as a hard disk or memory of the computer equipment.
  • the computer-readable storage medium may also be an external storage device of the computer device, such as a plug-in hard disk equipped on the computer device, a smart memory card (smart media card, SMC), a secure digital (secure digital, SD) card, Flash card (flash card), etc.
  • the computer-readable storage medium may also include both an internal storage unit of the computer device and an external storage device.
  • the computer-readable storage medium is used to store the computer program and other programs and data required by the computer device.
  • the computer-readable storage medium can also be used to temporarily store data that has been output or will be output.
  • the embodiment of the present application also provides a computer program product or computer program, where the computer program product or computer program includes computer instructions, and the computer instructions are stored in a computer-readable storage medium.
  • the processor of the computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes the method provided by any one of the above corresponding embodiments.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Computer Security & Cryptography (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Software Systems (AREA)
  • Computing Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本申请公开了一种基于区块链的数据处理方法、装置、设备及可读存储介质,该方法包括:创建初始区块对应的第一世界状态;根据初始区块中的交易更新第一世界状态,得到初始更新状态,根据世界状态链对初始更新状态进行构建干净状态树处理,得到包含干净现世界状态树的更新后的第一世界状态;将干净现世界状态树对应的第一世界状态根写入初始区块,得到待上链区块,若待上链区块共识通过,则将待上链区块写入区块链中,通过世界状态链将更新后的第一世界状态逐级提交至最新上链世界状态,将更新后的第一世界状态确定为新的共识根世界状态。采用本申请,可以维护多个区块的世界状态,保证状态数据的一致性。

Description

基于区块链的数据处理方法、装置、设备及可读存储介质
本申请要求于2022年2月24日提交中国专利局、申请号202210174690.7、申请名称为“基于区块链的数据处理方法、装置、设备及可读存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及计算机技术领域,尤其涉及一种基于区块链的数据处理方法、装置、设备及可读存储介质。
背景技术
区块链系统是由多个区块链节点组成的区块链网络,每个区块链节点会存储该区块链网络对应的最新上链世界状态,即区块链中的最大区块高度的区块上链后,区块链网络中各个账户所拥有的状态数据共同组成的世界状态。
目前的区块链网络中,区块内交易的执行会修改若干账户所拥有的部分状态数据,因此每当有一个区块上链后,就会有对应有一个新的最新上链世界状态。新区块在共识时,又需要依赖其父区块上链后对应的最新上链世界状态来确定自己上链后对应的最新上链世界状态,因此目前的共识机制中往往仅允许一个区块进行共识。若采用多个区块同时进行共识的共识机制,则往往无法保证区块链系统的状态数据的一致性。
发明内容
本申请实施例提供了一种数据处理方法、装置、设备及可读存储介质,可以维护多个待上链区块的世界状态,保证区块链系统的状态数据的一致性。
本申请实施例一方面提供了一种基于区块链的数据处理方法,该方法由计算机设备执行,包括:
生成初始区块,创建初始区块对应的第一世界状态;第一世界状态具有指向第二世界状态的链式关系,第二世界状态为初始区块的父区块对应的世界状态;第一世界状态和第二世界状态存在于世界状态链中;若父区块为已上链区块中具有最大区块高度的区块,则第二世界状态为共识根世界状态;世界状态链中的第一个世界状态为最新上链世界状态;共识根世界状态具有指向最新上链世界状态的链式关系;最新上链世界状态用于记录已上链区块对应的最新世界状态;
根据初始区块中的交易更新第一世界状态,得到初始更新状态,根据世界状态链对初始更新状态进行构建干净状态树处理,得到更新后的第一世界状态,更新后的第一世界状态包括干净现世界状态树;
将干净现世界状态树对应的第一世界状态根写入初始区块,得到待上链区块,将待上链区块发送至共识节点,以使共识节点基于第一世界状态根对待上链区块进行共识处理,得到共识结果;
若共识结果为共识通过结果,则将待上链区块写入区块链中,通过世界状态链将更新后的第一世界状态逐级提交至最新上链世界状态,将更新后的第一世界状态确定为新的共识根世界状态,新的共识根世界状态具有指向提交后的最新上链世界状态的链式关系。
本申请实施例一方面提供了一种基于区块链的数据处理装置,该装置部署在计算机设备上,包括:
初始化模块,用于生成初始区块;
状态创建模块,用于创建初始区块对应的第一世界状态;第一世界状态具有指向第二世界状态的链式关系,第二世界状态为初始区块的父区块对应的世界状态;第一世界状态和第二世界状态存在于世界状态链中;若父区块为已上链区块中具有最大区块高度的区块,则第二世界状态为共识根世界状态;世界状态链中的第一个世界状态为最新上链世界状态;共识根世界状态具有指向最新上链世界状态的链式关系;最新上链世界状态用于记录已上链区块对应的最新世界状态;
第一状态更新模块,用于根据初始区块中的交易更新第一世界状态,得到初始更新状态;
第二状态更新模块,用于根据世界状态链对初始更新状态进行构建干净状态树处理,得到更新后的第一世界状态,更新后的第一世界状态包括干净现世界状态树;
共识模块,用于将干净现世界状态树对应的第一世界状态根写入初始区块,得到待上链区块,将共识区块发送至共识节点,以使共识节点基于第一世界状态根对待上链区块进行共识处理,得到共识结果;
状态提交模块,用于若共识结果为共识通过结果,则将待上链区块写入区块链中,通过世界状态链将更新后的第一世界状态逐级提交至最新上链世界状态,将更新后的第一世界状态确定为新的共识根世界状态,新的共识根世界状态具有指向提交后的最新上链世界状态的链式关系。
本申请实施例一方面提供了一种计算机设备,包括:处理器、存储器、网络接口;
上述处理器与上述存储器、上述网络接口相连,其中,上述网络接口用于提供数据通信网元,上述存储器用于存储计算机程序,上述处理器用于调用上述计算机程序,以执行本申请实施例中的方法。
本申请实施例一方面提供了一种计算机可读存储介质,上述计算机可读存储介质中存储有计算机程序,上述计算机程序适于由处理器加载并执行本申请实施例中的方法。
本申请实施例一方面提供了一种计算机程序产品,该计算机程序产品包括计算机程序/指令,该计算机程序/指令存储在计算机可读存储介质中,计算机设备的处理器从计算机可读存储介质读取该计算机程序/指令,处理器执行该计算机程序/指令,使得该计算机设备执行本申请实施例中的方法。
本申请实施例中,通过构建世界状态链,可以支持同时维护不同区块高度或者同一区块高度不同分支的世界状态,即每创建一个新的区块,都会为该新区块创建一个世界状态,将该世界状态加入世界状态链中,世界状态链中的第一个世界状态为已上链的最新的区块内的交易执行过后的最新上链世界状态,世界状态链中的第二个世界状态为是上一次被共识确认的共识根世界状态,再往后的世界状态即为正在共识的区块对应的世界状态,共识根世界状态具有指向最新上链世界状态的链式关系,正在共识的区块对应的世界状态具有指向其父区块对应的世界状态的链式关系,若其父区块为已上链区块,则其具有指向共识 根世界状态的链式关系,通过每个世界状态具有的链式关系,从而形成世界状态链的链式结构。因此可以保证无论同时共识多少区块,在区块共识通过后,其对应的世界状态均会按照世界状态链的链式结构逐级提交至最新上链世界状态,保证区块链系统的状态数据的一致性。
附图说明
为了更清楚地说明本申请实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。
图1是本申请实施例提供的一种区块链节点系统的结构示意图;
图2a是本申请实施例提供的一种世界状态的结构示意图;
图2b是本申请实施例提供的一种账户状态的结构示意图;
图2c是本申请实施例提供的一种世界状态管理的场景示意图;
图2d是本申请实施例提供的一种世界状态链的结构示意图;
图3是本申请实施例提供的一种基于区块链的数据处理方法的流程示意图;
图4a-图4c是本申请实施例提供的一种基于区块链的数据处理的场景示意图;
图5是本申请实施例提供的一种基于交易的第一世界状态更新方法的流程示意图;
图6是本申请实施例提供的一种干净世界状态树构建方法的流程示意图;
图7是本申请实施例提供的一种基于区块链的数据处理装置的结构示意图;
图8是本申请实施例提供的一种计算机设备的结构示意图。
具体实施方式
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。
为便于理解,以下将对区块链及其相关概念进行阐述:
区块链:区块链是一种分布式数据存储、点对点传输、共识机制以及加密算法等计算机技术的新型应用模式,主要用于对数据按时间顺序进行整理,并加密成账本,使其不可被篡改和伪造,同时可进行数据的验证、存储和更新。区块链本质上是一个去中心化的数据库,该数据库中的每个节点均存储一条相同的区块链,区块链网络可以将节点区分为共识节点和业务节点,其中共识节点负责区块链全网的共识。对于区块链网络中交易数据被写入账本的过程可以为:客户端发送交易数据至业务节点,随后该交易数据以接力棒的方式在区块链网络中的业务节点之间传递,直到共识节点收到该交易数据,共识节点再将该交易数据打包进区块,与其他共识节点之间进行共识,在共识通过后,将携带该交易数据的区块写入账本。
区块:是在区块链网络上承载交易数据(即交易业务)的数据包,是一种被标记上时间戳和之前一个区块的哈希值的数据结构,区块经过网络的共识机制验证并确定区块中的交易。
哈希值:也称作信息特征值或特征值,哈希值是通过哈希算法将任意长度的输入数据转换为密码并进行固定输出而生成的,不能通过解密哈希值来检索原始输入数据,它是一个单向的加密函数。在区块链中,每个区块(除了初始区块)都包含前继区块的哈希值,前继区块被称为当前区块的父区块。哈希值是区块链技术中的潜力核心基础和最重要的方面,它保留了记录和查看数据的真实性,以及区块链作为一个整体的完整性。
交易:区块链账户发送的交易,内有交易哈希作为唯一标识,包含有账户地址标识所属发送该交易的区块链账户。
状态快照:表示一定范围内的所有状态数据的快照,固定长度的哈希值,只要任何状态数据有任何变化,状态快照均发生变化,以此可以判断所有状态数据的完整性。
账户:区块链账户,内有账户地址作为唯一标识,包含有余额作为现世界状态下该账户的数字资产,每个账户有其若干状态数据,账户含有账户状态根作为其所有状态数据的状态快照。
状态数据:存储于区块链中的账户的数据,例如存储某个账户有多少资产,或者其它智能合约需要读取或者更新的数据,每个状态数据以键值对的形式表示。
上链:每个区块包含若干个交易,当一个区块经过共识插入到每个区块链节点内的区块链数据结构的过程,称为上链。
世界状态:区块链内各个账户所拥有的持久化数据共同组成的视图,由于交易的执行本身会修改若干个账户的部分持久化数据,因此每个区块内的每个交易执行后会有一个新的世界状态,每个区块上链后更是会更新每个区块链节点的世界状态。在同一区块上链后,每个区块链节点的世界状态必然一致。
MPT:Merkle Patricia Trie,默克尔帕特里夏树,一种组织状态数据的树形结构,内含数据节点、拓展节点、分支节点三种节点。其中,状态数据包含有状态数据键和状态数据值。其中,树据节点是树型结构的叶子节点,只会出现在MPT底部,存储着实际的状态数据值;拓展节点是仅有一个子节点的父节点,包含一个任意长度字符串代表状态数据键的一部分,和另一个指向子节点的树节点哈希;分支节点可以有1至16个子节点的父节点,有一个容量为16的哈希值数组,数组中的这16个位置分别对应16进制下的0-9-a-f,并且分别有可能作为树节点哈希而指向一个子节点。其中,树节点哈希是MPT中子节点的哈希值,存储在父节点。
状态树:本申请实施例中包含有账户状态树和世界状态树,均是以MPT作为组织区块链的状态数据的数据结构,可以提供以下操作:
(1)查询:可以根据状态数据键,从状态树中查询出状态数据值,此时需要向状态树提供树节点查询来源。其中,树节点查询来源是帮助状态树以树节点哈希为条件从中快速查找树节点的数据结构。状态树中的每个树节点,在数据库中是以键值对的形式存储,存储键为树节点的哈希值,存储值为树节点,因此可以根据树节点哈希从数据库中快速查找树节点。而因为状态树中每个父节点均包含其所以子节点的树节点哈希,所以可以由父节点从数据库中拓展出其所有子节点。
(2)更新:可以根据状态数据键将状态数据值更新到状态树中。
(3)获取状态树根:计算并获取状态树的树根的哈希值。
(4)提交:把状态树的每个树节点提交到树节点更新缓存中。因为状态树中的每个树节点,在数据库中是以键值对的形式存储,存储键为树节点的哈希值,存储值为树节点。因此,当状态树进行提交操作时,需要一个以树节点哈希为键和以树节点为值,接收键值对并存储的数据结构,此数据结构称为树节点更新缓存。
请参见图1,图1是本申请实施例提供的一种区块链节点系统的结构示意图。如图1所示的区块链节点系统可以对应于区块链网络,该区块链网络可以包括但不限于联盟链所对应的区块链网络。区块链节点系统是指用于进行区块链节点与区块链节点之间数据共享的系统,该区块链节点系统中可以包括多个区块链节点,多个区块链节点具体可以包括区块链节点10a、区块链节点10b、区块链节点10c、区块链节点10d、…、区块链节点10n。其中,每个区块链节点在进行正常工作时可以接收到外界发送的数据,并基于接收到的数据进行区块上链处理,也可以向外界发送数据。为了保证各个区块链节点之间的数据互通,每个区块链节点之间可以存在数据连接,例如区块链节点10a和区块链节点10b之间存在数据连接,区块链节点10a和区块链节点10c之间存在数据连接,区块链节点10b和区块链节点10c之间存在数据连接。
可以理解的是,区块链节点之间可以通过上述数据连接进行数据或者区块传输。区块链网络可以基于节点标识实现区块链节点之间的数据连接,对于区块链网络中的每个区块链节点,均具有与其对应的节点标识,而且上述每个区块链节点均可以存储与自身有相连关系的其他区块链节点的节点标识,以便后续根据其他区块链节点的节点标识,将获取到的数据或生成的区块广播至其他区块链节点,例如区块链节点10a中可以维护一个如表1所示的节点标识列表,该节点标识列表保存着其他节点的节点名称和节点标识:
表1
节点名称 节点标识
节点10a 117.114.151.174
节点10b 117.116.189.145
节点10c 117.114.151.183
节点10d 117.117.125.169
节点10n 117.116.189.125
其中,节点标识可为网络之间互联的协议(Internet Protocol,IP)地址以及其他任意一种能够用于标识区块链网络中节点的信息,表1中仅以IP地址为例进行说明。例如,区块链节点10a可以通过节点标识117.116.189.145向区块链节点10b发送信息(例如,区块),且区块链节点10b可以通过节点标识117.114.151.174确定该信息是由区块链节点10a所发送的。
在区块链中,在将一个区块进行上链之前,该区块必须经过区块链网络中的共识节点进行共识,在共识通过后才能将该区块添加到区块链上。可以理解的是,当区块链被用于政府或者商业机构的一些场景中时,并非区块链中的所有参与节点(即上述区块链节点系统中的区块链节点)都有足够的资源和必要性成为区块链的共识节点。例如,在图1所示的区块链节点系统中,可以将区块链节点10a、区块链节点10b、区块链节点10c和区块链节点10d作为该区块链节点系统中的共识节点。区块链节点系统中的共识节点参与共识,也就是对区块(包含一批交易)进行共识,包括生成区块,对区块进行投票;而非共识节点不参与共识,但会帮助传播区块和投票消息,以及相互同步状态等。
其中,区块链节点可以包含以下模块:
交易池:每个区块链节点会接收用户发送的交易,并缓存至交易池中,根据共识机制某个区块链节点被选为出块节点时,该区块链节点会在内存中创建新区块,并把交易池中的交易打包至新区块内。
共识模块:对交易进行打包生成候选区块,并在各个区块链节点之间,基于共识机制达成共识,产生新区块。
智能合约容器:共识机制执行过程中需要执行区块内的每个交易,本质是执行交易中的智能合约的过程,执行智能合约中可能需要读取或者更新状态数据,本模块为智能合约执行提供执行环境。
世界状态管理:负责对每个共识中区块的世界状态进行维护管理。
键值数据库:以键值对的方式持久化存储数据,可以根据键快速查找值,在本申请中负责持久化存储每个区块的数据和树节点存储,树节点存储即状态树的每个树节点的哈希值为键,每个树节点为值,因此可以根据树节点哈希快速查找树节点。
其中,可以理解的是,上述的数据连接不限定连接方式,可以通过有线通信方式进行直接或间接地连接,也可以通过无线通信方式进行直接或间接地连接,还可以通过其他连接方式,本申请在此不做限制。
可以理解的是,本申请实施例所提供的数据处理方法可以由计算机设备执行,计算机设备包括但不限于上述区块链节点(可以为服务器或者终端)。上述服务器可以是独立的物理服务器,也可以是多个物理服务器构成的服务器集群或者分布式系统,还可以是提供云服务、云数据库、云计算、云函数、云存储、网络服务、云通信、中间件服务、域名服务、安全服务、CDN、以及大数据和人工智能平台等基础云计算服务的云服务器。上述终端可以是智能手机、平板电脑、笔记本电脑、台式计算机、智能音箱、智能手表等,但并不局限于此。
可以理解的是,本申请实施例可应用于各种场景,包括但不限于云技术、人工智能、智慧交通、辅助驾驶等场景。
可以理解的是,在本申请的具体实施方式中,涉及到的状态数据等相关的数据,当本申请以上实施例运用到具体产品或技术中时,需要获得用户许可或者同意,且相关数据的收集、使用和处理需要遵守相关国家和地区的相关法律法规和标准。
如图1所示,区块链网络中的出块节点,例如,上述区块链节点系统中的区块链节点10a,在生成初始区块后,可以创建该初始区块对应的第一世界状态,该第一世界状态具有指向第二世界状态的链式关系,第二世界状态为初始区块的父区块对应的世界状态。此时第一世界状态和第二世界状态存在于世界状态链中,若父区块为已上链区块中具有最大区块高度的区块,则第二世界状态为共识根世界状态,共识根世界状态具有指向最新上链世界状态的链式关系,最新上链世界状态为世界状态链中的第一个世界状态,最新上链世界状态用于记录已上链区块对应的最新世界状态;然后,根据初始区块中的交易更新第一世界状态,得到初始更新状态,根据世界状态链对初始更新状态进行构建干净状态树处理,得到包含干净现世界状态树的更新后的第一世界状态;将干净现世界状态树对应的第一世界状态根写入初始区块,得到待上链区块,将共识区块发送至共识节点,以使共识节点基于第一世界状态根对待上链区块进行共识处理,得到共识结果;若共识结果为共识通过结果,则将待上链区块写入区块链中,通过世界状态链将更新后的第一世界状态逐级提交至最新上链世界状态,将更新后的第一世界状态确定为新的共识根世界状态,新的共识根世界状态具有指向提交后的最新上链世界状态的链式关系。
为更好地理解上述世界状态管理的过程,请先参见图2a,图2a是本申请实施例提供的一种世界状态的结构示意图,如图2a所示,世界状态20可以包含有前世界状态指针201、脏账户地址集合202、账户状态映射203、世界状态树204、树节点缓存205。其中,前世界状态指针201指向世界状态20的前世界状态,可以通过前世界状态指针201在内存中定位世界状态20的前世界状态,上述最新上链世界状态的前世界状态指针为空。其中,脏账户地址集合202是指世界状态20内经过更新但还未更新到世界状态树204中的账户状态的账户地址的集合。其中,账户状态映射203是指由账户地址映射到账户状态的映射结构,在账户状态映射203中,可以根据账户地址快速查找账户状态。其中,世界状态树204是指以账户地址为键,以账户状态根为值进行组织的MPT数据结构。其中,账户状态根是指账户地址对应的账户状态中包含的账户状态树的树根的哈希值。其中,树节点缓存205包含有前树节点缓存指针2051和树节点映射2052,前树节点缓存指针2051指向世界状态20的前世界状态的树节点缓存,上述最新上链世界状态的树节点缓存的前树节点缓存指针指向键值数据库中的树节点存储;树节点映射2052为由树节点哈希映射到树节点的映射结构,在树节点映射2052中可以根据树节点哈希快速查找树节点。树节点缓存205会作为世界状态20的世界状态树204和账户状态映射203中的每个账户状态的账户状态树的树节点查询来源,世界状态树204和每个账户状态的账户状态树可以根据树节点哈希从树节点缓存的树节点映射中查找树节点,当未能找到树节点时,会根据前树节点缓存指针在内存中定位前树节点缓存,并继续根据树节点哈希从前树节点缓存的树节点映射中查找树节点,仍然找不到则继续向前定位,如此类推,直到最前的树节点缓存的前树节点缓存指针为指向键值数据库的树节点存储,则继续根据树节点哈希从树节点存储中查找树节点。树节点缓存205还会作为世界状态树204和账户状态映射203中的每个账户状态的账户状态树的树节点更新缓存,世界状态树204和账户状态树可以进行提交操作,即以树节点哈希为键和以树节点为值更新到树节点缓存的树节点映射中。
请一并参见图2b,图2b是本申请实施例提供的一种账户状态的结构示意图。如图2b所示,账户状态21可以包含有账户地址211、账户状态根212、脏状态数据键集合213、状态数据映射214以及账户状态树215。其中,账户地址211是账户的唯一标识。其中,账户状态根212是账户状态树215的状态树根,也就是其树根的哈希值。其中,脏状态数据键集合213是指账户状态21中经过更新但未更新到账户状态树215的状态数据的键的集合。其中,状态数据映射214是指由状态数据键映射到状态数据值的映射结构,在状态数据映射214中可以根据状态数据键快速查找状态数据值。其中,账户状态树214是以状态数据键为键,以状态数据值为值进行组织的MPT数据结构。
本申请实施例提供的方法,可以通过上述图2a所示的结构来构建世界状态,通过上述图2b所示的结构来构建账户状态,然后对构建出的账户状态和世界状态进行管理,为便于理解,请一并参见图2c,图2c是本申请实施例提供的一种世界状态管理的场景示意图。如图2a所示,出块节点22(可以为上述图1所示的区块链节点系统中的任一区块链节点,例如区块链节点10b)的键值数据库23中存储着已上链的区块链数据结构231,该区块链数据结构231中包含了所有已经上链的区块。此外,键值数据库23中还包含有树节点存储232,树节点存储232中,以树节点哈希值为键、树节点为值对区块链网络中每个账户对应的账户状态树以及最新上链世界状态对应的世界状态树中的每个树节点及其哈希值进行存储。其中,最新上链世界状态是指已上链的最新的区块内的交易执行过后的世界状态。
如图2c所示,出块节点可以在内存24中维护正在共识中的若干不同高度的区块,例如区块高度n+1的区块n+1,区块高度为n+2的区块(n+2)a等等。当然按照共识机制的执行还有可能在同一高度下不同区块分支,例如,区块高度为n+2的区块(n+2)a和区块(n+2)b,但最终只会有其中一个分支在区块链网络的区块链节点中形成共识并完成上链操作进入到键值数据库21。除此以外,在内存21中还维护着不同的世界状态,除了包含有最新上链世界状态,还维护有共识根世界状态以及正在共识的区块对应的世界状态。其中,共识根世界状态是指上一次被共识确认的区块对应的世界状态;正在共识的区块对应的世界状态,顾名思义,就是对于每个共识中的区块,会为其创建相应的世界状态,代表该区块内的交易执行过程中和执行后的状态数据的查询来源和更新缓存。由图2c可知,正在共识的区块对应的世界状态均具有指向其父区块对应的世界状态的链式关系,出块节点通过某个正在共识的区块对应的世界状态具有的链式关系,就可以获取到其父区块对应的世界状态,然后根据其父区块对应的世界状态具有的链式关系,就可以继续获取到其父区块的父区块对应的世界状态。例如,区块(n+2)a对应的世界状态(n+2)a具有指向其父区块n+1对应的世界状态n+1的链式关系,出块节点20获取区块(n+2)a对应的世界状态(n+2)a后,就可以获取世界状态(n+2)a具有的链式关系,然后根据该链式关系获取世界状态n+1。当正在共识的区块的父区块为上一轮共识通过的区块时,该正在共识的区块的世界状态的链式关系就会指向共识根世界状态,因此正在共识的区块的世界状态必定是由共识根世界状态直接或间接延伸创建出来。而在共识根世界状态中,则具有指向最新上链世界状态的链式关系。可以理解,新的区块被共识后,新的区块对应的世界状态就会被确定为共 识根世界状态,原来的共识根世界状态就可以被清空了,但是新区块上链后只需对最新上链世界状态进行更新,得到新的最新上链世界状态即可,其在内存中的存储地址无需更改。
可以理解,世界状态的链式关系可以由其前树世界状态指针和前树节点缓存指针体现,每个世界状态通过前世界状态指针指向前世界状态,并且通过树节点缓存的前树节点缓存指针指向前世界状态的树节点缓存,最前的世界状态的前世界状态指针为空和树节点缓存的前树节点缓存指针指向键值数据库的树节点存储,以此形成世界状态链。为便于理解,可以一并参见图2d,图2d是本申请实施例提供的一种世界状态链的结构示意图。如图2d所示,在世界状态链中,第一个世界状态就为最新上链世界状态,最新上链世界状态没有前世界状态了,因此最新上链世界状态的前世界状态指针为空,此外,最新上链世界状态的前树节点缓存指针也无法指向前世界状态的树节点缓存,但是最新上链世界状态的前树节点缓存指针会指向树节点存储(例如,上述图2c所示的树节点存储232)。世界状态链中的第二个世界状态为共识根世界状态,共识根世界状态的前世界状态为最新上链世界状态,其树节点缓存的前树节点缓存指针,指向最新上链世界状态的树节点缓存。世界状态链从第三个世界状态开始,就是共识中的区块对应的世界状态,其前世界状态指针和树节点缓存的前树节点缓存指针,分别指向该区块的父区块的世界状态和父区块的世界状态的树节点缓存。当然,也允许两个不同的共识中的区块的世界状态的前世界状态指针和树节点缓存的前树节点缓存指针,指向同一个前世界状态和其内的树节点缓存。换言之,世界状态链在共识根世界状态之后,可以出现分支。
对于正在共识的区块对应的世界状态,最终会被提交至最新上链世界状态,当正在共识的区块完成共识后,其对应的世界状态就会成为新的共识根世界状态,具有指向最新上链世界状态的链式关系,为便于理解本申请实施例对世界状态管理的具体过程,进一步地,请参见图3,图3是本申请实施例提供的一种基于区块链的数据处理方法的流程示意图。其中,该方法可以由出块节点(例如,上述图1所对应实施例中的区块链节点系统10中的任一区块链节点)执行。以下将以本方法由出块节点执行为例进行说明,其中,该基于区块链的数据处理方法至少可以包括以下S101-S104:
S101,生成初始区块,创建所述初始区块对应的第一世界状态。
每个区块链节点可以接收交易,然后将交易缓存至交易池中。区块链网络中可以根据共识机制来选择出块节点,当某个区块链节点被选作出块节点时,就会在内存中创建新区块,新区块中包含有其父区块哈希值,通过父区块哈希值,就可以查找其父区块,然后出块节点可以把交易池中的交易打包至新区块内,就得到了初始区块。此时,出块节点就可以创建初始区块对应的第一世界状态了。
在一种可能的实现方式中,创建初始区块对应的第一世界状态的过程可以是出块节点先获取其父区块对应的第二世界状态,然后基于其父区块的第二世界状态来进行世界状态初始化,得到第一世界状态。需要说明的是,如果初始区块的父区块已经被写入了区块链数据结构中,此时初始区块的父区块只可能是区块链中最新上链的区块,父区块对应的第二世界状态即为上一轮共识通过的世界状态,即此时父区块对应的第二世界状态为上述图2c所示的共识根世界状态;如果初始区块的父区块还未被写入区块链数据结构中,此时初 始区块的父区块应该正在共识中,其对应的世界状态即为上述图2c所示的正在共识的区块对应的世界状态,例如,世界状态n+1。可以理解,第一世界状态和第二世界状态均位于世界状态链中,世界状态链中的第一个世界状态为最新上链世界状态,最新上链世界状态用于记录已上链区块对应的最新世界状态;第二个共识根世界状态为共识根世界状态,共识根世界状态具有指向最新上链世界状态的链式关系,换言之,第二世界状态可能是世界状态链中的第二个世界状态,也可能是第二个世界状态后的世界状态,第一世界状态在世界状态链中就位于第二世界状态之后。
在一种可能的实现方式中,创建初始区块对应的第一世界状态的一个可行实施方法为:创建初始区块对应的初始世界状态,该初始世界状态包含有第一前世界状态指针和第一树节点缓存,该第一树节点缓存包含有第一前树节点缓存指针;然后,将第一前世界状态指针指向初始区块的父区块对应的第二世界状态,将第一前树节点缓存指针指向第二世界状态包含的第二树节点缓存,得到初始区块对应的第一世界状态。需要说明的是,此时第一世界状态的结构组成依然可以参见上述图2a所示的世界状态20,此时出块节点仅初始化了第一世界状态的第一前世界状态指针和第一前树节点缓存指针,脏账户地址集合、账户状态映射、世界状态树以及树节点映射等结构可以先初始化为空集合,也可以后续使用时在添加进第一世界状态中,本申请实施例在此不做限制。不过后续统一以世界状态在创建时就会按照如图2a所示的世界状态结构来生成世界状态,没有对应的数据就默认创建为空集合为例进行阐述。
S102,根据所述初始区块中的交易更新所述第一世界状态,得到初始更新状态,根据世界状态链对所述初始更新状态进行构建干净状态树处理,得到更新后的第一世界状态,所述更新后的第一世界状态包括干净现世界状态树。
初始区块中的交易执行会修改区块链中若干个账户包含的部分状态数据,出块节点可以逐步执行初始区块中的每笔交易,确定每笔交易执行后需要修改的状态数据,作为待更新数据,然后根据待更新数据来更新第一世界状态,最终得到初始更新状态。此时的初始更新状态的账户状态映射中就将包含有需要更新的账户的账户地址以及更新后的账户状态,同一账户的账户地址和其更新后的账户状态之间具有映射关系,后续出块节点在访问第一世界状态时,就可以根据账户的账户地址,在账户状态映射中快速获取该账户对应的更新后的账户状态。同时,初始更新状态的脏账户地址集合中会包含有在初始区块中的交易执行完毕后,状态数据发生更新的账户的账户地址。有了初始更新状态的脏账户地址集合和账户状态映射,就可以去构建初始更新状态对应的干净现世界状态树了。
此时的初始更新状态中的世界状态树为空,也就是说初始更新状态中的世界状态树还未被构建,此时出块节点会根据初始更新状态中的第一前世界状态指针查找到第二世界状态,先获取到第二世界状态的干净的世界状态树,作为干净前世界状态树,然后根据第一树节点缓存和现状态树根构建初始更新状态对应的第二世界状态树,将第二世界状态树添加到初始更新状态,得到过渡初始更新状态;对过渡初始更新状态进行全链脏账户状态提交处理,得到更新后的第一世界状态。
S103,将所述干净现世界状态树对应的第一世界状态根写入所述初始区块,得到待上链区块,将所述共识区块发送至共识节点,以使所述共识节点基于所述第一世界状态根对所述待上链区块进行共识处理,得到共识结果。
干净现世界状态树对应的第一世界状态根是指干净现世界状态树的树根的哈希值,此时第一世界状态根可以作为初始区块执行后区块链网络中所有账户包含的状态数据的状态快照。当第一世界状态根被写入初始区块后,出块节点对区块的打包完成,就得到了待上链区块,随后,出块节点会将该待上链区块经过P2P(Peer to Peer,点对点)网络传送到区块链网络中的共识节点,随后共识节点可以先构建该待上链区块对应的世界状态,然后对构建的世界状态进行上述S102至S103的过程,得到构建的世界状态对应的干净现世界状态树,再获取其树根的哈希值作为校验世界状态根,共识节点会将校验世界状态根和待上链区块中的第一世界状态根进行比较,若相同,则校验通过;若不同,则校验失败,待上链区块的共识失败。
S104,若所述共识结果为共识通过结果,则将所述待上链区块写入区块链中,通过所述世界状态链将所述更新后的第一世界状态逐级提交至最新上链世界状态,将所述更新后的第一世界状态确定为新的共识根世界状态,所述新的共识根世界状态具有指向提交后的最新上链世界状态的链式关系。
倘若待上链区块共识通过,出块节点和区块链网络中的其他区块链节点均会将待上链区块写入区块链中,上述提到,新的区块上链后,最新上链世界状态也会更新,此时出块节点需要将更新后的第一世界状态按照世界状态链的顺序,逐级提交至最新上链世界状态。提交完成后,更新后的第一世界状态就将被确定为新的共识根世界状态,此时新的共识根世界状态中的第一前世界状态指针会从其父区块对应的世界状态指向最新上链世界状态,新的共识根世界状态中的第一前树节点缓存指针也会指向最新上链世界状态中的前树节点缓存。例如,上述图2c所示的世界状态链中,出块节点22可以在区块n+1共识通过后,将世界状态n+1提交至共识根世界状态,然后将提交后的共识根世界状态提交至最新上链世界状态,得到提交后的最新上链世界状态。提交完成后,世界状态n+1就会被确认为新的共识根世界状态,原本具有的指向共识根世界状态的链式关系会被更新为指向提交后的最新上链世界状态的链式关系。提交后的最新上链世界状态的存储地址依然和最新上链世界状态相同,提交后的最新上链世界状态用于表征区块n+1内的交易执行后的世界状态。可选的,原本的共识根世界状态就可以删除了。
在一种可能的实现方式中,当更新后的第一世界状态最终提交至最新上链世界状态后,出块节点还需要将提交后的最新上链世界状态提交至树节点存储中,因为树节点存储属于键值数据库,因此也可以认为是提交至树节点数据库,具体过程可以为:对提交后的最新上链世界状态进行全链脏账户状态提交处理,得到干净最新上链世界状态,干净最新上链世界状态中的树节点缓存中包括第一树节点映射;将第一树节点映射包含的树节点哈希和树节点更新到树节点数据库;清空干净最新上链世界状态中的脏账户地址集合、账户状态映射和第一树节点映射。
为便于理解上述过程,请一并参见图4a-图4c,图4a-图4c是本申请实施例提供的一种基于区块链的数据处理的场景示意图。如图4a所示,在出块节点40(可以为上述图2c所示的出块节点22)中,区块41是区块链42中最新被上链的区块,则最新上链世界状态400记录的就是区块42上链后区块链网络中所有账户对应的状态数据的视图,此时最新上链世界状态400中除了前世界状态指针为空以外,脏账户地址集合、账户状态映射以及树节点映射均为空集合,最新上链世界状态400中的世界状态树即是区块链此时所有状态数据对应的世界状态树,最新上链世界状态400的前树节点缓存指针指向树节点存储43,可以理解,最新上链世界状态400的世界状态树中的每个树节点以及树节点对应的树节点哈希均存储在树节点存储43中。此外,出块节点40的内存中还包含有共识根世界状态402,该共识根世界状态402其实就是区块41共识提交后对应的世界状态,其前世界状态就为最新上链世界状态400,由图4a可知,共识根世界状态402的前世界状态指针指向最新上链世界状态400,共识根世界状态402的前树节点缓存指针指向树节点缓存4005。
为便于更好地阐述本方法,请一并参见图4b。假设此时没有正在共识的区块。出块节点40在接收到出块命令后,就将生成以区块41为父区块的新区块420,该新区块420中包含的父哈希即为区块41的哈希值,然后出块节点40将交易池中的部分交易按序打包进了新区块420中,就得到了初始区块421,随后,出块节点40可以构建初始区块421对应的第一世界状态402,第一世界状态402中的第一世界状态会指向初始区块421的父区块对应的第二世界状态,因为初始区块421的父区块为已上链区块,因此其对应的第二世界状态其实为共识根世界状态401,因此第一世界状态402的第一前世界状态指针指向共识根世界状态401,第一前树节点缓存指针指向共识根世界状态401的树节点缓存,此时,第一世界状态402的其他组成,例如脏账户地址集合、世界状态树等皆为空集合。然后,出块节点40会执行初始区块421中的交易,然后在执行初始区块421中的交易的过程中,对第一世界状态402进行更新,得到初始更新状态403,其中,更新是指将需要更新的账户的账户地址以及更新后的账户状态写入第一世界状态402的账户状态映射中,将需要更新的账户的账户地址添加至第一世界状态402的脏账户地址集合中。例如,交易1执行后,会更改账户A的状态数据,因此账户A的账户状态会相应的更新,假设更新后的账户状态为账户状态A,出块节点40会将账户A对应的账户地址A写入第一世界状态402的脏账户地址集合中,然后将账户地址A和账户状态A的映射关系添加至第一世界状态402的账户状态映射中。等到初始区块421中的所有交易执行完毕后,就得到初始更新状态403了。此时,初始更新状态403的世界状态树还没有被构建,然后出块节点40会构建初始更新状态403进行干净世界状态树构建处理,得到干净现世界状态树,最后,出块节点将干净现世界状态树对应的状态树根作为第一世界状态根,添加进初始区块421中,就得到待上链区块422。随后,出块节点就可以将待上链区块422发送给区块链网络中的共识节点,让共识节点基于第一世界状态根对待上链区块22进行共识,得到共识结果。
请一并参见图4c。图4c所示,当共识结果为共识通过结果,此时出块节点40中待上链区块422对应的世界状态为包含干净现世界状态树的更新后的第一世界状态404,出块节点40会将更新后的第一世界状态404逐渐提交至最新上链世界状态,即将更新后的第一 世界状态404先提交至共识根世界状态401,再将提交后的共识根世界状态提交至最新上链世界状态400,最后将提交后的最新上链世界状态提交至树节点存储43中,待上链区块422也会被写入区块链42中,成为最新上链的区块,此时更新第一目标时间状态404会被作为新的共识根世界状态,出块节点40会将其第一前世界状态指针指向提交后的最新上链世界状态,将其第一前树节点缓存指针指向提交后的最新上链世界状态的树节点缓存。
采用本申请实施例提供的方法,在区块执行过程中更新状态数据时,不需要记录状态数据变更的旧值,而且对于执行失败的交易不需要进行状态数据的回滚操作,节省了系统开销。
请参见图5,图5是本申请实施例提供的一种基于交易的第一世界状态更新方法的流程示意图。其中,该更新方法是上述图3所对应实施例中S102所述的根据初始区块中的交易更新第一世界状态,得到初始更新状态的一种可行实现方法。其中,该方法同样可以由出块节点(例如,上述图1所对应实施例中的区块链节点系统10中的任一区块链节点)执行。以下将以本方法由出块节点执行为例进行说明,其中,该第一世界状态更新方法至少可以包括以下S201-S205:
S201,顺序遍历初始区块中的交易,获取所述初始区块中的第k个交易;k为小于或等于H的正整数;H为所述初始区块中的交易的总数量。
当初始区块中包含有多个交易时,出块节点会遍历初始区块,顺序获取第一个交易,然后执行第一个交易,再根据第一个交易的执行结果来更新第一世界状态,得到第一个提交世界状态,然后再获取第二个交易,执行第二个交易,再根据第二个交易的执行结果来更新第一个提交世界状态,得到第二个提交世界状态,以此类推,直至处理完初始区块中的所有交易,就得到初始更新状态了。为便于理解,以处理第k个交易为例进行说明。
S202,创建所述第k个交易对应的第k个交易世界状态;所述第k个交易世界状态具有指向第k-1个提交世界状态的链式关系;k为1时,所述第k-1个提交世界状态为第一世界状态。
出块节点会先创建第k个交易对应的第k个交易世界状态,对于第k个交易世界状态来说,其前世界状态就为第k-1个提交世界状态,此时第k个交易世界状态的创建可以参见上述S101中第一世界状态的创建过程,这里不再进行赘述。第k个交易世界状态具有指向第k-1个提交世界状态的链式关系。可以理解,对于第一个交易来说,其前世界状态就为第一世界状态。
S203,执行所述第k个交易,在第k个交易执行的过程中对所述第k个交易世界状态进行状态更新处理,得到第k个更新交易世界状态。
由上述图2b所示的账户状态的结构可知,第k个交易世界状态可以包含有账户状态映射和脏账户地址集合,只是此时第k个交易世界状态的账户状态映射和脏账户地址集合皆为空。在第k个交易执行的过程中,出块节点在执行交易中的智能合约时,可以需要读取或者更新某个账户的状态数据,此时出块节点会确定待查询数据或者待更新数据。其中,待查询数据可以包含待查询账户地址和待查询状态数据键;待更新数据可以包括待更新账户地址、待更新状态数据键和待更新状态数据值。然后,出块节点可以基于待更新数据来 对第k个交易世界状态进行状态更新处理,或者,基于待查询数据来对第k个交易世界状态进行查询处理。
在一种可能的实现方式中,执行第k个交易,在第k个交易执行的过程中对第k个交易世界状态进行状态更新处理,得到第k个更新交易世界状态的一个可行实施过程为:执行第k个交易,在第k个交易执行的过程中确定第k个交易对应的待更新数据,即上述所说的待更新账户地址、待更新状态数据键和待更新状态数据值,然后根据第k个交易世界状态获取待更新账户地址对应的账户状态,作为待更新账户状态;将待更新状态数据键和待更新状态数据值的映射关系更新到待更新状态数据映射中,将待更新状态数据键插入到待更新脏状态数据键集合中,得到现账户状态;将待更新账户地址和现账户状态的映射关系更新到第k个交易世界状态包含的账户状态映射中,将待更新账户地址插入到第k个交易世界状态包含的脏账户地址集合中,得到第k个更新交易世界状态。
在一种可能的实现方式中,根据第k个交易世界状态获取待更新账户地址对应的账户状态,作为待更新账户状态的一个可行实施过程为:根据待更新账户地址对第k个交易世界状态至最新上链世界状态进行账户状态映射顺序检索;若在账户状态映射顺序检索的过程中检索到与待更新账户地址具有映射关系的账户状态,则将最先检索到的与待更新账户地址具有映射关系的账户状态作为待更新账户状态;若在账户状态映射顺序检索的过程中未检索到与待更新账户地址具有映射关系的账户状态,则根据最新上链世界状态中的世界状态树获取待更新账户地址对应的待更新状态树根,根据待更新账户地址和待更新状态树根建立待更新账户状态。具体来说,出块节点可以根据第k个交易世界状态获取待更新账户状态的方法为,先在第k个交易世界状态的账户状态映射中去查找是否存在与待更新账户地址具有映射关系的账户状态,如果存在,就将该账户状态作为待更新账户状态,停止后续的查询检索;如果不存在,就根据第k个交易世界状态的前世界状态指针获取到第k个交易世界状态的前世界状态,也就是第k-1个提交世界状态,然后出块节点继续查找第k-1个提交世界状态的账户状态映射,看是否存在与待更新账户地址具有映射关系的账户状态,存在就直接获取,停止后续的查询检索;不存在就继续获取前世界状态,以此类推,直至出块节点一直查找到最新上链世界状态的账户状态映射,倘若最新上链世界状态的账户状态映射中也不存在与待更新账户地址具有映射关系的账户状态,上述可知,最新上链世界状态没有前世界状态了,此时出块节点就可以根据待更新账户地址,从最新上链世界状态的世界状态树中去检索待更新地址对应的账户状态根,然后在内存中新建一个账户状态,并将新建账户状态的账户地址初始化为待更新账户地址,将新建账户状态的账户状态根初始化为检索到的账户状态根,然后将初始化后的新建账户状态作为待更新账户状态。
在一种可能的实现方式中,执行第k个交易,在第k个交易执行的过程中对第k个交易世界状态进行查询处理的一个可行实施过程为:执行第k个交易,在第k个交易执行的过程中确定第k个交易对应的待查询数据,即上述所说的待查询账户地址和待查询状态数据键,然后,根据待查询账户地址在第k个交易世界状态的账户状态映射中进行检索,如果检索得到待查询账户地址对应的账户状态,就根据待查询状态数据键在检索得到的账户状态中继续检索,如果检索得到待查询状态数据键对应的状态数据值,就将该状态数据值 作为结果返回,不再进行后续检索;如果检索不到待查询状态数据键对应的状态数据值,或者没有在第k个交易世界状态的账户状态映射中检索到待查询账户地址对应的账户状态,就根据第k个交易世界状态的前世界状态指针判断是否存在前世界状态。如果第k个交易世界状态的前世界状态指针存在,就根据前世界状态指针获取第k个交易世界状态,即上述第k-1个提交世界状态,然后继续根据待查询地址和待查询状态数据键对第k-1个提交世界状态进行检索,如果在第k-1个提交世界状态中检索到待查询状态数据键对应的状态数据值,就停止后续的检索;如果在第k-1个提交世界状态中检索不到待查询状态数据键对应的状态数据值,就继续根据第k-1个提交世界状态前世界状态指针判断是否存在前世界状态。以此类推,倘若一直检索到最新上链世界状态,在最新上链世界状态中的账户状态映射中依然没有获取到待查询状态数据键对应的状态数据值,就从最新上链世界状态的世界状态树中去检索待更新地址对应的账户状态根,然后在内存中新建一个账户状态,并将新建账户状态的账户地址初始化为待更新账户地址,将新建账户状态的账户状态根初始化为检索到的账户状态根,然后将初始化后的新建账户状态作为待查询账户状态。倘若待查询账户状态的账户状态根为空,则确定待查询状态数据键对应的状态数据值为空,停止后续的检索。倘若待查询账户状态的账户状态根不为空,但是待查询账户状态的账户状态树为空,则以最新上链世界状态的树节点缓存作为树节点查询来源,以待查询账户状态的账户状态根作为状态树根,在内存中新建账户状态树,加入到待查询账户状态中;然后在根据待查询状态数据键从待查询账户状态的账户状态树中检索出状态数据值,检索结束。
S204,若所述第k个交易执行成功,则将所述第k个更新交易世界状态提交至所述第k-1个提交世界状态,得到第k个提交世界状态。
在一种可能的实现方式中,若第k个交易执行成功,则将第k个更新交易世界状态向第k-1个提交世界状态进行提交,得到第k个提交世界状态的一个可行实施过程为:遍历第k个更新交易世界状态包含的脏账户地址集合中的账户地址,顺序获取第j个账户地址;j为小于或等于I的正整数;I为第k个更新交易世界状态包含的脏账户地址集合中的账户地址的总数量;从第k个更新交易世界状态包含的账户状态映射中获取第j个账户地址对应的现账户状态;根据第k-1个提交世界状态获取第j个账户地址的前账户状态;将第j个账户地址对应的现账户状态提交至第j个账户地址的前账户状态,将第j个账户地址插入到第k-1个提交世界状态包含的脏账户地址集合,得到第j个过渡提交世界状态;当j等于I时,清空第k个更新交易世界状态包含的脏账户地址集合和账户状态映射,将第I个过渡提交世界状态作为第k个提交世界状态。其中,根据第k-1个提交世界状态获取第j个账户地址的前账户状态的过程,可以为:根据第j个账户地址在第k-1个提交世界状态中的账户状态映射中进行检索,如果检索得到与第j个账户地址具有映射关系的账户状态,则将其作为参考账户状态,然后在内存中新建账户状态,并根据参考账户状态的账户地址和账户状态根,来初始化刚新建的账户状态的账户地址和账户状态根,把刚新建的账户状态作为第j个账户地址的前账户状态;如果没有检索到与第j个账户地址具有映射关系的账户状态,就继续在第k-1个提交世界状态的前世界状态的账户状态映射进行检索,继续上述检索过程,倘若一直检索到最新上链世界状态的账户状态映射,都没有检索到与第j个账户地址 具有映射关系的账户状态,就在最新上链世界状态的世界状态树中进行检索,得到第j个账户地址对应的账户状态根,然后在内存中新建账户状态,并根据第j个账户地址和从世界状态树中获取的账户状态根,来初始化刚新建的账户状态的账户地址和账户状态根,把刚新建的账户状态作为第j个账户地址的前账户状态。
在一种可能的实现方式中,第j个账户地址对应的现账户状态包含第一状态数据映射,第j个账户地址的前账户状态包含第二状态数据映射,将第j个账户地址对应的现账户状态提交至第j个账户地址的前账户状态,将第j个账户地址插入到第k-1个提交世界状态包含的脏账户地址集合,得到第j个过渡提交世界状态的一个可行实施过程为:将第一状态数据映射中的状态数据键和状态数据值的映射关系,更新到第二状态数据映射中;将第一状态数据映射中的状态数据键插入到第j个账户地址的前账户状态包含的脏状态数据键集合中,得到第j个过渡提交世界状态。
S205,当k等于H时,将第H个提交世界状态作为初始更新状态。
通常情况下,初始更新状态中将包含有初始区块内所有交易执行完后,需要更新的账户地址以及该账户地址更新后的账户状态,初始更新状态的脏账户地址集合中将包含有所有需要更新的账户地址。
请参见图6,图6是本申请实施例提供的一种干净世界状态树构建方法的流程示意图。其中,该干净世界状态树构建方法是上述图3所对应实施例中S102所述的根据世界状态链对初始更新状态进行构建干净状态树处理,得到包含干净现世界状态树的更新后的第一世界状态的一种可行实现方法。其中,该方法同样可以由出块节点(例如,上述图1所对应实施例中的区块链节点系统10中的任一区块链节点)执行。以下将以本方法由出块节点执行为例进行说明,其中,该干净世界状态树构建方法至少可以包括以下S301-S306:
S301,对初始更新状态进行世界状态树查询。
出块节点管理的所有世界状态,都可以构建对其对应的干净的世界状态树,该干净世界状态树构建方法适用于所有世界状态,而某些世界状态中可能已经包含有世界状态树了,因此在该干净世界状态树构建方法中,需要先确定需要构建干净世界状态树的世界状态中是否包含有世界状态树。当出块节点针对初始更新状态进行构建干净世界状态树处理时,出块节点会对初始更新状态进行世界状态树查询。
S302,若所述初始更新状态包含第一世界状态树,则对所述初始更新状态进行全链脏账户状态提交处理,得到所述更新后的第一世界状态。
倘若初始更新状态中包含有第一世界状态树,则出块节点将直接对初始更新状态进行全链脏账户状态提交处理,得到包含干净现世界状态树的更新后的第一世界状态。该提交过程可以参考下述S306,这里先不进行展开描述。
S303,若所述初始更新状态未包含所述第一世界状态树,则根据所述第一前世界状态指针查找第二世界状态。
倘若初始更新状态中没有包含第一世界状态树,则出块节点可以根据世界状态链逐个向前进行查询,依赖世界状态链中之前的世界状态的干净世界状态来构建初始更新状态的第二世界状态树。首先,出块节点会先根据第一前世界状态指针获取到初始更新状态的前 世界状态,也就是第二世界状态,然后先获取第二世界状态对应的干净现世界状态树,将其作为干净前世界状态树。
S304,根据世界状态链对所述第二世界状态进行构建干净状态树处理,得到干净前世界状态树,将所述干净前世界状态树的前状态树根作为现状态树根。
出块节点会对第二世界状态进行构建干净状态树处理,即对第二世界状态进行S301-S306的处理过程,得到第二世界状态对应的干净现世界状态树,然后将其作为初始更新状态的干净前世界状态树。然后,出块节点会将干净前世界状态树的前状态树根作为现状态树根。
S305,根据第一树节点缓存和所述现状态树根构建所述初始更新状态对应的第二世界状态树,将所述第二世界状态树添加到所述初始更新状态,得到过渡初始更新状态。
出块节点会将第一树节点缓存作为树节点查询来源,然后基于现状态树根构建初始更新状态对应的第二世界状态树,此时初始更新状态的脏账户地址集合中的账户地址对应的更新账户状态还未被提交,因此需要将其进行提交,才能得到干净的第二世界状态树,即干净现世界状态树。
S306,对所述过渡初始更新状态进行全链脏账户状态提交处理,得到所述更新后的第一世界状态。
通常情况下,无论是获取到了初始更新状态对应的第一世界状态树或者第二世界状态树后,出块节点均会进行全链脏账户状态提交处理。以包含第二世界状态树的过渡初始更新状态为例,出块节点会顺序遍历世界状态链,获取第x个世界状态包含的脏账户地址集合,作为第x个脏账户地址集合;x为小于或等于Z的正整数;Z为过渡初始更新状态在世界状态链中的顺序序数;遍历第x个脏账户地址集合中的账户地址,顺序获取第m个账户地址;m为小于或等于第x个脏账户地址集合中账户地址的总数量的正整数;获取第m个账户地址对应的现账户状态和前账户状态;根据第m个账户地址的前账户状态对第m个账户地址的现账户状态进行账户脏状态数据提交处理;当第x个脏账户地址集合中每个脏账户地址的现账户状态均进行账户脏状态数据提交处理后,得到第x个提交后的世界状态;将第x个脏账户地址集合中每个脏账户地址添加至第x-1个链上脏账户地址集合,得到第x个链上脏账户地址集合;x为1时,第x-1个链上脏账户地址集合为空集合;当x等于Z时,将第x个链上脏账户地址集合作为全链脏账户地址集合,将第x个提交后的世界状态作为提交后的过渡初始更新状态。
在一种可能的实现方式中,根据第m个账户地址的前账户状态对第m个账户地址的现账户状态进行账户脏状态数据提交处理的一个可行实施过程为:对第m个账户地址的现账户状态进行账户状态树查询;若第m个账户地址的现账户状态不包含有账户状态树,或第m个账户地址的现账户状态的账户状态根不等于第m个账户地址的前账户状态的账户状态根,则根据第m个账户地址的现账户状态的树节点缓存和第m个账户地址的前账户状态的账户状态根建立指定账户状态树,将指定账户状态树添加至第m个账户地址的现账户状态,将第m个账户地址的现账户状态的账户状态根更新为第m个账户地址的前账户状态的账户状态根,得到指定账户状态;若第m个账户地址的现账户状态包含有账户状态树,且 第m个账户地址的现账户状态的账户状态根等于第m个账户地址的前账户状态的账户状态根,则将第m个账户地址的现账户状态作为指定账户状态;若指定账户状态的第一脏状态数据键集合不为空,则从指定账户状态的状态数据映射中获取第一脏状态数据键集合中脏状态数据键对应的状态数据值,将第一脏状态数据键集合中脏状态数据键和第一脏状态数据键集合中脏状态数据键对应的状态数据值更新到指定账户状态的账户状态树,得到包含更新账户状态树的指定账户状态;将包含更新账户状态树的指定账户状态的账户状态根更新为将更新账户状态树的状态树根;清空包含更新账户状态树的指定账户状态的脏状态数据键集合;将更新账户状态树的更新树节点哈希和更新树节点的关联关系存储至第x个世界状态。
在一种可能的实现方式中,上述过程的实际实现可以为:出块节点可以将过渡初始更新状态作为现世界状态,然后针对现世界状态执行“提交全链脏账户的状态数据”的方法,该方法的具体步骤为:根据现世界状态的前世界状态指针判断是否存在前世界状态,如果存在前世界状态则把前世界状态视为现世界状态继续执行“提交全链脏账户的状态数据”的方法,将得到的全链脏账户地址集合作为初始全链脏账户地址集合;如果不存在前世界状态则在内存中新建为空的初始全链脏账户地址集合。在得到初始全链脏账户地址集合后,出块节点可以遍历现世界状态的脏账户地址集合,对于每个账户地址,分别执行以下操作:根据账户地址从账户状态映射上检索出账户状态,作为现账户状态;根据现世界状态的前世界状态指针判断是否存在前世界状态,如果存在前世界状态则根据账户地址在前世界状态中获取前账户状态,如果不存在前世界状态则把现账户状态同时作为前账户状态;把前账户状态的账户状态根作为前账户状态根,并根据现世界状态的树节点缓存,现账户状态作为指定账户状态执行“提交单个账户的状态数据”的方法;然后把账户地址插入到处理全链脏账户地址集合中;当脏账户地址集合中的所有账户地址均完成上述操作后,就得到了全链脏账户地址集合和提交后的过渡初始更新状态。
在一种可能的实现方式中,把前账户状态的账户状态根作为前账户状态根,并根据现世界状态的树节点缓存,现账户状态作为指定账户状态执行“提交单个账户的状态数据”的方法的具体步骤为:如果指定账户状态的账户状态树不为空并且指定账户状态的账户状态根等于前账户状态根则跳过本步骤,否则以树节点缓存作为树节点查询来源,以前账户状态根作为状态树根,在内存中新建账户状态树,加入到指定账户状态中,再把指定账户状态的账户状态根更新为前账户状态根,继续以下步骤;如果指定账户状态的第一脏状态数据键集合为空则返回且本流程结束,如果指定账户状态的第一脏状态数据键集合不为空则继续以下步骤;遍历指定账户状态的第一脏状态数据键集合,根据每个状态数据键,从指定账户状态的状态数据映射中检索出状态数据值,把每对状态数据键和状态数据值更新到指定账户状态的账户状态树,继续以下步骤;把树节点缓存作为树节点更新缓存,对指定账户状态的账户状态树进行提交操作,继续以下步骤;获取指定账户状态的账户状态树的状态根,并更新到指定账户状态的账户状态根;清空指定账户状态的第一脏状态数据键集合。
通过本申请实施例提供的方法,通过构建世界状态链来同时维护不同区块高度或者同一区块高度不同分支的世界状态,兼容需要多区块同时共识的共识机制,可以保证区块链系统的状态数据的一致性
请参见图7,图7是本申请实施例提供的一种基于区块链的数据处理装置的结构示意图。该数据处理装置可以是运行于计算机设备的一个计算机程序(包括程序代码),例如该数据处理装置为一个应用软件;该装置可以用于执行本申请实施例提供的数据处理方法中的相应步骤。如图7所示,该数据处理装置1可以包括:初始化模块11、状态创建模块12、第一状态更新模块13、第二状态更新模块14、共识模块15以及状态提交模块16。
初始化模块11,用于生成初始区块;
状态创建模块12,用于创建初始区块对应的第一世界状态;第一世界状态具有指向第二世界状态的链式关系,第二世界状态为初始区块的父区块对应的世界状态;第一世界状态和第二世界状态存在于世界状态链中;若父区块为已上链区块中具有最大区块高度的区块,则第二世界状态为共识根世界状态;世界状态链中的第一个世界状态为最新上链世界状态;共识根世界状态具有指向最新上链世界状态的链式关系;最新上链世界状态用于记录已上链区块对应的最新世界状态;
第一状态更新模块13,用于根据初始区块中的交易更新第一世界状态,得到初始更新状态;
第二状态更新模块14,用于根据世界状态链对初始更新状态进行构建干净状态树处理,得到更新后的第一世界状态,更新后的第一世界状态包括干净现世界状态树;
共识模块15,用于将干净现世界状态树对应的第一世界状态根写入初始区块,得到待上链区块,将共识区块发送至共识节点,以使共识节点基于第一世界状态根对待上链区块进行共识处理,得到共识结果;
状态提交模块16,用于若共识结果为共识通过结果,则将待上链区块写入区块链中,通过世界状态链将更新后的第一世界状态逐级提交至最新上链世界状态,将更新后的第一世界状态确定为新的共识根世界状态,新的共识根世界状态具有指向提交后的最新上链世界状态的链式关系。
其中,初始化模块11、状态创建模块12、第一状态更新模块13、第二状态更新模块14、共识模块15以及状态提交模块16的具体实现方式可以参见上述图3所对应实施例中对S101-S104的描述,这里不再进行赘述。
其中,状态创建模块12,包括:创建单元121以及指向单元122。
创建单元121,用于创建初始区块对应的初始世界状态;初始世界状态包含有第一前世界状态指针和第一树节点缓存;第一树节点缓存包含有第一前树节点缓存指针;
指向单元122,用于将第一前世界状态指针指向初始区块的父区块对应的第二世界状态,将第一前树节点缓存指针指向第二世界状态包含的第二树节点缓存,得到初始区块对应的第一世界状态。
其中,创建单元121以及指向单元122的具体实现方式可以参见上述图3所对应实施例中对S101的描述,这里不再进行赘述。
其中,第一状态更新模块13,包括:第一交易获取单元131、交易状态创建单元132、交易状态更新单元133、交易状态提交单元134以及世界状态确定单元135。
第一交易获取单元131,用于顺序遍历初始区块中的交易,获取初始区块中的第k个交易;k为小于或等于H的正整数;H为初始区块中的交易的总数量;
交易状态创建单元132,用于创建第k个交易对应的第k个交易世界状态;第k个交易世界状态具有指向第k-1个提交世界状态的链式关系;k为1时,第k-1个提交世界状态为第一世界状态;
交易状态更新单元133,用于执行第k个交易,在第k个交易执行的过程中对第k个交易世界状态进行状态更新处理,得到第k个更新交易世界状态;
交易状态提交单元134,用于若第k个交易执行成功,则将第k个更新交易世界状态提交至第k-1个提交世界状态,得到第k个提交世界状态;
世界状态确定单元135,用于当k等于H时,将第H个提交世界状态作为初始更新状态。
其中,第一交易获取单元131、交易状态创建单元132、交易状态更新单元133、交易状态提交单元134以及世界状态确定单元135的具体实现方式可以参见上述图5所对应实施例中对S201-S205的描述,这里不再进行赘述。
其中,第k个交易世界状态包含有账户状态映射和脏账户地址集合;
交易状态更新单元133,包括:执行子单元1331、账户状态获取子单元1332、第一映射更新子单元1333以及第二映射更新单元1334。
执行子单元1331,用于执行第k个交易,在第k个交易执行的过程中确定第k个交易对应的待更新数据;待更新数据包括待更新账户地址、待更新状态数据键和待更新状态数据值;
账户状态获取子单元1332,用于根据第k个交易世界状态获取待更新账户地址对应的账户状态,作为待更新账户状态;待更新账户状态包含有待更新状态数据映射和待更新脏状态数据键集合;
第一映射更新子单元1333,用于将待更新状态数据键和待更新状态数据值的映射关系更新到待更新状态数据映射中,将待更新状态数据键插入到待更新脏状态数据键集合中,得到现账户状态;
第二映射更新单元1334,用于将待更新账户地址和现账户状态的映射关系更新到第k个交易世界状态包含的账户状态映射中,将待更新账户地址插入到第k个交易世界状态包含的脏账户地址集合中,得到第k个更新交易世界状态。
其中,账户状态获取子单元1332,具体用于根据待更新账户地址对第k个交易世界状态至最新上链世界状态进行账户状态映射顺序检索;若在账户状态映射顺序检索的过程中检索到与待更新账户地址具有映射关系的账户状态,则将最先检索到的与待更新账户地址具有映射关系的账户状态作为待更新账户状态;若在账户状态映射顺序检索的过程中未检索到与待更新账户地址具有映射关系的账户状态,则根据最新上链世界状态中的世界状态 树获取待更新账户地址对应的待更新状态树根,根据待更新账户地址和待更新状态树根建立待更新账户状态。
其中,执行子单元1331、账户状态获取子单元1332、第一映射更新子单元1333以及第二映射更新单元1334的具体实现方式可以参见上述图5所对应实施例中对S203的描述,这里不再进行赘述。
其中,交易状态提交单元134,包括:地址获取子单元1341、现账户状态获取子单元1342、前账户状态获取子单元1343、世界状态提交子单元1344以及世界状态确定子单元1345。
地址获取子单元1341,用于遍历第k个更新交易世界状态包含的脏账户地址集合中的账户地址,顺序获取第j个账户地址;j为小于或等于I的正整数;I为第k个更新交易世界状态包含的脏账户地址集合中的账户地址的总数量;
现账户状态获取子单元1342,用于从第k个更新交易世界状态包含的账户状态映射中获取第j个账户地址对应的现账户状态;
前账户状态获取子单元1343,用于根据第k-1个提交世界状态获取第j个账户地址的前账户状态;
世界状态提交子单元1344,用于将第j个账户地址对应的现账户状态提交至第j个账户地址的前账户状态,将第j个账户地址插入到第k-1个提交世界状态包含的脏账户地址集合,得到第j个过渡提交世界状态;
世界状态确定子单元1345,用于当j等于I时,清空第k个更新交易世界状态包含的脏账户地址集合和账户状态映射,将第I个过渡提交世界状态作为第k个提交世界状态。
其中,第j个账户地址对应的现账户状态包含第一状态数据映射,第j个账户地址的前账户状态包含第二状态数据映射,世界状态提交子单元1345,具体用于将第一状态数据映射中状态数据键和状态数据值的映射关系,更新到第二状态数据映射中;将第一状态数据映射中的状态数据键插入到第j个账户地址的前账户状态包含的脏状态数据键集合中,得到第j个过渡提交世界状态。
其中,地址获取子单元1341、现账户状态获取子单元1342、前账户状态获取子单元1343、世界状态提交子单元1344以及世界状态确定子单元1345的具体实现方式可以参见上述图5所对应实施例中对S204的描述,这里不再进行赘述。
其中,第二状态更新模块14,包括:树查询单元141、第一查询处理单元142、第二查询处理单元143、第一树构建单元144以及第二树构建单元145。
树查询单元141,用于对初始更新状态进行世界状态树查询;
第一查询处理单元142,用于若初始更新状态包含第一世界状态树,则对初始更新状态进行全链脏账户状态提交处理,得到更新后的第一世界状态;
第二查询处理单元143,用于若初始更新状态未包含第一世界状态树,则根据第一前世界状态指针查找第二世界状态;
第一树构建单元144,用于根据世界状态链对第二世界状态进行构建干净状态树处理,得到干净前世界状态树;
第二树构建单元145,用于将干净前世界状态树的前状态树根作为现状态树根;
第二树构建单元145,还用于根据第一树节点缓存和现状态树根构建初始更新状态对应的第二世界状态树,将第二世界状态树添加到初始更新状态,得到过渡初始更新状态;
脏状态提交单元146,用于对过渡初始更新状态进行全链脏账户状态提交处理,得到更新后的第一世界状态。
其中,树查询单元141、第一查询处理单元142、第二查询处理单元143、第一树构建单元144以及第二树构建单元145的具体实现方式可以参见上述图6所对应实施例中对S301-S306的描述,这里不再进行赘述。
其中,脏状态提交单元146,包括:脏数据提交子单元1461、根获取子单元1462、树更新子单元1463以及树提交子单元1464。
脏数据提交子单元1461,用于对过渡初始更新状态进行全链脏状态数据提交处理,得到提交后的过渡初始更新状态和全链脏账户地址集合;
根获取子单元1462,用于根据提交后的过渡初始更新状态获取全链脏账户地址集合中的每个全链脏账户地址对应的账户状态根;
树更新子单元1463,用于将每个全链脏账户地址和每个全链脏账户地址对应的账户状态根更新到第二世界状态树,得到干净现世界状态树;
树提交子单元1464,用于将干净现世界状态树的更新树节点哈希和更新树节点的关联关系存储至提交后的过渡初始更新状态中的树节点缓存的树节点映射中,得到更新后的第一世界状态。
其中,脏数据提交子单元1461,具体用于顺序遍历世界状态链,获取第x个世界状态包含的脏账户地址集合,作为第x个脏账户地址集合;x为小于或等于Z的正整数;Z为过渡初始更新状态在世界状态链中的顺序序数;遍历第x个脏账户地址集合中的账户地址,顺序获取第m个账户地址;m为小于或等于第x个脏账户地址集合中的账户地址的总数量的正整数;获取第m个账户地址对应的现账户状态和前账户状态;根据第m个账户地址的前账户状态对第m个账户地址的现账户状态进行账户脏状态数据提交处理;当第x个脏账户地址集合中每个脏账户地址的现账户状态均进行账户脏状态数据提交处理后,得到第x个提交后的世界状态;将第x个脏账户地址集合中每个脏账户地址添加至第x-1个链上脏账户地址集合,得到第x个链上脏账户地址集合;x为1时,第x-1个链上脏账户地址集合为空集合;当x等于Z时,将第x个链上脏账户地址集合作为全链脏账户地址集合,将第x个提交后的世界状态作为提交后的过渡初始更新状态。
其中,脏数据提交子单元1461,具体还用于对第m个账户地址的现账户状态进行账户状态树查询;若第m个账户地址的现账户状态不包含有账户状态树,或第m个账户地址的现账户状态的账户状态根不等于第m个账户地址的前账户状态的账户状态根,则根据第m个账户地址的现账户状态的树节点缓存和第m个账户地址的前账户状态的账户状态根建立指定账户状态树,将指定账户状态树添加至第m个账户地址的现账户状态,将第m个账户地址的现账户状态的账户状态根更新为第m个账户地址的前账户状态的账户状态根,得到指定账户状态;若第m个账户地址的现账户状态包含有账户状态树,且第m个账户地址的 现账户状态的账户状态根等于第m个账户地址的前账户状态的账户状态根,则将第m个账户地址的现账户状态作为指定账户状态;若指定账户状态的第一脏状态数据键集合不为空,则从指定账户状态的状态数据映射中获取第一脏状态数据键集合中脏状态数据键对应的状态数据值,将第一脏状态数据键集合中脏状态数据键和第一脏状态数据键集合中脏状态数据键对应的状态数据值更新到指定账户状态的账户状态树,得到包含更新账户状态树的指定账户状态;将包含更新账户状态树的指定账户状态的账户状态根更新为将更新账户状态树的状态树根;清空包含更新账户状态树的指定账户状态的脏状态数据键集合;将更新账户状态树的更新树节点哈希和更新树节点的关联关系存储至第x个世界状态。
其中,脏数据提交子单元1461、根获取子单元1462、树更新子单元1463以及树提交子单元1464的具体实现方式可以参见上述图3所对应实施例中对S306的描述,这里不再进行赘述。
其中,上述数据处理装置1,还包括:提交模块17、更新模块18以及清空模块19。
提交模块17,用于对提交后的最新上链世界状态进行全链脏账户状态提交处理,得到干净最新上链世界状态,干净最新上链世界状态中的树节点缓存中包括第一树节点映射;
更新模块18,用于将第一树节点映射包含的树节点哈希和树节点更新到树节点数据库;
清空模块19,用于清空干净最新上链世界状态中的脏账户地址集合、账户状态映射和第一树节点映射。
其中,提交模块17、更新模块18以及清空模块19的具体实现方式可以参见上述图3所对应实施例中的可选描述,这里不再进行赘述。
请参见图8,图8是本申请实施例提供的一种计算机设备的结构示意图。如图8所示,上述图7所对应实施例中的数据处理装置1可以应用于计算机设备1000,该计算机设备1000可以包括:处理器1001,网络接口1004和存储器1005,此外,上述计算机设备1000还可以包括:用户接口1003,和至少一个通信总线1002。其中,通信总线1002用于实现这些组件之间的连接通信。其中,用户接口1003可以包括显示屏(Display)、键盘(Keyboard),可选用户接口1003还可以包括标准的有线接口、无线接口。网络接口1004可选的可以包括标准的有线接口、无线接口(如WI-FI接口)。存储器1005可以是高速RAM存储器,也可以是非不稳定的存储器(non-volatile memory),例如至少一个磁盘存储器。存储器1005可选的还可以是至少一个位于远离前述处理器1001的存储装置。如图8所示,作为一种计算机可读存储介质的存储器1005中可以包括操作系统、网络通信模块、用户接口模块以及设备控制应用程序。
在如图8所示的计算机设备1000中,网络接口1004可提供网络通讯网元;而用户接口1003主要用于为用户提供输入的接口;而处理器1001可以用于调用存储器1005中存储的设备控制应用程序,以实现:
生成初始区块,创建初始区块对应的第一世界状态;第一世界状态具有指向第二世界状态的链式关系,第二世界状态为初始区块的父区块对应的世界状态;第一世界状态和第二世界状态存在于世界状态链中;若父区块为已上链区块中具有最大区块高度的区块,则第二世界状态为共识根世界状态;世界状态链中的第一个世界状态为最新上链世界状态; 共识根世界状态具有指向最新上链世界状态的链式关系;最新上链世界状态用于记录已上链区块对应的最新世界状态;
根据初始区块中的交易更新第一世界状态,得到初始更新状态,根据世界状态链对初始更新状态进行构建干净状态树处理,得到更新后的第一世界状态,更新后的第一世界状态包括干净现世界状态树;
将干净现世界状态树对应的第一世界状态根写入初始区块,得到待上链区块,将待上链区块发送至共识节点,以使共识节点基于第一世界状态根对待上链区块进行共识处理,得到共识结果;
若共识结果为共识通过结果,则将待上链区块写入区块链中,通过世界状态链将更新后的第一世界状态逐级提交至最新上链世界状态,将更新后的第一世界状态确定为新的共识根世界状态,新的共识根世界状态具有指向提交后的最新上链世界状态的链式关系。
应当理解,本申请实施例中所描述的计算机设备1000可执行前文图3任一个所对应实施例中对该数据处理方法的描述,在此不再赘述。另外,对采用相同方法的有益效果描述,也不再进行赘述。
此外,这里需要指出的是:本申请实施例还提供了一种计算机可读存储介质,且上述计算机可读存储介质中存储有前文提及的数据处理装置1所执行的计算机程序,且上述计算机程序包括程序指令,当上述处理器执行上述程序指令时,能够执行前文图3任一个所对应实施例中对上述数据处理方法的描述,因此,这里将不再进行赘述。另外,对采用相同方法的有益效果描述,也不再进行赘述。对于本申请所涉及的计算机可读存储介质实施例中未披露的技术细节,请参照本申请方法实施例的描述。
上述计算机可读存储介质可以是前述任一实施例提供的数据处理装置或者上述计算机设备的内部存储单元,例如计算机设备的硬盘或内存。该计算机可读存储介质也可以是该计算机设备的外部存储设备,例如该计算机设备上配备的插接式硬盘,智能存储卡(smart media card,SMC),安全数字(secure digital,SD)卡,闪存卡(flash card)等。进一步地,该计算机可读存储介质还可以既包括该计算机设备的内部存储单元也包括外部存储设备。该计算机可读存储介质用于存储该计算机程序以及该计算机设备所需的其他程序和数据。该计算机可读存储介质还可以用于暂时地存储已经输出或者将要输出的数据。
此外,这里需要指出的是:本申请实施例还提供了一种计算机程序产品或计算机程序,该计算机程序产品或计算机程序包括计算机指令,该计算机指令存储在计算机可读存储介质中。计算机设备的处理器从计算机可读存储介质读取该计算机指令,处理器执行该计算机指令,使得该计算机设备执行前文任一个所对应实施例提供的方法。
本申请实施例的说明书和权利要求书及附图中的术语“第一”、“第二”等是用于区别不同对象,而非用于描述特定顺序。此外,术语“包括”以及它们任何变形,意图在于覆盖不排他的包含。例如包含了一系列步骤或单元的过程、方法、装置、产品或设备没有限定于已列出的步骤或模块,而是可选地还包括没有列出的步骤或模块,或可选地还包括对于这些过程、方法、装置、产品或设备固有的其他步骤单元。
本领域普通技术人员可以意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、计算机软件或者二者的结合来实现,为了清楚地说明硬件和软件的可互换性,在上述说明中已经按照网元一般性地描述了各示例的组成及步骤。这些网元究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的网元,但是这种实现不应认为超出本申请的范围。
以上所揭露的仅为本申请较佳实施例而已,当然不能以此来限定本申请之权利范围,因此依本申请权利要求所作的等同变化,仍属本申请所涵盖的范围。

Claims (16)

  1. 一种基于区块链的数据处理方法,所述方法由计算机设备执行,所述方法包括:
    生成初始区块,创建所述初始区块对应的第一世界状态;所述第一世界状态具有指向第二世界状态的链式关系,所述第二世界状态为所述初始区块的父区块对应的世界状态;所述第一世界状态和所述第二世界状态存在于世界状态链中;若所述父区块为已上链区块中具有最大区块高度的区块,则所述第二世界状态为共识根世界状态;所述世界状态链中的第一个世界状态为最新上链世界状态;所述共识根世界状态具有指向最新上链世界状态的链式关系;所述最新上链世界状态用于记录所述已上链区块对应的最新世界状态;
    根据所述初始区块中的交易更新所述第一世界状态,得到初始更新状态,根据所述世界状态链对所述初始更新状态进行构建干净状态树处理,得到更新后的第一世界状态,所述更新后的第一世界状态包括干净现世界状态树;
    将所述干净现世界状态树对应的第一世界状态根写入所述初始区块,得到待上链区块,将所述待上链区块发送至共识节点,以使所述共识节点基于所述第一世界状态根对所述待上链区块进行共识处理,得到共识结果;
    若所述共识结果为共识通过结果,则将所述待上链区块写入区块链中,通过所述世界状态链将所述更新后的第一世界状态逐级提交至所述最新上链世界状态,将所述更新后的第一世界状态确定为新的共识根世界状态,所述新的共识根世界状态具有指向提交后的最新上链世界状态的链式关系。
  2. 根据权利要求1所述的方法,所述创建所述初始区块对应的第一世界状态,包括:
    创建所述初始区块对应的初始世界状态;所述初始世界状态包含有第一前世界状态指针和第一树节点缓存;所述第一树节点缓存包含有第一前树节点缓存指针;
    将所述第一前世界状态指针指向所述初始区块的父区块对应的第二世界状态,将所述第一前树节点缓存指针指向所述第二世界状态包含的第二树节点缓存,得到所述初始区块对应的第一世界状态。
  3. 根据权利要求1所述的方法,所述根据所述初始区块中的交易更新所述第一世界状态,得到初始更新状态,包括:
    顺序遍历所述初始区块中的交易,获取所述初始区块中的第k个交易;k为小于或等于H的正整数;H为所述初始区块中的交易的总数量;
    创建所述第k个交易对应的第k个交易世界状态;所述第k个交易世界状态具有指向第k-1个提交世界状态的链式关系;k为1时,所述第k-1个提交世界状态为所述第一世界状态;
    执行所述第k个交易,在所述第k个交易执行的过程中对所述第k个交易世界状态进行状态更新处理,得到第k个更新交易世界状态;
    若所述第k个交易执行成功,则将所述第k个更新交易世界状态提交至所述第k-1个提交世界状态,得到第k个提交世界状态;
    当k等于H时,将第H个提交世界状态作为所述初始更新状态。
  4. 根据权利要求3所述的方法,所述第k个交易世界状态包含有账户状态映射和脏账户地址集合,所述执行所述第k个交易,在所述第k个交易执行的过程中对所述第k个交易世界状态进行状态更新处理,得到第k个更新交易世界状态,包括:
    执行所述第k个交易,在所述第k个交易执行的过程中确定所述第k个交易对应的待更新数据;所述待更新数据包括待更新账户地址、待更新状态数据键和待更新状态数据值;
    根据所述第k个交易世界状态获取所述待更新账户地址对应的账户状态,作为待更新账户状态;所述待更新账户状态包含有待更新状态数据映射和待更新脏状态数据键集合;
    将所述待更新状态数据键和所述待更新状态数据值的映射关系更新到所述待更新状态数据映射中,将所述待更新状态数据键插入到所述待更新脏状态数据键集合中,得到现账户状态;
    将所述待更新账户地址和所述现账户状态的映射关系更新到所述第k个交易世界状态包含的账户状态映射中,将所述待更新账户地址插入到所述第k个交易世界状态包含的脏账户地址集合中,得到所述第k个更新交易世界状态。
  5. 根据权利要求4所述的方法,所述根据所述第k个交易世界状态获取所述待更新账户地址对应的账户状态,作为待更新账户状态,包括:
    根据所述待更新账户地址对所述第k个交易世界状态至所述最新上链世界状态进行账户状态映射顺序检索;
    若在账户状态映射顺序检索的过程中检索到与所述待更新账户地址具有映射关系的账户状态,则将最先检索到的与所述待更新账户地址具有映射关系的账户状态作为待更新账户状态;
    若在账户状态映射顺序检索的过程中未检索到与所述待更新账户地址具有映射关系的账户状态,则根据所述最新上链世界状态中的世界状态树获取所述待更新账户地址对应的待更新状态树根,根据所述待更新账户地址和所述待更新状态树根建立待更新账户状态。
  6. 根据权利要求4所述的方法,所述若所述第k个交易执行成功,则将所述第k个更新交易世界状态向所述第k-1个提交世界状态进行提交,得到第k个提交世界状态,包括:
    遍历所述第k个更新交易世界状态包含的脏账户地址集合中的账户地址,顺序获取第j个账户地址;j为小于或等于I的正整数;I为所述第k个更新交易世界状态包含的脏账户地址集合中的账户地址的总数量;
    从所述第k个更新交易世界状态包含的账户状态映射中获取所述第j个账户地址对应的现账户状态;
    根据所述第k-1个提交世界状态获取所述第j个账户地址的前账户状态;
    将所述第j个账户地址对应的现账户状态提交至所述第j个账户地址的前账户状态,将所述第j个账户地址插入到所述第k-1个提交世界状态包含的脏账户地址集合,得到第j个过渡提交世界状态;
    当j等于I时,清空第k个更新交易世界状态包含的脏账户地址集合和账户状态映射,将第I个过渡提交世界状态作为第k个提交世界状态。
  7. 根据权利要求6所述的方法,所述第j个账户地址对应的现账户状态包含第一状态数据映射,所述第j个账户地址的前账户状态包含第二状态数据映射,所述将所述第j个账户地址对应的现账户状态提交至所述第j个账户地址的前账户状态,将所述第j个账户地址插入到所述第k-1个提交世界状态包含的脏账户地址集合,得到第j个过渡提交世界状态,包括:
    将所述第一状态数据映射中状态数据键和状态数据值的映射关系,更新到所述第二状态数据映射中;
    将所述第一状态数据映射中的状态数据键插入到所述第j个账户地址的前账户状态包含的脏状态数据键集合中,得到第j个过渡提交世界状态。
  8. 根据权利要求2所述的方法,所述根据所述世界状态链对所述初始更新状态进行构建干净状态树处理,得到更新后的第一世界状态,包括:
    对所述初始更新状态进行世界状态树查询;
    若所述初始更新状态包含第一世界状态树,则对所述初始更新状态进行全链脏账户状态提交处理,得到所述更新后的第一世界状态;
    若所述初始更新状态未包含所述第一世界状态树,则根据所述第一前世界状态指针查找所述第二世界状态;
    根据所述世界状态链对所述第二世界状态进行构建干净状态树处理,得到干净前世界状态树;
    将所述干净前世界状态树的前状态树根作为现状态树根;
    根据所述第一树节点缓存和所述现状态树根构建所述初始更新状态对应的第二世界状态树,将所述第二世界状态树添加到所述初始更新状态,得到过渡初始更新状态;
    对所述过渡初始更新状态进行全链脏账户状态提交处理,得到所述更新后的第一世界状态。
  9. 根据权利要求8所述的方法,所述对所述过渡初始更新状态进行全链脏账户状态提交处理,得到所述更新后的第一世界状态,包括:
    对所述过渡初始更新状态进行全链脏状态数据提交处理,得到提交后的过渡初始更新状态和全链脏账户地址集合;
    根据所述提交后的过渡初始更新状态获取所述全链脏账户地址集合中的每个全链脏账户地址对应的账户状态根;
    将所述每个全链脏账户地址和所述每个全链脏账户地址对应的账户状态根更新到所述第二世界状态树,得到干净现世界状态树;
    将所述干净现世界状态树的更新树节点哈希和更新树节点的关联关系存储至所述提交后的过渡初始更新状态中的树节点缓存的树节点映射中,得到所述更新后的第一世界状态。
  10. 根据权利要求9所述的方法,所述对所述过渡初始更新状态进行全链脏状态数据提交处理,得到提交后的过渡初始更新状态和全链脏账户地址集合,包括:
    顺序遍历所述世界状态链,获取第x个世界状态包含的脏账户地址集合,作为第x个脏账户地址集合;x为小于或等于Z的正整数;Z为所述过渡初始更新状态在所述世界状态链中的顺序序数;
    遍历所述第x个脏账户地址集合中的账户地址,顺序获取第m个账户地址;m为小于或等于所述第x个脏账户地址集合中账户地址的总数量的正整数;
    获取所述第m个账户地址对应的现账户状态和前账户状态;
    根据所述第m个账户地址的前账户状态对所述第m个账户地址的现账户状态进行账户脏状态数据提交处理;
    当所述第x个脏账户地址集合中每个脏账户地址的现账户状态均进行账户脏状态数据提交处理后,得到第x个提交后的世界状态;
    将所述第x个脏账户地址集合中每个脏账户地址添加至第x-1个链上脏账户地址集合,得到第x个链上脏账户地址集合;x为1时,第x-1个链上脏账户地址集合为空集合;
    当x等于Z时,将第x个链上脏账户地址集合作为全链脏账户地址集合,将第x个提交后的世界状态作为提交后的过渡初始更新状态。
  11. 根据权利要求10所述的方法,所述根据所述第m个账户地址的前账户状态对所述第m个账户地址的现账户状态进行账户脏状态数据提交处理,包括:
    对所述第m个账户地址的现账户状态进行账户状态树查询;
    若所述第m个账户地址的现账户状态不包含有账户状态树,或所述第m个账户地址的现账户状态的账户状态根不等于所述第m个账户地址的前账户状态的账户状态根,则根据所述第m个账户地址的现账户状态的树节点缓存和所述第m个账户地址的前账户状态的账户状态根建立指定账户状态树,将所述指定账户状态树添加至所述第m个账户地址的现账户状态,将第m个账户地址的现账户状态的账户状态根更新为所述第m个账户地址的前账户状态的账户状态根,得到指定账户状态;
    若所述第m个账户地址的现账户状态包含有账户状态树,且所述第m个账户地址的现账户状态的账户状态根等于所述第m个账户地址的前账户状态的账户状态根,则将所述第m个账户地址的现账户状态作为指定账户状态;
    若所述指定账户状态的第一脏状态数据键集合不为空,则从所述指定账户状态的状态数据映射中获取所述第一脏状态数据键集合中脏状态数据键对应的状态数据值,将所述第一脏状态数据键集合中脏状态数据键和所述第一脏状态数据键集合中脏状态数据键对应的状态数据值更新到所述指定账户状态的账户状态树,得到包含更新账户状态树的指定账户状态;
    将所述包含更新账户状态树的指定账户状态的账户状态根更新为将所述更新账户状态树的状态树根;
    清空所述包含更新账户状态树的指定账户状态的脏状态数据键集合;
    将所述更新账户状态树的更新树节点哈希和更新树节点的关联关系存储至所述第x个世界状态。
  12. 根据权利要求11所述的方法,所述方法还包括:
    对提交后的最新上链世界状态进行全链脏账户状态提交处理,得到干净最新上链世界状态,所述干净最新上链世界状态中的树节点缓存中包括第一树节点映射;
    将所述第一树节点映射包含的树节点哈希和树节点更新到树节点数据库;
    清空所述干净最新上链世界状态中的脏账户地址集合、账户状态映射和所述第一树节点映射。
  13. 一种基于区块链的数据处理装置,所述装置部署在计算机设备上,所述装置包括:
    初始化模块,用于生成初始区块;
    状态创建模块,用于创建所述初始区块对应的第一世界状态;所述第一世界状态具有指向第二世界状态的链式关系,所述第二世界状态为所述初始区块的父区块对应的世界状态;所述第一世界状态和所述第二世界状态存在于世界状态链中;若所述父区块为已上链区块中具有最大区块高度的区块,则所述第二世界状态为共识根世界状态;所述世界状态链中的第一个世界状态为最新上链世界状态;所述共识根世界状态具有指向最新上链世界状态的链式关系;所述最新上链世界状态用于记录所述已上链区块对应的最新世界状态;
    第一状态更新模块,用于根据所述初始区块中的交易更新所述第一世界状态,得到初始更新状态;
    第二状态更新模块,用于根据所述世界状态链对所述初始更新状态进行构建干净状态树处理,得到更新后的第一世界状态,所述更新后的第一世界状态包括干净现世界状态树;
    共识模块,用于将所述干净现世界状态树对应的第一世界状态根写入所述初始区块,得到待上链区块,将所述共识区块发送至共识节点,以使所述共识节点基于所述第一世界状态根对所述待上链区块进行共识处理,得到共识结果;
    状态提交模块,用于若所述共识结果为共识通过结果,则将所述待上链区块写入区块链中,通过所述世界状态链将所述更新后的第一世界状态逐级提交至所述最新上链世界状态,将所述更新后的第一世界状态确定为新的共识根世界状态,所述新的共识根世界状态具有指向提交后的最新上链世界状态的链式关系。
  14. 一种计算机设备,包括:处理器、存储器以及网络接口;
    所述处理器与所述存储器、所述网络接口相连,其中,所述网络接口用于提供数据通信功能,所述存储器用于存储程序代码,所述处理器用于调用所述程序代码,以执行权利要求1-12任一项所述的方法。
  15. 一种计算机可读存储介质,所述计算机可读存储介质中存储有计算机程序,所述计算机程序适于由处理器加载并执行权利要求1-12任一项所述的方法。
  16. 一种计算机程序产品,包括计算机程序/指令,所述计算机程序/指令被处理器执行时,可以执行权利要求1-12任一项所述的方法。
PCT/CN2022/132559 2022-02-24 2022-11-17 基于区块链的数据处理方法、装置、设备及可读存储介质 WO2023160040A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
EP22928300.7A EP4394619A1 (en) 2022-02-24 2022-11-17 Data processing method and apparatus based on blockchain, and device and readable storage medium
US18/218,841 US20230353393A1 (en) 2022-02-24 2023-07-06 Blockchain-based methods and apparatuses for processing data, devices and readable storage mediums

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202210174690.7 2022-02-24
CN202210174690.7A CN116701414A (zh) 2022-02-24 2022-02-24 基于区块链的数据处理方法、装置、设备及可读存储介质

Related Child Applications (1)

Application Number Title Priority Date Filing Date
US18/218,841 Continuation US20230353393A1 (en) 2022-02-24 2023-07-06 Blockchain-based methods and apparatuses for processing data, devices and readable storage mediums

Publications (1)

Publication Number Publication Date
WO2023160040A1 true WO2023160040A1 (zh) 2023-08-31

Family

ID=87764590

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/132559 WO2023160040A1 (zh) 2022-02-24 2022-11-17 基于区块链的数据处理方法、装置、设备及可读存储介质

Country Status (4)

Country Link
US (1) US20230353393A1 (zh)
EP (1) EP4394619A1 (zh)
CN (1) CN116701414A (zh)
WO (1) WO2023160040A1 (zh)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN118093557B (zh) * 2024-04-28 2024-08-27 杭州高新区(滨江)区块链与数据安全研究院 区块链节点状态数据处理方法、电子装置和存储介质

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110800008A (zh) * 2019-03-04 2020-02-14 阿里巴巴集团控股有限公司 构建区块链世界状态默克尔帕特里夏字典树子树
US20200364205A1 (en) * 2019-05-17 2020-11-19 International Business Machines Corporation Database world state integrity validation
CN113994324A (zh) * 2020-10-27 2022-01-28 支付宝(杭州)信息技术有限公司 具有高效世界状态数据结构的区块链系统
CN114064984A (zh) * 2022-01-14 2022-02-18 浙商银行股份有限公司 一种基于稀疏数组链表的世界状态增量更新方法及装置

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110800008A (zh) * 2019-03-04 2020-02-14 阿里巴巴集团控股有限公司 构建区块链世界状态默克尔帕特里夏字典树子树
US20200364205A1 (en) * 2019-05-17 2020-11-19 International Business Machines Corporation Database world state integrity validation
CN113994324A (zh) * 2020-10-27 2022-01-28 支付宝(杭州)信息技术有限公司 具有高效世界状态数据结构的区块链系统
CN114064984A (zh) * 2022-01-14 2022-02-18 浙商银行股份有限公司 一种基于稀疏数组链表的世界状态增量更新方法及装置

Also Published As

Publication number Publication date
US20230353393A1 (en) 2023-11-02
CN116701414A (zh) 2023-09-05
EP4394619A1 (en) 2024-07-03

Similar Documents

Publication Publication Date Title
US11075757B2 (en) Shielded interoperability of distributed ledgers
CN101009516B (zh) 一种进行数据同步的方法、系统及装置
CN106815218B (zh) 数据库访问方法、装置和数据库系统
US11294875B2 (en) Data storage on tree nodes
US20230074102A1 (en) Method and apparatus for processing data based on block chain, device and readable storage medium
US11100094B2 (en) Taking snapshots of blockchain data
CN110597922B (zh) 数据处理方法、装置、终端及存储介质
US20210279205A1 (en) Log-structured merge-tree with blockchain properties
US20230334009A1 (en) Data archiving method and apparatus, device, and storage medium
US12056156B2 (en) Block-chain-based data processing
WO2016169237A1 (zh) 数据处理方法及装置
WO2023160040A1 (zh) 基于区块链的数据处理方法、装置、设备及可读存储介质
US20210049156A1 (en) Taking snapshots of blockchain data
CN111553669B (zh) 一种交易路由方法、装置及计算机可读存储介质
WO2023142605A1 (zh) 一种基于区块链的数据处理方法和相关装置
CN116977067A (zh) 基于区块链的数据处理方法、装置、设备及可读存储介质
CN110928923A (zh) 一种基于区块链的数据存储方法及系统
CN113656504A (zh) 一种基于时序属性的区块链交易提交、编辑和查询方法
WO2024007856A1 (zh) 数据处理方法、装置及设备、介质、产品
CN117056342B (zh) 一种基于区块链的数据处理方法及相关设备
CN110889040B (zh) 用于推送信息的方法和装置
CN117421369A (zh) 基于区块链的数据处理方法、装置、设备及可读存储介质
CN117539962B (zh) 数据处理方法、装置、计算机设备和存储介质
CN116846748A (zh) 网络配置管理方法及相关装置
CN116680729A (zh) 一种基于智能合约的数据处理方法、装置及相关设备

Legal Events

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

Ref document number: 22928300

Country of ref document: EP

Kind code of ref document: A1

WWE Wipo information: entry into national phase

Ref document number: 2022928300

Country of ref document: EP

ENP Entry into the national phase

Ref document number: 2022928300

Country of ref document: EP

Effective date: 20240327

WWE Wipo information: entry into national phase

Ref document number: 11202402262X

Country of ref document: SG