Method and apparatus for scheduling blockchain transaction, electronic device, and storage medium

By scheduling blockchain transactions based on resource consumption parameters, the problems of resource waste and performance reduction in blockchain transaction scheduling are solved, and more efficient transaction execution is achieved.

WO2024239558A1PCT designated stage expired Publication Date: 2024-11-28TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2023/131387
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-05-25
Filing Date
2023-11-14
Publication Date
2024-11-28

AI Technical Summary

Technical Problem

During the execution of blockchain transactions, conflicting transactions require scheduling, and the prior art is usually based on preset order or execution time order, resulting in waste of resources and reduced performance.

Method used

By obtaining multiple blockchain transactions to be executed, the conflict relationship between the target transaction and the reference transaction is determined, and scheduling is carried out based on the weights based on the resource consumption parameters, the transactions that consume more resources are retained, and the transactions that consume less resources are re-executed. trade.

Benefits of technology

It effectively avoids resource waste, improves the performance of the blockchain network, and optimizes the transaction scheduling process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2023131387_28112024_PF_FP_ABST
    Figure CN2023131387_28112024_PF_FP_ABST
Patent Text Reader

Abstract

Disclosed in embodiments of the present application are a method and apparatus for scheduling blockchain transactions, an electronic device, and a storage medium. In the method for scheduling blockchain transactions, a plurality of blockchain transactions are executed, and a completely executed blockchain transaction is taken as a target transaction; when the target transaction and a first reference transaction, which conflict with each other, are scheduled, a first weight of the target transaction and a second weight of the first reference transaction are determined. As the first weight and the second weight are both determined on the basis of resource consumption parameters, the target transaction is scheduled according to the size relation between the first weight and the second weight, which is equivalent to scheduling the target transaction according to the resource consumption parameters, so that when the target transaction is scheduled, a blockchain transaction that consumes more resources can be kept, and a blockchain transaction that consumes fewer resources is re-executed. This avoids resource wastage and improves the performance of the blockchain network. The method can be widely applied to the technical fields of cloud computing, blockchains, etc.
Need to check novelty before this filing date? Find Prior Art

Description

Blockchain transaction scheduling method, device, electronic device and storage medium

[0001] This application claims priority to the Chinese patent application filed with the China Patent Office on May 25, 2023, with application number 2023106047443 and application name “Scheduling method, device, electronic device and storage medium for blockchain transactions”, the entire contents of which are incorporated by reference into this application. Technical Field

[0002] The present application relates to the field of blockchain technology, and in particular to transaction scheduling technology in blockchain. Background Art

[0003] Currently, when executing blockchain transactions, if conflicting transactions occur, they must be executed serially. This necessitates scheduling transactions, preserving one transaction while re-executing the remaining ones. Related technologies typically retain transactions based on a pre-set transaction order or the order in which they were completed. This approach can cause resource-intensive transactions to be re-executed, resulting in wasted resources and reduced blockchain network performance.

[0004] Summary of the Invention

[0005] The embodiments of the present application provide a method, device, electronic device, and storage medium for scheduling blockchain transactions, which can avoid resource waste and improve the performance of the blockchain network.

[0006] In one aspect, an embodiment of the present application provides a method for scheduling blockchain transactions, which is executed by a computer device and includes:

[0007] Obtain multiple blockchain transactions to be executed, and execute each of the blockchain transactions;

[0008] Obtaining a completed target transaction from each of the blockchain transactions, and determining a first conflict relationship between the target transaction and at least one first reference transaction, wherein the first reference transaction is a currently completed blockchain transaction other than the target transaction;

[0009] When the first conflict relationship indicates that there is a conflict between the target transaction and the first reference transaction, obtaining a first weight of the target transaction and a second weight of the first reference transaction, wherein the first weight is determined based on a resource consumption parameter when executing the target transaction, and the second weight is determined based on a resource consumption parameter when executing the first reference transaction;

[0010] The target transaction is scheduled according to a magnitude relationship between the first weight and the second weight.

[0011] On the other hand, an embodiment of the present application further provides a blockchain transaction scheduling device, comprising:

[0012] An execution module, configured to obtain a plurality of blockchain transactions to be executed and execute each of the blockchain transactions;

[0013] a conflict detection module, configured to obtain a completed target transaction from each of the blockchain transactions and determine a first conflict relationship between the target transaction and at least one first reference transaction, wherein the first reference transaction is a currently completed blockchain transaction other than the target transaction;

[0014] a weight acquisition module, configured to, when the first conflict relationship indicates that there is a conflict between the target transaction and the first reference transaction, acquire a first weight of the target transaction and a second weight of the first reference transaction, wherein the first weight is determined based on a resource consumption parameter when executing the target transaction, and the second weight is determined based on a resource consumption parameter when executing the first reference transaction;

[0015] The first scheduling module is configured to schedule the target transaction according to a size relationship between the first weight and the second weight.

[0016] On the other hand, an embodiment of the present application further provides a computer device comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the above-mentioned blockchain transaction scheduling method when executing the computer program.

[0017] On the other hand, an embodiment of the present application further provides a computer-readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement the above-mentioned blockchain transaction scheduling method.

[0018] In another aspect, embodiments of the present application further provide a computer program product, comprising a computer program stored in a computer-readable storage medium. A processor of a computer device reads the computer program from the computer-readable storage medium and executes the computer program, causing the computer device to implement the aforementioned blockchain transaction scheduling method.

[0019] The embodiments of the present application include at least the following beneficial effects: by executing multiple blockchain transactions, taking the executed blockchain transactions as target transactions, and scheduling the conflicting target transactions and the first reference transaction, obtaining the first weight of the target transaction and the second weight of the first reference transaction; since the first weight and the second weight are both determined based on the resource consumption parameter, scheduling the target transaction according to the size relationship between the first weight and the second weight is equivalent to scheduling the target transaction according to the resource consumption parameter, so that when scheduling the target transaction, the blockchain transaction with more resource consumption can be retained and the blockchain transaction with less resource consumption can be re-executed, thereby avoiding resource waste and improving the performance of the blockchain network. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] FIG1 is a schematic diagram of an optional implementation environment provided in an embodiment of the present application;

[0021] FIG2 is a schematic diagram of an optional flow chart of a method for scheduling blockchain transactions according to an embodiment of the present application;

[0022] FIG3 is a schematic diagram of an optional process flow before deterministic scheduling optimization provided in an embodiment of the present application;

[0023] FIG4 is a schematic diagram of an optional process after deterministic scheduling optimization provided in an embodiment of the present application;

[0024] FIG5 is a schematic diagram of an optional flow chart of the first scheduling step provided in an embodiment of the present application;

[0025] FIG6 is a schematic diagram of an optional flow chart of the second scheduling step provided in an embodiment of the present application;

[0026] FIG7 is a schematic diagram of an optional architecture before non-deterministic scheduling optimization provided in an embodiment of the present application;

[0027] FIG8 is a schematic diagram of an optional architecture after non-deterministic scheduling optimization provided in an embodiment of the present application;

[0028] FIG9 is a schematic diagram of an optional process flow after non-deterministic scheduling optimization provided in an embodiment of the present application;

[0029] FIG10 is a schematic diagram of another optional process after non-deterministic scheduling optimization provided in an embodiment of the present application;

[0030] FIG11 is a schematic diagram of an optional process of block verification between nodes provided in an embodiment of the present application;

[0031] FIG12 is a schematic diagram of an optional structure of a scheduling device for blockchain transactions provided in an embodiment of the present application;

[0032] FIG13 is a schematic diagram of another optional structure of a scheduling device for blockchain transactions provided in an embodiment of the present application;

[0033] FIG14 is a schematic diagram of another optional structure of a scheduling device for blockchain transactions provided in an embodiment of the present application;

[0034] FIG15 is a schematic diagram of another optional structure of a scheduling device for blockchain transactions provided in an embodiment of the present application;

[0035] FIG16 is a partial structural block diagram of a terminal provided in an embodiment of the present application;

[0036] FIG17 is a partial structural block diagram of the server provided in an embodiment of the present application. DETAILED DESCRIPTION

[0037] In order to make the purpose, technical solutions and advantages of this application more clear, the following further describes this application in detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain this application and are not intended to limit this application.

[0038] It should be noted that, in each specific embodiment of the present application, when it comes to the need to perform relevant processing based on data related to the characteristics of the target object such as target object attribute information or attribute information set, the permission or consent of the target object will be obtained first, and the collection, use and processing of these data will comply with relevant laws, regulations and standards. Among them, the target object can be a user. In addition, when the embodiment of the present application needs to obtain target object attribute information, the target object's separate permission or separate consent will be obtained through a pop-up window or by jumping to a confirmation page. After clearly obtaining the target object's separate permission or separate consent, the necessary target object-related data for the normal operation of the embodiment of the present application will be obtained.

[0039] To facilitate understanding of the technical solutions provided in the embodiments of the present application, some key terms used in the embodiments of the present application are explained here:

[0040] Blockchain is a new application model for computer technologies, including distributed data storage, peer-to-peer transmission, consensus mechanisms, and encryption algorithms. Essentially, a blockchain is a decentralized database, a series of linked data blocks generated using cryptographic methods. Each block contains information about a batch of online transactions, which is used to verify the validity of the information (to prevent counterfeiting) and generate the next block.

[0041] The blockchain can include the blockchain underlying platform, the platform product service layer, and the application service layer. The blockchain underlying platform can include processing modules such as user management, basic services, smart contracts, and operational detection. Among them, the user management module is responsible for managing the identity information of all blockchain participants, including maintaining public and private key generation (account management), key management, and maintaining the correspondence between the user's real identity and the blockchain address (authority management), etc., and under authorization, it supervises and audits the transactions of certain real identities and provides risk control rule configuration (risk control audit); the basic service module is deployed on all blockchain node devices to verify the validity of business requests and record and store them after the valid requests have completed consensus. For a new business request, the basic service first adapts the interface to parse and authenticate (interface adaptation), and then encrypts the business information through the consensus algorithm (consensus Management), which is transmitted completely and consistently to a shared ledger after encryption (network communication) for record storage. The smart contract module is responsible for contract registration, issuance, contract triggering, and contract execution. Developers can define contract logic in a programming language and publish it to the blockchain (contract registration). Based on the logic of the contract terms, they call keys or trigger other events to complete the contract logic. It also provides the ability to upgrade and cancel contracts. The operation detection module is mainly responsible for deployment, configuration modification, contract setting, cloud adaptation, and real-time status visualization during product release. For example, it can detect alarms, network conditions, and node device health. The platform product service layer provides the basic capabilities and implementation framework for typical applications. Developers can build on these basic capabilities and overlay business features to complete the blockchain implementation of business logic. The application service layer provides application services based on blockchain solutions for business participants.

[0042] Cloud computing refers to the delivery and usage model of IT infrastructure, enabling on-demand, scalable access to required resources over the internet. Broadly speaking, cloud computing refers to the delivery and usage model of services, enabling on-demand, scalable access to required services over the internet. These services can be IT-related, software-related, internet-related, or other services. Cloud computing is the product of the convergence of traditional computer and network technologies, including grid computing, distributed computing, parallel computing, utility computing, network storage technologies, virtualization, and load balancing.

[0043] Currently, when executing blockchain transactions, if conflicting transactions occur, they must be executed serially. This requires scheduling, which involves retaining one transaction while re-executing the remaining transactions. Related technologies typically retain transactions based on a pre-set transaction order or the order in which they were completed. This approach can cause resource-intensive transactions to be re-executed, resulting in wasted resources and reduced blockchain network performance.

[0044] Based on this, the embodiments of the present application provide a method, device, electronic device and storage medium for scheduling blockchain transactions, which can avoid resource waste and improve the performance of the blockchain network.

[0045] Referring to Figure 1, Figure 1 is a schematic diagram of an optional implementation environment provided in an embodiment of the present application, the implementation environment includes a terminal 101 and a server 102, wherein the terminal 101 and the server 102 are connected via network communication, and the number of terminals 101 can be one or more.

[0046] Exemplarily, any terminal 101 can send a blockchain transaction to be executed to the server 102, any two terminals 101 can send different blockchain transactions, and the same terminal 101 can also send different blockchain transactions. The server 102 can obtain multiple blockchain transactions to be executed and then execute each blockchain transaction; obtain the executed target transaction from the multiple blockchain transactions, and determine the first conflict relationship between the target transaction and at least one first reference transaction, wherein the first reference transaction is a currently executed blockchain transaction other than the target transaction; when the first conflict relationship indicates that there is a conflict between the target transaction and the first reference transaction, obtain a first weight of the target transaction and a second weight of the first reference transaction, wherein the first weight is determined based on the resource consumption parameters when executing the target transaction, and the second weight is determined based on the resource consumption parameters when executing the first reference transaction; schedule the target transaction according to the size relationship between the first weight and the second weight.

[0047] The server 102 executes multiple blockchain transactions and uses the completed blockchain transactions as target transactions. When scheduling the conflicting target transactions and the first reference transaction, the server 102 obtains the first weight of the target transaction and the second weight of the first reference transaction. Since the first weight and the second weight are both determined based on the resource consumption parameters when executing the corresponding transactions, scheduling the target transaction according to the size relationship between the first weight and the second weight is equivalent to scheduling the target transaction according to the resource consumption parameters. Therefore, when scheduling the target transaction, the blockchain transaction with more resource consumption can be retained and the blockchain transaction with less resource consumption can be re-executed, thereby avoiding resource waste and improving the performance of the blockchain network.

[0048] Server 102 can be a standalone physical server, a server cluster or distributed system consisting of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. Furthermore, server 102 can be a node server in a blockchain network.

[0049] The terminal 101 may be a smartphone, tablet computer, laptop computer, desktop computer, smart speaker, smart watch, vehicle-mounted terminal, etc., but is not limited thereto. The terminal 101 and the server 102 may be connected directly or indirectly via wired or wireless communication, which is not limited in this embodiment of the present application.

[0050] The method provided in the embodiments of the present application can be applied to various technical fields, including but not limited to cloud computing, blockchain and other technical fields.

[0051] 2 , which is a schematic diagram of an optional flow chart of a method for scheduling blockchain transactions according to an embodiment of the present application. The method for scheduling blockchain transactions may be executed by a computer device, specifically a server, or a terminal, or a server in cooperation with a terminal. The method for scheduling blockchain transactions includes but is not limited to steps 201 to 204 .

[0052] Step 201: Obtain multiple blockchain transactions to be executed and execute each blockchain transaction.

[0053] Among them, blockchain transactions refer to transactions generated in the blockchain network. Blockchain nodes in the blockchain network can execute blockchain transactions. Blockchain nodes store ledgers, which include blockchains and world state databases. The world state database is a database that stores the current status of all state data. The world state refers to the current status of all state data. The blockchain is used to record historical transactions involved in the process of changing all state data from the initial state to the current state. Among them, state data can be stored in the form of key-value pairs. The current state refers to the key of the state data, the value corresponding to the key, and the current version number; blockchain nodes executing blockchain transactions refer to reading or writing state data. If the blockchain transaction is used to read state data, the blockchain transaction will include the key of the state data. If the blockchain transaction is used to write state data, the blockchain transaction will include the key of the state data and the value corresponding to the key.

[0054] Exemplarily, the first blockchain transaction is used to read the first state data and write the second state data. The first blockchain transaction includes the key key1 of the first state data, the key key2 of the second state data, and the value value2' of the key key2. When the first blockchain transaction is executed, the value value1 corresponding to the key key1 is read from the world state database. At this time, the current version number of the key key1 in the world state database will not change. Then, the value value2' corresponding to the key key2 is written into the world state database, and the version number corresponding to the key key2 in the world state database will change. For example, before the execution of the first blockchain transaction, the world state database stores the key key2, the value corresponding to the key key2 is value2, and the current version number corresponding to the key key2 is 1. After the execution of the first blockchain transaction, the value corresponding to the key key2 is updated to value2', the current version number corresponding to the key key2 is increased by one, and the current version number corresponding to the key key2 is updated to 2.

[0055] Based on this, in an embodiment of the present application, after a blockchain node obtains multiple blockchain transactions to be executed, the blockchain node can use multiple threads to concurrently execute each blockchain transaction. It can be understood that threads can also be replaced by execution bodies such as processes and coroutines. Each thread executes one blockchain transaction, and each blockchain transaction needs to correspond to the same initial world state, which is equivalent to the execution environment of each thread being the same. Specifically, the current world state is obtained from the world state database, and the current world state is used as the initial world state. Then, each thread executes the corresponding blockchain transaction based on the same initial world state.

[0056] For example, a batch of 20 blockchain transactions to be executed is obtained, and then based on the same initial world state, the 20 blockchain transactions are executed concurrently using multiple threads. After all 20 blockchain transactions are executed, the intermediate world state corresponding to each blockchain transaction can be obtained. Generally speaking, due to differences between different blockchain transactions, the intermediate world state corresponding to each blockchain transaction is different. Therefore, 20 different intermediate world states can be obtained.

[0057] Step 202: Obtain a completed target transaction from each blockchain transaction, and determine a first conflict relationship between the target transaction and at least one first reference transaction.

[0058] The first reference transaction is a currently executed blockchain transaction other than the target transaction.

[0059] Among them, the execution time of different blockchain transactions may be different. When a blockchain transaction is executed, the executed blockchain transaction can be used as a target transaction. If no other blockchain transactions are executed when the target transaction is executed, it means that at the moment when the target transaction is executed, there is no conflict between other blockchain transactions and the target transaction; conversely, if other blockchain transactions have been executed when the target transaction is executed, it means that at the moment when the target transaction is executed, there may be a conflict between other blockchain transactions and the target transaction. Therefore, the currently executed blockchain transaction other than the target transaction is used as the first reference transaction, and conflict detection is performed on the target transaction and the first reference transaction to determine the first conflict relationship between the target transaction and the first reference transaction, wherein the first conflict relationship is used to indicate whether there is a conflict between the target transaction and the first reference transaction.

[0060] For example, based on the above content about using multiple threads to concurrently execute 20 blockchain transactions, it can be seen that after all 20 blockchain transactions are executed, 20 corresponding intermediate world states can be obtained. Since a corresponding read set and write set will be created for each blockchain transaction during the execution of each blockchain transaction; the read set is used to indicate the state data read when executing the blockchain transaction. Therefore, the read set includes the key of the read state data and the submission version number corresponding to the key. The read set may also include the value corresponding to the key of the read state data; the write set is used to indicate the state data inserted, deleted or updated when executing the blockchain transaction. Therefore, the write set includes the key of the written state data and the value corresponding to the key. The read set and write set of the blockchain transaction can be collectively referred to as the read-write set of the blockchain transaction.

[0061] Among them, in multiple blockchain transactions executed serially, when the blockchain transaction with an earlier execution order is completed and the current status of the corresponding status data is updated, the current version number corresponding to the key will change. When the blockchain transaction with an earlier execution order is executed and the status data needs to be read, the current version number corresponding to the key of the status data will be read. If the version number corresponding to the key is updated when the blockchain transaction with an earlier execution order is executed, the current version number corresponding to the key is the updated version number. The updated version number is used as the submitted version number corresponding to the key and recorded in the read set.

[0062] Therefore, executing 20 blockchain transactions can obtain 20 read-write sets. Under ideal conditions, any two read-write sets are disjoint. Disjoint read-write sets means that the two read-write sets do not contain the same key. At this time, the above 20 blockchain transactions can be executed in parallel, and the 20 intermediate world states obtained by execution can be directly merged to obtain the final world state, which is then used as the execution result of this batch of blockchain transactions. Under normal circumstances, there will be at least one pair of intersecting read-write sets. Intersection of two read-write sets means that the two read-write sets contain at least one identical key. When the read-write set of one blockchain transaction intersects with the read-write set of another blockchain transaction, it is equivalent to that the two blockchain transactions conflict with each other, and each conflicting blockchain transaction needs to be executed serially.

[0063] Step 203: When the first conflict relationship indicates that there is a conflict between the target transaction and the first reference transaction, a first weight of the target transaction and a second weight of the first reference transaction are obtained.

[0064] The first weight is determined based on the resource consumption parameter when executing the target transaction, and the second weight is determined based on the resource consumption parameter when executing the first reference transaction.

[0065] The resource consumption parameter is used to indicate the resources consumed in executing a blockchain transaction. The resource may be a time resource, a memory resource, or the like. For example, when the resource is a time resource, the resource consumption parameter may be the execution time of the blockchain transaction. When the resource is a memory resource, the resource consumption parameter may be at least one of the number of read-set keys, the read-set memory size, the number of write-set keys, and the write-set memory size.

[0066] Among them, when the first conflict relationship indicates that there is a conflict between the target transaction and the first reference transaction, it means that the target transaction and the first reference transaction need to be executed serially, and the first weight of the target transaction is determined based on the resource consumption parameters when executing the target transaction, and the second weight of the first reference transaction is determined based on the resource consumption parameters when executing the first reference transaction. Then, according to the weight between the first weight of the target transaction and the second weight of the first reference transaction, the target transaction and the first reference transaction are scheduled.

[0067] Step 204: Schedule the target transaction based on the relationship between the first weight and the second weight.

[0068] Specifically, when the weight is positively correlated with the resource consumption parameter, that is, the more resources consumed, the greater the corresponding weight, if the first weight is greater than the second weight, it means that the resources consumed when executing the target transaction are greater than the resources consumed when executing the first reference transaction. In this case, the target transaction can be retained and the first reference transaction can be re-executed. If the first weight is less than the second weight, it means that the resources consumed when executing the target transaction are less than the resources consumed when executing the first reference transaction. In this case, the first reference transaction can be retained and the target transaction can be re-executed.

[0069] Among them, since the first weight and the second weight are both determined based on the resource consumption parameters, scheduling the target transaction according to the size relationship between the first weight and the second weight is equivalent to scheduling the target transaction according to the resource consumption parameters. Therefore, when scheduling the target transaction, the blockchain transaction with more resource consumption can be retained and the blockchain transaction with less resource consumption can be re-executed, thereby avoiding resource waste and improving the performance of the blockchain network.

[0070] In a possible implementation, the target transaction is scheduled according to the relationship between the first weight and the second weight, specifically:

[0071] Scheduling the target transaction based on the relationship between the first weight and each second weight;

[0072] Alternatively, the sum of the second weights is calculated as the sum of the first weights, and the target transaction is scheduled according to the relationship between the first weights and the sum of the first weights.

[0073] Among them, the size relationship between the first weight and each second weight means that the first weight is greater than the second weight, or the first weight is less than the second weight, or the first weight is equal to the second weight; the size relationship between the first weight and the sum of the first weights means that the first weight is greater than the sum of the first weights, or the first weight is less than the sum of the first weights, or the first weight is equal to the sum of the first weights.

[0074] Among them, by comparing the first weight and each second weight, it is possible to effectively determine whether the resource consumption when executing the target transaction is greater than the resource consumption when executing each first reference transaction, and then retain the blockchain transaction with more resource consumption and re-execute the blockchain transaction with less resource consumption, thereby avoiding resource waste and improving the performance of the blockchain network.

[0075] In one possible implementation, the target transaction is obtained when all acquired blockchain transactions are executed, and the first reference transaction is not added to the transaction snapshot. The target transaction is scheduled based on the relationship between the first weight and each second weight. Specifically, the scheduling may be:

[0076] When the first weight is greater than each second weight, adding the target transaction to the transaction snapshot;

[0077] Alternatively, when the first weight is less than any second weight, re-execute the target transaction;

[0078] Alternatively, when the first weight is equal to the maximum value of the second weights, the target transaction is added to the transaction snapshot or the target transaction is re-executed.

[0079] Among them, the transaction snapshot refers to the completion queue of the blockchain transaction. When the blockchain transaction is executed, the executed blockchain is added to the transaction snapshot, which is equivalent to adding the executed blockchain to the end of the completion queue. When multiple blockchain transactions are executed concurrently using multiple threads, the number of completion queues can be multiple, and the number of completion queues depends on the number of blockchain transactions that can be executed in parallel; when multiple blockchain transactions with conflicting relationships correspond to the same completion queue, the blockchain transaction added to the transaction snapshot first is positioned at the front of the completion queue, and the blockchain transaction added to the transaction snapshot later is positioned at the back of the completion queue. Subsequently, the blockchain transactions with conflicting relationships can be executed in sequence according to the order in the completion queue.

[0080] Among them, blockchain transactions can be scheduled in a deterministic scheduling manner, and the execution result of each blockchain transaction is certain. Deterministic scheduling performs conflict detection on blockchain transactions in a round-by-round manner. In deterministic scheduling, the time point of conflict detection is configured as follows: when all blockchain transactions are executed, conflict detection is performed on each executed blockchain transaction separately to determine the conflict relationship between each executed blockchain transaction. For example, in the first round, conflict detection is performed on blockchain transactions only after all blockchain transactions are executed to determine the conflict relationship between each blockchain transaction. The result of the conflict detection may be that there is no conflict between multiple blockchain transactions, or the result of the conflict detection may be that there is a conflict between multiple blockchain transactions. The result of the conflict detection is that there is a conflict between multiple blockchain transactions or there is no conflict between multiple blockchain transactions. When the result of the conflict detection indicates that there is no conflict between multiple blockchain transactions, it means that the multiple blockchain transactions can be executed in parallel. When the result of the conflict detection indicates that there is a conflict between multiple blockchain transactions, it means that the multiple blockchain transactions need to be executed serially.

[0081] For multiple conflicting blockchain transactions, only one of them is retained in the current round and added to the transaction snapshot. The remaining blockchain transactions are re-executed in the next round. Since deterministic scheduling handles conflicts between blockchain transactions in a round-by-round manner, conflict detection is performed on the blockchain transactions in the next round only after all blockchain transactions that need to be re-executed have been re-executed. Therefore, in deterministic scheduling, the target transaction is obtained when all acquired blockchain transactions have been executed. The first reference transaction to be conflict-detected has not been added to the transaction snapshot, so there is no need to perform conflict detection on the first reference transaction that has been added to the transaction snapshot.

[0082] Currently, when using deterministic scheduling to schedule multiple conflicting blockchain transactions, the blockchain transaction that is executed first is added to the transaction snapshot in the order of the time when the blockchain transactions are executed, and the remaining blockchain transactions are re-executed. This may cause the blockchain transactions that consume more resources to be re-executed, resulting in resource waste and reduced blockchain network performance.

[0083] Based on this, the scheduling method provided in the embodiment of the present application can optimize deterministic scheduling. When scheduling a target transaction and a first reference transaction that conflict with each other, the first weight of the target transaction and the second weight of the first reference transaction are first obtained. Since the first weight and the second weight are respectively determined based on the resource consumption parameters when executing the target transaction and executing the first reference transaction, scheduling the target transaction according to the size relationship between the first weight and the second weight is equivalent to scheduling the target transaction according to the corresponding resource consumption parameter. The resource consumption parameter is used to indicate the resources required to execute the blockchain transaction. The first weight is used to indicate the resources required to execute the target transaction, and the second weight is used to indicate the resources required to execute the first reference transaction. When the resources required to execute the target transaction are small, the first weight of the target transaction is small. Conversely, when the resources required to execute the target transaction are large, the first weight of the target transaction is large. Similarly, when the resources required to execute the first reference transaction are small, the second weight of the first reference transaction is small. Conversely, when the resources required to execute the first reference transaction are large, the second weight of the first reference transaction is large.

[0084] Specifically, for the three comparison situations of the first weight and the second weight, when the first weight is the largest, the target transaction is retained and added to the transaction snapshot; when the first weight is less than any second weight, the target transaction is re-executed; when the first weight is the same as the maximum value of each second weight, the target transaction can be added to the transaction snapshot or re-executed. In this way, when scheduling the target transaction, the blockchain transaction with more resource consumption can be retained and the blockchain transaction with less resource consumption can be re-executed, thereby avoiding resource waste and improving the performance of the blockchain network.

[0085] Exemplarily, for three blockchain transactions A, B, and C that conflict with each other, before executing the blockchain transactions, the sequence numbers of the three blockchain transactions can be determined as: A < B < C, and these three blockchain transactions are executed in parallel. The first-round execution results are: A, B, C. Assume that the order of the amounts of resources required to execute these three blockchain transactions is: A < B < C. In the first round, when all three blockchain transactions are executed, conflict detection is performed on the blockchain transactions. Since blockchain transaction A, blockchain transaction B, and blockchain transaction C conflict with each other, scheduling is required for blockchain transaction A, blockchain transaction B, and blockchain transaction C. One of the blockchain transactions is taken as the target transaction, and the remaining blockchain transactions are taken as the first reference transactions. When blockchain transaction A is the target transaction and blockchain transactions B and C are the first reference transactions, the first weight of blockchain transaction A is less than the second weight of blockchain transaction B, and at the same time, the first weight of blockchain transaction A is less than the second weight of blockchain transaction C. Therefore, blockchain transaction A is re-executed in the next round. Similarly, when blockchain transaction B is the target transaction and blockchain transactions A and C are the first reference transactions, the first weight of blockchain transaction B is less than the second weight of blockchain transaction C, and it can be determined that blockchain transaction B needs to be re-executed in the next round. In the next round, blockchain transactions A and B can be executed in parallel; when blockchain transaction C is the target transaction and blockchain transactions A and B are the first reference transactions, the first weight of blockchain transaction C is greater than the second weight of blockchain transaction A, and the first weight of blockchain transaction C is greater than the second weight of blockchain transaction B. Therefore, blockchain transaction C is added to the transaction snapshot; thus, in the conflict handling of the first round, it is possible to retain the blockchain transaction C that consumes more resources and add this blockchain transaction C to the transaction snapshot, and re-execute the blockchain transactions A and B that consume less resources. Similarly, in the conflict handling of the second round, it is possible to retain the blockchain transaction B that consumes more resources and add this blockchain transaction B to the transaction snapshot, and re-execute the blockchain transaction A that consumes less resources, avoiding resource waste and improving the performance of the blockchain network.

[0086] In a possible implementation, adding the target transaction to the transaction snapshot or re-executing the target transaction can specifically be to form a first transaction set by using the target transaction and the first reference transaction corresponding to the second weight equal to the first weight; adding any one of the blockchain transactions in the first transaction set to the transaction snapshot and re-executing the remaining blockchain transactions in the first transaction set.

[0087] Based on this, when processing the case where the first weight is the same as the maximum value of each second weight, that is, when processing the case where the first weight is the same as some of the second weights and the first weight is greater than the remaining second weights, the target transaction and the first reference transaction with the same first weight as the target transaction are combined into a first transaction set, and then in the first transaction set, the blockchain transactions that need to be added to the transaction snapshot are selected, and the blockchain transactions that need to be re-executed are selected, so that conflicting blockchain transactions can be executed serially.

[0088] Among them, the blockchain transactions to be added to the transaction snapshot can be selected by random selection. Specifically, one blockchain transaction is randomly selected in the first transaction set and added to the transaction snapshot, and the remaining blockchain transactions in the first transaction set are re-executed. When all blockchain transactions are added to the transaction snapshot, in the results of each random selection, no matter which blockchain transaction is selected to be added to the transaction snapshot, it can be guaranteed that conflicting blockchain transactions can be executed serially.

[0089] Based on this, when random selection is used, the execution order of multiple blockchain transactions executed serially is not fixed. However, as long as the execution results are the same after all blockchain transactions are executed, consensus can be achieved later. The execution process of blockchain transactions is: first call the transaction execution function in the smart contract, and then process the historical transaction data according to the transaction execution function and blockchain transactions. There can be multiple smart contracts, and multiple transaction execution functions can be deployed in one smart contract. Therefore, it is necessary to call the corresponding transaction execution function in the corresponding smart contract. Historical transaction data refers to the state data in the initial world state before the execution of the blockchain transaction. The execution result of the blockchain transaction is the final world state after the execution of the blockchain transaction. Therefore, when non-conflicting blockchain transactions are executed in parallel and conflicting blockchain transactions are executed serially, changing the execution order of multiple serially executed blockchain transactions can also make the final world state obtained after all blockchain transactions are executed the same.

[0090] Among them, state data can be stored in the form of key-value pairs. Different blockchain transactions can be used to process state data corresponding to different keys, or to process state data corresponding to the same key. When different blockchain transactions are used to process state data corresponding to the same key, and the blockchain transactions are executed in parallel, there will be conflicts between the blockchain transactions.

[0091] For example, a batch of three pending blockchain transactions is as follows: the first blockchain transaction involves a transfer of 100 yuan from the first party to the second party through their account; the second blockchain transaction involves a transfer of 200 yuan from the first party to the third party through their account; and the third blockchain transaction involves a transfer of 200 yuan from the fourth party to the fifth party through their account. Before each blockchain transaction is executed, the corresponding state data in the initial world state is as follows: the first historical transaction data indicates that the first party has 500 yuan in its account, and the second historical transaction data indicates that the fourth party has 300 yuan in its account.

[0092] Through conflict detection, it can be determined that the first blockchain transaction and the second blockchain transaction conflict with each other, and the first blockchain transaction and the second blockchain transaction need to be executed serially. The third blockchain transaction does not conflict with the remaining blockchain transactions, and the third blockchain transaction can be executed in parallel with the remaining blockchain transactions.

[0093] Assuming that executing the first blockchain transaction and executing the second blockchain transaction require the same amount of resources, which is equivalent to the first blockchain transaction and the second blockchain transaction having the same weight, a random selection method can be used for selection.

[0094] In the first case: first call the first transaction execution function to execute the first blockchain transaction, process the first historical transaction data, and obtain a first execution result that the first object has 400 yuan in the account. Then use the first execution result as the historical transaction data, and then call the second transaction execution function to execute the second blockchain transaction. Process the first execution result, and obtain a second execution result that the first object has 200 yuan in the account. During the execution of the first and second blockchain transactions, the third blockchain transaction can be executed in parallel. Call the third transaction execution function to execute the third blockchain transaction, process the third historical transaction data, and obtain a third execution result that the fourth object has 100 yuan in the account. Therefore, the final world state after all blockchain transactions are executed is: the first object has 200 yuan in the account, and the fourth object has 100 yuan in the account.

[0095] In the second case: first call the second transaction execution function to execute the second blockchain transaction, process the first historical transaction data, and obtain a first execution result that the first object has 300 yuan in its account. Then use the first execution result as the historical transaction data, call the first transaction execution function again to execute the first blockchain transaction, process the first execution result, and obtain a second execution result that the first object has 200 yuan in its account. During the execution of the first and second blockchain transactions, the third blockchain transaction can be executed in parallel. Call the third transaction execution function to execute the third blockchain transaction, process the third historical transaction data, and obtain a third execution result that the fourth object has 100 yuan in its account. Therefore, the final world state after all blockchain transactions are executed is: the first object has 200 yuan in its account, and the fourth object has 100 yuan in its account.

[0096] It can be seen that compared with the first case, the second case does not change the final world state obtained after all blockchain transactions are executed; therefore, when non-conflicting blockchain transactions are executed in parallel, and when conflicting blockchain transactions are executed serially, changing the execution order of multiple serially executed blockchain transactions can also make the final world state obtained after all blockchain transactions are executed the same.

[0097] Specifically, a fixed selection method may be used. Specifically, the blockchain transaction at a fixed position in the first transaction set is added to the transaction snapshot, and the remaining blockchain transactions in the first transaction set are re-executed. Assuming that the blockchain transactions are arranged in order in the first transaction set, the fixed position may be the first or the last. Therefore, the blockchain transaction at the first or the last position in the first transaction set is added to the transaction snapshot. The fixed position may also be the middle position. When the number of blockchain transactions in the first transaction set is an even number, half of the number is used as the value of the middle position. For example, if the number of transactions is 4 and the value of the middle position is 2, the blockchain transaction at the second position in the first transaction set is added to the transaction snapshot. Similarly, the fixed selection method will not affect the execution result of the blockchain transaction.

[0098] In one possible implementation, the blockchain transaction scheduling method further includes:

[0099] When a blockchain transaction that has not been added to the transaction snapshot is re-executed, the blockchain transaction that has been re-executed and not added to the transaction snapshot will be used as the target transaction;

[0100] The target transaction is rescheduled until all blockchain transactions are added to the transaction snapshot.

[0101] Among them, the target transaction can be scheduled in a deterministic scheduling manner. Deterministic scheduling is to perform conflict detection on blockchain transactions in a round-by-round manner. For example, in the first round, conflict detection is performed on blockchain transactions only after all blockchain transactions have been executed to determine the conflict relationship between each blockchain transaction. The result of the conflict detection may be that there is no conflict between multiple blockchain transactions, or the result of the conflict detection may be that there is a conflict between multiple blockchain transactions. When the result of the conflict detection indicates that there is no conflict between multiple blockchain transactions, it means that the multiple blockchain transactions can be executed in parallel. Therefore, when the target transaction does not conflict with each first reference transaction, the target transaction can be added to the transaction snapshot without re-executing the target transaction; however, when the result of the conflict detection indicates that there is a conflict between multiple blockchain transactions, it means that the multiple blockchain transactions need to be executed serially.

[0102] When the target transaction conflicts with the first reference transaction, the target transaction cannot be executed in parallel with the conflicting first reference transaction. The target transaction is scheduled based on the relationship between the first weight and the second weight. Specifically, in the current round, for conflicting blockchain transactions, the blockchain transaction with the largest weight is added to the transaction snapshot, and the blockchain transaction with the smaller weight is re-executed in the next round. In addition, in the second round, after all blockchain transactions that need to be re-executed are re-executed, conflict detection is performed on the re-executed blockchain transactions. The re-executed blockchain transactions are equivalent to the target transactions in the first round. Therefore, the target transaction can be scheduled again according to the scheduling method of the first round. It can be seen that in the current round, if there are still conflicting blockchain transactions, the blockchain transaction with the smaller weight needs to be re-executed, and then the target transaction is scheduled again in the next round until a round is entered in which there are no conflicting blockchain transactions. At the end of this round, the scheduling of the target transaction is completed, which is equivalent to all blockchain transactions being added to the transaction snapshot.

[0103] Specifically, referring to Figure 3, Figure 3 is an optional flow chart before deterministic scheduling optimization provided by an embodiment of the present application. In the order in which the blockchain transactions are executed, the first blockchain transactions to be executed are added to the transaction snapshot, and the remaining blockchain transactions are re-executed. This may cause the blockchain transactions that consume more resources to be re-executed, thereby resulting in resource waste and reducing the performance of the blockchain network.

[0104] In addition, referring to Figure 4, Figure 4 is an optional flow chart after deterministic scheduling optimization provided by an embodiment of the present application, in which six blockchain transactions are executed in parallel. The six blockchain transactions are: Tx0, Tx1, Tx2, Tx3, Tx4 and Tx5, and the execution time of Tx0 is 3 seconds, the execution time of Tx1 is 1 second, the execution time of Tx2 is 2 seconds, the execution time of Tx3 is 4 seconds, the execution time of Tx4 is 2 seconds, and the execution time of Tx5 is 4 seconds. The preset duration is 1 second. Based on the resources required to execute each blockchain transaction, the weight of Tx0 is determined to be 30, the weight of Tx1 is 10, the weight of Tx2 is 20, the weight of Tx3 is 40, the weight of Tx4 is 20, and the weight of Tx5 is 40.

[0105] In the first round, when all blockchain transactions are executed, conflict detection is performed on each blockchain transaction. For example, Tx0 is used as the target transaction, and other blockchain transactions that have been executed and not added to the transaction snapshot are used as the first reference transactions. The first reference transactions include: Tx1, Tx2, Tx3, Tx4 and Tx5. Then, the first conflict relationship between the target transaction and each first reference transaction is determined. Since the read-write sets of Tx0, Tx2 and Tx5 all contain key k1, while the read-write sets of Tx1, Tx3 and Tx4 do not contain key k1, after conflict detection, it can be determined that there is a conflict between Tx0 and Tx2, and there is a conflict between Tx0 and Tx5. Then, according to the size relationship between the weight of Tx0 and the weight of Tx2, Tx0 is scheduled, and according to the weight of Tx0 and Tx5, the conflict relationship between Tx0 and Tx5 is determined. 5, Tx0 is scheduled. Since the weight of Tx0 is less than the weight of Tx5, Tx0 is re-executed. Similarly, it can be determined that Tx2 is re-executed and Tx5 is added to the transaction snapshot; then Tx1 is used as the target transaction. The read-write sets of Tx1 and Tx3 both contain key k2. After conflict detection, it can be determined that there is a conflict between Tx1 and Tx3. Then, according to the size relationship between the weight of Tx1 and the weight of Tx3, Tx1 is scheduled. Since the weight of Tx1 is less than the weight of Tx3, Tx1 is re-executed. Similarly, Tx3 is added to the transaction snapshot; then Tx4 is used as the target transaction. The read-write set of Tx4 contains key k3. After conflict detection, it can be determined that Tx4 does not conflict with other blockchain transactions, and T4 is added to the transaction snapshot.

[0106] In the second round, the re-executed Tx0, Tx1, and Tx2 are scheduled to add Tx0 and Tx1 to the transaction snapshot and re-execute Tx2.

[0107] In the third round, the re-executed Tx2 is scheduled to confirm that Tx2 is added to the transaction snapshot. After the third round, all blockchain transactions are added to the transaction snapshot, completing the scheduling of the target transaction.

[0108] It can be seen that compared with the total execution time of 12 seconds before deterministic scheduling optimization, the total execution time after deterministic scheduling optimization is 9 seconds, a reduction of three seconds, and the execution efficiency is improved by 25%. The execution efficiency is significantly improved. At the same time, it is possible to retain blockchain transactions with higher resource consumption and re-execute blockchain transactions with lower resource consumption, avoiding resource waste and improving the performance of the blockchain network.

[0109] In addition, based on the scheduling results of the target transaction, a directed acyclic graph (DAG) is constructed. The DAG and various blockchain transactions can be packaged to obtain a proposal block carrying the DAG. The proposal block is then sent to the verification nodes in the blockchain network. The verification nodes can execute the blockchain transactions in the proposal block based on the DAG.

[0110] In one possible implementation, the target transaction is obtained whenever a blockchain transaction is executed. The first reference transaction is not added to the transaction snapshot. The target transaction is scheduled based on the relationship between the first weight and the sum of the first weights. Specifically, the schedule may be:

[0111] When the first weight is greater than the sum of the first weights, wait for a preset time, and after the waiting time reaches the preset time, schedule the target transaction;

[0112] Alternatively, when the first weight is less than the sum of the first weights, re-execute the target transaction;

[0113] Alternatively, when the first weight is equal to the sum of the first weights, wait for a preset time period, and after the waiting time period reaches the preset time period, schedule the target transaction or re-execute the target transaction.

[0114] Among them, the target transaction can be scheduled in a non-deterministic scheduling manner. In the non-deterministic scheduling, the execution result of each blockchain transaction is uncertain. The non-deterministic scheduling uses the specific execution time of the blockchain transaction as the judgment criterion. In the non-deterministic scheduling, the time point of conflict detection is configured as follows: whenever a blockchain transaction is executed, a conflict detection is performed on the blockchain transaction to determine the conflict relationship between the blockchain transaction and the remaining completed blockchain transactions. The result of the conflict detection may be that there is no conflict between the blockchain transaction and the remaining completed blockchain transactions, or the result of the conflict detection may be that there is a conflict between the blockchain transaction and the remaining completed blockchain transactions; when the result of the conflict detection indicates that there is no conflict between the blockchain transaction and the remaining completed blockchain transactions, it means that the blockchain transaction can be executed in parallel with the remaining completed blockchain transactions; when the result of the conflict detection indicates that there is a conflict between the blockchain transaction and the remaining completed blockchain transactions, it means that the blockchain transaction needs to be executed serially with the conflicting blockchain transactions.

[0115] For conflicting blockchain transactions, only one of them is retained and added to the transaction snapshot, and the remaining transactions are re-executed. Since the execution time of different blockchain transactions can be different, the conflict detection time points corresponding to different blockchain transactions can also be different in non-deterministic scheduling. The target transaction is obtained whenever one of the blockchain transactions is executed.

[0116] Currently, when a non-deterministic scheduling method is used to schedule multiple conflicting blockchain transactions, the blockchain transaction that is executed first is added to the transaction snapshot in the order of the time when the blockchain transactions are executed, and the remaining blockchain transactions are re-executed. This may cause the blockchain transactions that consume more resources to be re-executed, resulting in resource waste and reduced blockchain network performance.

[0117] Based on this, the scheduling method provided in the embodiment of the present application can optimize non-deterministic scheduling. Non-deterministic scheduling can be applicable to pessimistic scenarios. In pessimistic scenarios, a blockchain transaction is allowed to depend on multiple blockchain transactions at the same time. When the target transaction is executed, the first scheduling phase is entered. In the first scheduling phase: when the target transaction is executed, the conflicting target transaction and the first reference transaction are scheduled. The first weight of the target transaction and the second weight of the first reference transaction are first obtained. The number of first reference transactions can be one or more. Therefore, different scheduling situations can be distinguished according to the number of first reference transactions, as follows:

[0118] Scheduling situation 11: The number of first reference transactions is one, and the sum of the first weights is the second weight of the first reference transaction. Since the first weight and the second weight are both determined based on the resource consumption parameter, scheduling the target transaction according to the size relationship between the first weight and the sum of the first weights is equivalent to scheduling the target transaction according to the resource consumption parameter. The resource consumption parameter is used to indicate the resources required to execute the blockchain transaction. The first weight is used to indicate the resources required to execute the target transaction, and the second weight is used to indicate the resources required to execute the first reference transaction. When the resources required to execute the target transaction are small, the first weight is small. Conversely, when the resources required to execute the target transaction are large, the first weight is large. Similarly, when the resources required to execute the first reference transaction are small, the sum of the first weights is small. Conversely, when the resources required to execute the first reference transaction are large, the sum of the first weights is large.

[0119] Scheduling Case 12: There are multiple first reference transactions, and when the target transaction is executed, no two first reference transactions conflict with each other. All first reference transactions can be used as the first reference set. The second weights of all first reference transactions need to be summed, which is equivalent to obtaining the sum of the first weights corresponding to the first reference set. Since the first weight and the second weight are both determined based on the resource consumption parameter, scheduling the target transactions based on the relationship between the first weight and the sum of the first weights is equivalent to scheduling the target transactions based on the resource consumption parameter. The resource consumption parameter is used to indicate the resources required to execute the blockchain transaction. The first weight indicates the resources required to execute the target transaction, and the second weight indicates the resources required to execute the first reference transaction. When the target transaction requires less resources, the first weight is smaller. Conversely, when the target transaction requires more resources, the first weight is larger. Similarly, when the resources required to execute all first reference transactions in the first reference set are less, the sum of the first weights is smaller. Conversely, when the resources required to execute all first reference transactions in the first reference set are more, the sum of the first weights is larger.

[0120] Exemplarily, the first reference transaction 1, the first reference transaction 2, and the first reference transaction 3 are all used to process the state data corresponding to the same key. The execution time of the first reference transaction 1 is 1 second, the execution time of the first reference transaction 2 is 2 seconds, and the execution time of the first reference transaction 3 is 3 seconds. The first reference transaction 1 and the first reference transaction 2 are executed in parallel. When one second is reached, the first reference transaction 1 is completed. The first reference transaction 1 is used as the target transaction. Through conflict detection, it is determined that the first reference transaction 1 does not conflict with the remaining blockchain transactions. The first reference transaction 1 is retained, and at this time, the first reference transaction 3 is started to be executed. When two seconds are reached, the first reference transaction 2 is completed. The first reference transaction 2 is used as the target transaction. Through conflict detection, it is determined that the first reference transaction 2 conflicts with the first reference transaction 1. Then, the weight relationship between the first reference transaction 2 and the first reference transaction 1 is determined. Assuming that the weight of the first reference transaction 2 is larger, the first reference transaction 1 is re-executed and the first reference transaction 2 is retained. When three seconds are reached, the first reference transaction 1 is executed again. The first reference transaction 1 is used as the target transaction. Through conflict detection, it is determined that the first reference transaction 1 does not conflict with the remaining blockchain transactions, and the first reference transaction 1 is retained. When four seconds have passed, the first reference transaction 3 is executed. The first reference transaction 3 is used as the target transaction. Through conflict detection, it is determined that the first reference transaction 3 conflicts with all the remaining blockchain transactions. Since there is no conflict between the first reference transaction 1 and the first reference transaction 2 when the first reference transaction 3 is executed, the first reference transaction 1 and the first reference transaction 2 are used as the first reference set. Assuming that the weight of the first reference transaction 1 is 100, the weight of the first reference transaction 2 is 200, and the weight of the first reference transaction 3 is 250, by summing the weights of the first reference transaction 1 and the first reference transaction 2, the first weight sum of the first reference set is 300. Comparing the relationship between the first weight and the first weight sum, since 250<300, the first reference transaction 3 is re-executed, and the first reference transaction 1 and the first reference transaction 2 are retained. This achieves the retention of blockchain transactions with more resource consumption and the re-execution of blockchain transactions with less resource consumption, thereby avoiding resource waste and improving the performance of the blockchain network.

[0121] Based on this, since a blockchain transaction is allowed to depend on multiple blockchain transactions at the same time in a pessimistic scenario, when the target transaction is executed, some blockchain transactions that the target transaction depends on may not have been completed. By setting a preset time and waiting, it is possible to wait for the execution of each blockchain transaction that the target transaction depends on, so that the scheduling result of the target transaction is more accurate, thereby improving the certainty of the execution result. Specifically, if there is no need to re-execute the target transaction in the first scheduling link, the second scheduling link is entered. In the second scheduling link: after the preset time is reached, the target transaction is scheduled, so that when the target transaction is scheduled, the blockchain transaction with more resource consumption can be retained and the blockchain transaction with less resource consumption can be re-executed, thereby avoiding resource waste and improving the performance of the blockchain network.

[0122] It should be noted that different blockchain transactions can correspond to different preset durations. However, it is necessary to ensure that the preset duration is set according to the same delay rules in each node. For example, the corresponding preset duration can be set according to the contract, and all nodes are required to have the same preset duration for the same contract.

[0123] In one possible implementation, determining a first conflict relationship between a target transaction and at least one first reference transaction may specifically include determining a second conflict relationship between the target transaction and a second reference transaction, where the second reference transaction is a blockchain transaction other than the target transaction that has been currently executed and added to the transaction snapshot; and when the second conflict relationship indicates that there is no conflict between the target transaction and the second reference transaction, determining a first conflict relationship between the target transaction and the at least one first reference transaction.

[0124] The second conflict relationship is used to indicate whether there is a conflict between the target transaction and the second reference transaction.

[0125] Based on this, in the first scheduling link, it is necessary to first determine whether there is a conflict between the target transaction and the second reference transaction, which is equivalent to determining whether there is a conflict between the target transaction and the blockchain transaction currently added to the transaction snapshot. If there is a conflict, the target transaction is re-executed. There is no need to subsequently determine the size relationship between the first weight and the sum of the first weights, which can improve the scheduling efficiency of blockchain transactions and thus improve the execution efficiency of blockchain transactions.

[0126] Specifically, referring to Figure 5, Figure 5 is an optional flow chart of the first scheduling link provided by an embodiment of the present application, which needs to be judged three times in sequence. In the first judgment, the second conflict relationship is used to determine whether there is a conflict between the target transaction and the second reference transaction. When the judgment is yes, the target transaction is re-executed, otherwise a second judgment is made. In the second judgment, the first conflict relationship is used to determine whether there is a conflict between the target transaction and the first reference transaction. When the judgment is no, the target transaction is re-executed. If the judgment is yes, a third judgment is made. In the third judgment, it is determined whether the first weight is greater than the sum of the first weights. When the first weight is greater than the sum of the first weights, the second scheduling link is entered, and a preset time is waited in the second scheduling link. When the first weight is less than the sum of the first weights, the target transaction is re-executed. When the first weight is equal to the sum of the first weights, you can choose to enter the second scheduling link or choose to re-execute the target transaction. The figure shows the option of re-executing the target transaction.

[0127] Among them, when the blockchain transaction starts to execute, the current transaction quantity in the transaction snapshot is used as the first reference quantity, wherein the current transaction quantity in the transaction snapshot refers to the number of blockchain transactions contained in the transaction snapshot. After the corresponding transaction execution time, the blockchain transaction is completed. When the blockchain transaction is completed, the blockchain transaction is used as the target transaction, and the current transaction quantity in the transaction snapshot is used as the second reference quantity. The first reference quantity and the second reference quantity are compared. When the first reference quantity is the same as the second reference quantity, it means that the second reference transaction does not exist for the target transaction; otherwise, the second reference transaction exists for the target transaction.

[0128] In contrast, in another possible implementation, in the first scheduling link, it is not necessary to determine whether there is a conflict between the target transaction and the second reference transaction. Compared with the case where it is necessary to determine whether there is a conflict between the target transaction and the second reference transaction, the scheduling process will consume a little more time, but this time is much less than the time consumed by re-executing the blockchain transaction that consumes more resources. Therefore, when scheduling the target transaction, it is possible to retain the blockchain transaction that consumes more resources and re-execute the blockchain transaction that consumes less resources, thereby avoiding resource waste and improving the performance of the blockchain network.

[0129] In one possible implementation, the target transaction is scheduled after the waiting time reaches a preset time. Specifically, after the waiting time reaches the preset time, a third conflict relationship between the target transaction and at least one third reference transaction is determined, wherein the third reference transaction is a blockchain transaction other than the target transaction that has been currently executed and has not been added to the transaction snapshot; when the third conflict relationship indicates that there is a conflict between the target transaction and the third reference transaction, a third weight of the third reference transaction is obtained, wherein the third weight is determined based on a resource consumption parameter when executing the third reference transaction; the sum of the third weights is calculated as the second weight sum, and the target transaction is scheduled according to the size relationship between the first weight and the second weight sum.

[0130] Among them, the third conflict relationship is used to indicate whether there is a conflict between the target transaction and the third reference transaction; the size relationship between the first weight and the sum of the second weights means that the first weight is greater than the sum of the second weights, or the first weight is less than the sum of the second weights, or the first weight is equal to the sum of the second weights.

[0131] Based on this, when it is determined in the first scheduling phase that the preset waiting time is waited, it is determined to enter the second scheduling phase. After waiting for the preset waiting time in the second scheduling phase, the conflicting target transaction and the third reference transaction are scheduled after the preset waiting time is reached. The first weight of the target transaction and the third weight of the third reference transaction are first obtained. The number of the third reference transactions can be one or more. Therefore, different scheduling situations can be distinguished according to the number of the third reference transactions, as follows:

[0132] Scheduling situation 13: The number of third reference transactions is one, and the sum of the second weights is the third weight of the third reference transaction. Since the first weight and the third weight are both determined based on the resource consumption parameter, scheduling the target transaction according to the size relationship between the first weight and the sum of the second weights is equivalent to scheduling the target transaction according to the resource consumption parameter. The resource consumption parameter is used to indicate the resources required to execute the blockchain transaction. The first weight is used to indicate the resources required to execute the target transaction, and the third weight is used to indicate the resources required to execute the third reference transaction. When the resources required to execute the target transaction are small, the first weight is small. Conversely, when the resources required to execute the target transaction are large, the first weight is large. Similarly, when the resources required to execute the third reference transaction are small, the sum of the second weights is small. Conversely, when the resources required to execute the third reference transaction are large, the sum of the second weights is large.

[0133] Scheduling Case 14: There are multiple third reference transactions, and when the target transaction is executed, there is no conflict between any two third reference transactions. All third reference transactions can be used as the second reference set. Similar to Scheduling Case 12, the third weights of all third reference transactions need to be summed, which is equivalent to obtaining the sum of the second weights corresponding to the second reference set. Since the first weight and the third weight are both determined based on the resource consumption parameter, scheduling the target transaction based on the relationship between the first weight and the sum of the second weights is equivalent to scheduling the target transaction based on the resource consumption parameter. The resource consumption parameter is used to indicate the resources required to execute the blockchain transaction. The first weight indicates the resources required to execute the target transaction, and the third weight indicates the resources required to execute the third reference transaction. When the target transaction requires less resources, the first weight is smaller. Conversely, when the target transaction requires more resources, the first weight is larger. Similarly, when the execution of all third reference transactions in the second reference set requires less resources, the sum of the second weights is smaller. Conversely, when the execution of all third reference transactions in the second reference set requires more resources, the sum of the second weights is larger.

[0134] In addition, relative to scheduling situation 14, there is also scheduling situation 15.

[0135] Scheduling situation 15: There are multiple third reference transactions, and when the target transaction is executed, there are conflicts between the third reference transactions. In the transaction set consisting of the target transaction and the third reference transactions, the blockchain transaction with the largest weight is retained, and the blockchain transaction with the smallest weight is re-executed.

[0136] In one possible implementation, the target transaction is scheduled based on the relationship between the first weight and the sum of the second weights, specifically:

[0137] When the first weight is greater than the sum of the second weights, the target transaction is added to the transaction snapshot;

[0138] Alternatively, when the first weight is less than the sum of the second weights, re-execute the target transaction;

[0139] Alternatively, when the first weight is equal to the sum of the second weights, the target transaction is added to the transaction snapshot or the target transaction is re-executed.

[0140] Based on this, for the three comparison situations of the first weight and the sum of the second weight, when the first weight is greater than the sum of the second weight, the target transaction is retained and added to the transaction snapshot; when the first weight is less than the sum of the second weight, the target transaction is re-executed; when the first weight is equal to the sum of the second weight, the target transaction can be added to the transaction snapshot or re-executed. In this way, when scheduling the target transaction, the blockchain transaction with more resource consumption can be retained and the blockchain transaction with less resource consumption can be re-executed, thereby avoiding resource waste and improving the performance of the blockchain network.

[0141] In one possible implementation, determining a third conflict relationship between the target transaction and at least one third reference transaction may specifically include: determining a fourth conflict relationship between the target transaction and a fourth reference transaction, where the fourth reference transaction is a blockchain transaction other than the target transaction that has been currently executed and added to the transaction snapshot; and when the fourth conflict relationship indicates that there is no conflict between the target transaction and the fourth reference transaction, determining a third conflict relationship between the target transaction and the at least one third reference transaction.

[0142] The fourth conflict relationship is used to indicate whether there is a conflict between the target transaction and the fourth reference transaction.

[0143] Based on this, in the second scheduling link, it is necessary to first determine whether there is a conflict between the target transaction and the fourth reference transaction, which is equivalent to determining whether there is a conflict between the target transaction and the blockchain transaction currently added to the transaction snapshot. If there is a conflict, the target transaction is re-executed. There is no need to subsequently determine the size relationship between the first weight and the sum of the second weights, which can improve the scheduling efficiency of blockchain transactions and thus improve the execution efficiency of blockchain transactions.

[0144] Specifically, referring to Figure 6, Figure 6 is an optional flow chart of the second scheduling link provided by an embodiment of the present application, which needs to be judged three times in sequence. In the first judgment, the fourth conflict relationship is used to determine whether there is a conflict between the target transaction and the fourth reference transaction. When the judgment is yes, the target transaction is re-executed, otherwise a second judgment is performed. In the second judgment, the third conflict relationship is used to determine whether there is a conflict between the target transaction and the third reference transaction. When the judgment is no, the target transaction is re-executed, otherwise a third judgment is performed. In the third judgment, it is determined whether the first weight is greater than the sum of the second weights. When the first weight is greater than the sum of the second weights, the target transaction is added to the transaction snapshot. When the first weight is less than the sum of the second weights, the target transaction is re-executed. When the first weight is equal to the sum of the second weights, you can choose to add the target transaction to the transaction snapshot or choose to re-execute the target transaction. The figure shows the selection of re-executing the target transaction.

[0145] Among them, when the target transaction is executed, the current transaction quantity in the transaction snapshot is used as the second reference quantity. After the corresponding preset time period, the target transaction reaches the preset time period. When the target transaction reaches the preset time period, the current transaction quantity in the transaction snapshot is used as the third reference quantity. The second reference quantity and the third reference quantity are compared. When the second reference quantity is the same as the third reference quantity, it means that the fourth reference transaction does not exist for the target transaction; otherwise, the blockchain transaction exists for the fourth reference transaction.

[0146] In contrast, in another possible implementation, in the second scheduling link, it is not necessary to determine whether there is a conflict between the target transaction and the fourth reference transaction. Compared with the need to determine whether there is a conflict between the target transaction and the fourth reference transaction, the scheduling process will consume a little more time, but this time is much less than the time consumed by re-executing the blockchain transaction that consumes more resources. Therefore, when scheduling the target transaction, it is possible to retain the blockchain transaction that consumes more resources and re-execute the blockchain transaction that consumes less resources, thereby avoiding resource waste and improving the performance of the blockchain network.

[0147] In one possible implementation, the blockchain transaction scheduling method further includes:

[0148] When a blockchain transaction that has not been added to the transaction snapshot is re-executed, the blockchain transaction that has been re-executed and not added to the transaction snapshot will be used as the target transaction;

[0149] The target transaction is rescheduled until all blockchain transactions are added to the transaction snapshot.

[0150] Among them, the target transaction can be scheduled by non-deterministic scheduling. In non-deterministic scheduling, the execution result of each blockchain transaction is uncertain. Non-deterministic scheduling can be applied to pessimistic scenarios. In pessimistic scenarios, a blockchain transaction is allowed to depend on multiple blockchain transactions at the same time. Non-deterministic scheduling uses the specific execution time of the blockchain transaction as the judgment standard. In non-deterministic scheduling, the time point of conflict detection is configured as follows: whenever a blockchain transaction is executed, a conflict detection is performed on the blockchain transaction to determine the conflict relationship between the blockchain transaction and the other completed blockchain transactions. Therefore, when the blockchain transaction is re-executed, it is necessary to re-detect the conflict on the blockchain transaction to determine the conflict relationship between the blockchain transaction and the other completed blockchain transactions. When all blockchain transactions are added to the transaction snapshot, it means that the scheduling of the target transaction has been completed.

[0151] Specifically, referring to Figure 7, Figure 7 is an optional flow chart before non-deterministic scheduling optimization provided by an embodiment of the present application. In the order of the time when the blockchain transactions are executed, the blockchain transactions that are executed first are added to the transaction snapshot, and the remaining blockchain transactions are re-executed. This may cause the blockchain transactions that consume a lot of resources to be re-executed, thereby resulting in resource waste and reducing the performance of the blockchain network.

[0152] In addition, referring to Figure 8, Figure 8 is an optional flow chart after non-deterministic scheduling optimization provided by an embodiment of the present application. In non-deterministic scheduling, whenever a blockchain transaction is executed, a conflict detection is performed on the blockchain transaction to determine the conflict relationship between the blockchain transaction and the remaining executed blockchain transactions. In addition, since a blockchain transaction is allowed to depend on multiple blockchain transactions at the same time in a pessimistic scenario, when the target transaction is executed, some blockchain transactions that the target transaction depends on may not have been completed. By setting a preset time and waiting, it is possible to wait for the completion of the execution of each blockchain transaction that the target transaction depends on, so that the scheduling result of the target transaction is more accurate, thereby improving the certainty of the execution result.

[0153] Specifically, six blockchain transactions are executed in parallel, and the six blockchain transactions are: Tx0, Tx1, Tx2, Tx3, Tx4 and Tx5. The execution time of Tx0 is 3 seconds, the execution time of Tx1 is 1 second, the execution time of Tx2 is 2 seconds, the execution time of Tx3 is 4 seconds, the execution time of Tx4 is 2 seconds, and the execution time of Tx5 is 4 seconds. The preset duration is 1 second. Based on the resources required to execute each blockchain transaction, it can be determined that the weight of Tx0 is 30, the weight of Tx1 is 10, the weight of Tx2 is 20, the weight of Tx3 is 40, the weight of Tx4 is 20, and the weight of Tx5 is 40.

[0154] When one second is reached, Tx1 is executed and taken as the target transaction. In the first scheduling phase, conflict detection is performed to determine that Tx1 does not conflict with other blockchain transactions. Tx1 then enters the second scheduling phase and waits for a preset time in the second scheduling phase.

[0155] When two seconds have passed, Tx1 reaches the preset duration. Conflict detection is performed in the second scheduling phase to determine that Tx1 does not conflict with other blockchain transactions, and Tx1 is added to the transaction snapshot. At the same time, Tx2 is executed, and Tx2 is used as the target transaction. Conflict detection is performed in the first scheduling phase to determine that Tx2 does not conflict with other blockchain transactions. Tx2 enters the second scheduling phase, where Tx2 waits for the preset duration. At the same time, Tx4 is executed, and Tx4 is used as the target transaction. Conflict detection is performed in the first scheduling phase to determine that Tx4 does not conflict with other blockchain transactions. Tx4 enters the second scheduling phase, where Tx4 waits for the preset duration.

[0156] When three seconds have passed, Tx0 is executed and Tx0 is used as the target transaction. In the first scheduling phase, conflict detection is passed. Since the read and write sets of Tx0 and Tx2 both contain key k1, and Tx2 is executed and not added to the transaction snapshot, Tx2 is determined to be the first reference transaction that conflicts with Tx1. Based on the size relationship between the weight of Tx0 and the weight of Tx2, Tx0 is scheduled. Since the weight of Tx0 is greater than that of Tx2, Tx0 enters the second scheduling phase. In the second scheduling phase, Tx0 Wait for the preset time. At the same time, Tx2 reaches the preset time. In the second scheduling phase, conflict detection is performed and it is determined that Tx0 is the third reference transaction that conflicts with Tx2. According to the relationship between the weight of Tx2 and the weight of Tx0, Tx2 is scheduled. Since the weight of Tx2 is less than the weight of Tx0, Tx2 is re-executed. At the same time, Tx4 reaches the preset time. In the second scheduling phase, conflict detection is performed and it is determined that Tx4 does not conflict with other blockchain transactions. Tx4 is added to the transaction snapshot.

[0157] When it reaches four seconds, Tx0 reaches the preset duration and passes the conflict detection in the second scheduling link. Since the read and write sets of Tx0 and Tx5 both contain key k1, and Tx5 is executed and not added to the transaction snapshot, it is determined that Tx5 is the third reference transaction that conflicts with Tx0. According to the size relationship between the weight of Tx0 and the weight of Tx5, Tx0 is scheduled. Since the weight of Tx0 is less than the weight of Tx5, Tx0 is re-executed; at the same time, Tx3 is executed and Tx3 is used as the target transaction. It passes the conflict detection in the first scheduling link. The read / write sets of Tx3 and Tx1 both contain key k2, and Tx1 has been added to the transaction snapshot. It is determined that Tx1 is the second reference transaction that conflicts with Tx3, and Tx3 is re-executed. At the same time, Tx5 is executed. Tx5 is used as the target transaction. In the first scheduling phase, conflict detection is performed, and it is determined that Tx0 is the first reference transaction that conflicts with Tx5. Based on the size relationship between the weight of Tx5 and the weight of Tx0, Tx5 is scheduled. Since the weight of Tx5 is greater than the weight of Tx0, Tx5 waits for a preset time in the second scheduling phase.

[0158] When five seconds are reached, Tx2 is re-executed and Tx2 is used as the target transaction. In the first scheduling link, conflict detection is performed to determine that Tx5 is the first reference transaction that conflicts with Tx2. Based on the size relationship between the weight of Tx2 and the weight of Tx5, Tx2 is scheduled. Since the weight of Tx2 is less than the weight of Tx5, Tx2 is re-executed. At the same time, Tx5 reaches the preset duration. In the second scheduling link, conflict detection is performed to determine that Tx2 is the third reference transaction that conflicts with Tx5. Based on the size relationship between the weight of Tx5 and the weight of Tx2, Tx5 is scheduled. Since the weight of Tx5 is greater than the weight of Tx2, Tx5 is added to the transaction snapshot.

[0159] When seven seconds are reached, Tx0 is re-executed and Tx0 is used as the target transaction. In the first scheduling link, conflict detection is performed to determine that Tx2 is the first reference transaction that conflicts with Tx0. According to the size relationship between the weight of Tx0 and the weight of Tx2, Tx0 is scheduled. Since the weight of Tx0 is greater than the weight of Tx2, Tx0 enters the second scheduling link, and Tx0 waits for a preset time in the second scheduling link; at the same time, Tx2 is re-executed and Tx2 is used as the target transaction. In the first scheduling link, conflict detection is performed to determine that Tx0 is the first reference transaction that conflicts with Tx2. According to the size relationship between the weight of Tx2 and the weight of Tx0, Tx2 is scheduled. Since the weight of Tx2 is less than the weight of Tx0, Tx2 is re-executed.

[0160] When eight seconds have passed, Tx0 reaches the preset duration. Conflict detection is performed in the second scheduling phase to determine that Tx0 does not conflict with other blockchain transactions, and Tx0 is added to the transaction snapshot. At the same time, Tx3 is executed, and Tx3 is used as the target transaction. Conflict detection is performed in the first scheduling phase to determine that Tx3 does not conflict with other blockchain transactions. Tx3 enters the second scheduling phase, where it waits for the preset duration.

[0161] When nine seconds are reached, Tx2 is executed and taken as the target transaction. In the first scheduling link, conflict detection is performed to determine that Tx2 does not conflict with other blockchain transactions. Tx2 enters the second scheduling link, where Tx2 waits for a preset time. At the same time, Tx3 reaches the preset time. In the second scheduling link, conflict detection is performed to determine that Tx3 does not conflict with other blockchain transactions. Tx3 is added to the transaction snapshot. When ten seconds are reached, Tx2 reaches the preset time. In the second scheduling link, conflict detection is performed to determine that Tx2 does not conflict with other blockchain transactions. Tx2 is added to the transaction snapshot.

[0162] It can be seen that compared with the total execution time of 12 seconds before non-deterministic scheduling optimization, the total execution time after non-deterministic scheduling optimization for pessimistic scenarios is 10 seconds, a reduction of two seconds, and the execution efficiency is improved by nearly 17%. The execution efficiency is significantly improved, and blockchain transactions with higher resource consumption are retained and blockchain transactions with lower resource consumption are re-executed, avoiding resource waste and improving the performance of the blockchain network.

[0163] In addition, based on the scheduling results of the target transaction, a transaction directed acyclic graph is constructed, and the transaction directed acyclic graph and each blockchain transaction are packaged to obtain a proposal block carrying the directed acyclic graph. The proposal block is then sent to the verification node in the blockchain network. The verification node can execute the blockchain transactions in the proposal block based on the transaction directed acyclic graph.

[0164] In one possible implementation, the extension time can be further optimized. For example, the preset duration can be optimized by a block-by-block optimization method. The block with the highest block height in the blockchain is used as the initial block, and an initial preset duration is set for the initial block. The corresponding blockchain transactions are scheduled according to the initial preset duration, and then the blockchain transactions are executed, and the total execution time is determined. The preset duration is optimized according to the total execution time. In the next block of the initial block, the corresponding blockchain transactions are scheduled according to the optimized preset duration, and then the blockchain transactions are executed. The preset duration can be optimized again according to the total execution time. Therefore, the preset duration can be continuously optimized to obtain a better preset duration, which can effectively improve the execution efficiency. Among them, optimizing the preset duration can be to extend the preset duration, or it can be to shorten the preset duration, depending on the actual situation.

[0165] In addition, the preset duration can also be optimized through simulation training methods. The block with the highest block height in the blockchain is used as the initial block, and a preset duration is preset for the initial block. Then, a batch of blockchain transactions are selected in the transaction pool as sample transactions. Based on the initial block, the corresponding sample transactions are scheduled according to the initial preset duration, and then the sample transactions are executed and the total execution time is determined. Then, based on the total execution time, an optimized preset duration is determined. Then, based on the initial block again, the corresponding sample transactions are scheduled according to the optimized preset duration, and then the sample transactions are executed and the total execution time is determined. The preset duration can be optimized again through the total execution time. Therefore, the preset duration can be continuously optimized to obtain a better preset duration, which can effectively improve the execution efficiency.

[0166] In one possible implementation, the target transaction is obtained whenever a blockchain transaction is executed. The first reference transaction has been added to the transaction snapshot. The target transaction is scheduled based on the relationship between the first weight and the sum of the first weights. Specifically, the schedule may be:

[0167] When the first weight is greater than the sum of the first weights, replacing the first reference transaction in the transaction snapshot with the target transaction;

[0168] Alternatively, when the first weight is less than the sum of the first weights, re-execute the target transaction;

[0169] Alternatively, when the first weight is equal to the sum of the first weights, the first reference transaction in the transaction snapshot is replaced with the target transaction or the target transaction is re-executed.

[0170] Based on this, the scheduling method provided in the embodiment of the present application can also optimize the non-deterministic scheduling of optimistic scenarios. In the optimistic scenario, the number of blockchain transactions that a blockchain transaction depends on is less than or equal to one. When conflicting blockchain transactions are executed serially, each blockchain transaction only depends on the previous blockchain transaction and will not depend on multiple blockchain transactions at the same time. Exchanging the execution order of blockchain transactions will not affect the final execution result. Therefore, conflicting transactions are allowed to be replaced in the optimistic scenario. Specifically, when the blockchain transaction is executed, if there is no conflicting transaction that conflicts with the blockchain transaction in the transaction snapshot, the blockchain transaction can be temporarily added to the transaction snapshot, or if there is a conflicting transaction that conflicts with the blockchain transaction in the transaction snapshot, if replacement is required, the blockchain transaction can be used to replace the conflicting transaction in the transaction snapshot and the conflicting transaction can be re-executed. Therefore, in the optimistic scenario, the first reference transaction is the blockchain transaction that has been added to the transaction snapshot.

[0171] When the target transaction is completed, the conflicting target transaction and the first reference transaction are scheduled. First, the first weight of the target transaction and the second weight of the first reference transaction are obtained. The number of first reference transactions can be one or more. Therefore, different scheduling situations can be distinguished according to the number of first reference transactions, as follows:

[0172] Scheduling situation 21: The number of first reference transactions is one, and the sum of the first weights is the second weight of the first reference transaction. Since the first weight and the second weight are both determined based on the resource consumption parameter, scheduling the target transaction according to the size relationship between the first weight and the sum of the first weights is equivalent to scheduling the target transaction according to the resource consumption parameter. The resource consumption parameter is used to indicate the resources required to execute the blockchain transaction. The first weight is used to indicate the resources required to execute the target transaction, and the second weight is used to indicate the resources required to execute the first reference transaction. When the resources required to execute the target transaction are small, the first weight is small. Conversely, when the resources required to execute the target transaction are large, the first weight is large. Similarly, when the resources required to execute the first reference transaction are small, the sum of the first weights is small. Conversely, when the resources required to execute the first reference transaction are large, the sum of the first weights is large.

[0173] Specifically, when multiple blockchain transactions for processing state data corresponding to the same key are executed in parallel, and the completion time points of the respective blockchain transactions do not overlap, the first completed blockchain transaction is temporarily added to the transaction snapshot. The subsequent completed blockchain transactions are weighted and compared with the blockchain transactions in the transaction snapshot. The weight comparison result is used to determine whether they need to be replaced. If the completion time points of some blockchain transactions overlap, the blockchain transaction that performs conflict detection first will not treat the blockchain transaction that performs conflict detection later as a conflicting transaction. For example, if two blockchain transactions are executed in parallel and the blockchain transactions are completed at the same time, one of the blockchain transactions is used as the target transaction and conflict detection is performed on the target transaction. Since the other blockchain transaction is not treated as a conflicting transaction, the blockchain transaction that performs conflict detection first is directly temporarily added to the transaction snapshot, which is equivalent to the number of first reference transactions being zero. Then, the other blockchain transaction is used as the target transaction and conflict detection is performed on the target transaction. The other blockchain transaction is weighted and compared with the blockchain transactions in the transaction snapshot. The weight comparison result is used to determine whether it needs to be replaced, which is equivalent to the number of first reference transactions being one. Similarly, if the completion time points of three or more blockchain transactions overlap, only the blockchain transaction that has been added to the transaction snapshot will be used as the first reference transaction.

[0174] In addition, based on the scheduling results of the target transaction, a transaction directed acyclic graph is constructed, and the transaction directed acyclic graph and each blockchain transaction are packaged to obtain a proposal block carrying the directed acyclic graph. The proposal block is then sent to the verification node in the blockchain network. The verification node can execute the blockchain transactions in the proposal block based on the transaction directed acyclic graph.

[0175] Scheduling situation 22: There are multiple first reference transactions, and all of them have been added to the transaction snapshot. All of the first reference transactions can be used as the third reference set. The second weights of all of the first reference transactions need to be summed, which is equivalent to obtaining the sum of the first weights of the third reference set. Since the first weight and the second weight are both determined based on the resource consumption parameter, scheduling the target transaction based on the relationship between the first weight and the sum of the first weights is equivalent to scheduling the target transaction based on the resource consumption parameter. The resource consumption parameter is used to indicate the resources required to execute the blockchain transaction. The first weight is used to indicate the resources required to execute the target transaction, and the second weight is used to indicate the resources required to execute the first reference transaction. When the resources required to execute the target transaction are small, the first weight is small. Conversely, when the resources required to execute the target transaction are large, the first weight is large. Similarly, when the resources required to execute all of the first reference transactions in the third reference set are small, the sum of the first weights is small. Conversely, when the resources required to execute all of the first reference transactions in the third reference set are large, the sum of the first weights is large.

[0176] Due to the existence of system scheduling, system scheduling may result in the situation that not all blockchain transactions are started completely in parallel. System scheduling refers to the scheduling of the program by the operating system. In this case, when the blockchain transaction executed later is completed, all the first reference transactions that were executed first and completed can be used as the objects of weight comparison, and the sum of the first weights of all the second weights is calculated. By comparing the size between the first weight and the sum of the first weights, it can be effectively determined whether the resource consumption of executing the target transaction is greater than the resource consumption corresponding to executing all the first reference transactions that were executed first and completed. In this way, the blockchain transaction with more resource consumption is retained, and the blockchain transaction with less resource consumption is re-executed to avoid resource waste and improve the performance of the blockchain network.

[0177] Specifically, referring to Figure 9, Figure 9 is another optional flow diagram after non-deterministic scheduling optimization provided by an embodiment of the present application, in which three blockchain transactions are executed in parallel. The three blockchain transactions are: Tx0, Tx1, and Tx2. The execution time of Tx0 is 3 seconds, the execution time of Tx1 is 1 second, and the execution time of Tx2 is 2 seconds. Based on the resources required to execute each blockchain transaction, it can be determined that the weight of Tx0 is 25, the weight of Tx1 is 10, and the weight of Tx2 is 20.

[0178] When one second is reached, Tx1 is executed and used as the target transaction. Conflict detection confirms that Tx1 does not conflict with other blockchain transactions and adds Tx1 to the transaction snapshot. At the same time, due to system scheduling reasons, Tx0 begins to be executed.

[0179] When two seconds have passed, Tx2 is executed and used as the target transaction. Conflict detection determines that Tx1 is the first reference transaction that conflicts with Tx2. Based on the weight relationship between Tx1 and Tx2, Tx2 is scheduled. Since the weight of Tx2 is greater than that of Tx1, Tx2 replaces Tx1 in the transaction snapshot, which is equivalent to adding Tx2 to the transaction snapshot and re-executing Tx1.

[0180] When three seconds have passed, Tx1 is re-executed and used as the target transaction. Conflict detection is performed to determine that Tx1 does not conflict with other blockchain transactions, and Tx1 is added to the transaction snapshot.

[0181] When four seconds are reached, Tx0 is executed and Tx0 is used as the target transaction. Through conflict detection, it is determined that Tx1 and Tx2 are both the first reference transactions that conflict with Tx0. Since there is no conflict between Tx1 and Tx2, Tx1 and Tx2 are used as the third reference set. The first weight sum of the third reference set is calculated to be 30. According to the relationship between the weight of Tx0 and the first weight sum, Tx0 is scheduled. Since the weight of Tx0 is less than the first weight sum, Tx0 is re-executed to retain the blockchain transactions with more resource consumption and re-execute the blockchain transactions with less resource consumption, thereby avoiding resource waste and improving the performance of the blockchain network.

[0182] Among them, for the three comparison situations of the first weight and the sum of the first weights, when the first weight is greater than the sum of the first weights, the target transaction is retained and the target transaction replaces the first reference transaction, which is equivalent to temporarily adding the target transaction to the transaction snapshot and re-executing the first reference transaction. When the first weight is less than the sum of the first weights, the target transaction is re-executed. When the first weight is equal to the sum of the first weights, the target transaction can replace the first reference transaction, or the first reference transaction can be re-executed. Therefore, when scheduling the target transaction, the blockchain transaction with more resource consumption can be retained and the blockchain transaction with less resource consumption can be re-executed, thereby avoiding resource waste and improving the performance of the blockchain network.

[0183] In one possible implementation, the blockchain transaction scheduling method further includes:

[0184] Re-execute the first reference transaction that was replaced in the transaction snapshot;

[0185] When the replaced first reference transaction is re-executed, the re-executed first reference transaction is used as the target transaction;

[0186] The target transaction is rescheduled until all blockchain transactions are added to the transaction snapshot.

[0187] Among them, the target transaction can be scheduled by non-deterministic scheduling. In non-deterministic scheduling, the execution result of each blockchain transaction is uncertain. Non-deterministic scheduling uses the specific execution time of the blockchain transaction as the judgment criterion. Non-deterministic scheduling can be applied to optimistic scenarios. In optimistic scenarios, conflicting transactions are allowed to be replaced. In non-deterministic scheduling, the time point of conflict detection is configured as follows: whenever a blockchain transaction is executed, a conflict detection is performed on the blockchain transaction to determine the conflict relationship between the blockchain transaction and the remaining executed blockchain transactions. Therefore, when the blockchain transaction is re-executed, the conflict detection needs to be re-performed on the blockchain transaction. For example, when the first reference transaction is re-executed, the re-executed first reference transaction is used as the target transaction, and the conflict relationship between the target transaction and the remaining executed blockchain transactions is re-determined. When all blockchain transactions are added to the transaction snapshot, it means that the scheduling of the target transaction has been completed.

[0188] Specifically, referring to FIG10 , FIG10 is another optional flow chart after the non-deterministic scheduling optimization provided in an embodiment of the present application. In the non-deterministic scheduling, each time a blockchain transaction is executed, a conflict detection is performed on the blockchain transaction to determine the conflict relationship between the blockchain transaction and the other completed blockchain transactions. In addition, conflicting transactions are allowed to be replaced in an optimistic scenario.

[0189] Specifically, six blockchain transactions are executed in parallel, namely: Tx0, Tx1, Tx2, Tx3, Tx4 and Tx5. The execution time of Tx0 is 3 seconds, the execution time of Tx1 is 1 second, the execution time of Tx2 is 2 seconds, the execution time of Tx3 is 4 seconds, the execution time of Tx4 is 2 seconds, and the execution time of Tx5 is 4 seconds. Based on the resources required to execute each blockchain transaction, it can be determined that the weight of Tx0 is 30, the weight of Tx1 is 10, the weight of Tx2 is 20, the weight of Tx3 is 40, the weight of Tx4 is 20, and the weight of Tx5 is 40.

[0190] When one second is reached, Tx1 is executed and Tx1 is used as the target transaction. After conflict detection, it is determined that Tx1 does not conflict with other blockchain transactions and Tx1 is added to the transaction snapshot.

[0191] When two seconds have passed, Tx2 is executed and used as the target transaction. Conflict detection is performed to determine whether Tx2 conflicts with other blockchain transactions and Tx2 is added to the transaction snapshot. At the same time, Tx4 is executed and used as the target transaction. Conflict detection is performed to determine whether Tx4 conflicts with other blockchain transactions and Tx4 is added to the transaction snapshot.

[0192] When three seconds have passed, Tx0 is executed and used as the target transaction. Conflict detection determines that Tx2 is the first reference transaction that conflicts with Tx0. Tx0 is scheduled based on the weight of Tx0 and the weight of Tx2. Since the weight of Tx0 is greater than that of Tx2, Tx0 replaces Tx2 in the transaction snapshot, which is equivalent to adding Tx0 to the transaction snapshot and re-executing Tx2.

[0193] When four seconds have passed, Tx3 is executed and used as the target transaction. Conflict detection determines that Tx1 is the first reference transaction that conflicts with Tx3. Based on the weight relationship between Tx3 and Tx1, Tx3 is scheduled. Since the weight of Tx3 is greater than that of Tx1, Tx3 replaces Tx1 in the transaction snapshot, which is equivalent to adding Tx3 to the transaction snapshot and re-executing Tx1. At the same time, Tx5 is executed and used as the target transaction. Conflict detection determines that Tx0 is the first reference transaction that conflicts with Tx5. Based on the weight relationship between Tx5 and Tx0, Tx5 is scheduled. Since the weight of Tx5 is greater than that of Tx0, Tx5 replaces Tx0 in the transaction snapshot, which is equivalent to adding Tx5 to the transaction snapshot and re-executing Tx0.

[0194] When five seconds have passed, Tx1 is executed and used as the target transaction. Conflict detection is performed to determine that Tx1 does not conflict with other blockchain transactions, and Tx1 is added to the transaction snapshot. At the same time, Tx2 is executed and used as the target transaction. Conflict detection determines that Tx5 is the first reference transaction that conflicts with Tx2. Based on the weight relationship between Tx2 and Tx5, Tx2 is scheduled. Since the weight of Tx2 is less than that of Tx5, Tx2 is re-executed.

[0195] When seven seconds have passed, Tx0 is executed and used as the target transaction. Conflict detection is performed to determine that Tx0 does not conflict with other blockchain transactions, and Tx0 is added to the transaction snapshot. At the same time, Tx2 is executed and used as the target transaction. Conflict detection determines that Tx0 is the first reference transaction that conflicts with Tx2. Based on the relationship between the weight of Tx2 and the weight of Tx0, Tx2 is scheduled. Since the weight of Tx2 is less than that of Tx0, Tx2 is re-executed.

[0196] When nine seconds have passed, Tx2 is executed and used as the target transaction. Conflict detection is performed to determine that Tx2 does not conflict with other blockchain transactions, and Tx2 is added to the transaction snapshot.

[0197] Referring again to Figure 7 , we can see that compared to the total execution time of 12 seconds before the non-deterministic scheduling optimization, the total execution time after the non-deterministic scheduling optimization for the optimistic scenario is 9 seconds, a reduction of 3 seconds. This significantly improves execution efficiency by 25%.

[0198] In one possible implementation, the resource consumption parameter includes at least one of a transaction execution time of a blockchain transaction, a number of read-set keys of the blockchain transaction, a read-set memory size of the blockchain transaction, a number of write-set keys of the blockchain transaction, and a write-set memory size of the blockchain transaction. The first weight may be specifically determined by the following steps:

[0199] Determine a score value corresponding to at least one of a transaction execution time, a number of read-set keys, a read-set memory size, a number of write-set keys, and a write-set memory size for a target transaction;

[0200] A first weight is obtained according to at least one score value.

[0201] Among them, the resource consumption parameter is used to indicate the resources required to execute the blockchain transaction. Therefore, the first weight is used to indicate the resources required to execute the target transaction. The resources required to execute the blockchain transaction can be time resources, memory resources, etc.

[0202] Regarding the time resources consumed in executing blockchain transactions, the transaction execution time is very sensitive to the transaction requester and can be determined by the transaction execution time of the blockchain transaction. Therefore, the resource consumption parameter can be the transaction execution time.

[0203] In addition, for the memory resources consumed by executing blockchain transactions, the information of the read-write sets involved is an important resource consumption evaluation factor for the transaction executor. It can be determined by at least one of the number of read-set keys, the read-set memory size, the number of write-set keys, and the write-set memory size. The reasons are as follows:

[0204] State data can be stored in the form of key-value pairs. During the execution of a blockchain transaction, a read set and a write set are created for the blockchain transaction. The read set is used to indicate the state data read when executing the blockchain transaction. Therefore, the read set includes the key of the read state data and the commit version number corresponding to the key. The read set can also include the value corresponding to the key. The write set is used to indicate the state data inserted, deleted, or updated when executing the blockchain transaction. Therefore, the write set includes the key of the written state data and the value corresponding to the key. The number of read set keys refers to the number of keys included in the read set, and the number of write set keys refers to the number of keys included in the write set. The read set memory size refers to the total memory occupied by each data in the read set, and the write set memory size refers to the total memory occupied by each data in the write set. It can be seen that creating read sets and write sets will occupy memory space. The more keys included in the read set, the more memory resources are generally consumed. The more keys included in the write set, the more memory resources are generally consumed. The larger the total memory occupied by each data in the read set, the more memory resources are consumed. The larger the total memory occupied by each data in the write set, the more memory resources are consumed.

[0205] Therefore, the memory resources consumed by executing blockchain transactions can be determined by at least one of the number of read-set keys, the read-set memory size, the number of write-set keys, and the write-set memory size. It can be seen that the resource consumption parameters can be the number of read-set keys, the read-set memory size, the number of write-set keys, and the write-set memory size.

[0206] It is understandable that other parameters for indicating the resources required to execute blockchain transactions can be selected as resource consumption parameters according to actual conditions, and this embodiment of the present application does not limit this.

[0207] Specifically, when using multiple types of resource consumption parameters to determine the first weight, in order to facilitate calculation, the values ​​of each resource consumption parameter need to be consistent. Therefore, the score value corresponding to each resource consumption parameter can be calculated first, and then the sum of each score value can be calculated to obtain the first weight.

[0208] In a possible implementation, since different resource consumption parameters have different degrees of influence on the evaluation of resource consumption, a corresponding upper limit of the score value may be set for each resource consumption parameter.

[0209] For example, the upper limit of the score value corresponding to each resource consumption parameter is shown in Table 1 below:

[0210] Table 1

[0211] As can be seen from Table 1, the corresponding upper limit of the score value is set according to the degree of influence of each resource consumption parameter on the evaluation of resource consumption. For example, the transaction execution time has the greatest influence on the evaluation of resource consumption, so the upper limit of the score value corresponding to the transaction execution time is the largest. Then, based on the upper limit of the score value of the resource consumption parameter and the actual parameter value, the score value corresponding to the resource consumption parameter can be determined.

[0212] Taking transaction execution time as an example, the upper limit of the score value corresponding to the transaction execution time is 100 points. By setting multiple time thresholds, 100 points can be divided into multiple score intervals. For example, the time threshold can be set to 1 second, 2 seconds, 3 seconds, 4 seconds and 5 seconds. When the transaction execution time is less than 1 second, the score value corresponding to the transaction execution time is 0 points. When the transaction execution time is between 1 second and 2 seconds, the score value corresponding to the transaction execution time is between 0 and 20 points. When the transaction execution time is between 2 seconds and 3 seconds, the score value corresponding to the transaction execution time is between 20 and 50 points. When the transaction execution time is between 3 seconds and 4 seconds, the score corresponding to the transaction execution time is between 50 and 80 points. When the transaction execution time is between 4 seconds and 5 seconds, the score corresponding to the transaction execution time is between 80 and 100 points. When the transaction execution time is greater than 5 seconds, the score corresponding to the transaction execution time is 100 points. Within the score range, the actual score can be determined according to the linear relationship between the score and the transaction execution time. Similarly, the score corresponding to other resource consumption parameters can be calculated, and then all the score values ​​can be added together to obtain the first weight.

[0213] It is understandable that the upper limit of the score value corresponding to the resource consumption parameter can be set to other values ​​according to actual conditions, and this embodiment of the present application does not limit this.

[0214] In another possible implementation, the same score upper limit may be set for each resource consumption parameter. For example, the score upper limit is set to 100 points. Taking the transaction execution time as an example again, the score value corresponding to the transaction execution time is determined according to the above-mentioned score value determination method. The score values ​​corresponding to other resource consumption parameters are determined according to the score value determination method based on the same principle. Since different resource consumption parameters have different degrees of influence on the evaluation of resource consumption, corresponding weight values ​​may be set for the score values ​​corresponding to different resource consumption parameters according to the degree of influence of each resource consumption parameter on the evaluation of resource consumption. Then, based on the corresponding weight values, the score values ​​corresponding to each resource consumption parameter are weighted, and then all weighted score values ​​are added together to obtain the first weight.

[0215] Referring to Figure 11, Figure 11 is an optional flow diagram of block verification between nodes provided by an embodiment of the present application, wherein the blockchain network includes block-producing nodes and verification nodes, and the number of verification nodes can be multiple. Multiple blockchain transactions, such as Tx0, Tx1, Tx2, Tx3, Tx4 and Tx5, are executed in parallel through multi-threading of the block-producing nodes. The executed blockchain transactions are used as target transactions. When scheduling conflicting target transactions and first reference transactions, the first weight of the target transaction and the second weight of the first reference transaction are first obtained. Since the first weight and the second weight are both determined based on the resource consumption parameter, scheduling the target transaction according to the size relationship between the first weight and the second weight is equivalent to scheduling the target transaction according to the resource consumption parameter, thereby When scheduling the target transaction, it is possible to retain the blockchain transactions that consume more resources and re-execute the blockchain transactions that consume less resources, so as to avoid resource waste and improve the performance of the blockchain network. According to the scheduling result of the target transaction, a transaction directed acyclic graph is constructed, and the transaction directed acyclic graph and each blockchain transaction are packaged to obtain a proposal block carrying the directed acyclic graph. The proposal block will also include the final world state determined according to the execution result of the blockchain transaction. The block-producing node sends the proposal block to each verification node. The verification node can execute the blockchain transaction in the proposal block based on the transaction directed acyclic graph to obtain a reference world state, and compare the reference state with the final state. When the reference world state is the same as the final world state, the proposal block is determined to be verified, otherwise the verification fails.

[0216] It will be appreciated that, although the various steps in the above-mentioned various flow charts are shown in sequence according to the indication of the arrows, these steps are not necessarily performed in sequence according to the order indicated by the arrows. Unless clearly stated in the present embodiment, the execution of these steps does not have strict order restrictions, and these steps can be performed in other orders. Moreover, at least a portion of the steps in the above-mentioned flow charts can include multiple steps or multiple stages, and these steps or stages are not necessarily performed at the same time, but can be performed at different times, and the execution order of these steps or stages is not necessarily performed in sequence, but can be performed in turn or alternately with at least a portion of the steps or stages in other steps or other steps.

[0217] Referring to FIG. 12 , FIG. 12 is a schematic diagram of an optional structure of a scheduling device for blockchain transactions provided in an embodiment of the present application. The scheduling device 1200 for blockchain transactions includes:

[0218] An execution module 1201 is used to obtain multiple blockchain transactions to be executed and execute each blockchain transaction;

[0219] A conflict detection module 1202 is configured to obtain a completed target transaction from each blockchain transaction and determine a first conflict relationship between the target transaction and at least one first reference transaction, where the first reference transaction is a currently completed blockchain transaction other than the target transaction.

[0220] a weight acquisition module 1203 configured to acquire a first weight of the target transaction and a second weight of the first reference transaction when the first conflict relationship indicates a conflict between the target transaction and the first reference transaction, wherein the first weight is determined based on a resource consumption parameter when executing the target transaction, and the second weight is determined based on a resource consumption parameter when executing the first reference transaction;

[0221] The first scheduling module 1204 is configured to schedule the target transaction according to the relationship between the first weight and the second weight.

[0222] Furthermore, the first scheduling module 1204 is specifically configured to:

[0223] Scheduling the target transaction based on the relationship between the first weight and each second weight;

[0224] Alternatively, the sum of the second weights is calculated as the sum of the first weights, and the target transaction is scheduled according to the relationship between the first weights and the sum of the first weights.

[0225] Furthermore, the target transaction is obtained after all blockchain transactions are executed, and the first reference transaction is not added to the transaction snapshot. The first scheduling module 1204 is specifically used to:

[0226] When the first weight is greater than each second weight, adding the target transaction to the transaction snapshot;

[0227] Alternatively, when the first weight is less than any second weight, re-execute the target transaction;

[0228] Alternatively, when the first weight is equal to the maximum value of the second weights, the target transaction is added to the transaction snapshot or the target transaction is re-executed.

[0229] Furthermore, the first scheduling module 1204 is specifically configured to:

[0230] A first transaction set is formed using the target transaction and a first reference transaction corresponding to a second weight equal to the first weight;

[0231] Add any blockchain transaction in the first transaction set to the transaction snapshot and re-execute the remaining blockchain transactions in the first transaction set.

[0232] Further, referring to FIG. 12 , FIG. 12 is a schematic diagram of another optional structure of a scheduling device for blockchain transactions provided in an embodiment of the present application. The scheduling device 1200 for blockchain transactions further includes:

[0233] The second scheduling module 1205 is configured to, when all blockchain transactions that have not been added to the transaction snapshot have been re-executed, use the blockchain transactions that have been re-executed and not added to the transaction snapshot as target transactions; and re-schedule the target transactions until all blockchain transactions have been added to the transaction snapshot.

[0234] Furthermore, the target transaction is obtained whenever a blockchain transaction is executed, and the first reference transaction is not added to the transaction snapshot. The first scheduling module 1204 is specifically configured to:

[0235] When the first weight is greater than the sum of the first weights, wait for a preset time, and after the waiting time reaches the preset time, schedule the target transaction;

[0236] Alternatively, when the first weight is less than the sum of the first weights, re-execute the target transaction;

[0237] Alternatively, when the first weight is equal to the sum of the first weights, wait for a preset time period, and after the waiting time period reaches the preset time period, schedule the target transaction or re-execute the target transaction.

[0238] Furthermore, the conflict detection module 1202 is specifically configured to:

[0239] Determining a second conflict relationship between the target transaction and a second reference transaction, wherein the second reference transaction is a blockchain transaction other than the target transaction that has been currently executed and added to the transaction snapshot;

[0240] When the second conflict relationship indicates that there is no conflict between the target transaction and the second reference transaction, a first conflict relationship between the target transaction and the at least one first reference transaction is determined.

[0241] Furthermore, the first scheduling module 1204 is specifically configured to:

[0242] After the waiting time reaches a preset time, determining a third conflict relationship between the target transaction and at least one third reference transaction, wherein the third reference transaction is a blockchain transaction other than the target transaction that has been currently executed and has not been added to the transaction snapshot;

[0243] When the third conflict relationship indicates that there is a conflict between the target transaction and the third reference transaction, obtaining a third weight of the third reference transaction, wherein the third weight is determined based on a resource consumption parameter when executing the third reference transaction;

[0244] The sum of the third weights is calculated as the second weight sum, and the target transaction is scheduled according to the size relationship between the first weight and the second weight sum.

[0245] Furthermore, the first scheduling module 1204 is specifically configured to:

[0246] When the first weight is greater than the sum of the second weights, the target transaction is added to the transaction snapshot;

[0247] Alternatively, when the first weight is less than the sum of the second weights, re-execute the target transaction;

[0248] Alternatively, when the first weight is equal to the sum of the second weights, the target transaction is added to the transaction snapshot or the target transaction is re-executed.

[0249] Furthermore, the first scheduling module 1204 is specifically configured to:

[0250] Determining a fourth conflict relationship between the target transaction and a fourth reference transaction, where the fourth reference transaction is a blockchain transaction other than the target transaction that has been completed and added to the transaction snapshot;

[0251] When the fourth conflict relationship indicates that there is no conflict between the target transaction and the fourth reference transaction, a third conflict relationship between the target transaction and at least one third reference transaction is determined.

[0252] Further, referring to FIG. 14 , FIG. 14 is a schematic diagram of another optional structure of a scheduling device for blockchain transactions provided in an embodiment of the present application. The scheduling device 1200 for blockchain transactions further includes:

[0253] The third scheduling module 1206 is configured to, when a blockchain transaction that has not been added to the transaction snapshot is re-executed, use the blockchain transaction that has been re-executed and not added to the transaction snapshot as a target transaction; and re-schedule the target transaction until all blockchain transactions are added to the transaction snapshot.

[0254] Furthermore, the target transaction is obtained whenever a blockchain transaction is completed, and the first reference transaction has been added to the transaction snapshot. The first scheduling module 1204 is specifically used to:

[0255] When the first weight is greater than the sum of the first weights, replacing the first reference transaction in the transaction snapshot with the target transaction;

[0256] Alternatively, when the first weight is less than the sum of the first weights, re-execute the target transaction;

[0257] Alternatively, when the first weight is equal to the sum of the first weights, the first reference transaction in the transaction snapshot is replaced with the target transaction or the target transaction is re-executed.

[0258] Further, referring to FIG. 15 , FIG. 15 is a schematic diagram of another optional structure of a scheduling device for blockchain transactions provided in an embodiment of the present application. The scheduling device 1200 for blockchain transactions further includes:

[0259] The fourth scheduling module 1207 is configured to re-execute the replaced first reference transaction in the transaction snapshot; when the replaced first reference transaction is re-executed, use the re-executed first reference transaction as the target transaction; and re-schedule the target transaction until all blockchain transactions are added to the transaction snapshot.

[0260] Furthermore, the resource consumption parameter includes at least one of the transaction execution time of the blockchain transaction, the number of read-set keys of the blockchain transaction, the read-set memory size of the blockchain transaction, the number of write-set keys of the blockchain transaction, and the write-set memory size of the blockchain transaction. The weight acquisition module 1203 is specifically used to:

[0261] Determine a score value corresponding to at least one of a transaction execution time, a number of read-set keys, a read-set memory size, a number of write-set keys, and a write-set memory size for a target transaction;

[0262] A first weight is obtained according to at least one score value.

[0263] The above-mentioned blockchain transaction scheduling device 1200 and blockchain transaction scheduling method are based on the same inventive concept. By executing multiple blockchain transactions, the executed blockchain transaction is used as the target transaction. When scheduling the conflicting target transactions and the first reference transaction, the first weight of the target transaction and the second weight of the first reference transaction are obtained. Since the first weight and the second weight are both determined based on the resource consumption parameter, scheduling the target transaction according to the size relationship between the first weight and the second weight is equivalent to scheduling the target transaction according to the resource consumption parameter. Therefore, when scheduling the target transaction, the blockchain transaction with more resource consumption can be retained and the blockchain transaction with less resource consumption can be re-executed, thereby avoiding resource waste and improving the performance of the blockchain network.

[0264] The electronic device for executing the scheduling method for blockchain transactions provided in the embodiment of the present application may be a terminal. Referring to FIG16 , FIG16 is a partial structural block diagram of the terminal provided in the embodiment of the present application. The terminal includes components such as a camera assembly 1610, a memory 1620, an input unit 1630, a display unit 1640, a sensor 1650, an audio circuit 1660, a wireless fidelity (WiFi) module 1670, a processor 1680, and a power supply 1690. It will be understood by those skilled in the art that the terminal structure shown in FIG16 does not constitute a limitation on the terminal, and may include more or fewer components than shown, or combine certain components, or arrange the components differently.

[0265] The camera assembly 1610 can be used to capture images or videos. Optionally, the camera assembly 1610 includes a front camera and a rear camera. Typically, the front camera is provided on the front panel of the terminal, and the rear camera is provided on the back of the terminal. In some embodiments, there are at least two rear cameras, which are any one of a main camera, a depth of field camera, a wide-angle camera, and a telephoto camera, so as to realize the fusion of the main camera and the depth of field camera to realize the background blur function, the fusion of the main camera and the wide-angle camera to realize panoramic shooting and VR (Virtual Reality) shooting function or other fusion shooting functions.

[0266] The memory 1620 may be used to store software programs and modules. The processor 1680 executes the software programs and modules stored in the memory 1620 to execute various functional applications and data processing of the terminal.

[0267] The input unit 1630 may be configured to receive input digital or character information and generate key signal input related to terminal settings and function control. Specifically, the input unit 1630 may include a touch panel 1631 and other input devices 1632 .

[0268] The display unit 1640 may be configured to display input information or provided information and various menus of the terminal. The display unit 1640 may include a display panel 1641 .

[0269] The audio circuit 1660 , the speaker 1661 , and the microphone 1662 may provide an audio interface.

[0270] The power source 1690 may be AC ​​power, DC power, disposable batteries, or rechargeable batteries.

[0271] The number of sensors 1650 can be one or more, and the one or more sensors 1650 include but are not limited to: acceleration sensors, gyroscope sensors, pressure sensors, optical sensors, etc. Among them:

[0272] The accelerometer can detect the magnitude of acceleration along the three coordinate axes of the coordinate system established by the terminal. For example, the accelerometer can be used to detect the components of gravity acceleration along the three coordinate axes. The processor 1680 can control the display unit 1640 to display the user interface in a landscape or portrait view based on the gravity acceleration signal collected by the accelerometer. The accelerometer can also be used to collect game or user motion data.

[0273] The gyroscope sensor can detect the device's orientation and rotation angle. It can also work with the accelerometer to capture the user's 3D movements. Based on the data collected by the gyroscope sensor, the processor 1680 can implement the following functions: motion sensing (such as changing the UI based on the user's tilt), image stabilization during shooting, game control, and inertial navigation.

[0274] The pressure sensor can be set on the side frame of the terminal and / or the lower layer of the display unit 1640. When the pressure sensor is set on the side frame of the terminal, it can detect the user's grip signal of the terminal, and the processor 1680 performs left and right hand recognition or shortcut operations based on the grip signal collected by the pressure sensor. When the pressure sensor is set on the lower layer of the display unit 1640, the processor 1680 controls the operability controls on the UI interface based on the user's pressure operation on the display unit 1640. The operability controls include at least one of a button control, a scroll bar control, an icon control, and a menu control.

[0275] The optical sensor is used to collect ambient light intensity. In one embodiment, the processor 1680 can control the display brightness of the display unit 1640 based on the ambient light intensity collected by the optical sensor. Specifically, when the ambient light intensity is high, the display brightness of the display unit 1640 is increased; when the ambient light intensity is low, the display brightness of the display unit 1640 is decreased. In another embodiment, the processor 1680 can also dynamically adjust the shooting parameters of the camera assembly 1610 based on the ambient light intensity collected by the optical sensor.

[0276] In this embodiment, the processor 1680 included in the terminal can execute the blockchain transaction scheduling method of the previous embodiment.

[0277] The electronic device used to execute the above-mentioned blockchain transaction scheduling method provided in the embodiments of the present application can also be a server. Referring to FIG. 17 , which is a partial block diagram of the server provided in the embodiments of the present application, server 1700 may vary significantly due to different configurations or performance. It may include one or more central processing units (CPUs) 1722 (e.g., one or more processors), memory 1732, and one or more storage media 1730 (e.g., one or more mass storage devices) storing application programs 1742 or data 1744. Memory 1732 and storage media 1730 may be either ephemeral or persistent storage. The program stored in storage medium 1730 may include one or more modules (not shown), each of which may include a series of instruction operations on server 1700. Furthermore, CPU 1722 may be configured to communicate with storage medium 1730 to execute the series of instruction operations in storage medium 1730 on server 1700.

[0278] The server 1700 may also include one or more power supplies 1726, one or more wired or wireless network interfaces 1750, one or more input and output interfaces 1758, and / or one or more operating systems 1741, such as Windows Server 2003. TM , Mac OS X TM , Unix TM , Linux TM , FreeBSD TM etc.

[0279] The processor in the server 1700 can be used to execute the scheduling method of the blockchain transaction.

[0280] An embodiment of the present application further provides a computer-readable storage medium, which is used to store program code, and the program code is used to execute the blockchain transaction scheduling method of each of the aforementioned embodiments.

[0281] The present application also provides a computer program product, comprising a computer program stored in a computer-readable storage medium. A processor of a computer device reads the computer program from the computer-readable storage medium and executes the computer program, causing the computer device to implement the aforementioned blockchain transaction scheduling method.

[0282] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can, for example, be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0283] It should be understood that in this application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship. "At least one of the following items" or similar expressions refers to any combination of these items, including any combination of single items or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.

[0284] It should be understood that in the description of the embodiments of the present application, multiple (or multiple items) means more than two, greater than, less than, exceed, etc. are understood to exclude the number itself, and above, below, within, etc. are understood to include the number itself.

[0285] In the several embodiments provided in this application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic. For example, the division of units is only a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interface, device or unit, which can be electrical, mechanical or other forms.

[0286] Units described as separate components may or may not be physically separate, and components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.

[0287] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.

[0288] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0289] It should also be understood that the various implementation methods provided in the embodiments of the present application can be combined arbitrarily to achieve different technical effects.

[0290] The above is a specific description of the preferred implementation of the present application, but the present application is not limited to the above implementation mode. Technical personnel familiar with the art can also make various equivalent modifications or substitutions under the shared conditions that do not violate the spirit of the present application. These equivalent modifications or substitutions are all included in the scope defined by the claims of the present application.

Claims

1. A method for scheduling blockchain transactions, executed by a computer device, comprising: Obtain multiple blockchain transactions to be executed, and execute each of the blockchain transactions; Acquire a target transaction that has been executed from each of the blockchain transactions, and determine a first conflict relationship between the target transaction and at least one first reference transaction, wherein the first reference transaction is a currently executed blockchain transaction other than the target transaction; When the first conflict relationship indicates that there is a conflict between the target transaction and the first reference transaction, obtaining a first weight of the target transaction and a second weight of the first reference transaction, wherein the first weight is determined based on a resource consumption parameter when executing the target transaction, and the second weight is determined based on a resource consumption parameter when executing the first reference transaction; The target transaction is scheduled according to the magnitude relationship between the first weight and the second weight.

2. The method for scheduling blockchain transactions according to claim 1, wherein scheduling the target transaction according to the relationship between the first weight and the second weight comprises: Scheduling the target transaction according to a magnitude relationship between the first weight and each of the second weights; Alternatively, the sum of the second weights is calculated as the first weight sum, and the target transaction is scheduled according to the relationship between the first weight and the first weight sum.

3. According to the method for scheduling blockchain transactions in claim 1 or 2, the target transaction is obtained after each of the blockchain transactions is executed, the first reference transaction is not added to the transaction snapshot, and the target transaction is scheduled according to the relationship between the first weight and each of the second weights, comprising: When the first weight is greater than each of the second weights, adding the target transaction to the transaction snapshot; Alternatively, when the first weight is less than any of the second weights, re-execute the target transaction; Alternatively, when the first weight is equal to the maximum value of the second weights, the target transaction is added to the transaction snapshot or the target transaction is re-executed.

4. The method for scheduling blockchain transactions according to claim 3, wherein the step of adding the target transaction to the transaction snapshot or re-executing the target transaction comprises: Using the target transaction and the first reference transaction corresponding to a second weight equal to the first weight, a first transaction set is formed; Add any one of the blockchain transactions in the first transaction set to the transaction snapshot, and re-execute the remaining blockchain transactions in the first transaction set.

5. According to the scheduling method of blockchain transactions according to claim 3 or 4, the scheduling method further comprises: When all the blockchain transactions that have not been added to the transaction snapshot have been re-executed, the blockchain transactions that have been re-executed and have not been added to the transaction snapshot are used as the target transactions; The target transaction is rescheduled until all the blockchain transactions are added to the transaction snapshot.

6. The method for scheduling blockchain transactions according to claim 2, wherein the target transaction is obtained whenever a blockchain transaction is executed, the first reference transaction is not added to the transaction snapshot, and the target transaction is scheduled according to the relationship between the first weight and the sum of the first weights, comprising: When the first weight is greater than the sum of the first weights, wait for a preset time, and after the waiting time reaches the preset time, schedule the target transaction; Alternatively, when the first weight is less than the sum of the first weights, re-executing the target transaction; Alternatively, when the first weight is equal to the sum of the first weights, wait for the preset time period, and after the waiting time period reaches the preset time period, schedule the target transaction or re-execute the target transaction.

7. The method for scheduling blockchain transactions according to claim 6, wherein determining a first conflict relationship between the target transaction and at least one first reference transaction comprises: Determine a second conflict relationship between the target transaction and a second reference transaction, wherein the second reference transaction is the blockchain transaction other than the target transaction that has been currently executed and has been added to the transaction snapshot; When the second conflict relationship indicates that there is no conflict between the target transaction and the second reference transaction, the first conflict relationship between the target transaction and at least one of the first reference transactions is determined.

8. The method for scheduling blockchain transactions according to claim 6, wherein after the waiting time reaches the preset time, scheduling the target transaction comprises: After the waiting time reaches the preset time, determining a third conflict relationship between the target transaction and at least one third reference transaction, wherein the third reference transaction is the blockchain transaction other than the target transaction that has been currently executed and has not been added to the transaction snapshot; When the third conflict relationship indicates that there is a conflict between the target transaction and the third reference transaction, obtaining a third weight of the third reference transaction, wherein the third weight is determined based on a resource consumption parameter when executing the third reference transaction; The sum of the third weights is calculated as the second weight sum, and the target transaction is scheduled according to the relationship between the first weight and the second weight sum.

9. The method for scheduling blockchain transactions according to claim 8, wherein scheduling the target transaction according to the relationship between the first weight and the sum of the second weights comprises: When the first weight is greater than the sum of the second weights, adding the target transaction to the transaction snapshot; Alternatively, when the first weight is less than the sum of the second weights, re-executing the target transaction; Alternatively, when the first weight is equal to the sum of the second weights, the target transaction is added to the transaction snapshot or the target transaction is re-executed.

10. The method for scheduling blockchain transactions according to claim 8, wherein determining a third conflict relationship between the target transaction and at least one third reference transaction comprises: Determining a fourth conflict relationship between the target transaction and a fourth reference transaction, wherein the fourth reference transaction is the blockchain transaction other than the target transaction that has been currently executed and has been added to the transaction snapshot; When the fourth conflict relationship indicates that there is no conflict between the target transaction and the fourth reference transaction, the third conflict relationship between the target transaction and at least one of the third reference transactions is determined.

11. The method for scheduling blockchain transactions according to any one of claims 6 to 10, further comprising: When the blockchain transaction that has not been added to the transaction snapshot is re-executed, the blockchain transaction that has been re-executed and has not been added to the transaction snapshot is used as the target transaction; The target transaction is rescheduled until all the blockchain transactions are added to the transaction snapshot.

12. The method for scheduling blockchain transactions according to claim 2, wherein the target transaction is obtained whenever a blockchain transaction is executed, the first reference transaction has been added to a transaction snapshot, and the target transaction is scheduled according to the relationship between the first weight and the sum of the first weights, comprising: When the first weight is greater than the sum of the first weights, replacing the first reference transaction in the transaction snapshot with the target transaction; Alternatively, when the first weight is less than the sum of the first weights, re-executing the target transaction; Alternatively, when the first weight is equal to the first weight sum, the first reference transaction in the transaction snapshot is replaced with the target transaction or the target transaction is re-executed.

13. The method for scheduling blockchain transactions according to claim 12, further comprising: re-executing the first reference transaction that is replaced in the transaction snapshot; When the replaced first reference transaction is re-executed, the re-executed first reference transaction is used as the target transaction; The target transaction is rescheduled until all the blockchain transactions are added to the transaction snapshot.

14. The method for scheduling blockchain transactions according to any one of claims 1 to 13, wherein the resource consumption parameter comprises at least one of a transaction execution time of the blockchain transaction, a number of read set keys of the blockchain transaction, a read set memory size of the blockchain transaction, a number of write set keys of the blockchain transaction, and a write set memory size of the blockchain transaction, and the first weight is determined by the following steps: Determine a score value corresponding to at least one of the transaction execution time, the number of read set keys, the read set memory size, the number of write set keys, and the write set memory size of the target transaction; The first weight is obtained according to at least one of the score values.

15. A scheduling device for blockchain transactions, comprising: An execution module, used to obtain multiple blockchain transactions to be executed and execute each of the blockchain transactions; a conflict detection module, configured to obtain a target transaction that has been executed from each of the blockchain transactions, and determine a first conflict relationship between the target transaction and at least one first reference transaction, wherein the first reference transaction is a currently executed blockchain transaction other than the target transaction; a weight acquisition module, configured to acquire a first weight of the target transaction and a second weight of the first reference transaction when the first conflict relationship indicates that there is a conflict between the target transaction and the first reference transaction, wherein the first weight is determined based on a resource consumption parameter when executing the target transaction, and the second weight is determined based on a resource consumption parameter when executing the first reference transaction; The first scheduling module is used to schedule the target transaction according to the relationship between the first weight and the second weight.

16. A computer device comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the blockchain transaction scheduling method described in any one of claims 1 to 14 when executing the computer program.

17. A computer-readable storage medium, wherein the storage medium stores a computer program, and when the computer program is executed by a processor, the scheduling method for blockchain transactions described in any one of claims 1 to 14 is implemented.

18. A computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the method for scheduling blockchain transactions as described in any one of claims 1 to 14 is implemented.

Citation Information

Patent Citations

  • Deterministic transaction concurrent scheduling method and system of block chain

    CN114564412A

  • Block chain transaction processing system and method

    CN115398397A

  • Transaction execution method and device, computer equipment and medium

    CN115760405A

  • Resource exchange system

    US20210118054A1