A blockchain transaction management method, device, equipment and storage medium
By performing consensus judgment and SQL statement execution on the blocks to be traded in blockchain transactions, the problem of low efficiency in blockchain transactions is solved, and efficient processing of high-frequency transactions is achieved.
Patent Information
- Application Number
- CN202210026634.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-11
- Publication Date
- 2026-02-24
- Estimated Expiration
- 2042-01-11
AI Technical Summary
Existing blockchain asset transactions suffer from low read efficiency due to excessive I/O operations, failing to meet the demands of high-frequency trading.
By obtaining transaction information from blocks to be traded, consensus judgment is made on the transaction, which is then translated into SQL statements and executed in a relational database. The balances of the asset remittance and remittance accounts are queried, and the transaction is written to the block data table after confirming that there are no negative values.
It improved data reading efficiency and enhanced the efficiency of high-frequency trading.
Smart Images

Figure CN114356950B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of blockchain, and in particular to a blockchain transaction management method, apparatus, device, and storage medium. Background Technology
[0002] Currently, blockchain technology is widely used in asset scenarios such as cross-border asset transactions and securitized asset trading and transfer.
[0003] Existing blockchain asset transactions often rely on smart contracts. For example, in Ethereum, the tree is quite tall, and searching each level requires reading nodes from LevelDB, increasing the number of I / O operations and significantly reducing read efficiency. This impacts contract execution speed, resulting in low execution efficiency that cannot meet the demands of high-frequency asset trading. Improving the efficiency of high-frequency asset trading is a key concern. Summary of the Invention
[0004] In view of this, this application provides a blockchain transaction management method, apparatus, device and storage medium to improve the efficiency of high-frequency asset trading.
[0005] To achieve the above objectives, the following solution is proposed:
[0006] A blockchain transaction management method, comprising:
[0007] Obtain transaction information of the broadcast block to be traded, the transaction information including block data to be traded, asset outflow account, asset inflow account, and asset amount;
[0008] A consensus judgment operation is performed on the block to be traded to determine whether the block to be traded is a correct block;
[0009] If so, the transaction information is translated into a first SQL statement deducting from the account corresponding to the asset remittance account and a second SQL statement adding to the account corresponding to the asset remittance account;
[0010] The first SQL statement is used to query the current balance of the asset remittance account in the asset data table of the relational database, calculate the balance after deducting the asset quota, and write the balance after deducting the asset quota into the asset remittance account as the latest balance of the asset remittance account. The second SQL statement is used to query the current balance of the asset remittance account in the asset data table of the relational database, calculate the balance after increasing the asset quota, and write the balance after increasing the asset quota into the asset remittance account as the latest balance of the asset remittance account.
[0011] In the asset data table of the relational database, the first SQL statement and the second SQL statement are executed to obtain the execution results, which include the latest balance of the asset remittance account and the latest balance of the asset remittance account.
[0012] Check if the execution result has a negative value. If it does, restore the asset data table in the relational database to the data before the execution of the SQL statement set.
[0013] If no negative value exists, the transaction data of the pending block is written into the block data table of the relational database, and a commit operation is performed to complete the transaction.
[0014] Optionally, a consensus judgment operation is performed on the pending blocks in the pending block information to determine whether the pending blocks are correct blocks, including:
[0015] Determine the height and prevHash value of the block to be traded;
[0016] Query the block data table of the relational database and select the block with the highest current height as the first block;
[0017] Determine whether the height of the first block is equal to the height of the block to be traded minus 1;
[0018] If so, then further query whether the block hash value of the first block in the block data table of the relational database is equal to the prevHash value of the block to be traded;
[0019] If so, then the block data to be traded is determined to be correct block data.
[0020] Optional, also includes:
[0021] Obtain the seller's public key signature corresponding to the block to be traded;
[0022] After determining that the block to be traded is a correct block, the seller's public key is used to sign and verify whether the transaction information is legal. If it is legal, the steps of translating the transaction information into a first SQL statement that deducts from the account corresponding to the asset remittance account and a second SQL statement that adds to the account corresponding to the asset remittance account are executed.
[0023] Optionally, the transaction information further includes the asset category, and the step of verifying the legality of the transaction information using the seller's public key signature includes:
[0024] The hash function is used to calculate the outgoing account, incoming account, asset amount, and asset category of the asset, and obtain the hash value.
[0025] The seller's public key signature is decrypted using a decryption function to obtain the decryption result;
[0026] Determine whether the hash value matches the decryption result. If they match, the result is valid; otherwise, send a prompt message.
[0027] Optionally, after determining whether the height of the first block is equal to the height of the block to be transacted minus 1, the method further includes:
[0028] If the height of the first block is not equal to the height of the block to be traded minus 1, then the existence of the block to be traded is determined by querying the block data table of the relational database.
[0029] If it exists, discard the block to be traded and send a notification message;
[0030] If it does not exist, the consensus algorithm is used to determine the processing method for the block to be traded. The processing method includes discarding the block, temporarily storing the block, and performing a rollback operation.
[0031] Optionally, the rollback operation includes:
[0032] In the block data table of the relational database, the first block is rolled back to the second block, and the first block is deleted. The second block is the block with the current highest height minus 1 in the block data table.
[0033] In the asset data table of the relational database, delete the execution result of the SQL statement corresponding to the first block;
[0034] The second block is used as the new first block, and the process returns to the step of determining whether the height of the first block is equal to the height of the block to be traded minus 1.
[0035] A blockchain transaction management device, comprising:
[0036] The information acquisition unit is used to acquire the transaction information of the broadcast block to be traded, the transaction information including the block data to be traded, the asset remittance account, the asset remittance account, and the asset amount;
[0037] The consensus judgment unit is used to perform a consensus judgment operation on the block to be traded to determine whether the block to be traded is a correct block;
[0038] The information translation unit is used to translate the transaction information into a first SQL statement deducting from the account corresponding to the asset remittance account and a second SQL statement adding to the account corresponding to the asset remittance account when the block to be traded is a correct block.
[0039] The first SQL statement is used to query the current balance of the asset remittance account in the asset data table of the relational database, calculate the balance after deducting the asset quota, and write the balance after deducting the asset quota into the asset remittance account as the latest balance of the asset remittance account. The second SQL statement is used to query the current balance of the asset remittance account in the asset data table of the relational database, calculate the balance after increasing the asset quota, and write the balance after increasing the asset quota into the asset remittance account as the latest balance of the asset remittance account.
[0040] The statement execution unit is used to execute the first SQL statement and the second SQL statement in the asset data table of the relational database and obtain the execution result, which includes the latest balance of the asset remittance account and the latest balance of the asset remittance account.
[0041] The result query unit is used to query whether there is a negative value in the execution result. If there is, the asset data table in the relational database is restored to the data before the execution of the SQL statement set.
[0042] The data writing unit is used to write the transaction-pending block data into the block data table of the relational database when the execution result does not have a negative value, and to perform a commit operation to complete the transaction.
[0043] Optionally, the consensus determination unit includes:
[0044] The first consensus judgment subunit is used to determine the height and prevHash value of the block to be traded.
[0045] The second consensus judgment subunit is used to query the block data table of the relational database and select the block with the highest current height as the first block;
[0046] The third consensus judgment subunit is used to determine whether the height of the first block is equal to the height of the block to be traded minus 1. If so, it further queries whether the block hash value of the first block in the block data table of the relational database is equal to the prevHash value of the block to be traded. If so, it determines that the block data to be traded is correct block data.
[0047] A blockchain transaction management device, comprising a memory and a processor;
[0048] The memory is used to store programs;
[0049] The processor is used to execute the program and implement each step of the aforementioned blockchain transaction management method.
[0050] A readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the various steps of the aforementioned blockchain transaction management method.
[0051] As can be seen from the above technical solution, this application obtains the transaction information of the block to be traded, performs consensus judgment on the block to be traded, determines that the block to be traded is a correct block, translates the transaction information into a first SQL statement and a second SQL statement, executes the statements, obtains the execution result, checks whether the execution result has a negative value, if it does, the asset data table is restored to the data before the execution of the SQL statement set, if it does not, the data of the block to be traded after the transaction is written into the block data table of the relational database, and the transaction is completed by executing the commit operation. This solution improves the data reading efficiency by translating the obtained transaction information into SQL statements and executing the SQL statements in the asset data table of the relational database to obtain the transaction execution result, compared with the existing technology of reading asset data one by one. This application improves the efficiency of high-frequency trading by processing asset data through a relational asset data table. Attached Figure Description
[0052] Figure 1 A schematic diagram of a relational blockchain state storage architecture based on blocks and asset data tables is provided for embodiments of this application;
[0053] Figure 2 A flowchart of a blockchain transaction management method provided in this application embodiment;
[0054] Figure 3 This is a schematic diagram of the structure of a blockchain transaction management device provided in an embodiment of this application;
[0055] Figure 4 This is a hardware structure block diagram of a blockchain transaction device provided in an embodiment of this application. Detailed Implementation
[0056] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0057] To better understand this solution, this application provides a schematic diagram of a relational blockchain state storage architecture based on blocks and asset data tables, such as... Figure 1As shown, the system mainly consists of a new block module, an accounting program module, and a relational database module. The new block module is used by nodes in the blockchain network to generate new blocks, which can be packaged by local nodes or by other nodes. The accounting program module serves as the main program for asset accounting through blockchain consensus and execution. The relational database module can be used as a standalone relational database, such as a single-machine relational database, a distributed relational database, or a cloud-native relational database. It only needs to provide a query interface to the accounting program. The relational database includes a block data table and an asset data table. The block data table is a relational data table used to store block data, where each row can include information such as the block height, the block packager (singer), and the serialization encoding result (txs) of the included asset transactions. The asset data table is a relational data table storing the asset details of each user, where each row can include the user's unique identifier (user), asset type (asset), the user's asset balance (balance), and the height of the last updated block. The accounting program module can receive new blocks generated by the new block module and send consensus judgment instructions to the relational database module. After that, it judges the new blocks and sends execution or rollback instructions to the relational database module. Users can also send business query instructions to the asset data table to query related businesses.
[0058] Figure 2 A flowchart of a blockchain transaction management method provided in this application embodiment is included, which may include the following steps:
[0059] Step S100: Obtain transaction information of the broadcast block to be traded.
[0060] Specifically, transaction information can include data of blocks to be traded, asset outflow accounts, asset inflow accounts, and asset amounts. It can also obtain transaction information of blocks to be traded broadcast by a certain ledger node in an asset-based blockchain network.
[0061] Step S110: Perform a consensus judgment operation on the block to be traded to determine whether the block to be traded is a correct block. If so, proceed to step S120.
[0062] Specifically, due to the decentralized design of blockchain, the nodes are distributed and parallel, so consensus judgment is necessary to maintain the operating order and fairness of the system. Consensus judgment can be performed on the block to be traded to determine whether the block to be traded is a correct block. If it is, then step S120 can be executed.
[0063] Step S120: Translate the transaction information into a first SQL statement deducting from the account corresponding to the asset remittance account and a second SQL statement adding to the account corresponding to the asset remittance account.
[0064] Specifically, the first SQL statement can be used to query the current balance of the asset remittance account in the relational database's asset data table, calculate the balance after deducting the asset limit, and write the balance after deducting the asset limit into the asset remittance account as its latest balance. The second SQL statement can be used to query the current balance of the asset inflow account in the relational database's asset data table, calculate the balance after increasing the asset limit, and write the balance after increasing the asset limit into the asset inflow account as its latest balance. Once it is determined that the block to be traded is a correct block, the transaction information can be translated into the first SQL statement deducting from the account corresponding to the asset remittance account and the second SQL statement increasing the account corresponding to the asset inflow account. The asset data table can be a relational data table storing the asset details of each user, where each row can include the user's unique identifier, asset category, asset balance, latest block height, etc., and can be designed according to requirements. The translation is shown below:
[0065] SQL1='SELECT balance INTO@bl FROM AssetTable WHERE user=from,asset=asset ORDER BY height DESC LIMIT=1;
[0066] INSERT from,asset,@bl-value,height INTO AssetTable'
[0067] SQL2='SELECT balance INTO@bl FROM AssetTable WHERE user=to,asset=asset ORDER BY height DESC LIMIT=1;
[0068] INSERT to,asset,@bl+value,height INTO AssetTable'
[0069] In this context, "from" represents the account from which the asset is transferred, "to" represents the account from which the asset is transferred, "asset" represents the asset category, "value" represents the asset amount, "sql1" represents the first SQL statement, and "sql2" represents the second SQL statement.
[0070] Step S130: Execute the first SQL statement and the second SQL statement in the asset data table of the relational database to obtain the execution result.
[0071] Specifically, the execution results can include the latest balance of the asset remittance account and the latest balance of the asset remittance account. In the asset data table of the relational database, the first SQL statement and the second SQL statement can be executed. That is, query the current balance of the asset remittance account, calculate the balance after deducting the asset quota, and write the balance after deducting the asset quota into the asset remittance account as the latest balance of the asset remittance account. The second SQL statement can be executed, query the current balance of the asset remittance account, calculate the balance after adding the asset quota, and write the balance after adding the asset quota into the asset remittance account as the latest balance of the asset remittance account. The execution results of obtaining the latest balance of the asset remittance account and the latest balance of the asset remittance account are obtained.
[0072] Step S140: Check if the execution result has a negative value. If it does, proceed to step S150; otherwise, proceed to step S160.
[0073] Specifically, the QUERY function can be used to check if the execution result has a negative value. If it does, step S150 can be executed; otherwise, step S160 can be executed.
[0074] Step S150: Restore the asset data table in the relational database to the data before the execution of the SQL statement set.
[0075] Specifically, when the execution result is negative, the asset data table in the relational database can be restored to the data before the execution of the SQL statement set, that is, the current transaction is canceled. The query statement is as follows:
[0076] Nagative=QUERY(SELECT count(*)FROM AssetTable WHERE balance<0)
[0077] Here, Nagative represents the number of rows with negative values found. If Nagative is 0, then there are no negative values.
[0078] Step S160: Write the transaction data of the block to be traded after the transaction into the block data table of the relational database, and execute the commit operation to complete the transaction.
[0079] Specifically, when the execution result does not contain a negative value, the pending block data after the transaction can be written into the block data table of the relational database, and the commit operation can be performed to complete the transaction.
[0080] In this embodiment, the application obtains the transaction information of the block to be traded, performs consensus judgment on the block to be traded, determines that the block to be traded is a correct block, translates the transaction information into a first SQL statement and a second SQL statement, executes the statements, obtains the execution result, checks whether the execution result has a negative value, if it does, the asset data table is restored to the data before the execution of the SQL statement set, if it does not, the data of the block to be traded after the transaction is written into the block data table of the relational database, and the transaction is completed by performing a commit operation. This solution improves the data reading efficiency by translating the obtained transaction information into SQL statements and executing the SQL statements in the asset data table of the relational database to obtain the transaction execution result, compared with the prior art of reading asset data one by one. This application improves the efficiency of high-frequency trading by processing asset data through a relational asset data table.
[0081] In some embodiments of this application, the process of step S110, performing a consensus judgment operation on the block to be traded to determine whether the block to be traded is a correct block, is described. This process may include the following steps:
[0082] Step S111: Determine the height and prevHash value of the block to be traded.
[0083] Specifically, the height and prevHash value of the block to be traded can be determined through the block data.
[0084] Step S112: Query the block data table of the relational database and select the block with the highest current height as the first block.
[0085] Specifically, you can query the block data table of a relational database and select the block with the highest current height as the first block. This can be done using the QUERY function, as shown below:
[0086] Result=QUERY(SELECT max(height)from BlockTable)
[0087] LocalHeight = Result[0]
[0088] Where Result is the number of rows of the query results, and LocalHeight is the height of the highest block.
[0089] Step S113: Determine whether the height of the first block is equal to the height of the block to be traded minus 1. If so, proceed to step S114.
[0090] Specifically, the height of the first block obtained from the query can be compared with the height of the block to be traded minus 1 to determine whether they are equal. If they are equal, step S114 can be executed.
[0091] Step S114: Further query whether the block hash value of the first block in the block data table of the relational database is equal to the prevHash value of the block to be traded. If so, step S115 can be executed.
[0092] Specifically, if the height of the first block is equal to the height of the block to be traded minus 1, then the block hash value of the first block in the block data table of the relational database can be further queried to see if it is equal to the prevHash value of the block to be traded. If so, then step S115 is executed.
[0093] Step S115: Determine that the block data to be traded is correct block data.
[0094] Specifically, if the block hash value of the first block obtained from the query is equal to the prevHash value of the block to be traded, then it can be determined that the block data to be traded is the correct block data.
[0095] In some embodiments of this application, considering the possibility of blockchain splitting, in order to follow the longest chain principle of the blockchain, when there is no progressive relationship between the height of the block to be traded and the height of the highest recorded block, it is necessary to review the blocks that have already been traded. After step S113, determining whether the height of the first block is equal to the height of the block to be traded minus 1, this scheme may further include the following steps:
[0096] Step S116: If the height of the first block is not equal to the height of the block to be traded minus 1, then by querying the block data table of the relational database, determine whether the block to be traded already exists. If it does, proceed to step S117; otherwise, proceed to step S118.
[0097] Specifically, when the height of the first block is not equal to the height of the block to be traded minus 1, it can be determined whether the block to be traded already exists by querying the block data table of the relational database.
[0098] Step S117: Discard the block to be traded and send a notification message.
[0099] Specifically, when querying the block data table of the relational database and confirming that the block to be traded exists, it means that the block to be traded is a block of duplicate transactions. At this time, the block to be traded can be discarded, and a prompt message can be sent to the user to inform the user that the block to be traded already exists.
[0100] Step S118: Further utilize the consensus algorithm to determine the processing method for the block to be traded, the processing method includes discarding the block, temporarily storing the block, and performing a rollback operation.
[0101] Specifically, when querying the block data table of a relational database and determining that the block to be traded does not exist, a consensus algorithm can be used to further determine the height of the block to be traded, and the corresponding processing method can be selected according to different heights. The processing methods can include discarding the block, temporarily storing the block, and performing a rollback operation.
[0102] In some embodiments of this application, to ensure the normal operation of block transactions, the emergence of blockchain subchains is accidental. When users become aware of a subchain, they will proactively align with the main chain and update their data, thus preventing an excessive number of subchain blocks. When the consensus algorithm determines that some blocks in the block data table belong to subchain blocks based on the blocks to be traded, to adhere to the longest chain principle of the blockchain, it is necessary to roll back the subchain blocks in the block data table and delete the execution results corresponding to the subchain blocks in the asset data table. Specifically, this may include the following steps:
[0103] Step S201: In the block data table of the relational database, roll back the first block to the second block and delete the first block. The second block is the block with the current highest height minus 1 in the block data table.
[0104] Specifically, when a chain split occurs, the first block with the highest current height can be used as the split block. In the block data table of the relational database, the first block can be rolled back to the second block and the first block can be deleted. The second block is the block with the highest current height minus 1 in the block data table.
[0105] Step S202: In the asset data table of the relational database, delete the execution result of the SQL statement corresponding to the first block;
[0106] Specifically, when a subchain occurs, since the first block belongs to a subchain of the blockchain, the subchain data needs to be deleted. The subchain data includes the data in the block data table and the corresponding data in the asset data table. Therefore, the execution result of the SQL statement corresponding to the first block can be deleted from the asset data table of the relational database.
[0107] Step S203: Use the second block as the new first block and return to the step of determining whether the height of the first block is equal to the height of the block to be traded minus 1.
[0108] Specifically, after deleting the subchain data, it is necessary to align with the long main chain. Therefore, the second block can be used as the new first block, and the process of determining whether the height of the first block is equal to the height of the block to be traded minus 1 can be returned to the normal transaction process.
[0109] In some embodiments of this application, considering potential data security issues, the solution may further include the following steps:
[0110] Step S160: Obtain the seller's public key signature corresponding to the block to be traded.
[0111] Specifically, the seller's public key signature corresponding to the block to be traded can be obtained through broadcasting.
[0112] Step S170: After determining that the block to be traded is a correct block, the seller's public key is used to sign and verify whether the transaction information is legal. If it is legal, the transaction information is translated into a first SQL statement that deducts from the account corresponding to the asset remittance account and a second SQL statement that adds to the account corresponding to the asset remittance account.
[0113] In some embodiments of this application, the process of step S170, after determining that the block to be traded is a correct block, using the seller's public key to sign and verify whether the transaction information is legal, and if legal, executing the step of translating the transaction information into a first SQL statement deducting from the account corresponding to the asset remittance account and a second SQL statement adding to the account corresponding to the asset remittance account, is described. This process may include:
[0114] Step S171: Use a hash function to calculate the asset remittance account, asset inflow account, asset amount, and asset category to obtain the hash value.
[0115] Specifically, the following hash function can be used to calculate the hash value for the asset remittance account, asset inflow account, asset amount, and asset category:
[0116] txid=Hash(from,to,asset,value)
[0117] Here, txid represents the hash value obtained.
[0118] Step S172: Decrypt the seller's public key signature using the decryption function to obtain the decryption result.
[0119] Specifically, the seller's public key signature can be decrypted using the following formula to obtain the decryption result:
[0120] result=Decrypt(Pubkey,signature)
[0121] Where result represents the decryption result, Pubkey represents the seller's public key, signature represents the signature, and Decrypt represents the cryptographic decryption function.
[0122] Step S173: Determine whether the hash value is consistent with the decryption result. If they are consistent, the result is valid; otherwise, send a prompt message.
[0123] Specifically, the hash value can be compared with the decryption result to determine if they match. If they match, the signature is valid; if they do not match, a prompt message can be sent, which can be in the form of a pop-up window or SMS, indicating that the public key signature is invalid.
[0124] The blockchain transaction management device provided in the embodiments of this application is described below. The blockchain transaction management device described below can be referred to in correspondence with the blockchain transaction management method described above.
[0125] like Figure 3 As shown, a schematic diagram of a blockchain transaction device is disclosed, which may include:
[0126] The information acquisition unit 11 is used to acquire the transaction information of the broadcast block to be traded, the transaction information including the block data to be traded, the asset remittance account, the asset remittance account, and the asset amount;
[0127] Consensus judgment unit 12 is used to perform consensus judgment operation on the block to be traded to determine whether the block to be traded is a correct block;
[0128] The information translation unit 13 is used to translate the transaction information into a first SQL statement for deducting from the account corresponding to the asset remittance account and a second SQL statement for adding to the account corresponding to the asset remittance account when the block to be traded is a correct block.
[0129] The first SQL statement is used to query the current balance of the asset remittance account in the asset data table of the relational database, calculate the balance after deducting the asset quota, and write the balance after deducting the asset quota into the asset remittance account as the latest balance of the asset remittance account. The second SQL statement is used to query the current balance of the asset remittance account in the asset data table of the relational database, calculate the balance after increasing the asset quota, and write the balance after increasing the asset quota into the asset remittance account as the latest balance of the asset remittance account.
[0130] The statement execution unit 14 is used to execute the first SQL statement and the second SQL statement in the asset data table of the relational database to obtain the execution result, which includes the latest balance of the asset remittance account and the latest balance of the asset remittance account.
[0131] The result query unit 15 is used to query whether there is a negative value in the execution result. If there is, the asset data table in the relational database is restored to the data before the execution of the SQL statement set.
[0132] The data writing unit 16 is used to write the transaction-pending block data into the block data table of the relational database when the execution result does not have a negative value, and to perform a commit operation to complete the transaction.
[0133] Optionally, the consensus determination unit 12 may include:
[0134] The first consensus judgment subunit is used to determine the height and prevHash value of the block to be traded.
[0135] The second consensus judgment subunit is used to query the block data table of the relational database and select the block with the highest current height as the first block;
[0136] The third consensus judgment subunit is used to determine whether the height of the first block is equal to the height of the block to be traded minus 1. If so, it further queries whether the block hash value of the first block in the block data table of the relational database is equal to the prevHash value of the block to be traded. If so, it determines that the block data to be traded is correct block data.
[0137] Optionally, this device may also include:
[0138] A signature acquisition unit is used to acquire the seller's public key signature corresponding to the block to be traded;
[0139] The signature judgment unit is used to verify the legality of the transaction information by using the seller's public key signature after the consensus judgment unit 12 has been executed and the transaction block to be traded is determined to be a correct block. If the transaction information is legal, the information translation unit 13 is executed.
[0140] Optionally, the transaction information may further include asset categories, and the signature determination unit may include:
[0141] The first signature judgment subunit is used to calculate the asset remittance account, asset remittance account, asset amount and asset category using a hash function to obtain the hash value;
[0142] The second signature determination subunit is used to decrypt the seller's public key signature using a decryption function to obtain the decryption result;
[0143] The third signature judgment subunit is used to determine whether the hash value is consistent with the decryption result. If they are consistent, the result is valid; otherwise, a prompt message is sent.
[0144] Optionally, the device may also include:
[0145] The pending block query unit is used to determine whether the pending block already exists by querying the block data table of the relational database when the height of the first block is not equal to the height of the pending block minus 1.
[0146] The pending block discarding unit is used to discard the pending block and send a prompt message when it is found that the pending block already exists in the block data table.
[0147] The algorithm processing unit is used to further determine the processing method for the block to be traded when the block to be traded does not exist in the block data table. The processing method includes discarding the block, temporarily storing the block, and performing a rollback operation.
[0148] Optionally, the algorithm processing unit may include:
[0149] The first algorithm processing subunit is used to roll back the first block to the second block and delete the first block in the block data table of the relational database, wherein the second block is the block with the current highest height minus 1 in the block data table;
[0150] The first algorithm processing subunit is used to delete the execution result of the SQL statement corresponding to the first block in the asset data table of the relational database;
[0151] The first algorithm processing subunit is used to take the second block as the new first block and return to execute the third consensus judgment subunit.
[0152] The blockchain transaction management device provided in this application embodiment can be applied to blockchain transaction management equipment. The blockchain transaction management equipment can be a terminal. Figure 4 The hardware structure block diagram of the blockchain transaction management device is shown below. Figure 4 The hardware structure of a blockchain transaction management device may include: at least one processor 1, at least one communication interface 2, at least one memory 3, and at least one communication bus 4;
[0153] In this embodiment of the application, the number of processor 1, communication interface 2, memory 3, and communication bus 4 is at least one, and processor 1, communication interface 2, and memory 3 communicate with each other through communication bus 4;
[0154] Processor 1 may be a central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement embodiments of the present invention.
[0155] Memory 3 may include high-speed RAM, and may also include non-volatile memory, such as at least one disk storage device;
[0156] The memory stores a program, which the processor can call. The program is used for:
[0157] Obtain transaction information of the broadcast block to be traded, the transaction information including block data to be traded, asset outflow account, asset inflow account, and asset amount;
[0158] A consensus judgment operation is performed on the block to be traded to determine whether the block to be traded is a correct block;
[0159] If so, the transaction information is translated into a first SQL statement deducting from the account corresponding to the asset remittance account and a second SQL statement adding to the account corresponding to the asset remittance account;
[0160] The first SQL statement is used to query the current balance of the asset remittance account in the asset data table of the relational database, calculate the balance after deducting the asset quota, and write the balance after deducting the asset quota into the asset remittance account as the latest balance of the asset remittance account. The second SQL statement is used to query the current balance of the asset remittance account in the asset data table of the relational database, calculate the balance after increasing the asset quota, and write the balance after increasing the asset quota into the asset remittance account as the latest balance of the asset remittance account.
[0161] In the asset data table of the relational database, the first SQL statement and the second SQL statement are executed to obtain the execution results, which include the latest balance of the asset remittance account and the latest balance of the asset remittance account.
[0162] Check if the execution result has a negative value. If it does, restore the asset data table in the relational database to the data before the execution of the SQL statement set.
[0163] If no negative value exists, the transaction data of the pending block is written into the block data table of the relational database, and a commit operation is performed to complete the transaction.
[0164] Optionally, the refined and extended functions of the program can be found in the description above.
[0165] This application embodiment also provides a storage medium that can store a program suitable for execution by a processor, the program being used for:
[0166] Obtain transaction information of the broadcast block to be traded, the transaction information including block data to be traded, asset outflow account, asset inflow account, and asset amount;
[0167] A consensus judgment operation is performed on the block to be traded to determine whether the block to be traded is a correct block;
[0168] If so, the transaction information is translated into a first SQL statement deducting from the account corresponding to the asset remittance account and a second SQL statement adding to the account corresponding to the asset remittance account;
[0169] The first SQL statement is used to query the current balance of the asset remittance account in the asset data table of the relational database, calculate the balance after deducting the asset quota, and write the balance after deducting the asset quota into the asset remittance account as the latest balance of the asset remittance account. The second SQL statement is used to query the current balance of the asset remittance account in the asset data table of the relational database, calculate the balance after increasing the asset quota, and write the balance after increasing the asset quota into the asset remittance account as the latest balance of the asset remittance account.
[0170] In the asset data table of the relational database, the first SQL statement and the second SQL statement are executed to obtain the execution results, which include the latest balance of the asset remittance account and the latest balance of the asset remittance account.
[0171] Check if the execution result has a negative value. If it does, restore the asset data table in the relational database to the data before the execution of the SQL statement set.
[0172] If no negative value exists, the transaction data of the pending block is written into the block data table of the relational database, and a commit operation is performed to complete the transaction.
[0173] Optionally, the refined and extended functions of the program can be found in the description above.
[0174] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0175] The various embodiments in this specification are described in a progressive manner. Each embodiment focuses on the differences from other embodiments. The various embodiments can be combined with each other, and the same or similar parts can be referred to each other.
[0176] The above description of the disclosed embodiments enables those skilled in the art to make or use this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A blockchain transaction management method, characterized in that, include: Obtain transaction information of the broadcast block to be traded, the transaction information including block data to be traded, asset outflow account, asset inflow account, and asset amount; A consensus judgment operation is performed on the block to be traded to determine whether the block to be traded is a correct block; If so, the transaction information is translated into a first SQL statement deducting from the account corresponding to the asset remittance account and a second SQL statement adding to the account corresponding to the asset remittance account; The first SQL statement is used to query the current balance of the asset remittance account in the asset data table of the relational database, calculate the balance after deducting the asset quota, and write the balance after deducting the asset quota into the asset remittance account as the latest balance of the asset remittance account. The second SQL statement is used to query the current balance of the asset remittance account in the asset data table of the relational database, calculate the balance after increasing the asset quota, and write the balance after increasing the asset quota into the asset remittance account as the latest balance of the asset remittance account. In the asset data table of the relational database, the first SQL statement and the second SQL statement are executed to obtain the execution results, which include the latest balance of the asset remittance account and the latest balance of the asset remittance account. Check if the execution result has a negative value. If it does, restore the asset data table in the relational database to the data before the execution of the SQL statement set. If no negative value exists, the transaction data of the block to be traded after the transaction is written into the block data table of the relational database, and the commit operation is executed to complete the transaction; The relational blockchain state storage architecture based on blocks and asset data tables mainly consists of a new block module, an accounting program module, and a relational database module. The new block module is used by nodes in the blockchain network to generate new blocks. The accounting program module serves as the main program carrier for asset accounting through blockchain consensus and execution. The relational database module serves as the carrier for an independently deployed relational database, which includes a block data table and an asset data table. The asset data table is a relational data table that stores the asset details of each user, where each row includes the user's unique identifier (user), asset type (asset), user's asset balance (balance), and the height of the last updated block.
2. The method according to claim 1, characterized in that, A consensus judgment operation is performed on the pending blocks in the pending block information to determine whether the pending blocks are correct blocks, including: Determine the height and prevHash value of the block to be traded; Query the block data table of the relational database and select the block with the highest current height as the first block; Determine whether the height of the first block is equal to the height of the block to be traded minus 1; If so, then further query whether the block hash value of the first block in the block data table of the relational database is equal to the prevHash value of the block to be traded; If so, then the block data to be traded is determined to be correct block data.
3. The method according to claim 1, characterized in that, Also includes: Obtain the seller's public key signature corresponding to the block to be traded; After determining that the block to be traded is a correct block, the seller's public key is used to sign and verify whether the transaction information is legal. If it is legal, the steps of translating the transaction information into a first SQL statement that deducts from the account corresponding to the asset remittance account and a second SQL statement that adds to the account corresponding to the asset remittance account are executed.
4. The method according to claim 3, characterized in that, The transaction information also includes asset categories, and the step of verifying the legality of the transaction information using the seller's public key signature includes: The hash function is used to calculate the outgoing account, incoming account, asset amount, and asset category of the asset, and obtain the hash value. The seller's public key signature is decrypted using a decryption function to obtain the decryption result; Determine whether the hash value matches the decryption result. If they match, the result is valid; otherwise, send a prompt message.
5. The method according to claim 2, characterized in that, After determining whether the height of the first block is equal to the height of the block to be traded minus 1, the process also includes: If the height of the first block is not equal to the height of the block to be traded minus 1, then the existence of the block to be traded is determined by querying the block data table of the relational database. If it exists, discard the block to be traded and send a notification message; If it does not exist, the consensus algorithm is used to determine the processing method for the block to be traded. The processing method includes discarding the block, temporarily storing the block, and performing a rollback operation.
6. The method according to claim 5, characterized in that, The rollback operation includes: In the block data table of the relational database, the first block is rolled back to the second block, and the first block is deleted. The second block is the block with the current highest height minus 1 in the block data table. In the asset data table of the relational database, delete the execution result of the SQL statement corresponding to the first block; The second block is used as the new first block, and the process returns to the step of determining whether the height of the first block is equal to the height of the block to be traded minus 1.
7. A blockchain transaction management device, characterized in that, include: The information acquisition unit is used to acquire the transaction information of the broadcast block to be traded, the transaction information including the block data to be traded, the asset remittance account, the asset remittance account, and the asset amount; The consensus judgment unit is used to perform a consensus judgment operation on the block to be traded to determine whether the block to be traded is a correct block; The information translation unit is used to translate the transaction information into a first SQL statement deducting from the account corresponding to the asset remittance account and a second SQL statement adding to the account corresponding to the asset remittance account when the block to be traded is a correct block. The first SQL statement is used to query the current balance of the asset remittance account in the asset data table of the relational database, calculate the balance after deducting the asset quota, and write the balance after deducting the asset quota into the asset remittance account as the latest balance of the asset remittance account. The second SQL statement is used to query the current balance of the asset remittance account in the asset data table of the relational database, calculate the balance after increasing the asset quota, and write the balance after increasing the asset quota into the asset remittance account as the latest balance of the asset remittance account. The statement execution unit is used to execute the first SQL statement and the second SQL statement in the asset data table of the relational database and obtain the execution result, which includes the latest balance of the asset remittance account and the latest balance of the asset remittance account. The result query unit is used to query whether there is a negative value in the execution result. If there is, the asset data table in the relational database is restored to the data before the execution of the SQL statement set. The data writing unit is used to write the transaction-pending block data into the block data table of the relational database when the execution result does not have a negative value, and to perform a commit operation to complete the transaction. The relational blockchain state storage architecture based on blocks and asset data tables mainly consists of a new block module, an accounting program module, and a relational database module. The new block module is used by nodes in the blockchain network to generate new blocks. The accounting program module serves as the main program carrier for asset accounting through blockchain consensus and execution. The relational database module serves as the carrier for an independently deployed relational database, which includes a block data table and an asset data table. The asset data table is a relational data table that stores the asset details of each user, where each row includes the user's unique identifier (user), asset type (asset), user's asset balance (balance), and the height of the last updated block.
8. The apparatus according to claim 7, characterized in that, The consensus judgment unit includes: The first consensus judgment subunit is used to determine the height and prevHash value of the block to be traded. The second consensus judgment subunit is used to query the block data table of the relational database and select the block with the highest current height as the first block; The third consensus judgment subunit is used to determine whether the height of the first block is equal to the height of the block to be traded minus 1. If so, it further queries whether the block hash value of the first block in the block data table of the relational database is equal to the prevHash value of the block to be traded. If so, it determines that the block data to be traded is correct block data.
9. A blockchain transaction management device, characterized in that, Including memory and processor; The memory is used to store programs; The processor is used to execute the program to implement the various steps of the blockchain transaction management method as described in any one of claims 1-6.
10. A readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the various steps of the blockchain transaction management method as described in any one of claims 1-6.
Citation Information
Patent Citations
Block chain data processing method, device and equipment supporting relational retrieval
CN110096522A
Data storage method and device and computer equipment
CN112527825A