WO2023098042A1 - 基于区块链的交易共识方法、装置、设备及存储介质 - Google Patents

基于区块链的交易共识方法、装置、设备及存储介质 Download PDF

Info

Publication number
WO2023098042A1
WO2023098042A1 PCT/CN2022/100649 CN2022100649W WO2023098042A1 WO 2023098042 A1 WO2023098042 A1 WO 2023098042A1 CN 2022100649 W CN2022100649 W CN 2022100649W WO 2023098042 A1 WO2023098042 A1 WO 2023098042A1
Authority
WO
WIPO (PCT)
Prior art keywords
block
consensus
blockchain
transaction
message package
Prior art date
Application number
PCT/CN2022/100649
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 WO2023098042A1 publication Critical patent/WO2023098042A1/zh

Links

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/382Payment protocols; Details thereof insuring higher security of transaction
    • G06Q20/3825Use of electronic signatures
    • 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/382Payment protocols; Details thereof insuring higher security of transaction
    • G06Q20/3827Use of message hashing
    • 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/382Payment protocols; Details thereof insuring higher security of transaction
    • G06Q20/3829Payment protocols; Details thereof insuring higher security of transaction involving key management
    • 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

Definitions

  • the embodiments of the present application relate to the technical field of financial technology (Fintech), and in particular to a blockchain-based transaction consensus method, device, equipment, and storage medium.
  • Fetech technical field of financial technology
  • the Byzantine consensus algorithm is usually used to complete the block. Since the block vote of each blockchain must contain the hash of the parent block and the result of the current block, all the nodes participating in the consensus in the blockchain need to follow the transaction
  • the sorting adopts a serial method for block consensus and execution to complete the chaining of blocks on the blockchain.
  • the embodiment of the present application provides a block chain-based transaction consensus method, device, equipment, and storage medium to overcome the block consensus of all transaction blocks in the block chain in the related art, which leads to block chain
  • the execution efficiency is very low, which affects the performance of the blockchain system.
  • the embodiment of the present application provides a blockchain-based transaction consensus method, including:
  • any consensus node of the blockchain stores the transaction information in the transaction pool and broadcasts the transaction information to other consensus nodes;
  • the leader node of the blockchain packs the transaction information in the transaction pool to obtain multiple transaction blocks, and puts each transaction block into a pre-prepared message package to obtain multiple pre-prepared message packages, wherein the pre-prepared
  • the preparation message package includes the transaction block and the first verification information
  • the leader node of the blockchain broadcasts each pre-prepared message packet to all consensus nodes of the blockchain, and each consensus node of the blockchain verifies the validity of the pre-prepared message packet;
  • any consensus node of the block chain successfully verifies the received pre-preparation message package, it will broadcast the preparation message package to other consensus nodes, wherein the preparation message package includes the block hash of the transaction block and the first 2. Verification information; other consensus nodes of the blockchain verify the validity of the preparation message package, and store the successful preparation message package locally;
  • the submission message package will be broadcast to other consensus nodes, wherein the submission message package includes the block hash of the transaction block and the first 3. Verification information; other consensus nodes of the blockchain verify the validity of the submission message package, and store the successfully verified submission message package locally;
  • the transaction block is extracted from the corresponding pre-prepared message packet to complete the sorting consensus of each transaction block.
  • the first verification information includes a block index, a view, and a signature of a pre-prepared message package; correspondingly, each consensus node of the blockchain validates the pre-prepared message package Validity verification, including: if any consensus node of the blockchain has not received the pre-prepared message package, then verify the validity of the pre-prepared message package according to the block index, view information and pre-prepared message package signature verify.
  • the verification of the validity of the pre-prepared message package according to the block index, view information and signature of the pre-prepared message package includes: if the block index is greater than the block chain If the current height value is less than the sum of the current height value of the blockchain and the preset limit value, it is determined that the block index is valid; if the view is not less than the view of the current node of the blockchain, the view is determined Valid; calculate the hash of the pre-prepared message package, and obtain the public key of the leader node of the blockchain according to the hash of the pre-prepared message package; if the public key of the leader node of the blockchain is determined If it matches the signature of the pre-prepared message packet, it is determined that the signature of the pre-prepared message packet is valid; if the block index, the view and the signature of the pre-prepared message packet are all valid, it is determined that the verification of the pre-prepared message packet is successful .
  • the transaction block is extracted from the corresponding pre-prepared message packet, and the transaction block is completed.
  • the sorting consensus it also includes: any consensus node of the blockchain puts the transaction blocks into the block queue; each consensus node of the blockchain extracts the target transaction to be executed from the block queue block, and execute the target transaction block to obtain the corresponding execution result; any consensus node of the blockchain will upload the corresponding transaction block to the chain according to the execution result of the target transaction block to be executed.
  • each consensus node of the block chain extracts the target transaction block to be executed from the block queue, executes the target transaction block to obtain a corresponding execution result; Any consensus node uploads the corresponding transaction block to the chain according to the execution result of the target transaction block to be executed, including: each consensus node of the block chain extracts the target transaction block to be executed from the block queue , execute the target transaction block to obtain the corresponding execution result and block execution hash, generate a checkpoint message package, and broadcast the checkpoint message package to other consensus nodes, wherein the checkpoint message package includes all The block execution hash of the target transaction block and the fourth verification information; other consensus nodes of the blockchain verify the validity of the checkpoint message package, and store the successfully verified checkpoint message package locally; if When the number of checkpoint message packets with consistent execution results of the target transaction block stored by any consensus node of the blockchain reaches a preset ratio, it is determined that all consensus nodes have reached a consensus on the execution results of the target transaction block, and Putting the target transaction block
  • the embodiment of the present application provides a blockchain-based transaction consensus device, including:
  • the transaction upload module is used for responding to the transaction information uploaded by the client, any consensus node of the block chain stores the transaction information in the transaction pool, and broadcasts the transaction information to other consensus nodes;
  • the first processing module is used for the leader node of the blockchain to package the transaction information in the transaction pool to obtain multiple transaction blocks, and put each transaction block into the pre-preparation message package to obtain multiple pre-preparation A message packet, wherein the pre-prepared message packet includes the transaction block and first verification information; the leader node of the block chain broadcasts each pre-prepared message packet to all consensus nodes of the block chain, and the block chain Each consensus node verifies the validity of the pre-prepared message package;
  • the second processing module is used to broadcast the preparation message package to other consensus nodes if any consensus node of the block chain successfully verifies the received pre-preparation message package, wherein the preparation message package includes the transaction block The block hash and the second verification information; other consensus nodes of the block chain verify the validity of the preparation message package, and store the successful preparation message package locally;
  • the third processing module is configured to broadcast a submission message package to other consensus nodes if the number of preparation message packages stored by any consensus node of the blockchain reaches a preset ratio, wherein the submission message package includes the transaction block The block hash and the third verification information; other consensus nodes of the blockchain verify the validity of the submission message package, and store the successfully verified submission message package locally;
  • the sorting consensus module is used to extract the transaction block from the corresponding pre-prepared message package if the number of submission message packages stored by any consensus node of the blockchain reaches the preset ratio, so as to complete the sorting consensus of each transaction block .
  • the first verification information includes a block index, a view, and a signature of a pre-prepared message package; the first processing module is specifically configured to If the pre-prepared message package is used, the validity of the pre-prepared message package is verified according to the block index, view information and signature of the pre-prepared message package.
  • the first processing module is specifically configured to: if the block index is greater than the current height value of the blockchain and less than the sum of the current height value of the blockchain and a preset limit value, Then determine that the block index is valid; if the view is not less than the view of the current node of the block chain, then determine that the view is valid; calculate the hash of the pre-prepared message package, and according to the pre-prepared message package Obtain the public key of the leading node of the block chain through the hash; if it is determined that the public key of the leading node of the block chain matches the signature of the pre-prepared message packet, then determine that the signature of the pre-prepared message packet is valid; If the block index, the view, and the signature of the pre-prepared message package are all valid, it is determined that the verification of the pre-prepared message package is successful.
  • the device also includes:
  • Execute the consensus module which is used for any consensus node of the blockchain to put the transaction blocks into the block queue; each consensus node of the blockchain extracts the target transaction block to be executed from the block queue , and execute the target transaction block to obtain a corresponding execution result; any consensus node of the block chain uploads the corresponding transaction block to the chain according to the execution result of the target transaction block to be executed.
  • the execution consensus module is specifically used for each consensus node of the blockchain to extract the target transaction block to be executed from the block queue, and execute the target transaction block to obtain the corresponding Execution result and block execution hash, and generate a checkpoint message package, and broadcast the checkpoint message package to other consensus nodes, wherein the checkpoint message package includes the block execution hash of the target transaction block And the fourth verification information; other consensus nodes of the blockchain verify the validity of the checkpoint message package, and store the successfully verified checkpoint message package locally; if any consensus node of the blockchain stores all If the number of checkpoint message packets with the same execution result of the target transaction block reaches the preset ratio, it is determined that all consensus nodes agree on the execution result of the target transaction block, and according to the execution result of the target transaction block, the The target transaction block is uploaded to the chain.
  • an embodiment of the present application provides a service device, including: a processor and a memory;
  • the memory stores computer-executable instructions
  • the processor executes the computer-executed instructions stored in the memory, so that the processor executes the blockchain-based transaction consensus method described in the first aspect and various possible designs of the first aspect.
  • the embodiment of the present application provides a computer-readable storage medium, the computer-readable storage medium stores computer-executable instructions, and when the processor executes the computer-executable instructions, the above first aspect and the first Various possible designs of the blockchain-based transaction consensus method described.
  • the embodiment of the present application provides a computer program product, including a computer program.
  • the computer program is executed by a processor, the blockchain-based Transaction consensus method.
  • the leader node of the block chain obtains multiple transaction blocks from the transaction pool, it puts each transaction block into the pre-prepared In order to obtain multiple pre-prepared message packets; for each pre-prepared message packet, the following sorting consensus is executed in parallel: the leader node of the blockchain broadcasts each pre-prepared message packet to all consensus nodes of the blockchain, and the block Each consensus node of the chain verifies the validity of the pre-preparation message package; if any consensus node of the blockchain successfully verifies the received pre-preparation message package, it broadcasts the preparation message package to other consensus nodes; Other consensus nodes verify the validity of the preparation message package, and store the successfully verified preparation message package locally; if the number of preparation message packages stored by any consensus node of the blockchain reaches the preset ratio, it will be broadcast to other consensus nodes Submit the message package; other consensus nodes in the blockchain verify the validity of the prepared message package, and store the successfully verified submission message package locally
  • Fig. 1 is a schematic diagram of the consensus process of transaction blocks in the block chain of the prior art
  • Fig. 2 is a schematic flow diagram 1 of the blockchain-based transaction consensus method provided by the embodiment of the present application;
  • Fig. 3 is the second schematic flow diagram of the blockchain-based transaction consensus method provided by the embodiment of the present application.
  • FIG. 4 is a schematic structural diagram of a blockchain-based transaction consensus device provided by an embodiment of the present application.
  • FIG. 5 is a schematic diagram of a hardware structure of a service device provided by an embodiment of the present application.
  • Byzantine Consensus Algorithm Reach a consensus in the scenario where a small number of nodes do evil (such as forged messages), and use cryptographic algorithms such as signatures, signature verification, and hashing to ensure tamper-proof, anti-forgery, and non-repudiation in the process of message delivery.
  • the complexity is reduced from exponential to polynomial level.
  • Consensus node A node that participates in the consensus process in the blockchain, and the consensus node elects a leader node.
  • Leader node Responsible for packaging transactions into blocks and initiating block consensus. There is only one leader node in each round of consensus.
  • View Record the consensus status of each node, and the same view node maintains the same node list of consensus nodes. View switching occurs when the leader node fails.
  • the transaction processing module of blockchain can be abstracted as a transaction-based state machine.
  • the state refers to the state of all accounts in the blockchain.
  • the blockchain uses transactions as a state transition function, and updates from the old state to the new state according to the transaction content.
  • the blockchain starts from the genesis block state, continuously collects the transactions that occur on the blockchain network, and the leader node sorts and packages the transactions into blocks, and executes the transactions in the blocks among all consensus nodes participating in the consensus.
  • the transactions in a block are executed on multiple consensus nodes and the status is consistent, it is said that a consensus has been reached on the block, and the block is permanently recorded in the blockchain to complete the block on-chain.
  • the current transaction consensus process of the traditional blockchain is: the leader node of the blockchain takes a certain amount of transaction blocks from the transaction pool and sorts them. As shown in Figure 1, the leader node obtains transaction information, including The sorted transaction blocks include transaction block 1, transaction block 2, transaction block 3...transaction block n, and then the leader node broadcasts and sends it to all consensus nodes participating in the consensus for consensus.
  • the embodiment of this application provides the following technical solution: after the leader node of the blockchain obtains multiple transaction blocks from the transaction pool, it puts each transaction block into the pre-prepared message package to obtain multiple Pre-prepared message package; for each pre-prepared message package, the following sorting consensus is executed in parallel: the leader node of the blockchain broadcasts each pre-prepared message package to all consensus nodes of the blockchain, and each consensus node of the blockchain The validity of the pre-prepared message package is verified; if any consensus node of the blockchain successfully verifies the received pre-prepared message package, it broadcasts the pre-prepared message package to other consensus nodes; other consensus nodes of the blockchain verify the pre-prepared message package Perform validity verification, and store the successfully verified preparation message package locally; if the number of preparation message packages stored by any consensus node of the blockchain reaches the preset ratio, the submission message package will be broadcast to other consensus nodes; the blockchain Other consensus nodes of the blockchain verify the validity of the prepared message package, and store the successfully verified submitted message package locally; if the number of submitted
  • FIG. 2 is a first schematic flow diagram of a blockchain-based transaction consensus method provided by an embodiment of the present application. This embodiment is applied to the blockchain of the server, and the blockchain includes consensus nodes, wherein the leader node is a node elected by all consensus nodes.
  • the above method is described in detail as follows:
  • any consensus node of the blockchain In response to the transaction information uploaded by the client, any consensus node of the blockchain stores the transaction information in the transaction pool, and broadcasts the transaction information to other consensus nodes.
  • the client can be any client that has a transaction behavior, and the client generates transaction information according to the transaction behavior, and sends the transaction information to any consensus node of the block chain. For example, a user purchases a commodity in an online mall and completes the transaction through the client, and the client sends the transaction information of the purchased commodity to any consensus node of the blockchain.
  • any consensus node of the blockchain is any node among the consensus nodes in the blockchain.
  • the leader node is elected from the consensus nodes of the blockchain.
  • S202 The leader node of the blockchain packs the transaction information in the transaction pool to obtain multiple transaction blocks, and puts each transaction block into a pre-prepared message package to obtain multiple pre-prepared message packages, in which The pre-preparation message package includes the transaction block and the first verification information.
  • the process for the leader node to package the transaction information in the transaction pool to obtain multiple transaction blocks is: to package the transaction information in batches according to the transaction quantity to obtain multiple transaction blocks, wherein each transaction block contains the same amount of transaction information.
  • the process of putting each transaction block into a pre-prepared message packet to obtain multiple pre-prepared message packets is: according to the transaction block and the first verification information of the pre-prepared message packet, pack it into the pre-prepared message packet, and obtain Multiple pre-prepared message bundles.
  • the first verification information may include a block index, a view, and a signature of a pre-prepared message package.
  • the block index is the index of the transaction block
  • the view is the view corresponding to the current node.
  • the multiple transaction blocks obtained by packaging the transaction information in the transaction pool by the leader node can be recorded as: ⁇ block(i), block(i+1), ..., block(i+N) ⁇
  • the corresponding preprepare message package can be recorded as: ⁇ PrePrepare(i), PrePrepare(i+1), ..., PrePrepare(i+N) ⁇
  • PrePrepare(i) ⁇ i, view, block(i), sig ⁇
  • i is the block index of the transaction block
  • view is the view when sending the pre-prepared message
  • block(i) is the transaction block
  • sig is the signature of the pre-prepared message package.
  • S203 The leader node of the blockchain broadcasts each pre-prepared message package to all consensus nodes of the blockchain, and each consensus node of the blockchain verifies the validity of the pre-prepared message package.
  • the first verification information includes block index, view, and signature of the pre-prepared message package; correspondingly, each consensus node of the blockchain verifies the validity of the pre-prepared message package, including: if any If a consensus node has not received the pre-prepared message package, it will verify the validity of the pre-prepared message package according to the block index, view information and pre-prepared message package signature.
  • the validity of the pre-prepared message package is verified according to the block index, view information and pre-prepared message package signature.
  • the specific process includes: if the block index is greater than the current height value of the blockchain and less than the current height of the blockchain value and the preset limit value, it is determined that the block index is valid; if the view is not less than the view of the current node of the blockchain, it is determined that the view is valid; calculate the hash of the pre-prepared message package, and according to the pre-prepared message package Hash to get the public key of the leading node of the blockchain; if it is determined that the public key of the leading node of the blockchain matches the signature of the pre-prepared message package, it is determined that the signature of the pre-prepared message package is valid; if the block index, view and pre-prepared If the message package signatures are valid, it is determined that the verification of the pre-prepared message package is successful.
  • the hash calculated according to the block index, view, and transaction block can be used as the hash of the pre-prepared message package; and the hash of the pre-prepared message package can be used as plaintext to obtain the public key.
  • verifying that the block index i is valid means that the block index is greater than the current height value of the blockchain and less than the sum of the current height value of the blockchain and the preset limit value, which can be expressed as: h ⁇ i ⁇ ( h+waterMarkLimit), where h is the current height value of the blockchain; waterMarkLimit is the preset limit value, which is used to limit the number of blocks that can be consensused at the same time, so as to ensure the stability of the blockchain system.
  • Verify that the view view is valid which means: the view is not smaller than the view of the current node of the blockchain, which can be expressed as: view ⁇ the view of the current node of the blockchain.
  • Verifying that the signature of the pre-prepared message package is valid refers to calculating the hash of the block index, view, and transaction block through a relevant hash algorithm (such as a hash algorithm), that is, hash(i, view, block(i)), as a hash of the pre-prepared message bundle.
  • a relevant hash algorithm such as a hash algorithm
  • each consensus node of the blockchain After each consensus node of the blockchain receives the pre-preparation message, it verifies the validity of the pre-preparation message; after any consensus node is successfully verified, it generates a pre-preparation message package according to the pre-preparation message package ( Including the block hash of the transaction block and the second verification information), and broadcast the preparation message package obtained according to the pre-preparation message to other consensus nodes.
  • the second verification information includes the block index, view, block hash of the transaction block and the signature of the preparation message package; correspondingly, other consensus nodes of the blockchain verify the validity of the preparation message package, including:
  • the block index is greater than the current height value of the blockchain and less than the sum of the current height value of the blockchain and the preset limit value, it is determined that the block index is valid; if the view is not less than the view of the current node of the blockchain, then Determine that the view is valid; calculate the hash of the prepared message package, and obtain the public key of the consensus node that sent the prepared message package according to the hash of the prepared message package; if it is determined that the public key of the consensus node matches the signature of the prepared message package, then determine the The preparation message package signature is valid; if the block index, view and preparation message package signature are all valid, it is determined that the preparation message package verification is successful.
  • the hash obtained by calculating the block index, view and block hash can be used as the hash of the prepared message package; and the public key of the consensus node can be obtained by using the hash of the prepared message package as plaintext.
  • verifying the validity of the block index i refers to: the block index is greater than the current height value of the blockchain and less than the sum of the current height value of the blockchain and the preset limit value, which can be expressed as: h ⁇ i ⁇ (h+waterMarkLimit), where h is the current height value of the blockchain; waterMarkLimit is the preset limit value, which is used to limit the number of blocks that can be consensused at the same time to ensure the stability of the blockchain system.
  • Verify that the view view is valid which means: the view is not smaller than the view of the current node of the blockchain, which can be expressed as: view ⁇ the view of the current node of the blockchain.
  • Verify that the signature of the preparation message package is valid which means: through the relevant hash algorithm, calculate the hash of the block index, view and block hash, that is, hash(i, view, blockHash(i)), as the hash of the prepared message packet.
  • S205 If the number of preparation message packages stored by any consensus node of the blockchain reaches the preset ratio, broadcast the submission message package to other consensus nodes, wherein the submission message package includes the block hash of the transaction block and the third verification Information; other consensus nodes of the blockchain verify the validity of the submission message package, and store the successfully verified submission message package locally.
  • the preset ratio can be set according to requirements, and optionally, the preset ratio is two-thirds. For example, if the number of preparation message packets stored by any consensus node of the blockchain reaches a preset ratio, it means that the number of the same preparation message packets stored by the consensus node reaches two-thirds of the total number of consensus nodes.
  • the third verification information includes the block index, view, block hash of the transaction block and the signature of the submission message package; correspondingly, other consensus nodes of the blockchain verify the validity of the submission message package, including:
  • the block index is greater than the current height value of the blockchain and less than the sum of the current height value of the blockchain and the preset limit value, it is determined that the block index is valid; if the view is not less than the view of the current node of the blockchain, then Determine that the view is valid; calculate the hash of the submission message package, and obtain the public key of the consensus node that sent the submission message package according to the hash of the submission message package; if it is determined that the public key of the consensus node matches the signature of the submission message package, then determine the The signature of the submission message package is valid; if the block index, view and signature of the submission message package are all valid, it is determined that the submission message package verification is successful.
  • verifying the validity of the block index i refers to: the block index is greater than the current height value of the blockchain and less than the sum of the current height value of the blockchain and the preset limit value, which can be expressed as: h ⁇ i ⁇ (h+waterMarkLimit), where h is the current height value of the blockchain; waterMarkLimit is a preset limit value, which is used to limit the number of blocks that can be consensused at the same time to ensure the stability of the blockchain system.
  • Verify that the view view is valid which means: the view is not smaller than the view of the current node of the blockchain, which can be expressed as: view ⁇ the view of the current node of the blockchain.
  • Verify that the signature of the submission message package is valid which means: through the relevant hash algorithm, calculate the hash of the block index, view and block hash, that is, hash(i, view, blockHash(i)), as the hash of the commit message bundle.
  • the preset ratio can be set according to requirements, and optionally, the preset ratio is two-thirds. For example, if the number of submission message packages stored by any consensus node of the blockchain reaches a preset ratio, it means that the number of identical submission message packages stored by the consensus node reaches two-thirds of the total number of consensus nodes.
  • the leader node of the blockchain After the leader node of the blockchain obtains multiple transaction blocks from the transaction pool, it puts each transaction block into the pre-preparation message package to obtain multiple pre-preparation message packages; for each pre-preparation Message packets execute the following sorting consensus in parallel: the leader node of the blockchain broadcasts each pre-prepared message packet to all consensus nodes of the blockchain, and each consensus node of the blockchain verifies the validity of the pre-prepared message packet; if If any consensus node of the blockchain successfully verifies the received pre-preparation message package, it broadcasts the pre-preparation message package to other consensus nodes; other consensus nodes of the blockchain verify the validity of the pre-preparation message package and will verify the successful
  • the preparation message package is stored locally; if the number of preparation message packages stored by any consensus node of the blockchain reaches the preset ratio, the submission message package is broadcast to other consensus nodes; other consensus nodes of the blockchain are effective for the preparation message package verification, and store the successfully verified submission message package locally; if the number
  • FIG. 3 is the second schematic flow diagram of the blockchain-based transaction consensus method provided by the embodiment of the present application.
  • step S206 further includes:
  • the consensus engine puts the transaction blocks that have completed the sorting consensus into the block queue.
  • BlockQueue ⁇ block(i), block(i+1),...,block(i+N) ⁇ .
  • Each consensus node of the blockchain extracts the target transaction block to be executed from the block queue, and executes the target transaction block to obtain the corresponding execution result; any consensus node of the blockchain The execution result of the block puts the corresponding transaction block on the chain.
  • step S302 is described in detail as follows:
  • Each consensus node of the blockchain extracts the target transaction block to be executed from the block queue, executes the target transaction block to obtain the corresponding execution result and block execution hash, and generates a checkpoint message packet, and sends it to other
  • the consensus node broadcasts a checkpoint message package, wherein the checkpoint message package includes the block execution hash of the target transaction block and the fourth verification information.
  • the consensus engine takes out a transaction block to be executed from the block queue as the target transaction block, and puts it into the execution engine; then, the execution engine executes the transaction on the target transaction block, Get the execution result corresponding to the target transaction block and the block execution hash.
  • the target transaction block can be recorded as: block(i); the execution result of the target transaction block can be recorded as: checkPoint(i); the execution hash of the corresponding block can be recorded as: checkPointHash(i).
  • each consensus node generates a checkpoint message packet after the execution of the target transaction block is completed.
  • the fourth verification information includes: block index, block execution hash and checkpoint message package signature.
  • S3022 Other consensus nodes of the blockchain verify the validity of the checkpoint message package, and store the successfully verified checkpoint message package locally.
  • the preset ratio can be set according to requirements, and optionally, the preset ratio is two-thirds. For example, if the number of checkpoint message packets with consistent execution results of the target transaction block stored by any consensus node of the blockchain reaches a preset ratio, it may be a checkpoint message with consistent execution results of the target transaction block stored by the consensus node The number of packages reaches two-thirds of the total number of consensus nodes.
  • the next target transaction block block(i+1) can be based on the current target transaction block block(i) Execution result, execute the block execution hash corresponding to the execution result of the target transaction block block(i) as the parent block hash of the next target transaction block block(i+1), and generate a new execution result checkPoint (i+1) and the execution hash of the block is checkPointHash(i+1); then continue to generate the checkpoint message package, and broadcast the checkpoint message package to other consensus nodes, and then complete the next target transaction block block( i+1) blockchain on-chain processing.
  • FIG. 4 is a schematic structural diagram of a blockchain-based transaction consensus device provided by an embodiment of the present application.
  • the blockchain-based transaction consensus device 40 includes: a transaction upload module 401 , a first processing module 402 , a second processing module 403 , a third processing module 404 and a ranking consensus module 405 .
  • the transaction upload module 401 is used for responding to the transaction information uploaded by the client, any consensus node of the block chain stores the transaction information in the transaction pool, and broadcasts the transaction information to other consensus nodes;
  • the first processing module 402 is used for the leader node of the block chain to package the transaction information in the transaction pool to obtain multiple transaction blocks, and put each transaction block into the pre-preparation message package to obtain multiple pre-preparation messages.
  • Prepare a message package wherein the pre-prepared message package includes the transaction block and first verification information;
  • the leader node of the blockchain broadcasts each pre-prepared message package to all consensus nodes of the blockchain, and the blockchain Each consensus node of , verifies the validity of the pre-prepared message package;
  • the second processing module 403 is configured to broadcast a preparation message packet to other consensus nodes if any consensus node of the blockchain successfully verifies the received pre-preparation message packet, wherein the preparation message packet includes the transaction area
  • the third processing module 404 is configured to broadcast a submission message package to other consensus nodes if the number of preparation message packages stored by any consensus node of the blockchain reaches a preset ratio, wherein the submission message package includes the transaction area
  • the block hash of the block and the third verification information; other consensus nodes of the blockchain verify the validity of the submission message package, and store the successfully verified submission message package locally;
  • the sorting consensus module 405 is used to extract the transaction blocks from the corresponding pre-prepared message packets if the number of submission message packets stored by any consensus node of the blockchain reaches a preset ratio, so as to complete the sorting of each transaction block consensus.
  • the first verification information includes block index, view and signature of pre-prepared message package; the first processing module 402 is specifically used for if any consensus node of the blockchain does not receive After the pre-preparation message package is passed, the validity verification of the pre-preparation message package is performed according to the block index, view information and pre-preparation message package signature.
  • the first processing module 402 is specifically configured to: if the block index is greater than the current height value of the blockchain and less than the current height value of the blockchain and the preset limit value and, it is determined that the block index is valid; if the view is not less than the view of the current node of the block chain, then it is determined that the view is valid; the hash of the pre-preparation message packet is calculated, and according to the pre-preparation The hash of the message packet obtains the public key of the leader node of the blockchain; if it is determined that the public key of the leader node of the blockchain matches the signature of the pre-prepared message packet, then determine the signature of the pre-prepared message packet Valid; if the block index, the view, and the signature of the pre-prepared message package are all valid, it is determined that the verification of the pre-prepared message package is successful.
  • the device provided in this embodiment can be used to implement the technical solutions of the above method embodiments, and its implementation principle and technical effect are similar, so this embodiment will not repeat them here.
  • the block chain-based transaction consensus device 40 also includes: an execution consensus module 406, which is used for any consensus node of the block chain to convert each transaction The block is put into the block queue; each consensus node of the blockchain extracts the target transaction block to be executed from the block queue, and executes the target transaction block to obtain the corresponding execution result; the block chain Any consensus node uploads the corresponding transaction block to the chain according to the execution result of the target transaction block to be executed.
  • an execution consensus module 406 which is used for any consensus node of the block chain to convert each transaction The block is put into the block queue
  • each consensus node of the blockchain extracts the target transaction block to be executed from the block queue, and executes the target transaction block to obtain the corresponding execution result
  • the block chain Any consensus node uploads the corresponding transaction block to the chain according to the execution result of the target transaction block to be executed.
  • the execution consensus module 406 is specifically used for each consensus node of the blockchain to extract the target transaction block to be executed from the block queue, and execute the target transaction block to obtain The corresponding execution result and block execution hash, and generate a checkpoint message package, and broadcast the checkpoint message package to other consensus nodes, wherein the checkpoint message package includes the block execution of the target transaction block Hash and the fourth verification information; other consensus nodes of the blockchain verify the validity of the checkpoint message package, and store the successfully verified checkpoint message package locally; if any consensus node of the blockchain stores If the number of checkpoint message packets with the same execution result of the target transaction block reaches the preset ratio, it is determined that all consensus nodes agree on the execution result of the target transaction block, and according to the execution result of the target transaction block As a result, the target transaction block is uploaded to the chain.
  • FIG. 5 is a schematic diagram of a hardware structure of a service device provided by an embodiment of the present application.
  • the service device 50 of this embodiment includes: a processor 501 and a memory 502;
  • the memory 502 is used to store computer-executable instructions
  • the processor 501 is configured to execute the computer-executed instructions stored in the memory, so as to realize the various steps executed by the server-side blockchain in the above-mentioned embodiments. For details, refer to the related descriptions in the foregoing method embodiments.
  • the memory 502 can be independent or integrated with the processor 501 .
  • the service-based device further includes a bus 503 for connecting the memory 502 and the processor 501 .
  • the embodiment of the present application also provides a computer-readable storage medium, where computer-executable instructions are stored in the computer-readable storage medium, and when the processor executes the computer-executable instructions, the transaction based on the blockchain as described above is realized consensus method.
  • the embodiment of the present application also provides a computer program product, when the computer program is executed by a processor, the above-mentioned transaction consensus method based on blockchain is realized.
  • the disclosed devices and methods may be implemented in other ways.
  • the device embodiments described above are only illustrative.
  • the division of the modules is only a logical function division. In actual implementation, there may be other division methods, for example, multiple modules can be combined or integrated. to another system, or some features may be ignored, or not implemented.
  • the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces, and the indirect coupling or communication connection of devices or modules may be in electrical, mechanical or other forms.
  • modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Part or all of the modules can be selected according to actual needs to implement the solution of this embodiment.
  • each functional module in each embodiment of the present application may be integrated into one processing unit, each module may exist separately physically, or two or more modules may be integrated into one unit.
  • the units formed by the above modules can be implemented in the form of hardware, or in the form of hardware plus software functional units.
  • the above-mentioned integrated modules implemented in the form of software function modules can be stored in a computer-readable storage medium.
  • the above-mentioned software function modules are stored in a storage medium, and include several instructions to make a computer device (which may be a personal computer, server, or network device, etc.) or a processor execute some steps of the methods described in various embodiments of the present application.
  • processor may be a central processing unit (Central Processing Unit, referred to as CPU), and may also be other general-purpose processors, digital signal processors (Digital Signal Processor (DSP for short), Application Specific Integrated Circuit (ASIC for short), etc.
  • a general-purpose processor may be a microprocessor, or the processor may be any conventional processor, or the like.
  • the steps of the method disclosed in conjunction with the invention can be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules in the processor.
  • the storage may include a high-speed RAM memory, and may also include a non-volatile storage NVM, such as at least one disk storage, and may also be a U disk, a mobile hard disk, a read-only memory, a magnetic disk, or an optical disk.
  • NVM non-volatile storage
  • the bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI for short) bus or Extended Industry Standard Architecture (Extended Industry Standard Architecture, EISA for short) bus, etc.
  • ISA Industry Standard Architecture
  • PCI Peripheral Component Interconnect
  • EISA Extended Industry Standard Architecture
  • the bus can be divided into address bus, data bus, control bus and so on.
  • the buses in the drawings of the present application are not limited to only one bus or one type of bus.
  • the above-mentioned storage medium can be realized by any type of volatile or non-volatile storage device or their combination, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable In addition to programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
  • SRAM static random access memory
  • EEPROM electrically erasable programmable read-only memory
  • EPROM programmable read-only memory
  • ROM read-only memory
  • magnetic memory magnetic memory
  • flash memory magnetic disk or optical disk.
  • a storage media may be any available media that can be accessed by a general purpose or special purpose computer.
  • An exemplary storage medium is coupled to the processor such the processor can read information from, and write information to, the storage medium.
  • the storage medium may also be a component of the processor.
  • Processors and storage media can be located in application-specific integrated circuits (Application Specific Integrated Circuits, referred to as ASIC).
  • ASIC Application Specific Integrated Circuits
  • the processor and the storage medium can also exist in the electronic device or the main control device as discrete components.
  • the aforementioned program can be stored in a computer-readable storage medium.
  • the program executes the steps including the above-mentioned method embodiments; and the aforementioned storage medium includes: ROM, RAM, magnetic disk or optical disk and other various media that can store program codes.

Landscapes

  • Business, Economics & Management (AREA)
  • Engineering & Computer Science (AREA)
  • Accounting & Taxation (AREA)
  • Computer Security & Cryptography (AREA)
  • Finance (AREA)
  • Strategic Management (AREA)
  • Physics & Mathematics (AREA)
  • General Business, Economics & Management (AREA)
  • General Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Financial Or Insurance-Related Operations Such As Payment And Settlement (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

一种基于区块链的交易共识方法,包括:领导节点将各交易区块放入到预准备消息包;领导节点广播每个预准备消息包,每个共识节点对预准备消息包进行有效性验证;若任一共识节点对接收到的预准备消息包验证成功,则广播准备消息包;其他共识节点对准备消息包进行有效性验证,并将验证成功的准备消息包存储在本地;若任一共识节点存储的准备消息包数量达到预设比例,则广播提交消息包;其他共识节点对准备消息包进行有效性验证,并将验证成功的提交消息包存储在本地;若任一共识节点存储的提交消息包数量达到预设比例,则提取对应的交易区块,以完成对各交易区块的排序共识。还公开了一种基于区块链的交易共识装置、服务设备、计算机可读存储介质及计算机程序产品。

Description

基于区块链的交易共识方法、装置、设备及存储介质
本申请要求于2021年12月01日提交中国专利局、申请号为202111448776.6、申请名称为“基于区块链的交易共识方法、装置、设备及存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请实施例涉及金融科技(Fintech)技术领域,尤其涉及一种基于区块链的交易共识方法、装置、设备及存储介质。
背景技术
随着计算机技术的发展,越来越多的技术应用在金融领域,传统金融业正在逐步向金融科技(Finteh)转变,基于区块链的交易技术也不例外,但由于金融行业的安全性、实时性要求,也对技术提出了更高的要求。
目前,现有的基于联盟区块链的交易共识过程中,通常采用拜占庭共识算法完成区块的。由于每个区块链的区块投中必须包含父区块的哈希和当前区块的结果,因此在区块链中所有参与共识的节点中,需要对区块中的各笔交易按照交易的排序采用串行的方式进行区块共识和执行,以完成对区块在区块链上链。
然而,由于对于区块中所有交易采用串行方式进行区块共识,导致区块链执行效率非常低,影响区块链系统性能。
技术解决方案
本申请实施例提供一种基于区块链的交易共识方法、装置、设备及存储介质,以克服相关技术中对于区块链中所有交易区块采用串行方式进行区块共识,导致区块链执行效率非常低,影响区块链系统性能的问题。
第一方面,本申请实施例提供一种基于区块链的交易共识方法,包括:
响应于客户端上传的交易信息,区块链的任一共识节点将所述交易信息存入交易池中,并向其他共识节点广播交易信息;
区块链的领导节点对交易池中的交易信息进行打包以获得多个交易区块,并将各交易区块放入到预准备消息包中以得到多个预准备消息包,其中所述预准备消息包中包括所述交易区块以及第一验证信息;
区块链的领导节点将每个预准备消息包广播至区块链的所有共识节点,区块链的每个共识节点对所述预准备消息包进行有效性验证;
若区块链的任一共识节点对接收到的预准备消息包验证成功,则向其他共识节点广播准备消息包,其中所述准备消息包中包括所述交易区块的区块哈希以及第二验证信息;区块链的其他共识节点对所述准备消息包进行有效性验证,并将验证成功的准备消息包存储在本地;
若区块链的任一共识节点存储的准备消息包数量达到预设比例,则向其他共识节点广播提交消息包,其中所述提交消息包中包括所述交易区块的区块哈希以及第三验证信息;区块链的其他共识节点对所述提交消息包进行有效性验证,并将验证成功的提交消息包存储在本地;
若区块链的任一共识节点存储的提交消息包数量达到预设比例,则从对应的预准备消息包中提取交易区块,以完成对各交易区块的排序共识。
在一种可能的设计中,其中所述第一验证信息包括区块索引、视图和预准备消息包签名;相应地,所述区块链的每个共识节点对所述预准备消息包进行有效性验证,包括:若区块链的任一共识节点没有接收过所述预准备消息包,则根据所述区块索引、视图信息和预准备消息包签名对所述预准备消息包进行有效性验证。
在一种可能的设计中,所述根据所述区块索引、视图信息和预准备消息包签名对所述预准备消息包进行有效性验证,包括:若所述区块索引大于区块链的当前高度值、且小于区块链的当前高度值与预设限值之和,则确定所述区块索引有效;若所述视图不小于区块链的当前节点的视图,则确定所述视图有效;计算所述预准备消息包的哈希,并根据所述预准备消息包的哈希获取所述区块链的领导节点的公钥;若确定所述区块链的领导节点的公钥与所述预准备消息包签名匹配,则确定所述预准备消息包签名有效;若所述区块索引、所述视图和预准备消息包签名均有效,则确定所述预准备消息包验证成功。
在一种可能的设计中,所述若区块链的任一共识节点存储的提交消息包数量达到预设比例,则从对应的预准备消息包中提取交易区块,完成对各交易区块的排序共识之后,还包括:区块链的任一共识节点将所述各交易区块放入区块队列中;区块链的各共识节点从所述区块队列中提取待执行的目标交易区块,并执行所述目标交易区块得到对应的执行结果;区块链的任一共识节点根据所述待执行的目标交易区块的执行结果将对应的交易区块上链。
在一种可能的设计中,所述区块链的各共识节点从所述区块队列中提取待执行的目标交易区块,执行所述目标交易区块得到对应的执行结果;区块链的任一共识节点根据所述待执行的目标交易区块的执行结果将对应的交易区块上链,包括:区块链的各共识节点从所述区块队列中提取待执行的目标交易区块,执行所述目标交易区块得到对应的执行结果以及区块执行哈希,并生成检查点消息包,并向其他共识节点广播所述检查点消息包,其中所述检查点消息包中包括所述目标交易区块的区块执行哈希以及第四验证信息;区块链的其他共识节点对所述检查点消息包进行有效性验证,并将验证成功的检查点消息包存储在本地;若区块链的任一共识节点存储的所述目标交易区块的执行结果一致的检查点消息包数量达到预设比例,则确定所有共识节点对所述目标交易区块的执行结果达成一致,并根据所述目标交易区块的执行结果将所述目标交易区块上链。
第二方面,本申请实施例提供一种基于区块链的交易共识装置,包括:
交易上传模块,用于响应于客户端上传的交易信息,区块链的任一共识节点将所述交易信息存入交易池中,并向其他共识节点广播交易信息;
第一处理模块,用于区块链的领导节点对交易池中的交易信息进行打包以获得多个交易区块,并将各交易区块放入到预准备消息包中以得到多个预准备消息包,其中所述预准备消息包中包括所述交易区块以及第一验证信息;区块链的领导节点将每个预准备消息包广播至区块链的所有共识节点,区块链的每个共识节点对所述预准备消息包进行有效性验证;
第二处理模块,用于若区块链的任一共识节点对接收到的预准备消息包验证成功,则向其他共识节点广播准备消息包,其中所述准备消息包中包括所述交易区块的区块哈希以及第二验证信息;区块链的其他共识节点对所述准备消息包进行有效性验证,并将验证成功的准备消息包存储在本地;
第三处理模块,用于若区块链的任一共识节点存储的准备消息包数量达到预设比例,则向其他共识节点广播提交消息包,其中所述提交消息包中包括所述交易区块的区块哈希以及第三验证信息;区块链的其他共识节点对所述提交消息包进行有效性验证,并将验证成功的提交消息包存储在本地;
排序共识模块,用于若区块链的任一共识节点存储的提交消息包数量达到预设比例,则从对应的预准备消息包中提取交易区块,以完成对各交易区块的排序共识。
在一种可能的设计中,所述第一验证信息包括区块索引、视图和预准备消息包签名;所述第一处理模块,具体用于若区块链的任一共识节点没有接收过所述预准备消息包,则根据所述区块索引、视图信息和预准备消息包签名对所述预准备消息包进行有效性验证。
在一种可能的设计中,所述第一处理模块,具体用于若所述区块索引大于区块链的当前高度值、且小于区块链的当前高度值与预设限值之和,则确定所述区块索引有效;若所述视图不小于区块链的当前节点的视图,则确定所述视图有效;计算所述预准备消息包的哈希,并根据所述预准备消息包的哈希获取所述区块链的领导节点的公钥;若确定所述区块链的领导节点的公钥与所述预准备消息包签名匹配,则确定所述预准备消息包签名有效;若所述区块索引、所述视图和预准备消息包签名均有效,则确定所述预准备消息包验证成功。
在一种可能的设计中,所述装置还包括:
执行共识模块,用于区块链的任一共识节点将所述各交易区块放入区块队列中;区块链的各共识节点从所述区块队列中提取待执行的目标交易区块,并执行所述目标交易区块得到对应的执行结果;区块链的任一共识节点根据所述待执行的目标交易区块的执行结果将对应的交易区块上链。
在一种可能的设计中,所述执行共识模块,具体用于区块链的各共识节点从所述区块队列中提取待执行的目标交易区块,执行所述目标交易区块得到对应的执行结果以及区块执行哈希,并生成检查点消息包,并向其他共识节点广播所述检查点消息包,其中所述检查点消息包中包括所述目标交易区块的区块执行哈希以及第四验证信息;区块链的其他共识节点对所述检查点消息包进行有效性验证,并将验证成功的检查点消息包存储在本地;若区块链的任一共识节点存储的所述目标交易区块的执行结果一致的检查点消息包数量达到预设比例,则确定所有共识节点对所述目标交易区块的执行结果达成一致,并根据所述目标交易区块的执行结果将所述目标交易区块上链。
第三方面,本申请实施例提供一种服务设备,包括:处理器和存储器;
所述存储器存储计算机执行指令;
所述处理器执行所述存储器存储的计算机执行指令,使得所述处理器执行如上第一方面以及第一方面各种可能的设计所述的基于区块链的交易共识方法。
第四方面,本申请实施例提供一种计算机可读存储介质,所述计算机可读存储介质中存储有计算机执行指令,当处理器执行所述计算机执行指令时,实现如上第一方面以及第一方面各种可能的设计所述的基于区块链的交易共识方法。
第五方面,本申请实施例提供一种计算机程序产品,包括计算机程序,所述计算机程序被处理器执行时实现如上第一方面以及第一方面各种可能的设计所述的基于区块链的交易共识方法。
本申请实施例提供的基于区块链的交易共识方法、装置、设备及存储介质,区块链的领导节点从交易池中获取多个交易区块后,将各交易区块放入到预准备消息包中以得到多个预准备消息包;针对每个预准备消息包并行执行如下排序共识:区块链的领导节点将每个预准备消息包广播至区块链的所有共识节点,区块链的每个共识节点对预准备消息包进行有效性验证;若区块链的任一共识节点对接收到的预准备消息包验证成功,则向其他共识节点广播准备消息包;区块链的其他共识节点对准备消息包进行有效性验证,并将验证成功的准备消息包存储在本地;若区块链的任一共识节点存储的准备消息包数量达到预设比例,则向其他共识节点广播提交消息包;区块链的其他共识节点对准备消息包进行有效性验证,并将验证成功的提交消息包存储在本地;若区块链的任一共识节点存储的提交消息包数量达到预设比例,则从对应的预准备消息包中提取交易区块,以完成对各交易区块的排序共识。这样,能够实现对交易区块批量地进行并行排序共识,大大提升了区块链的吞吐量,进而提升了区块链交易处理效率。
附图说明
图1为现有技术的区块链中交易区块的共识过程示意图;
图2为本申请实施例提供的基于区块链的交易共识方法的流程示意图一;
图3为本申请实施例提供的基于区块链的交易共识方法的流程示意图二;
图4为本申请实施例提供的基于区块链的交易共识装置的结构示意图;
图5为本申请实施例提供的服务设备的硬件结构示意图。
本发明的实施方式
为使本申请实施例的目的、技术方案和优点更加清楚,下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。
技术名词解释:
拜占庭共识算法:在少数节点作恶(如伪造消息)场景中达成共识,采用签名、签名验证、哈希等密码学算法确保消息传递过程中的防篡改性、防伪造性、不可抵赖性,将算法复杂度从指数级降低到多项式级别。
共识节点:区块链中参与共识过程的节点,共识节点选举产生一个领导节点。
领导节点:负责将交易打包成区块和发起区块共识,每轮共识过程中有且仅有一个领导节点。
视图:记录每个节点的共识状态,相同的视图节点维护相同的共识节点的节点列表。当领导节点出现故障时,会发生视图切换。
区块链的交易处理模块可以被抽象为一个基于交易的状态机。状态指的是区块链中所有账户的状态,区块链将交易作为状态迁移函数,并根据交易内容从旧状态更新为新状态。区块链从创世块状态开始,不断收集区块链网络上发生的交易并由领导节点将交易排序并打包成区块,并在所有参与共识的共识节点间执行区块中的交易。当一个区块内的交易在多个共识节点上执行完成且状态一致,则称在该区块上达成了共识,并将该区块永久记录在区块链中,完成区块上链。
从区块链的打包→共识→存储过程中可以理解,执行区块中的所有交易是区块上链的必经之路。目前传统的区块链的交易共识过程是:区块链的领导节点从交易池中取出一定量的交易区块并进行排序,如图1所示,领导节点获取交易信息,其中包括按照交易顺序排序的各交易区块,包括交易区块1、交易区块2、交易区块3......交易区块n,然后领导节点广播并发送至所有参与共识的共识节点进行共识。目前,在现有技术中,对于区块中所有交易区块均采用串行方式进行区块排序共识(即交易区块1→交易区块2→交易区块3→......→交易区块n的顺序),导致无法充分利用各节点的处理器(Central Processing Unit,CPU)的计算性能,使得区块链的执行效率非常低,影响区块链的交易处理效率,降低了区块链系统性能。
为了解决上述技术问题,本申请实施例提供如下技术方案:区块链的领导节点从交易池中获取多个交易区块后,将各交易区块放入到预准备消息包中以得到多个预准备消息包;针对每个预准备消息包并行执行如下排序共识:区块链的领导节点将每个预准备消息包广播至区块链的所有共识节点,区块链的每个共识节点对预准备消息包进行有效性验证;若区块链的任一共识节点对接收到的预准备消息包验证成功,则向其他共识节点广播准备消息包;区块链的其他共识节点对准备消息包进行有效性验证,并将验证成功的准备消息包存储在本地;若区块链的任一共识节点存储的准备消息包数量达到预设比例,则向其他共识节点广播提交消息包;区块链的其他共识节点对准备消息包进行有效性验证,并将验证成功的提交消息包存储在本地;若区块链的任一共识节点存储的提交消息包数量达到预设比例,则从对应的预准备消息包中提取交易区块,以完成对各交易区块的排序共识。这样,能够实现对交易区块批量地进行并行排序共识,大大提升了区块链的吞吐量,进而提升了区块链交易处理效率。
参考图2,图2为本申请实施例提供的基于区块链的交易共识方法的流程示意图一。本实施例应用于服务端的区块链,该区块链包括共识节点,其中领导节点为所有共识节点选举产生的一个节点,上述方法详述如下:
S201:响应于客户端上传的交易信息,区块链的任一共识节点将交易信息存入交易池中,并向其他共识节点广播交易信息。
在本实施例,客户端可以是任一发生交易行为的客户端,客户端根据交易行为产生交易信息,并发送交易信息至区块链的任一共识节点上。例如,用户在网上商城购买商品,通过客户端完成交易,客户端将购买商品的交易信息发送至区块链的任一共识节点。
在本实施例中,区块链的任一共识节点为区块链中的共识节点中的任一节点。领导节点由区块链的共识节点中选举产生。
S202:区块链的领导节点对交易池中的交易信息进行打包以获得多个交易区块,并将各交易区块放入到预准备消息包中以得到多个预准备消息包,其中所述预准备消息包中包括所述交易区块以及第一验证信息。
具体地,领导节点对交易池中的交易信息进行打包以获得多个交易区块的过程为:对交易信息按照交易数量进行批量的打包,以得到多个交易区块,其中每个交易区块中包含相同数量的交易信息。
将各交易区块放入到预准备消息包中以得到多个预准备消息包的过程为:根据所述交易区块以及预准备消息包的第一验证信息打包入预准备消息包中,得到多个预准备消息包。
其中,第一验证信息可以包括区块索引、视图和预准备消息包签名。其中,区块索引为所述交易区块的索引,视图为当前节点对应的视图。
其中,领导节点对交易池中的交易信息进行打包得到的多个交易区块,可以记为:{block(i), block(i+1), …, block(i+N)},其对应的预准备消息包可以记为:{PrePrepare(i), PrePrepare(i+1), …, PrePrepare(i+N)},其中PrePrepare(i)={i, view, block(i), sig};其中,i为交易区块的区块索引,view为发送预准备消息时的视图,block(i)为交易区块,sig为预准备消息包签名。
S203:区块链的领导节点将每个预准备消息包广播至区块链的所有共识节点,区块链的每个共识节点对预准备消息包进行有效性验证。
具体地,其中第一验证信息包括区块索引、视图和预准备消息包签名;相应地,区块链的每个共识节点对预准备消息包进行有效性验证,包括:若区块链的任一共识节点没有接收过预准备消息包,则根据区块索引、视图信息和预准备消息包签名对预准备消息包进行有效性验证。
其中,根据区块索引、视图信息和预准备消息包签名对预准备消息包进行有效性验证,的具体过程包括:若区块索引大于区块链的当前高度值且小于区块链的当前高度值与预设限值之和,则确定区块索引有效;若视图不小于区块链的当前节点的视图,则确定视图有效;计算预准备消息包的哈希,并根据预准备消息包的哈希获取区块链的领导节点的公钥;若确定区块链的领导节点的公钥与预准备消息包签名匹配,则确定预准备消息包签名有效;若区块索引、视图和预准备消息包签名均有效,则确定预准备消息包验证成功。
在本实施例中,可以根据区块索引、视图和交易区块计算得到的哈希,作为预准备消息包的哈希;并以该预准备消息包的哈希为明文,取得领导节点的公钥。
其中,验证区块索引i有效,指的是:区块索引大于区块链的当前高度值且小于区块链的当前高度值与预设限值之和,可以表示为:h<i<(h+waterMarkLimit),其中,h为区块链的当前高度值;waterMarkLimit为预设限值,用于限制可同时进行共识的区块数目,以保证区块链系统的稳定性。
验证视图view有效,指的是:视图不小于区块链的当前节点的视图,可以表示为:view<区块链的当前节点的视图。
验证预准备消息包签名有效,指的是:通过相关的哈希算法(例如散列算法),计算区块索引、视图和交易区块的哈希,即hash(i, view, block(i)),作为预准备消息包的哈希。根据预准备消息包的哈希获取区块链的领导节点的公钥;若确定区块链的领导节点的公钥与预准备消息包签名匹配,则确定预准备消息包签名有效。
S204:若区块链的任一共识节点对接收到的预准备消息包验证成功,则向其他共识节点广播准备消息包,其中准备消息包中包括交易区块的区块哈希以及第二验证信息;区块链的其他共识节点对准备消息包进行有效性验证,并将验证成功的准备消息包存储在本地。
在本实施例中,区块链的每个共识节点在接收到的预准备消息后,对预准备消息进行有效性验证;任一共识节点验证成功后,根据预准备消息包生成准备消息包(包括交易区块的区块哈希以及第二验证信息),并向其他共识节点广播根据预准备消息得到的准备消息包。
其中,第二验证信息包括区块索引、视图、交易区块的区块哈希和准备消息包签名;相应地,区块链的其他共识节点对准备消息包进行有效性验证,包括:
若区块索引大于区块链的当前高度值且小于区块链的当前高度值与预设限值之和,则确定区块索引有效;若视图不小于区块链的当前节点的视图,则确定视图有效;计算准备消息包的哈希,并根据准备消息包的哈希获取发送准备消息包的共识节点的公钥;若确定该共识节点的公钥与准备消息包签名匹配,则确定该准备消息包签名有效;若区块索引、视图和准备消息包签名均有效,则确定准备消息包验证成功。
其中,可以根据区块索引、视图和区块哈希的计算得到的哈希,作为准备消息包的哈希;并以该准备消息包的哈希为明文,取得共识节点的公钥。
其中,准备消息包,可以记为:Prepare(i) = {i, view, blockHash(i), sig};其中,i为交易区块的区块索引(与预准备消息包一一对应),view为发送准备消息包时的视图,blockHash(i)为交易区块的区块哈希,sig为准备消息包签名。
其中,验证区块索引i有效性,指的是:区块索引大于区块链的当前高度值、且小于区块链的当前高度值与预设限值之和,可以表示为:h<i<(h+waterMarkLimit),其中,h为区块链的当前高度值;waterMarkLimit为预设限值,用于限制可同时进行共识的区块数目,以保证区块链系统的稳定性。
验证视图view有效,指的是:视图不小于区块链的当前节点的视图,可以表示为:view<区块链的当前节点的视图。
验证准备消息包签名有效,指的是:通过相关的哈希算法,计算区块索引、视图和区块哈希的哈希,即hash(i, view, blockHash(i)),作为准备消息包的哈希。根据准备消息包的哈希获取发送准备消息包的共识节点的公钥;若确定该共识节点的公钥与准备消息包签名匹配,则确定该准备消息包签名有效。
S205:若区块链的任一共识节点存储的准备消息包数量达到预设比例,则向其他共识节点广播提交消息包,其中提交消息包中包括交易区块的区块哈希以及第三验证信息;区块链的其他共识节点对提交消息包进行有效性验证,并将验证成功的提交消息包存储在本地。
在本实施例中,预设比例可以根据需求进行设置,可选地,预设比例为三分之二。例如,区块链的任一共识节点存储的准备消息包数量达到预设比例,指的是该共识节点存储的相同的准备消息包数量达到总的共识节点数量的三分之二。
其中,第三验证信息包括区块索引、视图、交易区块的区块哈希和提交消息包签名;相应地,区块链的其他共识节点对提交消息包进行有效性验证,包括:
若区块索引大于区块链的当前高度值且小于区块链的当前高度值与预设限值之和,则确定区块索引有效;若视图不小于区块链的当前节点的视图,则确定视图有效;计算提交消息包的哈希,并根据提交消息包的哈希获取发送提交消息包的共识节点的公钥;若确定该共识节点的公钥与提交消息包签名匹配,则确定该提交消息包签名有效;若区块索引、视图和提交消息包签名均有效,则确定提交消息包验证成功。
其中,提交消息包可以记为:CommitReq(i) = {i, view, blockHash(i), sig};其中,i为交易区块的区块索引(与预准备消息包一一对应),view为发送提交消息包时的视图,blockHash(i)为交易区块的区块哈希,sig为该提交消息包签名。
其中,验证区块索引i有效性,指的是:区块索引大于区块链的当前高度值且小于区块链的当前高度值与预设限值之和,可以表示为:h<i<(h+waterMarkLimit),其中,h为区块链的当前高度值;waterMarkLimit为预设限值,用于限制可同时进行共识的区块数目,以保证区块链系统的稳定性。
验证视图view有效,指的是:视图不小于区块链的当前节点的视图,可以表示为:view<区块链的当前节点的视图。
验证提交消息包签名有效,指的是:通过相关的哈希算法,计算区块索引、视图和区块哈希的哈希,即hash(i, view, blockHash(i)),作为提交消息包的哈希。根据该提交消息包的哈希获取发送提交消息包的共识节点的公钥;若确定该共识节点的公钥与提交消息包签名匹配,则确定该提交消息包签名有效。
S206:若区块链的任一共识节点存储的提交消息包数量达到预设比例,则从对应的预准备消息包中提取交易区块,以完成对各交易区块的排序共识。
在本实施例中,针对每个交易区块,区块链的任一共识节点存储的对应的提交消息包数量达到预设比例,则从对应的预准备消息包中提取对应的交易区块,从而完成对各交易区块的排序共识。
在本实施例中,预设比例可以根据需求进行设置,可选地,预设比例为三分之二。例如,区块链的任一共识节点存储的提交消息包数量达到预设比例,指的是该共识节点存储的相同的提交消息包数量达到总的共识节点数量的三分之二。
从上述描述可知,区块链的领导节点从交易池中获取多个交易区块后,将各交易区块放入到预准备消息包中以得到多个预准备消息包;针对每个预准备消息包并行执行如下排序共识:区块链的领导节点将每个预准备消息包广播至区块链的所有共识节点,区块链的每个共识节点对预准备消息包进行有效性验证;若区块链的任一共识节点对接收到的预准备消息包验证成功,则向其他共识节点广播准备消息包;区块链的其他共识节点对准备消息包进行有效性验证,并将验证成功的准备消息包存储在本地;若区块链的任一共识节点存储的准备消息包数量达到预设比例,则向其他共识节点广播提交消息包;区块链的其他共识节点对准备消息包进行有效性验证,并将验证成功的提交消息包存储在本地;若区块链的任一共识节点存储的提交消息包数量达到预设比例,则从对应的预准备消息包中提取交易区块,以完成对各交易区块的排序共识。这样,能够实现对交易区块批量地进行并行排序共识,大大提升了区块链的吞吐量,进而提升了区块链交易处理效率。
参考图3,图3为本申请实施例提供的基于区块链的交易共识方法的流程示意图二。在本申请的一个实施例中,在上述步骤S206之后,还包括:
S301:区块链的任一共识节点将各交易区块放入区块队列中。
在本实施例中,通过共识引擎将完成排序共识的交易区块的放入到区块队列中。
其中,区块队列的交易区块,可以记为:BlockQueue={block(i), block(i+1),…,block(i+N)}。
S302:区块链的各共识节点从区块队列中提取待执行的目标交易区块,并执行目标交易区块得到对应的执行结果;区块链的任一共识节点根据待执行的目标交易区块的执行结果将对应的交易区块上链。
具体地,步骤S302具体详述如下:
S3021:区块链的各共识节点从区块队列中提取待执行的目标交易区块,执行目标交易区块得到对应的执行结果以及区块执行哈希,并生成检查点消息包,并向其他共识节点广播检查点消息包,其中检查点消息包中包括目标交易区块的区块执行哈希以及第四验证信息。
在本实施例中,首先,共识引擎从区块队列中取出一个待执行交易区块作为目标交易区块,并将其放入到执行引擎中;然后,执行引擎对目标交易区块执行交易,得到目标交易区块对应的执行结果以及区块执行哈希。
其中,目标交易区块,可以记为:block(i);目标交易区块的执行结果,可以记为:checkPoint(i);其对应区块执行哈希,可以记为:checkPointHash(i)。
在本实施例中,各共识节点在目标交易区块执行完毕后,生成检查点消息包。其中,第四验证信息包括:区块索引、区块执行哈希和检查点消息包签名。
其中,检查点消息包,可以记为:CheckPointReq(i) = {i, checkPointHash(i), sig},其中i为区块索引,checkPointHash(i)为区块执行哈希,sig是检查点消息包签名。
S3022:区块链的其他共识节点对检查点消息包进行有效性验证,并将验证成功的检查点消息包存储在本地。
在本实施例中,其他共识节点接收到检查点消息包CheckPointReq(i) = {i, checkPointHash(i), sig}后,对检查点消息包签名进行验证,若签名验证通过,则将该检查点消息包放置到本地缓存中。
S3023:若区块链的任一共识节点存储的目标交易区块的执行结果一致的检查点消息包数量达到预设比例,则确定所有共识节点对目标交易区块的执行结果达成一致,并根据目标交易区块的执行结果将目标交易区块上链。
在本实施例中,预设比例可以根据需求进行设置,可选地,预设比例为三分之二。例如,区块链的任一共识节点存储的目标交易区块的执行结果一致的检查点消息包数量达到预设比例,可以是该共识节点存储的目标交易区块的执行结果一致的检查点消息包数量达到总的共识节点数量的三分之二。
在本申请的一个实施例中,在当前的目标交易区块block(i)执行完毕后,下一个目标交易区块block(i+1)即可以基于当前的目标交易区块block(i)的执行结果,将目标交易区块block(i)执行结果对应的区块执行哈希作为下一个目标交易区块block(i+1)的父区块哈希进行执行,并产生新的执行结果checkPoint(i+1)和区块执行哈希为checkPointHash(i+1);然后继续执行生成检查点消息包,并向其他共识节点广播检查点消息包,进而完成对下一个目标交易区块block(i+1)的区块链上链处理。
从上述描述可知,通过将区块链对交易区块的共识上链过程,划分为批量区块排序共识和区块执行共识的两个独立的过程,两个区块链处理过程并行处理,相较于现有相关技术中需要先进行区块共识过程再进行区块执行过程(即区块共识和区块执行为耦合关系),能够进一步提高区块链的处理效率。
参考图4,图4为本申请实施例提供的基于区块链的交易共识装置的结构示意图。如图4所示,该基于区块链的交易共识装置40包括:交易上传模块401、第一处理模块402、第二处理模块403、第三处理模块404和排序共识模块405。
其中,交易上传模块401,用于响应于客户端上传的交易信息,区块链的任一共识节点将所述交易信息存入交易池中,并向其他共识节点广播交易信息;
第一处理模块402,用于区块链的领导节点对交易池中的交易信息进行打包以获得多个交易区块,并将各交易区块放入到预准备消息包中以得到多个预准备消息包,其中所述预准备消息包中包括所述交易区块以及第一验证信息;区块链的领导节点将每个预准备消息包广播至区块链的所有共识节点,区块链的每个共识节点对所述预准备消息包进行有效性验证;
第二处理模块403,用于若区块链的任一共识节点对接收到的预准备消息包验证成功,则向其他共识节点广播准备消息包,其中所述准备消息包中包括所述交易区块的区块哈希以及第二验证信息;区块链的其他共识节点对所述准备消息包进行有效性验证,并将验证成功的准备消息包存储在本地;
第三处理模块404,用于若区块链的任一共识节点存储的准备消息包数量达到预设比例,则向其他共识节点广播提交消息包,其中所述提交消息包中包括所述交易区块的区块哈希以及第三验证信息;区块链的其他共识节点对所述提交消息包进行有效性验证,并将验证成功的提交消息包存储在本地;
排序共识模块405,用于若区块链的任一共识节点存储的提交消息包数量达到预设比例,则从对应的预准备消息包中提取交易区块,以完成对各交易区块的排序共识。
在本申请的一个实施例中,所述第一验证信息包括区块索引、视图和预准备消息包签名;所述第一处理模块402,具体用于若区块链的任一共识节点没有接收过所述预准备消息包,则根据所述区块索引、视图信息和预准备消息包签名对所述预准备消息包进行有效性验证。
在本申请的一个实施例中,所述第一处理模块402,具体用于若所述区块索引大于区块链的当前高度值、且小于区块链的当前高度值与预设限值之和,则确定所述区块索引有效;若所述视图不小于区块链的当前节点的视图,则确定所述视图有效;计算所述预准备消息包的哈希,并根据所述预准备消息包的哈希获取所述区块链的领导节点的公钥;若确定所述区块链的领导节点的公钥与所述预准备消息包签名匹配,则确定所述预准备消息包签名有效;若所述区块索引、所述视图和预准备消息包签名均有效,则确定所述预准备消息包验证成功。
本实施例提供的装置,可用于执行上述方法实施例的技术方案,其实现原理和技术效果类似,本实施例此处不再赘述。
继续参考图4,在本申请的一个实施例中,所述该基于区块链的交易共识装置40,还包括:执行共识模块406,用于区块链的任一共识节点将所述各交易区块放入区块队列中;区块链的各共识节点从所述区块队列中提取待执行的目标交易区块,并执行所述目标交易区块得到对应的执行结果;区块链的任一共识节点根据所述待执行的目标交易区块的执行结果将对应的交易区块上链。
在本申请的一个实施例中,所述执行共识模块406,具体用于区块链的各共识节点从所述区块队列中提取待执行的目标交易区块,执行所述目标交易区块得到对应的执行结果以及区块执行哈希,并生成检查点消息包,并向其他共识节点广播所述检查点消息包,其中所述检查点消息包中包括所述目标交易区块的区块执行哈希以及第四验证信息;区块链的其他共识节点对所述检查点消息包进行有效性验证,并将验证成功的检查点消息包存储在本地;若区块链的任一共识节点存储的所述目标交易区块的执行结果一致的检查点消息包数量达到预设比例,则确定所有共识节点对所述目标交易区块的执行结果达成一致,并根据所述目标交易区块的执行结果将所述目标交易区块上链。
从上述描述可知,通过将区块链对交易区块的共识上链过程,划分为批量区块排序共识和区块执行共识的两个独立的过程,两个区块链处理过程并行处理,相较于现有相关技术中需要先进行区块共识过程再进行区块执行过程(即区块共识和区块执行为耦合关系),能够进一步提高区块链的处理效率。
参考图5,图5为本申请实施例提供的服务设备的硬件结构示意图。如图5所示,本实施例的服务设备50包括:处理器501以及存储器502;其中
存储器502,用于存储计算机执行指令;
处理器501,用于执行存储器存储的计算机执行指令,以实现上述实施例中服务端的区块链所执行的各个步骤。具体可以参见前述方法实施例中的相关描述。
可选地,存储器502既可以是独立的,也可以跟处理器501集成在一起。
当存储器502独立设置时,该基于服务设备还包括总线503,用于连接所述存储器502和处理器501。
本申请实施例还提供一种计算机可读存储介质,所述计算机可读存储介质中存储有计算机执行指令,当处理器执行所述计算机执行指令时,实现如上所述的基于区块链的交易共识方法。
本申请实施例还提供一种计算机程序产品,所述计算机程序被处理器执行时,实现如上所述的基于区块链的交易共识方法。
在本申请所提供的几个实施例中,应该理解到,所揭露的设备和方法,可以通过其它的方式实现。例如,以上所描述的设备实施例仅仅是示意性的,例如,所述模块的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个模块可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或模块的间接耦合或通信连接,可以是电性,机械或其它的形式。
所述作为分离部件说明的模块可以是或者也可以不是物理上分开的,作为模块显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部模块来实现本实施例方案。
另外,在本申请各个实施例中的各功能模块可以集成在一个处理单元中,也可以是各个模块单独物理存在,也可以两个或两个以上模块集成在一个单元中。上述模块成的单元既可以采用硬件的形式实现,也可以采用硬件加软件功能单元的形式实现。
上述以软件功能模块的形式实现的集成的模块,可以存储在一个计算机可读取存储介质中。上述软件功能模块存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)或处理器执行本申请各个实施例所述方法的部分步骤。
应理解,上述处理器可以是中央处理单元(Central Processing Unit,简称CPU),还可以是其他通用处理器、数字信号处理器(Digital Signal Processor,简称DSP)、专用集成电路(Application Specific Integrated Circuit,简称ASIC)等。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。结合发明所公开的方法的步骤可以直接体现为硬件处理器执行完成,或者用处理器中的硬件及软件模块组合执行完成。
存储器可能包含高速RAM存储器,也可能还包括非易失性存储NVM,例如至少一个磁盘存储器,还可以为U盘、移动硬盘、只读存储器、磁盘或光盘等。
总线可以是工业标准体系结构(Industry Standard Architecture,简称ISA)总线、外部设备互连(Peripheral Component Interconnect,简称PCI)总线或扩展工业标准体系结构(Extended Industry Standard Architecture,简称EISA)总线等。总线可以分为地址总线、数据总线、控制总线等。为便于表示,本申请附图中的总线并不限定仅有一根总线或一种类型的总线。
上述存储介质可以是由任何类型的易失性或非易失性存储设备或者它们的组合实现,如静态随机存取存储器(SRAM),电可擦除可编程只读存储器(EEPROM),可擦除可编程只读存储器(EPROM),可编程只读存储器(PROM),只读存储器(ROM),磁存储器,快闪存储器,磁盘或光盘。存储介质可以是通用或专用计算机能够存取的任何可用介质。
一种示例性的存储介质耦合至处理器,从而使处理器能够从该存储介质读取信息,且可向该存储介质写入信息。当然,存储介质也可以是处理器的组成部分。处理器和存储介质可以位于专用集成电路(Application Specific Integrated Circuits,简称ASIC)中。当然,处理器和存储介质也可以作为分立组件存在于电子设备或主控设备中。
本领域普通技术人员可以理解:实现上述各方法实施例的全部或部分步骤可以通过程序指令相关的硬件来完成。前述的程序可以存储于一计算机可读取存储介质中。该程序在执行时,执行包括上述各方法实施例的步骤;而前述的存储介质包括:ROM、RAM、磁碟或者光盘等各种可以存储程序代码的介质。
最后应说明的是:以上各实施例仅用以说明本申请的技术方案,而非对其限制;尽管参照前述各实施例对本申请进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分或者全部技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本申请各实施例技术方案的范围。

Claims (13)

  1. 一种基于区块链的交易共识方法,其特征在于,包括:
    响应于客户端上传的交易信息,区块链的任一共识节点将所述交易信息存入交易池中,并向其他共识节点广播交易信息;
    区块链的领导节点对交易池中的交易信息进行打包以获得多个交易区块,并将各交易区块放入到预准备消息包中以得到多个预准备消息包,其中所述预准备消息包中包括所述交易区块以及第一验证信息;
    区块链的领导节点将每个预准备消息包广播至区块链的所有共识节点,区块链的每个共识节点对所述预准备消息包进行有效性验证;
    若区块链的任一共识节点对接收到的预准备消息包验证成功,则向其他共识节点广播准备消息包,其中所述准备消息包中包括所述交易区块的区块哈希以及第二验证信息;区块链的其他共识节点对所述准备消息包进行有效性验证,并将验证成功的准备消息包存储在本地;
    若区块链的任一共识节点存储的准备消息包数量达到预设比例,则向其他共识节点广播提交消息包,其中所述提交消息包中包括所述交易区块的区块哈希以及第三验证信息;区块链的其他共识节点对所述提交消息包进行有效性验证,并将验证成功的提交消息包存储在本地;
    若区块链的任一共识节点存储的提交消息包数量达到预设比例,则从对应的预准备消息包中提取交易区块,以完成对各交易区块的排序共识。
  2. 根据权利要求1所述的方法,其特征在于,其中所述第一验证信息包括区块索引、视图和预准备消息包签名;
    相应地,所述区块链的每个共识节点对所述预准备消息包进行有效性验证,包括:
    若区块链的任一共识节点没有接收过所述预准备消息包,则根据所述区块索引、视图信息和预准备消息包签名对所述预准备消息包进行有效性验证。
  3. 根据权利要求2所述的方法,其特征在于,所述根据所述区块索引、视图信息和预准备消息包签名对所述预准备消息包进行有效性验证,包括:
    若所述区块索引大于区块链的当前高度值、且小于区块链的当前高度值与预设限值之和,则确定所述区块索引有效;
    若所述视图不小于区块链的当前节点的视图,则确定所述视图有效;
    计算所述预准备消息包的哈希,并根据所述预准备消息包的哈希获取所述区块链的领导节点的公钥;
    若确定所述区块链的领导节点的公钥与所述预准备消息包签名匹配,则确定所述预准备消息包签名有效;
    若所述区块索引、所述视图和预准备消息包签名均有效,则确定所述预准备消息包验证成功。
  4. 根据权利要求1至3任一项所述的方法,其特征在于,所述若区块链的任一共识节点存储的提交消息包数量达到预设比例,则从对应的预准备消息包中提取交易区块,完成对各交易区块的排序共识之后,还包括:
    区块链的任一共识节点将所述各交易区块放入区块队列中;
    区块链的各共识节点从所述区块队列中提取待执行的目标交易区块,并执行所述目标交易区块得到对应的执行结果;区块链的任一共识节点根据所述待执行的目标交易区块的执行结果将对应的交易区块上链。
  5. 根据权利要求4所述的方法,其特征在于,所述区块链的各共识节点从所述区块队列中提取待执行的目标交易区块,执行所述目标交易区块得到对应的执行结果;区块链的任一共识节点根据所述待执行的目标交易区块的执行结果将对应的交易区块上链,包括:
    区块链的各共识节点从所述区块队列中提取待执行的目标交易区块,执行所述目标交易区块得到对应的执行结果以及区块执行哈希,并生成检查点消息包,并向其他共识节点广播所述检查点消息包,其中所述检查点消息包中包括所述目标交易区块的区块执行哈希以及第四验证信息;
    区块链的其他共识节点对所述检查点消息包进行有效性验证,并将验证成功的检查点消息包存储在本地;
    若区块链的任一共识节点存储的所述目标交易区块的执行结果一致的检查点消息包数量达到预设比例,则确定所有共识节点对所述目标交易区块的执行结果达成一致,并根据所述目标交易区块的执行结果将所述目标交易区块上链。
  6. 一种基于区块链的交易共识装置,其特征在于,包括:
    交易上传模块,用于响应于客户端上传的交易信息,区块链的任一共识节点将所述交易信息存入交易池中,并向其他共识节点广播交易信息;
    第一处理模块,用于区块链的领导节点对交易池中的交易信息进行打包以获得多个交易区块,并将各交易区块放入到预准备消息包中以得到多个预准备消息包,其中所述预准备消息包中包括所述交易区块以及第一验证信息;区块链的领导节点将每个预准备消息包广播至区块链的所有共识节点,区块链的每个共识节点对所述预准备消息包进行有效性验证;
    第二处理模块,用于若区块链的任一共识节点对接收到的预准备消息包验证成功,则向其他共识节点广播准备消息包,其中所述准备消息包中包括所述交易区块的区块哈希以及第二验证信息;区块链的其他共识节点对所述准备消息包进行有效性验证,并将验证成功的准备消息包存储在本地;
    第三处理模块,用于若区块链的任一共识节点存储的准备消息包数量达到预设比例,则向其他共识节点广播提交消息包,其中所述提交消息包中包括所述交易区块的区块哈希以及第三验证信息;区块链的其他共识节点对所述提交消息包进行有效性验证,并将验证成功的提交消息包存储在本地;
    排序共识模块,用于若区块链的任一共识节点存储的提交消息包数量达到预设比例,则从对应的预准备消息包中提取交易区块,以完成对各交易区块的排序共识。
  7. 根据权利要求6所述的装置,其特征在于,所述第一验证信息包括区块索引、视图和预准备消息包签名;所述第一处理模块,具体用于若区块链的任一共识节点没有接收过所述预准备消息包,则根据所述区块索引、视图信息和预准备消息包签名对所述预准备消息包进行有效性验证。
  8. 根据权利要求7所述的装置,其特征在于,所述第一处理模块,具体用于若所述区块索引大于区块链的当前高度值、且小于区块链的当前高度值与预设限值之和,则确定所述区块索引有效;若所述视图不小于区块链的当前节点的视图,则确定所述视图有效;计算所述预准备消息包的哈希,并根据所述预准备消息包的哈希获取所述区块链的领导节点的公钥;若确定所述区块链的领导节点的公钥与所述预准备消息包签名匹配,则确定所述预准备消息包签名有效;若所述区块索引、所述视图和预准备消息包签名均有效,则确定所述预准备消息包验证成功。
  9. 根据权利要求6至8任一项所述的装置,其特征在于,所述装置还包括:
    执行共识模块,用于区块链的任一共识节点将所述各交易区块放入区块队列中;区块链的各共识节点从所述区块队列中提取待执行的目标交易区块,并执行所述目标交易区块得到对应的执行结果;区块链的任一共识节点根据所述待执行的目标交易区块的执行结果将对应的交易区块上链。
  10. 根据权利要求9所述的装置,其特征在于,所述执行共识模块,具体用于区块链的各共识节点从所述区块队列中提取待执行的目标交易区块,执行所述目标交易区块得到对应的执行结果以及区块执行哈希,并生成检查点消息包,并向其他共识节点广播所述检查点消息包,其中所述检查点消息包中包括所述目标交易区块的区块执行哈希以及第四验证信息;区块链的其他共识节点对所述检查点消息包进行有效性验证,并将验证成功的检查点消息包存储在本地;若区块链的任一共识节点存储的所述目标交易区块的执行结果一致的检查点消息包数量达到预设比例,则确定所有共识节点对所述目标交易区块的执行结果达成一致,并根据所述目标交易区块的执行结果将所述目标交易区块上链。
  11. 一种服务设备,其特征在于,包括:
    处理器和存储器;
    所述存储器存储计算机执行指令;
    所述处理器执行所述存储器存储的计算机执行指令,使得所述处理器执行如权利要求1至5任一项所述的基于区块链的交易共识方法。
  12. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质中存储有计算机执行指令,当处理器执行所述计算机执行指令时,实现如权利要求1至5任一项所述的基于区块链的交易共识方法。
  13. 一种计算机程序产品,包括计算机程序,其特征在于,所述计算机程序被处理器执行时实现如权利要求1至5任一项所述的基于区块链的交易共识方法。
PCT/CN2022/100649 2021-12-01 2022-06-23 基于区块链的交易共识方法、装置、设备及存储介质 WO2023098042A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202111448776.6A CN113850600B (zh) 2021-12-01 2021-12-01 基于区块链的交易共识方法、装置、设备及存储介质
CN202111448776.6 2021-12-01

Publications (1)

Publication Number Publication Date
WO2023098042A1 true WO2023098042A1 (zh) 2023-06-08

Family

ID=78982588

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/100649 WO2023098042A1 (zh) 2021-12-01 2022-06-23 基于区块链的交易共识方法、装置、设备及存储介质

Country Status (2)

Country Link
CN (1) CN113850600B (zh)
WO (1) WO2023098042A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117240862A (zh) * 2023-11-15 2023-12-15 国网数字科技控股有限公司 适用于分布式电力交易的区块链共识方法及装置

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113850600B (zh) * 2021-12-01 2022-04-26 深圳前海微众银行股份有限公司 基于区块链的交易共识方法、装置、设备及存储介质
CN114880397B (zh) * 2022-04-28 2024-04-26 中国电信股份有限公司 去中心化的数据存储方法和装置、计算机介质、电子设备

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108182635A (zh) * 2017-12-18 2018-06-19 深圳前海微众银行股份有限公司 区块链共识方法、系统和计算机可读存储介质
US20210091926A1 (en) * 2019-09-25 2021-03-25 The Mitre Corporation Assessing permissioned blockchains
CN112669149A (zh) * 2020-12-24 2021-04-16 杭州趣链科技有限公司 一种区块链的共识方法、装置、服务器及存储介质
CN113395165A (zh) * 2021-05-28 2021-09-14 网易(杭州)网络有限公司 共识流程处理方法、装置、存储介质及计算机设备
CN113541968A (zh) * 2021-09-16 2021-10-22 中国信息通信研究院 共识方法、装置及区块链系统
CN113850600A (zh) * 2021-12-01 2021-12-28 深圳前海微众银行股份有限公司 基于区块链的交易共识方法、装置、设备及存储介质

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10740732B2 (en) * 2015-05-20 2020-08-11 Ripple Luxembourg S.A. Resource transfer system
CN109150598B (zh) * 2018-08-10 2021-09-03 上交所技术有限责任公司 一种基于块片的bft共识算法带宽使用率改进方法
AU2019203865B2 (en) * 2019-03-18 2021-01-21 Advanced New Technologies Co., Ltd. Consensus system downtime recovery
US11343073B2 (en) * 2019-06-18 2022-05-24 Electronics And Telecommunications Research Institute Apparatus and method for achieving distributed consensus based on decentralized byzantine fault tolerance
CN111080449B (zh) * 2019-12-03 2023-12-19 深圳前海微众银行股份有限公司 区块链的跨链交易方法、管理节点、区块链网络
CN112907369B (zh) * 2021-02-08 2022-04-12 网易(杭州)网络有限公司 基于区块链的数据共识方法及装置、电子设备、存储介质
CN113254526A (zh) * 2021-03-02 2021-08-13 中国信息通信研究院 区块链共识方法、装置及系统

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108182635A (zh) * 2017-12-18 2018-06-19 深圳前海微众银行股份有限公司 区块链共识方法、系统和计算机可读存储介质
US20210091926A1 (en) * 2019-09-25 2021-03-25 The Mitre Corporation Assessing permissioned blockchains
CN112669149A (zh) * 2020-12-24 2021-04-16 杭州趣链科技有限公司 一种区块链的共识方法、装置、服务器及存储介质
CN113395165A (zh) * 2021-05-28 2021-09-14 网易(杭州)网络有限公司 共识流程处理方法、装置、存储介质及计算机设备
CN113541968A (zh) * 2021-09-16 2021-10-22 中国信息通信研究院 共识方法、装置及区块链系统
CN113850600A (zh) * 2021-12-01 2021-12-28 深圳前海微众银行股份有限公司 基于区块链的交易共识方法、装置、设备及存储介质

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117240862A (zh) * 2023-11-15 2023-12-15 国网数字科技控股有限公司 适用于分布式电力交易的区块链共识方法及装置
CN117240862B (zh) * 2023-11-15 2024-04-12 国网数字科技控股有限公司 适用于分布式电力交易的区块链共识方法及装置

Also Published As

Publication number Publication date
CN113850600B (zh) 2022-04-26
CN113850600A (zh) 2021-12-28

Similar Documents

Publication Publication Date Title
WO2023098042A1 (zh) 基于区块链的交易共识方法、装置、设备及存储介质
WO2020168937A1 (zh) 区块链多方见证方法、装置、设备及计算机可读存储介质
CN112685796B (zh) 一种基于区块链的区块共识方法以及相关设备
US20200134613A1 (en) Method and Apparatus for Running Smart Contract
WO2020042805A1 (zh) 基于区块链的交易共识处理方法及装置、电子设备
US20220237181A1 (en) Method, apparatus, device, and storage medium for proposal message processing for blockchain
WO2021027529A1 (zh) 一种区块处理、区块共识和区块同步方法及装置
CN110083606B (zh) 跨链存储方法、终端及存储介质
WO2021244568A1 (zh) 区块链中的共识方法和系统
TW201943250A (zh) 跨區塊鏈的認證方法及裝置、電子設備
CN111698094B (zh) 一种基于区块链系统的共识方法及区块链系统
TW202016787A (zh) 基於區塊鏈的交易處理方法及裝置、電子設備
EP3934161A1 (en) Consensus method and data verification method, apparatus, and system of consortium blockchain
CN113055188A (zh) 一种数据处理方法、装置、设备及存储介质
CN111010284B (zh) 一种待共识区块的处理方法、相关装置及区块链系统
WO2021051782A1 (zh) 区块链的共识方法、装置及设备
WO2023020242A1 (zh) 基于区块链的数据处理方法、装置、计算机设备、计算机可读存储介质及计算机程序产品
CN112381649A (zh) 基于区块链的交易共识方法、装置及设备
JPWO2019038839A1 (ja) ブロックチェーン管理装置、ブロックチェーン管理方法及びプログラム
Wang et al. The research on the incentive method of consortium blockchain based on practical byzantine fault tolerant
CN113259179A (zh) 一种基于节点评分的拜占庭容错共识方法与系统
CN112995167A (zh) 基于Kafka机制的用电信息采集方法、区块链网络及用户端
CN116455974A (zh) 交易缓存及排序的方法、装置、电子设备和存储介质
WO2023005500A1 (zh) 跨链交易处理方法、装置、电子设备以及存储介质
KR102137641B1 (ko) 블록체인을 이용한 트랜잭션 일괄처리 시스템 및 방법

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: 22899862

Country of ref document: EP

Kind code of ref document: A1