A block message collection method and device for a blockchain
By establishing a chain head listening service on a remote blockchain node to acquire and process the latest chain head information, the problems of computational resource consumption and data omission in blockchain data collection services are solved, data integrity and accuracy are achieved, and processing efficiency is improved.
Patent Information
- Application Number
- CN202310747470.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-21
- Publication Date
- 2026-11-06
- Estimated Expiration
- 2043-06-21
AI Technical Summary
In existing technologies, blockchain data collection services result in high consumption of computing resources, data omissions, and the inability to guarantee data correctness during synchronization, especially in the case of soft forks where data integrity and accuracy are difficult to guarantee.
By establishing a chain head listening service on remote nodes of the blockchain, the latest chain head information is obtained, and block messages are collected when the difference reaches a preset confirmation height. Combined with high boundary information updates and parent-child relationship binding, multiple core extraction coroutines are used to process data in parallel.
It ensures data integrity and accuracy in the case of soft forks, reduces computing resource consumption, avoids data omissions, and improves data processing efficiency.
Smart Images

Figure CN117472991B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and more particularly to a technique for collecting block messages for blockchain. Background Technology
[0002] Each height of a blockchain contains blocks that are packaged and uploaded to the chain. A block is composed of a collection of messages, and the execution of each message leads to a change in the on-chain state. Tracking the chain height, collecting block messages at each height, and calculating the final state data for data analysis are essential for users deeply involved in blockchain.
[0003] In existing technology, Lily is Lotus's official blockchain data collection service. Lily acts as a node, synchronizing with the Filecoin network in daemon mode and running necessary data collection tasks. Collecting data as a node during blockchain network synchronization consumes significant computing resources, disk space, and memory, making it impossible to collect comprehensive data for each height. If the Lily service unexpectedly terminates, it must wait for synchronization to the latest height before resuming height data collection. The data collected between the unexpected termination and the completion of synchronization requires additional data collection tasks, potentially leading to data omissions. If a Lily node experiences a soft fork due to network instability or other reasons (a hard fork refers to a permanent divergence in the blockchain; after a new consensus rule is released, some nodes that haven't upgraded cannot verify blocks produced by upgraded nodes, which usually occurs. A hard fork changes the difficulty level of the accounting algorithm; a soft fork is a temporary phenomenon within the system and does not create a new blockchain. It generally refers to a blockchain system upgrade where some nodes can still function even if they haven't upgraded in time. After a soft fork, unlike a hard fork, two chains are not created; instead, they remain on a single chain. A soft fork involves some upgrades, but it does not affect the stability and effectiveness of the entire system. Old nodes are compatible with new nodes; only new nodes are incompatible with old nodes. Both can still coexist on the same chain), then the data collected during chain synchronization may be incorrect for the main chain, and the data's correctness cannot be guaranteed. Summary of the Invention
[0004] The purpose of this application is to provide a method and device for collecting block messages in a blockchain.
[0005] According to one aspect of this application, a method for collecting block messages in a blockchain is provided, wherein the method includes:
[0006] Establish a chain head listening service, wherein the chain head listening service is established on a remote node of the blockchain;
[0007] The latest chain head information obtained through the chain head monitoring service is then transmitted to the extraction process.
[0008] When the extraction process determines that the difference between the latest chain head information and the high boundary information of the extraction process is not less than a preset confirmation height, it collects block messages between the latest chain head information and the high boundary information, wherein the high boundary information is used to record the highest height information of the collected chain.
[0009] Furthermore, the method further includes:
[0010] After collecting the data status between the latest chain head information and the high boundary information, the high boundary information is updated to the latest chain head information.
[0011] Furthermore, the method further includes:
[0012] Bind the latest chain head information and the high boundary information to the block with a parent-child relationship to obtain the block message between the latest chain head information and the high boundary information.
[0013] Furthermore, the method further includes:
[0014] The extraction process obtains one or more target blockchain heights based on a request, and determines the blockchain state information of the target blockchain height based on the parent state of the one or more target blockchain heights and the block messages of the target blockchain height.
[0015] Furthermore, the extraction process, which obtains one or more target blockchain heights based on a request, and determines the blockchain state information of the target blockchain height based on the parent state of the one or more target blockchain heights and the block messages of the target blockchain heights, includes:
[0016] The extraction process obtains multiple target blockchain heights based on requests, and distributes the multiple target blockchain heights and corresponding block messages to each core extraction goroutine to determine the blockchain state information for each target blockchain height.
[0017] Furthermore, the blockchain state information for each target blockchain height determined by each core extraction coroutine includes:
[0018] Each core extraction coroutine performs calculations based on preset data types and preset extraction intervals to determine the blockchain state information for each target blockchain height.
[0019] According to another aspect of this application, a computer-readable medium is also provided, on which computer-readable instructions are stored, which can be executed by a processor to perform the operation as described above.
[0020] According to another aspect of this application, a block message collection device for a blockchain is also provided, wherein the device includes:
[0021] One or more processors; and
[0022] A memory storing computer-readable instructions, which, when executed, cause the processor to perform operations as described above.
[0023] Compared to existing technologies, this application establishes a chain head monitoring service, which is built on a remote node of the blockchain. Based on this service, the latest chain head information is transmitted to the extraction process. When the extraction process determines that the difference between the latest chain head information and the high boundary information of the extraction process is not less than a preset confirmation height, it collects block messages between the latest chain head information and the high boundary information. The high boundary information is used to record the highest height information of the collected chains. This approach ensures the accuracy of the collected block messages, effectively handles soft forks, and guarantees the integrity of the collected data, preventing data loss even after unexpected service termination. Attached Figure Description
[0024] Other features, objects, and advantages of the invention will become more apparent from the following detailed description of non-limiting embodiments with reference to the accompanying drawings:
[0025] Figure 1 A flowchart of a block message collection method for a blockchain according to one aspect of this application is shown;
[0026] Figure 2 A flowchart of a method for collecting blockchain state information according to a preferred embodiment of this application is shown.
[0027] The same or similar reference numerals in the accompanying drawings represent the same or similar parts. Detailed Implementation
[0028] The present invention will now be described in further detail with reference to the accompanying drawings.
[0029] In a typical configuration of this application, the terminal, the device of the service network, and the trusted party all include one or more processors (CPUs), input / output interfaces, network interfaces, and memory.
[0030] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0031] Computer-readable media include both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include non-transitory computer-readable media, such as modulated data signals and carrier waves.
[0032] To further illustrate the technical means adopted and the effects achieved in this application, the technical solution of this application will be clearly and completely described below in conjunction with the accompanying drawings and preferred embodiments.
[0033] Figure 1 This application illustrates a method for collecting block messages in a blockchain, comprising:
[0034] S11 establishes a chain head listening service, wherein the chain head listening service is established on a remote node of the blockchain;
[0035] S12 transmits the latest chain head information obtained based on the chain head monitoring service to the extraction process;
[0036] S13 When the extraction process determines that the difference between the latest chain head information and the high boundary information of the extraction process is not less than a preset confirmation height, the block message between the latest chain head information and the high boundary information is collected, wherein the high boundary information is used to record the highest height information of the collected chain.
[0037] In this embodiment, in step S11, a headnotifier service is established at a remote node of the blockchain. The headnotifier is responsible for receiving head change events and can monitor the latest head information. By using a remote node, the consumption of computing, memory, and disk resources during chain data collection can be reduced.
[0038] In step S12, the chain head listening service transmits the latest chain head information to the extraction process, which is responsible for requesting block messages within the height to be processed from the remote node.
[0039] Continuing in this embodiment, in step S13, the extraction process determines whether the difference between the latest chain head information and the high boundary information of the extraction process is not less than a preset confirmation height. The high boundary information records the highest chain height information that has been extracted and stored. The preset confirmation height is used to determine that the data at the latest chain head height and previous heights are reliable and will not be rolled back. Therefore, the block data from the high boundary to the latest chain head height can be calculated, extracted, and stored. That is, when the difference between the latest chain head information and the high boundary information of the extraction process is not less than the preset confirmation height, it can be determined that the data at the latest chain head height and previous heights are reliable. Here, the preset confirmation height can be determined based on an empirical value. In this way, the accuracy and integrity of the data are ensured.
[0040] Preferably, after collecting the data state between the latest chain head information and the high boundary information, the high boundary information is updated to the latest chain head information. Specifically, after calculating, extracting, and storing the height of each segment, the high bound is updated to the highest height information.
[0041] Preferably, the method further includes: binding the blocks between the latest chain head information and the high boundary information into parent-child relationships to obtain block messages between the latest chain head information and the high boundary information. Specifically, the extraction process is responsible for requesting block data within the height to be processed from the remote node and binding the blocks at each height into parent-child relationships. Since the extractor needs the parent state of the current height to calculate the block message at each height, the blocks in the height from high bound to the chain head are bound into parent-child relationships. For example, the parent block of the block at height 1001 is the block at height 1000, and the child block is the block at height 1002.
[0042] Preferably, the method further includes: S14 (not shown) the extraction process obtains one or more target blockchain heights based on a request, and determines the blockchain state information of the target blockchain height based on the parent state of the one or more target blockchain heights and the block messages of the target blockchain height. In this embodiment, when it is necessary to determine one or more blockchain state information, it can be determined based on the block messages of the target blockchain height and the parent state of the target blockchain height.
[0043] Preferably, step S14 includes: the extraction process obtains multiple target blockchain heights based on requests, and distributes the multiple target blockchain heights and corresponding block messages to each core extraction goroutine to determine the blockchain state information of each target blockchain height.
[0044] In this embodiment, the multiple target blockchain heights include multiple adjacent target blockchain heights. The blockchain state information for each target blockchain height can be calculated in parallel by multiple core extractors. Specifically, the Extraction Process is responsible for requesting block data within the height to be processed from remote nodes, binding parent-child relationships between blocks at each height, and then distributing the data to various core extractor coroutines to calculate and extract data from different dimensions, ultimately storing it in the database. This approach improves data processing efficiency through concurrent processing by multiple core extractor coroutines.
[0045] Preferably, the process by which each core extraction goroutine determines the blockchain state information for each target blockchain height includes: each core extraction goroutine calculating based on a preset data type and a preset extraction interval to determine the blockchain state information for each target blockchain height. Here, the data type can be determined based on different application scenarios, such as user activity, order activity, etc., and is not specifically limited here.
[0046] Figure 2 This paper illustrates a flowchart of a block message collection method for a blockchain according to a preferred embodiment of this application.
[0047] In this embodiment, assuming a blockchain is in the process of synchronization, and the latest synchronization height is 1004, the HeadNotifier (chain head listening service) obtains the chain head information at height 1004 and passes it to the Extraction Process. At this time, the high bound of the Extraction Process is 1000, and the confidence is set to 5. Since the confidence height is the chain head height 1004 minus the confidence equals 999, which is less than the high bound, the Extractor will continue to wait.
[0048] Continuing in this embodiment, the Extraction Process receives the chain head information at height 1010. The confidence height is the chain head height 1010 minus confidence, which equals 1005, greater than the high bound. The Extraction Process requests block information from the remote node within the height range from the high bound to 1005 and binds the parent-child relationship between blocks at each height.
[0049] Furthermore, the Extraction Process distributes the processed blocks to multiple Core Extractor coroutines for concurrent processing.
[0050] Each Core Extractor performs calculations and extractions according to the different data types and defined extraction intervals to obtain the final data, which is then stored in the database.
[0051] According to another aspect of this application, a computer-readable medium is also provided, the computer-readable medium storing computer-readable instructions that can be executed by a processor to implement the aforementioned method.
[0052] According to another aspect of this application, a block message collection device for a blockchain is also provided, wherein the device includes:
[0053] One or more processors; and
[0054] A memory storing computer-readable instructions, which, when executed, cause the processor to perform operations as described above.
[0055] For example, when executed, the computer-readable instructions cause the one or more processors to: establish a chain head listening service, wherein the chain head listening service is established on a remote node of the blockchain; transmit the latest chain head information obtained based on the chain head listening service to the extraction process; when the extraction process determines that the difference between the latest chain head information and the high boundary information of the extraction process is not less than a preset confirmation height, collect block messages between the latest chain head information and the high boundary information, wherein the high boundary information is used to record the highest height information of the collected chain.
[0056] It will be apparent to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, and that the invention can be implemented in other specific forms without departing from the spirit or essential characteristics of the invention. Therefore, the embodiments should be considered illustrative and non-limiting in all respects, and the scope of the invention is defined by the appended claims rather than the foregoing description. Thus, all variations falling within the meaning and scope of equivalents of the claims are intended to be embraced within the present invention. No reference numerals in the claims should be construed as limiting the scope of the claims. Furthermore, it is clear that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or devices recited in the apparatus claims may also be implemented by a single unit or device in software or hardware. The terms "first," "second," etc., are used to indicate names and do not indicate any particular order.
Claims
1. A method for collecting block messages in a blockchain, wherein, The method includes: establishing a chain head listening service, wherein the chain head listening service is established on a remote node of the blockchain; The latest chain head information obtained through the chain head monitoring service is then transmitted to the extraction process. When the extraction process determines that the difference between the latest chain head information and the high boundary information of the extraction process is not less than a preset confirmation height, it collects block messages between the latest chain head information and the high boundary information, wherein the high boundary information is used to record the highest height information of the collected chain. The method further includes: after collecting the data state between the latest chain head information and the high boundary information, updating the high boundary information to the latest chain head information. The preset confirmation height is used to determine that the latest chain head height and previous height data are reliable and will not be rolled back.
2. The method according to claim 1, wherein, The method further includes: binding the latest chain head information and the high boundary information to a parent-child relationship to obtain the block messages between the latest chain head information and the high boundary information.
3. The method according to claim 2, wherein, The method further includes: the extraction process obtains one or more target blockchain heights based on a request, and determines the blockchain state information of the target blockchain height based on the parent state of the one or more target blockchain heights and the block messages of the target blockchain height.
4. The method according to claim 3, wherein, The extraction process obtains one or more target blockchain heights based on a request, and determines the blockchain state information of the target blockchain height based on the parent state of the one or more target blockchain heights and the block messages of the target blockchain heights. This includes: the extraction process obtains multiple target blockchain heights based on a request, and distributes the multiple target blockchain heights and their corresponding block messages to each core extraction goroutine to determine the blockchain state information of each target blockchain height.
5. The method according to claim 4, wherein, The blockchain state information for each target blockchain height determined by each core extraction goroutine includes: each core extraction goroutine calculates based on a preset data type and a preset extraction interval to determine the blockchain state information for each target blockchain height.
6. A computer-readable medium having stored thereon computer-readable instructions that can be executed by a processor to implement the method as described in any one of claims 1 to 5.
7. A block message collection device for blockchain, wherein, The device includes: one or more processors; and a memory storing computer-readable instructions that, when executed, cause the processor to perform the operations of the method as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Dynamic reconfiguration of resilient logical modules in a software defined server
US20190149399A1
Systems, methods, and apparatuses for implementing efficient storage and validation of data and metadata within a blockchain using distributed ledger technology (DLT)
US20200250174A1
