Data processing method based on two-layer network technology and related device
Patent Information
- Application Number
- CN202410044763.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-11
- Publication Date
- 2025-07-11
Smart Images

Figure CN120297972A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of blockchain technology, and particularly to a data processing method and apparatus, an electronic device, and a computer-readable storage medium based on layer 2 network technology. Background Art
[0002] Layer 2 network technology, also known as Rollups, is a solution for executing transactions outside the underlying blockchain (Ethereum) mainnet. After the transactions are completed, the transaction data is sent back to the mainnet. In other words, Rollups attempts to offload the transaction volume from the blockchain itself and execute transactions on a separate chain, and periodically upload the state and transactions to the mainnet for verification when necessary. Therefore, the underlying blockchain mainnet is also referred to as the first layer network, and the network outside the mainnet is referred to as the second layer network.
[0003] There are mainly two implementation methods for layer 2 network technology: optimistic layer 2 network technology (Optimistic Rollup) and zero-knowledge proof-based layer 2 network technology (ZK Rollup). Optimistic layer 2 network technology relies on a penalty mechanism to ensure security. Once a validator node behaves maliciously, it will pay a great price. Zero-knowledge proof-based layer 2 network technology ensures security through zero-knowledge proof cryptographic algorithms, so it has higher reliability.
[0004] The implementation process of zero-knowledge proof-based layer 2 network technology can be simply understood as follows: after the nodes in the second layer network collect transactions and package them into blocks, they will execute the transactions in the block using the current latest world state to obtain a new world state. This process will use zero-knowledge proof technology to generate a commitment proof, and finally submit the commitment proof to the rollup contract in the first layer network. If the commitment proof verification passes, it can indicate the correctness of the world state update and transaction execution, indicating that the current batch of transactions in the second layer network has been successfully executed.
[0005] In order to ensure data availability, existing zero-knowledge proof-based layer 2 network technology needs to compress transaction data and upload it to the first layer network for subsequent reading and execution by relevant users to construct the latest Merkle state tree, so that users can read the latest state of the account and make independent verification. However, since the transaction data occupies a large amount of storage space in the first layer network, it will consume more storage costs, resulting in low resource utilization efficiency in the first layer network. Summary of the Invention
[0006] To solve the above technical problems, embodiments of the present application provide a data processing method and apparatus, an electronic device, a computer-readable storage medium, and a computer program product based on layer 2 network technology to reduce the computing costs consumed by layer 2 network technology.
[0007] An aspect of an embodiment of the present application provides a data processing method based on a two-layer network technology. This method is executed by an ordering node in the second layer network, and the method includes: constructing a target block according to multiple transactions; executing the multiple transactions and recording the state changes corresponding to each transaction, where the state changes include the resource transfer information of each of the two parties to the transaction; performing a merge process on the state changes corresponding to the multiple transactions to obtain a state difference set, where the state difference set includes the final resource transfer information of each transaction participant; generating proof data corresponding to the execution of the multiple transactions; generating a transaction to be processed according to the block header of the target block, the proof data, and the state difference set, and sending the transaction to be processed to a roll-up contract in the first layer network, so that after the roll-up contract successfully verifies the legality based on the proof data, it records the block header of the target block and the state difference set.
[0008] An aspect of an embodiment of the present application provides a data processing device based on a two-layer network technology. This device is deployed on an ordering node in the second layer network, and the device includes: a block construction module configured to construct a target block according to multiple transactions; a transaction execution module configured to execute the multiple transactions and record the state changes corresponding to each transaction, where the state changes include the resource transfer information of each of the two parties to the transaction; a state change processing module configured to perform a merge process on the state changes corresponding to the multiple transactions to obtain a state difference set, where the state difference set includes the final resource transfer information of each transaction participant; a proof generation module configured to generate proof data corresponding to the execution of the multiple transactions; a transaction reporting module configured to generate a transaction to be processed according to the block header of the target block, the proof data, and the state difference set, and send the transaction to be processed to a roll-up contract in the first layer network, so that after the roll-up contract successfully verifies the legality based on the proof data, it records the block header of the target block and the state difference set.
[0009] Another aspect of the embodiments of the present application also provides another data processing method based on the two-layer network technology. This method is executed by ordinary nodes in the second layer network and includes: obtaining transactions that have been uploaded to the first layer network from the sequencing nodes in the second layer network. The transactions include a block header, proof data, and a set of state differences; based on the block height included in the block header, invoking a rollup contract in the first layer network to obtain the block header recorded by the rollup contract that matches the block height; comparing the block header obtained from the sequencing node with the block header obtained through the rollup contract. If the two are consistent, updating the Merkle state tree according to the set of state differences and calculating a state root based on the updated Merkle state tree; comparing the calculated state root with the new state root included in the block header obtained from the sequencing node. If the two are consistent, using the updated Merkle state tree as the target Merkle state tree.
[0010] One aspect of the embodiments of the present application provides another data processing device based on the two-layer network technology. This device is deployed on ordinary nodes in the second layer network and includes: a first acquisition module configured to obtain transactions that have been uploaded to the first layer network from the sequencing nodes in the second layer network. The transactions include a block header, proof data, and a set of state differences; a second acquisition module configured to, based on the block height included in the block header, invoke a rollup contract in the first layer network to obtain the block header recorded by the rollup contract that matches the block height; a block header processing module configured to compare the block header obtained from the sequencing node with the block header obtained through the rollup contract. If the two are consistent, updating the Merkle state tree according to the set of state differences and calculating a state root based on the updated Merkle state tree; a state root comparison module configured to compare the calculated state root with the new state root included in the block header obtained from the sequencing node. If the two are consistent, using the updated Merkle state tree as the target Merkle state tree.
[0011] Another aspect of the embodiments of the present application provides an electronic device, including: one or more processors; a memory for storing one or more programs. When the one or more programs are executed by the one or more processors, the electronic device is caused to implement the steps in the data processing method based on the two-layer network technology as described above.
[0012] Another aspect of the embodiments of the present application provides a computer-readable storage medium, on which computer-readable instructions are stored. When the computer-readable instructions are executed by a processor of a computer, the computer is caused to execute the steps in the data processing method based on the two-layer network technology as described above.
[0013] Another aspect of the embodiments of the present application provides a computer program product, including a computer program which, when executed by a processor, implements the steps in the data processing method based on the two-layer network technology as described above.
[0014] In the technical solution provided by the embodiments of the present application, during the execution of a transaction by the sequencing node in the second layer network, not only the proof data of the transaction execution is generated, but also the set of state differences caused by the execution process is generated. Finally, the proof data and the set of state differences are uploaded to the first layer network, rather than uploading the transaction data. Thus, to a large extent, the data cost stored in the first layer network is reduced, thereby improving the utilization efficiency of the resources in the first layer network by the second layer network.
[0015] It should be understood that the above general description and the following detailed description are only exemplary and explanatory, and cannot limit the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Figure 1 is a schematic diagram of the network architecture related to the two-layer network technology disclosed in the present application;
[0017] Figure 2 is a schematic diagram of the implementation process of an exemplary two-layer network technology based on zero-knowledge proof;
[0018] Figure 3 is a flowchart of an exemplary data processing method based on the two-layer network technology;
[0019] Figure 4 is a schematic diagram of the state changes involved in an exemplary multiple transactions;
[0020] Figure 5 is a schematic diagram of the process of an exemplary sequencing node executing data processing;
[0021] Figure 6 is a flowchart of the data processing method based on the two-layer network technology shown in another exemplary embodiment of the present application;
[0022] Figure 7 is a schematic diagram of the process of an exemplary ordinary node executing data processing;
[0023] Figure 8 is a block diagram of a data processing device based on the two-layer network technology shown in an exemplary embodiment of the present application;
[0024] Figure 9 is a block diagram of a data processing device based on the two-layer network technology shown in another exemplary embodiment of the present application;
[0025] Figure 10The figure shows a schematic structural diagram of a computer system of an electronic device suitable for implementing the embodiments of the present application. Detailed implementation manners
[0026] Here, exemplary embodiments will be described in detail, and examples thereof are shown in the drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementation manners described in the following exemplary embodiments do not represent all implementation manners consistent with the present application. On the contrary, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0027] The block diagrams shown in the drawings are only functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities can be implemented in software form, or implemented in one or more hardware modules or integrated circuits, or implemented in different networks and / or processor devices and / or microcontroller devices.
[0028] The flowcharts shown in the drawings are only exemplary descriptions and do not necessarily include all contents and operations / steps, nor do they necessarily need to be executed in the described order. For example, some operations / steps can be decomposed, while some operations / steps can be combined or partially combined. Therefore, the actual execution order may change according to the actual situation.
[0029] The term "a plurality of" mentioned in the present application means two or more. The "and / or" describes the association relationship of associated objects and indicates that three relationships can exist. For example, A and / or B can represent: A exists alone, A and B exist simultaneously, and B exists alone. The character " / " generally represents an "or" relationship between the associated objects before and after.
[0030] The terms "first", "second", "third", "fourth", etc. in the specification, claims, and drawings of the present application are used to distinguish different objects, rather than to describe a specific order. The terms "comprise" and "have" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units is not limited to the listed steps or units, but optionally further includes steps or units not listed, or optionally further includes other steps or units inherent to these processes, methods, products, or devices.
[0031] First of all, it should be noted that the embodiments of this application relate to the field of blockchain technology. Blockchain is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, and encryption algorithms. Essentially, blockchain is a decentralized database, a string of data blocks generated by using cryptographic methods. Each data block contains information about a batch of network transactions, which is used to verify the validity of the information and generate the next block. Blockchain can include the blockchain underlying platform, the platform product service layer, and the application service layer.
[0032] The blockchain underlying platform can include processing modules such as user management, basic services, smart contracts, and operation detection. Among them, the user management module is responsible for the identity information management of all blockchain participants, including maintaining the generation of public and private keys, key management, and the correspondence between the real identity of users and blockchain addresses. And under the authorization, it supervises and audits the transaction situations of certain real identities, and provides the rule configuration for risk control; the basic service module is deployed on all blockchain node devices, used to verify the validity of business requests, and records them on the storage after completing the consensus for valid requests. For a new business request, the basic service first performs interface adaptation parsing and authentication processing, then encrypts the business information through the consensus algorithm, and transmits it to the shared ledger completely and consistently after encryption for recording and storage; the smart contract module is responsible for the registration, issuance, triggering, and execution of contracts. Developers can define contract logic through a certain programming language, publish it to the blockchain, and trigger the execution according to the logic of the contract terms by calling keys or other events to complete the contract logic. At the same time, it also provides functions for contract upgrade and cancellation; the operation detection module is mainly responsible for the deployment, configuration modification, contract setting, cloud adaptation during the product release process, and the visual output of the real-time state during product operation, such as: alarming, detecting network conditions, detecting the health status of node devices, etc.
[0033] The platform product service layer provides the basic capabilities and implementation frameworks of typical applications. Developers can build on these basic capabilities and superimpose the characteristics of the business to complete the blockchain implementation of the business logic. The application service layer provides application services based on the blockchain solution for business participants to use.
[0034] The decentralization, security, and transparency promised by blockchain technology have led to huge innovation and growth. However, as these networks expand, the limitations of scalability and efficiency have become increasingly obvious.
[0035] Ethereum is a decentralized platform based on blockchain technology, which can be used to build and deploy smart contracts. It can be understood that a smart contract is a computer program that automatically executes the terms of a contract, which contains the rules and conditions that both parties need to abide by in a transaction. The main goal of Ethereum is to provide a programmable blockchain platform that enables developers to build decentralized applications with various functions. It can be seen that Ethereum, as a platform, uses blockchain technology as its infrastructure. Each block of Ethereum contains a series of transaction data, and these transaction data contain the execution results of smart contracts. Therefore, it can also be said that Ethereum is a blockchain-based smart contract platform.
[0036] The account-based model is adopted in Ethereum, that is to say, the latest status information of each account is recorded in the system. Each account is composed of an address with a specified number of digits, and the status in the corresponding account includes the balance, the number of transactions, and the contract code, etc.
[0037] The Merkle state tree is one of the most important data structures in Ethereum. It stores the status information of all accounts in the entire system and is also called the Merkle prefix tree. The status information of each account includes the account address, balance, and contract code, etc. The state tree is the core of Ethereum, which can help nodes verify the legality of transactions and calculate the execution results of transactions. The transaction tree is a tree-like structure used to store transaction information in Ethereum. By organizing all transaction information into a tree-like structure, it realizes efficient transaction management and verification. The structure of the transaction tree can make the Ethereum network process transactions and the execution of smart contracts more efficiently, thus improving the performance and scalability of Ethereum.
[0038] The nodes of the Merkle state tree include four types: Extension Node, Branch Node, Leaf Node, and Empty Node. Among them, the Extension Node has only one child node, the Branch Node can have multiple nodes, and the Leaf Node has no child nodes. The Value of the Leaf Node stores the content of a data item, so it is used to store the status information of the account. The Value of the Extension Node stores the hash value of the child node. The Value of the Branch Node stores the value just at the end of the branch node. If no node ends at the branch node, the Value does not store data. The root node of the Merkle state tree is also a type of Branch Node, and the stored root hash value is called the state root.
[0039] Each time a new block is released, since the new block contains new transactions, executing the transactions will inevitably change the status of some nodes in the Merkle state tree, but only a small part of the accounts actually change, that is, only the accounts associated with the transactions in the new block will change, while the status of most accounts remains unchanged.
[0040] Due to problems such as throughput limitations and high transaction fees in the original architecture of Ethereum, there are currently two ways to expand Ethereum. The first is to expand at the Ethereum blockchain layer by means of sharding to expand the blockchain itself. The second is to expand at the layer above the Ethereum blockchain, that is, the Layer 2 expansion solution.
[0041] It should be understood that the handling fee mentioned in this application refers to the fact that when a user uses the platform resources provided by Ethereum, Ethereum will charge the user corresponding remuneration according to the user's usage of the platform resources. This remuneration is usually also a virtual resource, thereby realizing the healthy operation of the platform.
[0042] Currently, the main Layer 2 expansion solutions include sidechains, state channels, and rollups. The sidechain solution is an independent blockchain expanded at the layer above the Ethereum blockchain, running in parallel with the Ethereum mainnet and operating independently, but with relatively weak security. The state channel solution allows users to conduct multiple off-chain transactions and only submit two transactions to the Ethereum mainnet, the first when opening the channel and the second when closing the channel. However, it takes a relatively long time to establish a channel, and resources will be locked during the validity period of the channel. The rollup solution is the aforementioned layer 2 network technology that packs (or rolls up) multiple transactions into one transaction on the mainnet. Therefore, this will spread the storage cost of the mainnet to all parties in the entire rollup, improving the resource utilization efficiency of the mainnet and thus reducing the usage handling fee.
[0043] There are mainly two implementation methods for layer 2 network technology, the optimistic layer 2 network technology (Optimistic Rollup) and the zero-knowledge proof-based layer 2 network technology (ZK Rollup). The optimistic layer 2 network technology relies on a penalty mechanism to ensure security. Once a validator node acts maliciously, it will pay a huge price. The zero-knowledge proof-based layer 2 network technology ensures security through zero-knowledge proof cryptographic algorithms, so it has higher reliability.
[0044] It can be understood that in cryptography, zero-knowledge proof is a method for one party (the prover) to prove a certain proposition to another party (the verifier), characterized by not revealing any information except the fact that "the proposition is true" during the process. Therefore, zero-knowledge proof can be understood as "zero-disclosure proof". Zero-knowledge proof algorithms include ZK-SNARKs, ZK-STARKs, etc.
[0045] Since the two-layer network technology based on zero-knowledge proof is more reliable, the mainstream roll-up solution adopts the two-layer network technology based on zero-knowledge proof. The technical solution proposed in the embodiments of this application also relies on the two-layer network technology based on zero-knowledge proof to be implemented. However, it should be understood that with the continuous development of the two-layer network technology, other proof technology solutions similar to or better than the zero-knowledge proof technology may emerge in the future to be combined with the two-layer network technology. This application does not limit the embodiments of this application to be implemented only relying on the two-layer network technology based on zero-knowledge proof technology.
[0046] Please refer to Figure 1 , Figure 1 which is a schematic diagram of the network architecture involved in the two-layer network technology disclosed in this application. As can be seen from Figure 1 , the first-layer network 110 is a blockchain network, including multiple blockchain nodes that communicate with each other. Smart contracts, such as roll-up contracts, are deployed on the blockchain nodes. It can be understood that the roll-up contract is a deposit contract of the second-layer network 120 in the nodes of the first-layer network 110, mainly storing and processing the transactions transmitted by the second-layer network 120. The detailed processing process will be described in the subsequent embodiments and will not be elaborated here.
[0047] The second-layer network 120 is an off-chain network built on top of the first-layer network 110. The "above" mentioned here is understood as the second-layer network 120 is an extension of the second-layer network 110. The second-layer network 120 includes an ordering node 121 and ordinary nodes 122. The ordering node 121 is a special node in the second-layer network 120 that has the function of sorting and packaging transactions. The number is usually 1, but it is not limited to 1. The ordinary node 121 is a node in the second-layer network 120 that has the function of executing business logic, such as synchronizing and verifying status data, reading the latest status of accounts, etc. The number of them is generally multiple. Both the ordering node 121 and the ordinary nodes 122 can communicate with blockchain users, and both the ordering node 121 and the ordinary nodes 122 can also communicate with the nodes in the first-layer network 110. The detailed functions of the two types of nodes can also be seen in the subsequent embodiments.
[0048] It can be understood that the nodes in the first-layer network 110 and the second-layer network 120 can be servers or terminals. The server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers. It can also be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, CDN (Content Delivery Network), security services, and big data and artificial intelligence platforms. The terminal includes, but is not limited to, mobile phones, computers, intelligent voice interaction devices, smart home appliances, vehicle-mounted terminals, aircraft, etc. The terminal and the server can be directly or indirectly connected through wired or wireless communication methods, which are not limited in this application.
[0049] Please refer to Figure 2 , Figure 2 which is a schematic diagram of the implementation process of an exemplary two-layer network technology based on zero-knowledge proof, that is, it shows the working process of the ordering nodes in the two-layer network. As Figure 2 shown, after the ordering node executes and packages multiple transactions, the local Merkle state tree root will be converted from the currently maintained state root to a new state root, and a zero-knowledge proof that proves the validity of the account state transfer is generated. The ordering node submits the currently maintained state root, the new state root, the transaction data, and the zero-knowledge proof to the rollup contract in the first-layer network. If the rollup contract passes the verification of the zero-knowledge proof, it can prove that the Merkle state tree corresponding to the new state root is correctly updated to the Merkle state tree corresponding to the new state root after the transaction is executed, that is, it proves the legality of the transaction and the correctness of the transaction execution. And in this process, there is no need to read the specific content (i.e., the content of the leaf nodes) of the Merkle state tree, thereby reducing the consumption of computing resources on the chain. The reason why the ordering node needs to upload the transaction data to the first-layer network is to ensure data availability, that is, relevant users can use the transaction data and the Merkle state tree corresponding to the new state root to re-execute the transaction and obtain the latest state tree for the user to read the latest state of their account, such as the balance.
[0050] It can be seen that in order to ensure data availability, the ordering node still needs to compress and upload the transaction data to the second-layer network for relevant users to read and execute, in order to construct the latest Merkle state tree so that users can read the latest state of the account and verify independently. However, since the storage space occupied by the transaction data in the first-layer network is relatively large, it will consume more computing costs, resulting in a still low resource utilization efficiency of the first-layer network and a relatively high handling fee for the two-layer network technology.
[0051] Correspondingly, if a user wants to restore the latest Merkel state tree, they still need to read the complete transaction data from the first-layer network, execute all transactions based on the currently maintained Merkel state tree, and update the Merkel state tree. Only in this way can they obtain the latest Merkel state tree. This way of executing full-scale transactions requires high computing resources and results in slow synchronization of state data.
[0052] To solve the above technical problems, the technical solution proposed by the embodiments of this application is that during the process of an ordering node executing a transaction, not only zero-knowledge proofs are generated, but also a set of state differences caused during the transaction execution process is generated. The zero-knowledge proofs and the set of state differences are uploaded to the first-layer network instead of uploading the transaction data. This greatly reduces the data cost stored in the first-layer network. By improving the resource utilization efficiency of the first-layer network, the transaction fees are further reduced. Moreover, when relevant users want to restore the latest Merkel state tree, they can quickly construct the latest Merkel state tree using the set of state differences without having to execute the transactions again, saving the computing power required for synchronizing the state and thus accelerating the speed of state data synchronization.
[0053] The embodiments of this application will be introduced in detail below.
[0054] First, as Figure 3 shown, Figure 3 is a flowchart of an exemplary data processing method based on a two-layer network technology, which is specifically executed by an ordering node in the second-layer network. As Figure 3 shown, the method includes S310 - S350, which are introduced in detail as follows:
[0055] S310, construct a target block based on multiple transactions.
[0056] It can be understood that blockchain users who want to interact with the second-layer network hold a private key and can sign and initiate a transaction to interact with the Dapp (Decentralized Application) contract on the chain. The user constructs and signs the transaction and sends it to the ordering node through the RPC (Remote Procedure Call) interface provided by the ordering node.
[0057] The main content of each transaction is defined as follows:
[0058] Transaction object =(from, to, data, value, nonce, sig)
[0059] where Transaction objectFor a transaction, "from" is the address of the user, "to" is the address of the target Dapp contract or the address of another user, "data" is the encoding of the called function and parameters (if "to" is the address of a user, it is empty), "value" is the quantity of transferred resources (which can be empty), "nonce" is incremented by 1 from the total number of transactions already sent by the user, and can be understood as the transaction sequence number, used to prevent replay attacks, and "sig" is the user's signature.
[0060] The ordering node will receive transactions sent by numerous users and generate a transaction set based on multiple transactions, which can be represented as [Transaction object . In some embodiments, the ordering node also sorts multiple transactions according to a preset sorting rule (such as the order from high to low in terms of transaction fees), and generates a transaction set based on the transaction sequence obtained from the sorting.
[0061] The ordering node needs to construct a target block based on the transaction set. The target block is also the new block. Therefore, it is necessary to obtain the Merkle state tree maintained locally and take out the previous state root, denoted as prestateroot. And it is also necessary to take out the latest block height from the local data and increment it by 1 to obtain the block height of the target block, denoted as blockheight. Finally, generate the target block based on the previous state root, the block height of the target block, and the transaction set (blockheight, prestateroot, [Transaction object ).
[0062] S320, execute these multiple transactions and record the state changes corresponding to each transaction. The state changes include the resource transfer information of both parties to the transaction.
[0063] The ordering node traverses each transaction in the transaction set and executes each traversed transaction. The ordering node also determines the corresponding Merkle state tree based on the world state and the previous state root maintained locally, and after executing each transaction, updates the Merkle state tree according to the state changes corresponding to each transaction. After executing all transactions, that is, after updating the Merkle state tree, calculate the new state root using the updated Merkle state tree, denoted as poststateroot.
[0064] During the transaction execution process, the ordering node also records the state changes involved in each transaction, which are mainly defined as follows:
[0065] Transaction diff =[State diff
[0066] State diff =(Address, diff)
[0067] Among them, Transaction diff represents the status change of each transaction. The specific content includes the user addresses Address of both parties to the transaction and the resource transfer information diff. Please refer to Figure 4 , Figure 4 which exemplifies the status changes involved in exemplary multiple transactions. It can be seen that taking the first transaction as an example, the transaction data is specifically represented as:
[0068] Transaction object =(A, B, empty, 5ETH, nonce, sig)
[0069] Executing this transaction will result in two status changes, that is, the account of user A will decrease by 5 ETH resources, and the account of user B will correspondingly increase by 5 ETH resources, which can be represented as follows:
[0070] Transaction diff =[(A, -5ETH), (B, +5ETH)]
[0071] Similarly, for the second transaction , executing this transaction will still result in two status changes, that is, the account of user B will decrease by 5 ETH resources, and the account of user C will correspondingly increase by 5 ETH resources.
[0072] For the third transaction <C transfer 5 ETH to Uniswap>, executing this transaction will cause the account of user C to decrease by 5 ETH resources, while the account of the Uniswap platform will correspondingly increase by 5 ETH resources.
[0073] For the fourth transaction <D swap 100 USDT for 5 ETH to Uniswap>, this transaction means that user D exchanges 100 USDT resources for 5 ETH resources on the Uniswap platform. Therefore, executing this transaction will cause the account of user D to increase by 5 ETH resources and decrease by 100 USDT resources, while the account of the Uniswap platform will increase by 100 USDT resources and decrease by 5 ETH resources.
[0074] S330. Perform a merging process on the status changes corresponding to multiple transactions to obtain a status difference set, and the status difference set includes the final resource transfer information of each transaction participant.
[0075] After the sequencing node collects the state changes corresponding to all transactions included in the target block, it traverses all the state changes of the same transaction participants, determines the final resource transfer information of the same transaction participants based on all the state changes, and then generates a state difference set based on the final resource transfer information of each transaction participant and the account addresses of each transaction participant.
[0076] Specifically, the sequencing node traverses these state changes and performs merging and cancellation. For example Figure 4 (B, +5ETH) caused by the first transaction shown and (B, -5ETH) caused by the second transaction will cancel each other out. That is, after the merging process, the account of user B will not change, so it will not appear in the final state difference set.
[0077] And the remaining uncanceled State diff Or the State that cannot be fully canceled diff , will be constructed into the final state difference set, which is expressed as follows:
[0078] set = [State diff
[0079] It can be seen that the storage space occupied by uploading the state difference set set to the first-layer network is much smaller than that of uploading all Transactions object to the first-layer network. As Figure 4 shown, the state difference set on the right is obtained by merging the state changes corresponding to multiple transactions on the left, which can greatly reduce the storage cost and thus reduce the usage fee.
[0080] It should also be noted that Figure 4 It can also be seen that the respective resource transfer information of both parties of the transaction corresponding to the state change mentioned in this embodiment can be the resource transfer information corresponding to the user's own account or the platform account. In other words, the participant of each transaction can be either the user account or the platform account, which depends on the actual transaction content initiated by the user.
[0081] S340, generate proof data corresponding to the execution of multiple transactions.
[0082] After the sequencing node finishes executing the transactions included in the target block, it will use relevant proof technologies to generate a proof file for verifying the correctness of transaction execution and state transition. It should be noted that the mainstream proof technology at this stage is the zero-knowledge proof technology, such as ZK-SNARKs technology or ZK-STARKs technology. However, with the development of technology, new proof technologies that can prove the correctness of transaction execution and state transition may also emerge in the future. Therefore, this embodiment is not limited to using zero-knowledge proof to generate zero-knowledge proof files.
[0083] Exemplarily, by splicing the previous state root, the new state root, and the transaction set, a sequence to be processed can be obtained. Then, using a preset proof algorithm, proof data is generated based on the sequence to be processed. Taking the generation of a zero-knowledge proof proof as an example, its generation process can be expressed as follows:
[0084] proof = ZK_SNARKS(prestateroot,poststateroot,[Transaction object )
[0085] S350, Generate a transaction to be processed based on the block header, proof data, and state difference set of the target block, and send the transaction to be processed to the rollup contract in the first-layer network. After the rollup contract successfully verifies the legality based on the proof data, record the block header and state difference set of the target block.
[0086] After executing the above steps, the sequencing node constructs the block header block_header of the target block according to the block height, previous state root, and new state root of the target block, which is expressed as follows:
[0087] block_header = [blockheight, prestateroot, post state root]
[0088] The sequencing node constructs a transaction with the block header block_header, state difference set set, and proof data proof of the target block as parameters to obtain a transaction to be processed, and calls the relevant functions in the rollup contract in the first-layer network to send the transaction to be processed to the nodes in the first-layer network.
[0089] It can be understood that the roll-up contract is a deposit contract of the second-layer network in the nodes of the first-layer network. It will use corresponding proof technologies, such as zero-knowledge proof technology, to extract the pre-state root prestateroot, new state root post state root, and proof data proof from the transaction to be processed as the input for proof verification, and verify the legality of the proof data proof. If the verification passes, it means that the state transition from the pre-state root prestateroot to the new state root post state root is legal, that is, the target block is legal. Furthermore, the block header of the target block is used as the latest block header of the second-layer network and stored on the chain. The state difference set set, as part of the transaction, will also be stored on the chain to achieve data availability, so that relevant users can retrieve the state difference set and use it to restore and calculate the latest Merkle state tree in the second-layer network. For the specific content, please refer to the description in the subsequent embodiments and will not be elaborated here.
[0090] The process of the sequencer node performing data processing as described above can also be referred to Figure 5 in the Figure 5 shown process. It should be noted that
[0091] Please continue to refer to Figure 6 in Figure 6 which is a flowchart of a data processing method based on the two-layer network technology shown in another exemplary embodiment of the present application. This method is specifically executed by ordinary nodes in the second-layer network.
[0092] This method includes S610-S640, which are introduced in detail as follows:
[0093] S610, obtain the transactions uploaded to the first-layer network from the sequencer nodes in the second-layer network. The transactions include block headers, proof data, and state difference sets.
[0094] When a user wants to read the latest status of their account, such as the balance, they need to obtain the latest status tree in the second-layer network. A normal node in the second-layer network can be synchronously deployed and connected to the sequencer node to synchronize and verify the status data, ensuring that a correct Merkle status tree can be obtained to read the latest status of the account that the user is concerned about. Therefore, the normal node can obtain the transactions uploaded from the second-layer network to the first-layer network from the sequencer node. As described in the foregoing embodiments, the transactions obtained by the normal node include the block header block_header, proof data proof, and status difference set set. The block header contains the block height blockheight, the previous state root prestateroot, and the new state root post state root.
[0095] And it can be understood that the transaction uploaded from the second-layer network to the first-layer network mentioned in this embodiment essentially corresponds to a block. Therefore, this block can also be referred to as the current block, and the current block is usually the latest block maintained locally.
[0096] S620, based on the block height included in the block header, call the rollup contract in the first-layer network to obtain the block header recorded by the rollup contract that matches the block height.
[0097] Similarly, as previously recorded, the sequencer node will send the relevant information in the second-layer network to the first-layer network as a transaction and store it in the blockchain ledger of the blockchain node, while the block header is stored in the rollup contract as part of the world state of the first-layer network. Therefore, the normal node in the second-layer network can also obtain the transactions related to the rollup contract and extract the status difference set and the block header from the obtained transactions.
[0098] Thus, for the block header obtained from the sequencer node, the normal node extracts the block height from the block header and calls the rollup contract to extract the corresponding block header information, that is, to obtain the block header recorded by the rollup contract that is equal to this block height.
[0099] S630, compare the block header obtained from the sequencer node with the block header obtained through the rollup contract. If the two are consistent, update the Merkle status tree according to the status difference set and calculate the state root based on the updated Merkle status tree.
[0100] The normal node confirms whether they are consistent by comparing the two block headers. If they are consistent, it means the verification passes; otherwise, it means there is malicious behavior resulting in an error in the Merkle status tree.
[0101] After passing the verification, ordinary nodes will update the Merkle state tree according to the set of state differences included in the current block. The update of the Merkle state tree is actually an update of its leaf nodes. Traverse the final resource transfer information and account addresses of each transaction party in the set of state differences, find the corresponding leaf nodes in the Merkle state tree according to the account addresses, and apply the final resource transfer information to the balances of the leaf nodes, thereby updating the data of the leaf nodes. Until all the final resource transfer information of all transaction parties in the state difference combination is applied, that is, after all leaf nodes are updated, it means that the Merkle state tree update is completed, and the updated Merkle state tree is obtained. Using the updated Merkle state tree, calculate a new state root, denoted as state root.
[0102] S640, compare the calculated state root with the new state root contained in the block header obtained from the sequencer node. If the two are the same, use the updated Merkle state tree as the target Merkle state tree.
[0103] Compare the state root state root calculated based on the updated Merkle state tree with the new state root post state root contained in the block header obtained from the sequencer node. If the two are the same, it means that the state changes involved in the current block have been successfully updated to the Merkle state tree. Therefore, the updated Merkle state tree is used as the target Merkle state tree, and the latest state of the user's account can be determined accordingly. If the two are not the same, it means that there is malicious behavior resulting in an error in the Merkle state tree, so the processing is terminated.
[0104] The process illustrated above can also be expressed as Figure 7 As shown, when the user submits a request to obtain the latest Merkle state tree, ordinary nodes perform the above processing to obtain the target Merkle state tree. It can be seen that in the solution provided in this embodiment, when updating the Merkle state tree, ordinary nodes do not need to re-execute the transactions in the block, but only apply the set of state differences to the leaf nodes of the corresponding Merkle state tree. This update process saves the calculations required to execute the transactions, thereby accelerating the speed of state data synchronization.
[0105] It should be noted that generally, the request submitted by the user is to obtain the latest Merkel state tree corresponding to the latest block. The update of the Merkel state tree is continuously updated as the block height increases. The latest Merkel state tree corresponding to the latest block is obtained by updating the latest Merkel state tree corresponding to the previous block based on the state difference set corresponding to the latest block. Considering that sudden situations such as interruptions may occur in the Merkel state tree, in order to ensure the accurate update of the Merkel state tree, in another embodiment of the present application, the data processing method based on the two-layer network technology applied to ordinary nodes further includes the following steps:
[0106] S631, determine whether the previous block of the block where the transaction is located has executed the process of updating the Merkel state tree based on the corresponding state difference set;
[0107] S632, if yes, directly update the Merkel state tree updated by the previous block according to the state difference set corresponding to the current transaction;
[0108] S633, if no, start from the genesis block, update the Merkel state tree updated by the previous block according to the state difference set corresponding to each block until the Merkel state tree updated by the block where the transaction is located is obtained.
[0109] Specifically, in the process of updating the Merkel state tree by the ordinary node according to the state difference set, it is necessary to first determine whether the previous block of the block where the current transaction is located (i.e., the current block) has executed the process of updating the Merkel state tree based on the corresponding state difference set. If yes, the Merkel state tree updated by the previous block is updated according to the state difference set corresponding to the current transaction to obtain the updated Merkel state tree. If no, it is necessary to start from the genesis block and update the Merkel state tree updated by the previous block according to the state difference set corresponding to each block until the Merkel state tree updated by the block where the current transaction is located is obtained.
[0110] Thus, it can be ensured that the latest Merkel state tree synchronized by the ordinary node each time it responds to the user's request, that is, the target Merkel state tree, is accurate, and then the latest state of the user's account is determined accordingly based on the target Merkel state tree. Since this process does not need to re-execute the transactions in the block, but only applies the state difference set to the leaf nodes of the corresponding Merkel state tree, it speeds up the synchronization speed of the state data and at the same time ensures the accuracy. Therefore, it can greatly improve the user's experience in using the two-layer network technology, and thus greatly promote the application and development of the two-layer network technology.
[0111] Please refer to Figure 8 , Figure 8It is a block diagram of a data processing device based on layer - two network technology shown in an exemplary embodiment of the present application. The exemplary data processing device 800 based on layer - two network technology can be configured on an ordering node in the second - layer network. The data processing device 800 based on layer - two network technology includes:
[0112] A block building module 810, configured to build a target block according to multiple transactions;
[0113] A transaction execution module 820, configured to execute multiple transactions and record the state changes corresponding to each transaction, where the state changes include the resource transfer information of both parties to the transaction;
[0114] A state change processing module 830, configured to perform a merging process on the state changes corresponding to multiple transactions to obtain a state difference set, where the state difference set includes the final resource transfer information of each transaction participant;
[0115] A proof generation module 840, configured to generate proof data corresponding to the execution of multiple transactions;
[0116] A transaction reporting module 850, configured to generate a transaction to be processed according to the block header of the target block, the proof data, and the state difference set, and send the transaction to be processed to a folded contract in the first - layer network. After the folded contract successfully verifies the legality based on the proof data, it records the block header of the target block and the state difference set.
[0117] In another exemplary embodiment, the block building module 810 is further configured to:
[0118] Generate a transaction set according to multiple transactions;
[0119] Obtain the Merkle state tree maintained locally, and determine the previous state root based on the Merkle state data;
[0120] Obtain the latest block height, and add one to the latest block height to obtain the block height of the target block;
[0121] Generate a target block based on the previous state root, the block height of the target block, and the transaction set.
[0122] In another exemplary embodiment, the block building module 810 is further configured to: sort multiple transactions according to a preset sorting rule, and generate a transaction set based on the sorted transaction sequence.
[0123] In another exemplary embodiment, the transaction execution module 820 is further configured to:
[0124] Traverse each transaction in the transaction set and execute each traversed transaction;
[0125] Determine the corresponding Merkel state tree according to the previous state root, and after multiple transactions are executed, update the Merkel state tree according to the state changes corresponding to each transaction, and calculate a new state root based on the updated Merkel state tree.
[0126] In another exemplary embodiment, the proof generation module 840 is further configured to:
[0127] Concatenate the previous state root, the new state root, and the transaction set to obtain a sequence to be processed;
[0128] Use a preset proof algorithm to generate proof data based on the sequence to be processed.
[0129] In another exemplary embodiment, the device further includes a block header generation module configured to generate a block header of the target block according to the block height, the previous state root, and the new state root of the target block.
[0130] In another exemplary embodiment, the state change corresponding to each transaction further includes the account addresses of both parties to the transaction; the state change processing module 830 is further configured to:
[0131] Traverse all state changes of the same transaction participant and determine the final resource transfer information of the same transaction participant based on all state changes;
[0132] Generate a state difference set based on the final resource transfer information of each transaction participant and the account addresses of each transaction participant.
[0133] It should be noted that the data processing device based on the two-layer network technology provided in this embodiment and Figure 3 the data processing method based on the two-layer network technology provided in the illustrated embodiment belong to the same concept. The specific manners in which each module and unit perform operations have been described in detail in the method embodiment and will not be elaborated here. The data processing device based on the two-layer network technology provided in this embodiment can, in practical applications, allocate the above functions to different functional modules as needed, that is, divide the internal structure of the device into different functional modules to complete all or part of the functions described above, and this will not be limited here either.
[0134] In the data processing device based on the two-layer network technology proposed in this embodiment, after the state difference set cancels out the state changes due to merging, the storage space it occupies is much smaller than the original transaction data, and as the number of transactions in a block increases, the more state changes are offset, and this advantage will become more obvious. Therefore, this embodiment can greatly reduce the storage cost of the second layer network in the first layer network, and thus reduce the handling fee for the second layer network to process transactions.
[0135] Please refer to Figure 9, Figure 9 FIG. Figure 9 is a block diagram of a data processing apparatus based on a two - layer network technology shown in another exemplary embodiment of the present application. The exemplary data processing apparatus 900 based on the two - layer network technology can be configured on a common node in the second - layer network. The exemplary data processing apparatus 900 based on the two - layer network technology includes:
[0136] A first acquisition module 910, configured to acquire transactions uploaded to the first - layer network from an ordering node in the second - layer network, where the transactions include a block header, proof data, and a set of state differences;
[0137] A second acquisition module 920, configured to call a roll - up contract in the first - layer network based on the block height included in the block header to acquire a block header recorded by the roll - up contract that matches the block height;
[0138] A block - header processing module 930, configured to compare the block header acquired from the ordering node with the block header acquired through the roll - up contract. If the two are the same, update the Merkle state tree according to the set of state differences, and calculate a state root based on the updated Merkle state tree;
[0139] A state - root comparison module 940, configured to compare the calculated state root with the new state root included in the block header acquired from the ordering node. If the two are the same, use the updated Merkle state tree as the target Merkle state tree.
[0140] In another exemplary embodiment, the block - header processing module 930 is further configured to:
[0141] Determine whether the previous block of the block where the transaction is located has executed the process of updating the Merkle state tree based on the corresponding set of state differences;
[0142] If so, directly update the Merkle state tree updated for the previous block according to the set of state differences corresponding to the transaction;
[0143] If not, starting from the genesis block, update the Merkle state tree updated for the previous block according to the set of state differences corresponding to each block until the Merkle state tree updated for the block where the transaction is located is obtained.
[0144] In another exemplary embodiment, the block - header processing module 930 is further configured to:
[0145] Traverse the final resource transfer information and account addresses of each transaction participant in the set of state differences;
[0146] Determine the leaf node corresponding to the account address in the Merkel state tree, and apply the final resource transfer information to the leaf node until the application processing of the final resource transfer information of all transaction parties in the state difference set is completed.
[0147] It should also be noted that the data processing device based on the two-layer network technology provided in this embodiment and Figure 6 the data processing method based on the two-layer network technology provided in the illustrated embodiment belong to the same concept. The specific manners in which each module and unit perform operations have been described in detail in the method embodiment, and will not be elaborated here.
[0148] In the data processing device based on the two-layer network technology provided in this embodiment, when updating the Merkel state tree, ordinary nodes do not need to re-execute the transactions in the block, but only apply the state difference set to the leaf nodes of the corresponding Merkel state tree. This update process saves the calculations required for executing transactions, thereby accelerating the speed of state data synchronization.
[0149] An embodiment of the present application also provides an electronic device, including: one or more processors; a memory for storing one or more programs, which when executed by the one or more processors, cause the electronic device to implement the data processing method based on the two-layer network technology provided in the above respective embodiments.
[0150] Figure 10 The structural diagram of a computer system of an electronic device suitable for implementing the embodiments of the present application is shown. It should be noted that Figure 10 the computer system 1000 of the shown electronic device is only an example, and should not impose any limitation on the functions and usage scope of the embodiments of the present application.
[0151] As Figure 10 shown, the computer system 1000 includes a central processing unit (CPU) 1001, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 1002 or the program loaded from the storage section 1008 into the random access memory (RAM) 1003, such as executing the method described in the above embodiments. In the RAM 1003, various programs and data required for system operation are also stored. The CPU 1001, ROM 1002, and RAM 1003 are connected to each other through a bus 1004. The input / output (I / O) interface 1005 is also connected to the bus 1004.
[0152] The following components are connected to the I / O interface 1005: an input section 1006 including a keyboard, a mouse, etc.; an output section 1007 including, for example, a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 1008 including a hard disk, etc.; and a communication section 1009 including a network interface card such as a LAN (Local Area Network) card, a modem, etc. The communication section 1009 performs communication processing via a network such as the Internet. A drive 1010 is also connected to the I / O interface 1005 as needed. A removable medium 1011, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is mounted on the drive 1010 as needed so that a computer program read therefrom can be installed into the storage section 1008 as needed.
[0153] Specifically, according to an embodiment of the present application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, an embodiment of the present application includes a computer program product that includes a computer program carried on a computer-readable medium, and the computer program includes a computer program for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through the communication section 1009, and / or installed from the removable medium 1011. When the computer program is executed by a central processing unit (CPU) 1001, various functions defined in the system of the present application are executed.
[0154] It should be noted that the computer-readable medium shown in the embodiments of the present application may be a computer-readable signal medium, a computer-readable storage medium, or any combination of the two. More specific examples of the computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. The computer program included on the computer-readable medium can be transmitted using any appropriate medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0155] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments of the present application. Among them, each block in the flowchart or block diagram may represent a module, a program segment, or a part of code, and the above-mentioned module, program segment, or part of code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order from that marked in the accompanying drawings. For example, two consecutively represented blocks may actually be executed substantially in parallel, and they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram or flowchart, as well as the combination of blocks in the block diagram or flowchart, may be implemented by a dedicated hardware-based system for performing the specified functions or operations, or may be implemented by a combination of dedicated hardware and computer instructions.
[0156] The units involved in the embodiments described in the present application can be implemented in software or in hardware, and the described units can also be provided in a processor. Among them, the names of these units do not, in some cases, constitute a limitation on the unit itself.
[0157] Another aspect of the present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, it implements the data processing method based on the two-layer network technology as described above. The computer-readable storage medium may be included in the electronic device described in the above embodiments, or may exist separately and not be assembled into the electronic device.
[0158] Another aspect of the present application also provides a computer program product or a computer program. The computer program product or the computer program includes computer instructions, and the computer instructions are stored in a computer-readable storage medium. The processor of the computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the data processing method based on the two-layer network technology provided in the above various embodiments.
[0159] The above content is only a preferred exemplary embodiment of the present application and is not used to limit the implementation of the present application. Those of ordinary skill in the art can easily make corresponding adaptations or modifications according to the main concept and spirit of the present application. Therefore, the protection scope of the present application should be subject to the protection scope required by the claims.
[0160] It is understandable that in the specific embodiments of the present application, data related to transactions, blocks, etc. are involved. When the above embodiments of the present application are applied to specific products or technologies, user permission or consent needs to be obtained, and the collection, use, and processing of relevant data need to comply with relevant laws, regulations, and standards of relevant countries and regions.
Claims
1. A data processing method based on two-layer network technology, characterized in that Applied to the sequencing node in the second-layer network, the method includes: Construct a target block based on multiple transactions; Execute the multiple transactions and record the status changes corresponding to each transaction, where the status changes include the resource transfer information of each of the two parties to the transaction; Perform a merging process on the status changes corresponding to the multiple transactions to obtain a status difference set, where the status difference set includes the final resource transfer information of each transaction participant; Generate proof data corresponding to the execution of the multiple transactions; Generate a pending transaction based on the block header of the target block, the proof data, and the status difference set, and send the pending transaction to the roll-up contract in the first-layer network. After the roll-up contract successfully verifies the legality based on the proof data, record the block header of the target block and the status difference set.
2. The method according to claim 1, characterized in that The constructing the target block based on multiple transactions includes: Generate a transaction set based on the multiple transactions; Obtain the locally maintained Merkle state tree, and determine the previous state root based on the Merkle state data; Obtain the latest block height, and add one to the latest block height to obtain the block height of the target block; Generate the target block based on the previous state root, the block height of the target block, and the transaction set.
3. The method according to claim 2, characterized in that, The generating the transaction set based on the multiple transactions includes: Sort the multiple transactions according to a preset sorting rule, and generate the transaction set based on the sorted transaction sequence.
4. The method according to claim 2, wherein The executing the multiple transactions includes: Traverse each transaction in the transaction set and execute each traversed transaction; Determine the corresponding Merkle state tree based on the previous state root, and after executing the multiple transactions, update the Merkle state tree according to the status change corresponding to each transaction, and calculate a new state root based on the updated Merkle state tree.
5. The method according to claim 4, characterized in that The generating the proof data corresponding to the execution of the multiple transactions includes: Concatenate the previous state root, the new state root, and the transaction set to obtain a pending sequence; Generate the proof data based on the pending sequence using a preset proof algorithm.
6. The method according to claim 4, characterized in that, The method further includes: Generate the block header of the target block based on the block height of the target block, the previous state root, and the new state root.
7. The method according to any one of claims 1-6, characterized in that, The status change corresponding to each transaction further includes the account addresses of the two parties to the transaction respectively; the performing a merging process on the status changes corresponding to the multiple transactions to obtain a status difference set includes: Traverse all the status changes of the same transaction participant, and determine the final resource transfer information of the same transaction participant based on all the status changes; Generate the status difference set based on the final resource transfer information of each transaction participant and the account addresses of each transaction participant.
8. A data processing method based on two-layer network technology, characterized in that, Applied to a common node in the second-layer network, the method includes: Obtain the transactions that have been uploaded to the first-layer network from the sequencing nodes in the second-layer network, where the transactions include a block header, proof data, and a status difference set; Based on the block height included in the block header, call the rollup contract in the first-layer network to obtain the block header recorded by the rollup contract that matches the block height; Compare the block header obtained from the sequencer node with the block header obtained through the rollup contract. If the two are consistent, update the Merkle state tree according to the state difference set, and calculate the state root based on the updated Merkle state tree; Compare the calculated state root with the new state root contained in the block header obtained from the sequencer node. If the two are consistent, use the updated Merkle state tree as the target Merkle state tree.
9. The method according to claim 8, wherein The updating the Merkle state tree according to the state difference set includes: Determine whether the previous block of the block where the transaction is located has executed the process of updating the Merkle state tree based on the corresponding state difference set; If so, directly update the Merkle state tree updated by the previous block according to the state difference set corresponding to the transaction; If not, starting from the genesis block, update the Merkle state tree updated by the previous block according to the state difference set corresponding to each block until the Merkle state tree updated by the block where the transaction is located is obtained.
10. The method according to claim 8 or 9, characterized in that, The updating the Merkle state tree according to the state difference set includes: Traverse the final resource transfer information and account addresses of each transaction participant in the state difference set; Determine the leaf node corresponding to the account address in the Merkle state tree, and apply the final resource transfer information to the leaf node until the application process of the final resource transfer information of all transaction participants in the state difference set is completed.
11. A data processing device based on two-layer network technology, characterized in that, Configured on a sequencer node in the second-layer network, the device includes: A block construction module configured to construct a target block according to multiple transactions; A transaction execution module configured to execute the multiple transactions and record the state changes corresponding to each transaction, where the state changes include the respective resource transfer information of the two parties to the transaction; A state change processing module configured to perform a merging process on the state changes corresponding to the multiple transactions to obtain a state difference set, where the state difference set includes the final resource transfer information of each transaction participant; A proof generation module configured to generate proof data corresponding to the execution of the multiple transactions; A transaction reporting module configured to generate a pending transaction according to the block header of the target block, the proof data, and the state difference set, and send the pending transaction to the rollup contract in the first-layer network, so that after the rollup contract successfully performs a legality verification based on the proof data, record the block header of the target block and the state difference set.
12. A data processing device based on layer 2 network technology, characterized in that, Configured on an ordinary node in the second-layer network, the device includes: A first acquisition module configured to acquire the transactions that have been uploaded to the first-layer network from the sequencer nodes in the second-layer network, where the transactions include a block header, proof data, and a state difference set; A second acquisition module, configured to call a rolling contract in the first-layer network based on the block height included in the block header to acquire the block header recorded by the rolling contract that matches the block height; A block header processing module, configured to compare the block header obtained from the sequencer node with the block header obtained through the rolling contract. If the two are consistent, update the Merkle state tree according to the state difference set, and calculate a state root based on the updated Merkle state tree; A state root comparison module, configured to compare the calculated state root with the new state root included in the block header obtained from the sequencer node. If the two are consistent, use the updated Merkle state tree as the target Merkle state tree.
13. An electronic device, characterized in that, Comprising: One or more processors; A memory for storing one or more programs, which when executed by the one or more processors cause the electronic device to implement the method according to any one of claims 1-7 or 8-10.
14. A computer-readable storage medium, characterized in that, Computer-readable instructions are stored thereon, which when executed by a processor of a computer cause the computer to execute the method according to any one of claims 1-7 or 8-10.