WO2021103403A1 - 区块链交易信息管理方法、装置、计算机设备及存储介质 - Google Patents

区块链交易信息管理方法、装置、计算机设备及存储介质 Download PDF

Info

Publication number
WO2021103403A1
WO2021103403A1 PCT/CN2020/085823 CN2020085823W WO2021103403A1 WO 2021103403 A1 WO2021103403 A1 WO 2021103403A1 CN 2020085823 W CN2020085823 W CN 2020085823W WO 2021103403 A1 WO2021103403 A1 WO 2021103403A1
Authority
WO
WIPO (PCT)
Prior art keywords
transactions
total number
local
information
ledger
Prior art date
Application number
PCT/CN2020/085823
Other languages
English (en)
French (fr)
Inventor
姚杰
褚镇飞
Original Assignee
深圳壹账通智能科技有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 深圳壹账通智能科技有限公司 filed Critical 深圳壹账通智能科技有限公司
Publication of WO2021103403A1 publication Critical patent/WO2021103403A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/2379Updates performed during online database operations; commit processing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2453Query optimisation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q40/00Finance; Insurance; Tax strategies; Processing of corporate or income taxes
    • G06Q40/04Trading; Exchange, e.g. stocks, commodities, derivatives or currency exchange

Definitions

  • This application belongs to the field of blockchain technology, and in particular relates to a blockchain transaction information management method, device, computer equipment, and storage medium.
  • Blockchain is a new application mode of computer technology such as distributed data storage, point-to-point transmission, consensus mechanism, and encryption algorithm.
  • the blockchain is essentially a decentralized database. It is a collection of data blocks associated with cryptographic methods. Each data block contains the transaction information of the corresponding smart contract. The transaction information of these smart contracts can be It is used to verify the validity of the information (anti-counterfeiting function) and generate the next block.
  • the inventor realizes that as these advantages of the blockchain gradually show, more and more electronic transactions are carried out using the blockchain, and the blockchain network becomes more and more complex. Therefore, the management side needs to regularly check the block The chain is maintained. For example, the management terminal needs to query and monitor the total amount of transactions.
  • the current method is mainly to traverse the transaction information recorded in each block, and calculate the total number of transactions from the block storage in real time by traversing all blocks. This is used to obtain information on the total amount of transactions, and the management side needs to traverse all blocks in real time every time. Therefore, the speed of obtaining the total number of transactions in this way is very slow, and it is difficult to guarantee the immediacy of the total number of transactions.
  • the number of blocks in the chain continues to increase, and the efficiency of querying the total transaction volume in this way is getting lower and lower.
  • the purpose of the embodiments of the present application is to propose a blockchain transaction information management method, device, computer equipment, and storage medium, so as to solve the problems of poor immediacy and low efficiency of the existing blockchain information query methods.
  • an embodiment of the present application provides a blockchain transaction information management method, which adopts the following technical solutions:
  • the transaction is monitored in real time, and when a new transaction is detected, the number of new transactions is obtained;
  • the embodiments of the present application also provide a block chain transaction information management device, which adopts the following technical solutions:
  • the obtaining module is used to obtain the current block height Hx and the local block height H, where the current block height Hx is the height of the block in the blockchain ledger when the Peer node is started, and the local block height H is the local when the Peer node is started.
  • the judgment module is used to judge the synchronization state of the blockchain ledger and the local ledger based on the current block height Hx and the local block height H;
  • the monitoring module is used for real-time monitoring of transactions if the synchronization status is synchronized and readable R, or the synchronization status is synchronized S, and when a new transaction is detected, the number of new transactions is obtained;
  • the update module is used to calculate the current total number of transactions based on the number of new transactions, and update the current total number of transactions to the local ledger;
  • the query module is used to read the corresponding total number of transactions information from the total number of historical transactions or the total number of current transactions in the local ledger based on the synchronization state based on the synchronization status when receiving the total number of transactions query request, and read it to The total number of transactions information is used as the query result, where the query result is the total number of historical transactions or the total number of current transactions.
  • an embodiment of the present application also provides a computer device, including a memory and a processor, a computer program is stored in the memory, and the processor implements the steps of the blockchain transaction information management method when the computer program is executed.
  • Blockchain transaction information management methods include:
  • the transaction is monitored in real time, and when a new transaction is detected, the transaction number of the new transaction is obtained;
  • the information on the total number of transactions is used as a query result, where the query result is information on the total number of historical transactions or information on the total number of current transactions.
  • the embodiments of the present application also provide a computer-readable storage medium on which a computer program is stored.
  • the steps of the above-mentioned blockchain transaction information management method are implemented.
  • the block chain transaction information management method includes:
  • the transaction is monitored in real time, and when a new transaction is detected, the transaction number of the new transaction is obtained;
  • the information on the total number of transactions is used as a query result, where the query result is information on the total number of historical transactions or information on the total number of current transactions.
  • the method described in this application monitors transactions in real time based on the synchronization status of the blockchain ledger and the local ledger, and realizes the synchronization of the total number of transactions information in the local ledger and the total number of transactions in the blockchain ledger.
  • the corresponding total number of transactions information can be directly obtained from the local ledger through the preset interface.
  • the existing blockchain information query method requires the management end to check each of the blockchain networks. Compared with traversing the blocks to obtain the total number of transactions, the blockchain transaction information management method provided in this application greatly improves the efficiency and immediacy of querying the total number of transactions on the blockchain, and also saves system resources.
  • a blockchain transaction information management method uses a binary key value storage method to store the total number of transactions information in a local ledger, which not only improves the efficiency of judging the synchronization status, but also helps to improve the total number of transactions information. Update efficiency.
  • Figure 1 is an exemplary system architecture diagram to which the present application can be applied;
  • Fig. 2 is a flowchart of an embodiment of a method for managing blockchain transaction information according to the present application
  • Fig. 3 is a flowchart of a relatively complete embodiment of the blockchain transaction information management method of the present application in Fig. 2;
  • Fig. 4 is a schematic structural diagram of an embodiment of a block chain transaction information management device according to the present application.
  • Fig. 5 is a schematic structural diagram of an embodiment of a computer device according to the present application.
  • Current block height Hx refers to the height of the current block in the blockchain ledger when the Peer node is started.
  • Local block height H refers to the height of the block stored in the local ledger when the Peer node is started.
  • the total number of historical transactions information When the Peer node is started, the total number of transactions calculated based on the number of transactions at the current block height Hx that has been synchronized to the local ledger is called the total number of historical transactions.
  • the block height Hx is inconsistent.
  • the system architecture 100 may include terminal devices 101, 102, 103, a network 104, and a server 105.
  • the network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105.
  • the network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, and so on.
  • the user can use the terminal devices 101, 102, and 103 to interact with the server 105 through the network 104 to receive or send messages and so on.
  • Various communication client applications such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, and social platform software, can be installed on the terminal devices 101, 102, and 103.
  • the terminal devices 101, 102, 103 may be various electronic devices with display screens and support for web browsing, including but not limited to smart phones, tablet computers, e-book readers, MP3 players (Moving Picture Experts Group Audio Layer III, dynamic Video experts compress standard audio layer 3), MP4 (Moving Picture Experts Group Audio Layer IV, dynamic image experts compress standard audio layer 4) players, laptop portable computers and desktop computers, etc.
  • MP3 players Moving Picture Experts Group Audio Layer III, dynamic Video experts compress standard audio layer 3
  • MP4 Moving Picture Experts Group Audio Layer IV, dynamic image experts compress standard audio layer 4
  • laptop portable computers and desktop computers etc.
  • the server 105 may be a server that provides various services, for example, a background server that provides support for pages displayed on the terminal devices 101, 102, and 103.
  • the blockchain transaction information management method provided by the embodiments of the present application is generally executed by a server/terminal device. Accordingly, the blockchain transaction information management device is generally set in the server/terminal device.
  • terminal devices, networks, and servers in FIG. 1 are merely illustrative. There can be any number of terminal devices, networks, and servers according to implementation needs.
  • FIG. 2 there is shown a flowchart of an embodiment of the blockchain transaction information management method according to the present application.
  • the described blockchain transaction information management method includes the following steps:
  • the block height refers to the number of blocks connected to the main chain, that is, the total number of all blocks connected to the block chain.
  • the block height is the identifier of the block, and the block height represents a certain area.
  • the current block height Hx is the height of the current block in the blockchain ledger when the Peer node is started.
  • the local block height H is the height of the block stored in the local ledger when the Peer node is started.
  • the local ledger can be a local database
  • the local database can be a pre-established database used to store transaction information
  • the local database is connected to the above-mentioned blockchain network
  • the local database can be a Mysql database or an Oracle database. Any one of the database, Sybase database, etc., is not limited in this application.
  • step S201 acquiring the current block height Hx and the local block height H specifically includes the following steps:
  • the total number of transactions state machine is preset on each Peer node.
  • the preset total number of transactions state machine is run to obtain the current block height Hx in the blockchain ledger.
  • the aforementioned preset total number of transactions state machine obtains the local block height H from the local ledger, so as to identify the synchronization state of the blockchain ledger and the local ledger.
  • the preset total number of transactions state machine in this embodiment refers to a finite state machine used to determine whether the storage state of the total number of transactions between the blockchain ledger and the local ledger has changed.
  • Finite-state machine Finite-state machine, FSM
  • FSM Finite-state machine
  • FSM Finite-state machine
  • the above-mentioned preset total number of transactions state machine can also be used to maintain the blockchain ledger and The storage status of the total number of transactions between local ledgers.
  • the total number of transactions state machine can determine the synchronization state of the blockchain ledger and the local ledger based on the current block height Hx and the local block height H.
  • Hx and the local block height H If H is consistent, it is determined that the synchronization state of the blockchain ledger and the local ledger is synchronized.
  • the total number of transactions state machine determines that the current block height Hx and the local block height H are inconsistent, the synchronization of the blockchain ledger and the local ledger is determined The status is not synchronized.
  • the total number of transactions preset at the Peer node state machine judges the synchronization state between the blockchain ledger and the local ledger based on the current block height Hx and the local block height H.
  • the synchronization status with the local ledger is synchronized, that is, when the total number of transactions state machine determines that the current block height Hx is consistent with the local block height H, the total number of transactions stored in the blockchain ledger is the same as the total number of transactions stored in the local ledger.
  • the information is consistent, so the corresponding total number of transactions information can be read from the local ledger through the preset interface, and the read total number of transactions information is used as the query result; when the synchronization state of the blockchain ledger and the local ledger is not synchronized, that is When the total number of transactions state machine judges that the current block height Hx is inconsistent with the local block height H, the total number of transactions information stored in the blockchain ledger is also inconsistent with the total number of transactions information stored in the local ledger. If the local ledger is read at this time As the query result, the query result has an error. Therefore, when the synchronization state of the blockchain ledger and the local ledger is not synchronized, it is not allowed to directly read the total transaction information from the local ledger through the preset interface.
  • the block height Hx is inconsistent.
  • the synchronization state between the blockchain ledger and the local ledger is judged by the total number of transactions state machine according to the current block height Hx and the local block height H.
  • step S202 determines the synchronization status of the blockchain ledger and the local ledger according to the current block height Hx and the local block height H, specifically including:
  • the synchronization state is determined to be synchronized and readable R, otherwise, the synchronization state is determined to be unsynchronized U.
  • the total number of transactions state machine determines that the synchronization state of the blockchain ledger and the local ledger is synchronized and readable R, and continues to perform step S203; when the current block height Hx in the blockchain ledger is greater than 0, the total number of transactions The state machine first judges whether the height H of a slight local block in the local ledger is consistent with the current block height Hx of the blockchain ledger. When the local block height H is consistent with the current block height Hx, the total number of transactions state machine determines the blockchain ledger.
  • the synchronization status with the local ledger is synchronized and readable R, and step S203 is continued; when the local block height H is inconsistent with the current block height Hx, the synchronization state of the blockchain ledger and the local ledger is determined to be unsynchronized U , And continue to perform the following steps S301 to S304, please refer to FIG. 3 for details.
  • S302 Traverse all the blocks to be synchronized to obtain the number of transactions in each block to be synchronized;
  • S303 Accumulate the number of transactions in each block to be synchronized with the original total number of historical transactions in the local ledger to calculate new total number of historical transactions;
  • S304 Update the new total historical transaction information to the local ledger to replace the original total historical transaction information, and update the synchronization status to synchronized S.
  • the total number of transactions state machine determines that the synchronization state of the blockchain ledger and the local ledger is unsynchronized U, it is not allowed to directly query the total number of transactions information through the local ledger. At this time, the total number of transactions state machine is required to check the synchronization status and the total number of transactions information. The query can only be performed after the update. Specifically, the total number of transactions state machine takes all blocks in the range from the local block height H in the local ledger to the current block height Hx in the blockchain ledger as the blocks to be synchronized. The total number of transactions state machine traverses all the blocks to be synchronized.
  • step S203 Get the number of transactions in each block to be synchronized, and accumulate the number of transactions in each block to be synchronized on the basis of the original total historical transaction information, that is, the number of transactions in each block to be synchronized with the original number in the local ledger
  • the total number of historical transactions (the original total number of historical transactions refers to the total number of transactions calculated based on the number of transactions at the local block height H in the local ledger) is accumulated to obtain the new total historical transaction information, and the new history
  • the total number of transactions information is updated to the local ledger to replace the original total number of historical transactions information, and the synchronization status is updated to synchronized S, and step S203 is continued.
  • the new historical transaction information degree of the local ledger center is equal to the number of transactions calculated by Hx Total number of transactions information.
  • the synchronization state of the blockchain ledger and the local ledger is synchronized S, it means that the current block height Hx of the blockchain ledger and the local block height H of the local ledger have been consistent, and in the continuous monitoring process, there is no New transactions are generated, that is, in the process of real-time monitoring, the total number of transactions in the blockchain ledger and the local ledger has not changed; when the synchronization status of the blockchain ledger and the local ledger is synchronized and R is readable, the description area The current block height Hx of the blockchain ledger has been consistent with the local block height H of the local ledger, and in the process of continuous monitoring, there are new transactions generated, that is, in the real-time monitoring process, the block chain ledger and the local ledger The total number of transactions is kept updated synchronously.
  • S204 Calculate the current total number of transactions information according to the number of new transactions, and update the current total number of transactions to the local ledger;
  • the completion of each new transaction will record the transaction information of the new transaction on the blockchain ledger in real time.
  • the transaction information here includes the number of transactions.
  • the total number of transactions is based on the number of transactions in the new transaction. Calculate the current total number of transactions information, and update the current total number of transactions information to the local ledger.
  • step S204 calculates the current total number of transactions information according to the number of new transactions, and updating the current total number of transactions to the local ledger specifically includes:
  • the total number of transactions state machine judges the synchronization status of the blockchain ledger and the local ledger in real time.
  • the synchronization status is synchronized and readable R
  • the current total number of transactions is continuously updated according to the number of new transactions; when synchronized If the status is synchronized S, first read the total number of historical transactions from the local ledger, then add the number of new transactions to the total number of historical transactions to obtain the new total number of current transactions, and finally add the new total number of current transactions.
  • Update to the local ledger to replace the original current total number of transactions information (the original current total number of transactions information refers to the total number of transactions calculated based on the current block height Hx when the Peer node is started), and update the synchronization status It is synchronized and readable R; when the synchronization status is unsynchronized U, continue to execute step S302 to step S304, and execute again when the synchronization state between the blockchain ledger and the local ledger changes to synchronized S Step S204 is to obtain the current total number of transactions information.
  • the new current total transaction information in the local ledger at this time is equivalent to the completion of new transactions after the Peer node is started. It is calculated based on the number of transactions from the current block height Hx to the latest block height when the Peer node is started. Information about the total number of transactions.
  • S205 When receiving the total number of transactions query request, based on the synchronization status, read the corresponding total number of transactions information from the total number of historical transactions or the total number of current transactions in the local ledger through a preset interface, and read the total number of transactions. The information is used as the query result, where the query result is the total number of historical transactions or the total number of current transactions.
  • the total number of transactions query request can be initiated by the user through the client.
  • the total number of transactions state machine determines the synchronization state between the blockchain ledger and the local ledger when the total number of transactions query request is received. Then read the corresponding total number of transactions information based on the different synchronization status between the blockchain ledger and the local ledger, and use the total number of transactions as the query result.
  • the query result can be the total number of historical transactions or the total number of current transactions.
  • the electronic device (such as the server/terminal device shown in FIG. 1) on which the blockchain transaction information management method runs can receive a request for querying the total number of transactions through a wired connection or a wireless connection.
  • the above-mentioned wireless connection methods can include but are not limited to 3G/4G connection, WiFi connection, Bluetooth connection, WiMAX connection, Zigbee connection, UWB (ultra wideband) connection, and other currently known or future wireless connection methods .
  • the corresponding transaction is read from the total number of historical transactions information or the total number of current transactions in the local ledger through a preset interface.
  • the total information specifically includes:
  • the synchronization status is synchronized and readable R when the query request is received, the current total number of transactions information is read from the local ledger through the preset interface;
  • the total historical transaction information is read from the local ledger through the preset interface.
  • the total number of transactions state machine first judges the synchronization state between the blockchain ledger and the local ledger when the query request for the total number of transactions is received, and then reads the corresponding total number of transactions information according to the different synchronization states between the blockchain ledger and the local ledger. And use the total number of transactions as the query result. Specifically, the total number of historical transactions and the total number of current transactions are stored in the local ledger at the same time. When a query request is received, the synchronization state between the blockchain ledger and the local ledger is synchronized and readable.
  • the synchronization state between the blockchain ledger and the local ledger is synchronized S, and the total number of historical transactions is read from the local ledger through the preset interface Information as the result of the query. It should be further explained that when the synchronization state between the blockchain ledger and the local ledger is synchronized S, and no new transactions are generated during the monitoring process, the current total number of transactions information is equivalent to the total number of historical transactions information.
  • the steps S302 to S304 are continued to be executed, so that the area The synchronization state between the blockchain ledger and the local ledger changes to synchronized S, and continues to monitor whether new transactions are generated.
  • the total number of historical transactions is read from the local ledger through the preset interface as the query result.
  • the synchronization state between the blockchain ledger and the local ledger is changed to synchronized and readable R, and the current total number of transactions information is read from the local ledger through a preset interface as the query result.
  • the method performs real-time monitoring of transactions according to the synchronization state of the blockchain ledger and the local ledger, and realizes the synchronization of the total number of transactions information in the local ledger and the total number of transactions in the blockchain ledger.
  • the corresponding total number of transactions information can be directly obtained from the local ledger through the preset interface, and the existing blockchain information query method requires the management end to traverse each block in the blockchain network to obtain transactions
  • the blockchain transaction information management method provided in this application greatly improves the efficiency and immediacy of querying the total information of blockchain transactions, and also saves system resources.
  • step S202 further includes step S301 to step S304 after judging the synchronization state of the blockchain ledger and the local ledger according to the current block height Hx and the local block height H.
  • step S301 further includes step S301 to step S304 after judging the synchronization state of the blockchain ledger and the local ledger according to the current block height Hx and the local block height H.
  • S302 Traverse all the blocks to be synchronized to obtain the number of transactions in each block to be synchronized;
  • S303 Accumulate the number of transactions in each block to be synchronized with the original total number of historical transactions in the local ledger to calculate new total number of historical transactions;
  • S304 Update the new total historical transaction information to the local ledger to replace the original total historical transaction information, and update the synchronization status to synchronized S.
  • step S304 updates the new historical transaction total information to the local ledger to replace the original historical transaction total information as follows:
  • the binary key value storage method is used to update the new historical transaction total information to the local ledger to replace the original historical transaction total information.
  • the current chain is testChain
  • the block height of the current chain is 100
  • the total number of transactions in the current chain is 1234
  • the stored key is: testChain+totalTxNum
  • the stored value is (100, 1234 ), where totalTxNum is a fixed string.
  • the storage method using binary keys not only improves the efficiency of the state machine of the total number of transactions in judging the synchronization state between the blockchain ledger and the local ledger, but also helps to improve the efficiency of updating the total number of transactions.
  • this application discloses a blockchain transaction information management method, device, computer equipment and storage medium.
  • the method obtains the current block height Hx and the local block height H; according to the current block height Hx and the local block height H, to determine the synchronization status of the blockchain ledger and the local ledger; if the synchronization status is synchronized and readable R, or the synchronization status is synchronized S, the transaction will be monitored in real time.
  • the method performs real-time monitoring of transactions according to the synchronization state of the blockchain ledger and the local ledger, and realizes the synchronization of the total number of transactions information in the local ledger and the total number of transactions in the blockchain ledger.
  • the blockchain transaction information management method greatly improves the efficiency and immediacy of querying the total information of blockchain transactions, and also saves system resources.
  • a blockchain transaction information management method uses a binary key value storage method to store the total number of transactions information in a local ledger, which not only improves the efficiency of judging the synchronization status, but also helps to improve the total number of transactions information. Update efficiency.
  • the computer program can be stored in a computer readable storage medium, and the program can be stored in a computer readable storage medium. When executed, it may include the procedures of the above-mentioned method embodiments.
  • the aforementioned storage medium may be a non-volatile storage medium such as a magnetic disk, an optical disc, a read-only memory (Read-Only Memory, ROM), or a random access memory (Random Access Memory, RAM), etc.
  • this application provides an embodiment of a block chain transaction information management device, which corresponds to the method embodiment shown in FIG. 2.
  • the device can be specifically applied to various electronic devices.
  • the blockchain transaction information management device in this embodiment includes: an acquisition module 401, a judgment module 402, a monitoring module 403, an update module 404, and a query module 405, wherein:
  • the obtaining module 401 is used to obtain the current block height Hx and the local block height H, where the current block height Hx is the height of the block in the blockchain ledger when the Peer node is started, and the local block height H is when the Peer node is started The height of the block in the local ledger;
  • the judging module 402 is used to judge the synchronization state of the blockchain ledger and the local ledger based on the current block height Hx and the local block height H;
  • the monitoring module 403 is used to monitor the transaction in real time if the synchronization status is synchronized and readable R, or the synchronization status is synchronized S, and obtain the transaction number of the new transaction when a new transaction is detected;
  • the update module 404 is used to calculate the current total number of transactions information according to the number of new transactions, and update the current total number of transactions to the local ledger;
  • the query module 405 is used to read the corresponding transaction total information from the historical transaction total information or the current transaction total information in the local ledger based on the synchronization state based on the synchronization state when receiving the transaction total number query request, and read it
  • the information of the total number of transactions received is used as the query result, where the query result is the information of the total number of historical transactions or the total number of current transactions.
  • the blockchain transaction information management device monitors transactions in real time according to the synchronization status of the blockchain ledger and the local ledger.
  • the above technical solution realizes the synchronization of the total number of transactions information in the local ledger and the total number of transactions in the blockchain ledger.
  • the existing blockchain information query method requires the management end to check each block in the blockchain network. Compared with traversing to obtain the total number of transactions information, the blockchain transaction information management method provided by this application greatly improves the efficiency and immediacy of querying the total number of blockchain transactions information, and also saves system resources.
  • judgment module 402 is used for judging the synchronization state of the blockchain ledger and the local ledger according to the current block height Hx and the local block height H, specifically including:
  • the synchronization state is determined to be synchronized and readable R, otherwise, the synchronization state is determined to be unsynchronized U.
  • the acquiring module 401 specifically includes: a first acquiring unit and a second acquiring unit, where:
  • the first obtaining unit is used to run the preset total number of transactions state machine when monitoring the startup of the Peer node, and obtain the current block height Hx in the blockchain ledger when obtaining;
  • the second obtaining unit is used to obtain the local block height H from the local ledger.
  • the update module 404 specifically includes: a first judgment unit, a first reading unit, a calculation unit, and an update unit, where:
  • the first judgment unit is used to judge the synchronization state of the blockchain ledger and the local ledger in the new transaction process
  • the first reading unit if the synchronization status is synchronized S, read the total number of historical transactions information from the local ledger;
  • the calculation unit is used to add the number of new transactions to the total number of historical transactions to obtain the new total number of current transactions;
  • the update unit is used to update the new current total number of transactions information to the local ledger to replace the original current total number of transactions information, and update the synchronization status to be synchronized and readable R.
  • the query module 405 specifically includes: a second judging unit, a second reading unit, and a third reading unit, where:
  • the second judging unit is used to judge the synchronization state when the request for querying the total number of transactions is received;
  • the second reading unit is configured to read the current total number of transactions information from the local ledger through the preset interface if the synchronization status is synchronized and readable R when the query request is received;
  • the third reading unit is configured to read the total number of historical transactions from the local ledger through the preset interface if the synchronization status is synchronized S when the query request is received, and no new transactions are generated.
  • the above-mentioned blockchain transaction information management device further includes an unsynchronized processing module, which is used to change the local block height H to the current block height if the synchronization state is unsynchronized U Blocks within the range of Hx are used as blocks to be synchronized;
  • the unsynchronized processing module includes a storage unit for updating the new historical transaction total information to the local ledger by using a binary key value storage method to replace the original historical transaction total information .
  • Each module in the above-mentioned block chain transaction information management device can be implemented in whole or in part by software, hardware and a combination thereof.
  • the above-mentioned modules may be embedded in the form of hardware or independent of the processor in the computer equipment, or may be stored in the memory of the computer equipment in the form of software, so that the processor can call and execute the operations corresponding to the above-mentioned modules.
  • the blockchain transaction information management device disclosed in this application monitors transactions in real time according to the synchronization state of the blockchain ledger and the local ledger.
  • the above technical solution realizes the total number of transactions in the local ledger and the total number of transactions in the blockchain ledger.
  • the corresponding total number of transactions information can be directly obtained from the local ledger through the preset interface according to the needs.
  • the existing blockchain information query method requires the management end to check the total number of transactions in the blockchain network. Each block is traversed to obtain the total number of transactions.
  • the efficiency and immediacy of querying the total number of transactions on the blockchain are greatly improved, and system resources are also saved. .
  • FIG. 5 is a block diagram of the basic structure of the computer device in this embodiment.
  • the computer device 6 includes a memory 61, a processor 62, and a network interface 63 that communicate with each other through a system bus. It should be pointed out that only the computer device 6 with components 61-63 is shown in the figure, but it should be understood that it is not required to implement all the illustrated components, and more or fewer components may be implemented instead. Among them, those skilled in the art can understand that the computer device here is a device that can automatically perform numerical calculation and/or information processing in accordance with pre-set or stored instructions.
  • Its hardware includes, but is not limited to, a microprocessor, a dedicated Integrated Circuit (Application Specific Integrated Circuit, ASIC), Programmable Gate Array (Field-Programmable Gate Array, FPGA), Digital Processor (Digital Signal Processor, DSP), embedded equipment, etc.
  • ASIC Application Specific Integrated Circuit
  • ASIC Application Specific Integrated Circuit
  • FPGA Field-Programmable Gate Array
  • DSP Digital Processor
  • the computer device may be a computing device such as a desktop computer, a notebook, a palmtop computer, and a cloud server.
  • the computer device can interact with the user through a keyboard, a mouse, a remote control, a touch panel, or a voice control device.
  • the memory 61 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static memory Random access memory (SRAM), read only memory (ROM), electrically erasable programmable read only memory (EEPROM), programmable read only memory (PROM), magnetic memory, magnetic disk, optical disk, etc.
  • the memory 61 may be an internal storage unit of the computer device 6, such as a hard disk or a memory of the computer device 6.
  • the memory 61 may also be an external storage device of the computer device 6, for example, a plug-in hard disk, a smart media card (SMC), and a secure digital device equipped on the computer device 6. (Secure Digital, SD) card, Flash Card, etc.
  • the memory 61 may also include both the internal storage unit of the computer device 6 and its external storage device.
  • the memory 61 is generally used to store the operating system and various application software installed in the computer device 6, such as the program code of the blockchain transaction information management method.
  • the memory 61 can also be used to temporarily store various types of data that have been output or will be output.
  • the processor 62 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chips.
  • the processor 62 is generally used to control the overall operation of the computer device 6.
  • the processor 62 is configured to run the program code or process data stored in the memory 61, for example, to run the program code of the blockchain transaction information management method, so as to realize the blockchain transaction information
  • a management method the method at least includes: obtaining the current block height Hx and the local block height H, where the current block height Hx is the height of the block in the blockchain ledger when the Peer node is started, and the local block height H is the height of the block in the local ledger when the Peer node is started; according to the current block height Hx and the local block height H, determine the synchronization state of the blockchain ledger and the local ledger; if said If the synchronization status is synchronized and readable R, or if the synchronization status is synchronized S, the transaction is monitored in
  • the transaction number of the new transaction is obtained;
  • the total number of transactions is calculated by calculating the current total number of transactions information, and the current total number of transactions information is updated to the local ledger; upon receiving the total number of transactions query request, based on the synchronization state, from the local ledger through a preset interface Read the corresponding total number of transactions information from the total number of historical transactions information or the total number of current transactions information, and use the read total number of transactions information as the query result, where the query result is the total number of historical transactions information or the current total number of transactions information.
  • the network interface 63 may include a wireless network interface or a wired network interface, and the network interface 63 is generally used to establish a communication connection between the computer device 6 and other electronic devices.
  • the computer-readable storage medium may be non-volatile or volatile, and the computer-readable storage medium stores Block chain transaction information management method program, the program of the blockchain transaction information management method can be executed by at least one processor, so that the at least one processor executes the steps of the above-mentioned blockchain transaction information management method ,
  • the sand control method of the blockchain transaction information management includes: obtaining the current block height Hx and the local block height H, wherein the current block height Hx is the value of the block in the blockchain ledger when the Peer node is started.
  • the local block height H is the height of the block in the local ledger when the Peer node is started; according to the current block height Hx and the local block height H, it is determined that the blockchain ledger and the local
  • the synchronization status of the ledger if the synchronization status is synchronized and readable R, or the synchronization status is synchronized S, the transaction is monitored in real time, and when a new transaction is detected, the new transaction is obtained
  • the number of transactions; the current total number of transactions is calculated according to the number of new transactions, and the current total number of transactions information is updated to the local ledger; upon receiving the total number of transactions query request, based on the synchronization status, through preset
  • the interface reads the corresponding total number of transactions information from the total number of historical transactions information or the total number of current transactions in the local ledger, and uses the read total number of transactions information as a query result, where the query result is a historical transaction Total information or total current transaction information.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • General Physics & Mathematics (AREA)
  • Physics & Mathematics (AREA)
  • Business, Economics & Management (AREA)
  • Data Mining & Analysis (AREA)
  • General Engineering & Computer Science (AREA)
  • Finance (AREA)
  • Accounting & Taxation (AREA)
  • Economics (AREA)
  • Development Economics (AREA)
  • Computing Systems (AREA)
  • Marketing (AREA)
  • Strategic Management (AREA)
  • Technology Law (AREA)
  • General Business, Economics & Management (AREA)
  • Computational Linguistics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本申请实施例属于区块链技术领域,涉及一种区块链交易信息管理方法、装置、计算机设备及存储介质,方法包括获取当前区块高度Hx和本地区块高度H;根据当前区块高度Hx和本地区块高度H,判断区块链账本与本地账本的同步状态;若同步状态为已同步且可读R,或者,同步状态为已同步S,则对交易进行实时监测,当监测到有新交易产生时,获取新交易的交易数;根据新交易的交易数计算出当前交易总数信息,并将当前交易总数信息更新到本地账本;在接收到交易总数查询请求时,基于同步状态,通过预设接口从本地账本中读取对应的交易总数信息,并将读取到的交易总数信息作为查询结果。本申请提升了查询区块链交易总数信息的效率以及即时性。

Description

区块链交易信息管理方法、装置、计算机设备及存储介质
本申请要求于2019年11月25日提交中国专利局,申请号为201911164204.8,发明名称为“区块链交易信息管理方法、装置、计算机设备及存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请属于区块链技术领域,尤其涉及一种区块链交易信息管理方法、装置、计算机设备及存储介质。
背景技术
区块链(Blockchain)是分布式数据存储、点对点传输、共识机制、加密算法等计算机技术的新型应用模式。区块链本质上是一个去中心化的数据库,是一串使用密码学方法相关联产生的数据块集合,其中每一个数据块包含了相应的智能合约的交易信息,这些智能合约的交易信息可以用于验证信息的有效性(防伪功能)以及生成下一个区块。
发明人意识到,随着区块链的这些优势逐渐地显示,越来越多的电子交易采用区块链来进行,区块链网络变得越来越复杂,因此需要管理端定期对区块链进行维护。例如,管理端需要对交易总量进行查询监控,当前采用的方式主要是通过对每个区块记载的交易信息进行遍历统计,从区块存储中实时遍历所有区块的方式计算出交易总数,以此来获取交易总量的信息,并且管理端每次都需要实时遍历所有区块,因此通过此方式获取交易总数的速度非常慢,很难保证交易总数信息的即时性,而随着区块链中区块数量不断地增多,采用这种方式进行交易总量的查询效率越来越低。
发明内容
本申请实施例的目的在于提出一种区块链交易信息管理方法、装置、计算机设备及存储介质,以解决现有的区块链信息查询方式即时性差、效率低的问题。
为了解决上述技术问题,本申请实施例提供一种区块链交易信息管理方法,采用了如下所述的技术方案:
获取当前区块高度Hx和本地区块高度H,其中,当前区块高度Hx为Peer节点启动时区块链账本中区块的高度,本地区块高度H为Peer节点启动时本地账本中区块的高度;
根据当前区块高度Hx和本地区块高度H,判断区块链账本与本地账本的同步状态;
若同步状态为已同步且可读R,或者,同步状态为已同步S,则对交易进行实时监测,当监测到有新交易产生时,获取新交易的交易数;
根据新交易的交易数计算出当前交易总数信息,并将当前交易总数信息更新到本地账本;
在接收到交易总数查询请求时,基于同步状态,通过预设接口从本地账本中的历史交易总数信息或当前交易总数信息中读取对应的交易总数信息,并将读取到的交易总数信息作为查询结果,其中,查询结果为历史交易总数信息或当前交易总数信息。
为了解决上述技术问题,本申请实施例还提供一种区块链交易信息管理装置,采用了如下所述的技术方案:
获取模块,用于获取当前区块高度Hx和本地区块高度H,其中,当前区块高度Hx为Peer节点启动时区块链账本中区块的高度,本地区块高度H为Peer节点启动时本地账本中区块的高度;
判断模块,用于根据当前区块高度Hx和本地区块高度H,判断区块链账本与本地账本的同步状态;
监测模块,用于若同步状态为已同步且可读R,或者,同步状态为已同步S,则对交易进 行实时监测,当监测到有新交易产生时,获取新交易的交易数;
更新模块,用于根据新交易的交易数计算出当前交易总数信息,并将当前交易总数信息更新到本地账本;
查询模块,用于在接收到交易总数查询请求时,基于同步状态,通过预设接口从本地账本中的历史交易总数信息或当前交易总数信息中读取对应的交易总数信息,并将读取到的交易总数信息作为查询结果,其中,查询结果为历史交易总数信息或当前交易总数信息。
为了解决上述技术问题,本申请实施例还提供一种计算机设备,包括存储器和处理器,存储器中存储有计算机程序,处理器执行计算机程序时实现上述区块链交易信息管理方法的步骤,所述区块链交易信息管理方法包括:
获取当前区块高度Hx和本地区块高度H,其中,所述当前区块高度Hx为Peer节点启动时区块链账本中区块的高度,所述本地区块高度H为Peer节点启动时本地账本中区块的高度;
根据所述当前区块高度Hx和所述本地区块高度H,判断所述区块链账本与所述本地账本的同步状态;
若所述同步状态为已同步且可读R,或者,所述同步状态为已同步S,则对交易进行实时监测,当监测到有新交易产生时,获取所述新交易的交易数;
根据所述新交易的交易数计算出当前交易总数信息,并将所述当前交易总数信息更新到本地账本;
在接收到交易总数查询请求时,基于所述同步状态,通过预设接口从所述本地账本中的历史交易总数信息或当前交易总数信息中读取对应的交易总数信息,并将读取到的所述交易总数信息作为查询结果,其中,所述查询结果为历史交易总数信息或当前交易总数信息。
为了解决上述技术问题,本申请实施例还提供一种计算机可读存储介质,计算机可读存储介质上存储有计算机程序,计算机程序被处理器执行时实现上述区块链交易信息管理方法的步骤,所述区块链交易信息管理方法包括:
获取当前区块高度Hx和本地区块高度H,其中,所述当前区块高度Hx为Peer节点启动时区块链账本中区块的高度,所述本地区块高度H为Peer节点启动时本地账本中区块的高度;
根据所述当前区块高度Hx和所述本地区块高度H,判断所述区块链账本与所述本地账本的同步状态;
若所述同步状态为已同步且可读R,或者,所述同步状态为已同步S,则对交易进行实时监测,当监测到有新交易产生时,获取所述新交易的交易数;
根据所述新交易的交易数计算出当前交易总数信息,并将所述当前交易总数信息更新到本地账本;
在接收到交易总数查询请求时,基于所述同步状态,通过预设接口从所述本地账本中的历史交易总数信息或当前交易总数信息中读取对应的交易总数信息,并将读取到的所述交易总数信息作为查询结果,其中,所述查询结果为历史交易总数信息或当前交易总数信息。
由以上技术方案可知,本申请所述方法根据区块链账本与本地账本的同步状态对交易进行实时监测,实现了本地账本中的交易总数信息与区块链账本中的交易总数信息的同步,在进行交易总数的查询时,根据同步状态,可以通过预设接口从本地账本中直接获取对应交易总数信息,与现有的区块链信息查询方式要求管理端对区块链网络中的每一区块进行遍历,以获取交易总数信息相比,本申请提供的区块链交易信息管理方法极大地提升了查询区块链交易总数信息的效率以及即时性,同时还节约了系统资源。此外,本申请提供的一种区块链交易信息管理方法采用二进制键值的存储方式将交易总数信息存储在本地账本中,不仅提高了判断同步状态的效率,而且还有利于提高交易总数信息的更新效率。
附图说明
图1是本申请可以应用于其中的示例性系统架构图;
图2根据本申请的区块链交易信息管理方法的一个实施例的流程图;
图3是图2中本申请的区块链交易信息管理方法的一个较为完整实施例的流程图;
图4是根据本申请的区块链交易信息管理装置的一个实施例的结构示意图;
图5是根据本申请的计算机设备的一个实施例的结构示意图。
具体实施方式
为了使本技术领域的人员更好地理解本申请方案,在对本申请实施例中的技术方案进行清楚、完整地描述前,先对本提案中的涉及到的部分专有名词和自定义名词分别进行解释说明,具体如下:
当前区块高度Hx:指Peer节点启动时,区块链账本中当前区块的高度。
本地区块高度H:指Peer节点启动时,存储在本地账本中的区块的高度。
历史交易总数信息:Peer节点启动时,根据已同步至本地账本的当前区块高度Hx的交易数计算出来的交易总数信息,称为历史交易总数信息。
当前交易总数信息:Peer节点启动后陆续有新交易完成,根据Peer节点启动时当前区块高度Hx开始到最新区块高度的交易数计算出来的交易总数信息,称为当前交易总数信息。
未同步(U):Peer节点启动时,区块链账本中的交易总数信息与本地账本中的交易总数信息未进行同步,即本地账本中的本地区块高度H与区块链账本中的当前区块高度Hx不一致。
已同步(S):Peer节点启动时,区块链账本中的交易总数信息与本地账本中的交易总数信息已经进行同步,即本地账本中的本地区块高度H与区块链账本中的当前区块高度Hx一致。
已同步且可读(R):在区块链账本中的交易总数信息与本地账本中的交易总数信息已经进行同步的情况下,区块链上陆续有新的交易产生,并持续更新账本中的交易总数信息。
为了使本技术领域的人员更好地理解本申请方案,下面将结合附图,对本申请实施例中的技术方案进行清楚、完整地描述。
如图1所示,系统架构100可以包括终端设备101、102、103,网络104和服务器105。网络104用以在终端设备101、102、103和服务器105之间提供通信链路的介质。网络104可以包括各种连接类型,例如有线、无线通信链路或者光纤电缆等等。
用户可以使用终端设备101、102、103通过网络104与服务器105交互,以接收或发送消息等。终端设备101、102、103上可以安装有各种通讯客户端应用,例如网页浏览器应用、购物类应用、搜索类应用、即时通信工具、邮箱客户端、社交平台软件等。
终端设备101、102、103可以是具有显示屏并且支持网页浏览的各种电子设备,包括但不限于智能手机、平板电脑、电子书阅读器、MP3播放器(Moving Picture Experts Group Audio Layer III,动态影像专家压缩标准音频层面3)、MP4(Moving Picture Experts Group Audio Layer IV,动态影像专家压缩标准音频层面4)播放器、膝上型便携计算机和台式计算机等等。
服务器105可以是提供各种服务的服务器,例如对终端设备101、102、103上显示的页面提供支持的后台服务器。
需要说明的是,本申请实施例所提供的区块链交易信息管理方法一般由服务器/终端设备执行,相应地,区块链交易信息管理装置一般设置于服务器/终端设备中。
应该理解,图1中的终端设备、网络和服务器的数目仅仅是示意性的。根据实现需要,可以具有任意数目的终端设备、网络和服务器。
继续参考图2,示出了根据本申请的区块链交易信息管理方法的一个实施例的流程图。所述的区块链交易信息管理方法,包括以下步骤:
S201,获取当前区块高度Hx和本地区块高度H,其中,当前区块高度Hx为Peer节点启动时区块链账本中区块的高度,本地区块高度H为Peer节点启动时本地账本中区块的高度;
其中,区块高度是指区块链接在主链的个数,也即连接在区块链上所有区块的总数,区块高度是区块的标示符,区块高度表示的是某一区块在区块链中的具体位置,单一的区块总是会有一个明确的、固定的区块高度,当前区块高度Hx为Peer节点启动时,区块链账本中 当前区块的高度,本地区块高度H为Peer节点启动时,存储在本地账本中区块的高度。
需要说明的是,本地账本可以是一个本地数据库,该本地数据库可以为预先建立的,并用于存储交易信息的数据库,该本地数据库与上述区块链网络连接,该本地数据库可以为Mysql数据库、Oracle数据库、Sybase数据库等数据库中的任意一个,本申请在此并不作限定。
在进一步的一种具体实施方式中,步骤S201获取当前区块高度Hx和本地区块高度H具体包括以下步骤:
在监测到Peer节点启动时,运行预设的交易总数状态机,获取时区块链账本中当前区块高度Hx;
从本地账本中获取本地区块高度H。
在本实施例中,在每个Peer节点均预设交易总数状态机,在监测到Peer节点启动时,运行上述预设的交易总数状态机,以获取区块链账本中的当前区块高度Hx,同时上述预设的交易总数状态机从本地账本中获取本地区块高度H,以便于识别区块链账本与本地账本的同步状态。
其中,在本实施例中预设的交易总数状态机,是指用于判断区块链账本与本地账本之间交易总数存储状态是否发生变化的有限状态机,有限状态机(Finite-state machine,FSM),又称有限状态自动机,是能够对有限个状态以及这些状态之间的转移、动作进行识别的网络虚拟机,上述预设的交易总数状态机也可以用于维护区块链账本与本地账本之间交易总数存储状态。
S202,根据当前区块高度Hx和本地区块高度H,判断区块链账本与本地账本的同步状态;
其中,交易总数状态机根据当前区块高度Hx和本地区块高度H,即可判断区块链账本与本地账本的同步状态,当交易总数状态机判断出当前区块高度Hx和本地区块高度H一致,则确定区块链账本与本地账本的同步状态为已同步,当交易总数状态机判断出当前区块高度Hx和本地区块高度H不一致,则确定区块链账本与本地账本的同步状态为未同步。
在本实施例中,预设在Peer节点的交易总数状态机根据当前区块高度Hx和本地区块高度H,对区块链账本与本地账本之间的同步状态进行判断,当区块链账本与本地账本的同步状态为已同步,即当交易总数状态机判断出当前区块高度Hx和本地区块高度H一致时,区块链账本中存储的交易总数信息与本地账本中存储的交易总数信息一致,因此可以通过预设接口从本地账本中读取对应的交易总数信息,并将读取到的交易总数信息作为查询结果;当区块链账本与本地账本的同步状态为未同步,即当交易总数状态机判断出当前区块高度Hx和本地区块高度H不一致时,区块链账本中存储的交易总数信息与本地账本中存储的交易总数信息也不一致,若此时读取本地账本的交易总数信息作为查询结果,则该查询结果存在误差,因此,当区块链账本与本地账本的同步状态为未同步时,不允许直接通过预设接口从本地账本中读取交易总数信息。
需要说明的是,区块链账本与本地账本之间存在三种同步状态,分别为未同步U、已同步S、已同步且可读R,具体说明如下:
未同步(U):Peer节点启动时,区块链账本中的交易总数信息与本地账本中的交易总数信息未进行同步,即本地账本中的本地区块高度H与区块链账本中的当前区块高度Hx不一致。
已同步(S):Peer节点启动时,区块链账本中的交易总数信息与本地账本中的交易总数信息已经进行同步,即本地账本中的本地区块高度H与区块链账本中的当前区块高度Hx一致。
已同步且可读(R):在区块链账本中的交易总数信息与本地账本中的交易总数信息已经进行同步的情况下,区块链上陆续有新的交易产生,并持续更新账本中的交易总数信息。
区块链账本与本地账本之间的同步状态由交易总数状态机根据当前区块高度Hx和本地区块高度H进行判断。
在进一步的一种具体实施方式中,步骤S202根据当前区块高度Hx和本地区块高度H,判断区块链账本和本地账本的同步状态具体包括:
当当前区块高度Hx=0时,确定同步状态为同步且可读R。
当当前区块高度Hx>0时,判断本地区块高度H是否与当前区块高度Hx一致。
若本地区块高度H与当前区块高度Hx一致,则确定同步状态为已同步且可读R,反之,则确定同步状态为未同步U。
其中,当区块链账本中的当前区块高度Hx为0时,表示区块链网络中还没有交易产生,即当前区块链账本中无交易记录,对应的本地账本中本地区块高度H也为0,交易总数状态机确定区块链账本与本地账本的同步状态为同步且可读R,并继续执行步骤S203;当区块链账本中的当前区块高度Hx大于0时,交易总数状态机首先判断本地账本中稍微本地区块高度H是否与区块链账本当前区块高度Hx一致,当本地区块高度H与当前区块高度Hx一致时,交易总数状态机确定区块链账本与本地账本的同步状态为已同步且可读R,并继续执行步骤S203;当本地区块高度H与当前区块高度Hx不一致,则确定区块链账本与本地账本的同步状态为未同步U,并继续执行以下步骤S301至步骤S304,具体请参照图3所示。
S301,若同步状态为未同步U,则将本地区块高度H到当前区块高度Hx范围内的区块作为待同步区块;
S302,遍历所有的待同步区块,得到每一个待同步区块的交易数;
S303,将每一个待同步区块的交易数与本地账本中原来的历史交易总数信息进行累加,以计算出新的历史交易总数信息;
S304,将新的历史交易总数信息更新到本地账本,以替换原来的历史交易总数信息,并将同步状态更新为已同步S。
其中,当交易总数状态机确定区块链账本与本地账本的同步状态为未同步U时,不允许直接通过本地账本直接查询交易总数信息,此时需要交易总数状态机对同步状态和交易总数信息进行更新后才可进行查询。具体为交易总数状态机将本地账本中本地区块高度H到区块链账本中的当前区块高度Hx范围内的所有区块作为待同步区块,交易总数状态机遍历所有的待同步区块,得到每一个待同步区块的交易数,将每一个待同步区块的交易数在原来的历史交易总数信息的基础上进行累加,即将每一个待同步区块的交易数与本地账本中原来的历史交易总数信息(原来的历史交易总数信息指的是根据本地账本中本地区块高度H的交易数计算出来的交易总数信息)进行累加,得出新的历史交易总数信息,将新的历史交易总数信息更新到本地账本,以替换原来的历史交易总数信息,并将同步状态更新为已同步S,并继续执行步骤S203。需要说明的是,当同步状态更新为已同步S时,即本地区块高度H与当前区块高度Hx一致,则本地账本中心的新的历史交易总数信息度等同于Hx的交易数计算出来的交易总数信息。
S203,若同步状态为已同步且可读R,或者,同步状态为已同步S,则对交易进行实时监测,当监测到有新交易产生时,获取新交易的交易数;
其中,当区块链账本与本地账本的同步状态为已同步S,则说明区块链账本的当前区块高度Hx与本地账本的本地区块高度H已经一致,并且在持续监测过程中,无新交易产生,也即在实时监测过程中,区块链账本与本地账本中的交易总数信息均未发生变化;当区块链账本与本地账本的同步状态为同步且可读R,则说明区块链账本的当前区块高度Hx与本地账本的本地区块高度H已经一致,并且在持续监测过程中,存在新交易产生,也即在实时监测过程中,区块链账本与本地账本中的交易总数信息均同步保持更新状态。
S204,根据新交易的交易数计算出当前交易总数信息,并将当前交易总数信息更新到本地账本;
其中,在区块链网络中,每一个新交易的完成,都会实时在区块链账本上记录新交易的交易信息,这里的交易信息包括交易数,交易总数状态机实时根据新交易的交易数计算出当前交易总数信息,并将当前交易总数信息更新到本地账本。
在进一步的一种具体实施方式中,步骤S204根据新交易的交易数计算出当前交易总数信息,并将当前交易总数信息更新到本地账本具体包括:
判断区块链账本与本地账本在新交易过程中的同步状态;
若同步状态为已同步S,则从本地账本中读取历史交易总数信息;
将新交易的交易数累加到历史交易总数信息上,得到新的当前交易总数信息;
将新的当前交易总数信息更新到本地账本,以替换原来的当前交易总数信息,并将同步状态更新为已同步且可读R。
在新交易过程中,交易总数状态机实时判断区块链账本与本地账本的同步状态,当同步状态为已同步且可读R,则根据新交易的交易数持续更新当前交易总数信息;当同步状态为已同步S,则首先从本地账本中读取历史交易总数信息,然后将新交易的交易数累加到历史交易总数信息上,得到新的当前交易总数信息,最后将新的当前交易总数信息更新到本地账本,以替换原来的当前交易总数信息(原来的当前交易总数信息指的是根据Peer节点启动时的当前区块高度Hx的交易数计算出来的交易总数信息),并将同步状态更新为已同步且可读R;当同步状态为未同步U,则继续执行执行步骤S302至步骤S304,并在区块链账本与本地账本之间的同步状态转变为已同步S情况下,再次执行步骤S204,以获得当前交易总数信息。需要说明的是,此时本地账本中的新的当前交易总数信息等同于Peer节点启动后陆续有新交易完成,根据Peer节点启动时当前区块高度Hx开始到最新区块高度的交易数计算出来的交易总数信息。
S205,在接收到交易总数查询请求时,基于同步状态,通过预设接口从本地账本中的历史交易总数信息或当前交易总数信息中读取对应的交易总数信息,并将读取到的交易总数信息作为查询结果,其中,查询结果为历史交易总数信息或当前交易总数信息。
其中,交易总数查询请求可以是用户通过用户端发起,用户端接收到用户的交易总数查询请求后,交易总数状态机判断接收到交易总数查询请求时区块链账本与本地账本之间的同步状态,然后基于区块链账本与本地账本之间不同的同步状态读取相应的交易总数信息,并将该交易总数信息作为查询结果,查询结果可以为历史交易总数信息或当前交易总数信息。
在本实施例中,区块链交易信息管理方法运行于其上的电子设备(例如图1所示的服务器/终端设备)可以通过有线连接方式或者无线连接方式接收交易总数查询的请求。需要指出的是,上述无线连接方式可以包括但不限于3G/4G连接、WiFi连接、蓝牙连接、WiMAX连接、Zigbee连接、UWB(ultra wideband)连接、以及其他现在已知或将来开发的无线连接方式。
在进一步的一种具体实施方式中,步骤S205中在接收到交易总数查询请求时,基于同步状态,通过预设接口从本地账本中的历史交易总数信息或当前交易总数信息中读取对应的交易总数信息具体包括:
判断接收到交易总数查询请求时的同步状态;
若接收到查询请求时,同步状态为已同步且可读R,则通过预设接口从本地账本中读取当前交易总数信息;
若接收到查询请求时,同步状态为已同步S,且没有新交易产生,则通过预设接口从本地账本中读取历史交易总数信息。
其中,交易总数状态机首先判断接收到交易总数查询请求时区块链账本与本地账本之间的同步状态,然后根据区块链账本与本地账本之间不同的同步状态读取相应的交易总数信息,并将该交易总数信息作为查询结果。具体的在本地账本中同时存储历史交易总数信息和当前交易总数信息,当接收到查询请求时,区块链账本与本地账本之间的同步状态为已同步且可读R,通过预设接口从本地账本中读取当前交易总数信息作为查询结果;当接收到查询请求时,区块链账本与本地账本之间的同步状态为已同步S,通过预设接口从本地账本中读取历史交易总数信息作为查询结果。需要进一步说明的是,区块链账本与本地账本之间的同步状态为已同步S,并且在监测过程中未产生新交易时,当前交易总数信息与历史交易总数信息是等同的。
作为本申请实施例的另一种更完整的实施方式,当接收到查询请求时,区块链账本与本地账本之间的同步状态为未同步U,则继续执行步骤S302至步骤S304,使得区块链账本与本 地账本之间的同步状态转变为已同步S,继续监测是否有新交易产生,当没有新交易产生时,通过预设接口从本地账本中读取历史交易总数信息作为查询结果,当有新交易产生时,将区块链账本与本地账本之间的同步状态转变为已同步且可读R,并通过预设接口从本地账本中读取当前交易总数信息作为查询结果。
所述方法根据区块链账本与本地账本的同步状态对交易进行实时监测,实现了本地账本中的交易总数信息与区块链账本中的交易总数信息的同步,在进行交易总数的查询时,根据同步状态,可以通过预设接口从本地账本中直接获取对应交易总数信息,与现有的区块链信息查询方式要求管理端对区块链网络中的每一区块进行遍历,以获取交易总数信息相比,本申请提供的区块链交易信息管理方法极大地提升了查询区块链交易总数信息的效率以及即时性,同时还节约了系统资源。
作为本申请实施例的另一种更完整的实施方式,步骤S202根据当前区块高度Hx和本地区块高度H,判断区块链账本和本地账本的同步状态之后,还包括步骤S301至步骤S304,具体可以参照图3所述。
S301,若同步状态为未同步U,则将本地区块高度H到当前区块高度Hx范围内的区块作为待同步区块;
S302,遍历所有的待同步区块,得到每一个待同步区块的交易数;
S303,将每一个待同步区块的交易数与本地账本中原来的历史交易总数信息进行累加,以计算出新的历史交易总数信息;
S304,将新的历史交易总数信息更新到本地账本,以替换原来的历史交易总数信息,并将同步状态更新为已同步S。
由于本实施例的具体实现方式已在其他实施例中描述,在此不作赘述。
作为本申请实施例的另一种更完整的实施方式,步骤S304将新的历史交易总数信息更新到本地账本,以替换原来的历史交易总数信息具体为:
S3041,采用二进制键值的存储方式将新的历史交易总数信息更新到本地账本,以替换原来的历史交易总数信息。
在本实施例中,采用二进制键值的存储方式将新的历史交易总数信息更新到本地账本,以替换原来的历史交易总数信息。具体的,在一具体实施方式中,当前链为testChain、当前链的区块高度为100、当前链的交易总数为1234,则存储的键为:testChain+totalTxNum,存储的值为(100,1234),其中totalTxNum为固定字符串。采用二进制键值的存储方式不仅提高了交易总数状态机判断区块链账本与本地账本之间的同步状态的效率,而且还有利于提高交易总数信息的更新效率。
由以上技术方案可知,本申请公开了一种区块链交易信息管理方法、装置、计算机设备及存储介质,所述方法通过获取当前区块高度Hx和本地区块高度H;根据当前区块高度Hx和本地区块高度H,判断区块链账本与本地账本的同步状态;若同步状态为已同步且可读R,或者,同步状态为已同步S,则对交易进行实时监测,当监测到有新交易产生时,获取新交易的交易数;根据新交易的交易数计算出当前交易总数信息,并将当前交易总数信息更新到本地账本;在接收到交易总数查询请求时,基于同步状态,通过预设接口从本地账本中的历史交易总数信息或当前交易总数信息中读取对应的交易总数信息,并将读取到的交易总数信息作为查询结果。所述方法根据区块链账本与本地账本的同步状态对交易进行实时监测,实现了本地账本中的交易总数信息与区块链账本中的交易总数信息的同步,在进行交易总数的查询时,根据同步状态,可以通过预设接口从本地账本中直接获取对应交易总数信息,与现有的区块链信息查询方式要求管理端对区块链网络中的每一区块进行遍历,以获取交易总数信息相比,本申请提供的区块链交易信息管理方法极大地提升了查询区块链交易总数信息的效率以及即时性,同时还节约了系统资源。
此外,本申请提供的一种区块链交易信息管理方法采用二进制键值的存储方式将交易总数信息存储在本地账本中,不仅提高了判断同步状态的效率,而且还有利于提高交易总数信 息的更新效率。
本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,是可以通过计算机程序来指令相关的硬件来完成,该计算机程序可存储于一计算机可读取存储介质中,该程序在执行时,可包括如上述各方法的实施例的流程。其中,前述的存储介质可为磁碟、光盘、只读存储记忆体(Read-Only Memory,ROM)等非易失性存储介质,或随机存储记忆体(Random Access Memory,RAM)等。
应该理解的是,虽然附图的流程图中的各个步骤按照箭头的指示依次显示,但是这些步骤并不是必然按照箭头指示的顺序依次执行。除非本文中有明确的说明,这些步骤的执行并没有严格的顺序限制,其可以以其他的顺序执行。而且,附图的流程图中的至少一部分步骤可以包括多个子步骤或者多个阶段,这些子步骤或者阶段并不必然是在同一时刻执行完成,而是可以在不同的时刻执行,其执行顺序也不必然是依次进行,而是可以与其他步骤或者其他步骤的子步骤或者阶段的至少一部分轮流或者交替地执行。
进一步参考图4,作为对上述图2所示方法的实现,本申请提供了一种区块链交易信息管理装置的一个实施例,该装置实施例与图2所示的方法实施例相对应,该装置具体可以应用于各种电子设备中。
如图4所示,本实施例所述的区块链交易信息管理装置包括:获取模块401、判断模块402、监测模块403、更新模块404以及查询模块405,其中:
获取模块401,用于获取当前区块高度Hx和本地区块高度H,其中,当前区块高度Hx为Peer节点启动时区块链账本中区块的高度,本地区块高度H为Peer节点启动时本地账本中区块的高度;
判断模块402,用于根据当前区块高度Hx和本地区块高度H,判断区块链账本与本地账本的同步状态;
监测模块403,用于若同步状态为已同步且可读R,或者,同步状态为已同步S,则对交易进行实时监测,当监测到有新交易产生时,获取新交易的交易数;
更新模块404,用于根据新交易的交易数计算出当前交易总数信息,并将当前交易总数信息更新到本地账本;
查询模块405,用于在接收到交易总数查询请求时,基于同步状态,通过预设接口从本地账本中的历史交易总数信息或当前交易总数信息中读取对应的交易总数信息,并将读取到的交易总数信息作为查询结果,其中,查询结果为历史交易总数信息或当前交易总数信息。
区块链交易信息管理装置根据区块链账本与本地账本的同步状态对交易进行实时监测,上述技术方案实现了本地账本中的交易总数信息与区块链账本中的交易总数信息的同步,在进行交易总数的查询时,可以根据需求通过预设接口从本地账本中直接获取对应交易总数信息,与现有的区块链信息查询方式要求管理端要对区块链网络中的每一区块进行遍历,以获取交易总数信息相比,本申请提供的区块链交易信息管理方法极大地提升了查询查询区块链交易总数信息的效率以及即时性,同时还节约了系统资源。
需要说明的是,判断模块402,用于根据当前区块高度Hx和本地区块高度H,判断区块链账本与本地账本的同步状态具体包括:
当当前区块高度Hx=0时,确定同步状态为同步且可读R;
当当前区块高度Hx>0时,判断本地区块高度H是否与当前区块高度Hx一致;
若本地区块高度H与当前区块高度Hx一致,则确定同步状态为已同步且可读R,反之,则确定同步状态为未同步U。
在本实施例的一些可选的实现方式中,获取模块401具体包括:第一获取单元和第二获取单元,其中:
第一获取单元,用于在监测到Peer节点启动时,运行预设的交易总数状态机,获取时区块链账本中当前区块高度Hx;
第二获取单元,用于从本地账本中获取本地区块高度H。
在本实施例的一些可选的实现方式中,更新模块404具体包括:第一判断单元、第一读取单元、计算单元和更新单元,其中:
第一判断单元,用于判断区块链账本与本地账本在新交易过程中的同步状态;
第一读取单元,若同步状态为已同步S,则从本地账本中读取历史交易总数信息;
计算单元,用于将新交易的交易数累加到历史交易总数信息上,得到新的当前交易总数信息;
更新单元,用于将新的当前交易总数信息更新到本地账本,以替换原来的当前交易总数信息,并将同步状态更新为已同步且可读R。
在本实施例的一些可选的实现方式中,查询模块405具体包括:第二判断单元、第二读取单元和第三读取单元,其中:
第二判断单元,用于判断接收到交易总数查询请求时的同步状态;
第二读取单元,用于若接收到查询请求时,同步状态为已同步且可读R,则通过预设接口从本地账本中读取当前交易总数信息;
第三读取单元,用于若接收到查询请求时,同步状态为已同步S,且没有新交易产生,则通过预设接口从本地账本中读取历史交易总数信息。
在本实施例的一些可选的实现方式中,上述区块链交易信息管理装置还包括未同步处理模块,用于若同步状态为未同步U,则将本地区块高度H到当前区块高度Hx范围内的区块作为待同步区块;
遍历所有的待同步区块,得到每一个待同步区块的交易数;将每一个待同步区块的交易数与本地账本中原来的历史交易总数信息进行累加,以计算出新的历史交易总数信息;将新的历史交易总数信息更新到本地账本,以替换原来的历史交易总数信息,并将同步状态更新为已同步S。
在本实施例的一些可选的实现方式中,未同步处理模块包括存储单元,用于采用二进制键值的存储方式将新的历史交易总数信息更新到本地账本,以替换原来的历史交易总数信息。
关于区块链交易信息管理装置的具体限定可以参见上文中对于区块链交易信息管理方法的限定,在此不再赘述。上述区块链交易信息管理装置中的各个模块可全部或部分通过软件、硬件及其组合来实现。上述各模块可以硬件形式内嵌于或独立于计算机设备中的处理器中,也可以以软件形式存储于计算机设备中的存储器中,以便于处理器调用执行以上各个模块对应的操作。
本申请公开的区块链交易信息管理装置根据区块链账本与本地账本的同步状态对交易进行实时监测,上述技术方案实现了本地账本中的交易总数信息与区块链账本中的交易总数信息的同步,在进行交易总数的查询时,可以根据需求通过预设接口从本地账本中直接获取对应交易总数信息,与现有的区块链信息查询方式要求管理端要对区块链网络中的每一区块进行遍历,以获取交易总数信息相比,本申请提供的区块链交易信息管理方法极大地提升了查询查询区块链交易总数信息的效率以及即时性,同时还节约了系统资源。
为解决上述技术问题,本申请实施例还提供计算机设备。具体请参阅图5,图5为本实施例计算机设备基本结构框图。
所述计算机设备6包括通过系统总线相互通信连接存储器61、处理器62、网络接口63。需要指出的是,图中仅示出了具有组件61-63的计算机设备6,但是应理解的是,并不要求实施所有示出的组件,可以替代的实施更多或者更少的组件。其中,本技术领域技术人员可以理解,这里的计算机设备是一种能够按照事先设定或存储的指令,自动进行数值计算和/或信息处理的设备,其硬件包括但不限于微处理器、专用集成电路(Application Specific Integrated Circuit,ASIC)、可编程门阵列(Field-Programmable Gate Array,FPGA)、数字处理器(Digital Signal Processor,DSP)、嵌入式设备等。
所述计算机设备可以是桌上型计算机、笔记本、掌上电脑及云端服务器等计算设备。所述计算机设备可以与用户通过键盘、鼠标、遥控器、触摸板或声控设备等方式进行人机交互。
所述存储器61至少包括一种类型的可读存储介质,所述可读存储介质包括闪存、硬盘、多媒体卡、卡型存储器(例如,SD或DX存储器等)、随机访问存储器(RAM)、静态随机访问存储器(SRAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、可编程只读存储器(PROM)、磁性存储器、磁盘、光盘等。在一些实施例中,所述存储器61可以是所述计算机设备6的内部存储单元,例如该计算机设备6的硬盘或内存。在另一些实施例中,所述存储器61也可以是所述计算机设备6的外部存储设备,例如该计算机设备6上配备的插接式硬盘,智能存储卡(Smart Media Card,SMC),安全数字(Secure Digital,SD)卡,闪存卡(Flash Card)等。当然,所述存储器61还可以既包括所述计算机设备6的内部存储单元也包括其外部存储设备。本实施例中,所述存储器61通常用于存储安装于所述计算机设备6的操作系统和各类应用软件,例如区块链交易信息管理方法的程序代码等。此外,所述存储器61还可以用于暂时地存储已经输出或者将要输出的各类数据。
所述处理器62在一些实施例中可以是中央处理器(Central Processing Unit,CPU)、控制器、微控制器、微处理器、或其他数据处理芯片。该处理器62通常用于控制所述计算机设备6的总体操作。本实施例中,所述处理器62用于运行所述存储器61中存储的程序代码或者处理数据,例如运行所述区块链交易信息管理方法的程序代码,以实现所述区块链交易信息管理方法,该方法至少包括:获取当前区块高度Hx和本地区块高度H,其中,所述当前区块高度Hx为Peer节点启动时区块链账本中区块的高度,所述本地区块高度H为Peer节点启动时本地账本中区块的高度;根据所述当前区块高度Hx和所述本地区块高度H,判断所述区块链账本与所述本地账本的同步状态;若所述同步状态为已同步且可读R,或者,所述同步状态为已同步S,则对交易进行实时监测,当监测到有新交易产生时,获取所述新交易的交易数;根据所述新交易的交易数计算出当前交易总数信息,并将所述当前交易总数信息更新到本地账本;在接收到交易总数查询请求时,基于所述同步状态,通过预设接口从所述本地账本中的历史交易总数信息或当前交易总数信息中读取对应的交易总数信息,并将读取到的所述交易总数信息作为查询结果,其中,所述查询结果为历史交易总数信息或当前交易总数信息。
所述网络接口63可包括无线网络接口或有线网络接口,该网络接口63通常用于在所述计算机设备6与其他电子设备之间建立通信连接。
本申请还提供了另一种实施方式,即提供一种计算机可读存储介质,所述计算机可读存储介质可以是非易失性,也可以是易失性,所述计算机可读存储介质存储有区块链交易信息管理方法的程序,所述区块链交易信息管理方法的程序可被至少一个处理器执行,以使所述至少一个处理器执行如上述的区块链交易信息管理方法的步骤,其中,所述区块链交易信息管理方法治沙包括:获取当前区块高度Hx和本地区块高度H,其中,所述当前区块高度Hx为Peer节点启动时区块链账本中区块的高度,所述本地区块高度H为Peer节点启动时本地账本中区块的高度;根据所述当前区块高度Hx和所述本地区块高度H,判断所述区块链账本与所述本地账本的同步状态;若所述同步状态为已同步且可读R,或者,所述同步状态为已同步S,则对交易进行实时监测,当监测到有新交易产生时,获取所述新交易的交易数;根据所述新交易的交易数计算出当前交易总数信息,并将所述当前交易总数信息更新到本地账本;在接收到交易总数查询请求时,基于所述同步状态,通过预设接口从所述本地账本中的历史交易总数信息或当前交易总数信息中读取对应的交易总数信息,并将读取到的所述交易总数信息作为查询结果,其中,所述查询结果为历史交易总数信息或当前交易总数信息。
显然,以上所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例,附图中给出了本申请的较佳实施例,但并不限制本申请的专利范围。本申请可以以许多不同的形式来实现,相反地,提供这些实施例的目的是使对本申请的公开内容的理解更加透彻全面。尽管参照前述实施例对本申请进行了详细的说明,对于本领域的技术人员来而言,其依然可以对前述各具体实施方式所记载的技术方案进行修改,或者对其中部分技术特征进行等效替换。凡是利用本申请说明书及附图内容所做的等效结构,直接或间接运用在其他相关的技术领域,均同理在本申请专利保护范围之内。

Claims (20)

  1. 一种区块链交易信息管理方法,其中,包括:
    获取当前区块高度Hx和本地区块高度H,其中,所述当前区块高度Hx为Peer节点启动时区块链账本中区块的高度,所述本地区块高度H为Peer节点启动时本地账本中区块的高度;
    根据所述当前区块高度Hx和所述本地区块高度H,判断所述区块链账本与所述本地账本的同步状态;
    若所述同步状态为已同步且可读R,或者,所述同步状态为已同步S,则对交易进行实时监测,当监测到有新交易产生时,获取所述新交易的交易数;
    根据所述新交易的交易数计算出当前交易总数信息,并将所述当前交易总数信息更新到本地账本;
    在接收到交易总数查询请求时,基于所述同步状态,通过预设接口从所述本地账本中的历史交易总数信息或当前交易总数信息中读取对应的交易总数信息,并将读取到的所述交易总数信息作为查询结果,其中,所述查询结果为历史交易总数信息或当前交易总数信息。
  2. 如权利要求1所述的区块链交易信息管理方法,其中,所述获取当前区块高度Hx和本地区块高度H具体包括:
    在监测到Peer节点启动时,运行预设的交易总数状态机,获取所述时区块链账本中所述当前区块高度Hx;
    从所述本地账本中获取所述本地区块高度H。
  3. 如权利要求1所述的区块链交易信息管理方法,其中,所述根据所述当前区块高度Hx和所述本地区块高度H,判断所述区块链账本和所述本地账本的同步状态具体包括:
    当所述当前区块高度Hx=0时,确定所述同步状态为同步且可读R;
    当所述当前区块高度Hx>0时,判断所述本地区块高度H是否与所述当前区块高度Hx一致;
    若所述本地区块高度H与所述当前区块高度Hx一致,则确定所述同步状态为已同步且可读R,反之,则确定所述同步状态为未同步U。
  4. 如权利要求3所述的区块链交易信息管理方法,其中,所述根据所述当前区块高度Hx和所述本地区块高度H,判断所述区块链账本和所述本地账本的同步状态之后,还包括:
    若所述同步状态为未同步U,则将所述本地区块高度H到所述当前区块高度Hx范围内的区块作为待同步区块;
    遍历所有的所述待同步区块,得到每一个所述待同步区块的交易数;
    将每一个待同步区块的交易数与所述本地账本中原来的历史交易总数信息进行累加,以计算出新的历史交易总数信息;
    将所述新的历史交易总数信息更新到本地账本,以替换所述原来的历史交易总数信息,并将所述同步状态更新为已同步S。
  5. 如权利要求4所述的区块链交易信息管理方法,其中,所述将所述新的历史交易总数信息更新到本地账本,以替换所述原来的历史交易总数信息具体为:
    采用二进制键值的存储方式将所述新的历史交易总数信息更新到本地账本,以替换所述原来的历史交易总数信息。
  6. 如权利要求1所述的区块链交易信息管理方法,其中,所述根据所述新交易的交易数计算出当前交易总数信息,并将所述当前交易总数信息更新到本地账本具体包括:
    判断所述区块链账本与所述本地账本在新交易过程中的同步状态;
    若所述同步状态为已同步S,则从所述本地账本中读取历史交易总数信息;
    将所述新交易的交易数累加到所述历史交易总数信息上,得到新的当前交易总数信息;
    将所述新的当前交易总数信息更新到本地账本,以替换原来的当前交易总数信息,并将 所述同步状态更新为已同步且可读R。
  7. 如权利要求1至6任意一项所述的区块链交易信息管理方法,其中,所述在接收到交易总数查询请求时,基于所述同步状态,通过预设接口从所述本地账本中的历史交易总数信息或当前交易总数信息中读取对应的交易总数信息具体包括:
    判断接收到所述交易总数查询请求时的所述同步状态;
    若接收到查询请求时,所述同步状态为已同步且可读R,则通过所述预设接口从本地账本中读取当前交易总数信息;
    若接收到查询请求时,所述同步状态为已同步S,且没有新交易产生,则通过所述预设接口从本地账本中读取历史交易总数信息。
  8. 一种区块链交易信息管理装置,其中,包括:
    获取模块,用于获取当前区块高度Hx和本地区块高度H,其中,所述当前区块高度Hx为Peer节点启动时区块链账本中区块的高度,所述本地区块高度H为Peer节点启动时本地账本中区块的高度;
    判断模块,用于根据所述当前区块高度Hx和所述本地区块高度H,判断所述区块链账本与所述本地账本的同步状态;
    监测模块,用于若所述同步状态为已同步且可读R,或者,所述同步状态为已同步S,则对交易进行实时监测,当监测到有新交易产生时,获取所述新交易的交易数;
    更新模块,用于根据所述新交易的交易数计算出当前交易总数信息,并将所述当前交易总数信息更新到本地账本;
    查询模块,用于在接收到交易总数查询请求时,基于所述同步状态,通过预设接口从所述本地账本中的历史交易总数信息或当前交易总数信息中读取对应的交易总数信息,并将读取到的所述交易总数信息作为查询结果,其中,所述查询结果为历史交易总数信息或当前交易总数信息。
  9. 一种计算机设备,包括存储器和处理器,所述存储器中存储有计算机程序,其中,所述处理器执行所述计算机程序时实现一种区块链交易信息管理方法的步骤,所述区块链交易信息管理方法包括:
    获取当前区块高度Hx和本地区块高度H,其中,所述当前区块高度Hx为Peer节点启动时区块链账本中区块的高度,所述本地区块高度H为Peer节点启动时本地账本中区块的高度;
    根据所述当前区块高度Hx和所述本地区块高度H,判断所述区块链账本与所述本地账本的同步状态;
    若所述同步状态为已同步且可读R,或者,所述同步状态为已同步S,则对交易进行实时监测,当监测到有新交易产生时,获取所述新交易的交易数;
    根据所述新交易的交易数计算出当前交易总数信息,并将所述当前交易总数信息更新到本地账本;
    在接收到交易总数查询请求时,基于所述同步状态,通过预设接口从所述本地账本中的历史交易总数信息或当前交易总数信息中读取对应的交易总数信息,并将读取到的所述交易总数信息作为查询结果,其中,所述查询结果为历史交易总数信息或当前交易总数信息。
  10. 如权利要求9所述的计算机设备,其中,所述获取当前区块高度Hx和本地区块高度H具体包括:
    在监测到Peer节点启动时,运行预设的交易总数状态机,获取所述时区块链账本中所述当前区块高度Hx;
    从所述本地账本中获取所述本地区块高度H。
  11. 如权利要求9所述的计算机设备,其中,所述根据所述当前区块高度Hx和所述本地区块高度H,判断所述区块链账本和所述本地账本的同步状态具体包括:
    当所述当前区块高度Hx=0时,确定所述同步状态为同步且可读R;
    当所述当前区块高度Hx>0时,判断所述本地区块高度H是否与所述当前区块高度Hx一 致;
    若所述本地区块高度H与所述当前区块高度Hx一致,则确定所述同步状态为已同步且可读R,反之,则确定所述同步状态为未同步U。
  12. 如权利要求11所述的计算机设备,其中,所述根据所述当前区块高度Hx和所述本地区块高度H,判断所述区块链账本和所述本地账本的同步状态之后,还包括:
    若所述同步状态为未同步U,则将所述本地区块高度H到所述当前区块高度Hx范围内的区块作为待同步区块;
    遍历所有的所述待同步区块,得到每一个所述待同步区块的交易数;
    将每一个待同步区块的交易数与所述本地账本中原来的历史交易总数信息进行累加,以计算出新的历史交易总数信息;
    将所述新的历史交易总数信息更新到本地账本,以替换所述原来的历史交易总数信息,并将所述同步状态更新为已同步S。
  13. 如权利要求12所述的计算机设备,其中,所述将所述新的历史交易总数信息更新到本地账本,以替换所述原来的历史交易总数信息具体为:
    采用二进制键值的存储方式将所述新的历史交易总数信息更新到本地账本,以替换所述原来的历史交易总数信息。
  14. 如权利要求9所述的计算机设备,其中,所述根据所述新交易的交易数计算出当前交易总数信息,并将所述当前交易总数信息更新到本地账本具体包括:
    判断所述区块链账本与所述本地账本在新交易过程中的同步状态;
    若所述同步状态为已同步S,则从所述本地账本中读取历史交易总数信息;
    将所述新交易的交易数累加到所述历史交易总数信息上,得到新的当前交易总数信息;
    将所述新的当前交易总数信息更新到本地账本,以替换原来的当前交易总数信息,并将所述同步状态更新为已同步且可读R。
  15. 一种计算机可读存储介质,其中,所述计算机可读存储介质上存储有计算机程序,所述计算机程序被处理器执行时实现一种区块链交易信息管理方法的步骤,所述区块链交易信息管理方法包括:
    获取当前区块高度Hx和本地区块高度H,其中,所述当前区块高度Hx为Peer节点启动时区块链账本中区块的高度,所述本地区块高度H为Peer节点启动时本地账本中区块的高度;
    根据所述当前区块高度Hx和所述本地区块高度H,判断所述区块链账本与所述本地账本的同步状态;
    若所述同步状态为已同步且可读R,或者,所述同步状态为已同步S,则对交易进行实时监测,当监测到有新交易产生时,获取所述新交易的交易数;
    根据所述新交易的交易数计算出当前交易总数信息,并将所述当前交易总数信息更新到本地账本;
    在接收到交易总数查询请求时,基于所述同步状态,通过预设接口从所述本地账本中的历史交易总数信息或当前交易总数信息中读取对应的交易总数信息,并将读取到的所述交易总数信息作为查询结果,其中,所述查询结果为历史交易总数信息或当前交易总数信息。
  16. 如权利要求15所述的计算机可读存储介质,其中,所述获取当前区块高度Hx和本地区块高度H具体包括:
    在监测到Peer节点启动时,运行预设的交易总数状态机,获取所述时区块链账本中所述当前区块高度Hx;
    从所述本地账本中获取所述本地区块高度H。
  17. 如权利要求15所述的计算机可读存储介质,其中,所述根据所述当前区块高度Hx和所述本地区块高度H,判断所述区块链账本和所述本地账本的同步状态具体包括:
    当所述当前区块高度Hx=0时,确定所述同步状态为同步且可读R;
    当所述当前区块高度Hx>0时,判断所述本地区块高度H是否与所述当前区块高度Hx一 致;
    若所述本地区块高度H与所述当前区块高度Hx一致,则确定所述同步状态为已同步且可读R,反之,则确定所述同步状态为未同步U。
  18. 如权利要求17所述的计算机可读存储介质,其中,所述根据所述当前区块高度Hx和所述本地区块高度H,判断所述区块链账本和所述本地账本的同步状态之后,还包括:
    若所述同步状态为未同步U,则将所述本地区块高度H到所述当前区块高度Hx范围内的区块作为待同步区块;
    遍历所有的所述待同步区块,得到每一个所述待同步区块的交易数;
    将每一个待同步区块的交易数与所述本地账本中原来的历史交易总数信息进行累加,以计算出新的历史交易总数信息;
    将所述新的历史交易总数信息更新到本地账本,以替换所述原来的历史交易总数信息,并将所述同步状态更新为已同步S。
  19. 如权利要求18所述的计算机可读存储介质,其中,所述将所述新的历史交易总数信息更新到本地账本,以替换所述原来的历史交易总数信息具体为:
    采用二进制键值的存储方式将所述新的历史交易总数信息更新到本地账本,以替换所述原来的历史交易总数信息。
  20. 如权利要求15所述的计算机可读存储介质,其中,所述根据所述新交易的交易数计算出当前交易总数信息,并将所述当前交易总数信息更新到本地账本具体包括:
    判断所述区块链账本与所述本地账本在新交易过程中的同步状态;
    若所述同步状态为已同步S,则从所述本地账本中读取历史交易总数信息;
    将所述新交易的交易数累加到所述历史交易总数信息上,得到新的当前交易总数信息;
    将所述新的当前交易总数信息更新到本地账本,以替换原来的当前交易总数信息,并将所述同步状态更新为已同步且可读R。
PCT/CN2020/085823 2019-11-25 2020-04-21 区块链交易信息管理方法、装置、计算机设备及存储介质 WO2021103403A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201911164204.8A CN110928950A (zh) 2019-11-25 2019-11-25 区块链交易信息管理方法、装置、计算机设备及存储介质
CN201911164204.8 2019-11-25

Publications (1)

Publication Number Publication Date
WO2021103403A1 true WO2021103403A1 (zh) 2021-06-03

Family

ID=69851744

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/085823 WO2021103403A1 (zh) 2019-11-25 2020-04-21 区块链交易信息管理方法、装置、计算机设备及存储介质

Country Status (2)

Country Link
CN (1) CN110928950A (zh)
WO (1) WO2021103403A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US11316921B2 (en) * 2020-09-25 2022-04-26 Alipay (Hangzhou) Information Technology Co., Ltd. Block synchronization methods and apparatuses

Families Citing this family (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110928950A (zh) * 2019-11-25 2020-03-27 深圳壹账通智能科技有限公司 区块链交易信息管理方法、装置、计算机设备及存储介质
US11233640B2 (en) * 2020-05-13 2022-01-25 Ridgeline, Inc. Mutation processing for events
US11949784B2 (en) 2020-05-13 2024-04-02 Ridgeline, Inc. Auditing for events
CN111694852A (zh) * 2020-05-28 2020-09-22 平安科技(深圳)有限公司 基于分布式事务的数据处理方法、装置、终端及存储介质
CN112988891B (zh) * 2021-03-11 2023-04-21 重庆文理学院 存储区块链账本的方法、装置、电子设备及存储介质
CN113469679A (zh) * 2021-05-11 2021-10-01 深圳前海移联科技有限公司 区块链庞氏骗局智能合约的识别方法、系统及电子设备

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109299336A (zh) * 2018-09-30 2019-02-01 腾讯科技(深圳)有限公司 数据备份方法、装置、存储介质及计算设备
US20190311357A1 (en) * 2018-04-04 2019-10-10 Vijay Madisetti Method and System for Exchange of Value or Tokens Between Blockchain Networks
CN110365768A (zh) * 2019-07-15 2019-10-22 腾讯科技(深圳)有限公司 分布式系统的数据同步方法、装置、介质、电子设备
CN110490590A (zh) * 2019-09-27 2019-11-22 腾讯科技(深圳)有限公司 基于区块链的活动记录查询方法、装置、设备及存储介质
CN110928950A (zh) * 2019-11-25 2020-03-27 深圳壹账通智能科技有限公司 区块链交易信息管理方法、装置、计算机设备及存储介质

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108985757B (zh) * 2017-11-27 2021-03-30 京东数字科技控股有限公司 信息处理方法、装置及系统、存储介质、电子设备
CN108776929A (zh) * 2018-04-02 2018-11-09 成都云创智融科技有限公司 基于区块链数据库的账单处理方法、系统和可读存储介质
CN110245190B (zh) * 2019-06-11 2021-11-02 南京荣链科技有限公司 一种区块数据分段存储方法、终端及介质

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20190311357A1 (en) * 2018-04-04 2019-10-10 Vijay Madisetti Method and System for Exchange of Value or Tokens Between Blockchain Networks
CN109299336A (zh) * 2018-09-30 2019-02-01 腾讯科技(深圳)有限公司 数据备份方法、装置、存储介质及计算设备
CN110365768A (zh) * 2019-07-15 2019-10-22 腾讯科技(深圳)有限公司 分布式系统的数据同步方法、装置、介质、电子设备
CN110490590A (zh) * 2019-09-27 2019-11-22 腾讯科技(深圳)有限公司 基于区块链的活动记录查询方法、装置、设备及存储介质
CN110928950A (zh) * 2019-11-25 2020-03-27 深圳壹账通智能科技有限公司 区块链交易信息管理方法、装置、计算机设备及存储介质

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US11316921B2 (en) * 2020-09-25 2022-04-26 Alipay (Hangzhou) Information Technology Co., Ltd. Block synchronization methods and apparatuses

Also Published As

Publication number Publication date
CN110928950A (zh) 2020-03-27

Similar Documents

Publication Publication Date Title
WO2021103403A1 (zh) 区块链交易信息管理方法、装置、计算机设备及存储介质
CN109299336B (zh) 数据备份方法、装置、存储介质及计算设备
CN110275884B (zh) 数据存储方法及节点
WO2022126974A1 (zh) 基于Kafka的增量数据同步方法、装置、设备及介质
US10097659B1 (en) High performance geographically distributed data storage, retrieval and update
CN110599169B (zh) 数据处理方法、装置、终端及介质
CN109726174A (zh) 数据归档方法、系统、设备以及存储介质
WO2022143540A1 (zh) 区块链索引的存储方法、装置、计算机设备及介质
CN107357896A (zh) 数据库集群的扩容方法、装置、系统和数据库集群系统
CN112380227B (zh) 基于消息队列的数据同步方法、装置、设备及存储介质
CN109885786A (zh) 数据缓存处理方法、装置、电子设备及可读存储介质
CN113034281A (zh) 基于区块链的业务数据处理方法、相关系统及节点
CN112182004A (zh) 实时查看数据方法、装置、计算机设备及存储介质
EP3269098B1 (en) Large data management in communication applications through multiple mailboxes
US8959248B2 (en) Personal computing environment with virtual computing device
US20160269339A1 (en) Architecture for large data management in communication applications through multiple mailboxes
CN103812912B (zh) 一种维护组织结构信息的方法及装置
CN113361236A (zh) 一种编辑文档的方法和装置
CN114218586B (zh) 商业数据智能管理方法、装置、电子设备及存储介质
CN116028517A (zh) 一种融合数据库系统及电子设备
KR102416336B1 (ko) 블록체인을 관리하기 위한 장치, 방법, 시스템 및 컴퓨터 판독가능 저장 매체
CN112800066A (zh) 索引管理的方法、相关设备及存储介质
CN112487065A (zh) 一种数据检索方法和装置
CN112685557A (zh) 可视化信息资源管理方法及装置
CN111030856B (zh) 一种基于云的数据接入方法、电子设备及计算机可读介质

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20892541

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

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

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

122 Ep: pct application non-entry in european phase

Ref document number: 20892541

Country of ref document: EP

Kind code of ref document: A1