Data subscription processing method and device based on block chain, readable medium and equipment
By creating file descriptors in the memory space of blockchain nodes and directly transmitting data, the problem of excessive data replication in the data subscription process in the prior art is solved, and the performance of the blockchain system is improved.
Patent Information
- Application Number
- CN202311426468.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-30
- Publication Date
- 2025-05-02
AI Technical Summary
When existing blockchain systems process multiple data subscription requests, they require multiple data copy operations, resulting in excessive consumption of CPU and memory resources, affecting system performance.
By querying the target data in the local storage space of the blockchain node and reading it into the memory space to create a file descriptor, the file descriptor is sent directly to the operating system to transmit the target data to the data subscriber, reducing the data copying process.
It reduces data replication operations during the data subscription process, saves memory and CPU resources consumption, and improves the subscription processing performance of blockchain systems.
Smart Images

Figure CN119917536A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer and communication technology, and more specifically, to a blockchain-based data subscription processing method, apparatus, readable medium and device. Background Art
[0002] Blockchain systems usually support subscription functions, such as subscription to block information, subscription to transaction information, subscription to events, etc. In the related art, the subscription process is mainly that after the client establishes a connection with the server (i.e., the blockchain system), the application on the server queries the subscription data from the database of the blockchain system, and then loads the subscription data into the memory of the blockchain node, and also needs to copy the subscription data from the memory to the buffer of the application for subsequent sending processing. In this case, if there are many subscription requests, the solution in the related art will consume a lot of CPU (Central Processing Unit) and memory resources because it involves multiple data copy operations. Summary of the invention
[0003] The embodiments of the present application provide a blockchain-based data subscription processing method, apparatus, readable medium and device, which can reduce the data copying process in the data subscription process, save the consumption of memory resources and CPU resources, and help improve the subscription processing performance of the blockchain system.
[0004] Other features and advantages of the present application will become apparent from the following detailed description, or may be learned in part by the practice of the present application.
[0005] According to one aspect of an embodiment of the present application, a blockchain-based data subscription processing method is provided, including: in response to a blockchain data subscription request sent by a data subscriber, querying the target data corresponding to the blockchain data subscription request in the local storage space of the blockchain node; reading the queried target data into the memory space of the blockchain node, and creating a file descriptor corresponding to the target data in the memory space; sending the file descriptor to the operating system of the blockchain node, so that the operating system transfers the target data in the memory space to the data subscriber based on the file descriptor.
[0006] According to one aspect of an embodiment of the present application, a blockchain-based data subscription processing device is provided, including: a query unit, configured to respond to a blockchain data subscription request sent by a data subscriber, and query the target data corresponding to the blockchain data subscription request in the local storage space of the blockchain node; a processing unit, configured to read the queried target data into the memory space of the blockchain node, and create a file descriptor corresponding to the target data in the memory space; a sending unit, configured to send the file descriptor to the operating system of the blockchain node, so that the operating system transmits the target data in the memory space to the data subscriber based on the file descriptor.
[0007] In some embodiments of the present application, based on the aforementioned scheme, the processing unit is configured to: call a DMA (Direct Memory Access) controller to read the target data from the local storage space to the memory space of the blockchain node, and create a file descriptor corresponding to the target data in the memory space.
[0008] In some embodiments of the present application, based on the aforementioned scheme, the sending unit is configured to: send the file descriptor to the operating system of the blockchain node through a system call, so that the operating system calls the DMA controller to transfer the target data in the memory space to the data subscriber through the network card device of the blockchain node.
[0009] In some embodiments of the present application, based on the aforementioned scheme, the sending unit is configured to: initiate a sendfile system call to transfer the file descriptor from the kernel buffer of the memory space to the socket buffer in the memory space, so that the operating system of the blockchain node calls the DMA controller to transmit the target data in the memory space to the data subscriber through the network card device of the blockchain node.
[0010] In some embodiments of the present application, based on the aforementioned scheme, the data subscription processing device also includes: an identity authentication unit, configured to verify the identity of the data subscriber before querying the target data corresponding to the blockchain data subscription request in the local storage space of the blockchain node; the query unit is configured to: if the identity authentication of the data subscriber is passed, determine the data access rights of the data subscriber according to the identity information of the data verifier, so as to query the local storage space of the blockchain node for the target data that the data subscriber has access rights and corresponds to the blockchain data subscription request based on the data access rights.
[0011] In some embodiments of the present application, based on the aforementioned scheme, the processing unit is further configured to: refuse to respond to the blockchain data subscription request if the identity authentication of the data subscriber fails.
[0012] In some embodiments of the present application, based on the aforementioned scheme, the data subscription processing device also includes: a memory mapping unit, configured to map the memory space of the blockchain node to the address space of the data subscription processing module by means of memory mapping; a data access unit, configured to access the data in the memory space based on the pointer of the blockchain data in the address space of the data subscription processing module.
[0013] In some embodiments of the present application, based on the aforementioned scheme, the data access unit is configured to: find the target data in the memory space based on the pointer of the blockchain data in the address space of the data subscription processing module; encrypt the target data so as to transmit the encrypted target data to the data subscriber.
[0014] In some embodiments of the present application, based on the aforementioned scheme, the data subscription processing device further includes: a negotiation unit configured to communicate and negotiate with the data subscriber to agree with the data subscriber on a decryption key for the target data.
[0015] In some embodiments of the present application, based on the aforementioned scheme, a smart contract is deployed in the blockchain node; wherein the smart contract is used to respond to the blockchain data subscription request to execute query processing of the target data, read the target data into the memory space, and create a file descriptor corresponding to the target data in the memory space, and send the file descriptor to the operating system of the blockchain node.
[0016] In some embodiments of the present application, based on the aforementioned scheme, the file descriptor corresponding to the target data contains address information of the target data in the memory space and length information of the target data; wherein, the address information and the length information are used to enable the operating system to locate the target data in the memory space, so as to transfer the target data in the memory space to the data subscriber.
[0017] According to one aspect of an embodiment of the present application, a computer-readable medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the blockchain-based data subscription processing method as described in the above embodiment is implemented.
[0018] According to one aspect of an embodiment of the present application, an electronic device is provided, comprising: one or more processors; a storage device for storing one or more computer programs, wherein when the one or more computer programs are executed by the one or more processors, the electronic device implements the blockchain-based data subscription processing method as described in the above embodiments.
[0019] According to one aspect of an embodiment of the present application, a computer program product is provided, the computer program product comprising a computer program, the computer program being stored in a computer-readable storage medium. A processor of an electronic device reads and executes the computer program from the computer-readable storage medium, so that the electronic device executes the data subscription processing method based on blockchain provided in the above various optional embodiments.
[0020] In the technical solutions provided by some embodiments of the present application, after querying the target data corresponding to the blockchain data subscription request in the local storage space of the blockchain node, the queried target data is read into the memory space of the blockchain node, and a file descriptor corresponding to the target data is created in the memory space, and then the file descriptor is sent to the operating system of the blockchain node, so that the operating system of the blockchain node can transmit the target data in the memory space of the blockchain node to the data subscriber based on the file descriptor. It can be seen that in the technical solutions of the embodiments of the present application, the subscribed target data will only be read into the memory space of the blockchain node, and there is no need to pass the subscription data to the sending buffer through multiple copy operations and then send it to the data subscriber, thereby reducing the data copy process in the data subscription process, saving the consumption of memory resources and CPU resources, and helping to improve the subscription processing performance of the blockchain system.
[0021] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 A schematic diagram of the structure of a blockchain network is shown;
[0023] Figure 2 A schematic diagram showing the connection relationship between blocks in the blockchain;
[0024] Figure 3 A flowchart of a subscription process based on blockchain is shown;
[0025] Figure 4 Shows Figure 3 The specific flow chart of the blockchain node sending the filtered data to the client shown in;
[0026] Figure 5A flowchart of a data subscription processing method based on blockchain according to an embodiment of the present application is shown;
[0027] Figure 6 A transmission flow chart of subscription data according to an embodiment of the present application is shown;
[0028] Figure 7 A schematic diagram showing a subscription processing process according to an embodiment of the present application is shown;
[0029] Figure 8 A schematic diagram of a permission verification process according to an embodiment of the present application is shown;
[0030] Fig. 9 A block diagram of a data subscription processing device based on blockchain according to an embodiment of the present application is shown;
[0031] Fig.10 A schematic diagram of the structure of a computer system suitable for implementing an electronic device of an embodiment of the present application is shown. DETAILED DESCRIPTION
[0032] The exemplary embodiments are now described in a more comprehensive manner with reference to the accompanying drawings. However, the exemplary embodiments can be implemented in various forms and should not be understood as being limited to these examples; on the contrary, the purpose of providing these embodiments is to make this application more comprehensive and complete, and to fully convey the concept of the exemplary embodiments to those skilled in the art.
[0033] In addition, the features, structures or characteristics described in the present application may be combined in one or more embodiments in any suitable manner. In the following description, there are many specific details so that the embodiments of the present application can be fully understood. However, those skilled in the art will appreciate that when implementing the technical scheme of the present application, all the detailed features in the embodiments may not be needed, one or more specific details may be omitted, or other methods, elements, devices, steps, etc. may be adopted.
[0034] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0035] The flowcharts shown in the accompanying drawings are only exemplary and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps can be decomposed, and some operations / steps can be combined or partially combined, so the actual execution order may change according to actual conditions.
[0036] It should be noted that the "multiple" mentioned in this article refers to two or more. "And / or" describes the association relationship of the associated objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the associated objects before and after are in an "or" relationship.
[0037] It is understandable that this application can display a prompt interface or pop-up window before collecting relevant data (such as blockchain data, target data subscribed by the data subscriber, etc.) and during the process of collecting relevant data. The prompt interface or pop-up window is used to prompt the user that the relevant data is currently being collected, so that this application only starts to execute the relevant steps of obtaining relevant data after obtaining the user's confirmation operation on the prompt interface or pop-up window, otherwise (that is, when the user's confirmation operation on the prompt interface or pop-up window is not obtained), the step of obtaining relevant data is terminated, that is, the relevant data is not obtained. In other words, all data collected by this application are collected with the user's consent and authorization, and the collection, use and processing of relevant data need to comply with the relevant laws, regulations and standards of relevant countries and regions.
[0038] The technical solution of the embodiment of the present application involves blockchain technology. Specifically, blockchain is a new application mode of computer technologies such as distributed data storage, point-to-point transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks (i.e., blocks) generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, the platform product service layer, and the application service layer.
[0039] The underlying blockchain platform can include processing modules such as user management, basic services, smart contracts, and operation management. Among them, the user management module is responsible for the identity information management of all blockchain participants, including maintaining the generation of public and private keys (account management), key management, and the maintenance of the corresponding relationship between user information and blockchain addresses (authority management). The basic service module is deployed on all blockchain node devices to verify the validity of business requests and record the valid requests to the storage after consensus is reached. For a new business request, the basic service first performs interface adaptation analysis and authentication processing (interface adaptation), and then encrypts the business information through the consensus algorithm (consensus management). After encryption, it is completely and consistently transmitted to the shared ledger (network communication) and recorded and stored. The smart contract module is responsible for the registration and issuance of contracts, as well as contract triggering and contract execution. Developers can define the contract logic in a certain programming language and publish it to the blockchain (contract registration). According to the logic of the contract terms, the key or other event triggers the execution to complete the contract logic. At the same time, it also provides the function of contract upgrade and cancellation. The operation management module is mainly responsible for the deployment, configuration modification, contract setting, cloud adaptation and real-time status visualization output of the product during the product release process, such as alarm, network status detection, node device health status detection, etc.
[0040] The platform product service layer provides the basic capabilities and implementation framework of typical applications. Developers can superimpose business features based on these basic capabilities to complete the blockchain implementation of business logic. The application service layer provides application services based on blockchain solutions for business participants to use.
[0041] As mentioned above, blockchain is essentially a decentralized database, and the blockchain is maintained by the nodes in the blockchain network. Figure 1 The blockchain network shown may include multiple nodes 101, and the multiple nodes 101 may be the various clients forming the blockchain network. Each node 101 may receive input information during normal operation, and maintain the shared data in the blockchain network based on the received input information. In order to ensure the information intercommunication within the blockchain network, there may be an information connection between each node in the blockchain network, and information may be transmitted between nodes through the above information connection. For example, when any node in the blockchain network receives input information, other nodes in the blockchain network obtain the input information according to the consensus algorithm, and store the input information as shared data, so that the data stored on all nodes in the blockchain network are consistent.
[0042] Each node in the blockchain network has a corresponding node identifier, and each node in the blockchain network can store the node identifiers of other nodes, so that the generated blocks can be broadcast to other nodes in the blockchain network according to the node identifiers of other nodes. A node identifier list can be maintained in each node, and the node name and node identifier are stored in the node identifier list accordingly. The node identifier can be an IP (Internet Protocol, a protocol for interconnecting networks) address or any other information that can be used to identify the node.
[0043] Each node in the blockchain network stores the same blockchain. The blockchain consists of multiple blocks, see Figure 2 As shown in the figure, the blockchain consists of multiple blocks, which are connected into a chain structure in the order of creation timestamp from small to large. Each block includes a block header and a block body. The block header stores the hash of the previous block and the Merkle root of this block. The block body contains the complete transaction data of this block and is organized in the form of a Merkle tree. From the structure of the blockchain, it can be seen that the block data stored in each block in the blockchain is associated with the block data stored in the parent block (i.e., the previous block), which ensures the security of the information input in the block.
[0044] Each node in the blockchain network can be a server or a terminal device. The server can be an independent physical server, a server cluster or a distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. The terminal device can be a smart phone, tablet computer, laptop computer, desktop computer, smart speaker, smart watch, smart home, vehicle terminal, aircraft, etc., but is not limited to this. Each node can be directly or indirectly connected by wired or wireless communication, and this application is not limited here.
[0045] It should be noted that the Merkle tree is an important part of blockchain technology. The blockchain will not directly save the original data in plain text. The original data needs to be hashed and stored in the form of hash values. The Merkle tree is used to organize the hash values formed by hashing multiple original data according to the binary tree structure and save them in the block body.
[0046] Generally, blockchains support subscription functions, such as block information subscription, transaction information subscription, event subscription, etc. Figure 3 As shown, a blockchain-based subscription processing flow includes the following steps:
[0047] 1. The client initiates a subscription request. Specifically, the client can use the gRPC (Google Remote Procedure Call) protocol to send a subscription request to a blockchain node (such as Figure 3 Node 2) shown in the figure sends a subscription request. The subscription request may include subscription conditions, such as the contract address, event or specific block information of interest, and the client may also specify relevant parameters such as the starting block and event topic.
[0048] 2. The blockchain node receives the subscription request sent by the client and establishes the subscription process. Specifically, after receiving the subscription request, the blockchain node will verify the validity of the subscription request and establish the subscription process. Then, the blockchain node will filter out the qualified data in the database according to the conditions in the subscription request and keep it in the memory for subsequent push to the subscriber (ie, the client).
[0049] 3. The blockchain node sends the filtered data to the client. Specifically, after filtering the data from the database according to the subscription request, the blockchain node pushes the filtered data to the client that initiated the subscription. Optionally, when pushing the filtered data to the client that initiated the subscription, it can be achieved through streaming transmission of the gRPC protocol to ensure that the client can receive the latest data. If multiple subscription events occur, the blockchain node will send the filtered data to the client in turn.
[0050] 4. The client receives and processes the data. Specifically, after receiving the data sent by the blockchain node, the client can process and parse the data and perform corresponding processing according to business needs.
[0051] The processing process of step 3 is as follows: Figure 4 As shown in Figure 1, the data filtered according to the subscription request is copied back and forth from the kernel space to the user space during the reading and writing process, and the data in the kernel space is read or written from the disk through the I / O interface at the operating system level. Figure 4In the process flow shown, two system calls occur, one is read() and the other is write(). Each system call must first switch from user mode to kernel mode, and then switch from kernel mode back to user mode after the kernel completes the task. Therefore, four context switches between user mode and kernel mode occur. A context switch takes tens of nanoseconds to several microseconds. Although the time seems short, in high-concurrency scenarios, this time is easily accumulated and magnified, thus affecting system performance.
[0052] at the same time, Figure 4 There are also 4 data copy processes in the processing flow shown, two of which are DMA copies and the other two are copied by the CPU. The following is an explanation of these 4 data copy processes:
[0053] The first data copy is to query the subscription data on the disk and copy it to the buffer of the operating system kernel (ie, the kernel buffer). This copy process is carried out through DMA.
[0054] The second data copy is to copy the subscription data in the kernel buffer to the user space buffer (ie, user buffer), so that the blockchain program can use this part of data in the user space. This copy process is completed by the CPU.
[0055] The third data copy is to copy the data copied to the user buffer to the socket buffer in the kernel space. This process is still completed by the CPU.
[0056] The fourth data copy is to copy the data in the socket buffer in the kernel space to the buffer of the network card, and then send it to the client through the network card. This process is carried out by DMA.
[0057] Figure 4 The data transmission method shown requires reading data from the disk or network to the application's buffer (i.e., kernel buffer) first, and then copying it to the subscription module's memory (i.e., user buffer). The redundant context switching and data copying cause a lot of unnecessary overhead in a high-concurrency system, which will seriously affect system performance.
[0058] Specifically, in a blockchain network, blockchain nodes need to perform transaction verification, transaction packaging, block consensus, block synchronization, etc. They also need to process and maintain subscription requests, and filter and push corresponding subscription data according to subscription conditions. If there are a large number of concurrent subscription requests or the subscription conditions are too fine-grained, blockchain nodes need to allocate more computing resources to meet processing requirements, which will put a lot of pressure on the computing and bandwidth resources of blockchain nodes, reducing the performance and throughput of blockchain nodes.
[0059] There are also some solutions in the related technology that optimize by setting a cache area, that is, caching the most recently subscribed data in the user memory. When there is the same subscription request, it can be directly read from the user memory to respond to the subscription request. However, this solution also has disadvantages: on the one hand, the same data may not be subscribed frequently; on the other hand, too much cached data cannot be pushed to the client in time, which will cause cache accumulation and OOM (Out Of Memory) situation.
[0060] Based on this, the technical solution of the embodiment of the present application proposes a new blockchain-based data subscription processing solution, which can reduce or avoid the copying operation of data between memories, save the consumption of memory resources and CPU resources, and is conducive to improving the subscription processing performance of the blockchain system, and can also reduce security risks.
[0061] The implementation details of the technical solution of the embodiment of the present application are described in detail below:
[0062] Figure 5 A flowchart of a data subscription processing method based on blockchain according to an embodiment of the present application is shown. The data subscription processing method based on blockchain can be executed by an electronic device, which can be a blockchain node. Figure 5 As shown, the data subscription processing method based on blockchain includes at least steps S510 to S530, which are described in detail as follows:
[0063] In step S510, in response to the blockchain data subscription request sent by the data subscriber, the target data corresponding to the blockchain data subscription request is queried in the local storage space of the blockchain node.
[0064] In some optional embodiments, the data subscriber may be a client that communicates with the blockchain node. Optionally, the blockchain data subscription request mainly defines the conditions for filtering the data. For example, the blockchain data subscription request may include the data type to be subscribed, such as the subscribed block type, transaction information type, event type, etc. The blockchain data subscription request may also include the account information to be subscribed, such as subscribing to the data of a certain account.
[0065] Optionally, the local storage space of the blockchain node is a local database of the blockchain node, such as a disk, a USB flash drive, or a mobile hard disk, etc. The target data corresponding to the blockchain data subscription request is the data in the local storage space of the blockchain node that can meet the data screening conditions defined by the blockchain data subscription request.
[0066] In step S520, the queried target data is read into the memory space of the blockchain node, and a file descriptor corresponding to the target data is created in the memory space.
[0067] It should be noted that the memory space of the blockchain node can be the kernel buffer of the blockchain node. Optionally, the DMA controller can be called to read the queried target data from the local storage space of the blockchain node to the memory space of the blockchain node, and create a file descriptor corresponding to the target data in the memory space of the blockchain node.
[0068] Among them, DMA is a memory access technology implemented by hardware components, which allows certain specific hardware devices, such as hard disk drives, graphics cards, etc., to read or write data directly from the system memory without being transferred through the CPU. In the embodiment of the present application, by calling the DMA controller to read the queried target data from the local storage space of the blockchain node to the memory space of the blockchain node, the task of data processing can be handed over to the hardware device to complete, thereby reducing the burden on the CPU and memory and improving the performance of the entire system.
[0069] Optionally, the file descriptor corresponding to the target data may include address information of the target data in the memory space and length information of the target data; the address information and length information are used to enable the operating system to locate the target data in the memory space, so that after locating the target data, the target data in the memory space can be transmitted to the data subscriber.
[0070] In step S530, the file descriptor corresponding to the target data is sent to the operating system of the blockchain node, so that the operating system transmits the target data in the memory space to the data subscriber based on the file descriptor.
[0071] In some optional embodiments, the process of sending the file descriptor corresponding to the target data to the operating system of the blockchain node may be to send the file descriptor to the operating system of the blockchain node by way of a system call, so that the operating system calls a DMA controller to transfer the target data in the memory space to the data subscriber through the network card device of the blockchain node.
[0072] Optionally, a sendfile system call can be initiated to transfer the file descriptor from the kernel buffer in the memory space to the socket buffer in the memory space, so that the operating system of the blockchain node calls the DMA controller to transfer the target data in the memory space to the data subscriber through the network card device of the blockchain node.
[0073] It should be noted that the sendfile system call can reduce the process of data copying and context switching, thereby improving data transmission efficiency. Specifically, the sendfile system call can copy data directly from the kernel buffer to the socket buffer, avoiding multiple copies of data between user space and kernel space. In the embodiment of the present application, on the basis of using the sendfile system call, the data transmission process is further optimized through the DMA controller, that is, the target data in the memory space is directly transmitted to the data subscriber through the network card device of the blockchain node.
[0074] In one embodiment of the present application, the security of the data subscription process can also be ensured by verifying the identity of the data subscriber. Specifically, before querying the target data corresponding to the blockchain data subscription request, the identity of the data subscriber can be verified. If the identity authentication of the data subscriber is passed, the data access rights of the data subscriber are determined according to the identity information of the data verifier, so as to query the local storage space of the blockchain node for the target data that the data subscriber has access rights and corresponds to the blockchain data subscription request based on the data access rights.
[0075] Optionally, when verifying the identity of the data subscriber, the user name, password, etc. provided by the data subscriber can be verified to determine whether the identity of the data subscriber is legitimate. Once the identity of the data subscriber is authenticated, the data subscriber's access rights to the relevant data can be checked. This process usually involves the access control mechanism in the blockchain smart contract. For example, different roles and permission levels are defined through smart contracts, and only data subscribers who meet specific conditions can obtain corresponding access rights. If the identity of the data subscriber is legitimate and has certain data access rights, the target data that the data subscriber has access rights to and corresponds to the blockchain data subscription request can be queried in the local storage space of the blockchain node.
[0076] In some optional embodiments, if the identity authentication of the data subscriber fails, the blockchain data subscription request may be rejected to ensure the security of the blockchain data.
[0077] In some optional embodiments, since the subscription data queried in the present application is in the memory space of the blockchain node (i.e., the kernel buffer), in order to enable the data subscription processing module to process the subscription data without copying the subscription data, the memory space of the blockchain node can be mapped to the address space of the data subscription processing module through memory mapping, and then the data in the memory space can be accessed based on the pointer of the blockchain data in the address space of the data subscription processing module.
[0078] It should be noted that memory mapping refers to mapping a part of a file or device to the virtual address space of a process (the data subscription processing module in this application), so that the process can access the data in the file or device as if it were accessing its own memory, which can reduce the number of system calls and improve data access efficiency. In the embodiment of the present application, the memory space of the blockchain node is mapped to the address space of the data subscription processing module, that is, an anonymous mapping process. In other embodiments of the present application, a file mapping method can also be used, that is, mapping the files stored in the memory space of the blockchain node to the address space of the data subscription processing module.
[0079] In some optional embodiments, after the memory mapping process is performed, the process of accessing the data in the memory space based on the pointer of the blockchain data in the address space of the data subscription processing module can be to find the target data in the memory space (i.e., the subscription data queried according to the blockchain data subscription request) based on the pointer of the blockchain data in the address space of the data subscription processing module, and then encrypt the found target data to facilitate the transmission of the encrypted target data to the data subscriber, thereby ensuring the security of the subscription data transmission process.
[0080] In some optional embodiments, the blockchain node may communicate and negotiate with the data subscriber in advance to agree with the data subscriber on the decryption key of the target data, so that after receiving the encrypted target data, the data subscriber may decrypt the target data based on the agreed decryption key. Optionally, the encryption of the target data may be performed using an asymmetric key or a symmetric key.
[0081] In some optional embodiments, a smart contract may be deployed in the blockchain node, and the smart contract is used to respond to the blockchain data subscription request to perform query processing of the target data, read the target data into the memory space, and create a file descriptor corresponding to the target data in the memory space, and send the file descriptor to the operating system of the blockchain node. That is, the data subscription process in the embodiment of the present application can be implemented by a smart contract, which can ensure the legitimacy of the data subscription process.
[0082] The following combination Figures 6 to 8 The implementation details of the technical solution of the embodiment of the present application are further elaborated:
[0083] In an embodiment of the present application, after the subscribed data is queried in the local storage space of the blockchain node, it can be sent directly to the client through the network adapter, avoiding the overhead of data replication, which means that the subscribed data will be read directly from the memory of the blockchain node instead of being copied to the user buffer of the blockchain program first.
[0084] Specifically, if Figure 6 As shown, the blockchain program running on the blockchain node can initiate a sendfile system call from the user space, and then the context switches from the user state to the kernel state (i.e., switch 1). The DMA controller then copies the subscribed data from the disk to the kernel buffer, and then the CPU sends the file descriptor information in the kernel buffer (including the memory address and offset of the kernel buffer) to the socket buffer. After that, the DMA controller directly copies the subscribed data from the kernel buffer to the network card based on the file descriptor information and sends it to the subscribed client. At the same time, the context switches from the kernel state back to the user state (i.e., switch 2), and the sendfile system call returns.
[0085] from Figure 6 It can be seen that the technical solution of the embodiment of the present application uses the sendfile system call and DMA technology to enable I / O to perform two context switches between the user space and the kernel space and two data copies when transmitting subscription data. Both data copies are DMA copies, and the data is not moved by the CPU throughout the process. This can reduce the data copying process in the data subscription process, save memory resources and CPU resource consumption, and is conducive to improving the subscription processing performance of the blockchain system.
[0086] Figure 6 The details of the specific implementation of the process shown can be referred to Figure 7 As shown, the client sends a subscription request to the blockchain node, and then the blockchain program on the blockchain node initiates a query request to the database of the blockchain node to obtain the required data (i.e., the subscription data that satisfies the subscription request). Once the database returns the query result (i.e., the subscription data that satisfies the subscription request is found), the blockchain program can read the subscription data from the database to the kernel buffer of the blockchain node. At this stage, the subscription data still exists in the address space of the blockchain program.
[0087] The blockchain program then uses the DMA scatter / gather function to create a file descriptor list (i.e., a scatter / gather list, which specifically describes the distribution of data in memory), which contains the address information (such as source address, destination address, etc.) and length information (i.e., data length) of the subscribed data in memory. The blockchain program then uses the sendfile system call to pass the file descriptor list and the associated socket file descriptor to the operating system. In this way, the operating system can directly operate these descriptors in the kernel space and use the DMA scatter / gather function to transfer data from various distributed locations in the node memory to the client's socket buffer.
[0088] It can be seen that based on Figure 7 As shown in the processing flow, the blockchain program can send the subscription data queried from the database to the client quickly and efficiently, reducing the overhead of data replication and memory copying, and improving the performance and efficiency of data transmission. It is worth noting that the specific implementation method and the interface name called may vary depending on the operating system and programming language.
[0089] In addition, the technical solution of the embodiment of the present application adopts the method of memory mapping and data pointer operation. The module that performs subscription processing (i.e., subscription processing module, which can be a blockchain program) can directly perform the required operations on the subscription data in the memory of the blockchain node without copying the subscription data to its own memory buffer, thereby avoiding the overhead of data copying and improving processing efficiency. Memory mapping means that after the subscription module establishes a connection with the blockchain node, it can use memory mapping to map the memory of the blockchain node to its own address space, so that the subscription module can directly access the blockchain data stored in the node memory without copying the data to its own buffer; and data pointer operation means that through memory mapping, the subscription module can obtain a pointer directly pointing to the blockchain data. Using these pointers, the subscription module can directly read, parse and process the data without copying the data from the blockchain node to its own memory area.
[0090] In one embodiment of the present application, the security of the subscription process can be enhanced by combining the permission control module of the blockchain. Specifically, the blockchain usually has a flexible permission control mechanism, which can control access to data according to different roles and identities. The subscription processing module can be integrated with the permission control module of the blockchain to perform identity authentication and permission checks on subscribers before data subscription. Figure 8As shown, the user identity can be verified first, and then the user authority can be verified (of course, the user identity and user authority can also be verified at the same time). Only legitimate users who have been authenticated can successfully subscribe to relevant data, and only when authorized users or subscription modules can obtain corresponding permissions can memory mapping and data pointer operations be performed. This ensures that the data processing process is only carried out within the authorized scope, reducing the risk of illegal access or attack.
[0091] In one embodiment of the present application, the data in the blockchain may contain private information. In order to ensure the security of the data, the encryption algorithm and digital signature technology provided by the blockchain can be used to ensure the confidentiality and integrity of the data. For example, during the transmission of subscription data, appropriate encryption protocols and keys are used to encrypt and decrypt data to prevent data from being illegally obtained or stolen. At the same time, since smart contracts are one of the core components of the blockchain, access permission rules and data processing logic can be defined through smart contracts. Therefore, when executing the data processing process in the embodiment of the present application, the operation of the subscription module can be embedded in the smart contract, and the contract can be detected and verified through the audit mechanism, so that it can be ensured that the subscription module only performs legal operations and avoids additional risks to data operations.
[0092] In summary, the technical solution of the embodiment of the present application can reduce or avoid the copy operation of data between memories when performing subscription processing in the blockchain system, thereby improving the processing performance of the blockchain node. By directly passing the file descriptor information to the network transport layer, data can be directly transmitted from the memory to the network, avoiding the operation of copying data from the memory to the send buffer. At the same time, the present application also introduces a permission control scheme to manage the subscription process, reducing security risks.
[0093] The following describes an embodiment of the device of the present application, which can be used to execute the data subscription processing method based on blockchain in the above embodiment of the present application. For details not disclosed in the embodiment of the device of the present application, please refer to the embodiment of the data subscription processing method based on blockchain in the above embodiment of the present application.
[0094] Fig. 9 A block diagram of a blockchain-based data subscription processing device according to an embodiment of the present application is shown. The blockchain-based data subscription processing device can be applied to an electronic device, which can be a blockchain node.
[0095] Reference Fig. 9 As shown, a blockchain-based data subscription processing device 900 according to an embodiment of the present application includes: a query unit 902, a processing unit 904 and a sending unit 906.
[0096] Among them, the query unit 902 is configured to respond to the blockchain data subscription request sent by the data subscriber, and query the target data corresponding to the blockchain data subscription request in the local storage space of the blockchain node; the processing unit 904 is configured to read the queried target data into the memory space of the blockchain node, and create a file descriptor corresponding to the target data in the memory space; the sending unit 906 is configured to send the file descriptor to the operating system of the blockchain node, so that the operating system transfers the target data in the memory space to the data subscriber based on the file descriptor.
[0097] In some embodiments of the present application, based on the aforementioned scheme, the processing unit 904 is configured to: call the DMA controller, read the target data from the local storage space to the memory space of the blockchain node, and create a file descriptor corresponding to the target data in the memory space.
[0098] In some embodiments of the present application, based on the aforementioned scheme, the sending unit 906 is configured to: send the file descriptor to the operating system of the blockchain node through a system call, so that the operating system calls the DMA controller to transfer the target data in the memory space to the data subscriber through the network card device of the blockchain node.
[0099] In some embodiments of the present application, based on the aforementioned scheme, the sending unit 906 is configured to: initiate a sendfile system call to transfer the file descriptor from the kernel buffer of the memory space to the socket buffer in the memory space, so that the operating system of the blockchain node calls the DMA controller to transmit the target data in the memory space to the data subscriber through the network card device of the blockchain node.
[0100] In some embodiments of the present application, based on the aforementioned scheme, the data subscription processing device 900 also includes: an identity authentication unit, configured to verify the identity of the data subscriber before querying the target data corresponding to the blockchain data subscription request in the local storage space of the blockchain node; the query unit 902 is configured to: if the identity authentication of the data subscriber is passed, determine the data access rights of the data subscriber according to the identity information of the data verifier, so as to query the local storage space of the blockchain node for the target data that the data subscriber has access rights and corresponds to the blockchain data subscription request based on the data access rights.
[0101] In some embodiments of the present application, based on the aforementioned scheme, the processing unit 904 is further configured to: if the identity authentication of the data subscriber fails, refuse to respond to the blockchain data subscription request.
[0102] In some embodiments of the present application, based on the aforementioned scheme, the data subscription processing device 900 also includes: a memory mapping unit, configured to map the memory space of the blockchain node to the address space of the data subscription processing module by memory mapping; a data access unit, configured to access the data in the memory space based on the pointer of the blockchain data in the address space of the data subscription processing module.
[0103] In some embodiments of the present application, based on the aforementioned scheme, the data access unit is configured to: find the target data in the memory space based on the pointer of the blockchain data in the address space of the data subscription processing module; encrypt the target data so as to transmit the encrypted target data to the data subscriber.
[0104] In some embodiments of the present application, based on the aforementioned solution, the data subscription processing device 900 further includes: a negotiation unit configured to communicate and negotiate with the data subscriber to agree with the data subscriber on a decryption key for the target data.
[0105] In some embodiments of the present application, based on the aforementioned scheme, a smart contract is deployed in the blockchain node; wherein the smart contract is used to respond to the blockchain data subscription request to execute query processing of the target data, read the target data into the memory space, and create a file descriptor corresponding to the target data in the memory space, and send the file descriptor to the operating system of the blockchain node.
[0106] In some embodiments of the present application, based on the aforementioned scheme, the file descriptor corresponding to the target data contains address information of the target data in the memory space and length information of the target data; wherein, the address information and the length information are used to enable the operating system to locate the target data in the memory space, so as to transfer the target data in the memory space to the data subscriber.
[0107] Fig.10 A schematic diagram of the structure of a computer system of an electronic device suitable for implementing an embodiment of the present application is shown, and the electronic device may be a blockchain node in the aforementioned embodiment.
[0108] It should be noted that Fig.10The computer system 1000 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0109] like Fig.10 As shown, the computer system 1000 may include a central processing unit (CPU) 1001, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 1002 or the program loaded from the storage part 1008 to the random access memory (RAM) 1003, such as executing the method described in the above embodiment. In the RAM 1003, various programs and data required for system operation are also stored. The CPU 1001, the ROM 1002 and the RAM 1003 are connected to each other through the bus 1004. The input / output (I / O) interface 1005 is also connected to the bus 1004.
[0110] The following components can be connected to the I / O interface 1005: an input section 1006 including a keyboard, a mouse, etc.; an output section 1007 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 1008 including a hard disk, etc.; and a communication section 1009 including a network interface card such as a LAN (Local Area Network) card, a modem, etc. The communication section 1009 performs communication processing via a network such as the Internet. A drive 1010 is also connected to the I / O interface 1005 as needed. A removable medium 1011, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 1010 as needed, so that a computer program read therefrom is installed into the storage section 1008 as needed.
[0111] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program is used to perform the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication part 1009, and / or installed from a removable medium 1011. When the computer program is executed by a central processing unit (CPU) 1001, various functions defined in the system of the present application are executed.
[0112] It should be noted that the computer-readable medium shown in the embodiment of the present application may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium may be any tangible medium containing or storing a computer program, which may be used by an instruction execution system, device or device or used in combination with it. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, wherein a computer-readable computer program is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate, or transmit programs for use by or in conjunction with an instruction execution system, apparatus, or device. The computer program contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0113] The flowchart and block diagram in the accompanying drawings illustrate the possible architecture, functions and operations of the system, method and computer program product according to various embodiments of the present application. Wherein, each box in the flowchart or block diagram can represent a module, a program segment, or a part of the code, and the above-mentioned module, program segment, or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of the boxes in the block diagram or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and a computer program.
[0114] The units involved in the embodiments described in this application may be implemented by software or hardware, and the units described may also be set in a processor. The names of these units do not, in some cases, constitute limitations on the units themselves.
[0115] As another aspect, the present application also provides a computer-readable medium, which may be included in the electronic device described in the above embodiment; or may exist independently without being assembled into the electronic device. The above computer-readable medium carries one or more computer programs, and when the above one or more computer programs are executed by an electronic device, the electronic device implements the method described in the above embodiment.
[0116] It should be noted that, although several modules or units of the equipment for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present application, the features and functions of two or more modules or units described above can be embodied in one module or unit. On the contrary, the features and functions of one module or unit described above can be further divided into being embodied by multiple modules or units.
[0117] Through the description of the above implementation methods, it is easy for those skilled in the art to understand that the example implementation methods described here can be implemented by software or by combining software with necessary hardware. Therefore, the technical solution according to the implementation methods of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, and includes several instructions to enable an electronic device to execute the method according to the implementation methods of the present application.
[0118] For example, an electronic device can be a blockchain node that can execute Figure 5 The blockchain-based data subscription processing method shown.
[0119] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the embodiments disclosed herein. The present application is intended to cover any variations, uses or adaptations of the present application, which follow the general principles of the present application and include common knowledge or customary technical means in the art that are not disclosed in the present application.
[0120] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
Claims
1. A data subscription processing method based on blockchain, characterized in that: include: In response to a blockchain data subscription request sent by a data subscriber, querying the local storage space of the blockchain node for target data corresponding to the blockchain data subscription request; Read the queried target data into the memory space of the blockchain node, and create a file descriptor corresponding to the target data in the memory space; The file descriptor is sent to the operating system of the blockchain node, so that the operating system transmits the target data in the memory space to the data subscriber based on the file descriptor.
2. The data subscription processing method based on blockchain according to claim 1 is characterized in that: The queried target data is read into the memory space of the blockchain node, and a file descriptor corresponding to the target data is created in the memory space, including: A direct memory access DMA controller is called to read the target data from the local storage space into the memory space of the blockchain node, and a file descriptor corresponding to the target data is created in the memory space.
3. The data subscription processing method based on blockchain according to claim 1 is characterized in that: Sending the file descriptor to the operating system of the blockchain node includes: The file descriptor is sent to the operating system of the blockchain node by way of a system call, so that the operating system calls a DMA controller to transmit the target data in the memory space to the data subscriber through the network card device of the blockchain node.
4. The data subscription processing method based on blockchain according to claim 3 is characterized in that: The method includes sending the file descriptor to the operating system of the blockchain node by way of a system call, so that the operating system calls a DMA controller to transmit the target data in the memory space to the data subscriber through the network card device of the blockchain node, including: A sendfile system call is initiated to transfer the file descriptor from the kernel buffer of the memory space to the socket buffer in the memory space, so that the operating system of the blockchain node calls the DMA controller to transfer the target data in the memory space to the data subscriber through the network card device of the blockchain node.
5. The data subscription processing method based on blockchain according to claim 1 is characterized in that: Before querying the local storage space of the blockchain node for the target data corresponding to the blockchain data subscription request, the data subscription processing method further includes: Verifying the identity of the data subscriber; If the identity authentication of the data subscriber is passed, the data access rights of the data subscriber are determined according to the identity information of the data verifier, so as to query the local storage space of the blockchain node for target data to which the data subscriber has access rights and which corresponds to the blockchain data subscription request based on the data access rights.
6. The data subscription processing method based on blockchain according to claim 5 is characterized in that: The data subscription processing method further includes: If the identity authentication of the data subscriber fails, the blockchain data subscription request will be rejected.
7. The data subscription processing method based on blockchain according to claim 1 is characterized in that: The data subscription processing method further includes: Mapping the memory space of the blockchain node to the address space of the data subscription processing module by means of memory mapping; Access the data in the memory space based on the pointer of the blockchain data in the address space of the data subscription processing module.
8. The data subscription processing method based on blockchain according to claim 7 is characterized in that: Accessing the data in the memory space based on the pointer of the blockchain data in the address space of the data subscription processing module includes: In the address space of the data subscription processing module, based on the pointer of the blockchain data, find the target data in the memory space; The target data is encrypted so as to transmit the encrypted target data to the data subscriber.
9. The data subscription processing method based on blockchain according to claim 8 is characterized in that: The data subscription processing method further includes: Communicate and negotiate with the data subscriber to agree with the data subscriber on a decryption key for the target data.
10. The data subscription processing method based on blockchain according to claim 1 is characterized in that: A smart contract is deployed in the blockchain node; Among them, the smart contract is used to respond to the blockchain data subscription request to execute query processing of the target data, read the target data into the memory space, create a file descriptor corresponding to the target data in the memory space, and send the file descriptor to the operating system of the blockchain node.
11. The data subscription processing method based on blockchain according to any one of claims 1 to 10, characterized in that: The file descriptor corresponding to the target data includes address information of the target data in the memory space and length information of the target data; The address information and the length information are used to enable the operating system to locate the target data in the memory space, so as to transmit the target data in the memory space to the data subscriber.
12. A data subscription processing device based on blockchain, characterized in that: include: A query unit, configured to query the target data corresponding to the blockchain data subscription request in the local storage space of the blockchain node in response to the blockchain data subscription request sent by the data subscriber; A processing unit, configured to read the queried target data into the memory space of the blockchain node, and create a file descriptor corresponding to the target data in the memory space; The sending unit is configured to send the file descriptor to the operating system of the blockchain node, so that the operating system transmits the target data in the memory space to the data subscriber based on the file descriptor.
13. A computer readable medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the blockchain-based data subscription processing method as described in any one of claims 1 to 11 is implemented.
14. An electronic device, characterized in that: include: one or more processors; A memory for storing one or more computer programs, which, when executed by the one or more processors, enables the electronic device to implement the blockchain-based data subscription processing method as described in any one of claims 1 to 11.
15. A computer program product, characterized in that The computer program product includes a computer program, which is stored in a computer-readable storage medium. The processor of the electronic device reads and executes the computer program from the computer-readable storage medium, so that the electronic device performs the blockchain-based data subscription processing method as described in any one of claims 1 to 11.
Citation Information
Cited By
Media data transmission method, media chip and storage medium
CN122476131A