Block chain event subscription method, device and system and storage medium

The introduction of an application-layer event subscription component for blockchain systems addresses high processing overhead by persisting block heights and managing events, enhancing reliability and efficiency in event data management.

CN119094533APending Publication Date: 2024-12-06HANGZHOU HIGH-TECH ZONE (BINJIANG) INSTITUTE OF BLOCKCHAIN & DATA SECURITY
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411102781.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-12
Publication Date
2024-12-06

AI Technical Summary

Technical Problem

Existing blockchain event subscription technologies suffer from high processing overhead due to the need for maintaining multiple long connections and re-querying interfaces upon connection interruptions, leading to inefficiencies and potential node crashes.

Method used

Implementing an event subscription component at the application layer to persist block heights and manage subscription events, reducing the need for multiple long connections by using an intermediate layer for event processing and data persistence, and ensuring event data integrity through database or memory storage.

Benefits of technology

Reduces the overhead required to maintain long connections, prevents event loss during connection interruptions, and enhances the reliability of blockchain event subscription by ensuring data persistence and timely event processing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119094533A_ABST
    Figure CN119094533A_ABST
Patent Text Reader

Abstract

The invention relates to a block chain event subscription method, device and system and a storage medium, and the method comprises the steps: creating an event subscription component at an application layer; acquiring a subscription event of a new block under the condition that the event subscription component senses that the new block is generated on the block chain network connected with the application layer; and performing persistence on the block height corresponding to the subscription event by using the event subscription component. Through the method and the device, the problem of high processing overhead of block chain event subscription is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of blockchain, and in particular to a method, device, system and storage medium for subscribing to blockchain events. Background Art

[0002] Blockchain is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. In the blockchain system, blocks are sequentially connected in chronological order to form a chain data structure, and a distributed ledger that cannot be tampered with or forged is guaranteed by cryptography.

[0003] Transactions within a block may generate events when they are executed, and these events will be recorded in the block. In the service-oriented scenario of blockchain, a blockchain node can be composed of multiple services, among which the block service can provide the events to other services for use.

[0004] In the related technology, the caller needs to maintain the stability of multiple long connections when maintaining the event subscription status and reconnect when problems occur. If the caller has higher requirements for the integrity of the subscription data, it is also necessary to re-query the interface before re-establishing the connection to supplement the events lost due to the interruption of the event subscription connection, resulting in a high processing overhead for blockchain event subscription.

[0005] Currently, no effective solution has been proposed for the problem of high processing overhead of blockchain event subscription in related technologies. Summary of the invention

[0006] The embodiments of the present application provide a blockchain event subscription method, device, system, electronic device and storage medium to at least solve the problem of high processing overhead of blockchain event subscription in related technologies.

[0007] In a first aspect, an embodiment of the present application provides a method for subscribing to a blockchain event, the method comprising:

[0008] Create an event subscription component at the application layer;

[0009] Using the event subscription component, when sensing that a new block is generated on the blockchain network connected to the application layer, obtaining a subscription event of the new block;

[0010] The event subscription component is used to persist the block height corresponding to the subscription event.

[0011] In some embodiments, the step of creating an event subscription component at the application layer includes:

[0012] Get blockchain node link and event subscription link;

[0013] The blockchain node link and the event subscription link are passed into the application layer to generate the event subscription component.

[0014] In some embodiments, the event subscription component is further configured with database link parameters; and using the event subscription component to persist the block height corresponding to the subscription event includes:

[0015] The event subscription component is used to call the database link parameter, and the subscription event and the block height are persisted in the database corresponding to the database link parameter.

[0016] In some embodiments, after persisting the subscription event and the block height corresponding to the subscription event, the method further includes:

[0017] Monitoring the running status of the application layer;

[0018] When it is monitored that the running status indicates that the application layer is abnormal, obtaining the event subscription instance recreated by the application layer;

[0019] Utilizing the event subscription instance, determine the height difference between the current event subscription synchronization height in the database and the current block height, and query the subscription events on the blockchain network.

[0020] In some embodiments, after obtaining the subscription event of the new block, the method further includes:

[0021] The event subscription component is used to store the block height in a preset storage space.

[0022] In some embodiments, the using the event subscription component to persist the block height corresponding to the subscription event includes:

[0023] Determine the preset callback function;

[0024] The callback function is called through the event subscription component to obtain the subscription event and the block height, and the block height is persisted.

[0025] In some embodiments, there is at least one event subscription component; each of the event subscription components corresponds to a blockchain network.

[0026] In a second aspect, an embodiment of the present application provides a blockchain event subscription device, including:

[0027] Create a module to create event subscription components in the application layer;

[0028] A subscription module, configured to utilize the event subscription component to obtain a subscription event of a new block when sensing that a new block is generated on the blockchain network connected to the application layer;

[0029] The persistence module is used to use the event subscription component to persist the block height corresponding to the subscription event.

[0030] In a third aspect, an embodiment of the present application provides an event subscription system, comprising: an application layer, a blockchain node, and a blockchain event subscription device as described in the second aspect above.

[0031] In a fourth aspect, an embodiment of the present application provides a storage medium on which a computer program is stored, which, when executed by a processor, implements the blockchain event subscription method as described in the first aspect above.

[0032] Compared with the related art, the blockchain event subscription method, device, system and storage medium provided in the embodiment of the present application create an event subscription component at the application layer; using the event subscription component, when a new block is sensed to be generated on the blockchain network connected to the application layer, the subscription event of the new block is obtained; using the event subscription component, the block height corresponding to the subscription event is persisted. Based on this, the actual event subscription long connection is reduced, and the long connection of different event subscriptions can be maintained using one blockchain subscription, which effectively reduces the overhead required to maintain the long connection, reduces the pressure on the blockchain, and solves the problem of high processing overhead of blockchain event subscription.

[0033] Details of one or more embodiments of the present application are set forth in the following drawings and description to make other features, objects, and advantages of the present application more readily apparent. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0035] Figure 1 This is an application scenario diagram of a blockchain event subscription method according to an embodiment of the present application;

[0036] Figure 2 This is a flowchart of a method for subscribing to blockchain events according to an embodiment of the present application;

[0037] Figure 3 It is a schematic diagram of a subscription process of a blockchain event according to an embodiment of the present application;

[0038] Figure 4 It is a schematic diagram of a subscription restart process of a blockchain event according to an embodiment of the present application;

[0039] Figure 5 is a flowchart of another method for subscribing to blockchain events according to an embodiment of the present application;

[0040] Figure 6 It is a structural block diagram of a blockchain event subscription device according to an embodiment of the present application;

[0041] Figure 7 It is a diagram of the internal structure of a computer device according to an embodiment of the present application. DETAILED DESCRIPTION

[0042] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application is described and illustrated below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application. Based on the embodiments provided in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present application. In addition, it can also be understood that although the efforts made in this development process may be complex and lengthy, for ordinary technicians in the field related to the contents disclosed in the present application, some changes such as design, manufacturing or production based on the technical contents disclosed in the present application are only conventional technical means, and should not be understood as insufficient contents disclosed in the present application.

[0043] Reference to "embodiments" in this application means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those of ordinary skill in the art that the embodiments described in this application may be combined with other embodiments without conflict.

[0044] Unless otherwise defined, the technical terms or scientific terms involved in this application should be understood by people with ordinary skills in the technical field to which this application belongs. The words "one", "a", "a", "the" and the like involved in this application do not indicate a quantitative limitation, and may represent the singular or plural. The terms "include", "comprise", "have" and any of their variations involved in this application are intended to cover non-exclusive inclusions; for example, a process, method, system, product or device that includes a series of steps or modules (units) is not limited to the listed steps or units, but may also include steps or units that are not listed, or may also include other steps or units inherent to these processes, methods, products or devices. The words "connect", "connected", "coupled" and the like involved in this application are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. The "multiple" involved in this application refers to greater than or equal to two. "And / or" describes the association relationship of associated objects, indicating that there can be three relationships, for example, "A and / or B" can represent: A exists alone, A and B exist at the same time, and B exists alone. The terms "first", "second", "third" and the like involved in the present application are merely used to distinguish similar objects and do not represent a specific ordering of the objects.

[0045] In this embodiment, an application scenario of a blockchain event subscription method is provided. Figure 1 is an application scenario diagram of a blockchain event subscription method according to an embodiment of the present application, such as Figure 1 As shown, it includes a terminal 12, a server 14 and a blockchain network 16. The terminal 12 can be a producer or a consumer. The terminal 12, the blockchain network 16 and the server 14 communicate through a network. The network can include a local area network (LAN), a wide area network (WAN), the Internet or a combination thereof, and is connected to a website, a user device (such as a computing device) and a back-end system. An event subscription component is created by deploying the application layer of the terminal 12; using the event subscription component, when a new block is generated on the blockchain network 16 connected to the application layer, the subscription event of the new block is obtained; using the event subscription component, the block height corresponding to the subscription event is persisted. Optionally, the server 14 can be a node of a cloud computing system (not shown in the figure), or each server 14 can be a separate cloud computing system, including multiple computers interconnected by a network and working as a distributed processing system. The server 14 can run any appropriate computing system to enable it to serve as a node in the blockchain network 16. The terminal 12 can be, but is not limited to, various personal computers, laptops, smart phones, tablets, Internet of Things devices and portable wearable devices.

[0046] The blockchain network 16 includes multiple blockchain nodes, and each blockchain node together forms a blockchain network. In actual applications, a user can initiate a transaction request to a blockchain node in the blockchain network 16 and submit pending transaction data. The blockchain node performs corresponding data processing based on the pending transaction data, such as requesting other blockchain nodes to perform consensus processing on the pending transaction data, generate blocks, store data, etc. The block includes multiple transaction data, and these transaction data may include event data related to the event. Smart contracts can be deployed in the blockchain network 16.

[0047] Specifically, after executing a transaction that calls a smart contract, a node in the blockchain network 16 will generate a corresponding receipt to record information related to the execution of the smart contract. In this way, relevant information about the contract execution result can be obtained by querying the transaction receipt. The contract execution result can be expressed as an event in the receipt. The message mechanism can realize message transmission through the event in the receipt to trigger the blockchain node to perform corresponding processing. The structure of the event can be, for example:

[0048] Event:

[0049] [topic][data]

[0050] [topic][data] .....

[0052] In the above example, the number of events can be one or more, wherein each event includes fields such as topic and data. The blockchain node 16 can monitor the topic of the event, and when a predefined topic is monitored, perform a preset process, or read relevant content from the data field of the corresponding event, and perform a preset process based on the read content.

[0053] based on Figure 1 As shown in the application scenario diagram, this embodiment provides a method for subscribing to blockchain events. Figure 2 is a flowchart of a method for subscribing to blockchain events according to an embodiment of the present application, such as Figure 2 As shown, the process includes the following steps:

[0054] Step S210, creating an event subscription component at the application layer.

[0055] In the related art, the application layer interacts with the blockchain network and subscribes to on-chain events, but too many long connections will cause excessive pressure on the node, affecting the subsequent blockchain block generation, and even causing the node to crash. In order to solve the above problem, in this step, the developer can generate an event subscription component at the application layer to create an instance of event subscription, so that when subscribing to events later, the contract topic and callback function can be passed to it. The event subscription component can be regarded as an intermediate layer for maintaining blockchain connections and event processing; this intermediate layer (or intermediate component) can not only handle the details of event subscription, but also provide support for multiple blockchain networks, allowing the application layer to interact with different blockchain networks through interfaces.

[0056] More specifically, the above process includes the following steps: obtaining the blockchain node link and the event subscription link; passing the blockchain node link and the event subscription link into the application layer to generate an event subscription component.

[0057] Among them, the blockchain node connection can rely on the Remote Procedure Call (RPC) protocol; in the blockchain field, RPC is used for remote calls between nodes, allowing developers to interact with blockchain nodes through Hypertext Transfer Protocol (HTTP) or InterProcess Communication (IPC). Event subscription links can rely on WebSocket, which is a protocol for full-duplex communication on a single Transmission Control Protocol (TCP) connection; WebSocket provides real-time data transmission capabilities, so that the client can receive event notifications pushed by the server almost immediately, without the need to request data regularly as in the traditional polling method. The following is a code example of an event subscription instance based on the Go language in an embodiment of the present application:

[0058] NewClient(rpcUrl string,wsUrl string,logger slog.Logger)(*SubClient,error)

[0059] In the above example, NewClient is a function that initializes an instance; the function can receive an RPC URL, a WebSocket URL, and a logger as parameters, and returns a pointer to a SubClient type or an error.

[0060] It should be noted that, in another embodiment, there is at least one event subscription component, and each event subscription component corresponds to a blockchain network; through the above method, the application layer supports the creation of multiple instances, and multiple instances are connected to different blockchains, so that event subscriptions on multiple blockchains can be maintained at the same time, which is conducive to improving the subscription efficiency of blockchain events. At the same time, each event subscription component can include at least one event subscription. That is, one blockchain corresponds to one event subscription component, and one event subscription component corresponds to multiple event subscriptions. Alternatively, where permitted by the embodiment, one blockchain can also correspond to more than two (including two) event subscription components. Specifically, when the application layer creates the event subscription component corresponding to the blockchain, it assigns a corresponding flag bit to each event subscription component; then when subscribing to an event, the application layer selects the event subscription component, and based on the flag bit, starts the corresponding event subscription component to subscribe to the event to the perceived new block.

[0061] Step S220, using the event subscription component, when sensing that a new block is generated on the blockchain connected to the application layer, obtain the subscription event of the new block.

[0062] In this step, the event subscription component can create a block header subscription event to the corresponding blockchain. When the block header subscription is created to perceive the generation of a new block in the blockchain, different queries are generated according to the maintained subscription parameters. Taking the above code as an example, the instance NewClient in the event subscription component uses the parameter data of the application layer to query the blockchain event from the corresponding blockchain node and return the queried event data, that is, different queries are generated according to the maintained subscription parameters. Specifically, the event subscription component connects to the WebSocket service of the blockchain node through the parameter parameters of the application layer and subscribes to the notification of the generation of a new block; when a new block is generated, the blockchain node sends an event to the event subscription component through the WebSocket connection. The event subscription component needs to be able to receive and process these events, such as parsing block data, extracting detailed information of the new block (such as block hash, transaction list) from the received events, etc.

[0063] Step S230, using the event subscription component to persist the block height corresponding to the subscription event.

[0064] The above-mentioned persistence processing refers to the process in which the event subscription component stores the block height corresponding to the subscription event in the database to achieve data persistence. The database can store and maintain the preset event subscription table created by the event subscription component; specifically, for the subscription content that needs to be persisted, the event subscription component will automatically create an event subscription table, which is stored in the database of the application layer; and the subscribed block height and subscription incoming data are maintained in the event subscription table. Through the above-mentioned persistence steps for subscription events and block heights, the problem of event loss due to interruption of event subscription connection when the application layer crashes in related technologies is avoided.

[0065] The following is a brief description of the blockchain event subscription process. Figure 3 . Among them, the application layer creates an event subscription component according to actual application needs, and subscribes to contract events in real time through the event subscription component. Specifically, the event subscription component subscribes to the block header of the corresponding blockchain. When the blockchain network generates a new block, it will trigger a query of the subscription log of the new block, parse it into the corresponding subscription 1 content, and obtain the subscription block height at the same time; for other block subscription contents such as subscription 2 and subscription 3, the above steps are also used to obtain them. The above subscription events and the corresponding subscription block heights can be updated by the event subscription component to the event subscription table of the database. Finally, the event subscription component pushes the pulled subscription events to the application layer.

[0066] It should be noted that, in this embodiment, the subscription can be canceled and related resources can be cleaned up when there is no need to monitor the event.

[0067] In the above-mentioned blockchain event subscription method, by instantiating the event subscription component, the event subscription component as an intermediate component queries the blockchain network, thereby realizing the event subscription that needs to establish a long connection is converted into a block header of the corresponding blockchain for subscription, and then the event subscription method of all events required to maintain the current subscription is obtained through the RPC interface query. There is no need for the application layer to maintain the relationship with the chain, which reduces the actual event subscription long connection. The long connection of different event subscriptions can be maintained using one blockchain subscription, which effectively reduces the overhead required to maintain the long connection, and also reduces the pressure on the blockchain, solving the problem of high processing overhead of blockchain event subscription. In addition, the block height corresponding to the queried subscription event is persisted, which avoids the phenomenon of event loss due to the interruption of the event subscription connection when the application layer crashes, thereby improving the reliability of blockchain event subscription.

[0068] In some of the embodiments, in order to achieve persistence of the subscription event block height, in this embodiment, the event subscription component created by the application layer can be configured with database link parameters. For example, the following is a code example of an event subscription instance configured with database link parameters in an embodiment of the present application:

[0069] NewClient(rpcUrl string,wsUrl string,db*sqlx.DB,logger slog.Logger)(*SubClient,error)

[0070] It can be seen that the application layer passes parameters to the above instance and passes the corresponding database connection parameters to db*sqlx.DB, so that the instantiated event subscription component can be connected to the database of the sqlx package to perform database operations on it.

[0071] The above-mentioned use of the event subscription component to persist the block height corresponding to the subscription event may also include the following steps: using the event subscription component to call the database connection parameter, and persist the subscription event and the block height to the database corresponding to the database connection parameter. Among them, for the event data that needs to be persistently subscribed, the event subscription component will connect to the corresponding database through the database connection parameter passed as a parameter, and maintain the subscribed block height and the subscription incoming data in the database, thereby realizing an event subscription component that can support persistent subscription.

[0072] On the other hand, in the case where the configuration parameters of the event subscription component include database link parameters, the developer can also choose to store the block height corresponding to the current subscription event in a preset storage space. That is, for event content that does not require persistent subscription, the event subscription component can store the corresponding block height in a storage space such as memory to reduce the maintenance pressure of the database. Based on this, this embodiment also implements an event subscription component that can support both persistent subscription and memory subscription, expanding the application scenario.

[0073] In some embodiments, after persisting the block height corresponding to the subscription event, the blockchain event subscription method further includes the following steps:

[0074] Step S241, monitoring the running status of the application layer; when the running status is monitored to indicate that the application layer is abnormal, obtaining the event subscription instance recreated by the application layer.

[0075] The running status of the application layer can be monitored in real time using system monitoring tools. For example, the status of the application layer can be monitored through tools such as Systemd, and a notification can be sent when the process exits abnormally. For another example, the performance indicators of the application such as the CPU usage and memory usage of the application layer can be monitored in real time through performance monitoring tools. When certain performance anomalies (such as frequent restarts caused by memory leaks) may indicate that the application is at risk of crashing. For another example, a heartbeat mechanism can be implemented in the application; if the monitoring system does not receive a heartbeat signal within a predetermined time, it can be considered that the application layer has crashed or restarted. It can be understood that the monitoring of the running status of the application layer can be achieved by any of the above methods, or by a combination of at least two of the above monitoring methods.

[0076] When the above steps detect that the application layer is in an abnormal state such as crash or restart, wait for the application layer to recover; after the application layer recovers, the instance will be recreated.

[0077] Step S242, using the event subscription instance, determines the height difference between the current event subscription synchronization height in the database and the current block height, and queries the subscription events on the blockchain network.

[0078] The event subscription synchronization height refers to the block height corresponding to the latest synchronized subscription event queried from the database. When the application layer is interrupted, the event subscription component suspends the subscription event of the new block generated on the blockchain during the process, so there is a certain height difference between the event subscription synchronization height and the interval height of the new block. Based on this, in this step, if the application layer is monitored to have an abnormal operation state such as a crash or restart, when the application layer recreates the instance, using the same blockchain link and event subscription input parameters as the previous subscription, the event subscription component queries the event subscription synchronization height in the above-mentioned database storing the persistent subscription, and then determines the block height of the new block generated on the current blockchain, and the height difference between the event subscription synchronization height, and pulls the event content in the middle of the difference, so that the subscription log generated by the intermediate block can be aligned. In the above steps, the block state of the event subscription can be selectively maintained, that is, by maintaining and updating the blockchain block height corresponding to the event subscription, to ensure that even if there are problems such as application interruption or project crash, the events generated on the blockchain during the interruption process can be restored when the application layer is restarted.

[0079] The following is a brief description of the blockchain event subscription restart process. Figure 4. In this application scenario, an interruption occurs when the application layer crashes or restarts, and the event subscription component suspends subscribing to new block events generated on the blockchain. After the application layer recovers, the subscription is restarted. When the application layer recreates the instance and uses the same blockchain link and event subscription input parameters, the event subscription component queries the database for the event subscription status, and queries the blockchain events within the range of the current block height and the subscription block height based on the existing event subscription synchronization height fed back by the event subscription table of the database. The blockchain events queried at this time are the historical subscription events during the interruption process; the event subscription component pushes the above-queried historical subscription events to the application layer and updates the subscription block height.

[0080] Through the above steps S241 to S242, by providing an event subscription component that supports persistent subscription, a subscription method that can automatically pull up the subscription log generated by the intermediate block when the subscription is restored at the application layer is implemented, so that when a problem occurs at the application layer, the historical events of the interruption process can be restored and automatically pulled, effectively preventing the problem of event data loss that is easily caused by problems such as crashes at the application layer, thereby improving the reliability of blockchain event subscription processing.

[0081] In some embodiments, the above-mentioned use of the event subscription component to persist the block height corresponding to the subscription event may also include the following steps:

[0082] Determine the preset callback function; call the callback function through the event subscription component, obtain the subscription event and block height, and persist the subscription event and block height.

[0083] Among them, the application layer registers a callback function while registering the event subscription; in the persistence step, the application layer event is first notified through the callback function, and the persistence of the subscribed event block height is performed only when the callback function is executed successfully; when the application layer processing fails, it will not be persisted immediately, but the subsequent new blocks and events in this interval will continue to be pushed until the application layer processing is completed, and the block height will be persisted.

[0084] The following is a code example of a callback function interface based on the Go language in an embodiment of the present application: AddSubscription(tag string,addresses[]common.Address,topics[][]common.Hash,isPersisted bool,handler func(ctx*subTypes.SubClientCtx,brl*subTypes.BlockRangeLogs)(err error))error.

[0085] In the above example, tag string is an identifier or label that uniquely identifies this subscription; it allows the caller to later manage (such as unsubscribe) this specific subscription based on this tag. addresses[]common.Address is a list of addresses that specifies which accounts (or contracts) whose addresses' logs will be monitored. common.Address is commonly used to represent Ethereum addresses. topics[][]common.Hash is a two-dimensional hash list that specifies the topics of the logs to subscribe to; in Ethereum, logs (also called events) can have one or more topics, which are used to filter logs. isPersisted bool indicates whether the subscription should be persisted. If set to true, the subscription should remain valid even after the program is restarted. handler func(ctx*subTypes.SubClientCtx,brl*subTypes.BlockRangeLogs)(err error) is the callback function that will be called when the subscribed log is triggered.

[0086] In this step, the application layer triggers the above callback function when subscribing, and asynchronously notifies the caller of the subscribed event content and the block range of the event through callback, so that the application can respond to the events on the blockchain in a timely manner.

[0087] The following describes the invention in conjunction with specific embodiments. Figure 5 is a flowchart of another method for subscribing to blockchain events according to an embodiment of the present application, such as Figure 5 As shown, the process includes the following steps:

[0088] Step S501, create an event subscription instance, the instance creates a block header subscription event to the corresponding blockchain. The application layer creates an event subscription component, passes in the query link and event subscription link of the corresponding blockchain node, and the event device automatically generates a block subscription.

[0089] Step S502, using the instance to create an event subscription, during which it is checked whether the database already exists, and if so, the events generated in the middle are supplemented.

[0090] Step S503, when a new block is generated by the blockchain, the subscription-related events in the new block are queried according to the event subscription, and the events are pushed to the application layer. Among them, when a new block is generated by the blockchain, the device obtains the event generated by the new block, queries each subscription in the event subscription component to see whether the subscription event generated in the new block exists, and pushes the queried event to the application layer for processing. If the block does not generate the corresponding subscription event or the application layer has completed the processing, the event subscription component will determine whether the current instance is persistent. If it is persistent, the latest block subscription height will be updated to the data table.

[0091] Step S504, updating the subscription block height according to the application layer processing result.

[0092] It should be noted that the steps shown in the above process or the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0093] This embodiment also provides a subscription device for blockchain, which is used to implement the above embodiments and preferred implementations, and will not be repeated here. As used below, the terms "module", "unit", "subunit", etc. can implement a combination of software and / or hardware for a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.

[0094] Figure 6 is a structural block diagram of a blockchain event subscription device according to an embodiment of the present application, such as Figure 6 As shown, the device includes: a creation module 62, which is used to create an event subscription component in the application layer; a subscription module 64, which is used to use the event subscription component to obtain the subscription event of the new block when a new block is sensed to be generated on the blockchain network connected to the application layer; a persistence module 66, which is used to use the event subscription component to persist the block height corresponding to the subscription event.

[0095] In some of the embodiments, the creation module 62 is also used to obtain the blockchain node link and the event subscription link; the creation module 62 passes the blockchain node link and the event subscription link at the application layer to generate an event subscription component.

[0096] In some of the embodiments, the event subscription component is also configured with database link parameters; the persistence module is also used to utilize the event subscription component to call the database link parameters and persist the block height to the database corresponding to the database link parameters.

[0097] In some embodiments, the above-mentioned subscription device also includes a restart module; the restart module is used to monitor the running status of the application layer; the restart module is also used to obtain the event subscription instance recreated by the application layer when the running status is monitored to indicate that the application layer is abnormal; the restart module uses the event subscription instance to determine the current event subscription synchronization height in the database, the height difference between the current block height, and query the subscription events on the blockchain network.

[0098] In some of the embodiments, the subscription device further includes a memory subscription module; the memory subscription module is used to store the block height into a preset storage space by using an event subscription component.

[0099] In some of the embodiments, the persistence module 66 is further used to determine a preset callback function; the persistence module 66 calls the callback function through the event subscription component, obtains the subscription event and the block height, and persists the block height.

[0100] In some of the embodiments, there is at least one of the above-mentioned event subscription components; each event subscription component corresponds to a blockchain network.

[0101] This embodiment also provides a blockchain event subscription system, which includes: an application layer, a blockchain network, and a blockchain event subscription device as described in any of the above embodiments.

[0102] It should be noted that the above modules can be functional modules or program modules, and can be implemented by software or hardware. For modules implemented by hardware, the above modules can be located in the same processor; or the above modules can be located in different processors in any combination.

[0103] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 7 As shown. The computer device includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store block height data. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a subscription method for blockchain events is implemented.

[0104] Those skilled in the art will understand that Figure 7The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0105] This embodiment further provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.

[0106] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.

[0107] Optionally, in this embodiment, the processor may be configured to perform the following steps through a computer program:

[0108] S1, create an event subscription component at the application layer.

[0109] S2, using the event subscription component, obtains the subscription event of the new block when sensing that a new block is generated on the blockchain network connected to the application layer.

[0110] S3, uses the event subscription component to persist the block height corresponding to the subscription event.

[0111] It should be noted that the specific examples in this embodiment can refer to the examples described in the above embodiments and optional implementation modes, and this embodiment will not be described in detail here.

[0112] In addition, in combination with the blockchain event subscription method in the above embodiment, the present application embodiment can provide a storage medium for implementation. The storage medium stores a computer program; when the computer program is executed by the processor, any blockchain event subscription method in the above embodiment is implemented.

[0113] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).

[0114] Those skilled in the art should understand that the technical features of the above-described embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above-described embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0115] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.

Claims

1. A method for subscribing to blockchain events, characterized in that: The method comprises: Create an event subscription component at the application layer; Using the event subscription component, when sensing that a new block is generated on the blockchain network connected to the application layer, obtaining a subscription event of the new block; The event subscription component is used to persist the block height corresponding to the subscription event.

2. The subscription method according to claim 1, characterized in that: The step of creating an event subscription component at the application layer includes: Get blockchain node link and event subscription link; The blockchain node link and the event subscription link are passed into the application layer to generate the event subscription component.

3. The subscription method according to claim 1, characterized in that: The event subscription component is also configured with database link parameters; the use of the event subscription component to persist the block height corresponding to the subscription event includes: The event subscription component is used to call the database link parameter, and the block height is persisted in the database corresponding to the database link parameter.

4. The subscription method according to claim 3, characterized in that: After persisting the block height corresponding to the subscription event, the method further includes: Monitoring the running status of the application layer; When it is monitored that the running status indicates that the application layer is abnormal, obtaining the event subscription instance recreated by the application layer; Utilizing the event subscription instance, determine the height difference between the current event subscription synchronization height in the database and the current block height, and query the subscription events on the blockchain network.

5. The subscription method according to claim 3, characterized in that: After obtaining the subscription event of the new block, the method further includes: The event subscription component is used to store the block height in a preset storage space.

6. The subscription method according to claim 1, characterized in that: The utilizing the event subscription component to persist the block height corresponding to the subscription event includes: Determine the preset callback function; The callback function is called through the event subscription component to obtain the subscription event and the block height, and the block height is persisted.

7. The subscription method according to any one of claims 1 to 6, characterized in that: There is at least one event subscription component; each event subscription component corresponds to a blockchain network.

8. A blockchain event subscription device, characterized in that: include: Create a module to create event subscription components in the application layer; A subscription module, configured to utilize the event subscription component to obtain a subscription event of a new block when sensing that a new block is generated on the blockchain network connected to the application layer; The persistence module is used to use the event subscription component to persist the block height corresponding to the subscription event.

9. A blockchain event subscription system, characterized in that: include: An application layer, a blockchain network, and a subscription device for blockchain events as described in claim 8.

10. A storage medium, characterized in that: The storage medium stores a computer program, wherein the computer program is configured to execute the blockchain event subscription method described in any one of claims 1 to 7 when running.

Citation Information

Cited By

  • Method and system for optimizing eBPF monitoring service based on dynamic subscription mechanism

    CN119906757A