Method for executing smart contract in block chain system and block chain node
By using aggregated storage types in the blockchain system, multiple member variables in the smart contract share the same key, the problem of low allocation efficiency of state variable keys in the smart contract is solved, and the utilization rate of the data storage system is improved.
Patent Information
- Application Number
- CN202411970821.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-27
- Publication Date
- 2025-04-29
AI Technical Summary
In blockchain systems, multiple state variables in smart contracts need to be allocated different keys, resulting in a lower utilization rate of key-value pairs.
By using aggregation storage types in the contract code of a smart contract, sharing the key of the same parent variable for multiple member variables, it is possible to access the value of a member variable without assigning different keys.
The key-value pairs stored in the data storage system are reduced, and the amount of data of a single value is increased, thereby improving the utilization rate of key-value pairs in the data storage system.
Smart Images

Figure CN119903104A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of this specification belong to the field of computer technology, and more particularly to a method for executing a smart contract in a blockchain system and a blockchain node. Background Art
[0002] The blockchain system is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, and encryption algorithm. In the blockchain system, data blocks are combined into a chain data structure in a sequential manner according to time order, and a distributed ledger that cannot be tampered with or forged is guaranteed by cryptography. Due to the characteristics of decentralization, information cannot be tampered with, and autonomy, the blockchain system has received more and more attention and application.
[0003] The blockchain system can provide the function of smart contracts. Smart contracts usually include multiple state variables, and the values of the state variables are stored in the data storage system in the form of key-value pairs. In this case, different keys need to be assigned to the multiple state variables in the smart contract. The amount of data for a single value is usually relatively small, and the utilization rate of the key-value pair is relatively low. Summary of the invention
[0004] The object of the present invention is to provide a method for executing a smart contract in a blockchain system and a blockchain node.
[0005] In a first aspect, a method for executing a smart contract in a blockchain system is provided, wherein the smart contract includes a first state variable and multiple first member variables of the first state variable, wherein the storage type corresponding to the multiple first member variables in a data storage system is aggregate storage, and the method is implemented by executing the contract code, and the method includes: determining a target state variable to be accessed in the data storage system; when the target state variable belongs to the multiple first member variables, accessing the value of the first key in the data storage system at least according to the first key of the first state variable.
[0006] In a possible implementation, the contract code is obtained by compiling the source code of the smart contract through a compiler, and the source code includes annotation information corresponding to the first state variable, and the annotation information is used to indicate that the storage type corresponding to the multiple first member variables in the data storage system is aggregate storage.
[0007] In a possible implementation manner, the source code includes a first structure corresponding to the first state variable, and the annotation information is a structure annotation set for the first structure.
[0008] In a possible implementation, the data type of the first state variable is a vector or an array, and the annotation information is a variable annotation set for the first state variable.
[0009] In a possible implementation, accessing the value of the first key in the data storage system according to the first key of the first state variable includes: reading the value of the first key from the data storage system; wherein the method further includes: decoding the value of the first key to obtain a decoding result; and obtaining the value of the target state variable from the decoding result.
[0010] In a possible implementation, the method further includes: obtaining the value of the target state variable to be stored; and obtaining the current values of the remaining first member variables except the target state variable among the plurality of first member variables; encoding the value of the target state variable to be stored and the current values of the remaining first member variables to obtain an encoding result; wherein,
[0011] The accessing the value of the first key in the data storage system according to the first key of the first state variable includes: storing the encoding result as the value of the first key in the data storage system.
[0012] In a possible implementation, the smart contract also includes a second state variable and multiple second member variables of the second state variable, and the storage type corresponding to the multiple second member variables in the data storage system is separated storage; wherein the method also includes: when the target state variable belongs to the multiple second member variables, accessing the value of the second key in the data storage system according to the second key of the target state variable.
[0013] In a possible implementation, when the data storage system includes a second key for the target state variable, the second key is determined based on the target state variable and several preceding state variables in the smart contract that have a nested relationship with the target state variable.
[0014] In a possible implementation, the second key is determined based on a directed path with the target state variable as the termination node, and the directed path also includes the several preceding state variables; any i-th state variable in the directed path is a member variable of the i-1-th state variable in the directed path.
[0015] In a possible implementation manner, the amount of data in the encoding result obtained by encoding the values of the plurality of first member variables in the data storage system is not greater than a predetermined value.
[0016] In a second aspect, a blockchain node in a blockchain system is provided, wherein a smart contract is deployed in the blockchain system, wherein the smart contract includes a first state variable and multiple first member variables of the first state variable, wherein the storage type corresponding to the multiple first member variables in the data storage system is aggregate storage, and the blockchain node is used to execute the contract code to achieve: determining a target state variable to be accessed in the data storage system; when the target state variable belongs to the multiple first member variables, accessing the value of the first key in the data storage system at least according to the first key of the first state variable.
[0017] According to a third aspect, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed in a computing device, the computing device executes the method described in the first aspect.
[0018] In the technical solution provided by the embodiments of this specification, there is a state variable in the smart contract that is used as a parent variable, and the parent variable includes multiple member variables that are also state variables; the storage type corresponding to the multiple state variables in the data storage system can be aggregate storage, so that the multiple member variables can share the same key of the parent variable, and access to the value of the member variable is completed by accessing the value of the key of the parent variable in the data storage system without assigning different keys to the multiple member variables, which is beneficial to reducing the key-value pairs stored in the data storage system, and at the same time can also increase the data volume of a single value, thereby helping to improve the utilization rate of the key-value pairs in the data storage system. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the technical solutions of the embodiments of this specification, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0020] Figure 1 This is an architectural diagram of a blockchain system exemplarily provided in the embodiments of this specification;
[0021] Figure 2 A schematic diagram of the process of assigning keys to state variables in a smart contract is provided as an example;
[0022] Figure 3 A schematic diagram of the data structure of the value in the key-value pair stored in the exemplary data storage system;
[0023] Figure 4 This is a flowchart of a method for executing a smart contract in a blockchain system provided in an embodiment of this specification. DETAILED DESCRIPTION
[0024] In order to enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of this specification, not all of the embodiments. Based on the embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this specification.
[0025] Figure 1 This is an architectural diagram of a blockchain system provided exemplarily in the embodiments of this specification. The blockchain system may include N blockchain nodes, where Figure 1 8 blockchain nodes, i.e., node 1 to node 8, are shown as examples. The lines between the nodes schematically represent the connection between the nodes, and the aforementioned connection is used to support data transmission between different nodes.
[0026] The blockchain system can provide the function of smart contracts. Smart contracts in the blockchain system are contracts that can be triggered and executed by transactions. Smart contracts can be defined in the form of contract code. Calling a smart contract in the blockchain system is to initiate a transaction pointing to the contract address of the smart contract, so that each node in the blockchain system can run the corresponding contract code in a distributed manner.
[0027] In various blockchain systems that introduce smart contracts, accounts can generally be divided into two types:
[0028] Contract account (CA): mainly used to store the contract code of the corresponding smart contract and the value of the state variable in the smart contract. It can usually only be activated by calling an external account.
[0029] Externally owned account (EOA): An account registered by an external user in the blockchain system.
[0030] The design of external accounts and contract accounts is actually a mapping from account addresses to account states. The account state of any account usually includes fields such as nonce, balance, storageRoot, code, and / or codeHash. Nonce and balance exist in both external accounts and contract accounts, while code, codeHash, and storageRoot attributes are generally only valid on contract accounts.
[0031] The contract account is used to store the contract status of the smart contract. After the smart contract is deployed in the blockchain system, a corresponding contract account will be generated. This contract account generally has some states, which are defined by the state variables in the smart contract and generate new values when the smart contract is created and executed. The smart contract generally refers to a contract that can automatically execute terms defined in digital form in the blockchain environment. When an event triggers the terms in the contract (meets the execution conditions), the code can be automatically executed. The contract status of the smart contract is saved in the storage trie, and the hash value of the storagetrie root node is stored in the above storageroot, so that all the contract states of the smart contract are locked to the contract account through hash. The storage trie can be a tree structure that stores the key-value mapping from the state address to the state value. The address of a state variable is stored from the root node of the storage trie tree to a leaf node, and the value of the state variable is stored in the leaf node.
[0032] In one possible implementation, a slot-based storage model can usually be used for the state variables of a smart contract, that is, developers can define state variables in the source code of a smart contract; when the source code is compiled by a compiler, the state variable will be mapped to the corresponding state address (i.e., the key of the state variable) according to the declaration position and / or variable type of the state variable in the source code, and the value of the state variable will form a key-value pair with the key of the state variable and be stored in the corresponding data storage system. In the aforementioned implementation, different keys need to be assigned to each state variable in the smart contract; moreover, it is usually necessary to allocate a fixed-size storage space to the value in the key-value pair, and there are a large number of cases where too much storage space is allocated for relatively small values; this ultimately leads to low utilization of key-value pairs.
[0033] In the embodiments of this specification, a method and a blockchain node for executing a smart contract in a blockchain system are provided. The contract code of the smart contract includes a first state variable and multiple first member variables of the first state variable, and the storage type corresponding to the multiple first member variables in the data storage system is aggregate storage; in the process of executing the smart contract by executing the contract code, when it is necessary to access a certain target state variable in the data storage system, if the target state variable belongs to the multiple first member variables included in the first state variable, the value of the first key can be accessed in the data storage system according to the first key of the first state variable, thereby completing the access to the value of the target state variable included in the value.
[0034] In this way, there is a state variable in the smart contract that is used as a parent variable, and the parent variable includes multiple member variables that are also state variables; the storage type corresponding to the multiple state variables in the data storage system can be aggregate storage, so that the multiple member variables can share the same parent variable key, and access to the value of the member variable is completed by accessing the value of the key of the parent variable in the data storage system without assigning different keys to the multiple member variables, which is beneficial to reducing the key-value pairs stored in the data storage system, and at the same time can also increase the data volume of a single value, thereby helping to improve the utilization rate of key-value pairs in the data storage system.
[0035] The data types of state variables in smart contracts can usually be divided into basic types and composite types. Basic data types include, but are not limited to, u8, i8, u16, i16, u32, i32, bool, and string, and composite data types include, but are not limited to, array, map, vector, enum, struct, and asset.
[0036] A state variable with a composite data type usually includes / nests multiple member variables, where the member variables also belong to the state variables; the data types of any two member variables among the multiple member variables may be the same or different.
[0037] When developers write the source code of a smart contract, for multiple member variables included in a single state variable, they can estimate the estimated amount of data corresponding to the encoding results obtained when a specific encoding algorithm is used to encode the values of the multiple member variables. If the estimated amount of data is not greater than a predetermined value, such as not greater than 32 bytes, annotation information can be set for the state variable in the source code to indicate that the storage type corresponding to the multiple member variables included in the state variable in the data storage system is aggregate storage. On the contrary, if the estimated amount of data is greater than a predetermined value, such as greater than 32 bytes, there is no need to set the aforementioned annotation information for the state variable in the source code; in this case, it means that the storage type corresponding to the multiple member variables included in the state variable in the data storage system is separate storage.
[0038] Generally, for a state variable whose data type is a structure (struct), the annotation information of the state variable may be a structure annotation set for the structure corresponding to the state variable; for a state variable whose data type is an array (array) or a vector (vector) or other data types, the annotation information of the state variable may be a variable annotation set for the state variable.
[0039] For example, refer to Figure 2 The pseudo code of the smart contract shown in . The smart contract includes the state variable packed_data corresponding to the structure structPersonalinfo and the state variable unpacked_data corresponding to the structure struct Personalinfo2. Struct Personalinfo defines the member variables age, name, info included in packed_data and their corresponding data types; struct Personalinfo2 defines the member variables age2, name2, info2 included in unpacked_data and their corresponding data types. Based on the process of selecting the storage type for the state variables described in the previous example, the developer may selectively set a structure annotation such as "@pack" for struct Personalinfo in the source code, and do not set the structure annotation "@pack" for struct Personalinfo2. In this way, the storage type corresponding to the member variables age, name, and info included in packed_data in the data storage system is aggregate storage, while the storage type corresponding to the member variables age2, name2, and info2 included in unpacked_data in the data storage system is separate storage.
[0040] Please continue to refer to Figure 2For example, the smart contract may also include a state variable packed_vec with a vector data type, and the data type of each element / member variable in packed_vec is u8. Based on the process of selecting a storage type for a state variable described in the above example, the developer may set a variable annotation "@pack" for packed_vec in the source code.
[0041] When the compiler compiles the source code of the smart contract, if the source code has the aforementioned annotation information set for a state variable, the compiler may no longer allocate a state address to the member variables of the state variable; in other words, the compiler may not allocate a key for storing the values of the multiple member variables in the corresponding data storage system for the multiple member variables included in the state variable. Figure 2 For example, for the member variables age, name, and info of packed_data, the compiler does not need to assign corresponding keys to age, name, and info; for the member variables age2, name2, and info2 of unpacked_data, the compiler needs to assign corresponding keys to age2, name2, and info2.
[0042] A path-based storage model can be used in the data storage system to manage the contract state of the smart contract. More specifically, for any state variable in the smart contract, if the compiler needs to assign the key of the state variable in the data storage system, the key of the state variable can be determined based on the state variable and several preceding state variables that are nested with the state variable; for example, the key of the state variable can be determined based on a directed path with the state variable as the terminal node, wherein the directed path also includes several preceding state variables, and any i-th state variable in the directed path is a member variable of the i-1-th state variable in the directed path.
[0043] For example, please refer to the following pseudo code for the smart contract:
[0044]
[0045] In the pseudo code of the smart contract in the above example, the state variable foo corresponds to the structure Struct Foo, StructFoo defines that foo includes / nested member variables foo_f1 and foo_f2; foo_f2 corresponds to the structure Struct Bar, StructBar defines that foo_f2 includes / nested member variables bar_f1 and bar_f2. In this way, the preceding state variables that have a nested relationship with the state variable bar_f1 include foo and foo_f2, so that the key of bar_f1 can be determined based on foo, foo_f2 and bar_f1, for example, the key of bar_f1 can be determined based on the directed path composed of the state variables foo, foo_f2 and bar_f1.
[0046] Please continue to refer to Figure 2 For example, it is assumed here that the keys of various state variables in the same smart contract need to be determined based on the same root node, such as "contract". Then, the key of packed_data can be determined according to the directed path composed of contract and packed_data; the key of age2 can be determined according to the directed path composed of contract, unpacked_data and age2; the key of name2 can be determined according to the directed path composed of contract, unpacked_data and name2; the key of info2 can be determined according to the directed path composed of contract, unpacked_data and info2; the key of packed_vec can be determined according to contract and packed_vec; the key of alice can be determined according to contract, location, and alice; the key of bob can be determined according to contract, location, and bob; the key of carol can be determined according to contract, location, and carol.
[0047] The key of the state variable can be assigned when the source code of the smart contract is compiled by the compiler, or it can be dynamically determined during the execution of the smart contract. The only difference is the timing of determining the key of the state variable.
[0048] When a key is assigned to a state variable in a data storage system, a specific encoding algorithm is usually required to encode the value of the state variable, and the resulting encoding result will be stored in the data storage system as the value of the key of the state variable. The aforementioned encoding algorithm may include, but is not limited to, Simple Serialize (SSZ). For example, refer to Figure 3 As shown, in the SSZ encoding scheme, all encoded member variables are arranged in the order defined in the smart contract. For example, for the state variable packed_data corresponding to the structure StructPersonalinfo in the above example, three positions arranged in sequence can be determined, where position 1 corresponds to the member variable age, position 2 corresponds to the member variable name, and position 3 corresponds to the member variable info. The above positions 1 to 3 can all have the same predetermined length. Among them, the value of a member variable with a fixed length, such as age, can be directly stored in its corresponding position, such as position 1. For a member variable of variable length, such as name, the corresponding position, such as position 2, can store an address offset, which is used to indicate the address where the value of name is actually stored, such as the address of position 4 after position 3; based on similar rules, for a member variable of variable length, such as info, the corresponding position, such as position 3, can store an address offset, which is used to indicate the address where the value of info is actually stored, such as the address of position 5 after position 4.
[0049] The contract code obtained by compiling the source code of the smart contract may also include encoding functions and decoding functions corresponding to state variables. The encoding function is used to encode according to the value of the relevant state variable or the values of multiple member variables included in the relevant state variable to obtain the value of a key to be stored in the data storage system; the decoding function is used to decode the value of a key in the data storage system to obtain the value of the relevant state variable or the values of multiple member variables included in the relevant state variable. It should be noted that different state variables may correspond to the same or different encoding functions / decoding functions.
[0050] After obtaining the contract code of the smart contract, the smart contract can be deployed in the blockchain system using the contract code of the smart contract. The smart contract may be executed by the blockchain system under the call of other smart contracts or related transactions.
[0051] Figure 4 This is a flowchart of a method for executing a smart contract in a blockchain system provided in an embodiment of this specification. The method is implemented by executing the contract code of the smart contract by a blockchain node in the blockchain system. The smart contract includes a first state variable and multiple first member variables of the first state variable, and the storage type corresponding to the multiple first member variables in the data storage system is aggregate storage; in addition, the contract code of the smart contract may also include a second state variable and multiple second member variables of the second state variable, and the storage type corresponding to the multiple second member variables in the data storage system is separate storage. Figure 4As shown, the method may include but is not limited to part or all of the following steps S401 to 415.
[0052] Step S401: determine a target state variable to be accessed in a data storage system.
[0053] In the process of executing the contract code, the blockchain node in the blockchain system can know whether the target state variable to be accessed has a parent variable through the execution context of the contract code, that is, it can know whether the target state variable is a member variable of other state variables. If the target state variable is a member variable of other state variables, the storage type corresponding to the multiple member variables included in the other state variables (i.e., the parent variable) in the data storage system can also be known through the execution context. If the storage type is aggregate storage, part or all of the following steps S403 to S413 can be executed; if the storage type is separate storage, or the target state variable does not have a parent variable, the following step S415 can be directly executed.
[0054] Accessing the target state variable in the data storage system may include: obtaining the value of the target state variable from the data storage system, or storing the value of the target state variable in the data storage system. When it is necessary to store the value of the target state variable in the data storage system, part or all of the following steps S403 to S409 may be executed; when it is necessary to obtain the value of the target state variable from the data storage system, part or all of the following steps S409 to S413 may be executed.
[0055] Step S403, obtaining the value of the target state variable to be stored.
[0056] Step S405, obtaining current values of the remaining first member variables except the target state variable among the multiple first member variables included in the first state variable, wherein the storage type corresponding to the multiple first member variables in the data storage system is aggregate storage.
[0057] The current values of the remaining first member variables may be first queried in the memory; if the current values of the remaining first member variables cannot be queried from the memory, the current values of the remaining first member variables may be obtained from the data storage system. The process of obtaining the current values of the first member variables from the data storage system may refer to the process of obtaining the value of the target state variable from the data storage system through subsequent steps S409 to S413 below, which is not described in detail here.
[0058] Step S407, encoding the value of the target state variable to be stored and the current values of the remaining first member variables except the target state variable to obtain an encoding result.
[0059] The encoding function corresponding to the first state variable can be used to implement encoding according to the data types of the multiple first member variables included in the first state variable, the value of the target state variable to be stored, and the current values of the remaining first member variables. The encoding process and the encoding results obtained can be referred to Figure 3 And its corresponding text description, will not be repeated here.
[0060] Step S409 , accessing the value of the first key in the data storage system according to the first key of the first state variable.
[0061] When it is necessary to store the value of the target state variable in the data storage system, that is, when the aforementioned steps S403 to S407 are executed before executing step S409, in step S409, the encoding result obtained in step S407 can be specifically stored in the data storage system as the value of the first key of the first state variable.
[0062] When it is necessary to obtain the value of the target state variable from the data storage system, that is, when the aforementioned steps S403 to S407 are not executed before executing step S409, in step S409, the value of the first key can be read from the data storage system according to the first key of the first state variable.
[0063] Step S411, decode the value of the first key to obtain a decoding result.
[0064] Step S413, obtaining the value of the target state variable from the decoding result.
[0065] Please continue to refer to Figure 3 , take the case where the target state variable is the member variable name of the state variable packed_data. First, the value of packed_data can be read from the data storage system; then, the multiple fields included in the value of packed_data are decoded in sequence, and the decoded result obtained can include the values of the state variables age, name, and info arranged in sequence; finally, according to the arrangement position of the target state variable name in the multiple member variables included in packed_data, the value of the target state variable name is determined from the decoding result.
[0066] Step S415 , accessing the value of the second key in the data storage system according to the second key of the target state variable.
[0067] As mentioned above, if the storage type of the target state variable is separate storage, or the target state variable does not have a parent variable, the target state variable will be independently assigned its corresponding key in the data storage system during the compilation of the source code of the smart contract or the execution of the smart contract. In this case, the value of the target state variable can be directly used as the value of the key of the target state variable, or after encoding the value of the target state variable through a corresponding encoding algorithm, the encoding result is used as the value of the key of the target state variable and stored in the data storage system. Therefore, the value of the second key can be directly stored in the data storage system or the value of the second key can be obtained from the data storage system according to the second key of the target state variable, thereby completing the access to the value of the target state variable.
[0068] Based on the same concept as the aforementioned method embodiment, the embodiments of this specification also provide a blockchain node in a blockchain system, wherein a smart contract is deployed in the blockchain system, wherein the smart contract includes a first state variable and multiple first member variables of the first state variable, wherein the storage type corresponding to the multiple first member variables in the data storage system is aggregate storage, and the blockchain node is used to execute the contract code of the smart contract to achieve: determining a target state variable to be accessed in the data storage system; when the target state variable belongs to the multiple first member variables, accessing the value of the first key in the data storage system at least according to the first key of the first state variable.
[0069] A computer-readable storage medium is also provided in an embodiment of the present specification, on which a computer program / instruction is stored. When the computer program / instruction is executed in a computer, the computer is caused to execute a method for executing a smart contract in a blockchain system, which is executed by a blockchain node in the blockchain system in each of the aforementioned embodiments.
[0070] A computing device is also provided in an embodiment of the present specification, including a memory and a processor, wherein the memory stores a computer program / instruction, and when the processor executes the computer program / instruction, a method for executing a smart contract in a blockchain system is implemented in the aforementioned embodiments, which is executed by a blockchain node in the blockchain system.
[0071] In the 1990s, improvements to a technology could be clearly distinguished as hardware improvements (for example, improvements to the circuit structure of diodes, transistors, switches, etc.) or software improvements (improvements to the method flow). However, with the development of technology, many improvements to the method flow today can be regarded as direct improvements to the hardware circuit structure. Designers almost always obtain the corresponding hardware circuit structure by programming the improved method flow into the hardware circuit. Therefore, it cannot be said that an improvement in a method flow cannot be implemented using a hardware entity module. For example, a programmable logic device (PLD) (such as a field programmable gate array (FPGA)) is such an integrated circuit whose logical function is determined by the user's programming of the device. Designers can "integrate" a digital system on a PLD by programming it themselves, without having to ask a chip manufacturer to design and produce a dedicated integrated circuit chip. Moreover, nowadays, instead of manually making integrated circuit chips, this kind of programming is mostly implemented by "logic compiler" software, which is similar to the software compiler used when developing and writing programs, and the original code before compilation must also be written in a specific programming language, which is called hardware description language (HDL). There is not only one HDL, but many kinds, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, RHDL (Ruby Hardware Description Language), etc. The most commonly used ones are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should also know that it is only necessary to program the method flow slightly in the above-mentioned hardware description languages and program it into the integrated circuit, and then it is easy to obtain the hardware circuit that implements the logic method flow.
[0072] The controller can be implemented in any appropriate manner, for example, the controller can take the form of a microprocessor or processor and a computer-readable medium storing a computer-readable program code (such as software or firmware) that can be executed by the (micro)processor, a logic gate, a switch, an application-specific integrated circuit (ASIC), a programmable logic controller, and an embedded microcontroller. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320. The memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art also know that in addition to implementing the controller in a purely computer-readable program code manner, the controller can be implemented in the form of a logic gate, a switch, an application-specific integrated circuit, a programmable logic controller, and an embedded microcontroller by logically programming the method steps. Therefore, this controller can be considered as a hardware component, and the devices included therein for implementing various functions can also be regarded as structures within the hardware component. Or even, the devices for implementing various functions can be regarded as both software modules for implementing the method and structures within the hardware component.
[0073] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a server system. Of course, the present application does not exclude that with the development of computer technology in the future, the computer that implements the functions of the above embodiments may be, for example, a personal computer, a laptop computer, a vehicle-mounted human-computer interaction device, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
[0074] Although one or more embodiments of the present specification provide method operation steps as described in the embodiments or flow charts, more or less operation steps may be included based on conventional or non-creative means. The order of steps listed in the embodiments is only one way of executing the order of many steps, and does not represent the only execution order. When the device or terminal product in practice is executed, it can be executed in sequence or in parallel according to the method shown in the embodiments or the drawings (for example, a parallel processor or a multi-threaded processing environment, or even a distributed data processing environment). The term "include", "include" or any other variant thereof is intended to cover non-exclusive inclusion, so that the process, method, product or equipment including a series of elements includes not only those elements, but also includes other elements that are not explicitly listed, or also includes elements inherent to such a process, method, product or equipment. In the absence of more restrictions, it is not excluded that there are other identical or equivalent elements in the process, method, product or equipment including the elements. For example, if the words first, second, etc. are used to represent the name, they do not represent any specific order.
[0075] For the convenience of description, the above devices are described in various modules according to their functions. Of course, when implementing one or more of the present specification, the functions of each module can be implemented in the same or more software and / or hardware, or the module implementing the same function can be implemented by a combination of multiple sub-modules or sub-units, etc. The device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0076] The present invention is described with reference to flowcharts and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0077] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0078] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0079] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0080] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0081] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic disk storage, graphene storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0082] It should be understood by those skilled in the art that one or more embodiments of the present specification may be provided as a method, system or computer program product. Therefore, one or more embodiments of the present specification may take the form of a complete hardware embodiment, a complete software embodiment or an embodiment combining software and hardware. Moreover, one or more embodiments of the present specification may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0083] One or more embodiments of the present specification may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. One or more embodiments of the present specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules may be located in local and remote computer storage media, including storage devices.
[0084] Each embodiment in this specification is described in a progressive manner, and the same and similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment. In the description of this specification, the description of the reference terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of this specification. In this specification, the schematic representation of the above terms does not necessarily target the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any one or more embodiments or examples in a suitable manner. In addition, in the absence of mutual contradiction, a person skilled in the art can combine and combine the different embodiments or examples described in this specification and the features of different embodiments or examples.
[0085] The above description is only an example of one or more embodiments of the present specification and is not intended to limit one or more embodiments of the present specification. For those skilled in the art, one or more embodiments of the present specification may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present specification shall be included in the scope of the claims.
Claims
1. A method for executing a smart contract in a blockchain system, wherein the smart contract includes a first state variable and a plurality of first member variables of the first state variable, wherein the storage type corresponding to the plurality of first member variables in a data storage system is aggregate storage, and the method is implemented by executing the contract code of the smart contract, and the method includes: determining a target state variable to be accessed in the data storage system; When the target state variable belongs to the plurality of first member variables, the value of the first key is accessed in the data storage system at least according to the first key of the first state variable.
2. According to the method according to claim 1, the contract code is obtained by compiling the source code of the smart contract through a compiler, and the source code includes annotation information corresponding to the first state variable, and the annotation information is used to indicate that the storage type corresponding to the multiple first member variables in the data storage system is aggregate storage. 3 . According to the method of claim 2 , the source code includes a first structure corresponding to the first state variable, and the annotation information is a structure annotation set for the first structure. 4 . The method according to claim 2 , wherein the data type of the first state variable is a vector or an array, and the annotation information is a variable annotation set for the first state variable.
5. The method according to claim 1, wherein accessing the value of the first key in the data storage system according to the first key of the first state variable comprises: Read the value of the first key from the data storage system; Wherein, the method further comprises: Decode the value of the first key to obtain a decoding result; The value of the target state variable is obtained from the decoding result.
6. The method according to claim 1, further comprising: Obtaining the value of the target state variable to be stored; as well as, Obtaining current values of remaining first member variables among the plurality of first member variables except the target state variable; Encoding the value of the target state variable to be stored and the current values of the remaining first member variables to obtain an encoding result; Wherein, accessing the value of the first key in the data storage system according to the first key of the first state variable includes: storing the encoding result as the value of the first key in the data storage system.
7. According to the method of claim 1, the smart contract further includes a second state variable and a plurality of second member variables of the second state variable, and the storage type corresponding to the plurality of second member variables in the data storage system is separate storage; wherein, The method further includes: when the target state variable belongs to the plurality of second member variables, accessing the value of the second key in the data storage system according to the second key of the target state variable.
8. According to the method described in claim 1, when the data storage system includes a second key of the target state variable, the second key is determined based on the target state variable and several preceding state variables in the smart contract that have a nested relationship with the target state variable.
9. A blockchain node in a blockchain system, wherein a smart contract is deployed in the blockchain system, wherein the smart contract includes a first state variable and multiple first member variables of the first state variable, wherein the storage type corresponding to the multiple first member variables in the data storage system is aggregate storage, and the blockchain node is used to execute the contract code of the smart contract to achieve: determining a target state variable to be accessed in the data storage system; when the target state variable belongs to the multiple first member variables, accessing the value of the first key in the data storage system at least according to the first key of the first state variable.
10. A computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed in a computing device, the computing device executes the method according to any one of claims 1 to 8.