Blockchain state data processing method and apparatus, and electronic device
By setting up a temporary state data validity period storage contract in the blockchain system, expired data can be automatically filtered and released, solving the problem of cumbersome blockchain state data management and realizing the automated release and efficient management of state data.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- TENCENT TECHNOLOGY (SHENZHEN) CO LTD
- Filing Date
- 2024-12-12
- Publication Date
- 2026-06-12
AI Technical Summary
In existing technologies, the modification and release of blockchain state data are cumbersome and inflexible. In particular, the management efficiency of temporary state data is low, and users need to manually initiate transactions, which leads to the expansion of the node world state.
In a blockchain system, a contract is set up to store the validity period of temporary state data. This contract records the validity period of temporary state data and automatically filters and releases expired data, reducing the expansion of the state tree and achieving automated management of state data.
It enables the automatic release of temporary state data, reduces the storage burden on nodes, improves the flexibility and efficiency of state data management, and reduces the need for manual transactions.
Smart Images

Figure CN122196076A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of blockchain technology, and in particular to a method, apparatus and electronic device for processing blockchain state data. Background Technology
[0002] Blockchain state data refers to the global world state maintained by blockchain nodes, which mainly includes user balances, contract code, and contract state variables. In current technology, changes to blockchain state data are triggered by transactions; however, since state writes are assumed to be permanent, state storage flexibility is low, leading to rapid expansion of the node's world state. Releasing state data in the blockchain currently requires users to manually send transactions combined with code to release permanently stored contract state data, which is cumbersome and inefficient. Furthermore, when users have time-window state storage needs—that is, they want a certain state variable to be valid only within a specific time frame—they need to first send a transaction to write the state, and then send another transaction to clear the state when it is no longer needed. This method of contract state management and release is not flexible enough.
[0003] Therefore, there is a need to provide a solution for processing blockchain state data, which can at least partially solve the above problems. Summary of the Invention
[0004] This specification provides a method, apparatus, device, storage medium, and computer program product for processing blockchain state data, which realizes the automatic release of temporary state data and improves the management flexibility and release efficiency of blockchain state data.
[0005] On one hand, embodiments of this specification provide a method for processing blockchain state data. The blockchain system includes a temporary state data validity period storage contract, which records the validity period of the temporary state data. The method includes:
[0006] The temporary state data validity period storage contract is invoked, and the state variables in the temporary state data validity period storage contract are traversed to obtain the validity period of each temporary state data in the state variables; the state variables include the contract address, key value and validity period corresponding to each temporary state data; the key value is used to represent the storage location of the temporary state data.
[0007] The temporary state data whose validity period exceeds the timestamp of the current data release block is used as the data to be released.
[0008] Based on the contract address and key value in the state variable of the data to be released, delete the state value at the position corresponding to the key value in the state tree of the blockchain system.
[0009] On the other hand, a device for processing blockchain state data is provided. The blockchain system includes a temporary state data validity period storage contract, which records the validity period of the temporary state data. The device includes:
[0010] The validity period acquisition module is used to call the temporary state data validity period storage contract, traverse the state variables in the temporary state data validity period storage contract, and obtain the validity period of each temporary state data in the state variables; the state variables include the contract address, key value, and validity period corresponding to each temporary state data; the key value is used to represent the storage location of the temporary state data.
[0011] The data to be released determination module is used to take temporary state data whose validity period exceeds the timestamp of the current data release block as data to be released;
[0012] The state data release module is used to delete the state value at the position corresponding to the key value in the state tree of the blockchain system based on the contract address and key value in the state variable of the data to be released.
[0013] On the other hand, an electronic device is provided, including: a processor;
[0014] Memory used to store the processor's executable instructions;
[0015] The processor is configured to execute the instructions to implement the blockchain state data processing method described in any of the preceding claims.
[0016] On the other hand, a computer-readable storage medium is provided, which, when the instructions in the storage medium are executed by the processor of an electronic device, enables the electronic device to perform any of the above-described methods for processing blockchain state data.
[0017] On the other hand, a computer program product or computer program is provided, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the blockchain state data processing methods provided in the various optional implementations described above.
[0018] The blockchain state data processing methods, apparatus, devices, storage media, and computer program products provided in the embodiments of this specification have the following technical effects:
[0019] The blockchain state data processing method provided in this specification involves setting up a temporary state data expiration storage contract within the blockchain system. This contract stores the expiration dates of various temporary state data items. Based on these expiration dates, expired temporary state data can be automatically filtered out and released, reducing the expansion of the state tree and lowering the storage burden on nodes. Simultaneously, the state data release process is automated without requiring manual transaction initiation by the user, achieving automated state data release, reducing the cost of state data management, and improving the flexibility and efficiency of state data management. Attached Figure Description
[0020] To more clearly illustrate the technical solutions and advantages in the embodiments or prior art of this specification, the drawings used in the description of the embodiments or prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this specification. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0021] Figure 1 This is a flowchart illustrating a method for processing blockchain state data according to one embodiment of this specification.
[0022] Figure 2 This is a schematic diagram illustrating the principle of temporary state data release in one embodiment of this specification;
[0023] Figure 3 This is a flowchart illustrating a method for writing temporary state data in one embodiment of this specification.
[0024] Figure 4 This is a schematic diagram illustrating the principle of temporary state data reading and writing in one embodiment of this specification;
[0025] Figure 5 This is a schematic diagram of the process for reading temporary state data in one embodiment of this specification;
[0026] Figure 6 This is a schematic diagram of the structure of a blockchain state data processing device provided in the embodiments of this specification;
[0027] Figure 7 This is a block diagram of an electronic device for processing blockchain state data, provided in the embodiments of this specification.
[0028] Figure 8 This is a block diagram of another electronic device for processing blockchain state data, provided in the embodiments of this specification. Detailed Implementation
[0029] The technical solutions in the embodiments of this specification will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this specification, and not all embodiments. Based on the embodiments in this specification, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this specification.
[0030] It should be noted that the terms "first," "second," etc., in the description, claims, and accompanying drawings of the embodiments in this specification are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or server that includes a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or devices.
[0031] This specification relates to blockchain technology, a novel application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanisms, and encryption algorithms. Essentially, a blockchain is a decentralized database, a chain of data blocks linked together using cryptographic methods. Each data block contains information about a batch of network transactions, used to verify the validity of the information (anti-counterfeiting) and generate the next block. A blockchain can include an underlying platform, a platform product service layer, and an application service layer.
[0032] The underlying blockchain platform can include modules for user management, basic services, smart contracts, and operational monitoring. The user management module is responsible for managing the identity information of all blockchain participants, including maintaining public and private key generation (account management), key management, and maintaining the correspondence between user identities and blockchain addresses (access management). Under authorization, it also monitors and audits transactions of certain real identities and provides risk control rule configuration (risk control audit). The basic services module is deployed on all blockchain node devices to verify the validity of business requests. After consensus is reached on valid requests, they are recorded in storage. For a new business request, the basic services first perform interface adaptation parsing and authentication (interface adaptation), and then encrypt the business information using a consensus algorithm (consensus management). After encryption, the data is transmitted completely and consistently to the shared ledger (network communication) and recorded and stored. The smart contract module is responsible for contract registration, issuance, triggering, and execution. Developers can define contract logic using a programming language and publish it to the blockchain (contract registration). According to the contract terms, the key or other events are invoked to trigger execution and complete the contract logic. It also provides functions for contract upgrades and cancellations. The operation and monitoring module is mainly responsible for deployment, configuration modification, contract settings, cloud adaptation, and real-time status visualization output during product release, such as alarms, network status monitoring, and node device health status monitoring.
[0033] The platform's product service layer provides the basic capabilities and implementation frameworks for typical applications. Developers can leverage these basic capabilities, along with the specific characteristics of their business needs, to implement blockchain-based business logic. The application service layer provides blockchain-based application services to business stakeholders.
[0034] Smart contracts can be understood as computer programs running on a distributed ledger (i.e., blockchain) with pre-defined rules, states, and conditional responses. They encapsulate, verify, and execute complex behaviors of distributed nodes to complete information exchange, value transfer, and asset management. Based on the distributed architecture and consensus algorithms of blockchain, smart contracts allow mutually distrustful parties to complete transactions without the need for any trusted third-party intermediaries or authorities. Furthermore, digital smart contracts can be flexibly embedded in various tangible or intangible assets, transactions, and data to achieve proactive or passive asset and information management and control, gradually building programmable smart assets and systems.
[0035] State data refers to the global world state maintained by blockchain nodes, mainly including user balances, contract code, and contract state variables. Generally, changes to blockchain state data are triggered by transactions. Whether writing or releasing blockchain state data, users need to submit transactions. This makes the management of blockchain state data inflexible and cumbersome.
[0036] The blockchain state data processing method in the embodiments of this specification can set an expiration period when writing state data, thereby realizing temporary storage of state data. Furthermore, it can read and release state data based on the expiration period. When reading state data, it is not necessary to manually trigger transactions, which improves the flexibility and convenience of state data management.
[0037] The following describes a method for processing blockchain state data according to an embodiment of this specification. Figure 1 This is a flowchart illustrating a method for processing blockchain state data according to one embodiment of this specification. This specification provides method operation steps as shown in the embodiment or flowchart, but based on conventional or non-inventive labor, more or fewer operation steps may be included. The order of steps listed in the embodiment is merely one possible execution order among many and does not represent the only possible execution order. In actual system or server products, the method can be executed sequentially according to the embodiment or the accompanying drawings, or in parallel (e.g., in a parallel processor or multi-threaded processing environment). This method can be applied to terminals such as computers, tablets, smartphones, smart wearable devices, and in-vehicle devices. Of course, it can also be applied to servers as needed; this specification does not specifically limit this application. Specifically, as shown in the following... Figure 1 As shown, the method may include:
[0038] S102: Call the temporary state data validity period storage contract, traverse the state variables in the temporary state data validity period storage contract, and obtain the validity period of each temporary state data in the state variables; the state variables include the contract address, key value and validity period corresponding to each temporary state data; the key value is used to represent the storage location of the temporary state data.
[0039] In the specific implementation process Figure 2 This is a schematic diagram illustrating the principle of temporary state data release in one embodiment of this specification, as shown below. Figure 2As shown, the Ethereum Virtual Machine (EVM), also known as the Ethereum Virtual Machine, can be understood as the execution engine of Ethereum's smart contracts. It is responsible for executing transactions initiated by users and modifying the state of users and contracts. Transaction execution essentially runs on the virtual machine. At any given moment, it reads an instruction from the instruction stack step by step and executes state changes, calculations, and other operations according to the virtual machine's preset instruction logic. Essentially, it is a stack-based virtual machine with multiple preset instructions, including computation and storage instructions, capable of reading, writing, and calculating the world state. The world state is the set of states arranged according to a Merkel-Patricia tree, representing the actual execution of transactions. The states of all external accounts and smart contracts are called the world state. This embodiment primarily focuses on the state of smart contracts. In this embodiment, a system contract, namely a temporary state data validity period storage contract, can also be set in the blockchain system. This contract is mainly responsible for recording the storage validity period of each contract's temporary state data, helping nodes release expired data.
[0040] Temporary state data can be understood as state data that is valid for a certain time range and expires after that time range. When it is necessary to release temporary state data, the temporary state data validity period storage contract can be invoked. This contract iterates through the state variables and retrieves the validity period of the temporary state data for each state variable. The state variables can include the contract address, key, and validity period corresponding to each piece of temporary state data. The key represents the storage location of the temporary state data. The contract address is the unique identifier of the smart contract on the blockchain. Users can interact with the smart contract through the contract address, such as querying the contract status, sending transaction requests, and calling functions within the contract. The validity period can be in the form of a time window, including a start time and an end time.
[0041] S104: Treat temporary state data whose validity period exceeds the timestamp of the current block to be released as data to be released.
[0042] In the specific implementation process, after obtaining the validity period of each temporary state data in the state variables stored in the temporary state data validity period storage contract, the validity period can be compared with the timestamp of the current block where the data is released. Temporary state data whose validity period exceeds the timestamp of the current block where the data is released is designated as data to be released. Here, "current block where the data is released" can be understood as the current block in which data release processing is being performed. In the embodiments of this specification, the validity period of temporary state data can be written into the temporary state data validity period storage contract, and expired temporary state data can be automatically identified based on this validity period.
[0043] S106: Based on the contract address and key value in the state variable of the data to be released, delete the state value at the position corresponding to the key value in the state tree of the blockchain system.
[0044] In the specific implementation process, after filtering out the data to be released, the state value corresponding to the key value recorded in the state variable of the data to be released can be deleted from the state tree of the blockchain system, thereby releasing the data to be released from the blockchain system and avoiding state bloat in the node world. After obtaining the data to be released, all the data to be released can be treated as a set called Data. rrlease When releasing data, you can iterate through the Data collection. release For each contract address and key-value pair of data to be released, the data corresponding to the key in the state tree is pruned, as shown below:
[0045]
[0046] Here, State can be understood as the world state maintained by the MPT (Multi-Level Tree), State[Contract] can be understood as the world state corresponding to the contract address Contract, and DELETE means deleting the state value corresponding to the key in the MPT tree.
[0047] In some embodiments of this specification, after deleting the state value at the position corresponding to the key value in the state tree of the blockchain, the method further includes:
[0048] Call the temporary state data expiration storage contract to set the expiration date in the state variable corresponding to the data to be released to null.
[0049] In the specific implementation process, after deleting the state value corresponding to the data to be released from the state tree, the temporary state data validity period storage contract can be called to set the validity period in the state variable corresponding to the data to be released to empty, such as setting the validity period to 0 or clearing it directly. This can avoid repeated processing of the data to be released in the next data release, reduce the amount of data processing, improve the data processing speed, and at the same time, release the storage space of the temporary state data validity period storage contract, avoiding resource waste.
[0050] The blockchain state data processing method provided in this specification involves setting up a temporary state data expiration storage contract within the blockchain system. This contract stores the expiration dates of various temporary state data items. Based on these expiration dates, expired temporary state data can be automatically filtered out and released, reducing the expansion of the state tree and lowering the storage burden on nodes. Simultaneously, the state data release process is automated without requiring manual transaction initiation by the user, achieving automated state data release, reducing the cost of state data management, and improving the flexibility and efficiency of state data management.
[0051] In some embodiments of this specification, the state variables include block state variables and timestamp state variables; temporary state data whose validity period exceeds the timestamp of the current block to be released is used as data to be released, including:
[0052] When iterating through the block state variables in the temporary state data validity period storage contract, the validity period of the temporary state data is compared with the block height of the current block where the data is released. If the end point of the time in the validity period of the temporary state data is less than the block height, the temporary state data is treated as data to be released.
[0053] When iterating through the timestamp state variables in the temporary state data validity storage contract, the validity period of the temporary state data is compared with the timestamp of the data release in the current block. If the end point of the time in the validity period of the temporary state data is less than the timestamp of the data release in the current block, then the temporary state data is treated as data to be released.
[0054] In practical implementation, because each block height in the blockchain has a timestamp, the block height can also be used to represent time. In this embodiment, when writing temporary state data, the state variables corresponding to the temporary state data can be divided into block state variables and timestamp state variables based on the type of the temporary state data's validity period. Block state variables can be understood as the block state variables corresponding to temporary state data whose validity period is set with the block height, while timestamp state variables can be understood as the block state variables corresponding to temporary state data whose validity period is set with the system time. In this embodiment, when releasing data, the state variables can be traversed according to their type. When traversing the block state variables in the temporary state data validity period storage contract, the validity period of the temporary state data corresponding to the block state variable can be compared with the block height of the current block where the data is released. If the end point of the time in the validity period of the temporary state data is less than the block height of the current block where the data is released, it indicates that the temporary state data has expired and is treated as data to be released. When iterating through the timestamp state variables in the temporary state data validity storage contract, the validity period of the timestamp state variables can be compared with the timestamp of the data release in the current block. If the end point of the validity period of the temporary state data is less than the timestamp of the data release in the current block, it means that the temporary state data has expired and will be treated as data to be released.
[0055] This specification provides two dimensions for setting the validity period of temporary states: block height and timestamp. Both block height and timestamp can be used to identify whether temporary state data has expired, thereby enabling the automatic release of temporary state data.
[0056] In some embodiments of this specification, before invoking the temporary state data validity period storage contract and traversing the state variables in the temporary state data validity period storage contract, the method further includes:
[0057] The block height of the blockchain is retrieved at preset intervals.
[0058] Calculate the distance between the block height of the blockchain and the block height of the last data release. If the distance is greater than or equal to the preset height, call the temporary state data validity period storage contract and traverse the state variables in the temporary state data validity period storage contract.
[0059] In the specific implementation process, the current block height of the blockchain can be obtained every preset time interval. The distance between this block height and the block height at the time of the last data release can be calculated. If the distance is greater than or equal to the preset height, the temporary state data is released, the temporary state data validity period storage contract is invoked, and the state variables in the temporary state data validity period storage contract are traversed. If the distance between the calculated block height of the current block and the block height at the time of the last data release is less than the preset height, it means that the last released block is relatively close, and data release is not yet necessary. A comparison can be performed every preset time interval.
[0060] In this embodiment, the block height of the blockchain is obtained at preset intervals. Based on the block height and the block height at the time of the last data release, it is determined whether the data release requirements are met. Data release is performed only when the block height at the time of the last data release reaches the preset height. This achieves data release every certain block height, i.e., every K blocks. This avoids the storage burden caused by nodes frequently releasing state data (frequent disk reads) and ensures the stability of the blockchain system performance.
[0061] Figure 3 This is a flowchart illustrating a method for writing temporary state data in one embodiment of this specification, as shown below. Figure 3 As shown in some embodiments of this specification, a method for writing temporary state data can also be provided, which may include the following steps:
[0062] S302: Write the corresponding write contract code for temporary state data into the smart contract of the blockchain system; the write contract code includes the value and validity period of the temporary state data.
[0063] In practical implementation, when a temporary state variable needs to be stored in the blockchain, the corresponding write contract code for the temporary state data can be written into the smart contract of the blockchain system. The write contract code includes the value and validity period of the temporary state data. In the embodiments of this specification, smart contracts support temporary state writing based on time windows. That is, users can request the temporary writing of a certain state variable by writing the validity period of the temporary state data into the contract code of the smart contract. The validity period can take the form of a time window, including a start time and an end time. The value of the temporary state data can be determined according to actual needs, such as the user's balance.
[0064] S304: Execute the write contract code based on the temporary write instruction pre-stored in the smart contract, call the temporary state data validity period storage contract in the blockchain system, and store the state variables corresponding to the temporary state data in the temporary state data validity period storage contract; the temporary write instruction is used to temporarily store the world state according to the given time window.
[0065] In the specific implementation process Figure 4 This is a schematic diagram illustrating the principle of temporary state data reading and writing in one embodiment of this specification, as shown below. Figure 4 As shown, the meanings of the smart contract virtual machine (EVM), the temporary state data validity storage contract, and the world state are the same as those mentioned above. Figure 2 The meanings are the same and will not be repeated here. In this embodiment, two instructions can be added to the EVM: the temporary write instruction TSTORE and the temporary read instruction TSLOAD. TSTORE can be used to temporarily store the world state according to a user-given time window, while TSLOAD can be used to read the temporary state data based on the current time. In this embodiment, a system contract, namely a temporary state data validity period storage contract, can also be set up in the blockchain system. This contract is mainly responsible for recording the storage validity period of the temporary state data for each contract, which can help nodes release expired data.
[0066] After a user writes the write contract code corresponding to temporary state data through a smart contract, the pre-stored temporary write instructions in the smart contract can automatically convert the contract code into a TSTORE instruction, which is then executed in the EVM. When executing the write contract code based on the TSTORE instruction in the EVM, the temporary state data validity period storage contract can be invoked. This contract stores the state variables corresponding to the temporary state data, including the contract address, key, and validity period of the temporary state data. The key represents the storage location of the temporary state data.
[0067] S306: Write the value of the temporary state data at the position corresponding to the key value of the temporary state data.
[0068] In the specific implementation process, after writing the expiration date of the temporary state data into the temporary state data expiration date storage contract based on the TSTORE instruction, the value of the temporary state data can be written to the position corresponding to the key value, thus completing the writing of the temporary state data.
[0069] The blockchain state data processing method provided in this specification establishes a temporary state data validity period storage contract in the blockchain system and pre-writes temporary write instructions in the smart contract. When temporary state data needs to be written, based on the temporary write instruction, the temporary state data validity period storage contract can be invoked to write the validity period of the temporary state data into the temporary state data validity period storage contract, and then the value of the temporary state data is written to the corresponding position, thus realizing the temporary storage of state data. Furthermore, based on the validity period of each state data recorded in the temporary state data validity period storage contract, the state data can be automatically released after its validity period expires, avoiding state inflation in the node world. Moreover, subsequent reading and releasing of state data can be achieved based on the validity period of the temporary state data without manually triggering transactions, improving the flexibility and convenience of state data management.
[0070] In some embodiments of this specification, based on the validity period of the temporary state data, the state variable corresponding to the temporary state data is written into the temporary state data validity period storage contract, including:
[0071] Get the timestamp of the data being written to the current block;
[0072] If the end time of the validity period of the temporary state data is greater than the start time, and the start time is greater than the timestamp when the data is written to the current block, then the state variable corresponding to the temporary state data is written into the temporary state data validity period storage contract.
[0073] In the specific implementation process, when writing temporary state data, the timestamp of the current block at the time of data writing can be obtained first. Based on this timestamp and the validity period of the temporary state data, it can be confirmed whether the temporary state data is still valid. If it is valid, the data writing operation continues; if it is invalid, the data writing operation stops. Specifically, the end point and start point of the validity period of the temporary state data can be compared with the timestamp of the data being written to the current block. If the end point is greater than the start point, and the start point is greater than the timestamp, then the temporary state data is considered to be still valid when the data is written, and the corresponding state variable of the temporary state data is written into the temporary state data validity period storage contract.
[0074] In the embodiments of this specification, when performing a temporary state data writing operation, the temporary state data is confirmed to be within the validity period based on the timestamp of the current block and the validity period of the temporary state data before the data writing operation is performed. This ensures that the written temporary state data is valid, avoids writing invalid data, avoids wasting resources, and guarantees the accuracy of data writing.
[0075] In some embodiments of this specification, the contract code also includes a validity period storage type for temporary state data, which includes a timestamp storage type and a block height storage type; obtaining the timestamp of the data being written to the current block includes:
[0076] When the validity period storage type of temporary state data is timestamp storage type, directly obtain the timestamp of the data being written to the current block;
[0077] When the validity period storage type of temporary state data is block height storage type, obtain the block height at which the data was written to the current block, and obtain the timestamp of the data being written to the current block based on the block height at which the data was written to the current block.
[0078] In practical implementation, because each block height in a blockchain has a timestamp, the block height can also be used to represent time. In this embodiment, when writing temporary state data, the validity period storage type can be divided into timestamp storage type and block height storage type based on the validity period setting type of the temporary state data. The timestamp storage type can be understood as using the system timestamp as the start and end point of the validity period time window, while the block height storage type can be understood as using the block height as the start and end point of the validity period time window. In this embodiment, when obtaining the current block timestamp during data writing, the method for obtaining the timestamp can be determined based on the validity period storage type in the contract code of the temporary state data. If the validity period storage type of the temporary state data is timestamp storage type, the timestamp of the data being written to the current block can be directly obtained, and the validity of the temporary state data can be determined based on this timestamp. If the validity period storage type of the temporary state data is block height storage type, the block height at which the data is written to the current block can be obtained, and the timestamp of the data being written to the current block can be determined based on this block height, thereby determining the validity of the temporary state data. In addition, after confirming the validity of the temporary state data, when storing the state variables corresponding to the temporary state data in the temporary state data validity storage contract, the corresponding state variables can be written based on the validity storage type of the temporary state data. The state variables corresponding to the temporary state data can be divided into block state variables and timestamp state variables, which facilitates the comparison of validity periods when reading and releasing data in the future.
[0079] This specification provides two dimensions for setting the validity period of temporary states: block height and timestamp. Both block height and timestamp can be used to identify whether temporary state data has expired, thus facilitating the identification of whether temporary state data is valid when data is written.
[0080] Figure 5 This is a schematic diagram of the temporary state data reading process in one embodiment of this specification, as shown below. Figure 5As shown, in some embodiments of this specification, a method for reading temporary state data may also be provided, which may specifically include the following steps:
[0081] S502: Write the read contract code corresponding to the temporary state data to be read into the smart contract of the blockchain system. The read contract code includes the state variable corresponding to the temporary state data to be read.
[0082] S504: Based on the temporary read instruction pre-stored in the smart contract, execute the read contract code, call the temporary state data validity period storage contract, and obtain the timestamp of the current block to be read and the validity period of the temporary state data to be read.
[0083] S506: Based on the timestamp of the current block being read and the validity period of the temporary state data to be read, determine whether the temporary state data to be read is within its validity period.
[0084] S508: When the temporary state data to be read is within its validity period, read the value at the position corresponding to the key value in the state variable of the temporary state data to be read.
[0085] In the specific implementation process, such as Figure 4 As shown in the embodiments of this specification, a temporary read instruction TSLOAD is pre-written into the smart contract. When reading temporary state data, the read contract code for the temporary state to be read can be written into the smart contract first. This read contract code can include the state variable corresponding to the temporary state data to be read, indicating that the temporary state data to be read is to be read. Based on the temporary read instruction TSLOAD pre-written in the smart contract, the read contract code can be converted into a TSLOAD instruction and executed in the EVM. When the read contract code is executed based on TSLOAD, the temporary state data validity period storage contract is automatically called to obtain the validity period of the temporary state data to be read from the temporary state data validity period storage contract, and at the same time, the timestamp of the current block when the data is read is obtained, that is, the timestamp of the current block when the data read operation is performed. Based on the obtained timestamp and validity period, it can be determined whether the temporary state data to be read is within the validity period. If it is determined that the temporary state data to be read is within the validity period, the value at the corresponding position can be read based on the key value in the state variable of the temporary state data to be read, thereby realizing the reading of the temporary state data.
[0086] In this embodiment, a temporary read instruction TSLOAD is pre-written into the smart contract. Executing the temporary read instruction TSLOAD automatically calls the temporary state data validity period storage contract, obtains the validity period of the temporary state data to be read from the temporary state data validity period storage contract, and automatically reads the value at the corresponding position of the key value in the state variable of the temporary state data when it is determined that the temporary state data to be read is within the validity period, thereby realizing the automatic reading of the temporary state data.
[0087] In some embodiments of this specification, the contract code for reading the temporary state data also includes a validity period storage type, which includes a timestamp storage type and a block height storage type; obtaining the timestamp of the current block includes:
[0088] When the validity period storage type of the temporary state data to be read is timestamp storage type, directly obtain the timestamp of the data being written to the current block;
[0089] When the validity period storage type of the temporary state data to be read is block height storage type, obtain the block height at which the data was written to the current block, and obtain the timestamp of the data being written to the current block based on the block height at which the data was written to the current block.
[0090] In specific implementation, referring to the description of the above embodiments, the embodiments of this specification can divide the validity period storage type into timestamp storage type and block height storage type based on the time setting type of the validity period of the temporary state data. When reading data to obtain the current block timestamp, the embodiments of this specification can determine the method of obtaining the timestamp according to the validity period storage type in the contract code of the temporary state data to be read. If the validity period storage type of the temporary state data to be read is timestamp storage type, the timestamp of the current block can be directly obtained, and the validity of the temporary state data to be read can be determined based on the timestamp. If the validity period storage type of the temporary state data to be read is block height storage type, the block height of the current block can be obtained, and the timestamp of the current block can be determined based on the block height, thereby determining whether the temporary state data to be read is valid.
[0091] This specification provides two dimensions for setting the validity period of temporary states: block height and timestamp. Both block height and timestamp can be used to identify whether the temporary state data to be read has expired, thus facilitating the identification of whether the temporary state data is valid when reading data.
[0092] The blockchain state data processing methods provided in the embodiments of this specification can be mainly divided into contract temporary state data reading and writing technology based on time windows and contract temporary state data automatic release technology based on expiration mechanisms. The overall process of data reading and data release is described in detail below:
[0093] 1. Writing temporary state data
[0094] 1) Write temporary state data into the contract code
[0095] In the embodiments described in this specification, smart contracts are supported to temporarily write state based on a time window. When writing smart contract code, users can use a method similar to the following to request the temporary writing of a certain state variable.
[0096] X = (Value, Time) start Time end (Type)
[0097] Here, X is a state variable in the contract, Value is the value to be assigned to X, such as 100, and Time... start Time end The effective time window for temporary state data storage can be determined by the specific value of Type. For example, if Type = 1, then Time... start Time end The starting UNIX timestamp; if Type=2, then Time start Time end The starting block height is denoted as Type. Type can be understood as the validity period storage type, which has several possibilities and can be adjusted and set according to the actual situation. In the embodiment of this specification, Type can have two values: 1 and 2. Type 1 can be understood as the validity period storage type being a timestamp storage type, and Type 2 can be understood as the validity period storage type being a block height storage type.
[0098] 2) Execute the temporary write command TSTORE:
[0099] like Figure 4 As shown, the contract code in step 1) is ultimately transformed into a TSTORE instruction and executed in the EVM. When the EVM encounters a TSTORE instruction, it reads and parses the top element of the stack, assigns a value to the variable X, and sets a time window as its validity period, specifically:
[0100] TSTORE[STACK_TOP]
[0101] Its parameter is STACK_TOP, which is the content of the element at the top of the virtual machine stack, mainly including:
[0102] <Key,Value,Time start Time end Type>
[0103] In the tuple, the Key and Value correspond to the key and value of the SSTORE opcode in existing smart contract technology, respectively. In other words, the Key is the storage location of the variable X, and the Value is the actual value. And when Time... start Time end Type equals the value set in step 1.
[0104] 3) Write storage validity period
[0105] Step 2) When the TSTORE instruction is executed, the system contract, namely the temporary state data expiration storage contract, is invoked to set the storage expiration of variable X in the contract to the corresponding time period:
[0106] Assuming Type = 1, then Time start Time end If the starting UNIX timestamp is used, then the timestamp (Time) of the current block is obtained. block and ensure
[0107] Time end Time start >=Time block
[0108] If satisfied, the following content will be stored in a Map state variable of the validity period storage contract according to the following mapping relationship: time If the conditions are not met, storage fails and transaction execution fails. Here, Contract is the address of the transaction execution contract, Key is the storage location of X in the state tree, and the tuple (Time)... start Time end () is the starting UNIX timestamp.
[0109] Contract => Key => (Time) start Time end )
[0110] Assuming Type = 2, then Time start Time end If the starting block height is given, then the current block height (Block) is obtained. height and ensure
[0111] Time end Time start >=Block height
[0112] If satisfied, the following content will be stored in a Map state variable of the validity period storage contract according to the following mapping relationship: blockIf the conditions are not met, storage fails and transaction execution fails. Here, Contract is the address of the transaction execution contract, Key is the storage location of X in the state tree, and the tuple (Time)... start Time end ) represents the starting block height.
[0113] Contract => Key => (Time) start Time end )
[0114] After successfully writing the storage expiration date, the value will be set in the key storage location, just like the SSTORE opcode in existing smart contract technology.
[0115] 2. Temporary state data reading
[0116] 1) Reading temporary state data from the contract code:
[0117] The embodiments in this specification support smart contracts reading temporary storage state variables. When writing smart contract code, users can use a method similar to the following to request the reading of a certain temporary storage state variable.
[0118] Y = (X, Type)
[0119] Here, X is a state variable in the contract, and Type indicates which mode (consistent with the meaning of writing temporary state data mentioned above) is used to read the value of X and finally assign it to the variable Y.
[0120] 2) Execute the temporary read instruction TSLOAD:
[0121] like Figure 4 As shown, the contract code in step 1) is ultimately transformed into a TSLOAD instruction and executed in the EVM. When the EVM encounters a TSLOAD instruction, it reads and parses the top element of the stack, specifically:
[0122] TSLOAD[STACK_TOP]
[0123] The parameter STACK_TOP represents the content of the element at the top of the virtual machine stack, which mainly includes:
[0124] <Key,Type>
[0125] The Key in the tuple is the storage location of variable X, and the Type is the type of time window, i.e., the storage type of the validity period.
[0126] If Type = 1, then get the timestamp Time of the current block. blockUsing the current contract (Contract) and key as the combined key, call the temporary state data validity storage contract to obtain the Map. time Medium time period (Time) start Time end If Time block If the value is within this range, the value at the Key position is read and assigned to Y; otherwise, a null value of the corresponding type is assigned to Y.
[0127] If Type = 2, then get the height of the current block. height Using the current contract (Contract) and key as the combined key, call the temporary state data validity storage contract to obtain the Map. block Medium block cycle (Time) start Time end If Block height If the value is within this range, the value at the Key position is read and assigned to Y; otherwise, a null value of the corresponding type is assigned to Y.
[0128] This completes the storage and reading / writing of the contract's temporary state data.
[0129] This specification presents a time-window-based technology for reading and writing temporary contract state data. It provides both block and timestamp dimensions, allowing users to set the data's validity period when writing state data. Simultaneously, during reading, the time window ensures correct data retrieval within the validity period. This approach improves the flexibility of state management, enabling users to read and write temporary state data without manually triggering transactions to invalidate the data, thus reducing the cost of state management.
[0130] 3. Automatic release of temporary state data
[0131] 1) Execute block transactions
[0132] like Figure 2 As shown, whenever a node packages or synchronizes a new block, it calls the EVM to execute all transactions within the block. After all transactions have been executed, the current block height (Block) is obtained. height Determine the Block height If the block height since the last data release is greater than or equal to K, proceed to the next step; otherwise, there is no need to release the state, and the process continues with the next block. Alternatively, the block height of the current block can be retrieved at preset intervals. height Determine the Block height If the block height since the last data release is greater than or equal to K, proceed to the next step; otherwise, there is no need to release the state.
[0133] 2) Read the data to be released
[0134] Based on the current block height (Block) height The EVM will call the expiration storage contract and iterate through the Map. block For each Contract => Key, if its (Time) start Time end Time in ) end Less than Map block Then it will<Contract,Key,2> The tuple is added to the returned result.
[0135] Based on the timestamp of the current block (Time) block The EVM will call the expiration storage contract and iterate through the Map. time For each Contract => Key, if its (Time) start Time end Time in ) end Less than Time block Then it will<Contract,Key,1> The tuple is added to the returned result.
[0136] Finally, the data to be released is returned to the EVM, i.e.
[0137] Data release =[<Contract,Key,Type> ]
[0138] 3) Release data
[0139] Regarding the Data obtained in step 2), release traverse each<Contract,Key,Type> The data corresponding to the key in the state tree is pruned as follows:
[0140]
[0141] Where State is the world state maintained by the MPT state tree, State[Contract] is the world state of the contract, and DELETE means deleting the state value at the position corresponding to the key in the MPT tree.
[0142] 4) Reset validity period
[0143] After resetting and releasing the world state in step 3), the Data obtained in step 2) release traverse each<Contract,Key,Type> .
[0144] If Type = 1, the temporary state data expiration storage contract will be invoked, and the Map will be... time The value corresponding to Contract => Key, i.e. the expiration date, can be set to (0,0), or it can be cleared.
[0145] If Type = 2, the temporary state data expiration storage contract will be invoked, and the Map will be... block The value corresponding to Contract => Key, i.e. the expiration date, can be set to (0,0), or it can be cleared.
[0146] This specification provides an automated release technology for contract temporary state data based on an expiration mechanism. By storing the validity period of temporary state data, nodes automatically release expired temporary state data every K blocks, clearing expired data, reducing the expansion of the state tree, and lowering the storage burden on nodes. Simultaneously, the state data release action is completed automatically without requiring users to manually initiate transactions, reducing the cost of state management for users.
[0147] Based on the blockchain state data processing method described above, one or more embodiments of this specification also provide a terminal and server for processing blockchain state data. The terminal and server may include devices (including distributed systems), software (applications), modules, components, servers, terminals, etc., using the methods described in the embodiments of this specification, combined with necessary hardware implementation. Based on the same innovative concept, the devices in one or more embodiments provided in this specification are as described in the following embodiments. Since the implementation schemes and methods for solving the problem by the devices are similar, the implementation of specific devices in the embodiments of this specification can refer to the implementation of the foregoing methods, and repeated details will not be elaborated further. As used below, the terms "unit" or "module" can refer to a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0148] As can be seen from the technical solutions provided in the embodiments of this specification above, the embodiments of this specification also provide a blockchain state data processing device, wherein a temporary state data validity period storage contract is set in the blockchain system, and the temporary state data validity period storage contract is used to record the validity period of the temporary state data. Figure 6 This is a schematic diagram of the structure of a blockchain state data processing device provided in the embodiments of this specification, such as... Figure 6 As shown, the above-mentioned device includes:
[0149] The validity period acquisition module 610 is used to call the temporary state data validity period storage contract, traverse the state variables in the temporary state data validity period storage contract, and obtain the validity period of each temporary state data in the state variables; the state variables include the contract address, key value and validity period corresponding to each temporary state data; the key value is used to represent the storage location of the temporary state data.
[0150] The data to be released determination module 620 is used to take the temporary state data whose validity period exceeds the timestamp of the current data release block as the data to be released;
[0151] The state data release module 630 is used to delete the state value at the position corresponding to the key value in the state tree of the blockchain system according to the contract address and key value in the state variable of the data to be released.
[0152] In some embodiments, the state variables include block state variables and timestamp state variables; the data to be released determination module 620 is specifically used for:
[0153] When iterating through the block state variables in the temporary state data validity period storage contract, the validity period of the temporary state data is compared with the block height at which the data is released in the current block. If the end point of the time in the validity period of the temporary state data is less than the block height, then the temporary state data is regarded as data to be released.
[0154] When iterating through the timestamp state variables in the temporary state data validity period storage contract, the validity period of the temporary state data is compared with the timestamp of the data release of the current block. If the end point of the time in the validity period of the temporary state data is less than the timestamp of the data release of the current block, then the temporary state data is regarded as data to be released.
[0155] In some embodiments, the validity period acquisition module 610 is further configured to:
[0156] Before calling the temporary state data validity period storage contract and traversing the state variables in the temporary state data validity period storage contract, the block height of the blockchain is obtained once every preset time.
[0157] Calculate the distance between the block height of the blockchain and the block height of the last data release. If the distance is greater than or equal to a preset height, call the temporary state data validity period storage contract and traverse the state variables in the temporary state data validity period storage contract.
[0158] In some embodiments, the apparatus further includes an expiration date reset module, configured to:
[0159] After deleting the state value corresponding to the key in the blockchain's state tree, the temporary state data validity period storage contract is invoked to set the validity period in the state variable corresponding to the data to be released to null.
[0160] In some embodiments, the apparatus further includes a temporary state data writing module, configured to:
[0161] Write the corresponding write contract code for the temporary state data into the smart contract of the blockchain system; the write contract code includes the value and validity period of the temporary state data;
[0162] The write contract code is executed based on the temporary write instruction pre-stored in the smart contract, which calls the temporary state data validity period storage contract in the blockchain system and stores the state variable corresponding to the temporary state data in the temporary state data validity period storage contract; the temporary write instruction is used to temporarily store the world state according to a given time window.
[0163] Write the value of the temporary state data at the position corresponding to the key value of the temporary state data.
[0164] In some embodiments, the temporary state data writing module is specifically used for:
[0165] Get the timestamp of the data being written to the current block;
[0166] If the end point of the validity period of the temporary state data is greater than the start point of the time, and the start point of the time is greater than the timestamp of the data being written to the current block, then the state variable corresponding to the temporary state data is written into the temporary state data validity period storage contract.
[0167] In some embodiments, the writing of contract code further includes a validity period storage type for the temporary state data, wherein the validity period storage type includes a timestamp storage type and a block height storage type; the temporary state data writing module is specifically used for:
[0168] When the validity period storage type of the temporary state data is timestamp storage type, the timestamp of the data being written to the current block is directly obtained;
[0169] When the validity period storage type of the temporary state data is block height storage type, the block height at which the data is written to the current block is obtained, and the timestamp of the data being written to the current block is obtained based on the block height at which the data is written to the current block.
[0170] In some embodiments, the apparatus includes a temporary state data reading module, configured to:
[0171] Write the read contract code corresponding to the temporary state data to be read into the smart contract of the blockchain system. The read contract code includes the state variable corresponding to the temporary state data to be read.
[0172] Based on the temporary read instruction pre-stored in the smart contract, the read contract code is executed, the temporary state data validity period storage contract is called, and the timestamp of the current block read and the validity period of the temporary state data to be read are obtained.
[0173] Based on the timestamp of the current block read and the validity period of the temporary state data to be read, determine whether the temporary state data to be read is within the validity period;
[0174] When the temporary state data to be read is within its validity period, the value at the position corresponding to the key value in the state variable of the temporary state data to be read is read.
[0175] In some embodiments, the contract code for reading the temporary state data further includes a validity period storage type, wherein the validity period storage type includes a timestamp storage type and a block height storage type; the temporary state data reading module is specifically used for:
[0176] When the validity period storage type of the temporary state data to be read is timestamp storage type, directly obtain the timestamp of the data being written to the current block;
[0177] When the validity period storage type of the temporary state data to be read is the block height storage type, the block height at which the data was written to the current block is obtained, and the timestamp of the data being written to the current block is obtained based on the block height at which the data was written to the current block.
[0178] Regarding the apparatus in the above embodiments, the specific manner in which each module performs its operations has been described in detail in the embodiments related to the method, and will not be elaborated upon here. The apparatus in the above embodiments may also include other implementation methods based on the description of the method embodiments; specific implementation methods can be referred to the description of the relevant method embodiments, and will not be repeated here.
[0179] Figure 7 This is a block diagram of an electronic device for processing blockchain state data, provided in the embodiments of this specification. The electronic device can be a terminal, and its internal structure diagram can be as follows: Figure 7As shown, the electronic device includes a processor, memory, network interface, display screen, and input devices connected via a system bus. The processor provides computing and control capabilities. The memory includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The network interface is used to communicate with external terminals via a network connection. When the computer program is executed by the processor, it implements a method for processing blockchain state data. The display screen can be an LCD screen or an e-ink screen. The input devices can be a touch layer covering the display screen, buttons, a trackball, or a touchpad mounted on the device's casing, or an external keyboard, touchpad, or mouse.
[0180] Figure 8 This is a block diagram of another electronic device for processing blockchain state data provided in the embodiments of this specification. This electronic device can be a server, and its internal structure diagram can be as follows: Figure 8 As shown, the electronic device includes a processor, memory, and a network interface connected via a system bus. The processor provides computing and control capabilities. The memory includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The network interface is used to communicate with external terminals via a network connection. When the computer program is executed by the processor, it implements a method for processing blockchain state data.
[0181] Those skilled in the art will understand that Figure 7 or Figure 8 The structures shown are merely block diagrams of some structures related to the embodiments of this specification, and do not constitute a limitation on the electronic devices to which the embodiments of this specification are applied. Specific electronic devices may include more or fewer components than those shown in the figures, or combine certain components, or have different component arrangements.
[0182] In an exemplary embodiment, an electronic device is also provided, including: a processor; and a memory for storing processor-executable instructions; wherein the processor is configured to execute the instructions to implement a blockchain state data processing method as described in the embodiments of this specification.
[0183] In an exemplary embodiment, a computer-readable storage medium is also provided, which, when the instructions in the storage medium are executed by the processor of an electronic device, enables the electronic device to perform the blockchain state data processing method in the embodiments of this specification.
[0184] In an exemplary embodiment, a computer program product or computer program is also provided, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the blockchain state data processing method provided in the various optional implementations described above.
[0185] It is understood that in the specific implementation of this specification, user-related data is involved. When the above embodiments of this specification are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions.
[0186] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. This computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the methods described above. Any references to memory, storage, databases, or other media used in the embodiments provided in this specification can include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and RAMbus dynamic RAM (RDRAM), etc.
[0187] Other embodiments of the embodiments of this specification will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This specification is intended to cover any variations, uses, or adaptations of the embodiments of this specification that follow the general principles of the embodiments of this specification and include common knowledge or customary techniques in the art not disclosed in the embodiments of this specification. The specification and embodiments are to be considered exemplary only, and the true scope and spirit of the embodiments of this specification are indicated by the following claims.
[0188] It should be understood that the embodiments described herein are not limited to the precise structures already described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from their scope. The scope of the embodiments described herein is limited only by the appended claims.
Claims
1. A method for processing blockchain state data, characterized in that, The blockchain system includes a temporary state data validity period storage contract, which records the validity period of temporary state data. The method includes: The temporary state data validity period storage contract is invoked, and the state variables in the temporary state data validity period storage contract are traversed to obtain the validity period of each temporary state data in the state variables; the state variables include the contract address, key value and validity period corresponding to each temporary state data; the key value is used to represent the storage location of the temporary state data. The temporary state data whose validity period exceeds the timestamp of the current data release block is used as the data to be released. Based on the contract address and key value in the state variable of the data to be released, delete the state value at the position corresponding to the key value in the state tree of the blockchain system.
2. The method according to claim 1, characterized in that, The state variables include block state variables and timestamp state variables; the step of using temporary state data whose validity period exceeds the timestamp of the data release current block as data to be released includes: When iterating through the block state variables in the temporary state data validity period storage contract, the validity period of the temporary state data is compared with the block height at which the data is released in the current block. If the end point of the time in the validity period of the temporary state data is less than the block height, then the temporary state data is regarded as data to be released. When iterating through the timestamp state variables in the temporary state data validity period storage contract, the validity period of the temporary state data is compared with the timestamp of the data release of the current block. If the end point of the time in the validity period of the temporary state data is less than the timestamp of the data release of the current block, then the temporary state data is regarded as data to be released.
3. The method according to claim 1, characterized in that, Before invoking the temporary state data validity period storage contract and iterating through the state variables in the temporary state data validity period storage contract, the method further includes: The block height of the blockchain is retrieved at preset intervals. Calculate the distance between the block height of the blockchain and the block height of the last data release. If the distance is greater than or equal to a preset height, call the temporary state data validity period storage contract and traverse the state variables in the temporary state data validity period storage contract.
4. The method according to claim 1, characterized in that, After deleting the state value at the position corresponding to the key value in the blockchain's state tree, the method further includes: Invoke the temporary state data validity period storage contract to set the validity period in the state variable corresponding to the data to be released to null.
5. The method according to claim 1, characterized in that, The method further includes: Write the corresponding write contract code for the temporary state data into the smart contract of the blockchain system; the write contract code includes the value and validity period of the temporary state data; The write contract code is executed based on the temporary write instruction pre-stored in the smart contract, which calls the temporary state data validity period storage contract in the blockchain system and stores the state variable corresponding to the temporary state data in the temporary state data validity period storage contract; the temporary write instruction is used to temporarily store the world state according to a given time window. Write the value of the temporary state data at the position corresponding to the key value of the temporary state data.
6. The method according to claim 5, characterized in that, The step of writing the state variable corresponding to the temporary state data into the temporary state data validity period storage contract based on the validity period of the temporary state data includes: Get the timestamp of the data being written to the current block; If the end point of the validity period of the temporary state data is greater than the start point of the time, and the start point of the time is greater than the timestamp of the data being written to the current block, then the state variable corresponding to the temporary state data is written into the temporary state data validity period storage contract.
7. The method according to claim 6, characterized in that, The contract code writing also includes the validity period storage type of the temporary state data, which includes a timestamp storage type and a block height storage type; obtaining the timestamp of the data being written to the current block includes: When the validity period storage type of the temporary state data is timestamp storage type, the timestamp of the data being written to the current block is directly obtained; When the validity period storage type of the temporary state data is block height storage type, the block height at which the data is written to the current block is obtained, and the timestamp of the data being written to the current block is obtained based on the block height at which the data is written to the current block.
8. The method according to claim 1, characterized in that, The method further includes: Write the read contract code corresponding to the temporary state data to be read into the smart contract of the blockchain system. The read contract code includes the state variable corresponding to the temporary state data to be read. Based on the temporary read instruction pre-stored in the smart contract, the read contract code is executed, the temporary state data validity period storage contract is called, and the timestamp of the current block read and the validity period of the temporary state data to be read are obtained. Based on the timestamp of the current block read and the validity period of the temporary state data to be read, determine whether the temporary state data to be read is within the validity period; When the temporary state data to be read is within its validity period, the value at the position corresponding to the key value in the state variable of the temporary state data to be read is read.
9. The method according to claim 8, characterized in that, The read contract code also includes the validity period storage type of the temporary state data to be read, which includes timestamp storage type and block height storage type; The timestamp for reading the current block when acquiring data includes: When the validity period storage type of the temporary state data to be read is timestamp storage type, directly obtain the timestamp of the data being written to the current block; When the validity period storage type of the temporary state data to be read is the block height storage type, the block height at which the data was written to the current block is obtained, and the timestamp of the data being written to the current block is obtained based on the block height at which the data was written to the current block.
10. A device for processing blockchain state data, characterized in that, The blockchain system includes a temporary state data validity period storage contract, which records the validity period of temporary state data. The device includes: The validity period acquisition module is used to call the temporary state data validity period storage contract, traverse the state variables in the temporary state data validity period storage contract, and obtain the validity period of each temporary state data in the state variables; the state variables include the contract address, key value, and validity period corresponding to each temporary state data; the key value is used to represent the storage location of the temporary state data. The data to be released determination module is used to take temporary state data whose validity period exceeds the timestamp of the current data release block as data to be released; The state data release module is used to delete the state value at the position corresponding to the key value in the state tree of the blockchain system based on the contract address and key value in the state variable of the data to be released.
11. An electronic device, characterized in that, include: processor; Memory used to store the processor's executable instructions; The processor is configured to execute the instructions to implement the blockchain state data processing method as described in any one of claims 1-9.
12. A computer-readable storage medium, characterized in that, When the instructions in the storage medium are executed by the processor of the electronic device, the electronic device is able to perform the blockchain state data processing method as described in any one of claims 1-9.