WO2021042733A1 - Blockchain transaction processing method and apparatus, computer device, and storage medium - Google Patents

Blockchain transaction processing method and apparatus, computer device, and storage medium Download PDF

Info

Publication number
WO2021042733A1
WO2021042733A1 PCT/CN2020/085565 CN2020085565W WO2021042733A1 WO 2021042733 A1 WO2021042733 A1 WO 2021042733A1 CN 2020085565 W CN2020085565 W CN 2020085565W WO 2021042733 A1 WO2021042733 A1 WO 2021042733A1
Authority
WO
WIPO (PCT)
Prior art keywords
block
processed
signature verification
verification result
verification
Prior art date
Application number
PCT/CN2020/085565
Other languages
French (fr)
Chinese (zh)
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 WO2021042733A1 publication Critical patent/WO2021042733A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24552Database cache management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor

Definitions

  • This application relates to the field of blockchain technology, and in particular to a blockchain transaction processing method, device, computer equipment and storage medium.
  • Blockchain is generally understood as a distributed ledger, and its essence is also a distributed database.
  • One of the fundamental differences between the alliance blockchain and the ordinary blockchain is the need to provide a privacy protection mechanism.
  • the privacy protection mechanism is implemented through signature encryption and signature verification and decryption in cryptography.
  • multiple transactions are packaged into blocks and sent to the nodes on the blockchain.
  • the node unlocks the block, obtains the transactions in the block, first verifies the signature of each transaction, and then all signatures
  • the verified transactions are verified for multi-version concurrency control as a whole, and finally processed for transaction persistence to write the transaction information to the disk.
  • each block needs to be sequentially verified by signatures and multiple blocks.
  • Version concurrency control verification and transaction persistence are processed, and the next block is processed after the processing of one block is completed.
  • the signature verification is to verify the signature corresponding to the transaction data in the block.
  • the verification process involves a large number of mathematical operations and takes a long time.
  • the serial verification method is mainly used to verify the signature of the block. This verification method makes the subsequent blocks only wait for the previous block to be verified before they can be verified, and the system’s computing resources cannot be fully utilized. This leads to a large waste of system resources, resulting in low blockchain transaction processing performance and low transaction processing efficiency.
  • the embodiments of the application provide a blockchain transaction processing method, device, computer equipment, and storage medium, so as to solve the problem of low processing efficiency when using serial verification to verify the signature of the block in the current blockchain transaction processing. And the problem of large waste of computing resources.
  • a blockchain transaction processing method including:
  • a blockchain transaction processing device including:
  • a computer device comprising a memory, a processor, and a computer program stored in the memory and capable of running on the processor, and the processor implements the steps of the blockchain transaction processing method when the computer program is executed .
  • a computer-readable storage medium which stores a computer program, and when the computer program is executed by a processor, realizes the steps of the blockchain transaction processing method described above.
  • the above-mentioned blockchain transaction processing method, device, computer equipment and storage medium simultaneously start the pre-created standby verification thread to perform signature verification on the block to be processed in the block queue, and obtain the corresponding verification result block to ensure
  • the verification efficiency of signature verification for all pending blocks in the block queue saves the processing time of signature verification, and the standby verification thread does not need to create and destroy threads, which helps to save system loss.
  • the real-time detection cache contains the current desired block
  • at least one continuous verification result block with the current desired block as the starting block is determined as the target block and submitted The target block is to ensure that the submitted target block contains at least one consecutive signature verification result block to ensure the execution sequence between the blocks.
  • FIG. 1 is a schematic diagram of an application environment of a blockchain transaction processing method in an embodiment of the present application
  • Figure 2 is a flowchart of a blockchain transaction processing method in an embodiment of the present application
  • Fig. 3 is another flowchart of a blockchain transaction processing method in an embodiment of the present application.
  • FIG. 4 is another flowchart of a blockchain transaction processing method in an embodiment of the present application.
  • FIG. 5 is another flowchart of a blockchain transaction processing method in an embodiment of the present application.
  • Fig. 6 is another flowchart of a blockchain transaction processing method in an embodiment of the present application.
  • FIG. 7 is another flowchart of a blockchain transaction processing method in an embodiment of the present application.
  • FIG. 8 is another flowchart of a blockchain transaction processing method in an embodiment of the present application.
  • FIG. 9 is a schematic diagram of a blockchain transaction processing method in an embodiment of the present application.
  • Fig. 10 is a schematic diagram of a computer device in an embodiment of the present application.
  • the blockchain transaction processing method can be applied to the application environment as shown in FIG. 1.
  • the blockchain transaction processing method is applied to a blockchain system.
  • the blockchain system includes multiple blockchain nodes connected by a blockchain network, and each blockchain node corresponds to a blockchain node
  • Each block chain node device is connected to other block chain node devices through the block chain network, so as to realize the parallel processing of the signature verification process, which is computationally intensive and takes a long time in block chain transaction processing, to improve The efficiency of signature verification and saving processing time will help improve the overall efficiency of the entire blockchain transaction processing.
  • the blockchain node device is a device that can automatically perform numerical calculation and/or information processing in accordance with pre-set or stored instructions.
  • the blockchain node device can be a computer, a single network server, a server group composed of multiple network servers, or a cloud composed of a large number of hosts or network servers based on cloud computing.
  • Cloud computing is a type of distributed computing.
  • a super virtual computer composed of a group of loosely coupled computer sets.
  • a blockchain transaction processing method is provided. Taking the method applied to the blockchain node device in FIG. 1 as a server as an example for description, the method includes the following steps:
  • S201 Receive a block to be processed, and store the block to be processed in a block queue, and each block to be processed corresponds to a block label.
  • the block to be processed is the block that needs to be processed sent to the node to be processed on the blockchain.
  • the node to be processed is a blockchain node on the blockchain network that needs to process data.
  • Each block to be processed includes at least one transaction to be processed, and the transaction to be processed is a transaction that requires subsequent processing.
  • the server can obtain the to-be-processed block from the to-be-processed node of the blockchain for subsequent processing of the three links of signature verification, multi-version concurrency control verification, and transaction persistence processing in the to-be-processed block .
  • the block queue is a pre-created queue in the system for caching the to-be-processed blocks that need to be processed.
  • the block queue can manage all the to-be-processed blocks in the queue in a first-in first-out order.
  • the block label is the label information corresponding to the block stored in the block to be processed.
  • the block label corresponding to each block to be processed includes the block serial number (i.e. Number), the current block hash value (i.e. DataHash) and the previous block hash value (i.e. PreviousHash), so as to be based on
  • the current block hash value and the previous block hash value determine the execution order of different blocks to be processed.
  • the block serial number is a serial number used to uniquely identify a certain block.
  • the current block hash value is a hash pointer value used to point to the current block.
  • the previous block hash value is the hash pointer value used to point to the previous block of the current block.
  • the execution sequence between the two blocks to be processed can be determined based on the hash value of the current block and the hash value of the previous block. Understandably, if the block serial number is named according to a specific block serial number naming rule, that is, when the block serial number named according to the block serial number naming rule has a sequence corresponding to the execution order between the blocks, it can be Determine the execution sequence between different blocks to be processed according to the block number.
  • each block to be processed includes a block header area (ie, Block Header), a block data area (ie, Block Data), and a metadata area (Metadata).
  • the block header area i.e. Block Header
  • the block header area is an area used to record block attributes, specifically including the block number (i.e. Number), the previous block hash value (i.e. PreviousHash) and the current block hash value. (Ie DataHash) and other block attributes.
  • the block data area ie, Block Data
  • the block data area is an area used to record transaction data in the block and signature data corresponding to the transaction data.
  • each block to be processed can store transaction data and signature data corresponding to one transaction to be processed, or it can store at least two transaction data and transaction data corresponding to the transaction to be processed.
  • signature data That is to say, each block to be processed includes at least one transaction to be processed, and the transaction data and signature data corresponding to at least one transaction to be processed are sequentially recorded in the block data area (i.e., Block Data), during the process of blockchain transaction processing , It is necessary to perform signature verification on the signature data corresponding to each transaction to be processed in the block data block to ensure the security of the transaction data corresponding to the transaction to be processed.
  • Metadata also known as intermediary data or relay data, is data describing data (data about data), mainly information describing data properties, used to support such as indicating storage location, historical data, and resource search And file recording and other functions. Metadata can be regarded as an electronic catalog. In order to achieve the purpose of cataloging, it is necessary to describe and collect the content or characteristics of the data, and then achieve the purpose of assisting data retrieval.
  • the block signature recorded in the metadata area (Metadata) can be verified based on the block signature. Among them, the block signature is a digital signature corresponding to the block to be processed. Understandably, the metadata area (Metadata) is also provided with a to-be-filled area for recording the signature verification result, and the to-be-filled area is a blank area before the signature verification of the block to be processed is performed.
  • S202 Concurrently start the pre-created standby signature verification thread, perform signature verification on the block to be processed in the block queue, obtain the signature verification result block, and store the signature verification result block in the cache.
  • the standby verification thread is a thread pre-allocated by the system for signature verification.
  • the standby verification thread performs signature verification when it is working, and enters a sleep state when it is not working. It does not need to create and destroy threads, which is helpful Save system loss.
  • the signature verification algorithm adopted in the standby verification thread matches the signature encryption algorithm used in advance in the transaction to be processed, that is, the decryption algorithm and the encryption algorithm are mutually used to ensure the feasibility of signature verification.
  • the server can concurrently start a pre-created standby verification thread according to the number of blocks to be processed in the block queue.
  • the standby verification thread is used to perform signature verification on each block to be processed in the block queue, and the verification result block corresponding to the pending block is obtained.
  • the signature thread can directly process the block to be processed to ensure the verification efficiency of signature verification for all blocks to be processed in the block queue and save the processing time of signature verification.
  • a corresponding standby verification thread can be assigned to each block to be processed in turn, so that the standby verification thread is used to perform signature verification on the block to be processed.
  • the signature verification process that uses multiple standby verification threads to execute concurrently can make full use of the system's CPU and memory performance, give full play to the advantages of multi-core CPUs, increase the throughput of the entire block processing, reduce processing delays, and improve processing efficiency.
  • the signature verification result block is the block containing the signature verification result obtained after the block to be processed is verified by the signature.
  • the signature verification result includes two results: the signature is valid and the signature is invalid.
  • the signature verification result of each pending transaction is stored in In the metadata area (Metadata) of the block to be processed, the signature verification result is specifically filled in the area to be filled corresponding to the metadata area (Metadata) to form a signature verification result block. That is, the finally formed signature verification result block not only includes all the contents of the block to be processed, but also includes the signature verification result obtained after the signature verification, so as to perform subsequent verification processing based on the signature verification result.
  • the cache is a space for storing the verification result blocks after signature verification in the server in advance to ensure that there is a sequence between all verification result blocks submitted to the next processing link (that is, the multi-version concurrency control verification link).
  • the server concurrently starts the standby verification thread to perform signature verification on each block to be processed in the block queue to obtain the corresponding verification result block, and store the verification result block in
  • multiple standby verification threads can be simultaneously used to perform signature verification on multiple blocks to be processed. No matter which standby verification thread completes the signature verification process first, the corresponding verification result block can be stored In the cache, there is no need to wait for the signature verification of the block to be processed in the first execution order to complete the signature verification of the block to be processed in the subsequent execution order, so that the signature verification process is not affected by the execution order between the blocks to be processed.
  • S203 Detect in real time whether the current desired block is included in the cache, and if the current desired block is included in the cache, at least one consecutive signature verification result block with the current desired block as the starting block is determined as the target block.
  • the current desired block refers to a block that can be submitted to the next processing link (that is, the multi-version concurrency control verification link) determined according to the execution sequence of different to-be-processed blocks in the blockchain.
  • the target block refers to a continuous block formed by at least one continuous verification result block with the current expected block as the starting block according to the processing sequence between different blocks to be processed in the blockchain.
  • the target block may include only one verification result block, at this time, the verification result block is the current desired block; it may also include at least two verification result blocks, and at least two verification result areas
  • a block is a continuous verification result block with the current desired block as the starting block, and at least one continuous verification result block containing the current desired block after the signature verification is completed is determined as the target block.
  • the target block is submitted to the next processing link (i.e. multi-version concurrency control verification link), so that the next processing link (i.e.
  • multi-version concurrency control verification link contains the verification result area contained in all target blocks received The blocks are sorted according to their execution order, so that they are executed in order, which improves the processing efficiency of the next processing link (that is, the multi-version concurrency control verification link).
  • the block header area (i.e. Block Header) of each verification result block is recorded with the block serial number (i.e. Number) and the previous block hash value (That is, PreviousHash) and the current block hash value (ie, DataHash). Since the next processing link (i.e., multi-version concurrency control verification link), the sequence of all submitted verification result blocks must be guaranteed, and the order of all verification result blocks can be determined by the block sequence number. It can be determined based on the hash pointers between different pointers, specifically based on the sequence of the previous block's hash value and the current block's hash value. Therefore, it is possible to detect whether the newly stored signature verification result block in the cache is the current expected block in real time.
  • block serial number i.e. Number
  • PreviousHash PreviousHash
  • DataHash DataHash
  • the latest signature verification result block is the current expected block, it can be based on all the signature verification results stored in the cache
  • the block number or hash pointer value of the block (including the hash value of the previous block and the hash value of the current block) will be determined by at least one verification result block that is continuous with the current expected block as the starting block It is a target block that can be submitted to the next processing link.
  • the sliding window technology can be used to determine the current desired block and all consecutive verification result blocks as the target block, that is, the sliding window is used to determine at least one continuous verification with the current desired block as the starting block. Check the result block to determine the target block.
  • the current desired block is contained in the cache, and if the current desired block is contained in the cache, at least one continuous verification result block with the current desired block as the starting block is determined as the target area Block in order to subsequently submit the target block as a whole to the next processing link, so that the next processing link processes all the verification result blocks in sequence.
  • all verification result blocks are sorted according to the current block hash value or block serial number of all verification result blocks in the cache, so that all verification result blocks are sorted.
  • the result block is stored in the cache according to the current block hash value or the sequence of the block serial number, so as to ensure the efficiency of subsequent determination of the target block.
  • S204 Submit the target block, and update the current desired block based on the block label corresponding to the last verification result block in the target block.
  • the server determines at least one consecutive signature verification result block with the current desired block as the starting block as the target block, and submits the target block to the next processing link. After the submission is successful, the target block is not Stored in the cache, other verification result blocks that are not continuous with the target block are still stored in the cache. Understandably, when the target block is submitted to the next processing link, the current desired block in the cache needs to be updated in real time, so that when the cache receives a new verification result block, the steps S203 and S204 can be executed smoothly. step.
  • the current desired block when the target block is submitted to the next processing link, the current desired block needs to be updated based on the block label corresponding to the last verification result block in the target block. Since the target block is a continuous block formed by at least one continuous verification result block, and the last verification result block in the target block is the end block, the next block after the end block is the update The current desired block of, so as to repeat step S203 and step S204 based on the updated current desired block.
  • the pre-created standby verification thread is concurrently started to perform signature verification on the block to be processed in the block queue, and the corresponding verification result block is obtained to ensure the block
  • the verification efficiency of signature verification for all pending blocks in the queue saves the processing time of signature verification, and the standby verification thread does not need to create and destroy threads, which helps to save system loss.
  • the real-time detection cache contains the current desired block
  • at least one continuous verification result block with the current desired block as the starting block is determined as the target block and submitted The target block is to ensure that the submitted target block contains at least one consecutive signature verification result block to ensure the execution sequence between the blocks.
  • the real-time detection of whether the current desired block is contained in the cache in step S203 specifically includes the following steps:
  • S301 Detect the block label corresponding to the verification result block in the cache in real time, and determine whether the block label matches the block guide information recorded in the cache in real time.
  • the server may use a cache monitoring program to monitor whether there is incremental data change in the cache, so as to detect in real time whether the cache receives a new verification result block. That is, if the cache monitoring program monitors that there is an incremental change in the data in the cache, it means that the cache has received the newly stored signature verification result block, and it needs to detect in real time whether the newly stored signature verification result structure is the current desired block.
  • the server when the server detects that the cache receives the newly stored signature verification result block, it parses the signature verification result block to obtain the signature verification result block corresponding to the signature verification result block from the block header area of the signature verification result block.
  • the block label of the block label can include the block serial number, and can also include the current block hash value and the previous block hash value.
  • the block guide information is information used to guide the determination of the current desired block corresponding to the cache.
  • the block guide information can be stored in a sliding window, an array or other forms, so that when a new verification result block is detected to be added to the cache, the block label of the new verification result block and the block guide information are used Matching is performed to determine whether the new verification result block is the current expected block.
  • the block guide information can be the desired block serial number, which is the block serial number corresponding to the current desired block, and the desired block serial number can correspond to the last verification result block in the newly submitted target block
  • the ending block sequence number is the next block sequence number determined by processing the ending block sequence number using the block sequence number naming rule.
  • the last verification result block in the newly submitted target block can be understood as the end block in the target block
  • the end block sequence number is the block sequence number in the end block.
  • the block sequence number naming rule is a naming rule used to assign unique block sequence numbers to different blocks in a certain event.
  • the block sequence numbers determined by naming according to the block sequence number naming rule are sequential, so that according to the block The naming determines whether at least two verification result blocks are consecutive blocks.
  • the block sequence number of the newly stored signature verification result block in the cache is the expected block sequence number, it can be detected in real time whether the current expected block is contained in the cache. That is, if the block sequence number of the newly stored verification result block is the same as the expected block sequence number, the verification result block is the current expected block; if the block sequence number of the newly stored verification result block is the same as the expected area If the sequence numbers of the blocks are not the same, the verification result block is not the current expected block.
  • the block guide information can also be the expected block pointer value, and the expected block pointer value can be the current block hash value corresponding to the last verification result block in the newly submitted target block, that is, the expected block pointer The value is the current block hash value of the ending block.
  • the previous block hash value of the newly stored verification result block in the cache is the same as the expected block pointer value; if the same, the verification result block is the current expected block; if not If it is the same, the verification result block is not the current expected block.
  • the expected block pointer value is specifically the last submitted target block
  • the specific process of real-time detection of whether the current desired block is contained in the cache includes the following steps: (1) First determine whether the verification result block pointed to by the hash value of the previous block is a system configuration block, and the system configuration block Refers to the block pre-configured by the system administrator to record information such as event information of an event and information of both parties to the transaction. Generally speaking, the system configuration block is the first current desired block corresponding to an event. Directly submitted as the target block to the next processing link.
  • the signature verification result block pointed to by the hash value of the previous block is a system configuration block
  • the signature verification result block is the current desired block, so that it can be submitted to the next block based on the current desired block.
  • the target block of the processing link If the verification result block pointed to by the hash value of the previous block is not a system configuration block, it is determined whether the hash value of the previous block matches the expected block pointer value; if it matches, then The verification result block is the current expected block; if it does not match, the verification result block is not the current expected block. Since the target block submitted each time contains at least one continuous verification result block with the current expected block in the cache as the starting block, the current area of the last verification result block in the target block The block hash value can indicate the next current expected block after the target block submitted this time.
  • the block guide information in the cache can be determined using the expected block number, which is set to 1. Specifically, when the cache receives the first verification result block, its block sequence number is 6.
  • the block sequence number is 6 in the verification result area
  • the block is not the current expected block, save it in the cache.
  • its block sequence number is 8. Since its block sequence number is not the expected block sequence number (ie 1), the verification result block with the block sequence number 6 is not
  • the current expected block is sorted according to the block sequence numbers corresponding to all the verification result blocks in the cache, so that the verification result block No. 6 is stored in front of the verification result block No. 8...
  • the cache is cached in the receiving To the seventh verification result block, when the block sequence number is 1, since its block sequence number is the current expected sequence number (ie 1), the verification result block with the block sequence number 1 is the current expected sequence number, then All consecutive verification result blocks starting with the first verification result block are regarded as a target block, that is, the first, second, third, fourth, fifth and sixth verification result blocks will be checked in sequence.
  • the signature result block is determined to be a target block. Since the signature verification result block No. 8 and the signature verification result block No. 6 in the cache are not continuous, the signature verification result block No. 8 is not determined as one of the target blocks. Check result block. At this time, the signature verification result block No. 6 is the end block in the target block.
  • the current desired block After submitting the target block formed by the verification result blocks 1 to 6 to the next processing link, the current desired block needs to be updated based on the block label corresponding to the last verification result block in the target block. That is, based on the block label corresponding to the block No. 6 verification result (such as the block number or the current block hash value), the block guide information corresponding to the new current desired block in the cache is updated, that is, the new current block in the cache is updated.
  • the desired block serial number corresponding to the desired block, and the desired block serial number is specifically the next block serial number after the end block serial number, that is, the 7th serial number. Understandably, after submitting the target block formed by the signature verification result block No.
  • the newly determined expected block sequence number is 7; when the cache receives the eighth verification result block, because of its block The serial number is 7, which is the same as the expected block serial number, so the 7th verification result block is the current desired block, based on the 7th verification result block in the cache and its consecutive verification result blocks (that is, the 8th verification result block) Result block) form a new target block and submit it to the next processing link...and so on to submit all verification result blocks to the next processing link.
  • the block label of the verification result block in the cache is detected in real time, and a certain verification result area can be quickly determined according to whether the block label and the block guidance information match. Whether the block is the current desired block, in order to improve the efficiency of determining the current desired block, thereby helping to improve the overall processing efficiency of the event.
  • the blockchain transaction processing method further includes the following steps:
  • the number of cores of the blockchain system is specifically the number of cores of the CPU (Central Processing Unit, central processing unit) in the server, that is, the number of processors.
  • the process of obtaining the number of cores of the blockchain system is based on the prior art.
  • the user can view the number of processors corresponding to the number of cores of the blockchain system in the task manager, or it can be executed in sequence. Start menu" -> "Run” -> "Enter cmd” -> "Enter wmic” -> “Enter cpu get” These operations get the number of cores of each server in the blockchain system.
  • S402 Determine the target number based on the number of cores and the target ratio range, and create a signature verification thread pool.
  • the signature verification thread pool includes standby verification threads corresponding to the target number.
  • the target ratio range is a preset ratio range, which can be 1.5-3 times.
  • the target number is specifically the product of the number of cores and the target ratio range. Generally speaking, when the target number is twice the number of cores, that is, when the target ratio range is 2, the cost of thread switching in the CPU of the blockchain system is less, which is more conducive to reducing the loss of the signature verification system.
  • a signature verification thread pool is created on the server of the blockchain system, and the signature verification thread pool includes the target number
  • the corresponding standby verification thread is used to subsequently use the standby verification thread corresponding to the target number to perform signature verification on the pending block in the block queue that needs to be processed.
  • the standby verification thread performs signature verification when it is working, and enters a dormant state when it is not working, without thread creation and destruction, which reduces CPU usage and helps reduce system loss.
  • the number of standby verification threads in the verification thread pool matches the target number, which can maximize the processing efficiency of signature verification, avoid waste of system resources, and avoid excessive numbers that affect other tasks except signature verification. Processing efficiency.
  • step S202 concurrently starting the pre-created standby verification thread includes the following steps:
  • S501 Monitor the number of blocks corresponding to the blocks to be processed in the block queue in real time.
  • a counter is provided on the server, and the counter is used to monitor the number of blocks corresponding to the blocks to be processed in the block queue in real time. For example, if a newly added block to be processed is added to the block queue, the counter is increased by 1. ; If a block to be processed in the block queue is allocated to the standby verification thread for signature verification processing, the counter is reduced by 1, so as to realize the real-time monitoring of the number of blocks to be processed in the block queue through the counter.
  • the wake-up instruction is an instruction used to wake up the standby verification thread in the dormant state. Specifically, if the number of blocks is greater than zero, it means that there are pending blocks that need to be processed in the block queue. At this time, the server triggers a standby verification thread that matches the number of blocks in the verification thread pool. The system thread is used to allocate the to-be-processed block in the block queue to the corresponding signature verification thread for signature verification processing.
  • the triggered wake-up instruction can wake up all the standby verification threads in the dormant state in the verification thread pool, and determine the corresponding standby verification threads according to the CPU scheduling situation.
  • the block to be processed is allocated to the corresponding standby verification thread, and the other standby verification threads enter the dormant state again.
  • the triggered wake-up instruction can randomly wake up the standby signature verification thread in the dormant state, and allocate the pending block in the block queue to the corresponding standby signature verification thread.
  • concurrently waking the standby verification threads in the dormant state in the signature verification thread pool specifically refers to: comparing the number of blocks with the number of threads in the dormant state in the verification thread pool. ; If the number of blocks is less than or equal to the number of threads, based on the wake-up instruction, wake up the standby verification thread that matches the number of blocks; if the number of blocks is greater than the number of threads, wake up the standby that matches the number of threads based on the wake-up instruction
  • the signature verification thread wakes up all the standby verification threads that are in the dormant state. Understandably, based on the comparison result of the number of blocks and the number of threads, the number of standby verification threads that need to be awakened is determined, so as to realize the unified management of the standby verification threads.
  • the working status of each standby verification thread is monitored in real time, and the block is processed in any standby verification thread Perform signature verification, obtain the verification result block, and store the verification result block in the cache, then determine the standby verification thread as an idle wake-up thread to send the pending block in the block queue to the corresponding Idle wake up thread.
  • the idle wake-up thread refers to the standby verification thread waiting to receive a new block to be processed for processing within a preset time after the end of the working state; if a new block to be processed is received within the preset time, Then the idle wake-up thread enters the working state again; if no new block to be processed is received within the preset time, the idle wake-up thread enters the sleep state.
  • the standby verification thread is determined to be an idle wake-up thread, which can be placed in waiting to receive a new block to be processed within a preset time, avoiding directly entering the sleep state and requiring additional wake-up operations, which helps to reduce system overhead .
  • a wake-up instruction is triggered based on the number of blocks corresponding to the blocks to be processed in the block queue to wake up the standby verification threads in the dormant state in the verification thread pool, and The block to be processed is allocated to the corresponding standby verification thread, which can make the standby verification thread in the dormant state enter the working state.
  • the thread wake-up operation is required, and the thread creation and destruction are not required. To reduce the CPU usage and reduce system consumption.
  • step S201 which is to receive a block to be processed, and store the block to be processed in a block queue, includes:
  • S601 Receive a block to be processed, perform a legality check on the block to be processed, and obtain a legality check result.
  • the legality check refers to the process of checking whether the received block to be processed is a block sent by a legal blockchain node. Specifically, after receiving the block to be processed, the server performs legality verification on the block signature recorded in the metadata area of the block to be processed, and if the signature verification is passed, the legality verification result that has passed the verification is obtained; if If the signature verification fails, the legality verification result that the verification fails is obtained. Understandably, each legal blockchain node in the blockchain system will record its own digital signature in the metadata area of each block to be processed, and this digital signature is the The block signature of the block to be processed. After receiving each block to be processed, the server obtains the block signature from the metadata area, and then uses the signature verification method corresponding to the signature encryption algorithm corresponding to the digital signature to perform legality verification, and obtain the legality verification result.
  • the block to be processed is stored in the block queue, so that the standby verification thread is used to subsequently check the pending block in the block queue.
  • step S202 which is to perform signature verification on the block to be processed in the block queue, to obtain the verification result block, includes the following steps:
  • S701 Detect the number of transactions corresponding to all transactions to be processed in each block to be processed.
  • the number of transactions refers to the number of all transactions to be processed in the block to be processed, and specifically refers to the number corresponding to all transaction data recorded in the block data area of the block to be processed. Understandably, each transaction data recorded in the block data area corresponds to a pending transaction.
  • the preset number threshold is a preset threshold used to evaluate whether the number of transactions reaches a standard recognized as a larger threshold. Specifically, if the number of transactions corresponding to all pending transactions in any to-be-processed block is greater than the preset number threshold, it means that the number of transactions corresponding to pending transactions in the to-be-processed block is too large. If only the standby verification thread is used Processing may result in too long processing time. Therefore, an auxiliary signature verification sub-thread needs to be created to process the pending transactions in the processing block.
  • the auxiliary signature verification sub-thread is a thread created by the system to assist the standby signature verification thread to process a block to be processed with a large number of transactions, and is destroyed after the block to be processed is processed.
  • the number of sub-threads is determined according to the number of transactions, and creating an auxiliary signature verification sub-thread matching the number of sub-threads specifically includes: rounding down the quotient of the number of transactions and a preset number threshold to obtain the number of sub-threads, And create an auxiliary sign verification sub-thread that matches the number of sub-threads. That is, the number of child threads can be determined using the following formula: Among them, N is the auxiliary signature verification sub-thread, A is the number of transactions, and B is the preset number threshold.
  • S703 Use the standby signature verification thread and the auxiliary signature verification subthread to perform signature verification on the transaction to be processed, and obtain a signature verification result.
  • the server uses the standby verification thread and the auxiliary verification sub-thread matching the number of sub-threads to perform concurrent signature verification on all pending transactions in the pending block, so as to quickly obtain the correspondence of all pending transactions in the pending block.
  • the result of signature verification to improve the efficiency of signature verification of the block to be processed with more transactions to be processed. That is, in this embodiment, N+1 threads may be used to perform signature verification on all pending transactions in a pending block, and the corresponding signature verification results may be quickly obtained.
  • S704 Store the signature verification result in the metadata area of the block to be processed, obtain the signature verification result block, release the standby signature verification thread, and destroy the auxiliary signature verification subthread.
  • the server stores the signature verification results corresponding to all pending transactions in the metadata area of the pending block to form a verification result block containing the signature verification result, which can ensure the efficiency of obtaining the verification result block.
  • the standby signature verification thread needs to be released so that the standby signature verification thread can process other pending blocks.
  • the standby signature verification thread will be used within a preset time.
  • the thread is an idle wake-up thread; if a new block to be processed is received within the preset time, the idle wake-up thread re-enters the working state; if a new block to be processed is not received within the preset time, it is idle Wake up the thread to enter the sleep state.
  • auxiliary signature verification sub-thread Since the auxiliary signature verification sub-thread is temporarily created by the system to assist the standby verification thread to process the block to be processed with a large number of transactions, after the processing of the pending block is completed, the auxiliary signature verification sub-thread needs to be destroyed. Avoid too many threads in the system to affect the processing efficiency of each thread.
  • an auxiliary signature verification subthread and a standby verification subthread are created concurrently for these pending transactions Perform signature verification processing to improve the signature verification efficiency of the block to be processed, thereby ensuring the overall processing efficiency.
  • the standby verification thread needs to be released and the auxiliary verification subthread is destroyed, which can effectively save system losses and ensure system processing efficiency.
  • step S204 that is, after submitting the target block
  • the blockchain transaction processing method further includes the following steps:
  • S801 In the process of multi-version concurrency control verification, sequentially identify the signature verification result of each verification result block in the target block.
  • the multiple version concurrent control (MVCC) verification process is mainly used to verify whether the transaction state when the transaction (that is, the transaction corresponding to the verification result block) is submitted is the current state when the transaction is generated process.
  • MVCC multiple version concurrent control
  • the check result corresponding to any verification result block depends on the previous verification result block, that is, the previous verification result block may modify the current state of the system. It will affect the validity judgment of the subsequent verification result blocks, that is, the order of the verification result blocks may cause the final state of the entire blockchain to be inconsistent. Therefore, each verification result in the target block needs to be sequentially checked.
  • the signature verification result of the block is identified.
  • the transaction state corresponding to the verification result block is compared with the current state, and if the transaction state is consistent with the current state, the verification result block is compared Perform an execution operation to perform an operation on the verification result block to obtain valid transaction data; if the transaction status is inconsistent with the current state, the transaction data corresponding to the verification result block is determined to be invalid transaction data.
  • the transaction state corresponding to the verification result block refers to the state recorded by the transaction data in the verification result block; the current state corresponding to the verification result block refers to the system corresponding to the transaction data in the verification result block status.
  • a transaction of 100 yuan transferred to B is submitted at time T1 after a period of time after checking the account balance to form the first transaction data, that is, the system The transaction will be received and processed at time T1.
  • A's friend C uses the secondary card of the bank card or online banking and other other methods to swipe 100 yuan in other places during the period from A's checking of the account balance to the submission of the transaction, that is, T0-T1, then A at this time
  • the submitted transfer transaction of 100 yuan will fail because the transaction status (account balance is 100 yuan, the transfer transaction can be executed) when the transaction is generated, and the current state before the transaction is executed by the system (the account balance is 0 yuan) makes the transaction status Inconsistent with the current status, the transaction data corresponding to this 100 yuan transfer transaction is directly determined as invalid transaction data.
  • the transaction occurred when the transaction occurred. If the transaction status (account balance is 100 yuan) and the current status before the transaction is executed (account balance is 100 yuan), if the two are consistent, the transaction data corresponding to this 100 yuan transfer transaction is determined as valid transaction data. Understandably, whether the transaction status corresponding to the verification result block is consistent with the current status mainly depends on the time difference in the transaction process.
  • the transaction data corresponding to the verification result block is directly determined as invalid transaction data, without the need to perform subsequent operations of verifying the transaction state and the current state. It helps to reduce the process of multi-version concurrency control verification and improve processing efficiency.
  • S804 Perform transaction persistence processing based on valid transaction data and invalid transaction data.
  • transaction persistence is also called transaction commit (Commit) refers to the process of committing transaction data obtained after signature verification and multi-version concurrency control verification in a block, and writing it to disk.
  • Transaction commit refers to the process of committing transaction data obtained after signature verification and multi-version concurrency control verification in a block, and writing it to disk.
  • the process of transaction persistence if the transaction data corresponding to a verification result block is valid transaction data, the corresponding current state in the blockchain is modified based on the valid transaction data; if a verification result is If the transaction data corresponding to the block is invalid transaction data, the invalid transaction data will not be adopted. Therefore, there is no need to modify the current state in the blockchain and perform transaction persistence processing on invalid transaction data to facilitate traceability.
  • the signature verification results of each verification result block in the target block are sequentially identified, so that the execution order is first
  • the verification result block is verified first, and the verification result block with the subsequent execution sequence is verified later, so that the verification of the verification result block with the subsequent execution sequence can rely on the verification result block with the previous execution sequence
  • the verification results are changed.
  • the valid transaction data and invalid transaction data determined by the multi-version concurrency control verification process can be subjected to transaction persistence processing to ensure the security of these valid transaction data and invalid transaction data and avoid tampering.
  • a blockchain transaction processing device is provided, and the blockchain transaction processing device corresponds to the blockchain transaction processing method in the above-mentioned embodiment one-to-one.
  • the blockchain transaction processing device includes a block receiving module 901 to be processed, a signature verification processing module 902, a target block determination module 903, and a target block submission module 904.
  • the detailed description of each functional module is as follows:
  • the to-be-processed block receiving module 901 is configured to receive the to-be-processed blocks and store the to-be-processed blocks in a block queue, and each to-be-processed block corresponds to a block label.
  • the signature verification processing module 902 is configured to concurrently start a pre-created standby verification thread, perform signature verification on the block to be processed in the block queue, obtain the verification result block, and store the verification result block in the cache.
  • the target block determination module 903 is used for real-time detection of whether the current desired block is contained in the cache, and if the current desired block is contained in the cache, at least one continuous verification result block with the current desired block as the starting block will be used Determined as the target block.
  • the target block submission module 904 is used to submit the target block and update the current desired block based on the block label corresponding to the last verification result block in the target block.
  • the target block determining module 903 includes:
  • the block label matching processing unit is used to detect the block label corresponding to the verification result block in the cache in real time, and determine whether the block label matches the block guide information recorded in the cache in real time.
  • the current desired block determining unit is configured to, if the block label matches the block guide information, the verification result block corresponding to the block label is the current desired block.
  • the blockchain transaction processing device further includes:
  • the number of cores determining unit is used to obtain the number of cores of the blockchain system.
  • the verification thread creation unit is used to determine the target number based on the number of cores and the target ratio range, and create a verification thread pool.
  • the verification thread pool includes the standby verification threads corresponding to the target number.
  • the signature verification processing module 902 includes:
  • the block quantity monitoring unit is used for real-time monitoring of the block quantity corresponding to the to-be-processed block in the block queue.
  • the thread wakeup allocation unit is used to trigger a wake-up instruction if the number of blocks is greater than zero. Based on the wake-up instruction, it concurrently wakes up the standby verification threads in the verification thread pool and allocates the pending blocks in the block queue Give the corresponding standby verification thread.
  • the block receiving module 901 to be processed includes:
  • the legality check unit is used to receive the block to be processed, perform legality check on the block to be processed, and obtain the legality check result.
  • the block storage unit is used to store the to-be-processed block in the block queue if the result of the legality check is passed.
  • the signature verification processing module 902 includes:
  • the transaction quantity detection unit is used to detect the transaction quantity corresponding to all pending transactions in each pending block.
  • the auxiliary thread creation unit is used to determine the number of child threads according to the number of transactions if the number of transactions is greater than the preset number threshold, and create an auxiliary sign verification child thread that matches the number of child threads.
  • the signature verification processing unit is used to use the standby verification thread and the auxiliary verification sub-thread to perform signature verification on the transaction to be processed, and obtain the signature verification result.
  • the signature verification result block acquisition unit is used to store the signature verification result in the metadata area of the block to be processed, obtain the signature verification result block, release the standby signature verification thread and destroy the auxiliary signature verification subthread.
  • the blockchain transaction processing device further includes:
  • the signature verification result identification unit is used to sequentially identify the signature verification result of each verification result block in the target block in the multi-version concurrency control verification process.
  • the valid transaction data determining unit is used to compare the transaction state corresponding to the verification result block with the current state if the signature verification result is valid, and the transaction state is consistent with the current state, then perform operations on the verification result block To obtain valid transaction data.
  • the invalid transaction data determining unit is configured to determine the transaction data corresponding to the verification result block as invalid transaction data if the signature verification result is that the signature is invalid.
  • the transaction persistence processing unit is used to perform transaction persistence processing based on valid transaction data and invalid transaction data.
  • Each module in the above-mentioned blockchain transaction processing device can be implemented in whole or in part by software, hardware, and a combination thereof.
  • the above-mentioned modules may be embedded in the form of hardware or independent of the processor in the computer equipment, or may be stored in the memory of the computer equipment in the form of software, so that the processor can call and execute the operations corresponding to the above-mentioned modules.
  • a computer device is provided.
  • the computer device may be a server, and its internal structure diagram may be as shown in FIG. 10.
  • the computer equipment includes a processor, a memory, a network interface, and a database connected through a system bus.
  • the processor of the computer device is used to provide calculation and control capabilities.
  • the memory of the computer device includes a non-volatile storage medium and an internal memory.
  • the non-volatile storage medium stores an operating system, a computer program, and a database.
  • the internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium.
  • the database of the computer device is used to execute the data adopted or formed in the process of the blockchain transaction processing method in the foregoing embodiment.
  • the network interface of the computer device is used to communicate with an external terminal through a network connection.
  • the computer program is executed by the processor to realize a blockchain transaction processing method.
  • a computer device including a memory, a processor, and a computer program stored on the memory and capable of running on the processor.
  • the processor executes the blockchain transaction processing in the above embodiment when the processor executes the computer program.
  • the steps of the method such as steps S201-S204 shown in FIG. 2, or the steps shown in FIG. 3 to FIG. 8, are not repeated here to avoid repetition.
  • the function of each module/unit in the embodiment of the blockchain transaction processing device is realized, for example, the block receiving module 901, the signature verification processing module 902, and the target area shown in FIG. 9
  • the functions of the block determination module 903 and the target block submission module 904 are not repeated here in order to avoid repetition.
  • a computer-readable storage medium is provided, and a computer program is stored on the computer-readable storage medium.
  • the computer program When the computer program is executed by a processor, it realizes the steps of the blockchain transaction processing method in the above-mentioned embodiment, as shown in FIG. Steps S201-S204 shown in 2 or the steps shown in FIG. 3 to FIG. 8 are not repeated here in order to avoid repetition.
  • the computer program when the computer program is executed by the processor, the function of each module/unit in the embodiment of the blockchain transaction processing device is realized, for example, the to-be-processed block receiving module 901 and the signature verification processing module 902 shown in FIG. 9
  • the functions of the target block determining module 903 and the target block submitting module 904 are not repeated here in order to avoid repetition.
  • Non-volatile memory may include read only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory.
  • Volatile memory may include random access memory (RAM) or external cache memory.
  • RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous chain Channel (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

Abstract

A blockchain transaction processing method and apparatus, a computer device, and a storage medium. The method comprises: receiving blocks to be processed, and storing said blocks in a block queue, wherein each of said blocks corresponds to one block label (S201); concurrently starting a pre-created standby signature verification thread, performing signature verification on said blocks in the block queue to acquire a signature verification result block, and storing the signature verification result block in a cache (S202); detecting, in real time, whether the cache contains the current expected block, and if the cache contains the current expected block, determining at least one continuous signature verification result block, which takes the current expected block as a starting block, to be a target block (S203); and submitting the target block, and updating the current expected block on the basis of the block label corresponding to the last signature verification result block in the target block (S204). According to the method, the verification efficiency of concurrently starting the standby signature verification thread to perform signature verification on said blocks is improved, saving the processing time for signature verification, and facilitating the reduction of system loss.

Description

区块链事务处理方法、装置、计算机设备及存储介质Block chain transaction processing method, device, computer equipment and storage medium
本申请要求于2019年9月6日提交中国专利局、申请号为201910843124.9,发明名称为“区块链事务处理方法、装置、计算机设备及存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of a Chinese patent application filed with the Chinese Patent Office on September 6, 2019 with the application number 201910843124.9 and the invention title "Blockchain transaction processing methods, devices, computer equipment and storage media", and its entire contents Incorporated in this application by reference.
技术领域Technical field
本申请涉及区块链技术领域,尤其涉及一种区块链事务处理方法、装置、计算机设备及存储介质。This application relates to the field of blockchain technology, and in particular to a blockchain transaction processing method, device, computer equipment and storage medium.
背景技术Background technique
区块链一般被理解为一个分布式账本,它的本质也是一个分布式的数据库。联盟区块链与普通区块链的根本区别之一是需要提供隐私保护机制,通常情况下,该隐私保护机制是通过密码学中的签名加密和验签解密来实现。通常情况下,多个事务打包成区块的形式发送给区块链上的节点,由节点解开该区块,获取区块中的事务,先对每个事务进行签名验证,然后对所有签名验证通过的事务整体做多版本并发控制验证,最后进行事务持久化处理,以将事务信息写入磁盘。发明人意识到,由于多版本并发控制验证过程中需依据区块之间先后的执行顺序进行检查,因此,当前区块链事务处理过程中,需先对每个区块依次进行签名验证、多版本并发控制验证和事务持久化进行处理,在完成一个区块的处理之后再处理下一个区块。其中,签名验证,即验证区块中交易数据对应的签名,其验证过程包含大量的数学运算,耗时较长。Blockchain is generally understood as a distributed ledger, and its essence is also a distributed database. One of the fundamental differences between the alliance blockchain and the ordinary blockchain is the need to provide a privacy protection mechanism. Normally, the privacy protection mechanism is implemented through signature encryption and signature verification and decryption in cryptography. Usually, multiple transactions are packaged into blocks and sent to the nodes on the blockchain. The node unlocks the block, obtains the transactions in the block, first verifies the signature of each transaction, and then all signatures The verified transactions are verified for multi-version concurrency control as a whole, and finally processed for transaction persistence to write the transaction information to the disk. The inventor realizes that since the verification process of multi-version concurrency control needs to be checked according to the sequence of execution between the blocks, therefore, in the current blockchain transaction processing process, each block needs to be sequentially verified by signatures and multiple blocks. Version concurrency control verification and transaction persistence are processed, and the next block is processed after the processing of one block is completed. Among them, the signature verification is to verify the signature corresponding to the transaction data in the block. The verification process involves a large number of mathematical operations and takes a long time.
当前区块链中主要采用串行验证方式对区块进行签名验证,这种验证方式使得后面的区块只能等待前面的区块验证完毕之后才可被验证,不能充分利用系统的计算资源,导致系统资源浪费较大,使得区块链事务处理性能低下,事务处理效率较低。In the current blockchain, the serial verification method is mainly used to verify the signature of the block. This verification method makes the subsequent blocks only wait for the previous block to be verified before they can be verified, and the system’s computing resources cannot be fully utilized. This leads to a large waste of system resources, resulting in low blockchain transaction processing performance and low transaction processing efficiency.
发明内容Summary of the invention
本申请实施例提供一种区块链事务处理方法、装置、计算机设备及存储介质,以解决当前区块链事务处理过程中采用串行验证方式对区块进行签名验证时存在的处理效率较低且计算资源浪费较大的问题。The embodiments of the application provide a blockchain transaction processing method, device, computer equipment, and storage medium, so as to solve the problem of low processing efficiency when using serial verification to verify the signature of the block in the current blockchain transaction processing. And the problem of large waste of computing resources.
一种区块链事务处理方法,包括:A blockchain transaction processing method, including:
接收待处理区块,将所述待处理区块存储在区块队列中,每一所述待处理区块对应一区块标签;Receiving the to-be-processed blocks, storing the to-be-processed blocks in a block queue, and each of the to-be-processed blocks corresponds to a block label;
并发启动预先创建的待命验签线程,对所述区块队列中的所述待处理区块进行签名验证,获取验签结果区块,将所述验签结果区块存储到缓存中;Concurrently start a pre-created standby signature verification thread, perform signature verification on the block to be processed in the block queue, obtain a signature verification result block, and store the signature verification result block in a cache;
实时检测所述缓存中是否包含当前期望区块,若所述缓存中包含所述当前期望区块,则将以所述当前期望区块为起始块的连续的至少一个验签结果区块确定为目标区块;Real-time detection of whether the current desired block is included in the cache, and if the current desired block is included in the cache, at least one continuous verification result block with the current desired block as the starting block is determined Is the target block;
提交所述目标区块,并基于所述目标区块中最后一个验签结果区块对应的区块标签更新所述当前期望区块。Submit the target block, and update the current desired block based on the block label corresponding to the last verification result block in the target block.
一种区块链事务处理装置,包括:A blockchain transaction processing device, including:
接收待处理区块,将所述待处理区块存储在区块队列中,每一所述待处理区块对应一区块标签;Receiving the to-be-processed blocks, storing the to-be-processed blocks in a block queue, and each of the to-be-processed blocks corresponds to a block label;
并发启动预先创建的待命验签线程,对所述区块队列中的所述待处理区块进行签名验证,获取验签结果区块,将所述验签结果区块存储到缓存中;Concurrently start a pre-created standby signature verification thread, perform signature verification on the block to be processed in the block queue, obtain a signature verification result block, and store the signature verification result block in a cache;
实时检测所述缓存中是否包含当前期望区块,若所述缓存中包含所述当前期望区块,则将以所述当前期望区块为起始块的连续的至少一个验签结果区块确定为目标区块;Real-time detection of whether the current desired block is included in the cache, and if the current desired block is included in the cache, at least one continuous verification result block with the current desired block as the starting block is determined Is the target block;
提交所述目标区块,并基于所述目标区块中最后一个验签结果区块对应的区块标签更新所述当前期望区块。Submit the target block, and update the current desired block based on the block label corresponding to the last verification result block in the target block.
一种计算机设备,包括存储器、处理器以及存储在所述存储器中并可在所述处理器上运行的计算机程序,所述处理器执行所述计算机程序时实现上述区块链事务处理方法的步骤。A computer device comprising a memory, a processor, and a computer program stored in the memory and capable of running on the processor, and the processor implements the steps of the blockchain transaction processing method when the computer program is executed .
一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,所述计算机程序被处理器执行时实现上述区块链事务处理方法的步骤。A computer-readable storage medium, which stores a computer program, and when the computer program is executed by a processor, realizes the steps of the blockchain transaction processing method described above.
上述区块链事务处理方法、装置、计算机设备及存储介质,并发启动预先创建的待命验签线程对区块队列中的待处理区块进行签名验证,获取对应的验签结果区块,以保证区块队列中所有待处理区块进行签名验证的验证效率,节省签名验证的处理时间,而且待命验签线程无需进行线程的创建和销毁,有助于节省系统损耗。将所有验签结果区块存储到缓存中,实时检测缓存中包含当前期望区块时,将以当前期望区块为起始块的连续的至少一个验签结果区块确定为目标区块并提交该目标区块,以保证提交的目标区块中包含连续的至少一个验签结果区块,确保区块之间的执行顺序。The above-mentioned blockchain transaction processing method, device, computer equipment and storage medium simultaneously start the pre-created standby verification thread to perform signature verification on the block to be processed in the block queue, and obtain the corresponding verification result block to ensure The verification efficiency of signature verification for all pending blocks in the block queue saves the processing time of signature verification, and the standby verification thread does not need to create and destroy threads, which helps to save system loss. Store all verification result blocks in the cache. When the real-time detection cache contains the current desired block, at least one continuous verification result block with the current desired block as the starting block is determined as the target block and submitted The target block is to ensure that the submitted target block contains at least one consecutive signature verification result block to ensure the execution sequence between the blocks.
附图说明Description of the drawings
图1是本申请一实施例中区块链事务处理方法的一应用环境示意图;FIG. 1 is a schematic diagram of an application environment of a blockchain transaction processing method in an embodiment of the present application;
图2是本申请一实施例中区块链事务处理方法的一流程图;Figure 2 is a flowchart of a blockchain transaction processing method in an embodiment of the present application;
图3是本申请一实施例中区块链事务处理方法的另一流程图;Fig. 3 is another flowchart of a blockchain transaction processing method in an embodiment of the present application;
图4是本申请一实施例中区块链事务处理方法的另一流程图;FIG. 4 is another flowchart of a blockchain transaction processing method in an embodiment of the present application;
图5是本申请一实施例中区块链事务处理方法的另一流程图;FIG. 5 is another flowchart of a blockchain transaction processing method in an embodiment of the present application;
图6是本申请一实施例中区块链事务处理方法的另一流程图;Fig. 6 is another flowchart of a blockchain transaction processing method in an embodiment of the present application;
图7是本申请一实施例中区块链事务处理方法的另一流程图;FIG. 7 is another flowchart of a blockchain transaction processing method in an embodiment of the present application;
图8是本申请一实施例中区块链事务处理方法的另一流程图;FIG. 8 is another flowchart of a blockchain transaction processing method in an embodiment of the present application;
图9是本申请一实施例中区块链事务处理方法的一示意图;FIG. 9 is a schematic diagram of a blockchain transaction processing method in an embodiment of the present application;
图10是本申请一实施例中计算机设备的一示意图。Fig. 10 is a schematic diagram of a computer device in an embodiment of the present application.
具体实施方式detailed description
本申请实施例提供的区块链事务处理方法,该区块链事务处理方法可应用如图1所示的应用环境中。具体地,该区块链事务处理方法应用在区块链系统中,该区块链系统包括通过区块链网络相连的多个区块链节点,每一区块链节点对应一区块链节点装置,每一区块链节点装置通过区块链网络与其他区块链节点装置相连,实现对区块链事务处理中运算量较大且耗时较长的签名验证过程进行并行处理,以提高签名验证的效率并节省处理时间,有助于提高整个区块链事务处理的整体效率。其中,区块链节点装置是一种能够按照事先设定或者存储的指令,自动进行数值计算和/或信息处理的设备。该区块链节点装置可以是计算机、也可以是单个网络服务器、多个网络服务器组成的服务器组或者基于云计算的由大量主机或者网络服务器构成的云,云计算是分布式计算的一种,由一群松散耦合的计算机集组成的一个超级虚拟计算机。According to the blockchain transaction processing method provided by the embodiment of the present application, the blockchain transaction processing method can be applied to the application environment as shown in FIG. 1. Specifically, the blockchain transaction processing method is applied to a blockchain system. The blockchain system includes multiple blockchain nodes connected by a blockchain network, and each blockchain node corresponds to a blockchain node Each block chain node device is connected to other block chain node devices through the block chain network, so as to realize the parallel processing of the signature verification process, which is computationally intensive and takes a long time in block chain transaction processing, to improve The efficiency of signature verification and saving processing time will help improve the overall efficiency of the entire blockchain transaction processing. Among them, the blockchain node device is a device that can automatically perform numerical calculation and/or information processing in accordance with pre-set or stored instructions. The blockchain node device can be a computer, a single network server, a server group composed of multiple network servers, or a cloud composed of a large number of hosts or network servers based on cloud computing. Cloud computing is a type of distributed computing. A super virtual computer composed of a group of loosely coupled computer sets.
在一实施例中,如图2所示,提供一种区块链事务处理方法,以该方法应用在图1中的区块链节点装置为服务器为例进行说明,包括如下步骤:In one embodiment, as shown in FIG. 2, a blockchain transaction processing method is provided. Taking the method applied to the blockchain node device in FIG. 1 as a server as an example for description, the method includes the following steps:
S201:接收待处理区块,将待处理区块存储在区块队列中,每一待处理区块对应一区块标签。S201: Receive a block to be processed, and store the block to be processed in a block queue, and each block to be processed corresponds to a block label.
其中,待处理区块是发送到区块链的待处理节点上的需要进行处理的区块。其中,待处理节点是区块链网络上的一个需要进行数据处理的区块链节点。每一待处理区块包括至少一个待处理事务,该待处理事务为需要进行后续处理的事务。可以理解地,服务器可以从区块链的待处理节点上获取待处理区块,以便后续对该待处理区块中的签名验证、多版本并发控制验证和事务持久化处理这三个环节的处理。Among them, the block to be processed is the block that needs to be processed sent to the node to be processed on the blockchain. Among them, the node to be processed is a blockchain node on the blockchain network that needs to process data. Each block to be processed includes at least one transaction to be processed, and the transaction to be processed is a transaction that requires subsequent processing. Understandably, the server can obtain the to-be-processed block from the to-be-processed node of the blockchain for subsequent processing of the three links of signature verification, multi-version concurrency control verification, and transaction persistence processing in the to-be-processed block .
区块队列是系统中预先创建的用于缓存需要进行处理的待处理区块的队列,该区块队列可以依据先进先出的顺序管理队列中的所有待处理区块。The block queue is a pre-created queue in the system for caching the to-be-processed blocks that need to be processed. The block queue can manage all the to-be-processed blocks in the queue in a first-in first-out order.
区块标签是待处理区块中存储的与该区块相对应的标签信息。本实施例中,每一待处理区块对应的区块标签包括区块序号(即Number)、当前区块哈希值(即DataHash)和上一区块哈希值(即PreviousHash),以便基于当前区块哈希值和上一区块哈希值确定不同待处理区块之间的执行顺序。其中,区块序号是用于唯一识别某一区块的序号。当前区块哈希值是用于指向当前区块的哈希指针值。上一区块哈希值是用于指向当前区块的上一区块的哈希指针值。因此,可基于当前区块哈希值和上一区块哈希值确定前后两个待处理区块之间的执行顺序。可以理解地,若区块序号是依据特定的区块序号命名规则进行命名的,即依据区块序号命名规则命名出的区块序号存在与区块之间执行顺序相对应的先后顺序时,可以依据区块序号确定不同待处理区块之间的执行顺序。The block label is the label information corresponding to the block stored in the block to be processed. In this embodiment, the block label corresponding to each block to be processed includes the block serial number (i.e. Number), the current block hash value (i.e. DataHash) and the previous block hash value (i.e. PreviousHash), so as to be based on The current block hash value and the previous block hash value determine the execution order of different blocks to be processed. Among them, the block serial number is a serial number used to uniquely identify a certain block. The current block hash value is a hash pointer value used to point to the current block. The previous block hash value is the hash pointer value used to point to the previous block of the current block. Therefore, the execution sequence between the two blocks to be processed can be determined based on the hash value of the current block and the hash value of the previous block. Understandably, if the block serial number is named according to a specific block serial number naming rule, that is, when the block serial number named according to the block serial number naming rule has a sequence corresponding to the execution order between the blocks, it can be Determine the execution sequence between different blocks to be processed according to the block number.
本实施例中,每一待处理区块包括区块头区域(即Block Header)、区块数据区域(即Block Data)和元数据区域(Metadata)。该区块头区域(即Block Header)是用于记录区块属性的区域,具体包括用于记录区块序号(即Number)、上一区块哈希值(即PreviousHash)和当前区块哈希值(即DataHash)等区块属性的区域。区块数据区域(即Block Data)就用于记录区块中的交易数据以及交易数据对应的签名数据等数据的区域。可以理解地,每一待处理区块的区块数据区域(即Block Data)上可以存储一个待处理事务对应的交易数据及其签名数据,也可以存储至少两个待处理事务对应的交易数据及其签名数据。也即每一待处理区块中包括至少一个待处理事务,至少一个待处理事务对应的交易数据及其签名数据依次记录在区块数据区域(即Block Data),在区块链事务处理过程中,需对区块数据区块中的每一待处理事务对应的签名数据进行签名验证,以保证该待处理事务对应的交易数据的安全性。元数据(Metadata),又称中介数据或中继数据,为描述数据的数据(data about data),主要是描述数据属性(property)的信息,用来支持如指示存储位置、历史数据、资源查找和文件记录等功能。元数据算是一种电子式目录,为了达到编制目录的目的,必须在描述并收藏数据的内容或特色,进而达成协助数据检索的目的。该元数据区域(Metadata)中记录的区块签名,以便基于该区块签名进行合法性校验。其中,区块签名是与待处理区块相对应的数字签名。可以理解地,该元数据区域(Metadata)上还设有用于记录签名验证结果的待填充区域,在对待处理区块进行签名验证之前,该待填充区域为空白区域。In this embodiment, each block to be processed includes a block header area (ie, Block Header), a block data area (ie, Block Data), and a metadata area (Metadata). The block header area (i.e. Block Header) is an area used to record block attributes, specifically including the block number (i.e. Number), the previous block hash value (i.e. PreviousHash) and the current block hash value. (Ie DataHash) and other block attributes. The block data area (ie, Block Data) is an area used to record transaction data in the block and signature data corresponding to the transaction data. Understandably, the block data area (i.e., Block Data) of each block to be processed can store transaction data and signature data corresponding to one transaction to be processed, or it can store at least two transaction data and transaction data corresponding to the transaction to be processed. Its signature data. That is to say, each block to be processed includes at least one transaction to be processed, and the transaction data and signature data corresponding to at least one transaction to be processed are sequentially recorded in the block data area (i.e., Block Data), during the process of blockchain transaction processing , It is necessary to perform signature verification on the signature data corresponding to each transaction to be processed in the block data block to ensure the security of the transaction data corresponding to the transaction to be processed. Metadata, also known as intermediary data or relay data, is data describing data (data about data), mainly information describing data properties, used to support such as indicating storage location, historical data, and resource search And file recording and other functions. Metadata can be regarded as an electronic catalog. In order to achieve the purpose of cataloging, it is necessary to describe and collect the content or characteristics of the data, and then achieve the purpose of assisting data retrieval. The block signature recorded in the metadata area (Metadata) can be verified based on the block signature. Among them, the block signature is a digital signature corresponding to the block to be processed. Understandably, the metadata area (Metadata) is also provided with a to-be-filled area for recording the signature verification result, and the to-be-filled area is a blank area before the signature verification of the block to be processed is performed.
S202:并发启动预先创建的待命验签线程,对区块队列中的待处理区块进行签名验证,获取验签结果区块,将验签结果区块存储到缓存中。S202: Concurrently start the pre-created standby signature verification thread, perform signature verification on the block to be processed in the block queue, obtain the signature verification result block, and store the signature verification result block in the cache.
其中,待命验签线程是系统预先分配的用于进行签名验证的线程,该待命验签线程在工作状态时进行签名验证,不工作时进入休眠状态,无需进行线程的创建和销毁,有助于节省系统损耗。该待命验签线程中采用的签名验证算法与待处理事务中预先采用的签名加密算法相匹配,即互为解密算法和加密算法,以保证签名验证的可行性。Among them, the standby verification thread is a thread pre-allocated by the system for signature verification. The standby verification thread performs signature verification when it is working, and enters a sleep state when it is not working. It does not need to create and destroy threads, which is helpful Save system loss. The signature verification algorithm adopted in the standby verification thread matches the signature encryption algorithm used in advance in the transaction to be processed, that is, the decryption algorithm and the encryption algorithm are mutually used to ensure the feasibility of signature verification.
本实施例中,服务器在检测到区块队列中存在需要进行处理的待处理区块之后,可以根据区块队列中的待处理区块的区块数量,并发启动预先创建的待命验签线程,采用该待命验签线程对区块队列中的每一待处理区块进行签名验证,获取该待处理区块对应的验签结果区块,由于待命验签线程是预先创建时,无需等待创建验签线程即可直接对待处理区块进行处理,以保证区块队列中所有待处理区块进行签名验证的验证效率,节省签名验证 的处理时间。可以理解地,可以依据区块队列中的先进先出顺序,依次给每一待处理区块分配相应的待命验签线程,以采用待命验签线程对待处理区块进行签名验证。采用多个待命验签线程并发执行的签名验证过程,能充分利用系统CPU和内存性能,发挥多核CPU的优势,提升整个区块处理的吞吐量,降低处理时延,提高处理效率。In this embodiment, after detecting that there is a block to be processed in the block queue, the server can concurrently start a pre-created standby verification thread according to the number of blocks to be processed in the block queue. The standby verification thread is used to perform signature verification on each block to be processed in the block queue, and the verification result block corresponding to the pending block is obtained. When the standby verification thread is created in advance, there is no need to wait for the creation of verification. The signature thread can directly process the block to be processed to ensure the verification efficiency of signature verification for all blocks to be processed in the block queue and save the processing time of signature verification. Understandably, according to the first-in-first-out order in the block queue, a corresponding standby verification thread can be assigned to each block to be processed in turn, so that the standby verification thread is used to perform signature verification on the block to be processed. The signature verification process that uses multiple standby verification threads to execute concurrently can make full use of the system's CPU and memory performance, give full play to the advantages of multi-core CPUs, increase the throughput of the entire block processing, reduce processing delays, and improve processing efficiency.
验签结果区块是待处理区块经过签名验证之后,获取的包含签名验证结果的区块。该签名验证结果包括签名有效和签名无效两种结果,在待命验签线程对每一待处理区块中的至少一个待处理事务进行签名验证之后,将每一待处理事务的签名验证结果存储在待处理区块的元数据区域(Metadata)上,具体是将签名验证结果填充在元数据区域(Metadata)对应的的待填充区域上,以形成验签结果区块。也即最终形成的验签结果区块不仅包括待处理区块的所有内容,还包括签名验证之后获取的签名验证结果,以便基于该签名验证结果进行后续的验证处理。The signature verification result block is the block containing the signature verification result obtained after the block to be processed is verified by the signature. The signature verification result includes two results: the signature is valid and the signature is invalid. After the standby verification thread performs signature verification on at least one pending transaction in each pending block, the signature verification result of each pending transaction is stored in In the metadata area (Metadata) of the block to be processed, the signature verification result is specifically filled in the area to be filled corresponding to the metadata area (Metadata) to form a signature verification result block. That is, the finally formed signature verification result block not only includes all the contents of the block to be processed, but also includes the signature verification result obtained after the signature verification, so as to perform subsequent verification processing based on the signature verification result.
缓存是服务器中预先开辟的用于存储签名验证后的验签结果区块的空间,以保证提交到下一处理环节(即多版本并发控制验证环节)的所有验签结果区块之间存在先后的执行顺序,以保证多版本并发控制验证环节可以依据相应的执行顺序进行执行,提高整体处理效率。The cache is a space for storing the verification result blocks after signature verification in the server in advance to ensure that there is a sequence between all verification result blocks submitted to the next processing link (that is, the multi-version concurrency control verification link). The order of execution to ensure that the multi-version concurrency control verification link can be executed according to the corresponding execution order, and the overall processing efficiency is improved.
本实施例中,服务器并发启动待命验签线程,对区块队列中的每一待处理区块分别进行签名验证,以获取相应的验签结果区块,并将该验签结果区块存储到缓存中,也即可同时采用多个待命验签线程对多个待处理区块分别进行签名验证,无论哪个待命验签线程先完成签名验证过程,均可以将其对应的验签结果区块存储到缓存中,无需等待执行顺序在先的待处理区块签名验证完毕再对执行顺序在后的待处理区块进行签名验证,使得签名验证过程不受待处理区块之间执行顺序的影响,有助于提高区块队列中所有待处理区块的签名验证效率,提高所有待处理区块的整体处理效率,充分利用服务器的系统计算资源,避免资源浪费。由于待命验签线程是预先创建时,启动待命验签线程对待处理区块进行签名验证过程无需等待线程创建,可进一步节省签名验证过程的时间,提高签名验证效率。In this embodiment, the server concurrently starts the standby verification thread to perform signature verification on each block to be processed in the block queue to obtain the corresponding verification result block, and store the verification result block in In the cache, multiple standby verification threads can be simultaneously used to perform signature verification on multiple blocks to be processed. No matter which standby verification thread completes the signature verification process first, the corresponding verification result block can be stored In the cache, there is no need to wait for the signature verification of the block to be processed in the first execution order to complete the signature verification of the block to be processed in the subsequent execution order, so that the signature verification process is not affected by the execution order between the blocks to be processed. It is helpful to improve the signature verification efficiency of all pending blocks in the block queue, improve the overall processing efficiency of all pending blocks, make full use of the server's system computing resources, and avoid resource waste. Since the standby verification thread is created in advance, starting the standby verification thread to perform the signature verification process of the block to be processed does not need to wait for the thread to be created, which can further save the time of the signature verification process and improve the efficiency of signature verification.
S203:实时检测缓存中是否包含当前期望区块,若缓存中包含当前期望区块,则将以当前期望区块为起始块的连续的至少一个验签结果区块确定为目标区块。S203: Detect in real time whether the current desired block is included in the cache, and if the current desired block is included in the cache, at least one consecutive signature verification result block with the current desired block as the starting block is determined as the target block.
其中,当前期望区块是指依据区块链中不同待处理区块之间的执行顺序确定的可提交到下一处理环节(即多版本并发控制验证环节)的区块。目标区块是指依据区块链中不同待处理区块之间的处理顺序,将以当前期望区块为起始块的连续的至少一个验签结果区块所形成的连续区块。即该目标区块可以只包括一个验签结果区块,此时,该验签结果区块为当前期望区块;也可以包括至少两个验签结果区块,且至少两个验签结果区块是以当前期望区块为起始块的连续的验签结果区块,以将签名验证完成后的包含当前期望区块的连续的至少一个验签结果区块确定为目标区块,从而将该目标区块提交到下一处理环节(即多版本并发控制验证环节),以使下一处理环节(即多版本并发控制验证环节)所接收到的所有目标区块中包含的验签结果区块依据其执行顺序排序,从而依序执行,提高下一处理环节(即多版本并发控制验证环节)的处理效率。Among them, the current desired block refers to a block that can be submitted to the next processing link (that is, the multi-version concurrency control verification link) determined according to the execution sequence of different to-be-processed blocks in the blockchain. The target block refers to a continuous block formed by at least one continuous verification result block with the current expected block as the starting block according to the processing sequence between different blocks to be processed in the blockchain. That is, the target block may include only one verification result block, at this time, the verification result block is the current desired block; it may also include at least two verification result blocks, and at least two verification result areas A block is a continuous verification result block with the current desired block as the starting block, and at least one continuous verification result block containing the current desired block after the signature verification is completed is determined as the target block. The target block is submitted to the next processing link (i.e. multi-version concurrency control verification link), so that the next processing link (i.e. multi-version concurrency control verification link) contains the verification result area contained in all target blocks received The blocks are sorted according to their execution order, so that they are executed in order, which improves the processing efficiency of the next processing link (that is, the multi-version concurrency control verification link).
本实施例中,每一验签结果区块的区块头区域(即Block Header)上记录用于唯一识别该验签结果区块的区块序号(即Number)、上一区块哈希值(即PreviousHash)和当前区块哈希值(即DataHash)。由于向下一处理环节(即多版本并发控制验证环节),需保证所提交的所有验签结果区块的顺序性,而所有验签结果区块之间的顺序可以通过区块序号确定,也可以依据不同指针之间的哈希指针确定,具体根据上一区块哈希值与当前区块哈希值的先后顺序确定。因此,可通过实时检测新存储到缓存中的验签结果区块是否为当前期望区块,若最新存储的验签结果区块为当前期望区块,则可依据缓存中存储的所有验签结果区块的区块序号或者哈希指针值(包括上一区块哈希值和当前区块哈希值),将与当前期望区块为起始块的连续的至少一个验签结果区块确定为可提交到下一处理环节的目 标区块。本实施例中,可采用滑动窗口技术将当前期望区块和所有连续的验签结果区块确定为目标区块,即采用滑动窗口将以当前期望区块为起始块的连续的至少一个验签结果区块选中,以确定目标区块。In this embodiment, the block header area (i.e. Block Header) of each verification result block is recorded with the block serial number (i.e. Number) and the previous block hash value ( That is, PreviousHash) and the current block hash value (ie, DataHash). Since the next processing link (i.e., multi-version concurrency control verification link), the sequence of all submitted verification result blocks must be guaranteed, and the order of all verification result blocks can be determined by the block sequence number. It can be determined based on the hash pointers between different pointers, specifically based on the sequence of the previous block's hash value and the current block's hash value. Therefore, it is possible to detect whether the newly stored signature verification result block in the cache is the current expected block in real time. If the latest signature verification result block is the current expected block, it can be based on all the signature verification results stored in the cache The block number or hash pointer value of the block (including the hash value of the previous block and the hash value of the current block) will be determined by at least one verification result block that is continuous with the current expected block as the starting block It is a target block that can be submitted to the next processing link. In this embodiment, the sliding window technology can be used to determine the current desired block and all consecutive verification result blocks as the target block, that is, the sliding window is used to determine at least one continuous verification with the current desired block as the starting block. Check the result block to determine the target block.
本实施例中,实时检测缓存中是否包含当前期望区块,若缓存中包含当前期望区块,则将以当前期望区块为起始块的连续的至少一个验签结果区块确定为目标区块,以便后续将该目标区块整体提交到下一处理环节,以使下一处理环节依序对所有验签结果区块进行处理。相应地,若缓存中不包含当前期望区块,则依据缓存中所有验签结果区块的当前区块哈希值或者区块序号,对所有验签结果区块进行排序,以使所有验签结果区块依据当前区块哈希值或者区块序号的顺序存储在缓存中,以便保障后续确定目标区块的效率。In this embodiment, it is detected in real time whether the current desired block is contained in the cache, and if the current desired block is contained in the cache, at least one continuous verification result block with the current desired block as the starting block is determined as the target area Block in order to subsequently submit the target block as a whole to the next processing link, so that the next processing link processes all the verification result blocks in sequence. Correspondingly, if the current expected block is not contained in the cache, all verification result blocks are sorted according to the current block hash value or block serial number of all verification result blocks in the cache, so that all verification result blocks are sorted. The result block is stored in the cache according to the current block hash value or the sequence of the block serial number, so as to ensure the efficiency of subsequent determination of the target block.
S204:提交目标区块,并基于目标区块中最后一个验签结果区块对应的区块标签更新当前期望区块。S204: Submit the target block, and update the current desired block based on the block label corresponding to the last verification result block in the target block.
具体地,服务器将以当前期望区块为起始块的连续的至少一个验签结果区块确定为目标区块,并将目标区块提交到下一处理环节,提交成功之后,目标区块不存储在缓存中,与目标区块不连续的其他验签结果区块仍然存储在缓存中。可以理解地,在将目标区块提交到下一处理环节时,需实时更新缓存中的当前期望区块,以便在缓存接收到新的验签结果区块时,可顺利执行步骤S203及S204的步骤。Specifically, the server determines at least one consecutive signature verification result block with the current desired block as the starting block as the target block, and submits the target block to the next processing link. After the submission is successful, the target block is not Stored in the cache, other verification result blocks that are not continuous with the target block are still stored in the cache. Understandably, when the target block is submitted to the next processing link, the current desired block in the cache needs to be updated in real time, so that when the cache receives a new verification result block, the steps S203 and S204 can be executed smoothly. step.
本实施例中,在将目标区块提交到下一处理环节时,需基于目标区块中最后一个验签结果区块对应的区块标签更新当前期望区块。由于目标区块是由连续的至少一个验签结果区块形成的连续区块,而目标区块中最后一个验签结果区块为结束区块,该结束区块之后的下一个区块为更新的当前期望区块,以便基于更新后的当前期望区块重复执行步骤S203及步骤S204。In this embodiment, when the target block is submitted to the next processing link, the current desired block needs to be updated based on the block label corresponding to the last verification result block in the target block. Since the target block is a continuous block formed by at least one continuous verification result block, and the last verification result block in the target block is the end block, the next block after the end block is the update The current desired block of, so as to repeat step S203 and step S204 based on the updated current desired block.
本实施例所提供的区块链事务处理方法中,并发启动预先创建的待命验签线程对区块队列中的待处理区块进行签名验证,获取对应的验签结果区块,以保证区块队列中所有待处理区块进行签名验证的验证效率,节省签名验证的处理时间,而且待命验签线程无需进行线程的创建和销毁,有助于节省系统损耗。将所有验签结果区块存储到缓存中,实时检测缓存中包含当前期望区块时,将以当前期望区块为起始块的连续的至少一个验签结果区块确定为目标区块并提交该目标区块,以保证提交的目标区块中包含连续的至少一个验签结果区块,确保区块之间的执行顺序。In the blockchain transaction processing method provided in this embodiment, the pre-created standby verification thread is concurrently started to perform signature verification on the block to be processed in the block queue, and the corresponding verification result block is obtained to ensure the block The verification efficiency of signature verification for all pending blocks in the queue saves the processing time of signature verification, and the standby verification thread does not need to create and destroy threads, which helps to save system loss. Store all verification result blocks in the cache. When the real-time detection cache contains the current desired block, at least one continuous verification result block with the current desired block as the starting block is determined as the target block and submitted The target block is to ensure that the submitted target block contains at least one consecutive signature verification result block to ensure the execution sequence between the blocks.
在一实施例中,如图3所示,步骤S203中的实时检测缓存中是否包含当前期望区块,具体包括如下步骤:In one embodiment, as shown in FIG. 3, the real-time detection of whether the current desired block is contained in the cache in step S203 specifically includes the following steps:
S301:实时检测缓存中验签结果区块对应的区块标签,判断区块标签是否与缓存中实时记录的区块指引信息相匹配。S301: Detect the block label corresponding to the verification result block in the cache in real time, and determine whether the block label matches the block guide information recorded in the cache in real time.
具体地,服务器可以采用缓存监控程序监听缓存中是否存在数据增量变化,以实时检测是否缓存是否接收到新的验签结果区块。即若缓存监控程序监控到缓存中存在数据增量变化,说明缓存接收到新存储的验签结果区块,需实时检测该新存储的验签结果结构是否为当前期望区块。Specifically, the server may use a cache monitoring program to monitor whether there is incremental data change in the cache, so as to detect in real time whether the cache receives a new verification result block. That is, if the cache monitoring program monitors that there is an incremental change in the data in the cache, it means that the cache has received the newly stored signature verification result block, and it needs to detect in real time whether the newly stored signature verification result structure is the current desired block.
本实施例中,服务器在检测到缓存接收到新存储的验签结果区块时,对验签结果区块进行解析,以从验签结果区块的区块头区域,获取验签结果区块对应的区块标签,区块标签可以包括区块序号,也可以包括当前区块哈希值和上一区块哈希值。In this embodiment, when the server detects that the cache receives the newly stored signature verification result block, it parses the signature verification result block to obtain the signature verification result block corresponding to the signature verification result block from the block header area of the signature verification result block. The block label of the block label can include the block serial number, and can also include the current block hash value and the previous block hash value.
S302:若区块标签与区块指引信息相匹配,则区块标签对应的验签结果区块为当前期望区块。S302: If the block label matches the block guide information, the signature verification result block corresponding to the block label is the current expected block.
其中,区块指引信息是用于指引确定缓存对应的当前期望区块的信息。该区块指引信息可以采用滑动窗口、数组或者其他形式存储,以便在检测到有新的验签结果区块加入缓存时,利用新的验签结果区块的区块标签与该区块指引信息进行匹配,以确定该新的验签结果区块是否为当前期望区块。Among them, the block guide information is information used to guide the determination of the current desired block corresponding to the cache. The block guide information can be stored in a sliding window, an array or other forms, so that when a new verification result block is detected to be added to the cache, the block label of the new verification result block and the block guide information are used Matching is performed to determine whether the new verification result block is the current expected block.
该区块指引信息可以是期望区块序号,该期望区块序号是当前期望区块对应的区块序号,该期望区块序号可以最新提交的目标区块中最后一个验签结果区块对应的结束区块序号,采用区块序号命名规则对结束区块序号进行处理所确定的下一区块序号。其中,最新提交的目标区块中最后一个验签结果区块可以理解为该目标区块中的结束区块,结束区块序号为结束区块中的区块序号。区块序号命名规则是用于给某一事件中不同区块分配唯一的区块序号的命名规则,依据区块序号命名规则进行命名所确定的区块序号之间具有顺序性,以便根据区块命名确定至少两个验签结果区块是否为连续区块。相应地,可通过检测缓存中新存储的验签结果区块的区块序号是否为期望区块序号,以实时检测缓存中是否包含当前期望区块。即若新存储的验签结果区块的区块序号与期望区块序号相同,则该验签结果区块为当前期望区块;若新存储的验签结果区块的区块序号与期望区块序号不相同,则该验签结果区块不为当前期望区块。The block guide information can be the desired block serial number, which is the block serial number corresponding to the current desired block, and the desired block serial number can correspond to the last verification result block in the newly submitted target block The ending block sequence number is the next block sequence number determined by processing the ending block sequence number using the block sequence number naming rule. Among them, the last verification result block in the newly submitted target block can be understood as the end block in the target block, and the end block sequence number is the block sequence number in the end block. The block sequence number naming rule is a naming rule used to assign unique block sequence numbers to different blocks in a certain event. The block sequence numbers determined by naming according to the block sequence number naming rule are sequential, so that according to the block The naming determines whether at least two verification result blocks are consecutive blocks. Correspondingly, by detecting whether the block sequence number of the newly stored signature verification result block in the cache is the expected block sequence number, it can be detected in real time whether the current expected block is contained in the cache. That is, if the block sequence number of the newly stored verification result block is the same as the expected block sequence number, the verification result block is the current expected block; if the block sequence number of the newly stored verification result block is the same as the expected area If the sequence numbers of the blocks are not the same, the verification result block is not the current expected block.
该区块指引信息也可以是期望区块指针值,该期望区块指针值可以最新提交的目标区块中最后一个验签结果区块对应的当前区块哈希值,也即期望区块指针值是结束区块的当前区块哈希值。相应地,可通过检测缓存中新存储的验签结果区块的上一区块哈希值是否与期望区块指针值相同;若相同,则验签结果区块为当前期望区块;若不相同,则验签结果区块不为当前期望区块。The block guide information can also be the expected block pointer value, and the expected block pointer value can be the current block hash value corresponding to the last verification result block in the newly submitted target block, that is, the expected block pointer The value is the current block hash value of the ending block. Correspondingly, it is possible to check whether the previous block hash value of the newly stored verification result block in the cache is the same as the expected block pointer value; if the same, the verification result block is the current expected block; if not If it is the same, the verification result block is not the current expected block.
例如,在验签结果区块的区块标签为上一区块哈希值,而区块指引信息为期望区块指针值时,该期望区块指针值具体为最近一次提交的目标区块中最后一个验签结果区块的当前区块哈希值。其实时检测缓存中是否包含当前期望区块的具体过程包括如下步骤:(1)先判断上一区块哈希值所指向的验签结果区块是否为系统配置区块,该系统配置区块是指系统管理员预先配置的用于记录某一事件的事件信息和交易双方信息等信息的区块,一般而言,系统配置区块为某一事件对应的第一个当前期望区块,可直接作为目标区块提交到下一处理环节。(2)若上一区块哈希值所指向的验签结果区块为系统配置区块,则该验签结果区块为当前期望区块,以便基于当前期望区块确定可提交到下一处理环节的目标区块。(3)若上一区块哈希值所指向的验签结果区块不为系统配置区块,则判断上一区块哈希值是否与期望区块指针值相匹配;若相匹配,则验签结果区块为当前期望区块;若不相匹配,验签结果区块不为当前期望区块。由于每次提交的目标区块包含以缓存中本次当前期望区块为起始块的连续的至少一个验签结果区块,则该目标区块中的最后一个验签结果区块的当前区块哈希值可以指示本次提交的目标区块之后的下一个当前期望区块。For example, when the block label of the verification result block is the hash value of the previous block, and the block guide information is the expected block pointer value, the expected block pointer value is specifically the last submitted target block The current block hash value of the last verification result block. The specific process of real-time detection of whether the current desired block is contained in the cache includes the following steps: (1) First determine whether the verification result block pointed to by the hash value of the previous block is a system configuration block, and the system configuration block Refers to the block pre-configured by the system administrator to record information such as event information of an event and information of both parties to the transaction. Generally speaking, the system configuration block is the first current desired block corresponding to an event. Directly submitted as the target block to the next processing link. (2) If the signature verification result block pointed to by the hash value of the previous block is a system configuration block, then the signature verification result block is the current desired block, so that it can be submitted to the next block based on the current desired block. The target block of the processing link. (3) If the verification result block pointed to by the hash value of the previous block is not a system configuration block, it is determined whether the hash value of the previous block matches the expected block pointer value; if it matches, then The verification result block is the current expected block; if it does not match, the verification result block is not the current expected block. Since the target block submitted each time contains at least one continuous verification result block with the current expected block in the cache as the starting block, the current area of the last verification result block in the target block The block hash value can indicate the next current expected block after the target block submitted this time.
例如,若区块队列中存储有10个需要进行处理的待处理区块,其区块序号分别为1-10,可并发启动10个待命验签线程对10分待处理区块分别进行处理,以分别获取其对应的验签结果区块,并将验签结果区块存储到缓存中,设这10个待处理区块处理完毕的顺序为6,8,2,3,4,5,1,7,9,10,而系统在开始处理这10个待处理区块之前,缓存中的区块指引信息可采用期望区块序号进行确定,该期望区块序号设为1。具体地,缓存在接收到第一个验签结果区块,其区块序号为6,由于其区块序号不为期望区块序号(即1),则区块序号为6的验签结果区块不为当前期望区块,将其保存在缓存中。缓存在接收到第二个验签结果区块,其区块序号为8,由于其区块序号不为期望区块序号(即1),则区块序号为6的验签结果区块不为当前期望区块,则依据缓存中所有验签结果区块对应的区块序号进行排序,以将6号验签结果区块存储在8号验签结果区块前面……依次类推,缓存在接收到第七个验签结果区块,其区块序号为1时,由于其区块序号为当前期望序号(即1),则区块序号为1的验签结果区块为当前期望序号,则将以1号验签结果区块为起始块的所有连续的验签结果区块作为一目标区块,即依序将1号、2号、3号、4号、5号和6号验签结果区块确定为一目标区块,由于缓存中8号验签结果区块与6号验签结果区块不连续,因此,不将8号验签结果区块确定目标区块中的一个验签结果区块。此时,6号验签结果区块为该目标区块中的结束区块。在将1至6号验签结果区块所形成的目标区块提交到下 一处理环节后,需基于该目标区块中最后一个验签结果区块对应的区块标签更新当前期望区块,即基于6号验签结果区块对应的区块标签(如区块序号或者当前区块哈希值)更新缓存中新的当前期望区块对应的区块指引信息,即更新缓存中新的当前期望区块对应的期望区块序号,该期望区块序号具体为结束区块序号之后的下一个区块序号,即7号序号。可以理解地,在提交1-6号验签结果区块形成的目标区块之后,新确定的期望区块序号为7;在缓存接收到第八个验签结果区块时,由于其区块序号为7,与期望区块序号相同,则7号验签结果区块为当前期望区块,基于缓存中7号验签结果区块及其连续的验签结果区块(即8号验签结果区块)形成新的目标区块,并提交到下一处理环节…依此类推,以将所有验签结果区块提交到下一处理环节。For example, if there are 10 pending blocks that need to be processed in the block queue, and their block numbers are 1-10, 10 standby verification threads can be started concurrently to process the 10 pending blocks separately. To obtain the corresponding verification result blocks respectively, and store the verification result blocks in the cache, suppose the order of the completion of the processing of the 10 blocks to be processed is 6, 8, 2, 3, 4, 5, 1 ,7,9,10, and before the system starts to process the 10 blocks to be processed, the block guide information in the cache can be determined using the expected block number, which is set to 1. Specifically, when the cache receives the first verification result block, its block sequence number is 6. Since its block sequence number is not the expected block sequence number (ie 1), the block sequence number is 6 in the verification result area The block is not the current expected block, save it in the cache. When the cache receives the second verification result block, its block sequence number is 8. Since its block sequence number is not the expected block sequence number (ie 1), the verification result block with the block sequence number 6 is not The current expected block is sorted according to the block sequence numbers corresponding to all the verification result blocks in the cache, so that the verification result block No. 6 is stored in front of the verification result block No. 8... and so on, the cache is cached in the receiving To the seventh verification result block, when the block sequence number is 1, since its block sequence number is the current expected sequence number (ie 1), the verification result block with the block sequence number 1 is the current expected sequence number, then All consecutive verification result blocks starting with the first verification result block are regarded as a target block, that is, the first, second, third, fourth, fifth and sixth verification result blocks will be checked in sequence. The signature result block is determined to be a target block. Since the signature verification result block No. 8 and the signature verification result block No. 6 in the cache are not continuous, the signature verification result block No. 8 is not determined as one of the target blocks. Check result block. At this time, the signature verification result block No. 6 is the end block in the target block. After submitting the target block formed by the verification result blocks 1 to 6 to the next processing link, the current desired block needs to be updated based on the block label corresponding to the last verification result block in the target block. That is, based on the block label corresponding to the block No. 6 verification result (such as the block number or the current block hash value), the block guide information corresponding to the new current desired block in the cache is updated, that is, the new current block in the cache is updated. The desired block serial number corresponding to the desired block, and the desired block serial number is specifically the next block serial number after the end block serial number, that is, the 7th serial number. Understandably, after submitting the target block formed by the signature verification result block No. 1-6, the newly determined expected block sequence number is 7; when the cache receives the eighth verification result block, because of its block The serial number is 7, which is the same as the expected block serial number, so the 7th verification result block is the current desired block, based on the 7th verification result block in the cache and its consecutive verification result blocks (that is, the 8th verification result block) Result block) form a new target block and submit it to the next processing link...and so on to submit all verification result blocks to the next processing link.
本实施例中所提供的区块链事务处理方法中,实时检测缓存中验签结果区块的区块标签,根据区块标签和区块指引信息是否匹配,可快速确定某一验签结果区块是否为当前期望区块,以提高当前期望区块的确定效率,进而有助于提高事件整体处理效率。In the blockchain transaction processing method provided in this embodiment, the block label of the verification result block in the cache is detected in real time, and a certain verification result area can be quickly determined according to whether the block label and the block guidance information match. Whether the block is the current desired block, in order to improve the efficiency of determining the current desired block, thereby helping to improve the overall processing efficiency of the event.
在一实施例中,若系统预先创建的待命验签线程的数量过少,可能无法保障最大程度提高签名验证处理的效率,也可能存储系统资源的浪费;若待命验签线程的数量过多,可能影响系统处理除签名验证之外的其他工作的效率,因此,需均衡预先创建的待命验签线程。如图4所示,在步骤S201之前,即在接收待处理区块,将待处理区块存储在区块队列中之前,区块链事务处理方法还包括如下步骤:In an embodiment, if the number of standby verification threads created by the system in advance is too small, it may not be able to ensure that the efficiency of the signature verification processing is maximized, and system resources may be wasted; if the number of standby verification threads is too large, It may affect the efficiency of the system in processing other tasks besides signature verification. Therefore, it is necessary to balance the pre-created standby verification threads. As shown in FIG. 4, before step S201, that is, before receiving the block to be processed and storing the block to be processed in the block queue, the blockchain transaction processing method further includes the following steps:
S401:获取区块链系统的内核数量。S401: Obtain the number of cores of the blockchain system.
其中,区块链系统的内核数量具体为服务器中CPU(Central Processing Unit,中央处理器)的内核数量,即处理器的数量。本实施例中,获取区块链系统的内核数量的过程为现有技术,例如,用户可在任务管理器中查看处理器对应的数量即为区块链系统的内核数量,也可以依次执行“开始菜单”->“运行”->“输入cmd”->“输入wmic”->“输入cpu get”这些操作获取区块链系统中每个服务器的内核数量。Among them, the number of cores of the blockchain system is specifically the number of cores of the CPU (Central Processing Unit, central processing unit) in the server, that is, the number of processors. In this embodiment, the process of obtaining the number of cores of the blockchain system is based on the prior art. For example, the user can view the number of processors corresponding to the number of cores of the blockchain system in the task manager, or it can be executed in sequence. Start menu" -> "Run" -> "Enter cmd" -> "Enter wmic" -> "Enter cpu get" These operations get the number of cores of each server in the blockchain system.
S402:基于内核数量和目标比例范围,确定目标数量,创建验签线程池,验签线程池包括与目标数量相对应的待命验签线程。S402: Determine the target number based on the number of cores and the target ratio range, and create a signature verification thread pool. The signature verification thread pool includes standby verification threads corresponding to the target number.
该目标比例范围是预先设置的比例范围,可以是1.5-3倍。目标数量具体为内核数量与目标比例范围的乘积。一般来说,当目标数量为内核数量的2倍时,即目标比例范围为2时,区块链系统的CPU中线程切换的代价较少,更有利于降低签名验证的系统损耗。The target ratio range is a preset ratio range, which can be 1.5-3 times. The target number is specifically the product of the number of cores and the target ratio range. Generally speaking, when the target number is twice the number of cores, that is, when the target ratio range is 2, the cost of thread switching in the CPU of the blockchain system is less, which is more conducive to reducing the loss of the signature verification system.
本实施例所提供的区块链事务处理方法中,在基于内核数量和目标比例范围确定目标数量之后,在区块链系统的服务器上创建验签线程池,该验签线程池包括与目标数量相对应的待命验签线程,以便后续利用与目标数量相对应的待命验签线程对区块队列中需要进行处理的待处理区块进行签名验证。该待命验签线程在工作时进行签名验证,不工作时进入休眠状态,无需进行线程的创建和销毁,减少对CPU的占用,有助于降低系统损耗。验签线程池中的待命验签线程的数量与目标数量相匹配,既可最大程度提高签名验证的处理效率,避免系统资源的浪费,也可避免数量过多影响除签名验证以外的其他工作的处理效率。In the blockchain transaction processing method provided in this embodiment, after the target number is determined based on the number of cores and the target ratio range, a signature verification thread pool is created on the server of the blockchain system, and the signature verification thread pool includes the target number The corresponding standby verification thread is used to subsequently use the standby verification thread corresponding to the target number to perform signature verification on the pending block in the block queue that needs to be processed. The standby verification thread performs signature verification when it is working, and enters a dormant state when it is not working, without thread creation and destruction, which reduces CPU usage and helps reduce system loss. The number of standby verification threads in the verification thread pool matches the target number, which can maximize the processing efficiency of signature verification, avoid waste of system resources, and avoid excessive numbers that affect other tasks except signature verification. Processing efficiency.
在一实施例中,如图5所示,步骤S202中,并发启动预先创建的待命验签线程,包括如下步骤:In one embodiment, as shown in FIG. 5, in step S202, concurrently starting the pre-created standby verification thread includes the following steps:
S501:实时监控区块队列中的待处理区块对应的区块数量。S501: Monitor the number of blocks corresponding to the blocks to be processed in the block queue in real time.
具体地,服务器上设有计数器,采用计数器实时监控区块队列中的待处理区块对应的区块数量,例如,若区块队列中有一个新增的待处理区块加入,则计数器加1;若区块队列中有一个待处理区块被分配到待命验签线程进行签名验证处理,则计数器减1,以实现通过计数器实时监控区块队列中的待处理区块的区块数量。Specifically, a counter is provided on the server, and the counter is used to monitor the number of blocks corresponding to the blocks to be processed in the block queue in real time. For example, if a newly added block to be processed is added to the block queue, the counter is increased by 1. ; If a block to be processed in the block queue is allocated to the standby verification thread for signature verification processing, the counter is reduced by 1, so as to realize the real-time monitoring of the number of blocks to be processed in the block queue through the counter.
S502:若区块数量大于零,则触发唤醒指令,基于唤醒指令,并发唤醒验签线程池中处于休眠状态的待命验签线程,将区块队列中的待处理区块分配给对应的待命验签线程。S502: If the number of blocks is greater than zero, a wake-up instruction is triggered, and based on the wake-up instruction, the standby verification thread in the dormant state in the verification thread pool is concurrently awakened, and the pending block in the block queue is allocated to the corresponding standby verification Sign thread.
其中,唤醒指令是用于唤醒处于休眠状态的待命验签线程的指令。具体地,若区块数量大于零,则说明区块队列中存在需要进行处理的待处理区块,此时,服务器触发验签线程池中处于休眠状态的与区块数量相匹配的待命验签统线程,以将区块队列中的待处理区块分配给对应的符合验签线程进行签名验证处理。Among them, the wake-up instruction is an instruction used to wake up the standby verification thread in the dormant state. Specifically, if the number of blocks is greater than zero, it means that there are pending blocks that need to be processed in the block queue. At this time, the server triggers a standby verification thread that matches the number of blocks in the verification thread pool. The system thread is used to allocate the to-be-processed block in the block queue to the corresponding signature verification thread for signature verification processing.
例如,若区块数量大于零,所触发的唤醒指令,可以全部唤醒验签线程池中所有处于休眠状态的待命验签线程,依据CPU调度情况确定对应的待命验签线程,在将区块队列的待处理区块分配给对应的待命验签线程,其他待命验签线程重新进入休眠状态。又例如,若区块数量大于零,所触发的唤醒指令,可以随机唤醒处于休眠状态的待命验签线程,在将区块队列的待处理区块分配给对应的待命验签线程。For example, if the number of blocks is greater than zero, the triggered wake-up instruction can wake up all the standby verification threads in the dormant state in the verification thread pool, and determine the corresponding standby verification threads according to the CPU scheduling situation. The block to be processed is allocated to the corresponding standby verification thread, and the other standby verification threads enter the dormant state again. For another example, if the number of blocks is greater than zero, the triggered wake-up instruction can randomly wake up the standby signature verification thread in the dormant state, and allocate the pending block in the block queue to the corresponding standby signature verification thread.
本实施例中,基于唤醒指令,并发唤醒验签线程池中处于休眠状态的待命验签线程,具体是指:比较区块数量与验签线程池中处于休眠状态的待命验签线程的线程数量;若区块数量小于或者等于线程数量,则基于唤醒指令,唤醒与区块数量相匹配的待命验签线程;若区块数量大于线程数量,则基于唤醒指令,唤醒与线程数量相匹配的待命验签线程,即唤醒所有处于休眠状态的待命验签线程。可以理解地,通过区块数量和线程数量的比较结果,确定所需唤醒的待命验签线程的数量,以便实现对待命验签线程统一管理。In this embodiment, based on the wake-up instruction, concurrently waking the standby verification threads in the dormant state in the signature verification thread pool, specifically refers to: comparing the number of blocks with the number of threads in the dormant state in the verification thread pool. ; If the number of blocks is less than or equal to the number of threads, based on the wake-up instruction, wake up the standby verification thread that matches the number of blocks; if the number of blocks is greater than the number of threads, wake up the standby that matches the number of threads based on the wake-up instruction The signature verification thread wakes up all the standby verification threads that are in the dormant state. Understandably, based on the comparison result of the number of blocks and the number of threads, the number of standby verification threads that need to be awakened is determined, so as to realize the unified management of the standby verification threads.
进一步地,若区块数量大于零,且验签线程池中不存在处于休眠状态的待命验签线程,则实时监控每一待命验签线程的工作状态,在任一待命验签线程对待处理区块进行签名验证,获取验签结果区块,并将验签结果区块存储到缓存后,将该待命验签线程确定为空闲唤醒线程,以将区块队列中的待处理区块发送给对应的空闲唤醒线程。其中,空闲唤醒线程是指是指处于工作状态结束之后预设时间内等待接收新的待处理区块进行处理的待命验签线程;若在该预设时间内接收到新的待处理区块,则空闲唤醒线程重新进入工作状态;若在该预设时间内未接收到新的待处理区块,则空闲唤醒线程进入休眠状态。可以理解地,将待命验签线程确定为空闲唤醒线程,可在预设时间内使其处于等待接收新的待处理区块,避免直接进入休眠状态需另外进行唤醒操作,有助于减少系统开销。Further, if the number of blocks is greater than zero, and there is no standby verification thread in the dormant state in the verification thread pool, the working status of each standby verification thread is monitored in real time, and the block is processed in any standby verification thread Perform signature verification, obtain the verification result block, and store the verification result block in the cache, then determine the standby verification thread as an idle wake-up thread to send the pending block in the block queue to the corresponding Idle wake up thread. Among them, the idle wake-up thread refers to the standby verification thread waiting to receive a new block to be processed for processing within a preset time after the end of the working state; if a new block to be processed is received within the preset time, Then the idle wake-up thread enters the working state again; if no new block to be processed is received within the preset time, the idle wake-up thread enters the sleep state. Understandably, the standby verification thread is determined to be an idle wake-up thread, which can be placed in waiting to receive a new block to be processed within a preset time, avoiding directly entering the sleep state and requiring additional wake-up operations, which helps to reduce system overhead .
本实施例所提供的区块链事务处理方法中,基于区块队列中待处理区块对应的区块数量触发唤醒指令,以唤醒验签线程池中处于休眠状态的待命验签线程,并将待处理区块分配给对应的待命验签线程,可以使处于休眠状态的待命验签线程进入工作状态,对待处理区块进行处理,只需进行线程唤醒操作,无需进行线程创建和销毁,有助于减少对CPU的占用,降低系统损耗。In the blockchain transaction processing method provided in this embodiment, a wake-up instruction is triggered based on the number of blocks corresponding to the blocks to be processed in the block queue to wake up the standby verification threads in the dormant state in the verification thread pool, and The block to be processed is allocated to the corresponding standby verification thread, which can make the standby verification thread in the dormant state enter the working state. To process the processing block, only the thread wake-up operation is required, and the thread creation and destruction are not required. To reduce the CPU usage and reduce system consumption.
在一实施例中,如图6所示,步骤S201,即接收待处理区块,将待处理区块存储在区块队列中,包括:In one embodiment, as shown in FIG. 6, step S201, which is to receive a block to be processed, and store the block to be processed in a block queue, includes:
S601:接收待处理区块,对待处理区块进行合法性校验,获取合法性校验结果。S601: Receive a block to be processed, perform a legality check on the block to be processed, and obtain a legality check result.
其中,合法性校验是指检验接收到的待处理区块是否为合法的区块链节点发送的区块的过程。具体地,服务器在接收到待处理区块之后,对待处理区块的元数据区域中记载的区块签名进行合法性验证,若签名验证通过,则获取校验通过的合法性校验结果;若签名验证不通过,则获取校验不通过的合法性校验结果。可以理解地,区块链系统中每个合法的区块链节点会在其所打包的每个待处理区块的元数据区域记载该区块链节点自身的数字签名,这个数字签名即为该待处理区块的区块签名。服务器在接收到每一待处理区块后,从元数据区域获取到区块签名之后,采用与数字签名对应的签名加密算法对应的签名验证方法进行合法性校验,获取合法性校验结果。Among them, the legality check refers to the process of checking whether the received block to be processed is a block sent by a legal blockchain node. Specifically, after receiving the block to be processed, the server performs legality verification on the block signature recorded in the metadata area of the block to be processed, and if the signature verification is passed, the legality verification result that has passed the verification is obtained; if If the signature verification fails, the legality verification result that the verification fails is obtained. Understandably, each legal blockchain node in the blockchain system will record its own digital signature in the metadata area of each block to be processed, and this digital signature is the The block signature of the block to be processed. After receiving each block to be processed, the server obtains the block signature from the metadata area, and then uses the signature verification method corresponding to the signature encryption algorithm corresponding to the digital signature to perform legality verification, and obtain the legality verification result.
S602:若合法性校验结果为校验通过,则将待处理区块存储在区块队列中。S602: If the result of the validity check is that the check is passed, store the block to be processed in the block queue.
具体地,若所接收到的待处理区块的合法性校验结果为校验通过,则将待处理区块存储在区块队列中,以便后续采用待命验签线程对区块队列中的待处理区块进行签名验证;若所接收到的待处理区块的合法性校验结果为校验不通过,则直接丢弃该待处理区块,以避免后续对合法性校验不通过的待处理区块进行处理,从而避免系统资源的浪费,以达到 降低系统损耗的目的。Specifically, if the received legality check result of the block to be processed is that the check is passed, the block to be processed is stored in the block queue, so that the standby verification thread is used to subsequently check the pending block in the block queue. Process the block for signature verification; if the received legality check result of the block to be processed is that the check fails, then the block to be processed is directly discarded to avoid subsequent pending processing that fails the legality check Block processing, so as to avoid the waste of system resources, in order to achieve the purpose of reducing system loss.
本实施例所提供的区块链事务处理方法中,通过对所接收到的每一待处理区块进行合法性校验,只将合法性校验结果为校验通过的待处理区块存储在区块队列中,以避免将合法性校验结果为校验不通过的待处理区块加入区块队列进行后续处理,从而避免系统资源的浪费,以达到降低系统损耗的目的。In the blockchain transaction processing method provided in this embodiment, by performing a legality check on each received block to be processed, only the block to be processed whose legality check result is verified is stored in In the block queue, to avoid adding the to-be-processed block whose legality check result is not passed into the block queue for subsequent processing, so as to avoid the waste of system resources and achieve the purpose of reducing system loss.
在一实施例中,由于不同待处理区块之间存在特定的执行顺序,使得区块链事务处理过程中,需依据执行顺序进行事务处理;而每一待处理区块均包含至少一个待处理事务,若任一待处理区块中的待处理事务的事务数量较多,使得待命验签线程对该待处理区块进行处理的时间较长,而执行顺序在该待处理区块之后的其他待处理区块需等待较长时间,才可形成目标区块提交到下一处理环节,从而影响整个区块链事件处理过程的处理效率。如图7所示,步骤S202,即对区块队列中的待处理区块进行签名验证,获取验签结果区块,包括如下步骤:In one embodiment, because there is a specific execution sequence between different blocks to be processed, the transaction processing of the blockchain needs to be performed according to the execution sequence; and each block to be processed contains at least one block to be processed Transaction, if there are a large number of pending transactions in any pending block, the waiting time for the signature verification thread to process the pending block is longer, and the execution order is the other after the pending block It takes a long time for the block to be processed to form the target block and submit it to the next processing link, which affects the processing efficiency of the entire blockchain event processing process. As shown in Figure 7, step S202, which is to perform signature verification on the block to be processed in the block queue, to obtain the verification result block, includes the following steps:
S701:检测每一待处理区块中所有待处理事务对应的事务数量。S701: Detect the number of transactions corresponding to all transactions to be processed in each block to be processed.
其中,事务数量是指待处理区块中所有待处理事务的数量,具体是指待处理区块的区块数据区域所记载的所有交易数据对应的数量。可以理解地,区块数据区域所记载的每一笔交易数据对应一个待处理事务。Wherein, the number of transactions refers to the number of all transactions to be processed in the block to be processed, and specifically refers to the number corresponding to all transaction data recorded in the block data area of the block to be processed. Understandably, each transaction data recorded in the block data area corresponds to a pending transaction.
S702:若事务数量大于预设数量阈值,则依据事务数量确定子线程数量,创建与子线程数量相匹配的辅助验签子线程。S702: If the number of transactions is greater than the preset number threshold, the number of sub-threads is determined according to the number of transactions, and an auxiliary signature verification sub-thread matching the number of sub-threads is created.
其中,预设数量阈值是预先设置的用于评估事务数量是否达到认定为较大标准的阈值。具体地,若任一待处理区块中所有待处理事务对应的事务数量大于预设数量阈值,说明该待处理区块中的待处理事务对应的事务数量过多,若只采用待命验签线程进行处理,可能会导致处理时间过长,因此需创建辅助验签子线程对待处理区块中的待处理事务进行处理。其中,辅助验签子线程是系统创建的用于辅助待命验签线程处理事务数量较大的待处理区块的线程,在待处理区块处理完毕之后进行销毁。Among them, the preset number threshold is a preset threshold used to evaluate whether the number of transactions reaches a standard recognized as a larger threshold. Specifically, if the number of transactions corresponding to all pending transactions in any to-be-processed block is greater than the preset number threshold, it means that the number of transactions corresponding to pending transactions in the to-be-processed block is too large. If only the standby verification thread is used Processing may result in too long processing time. Therefore, an auxiliary signature verification sub-thread needs to be created to process the pending transactions in the processing block. Among them, the auxiliary signature verification sub-thread is a thread created by the system to assist the standby signature verification thread to process a block to be processed with a large number of transactions, and is destroyed after the block to be processed is processed.
本实施例中,依据事务数量确定子线程数量,创建与子线程数量相匹配的辅助验签子线程具体包括:对事务数量与预设数量阈值的商进行向下取整,以获取子线程数量,并创建与子线程数量相匹配的辅助验签子线程。即子线程数量可采用如下公式确定:
Figure PCTCN2020085565-appb-000001
其中,N为辅助验签子线程,A为事务数量,B为预设数量阈值。
In this embodiment, the number of sub-threads is determined according to the number of transactions, and creating an auxiliary signature verification sub-thread matching the number of sub-threads specifically includes: rounding down the quotient of the number of transactions and a preset number threshold to obtain the number of sub-threads, And create an auxiliary sign verification sub-thread that matches the number of sub-threads. That is, the number of child threads can be determined using the following formula:
Figure PCTCN2020085565-appb-000001
Among them, N is the auxiliary signature verification sub-thread, A is the number of transactions, and B is the preset number threshold.
S703:采用待命验签线程和辅助验签子线程对待处理事务进行签名验证,获取签名验证结果。S703: Use the standby signature verification thread and the auxiliary signature verification subthread to perform signature verification on the transaction to be processed, and obtain a signature verification result.
具体地,服务器采用待命验签线程和与子线程数量相匹配的辅助验签子线程对待处理区块中所有的待处理事务进行并发签名验证,以快速获取该待处理区块中所有待处理事务对应的签名验证结果,以提高待处理事务较多的待处理区块的签名验证效率。也即本实施例中可采用N+1个线程对一个待处理区块中所有待处理事务进行签名验证,可快速获取相应的签名验证结果。Specifically, the server uses the standby verification thread and the auxiliary verification sub-thread matching the number of sub-threads to perform concurrent signature verification on all pending transactions in the pending block, so as to quickly obtain the correspondence of all pending transactions in the pending block. The result of signature verification to improve the efficiency of signature verification of the block to be processed with more transactions to be processed. That is, in this embodiment, N+1 threads may be used to perform signature verification on all pending transactions in a pending block, and the corresponding signature verification results may be quickly obtained.
S704:将签名验证结果存储在待处理区块的元数据区域,获取验签结果区块,释放待命验签线程并销毁辅助验签子线程。S704: Store the signature verification result in the metadata area of the block to be processed, obtain the signature verification result block, release the standby signature verification thread, and destroy the auxiliary signature verification subthread.
具体地,服务器将所有待处理事务对应的签名验证结果存储在待处理区块的元数据区域,以形成包含签名验证结果的验签结果区块,可保障验签结果区块的获取效率。在获取验签结果区块之后,需释放该待命验签线程,以使该待命验签线程可以处理其他待处理区块,在释放该待命验签线程之后,在预设时间内该待命验签线程为空闲唤醒线程;若在该预设时间内接收到新的待处理区块,则空闲唤醒线程重新进入工作状态;若在该预设时间内未接收到新的待处理区块,则空闲唤醒线程进入休眠状态。由于辅助验签子线程是系统 临时创建的用于协助待命验签线程对事务数量较多的待处理区块进行处理的线程,在该待处理区块处理完成后,需销毁辅助验签子线程,以避免系统中线程数量过多而影响各线程的处理效率。Specifically, the server stores the signature verification results corresponding to all pending transactions in the metadata area of the pending block to form a verification result block containing the signature verification result, which can ensure the efficiency of obtaining the verification result block. After obtaining the signature verification result block, the standby signature verification thread needs to be released so that the standby signature verification thread can process other pending blocks. After the standby signature verification thread is released, the standby signature verification thread will be used within a preset time. The thread is an idle wake-up thread; if a new block to be processed is received within the preset time, the idle wake-up thread re-enters the working state; if a new block to be processed is not received within the preset time, it is idle Wake up the thread to enter the sleep state. Since the auxiliary signature verification sub-thread is temporarily created by the system to assist the standby verification thread to process the block to be processed with a large number of transactions, after the processing of the pending block is completed, the auxiliary signature verification sub-thread needs to be destroyed. Avoid too many threads in the system to affect the processing efficiency of each thread.
本实施例所提供的区块链事务处理方法中,在待处理区块中所有待处理事务的事务数量大于预设数量阈值时,创建辅助验签子线程与待命验签子线程对这些待处理事务并发进行签名验证处理,以提高该待处理区块的签名验证效率,进而保障整体处理效率。在签名验证完成,获取验签结果区块后,需释放待命验签线程并销毁辅助验签子线程,可有效节省系统损耗,保障系统处理效率。In the blockchain transaction processing method provided in this embodiment, when the number of transactions of all pending transactions in the block to be processed is greater than a preset number threshold, an auxiliary signature verification subthread and a standby verification subthread are created concurrently for these pending transactions Perform signature verification processing to improve the signature verification efficiency of the block to be processed, thereby ensuring the overall processing efficiency. After the signature verification is completed and the verification result block is obtained, the standby verification thread needs to be released and the auxiliary verification subthread is destroyed, which can effectively save system losses and ensure system processing efficiency.
在一实施例中,如图8所示,在步骤S204之后,即在提交目标区块之后,区块链事务处理方法还包括如下步骤:In one embodiment, as shown in FIG. 8, after step S204, that is, after submitting the target block, the blockchain transaction processing method further includes the following steps:
S801:在多版本并发控制验证过程中,依序对目标区块中的每一验签结果区块的签名验证结果进行识别。S801: In the process of multi-version concurrency control verification, sequentially identify the signature verification result of each verification result block in the target block.
其中,多版本并发控制(multiple version concurrent control,简称为MVCC)验证过程主要用于确定交易(即验签结果区块对应的交易)被提交时的交易状态是否为交易产生时的当前状态的验证过程。在多版本并发控制验证过程中,依序对目标区块中的每一验签结果区块的元数据区域记载的签名验证结果进行识别,以确定其对应的签名验证结果为签名有效还是签名无效。可以理解地,由于多版本并发控制验证过程中,任一验签结果区块对应的检查结果依赖于前一个验签结果区块,即前面的验签结果区块对系统的当前状态的修改可能会影响后面的验签结果区块的有效性判定,即验签结果区块之间顺序不同可能导致整个区块链最终状态不一致,因此,需依序对目标区块中的每一个验签结果区块的签名验证结果进行识别。Among them, the multiple version concurrent control (MVCC) verification process is mainly used to verify whether the transaction state when the transaction (that is, the transaction corresponding to the verification result block) is submitted is the current state when the transaction is generated process. In the process of multi-version concurrency control verification, sequentially identify the signature verification results recorded in the metadata area of each verification result block in the target block to determine whether the corresponding signature verification result is valid or invalid . Understandably, due to the multi-version concurrency control verification process, the check result corresponding to any verification result block depends on the previous verification result block, that is, the previous verification result block may modify the current state of the system. It will affect the validity judgment of the subsequent verification result blocks, that is, the order of the verification result blocks may cause the final state of the entire blockchain to be inconsistent. Therefore, each verification result in the target block needs to be sequentially checked. The signature verification result of the block is identified.
S802:若签名验证结果为签名有效,则将验签结果区块对应的交易状态与当前状态进行对比,交易状态与当前状态一致,则对验签结果区块进行执行操作,获取有效交易数据。S802: If the signature verification result is that the signature is valid, the transaction status corresponding to the signature verification result block is compared with the current state, and the transaction status is consistent with the current state, then an operation is performed on the signature verification result block to obtain valid transaction data.
具体地,在验签结果区块对应的签名验证结果为签名有效时,将验签结果区块对应的交易状态与当前状态进行对比,若交易状态与当前状态一致,则对验签结果区块进行执行操作,则对验签结果区块进行执行操作,获取有效交易数据;若交易状态与当前状态不一致,则将验签结果区块对应的交易数据确定为无效交易数据。其中,验签结果区块对应的交易状态是指验签结果区块中的交易数据所记录的状态;验签结果区块对应的当前状态是指验签结果区块中的交易数据对应的系统状态。Specifically, when the signature verification result corresponding to the verification result block is the signature valid, the transaction state corresponding to the verification result block is compared with the current state, and if the transaction state is consistent with the current state, the verification result block is compared Perform an execution operation to perform an operation on the verification result block to obtain valid transaction data; if the transaction status is inconsistent with the current state, the transaction data corresponding to the verification result block is determined to be invalid transaction data. Among them, the transaction state corresponding to the verification result block refers to the state recorded by the transaction data in the verification result block; the current state corresponding to the verification result block refers to the system corresponding to the transaction data in the verification result block status.
例如,若A在T0时刻查询到银行卡的账户余额为100元,在查看账户余额之后一段时间后的T1时刻提交一个向B转账的100元的交易,形成第1笔交易数据,也即系统在T1时刻才会接收到该笔交易并进行处理。若在A查看账户余额到提交交易这一段时间内,即T0-T1内,A的朋友C采用该银行卡的副卡或者网上银行等其他更方式在其他地方刷了100元,则此时A提交的100元的转账交易会失败,因为交易产生时的交易状态(账户余额为100元,可执行转账交易),而交易被系统执行前的当前状态(账户余额为0元),使得交易状态与当前状态不一致,则直接将这个100元转账交易对应的交易数据确定为无效交易数据。相应地,若在A查看账户余额到提交交易这一段时间内,即T0-T1内,没有其他人采用该银行卡的副卡或者网上银行等方式在其他地方进行交易,则其交易产生时的交易状态(账户余额为100元),而交易被执行前的当前状态(账户余额为100元),两者一致,则将这个100元转账交易对应的交易数据确定为有效交易数据。可以理解地,验签结果区块对应的交易状态与当前状态是否一致主要取决于交易过程中的时间差。For example, if A finds that the account balance of the bank card is 100 yuan at time T0, a transaction of 100 yuan transferred to B is submitted at time T1 after a period of time after checking the account balance to form the first transaction data, that is, the system The transaction will be received and processed at time T1. If A's friend C uses the secondary card of the bank card or online banking and other other methods to swipe 100 yuan in other places during the period from A's checking of the account balance to the submission of the transaction, that is, T0-T1, then A at this time The submitted transfer transaction of 100 yuan will fail because the transaction status (account balance is 100 yuan, the transfer transaction can be executed) when the transaction is generated, and the current state before the transaction is executed by the system (the account balance is 0 yuan) makes the transaction status Inconsistent with the current status, the transaction data corresponding to this 100 yuan transfer transaction is directly determined as invalid transaction data. Correspondingly, if in the period from A’s checking of the account balance to the submission of the transaction, that is, within T0-T1, no one else uses the secondary card of the bank card or online banking to conduct transactions in other places, then the transaction occurred when the transaction occurred. If the transaction status (account balance is 100 yuan) and the current status before the transaction is executed (account balance is 100 yuan), if the two are consistent, the transaction data corresponding to this 100 yuan transfer transaction is determined as valid transaction data. Understandably, whether the transaction status corresponding to the verification result block is consistent with the current status mainly depends on the time difference in the transaction process.
S803:若签名验证结果为签名无效,则将验签结果区块对应的交易数据确定为无效交易数据。S803: If the signature verification result is that the signature is invalid, the transaction data corresponding to the signature verification result block is determined to be invalid transaction data.
具体地,在验签结果区块对应的签名验证结果为签名无效时,将验签结果区块对应的交易数据直接确定为无效交易数据,无需进行后续的交易状态与当前状态进行验证的操作, 有助于减少多版本并发控制验证的处理过程,提高处理效率。Specifically, when the signature verification result corresponding to the verification result block is that the signature is invalid, the transaction data corresponding to the verification result block is directly determined as invalid transaction data, without the need to perform subsequent operations of verifying the transaction state and the current state. It helps to reduce the process of multi-version concurrency control verification and improve processing efficiency.
S804:基于有效交易数据和无效交易数据进行事务持久化处理。S804: Perform transaction persistence processing based on valid transaction data and invalid transaction data.
其中,事务持久化也称为交易的提交(Commit)是指区块中经过签名验证和多版本并发控制验证后获取的交易数据进行提交,写入磁盘的过程。一般来说,在事务持久化处理过程中,若一验签结果区块对应的交易数据为有效交易数据,则基于该有效交易数据修改区块链中的相应的当前状态;若一验签结果区块对应的交易数据为无效交易数据,则无效交易数据不被采纳,因此,无需修改区块链中的当前状态,对无效交易数据进行事务持久化处理,以便于进行溯源。Among them, transaction persistence is also called transaction commit (Commit) refers to the process of committing transaction data obtained after signature verification and multi-version concurrency control verification in a block, and writing it to disk. Generally speaking, in the process of transaction persistence, if the transaction data corresponding to a verification result block is valid transaction data, the corresponding current state in the blockchain is modified based on the valid transaction data; if a verification result is If the transaction data corresponding to the block is invalid transaction data, the invalid transaction data will not be adopted. Therefore, there is no need to modify the current state in the blockchain and perform transaction persistence processing on invalid transaction data to facilitate traceability.
本实施例所提供的区块链事务处理方法,在多版本并发控制验证过程中,依序对目标区块中的每一验签结果区块的签名验证结果进行识别,以使执行顺序在先的验签结果区块先进行验证,而执行顺序在后的验签结果区块在后验证,使得执行顺序在后的验签结果区块的验证可以依赖执行顺序在前的验签结果区块的验证结果进行更改。可对多版本并发控制验证过程确定的有效交易数据和无效交易数据进行进行事务持久化处理,以保证这些有效交易数据和无效交易数据的安全性,避免被篡改。In the blockchain transaction processing method provided in this embodiment, in the multi-version concurrency control verification process, the signature verification results of each verification result block in the target block are sequentially identified, so that the execution order is first The verification result block is verified first, and the verification result block with the subsequent execution sequence is verified later, so that the verification of the verification result block with the subsequent execution sequence can rely on the verification result block with the previous execution sequence The verification results are changed. The valid transaction data and invalid transaction data determined by the multi-version concurrency control verification process can be subjected to transaction persistence processing to ensure the security of these valid transaction data and invalid transaction data and avoid tampering.
应理解,上述实施例中各步骤的序号的大小并不意味着执行顺序的先后,各过程的执行顺序应以其功能和内在逻辑确定,而不应对本申请实施例的实施过程构成任何限定。It should be understood that the size of the sequence number of each step in the foregoing embodiment does not mean the order of execution. The execution sequence of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present application.
在一实施例中,提供一种区块链事务处理装置,该区块链事务处理装置与上述实施例中区块链事务处理方法一一对应。如图9所示,该区块链事务处理装置包括待处理区块接收模块901、签名验证处理模块902、目标区块确定模块903和目标区块提交模块904。各功能模块详细说明如下:In one embodiment, a blockchain transaction processing device is provided, and the blockchain transaction processing device corresponds to the blockchain transaction processing method in the above-mentioned embodiment one-to-one. As shown in FIG. 9, the blockchain transaction processing device includes a block receiving module 901 to be processed, a signature verification processing module 902, a target block determination module 903, and a target block submission module 904. The detailed description of each functional module is as follows:
待处理区块接收模块901,用于接收待处理区块,将待处理区块存储在区块队列中,每一待处理区块对应一区块标签。The to-be-processed block receiving module 901 is configured to receive the to-be-processed blocks and store the to-be-processed blocks in a block queue, and each to-be-processed block corresponds to a block label.
签名验证处理模块902,用于并发启动预先创建的待命验签线程,对区块队列中的待处理区块进行签名验证,获取验签结果区块,将验签结果区块存储到缓存中。The signature verification processing module 902 is configured to concurrently start a pre-created standby verification thread, perform signature verification on the block to be processed in the block queue, obtain the verification result block, and store the verification result block in the cache.
目标区块确定模块903,用于实时检测缓存中是否包含当前期望区块,若缓存中包含当前期望区块,则将以当前期望区块为起始块的连续的至少一个验签结果区块确定为目标区块。The target block determination module 903 is used for real-time detection of whether the current desired block is contained in the cache, and if the current desired block is contained in the cache, at least one continuous verification result block with the current desired block as the starting block will be used Determined as the target block.
目标区块提交模块904,用于提交目标区块,并基于目标区块中最后一个验签结果区块对应的区块标签更新当前期望区块。The target block submission module 904 is used to submit the target block and update the current desired block based on the block label corresponding to the last verification result block in the target block.
优选地,目标区块确定模块903,包括:Preferably, the target block determining module 903 includes:
区块标签匹配处理单元,用于实时检测缓存中验签结果区块对应的区块标签,判断区块标签是否与缓存中实时记录的区块指引信息相匹配。The block label matching processing unit is used to detect the block label corresponding to the verification result block in the cache in real time, and determine whether the block label matches the block guide information recorded in the cache in real time.
当前期望区块确定单元,用于若区块标签与区块指引信息相匹配,则区块标签对应的验签结果区块为当前期望区块。The current desired block determining unit is configured to, if the block label matches the block guide information, the verification result block corresponding to the block label is the current desired block.
优选地,在待处理区块接收模块901之前,区块链事务处理装置还包括:Preferably, before the to-be-processed block receiving module 901, the blockchain transaction processing device further includes:
内核数量确定单元,用于获取区块链系统的内核数量。The number of cores determining unit is used to obtain the number of cores of the blockchain system.
验签线程创建单元,用于基于内核数量和目标比例范围,确定目标数量,创建验签线程池,验签线程池包括与目标数量相对应的待命验签线程。The verification thread creation unit is used to determine the target number based on the number of cores and the target ratio range, and create a verification thread pool. The verification thread pool includes the standby verification threads corresponding to the target number.
优选地,签名验证处理模块902,包括:Preferably, the signature verification processing module 902 includes:
区块数量监控单元,用于实时监控区块队列中的待处理区块对应的区块数量。The block quantity monitoring unit is used for real-time monitoring of the block quantity corresponding to the to-be-processed block in the block queue.
线程唤醒分配单元,用于若区块数量大于零,则触发唤醒指令,基于唤醒指令,并发唤醒验签线程池中处于休眠状态的待命验签线程,将区块队列中的待处理区块分配给对应的待命验签线程。The thread wakeup allocation unit is used to trigger a wake-up instruction if the number of blocks is greater than zero. Based on the wake-up instruction, it concurrently wakes up the standby verification threads in the verification thread pool and allocates the pending blocks in the block queue Give the corresponding standby verification thread.
优选地,待处理区块接收模块901,包括:Preferably, the block receiving module 901 to be processed includes:
合法性校验单元,用于接收待处理区块,对待处理区块进行合法性校验,获取合法性 校验结果。The legality check unit is used to receive the block to be processed, perform legality check on the block to be processed, and obtain the legality check result.
区块存储单元,用于若合法性校验结果为校验通过,则将待处理区块存储在区块队列中。The block storage unit is used to store the to-be-processed block in the block queue if the result of the legality check is passed.
优选地,签名验证处理模块902,包括:Preferably, the signature verification processing module 902 includes:
事务数量检测单元,用于检测每一待处理区块中所有待处理事务对应的事务数量。The transaction quantity detection unit is used to detect the transaction quantity corresponding to all pending transactions in each pending block.
辅助线程创建单元,用于若事务数量大于预设数量阈值,则依据事务数量确定子线程数量,创建与子线程数量相匹配的辅助验签子线程。The auxiliary thread creation unit is used to determine the number of child threads according to the number of transactions if the number of transactions is greater than the preset number threshold, and create an auxiliary sign verification child thread that matches the number of child threads.
签名验证处理单元,用于采用待命验签线程和辅助验签子线程对待处理事务进行签名验证,获取签名验证结果。The signature verification processing unit is used to use the standby verification thread and the auxiliary verification sub-thread to perform signature verification on the transaction to be processed, and obtain the signature verification result.
验签结果区块获取单元,用于将签名验证结果存储在待处理区块的元数据区域,获取验签结果区块,释放待命验签线程并销毁辅助验签子线程。The signature verification result block acquisition unit is used to store the signature verification result in the metadata area of the block to be processed, obtain the signature verification result block, release the standby signature verification thread and destroy the auxiliary signature verification subthread.
优选地,在目标区块提交模块904之后,区块链事务处理装置还包括:Preferably, after the target block submission module 904, the blockchain transaction processing device further includes:
签名验证结果识别单元,用于在多版本并发控制验证过程中,依序对目标区块中的每一验签结果区块的签名验证结果进行识别。The signature verification result identification unit is used to sequentially identify the signature verification result of each verification result block in the target block in the multi-version concurrency control verification process.
有效交易数据确定单元,用于若签名验证结果为签名有效,则将验签结果区块对应的交易状态与当前状态进行对比,交易状态与当前状态一致,则对验签结果区块进行执行操作,获取有效交易数据。The valid transaction data determining unit is used to compare the transaction state corresponding to the verification result block with the current state if the signature verification result is valid, and the transaction state is consistent with the current state, then perform operations on the verification result block To obtain valid transaction data.
无效交易数据确定单元,用于若签名验证结果为签名无效,则将验签结果区块对应的交易数据确定为无效交易数据。The invalid transaction data determining unit is configured to determine the transaction data corresponding to the verification result block as invalid transaction data if the signature verification result is that the signature is invalid.
事务持久化处理单元,用于基于有效交易数据和无效交易数据进行事务持久化处理。The transaction persistence processing unit is used to perform transaction persistence processing based on valid transaction data and invalid transaction data.
关于区块链事务处理装置的具体限定可以参见上文中对于区块链事务处理方法的限定,在此不再赘述。上述区块链事务处理装置中的各个模块可全部或部分通过软件、硬件及其组合来实现。上述各模块可以硬件形式内嵌于或独立于计算机设备中的处理器中,也可以以软件形式存储于计算机设备中的存储器中,以便于处理器调用执行以上各个模块对应的操作。For the specific limitation of the blockchain transaction processing device, please refer to the above limitation on the blockchain transaction processing method, which will not be repeated here. Each module in the above-mentioned blockchain transaction processing device can be implemented in whole or in part by software, hardware, and a combination thereof. The above-mentioned modules may be embedded in the form of hardware or independent of the processor in the computer equipment, or may be stored in the memory of the computer equipment in the form of software, so that the processor can call and execute the operations corresponding to the above-mentioned modules.
在一个实施例中,提供了一种计算机设备,该计算机设备可以是服务器,其内部结构图可以如图10所示。该计算机设备包括通过系统总线连接的处理器、存储器、网络接口和数据库。其中,该计算机设备的处理器用于提供计算和控制能力。该计算机设备的存储器包括非易失性存储介质、内存储器。该非易失性存储介质存储有操作系统、计算机程序和数据库。该内存储器为非易失性存储介质中的操作系统和计算机程序的运行提供环境。该计算机设备的数据库用于执行上述实施例中的区块链事务处理方法过程中采用或者形成的数据。该计算机设备的网络接口用于与外部的终端通过网络连接通信。该计算机程序被处理器执行时以实现一种区块链事务处理方法。In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as shown in FIG. 10. The computer equipment includes a processor, a memory, a network interface, and a database connected through a system bus. Among them, the processor of the computer device is used to provide calculation and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The database of the computer device is used to execute the data adopted or formed in the process of the blockchain transaction processing method in the foregoing embodiment. The network interface of the computer device is used to communicate with an external terminal through a network connection. The computer program is executed by the processor to realize a blockchain transaction processing method.
在一个实施例中,提供了一种计算机设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,处理器执行计算机程序时实现上述实施例中区块链事务处理方法的步骤,例如图2所示的步骤S201-S204,或者图3至图8中所示的步骤,为避免重复,这里不再赘述。或者,处理器执行计算机程序时实现区块链事务处理装置这一实施例中的各模块/单元的功能,例如图9所示的待处理区块接收模块901、签名验证处理模块902、目标区块确定模块903和目标区块提交模块904的功能,为避免重复,这里不再赘述。In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored on the memory and capable of running on the processor. The processor executes the blockchain transaction processing in the above embodiment when the processor executes the computer program. The steps of the method, such as steps S201-S204 shown in FIG. 2, or the steps shown in FIG. 3 to FIG. 8, are not repeated here to avoid repetition. Or, when the processor executes the computer program, the function of each module/unit in the embodiment of the blockchain transaction processing device is realized, for example, the block receiving module 901, the signature verification processing module 902, and the target area shown in FIG. 9 The functions of the block determination module 903 and the target block submission module 904 are not repeated here in order to avoid repetition.
在一实施例中,提供一计算机可读存储介质,该计算机可读存储介质上存储有计算机程序,该计算机程序被处理器执行时实现上述实施例中区块链事务处理方法的步骤,例如图2所示的步骤S201-S204,或者图3至图8中所示的步骤,为避免重复,这里不再赘述。或者,该计算机程序被处理器执行时实现上述区块链事务处理装置这一实施例中的各模块/单元的功能,例如图9所示的待处理区块接收模块901、签名验证处理模块902、目标区块 确定模块903和目标区块提交模块904的功能,为避免重复,这里不再赘述。In one embodiment, a computer-readable storage medium is provided, and a computer program is stored on the computer-readable storage medium. When the computer program is executed by a processor, it realizes the steps of the blockchain transaction processing method in the above-mentioned embodiment, as shown in FIG. Steps S201-S204 shown in 2 or the steps shown in FIG. 3 to FIG. 8 are not repeated here in order to avoid repetition. Or, when the computer program is executed by the processor, the function of each module/unit in the embodiment of the blockchain transaction processing device is realized, for example, the to-be-processed block receiving module 901 and the signature verification processing module 902 shown in FIG. 9 The functions of the target block determining module 903 and the target block submitting module 904 are not repeated here in order to avoid repetition.
本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,是可以通过计算机程序来指令相关的硬件来完成,所述的计算机程序可存储于一非易失性计算机可读取存储介质中,也可以存储于易失性存储介质中。该计算机程序在执行时,可包括如上述各方法的实施例的流程。其中,本申请所提供的各实施例中所使用的对存储器、存储、数据库或其它介质的任何引用,均可包括非易失性和/或易失性存储器。非易失性存储器可包括只读存储器(ROM)、可编程ROM(PROM)、电可编程ROM(EPROM)、电可擦除可编程ROM(EEPROM)或闪存。易失性存储器可包括随机存取存储器(RAM)或者外部高速缓冲存储器。作为说明而非局限,RAM以多种形式可得,诸如静态RAM(SRAM)、动态RAM(DRAM)、同步DRAM(SDRAM)、双数据率SDRAM(DDRSDRAM)、增强型SDRAM(ESDRAM)、同步链路(Synchlink)DRAM(SLDRAM)、存储器总线(Rambus)直接RAM(RDRAM)、直接存储器总线动态RAM(DRDRAM)、以及存储器总线动态RAM(RDRAM)等。A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing relevant hardware through a computer program. The computer program can be stored in a non-volatile computer readable storage. In the medium, it can also be stored in a volatile storage medium. When the computer program is executed, it may include the processes of the above-mentioned method embodiments. Wherein, any reference to memory, storage, database or other media used in the embodiments provided in this application may include non-volatile and/or volatile memory. Non-volatile memory may include read only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. As an illustration and not a limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous chain Channel (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

Claims (20)

  1. 一种区块链事务处理方法,包括:A blockchain transaction processing method, including:
    接收待处理区块,将所述待处理区块存储在区块队列中,每一所述待处理区块对应一区块标签;Receiving the to-be-processed blocks, storing the to-be-processed blocks in a block queue, and each of the to-be-processed blocks corresponds to a block label;
    并发启动预先创建的待命验签线程,对所述区块队列中的所述待处理区块进行签名验证,获取验签结果区块,将所述验签结果区块存储到缓存中;Concurrently start a pre-created standby signature verification thread, perform signature verification on the block to be processed in the block queue, obtain a signature verification result block, and store the signature verification result block in a cache;
    实时检测所述缓存中是否包含当前期望区块,若所述缓存中包含所述当前期望区块,则将以所述当前期望区块为起始块的连续的至少一个验签结果区块确定为目标区块;Real-time detection of whether the current desired block is included in the cache, and if the current desired block is included in the cache, at least one continuous verification result block with the current desired block as the starting block is determined Is the target block;
    提交所述目标区块,并基于所述目标区块中最后一个验签结果区块对应的区块标签更新所述当前期望区块。Submit the target block, and update the current desired block based on the block label corresponding to the last verification result block in the target block.
  2. 如权利要求1所述的区块链事务处理方法,所述实时检测所述缓存中是否包含当前期望区块,包括:The blockchain transaction processing method of claim 1, wherein the real-time detection of whether the current desired block is contained in the cache includes:
    实时检测所述缓存中验签结果区块对应的区块标签,判断所述区块标签是否与所述缓存中实时记录的区块指引信息相匹配;Real-time detection of the block label corresponding to the verification result block in the cache, and determining whether the block label matches the block guide information recorded in the cache in real time;
    若所述区块标签与所述区块指引信息相匹配,则所述区块标签对应的验签结果区块为当前期望区块。If the block label matches the block guide information, the verification result block corresponding to the block label is the current expected block.
  3. 如权利要求1所述的区块链事务处理方法,在所述接收待处理区块,将所述待处理区块存储在区块队列中之前,所述区块链事务处理方法还包括:The blockchain transaction processing method according to claim 1, before the receiving the block to be processed and storing the block to be processed in the block queue, the block chain transaction processing method further comprises:
    获取区块链系统的内核数量;Get the number of cores of the blockchain system;
    基于内核数量和目标比例范围,确定目标数量,创建验签线程池,所述验签线程池包括与所述目标数量相对应的待命验签线程。Based on the number of cores and the target ratio range, the target number is determined, and a signature verification thread pool is created. The signature verification thread pool includes a standby verification thread corresponding to the target number.
  4. 如权利要求1所述的区块链事务处理方法,所述并发启动预先创建的待命验签线程,包括:The blockchain transaction processing method according to claim 1, wherein said concurrently starting a pre-created standby verification thread comprises:
    实时监控所述区块队列中的待处理区块对应的区块数量;Real-time monitoring of the number of blocks corresponding to the blocks to be processed in the block queue;
    若所述区块数量大于零,则触发唤醒指令,基于所述唤醒指令,并发唤醒所述验签线程池中处于休眠状态的待命验签线程,将所述区块队列中的待处理区块分配给对应的待命验签线程。If the number of blocks is greater than zero, a wake-up instruction is triggered, and based on the wake-up instruction, the standby verification thread in the dormant state in the verification thread pool is concurrently awakened, and the pending block in the block queue Assigned to the corresponding standby verification thread.
  5. 如权利要求1所述的区块链事务处理方法,所述接收待处理区块,将所述待处理区块存储在区块队列中,包括:The blockchain transaction processing method of claim 1, wherein the receiving the block to be processed and storing the block to be processed in a block queue comprises:
    接收待处理区块,对所述待处理区块进行合法性校验,获取合法性校验结果;Receiving a block to be processed, performing a legality check on the block to be processed, and obtaining a legality check result;
    若所述合法性校验结果为校验通过,则将所述待处理区块存储在区块队列中。If the result of the legality check is that the check is passed, the block to be processed is stored in the block queue.
  6. 如权利要求1所述的区块链事务处理方法,所述对所述区块队列中的所述待处理区块进行签名验证,获取验签结果区块,包括:5. The blockchain transaction processing method according to claim 1, wherein said performing signature verification on said block to be processed in said block queue to obtain a signature verification result block comprises:
    检测每一所述待处理区块中所有待处理事务对应的事务数量;Detecting the number of transactions corresponding to all pending transactions in each of the pending blocks;
    若所述事务数量大于预设数量阈值,则依据所述事务数量确定子线程数量,创建与所述子线程数量相匹配的辅助验签子线程;If the number of transactions is greater than the preset number threshold, the number of sub-threads is determined according to the number of transactions, and an auxiliary signature verification sub-thread that matches the number of sub-threads is created;
    采用所述待命验签线程和所述辅助验签子线程对所述待处理事务进行签名验证,获取签名验证结果;Using the standby signature verification thread and the auxiliary signature verification subthread to perform signature verification on the pending transaction, and obtain a signature verification result;
    将所述签名验证结果存储在所述待处理区块的元数据区域,获取验签结果区块,释放所述待命验签线程并销毁所述辅助验签子线程。The signature verification result is stored in the metadata area of the block to be processed, the signature verification result block is obtained, the standby signature verification thread is released, and the auxiliary signature verification subthread is destroyed.
  7. 如权利要求1所述的区块链事务处理方法,在所述提交所述目标区块之后,所述区块链事务处理方法还包括:The blockchain transaction processing method according to claim 1, after the submission of the target block, the blockchain transaction processing method further comprises:
    在多版本并发控制验证过程中,依序对所述目标区块中的每一验签结果区块的签名验 证结果进行识别;In the process of multi-version concurrency control verification, sequentially identify the signature verification result of each verification result block in the target block;
    若所述签名验证结果为签名有效,则将所述验签结果区块对应的交易状态与当前状态进行对比,所述交易状态与所述当前状态一致,则对所述验签结果区块进行执行操作,获取有效交易数据;If the signature verification result is that the signature is valid, the transaction state corresponding to the verification result block is compared with the current state, and the transaction state is consistent with the current state, then the verification result block is performed Perform operations to obtain valid transaction data;
    若所述签名验证结果为签名无效,则将所述验签结果区块对应的交易数据确定为无效交易数据;If the signature verification result is that the signature is invalid, the transaction data corresponding to the signature verification result block is determined to be invalid transaction data;
    基于所述有效交易数据和所述无效交易数据进行事务持久化处理。Perform transaction persistence processing based on the valid transaction data and the invalid transaction data.
  8. 一种区块链事务处理装置,包括:A blockchain transaction processing device, including:
    待处理区块接收模块,用于接收待处理区块,将所述待处理区块存储在区块队列中,每一所述待处理区块对应一区块标签;The block to be processed receiving module is used to receive the block to be processed, and store the block to be processed in a block queue, and each block to be processed corresponds to a block label;
    签名验证处理模块,用于并发启动预先创建的待命验签线程,对所述区块队列中的所述待处理区块进行签名验证,获取验签结果区块,将所述验签结果区块存储到缓存中;The signature verification processing module is used to concurrently start a pre-created standby verification thread, perform signature verification on the to-be-processed block in the block queue, obtain the verification result block, and transfer the verification result block Store in the cache;
    目标区块确定模块,用于实时检测所述缓存中是否包含当前期望区块,若所述缓存中包含所述当前期望区块,则将以所述当前期望区块为起始块的连续的至少一个验签结果区块确定为目标区块;The target block determination module is used to detect in real time whether the current desired block is included in the cache, and if the current desired block is included in the cache, the current desired block will be a continuous starting block. At least one verification result block is determined as the target block;
    目标区块提交模块,用于提交所述目标区块,并基于所述目标区块中最后一个验签结果区块对应的区块标签更新所述当前期望区块。The target block submission module is configured to submit the target block and update the current desired block based on the block label corresponding to the last verification result block in the target block.
  9. 一种计算机设备,包括存储器、处理器以及存储在所述存储器中并可在所述处理器上运行的计算机程序,所述处理器执行所述计算机程序时实现区块链事务处理方法:接收待处理区块,将所述待处理区块存储在区块队列中,每一所述待处理区块对应一区块标签;A computer device includes a memory, a processor, and a computer program stored in the memory and capable of running on the processor. The processor implements a blockchain transaction processing method when the processor executes the computer program: receiving waiting Processing blocks, storing the blocks to be processed in a block queue, and each block to be processed corresponds to a block label;
    并发启动预先创建的待命验签线程,对所述区块队列中的所述待处理区块进行签名验证,获取验签结果区块,将所述验签结果区块存储到缓存中;Concurrently start a pre-created standby signature verification thread, perform signature verification on the block to be processed in the block queue, obtain a signature verification result block, and store the signature verification result block in a cache;
    实时检测所述缓存中是否包含当前期望区块,若所述缓存中包含所述当前期望区块,则将以所述当前期望区块为起始块的连续的至少一个验签结果区块确定为目标区块;Real-time detection of whether the current desired block is included in the cache, and if the current desired block is included in the cache, at least one continuous verification result block with the current desired block as the starting block is determined Is the target block;
    提交所述目标区块,并基于所述目标区块中最后一个验签结果区块对应的区块标签更新所述当前期望区块。Submit the target block, and update the current desired block based on the block label corresponding to the last verification result block in the target block.
  10. 根据权利要求9所述的一种计算机设备,所述实时检测所述缓存中是否包含当前期望区块,包括:The computer device according to claim 9, wherein the real-time detection of whether the current desired block is contained in the cache includes:
    实时检测所述缓存中验签结果区块对应的区块标签,判断所述区块标签是否与所述缓存中实时记录的区块指引信息相匹配;Real-time detection of the block label corresponding to the verification result block in the cache, and determining whether the block label matches the block guide information recorded in the cache in real time;
    若所述区块标签与所述区块指引信息相匹配,则所述区块标签对应的验签结果区块为当前期望区块。If the block label matches the block guide information, the verification result block corresponding to the block label is the current expected block.
  11. 根据权利要求9所述的一种计算机设备,在所述接收待处理区块,将所述待处理区块存储在区块队列中之前,所述区块链事务处理方法还包括:The computer device according to claim 9, before the receiving the block to be processed and storing the block to be processed in the block queue, the blockchain transaction processing method further comprises:
    获取区块链系统的内核数量;Get the number of cores of the blockchain system;
    基于内核数量和目标比例范围,确定目标数量,创建验签线程池,所述验签线程池包括与所述目标数量相对应的待命验签线程。Based on the number of cores and the target ratio range, the target number is determined, and a signature verification thread pool is created. The signature verification thread pool includes a standby verification thread corresponding to the target number.
  12. 根据权利要求9所述的一种计算机设备,所述并发启动预先创建的待命验签线程,包括:8. The computer device according to claim 9, wherein said concurrently starting a pre-created standby signature verification thread comprises:
    实时监控所述区块队列中的待处理区块对应的区块数量;Real-time monitoring of the number of blocks corresponding to the blocks to be processed in the block queue;
    若所述区块数量大于零,则触发唤醒指令,基于所述唤醒指令,并发唤醒所述验签线程池中处于休眠状态的待命验签线程,将所述区块队列中的待处理区块分配给对应的待命验签线程。If the number of blocks is greater than zero, a wake-up instruction is triggered, and based on the wake-up instruction, the standby verification thread in the dormant state in the verification thread pool is concurrently awakened, and the pending block in the block queue Assigned to the corresponding standby verification thread.
  13. 根据权利要求9所述的一种计算机设备,所述接收待处理区块,将所述待处理区块存储在区块队列中,包括:The computer device according to claim 9, wherein said receiving the block to be processed and storing the block to be processed in a block queue comprises:
    接收待处理区块,对所述待处理区块进行合法性校验,获取合法性校验结果;Receiving a block to be processed, performing a legality check on the block to be processed, and obtaining a legality check result;
    若所述合法性校验结果为校验通过,则将所述待处理区块存储在区块队列中。If the result of the legality check is that the check is passed, the block to be processed is stored in the block queue.
  14. 根据权利要求9所述的一种计算机设备,所述对所述区块队列中的所述待处理区块进行签名验证,获取验签结果区块,包括:The computer device according to claim 9, wherein said performing signature verification on said block to be processed in said block queue to obtain a signature verification result block comprises:
    检测每一所述待处理区块中所有待处理事务对应的事务数量;Detecting the number of transactions corresponding to all pending transactions in each of the pending blocks;
    若所述事务数量大于预设数量阈值,则依据所述事务数量确定子线程数量,创建与所述子线程数量相匹配的辅助验签子线程;If the number of transactions is greater than the preset number threshold, the number of sub-threads is determined according to the number of transactions, and an auxiliary signature verification sub-thread that matches the number of sub-threads is created;
    采用所述待命验签线程和所述辅助验签子线程对所述待处理事务进行签名验证,获取签名验证结果;Using the standby signature verification thread and the auxiliary signature verification subthread to perform signature verification on the pending transaction, and obtain a signature verification result;
    将所述签名验证结果存储在所述待处理区块的元数据区域,获取验签结果区块,释放所述待命验签线程并销毁所述辅助验签子线程。The signature verification result is stored in the metadata area of the block to be processed, the signature verification result block is obtained, the standby signature verification thread is released, and the auxiliary signature verification subthread is destroyed.
  15. 根据权利要求9所述的一种计算机设备,在所述提交所述目标区块之后,所述区块链事务处理方法还包括:The computer device according to claim 9, after the submission of the target block, the blockchain transaction processing method further comprises:
    在多版本并发控制验证过程中,依序对所述目标区块中的每一验签结果区块的签名验证结果进行识别;In the process of multi-version concurrency control verification, sequentially identify the signature verification result of each verification result block in the target block;
    若所述签名验证结果为签名有效,则将所述验签结果区块对应的交易状态与当前状态进行对比,所述交易状态与所述当前状态一致,则对所述验签结果区块进行执行操作,获取有效交易数据;If the signature verification result is that the signature is valid, the transaction state corresponding to the verification result block is compared with the current state, and the transaction state is consistent with the current state, then the verification result block is performed Perform operations to obtain valid transaction data;
    若所述签名验证结果为签名无效,则将所述验签结果区块对应的交易数据确定为无效交易数据;If the signature verification result is that the signature is invalid, the transaction data corresponding to the signature verification result block is determined to be invalid transaction data;
    基于所述有效交易数据和所述无效交易数据进行事务持久化处理。Perform transaction persistence processing based on the valid transaction data and the invalid transaction data.
  16. 一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,所述计算机程序被处理器执行时实现区块链事务处理方法的步骤:A computer-readable storage medium, the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of a blockchain transaction processing method are realized:
    接收待处理区块,将所述待处理区块存储在区块队列中,每一所述待处理区块对应一区块标签;Receiving the to-be-processed blocks, storing the to-be-processed blocks in a block queue, and each of the to-be-processed blocks corresponds to a block label;
    并发启动预先创建的待命验签线程,对所述区块队列中的所述待处理区块进行签名验证,获取验签结果区块,将所述验签结果区块存储到缓存中;Concurrently start a pre-created standby signature verification thread, perform signature verification on the block to be processed in the block queue, obtain a signature verification result block, and store the signature verification result block in a cache;
    实时检测所述缓存中是否包含当前期望区块,若所述缓存中包含所述当前期望区块,则将以所述当前期望区块为起始块的连续的至少一个验签结果区块确定为目标区块;Real-time detection of whether the current desired block is included in the cache, and if the current desired block is included in the cache, at least one continuous verification result block with the current desired block as the starting block is determined Is the target block;
    提交所述目标区块,并基于所述目标区块中最后一个验签结果区块对应的区块标签更新所述当前期望区块。Submit the target block, and update the current desired block based on the block label corresponding to the last verification result block in the target block.
  17. 根据权利要求16所述的计算机可读存储介质,所述实时检测所述缓存中是否包含当前期望区块,包括:The computer-readable storage medium according to claim 16, wherein the real-time detection of whether the current desired block is contained in the cache includes:
    实时检测所述缓存中验签结果区块对应的区块标签,判断所述区块标签是否与所述缓存中实时记录的区块指引信息相匹配;Real-time detection of the block label corresponding to the verification result block in the cache, and determining whether the block label matches the block guide information recorded in the cache in real time;
    若所述区块标签与所述区块指引信息相匹配,则所述区块标签对应的验签结果区块为当前期望区块。If the block label matches the block guide information, the verification result block corresponding to the block label is the current expected block.
  18. 根据权利要求16所述的计算机可读存储介质,在所述接收待处理区块,将所述待处理区块存储在区块队列中之前,所述区块链事务处理方法还包括:The computer-readable storage medium according to claim 16, before the receiving the block to be processed and storing the block to be processed in a block queue, the blockchain transaction processing method further comprises:
    获取区块链系统的内核数量;Get the number of cores of the blockchain system;
    基于内核数量和目标比例范围,确定目标数量,创建验签线程池,所述验签线程池包括与所述目标数量相对应的待命验签线程。Based on the number of cores and the target ratio range, the target number is determined, and a signature verification thread pool is created. The signature verification thread pool includes a standby verification thread corresponding to the target number.
  19. 根据权利要求16所述的计算机可读存储介质,所述并发启动预先创建的待命验签线程,包括:15. The computer-readable storage medium according to claim 16, wherein the concurrently starting a pre-created standby verification thread comprises:
    实时监控所述区块队列中的待处理区块对应的区块数量;Real-time monitoring of the number of blocks corresponding to the blocks to be processed in the block queue;
    若所述区块数量大于零,则触发唤醒指令,基于所述唤醒指令,并发唤醒所述验签线程池中处于休眠状态的待命验签线程,将所述区块队列中的待处理区块分配给对应的待命验签线程。If the number of blocks is greater than zero, a wake-up instruction is triggered, and based on the wake-up instruction, the standby verification thread in the dormant state in the verification thread pool is concurrently awakened, and the pending block in the block queue Assigned to the corresponding standby verification thread.
  20. 根据权利要求16所述的计算机可读存储介质,所述接收待处理区块,将所述待处理区块存储在区块队列中,包括:The computer-readable storage medium according to claim 16, wherein said receiving the block to be processed and storing the block to be processed in a block queue comprises:
    接收待处理区块,对所述待处理区块进行合法性校验,获取合法性校验结果;Receiving a block to be processed, performing a legality check on the block to be processed, and obtaining a legality check result;
    若所述合法性校验结果为校验通过,则将所述待处理区块存储在区块队列中。If the result of the legality check is that the check is passed, the block to be processed is stored in the block queue.
PCT/CN2020/085565 2019-09-06 2020-04-20 Blockchain transaction processing method and apparatus, computer device, and storage medium WO2021042733A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910843124.9A CN110781196A (en) 2019-09-06 2019-09-06 Block chain transaction processing method and device, computer equipment and storage medium
CN201910843124.9 2019-09-06

Publications (1)

Publication Number Publication Date
WO2021042733A1 true WO2021042733A1 (en) 2021-03-11

Family

ID=69383374

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/085565 WO2021042733A1 (en) 2019-09-06 2020-04-20 Blockchain transaction processing method and apparatus, computer device, and storage medium

Country Status (2)

Country Link
CN (1) CN110781196A (en)
WO (1) WO2021042733A1 (en)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110781196A (en) * 2019-09-06 2020-02-11 深圳壹账通智能科技有限公司 Block chain transaction processing method and device, computer equipment and storage medium
CN112037058B (en) * 2020-08-28 2024-03-26 平安科技(深圳)有限公司 Data verification method, device and storage medium
CN112131236B (en) * 2020-09-21 2022-07-05 中国电子科技网络信息安全有限公司 Novel block chain parallel processing performance optimization method
CN112819463B (en) * 2021-01-15 2022-08-02 山大地纬软件股份有限公司 Block chain high-concurrency signature checking method and system based on trusted key system
CN113220790A (en) * 2021-06-02 2021-08-06 湖北央中巨石信息技术有限公司 Block chain-based block concurrent synchronization method

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9804891B1 (en) * 2015-03-20 2017-10-31 Antara Teknik LLC Parallelizing multiple signing and verifying operations within a secure routing context
CN108322309A (en) * 2017-12-27 2018-07-24 北京欧链科技有限公司 Transaction processing method based on block chain and device
CN108846674A (en) * 2018-07-12 2018-11-20 众安信息技术服务有限公司 The method and apparatus of signature are verified in block chain
CN109271245A (en) * 2018-09-13 2019-01-25 腾讯科技(深圳)有限公司 A kind of control method and device of block processes task
CN109614206A (en) * 2018-10-25 2019-04-12 深圳壹账通智能科技有限公司 Device, method and the storage medium of block chain issued transaction
CN110781196A (en) * 2019-09-06 2020-02-11 深圳壹账通智能科技有限公司 Block chain transaction processing method and device, computer equipment and storage medium

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9804891B1 (en) * 2015-03-20 2017-10-31 Antara Teknik LLC Parallelizing multiple signing and verifying operations within a secure routing context
CN108322309A (en) * 2017-12-27 2018-07-24 北京欧链科技有限公司 Transaction processing method based on block chain and device
CN108846674A (en) * 2018-07-12 2018-11-20 众安信息技术服务有限公司 The method and apparatus of signature are verified in block chain
CN109271245A (en) * 2018-09-13 2019-01-25 腾讯科技(深圳)有限公司 A kind of control method and device of block processes task
CN109614206A (en) * 2018-10-25 2019-04-12 深圳壹账通智能科技有限公司 Device, method and the storage medium of block chain issued transaction
CN110781196A (en) * 2019-09-06 2020-02-11 深圳壹账通智能科技有限公司 Block chain transaction processing method and device, computer equipment and storage medium

Also Published As

Publication number Publication date
CN110781196A (en) 2020-02-11

Similar Documents

Publication Publication Date Title
WO2021042733A1 (en) Blockchain transaction processing method and apparatus, computer device, and storage medium
US8438568B2 (en) Speculative thread execution with hardware transactional memory
WO2020082576A1 (en) Device and method for processing block transaction, and storage medium
BR112018011775B1 (en) METHOD AND SYSTEM FOR USING DIGITAL SIGNATURES TO SIGN BLOCKCHAIN TRANSACTIONS
WO2020093501A1 (en) File storage method and deletion method, server, and storage medium
US11728976B1 (en) Systems and methods for efficiently serving blockchain requests using an optimized cache
EP3379421B1 (en) Method, apparatus, and chip for implementing mutually-exclusive operation of multiple threads
WO2022048358A1 (en) Data processing method and device, and storage medium
JP5754301B2 (en) Transaction concurrency control system, transaction concurrency control method, and program
CN112231070A (en) Data writing and reading method and device and server
US8484342B2 (en) Organizing individual java client request flows into a single server transaction
CN110704112A (en) Method and apparatus for concurrently executing transactions in a blockchain
CN111694843B (en) Missing number detection method and device, electronic equipment and storage medium
JP2023541298A (en) Transaction processing methods, systems, devices, equipment, and programs
CN111176850B (en) Data pool construction method, device, server and medium
CN115470156A (en) RDMA-based memory use method, system, electronic device and storage medium
US20220092224A1 (en) Data management system with tamper-evidence
WO2021082720A1 (en) Data processing method and apparatus
US10523741B2 (en) System and method for avoiding proxy connection latency
WO2021139113A1 (en) Method and apparatus for signing transaction data, computer device, and storage medium
WO2016141719A1 (en) Channel detection method and apparatus
JP2019504401A (en) High throughput, high reliability data processing system
US10896140B2 (en) Controlling operation of multiple computational engines
US9847983B1 (en) Epoch-based management of security credentials
CN109241362B (en) Block generation method, device, equipment and storage medium

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

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 20.07.2022)

122 Ep: pct application non-entry in european phase

Ref document number: 20860993

Country of ref document: EP

Kind code of ref document: A1