[go: up one dir, main page]

HK40092276A - Blockchain-based data processing method, apparatus, device, and readable storage medium - Google Patents

Blockchain-based data processing method, apparatus, device, and readable storage medium Download PDF

Info

Publication number
HK40092276A
HK40092276A HK42023081733.0A HK42023081733A HK40092276A HK 40092276 A HK40092276 A HK 40092276A HK 42023081733 A HK42023081733 A HK 42023081733A HK 40092276 A HK40092276 A HK 40092276A
Authority
HK
Hong Kong
Prior art keywords
state
account
world state
world
tree
Prior art date
Application number
HK42023081733.0A
Other languages
Chinese (zh)
Other versions
HK40092276B (en
Inventor
冯浩铭
颜喆明
屠海涛
何立宝
陈家宝
Original Assignee
腾讯科技(深圳)有限公司
Filing date
Publication date
Application filed by 腾讯科技(深圳)有限公司 filed Critical 腾讯科技(深圳)有限公司
Publication of HK40092276A publication Critical patent/HK40092276A/en
Publication of HK40092276B publication Critical patent/HK40092276B/en

Links

Description

基于区块链的数据处理方法、装置、设备及可读存储介质Data processing methods, devices, equipment, and readable storage media based on blockchain.

技术领域Technical Field

本申请涉及计算机技术领域,尤其涉及一种基于区块链的数据处理方法、装置、设备及可读存储介质。This application relates to the field of computer technology, and in particular to a data processing method, apparatus, device, and readable storage medium based on blockchain.

背景技术Background Technology

区块链系统是由多个区块链节点组成的区块链网络,每个区块链节点会存储该区块链网络对应的最新上链世界状态,即区块链中的最大区块高度的区块上链后,区块链网络中各个账户所拥有的状态数据共同组成的世界状态。A blockchain system is a blockchain network composed of multiple blockchain nodes. Each blockchain node stores the latest on-chain world state corresponding to the blockchain network. That is, after the block with the highest block height in the blockchain is on-chain, the world state is composed of the state data owned by each account in the blockchain network.

现有区块链网络中,区块内交易的执行会修改若干账户所拥有的部分状态数据,因此每当有一个区块上链后,就会有对应有一个新的最新上链世界状态。新区块在共识时,又需要依赖其父区块上链后对应的最新上链世界状态来确定自己上链后对应的最新上链世界状态,因此现有共识机制中往往仅允许一个区块进行共识。若采用多个区块同时进行共识的共识机制,则往往无法保证区块链系统的状态数据的一致性。In existing blockchain networks, the execution of transactions within a block modifies some state data held by several accounts. Therefore, each time a block is added to the chain, a new, up-to-date world state is generated. During consensus, a new block relies on the up-to-date world state of its parent block to determine its own up-to-date world state. Consequently, existing consensus mechanisms often only allow one block to reach consensus simultaneously. If a consensus mechanism involving multiple blocks simultaneously is adopted, the consistency of the blockchain system's state data often cannot be guaranteed.

发明内容Summary of the Invention

本申请实施例提供了一种数据处理方法、装置、设备及可读存储介质,可以维护多个待上链区块的世界状态,保证区块链系统的状态数据的一致性。This application provides a data processing method, apparatus, device, and readable storage medium that can maintain the world state of multiple blocks to be added to the blockchain and ensure the consistency of the state data of the blockchain system.

本申请实施例一方面提供了一种基于区块链的数据处理方法,包括:One embodiment of this application provides a blockchain-based data processing method, including:

生成初始区块,创建初始区块对应的第一世界状态;第一世界状态具有指向初始区块的父区块对应的第二世界状态的链式关系;第一世界状态和第二世界状态存在于世界状态链中;若父区块为已上链区块中具有最大区块高度的区块,则第二世界状态为共识根世界状态;世界状态链中的第一个世界状态为最新上链世界状态;共识根世界状态具有指向最新上链世界状态的链式关系;最新上链世界状态用于记录已上链区块对应的最新世界状态;An initial block is generated, and a first world state corresponding to the initial block is created. The first world state has a chain relationship pointing to the second world state corresponding to the parent block of the initial block. The first and second world states exist in the world state chain. If the parent block is the block with the highest block height among the already chained blocks, then the second world state is the consensus root world state. The first world state in the world state 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 already chained blocks.

根据初始区块中的交易更新第一世界状态,得到目标第一世界状态,根据世界状态链对目标第一世界状态进行构建干净状态树处理,得到包含干净现世界状态树的更新目标第一世界状态;The first world state is updated based on the transactions in the initial block to obtain the target first world state. A clean state tree is then constructed on the target first world state based on the world state chain to obtain the updated target first world state containing the clean current world state tree.

将干净现世界状态树对应的第一世界状态根写入初始区块,得到待上链区块,将共识区块发送至共识节点,以使共识节点基于第一世界状态根对待上链区块进行共识处理,得到共识结果;Write the first world state root corresponding to the clean current world state tree into the initial block to obtain the block to be added to the chain. Send the consensus block to the consensus node so that the consensus node can perform consensus processing on the block to be added to the chain based on the first world state root and obtain the consensus result.

若共识结果为共识通过结果,则将待上链区块写入区块链中,通过世界状态链将更新目标第一世界状态逐级提交至最新上链世界状态,将更新目标第一世界状态确定为新的共识根世界状态,新的共识根世界状态具有指向提交后的最新上链世界状态的链式关系。If the consensus result is a consensus pass, the block to be added to the blockchain is written into the blockchain. The target first world state is submitted to the latest on-chain world state through the world state chain. The target first world state is determined as the new consensus root world state. The new consensus root world state has a chain relationship pointing to the latest on-chain world state after submission.

本申请实施例一方面提供了一种基于区块链的数据处理装置,包括:One embodiment of this application provides a blockchain-based data processing device, 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 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 highest block height among the already chained blocks, then the second world state is the consensus root world state. The first world state in the world state 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 already chained blocks.

第一状态更新模块,用于根据初始区块中的交易更新第一世界状态,得到目标第一世界状态;The first state update module is used to update the first world state based on the transactions in the initial block to obtain the target first world state.

第二状态更新模块,用于根据世界状态链对目标第一世界状态进行构建干净状态树处理,得到包含干净现世界状态树的更新目标第一世界状态;The second state update module is used to construct a clean state tree for the target first world state based on the world state chain, so as to obtain an updated target first world state containing the 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 added to the chain, and send the consensus block to the consensus node so that the consensus node can perform consensus processing on the block to be added to the chain based on the first world state root and obtain the consensus result.

状态提交模块,用于若共识结果为共识通过结果,则将待上链区块写入区块链中,通过世界状态链将更新目标第一世界状态逐级提交至最新上链世界状态,将更新目标第一世界状态确定为新的共识根世界状态,新的共识根世界状态具有指向提交后的最新上链世界状态的链式关系。The state submission module is used to write the block to be added to the blockchain if the consensus result is a consensus pass result. It submits the target first world state to the latest on-chain world state through the world state chain, and determines the target first world state as the new consensus root world state. The new consensus root world state has a chain relationship pointing to the latest on-chain world state after submission.

其中,状态创建模块,包括:The state creation module includes:

创建单元,用于创建初始区块对应的初始世界状态;初始世界状态包含有第一前世界状态指针和第一树节点缓存;第一树节点缓存包含有第一前树节点缓存指针;A creation unit is used to create the initial world state corresponding to the initial block; the initial world state contains a pointer to the first previous world state and a first tree node cache; the first tree node cache contains a pointer to the first previous tree node cache;

指向单元,用于将第一前世界状态指针指向初始区块的父区块对应的第二世界状态,将第一前树节点缓存指针指向第二世界状态包含的第二树节点缓存,得到初始区块对应的第一世界状态。The pointer unit is used to point the first previous world state pointer to the second world state corresponding to the parent block of the initial block, and to point the first previous tree node cache pointer to the second tree node cache contained in the second world state, so as to obtain the first world state corresponding to the initial block.

其中,第一状态更新模块,包括:The first state update module includes:

交易获取单元,用于顺序遍历初始区块中的交易,获取初始区块中的第k个交易;k为小于或等于H的正整数;H为初始区块中的交易的总数量;The transaction retrieval unit is used to sequentially traverse the transactions in the initial block and retrieve the k-th 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;

交易状态创建单元,用于创建第k个交易对应的第k个交易世界状态;第k个交易世界状态具有指向第k-1个提交世界状态的链式关系;k为1时,第k-1个提交世界状态为第一世界状态;The transaction state creation unit is used to create the k-th transaction world state corresponding to the k-th transaction; the k-th transaction world state has a chain relationship pointing to the (k-1)-th submitted world state; when k is 1, the (k-1)-th submitted world state is the first world state;

交易状态更新单元,用于执行第k个交易,在第k个交易执行的过程中对第k个交易世界状态进行状态更新处理,得到第k个更新交易世界状态;The transaction state update unit is used to execute the kth transaction. During the execution of the kth transaction, the world state of the kth transaction is updated to obtain the updated world state of the kth transaction.

交易状态提交单元,用于若第k个交易执行成功,则将第k个更新交易世界状态提交至第k-1个提交世界状态,得到第k个提交世界状态;The transaction state submission unit is used to submit the world state of the kth updated transaction to the (k-1)th submission world state if the kth transaction is successfully executed, thus obtaining the kth submission world state.

世界状态确定单元,用于当k等于H时,将第H个提交世界状态作为目标第一世界状态。The world state determination unit is used to take the Hth submitted world state as the target first world state when k equals H.

其中,第k个交易世界状态包含有账户状态映射和脏账户地址集合;The k-th transaction world state contains an account state mapping and a set of dirty account addresses;

交易状态更新单元,包括:The transaction status update unit includes:

执行子单元,用于执行第k个交易,在第k个交易执行的过程中确定第k个交易对应的待更新数据;待更新数据包括待更新账户地址、待更新状态数据键和待更新状态数据值;The execution subunit is used to execute the k-th transaction. During the execution of the k-th transaction, the data to be updated corresponding to the k-th transaction is determined. The data to be updated includes the account address to be updated, the status data key to be updated, and the status data value to be updated.

账户状态获取子单元,用于根据第k个交易世界状态获取待更新账户地址对应的账户状态,作为待更新账户状态;待更新账户状态包含有待更新状态数据映射和待更新脏状态数据键集合;The account status acquisition subunit is used to obtain the account status corresponding to the account address to be updated based on the k-th transaction world state, and use it as the account status to be updated; the account status to be updated contains the data mapping of the status to be updated and the set of dirty status data keys to be updated;

第一映射更新子单元,用于将待更新状态数据键和待更新状态数据值的映射关系更新到待更新状态数据映射中,将待更新状态数据键插入到待更新脏状态数据键集合中,得到现账户状态;The first mapping update subunit is used to update the mapping relationship between the state data key to be updated and the state data value to be updated to the state data mapping to be updated, and to insert the state data key to be updated into the dirty state data key set to be updated, so as to obtain the current account status.

第二映射更新单元,用于将待更新账户地址和现账户状态的映射关系更新到第k个交易世界状态包含的账户状态映射中,将待更新账户地址插入到第k个交易世界状态包含的脏账户地址集合中,得到第k个更新交易世界状态。The second mapping update unit is used to update the mapping relationship between the account address to be updated and the current account status to the account status mapping contained in the kth transaction world state, and to insert the account address to be updated into the dirty account address set contained in the kth transaction world state to obtain the kth updated transaction world state.

其中,账户状态获取子单元,具体用于根据待更新账户地址对第k个交易世界状态至最新上链世界状态进行账户状态映射顺序检索;若在账户状态映射顺序检索的过程中检索到与待更新账户地址具有映射关系的账户状态,则将最先检索到的与待更新账户地址具有映射关系的账户状态作为待更新账户状态;若在账户状态映射顺序检索的过程中未检索到与待更新账户地址具有映射关系的账户状态,则根据最新上链世界状态中的世界状态树获取待更新账户地址对应的待更新状态树根,根据待更新账户地址和待更新状态树根建立待更新账户状态。The account status acquisition subunit is specifically used to perform an account status mapping sequence retrieval from the k-th transaction world state to the latest on-chain world state based on the account address to be updated. If an account state with a mapping relationship to the account address to be updated is found during the account status mapping sequence retrieval, the first account state with a mapping relationship to the account address to be updated is taken as the account state to be updated. If no account state with a mapping relationship to the account address to be updated is found during the account status mapping sequence retrieval, the root of the state tree corresponding to the account address to be updated is obtained from the world state tree in the latest on-chain world state, and the account state to be updated is established based on the account address to be updated and the root of the state tree to be updated.

其中,交易状态提交单元,包括:The transaction status submission unit includes:

地址获取子单元,用于遍历第k个更新交易世界状态包含的脏账户地址集合中的账户地址,顺序获取第j个账户地址;j为小于或等于I的正整数;I为第k个更新交易世界状态包含的脏账户地址集合中的账户地址的总数量;The address retrieval subunit is used to traverse the set of dirty account addresses contained in the k-th updated transaction world state and sequentially retrieve the j-th account address; j is a positive integer less than or equal to I; I is the total number of account addresses in the set of dirty account addresses contained in the k-th updated transaction world state.

现账户状态获取子单元,用于从第k个更新交易世界状态包含的账户状态映射中获取第j个账户地址对应的现账户状态;The current account status acquisition subunit is used to obtain the current account status corresponding to the j-th account address from the account status mapping contained in the k-th updated transaction world state;

前账户状态获取子单元,用于根据第k-1个提交世界状态获取第j个账户地址的前账户状态;The previous account state retrieval subunit is used to retrieve the previous account state of the j-th account address based on the (k-1)-th submitted world state.

世界状态提交子单元,用于将第j个账户地址对应的现账户状态提交至第j个账户地址的前账户状态,将第j个账户地址插入到第k-1个提交世界状态包含的脏账户地址集合,得到第j个过渡提交世界状态;The world state commit subunit is used to commit the current account state corresponding to the j-th account address to the previous account state of the j-th account address, and to insert the j-th account address into the dirty account address set contained in the (k-1)-th commit world state to obtain the j-th transition commit world state.

世界状态确定子单元,用于当j等于I时,清空第k个更新交易世界状态包含的脏账户地址集合和账户状态映射,将第I个过渡提交世界状态作为第k个提交世界状态。The world state determination subunit is used to clear the dirty account address set and account state mapping contained in the k-th update transaction world state when j equals I, and to take the i-th transitional commit world state as the k-th commit world state.

其中,世界状态提交子单元,具体用于将第j个账户地址对应的现账户状态包含的状态数据映射中的状态数据键和状态数据值的映射关系,更新到第j个账户地址的前账户状态包含的状态数据映射中;将第j个账户地址对应的现账户状态包含的状态数据映射中的状态数据键插入到第j个账户地址的前账户状态包含的脏状态数据键集合中,得到第j个过渡提交世界状态。Specifically, the world state commit subunit is used to update the mapping relationship between state data keys and state data values in the state data mapping of the current account state corresponding to the j-th account address to the state data mapping of the previous account state corresponding to the j-th account address; and to insert the state data keys in the state data mapping of the current account state corresponding to the j-th account address into the dirty state data key set of the previous account state corresponding to the j-th account address to obtain the j-th transition commit world state.

其中,第二状态更新模块,包括:The second state update module includes:

树查询单元,用于对目标第一世界状态进行世界状态树查询;The tree query unit is used to perform a world state tree query on the first world state of the target.

第一查询处理单元,用于若目标第一世界状态包含第一世界状态树,则对包含第一世界状态树的目标第一世界状态进行全链脏账户状态提交处理,得到包含干净现世界状态树的更新目标第一世界状态;The first query processing unit is used to perform full-chain dirty account state submission processing on the target first world state containing the first world state tree if the target first world state contains the first world state tree, so as to obtain the updated target first world state containing the clean current world state tree.

第二查询处理单元,用于若目标第一世界状态未包含第一世界状态树,则根据第一前世界状态指针查找第二世界状态;The second query processing unit is used to find the second world state based on the first previous world state pointer if the target first world state does not contain the first world state tree.

第一树构建单元,用于根据世界状态链对第二世界状态进行构建干净状态树处理,得到干净前世界状态树;The first tree construction unit is used to construct a clean state tree for the second world state based on the world state chain, so as to obtain a clean pre-world state tree.

第二树构建单元,用于将干净前世界状态树的前状态树根作为现状态树根;The second tree construction unit is used to take the root of the previous state tree of the clean previous world state tree as the root of the current state tree.

第二树构建单元,还用于根据第一树节点缓存和现状态树根构建目标第一世界状态对应的第二世界状态树,将第二世界状态树添加到目标第一世界状态,得到过渡目标第一世界状态;The second tree construction unit is also used to construct the second world state tree corresponding to the target first world state based on the first tree node cache and the current state tree root, and add the second world state tree to the target first world state to obtain the transition target first world state.

脏状态提交单元,用于对过渡目标第一世界状态进行全链脏账户状态提交处理,得到包含干净现世界状态树的更新目标第一世界状态。The dirty state submission unit is used to perform full-chain dirty account state submission processing on the transition target first world state to obtain the updated target first world state containing the clean current world state tree.

其中,脏状态提交单元,包括:The dirty state submission unit includes:

脏数据提交子单元,用于对过渡目标第一世界状态进行全链脏状态数据提交处理,得到提交后的过渡目标第一世界状态和全链脏账户地址集合;The dirty data submission subunit is used to perform full-chain dirty state data submission processing on the first world state of the transition target, and obtain the submitted first world state of the transition target and the full-chain dirty account address set.

根获取子单元,用于根据提交后的过渡目标第一世界状态获取全链脏账户地址集合中的每个全链脏账户地址对应的账户状态根;The root acquisition subunit is used to obtain the account state root corresponding to each full-chain dirty account address in the full-chain dirty account address set based on the first-world state of the submitted transition target.

树更新子单元,用于将每个全链脏账户地址和每个全链脏账户地址对应的账户状态根更新到第二世界状态树,得到干净现世界状态树;The tree update subunit is used to update the second world state tree with each full-chain dirty account address and the account state root corresponding to each full-chain dirty account address to obtain the clean current world state tree.

树提交子单元,用于将干净现世界状态树的更新树节点哈希和更新树节点的关联关系存储至提交后的过渡目标第一世界状态中的树节点缓存的树节点映射中,得到包含干净现世界状态树的更新目标第一世界状态。The tree submission subunit is used to store the updated tree node hash and the association relationship of the updated tree node of the clean current world state tree into the tree node mapping of the tree node cache in the transition target first world state after submission, so as to obtain the updated target first world state containing the clean current world state tree.

其中,脏数据提交子单元,具体用于顺序遍历世界状态链,获取第x个世界状态包含的脏账户地址集合,作为第x个目标脏账户地址集合;x为小于或等于Z的正整数;Z为过渡目标第一世界状态在世界状态链中的顺序序数;遍历第x个目标脏账户地址集合中的账户地址,顺序获取第m个账户地址;m为小于或等于第x个目标脏账户地址集合中的账户地址的总数量的正整数;获取第m个账户地址对应的目标现账户状态和目标前账户状态;根据第m个账户地址的前账户状态对第m个账户地址的现账户状态进行账户脏状态数据提交处理;当第x个目标脏账户地址集合中每个脏账户地址的现账户状态均进行账户脏状态数据提交处理后,得到第x个提交后的世界状态;将目标脏账户地址添加至第x-1个链上目标脏账户地址集合,得到第x个链上目标脏账户地址集合;x为1时,第x-1个链上目标脏账户地址集合为空集合;当x等于Z时,将第x个链上目标脏账户地址集合作为全链脏账户地址集合,将第x个提交后的世界状态作为提交后的过渡目标第一世界状态。The dirty data submission subunit is specifically used to sequentially traverse the world state chain, obtain the set of dirty account addresses contained in the x-th world state, and use it as the x-th target dirty account address set; x is a positive integer less than or equal to Z; Z is the ordinal number of the transition target first world state in the world state chain; traverse the account addresses in the x-th target dirty account address set, and sequentially obtain the m-th account address; m is a positive integer less than or equal to the total number of account addresses in the x-th target dirty account address set; obtain the target current account state and target previous account state corresponding to the m-th account address; and process the m-th account address according to the previous account state of the m-th account address. The current account status of the user address is processed by committing dirty account status data. After the current account status of each dirty account address in the x-th target dirty account address set is processed by committing dirty account status data, the world state after the x-th commit is obtained. The target dirty account address is added to the (x-1)-th on-chain target dirty account address set to obtain the x-th on-chain target dirty account address set. When x is 1, the (x-1)-th on-chain target dirty account address set is an empty set. When x equals Z, the x-th on-chain target dirty account address set is taken as the full chain dirty account address set, and the world state after the x-th commit is taken as the transition target first world state after the commit.

其中,脏数据提交子单元,具体还用于对第m个账户地址的现账户状态进行账户状态树查询;若第m个账户地址的现账户状态不包含有账户状态树,或第m个账户地址的现账户状态的账户状态根不等于第m个账户地址的前账户状态的账户状态根,则根据第m个账户地址的现账户状态的树节点缓存和第m个账户地址的前账户状态的账户状态根建立指定账户状态树,将账户状态树添加至第m个账户地址的现账户状态,将第m个账户地址的现账户状态的账户状态根更新为第m个账户地址的前账户状态的账户状态根,得到指定账户状态;若第m个账户地址的现账户状态包含有账户状态树,且第m个账户地址的现账户状态的账户状态根等于第m个账户地址的前账户状态的账户状态根,则将第m个账户地址的现账户状态作为指定账户状态;若指定账户状态的脏状态数据键集合不为空,则从指定账户状态的状态数据映射中获取指定账户状态的脏状态数据键集合中脏状态数据键对应的状态数据值,将指定账户状态的脏状态数据键集合中脏状态数据键和指定账户状态的脏状态数据键集合中脏状态数据键对应的状态数据值更新到指定账户状态的账户状态树,得到包含更新账户状态树的指定账户状态;将包含更新账户状态树的指定账户状态的账户状态根更新为将更新账户状态树的状态树根;清空包含更新账户状态树的指定账户状态的脏状态数据键集合;将更新账户状态树的更新树节点哈希和更新树节点的关联关系存储至第x个世界状态。Specifically, the dirty data submission subunit is further used to perform an account state tree query on 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 state tree, or the account state root of the current account status of the m-th account address is not equal to the account state root of the previous account status of the m-th account address, then a specified account state tree is built based on the tree node cache of the current account status of the m-th account address and the account state root of the previous account status of the m-th account address. The account state tree is added to the current account status of the m-th account address, and the account state root of the current account status of the m-th account address is updated to the account state root of the previous account status of the m-th account address to obtain the specified account status. If the current account status of the m-th account address contains an account state tree, and the account state root of the current account status of the m-th account address is equal to the account state root of the previous account status of the m-th account address... If the account state root is determined, the current account state of the m-th account address is taken as the specified account state. If the dirty state data key set of the specified account state is not empty, the state data value corresponding to the dirty state data key in the dirty state data key set of the specified account state is obtained from the state data mapping of the specified account state. The dirty state data key and the state data value corresponding to the dirty state data key in the dirty state data key set of the specified account state are updated to the account state tree of the specified account state to obtain the specified account state containing the updated account state tree. The account state root of the specified account state containing the updated account state tree is updated to the state tree root of the updated account state tree. The dirty state data key set of the specified account state containing the updated account state tree is cleared. The update tree node hash and the association relationship of the update tree node are stored in the x-th world state.

其中,上述数据处理装置,还包括:The aforementioned data processing device further includes:

提交模块,用于对提交后的最新上链世界状态进行全链脏账户状态提交处理,得到干净最新上链世界状态;The submission module is used to perform full-chain dirty account state submission processing on the latest on-chain world state after submission, so as to obtain a clean latest on-chain world state.

更新模块,用于将干净最新上链世界状态中的树节点缓存中的树节点映射包含的树节点哈希和树节点更新到树节点数据库;The update module is used to update the tree node database with the tree node hashes and tree nodes contained in the tree node mapping in the clean, latest on-chain world state tree node cache.

清空模块,用于清空干净最新上链世界状态中的脏账户地址集合、账户状态映射和树节点缓存中的树节点映射。The clear module is used to clear the dirty account address set, account state mapping, and tree node mapping in the tree node cache from the latest on-chain world state.

本申请实施例一方面提供了一种计算机设备,包括:处理器、存储器、网络接口;One embodiment of this application provides a computer device, including: a processor, a memory, and a network interface;

上述处理器与上述存储器、上述网络接口相连,其中,上述网络接口用于提供数据通信网元,上述存储器用于存储计算机程序,上述处理器用于调用上述计算机程序,以执行本申请实施例中的方法。The processor is connected to the memory and the network interface. The network interface is used to provide a data communication network element, the memory is used to store a computer program, and the processor is used to call the computer program to execute the method in the embodiments of this application.

本申请实施例一方面提供了一种计算机可读存储介质,上述计算机可读存储介质中存储有计算机程序,上述计算机程序适于由处理器加载并执行本申请实施例中的方法。One aspect of this application provides a computer-readable storage medium storing a computer program adapted for loading by a processor and executing the methods described in this application.

本申请实施例一方面提供了一种计算机程序产品或计算机程序,该计算机程序产品或计算机程序包括计算机指令,该计算机指令存储在计算机可读存储介质中,计算机设备的处理器从计算机可读存储介质读取该计算机指令,处理器执行该计算机指令,使得该计算机设备执行本申请实施例中的方法。One aspect of this application provides a computer program product or computer program that includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the method described in this application.

本申请实施例中,通过构建世界状态链,可以支持同时维护不同区块高度或者同一区块高度不同分支的世界状态,即每创建一个新的区块,都会为该新区块创建一个世界状态,将该世界状态加入世界状态链中,世界状态链中的第一个世界状态为已上链的最新的区块内的交易执行过后的最新上链世界状态,世界状态链中的第二个世界状态为是上一次被共识确认的共识根世界状态,再往后的世界状态即为正在共识的区块对应的世界状态,共识根世界状态具有指向最新上链世界状态的链式关系,正在共识的区块对应的世界状态具有指向其父区块对应的世界状态的链式关系,若其父区块为已上链区块,则其具有指向共识根世界状态的链式关系,通过每个世界状态具有的链式关系,从而形成世界状态链的链式结构。因此可以保证无论同时共识多少区块,在区块共识通过后,其对应的世界状态均会按照世界状态链的链式结构逐级提交至最新上链世界状态,保证区块链系统的状态数据的一致性。In this embodiment, by constructing a world state chain, it is possible to simultaneously maintain world states at different block heights or different branches of the same block height. That is, each time a new block is created, a world state is created for that new block and added to the world state chain. The first world state in the world state chain is the latest on-chain world state after the transactions in the latest block that has been uploaded to the chain have been executed. The second world state in the world state chain is the consensus root world state that was previously confirmed by consensus. Subsequent world states are the world states corresponding to the blocks that are currently under consensus. The consensus root world state has a chain relationship pointing to the latest on-chain world state. The world state corresponding to the block that is currently under consensus has a chain relationship pointing to the world state corresponding to its parent block. If its parent block is an already on-chain block, then it has a chain relationship pointing to the consensus root world state. Through the chain relationships of each world state, a chain structure of the world state chain is formed. Therefore, it can be guaranteed that no matter how many blocks are reached in consensus at the same time, after the block consensus is passed, its corresponding world state will be submitted to the latest on-chain world state level by level according to the chain structure of the world state chain, ensuring the consistency of the state data of the blockchain system.

附图说明Attached Figure Description

为了更清楚地说明本申请实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

图1是本申请实施例提供的一种区块链节点系统的结构示意图;Figure 1 is a schematic diagram of the structure of a blockchain node system provided in an embodiment of this application;

图2a是本申请实施例提供的一种世界状态的结构示意图;Figure 2a is a schematic diagram of a world state provided in an embodiment of this application;

图2b是本申请实施例提供的一种账户状态的结构示意图;Figure 2b is a schematic diagram of an account status provided in an embodiment of this application;

图2c是本申请实施例提供的一种世界状态管理的场景示意图;Figure 2c is a schematic diagram of a world state management scenario provided by an embodiment of this application;

图2d是本申请实施例提供的一种世界状态链的结构示意图;Figure 2d is a schematic diagram of a world state chain provided in an embodiment of this application;

图3是本申请实施例提供的一种基于区块链的数据处理方法的流程示意图;Figure 3 is a flowchart illustrating a data processing method based on blockchain provided in an embodiment of this application;

图4a-图4c是本申请实施例提供的一种基于区块链的数据处理的场景示意图;Figures 4a-4c are schematic diagrams of a data processing scenario based on blockchain provided in the embodiments of this application;

图5是本申请实施例提供的一种基于交易的第一世界状态更新方法的流程示意图;Figure 5 is a flowchart illustrating a transaction-based first-world state update method provided in an embodiment of this application;

图6是本申请实施例提供的一种干净世界状态树构建方法的流程示意图;Figure 6 is a flowchart illustrating a method for constructing a clean world state tree according to an embodiment of this application;

图7是本申请实施例提供的一种基于区块链的数据处理装置的结构示意图;Figure 7 is a schematic diagram of the structure of a blockchain-based data processing device provided in an embodiment of this application;

图8是本申请实施例提供的一种计算机设备的结构示意图。Figure 8 is a schematic diagram of the structure of a computer device provided in an embodiment of this application.

具体实施方式Detailed Implementation

下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.

区块链是运行区块链技术的载体和组织方式。区块链技术(Blockchaintechnology,BT)也被称之为分布式账本技术,是一种互联网数据库技术,其特点是去中心化、公开透明,让每个人均可参与数据库记录。区块链技术是利用块链式数据结构来验证与存储数据、利用分布式节点共识算法来生成和更新数据、利用密码学的方式保证数据传输和访问的安全、利用由自动化脚本代码组成的智能合约来编程和操作数据的一种分布式基础架构与计算方式。Blockchain is the carrier and organizational method for running blockchain technology. Blockchain technology (BT), also known as distributed ledger technology, is an internet database technology characterized by decentralization and transparency, allowing everyone to participate in database recording. Blockchain technology utilizes a block-chain data structure to verify and store data, distributed node consensus algorithms to generate and update data, cryptography to ensure the security of data transmission and access, and smart contracts composed of automated script code to program and manipulate data—a distributed infrastructure and computing method.

为便于理解,以下将对区块链及其相关概念进行阐述:To facilitate understanding, the following will explain blockchain and related concepts:

区块链:区块链是一种分布式数据存储、点对点传输、共识机制以及加密算法等计算机技术的新型应用模式,主要用于对数据按时间顺序进行整理,并加密成账本,使其不可被篡改和伪造,同时可进行数据的验证、存储和更新。区块链本质上是一个去中心化的数据库,该数据库中的每个节点均存储一条相同的区块链,区块链网络可以将节点区分为共识节点和业务节点,其中共识节点负责区块链全网的共识。对于区块链网络中交易数据被写入账本的过程可以为:客户端发送交易数据至业务节点,随后该交易数据以接力棒的方式在区块链网络中的业务节点之间传递,直到共识节点收到该交易数据,共识节点再将该交易数据打包进区块,与其他共识节点之间进行共识,在共识通过后,将携带该交易数据的区块写入账本。Blockchain: Blockchain is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanisms, and encryption algorithms. It is mainly used to organize data in chronological order and encrypt it into a ledger, making it tamper-proof and forgery-proof. It also allows for data verification, storage, and updating. Essentially, a blockchain is a decentralized database where each node stores the same blockchain. The blockchain network can distinguish between consensus nodes and business nodes, with the consensus node responsible for achieving consensus across the entire network. The process of writing transaction data into the ledger in a blockchain network can be described as follows: the client sends transaction data to a business node, which then relays this data among the business nodes in the blockchain network until the consensus node receives it. The consensus node then packages the transaction data into a block and reaches a consensus with other consensus nodes. After consensus is reached, the block containing the transaction data is written into the ledger.

区块:是在区块链网络上承载交易数据(即交易业务)的数据包,是一种被标记上时间戳和之前一个区块的哈希值的数据结构,区块经过网络的共识机制验证并确定区块中的交易。A block is a data packet that carries transaction data (i.e., transaction business) on a blockchain network. It is a data structure that is marked with a timestamp and the hash value of the previous block. The transactions in the block are verified and confirmed by the network's consensus mechanism.

哈希值:也称作信息特征值或特征值,哈希值是通过哈希算法将任意长度的输入数据转换为密码并进行固定输出而生成的,不能通过解密哈希值来检索原始输入数据,它是一个单向的加密函数。在区块链中,每个区块(除了初始区块)都包含前继区块的哈希值,前继区块被称为当前区块的父区块。哈希值是区块链技术中的潜力核心基础和最重要的方面,它保留了记录和查看数据的真实性,以及区块链作为一个整体的完整性。Hash value: Also known as information feature value or characteristic value, a hash value is generated by converting input data of arbitrary length into cryptographic data and producing a fixed output through a hash algorithm. The original input data cannot be retrieved by decrypting the hash value; it is a one-way cryptographic function. In a blockchain, each block (except the initial block) contains the hash value of its predecessor block, which is called the parent block of the current block. The hash value is a core and crucial aspect of blockchain technology, preserving the authenticity of recorded and viewed data, as well as the integrity of the blockchain as a whole.

交易:区块链账户发送的交易,内有交易哈希作为唯一标识,包含有账户地址标识所属发送该交易的区块链账户。Transaction: A transaction sent by a blockchain account contains a transaction hash as a unique identifier and includes an account address to identify the blockchain account that sent the transaction.

状态快照:表示一定范围内的所有状态数据的快照,固定长度的哈希值,只要任何状态数据有任何变化,状态快照均发生变化,以此可以判断所有状态数据的完整性。State snapshot: Represents a snapshot of all state data within a certain range. It is a fixed-length hash value. Whenever any state data changes, the state snapshot changes, which can be used to determine the integrity of all state data.

账户:区块链账户,内有账户地址作为唯一标识,包含有余额作为现世界状态下该账户的数字资产,每个账户有其若干状态数据,账户含有账户状态根作为其所有状态数据的状态快照。Account: A blockchain account contains an account address as a unique identifier, a balance as the account's digital assets in the current world state, and each account has some state data. The account contains an account state root as a state snapshot of all its state data.

状态数据:存储于区块链中的账户的数据,例如存储某个账户有多少资产,或者其它智能合约需要读取或者更新的数据,每个状态数据以键值对的形式表示。State data: Data stored in the blockchain of an account, such as how much assets an account has, or other data that smart contracts need to read or update. Each piece of state data is represented in the form of a key-value pair.

上链:每个区块包含若干个交易,当一个区块经过共识插入到每个区块链节点内的区块链数据结构的过程,称为上链。On-chain: Each block contains several transactions. The process of inserting a block into the blockchain data structure of each blockchain node after consensus is called on-chain.

世界状态:区块链内各个账户所拥有的持久化数据共同组成的视图,由于交易的执行本身会修改若干个账户的部分持久化数据,因此每个区块内的每个交易执行后会有一个新的世界状态,每个区块上链后更是会更新每个区块链节点的世界状态。在同一区块上链后,每个区块链节点的世界状态必然一致。World state: A view comprised of the persistent data held by all accounts within the blockchain. Since transaction execution modifies some of the persistent data of several accounts, each transaction within a block generates a new world state after execution. Furthermore, each block's inclusion on the blockchain updates the world state of every blockchain node. Once the same block is included, the world state of every blockchain node must be consistent.

MPT:Merkle Patricia Trie,默克尔帕特里夏树,一种组织状态数据的树形结构,内含数据节点、拓展节点、分支节点三种节点。其中,状态数据包含有状态数据键和状态数据值。其中,树据节点是树型结构的叶子节点,只会出现在MPT底部,存储着实际的状态数据值;拓展节点是仅有一个子节点的父节点,包含一个任意长度字符串代表状态数据键的一部分,和另一个指向子节点的树节点哈希;分支节点可以有1至16个子节点的父节点,有一个容量为16的哈希值数组,数组中的这16个位置分别对应16进制下的0-9-a-f,并且分别有可能作为树节点哈希而指向一个子节点。其中,树节点哈希是MPT中子节点的哈希值,存储在父节点。MPT (Merkle Patricia Trie) is a tree-like structure for organizing state data, containing three types of nodes: data nodes, extension nodes, and branch nodes. State data packets contain state data keys and state data values. Data nodes are the leaf nodes of the tree structure, appearing only at the bottom of the MPT, and store the actual state data values. Extension nodes are parent nodes with only one child node, containing a string of arbitrary length representing part of the state data key, and another tree node hash pointing to the child node. Branch nodes can have parent nodes with 1 to 16 child nodes, and have a hash array of 16 capacity, where the 16 positions correspond to hexadecimal 0-9-a-f, and each can potentially serve as a tree node hash pointing to a child node. The tree node hash is the hash value of the child node in the MPT, stored in the parent node.

状态树:本申请实施例中包含有账户状态树和世界状态树,均是以MPT作为组织区块链的状态数据的数据结构,可以提供以下操作:State Tree: This application embodiment includes an account state tree and a world state tree, both of which use MPT as the data structure for the state data of the organizational blockchain and can provide the following operations:

(1)查询:可以根据状态数据键,从状态树中查询出状态数据值,此时需要向状态树提供树节点查询来源。其中,树节点查询来源是帮助状态树以树节点哈希为条件从中快速查找树节点的数据结构。状态树中的每个树节点,在数据库中是以键值对的形式存储,存储键为树节点的哈希值,存储值为树节点,因此可以根据树节点哈希从数据库中快速查找树节点。而因为状态树中每个父节点均包含其所以子节点的树节点哈希,所以可以由父节点从数据库中拓展出其所有子节点。(1) Query: The state data value can be retrieved from the state tree based on the state data key. This requires providing the state tree with a tree node query source. The tree node query source is a data structure that helps the state tree quickly find tree nodes based on their hashes. Each tree node in the state tree is stored in the database as a key-value pair, with the key being the tree node's hash value and the value being the tree node itself. Therefore, tree nodes can be quickly retrieved from the database based on their hashes. Furthermore, since each parent node in the state tree contains the hashes of all its child nodes, all its child nodes can be derived from the database from the parent node.

(2)更新:可以根据状态数据键将状态数据值更新到状态树中。(2) Update: The status data value can be updated to the status tree according to the status data key.

(3)获取状态树根:计算并获取状态树的树根的哈希值。(3) Get the root of the state tree: Calculate and get the hash value of the root of the state tree.

(4)提交:把状态树的每个树节点提交到树节点更新缓存中。因为状态树中的每个树节点,在数据库中是以键值对的形式存储,存储键为树节点的哈希值,存储值为树节点。因此,当状态树进行提交操作时,需要一个以树节点哈希为键和以树节点为值,接收键值对并存储的数据结构,此数据结构称为树节点更新缓存。(4) Commit: Commit each tree node of the state tree to the tree node update cache. Because each tree node in the state tree is stored in the database as a key-value pair, with the hash value of the tree node as the key and the tree node as the value, a data structure is needed to receive and store key-value pairs with the tree node hash as the key and the tree node as the value when the state tree is committed. This data structure is called the tree node update cache.

请参见图1,图1是本申请实施例提供的一种区块链节点系统的结构示意图。如图1所示的区块链节点系统可以对应于区块链网络,该区块链网络可以包括但不限于联盟链所对应的区块链网络。区块链节点系统是指用于进行区块链节点与区块链节点之间数据共享的系统,该区块链节点系统中可以包括多个区块链节点,多个区块链节点具体可以包括区块链节点10a、区块链节点10b、区块链节点10c、区块链节点10d、…、区块链节点10n。其中,每个区块链节点在进行正常工作时可以接收到外界发送的数据,并基于接收到的数据进行区块上链处理,也可以向外界发送数据。为了保证各个区块链节点之间的数据互通,每个区块链节点之间可以存在数据连接,例如区块链节点10a和区块链节点10b之间存在数据连接,区块链节点10a和区块链节点10c之间存在数据连接,区块链节点10b和区块链节点10c之间存在数据连接。Please refer to Figure 1, which is a schematic diagram of a blockchain node system provided in an embodiment of this application. The blockchain node system shown in Figure 1 can correspond to a blockchain network, which may include, but is not limited to, the blockchain network corresponding to a consortium blockchain. A blockchain node system refers to a system used for data sharing between blockchain nodes. This system can include multiple blockchain nodes, specifically blockchain node 10a, blockchain node 10b, blockchain node 10c, blockchain node 10d, ..., blockchain node 10n. Each blockchain node, during normal operation, can receive data sent from the outside world and perform block-on-chain processing based on the received data, and can also send data to the outside world. To ensure data interoperability between blockchain nodes, data connections can exist between each blockchain node. For example, there is a data connection between blockchain node 10a and blockchain node 10b, a data connection between blockchain node 10a and blockchain node 10c, and a data connection between blockchain node 10b and blockchain node 10c.

可以理解的是,区块链节点之间可以通过上述数据连接进行数据或者区块传输。区块链网络可以基于节点标识实现区块链节点之间的数据连接,对于区块链网络中的每个区块链节点,均具有与其对应的节点标识,而且上述每个区块链节点均可以存储与自身有相连关系的其他区块链节点的节点标识,以便后续根据其他区块链节点的节点标识,将获取到的数据或生成的区块广播至其他区块链节点,例如区块链节点10a中可以维护一个如表1所示的节点标识列表,该节点标识列表保存着其他节点的节点名称和节点标识:It is understandable that blockchain nodes can transmit data or blocks through the aforementioned data connections. The blockchain network can establish data connections between blockchain nodes based on node identifiers. Each blockchain node in the network has a corresponding node identifier, and each blockchain node can store the node identifiers of other blockchain nodes that are connected to it. This allows it to broadcast acquired data or generated blocks to other blockchain nodes based on their node identifiers. For example, blockchain node 10a can maintain a node identifier list as shown in Table 1, which stores the node names and node identifiers of other nodes.

表1Table 1

节点名称Node Name 节点标识Node identifier 节点10aNode 10a 117.114.151.174117.114.151.174 节点10bNode 10b 117.116.189.145117.116.189.145 节点10cNode 10c 117.114.151.183117.114.151.183 节点10dNode 10d 117.117.125.169117.117.125.169 节点10nNode 10n 117.116.189.125117.116.189.125

其中,节点标识可为网络之间互联的协议(Internet Protocol,IP)地址以及其他任意一种能够用于标识区块链网络中节点的信息,表1中仅以IP地址为例进行说明。例如,区块链节点10a可以通过节点标识117.116.189.145向区块链节点10b发送信息(例如,区块),且区块链节点10b可以通过节点标识117.114.151.174确定该信息是由区块链节点10a所发送的。The node identifier can be an Internet Protocol (IP) address or any other information that can be used to identify a node in a blockchain network. Table 1 uses IP addresses as an example only. For instance, blockchain node 10a can send information (e.g., a block) to blockchain node 10b using node identifier 117.116.189.145, and blockchain node 10b can determine that the information was sent by blockchain node 10a using node identifier 117.114.151.174.

在区块链中,在将一个区块进行上链之前,该区块必须经过区块链网络中的共识节点进行共识,在共识通过后才能将该区块添加到区块链上。可以理解的是,当区块链被用于政府或者商业机构的一些场景中时,并非区块链中的所有参与节点(即上述区块链节点系统中的区块链节点)都有足够的资源和必要性成为区块链的共识节点。例如,在图1所示的区块链节点系统中,可以将区块链节点10a、区块链节点10b、区块链节点10c和区块链节点10d作为该区块链节点系统中的共识节点。区块链节点系统中的共识节点参与共识,也就是对区块(包含一批交易)进行共识,包括生成区块,对区块进行投票;而非共识节点不参与共识,但会帮助传播区块和投票消息,以及相互同步状态等。In blockchain, before a block is added to the chain, it must pass consensus among the consensus nodes in the blockchain network. Only after consensus is reached can the block be added to the blockchain. It's understandable that when blockchain is used in scenarios involving government or commercial institutions, not all participating nodes in the blockchain (i.e., the blockchain nodes in the aforementioned blockchain node system) have sufficient resources and necessity to become consensus nodes. For example, in the blockchain node system shown in Figure 1, blockchain nodes 10a, 10b, 10c, and 10d can be considered as consensus nodes. Consensus nodes in the blockchain node system participate in consensus, that is, reaching consensus on blocks (containing a batch of transactions), including generating blocks and voting on blocks; while non-consensus nodes do not participate in consensus but help propagate block and voting messages, and synchronize states with each other.

其中,区块链节点可以包含以下模块:A blockchain node can contain the following modules:

交易池:每个区块链节点会接收用户发送的交易,并缓存至交易池中,根据共识机制某个区块链节点被选为出块节点时,该区块链节点会在内存中创建新区块,并把交易池中的交易打包至新区块内。Transaction pool: Each blockchain node receives transactions sent by users and caches them in the transaction pool. When a blockchain node is selected as a block producer according to the consensus mechanism, the blockchain node will create a new block in memory and package the transactions in the transaction pool into the new block.

共识模块:对交易进行打包生成候选区块,并在各个区块链节点之间,基于共识机制达成共识,产生新区块。Consensus module: Packages transactions to generate candidate blocks, and reaches a consensus among various blockchain nodes based on the consensus mechanism to generate new blocks.

智能合约容器:共识机制执行过程中需要执行区块内的每个交易,本质是执行交易中的智能合约的过程,执行智能合约中可能需要读取或者更新状态数据,本模块为智能合约执行提供执行环境。Smart contract container: The consensus mechanism needs to execute each transaction within a block during its execution process. Essentially, it is the process of executing smart contracts within transactions. Executing smart contracts may require reading or updating state data. This module provides the execution environment for smart contract execution.

世界状态管理:负责对每个共识中区块的世界状态进行维护管理。World State Management: Responsible for maintaining and managing the world state of each block in the consensus mechanism.

键值数据库:以键值对的方式持久化存储数据,可以根据键快速查找值,在本发明中负责持久化存储每个区块的数据和树节点存储,树节点存储即状态树的每个树节点的哈希值为键,每个树节点为值,因此可以根据树节点哈希快速查找树节点。Key-value database: Persistently stores data in key-value pairs, allowing for quick lookup of values based on keys. In this invention, it is responsible for persistently storing the data of each block and storing tree nodes. Tree node storage means that the hash value of each tree node in the state tree is the key, and each tree node is the value. Therefore, tree nodes can be quickly looked up based on the tree node hash.

其中,可以理解的是,上述的数据连接不限定连接方式,可以通过有线通信方式进行直接或间接地连接,也可以通过无线通信方式进行直接或间接地连接,还可以通过其他连接方式,本申请在此不做限制。It is understood that the above-mentioned data connection is not limited to the connection method. It can be connected directly or indirectly through wired communication, or directly or indirectly through wireless communication, or through other connection methods. This application does not impose any restrictions on this.

可以理解的是,本申请实施例所提供的数据处理方法可以由计算机设备执行,计算机设备包括但不限于上述区块链节点(可以为服务器或者终端)。上述服务器可以是独立的物理服务器,也可以是多个物理服务器构成的服务器集群或者分布式系统,还可以是提供云服务、云数据库、云计算、云函数、云存储、网络服务、云通信、中间件服务、域名服务、安全服务、CDN、以及大数据和人工智能平台等基础云计算服务的云服务器。上述终端可以是智能手机、平板电脑、笔记本电脑、台式计算机、智能音箱、智能手表等,但并不局限于此。It is understood that the data processing method provided in this application embodiment can be executed by a computer device, which includes, but is not limited to, the aforementioned blockchain node (which can be a server or a terminal). The aforementioned server can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms. The aforementioned terminal can be a smartphone, tablet computer, laptop computer, desktop computer, smart speaker, smartwatch, etc., but is not limited to these.

可以理解的是,本申请实施例可应用于各种场景,包括但不限于云技术、人工智能、智慧交通、辅助驾驶等场景。It is understood that the embodiments of this application can be applied to various scenarios, including but not limited to cloud technology, artificial intelligence, smart transportation, and assisted driving.

可以理解的是,在本申请的具体实施方式中,涉及到的状态数据等相关的数据,当本申请以上实施例运用到具体产品或技术中时,需要获得用户许可或者同意,且相关数据的收集、使用和处理需要遵守相关国家和地区的相关法律法规和标准。It is understood that, in the specific embodiments of this application, the status data and other related data involved need to obtain user permission or consent when the above embodiments of this application are applied to specific products or technologies, and the collection, use and processing of related data need to comply with the relevant laws, regulations and standards of relevant countries and regions.

如图1所示,区块链网络中的出块节点,例如,上述区块链节点系统中的区块链节点10a,在生成初始区块后,可以创建该初始区块对应的第一世界状态,该第一世界状态具有指向初始区块的父区块对应的第二世界状态的链式关系,此时第一世界状态和第二世界状态存在于世界状态链中,若父区块为已上链区块中具有最大区块高度的区块,则第二世界状态为共识根世界状态,共识根世界状态具有指向最新上链世界状态的链式关系,最新上链世界状态为世界状态链中的第一个世界状态,最新上链世界状态用于记录已上链区块对应的最新世界状态;然后,根据初始区块中的交易更新第一世界状态,得到目标第一世界状态,根据世界状态链对目标第一世界状态进行构建干净状态树处理,得到包含干净现世界状态树的更新目标第一世界状态;将干净现世界状态树对应的第一世界状态根写入初始区块,得到待上链区块,将共识区块发送至共识节点,以使共识节点基于第一世界状态根对待上链区块进行共识处理,得到共识结果;若共识结果为共识通过结果,则将待上链区块写入区块链中,通过世界状态链将更新目标第一世界状态逐级提交至最新上链世界状态,将更新目标第一世界状态确定为新的共识根世界状态,新的共识根世界状态具有指向提交后的最新上链世界状态的链式关系。As shown in Figure 1, a block-producing node in a blockchain network, such as blockchain node 10a in the aforementioned blockchain node system, can create a first world state corresponding to the initial block after generating it. This first world state has a chained relationship pointing to the second world state corresponding to the parent block of the initial block. At this time, the first and second world states exist in the world state chain. If the parent block is the block with the highest block height among the already chained blocks, then the second world state is the consensus root world state. The consensus root world state has a chained relationship pointing to the latest chained world state. The latest chained world state is the first world state in the world state chain and is used to record the latest world state corresponding to the already chained blocks. Then, the first world state is updated according to the transactions in the initial block. The process begins by obtaining the target first-world state. Based on the world state chain, a clean state tree is constructed from the target first-world state, resulting in an updated target first-world state containing the clean current world state tree. The first-world state root corresponding to the clean current world state tree is written into the initial block, resulting in a block to be added to the blockchain. The consensus block is then sent to the consensus nodes, enabling them to process the block to be added to the blockchain based on the first-world state root, yielding a consensus result. If the consensus result is successful, the block to be added to the blockchain is written into the blockchain. The updated target first-world state is then submitted level by level to the latest on-chain world state through the world state chain, establishing the updated target first-world state as the new consensus root world state. This new consensus root world state has a chain relationship pointing to the latest on-chain world state after submission.

为更好地理解上述世界状态管理的过程,请先参见图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还会作为世界状态20的世界状态树204和账户状态映射203中的每个账户状态的账户状态树的树节点更新缓存,世界状态树204和账户状态树可以进行提交操作,即以树节点哈希为键和以树节点为值更新到树节点缓存的树节点映射中。To better understand the world state management process described above, please refer to Figure 2a. Figure 2a is a schematic diagram of a world state structure provided in an embodiment of this application. As shown in Figure 2a, world state 20 may include a previous world state pointer 201, a dirty account address set 202, an account state mapping 203, a world state tree 204, and a tree node cache 205. The previous world state pointer 201 points to the previous world state of world state 20. The previous world state of world state 20 can be located in memory through the previous world state pointer 201. The previous world state pointer of the latest chained world state is null. The dirty account address set 202 refers to the set of account addresses within world state 20 that have been updated but have not yet been updated to the account state in world state tree 204. The account state mapping 203 is a mapping structure that maps account addresses to account states. In the account state mapping 203, account states can be quickly found based on account addresses. The world state tree 204 is an MPT data structure organized with account addresses as keys and account state roots as values. Here, the account state root refers to the hash value of the root of the account state tree contained in the account state corresponding to the account address. The tree node cache 205 includes a previous tree node cache pointer 2051 and a tree node map 2052. The previous tree node cache pointer 2051 points to the tree node cache of the previous world state of world state 20, and the previous tree node cache pointer of the tree node cache of the latest on-chain world state points to the tree node storage in the key-value database. The tree node map 2052 is a mapping structure from tree node hashes to tree nodes, allowing for fast lookup of tree nodes based on their hashes. Tree node cache 205 serves as the source for querying tree nodes in the world state tree 204 of world state 20 and the account state map 203 for each account state. World state tree 204 and the account state tree for each account state can search for tree nodes in the tree node cache's tree node map based on the tree node hash. If no tree node is found, the previous tree node cache pointer is used to locate it in memory, and the search continues in the previous tree node cache's tree node map based on the tree node hash. If still not found, the search continues backward, and so on, until the previous tree node cache pointer of the foremost tree node cache points to the tree node storage in the key-value database. Then, the search continues in the tree node storage based on the tree node hash. Tree node cache 205 also serves as the update cache for tree nodes in the world state tree 204 of world state 20 and the account state map 203 for each account state. World state tree 204 and the account state tree can be committed, i.e., updated in the tree node cache's tree node map with the tree node hash as the key and the tree node as the value.

请一并参见图2b,图2b是本申请实施例提供的一种账户状态的结构示意图。如图2b所示,账户状态21可以包含有账户地址211、账户状态根212、脏状态数据键集合213、状态数据映射214以及账户状态树215。其中,账户地址211是账户的唯一标识。其中,账户状态根212是账户状态树215的状态树根,也就是其树根的哈希值。其中,脏状态数据键集合213是指账户状态21中经过更新但未更新到账户状态树215的状态数据的键的集合。其中,状态数据映射214是指由状态数据键映射到状态数据值的映射结构,在状态数据映射214中可以根据状态数据键快速查找状态数据值。其中,账户状态树214是以状态数据键为键,以状态数据值为值进行组织的MPT数据结构。Please refer to Figure 2b, which is a schematic diagram of an account state structure provided in an embodiment of this application. As shown in Figure 2b, account state 21 may include account address 211, account state root 212, dirty state data key set 213, state data mapping 214, and account state tree 215. The account address 211 is the unique identifier of the account. The account state root 212 is the root of the account state tree 215, i.e., its hash value. The dirty state data key set 213 refers to the set of keys for state data in account state 21 that have been updated but not yet updated in the account state tree 215. The state data mapping 214 is a mapping structure that maps state data keys to state data values, allowing for quick lookup of state data values based on state data keys. The account state tree 214 is an MPT data structure organized with state data keys as keys and state data values as values.

本申请实施例提供的方法,可以通过上述图2a所示的结构来构建世界状态,通过上述图2b所示的结构来构建账户状态,然后对构建出的账户状态和世界状态进行管理,为便于理解,请一并参见图2c,图2c是本申请实施例提供的一种世界状态管理的场景示意图。如图2a所示,出块节点22(可以为上述图1所示的区块链节点系统中的任一区块链节点,例如区块链节点10b)的键值数据库23中存储着已上链的区块链数据结构231,该区块链数据结构231中包含了所有已经上链的区块。此外,键值数据库23中还包含有树节点存储232,树节点存储232中,以树节点哈希值为键、树节点为值对区块链网络中每个账户对应的账户状态树以及最新上链世界状态对应的世界状态树中的每个树节点及其哈希值进行存储。其中,最新上链世界状态是指已上链的最新的区块内的交易执行过后的世界状态。The method provided in this application embodiment can construct the world state using the structure shown in Figure 2a and the account state using the structure shown in Figure 2b. Then, the constructed account state and world state are managed. For ease of understanding, please also refer to Figure 2c, which is a schematic diagram of a world state management scenario provided in this application embodiment. As shown in Figure 2a, the key-value database 23 of the block-producing node 22 (which can be any blockchain node in the blockchain node system shown in Figure 1, such as blockchain node 10b) stores the blockchain data structure 231 that has been uploaded to the chain. This blockchain data structure 231 contains all the blocks that have been uploaded to the chain. Furthermore, the key-value database 23 also includes a tree node storage 232. In the tree node storage 232, each tree node and its hash value in the account state tree corresponding to each account in the blockchain network and the world state tree corresponding to the latest uploaded world state are stored, using the tree node hash value as the key and the tree node as the value. The latest uploaded world state refers to the world state after the transactions in the latest uploaded block have been executed.

如图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。当正在共识的区块的父区块为上一轮共识通过的区块时,该正在共识的区块的世界状态的链式关系就会指向共识根世界状态,因此正在共识的区块的世界状态必定是由共识根世界状态直接或间接延伸创建出来。而在共识根世界状态中,则具有指向最新上链世界状态的链式关系。可以理解,新的区块被共识后,新的区块对应的世界状态就会被确定为共识根世界状态,原来的共识根世界状态就可以被清空了,但是新区块上链后只需对最新上链世界状态进行更新,得到新的最新上链世界状态即可,其在内存中的存储地址无需更改。As shown in Figure 2c, the block-producing node can maintain several blocks at different heights undergoing consensus in memory 24, such as block n+1 at height n+1, block (n+2)a at height n+2, and so on. Of course, according to the consensus mechanism, there may also be different block branches at the same height, such as block (n+2)a and block (n+2)b at height n+2, but ultimately only one branch will reach consensus among the blockchain nodes of the blockchain network and complete the on-chain operation, entering the key-value database 21. In addition, memory 21 also maintains different world states, including the latest on-chain world state, the consensus root world state, and the world state corresponding to the blocks currently under consensus. The consensus root world state refers to the world state corresponding to the last block confirmed by consensus; the world state corresponding to the blocks currently under consensus, as the name suggests, is the world state created for each block in consensus, representing the source of query and update cache for state data during and after the execution of transactions within that block. As shown in Figure 2c, the world states corresponding to blocks undergoing consensus all have a chain relationship pointing to the world states corresponding to their parent blocks. A block-producing node can obtain the world state corresponding to its parent block through this chain relationship, and then, based on the chain relationship, can obtain the world state corresponding to the parent block's parent block. For example, the world state (n+2)a corresponding to block (n+2)a has a chain relationship pointing to the world state n+1 corresponding to its parent block n+1. After obtaining the world state (n+2)a corresponding to block (n+2)a, block-producing node 20 can obtain the chain relationship of world state (n+2)a, and then obtain world state n+1 based on this chain relationship. When the parent block of a block undergoing consensus is a block passed in the previous round of consensus, the chain relationship of the world state of this block will point to the consensus root world state. Therefore, the world state of a block undergoing consensus must be created directly or indirectly from the consensus root world state. Within the consensus root world state, there is a chain-like relationship pointing to the latest on-chain world state. It can be understood that after a new block is reached through consensus, the world state corresponding to the new block is determined as the consensus root world state, and the original consensus root world state can be cleared. However, after a new block is added to the chain, only the latest on-chain world state needs to be updated to obtain the new latest on-chain world state; its storage address in memory does not need to be changed.

可以理解,世界状态的链式关系可以由其前树世界状态指针和前树节点缓存指针体现,每个世界状态通过前世界状态指针指向前世界状态,和通过树节点缓存的前树节点缓存指针指向前世界状态的树节点缓存,最前的世界状态的前世界状态指针为空和树节点缓存的前树节点缓存指针指向键值数据库的树节点存储,以此形成世界状态链。为便于理解,可以一并参见图2d,图2d是本申请实施例提供的一种世界状态链的结构示意图。如图2d所示,在世界状态链中,第一个世界状态就为最新上链世界状态,最新上链世界状态没有前世界状态了,因此最新上链世界状态的前世界状态指针为空,此外,最新上链世界状态的前树节点缓存指针也无法指向前世界状态的树节点缓存,但是最新上链世界状态的前树节点缓存指针会指向树节点存储(例如,上述图2c所示的树节点存储232)。世界状态链中的第二个世界状态为共识根世界状态,共识根世界状态的前世界状态为最新上链世界状态,其树节点缓存的前树节点缓存指针,指向最新上链世界状态的树节点缓存。世界状态链从第三个世界状态开始,就是共识中的区块对应的世界状态,其前世界状态指针和树节点缓存的前树节点缓存指针,分别指向该区块的父区块的世界状态和父区块的世界状态的树节点缓存。当然,也允许两个不同的共识中的区块的世界状态的前世界状态指针和树节点缓存的前树节点缓存指针,指向同一个前世界状态和其内的树节点缓存。换言之,世界状态链在共识根世界状态之后,可以出现分支。It can be understood that the chained relationship of world states can be represented by its previous tree world state pointer and previous tree node cache pointer. Each world state points to its previous world state through the previous world state pointer, and points to the tree node cache of the previous world state through the previous tree node cache pointer of the tree node cache. The previous world state pointer of the foremost world state is null, and the previous tree node cache pointer of the tree node cache points to the tree node storage of the key-value database, thus forming a world state chain. For ease of understanding, please refer to Figure 2d, which is a schematic diagram of the structure of a world state chain provided by an embodiment of this application. As shown in Figure 2d, in the world state chain, the first world state is the latest chained world state. The latest chained world state has no previous world state, so the previous world state pointer of the latest chained world state is null. In addition, the previous tree node cache pointer of the latest chained world state cannot point to the tree node cache of the previous world state, but the previous tree node cache pointer of the latest chained world state will point to the tree node storage (for example, the tree node storage 232 shown in Figure 2c above). 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 most recently added world state, and its tree node cache pointer points to the tree node cache of the most recently added world state. Starting from the third world state, the world state corresponds to the block in the consensus. Its previous world state pointer and tree node cache pointer point to the world state of the parent block and its tree node cache, respectively. Of course, it is also permissible for the previous world state pointers and tree node cache pointers of two different blocks in the consensus to point to the same previous world state and its corresponding tree node cache. In other words, the world state chain can branch after the consensus root world state.

对于正在共识的区块对应的世界状态,最终会被提交至最新上链世界状态,当正在共识的区块完成共识后,其对应的世界状态就会成为新的共识根世界状态,具有指向最新上链世界状态的链式关系,为便于理解本申请实施例对世界状态管理的具体过程,进一步地,请参见图3,图3是本申请实施例提供的一种基于区块链的数据处理方法的流程示意图。其中,该方法可以由出块节点(例如,上述图1所对应实施例中的区块链节点系统10中的任一区块链节点)执行。以下将以本方法由出块节点执行为例进行说明,其中,该基于区块链的数据处理方法至少可以包括以下步骤S101-步骤S104:The world state corresponding to a block currently undergoing consensus will eventually be submitted to the latest on-chain world state. Once the block completing consensus, its corresponding world state becomes the new consensus root world state, possessing a chain-like relationship pointing to the latest on-chain world state. To facilitate understanding of the specific process of world state management in this application embodiment, please further refer to Figure 3, which is a flowchart illustrating a blockchain-based data processing method provided in this application embodiment. This method can be executed by a block-producing node (e.g., any blockchain node in the blockchain node system 10 in the embodiment corresponding to Figure 1 above). The following will illustrate this method using the execution of a block-producing node as an example. This blockchain-based data processing method can at least include the following steps S101-S104:

步骤S101,生成初始区块,创建所述初始区块对应的第一世界状态。Step S101: Generate an initial block and create the first world state corresponding to the initial block.

具体的,每个区块链节点可以接收交易,然后将交易缓存至交易池中。区块链网络中可以根据共识机制来选择出块节点,当某个区块链节点被选作出块节点时,就会在内存中创建新区块,新区块中包含有其父区块哈希值,通过父区块哈希值,就可以查找其父区块,然后出块节点可以把交易池中的交易打包至新区块内,就得到了初始区块。此时,出块节点就可以创建初始区块对应的第一世界状态了,出块节点可以先获取其父区块对应的第二世界状态,然后基于其父区块的第二世界状态来进行世界状态初始化,得到第一世界状态。需要说明的是,如果初始区块的父区块已经被写入了区块链数据结构中,此时初始区块的父区块只可能是区块链中最新上链的区块,父区块对应的第二世界状态即为上一轮共识通过的世界状态,即此时父区块对应的第二世界状态为上述图2c所示的共识根世界状态;如果初始区块的父区块还未被写入区块链数据结构中,此时初始区块的父区块应该正在共识中,其对应的世界状态即为上述图2c所示的正在共识的区块对应的世界状态,例如,世界状态n+1。可以理解,第一世界状态和第二世界状态均位于世界状态链中,世界状态链中的第一个世界状态为最新上链世界状态,最新上链世界状态用于记录已上链区块对应的最新世界状态;第二个共识根世界状态为共识根世界状态,共识根世界状态具有指向最新上链世界状态的链式关系,换言之,第二世界状态可能是世界状态链中的第二个世界状态,也可能是第二个世界状态后的世界状态,第一世界状态在世界状态链中就位于第二世界状态之后。Specifically, each blockchain node receives transactions and caches them in a transaction pool. Block-producing nodes are selected in the blockchain network based on a consensus mechanism. When a blockchain node is selected as a block-producing node, it creates a new block in memory. This new block contains the hash value of its parent block. Using the parent block hash value, the parent block can be found. The block-producing node then packages the transactions from the transaction pool into the new block, thus obtaining the initial block. At this point, the block-producing node can create the first-world state corresponding to the initial block. The block-producing node can first obtain the second-world state corresponding to its parent block, and then initialize the world state based on the second-world state of its parent block to obtain the first-world state. It should be noted that if the parent block of the initial block has already been written into the blockchain data structure, then the parent block of the initial block can only be the most recently added block in the blockchain. The second world state corresponding to the parent block is the world state that passed the previous round of consensus. That is, the second world state corresponding to the parent block is the consensus root world state shown in Figure 2c above. If the parent block of the initial block has not yet been written into the blockchain data structure, then the parent block of the initial block should be in consensus. 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. It is understandable that both the first world state and the second world state are located in the world state chain. The first world state in the world state chain is the latest on-chain world state, which is used to record the latest world state corresponding to the on-chain blocks. The second consensus root world state is the consensus root world state, which has a chain relationship pointing to the latest on-chain world state. In other words, the second world state may be the second world state in the world state chain, or it may be the world state after the second world state. The first world state is located after the second world state in the world state chain.

具体的,创建初始区块对应的第一世界状态的一个可行实施方法为:创建初始区块对应的初始世界状态,该初始世界状态包含有第一前世界状态指针和第一树节点缓存,该第一树节点缓存包含有第一前树节点缓存指针;然后,将第一前世界状态指针指向初始区块的父区块对应的第二世界状态,将第一前树节点缓存指针指向第二世界状态包含的第二树节点缓存,得到初始区块对应的第一世界状态。需要说明的是,此时第一世界状态的结构组成依然可以参见上述图2a所示的世界状态20,此时出块节点仅初始化了第一世界状态的第一前世界状态指针和第一前树节点缓存指针,脏账户地址集合、账户状态映射、世界状态树以及树节点映射等结构可以先初始化为空集合,也可以后续使用时在添加进第一世界状态中,本申请实施例在此不做限制。不过后续统一以世界状态在创建时就会按照如图2a所示的世界状态结构来生成世界状态,没有对应的数据就默认创建为空集合为例进行阐述。Specifically, a feasible implementation method for creating the first world state corresponding to the initial block is as follows: Create an initial world state corresponding to the initial block, which includes a pointer to the first previous world state and a first tree node cache. The first tree node cache includes a pointer to the first previous tree node cache. Then, point the pointer to the first previous world state to the second world state corresponding to the parent block of the initial block, and point the pointer to the first previous tree node cache to the second tree node cache contained in the second world state, thus obtaining the first world state corresponding to the initial block. It should be noted that the structure of the first world state can still refer to world state 20 shown in Figure 2a above. At this time, the block-producing node only initializes the pointer to the first previous world state and the pointer to the first previous tree node cache of the first world state. The dirty account address set, account state mapping, world state tree, and tree node mapping can be initialized as empty sets first, or added to the first world state later. This embodiment does not impose any restrictions here. However, the following explanation will uniformly assume that the world state is generated according to the world state structure shown in Figure 2a during creation, and an empty set is created by default if there is no corresponding data.

步骤S102,根据所述初始区块中的交易更新所述第一世界状态,得到目标第一世界状态,根据世界状态链对所述目标第一世界状态进行构建干净状态树处理,得到包含干净现世界状态树的更新目标第一世界状态。Step S102: Update the first world state according to the transactions in the initial block to obtain the target first world state; construct a clean state tree for the target first world state according to the world state chain to obtain an updated target first world state containing the clean current world state tree.

具体的,初始区块中的交易执行会修改区块链中若干个账户包含的部分状态数据,出块节点可以逐步执行初始区块中的每笔交易,确定每笔交易执行后需要修改的状态数据,作为待更新数据,然后根据待更新数据来更新第一世界状态,最终得到目标第一世界状态。此时的目标第一世界状态的账户状态映射中就将包含有需要更新的账户的账户地址以及更新后的账户状态,同一账户的账户地址和其更新后的账户状态之间具有映射关系,后续出块节点在访问第一世界状态时,就可以根据账户的账户地址,在账户状态映射中快速获取该账户对应的更新后的账户状态。同时,目标第一世界状态的脏账户地址集合中会包含有在初始区块中的交易执行完毕后,状态数据发生更新的账户的账户地址。有了目标第一世界状态的脏账户地址集合和账户状态映射,就可以去构建目标第一世界状态对应的干净现世界状态树了。Specifically, the execution of transactions in the initial block modifies some state data contained in several accounts within the blockchain. Block-producing nodes can progressively execute each transaction in the initial block, determining the state data that needs modification after each transaction's execution, which is then recorded as data to be updated. The first-world state is then updated based on this data, ultimately yielding the target first-world state. At this point, the account state mapping of the target first-world state will contain the account addresses of the accounts that need updating and their updated account states. There is a mapping relationship between the account addresses of the same account and their updated account states. Subsequent block-producing nodes, when accessing the first-world state, can quickly retrieve the updated account state corresponding to that account from the account state mapping based on the account address. Simultaneously, the dirty account address set of the target first-world state will contain the account addresses of accounts whose state data was updated after the transactions in the initial block were executed. With the dirty account address set and account state mapping of the target first-world state, the clean current-world state tree corresponding to the target first-world state can be constructed.

具体的,此时的目标第一世界状态中的世界状态树为空,也就是说目标第一世界状态中的世界状态树还未被构建,此时出块节点会根据目标第一世界状态中的第一前世界状态指针查找到第二世界状态,先获取到第二世界状态的干净的世界状态树,作为干净前世界状态树,然后根据第一树节点缓存和现状态树根构建目标第一世界状态对应的第二世界状态树,将第二世界状态树添加到目标第一世界状态,得到过渡目标第一世界状态;对过渡目标第一世界状态进行全链脏账户状态提交处理,得到包含干净现世界状态树的更新目标第一世界状态。Specifically, at this point, the world state tree in the target first world state is empty, meaning that the world state tree in the target first world state has not yet been constructed. At this time, the block-producing node will find the second world state based on the first previous world state pointer in the target first world state, first obtain the clean world state tree of the second world state as the clean previous world state tree, and then construct the second world state tree corresponding to the target first world state based on the first tree node cache and the current state tree root. The second world state tree is added to the target first world state to obtain the transitional target first world state. The transitional target first world state is then subjected to a full-chain dirty account state commit process to obtain the updated target first world state containing the clean current world state tree.

步骤S103,将所述干净现世界状态树对应的第一世界状态根写入所述初始区块,得到待上链区块,将所述共识区块发送至共识节点,以使所述共识节点基于所述第一世界状态根对所述待上链区块进行共识处理,得到共识结果。Step S103: Write the first world state root corresponding to the clean current world state tree into the initial block to obtain the block to be added to the chain. Send the consensus block to the consensus node so that the consensus node can perform consensus processing on the block to be added to the chain based on the first world state root to obtain a consensus result.

具体的,干净现世界状态树对应的第一世界状态根是指干净现世界状态树的树根的哈希值,此时第一世界状态根可以作为初始区块执行后区块链网络中所有账户包含的状态数据的状态快照。当第一世界状态根被写入初始区块后,出块节点对区块的打包完成,就得到了待上链区块,随后,出块节点会将该待上链区块经过P2P(Peer to Peer,点对点)网络传送到区块链网络中的共识节点,随后共识节点可以先构建该待上链区块对应的世界状态,然后对构建的世界状态进行上述步骤S102至步骤S103的过程,得到构建的世界状态对应的干净现世界状态树,再获取其树根的哈希值作为校验世界状态根,共识节点会将校验世界状态根和待上链区块中的第一世界状态根进行比较,若相同,则校验通过;若不同,则校验失败,待上链区块的共识失败。Specifically, the first world state root corresponding to the clean current world state tree refers to the hash value of the root of the clean current world state tree. At this time, the first world state root can serve as a state snapshot of the state data contained in all accounts in the blockchain network after the initial block is executed. After the first world state root is written into the initial block, the block-producing node completes the packaging of the block, thus obtaining the block to be added to the chain. Subsequently, the block-producing node will transmit the block to be added to the chain to the consensus node in the blockchain network through the P2P (Peer to Peer) network. Then, the consensus node can first construct the world state corresponding to the block to be added to the chain, and then perform the above steps S102 to S103 on the constructed world state to obtain the clean current world state tree corresponding to the constructed world state. Then, it obtains the hash value of its root as the verification world state root. The consensus node will compare the verification world state root with the first world state root in the block to be added to the chain. If they are the same, the verification passes; if they are different, the verification fails, and the consensus of the block to be added to the chain fails.

步骤S104,若所述共识结果为共识通过结果,则将所述待上链区块写入区块链中,通过所述世界状态链将所述更新目标第一世界状态逐级提交至最新上链世界状态,将所述更新目标第一世界状态确定为新的共识根世界状态,所述新的共识根世界状态具有指向提交后的最新上链世界状态的链式关系。Step S104: If the consensus result is a consensus pass result, the block to be added to the blockchain is written into the blockchain. The first world state of the update target is submitted to the latest on-chain world state through the world state chain. The first world state of the update target is determined as the new consensus root world state. The new consensus root world state has a chain relationship pointing to the latest on-chain world state after submission.

具体的,倘若待上链区块共识通过,出块节点和区块链网络中的其他区块链节点均会将待上链区块写入区块链中,上述提到,新的区块上链后,最新上链世界状态也会更新,此时出块节点需要将更新目标第一世界状态按照世界状态链的顺序,逐级提交至最新上链世界状态。提交完成后,更新目标第一世界状态就将被确定为新的共识根世界状态,此时新的共识根世界状态中的第一前世界状态指针会从其父区块对应的世界状态指向最新上链世界状态,新的共识根世界状态中的第一前树节点缓存指针也会指向最新上链世界状态中的前树节点缓存。例如,上述图2c所示的世界状态链中,出块节点22可以在区块n+1共识通过后,将世界状态n+1提交至共识根世界状态,然后将提交后的共识根世界状态提交至最新上链世界状态,得到提交后的最新上链世界状态。提交完成后,世界状态n+1就会被确认为新的共识根世界状态,原本具有的指向共识根世界状态的链式关系会被更新为指向提交后的最新上链世界状态的链式关系。提交后的最新上链世界状态的存储地址依然和最新上链世界状态相同,提交后的最新上链世界状态用于表征区块n+1内的交易执行后的世界状态。可选的,原本的共识根世界状态就可以删除了。Specifically, if the consensus of the block to be added to the blockchain is passed, the block-producing node and other blockchain nodes in the blockchain network will write the block to be added to the blockchain. As mentioned above, after the new block is added to the blockchain, the latest world state will also be updated. At this time, the block-producing node needs to submit the target first world state to be updated to the latest world state in the order of the world state chain. After the submission is completed, the target first world state will be determined as the new consensus root world state. At this time, the pointer of the first previous world state in the new consensus root world state will point from the world state corresponding to its parent block to the latest world state, and the pointer of the first previous tree node cache in the new consensus root world state will also point to the previous tree node cache in the latest world state. For example, in the world state chain shown in Figure 2c above, the block-producing node 22 can submit world state n+1 to the consensus root world state after the consensus of block n+1 is passed, and then submit the submitted consensus root world state to the latest world state to obtain the latest world state after submission. After the submission, world state n+1 will be confirmed as the new consensus root world state. The original chain relationship pointing to the consensus root world state will be updated to point to the latest on-chain world state after the submission. The storage address of the latest on-chain world state after the submission remains the same as the original latest on-chain world state. The latest on-chain world state after the submission is used to represent the world state after the transactions in block n+1 are executed. Optionally, the original consensus root world state can be deleted.

可选的,当更新目标第一世界状态最终提交至最新上链世界状态后,出块节点还需要将提交后的最新上链世界状态提交至树节点存储中,因为树节点存储属于键值数据库,因此也可以认为是提交至树节点数据库,具体过程可以为:对提交后的最新上链世界状态进行全链脏账户状态提交处理,得到干净最新上链世界状态;将干净最新上链世界状态中的树节点缓存中的树节点映射包含的树节点哈希和树节点更新到树节点数据库;清空干净最新上链世界状态中的脏账户地址集合、账户状态映射和树节点缓存中的树节点映射。Optionally, after the target first-world state is finally committed to the latest on-chain world state, the block-producing node also needs to commit the committed latest on-chain world state to the tree node storage. Since the tree node storage is a key-value database, it can also be considered as a commit to the tree node database. The specific process can be as follows: perform a full-chain dirty account state commit process on the committed latest on-chain world state to obtain a clean latest on-chain world state; update the tree node hash and tree node contained in the tree node cache in the clean latest on-chain world state to the tree node database; clear the dirty account address set, account state mapping and tree node mapping in the tree node cache of the clean latest on-chain world state.

为便于理解上述过程,请一并参见图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。To facilitate understanding of the above process, please refer to Figures 4a-4c. Figures 4a-4c are schematic diagrams of a data processing scenario based on blockchain provided by an embodiment of this application. As shown in Figure 4a, in block-producing node 40 (which can be block-producing node 22 shown in Figure 2c above), block 41 is the latest block added to the blockchain 42. The latest added world state 400 records a view of the state data corresponding to all accounts in the blockchain network after block 42 is added to the blockchain. At this time, in the latest added world state 400, except for the previous world state pointer which is empty, the dirty account address set, account state mapping, and tree node mapping are all empty sets. The world state tree in the latest added world state 400 is the world state tree corresponding to all state data of the blockchain at this time. The previous tree node cache pointer of the latest added world state 400 points to the tree node storage 43. It can be understood that each tree node in the world state tree of the latest added world state 400 and the tree node hash corresponding to the tree node are stored in the tree node storage 43. In addition, the memory of block-producing node 40 also contains consensus root world state 402. Consensus root world state 402 is actually the world state corresponding to the consensus submission of block 41. Its previous world state is the latest on-chain world state 400. As shown in Figure 4a, the previous world state pointer of consensus root world state 402 points to the latest on-chain world state 400, and the previous tree node cache pointer of consensus root world state 402 points to tree node cache 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进行共识,得到共识结果。For a better explanation of this method, please refer to Figure 4b. Assume that there are no blocks currently in consensus. After receiving the block production command, block production node 40 generates a new block 420 with block 41 as its parent block. The parent hash contained in the new block 420 is the hash value of block 41. Then, block production node 40 packages a portion of the transactions in the transaction pool into the new block 420 in order, thus obtaining the initial block 421. Subsequently, block production node 40 can construct the first world state 402 corresponding to the initial block 421. The first world state in the first world state 402 will point to the second world state corresponding to the parent block of the initial block 421. Since the parent block of the initial block 421 is an on-chain block, its corresponding second world state is actually the consensus root world state 401. Therefore, 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. At this time, the other components of the first world state 402, such as the dirty account address set and the world state tree, are all empty sets. Then, block-producing node 40 executes the transactions in the initial block 421. During the execution of these transactions, it updates the first-world state 402 to obtain the target first-world state 403. This update involves writing the account address of the account to be updated and the updated account state into the account state mapping of first-world state 402, and adding the account address of the account to be updated to the dirty account address set of first-world state 402. For example, after transaction 1 is executed, the state data of account A will be changed, so the account state of account A will be updated accordingly. Assuming the updated account state is account state A, block-producing node 40 will write the account address A corresponding to account A into the dirty account address set of first-world state 402, and then add the mapping relationship between account address A and account state A to the account state mapping of first-world state 402. After all transactions in the initial block 421 have been executed, the target first-world state 403 is obtained. At this point, the world state tree for the target first-world state 403 has not yet been constructed. Then, block-producing node 40 constructs the target first-world state 403 to perform a clean world state tree construction process, obtaining a clean current-world state tree. Finally, the block-producing node uses the root of the state tree corresponding to the clean current-world state tree as the first-world state root and adds it to the initial block 421, resulting in the block to be added to the blockchain 422. Subsequently, the block-producing node can send the block to be added to the blockchain 422 to the consensus nodes in the blockchain network, allowing the consensus nodes to reach a consensus on the block to be added based on the first-world state root, thus obtaining the consensus result.

进一步地,请一并参见图4c。图4c所示,当共识结果为共识通过结果,此时出块节点40中待上链区块422对应的世界状态为包含干净现世界状态树的更新目标第一世界状态404,出块节点40会将更新目标第一世界状态404逐渐提交至最新上链世界状态,即将更新目标第一世界状态404先提交至共识根世界状态401,再将提交后的共识根世界状态提交至最新上链世界状态400,最后将提交后的最新上链世界状态提交至树节点存储43中,待上链区块422也会被写入区块链42中,成为最新上链的区块,此时更新第一目标时间状态404会被作为新的共识根世界状态,出块节点40会将其第一前世界状态指针指向提交后的最新上链世界状态,将其第一前树节点缓存指针指向提交后的最新上链世界状态的树节点缓存。Further, please refer to Figure 4c. As shown in Figure 4c, when the consensus result is a consensus pass, the world state corresponding to the block 422 to be added to the chain in the block-producing node 40 is the first world state 404, which contains the clean current world state tree. The block-producing node 40 will gradually submit the first world state 404 to the latest on-chain world state. That is, the first world state 404 will first be submitted to the consensus root world state 401, then the submitted consensus root world state will be submitted to the latest on-chain world state 400, and finally the submitted latest on-chain world state will be submitted to the tree node storage 43. The block 422 to be added to the chain will also be written into the blockchain 42 and become the latest on-chain block. At this time, 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 point its first previous tree node cache pointer to the tree node cache of the latest on-chain world state after submission.

采用本申请实施例提供的方法,在区块执行过程中更新状态数据时,不需要记录状态数据变更的旧值,而且对于执行失败的交易不需要进行状态数据的回滚操作,节省了系统开销。Using the method provided in this application embodiment, when updating state data during block execution, it is not necessary to record the old value of the changed state data, and it is not necessary to perform state data rollback operation for failed transactions, thus saving system overhead.

进一步地,请参见图5,图5是本申请实施例提供的一种基于交易的第一世界状态更新方法的流程示意图。其中,该更新方法是上述图3所对应实施例中步骤S102所述的根据初始区块中的交易更新第一世界状态,得到目标第一世界状态的一种可行实现方法。其中,该方法同样可以由出块节点(例如,上述图1所对应实施例中的区块链节点系统10中的任一区块链节点)执行。以下将以本方法由出块节点执行为例进行说明,其中,该第一世界状态更新方法至少可以包括以下步骤S201-步骤S205:Further, please refer to Figure 5, which is a flowchart illustrating a transaction-based first-world state update method provided in an embodiment of this application. This update method is a feasible implementation of step S102 in the embodiment corresponding to Figure 3, which updates the first-world state based on transactions in the initial block to obtain the target first-world state. This method can also be executed by a block-producing node (e.g., any blockchain node in the blockchain node system 10 in the embodiment corresponding to Figure 1). The following description will use the execution of this method by a block-producing node as an example, wherein the first-world state update method may include at least the following steps S201-S205:

步骤S201,顺序遍历初始区块中的交易,获取所述初始区块中的第k个交易;k为小于或等于H的正整数;H为所述初始区块中的交易的总数量。Step S201: Iterate through the transactions in the initial block sequentially to obtain the k-th 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.

具体的,当初始区块中包含有多个交易时,出块节点会遍历初始区块,顺序获取第一个交易,然后执行第一个交易,再根据第一个交易的执行结果来更新第一世界状态,得到第一个提交世界状态,然后再获取第二个交易,执行第二个交易,再根据第二个交易的执行结果来更新第一个提交世界状态,得到第二个提交世界状态,以此类推,直至处理完初始区块中的所有交易,就得到目标第一世界状态了。为便于理解,以处理第k个交易为例进行说明。Specifically, when the initial block contains multiple transactions, the block-producing node traverses the initial block, sequentially retrieving the first transaction, executing it, and updating the first-world state based on the execution result of the first transaction to obtain the first committed world state. Then, it retrieves the second transaction, executes it, and updates the first committed world state based on the execution result to obtain the second committed world state, and so on, until all transactions in the initial block have been processed, thus obtaining the target first-world state. For ease of understanding, we will use the processing of the k-th transaction as an example.

步骤S202,创建所述第k个交易对应的第k个交易世界状态;所述第k个交易世界状态具有指向第k-1个提交世界状态的链式关系;k为1时,所述第k-1个提交世界状态为第一世界状态。Step S202: Create the world state of the kth transaction corresponding to the kth transaction; the world state of the kth transaction has a chain relationship pointing to the (k-1)th submitted world state; when k is 1, the (k-1)th submitted world state is the first world state.

具体的,出块节点会先创建第k个交易对应的第k个交易世界状态,对于第k个交易世界状态来说,其前世界状态就为第k-1个提交世界状态,此时第k个交易世界状态的创建可以参见上述步骤S101中第一世界状态的创建过程,这里不再进行赘述。第k个交易世界状态具有指向第k-1个提交世界状态的链式关系。可以理解,对于第一个交易来说,其前世界状态就为第一世界状态。Specifically, the block-producing node first creates the world state corresponding to the k-th transaction. For the k-th transaction world state, its previous world state is the (k-1)-th committed world state. The creation of the k-th transaction world state can be referenced from the creation process of the first world state in step S101 above, and will not be repeated here. The k-th transaction world state has a chain relationship pointing to the (k-1)-th committed world state. It can be understood that for the first transaction, its previous world state is the first world state.

步骤S203,执行所述第k个交易,在第k个交易执行的过程中对所述第k个交易世界状态进行状态更新处理,得到第k个更新交易世界状态。Step S203: Execute the k-th transaction. During the execution of the k-th transaction, perform state update processing on the world state of the k-th transaction to obtain the world state of the k-th updated transaction.

具体的,由上述图2b所示的账户状态的结构可知,第k个交易世界状态可以包含有账户状态映射和脏账户地址集合,只是此时第k个交易世界状态的账户状态映射和脏账户地址集合皆为空。在第k个交易执行的过程中,出块节点在执行交易中的智能合约时,可以需要读取或者更新某个账户的状态数据,此时出块节点会确定待查询数据或者待更新数据。其中,待查询数据可以包含待查询账户地址和待查询状态数据键;待更新数据可以包括待更新账户地址、待更新状态数据键和待更新状态数据值。然后,出块节点可以基于待更新数据来对第k个交易世界状态进行状态更新处理,或者,基于待查询数据来对第k个交易世界状态进行查询处理。Specifically, as shown in Figure 2b above, the account state structure can contain an account state mapping and a set of dirty account addresses, except that both the account state mapping and the dirty account address set are empty at this point. During the execution of the k-th transaction, when the block-producing node executes the smart contract within the transaction, it may need to read or update the state data of a certain account. At this time, the block-producing node will determine the data to be queried or the data to be updated. The data to be queried may contain the account address to be queried and the state data key to be queried; the data to be updated may contain the account address to be updated, the state data key to be updated, and the state data value to be updated. Then, the block-producing node can either update the k-th transaction world state based on the data to be updated, or query the k-th transaction world state based on the data to be queried.

具体的,执行第k个交易,在第k个交易执行的过程中对第k个交易世界状态进行状态更新处理,得到第k个更新交易世界状态的一个可行实施过程为:执行第k个交易,在第k个交易执行的过程中确定第k个交易对应的待更新数据,即上述所说的待更新账户地址、待更新状态数据键和待更新状态数据值,然后根据第k个交易世界状态获取待更新账户地址对应的账户状态,作为待更新账户状态;将待更新状态数据键和待更新状态数据值的映射关系更新到待更新状态数据映射中,将待更新状态数据键插入到待更新脏状态数据键集合中,得到现账户状态;将待更新账户地址和现账户状态的映射关系更新到第k个交易世界状态包含的账户状态映射中,将待更新账户地址插入到第k个交易世界状态包含的脏账户地址集合中,得到第k个更新交易世界状态。Specifically, a feasible implementation process for executing the k-th transaction and updating the world state of the k-th transaction during the execution of the k-th transaction to obtain the k-th updated transaction world state is as follows: Execute the k-th transaction; during the execution of the k-th transaction, determine the data to be updated corresponding to the k-th transaction, namely the account address to be updated, the state data key to be updated, and the state data value to be updated, as mentioned above; then, obtain the account state corresponding to the account address to be updated based on the world state of the k-th transaction, and use it as the account state to be updated; update the mapping relationship between the state data key and the state data value to be updated in the state data mapping to be updated; insert the state data key to be updated into the dirty state data key set to be updated to obtain the current account state; update the mapping relationship between the account address to be updated and the current account state to the account state mapping contained in the k-th transaction world state; insert the account address to be updated into the dirty account address set contained in the k-th transaction world state to obtain the k-th updated transaction world state.

具体的,根据第k个交易世界状态获取待更新账户地址对应的账户状态,作为待更新账户状态的一个可行实施过程为:根据待更新账户地址对第k个交易世界状态至最新上链世界状态进行账户状态映射顺序检索;若在账户状态映射顺序检索的过程中检索到与待更新账户地址具有映射关系的账户状态,则将最先检索到的与待更新账户地址具有映射关系的账户状态作为待更新账户状态;若在账户状态映射顺序检索的过程中未检索到与待更新账户地址具有映射关系的账户状态,则根据最新上链世界状态中的世界状态树获取待更新账户地址对应的待更新状态树根,根据待更新账户地址和待更新状态树根建立待更新账户状态。具体来说,出块节点可以根据第k个交易世界状态获取待更新账户状态的方法为,先在第k个交易世界状态的账户状态映射中去查找是否存在与待更新账户地址具有映射关系的账户状态,如果存在,就将该账户状态作为待更新账户状态,停止后续的查询检索;如果不存在,就根据第k个交易世界状态的前世界状态指针获取到第k个交易世界状态的前世界状态,也就是第k-1个提交世界状态,然后出块节点继续查找第k-1个提交世界状态的账户状态映射,看是否存在与待更新账户地址具有映射关系的账户状态,存在就直接获取,停止后续的查询检索;不存在就继续获取前世界状态,以此类推,直至出块节点一直查找到最新上链世界状态的账户状态映射,倘若最新上链世界状态的账户状态映射中也不存在与待更新账户地址具有映射关系的账户状态,上述可知,最新上链世界状态没有前世界状态了,此时出块节点就可以根据待更新账户地址,从最新上链世界状态的世界状态树中去检索待更新地址对应的账户状态根,然后在内存中新建一个账户状态,并将新建账户状态的账户地址初始化为待更新账户地址,将新建账户状态的账户状态根初始化为检索到的账户状态根,然后将初始化后的新建账户状态作为待更新账户状态。Specifically, a feasible implementation process for obtaining the account state corresponding to the account address to be updated based on the k-th transaction world state is as follows: Based on the account address to be updated, perform an account state mapping sequence retrieval from the k-th transaction world state to the latest on-chain world state; if an account state with a mapping relationship to the account address to be updated is found during the account state mapping sequence retrieval, then the first retrieved account state with a mapping relationship to the account address to be updated is taken as the account state to be updated; if no account state with a mapping relationship to the account address to be updated is found during the account state mapping sequence retrieval, then obtain the root of the state tree corresponding to the account address to be updated based on the world state tree in the latest on-chain world state, and establish the account state to be updated based on the account address to be updated and the root of the state tree to be updated. Specifically, the block-producing node can obtain the account state to be updated based on the k-th transaction world state as follows: First, it checks the account state mapping of the k-th transaction world state to see if there is an account state that is mapped to the account address to be updated. If it exists, it takes that account state as the account state to be updated and stops subsequent queries. If it does not exist, it obtains the previous world state of the k-th transaction world state (i.e., the (k-1)-th commit world state) based on the previous world state pointer of the k-th transaction world state. Then, the block-producing node continues to check the account state mapping of the (k-1)-th commit world state to see if there is an account state that is mapped to the account address to be updated. If it exists, it obtains it directly and stops subsequent queries. If it does not exist... The process continues to retrieve the previous world state, and so on, until the block-producing node finds the account state mapping of the latest on-chain world state. If there is no account state in the account state mapping of the latest on-chain world state that has a mapping relationship with the account address to be updated, as mentioned above, the latest on-chain world state has no previous world state. At this time, the block-producing node can retrieve the account state root corresponding to the address to be updated from the world state tree of the latest on-chain world state based on the account address to be updated. Then, it creates a new account state in memory, initializes the account address of the new account state to the account address to be updated, initializes the account state root of the new account state to the retrieved account state root, and then uses the initialized new account state as the account state to be updated.

具体的,执行第k个交易,在第k个交易执行的过程中对第k个交易世界状态进行查询处理的一个可行实施过程为:执行第k个交易,在第k个交易执行的过程中确定第k个交易对应的待查询数据,即上述所说的待查询账户地址和待查询状态数据键,然后,根据待查询账户地址在第k个交易世界状态的账户状态映射中进行检索,如果检索得到待查询账户地址对应的账户状态,就根据待查询状态数据键在检索得到的账户状态中继续检索,如果检索得到待查询状态数据键对应的状态数据值,就将该状态数据值作为结果返回,不再进行后续检索;如果检索不到待查询状态数据键对应的状态数据值,或者没有在第k个交易世界状态的账户状态映射中检索到待查询账户地址对应的账户状态,就根据第k个交易世界状态的前世界状态指针判断是否存在前世界状态。如果第k个交易世界状态的前世界状态指针存在,就根据前世界状态指针获取第k个交易世界状态,即上述第k-1个提交世界状态,然后继续根据待查询地址和待查询状态数据键对第k-1个提交世界状态进行检索,如果在第k-1个提交世界状态中检索到待查询状态数据键对应的状态数据值,就停止后续的检索;如果在第k-1个提交世界状态中检索不到待查询状态数据键对应的状态数据值,就继续根据第k-1个提交世界状态前世界状态指针判断是否存在前世界状态。以此类推,倘若一直检索到最新上链世界状态,在最新上链世界状态中的账户状态映射中依然没有获取到待查询状态数据键对应的状态数据值,就从最新上链世界状态的世界状态树中去检索待更新地址对应的账户状态根,然后在内存中新建一个账户状态,并将新建账户状态的账户地址初始化为待更新账户地址,将新建账户状态的账户状态根初始化为检索到的账户状态根,然后将初始化后的新建账户状态作为待查询账户状态。倘若待查询账户状态的账户状态根为空,则确定待查询状态数据键对应的状态数据值为空,停止后续的检索。倘若待查询账户状态的账户状态根不为空,但是待查询账户状态的账户状态树为空,则以最新上链世界状态的树节点缓存作为树节点查询来源,以待查询账户状态的账户状态根作为状态树根,在内存中新建账户状态树,加入到待查询账户状态中;然后在根据待查询状态数据键从待查询账户状态的账户状态树中检索出状态数据值,检索结束。Specifically, a feasible implementation process for querying the world state of the k-th transaction during its execution is as follows: During the execution of the k-th transaction, determine the data to be queried corresponding to the k-th transaction, namely the aforementioned account address and status data key. Then, search the account status mapping of the k-th transaction world state based on the account address. If the account status corresponding to the account address is found, continue searching among the retrieved account statuses based on the status data key. If the status data value corresponding to the status data key is found, return that status data value as the result and do not perform further searches. If the status data value corresponding to the status data key is not found, or if the account status corresponding to the account address is not found in the account status mapping of the k-th transaction world state, determine whether a previous world state exists based on the previous world state pointer of the k-th transaction world state. If the pointer to the previous world state of the k-th transaction world state exists, the k-th transaction world state (i.e., the (k-1)-th submitted world state) is obtained based on the pointer. Then, the (k-1)-th submitted world state is searched using the address to be queried and the data key of the state to be queried. If the state data value corresponding to the data key of the state to be queried is found in the (k-1)-th submitted world state, the subsequent search stops. If the state data value corresponding to the data key of the state to be queried is not found in the (k-1)-th submitted world state, the pointer to the previous world state of the (k-1)-th submitted world state is used to determine if a previous world state exists. This process continues until the latest on-chain world state is reached. If the state data value corresponding to the data key of the state to be queried is still not found in the account state mapping of the latest on-chain world state, the root account state corresponding to the address to be updated is retrieved from the world state tree of the latest on-chain world state. A new account state is then created in memory, and the account address of the new account state is initialized to the address to be updated. The root account state of the new account state is initialized to the retrieved root account state. The initialized new account state is then used as the account state to be queried. If the root of the account state to be queried is empty, then the state data value corresponding to the data key of the account state to be queried is determined to be empty, and subsequent retrieval stops. If the 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, then the tree node cache of the latest on-chain world state is used as the source of the tree node query, and the root of the account state to be queried is used as the root of the state tree. A new account state tree is created in memory and added to the account state to be queried; then, the state data value is retrieved from the account state tree of the account state to be queried based on the data key of the account state to be queried, and the retrieval ends.

步骤S204,若所述第k个交易执行成功,则将所述第k个更新交易世界状态提交至所述第k-1个提交世界状态,得到第k个提交世界状态。Step S204: If the kth transaction is successfully executed, the world state of the kth update transaction is submitted to the (k-1)th submission world state to obtain the kth submission world state.

具体的,若第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个账户地址的前账户状态。Specifically, if the k-th transaction is successfully executed, the k-th update transaction world state is submitted to the (k-1)-th commit world state to obtain the k-th commit world state. A feasible implementation process is as follows: traverse the account addresses in the dirty account address set contained in the k-th update transaction world state, and sequentially obtain the j-th account address; j is a positive integer less than or equal to I; I is the total number of account addresses in the dirty account address set contained in the k-th update transaction world state; obtain the current account state corresponding to the j-th account address from the account state mapping contained in the k-th update transaction world state; obtain the previous account state of the j-th account address according to the (k-1)-th commit world state; submit the current account state corresponding to the j-th account address to the previous account state of the j-th account address, insert the j-th account address into the dirty account address set contained in the (k-1)-th commit world state, and obtain the j-th transitional commit world state; when j equals I, clear the dirty account address set and account state mapping contained in the k-th update transaction world state, and take the I-th transitional commit world state as the k-th commit world state. The process of obtaining the previous account state of the j-th account address based on the (k-1)-th committed world state can be described as follows: Search the account state mapping in the (k-1)-th committed world state based on the j-th account address. If an account state with a mapping relationship to the j-th account address is found, it is used as a reference account state. Then, a new account state is created in memory, and the account address and account state root of the newly created account state are initialized based on the account address and account state root of the reference account state. This newly created account state is then used as the previous account state of the j-th account address. If no account state with a mapping relationship to the j-th account address is found... The process continues to search for the account state mapping of the previous world state submitted at the (k-1)th world state. If the search continues until the latest on-chain world state's account state mapping is found, and no account state with a mapping relationship to the j-th account address is found, the search is performed in the world state tree of the latest on-chain world state to obtain the account state root corresponding to the j-th account address. Then, a new account state is created in memory, and the account address and account state root of the newly created account state are initialized based on the j-th account address and the account state root obtained from the world state tree. The newly created account state is then used as the previous account state of the j-th account address.

具体的,将第j个账户地址对应的现账户状态提交至第j个账户地址的前账户状态,将第j个账户地址插入到第k-1个提交世界状态包含的脏账户地址集合,得到第j个过渡提交世界状态的一个可行实施过程为:将第j个账户地址对应的现账户状态包含的状态数据映射中的状态数据键和状态数据值的映射关系,更新到第j个账户地址的前账户状态包含的状态数据映射中;将第j个账户地址对应的现账户状态包含的状态数据映射中的状态数据键插入到第j个账户地址的前账户状态包含的脏状态数据键集合中,得到第j个过渡提交世界状态。Specifically, a feasible implementation of submitting the current account state corresponding to the j-th account address to the previous account state of the j-th account address, and inserting the j-th account address into the dirty account address set contained in the (k-1)-th submitted world state to obtain the j-th transitional submitted world state is as follows: update the mapping relationship between state data keys and state data values in the state data mapping contained in the current account state corresponding to the j-th account address to the state data mapping contained in the previous account state of the j-th account address; insert the state data keys in the state data mapping contained in the current account state corresponding to the j-th account address into the dirty state data key set contained in the previous account state of the j-th account address to obtain the j-th transitional submitted world state.

步骤S205,当k等于H时,将第H个提交世界状态作为目标第一世界状态。Step S205: When k equals H, the Hth submitted world state is taken as the target first world state.

具体的,目标第一世界状态中将包含有初始区块内所有交易执行完后,需要更新的账户地址以及该账户地址更新后的账户状态,目标第一世界状态的脏账户地址集合中将包含有所有需要更新的账户地址。Specifically, the target first-world state will contain the account addresses that need to be updated after all transactions in the initial block have been executed, as well as the account status after the update of the account addresses. The dirty account address set of the target first-world state will contain all account addresses that need to be updated.

进一步地,请参见图6,图6是本申请实施例提供的一种干净世界状态树构建方法的流程示意图。其中,该干净世界状态树构建方法是上述图3所对应实施例中步骤S102所述的根据世界状态链对目标第一世界状态进行构建干净状态树处理,得到包含干净现世界状态树的更新目标第一世界状态的一种可行实现方法。其中,该方法同样可以由出块节点(例如,上述图1所对应实施例中的区块链节点系统10中的任一区块链节点)执行。以下将以本方法由出块节点执行为例进行说明,其中,该干净世界状态树构建方法至少可以包括以下步骤S301-步骤S306:Further, please refer to Figure 6, which is a flowchart illustrating a clean world state tree construction method provided in this application embodiment. This clean world state tree construction method is a feasible implementation of step S102 in the embodiment corresponding to Figure 3 above, which involves constructing a clean state tree from the target first world state based on the world state chain to obtain an updated target first world state containing the clean current world state tree. This method can also be executed by a block-producing node (e.g., any blockchain node in the blockchain node system 10 in the embodiment corresponding to Figure 1 above). The following description will use the execution of this method by a block-producing node as an example, where the clean world state tree construction method can include at least the following steps S301-S306:

步骤S301,对目标第一世界状态进行世界状态树查询。Step S301: Perform a world state tree query on the target first world state.

具体的,出块节点管理的所有世界状态,都可以构建对其对应的干净的世界状态树,该干净世界状态树构建方法适用于所有世界状态,而某些世界状态中可能已经包含有世界状态树了,因此在该干净世界状态树构建方法中,需要先确定需要构建干净世界状态树的世界状态中是否包含有世界状态树。当出块节点针对目标第一世界状态进行构建干净世界状态树处理时,出块节点会对目标第一世界状态进行世界状态树查询。Specifically, a clean world state tree can be constructed for each world state managed by the block-producing node. This clean world state tree construction method applies to all world states. However, some world states may already contain a world state tree. Therefore, in this clean world state tree construction method, it is necessary to first determine whether the world state for which a clean world state tree needs to be constructed already contains a world state tree. When the block-producing node performs clean world state tree construction for the target first world state, the block-producing node will perform a world state tree lookup for the target first world state.

步骤S302,若所述目标第一世界状态包含第一世界状态树,则对包含所述第一世界状态树的所述目标第一世界状态进行全链脏账户状态提交处理,得到包含干净现世界状态树的更新目标第一世界状态。Step S302: If the target first world state contains a first world state tree, then perform a full-chain dirty account state submission process on the target first world state containing the first world state tree to obtain an updated target first world state containing a clean current world state tree.

具体的,倘若目标第一世界状态中包含有第一世界状态树,则出块节点将直接对包含第一世界状态树的目标第一世界状态进行全链脏账户状态提交处理,得到包含干净现世界状态树的更新目标第一世界状态。该提交过程可以参考下述步骤S306,这里先不进行展开描述。Specifically, if the target first-world state contains a first-world state tree, the block-producing node will directly perform a full-chain dirty account state commit on the target first-world state containing the first-world state tree, resulting in an updated target first-world state containing a clean current-world state tree. This commit process can be referred to in step S306 below, which will not be described in detail here.

步骤S303,若所述目标第一世界状态未包含所述第一世界状态树,则根据所述第一前世界状态指针查找第二世界状态。Step S303: If the target first world state does not contain the first world state tree, then the second world state is searched according to the first previous world state pointer.

具体的,倘若目标第一世界状态中没有包含第一世界状态树,则出块节点可以根据世界状态链逐个向前进行查询,依赖世界状态链中之前的世界状态的干净世界状态来构建目标第一世界状态的第二世界状态树。首先,出块节点会先根据第一前世界状态指针获取到目标第一世界状态的前世界状态,也就是第二世界状态,然后先获取第二世界状态对应的干净现世界状态树,将其作为干净前世界状态树。Specifically, if the target first-world state does not contain a first-world state tree, the block-producing node can query backwards through the world state chain, relying on the clean world states of previous world states in the world state chain to construct the second-world state tree of the target first-world state. First, the block-producing node will obtain the previous world state of the target first-world state, which is the second-world state, based on the pointer to the first previous world state. Then, it will obtain the clean current world state tree corresponding to the second world state and use it as the clean previous world state tree.

步骤S304,根据世界状态链对所述第二世界状态进行构建干净状态树处理,得到干净前世界状态树,将所述干净前世界状态树的前状态树根作为现状态树根。Step S304: Construct a clean state tree for the second world state according to the world state chain to obtain a clean pre-world state tree, and take the root of the pre-world state tree of the clean pre-world state tree as the root of the current state tree.

具体的,出块节点会对第二世界状态进行构建干净状态树处理,即对第二世界状态进行步骤S301-步骤S306的处理过程,得到第二世界状态对应的干净现世界状态树,然后将其作为目标第一世界状态的干净前世界状态树。然后,出块节点会将干净前世界状态树的前状态树根作为现状态树根。Specifically, the block-producing node constructs a clean state tree for the second world state, that is, it performs steps S301-S306 on the second world state to obtain a clean current world state tree corresponding to the second world state, and then uses this as the clean previous world state tree of the target first world state. Then, the block-producing node uses the root of the previous state tree of the clean previous world state tree as the root of the current state tree.

步骤S305,根据第一树节点缓存和所述现状态树根构建所述目标第一世界状态对应的第二世界状态树,将所述第二世界状态树添加到所述目标第一世界状态,得到过渡目标第一世界状态。Step S305: Construct a second world state tree corresponding to the target first world state based on the first tree node cache and the current state tree root, and add the second world state tree to the target first world state to obtain the transition target first world state.

具体的,出块节点会将第一树节点缓存作为树节点查询来源,然后基于现状态树根构建目标第一世界状态对应的第二世界状态树,此时目标第一世界状态的脏账户地址集合中的账户地址对应的更新账户状态还未被提交,因此需要将其进行提交,才能得到干净的第二世界状态树,即干净现世界状态树。Specifically, the block-producing node caches the first tree node as the source of tree node queries, and then constructs the second world state tree corresponding to the target first world state based on the current state tree root. At this time, the updated account state corresponding to the account address in the dirty account address set of the target first world state has not yet been committed, so it needs to be committed in order to obtain a clean second world state tree, that is, a clean current world state tree.

步骤S306,对所述过渡目标第一世界状态进行全链脏账户状态提交处理,得到包含干净现世界状态树的更新目标第一世界状态。Step S306: Perform full-chain dirty account state submission processing on the transition target first world state to obtain an updated target first world state containing a clean current world state tree.

具体的,无论是获取到了目标第一世界状态对应的第一世界状态树或者第二世界状态树后,出块节点均会进行全链脏账户状态提交处理。以包含第二世界状态树的过渡目标第一世界状态为例,出块节点会顺序遍历世界状态链,获取第x个世界状态包含的脏账户地址集合,作为第x个目标脏账户地址集合;x为小于或等于Z的正整数;Z为过渡目标第一世界状态在世界状态链中的顺序序数;遍历第x个目标脏账户地址集合中的账户地址,顺序获取第m个账户地址;m为小于或等于第x个目标脏账户地址集合中的账户地址的总数量的正整数;获取第m个账户地址对应的目标现账户状态和目标前账户状态;根据第m个账户地址的前账户状态对第m个账户地址的现账户状态进行账户脏状态数据提交处理;当第x个目标脏账户地址集合中每个脏账户地址的现账户状态均进行账户脏状态数据提交处理后,得到第x个提交后的世界状态;将目标脏账户地址添加至第x-1个链上目标脏账户地址集合,得到第x个链上目标脏账户地址集合;x为1时,第x-1个链上目标脏账户地址集合为空集合;当x等于Z时,将第x个链上目标脏账户地址集合作为全链脏账户地址集合,将第x个提交后的世界状态作为提交后的过渡目标第一世界状态。Specifically, regardless of whether the first-world state tree or the second-world state tree corresponding to the target first-world state is obtained, the block-producing node will perform a full-chain dirty account state commit process. Taking a transitional target first-world state containing a second-world state tree as an example, the block-producing node will sequentially traverse the world state chain to obtain the set of dirty account addresses contained in the x-th world state, which will be used as the x-th target dirty account address set; x is a positive integer less than or equal to Z; Z is the ordinal number of the transitional target first-world state in the world state chain; it will traverse the account addresses in the x-th target dirty account address set to sequentially obtain the m-th account address; m is a positive integer less than or equal to the total number of account addresses in the x-th target dirty account address set; it will obtain the target current account state and the target previous account state corresponding to the m-th account address; and based on the previous account of the m-th account address... The state performs dirty state data submission processing on the current account state of the m-th account address; after the current account state of each dirty account address in the x-th target dirty account address set has been submitted, the world state after the x-th submission is obtained; the target dirty account address is added to the (x-1)-th on-chain target dirty account address set, resulting in the x-th on-chain target dirty account address set; when x is 1, the (x-1)-th on-chain target dirty account address set is an empty set; when x equals Z, the x-th on-chain target dirty account address set is taken as the full chain dirty account address set, and the world state after the x-th submission is taken as the transition target first world state after submission.

具体的,根据第m个账户地址的前账户状态对第m个账户地址的现账户状态进行账户脏状态数据提交处理的一个可行实施过程,为:对第m个账户地址的现账户状态进行账户状态树查询;若第m个账户地址的现账户状态不包含有账户状态树,或第m个账户地址的现账户状态的账户状态根不等于第m个账户地址的前账户状态的账户状态根,则根据第m个账户地址的现账户状态的树节点缓存和第m个账户地址的前账户状态的账户状态根建立指定账户状态树,将账户状态树添加至第m个账户地址的现账户状态,将第m个账户地址的现账户状态的账户状态根更新为第m个账户地址的前账户状态的账户状态根,得到指定账户状态;若第m个账户地址的现账户状态包含有账户状态树,且第m个账户地址的现账户状态的账户状态根等于第m个账户地址的前账户状态的账户状态根,则将第m个账户地址的现账户状态作为指定账户状态;若指定账户状态的脏状态数据键集合不为空,则从指定账户状态的状态数据映射中获取指定账户状态的脏状态数据键集合中脏状态数据键对应的状态数据值,将指定账户状态的脏状态数据键集合中脏状态数据键和指定账户状态的脏状态数据键集合中脏状态数据键对应的状态数据值更新到指定账户状态的账户状态树,得到包含更新账户状态树的指定账户状态;将包含更新账户状态树的指定账户状态的账户状态根更新为将更新账户状态树的状态树根;清空包含更新账户状态树的指定账户状态的脏状态数据键集合;将更新账户状态树的更新树节点哈希和更新树节点的关联关系存储至第x个世界状态。Specifically, a feasible implementation process for submitting dirty account state data for the current account state of the m-th account address based on the previous account state of the m-th account address is as follows: Perform an account state tree query on the current account state of the m-th account address; if the current account state of the m-th account address does not contain an account state tree, or the account state root of the current account state of the m-th account address is not equal to the account state root of the previous account state of the m-th account address, then establish a specified account state tree based on 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, add the account state tree to the current account state of the m-th account address, and 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 to obtain the specified account state; if the current account state of the m-th account address contains an account state tree, and the current account state of the m-th account address... If the account state root is equal to the account state root of the previous account state of the m-th account address, then the current account state of the m-th account address is taken as the specified account state. If the dirty state data key set of the specified account state is not empty, then the state data value corresponding to the dirty state data key in the dirty state data key set of the specified account state is obtained from the state data mapping of the specified account state. The dirty state data key in the dirty state data key set of the specified account state and the state data value corresponding to the dirty state data key in the dirty state data key set of the specified account state are updated to the account state tree of the specified account state to obtain the specified account state containing the updated account state tree. The account state root of the specified account state containing the updated account state tree is updated to the state tree root of the updated account state tree. The dirty state data key set of the specified account state containing the updated account state tree is cleared. The update tree node hash and the association relationship of the update tree node are stored in the x-th world state.

具体的,上述过程的实际实现可以为:出块节点可以将过渡目标第一世界状态作为现世界状态,然后针对现世界状态执行“提交全链脏账户的状态数据”的方法,该方法的具体步骤为:根据现世界状态的前世界状态指针判断是否存在前世界状态,如果存在前世界状态则把前世界状态视为现世界状态继续执行“提交全链脏账户的状态数据”的方法,将得到的全链脏账户地址集合作为初始全链脏账户地址集合;如果不存在前世界状态则在内存中新建为空的初始全链脏账户地址集合。在得到初始全链脏账户地址集合后,出块节点可以遍历现世界状态的脏账户地址集合,对于每个账户地址,分别执行以下操作:根据账户地址从账户状态映射上检索出账户状态,作为现账户状态;根据现世界状态的前世界状态指针判断是否存在前世界状态,如果存在前世界状态则根据账户地址在前世界状态中获取前账户状态,如果不存在前世界状态则把现账户状态同时作为前账户状态;把前账户状态的账户状态根作为前账户状态根,并根据现世界状态的树节点缓存,现账户状态作为指定账户状态执行“提交单个账户的状态数据”的方法;然后把账户地址插入到处理全链脏账户地址集合中;当脏账户地址集合中的所有账户地址均完成上述操作后,就得到了全链脏账户地址集合和提交后的过渡目标第一世界状态。Specifically, the actual implementation of the above process can be as follows: the block-producing node can take the transition target first-world state as the current world state, and then execute the method of "submitting the state data of the entire chain dirty accounts" for the current world state. The specific steps of this method are: determine whether there is a previous world state based on the previous world state pointer of the current world state. If there is a previous world state, then take the previous world state as the current world state and continue to execute the method of "submitting the state data of the entire chain dirty accounts", and take the obtained set of the entire chain dirty account addresses as the initial set of the entire chain dirty account addresses; if there is no previous world state, then create an empty initial set of the entire chain dirty account addresses in memory. After obtaining the initial set of dirty account addresses across the entire chain, the block-producing node can traverse the set of dirty account addresses in the current world state. For each account address, the following operations are performed: The account state is retrieved from the account state mapping based on the account address and used as the current account state; the existence of a previous world state is determined based on the previous world state pointer of the current world state. If a previous world state exists, it is retrieved from the previous world state based on the account address; otherwise, the current account state is used as the previous account state; the root of the previous account state is used as the root of the previous account state, and the current account state is used as the specified account state to execute the "submit state data for a single account" method based on the tree node cache of the current world state; then, the account address is inserted into the set of dirty account addresses for processing the entire chain; after all account addresses in the dirty account address set have completed the above operations, the set of dirty account addresses across the entire chain and the first world state after submission are obtained.

具体的,把前账户状态的账户状态根作为前账户状态根,并根据现世界状态的树节点缓存,现账户状态作为指定账户状态执行“提交单个账户的状态数据”的方法的具体步骤为:如果指定账户状态的账户状态树不为空并且指定账户状态的账户状态根等于前账户状态根则跳过本步骤,否则以树节点缓存作为树节点查询来源,以前账户状态根作为状态树根,在内存中新建账户状态树,加入到指定账户状态中,再把指定账户状态的账户状态根更新为前账户状态根,继续以下步骤;如果指定账户状态的脏状态数据键集合为空则返回且本流程结束,如果指定账户状态的脏状态数据键集合不为空则继续以下步骤;遍历指定账户状态的脏状态数据键集合,根据每个状态数据键,从指定账户状态的状态数据映射中检索出状态数据值,把每对状态数据键和状态数据值更新到指定账户状态的账户状态树,继续以下步骤;把树节点缓存作为树节点更新缓存,对指定账户状态的账户状态树进行提交操作,继续以下步骤;获取指定账户状态的账户状态树的状态根,并更新到指定账户状态的账户状态根;清空指定账户状态的脏状态数据键集合。Specifically, the steps for executing the "Submit Single Account State Data" method, which uses the account state root of the previous account state as the previous account state root and the current account state as the specified account state based on the current world state tree node cache, are as follows: 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, use the tree node cache as the tree node query source, the previous account state root as the state tree root, create a new account state tree in memory, add it to the specified account state, update the account state root of the specified account state to the previous account state root, and continue with the following steps; if the dirty state data key set of the specified account state... If the set of dirty state data keys for the specified account state is empty, return and end the process. If the set of dirty state data keys for the specified account state is not empty, continue with the following steps: Traverse the set of dirty state data keys for the specified account state, retrieve the state data value from the state data mapping for the specified account state based on each state data key, update each pair of state data keys and state data values to the account state tree for the specified account state, and continue with the following steps: Use the tree node cache as the tree node update cache, commit the account state tree for the specified account state, and continue with the following steps: Obtain the state root of the account state tree for the specified account state and update the account state root for the specified account state; Clear the set of dirty state data keys for the specified account state.

通过本申请实施例提供的方法,通过构建世界状态链来同时维护不同区块高度或者同一区块高度不同分支的世界状态,兼容需要多区块同时共识的共识机制,可以保证区块链系统的状态数据的一致性The method provided in this application, by constructing a world state chain, simultaneously maintains the world state at different block heights or different branches at the same block height, is compatible with consensus mechanisms requiring simultaneous consensus across multiple blocks, and can guarantee the consistency of state data in the blockchain system.

请参见图7,图7是本申请实施例提供的一种基于区块链的数据处理装置的结构示意图。该数据处理装置可以是运行于计算机设备的一个计算机程序(包括程序代码),例如该数据处理装置为一个应用软件;该装置可以用于执行本申请实施例提供的数据处理方法中的相应步骤。如图7所示,该数据处理装置1可以包括:初始化模块11、状态创建模块12、第一状态更新模块13、第二状态更新模块14、共识模块15以及状态提交模块16。Please refer to Figure 7, which is a schematic diagram of the structure of a blockchain-based data processing device provided in an embodiment of this application. The data processing device can be a computer program (including program code) running on a computer device; for example, the data processing device is an application software. The device can be used to execute the corresponding steps in the data processing method provided in the embodiment of this application. As shown in Figure 7, 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.

初始化模块11,用于生成初始区块;Initialization module 11 is used to generate the initial block;

状态创建模块12,用于创建初始区块对应的第一世界状态;第一世界状态具有指向初始区块的父区块对应的第二世界状态的链式关系;第一世界状态和第二世界状态存在于世界状态链中;若父区块为已上链区块中具有最大区块高度的区块,则第二世界状态为共识根世界状态;世界状态链中的第一个世界状态为最新上链世界状态;共识根世界状态具有指向最新上链世界状态的链式关系;最新上链世界状态用于记录已上链区块对应的最新世界状态;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 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 already chained blocks, then the second world state is the consensus root world state; the first world state in the world state 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 already chained blocks;

第一状态更新模块13,用于根据初始区块中的交易更新第一世界状态,得到目标第一世界状态;The first state update module 13 is used to update the first world state based on the transactions in the initial block to obtain the target first world state.

第二状态更新模块14,用于根据世界状态链对目标第一世界状态进行构建干净状态树处理,得到包含干净现世界状态树的更新目标第一世界状态;The second state update module 14 is used to construct a clean state tree for the target first world state according to the world state chain, so as to obtain an updated target first world state containing the clean current world state tree.

共识模块15,用于将干净现世界状态树对应的第一世界状态根写入初始区块,得到待上链区块,将共识区块发送至共识节点,以使共识节点基于第一世界状态根对待上链区块进行共识处理,得到共识结果;Consensus module 15 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 added to the chain, and send the consensus block to the consensus node so that the consensus node can perform consensus processing on the block to be added to the chain based on the first world state root and obtain the consensus result.

状态提交模块16,用于若共识结果为共识通过结果,则将待上链区块写入区块链中,通过世界状态链将更新目标第一世界状态逐级提交至最新上链世界状态,将更新目标第一世界状态确定为新的共识根世界状态,新的共识根世界状态具有指向提交后的最新上链世界状态的链式关系。The state submission module 16 is used to write the block to be added to the blockchain if the consensus result is a consensus pass result. It submits the target first world state to the latest on-chain world state through the world state chain, and determines the target first world state as the new consensus root world state. The new consensus root world state has a chain relationship pointing to the latest on-chain world state after submission.

其中,初始化模块11、状态创建模块12、第一状态更新模块13、第二状态更新模块14、共识模块15以及状态提交模块16的具体实现方式可以参见上述图3所对应实施例中对步骤S101-步骤S104的描述,这里不再进行赘述。The specific implementation methods 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 be found in the description of steps S101-S104 in the embodiment corresponding to Figure 3 above, and will not be repeated here.

其中,状态创建模块12,包括:创建单元121以及指向单元122。The state creation module 12 includes a creation unit 121 and a pointing unit 122.

创建单元121,用于创建初始区块对应的初始世界状态;初始世界状态包含有第一前世界状态指针和第一树节点缓存;第一树节点缓存包含有第一前树节点缓存指针;Creation unit 121 is used to create the initial world state corresponding to the initial block; the initial world state contains a pointer to the first previous world state and a first tree node cache; the first tree node cache contains a pointer to the first previous tree node cache;

指向单元122,用于将第一前世界状态指针指向初始区块的父区块对应的第二世界状态,将第一前树节点缓存指针指向第二世界状态包含的第二树节点缓存,得到初始区块对应的第一世界状态。Pointer 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, and to point the first previous tree node cache pointer to the second tree node cache contained in the second world state, so as to obtain the first world state corresponding to the initial block.

其中,创建单元121以及指向单元122的具体实现方式可以参见上述图3所对应实施例中对步骤S101的描述,这里不再进行赘述。The specific implementation of the creation unit 121 and the pointing unit 122 can be found in the description of step S101 in the embodiment corresponding to Figure 3 above, and will not be repeated here.

其中,第一状态更新模块13,包括:第一交易获取单元131、交易状态创建单元132、交易状态更新单元133、交易状态提交单元134以及世界状态确定单元135。The first state update module 13 includes: a first transaction acquisition unit 131, a transaction state creation unit 132, a transaction state update unit 133, a transaction state submission unit 134, and a world state determination unit 135.

第一交易获取单元131,用于顺序遍历初始区块中的交易,获取初始区块中的第k个交易;k为小于或等于H的正整数;H为初始区块中的交易的总数量;The first transaction acquisition unit 131 is used to sequentially traverse the transactions in the initial block and acquire the k-th 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;

交易状态创建单元132,用于创建第k个交易对应的第k个交易世界状态;第k个交易世界状态具有指向第k-1个提交世界状态的链式关系;k为1时,第k-1个提交世界状态为第一世界状态;The transaction state creation unit 132 is used to create the k-th transaction world state corresponding to the k-th transaction; the k-th transaction world state has a chain relationship pointing to the (k-1)-th submitted world state; when k is 1, the (k-1)-th submitted world state is the first world state;

交易状态更新单元133,用于执行第k个交易,在第k个交易执行的过程中对第k个交易世界状态进行状态更新处理,得到第k个更新交易世界状态;The transaction state update unit 133 is used to execute the kth transaction. During the execution of the kth transaction, the world state of the kth transaction is updated to obtain the updated world state of the kth transaction.

交易状态提交单元134,用于若第k个交易执行成功,则将第k个更新交易世界状态提交至第k-1个提交世界状态,得到第k个提交世界状态;The transaction status submission unit 134 is used to submit the world state of the kth updated transaction to the (k-1)th submission world state if the kth transaction is successfully executed, thus obtaining the kth submission world state.

世界状态确定单元135,用于当k等于H时,将第H个提交世界状态作为目标第一世界状态。World state determination unit 135 is used to take the Hth submitted world state as the target first world state when k equals H.

其中,第一交易获取单元131、交易状态创建单元132、交易状态更新单元133、交易状态提交单元134以及世界状态确定单元135的具体实现方式可以参见上述图5所对应实施例中对步骤S201-步骤S205的描述,这里不再进行赘述。The specific implementation methods 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 be found in the description of steps S201-S205 in the embodiment corresponding to Figure 5 above, and will not be repeated here.

其中,第k个交易世界状态包含有账户状态映射和脏账户地址集合;The k-th transaction world state contains an account state mapping and a set of dirty account addresses;

交易状态更新单元133,包括:执行子单元1331、账户状态获取子单元1332、第一映射更新子单元1333以及第二映射更新单元1334。The transaction status update unit 133 includes: an execution subunit 1331, an account status acquisition subunit 1332, a first mapping update subunit 1333, and a second mapping update unit 1334.

执行子单元1331,用于执行第k个交易,在第k个交易执行的过程中确定第k个交易对应的待更新数据;待更新数据包括待更新账户地址、待更新状态数据键和待更新状态数据值;Execution subunit 1331 is used to execute the k-th transaction. During the execution of the k-th transaction, the data to be updated corresponding to the k-th transaction is determined. The data to be updated includes the account address to be updated, the status data key to be updated, and the status data value to be updated.

账户状态获取子单元1332,用于根据第k个交易世界状态获取待更新账户地址对应的账户状态,作为待更新账户状态;待更新账户状态包含有待更新状态数据映射和待更新脏状态数据键集合;The account status acquisition subunit 1332 is used to obtain the account status corresponding to the account address to be updated based on the k-th transaction world status, and use it as the account status to be updated; the account status to be updated contains the data mapping of the status to be updated and the set of dirty status data keys to be updated;

第一映射更新子单元1333,用于将待更新状态数据键和待更新状态数据值的映射关系更新到待更新状态数据映射中,将待更新状态数据键插入到待更新脏状态数据键集合中,得到现账户状态;The first mapping update subunit 1333 is used to update the mapping relationship between the state data key to be updated and the state data value to be updated to the state data mapping to be updated, and to insert the state data key to be updated into the dirty state data key set to be updated to obtain the current account status.

第二映射更新单元1334,用于将待更新账户地址和现账户状态的映射关系更新到第k个交易世界状态包含的账户状态映射中,将待更新账户地址插入到第k个交易世界状态包含的脏账户地址集合中,得到第k个更新交易世界状态。The second mapping update unit 1334 is used to update the mapping relationship between the account address to be updated and the current account status to the account status mapping contained in the kth transaction world state, and insert the account address to be updated into the dirty account address set contained in the kth transaction world state to obtain the kth updated transaction world state.

其中,账户状态获取子单元1332,具体用于根据待更新账户地址对第k个交易世界状态至最新上链世界状态进行账户状态映射顺序检索;若在账户状态映射顺序检索的过程中检索到与待更新账户地址具有映射关系的账户状态,则将最先检索到的与待更新账户地址具有映射关系的账户状态作为待更新账户状态;若在账户状态映射顺序检索的过程中未检索到与待更新账户地址具有映射关系的账户状态,则根据最新上链世界状态中的世界状态树获取待更新账户地址对应的待更新状态树根,根据待更新账户地址和待更新状态树根建立待更新账户状态。The account state acquisition subunit 1332 is specifically used to perform an account state mapping order retrieval from the k-th transaction world state to the latest on-chain world state based on the account address to be updated. If an account state with a mapping relationship to the account address to be updated is found during the account state mapping order retrieval process, the first account state with a mapping relationship to the account address to be updated is taken as the account state to be updated. If no account state with a mapping relationship to the account address to be updated is found during the account state mapping order retrieval process, the root of the state tree corresponding to the account address to be updated is obtained according to the world state tree in the latest on-chain world state, and the account state to be updated is established based on the account address to be updated and the root of the state tree to be updated.

其中,执行子单元1331、账户状态获取子单元1332、第一映射更新子单元1333以及第二映射更新单元1334的具体实现方式可以参见上述图5所对应实施例中对步骤S203的描述,这里不再进行赘述。The specific implementation methods 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 be found in the description of step S203 in the embodiment corresponding to Figure 5 above, and will not be repeated here.

其中,交易状态提交单元134,包括:地址获取子单元1341、现账户状态获取子单元1342、前账户状态获取子单元1343、世界状态提交子单元1344以及世界状态确定子单元1345。The transaction status submission unit 134 includes: address acquisition subunit 1341, current account status acquisition subunit 1342, previous account status acquisition subunit 1343, world status submission subunit 1344, and world status determination subunit 1345.

地址获取子单元1341,用于遍历第k个更新交易世界状态包含的脏账户地址集合中的账户地址,顺序获取第j个账户地址;j为小于或等于I的正整数;I为第k个更新交易世界状态包含的脏账户地址集合中的账户地址的总数量;Address acquisition subunit 1341 is used to traverse the set of dirty account addresses contained in the k-th updated transaction world state and sequentially acquire the j-th account address; j is a positive integer less than or equal to I; I is the total number of account addresses in the set of dirty account addresses contained in the k-th updated transaction world state.

现账户状态获取子单元1342,用于从第k个更新交易世界状态包含的账户状态映射中获取第j个账户地址对应的现账户状态;The current account status acquisition subunit 1342 is used to obtain the current account status corresponding to the j-th account address from the account status mapping contained in the k-th updated transaction world state;

前账户状态获取子单元1343,用于根据第k-1个提交世界状态获取第j个账户地址的前账户状态;The previous account status acquisition subunit 1343 is used to obtain the previous account status of the j-th account address based on the (k-1)-th submitted world status;

世界状态提交子单元1344,用于将第j个账户地址对应的现账户状态提交至第j个账户地址的前账户状态,将第j个账户地址插入到第k-1个提交世界状态包含的脏账户地址集合,得到第j个过渡提交世界状态;The world state commit subunit 1344 is used to commit the current account state corresponding to the j-th account address to the previous account state of the j-th account address, and insert the j-th account address into the dirty account address set contained in the (k-1)-th commit world state to obtain the j-th transition commit world state.

世界状态确定子单元1345,用于当j等于I时,清空第k个更新交易世界状态包含的脏账户地址集合和账户状态映射,将第I个过渡提交世界状态作为第k个提交世界状态。The world state determination subunit 1345 is used to clear the dirty account address set and account state mapping contained in the k-th update transaction world state when j equals I, and take the i-th transitional commit world state as the k-th commit world state.

其中,世界状态提交子单元1345,具体用于将第j个账户地址对应的现账户状态包含的状态数据映射中的状态数据键和状态数据值的映射关系,更新到第j个账户地址的前账户状态包含的状态数据映射中;将第j个账户地址对应的现账户状态包含的状态数据映射中的状态数据键插入到第j个账户地址的前账户状态包含的脏状态数据键集合中,得到第j个过渡提交世界状态。Specifically, the world state commit subunit 1345 is used to update the mapping relationship between state data keys and state data values in the state data mapping of the current account state corresponding to the j-th account address to the state data mapping of the previous account state corresponding to the j-th account address; and to insert the state data keys in the state data mapping of the current account state corresponding to the j-th account address into the dirty state data key set of the previous account state corresponding to the j-th account address to obtain the j-th transition commit world state.

其中,地址获取子单元1341、现账户状态获取子单元1342、前账户状态获取子单元1343、世界状态提交子单元1344以及世界状态确定子单元1345的具体实现方式可以参见上述图5所对应实施例中对步骤S204的描述,这里不再进行赘述。The specific implementation methods of address acquisition subunit 1341, current account status acquisition subunit 1342, previous account status acquisition subunit 1343, world status submission subunit 1344, and world status determination subunit 1345 can be found in the description of step S204 in the embodiment corresponding to Figure 5 above, and will not be repeated here.

其中,第二状态更新模块14,包括:树查询单元141、第一查询处理单元142、第二查询处理单元143、第一树构建单元144以及第二树构建单元145。The second state 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.

树查询单元141,用于对目标第一世界状态进行世界状态树查询;Tree query unit 141 is used to perform world state tree query on the first world state of the target;

第一查询处理单元142,用于若目标第一世界状态包含第一世界状态树,则对包含第一世界状态树的目标第一世界状态进行全链脏账户状态提交处理,得到包含干净现世界状态树的更新目标第一世界状态;The first query processing unit 142 is used to perform full-chain dirty account state submission processing on the target first world state containing the first world state tree if the target first world state contains the first world state tree, so as to obtain the updated target first world state containing the clean current world state tree.

第二查询处理单元143,用于若目标第一世界状态未包含第一世界状态树,则根据第一前世界状态指针查找第二世界状态;The second query processing unit 143 is used to search for the second world state based on the first previous world state pointer if the target first world state does not contain the first world state tree.

第一树构建单元144,用于根据世界状态链对第二世界状态进行构建干净状态树处理,得到干净前世界状态树;The first tree construction unit 144 is used to construct a clean state tree for the second world state according to the world state chain, so as to obtain a clean pre-world state tree.

第二树构建单元145,用于将干净前世界状态树的前状态树根作为现状态树根;The second tree construction unit 145 is used to take the root of the previous state tree of the clean previous world state tree as the root of the current state tree.

第二树构建单元145,还用于根据第一树节点缓存和现状态树根构建目标第一世界状态对应的第二世界状态树,将第二世界状态树添加到目标第一世界状态,得到过渡目标第一世界状态;The second tree construction unit 145 is also used to construct the second world state tree corresponding to the target first world state based on the first tree node cache and the current state tree root, and add the second world state tree to the target first world state to obtain the transition target first world state.

脏状态提交单元146,用于对过渡目标第一世界状态进行全链脏账户状态提交处理,得到包含干净现世界状态树的更新目标第一世界状态。The dirty state submission unit 146 is used to perform full-chain dirty account state submission processing on the transition target first world state to obtain the updated target first world state containing the clean current world state tree.

其中,树查询单元141、第一查询处理单元142、第二查询处理单元143、第一树构建单元144以及第二树构建单元145的具体实现方式可以参见上述图6所对应实施例中对步骤S301-步骤S306的描述,这里不再进行赘述。The specific implementation methods of the tree query unit 141, the first query processing unit 142, the second query processing unit 143, the first tree construction unit 144, and the second tree construction unit 145 can be found in the description of steps S301-S306 in the embodiment corresponding to Figure 6 above, and will not be repeated here.

其中,脏状态提交单元146,包括:脏数据提交子单元1461、根获取子单元1462、树更新子单元1463以及树提交子单元1464。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.

脏数据提交子单元1461,用于对过渡目标第一世界状态进行全链脏状态数据提交处理,得到提交后的过渡目标第一世界状态和全链脏账户地址集合;Dirty data submission subunit 1461 is used to perform full-chain dirty state data submission processing on the first world state of the transition target, and obtain the submitted first world state of the transition target and the full-chain dirty account address set.

根获取子单元1462,用于根据提交后的过渡目标第一世界状态获取全链脏账户地址集合中的每个全链脏账户地址对应的账户状态根;The root acquisition subunit 1462 is used to obtain the account state root corresponding to each full-chain dirty account address in the full-chain dirty account address set according to the first-world state of the transition target after submission.

树更新子单元1463,用于将每个全链脏账户地址和每个全链脏账户地址对应的账户状态根更新到第二世界状态树,得到干净现世界状态树;Tree update subunit 1463 is used to update the second world state tree with each full-chain dirty account address and the account state root corresponding to each full-chain dirty account address to obtain a clean current world state tree.

树提交子单元1464,用于将干净现世界状态树的更新树节点哈希和更新树节点的关联关系存储至提交后的过渡目标第一世界状态中的树节点缓存的树节点映射中,得到包含干净现世界状态树的更新目标第一世界状态。Tree submission subunit 1464 is used to store the updated tree node hash and the association relationship of the updated tree node of the clean current world state tree into the tree node mapping of the tree node cache in the transition target first world state after submission, so as to obtain the updated target first world state containing the clean current world state tree.

其中,脏数据提交子单元1461,具体用于顺序遍历世界状态链,获取第x个世界状态包含的脏账户地址集合,作为第x个目标脏账户地址集合;x为小于或等于Z的正整数;Z为过渡目标第一世界状态在世界状态链中的顺序序数;遍历第x个目标脏账户地址集合中的账户地址,顺序获取第m个账户地址;m为小于或等于第x个目标脏账户地址集合中的账户地址的总数量的正整数;获取第m个账户地址对应的目标现账户状态和目标前账户状态;根据第m个账户地址的前账户状态对第m个账户地址的现账户状态进行账户脏状态数据提交处理;当第x个目标脏账户地址集合中每个脏账户地址的现账户状态均进行账户脏状态数据提交处理后,得到第x个提交后的世界状态;将目标脏账户地址添加至第x-1个链上目标脏账户地址集合,得到第x个链上目标脏账户地址集合;x为1时,第x-1个链上目标脏账户地址集合为空集合;当x等于Z时,将第x个链上目标脏账户地址集合作为全链脏账户地址集合,将第x个提交后的世界状态作为提交后的过渡目标第一世界状态。The dirty data submission subunit 1461 is specifically used to sequentially traverse the world state chain, obtain the set of dirty account addresses contained in the x-th world state as the x-th target dirty account address set; x is a positive integer less than or equal to Z; Z is the ordinal number of the transition target first world state in the world state chain; traverse the account addresses in the x-th target dirty account address set, and sequentially obtain the m-th account address; m is a positive integer less than or equal to the total number of account addresses in the x-th target dirty account address set; obtain the target current account state and target previous account state corresponding to the m-th account address; and adjust the m-th account address according to the previous account state of the m-th account address. The current account status of each account address is processed by committing dirty state data. After the current account status of each dirty account address in the x-th target dirty account address set is processed by committing dirty state data, the world state after the x-th commit is obtained. The target dirty account address is added to the (x-1)-th on-chain target dirty account address set to obtain the x-th on-chain target dirty account address set. When x is 1, the (x-1)-th on-chain target dirty account address set is an empty set. When x equals Z, the x-th on-chain target dirty account address set is taken as the full chain dirty account address set, and the world state after the x-th commit is taken as the transition target first world state after the commit.

其中,脏数据提交子单元1461,具体还用于对第m个账户地址的现账户状态进行账户状态树查询;若第m个账户地址的现账户状态不包含有账户状态树,或第m个账户地址的现账户状态的账户状态根不等于第m个账户地址的前账户状态的账户状态根,则根据第m个账户地址的现账户状态的树节点缓存和第m个账户地址的前账户状态的账户状态根建立指定账户状态树,将账户状态树添加至第m个账户地址的现账户状态,将第m个账户地址的现账户状态的账户状态根更新为第m个账户地址的前账户状态的账户状态根,得到指定账户状态;若第m个账户地址的现账户状态包含有账户状态树,且第m个账户地址的现账户状态的账户状态根等于第m个账户地址的前账户状态的账户状态根,则将第m个账户地址的现账户状态作为指定账户状态;若指定账户状态的脏状态数据键集合不为空,则从指定账户状态的状态数据映射中获取指定账户状态的脏状态数据键集合中脏状态数据键对应的状态数据值,将指定账户状态的脏状态数据键集合中脏状态数据键和指定账户状态的脏状态数据键集合中脏状态数据键对应的状态数据值更新到指定账户状态的账户状态树,得到包含更新账户状态树的指定账户状态;将包含更新账户状态树的指定账户状态的账户状态根更新为将更新账户状态树的状态树根;清空包含更新账户状态树的指定账户状态的脏状态数据键集合;将更新账户状态树的更新树节点哈希和更新树节点的关联关系存储至第x个世界状态。Specifically, the dirty data submission subunit 1461 is further used to perform an account state tree query on the current account state of the m-th account address. If the current account state of the m-th account address does not contain an account state tree, or the account state root of the current account state of the m-th account address is not equal to the account state root of the previous account state of the m-th account address, then a specified account state tree is established based on 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. The account state tree is added to the current account state of the m-th account address, and the account state root of the current account state of the m-th account address is updated to the account state root of the previous account state of the m-th account address to obtain the specified account state. If the current account state of the m-th account address contains an account state tree, and the account state root of the current account state of the m-th account address is equal to the account state root of the previous account state of the m-th account address, then... If the m-th account address is the root of the account state, then the current account state of the m-th account address is taken as the specified account state. If the dirty state data key set of the specified account state is not empty, then the state data value corresponding to the dirty state data key in the dirty state data key set of the specified account state is obtained from the state data mapping of the specified account state. The dirty state data key in the dirty state data key set of the specified account state and the state data value corresponding to the dirty state data key in the dirty state data key set of the specified account state are updated to the account state tree of the specified account state to obtain the specified account state containing the updated account state tree. The account state root of the specified account state containing the updated account state tree is updated to the state tree root of the updated account state tree. The dirty state data key set of the specified account state containing the updated account state tree is cleared. The update tree node hash and the association relationship of the update tree node are stored in the x-th world state.

其中,脏数据提交子单元1461、根获取子单元1462、树更新子单元1463以及树提交子单元1464的具体实现方式可以参见上述图3所对应实施例中对步骤S306的描述,这里不再进行赘述。The specific implementation methods of the dirty data submission subunit 1461, root acquisition subunit 1462, tree update subunit 1463 and tree submission subunit 1464 can be found in the description of step S306 in the embodiment corresponding to Figure 3 above, and will not be repeated here.

其中,上述数据处理装置1,还包括:提交模块17、更新模块18以及清空模块19。The data processing device 1 mentioned above also includes: a submission module 17, an update module 18, and a clear module 19.

提交模块17,用于对提交后的最新上链世界状态进行全链脏账户状态提交处理,得到干净最新上链世界状态;Submission module 17 is used to perform full-chain dirty account state submission processing on the latest on-chain world state after submission, so as to obtain a clean latest on-chain world state.

更新模块18,用于将干净最新上链世界状态中的树节点缓存中的树节点映射包含的树节点哈希和树节点更新到树节点数据库;Update module 18 is used to update the tree node database with the tree node hash and tree node contained in the tree node mapping in the clean and latest on-chain world state tree node cache;

清空模块19,用于清空干净最新上链世界状态中的脏账户地址集合、账户状态映射和树节点缓存中的树节点映射。The Clear Module 19 is used to clear the dirty account address set, account state mapping, and tree node mapping in the tree node cache in the latest on-chain world state.

其中,提交模块17、更新模块18以及清空模块19的具体实现方式可以参见上述图3所对应实施例中的可选描述,这里不再进行赘述。The specific implementation methods of the submission module 17, update module 18 and clear module 19 can be found in the optional descriptions in the embodiments corresponding to Figure 3 above, and will not be repeated here.

请参见图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中可以包括操作系统、网络通信模块、用户接口模块以及设备控制应用程序。Please refer to Figure 8, which is a schematic diagram of the structure of a computer device provided in an embodiment of this application. As shown in Figure 8, the data processing device 1 in the embodiment corresponding to Figure 7 can be applied to a computer device 1000. The computer device 1000 may include: a processor 1001, a network interface 1004, and a memory 1005. In addition, the computer device 1000 may also include: a user interface 1003, and at least one communication bus 1002. The communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen and a keyboard. Optionally, the user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a Wi-Fi interface). The memory 1005 may be a high-speed RAM memory or a non-volatile memory, such as at least one disk storage device. Optionally, the memory 1005 may also be at least one storage device located away from the aforementioned processor 1001. As shown in Figure 8, the memory 1005, which is a computer-readable storage medium, may include an operating system, a network communication module, a user interface module, and a device control application program.

在如图8所示的计算机设备1000中,网络接口1004可提供网络通讯网元;而用户接口1003主要用于为用户提供输入的接口;而处理器1001可以用于调用存储器1005中存储的设备控制应用程序,以实现:In the computer device 1000 shown in Figure 8, the network interface 1004 provides 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 application stored in the memory 1005 to achieve:

生成初始区块,创建初始区块对应的第一世界状态;第一世界状态具有指向初始区块的父区块对应的第二世界状态的链式关系;第一世界状态和第二世界状态存在于世界状态链中;若父区块为已上链区块中具有最大区块高度的区块,则第二世界状态为共识根世界状态;世界状态链中的第一个世界状态为最新上链世界状态;共识根世界状态具有指向最新上链世界状态的链式关系;最新上链世界状态用于记录已上链区块对应的最新世界状态;An initial block is generated, and a first world state corresponding to the initial block is created. The first world state has a chain relationship pointing to the second world state corresponding to the parent block of the initial block. The first and second world states exist in the world state chain. If the parent block is the block with the highest block height among the already chained blocks, then the second world state is the consensus root world state. The first world state in the world state 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 already chained blocks.

根据初始区块中的交易更新第一世界状态,得到目标第一世界状态,根据世界状态链对目标第一世界状态进行构建干净状态树处理,得到包含干净现世界状态树的更新目标第一世界状态;The first world state is updated based on the transactions in the initial block to obtain the target first world state. A clean state tree is then constructed on the target first world state based on the world state chain to obtain the updated target first world state containing the clean current world state tree.

将干净现世界状态树对应的第一世界状态根写入初始区块,得到待上链区块,将共识区块发送至共识节点,以使共识节点基于第一世界状态根对待上链区块进行共识处理,得到共识结果;Write the first world state root corresponding to the clean current world state tree into the initial block to obtain the block to be added to the chain. Send the consensus block to the consensus node so that the consensus node can perform consensus processing on the block to be added to the chain based on the first world state root and obtain the consensus result.

若共识结果为共识通过结果,则将待上链区块写入区块链中,通过世界状态链将更新目标第一世界状态逐级提交至最新上链世界状态,将更新目标第一世界状态确定为新的共识根世界状态,新的共识根世界状态具有指向提交后的最新上链世界状态的链式关系。If the consensus result is a consensus pass, the block to be added to the blockchain is written into the blockchain. The target first world state is submitted to the latest on-chain world state through the world state chain. The target first world state is determined as the new consensus root world state. The new consensus root world state has a chain relationship pointing to the latest on-chain world state after submission.

应当理解,本申请实施例中所描述的计算机设备1000可执行前文图3任一个所对应实施例中对该数据处理方法的描述,在此不再赘述。另外,对采用相同方法的有益效果描述,也不再进行赘述。It should be understood that the computer device 1000 described in the embodiments of this application can execute the data processing method described in any of the embodiments corresponding to Figure 3 above, and will not be repeated here. In addition, the beneficial effects of using the same method will also not be repeated.

此外,这里需要指出的是:本申请实施例还提供了一种计算机可读存储介质,且上述计算机可读存储介质中存储有前文提及的数据处理装置1所执行的计算机程序,且上述计算机程序包括程序指令,当上述处理器执行上述程序指令时,能够执行前文图3任一个所对应实施例中对上述数据处理方法的描述,因此,这里将不再进行赘述。另外,对采用相同方法的有益效果描述,也不再进行赘述。对于本申请所涉及的计算机可读存储介质实施例中未披露的技术细节,请参照本申请方法实施例的描述。Furthermore, it should be noted that this application also provides a computer-readable storage medium storing a computer program executed by the aforementioned data processing apparatus 1. This computer program includes program instructions, which, when executed by the processor, can perform the data processing method described in any of the embodiments corresponding to FIG3 above. Therefore, further details will not be repeated here. Additionally, the beneficial effects of using the same method will also not be repeated. For technical details not disclosed in the embodiments of the computer-readable storage medium involved in this application, please refer to the description of the method embodiments of this application.

上述计算机可读存储介质可以是前述任一实施例提供的数据处理装置或者上述计算机设备的内部存储单元,例如计算机设备的硬盘或内存。该计算机可读存储介质也可以是该计算机设备的外部存储设备,例如该计算机设备上配备的插接式硬盘,智能存储卡(smart media card,SMC),安全数字(secure digital,SD)卡,闪存卡(flash card)等。进一步地,该计算机可读存储介质还可以既包括该计算机设备的内部存储单元也包括外部存储设备。该计算机可读存储介质用于存储该计算机程序以及该计算机设备所需的其他程序和数据。该计算机可读存储介质还可以用于暂时地存储已经输出或者将要输出的数据。The aforementioned computer-readable storage medium can be an internal storage unit of the data processing apparatus or computer device provided in any of the foregoing embodiments, such as a hard disk or memory of the computer device. The computer-readable storage medium can also be an external storage device of the computer device, such as a plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, etc., provided on the computer device. Furthermore, the computer-readable storage medium can include both internal and external storage units of the computer 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.

此外,这里需要指出的是:本申请实施例还提供了一种计算机程序产品或计算机程序,该计算机程序产品或计算机程序包括计算机指令,该计算机指令存储在计算机可读存储介质中。计算机设备的处理器从计算机可读存储介质读取该计算机指令,处理器执行该计算机指令,使得该计算机设备执行前文任一个所对应实施例提供的方法。Furthermore, it should be noted that this application also provides a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. The processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the method provided in any of the preceding corresponding embodiments.

本申请实施例的说明书和权利要求书及附图中的术语“第一”、“第二”等是用于区别不同对象,而非用于描述特定顺序。此外,术语“包括”以及它们任何变形,意图在于覆盖不排他的包含。例如包含了一系列步骤或单元的过程、方法、装置、产品或设备没有限定于已列出的步骤或模块,而是可选地还包括没有列出的步骤或模块,或可选地还包括对于这些过程、方法、装置、产品或设备固有的其他步骤单元。The terms "first," "second," etc., in the specification, claims, and drawings of this application are used to distinguish different objects, not to describe a specific order. Furthermore, the term "comprising," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, apparatus, product, or device that includes a series of steps or units is not limited to the listed steps or modules, but may optionally include steps or modules not listed, or may optionally include other step units inherent to these processes, methods, apparatuses, products, or devices.

本领域普通技术人员可以意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、计算机软件或者二者的结合来实现,为了清楚地说明硬件和软件的可互换性,在上述说明中已经按照网元一般性地描述了各示例的组成及步骤。这些网元究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的网元,但是这种实现不应认为超出本申请的范围。Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the foregoing description as a network element. Whether these network elements are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can implement the described network elements using different methods for each specific application, but such implementation should not be considered beyond the scope of this application.

以上所揭露的仅为本申请较佳实施例而已,当然不能以此来限定本申请之权利范围,因此依本申请权利要求所作的等同变化,仍属本申请所涵盖的范围。The above-disclosed embodiments are merely preferred embodiments of this application and should not be construed as limiting the scope of this application. Therefore, any equivalent variations made in accordance with the claims of this application shall still fall within the scope of this application.

Claims (16)

1.一种基于区块链的数据处理方法,其特征在于,包括:1. A data processing method based on blockchain, characterized in that it includes: 生成初始区块,创建所述初始区块对应的第一世界状态;所述第一世界状态具有指向所述初始区块的父区块对应的第二世界状态的链式关系;所述第一世界状态和所述第二世界状态存在于世界状态链中;若所述父区块为已上链区块中具有最大区块高度的区块,则所述第二世界状态为共识根世界状态;所述世界状态链中的第一个世界状态为最新上链世界状态;所述共识根世界状态具有指向最新上链世界状态的链式关系;所述最新上链世界状态用于记录所述已上链区块对应的最新世界状态;An initial block is generated, and a first world state corresponding to the initial block is created. The first world state has a chain relationship pointing to the second 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 highest block height among the already chained blocks, then the second world state is the consensus root world state. The first world state in the world state 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 already chained block. 根据所述初始区块中的交易更新所述第一世界状态,得到目标第一世界状态,根据所述世界状态链对所述目标第一世界状态进行构建干净状态树处理,得到包含干净现世界状态树的更新目标第一世界状态;The first world state is updated according to the transactions in the initial block to obtain the target first world state. A clean state tree is constructed on the target first world state according to the world state chain to obtain the updated target first world state containing the clean current world state tree. 将所述干净现世界状态树对应的第一世界状态根写入所述初始区块,得到待上链区块,将所述待上链区块发送至共识节点,以使所述共识节点基于所述第一世界状态根对所述待上链区块进行共识处理,得到共识结果;Write the first world state root corresponding to the clean current world state tree into the initial block to obtain the block to be added to the chain. Send the block to be added to the chain to the consensus node so that the consensus node performs consensus processing on the block to be added to the chain based on the first world state root to obtain a consensus result. 若所述共识结果为共识通过结果,则将所述待上链区块写入区块链中,通过所述世界状态链将所述更新目标第一世界状态逐级提交至所述最新上链世界状态,将所述更新目标第一世界状态确定为新的共识根世界状态,所述新的共识根世界状态具有指向提交后的最新上链世界状态的链式关系。If the consensus result is a consensus pass, the block to be added to the blockchain is written into the blockchain. The target world state is submitted to the latest on-chain world state through the world state chain. The target world state is determined as the new consensus root world state. The new consensus root world state has a chain relationship pointing to the latest on-chain world state after submission. 2.根据权利要求1所述的方法,其特征在于,所述创建所述初始区块对应的第一世界状态,包括:2. The method according to claim 1, wherein creating the first world state corresponding to the initial block includes: 创建所述初始区块对应的初始世界状态;所述初始世界状态包含有第一前世界状态指针和第一树节点缓存;所述第一树节点缓存包含有第一前树节点缓存指针;Create the 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 first previous world state pointer is set to the second world state corresponding to the parent block of the initial block, and the first previous tree node cache pointer is set to the second tree node cache contained in the second world state, so as to obtain the first world state corresponding to the initial block. 3.根据权利要求1所述的方法,其特征在于,所述根据所述初始区块中的交易更新所述第一世界状态,得到目标第一世界状态,包括:3. The method according to claim 1, wherein updating the first world state based on the transactions in the initial block to obtain the target first world state comprises: 顺序遍历所述初始区块中的交易,获取所述初始区块中的第k个交易;k为小于或等于H的正整数;H为所述初始区块中的交易的总数量;The transactions in the initial block are sequentially traversed to obtain the k-th 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; 创建所述第k个交易对应的第k个交易世界状态;所述第k个交易世界状态具有指向第k-1个提交世界状态的链式关系;k为1时,所述第k-1个提交世界状态为所述第一世界状态;Create the world state of the kth transaction corresponding to the kth transaction; the kth transaction world state has a chain relationship pointing to the (k-1)th submitted world state; when k is 1, the (k-1)th submitted world state is the first world state; 执行所述第k个交易,在第k个交易执行的过程中对所述第k个交易世界状态进行状态更新处理,得到第k个更新交易世界状态;Execute the k-th transaction, and during the execution of the k-th transaction, perform state update processing on the world state of the k-th transaction to obtain the updated world state of the k-th transaction; 若所述第k个交易执行成功,则将所述第k个更新交易世界状态提交至所述第k-1个提交世界状态,得到第k个提交世界状态;If the kth transaction is executed successfully, the world state of the kth update transaction is submitted to the (k-1)th submitted world state to obtain the kth submitted world state; 当k等于H时,将第H个提交世界状态作为目标第一世界状态。When k equals H, the Hth submitted world state is taken as the target first world state. 4.根据权利要求3所述的方法,其特征在于,所述第k个交易世界状态包含有账户状态映射和脏账户地址集合;4. The method according to claim 3, wherein the kth transaction world state includes an account state mapping and a set of dirty account addresses; 所述执行所述第k个交易,在第k个交易执行的过程中对所述第k个交易世界状态进行状态更新处理,得到第k个更新交易世界状态,包括:The execution of the k-th transaction involves updating the world state of the k-th transaction during the execution process to obtain the updated world state of the k-th transaction, including: 执行所述第k个交易,在第k个交易执行的过程中确定第k个交易对应的待更新数据;所述待更新数据包括待更新账户地址、待更新状态数据键和待更新状态数据值;Execute the k-th transaction, and during the execution of the k-th transaction, determine the data to be updated corresponding to the k-th transaction; the data to be updated includes the account address to be updated, the status data key to be updated, and the status data value to be updated; 根据所述第k个交易世界状态获取所述待更新账户地址对应的账户状态,作为待更新账户状态;所述待更新账户状态包含有待更新状态数据映射和待更新脏状态数据键集合;The account status corresponding to the account address to be updated is obtained based on the kth transaction world state, and is used as the account status to be updated; the account status to be updated includes the data mapping of the status to be updated and the set of dirty state data keys to be updated; 将所述待更新状态数据键和所述待更新状态数据值的映射关系更新到所述待更新状态数据映射中,将所述待更新状态数据键插入到所述待更新脏状态数据键集合中,得到现账户状态;The mapping relationship between the state data key to be updated and the state data value to be updated is updated to the state data mapping to be updated, and the state data key to be updated is inserted into the dirty state data key set to be updated to obtain the current account status. 将所述待更新账户地址和所述现账户状态的映射关系更新到所述第k个交易世界状态包含的账户状态映射中,将所述待更新账户地址插入到所述第k个交易世界状态包含的脏账户地址集合中,得到第k个更新交易世界状态。The mapping relationship between the account address to be updated and the current account status is updated to the account status mapping contained in the k-th transaction world state. The account address to be updated is inserted into the dirty account address set contained in the k-th transaction world state to obtain the k-th updated transaction world state. 5.根据权利要求4所述的方法,其特征在于,所述根据所述第k个交易世界状态获取所述待更新账户地址对应的账户状态,作为待更新账户状态,包括:5. The method according to claim 4, wherein obtaining the account status corresponding to the account address to be updated based on the kth transaction world state, as the account status to be updated, includes: 根据所述待更新账户地址对所述第k个交易世界状态至所述最新上链世界状态进行账户状态映射顺序检索;Based on the account address to be updated, perform an account state mapping sequence retrieval from the kth transaction world state to the latest on-chain world state; 若在账户状态映射顺序检索的过程中检索到与所述待更新账户地址具有映射关系的账户状态,则将最先检索到的与所述待更新账户地址具有映射关系的账户状态作为待更新账户状态;If an account status that is mapped to the address of the account to be updated is found during the account status mapping order retrieval process, the first account status that is mapped to the address of the account to be updated will be taken as the account status to be updated. 若在账户状态映射顺序检索的过程中未检索到与所述待更新账户地址具有映射关系的账户状态,则根据所述最新上链世界状态中的世界状态树获取所述待更新账户地址对应的待更新状态树根,根据所述待更新账户地址和所述待更新状态树根建立待更新账户状态。If no account state with a mapping relationship to the account address to be updated is found during the account state mapping sequence retrieval process, then the root of the state tree corresponding to the account address to be updated is obtained according to the world state tree in the latest on-chain world state, and the account state to be updated is established according to the account address to be updated and the root of the state tree to be updated. 6.根据权利要求4所述的方法,其特征在于,所述若所述第k个交易执行成功,则将所述第k个更新交易世界状态向所述第k-1个提交世界状态进行提交,得到第k个提交世界状态,包括:6. The method according to claim 4, characterized in that, if the k-th transaction is successfully executed, the step of submitting the k-th updated transaction world state to the (k-1)-th submitted world state to obtain the k-th submitted world state includes: 遍历所述第k个更新交易世界状态包含的脏账户地址集合中的账户地址,顺序获取第j个账户地址;j为小于或等于I的正整数;I为所述第k个更新交易世界状态包含的脏账户地址集合中的账户地址的总数量;Iterate through the set of dirty account addresses contained in the k-th updated transaction world state, and sequentially obtain the j-th account address; j is a positive integer less than or equal to I; I is the total number of account addresses in the set of dirty account addresses contained in the k-th updated transaction world state. 从所述第k个更新交易世界状态包含的账户状态映射中获取所述第j个账户地址对应的现账户状态;Obtain the current account status corresponding to the j-th account address from the account status mapping contained in the k-th updated transaction world state; 根据所述第k-1个提交世界状态获取所述第j个账户地址的前账户状态;The previous account state of the j-th account address is obtained based on the (k-1)-th submitted world state; 将所述第j个账户地址对应的现账户状态提交至所述第j个账户地址的前账户状态,将所述第j个账户地址插入到所述第k-1个提交世界状态包含的脏账户地址集合,得到第j个过渡提交世界状态;Submit the current account state corresponding to the j-th account address to the previous account state of the j-th account address, insert the j-th account address into the dirty account address set contained in the (k-1)-th submitted world state, and obtain the j-th transitional submitted world state; 当j等于I时,清空第k个更新交易世界状态包含的脏账户地址集合和账户状态映射,将所述第I个过渡提交世界状态作为第k个提交世界状态。When j equals I, clear the dirty account address set and account state mapping contained in the kth updated transaction world state, and take the i-th transitional commit world state as the kth commit world state. 7.根据权利要求6所述的方法,其特征在于,所述将所述第j个账户地址对应的现账户状态提交至所述第j个账户地址的前账户状态,将所述第j个账户地址插入到所述第k-1个提交世界状态包含的脏账户地址集合,得到第j个过渡提交世界状态,包括:7. The method according to claim 6, characterized in that, the step of submitting the current account state corresponding to the j-th account address to the previous account state of the j-th account address, and inserting the j-th account address into the dirty account address set included in the (k-1)-th submitted world state to obtain the j-th transitional submitted world state, includes: 将所述第j个账户地址对应的现账户状态包含的状态数据映射中的状态数据键和状态数据值的映射关系,更新到所述第j个账户地址的前账户状态包含的状态数据映射中;Update the mapping relationship between the status data key and the status data value in the status data mapping of the current account status corresponding to the j-th account address to the status data mapping of the previous account status of the j-th account address; 将所述第j个账户地址对应的现账户状态包含的状态数据映射中的状态数据键插入到所述第j个账户地址的前账户状态包含的脏状态数据键集合中,得到第j个过渡提交世界状态。Insert the state data key from the state data mapping of the current account state corresponding to the j-th account address into the dirty state data key set of the previous account state of the j-th account address to obtain the j-th transitional commit world state. 8.根据权利要求2所述的方法,其特征在于,所述根据所述世界状态链对所述目标第一世界状态进行构建干净状态树处理,得到更新目标第一世界状态,包括:8. The method according to claim 2, characterized in that, the step of constructing a clean state tree for the target first world state based on the world state chain to obtain an updated target first world state includes: 对所述目标第一世界状态进行世界状态树查询;Perform a world state tree query on the first world state of the target; 若所述目标第一世界状态包含第一世界状态树,则对包含所述第一世界状态树的所述目标第一世界状态进行全链脏账户状态提交处理,得到包含干净现世界状态树的更新目标第一世界状态;If the target first world state contains a first world state tree, then the target first world state containing the first world state tree is subjected to full-chain dirty account state submission processing to obtain an updated target first world state containing a clean current world state tree. 若所述目标第一世界状态未包含所述第一世界状态树,则根据所述第一前世界状态指针查找所述第二世界状态;If the target first world state does not contain the first world state tree, then the second world state is found according to the first previous world state pointer; 根据所述世界状态链对所述第二世界状态进行构建干净状态树处理,得到干净前世界状态树;Based on the world state chain, a clean state tree is constructed for the second world state to obtain a clean pre-world state tree; 将所述干净前世界状态树的前状态树根作为现状态树根;The root of the clean former world state tree is taken as the root of the current state tree. 根据所述第一树节点缓存和所述现状态树根构建所述目标第一世界状态对应的第二世界状态树,将所述第二世界状态树添加到所述目标第一世界状态,得到过渡目标第一世界状态;Construct a second world state tree corresponding to the target first world state based on the first tree node cache and the current state tree root, and add the second world state tree to the target first world state to obtain the transition target first world state; 对所述过渡目标第一世界状态进行全链脏账户状态提交处理,得到包含干净现世界状态树的更新目标第一世界状态。The transition target first world state is subjected to full-chain dirty account state submission processing to obtain an updated target first world state containing a clean current world state tree. 9.根据权利要求8所述的方法,其特征在于,所述对所述过渡目标第一世界状态进行全链脏账户状态提交处理,得到包含干净现世界状态树的更新目标第一世界状态,包括:9. The method according to claim 8, characterized in that, the step of performing a full-chain dirty account state commit process on the transition target first world state to obtain an updated target first world state containing a clean current world state tree includes: 对所述过渡目标第一世界状态进行全链脏状态数据提交处理,得到提交后的过渡目标第一世界状态和全链脏账户地址集合;The first world state of the transition target is processed by submitting full-chain dirty state data to obtain the submitted first world state of the transition target and the set of full-chain dirty account addresses. 根据所述提交后的过渡目标第一世界状态获取所述全链脏账户地址集合中的每个全链脏账户地址对应的账户状态根;Based on the first world state of the submitted transition target, obtain the account state root corresponding to each full-chain dirty account address in the full-chain dirty account address set; 将所述每个全链脏账户地址和所述每个全链脏账户地址对应的账户状态根更新到所述第二世界状态树,得到干净现世界状态树;Update the second world state tree with each full-chain dirty account address and the account state root corresponding to each full-chain dirty account address to obtain the clean current world state tree; 将所述干净现世界状态树的更新树节点哈希和更新树节点的关联关系存储至所述提交后的过渡目标第一世界状态中的树节点缓存的树节点映射中,得到包含干净现世界状态树的更新目标第一世界状态。The hash of the updated tree node of the clean current world state tree and the association relationship of the updated tree node are stored in the tree node mapping of the tree node cache in the first world state of the transition target after submission, so as to obtain the first world state of the updated target containing the clean current world state tree. 10.根据权利要求9所述的方法,其特征在于,所述对所述过渡目标第一世界状态进行全链脏状态数据提交处理,得到提交后的过渡目标第一世界状态和全链脏账户地址集合,包括:10. The method according to claim 9, characterized in that, the step of performing full-chain dirty state data submission processing on the first world state of the transition target to obtain the submitted first world state of the transition target and the full-chain dirty account address set includes: 顺序遍历所述世界状态链,获取第x个世界状态包含的脏账户地址集合,作为第x个目标脏账户地址集合;x为小于或等于Z的正整数;Z为所述过渡目标第一世界状态在所述世界状态链中的顺序序数;The world state chain is traversed sequentially to obtain the set of dirty account addresses contained in the x-th world state, which is used as the x-th target dirty account address set; x is a positive integer less than or equal to Z; Z is the ordinal number of the transition target first world state in the world state chain; 遍历所述第x个目标脏账户地址集合中的账户地址,顺序获取第m个账户地址;m为小于或等于所述第x个目标脏账户地址集合中的账户地址的总数量的正整数;Traverse the account addresses in the x-th target dirty account address set, and sequentially obtain the m-th account address; m is a positive integer less than or equal to the total number of account addresses in the x-th target dirty account address set; 获取所述第m个账户地址对应的目标现账户状态和目标前账户状态;Obtain the current target account status and the previous target account status corresponding to the m-th account address; 根据所述第m个账户地址的前账户状态对所述第m个账户地址的现账户状态进行账户脏状态数据提交处理;Based on the previous account status of the m-th account address, the current account status of the m-th account address is processed by submitting dirty account status data. 当所述第x个目标脏账户地址集合中每个脏账户地址的现账户状态均进行账户脏状态数据提交处理后,得到第x个提交后的世界状态;After the current account status of each dirty account address in the x-th target dirty account address set is processed by submitting the dirty account status data, the world state after the x-th submission is obtained. 将所述目标脏账户地址添加至第x-1个链上目标脏账户地址集合,得到第x个链上目标脏账户地址集合;x为1时,第x-1个链上目标脏账户地址集合为空集合;The target dirty account address is added to the (x-1)th on-chain target dirty account address set to obtain the xth on-chain target dirty account address set; when x is 1, the (x-1)th on-chain target dirty account address set is an empty set; 当x等于Z时,将第x个链上目标脏账户地址集合作为全链脏账户地址集合,将第x个提交后的世界状态作为提交后的过渡目标第一世界状态。When x equals Z, the set of dirty account addresses of the xth on-chain target is taken as the set of dirty account addresses of the entire chain, and the world state after the xth commit is taken as the first world state of the transition target after the commit. 11.根据权利要求10所述的方法,其特征在于,所述根据所述第m个账户地址的前账户状态对所述第m个账户地址的现账户状态进行账户脏状态数据提交处理,包括:11. The method according to claim 10, characterized in that, the step of performing dirty account status data submission processing on the current account status of the m-th account address based on the previous account status of the m-th account address includes: 对所述第m个账户地址的现账户状态进行账户状态树查询;Perform an account status tree query on the current account status of the m-th account address; 若所述第m个账户地址的现账户状态不包含有账户状态树,或所述第m个账户地址的现账户状态的账户状态根不等于所述第m个账户地址的前账户状态的账户状态根,则根据所述第m个账户地址的现账户状态的树节点缓存和所述第m个账户地址的前账户状态的账户状态根建立指定账户状态树,将所述账户状态树添加至所述第m个账户地址的现账户状态,将第m个账户地址的现账户状态的账户状态根更新为所述第m个账户地址的前账户状态的账户状态根,得到指定账户状态;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 account status root of the previous account status of the m-th account address, then a specified account status tree is established based on the tree node cache of the current account status of the m-th account address and the account status root of the previous account status of the m-th account address. The account status tree is added to the current account status of the m-th account address, and the account status root of the current account status of the m-th account address is updated to the account status root of the previous account status of the m-th account address to obtain the specified account status. 若所述第m个账户地址的现账户状态包含有账户状态树,且所述第m个账户地址的现账户状态的账户状态根等于所述第m个账户地址的前账户状态的账户状态根,则将所述第m个账户地址的现账户状态作为指定账户状态;If the current account status of the m-th account address contains an account status tree, and the account status root of the current account status of the m-th account address is equal to the account status root of the previous account status of the m-th account address, then the current account status of the m-th account address is taken as the specified account status. 若所述指定账户状态的脏状态数据键集合不为空,则从所述指定账户状态的状态数据映射中获取所述指定账户状态的脏状态数据键集合中脏状态数据键对应的状态数据值,将所述指定账户状态的脏状态数据键集合中脏状态数据键和所述指定账户状态的脏状态数据键集合中脏状态数据键对应的状态数据值更新到所述指定账户状态的账户状态树,得到包含更新账户状态树的指定账户状态;If the dirty state data key set of the specified account state is not empty, then obtain the state data value corresponding to the dirty state data key in the dirty state data key set of the specified account state from the state data mapping of the specified account state, update the account state tree of the specified account state with the dirty state data key in the dirty state data key set of the specified account state and the state data value corresponding to the dirty state data key in the dirty state data key set of the specified account state, and obtain the specified account state containing the updated account state tree; 将所述包含更新账户状态树的指定账户状态的账户状态根更新为将所述更新账户状态树的状态树根;Update the account state root containing the specified account state of the updated account state tree to the state tree root of the updated account state tree; 清空所述包含更新账户状态树的指定账户状态的脏状态数据键集合;Clear the dirty state data key set containing the state of the specified account that updates the account state tree; 将所述更新账户状态树的更新树节点哈希和更新树节点的关联关系存储至所述第x个世界状态。Store the hash of the updated tree node and the association relationship of the updated tree node in the xth world state. 12.根据权利要求11所述的方法,其特征在于,还包括:12. The method according to claim 11, characterized in that it further comprises: 对提交后的最新上链世界状态进行全链脏账户状态提交处理,得到干净最新上链世界状态;The latest on-chain world state after submission is processed by submitting the dirty account state of the entire chain to obtain a clean latest on-chain world state. 将所述干净最新上链世界状态中的树节点缓存中的树节点映射包含的树节点哈希和树节点更新到树节点数据库;Update the tree node database with the tree node hash and tree node contained in the tree node cache of the clean latest on-chain world state; 清空所述干净最新上链世界状态中的脏账户地址集合、账户状态映射和树节点缓存中的树节点映射。Clear the set of dirty account addresses, account state mappings, and tree node mappings in the clean, latest on-chain world state. 13.一种基于区块链的数据处理装置,其特征在于,包括:13. A blockchain-based data processing device, characterized in that it comprises: 初始化模块,用于生成初始区块;The initialization module is used to generate the initial block. 状态创建模块,用于创建所述初始区块对应的第一世界状态;所述第一世界状态具有指向所述初始区块的父区块对应的第二世界状态的链式关系;所述第一世界状态和所述第二世界状态存在于世界状态链中;若所述父区块为已上链区块中具有最大区块高度的区块,则所述第二世界状态为共识根世界状态;所述世界状态链中的第一个世界状态为最新上链世界状态;所述共识根世界状态具有指向最新上链世界状态的链式关系;所述最新上链世界状态用于记录所述已上链区块对应的最新世界状态;A state creation module is used to create a first world state corresponding to the initial block; the first world state has a chained relationship pointing to the second world state corresponding to the parent block of the initial block; the first world state and the second world state exist in a world state chain; if the parent block is the block with the highest block height among the already chained blocks, then the second world state is the consensus root world state; the first world state in the world state chain is the latest on-chain world state; the consensus root world state has a chained 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 already chained 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 target first world state. 第二状态更新模块,用于根据所述世界状态链对所述目标第一世界状态进行构建干净状态树处理,得到包含干净现世界状态树的更新目标第一世界状态;The second state update module is used to construct a clean state tree for the target first world state according to the world state chain, so as to obtain an updated target first world state containing the 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 to obtain the block to be added to the chain, and send the block to be added to the chain to the consensus node so that the consensus node performs consensus processing on the block to be added to the chain based on the first world state root to obtain a consensus result. 状态提交模块,用于若所述共识结果为共识通过结果,则将所述待上链区块写入区块链中,通过所述世界状态链将所述更新目标第一世界状态逐级提交至所述最新上链世界状态,将所述更新目标第一世界状态确定为新的共识根世界状态,所述新的共识根世界状态具有指向提交后的最新上链世界状态的链式关系。The state submission module is used to write the block to be added to the blockchain if the consensus result is a consensus pass result, and to submit the target first world state to the latest on-chain world state through the world state chain, and to determine the target first world state as the new consensus root world state. The new consensus root world state has a chain relationship pointing to the latest on-chain world state after submission. 14.一种计算机设备,其特征在于,包括:处理器、存储器以及网络接口;14. A computer device, characterized in that it comprises: a processor, a memory, and a network interface; 所述处理器与所述存储器、所述网络接口相连,其中,所述网络接口用于提供数据通信功能,所述存储器用于存储程序代码,所述处理器用于调用所述程序代码,以执行权利要求1-12任一项所述的方法。The processor is connected to the memory and the network interface, wherein the network interface is used to provide data communication functions, the memory is used to store program code, and the processor is used to call the program code to execute the method according to any one of claims 1-12. 15.一种计算机可读存储介质,其特征在于,所述计算机可读存储介质中存储有计算机程序,所述计算机程序适于由处理器加载并执行权利要求1-12任一项所述的方法。15. A computer-readable storage medium, characterized in that the computer-readable storage medium stores a computer program adapted to be loaded by a processor and to execute the method according to any one of claims 1-12. 16.一种计算机程序产品,包括计算机程序/指令,其特征在于,所述计算机程序/指令被处理器执行时,可以执行权利要求1-12任一项所述的方法。16. A computer program product comprising a computer program/instructions, characterized in that, when the computer program/instructions are executed by a processor, they can perform the method described in any one of claims 1-12.
HK42023081733.0A 2023-10-31 Blockchain-based data processing method, apparatus, device, and readable storage medium HK40092276B (en)

Publications (2)

Publication Number Publication Date
HK40092276A true HK40092276A (en) 2023-12-22
HK40092276B HK40092276B (en) 2025-10-03

Family

ID=

Similar Documents

Publication Publication Date Title
CN109165224B (en) An indexing method for keyword keys on a blockchain database
US11283616B2 (en) Method for index-based and integrity-assured search in a blockchain
US11556516B2 (en) Distributed blockchain data storage under account model
US11526488B2 (en) Distributed blockchain data storage under account model
JP6865851B2 (en) Blockchain World State Markle Patricia Tri Tree Subtree Construction
CN110800255B (en) Updating block chain world state mercker patricia dictionary tree subtree
CN107577427B (en) data migration method, device and storage medium for blockchain system
CN108628942B (en) Block chain node equipment and data reading and writing method of distributed database
US10936559B1 (en) Strongly-consistent secondary index for a distributed data set
TW202046299A (en) Data storage method and node
WO2022242457A1 (en) Transaction verification method and apparatus, device, and storage medium
US12056156B2 (en) Block-chain-based data processing
US12244723B2 (en) System and method to cryptographically validate rich query results
CN107291876A (en) A kind of DDM method
US12348654B2 (en) Blockchain-based methods and apparatuses for processing data, devices and readable storage mediums
CN116542668A (en) Block chain-based data processing method, equipment and readable storage medium
CN110032547A (en) File stores improved method under a kind of distributed environment
CN113656504A (en) A method for submitting, editing and querying blockchain transactions based on time series attributes
CN115114372B (en) Blockchain-based data processing method, device, equipment, and readable storage medium
CN117056342B (en) Data processing method based on block chain and related equipment
HK40092276A (en) Blockchain-based data processing method, apparatus, device, and readable storage medium
HK40092276B (en) Blockchain-based data processing method, apparatus, device, and readable storage medium
CN116680729A (en) Data processing method and device based on intelligent contract and related equipment
CN111488607A (en) Data processing method and device for service data block chain
CN113032408A (en) Data processing method, system and equipment