Block information updating method, device, computer equipment and storage medium
By constructing a Merkle tree and updating status data according to block height, the problem of low processing efficiency in the existing blockchain system is solved, and more efficient status data processing and storage are achieved.
Patent Information
- Application Number
- CN202010221292.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-03-26
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2040-03-26
AI Technical Summary
The existing blockchain system based on Merkle Patricia Tree has low processing efficiency when processing block information updates, resulting in poor system performance.
By obtaining and updating the status data of the account, a Merkel tree is constructed, the status data is stored in a preset database area, and the status data is updated according to the block height, simplifying the storage structure of the status data and improving data processing efficiency.
It improves the processing efficiency of the blockchain system when adding and querying status data, simplifies the storage and update process of status data, and improves system performance.
Smart Images

Figure CN111444185B
Abstract
Description
Technical Field
[0001] The present application relates to the field of blockchain technology, and in particular to a block information updating method, device, computer equipment and storage medium. Background Art
[0002] With the development of computer technology, blockchain technology has emerged. Blockchain is a distributed system based on cryptography, peer-to-peer networks and consensus mechanisms. The system consists of a large number of nodes that jointly maintain a ledger based on group consensus. The world state refers to the global state information of the blockchain ledger at a certain moment. Since there are a batch of transactions in each block that will modify the state, the world state of each block will be different. The new world state is generated based on the change of the world state of the previous block. Most of the existing blockchain systems based on account status use a special customized solution to obtain the world state. The core of this solution is a tree structure called MPT (Merkle Patricia Tree), which is a complex structure that integrates multiple data structures.
[0003] However, since the existing world state is obtained and stored based on a complex structure that integrates multiple data structures, there will be a problem of low processing efficiency when using the existing world state to implement blockchain functions, such as adding and querying status data. Summary of the invention
[0004] Based on this, it is necessary to provide a block information updating method, apparatus, computer equipment and storage medium that can improve processing efficiency in response to the above technical problems.
[0005] A block information updating method, the method comprising:
[0006] Acquire an updated account and account status data corresponding to the updated account, and store the account status data in a first area of a preset database according to a preset status storage mapping relationship and the updated account;
[0007] According to the account status data and the updated account, the Merkle tree of the current block is constructed, and the updated status data of the current block is obtained according to the Merkle tree;
[0008] Obtaining update status data, account status data, and key-value mapping information of the updated account, and storing the key-value mapping information in a second area of the database;
[0009] Obtain the block height of the current block, obtain the status data of the previous block of the current block from the database according to the block height, obtain the status data of the current block according to the status data of the previous block and the update status data, and store the status data of the current block into the third area in the database according to the block height.
[0010] In one embodiment, obtaining the updated account and the account status data corresponding to the updated account includes:
[0011] receiving a resource transfer request;
[0012] Determine resource transfer information and update accounts based on resource transfer requests;
[0013] The account status data of the updated account is updated according to the resource transfer information.
[0014] In one embodiment, storing the account status data in a first area of a preset database according to a preset status storage mapping relationship and updating the account includes:
[0015] Determine, according to a preset state storage mapping relationship, data to be written in a first area of a preset database for updating an account, wherein the data to be written includes account state data;
[0016] Write the data to be written into the first area of the database.
[0017] In one embodiment, a Merkle tree of the current block is constructed according to the account status data and the updated account, and the updated status data of the current block is obtained according to the Merkle tree, including:
[0018] Perform eigenvalue calculations on account status data and updated accounts according to the preset eigenvalue algorithm to obtain the child nodes of the Merkle tree of the current block;
[0019] According to the child nodes of the Merkle tree of the current block, get the Merkle tree of the current block;
[0020] The root node of the Merkle tree is used as the updated status data of the current block.
[0021] In one embodiment, obtaining the update status data, the account status data, and the key-value mapping information of the updated account, and storing the key-value mapping information in the second area of the database includes:
[0022] Using the update status data as a key, the account status data and the update account as values, obtaining key-value mapping information of the update status data, the account status data and the update account;
[0023] The key-value mapping information is stored in a second area of the database.
[0024] In one embodiment, obtaining the block height of the current block, obtaining the status data of the previous block of the current block from the database according to the block height, and obtaining the status data of the current block according to the status data of the previous block and the update status data includes:
[0025] Get the block height of the current block, and determine the block height of the previous block based on the block height;
[0026] Obtain the status data of the previous block from the database according to the block height of the previous block;
[0027] The state data of the previous block and the updated state data are subjected to eigenvalue calculation according to the preset eigenvalue algorithm to obtain the state data of the current block.
[0028] In one embodiment, after storing the status data of the current block in the third area of the database according to the block height, the method further includes:
[0029] When a query request is received, the query height and the account to be queried are determined according to the query request;
[0030] Obtain the latest account status corresponding to the account to be queried according to the account to be queried, and determine the account block height corresponding to the latest account status;
[0031] Compare the query height and the account block height;
[0032] When the account block height is less than the query height, the account status data is obtained and fed back based on the latest account status;
[0033] When the account block height is greater than the query height, the latest version number is determined based on the latest account status, and the account status data is obtained and fed back based on the latest version number.
[0034] A block information updating device, the device comprising:
[0035] A first storage module, used to obtain an updated account and account status data corresponding to the updated account, and store the account status data in a first area of a preset database according to a preset status storage mapping relationship and the updated account;
[0036] The construction module is used to construct the Merkle tree of the current block according to the account status data and the updated account, and obtain the updated status data of the current block according to the Merkle tree;
[0037] A second storage module is used to obtain update status data, account status data and key-value mapping information of the updated account, and store the key-value mapping information in a second area of the database;
[0038] The update module is used to obtain the block height of the current block, obtain the status data of the previous block of the current block from the database according to the block height, obtain the status data of the current block according to the status data of the previous block and the update status data, and store the status data of the current block into the third area in the database according to the block height.
[0039] A computer device comprises a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0040] Acquire an updated account and account status data corresponding to the updated account, and store the account status data in a first area of a preset database according to a preset status storage mapping relationship and the updated account;
[0041] According to the account status data and the updated account, the Merkle tree of the current block is constructed, and the updated status data of the current block is obtained according to the Merkle tree;
[0042] Obtaining update status data, account status data, and key-value mapping information of the updated account, and storing the key-value mapping information in a second area of the database;
[0043] Obtain the block height of the current block, obtain the status data of the previous block of the current block from the database according to the block height, obtain the status data of the current block according to the status data of the previous block and the update status data, and store the status data of the current block into the third area in the database according to the block height.
[0044] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the following steps:
[0045] Acquire an updated account and account status data corresponding to the updated account, and store the account status data in a first area of a preset database according to a preset status storage mapping relationship and the updated account;
[0046] According to the account status data and the updated account, the Merkle tree of the current block is constructed, and the updated status data of the current block is obtained according to the Merkle tree;
[0047] Obtaining update status data, account status data, and key-value mapping information of the updated account, and storing the key-value mapping information in a second area of the database;
[0048] Obtain the block height of the current block, obtain the status data of the previous block of the current block from the database according to the block height, obtain the status data of the current block according to the status data of the previous block and the update status data, and store the status data of the current block into the third area in the database according to the block height.
[0049] The above-mentioned block information updating method, device, computer equipment and storage medium obtain the update account and the account status data corresponding to the update account, construct the Merkle tree of the current block according to the account status data and the update account, obtain the update status data of the current block according to the Merkle tree, obtain the block height of the current block, obtain the status data of the previous block of the current block from the database according to the block height, and obtain the status data of the current block according to the status data of the previous block and the update status data. The data structure of the status data is simplified, and the account status data is stored in the first area of the preset database according to the preset state storage mapping relationship and the update account, the update status data, the account status data and the key-value mapping information of the update account are obtained, and the key-value mapping information is stored in the second area of the database, and the status data of the current block is stored in the third area of the database according to the block height, so as to realize the storage of the change data of the status data, so that it is more convenient to realize the function of the blockchain by using the status data, and the processing efficiency can be improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] Figure 1 This is an application scenario diagram of a block information updating method in an embodiment;
[0051] Figure 2 It is a flowchart of a method for updating block information in one embodiment;
[0052] Figure 3 is a schematic diagram of a block information updating method in one embodiment;
[0053] Figure 4 is a flowchart of a method for updating block information in another embodiment;
[0054] Figure 5 is a structural block diagram of a block information updating device in one embodiment;
[0055] Figure 6 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0056] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0057] The block information updating method provided in this application can be applied to Figure 1In the application environment shown. Among them, the blockchain network 10 includes multiple blockchain nodes 110, and the terminal 120 communicates with the blockchain node 110 through the network. The blockchain node 110 obtains the update account and the account status data corresponding to the update account through the terminal 120, stores the account status data in the first area of the preset database according to the preset state storage mapping relationship and the update account, builds the Merkle tree of the current block according to the account status data and the update account, obtains the update status data of the current block according to the Merkle tree, obtains the key-value mapping information of the update status data, the account status data and the update account, stores the key-value mapping information in the second area of the database, obtains the block height of the current block, obtains the status data of the previous block of the current block from the database according to the block height, obtains the status data of the current block according to the status data of the previous block and the update status data, and stores the status data of the current block in the third area of the database according to the block height. Among them, the terminal 120 can be, but is not limited to, various personal computers, laptops, smart phones, tablet computers and portable wearable devices, and the blockchain node 110 can be implemented with an independent server or a server cluster composed of multiple servers.
[0058] In one embodiment, if Figure 2 As shown, a block information updating method is provided, which is applied to Figure 1 The blockchain node in is used as an example to illustrate, including the following steps S202 to S208.
[0059] S202: Acquire an updated account and account status data corresponding to the updated account, and store the account status data in a first area of a preset database according to a preset status storage mapping relationship and the updated account.
[0060] Among them, the updated account refers to the account whose status data is to be updated, the account status data refers to the data used to represent the account status, and the account status refers to the account balance, the number of transactions issued, the contract code, related storage and other data. For example, the account status data can specifically be an account status feature value. Further, the account status feature value can specifically be an account status hash value. The preset state storage mapping relationship refers to a preset state storage relationship, which is used to store the account status data of the updated account, and store the account status data in the first area of the preset database.
[0061] Specifically, when the account status data of an account needs to be updated, the terminal will send a resource transfer request to the blockchain node. After receiving the resource transfer request, the blockchain node will determine the updated account and the account status data corresponding to the updated account based on the resource transfer request, and store the account status data in the first area of the preset database according to the preset status storage mapping relationship and the updated account.
[0062] In one embodiment, S202 includes: receiving a resource transfer request, determining resource transfer information and an updated account according to the resource transfer request, and updating account status data of the updated account according to the resource transfer information.
[0063] Among them, the resource transfer request refers to a request to update the account status of an account, and the resource transfer request carries resource transfer information and an updated account. Resource transfer information refers to the way to update the account status of an account. For example, the resource transfer information may specifically include adding operations, modifying operations, and rolling back operations. Resource transfer information also includes resource transfer data, which refers to pending data of the updated account, and is used to update the account status of the updated account. For example, in a blockchain data transaction scenario, resource transfer data may specifically include pending transaction data of the updated account.
[0064] Specifically, when the account status data of an account needs to be updated, the terminal will send a resource transfer request to the blockchain node, and the resource transfer request carries the resource transfer information and the updated account. After receiving the resource transfer request, the blockchain node can determine the resource transfer information and the updated account through the resource transfer request, update the account status of the updated account according to the resource transfer information, and obtain the updated account status data according to the updated account status. Among them, updating the account status of the updated account according to the resource transfer information includes determining the method for updating the account status of the updated account according to the resource transfer information, and updating the account status according to the resource transfer data included in the resource transfer information. The account status data updated according to the updated account status includes the account status data updated according to the updated account status and the preset feature value algorithm. For example, the preset feature value algorithm can be a hash algorithm, and the updated account status data obtained is the account status hash value.
[0065] In the above embodiment, a resource transfer request is received, resource transfer information and an updated account are determined according to the resource transfer request, and the account status data of the updated account is updated according to the resource transfer information.
[0066] In one embodiment, S202 includes:
[0067] Determine, according to a preset state storage mapping relationship, data to be written in a first area of a preset database for updating an account, wherein the data to be written includes account state data;
[0068] Write the data to be written into the first area of the database.
[0069] Among them, the data to be written specifically refers to the data to be written in each data table in the first area of the preset database of the updated account. Each data table corresponds to the state storage mapping relationship. The data to be written includes account status data, account status, and updated account, etc. Specifically, the data table includes a state table, a version table, and a latest version table. Each data table stores the data to be written in a key-value manner. According to the state storage mapping relationship, data with different corresponding relationships needs to be stored in different data tables, that is, the data to be stored in each data table is not exactly the same, so it is necessary to determine the data to be written in each data table. After determining the data to be written in each data table, the blockchain node will write the data to be written to the first area in the database. The first area in the database refers to the area used to store each data table corresponding to the state storage mapping relationship, which is used to store the account data of the account. The account data of the account includes account status data, account status, reference count, version number, block height, etc.
[0070] In the status table, the account status data is used as the key, and the account status and reference count are used as the value. In the version table, the updated account and version number are used as the key, and the block height and account status data are used as the value. In the latest version table, the updated account is used as the key, and the latest version number, block height, and account status data are used as the value. The reference count is used to indicate the number of occurrences of the current account status of the updated account.
[0071] In the above embodiment, storage of the account status data of the updated account in the first area of the database is implemented according to the preset status storage mapping relationship.
[0072] S204: Build a Merkle tree of the current block based on the account status data and the updated account, and obtain the updated status data of the current block based on the Merkle tree.
[0073] Among them, the Merkle tree is a binary tree, which contains a group of nodes. Their tree roots containing basic information have a large number of leaf nodes and a group of intermediate nodes. Each node is the hash of its two child nodes. The final root node is also formed by the hash of its two child nodes, representing the "top" of the tree. The blockchain node constructs the Merkle tree of the current block based on the account status data and the updated account, that is, the characteristic value of the key-value pair composed of the account status data and the updated account (with the updated account as the key and the account status data as the value) is used as the leaf node to construct the Merkle tree of the current block. The updated status data of the current block can be represented by the account status data updated by the updated account. When the account status data is updated, the status data of the current block will also be updated accordingly. Specifically, the updated status data of the current block can be obtained by constructing the Merkle tree of the current block based on the updated account status data. According to the characteristics of the Merkle tree, the updated status data of the current block is the top of the Merkle tree, that is, the root node.
[0074] In one embodiment, S204 includes:
[0075] Perform eigenvalue calculations on account status data and updated accounts according to the preset eigenvalue algorithm to obtain the child nodes of the Merkle tree of the current block;
[0076] According to the child nodes of the Merkle tree of the current block, get the Merkle tree of the current block;
[0077] The root node of the Merkle tree is used as the updated status data of the current block.
[0078] Among them, the preset eigenvalue algorithm can be set as needed. For example, the eigenvalue algorithm can be a hash algorithm. Specifically, the blockchain node will perform eigenvalue operations on the key-value pairs consisting of the account status data and the updated account (with the updated account as the key and the account status data as the value), obtain the account status eigenvalue, and use the account status eigenvalue as the leaf node of the Merkle tree to build the Merkle tree of the current block. Further, in the process of building the Merkle tree of the current block, after obtaining the leaf node of the account status eigenvalue, the blockchain node will perform eigenvalue operations again according to the account status eigenvalues of all accounts in the current block, further obtain the intermediate node, and obtain the two child nodes of the root node by continuously performing eigenvalue operations on the intermediate nodes, and finally obtain the root node by performing eigenvalue operations on the two child nodes of the root node, and complete the construction of the Merkle tree of the current block. The root node of the Merkle tree is the corresponding updated status data of the current block.
[0079] For example, Figure 3As shown, in the blockchain node, UpdatedStates[n][0], UpdatedStates[n][1], ..., UpdatedStates[n][L-1], UpdatedStates[n][L] represent all key-value pairs consisting of account status data and updated accounts in the current block n, where the key is the updated account and the value is the account status data. Through hash operation, the corresponding TR[0][0], TR[0][1], ..., TR[0][L-1], TR[0][L] can be obtained to represent the hash values of the key-value pairs consisting of the above account status data and updated accounts. TR[1][0], ..., TR[1][? ] and the intermediate nodes of each layer omitted above are the intermediate nodes obtained by splicing the two child nodes of the lower layer and then hashing. The root node UpdateRoot[n] is the Merkle tree root of the current block n, which can uniquely represent the status update of the current block and is used to participate in the calculation of the block world state.
[0080] In the above embodiment, characteristic value operations are performed on the account status data and the updated account according to a preset characteristic value algorithm to obtain the child nodes of the Merkle tree of the current block. The Merkle tree of the current block is obtained according to the child nodes of the Merkle tree of the current block, and the root node of the Merkle tree is used as the updated status data of the current block, thereby realizing the acquisition of the updated status data of the current block.
[0081] S206: Acquire update status data, account status data, and key-value mapping information of the updated account, and store the key-value mapping information in a second area of the database.
[0082] Among them, the key-value mapping information refers to the correspondence between the update status data, the account status data, and the update account. Specifically, the blockchain node will use the update status data as the key, the account status data and the update account as the value, and obtain the key-value mapping information of the update status data, the account status data, and the update account. Among them, using the account status data and the update account as the value means using all key-value pairs consisting of the account status data and the update account corresponding to the update status data as the value. After obtaining the key-value mapping information, the blockchain node will store the key-value mapping information in the second area of the database. The second block in the database refers to the area for storing the key-value mapping information of the update status data, the account status data, and the update account, and the second area includes a data table for storing the key-value mapping information.
[0083] In one embodiment, S206 includes:
[0084] Using the update status data as a key, the account status data and the update account as values, obtaining key-value mapping information of the update status data, the account status data and the update account;
[0085] The key-value mapping information is stored in a second area of the database.
[0086] Specifically, the blockchain node will package all key-value pairs corresponding to the updated status data, which are composed of account status data and updated accounts, as values, and use the updated status data as keys to obtain key-value mapping information. After obtaining the key-value mapping information, the blockchain node will store the key-value mapping information in a data table for storing key-value mapping information in the second area of the database. The data table stores the key-value mapping information corresponding to each block in the blockchain. By storing the key-value mapping information in the data table, hierarchical storage of the updated status data can be achieved.
[0087] In the above embodiment, the update status data is used as the key, the account status data and the update account are used as the value, and the key-value mapping information of the update status data, the account status data and the update account is obtained, and the key-value mapping information is stored in the second area of the database, thereby realizing the storage of the update status data.
[0088] S208: Obtain the block height of the current block, obtain the status data of the previous block of the current block from the database according to the block height, obtain the status data of the current block according to the status data of the previous block and the update status data, and store the status data of the current block into the third area in the database according to the block height.
[0089] Specifically, since the updated status data corresponds to the current block, the blockchain node can obtain the block height of the current block according to the updated status data, and then determine the block height of the previous block according to the block height of the current block, and obtain the status data of the previous block of the current block from the database according to the block height of the previous block. Among them, the database stores the corresponding data table of block height and status data, in which the block height and status data correspond one to one, and the status data corresponding to the block height can be obtained from the database according to the block height. The status data of the previous block can be used to represent the account status of all accounts in the blockchain before the account status data is updated. After obtaining the status data of the previous block, the blockchain node will obtain the status data of the current block according to the status data of the previous block and the updated status data. The status data of the current block is used to represent the account status of all accounts in the blockchain after the account status data is updated. After obtaining the status data of the current block, the blockchain node will store the status data of the current block in the third area of the database according to the block height. Among them, the third area includes the corresponding data table.
[0090] In one embodiment, S208 includes:
[0091] Get the block height of the current block, and determine the block height of the previous block based on the block height;
[0092] Obtain the status data of the previous block from the database according to the block height of the previous block;
[0093] The state data of the previous block and the updated state data are subjected to eigenvalue calculation according to the preset eigenvalue algorithm to obtain the state data of the current block.
[0094] Specifically, the block height of the previous block is 1 less than the block height of the current block, and the blockchain node can determine the block height of the previous block based on the block height of the current block. After determining the block height of the previous block, the blockchain node can query the corresponding data table of the block height and status data stored in the database based on the block height of the previous block to obtain the status data of the previous block, and then perform eigenvalue calculations on the status data and updated status data of the previous block based on a preset eigenvalue algorithm to obtain the status data of the current block. Among them, the preset eigenvalue algorithm can specifically be a hash algorithm.
[0095] In the above embodiment, the block height of the previous block is determined according to the block height, the status data of the previous block is obtained from the database according to the block height of the previous block, and the status data of the previous block and the update status data are subjected to eigenvalue operation according to a preset eigenvalue algorithm to obtain the status data of the current block, thereby realizing the acquisition of the status data of the current block.
[0096] In one embodiment, after S208, the block information updating method further includes:
[0097] When a query request is received, the query height and the account to be queried are determined according to the query request;
[0098] Obtain the latest account status corresponding to the account to be queried according to the account to be queried, and determine the account block height corresponding to the latest account status;
[0099] Compare the query height and the account block height;
[0100] When the account block height is less than the query height, the account status data is obtained and fed back based on the latest account status;
[0101] When the account block height is greater than the query height, the latest version number is determined based on the latest account status, and the account status data is obtained and fed back based on the latest version number.
[0102] The query request refers to a user's request to query account status data at any height. The query height refers to the block height to be queried. The latest account status refers to the latest account feature value of the account to be queried stored in the database. For example, the latest account status can specifically be the latest account status hash value. The account block height refers to the block height corresponding to the latest account status.
[0103] Specifically, when a user needs to query account status data at any height, a query request will be sent to the blockchain node through the terminal. After receiving the query request, the blockchain node will determine the query height and the account to be queried according to the query request, obtain the latest account status corresponding to the account to be queried from the database according to the account to be queried, determine the account block height corresponding to the latest account status, compare the query height and the account block height, when the account block height is less than the query height, it means that the account status data of the block corresponding to the query height is the same as the account status data of the block corresponding to the account block height, the blockchain node will directly obtain the account status data from the database according to the latest account status and feedback, when the account block height is greater than the query height, the blockchain node needs to further determine the latest version number according to the latest account status, obtain the account status data according to the latest version number and feedback.
[0104] Furthermore, obtaining account status data according to the latest version number and feeding back the data includes: comparing the latest version number with a preset version value, when the latest version number and the preset version value are not equal, obtaining the average value of the latest version number and the preset version value, determining the version number corresponding to the average value, and obtaining the block height and account status corresponding to the version number from a preset database, further comparing the block height and query height corresponding to the version number, when the block height and query height corresponding to the version number are the same, obtaining the account status data from the preset database according to the account status corresponding to the version number and feeding back the data, when the block height and query height corresponding to the version number are not the same, setting the average value as the new version value, and returning to the step of comparing the latest version number and the version value.
[0105] The above block information updating method obtains the update account and the account status data corresponding to the update account, constructs the Merkle tree of the current block according to the account status data and the update account, obtains the update status data of the current block according to the Merkle tree, obtains the block height of the current block, obtains the status data of the previous block of the current block from the database according to the block height, and obtains the status data of the current block according to the status data of the previous block and the update status data. The data structure of the status data is simplified, and the account status data is stored in the first area of the preset database according to the preset state storage mapping relationship and the update account, the update status data, the account status data and the key-value mapping information of the update account are obtained, and the key-value mapping information is stored in the second area of the database, and the status data of the current block is stored in the third area of the database according to the block height, thereby realizing the storage of the change data of the status data, so that it is more convenient to realize the function of the blockchain by using the status data, and the processing efficiency can be improved.
[0106] In one embodiment, if Figure 4 As shown, a most specific embodiment is used to illustrate the block information updating method in the present application. The method includes the following steps S402 to S440.
[0107] S402: receiving a resource transfer request;
[0108] S404: Determine resource transfer information and update account according to the resource transfer request;
[0109] S406: updating the account status data of the updated account according to the resource transfer information;
[0110] S408: Determine the data to be written in the first area of the preset database for updating the account according to the preset state storage mapping relationship, where the data to be written includes the account state data;
[0111] S410: writing the data to be written into the first area in the database;
[0112] S412: Performing eigenvalue calculations on the account status data and the updated account according to a preset eigenvalue algorithm to obtain child nodes of the Merkle tree of the current block;
[0113] S414: Obtain the Merkle tree of the current block according to the child nodes of the Merkle tree of the current block;
[0114] S416: Using the root node of the Merkle tree as the update status data of the current block;
[0115] S418: Using the update status data as a key, the account status data and the update account as values, to obtain key-value mapping information of the update status data, the account status data and the update account;
[0116] S420: storing the key-value mapping information in the second area of the database;
[0117] S422: Obtain the block height of the current block, and determine the block height of the previous block according to the block height;
[0118] S424: Obtain the status data of the previous block from the database according to the block height of the previous block;
[0119] S426: Performing eigenvalue calculation on the state data of the previous block and the updated state data according to a preset eigenvalue algorithm to obtain the state data of the current block;
[0120] S428: storing the status data of the current block into the third area in the database according to the block height;
[0121] S430: When a query request is received, determining a query height and an account to be queried according to the query request;
[0122] S432: Obtain the latest account status corresponding to the account to be queried according to the account to be queried, and determine the account block height corresponding to the latest account status;
[0123] S434: Compare the query height and the account block height;
[0124] S436: Determine whether the account block height is less than the query height. If the determination result is yes, jump to step S438; if the determination result is no, jump to step S440;
[0125] S438: Obtain account status data according to the latest account status and provide feedback;
[0126] S440: Determine the latest version number according to the latest account status, obtain account status data according to the latest version number and provide feedback.
[0127] It should be understood that although Figure 2 and Figure 4 The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, Figure 2 and Figure 4At least part of the steps may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least part of the sub-steps or stages of other steps.
[0128] In one embodiment, if Figure 5 As shown, a block information updating device is provided, comprising: a first storage module, a construction module, a second storage module and an updating module, wherein:
[0129] A first storage module, used to obtain an updated account and account status data corresponding to the updated account, and store the account status data in a first area of a preset database according to a preset status storage mapping relationship and the updated account;
[0130] The construction module is used to construct the Merkle tree of the current block according to the account status data and the updated account, and obtain the updated status data of the current block according to the Merkle tree;
[0131] A second storage module is used to obtain update status data, account status data and key-value mapping information of the updated account, and store the key-value mapping information in a second area of the database;
[0132] The update module is used to obtain the block height of the current block, obtain the status data of the previous block of the current block from the database according to the block height, obtain the status data of the current block according to the status data of the previous block and the update status data, and store the status data of the current block into the third area in the database according to the block height.
[0133] The above-mentioned block information updating device obtains the update account and the account status data corresponding to the update account, constructs the Merkle tree of the current block according to the account status data and the update account, obtains the update status data of the current block according to the Merkle tree, obtains the block height of the current block, obtains the status data of the previous block of the current block from the database according to the block height, and obtains the status data of the current block according to the status data of the previous block and the update status data. The data structure of the status data is simplified, and the account status data is stored in the first area of the preset database according to the preset state storage mapping relationship and the update account, the update status data, the account status data and the key-value mapping information of the update account are obtained, and the key-value mapping information is stored in the second area of the database, and the status data of the current block is stored in the third area of the database according to the block height, thereby realizing the storage of the change data of the status data, so that it can make it more convenient to realize the function of the blockchain by using the status data, and can improve the processing efficiency.
[0134] In one of the embodiments, the first storage module is further used to receive a resource transfer request, determine resource transfer information and update the account according to the resource transfer request, and update the account status data of the updated account according to the resource transfer information.
[0135] In one embodiment, the first storage module is further used to determine the data to be written in the first area of the preset database of the updated account according to the preset status storage mapping relationship, the data to be written includes the account status data, and write the data to be written into the first area of the database.
[0136] In one of the embodiments, the construction module is also used to perform eigenvalue operations on the account status data and the updated account according to a preset eigenvalue algorithm to obtain the child nodes of the Merkle tree of the current block, obtain the Merkle tree of the current block according to the child nodes of the Merkle tree of the current block, and use the root node of the Merkle tree as the updated status data of the current block.
[0137] In one embodiment, the second storage module is also used to use the update status data as the key, the account status data and the updated account as the value, obtain the key-value mapping information of the update status data, the account status data and the updated account, and store the key-value mapping information in the second area of the database.
[0138] In one of the embodiments, the update module is also used to obtain the block height of the current block, determine the block height of the previous block according to the block height, obtain the status data of the previous block from the database according to the block height of the previous block, and perform eigenvalue operations on the status data of the previous block and the update status data according to a preset eigenvalue algorithm to obtain the status data of the current block.
[0139] In one of the embodiments, the block information updating device also includes a query module, which is used to determine the query height and the account to be queried according to the query request when a query request is received, obtain the latest account status corresponding to the account to be queried according to the account to be queried, determine the account block height corresponding to the latest account status, compare the query height and the account block height, when the account block height is less than the query height, obtain account status data according to the latest account status and feedback, when the account block height is greater than the query height, determine the latest version number according to the latest account status, obtain account status data according to the latest version number and feedback.
[0140] For the specific definition of the block information updating device, please refer to the definition of the block information updating method above, which will not be repeated here. Each module in the above block information updating device can be implemented in whole or in part by software, hardware and a combination thereof. Each of the above modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.
[0141] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 6 As shown. The computer device includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store account status data. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a block information update method is implemented.
[0142] Those skilled in the art will understand that Figure 6 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0143] In one embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0144] Acquire an updated account and account status data corresponding to the updated account, and store the account status data in a first area of a preset database according to a preset status storage mapping relationship and the updated account;
[0145] According to the account status data and the updated account, the Merkle tree of the current block is constructed, and the updated status data of the current block is obtained according to the Merkle tree;
[0146] Obtaining update status data, account status data, and key-value mapping information of the updated account, and storing the key-value mapping information in a second area of the database;
[0147] Obtain the block height of the current block, obtain the status data of the previous block of the current block from the database according to the block height, obtain the status data of the current block according to the status data of the previous block and the update status data, and store the status data of the current block into the third area in the database according to the block height.
[0148] The above-mentioned block information updating computer device obtains the update account and the account status data corresponding to the update account, constructs the Merkle tree of the current block according to the account status data and the update account, obtains the update status data of the current block according to the Merkle tree, obtains the block height of the current block, obtains the status data of the previous block of the current block from the database according to the block height, and obtains the status data of the current block according to the status data of the previous block and the update status data. The data structure of the status data is simplified, and the account status data is stored in the first area of the preset database according to the preset state storage mapping relationship and the update account, the update status data, the account status data and the key-value mapping information of the update account are obtained, and the key-value mapping information is stored in the second area of the database, and the status data of the current block is stored in the third area of the database according to the block height, thereby realizing the storage of the change data of the status data, so that it can make it more convenient to realize the function of the blockchain by using the status data, and can improve the processing efficiency.
[0149] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0150] receiving a resource transfer request;
[0151] Determine resource transfer information and update accounts based on resource transfer requests;
[0152] The account status data of the updated account is updated according to the resource transfer information.
[0153] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0154] Determine, according to a preset state storage mapping relationship, data to be written in a first area of a preset database for updating an account, wherein the data to be written includes account state data;
[0155] Write the data to be written into the first area of the database.
[0156] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0157] Perform eigenvalue calculations on account status data and updated accounts according to the preset eigenvalue algorithm to obtain the child nodes of the Merkle tree of the current block;
[0158] According to the child nodes of the Merkle tree of the current block, get the Merkle tree of the current block;
[0159] The root node of the Merkle tree is used as the updated status data of the current block.
[0160] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0161] Using the update status data as a key, the account status data and the update account as values, obtaining key-value mapping information of the update status data, the account status data and the update account;
[0162] The key-value mapping information is stored in a second area of the database.
[0163] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0164] Get the block height of the current block, and determine the block height of the previous block based on the block height;
[0165] Obtain the status data of the previous block from the database according to the block height of the previous block;
[0166] The state data of the previous block and the updated state data are subjected to eigenvalue calculation according to the preset eigenvalue algorithm to obtain the state data of the current block.
[0167] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0168] When a query request is received, the query height and the account to be queried are determined according to the query request;
[0169] Obtain the latest account status corresponding to the account to be queried according to the account to be queried, and determine the account block height corresponding to the latest account status;
[0170] Compare the query height and the account block height;
[0171] When the account block height is less than the query height, the account status data is obtained and fed back based on the latest account status;
[0172] When the account block height is greater than the query height, the latest version number is determined based on the latest account status, and the account status data is obtained and fed back based on the latest version number.
[0173] In one embodiment, a computer readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
[0174] Acquire an updated account and account status data corresponding to the updated account, and store the account status data in a first area of a preset database according to a preset status storage mapping relationship and the updated account;
[0175] According to the account status data and the updated account, the Merkle tree of the current block is constructed, and the updated status data of the current block is obtained according to the Merkle tree;
[0176] Obtaining update status data, account status data, and key-value mapping information of the updated account, and storing the key-value mapping information in a second area of the database;
[0177] Obtain the block height of the current block, obtain the status data of the previous block of the current block from the database according to the block height, obtain the status data of the current block according to the status data of the previous block and the update status data, and store the status data of the current block into the third area in the database according to the block height.
[0178] The above-mentioned block information updates the storage medium, by acquiring the update account and the account status data corresponding to the update account, constructing the Merkle tree of the current block according to the account status data and the update account, obtaining the update status data of the current block according to the Merkle tree, obtaining the block height of the current block, obtaining the status data of the previous block of the current block from the database according to the block height, and obtaining the status data of the current block according to the status data of the previous block and the update status data. The data structure of the status data is simplified, and the account status data is stored in the first area of the preset database according to the preset state storage mapping relationship and the update account, the update status data, the account status data and the key-value mapping information of the update account are obtained, and the key-value mapping information is stored in the second area of the database, and the status data of the current block is stored in the third area of the database according to the block height, thereby realizing the storage of the change data of the status data, so that it is more convenient to realize the function of the blockchain by using the status data, and the processing efficiency can be improved.
[0179] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0180] receiving a resource transfer request;
[0181] Determine resource transfer information and update accounts based on resource transfer requests;
[0182] The account status data of the updated account is updated according to the resource transfer information.
[0183] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0184] Determine, according to a preset state storage mapping relationship, data to be written in a first area of a preset database for updating an account, wherein the data to be written includes account state data;
[0185] Write the data to be written into the first area of the database.
[0186] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0187] Perform eigenvalue calculations on account status data and updated accounts according to the preset eigenvalue algorithm to obtain the child nodes of the Merkle tree of the current block;
[0188] According to the child nodes of the Merkle tree of the current block, get the Merkle tree of the current block;
[0189] The root node of the Merkle tree is used as the updated status data of the current block.
[0190] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0191] Using the update status data as a key, the account status data and the update account as values, obtaining key-value mapping information of the update status data, the account status data and the update account;
[0192] The key-value mapping information is stored in a second area of the database.
[0193] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0194] Get the block height of the current block, and determine the block height of the previous block based on the block height;
[0195] Obtain the status data of the previous block from the database according to the block height of the previous block;
[0196] The state data of the previous block and the updated state data are subjected to eigenvalue calculation according to the preset eigenvalue algorithm to obtain the state data of the current block.
[0197] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0198] When a query request is received, the query height and the account to be queried are determined according to the query request;
[0199] Obtain the latest account status corresponding to the account to be queried according to the account to be queried, and determine the account block height corresponding to the latest account status;
[0200] Compare the query height and the account block height;
[0201] When the account block height is less than the query height, the account status data is obtained and fed back based on the latest account status;
[0202] When the account block height is greater than the query height, the latest version number is determined based on the latest account status, and the account status data is obtained and fed back based on the latest version number.
[0203] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0204] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0205] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.
Claims
1. A method for updating block information, the method comprising: Acquire an update account and account status data corresponding to the update account, and store the account status data in a first area of a preset database according to a preset status storage mapping relationship and the update account; Performing feature value calculation on the key-value pair of the account status data and the updated account according to a preset feature value algorithm to obtain an account status feature value, and using the account status feature value as a leaf node of the Merkle tree of the current block; Perform feature value calculation again based on the account status feature values of all accounts in the current block to obtain the intermediate node. Perform feature value calculation on the intermediate node multiple times to obtain the two child nodes of the root node. Perform feature value calculation on the two child nodes of the root node to obtain the root node to construct the Merkle tree of the current block. Using the root node of the Merkle tree as the updated state data of the current block; Using the update status data as a key, the account status data and the update account as values, obtaining key-value mapping information of the update status data, the account status data and the update account; Storing the key-value mapping information in a second area of the database; Obtaining a block height of a current block according to the updated status data, and determining a block height of a previous block according to the block height; Acquire the status data of the previous block from the database according to the block height of the previous block; the database stores a corresponding data table of block height and status data, in which the block height and status data correspond one to one; Performing eigenvalue operations on the status data of the previous block and the updated status data according to a preset eigenvalue algorithm to obtain the status data of the current block, and storing the status data of the current block in a third area in the database according to the block height; the status data of the previous block is used to represent the account status of all accounts in the blockchain before the account status data is updated; the status data of the current block is used to represent the account status of all accounts in the blockchain after the account status data is updated.
2. The method according to claim 1, characterized in that The obtaining of the updated account and the account status data corresponding to the updated account includes: receiving a resource transfer request; Determining resource transfer information and updating an account according to the resource transfer request; The account status data of the update account is updated according to the resource transfer information.
3. The method according to claim 1, characterized in that The storing of the account status data in a first area of a preset database according to a preset status storage mapping relationship and the updating of the account comprises: Determine the data to be written in the first area of the preset database of the updated account according to the preset state storage mapping relationship, wherein the data to be written includes the account state data; The data to be written is written into the first area in the database.
4. The method according to claim 1, characterized in that: After storing the status data of the current block in the third area of the database according to the block height, the method further includes: When receiving a query request, determining a query height and an account to be queried according to the query request; Acquire the latest account status corresponding to the account to be queried according to the account to be queried, and determine the account block height corresponding to the latest account status; Comparing the query height with the account block height; When the account block height is less than the query height, the account status data is obtained and fed back according to the latest account status; When the account block height is greater than the query height, the latest version number is determined according to the latest account status, and the account status data is obtained and fed back according to the latest version number.
5. A block information updating device, characterized in that: The device comprises: A first storage module, configured to obtain an update account and account status data corresponding to the update account, and store the account status data in a first area of a preset database according to a preset status storage mapping relationship and the update account; A construction module, configured to perform a characteristic value operation on the key-value pairs consisting of the account status data and the updated account according to a preset characteristic value algorithm to obtain an account status characteristic value, use the account status characteristic value as a leaf node of the Merkle tree of the current block, perform a characteristic value operation again according to the account status characteristic values of all accounts in the current block to obtain an intermediate node, perform characteristic value operations on the intermediate nodes multiple times to obtain two child nodes of a root node, perform characteristic value operations on the two child nodes of the root node to obtain a root node, so as to construct a Merkle tree of the current block, and use the root node of the Merkle tree as the updated status data of the current block; a second storage module, configured to use the update status data as a key, the account status data and the update account as values, obtain key-value mapping information of the update status data, the account status data and the update account, and store the key-value mapping information in a second area of the database; An update module is used to obtain a block height of a current block according to the updated status data, determine a block height of a previous block according to the block height, obtain status data of the previous block from the database according to the block height of the previous block, wherein a corresponding data table of block heights and status data is stored in the database, in which block heights and status data correspond one to one, perform eigenvalue operations on the status data of the previous block and the updated status data according to a preset eigenvalue algorithm to obtain status data of the current block, and store the status data of the current block in a third area in the database according to the block height; the status data of the previous block is used to represent the account status of all accounts in the blockchain before the account status data is updated; and the status data of the current block is used to represent the account status of all accounts in the blockchain after the account status data is updated.
6. The device according to claim 5, characterized in that The first storage module is further configured to receive a resource transfer request, determine resource transfer information and an update account according to the resource transfer request, and update account status data of the update account according to the resource transfer information.
7. The device according to claim 5, characterized in that The first storage module is further used to determine the data to be written in the first area of the preset database of the updated account according to the preset state storage mapping relationship, the data to be written includes the account state data, and write the data to be written into the first area of the database.
8. The device according to claim 5, characterized in that The device also includes a query module, which is used to determine the query height and the account to be queried according to the query request when a query request is received, obtain the latest account status corresponding to the account to be queried according to the account to be queried, determine the account block height corresponding to the latest account status, compare the query height and the account block height, when the account block height is less than the query height, obtain account status data according to the latest account status and feedback, when the account block height is greater than the query height, determine the latest version number according to the latest account status, obtain account status data according to the latest version number and feedback.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 4 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 4 are implemented.
