Disclosure of Invention
The invention aims to provide a high-performance blockchain system supporting distributed parallel processing and bidirectional retrieval, which utilizes a hash table technology to store TXO pointers and token quantity data with the same locking script contract data in the same storage position so as to provide the retrieval service which is as concise and efficient as an account model and solve the problem that efficient parallel and efficient retrieval are difficult to be compatible.
In order to achieve the above-mentioned purpose, the present invention provides a high performance blockchain system supporting distributed parallel processing and bidirectional retrieval, which comprises an initialization and resource scheduling module, a network data transceiver module, a retrieval service module and a parallel processing module, wherein the parallel processing module comprises a blockdata parallel processing module, a transaction data parallel processing module and a contract data parallel processing module, and the retrieval service module comprises a transaction inquiry component and a contract inquiry component;
the processing process of the network data transceiver module for data specifically comprises the following steps:
S1, receiving block data and transaction data of a block chain network node and a user terminal, judging a corresponding processing unit based on a parallel task-processing unit mapping table constructed in an initialization and resource scheduling module, if the received data is the block data, sending the data to the corresponding processing unit of the block parallel processing module, and if the received data is the transaction data, sending the data to the corresponding parallel processing unit of the transaction parallel processing module;
And S2, receiving the block data of the block parallel processing module and the transaction data of the transaction parallel processing module, and transmitting the block data and the transaction data to the corresponding block chain network node and the user terminal.
Preferably, in step S1, the initialization and resource scheduling module is responsible for processing the starting and initialization of parallel task-processing units, the parallel task-processing units are set to be single-threaded or multithread, the initialization and resource scheduling module manages the allocation and scheduling of computing tasks, and the number of processing units required to be started by the block parallel processing module and the transaction parallel processing module, the mapping relation and the topology structure of the parallel processing units and the single computing device in the computer cluster are determined by reading configuration files or using an empirical algorithm, so as to construct and manage a mapping table of parallel task-processing units in three layers of block data verification, transaction data verification and contract data verification.
Preferably, in step S1, the processing procedure of the block data parallel processing module on the node data specifically includes:
S11, analyzing the block data received by the network data receiving and transmitting module, analyzing and checking the validity of the block header data, analyzing the transaction data contained in the block header data, and transmitting the transaction data to the transaction parallel processing module;
S12, receiving a processing and verifying result sent back by the transaction parallel processing module, summarizing the processing and verifying result, marking a corresponding block as legal if both the block head data and the internal block transaction are legal, and marking the corresponding block as illegal if the block head data or the internal block transaction are illegal;
and S13, if the node where the block data is located bears the block propagation task, the corresponding block marked as legal is sent to the network data receiving and transmitting module.
Preferably, for a low load scenario with a small amount of block data, the block data parallel processing module sets the number of parallel tasks to 1, and starts and uses a single processing unit.
Preferably, in step S1, the processing procedure of the transaction data parallel processing module on the node data specifically includes:
The method comprises the steps of firstly, receiving transaction data of a network data transceiver module, analyzing the transaction data, calculating and constructing a transaction data reduced set, wherein the transaction data reduced set comprises hash value data of contract data of an unlocking script and a locking script or derivative data of the hash value data based on the contract data of the unlocking script and the locking script, and does not contain complete contract data of the unlocking script and the locking script;
Sequentially processing transaction input data, positioning TXO of a father transaction through an output pointer, acquiring locking script contract data corresponding to the TXO, determining the position or label of a parallel processing unit of the locking script contract data based on initializing a parallel task-processing unit mapping table of a contract data verification layer constructed in a resource scheduling module, and transmitting unlocking dependent data input by the current transaction to a parallel processing unit corresponding to the contract for verification, wherein the unlocking dependent data comprises unlocking script contract data input by the current transaction and a transaction data reduced set of the current transaction;
Sequentially processing transaction output data, analyzing and acquiring TXO data comprising 'locking script' contract data, acquiring a hash value of the 'locking script' contract data according to a hash function, acquiring a position or a label of a corresponding parallel processing unit based on a 'parallel task-processing unit' mapping table of a contract data verification layer constructed in an initialization and resource scheduling module, defining a dataset comprising the TXO data and TXO pointers as 'locking data' according to the position or the label of the parallel processing unit, and transmitting the 'locking data' to the corresponding parallel processing unit of a contract data parallel processing module;
Checking the legal requirement of the transaction except for unlocking verification of single transaction input, and calculating the lowest transaction fee specified by the current blockchain network consensus according to the transaction data and the transaction rate, wherein amount paid in transaction fee is higher than the lowest transaction fee;
Step five, aiming at the transaction input data processed in the step two, receiving a verification result sent back by a contract parallel processing unit, and marking the whole transaction as illegal transaction if the verification result contains 'failed';
And step six, integrating the verification results from the step one to the step five to obtain an overall validity verification result of the transaction data, and sending the overall validity verification result of the transaction data back to the block data parallel processing module.
Preferably, in the third step, the processing procedure of the contract data parallel processing module on the unlocking dependent data and the locking data specifically includes:
Step 3-1, receiving locking data and unlocking dependent data of a transaction data parallel processing module, and analyzing the locking data and the unlocking dependent data;
Step 3-2, when the received data is 'locking data', determining the position of a data table corresponding to the contract according to the hash value of the TXO locking script in the 'locking data', storing the TXO pointer in the 'locking data' in the data table, and marking the TXO pointer in the 'locking data' as an unexpired transaction output UTXO;
step 3-3, when the received data is unlocking dependent data, acquiring a data table position of the UTXO to be unlocked, checking whether the corresponding TXO pointer is UTXO, if the corresponding TXO pointer is UTXO, the corresponding TXO is not spent, and if the corresponding TXO pointer is not UTXO, the corresponding TXO is spent;
Step 3-4, if the corresponding TXO is spent, the verification is failed, and a result of the verification error is returned to the transaction parallel processing unit;
Step 3-5, if the corresponding TXO is not spent, splicing the unlocking script in the unlocking dependent data and the locking script of the corresponding contract in turn to obtain a new script, executing the new script in the contract computing virtual machine, and sending the verification result after execution back to the transaction parallel processing unit;
and 3-6, if the verification execution passes, marking a TXO pointer at a data table position corresponding to the UTXO as the spent TXO, and adding a transaction number TXID for unlocking and spending the transaction of the UTXO.
Preferably, in step 3-1 to step 3-6, if the received "unlock dependent data" belongs to a transaction in a packaged block, the block height and the block hash value of the corresponding block are added to the position of the data table where the corresponding UTXO is located, so as to increase the information amount of contract inquiry.
Preferably, the search service module comprises a distributed block query component, a transaction query component, a contract query component and a query forwarding component, wherein the query forwarding component provides distributed bidirectional search and query service and unified external query interface service, acquires storage positions of transaction data and contract data in the equipment based on a parallel task-processing unit mapping table of a transaction data verification layer and a parallel task-processing unit mapping table of a contract data verification layer constructed in the initialization and resource scheduling module, receives a query request, and forwards the query request to the transaction query component or the contract query component where the data to be queried are located.
Preferably, if the "locked script" of the contract to be queried is the same, the collection and calculation of the query are completed locally.
Preferably, when all modules communicate data, infiniband or RoCE lossless network, RDMA technology or message passing interface technology on lossless network is used, and non-blocking sending and receiving functions are used to increase parallel processing performance between modules.
Therefore, the invention adopts the high-performance blockchain system supporting distributed parallel processing and bidirectional retrieval, and has the following beneficial effects:
(1) The verification speed is high, a multi-layer parallel processing model aiming at the UTXO model blockchain node is provided, the fineness of parallel tasks is enhanced, the calculation task duty ratio of distributable parallel processing is improved, the large-scale expansion capacity of transaction verification is improved, the transaction processing performance is enhanced, and the blockchain system can be used as a high-flux low-cost infrastructure platform;
(2) The retrieval efficiency is high, the transaction list of the same contract script (analog fund account) is stored locally or in a neighboring way, so that the localization or neighboring processing is realized by the aggregation operation, the communication requirement between nodes is reduced, the retrieval delay and the retrieval cost are reduced, the user experience of the blockchain application is improved, and the blockchain application software is helped to improve the competitiveness;
(3) The method realizes the two-way searching capability of searching and trading to obtain contracts on the bottom layer 'node software' level of the blockchain, and facilitates the development of application software;
(4) Because the verification calculation of the same contract script is distributed to run on the same computing equipment, the method provides an implementation basis for hardware customization of contract script verification, can support a low-cost high-efficiency hardware platform, and helps to further reduce service cost.
The technical scheme of the invention is further described in detail through the drawings and the embodiments.
Detailed Description
The technical scheme of the invention is further described below through the attached drawings and the embodiments.
Unless defined otherwise, technical or scientific terms used herein should be given the ordinary meaning as understood by one of ordinary skill in the art to which this invention belongs.
As used herein, the word "comprising" or "comprises" and the like means that elements preceding the word encompass the elements recited after the word, and not exclude the possibility of also encompassing other elements. The terms "inner," "outer," "upper," "lower," and the like are used for convenience in describing and simplifying the description based on the orientation or positional relationship shown in the drawings, and do not denote or imply that the devices or elements referred to must have a specific orientation, be constructed and operated in a specific orientation, and thus should not be construed as limiting the invention, but the relative positional relationship may be changed when the absolute position of the object to be described is changed accordingly. In the present invention, unless explicitly specified and limited otherwise, the term "attached" and the like should be construed broadly, and may be fixedly connected, detachably connected, or integrally formed, directly connected, indirectly connected through an intermediate medium, or in communication between two elements or in interaction with each other. The specific meaning of the above terms in the present invention can be understood by those of ordinary skill in the art according to the specific circumstances.
As shown in fig. 1, the present invention provides a high performance blockchain system supporting distributed parallel processing and bidirectional retrieval, which comprises an initialization and resource scheduling module, a network data transceiver module, a retrieval service module and a parallel processing module, wherein the parallel processing module comprises a blockdata parallel processing module, a transaction data parallel processing module and a contract data parallel processing module, and the retrieval service module comprises a transaction inquiry component and a contract inquiry component;
as shown in fig. 2, the processing procedure of the network data transceiver module for data specifically includes the following steps:
S1, receiving block data and transaction data of a block chain network node and a user terminal, judging a corresponding processing unit based on a parallel task-processing unit mapping table constructed in an initialization and resource scheduling module, if the received data is the block data, sending the data to the corresponding processing unit of the block parallel processing module, and if the received data is the transaction data, sending the data to the corresponding parallel processing unit of the transaction parallel processing module;
And S2, receiving the block data of the block parallel processing module and the transaction data of the transaction parallel processing module, and transmitting the block data and the transaction data to the corresponding block chain network node and the user terminal.
In step S1, the initialization and resource scheduling module is responsible for processing the starting and initialization of parallel task-processing units, the parallel task-processing units are set to be single-threaded or multithread, the initialization and resource scheduling module manages the allocation and scheduling of computing tasks, and the number of processing units required to be started by the block parallel processing module and the transaction parallel processing module, the mapping relation and the topology structure of the parallel processing units and single computing devices in the computer cluster are determined by reading configuration files or using an empirical algorithm, so as to construct and manage a parallel task-processing unit mapping table of three levels of block data verification, transaction data verification and contract data verification.
In step S1, the processing procedure of the block data parallel processing module on the node data specifically includes:
S11, analyzing and checking the block data of the network data receiving and transmitting module, analyzing and checking the validity of the block header data, analyzing the contained transaction data, checking the format validity of the transaction data, and transmitting the analyzed legal transaction data to the transaction parallel processing module;
S12, receiving a processing and verifying result sent back by the transaction parallel processing module, summarizing the processing and verifying result, marking a corresponding block as legal if both the block head data and the internal block transaction are legal, and marking the corresponding block as illegal if the block head data or the internal block transaction are illegal;
And S13, if the node where the block data is located bears the block transmission task, the corresponding block marked as legal is sent to the network data receiving and transmitting module, and if the node where the block data is located bears the block production task, a legal transaction list is created, the transaction legal list is assembled into a candidate block, and the candidate block is sent to a self-built or remote mine pool.
For low-load scenarios with small amounts of transaction data, the block data parallel processing module sets the number of parallel tasks to 1, starting and using a single processing unit.
In step S1, the processing procedure of the transaction data parallel processing module on the node data specifically includes:
The method comprises the steps of firstly, receiving transaction data of a network data transceiver module, analyzing the transaction data, calculating and constructing a transaction data reduced set, wherein the transaction data reduced set comprises hash value data of contract data of an unlocking script and a locking script or derivative data of the hash value data based on the contract data of the unlocking script and the locking script, and does not contain complete contract data of the unlocking script and the locking script;
Sequentially processing transaction input data, positioning TXO of a father transaction through an output pointer, acquiring locking script contract data corresponding to the TXO, determining the position or label of a parallel processing unit of the locking script contract data based on initializing a parallel task-processing unit mapping table of a contract data verification layer constructed in a resource scheduling module, and transmitting unlocking dependent data input by the current transaction to a parallel processing unit corresponding to the contract for verification, wherein the unlocking dependent data comprises unlocking script contract data input by the current transaction and a transaction data reduced set of the current transaction;
Sequentially processing transaction output data, acquiring corresponding 'locking script' contract data and Token Value as TXO data, acquiring a hash Value of the 'locking script' contract data according to a hash function, acquiring a position or a label of a corresponding parallel processing unit based on a 'parallel task-processing unit' mapping table of a contract data verification layer constructed in an initialization and resource scheduling module, defining a dataset comprising the TXO data and a TXO pointer as 'locking data' according to the position or the label of the parallel processing unit, and transmitting the 'locking data' to the corresponding parallel processing unit of the contract data parallel processing module;
In the third step, the contract data parallel processing module and the transaction data parallel processing module use the same computer, and the processing procedure of the contract data parallel processing module for unlocking dependent data and locking data specifically comprises the following steps:
Step 3-1, receiving locking data and unlocking dependent data of a transaction data parallel processing module, and analyzing the locking data and the unlocking dependent data;
step 3-2, if the received data is the 'locking data', determining the position of a data table corresponding to the contract according to the hash value of the TXO locking script in the 'locking data', storing the TXO pointer in the 'locking data' in the data table, and marking the TXO pointer in the 'locking data' as an unexpired transaction output UTXO;
Step 3-3, if the received data is unlocking dependent data, acquiring a data table position of the UTXO corresponding to the to-be-unlocked data table, checking whether the corresponding TXO pointer is the UTXO, if the corresponding TXO pointer is the UTXO, the corresponding TXO is not spent, and if the corresponding TXO pointer is not the UTXO, the corresponding TXO is spent;
Step 3-4, if the corresponding TXO is spent, the verification is failed, and a result of the verification error is returned to the transaction parallel processing unit;
Step 3-5, if the corresponding TXO is not spent, splicing the unlocking script in the unlocking dependent data and the locking script of the corresponding contract in turn to obtain a new script, executing the new script in the contract computing virtual machine, and sending the verification result after execution back to the transaction parallel processing unit;
and 3-6, if the verification execution passes, marking a TXO pointer at a data table position corresponding to the UTXO as the spent TXO, and adding a transaction number TXID for unlocking and spending the transaction of the UTXO.
In step 3-1 to step 3-6, if the received "unlock dependent data" belongs to a transaction in the packaged block, the block height and the block hash value of the corresponding block are added to the position of the data table where the corresponding UTXO is located, and the amount of information of contract query is increased.
Checking the legal requirement of the transaction except for single transaction input, and calculating the lowest transaction fee specified by the current blockchain network consensus according to the volume and the transaction rate of the transaction data, wherein amount paid in transaction fee is higher than the lowest transaction fee;
Step five, acquiring the transaction input data processed in the step two, receiving a verification result sent back by the contract parallel processing unit, and marking the whole transaction as illegal transaction if the verification result contains 'failed';
And step six, integrating the verification results from the step one to the step five to obtain an overall validity verification result of the transaction data, and sending the overall validity verification result of the transaction data back to the block data parallel processing module.
The search service module comprises a distributed block query component, a transaction query component, a contract query component and a query forwarding component, wherein the query forwarding component provides distributed bidirectional search and query service and unified external query interface service, acquires storage positions of transaction data and contract data in equipment based on a parallel task-processing unit mapping table of a transaction data verification layer and a parallel task-processing unit mapping table of a contract data verification layer constructed in the initialization and resource scheduling module, receives a query request and forwards the query request to the transaction query component or the contract query component where the data to be queried are located.
If the "locking script" of the contract to be queried is the same, the collection and calculation of the query are completed locally.
When all the modules communicate data, infiniband or RoCE network lossless network, RDMA technology or message transfer interface technology on lossless network is used, and non-blocking sending and receiving functions are used to increase parallel processing performance between the modules.
When the transaction parallel processing unit processes each transaction output in turn, when the locking script of the processed transaction output is encoded and designed as a non-spendable transaction output, or when the transaction output of the specific type is set as non-affordable in the blockchain consensus protocol, the transaction output cannot be marked as a non-spendable transaction output UTXO, and at this time, the transaction output is not sent to the contract parallel processing unit for distributed storage.
Example 1
In this embodiment, taking a blockchain using a UTXO model as an example, a model for segmentation and distributed verification and storage of blockchain transaction data is disclosed, the embodiment does not limit the hardware type of a computer cluster, a computer based on a processor of an X86 or ARM instruction set or a hardware device designed for the scheme can be used as a device in the computer cluster, in order to reduce communication delay time and avoid packet loss possibility of network data, data communication between all modules is designed using an Infiniband-based lossless network, if other lossy networks are used, reception confirmation and packet loss detection need to be added in implementation, and when packet loss occurs, a network data transceiver module can perform retransmission and reception;
In the initialization and resource scheduling module, an MPI function library and tools are utilized to start and manage processes in a distributed manner on the computer cluster equipment, computation tasks on each process are distributed and inter-process communication is carried out, an open source library OpenMPI meeting MPI specifications is selected, and the specific initialization and resource scheduling process in the initialization and resource scheduling module is as follows:
first, a process and device mapping table text document, hots, is compiled, in which text is populated as follows:
Host1 slots=2
Host2 slots=10
Host3 slots=10
Host4 slots=10
Host5 slots=10
The Secure Shell protocol can be used on the computer device Host0 to log in Host1, host2, host3, host4 and Host5 devices, mpiexec-hostfile hosts program exec can be executed on the Host0 system terminal, at this time, a process will be started on the Host1, 10 processes are respectively started on the Host2-Host5, 42 processes are total, and meanwhile, the program exec program is run, and in the execution process of any program exec process, the number of all processes and the number of the current process can be detected by using the MPI function library, and the specific MPI function library is as follows:
MPI_Comm_size(MPI_COMM_WORLD,&procSum);
MPI_Comm_rank(MPI_COMM_WORLD,&procIndex)。
At this time procIndex stores the number of the current process, procSum stores the total number of all processes, the total number of all processes is 42,42 processes are numbered according to the node list and the number of processes in the hosts file in sequence, procIndex values are respectively 0 to 41, if the program detects that the current process number procIndex is 0, the corresponding process executes the network data transceiver module and the block data processing module, if the program detects that the current process number procIndex is 1, the corresponding process executes the bidirectional retrieval service module;
If the program detects that the current process number is greater than 1 and mod (procIndex-2, 10) belongs to {0, & gt, 3}, the corresponding program executes a transaction processing module, so that 16 processes distributed in 4 computing devices host2-host5 are respectively used as 16 transaction processing units, if the program detects that the current process number is greater than 1 and mod (procIndex-2, 10) belongs to {4, & gt, 7}, the corresponding program executes a contract processing module, so that 16 processes distributed in 4 computing devices are respectively used as 16 contract processing units, if the program detects that the current process mod (procIndex-2, 10) is 8, the corresponding program provides a transaction query service local to the device, if the program detects that the current process mod (procIndex-2, 10) is 9, the corresponding program provides a contract query service local to the device, wherein the function mod is a remainder function, and mod (A, B) represents the remainder of dividing A by B;
The distribution topological structure of the modules and the processing units is shown in figure 3;
If the program obtains a transaction data when executing the network data transceiver module or executes step S11 in the block data processing module, the corresponding program calculates a transaction identification number TXID of the transaction data, obtains a processing process number of the corresponding transaction according to the transaction identification number TXID, if the first 4bit data of the binary data of the transaction identification number TXID is taken to express 0-15 total 16 numbers, the 16 numbers respectively correspond to 16 transaction processing units, a mapping table of transaction ID-processing unit is established, the processing unit of the current transaction and the processing process number of the corresponding transaction are determined according to the mapping table of transaction ID-processing unit, and the transaction data is sent to a remote processing unit through a non-blocking MPI point-to-point process communication function, and because TXID calculation is based on a hash algorithm, the first 4bit data of TXID values has good uniformly distributed characteristics, so that the 16 transaction processing units can obtain relatively uniform processing task numbers;
The transaction parallel processing unit receives transaction data and performs examination and verification except contract script verification, and when the transaction parallel processing unit sequentially processes contract script verification of single transaction input data, unlocking dependent data is required to be sent to the contract parallel processing unit where the corresponding locking script contract is located;
As shown in the example of transaction data, the reduced transaction data set can be set as any intermediate transaction data set when hierarchical clipping is performed by using a hierarchical hash algorithm;
TABLE 1 transaction data instance examples
;
In this embodiment, all locking script data in the transaction data set is replaced by a locking script hash value, and all unlocking script data which is not currently input in the transaction data set is deleted to obtain a simplified transaction data set, and the selection mode of the simplified transaction data set is not limited, so that the data transmission amount is reduced as much as possible on the premise that the contract is verifiable;
Taking the first input of the transaction processing as an example, version number (Version), transaction freeze time (LockTime), input count (InputsCount), output count (OutputsCount), output Sequence number (Vout), sequence (Sequence), unlock script contract data (UnlockingScript), lock script contract data (LockingScript), amount (TokenValue), lock script Hash value (LockingScriptHash), lock script Hash value (LockingScriptHash) is defined as Hash (Output: lockingScript), unlock dependency data is defined as {Version,LockTime,InputsCount,OutputsCount,Input1:TXID,Input1:Vout,Input1:Sequence,Input1:UnlockingScript,Input2:TXID,Input2:Vout,Input2:Sequence,Input3…,Output1:TokenValue,Output1:LockingScriptHash,Output2:TokenValue,Output2:LockingScriptHash,Output3…};
The position of the locking script to be unlocked is positioned through an output pointer { TXID, VOUT }, wherein a mapping table of a transaction ID-processing unit which is established through a transaction identification number TXID is used, the hash value of the locking script is queried through an MPI point-to-point communication function, or the hash value of the locking script is queried firstly and obtained through hash calculation, a mapping table of the transaction ID-processing unit is established through a transaction identification number TXID, a mapping table of the locking script hash value-contract processing unit is established through the locking script hash value, the establishment modes of the mapping table of the transaction ID-processing unit and the mapping table of the locking script hash value-contract processing unit are not limited, the position starting point of 4bit data which is used can be changed, and technical advantages and application effects of the mapping table are not influenced;
According to the established mapping table of the locking script hash value and the contract processing unit, a contract parallel processing unit where a locking script contract of the UTXO to be unlocked is located is obtained, unlocking dependent data is sent to a corresponding processing process for contract verification through an MPI point-to-point communication function, meanwhile, contract verification results under corresponding transaction input numbers are obtained through the MPI point-to-point communication function, after the transaction processing unit obtains all input verification results of one transaction, the unlocking script and the locking script of the transaction data are deleted, and the hash values of the unlocking script and the locking script of the transaction data are replaced so as to relieve data storage pressure;
When the transaction parallel processing unit processes single transaction output data in turn, according to the hash value of the locking script output by the current transaction, inquiring a mapping table of the locking script hash value-contract processing unit to obtain a contract processing unit corresponding to the newly generated UTXO and a process number thereof, and sending an output pointer of the output, namely the transaction TXID number and the output serial number VOUT, and the output TokenValue and the locking script to the inquired contract parallel processing unit for processing and saving;
when the contract parallel processing unit receives a new UTXO, the UTXO is stored in a local data table, a Key (Key) in a Key value pair of stored data is a hash value of a locking script of the UTXO, the hash value is changed to be added with a spendable data bar, as shown in a UTXO information column in a contract data table, and if and only if the transaction where the UTXO is located is effectively packed into a block and has a block hash value, the block hash value is filled in a < block > -column;
If the contract parallel processing unit receives the unlocking data, positioning the data strip of the UTXO, splicing an unlocking script in the unlocking data with a locking script of the current UTXO data strip to form a complete contract unlocking instruction, taking other unlocking data as context data for instruction operation, executing the instruction, obtaining an instruction execution result as a contract verification result, and updating the UTXO data strip according to the execution result, as shown in a cost information column in a contract data table, if and only if the transaction where the unlocking data is located is effectively packed into a block and has a block hash value, filling the block hash value in a < cost block > column;
TABLE 2 contract data sheet
;
The transaction data table and the contract data table are respectively stored in four devices distributed by 16 processing units, wherein the processes of mod (procIndex-2, 10) are respectively 8 and 9, respectively process transaction inquiry service and contract inquiry service of the device, and are also distributed in the same four devices;
The specific service flow is that when the bidirectional search service module with the number of 1 receives a transaction query request, the device position of the processing unit is obtained according to TXID of the requested transaction and a transaction ID-processing unit mapping table, the process number of the transaction query service process of the same device position is obtained, the request is sent to the process number through MPI point-to-point communication, a return result is received, finally the result is returned to a requester, when the bidirectional search service module with the number of 1 receives a contract query request, the bidirectional search service module also obtains the device position of the processing unit of the locking script according to a locking script hash value-contract processing unit mapping table, the request is forwarded to the contract query service process at the device through MPI point-to-point communication, the contract query service process can process all related transactions related to the contract locally, then the complete result is returned to the bidirectional search service module, and the bidirectional search service module returns the result to the requester after receiving the return result.
In this embodiment, after the transaction parallel processing unit receives the contract verification result of the contract parallel processing unit, the locking script and the unlocking script in the transaction data stored in the transaction parallel processing unit may be replaced with hash values of the locking script and the unlocking script, and finally the transaction data stored in the transaction parallel processing unit is :{Version,LockTime,InputsCount,OutputsCount,Input1:TXID,Input1:Vout,Input1:Sequence,Hash(Input1:UnlockingScript),Input2:TXID,Input2:Vout,Input2:Sequence,Hash(Input2:UnlockingScript),Input3…,Output1:TokenValue,Hash(Output1:LockingScript),Output2:TokenValue,Hash(Output2:LockingScript),Output3…};
In this embodiment, the method for hierarchically clipping the data in the transaction is used, the transaction data reserved in the transaction parallel processing unit is used, the locking script and the unlocking script are not used, the hash value of the locking script and the hash value of the unlocking script are used for replacing, and the transaction number TXID of the transaction can be recalculated, so that the reserved transaction data has the capability of verifying the authenticity, can be identified when the reserved transaction data is wrong, the security of the data is increased, and the transaction data which can be safely verified and clipped is provided for the transaction inquiry assembly.
In this embodiment, the non-expendable transaction output may originate from a consensus protocol or from a specific Script program written, such as a Script that may be set by the consensus protocol to have a structure of "Op_Return < Other Script/Data >", a locking Script that is set by the consensus protocol to have zero TokenValue amount, written such that there is no unlock Script that can be validated (e.g., "Op_FalsOp_Return < OtherScript/Data >").
Example 2
The present embodiment is adjusted based on embodiment 1, and the present solution provides for the ability and superiority of the implementation of the migration under different transaction types or distributed topologies of different processing units.
In this embodiment, the mapping table hosts text document of the compiled process and device is as follows:
Host1 slots=1
Host2 slots=1
Host3 slots=1
Host4 slots=9
Host5 slots=9
Host6 slots=9
Host7 slots=9
Wherein the number of devices and processes in the hosts file may select other configurations.
The system of the embodiment operates in a cluster formed by 7 computers, the 7 computers respectively start 1-9 processes according to the mapping relation of the hosts document, the 39 processes are started in a distributed mode, the 39 processes are numbered 0-38 in sequence, and a network data transceiver module, a block parallel processing module, a search service module, 8 transaction parallel processing units and 1 transaction query service assembly, 8 contract parallel processing units and 1 contract query service assembly are operated in sequence;
the distribution topological structure of the modules and the processing units is shown in figure 4;
In this embodiment, the transaction parallel processing unit and the contract parallel processing unit operate in different computer devices, and at this time, the computing and communication characteristics of the different types of processing units are different, so that customized computer devices can be conveniently designed and used respectively, but the distributed data processing capability is not affected, and the application effect and advantage of the scheme are not affected.
In this embodiment, for a transaction with isolated witness area data and payment to script hash value output, such as a P2WSH transaction or a P2TR transaction, a difference implementation needs to be made between the transaction and the contract processing layer, and the specific implementation is as follows:
As shown in table 3, in a transaction with isolated witness zone data and payment to script hash value output, the present transaction is marked as an isolated witness transaction using an isolated witness tag WitnessLabel, WITNESSFLAG data generally includes two parts, marker and Flag, this type of transaction is in the input data space of the current transaction, the unlock script may be blank, and the unlock script required for contract validation is moved to the witness zone, referred to as witness zone unlock data WITNESSDATA.
TABLE 3 transaction data sheet with isolated witness zone data and Payment to script hash value output
;
In the transaction output data space, the locking script hash value LockingScriptHash is used for replacing the corresponding locking script, and the original text data of the locking script can be moved to the witness area of the child transaction ChildTX created when the UTXO is spent and is called as a witness area locking script WITNESSSCRIPT, so that the witness area of the current transaction also stores WITNESSSCRIPT data of the parent transaction UTXO of the current transaction;
In this embodiment, the transaction parallel processing unit processes each transaction output in turn, sends UTXO data of the transaction output to the corresponding contract parallel processing unit for distributed storage, first, the transaction parallel processing unit parses the transaction output to obtain LockingScriptHash of the transaction output UTXO, which is used to create a mapping table of "locking script hash value-contract processing unit", and in the process of constructing the mapping table, an integer format value of the tail end 4bit data is selected as a serial number of the contract parallel processing unit corresponding to the locking script, so that implementation benefits are not affected;
Then, the transaction parallel processing unit obtains a contract parallel processing unit corresponding to the newly generated UTXO and a process number thereof according to the mapping table of the locking script hash value and the contract processing unit, and sends an output pointer corresponding to the output, namely the transaction TXID number and the output serial number VOUT, and TokenValue of the output to a corresponding contract inquiry component for processing and storing, and the locking script original text is not transmitted at the moment because the transaction output of the embodiment has no locking script original text;
When receiving a new UTXO, the contract parallel processing unit stores the UTXO in a local data table, specifically expressed as adding a spendable UTXO data bar, the data table refers and inquires through a locking script hash value of the UTXO, as shown in a table 4:P2WSH contract data table and a table 5:P2TR contract data table, and when receiving a new UTXO, adding a row of records and filling a UTXO information column, and when a transaction where the UTXO is located is effectively packed into a block and has a block hash value, filling the block hash value in a < block > column, otherwise, leaving empty;
TABLE 4P 2WSH contract data Table
;
TABLE 5P 2TR contract data Table
;
In this embodiment, the transaction parallel processing unit processes each transaction input and the witness area data corresponding to each transaction input in turn, and first obtains the "output pointer" of the UTXO, that is TXID +vout, that is, the UTXO that the current transaction input is verifying the cost, so as to obtain LockingScriptHash of the UTXO;
For a P2WSH type transaction, lockingScriptHash is denoted as:
Input UTXO:LockingScriptHash=Hash(WitnessScript)。
LockingScriptHash defines that the unlocking script is WITNESSSCRIPT data of a witness area, lockingScriptHash and WITNESSDATA are combined and marked as WitnessTotal, and the locking script and the unlocking script which are necessary for contract verification are formed together;
thus, the "unlock dependent data" may be constructed as {Version,WitnessLabel,LockTime,InputsCount,OutputsCount,CurrentInputIndex=1,Input1:WitnessTotal,Input1:TXID,Input1:Vout,Input1:Sequence,Input2:TXID,Input2:Vout,Input2:Sequence,Input3…,Output1:TokenValue,Output1:LockingScriptHash,Output2:TokenValue,Output2:LockingScriptHash,Output3…};
Wherein CurrentInputIndex denotes the number of the transaction input currently processed, currentInputIndex may be set according to the actual situation, and CurrentInputIndex is set to 1 in this embodiment;
And finally, according to the mapping table of the locking script hash value and the contract processing unit, sending the unlocking dependent data to the corresponding contract parallel processing unit, executing the verification contract after the contract parallel processing unit receives the unlocking dependent data, sending an execution result back to the corresponding transaction parallel processing unit, and filling the spending information column after the execution is passed.
For a transaction of the P2TR type LockingScriptHash is denoted as:
input UTXO: lockingScriptHash = TAGGEDHASHTREE (WITNESSSCRIPTLEAF, WITNESSSCRIPTLEAF..) any WITNESSSCRIPTLEAF may be referred to as a valid script branch by path verification, and all valid scripts need not be revealed, so that the same LockingScriptHash may have multiple valid WITNESSSCRIPT, and a fixed unlock script cannot be determined.
When implementing distributed storage and verification for contracts in P2TR transaction, under the precondition of keeping LockingScriptHash used as hash table keywords to perform distributed contract storage, verification and query, as shown in a P2TR contract data table, common LockingScript or WITNESSSCRIPT fields are removed from the P2TR contract data table, and complete contract verification data including WITNESSDATA and WITNESSSCRIPT are used each time "unlocking dependent data" is sent;
In contrast, under other types of transactions, sharing use can be performed after first transmission and distributed storage LockingScript/WITNESSSCRIPT, so that repeated data transmission is reduced;
The other embodiments are the same as in example 1.
As described above, by the bidirectional retrieval service module, not only the service of searching for contracts through transactions, but also the service of searching for all transactions through contracts can be provided, and the unification of distributed verification and distributed query is realized by depending on the states of all UTXO data tables stored in the same device in the process of distributed unlocking and verifying contracts, so that all data for querying one UTXO contract is the same as global data for querying one contract under an account model, and only one storage position is required to be accessed.
Therefore, the invention adopts the high-performance blockchain system supporting distributed parallel processing and bidirectional retrieval, is applicable to the refined parallel processing of transaction data of the current mainstream type in the field of blockchain of UTXO model, can separate the contract data in the transaction independently, and performs distributed storage, verification and provides localized quick query service of contracts to all transaction lists, thereby realizing bidirectional retrieval or query capability from transaction to contract and contract to transaction in the aspects of blockchain point software and underlying facilities.
It should be noted that the above-mentioned embodiments are merely for illustrating the technical solution of the present invention and not for limiting the same, and although the present invention has been described in detail with reference to the preferred embodiments, it should be understood by those skilled in the art that the technical solution of the present invention may be modified or substituted by the same, and the modified or substituted technical solution may not deviate from the spirit and scope of the technical solution of the present invention.