Blockchain transaction execution method and blockchain node

By pre-stored read and write information and obtaining the storage location information of state variables during contract deployment, parallel reading is achieved, which solves the problem of low efficiency in reading state variables during blockchain transaction execution and improves the overall processing efficiency.

WO2024198449A1PCT designated stage expired Publication Date: 2024-10-03ANT BLOCKCHAIN TECHNOLOGY (SHANGHAI) CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2023/135035
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-03-31
Filing Date
2023-11-29
Publication Date
2024-10-03

AI Technical Summary

Technical Problem

During the execution of blockchain transactions, state variables are usually read serially, resulting in low overall efficiency. Especially when multiple state variables are read, the time spent waiting for storage access results is large.

Method used

When the contract is deployed, the read and write information is stored in the blockchain in advance, the storage location information of the state variable is obtained through the access information table in the contract data, and the requested state variable value is read in advance to achieve parallel reading.

Benefits of technology

It improves the efficiency of blockchain transaction execution, reduces the time waiting for reading results, and improves processing efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2023135035_03102024_PF_FP_ABST
    Figure CN2023135035_03102024_PF_FP_ABST
Patent Text Reader

Abstract

A blockchain transaction execution method and a blockchain node. The method comprises: acquiring a first transaction, the first transaction calling a first contract, contract data of the first contract being stored in a blockchain, the contract data comprising a first access information table, and the first access information table comprising first storage position information of a first state variable read by a first contract request; reading the first storage position information from the blockchain; and reading the value of the first state variable from the blockchain according to the first storage position information so as to execute the first transaction.
Need to check novelty before this filing date? Find Prior Art

Description

Blockchain transaction execution method and blockchain node

[0001] This application claims priority to the Chinese patent application filed with the State Intellectual Property Office of China on March 31, 2023, with application number 202310341272.7 and application name “Blockchain Transaction Execution Method and Blockchain Node”, the entire contents of which are incorporated by reference into this application. Technical Field

[0002] The embodiments of this specification belong to the field of blockchain technology, and in particular to a blockchain transaction execution method and a blockchain node. Background Art

[0003] Blockchain is a novel application model for computer technologies, including distributed data storage, peer-to-peer transmission, consensus mechanisms, and encryption algorithms. In a blockchain system, data blocks are linked sequentially in chronological order to form a chain-like data structure, cryptographically guaranteeing an unalterable and unforgeable distributed ledger. Due to its decentralized, tamper-proof, and autonomous nature, blockchain is gaining increasing attention and application.

[0004] Summary of the Invention

[0005] The purpose of the present invention is to provide a blockchain transaction execution solution to improve the efficiency of transaction execution in the blockchain.

[0006] A first aspect of this specification provides a blockchain transaction execution method, which is executed by a blockchain node, the method comprising:

[0007] Obtaining a first transaction, the first transaction invoking a first contract, the blockchain storing contract data for the first contract, the contract data including a first access information table, the first access information table including first storage location information of a first state variable requested to be read by the first contract;

[0008] Reading the first storage location information from the blockchain;

[0009] The value of the first state variable is read from the blockchain according to the first storage location information, for executing the first transaction.

[0010] A second aspect of this specification provides a blockchain node, including:

[0011] an acquiring unit, configured to acquire a first transaction, the first transaction invoking a first contract, contract data of the first contract stored in the blockchain, the contract data including a first access information table, the first access information table including first storage location information of a first state variable requested to be read by the first contract;

[0012] A reading unit is configured to read the first storage location information from the blockchain; and read the value of the first state variable from the blockchain according to the first storage location information, for executing the first transaction.

[0013] A third aspect of this specification provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed in a computer, the computer is caused to execute the method described in the first aspect.

[0014] A fourth aspect of this specification provides a blockchain node, comprising a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the method described in the first aspect is implemented.

[0015] In the solution provided in the embodiments of this specification, by pre-storing the read-write information in the contract in the blockchain when deploying the contract, the value of the state variable requested to be read by the transaction can be pre-read according to the read-write information stored in the blockchain when or before executing the transaction that calls the contract. This can reduce the time waiting for the read result during the transaction execution process and improve the processing efficiency of the blockchain. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] In order to more clearly illustrate the technical solutions of the embodiments of this specification, the following briefly introduces the drawings required for use in the description of the embodiments. 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 any creative labor.

[0017] FIG1 is a schematic diagram of deploying a smart contract in one embodiment;

[0018] FIG2 is a schematic diagram of calling a smart contract in one embodiment;

[0019] FIG3 is a schematic diagram of a blockchain data storage structure in one embodiment;

[0020] FIG4 is a schematic diagram of a blockchain data storage structure in one embodiment;

[0021] FIG5 is a schematic diagram of an EVM virtual machine module involved in a transaction processing process in one embodiment;

[0022] FIG6 is a schematic diagram of a slot structure in one embodiment;

[0023] FIG7 is a schematic diagram of a slot structure in one embodiment;

[0024] FIG8 is a flow chart of a method for deploying a contract in a blockchain according to an embodiment of this specification;

[0025] FIG9 is a schematic diagram of a contract call relationship in an embodiment of this specification;

[0026] FIG10 is a schematic diagram of contract data in an embodiment of this specification;

[0027] FIG11 is a flow chart of a blockchain transaction execution method according to an embodiment of this specification;

[0028] FIG12 is an architectural diagram of a blockchain node in an embodiment of this specification. DETAILED DESCRIPTION

[0029] To help those skilled in the art better understand the technical solutions in this specification, the following will provide a clear and complete description of the technical solutions in the embodiments of this specification, in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of this specification, not all of them. All other embodiments derived by those skilled in the art based on the embodiments in this specification without creative effort shall fall within the scope of protection of this specification.

[0030] Blockchains are generally categorized into three types: public, private, and consortium. Furthermore, various combinations exist, such as private + consortium, or consortium + public. Public blockchains offer the highest degree of decentralization. Examples include Bitcoin and Ethereum. Participants in public blockchains can access data records, participate in transactions, and compete for the right to record new blocks. Furthermore, participants (represented by nodes on the blockchain) can freely join and exit the network and perform related operations. In contrast, private blockchains have write permissions controlled by a specific organization or institution, while data read permissions are regulated by the organization. Simply put, a private blockchain can be a weakly centralized system with a small and strictly limited number of participating nodes. This type of blockchain is more suitable for internal use within a specific organization. Consortium blockchains fall somewhere between public and private blockchains, achieving "partial decentralization." Each node in the consortium chain usually has a corresponding entity or organization; participants join the network through authorization and form a stakeholder alliance to jointly maintain the operation of the blockchain.

[0031] Whether public, private, or consortium blockchains, most offer smart contract functionality. Smart contracts on the blockchain are contracts that can be triggered and executed by transactions on the blockchain system. Smart contracts can be defined in code.

[0032] Taking Ethereum as an example, supporting users to create and invoke complex logic within the Ethereum network is the biggest challenge that distinguishes Ethereum from Bitcoin blockchain technology. At the core of Ethereum, as a programmable blockchain, is the Ethereum Virtual Machine (EVM), which runs on every Ethereum node. The EVM is a Turing-complete virtual machine, meaning it can implement a wide range of complex logic. When users publish and invoke smart contracts within Ethereum, they are executing on the EVM. In reality, the virtual machine directly runs virtual machine code (virtual machine bytecode, hereinafter referred to as "bytecode"). Smart contracts deployed on the blockchain can be in bytecode form.

[0033] For example, as shown in Figure 1, after Bob sends a transaction containing information to create a smart contract to the Ethereum network, the EVM on Node 1 executes the transaction and generates a corresponding contract instance. "0x6f8ae93..." in Figure 1 represents the address of the contract. The transaction's data field may contain bytecode, and the transaction's to field is an empty account. Once consensus is reached between the nodes, the contract is successfully deployed and can be subsequently invoked by users.

[0034] After a contract is successfully deployed, a contract account corresponding to the smart contract appears on the blockchain with a specific address. The contract code and account storage are stored in this contract account. The smart contract's behavior is controlled by the contract code, while the smart contract's account storage stores the contract's state. In other words, a smart contract creates a virtual account on the blockchain that contains the contract code and account storage.

[0035] As mentioned above, the data field of a transaction that creates a smart contract may include the bytecode for that smart contract. Bytecode consists of a series of bytes, each of which identifies an operation. For reasons of development efficiency and readability, developers can choose to write smart contract code in a high-level language rather than directly writing bytecode. Smart contract code written in a high-level language is compiled by a compiler to generate bytecode, which can then be deployed on the blockchain. Ethereum supports many high-level languages, such as Solidity, Serpent, and LLL.

[0036] Taking the Solidity language as an example, contracts written in it are very similar to classes in object-oriented programming languages. A contract can declare multiple members (or objects), including state variables, functions, function modifiers, events, etc. State variables are values ​​stored in the smart contract's account storage and are used to save the contract's state.

[0037] The following is a code example of a simple smart contract written in Solidity language 1:

[0038] Code Example 1. SimpleStorage Code

[0039] In the code example 1 above, line 2 declares the state variable storedData of type string, and line 3 declares an event, which stores the address of the initiator of the contract call and the string s. Lines 4-7 define the set function, which takes the string s as its input. The set function sets the input parameter to the state variable storedData and generates an event whose content includes the address of the initiator of the contract call and the string s.

[0040] As mentioned above, the state variables will eventually be stored in the database. The generated events are generally in the following form: [topic1][topic2]...[topicn][data]

[0041] Here, the first topic, topic1, is generally the default value, such as the receipt identifier, which can be a hash value obtained by sequentially concatenating the event name, event parameter type, etc. Whether each topic exists from topic2 to topicn depends on whether the Indexed modifier is added when defining the parameter. If so, the value of this parameter will be a topic in the receipt, and the one without the Indexed modifier will generally be placed in the data. In the example of code example 1 above, when declaring the event in line 3, the two parameters address from and s have no Indexed modifier and are generally placed in the data. The code in line 6 sets the data content [msg.sender, s] in the event through the stored() event. In this way, for the event operated on line 6, the overall format is: [topic1: event identifier][data:msg.sender, s]

[0042] Lines 8-10 define the get function. This function's operations include returning the value of the queried storedData . returns(string) indicates the type of the return value, and the constant modifier indicates that this function cannot modify the value of the state variable in the contract.

[0043] Furthermore, as shown in Figure 2, still using Ethereum as an example, after Bob sends a transaction containing information to call a smart contract to the Ethereum network, the EVM of Node 1 can execute this transaction and generate the corresponding contract instance. The from field of the transaction in Figure 2 is the address of the account initiating the smart contract call, the "0x6f8ae93..." in the to field represents the address of the smart contract being called, and the data field of the transaction stores the method and parameters used to call the smart contract. After calling the smart contract, the value of storedData may change. Later, a client can view the current value of storedData through a blockchain node (for example, Node 6 in Figure 2).

[0044] Smart contracts can be executed independently on each node in the blockchain network in a prescribed manner, and all execution records and data are stored on the blockchain. Therefore, when such a transaction is completed, the blockchain stores transaction credentials that cannot be tampered with or lost.

[0045] As mentioned above, the storedData in the above example is a state variable, which is stored in the smart contract's account storage. In various blockchain networks that introduce smart contracts, such as Ethereum, accounts can generally be of two types:

[0046] Contract account: stores the executed smart contract code and the state value in the smart contract code, and can usually only be activated by external account calls;

[0047] Externally owned account: A user's account.

[0048] The design of external accounts and contract accounts is essentially a mapping of account addresses to account states. Account states typically include fields such as Nonce, Balance, Storage root, and CodeHash. Nonce and Balance exist in both external accounts and contract accounts. CodeHash and Storage root properties are generally only valid for contract accounts.

[0049] Nonce: A counter. For external accounts, this number can represent the number of transactions sent from the account address; for contract accounts, it can be the number of contracts created by the account.

[0050] Balance: Account balance.

[0051] Storage root: The hash of the root node of an MPT tree. This MPT tree organizes the storage of the state variables of the contract account.

[0052] CodeHash: The hash value of the smart contract code. For contract accounts, this is the hash value of the smart contract. For external accounts, since they do not include a smart contract, the CodeHash field can generally be an empty string or a string of all zeros.

[0053] MPT stands for Merkle Patricia Tree, a tree structure that combines the Merkle Tree and the Patricia Tree (a compressed prefix tree, a more space-efficient Trie tree, also known as a dictionary tree). The Merkle Tree algorithm calculates a hash value for each transaction, then hashes each transaction again, until the top-level Merkle root is reached. Ethereum uses a modified MPT tree, such as a hexadecimal tree structure, often referred to as the MPT tree.

[0054] The data structure of the Ethereum MPT tree includes a state trie. The state trie contains key-value pairs (kv or kv) representing the storage content of each account in the Ethereum network. A "key" in the state trie can be a 160-bit identifier (such as an Ethereum account address or a portion of an address's hash value, collectively referred to as an account address). This account address is distributed across the storage from the root node to the leaf nodes of the state trie. The "values" in the state trie are generated by encoding Ethereum account information using Recursive-Length Prefix encoding (RLP). As mentioned previously, for external accounts, the values ​​include nonce and balance; for contract accounts, the values ​​include nonce, balance, codehash, and storageroot.

[0055] A contract account is used to store the state associated with a smart contract. Once a smart contract is deployed on the blockchain, a corresponding contract account is created. This contract account typically has certain states, defined by state variables in the smart contract and generating new values ​​when the smart contract executes. A smart contract is typically a contract defined in code within a blockchain environment that automatically executes its terms. Once an event triggers a term in the contract (meets the execution condition), the code automatically executes. In the blockchain, the state associated with a contract is stored in the storage trie. The hash value of the storage trie's root node is stored in the storageroot, locking all states of the contract to the contract account through the hash. The storage trie is also an MPT tree structure, storing a key-value mapping from state addresses to state values. Part of the information from the storage trie's root node to the leaf nodes is sequentially arranged to store the address of a state, while the leaf nodes store the state value.

[0056] In some blockchain data stores, as shown in Figure 3, each block's header includes several fields, such as the previous block's hash (prev_Hash, in the figure), a random number (in some blockchain systems, this nonce is not a random number, or in some blockchain systems, nonce in the block header is not enabled), a timestamp, a block number (Block Num), a state root hash (State_Root), a transaction root hash (Transaction_Root), and a receipt root hash (Receipt_Root). The Prev_Hash field in the block header of the next block (e.g., block N+1) points to the previous block (e.g., block N), which is the hash value of the previous block. In this way, the block header on the blockchain locks the previous block to the next block. State_Root, Transaction_Root, and Receipt_Root lock the state set, transaction set, and receipt set, respectively. The state set, transaction set, and receipt set organize the state, transactions, and receipts, respectively, in a tree format. Generally, these tree structures can be the same or different. For example, Ethereum uses the same MPT structure. In some tree structures like Ethereum, which include smart contract state collections, there are two levels of MPT structures: the leaf nodes of the upper-level MPT structure include two types: external accounts and contract accounts; each contract account includes the lower-level MPT structure, and the leaf nodes of the lower-level contain the state values ​​of the contract account.

[0057] Figure 4 is a schematic diagram of the blockchain data storage structure. Still using Ethereum as an example, and in conjunction with Figure 3, state_root is the hash value of the root of the MPT tree, which represents the states of all accounts in the current block. This means that the state trie, which points to state_root, is an MPT-style state trie. The root node of this MPT tree is typically an extension node or a branch node, and state_root typically stores the hash value of this root node. The root node can be connected to one or more layers of extension nodes / branch nodes below it. These multiple layers of tree nodes are collectively referred to as internal nodes. A portion of the values ​​in each node from the root to the leaf nodes of the MPT are sequentially concatenated to form an account address, which serves as the key. The account information stored in the leaf nodes is the value corresponding to this account address, thus forming a key-value pair. This key can also be a portion of the hash of the account address (using, for example, the SHA3 algorithm). The stored value can be RLP (Account), the RLP encoding of the account information. Account information is a four-tuple consisting of [nonce, balance, storageRoot, codeHash]. As mentioned earlier, external accounts typically only contain the nonce and balance fields, while the storageRoot and codeHash fields default to empty strings or all zeros. In other words, external accounts do not store contracts or state variables generated after contract execution. Contract accounts typically include Nonce, Balance, Storage Root, and CodeHash. Nonce is the transaction counter for the contract account; Balance is the account balance; Storage Root corresponds to another MPT and can be used to link to contract-related state information; CodeHash is the hash of the contract code. Account information for both external and contract accounts is generally stored in a separate leaf node. From the root node's Extension Node / Branch Node to each account's Leaf Node, there may be several branch nodes and extension nodes in between.

[0058] The state trie can be an MPT-style tree, typically a hexadecimal tree, meaning each layer can have up to 16 child nodes. Extension nodes, used to store common prefixes, typically have one child node, which can be a branch node. Branch nodes can have up to 16 child nodes, which may include extension nodes and / or leaf nodes.

[0059] For a contract account in the state trie, its storage_Root points to another MPT-formatted tree, which stores data related to state variables involved in contract execution. The MPT-formatted tree pointed to by storage_Root is the Storage Trie, which is the hash value of the Storage Trie's root node. Generally, this Storage Trie also stores key-value pairs. The key indicates the address of the state variable. Its value can be the result of processing the location of the state variable declaration in the contract (a value starting from 0) using certain rules, such as sha3 (location of the state variable declaration) or sha3 (contract name + location of the state variable declaration). The value is used to store the value of the state variable (for example, an RLP-encoded value). The key is formed by concatenating a portion of the data stored along the path from the root node through the intermediate nodes to the leaf nodes. The leaf nodes store the value. As mentioned earlier, the Storage trie can also be an MPT-style tree, typically a hexadecimal tree. This means a Branch Node can have up to 16 child nodes, which may include Extension Nodes and / or Leaf Nodes. An Extension Node can typically have one child node, which can be either a Branch Node or a Leaf Node.

[0060] For example, the Leaf Node Account P of the state trie in Figure 4 is a contract account, and its Storage Root locks all states in the contract storage. These states are organized into an MPT tree, and the tree structure is like the Storage trie linked to the Storage Root. In this linked Storage trie, taking Leaf Node State Variable N as an example, for example, the value of storedData in the aforementioned contract code example, its key can be, for example, but not limited to, sha3 (the declaration location of storedData), and its value is s (for the sake of simplicity, the encoding format of the value is omitted here, for example, RLP, which will be similar in the future and will not be repeated). Among them, the key values ​​are distributed sequentially from the root node to the leaf node (i.e., Leaf Node Variable N) of the storage trie.

[0061] For another example, in the state trie of Figure 4, Leaf Node Account C is an external account, and its key is sha3(Address C), which is the hash value of the address of account C (the hash algorithm uses the sha3 algorithm, for example). The stored value value can be (Account), where the account information Account is a tuple consisting of [nonce, balance]. As mentioned above, since Account C is an external account, its account information includes two items: nonce and balance (excluding codehash and storage root, similar to the following). For example, if an external account has a nonce of 20 and a balance of 4550, then the leaf node Leaf Node State Variable C stores nonce = 20 and balance = 4550. The address of Account C is the key, and its values ​​are distributed sequentially from the root node to the leaf node (i.e., Leaf Node Variable C) of the state trie.

[0062] As described above, after a transaction creating a smart contract is sent to the blockchain and consensus is reached on the transaction, each blockchain node can execute the transaction. A contract account corresponding to the smart contract appears on the blockchain (including, for example, the account's identity, the contract's hash value, and the contract's storage root, StorageRoot) with a specific address. The contract code and account storage are stored in the contract account's storage, as shown in Figure 5. The smart contract's behavior is controlled by the contract code, while the smart contract's account storage stores the contract's state. In other words, a smart contract creates a virtual account on the blockchain containing the contract code and storage. Contract deployment or contract update transactions generate or modify the Codehash value. Subsequently, blockchain nodes can receive transaction requests to invoke the deployed smart contract. These transaction requests may include the address of the invoked contract, the function within the invoked contract, and the input parameters. Generally, after consensus is reached on the transaction request, each blockchain node can independently execute the designated smart contract.

[0063] The left side of Figure 5 shows an example of a smart contract written in Solidity and its compilation and execution process. This smart contract is compiled by a compiler to generate bytecode. The solc command-line compiler in the figure represents Solidity. Ethereum smart contracts written in Solidity can be compiled using the solc command-line tool with parameters to generate bytecode that can be run on the EVM. After the contract deployment process described in Figure 1, a smart contract is successfully created on the blockchain. After the contract is deployed, a contract account corresponding to the smart contract is generated on the blockchain. This contract account includes information such as the contract counter Nonce, the account balance Balance, the contract bytecode hash Codehash, and the contract storage root StorageRoot. The contract has a specific address on the blockchain, known as the contract address.

[0064] In Ethereum, for example, this contract address is calculated by hashing the address of the external account that deployed the contract and its counter nonce. Specifically, an example is sha3(rlp.encode([address_sender, nonce])). (As mentioned above, rlp is an encoding format. Different blockchains can use other encoding formats, or even no re-encoding, so rlp is omitted here.) sha3 is a type of hash algorithm, such as the commonly used keccak256. As mentioned above, rlp represents an encoding format. rlp.encode([address_sender, nonce]) performs rlp encoding on the contents enclosed in parentheses. The [address_sender, nonce] in the parentheses concatenates the address_sender of the external account that deployed the contract and its counter nonce. For example, using the keccak256 algorithm, a 256-bit hash value is obtained. Based on this hash value, the address of the deployed contract on the blockchain (for example, the first 20 bytes) can be obtained. 256 bits is equivalent to 32 bytes. Upon deployment, the account balance can be set to a default value of 0 or 0. The contract bytecode hash value, Codehash, can be calculated by the blockchain platform through hashing the contract bytecode. The contract storage root, StorageRoot, can be a default value or a hash value calculated from the root node of the underlying storage trie. This generally depends on whether the deployed contract performs initialization operations, such as executing the contract's constructor. If the deployed contract includes a constructor, it typically initializes state variables that will ultimately be stored in the underlying database. This initialization can be performed in the virtual machine. As described above, the initialized state variables can be used to construct an MPT tree, which can then be used to obtain the root node of the MPT tree and, in turn, the hash value of this root node. If the deployed contract does not include a constructor, the specific function may not be executed, and the blockchain platform will assign a default value to StorageRoot, such as a hash value of empty content.

[0065] After the contract is deployed, it can be called later, as described above. As shown in Figure 2, Bob initiates a transaction to the Ethereum network to call the smart contract. The contract executes, setting the state variable to the string "hello".

[0066] The execution of a contract can be specifically illustrated in Figure 5. For example, a transaction calling a contract in Figure 2 is sent to the blockchain network. After consensus is reached, each node can execute the transaction. The transaction's "to" field indicates the address of the called contract. Any node can use the contract's address to locate the contract account's storage, then read the codehash from the contract account's storage and, based on the codehash, find the corresponding contract bytecode. The node can load the contract's bytecode from storage into the virtual machine. The interpreter then interprets and executes the contract. For example, this involves parsing the called contract's bytecode (e.g., parsing Push, Add, SGET, SSTORE, Pop, etc.) to obtain the opcodes and functions. These opcodes are then stored in memory allocated by the virtual machine (alloc in the figure; the corresponding memory release operation after program execution, e.g., Free in the figure). The interpreter also obtains the jump code of the called function in the memory space. Generally, after calculating the gas required to execute the contract and ensuring that sufficient gas is available, the contract jumps to the corresponding address in memory, retrieves the OPcode of the called function, and begins execution. The data operated on by the called function's OPcode is computed (data computation), pushed onto / popped from the stack, and so on, completing the data computation. During this process, some contract context information may be required, such as the block number and information about the initiator of the contract call. This information can be obtained from the Context (Get operation). Finally, the resulting state is stored in the database storage by calling the storage interface. It should be noted that during the contract creation process, certain functions within the contract may be executed, such as the initialization function. This also involves code parsing, generating jump instructions, storing them into memory, and performing operations on the stack.

[0067] Through the above process, the virtual machine loads and executes the contract's bytecode, which may generate and / or read state, thus requiring access to the underlying database. The virtual machine needs convenient access to the underlying key-value database. This access is generally achieved using pointer-like data access capabilities. For example, in Ethereum, if you need to read the value corresponding to a key from the KV database, you must know the key of the data before accessing it.

[0068] Each contract generally has its own virtual storage space, the capacity of which can be a very large array, for example, 2 256 An array of elements, numbered from 0 to 2 256-1. Each element can occupy a certain length, for example, 32 bytes. Each element is called a slot. FIG6 is a schematic diagram of a slot structure in one embodiment. It should be noted that a total of 2 256 The storage space of each slot is the total capacity of the virtual space, that is, unused slots do not occupy the actual storage space of the underlying database.

[0069] During the virtual machine's execution of contract bytecode, the slot locations of identical state variables in the virtual storage space must be fixed, ensuring that the keys generated during contract execution are consistent. This fixed location is typically established once the contract code is finalized. Therefore, the task of fixing the location of state variables is typically determined during the compiler compilation phase and is not directly related to the virtual machine.

[0070] The compiler compilation process can generally include the following steps: generating an abstract syntax tree, performing lexical / syntactic analysis based on the abstract syntax tree, filling symbols according to the symbol table, semantic analysis, and code generation. The abstract syntax tree includes a plurality of nodes arranged in sequence, and the plurality of nodes correspond to the plurality of objects declared in the contract. The arrangement order of the plurality of nodes corresponds to the declaration position of the plurality of objects in the contract, and the plurality of objects include the first state variable. In the link of performing lexical / syntactic analysis based on the abstract syntax tree, the slot position information of the state variable of the contract can be generated. Assume that the code of contract C1 is as follows:

[0071] Code Example 2. Solidity code for contract C1

[0072] Based on the contract code, for example, the following abstract syntax tree is generated: In the abstract syntax tree, information related to an object is placed in a node. These objects include, for example, state variables A and B, and mapping relationships "tokenOwner" and "ownedTokensCount". The multiple nodes corresponding to multiple objects are arranged in the order in which the objects are declared in the contract. For example, the 0th node in the abstract syntax tree corresponds to the state variable A, the 1st node in the abstract syntax tree corresponds to the state variable B, the 2nd node in the abstract syntax tree corresponds to the mapping relationship tokenOwner, and the 3rd node in the abstract syntax tree corresponds to the mapping relationship ownedTokensCount. Each node contains a number of information. Overall, the information inside a node can be called the node information of the abstract syntax tree.

[0073] For the abstract syntax tree of contract C1, the two state variables A and B in contract C1 have node positions 0 and 1 in the abstract syntax tree respectively, which can correspond to the following two slots in Figure 6: 0x0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0x0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0001

[0074] Each of the two slots above is 256 bits, which is 32 bytes when represented by hexadecimal (0x). Four consecutive hexadecimal digits in each segment separated by spaces after 0x represent 2 bytes, so there are 16 such segments in total.

[0075] In this way, in the contract bytecode compiled by the compiler, these two positions in the slot can be used to replace the identifiers of the two state variables, such as the two 256 bits mentioned above replacing A and B respectively. In this way, when the data type is a fixed-size value, the compilation process can pre-allocate storage locations for each data to be stored based on the field sorting order, which is equivalent to specifying a fixed data pointer in advance.

[0076] During the process of loading and executing the contract bytecode in the virtual machine, the operation on A is the operation on the slot position corresponding to 0x000...00 (i.e., position 0 of the above slot, with ellipsis replacing the more 0s in the middle). Similarly, the operation on B is the operation on the slot position 0x000...01.

[0077] Figure 7 illustrates slot operations. For example, a transaction calling contract C1 invokes the setA() function within that contract with the string "0001" as an argument. During the execution of this transaction, the virtual machine stores 0001 in the slot 0x000...01. Specifically, the virtual machine pushes the 32-byte slot 0x000...01 onto the stack, followed by the corresponding value. During interpretation and execution, the virtual machine retrieves the opcode of the called function from memory and begins execution. Based on the stack's first-in, last-out (FIFO) or last-in, first-out (LIFO) nature, the value is popped from the stack, and the slot is then popped from the stack, forming a slot-value pair. The contract virtual machine then executes the opcode, writing the value to the slot. This slot acts as a serial number, uniquely identifying the contract's state variables during contract execution. In the above process, the stack generally uses 32 bytes as a storage unit, which is equal to the length of one slot. The corresponding value may be less than, equal to, or greater than 32 bytes, so the value may occupy one or more units in the stack.

[0078] As shown in Figure 7, for example, a transaction calling contract C1 calls the setB() function in the contract with an input parameter of "36". When the virtual machine executes the transaction, it stores 36 in the slot 0x000...02.

[0079] The results of the execution of the above two contracts can be simply expressed as follows: 0x000...00:0001 (1) 0x000...01:36 (2)

[0080] After the virtual machine is executed, the virtual machine or blockchain platform can convert the slots in the two slot-value pairs (1) and (2) into state keys. Specifically, the state key (i.e., the storage key of the state variable in the storage tree) can be obtained by splicing the contract address + slot position. For example, the address length of contract C1 is 20 bytes, which is 0x3321 dcaf 8911 d384 2e14 a7a4 15be 2fb1 a337 f43e. After splicing the contract address + slot position,

[0081] (1) The corresponding state key of state variable A is: 0x3321dcaf8911d3842e14a7a415be2fb1a337f43e00000000000000000000000000000000000 00000000000000000000000000000000

[0082] (2) The corresponding state key of state variable B is: 0x3321dcaf8911d3842e14a7a415be2fb1a337f43e00000000000000000000000000000000000 000000000000000000000000000000001

[0083] Afterward, blockchain nodes can store these generated state key-value pairs in the underlying database. Specifically, blockchain nodes may include a tree construction module and a state database module. The tree construction module converts these keys into a storage trie, as shown in Figure 4, and constructs the value in the state key-value pair into a leaf node of this MPT tree. It should be noted that, as previously mentioned, the state key is split into several segments, which are stored sequentially in the tree nodes from the root of the storage trie to the leaf nodes. Which segment of the state key is stored in each tree node depends on whether the state key shares a prefix with other state keys in the tree. From the leaf node, through the intermediate nodes, to the root node, a series of hash value changes occur, and the tree construction module constructs the key-value pairs of these tree nodes. The tree construction module then sends these changed tree node key-value pairs to the state database module, which then stores them in the state database.

[0084] In the above process, the slots for state variables are fixed during compilation. As mentioned above, they are determined by the contract address and the slot location of the state variable. The state key can be obtained by concatenating the contract address and the slot. This way, when running the same contract and reading or writing the same state variable, the same slot is used, corresponding to the fixed state key.

[0085] It should be noted that the state variables A and B in the above example are of type uint256 and bool, respectively. uint256 is 256 bits, or 32 bytes, and bool is 1 byte. The type of these state variables determines that the data length is fixed, or fixed-length. In addition, types such as uint, uint8, and uint128 are also fixed-length. Arrays consisting of a fixed number of fixed-length elements are also fixed-length. For example, uint[2] consists of two elements, each of which is a 32-byte uint type, so uint[2] is 64 bytes in total.

[0086] In addition to fixed-length data storage, there are also variable-length data, or data whose size is unpredictable. In this case, the fixed-length approach cannot directly determine the slot location during compilation, so a different solution is used.

[0087] For example, in contract C1, mapping(uint256=>address)tokenOwner and mapping(uint256=>Counter)ownedTokensCount are defined after state variables A and B. This is a mapping relationship, which is a data type of indeterminate length. In the example of mapping(uint256=>address)tokenOwner, tokenOwner is the name of the mapping relationship.

[0088] The mint function in contract C1, for example, is used to mint NFT resources. Its input parameter, address to, is the recipient's account address of the minted NFT resource, and token id is the identifier of the minted NFT resource. Based on the previously defined mapping relationship, the mapping element tokenOwner[tokenid] = to, ownedTokensCount[to], increment() is defined in the mint function. This mapping element is a state variable and will be stored in the state database. For example, in the case of tokenOwner[tokenid] = to, tokenid and to are the two input parameters of the mint function. Tokenid can also be called the key of the mapping relationship tokenOwner.

[0089] As shown in Figure 7, when the contract code is compiled, the name of the mapping relationship tokenOwner can be assigned the slot 0x000...02 according to the position of the node corresponding to the mapping relationship tokenOwner in the abstract syntax tree (i.e., the second position). Since tokenOwner is not a state variable, there is no value in this slot. Similarly, the mapping relationship ownedTokensCount can be assigned the slot with a position value of 0x000...03.

[0090] When the virtual machine executes contract C1, it can uniquely determine the slot of the mapping element corresponding to the key based on the key of the mapping relationship and the slot of the mapping relationship name. The slot is, for example: keccak256(key.slot), where "." is a concatenation symbol, and the slot after "." is the position of the slot where the mapping relationship name is located. The number of mapping elements of the mapping relationship is uncertain, and the length of the key and value in the element is also uncertain. For example, after contract C1 is called several times, there may be two elements of the mapping relationship tokenowner, namely: tokenowner["nft1"]=Account1; tokenowner["nft2"]=Account2;

[0091] The key of the first mapping element in the mapping relationship tokenOwner is nft1, and the value is Account1. The slot position of the corresponding mapping element tokenOwner[nft1] can be keccak256("nft1".0x000...02), and the value can be stored in one or more consecutive slots starting from this position (for example, the data length of the value is greater than 32 bytes). Similarly, the key of the second mapping element in the mapping relationship tokenOwner is nft2, and the value is Account2. The slot position of the corresponding mapping element tokenOwner[nft2] can be keccak256("nft2".0x000...02), and the value can be stored in one or more consecutive slots starting from this position (for example, the data length of the value is greater than 32 bytes).

[0092] For example, the length of the tokenOwner[nft1] value is less than 32 bytes, and the length of the tokenOwner[nft2] value is greater than 32 bytes and less than 64 bytes.

[0093] As shown in Figure 7, the length of the tokenOwner[nft1] value is less than 32 bytes, and its value can be stored in one slot. The location of this slot is, for example, the value of keccak256("nft1",0x000...02), for example: 0x000...05

[0094] Assume that the length of the tokenOwner[nft2] value is greater than 32 bytes and less than 64 bytes. Its value can be stored in two consecutive slots. The starting positions of these two slots are, for example, the values ​​of keccak256("nft2", 0x000...02). The positions of these two slots are, for example: 0x000...07 0x000...08.

[0095] Similarly, when executing contract C1, the virtual machine can uniquely determine the slot of each element based on the key of the mapping element ownedTokensCount[to] and the slot of the mapping relationship ownedTokensCount, that is, keccak256("to".0x000...03). For example, as shown in Figure 7, the slot of ownedTokensCount[Account1] can be determined as: 0x5b4d ed6c c162 9f13 8186 f4b0 7950 04ad bed7 ec13 374d 15ca 04ec 96f1 4913 2460

[0096] The slot of ownedTokensCount[Account2] can be determined as: 0x9019 1b3f 1d96 c216 c6a6 637b 9c84 98bc 25cc 907a fe24 6d61 1b3a 8bf7 27bc 081d

[0097] That is, for a contract that includes a mapping relationship, after a transaction calls the contract and defines a mapping element, the slot of the mapping element can be uniquely determined based on the key of the mapping element in the transaction and the slot of the mapping relationship.

[0098] In the blockchain field, when a virtual machine executes a transaction that calls a contract, it reads the values ​​of the requested state variables from the state database in the order in which the contract's bytecode is executed. When reading the state, the virtual machine synchronously waits for the result of the storage access and then proceeds with subsequent execution steps. This means that multiple state variables are read serially during this process. Reading the state database is often very time-consuming, reducing overall execution efficiency.

[0099] To this end, an embodiment of this specification provides a transaction execution method, which pre-stores the read and write information in the contract in the blockchain when deploying the contract. Therefore, before executing the transaction that calls the contract, multiple state variables requested to be read in the contract can be pre-read according to the read and write information stored in the blockchain. The reading of multiple state variables can be executed in parallel, thereby improving the processing efficiency of the blockchain.

[0100] FIG8 is a flow chart of a method for deploying a contract in a blockchain according to an embodiment of this specification. The method can be executed by any blockchain node in the blockchain. The method includes the following steps S810-S820.

[0101] First, in step S810, the blockchain node receives transaction Tx1 for deploying contract Contract1, where transaction Tx1 includes contract data of the contract to be deployed, and the contract data includes an access information table and / or a call information table.

[0102] As mentioned above, the contract deployer can use a compiler to compile the solidity code of contract Contract1 to generate bytecode that can be run in a virtual machine (such as the EVM). During the compilation of the contract code, if the compiler includes declared objects in contract Contract1, it will generate corresponding object identifiers for the objects declared in the contract according to preset rules and convert the name of the declared object into the object identifier corresponding to the object in the generated bytecode.

[0103] The object identifier is, for example, the slot described above. Objects declared in the contract include, for example, state variables, mapping relationships, and other objects. It is understood that the object identifier is not limited to a slot, but can be an identifier generated using other preset rules to uniquely identify the object. For example, the object identifier can be generated based on attributes such as the object's name and length. In one embodiment, if the object declared in the contract is a state variable, the object identifier can be the storage key of the state variable in the state database.

[0104] Taking slots as an example, after the compiler generates the slots for each object declared in the contract, the compiler can generate the storage location information of the state variables accessed by the contract based on the identifiers of each object.

[0105] In one case, the state variable A accessed by the contract is a fixed-length variable, and its storage location information can be the slot of the state variable included in the contract bytecode.

[0106] In another case, the state variable accessed by the contract (e.g., variable B) is a state variable corresponding to a mapping relationship, and its storage location information may include parameter information associated with the mapping relationship, as well as the slot of the mapping relationship in the contract bytecode. The mapping relationship is, for example, associated with the sending account of the transaction, or the value of the storage object in the incoming parameters of the transaction to the contract, so that the parameter information is used to indicate the sending account of the transaction, or the incoming parameters of the transaction to the contract. For example, the contract Contract1 includes a mapping relationship a[], which is used to map the sending account of the transaction that calls the contract to the state variable a[from]. The storage location information of the state variable a[from] may include: "slota, {index 0}", where slota is the slot of the mapping relationship a, and index0 is used to indicate the from field of the transaction.

[0107] When compiling contract code, the compiler can determine not only the storage location information of each state variable but also the access mode for that state variable in the contract based on the contract code. Examples of access modes include read mode, write mode, or read and write mode. Thus, the compiler can generate an access information table for the contract. Refer to the access information table in the contract data shown in FIG10 . This access information table can include the access mode and storage location information for each state variable requested for access in the contract.

[0108] In one embodiment, a contract includes multiple functions, and the compiler can generate an access information table corresponding to each function. For example, if contract Contract1 includes functions method1 and method2, the compiler can generate an access information table corresponding to function method1 and an access information table corresponding to function method2.

[0109] When Contract 1 calls other contracts, the compiler can also determine the information of the called contracts based on the contract code of Contract 1. Specifically, the compiler can generate contract call information corresponding to each function in Contract 1. For example, if Contract 1 includes functions method1 and method2, the compiler can generate a call information table corresponding to function method1 and a call information table corresponding to function method2.

[0110] Assume that method1 of contract Contract1 includes the call relationship diagram shown in Figure 9. As shown in Figure 9, function method1 in contract Contract1 calls function method3 in contract Contract2 and function method4 in contract Contract3, and function method3 in contract Contract2 calls function method5 in contract Contract4. For method1, based on the contract code of contract Contract1, the compiler can obtain the contract address of Contract2 called by Contract1, the function name of function method3, and the parameters passed by function method1 to function method3 in Contract2; the contract address of Contract3, the function name of function method4, and the parameters passed by function method1 to function method4 in Contract3. This generates a call information table for function method1. The call information table corresponding to function method1 includes: the contract address of contract Contract2 called in function method1, the function name of function method3 in contract Contract2, and the input parameters of function method1 to function method3; the contract address of contract Contract3 called in function method1, the function name of function method4 in contract Contract3, and the input parameters of function method1 to function method4.

[0111] After performing the above operations, the compiler can generate contract data for the contract Contract1, which includes contract bytecode, and an access information table and / or a call information table. In the case where the contract Contract1 includes access objects but does not include calls to other contracts, the contract data includes contract bytecode and an access information table. In the case where the contract Contract1 does not include access objects but includes calls to other contracts, the contract data includes contract bytecode and a call information table. In the case where the contract Contract1 includes access objects and calls to other contracts, the contract data includes contract bytecode, an access information table, and a call information table.

[0112] Specifically, as shown in Figure 10, the contract data in the embodiments of this specification may include function data for each function in contract Contract1. Each function data includes the bytecode corresponding to that function, an access information table, and a call information table. As shown in Figure 10, the contract data for contract Contract1 includes function data for function method1 and function data for function method2, among others. The function data for function method1 is used as an example for description. The function data for function method1 includes the bytecode, access information table, and call information table. The access information table includes multiple read / write items, each corresponding to a state variable requested for access in function method1. Each read / write item includes access mode and storage location information. The call information table includes multiple call items, each corresponding to a call to another contract in function method1. Each call item includes the contract address of the contract called in function method1, the function name of the function called in the contract, and the parameters passed to the function of the called contract by function method1. It should be understood that the contract data in the embodiments of this specification is not limited to that shown in Figure 10.

[0113] It is understood that before deployment, each contract to be deployed is converted into contract data, such as that shown in Figure 10, for storage in the blockchain. For example, for the contract Contract2 shown in Figure 9, its contract data includes function data corresponding to function method3. This function data includes an access information table and a call information table for function method3. The call information table includes call information for function method5 in contract Contract4.

[0114] After the contract deployer generates contract data, such as that shown in Figure 10, through the compiler, it can generate a transaction Tx1 for deploying contract Contract1. The from field of transaction Tx1 is the deployer's account, the to field is empty, and the data field includes the contract data, such as that shown in Figure 10. The contract deployer can then send transaction Tx1 to the blockchain so that each node in the blockchain can receive it.

[0115] At S820 , the contract data is stored in the blockchain.

[0116] After receiving transaction Tx1 and reaching consensus on transaction Tx1, the blockchain node can execute transaction Tx1, thereby deploying contract Contract1 in the blockchain. Specifically, referring to the description above, the blockchain node determines the contract address of contract Contract1 and stores the contract data in transaction Tx1 in association with the contract address in the blockchain. For example, referring to the description of Figure 4 above, the state data of contract Contract1 is created in the state tree, and the CodeHash field in the state data records the hash value of the above contract data. The contract data is then stored in association with its hash value. This allows the contract data of contract Contract1 to be read based on CodeHash, and the bytecode of each function, access information table, or call information table can be read from the contract data.

[0117] By deploying the contract as shown in FIG8 , the blockchain node can read the contract data of the contract stored in the blockchain for the transaction that calls the contract, and pre-read the state variables requested to be read by the contract based on the information in the contract data, thereby improving the efficiency of transaction execution.

[0118] FIG11 is a flow chart of a blockchain transaction execution method in an embodiment of this specification.

[0119] As shown in FIG11 , in S110 , transaction Tx2 is obtained, wherein the blockchain stores contract data of the contract called by transaction Tx2, and the contract data includes storage location information of the state variables requested to be read by the contract.

[0120] For example, transaction Tx2 calls contract Contract1. The transaction body of transaction Tx2 includes the from field, to field, and data field. The from field is the transaction sending account, the to field is the contract address of contract Contract1, and the data field is the function in contract Contract1 called by transaction Tx2 (such as function method1) and the input parameters of the function.

[0121] A blockchain node (e.g., a master node) can receive transaction Tx2 from a client and thereby obtain the transaction data for transaction Tx2. After receiving transaction Tx2 from the client, the master node broadcasts transaction Tx2 to all other nodes in the blockchain. Each node in the blockchain can then obtain transaction Tx2 and execute the methods described in the embodiments of this specification. The following description uses a node in the blockchain as an example, but this node can be any node in the blockchain.

[0122] As described above, contract Contract 1 can be deployed in the blockchain using the method shown in FIG8 . Specifically, the blockchain stores contract data for Contract 1, which includes an access information table. This access information table includes, for example, storage location information for multiple state variables that Contract 1 requests to read. As described above, this access information table may also include storage location information for state variables that Contract 1 requests to write, as well as the access mode for each state variable in Contract 1. Furthermore, this contract data may also include the call information table described above.

[0123] At S120 , the storage location information of the state variables requested to be read by the contract Contract1 is read from the blockchain.

[0124] After receiving transaction Tx2, the blockchain node reads the contract data for Contract 1 from the blockchain based on the contract address of Contract 1 invoked in transaction Tx2. Specifically, referring to Figure 4, the blockchain node reads the state data for Contract 1 from the state tree based on the contract address of Contract 1, reads the CodeHash from this state data, and then reads the data corresponding to the CodeHash based on the CodeHash, i.e., the contract data for the CodeHash. This contract data may include the access information table and / or call information table for Contract 1.

[0125] For example, as shown in Figure 10, the contract data may include the bytecode, access information table, and call information table for each function in contract Contract1. The blockchain node can read the bytecode, access information table, and call information table of function method1 from the contract data, and obtain the storage location information of the state variables requested to be read from the access information table. Specifically, as described above, the access information table includes multiple read-write items, each of which includes access location information and access mode. The blockchain node can obtain the storage location information of each read-write item in the access information table whose access mode is read or read-write, that is, the storage location information of each state variable requested to be read by contract Contract1.

[0126] In S130 , the value of the state variable is read according to the storage location information of the state variable requested to be read by the contract Contract1.

[0127] In one embodiment, before executing transaction Tx2, a blockchain node may pre-read the state variables requested by function method1 based on the access information table and / or call information table of function method1 and the transaction body of transaction Tx2. In another embodiment, after starting to execute transaction Tx2, a blockchain node may pre-read the state variables requested by function method1 based on the access information table and / or call information table of function method1 and the transaction body of transaction Tx2. Pre-reading state variables saves time waiting for stored results when executing transaction Tx2.

[0128] Furthermore, when a request is made to read multiple state variables from function method1, the blockchain node can read the values ​​of these multiple state variables in parallel based on the access information table and / or call information table of function method1 and the transaction body of transaction Tx2, thereby saving storage read time. Specifically, the blockchain node can obtain multiple storage location information for the multiple state variables to be read based on the access information table and / or call information table of function method1 and the transaction body of transaction Tx2, and read the values ​​of these multiple state variables in parallel from the blockchain based on this multiple storage location information.

[0129] Specifically, referring to Figures 9 and 10, the blockchain node can generate a storage key (key) for the state variable in the state database (i.e., storage tree) based on the storage location information of one or more state variables read by the method1 request obtained above, and read the value of the state variable from the state database according to the storage key.

[0130] In one scenario, assume that the access information table includes read and write items for state variable A, where state variable A is a fixed-length variable. The storage location information of state variable A in the access information table can be the slot of the state variable included in the contract bytecode, and the access mode of state variable A in the access information table can be read mode or read-write mode. For state variable A, the blockchain node can combine (e.g., concatenate) the slot in its storage location information with the contract address to obtain the storage key keyA of state variable A. Before the blockchain node executes the read operation on state variable A in transaction Tx2, the value of state variable A is pre-read from the state database based on the storage key keyA.

[0131] In another case, the state variable (e.g., variable B) accessed by function method1 is a state variable corresponding to a mapping relationship. The storage location information of state variable B in the access information table may include parameter information associated with the mapping relationship and the slot of the mapping relationship in the contract bytecode. In the case where the parameter information is used to indicate the transaction sending account or the transaction incoming parameters, the blockchain node can calculate the slot of state variable B based on the parameter information in the storage location information, the slot of the mapping relationship, and the transaction data of transaction Tx2, and calculate the storage key keyB of state variable B based on the slot of state variable B. For example, the state variable B is the above-mentioned a[from], and its storage location information may include "slota, {index 0}. The blockchain node obtains the sending account of transaction Tx2 according to "index 0", and then calculates the slot of the state variable a[from] based on the sending account of transaction Tx2 and slota, so that the storage key keyB of the state variable a[from] can be calculated based on the slot of the state variable a[from]. Among them, the blockchain node can calculate the slot of the state variable a[from] based on the sending account of transaction Tx2 and slota according to the preset rules, and the preset rules are determined based on the world state model. For example, as described above, the blockchain node can splice the sending account and slota of transaction Tx2 together to obtain spliced ​​data, and take a hash value of the spliced ​​data to obtain the slot of the state variable a[from]. It can be understood that different world state models may have different preset rules.

[0132] Afterwards, the blockchain node can determine the storage key of the state variable a[from] based on the slot of the state variable a[from], and pre-read the value of the state variable a[from] from the state database according to the storage key of the state variable a[from].

[0133] If the function data of the function method1 includes a call information table corresponding to the call relationship shown in FIG9 , the call information table includes a call item corresponding to Contract2 / method3 and a call item corresponding to Contract3 / method4.

[0134] For the call item corresponding to Contract3 / Method4, the blockchain node reads the contract data for Contract3 from the blockchain and the function data for Method4 from this contract data, assuming that this function data includes the access information table for Method4. Similarly to the above, based on the storage location information for state variables whose access mode is read or read in the access information table for Method4, the blockchain node determines the storage key for the state variable requested to be read in Method4 and pre-reads the value of the state variable from the state database based on this storage key. Specifically, if the storage location information for the state variable requested to be read in Method4 indicates the parameter passed to Method4 in Method1, the blockchain node can determine the storage key for the state variable requested to be read in Method4 based on the read / write items in the access information table for Method4 and the parameter passed to Method4 in Method1. For example, for the state variable D in method4 that is mapped according to the mapping relationship and the input parameters, the blockchain node can obtain the slot of the state variable D based on the slot calculation of the input parameters of function method4 and the mapping relationship in function method1, calculate the storage key of the state variable D based on the slot, and read the value of the state variable D from the state database in advance based on the storage key.

[0135] For the call item corresponding to Contract2 / Method3, the blockchain node reads the contract data for Contract2 from the blockchain and the function data for Method3 from this contract data. Assuming this function data includes the access information table and call information table for Method3, the blockchain node pre-reads the values ​​of the state variables requested by Method3 based on the read and write entries in the access information table. Regarding the call information table for Method3, referring to Figure 9, the call information table includes a call item corresponding to Contract4 / Method5. Based on this call item, the blockchain node similarly reads the function data for Method5 in Contract4 and, based on this function data, pre-reads the values ​​of the state variables requested to be read in Method5. In this manner, the blockchain node can recursively pre-read the values ​​of the state variables requested to be read at each call level in Transaction Tx2.

[0136] In another embodiment, a blockchain node may obtain multiple transactions, obtain contract data of contracts called by the multiple transactions based on the multiple transactions, obtain multiple storage location information of multiple state variables requested to be read by the multiple transactions based on the contract data of each transaction call contract, and thus read the values ​​of the multiple state variables in parallel based on the multiple storage location information, thereby improving the efficiency of executing the multiple transactions in the blockchain.

[0137] Specifically, the blockchain node can determine the read-write set for each transaction based on the access information table and / or call information table in the contract data of the multiple transaction call contracts, and group the multiple transactions according to the read-write set of each transaction to obtain multiple transaction groups. The read-write set includes the read-write keys of the state variables accessed by each transaction. Specifically, for the state variable A accessed in transaction Tx2 above, the blockchain node can use the storage key of state variable A (e.g., the concatenation of SlotA and the contract address) as the read-write key for state variable A in the read-write set of transaction Tx2. For the state variable a[from] accessed in transaction Tx2, in one embodiment, the blockchain node can use the storage key of state variable a[from] as the read-write key for state variable a[from] in the read-write set of transaction Tx2. In another embodiment, the blockchain node can use the concatenation of slotA and the contract address as the read-write key for state variable a[from] in the read-write set of transaction Tx2.

[0138] The blockchain node may perform the following operations in parallel for each transaction group: based on the access information table and / or call information table of multiple transactions in the transaction group, obtain multiple storage location information for multiple state variables to be read corresponding to the transaction group; pre-read the values ​​of the multiple state variables from the blockchain based on the multiple storage location information; and execute the multiple transactions in the transaction group based on the read state variable values. Specifically, the blockchain node may pre-read the values ​​of the multiple state variables from the blockchain based on the multiple storage location information and the multiple transactions.

[0139] Through the above method, a blockchain node can obtain the storage key of the state variable requested by a transaction based on the contract data of the contract pre-stored in the blockchain. The value of the state variable can be read in advance, or after the transaction begins and before the read operation on the state variable in the transaction is executed, the value of the state variable can be read. This saves time waiting for the read result during the transaction execution, improves the efficiency of transaction execution, and improves the efficiency of the blockchain system. In addition, when a transaction requests to read multiple state variables, the storage keys of the multiple state variables to be read can be obtained based on the contract data, and the multiple state variables can be batch read according to the storage keys of the multiple state variables. In this batch read, the values ​​of the multiple state variables can be read in parallel, thus saving time waiting for the read result compared to serial reading of the values ​​of multiple state variables. In the case of multiple transactions requesting to read multiple state variables, the blockchain node can obtain the storage keys of the multiple state variables to be read based on the contract data of the multiple transaction call contracts, and similarly batch read the multiple state variables according to the storage keys of the multiple state variables, thereby saving transaction execution time and improving the processing efficiency of the blockchain.

[0140] FIG12 is an architecture diagram of a blockchain node in an embodiment of this specification, which is used to execute the method shown in FIG8 or FIG11, including:

[0141] An acquiring unit 121 is configured to acquire a first transaction, the first transaction invoking a first contract, contract data of the first contract stored in the blockchain, the contract data including a first access information table, the first access information table including first storage location information of a first state variable requested to be read by the first contract;

[0142] The reading unit 122 is configured to read the first storage location information from the blockchain; and read the value of the first state variable from the blockchain according to the first storage location information, for executing the first transaction.

[0143] The embodiments of this specification also provide a computer-readable storage medium having a computer program stored thereon. When the computer program is executed in a computer, the computer is caused to execute the method shown in FIG. 8 or FIG. 11 .

[0144] The embodiments of this specification also provide a blockchain node, including a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the method shown in Figure 8 or Figure 11 is implemented.

[0145] In the 1990s, technological improvements could be clearly distinguished as either hardware improvements (for example, improvements to circuit structures like diodes, transistors, and switches) or software improvements (improvements to process flows). However, with the advancement of technology, many process flow improvements today can now be considered direct improvements to hardware circuit structures. Designers almost always create the corresponding hardware circuit structure by programming the improved process flow into the hardware circuit. Therefore, it cannot be said that a process flow improvement cannot be implemented using hardware modules. For example, a programmable logic device (PLD), such as a field programmable gate array (FPGA), is an integrated circuit whose logical function is determined by user programming. Designers can "integrate" a digital system on a PLD by programming it themselves, without having to hire a chip manufacturer to design and manufacture a dedicated integrated circuit chip. Moreover, nowadays, instead of manually fabricating integrated circuit chips, this programming is mostly done using "logic compiler" software. This is similar to the software compiler used when developing programs. Before compilation, the original code must also be written in a specific programming language, called a hardware description language (HDL). There is not just one HDL, but many, 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 are VHDL (Very-High-Speed ​​Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art will also understand that by simply programming the method flow in one of these hardware description languages ​​and then programming it into an integrated circuit, a hardware circuit that implements the logic method flow can be easily obtained.

[0146] The controller can be implemented in any suitable manner. For example, the controller can take the form of a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro)processor, logic gates, switches, application-specific integrated circuits (ASICs), programmable logic controllers, and embedded microcontrollers. 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 will also know that in addition to implementing the controller in a purely computer-readable program code format, the controller can be implemented in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers by logically programming the method steps. Therefore, such a controller can be considered a hardware component, and the devices included therein for implementing various functions can also be considered as structures within the hardware component. Or even, the devices for implementing various functions can be considered as both software modules that implement the method and structures within the hardware component.

[0147] 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, this application does not exclude that with the future development of computer technology, the computer that implements the functions of the above embodiments may be, for example, a personal computer, a laptop computer, an in-vehicle 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.

[0148] Although one or more embodiments of this specification provide method operation steps as described in the embodiments or flow charts, more or fewer 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 "comprise", "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 clearly listed, or also includes elements inherent to such 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 particular order.

[0149] For the convenience of description, the above devices are described in terms of functions divided into various modules. Of course, when implementing one or more of the present specifications, the functions of each module can be implemented in the same or multiple software and / or hardware, or the module that implements the same function can be implemented by a combination of multiple sub-modules or sub-units, etc. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as 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 an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.

[0150] The present invention is described with reference to the flowcharts and / or block diagrams of the 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 produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device produce a device for implementing the functions specified in one or more processes in the flowchart and / or one or more blocks in the block diagram.

[0151] These computer program instructions may also be stored in a computer-readable memory that can direct 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 a manufactured product including an instruction device that implements the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.

[0152] 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, so that the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.

[0153] 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 disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape, 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 transitory media such as modulated data signals and carrier waves.

[0154] Those skilled in the art will appreciate that one or more embodiments of this specification may be provided as a method, system, or computer program product. Thus, one or more embodiments of this specification may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. Furthermore, one or more embodiments of this specification may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0155] One or more embodiments of this 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, and the like that perform specific tasks or implement specific abstract data types. One or more embodiments of this specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communications network. In distributed computing environments, program modules may be located in local and remote computer storage media, including storage devices.

[0156] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between the various embodiments can be referenced across them. Each embodiment focuses on the differences from the other embodiments. In particular, since the system embodiments are generally similar to the method embodiments, their description is relatively simple. For relevant parts, reference can be made to the description of the method embodiments. Throughout this specification, reference to the terms "one embodiment," "some embodiments," "examples," "specific examples," or "some examples" means that the specific features, structures, materials, or characteristics described in conjunction with that embodiment or example are included in at least one embodiment or example of this specification. In this specification, the schematic representations of these terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples. Furthermore, those skilled in the art may combine and integrate the different embodiments or examples, and features of different embodiments or examples, described in this specification, without conflict.

[0157] The foregoing is merely an example of one or more embodiments of this specification and is not intended to limit the one or more embodiments of this specification. It will be apparent to those skilled in the art that various modifications and variations may be made to one or more embodiments of this specification. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of this specification shall be included within the scope of the claims.

Claims

1. A blockchain transaction execution method, executed by a blockchain node, the method include: Obtaining a first transaction, the first transaction calling a first contract, the blockchain storing contract data of the first contract, the contract data including a first access information table, the first access information table including first storage location information of a first state variable requested to be read by the first contract; Reading the first storage location information from the blockchain; The value of the first state variable is read from the blockchain according to the first storage location information for executing the first transaction.

2. According to the method of claim 1, the first access information table includes a plurality of the first storage location information of the plurality of the first state variables requested to be read by the first contract, and the first storage location information is read from the blockchain include: Reading the plurality of first storage location information from the blockchain; Reading the value of the first state variable from the blockchain according to the first storage location information includes: reading multiple values ​​of the first state variables from the blockchain in parallel according to multiple pieces of the first storage location information.

3. The method according to claim 1, in, The obtaining of the first transaction includes obtaining a plurality of first transactions, the reading of the first storage location information from the blockchain includes reading a plurality of first storage location information corresponding to the plurality of first transactions from the blockchain, and the reading of the value of the first state variable from the blockchain according to the first storage location information includes reading the values ​​of the plurality of first state variables from the blockchain in parallel according to the plurality of first storage location information.

4. The method according to claim 3, wherein the first access information table further includes second storage location information of a second state variable requested to be written by the first contract. The method also include: grouping the plurality of first transactions based on the first storage location information and the second storage location information of each first transaction to obtain a plurality of transaction groups; The reading the value of the first state variable from the blockchain according to the first storage location information includes: Before executing a first transaction group among the multiple transaction groups, values ​​of multiple first state variables corresponding to the first transaction group are read from the blockchain according to multiple first storage location information corresponding to the first transaction group.

5. According to the method according to claim 1, the contract data includes first function data corresponding to the first function in the first contract, the first function data includes the first access information table, and the first access information table includes storage location information of the first state variable requested to be read by the first function.

6. According to the method of claim 1, the storage location information of the first state variable is obtained based on at least one of the following: the location information of the first state variable in the contract code, the name of the first state variable, and the length of the first state variable.

7. The method according to claim 1, wherein the first state variable is mapped to the first information in the first transaction according to a mapping relationship, the first storage location information includes an identifier of the mapping relationship and second information, and the second information is used to indicate the first information; The step of reading the value of the first state variable from the blockchain according to the first storage location information include: The first information is acquired from the first transaction based on the second information, and the value of the first state variable is read based on the identifier of the mapping relationship and the first information.

8. The method according to claim 5, wherein the first function includes a call to a second contract, and the first function data also includes first call information corresponding to the second contract, and the first call information includes an address of the second contract and a function name of the second function in the second contract. The method also include: Reading the first call information from the blockchain; Reading second function data corresponding to the second function from the blockchain according to the address of the second contract and the function name of the second function in the first call information, wherein the second function data includes a second access information table, and the second access information table includes third storage location information of a third state variable requested to be read by the second function; The value of the third state variable is read according to the third storage location information to execute the first transaction.

9. The method according to claim 8, wherein the first call information further includes parameters passed by the first function to the second function. reading the value of the third state variable according to the third storage location information include: The value of the third state variable is read according to the third storage location information and the input parameter.

10. The method according to claim 1 or 2, further comprising: include: receiving a second transaction, where the second transaction is used to deploy the first contract, and the second transaction includes contract data of the first contract; According to the second transaction, the contract data of the first contract is stored in the blockchain.

11. The method according to claim 1 or 2, wherein the first access information table also includes an access mode of the state variables that the first contract requests to access.

12. The method according to claim 7, wherein the first contract corresponds to a plurality of numbers arranged in order of size, the identifier of the mapping relationship includes a first number among the plurality of numbers, the first number is determined based on a declaration position of the mapping relationship in the first contract, and the first information includes a sending account of the first transaction or an input parameter to the first contract in the first transaction; The reading the value of the first state variable based on the identifier of the mapping relationship and the first information includes: Determine a second number of the first state variable based on a sending account of the first transaction or an input parameter of the first contract in the first transaction, and the first number; The value of the first state variable is read from the blockchain based on the second number.

13. A blockchain node, include: an acquiring unit, configured to acquire a first transaction, wherein the first transaction calls a first contract, contract data of the first contract is stored in the blockchain, the contract data includes a first access information table, and the first access information table includes first storage location information of a first state variable requested to be read by the first contract; A reading unit, configured to read the first storage location information from a blockchain; And reading the value of the first state variable from the blockchain according to the first storage location information, so as to execute the first transaction.

14. A blockchain node, comprising a memory and a processor, wherein the memory stores an executable code, and when the processor executes the executable code, the method according to any one of claims 1 to 12 is implemented.

Citation Information

Patent Citations

  • Method for executing transaction in block chain and block chain system

    CN112884585A

  • Block chain network-based transaction method, medium and device

    CN115705603A

  • Block chain transaction execution method and block chain node

    CN116302358A

  • Block chain transaction execution method and block chain node

    CN116302359A

  • Method and apparatus for implementing a distributed blockchain transaction processing element in a datacenter

    WO2020002974A1