Transaction data storage methods, devices, computer equipment and storage media

By generating new key-value pairs in the blockchain, combining the contract address and hash value of transaction data, and randomly distributing them to multiple subtrees, the IAVL tree imbalance problem is solved, and the blockchain storage performance is improved.

CN116126866BActive Publication Date: 2025-12-02SHANGHAI ENCRYPTION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310141031.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-02-20
Publication Date
2025-12-02
Estimated Expiration
2043-02-20

AI Technical Summary

Technical Problem

In blockchain applications developed based on the Cosmos framework, the height difference between subtrees of the IAVL tree becomes unbalanced across the entire tree, leading to frequent self-balancing actions that consume server computing and storage resources and reduce blockchain storage performance.

Method used

By calculating the combination of contract address and hash value of transaction data, new key-value pairs are generated and inserted into the IAVL tree. The storage data is randomly distributed to multiple subtrees, reducing the probability of subtree height imbalance and reducing self-balancing actions.

Benefits of technology

It effectively reduces the probability of subtree height imbalance, reduces the number of self-balancing actions of the IAVL tree, saves server computing and storage resources, and improves blockchain storage performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116126866B_ABST
    Figure CN116126866B_ABST
Patent Text Reader

Abstract

This application discloses a transaction data storage method. The method includes: acquiring transaction data from a blockchain block, wherein the block contains multiple transaction data; parsing the multiple transaction data to obtain a contract address and a key-value pair corresponding to each transaction data; calculating the hash value of the key value in the key-value pair; obtaining a character at a preset position in the hash value, concatenating the character with the contract address and the hash value to obtain a new key value; combining the new key value with the value value in the key-value pair to form data to be stored, and inserting the data to be stored into an IAVL tree. This application can reduce the probability of IAVL tree subtree height imbalance, reduce the number of self-balancing triggers, and reduce server computing and storage resource consumption.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of blockchain technology, and in particular to a transaction data storage method, apparatus, computer equipment, and storage medium. Background Technology

[0002] For blockchain applications developed based on the Cosmos framework, the underlying data storage uses an IAVL tree. When a smart contract is called to process user transaction data, the key-value pairs in the transaction data are stored as key-value pairs on the underlying IAVL tree.

[0003] However, the inventors discovered that the existing storage rules on IAVL trees are as follows: the corresponding key is the hash of the data key value concatenated with the contract address, and the corresponding value is the data value. Therefore, transaction data within the same contract has the same prefix (contract address) on the IAVL tree. According to the characteristics of IAVL trees, the stored data will fall on the same subtree. Under this Cosmos framework, if a contract has a large amount of data that needs to be stored, this data will be inserted into the same subtree of the IAVL tree. This will frequently cause the height difference of the current subtree to become unbalanced in the entire IAVL tree, triggering the IAVL tree self-balancing action, consuming a large amount of server computing and storage resources, and reducing the blockchain storage performance. Summary of the Invention

[0004] In view of this, a transaction data storage method, apparatus, computer equipment, and computer-readable storage medium are provided to solve the problem that in the prior art, when storing transaction data in blockchain applications developed through the Cosmos framework, the height difference of the subtrees of the IAVL tree frequently becomes unbalanced across the entire IAVL tree, triggering the IAVL tree self-balancing action, consuming a large amount of server computing and storage resources, and reducing the performance of blockchain storage.

[0005] This application provides a method for storing transaction data, including:

[0006] Obtain transaction data from blocks in a blockchain, wherein the blocks contain multiple transaction data;

[0007] The transaction data is parsed to obtain the contract address and key-value pair corresponding to each transaction data.

[0008] Calculate the hash value of the key value in the key-value pair;

[0009] Obtain the character in the preset position of the hash value, and concatenate the character with the contract address and the hash value to obtain a new key value;

[0010] The new key value and the value in the key-value pair are combined to form the data to be stored, and the data to be stored is inserted into the IAVL tree.

[0011] Optionally, calculating the hash value of the key in the key-value pair includes:

[0012] The hash value of the key in the key-value pair is calculated using a preset hash algorithm.

[0013] Optionally, the preset hash algorithm is the SHA-256 algorithm.

[0014] Optionally, obtaining the character at a preset position in the hash value and concatenating the character with the contract address and the hash value to obtain a new key value includes:

[0015] Obtain the first character of the hash value, concatenate the first character with the contract address and the hash value to obtain a new key value.

[0016] Optionally, the step of combining the new key value with the value value in the key-value pair to form the data to be stored, and inserting the data to be stored into the IAVL tree, includes:

[0017] The new key value and the value in the key-value pair are combined to form the data to be stored, and the data to be stored is cached in memory;

[0018] When the memory caches multiple key-value pairs corresponding to the transaction data, all the cached data to be stored is inserted into the IAVL tree in batches.

[0019] Optionally, before parsing the transaction data, the method further includes:

[0020] The signature information of the sender of the transaction data is verified.

[0021] Optionally, the method further includes:

[0022] The IAVL tree is used to check whether its own balance has been broken. If the balance of the IAVL tree is broken, a self-balancing action is triggered.

[0023] This application also provides a transaction data storage device, comprising:

[0024] The acquisition module is used to acquire transaction data in blocks of the blockchain, wherein the blocks contain multiple transaction data.

[0025] The parsing module is used to parse multiple transaction data to obtain the contract address and key-value pair corresponding to each transaction data.

[0026] The calculation module is used to calculate the hash value of the key value in the key-value pair;

[0027] The concatenation module is used to obtain the character in the preset position in the hash value, and concatenate the character with the contract address and the hash value to obtain a new key value;

[0028] The insertion module is used to combine the new key value with the value value in the key-value pair to form the data to be stored, and to insert the data to be stored into the IAVL tree.

[0029] This application also provides a computer device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the above-described method.

[0030] This application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the above-described method.

[0031] In this embodiment, transaction data is obtained from blockchain blocks, where each block contains multiple transaction data. The multiple transaction data are parsed to obtain the contract address and key-value pair corresponding to each transaction data. The hash value of the key in the key-value pair is calculated. The character at a preset position in the hash value is obtained and concatenated with the contract address and the hash value to obtain a new key value. The new key value and the value in the key-value pair are combined to form the data to be stored, and the data to be stored is inserted into the IAVL tree. Using this transaction data storage scheme, the prefix of the data to be stored under the same smart contract can be randomly shuffled into multiple parts. Thus, during the insertion process into the IAVL tree, this data will be randomly assigned to multiple subtrees, effectively reducing the probability of subtree height imbalance, reducing the number of times the IAVL tree triggers self-balancing actions, thereby reducing the consumption of server computing and storage resources and improving blockchain storage performance. Attached Figure Description

[0032] Figure 1 This is a schematic diagram illustrating the application environment of the transaction data storage method according to an embodiment of this application;

[0033] Figure 2 A flowchart of one embodiment of the transaction data storage method described in this application;

[0034] Figure 3 This is a detailed flowchart of the steps in one embodiment of the present application to form data to be stored by combining the new key value with the value value in the key-value pair and inserting the data to be stored into the IAVL tree;

[0035] Figure 4 This is a program block diagram of one embodiment of the transaction data storage device described in this application;

[0036] Figure 5 This is a schematic diagram of the hardware structure of a computer device for executing a transaction data storage method, as provided in an embodiment of this application. Detailed Implementation

[0037] The advantages of this application are further illustrated below with reference to the accompanying drawings and specific embodiments.

[0038] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numerals in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this disclosure. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this disclosure as detailed in the appended claims.

[0039] The terminology used in this disclosure is for the purpose of describing particular embodiments only and is not intended to be limiting of the disclosure. The singular forms “a,” “the,” and “the” used in this disclosure and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to and includes any and all possible combinations of one or more of the associated listed items.

[0040] It should be understood that although the terms first, second, third, etc., may be used in this disclosure to describe various information, such information should not be limited to these terms. These terms are used only to distinguish information of the same type from one another. For example, without departing from the scope of this disclosure, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" as used herein may be interpreted as "when," "when," or "in response to determination."

[0041] In the description of this application, it should be understood that the numerical labels before the steps do not indicate the order of the steps, but are only used to facilitate the description of this application and to distinguish each step, and therefore should not be construed as a limitation of this application.

[0042] The following provides an exemplary application environment for this application. Figure 1The illustration shows a schematic diagram of the application environment of the transaction data storage method according to an embodiment of this application.

[0043] See Figure 1 Blockchain 100 is a typical distributed collaborative system. This system includes multiple blockchain nodes 110. These multiple blockchain nodes 110 can jointly maintain a continuously growing distributed data record. The data in these records can be protected in terms of content and time sequence using cryptographic techniques, making it difficult for any party to tamper with, deny, or forge. Blockchain nodes 110 can be devices with computing capabilities, such as servers, server groups, blockchain chips, etc., where server groups can be centralized or distributed. In some implementations, the aforementioned servers can also be servers providing services to a cloud platform.

[0044] In a blockchain, data (such as transaction information, transaction execution results, etc.) can be encapsulated in the form of blocks. Blocks can be linked together through forward references to form a "chain," i.e., a blockchain. Typically, the first block in a blockchain is called the "genesis block" or "initial block," the block preceding the current block is called the "previous block," and the block following the current block is called the "successor block."

[0045] Typically, a block can include a block header and a block body. The block header contains basic information about the current block to ensure it is correctly entered into the blockchain. For example, the block header might record the block hash of the previous block. It might also record the block height, which identifies the block's position in the blockchain. In some implementations, the genesis block has a height of 0. The block body records transaction information, such as the number of transactions and transaction data.

[0046] Blockchains are generally classified into three types: public blockchains, private blockchains, and consortium blockchains. Furthermore, combinations of these types are possible, such as private blockchain + consortium blockchain, or consortium blockchain + public blockchain. The implementation methods provided in this disclosure can be implemented in suitable types of blockchains.

[0047] In a blockchain system, the validity of a record is determined through a consensus mechanism. This consensus mechanism can be understood as how the nodes responsible for recording transactions in the blockchain (or the ledger nodes) reach a consensus to determine the validity of a record.

[0048] The consensus mechanism of blockchain features "majority rule" and "equality for all." "Majority rule" doesn't solely refer to the number of nodes; it can also be computing power, shareholding, or other comparable computer characteristics. "Equality for all" means that when nodes meet certain conditions, all nodes have the right to propose a consensus result first, which can then be directly accepted by other nodes and potentially become the final consensus result.

[0049] The self-trust inherent in blockchain technology lies in the fact that users distributed across the blockchain do not need to trust the other party in a transaction, nor do they need to trust a centralized institution; they only need to trust the software system under the blockchain protocol to complete a transaction. This self-trust is predicated on the blockchain's consensus mechanism. In a market where there is no mutual trust, the necessary and sufficient condition for nodes to reach a consensus is that each node, driven by the pursuit of its own maximum benefit, will spontaneously and honestly adhere to the pre-defined rules of the protocol, verify the authenticity of each record, and ultimately record the verifiable records in the blockchain. In other words, if nodes have independent interests and compete with each other, it is virtually impossible for them to collude to deceive you. This is especially evident when nodes possess public credibility within the network. Blockchain technology uses a consensus-based mathematical algorithm to establish a "trust" network between machines, thereby creating new forms of credit through technological endorsement rather than centralized credit institutions.

[0050] The consensus mechanism of a blockchain can be one of the following: Proof of Work (PoW), Proof of Stake, Delegated Proof of Stake, Verification Pool, and Practical Byzantine Fault Tolerance (PBFT).

[0051] In blockchain systems, transactions are executed through smart contracts. A smart contract is a protocol or contract within the blockchain system that can be executed automatically, allowing for trusted transactions without a third party. These transactions are traceable and irreversible. A smart contract is a set of promises defined in digital form, including the protocols by which the contract participants can execute these promises. Alternatively, a smart contract can be understood as a program deployed on a computer system that can be executed automatically when its triggering conditions are met.

[0052] In the blockchain field, another important concept is the account. For blockchain networks that support smart contracts, blockchain accounts can generally be divided into the following two types:

[0053] Contract account: Stores the executed smart contract code and the values ​​of the state within the smart contract code; it can typically only be activated by an external account.

[0054] Externally owned account: This is an account directly controlled by the user, also known as a user account.

[0055] The design of external accounts and contract accounts is essentially a mapping from account addresses to account states. The state of an account is typically represented by a structure. When a transaction in a block is executed, the state of the account associated with that transaction in the blockchain usually changes.

[0056] In one example, the account structure typically includes fields such as Balance, Nonce, Codehash, and Storageroot. Among these:

[0057] The Balance field is used to maintain the current account balance.

[0058] The Nonce field is used to maintain the number of transactions for this account. It is a counter used to ensure that each transaction can be processed exactly once, effectively preventing replay attacks;

[0059] The Codehash field is used to maintain the contract code for this account. In practice, the Codehash field typically only maintains the hash value of the contract code.

[0060] The Storageroot field is used to maintain the storage content of this account. For contract accounts, a separate persistent storage space is typically allocated to store the contract data corresponding to that contract account. This separate storage space is usually referred to as the account storage for that contract account.

[0061] Contract account data is typically stored in key-value pairs, constructed into a logical tree structure. For example, a Merkle tree is a commonly used logical tree structure in the blockchain field for storing and maintaining blockchain data. A Merkle tree is a binary tree where the parent node stores the hash of its left and right child nodes, and the specific business data is stored in the leaf nodes.

[0062] The logical tree structure built based on the stored content of the contract account is often referred to as a Storage tree. The Storageroot field typically only maintains the hash value of the root node of this Storage tree. For external accounts, both the Codehash and Storageroot fields shown above have null values.

[0063] See Figure 2 This is a flowchart illustrating a transaction data storage method according to an embodiment of this application. It should be understood that the flowchart in this method embodiment is not intended to limit the order of execution steps. As can be seen from the figure, the transaction data storage method provided in this embodiment includes:

[0064] Step S21: Obtain transaction data from a block in the blockchain, wherein the block contains multiple transaction data.

[0065] Specifically, when a user initiates N transactions for a smart contract (i.e., a contract account), the blockchain system will package the N transactions into a block of the blockchain system. Then, the transactions in the block will be processed through a consensus mechanism across the entire network. After the consensus is successful, the blockchain system will obtain the transaction data from the block and then execute each of the obtained transaction data in sequence.

[0066] Step S21: Parse the multiple transaction data to obtain the contract address and key-value pair corresponding to each transaction data.

[0067] Specifically, since each transaction data is packaged into the block in the form of bytecode, when the transaction data is obtained from the block, in order to facilitate the subsequent storage of the transaction data into the IAVL tree, it is necessary to first parse the transaction data in the form of bytecode to obtain the contract address and key-value pair corresponding to the transaction data.

[0068] The contract address is a smart contract that maps an account address to its balance.

[0069] In this embodiment, when parsing multiple transaction data, the multiple transaction data can be parsed sequentially or in parallel. No limitation is made in this embodiment.

[0070] In one exemplary embodiment, to improve the security of transaction data, the process further includes the following steps before parsing the transaction data:

[0071] The signature information of the sender of the transaction data is verified.

[0072] In this embodiment, the legitimacy of the transaction data can be determined by verifying the sender's signature information. If the sender's signature verification fails, it indicates that the transaction data is not legitimate and no further processing is required. Only when the sender's signature verification passes, indicating that the transaction data is legitimate, will further parsing of the transaction data proceed.

[0073] Step S22: Calculate the hash value of the key value in the key-value pair.

[0074] Specifically, when key-value pair data is obtained, the hash value of the key value in each key-value pair is calculated. For example, if there are a total of 5 key-value pairs, namely key1-value1, key2-value2, key3-value3, key4-value4, and key5-value5, then the hash value of key1 in key1-value1 is calculated to obtain hash1; the hash value of key2 in key2-value2 is calculated to obtain hash2; the hash value of key3 in key3-value3 is calculated to obtain hash3; the hash value of key4 in key4-value4 is calculated to obtain hash4; and the hash value of key5 in key5-value5 is calculated to obtain hash5.

[0075] In one exemplary implementation, the hash value of the key value in the key-value pair can be calculated using a preset hash algorithm.

[0076] The hash algorithm can be MD5, SHA-1, SHA-256, SHA-512, etc.

[0077] In this embodiment, the preset hash algorithm is preferably the SHA-256 algorithm. The SHA-256 algorithm is a sub-algorithm of SHA-2; it is a cryptographic hash function, simply put, it is a hash function. For a message of any length, SHA256 will produce a 256-bit hash value, called a message digest, which can be represented by a 64-bit hexadecimal string.

[0078] Step S23: Obtain the character in the preset position of the hash value, and concatenate the character with the contract address and the hash value to obtain a new key value.

[0079] Specifically, the preset bit is pre-set and can be set and adjusted according to actual conditions. In this embodiment, when the hash value is a 256-bit hash value, the preset bit can be set to any one bit in the 256-bit hash value, such as the 1st, 2nd, 256th bit, etc. of the 256-bit hash value.

[0080] As an example, assuming the character in the preset position of the obtained hash value is byteN, the hash value of the key value in the key-value pair is hashN, and the contract address is addrA, then the new key value newKey = byteN + addrA + hashN.

[0081] In one exemplary implementation, obtaining the character at a preset position in the hash value and concatenating the character with the contract address and the hash value to obtain a new key value includes:

[0082] Obtain the first character of the hash value, concatenate the first character with the contract address and the hash value to obtain a new key value.

[0083] In this embodiment, by setting the preset position to the first position of the hash value, the character in the preset position of the hash value can be obtained very conveniently and quickly.

[0084] Step S24: Combine the new key value with the value value in the key-value pair to form the data to be stored, and insert the data to be stored into the IAVL tree.

[0085] Specifically, the new key value and the value value in the key-value pair can form the data to be stored, newKey-value.

[0086] When the newKey-value pair of data to be stored is formed, it can be inserted into the IAVL tree to achieve persistent storage of the data.

[0087] Among them, the IAVL tree is the underlying storage structure used by the Cosmos framework, which is essentially a variant of Merkle tree + AVL tree.

[0088] Cosmos is a well-known blockchain development framework that allows developers to quickly deploy blockchain systems.

[0089] Merkle trees are the most commonly used underlying storage structure in blockchains, and the root hash can ensure that the data in the entire tree is immutable.

[0090] AVL trees are the first self-balancing binary search trees invented. In an AVL tree, the maximum difference in height between the two subtrees of any node is 1, so it is also called a height-balanced tree.

[0091] IAVL trees are the underlying storage structure used by the Cosmos framework, and are essentially a variant of Merkle trees + AVL trees.

[0092] In one exemplary implementation, see [reference] Figure 3 The step of combining the new key value with the value value in the key-value pair to form the data to be stored, and inserting the data to be stored into the IAVL tree, includes:

[0093] Step S30: Combine the new key value with the value value in the key-value pair to form data to be stored, and cache the data to be stored in memory.

[0094] Step S31: When there are multiple key-value pairs of transaction data cached in the memory, all the data to be stored cached in the memory are inserted into the IAVL tree in batch.

[0095] Specifically, after converting the key-value pairs corresponding to the transaction data into the corresponding newKey-value pairs to be stored, the newKey-value pairs to be stored will be cached in memory first. This way, when the memory caches all the key-value pairs corresponding to the transaction data in the block, the newKey-value pairs corresponding to all the transaction data can be inserted into the IAVL tree in batches at once, thereby saving resource consumption.

[0096] It is understandable that, in another implementation, when a data to be stored, newKey-valueN, is obtained, it can also be immediately inserted into the IAVL tree.

[0097] In one exemplary implementation, after the data to be stored is inserted into the IAVL tree, the IAVL tree can be used to check whether its self-balance has been broken. If the self-balance of the IAVL tree is broken, a self-balancing action is triggered. If the self-balance of the IAVL tree is not broken, a self-balancing action is not triggered.

[0098] This embodiment obtains transaction data from blockchain blocks, where each block contains multiple transaction data. The multiple transaction data are parsed to obtain the contract address and key-value pair corresponding to each transaction data. The hash value of the key in the key-value pair is calculated. The character at a preset position in the hash value is obtained and concatenated with the contract address and the hash value to obtain a new key value. The new key value and the value in the key-value pair are combined to form the data to be stored, and the data to be stored is inserted into an IAVL tree. Using this transaction data storage scheme, the prefix of the data to be stored under the same smart contract can be randomly shuffled into multiple parts. Thus, during the insertion process into the IAVL tree, this data will be randomly assigned to multiple subtrees, effectively reducing the probability of subtree height imbalance, reducing the number of times the IAVL tree triggers self-balancing actions, thereby reducing the consumption of server computing and storage resources and improving blockchain storage performance.

[0099] See Figure 4 The diagram shown is a program block diagram of an embodiment of the transaction data storage device 40 of this application.

[0100] In this embodiment, the transaction data storage device 40 includes a series of computer program instructions stored in a memory. When these computer program instructions are executed by a processor, the imaging function of each embodiment of this application can be implemented. In some embodiments, based on the specific operations implemented by each part of the computer program instructions, the transaction data storage device 40 can be divided into one or more modules. Specifically, the modules that can be divided are as follows:

[0101] The acquisition module 41 is used to acquire transaction data in a block of the blockchain, wherein the block contains multiple transaction data.

[0102] The parsing module 42 is used to parse multiple transaction data to obtain the contract address and key-value pair corresponding to each transaction data.

[0103] Calculation module 43 is used to calculate the hash value of the key value in the key-value pair;

[0104] The concatenation module 44 is used to obtain the character in the preset position of the hash value, and concatenate the character with the contract address and the hash value to obtain a new key value;

[0105] Insertion module 45 is used to combine the new key value with the value value in the key-value pair to form data to be stored, and to insert the data to be stored into the IAVL tree.

[0106] In one exemplary embodiment, the calculation module 43 is further configured to calculate the hash value of the key value in the key-value pair using a preset hash algorithm.

[0107] In one exemplary embodiment, the preset hash algorithm is the SHA-256 algorithm.

[0108] In one exemplary embodiment, the splicing module 44 is further configured to obtain the first character in the hash value, and splice the character with the contract address and the hash value to obtain a new key value.

[0109] In an exemplary embodiment, the insertion module 45 is further configured to combine the new key value with the value in the key-value pair to form data to be stored, and cache the data to be stored in memory; when there are multiple data to be stored corresponding to the key-value pairs of the transaction data cached in memory, all the data to be stored cached in memory are inserted into the IAVL tree in batches.

[0110] In one exemplary embodiment, the transaction data storage device further includes a verification module.

[0111] The verification module is used to verify the signature information of the sender of the transaction data.

[0112] In one exemplary embodiment, the verification module is further configured to verify whether its own balance has been broken through the IAVL tree. If the self-balance of the IAVL tree is broken, a self-balancing action is triggered.

[0113] By acquiring transaction data from blockchain blocks, where each block contains multiple transaction data, and parsing these transaction data to obtain the contract address and key-value pairs corresponding to each transaction data, the hash value of the key value in each key-value pair is calculated. A character at a preset position in the hash value is obtained, and this character is concatenated with the contract address and the hash value to obtain a new key value. This new key value and the value in the key-value pair are combined to form the data to be stored, and the data to be stored is inserted into an IAVL tree. Using this transaction data storage scheme, the prefix of the data to be stored under the same smart contract can be randomly shuffled into multiple parts. Thus, during the insertion process into the IAVL tree, this data will be randomly assigned to multiple subtrees, effectively reducing the probability of subtree height imbalance, reducing the number of times the IAVL tree triggers self-balancing actions, thereby reducing the consumption of server computing and storage resources and improving blockchain storage performance.

[0114] Figure 5This illustration schematically shows a hardware architecture diagram of a computer device 5 suitable for implementing a transaction data storage method according to an embodiment of this application. In this embodiment, the computer device 5 is a device capable of automatically performing numerical calculations and / or information processing according to pre-set or stored instructions. For example, it may be a tablet computer, laptop computer, desktop computer, rack server, blade server, tower server, or cabinet server (including independent servers or server clusters composed of multiple servers), etc. Figure 5 As shown, computer device 5 includes, but is not limited to: a memory 120, a processor 121, and a network interface 122 that can communicate with each other via a system bus. Wherein:

[0115] The memory 120 includes at least one type of computer-readable storage medium, which can be volatile or non-volatile. Specifically, the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (e.g., SD or DX memory), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the memory 120 may be an internal storage module of the computer device 5, such as the hard disk or memory of the computer device 5. In other embodiments, the memory 120 may also be an external storage device of the computer device 5, such as a plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, etc., equipped on the computer device 5. Of course, the memory 120 may also include both the internal storage module and the external storage device of the computer device 5. In this embodiment, the memory 120 is typically used to store the operating system and various application software installed on the computer device 5, such as program code for transaction data storage methods. Furthermore, the memory 120 can also be used to temporarily store various types of data that have already been output or will be output.

[0116] In some embodiments, processor 121 may be a central processing unit (CPU), controller, microcontroller, microprocessor, or other imaging chip. This processor 121 is typically used to control the overall operation of the computer device 5, such as performing control and processing related to data interaction or communication with the computer device 5. In this embodiment, processor 121 is used to run program code stored in memory 120 or process data.

[0117] Network interface 122 may include a wireless network interface or a wired network interface, which is typically used to establish a communication link between computer device 5 and other computer devices. For example, network interface 122 is used to connect computer device 5 to an external terminal via a network, establishing a data transmission channel and communication link between computer device 5 and the external terminal. The network may be an intranet, the Internet, Global System for Mobile Communication (GSM), Wideband Code Division Multiple Access (WCDMA), 4G network, 5G network, Bluetooth, Wi-Fi, or other wireless or wired networks.

[0118] It should be pointed out that, Figure 5 Only computer devices with components 120 to 122 are shown; however, it should be understood that it is not required to implement all of the shown components, and more or fewer components may be implemented instead.

[0119] In this embodiment, the transaction data storage method stored in memory 120 can be divided into one or more program modules and executed by one or more processors (processor 121 in this embodiment) to complete this application.

[0120] This application provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, it implements the steps of the transaction data storage method in the embodiment.

[0121] In this embodiment, the computer-readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (e.g., SD or DX memory), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the computer-readable storage medium can be an internal storage unit of a computer device, such as the hard disk or memory of the computer device. In other embodiments, the computer-readable storage medium can also be an external storage device of the computer device, such as a plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, etc., equipped on the computer device. Of course, the computer-readable storage medium can also include both the internal storage unit and the external storage device of the computer device. In this embodiment, the computer-readable storage medium is typically used to store the operating system and various application software installed on the computer device, such as the program code of the transaction data storage method in the embodiment. In addition, the computer-readable storage medium can also be used to temporarily store various types of data that have been output or will be output.

[0122] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across at least two network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the embodiments of this application. Those skilled in the art can understand and implement this without any creative effort.

[0123] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented using software and a general-purpose hardware platform, or of course, using hardware. Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. The storage medium can be a magnetic disk, optical disk, read-only memory (ROM), or random access memory (RAM), etc.

[0124] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.

Claims

1. A method for storing transaction data, characterized in that, include: Obtain transaction data from blocks in a blockchain, wherein the blocks contain multiple transaction data; The transaction data is parsed to obtain the contract address and key-value pair corresponding to each transaction data. Calculate the hash value of the key value in the key-value pair; Obtain the character in the preset position of the hash value, and concatenate the character with the contract address and the hash value to obtain a new key value; The new key value and the value in the key-value pair are combined to form the data to be stored, and the data to be stored is inserted into the IAVL tree.

2. The transaction data storage method according to claim 1, characterized in that, The calculation of the hash value of the key value in the key-value pair includes: The hash value of the key in the key-value pair is calculated using a preset hash algorithm.

3. The transaction data storage method according to claim 2, characterized in that, The preset hash algorithm is the SHA-256 algorithm.

4. The transaction data storage method according to claim 1, characterized in that, The step of obtaining the character at a preset position in the hash value, and concatenating the character with the contract address and the hash value to obtain a new key value includes: Obtain the first character of the hash value, concatenate the first character with the contract address and the hash value to obtain a new key value.

5. The transaction data storage method according to any one of claims 1 to 4, characterized in that, The step of combining the new key value with the value value in the key-value pair to form the data to be stored, and inserting the data to be stored into the IAVL tree, includes: The new key value and the value in the key-value pair are combined to form the data to be stored, and the data to be stored is cached in memory; When the memory caches multiple key-value pairs corresponding to the transaction data, all the cached data to be stored is inserted into the IAVL tree in batches.

6. The transaction data storage method according to claim 1, characterized in that, Before parsing the transaction data, the process also includes: The signature information of the sender of the transaction data is verified.

7. The transaction data storage method according to claim 1, characterized in that, The method further includes: The IAVL tree is used to check whether its own balance has been broken. If the balance of the IAVL tree is broken, a self-balancing action is triggered.

8. A transaction data storage device, characterized in that, include: The acquisition module is used to acquire transaction data in blocks of the blockchain, wherein the blocks contain multiple transaction data. The parsing module is used to parse multiple transaction data to obtain the contract address and key-value pair corresponding to each transaction data. The calculation module is used to calculate the hash value of the key value in the key-value pair; The concatenation module is used to obtain the character in the preset position of the hash value, and concatenate the character with the contract address and the hash value to obtain a new key value; The insertion module is used to combine the new key value with the value value in the key-value pair to form the data to be stored, and to insert the data to be stored into the IAVL tree.

9. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements the steps of the method according to any one of claims 1 to 7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Data storage method and device, computer readable storage medium and computer equipment

    CN110489421A

  • Data obtaining method and device, computer readable storage medium and computer equipment

    CN110489429A