Block chain node difference synchronization method, electronic equipment and chip system
During the blockchain node synchronization process, multiple blocks to be synchronized are acquired based on the block height difference and processed in parallel, the problem of excessive synchronization time of blockchain nodes is solved, and synchronization efficiency and parallel processing capabilities are improved.
Patent Information
- Application Number
- CN202411450619.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-16
- Publication Date
- 2025-02-28
- Estimated Expiration
- 2044-10-16
AI Technical Summary
During the blockchain node synchronization process, when the full synchronization mode is adopted, the number of blocks between the newly launched node and the current highest block in the blockchain network is quite different, resulting in too long and uncontrollable synchronization time.
By using the blockchain-based block height difference, multiple blocks to be synchronized are obtained and parallel data processing is performed on them in the data processing stage, including executing transactions of multiple blocks to be synchronized in parallel, and updating the world state after each block to be synchronized in parallel.
It improves the parallel processing capabilities of blockchain nodes, shortens the synchronization time, improves synchronization efficiency, and achieves strong ease of use and practicality.
Smart Images

Figure CN119539802A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of blockchain technology, and in particular to a blockchain node difference synchronization method, electronic device and chip system. Background Art
[0002] In the process of data synchronization of blockchain nodes, the full synchronization mode can be used; for example, the open source Ethereum Geth (Go Ethereum) client written in Go language, as a bridge connecting users and the Ethereum network, can support the full synchronization mode.
[0003] However, in the process of synchronizing blockchain nodes using the full synchronization mode, each link is executed serially, and the execution performance is completely dependent on the single-core main frequency; when the number of blocks between the newly started node and the current highest block in the blockchain network is significantly different, the synchronization time is too long and uncontrollable. Summary of the invention
[0004] According to various embodiments of the present application, a blockchain node difference synchronization method, electronic device and chip system are provided, which can improve the system parallel processing capability and improve the synchronization efficiency.
[0005] In a first aspect, the present application provides a blockchain node balance synchronization method; the method comprises:
[0006] Based on the block height of the blockchain, multiple blocks to be synchronized are obtained from at least one peer node; in the data processing stage, parallel data processing is performed on the multiple blocks to be synchronized; the parallel data processing includes parallel execution of transactions of the multiple blocks to be synchronized; in the data update stage, each world state after the execution of each block to be synchronized is updated in parallel according to the data processing result of each block to be synchronized; wherein, one round of data processing stage and data update stage is used to complete the parallel synchronization processing of multiple blocks to be synchronized.
[0007] Through the above method, based on the block height difference, multiple blocks to be synchronized are obtained, and the multiple blocks to be synchronized are synchronized in parallel, without the need to execute a serial synchronization process of executing transactions and updating status for each block data to be synchronized; by executing transactions of multiple blocks to be synchronized in parallel, each block is relatively independent, and the execution of the next block transaction does not need to rely on the execution result of the previous block transaction, thereby realizing multi-core parallel batch processing; according to the data processing result corresponding to each block, the corresponding world state after the execution of each block is updated in parallel, which can improve the parallel processing capability of the node, shorten the synchronization time, and improve the synchronization efficiency; it has strong ease of use and practicality.
[0008] In a possible implementation manner of the first aspect, each block to be synchronized includes a block header and a block body, and the data processing stage includes a block header stage and a block body stage; performing parallel data processing on multiple blocks to be synchronized includes:
[0009] In the block header stage, parallel data processing is performed on multiple block headers to be synchronized; after the block header processing is completed, parallel data processing is performed in the block body stage to obtain the data processing results for each block to be synchronized.
[0010] In a possible implementation of the first aspect, performing parallel data processing on multiple to-be-synchronized block headers includes:
[0011] Verify multiple block headers to be synchronized in parallel, and calculate the reverse mapping of each block header in parallel after verification.
[0012] In a possible implementation of the first aspect, parallel data processing is performed on multiple blocks to be synchronized to obtain a data processing result for each block to be synchronized, including:
[0013] Perform parallel verification on multiple blocks to be synchronized to determine the transaction data of each block, where the transaction data includes the number of transactions and the transaction identifier; execute the transactions of multiple blocks to be synchronized in parallel according to the identifier and the number, and obtain the transaction execution result corresponding to each block to be synchronized; based on the transaction execution result corresponding to each block to be synchronized, calculate the global state after executing each block to be synchronized in parallel, and use the global state as the data processing result of each block to be synchronized.
[0014] In a possible implementation manner of the first aspect, the data update phase includes a hash phase; and according to a data processing result of each block to be synchronized, updating in parallel each world state after executing each block to be synchronized includes:
[0015] In the hashing phase, based on each data processing result, the status data after executing each block to be synchronized in the hash table is updated in parallel; the status data includes the account address and storage location; the world state includes the status data of the hash table.
[0016] In a possible implementation of the first aspect, the update phase also includes a state tree phase; after the hash phase, the method also includes: in the state tree phase, based on the state data of the hash table, the hash value of the root node corresponding to each block to be synchronized is calculated in parallel to obtain the state root hash corresponding to each block to be synchronized.
[0017] In a possible implementation of the first aspect, the update phase also includes calling a tracking index phase; after the state number phase, the method also includes: based on each state root hash, updating the transaction execution process data of multiple blocks to be synchronized in the temporary table in parallel; for multiple blocks to be synchronized, creating a first reverse index of the transaction execution process data of each block to be synchronized in parallel; the first reverse index is used to record and track the transaction execution process data.
[0018] In a possible implementation manner of the first aspect, the update phase also includes: a historical index phase, a log index phase, and a transaction search phase; after calling the tracking index phase, the method also includes: at the historical index node, based on the data of the change set after each block to be synchronized is executed in parallel in the blockchain, the account and stored historical index corresponding to each block to be synchronized are created in parallel; in the log index phase, based on the data of the log table after each block to be synchronized is executed in parallel in the blockchain, a second reverse index of the event log corresponding to each block to be synchronized is created in parallel; in the transaction search phase, for the block bodies of multiple blocks to be synchronized and the transaction data of multiple blocks to be synchronized in the transaction table, a mapping of the transaction data of each block to be synchronized and the transaction hash is created in parallel.
[0019] In a possible implementation of the first aspect, the method further includes: receiving and storing all blocks to be synchronized sent by one or more peer nodes during the execution of the first control flow; based on the data exchange between the first control flow and the second control flow, obtaining a first number of blocks to be synchronized among all blocks to be synchronized during the execution of the second control flow, and performing parallel synchronization processing on the first number of blocks to be synchronized; after completing the synchronization of the first number of blocks to be synchronized, performing parallel synchronization processing on a second number of blocks to be synchronized among all blocks to be synchronized until all blocks to be synchronized are synchronized; the second number is less than or equal to the first number; in the process of performing parallel synchronization of the first number and the second number of blocks to be synchronized, continuing to receive and store all blocks to be synchronized in the next stage sent by one or more peer nodes based on the first control flow.
[0020] In a possible implementation manner of the first aspect, the method further includes: when receiving a synchronization request sent by a lagging node, sending one or more blocks to be synchronized to the lagging node based on the block height difference of the blockchain.
[0021] In a second aspect, the present application provides a blockchain node balance synchronization device, the device comprising:
[0022] A data acquisition unit, configured to acquire a plurality of blocks to be synchronized from at least one peer node based on a block height difference of the blockchain;
[0023] A parallel processing unit, used for performing parallel data processing on the plurality of blocks to be synchronized in the data processing stage; the parallel data processing includes executing transactions of the plurality of blocks to be synchronized in parallel;
[0024] The state update unit is used to update each world state after executing each block to be synchronized in parallel according to the data processing results of each block to be synchronized during the data update phase; wherein the data processing phase and the data update phase of one round are used to complete the parallel synchronization processing of multiple blocks to be synchronized.
[0025] In a third aspect, the present application provides an electronic device, comprising at least one processor and a memory communicatively connected to the at least one processor; wherein the memory stores a computer program executed by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute any one of the methods described in the first aspect.
[0026] In a fourth aspect, the present application provides a chip system, which is applied to an electronic device, and the chip system includes one or more processors, and the one or more processors are used to call computer instructions so that the electronic device executes the method described in the first aspect.
[0027] In a fifth aspect, the present application provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the method described in the first aspect is implemented.
[0028] In a sixth aspect, the present application provides a computer program product. When the computer program product runs on an electronic device, the electronic device executes the method described in the first aspect above.
[0029] It can be understood that the beneficial effects of the second to sixth aspects mentioned above can be found in the relevant description of the first aspect mentioned above, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0031] Figure 1 A schematic diagram of the system architecture of an application scenario provided in an embodiment of the present application;
[0032] Figure 2A flowchart of a blockchain node balance synchronization method provided in an embodiment of the present application;
[0033] Figure 3 A schematic diagram of the overall synchronization process architecture provided for an embodiment of the present application;
[0034] Figure 4 A schematic diagram of a plurality of blocks to be synchronized executing transactions in parallel and updating the world state in parallel provided in an embodiment of the present application;
[0035] Figure 5 A schematic diagram of the structure of a blockchain node balance synchronization device provided in an embodiment of the present application;
[0036] Figure 6 A structural schematic diagram of an electronic device is provided for an embodiment of the present application. DETAILED DESCRIPTION
[0037] The following embodiments of the technical solution of the present application are described in detail in conjunction with the accompanying drawings. The following embodiments are only used to more clearly illustrate the technical solution of the present application, and are therefore only used as examples, and cannot be used to limit the scope of protection of the present application.
[0038] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by technicians in the technical field to which this application belongs; the terms used herein are only for the purpose of describing specific embodiments and are not intended to limit this application; the terms "including" and "having" in the specification and claims of this application and the above-mentioned figure descriptions and any variations thereof are intended to cover non-exclusive inclusions.
[0039] In the description of the embodiments of the present application, the technical terms "first", "second", etc. are only used to distinguish different objects, and cannot be understood as indicating or implying relative importance or implicitly indicating the number, specific order or primary and secondary relationship of the indicated technical features. In the description of the embodiments of the present application, the meaning of "multiple" is more than two, unless otherwise clearly and specifically defined.
[0040] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0041] In the description of the embodiments of the present application, the term "and / or" is only a description of the association relationship of the associated objects, indicating that there may be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.
[0042] In the blockchain network, nodes with lagging block height (such as newly started nodes) synchronize blocks through the client to ensure the consistency of the blockchain network. For example, the block synchronization process of the client software Geth (GoEthereum) of the Ethereum blockchain node adopts the full synchronization mode, which completes the synchronization process by downloading the block header, verifying the block header, and then downloading the complete block, verifying the transaction of the block and updating the world state. The lagging node repeats the above process for each block until it synchronizes to the latest block.
[0043] like Figure 1 As shown, a schematic diagram of the system architecture of the application scenario provided by an embodiment of the present application. A plurality of nodes are included in the blockchain network, such as node 1 to node N (N is an integer greater than 1), and each node maintains a corresponding number of blocks, such as block 1 to block n (n is an integer greater than 3). There are some nodes in the blockchain network whose block height is lower than the current latest block height of the blockchain network, such as the started node 1, whose corresponding block height is 3; the current latest block height of other nodes is n (that is, the current latest block height of the blockchain network is n). The lagging nodes need to synchronize data so that the block height is consistent with the block height of other nodes, thereby ensuring the consistency of the blockchain network.
[0044] Since the block synchronization process in the current relevant technical solutions, including verification of block headers, block transaction verification and updating of the world state, is aimed at the serial synchronization of each block, that is, the above synchronization process is executed for the previous block, and after the synchronization is completed, the above synchronization process is executed for the current block, and then the synchronization of the next block is performed; in this way, the above synchronization process must be executed serially for each block, that is, the synchronization of the next block depends on the synchronization result of the previous block, and the execution performance of the synchronization process is completely dependent on the single-core main frequency performance of the processor; when the number of blocks between the block height of the lagging node and the current latest block height is large, the block synchronization speed will be too slow and the synchronization time will be uncontrollable.
[0045] In view of the problem that the synchronization time is too long and uncontrollable during the data synchronization process of the blockchain, an embodiment of the present application provides a blockchain node difference synchronization method, in which the lagging node splits the synchronization process into stages for the blocks to be synchronized; in the execution process of each stage after the split, multiple Go coroutines are called to process the data of multiple blocks to be synchronized in parallel, giving full play to the performance of the multi-core processor. In each round of synchronization, the data of multiple blocks to be synchronized can be processed in batches in parallel to improve the synchronization speed.
[0046] The specific implementation process of the blockchain node difference synchronization method provided by this application is further introduced below through examples.
[0047] like Figure 2 As shown, the flowchart of the blockchain node balance synchronization method provided by the embodiment of the present application, the execution subject of the method can be Figure 1 The backward node shown in , the method may include the following steps:
[0048] S201, based on the block height difference of the blockchain, obtain multiple blocks to be synchronized from at least one peer node.
[0049] In some embodiments, the lagging node can communicate with other nodes in the blockchain network to obtain the latest block height of the blockchain network. When the lagging node compares the block height and finds a difference with the latest block height, it sends a data request to one or more other peer nodes based on the difference in block height of the blockchain, requesting to obtain the block data of other peer nodes, i.e., the block to be synchronized.
[0050] Exemplarily, based on the block height difference, the lagging node can obtain all the blocks to be synchronized from the peer node, or obtain part of all the blocks to be synchronized based on the processing performance of the lagging node; for example, the latest block height of the blockchain is 2n, and the block height of the lagging node is 1, then the lagging node can obtain the blocks to be synchronized from block 2 to block 2n from the peer node, or first obtain the blocks to be synchronized from block 2 to block n, and then obtain the blocks to be synchronized from block n+1 to block 2n during the next synchronization.
[0051] Among them, after the lagging node obtains the block to be synchronized from the peer node, it can store the block to be synchronized, so as to facilitate the rapid reading of the block to be synchronized in the subsequent data synchronization process, avoid repeated requests to the peer node, and improve data transmission efficiency.
[0052] For example, the blockchain synchronization process may include two parts of control flow, such as Figure 3The first control flow and the second control flow shown. Among them, the first control flow is implemented based on the network communication module of the lagging node, and the second control flow is implemented based on the synchronization execution module of the lagging node. The first control flow is the process of the lagging node obtaining the blocks to be synchronized from one or more peer nodes based on the network communication module. The lagging node sends a data request based on the communication connection interface (or network communication module) with other peer nodes to obtain the blocks to be synchronized, or obtains the blocks to be synchronized (such as new blocks) by receiving the broadcast of the peer node.
[0053] In the blockchain network, nodes will continuously exchange block information to ensure the synchronization and consistency of the entire network. The above network communication module can realize data transmission between lagging nodes and other peer nodes based on the sentinel component; Figure 3 As shown in the figure, the backward node is based on the peer-to-peer network (p2p network via sentry) communication mechanism of the sentinel component, which is driven by the data of the peer node and is responsible for receiving the newly generated block (New Block) and the block headers (Block Headers) and block bodies (Block Bodies) requested from other peer nodes. Among them, the sentinel component is responsible for monitoring, managing or assisting the communication between nodes, ensuring smooth operation and efficient communication between nodes in the blockchain network.
[0054] Among them, the new block can be a block to be synchronized that is broadcasted by the peer node to the lagging node through the P2P network. The lagging node receives the new block by listening to the broadcast message in the network; when the lagging node finds that the block lags behind the latest block height of the blockchain network through block height comparison, it can also actively send a data request to the peer node (the node updated to the latest block height or the node with a block height higher than the lagging node) to obtain the block to be synchronized. Figure 3 As shown, the lagging node sends a data request to the peer node, and can request the data of the block header (Block Headers) and the data of the block body (Block Bodies) respectively.
[0055] Exemplarily, the block header may contain metadata of the block, such as block height, timestamp, hash value of the previous block (i.e., parent block hash), and state root (a summary of hash values of all transactions in the block, such as a Merkle root), etc.; the block body may contain all transaction data in the block, i.e., records of data operations actually occurring on the chain.
[0056] In the first control flow above, for the block header stage and block body stage of the second control flow, after verifying the block header and block body, the backward node can also obtain the verified block header (GetBlock Header) and block body (Get Block Body) based on the peer-to-peer network of the sentinel component, such as Figure 3 As shown by the dotted line in , the sentinel component confirms the successfully verified block headers and block bodies to other nodes in the blockchain network, and saves these verified block headers and block bodies in the blockchain copy to keep the data consistent with other nodes in the blockchain network.
[0057] S202, in the data processing stage, parallel data processing is performed on multiple blocks to be synchronized; the parallel data processing includes executing transactions of multiple blocks to be synchronized in parallel.
[0058] In an embodiment of the present application, when parallel data processing is performed on multiple blocks to be synchronized, transactions in each block to be synchronized are executed in parallel. In the transaction execution process of multiple blocks to be synchronized, the traditional execution process serially executes the height of each block and updates the world state in sequence according to the block height. For example, the transaction of the first block (such as block 3) is executed first, and after the transaction of the first block is executed, the corresponding world state 3 is updated; then based on the execution result of the transaction of the first block (such as block 3), the transaction of the second block (such as block 4) is executed, and then the corresponding world state 4 is updated. Different from the traditional transaction execution process, in an embodiment of the present application, for transactions in multiple blocks to be synchronized, based on the system multi-core processing mechanism, the transactions of multiple blocks to be synchronized are executed in parallel; for example, all transactions in multiple blocks to be synchronized are replayed in parallel; so that when executing transactions of blocks, each block is independent of each other and executed in parallel, thereby improving synchronization efficiency.
[0059] In some embodiments, each block to be synchronized includes a block header and a block body, and the data processing stage includes a block header stage and a block body stage; performing parallel data processing on multiple blocks to be synchronized includes:
[0060] In the block header stage, multiple block headers to be synchronized are processed in parallel, and after the block header processing is completed, in the block body stage, multiple block bodies to be synchronized are processed in parallel to obtain the data processing results for each block to be synchronized.
[0061] In some embodiments, Figure 3 As shown, there is a data exchange mechanism between the first control flow and the second control flow, such as block header exchange (Block Header Exchange) and block body exchange (Block Body Exchange).
[0062] For example, in the header stage of the second control flow, the header data of the block to be synchronized is obtained through the header exchange mechanism. Figure 4As shown in Figure (a) in the header stage, the block headers (such as block header 1 to block header n) of multiple blocks to be synchronized (such as block 1 to block n to be synchronized) are verified in parallel. Figure 3 As shown, after the block header is successfully verified, the verified block header (GetBlock Header) can also be returned to the Sentinel component. Based on the peer-to-peer network of the Sentinel component, the backward node confirms the successfully verified block header to other nodes in the blockchain network and stores it in the copy, thereby realizing the data exchange of the block header.
[0063] Accordingly, in the Bodies Stage of the second control flow, the data of the block body of the block to be synchronized is obtained through the block body exchange mechanism. Figure 4 As shown in Figure (a) in FIG. 1 , in the Bodies Stage, the block bodies (such as block body 1 to block body n) of multiple blocks to be synchronized (such as block body 1 to block body n to be synchronized) are processed in parallel. Figure 3 As shown, after the parallel processing of the block body is completed, the verified block body (GetBlock bodies) can also be returned to the sentinel component. Based on the peer-to-peer network of the sentinel component, the lagging node confirms the successfully verified block body to other nodes in the blockchain network and stores it in the replica, thereby realizing the data exchange of the block body.
[0064] Exemplarily, the process of performing parallel synchronization processing on multiple block headers to be synchronized includes the process of simultaneously verifying the header information of multiple block headers to be synchronized in parallel, and the process of performing parallel synchronization and persistent storage of the header information. The header information of the block header includes the block height, hash value, total difficulty, etc. The process of verifying the header information includes verifying the block height, hash value, and total difficulty; when the header information is stored in parallel, it includes calculating the hash of the header information and persistently storing the hash of the header information.
[0065] Exemplarily, the process of parallel processing of multiple blocks to be synchronized includes obtaining multiple blocks to be synchronized corresponding to the canonical block hash based on the parallel verification results of the block header, performing parallel data processing on the multiple blocks to be synchronized, and persistently storing the actual data of the multiple blocks to be synchronized to the disk. After the verification is passed, the stored information is the transaction height and transaction identifier contained in each block body, the transaction height includes the identifier of the start transaction and the transaction quantity, and the transaction identifier is stored in the RLP code of the transaction.
[0066] Among them, based on the above-mentioned data exchange mechanism, data blocking of the first control flow is avoided. After the first control flow obtains the block data, it stores it, so that the second control flow can continuously extract data from the storage unit of the first control flow as the synchronization is executed, thereby reducing the consumption of infinite memory during the block synchronization process, and reducing the delay caused by repeated requests and data transmission of lagging nodes.
[0067] In some embodiments, parallel data processing is performed on multiple block headers to be synchronized, including: parallel verification of the multiple block headers to be synchronized, and parallel calculation of the reverse mapping of each block header after the verification is passed.
[0068] Exemplarily, the parallel verification process of multiple block headers to be synchronized may include hash value verification, proof of work verification, timestamp verification, and parent block hash verification. Among them, the hash value in the block header (such as the Merkle root hash) is the encrypted summary of all transactions in the block. When verifying the hash value, the node recalculates the Merkle tree of all transactions in the block and compares whether its root hash is consistent with the Merkle root hash in the block header. If consistent, the verification is passed. Proof of work verification is performed by randomly calculating the value of the random number. The timestamp of the block header records the generation time of the block. By checking whether the timestamp in the block header is within a preset reasonable range (such as greater than the timestamp of the previous block and less than the current time plus a certain time threshold), it is verified whether the timestamp in the block header is reasonable. The parent block hash in the block header is a reference to the previous block header. The parent block hash verification is achieved by checking whether the parent block hash of the current block header is consistent with the hash value of the previous block header.
[0069] Exemplarily, the lagging node performs parallel synchronization processing on the block headers of multiple blocks to be synchronized based on the synchronization execution module. The header information of the block header includes the block height, hash value and total difficulty (TD). By calculating the hash of the header information, the calculated hash result is persistently stored.
[0070] For example, after verifying multiple block headers to be synchronized in parallel, the height hash of the block header is calculated, and the detailed data of the block header is stored through the block header table. Each block header is uniquely identified by its height and hash. Among them, the height is used to indicate the position of the block in the blockchain, counting from the genesis block; the hash value of the block header is used to indicate the unique identification of the block header; the height and block header hash are stored through the encoding method of serialized data, such as the recursive length prefix (RLP) encoding method based on the block header information for persistent storage.
[0071] The total difficulty of each block is tracked by persistently storing the RLP encoding of the total difficulty contained in the block header through the block header total difficulty (HeadersTD) table; the total difficulty is the cumulative value of all blockchain difficulties from the genesis block to the current block in the blockchain, which is used to prevent replay attacks and ensure the continuity of blockchain data. Among them, the block height in the HeadersTD table corresponds to the height in the Headers table, indicating the location of the block; the hash in the HeadersTD table corresponds to the hash in the Headers table, indicating the hash of the block header.
[0072] The HeaderCanonical table maintains the canonical path of the blockchain, that is, the longest and heaviest (calculated by total difficulty) chain, by storing the hash of the block height. For example, when a chain forks, the canonical blockchain is determined through this table. Thus, the hash value of the block on the blockchain is standardized at the block height, ensuring the standardization and continuity of the blockchain.
[0073] For example, Figure 3 As shown, the parallel processing of multiple block headers to be synchronized also includes a block hash stage (Block Hashes Stage), which calculates the reverse mapping of the block headers of multiple blocks to be synchronized in parallel and persists the reverse mapping to the database. Compared with the traditional method of calculating a reverse mapping after each execution of a block, the present application calculates the reverse mapping of the block headers of multiple blocks to be synchronized in parallel after the parallel verification of the block headers of multiple blocks to be synchronized, thereby splitting and reorganizing the synchronization process and processing multiple blocks to be synchronized in parallel, thereby improving the synchronization processing efficiency of the blocks.
[0074] Among them, the reverse mapping of the block header is a reverse index mechanism based on the block header to locate the block itself. Each block in the blockchain has a unique hash value, which is obtained by encrypting the content of the block header through a hash algorithm; the reverse mapping corresponds to the mapping relationship between the hash value of the block header and the actual data of the corresponding block header. When it is necessary to find the block header corresponding to a specific hash value, the hash index of the reverse mapping can be used to reversely locate the actual data of the associated block header without traversing the entire blockchain.
[0075] Accordingly, the reverse mapping of the block header is persisted to the database to ensure the reliability and persistence of the data. At the same time, the database can provide efficient data retrieval and query capabilities, supporting rapid positioning and access to block headers and related information.
[0076] After verifying the block header, the header information of the block header is persistently stored based on the above data table, so that the node can quickly verify the new block, ensuring that the new block complies with the specifications and historical records of the blockchain, thereby maintaining the security and stability of the entire network. Compared with the traditional solution, after the entire block synchronization is completed, each data table is persistently stored. After the verification of multiple block headers to be synchronized, the present application can perform parallel persistent storage of the header information of multiple block headers to be synchronized to the above data table, and improve the synchronization efficiency by splitting and reorganizing the synchronization process.
[0077] In some embodiments, parallel data processing is performed on multiple blocks to be synchronized to obtain data processing results for each block to be synchronized, including:
[0078] S2021, perform parallel verification on multiple blocks to be synchronized to determine the transaction data of each block, where the transaction data includes the number of transactions and transaction identifiers.
[0079] For example, Figure 3 As shown, the process of parallel processing of multiple blocks to be synchronized includes the Bodies Stage; in this stage, based on the verification results of multiple block headers to be synchronized, the synchronization execution module of the lagging node can request the block corresponding to the standard block hash from the network communication module. The standard block hash refers to the hash value that conforms to the blockchain hash algorithm format.
[0080] The process of parallel verification of multiple blocks to be synchronized may include transaction signature verification, transaction order and dependency verification, and Merkle tree verification. The lagging node verifies the validity of the signature of each transaction in the block through the public key to verify the transaction signature. In the blockchain network, there may be dependencies between transactions (such as call relationships in smart contracts). By checking whether the dependencies are correctly processed, the transaction order and dependency are verified to ensure the order and logical correctness of the transactions.
[0081] For example, Figure 3 As shown in the figure, after the block body stage, there is also a sender stage (Sender Stage). Since the sender field is not recorded in the block body transaction, this field is the address derived from the private key that signs a transaction, and this address is required in the blockchain node operation logic. Therefore, during the synchronization of blocks, by processing the digital signature of the transaction and restoring the public key, the backward node can calculate the sender of each transaction in the block body, that is, the aforementioned address, and store the address persistently.
[0082] S2022, executing the transactions of multiple blocks to be synchronized in parallel according to the identifiers and quantities, and obtaining the transaction execution results corresponding to each block to be synchronized.
[0083] For example, Figure 4 As shown in Figure (b), each block (such as block 1 to block n) contains multiple transactions. In the block stage, the data of the block is persistently stored, and the stored content includes the transaction height and transaction identifier in each block. The transaction height includes the start transaction identifier and the number of transactions. The transactions in the block include transactions that have occurred in historical blocks or transactions in new blocks.
[0084] like Figure 3 As shown in Figure 2, the block synchronization process also includes the transaction execution stage (Execution Stage); Figure 4 As shown in Figure (b), the lagging node replays the transaction data contained in each block in parallel, that is, all transactions contained in each block are re-executed in order through the blockchain virtual machine, such as verifying transactions, executing transactions, and state transitions. Among them, verifying transactions includes checking the format, signature, account balance, etc. of transactions to ensure that the transactions are valid; executing transactions is to execute the contract code in the transaction in the virtual machine, including transfers, contract calls, etc.; state transition is to update the state of the blockchain according to the transaction execution results, such as account balances, contract status, etc.
[0085] In the embodiment of the present application, the transaction replay is to process the transactions of multiple blocks to be synchronized in parallel, that is, the transactions of block body 1 to block body n are executed in parallel, and the transaction execution results corresponding to each block body (such as transaction execution result 1 to transaction execution result n) are obtained in parallel; it is not necessary to execute the next block after the execution of one block is completed, so the synchronization processing efficiency can be greatly improved.
[0086] S2023, based on the transaction execution results corresponding to each block to be synchronized, parallelly calculate the global state after executing each block to be synchronized, and use the global state as the data processing result of each block to be synchronized.
[0087] For example, Figure 4 As shown in Figure (b), for multiple blocks to be synchronized, after executing all transactions in each block body, the global state (plain state) of the blockchain (i.e., the global state corresponding to each block to be synchronized, such as global state 1 to global state n) is calculated according to the transaction execution results (such as transaction execution results 1 to transaction execution results n). The global state may include account state, contract state, and global parameters, etc. Among them, the account state includes the balance of all accounts, the value of random numbers, contract code, and storage, etc.; the contract state is the internal state of the smart contract, including variable values, storage, etc.; the global parameters include block height, difficulty value, timestamp, etc.
[0088] Accordingly, after calculating the global state, the global state is persisted to the disk as the data processing result for each block to be synchronized; for example, the transaction log (or event log) during the synchronization process is stored in the log table, and the change data record during the synchronization process is stored in the change set.
[0089] S203, in the data update phase, according to the data processing result of each block to be synchronized, each world state after executing each block to be synchronized is updated in parallel.
[0090] In some embodiments, after the lagging node completes block synchronization and parallel calculation of the global state corresponding to each block, Figure 4 As shown in Figure (a), the world state of the blockchain is updated in parallel according to the global state, that is, each world state (such as world state 1 to world state n) corresponding to each block to be synchronized is updated in parallel. The world state stores the current value of all ledger states in the blockchain network, such as account balances, smart contract bytecodes, and smart contract customized data.
[0091] Exemplarily, the lagging node calculates the global state in parallel based on the transaction execution results of each block to be synchronized, and updates its internal world state database accordingly, ensuring that the lagging node is in a completely consistent state after executing transactions in blocks with the same identifier, that is, the updated world state of each node in the blockchain network remains consistent.
[0092] The world state can be tracked by version number. Each time a node updates the world state, the corresponding version number increases synchronously. The world state data is persistently stored in the database to ensure data reliability and recoverability.
[0093] In some embodiments, the data update phase includes a hash phase; according to the data processing result of each block to be synchronized, each world state after executing each block to be synchronized is updated in parallel, including:
[0094] In the hashing stage, based on each data processing result, the status data after executing each block to be synchronized in the hash table is updated in parallel; the status data includes the account address and storage location; and the world state includes the status data of the hash table.
[0095] For example, Figure 3As shown, the second control flow also includes a hash stage, in which the account address and storage location of the new account are determined by reading the new change record in the change set (generated based on the synchronization result), and the account address and storage location are persisted in the hash table. Among them, the account address of the new account is a unique string used to identify the new account in the blockchain network, and the storage location is the specific location of the state data of the account address in the underlying storage structure of the blockchain.
[0096] In some embodiments, the update phase also includes a state tree phase; after the hash phase, the method also includes: in the state tree phase, based on the state data of the hash table, the hash value of the root node corresponding to each block to be synchronized is calculated in parallel to obtain the state root hash corresponding to each block to be synchronized.
[0097] For example, Figure 3 As shown in the figure, after the hash stage, there is also a state tree stage (Trie Stage). In this stage, the state data of the blockchain is stored based on the Merkle tree structure; the lagging node calculates the state root hash according to the state data of the hash table, and builds and updates the storage state of the Merkle tree structure. Among them, the state root hash is the hash value of the root node of the Merkle tree, which represents a snapshot of the complete state of the blockchain at a specific moment; by calculating the state root hash, it is ensured that the lagging node reaches the same world state as other nodes after block synchronization and state update.
[0098] In some embodiments, the update phase also includes a calling tracking index phase; after the state number phase, the method also includes: in the calling tracking index phase, based on each state root hash, updating the transaction execution process data of multiple blocks to be synchronized in the temporary table in parallel; for multiple blocks to be synchronized, creating a first reverse index of the transaction execution process data of each block to be synchronized in parallel; the first reverse index is used to record and track the transaction execution process data.
[0099] For example, Figure 3 As shown, after the state tree stage, the second control flow also includes a call trace index stage. In the call trace index stage, the data in the temporary table of the blockchain network is processed, and based on the execution process of the transaction in each block, the transaction execution process data in the temporary table is updated, and a first reverse index is created; the transaction execution process data in the temporary table is recorded and tracked through the first reverse index, such as tracking contract calls, transaction execution paths, etc.
[0100] Among them, the first reverse index can be a reverse index between the transaction created and the called smart contract for the transaction execution process data in the temporary table, that is, the smart contract called by the transaction and the execution result can be queried through the reverse index; or a reverse index of the contract call chain can be created, that is, the call relationship between smart contracts can be traced through the reverse index to indicate the transaction execution path, etc.
[0101] Accordingly, a mapping relationship is established between the keywords corresponding to the transaction and the smart contract, and the document location information of the keyword, to form a first reverse index; and a mapping relationship between the keyword and the document location information is established to achieve fast retrieval and query.
[0102] In some embodiments, the update phase also includes: a historical index phase, a log index phase, and a transaction search phase; after calling the tracking index phase, the method also includes: in the historical index phase, based on the data of the change set after each of the blocks to be synchronized is executed in parallel in the blockchain, the account and storage historical index corresponding to each of the blocks to be synchronized are created in parallel; in the log index phase, based on the data of the log table after each of the blocks to be synchronized is executed in parallel in the blockchain, a second reverse index of the event log corresponding to each block to be synchronized is created in parallel; in the transaction search phase, for the block bodies of multiple blocks to be synchronized and the transaction data of multiple blocks to be synchronized in the transaction table, a mapping of the transaction data and the transaction hash of each block to be synchronized is created in parallel.
[0103] For example, Figure 3 As shown, after the call tracking index stage, the second control flow also includes a history index stage (History Index Stage); after the history index stage, it also includes a log index stage (Log IndexStage); after the log index stage, it also includes a transaction lookup stage (Tx Lookup Stage).
[0104] Among them, after updating the data in the temporary table, in the historical index stage, the status data in the change set continues to be processed, and corresponding historical indexes are created for the accounts and storage in the change set to record the historical data of the world state; the historical index is used to query the historical values of account balances, contract status or other status variables.
[0105] Accordingly, after creating the historical index, in the log indexing stage, the data in the log table continues to be processed. The data in the log table includes data related to the event log. For the event log, a second reverse index is created; the second reverse index is used to store the mapping relationship between the keywords of the event log and the location information on the disk, and the event information in the event log (such as transfer, contract creation, contract call and other related information) is extracted, and the event information is standardized, and the keywords in the event information are extracted. The keyword is used as the key of the index, and a mapping relationship is established with all the location information (such as log identification ID, timestamp, block height, etc.) where the keyword appears in the event log. The mapping relationship is stored in the form of a reverse index, and the relevant event log can be quickly located through the keyword.
[0106] Exemplarily, after creating a reverse index of the event log, in the transaction lookup stage (Tx LookupStage), the data in the block body and the transaction table are processed, and the lookup mapping of the transaction hash is persisted; this facilitates rapid verification of the existence of the transaction, search for transaction details, etc.
[0107] It should be noted that in the traditional block synchronization process, synchronization is performed in sequence according to the block order. Each execution of a block requires a serial execution of the process of updating the world state. When the number of blocks that differ is large, the synchronization time will be very long. The embodiment of the present application processes multiple blocks to be synchronized in parallel, and then synchronizes the processing results of batch blocks in parallel in one round, and also updates the storage state in parallel. The synchronization processing of multiple blocks to be synchronized is completed in one synchronization execution round, thereby shortening the synchronization time.
[0108] In some embodiments, the method further comprises:
[0109] During the execution of the first control flow, all blocks to be synchronized sent by one or more peer nodes are received and stored; based on the data exchange between the first control flow and the second control flow, during the execution of the second control flow, a first number of blocks to be synchronized among all the blocks to be synchronized are obtained, and parallel synchronization processing is performed on the first number of blocks to be synchronized; after the synchronization of the first number of blocks to be synchronized is completed, parallel synchronization processing is performed on the second number of blocks to be synchronized among all the blocks to be synchronized until all the blocks to be synchronized are synchronized; the second number is less than or equal to the first number; during the parallel synchronization of the first number and the second number of blocks to be synchronized, all blocks to be synchronized in the next stage sent by one or more peer nodes are continuously received and stored based on the first control flow.
[0110] Exemplarily, the network communication module of the lagging node is responsible for data interaction with other peer nodes. The lagging node can obtain the latest block height of the blockchain network, request all blocks to be synchronized based on the difference between the latest block height and its own block height, and store all blocks to be synchronized; the synchronization execution module extracts the block headers and corresponding block bodies of multiple blocks to be synchronized from the network communication module based on the parallel computing capability of the processor during the synchronization execution process, and executes the parallel synchronization process. In the initial round of synchronization, a first number of blocks are extracted from the stored blocks to be synchronized and synchronized; in the second round of synchronization, a second number of blocks are extracted from the stored blocks to be synchronized and synchronized.
[0111] Among them, the second number is less than or equal to the first number, that is, in the process of multiple rounds of synchronization, the number of blocks to be synchronized in each round will become less and less, and finally reach one block to be synchronized, thereby completing the synchronization process of the blockchain.
[0112] In addition, in the second control flow, during the process of synchronizing the blocks to be synchronized through the synchronization execution module, the network communication module can continue to obtain the blocks to be synchronized in the blockchain network, thereby reducing the request delay in the synchronization process; since the synchronization execution module continuously extracts the blocks to be synchronized from the network communication module, memory consumption can be reduced.
[0113] In some embodiments, the method further comprises:
[0114] When a synchronization request is received from a lagging node, one or more blocks to be synchronized are sent to the lagging node based on the block height difference of the blockchain.
[0115] Exemplarily, when there are other backward nodes whose block height is lower than their current block, synchronization requests sent by other backward nodes can also be received, and one or more blocks to be synchronized can be sent to other backward nodes based on the block height of the blockchain.
[0116] Through the embodiments of the present application, the node full synchronization process is split, and the synchronized blocks are processed in parallel batches, releasing the parallel processing capabilities of the server's multi-core processor, and batch processing of the same type of tasks (such as various stages of the synchronization process), thereby optimizing the latency and performance pressure in each stage and greatly improving the synchronization rate.
[0117] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0118] Corresponding to the blockchain node balance synchronization method provided in the above embodiment, Figure 5 As shown, an embodiment of the present application provides a blockchain node difference synchronization device. For the sake of ease of explanation, only the parts related to the embodiment of the present application are shown.
[0119] The device includes:
[0120] A data acquisition unit 51 is used to acquire a plurality of blocks to be synchronized from at least one peer node based on the block height difference of the blockchain;
[0121] The parallel processing unit 52 is used to perform parallel data processing on multiple blocks to be synchronized during the data processing stage; the parallel data processing includes executing transactions of multiple blocks to be synchronized in parallel;
[0122] The state updating unit 53 is used to update each world state after executing each block to be synchronized in parallel according to the data processing result of each block to be synchronized during the data updating stage;
[0123] Among them, a round of data processing phase and data update phase is used to complete the parallel synchronization processing of multiple blocks to be synchronized.
[0124] In a possible implementation, each block to be synchronized includes a block header and a block body, and the data processing stage includes a block header stage and a block body stage; the parallel processing unit 52 is also used to perform parallel data processing on multiple block headers in the block header stage; after the block header processing is completed, in the block body stage, parallel data processing is performed on multiple block bodies to obtain data processing results for each block to be synchronized.
[0125] In a possible implementation, the parallel processing unit 52 is also used to perform parallel verification on multiple block headers, and to calculate the reverse mapping of each block header in parallel after the verification is passed.
[0126] In a possible implementation, the parallel processing unit 52 is also used to perform parallel verification on multiple block bodies, determine the transaction data of each block body, and the transaction data includes the number of transactions and the transaction identification; according to the identification and the number, execute the transactions of multiple block bodies in parallel to obtain the transaction execution results corresponding to each block to be synchronized; based on the transaction execution results corresponding to each block to be synchronized, parallelly calculate the global state after executing each block to be synchronized, and use the global state as the data processing result of each block to be synchronized.
[0127] In one possible implementation, the data update phase includes a hash phase; the state update unit 53 is also used to update the state data of each block to be synchronized in the hash table in parallel based on each data processing result during the hash phase; the state data includes the account address and storage location; and the world state includes the state data of the hash table.
[0128] In one possible implementation, the data update phase also includes a state tree phase; the state update unit 53 is also used to calculate the hash value of the root node corresponding to each block to be synchronized in parallel based on the state data of the hash table in the state tree phase to obtain the state root hash corresponding to each block to be synchronized.
[0129] In a possible implementation, the data update phase also includes a call tracking index phase, and the state update unit 53 is also used to update the transaction execution process data of multiple blocks to be synchronized in the temporary table in parallel based on each state root hash during the call tracking index phase; for multiple blocks to be synchronized, create a first reverse index of the transaction execution process data of each block to be synchronized in parallel; the first reverse index is used to record and track the transaction execution process data.
[0130] In a possible implementation, the data update phase also includes: a historical index phase, a log index phase, and a transaction search phase; the state update unit 53 is also used to create in parallel the account and storage historical index corresponding to each block to be synchronized in the historical index phase based on the data of the change set after each block to be synchronized is executed in parallel in the blockchain; in the log index phase, based on the data of the log table after each block to be synchronized is executed in parallel in the blockchain, create in parallel the second reverse index of the event log corresponding to each block to be synchronized; in the transaction search phase, for the block bodies of multiple blocks to be synchronized and the transaction data of multiple blocks to be synchronized in the transaction table, create in parallel a mapping of the transaction data of each block to be synchronized and the transaction hash.
[0131] In one possible implementation, the data acquisition unit 51 is also used to receive and store all blocks to be synchronized sent by one or more peer nodes during the execution of the first control flow; the parallel processing unit 52 is also used to obtain a first number of blocks to be synchronized among all blocks to be synchronized based on the data exchange between the first control flow and the second control flow during the execution of the second control flow, and perform parallel synchronization processing on the first number of blocks to be synchronized; after the synchronization of the first number of blocks to be synchronized is completed, perform parallel synchronization processing on a second number of blocks to be synchronized among all blocks to be synchronized until all blocks to be synchronized are synchronized; the second number is less than or equal to the first number; the data acquisition unit 51 is also used to continue to receive and store all blocks to be synchronized in the next stage sent by one or more peer nodes based on the first control flow during the parallel synchronization of the first number and the second number of blocks to be synchronized.
[0132] In a possible implementation, the device also includes a data sending unit, which is used to send one or more blocks to be synchronized to the backward node based on the block height difference of the blockchain when receiving a synchronization request sent by the backward node.
[0133] Through the embodiments of the present application, during the synchronization process, the multiple block headers to be synchronized are processed in parallel, and the multiple block bodies to be synchronized are processed in parallel. There is no need to execute a serial synchronization process for each block data to be synchronized each time. By performing parallel batch processing on multiple blocks to be synchronized and then uniformly updating their status, the parallel processing capability of the nodes can be improved, the synchronization time can be shortened, and the synchronization efficiency can be improved.
[0134] Figure 6 A schematic diagram of the hardware structure of the electronic device 6 is shown.
[0135] like Figure 6 As shown, the electronic device 6 of this embodiment includes: at least one processor 60 ( Figure 6 Only one is shown in the figure), a memory 61, in which a computer program 62 that can be run on the processor 60 is stored. When the processor 60 executes the computer program 62, the steps in the above method embodiment are implemented, such as Figure 2 Alternatively, when the processor 60 executes the computer program 62, the functions of the modules / units in the above-mentioned device embodiments are realized.
[0136] It is to be understood that the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the electronic device 6. In other embodiments of the present application, the electronic device 6 may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0137] The electronic device 6 may include, but is not limited to, a processor 60 and a memory 61. Those skilled in the art will appreciate that Figure 6 It is only an example of the electronic device 6 and does not constitute a limitation of the electronic device 6. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the electronic device may also include an input sending device, a network access device, a bus, etc.
[0138] The processor 60 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0139] The processor 60 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 60 is a cache memory. The memory may store instructions or data that the processor 60 has just used or circulated. If the processor 60 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 60, and thus improves the efficiency of the system.
[0140] In some embodiments, the memory 61 may be an internal storage unit of the electronic device 6, such as a hard disk or memory of the electronic device 6. The memory 61 may also be an external storage device of the electronic device 6, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the electronic device 6. Further, the memory 61 may also include both an internal storage unit of the electronic device 6 and an external storage device. The memory 61 is used to store an operating system, an application program, a boot loader (BootLoader), data, and other programs, such as program codes of a computer program, etc. The memory 61 may also be used to temporarily store data that has been sent or is to be sent.
[0141] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0142] It should be noted that the structure of the above-mentioned electronic device is only illustrative, and based on different application scenarios, it may also include other physical structures, and the physical structure of the electronic device is not limited here.
[0143] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0144] An embodiment of the present application also provides a chip system, which is applied to an electronic device. The chip system includes one or more processors, and the one or more processors are used to call computer instructions so that the electronic device implements the steps in the above-mentioned method embodiments.
[0145] An embodiment of the present application further provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments can be implemented.
[0146] An embodiment of the present application provides a computer program product. When the computer program product runs on an electronic device, the electronic device can implement the steps in the above-mentioned method embodiments when executing the computer program product.
[0147] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the process in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. Computer-readable media may include: any entity or device capable of carrying computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium, etc.
[0148] The devices, electronic devices, chip systems, computer storage media, and computer program products provided in the above-mentioned embodiments of the present application are all used to execute the methods provided above. Therefore, the beneficial effects that can be achieved can refer to the corresponding beneficial effects of the methods provided above, and will not be repeated here.
[0149] It should be understood that the above is only to help those skilled in the art to better understand the embodiments of the present application, rather than to limit the scope of the embodiments of the present application. According to the above examples given, those skilled in the art can obviously make various equivalent modifications or changes. For example, some steps in each embodiment of the above detection method may be unnecessary, or some steps may be newly added. Or a combination of any two or any multiple embodiments of the above. Such modifications, changes or combined schemes also fall within the scope of the embodiments of the present application.
[0150] It should also be understood that the division of the methods, situations, categories and embodiments in the embodiments of the present application is only for the convenience of description and should not constitute a special limitation. The features of various methods, categories, situations and embodiments can be combined without contradiction.
[0151] It should also be understood that in the various embodiments of the present application, unless otherwise specified or there is a logical conflict, the terms and / or descriptions between different embodiments are consistent and can be referenced to each other, and the technical features in different embodiments can be combined to form new embodiments according to their internal logical relationships.
[0152] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0153] In the embodiments provided in the present application, it should be understood that the disclosed devices / network equipment and methods can be implemented in other ways. For example, the device / network equipment embodiments described above are merely schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0154] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0155] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
[0156] Finally, it should be noted that the above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A blockchain node balance synchronization method, characterized in that: The method comprises: Based on the block height difference of the blockchain, multiple blocks to be synchronized are obtained from at least one peer node; In the data processing stage, parallel data processing is performed on the plurality of blocks to be synchronized; the parallel data processing includes executing transactions of the plurality of blocks to be synchronized in parallel; In the data update phase, according to the data processing results of each block to be synchronized, each world state after executing each block to be synchronized is updated in parallel; The data processing phase and the data updating phase of one round are used to complete the parallel synchronization processing of multiple blocks to be synchronized.
2. The method according to claim 1, characterized in that Each of the blocks to be synchronized includes a block header and a block body, and the data processing stage includes a block header stage and a block body stage; the parallel data processing of the multiple blocks to be synchronized includes: In the block header stage, parallel data processing is performed on a plurality of the block headers; After the block header processing is completed, in the block body stage, parallel data processing is performed on multiple block bodies to obtain data processing results for each block to be synchronized.
3. The method according to claim 2, characterized in that The performing parallel data processing on the plurality of block headers includes: The plurality of block headers are verified in parallel, and the reverse mapping of each block header is calculated in parallel after the verification is passed.
4. The method according to claim 2, characterized in that: The performing parallel data processing on the plurality of block bodies to obtain a data processing result for each block to be synchronized includes: Performing parallel verification on the plurality of block bodies to determine transaction data of each block body, wherein the transaction data includes the quantity of the transaction and an identifier of the transaction; According to the identifier and the quantity, executing the transactions of the plurality of block bodies in parallel, and obtaining a transaction execution result corresponding to each block to be synchronized; Based on the transaction execution result corresponding to each block to be synchronized, the global state after executing each block to be synchronized is calculated in parallel, and the global state is used as the data processing result of each block to be synchronized.
5. The method according to claim 1, characterized in that The data update phase includes a hash phase; The step of updating each world state after executing each block to be synchronized in parallel according to the data processing result of each block to be synchronized includes: In the hashing stage, based on each of the data processing results, the state data after executing each of the blocks to be synchronized is updated in parallel in the hash table; The state data includes an account address and a storage location; the world state includes the state data of the hash table.
6. The method according to claim 5, characterized in that The data update phase also includes a state tree phase; after the hash phase, the method further includes: In the state tree stage, based on the state data of the hash table, the hash value of the root node corresponding to each of the blocks to be synchronized is calculated in parallel to obtain the state root hash corresponding to each of the blocks to be synchronized.
7. The method according to claim 6, characterized in that The data update phase also includes a call tracking index phase; After the state number stage, the method further comprises: In the call tracking index phase, based on each of the state root hashes, the transaction execution process data of the plurality of blocks to be synchronized in the temporary table are updated in parallel; For the plurality of blocks to be synchronized, a first reverse index of the transaction execution process data of each block to be synchronized is created in parallel; the first reverse index is used to record and track the transaction execution process data.
8. The method according to claim 7, characterized in that The data update phase also includes: a history index phase, a log index phase, and a transaction search phase; after the call tracking index phase, the method further includes: In the historical indexing stage, based on the data of the change set after each block to be synchronized is executed in parallel in the blockchain, the account and storage historical index corresponding to each block to be synchronized are created in parallel; In the log indexing stage, based on the data in the log table after each block to be synchronized is executed in parallel in the blockchain, a second reverse index of the event log corresponding to each block to be synchronized is created in parallel; In the transaction search phase, for the block bodies of multiple blocks to be synchronized and the transaction data of multiple blocks to be synchronized in the transaction table, a mapping between the transaction data of each block to be synchronized and the transaction hash is created in parallel.
9. The method according to any one of claims 1 to 8, characterized in that: The method further comprises: During the execution of the first control flow, all blocks to be synchronized sent by one or more peer nodes are received and stored; Based on the data exchange between the first control flow and the second control flow, during the execution of the second control flow, a first number of blocks to be synchronized among all the blocks to be synchronized are obtained, and parallel synchronization processing is performed on the first number of blocks to be synchronized; after the synchronization of the first number of blocks to be synchronized is completed, parallel synchronization processing is performed on a second number of blocks to be synchronized among all the blocks to be synchronized, until all the blocks to be synchronized are synchronized; the second number is less than or equal to the first number; During the parallel synchronization of the first number and the second number of blocks to be synchronized, all blocks to be synchronized in the next stage sent by one or more opposite nodes are continuously received and stored based on the first control flow.
10. An electronic device, characterized in that: The electronic device includes at least one processor and a memory communicatively connected to the at least one processor; wherein the memory stores a computer program executed by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the method described in any one of claims 1 to 9.
11. A chip system, characterized in that: The chip system is applied to an electronic device, and the chip system includes one or more processors, and the one or more processors are used to call computer instructions so that the electronic device executes the method as described in any one of claims 1 to 9.
12. A computer program product, characterized in that When the computer program product runs on an electronic device, the electronic device is enabled to execute the method according to any one of claims 1 to 9.
Citation Information
Patent Citations
Data processing method and device based on block chain system
CN110008206A
Method for realizing block chain transaction parallelization and block chain node
CN111861744A
Method for synchronizing blocks and joining nodes into block chain network
CN113206893A
Block chain synchronization method and device based on state increment and storage medium
CN118101677A
Block chain total data synchronization method and device, equipment, medium and product
CN118535640A