WO2023142605A1 - 一种基于区块链的数据处理方法和相关装置 - Google Patents

一种基于区块链的数据处理方法和相关装置 Download PDF

Info

Publication number
WO2023142605A1
WO2023142605A1 PCT/CN2022/131599 CN2022131599W WO2023142605A1 WO 2023142605 A1 WO2023142605 A1 WO 2023142605A1 CN 2022131599 W CN2022131599 W CN 2022131599W WO 2023142605 A1 WO2023142605 A1 WO 2023142605A1
Authority
WO
WIPO (PCT)
Prior art keywords
transaction
account
pending
queue
execution sequence
Prior art date
Application number
PCT/CN2022/131599
Other languages
English (en)
French (fr)
Inventor
冯浩铭
赵勇
陈诗鹏
刘生乾
Original Assignee
腾讯科技(深圳)有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 腾讯科技(深圳)有限公司 filed Critical 腾讯科技(深圳)有限公司
Publication of WO2023142605A1 publication Critical patent/WO2023142605A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q20/00Payment architectures, schemes or protocols
    • G06Q20/38Payment protocols; Details thereof
    • G06Q20/40Authorisation, e.g. identification of payer or payee, verification of customer or shop credentials; Review and approval of payers, e.g. check credit lines or negative lists
    • G06Q20/401Transaction verification
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L9/00Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
    • H04L9/50Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols using hash chains, e.g. blockchains or hash trees
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q20/00Payment architectures, schemes or protocols
    • G06Q20/38Payment protocols; Details thereof
    • G06Q20/40Authorisation, e.g. identification of payer or payee, verification of customer or shop credentials; Review and approval of payers, e.g. check credit lines or negative lists
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q20/00Payment architectures, schemes or protocols
    • G06Q20/38Payment protocols; Details thereof
    • G06Q20/40Authorisation, e.g. identification of payer or payee, verification of customer or shop credentials; Review and approval of payers, e.g. check credit lines or negative lists
    • G06Q20/405Establishing or using transaction specific rules
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L63/00Network architectures or network communication protocols for network security
    • H04L63/12Applying verification of the received information
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Definitions

  • the present application relates to the field of computer technology, and in particular to a blockchain-based data processing method, device, and readable storage medium.
  • the txNonce Transaction Number once, non-repeating number of transactions
  • the accountNonce Account Number once, non-repeating number of accounts
  • txNonce is used to identify the order in which the blockchain account that sent the transaction wants the transaction to be executed in the transactions sent by the blockchain account, and increments from 0
  • accountNonce is used to identify that the blockchain account in the current world state has already The number of transactions executed, incrementing from 0.
  • the blockchain node After the blockchain node receives the transaction, it will put the transaction into the transaction pool for caching, and then package some transactions in the transaction pool to generate a block.
  • transactions of different txNonces under the same blockchain account may not arrive at the blockchain nodes in the order from small to large, resulting in transactions being mistakenly considered illegal and unable to be processed.
  • the fault tolerance rate of the blockchain system is low, even if the transaction can be received by the transaction pool, there may be a problem that the txNonce of the transaction contained in the block generated does not match the accountNonce of the account that sent the transaction in the current world state , causing the block to fail to reach a consensus and fail to be uploaded to the chain.
  • the embodiment of the present application provides a block chain-based data processing method, device, and readable storage medium, which can enhance the fault tolerance of the block chain system and improve the success rate of block chaining.
  • an embodiment of the present application provides a blockchain-based data processing method, which is executed by a computer device, including:
  • the pending transaction contains the pending execution sequence identifier;
  • the pending account preparation queue is used to store the Prepared transactions in status and execution sequence identifiers that have a mapping relationship with the prepared transactions;
  • pending account waiting queues are used to store pending transactions that are not in the ready state and execution sequence identifiers that have a mapping relationship with the pending transactions;
  • the execution sequence identifier that can form a sequence identifier continuous sequence with the pending execution sequence identifier is used as the upgrade execution sequence identifier, and the upgrade execution sequence identifier and the waiting transactions corresponding to the upgrade execution sequence identifier are added in order Go to the transition account preparation queue to get the upgrade account preparation queue;
  • an embodiment of the present application provides a blockchain-based data processing device, which is deployed on computer equipment, including:
  • the acquisition module is used to obtain the pending transactions sent by the pending accounts, and obtain the pending account preparation queue and the pending account waiting queue corresponding to the pending accounts; the pending transactions include the pending execution sequence identifier; the pending account preparation queue is used It is used to store the prepared transactions in the prepared state and the execution order identifiers that have a mapping relationship with the prepared transactions; the pending account waiting queue is used to store the waiting transactions that are in the unprepared state and the execution sequence identifiers that have a mapping relationship with the waiting transactions;
  • the transaction transition module is used to add the pending transaction and the pending execution sequence identifier to the pending account preparation queue to obtain the transition account preparation queue if it is determined that the pending transaction is in the prepared state;
  • the transaction upgrade module is used to use the execution sequence identifier that can form a continuous sequence of sequence identifiers with the pending execution sequence identifier in the pending account waiting queue as the upgrade execution sequence identifier, and correspond the upgrade execution sequence identifier to the upgrade execution sequence identifier
  • the waiting transactions are migrated to the transition account preparation queue in order, and the upgrade account preparation queue is obtained;
  • the transaction addition module is used to add the pending transactions in the upgrade account preparation queue and the waiting transactions corresponding to the upgrade execution sequence identifier to the total preparation queue; the transactions in the total preparation queue will be packaged into the candidate block according to the order of transaction insertion time .
  • An embodiment of the present application provides a computer device, including: a processor, a memory, and a network interface;
  • the above-mentioned processor is connected to the above-mentioned memory and the above-mentioned network interface, wherein the above-mentioned network interface is used to provide data communication network elements, the above-mentioned memory is used to store computer programs, and the above-mentioned processor is used to call the above-mentioned computer programs to execute the method.
  • the embodiments of the present application provide a computer-readable storage medium, where a computer program is stored in the computer-readable storage medium, and the computer program is adapted to be loaded by a processor and execute the method in the embodiment of the present application.
  • the embodiments of the present application provide a computer program product, including computer programs/instructions, and when the computer programs/instructions are executed by a processor, the methods in the embodiments of the present application are implemented.
  • the pending transaction whose account is in the prepared state and the execution sequence identifier that has a mapping relationship with the prepared transaction will be stored in the pending account preparation queue, and the pending transaction with the pending account in the unprepared state and the waiting
  • the execution sequence ID of the transaction with the mapping relationship will be stored in the waiting queue of the pending account, and then when the pending transaction sent by the pending account containing the pending execution sequence ID is obtained, if it is determined that the pending transaction is in the ready state, it will be Add the pending transaction and the pending execution sequence identifier to the pending account preparation queue to obtain the transition account preparation queue, and then in the pending account waiting queue, add the execution sequence identifier that can form a sequence identifier continuous sequence with the pending execution sequence identifier , as the upgrade execution sequence identifier, and the upgrade execution sequence identifier and the waiting transactions corresponding to the upgrade execution sequence identifier are added to the transition account preparation queue in order to obtain the upgrade account preparation queue.
  • the pending transactions in the upgrade account preparation queue and The waiting transactions corresponding to the upgrade execution sequence ID are added to the general preparation queue.
  • the transactions in the general preparation queue will be packaged into candidate blocks in the order of transaction insertion time.
  • the preparation transactions of the accounts to be processed in the prepared state are all stored in the preparation queue of the accounts to be processed, and the preparation transactions of the accounts to be processed can be added to the general preparation queue, which can ensure that the transaction based on the total There will be no unprepared waiting transactions in the candidate block generated by the transaction packaging in the preparation queue, which can improve the success rate of the block on the chain.
  • the unprepared transaction sent by the pending account will not be rejected, and will be temporarily stored in the waiting queue of the pending account.
  • the pending account When preparing the queue, the pending account waiting queue is upgraded, and eligible waiting transactions will be added to the pending account preparation queue, and further added to the general preparation queue for packaging, which can enhance the fault tolerance of the blockchain system.
  • Fig. 1 is a schematic structural diagram of a block chain node system provided by the embodiment of the present application.
  • FIG. 2 is a schematic diagram of a blockchain-based data processing scenario provided by an embodiment of the present application
  • Fig. 3 is a schematic flow diagram of a blockchain-based data processing method provided by an embodiment of the present application.
  • Fig. 4 is a schematic diagram of queue construction for transaction pool management provided by the embodiment of the present application.
  • FIG. 5 is a schematic flow diagram of a blockchain-based data processing method provided by an embodiment of the present application.
  • FIG. 6 is a schematic flow diagram of a blockchain-based data processing method provided by an embodiment of the present application.
  • Fig. 7 is a schematic flow chart of a transaction receiving method provided by an embodiment of the present application.
  • Fig. 8 is a schematic flow diagram of refreshing the transaction pool provided by the embodiment of the present application.
  • FIG. 9 is a schematic structural diagram of a data processing device provided in an embodiment of the present application.
  • Fig. 10 is a schematic structural diagram of a computer device provided by an embodiment of the present application.
  • Blockchain is a new application mode of computer technology such as distributed data storage, point-to-point transmission, consensus mechanism and encryption algorithm. It can be tampered with and forged, and at the same time, data can be verified, stored and updated.
  • the blockchain is essentially a decentralized database, each node in the database stores the same blockchain, and the blockchain network can distinguish nodes into consensus nodes and business nodes, where consensus nodes are responsible for block The consensus of the entire network.
  • the process of writing transaction data into the ledger in the blockchain network can be as follows: the client sends the transaction data to the business node, and then the transaction data is passed between the business nodes in the blockchain network in the form of a baton until the consensus node After receiving the transaction data, the consensus node will package the transaction data into a block and carry out consensus with other consensus nodes. After the consensus is passed, the block carrying the transaction data will be written into the ledger.
  • Block It is a data packet that carries transaction data (that is, transaction business) on the blockchain network. It is a data structure marked with a timestamp and the hash value of the previous block. The block passes through the consensus mechanism of the network Validate and finalize the transactions in the block.
  • Hash value Also known as information feature value or feature value, the hash value is generated by converting input data of any length into a password through a hash algorithm and performing a fixed output. The original input data cannot be retrieved by decrypting the hash value , which is a one-way encryption function.
  • each block (except the initial block) contains the hash value of the previous block, which is called the parent block of the current block.
  • Hash is the core underlying and most important aspect of potential in blockchain technology, which preserves the authenticity of recorded and viewed data, and the integrity of the blockchain as a whole.
  • Blockchain account There is an account address as its unique identifier.
  • the blockchain account contains a balance as the digital resource of the blockchain account in the current world state.
  • the blockchain account corresponds to accountNonce, which is used to record the current world How many transactions sent by the blockchain account have been executed in the state, the initial value of accountNonce is 0, and the accountNonce is incremented by 1 after each transaction under the blockchain account is executed. It should be noted that the accounts mentioned in the subsequent embodiments of this application all refer to blockchain accounts, and will not be described in detail later.
  • the transaction sent by the blockchain account which contains the transaction hash as the unique identifier, contains the account address to identify the blockchain account that sent the transaction, and has a txNonce to identify the blockchain account to which the transaction belongs in the current world.
  • the transaction execution sequence in the state for example, the blockchain account expects the txNonce of the first executed transaction to be 0, the second executed transaction to have a txNonce of 1, and so on. Therefore, the txNonce of the transaction must be equal to the accountNonce of the blockchain account before the transaction is executed in the current world state, otherwise the transaction is invalid. As long as at least one transaction in the block is invalid, it will cause the block to fail to reach a consensus and cannot be uploaded to the chain.
  • txFee transaction fee
  • the txFee field may be calculated by certain fields through established rules, for example, value (transfer amount) + gas (consumption) * gasPrice (consumption unit price).
  • On-chain Each block contains several transactions. When a block is inserted into the blockchain data structure of each blockchain node through consensus, it is called on-chain.
  • World state a view composed of the persistent data owned by each account in the blockchain. Since the execution of the transaction itself will modify some of the persistent data of several accounts, each transaction in each block will have A new world state. After each block is chained, the world state of each blockchain node will be updated. After the same block is chained, the world state of each blockchain node must be consistent.
  • FIG. 1 is a schematic structural diagram of a blockchain node system provided by an embodiment of the present application.
  • the blockchain node system shown in FIG. 1 may correspond to a blockchain network, which may include but not limited to a blockchain network corresponding to a consortium chain.
  • the blockchain node system refers to a system for data sharing between blockchain nodes and blockchain nodes.
  • the blockchain node system can include multiple blockchain nodes, and multiple blockchain nodes can specifically Including blockchain node 10a, blockchain node 10b, blockchain node 10c, blockchain node 10d, ..., blockchain node 10n.
  • each blockchain node can receive data sent by the outside world during normal work, and perform block chain processing based on the received data, and can also send data to the outside world.
  • each blockchain node there may be a data connection between each blockchain node, for example, there is a data connection between the blockchain node 10a and the blockchain node 10b, and the blockchain node 10a and the blockchain node 10b There is a data connection between the blockchain nodes 10c, and there is a data connection between the blockchain node 10b and the blockchain node 10c.
  • the blockchain network can realize the data connection between the blockchain nodes based on the node identification.
  • each blockchain node in the blockchain network it has its corresponding node identification, and each of the above blockchain nodes has It can store the node IDs of other blockchain nodes that are connected to itself, so that the obtained data or generated blocks can be broadcast to other blockchain nodes based on the node IDs of other blockchain nodes, such as block A node identification list as shown in Table 1 can be maintained in the chain node 10a, which stores the node names and node identifications of other nodes:
  • the node identification can be the Internet Protocol (IP) address between the networks and any other information that can be used to identify the nodes in the blockchain network.
  • IP Internet Protocol
  • Table 1 only uses the IP address as an example for illustration.
  • blockchain node 10a can send information (e.g., a block) to blockchain node 10b through node identifier 117.116.189.145, and blockchain node 10b can determine through node identifier 117.114.151.174 that the information is provided by blockchain node 10b. sent by node 10a.
  • block chain node 10a, block chain node 10b, block chain node 10c and block chain node 10d can be used as the consensus in the block chain node system node.
  • Consensus nodes in the blockchain node system participate in consensus, that is, consensus on blocks (including a batch of transactions), including generating blocks and voting on blocks; non-consensus nodes do not participate in consensus, but will help spread the consensus Block and voting messages, and mutual synchronization state, etc.
  • connection method can be directly or indirectly connected through wired communication, or can be directly or indirectly connected through wireless communication, or through other connection methods.
  • connection methods can be directly or indirectly connected through wired communication, or can be directly or indirectly connected through wireless communication, or through other connection methods.
  • the data processing method provided by the embodiment of the present application can be executed by computer equipment, and the computer equipment includes but is not limited to the above-mentioned blockchain nodes (which may be servers or terminals).
  • the above-mentioned server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, and can also provide cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, Cloud servers for basic cloud computing services such as middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms.
  • the above-mentioned terminal may be a smart phone, a tablet computer, a notebook computer, a desktop computer, a smart speaker, a smart watch, etc., but is not limited thereto.
  • embodiments of the present application can be applied to various scenarios, including but not limited to scenarios such as cloud technology, artificial intelligence, intelligent transportation, and assisted driving.
  • the blockchain node can contain the following modules:
  • Transaction pool Stores transactions known in the blockchain network but not yet included in the blockchain.
  • the blockchain node caches the received transactions through the transaction pool, and will send the txNonce equal to the accountNonce of the blockchain account in the current world state and subsequent consecutive txNonce transactions to the consensus module for packaging and consensus block generation.
  • a new block consensus is reached and then inserted into the blockchain structure, it will trigger the refresh operation of the transaction pool, that is, delete the transactions already included in the blockchain.
  • Consensus module Pack transactions to generate candidate blocks, and reach a consensus based on consensus algorithms among each blockchain node to generate new blocks.
  • Blockchain structure a chain structure composed of all blocks connected end to end, storing all transactions of the blockchain system.
  • World state the data set of all accounts after the execution of the transaction in the latest block in the current blockchain structure.
  • Configuration module Store related configurations such as the total upper limit of the transaction pool, the upper limit of a single account, and the upper limit of the number of block transactions.
  • the transaction sent by the blockchain account will be broadcast to all blockchain nodes, but due to problems such as network delays and long transmission distances, the blockchain nodes are not necessarily identified in the order of execution (that is, the above txNonce ) received transactions belonging to the same blockchain account in order from small to large.
  • the blockchain nodes are not necessarily identified in the order of execution (that is, the above txNonce ) received transactions belonging to the same blockchain account in order from small to large.
  • the smallest execution sequence among the execution sequence identifiers corresponding to transactions sent by a certain blockchain account will appear The identification is not equal to the number of currently executed transactions of the blockchain account in the current world state (that is, the above-mentioned accountNonce), or the execution sequence identification corresponding to the transactions sent by a certain blockchain account is not continuous.
  • the block The blockchain nodes in the chain node system can finely manage the transactions cached in the transaction pool.
  • the blockchain node can manage the transactions in the transaction pool according to the dimension of the account, and further divide the transactions sent by the same account into the account preparation queue and the account waiting queue.
  • the pending account as an example, which corresponds to the pending account preparation queue and the pending account waiting queue.
  • the pending account preparation queue is used to store the prepared transaction sent by the pending account and the transaction that has a mapping relationship with the prepared transaction Execution sequence identifier;
  • the pending account waiting queue is used to store pending transactions sent by pending accounts in an unprepared state, and the execution sequence identifier that has a mapping relationship with the pending transaction.
  • the identification relationship between the execution sequence identifiers corresponding to the prepared transactions in the prepared state satisfies the sequence continuity relationship, and the smallest execution order identifier in the pending account preparation queue must be the current completed transaction corresponding to the pending account in the current world state. Execute the same number of trades.
  • the prepared transactions in the pending account preparation queue will be added to the general preparation queue at the same time as they are added to the pending account preparation queue.
  • the prepared transactions sent by other accounts in the blockchain network are in the prepared state. When added to the corresponding account preparation queue, it will also be added to the general preparation queue.
  • Transactions in the total preparation queue will be packaged into candidate blocks in order of transaction insertion time. At this time, the transactions packaged into the candidate block can be executed according to the execution sequence indicated by the execution sequence identifier, and the probability of passing the consensus of the candidate block will increase.
  • the blockchain node when it receives a pending transaction newly sent by the pending account, it can first determine whether the pending transaction is in the prepared state, and if it is determined that the pending transaction is in the prepared state, the pending transaction and the pending The pending execution sequence identifier corresponding to the processing transaction is added to the pending account preparation queue to obtain the transition account preparation queue; then the blockchain node can perform transaction upgrade processing on the pending account waiting queue, that is, in the pending account waiting queue, it will be processed with
  • the pending execution sequence identifier can constitute the execution sequence identifier of the sequence identifier continuous sequence, as the upgrade execution sequence identifier, and the upgrade execution sequence identifier and the waiting transactions corresponding to the upgrade execution sequence identifier are migrated to the transition account preparation queue in order, and the upgrade account preparation queue is obtained , and finally, the blockchain node can add the pending transactions in the upgrade account preparation queue and the waiting transactions corresponding to the upgrade execution order identifier to the general preparation queue for packaging.
  • Figure 2 is a schematic diagram of a blockchain-based data processing scenario provided by the embodiment of this application.
  • the block chain node 20 shown in Figure 2 can be any block chain node in the block chain node system in the embodiment corresponding to Figure 1 above, for example, the block chain node 20 can be a block chain Node 10a.
  • the blockchain node 20 includes a blockchain 21, and the blockchain 21 includes multiple blocks, for example, a block 211, a block 212, and so on.
  • a block may contain multiple transactions sent by different accounts, for example, block 211 contains transaction A2, transaction B1, etc.; block 212 contains transaction A1, etc.
  • transaction A2 and transaction A1 are transactions sent by account A
  • transaction B1 is a transaction sent by account B.
  • the block chain node 20 also contains execution data 22 under the current world state.
  • the current world state refers to the world state of the blockchain network after the block 211 is linked to the blockchain 21, and the world state corresponding to the blockchain network refers to the persistent data owned by each account in the blockchain network.
  • Execution data 22 contains the number of currently executed transactions corresponding to each account in the blockchain network. The transactions contained in the blocks that have been uploaded to the chain are all executed transactions. Therefore, transaction A2, transaction A1, and transaction B1 are all executed transactions. Executed transactions, assuming that other blocks in the blockchain 21 do not contain transactions sent by account A and account B, at this time, the execution data 22 will record that the number of currently executed transactions corresponding to account A is 2, and account B The corresponding number of currently executed transactions is 1.
  • the blockchain node 20 also includes a transaction pool 23 .
  • the transaction pool 23 is used to cache the transactions received by the blockchain nodes 20 and not uploaded to the blockchain 21 .
  • the blockchain node 20 has received the transaction A5 sent by the account A at this time, and the transaction A5 contains the execution sequence identifier 4.
  • the execution order identification 4 means that account A wants transaction A5 to be the fifth executed transaction in the blockchain network, if the execution order of transaction A5 in the blockchain network does not meet the execution order indicated by the execution order identification 4 order, then transaction A5 will be considered an invalid transaction, and the chaining of the block containing transaction A5 will not succeed.
  • the blockchain node 20 After the blockchain node 20 receives the transaction A5, it will be temporarily stored in the transaction pool 23. In order to enable transaction A5 to be executed as the fifth transaction sent by account A in the blockchain, the blockchain node 20 will obtain the account preparation queue 231 and the account waiting queue 232 corresponding to account A. Wherein, the account preparation queue 231 is used to store the preparation transactions in the prepared state, assuming that the account preparation queue 231 includes transaction A3 and the execution sequence identifier 2 corresponding to the transaction A3, and transaction A4 and the execution sequence identifier 3 corresponding to the transaction A4.
  • the execution order of the prepared transactions in the prepared state on the blockchain will be the same as the execution order indicated by the corresponding execution order identification, because transaction A3 and transaction A4 in the account preparation queue 231 will be based on the execution order identification From small to large, they are added to the total preparation queue 230, and the total preparation queue 230 is used to store transactions in the account preparation queue corresponding to all accounts in the blockchain network.
  • the blockchain node 20 will start from the total preparation queue 230 according to Transaction insertion time order packs transactions into blocks. Therefore, in the process of executing the block, the transaction will also be executed in the order of transaction insertion time. That is to say, in the process of packaging and uploading blocks after the blockchain node 20, transaction A3 will be executed first, and then transaction A4 will be executed.
  • transaction A3 will be the third transaction executed by account A in the blockchain network, and the execution order of transaction A3 is the same as the execution order indicated by the execution order identification 2 of transaction A3, so transaction A3 is in the ready state Ready to trade.
  • transaction A4 will be the fourth transaction executed by account A in the blockchain network.
  • the execution order of transaction A4 is the same as the execution order indicated by the execution order indicator 3 of transaction A4, and transaction A4 is also in the ready state ready to trade.
  • the account waiting queue 232 is used to store waiting transactions in an unprepared state.
  • transaction A6 is the fifth transaction executed by account A in the blockchain network, and transaction A6 The execution order of is different from the execution order indicated by the executable ID 5 corresponding to transaction A6, so transaction A6 is a waiting transaction in an unprepared state.
  • the block chain node 20 will determine whether the transaction A5 is in the prepared state, the block chain node 20 will query the account preparation queue 231, and determine that the largest execution order ID contained in it is the execution order identification 3, and the execution order The execution order ID 4 corresponding to ID 3 and transaction A5 satisfies the sequence continuity relationship.
  • transaction A5 is executed after transaction A4, transaction A5 will be the fifth transaction executed by account A in the blockchain network, so The blockchain node 20 can determine that the execution sequence of transaction A5 is the same as the execution sequence indicated by its corresponding execution sequence identifier 4, then transaction A5 is in the ready state, therefore, the blockchain node 20 will correspond transaction A5 to transaction A5
  • the execution sequence identifier 4 of the transaction A5 is added to the account preparation queue 231 of account A to obtain the transitional account preparation queue (not shown in the figure), and the transaction A5 and the execution sequence identifier 4 corresponding to transaction A5 are added to the account preparation of account A
  • the blockchain node 20 can upgrade the transactions in the account waiting queue 232, that is, to judge whether there is any transaction that can be executed according to The corresponding execution sequence identifies the executed execution sequence for execution, and if so, the transaction is migrated from the account waiting queue 232 to the account preparation queue 231 .
  • the execution sequence identifier 6 corresponding to transaction A6 and the execution sequence identifier 5 corresponding to transaction A5 can form a continuous sequence of sequence identifiers, so the blockchain node 20 will migrate transaction A6 and the execution sequence identifier 5 corresponding to transaction A6 Go to the transition account preparation queue to obtain an upgrade account preparation queue 234 and an upgrade account waiting queue 235 . Finally, the blockchain node 20 will add transaction A5 and transaction A6 into the account general preparation queue 230 .
  • the transactions temporarily stored in the transaction pool of the blockchain nodes are managed in a refined manner according to the account dimension, so as to ensure the execution order of the transactions packaged into the block and the execution order contained in it
  • the execution sequence indicated by the logo is the same, which increases the probability of passing the block consensus, thereby increasing the success rate of the block on the chain.
  • FIG. 3 is a schematic flowchart of a blockchain-based data processing method provided by an embodiment of the present application.
  • the method can be executed by a blockchain node (for example, any blockchain node in the blockchain node system in the above-mentioned embodiment corresponding to Figure 1).
  • the following will take this method executed by a blockchain node as an example, wherein the blockchain-based data processing method may at least include the following S101-S104:
  • the execution sequence identifier refers to the txNonce corresponding to the transaction, which is used to identify the transaction execution sequence that the account that sent the transaction expects the transaction to be among the transactions sent by the account, and increments from 0, for example, the execution sequence corresponding to the transaction C3 sent by account C If the flag is 2, account C hopes that transaction C3 will be the third executed transaction in the blockchain network. After transaction C3 is executed, the current number of executed transactions of account C will be 3. Therefore, it can be understood that The next transaction executed by account C should be transaction C4 whose execution order is 3.
  • Blockchain nodes can cache transactions according to the account dimension, for example, further divide pending account transactions into ready Transactions and waiting transactions in the unprepared state, then add the ready transactions in the prepared state and their corresponding execution sequence identifiers to the pending account preparation queue, and add the waiting transactions in the unprepared state and their corresponding execution sequence identifiers Added to the pending account waiting queue.
  • the prepared transaction is in the prepared state, which means that if all the transactions of the accounts to be processed in the transaction pool are executed in ascending order according to the order of execution at this time, all transactions (including transactions) sent by the account to be processed to the blockchain network
  • the execution order in the transactions in the pool and the transactions already on the chain) will be the same as the execution order indicated by the corresponding execution order identifier.
  • Waiting for the transaction to be in the unprepared state means that if all the transactions of the pending accounts in the transaction pool are executed in ascending order according to the execution order at this time, all transactions sent to the blockchain network by the pending accounts (including transactions in the transaction pool) The execution order in the transaction and the transaction already on the chain) will be different from the execution order indicated by the corresponding execution order identification.
  • the transactions in the blockchain nodes need to be packaged into the candidate block, and the transactions in the candidate block can only be executed after the candidate block passes the consensus.
  • the blockchain node When the blockchain node packs the transaction, it obtains the transaction from the general preparation queue according to the order of transaction insertion time, and then packs it to generate a candidate block.
  • the total preparation queue contains the preparation transactions in the account preparation queue corresponding to all accounts in the blockchain network, but the transactions in the preparation transactions of the same account are added based on the order of their execution sequence identification in the account preparation queue into the general preparation queue.
  • the blockchain node only needs to ensure that in the pending account preparation queue, the prepared transactions can be arranged in ascending order of the execution sequence identifier, and the smallest execution sequence identifier in the pending account preparation queue is equal to the pending account in the current world state
  • the corresponding number of currently executed transactions that is, the accountNonce corresponding to the account to be processed, can ensure that when the transaction to be processed is packaged into the candidate block and executed, the transaction to be processed will be included in all transactions sent to the blockchain network by the account to be processed
  • the execution order of is the execution order indicated by its execution order identifier. For example, the accountNonce of account D is 3, which means that three transactions of account D have been executed by the blockchain node.
  • the account preparation queue corresponding to account D contains transaction D4 and the execution sequence identifier 3 corresponding to transaction D4.
  • Transaction D5 and transaction D5 correspond to the execution sequence ID 4, and the blockchain node will add transaction D4 and transaction D5 to the general preparation queue according to the order of execution sequence ID from small to large, then the blockchain node will follow the order of transaction insertion time, Transaction D4 will be packaged into the candidate block first, and then transaction D5 will be packaged into the candidate block, then the subsequent blockchain nodes will execute transaction D4 and transaction D5 in turn, and transaction D4 will be the fourth one executed by account D Transaction, transaction D5 will be the fifth transaction executed by account D, and the execution order corresponding to transaction D4 and transaction D5 is in line with the execution order indicated by their corresponding execution order identifiers.
  • the blockchain node can determine the number of transactions to be processed according to the number of currently executed transactions of the pending account, or according to the relationship between the execution order identification of the pending transaction and the execution order identification in the preparation queue of the pending account Whether the transaction is in the prepared state. If the pending transaction is in the prepared state, directly add the pending transaction and the executable sequence identifier corresponding to the pending transaction into the pending account preparation queue to obtain the transition account preparation queue; if the pending transaction is in the unprepared state, then Add pending transactions and pending execution order identifiers to the pending account waiting queue.
  • a feasible process for determining whether the pending transaction is in the prepared state at this time can be It is: compare the pending execution sequence identifier with the current executed transaction quantity of the pending account; if the pending execution sequence identifier is the same as the pending executed transaction quantity of the pending account, it is determined that the pending transaction is in the prepared state; if If the pending execution sequence identifier is not the same as the number of currently executed transactions of the pending account, it is determined that the pending transaction is in an unprepared state, and the pending transaction and the pending execution sequence identifier are added to the waiting queue of the pending account.
  • the blockchain node receives transaction D5 containing the execution sequence identifier 4 sent by account E, indicating that account E expects transaction D5 to be its fifth At this time, if transaction D5 is added to the account preparation queue, transaction D5 will become the fourth transaction executed by account E, which is inconsistent with the order of execution desired by account E, so transaction D5 is in an unprepared state For waiting transactions, transaction D5 should be added to the account waiting queue for upgrade.
  • a feasible process for determining whether the pending transaction is in the prepared state at this time can be is: if the pending account preparation queue is a non-empty queue, then determine the identity relationship between the pending execution sequence identifier and the largest execution sequence identifier in the pending account preparation queue; if the identifier relationship satisfies the sequence continuity relationship, then determine the pending The transaction is in the prepared state; if the identification relationship does not satisfy the sequential relationship, it is determined that the pending transaction is in the unprepared state, and the pending transaction and the pending execution sequence identifier are added to the pending account waiting queue.
  • the preparation transactions in the pending account preparation queue are all in the prepared state, that is, the preparation transactions can be executed according to the execution sequence indicated by their execution sequence identifiers. If the largest execution sequence identifier in the pending account preparation queue is execution If the sequence ID is 5, the preparation transaction corresponding to the execution sequence ID 5 will be the sixth executed transaction of the pending account. Executed transactions, so the execution sequence ID of the pending transaction should be the execution sequence ID 6, that is to say, the execution sequence ID of the pending transaction should be in a sequential relationship with the execution sequence ID 5, so that the pending transaction can be executed according to it The execution order indicated by the order identifier is executed.
  • the blockchain node can query the pending transaction In the account waiting queue, the execution order identification that can form a continuous sequence of order identification with the pending execution order identification is used as the upgrade execution order identification, and the upgrade execution order identification and the waiting transactions corresponding to the upgrade execution order identification are migrated to the transition account in sequence Prepare queue, get upgrade account prepare queue.
  • the execution order identifiers in the upgrade account preparation queue may constitute a continuous sequence of order identifiers headed by the current number of executed transactions of the account to be processed.
  • each account corresponds to an account preparation queue and an account waiting queue.
  • the blockchain node will add a new preparation transaction to the account preparation queue corresponding to an account at the same time , adding it to the general preparation queue.
  • the blockchain node packs the candidate block, it will obtain transactions from the total preparation queue according to the order of transaction insertion time.
  • the transaction insertion time sequence refers to the time sequence in which transactions are added to the general preparation queue.
  • the blockchain node may also include a total transaction queue, where the total transaction queue is used to record all transactions in the transaction pool, that is to say, the total transaction queue may contain block The ready transactions and waiting transactions corresponding to all accounts in the chain network facilitate the overall query and management of the transaction pool by the blockchain nodes.
  • the blockchain node can also include an account preparation queue hash map and an account waiting queue hash map, wherein the account preparation queue hash map is used for the blockchain node to find the account preparation queue corresponding to the account; the account waiting queue The hash map is used by blockchain nodes to find the account waiting queue corresponding to the account.
  • FIG. 4 is a schematic diagram of queue construction for transaction pool management provided by an embodiment of the present application.
  • the blockchain node can build a total queue containing all transactions in the entire transaction pool, and a total preparation queue for storing all accounts in the prepared state.
  • the account preparation queue and account waiting queue corresponding to each account, and the account preparation queue hash mapping from the account address to the account preparation queue, and the account waiting queue hash mapping from the account address to the account waiting queue are established.
  • the account address is the unique address of the account.
  • the total transaction queue can include transactions and transaction hashes that have a mapping relationship with the transactions, so the total transaction queue can use a HashMap (hash table) hash mapping structure that maps from transaction hashes to transactions.
  • the transaction hash is the unique identifier of the transaction.
  • HashMap is a key value mapping structure, and the traversal order is random reading.
  • the total preparation queue can contain transactions and transaction hashes that have a mapping relationship with transactions, and allows blockchain nodes to store and traverse transactions in the order of transaction insertion time, so the total preparation queue can use the mapping from transaction hash to transaction LinkedHashMap (connected hash table) structure, and stores transactions in the order of insertion time.
  • LinkedHashMap is a key value mapping structure, which will maintain the order of insertion time for sorting, storage and traversal.
  • the account preparation queue needs to contain the preparation transaction and the txNonce that has a mapping relationship with the preparation transaction.
  • the account waiting queue needs to contain the waiting transaction and the txNonce that has a mapping relationship with the waiting transaction, and allows blockchain nodes to store and traverse transactions in order of the size of the txNonce , so both the account preparation queue and the account waiting queue can use the TreeMap (tree list) structure mapped from txNonce to transactions, and sort and store each transaction according to the txNonce field from small to large.
  • TreeMap tree list
  • TreeMap is a key value mapping structure, which will be sorted, stored and traversed according to the size of the key.
  • the account preparation queue hash mapping can use the HashMap structure from the account address to the account preparation queue, and the account waiting queue hash mapping can use the HashMap structure from the account address to the account waiting queue.
  • the blockchain node knows the txNonce of the pending transaction and the account address of the account sending the pending transaction, it can quickly locate the specified transaction in the account preparation queue or account waiting queue.
  • the same transaction may logically appear in the total transaction queue, the total preparation queue, or the account preparation list or the account waiting queue at the same time, but physically refers to the memory pointer of the transaction, and the physical data of the transaction is only A copy is stored in memory to save memory. Therefore, whenever the embodiment of the present application describes that a transaction is in a certain queue, it may mean that the memory pointer of the transaction is in the queue, which will not be described in detail below.
  • the preparation transactions of the pending accounts in the ready state are all stored in the preparation queue of the pending accounts, and the preparation transactions of the pending accounts can be added to the total preparation queue, which can ensure There will be no unprepared waiting transactions in the candidate block generated by the transaction packaging in the preparation queue, which can improve the success rate of the block on the chain.
  • the unprepared transaction sent by the pending account will not be rejected, and will be temporarily stored in the waiting queue of the pending account.
  • the pending account Whenever the pending account has a new transaction in the ready state, it will be added to the pending account
  • the pending account waiting queue is upgraded, and eligible waiting transactions will be added to the pending account preparation queue, and further added to the general preparation queue for packaging, which can enhance the fault tolerance of the blockchain system.
  • FIG. 5 is a schematic flowchart of a blockchain-based data processing method provided by an embodiment of the present application.
  • the method may be executed by a blockchain node (for example, any blockchain node in the blockchain node system in the above-mentioned embodiment corresponding to FIG. 1 ).
  • the following will take this method executed by a blockchain node as an example for illustration, wherein the blockchain-based data processing method may at least include the following 201-S207:
  • the block chain node After the block chain node receives the pending transaction sent by the pending account, it can first determine the cache verification result of the pending transaction. If the block chain node determines that the cache verification result of the pending transaction is a legal cache result, it can The transaction is cached into the transaction pool. If the blockchain node determines that the cache verification result of the transaction to be processed is an illegal cache result, the blockchain node can directly return an error message to the account to be processed.
  • a feasible implementation method for determining the cache verification result of transactions to be processed may be: obtain the total number of transactions in the total transaction queue; obtain the upper limit threshold of the total number of transactions; if the total number of transactions is equal to the total number of transactions If the upper limit threshold of the transaction quantity is exceeded, an error message of the transaction upper limit will be returned to the account to be processed; if the total transaction quantity is less than the upper limit threshold of the total transaction quantity, the cache verification result of the pending transaction will be determined to be a legal cache result.
  • the total number of transactions is the number of transactions contained in the total transaction queue, that is, the number of transactions cached in the transaction pool at this time. It should be understood that the capacity of the transaction pool is limited.
  • the blockchain node When the cached transactions in the transaction pool reach the upper limit, the blockchain node cannot add pending transactions to the transaction pool. At this time, the blockchain node can only send transactions to pending accounts Upper limit error message.
  • the upper limit of the capacity of the transaction pool can be configured through the configuration module of the blockchain node.
  • a feasible implementation method for determining the cache verification result of transactions to be processed may be: obtain the upper threshold of the account transaction quantity; If the upper limit threshold is exceeded, an error message will be sent to the account to be processed; if the sum of the number of ready transactions and the number of waiting transactions is less than the upper limit of account transactions, then the cache verification result of the pending transaction is determined to be a legal cache result.
  • the upper threshold of the number of account transactions refers to the maximum number of transactions that can be cached in the transaction pool for the account to be processed, which can be configured through the configuration module of the blockchain node. It should be understood that the transactions cached by the account to be processed in the transaction pool include ready transactions and waiting transactions. When the upper limit is reached, but the blockchain node receives the pending transaction sent by the pending account, it will still not cache it, but will return the transaction upper limit error message to the pending account.
  • a feasible implementation method for determining the cache verification result of the transaction to be processed may be: obtain the current number of executed transactions of the account to be processed; if the pending execution sequence identifier is less than the number of currently executed transactions , then send the transaction outdated error message to the account to be processed; if the execution sequence identifier to be processed is greater than or equal to the number of currently executed transactions, then it is determined that the cache verification result of the pending transaction is a legal cache result.
  • a feasible implementation method for determining the cache verification result of the transaction to be processed may be: obtain the transaction execution cost of the transaction to be processed, query the account resource of the account to be processed; if the account resource is less than the transaction execution overhead, send an error message of insufficient resources to the account to be processed; if the account resource is greater than or equal to the transaction execution overhead, then determine that the cache verification result of the pending transaction is a legal cache result.
  • the transaction execution cost refers to the digital resources that the pending account is willing to provide for the execution of the transaction
  • the account resource refers to the digital resources owned by the pending account in the blockchain network.
  • the blockchain node can simultaneously perform the above-mentioned multiple feasible implementation methods to determine the cache verification result of the pending transaction. At this time, the pending transaction needs to satisfy the verification of multiple feasible implementation methods at the same time.
  • Blockchain The node can determine that the cache verification result of the transaction to be processed is a legal cache result.
  • the cache verification result of the transaction to be processed is a legal cache result
  • obtain the pending account preparation queue and the pending account waiting queue corresponding to the pending account the pending account preparation queue is used to store the Prepared transactions in the prepared state, and execution order identifiers that have a mapping relationship with the prepared transactions
  • the pending account waiting queue is used to store waiting transactions that are in the unprepared state, and execution that has a mapping relationship with the waiting transactions Order ID.
  • the account to be processed After the account to be processed sends a transaction carrying a certain execution order identifier, there is a certain time difference until the transaction is packaged into the candidate block. During this period, if the account to be processed wants to execute the execution order indicated by the execution order For other transactions, the account to be processed can send a transaction that also includes the execution sequence identifier to the blockchain node, and the blockchain node may obtain multiple transactions with the same execution sequence identifier. However, the blockchain node will only select the optimal transaction or the transaction that the pending account most wants to execute from multiple transactions with the same execution sequence ID, and the remaining transactions will be discarded.
  • the block chain node After the block chain node receives the pending transaction, it needs to determine whether the pending account preparation queue corresponding to the pending account already contains the preparation transaction with the pending execution sequence identifier, or whether the pending account waiting queue already contains There are pending transactions with pending execution order IDs.
  • the conflicting transaction and the pending transaction have the same pending execution sequence identifier.
  • the blockchain node needs to determine whether the conflicting coverage condition is satisfied between the pending transaction and the conflicting transaction. If the conflicting coverage condition is satisfied between the pending transaction and the conflicting transaction, then Based on the pending transaction, the conflicting transaction is overwritten. If the conflicting coverage condition is not satisfied between the pending transaction and the conflicting transaction, the blockchain node will discard the pending transaction.
  • a feasible implementation method for the blockchain node to determine whether the conflict coverage condition is satisfied between the pending transaction and the conflicting transaction can be: obtaining the transaction execution cost of the pending transaction and obtaining the conflicting transaction Transaction execution overhead; if the transaction execution overhead of the pending transaction is greater than the transaction execution overhead of the conflicting transaction, it is determined that the conflict coverage condition is satisfied between the pending transaction and the conflicting transaction; if the transaction execution overhead of the pending transaction is less than or equal to the transaction of the conflicting transaction If the overhead is executed, it is determined that the conflict coverage condition is not satisfied between the pending transaction and the conflicting transaction, and an error message of transaction coverage failure is sent to the pending account.
  • the transaction execution cost refers to the digital resources that the pending account is willing to provide for the blockchain network to execute the transaction. Therefore, the transaction with a higher transaction execution cost is naturally the transaction that the pending account is more willing to execute. At this time, the blockchain The node will overwrite the conflicting transaction with the pending transaction.
  • a feasible implementation method for overriding conflicting transactions based on pending transactions may be: if the pending queue is the pending account preparation queue, then in the pending account preparation queue, the conflict The transaction is replaced with a pending transaction. In the general preparation queue, the conflicting transaction is replaced with a pending transaction; if the pending queue is a pending account waiting queue, the conflicting transaction is replaced with a pending transaction in the pending account waiting queue .
  • blockchain nodes can delete the conflicting transaction in the transaction pool.
  • the account to be processed After the account to be processed sends a transaction with a pending execution sequence identifier, it can overwrite the transaction by sending a pending transaction with the same pending execution sequence identifier at a higher transaction execution cost.
  • Previously sent transactions improve the flexibility of blockchain use, and replace previously sent transactions with pending transactions in the queue containing previously sent transactions, without disrupting the order of other transactions to be executed, improving transaction packaging effectiveness.
  • FIG. 6 is a schematic flowchart of a blockchain-based data processing method provided by an embodiment of the present application.
  • the method may be executed by a blockchain node (for example, any blockchain node in the blockchain node system in the above-mentioned embodiment corresponding to FIG. 1 ).
  • the following will take this method executed by a blockchain node as an example for illustration, wherein the blockchain-based data processing method may at least include the following 301-S306:
  • Candidate blocks can be generated by blockchain nodes, or generated by other blockchain nodes and then broadcast to blockchain nodes.
  • the blockchain node When the blockchain node has the authority to generate blocks, it can obtain transactions from the general preparation queue in the order of transaction insertion time, and then package them in turn to generate candidate blocks.
  • the number of transactions in the block needs to be less than or equal to the threshold of the number of transactions in the block, where the threshold of the number of transactions in the block refers to the maximum number of transactions that can be included in the block, which can be configured through the configuration module.
  • the blockchain node can perform consensus processing on the candidate block together with other consensus nodes. After the consensus is passed, the candidate block is executed, that is, all transactions in the candidate block are executed, and then the transaction execution including all transactions and all transactions is obtained. The resulting new block.
  • the new block will be inserted into the existing blockchain structure to obtain a new blockchain, and the account resources corresponding to the accounts in the new blockchain will also change, resulting in a new world state.
  • Blockchain nodes can still delete transactions according to the dimension of the account, that is, according to the transactions in the block, determine the maximum execution order identifier corresponding to each account, and then delete the ready transactions and waiting transactions of each account. Taking the account to be processed as an example, it is assumed that the blockchain node traverses the block to obtain the maximum execution sequence identifier of the account to be processed.
  • the blockchain node can obtain the pending account preparation queue corresponding to the pending account, and then search for the execution sequence identifier that is less than or equal to the maximum execution sequence identifier from the pending account preparation queue, and use the found execution sequence identifier as the first pending Delete the execution sequence flag. Then, the block chain node can use the preparation transaction in the pending account preparation queue that has a mapping relationship with the first execution sequence identifier to be deleted as the preparation transaction to be deleted.
  • the blockchain node can delete the preparation transaction to be deleted and the first execution sequence identifier to be deleted in the pending account preparation queue to obtain the updated account preparation queue; and delete the pending transaction in the total preparation queue To prepare a transaction, get an update to the total prepare queue.
  • the blockchain node can obtain the pending account waiting queue corresponding to the account to be processed, and then search for the execution sequence identifier that is less than or equal to the maximum execution sequence identifier from the pending account waiting queue, and use the found execution sequence identifier as the second pending Delete the execution sequence flag. Then, the block chain node can take the waiting transaction in the waiting queue of the pending account that has a mapping relationship with the second execution sequence identifier to be deleted as the waiting transaction to be deleted.
  • the block chain node can delete the waiting transaction to be deleted and the second execution sequence identifier to be deleted in the pending account waiting queue to obtain the updated account waiting queue.
  • the blockchain node can upgrade the update account waiting queue, that is, determine whether the ready state of the waiting transaction in the update account waiting queue occurs at this time Change, and the waiting transactions whose preparation state has changed to the ready state are migrated from the update account waiting queue to the update account preparation queue.
  • a feasible implementation method of the upgrade process can be as follows: the blockchain node obtains the minimum execution sequence identifier in the update account waiting queue; generates the optimized execution sequence identifier according to the maximum execution sequence identifier; if the minimum execution sequence identifier is equal to the optimized execution sequence identifier , then in the waiting queue of accounts to be processed, the execution order identification that can form a sequence identification continuous sequence with the minimum execution order identification is used as the optimization upgrade execution order identification, and the minimum execution order identification, the minimum execution order identification corresponding to the waiting transactions, optimization
  • the waiting transactions corresponding to the upgrade execution sequence identifier and the optimized upgrade execution sequence identifier are migrated to the update account preparation queue in order to obtain the optimized upgrade account preparation queue;
  • the waiting transactions corresponding to the optimization and upgrade execution order identifiers are added to the update general preparation queue in order to obtain the optimization and upgrade general preparation queue.
  • the process of generating the optimal execution sequence identifier according to the maximum execution sequence identifier is: adding one to the maximum execution sequence identifier to obtain the
  • the maximum execution sequence ID of account A contained in the new block is execution sequence ID 6, and the optimized execution sequence ID is execution sequence ID 7, assuming that the block chain node is not greater than the maximum execution sequence in the deletion account waiting queue
  • the updated account waiting queue obtained includes transaction 7 and execution order ID 7 corresponding to transaction 7, execution order ID 8 corresponding to transaction 8 and transaction 8, and transaction 10 and transaction 10
  • the execution order identification and optimized execution order identification corresponding to transaction 7, the execution order identification 7 and the execution order identification 8 can form a continuous sequence of order identification, so the block chain node will use the execution order identification 8 as the optimization Upgrade the execution sequence ID, and then migrate transaction 7, the execution sequence ID 7 corresponding to transaction 7, transaction 8, and the execution sequence ID 8 corresponding to transaction 8 to the update account preparation queue in sequence.
  • the blockchain node can delete the preparation transaction with insufficient balance, that is, the blockchain node can obtain the minimum execution sequence identifier corresponding to the update account preparation queue Prepare the transaction as a pending transaction; then obtain the transaction execution cost of the pending transaction; query the account resources of the account to be processed; if the transaction execution cost of the pending transaction is greater than the account resource, delete the pending transaction from the update account preparation queue Determine the preparation transaction and the minimum execution sequence identifier, delete the pending preparation transaction from the update total preparation queue; in the deleted update account preparation queue, use the execution sequence identifier greater than the minimum execution sequence identifier as the downgraded execution sequence identifier, and downgrade
  • the preparation transaction corresponding to the execution order identifier and the downgraded execution order identifier is migrated to the update account waiting queue, and the downgrade account waiting queue is obtained; the preparation transaction corresponding to the downgrade execution order identifier and the downgrade execution order identifier is deleted from the update account preparation queue after
  • the preparation transaction corresponding to the minimum execution sequence identifier will be the first transaction executed by the account to be processed in the candidate block.
  • the digital resources are not enough to support the transaction execution overhead required for the preparation transaction corresponding to the minimum execution order identification, and the consensus of the candidate block will fail. Therefore, the blockchain node can first judge the preparation transaction corresponding to the minimum execution order identification. If the pending account If the balance is insufficient, delete the preparation transaction corresponding to the minimum execution order identifier.
  • the blockchain node can first migrate other transactions in the update account preparation queue back to the account waiting queue for waiting.
  • the time-consuming operation of refreshing the transaction pool when adding a new block is not affected by the size of the transaction pool, but only related to the size of the block, which improves the efficiency of the transaction pool refresh operation.
  • FIG. 7 is a schematic flowchart of a method for receiving a transaction provided by an embodiment of the present application.
  • the transaction receiving method may be executed by a blockchain node (for example, any blockchain node in the blockchain node system in the above embodiment corresponding to FIG. 1 ).
  • the blockchain node may include the transaction pool, consensus module, blockchain structure, world state and configuration module described in the above-mentioned embodiment corresponding to FIG. 1 .
  • the blockchain node can construct the account preparation queue hash map, account waiting queue hash map, account preparation queue, account waiting queue, total preparation queue, and transaction total queue described in the embodiment corresponding to FIG. 4 above based on the transaction pool.
  • the blockchain node after the blockchain node receives the pending transaction sent by the pending account, it will perform the following operations:
  • the blockchain node can judge whether the number of transactions in the total transaction queue (also called the total number of transactions) has exceeded the upper limit according to the total upper limit of the transaction pool in the configuration module (also called the upper limit of the total number of transactions), and if it exceeds, send An error is reported for the account to be processed, and the pending transaction is not cached; if it is not exceeded, S702 is executed.
  • the blockchain node can obtain the account address in the pending transaction according to the upper limit of a single account in the configuration module, and then find the account preparation queue and account waiting queue corresponding to the pending account according to the hash map of the account preparation queue and the hash map of the account waiting queue. Queue, determine whether the sum of the number of ready transactions and the number of waiting transactions contained in the two has exceeded the upper limit of a single account (also known as the upper limit threshold of the number of account transactions), and if it exceeds, an error will be reported to the account to be processed, and the pending transaction will not be cached transaction; if not exceeded, execute S703.
  • the upper limit of a single account also known as the upper limit threshold of the number of account transactions
  • the blockchain node needs to verify whether the transaction to be processed is outdated. If the txNonce of the transaction to be processed is not less than the accountNonce of the account to be processed in the current world state, it is determined that the transaction is not outdated, and the execution of S704 is continued; Report an error, do not cache pending transactions.
  • the blockchain node can query the account balance (also called account resource) of the account to be processed in the current world state according to the account address carried by the pending transaction. If the account balance is less than the txFee of the pending transaction (also called transaction execution overhead ) reports an error to the account to be processed, and does not cache the transaction; if the account balance is not less than the txFee of the transaction, then execute S705.
  • account balance also called account resource
  • txFee of the pending transaction also called transaction execution overhead
  • the blockchain node can obtain the account preparation queue and account waiting queue corresponding to the pending account according to the account address carried by the pending transaction, and then the blockchain node will determine whether there are any For transactions with the same txNonce, if there is a transaction with the same txNonce, it is determined as a conflicting transaction, and S706 is executed. If there is no transaction with the same txNonce, execute S712.
  • the blockchain node can obtain the txFee of the pending transaction and the txFee of the conflicting transaction. If the txFee of the pending transaction is not greater than the txFee of the conflicting transaction, an error will be reported and the pending transaction will not be cached; if the txFee of the pending transaction is greater than the txFee of the conflicting transaction , execute S707.
  • the blockchain node looks up whether there is a transaction with the same txNonce in the account preparation queue and account waiting queue corresponding to the pending account. If it is found in the account preparation queue, it is determined that the pending transaction has been prepared , execute S708; if it is found in the account waiting queue, it is determined that the pending transaction is not prepared, and execute S710.
  • the blockchain node deletes the conflicting transaction in the account preparation queue corresponding to the pending account according to the account address and txNonce included in the pending transaction, adds the pending transaction to the account preparation queue, and then executes S709.
  • the blockchain node can delete the conflicting transaction and the transaction hash of the conflicting transaction in the total preparation queue, add the pending transaction and the transaction hash of the pending transaction to the total preparation queue, and then Execute S711.
  • the blockchain node deletes the conflicting transaction in the account waiting queue corresponding to the pending account, adds the pending transaction to the account waiting queue, and then executes S711.
  • the blockchain node deletes the conflicting transaction and the transaction hash of the conflicting transaction in the general transaction queue, and adds the pending transaction and the transaction hash of the pending transaction to the general transaction queue. The transaction is received and the process ends.
  • the blockchain node searches for the account preparation queue corresponding to the pending account according to the account address contained in the transaction to be processed.
  • the transaction has been prepared and needs to be satisfied: the account preparation queue is empty, and the txNonce of the pending transaction is equal to that of the pending account in the current world state accountNonce; or, the account preparation queue is not empty, and the txNonce of the pending transaction is equal to the txNonce of the last transaction in the account preparation queue plus 1. If the transaction to be processed has been prepared, execute S713; if the transaction to be processed is not prepared, execute S716.
  • the blockchain node will add the pending transaction and the txNonce corresponding to the pending transaction to the tail of the account preparation queue, that is, the pending transaction will become the last transaction in the account preparation queue, and then execute S714.
  • the blockchain node will check whether there are transactions that can be upgraded in the account waiting queue, and then upgrade the transactions that can be upgraded. Among them, upgrading refers to moving the transaction from the account waiting queue to the account preparation queue. The blockchain node will continue to execute S715.
  • the blockchain node determines whether there is a transaction that can be upgraded, and a feasible method for upgrading it is: the blockchain node can start the cycle from the first transaction in the account waiting queue, and judge Whether the txNonce of the transaction is equal to the txNonce of the last transaction in the account preparation queue plus 1, if so, delete the transaction from the account preparation queue and add it to the account preparation queue (it will become the last transaction in the account preparation queue), And record the transaction that has been upgraded.
  • the blockchain node determines whether there is a transaction that can be upgraded, and a feasible method for upgrading it is: when the transaction in the account waiting queue is in order from small to large according to the txNonce corresponding to the transaction
  • the blockchain node can judge whether the txNonce of the first transaction in the account waiting queue is equal to the txNonce of the last transaction in the account preparation queue plus 1, and if so, it will correspond to the first transaction in the account waiting queue
  • the transactions corresponding to the txNonce that can form a sequential sequence of txNonce are all determined as upgrade transactions, and the upgrade transactions are added to the account preparation queue.
  • the blockchain node will add the pending transaction and the upgraded transaction to the general preparation queue, and then execute S717.
  • the blockchain node will add the pending transaction and the txNonce corresponding to the pending transaction to the account waiting queue, and then execute S717.
  • the transaction that txNonce is not prepared can be effectively received and cached, and the transaction will be packaged normally after the txNonce is ready, so as to improve the fault tolerance of the blockchain system and ensure that the transaction is packaged when the candidate block is generated.
  • the effective matching between txNonce and accountNonce of the transaction improves the success rate of block generation.
  • it supports the same account to send transaction requests with a higher txFee, covering transactions with the same nonce in the transaction pool, and improving the flexibility of users to use the blockchain.
  • the blockchain node with the authority to produce blocks can start from the first transaction in the total preparation queue, and then package each transaction into the candidate block one by one, but the final number of packaged transactions should not be greater than the configuration module The upper limit of the number of block transactions in the block.
  • each blockchain node in the blockchain node system can execute the operation of refreshing the transaction pool.
  • FIG. 8 is a schematic flow chart of refreshing a transaction pool provided by an embodiment of the present application. As shown in Figure 8, the process of refreshing the transaction pool includes:
  • the blockchain node can traverse each transaction in the new block, find out the maximum txNonce of each account, establish a hash map from the account address to the maximum txNonce of the account, traverse the hash map, and for each account address and its For the maximum txNonce of the account, execute the following S802 to S805 respectively.
  • the blockchain node searches the account preparation queue and account waiting queue corresponding to the account according to the account address, deletes the transactions whose txNonce is not greater than the maximum txNonce of the account, and deletes the transactions in the total preparation queue and the total queue according to the transaction hash of the deleted transaction , continue to execute S803.
  • the blockchain node can search the corresponding account waiting queue according to the account address, and judge whether the txNonce of the first transaction in the account waiting queue is equal to the maximum txNonce of the account plus 1. If it is equal, the transaction will be upgraded and the subsequent txNonce in the account waiting queue will be continuous For a series of transactions, upgrading refers to deleting the transaction from the account waiting queue, adding it to the account preparation queue and the total preparation queue, and then continuing to execute S804.
  • the blockchain node can look up the corresponding account preparation queue according to the account address, and judge whether the txFee of the first transaction in the account preparation queue is greater than the account balance of the account to which it belongs in the current world state. If it is greater, the transaction will be removed from the account preparation queue, delete from the total preparation queue and the total queue, and continue to execute S805.
  • the blockchain node For the account of the transaction deleted due to insufficient account balance, the blockchain node will downgrade all the transactions in its account preparation queue. Downgrading refers to deleting the transaction from the general preparation queue and account preparation queue and adding it to the account waiting queue. The process is complete.
  • the time-consuming operation of refreshing the transaction pool when adding a new block is not affected by the size of the transaction pool, but only related to the size of the block, which improves the efficiency of the transaction pool refresh operation.
  • FIG. 9 is a schematic structural diagram of a data processing device provided by an embodiment of the present application.
  • the data processing device may be a computer program (including program code) running on a computer device, for example, the data processing device is an application software; the device may be used to execute the corresponding steps in the data processing method provided by the embodiment of the present application.
  • the data processing device 1 may include: an acquisition module 101 , a transaction transition module 102 , a transaction upgrade module 103 and a transaction addition module 104 .
  • the obtaining module 101 is used to obtain the pending transaction sent by the pending account, and obtain the pending account preparation queue and the pending account waiting queue corresponding to the pending account; the pending transaction includes the pending execution order identifier; the pending account preparation queue It is used to store the prepared transactions in the prepared state and the execution sequence identifiers that have a mapping relationship with the prepared transactions; the pending account waiting queue is used to store the waiting transactions that are in the unprepared state and the execution sequence identifiers that have a mapping relationship with the waiting transactions ;
  • Transaction transition module 102 for if it is determined that the transaction to be processed is in the prepared state, then add the transaction to be processed and the execution sequence identifier to be processed to the pending account preparation queue to obtain the transition account preparation queue;
  • the transaction upgrade module 103 is configured to use the execution sequence identifier that can form a continuous sequence of sequence identifiers with the execution sequence identifier to be processed in the pending account waiting queue as the upgrade execution sequence identifier, and use the upgrade execution sequence identifier and the upgrade execution sequence identifier The corresponding waiting transactions are migrated to the transition account preparation queue in order to obtain the upgrade account preparation queue;
  • the transaction adding module 104 is used to add the pending transactions in the upgrade account preparation queue and the waiting transactions corresponding to the upgrade execution sequence identifier to the total preparation queue; the transactions in the total preparation queue will be packaged into the candidate area according to the order of transaction insertion time piece.
  • the specific implementation manners of the acquisition module 101, the transaction transition module 102, the transaction upgrade module 103 and the transaction addition module 104 can refer to the description of S101-S104 in the embodiment corresponding to FIG. 3 above, and will not be repeated here.
  • the above data processing device 1 further includes: a first state determination module 105 .
  • the first state determination module 105 is used to compare the pending execution sequence identification with the currently executed transaction identification of the pending account if the pending account preparation queue is an empty queue;
  • the first state determination module 105 is also used to determine that the transaction to be processed is in a ready state if the pending execution sequence identifier is the same as the currently executed transaction identifier of the account to be processed;
  • the first state determination module 105 is also used to determine that the transaction to be processed is in an unprepared state if the pending execution sequence identifier is different from the current executed transaction identifier of the account to be processed, and add the pending transaction and the pending execution sequence identifier to To the pending account waiting queue.
  • the data processing device 1 above further includes: a second state determination module 106 .
  • the second state determination module 106 is used to determine the identification relationship between the pending execution sequence identifier and the largest execution sequence identifier in the pending account preparation queue if the pending account preparation queue is a non-empty queue;
  • the second state determination module 106 is also used to determine that the transaction to be processed is in the prepared state if the identification relationship satisfies the sequential and continuous relationship;
  • the second state determination module 106 is further configured to determine that the transaction to be processed is in an unprepared state if the identification relationship does not satisfy the sequence continuity relationship, and add the transaction to be processed and the execution sequence identification to be processed to the account waiting queue to be processed.
  • the data processing apparatus 1 above further includes: a traversal module 107 , a conflict determination module 108 , a first covering module 109 and a second covering module 110 .
  • the traversal module 107 is used for traversing the pending account preparation queue and the pending account waiting queue according to the execution sequence to be processed to obtain the traverse result for the pending transaction;
  • the conflict determination module 108 is also used to determine the transaction with the pending execution sequence identifier in the pending queue as a conflicting transaction if the traversal result indicates that there is a transaction with the pending execution sequence identifier in the pending queue; the pending queue Prepare queue for pending accounts or wait queue for pending accounts;
  • the first covering module 109 is configured to perform covering processing on the conflicting transaction based on the pending transaction if it is determined that the conflict covering condition is satisfied between the pending transaction and the conflicting transaction;
  • the second coverage module 110 is used to call the transaction transition module to execute if the transaction to be processed and the conflicting transaction do not meet the conflict coverage condition. Added to the pending account preparation queue to get the steps for the transition account preparation queue.
  • the traversal module 107 For specific implementations of the traversal module 107, the conflict determination module 108, the first covering module 109, and the second covering module 110, reference may be made to the description of S203-S205 in the embodiment corresponding to FIG.
  • the above-mentioned data processing device 1 further includes: a coverage determination module 111 .
  • Coverage determination module 111 configured to obtain the transaction execution cost of the transaction to be processed, and obtain the transaction execution cost of the conflicting transaction;
  • the coverage determination module 111 is further configured to determine that the conflict coverage condition is satisfied between the pending transaction and the conflicting transaction if the transaction execution overhead of the transaction to be processed is greater than the transaction execution overhead of the conflicting transaction;
  • the coverage determination module 111 is also used to determine that the conflict coverage condition is not satisfied between the pending transaction and the conflicting transaction if the transaction execution cost of the transaction to be processed is less than or equal to the transaction execution cost of the conflicting transaction, and send a transaction coverage failure to the account to be processed Error message.
  • the first covering module 109 includes: a first replacement unit 1091 and a second replacement unit 1092 .
  • the first replacement unit 1091 is configured to replace the conflicting transaction with the pending transaction in the pending account preparation queue if the pending queue is the pending account preparation queue, and replace the conflicting transaction with the pending transaction in the general preparation queue trade;
  • the second replacement unit 1092 is configured to replace the conflicting transaction with the pending transaction in the pending account waiting queue if the pending queue is the pending account waiting queue.
  • the above-mentioned data processing device 1 further includes: a first transaction processing module 112 .
  • the first transaction processing module 112 is configured to obtain an upper limit threshold of account transaction quantity
  • the first transaction processing module 112 is further configured to send a transaction to the account to be processed if the sum of the number of ready transactions in the pending account preparation queue and the number of waiting transactions in the pending account waiting queue is equal to the account transaction quantity upper limit threshold Upper limit error message;
  • the first transaction processing module 112 is also used to call the transaction transition module to execute if the transaction to be processed is in the prepared state, then the transaction to be processed and The pending execution sequence identifier is added to the pending account preparation queue to obtain the steps of the transition account preparation queue.
  • the above-mentioned data processing device 1 further includes: a second transaction processing module 113 .
  • the second transaction processing module 113 is used to obtain the current executed transaction quantity of the account to be processed
  • the second transaction processing module 113 is also used to send transaction outdated error message to the account to be processed if the pending execution sequence identifier is less than the current executed transaction quantity;
  • the second transaction processing module 113 is also used to call the transaction transition module to execute if the pending execution sequence identifier is greater than or equal to the number of currently executed transactions.
  • the sequence identifier is added to the pending account preparation queue to obtain the steps of the transition account preparation queue.
  • the above-mentioned data processing device 1 further includes: a third transaction processing module 114 .
  • the third transaction processing module 114 is used to obtain the transaction execution cost of the transaction to be processed, and query the account resource of the account to be processed;
  • the third transaction processing module 114 is also used to send an error message of insufficient resources to the account to be processed if the account resource is less than the transaction execution cost;
  • the third transaction processing module 114 is also used to call the transaction transition module to execute if the account resource is greater than or equal to the transaction execution cost. Pending account preparation queue, get the steps of transition account preparation queue.
  • the above-mentioned data processing device 1 further includes: a transaction packaging module 115 and a queue updating module 116 .
  • the transaction packaging module 115 is used to package the transactions in the total preparation queue into the candidate block according to the order of transaction insertion time; the transaction quantity in the candidate block is less than or equal to the block transaction quantity threshold;
  • the queue update module 116 is used for performing consensus processing on the candidate block, obtaining a new block, traversing the new block, and obtaining the maximum execution sequence identification of the account to be processed;
  • the queue update module 116 is also used to obtain, in the pending account preparation queue, a preparation transaction that has a mapping relationship with the first execution sequence identifier to be deleted as a preparation transaction to be deleted; the first execution sequence identifier to be deleted is an account preparation to be processed Execution sequence identifiers in the queue that are less than or equal to the maximum execution sequence identifier;
  • the queue update module 116 is also used to delete the preparation transaction to be deleted and the first execution sequence identifier to be deleted in the account preparation queue to be processed, so as to obtain an updated account preparation queue;
  • the queue update module 116 is also used to delete the preparation transaction to be deleted in the total preparation queue, so as to obtain an updated total preparation queue;
  • the queue update module 116 is also used to obtain, in the pending account waiting queue, a waiting transaction that has a mapping relationship with the second execution order identifier to be deleted, as a waiting transaction to be deleted; the second execution order identifier to be deleted is an account waiting to be processed Execution sequence identifiers in the queue that are less than or equal to the maximum execution sequence identifier;
  • the queue update module 116 is further configured to delete the waiting transaction to be deleted and the second execution sequence identifier to be deleted in the waiting queue of accounts to be processed, so as to obtain the waiting queue of updated accounts.
  • the specific implementation manners of the transaction packaging module 115 and the queue updating module 116 can refer to the description of S301-S306 in the above embodiment corresponding to FIG. 6 , which will not be repeated here.
  • the above-mentioned data processing device 1 further includes: a queue optimization module 117 .
  • Queue optimization module 117 configured to obtain the minimum execution sequence identifier in the update account waiting queue
  • the queue optimization module 117 is also used to generate an optimized execution sequence identifier according to the maximum execution sequence identifier
  • Queue optimization module 117 is also used to if the minimum execution sequence identifier is equal to the optimization execution sequence identifier, then in the pending account waiting queue, the execution sequence identifier that can form a sequence identifier continuous sequence with the minimum execution sequence identifier is used as the optimization upgrade execution sequence ID, migrating the minimum execution sequence identifier, the waiting transactions corresponding to the minimum execution sequence identifier, the optimized and upgraded execution sequence identifier, and the waiting transactions corresponding to the optimized and upgraded execution sequence identifier to the update account preparation queue to obtain the optimization and upgrade account preparation queue;
  • the queue optimization module 117 is also used to add the minimum execution sequence identifier, the waiting transactions corresponding to the minimum execution sequence identifier, the optimization and upgrade execution sequence identifier, and the waiting transactions corresponding to the optimization and upgrade execution sequence identifier to the update total preparation queue in order to obtain optimized Upgrade the general preparation queue.
  • the specific implementation manner of the queue optimization module 117 can refer to the description of the optional embodiment in the embodiment corresponding to FIG. 6 above, and details are not repeated here.
  • the above-mentioned data processing device 1 further includes: a queue deletion module 118 .
  • the queue deletion module 118 is configured to obtain the preparation transaction corresponding to the minimum execution sequence identifier in the update account preparation queue as the preparation transaction to be determined;
  • the queue deletion module 118 is also used to obtain the transaction execution cost of the transaction to be determined and to query the account resource of the account to be processed;
  • the queue deletion module 118 is also used to delete the pending preparation transaction and the minimum execution sequence identifier from the update account preparation queue, and delete the pending preparation transaction from the update total preparation queue if the transaction execution cost of the pending preparation transaction is greater than the account resource ;
  • the queue deletion module 118 is also configured to use the execution order identification greater than the minimum execution order identification in the deleted update account preparation queue as the downgraded execution order identification, and use the downgraded execution order identification and the downgraded execution order identification corresponding preparation transaction Migrate to update account waiting queue, get downgraded account waiting queue;
  • the queue deletion module 118 is also used to delete the downgraded execution sequence identifier and the preparation transaction corresponding to the downgraded execution sequence identifier from the deleted update account preparation queue;
  • the queue deletion module 118 is further configured to delete the downgraded execution sequence identifier and the preparation transaction corresponding to the downgraded execution order identifier from the deleted update general preparation queue.
  • queue deletion module 118 For the specific implementation manner of the queue deletion module 118, reference may be made to the description of the optional embodiment in the embodiment corresponding to FIG. 6 above, and details are not repeated here.
  • FIG. 10 is a schematic structural diagram of a computer device provided by an embodiment of the present application.
  • the data processing apparatus 1 in the embodiment corresponding to FIG. 9 above can be applied to a computer device 1000, and the computer device 1000 can include: a processor 1001, a network interface 1004 and a memory 1005.
  • the above-mentioned computer device 1000 It may also include: a user interface 1003 , and at least one communication bus 1002 .
  • the communication bus 1002 is used to realize connection and communication between these components.
  • the user interface 1003 may include a display screen (Display) and a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface.
  • the network interface 1004 may include a standard wired interface and a wireless interface (such as a WI-FI interface).
  • the memory 1005 can be a high-speed RAM memory, or a non-volatile memory, such as at least one disk memory.
  • the memory 1005 may also be at least one storage device located away from the aforementioned processor 1001 .
  • the memory 1005 as a computer-readable storage medium may include an operating system, a network communication module, a user interface module, and a device control application program.
  • the network interface 1004 can provide network communication elements;
  • the user interface 1003 is mainly used to provide an input interface for the user; and
  • the processor 1001 can be used to call the device control stored in the memory 1005 application to:
  • the pending transaction contains the pending execution sequence identifier;
  • the pending account preparation queue is used to store the Prepared transactions in status and execution sequence identifiers that have a mapping relationship with the prepared transactions;
  • pending account waiting queues are used to store pending transactions that are not in the ready state and execution sequence identifiers that have a mapping relationship with the pending transactions;
  • the execution sequence identifier that can form a sequence identifier continuous sequence with the pending execution sequence identifier is used as the upgrade execution sequence identifier, and the upgrade execution sequence identifier and the waiting transactions corresponding to the upgrade execution sequence identifier are added in order Go to the transition account preparation queue to get the upgrade account preparation queue;
  • the embodiment of the present application also provides a computer-readable storage medium, and the above-mentioned computer-readable storage medium stores the computer program executed by the aforementioned data processing device 1, and the above-mentioned computer
  • the program includes program instructions.
  • the processor executes the program instructions, it can execute the description of the data processing method in any one of the foregoing embodiments, so details will not be repeated here.
  • the description of the beneficial effect of adopting the same method will not be repeated here.
  • the above-mentioned computer-readable storage medium may be the data processing apparatus provided in any one of the foregoing embodiments or an internal storage unit of the above-mentioned computer equipment, such as a hard disk or memory of the computer equipment.
  • the computer-readable storage medium may also be an external storage device of the computer device, such as a plug-in hard disk equipped on the computer device, a smart memory card (smart media card, SMC), a secure digital (secure digital, SD) card, Flash card (flash card), etc.
  • the computer-readable storage medium may also include both an internal storage unit of the computer device and an external storage device.
  • the computer-readable storage medium is used to store the computer program and other programs and data required by the computer device.
  • the computer-readable storage medium can also be used to temporarily store data that has been output or will be output.
  • the embodiment of the present application also provides a computer program product or computer program, where the computer program product or computer program includes computer instructions, and the computer instructions are stored in a computer-readable storage medium.
  • the processor of the computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes the method provided by any one of the above embodiments corresponding to FIG. 3 and FIG. 4 .

Landscapes

  • Engineering & Computer Science (AREA)
  • Business, Economics & Management (AREA)
  • Computer Security & Cryptography (AREA)
  • Accounting & Taxation (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Physics & Mathematics (AREA)
  • Strategic Management (AREA)
  • Finance (AREA)
  • General Business, Economics & Management (AREA)
  • General Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Development Economics (AREA)
  • Economics (AREA)
  • Computer Hardware Design (AREA)
  • Computing Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本申请公开一种基于区块链的数据处理方法和相关装置,获取包含待处理执行顺序标识的待处理交易;若确定待处理交易处于已准备状态,将待处理交易和待处理执行顺序标识添加至待处理账户准备队列,得到过渡账户准备队列;在待处理账户等待队列中,将与待处理执行顺序标识能构成顺序标识连续序列的执行顺序标识,作为升级执行顺序标识,将升级执行顺序标识和升级执行顺序标识对应的等待交易按序添加至过渡账户准备队列,得到升级账户准备队列;将升级账户准备队列中的待处理交易和升级执行顺序标识对应的等待交易添加至总准备队列中;总准备队列中的交易会按照交易插入时间顺序被打包进候选区块。采用本申请可以提高区块上链的成功率。

Description

一种基于区块链的数据处理方法和相关装置
本申请要求于2022年1月25日提交中国专利局、申请号202210090413.8、申请名称为“一种基于区块链的数据处理方法、设备及可读存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及计算机技术领域,尤其涉及一种基于区块链的数据处理方法、设备及可读存储介质。
背景技术
交易在执行的过程中,交易对应的txNonce(Transaction Number once,交易非重复数)和发送该交易的区块链账户对应的accountNonce(Account Number once,账户非重复数)必须相等,否则该交易为无效交易。而区块中只要出现至少一个交易为无效交易,就会造成该区块无法达成共识,无法上链。其中,txNonce用于标识发送该交易的区块链账户希望该交易在区块链账户发送的交易中的交易执行顺序,从0开始递增;accountNonce用于标识当前世界状态下该区块链账户已经执行的交易数量,从0开始递增。
目前在区块链网络中,区块链节点接收到交易后,会把交易放入交易池中进行缓存,然后将交易池中的部分交易打包生成区块。但是由于网络波动或者用户误操作等原因,同一区块链账户下的不同txNonce的交易,可能并不是完全按照从小到大的顺序到达区块链节点,造成交易被错误地认为不合法而无法被交易池接收,区块链系统的容错率低,即使交易能被交易池接收,也可能出现产生区块时所包含的交易的txNonce与当前世界状态下发送该交易的账户的accountNonce不匹配的问题,导致区块无法达成共识,无法上链。
发明内容
本申请实施例提供了一种基于区块链的数据处理方法、设备及可读存储介质,可以增强区块链系统的容错性,提高区块上链的成功率。
本申请实施例一方面提供了一种基于区块链的数据处理方法,该方法由计算机设备执行,包括:
获取待处理账户发送的待处理交易,以及获取待处理账户对应的待处理账户准备队列和待处理账户等待队列;待处理交易包含有待处理执行顺序标识;待处理账户准备队列用于存储处于已准备状态的准备交易、以及与准备交易具有映射关系的执行顺序标识;待处理账户等待队列用于存储处于未准备状态的等待交易、以及与等待交易具有映射关系的执行顺序标识;
若确定待处理交易处于已准备状态,将待处理交易和待处理执行顺序标识添加至待处理账户准备队列,得到过渡账户准备队列;
在待处理账户等待队列中,将与待处理执行顺序标识能构成顺序标识连续序列的执行顺序标识,作为升级执行顺序标识,并将升级执行顺序标识和升级执行顺序标识对应的等待交易按序添加至过渡账户准备队列,得到升级账户准备队列;
将升级账户准备队列中的待处理交易和升级执行顺序标识对应的等待交易添加至总准备队列中;总准备队列中的交易会按照交易插入时间顺序被打包进候选区块。
本申请实施例一方面提供了一种基于区块链的数据处理装置,该装置部署在计算机设备上,包括:
获取模块,用于获取待处理账户发送的待处理交易,以及获取待处理账户对应的待处理账户准备队列和待处理账户等待队列;待处理交易包含有待处理执行顺序标识;待处理账户准备队列用于存储处于已准备状态的准备交易、以及与准备交易具有映射关系的执行顺序标识;待处理账户等待队列用于存储处于未准备状态的等待交易、以及与等待交易具有映射关系的执行顺序标识;
交易过渡模块,用于若确定待处理交易处于已准备状态,则将待处理交易和待处理执行顺序标识添加至待处理账户准备队列,得到过渡账户准备队列;
交易升级模块,用于在待处理账户等待队列中,将与待处理执行顺序标识能构成顺序标识连续序列的执行顺序标识,作为升级执行顺序标识,并将升级执行顺序标识和升级执行顺序标识对应的等待交易按序迁移至过渡账户准备队列,得到升级账户准备队列;
交易添加模块,用于将升级账户准备队列中的待处理交易和升级执行顺序标识对应的等待交易添加至总准备队列中;总准备队列中的交易会按照交易插入时间顺序被打包进候选区块。
本申请实施例一方面提供了一种计算机设备,包括:处理器、存储器、网络接口;
上述处理器与上述存储器、上述网络接口相连,其中,上述网络接口用于提供数据通信网元,上述存储器用于存储计算机程序,上述处理器用于调用上述计算机程序,以执行本申请实施例中的方法。
本申请实施例一方面提供了一种计算机可读存储介质,上述计算机可读存储介质中存储有计算机程序,上述计算机程序适于由处理器加载并执行本申请实施例中的方法。
本申请实施例一方面提供了一种计算机程序产品,包括计算机程序/指令,计算机程序/指令被处理器执行时实现本申请实施例中的方法。
本申请实施例中,待处理账户处于已准备状态的准备交易和与准备交易具有映射关系的执行顺序标识将存储在待处理账户准备队列中,待处理账户处于未准备状态的等待交易和与等待交易具有映射关系的执行顺序标识将存储在待处理账户等待队列中,然后当获取到待处理账户发送的包含有待处理执行顺序标识的待处理交易时,若确定待处理交易处于已准备状态,将待处理交易和待处理执行顺序标识添加至待处理账户准备队列中,得到过渡账户准备队列,随后在待处理账户等待队列中,将与待处理执行顺序标识能构成顺序标识连续序列的执行顺序标识,作为升级执行顺序标识,并将升级执行顺序标识和升级执行顺序标识对应的等待交易按序添加至过渡账户准备队列,得到升级账户准备队列,同时,将升级账户准备队列中的待处理交易和升级执行顺序标识对应的等待交易均添加至总准备队列中。其中,总准备队列中的交易会按照交易插入时间顺序被打包进候选区块。通过本申请实施例提供的方法,将待处理账户处于已准备状态的准备交易均存储在待处理账户准备队列中,且待处理账户的准备交易才可以添加进总准备队列中,可以保证基于总准备队 列中的交易打包生成的候选区块中不会出现处于未准备状态的等待交易,可以提高区块上链的成功率。另外,待处理账户发送的处于未准备状态的交易不会被拒绝接收,会先暂时存储在待处理账户等待队列中,每当待处理账户有新的处于已准备状态的交易添加进待处理账户准备队列时,对待处理账户等待队列进行升级,符合条件的等待交易会被添加进待处理账户准备队列中,进一步被添加进总准备队列中等待打包,可以增强区块链系统的容错性。
附图说明
为了更清楚地说明本申请实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。
图1是本申请实施例提供的一种区块链节点系统的结构示意图;
图2是本申请实施例提供的一种基于区块链的数据处理的场景示意图;
图3是本申请实施例提供的一种基于区块链的数据处理方法的流程示意图;
图4是本申请实施例提供的一种用于交易池管理的队列构建示意图;
图5是本申请实施例提供的一种基于区块链的数据处理方法的流程示意图;
图6是本申请实施例提供的一种基于区块链的数据处理方法的流程示意图;
图7是本申请实施例提供的一种交易接收方法的流程示意图;
图8是本申请实施例提供的一种刷新交易池的流程示意图;
图9是本申请实施例提供的一种数据处理装置的结构示意图;
图10是本申请实施例提供的一种计算机设备的结构示意。
具体实施方式
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。
为便于理解,以下将对区块链及其相关概念进行阐述:
区块链:区块链是一种分布式数据存储、点对点传输、共识机制以及加密算法等计算机技术的新型应用模式,主要用于对数据按时间顺序进行整理,并加密成账本,使其不可被篡改和伪造,同时可进行数据的验证、存储和更新。区块链本质上是一个去中心化的数据库,该数据库中的每个节点均存储一条相同的区块链,区块链网络可以将节点区分为共识节点和业务节点,其中共识节点负责区块链全网的共识。对于区块链网络中交易数据被写入账本的过程可以为:客户端发送交易数据至业务节点,随后该交易数据以接力棒的方式在区块链网络中的业务节点之间传递,直到共识节点收到该交易数据,共识节点再将该交易数据打包进区块,与其他共识节点之间进行共识,在共识通过后,将携带该交易数据的区块写入账本。
区块:是在区块链网络上承载交易数据(即交易业务)的数据包,是一种被标记上时间戳和之前一个区块的哈希值的数据结构,区块经过网络的共识机制验证并确定区块中的交易。
哈希值:也称作信息特征值或特征值,哈希值是通过哈希算法将任意长度的输入数据转换为密码并进行固定输出而生成的,不能通过解密哈希值来检索原始输入数据,它是一个单向的加密函数。在区块链中,每个区块(除了初始区块)都包含前继区块的哈希值,前继区块被称为当前区块的父区块。哈希值是区块链技术中的潜力核心基础和最重要的方面,它保留了记录和查看数据的真实性,以及区块链作为一个整体的完整性。
区块链账户:内有账户地址作为其唯一的标识,区块链账户中包含有余额作为当前世界状态下该区块链账户的数字资源,区块链账户对应有accountNonce,用于记录当前世界状态下已经执行了多少个由该区块链账户发送的交易,accountNonce初始值为0,每有一个该区块链账户下的交易执行后,accountNonce递增1。需要说明的是,本申请后续实施例中所提到的账户,均指区块链账户,后续不再进行赘述。
交易:区块链账户发送的交易,内有交易哈希作为唯一标识,包含有账户地址标识所属发送该交易的区块链账户,并有txNonce标识其所属区块链账户希望该交易在当前世界状态下的交易执行顺序,例如区块链账户希望第一个执行的交易的txNonce为0,希望第二个执行的交易的txNonce为1,如此类推。因此交易的txNonce与当前世界状态下执行该交易前的所属区块链账户的accountNonce必须相等,否则该交易为无效交易。区块中只要出现至少一个交易为无效交易,即会造成该区块无法达成共识,无法上链。交易内还有txFee(交易手续费)字段作为区块链账户需要支付的让区块链系统执行该交易的开销。对于不同的区块链类型,txFee字段可能由某些字段通过既定规则计算得到,例如,value(转账额度)+gas(消耗)*gasPrice(消耗单价)。
上链:每个区块包含若干个交易,当一个区块经过共识插入到每个区块链节点内的区块链数据结构的过程,称为上链。
世界状态:区块链内各个账户所拥有的持久化数据共同组成的视图,由于交易的执行本身会修改若干个账户的部分持久化数据,因此每个区块内的每个交易执行后会有一个新的世界状态,每个区块上链后更是会更新每个区块链节点的世界状态。在同一区块上链后,每个区块链节点的世界状态必然一致。
请参见图1,图1是本申请实施例提供的一种区块链节点系统的结构示意图。如图1所示的区块链节点系统可以对应于区块链网络,该区块链网络可以包括但不限于联盟链所对应的区块链网络。区块链节点系统是指用于进行区块链节点与区块链节点之间数据共享的系统,该区块链节点系统中可以包括多个区块链节点,多个区块链节点具体可以包括区块链节点10a、区块链节点10b、区块链节点10c、区块链节点10d、…、区块链节点10n。其中,每个区块链节点在进行正常工作时可以接收到外界发送的数据,并基于接收到的数据进行区块上链处理,也可以向外界发送数据。为了保证各个区块链节点之间的数据互通,每个区块链节点之间可以存在数据连接,例如区块链节点10a和区块链节点10b之间存在 数据连接,区块链节点10a和区块链节点10c之间存在数据连接,区块链节点10b和区块链节点10c之间存在数据连接。
可以理解的是,区块链节点之间可以通过上述数据连接进行数据或者区块传输。区块链网络可以基于节点标识实现区块链节点之间的数据连接,对于区块链网络中的每个区块链节点,均具有与其对应的节点标识,而且上述每个区块链节点均可以存储与自身有相连关系的其他区块链节点的节点标识,以便后续根据其他区块链节点的节点标识,将获取到的数据或生成的区块广播至其他区块链节点,例如区块链节点10a中可以维护一个如表1所示的节点标识列表,该节点标识列表保存着其他节点的节点名称和节点标识:
表1
节点名称 节点标识
节点10a 117.114.151.174
节点10b 117.116.189.145
节点10c 117.114.151.183
节点10d 117.117.125.169
节点10n 117.116.189.125
其中,节点标识可为网络之间互联的协议(Internet Protocol,IP)地址以及其他任意一种能够用于标识区块链网络中节点的信息,表1中仅以IP地址为例进行说明。例如,区块链节点10a可以通过节点标识117.116.189.145向区块链节点10b发送信息(例如,区块),且区块链节点10b可以通过节点标识117.114.151.174确定该信息是由区块链节点10a所发送的。
在区块链中,在将一个区块进行上链之前,该区块必须经过区块链网络中的共识节点进行共识,在共识通过后才能将该区块添加到区块链上。可以理解的是,当区块链被用于政府或者商业机构的一些场景中时,并非区块链中的所有参与节点(即上述区块链节点系统中的区块链节点)都有足够的资源和必要性成为区块链的共识节点。例如,在图1所示的区块链节点系统中,可以将区块链节点10a、区块链节点10b、区块链节点10c和区块链节点10d作为该区块链节点系统中的共识节点。区块链节点系统中的共识节点参与共识,也就是对区块(包含一批交易)进行共识,包括生成区块,对区块进行投票;而非共识节点不参与共识,但会帮助传播区块和投票消息,以及相互同步状态等。
其中,可以理解的是,上述的数据连接不限定连接方式,可以通过有线通信方式进行直接或间接地连接,也可以通过无线通信方式进行直接或间接地连接,还可以通过其他连接方式,本申请在此不做限制。
可以理解的是,本申请实施例所提供的数据处理方法可以由计算机设备执行,计算机设备包括但不限于上述区块链节点(可以为服务器或者终端)。上述服务器可以是独立的物理服务器,也可以是多个物理服务器构成的服务器集群或者分布式系统,还可以是提供云服务、云数据库、云计算、云函数、云存储、网络服务、云通信、中间件服务、域名服务、安全服务、CDN、以及大数据和人工智能平台等基础云计算服务的云服务器。上述终 端可以是智能手机、平板电脑、笔记本电脑、台式计算机、智能音箱、智能手表等,但并不局限于此。
可以理解的是,本申请实施例可应用于各种场景,包括但不限于云技术、人工智能、智慧交通、辅助驾驶等场景。
可以理解的是,在本申请的具体实施方式中,涉及到的交易数据等相关的数据,当本申请以上实施例运用到具体产品或技术中时,需要获得用户许可或者同意,且相关数据的收集、使用和处理需要遵守相关国家和地区的相关法律法规和标准。
其中,区块链节点可以包含以下模块:
交易池:存储区块链网络中已知但尚未包含在区块链中的交易。区块链节点通过交易池缓存接收到的交易,并且会把txNonce等于当前世界状态里所属区块链账户的accountNonce及后续连续txNonce的交易,交由共识模块进行打包共识出块。而当有新区块共识达成然后插入到区块链结构之后,会触发交易池的刷新操作,即删除掉已经包含在区块链中的交易。
共识模块:对交易进行打包生成候选区块,并在各个区块链节点之间,基于共识算法达成共识,产生新区块。
区块链结构:所有区块首尾相连组成的链式结构,存储着区块链系统的所有交易。
世界状态:当前区块链结构中最新一个区块内的交易执行过后的所有账户的数据集合。
配置模块:存储交易池总上限、单个账户上限、区块交易数上限等相关配置。
如图1所示,区块链账户发送的交易会广播至所有区块链节点,但是由于存在网络延迟、传输距离太长等问题,区块链节点并不是一定按照执行顺序标识(即上述txNonce)的从小到大的顺序接收到属于同个区块链账户的交易,此时交易池缓存的交易中,会出现某个区块链账户发送的交易对应的执行顺序标识中,最小的执行顺序标识与当前世界状态下该区块链账户的当前已执行交易数量(即上述accountNonce)不相等,或者,某个区块链账户发送的交易对应的执行顺序标识不连续的等问题,此时区块链节点系统中的区块链节点可以对交易池中缓存的交易进行精细化管理。
在一种可能的实现方式中,区块链节点可以对交易池中的交易按照账户的维度进行管理,再进一步地将同一账户发送的交易划分为账户准备队列和账户等待队列,以某个账户是待处理账户为例,其对应有待处理账户准备队列和待处理账户等待队列,待处理账户准备队列用于存储待处理账户发送的处于已准备状态的准备交易、以及与准备交易具有映射关系的执行顺序标识;待处理账户等待队列用于存储待处理账户发送的处于未准备状态的等待交易、以及与等待交易具有映射关系的执行顺序标识。其中,处于已准备状态的准备交易对应的执行顺序标识之间的标识关系满足顺序连续关系,且待处理账户准备队列中最小的执行顺序标识要和当前世界状态下该待处理账户对应的当前已执行交易数量相同。待处理账户准备队列中的准备交易在被添加进待处理账户准备队列的同时,会被添加进总准备队列中,此外,区块链网络中其他账户发送的处于已准备状态的准备交易在被添加进对应的账户准备队列中时,也会被添加进总准备队列中。总准备队列中的交易将会按照交易 插入时间顺序被打包进候选区块。此时,被打包进候选区块的交易均能按照其执行顺序标识所指示的执行顺序被执行,候选区块共识通过的概率会提高。
因此,当区块链节点接收到待处理账户新发送的待处理交易时,可以先确定该待处理交易是否处于已准备状态,若确定待处理交易处于已准备状态,则将待处理交易和待处理交易对应的待处理执行顺序标识添加至待处理账户准备队列,得到过渡账户准备队列;然后区块链节点可以对待处理账户等待队列进行交易升级处理,即在待处理账户等待队列中,将与待处理执行顺序标识能构成顺序标识连续序列的执行顺序标识,作为升级执行顺序标识,将升级执行顺序标识和升级执行顺序标识对应的等待交易按序迁移至过渡账户准备队列,得到升级账户准备队列,最后,区块链节点可以将升级账户准备队列中的待处理交易和升级执行顺序标识对应的等待交易添加至总准备队列中等待打包。
为便于理解区块链节点对待处理账户发送的待处理交易的处理过程,请一并参见图2,图2是本申请实施例提供的一种基于区块链的数据处理的场景示意图。其中,如图2所示的区块链节点20可以为上述图1所对应实施例中的区块链节点系统中的任一区块链节点,如,区块链节点20可以为区块链节点10a。
如图2所示,区块链节点20中包含有区块链21,区块链21中包含了多个区块,例如,区块211、区块212等等。在区块中可以包含有不同账户发送的多个交易,例如,区块211中包含了交易A2、交易B1等等;区块212中包含了交易A1等等。其中,交易A2、交易A1是账户A发送的交易,交易B1是账户B发送的交易。区块链节点20中还包含有当前世界状态下的执行数据22。其中,当前世界状态指的是区块211上链至区块链21后区块链网络的世界状态,区块链网络对应的世界状态指区块链网络中各个账户所拥有的持久化数据共同组成的视图,由于交易的执行可以更改账户对应的账户资源,因此每当有新的区块上链至区块链21时,世界状态会发生变更,也就是说,不同区块上链至区块链21时,区块链网络的世界状态不同。执行数据22中包含有区块链网络各个账户对应的当前已执行交易数量,已经上链的区块中包含的交易均为已执行过的交易,因此交易A2、交易A1以及交易B1均为已执行过的交易,假设区块链21中的其他区块均不包含有账户A和账户B发送的交易,此时执行数据22中会记录账户A对应的当前已执行交易数量为2,账户B对应的当前已执行交易数量为1。
如图2所示,区块链节点20中还包含有交易池23。其中,交易池23用于缓存区块链节点20接收到的且未被上链至区块链21的交易。假设,区块链节点20此时接收到了账户A发送的交易A5,该交易A5中包含有执行顺序标识4。其中,执行顺序标识4是指账户A希望交易A5是其在区块链网络中第五个被执行的交易,如果交易A5在区块链网络中的执行顺序不满足执行顺序标识4指示的执行顺序,则交易A5会被认为是无效交易,包含交易A5的区块的上链就不会成功。区块链节点20接收到交易A5后,会将其暂存在交易池23中。为了使得交易A5能作为账户A发送的第五个在区块链中被执行的交易,区块链节点20会获取账户A对应的账户准备队列231和账户等待队列232。其中,账户准备队列231用于存储处于已准备状态的准备交易,假设账户准备队列231中包含有交易A3和交易A3对应的执行顺序标识2,交易A4和交易A4对应的执行顺序标识3。可以理解,处于已 准备状态的准备交易在区块链上的执行顺序将和其对应的执行顺序标识指示的执行顺序相同,因为账户准备队列231中的交易A3和交易A4会基于执行顺序标识的从小到大被添加进总准备队列230中,而总准备队列230中用于存储区块链网络中所有账户对应的账户准备队列中的交易,区块链节点20会从总准备队列230中根据交易插入时间顺序将交易打包进区块。所以在执行区块的过程中,交易也会按照交易插入时间顺序被执行。也就是说,区块链节点20之后的区块打包上链的过程中,会先执行交易A3,再执行交易A4,由于区块链节点20已经执行过账户A发送的交易A1和交易A2,因此交易A3会是账户A在区块链网络中第三个被执行的交易,交易A3的执行顺序和交易A3的执行顺序标识2所指示的执行顺序相同,所以交易A3是处于已准备状态的准备交易。同理,交易A4会是账户A在区块链网络中第四个被执行的交易,交易A4的执行顺序和交易A4的执行顺序标识3所指示的执行顺序相同,交易A4也是处于已准备状态的准备交易。其中,账户等待队列232用于存储处于未准备状态的等待交易,假设账户等待队列232中包含有交易A6和交易A6对应的执行顺序标识5,可见账户A希望交易A6是其在区块链网络中第六个被执行的交易,但是,若此时将交易A3、交易A4和交易A6打包进区块,交易A6将是账户A在区块链网络中第五个被执行的交易,交易A6的执行顺序与交易A6对应的可执行顺便标识5所指示的执行顺序不同,因此交易A6是处于未准备状态的等待交易。
如图2所示,区块链节点20会确定交易A5是否处于已准备状态,区块链节点20会查询账户准备队列231,确定其包含的最大的执行顺序标识为执行顺序标识3,执行顺序标识3和交易A5对应的执行顺序标识4之间满足顺序连续关系,若交易A5在交易A4后一个执行,交易A5就将是账户A在区块链网络中第五个被执行的交易,因此区块链节点20可以确定交易A5的执行顺序和其对应的执行顺序标识4所指示的执行顺序相同,则交易A5处于已准备状态,因此,区块链节点20会将交易A5和交易A5对应的执行顺序标识4一起添加进账户A的账户准备队列231中,得到过渡账户准备队列(图中未画出),在将交易A5和交易A5对应的执行顺序标识4添加进账户A的账户准备队列231后,区块链节点20可以对账户等待队列232中的交易进行一次升级,即判断倘若交易A5将作为账户A在区块链网络中第五个执行的交易后,有无交易能够按照其对应的执行顺序标识所执行的执行顺序来执行,有就将该交易从账户等待队列232中迁移至账户准备队列231中。如图2所示,交易A6对应的执行顺序标识6和交易A5对应的执行顺序标识5能构成顺序标识连续序列,因此区块链节点20会将交易A6以及交易A6对应的执行顺序标识5迁移至过渡账户准备队列,得到升级账户准备队列234和升级账户等待队列235。最后,区块链节点20会将交易A5和交易A6添加进账户总准备队列230中。
通过本申请实施例提供的数据处理方法,对区块链节点暂存在交易池中的交易按照账户维度进行精细化管理,保证被打包进区块中的交易的执行顺序,和其包含的执行顺序标识所指示的执行顺序相同,提高区块共识通过的概率,从而提高区块上链的成功率。
请参见图3,图3是本申请实施例提供的一种基于区块链的数据处理方法的流程示意图。其中,该方法可以由区块链节点(例如,上述图1所对应实施例中的区块链节点系统 中的任一区块链节点)执行。以下将以本方法由区块链节点执行为例进行说明,其中,该基于区块链的数据处理方法至少可以包括以下S101-S104:
S101,获取待处理账户发送的待处理交易,以及获取所述待处理账户对应的待处理账户准备队列和待处理账户等待队列;所述待处理交易包含有待处理执行顺序标识;所述待处理账户准备队列用于存储处于已准备状态的准备交易、以及与所述准备交易具有映射关系的执行顺序标识;所述待处理账户等待队列用于存储处于未准备状态的等待交易、以及与所述等待交易具有映射关系的执行顺序标识。
其中,执行顺序标识指交易对应的txNonce,用于标识发送该交易的账户希望该交易在账户发送的交易中的交易执行顺序,从0开始递增,例如,账户C发送的交易C3对应的执行顺序标识为2,则账户C希望交易C3是其在区块链网络中第三个被执行的交易,当交易C3执行完以后,账户C的当前已执行交易数量就为3,因此,可以理解,账户C下一个被执行的交易应该是执行顺序标识为3的交易C4。
区块链节点接收到且未被打包进区块的交易会存储在交易池中,区块链节点可以按照账户维度缓存交易,例如,将待处理账户的交易进一步划分为处于已准备状态的准备交易和处于未准备状态的等待交易,然后将处于已准备状态的准备交易和其对应的执行顺序标识添加进待处理账户准备队列中,将处于未准备状态的等待交易和其对应的执行顺序标识添加进待处理账户等待队列中。其中,准备交易处于已准备状态是指若此时按照执行顺序标识从小到大顺序执行交易池中待处理账户的所有交易,其在待处理账户发送至区块链网络中的所有交易(包含交易池中的交易和已经上链的交易)中的执行顺序,将与其对应的执行顺序标识所指示的执行顺序相同。等待交易处于未准备状态是指若此时按照执行顺序标识从小到大顺序执行交易池中待处理账户的所有交易,其在待处理账户发送至区块链网络中的所有交易(包含交易池中的交易和已经上链的交易)中的执行顺序,将与其对应的执行顺序标识所指示的执行顺序不相同。当然,区块链节点中的交易需要被打包进候选区块,在候选区块通过共识后,候选区块中的交易才能被执行。
区块链节点在进行交易的打包时,是从总准备队列中按照交易插入时间顺序来获取交易然后打包生成候选区块的。其中,总准备队列中包含了区块链网络中所有账户对应的账户准备队列中的准备交易,不过同一账户的准备交易中的交易是基于其在账户准备队列中的执行顺序标识的顺序被添加进总准备队列中的。因此区块链节点只需保证待处理账户准备队列中,准备交易可以按照执行顺序标识从小到大的顺序进行排列,且待处理账户准备队列中最小的执行顺序标识等于当前世界状态下待处理账户对应的当前已执行交易数量,也就是待处理账户对应的accountNonce,就可以保证当准备交易被打包进候选区块后执行时,准备交易在待处理账户发送至区块链网络中的所有交易中的执行顺序为其执行顺序标识所指示的执行顺序。例如,账户D的accountNonce为3,代表账户D已经有3个交易被区块链节点执行过了,此时账户D对应的账户准备队列中包含有交易D4和交易D4对应的执行顺序标识3,交易D5和交易D5对应的执行顺序标识4,区块链节点会根据执行顺序标识从小到大的顺序将交易D4和交易D5添加进总准备队列中,则区块链节点按照交易插入时间顺序,会先将交易D4打包进候选区块,再将交易D5打包进候选区块,则后续区块 链节点会依次执行交易D4和交易D5,此时交易D4将是账户D第四个被执行的交易,交易D5将是账户D第五个被执行的交易,交易D4和交易D5对应的执行顺序均符合其对应的执行顺序标识指示的执行顺序。
S102,若确定所述待处理交易处于所述已准备状态,将所述待处理交易和所述待处理执行顺序标识添加至所述待处理账户准备队列,得到过渡账户准备队列。
在接收到待处理交易后,区块链节点可以根据待处理账户的当前已执行交易数量,或者根据待处理交易的执行顺序标识和待处理账户准备队列中的执行顺序标识的关系来确定待处理交易是否处于已准备状态。如果待处理交易处于已准备状态,则直接将待处理交易和待处理交易对应的可执行顺序标识添加进待处理账户准备队列,可以得到过渡账户准备队列;如果待处理交易处于未准备状态,则将待处理交易和待处理执行顺序标识添加至待处理账户等待队列中。
在一种可能的实现方式中,当待处理账户准备队列中不包含有准备交易,即待处理账户准备队列为空队列时,此时确定待处理交易是否处于已准备状态的一个可行过程,可以为:对待处理执行顺序标识和待处理账户的当前已执行交易数量进行比对;若待处理执行顺序标识和待处理账户的当前已执行交易数量相同,则确定待处理交易处于已准备状态;若待处理执行顺序标识和待处理账户的当前已执行交易数量不相同,则确定待处理交易处于未准备状态,将待处理交易和待处理执行顺序标识添加至待处理账户等待队列。例如,当账户E的accountNonce为3,账户E对应的账户准备队列为空队列时,区块链节点接收到账户E发送包含执行顺序标识4的交易D5,说明账户E希望交易D5是其第五个被执行的交易,此时若将交易D5添加进账户准备队列,则交易D5会成为账户E第四个被执行的交易,与账户E希望的执行顺序不一致,因此交易D5是处于未准备状态的等待交易,应该将交易D5添加进账户等待队列中等待升级。
在另一种可能的实现方式中,当待处理账户准备队列中包含有准备交易,即待处理账户准备队列为非空队列,此时确定待处理交易是否处于已准备状态的一个可行过程,可以为:若待处理账户准备队列为非空队列,则确定待处理执行顺序标识与待处理账户准备队列中最大的执行顺序标识之间的标识关系;若标识关系满足顺序连续关系,则确定待处理交易处于已准备状态;若标识关系不满足顺序连续关系,则确定待处理交易处于未准备状态,将待处理交易和待处理执行顺序标识添加至待处理账户等待队列。可以理解,待处理账户准备队列中的准备交易均处于已准备状态,即准备交易均可以按照其执行顺序标识所指示的执行顺序被执行,若待处理账户准备队列中最大的执行顺序标识为执行顺序标识5,则执行顺序标识5对应的准备交易会是待处理账户第六个被执行的交易,待处理交易此时被添加进待处理账户准备队列中,会成为待处理账户第七个被执行的交易,因此待处理交易的执行顺序标识应该为执行顺序标识6,也就是说,待处理交易的执行顺序标识应该和执行顺序标识5为顺序连续关系,才能使得待处理交易可以按照其执行顺序标识所指示的执行顺序被执行。
S103,在所述待处理账户等待队列中,将与所述待处理执行顺序标识能构成顺序标识连续序列的执行顺序标识,作为升级执行顺序标识,并将所述升级执行顺序标识和所述升 级执行顺序标识对应的等待交易按序迁移至所述过渡账户准备队列,得到升级账户准备队列。
当待处理交易被添加进账户准备队列中得到过渡账户准备队列后,过渡账户准备队列中最大的执行顺序标识就为待处理交易对应的待处理执行顺序标识,此时区块链节点可以查询待处理账户等待队列,将能够和待处理执行顺序标识构成顺序标识连续序列的执行顺序标识,作为升级执行顺序标识,将升级执行顺序标识和升级执行顺序标识对应的等待交易按序迁移至所述过渡账户准备队列,得到升级账户准备队列。可以理解,此时升级账户准备队列中的执行顺序标识可以构成以待处理账户的当前已执行交易数量为首的顺序标识连续序列。
S104,将所述升级账户准备队列中的所述待处理交易和所述升级执行顺序标识对应的等待交易添加至总准备队列中;所述总准备队列中的交易会按照交易插入时间顺序被打包进候选区块。
区块链网络中包含有至少两个账户,每个账户均对应有账户准备队列和账户等待队列,区块链节点会在将新的准备交易被添加进某个账户对应的账户准备队列的同时,将其添加进总准备队列中。区块链节点在打包候选区块时,会根据交易插入时间顺序从总准备队列中获取交易。其中,交易插入时间顺序是指交易被添加进总准备队列中的时间顺序。
在一种可能的实现方式中,区块链节点中还可以包含有交易总队列,其中,交易总队列用于记录交易池中的所有交易,也就是说,交易总队列中可以包含有区块链网络中所有账户对应的准备交易和等待交易,方便区块链节点对交易池进行整体查询管理。此外,区块链节点中还可以包含有账户准备队列哈希映射和账户等待队列哈希映射,其中,账户准备队列哈希映射用于区块链节点查找账户对应的账户准备队列;账户等待队列哈希映射用于区块链节点查找到账户对应的账户等待队列。
为便于理解,请一并参见图4,图4是本申请实施例提供的一种用于交易池管理的队列构建示意图。如图4所示,区块链节点根据交易池中的交易,可以构建包含整个交易池所有交易的总队列,和用于存储所有账户处于已准备状态的准备交易的总准备队列,还可以构建每个账户对应的账户准备队列和账户等待队列,并建立从账户地址到账户准备队列的账户准备队列哈希映射,从账户地址到账户等待队列的账户等待队列哈希映射。其中,账户地址是账户的唯一地址。
如图4所示,交易总队列可以包含有交易和与交易具有映射关系的交易哈希,故交易总队列可以使用从交易哈希映射到交易的HashMap(散列表)哈希映射结构。其中,交易哈希是交易的唯一标识。其中,HashMap是一种健值映射结构,遍历顺序为随机读取。总准备队列可以包含有交易和与交易具有映射关系的交易哈希,且允许区块链节点按照交易插入的时间顺序来存储交易和遍历,故总准备队列可以使用从交易哈希映射到交易的LinkedHashMap(连接散列表)结构,并且按照插入的时间顺序存放交易。其中,LinkedHashMap是一种健值映射结构,会保持插入时间的顺序进行排序存放和遍历。账户准备队列需要包含准备交易以及与准备交易具有映射关系的txNonce,账户等待队列需要包含等待交易以及与等待交易具有映射关系的txNonce,且允许区块链节点按照txNonce的大 小顺序来存储交易和遍历,因此账户准备队列和账户等待队列均可以使用从txNonce映射到交易的TreeMap(树列表)结构,按照txNonce字段从小到大对各个交易进行排序存放。其中,TreeMap是一种健值映射结构,会按照键的大小进行排序存放和遍历。账户准备队列哈希映射可以使用从账户地址到账户准备队列的HashMap结构,账户等待队列哈希映射可以使用从账户地址到账户等待队列的HashMap结构。根据如图4所示的列表,只要区块链节点知道待处理交易的txNonce以及发送待处理交易的账户的账户地址,就可以快速定位到账户准备队列或账户等待队列中的指定交易。需要说明的是,同一个交易可能逻辑上同时出现在交易总队列、总准备队列或者账户准备列表或账户等待队列中,但是物理上是指该交易的内存指针,而物理上该交易的数据只会在内存中存储一份,以此节省内存。因此,每当本申请实施例在描述交易在某个队列中时,可以指该交易的内存指针在队列中,后文不再赘述。
采用本申请实施例提供的方法,将待处理账户处于已准备状态的准备交易均存储在待处理账户准备队列中,且待处理账户的准备交易才可以添加进总准备队列中,可以保证基于总准备队列中的交易打包生成的候选区块中不会出现处于未准备状态的等待交易,可以提高区块上链的成功率。另外,待处理账户发送的处于未准备状态的交易不会被拒绝接收,会先暂时存储在待处理账户等待队列中,每当待处理账户有新的处于已准备状态的交易添加进待处理账户准备队列时,对待处理账户等待队列进行升级,符合条件的等待交易会被添加进待处理账户准备队列中,进一步被添加进总准备队列中等待打包,可以增强区块链系统的容错性。
请参见图5,图5是本申请实施例提供的一种基于区块链的数据处理方法的流程示意图。其中,该方法可以由区块链节点(例如,上述图1所对应实施例中的区块链节点系统中的任一区块链节点)执行。以下将以本方法由区块链节点执行为例进行说明,其中,该基于区块链的数据处理方法至少可以包括以下201-S207:
S201,获取待处理账户发送的待处理交易,并确定所述待处理交易的缓存验证结果;所述待处理交易包含有待处理执行顺序标识。
区块链节点接收到待处理账户发送的待处理交易后,可以先确定待处理交易的缓存验证结果,如果区块链节点确定待处理交易的缓存验证结果为合法缓存结果,就可以将待处理交易缓存进交易池中,如果区块链节点确定待处理交易的缓存验证结果为不合法缓存结果,区块链节点直接向待处理账户返回报错信息即可。
在一种可能的实现方式中,确定待处理交易的缓存验证结果的一个可行实施方法,可以为:获取交易总队列中的交易总数量;获取交易总数量上限阈值;若交易总数量等于交易总数量上限阈值,则向待处理账户返回交易上限报错信息;若交易总数量小于交易总数量上限阈值,则确定待处理交易的缓存验证结果为合法缓存结果。其中,交易总数量即交易总队列中包含的交易的数量,也就是此时交易池中缓存的交易数量。应当理解,交易池的容量有限,当交易池中缓存的交易达到上限后,区块链节点就无法将待处理交易添加进交易池中了,此时区块链节点只能向待处理账户发送交易上限报错信息。另外,交易池的容量上限可以通过区块链节点的配置模块来进行配置。
在另一种可能的实现方式中,确定待处理交易的缓存验证结果的一个可行实施方法,可以为:获取账户交易数量上限阈值;若准备交易的数量和等待交易的数量的总和等于账户交易数量上限阈值,则向待处理账户发送交易上限报错信息;若准备交易的数量和等待交易的数量的总和小于账户交易数量上限,则确定待处理交易的缓存验证结果为合法缓存结果。其中,账户交易数量上限阈值是指待处理账户可以在交易池中缓存的交易数量的最大值,可以通过区块链节点的配置模块来进行配置。应当理解,待处理账户在交易池中缓存的交易包含有准备交易和等待交易,当待处理账户在交易池中缓存的交易达到上限后,尽管此时区块链节点的交易池中缓存的交易没有达到上限,但区块链节点接收到待处理账户发送的待处理交易,仍然不会对其进行缓存,而是会向待处理账户返回交易上限报错信息。
在又一种可能的实现方式中,确定待处理交易的缓存验证结果的一个可行实施方法,可以为:获取待处理账户的当前已执行交易数量;若待处理执行顺序标识小于当前已执行交易数量,则向待处理账户发送交易过时报错信息;若待处理执行顺序标识大于或等于当前已执行交易数量,则确定待处理交易的缓存验证结果为合法缓存结果。可以理解,待处理账户的当前已执行交易数量大于待处理交易的待处理执行顺序标识时,待处理交易就不可能按照待处理执行顺序标识所指示的执行顺序被执行了,区块链节点就不用再存储执行待处理交易了。
在又一种可能的实现方式中,确定待处理交易的缓存验证结果的一个可行实施方法,可以为:获取待处理交易的交易执行开销,查询待处理账户的账户资源;若账户资源小于交易执行开销,则向待处理账户发送资源不足报错信息;若账户资源大于或等于交易执行开销,则确定待处理交易的缓存验证结果为合法缓存结果。其中,交易执行开销是指待处理账户愿意为执行该交易所提供的数字资源,账户资源是指待处理账户在区块链网络中所拥有的数字资源。
需要说明的是,区块链节点可以同时对待处理交易进行上述多个可行实施方法来确定待处理交易的缓存验证结果,此时待处理交易需要同时满足多个可行实施方法的验证,区块链节点才能确定待处理交易的缓存验证结果为合法缓存结果。
S202,若所述待处理交易的缓存验证结果为合法缓存结果,则获取与所述待处理账户对应的待处理账户准备队列和待处理账户等待队列;所述待处理账户准备队列用于存储处于已准备状态的准备交易、以及与所述准备交易具有映射关系的执行顺序标识;所述待处理账户等待队列用于存储处于未准备状态的等待交易、以及与所述等待交易具有映射关系的执行顺序标识。
其中,S202的实现可以参见上述图3所对应实施例中的S101,这里不再进行赘述。
S203,根据所述待处理执行顺序标识遍历所述待处理账户准备队列和所述待处理账户等待队列,得到针对所述待处理交易的遍历结果。
在待处理账户发送了携带某个执行顺序标识的交易后,到该交易被打包进候选区块中存在一定的时间差,这段时间内倘若待处理账户希望该执行顺序标识所指示的执行顺序执行其他交易,待处理账户可以发送同样包含该执行顺序标识的交易至区块链节点,则区块 链节点可能获取到具有相同执行顺序标识的多个交易。但是区块链节点只会从具有相同执行顺序标识的多个交易中选择最优或者待处理账户最希望执行的交易来执行,其余交易会被舍弃。因此,区块链节点接收到待处理交易后,需要确定待处理账户对应的待处理账户准备队列中是否已经包含有拥有待处理执行顺序标识的准备交易,或者待处理账户等待队列中是否已经包含有拥有待处理执行顺序标识的等待交易。
S204,当所述遍历结果指示待处理队列中存在具有所述待处理执行顺序标识的交易时,则将所述待处理队列中的具有所述待处理执行顺序标识的交易,确定为冲突交易,若所述待处理交易与所述冲突交易之间满足冲突覆盖条件,则基于所述待处理交易对所述冲突交易进行覆盖处理;所述待处理队列为所述待处理账户准备队列或所述待处理账户等待队列。
冲突交易和待处理交易具有相同的待处理执行顺序标识,区块链节点需要确定待处理交易和冲突交易之间是否满足冲突覆盖条件,若待处理交易与冲突交易之间满足冲突覆盖条件,则基于待处理交易对冲突交易进行覆盖处理,若待处理交易与冲突交易之间不满足冲突覆盖条件,则区块链节点会舍弃待处理交易。
在一种可能的实现方式中,区块链节点确定待处理交易和冲突交易之间是否满足冲突覆盖条件的一个可行实施方法,可以为:获取待处理交易的交易执行开销,以及获取冲突交易的交易执行开销;若待处理交易的交易执行开销大于冲突交易的交易执行开销,则确定待处理交易与冲突交易之间满足冲突覆盖条件;若待处理交易的交易执行开销小于或等于冲突交易的交易执行开销,则确定待处理交易与冲突交易之间不满足冲突覆盖条件,向待处理账户发送交易覆盖失败报错信息。其中,交易执行开销是指待处理账户愿意为区块链网络执行该交易所提供的数字资源,因此交易执行开销更大的交易自然是待处理账户更愿意执行的交易,此时,区块链节点会使用待处理交易对冲突交易进行覆盖处理。
在一种可能的实现方式中,基于待处理交易对冲突交易进行覆盖处理的一个可行实施方法,可以为:若待处理队列为待处理账户准备队列,则在待处理账户准备队列中,将冲突交易替换为待处理交易,在总准备队列中,将冲突交易替换为待处理交易;若待处理队列为待处理账户等待队列,则在待处理账户等待队列中,将冲突交易替换为待处理交易。此外,区块链节点可以在交易池中删除该冲突交易。
S205,当所述遍历结果指示所述待处理账户准备队列和所述待处理账户等待队列中不存在具有所述待处理执行顺序标识的交易时,若所述待处理交易处于所述已准备状态,则将所述待处理交易和所述待处理执行顺序标识添加至所述待处理账户准备队列,得到过渡账户准备队列。
S206,在所述待处理账户等待队列中,将与所述待处理执行顺序标识能构成顺序标识连续序列的执行顺序标识,作为升级执行顺序标识,并将所述升级执行顺序标识和所述升级执行顺序标识对应的等待交易按序迁移至所述过渡账户准备队列,得到升级账户准备队列。
S207,将所述升级账户准备队列中的所述待处理交易和所述升级执行顺序标识对应的等待交易添加至总准备队列中;所述总准备队列中的交易会按照交易插入时间顺序被打包进候选区块。
其中,S205-S207的具体实现过程可以参见上述图3所对应实施例中的S102-S104,这里不再进行赘述。
采用本申请实施例提供的方法,待处理账户在发送了具有待处理执行顺序标识的交易后,可以以更高的交易执行开销来发送具有相同待处理执行顺序标识的待处理交易,来覆盖掉之前发送的交易,提高区块链使用的灵活性,且在包含有之前发送的交易的队列中将之前发送的交易替换为待处理交易,不会打乱其余交易的待执行顺序,提高交易打包的有效性。
请参见图6,图6是本申请实施例提供的一种基于区块链的数据处理方法的流程示意图。其中,该方法可以由区块链节点(例如,上述图1所对应实施例中的区块链节点系统中的任一区块链节点)执行。以下将以本方法由区块链节点执行为例进行说明,其中,该基于区块链的数据处理方法至少可以包括以下301-S306:
S301,获取候选区块。
候选区块可以是区块链节点生成的,也可以是其他区块链节点生成然后广播给区块链节点的。当区块链节点具备出块权限时,可以从总准备队列中按照交易插入时间顺序获取交易,然后依次打包生成候选区块。区块中交易的数量需要小于或者等于区块交易数量阈值,其中,区块交易数量阈值是指区块中可以包含的交易的数量的最大值,可以通过配置模块来配置。
S302,对所述候选区块进行共识处理,得到新区块,遍历所述新区块,得到所述待处理账户的最大执行顺序标识。
区块链节点可以和其余共识节点一起对该候选区块进行共识处理,共识通过后执行该候选区块,即执行候选区块中的所有交易,然后得到包含所有交易以及所有交易对应的交易执行结果的新区块。新区块会被插入已有的区块链结构中,得到新的区块链,新的区块链中账户对应的账户资源也会发生变更,会得到新的世界状态。
其中,已经被执行过且写入区块链中的交易,应当从交易池中被删除,相应的也需要从发送该交易的账户对应的账户准备队列和账户等待队列中被删除。区块链节点依然可以按照账户的维度来对交易进行删除,即根据区块中的交易,确定每个账户对应的最大的执行顺序标识,然后对每个账户的准备交易和等待交易进行删除。以待处理账户为例进行说明,假设区块链节点遍历区块得到了待处理账户的最大执行顺序标识。
S303,在待处理账户准备队列中,获取与第一待删除执行顺序标识具有映射关系的准备交易,作为待删除准备交易;所述第一待删除执行顺序标识为所述待处理账户准备队列中小于或等于所述最大执行顺序标识的执行顺序标识。
区块链节点可以获取待处理账户对应的待处理账户准备队列,然后从待处理账户准备队列中,查找小于或等于最大执行顺序标识的执行顺序标识,将查找到的执行顺序标识作为第一待删除执行顺序标识。然后,区块链节点可以将待处理账户准备队列中,与第一待删除执行顺序标识具有映射关系的准备交易,作为待删除准备交易。
S304,在所述待处理账户准备队列中,删除所述待删除准备交易和所述第一待删除执行顺序标识,得到更新账户准备队列;在所述总准备队列中删除所述待删除准备交易,得到更新总准备队列。
在确定待删除准备交易后,区块链节点就可以在待处理账户准备队列中删除待删除准备交易和第一待删除执行顺序标识,得到更新账户准备队列;并且在总准备队列中删除待删除准备交易,得到更新总准备队列。
S305,在所述待处理账户等待队列中,获取与第二待删除执行顺序标识具有映射关系的等待交易,作为待删除等待交易;所述第二待删除执行顺序标识为所述待处理账户等待队列中小于或等于所述最大执行顺序标识的执行顺序标识。
区块链节点可以获取待处理账户对应的待处理账户等待队列,然后从待处理账户等待队列中,查找小于或等于最大执行顺序标识的执行顺序标识,将查找到的执行顺序标识作为第二待删除执行顺序标识。然后,区块链节点可以将待处理账户等待队列中,与第二待删除执行顺序标识具有映射关系的等待交易,作为待删除等待交易。
S306,在所述待处理账户等待队列中删除所述待删除等待交易和所述第二待删除执行顺序标识,得到更新账户等待队列。
在确定待删除准备交易后,区块链节点就可以在待处理账户等待队列中删除待删除等待交易和第二待删除执行顺序标识,得到更新账户等待队列。
在一种可能的实现方式中,在删除掉已经执行过的交易后,区块链节点可以对更新账户等待队列进行升级处理,即确定此时更新账户等待队列中的等待交易的准备状态是否发生变更,将准备状态变为已准备状态的等待交易从更新账户等待队列中迁移至更新账户准备队列中。其中,升级处理的一个可行实施方法,可以为:区块链节点获取更新账户等待队列中的最小执行顺序标识;根据最大执行顺序标识生成优化执行顺序标识;若最小执行顺序标识等于优化执行顺序标识,则在待处理账户等待队列中,将与最小执行顺序标识能构成顺序标识连续序列的执行顺序标识,作为优化升级执行顺序标识,将最小执行顺序标识、最小执行顺序标识对应的等待交易、优化升级执行顺序标识和优化升级执行顺序标识对应的等待交易按序迁移至更新账户准备队列,得到优化升级账户准备队列;将最小执行顺序标识、最小执行顺序标识对应的等待交易、优化升级执行顺序标识和优化升级执行顺序标识对应的等待交易按序添加至更新总准备队列中,得到优化升级总准备队列。其中,根据最大执行顺序标识生成优化执行顺序标识的过程为:对最大执行顺序标识进行加一,就得到优化执行顺序标识。
为便于理解,假设新区块中包含的账户A的最大执行顺序标识为执行顺序标识6,则优化执行顺序标识为执行顺序标识7,假设区块链节点在删除账户等待队列中不大于最大执行顺序标识的执行顺序标识以及其对应的交易后,得到的更新账户等待队列中包含了交易7和交易7对应的执行顺序标识7,交易8和交易8对应的执行顺序标识8以及交易10和交易10对应的执行顺序标识10,可见交易7对应的执行顺序标识和优化执行顺序标识,执行顺序标识7和执行顺序标识8能构成顺序标识连续序列,故区块链节点会将执行顺序 标识8作为优化升级执行顺序标识,然后将交易7、交易7对应的执行顺序标识7、交易8和交易8对应的执行顺序标识8按序迁移至更新账户准备队列中。
在一种可能的实现方式中,在删除掉已经执行过的交易后,区块链节点可以删除余额不足的准备交易,即区块链节点可以获取更新账户准备队列中的最小执行顺序标识对应的准备交易,作为待判定准备交易;然后获取待判定准备交易的交易执行开销;查询待处理账户的账户资源;若待判定准备交易的交易执行开销大于账户资源,则从更新账户准备队列中删除待判定准备交易以及最小执行顺序标识,从更新总准备队列中删除待判定准备交易;在删除后的更新账户准备队列中,将大于最小执行顺序标识的执行顺序标识,作为降级执行顺序标识,将降级执行顺序标识和降级执行顺序标识对应的准备交易迁移至更新账户等待队列,得到降级账户等待队列;将降级执行顺序标识和降级执行顺序标识对应的准备交易从删除后的更新账户准备队列中删除;将降级执行顺序标识和降级执行顺序标识对应的准备交易从删除后的更新总准备队列中删除。因为在下一次将更新账户准备队列中的交易打包进候选区块时,最小执行顺序标识对应的准备交易将是候选区块中待处理账户被执行的第一个交易,若此时待处理账户的数字资源不足以支撑最小执行顺序标识对应的准备交易所需要的交易执行开销,候选区块会共识失败,因此区块链节点可以先对最小执行顺序标识对应的准备交易进行判定,如果待处理账户余额不足,就将该最小执行顺序标识对应的准备交易删除,此时更新账户准备队列中的其他交易如果被打包进候选区块,就无法按照其对应的执行顺序标识所指示的执行顺序被执行,因此区块链节点可以先将更新账户准备队列中的其他交易迁移回账户等待队列中进行等待。
采用本申请实施例提供的方法,在新增区块时对交易池的刷新操作耗时不受交易池大小影响,只与区块大小相关,提升了交易池刷新操作的效率。
请参见图7,图7是本申请实施例提供的一种交易接收方法的流程示意图。其中,该交易接收方法可以由区块链节点执行(例如,上述图1所对应实施例中的区块链节点系统中的任一区块链节点)执行。其中,区块链节点可以包含有上述图1所对应实施例所述的交易池、共识模块、区块链结构、世界状态以及配置模块。此外区块链节点可以基于交易池构建上述图4所对应实施例所述的账户准备队列哈希映射、账户等待队列哈希映射、账户准备队列、账户等待队列、总准备队列以及交易总队列。如图7所示,区块链节点收到待处理账户发送的待处理交易后,会进行以下操作:
S701,校验总交易数是否已达到上限。
区块链节点可以根据配置模块中的交易池总上限(也可以称为交易总数量上限阈值),判断交易总队列的交易数(也可以称为交易总数量)是否已经超过上限,超过则向待处理账户报错,不缓存待处理交易;未超过则执行S702。
S702,校验账户交易数是否已达到上限。
区块链节点可以根据配置模块中的单个账户上限,获取待处理交易中的账户地址,然后根据账户准备队列哈希映射和账户等待队列哈希映射找到待处理账户对应的账户准备队列和账户等待队列,确定两者包含的准备交易的数量和所述等待交易的数量的总和是否已 经超过单个账户上限(也可以称为账户交易数量上限阈值),超过则向待处理账户报错,不缓存待处理交易;未超过则执行S703。
S703,校验交易是否过时。
区块链节点需要校验待处理交易是否过时,若待处理交易的txNonce不小于当前世界状态下待处理账户的accountNonce,则确定交易未过时,继续执行S704;否则确定交易过时,向待处理账户报错,不缓存待处理交易。
S704,校验账户余额是否充足。
区块链节点可以根据待处理交易携带的账户地址查询当前世界状态下待处理账户的账户余额(也可以称为账户资源),如果账户余额小于待处理交易的txFee(也可以称为交易执行开销)则向待处理账户报错,不缓存交易;如果账户余额不小于交易的txFee,则执行S705。
S705,确定是否交易冲突。
区块链节点可以根据待处理交易携带的账户地址,获取待处理账户对应的账户准备队列和账户等待队列,然后区块链节点会确定待处理账户对应的账户准备队列和账户等待队列中是否有相同txNonce的交易,如果有相同txNonce的交易,则将其确定为冲突交易,执行S706。如果没有相同txNonce的交易,则执行S712。
S706,确定是否交易覆盖。
区块链节点可以获取待处理交易的txFee和冲突交易的txFee,若待处理交易的txFee不大于冲突交易的txFee,则报错,不缓存待处理交易;若待处理交易的txFee大于冲突交易的txFee,则执行S707。
S707,校验交易是否已准备。
区块链节点根据待处理交易包含的账户地址,查找待处理账户对应的账户准备队列和账户等待队列中是否有相同txNonce的交易,如果是在账户准备队列中找到,则确定待处理交易已准备,执行S708;如果是在账户等待队列中找到,则确定待处理交易未准备,执行S710。
S708,覆盖账户准备队列中的冲突交易。
区块链节点根据待处理交易包含的账户地址和txNonce,将待处理账户对应的账户准备队列中的冲突交易删除,将待处理交易添加到账户准备队列中,然后执行S709。
S709,覆盖总准备队列中的冲突交易。
区块链节点可以根据冲突交易的交易哈希,将总准备队列中的冲突交易以及冲突交易的交易哈希删除,将待处理交易和待处理交易的交易哈希添加到总准备队列中,然后执行S711。
S710,覆盖账户等待队列中的冲突交易。
区块链节点根据待处理交易包含的账户地址和txNonce,将待处理账户对应的账户等待队列中的冲突交易删除,将待处理交易添加到账户等待队列中,然后执行S711。
S711,覆盖交易总队列中的冲突交易。
区块链节点根据冲突交易的交易哈希,将交易总队列中的冲突交易和冲突交易的交易哈希删除,将待处理交易以及待处理交易的交易哈希添加到交易总队列中,待处理交易接收完成,流程结束。
S712,校验交易是否已准备。
区块链节点根据待处理交易包含的账户地址,查找待处理账户对应的账户准备队列,交易已准备需要满足:账户准备队列为空,且待处理交易的txNonce等于当前世界状态下待处理账户的accountNonce;或者,账户准备队列不为空,且待处理交易的txNonce等于账户准备队列中最后一个交易的txNonce再加1。若待处理交易已准备,则执行S713;若待处理交易未准备,则执行S716。
S713,将待处理交易添加到账户准备队列中。
区块链节点会将待处理交易和待处理交易对应的txNonce添加进账户准备队列中的队尾,也就是说,待处理交易会成为账户准备队列中的最后一个交易,然后执行S714。
S714,查找账户等待队列中可以升级的交易并进行升级。
区块链节点会查找账户等待队列中是否存在可以升级的交易,然后对可以升级的交易进行升级。其中,升级是指将交易从账户等待队列,移动到账户准备队列。区块链节点会继续执行S715。
在一种可能的实现方式中,区块链节点确定是否存在可以升级的交易,并对其进行升级的一个可行方法为:区块链节点可以从账户等待队列的第一个交易开始循环,判断该交易的txNonce是否等于账户准备队列中最后一个交易的txNonce再加1,如果是则把该交易从账户准备队列中删除并添加到账户准备队列中(会成为账户准备队列中最后一个交易),并记录已升级的交易。
在一种可能的实现方式中,区块链节点确定是否存在可以升级的交易,并对其进行升级的一个可行方法为:当账户等待队列中的交易是按照交易对应的txNonce从小到大进行顺序排列时,区块链节点可以判断账户等待队列中的第一个交易的txNonce是否等于账户准备队列中最后一个交易的txNonce再加1,如果是则将和账户等待队列中的第一个交易对应的txNonce能构成顺序连续序列的txNonce对应的交易均确定为升级交易,将升级交易添加到账户准备队列中。
S715,将待处理交易和经过升级的交易添加到总准备队列中。
区块链节点会将待处理交易和经过升级的交易添加到总准备队列中,然后执行S717。
S716,将待处理交易添加到账户等待队列中。
区块链节点会将待处理交易和待处理交易对应的txNonce添加到账户等待队列中,然后执行S717。
S717,将待处理交易添加到交易总队列中。
区块链节点将待处理交易添加到交易总队列中后,待处理交易的接收流程结束。
采用本申请实施例提供的方法,可以有效接收txNonce未准备好的交易并缓存,待到txNonce准备好后正常打包该交易,提高区块链系统的容错性,并且保证生成候选区块时所打包的交易的txNonce与accountNonce的有效匹配,提高区块生成的成功率。另外,支持 同一账户以更高的txFee发送交易请求,覆盖交易池中的相同nonce的交易,提高用户使用区块链的灵活性。
区块链节点系统中具有出块权限的区块链节点,可以从总准备队列中的第一个交易开始,往后逐个交易打包进候选区块,但最终打包的交易个数不得大于配置模块里的区块交易数上限。每当有候选区块通过共识成为新的正式区块,插入区块链数据结构后,区块链节点系统中的每个区块链节点均可以执行刷新交易池操作。为便于理解,请参见图8,图8是本申请实施例提供的一种刷新交易池的流程示意图。如图8所示,刷新交易池的流程包括:
S801,统计新区块内每个账户对应的最大执行顺序标识。
区块链节点可以遍历新区块内的每个交易,从中找出每个账户的最大txNonce,建立从账户地址到账户最大txNonce的哈希映射,遍历该哈希映射,对于每个账户地址及其账户最大txNonce,均分别执行以下S802到S805。
S802,清理过时交易。
区块链节点根据账户地址查找账户对应的账户准备队列和账户等待队列,分别删除其中txNonce不大于账户最大txNonce的交易,根据删除的交易的交易哈希,删除总准备队列和总队列中的交易,继续执行S803。
S803,升级已准备交易。
区块链节点可以根据账户地址查找对应的账户等待队列,判断账户等待队列的第一个交易的txNonce是否等于账户最大txNonce加1,如果相等则升级该交易及后续在账户等待队列中txNonce连续的一系列交易,升级是指把交易从账户等待队列中删除,添加到账户准备队列和总准备队列,然后继续执行S804。
S804,删除账户余额不足的准备交易。
区块链节点可以根据账户地址查找对应的账户准备队列,判断账户准备队列的第一个交易的txFee是否大于当前世界状态下其所属账户的账户余额,如果大于则将该交易从账户准备队列、总准备队列及总队列中删除,继续执行S805。
S805,降级未准备交易。
区块链节点对于上述因账户余额不足而删除的交易的账户,将其账户准备队列中的所有交易降级,降级是指把交易从总准备队列和账户准备队列中删除,添加到账户等待队列,流程完成。
采用本申请实施例提供的方法,在新增区块时对交易池的刷新操作耗时不受交易池大小影响,只与区块大小相关,提升了交易池刷新操作的效率。
请参见图9,图9是本申请实施例提供的一种数据处理装置的结构示意图。该数据处理装置可以是运行于计算机设备的一个计算机程序(包括程序代码),例如该数据处理装置为一个应用软件;该装置可以用于执行本申请实施例提供的数据处理方法中的相应步骤。如图9所示,该数据处理装置1可以包括:获取模块101、交易过渡模块102、交易升级模块103以及交易添加模块104。
获取模块101,用于获取待处理账户发送的待处理交易,以及获取待处理账户对应的待处理账户准备队列和待处理账户等待队列;待处理交易包含有待处理执行顺序标识;待处理账户准备队列用于存储处于已准备状态的准备交易、以及与准备交易具有映射关系的执行顺序标识;待处理账户等待队列用于存储处于未准备状态的等待交易、以及与等待交易具有映射关系的执行顺序标识;
交易过渡模块102,用于若确定待处理交易处于已准备状态,则将待处理交易和待处理执行顺序标识添加至待处理账户准备队列,得到过渡账户准备队列;
交易升级模块103,用于在待处理账户等待队列中,将与待处理执行顺序标识能构成顺序标识连续序列的执行顺序标识,作为升级执行顺序标识,并将升级执行顺序标识和升级执行顺序标识对应的等待交易按序迁移至过渡账户准备队列,得到升级账户准备队列;
交易添加模块104,用于将升级账户准备队列中的待处理交易和升级执行顺序标识对应的等待交易添加至总准备队列中;总准备队列中的交易会按照交易插入时间顺序被打包进候选区块。
其中,获取模块101、交易过渡模块102、交易升级模块103以及交易添加模块104的具体实现方式可以参见上述图3所对应实施例中对S101-S104的描述,这里不再进行赘述。
请再参见图9,上述数据处理装置1,还包括:第一状态确定模块105。
第一状态确定模块105,用于若待处理账户准备队列为空队列,将待处理执行顺序标识和待处理账户的当前已执行交易标识进行比对;
第一状态确定模块105,还用于若待处理执行顺序标识和待处理账户的当前已执行交易标识相同,则确定待处理交易处于已准备状态;
第一状态确定模块105,还用于若待处理执行顺序标识和待处理账户的当前已执行交易标识不相同,则确定待处理交易处于未准备状态,将待处理交易和待处理执行顺序标识添加至待处理账户等待队列。
其中,第一状态确定模块105的具体实现方式可以参见上述图3所对应实施例中对S102的描述,这里不再进行赘述。
请再参见图9,上述数据处理装置1,还包括:第二状态确定模块106。
第二状态确定模块106,用于若待处理账户准备队列为非空队列,确定待处理执行顺序标识与待处理账户准备队列中最大的执行顺序标识之间的标识关系;
第二状态确定模块106,还用于若标识关系满足顺序连续关系,确定待处理交易处于已准备状态;
第二状态确定模块106,还用于若标识关系不满足顺序连续关系,确定待处理交易处于未准备状态,将待处理交易和待处理执行顺序标识添加至待处理账户等待队列。
其中,第二状态确定模块106的具体实现方式可以参见上述图3所对应实施例中对S102的描述,这里不再进行赘述。
请再参见图9,上述数据处理装置1,还包括:遍历模块107、冲突确定模块108、第一覆盖模块109以及第二覆盖模块110。
遍历模块107,用于根据待处理执行顺序标识遍历待处理账户准备队列和待处理账户等待队列,得到针对待处理交易的遍历结果;
冲突确定模块108,还用于若遍历结果指示待处理队列中存在具有待处理执行顺序标识的交易,则将待处理队列中的具有待处理执行顺序标识的交易,确定为冲突交易;待处理队列为待处理账户准备队列或待处理账户等待队列;
第一覆盖模块109,用于若确定待处理交易与冲突交易之间满足冲突覆盖条件,则基于待处理交易对冲突交易进行覆盖处理;
第二覆盖模块110,用于若待处理交易与冲突交易之间不满足冲突覆盖条件,则调用交易过渡模块来执行若待处理交易处于已准备状态,则将待处理交易和待处理执行顺序标识添加至待处理账户准备队列,得到过渡账户准备队列的步骤。
其中,遍历模块107、冲突确定模块108、第一覆盖模块109以及第二覆盖模块110的具体实现方式可以参见上述图5所对应实施例中对S203-S205的描述,这里不再进行赘述。
请再参见图9,上述数据处理装置1,还包括:覆盖确定模块111。
覆盖确定模块111,用于获取待处理交易的交易执行开销,以及获取冲突交易的交易执行开销;
覆盖确定模块111,还用于若待处理交易的交易执行开销大于冲突交易的交易执行开销,则确定待处理交易与冲突交易之间满足冲突覆盖条件;
覆盖确定模块111,还用于若待处理交易的交易执行开销小于或等于冲突交易的交易执行开销,则确定待处理交易与冲突交易之间不满足冲突覆盖条件,向待处理账户发送交易覆盖失败报错信息。
其中,覆盖确定模块111的具体实现方式可以参见上述图5所对应实施例中对S204的描述,这里不再进行赘述。
请再参见图9,第一覆盖模块109,包括:第一替换单元1091以及第二替换单元1092。
第一替换单元1091,用于若待处理队列为待处理账户准备队列,则在待处理账户准备队列中,将冲突交易替换为待处理交易,在总准备队列中,将冲突交易替换为待处理交易;
第二替换单元1092,用于若待处理队列为待处理账户等待队列,则在待处理账户等待队列中,将冲突交易替换为待处理交易。
其中,第一替换单元1091以及第二替换单元1092的具体实现方式可以参见上述图5所对应实施例中对S204的描述,这里不再进行赘述。
请再参见图9,上述数据处理装置1,还包括:第一交易处理模块112。
第一交易处理模块112,用于获取账户交易数量上限阈值;
第一交易处理模块112,还用于若待处理账户准备队列中的准备交易的数量和待处理账户等待队列中的等待交易的数量的总和等于账户交易数量上限阈值,则向待处理账户发送交易上限报错信息;
第一交易处理模块112,还用于若准备交易的数量和等待交易的数量的总和小于账户交易数量上限,则调用交易过渡模块来执行若待处理交易处于已准备状态,则将待处理交易和待处理执行顺序标识添加至待处理账户准备队列,得到过渡账户准备队列的步骤。
其中,第一交易处理模块112的具体实现方式可以参见上述图5所对应实施例中对S201的描述,这里不再进行赘述。
请再参见图9,上述数据处理装置1,还包括:第二交易处理模块113。
第二交易处理模块113,用于获取待处理账户的当前已执行交易数量;
第二交易处理模块113,还用于若待处理执行顺序标识小于当前已执行交易数量,则向待处理账户发送交易过时报错信息;
第二交易处理模块113,还用于若待处理执行顺序标识大于或等于当前已执行交易数量,则调用交易过渡模块来执行若待处理交易处于已准备状态,则将待处理交易和待处理执行顺序标识添加至待处理账户准备队列,得到过渡账户准备队列的步骤。
其中,第二交易处理模块113的具体实现方式可以参见上述图5所对应实施例中对S201的描述,这里不再进行赘述。
请再参见图9,上述数据处理装置1,还包括:第三交易处理模块114。
第三交易处理模块114,用于获取待处理交易的交易执行开销,查询待处理账户的账户资源;
第三交易处理模块114,还用于若账户资源小于交易执行开销,则向待处理账户发送资源不足报错信息;
第三交易处理模块114,还用于若账户资源大于或等于交易执行开销,则调用交易过渡模块来执行若确定待处理交易处于已准备状态,则将待处理交易和待处理执行顺序标识添加至待处理账户准备队列,得到过渡账户准备队列的步骤。
其中,第三交易处理模块114的具体实现方式可以参见上述图5所对应实施例中对S201的描述,这里不再进行赘述。
请再参见图9,上述数据处理装置1,还包括:交易打包模块115以及队列更新模块116。
交易打包模块115,用于将总准备队列中的交易按照交易插入时间顺序打包进候选区块中;候选区块中的交易数量小于或等于区块交易数量阈值;
队列更新模块116,用于对候选区块进行共识处理,得到新区块,遍历新区块,得到待处理账户的最大执行顺序标识;
队列更新模块116,还用于在待处理账户准备队列中,获取与第一待删除执行顺序标识具有映射关系的准备交易,作为待删除准备交易;第一待删除执行顺序标识为待处理账户准备队列中小于或等于最大执行顺序标识的执行顺序标识;
队列更新模块116,还用于在待处理账户准备队列中,删除待删除准备交易和第一待删除执行顺序标识,得到更新账户准备队列;
队列更新模块116,还用于在总准备队列中删除待删除准备交易,得到更新总准备队列;
队列更新模块116,还用于在待处理账户等待队列中,获取与第二待删除执行顺序标识具有映射关系的等待交易,作为待删除等待交易;第二待删除执行顺序标识为待处理账户等待队列中小于或等于最大执行顺序标识的执行顺序标识;
队列更新模块116,还用于在待处理账户等待队列中删除待删除等待交易和第二待删除执行顺序标识,得到更新账户等待队列。
其中,交易打包模块115以及队列更新模块116的具体实现方式可以参见上述图6所对应实施例中对S301-S306的描述,这里不再进行赘述。
请再参见图9,上述数据处理装置1,还包括:队列优化模块117。
队列优化模块117,用于获取更新账户等待队列中的最小执行顺序标识;
队列优化模块117,还用于根据最大执行顺序标识生成优化执行顺序标识;
队列优化模块117,还用于若最小执行顺序标识等于优化执行顺序标识,则在待处理账户等待队列中,将与最小执行顺序标识能构成顺序标识连续序列的执行顺序标识,作为优化升级执行顺序标识,将最小执行顺序标识、最小执行顺序标识对应的等待交易、优化升级执行顺序标识和优化升级执行顺序标识对应的等待交易按序迁移至更新账户准备队列,得到优化升级账户准备队列;
队列优化模块117,还用于将最小执行顺序标识、最小执行顺序标识对应的等待交易、优化升级执行顺序标识和优化升级执行顺序标识对应的等待交易按序添加至更新总准备队列中,得到优化升级总准备队列。
其中,队列优化模块117的具体实现方式可以参见上述图6所对应实施例中的可选实施例描述,这里不再进行赘述。
请再参见图9,上述数据处理装置1,还包括:队列删除模块118。
队列删除模块118,用于获取更新账户准备队列中的最小执行顺序标识对应的准备交易,作为待判定准备交易;
队列删除模块118,还用于获取待判定准备交易的交易执行开销,并查询待处理账户的账户资源;
队列删除模块118,还用于若待判定准备交易的交易执行开销大于账户资源,则从更新账户准备队列中删除待判定准备交易以及最小执行顺序标识,从更新总准备队列中删除待判定准备交易;
队列删除模块118,还用于在删除后的更新账户准备队列中,将大于最小执行顺序标识的执行顺序标识,作为降级执行顺序标识,并将降级执行顺序标识和降级执行顺序标识对应的准备交易迁移至更新账户等待队列,得到降级账户等待队列;
队列删除模块118,还用于将降级执行顺序标识和降级执行顺序标识对应的准备交易从删除后的更新账户准备队列中删除;
队列删除模块118,还用于将降级执行顺序标识和降级执行顺序标识对应的准备交易从删除后的更新总准备队列中删除。
其中,队列删除模块118的具体实现方式可以参见上述图6所对应实施例中的可选实施例的描述,这里不再进行赘述。
请参见图10,图10是本申请实施例提供的一种计算机设备的结构示意图。如图10所示,上述图9所对应实施例中的数据处理装置1可以应用于计算机设备1000,该计算机设备1000可以包括:处理器1001,网络接口1004和存储器1005,此外,上述计算机设备1000还可以包括:用户接口1003,和至少一个通信总线1002。其中,通信总线1002用于实现这些组件之间的连接通信。其中,用户接口1003可以包括显示屏(Display)、键盘(Keyboard),可选用户接口1003还可以包括标准的有线接口、无线接口。网络接口1004可选的可以包括标准的有线接口、无线接口(如WI-FI接口)。存储器1005可以是高速RAM存储器,也可以是非不稳定的存储器(non-volatile memory),例如至少一个磁盘存储器。存储器1005可选的还可以是至少一个位于远离前述处理器1001的存储装置。如图10所示,作为一种计算机可读存储介质的存储器1005中可以包括操作系统、网络通信模块、用户接口模块以及设备控制应用程序。
在如图10所示的计算机设备1000中,网络接口1004可提供网络通讯网元;而用户接口1003主要用于为用户提供输入的接口;而处理器1001可以用于调用存储器1005中存储的设备控制应用程序,以实现:
获取待处理账户发送的待处理交易,以及获取待处理账户对应的待处理账户准备队列和待处理账户等待队列;待处理交易包含有待处理执行顺序标识;待处理账户准备队列用于存储处于已准备状态的准备交易、以及与准备交易具有映射关系的执行顺序标识;待处理账户等待队列用于存储处于未准备状态的等待交易、以及与等待交易具有映射关系的执行顺序标识;
若确定待处理交易处于已准备状态,将待处理交易和待处理执行顺序标识添加至待处理账户准备队列,得到过渡账户准备队列;
在待处理账户等待队列中,将与待处理执行顺序标识能构成顺序标识连续序列的执行顺序标识,作为升级执行顺序标识,并将升级执行顺序标识和升级执行顺序标识对应的等待交易按序添加至过渡账户准备队列,得到升级账户准备队列;
将升级账户准备队列中的待处理交易和升级执行顺序标识对应的等待交易添加至总准备队列中;总准备队列中的交易会按照交易插入时间顺序被打包进候选区块。
应当理解,本申请实施例中所描述的计算机设备1000可执行前文任一个实施例对该数据处理方法的描述,在此不再赘述。另外,对采用相同方法的有益效果描述,也不再进行赘述。
此外,这里需要指出的是:本申请实施例还提供了一种计算机可读存储介质,且上述计算机可读存储介质中存储有前文提及的数据处理装置1所执行的计算机程序,且上述计算机程序包括程序指令,当上述处理器执行上述程序指令时,能够执行前文任一个实施例对上述数据处理方法的描述,因此,这里将不再进行赘述。另外,对采用相同方法的有益效果描述,也不再进行赘述。对于本申请所涉及的计算机可读存储介质实施例中未披露的技术细节,请参照本申请方法实施例的描述。
上述计算机可读存储介质可以是前述任一实施例提供的数据处理装置或者上述计算机设备的内部存储单元,例如计算机设备的硬盘或内存。该计算机可读存储介质也可以是该 计算机设备的外部存储设备,例如该计算机设备上配备的插接式硬盘,智能存储卡(smart media card,SMC),安全数字(secure digital,SD)卡,闪存卡(flash card)等。进一步地,该计算机可读存储介质还可以既包括该计算机设备的内部存储单元也包括外部存储设备。该计算机可读存储介质用于存储该计算机程序以及该计算机设备所需的其他程序和数据。该计算机可读存储介质还可以用于暂时地存储已经输出或者将要输出的数据。
此外,这里需要指出的是:本申请实施例还提供了一种计算机程序产品或计算机程序,该计算机程序产品或计算机程序包括计算机指令,该计算机指令存储在计算机可读存储介质中。计算机设备的处理器从计算机可读存储介质读取该计算机指令,处理器执行该计算机指令,使得该计算机设备执行前文图3、图4任一个所对应实施例提供的方法。
本申请实施例的说明书和权利要求书及附图中的术语“第一”、“第二”等是用于区别不同对象,而非用于描述特定顺序。此外,术语“包括”以及它们任何变形,意图在于覆盖不排他的包含。例如包含了一系列步骤或单元的过程、方法、装置、产品或设备没有限定于已列出的步骤或模块,而是可选地还包括没有列出的步骤或模块,或可选地还包括对于这些过程、方法、装置、产品或设备固有的其他步骤单元。
本领域普通技术人员可以意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、计算机软件或者二者的结合来实现,为了清楚地说明硬件和软件的可互换性,在上述说明中已经按照网元一般性地描述了各示例的组成及步骤。这些网元究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的网元,但是这种实现不应认为超出本申请的范围。
以上所揭露的仅为本申请较佳实施例而已,当然不能以此来限定本申请之权利范围,因此依本申请权利要求所作的等同变化,仍属本申请所涵盖的范围。

Claims (19)

  1. 一种基于区块链的数据处理方法,所述方法由计算机设备执行,所述方法包括:
    获取待处理账户发送的待处理交易,以及获取所述待处理账户对应的待处理账户准备队列和待处理账户等待队列;所述待处理交易包含有待处理执行顺序标识;所述待处理账户准备队列用于存储处于已准备状态的准备交易、以及与所述准备交易具有映射关系的执行顺序标识;所述待处理账户等待队列用于存储处于未准备状态的等待交易、以及与所述等待交易具有映射关系的执行顺序标识;
    若确定所述待处理交易处于所述已准备状态,将所述待处理交易和所述待处理执行顺序标识添加至所述待处理账户准备队列,得到过渡账户准备队列;
    在所述待处理账户等待队列中,将与所述待处理执行顺序标识能构成顺序标识连续序列的执行顺序标识,作为升级执行顺序标识,并将所述升级执行顺序标识和所述升级执行顺序标识对应的等待交易按序迁移至所述过渡账户准备队列,得到升级账户准备队列;
    将所述升级账户准备队列中的所述待处理交易和所述升级执行顺序标识对应的等待交易添加至总准备队列中;所述总准备队列中的交易会按照交易插入时间顺序被打包进候选区块。
  2. 根据权利要求1所述的方法,所述确定所述待处理交易处于所述已准备状态,包括:
    若所述待处理账户准备队列为空队列,将所述待处理执行顺序标识和所述待处理账户的当前已执行交易数量进行比对;
    若所述待处理执行顺序标识和所述待处理账户的当前已执行交易数量相同,确定所述待处理交易处于所述已准备状态。
  3. 根据权利要求2所述的方法,所述方法还包括:
    若所述待处理执行顺序标识和所述待处理账户的当前已执行交易数量不相同,则确定所述待处理交易处于所述未准备状态,将所述待处理交易和所述待处理执行顺序标识添加至所述待处理账户等待队列。
  4. 根据权利要求1所述的方法,所述确定所述待处理交易处于所述已准备状态,包括:
    若所述待处理账户准备队列为非空队列,确定所述待处理执行顺序标识与所述待处理账户准备队列中最大的执行顺序标识之间的标识关系;
    若所述标识关系满足顺序连续关系,确定所述待处理交易处于所述已准备状态。
  5. 根据权利要求4所述的方法,所述方法还包括:
    若所述标识关系不满足顺序连续关系,确定所述待处理交易处于所述未准备状态,将所述待处理交易和所述待处理执行顺序标识添加至所述待处理账户等待队列。
  6. 根据权利要求1所述的方法,还包括:
    根据所述待处理执行顺序标识遍历所述待处理账户准备队列和所述待处理账户等待队列,得到针对所述待处理交易的遍历结果;
    当所述遍历结果指示待处理队列中存在具有所述待处理执行顺序标识的交易时,将所述待处理队列中的具有所述待处理执行顺序标识的交易,确定为冲突交易;所述待处理队列为所述待处理账户准备队列或所述待处理账户等待队列;
    若确定所述待处理交易与所述冲突交易之间满足冲突覆盖条件,则基于所述待处理交易对所述冲突交易进行覆盖处理;
    当所述遍历结果指示所述待处理账户准备队列和所述待处理账户等待队列中不存在具有所述待处理执行顺序标识的交易时,执行所述若确定所述待处理交易处于所述已准备状态,则将所述待处理交易和所述待处理执行顺序标识添加至所述待处理账户准备队列,得到过渡账户准备队列的步骤。
  7. 根据权利要求6所述的方法,所述确定所述待处理交易与所述冲突交易之间满足冲突覆盖条件,包括:
    获取所述待处理交易的交易执行开销,以及获取所述冲突交易的交易执行开销;
    若所述待处理交易的交易执行开销大于所述冲突交易的交易执行开销,则确定所述待处理交易与所述冲突交易之间满足冲突覆盖条件。
  8. 根据权利要求7所述的方法,所述方法还包括:
    若所述待处理交易的交易执行开销小于或等于所述冲突交易的交易执行开销,则确定所述待处理交易与所述冲突交易之间不满足冲突覆盖条件,向所述待处理账户发送交易覆盖失败报错信息。
  9. 根据权利要求6所述的方法,所述基于所述待处理交易对所述冲突交易进行覆盖处理,包括:
    若所述待处理队列为所述待处理账户准备队列,则在所述待处理账户准备队列中,将所述冲突交易替换为所述待处理交易,在所述总准备队列中,将所述冲突交易替换为所述待处理交易;
    若所述待处理队列为所述待处理账户等待队列,则在所述待处理账户等待队列中,将所述冲突交易替换为所述待处理交易。
  10. 根据权利要求1所述的方法,所述方法还包括:
    获取账户交易数量上限阈值;
    若所述准备交易的数量和所述等待交易的数量的总和等于所述账户交易数量上限阈值,则向所述待处理账户发送交易上限报错信息;
    若所述准备交易的数量和所述等待交易的数量的总和小于所述账户交易数量上限,则执行所述若确定所述待处理交易处于所述已准备状态,则将所述待处理交易和所述待处理执行顺序标识添加至所述待处理账户准备队列,得到过渡账户准备队列的步骤。
  11. 根据权利要求1所述的方法,所述方法还包括:
    获取所述待处理账户的当前已执行交易数量;
    若所述待处理执行顺序标识小于所述当前已执行交易数量,则向所述待处理账户发送交易过时报错信息;
    若所述待处理执行顺序标识大于或等于所述当前已执行交易数量,则执行所述若所述待处理交易处于所述已准备状态,则将所述待处理交易和所述待处理执行顺序标识添加至所述待处理账户准备队列,得到过渡账户准备队列的步骤。
  12. 根据权利要求1所述的方法,所述方法还包括:
    获取所述待处理交易的交易执行开销,查询所述待处理账户的账户资源;
    若所述账户资源小于所述交易执行开销,则向所述待处理账户发送资源不足报错信息;
    若所述账户资源大于或等于所述交易执行开销,则执行所述若确定所述待处理交易处于所述已准备状态,则将所述待处理交易和所述待处理执行顺序标识添加至所述待处理账户准备队列,得到过渡账户准备队列的步骤。
  13. 根据权利要求1所述的方法,所述方法还包括:
    将所述总准备队列中的交易按照所述交易插入时间顺序打包进候选区块中;所述候选区块中的交易数量小于或等于区块交易数量阈值;
    对所述候选区块进行共识处理,得到新区块,遍历所述新区块,得到所述待处理账户的最大执行顺序标识;
    在所述待处理账户准备队列中,获取与第一待删除执行顺序标识具有映射关系的准备交易,作为待删除准备交易;所述第一待删除执行顺序标识为所述待处理账户准备队列中小于或等于所述最大执行顺序标识的执行顺序标识;
    在所述待处理账户准备队列中,删除所述待删除准备交易和所述第一待删除执行顺序标识,得到更新账户准备队列;在所述总准备队列中删除所述待删除准备交易,得到更新总准备队列;
    在所述待处理账户等待队列中,获取与第二待删除执行顺序标识具有映射关系的等待交易,作为待删除等待交易;所述第二待删除执行顺序标识为所述待处理账户等待队列中小于或等于所述最大执行顺序标识的执行顺序标识;
    在所述待处理账户等待队列中删除所述待删除等待交易和所述第二待删除执行顺序标识,得到更新账户等待队列。
  14. 根据权利要求13所述的方法,所述方法还包括:
    获取所述更新账户等待队列中的最小执行顺序标识;
    根据所述最大执行顺序标识生成优化执行顺序标识;
    若所述最小执行顺序标识等于所述优化执行顺序标识,则在所述待处理账户等待队列中,将与所述最小执行顺序标识能构成顺序标识连续序列的执行顺序标识,作为优化升级执行顺序标识,并将所述最小执行顺序标识、所述最小执行顺序标识对应的等待交易、所述优化升级执行顺序标识和所述优化升级执行顺序标识对应的等待交易按序迁移至更新账户准备队列,得到优化升级账户准备队列;
    将所述最小执行顺序标识、所述最小执行顺序标识对应的等待交易、所述优化升级执行顺序标识和所述优化升级执行顺序标识对应的等待交易按序添加至所述更新总准备队列中,得到优化升级总准备队列。
  15. 根据权利要求13所述的方法,所述方法还包括:
    获取所述更新账户准备队列中的最小执行顺序标识对应的准备交易,作为待判定准备交易;
    获取所述待判定准备交易的交易执行开销,并查询所述待处理账户的账户资源;
    若所述待判定准备交易的交易执行开销大于所述账户资源,则从所述更新账户准备队列中删除所述待判定准备交易以及所述最小执行顺序标识,从所述更新总准备队列中删除所述待判定准备交易;
    在删除后的更新账户准备队列中,将大于所述最小执行顺序标识的执行顺序标识,作为降级执行顺序标识,并将所述降级执行顺序标识和所述降级执行顺序标识对应的准备交易迁移至所述更新账户等待队列,得到降级账户等待队列;
    将所述降级执行顺序标识和所述降级执行顺序标识对应的准备交易从所述删除后的更新账户准备队列中删除;
    将所述降级执行顺序标识和所述降级执行顺序标识对应的准备交易从所述删除后的更新总准备队列中删除。
  16. 一种基于区块链的数据处理装置,所述装置部署在计算机设备上,所述装置包括:
    获取模块,用于获取待处理账户发送的待处理交易,以及获取所述待处理账户对应的待处理账户准备队列和待处理账户等待队列;所述待处理交易包含有待处理执行顺序标识;所述待处理账户准备队列用于存储处于已准备状态的准备交易、以及与所述准备交易具有映射关系的执行顺序标识;所述待处理账户等待队列用于存储处于未准备状态的等待交易、以及与所述等待交易具有映射关系的执行顺序标识;
    交易过渡模块,用于若确定所述待处理交易处于所述已准备状态,将所述待处理交易和所述待处理执行顺序标识添加至所述待处理账户准备队列,得到过渡账户准备队列;
    交易升级模块,用于在所述待处理账户等待队列中,将与所述待处理执行顺序标识能构成顺序标识连续序列的执行顺序标识,作为升级执行顺序标识,并将所述升级执行顺序标识和所述升级执行顺序标识对应的等待交易按序迁移至所述过渡账户准备队列,得到升级账户准备队列;
    交易添加模块,用于将所述升级账户准备队列中的所述待处理交易和所述升级执行顺序标识对应的等待交易添加至总准备队列中;所述总准备队列中的交易会按照交易插入时间顺序被打包进候选区块。
  17. 一种计算机设备,包括:处理器、存储器以及网络接口;
    所述处理器与所述存储器、所述网络接口相连,其中,所述网络接口用于提供数据通信功能,所述存储器用于存储程序代码,所述处理器用于调用所述程序代码,以执行权利要求1-15任一项所述的方法。
  18. 一种计算机可读存储介质,所述计算机可读存储介质中存储有计算机程序,所述计算机程序适于由处理器加载并执行权利要求1-15任一项所述的方法。
  19. 一种计算机程序产品,包括计算机程序/指令,所述计算机程序/指令被处理器执行时实现权利要求1-15任一项所述的方法。
PCT/CN2022/131599 2022-01-25 2022-11-14 一种基于区块链的数据处理方法和相关装置 WO2023142605A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202210090413.8 2022-01-25
CN202210090413.8A CN116542668A (zh) 2022-01-25 2022-01-25 一种基于区块链的数据处理方法、设备及可读存储介质

Publications (1)

Publication Number Publication Date
WO2023142605A1 true WO2023142605A1 (zh) 2023-08-03

Family

ID=87451120

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/131599 WO2023142605A1 (zh) 2022-01-25 2022-11-14 一种基于区块链的数据处理方法和相关装置

Country Status (3)

Country Link
US (1) US20230336368A1 (zh)
CN (1) CN116542668A (zh)
WO (1) WO2023142605A1 (zh)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117278326A (zh) * 2023-11-21 2023-12-22 四川易利数字城市科技有限公司 一种基于信用分层的区块链数据安全性提升方法

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20170068566A1 (en) * 2015-09-08 2017-03-09 International Business Machines Cororation Ordering repeating elements within a message
CN110738497A (zh) * 2019-12-19 2020-01-31 腾讯科技(深圳)有限公司 一种数据处理方法、装置、节点设备及存储介质
US20200042513A1 (en) * 2018-07-31 2020-02-06 Fujitsu Limited Transaction control device, transaction control method
CN111882322A (zh) * 2020-07-20 2020-11-03 杭州溪塔科技有限公司 一种按顺序打包交易的方法、装置及电子设备
CN112926981A (zh) * 2021-03-18 2021-06-08 腾讯科技(深圳)有限公司 用于区块链的交易信息处理方法、装置、介质及电子设备

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20170068566A1 (en) * 2015-09-08 2017-03-09 International Business Machines Cororation Ordering repeating elements within a message
US20200042513A1 (en) * 2018-07-31 2020-02-06 Fujitsu Limited Transaction control device, transaction control method
CN110738497A (zh) * 2019-12-19 2020-01-31 腾讯科技(深圳)有限公司 一种数据处理方法、装置、节点设备及存储介质
CN111882322A (zh) * 2020-07-20 2020-11-03 杭州溪塔科技有限公司 一种按顺序打包交易的方法、装置及电子设备
CN112926981A (zh) * 2021-03-18 2021-06-08 腾讯科技(深圳)有限公司 用于区块链的交易信息处理方法、装置、介质及电子设备

Also Published As

Publication number Publication date
CN116542668A (zh) 2023-08-04
US20230336368A1 (en) 2023-10-19

Similar Documents

Publication Publication Date Title
WO2022188831A1 (zh) 一种基于区块链的区块共识方法以及相关设备
US9405574B2 (en) System and method for transmitting complex structures based on a shared memory queue
US20210256016A1 (en) Blockchain system and method
CN112380149B (zh) 基于节点内存的数据处理方法、装置、设备以及介质
CN110191428B (zh) 一种基于智能云平台的数据分配方法
US20230074102A1 (en) Method and apparatus for processing data based on block chain, device and readable storage medium
US9372879B1 (en) Balanced append tree data structure
US9465880B2 (en) Optimizing storage in a publish / subscribe environment
US9830333B1 (en) Deterministic data replication with conflict resolution
CN112084258A (zh) 一种数据同步方法和装置
CN110413650B (zh) 一种业务数据的处理方法、装置、设备和存储介质
WO2023011022A1 (zh) 基于区块链的数据处理方法、设备及计算机可读存储介质
US20230052935A1 (en) Asynchronous accounting method and apparatus for blockchain, medium and electronic device
CN112685499B (zh) 一种工作业务流的流程数据同步方法、装置及设备
US20120224482A1 (en) Credit feedback system for parallel data flow control
US20230102617A1 (en) Repeat transaction verification method, apparatus, and device, and medium
WO2021051782A1 (zh) 区块链的共识方法、装置及设备
WO2023056797A1 (zh) 基于区块链的数据处理方法、装置、设备及存储介质
WO2023142605A1 (zh) 一种基于区块链的数据处理方法和相关装置
US20230370285A1 (en) Block-chain-based data processing method, computer device, computer-readable storage medium
US9578120B1 (en) Messaging with key-value persistence
CN110049133B (zh) 一种dns区文件全量下发的方法和装置
CN116977067A (zh) 基于区块链的数据处理方法、装置、设备及可读存储介质
CN115129779A (zh) 数据库的同步方法、装置及可读介质
WO2023160040A1 (zh) 基于区块链的数据处理方法、装置、设备及可读存储介质

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22923399

Country of ref document: EP

Kind code of ref document: A1