Data processing method and device based on block chain and storage medium
By mapping the status data characteristic information of the smart contract to the appropriate data source for processing in the blockchain, the performance degradation problem caused by storing smart contract data in a general database is solved, and more efficient data processing is achieved.
Patent Information
- Application Number
- CN202410298059.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-14
- Publication Date
- 2025-09-16
AI Technical Summary
Existing smart contract status data is stored in a general database, which results in a gradual decline in data processing performance as the amount of data increases, and is unable to effectively improve the processing efficiency of smart contract data in the blockchain.
By determining the storage location mapping relationship of the smart contract, it is mapped to the appropriate data source (shared database, independent database or cache) for processing based on the state data feature information of the smart contract, and a query index is established to optimize data processing operations.
It improves the processing performance of smart contract data in the blockchain, especially in reading and writing performance, meets the business needs of different smart contracts, and improves the efficiency and reliability of data processing.
Smart Images

Figure CN120653673A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of blockchain technology, and in particular to a blockchain-based data processing method, device, and storage medium. Background Art
[0002] Nowadays, blockchain technology is being used more and more. Due to the characteristic of blockchain that it only increases and never decreases, as time goes by, the data on the blockchain becomes more and more, and the status data of smart contracts in the blockchain will also become more and more on the chain.
[0003] Currently, the most common method for storing smart contract state data is to store it in a general-purpose database. However, these databases suffer from write amplification, and as the amount of state data continues to increase, data processing performance (e.g., reading and writing data) deteriorates. Therefore, improving the processing performance of smart contract data in blockchains is an urgent issue that needs to be addressed. Summary of the Invention
[0004] The embodiments of the present application provide a blockchain-based data processing method, a data processing device and a storage medium, and a computer program product, which can determine the data source of a smart contract based on the storage location mapping relationship corresponding to the smart contract, and perform data processing on the smart contract data in the data source to obtain a data processing result, thereby effectively improving the processing performance of the smart contract data in the blockchain.
[0005] In one aspect, an embodiment of the present application provides a blockchain-based data processing method, which is applied to a node of a blockchain network, wherein the method includes:
[0006] In response to the data processing instruction, determining a first smart contract of the blockchain, where the first smart contract is any smart contract in the blockchain;
[0007] Obtaining a first storage location mapping relationship corresponding to the first smart contract, and determining a first data source corresponding to the first smart contract based on the first storage location mapping relationship; wherein the first storage location mapping relationship is determined based on characteristic information of the state data of the first smart contract;
[0008] The data processing operation indicated by the data processing instruction is executed using the first data source to obtain a data processing result.
[0009] In one aspect, an embodiment of the present application provides a data processing device, comprising:
[0010] a determining unit, configured to determine, in response to the data processing instruction, a first smart contract on the blockchain, where the first smart contract is any smart contract on the blockchain;
[0011] An acquiring unit, configured to acquire a first storage location mapping relationship corresponding to the first smart contract;
[0012] The determining unit is further configured to determine a first data source corresponding to the first smart contract based on the first storage location mapping relationship; wherein the first storage location mapping relationship is determined based on characteristic information of the state data of the first smart contract;
[0013] A processing unit is configured to utilize the first data source to execute the data processing operation indicated by the data processing instruction to obtain a data processing result.
[0014] On the one hand, an embodiment of the present application provides a server, comprising: a processor, a communication interface, and a memory, wherein the processor, the communication interface, and the memory are interconnected, wherein the memory stores an executable program code, and the processor is used to call the executable program code to implement the blockchain-based data processing method provided in an embodiment of the present application.
[0015] Accordingly, an embodiment of the present application also provides a computer-readable storage medium, which stores computer instructions. When the computer-readable storage medium is executed on a computer, the computer implements the blockchain-based data processing method provided in the embodiment of the present application.
[0016] Accordingly, an embodiment of the present application also provides a computer program product, which includes a computer program or computer instructions. When the computer program or computer instructions are executed by a processor, they are used to implement the blockchain-based data processing method provided in an embodiment of the present application.
[0017] In an embodiment of the present application, the nodes of the blockchain network respond to the data processing instruction and determine the first smart contract of the blockchain, where the first smart contract is any smart contract in the blockchain; the nodes of the blockchain network obtain the first storage location mapping relationship corresponding to the first smart contract, and determine the first data source corresponding to the first smart contract based on the first storage location mapping relationship; wherein the first storage location mapping relationship is determined based on the characteristic information of the state data of the first smart contract; the nodes of the blockchain network use the first data source to perform the data processing operation indicated by the data processing instruction to obtain a data processing result. Through the embodiment of the present application, the nodes of the blockchain network, upon receiving the data processing instruction, can determine the smart contract in the blockchain based on the data processing instruction, thereby obtaining the storage location mapping relationship corresponding to the data of the smart contract, determining the data source of the smart contract based on the storage location mapping relationship, and using the data source to perform the data processing operation indicated by the data processing instruction to obtain a data processing result, thereby effectively improving the processing performance of the smart contract data in the blockchain. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The accompanying drawings herein are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present application, and together with the specification, are used to explain the principles of the present application. In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following is a brief introduction to the drawings required for describing the embodiments. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without inventive work.
[0019] Figure 1 This is a structural diagram of a data processing system provided in an embodiment of the present application;
[0020] Figure 2 This is a flowchart of a blockchain-based data processing method provided in an embodiment of the present application;
[0021] Figure 3 This is a schematic diagram of the structure of a query index of a data manager provided in an embodiment of the present application;
[0022] Figure 4 This is a flowchart of a data query process of a data iterator provided in an embodiment of the present application;
[0023] Figure 5 This is a flow chart of a data range reading process provided by an embodiment of the present application;
[0024] Figure 6 This is a schematic diagram of a data reading process provided by an embodiment of the present application;
[0025] Figure 7 This is a schematic diagram of a data writing process provided by an embodiment of the present application;
[0026] Figure 8 is a structural diagram of a data processing device provided in an embodiment of the present application;
[0027] Figure 9 This is a structural diagram of a server provided in an embodiment of the present application. DETAILED DESCRIPTION
[0028] Exemplary embodiments will be described in detail herein, with examples illustrated in the accompanying drawings. In the following description, when referring to the drawings, identical numerals in different figures represent identical or similar elements, unless otherwise indicated. The embodiments described in the following exemplary embodiments are not intended to represent all embodiments consistent with the present application. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present application, as detailed in the appended claims.
[0029] It should be noted that, in this document, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprising a ..." does not exclude the presence of other identical elements in the process, method, article or device comprising the element. In addition, components, features, and elements with the same name in different embodiments of the present application may have the same meaning or different meanings, and their specific meanings need to be determined by their explanation in the specific embodiment or further combined with the context of the specific embodiment.
[0030] It should be understood that although the terms "first," "second," "third," etc. may be used herein to describe various information, such information should not be limited to these terms. These terms are used solely 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 term "if," as used herein, may be interpreted as "upon," "when," or "in response to a determination." Furthermore, as used herein, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context indicates otherwise. It should be further understood that the terms "comprising" and "including" indicate the presence of the recited features, steps, operations, elements, components, items, types, and / or groups, but do not preclude the presence, occurrence, or addition of one or more other features, steps, operations, elements, components, items, types, and / or groups. The terms "or," "and / or," "including at least one of the following," etc., as used herein, may be interpreted as inclusive, meaning any one or any combination. For example, “comprising at least one of the following: A, B, C” means “any of the following: A; B; C; A and B; A and C; B and C; A and B and C”; and for another example, “A, B or C” or “A, B and / or C” means “any of the following: A; B; C; A and B; A and C; B and C; A and B and C”. An exception to this definition will occur only when a combination of elements, functions, steps or operations are inherently mutually exclusive in some manner.
[0031] It should be understood that, although the various steps in the flowchart in the embodiment of the present application are shown in sequence according to the indication of the arrows, these steps are not necessarily performed in sequence in the order indicated by the arrows. Unless clearly stated herein, the execution of these steps is not strictly limited in order, and they can be performed in other orders. Moreover, at least a portion of the steps in the figure may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily performed at the same time, but can be performed at different times, and their execution order is not necessarily performed in sequence, but can be performed in turn or alternately with at least a portion of other steps or sub-steps or stages of other steps.
[0032] As used herein, the words "if" and "if" may be interpreted as "at the time of" or "when" or "in response to determining" or "in response to detecting," depending on the context. Similarly, the phrases "if it is determined" or "if (stated condition or event) is detected" may be interpreted as "when it is determined" or "in response to the determination" or "when detecting (stated condition or event)" or "in response to detecting (stated condition or event)," depending on the context.
[0033] The following describes a data processing system provided by an embodiment of the present application.
[0034] See also Figure 1 , Figure 1 This is a structural diagram of a data processing system provided in an embodiment of the present application. Figure 1 As shown, the data processing system includes a terminal device 101 and a blockchain network 102. The terminal device 101 may include a smartphone (such as an Android phone, iOS phone, Windows Phone phone, etc.), a desktop computer, a tablet computer, a PDA, a laptop computer, a mobile Internet device (MID) or a wearable device; the nodes in the blockchain network 102 may be an independent physical server, a server cluster or a distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms.
[0035] In one feasible embodiment, a node in blockchain network 102 receives a data processing instruction sent by terminal device 101. The node can determine the smart contract in the blockchain in response to the data processing instruction, obtain the storage location mapping relationship corresponding to the smart contract, determine the data source corresponding to the smart contract based on the storage location mapping relationship, and use the data source to perform the data processing operation indicated by the data processing instruction to obtain a data processing result. The node in blockchain network 102 can be any node in blockchain network 102; the data processing instruction can be a data read instruction, a data write instruction, etc.; and the smart contract can be any smart contract in blockchain network 102. In this embodiment, the node in blockchain network 102 can determine the data source of the smart contract based on the storage location mapping relationship corresponding to the smart contract, and perform data processing on the smart contract data in the data source to obtain a data processing result, effectively improving the processing performance of smart contract data in the blockchain.
[0036] The following describes a data processing method based on blockchain provided in an embodiment of the present application.
[0037] See also Figure 2 , Figure 2 This is a flow chart of a data processing method based on blockchain provided by an embodiment of the present application. The data processing method based on blockchain provided by an embodiment of the present application can be applied to the above Figure 1 The following is an example of applying this method to any node of the blockchain network in the data processing system. Figure 2 As shown, the data processing method includes:
[0038] S201. In response to a data processing instruction, determine a first smart contract of the blockchain, where the first smart contract is any smart contract in the blockchain.
[0039] In this embodiment, a node of the blockchain network receives a data processing instruction and can determine the first smart contract in the blockchain corresponding to the data processing instruction.
[0040] In a feasible embodiment, the node of the blockchain network can be any node in the blockchain network; the first smart contract can be any smart contract in the blockchain.
[0041] S202. Obtain a first storage location mapping relationship corresponding to the first smart contract, and determine a first data source corresponding to the first smart contract based on the first storage location mapping relationship; wherein the first storage location mapping relationship is determined based on characteristic information of status data of the first smart contract.
[0042] In this embodiment, the nodes of the blockchain network can obtain the corresponding first storage location mapping relationship based on the first smart contract, and determine the first data source corresponding to the first smart contract based on the first storage location mapping relationship; wherein the first storage location mapping relationship is determined based on the characteristic information of the status data of the first smart contract.
[0043] In a feasible embodiment, obtaining the first storage location mapping relationship corresponding to the first smart contract may include: determining a query index based on the contract name of the first smart contract; and using the query index to query the first storage location mapping relationship corresponding to the first smart contract from a mapping relationship library managed by a data manager.
[0044] Specifically, a node in the blockchain network may determine a query index based on the contract name of the first smart contract, and use the query index to query a mapping relationship library managed by a data manager for a first storage location mapping relationship corresponding to the first smart contract. Each node in the blockchain network is configured with a data manager, which may manage a mapping relationship library that includes storage location mapping relationships corresponding to each smart contract in the blockchain network.
[0045] See also Figure 3 , Figure 3 This is a schematic diagram of the structure of a query index of a data manager provided by an embodiment of the present application. Figure 3 The data manager can manage database indexes and cache indexes. In the database index, the interval of the total status data can be divided into a first interval, a second interval, and a third interval. The first interval can include smart contract 1, smart contract 2, and smart contract 3. The data source corresponding to smart contract 1 is the general database, the data source corresponding to smart contract 2 is the independent database 1, and the data source corresponding to smart contract 3 is the independent database 2. The storage location mapping relationship between the smart contract and the corresponding database can be stored in the database index file; in the cache index, the total interval can be divided into a fourth interval, a fifth interval, and a sixth interval. The fifth interval includes smart contract 4 and smart contract 5. The data source corresponding to smart contract 4 is the first cache, and the data source corresponding to smart contract 5 is the second cache. The storage location mapping relationship between the smart contract and the corresponding cache can be stored in the cache index file.
[0046] The state data in a blockchain is a key-value pair data set (e.g., State Key-ValueSet). This key-value pair data set can be mapped to an interval, which can be split into different sub-intervals (e.g., the first interval and the second interval mentioned above). The key of the state data can be prefixed with the contract name of the smart contract. For example, the state data of a user account contract (userContract) can be prefixed with userContract. A database index can be a btree structure with the contract name as the key and a specific database that supports persistent storage (e.g., leveldb, badgerdb, pebble, etc.). Finding the specific persistent database corresponding to a smart contract can be done through the database index. Database persistence can be achieved by storing the database index in a database index file (ptree.file). A cache index can be a btree structure with the contract name as the key and the cache that supports memory lookup as the value. Finding the specific custom cache corresponding to a smart contract can be done through the cache index. Cache index persistence is achieved by storing the cache index in a cache index file (mtree.file). Cache indexes can be created by the data manager and can support operations such as query, range query, replace, and update. In this embodiment, the state data can be divided into different interval subsets according to the contract name. These interval subsets can be stored independently, realizing customized storage of state data.
[0047] In a feasible embodiment, when the data manager receives an update instruction for the database index or cache index, it can update the following according to the update instruction: Figure 3 The database index or cache index shown is updated, and the storage location mapping relationship of the updated database index or cache index is written into the database index file or cache index file.
[0048] Specifically, for example, there is a user-level contract (vipContract). The amount of state data corresponding to vipContract is very small, but the read and write performance requirements for the data are high. In this case, the state data of vipContract is stored in a shared database. If the amount of data of other smart contracts in the shared database is relatively large (for example, 1TB), when reading the state data of vipContract, the reading speed will be very slow. By suggesting a custom btree cache in the memory, the state data of vipContract can be cached in the memory, and a storage location mapping relationship between vipContract and the cache can be established at the same time, so that the state data of vipContract can be stored in the corresponding cache according to the storage location mapping relationship. In this embodiment, a cache can be built for smart contracts with high write performance requirements, effectively improving data reading performance.
[0049] In a feasible embodiment, when the data manager is restarted, the manager can obtain the mapping relationship between the smart contract in the database index file and the storage location of the corresponding database, obtain the mapping relationship between the smart contract in the cache index file and the storage location of the corresponding cache, and establish a mapping relationship between the smart contract in the database index file and the storage location of the corresponding database and the smart contract in the cache index file and the storage location of the corresponding cache. Figure 3 The query index shown in FIG. Among them, the data manager restart can be caused by unexpected situations such as power outages and data manager errors. When encountering similar unexpected situations, the query index can be quickly and accurately restored, effectively improving the disaster recovery capability of the data manager.
[0050] In one feasible embodiment, characteristic information of state data of a second smart contract of the blockchain is obtained, where the second smart contract is any smart contract in the blockchain; a second data source corresponding to the second smart contract is determined based on the characteristic information of the state data of the second smart contract; wherein the second data source includes one or more of a shared database, an independent database, and a cache; and a second storage location mapping relationship corresponding to the second smart contract is generated based on the second smart contract and the second data source.
[0051] Specifically, the second smart contract can be a newly added smart contract in the blockchain network. Nodes in the blockchain network can obtain characteristic data of the second smart contract's state data, determine a second data source corresponding to the second smart contract based on the characteristic data of the second smart contract's state data, and generate a second storage location mapping relationship corresponding to the second smart contract based on the second smart contract and the second data source. The second smart contract can be any smart contract in the blockchain; the second data source can include one of a shared database, an independent database, a shared database and a cache, or an independent database and a cache.
[0052] In one feasible embodiment, the process of creating an independent database for a smart contract may be: taking a smart contract (bigContract) with a large amount of state data as an example, the state data of bigContract is large. If it is stored in a shared database, it will affect the data reading and writing performance of other smart contracts in the shared database. An independent database with a custom state (such as badgerDB) can be created for bigContract. The key range of bigContract's state data can be determined to be ["bigContract", "bigContracu"), and the database index of badgerDB can be determined to be bigContract_badgerdb.
[0053] In one feasible embodiment, the process of creating a cache for a smart contract can be as follows: Taking a user account contract (userContract) as an example, assuming that userContract contains 1 million user account data, characterized by more writes than reads, with a read-write ratio of 1:100,000, and a state data volume of 200MB, if the state data of this contract is stored in a shared database, the performance will be poor due to the excessive size of the shared database state data. A custom scoped cache can be constructed for userContract, with a key range of ["userContract", "userContract"), and the cache index of the cache is designated as userContract_cache.
[0054] In a feasible embodiment, if the second data source includes an independent database, an independent database corresponding to the second smart contract is created, and the status data of the second smart contract is stored in the independent database corresponding to the second smart contract; if the second data source includes a cache, a cache corresponding to the second smart contract is created, cache data is determined from the status data of the second smart contract, and the cache data is stored in the cache corresponding to the second smart contract.
[0055] Specifically, when the node in the blockchain determines that the second data source includes an independent database, it can create an independent database corresponding to the second smart contract and store the state data of the second smart contract in the independent database corresponding to the second smart contract; when the node in the blockchain determines that the second data source includes a cache, it can create a cache corresponding to the second smart contract, determine the cache data from the state data of the second smart contract, and store the state data of the second smart contract in the cache corresponding to the second smart contract. In this embodiment, different data sources can be established for different smart contracts based on the characteristic data of the state data, so that smart contracts with higher priorities can obtain independent database resources, thereby ensuring that smart contracts with higher priorities (high data reading and writing performance requirements) can have higher execution performance. During the execution of the smart contract, the database of the smart contract can be flexibly customized according to the business, so that smart contracts with higher read and write data requirements can obtain independent databases.
[0056] See also Figure 7 , Figure 7 This is a flow chart of data writing provided by an embodiment of the present application. Figure 7 As shown, upon receiving a data write instruction, a blockchain node can determine whether the smart contract has an independent database index. If so, the state data is written to the independent database; if not, the state data is written to a shared database. Furthermore, the node can determine whether the smart contract has a cache index. If so, the state data is written to the cache. In this embodiment, when writing the state data of a second smart contract, a blockchain node can write to the shared database, an independent database, or a cache, depending on the second data source included in the second smart contract. This effectively improves the performance of writing state data for the smart contract.
[0057] In a feasible embodiment, the characteristic information includes data reading frequency, data writing frequency, and data volume; determining the second data source corresponding to the second smart contract based on the characteristic information of the status data of the second smart contract includes: determining that the second data source corresponding to the second smart contract includes a shared database or an independent database based on the data writing frequency and data volume of the status data of the second smart contract; if the data reading frequency of the status data of the second smart contract is greater than or equal to a preset first frequency, determining that the second data source corresponding to the second smart contract also includes a cache.
[0058] Specifically, when determining the second data source of the second smart contract, the node in the blockchain can use its corresponding data manager to obtain characteristic information of the status data of the second smart contract. The characteristic information may include data reading frequency, data writing frequency and data volume. Based on the data writing frequency and data volume, it can be determined that the second data source corresponding to the second smart contract includes a shared database or an independent database; when it is determined that the data reading frequency of the status data of the second smart contract is greater than or equal to the preset first frequency, it can be determined that the second data source corresponding to the second smart contract also includes a cache.
[0059] In a feasible embodiment, the characteristic information of the status data of the second smart contract may also include data update amount, data new amount, data reading amount, data compression and redundancy, which can be adaptively adjusted according to different needs, so that the storage and management of status data can be more compatible with different scenarios, thereby achieving a trade-off and balance between cost, function and performance, and effectively improving the diversity and rationality of determining the data source.
[0060] In a feasible embodiment, the determining, based on the data writing frequency and data volume of the status data of the second smart contract, whether the second data source corresponding to the second smart contract includes a shared database or an independent database includes: if the data volume of the status data of the second smart contract is greater than or equal to a preset data volume, determining that the second data source corresponding to the second smart contract includes a first independent database; the first independent database is a fast key-value database; if the data volume of the status data of the second smart contract is less than the preset data volume, and the data writing frequency of the status data of the second smart contract is greater than or equal to a preset second frequency, determining that the second data source corresponding to the second smart contract includes a second independent database; the second independent database is a key-value pair database; if the data volume of the status data of the second smart contract is less than the preset data volume, and the data writing frequency of the status data of the second smart contract is less than the preset second frequency, determining that the second data source corresponding to the second smart contract includes a shared database.
[0061] Specifically, when determining whether the second data source corresponding to the second smart contract includes a shared database or an independent database, the node in the blockchain can use its corresponding data manager to calculate the write frequency and data volume of the state data of the second smart contract. When the data volume of the state data of the second smart contract is greater than or equal to a preset data volume, it can be determined that the second data source corresponding to the second smart contract is stored in the first independent database; when the data volume of the state data of the second smart contract is less than the preset data volume and the data write frequency of the state data of the second smart contract is greater than or equal to a preset second frequency, it can be determined that the second data source corresponding to the second smart contract is stored in the second independent database; when the data volume of the state data of the second smart contract is less than the preset data volume and the data write frequency of the state data of the second smart contract is less than the preset second frequency, it can be determined that the second data source corresponding to the second smart contract is stored in the shared database. The first independent database can be a fast key-value database (such as BadgerDB), the second independent database can be a key-value database (such as LevelDB), and the shared database can store the state data of multiple smart contracts. In this embodiment, the data source (independent database or shared database) of the smart contract's status data can be determined based on the writing frequency and data volume of the smart contract's status data. The status data of smart contracts with a writing frequency lower than the preset frequency and a larger data volume can be stored in an independent database, which can reduce the impact of writing data to the shared database. Moreover, when the data volume of the shared database increases, the writing performance of the independent database will not be affected, thereby effectively improving the writing performance of the smart contract status data in the blockchain network.
[0062] S203: Utilize the first data source to execute the data processing operation indicated by the data processing instruction to obtain a data processing result.
[0063] In this embodiment, the nodes in the blockchain network can use the first data source corresponding to the first smart contract to execute the data processing operation corresponding to the data processing instruction to obtain the data processing result.
[0064] In a feasible embodiment, the data processing instruction includes a data write instruction; the use of the first data source to perform the data processing operation indicated by the data processing instruction to obtain a data processing result includes: obtaining the data to be written carried by the data write instruction; using the data to be written to update the data to be updated in the shared database or independent database included in the first data source; if the first data source also includes a cache, and the data to be updated has a corresponding cache index, then using the data to be written and the cache index to update the data to be updated in the cache.
[0065] Specifically, when the data processing instruction is a data write instruction, the blockchain node can obtain the data to be written carried by the data write instruction, use the data to be written to update the data to be updated in the corresponding database, and, if a corresponding cache index exists for the data to be updated, use the data to be written to update the data to be updated in the corresponding cache. The write instruction can include writing data, replacing data, and deleting data; and updating the data to be updated can include writing, replacing, or deleting the data to be updated.
[0066] In a feasible embodiment, the data processing instruction includes a data reading instruction, and the smart contract corresponding to the data reading instruction can be obtained. The data source is determined based on the smart contract. If the data source includes a cache, the target data indicated by the data reading instruction is obtained from the cache; if the data source includes an independent database or a shared database, the target data indicated by the data reading instruction is obtained from the corresponding independent database or shared database.
[0067] In a feasible embodiment, the data processing instruction includes a data query range; the use of the first data source to perform the data processing operation indicated by the data processing instruction to obtain a data processing result includes: obtaining multiple target data matching the data query range from the first data source; the first data source includes two or more of a shared database, an independent database, and a cache; sorting the multiple target data using the query order indicated by the data query range, and using the sorted multiple target data as the data processing result.
[0068] Specifically, when the data processing instruction includes a data query range, multiple target data in the shared database, independent database and cache can be determined according to the data query range, and the query order indicated by the data query range can be used to sort the multiple target data to obtain the data processing result.
[0069] In one possible embodiment, see Figure 4 , Figure 4 This is a flow chart of a data query process of a data iterator provided in an embodiment of the present application. Figure 4As shown, when the data processing instruction includes a query range, a data iterator can be used to query data, including a first sub-iterator, a second sub-iterator, and a third sub-iterator. Among them, the first sub-iterator, the second sub-iterator, and the third sub-iterator can query an independent database, a general database, and a cache respectively, and import the query results into a data stack. The data iterator then sorts the query results imported by the three sub-iterators in the data stack according to the query order indicated by the query range. In this embodiment, when the data processing instruction includes a query range, multiple sub-iterators can be used to query different data sources, import multiple query results into the data stack, and sort the multiple query results, which effectively improves the readability of the query results.
[0070] In one possible embodiment, see Figure 5 , Figure 5 This is a flow chart of a data range reading process provided by an embodiment of the present application. Figure 5 As shown, when using the data iterator to perform a data range query, you can first determine whether there is data in the data stack; if there is data in the data stack, the data in the data stack will be sorted and taken out; if there is no data in the data stack, the first iterator, the second iterator and the third iterator will be used to query from the corresponding data source and return the query results to the data stack.
[0071] In one possible embodiment, see Figure 6 , Figure 6 This is a flow chart of a data reading process provided by an embodiment of the present application. Figure 6 As shown, when the data query instruction is a data read instruction, it can first determine whether the smart contract has a cache index; if the smart contract has a cache index, the state data is read from the cache; if the smart contract does not have a cache index, the state data is read from the database. In this embodiment, when data is read and a cache index is available, the state data can be read from the cache based on the cache index, effectively improving data reading performance.
[0072] In a feasible embodiment, each node in the blockchain has its own corresponding general database, independent database and cache. When a node writes data to any data source in its general database, independent database and cache, it needs to verify the written data according to the consensus mechanism. When the write conditions are met, the data write operation is executed, ensuring the consistency of the data in the general database, independent database and cache of each node in the blockchain.
[0073] Based on the above embodiments, the beneficial effects of the embodiments of the present application are as follows: after a node in a blockchain receives a data processing instruction, it can determine the smart contract in the blockchain in response to the data processing instruction, obtain the storage location mapping relationship corresponding to the smart contract, determine the data source corresponding to the smart contract based on the storage location mapping relationship, and use the data source to perform the data processing operation indicated by the data processing instruction to obtain a data processing result. Through this embodiment, the storage location mapping relationship between the smart contract and the corresponding data source can be determined based on the data characteristics of the status data of different smart contracts in the blockchain, and a query index can be established based on the storage location mapping relationship of each smart contract. When a data processing instruction is received, the data source can be determined by querying the index, and the data in the data source can be processed using the data processing operation indicated by the data processing instruction, effectively improving the processing performance of smart contract data in the blockchain.
[0074] The following describes a data processing device provided in an embodiment of the present application.
[0075] See also Figure 8 , Figure 8 This is a structural diagram of a data processing device provided in an embodiment of the present application. Figure 8 As shown, the data processing device includes:
[0076] A determining unit 801 is configured to determine, in response to a data processing instruction, a first smart contract on the blockchain, where the first smart contract is any smart contract on the blockchain;
[0077] An acquiring unit 802 is configured to acquire a first storage location mapping relationship corresponding to the first smart contract;
[0078] The determining unit 801 is further configured to determine a first data source corresponding to the first smart contract based on the first storage location mapping relationship; wherein the first storage location mapping relationship is determined based on characteristic information of the state data of the first smart contract;
[0079] The processing unit 803 is configured to utilize the first data source to execute the data processing operation indicated by the data processing instruction to obtain a data processing result.
[0080] In a feasible embodiment, when the acquisition unit 802 obtains the first storage location mapping relationship corresponding to the first smart contract, it is specifically used to: determine a query index based on the contract name of the first smart contract; and use the query index to query the first storage location mapping relationship corresponding to the first smart contract from the mapping relationship library managed by the data manager.
[0081] In a feasible embodiment, the acquisition unit 802 is further used to obtain characteristic information of status data of a second smart contract of the blockchain, where the second smart contract is any smart contract in the blockchain; the determination unit 801 is further used to determine a second data source corresponding to the second smart contract based on the characteristic information of the status data of the second smart contract; wherein the second data source includes one or more of a shared database, an independent database, and a cache; and the processing unit 803 is further used to generate a second storage location mapping relationship corresponding to the second smart contract based on the second smart contract and the second data source.
[0082] In a feasible embodiment, the processing unit 803 is further used to: if the second data source includes an independent database, create an independent database corresponding to the second smart contract, and store the status data of the second smart contract in the independent database corresponding to the second smart contract; if the second data source includes a cache, create a cache corresponding to the second smart contract, determine the cache data from the status data of the second smart contract, and store the cache data in the cache corresponding to the second smart contract.
[0083] In a feasible embodiment, the characteristic information includes data reading frequency, data writing frequency, and data volume; when the determination unit 801 determines the second data source corresponding to the second smart contract based on the characteristic information of the status data of the second smart contract, it is specifically used to: determine, based on the data writing frequency and data volume of the status data of the second smart contract, whether the second data source corresponding to the second smart contract includes a shared database or an independent database; if the data reading frequency of the status data of the second smart contract is greater than or equal to a preset first frequency, determine that the second data source corresponding to the second smart contract also includes a cache.
[0084] In a feasible embodiment, when the determination unit 801 determines, based on the data writing frequency and data volume of the status data of the second smart contract, whether the second data source corresponding to the second smart contract includes a shared database or an independent database, it is specifically used to: if the data volume of the status data of the second smart contract is greater than or equal to a preset data volume, determine that the second data source corresponding to the second smart contract includes a first independent database; the first independent database is a fast key-value database; if the data volume of the status data of the second smart contract is less than the preset data volume, and the data writing frequency of the status data of the second smart contract is greater than or equal to a preset second frequency, determine that the second data source corresponding to the second smart contract includes a second independent database; the second independent database is a key-value pair database; if the data volume of the status data of the second smart contract is less than the preset data volume, and the data writing frequency of the status data of the second smart contract is less than the preset second frequency, determine that the second data source corresponding to the second smart contract includes a shared database.
[0085] In a feasible embodiment, the data processing instruction includes a data write instruction; the processing unit 803 uses the first data source to execute the data processing operation indicated by the data processing instruction, and when obtaining the data processing result, is specifically used to: obtain the data to be written carried by the data write instruction; use the data to be written to update the data to be updated in the shared database or independent database included in the first data source; if the first data source also includes a cache, and the data to be updated has a corresponding cache index, then use the data to be written and the cache index to update the data to be updated in the cache.
[0086] In a feasible embodiment, the data processing instruction includes a data query range; the processing unit 803 uses the first data source to execute the data processing operation indicated by the data processing instruction, and when obtaining the data processing result, is specifically used to: obtain multiple target data matching the data query range from the first data source; the first data source includes two or more of a shared database, an independent database, and a cache; sort the multiple target data using the query order indicated by the data query range, and use the sorted multiple target data as the data processing result.
[0087] In a feasible embodiment, the data processing device provided in the embodiment of the present application can be implemented in software. The data processing device can be stored in a memory. It can be software in the form of a program and a plug-in, and includes a series of units, including a determination unit, an acquisition unit and a processing unit; wherein the determination unit, the acquisition unit and the processing unit are used to implement the blockchain-based data processing method provided in the embodiment of the present application.
[0088] In other feasible embodiments, the data processing device provided in the embodiments of the present application may also be implemented in a combination of software and hardware. As an example, the data processing device provided in the embodiments of the present application may be a processor in the form of a hardware decoding processor, which is programmed to execute the blockchain-based data processing method provided in the embodiments of the present application. For example, the processor in the form of a hardware decoding processor may adopt one or more application-specific integrated circuits (ASICs), DSPs, programmable logic devices (PLDs), complex programmable logic devices (CPLDs), field-programmable gate arrays (FPGAs), or other electronic components.
[0089] The following introduces a server provided in an embodiment of the present application.
[0090] See Figure 9 , Figure 9 This is a schematic diagram of the structure of a server provided in an embodiment of the present application. Figure 9 The server in the illustrated embodiment may include one or more processors 901, one or more communication interfaces 902, and a memory 903. The processors 901, communication interfaces 902, and memory 903 are connected via a bus 904. The memory 903 is used to store computer programs, which include program instructions. The processor 901 is used to execute the program instructions stored in the memory 903. By running the executable program code in the memory 903, the processor 901 performs the following operations:
[0091] In response to the data processing instruction, determining a first smart contract of the blockchain, where the first smart contract is any smart contract in the blockchain;
[0092] Obtaining a first storage location mapping relationship corresponding to the first smart contract, and determining a first data source corresponding to the first smart contract based on the first storage location mapping relationship; wherein the first storage location mapping relationship is determined based on characteristic information of the state data of the first smart contract;
[0093] The data processing operation indicated by the data processing instruction is executed using the first data source to obtain a data processing result.
[0094] In a feasible embodiment, the obtaining of the first storage location mapping relationship corresponding to the first smart contract. The processor 901 is further configured to: determine a query index based on the contract name of the first smart contract; and use the query index to query the first storage location mapping relationship corresponding to the first smart contract from a mapping relationship library managed by a data manager.
[0095] In a feasible embodiment, the processor 901 is further used to: obtain characteristic information of status data of a second smart contract in the blockchain, where the second smart contract is any smart contract in the blockchain; determine a second data source corresponding to the second smart contract based on the characteristic information of the status data of the second smart contract; wherein the second data source includes one or more of a shared database, an independent database, and a cache; and generate a second storage location mapping relationship corresponding to the second smart contract based on the second smart contract and the second data source.
[0096] In a feasible embodiment, the processor 901 is further used to: if the second data source includes an independent database, create an independent database corresponding to the second smart contract, and store the status data of the second smart contract in the independent database corresponding to the second smart contract; if the second data source includes a cache, create a cache corresponding to the second smart contract, determine cache data from the status data of the second smart contract, and store the cache data in the cache corresponding to the second smart contract.
[0097] In one feasible embodiment, the characteristic information includes data read frequency, data write frequency, and data volume; and the second data source corresponding to the second smart contract is determined based on the characteristic information of the status data of the second smart contract. The processor 901 is further configured to: determine, based on the data write frequency and data volume of the status data of the second smart contract, whether the second data source corresponding to the second smart contract includes a shared database or an independent database; and if the data read frequency of the status data of the second smart contract is greater than or equal to a preset first frequency, determine that the second data source corresponding to the second smart contract also includes a cache.
[0098] In a feasible embodiment, the second data source corresponding to the second smart contract is determined to include a shared database or an independent database based on the data write frequency and data volume of the status data of the second smart contract. The processor 901 is further configured to: if the data volume of the status data of the second smart contract is greater than or equal to a preset data volume, determine that the second data source corresponding to the second smart contract includes a first independent database; the first independent database is a fast key-value database; if the data volume of the status data of the second smart contract is less than the preset data volume, and the data write frequency of the status data of the second smart contract is greater than or equal to a preset second frequency, determine that the second data source corresponding to the second smart contract includes a second independent database; the second independent database is a key-value database; if the data volume of the status data of the second smart contract is less than the preset data volume, and the data write frequency of the status data of the second smart contract is less than the preset second frequency, determine that the second data source corresponding to the second smart contract includes a shared database.
[0099] In one feasible embodiment, the data processing instruction includes a data write instruction; the first data source is used to execute the data processing operation indicated by the data processing instruction to obtain a data processing result. The processor 901 is further configured to: obtain the data to be written carried by the data write instruction; use the data to be written to update the data to be updated in the shared database or independent database included in the first data source; and if the first data source also includes a cache and the data to be updated has a corresponding cache index, use the data to be written and the cache index to update the data to be updated in the cache.
[0100] In one feasible embodiment, the data processing instruction includes a data query range; the data processing operation indicated by the data processing instruction is performed using the first data source to obtain a data processing result. The processor 901 is further configured to: obtain multiple target data matching the data query range from the first data source; the first data source includes two or more of a shared database, an independent database, and a cache; sort the multiple target data using the query order indicated by the data query range, and use the sorted multiple target data as the data processing result.
[0101] It should be understood that in the embodiment of the present application, the processor 901 may be a central processing unit (CPU), and the processor may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor, etc.
[0102] Those skilled in the art will appreciate that all or part of the processes in the above-described method embodiments can be implemented by instructing the relevant hardware through a computer program. The aforementioned computer program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes in the above-described method embodiments. The aforementioned storage medium can be a magnetic disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).
[0103] The method steps in the embodiments of the present application can be adjusted in sequence, combined, and deleted according to actual needs.
[0104] The units in the embodiments of the present application can be merged, divided, and deleted according to actual needs.
[0105] In the embodiments of the present application, the term "module" or "unit" refers to a computer program or a part of a computer program that has a predetermined function and works together with other related parts to achieve a predetermined goal, and can be implemented in whole or in part by using software, hardware (such as processing circuits or memories) or a combination thereof. Similarly, a processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be part of an overall module or unit that includes the function of the module or unit.
[0106] In this application, the same or similar terminology, technical solutions and / or application scenario descriptions are generally only described in detail the first time they appear. When they appear again later, they are generally not repeated for the sake of brevity. When understanding the technical solutions and other contents of this application, for the same or similar terminology, technical solutions and / or application scenario descriptions that are not described in detail later, you can refer to the previous relevant detailed descriptions.
[0107] In this application, the description of each embodiment has its own focus. For parts that are not described or recorded in detail in a certain embodiment, please refer to the relevant description of other embodiments.
[0108] The various technical features of the technical solution of this application can be combined arbitrarily. In order to make the description concise, not all possible combinations of the various 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 application.
[0109] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When software is used for implementation, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function according to the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website, computer, server or data center to another website, computer, server or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrations. The available medium can be a magnetic medium (e.g., a floppy disk, a storage disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state storage disk Solid State Disk (SSD)).
[0110] The above are only preferred embodiments of the present application and do not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A data processing method based on blockchain, characterized in that: Applied to a node of a blockchain network, the method comprises: In response to the data processing instruction, determining a first smart contract of the blockchain, where the first smart contract is any smart contract in the blockchain; Obtaining a first storage location mapping relationship corresponding to the first smart contract, and determining a first data source corresponding to the first smart contract based on the first storage location mapping relationship; wherein the first storage location mapping relationship is determined based on characteristic information of the state data of the first smart contract; The data processing operation indicated by the data processing instruction is executed using the first data source to obtain a data processing result.
2. The method according to claim 1, characterized in that The obtaining of a first storage location mapping relationship corresponding to the first smart contract includes: Determining a query index based on the contract name of the first smart contract; The query index is used to query the first storage location mapping relationship corresponding to the first smart contract from the mapping relationship library managed by the data manager.
3. The method according to claim 1, characterized in that The method further comprises: Obtain characteristic information of status data of a second smart contract on the blockchain, where the second smart contract is any smart contract on the blockchain; Determining a second data source corresponding to the second smart contract based on characteristic information of the state data of the second smart contract; wherein the second data source includes one or more of a shared database, an independent database, and a cache; Generate a second storage location mapping relationship corresponding to the second smart contract based on the second smart contract and the second data source.
4. The method according to claim 3, characterized in that The method further comprises: If the second data source includes an independent database, create an independent database corresponding to the second smart contract, and store the status data of the second smart contract in the independent database corresponding to the second smart contract; If the second data source includes a cache, a cache corresponding to the second smart contract is created, cache data is determined from the status data of the second smart contract, and the cache data is stored in the cache corresponding to the second smart contract.
5. The method according to claim 3, characterized in that The characteristic information includes data reading frequency, data writing frequency, and data volume; and determining the second data source corresponding to the second smart contract based on the characteristic information of the status data of the second smart contract includes: Determining, based on a data write frequency and data volume of the status data of the second smart contract, whether the second data source corresponding to the second smart contract includes a shared database or an independent database; If the data reading frequency of the status data of the second smart contract is greater than or equal to the preset first frequency, it is determined that the second data source corresponding to the second smart contract also includes a cache.
6. The method according to claim 5, characterized in that The determining, based on the data writing frequency and data volume of the status data of the second smart contract, that the second data source corresponding to the second smart contract includes a shared database or an independent database comprises: If the amount of state data of the second smart contract is greater than or equal to a preset amount of data, determining that the second data source corresponding to the second smart contract includes a first independent database; the first independent database is a fast key-value database; If the data volume of the state data of the second smart contract is less than the preset data volume, and the data writing frequency of the state data of the second smart contract is greater than or equal to the preset second frequency, it is determined that the second data source corresponding to the second smart contract includes a second independent database; and the second independent database is a key-value pair database; If the data volume of the status data of the second smart contract is less than the preset data volume, and the data writing frequency of the status data of the second smart contract is less than the preset second frequency, it is determined that the second data source corresponding to the second smart contract includes a shared database.
7. The method according to any one of claims 1 to 6, characterized in that The data processing instruction includes a data write instruction; and the step of using the first data source to perform the data processing operation indicated by the data processing instruction to obtain a data processing result includes: Obtaining the data to be written carried by the data writing instruction; Using the data to be written, update the data to be updated in the common database or the independent database included in the first data source; If the first data source further includes a cache, and the data to be updated has a corresponding cache index, the data to be updated in the cache is updated using the data to be written and the cache index.
8. The method according to any one of claims 1 to 6, characterized in that The data processing instruction includes a data query range; and using the first data source to perform the data processing operation indicated by the data processing instruction to obtain a data processing result includes: Acquire multiple target data matching the data query range from the first data source; the first data source includes two or more of a shared database, an independent database, and a cache; The plurality of target data are sorted using the query order indicated by the data query range, and the sorted plurality of target data are used as data processing results.
9. A data processing device, characterized in that: The device comprises: a determining unit, configured to determine, in response to the data processing instruction, a first smart contract on the blockchain, where the first smart contract is any smart contract on the blockchain; An acquiring unit, configured to acquire a first storage location mapping relationship corresponding to the first smart contract; The determining unit is further configured to determine a first data source corresponding to the first smart contract based on the first storage location mapping relationship; wherein the first storage location mapping relationship is determined based on characteristic information of the state data of the first smart contract; A processing unit is configured to utilize the first data source to execute the data processing operation indicated by the data processing instruction to obtain a data processing result.
10. A server, characterized in that: include: A processor, a communication interface, and a memory, wherein the processor, the communication interface, and the memory are interconnected, wherein the memory stores an executable program code, and the processor is used to call the executable program code to implement the blockchain-based data processing method according to any one of claims 1 to 8.
11. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer instructions, which, when executed on a computer, enable the computer to implement the blockchain-based data processing method according to any one of claims 1 to 8.
12. A computer program product, characterized in that The computer program product includes a computer program or computer instructions, which, when executed by a processor, are used to implement the blockchain-based data processing method according to any one of claims 1 to 8.