Transaction execution method in blockchain and blockchain node
By sending multiple operation transactions in the blockchain, multiple contract calls are completed in one transaction, solving the problems of slow speed and high cost caused by business behavior splitting in the existing technology, and improving transaction execution efficiency and cost-effectiveness .
Patent Information
- Application Number
- PCT/CN2023/135015
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-05-29
- Filing Date
- 2023-11-29
- Publication Date
- 2024-12-05
AI Technical Summary
In blockchain, the existing technology needs to complete business behavior through multiple transactions, resulting in slow business execution and high user costs, and each contract call requires signature and storage, which increases time and storage costs.
By sending transactions containing multiple operations in the blockchain, each operation corresponds to a contract call, the complete business behavior is achieved in one transaction, without splitting into multiple transactions, blockchain nodes are executed in parallel or in sequence These operations reduce signature and storage requirements.
Accelerate business execution speed, save users' costs of completing business, and reduce the time and cost of transaction signatures and storage.
Smart Images

Figure CN2023135015_05122024_PF_FP_ABST
Abstract
Description
Transaction execution methods and blockchain nodes in blockchain
[0001] This application claims priority to the Chinese patent application filed with the State Intellectual Property Office of China on May 29, 2023, with application number 202310612543.8 and application name “Transaction Execution Method and Blockchain Node in Blockchain”, 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 transaction execution method and blockchain node in a blockchain. 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 present invention aims to provide a transaction method in a blockchain to improve the execution efficiency of transactions that call contracts in the blockchain.
[0006] In a first aspect, this specification provides a transaction execution method in a blockchain, which is executed by a blockchain node, comprising:
[0007] Receive a first transaction, where the first transaction includes a first operation and a second operation, where the first operation is used to call a first function in a first contract, and the second operation is used to call a second function in a second contract;
[0008] The first operation and the second operation are performed.
[0009] A second aspect of this specification provides a blockchain node, including:
[0010] a receiving unit, configured to receive a first transaction, the first transaction including a first operation and a second operation, the first operation being used to call a first function in a first contract, and the second operation being used to call a second function in a second contract;
[0011] An execution unit, configured to execute the first operation and the second operation.
[0012] 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.
[0013] 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.
[0014] In the solution provided in the embodiments of this specification, a transaction including multiple operations is sent to the blockchain, where each operation corresponds to a contract call, so that the entire business behavior can be completed in one transaction without being split into multiple transactions, which speeds up the business process, saves users the cost of completing the business, and saves time and storage costs for signing transactions. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] 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.
[0016] FIG1 is a schematic diagram of deploying a smart contract in one embodiment;
[0017] FIG2 is a schematic diagram of calling a smart contract in one embodiment;
[0018] FIG3 is a schematic diagram of a blockchain data storage structure in one embodiment;
[0019] FIG4 is a schematic diagram of a blockchain data storage structure in one embodiment;
[0020] FIG5 is a flow chart of a transaction execution method in an embodiment of this specification;
[0021] FIG6 is a schematic diagram of the structure of transaction Tx1 and its signature in an embodiment of this specification;
[0022] FIG7 is an architectural diagram of a blockchain node in an embodiment of this specification. DETAILED DESCRIPTION
[0023] 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.
[0024] 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.
[0025] 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.
[0026] 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.
[0027] For example, as shown in Figure 1, after Bob sends a transaction containing information about creating 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.
[0028] 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.
[0029] 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.
[0030] 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.
[0031] The following is a code example of a simple smart contract written in Solidity language 1:
[0032] Code Example 1. SimpleStorage Code
[0033] 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 parameter. 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.
[0034] As mentioned earlier, state variables will ultimately be stored in the database. 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.
[0035] 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).
[0036] 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.
[0037] 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:
[0038] 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;
[0039] Externally owned account: A user's account.
[0040] 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.
[0041] 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.
[0042] Balance: Account balance.
[0043] 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.
[0044] 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.
[0045] 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.
[0046] 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.
[0047] 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.
[0048] 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.
[0049] 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.
[0050] 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.
[0051] 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 represents 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 at 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 stores the value of the state variable (e.g., 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.
[0052] 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.
[0053] 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.
[0054] As mentioned above, in related technologies, a transaction only involves calling a single function on a contract. However, a business activity typically requires multiple transactions. Different transactions may call different functions on the same contract, or even functions on different contracts. Therefore, each transaction corresponds to a transaction signature, and multiple signatures for multiple transactions require significant signing time and storage costs.
[0055] The embodiments of this specification provide a transaction execution method, in which a transaction including multiple operations is sent to a blockchain, where each operation corresponds to a contract call, so that a complete business behavior can be completed in one transaction without splitting it into multiple transactions, thereby speeding up the business process, saving users the cost of completing the business, and saving the time and storage costs used to sign the transaction.
[0056] FIG5 is a flowchart of a transaction execution method in an embodiment of this specification, which can be executed by a blockchain node.
[0057] As shown in FIG5 , in step S501 , the blockchain node receives a transaction Tx1 , which includes an operation OP1 for calling a function method1 in a contract C1 and an operation OP2 for calling a function mehtod2 in a contract C2 .
[0058] The user end of the blockchain can generate transaction Tx1 and its signature, and send transaction Tx1 and its signature to the blockchain.
[0059] Figure 6 is a schematic diagram of the structure of transaction Tx1 and its signature in an embodiment of this specification. As shown in Figure 6, transaction Tx1 (i.e., the transaction body of transaction Tx1) may include a From field and an Operations field. The From field represents the account address of the sender of the transaction. For example, if the sender of the transaction is Bob and his account address is 0xf5e..., the value of the From field of transaction Tx1 may be 0xf5e..., indicating that the sender of the transaction is Bob.
[0060] The Operations field corresponds to an array with an undefined number of elements, and each element of the array (i.e., operation) includes three fields: contract address, method name, and incoming parameter values. As can be seen, each operation in Operation corresponds to a call to the contract. As shown in Figure 6, the Operations field of transaction Tx1 includes two elements: C1, method1, args1 (hereinafter referred to as operation OP1); C2, method2, args2 (hereinafter referred to as operation OP2). Among them, operation OP1 corresponds to a call to method1 in contract C1, args1 is the incoming parameter to method1, and operation OP2 corresponds to a call to method2 in contract C2, args2 is the incoming parameter to method2.
[0061] For example, in one business, OP1 is used to call system contract C1 to create an on-chain account for a user, and OP2 is used to call NFT contract C2 to transfer NFT resources to the on-chain account created by OP1. In this business scenario, method1 is the function used to create an on-chain account, args1 is the account address to be created, method2 is the function used to transfer NFT resources, and args2 is the account address. Alternatively, in another business, OP1 is used to authorize an account by calling a contract, and OP2 is used to call a contract to transfer resources to the authorized account.
[0062] It is understood that different operations in the Operations field can call different functions of the same contract, or they can call the same function of the same contract. Furthermore, the number of operations included in the Operations field is not limited to two; it can be three or more depending on business needs. This specification uses two operations as an example for description.
[0063] In one embodiment, when there is no access conflict in the contract execution corresponding to different operations in the Operations field, a specific field can be set in transaction Tx1 to indicate that the different operations can be executed in parallel.
[0064] In another embodiment, the default is to execute the different operations in the order in which they are arranged in the Operations field.
[0065] In addition to the fields shown in Figure 6, transaction Tx1 may also include a timestamp field, a nonce field, a gas_limit field, and an extra_data field. The timestamp field indicates the timestamp when the transaction was sent, the nonce field indicates the nonce value of the transaction sending account, the gas_limit field indicates the upper limit of the transaction gas consumption, and the extra_data field indicates other data that needs to be uploaded to the blockchain.
[0066] The digital signature of transaction Tx1 is generated by Bob digitally signing the transaction body of transaction Tx1 using the private key corresponding to his account. In this embodiment of the specification, since a transaction includes multiple calls to a contract, only a single digital signature is required for each call to the contract, rather than requiring a signature for each call as in the prior art. This saves the sender's signature time and reduces the storage cost of storing the signature in the blockchain.
[0067] In step S520, operation OP1 and operation OP2 are performed.
[0068] After reaching consensus on transaction Tx1, each node in the blockchain can execute transaction Tx1 separately. When executing transaction Tx1, if transaction Tx1 indicates that operations OP1 and OP2 can be executed in parallel, the blockchain node can execute operations OP1 and OP2 in parallel.
[0069] In the case where operations OP1 and OP2 are executed in the order in which they are arranged by default in transaction Tx1, the blockchain node first executes operation OP1. If the execution of operation OP1 is successful, the blockchain node then executes operation OP2. If the execution of operation OP1 fails, the blockchain node determines that transaction Tx1 has failed and ends the execution of transaction Tx1, that is, it does not execute operation OP2.
[0070] After the blockchain node starts executing operation OP2, if the execution of operation OP2 fails, it determines that transaction Tx1 has failed and ends the execution of transaction Tx1.
[0071] That is, when a blockchain node executes transaction Tx1, if any operation in transaction Tx1 fails, the transaction is considered to have failed. The transaction is considered to have succeeded only if every operation in transaction Tx1 succeeds.
[0072] When executing transaction Tx1, the blockchain node generates a receipt for transaction Tx1.
[0073] The receipt may include a result field to indicate whether the transaction was successful. For example, if the result field is 0, it indicates that the transaction was successful, and if the result field is 1, it indicates that the transaction failed.
[0074] The receipt may include output information (Outputs) corresponding to each executed operation. Outputs can be an array. When result in the receipt is 0, Outputs includes output1 corresponding to OP1 and output2 corresponding to OP2, where output1 and output2 represent the return value of their corresponding operations.
[0075] When the result in the receipt is 1, Outputs only includes the output information corresponding to the executed operation. The output information corresponding to the failed operation is used to indicate the error message, and the output information corresponding to the successfully executed operation is used to indicate the return value of the operation.
[0076] If a blockchain node executes operations OP1 and OP2 in that order, the output information for the executed operations may be arranged in the output information list in the receipt in that order. In this case, when the result in the receipt is 1, the last output information in the output information list represents an error message, and the previous output information represents the return value of the corresponding operation. For example, when result is 1 and the output information list includes output1 and output2 corresponding to operations OP1 and OP2, respectively, output1 represents the return value of operation OP1, and output2 represents the error message for operation OP2. This error message may include, for example, information indicating an operation failure or insufficient gas.
[0077] In addition, the receipt of transaction Tx1 may also include event logs, which may include one or more event logs corresponding to each operation.
[0078] During the execution of operation OP1, a blockchain node may store the variable state written during the execution of operation OP1 in memory, for example, "A=V1," indicating that the new state of variable A is V1. Variable A is, for example, a variable defined in contract C1, and the state value of variable A is stored in the contract state of contract C1. After the blockchain node successfully executes operation OP1 and begins executing operation OP2, the execution of operation OP2 may include reading the state value of variable A. For example, if operation OP2 directly calls contract C1, or if operation OP2 calls contract C2, which in turn calls contract C1, both scenarios may result in operation OP2 including a read of variable A. Consequently, the blockchain node reads the new state value V1 of variable A stored during the execution of operation OP1 from memory and executes operation OP2 based on this state value V1.
[0079] When a blockchain node determines that the execution of transaction Tx1 has failed, it rolls back (discards) the world state modified during the execution of transaction Tx1. For example, in the example above, if the blockchain node fails to execute operation OP2, the blockchain node will delete from memory the state "A=V1" previously modified during the execution of operation OP1.
[0080] In addition, for the transactions shown in Figure 6, when performing read-write set analysis on multiple transactions to group the multiple transactions, the read-write sets of each operation of a single transaction can be aggregated to obtain the read-write set of the transaction, and grouping can be performed based on the read-write sets of the transactions. In this way, multiple transactions can be executed in parallel based on the multiple transaction groups obtained by grouping the multiple transactions.
[0081] In the transaction execution method provided in the embodiments of this specification, by including multiple calls to a contract in one transaction, the execution speed of the transaction is accelerated, and the execution cost required for multiple calls to the contract is also reduced.
[0082] FIG7 is an architecture diagram of a blockchain node in an embodiment of this specification, wherein the blockchain node is configured to execute the method shown in FIG5 , including:
[0083] A receiving unit 71 is configured to receive a first transaction, where the first transaction includes a first operation and a second operation, where the first operation is used to call a first function in a first contract, and the second operation is used to call a second function in a second contract;
[0084] The execution unit 72 is configured to execute the first operation and the second operation.
[0085] 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 FIG5 .
[0086] An embodiment of this specification also provides 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 5 is implemented.
[0087] 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.
[0088] 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.
[0089] 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.
[0090] 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.
[0091] 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.
[0092] 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.
[0093] 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 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.
[0094] 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.
[0095] 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.
[0096] 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.
[0097] 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.
[0098] 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.
[0099] 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 transaction execution method in a blockchain, executed by a blockchain node, comprising: Receive a first transaction, the first transaction including a first operation and a second operation, the first operation is used to call a first function in a first contract, and the second operation is used to call a second function in a second contract; The first operation and the second operation are performed.
2. The method according to claim 1, wherein the first transaction further includes an arrangement order of the first operation and the second operation, and the performing of the first operation and the second operation comprises: According to the arrangement order, execute the first operation arranged first; If the first operation is successfully executed, the second operation is executed.
3. The method according to claim 2, The performing of the first operation arranged in front includes: When performing the first operation, storing an updated first state of the first variable according to the first operation; The performing the second operation includes: when the second operation includes a read operation on the first variable, reading the first state, and performing the second operation according to the first state.
4. The method according to claim 2, wherein performing the first operation and the second operation comprises: In the case where the first operation or the second operation fails to be executed, it is determined that the first transaction has failed to be executed, and the execution of the first transaction is terminated.
5. The method according to claim 4, further comprising: After determining that the first transaction fails to execute, rolling back the modification of the world state during the execution of the first transaction.
6. The method according to claim 4, further comprising: Generate a receipt for the first transaction, the receipt including output information corresponding to the executed operations, wherein the output information corresponding to the failed operation is used to indicate the error information of the operation, and the output information corresponding to the successfully executed operation is used to indicate the return value of the operation.
7. The method according to claim 6, wherein the receipt further includes a transaction result, wherein the transaction result is used to indicate whether the first transaction fails to be executed; The receipt includes at least one output information corresponding to at least one operation that has been executed and arranged in sequence, and the arrangement order of the at least one output information is determined based on the arrangement order of the operations corresponding to each output information, wherein: In the case where the first transaction fails to be executed, the output information arranged last is used to indicate error information of the operation corresponding to the output information.
8. The method according to claim 1, further comprising: Before executing the first transaction, generating a read-write set of the first transaction, wherein the read-write set includes identifiers of variables accessed by the first operation and the second operation obtained through analysis; The first transaction is divided into transaction groups based on the read-write set, so as to execute transactions in each transaction group in parallel.
9. The method according to claim 1, wherein: The first operation further includes a first parameter for passing into the first function, and the second operation further includes a second parameter for passing into the second function.
10. The method according to claim 1, wherein the first transaction further includes a sending account, and the method further includes: Receive a signature of the sending account on the first transaction.
11. A blockchain node, comprising: A receiving unit is configured to receive a first transaction, wherein the first transaction includes a first operation and a second operation. The first operation is used to call a first function in a first contract, and the second operation is used to call a second function in a second contract; An execution unit, configured to execute the first operation and the second operation.
12. A blockchain node, comprising: The invention comprises a memory and a processor, wherein the memory stores executable codes, and when the processor executes the executable codes, the method according to any one of claims 1 to 10 is implemented.
Citation Information
Patent Citations
Method and device for executing transaction in blockchain system and blockchain system
CN113259478A
Method for executing transaction in block chain and block chain node
CN114385756A
Transaction execution method in block chain system and block chain node
CN115760386A
Method and device for querying data in block chain system and block chain node
CN116126966A
Transaction execution method in block chain and block chain node
CN116628091A
