Method and device for avoiding double-spending problem in read-write set-model-based blockchain technology

Disclosed herein are methods, systems, and apparatus, including computer programs encoded on computer storage media, for avoiding double-spending problem in read-write set-model-based blockchain technology. One of the methods includes receiving instructions to execute two or more blockchain transactions on a piece of data, where all blockchain transactions of the two or more blockchain transactions modify a value of the piece of data, and for each blockchain transaction from the two or more blockchain transactions, pre-executing a smart contract associated with the blockchain transaction to generate a special instruction indicating the blockchain transaction, where the special instruction is used to validate that a current value of the piece of data supports the blockchain transaction when executing the smart contract to write the blockchain transaction to a blockchain.

TECHNICAL FIELD

This specification relates to the field of blockchain technology, and in particular, to methods and devices for avoiding double-spending problem in read-write set-model-based blockchain technology.

BACKGROUND

Distributed ledger systems (DLSs), which can also be referred to as consensus networks, and/or blockchain networks, enable participating entities to securely and to immutably conduct transactions and to store data. DLSs are commonly referred to as blockchain networks without referencing any particular user case. Examples of types of blockchain networks can include public blockchain networks, private blockchain networks, and consortium blockchain networks. A consortium blockchain network is provided for a select group of entities, which control a consensus process, and includes an access control layer.

In blockchain networks, due to reproducibility of data, a digital asset could possibly be reused. For example, multiple parallel blockchain transactions can be performed on a same digital asset (referred to as double-spending). In some cases, if the multiple parallel blockchain transactions read on a same data, once the first parallel blockchain transaction modifies the data, other parallel blockchain transactions may fail due to the data modification (referred to as a double-spending problem).

Currently, there are two primary blockchain process types. One is led by Ethereum and achieves consensus first, executes a smart contract next, and modifies a state of a data last. The other is led by Hyperledger Fabric and pre-executes smart contracts for logical verification first, performs consensus sorting for the generated read-write sets next, and performs data verification for each generated read-write set last. Since Ethereum executes transactions sequentially, there can be no double-spending problem. However, Hyperledger Fabric implements a pre-execution smart contract scheme based on a read-write set, and may encounter the double-spending problem.

It would be desirable to provide a solution to the double-spending problem in read-write set-model-based blockchain technology (e.g., Hyperledger Fabric).

SUMMARY

This specification describes technologies for avoiding double-spending problem in blockchain transactions. These technologies generally involve receiving instructions to execute two or more blockchain transactions on a piece of data, where all blockchain transactions of the two or more blockchain transactions modify a value of the piece of data, and for each blockchain transaction from the two or more blockchain transactions, pre-executing a smart contract associated with the blockchain transaction to generate a special instruction indicating the blockchain transaction, where the special instruction is used to validate that a current value of the piece of data supports the blockchain transaction when executing the smart contract to write the blockchain transaction to a blockchain.

This specification also provides one or more non-transitory computer-readable storage media coupled to one or more processors and having instructions stored thereon which, when executed by the one or more processors, cause the one or more processors to perform operations in accordance with embodiments of the methods provided herein.

It is appreciated that methods in accordance with this specification may include any combination of the aspects and features described herein. That is, methods in accordance with this specification are not limited to the combinations of aspects and features specifically described herein, but can also include any combination of the aspects and features provided.

The details of one or more embodiments of this specification are set forth in the accompanying drawings and the description below. Other features and advantages of this specification will be apparent from the description and drawings, and from the claims.

DETAILED DESCRIPTION

The following detailed description describes avoiding double-spending problem in read-write set-model-based blockchain technology, and is presented to enable any person skilled in the art to make and use the disclosed subject matter in the context of one or more particular embodiments. Instructions to execute two or more blockchain transactions on a piece of data are received. For each blockchain transaction, a corresponding smart contract is pre-executed to generate a special instruction, instead of a read-write set. The special instruction is used to validate that a current value of the piece of data supports the blockchain transaction when executing the corresponding smart contract to write the blockchain transaction to a blockchain.

Various modifications, alterations, and permutations of the disclosed embodiments can be made and will be readily apparent to those of ordinary skill in the art, and the general principles defined can be applied to other embodiments and applications, without departing from the scope of this specification. In some instances, one or more technical details that are unnecessary to obtain an understanding of the described subject matter and that are within the skill of one of ordinary skill in the art may be omitted so as to not obscure one or more described embodiments. This specification is not intended to be limited to the described or illustrated embodiments, but to be accorded the widest scope consistent with the described principles and features.

To provide further context for embodiments of this specification, and as introduced above, distributed ledger systems (DLSs), which can also be referred to as consensus networks (e.g., made up of peer-to-peer nodes), and blockchain networks, enable participating entities to securely and to immutably conduct transactions and to store data. Although the term blockchain is generally associated with particular networks, and/or use cases, blockchain is used herein to generally refer to a DLS without reference to any particular use case.

A blockchain is a data structure that stores transactions in a way that the transactions are immutable. Thus, transactions recorded on a blockchain are reliable and trustworthy. A blockchain includes one or more blocks. Each block in the chain is linked to a previous block immediately before it in the chain by including a cryptographic hash of the previous block. Each block also includes a timestamp, its own cryptographic hash, and one or more transactions. The transactions, which have already been verified by the nodes of the blockchain network, are hashed and encoded into a Merkle tree. A Merkle tree is a data structure in which data at the leaf nodes of the tree is hashed, and all hashes in each branch of the tree are concatenated at the root of the branch. This process continues up the tree to the root of the entire tree, which stores a hash that is representative of all data in the tree. A hash purporting to be of a transaction stored in the tree can be quickly verified by determining whether it is consistent with the structure of the tree.

Whereas a blockchain is a decentralized or at least partially decentralized data structure for storing transactions, a blockchain network is a network of computing nodes that manage, update, and maintain one or more blockchains by broadcasting, verifying and validating transactions, etc. As introduced above, a blockchain network can be provided as a public blockchain network, a private blockchain network, or a consortium blockchain network. Embodiments of this specification are described in further detail herein with reference to a consortium blockchain network. It is contemplated, however, that embodiments of this specification can be realized in any appropriate type of blockchain network.

In general, a consortium blockchain network is private among the participating entities. In a consortium blockchain network, the consensus process is controlled by an authorized set of nodes, which can be referred to as consensus nodes, one or more consensus nodes being operated by a respective entity (e.g., a financial institution, insurance company). For example, a consortium of ten (10) entities (e.g., financial institutions, insurance companies) can operate a consortium blockchain network, each of which operates at least one node in the consortium blockchain network.

In some examples, within a consortium blockchain network, a global blockchain is provided as a blockchain that is replicated across all nodes. That is, all consensus nodes are in perfect state consensus with respect to the global blockchain. To achieve consensus (e.g., agreement to the addition of a block to a blockchain), a consensus protocol is implemented within the consortium blockchain network. For example, the consortium blockchain network can implement a practical Byzantine fault tolerance (PBFT) consensus, described in further detail below.

FIG. 1is a diagram illustrating an example of an environment100that can be used to execute embodiments of this specification. In some examples, the environment100enables entities to participate in a consortium blockchain network102. The environment100includes computing devices106,108, and a network110. In some examples, the network110includes a local area network (LAN), wide area network (WAN), the Internet, or a combination thereof, and connects web sites, user devices (e.g., computing devices), and back-end systems. In some examples, the network110can be accessed over a wired and/or a wireless communications link. In some examples, the network110enables communication with, and within the consortium blockchain network102. In general the network110represents one or more communication networks. In some cases, the computing devices106,108can be nodes of a cloud computing system (not shown), or each computing device106,108can be a separate cloud computing system including a number of computers interconnected by a network and functioning as a distributed processing system.

In the depicted example, the computing systems106,108can each include any appropriate computing system that enables participation as a node in the consortium blockchain network102. Examples of computing devices include, without limitation, a server, a desktop computer, a laptop computer, a tablet computing device, and a smartphone. In some examples, the computing systems106,108host one or more computer-implemented services for interacting with the consortium blockchain network102. For example, the computing system106can host computer-implemented services of a first entity (e.g., user A), such as a transaction management system that the first entity uses to manage its transactions with one or more other entities (e.g., other users). The computing system108can host computer-implemented services of a second entity (e.g., user B), such as a transaction management system that the second entity uses to manage its transactions with one or more other entities (e.g., other users). In the example ofFIG. 1, the consortium blockchain network102is represented as a peer-to-peer network of nodes, and the computing systems106,108provide nodes of the first entity, and second entity respectively, which participate in the consortium blockchain network102.

FIG. 2is a diagram illustrating an example of a conceptual architecture200in accordance with embodiments of this specification. The example conceptual architecture200includes participant systems202,204,206that correspond to Participant A, Participant B, Participant C, respectively. Each participant (e.g., user, enterprise) participates in a blockchain network212provided as a peer-to-peer network including a plurality of nodes214, at least some of which immutably record information in a blockchain216. Although a single blockchain216is schematically depicted within the blockchain network212, multiple copies of the blockchain216are provided, and are maintained across the blockchain network212, as described in further detail herein.

In the depicted example, each participant system202,204,206is provided by, or on behalf of Participant A, Participant B, Participant C, respectively, and functions as a respective node214within the blockchain network. As used herein, a node generally refers to an individual system (e.g., computer, server) that is connected to the blockchain network212, and enables a respective participant to participate in the blockchain network. In the example ofFIG. 2, a participant corresponds to each node214. It is contemplated, however, that a participant can operate multiple nodes214within the blockchain network212, and/or multiple participants can share a node214. In some examples, the participant systems202,204,206communicate with, or through the blockchain network212using a protocol (e.g., hypertext transfer protocol secure (HTTPS)), and/or using remote procedure calls (RPCs).

Nodes214can have varying degrees of participation within the blockchain network212. For example, some nodes214can participate in the consensus process (e.g., as minder nodes that add blocks to the blockchain216), while other nodes214do not participate in the consensus process. As another example, some nodes214store a complete copy of the blockchain216, while other nodes214only store copies of portions of the blockchain216. For example, data access privileges can limit the blockchain data that a respective participant stores within its respective system. In the example ofFIG. 2, the participant systems202,204,206store respective, complete copies216′,216″,216′″ of the blockchain216.

A blockchain (e.g., the blockchain216ofFIG. 2) is made up of a chain of blocks, each block storing data. Examples of data include transaction data representative of a transaction between two or more participants. While transactions are used herein by way of non-limiting example, it is contemplated that any appropriate data can be stored in a blockchain (e.g., documents, images, videos, audio). Examples of a transaction can include, without limitation, exchanges of something of value (e.g., assets, products, services, currency). The transaction data is immutably stored within the blockchain. That is, the transaction data cannot be changed.

Before storing in a block, the transaction data is hashed. Hashing is a process of transforming the transaction data (provided as string data) into a fixed-length hash value (also provided as string data). It is not possible to un-hash the hash value to obtain the transaction data. Hashing ensures that even a slight change in the transaction data results in a completely different hash value. Further, and as noted above, the hash value is of fixed length. That is, no matter the size of the transaction data the length of the hash value is fixed. Hashing includes processing the transaction data through a hash function to generate the hash value. An example of a hash function includes, without limitation, the secure hash algorithm (SHA)-256, which outputs 256-bit hash values.

Transaction data of multiple transactions are hashed and stored in a block. For example, hash values of two transactions are provided, and are themselves hashed to provide another hash. This process is repeated until, for all transactions to be stored in a block, a single hash value is provided. This hash value is referred to as a Merkle root hash, and is stored in a header of the block. A change in any of the transactions will result in change in its hash value, and ultimately, a change in the Merkle root hash.

Blocks are added to the blockchain through a consensus protocol. Multiple nodes within the blockchain network participate in the consensus protocol, and perform work to have a block added to the blockchain. Such nodes are referred to as consensus nodes. PBFT, introduced above, is used as a non-limiting example of a consensus protocol. The consensus nodes execute the consensus protocol to add transactions to the blockchain, and update the overall state of the blockchain network.

In further detail, the consensus node generates a block header, hashes all of the transactions in the block, and combines the hash value in pairs to generate further hash values until a single hash value is provided for all transactions in the block (the Merkle root hash). This hash is added to the block header. The consensus node also determines the hash value of the most recent block in the blockchain (i.e., the last block added to the blockchain). The consensus node also adds a nonce value, and a timestamp to the block header.

In general, PBFT provides a practical Byzantine state machine replication that tolerates Byzantine faults (e.g., malfunctioning nodes, malicious nodes). This is achieved in PBFT by assuming that faults will occur (e.g., assuming the existence of independent node failures, and/or manipulated messages sent by consensus nodes). In PBFT, the consensus nodes are provided in a sequence that includes a primary consensus node, and backup consensus nodes. The primary consensus node is periodically changed. Transactions are added to the blockchain by all consensus nodes within the blockchain network reaching an agreement as to the world state of the blockchain network. In this process, messages are transmitted between consensus nodes, and each consensus nodes proves that a message is received from a specified peer node, and verifies that the message was not modified during transmission.

In PBFT, the consensus protocol is provided in multiple phases with all consensus nodes beginning in the same state. To begin, a client sends a request to the primary consensus node to invoke a service operation (e.g., execute a transaction within the blockchain network). In response to receiving the request, the primary consensus node multicasts the request to the backup consensus nodes. The backup consensus nodes execute the request, and each sends a reply to the client. The client waits until a threshold number of replies are received. In some examples, the client waits for f+1 replies to be received, where f is the maximum number of faulty consensus nodes that can be tolerated within the blockchain network. The final result is that a sufficient number of consensus nodes come to an agreement on the order of the record that is to be added to the blockchain, and the record is either accepted, or rejected.

In some blockchain networks, cryptography is implemented to maintain privacy of transactions. For example, if two nodes desire to keep a transaction private, such that other nodes in the blockchain network cannot discern details of the transaction, the nodes can encrypt the transaction data. An example of cryptography includes, without limitation, symmetric encryption and asymmetric encryption. Symmetric encryption refers to an encryption process that uses a single key for both encryption (i.e., generating ciphertext from plaintext), and decryption (i.e., generating plaintext from ciphertext). In symmetric encryption, the same key is available to multiple nodes, so that each node can en-/de-crypt transaction data.

Asymmetric encryption uses keys pairs, where each key pair includes a private key and a public key. The private key is known only to a particular node, and the public key is known to any or all other nodes in the blockchain network. A node can use the public key of another node to encrypt data, and the encrypted data can be decrypted using another node's private key. For example, and referring again toFIG. 2, Participant A can use Participant B's public key to encrypt data, and to send the encrypted data to Participant B. Participant B can use its private key to decrypt the encrypted data (e.g., ciphertext) and to extract the original data (e.g., plaintext). Messages encrypted with a node's public key can only be decrypted using the node's private key.

Asymmetric encryption is used to provide digital signatures, which enables participants in a transaction to confirm other participants in the transaction, as well as the validity of the transaction. For example, a node can digitally sign a message, and another node can confirm that the message was sent by the node based on the digital signature of Participant A. Digital signatures can also be used to ensure that messages are not tampered with in transit. For example, and again referencingFIG. 2, Participant A is to send a message to Participant B. Participant A generates a hash of the message, and then, using its private key, encrypts the hash to provide a digital signature as the encrypted hash. Participant A appends the digital signature to the message, and sends the message with digital signature to Participant B. Participant B decrypts the digital signature using the public key of Participant A, and extracts the hash. Participant B hashes the message and compares the hashes. If the hashes are same, Participant B can confirm that the message was indeed from Participant A, and was not tampered with.

FIG. 3is a block diagram illustrating an example of a blockchain transaction execution scenario300in accordance with embodiments of this specification. The blockchain transaction execution scenario300includes a blockchain transaction where a user305intends to spend 40 yuan (¥ 40). The blockchain transaction includes a smart contract pre-execution phase310and a data storage verification phase315. For convenience, the blockchain transaction execution scenario300will be described as being performed by a system of one or more computers, located in one or more locations, and programmed appropriately in accordance with this specification (e.g., the computing system106and/or108ofFIG. 1or the participant system202,204, and/or206ofFIG. 2).

As illustrated inFIG. 3, the user305has a digital wallet320with a wallet balance of 100 yuan. The user305intends to spend 40 yuan322. Through, for example, a software development kit (SDK) call324for a smart contract, a blockchain transaction326to spend 40 yuan is submitted for execution. To execute the blockchain transaction326, the smart contract is first pre-executed to perform logical verification on the blockchain transaction326to generate a read-write set. After consensus sorting, data verification on the blockchain transaction326is performed based on the read-write set to determine whether the blockchain transaction326can be executed successfully.

During the smart contract pre-execution phase310, at328, a blockchain transaction for spending 40 yuan is received. From328, the flow proceeds to330.

At330, the user's account balance is read (i.e., balance=100). During the smart contract pre-execution phase310, the user's account balance is not modified (i.e., the balance remains at 100 yuan). From330, the flow proceeds to332.

At332, a determination is made as to whether there is enough (i.e., a sufficient) balance in the user's account for the blockchain transaction to spend 40 yuan. If it is determined that there is not enough balance in the user's account for the blockchain transaction to spend 40 yuan, then the flow proceeds to334, where a notice indicating not enough money is sent to the user305. In other words, in the situation with not enough balance, the smart contract pre-execution phase310fails, and the blockchain transaction to spend 40 yuan fails. Otherwise, if it is determined that there is enough balance in the user's account for the blockchain transaction to spend 40 yuan, then the flow proceeds to336, where a read-write set is generated. For example, a read-write set of (100→60) is generated. The read-write set of (100→60) indicates deducting 40 yuan from the user's account with a balance of 100 yuan, and the user's account with a remaining balance of 60 yuan after the blockchain transaction to spend 40 yuan succeeds (e.g., the user's account balance changing from 100 yuan to 60 yuan). After336, the blockchain transaction with the generated read-write set is submitted338for consensus sorting before finalized in the data storage verification phase315.

During the data storage verification phase315, at340, a blockchain transaction with a read-write set of (100→60) is received. From340, the flow proceeds to342.

At342, the user's account balance is read (i.e., balance=100). From342, the flow proceeds to344.

At344, a determination is made as to whether the user's account balance equals to the account balance indicated in the read-write set of (100→60) (i.e., read-write set account balance=100). If it is determined that the user's account balance does not equal to the account balance indicated in the read-write set of (100→60), then the flow proceeds to346, where a message indicating that data does not match is sent to notify the user305. In other words, the data storage verification phase315fails, and as a result the blockchain transaction to spend 40 yuan fails. Otherwise, if it is determined that the user's account balance equals to the account balance indicated in the read-write set of (100→60), then the flow proceeds to348, where a database is modified according to the read-write set of (100→60) (e.g., the user's account balance being modified from 100 yuan to 60 yuan). For example, the blockchain transaction to spend 40 yuan is stored in a data block of a blockchain. From348, the flow proceeds to350, where a message indicating money spent is sent to notify the user305. In other words, the blockchain transaction to spend 40 yuan succeeds.

The blockchain transaction execution scenario300illustrated inFIG. 3uses a read-write set-model-based blockchain technology (e.g., Hyperledger Fabric). Unlike traditional smart contract calling logic (such as, Ethereum), the read-write set-model-based blockchain technology separates logical verification and data verification. An execution during the smart contract pre-execution phase310(e.g., logical verification) does not modify data, and can obtain endorsement of one or more nodes in a blockchain network. A transaction after consensus sorting and during the data storage verification phase315(e.g., data verification) can modify the data. In doing so, the performance of the blockchain technology can be improved.

FIG. 4is a block diagram illustrating an example of a conventional execution scenario400for two parallel blockchain transactions in accordance with embodiments of this specification. The conventional execution scenario400includes two parallel blockchain transactions that a user405intended to spend 40 yuan (¥ 40) in each blockchain transaction of the two parallel blockchain transactions. Each blockchain transaction includes a smart contract pre-execution phase410, a consensus sorting phase415, and a data storage verification phase420. In some embodiments, the conventional execution scenario400can include more than two parallel blockchain transactions. For convenience, the conventional execution scenario400will be described as being performed by a system of one or more computers, located in one or more locations, and programmed appropriately in accordance with this specification. (e.g., the computing system106and/or108ofFIG. 1or the participant system202,204, and/or206ofFIG. 2).

As illustrated inFIG. 4, the user405has a digital wallet422with a wallet balance of 100 yuan. The user405intended to spend a total of 80 yuan in two parallel blockchain transactions424and426. Each blockchain transaction is to spend 40 yuan. In some embodiments, different amount can be spent on each blockchain transaction. To execute the two parallel blockchain transactions424and426, a smart contract is first pre-executed to perform logical verification on each blockchain transaction to generate a corresponding read-write set. After consensus sorting, data verification on each blockchain transaction is performed based on the corresponding read-write set to determine whether each blockchain transaction can be executed successfully.

During the smart contract pre-execution phase410(similar to the smart contract pre-execution phase310inFIG. 3), a read-write set428(i.e., (100→60)) is generated for the blockchain transaction424. The read-write set428indicates deducting 40 yuan from the user's account with a balance of 100 yuan, and the user's account with a remaining balance of 60 yuan after the blockchain transaction424succeeds (e.g., the user's account balance changing from 100 yuan to 60 yuan). In addition, a read-write set430(i.e., (100→60)) is generated for the blockchain transaction426.

If the user's account has no other consumption, the two parallel blockchain transactions424and426read the same user's account balance stored in a database during the smart contract pre-execution phase410. Therefore, the read-write set430also indicates deducting 40 yuan from the user's account with a balance of 100 yuan, and the user's account with a remaining balance of 60 yuan after the blockchain transaction430succeeds (e.g., the user's account balance changing from 100 yuan to 60 yuan).

After the smart contract pre-execution phase410, the blockchain transaction with the read-write set428is submitted432for consensus sorting, and the blockchain transaction with the read-write set430is also submitted434for consensus sorting.

During the consensus sorting phase415, assume, for convenience, that the blockchain transaction with the read-write set428is put as a first transaction436to be executed in the data storage verification phase420, and the blockchain transaction with the read-write set430is put as a second transaction438to be executed in the data storage verification phase420.

During the data storage verification phase420(similar to the data storage verification phase315inFIG. 3), the blockchain transaction with the read-write set428is executed first440. At440, the user's account balance is read (i.e., balance=100). A determination is made that the user's account balance equals to the account balance indicated in the read-write set428(i.e., 100==100). A database is modified according to the read-write set428(e.g., the user's account balance being modified from 100 yuan to 60 yuan). In other words, the data storage verification phase420for the blockchain transaction with the read-write set428succeeds, and as a result the blockchain transaction424succeeds. After the blockchain transaction with the read-write set428succeeds, the flow proceeds to442, where the blockchain transaction with the read-write set430is executed. At442, the user's account balance is read (i.e., balance=60). A determination is made that the user's account balance does not equal to the account balance indicated in the read-write set430(i.e., 60!=100). In other words, the data storage verification phase420for the blockchain transaction with the read-write set430fails, and as a result the blockchain transaction426fails.

As illustrated inFIG. 4, when two or more parallel blockchain transactions are executed on a piece of data (such as, an account balance), the same data is read for each blockchain transaction during logical verification (e.g., the smart contract pre-execution phase410). After consensus sorting and during data verification (e.g., the data storage verification phase420), a blockchain transaction, executed first among the two or more parallel blockchain transactions (e.g., the blockchain transaction424), succeeds in data verification, and modifies the piece of data. As a result, subsequent blockchain transactions, executed after the first executed blockchain transaction, will fail in data verification. In other words, even there is enough balance supporting a subsequent blockchain transaction (e.g., the blockchain transaction426), the subsequent blockchain transaction will fail in data verification since the piece of data has been modified by the first executed blockchain transaction. For example, all parallel blockchain transactions, except the first executed blockchain transaction, fails. Therefore, performance of the conventional execution scenario400is inefficient and consumes more resource when concurrent transactions are frequent on the piece of data.

FIG. 5is a block diagram illustrating an example of an execution scenario500for two parallel blockchain transactions in accordance with embodiments of this specification. The execution scenario500includes two parallel blockchain transactions that a user505intended to spend 40 yuan (¥ 40) in each blockchain transaction of the two parallel blockchain transactions. Each blockchain transaction includes a smart contract pre-execution phase510, a consensus sorting phase515, and a data storage verification phase520. In some embodiments, the execution scenario500can include more than two parallel blockchain transactions. For convenience, the execution scenario500will be described as being performed by a system of one or more computers, located in one or more locations, and programmed appropriately in accordance with this specification. For example, a computing system (e.g., the computing system106and/or108ofFIG. 1, the participant system202,204, and/or206ofFIG. 2), appropriately programmed, can perform the execution scenario500.

As illustrated inFIG. 5, the user505has a digital wallet522with a wallet balance of 100 yuan. The user505intended to spend a total of 80 yuan in two parallel blockchain transactions524and526. Each blockchain transaction is to spend 40 yuan. In some embodiments, different amount can be spent on each blockchain transaction. To execute the two parallel blockchain transactions524and526, a smart contract is first pre-executed to perform logical verification on each blockchain transaction to generate a corresponding read-write set. After consensus sorting, data verification on each blockchain transaction is performed based on the corresponding read-write set to determine whether each blockchain transaction can be executed successfully.

During the smart contract pre-execution phase510, a special instruction528(e.g., (100-40)), instead of the read-write set428inFIG. 4, is generated for the blockchain transaction524. The special instruction528indicates deducting 40 yuan from the user's account. In some embodiments, the special instruction528is used for a determination of a balance change in a smart contract. In addition, a special instruction530(e.g., (100-40)), instead of the read-write set430inFIG. 4, is generated for the blockchain transaction526. The special instruction530also indicates deducting 40 yuan from the user's account.

After the smart contract pre-execution phase510, the blockchain transaction with the special instruction528is submitted532for consensus sorting, and the blockchain transaction with the special instruction530is also submitted534for consensus sorting.

During the consensus sorting phase515, assume, for convenience, that the blockchain transaction with the special instruction528is put as a first transaction536to be executed in the data storage verification phase520, and the blockchain transaction with the special instruction530is put as a second transaction538to be executed in the data storage verification phase520.

During the data storage verification phase520, the blockchain transaction with the special instruction528is executed first540. At540, the user's account balance is read (i.e., balance=100). A determination is made as to whether the user's account balance is greater than or equals to a spending amount indicated in the special instruction528(i.e., 40). In this case, it is determined that the user's account balance is greater than or equals to the spending amount indicated in the special instruction528(i.e., 100>=40). Then, a database is modified according to the special instruction528(e.g., 40 yuan being deducted from the user's account). In other words, the data storage verification phase520for the blockchain transaction with the special instruction528succeeds, and as a result the blockchain transaction524succeeds. After the blockchain transaction with the special instruction528succeeds, the flow proceeds to542, where the blockchain transaction with the special instruction530is executed. At542, the user's account balance is read (i.e., balance=60). A determination is made as to whether the user's account balance is greater than or equals to a spending amount indicated in the special instruction530(i.e., 40). In this case, it is determined that the user's account balance is greater than or equals to the spending amount indicated in the special instruction530(i.e., 60>=40). Then, a database is modified according to the special instruction530(e.g., 40 yuan being deducted from the user's account). In other words, the data storage verification phase520for the blockchain transaction with the special instruction530succeeds, and as a result the blockchain transaction526succeeds.

Unlike the conventional execution scenario400inFIG. 4, the execution scenario500inFIG. 5generates a special instruction during logical verification (e.g., the smart contract pre-execution phase510). Instead of verifying, for example, account balance, the special instruction can be used to validate that the account balance supports a corresponding blockchain transaction during data verification. As a result, all parallel blockchain transactions can execute successfully if there is enough balance. In some embodiments, the execution scenario500can be used as an extension to the existing read-write set-model-based blockchain technology (e.g., the conventional execution scenario400inFIG. 4) to deal with multiple parallel blockchain transactions on a piece of data. For example, the special instruction based blockchain technology (e.g., the execution scenario500) can be used for accounts with frequent concurrent transactions, and a read-write set-model-based blockchain technology can be used for accounts with less or no concurrent transactions. In some embodiments, a simple logic command can be embedded into a special instruction. The special instruction can then be used to execute a corresponding logic verification during a data storage verification phase to determine whether a corresponding data transaction can be executed successfully.

Advantages can include one or more of the following. First, double-spending problem caused by concurrent reductions from an account can be solved. Multiple parallel blockchain transactions on the account can be executed successfully as long as there is enough balance in the account (e.g., logically reasonable according to special instructions). Second, special instructions are introduced as an extension to the existing read-write set-model-based blockchain technology. In smart contracts, logic to determine balance change is invoked by a special instruction. When a node performs a data status check, the special instruction is used to check a balance to determine validity of the data status. Third, the special instruction scheme is applicable to all kinds of situations where a single policy modification is applied to a piece of data in read-write set-model-based blockchain technology. The piece of data can have a data type including at least one of a numeric type, a state type, and a data type.

FIG. 6is a flowchart illustrating an example of a method600for avoiding double-spending problem in blockchain transactions in accordance with embodiments of this specification. For convenience, the method600will be described as being performed by a system of one or more computers, located in one or more locations, and programmed appropriately in accordance with this specification. For example, a computing system (e.g., the computing system106and/or108ofFIG. 1, the participant system202,204, and/or206ofFIG. 2), appropriately programmed, can perform the method600.

At602, instructions are received to execute two or more blockchain transactions on a piece of data. All blockchain transactions of the two or more blockchain transactions modify (e.g., add to, subtract from) a value of the piece of data. In some embodiments, the piece of data can be data that is used (e.g., modified) in a blockchain process. For example, the piece of data can be a user account that a user can spend money from or deposit money to. In some embodiments, the piece of data can have a data type including at least one of a numeric type, a state type, and a data type. In some embodiments, the two or more blockchain transactions are double-spending transactions and executed in parallel on the piece of data. In some embodiments, the blockchain is based on a read-write set model.

At604, for each blockchain transaction from the two or more blockchain transactions, a smart contract associated with the blockchain transaction is pre-executed to generate a special instruction indicating the blockchain transaction. The special instruction is used to validate that a current value of the piece of data supports the blockchain transaction when executing the smart contract to write the blockchain transaction to a blockchain. In some embodiments, the special instruction, instead of a read-write set, is generated when pre-executing the smart contract associated with the blockchain transaction. In other words, a read-write set is not generated when pre-executing the smart contract associated with the blockchain transaction. For example, when executing a blockchain transaction to spend 40 yuan from an account with a balance of 100 yuan, a special instruction (100-40) (such as,528and/or530ofFIG. 5) is generated and a read-write set (100→60) (such as,428and/or430ofFIG. 4) is not generated.

In some embodiments, the blockchain transaction is to deduct an amount from the piece of data. In such cases, validating that the current value of the piece of data supports the blockchain transaction comprises validating that the current value of the piece of data is greater than or equal to the amount. In some embodiments, the blockchain transaction is to deposit an amount to the piece of data. In such cases, validating that the current value of the piece of data supports the blockchain transaction may not be performed. For example, the smart contract can be executed to write the blockchain transaction to a blockchain without validating the current value of the piece of data. In some embodiments, for each blockchain transaction, pre-executing the smart contract associated with the blockchain transaction to generate the special instruction indicating the blockchain transaction comprises performing a balance check on the piece of data, and if the balance check on the piece of data supports the blockchain transaction, generating the special instruction indicating the blockchain transaction. In some embodiments, the special instruction indicates a comparison operation to be performed on the piece of data. For example, the comparison operation compares a current value of the piece of data with an amount to be deducted from the piece of data.

The method600shown inFIG. 6can be modified or reconfigured to include additional, fewer, or different actions (not shown inFIG. 6), which can be performed in the order shown or in a different order. For example, after604, the blockchain transaction is submitted for consensus sorting. In response to validating that the current value of the piece of data is greater than or equal to the amount, the smart contract associated with the blockchain transaction is executed to write the blockchain transaction to the blockchain. In some embodiments, validating that the current value of the piece of data is greater than or equal to the amount does not comprise validating that the current value of the piece of data is the same as a value of the piece of data indicated by the special instruction indicating the blockchain transaction. In some embodiments, executing the smart contract associated with the blockchain transaction to write the blockchain transaction to the blockchain comprises generating a data block associated with the blockchain transaction and publishing the data block to the blockchain. In some embodiments, one or more of the actions shown inFIG. 6can be repeated or iterated, for example, until a terminating condition is reached. In some embodiments, one or more of the individual actions shown inFIG. 6can be executed as multiple separate actions, or one or more subsets of the actions shown inFIG. 6can be combined and executed as a single action. In some embodiments, one or more of the individual actions shown inFIG. 6may also be omitted from the method600.

FIG. 7depicts examples of modules of an apparatus700in accordance with embodiments of this specification.

The apparatus700can be an example of an embodiment of a blockchain node configured to avoid double-spending problem in a blockchain network, wherein the blockchain network is a consortium blockchain network. The apparatus700can correspond to the embodiments described above, and the apparatus700includes the following: a receiving module702that receives instructions to execute two or more blockchain transactions on a piece of data; a pre-executing module704that pre-executes a smart contract associated with a blockchain transaction of the two or more blockchain transactions to generate a special instruction indicating the blockchain transaction; and a transmitting module706that transmits the blockchain transaction for consensus sorting.

In an optional embodiment, all blockchain transactions of the two or more blockchain transactions modify a value of the piece of data, and the special instruction is used to validate that a current value of the piece of data supports the blockchain transaction when executing the smart contract to write the blockchain transaction to a blockchain.

In an optional embodiment, the two or more blockchain transactions are executed in parallel on the piece of data.

In an optional embodiment, the blockchain is based on a read-write set model.

In an optional embodiment, for each blockchain transaction, the special instruction, instead of a read-write set, is generated when pre-executing the smart contract associated with the blockchain transaction.

In an optional embodiment, the apparatus700further includes a determining module for determining whether a current value of the piece of data is greater than or equal to an amount, to be deducted by the blockchain transaction and from the piece of data, for executing the smart contract to write the blockchain transaction to the blockchain.

In an optional embodiment, validating that the current value of the piece of data supports the blockchain transaction does not comprise validating that the current value of the piece of data is the same as a value of the piece of data indicated by the special instruction indicating the blockchain transaction.

In an optional embodiment, the apparatus700further includes a generating module for generating a data block associated with the blockchain transaction, and a publishing module for publishing the data block to the blockchain.

In an optional embodiment, the apparatus700further includes a balance checking module for performing a balance check on the piece of data, and a generating module for generating the special instruction indicating the blockchain transaction if the balance check on the piece of data supports the blockchain transaction.

For an embodiment process of functions and roles of each module in the apparatus, references can be made to an embodiment process of corresponding steps in the previous method. Details are omitted here for simplicity.

Because an apparatus embodiment basically corresponds to a method embodiment, for related parts, references can be made to related descriptions in the method embodiment. The previously described apparatus embodiment is merely an example. The modules described as separate parts may or may not be physically separate, and parts displayed as modules may or may not be physical modules, may be located in one position, or may be distributed on a number of network modules. Some or all of the modules can be selected based on actual demands to achieve the objectives of the solutions of the specification. A person of ordinary skill in the art can understand and implement the embodiments of the present specification without creative efforts.

Referring again toFIG. 7, it can be interpreted as illustrating an internal functional module and a structure of a blockchain data pre-execution apparatus. The blockchain data pre-execution apparatus can be an example of a blockchain node configured to avoid double-spending problem in a blockchain network. An execution body in essence can be an electronic device, and the electronic device includes the following: one or more processors; and a memory configured to store an executable instruction of the one or more processors.

The techniques described in this specification can produce one or more technical effects. In some embodiments, a special instruction is introduced as an extension to the existing read-write set-model-based blockchain technology to deal with double-spending issue (such as, executing multiple parallel blockchain transactions on a piece of data). In other embodiments, when executing multiple parallel blockchain transactions on a piece of data, a special instruction, instead of a read-write set, is generated for each blockchain transaction. In still other embodiments, a special instruction is used to validate that a current value of a piece of data supports a corresponding blockchain transaction when executing a smart contract to write the corresponding blockchain transaction to a blockchain.

Described embodiments of the subject matter can include one or more features, alone or in combination.

For example, in a first embodiment, a computer-implemented method for avoiding double-spending problem in blockchain transactions, comprising: receiving instructions to execute two or more blockchain transactions on a piece of data, wherein all blockchain transactions of the two or more blockchain transactions modify a value of the piece of data; and for each blockchain transaction from the two or more blockchain transactions: pre-executing a smart contract associated with the blockchain transaction to generate a special instruction indicating the blockchain transaction, wherein the special instruction is used to validate that a current value of the piece of data supports the blockchain transaction when executing the smart contract to write the blockchain transaction to a blockchain. The foregoing and other described embodiments can each, optionally, include one or more of the following features:

A first feature, combinable with any of the following features, specifies that the two or more blockchain transactions are executed in parallel on the piece of data.

A second feature, combinable with any of the previous or following features, specifies that the blockchain is based on a read-write set model.

A third feature, combinable with any of the previous or following features, specifies that for each blockchain transaction from the two or more blockchain transactions, the special instruction, instead of a read-write set, is generated when pre-executing the smart contract associated with the blockchain transaction.

A fourth feature, combinable with any of the previous or following features, specifies that the blockchain transaction from the two or more blockchain transactions deducts an amount from the piece of data, and wherein validating that the current value of the piece of data supports the blockchain transaction comprises validating that the current value of the piece of data is greater than or equal to the amount.

A fifth feature, combinable with any of the previous or following features, the method further comprises: submitting the blockchain transaction for consensus sorting; and in response to validating that the current value of the piece of data is greater than or equal to the amount, executing the smart contract associated with the blockchain transaction to write the blockchain transaction to the blockchain.

A sixth feature, combinable with any of the previous or following features, specifies that validating that the current value of the piece of data is greater than or equal to the amount does not comprise validating that the current value of the piece of data is the same as a value of the piece of data indicated by the special instruction indicating the blockchain transaction.

A seventh feature, combinable with any of the previous or following features, specifies that executing the smart contract associated with the blockchain transaction to write the blockchain transaction to the blockchain comprises: generating a data block associated with the blockchain transaction; and publishing the data block to the blockchain.

An eighth feature, combinable with any of the previous or following features, specifies that for each blockchain transaction from the two or more blockchain transactions, pre-executing the smart contract associated with the blockchain transaction to generate the special instruction indicating the blockchain transaction comprises: performing a balance check on the piece of data; and if the balance check on the piece of data supports the blockchain transaction, generating the special instruction indicating the blockchain transaction.

A ninth feature, combinable with any of the previous or following features, specifies that the special instruction indicates that a comparison operation is to be performed on the piece of data when executing the smart contract.

In a second embodiment, a system for avoiding double-spending problem in blockchain transactions, comprising: one or more processors; and one or more computer-readable memories coupled to the one or more processors and having instructions stored thereon which are executable by the one or more processors to perform operations comprising: receiving instructions to execute two or more blockchain transactions on a piece of data, wherein all blockchain transactions of the two or more blockchain transactions modify a value of the piece of data; and for each blockchain transaction from the two or more blockchain transactions: pre-executing a smart contract associated with the blockchain transaction to generate a special instruction indicating the blockchain transaction, wherein the special instruction is used to validate that a current value of the piece of data supports the blockchain transaction when executing the smart contract to write the blockchain transaction to a blockchain. The foregoing and other described embodiments can each, optionally, include one or more of the following features:

A first feature, combinable with any of the following features, specifies that the two or more blockchain transactions are executed in parallel on the piece of data.

A second feature, combinable with any of the previous or following features, specifies that the blockchain is based on a read-write set model.

A third feature, combinable with any of the previous or following features, specifies that for each blockchain transaction from the two or more blockchain transactions, the special instruction, instead of a read-write set, is generated when pre-executing the smart contract associated with the blockchain transaction.

A fourth feature, combinable with any of the previous or following features, specifies that the blockchain transaction from the two or more blockchain transactions deducts an amount from the piece of data, and wherein validating that the current value of the piece of data supports the blockchain transaction comprises validating that the current value of the piece of data is greater than or equal to the amount.

A fifth feature, combinable with any of the previous or following features, the operations further comprise: submitting the blockchain transaction for consensus sorting; and in response to validating that the current value of the piece of data is greater than or equal to the amount, executing the smart contract associated with the blockchain transaction to write the blockchain transaction to the blockchain.

A sixth feature, combinable with any of the previous or following features, specifies that validating that the current value of the piece of data is greater than or equal to the amount does not comprise validating that the current value of the piece of data is the same as a value of the piece of data indicated by the special instruction indicating the blockchain transaction.

A seventh feature, combinable with any of the previous or following features, specifies that executing the smart contract associated with the blockchain transaction to write the blockchain transaction to the blockchain comprises: generating a data block associated with the blockchain transaction; and publishing the data block to the blockchain.

An eighth feature, combinable with any of the previous or following features, specifies that for each blockchain transaction from the two or more blockchain transactions, pre-executing the smart contract associated with the blockchain transaction to generate the special instruction indicating the blockchain transaction comprises: performing a balance check on the piece of data; and if the balance check on the piece of data supports the blockchain transaction, generating the special instruction indicating the blockchain transaction.

A ninth feature, combinable with any of the previous or following features, specifies that the special instruction indicates that a comparison operation is to be performed on the piece of data when executing the smart contract.

In a third embodiment, an apparatus for avoiding double-spending problem in blockchain transactions, the apparatus comprising a plurality of modules for performing operations comprising: receiving instructions to execute two or more blockchain transactions on a piece of data, wherein all blockchain transactions of the two or more blockchain transactions modify a value of the piece of data; and for each blockchain transaction from the two or more blockchain transactions: pre-executing a smart contract associated with the blockchain transaction to generate a special instruction indicating the blockchain transaction, wherein the special instruction is used to validate that a current value of the piece of data supports the blockchain transaction when executing the smart contract to write the blockchain transaction to a blockchain. The foregoing and other described embodiments can each, optionally, include one or more of the following features:

A first feature, combinable with any of the following features, specifies that the two or more blockchain transactions are executed in parallel on the piece of data.

A second feature, combinable with any of the previous or following features, specifies that the blockchain is based on a read-write set model.

A third feature, combinable with any of the previous or following features, specifies that for each blockchain transaction from the two or more blockchain transactions, the special instruction, instead of a read-write set, is generated when pre-executing the smart contract associated with the blockchain transaction.

A fourth feature, combinable with any of the previous or following features, specifies that the blockchain transaction from the two or more blockchain transactions deducts an amount from the piece of data, and wherein validating that the current value of the piece of data supports the blockchain transaction comprises validating that the current value of the piece of data is greater than or equal to the amount.

A fifth feature, combinable with any of the previous or following features, the operations further comprise: submitting the blockchain transaction for consensus sorting; and in response to validating that the current value of the piece of data is greater than or equal to the amount, executing the smart contract associated with the blockchain transaction to write the blockchain transaction to the blockchain.

A sixth feature, combinable with any of the previous or following features, specifies that validating that the current value of the piece of data is greater than or equal to the amount does not comprise validating that the current value of the piece of data is the same as a value of the piece of data indicated by the special instruction indicating the blockchain transaction.

A seventh feature, combinable with any of the previous or following features, specifies that executing the smart contract associated with the blockchain transaction to write the blockchain transaction to the blockchain comprises: generating a data block associated with the blockchain transaction; and publishing the data block to the blockchain.

An eighth feature, combinable with any of the previous or following features, specifies that for each blockchain transaction from the two or more blockchain transactions, pre-executing the smart contract associated with the blockchain transaction to generate the special instruction indicating the blockchain transaction comprises: performing a balance check on the piece of data; and if the balance check on the piece of data supports the blockchain transaction, generating the special instruction indicating the blockchain transaction.

A ninth feature, combinable with any of the previous or following features, specifies that the special instruction indicates that a comparison operation is to be performed on the piece of data when executing the smart contract.

Embodiments of the subject matter and the actions and operations described in this specification can be implemented in digital electronic circuitry, in tangibly-embodied computer software or firmware, in computer hardware, including the structures disclosed in this specification and their structural equivalents, or in combinations of one or more of them. Embodiments of the subject matter described in this specification can be implemented as one or more computer programs, e.g., one or more modules of computer program instructions, encoded on a computer program carrier, for execution by, or to control the operation of, data processing apparatus. For example, a computer program carrier can include one or more computer-readable storage media that have instructions encoded or stored thereon. The carrier may be a tangible non-transitory computer-readable medium, such as a magnetic, magneto optical, or optical disk, a solid state drive, a random access memory (RAM), a read-only memory (ROM), or other types of media. Alternatively, or in addition, the carrier may be an artificially generated propagated signal, e.g., a machine-generated electrical, optical, or electromagnetic signal that is generated to encode information for transmission to suitable receiver apparatus for execution by a data processing apparatus. The computer storage medium can be or be part of a machine-readable storage device, a machine-readable storage substrate, a random or serial access memory device, or a combination of one or more of them. A computer storage medium is not a propagated signal.

A computer program, which may also be referred to or described as a program, software, a software application, an app, a module, a software module, an engine, a script, or code, can be written in any form of programming language, including compiled or interpreted languages, or declarative or procedural languages; and it can be deployed in any form, including as a stand-alone program or as a module, component, engine, subroutine, or other unit suitable for executing in a computing environment, which environment may include one or more computers interconnected by a data communication network in one or more locations.

A computer program may, but need not, correspond to a file in a file system. A computer program can be stored in a portion of a file that holds other programs or data, e.g., one or more scripts stored in a markup language document, in a single file dedicated to the program in question, or in multiple coordinated files, e.g., files that store one or more modules, sub programs, or portions of code.

Processors for execution of a computer program include, by way of example, both general- and special-purpose microprocessors, and any one or more processors of any kind of digital computer. Generally, a processor will receive the instructions of the computer program for execution as well as data from a non-transitory computer-readable medium coupled to the processor.

The term “data processing apparatus” encompasses all kinds of apparatuses, devices, and machines for processing data, including by way of example a programmable processor, a computer, or multiple processors or computers. Data processing apparatus can include special-purpose logic circuitry, e.g., an FPGA (field programmable gate array), an ASIC (application specific integrated circuit), or a GPU (graphics processing unit). The apparatus can also include, in addition to hardware, code that creates an execution environment for computer programs, e.g., code that constitutes processor firmware, a protocol stack, a database management system, an operating system, or a combination of one or more of them.

The processes and logic flows described in this specification can be performed by one or more computers or processors executing one or more computer programs to perform operations by operating on input data and generating output. The processes and logic flows can also be performed by special-purpose logic circuitry, e.g., an FPGA, an ASIC, or a GPU, or by a combination of special-purpose logic circuitry and one or more programmed computers.

Computers suitable for the execution of a computer program can be based on general or special-purpose microprocessors or both, or any other kind of central processing unit. Generally, a central processing unit will receive instructions and data from a read only memory or a random access memory or both. Elements of a computer can include a central processing unit for executing instructions and one or more memory devices for storing instructions and data. The central processing unit and the memory can be supplemented by, or incorporated in, special-purpose logic circuitry.

Generally, a computer will also include, or be operatively coupled to receive data from or transfer data to one or more storage devices. The storage devices can be, for example, magnetic, magneto optical, or optical disks, solid state drives, or any other type of non-transitory, computer-readable media. However, a computer need not have such devices. Thus, a computer may be coupled to one or more storage devices, such as, one or more memories, that are local and/or remote. For example, a computer can include one or more local memories that are integral components of the computer, or the computer can be coupled to one or more remote memories that are in a cloud network. Moreover, a computer can be embedded in another device, e.g., a mobile telephone, a personal digital assistant (PDA), a mobile audio or video player, a game console, a Global Positioning System (GPS) receiver, or a portable storage device, e.g., a universal serial bus (USB) flash drive, to name just a few.

Components can be “coupled to” each other by being commutatively such as electrically or optically connected to one another, either directly or via one or more intermediate components. Components can also be “coupled to” each other if one of the components is integrated into the other. For example, a storage component that is integrated into a processor (e.g., an L2 cache component) is “coupled to” the processor.

This specification uses the term “configured to” in connection with systems, apparatus, and computer program components. For a system of one or more computers to be configured to perform particular operations or actions means that the system has installed on it software, firmware, hardware, or a combination of them that in operation cause the system to perform the operations or actions. For one or more computer programs to be configured to perform particular operations or actions means that the one or more programs include instructions that, when executed by data processing apparatus, cause the apparatus to perform the operations or actions. For special-purpose logic circuitry to be configured to perform particular operations or actions means that the circuitry has electronic logic that performs the operations or actions.