Consensus data persistent storage method and block chain node
By using memory mapping technology in the blockchain system, the consensus data is persistently stored in the blockchain system, which solves the problem of low storage efficiency of consensus data and achieves efficient reading, writing and execution efficiency.
Patent Information
- Application Number
- CN202411048223.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-31
- Publication Date
- 2024-10-11
- Estimated Expiration
- 2044-07-31
AI Technical Summary
In the blockchain system, the existing technology for persistent storage of consensus data suffers from the problems of high I/O access frequency and low efficiency. Especially during garbage collection and state recovery, frequent interaction with the disk is required, resulting in large time overhead.
Using memory mapping, a one-to-one mapping relationship is established between the virtual memory address in the process address space of the consensus process and the physical storage address in the physical storage space, and read and write operations are performed directly in the memory to reduce the I of the physical storage space. /O access.
It reduces the I/O access frequency of the consensus process to the physical storage space, improves the reading and writing efficiency of consensus data, and improves the execution efficiency of the consensus protocol. In particular, the processing speed is significantly improved during garbage collection and state recovery.
Smart Images

Figure CN118760685A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of this specification belong to the field of blockchain technology, and in particular, relate to a persistent storage method for consensus data and a blockchain node. Background Art
[0002] In the blockchain system, different participants can establish a distributed blockchain network through deployed nodes. The decentralized (or multi-centralized) distributed ledger constructed using the chain block structure is stored on each node (or most nodes, such as consensus nodes) in the distributed blockchain network. Such a blockchain system needs to solve the problem of consistency and correctness of the distributed ledger maintained locally by each decentralized (or multi-centralized) node.
[0003] In practical applications, each node in a distributed blockchain network can run a consensus protocol to ensure that the consensus mechanism on each node's distributed ledger ensures the consistency and correctness of the locally maintained distributed ledger.
[0004] The current mainstream consensus protocols include: Proof of Work (POW), Proof of Stake (POS), Delegated Proof of Stake (DPOS), Practical Byzantine Fault Tolerance (PBFT) algorithm, HoneyBadgerBFT algorithm, and so on. Summary of the invention
[0005] This specification proposes a method for persistent storage of consensus data, which is applied to any consensus node participating in consensus in a blockchain system, wherein the process address space of the consensus process running on the consensus node includes a reserved mapping area; a one-to-one mapping relationship is established between the virtual memory address in the mapping area and the physical storage address in the non-volatile physical storage space carried by the consensus node for persistent storage of consensus data;
[0006] The method comprises:
[0007] Obtaining consensus data generated by the consensus process in the process of running the consensus protocol;
[0008] Writing the consensus data into the mapping area for persistent storage;
[0009] In response to the consensus data being successfully written to the mapping area, a physical storage address that has established a mapping relationship with the virtual memory address of the consensus data in the mapping area is determined, and based on the physical storage address, the consensus data is further written back to the physical storage space.
[0010] Optionally, the physical storage space is a disk storage space corresponding to a disk carried by the node device.
[0011] Optionally, the consensus data is persistently stored in the form of a file; the mapping area is a file mapping area reserved in the process address space.
[0012] Optionally, the mapping area is an area reserved in a shared area in the process address space.
[0013] Optionally, the consensus data includes metadata related to the consensus; and consensus message data for consensus interaction with other consensus nodes; accordingly, the mapping area includes a first mapping area for storing the metadata and a second mapping area for storing the consensus message data.
[0014] Optionally, the consensus data is stored in the mapping area in the form of a key-value pair; wherein the key in the key-value pair corresponding to the metadata is a fixed value; and at least the key in the key-value pair corresponding to the metadata is pre-stored in the first mapping area;
[0015] Writing the consensus data into the mapping area for persistent storage includes:
[0016] If the consensus data contains a key-value pair corresponding to the metadata, starting from the starting address of the first mapping area, traverse the first mapping area, and query the key in the key-value pair corresponding to the metadata pre-stored in the first mapping area; if the key in the key-value pair corresponding to the metadata is queried in the first mapping area, based on the value in the key-value pair corresponding to the metadata, further modify the value corresponding to the queried key, so as to write the key-value pair corresponding to the metadata into the first mapping area for persistent storage;
[0017] If the consensus data contains a key-value pair corresponding to the consensus message data, starting from the starting address of the second mapping area, traverse the second mapping area, determine the tail address of the data stored in the second mapping area, and use the storage position indicated by the tail address as the write starting position, and write the key-value pair corresponding to the consensus message data into the second mapping area for persistent storage.
[0018] Optionally, the method further includes:
[0019] In response to a read instruction for target consensus data, determining a data type of the target consensus data;
[0020] If the target consensus data is the metadata, reading the target consensus data from the first mapping area;
[0021] If the target consensus data is the consensus message data, the target consensus data is read from the second mapping area.
[0022] Optionally, the read instruction includes the key of the target consensus data;
[0023] Determine the data type of the target consensus data, including:
[0024] Determine whether the key of the target consensus data is a fixed value;
[0025] If the key of the target consensus data is a fixed value, determining that the target consensus data is the metadata;
[0026] If the key of the target consensus data is not a fixed value, the target consensus data is determined to be the consensus message data.
[0027] Optionally, the read instruction includes a virtual memory address of the target consensus data in the mapping area;
[0028] Determine the data type of the target consensus data, including:
[0029] Matching the virtual memory address with a first virtual memory address range corresponding to the first mapping area and a second virtual memory address range corresponding to the second mapping area respectively;
[0030] If the virtual memory address hits the first virtual memory address range, determining that the target consensus data is the metadata;
[0031] If the virtual memory address hits the second virtual memory address range, the target consensus data is determined to be the consensus message data.
[0032] Optionally, reading the target consensus data from the first mapping area or the second mapping area includes: searching for the target consensus data in the first mapping area or the second mapping area based on a key of the target consensus data.
[0033] Optionally, the method further includes:
[0034] In response to a garbage collection instruction for the consensus message data, traverse the second mapping area to determine target consensus message data stored in the second mapping area that needs to be garbage collected;
[0035] In response to determining that the target consensus message data needs to be garbage collected, the virtual memory space occupied by the target consensus message data in the second mapping area is released.
[0036] Optionally, the garbage collection instruction includes a specified value range corresponding to the key of the target consensus message data that needs to be garbage collected;
[0037] Traversing the second mapping area to determine the target consensus message data stored in the second mapping area that needs to be garbage collected, including: traversing the second mapping area to search for consensus message data whose key value stored in the second mapping area is within the value range, and determining the found consensus message data as the target consensus message data that needs to be garbage collected.
[0038] Optionally, the method further includes:
[0039] In response to determining that the target consensus message data needs to be garbage collected, it is further determined whether the target consensus message data has been written back to the physical storage space; if so, the target consensus message data stored in the physical storage space is synchronously deleted.
[0040] Optionally, the method further includes:
[0041] In response to an instruction to perform state recovery on the consensus protocol running the consensus process, the consensus data persistently stored in the mapping area is read, and state recovery processing is performed on the consensus protocol based on the read consensus data.
[0042] This specification also proposes a persistent storage device for consensus data, which is applied to any consensus node participating in consensus in a blockchain system, wherein the process address space of the consensus process running on the consensus node includes a reserved mapping area; a virtual memory address in the mapping area establishes a one-to-one mapping relationship with a physical storage address in a non-volatile physical storage space carried by the consensus node for persistent storage of consensus data; the device includes:
[0043] An acquisition module is used to acquire consensus data generated by the consensus process in the process of running the consensus protocol;
[0044] A storage module writes the consensus data into the mapping area for persistent storage;
[0045] A write-back module, in response to the consensus data being successfully written into the mapping area, determines a physical storage address that has established a mapping relationship with the virtual memory address of the consensus data in the mapping area, and based on the physical storage address, further writes the consensus data back to the physical storage space.
[0046] In the above embodiment, by adopting the memory mapping method, a one-to-one mapping relationship is established between the virtual memory address in the mapping area reserved in the process address space of the consensus process and the physical storage address in the non-volatile physical storage space used for persistent storage of consensus data. The consensus data generated by the consensus process in the process of running the consensus protocol can be stored in the memory space allocated for the consensus process, so that when the consensus process needs to access the persistently stored consensus data, it can directly read the consensus data from the memory space of the consensus process, and no longer needs to access the physical storage space through the system I / O method, thereby reducing the I / O access frequency of the consensus process to the physical storage space, improving the reading and writing efficiency of the consensus data, and helping to improve the execution efficiency of the consensus process when executing the consensus protocol. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] In order to more clearly illustrate the technical solutions of the embodiments of this specification, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0048] Figure 1 It is a schematic diagram showing a method of using a traditional database to persistently store consensus data in an embodiment of this specification;
[0049] Figure 2 It is a flowchart of a method for persistent storage of consensus data shown in an embodiment of this specification;
[0050] Figure 3 is a schematic diagram of reserving a mapping area in a process address space in an embodiment of this specification;
[0051] Figure 4 It is a schematic diagram of dividing the reserved mapping area in the process address space according to an embodiment of this specification;
[0052] Figure 5 is a schematic structural diagram of an electronic device shown in an embodiment of this specification;
[0053] Figure 6 It is a block diagram of a persistent storage device for consensus data shown in one embodiment of this specification. DETAILED DESCRIPTION
[0054] In order to enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below in conjunction with the drawings in the embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this specification, not all of the embodiments. Based on the embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this specification.
[0055] In related technologies, in order to ensure that the consensus protocol running in the blockchain system has a certain degree of recovery capability, it is usually necessary to persistently store the consensus data generated by the consensus nodes participating in the consensus in the blockchain system during the operation of the consensus protocol. Later, when the consensus protocol needs to be restored, the full amount of consensus data that has been persistently stored can be read, and then the consensus protocol can be restored based on the consensus data read. In addition, in order to avoid unlimited growth in the amount of data, for the consensus data that has been persistently stored, it is also necessary to periodically garbage collect these data and delete the consensus data stored earlier.
[0056] Currently, the solution used for persistent storage of consensus data is usually to use physical storage space such as disks to implement a centralized database (such as a key-value database), and use this database to persistently store consensus data.
[0057] See also Figure 1 , Figure 1 This is a schematic diagram of using a traditional database to persistently store consensus data as shown in this specification.
[0058] like Figure 1As shown in the figure, using a traditional database to persistently store consensus data, the consensus module on the consensus node and the database usually generate the following four interactions:
[0059] 1: Write data
[0060] When a consensus node needs to write consensus data generated by running a consensus protocol into a database, it can usually interact with the disk based on the write instruction of the system I / O to write the consensus data into a database created on the disk.
[0061] 2: Read data
[0062] When a consensus node needs to read consensus data persistently stored in the database, it can also interact with the disk based on the system I / O read instruction to read the consensus data that has been written to the database created on the disk.
[0063] 3: Garbage Collection
[0064] When it is necessary to perform garbage collection on the consensus data persistently stored in the database, it is also possible to interact with the disk and modify the consensus data stored in the database to delete the consensus data stored earlier.
[0065] 4: State recovery
[0066] When a consensus node needs to restore the state of a running consensus protocol, it can interact with the disk based on the system I / O read instruction to read the full amount of consensus data, and then restore the state of the consensus protocol based on the full amount of consensus data read.
[0067] It can be seen that in the solution of using traditional databases to persistently store consensus data, no matter which of the four cases shown above, it is necessary to interact with the disk. When the amount of data to be accessed is large, it is bound to generate a large amount of interaction with the disk, resulting in a large time overhead for accessing the consensus data.
[0068] For example, especially the garbage collection and state recovery mentioned above, since garbage collection may require the deletion of a large amount of consensus data stored earlier in the database, and state recovery often requires reading the full amount of consensus data, both garbage collection and state recovery usually require access to a large amount of consensus data persistently stored in the database, which will generate a large amount of and frequent interactions with the disk.
[0069] Based on this, this specification proposes a technical solution for persistently storing consensus data using memory mapping.
[0070] See also Figure 2 , Figure 2The flowchart of a method for persistent storage of consensus data shown in this specification, wherein the scheme can be applied to any consensus node participating in consensus in a blockchain system, wherein the process address space of the consensus process running on the consensus node includes a reserved mapping area; the virtual memory address in the mapping area establishes a one-to-one mapping relationship with the physical storage address in the physical storage space carried by the consensus node for persistent storage of consensus data; the method includes the following execution process:
[0071] Step 202: Acquire consensus data generated by the consensus process in the process of running the consensus protocol;
[0072] In this specification, a consensus process may be run on a consensus node participating in the consensus, and the consensus process may be specifically used to run the consensus protocol adopted by the blockchain system.
[0073] It should be noted that the consensus process can be a system process corresponding to the blockchain system program running on the consensus node, or it can be a process corresponding to an independent consensus module in the blockchain system, which is not specifically limited in this specification.
[0074] The operating system of the consensus node can allocate an independent process address space (processaddress space) for the consensus process. The process address space is specifically used to describe the memory space occupied by the process in the operating system. The process address space can usually contain a set of virtual memory addresses used by the process when it is running. In practical applications, after the operating system allocates an independent process address space for the consensus process, it can also use the page table to establish a mapping relationship between the virtual memory address contained in the process address space and the real physical memory address, so that the consensus process can access the real physical space in the memory based on the virtual memory address.
[0075] The consensus nodes participating in the consensus may also be equipped with a physical storage space for persistent storage of consensus data. The physical storage space may specifically be a non-volatile physical storage space, that is, the data persistently stored in the physical storage space can still maintain the ability to maintain the stored data without loss in the event of a power outage or power failure of the device. For example, in one example, the physical storage space may specifically be the disk storage space corresponding to the disk carried by the consensus node. Of course, the physical storage space may obviously also be other forms of non-volatile physical storage media besides the disk.
[0076] It should be noted that the physical storage space carried by the consensus node can be a physical storage space carried locally by the consensus node, or it can be an external physical storage space carried by the consensus node.
[0077] For example, taking the physical storage space as the disk storage space corresponding to the disk carried by the consensus node as an example, the physical storage space can be the physical storage space corresponding to a local disk of the consensus node, or it can be the physical storage space corresponding to a disk peripheral connected to the consensus node (for example, it can be a disk on an external server connected to the consensus node).
[0078] In this specification, a mapping area for persistent storage of consensus data can also be reserved in the process address space allocated for the consensus process. For example, in one example, the consensus data can be persistently stored in the form of a file, and the above-mentioned mapping area can be a file mapping area reserved in the process address space. Of course, in actual applications, consensus data can also be stored in other forms besides files, which is not particularly limited in this specification.
[0079] It should be noted that the specific location of the reserved mapping area in the process address space is not specifically limited in the specification.
[0080] For example, see Figure 3 In one embodiment shown, there is usually a shared area in the structure of the process address space, and the shared area usually refers to a memory area that can be shared between processes, and the reserved mapping area can be a reserved area in the shared area in the structure of the process address space. Of course, in actual applications, in addition to reserving the mapping area in the shared area, the mapping area can also be reserved by using unused areas in other areas of the structure of the process address space.
[0081] In order to utilize the reserved mapping area in the process address space of the consensus process to persistently store consensus data, a one-to-one mapping relationship can be established between the virtual memory address in the mapping area and the physical storage address in the above-mentioned physical storage space carried by the consensus node.
[0082] In this way, the consensus data stored in the physical storage space can be mapped to the reserved mapping area in the process address space of the consensus process, so that the consensus process can subsequently access the consensus data persistently stored in the physical storage space based on memory read / write instructions just like accessing data stored in the memory, without the need for I / O interaction with the physical storage space.
[0083] In this specification, the consensus process on the consensus node usually generates some consensus data during the execution of the consensus protocol, and the consensus node can obtain this consensus data and then store it persistently, so that the consensus node can subsequently restore the state of the consensus protocol based on the full amount of consensus data stored persistently.
[0084] Among them, the consensus data generated by the consensus process in the process of running the consensus protocol usually includes the full amount of data generated in the process of running the consensus protocol.
[0085] In one embodiment shown, the consensus data may generally include metadata related to consensus; and consensus message data for consensus interaction with other consensus nodes;
[0086] Among them, consensus-related metadata can generally refer to data used to describe the consensus protocol adopted by the blockchain system, as well as data used to describe the consensus process initiated based on the consensus protocol.
[0087] For example, in actual applications, consensus-related metadata may include data such as the algorithm type of the consensus protocol adopted by the blockchain system, the block height that the consensus protocol is currently consensus on, and the timestamp of the block that the consensus protocol is currently consensus on.
[0088] The consensus message data for consensus interaction with other consensus nodes usually refers to the consensus protocol adopted by the blockchain system and the consensus messages supported for interaction between consensus nodes. When the blockchain system runs different types of consensus protocols, there are usually certain differences in the types of consensus messages sent between consensus nodes during consensus interaction.
[0089] For example, taking the pbft consensus algorithm as an example, the pbft consensus algorithm supports consensus messages that interact between consensus nodes, typically including PRE-PREPARE (pre-prepare message), PREPARE (prepare message), COMMIT (commit message), VIEW-CHANGE (view switch message) and NEW-VIEW (new view message), etc.
[0090] Correspondingly, the mapping area reserved in the process address space of the consensus process may specifically include a first mapping area for storing the above metadata and a second mapping area for storing the above consensus message data.
[0091] For example, see Figure 4 , the reserved mapping area in the process address space can be divided into a metadata area (i.e., the first mapping area mentioned above) and a message data area (i.e., the second mapping area mentioned above). Figure 4 As shown, Figure 4The meta_data shown in the figure refers to the starting pointer of the metadata area, message_data refers to the starting pointer of the message data area, data_head refers to the head pointer of the consensus message data stored in the message data area, and data_tail refers to the tail pointer of the consensus message data stored in the message data area.
[0092] It should be noted that, in actual applications, no matter which consensus protocol the blockchain system adopts, the type and quantity of consensus-related metadata usually do not change. Based on this data characteristic, a fixed-size area can be allocated in the mapping area as the above-mentioned metadata area.
[0093] For example, the type and quantity of consensus-related metadata will not change, which means that even for different consensus protocols, the size of consensus-related metadata is usually relatively constant. Therefore, in practical applications, the size of the memory space corresponding to the metadata area can be planned based on the size of the metadata actually to be stored by the consensus protocol.
[0094] Different from the above-mentioned metadata, different consensus protocols usually have significant differences in the types and quantities of consensus messages for interaction between consensus nodes. Based on this data characteristic, a corresponding space that is larger than the above-mentioned metadata area and has a non-fixed size can be allocated in the mapping area as the above-mentioned message data area.
[0095] For example, in actual applications, for consensus protocols that support a large number of consensus messages for interaction between consensus nodes, a larger memory space can be allocated in the mapping area as the above-mentioned message data area. For consensus protocols that support a small number of consensus messages for interaction between consensus nodes, a smaller memory space can be allocated in the mapping area as the above-mentioned message data area.
[0096] In this way, not only can the memory space of the mapping area be fully utilized, but the mapping area can also be flexibly adapted to different consensus protocols and store consensus message data supported by different consensus protocols.
[0097] It should be noted that, in practical applications, consensus-related metadata can usually be included in the form of fields in the consensus message data generated by the consensus process in the process of running the consensus protocol.
[0098] For example, take the following consensus message data structure as an example:
[0099] Algorithm_type|seq|view|msg_type|senderID
[0100] The consensus message includes fields such as Algorithm_type, seq, view, msg_type, and senderID. Algorithm_type indicates the type of consensus algorithm corresponding to the consensus message, seq indicates the sequence number of the consensus message, view indicates the view of the consensus algorithm, which is a unique concept in the consensus algorithm and represents the stage or round of a consensus process. msg_type indicates the message type of the consensus message, and senderID indicates the sender ID of the consensus message. Among the above fields, the value of the Algorithm_type field is the type of consensus algorithm adopted by the blockchain system, and the value of this field can be used as metadata related to consensus.
[0101] Step 204: writing the consensus data into the mapping area for persistent storage;
[0102] In this specification, after obtaining the consensus data generated by the consensus process in the process of running the consensus protocol, the consensus node can try to use the write instruction of the memory to write these consensus data into the reserved mapping area in the process address space of the consensus process for persistent storage, without the need to use direct I / O interaction with the physical storage space to write these consensus data into the physical storage space for persistent storage.
[0103] Among them, when writing the consensus data to the above-mentioned mapping area for persistent storage, the consensus node can specifically start from the starting pointer in the above-mentioned mapping area, traverse the mapping area, and find the tail pointer of the consensus data already stored in the mapping area; then, the storage position indicated by the tail address can be used as the writing starting position, and the consensus message data to be written can be overwritten downward in sequence to write the consensus message data to the mapping area. Of course, if it is the first time to write data to the mapping area, the storage position indicated by the starting pointer of the mapping area can be used as the writing starting position, and then the consensus message data to be written can be overwritten downward in sequence to write the consensus message data to the mapping area.
[0104] For example, see Figure 4 , taking the example that the above consensus data includes metadata related to consensus and consensus message data for consensus interaction with other consensus nodes, in this case, the above mapping area may include a metadata area and a message data area.
[0105] When the consensus node writes the consensus data into the above mapping area for persistent storage, if the consensus data contains the above metadata, Figure 4The starting pointer meta_data of the metadata area shown in is used as the writing starting position, and the metadata to be written is overwritten downward in sequence to write the metadata into the metadata area. If the consensus data contains the above consensus message data, then Figure 4 The starting pointer message_data of the message data area shown in is used as the writing starting position, and the consensus message data to be written is overwritten downward in sequence to write the consensus message data into the message data area.
[0106] In one embodiment shown, in order to facilitate retrieval of the consensus data written into the above-mentioned mapping area, the consensus data may be stored in the mapping area in the form of key-value pairs.
[0107] Among them, no matter which consensus protocol the blockchain system adopts, the type and quantity of consensus-related metadata usually do not change, so the key in the key-value pair corresponding to the above metadata is usually a fixed value. In this case, the key-value pair corresponding to the above metadata or only the key in the key-value pair can be stored in the metadata area in the above mapping area in advance.
[0108] Furthermore, when the consensus node writes consensus data to the mapping area, on the one hand, if the consensus data contains a key-value pair corresponding to the above-mentioned metadata, it can start from the starting address of the metadata area of the mapping area (that is, the above-mentioned starting pointer meta_data), traverse the metadata area, and query the key in the key-value pair corresponding to the metadata pre-stored in the metadata area; if the key in the key-value pair corresponding to the metadata is queried in the metadata area, the value corresponding to the queried key can be further modified based on the value in the key-value pair corresponding to the metadata, so as to write the key-value pair corresponding to the metadata into the metadata area for persistent storage.
[0109] On the other hand, if the consensus data contains a key-value pair corresponding to the above-mentioned consensus message data, it is possible to start from the starting address of the message data area of the mapping area (i.e., the above-mentioned starting pointer message_data), traverse the message data area, determine the tail address of the data stored in the message data area, and use the storage position indicated by the tail address as the write start position, and write the key-value pair corresponding to the consensus message data into the message data area for persistent storage.
[0110] It should be noted that when the consensus node attempts to use the memory write instruction to write the consensus data into the reserved mapping area in the process address space of the consensus process for persistent storage, the write command usually carries a virtual memory address as the write start position. When the consensus node's operating system receives the write command, it can automatically map the virtual memory address as the write start position into a real physical memory address through the mapping relationship between the virtual memory address contained in the above process address space established in the page table and the real physical memory address, and then write the consensus data to be written into the physical memory based on the physical memory address.
[0111] Step 206: In response to the consensus data being successfully written to the mapping area, determine a physical storage address that has established a mapping relationship with the virtual memory address of the consensus data in the mapping area, and based on the physical storage address, further write the consensus data back to the physical storage space.
[0112] In this specification, after the consensus node successfully writes the consensus data into the above-mentioned mapping area, the operating system of the consensus node can automatically write the consensus data persistently stored in the memory back to the above-mentioned physical storage space in the background. Specifically, after the consensus node successfully writes the consensus data into the above-mentioned mapping area, the operating system of the consensus node can respond to the event that the consensus data is successfully written into the mapping area, based on the mapping relationship between the virtual memory address in the mapping area that has been established and the physical storage address in the non-volatile physical storage space carried by the consensus node for persistent storage of consensus data, to determine the physical storage address that has established a mapping relationship with the virtual memory address of the consensus data in the mapping area, and then based on the physical storage address, the consensus data can be further written back to the physical storage space.
[0113] It should be noted that, in actual applications, the specific timing of the operation of the consensus node's operating system writing the consensus data persistently stored in the memory back to the above-mentioned physical storage space in the background can be flexibly formulated based on actual needs;
[0114] For example, in one method, the operating system of the consensus node can write the consensus data back to the above-mentioned physical storage space in real time when it detects that the consensus data has been successfully written in the mapping area; in another method, the operating system of the consensus node can also periodically write the consensus data persistently stored in the memory back to the above-mentioned physical storage space; in the third method, the operating system of the consensus node can also trigger the writing back of the consensus data persistently stored in the memory to the above-mentioned physical storage space when the storage pressure in the memory is large, such as insufficient remaining storage space in the memory, or the used storage space in the memory reaches a threshold.
[0115] After the operating system of the consensus node writes the consensus data persistently stored in the memory back to the above-mentioned physical storage space in the background, the consensus data persistently stored in the above-mentioned physical storage space will be directly mapped to the process address space allocated for the consensus process. Subsequently, the consensus process can access the consensus data persistently stored in the physical storage space based on memory read / write instructions just like accessing data stored in the memory, without the need for I / O interaction with the physical storage space.
[0116] In one embodiment shown, when the consensus process needs to read the target consensus data that has been persistently stored, it can specifically generate a memory read instruction for the target consensus data and send the memory read instruction to the operating system of the consensus node. After receiving the memory read instruction, the operating system can respond to the memory read instruction and determine the data type of the target consensus data that needs to be read; if the target consensus data is the metadata, the target consensus data can be read from the metadata area in the mapping area; if the target consensus data is the consensus message data, the target consensus data can be read from the message data area in the mapping area.
[0117] It should be noted that when the operating system determines the data type of the target consensus data to be read, it can be determined based on the key of the target consensus data, or based on the virtual memory address of the target consensus data in the mapping area.
[0118] For example, in one embodiment shown, the above-mentioned memory read instruction may specifically include the key of the target consensus data; when determining the data type of the target consensus data, the operating system may determine whether the key of the target consensus data is a fixed value; if the key of the target consensus data is a fixed value, it may be determined that the target consensus data is the above-mentioned metadata; if the key of the target consensus data is not a fixed value, it may be determined that the target consensus data is the above-mentioned consensus message data.
[0119] In another embodiment shown, in the above-mentioned memory read instruction, the virtual memory address of the target consensus data in the above-mentioned mapping area may also be specifically included; when the operating system determines the data type of the target consensus data, the virtual memory address contained in the memory read instruction may be specifically matched with the first virtual memory address range corresponding to the above-mentioned metadata area and the second virtual memory address range corresponding to the above-mentioned message data area. If the virtual memory address contained in the memory read instruction hits the first virtual memory address range corresponding to the above-mentioned metadata area, it can be determined that the target consensus data is the above-mentioned metadata; if the virtual memory address hits the second virtual memory address range corresponding to the above-mentioned message data area, it can be determined that the target consensus data is the above-mentioned consensus message data.
[0120] In one embodiment shown, since consensus data can be stored in the mapping area in the form of key-value, when reading the target consensus data from the metadata area or the message data area, the target consensus data can be searched in the metadata area or the message data area based on the key of the target consensus data.
[0121] In this specification, in order to avoid unlimited growth of the amount of consensus data stored in the memory, garbage collection can also be performed on the consensus data that has been persistently stored to delete the consensus data stored earlier.
[0122] It should be noted that since the types and quantities of metadata related to consensus do not change, and will not cause data accumulation in the mapping area as the block height continues to increase, the above metadata may not participate in garbage collection. On the contrary, since the above consensus message data usually causes data accumulation in the mapping area as the block height continues to increase, when garbage collection is performed on the consensus data that has been persistently stored, garbage collection can be performed only on the above consensus message data.
[0123] For example, in one embodiment shown, a recycling process for performing garbage collection on persistently stored consensus message data may also be run on the consensus node. The recycling process may periodically scan the consensus message data stored in the mapping area to determine whether the consensus message data stored in the mapping area meets the garbage collection conditions.
[0124] When it is determined that the consensus message data stored in the mapping area meets the garbage collection conditions, the recovery process can generate a garbage collection instruction for the consensus message data and send the garbage collection instruction to the operating system of the consensus node.
[0125] It should be noted that, in actual applications, the above-mentioned garbage collection conditions can be flexibly set based on specific needs and are not particularly limited in this specification; for example, in one example, the above-mentioned garbage collection conditions can specifically be whether the capacity of the consensus message data stored in the message data area of the above-mentioned mapping area reaches a threshold, or whether the remaining capacity of the above-mentioned message data area reaches a threshold.
[0126] After receiving the garbage collection instruction, the operating system of the consensus node can respond to the garbage collection instruction, traverse the message data area in the above-mentioned mapping area, and determine the target consensus message data that needs to be garbage collected from the consensus message data stored in the message data area.
[0127] Among them, the specific method of determining the target consensus message data that needs to be garbage collected from the message data area usually depends on the specific garbage collection strategy and is not particularly limited in this specification.
[0128] In one embodiment shown, a strategy for garbage collection of consensus message data based on the key of the consensus message data may be specifically adopted. In this case, the above-mentioned garbage collection instruction may include a specified value range corresponding to the key of the target consensus message data that needs to be garbage collected. When determining the target consensus message data that needs to be garbage collected from the message data area, the above-mentioned message data area may be traversed to find the consensus message data whose key value stored in the message data area is within the value range, and then the found consensus message data is determined as the target consensus message data that needs to be garbage collected. For example, in one example, a key value may be specified as a critical value for garbage collection, and consensus message data with a key value greater than or less than the critical value may be specified as the target consensus data that needs to be garbage collected.
[0129] After the target consensus message data that needs to be garbage collected is determined, the virtual memory space occupied by the target consensus message data in the message data area can be directly released in response to the determined target consensus message data to achieve the purpose of clearing the target consensus message data.
[0130] For example, see Figure 4 In practical applications, Figure 4 The blank area between the starting pointer message_data of the message data area and the head pointer data_head of the consensus message data stored in the message data area shown in is the blank area left after the virtual memory space occupied by the consensus message data that needs to be garbage collected in the message data area is released.
[0131] In this way, the target consensus message data that needs to be recycled can be quickly cleared in the memory by releasing the memory, which can significantly improve the efficiency of garbage collection of the consensus message data.
[0132] For example, if a traditional database in a non-volatile physical storage medium is used to store consensus message data, if a large amount of early stored consensus data needs to be garbage collected, it is necessary to access the database to delete the consensus data that needs to be garbage collected one by one, and a large amount of I / O interaction is bound to occur during this process. However, garbage collection of consensus message data can be completed directly through memory release, which obviously does not require direct I / O interaction with the database, so the efficiency of garbage collection of consensus message data can be significantly improved.
[0133] In one embodiment shown, after the target consensus message data that needs to be garbage collected is determined, it is also possible to further determine whether the target consensus message data has been written back to the above-mentioned physical storage space in response to the determined target consensus message data; if the target consensus message data has been written back to the above-mentioned physical storage space, then in the garbage collection stage, in addition to releasing the virtual memory space occupied by the target consensus message data in the message data area, the target consensus message data stored in the physical storage space may also be synchronously deleted.
[0134] In one embodiment shown, when the consensus process needs to restore the state of the running consensus protocol, the consensus process can generate an instruction for restoring the state of the consensus protocol and send the instruction to the operating system of the consensus node. After receiving the instruction for restoring the state, the operating system of the consensus node can respond to the instruction for restoring the state, directly read the full amount of consensus data that has been persistently stored from the above-mentioned mapping area, and then perform state recovery processing on the consensus protocol based on the read consensus data.
[0135] It should be noted that in actual applications, the state recovery of the consensus protocol usually includes the following specific scenarios:
[0136] In one scenario, the state recovery of the consensus protocol can be performed after the consensus process running the consensus protocol is restarted or the system process of the entire blockchain system is restarted. In this scenario, when the consensus process running the consensus protocol is restarted or the system process of the entire blockchain system is restarted, the full amount of consensus data that has been persistently stored can be read from the above-mentioned mapping area to perform state recovery processing on the consensus protocol.
[0137] In another scenario, the state recovery of the consensus protocol can also be the state recovery of the consensus protocol when an exception occurs in the consensus protocol and a state rollback is required; for example, a fork occurs in a certain block of the blockchain system, and the blockchain system needs to roll back the consensus protocol running on the consensus node to the state of the previous block of the block. In this scenario, when an exception occurs in the consensus protocol and a state rollback is required, the full amount of consensus data that has been persistently stored can be read from the above-mentioned mapping area, and the state recovery process of the consensus protocol can be performed to restore the state of the consensus protocol to the state before the exception occurred in the consensus protocol.
[0138] In another scenario, the state recovery of the consensus protocol can also be the state recovery of the consensus protocol after an abnormal device restart (such as power failure restart) occurs in the node device corresponding to the consensus node. In this scenario, since the data stored in the memory will be lost after the node device restarts, it is necessary to re-establish the one-to-one mapping relationship between the virtual memory address in the above-mentioned mapping area and the physical storage address in the above-mentioned non-volatile physical storage space after the node device completes the restart, and synchronize the full amount of consensus data stored in the above-mentioned physical storage space to the above-mentioned mapping area for storage, and then read the full amount of consensus data from the above-mentioned mapping area to perform state recovery processing on the consensus protocol.
[0139] In the above technical solution, by adopting the memory mapping method, a one-to-one mapping relationship is established between the virtual memory address in the mapping area reserved in the process address space of the consensus process and the physical storage address in the non-volatile physical storage space used for persistent storage of consensus data. The consensus data generated by the consensus process in the process of running the consensus protocol can be stored in the memory space allocated for the consensus process, so that when the consensus process needs to access the persistently stored consensus data, it can directly read the consensus data from the memory space of the consensus process, and no longer needs to access the physical storage space through the system I / O method, thereby reducing the I / O access frequency of the consensus process to the physical storage space, improving the reading and writing efficiency of the consensus data, and helping to improve the execution efficiency of the consensus process when executing the consensus protocol.
[0140] For example, for the garbage collection and state recovery mentioned above, since garbage collection may need to delete a large amount of consensus data stored earlier, and state recovery often requires reading the full amount of consensus data, both garbage collection and state recovery usually require access to a large amount of consensus data that has been persistently stored; at this time, if the data is read directly from the database on the disk, a large amount of frequent interactions with the disk will be generated. On the contrary, if the memory-mapped persistent storage solution proposed in this specification is adopted, these consensus data can be quickly accessed directly from the memory, thereby significantly improving the efficiency of reading and writing consensus data.
[0141] In addition, the consensus process may also need to access persistently stored consensus data during the execution of the consensus protocol. For example, when an exception occurs in the operation of the consensus protocol, the consensus process needs to access the full amount of consensus data in the memory to restore the state of the consensus protocol. In this scenario, if the consensus process can quickly obtain the persistently stored consensus data by accessing the memory, then for the consensus process, it is obvious that after an exception occurs in the operation of the consensus protocol, the state of the consensus protocol can be quickly restored, and the consensus protocol can continue to run after the state is restored to complete the subsequent consensus processing flow, thereby significantly improving the execution efficiency when executing the consensus protocol.
[0142] Corresponding to the embodiments of the aforementioned method, this specification also provides embodiments of an apparatus, an electronic device, and a storage medium.
[0143] Figure 5 is a schematic structural diagram of an electronic device provided by an exemplary embodiment. Figure 5 At the hardware level, the device includes a processor 502, an internal bus 504, a network interface 506, a memory 508, and a non-volatile memory 510, and may also include other required hardware. One or more embodiments of this specification may be implemented based on software, such as the processor 502 reading the corresponding computer program from the non-volatile memory 510 into the memory 508 and then running it. Of course, in addition to the software implementation, one or more embodiments of this specification do not exclude other implementations, such as logic devices or a combination of software and hardware, etc., that is, the execution subject of the following processing flow is not limited to each logic unit, but may also be hardware or logic devices.
[0144] like Figure 6 As shown, Figure 6 This is a block diagram of a persistent storage device for consensus data according to an exemplary embodiment of the present specification. The device can be applied to Figure 5In the electronic device shown, the technical solution of this specification is implemented. The device can be applied to any consensus node participating in the consensus in the blockchain system, wherein the process address space of the consensus process running on the consensus node includes a reserved mapping area; the virtual memory address in the mapping area establishes a one-to-one mapping relationship with the physical storage address in the non-volatile physical storage space carried by the consensus node for persistent storage of consensus data; the device 600 includes:
[0145] An acquisition module 601 is used to acquire consensus data generated by the consensus process in the process of running the consensus protocol;
[0146] Storage module 602, writing the consensus data into the mapping area for persistent storage;
[0147] The write-back module 603, in response to the consensus data being successfully written into the mapping area, determines a physical storage address that has established a mapping relationship with the virtual memory address of the consensus data in the mapping area, and based on the physical storage address, further writes the consensus data back to the physical storage space.
[0148] Accordingly, the present specification also provides an electronic device, which includes a processor; a memory for storing instructions executable by the processor; wherein the processor is configured to implement the steps in all the method flows described above.
[0149] Accordingly, the present specification also provides a computer-readable storage medium on which executable computer program instructions are stored; wherein, when the instructions are executed by a processor, the steps in all the method flows described above are implemented.
[0150] Accordingly, the present specification also provides a computer program product having executable computer program instructions stored thereon; wherein, when the computer program instructions are executed by a processor, the steps in all the method flows described above are implemented.
[0151] In the 1990s, improvements to a technology could be clearly distinguished as hardware improvements (for example, improvements to the circuit structure of diodes, transistors, switches, etc.) or software improvements (improvements to the method flow). However, with the development of technology, many improvements to the method flow today can be regarded as direct improvements to the hardware circuit structure. Designers almost always obtain the corresponding hardware circuit structure by programming the improved method flow into the hardware circuit. Therefore, it cannot be said that an improvement in a method flow cannot be implemented using a hardware entity module. For example, a programmable logic device (PLD) (such as a field programmable gate array (FPGA)) is such an integrated circuit whose logical function is determined by the user's programming of the device. Designers can "integrate" a digital system on a PLD by programming it themselves, without having to ask a chip manufacturer to design and produce a dedicated integrated circuit chip. Moreover, nowadays, instead of manually making integrated circuit chips, this kind of programming is mostly implemented by "logic compiler" software, which is similar to the software compiler used when developing and writing programs, and the original code before compilation must also be written in a specific programming language, which is called hardware description language (HDL). There is not only one HDL, but many kinds, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, RHDL (Ruby Hardware Description Language), etc. The most commonly used ones are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should also know that it is only necessary to program the method flow slightly in the above-mentioned hardware description languages and program it into the integrated circuit, and then it is easy to obtain the hardware circuit that implements the logic method flow.
[0152] The controller can be implemented in any appropriate manner, for example, the controller can take the form of a microprocessor or processor and a computer-readable medium storing a computer-readable program code (such as software or firmware) that can be executed by the (micro)processor, a logic gate, a switch, an application-specific integrated circuit (ASIC), a programmable logic controller, and an embedded microcontroller. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320. The memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art also know that in addition to implementing the controller in a purely computer-readable program code manner, the controller can be implemented in the form of a logic gate, a switch, an application-specific integrated circuit, a programmable logic controller, and an embedded microcontroller by logically programming the method steps. Therefore, this controller can be considered as a hardware component, and the devices included therein for implementing various functions can also be regarded as structures within the hardware component. Or even, the devices for implementing various functions can be regarded as both software modules for implementing the method and structures within the hardware component.
[0153] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a server system. Of course, the present application does not exclude that with the development of computer technology in the future, the computer that implements the functions of the above embodiments may be, for example, a personal computer, a laptop computer, a vehicle-mounted human-computer interaction device, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
[0154] Although one or more embodiments of the present specification provide method operation steps as described in the embodiments or flow charts, more or less operation steps may be included based on conventional or non-creative means. The order of steps listed in the embodiments is only one way of executing the order of many steps, and does not represent the only execution order. When the device or terminal product in practice is executed, it can be executed in sequence or in parallel according to the method shown in the embodiments or the drawings (for example, a parallel processor or a multi-threaded processing environment, or even a distributed data processing environment). The term "include", "include" or any other variant thereof is intended to cover non-exclusive inclusion, so that the process, method, product or equipment including a series of elements includes not only those elements, but also includes other elements that are not explicitly listed, or also includes elements inherent to such a process, method, product or equipment. In the absence of more restrictions, it is not excluded that there are other identical or equivalent elements in the process, method, product or equipment including the elements. For example, if the words first, second, etc. are used to represent the name, they do not represent any specific order.
[0155] For the convenience of description, the above devices are described in various modules according to their functions. Of course, when implementing one or more of the present specification, the functions of each module can be implemented in the same or more software and / or hardware, or the module implementing the same function can be implemented by a combination of multiple sub-modules or sub-units, etc. The device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0156] The present invention is described with reference to flowcharts and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0157] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0158] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0159] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0160] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0161] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage, graphene storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0162] It should be understood by those skilled in the art that one or more embodiments of the present specification may be provided as a method, system or computer program product. Therefore, one or more embodiments of the present specification may take the form of a complete hardware embodiment, a complete software embodiment or an embodiment combining software and hardware. Moreover, one or more embodiments of the present specification may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0163] One or more embodiments of this specification may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. One or more embodiments of this specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules may be located in local and remote computer storage media, including storage devices.
[0164] Each embodiment in this specification is described in a progressive manner, and the same and similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment. In the description of this specification, the description of the reference terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of this specification. In this specification, the schematic representation of the above terms does not necessarily target the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art can combine and combine the different embodiments or examples described in this specification and the features of different embodiments or examples without contradiction.
[0165] The above description is only an example of one or more embodiments of this specification and is not intended to limit one or more embodiments of this specification. For those skilled in the art, one or more embodiments of this specification may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of this specification shall be included in the scope of the claims.
Claims
1. A method for persistent storage of consensus data, applied to any consensus node participating in the consensus in the blockchain system, in, The process address space of the consensus process running on the consensus node includes a reserved mapping area; a one-to-one mapping relationship is established between the virtual memory address in the mapping area and the physical storage address in the non-volatile physical storage space carried by the consensus node for persistent storage of consensus data; The method comprises: Obtaining consensus data generated by the consensus process in the process of running the consensus protocol; Writing the consensus data into the mapping area for persistent storage; In response to the consensus data being successfully written to the mapping area, a physical storage address that has established a mapping relationship with the virtual memory address of the consensus data in the mapping area is determined, and based on the physical storage address, the consensus data is further written back to the physical storage space.
2. According to the method as claimed in claim 1, the physical storage space is the disk storage space corresponding to the disk carried by the node device.
3. According to the method as claimed in claim 1, the consensus data is persistently stored in the form of a file; the mapping area is a file mapping area reserved in the process address space. 4 . The method according to claim 1 , wherein the mapping area is an area reserved in a shared area in the process address space.
5. According to the method as claimed in claim 1, the consensus data includes metadata related to the consensus; and consensus message data for consensus interaction with other consensus nodes; accordingly, the mapping area includes a first mapping area for storing the metadata and a second mapping area for storing the consensus message data.
6. The method according to claim 5, wherein the consensus data is stored in the mapping area in the form of key-value pairs; in, The key in the key-value pair corresponding to the metadata is a fixed value; The first mapping area at least pre-stores a key in a key-value pair corresponding to the metadata; Writing the consensus data into the mapping area for persistent storage includes: If the consensus data includes a key-value pair corresponding to the metadata, starting from the starting address of the first mapping area, traverse the first mapping area, and query the key in the key-value pair corresponding to the metadata pre-stored in the first mapping area; If a key in the key-value pair corresponding to the metadata is queried in the first mapping area, based on the value in the key-value pair corresponding to the metadata, further modify the value corresponding to the queried key to write the key-value pair corresponding to the metadata into the first mapping area for persistent storage; If the consensus data contains a key-value pair corresponding to the consensus message data, starting from the starting address of the second mapping area, traverse the second mapping area, determine the tail address of the data stored in the second mapping area, and use the storage position indicated by the tail address as the write starting position, and write the key-value pair corresponding to the consensus message data into the second mapping area for persistent storage.
7. The method according to claim 6, further comprising: include: In response to a read instruction for target consensus data, determining a data type of the target consensus data; If the target consensus data is the metadata, reading the target consensus data from the first mapping area; If the target consensus data is the consensus message data, the target consensus data is read from the second mapping area.
8. The method of claim 7, wherein the read instruction includes a key of the target consensus data; Determine the data type of the target consensus data, including: Determine whether the key of the target consensus data is a fixed value; If the key of the target consensus data is a fixed value, determining that the target consensus data is the metadata; If the key of the target consensus data is not a fixed value, the target consensus data is determined to be the consensus message data.
9. The method of claim 8, wherein the read instruction includes a virtual memory address of the target consensus data in the mapping area; Determine the data type of the target consensus data, including: Matching the virtual memory address with a first virtual memory address range corresponding to the first mapping area and a second virtual memory address range corresponding to the second mapping area respectively; If the virtual memory address hits the first virtual memory address range, determining that the target consensus data is the metadata; If the virtual memory address hits the second virtual memory address range, the target consensus data is determined to be the consensus message data.
10. The method of claim 8, reading the target consensus data from the first mapping area or the second mapping area, include: The target consensus data is searched in the first mapping area or the second mapping area based on the key of the target consensus data.
11. The method of claim 1, further comprising: include: In response to a garbage collection instruction for the consensus message data, traverse the second mapping area to determine target consensus message data stored in the second mapping area that needs to be garbage collected; In response to determining that the target consensus message data needs to be garbage collected, the virtual memory space occupied by the target consensus message data in the second mapping area is released.
12. The method of claim 11, wherein the garbage collection instruction includes a specified value range corresponding to a key of the target consensus message data that needs to be garbage collected; Traversing the second mapping area, determining the target consensus message data stored in the second mapping area that needs to be garbage collected, include: The second mapping area is traversed to search for consensus message data whose key value stored in the second mapping area is within the value range, and the found consensus message data is determined as the target consensus message data that needs to be garbage collected.
13. The method of claim 11, further comprising: include: In response to determining that the target consensus message data needs to be garbage collected, further determining whether the target consensus message data has been written back to the physical storage space; If so, the target consensus message data stored in the physical storage space is synchronously deleted.
14. The method of claim 1, further comprising: include: In response to an instruction to perform state recovery on the consensus protocol running on the consensus process, the consensus data persistently stored in the mapping area is read, and state recovery processing is performed on the consensus protocol based on the read consensus data.
15. A persistent storage device for consensus data, applied to any consensus node participating in consensus in a blockchain system, in, The process address space of the consensus process running on the consensus node includes a reserved mapping area; a one-to-one mapping relationship is established between the virtual memory address in the mapping area and the physical storage address in the non-volatile physical storage space carried by the consensus node for persistent storage of consensus data; the device includes: An acquisition module is used to acquire consensus data generated by the consensus process in the process of running the consensus protocol; A storage module writes the consensus data into the mapping area for persistent storage; A write-back module, in response to the consensus data being successfully written into the mapping area, determines a physical storage address that has established a mapping relationship with the virtual memory address of the consensus data in the mapping area, and based on the physical storage address, further writes the consensus data back to the physical storage space.
16. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, in, When the processor executes the computer program, the steps of the method according to any one of claims 1 to 14 are implemented.
17. A computer-readable storage medium having a computer program stored thereon, wherein the computer program implements the steps of any one of the methods of claims 1 to 14 when executed by a processor.
18. A computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 14 are implemented.
Citation Information
Patent Citations
Traceable tamper-proof chip research and development transaction data storage method and system
CN109657501A
Interminable peer relationships in transient communities
US20030187918A1
Optimized file system layout for distributed consensus protocol
US20170177448A1
Method for executing transaction in blockchain, and master node and slave node of blockchain
WO2023231337A1
Consensus node type conversion method and consensus node
WO2024066011A1
