Transaction method and system based on blockchain, electronic device and storage medium
By obtaining and combining user information, blockchain transaction sequence value and login node transaction sequence value in the blockchain environment, the third transaction sequence value for blockchain transactions is generated, which solves the problem of a large number of transaction requests submitted by users in a short time, resulting in transaction failure, and achieves transaction stability in high concurrency scenarios.
Patent Information
- Application Number
- CN202410038071.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-10
- Publication Date
- 2025-03-25
- Estimated Expiration
- 2044-01-10
AI Technical Summary
In a blockchain environment, when users submit a large number of transaction requests in a short period of time, the transaction fails.
By receiving the user's transaction request, obtaining user information, obtaining the first transaction order value on the blockchain and the second transaction order value of the login node, and generating the third transaction order value in combination with the transaction status, and using it to encapsulate the transaction data and send it to the blockchain.
It realizes the generation of real-time, unique and reasonable transaction order values for user transaction requests in high concurrency scenarios, avoids transaction failures, and improves the stability of blockchain processing user transactions.
Smart Images

Figure CN118101768B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of network technology, and in particular to a transaction method and system, electronic device and storage medium based on blockchain. Background Art
[0002] With the continuous development of the Internet, blockchain technology has emerged. It is a new generation of Internet database technology with the characteristics of decentralization, tamper-proof, openness and transparency. Users can use any device with a blockchain client to log in to the node of the blockchain network and initiate transactions to store data in the blockchain network. In the blockchain network, each node participating in the transaction can generate content data related to a transaction based on the occurrence of a transaction. These content data constitute the content data of the ledger. The content data in the ledger is associated with the account. Then, through the competition mechanism of the blockchain network, the ledger generated by each node is encrypted and the data is encapsulated to generate a new block that complies with the blockchain protocol, so that the transaction is completed through the node block.
[0003] However, with the widespread application of blockchain, more and more users are using blockchain networks, and therefore, at the same time, the number of transaction requests received by the nodes of the blockchain network is increasing day by day, and the working nodes cannot complete the block generation in time for the received transaction requests due to the limited scale of their computing resources. This will make it impossible to determine the execution order and identify the large number of transactions submitted by the user in a short period of time because the previous transactions have not been generated. Therefore, a high-concurrency transaction solution is needed that enables users to achieve high concurrency in a blockchain-based environment. Summary of the invention
[0004] The embodiments of the present application provide a blockchain-based transaction method and system, an electronic device, and a storage medium to solve the defect in the prior art that a large number of transactions are submitted by users in a short period of time in a blockchain environment, resulting in transaction failures.
[0005] To achieve the above-mentioned purpose, the embodiment of the present application provides a transaction method based on blockchain, wherein the blockchain includes multiple working nodes, and the transaction method includes:
[0006] Receiving a transaction request from a user, wherein the transaction request includes user information and transaction information;
[0007] Acquire a first transaction sequence value corresponding to the user information from the blockchain according to the user information, wherein the first transaction sequence value identifies the number of transactions initiated and agreed upon on the blockchain based on the user information;
[0008] Acquire a second transaction sequence value from a login node logged in by the user according to the user information, wherein the second transaction sequence value is a maximum value of transaction sequence values assigned to transactions initiated by the user from the login node and recorded by the login node;
[0009] generating a third transaction sequence value according to the first transaction sequence value, the second transaction sequence value, and the transaction status of each transaction recorded by the login node;
[0010] Generate encapsulated transaction data according to the third transaction sequence value and the transaction request to send to the blockchain.
[0011] The embodiment of the present application also provides a transaction system based on blockchain, the transaction system includes a business server and a blockchain, the blockchain includes multiple working nodes,
[0012] The business server is used to receive a transaction request from a user, wherein the transaction request includes user information and transaction information; obtain a first transaction sequence value corresponding to the user information from the blockchain according to the user information, wherein the first transaction sequence value identifies the number of transactions initiated and agreed upon on the blockchain based on the user information; obtain a second transaction sequence value according to the user information, wherein the second transaction sequence value is the maximum value of the transaction sequence values assigned to the transactions initiated by the user from the business server and recorded by the business server; generate a third transaction sequence value according to the first transaction sequence value, the second transaction sequence value, and the transaction status of each transaction recorded by the business server; generate encapsulated transaction data according to the third transaction sequence value and the transaction request to send to the blockchain;
[0013] The blockchain is used to obtain a first transaction sequence value corresponding to the user information from any node among the multiple working nodes according to a request for obtaining the first transaction sequence value of the business server, and send the obtained first transaction sequence value to the business server; receive the encapsulated transaction data; and distribute the encapsulated transaction data to any node among the multiple working nodes to execute a transaction corresponding to the encapsulated transaction data.
[0014] The present application also provides an electronic device, including:
[0015] Memory, used to store programs;
[0016] A processor is used to run the program stored in the memory, and when the program is run, the blockchain-based transaction method provided in the embodiment of the present application is executed.
[0017] An embodiment of the present application also provides a computer-readable storage medium, on which a computer program executable by a processor is stored, wherein the program, when executed by the processor, implements the blockchain-based transaction method provided in the embodiment of the present application.
[0018] The blockchain-based transaction method and system, electronic device, and storage medium provided in the embodiments of the present application obtain a first transaction sequence value corresponding to the user information from the blockchain according to the user information in the transaction request of the user, obtain a second transaction sequence value from the login node to which the user logs in according to the user information, generate the third transaction sequence value according to the first transaction sequence value, the second transaction sequence value, and the transaction status of each transaction recorded by the login node, and finally generate packaged transaction data according to the third transaction sequence value and the transaction request to send to the blockchain, so that in the embodiments of the present application, a real-time transaction sequence value can be generated for the transaction request of the user at the login node to which the user logs in, so that the user Each transaction initiated by the user locally can have a transaction sequence value generated according to the status of all transactions that have been initiated. Even in high-concurrency scenarios, there is no need to rely on the processing speed of the working nodes on the blockchain for the submitted transaction requests. When the login node generates the transaction sequence value, it also considers the processing status of the transaction on the blockchain when the user initiates the transaction, that is, the transaction sequence value confirmed in real time on the blockchain. Therefore, it can ensure the uniqueness and rationality of the transaction sequence value generated for each transaction initiated by the user, and ensure that each transaction data submitted to the blockchain will not fail due to the transaction sequence value, greatly improving the stability of the blockchain in processing user transactions.
[0019] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present application. Also, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:
[0021] Figure 1 A schematic diagram of an application scenario of a blockchain-based transaction solution according to an embodiment of the present application;
[0022] Figure 2 A flowchart of an embodiment of a blockchain-based transaction method provided by the present application;
[0023] Figure 3A schematic diagram of the structure of the blockchain-based transaction system provided for this application;
[0024] Figure 4 A schematic diagram of the structure of an electronic device embodiment provided in this application. DETAILED DESCRIPTION
[0025] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.
[0026] Embodiment 1
[0027] The solution provided in the embodiments of the present application can be applied to any blockchain system with blockchain data processing function.
[0028] With the continuous development of the Internet, blockchain technology has emerged. It is a new generation of Internet database technology with the characteristics of decentralization, tamper-proof, openness and transparency. Users can use any device with a blockchain client to log in to the node of the blockchain network and initiate transactions to store data in the blockchain network. In the blockchain network, each node participating in the transaction can generate content data related to a transaction based on the occurrence of a transaction. These content data constitute the content data of the ledger. The content data in the ledger is associated with the account. Then, through the competition mechanism of the blockchain network, the ledger generated by each node is encrypted and the data is encapsulated to generate a new block that complies with the blockchain protocol, so that the transaction is completed through the node block.
[0029] Due to the competition mechanism in the blockchain network, transactions initiated by users through a certain node need to consume the resources of other nodes to form new blocks, that is, to produce blocks, so as to record their own account data in the blockchain network. Therefore, for each transaction initiated by the user, the user needs to pay the corresponding resource fee, and therefore, it is necessary to sequentially identify each transaction of the user so as to charge the customer according to the content size of the transaction after consensus. With the widespread application of blockchain, more and more users are using the blockchain network, and therefore, at the same time, the number of transaction requests received by the nodes of the blockchain network is increasing. It is very likely that after a user submits a transaction request A, he does not receive transaction status feedback within the expected time, such as success or failure, so the user will submit the request A again, so that another node receives the same transaction request from the user again, which will cause the same transaction of the user to be executed repeatedly, resulting in repeated charges, and if the user's transaction involves changes in the account amount, it will also cause unnecessary losses to the user's account.
[0030] To this end, the prior art has proposed using a transaction sequence value (e.g., a Nonce value) as a sequence identifier for user transactions. Such a transaction sequence value can correspond to an account address in a blockchain network, and can therefore be used as a sequence counter to distinguish transactions initiated by different users. That is, a transaction initiated by a user in a blockchain network can only be considered completed after other nodes have completed the block generation, and the transaction sequence value assigned to the user is incremented accordingly. However, as mentioned above, at present, in the blockchain network, the nodes receive more and more transaction requests, and the working nodes are unable to complete the block generation in time for the received transaction requests due to the limitation of the scale of their computing resources. This will cause the transaction sequence value recorded for the user in the blockchain network to not be incremented in time according to the success or failure of the transaction. Therefore, it may happen that when a user submits multiple transaction requests in a short period of time, since the blockchain network is still processing the previously unfinished transactions, the transaction submitted after the last transaction that has not reached a consensus will have the same transaction sequence value as the transaction that has not reached a consensus, so that when these transactions with the same transaction sequence value are submitted to the working nodes in the blockchain network, since their transaction sequence values are the same as the transaction sequence values of the unfinished transactions, it will cause errors in the execution of these transactions.
[0031] Therefore, as more and more users transfer more work to the blockchain for execution, the load of working nodes in the blockchain network to execute user transactions is also increasing. The transaction sequence value mechanism in the existing technology results in the inability of subsequent transactions to obtain valid transaction sequence values before the previous transaction reaches a consensus among the working nodes in the blockchain network, resulting in errors in execution after submission to the blockchain network, and the existing blockchain network is unable to handle such high-concurrency transaction scenarios.
[0032] For example, Figure 1 As shown in Figure 1 is a schematic diagram showing an application scenario of a blockchain-based transaction solution according to an embodiment of the present application. Figure 1 In the transaction scheme shown in , the user can log in to the business server by using a mobile terminal or PC terminal installed with a predetermined application, and after logging in, the business server can be used to initiate a transaction request for the blockchain network. For example, in the blockchain network, multiple, for example, two or more working nodes can be arranged to facilitate the execution of transactions indicated by transaction data submitted by the user through the business server, and for transactions completed by any working node, other working nodes can perform consensus processing on the transaction completion information broadcast by the working node executing the transaction according to a predetermined consensus mechanism, and when the consensus processing is completed according to the consensus mechanism, other blockchains can create a new block for the transaction data, that is, a block, and correspondingly update the transaction sequence value corresponding to the user who submitted the transaction. Therefore, in the blockchain, the current transaction sequence value for the user is recorded on each working node, that is, the transaction sequence value corresponding to the transaction that completed the consensus processing most recently. When the user continues to submit another transaction data through the business server, in the prior art, the business server first obtains the latest transaction sequence value of the user from the blockchain network, and the blockchain network can obtain the transaction sequence value corresponding to the user information of the user, such as the account address, from any working node when receiving the user's request to obtain the transaction sequence value, and send it to the business server as the basis for the transaction sequence value used when the user submits the other transaction data. For example, the business server can increment the transaction sequence value obtained from the blockchain network by 1 as the transaction sequence value of this transaction. Therefore, the transaction request newly submitted by the user and the transaction sequence value obtained based on the increment of the transaction sequence value obtained from the blockchain network can be encapsulated as transaction data and sent to the blockchain network. The blockchain network can first put the transaction data obtained in this way into the transaction pool set on the blockchain, so that each working node in the blockchain network can obtain transaction data from the transaction pool for execution according to its workload. For example, such as Figure 1The work node 1 shown in can obtain the transaction data 1 submitted by user 1, and can first extract the transaction sequence value contained in the transaction data 1, for example, obtain the transaction sequence value 4. Then the obtained transaction sequence value 4 can be compared with the transaction sequence value (for example, 3) already stored in the work node 1. When it is confirmed that the transaction sequence value 4 contained in the transaction data is the next sequence value of the transaction sequence value 3 already stored in the node, the work node 1 can confirm that the transaction data is executable, and therefore call the corresponding resources to process the transaction according to the transaction information contained in the transaction data. However, as described above, with the increase in the number of users using the blockchain and the increase in the amount of transactions submitted by users, when the transaction containing the transaction sequence value 4 is processed by the work node 1, the user 1 submits a new transaction request, and as described above, the business server that receives the transaction request can obtain the transaction sequence value corresponding to the user from the blockchain network according to the user information of the user 1, for example, the transaction sequence value can be obtained from the work node 2. At this time, since the transaction data containing the transaction sequence value 4 is in the process of being processed by working node 1, or is in the process of being processed by working node 1 but not yet completing the consensus processing of other nodes, the transaction sequence value obtained by the business server from working node 2 of the blockchain network for the new transaction is still the transaction sequence value of the previous transaction that has completed the consensus processing, that is, 3. Therefore, the transaction sequence value obtained by the business server for the new transaction request submitted by the user is still 3, and the business server still increments based on the transaction sequence value of 3 as the transaction sequence value of the new transaction request, so that the new transaction request contains the same transaction sequence value as the previous transaction request, and if after being placed in the transaction pool by the blockchain network, if working node 1 completes the previous transaction and other nodes also complete the consensus processing, then each working node in the blockchain network will update the transaction sequence value of the user to the transaction sequence value 4 of the transaction that has just completed the consensus processing. Afterwards, if, for example, Worker Node 2 goes to the transaction pool to extract the next transaction of the user, and thus extracts a transaction containing a transaction sequence value of 4, then when Worker Node 2 checks the transaction sequence value of the transaction data, it will find that the transaction sequence value contained in the transaction is the same as the transaction sequence value of the user recorded on the node, so the node will think that the transaction has been processed, and therefore will not or cannot execute the new transaction, resulting in the failure of the transaction request submitted by the user. When the number of requests submitted by the user in a short period of time is large, such as in a high-concurrency scenario, a large number of transactions similar to the above-mentioned new transaction will fail because the assigned transaction sequence value cannot pass the verification of the worker node.
[0033] In the embodiment of the present application, Figure 1As shown in , the user can use various terminals to log in to the business server, for example, to log in to the interface provided by the business server. Then the user can initiate a transaction request for the blockchain on the interface, for example, the transaction request can include user information and transaction information. In an embodiment of the present application, the user information can be an account address on the blockchain that uniquely identifies the identity of the user on the blockchain, and the transaction information can be information such as transfer or other computing tasks that the user wants to perform on the blockchain. After receiving such a transaction request submitted by the user, the business server can first request the first transaction sequence value from the blockchain according to the user information contained in the transaction request. In an embodiment of the present application, the first transaction sequence value can be the transaction sequence value assigned to the last transaction that has completed consensus processing corresponding to the user information of the user in the blockchain, such as the user's account address on the blockchain, as described above. In other words, in an embodiment of the present application, the transaction sequence value can also identify the number of transactions initiated and reached consensus on the target blockchain based on the user information. For example, in the example discussed above, when the user initiates the transaction for the first time, the transaction sequence value corresponding to the user information of the user obtained in the blockchain network is 3, that is, in the blockchain network, when the user submits the transaction request 1, the transaction sequence value of the previous transaction that has been executed and completed the consensus processing for the user in the blockchain network is 3, or the number of transactions initiated and completed by the user in the blockchain network is 3. In the prior art, after the business server obtains the transaction sequence value from the blockchain network, it directly increments the transaction sequence value by 1 as the transaction sequence value corresponding to the current transaction request. However, as mentioned above, when the user submits a large number of transaction requests in a short period of time, such a method will cause such high-concurrency submitted transactions to be assigned the same transaction sequence value, and thus cause errors to occur when the working nodes of the blockchain network are processed and cannot be executed. In the embodiment of the present application, when the business server obtains the first transaction sequence value from the blockchain network, it can further obtain the second transaction sequence value from the business server locally according to the user information. The second transaction sequence value can be the maximum value of the transaction sequence of all transactions initiated by the user from the business server recorded locally by the business server. In other words, in the embodiment of the present application, since the business server is the login node that directly receives the transaction initiated by the user, the business server can maintain the transaction sequence value of all transactions submitted by the user locally by clearly recording the sequence of all transactions initiated by the user. Even if the user submits a large number of transaction requests in a short period of time, these transaction requests are submitted sequentially to the business server, so the business server can record the sequence value of each transaction request.For example, in the embodiment of the present application, the second sequence value is actually the transaction sequence value assigned to the previous transaction request of the transaction request submitted by the user, that is, the maximum value of the transaction sequence values recorded by the login node and assigned to the transaction initiated by the user from the login node. Therefore, the business server, for example, in the example described above, when the user submits a new transaction request 2 on the business server, the transaction sequence value 3 of the previous transaction request 1 of the transaction request 2 can be recorded on the business server, and therefore, next, the business server can generate the third transaction sequence value of the transaction request 2 newly submitted by the user based on the transaction sequence value 3 obtained from the blockchain network and the transaction sequence value 3 of the transaction request last submitted by the user recorded locally, that is, determine that the transaction sequence value of the transaction request 2 newly submitted by the user should be 4. Finally, the business server can encapsulate the generated third transaction sequence value 4 as the transaction sequence value of the transaction request 2 submitted by the user together with the transaction request 2 to generate transaction data, and send it to the blockchain.
[0034] After receiving the transaction data through its gateway, the blockchain can put the transaction data into the transaction pool, and the working nodes in the blockchain can obtain the transaction data from the transaction pool. Figure 1In the scenario shown in , after the transaction data generated by the business server based on the user's transaction request 2 encapsulation is placed in the transaction pool, if, for example, when the working node 2 goes to the transaction pool to obtain the transaction data, the transaction request 1 previously submitted by the user has not been processed by consensus, then the transaction sequence value corresponding to the user (user information) stored in each working node is still 2. At this time, when the working node obtains the transaction data of the user from the transaction pool, the transaction sequence value contained in the transaction data in the transaction pool is 4, which is discontinuous with the current transaction sequence value recorded in the working node, so that the working node will not extract the transaction data from the transaction pool to perform transaction processing; and if the transaction request 1 with a transaction data value of 3 previously submitted by the user has been completed by consensus when the working node 2 goes to the transaction pool to obtain the transaction data, so that the transaction sequence value corresponding to the user (user information) recorded in each working node (for example, the working node 2) has become 3, then the transaction sequence value 4 contained in the transaction data in the transaction pool is continuous with 3, so the transaction data can be extracted by the working node 2 for processing. It can be seen that in this embodiment of the present application, even if the user submits a new transaction request 2 before the previous transaction request (transaction request 1) has completed consensus processing, the business server can determine that a new transaction sequence value 4 should be assigned to transaction request 2 based on the current transaction sequence value in the blockchain and the transaction sequence value of the locally recorded submitted transaction, so that when transaction request 2 is extracted by the working node in the blockchain network, the transaction processing will not fail due to its transaction sequence value being the same as the transaction sequence value of the previous transaction, thereby greatly improving the stability of user submission of transactions in high concurrency scenarios.
[0035] The above embodiments are illustrations of the technical principles and exemplary application frameworks of the embodiments of the present application. The specific technical solutions of the embodiments of the present application are further described in detail below through multiple embodiments.
[0036] Embodiment 2
[0037] Figure 2 The flowchart of the embodiment of the transaction method based on blockchain provided by the present application, the execution subject of the method can be various terminals or server devices with data processing capabilities, or it can be a device or chip integrated on these devices. In particular, the blockchain used by the transaction method of the embodiment of the present application may include multiple working nodes for processing user transactions, and the user can use his own terminal as a login node for accessing the blockchain or can also use a business server set on the Internet as a login node for accessing the blockchain.
[0038] For example, in an embodiment of the present application, a transaction method based on blockchain may include:
[0039] S101, receiving a transaction request from a user.
[0040] In the embodiment of the present application, the user can use various terminals to log in to the business server, for example, can log in to the interface provided by the business server so as to access the blockchain network through the business server as a login node. In step S101, the user can initiate a transaction request of the blockchain by performing various operations on the interface, so that in step S101, for example, the login node of the business server can receive the transaction request submitted by the user.
[0041] For example, the transaction request received in step S101 may include user information and transaction information. In the embodiment of the present application, the user information may be a user ID that uniquely identifies the user's identity on the blockchain or an account address on the blockchain, and the transaction information may be information such as a transfer or other computing tasks that the user wants to perform on the blockchain.
[0042] S102, obtaining a first transaction sequence value corresponding to the user information from the blockchain according to the user information.
[0043] In step S102, the login node to which the user logs in may request the first transaction sequence value from the blockchain according to the user information included in the transaction request received in step S101. In an embodiment of the present application, the first transaction sequence value may be the user information corresponding to the user in the blockchain, such as the transaction sequence value assigned to the last transaction that has completed consensus processing for the user's account address on the blockchain.
[0044] In the embodiment of the present application, the transaction sequence value may also identify the number of transactions initiated and agreed upon on the target blockchain based on the user information. For example, when a user submits a transaction request through a business server, the transaction sequence value corresponding to the user information of the user obtained in the blockchain network is 3. The value 3 may mean that in the blockchain network, when the user submits the transaction request, the transaction sequence value of the last transaction that has been executed and completed consensus processing for the user in the blockchain network is 3, or that the number of transactions initiated and completed consensus processing by the user in the blockchain network as of step S102 is 3.
[0045] S103, obtaining a second transaction sequence value from the login node where the user logs in according to the user information.
[0046] In step S103, when or after the first transaction sequence value is obtained from the blockchain network in step S102, the second transaction sequence value can be obtained locally from the login node according to the user information. In the embodiment of the present application, the second transaction sequence value can be the maximum value of the transaction sequence of all transactions initiated by the user from the login node locally recorded by the login node logged in by the user.
[0047] In other words, in the embodiment of the present application, since the login node is the node that directly receives the transaction initiated by the user, the login node can maintain the transaction sequence value of all transactions submitted by the user locally by clearly recording the order of all transactions initiated by the user. Even if the user submits a large number of transaction requests in a short period of time, these transaction requests are submitted sequentially to the login node, so the login node can record the sequence value of each transaction request. For example, in the embodiment of the present application, the second sequence value obtained in step S103 is actually the transaction sequence value assigned to the previous transaction request submitted by the user in step S101, that is, the maximum value of the transaction sequence values assigned to the transactions initiated by the user from the login node recorded by the login node.
[0048] S104, generating a third transaction sequence value according to the first transaction sequence value, the second transaction sequence value and the transaction status of each transaction recorded by the login node.
[0049] In step S104, a third transaction sequence value for the transaction request received in step S101 can be generated based on the first transaction sequence value obtained from the blockchain in step S102 and the second transaction sequence value locally recorded by the login node obtained in step S103, and further based on the transaction status of each transaction submitted by the user locally recorded by the login node.
[0050] For example, when a transaction request newly submitted by the user through the login node is received in step S101, the transaction sequence value of the last transaction that completed consensus processing recorded by the working node of the blockchain can be obtained from the blockchain network in step S102, such as 3, and the transaction sequence value of the last transaction request recorded by the login node before the transaction request can be obtained in step S104, such as 3. Therefore, in step S104, the login node can generate a third transaction sequence value of the transaction request newly submitted by the user based on the transaction sequence value 3 obtained from the blockchain network and the transaction sequence value 3 of the transaction request last submitted by the user recorded locally, that is, determine that the transaction sequence value of the transaction request newly submitted by the user should be 4.
[0051] For example, in step S104, the first transaction sequence value obtained in step S102 may be first incremented by 1 to obtain a first self-incrementing transaction sequence value, and then it may be determined from each transaction recorded by the login node whether there is a transaction whose assigned transaction sequence value is the same as the generated first self-incrementing transaction sequence value and whose transaction status is in process; when it is determined that there is a transaction whose assigned transaction sequence value is the same as the first self-incrementing transaction sequence value and whose transaction status is in process, the second transaction sequence value is incremented by 1 to obtain the second self-incrementing transaction sequence value as the third transaction sequence value. When it is determined that there is no transaction whose assigned transaction sequence value is the same as the first self-incrementing transaction sequence value and whose transaction status is in process, the first self-incrementing transaction sequence value is used as the third transaction sequence value.
[0052] S105, generating packaged transaction data according to the third transaction sequence value and the transaction request, and sending the data to the blockchain.
[0053] In step S105, the third transaction sequence value generated in step S104 can be used as the transaction sequence value of the transaction request received in step S101 to encapsulate the transaction request together with the transaction request to generate transaction data, and send it to the blockchain.
[0054] For example, in step S105, the hash value of the generated encapsulated transaction data may be calculated first, and then the encapsulated transaction data may be signed to obtain signed transaction data, and the signed transaction data may be sent to the blockchain.
[0055] After the blockchain receives the transaction data, for example through its gateway, the transaction data can be put into a transaction pool, and the working nodes in the blockchain can obtain the transaction data from the transaction pool. For example, after the transaction data generated based on the user's transaction request encapsulation in step S105 is placed into the transaction pool by the blockchain network, if, for example, the transaction request previously submitted by the user has not been processed by consensus when the working node goes to the transaction pool to obtain the transaction data, then the transaction sequence value corresponding to the user (user information) stored in each working node is still 2. At this time, when the working node obtains the transaction data of the user from the transaction pool, the transaction sequence value contained in the transaction data in the transaction pool is 4, which is discontinuous with the current transaction sequence value recorded in the working node, and the working node will not extract the transaction data from the transaction pool to perform transaction processing; and if, when the working node goes to the transaction pool to obtain the transaction data, the transaction request with a transaction data value of 3 previously submitted by the user has been completed by consensus, so that the transaction sequence value corresponding to the user (user information) recorded in each working node (for example, working node 2) has become 3, then the transaction sequence value 4 contained in the transaction data in the transaction pool is continuous with 3, so the transaction data can be extracted by the working node for processing.
[0056] The blockchain-based transaction method provided in the embodiment of the present application obtains a first transaction sequence value corresponding to the user information from the blockchain according to the user information in the transaction request of the user, obtains a second transaction sequence value from the login node to which the user logs in according to the user information, generates the third transaction sequence value according to the first transaction sequence value, the second transaction sequence value and the transaction status of each transaction recorded by the login node, and finally generates packaged transaction data according to the third transaction sequence value and the transaction request to send to the blockchain, so that in the embodiment of the present application, a real-time transaction sequence value can be generated for the user's transaction request at the login node to which the user logs in, so that each transaction initiated by the user from the local can have a transaction sequence value generated according to the status of all transactions that have been initiated, even in a high-concurrency scenario, there is no need to rely on the processing speed of the working node on the blockchain for the submitted transaction request, and when the login node generates the transaction sequence value, the processing status of the transaction on the blockchain when the user initiates the transaction is also considered, that is, the transaction sequence value confirmed in real time on the blockchain, so that the uniqueness and rationality of the transaction sequence value generated for each transaction initiated by the user can be ensured, and each transaction data submitted to the blockchain will not fail due to the transaction sequence value, which greatly improves the stability of the blockchain in processing user transactions.
[0057] Embodiment 3
[0058] Figure 3 This is a schematic diagram of the structure of the blockchain-based transaction system provided in this application. The blockchain-based transaction system can be used to implement, for example, Figure 2 The transaction method based on blockchain provided by the embodiment of the present application is described. The transaction system according to the embodiment of the present application may include a business server 31 and a blockchain 32. The blockchain 32 may include multiple working nodes 33, which may be used to process transactions submitted by users through the business server 31. Users may use their own terminals as login nodes for accessing the blockchain or may use the business server 31 set on the Internet as a login node for accessing the blockchain.
[0059] The business server 31 can be used to receive a transaction request from a user. For example, in an embodiment of the present application, a user can use various terminals to log in to the business server 31, for example, can log in to the interface provided by the business server 31 so as to access the blockchain 32 through the business server 31. The user can initiate a transaction request for the blockchain 32 by performing various operations on the interface, so that, for example, the business server 31 can receive the transaction request submitted by the user. In an embodiment of the present application, the transaction request received by the business server 31 may include user information and transaction information. The user information may be a user ID that uniquely identifies the identity of the user on the blockchain 32 or an account address on the blockchain, and the transaction information may be information such as a transfer or other computing tasks that the user wants to perform on the blockchain 32.
[0060] The business server 31 may also be used to request a first transaction sequence value from the blockchain 32 according to the user information included in the received transaction request. In the embodiment of the present application, the first transaction sequence value may be the user information corresponding to the user in the blockchain 32, such as the transaction sequence value assigned to the last transaction that has completed consensus processing for the user's account address on the blockchain 32. In the embodiment of the present application, the transaction sequence value may also identify the number of transactions initiated and reached consensus on the blockchain 32 based on the user information.
[0061] For example, when a user submits a transaction request through the business server 31, the transaction sequence value corresponding to the user information of the user on the blockchain 32 is 3. The value 3 may mean that in the blockchain 32, when the user submits the transaction request through the business server 31, the transaction sequence value of the last transaction that has been executed and completed consensus processing for the user in the blockchain 32 is 3, or that by the time the business server 31 receives the transaction request submitted by the user or the business server 31 queries the blockchain 32 for the transaction sequence value of the user in response to the transaction request submitted by the user, the number of transactions initiated and completed consensus processing by the user in the blockchain network is 3.
[0062] The business server 31 may also be used to obtain a second transaction sequence value from the login node to which the user logs in according to the user information. For example, when or after the business server 31 obtains the first transaction sequence value from the working node 33 of the blockchain 32, it may obtain the second transaction sequence value from its local location according to the user information. In the embodiment of the present application, the second transaction sequence value may be the maximum value of the transaction sequence of all transactions initiated by the user from the business server 31 that the user logs in to and that is recorded locally.
[0063] In other words, in the embodiment of the present application, since the business server 31 is the node that directly receives the transaction initiated by the user, the business server 31 can maintain the transaction sequence value of all transactions submitted by the user locally by clearly recording the order of all transactions initiated by the user. Even if the user submits a large number of transaction requests in a short period of time, these transaction requests are submitted sequentially to the business server 31, so the business server 31 can record the sequence value of each transaction request. For example, in the embodiment of the present application, the second sequence value obtained by the business server 31 is actually the transaction sequence value assigned to the previous transaction request before receiving the transaction request submitted by the user, that is, the maximum value of the transaction sequence values assigned to the transactions initiated by the user from the business server 31 recorded by the business server 31.
[0064] The business server 31 may be further configured to generate a third transaction sequence value based on the first transaction sequence value, the second transaction sequence value, and the transaction status of each transaction recorded locally. The business server 31 may generate a third transaction sequence value for the received transaction request based on the first transaction sequence value obtained from the blockchain 32 and the second transaction sequence value recorded locally, and further based on the transaction status of each transaction that the user has submitted recorded locally.
[0065] For example, when the business server 31 receives a transaction request newly submitted by a user, the transaction sequence value of the last transaction that completed consensus processing recorded by the working node of the blockchain, such as 3, and the transaction sequence value of the last transaction request of the transaction request recorded locally, such as 3, can be obtained from any working node 33 of the blockchain 32. Therefore, the business server 31 can generate a third transaction sequence value of the transaction request newly submitted by the user based on the transaction sequence value 3 obtained from the blockchain 32 and the transaction sequence value 3 of the transaction request last submitted by the user recorded locally, that is, determine that the transaction sequence value of the transaction request newly submitted by the user should be 4.
[0066] For example, the business server 31 may first increment the acquired first transaction sequence value by 1 to obtain the first self-incrementing transaction sequence value, and then determine from each locally recorded transaction whether there is a transaction whose assigned transaction sequence value is the same as the generated first self-incrementing transaction sequence value and whose transaction status is in process; when it is determined that there is a transaction whose assigned transaction sequence value is the same as the first self-incrementing transaction sequence value and whose transaction status is in process, the second transaction sequence value is incremented by 1 to obtain the second self-incrementing transaction sequence value as the third transaction sequence value. When it is determined that there is no transaction whose assigned transaction sequence value is the same as the first self-incrementing transaction sequence value and whose transaction status is in process, the first self-incrementing transaction sequence value is used as the third transaction sequence value.
[0067] The business server 31 may also be used to generate encapsulated transaction data according to the third transaction sequence value and the transaction request to send to the blockchain 32. For example, the business server 31 may encapsulate the generated third transaction sequence value together with the transaction request as the transaction sequence value of the received transaction request to generate transaction data, and send it to the blockchain 32. For example, the hash value of the generated encapsulated transaction data may be calculated first, and then the encapsulated transaction data may be signed to obtain the signed transaction data, and the signed transaction data may be sent to the blockchain 32.
[0068] After receiving the transaction data sent by the business server 31, the blockchain 32 distributes the encapsulated transaction data to any node in the plurality of working nodes 33 to execute the transaction corresponding to the encapsulated transaction data. After receiving the transaction data, the blockchain 32 can put the transaction data into the transaction pool, and the working node 33 in the blockchain 32 can obtain the transaction data from the transaction pool. For example, after the transaction data generated based on the user's transaction request encapsulation is placed into the transaction pool by the blockchain 32, if, for example, when the working node 33 goes to the transaction pool to obtain the transaction data, the transaction request previously submitted by the user has not been processed by consensus, then at this time, the transaction sequence value corresponding to the user (user information) stored in each working node 33 is still 2. At this time, when the working node 33 obtains the transaction data of the user from the transaction pool, the transaction sequence value contained in the transaction data in the transaction pool is 4, which is discontinuous with the current transaction sequence value recorded in the working node 33, so that the working node 33 will not extract the transaction data from the transaction pool to perform transaction processing; and if the transaction request with a transaction data value of 3 previously submitted by the user has been completed by consensus when the working node 33 goes to the transaction pool to obtain the transaction data, so that the transaction sequence value corresponding to the user (user information) recorded in each working node 33 has become 3, then the transaction sequence value 4 contained in the transaction data in the transaction pool is continuous with 3, so the transaction data can be extracted by the working node 33 for processing.
[0069] The blockchain-based transaction system provided in the embodiment of the present application obtains the first transaction sequence value corresponding to the user information from the blockchain according to the user information in the transaction request of the user, obtains the second transaction sequence value from the login node to which the user logs in according to the user information, generates the third transaction sequence value according to the first transaction sequence value, the second transaction sequence value and the transaction status of each transaction recorded by the login node, and finally generates encapsulated transaction data according to the third transaction sequence value and the transaction request to send to the blockchain, so that in the embodiment of the present application, a real-time transaction sequence value can be generated for the user's transaction request at the login node to which the user logs in, so that each transaction initiated by the user from the local can have a transaction sequence value generated according to the status of all transactions that have been initiated, even in a high-concurrency scenario, there is no need to rely on the processing speed of the working node on the blockchain for the submitted transaction request, and when the login node generates the transaction sequence value, the processing status of the transaction on the blockchain when the user initiates the transaction is also considered, that is, the transaction sequence value confirmed in real time on the blockchain, so that the uniqueness and rationality of the transaction sequence value generated for each transaction initiated by the user can be ensured, and each transaction data submitted to the blockchain will not fail due to the transaction sequence value, which greatly improves the stability of the blockchain in processing user transactions.
[0070] Embodiment 4
[0071] The above describes the internal functions and structure of a blockchain-based transaction system, which can be implemented as an electronic device. Figure 4 This is a schematic diagram of the structure of an electronic device embodiment provided by this application. Figure 4 As shown, the electronic device includes a memory 41 and a processor 42 .
[0072] The memory 41 is used to store programs. In addition to the above programs, the memory 41 can also be configured to store various other data to support operations on the electronic device. Examples of such data include instructions for any application or method operating on the electronic device, contact data, phone book data, messages, pictures, videos, etc.
[0073] The memory 41 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0074] The processor 42 is not limited to a processor (CPU), but may also be a processing chip such as a graphics processing unit (GPU), a field programmable gate array (FPGA), an embedded neural network processor (NPU) or an artificial intelligence (AI) chip. The processor 42 is coupled to the memory 41 and executes the program stored in the memory 41 to execute the blockchain-based transaction method of the above-mentioned embodiment 2.
[0075] Further, if Figure 4 As shown, the electronic device may also include: a communication component 43, a power component 44, an audio component 45, a display 46 and other components. Figure 4 Only some components are shown schematically, which does not mean that the electronic device only includes Figure 4 Components shown.
[0076] The communication component 43 is configured to facilitate wired or wireless communication between the electronic device and other devices. The electronic device can access a wireless network based on a communication standard, such as WiFi, 3G, 4G or 5G, or a combination thereof. In an exemplary embodiment, the communication component 43 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 43 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0077] The power supply assembly 44 provides power to various components of the electronic device. The power supply assembly 44 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the electronic device.
[0078] The audio component 45 is configured to output and / or input audio signals. For example, the audio component 45 includes a microphone (MIC), and when the electronic device is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 41 or sent via the communication component 43. In some embodiments, the audio component 45 also includes a speaker for outputting audio signals.
[0079] The display 46 includes a screen, which may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from a user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundary of a touch or slide action, but also detect the duration and pressure associated with the touch or slide operation.
[0080] Those skilled in the art can understand that all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, the steps of the above-mentioned method embodiments are executed; and the aforementioned storage medium includes: ROM, RAM, disk or optical disk and other media that can store program codes.
[0081] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A transaction method based on blockchain, characterized in that: The blockchain includes multiple working nodes, and the transaction method includes: Receiving a transaction request from a user, wherein the transaction request includes user information and transaction information; Acquire a first transaction sequence value corresponding to the user information from the blockchain according to the user information, wherein the first transaction sequence value identifies the number of transactions initiated and agreed upon on the blockchain based on the user information; Acquire a second transaction sequence value from a login node logged in by the user according to the user information, wherein the second transaction sequence value is a maximum value of transaction sequence values assigned to transactions initiated by the user from the login node and recorded by the login node; generating a third transaction sequence value according to the first transaction sequence value, the second transaction sequence value, and the transaction status of each transaction recorded by the login node; generating encapsulated transaction data according to the third transaction sequence value and the transaction request to send to the blockchain, The generating the third transaction sequence value according to the first transaction sequence value, the second transaction sequence value and the transaction status of each transaction recorded by the login node comprises: Incrementing the first transaction sequence value by 1 to obtain a first self-incrementing transaction sequence value; Determine from each transaction recorded by the login node whether there is a transaction whose assigned transaction sequence value is the same as the first self-incrementing transaction sequence value and whose transaction status is in processing; When it is determined that there is a transaction whose assigned transaction sequence value is the same as the first self-incrementing transaction sequence value and whose transaction status is in progress, the second transaction sequence value is incremented by 1 to obtain a second self-incrementing transaction sequence value as the third transaction sequence value; When it is determined that there is no transaction whose assigned transaction sequence value is the same as the first self-incrementing transaction sequence value and whose transaction status is in-process, the first self-incrementing transaction sequence value is used as the third transaction sequence value.
2. The transaction method according to claim 1, characterized in that: The generating packaged transaction data according to the third transaction sequence value and the transaction request to send to the blockchain includes: generating encapsulated transaction data according to the third transaction sequence value and the transaction request; Calculating a hash value of the encapsulated transaction data; Signing the encapsulated transaction data to obtain signed transaction data; The signed transaction data is sent to the blockchain.
3. A transaction system based on blockchain, the transaction system comprising a business server and a blockchain, the blockchain comprising a plurality of working nodes, characterized in that: The business server is used to receive a transaction request from a user, wherein the transaction request includes user information and transaction information; obtain a first transaction sequence value corresponding to the user information from the blockchain according to the user information, wherein the first transaction sequence value identifies the number of transactions initiated and agreed upon on the blockchain based on the user information; obtain a second transaction sequence value according to the user information, wherein the second transaction sequence value is the maximum value of the transaction sequence values assigned to the transactions initiated by the user from the business server and recorded by the business server; generate a third transaction sequence value according to the first transaction sequence value, the second transaction sequence value, and the transaction status of each transaction recorded by the business server; generate encapsulated transaction data according to the third transaction sequence value and the transaction request to send to the blockchain; The blockchain is used to obtain the first transaction sequence value corresponding to the user information from any node among the multiple working nodes according to the first transaction sequence value acquisition request of the business server, and send the acquired first transaction sequence value to the business server; receive the encapsulated transaction data; distribute the encapsulated transaction data to any node among the multiple working nodes to execute the transaction corresponding to the encapsulated transaction data, The generating the third transaction sequence value according to the first transaction sequence value, the second transaction sequence value and the transaction status of each transaction recorded by the business server comprises: Incrementing the first transaction sequence value by 1 to obtain a first self-incrementing transaction sequence value; Determine from each transaction recorded by the business server whether there is a transaction whose assigned transaction sequence value is the same as the first self-incrementing transaction sequence value and whose transaction status is in processing; When it is determined that there is a transaction whose assigned transaction sequence value is the same as the first self-incrementing transaction sequence value and whose transaction status is in progress, the second transaction sequence value is incremented by 1 to obtain a second self-incrementing transaction sequence value as the third transaction sequence value; When it is determined that there is no transaction whose assigned transaction sequence value is the same as the first self-incrementing transaction sequence value and whose transaction status is in-process, the first self-incrementing transaction sequence value is used as the third transaction sequence value.
4. The trading system according to claim 3, characterized in that: The generating packaged transaction data according to the third transaction sequence value and the transaction request to send to the blockchain includes: generating encapsulated transaction data according to the third transaction sequence value and the transaction request; Calculating a hash value of the encapsulated transaction data; Signing the encapsulated transaction data to obtain signed transaction data; The signed transaction data is sent to the blockchain.
5. An electronic device, characterized in that: include: Memory, used to store programs; A processor, configured to run the program stored in the memory to execute the blockchain-based transaction method as described in any one of claims 1 to 2.
6. A computer-readable storage medium having a computer program executable by a processor stored thereon, characterized in that: When the program is executed by a processor, the blockchain-based transaction method as described in any one of claims 1-2 is implemented.
Citation Information
Patent Citations
Account book synchronization method and device of blockchain based on DAG
CN109672733A
Transaction number processing method and device, storage medium and computer equipment
CN113343292A