Method and device for monitoring block information, equipment and storage medium
By configuring data identifiers for blockchain data points and detecting and re-acquiring intermittent data identifiers, the problem of poor reliability of monitored block information is solved, thereby improving the data consistency and execution reliability of the business system.
Patent Information
- Application Number
- CN202511723286.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-21
- Publication Date
- 2026-02-27
AI Technical Summary
The reliability of monitoring block information in existing technologies is poor, and data points are easily missed or duplicated, which affects the security of business systems.
By configuring unique data identifiers for data points in the blockchain, detecting gaps in data identifiers, and re-acquiring data points in the block until continuous data identifiers are obtained, the integrity of data points is ensured.
It improves the reliability of block information monitoring, ensures the consistency of data points in the business system, and enhances the reliability and security of business execution.
Smart Images

Figure CN121585330A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of blockchains, and in particular to a method and device for monitoring block information, an apparatus, and a storage medium. BACKGROUND
[0002] Monitoring the blockchain enables a business system to obtain data points in the blockchain, so as to execute corresponding businesses based on the data points in the blockchain.
[0003] In related technologies, a high-periodic polling is performed on blocks, and the blocks of the blockchain are monitored in batches. However, this method cannot discover whether the data points in the blocks are adjacent in time, and is prone to missing or repeating the data points, which leads to poor reliability of monitoring the block information and affects the security of the business system in executing businesses based on the monitored data. SUMMARY
[0004] The present disclosure provides a method and device for monitoring block information, an apparatus, and a storage medium, aiming to solve the problem of poor reliability of monitoring block information in related technologies and affecting the security of a business system. The technical solutions of the present disclosure are as follows. According to an aspect of an embodiment of the present application, a method for monitoring block information is provided, which includes the following steps: Obtaining a plurality of data points of at least one block from a blockchain based on a subscription mechanism of the blockchain; any data point is any information recorded in the block; and any data point has a unique data identifier in the block; If the data identifiers of the data points belonging to the same block in the plurality of data points are discontinuous, the data points of the block are re-obtained until the data points with continuous data identifiers in the block are obtained.
[0005] In a possible implementation manner, If any data point is any transaction in the block, the data identifier is a transaction index number; or If any data point is an event log of any transaction, the data identifier is an event index number. Obtaining a plurality of data points of at least one block from a blockchain includes: Obtaining a plurality of data points of a block corresponding to a block number from the blockchain according to the block number.
[0006] In a possible implementation manner, before obtaining a plurality of data points of at least one block from a blockchain, the method further includes: Obtaining a first block number of the blockchain; the first block is a current highest block number of the blockchain; Determining that a difference between the first block number and a second block number that has been obtained satisfies a difference condition; the second block number is a highest block number that has been obtained from the blockchain through the subscription mechanism; Retrieve multiple data points from at least one block of the blockchain, including: Obtain multiple data points from each block from the second block number to the first block number from the blockchain.
[0007] In one possible implementation, after obtaining the data points identified by consecutive data identifiers in the block, the method further includes: After obtaining the data points of N blocks following the block through the subscription mechanism, the subscription status corresponding to the block is set to a confirmed state; Synchronize each data point in a block that is in a defined state to the corresponding service.
[0008] In one possible implementation, before determining that there is a discontinuity in the data identifiers of data points belonging to the same block among multiple data points, the method further includes: Determine the first hash value of the first block containing at least one data point; If the second hash value of the first block exists in the subscribed record, then the first hash value is determined to be consistent with the second hash value; the subscribed record contains the block to which any data point obtained through the subscription mechanism belongs, and the hash value corresponding to the block.
[0009] In one possible implementation, the subscription record also records the subscription status of the block, and the method further includes: If the first hash value is inconsistent with the second hash value, then each data point of the first block obtained based on the subscription mechanism will be rolled back until the third hash value of the second block in the subscribed record is consistent with the fourth hash value of the second block obtained from the blockchain; the block height of the second block is lower than the block height of the first block.
[0010] In one possible implementation, the method further includes: Multiple blockchains can be subscribed to separately, with each blockchain having its own subscription mechanism to achieve physical isolation.
[0011] According to two aspects of the present disclosure, an apparatus for monitoring block information is provided, the apparatus for monitoring block information comprising the following modules.
[0012] The acquisition module is used to acquire multiple data points from at least one block of the blockchain based on the subscription mechanism of the blockchain; each data point is any information recorded in the block; each data point has a unique data identifier in the block.
[0013] The reacquisition module is used to reacquire data points of a block when there are gaps in the data identifiers of data points belonging to the same block among multiple data points, until all data points with consecutive data identifiers in the block are obtained.
[0014] In one possible implementation, if any data point is any transaction in a block, then the data identifier is the transaction index number; or if any data point is the event log of any transaction, then the data identifier is the event index number. The acquisition module is used to retrieve multiple data points from the blockchain based on the block number.
[0015] In one possible implementation, the device for monitoring block information further includes: a subscription triggering module for obtaining the first block number of the blockchain; the first block number is the current highest block number of the blockchain; determining that the difference between the first block number and the obtained second block number satisfies a difference condition; the second block number is the highest block number obtained from the blockchain through the subscription mechanism; The aforementioned acquisition module is used to obtain multiple data points from each block from the second block number to the first block number in the blockchain.
[0016] In one possible implementation, the device for monitoring block information further includes a state transition module, which is used to set the subscription state corresponding to the block to a determined state after obtaining the data points of N blocks after the block through the subscription mechanism; and to synchronize each data point in the block in the determined state to the corresponding service.
[0017] In one possible implementation, the device for monitoring block information further includes: a hash value comparison module, used to determine a first hash value of a first block to which at least one data point belongs; and, if a second hash value of the first block exists in the subscribed record, to determine that the first hash value is consistent with the second hash value; the subscribed record contains the block to which any data point obtained through the subscription mechanism belongs, and the hash value corresponding to the block.
[0018] In one possible implementation, the subscription record also records the subscription status of the block, and the device for monitoring block information further includes: a block rollback module, used to roll back each data point of the first block obtained based on the subscription mechanism when the first hash value and the second hash value are inconsistent, until the third hash value of the second block in the subscription record is consistent with the fourth hash value of the second block obtained from the blockchain; the block height of the second block is lower than the block height of the first block.
[0019] In one possible implementation, the device for monitoring block information further includes a subscription module for subscribing to multiple blockchains separately, each blockchain having its own subscription mechanism to achieve physical isolation.
[0020] According to a third aspect of the present disclosure, an electronic device for monitoring block information is provided, comprising: a processor; and a memory for storing processor-executable instructions; wherein the processor is configured to execute the instructions to implement the method as described in any one of the first aspects above.
[0021] According to a fourth aspect of the present disclosure, a computer-readable storage medium is provided such that, when instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to perform any of the methods described in the first aspect of the present disclosure.
[0022] According to a fifth aspect of the present disclosure, a computer program product is provided, including computer instructions that, when executed by a processor, cause a computer to perform the method described in any one of the first aspects of the present disclosure.
[0023] The technical solutions provided by the embodiments of this disclosure have at least the following beneficial effects: In summary, by configuring data identifiers for data points, after retrieving multiple data points from a block based on a subscription mechanism, the system can detect whether any data points in the same block are missing by checking for gaps between their data identifiers. This allows for timely retrieval of missing data points from the blockchain if necessary. Consequently, this helps ensure that the data points retrieved by the business system are consistent with the data points included in the blockchain blocks, improving the reliability of block information monitoring.
[0024] Furthermore, ensuring that no data points are missed in the block helps the business system execute corresponding business operations based on the monitored block information. Therefore, it helps improve the reliability of business execution in the business system and maintain the order of business execution. Attached Figure Description
[0025] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure, and are not intended to unduly limit this disclosure.
[0026] Figure 1 This is a schematic diagram illustrating an application environment according to an exemplary embodiment; Figure 2 This is a flowchart illustrating a method for monitoring block information according to an exemplary embodiment; Figure 3 This is a flowchart illustrating a method for monitoring block information according to another exemplary embodiment; Figure 4 This is a flowchart illustrating a method for monitoring block information according to yet another exemplary embodiment; Figure 5 This is a schematic diagram illustrating multi-chain independent listening according to an exemplary embodiment; Figure 6 This is a block diagram illustrating an apparatus for monitoring block information according to an exemplary embodiment; Figure 7 This is a structural block diagram of an electronic device applied to monitoring block information, according to an exemplary embodiment. Detailed Implementation
[0027] To enable those skilled in the art to better understand the technical solutions of this disclosure, the technical solutions in the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings.
[0028] It should be noted that the terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this disclosure are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this disclosure described herein can be implemented in orders other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this disclosure. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this disclosure as detailed in the appended claims.
[0029] Please see Figure 1 , Figure 1 This is a schematic diagram illustrating an application environment according to an exemplary embodiment, such as... Figure 1 As shown, the application environment may include computer device 01 and server 02.
[0030] In an optional embodiment, the computer device 01 is used to execute a method for monitoring block information. Specifically, the computer device 01 may be, but is not limited to, electronic devices such as smartphones, desktop computers, tablets, laptops, and digital assistants. Optionally, the operating system running on the computer device 01 may include, but is not limited to, Android, iOS, Linux, and Windows.
[0031] Optionally, computer device 01 is a backend device of the business system, used to listen to block information and parse the corresponding business based on the block information, so that the business system can complete the corresponding business after a new transaction is generated in the blockchain.
[0032] In one optional embodiment, server 02 is a node in the blockchain used to process, verify, or broadcast transactions. Server 02 can be a node in the blockchain, for example, server 02 is a full node in the blockchain. Specifically, server 02 can be a standalone physical server, a server cluster or distributed system consisting of multiple physical servers, or a cloud server.
[0033] Optionally, computer device 01 synchronizes block information (e.g., block data points, see the embodiments below for details) in the blockchain from server 02 through a subscription mechanism in order to synchronize block information in the blockchain.
[0034] In addition, it should be noted that, Figure 1 The example shown is merely one application environment of the method for monitoring block information provided in this disclosure.
[0035] In the embodiments described in this specification, the computer device 01 and the server 02 can be directly or indirectly connected through wired or wireless communication, and this application does not impose any restrictions on this.
[0036] In one exemplary embodiment, computer device 01 obtains block data points from the blockchain corresponding to server 02 according to a subscription mechanism; if block data points are missing, computer device 01 re-obtains block data points.
[0037] The block information monitoring method provided in this application is used to correctly obtain block data points from the blockchain, avoiding data point omissions or duplications, thereby ensuring the consistency between the data points pulled by the computer device and the data points of the blocks in the blockchain. The block data points obtained from the blockchain can be parsed into the corresponding business functions in the business system, thus ensuring the consistency between the business functions in the business system and the data points in the blockchain, thereby helping to improve the reliability of business execution.
[0038] Optionally, the business systems provided in this application embodiment include, but are not limited to, at least one of the following: a banking business system, or a game business system, etc.
[0039] For example, in a banking system, data points in a block can be parsed into banking transactions. The consensus mechanism of the blockchain ensures the reliability of the data points, making the parsed transactions more reliable. This helps to improve the security of the banking system and reduce business risks.
[0040] For example, in a game business system, the data points in a block can be parsed into game business. Due to the consensus mechanism of the blockchain, the data points are guaranteed to be reliable, which makes the game business obtained from the parsing of the block information also reliable. This helps to prevent the game behavior executed in the game business system from being tampered with, helps to prevent problems such as cheating in the game business system, and improves the fairness of the game business system.
[0041] It should be noted that the following diagram illustrates one possible sequence of steps, and it is not strictly required to follow this order. Some steps can be performed in parallel without interdependence. The user information (including but not limited to user device information, user personal information, user behavior information, etc.) and data (including but not limited to data used for display, training data, etc.) involved in this disclosure are all information and data authorized by the user or fully authorized by all parties.
[0042] Figure 2 This is a flowchart illustrating a method for monitoring block information according to an exemplary embodiment. Exemplarily, the method for monitoring block information can be... Figure 1 The computer device 01 in the middle is executed.
[0043] like Figure 2 As shown, the method for monitoring block information may include the following steps: Step 210: Based on the blockchain subscription mechanism, obtain multiple data points from at least one block of the blockchain.
[0044] Each data point is any piece of information recorded in a block; each data point has a unique data identifier in a block.
[0045] Blockchain is a decentralized, distributed digital ledger technology. A blockchain consists of blocks arranged chronologically; each block includes at least one transaction, and each transaction corresponds to at least one event. Transactions record state changes in the shared ledger; the events corresponding to transactions refer to the actions taken by smart contracts within the blockchain when executing transactions. These events can be recorded in a transaction log. For example, each transaction has an event log, which records all events corresponding to the transaction. During the execution of a transaction, each time an event is generated by a smart contract, that event is recorded in the transaction's event log.
[0046] Optionally, a block includes at least one data point. In this embodiment, a data identifier is configured for each data point, and different data points are distinguished by the data identifier. The data identifier of a data point is used to indicate the location of the data point in the block on the blockchain.
[0047] For example, the data identifier includes at least one identifier element. Comparing the data identifiers of any two data points, there is at least one different identifier element. This at least one identifier element is obtained from the blockchain; for example, the blockchain's block header or block body includes the identifier element of the data point. The computer device obtains at least one identifier element of the data point from the blockchain and obtains the data identifier of the data point based on the identifier element.
[0048] In some embodiments, the data point type includes at least one of the following: a transaction in a block, or an event log of a transaction; multiple data points may be of the same type. For example, if the data point is an event log of a transaction, then step 210 is implemented as follows: the computer device retrieves event logs of multiple transactions from at least one block in the blockchain.
[0049] In some embodiments, a blockchain subscription mechanism is used to retrieve multiple transactions from at least one block of the blockchain. These multiple data points can be the sum of all data points from each of the at least one block.
[0050] Optionally, the subscription mechanism for the blockchain includes at least one of the following: an active subscription mechanism, or a passive subscription mechanism.
[0051] In the active subscription mechanism, computer devices obtain multiple data points from the blockchain by sending subscription requests. For example, a computer device sends a subscription request to a full node in the blockchain system to receive multiple data points sent by the full node, which holds a complete copy of the blockchain.
[0052] In the passive subscription mechanism, after the computer device establishes a communication connection with the blockchain, it sends a push request to the blockchain. The push subscription request is used to request the blockchain to send multiple data points from at least one block to the computer device if the push conditions are met.
[0053] For example, a push request includes at least one of the following: Periodic pushes, for example, every s seconds, the blockchain pushes multiple data points to the computer device, where s is a positive number; Pushing new blocks: For example, after adding q blocks in the blockchain, push multiple data points, where q is a positive integer; Confirm push notifications, for example, pushing multiple data points of a block when a block is confirmed.
[0054] In some embodiments, for each block in at least one block, after obtaining the data points of that block, the computer device obtains the data identifiers of the data points belonging to that block and determines whether there is a gap between the data identifiers of multiple data points belonging to that block. If there is a gap between multiple data points, the computer device executes step 220. If there is no gap, the service corresponding to the data point can be executed after the data point is switched to a confirmed state.
[0055] Step 220: If there is a gap in the data identifiers of data points belonging to the same block among multiple data points, then reacquire the data points of the block until the data points with continuous data identifiers in the block are obtained.
[0056] In this context, a discontinuity in the data identifiers of data points belonging to the same block refers to a skipped number in the data identifiers of data points within the same block. For example, if the difference between the data identifiers of the first and second data points in a block is minimal and greater than 1, then it indicates a discontinuity in the data identifiers of the data points in that block.
[0057] For example, among multiple data points, those belonging to Block 1 include data point a, data point b, and data point c. Data point a has a data identifier of 1, data point b has a data identifier of 2, and data point c has a data identifier of 4. For data point c, the first difference between its data identifier and that of data point b is 2, and the second difference between its data identifier and that of data point a is 3. The first difference is smaller than the second difference; therefore, the difference between the data identifiers of data point b and data point c is the smallest. Furthermore, since the first difference is greater than 1, it indicates a discontinuity in the data identifiers of data point b and data point c. This suggests that there are other data points between data point b and data point c, with a data identifier of 3. These other data points were missed when multiple data points were retrieved based on the subscription mechanism. To maintain the order of data points belonging to the same block as the order of data points in that block on the blockchain, it is necessary to retrieve the data points from that block again.
[0058] Optionally, to improve the efficiency of determining whether the data identifiers of data points belonging to the same block are discontinuous, the computer device sorts the data point identifiers of each data point belonging to the same block. For example, in determining whether the data identifiers of data points are discontinuous, the computer device first sorts the acquired data identifiers of each data point belonging to the same block to obtain a data identifier sequence; for any two adjacent data identifiers in the data identifier sequence, if the difference between the adjacent data identifiers is not 1, it indicates that there is an interval between data points belonging to the same block.
[0059] For example, if the total number of data points belonging to the same block is N, the computer device obtains the smallest data identifier min1 from the N data identifiers belonging to the same block, records the smallest data identifier min1, and deletes min1 from the N data identifiers; then, the computer device obtains the smallest data identifier min2 from the N-1 data identifiers; if the difference between data identifier min2 and data identifier min1 is 1, then the smallest data identifier min2 is recorded, and min2 is deleted from the N-1 data identifiers; the above operation is repeated until the N data identifiers have been traversed.
[0060] During the judgment process, if the difference between data identifier min i and data identifier min i-1 is greater than 1, then there is a gap between data identifier min1 and data identifier min2. There is at least one data block that should be missed between the data block corresponding to data identifier min1 and the data block corresponding to data identifier min2. Here, i is a positive integer less than or equal to N and greater than 1.
[0061] The format of the data identifier for a data point is related to the type of data point.
[0062] In one possible implementation, a data point is any transaction within a block, and the corresponding data identifier for a data point includes a transaction index number. That is, the identifier element includes the transaction index number.
[0063] The transaction index number is used to represent the order of transactions within a block. Different transactions within the same block have different transaction index numbers, while transaction index numbers in different blocks can be the same or different. In a blockchain, the transaction index numbers of each transaction within the same block are determined from smallest to largest according to the order in which the transactions were added to the block.
[0064] For example, a block may contain four transactions: transaction a, transaction b, transaction c, and transaction d. Transactions a, b, c, and d are added to the block sequentially. Transaction a has an index number of 0, transaction b has an index number of 1, transaction c has an index number of 2, and transaction d has an index number of 3. It should be noted that this embodiment is only used to illustrate one form of transaction index number for transactions within the same block and does not represent a limitation on the representation of transaction index numbers.
[0065] Optionally, when the data point is a transaction in a block, at least one identifier element may also include a block number, which is used to identify the position of the block to which the transaction belongs in the blockchain. The block number may also be referred to as the block height of the block in the blockchain.
[0066] For example, the transaction data identifier is in the form of a tuple, such as (block number, transaction index number) or (transaction index number, block number).
[0067] When a transaction's data identifier includes a block number, even if two transactions belonging to different blocks have the same transaction index number, this index number is different from the block number in the data identifier, thus allowing them to be distinguished from each other. This helps prevent confusion between transactions with the same transaction index number in different blocks during the monitoring process, thereby improving the reliability of monitoring block information.
[0068] In another possible implementation, the data point is the event log of any transaction, and the corresponding data point identifier includes the event index number.
[0069] For example, different transactions have logs, which record at least one event corresponding to the transaction. In this embodiment of the application, the event log refers to the event entries in the transaction log used to record one or more events, and these one or more events may correspond to a business in the business system.
[0070] The event index number is used to represent the order in which the events corresponding to a transaction occur. A transaction may correspond to multiple events, and the event index numbers of these events are arranged chronologically in the transaction's event log. For example, the event index number is the sequence number of the event in the transaction's log.
[0071] Optionally, when the data point is the event log of any transaction, at least one identifier element further includes at least one of the following: a block number, or a transaction index number. For the event log of any transaction, the event log belongs to a transaction, the transaction belongs to a block, the transaction index number in the data identifier of the event log is used to indicate the block to which the event log belongs, and the block number in the data identifier of the event log is used to indicate the block to which the event log belongs.
[0072] For example, the data identifier of a transaction's event log includes an event index number and a transaction index number. For instance, the data identifier of a transaction's event log may be (event index number, transaction index number), or (transaction index number, event index number).
[0073] For example, the data identifier of a transaction's event log includes: block number, transaction index number, and event index number. The data identifier of a transaction's event log can be in the form of a triple, for example, the data identifier of a transaction's event log is: (block number, transaction index number, event index number).
[0074] Incorporating event index numbers into the mechanism for listening to block information helps to achieve event-level listening to blocks obtained from the blockchain. Furthermore, data identification can ensure event continuity, guarantee the correct order of listened events, and prevent duplication.
[0075] When the data identifier includes at least two identifier elements, the sorting of the data point identifiers includes sorting the at least two identifier elements lexicographically.
[0076] For example, the data point is the event log of a transaction. The data identifier of the transaction event log is (block number, transaction index number, event log number). The lexicographical sorting is implemented by first comparing the block number, then comparing the transaction index number, and finally comparing the event log number. In this case, the data identifier discontinuity of the data point refers to the discontinuity of the event log number included in the data identifier. The definition of discontinuity is as described in the above embodiment and will not be repeated here.
[0077] Specifically, for the event logs of two adjacent transactions within the same block and the same transaction, the event logs of the two transactions have the same block number, the same transaction index number, and an interval of 1 between the event log numbers.
[0078] Optionally, in order to ensure that the acquired data points are synchronized with the data points in the block, if the data identifier of a data point belonging to a certain block is discontinuous, the computer device may reacquire all data points in that block.
[0079] For example, the computer device sends a re-retrieval request to the blockchain, wherein the re-retrieval request includes the block number of the block; after re-retrieving the data points in the block, the computer device re-executes step 220 until there are no gaps in the data identifiers of data points belonging to the same block.
[0080] In some embodiments, after obtaining the data points with consecutive data identifiers in the block, the computer device writes each data point into a data point list according to the order of the data point identifiers. The data point list is used to indicate the order between the data points. Each data point corresponds to an entry in the data point list, and the entry corresponding to the data point is used to store the data point and its data identifier.
[0081] In some embodiments, the method further includes step 230 ( Figure 2 (Not shown in the image).
[0082] Step 230: Execute the business operations corresponding to each of the multiple data points.
[0083] For example, step 230 is an optional step.
[0084] Optionally, the business logic corresponding to the data point is used to complete the corresponding operation in the business system. This allows the blockchain-based data points to achieve the corresponding business effects within the business system.
[0085] Taking a banking system as an example, the events corresponding to data points include, but are not limited to: subscription, redemption, or net asset value update.
[0086] After obtaining data points from the blockchain, the corresponding business operations are executed in the business system. By leveraging the security advantages of the blockchain system, the reliability of business execution in the business system is ensured.
[0087] In summary, by configuring data identifiers for data points, after retrieving multiple data points from a block based on a subscription mechanism, the system can detect whether any data points in the same block are missing by checking for gaps between their data identifiers. This allows for timely retrieval of missing data points from the blockchain if necessary. Consequently, this helps ensure that the data points retrieved by the business system are consistent with the data points included in the blockchain blocks, improving the reliability of block information monitoring.
[0088] Furthermore, ensuring that no data points are missed in the block helps the business system execute corresponding business operations based on the monitored block information. Therefore, it helps improve the reliability of business execution in the business system and maintain the order of business execution.
[0089] In one possible implementation, step 210, obtaining multiple data points from at least one block of the blockchain, includes: obtaining multiple data points of the block corresponding to the block number from the blockchain according to the block number.
[0090] Optionally, the computer device determines the block number of at least one block, and generates and sends a subscription request based on the at least one block number; and receives multiple data points of the block corresponding to the block number.
[0091] For example, the subscription request may include a portion of the block number from at least one block number, or may include all of the block numbers from at least one block number.
[0092] In one example, a computer device retrieves multiple data points from a block corresponding to a block number from the blockchain, grouped according to the block number. For instance, at least one block comprises multiple blocks, and the computer device determines the block number corresponding to each of the multiple blocks, resulting in a total of multiple block numbers; it then groups the multiple block numbers to obtain at least two groups of block numbers; based on each group of block numbers, it generates and sends a subscription request, which includes that group of block numbers, and retrieves multiple data points from the blockchain corresponding to at least one group of block numbers.
[0093] For example, the smallest unit of a group can be a block, meaning that at least one block of data points can be obtained through a subscription request.
[0094] For example, multiple block numbers include: block number 1, block number 2, block number 3, block number 4, block number 5, and block number 6; wherein, block number 1 and block number 2 belong to one group of block numbers, block number 3 and block number 4 belong to one group of block numbers, and block number 5 and block number 6 belong to one group of block numbers; the computer device generates subscription request 1 including block number 1 and block number 2, and sends subscription request 1 to obtain the data point of the block corresponding to block number 1, and the data point of the block corresponding to block number 2.
[0095] Optionally, after dividing multiple blocks into at least two groups of blocks, the computer device generates corresponding subscription requests based on at least two groups of blocks. The computer device sends subscription requests in ascending order of block numbers. After sending a subscription request and obtaining the data points of the block corresponding to a group of block numbers from the blockchain, if it is determined that the data identifiers of the data points belonging to that block are uninterrupted, the next subscription request is sent, until all subscription requests have been sent. In this way, by sending subscription requests sequentially, and ensuring that the data identifiers of the data points corresponding to a group of block numbers are uninterrupted before sending the next subscription request, the total number of data points of blocks that need to be re-obtained is reduced, thereby reducing unnecessary communication overhead.
[0096] On the one hand, grouping multiple blocks allows computer devices to retrieve data points from each block in groups from the blockchain. Compared to retrieving data points from multiple blocks at once, grouping data points helps reduce the transmission resources required for a single data point transmission and also helps shorten the time required for a single data point retrieval, thereby improving the efficiency of data point retrieval from blocks.
[0097] On the other hand, considering that if a block in the blockchain changes, the data points of that block will also change, resulting in the need to reacquire the data points of at least one block, this embodiment obtains the data points of each block in groups. This makes it convenient to selectively reacquire the data points of the changed blocks after a block changes, thereby reducing the total number of data blocks that need to be reacquired and thus helping to reduce unnecessary data acquisition.
[0098] The following is combined with Figure 3 This application introduces another method for monitoring block information, as provided in its embodiments. Figure 3 As shown, this method includes the following steps: Step 310: Obtain the first block number of the blockchain. The first block is the highest block number in the current blockchain.
[0099] In some embodiments, the computer device obtains the first block number from the blockchain through another subscription mechanism. This other subscription mechanism is used to periodically obtain the current highest block number of the blockchain.
[0100] Optionally, the computer device acquires a cursor of the blockchain, the cursor of which includes the first block number. The cursor is used to indicate the latest position in the blockchain.
[0101] For example, the cursor in the blockchain also includes a first transaction index number and a first event index number, wherein the first transaction index number is the highest transaction index number in the block corresponding to the current highest block number, and the first event index number is the highest event index number in the event log of the transaction corresponding to the current highest transaction index number.
[0102] In one example, the blockchain cursor takes the form of a triple, such as (block number, transaction index number, event index number). In this case, the blockchain cursor can be the same as the data identifier of the latest event of the latest transaction in the blockchain.
[0103] Optionally, the computer device periodically obtains the latest block number of the blockchain based on a polling mechanism. This polling mechanism involves obtaining a cursor of the blockchain every p seconds to obtain the highest block number of the blockchain within the current polling period, where p is a positive integer.
[0104] Step 320: Determine that the difference between the first block number and the acquired second block number satisfies the difference condition; the second block number is the highest block number that has been acquired from the blockchain through the subscription mechanism.
[0105] Optionally, the second block number is the highest historical block number obtained from the blockchain. For example, the second block number is the highest block number obtained from the blockchain in a previous polling cycle.
[0106] In one example, during the first polling cycle, the server retrieves the second block number from the blockchain and records it, for example, by retrieving the second cursor from the blockchain to obtain the second block number. During the second polling cycle, the server retrieves the first block number from the blockchain, for example, by retrieving the first cursor from the blockchain to obtain the first block number. The server then determines whether the difference between the first block number and the second block number satisfies the difference condition. If the difference between the first block number and the second block number satisfies the difference condition, the computer device executes step 330. If the difference between the first block number and the second block number does not satisfy the difference condition, the computer device waits for the next polling cycle to retrieve the new highest block number from the blockchain.
[0107] In some embodiments, the difference condition includes: the difference between the first block number and the second block number is greater than or equal to the block interval M, where M is a positive integer. M is a preset value, such as M=2, 4, 5, 6, 8, 10, 12, etc.
[0108] Optionally, the block interval M is also called the confirmation depth. For example, the confirmation depth of a blockchain is equal to 6, and the difference condition includes the difference between the first block and the second block being greater than 6.
[0109] For example, the greater the confirmation depth, the lower the risk of the block corresponding to the second block number in the blockchain being tampered with. This reduces the likelihood that after obtaining multiple data points in subsequent step 330, there will be changed data points among the obtained data points, which would require obtaining multiple data points again.
[0110] In one example, the computer device is equipped with a cursor table to record the cursors of the blockchain. The format of the blockchain cursor is (block number, transaction index number, event index number). After the blockchain is created, the computer device initializes the blockchain cursor to (0, 0, 0). Subsequently, the current cursor of the blockchain is obtained in each polling cycle.
[0111] Optionally, the second block number is stored in a cursor table. If the difference between the first block number and the second block number satisfies a difference condition, the computer device stores the first block number in the cursor table. For example, a cursor including the first block number is added to the cursor table.
[0112] Optionally, Figure 2 In the corresponding embodiment, step 210 can be implemented as step 330 below.
[0113] Step 330: Obtain multiple data points from each block from the second block number to the first block number from the blockchain.
[0114] For example, assuming the second block number is 10 and the first block number is 13, then each block includes: block number 11, block number 12 and block number 13; or, each block includes: block number 10, block number 11 and block number 12.
[0115] For example, in the process of acquiring multiple data points, the computer device generates and sends subscription request 1 based on block number 10, which includes block number 10, in order to acquire the data points of the block corresponding to block number 10, and so on.
[0116] In this example, multiple data points from the first block number to the second block number are acquired in groups, by data block, reducing the total amount of data acquired each time and helping to reduce the data receiving pressure on the computer equipment during a single data point acquisition process.
[0117] Step 340: If there is a gap in the data identifiers of data points belonging to the same block among multiple data points, then reacquire the data points of the block until the data points with continuous data identifiers in the block are obtained.
[0118] For details regarding step 340, please refer to the embodiment corresponding to step 220, which will not be repeated here.
[0119] By setting the difference between the first block number and the second block number to meet the difference condition, multiple data points are triggered to be retrieved. This is equivalent to waiting for the block corresponding to the second block number to become stable before retrieving the data points of the second block. This helps to avoid the computer device repeatedly retrieving data points from the blockchain, thereby reducing the number of times the data points of the second block are repeatedly retrieved, and thus helping to reduce the total transmission overhead of retrieving the data points of the second block.
[0120] In some embodiments, such as Figure 3 As shown, methods for monitoring block information also include: Step 350: After obtaining the data points of N blocks following the block through the subscription mechanism, set the subscription status of the corresponding block to the confirmed state.
[0121] Where N is a positive integer, representing the final confirmation depth of a block in the blockchain. For example, N is greater than or equal to M.
[0122] Optionally, for any block in the blockchain, if the number of blocks between the block and the latest block in the blockchain is greater than or equal to N, the subscription state corresponding to the block is a deterministic state; if the number of blocks between the block and the latest block in the blockchain is less than N, the subscription state corresponding to the block is a non-deterministic state.
[0123] For example, a deterministic state indicates that the corresponding block is a trusted block, and correspondingly, the block's data points are trusted data points, meaning that the block's data points will not be tampered with. Conversely, a non-deterministic state indicates that the corresponding block is an untrusted block, in which case the block's data points are untrusted data points, and the data points are at risk of being tampered with.
[0124] For example, after obtaining multiple data points of at least one block (including blocks from the second block number to the first block number) from the blockchain in step 330, the subscription state corresponding to the at least one block is in a non-deterministic state.
[0125] For example, a state machine is set up in the computer device to maintain the subscription state corresponding to the blocks obtained from the blockchain; after obtaining multiple data points of at least one block, the state machine sets the state corresponding to at least one block to a non-deterministic state; for each block in at least one block, after the computer device obtains data points of other blocks, if the difference between the block number of the block and the block number of other blocks is greater than or equal to N, the state machine changes the subscription state corresponding to the block from the non-deterministic state to the subscription state.
[0126] Step 360: Synchronize each data point in the block that is in a defined state to the corresponding service.
[0127] Optionally, each data point in a block in a defined state is a trusted data point, and the computer device executes the services corresponding to each data point in the block in a defined state.
[0128] For example, the data point is the event log of the transaction, and the business corresponding to the data point is the business corresponding to the event in the event log.
[0129] Whether the business corresponding to a data point is executed depends on the subscription status of the block to which the data point belongs. Executing the business corresponding to the data point in a block with a defined state helps to ensure the accurate execution sequence of each business.
[0130] Optionally, there is no strict execution sequence between steps 350 and 340. Step 350 can be executed before or after step 340, or steps 340 and 350 can be executed in parallel.
[0131] For example, step 360 is executed only after step 340 and step 350 have been completed, in order to avoid missing multiple events obtained from the blockchain and thus ensure the correct order of real-time business.
[0132] By maintaining the subscription state corresponding to each block, and synchronizing each data point in the block to its corresponding business function when the subscription state is certain, the business function corresponding to the data point in the block can only be executed when the block is in a certain state. In this way, by linking the subscription state of the block to the executable nature of the business function corresponding to the data point in the block, compared to executing the business function corresponding to the data point in the block before blockchain confirmation, this embodiment helps avoid situations where the business function executed in the business system cannot correspond to the data point in the blockchain after the block is modified. This avoids executing unnecessary business functions, thereby improving the reliability of business execution in the business system and ensuring the security of business execution.
[0133] In this embodiment of the application, steps 330, 340, 350 and 360 can constitute another method for monitoring block information. In this case, "multiple data points of each block from the second block number to the first block number" in step 330 can be replaced with "data points of at least one block" described in step 210. For a detailed description of each step, please refer to the corresponding embodiment of the step, which will not be repeated here.
[0134] The following is combined with Figure 4 This section introduces another method for monitoring block information.
[0135] For example, in this embodiment, a mechanism for monitoring block information to detect block reorganization is provided so that after the blockchain is reorganized, the computer device can detect the blockchain reorganization (hereinafter referred to as chain reorganization) in a timely manner and take corresponding rollback measures, thereby preventing the business corresponding to the data point of the rollback block from being executed, which helps to improve the reliability of business execution.
[0136] Optionally, in order to detect blockchain reorganization, this embodiment maintains a subscribed record, which records the acquired hash value of the block, and is used to detect the reorganization status of the blockchain.
[0137] like Figure 4 As shown, the method for monitoring block information also includes the following steps: Step 410: Based on the blockchain subscription mechanism, obtain multiple data points of at least one block from the blockchain.
[0138] Optionally, after acquiring data points for at least one block, the state machine sets the subscription status corresponding to each block in the at least one block to an pending state and maintains the subscription status corresponding to the at least one block.
[0139] For example, the services corresponding to data points in blocks that are in an undetermined state will not be executed temporarily.
[0140] Step 420: Determine the first hash value of the first block containing at least one data point.
[0141] Optionally, the first block is a block in a non-deterministic state among the blocks maintained by the computer device. For example, the first block can be a block that has been listened to for the first time, or it can be a block that has been listened to at least once.
[0142] For example, at least one block includes a first block; or, the block number of the first block is less than or equal to the block number of any of the at least one blocks, that is, the first block was added to the blockchain before at least one block.
[0143] Optionally, at least one data point belongs to the first block, and at least one data point is a data point of the first block. For example, multiple data points include at least one data point, or the data points acquired by the computer device (in addition to the multiple data points acquired in step 410) include the aforementioned at least one data point.
[0144] Optionally, the hash value of the first block is used to uniquely identify the first block in the blockchain system. The hash value of the first block is calculated by the nodes in the blockchain system based on the hash algorithm and recorded in the block header.
[0145] The hash value of the first block is closely related to the data points within it; changes in the data points within the first block will alter its hash value. For example, changes in the data points within the first block will also change the hash values of other blocks in the blockchain with a higher hash value than the first block.
[0146] The first hash value of the first block is the current hash value of the first block, which is the hash value of the first block obtained when step 420 is executed. Optionally, the computer device can obtain the hash value of the blockchain in a non-deterministic state from the blockchain according to the subscription mechanism; or, obtaining the hash value of the block can be independent of the subscription mechanism.
[0147] For example, when a new block is added to the blockchain, the computer device retrieves the hash value of the block that is in a non-deterministic state from the blockchain. For instance, when a new block is added to the blockchain, the computer device retrieves the hash values of the new block, as well as the hash values of the N blocks preceding it, and stores the retrieved hash values of the N blocks in a subscription record.
[0148] Where N is the final confirmation depth. For example, the (N+1)th block before the new block is in a confirmed state, and the hash value of this block usually does not change. Therefore, there is no need to obtain the hash value of the (N+1)th block before the new block, so as to reduce the total storage space occupied by storing the hash value of the block.
[0149] For example, there is no strict execution sequence between steps 410 and 420. Step 420 may be executed before or after step 410.
[0150] For example, it should be understood that the method for listening to block information is to execute multiple rounds in a loop, that is, the computer device executes step 410 once every certain period of time, or, as... Figure 3 In a corresponding embodiment, step 410 is triggered when the difference between the first block number and the second block number meets a difference condition. Therefore, step 410 can be executed before step 420 at times, and after step 420 at other times.
[0151] Step 430: If the second hash value of the first block exists in the subscribed record, then the first hash value and the second hash value are determined to be consistent.
[0152] The subscribed records contain the block to which any data point has been acquired through the subscription mechanism, and the hash value corresponding to the block.
[0153] For example, the subscribed records include a hash table, which contains at least one entry, with one entry corresponding to each block. This entry records at least one hash value corresponding to that block, with each hash value determined for a different time period. For instance, a computer device retrieves the hash value of block 1 from the blockchain at times 1, 2, and 3, respectively, obtaining hash value 1, hash value 2, and hash value 3. Hash value 1, hash value 2, and hash value 3 are stored in the corresponding entry in the hash table for block 1.
[0154] For example, after determining the first hash value of the first block, the computer device adds the first hash value to the entry corresponding to the first block in the hash value.
[0155] The second hash value is the historical hash value of the first block.
[0156] For example, after obtaining the first hash value of the first block, the computer device checks whether the first hash value and the second hash value blockchain are consistent from the subscribed records; if the first hash value is consistent with the second hash value, then step 440 is executed; if the first hash value is inconsistent with the second hash value, then step 450 is executed.
[0157] By comparing the hash value of a block with the hash value of that block in the subscribed records, off-chain business systems can detect whether the blockchain has been reorganized. If it is determined that the blockchain has not been reorganized, the system can continue to listen for block information based on the listening progress, thereby helping to ensure that the data points obtained by the computer devices are consistent with the data points in the blockchain.
[0158] Step 440: If there is a gap in the data identifier of the data points belonging to the same block among multiple data points, then reacquire the data points of the block until the data points with continuous data identifiers in the block are obtained.
[0159] For a detailed explanation of step 440, please refer to step 210, which will not be repeated here.
[0160] Step 450: If the first hash value is inconsistent with the second hash value, roll back each data point of the first block obtained based on the subscription mechanism until the third hash value of the second block in the subscribed record is consistent with the fourth hash value of the second block obtained from the blockchain.
[0161] The block height of the second block is lower than that of the first block.
[0162] If the first hash value and the second hash value are inconsistent, it indicates that a blockchain reorganization occurred after the second hash value was obtained, and the data points in the first block may have changed. Inconsistent hash values mean that the hash values are not equal, or that at least one character in the hash values is different.
[0163] The subscribed records also contain the subscription status of the corresponding blocks. For example, the subscribed records also include a status table to record the subscription status of the blocks that have been monitored.
[0164] Optionally, the subscription status corresponding to a block includes: undetermined status, determined status, and rollback status. The rollback status is used to indicate that the corresponding block has failed due to blockchain reorganization. Accordingly, in order to ensure the consistency between the business system and the blockchain system, it is necessary to retrieve the data points of the block from the blockchain based on the block number of the block.
[0165] For example, if the first hash value and the second hash value are inconsistent, the computer device will convert the subscription state corresponding to the first block to a rollback state.
[0166] A block in a rollback state is also called a rollback block, and the data points of the rollback block that the computer device has acquired are also called rollback data points. For example, in step 450, each data point of the first block is called a rollback data point.
[0167] For example, the computer device synchronizes blocks in a rollback state to the business system. That is, the business corresponding to the data points in the rollback blocks is also in a rollback state, and these business operations are temporarily not executed.
[0168] Optionally, if the first hash value and the second hash value are inconsistent, the computer device determines the second block from all blocks with block numbers lower than the first block. The second block is the ancestor node during blockchain reorganization, and the hash values of other blocks in the blockchain with heights higher than the second block are inconsistent with the hash values of their respective subscribed records. The second block is called the ancestor block of the first block. The blockchain reorganization corresponding to the inconsistency between the first and second hash values of the first block is due to a fork in the sub-chain after the second block in the blockchain. Among the blocks monitored by the computer device, all blocks with block heights greater than the second block are rollback blocks. The data points of the rollback blocks can be obtained based on step 210, and step 220 ensures that no data points of the rollback blocks obtained from the blockchain are omitted.
[0169] In some embodiments, if the first hash value and the second hash value of the first block are inconsistent, and if at least one block contains a third block with a block number greater than that of the second block, the method further includes: discarding the data points of the third block obtained in step 410. That is, the data points of the third block obtained in step 410 are not stored, and it is also determined whether the data identifiers of the data points of the third block obtained in step 410 are discontinuous, so as to re-obtain the data points of the block corresponding to the target block after blockchain reorganization from the blockchain system based on the target block number of the third block.
[0170] Step 460: Based on the blockchain subscription mechanism, retrieve multiple data points from the first block of the blockchain.
[0171] The specific implementation of step 460 is similar to that of step 210 and various related implementations. Please refer to the above embodiments for details, which will not be repeated here.
[0172] Step 470: If there is a gap in the data identifiers of multiple data points in the first block, then reacquire the multiple data points of the first block until the data points with continuous data identifiers in the first block are obtained.
[0173] Step 480: Execute the business corresponding to multiple data points.
[0174] Optionally, after obtaining the data points identified by consecutive data identifiers in the block, the computer device parses multiple data points to obtain the services corresponding to each data point.
[0175] For example, when the subscription status corresponding to a data point is in a determined state, the computer device executes the service corresponding to the data point. For instance, the computer device executes the services corresponding to each data point in a determined state one by one, according to their order in the data point list. For the data point subscription status maintenance process, please refer to the following embodiments.
[0176] This embodiment also supports and Figure 3 In the corresponding embodiment, step 410 is triggered based on the satisfaction of the difference condition between the first block number and the second block number, in order to reduce the frequency of retrieving multiple data points from the blockchain. Optionally, in this case, if the hash value of the first block is inconsistent with the hash value of the second block, the blockchain cursor is also rolled back to the second block, so that the method of listening to block information starts execution from the second block in the blockchain, that is, the method of listening to block information is replayed.
[0177] This embodiment uses the historical hash value of the cached block to compare the consistency between the current hash value and the historical hash value of the same block, thereby detecting whether a blockchain reorganization has occurred. If a blockchain reorganization occurs, the rollback mechanism automatically triggers the re-acquisition of data points in the rollback block, ensuring that the business rollback of the business system is consistent with the block rollback in the blockchain system, thus guaranteeing a one-to-one correspondence between the business execution in the business system and the data points in the blockchain system.
[0178] In one possible implementation, the method further includes subscribing to multiple blockchains separately, each blockchain having its own subscription mechanism to achieve physical isolation.
[0179] In some embodiments, multiple blockchains are associated with business systems, and data points in multiple blockchains can be resolved to business operations within the business systems.
[0180] Subscribing to multiple blockchains means that the subscription mechanisms of the multiple blockchains are independent of each other.
[0181] Alternatively, the subscription mechanisms of computer devices to multiple blockchains are isolated from each other and do not interfere with each other.
[0182] For example, multiple blockchains each have independent storage space and processing instance. The processing instance corresponding to each blockchain is used to execute the method for listening to block information for that blockchain. The storage space corresponding to each blockchain is used to record data points in that blockchain, such as data required or generated during the execution of the method for listening to block information for that blockchain.
[0183] like Figure 5 As shown, the method for listening to block information in blockchain 1 uses subscription mechanism 1, and the data required for the execution of the method for listening to block information in blockchain is stored in data partition 1; the method for listening to block information in blockchain 2 uses subscription mechanism 2, and the data required for the execution of the method for listening to block information in blockchain is stored in data partition 2, thereby realizing independent listening and data storage for each blockchain.
[0184] The processing instance includes at least one of the following: an entity processor, or logic in a virtual machine used to run listening block information.
[0185] The storage space corresponding to the blockchain is used to store the blockchain's storage tables, which include, but are not limited to, the cursor table, event list, or subscribed records as described in the above embodiments. Subscribed records include at least one of a hash value table and a state table.
[0186] Optionally, the storage space corresponding to the blockchain includes multiple data partitions in the database, and these multiple data partitions are isolated from each other in the database.
[0187] For example, multiple blockchains are configured with different primary keys in the database. The primary key of the blockchain is globally unique in the database, so that data related to each blockchain can be read and written through the primary key of its respective blockchain, avoiding the confusion between the data of different blockchains.
[0188] In this way, the business system can support querying the event log of a single blockchain, listen to the event logs of multiple blockchains in parallel, enable an independent processing instance for each blockchain, bind a dedicated cursor table, a dedicated event queue and a dedicated event handler, and include the chain number in the database primary key, thereby achieving physical isolation of the data corresponding to each blockchain.
[0189] Furthermore, this approach allows the business system to provide a unified query interface that supports multi-dimensional filtering by blockchain number, event type, subscription status, etc. The underlying system queries each blockchain in parallel and then aggregates and returns the results, balancing the isolation between the corresponding data of each blockchain with the convenience of the operation provided by the business system.
[0190] Optionally, in response to a user's query operation on a first asset, the computer device determines at least one blockchain associated with the first asset, obtains sub-query results of the first asset from each of the at least one blockchain, merges the sub-query results of the at least one blockchain to obtain the query result, and then feeds back the query result.
[0191] The subquery result of the first asset in the blockchain is used to represent the amount of the first asset that the user owns in the blockchain.
[0192] For example, the same asset is issued on both blockchain 1 and blockchain 2. The blockchain 1 instance writes to the data partition with chain_id=1, and the blockchain 2 instance writes to the data partition with chain_id=137. When a user queries their total asset share through the query interface provided by the business system, the business system searches in parallel on both data partitions, aggregating and returning the total cross-chain asset share. However, the data points on the two blockchains are physically isolated to avoid confusion and ensure storage security. Furthermore, during auditing and accounting, data points from either blockchain can be exported, thus helping to meet various auditing and accounting needs and improving audit processing efficiency.
[0193] In one example, based on this, the method further includes: obtaining the contract address of at least one blockchain, wherein at least one blockchain is associated with the business system; determining a first blockchain from at least one blockchain based on the contract address of at least one blockchain and the contract address of the blockchain that has been monitored, wherein the first blockchain is a blockchain that has not been monitored; determining the first monitoring mechanism corresponding to the first blockchain; obtaining multiple data points of at least one block from the first blockchain through the first monitoring mechanism; and continuing to execute the method of monitoring block information for the first block.
[0194] Optionally, upon detecting an association between the first blockchain and the business system, a corresponding processing instance is created for the first blockchain, and corresponding storage space is allocated. The storage table for the first blockchain is established and initialized, and the cursor for the first blockchain is initialized. Subsequently, the method for monitoring block information for the first blockchain is executed. Specific implementations of the method for monitoring block information for multiple blockchains can be found in the embodiments described above and will not be repeated here.
[0195] For example, the business system adds a compliant token corresponding to a new fund, with the new contract address being 0x5678. After comparing the hash differences, the business system only establishes a new subscription for 0x5678, while the cursors on other blockchains are retained, and historical data points (such as historical events) on other blockchains can still be queried. In the blockchain system, once the issuance event of the new fund is detected, it can enter the event queue, waiting for the corresponding business to handle it automatically, achieving seamless switching on the business side.
[0196] For newly associated blockchains in the business system, the new blockchain can be subscribed to separately without affecting the listening mechanism of other blockchains that are already being monitored. There is no need to restart the monitoring service, and there will be no interruption on the business side due to restarting the monitoring service. The block information of the newly added blockchain can be monitored without the business side being aware of it, thus realizing hot update of blockchain monitoring.
[0197] In another example, based on this, the method further includes: obtaining the contract address of at least one blockchain, wherein at least one blockchain is associated with the business system; determining a second blockchain from the monitored blockchains based on the contract address of at least one blockchain and the contract address of the monitored blockchain, wherein the second blockchain is a blockchain that has been monitored but removed by the business system; canceling the second monitoring mechanism corresponding to the second blockchain; and no longer monitoring the data points of blocks in the second blockchain, so that the business system no longer executes the transactions corresponding to the data points in the second blockchain.
[0198] The following example illustrates a method for monitoring block information. Specifically, this example demonstrates the process of monitoring block information on a blockchain.
[0199] In this embodiment, the business system is a banking business system. The data point of the block corresponds to the data point of the asset subscription block in the business system, which is the transaction event log. The blockchain is set with a cursor, which indicates the latest event in the blockchain. The data identifier of the event log is in the form of a triple, specifically (block number, transaction index number, event index number).
[0200] For example, the computer device is provided with a cursor table for recording the cursor of the blockchain; an event list for recording continuous events with event index numbers from blocks listened to from the blockchain; and data identifiers for transaction logs.
[0201] The execution process of the method for monitoring block information is as follows: 1. Initialization and triggering of blockchain cursors, and acquisition of event logs. After the bank system powers on, the computer device initializes the blockchain cursor, specifically (0, 0, 0). The computer device reads the last cursor recorded in the cursor table and obtains the second block number based on that cursor. Since there is only one cursor in the cursor table at this time, the second block number is "0".
[0202] Computer devices periodically obtain the latest cursor of the blockchain through a polling mechanism. As new blocks are continuously added to the blockchain, the highest block number in the blockchain changes, and the cursor obtained through polling also changes.
[0203] For example, if a computer device obtains the first block number 103 from the blockchain and the last cursor recorded in the cursor table is (100, 5, 0), then the second block number is 100.
[0204] The block interval M=2. The difference between the first block number and the second block number (3) is greater than the block interval. The computer device pulls the event logs of multiple transactions with block numbers 101, 102 and 103 from the blockchain through the subscription mechanism.
[0205] For example, a computer device generates at least two subscription requests using block numbers 101, 102, and 103 to pull transaction logs for multiple transactions in blocks 101, 102, and 103. Blocks 101 and 102 are grouped together, while block 103 is in a separate group.
[0206] Subsequently, the computer device retrieves a new cursor from the blockchain and records the cursor in the cursor table.
[0207] 2. Event log capture and adjacency determination
[0208] The computer equipment determines the data identifier for each event log entry it retrieves. For event logs of transactions within the same block, it assesses the contiguousness of the data identifiers to avoid gaps in the data identifiers. The data identifier for each event log entry is (block number, transaction index number, event index number), and the comparison of these data identifiers follows a lexicographical order.
[0209] For example, the computer device's memory temporarily stores the data identifier of the previous event log. The previous data identifier is compared with the data identifier of the next event log in lexicographical order. Specifically, the block number is compared first. If the block numbers are equal, the transaction index number is compared. If the transaction index numbers are equal, the event index number is compared.
[0210] If the location of the event log is not continuous with the location of the stored event log, it is determined to be a skip number. The missing event log is immediately retrieved again in both event intervals until the location is continuous without any skip numbers. Only then is the cursor updated and subsequent processing begins to ensure that the real-time stream events are strictly continuous.
[0211] For example, a transaction in block 100 includes two event logs. The computer device in the business system obtains an event log with data identifier (100, 0, 0) and an event log with data identifier (100, 0, 1). The data identifiers of the two event logs conform to lexicographical order, and the contiguousness determination passes.
[0212] Subsequently, the computer device obtains the event log with data identifier (104, 0, 3) and finds that the event log of block number 102 is missing, the event log of block number 103 is missing, and the event log of event index numbers 0, 1, and 2 in block number 104 is missing. That is, the data identifier of the event log is discontinuous. Therefore, the computer device pulls all the events from blocks 102 to 104 from the blockchain again to ensure that the real-time subscription order is correct.
[0213] 3. Blockchain reorganization perception and event log state rollback
[0214] This section is used to monitor whether a fork has occurred in the blockchain, causing a blockchain reorganization, that is, some old blocks in the blockchain are abandoned, and the event logs of the abandoned old blocks are invalid, so they need to be processed.
[0215] Optionally, the computer device maintains a "block number → block hash" mapping of the most recent N blocks in memory, where N is the final confirmation depth of the blockchain, meaning that for the current block to be fully confirmed, it needs to wait for N blocks to be added to the blockchain after it. For example, the "block number → block hash" mapping is stored in a hash value table.
[0216] For example, the computer device obtains the block number of the same block multiple times through polling, and compares the hash value of the block with the recorded hash value in each round. If the two hash values of the same block number are different, it is determined that a blockchain reorganization has occurred. The computer device finds the ancestor block at the fork in the blockchain and sets the subscription status of all blocks above the ancestor block in the blockchain to "rolled_back".
[0217] Correspondingly, the status of the pending event log in the block that is in the "rolled_back" subscription state also changes to "rolled_back". The blockchain cursor rolls back to the ancestor block, re-requests the event log of at least one block in the new chain, and records it in the event queue.
[0218] For example, if the highest block number in the blockchain is 200, and the final confirmation depth of the blockchain is N=6, then the computer device maintains the hash values corresponding to the 6 most recent block numbers (i.e., block numbers 195 to 200). If the hash value of the most recently fetched block number 198 is inconsistent with the hash value of the already recorded block number 198, indicating that block 198 has been reorganized, the computer device will discard the event logs in the blocks corresponding to block numbers 198 to 200, such as changing the status of these event logs from pending to rolled_back, and re-fetching the event logs starting from block number 198, thereby ensuring that the event logs recorded in the business system are consistent with the event logs in the blockchain.
[0219] For example, the above three parts 1, 2, and 3 can be executed on multiple blockchains. The resulting event logs are stored in the corresponding event lists of each blockchain. The computer device stores the event lists and waits for the block to which the event log belongs in the event list to be in a determined state before notifying the business system to execute the business corresponding to the event.
[0220] 4. Parsing into business processes and business execution.
[0221] This section is divided into a parsing phase and a submission phase, where: Parsing phase: The event decoder in the business system converts the event logs into structured event objects (including the business logic corresponding to the event logs) and stores them in memory, without writing to the database at this time.
[0222] Submission Phase: Based on the semantics of "update if it exists, insert if it does not exist", the event handler ensures idempotency and publishes business messages such as subscription, redemption, and net asset value update to the business message queue when the subscription status of the block to which the event log belongs is determined (i.e., the business corresponding to the event log).
[0223] For example, after pulling events from the blockchain and completing the adjacency determination to confirm that no block reorganization has occurred, the event log is decoded into an in-memory object and temporarily stored in the business queue. Once the subscription status of the block to which the event log belongs changes from pending to confirmed, an "insert or update" statement is executed to write the in-memory object (e.g., a user's subscription record) into the business table and publish a "subscription completed" message to the valuation system, ensuring that only data that is ultimately irreversible triggers fund settlement.
[0224] Dividing the business execution process into two independent stages—event log parsing and business submission—allows for the pre-parsing of event logs and the temporary storage of memory objects after the event logs are obtained. In this way, once the block to which the event log belongs is converted to the confirmed state, the memory objects can be directly written to the business table without waiting for the event logs to be parsed, thus achieving high-concurrency buffering.
[0225] Furthermore, in the event of a block rollback, the business corresponding to the event log in the block that is in the rollback state is not executed, and the business waiting to be executed can be accurately located based on the changes in the blockchain.
[0226] In summary, the method for monitoring block information provided in this application can achieve at least one of the following beneficial effects: 1. Implemented event-level precision and order guarantees. Using a three-dimensional cursor in the blockchain, such as (block number, transaction index number, event index number) as the unique progress key, compared to the coarse-grained management based on block number in related technologies, helps to avoid the problems of duplicate, omission, or disordered order of data points (such as event logs) within the same block when listening to block messages. It also helps to achieve a one-to-one correspondence between event logs on the blockchain and business records in the business system.
[0227] 2. It has reorganization fault tolerance and ensures consistency between the blockchain and the business system during rollback.
[0228] By caching the hash value of the block and using the "pending→rolled_back→confirmed" state machine to maintain the subscription state of the block, it achieves automatic detection of blockchain forks and rollback of acquired data points, replay of listening block information, and acquisition of event logs in the new block corresponding to the same block, ensuring that "on-chain rollback = business rollback", guaranteeing eventual data consistency, and avoiding deviation of key information such as share and net value due to reorganization.
[0229] 3. Achieved multi-chain isolation and compliance friendliness.
[0230] Each blockchain has its own independent cursor table, event queue, processing instance, and storage area, which physically isolates and prevents cross-chain data pollution. Moreover, the business system supports a unified query interface and multi-dimensional filtering by chain number, event type, status, etc., balancing isolation and convenience, and meeting the multi-chain issuance needs and single-entry auditing needs of assets such as funds.
[0231] 4. High concurrency, low interruption, and dynamic adaptation
[0232] Two-phase processing (parse first, then submit) buffers the impact of high-frequency events, and dynamic contract address difference updates can complete subscription switching without restarting the service. Combined with a three-dimensional cursor, it keeps the progress continuous and significantly improves the system throughput.
[0233] Figure 6 A block diagram of an apparatus for monitoring block information is shown according to an exemplary embodiment. (Refer to...) Figure 6 The device 600 may include: The acquisition module 610 is used to acquire multiple data points from at least one block of the blockchain based on the subscription mechanism of the blockchain; any data point is any information recorded in the block; any data point has a unique data identifier in the block.
[0234] The reacquisition module 620 is used to reacquire the data points of the block when there is a gap in the data identifiers of data points belonging to the same block among multiple data points, until the data points with continuous data identifiers in the block are obtained.
[0235] In one possible implementation, if any data point is any transaction in a block, then the data identifier is the transaction index number; or if any data point is the event log of any transaction, then the data identifier is the event index number. The acquisition module 610 is used to obtain multiple data points of the block corresponding to the block number from the blockchain.
[0236] In one possible implementation, the device for monitoring block information further includes: a subscription triggering module for obtaining the first block number of the blockchain; the first block number is the current highest block number of the blockchain; determining that the difference between the first block number and the obtained second block number satisfies a difference condition; the second block number is the highest block number obtained from the blockchain through the subscription mechanism; The aforementioned acquisition module 610 is used to acquire multiple data points from each block from the second block number to the first block number from the blockchain.
[0237] In one possible implementation, the device for monitoring block information further includes a state transition module, which is used to set the subscription state corresponding to the block to a determined state after obtaining the data points of N blocks after the block through the subscription mechanism; and to synchronize each data point in the block in the determined state to the corresponding service.
[0238] In one possible implementation, the device for monitoring block information further includes: a hash value comparison module, used to determine a first hash value of a first block to which at least one data point belongs; and, if a second hash value of the first block exists in the subscribed record, to determine that the first hash value is consistent with the second hash value; the subscribed record contains the block to which any data point obtained through the subscription mechanism belongs, and the hash value corresponding to the block.
[0239] In one possible implementation, the subscription record also records the subscription status of the block, and the device for monitoring block information further includes: a block rollback module, used to roll back each data point of the first block obtained based on the subscription mechanism when the first hash value and the second hash value are inconsistent, until the third hash value of the second block in the subscription record is consistent with the fourth hash value of the second block obtained from the blockchain; the block height of the second block is lower than the block height of the first block.
[0240] In one possible implementation, the device for monitoring block information further includes a subscription module for subscribing to multiple blockchains separately, each blockchain having its own subscription mechanism to achieve physical isolation.
[0241] Regarding the apparatus in the above embodiments, the specific manner in which each module performs its operation has been described in detail in the embodiments related to the method, and will not be elaborated upon here.
[0242] Figure 7 This is a block diagram illustrating an electronic device for monitoring block information based on an exemplary embodiment.
[0243] Based on the same inventive concept, embodiments of the present invention provide a computing device, such as... Figure 7 As shown, it includes at least one processor 701 and a memory 702 connected to at least one processor. In this embodiment of the invention, the specific connection medium between the processor 701 and the memory 702 is not limited. Figure 7 Taking the connection between the processor 701 and the memory 702 via a bus as an example, the bus can be divided into address bus, data bus, control bus, etc.
[0244] In this embodiment of the invention, the memory 702 stores instructions that can be executed by at least one processor 701. By executing the instructions stored in the memory 702, at least one processor 701 can perform the steps included in the aforementioned data processing method based on a blockchain system.
[0245] The processor 701 is the control center of the computing device, connecting various parts of the device via various interfaces and lines. It performs data processing by running or executing instructions stored in the memory 702 and accessing data stored in the memory 702. Optionally, the processor 701 may include one or more processing units. The processor 701 may integrate an application processor and a modem processor. The application processor primarily handles the operating system, user interface, and applications, while the modem processor primarily handles issuing instructions. It is understood that the modem processor may not be integrated into the processor 701. In some embodiments, the processor 701 and the memory 702 may be implemented on the same chip; in other embodiments, they may be implemented on separate chips.
[0246] Processor 701 can be a general-purpose processor, such as a central processing unit (CPU), digital signal processor, application-specific integrated circuit (ASIC), field-programmable gate array or other programmable logic device, discrete gate or transistor logic device, or discrete hardware component, capable of implementing or executing the methods, steps, and logic block diagrams disclosed in the embodiments of this invention. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in the data processing embodiments based on the blockchain system can be directly manifested as being executed by a hardware processor, or executed by a combination of hardware and software modules within the processor.
[0247] Memory 702, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer-executable programs, and modules. Memory 702 may include at least one type of storage medium, such as flash memory, hard disk, multimedia card, card-type memory, random access memory (RAM), static random access memory (SRAM), programmable read-only memory (PROM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), magnetic storage, magnetic disk, optical disk, etc. Memory 702 can be any other medium capable of carrying or storing desired program code in the form of instructions or data structures that can be accessed by a computer, but is not limited thereto. In embodiments of the present invention, memory 702 can also be a circuit or any other device capable of implementing storage functions for storing program instructions and / or data.
[0248] Based on the same inventive concept, embodiments of the present invention also provide a computer-readable storage medium storing a computer program executable by a computing device, wherein when the program is run on the computing device, the computing device performs the aforementioned... Figures 2 to 5 The method for monitoring block information as described in any one of the above.
[0249] Those skilled in the art will understand that embodiments of the present invention can be provided as methods or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0250] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams.Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0251] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0252] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 Figure 1 The steps of the function specified in one or more boxes.
[0253] Although preferred embodiments of the invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including both the preferred embodiments and all changes and modifications falling within the scope of the invention.
[0254] Obviously, those skilled in the art can make various modifications and variations to this invention without departing from its spirit and scope. Therefore, if these modifications and variations fall within the scope of the claims of this invention and their equivalents, this invention also intends to include these modifications and variations.
Claims
1. A method for monitoring block information, characterized in that, The method includes: Based on the blockchain subscription mechanism, multiple data points of at least one block are obtained from the blockchain; each data point is any information recorded in the block; each data point has a unique data identifier in the block; If there is a gap in the data identifiers of data points belonging to the same block among the multiple data points, then the data points of the block are reacquired until data points with consecutive data identifiers in the block are obtained.
2. The method according to claim 1, characterized in that, If any data point is any transaction in the block, then the data identifier includes the transaction index number; or If any data point is an event log of any transaction, then the data identifier includes the event index number; The step of obtaining multiple data points from at least one block of the blockchain includes: Based on the block number, obtain multiple data points from the blockchain corresponding to the block number.
3. The method according to claim 1, characterized in that, Before retrieving multiple data points from at least one block of the blockchain, the method further includes: Obtain the first block number of the blockchain; the first block number is the current highest block number of the blockchain; The difference between the first block number and the acquired second block number is determined to satisfy a difference condition; the second block number is the highest block number that has been acquired from the blockchain through the subscription mechanism. The process of obtaining multiple data points from at least one block of the blockchain includes: Obtain multiple data points from each block from the second block number to the first block number from the blockchain.
4. The method according to claim 1, characterized in that, After obtaining the data points of continuous data identifiers in the block, the method further includes: After obtaining the data points of N blocks following the block through the subscription mechanism, the subscription status corresponding to the block is set to a confirmed state; Synchronize each data point in a block that is in a defined state to the corresponding service.
5. The method according to any one of claims 1-4, characterized in that, Before determining that there is a discontinuity in the data identifiers of data points belonging to the same block among the plurality of data points, the method further includes: Determine the first hash value of the first block containing at least one data point; If the second hash value of the first block exists in the subscribed record, then the first hash value is determined to be consistent with the second hash value; the subscribed record records the block to which any data point obtained through the subscription mechanism belongs and the hash value corresponding to the block.
6. The method according to claim 5, characterized in that, The subscribed record also contains the subscription status of the corresponding block, and the method further includes: If the first hash value is inconsistent with the second hash value, then each data point of the first block obtained based on the subscription mechanism is rolled back until the third hash value of the second block in the subscribed record is consistent with the fourth hash value of the second block obtained from the blockchain; the block height of the second block is lower than the block height of the first block.
7. The method according to any one of claims 1 to 4, characterized in that, The method further includes: Multiple blockchains can be subscribed to separately, with each blockchain having its own subscription mechanism to achieve physical isolation.
8. A device for monitoring block information, characterized in that, The device includes: The acquisition module is used to acquire multiple data points from at least one block of the blockchain based on the blockchain subscription mechanism; each data point is any information recorded in the block; each data point has a unique data identifier in the block; The reacquisition module is used to reacquire the data points of the block when there is a gap in the data identifiers of the data points belonging to the same block among the multiple data points, until the data points with consecutive data identifiers in the block are obtained.
9. An electronic device for monitoring block information, characterized in that, include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; the processor executes the computer-executable instructions stored in the memory to implement the method as described in any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, When the instructions in the computer-readable storage medium are executed by the processor of the electronic device, the electronic device is enabled to perform the method as described in any one of claims 1-7.