Disclosure of Invention
Aiming at the defects existing in the prior art, the invention aims to provide a transaction verification method and system based on a blockchain.
In order to achieve the above purpose, the present invention provides the following technical solutions:
In a first aspect, a blockchain-based transaction verification method includes the steps of:
step 1, after a transaction initiator constructs a transaction and digital signature at a local client, broadcasting the transaction to a blockchain network node through a P2P network protocol;
Step 2, the block chain network node receives the broadcast transaction and stores the broadcast transaction in a local transaction pool, the broadcast transaction is verified by format, grammar and digital signature, the broadcast transaction is discarded after verification failure, and the broadcast transaction enters a subsequent flow after verification;
step 3, checking the account balance of the sender and performing double-flower check, wherein the transaction judgment is illegal or marked abnormally when the balance is insufficient or double flowers exist;
Step 4, constructing new blocks by corresponding nodes according to rules under different consensus mechanisms, verifying the new blocks and the contained transactions by the nodes of the whole network, and enabling the transactions to be effective by adding the new blocks into a main chain;
And 5, updating the account book state after confirming that the transaction effectively adds a new block, and providing an interface for conveniently inquiring transaction details and historical records.
Preferably, the step 1 includes:
the transaction initiator constructs a transaction containing the blockchain address of the sender, the blockchain address of the receiver, the transaction amount, a unique transaction identifier and optional additional information at the local client;
The initiator uses the corresponding private key to carry out digital signature on the transaction content, and processes the generated digital signature to obtain a transaction data packet;
And transmitting the digitally signed transaction data packet to a node in a blockchain network and broadcasting the transaction data packet through a P2P network protocol.
Preferably, the step 2 includes:
Nodes in the blockchain network receive the broadcasted transaction information and temporarily store the transaction information into a local transaction pool;
checking the format and grammar of the transaction to ensure that the transaction accords with the structure specified by a blockchain protocol and the type and length requirements of each field;
And verifying whether the digital signature on the transaction is correct or not by using the public key of the sender, discarding the transaction if the verification fails, and entering a subsequent verification process if the verification passes.
Preferably, the step3 includes:
Checking whether the account balance of the sender is enough to pay the transaction amount and the commission, and if the account balance is insufficient, judging that the transaction is illegal and removing;
A double-flower check is performed, whether UTXOs involved in transactions are referenced in other transactions to be confirmed or not is checked by a blockchain based on an account model, and the same funds are ensured not to participate in multiple concurrent transactions at the same time by a corresponding mechanism, so that the transactions with double-flower possibility are not further processed and marked as abnormal.
Preferably, the step4 includes:
In a blockchain adopting a workload proof consensus mechanism, a miner node selects legal transaction from a transaction pool to construct a new block, and a random number meeting a difficulty target is searched to enable a hash value of a block header to meet a condition;
After receiving the new block, the full network node again performs format and grammar check, digital signature verification and transaction validity check on all transactions contained in the new block, and verifies whether the new block meets the requirements of a common recognition mechanism or not, if so, the new block is added to a blockchain main chain, and the transactions in the new block are finally confirmed to be effective.
Preferably, the step 5 includes:
after confirming that the transaction is effective and adding the new block, updating the locally maintained account book state according to the transaction content;
a corresponding interface or tool is provided that allows users, authorities to query specific transaction details and history according to transaction identifiers, blockchain addresses.
The transaction verification system based on the blockchain comprises a transaction broadcasting module, a transaction verification module, an account and double-flower checking module, a block construction and verification module and an account book management and inquiry module;
The transaction broadcasting module is used for broadcasting the transaction to the blockchain network node through the P2P network protocol after the transaction initiator constructs the transaction and digitally signs the transaction at the local client;
The transaction verification module is used for verifying format grammar and digital signature of the transaction, and determining whether to discard the transaction or enable the transaction to enter a subsequent flow according to a verification result;
The account and double-flower checking module is used for checking the balance of the account of the sender and carrying out double-flower checking, and judging and marking the transaction with the possible double flowers or insufficient balance;
the block construction and verification module coordinates corresponding nodes to construct a new block according to different consensus mechanisms, organizes the whole network nodes to verify the new block and the contained transaction, and adds the new block into a main chain after the verification is passed;
and the account book management and query module updates the account book state after the transaction confirms that the new block is effectively added, and provides an interface to facilitate the query of transaction details and history records.
Compared with the prior art, the invention has the following beneficial effects:
1. In the invention, after the transaction is broadcasted from the initiator, the transaction is subjected to a plurality of strict verification processes such as format grammar checking, digital signature verification, account balance checking of the sender, double-flower checking and the like in sequence, and each link is subjected to corresponding treatment (such as discarding or marking abnormality) under the condition of unsatisfactory conditions, so that the possibility that the error transaction and illegal transaction enter a block chain main chain is greatly reduced, the accuracy of the finally confirmed effective transaction is improved, the legal compliance and the business logic compliance of each transaction recorded on the block chain are ensured, and the reliability of the whole transaction system is enhanced.
2. In the invention, two consensus mechanisms of PoW and PoS are adopted, and the different consensus mechanisms have advantages and application scenes, so that the PoW mechanism ensures fairness and decentralization degree of new block generation through power competition, is suitable for scenes with extremely high safety requirements and certain tolerance to resource consumption, and the PoS mechanism determines accounting rights according to rights held by nodes, is relatively more energy-saving, can ensure the safety and stability of a network to a certain extent, and is suitable for application scenes which pay attention to resource utilization efficiency. The system can select a proper consensus mechanism according to specific requirements, so that the blockchain network can stably and reliably run under different service scenes to continuously provide services for users.
3. In the invention, after confirming that the transaction is effective and adding the block, the state of the locally maintained account book can be updated in time, and a corresponding interface is provided for facilitating users, supervision authorities and the like to inquire specific transaction details and history records according to the transaction identifier, the blockchain address and other information. The system has the advantages that each transaction has clear records on the blockchain, can be traced and checked at any time just like a traditional account book, can conveniently acquire required transaction information no matter whether a common user checks own transaction conditions or a supervision organization carries out auditing, investigation and other works, ensures transparency and traceability of the blockchain transaction, is beneficial to enhancing trust of each party to the blockchain system, and meets the requirements of compliance supervision.
4. In the invention, the whole blockchain network is based on the distributed account book technology, transaction information is difficult to tamper once being verified and added to a main chain, all nodes keep the same account book copy, and account book content is public and transparent (although privacy-related parts such as private keys and the like are secret, key information of the transaction itself is searchable). The characteristics enable all parties participating in the transaction and external supervisors to trust the authenticity and the integrity of the transaction records, promote the application and popularization of the blockchain in more fields (such as supply chain finance, traceability systems and the like), and lay a foundation for constructing a trust ecological system based on the blockchain.
Detailed Description
The embodiment further describes a transaction verification method and a transaction verification system based on the blockchain.
Referring to fig. 1, a blockchain-based transaction verification method includes the steps of:
step 1, after a transaction initiator constructs a transaction and digital signature at a local client, broadcasting the transaction to a blockchain network node through a P2P network protocol;
Step 2, the block chain network node receives the broadcast transaction and stores the broadcast transaction in a local transaction pool, the broadcast transaction is verified by format, grammar and digital signature, the broadcast transaction is discarded after verification failure, and the broadcast transaction enters a subsequent flow after verification;
step 3, checking the account balance of the sender and performing double-flower check, wherein the transaction judgment is illegal or marked abnormally when the balance is insufficient or double flowers exist;
Step 4, constructing new blocks by corresponding nodes according to rules under different consensus mechanisms, verifying the new blocks and the contained transactions by the nodes of the whole network, and enabling the transactions to be effective by adding the new blocks into a main chain;
And 5, updating the account book state after confirming that the transaction effectively adds a new block, and providing an interface for conveniently inquiring transaction details and historical records.
The step 1 comprises the following steps:
the transaction initiator constructs a transaction containing the blockchain address of the sender, the blockchain address of the receiver, the transaction amount, a unique transaction identifier and optional additional information at the local client;
the unique transaction identifier is generated, and in the field of blockchain, an SHA-256 hash algorithm is often adopted to operate, wherein the SHA-256 can process input data with any length and then output the processed input data to be fixed into a hash value with 256 bits (32 bytes), and the hash value is usually displayed in a hexadecimal character string form;
The transaction key information is selected as input data, including the address of a sender, the address of a receiver, the transaction amount and a time stamp, and the information is spliced together in sequence to form a data string which is used as input to be sent into an SHA-256 hash algorithm for hash operation;
Firstly, filling input data to enable the length of the input data to meet a specific multiple of algorithm requirements (SHA-256 requires that the remainder of the input data after the length is modulo 512 bits is 448 bits, and if the input data is insufficient, the input data is complemented by a specific filling rule);
Setting an initial hash value (also called an intermediate state value, there are 8 initial intermediate state values of 32 bits in SHA-256, which are fixed constants for starting the entire operation);
For each divided 512-bit data block, performing operation on the current data block and the current intermediate state value by a series of complex logic functions (including nonlinear functions formed by combining logic operations such as AND, OR, NOT, XOR and the like and arithmetic operations such as displacement, addition and the like, wherein Ch (x, y, z) = (x & y) (-x) and z) are part of function examples, and not expanding all functions in detail;
After the iterative compression operation, the final obtained 8 intermediate state values of 32 bits are combined to be 256-bit hash values, and the 256-bit hash values are converted into hexadecimal character strings, so that the transaction identifier which is wanted by people is obtained.
The initiator uses the corresponding private key to carry out digital signature on the transaction content, and processes the generated digital signature to obtain a transaction data packet;
based on an ECDSA algorithm, carrying out digital signature by adopting secp k1 elliptic curve digital signature algorithm, and generating a group of temporary public key and private key pairs;
Before the actual signature operation is performed, the whole transaction content needs to be hashed, and a hash value with a fixed length is generated by adopting an SHA-256 hash algorithm, for example, assuming that a data string of the transaction content after being tidied is TransactionData, the hash value obtained by carrying out the hash operation by adopting the SHA-256 algorithm is recorded as HashValue, namely HashValue =SHA-256 (TransactionData);
The obtained private key may exist in the form of character string or byte array, etc., but in the mathematical operation of ECDSA algorithm, it needs to be converted into integer form meeting the requirements of elliptic curve cryptography operation;
The digital signature operation process comprises the steps of firstly, selecting a random number k, performing point multiplication operation through a base point of an elliptic curve to obtain a point P on the elliptic curve, wherein the abscissa value of the point P is the value of r, namely P=k×G, wherein G is the base point of the elliptic curve, and the point multiplication operation is represented by the G;
Then, according to the private key d, the random number k, the hash value HashValue and the r value obtained above, s values are obtained through formula calculation, wherein s=k (1) (HashValue +d (r)) mod n, k (1) represents the multiplication inverse element of k under the mode n, n is the order of elliptic curve, and mod represents the modulo operation;
the final digital signature is an ordered pair consisting of two integers, r and s, and is marked as (r, s);
the generated digital signature (r, s) is appended to the original transaction information in accordance with the format and requirements specified by the blockchain system to form a complete transaction data packet with the digital signature.
And transmitting the digitally signed transaction data packet to a node in a blockchain network and broadcasting the transaction data packet through a P2P network protocol.
The step2 includes:
Nodes in the blockchain network receive the broadcasted transaction information and temporarily store the transaction information into a local transaction pool;
checking the format and grammar of the transaction to ensure that the transaction accords with the structure specified by a blockchain protocol and the type and length requirements of each field;
the format and grammar checking of the transaction includes checking structural integrity, verifying field type requirements, verifying field length limitations;
The checking structure integrity completely comprises the structural parts of transaction version number, input list, output list and locking time, and the arrangement sequence of the parts strictly meets the requirements.
The verification of each field type requirement comprises transaction version number type checking, input list and sub-field type checking, output list and sub-field type checking and locking time type checking;
The transaction version number type is checked, and the transaction version number is specified as an integer type, and specifically can be in different formats (block chain-dependent) such as 32-bit unsigned integers;
The input list and the sub-field type check comprise a preamble transaction hash type check and an output index type, wherein the preamble transaction hash type is generally a byte array type, the byte length needs to meet the standard length generated by a specific hash algorithm (for example, the hash value generated by adopting an SHA-256 hash algorithm should be 32 bytes), whether the input list and the sub-field type check are stored in the form of a byte array or not and whether the actual length is consistent with the specified length or not is checked, the output index type is an integer type and is used for positioning a specific position in the preamble transaction output, whether the output index can be used as an integer to participate in operation or not is checked, whether the definition range (for example, the value range is between 0 and a certain positive integer) of the integer type of the block chain is met or not is checked, if the definition range is not met, errors occur when the specific output corresponding to the fund source is searched later, and the transaction grammar is incorrect;
The output list and subfield type check comprises a receiver blockchain address type check and a transfer amount type check, wherein the receiver blockchain address type check needs to be a character string type conforming to a blockchain specific coding rule, and when checking, whether the format of the character string is correct, whether the characters are in compliance, whether the length is in a specified range and the like is checked according to the address generation rule of the corresponding blockchain;
The lock time type check, if there is a lock time field, should be generally of integer type and have a value range and meaning (for example, representing a certain time stamp or time interval, etc.) specified by the corresponding blockchain protocol, check whether it accords with the characteristics of an integer and is within the specified value range, if the type is not right or out of range, it does not accord with the requirement of transaction grammar, because the limitation condition on the effective time of the transaction cannot be correctly reflected.
The length limit of each field comprises transaction identifier length verification and blockchain address length verification, wherein the transaction identifier length verification is generated by carrying out hash operation on transaction key information, whether the actual transaction identifier length is strictly equal to the specified byte number or not is checked, if the actual transaction identifier length is inconsistent, the blockchain address length verification is carried out, the addresses of different blockchains have respective specified length ranges, whether the lengths of the addresses of a receiver and a sender are consistent or not is verified according to corresponding standards, for example, the specified address length of a blockchain is minimum to be L_min and maximum to be L_max, the actual address length is marked as 1_address, the transaction identifier is judged by comparing the size relation of 1_address with L_min and L_max, and if the actual transaction identifier length is inconsistent or 1_address is inconsistent, the address length of the blockchain is judged to be inconsistent, and further the address which is inconsistent with the address which is not consistent with the length requirement is further indicated to be unable to be identified and processed in the blockchain network.
Verifying whether the digital signature on the transaction is correct or not by using the public key of the sender, discarding the transaction if the verification fails, and entering a subsequent verification process if the verification passes;
obtaining a sender public key, and marking the sender public key as a publicKey;
the node needs to accurately extract the corresponding representation forms of r and s from the transaction data according to the specific field positions specified by the blockchain protocol;
the verification logic based on the ECDSA algorithm specifically comprises the following steps:
Firstly, extracting all complete contents except a digital signature in transaction information, and then carrying out hash operation on the contents by using an SHA-256 hash algorithm to obtain a hash value with a fixed length, wherein the hash value is recorded as HashValue;
According to the mathematical principle of ECDSA algorithm, using the obtained public key publicKey of sender, the r and s values in the extracted digital signature and HashValue obtained by calculation to make verification operation,
The public key (public key) is converted into a corresponding point coordinate representation (assumed to be (x_public, y_public)) on an elliptic curve, then, the coordinate of a point Q is calculated according to an ECDSA algorithm, the base point of the elliptic curve is set as G, the order of the elliptic curve is n, the multiplication inverse element of s under the mode n is calculated first and is marked as s_index, the calculation principle is that an integer is found so that s is s_index identical to 1 (modn) (namely, the remainder of the product of s and s_index divided by n is 1, which is the definition of the mode multiplication inverse element is taken in the numerical theory), and then, the values of the abscissa Q_x and the ordinate Q_y of the point Q are calculated according to the following calculation formula:
Q_x=(s_inverse*HashValue*G.x+r*x_public)modn
Q_y=(s_inverse*HashValue*G.y+r*y_public)modn
Wherein, G.x and G.y respectively represent the abscissa and the ordinate of the base point G, and x_public and y_public are the point coordinates corresponding to the public key;
Finally, the key of verification is to determine whether the abscissa of the point Q (i.e., q_x) is equal to the r value in the digital signature after being converted into a suitable integer form, where the verification logic can be simply expressed as if q_x=r (where the values on both sides are required to be compared under the same integer representation and operation rule to ensure the accuracy of the comparison), it is explained that the digital signature verification passes, which means that the transaction is indeed initiated by the sender having the corresponding private key and the transaction content is not tampered with during the transmission process, otherwise, if q_x+.r, the digital signature verification fails, the node directly discards the transaction and does not further process it, because the validity and authenticity of the transaction cannot be guaranteed.
The step 3 includes:
Checking whether the account balance of the sender is enough to pay the transaction amount and the commission, and if the account balance is insufficient, judging that the transaction is illegal and removing;
A transmitter is determined by adopting a UTXO set firstly based on a blockchain of a UTXO (non-spent transaction output) model, and then the available balance is calculated and compared with the transaction amount and the commission;
The method adopts UTXO set to determine the sender, specifically comprises the following steps:
Traversing the blockchain historical transaction records, namely, the nodes need to access locally stored blockchain data, sequentially check each transaction information according to the sequence of transactions, and screen out the transaction records related to the sender blockchain address;
The method comprises the steps of screening the non-spent transaction output, namely checking a transaction output part of each found transaction related to a sender, wherein each transaction can have a plurality of outputs, each output has a corresponding state identifier, selecting the transaction output with the state identifier of 'non-spent', namely the UTXO currently available to the sender, and finding 'money bags' which are not used by the sender in a plurality of past transactions.
The calculation of the available balance is specifically as follows:
Extracting the amount of each UTXO, namely extracting a field value representing the amount from each record in the available UTXO set screened in the previous step, wherein the amount of each UTXO is a specific digital currency amount, the amounts of different UTXOs possibly differ, and the different UTXOs together form funds which can be governed by a sender;
Accumulating the sum to obtain the Total available Balance, namely accumulating and summing the sum of all available UTXOs to obtain the current Total available Balance of the sender, and assuming that the available UTXO Set is UTXO_set= { UTXO 1,UTXO2,…,UTXOn }, each UTXO i has a corresponding sum amount i, then the Total available Balance total_balance is calculated as follows: For example, the sender has 3 available UTXOs, and the amount is 5 digital currency units, 3 digital currency units, and 2 digital currency units, respectively, and the total available balance is 5+3+2=10 digital currency units by accumulation.
The comparison with the transaction amount and the commission fee is specifically as follows:
Acquiring the Transaction Cost, namely acquiring the Amount to be paid by the Transaction (namely, transaction Amount, which is set as transaction_amount) and the Transaction handling Fee (which is set as Fee), and adding the two to obtain the Total Cost of the Transaction, namely, total_cost=transaction_amountFee;
The balance comparison judgment is carried out, namely the calculated Total available balance (total_balance) of the sender is compared with the Total Cost (total_cost) of the transaction, if the total_balance is more than or equal to total_cost, the fact that the money of the sender is enough to pay the transaction can enter a subsequent verification flow is indicated, otherwise, if the total_balance is less than total_cost and means that the transaction cannot be completed, the transaction is judged to be an illegal transaction, the node can remove the transaction from a local transaction pool, the transaction is prevented from being transmitted and participating in subsequent processing in a blockchain network, for example, if the Total available balance is 7 digital currency units and the Total Cost of the transaction is 9 digital currency units, the transaction is judged to be illegal and the transaction is removed.
The blockchain based on the account model firstly inquires the account balance record of the sender and then compares the account balance record with the transaction amount and the commission fee;
The sender Account balance record is queried, namely, the node searches the balance according to the address, namely, the node rapidly locates and acquires the corresponding Account balance value (set as Account_balance) by taking the blockchain address of the sender as an index (similar to searching the bank Account balance by an Account number) in a locally maintained Account balance data storage (possibly based on a database management system or a specific key value pair storage structure and the like).
The comparison with the transaction amount and the commission fee is specifically as follows:
The Transaction Cost is obtained by firstly obtaining the Amount (transaction_amountto) to be paid by the Transaction and the set Transaction commission (Fee), and calculating the Total Cost total_cost=transaction_amountFee of the Transaction, for example, the Transaction Amount is 30 digital currency units, the commission is 2 digital currency units, and then the Total cost_cost=30+2=32 digital currency units;
The balance comparison and judgment is carried out, wherein the acquired Account balance (Account_balance) of the sender is compared with the Total Cost (total_cost) of the transaction, if the Account balance is more than or equal to the total_cost, the fact that the money in the Account of the sender can pay the transaction is indicated, the transaction is legal, the subsequent verification process can be continued, if the Account balance is less than the total_cost, the fact that the transaction is illegal is judged, the node can remove the transaction from the transaction pool, for example, if the Account balance is 25 digital currency units and the Total Cost of the transaction is 32 digital currency units, the transaction is judged to be illegal and the transaction is removed.
Performing double-flower checking, checking whether UTXOs involved in transactions are referenced in other transactions to be confirmed or not according to a blockchain based on the UTXO, ensuring that the same funds cannot participate in multiple concurrent transactions at the same time through a corresponding mechanism according to the blockchain based on an account model, and enabling the transactions with double-flower possibility to be not further processed and marked as abnormal;
The blockchain based on the UTXO model firstly collects input UTXO information of the transaction to be verified, then checks the quotation condition of the UTXO in the transaction to be confirmed, and if the transaction passes the double-flower check, updates the local UTXO quotation state record;
In UTXO model, the input of the Transaction points to the UTXO generated by some previous transactions, each input contains two key information, namely the Hash value (Transaction Hash) of the previous Transaction and the Output Index (Output Index) in the previous Transaction, for example, one Transaction input may be expressed as (TxHash, 0), meaning that it points to the 0 th Output in the previous Transaction with the Hash value of TxHash;
the node extracts utxoid information (i.e., a combination of the transaction hash value and the output index) related to all inputs of the transaction to be validated, forms a list, and prepares to subsequently check whether the UTXOs have been referenced in other transactions to be validated.
The node maintains a local data structure (which may be in the form of a mapping table, a database table, etc. in a memory) for recording the usage of all input UTXOs of the transactions to be confirmed in the current network, wherein the key of the data structure may be set as the identification of the UTXO (i.e. the combination string of the hash value of the transaction and the output index, such as "TxHash123 _0"), the value is a boolean type, and indicates whether the UTXO has been referenced by a certain transaction to be confirmed (e.g. True indicates that the UTXO has been referenced, false indicates that the UTXO has not been referenced);
for each UTXO identification of the transaction to be validated collected in the previous step, the node queries in a locally maintained data structure.
And at the moment, the node needs to update a UTXO reference state record data structure maintained locally, marks the reference states corresponding to all UTXO identifiers related to the transaction as referenced (namely set as True), and indicates that the UTXOs are participating in the current transaction to be verified, so that the problem that the subsequent other transactions repeatedly reference the UTXOs to cause double flowers is avoided.
Firstly extracting a serial number of a transaction to be verified based on a blockchain of an account model, then inquiring a maximum serial number of the confirmed transaction of the same account, and finally checking a serial number sequence and double-flower conditions;
The method comprises the steps of extracting a serial Number of a transaction to be verified, extracting a serial Number field value of the transaction from received transaction data to be verified by a node, wherein in a blockchain based on an account model and adopting a serial Number mechanism, each transaction is attached with a serial Number, usually an integer, and the serial Number of a new transaction is required to be larger than the maximum serial Number in confirmed transactions of the same account, so that the transaction Sequence is ensured and the double-flower problem is avoided.
The node screens all Confirmed transaction records of the account in a locally stored transaction record data structure (such as a database table, a transaction list in a memory and the like) according to the address of a sender account of the transaction to be verified, and then searches the maximum value of a serial Number field from the Confirmed transaction records, wherein the maximum value is the maximum serial Number (set as Max_confirmed_sequence_number) of the Confirmed transaction of the account.
The Sequence Number Sequence and double-flower condition are checked, the Sequence Number (set as sequence_number) of the transaction to be verified is compared with the maximum Confirmed Sequence Number (Max_confirmed_sequence_number) obtained by inquiry, and under normal conditions, the sequence_number > Max_confirmed_sequence_number should be satisfied, which means that the transaction is a new transaction initiated in Sequence;
Meanwhile, the node also checks the account balance change condition related to the transaction (for example, checks whether the locally recorded account balance has been deducted for the same amount in other unacknowledged transactions, if the repeated deduction condition exists, it may suggest that a double-flower attempt exists), if the sequence_number < = max_confirmed_sequence_number occurs and an abnormal condition such as repeated deduction exists in the account balance is found, it means that a double-flower problem may exist, and the node marks the transaction to be verified as abnormal and does not process the transaction.
The step 4 includes:
In a block chain adopting a work load proof (PoW) consensus mechanism, a miner node selects legal transaction from a transaction pool to construct a new block, a random number meeting a difficulty target is searched to enable a hash value of a block head to meet a condition, and under the work load proof (PoS) consensus mechanism, a verification node meeting corresponding conditions is responsible for selecting the transaction to construct the new block and meets the requirement of a consensus rule.
After receiving the new block, the full network node again performs format and grammar check, digital signature verification and transaction validity check on all transactions contained in the new block, and verifies whether the new block meets the requirements of a common recognition mechanism or not, if so, the new block is added to a blockchain main chain, and the transactions in the new block are finally confirmed to be effective.
The searching of the random number (mining process) meeting the difficulty target is specifically as follows:
Carrying out primary hash operation, namely taking assembled new block header information (all field values except random numbers are determined) as input by miners, and carrying out hash operation by using an SHA-256 hash algorithm to obtain an initial block header hash value;
Comparing the obtained hash value with the difficulty target set by the current network, taking a bit coin as an example, representing the difficulty target as a specific numerical value, judging whether the hash value meets the requirement by comparing the size relation between the hash value converted into the numerical value and the difficulty target numerical value, the number of the continuous 0 in the binary representation of the hash value and other conditions, and if the hash value does not meet the difficulty target (for example, the first several digits of the hash value are 0, but the corresponding position in front of the actually calculated hash value is not 0), continuously adjusting the random number;
The random number is regulated and hash operation is repeated, namely the value of the random number is increased by 1 each time (other reasonable increasing strategies can be adopted), then the hash operation is carried out on the block head information containing the new random number again to obtain a new hash value again, the comparison with a difficulty target is continued, the process is repeated continuously, and due to the randomness and the irreversibility of the hash operation, miners need to try a large number of different random number values until a random number is found, so that the calculated block head hash value meets the difficulty target set by a network.
The step 5 includes:
after confirming that the transaction is effective and adding the new block, updating the locally maintained account book state according to the transaction content;
a corresponding interface or tool is provided that allows users, authorities to query specific transaction details and history according to transaction identifiers, blockchain addresses.
Referring to fig. 2, a blockchain-based transaction verification system includes a transaction broadcasting module, a transaction verification module, an account and double-flower checking module, a block construction and verification module, and an account book management and inquiry module;
The transaction broadcasting module is used for broadcasting the transaction to the blockchain network node through the P2P network protocol after the transaction initiator constructs the transaction and digitally signs the transaction at the local client;
The transaction verification module is used for verifying format grammar and digital signature of the transaction, and determining whether to discard the transaction or enable the transaction to enter a subsequent flow according to a verification result;
The account and double-flower checking module is used for checking the balance of the account of the sender and carrying out double-flower checking, and judging and marking the transaction with the possible double flowers or insufficient balance;
the block construction and verification module coordinates corresponding nodes to construct a new block according to different consensus mechanisms, organizes the whole network nodes to verify the new block and the contained transaction, and adds the new block into a main chain after the verification is passed;
and the account book management and query module updates the account book state after the transaction confirms that the new block is effectively added, and provides an interface to facilitate the query of transaction details and history records.
The above description is only a preferred embodiment of the present invention, and the protection scope of the present invention is not limited to the above examples, and all technical solutions belonging to the concept of the present invention belong to the protection scope of the present invention. It should be noted that modifications and adaptations to the present invention may occur to one skilled in the art without departing from the principles of the present invention and are intended to be within the scope of the present invention.