A method and device for performing active-standby switching of a blockchain node
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-30
- Publication Date
- 2026-08-11
AI Technical Summary
在数据存储这一层,用户可通过接入一个高可用的数据库进程以达到数据层面的高可用保障,然而在链节点层面,当进程或节点服务器出现故障时,链不再往数据库写入新的数据,直接影响到用户对最新数据的获取
[0012]根据本说明书实施例提供的进行区块链节点主备切换的方法和装置,该区块链节点包括若干计算设备和控制设备,若干计算设备分别注册至控制设备,该控制设备用于向已注册至控制设备的多个计算设备中的一个计算设备提供分布式锁。第一计算设备初始拥有分布式锁,即,第一计算设备初始为区块链节点的主计算设备。控制设备在第一计算设备发生故障之后,删除第一计算设备的注册,并向其他计算设备发送与第一计算设备对应的删除事件。第二计算设备响应于删除事件,根据控制设备中记录的各计算设备的信息,获取到分布式锁,生成区块链节点的主计算设备。由此,通过控制设备提供的分布式锁,实现了在第一计算设备发生故障之后,将获取到分布式锁的第二计算设备切换为新的主计算设备,保证了区块链节点的主、备计算设备之间的顺利切换,保证了区块链节点的高可用性。
Smart Images

Figure CN116302714B_ABST
Abstract
Description
Technical Field
[0001] The embodiments in this specification belong to the field of blockchain technology, and in particular relate to a method and apparatus for switching blockchain nodes between primary and backup nodes. Background Technology
[0002] Blockchain is a novel application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanisms, and cryptographic algorithms. In a blockchain system, data blocks are sequentially linked together to form a chain-like data structure, and a distributed ledger is cryptographically guaranteed to be immutable and unforgeable. Due to its decentralized, immutable, and autonomous characteristics, blockchain is receiving increasing attention and application.
[0003] In a data access scenario where a business directly connects to a blockchain consortium participant node, a node failure prevents the business client from continuing to retrieve data from a trusted and authorized node, disrupting the continuous data export process. Businesses require a constant connection to the blockchain nodes. While users can achieve high availability at the data storage layer by connecting to a highly available database process, at the blockchain node level, a failure in the process or node server stops writing new data to the database, directly impacting users' access to the latest data. Therefore, to ensure the real-time and uninterrupted delivery of blocks to the database, blockchain nodes need to have hot-standby switching capabilities. Summary of the Invention
[0004] This specification describes one or more embodiments of a method and apparatus for performing master-slave switching of blockchain nodes.
[0005] According to a first aspect, a method for performing master-slave switching of blockchain nodes is provided. The blockchain node includes a plurality of computing devices and a control device. The plurality of computing devices are respectively registered to the control device. The control device is used to provide a distributed lock to one of the plurality of computing devices registered to the control device. The first computing device initially possesses the distributed lock. The method includes: after the first computing device fails, the control device deletes the registration of the first computing device and sends a deletion event corresponding to the first computing device to other computing devices; in response to the deletion event, the second computing device acquires the distributed lock according to the information of each computing device recorded in the control device and becomes the master computing device of the blockchain node.
[0006] According to the second aspect, a method for switching between primary and backup blockchain nodes is provided. The blockchain node includes several computing devices and a control device. The computing devices are respectively registered to the control device. The control device provides a distributed lock to one of the computing devices registered to the control device. The first computing device initially owns the distributed lock. The method is applied to a second computing device. The method includes: in response to a deletion event sent by the control device, sending a request to the control device to obtain information of each computing device recorded in the control device; and determining, based on the information of each computing device recorded in the control device, acquiring the distributed lock and becoming the primary computing device of the blockchain node.
[0007] According to the third aspect, a method for switching between primary and backup blockchain nodes is provided. The blockchain node includes several computing devices and a control device. The method is applied to the control device and includes: recording information of each registered computing device based on the registration of the several computing devices; determining a computing device that owns a distributed lock based on the information of each computing device; deleting the registration of a registered computing device that has failed and sending a deletion event to the registered computing devices in response to a request sent by the registered computing devices; and sending the recorded information of each registered computing device in response to a request sent by the registered computing devices, so that the registered computing devices can determine whether to acquire the distributed lock based on the received information, wherein the computing device that acquires the distributed lock becomes the primary computing device of the blockchain node.
[0008] According to the fourth aspect, an apparatus for switching between primary and backup blockchain nodes is provided. The blockchain node includes a plurality of computing devices and a control device. The plurality of computing devices are respectively registered to the control device. The control device is used to provide a distributed lock to one of the plurality of computing devices registered to the control device. The first computing device initially possesses the distributed lock. The apparatus is disposed on the second computing device. The apparatus includes: an acquisition unit configured to send a request to the control device in response to a deletion event sent by the control device to acquire information of each computing device recorded in the control device; and a determination unit configured to determine, based on the information of each computing device recorded in the control device, that the device that has acquired the distributed lock has become the primary computing device of the blockchain node.
[0009] According to the fifth aspect, an apparatus for performing master-slave switching of blockchain nodes is provided. The blockchain node includes a plurality of computing devices and a control device. The apparatus is disposed on the control device and includes: a recording unit configured to record information of each registered computing device based on the registration of the plurality of computing devices; a lock determination unit configured to determine, based on the information of each computing device, that a computing device possesses a distributed lock; a deletion unit configured to, in response to determining that a registered computing device has failed, delete the registration of the failed computing device and send a deletion event to the registered computing device; and an information sending unit configured to, in response to a request sent by a registered computing device, send the recorded information of each registered computing device, so that the registered computing device can determine whether to acquire the distributed lock based on the received information, wherein the computing device that acquires the distributed lock becomes the master computing device of the blockchain node.
[0010] According to a sixth aspect, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed in a computer, causes the computer to perform the methods described in the second or third aspect.
[0011] According to a seventh aspect, a computing device is provided, including a memory and a processor, wherein executable code is stored in the memory, and when the processor executes the executable code, it implements the method as described in the second or third aspect.
[0012] According to the method and apparatus for switching between primary and backup blockchain nodes provided in the embodiments of this specification, the blockchain node includes several computing devices and a control device. The computing devices are respectively registered to the control device, which provides a distributed lock to one of the multiple computing devices registered to it. A first computing device initially possesses the distributed lock, meaning it is initially the primary computing device of the blockchain node. After the first computing device fails, the control device deletes its registration and sends a deletion event corresponding to the first computing device to the other computing devices. In response to the deletion event, a second computing device acquires the distributed lock based on the information of each computing device recorded in the control device and becomes the primary computing device of the blockchain node. Thus, by using the distributed lock provided by the control device, after the first computing device fails, the second computing device, which has acquired the distributed lock, is switched to become the new primary computing device, ensuring a smooth switch between the primary and backup computing devices of the blockchain node and guaranteeing the high availability of the blockchain node. Attached Figure Description
[0013] To more clearly illustrate the technical solutions of the embodiments in this specification, the drawings used 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 those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0014] Figure 1 A blockchain architecture diagram in one embodiment is shown;
[0015] Figure 2 A schematic diagram is shown illustrating one application scenario in which the embodiments of this specification can be applied;
[0016] Figure 3 This diagram illustrates the registration of a first computing device to a control device.
[0017] Figure 4 A flowchart illustrating a method for switching between primary and backup blockchain nodes according to one embodiment is shown.
[0018] Figure 5 A schematic block diagram of an apparatus for performing master-slave switching of blockchain nodes is shown according to one embodiment;
[0019] Figure 6 A schematic block diagram of an apparatus for performing master-slave switching of blockchain nodes is shown according to yet another embodiment. Detailed Implementation
[0020] 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 with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this specification, and not all embodiments. Based on the embodiments in this specification, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of this specification.
[0021] Figure 1 A blockchain architecture diagram from one embodiment is shown. Figure 1 In the blockchain architecture diagram shown, blockchain 100 includes N nodes. Figure 1 The diagram illustrates nodes 1 through 8. The lines connecting the nodes schematically represent P2P (Peer-to-Peer) connections, such as TCP connections, used for data transmission between nodes.
[0022] In the blockchain field, a transaction refers to a unit of task executed and recorded within the blockchain. A transaction typically includes a From field, a To field, and a Data field. Specifically, in the case of a transfer transaction, the From field represents the account address initiating the transaction (i.e., initiating a transfer task to another account), the To field represents the account address receiving the transaction (i.e., receiving the transfer), and the Data field includes the transfer amount.
[0023] Blockchain provides the functionality of smart contracts. A smart contract on the blockchain is a contract that can be triggered and executed through transactions within the blockchain system. Smart contracts can be defined in the form of code. Calling a smart contract on the blockchain involves initiating a transaction pointing to the smart contract's address, causing each node in the blockchain to run the smart contract code in a distributed manner.
[0024] In a contract deployment scenario, for example, Bob sends a transaction containing information about creating a smart contract (i.e., deploying the contract) to a server such as... Figure 1 In the blockchain shown, the `data` field of the transaction includes the code (such as bytecode or machine code) of the contract to be created, and the `to` field of the transaction is empty, indicating that the transaction is used to deploy the contract. After the nodes reach an agreement through the consensus mechanism, they determine the contract address "0x6f8ae93…". Each node adds a contract account corresponding to the contract address of the smart contract to the state database, allocates state storage corresponding to the contract account, stores the contract code, and saves the hash value of the contract code in the contract's state storage, thus the contract is successfully created.
[0025] In scenarios where contracts are invoked, for example, Bob sends a transaction to invoke a smart contract, such as... Figure 1 In the blockchain shown, the `from` field of this transaction is the address of the account of the transaction initiator (i.e., Bob), the `to` field is the aforementioned "0x6f8ae93…", which is the address of the smart contract being invoked, and the `data` field of the transaction includes the method and parameters for invoking the smart contract. After consensus is reached on this transaction in the blockchain, each node in the blockchain can execute the transaction, thereby executing the contract separately, and updating the state database based on the execution of the contract.
[0026] The consensus mechanism in blockchain is a mechanism by which blockchain nodes reach a network-wide consensus on block information (or block data), ensuring that the latest block is accurately added to the blockchain. Current mainstream consensus mechanisms include Proof of Work (POW), Proof of Stake (POS), Delegated Proof of Stake (DPoS), and Practical Byzantine Fault Tolerance (PBFT) algorithms. In various consensus algorithms, consensus on a consensus proposal is typically determined after a predetermined number of consensus nodes reach agreement on the proposed data. Specifically, in the PBFT algorithm, for N ≥ 3f+1 consensus nodes, f malicious nodes can be tolerated. That is, when 2f+1 out of N consensus nodes reach agreement, consensus is considered successful.
[0027] As mentioned earlier, to ensure the real-time and uninterrupted nature of blocks stored in the database, chain nodes need to have hot standby switching capabilities. Therefore, the embodiments in this specification provide a method for performing primary / standby switching of blockchain nodes. As an example, Figure 2 A schematic diagram is shown illustrating one application scenario in which the embodiments of this specification can be applied.
[0028] like Figure 2As shown, in this application scenario, blockchain node 2 includes a first computing device 201, a second computing device 202, a third computing device 203, and a control device 204. The first computing device 201, second computing device 202, and third computing device 203 are registered with the control device 204. The control device 204 provides a distributed lock to one of the three computing devices, and the computing device holding the distributed lock becomes the master computing device of the blockchain node. In this example, the first computing device 201 initially holds the distributed lock; that is, initially, the first computing device 201 is the master computing device, and the second computing devices 202 and 203 are backup computing devices. The control device 204 can monitor in real time whether any computing device has failed. If a failure occurs, it deletes the registration of the failed computing device and sends a deletion event to the other computing devices. In this example, the first computing device 201 malfunctions, for example, it crashes. After the malfunction, the control device 204 deletes the registration of the first computing device 201 and sends deletion events corresponding to the first computing device 201 to the second computing device 202 and the third computing device 203. In response to the deletion event, the second computing device 202 acquires the distributed lock based on the information of each computing device recorded in the control device 204 and becomes the new master computing device of the blockchain node. This completes the switchover between the master and backup computing devices.
[0029] As described above, the control device 204 can provide distributed locks for several computing devices of the blockchain node. Therefore, the control device 204 can be equipped with a distributed storage system, such as Zookeeper, Redis (Remote Dictionary Server), ETCD, etc., all of which can provide distributed locks.
[0030] Before switching between the primary and backup computing devices of a blockchain node, the various computing devices included in the blockchain node need to register with the control device 204. As an example, Figure 3 A schematic diagram is shown, taking the first computing device as an example, registering with the control device 204. Figure 3 As shown, the specific registration process can be described as follows:
[0031] S301, the first computing device 201 registers with the control device 204 after startup.
[0032] In this embodiment, after startup, the first computing device 201 can connect to the distributed storage system deployed in the control device 204 and send a registration request to the control device 204. This request may include the identifier of the first computing device 201, such as its IP address (Internet Protocol Address). Based on the registration request, the control device 204 can create a key (value) corresponding to the identifier of the first computing device 201 under the distributed lock path. Taking ETCD as an example of the distributed storage system, the first computing device 201 can write the key to ETCD via a Put operation. For example, an example of the distributed lock path provided by ETCD for the blockchain can be as follows:
[0033] / [etcd_version] / [chain_name] / structured_election / ;
[0034] Taking the identifier of the first computing device 201 as the IP address XXX.0.0.1 as an example, the key corresponding to the identifier of the first computing device 201 can be created under the distributed lock path in the above example as follows:
[0035] / [etcd_version] / [chain_name] / structured_election / XXX.0.0.1.
[0036] S302, in response to the registration of the first computing device 201, the control device 204 determines the registration value corresponding to the first computing device 201.
[0037] In this embodiment, for the registration of the first computing device 201, the control device 204 can determine a registration value corresponding to the first computing device 201. Subsequently, the first computing device 201 can determine whether it has acquired the distributed lock based on this registration value. Taking the distributed storage system ETCD as an example, the registration value can refer to the Revision value. In practice, for the registration of the first computing device 201, ETCD can determine a Revision value, and the magnitude of the Revision value determines the order in which locks are acquired.
[0038] S303, the control device 204 can feed back the registration value corresponding to the first computing device 201 to the first computing device 201.
[0039] S304, the control device 204 stores the registration value and identifier corresponding to the first computing device 201 in the target list.
[0040] In practice, when a computing device fails, the control device can also delete the registration corresponding to the failed node. Taking the distributed storage system ETCD as an example, each computing device can set a lease for its corresponding key during registration. Computing devices can also create leases to maintain heartbeats, with the heartbeat interval being less than the lease duration; for example, it can be set to 2 / 3 of the lease duration, and the lease duration is updated after each heartbeat. After receiving heartbeat information from a computing device, if the control device determines that the time interval since the last heartbeat is greater than the preset lease duration, it determines that the computing device has failed, deletes the key corresponding to the failed computing device from the distributed lock directory, and removes the registration value and identifier corresponding to the failed computing device from the target list.
[0041] It is understandable that the process of other computing devices registering to the control device is the same as that of the first computing device, and will not be elaborated here.
[0042] In practical use, the control device first records the information of each registered computing device based on the registration of several computing devices. Then, based on this information, it determines which computing device possesses the distributed lock. In response to a registered computing device malfunctioning, its registration is deleted, and a deletion event is sent to the remaining registered computing devices. In response to a request from a registered computing device, the recorded information of each registered computing device is sent, allowing the registered computing device to determine whether to acquire the distributed lock based on the received information. The computing device that acquires the distributed lock becomes the master computing device of the blockchain node.
[0043] Continue to refer to Figure 4 , Figure 4 A flowchart illustrating a method for performing master-slave switchover of blockchain nodes according to one embodiment is shown. Figure 4 In the example shown, the blockchain node includes two computing devices, a first computing device 201 and a second computing device 202, and a control device 204. The first computing device 201 and the second computing device 202 are registered with the control device 204. The control device 204 can provide a distributed lock to one of the registered computing devices. In this example, the first computing device 201 initially holds the distributed lock. Specific methods for master-slave failover may include the following:
[0044] S401, after the first computing device 201 malfunctions, the control device 204 deletes the registration of the first computing device 201.
[0045] In this embodiment, the control device 204 can determine in real time whether any of the registered computing devices have malfunctioned, such as crashing. As an example, each computing device can periodically send heartbeat information to the control device 204, and the control device 204 can determine whether any computing device has malfunctioned based on the heartbeat information. In this example, if the control device 204 does not receive heartbeat information from the first computing device 201 for a preset interval, it can determine that the first computing device has malfunctioned.
[0046] If a malfunction occurs, the registration of the malfunctioning computing device will be deleted. Figure 3 Taking the registration example shown, when a computing device malfunctions, its key in the distributed lock directory can be deleted, as well as the corresponding registration value and identifier for that computing device in the target list can be deleted. After the registration is deleted, the computing device will be unable to participate in primary / standby failover.
[0047] S402, the control device 204 sends a deletion event corresponding to the first computing device 201 to other computing devices (in this example, the second computing device 202).
[0048] In this embodiment, after deleting the registration of the first computing device 201, the control device 204 can send a deletion event corresponding to the first computing device to each computing device registered with the control device 204.
[0049] In some implementations, each computing device registered with the control device 204 can listen for key deletion events in the distributed lock directory.
[0050] S403, in response to the deletion event, the second computing device 202 obtains the information of each computing device recorded in the control device 204.
[0051] In this embodiment, after receiving a deletion event, the second computing device 202 can obtain information about each computing device recorded in the control device 204, such as the name, identifier, and registration value of the computing device. Specifically, in response to the deletion event, the second computing device 202 can send a request to the control device to obtain information about each computing device recorded in the control device.
[0052] S404, the second computing device 202 obtains the distributed lock based on the information of each computing device recorded in the control device 204, and becomes the main computing device of the blockchain node.
[0053] In this embodiment, the second computing device 202 can determine whether it has acquired the distributed lock based on the information of each computing device recorded in the control device 204. If it acquires the distributed lock, it becomes the master computing device of the blockchain node. The master computing device can write block data into the database corresponding to the blockchain node according to the conventional processing flow of the blockchain node. For example, all write operations generated within each block can be treated as a complete transaction and committed when the block formation event is triggered.
[0054] In some application scenarios, the database is a relational database.
[0055] In some implementations, the second computing device 202 can obtain the latest target list from the control device 204 and determine whether it has acquired the distributed lock based on the registration values of each computing device included in the latest target list. Taking the distributed storage system ETCD as an example, the second computing device 202 can determine whether its own registration value is the minimum value in the latest target list; if it is the minimum value, it determines that it has acquired the distributed lock.
[0056] In some implementations, the blockchain node may also include a database for storing the blockchain node's block data, such as block and state data. After the second computing device 202 becomes the primary computing device for the blockchain node, the aforementioned method for switching between primary and backup blockchain nodes may further include the following:
[0057] 1) After acquiring the distributed lock, the second computing device 202 reads the first block number of the last block successfully written to the database by the first computing device 201.
[0058] 2) Based on the first block number and the second block number of the block corresponding to the latest successful consensus proposal of the blockchain, determine the missing block data in the database.
[0059] For example, suppose the first block number of the last block successfully written to the database by the first computing device is 101, and the second block number of the block corresponding to the latest successful consensus proposal of the blockchain is 105. Then, based on the first block number 101 and the second block number 105, it can be determined that the database contains missing block data with block numbers 102, 103, and 104. As an example, the missing block data may include the missing blocks and the state data corresponding to the missing blocks.
[0060] 3) The second computing device 202 can obtain the missing block data in the database and store the missing block data in the database.
[0061] In some implementations, before the first computing device 201 fails, the second computing device can synchronize the block data of the first computing device to the memory cache. Furthermore, the aforementioned acquisition of missing block data from the database can be specifically implemented as follows: a) In response to determining that the memory cache includes the missing first block data from the database, the first block data is retrieved from the memory cache. b) For second block data that is not stored in the memory cache and is missing from the database, the second block data is retrieved from other blockchain nodes. Through this implementation, missing block data from the database can be retrieved first from the memory cache, and for block data not stored in the memory cache, it can then be retrieved from other blockchain nodes, thereby accelerating the acquisition of block data and thus speeding up the completion of the database.
[0062] In some implementations, after supplementing the database with missing data, the second computing device 202 can also execute multiple transactions in the block with the second block number based on the latest successful consensus proposal of the blockchain, and update the database based on the execution results of the multiple transactions. This updating of the database based on the execution results of the multiple transactions includes updating the state tree in the state database, generating a block, and storing the generated block in the block database.
[0063] In some implementations, the first computing device can be restarted after troubleshooting. After restarting, the first computing device can re-register with the control device. Upon successful registration, it determines whether a distributed lock has been acquired based on the registration values of each computing device included in the updated target list. If the distributed lock has not been acquired, the first computing device serves as a backup computing device for the blockchain node.
[0064] Reviewing the above process, in the embodiments described in this specification, the blockchain node includes several computing devices and a control device. The computing devices are registered with the control device, which provides a distributed lock to one of the registered computing devices. The first computing device initially possesses the distributed lock; that is, the first computing device is initially the master computing device of the blockchain node. After the first computing device fails, the control device deletes its registration and sends a deletion event corresponding to the first computing device to the other computing devices. In response to the deletion event, the second computing device acquires the distributed lock based on the information of each computing device recorded in the control device and becomes the master computing device of the blockchain node. Thus, through the distributed lock provided by the control device, after the first computing device fails, the second computing device, having acquired the distributed lock, is switched to become the new master computing device, ensuring a smooth switch between the master and backup computing devices of the blockchain node and guaranteeing the high availability of the blockchain node.
[0065] According to another embodiment, an apparatus for performing master-slave switching of blockchain nodes is provided, which is disposed in a second computing device.
[0066] Figure 5 A schematic block diagram of an apparatus 500 for performing master-slave switching of blockchain nodes according to one embodiment is shown. The blockchain node includes a plurality of computing devices and a control device. The plurality of computing devices are respectively registered to the control device. The control device is used to provide a distributed lock to one of the plurality of computing devices registered to the control device, wherein the first computing device initially possesses the distributed lock. The apparatus 500 includes: an acquisition unit 501 configured to send a request to the control device in response to a deletion event sent by the control device to acquire information of each computing device recorded in the control device; and a determination unit 502 configured to determine, based on the information of each computing device recorded in the control device, that the device that has acquired the distributed lock has become the master computing device of the blockchain node.
[0067] According to another embodiment, a further device for performing master-slave switching of blockchain nodes is provided, which is disposed in a control device.
[0068] Figure 6 A schematic block diagram of an apparatus 600 for performing master-slave switching of blockchain nodes according to yet another embodiment is shown. The blockchain node includes a plurality of computing devices and a control device. The apparatus 600 includes: a recording unit 601 configured to record information of each registered computing device based on the registration of the plurality of computing devices; a lock determination unit 602 configured to determine, based on the information of each computing device, that a computing device possesses a distributed lock; a deletion unit 603 configured to, in response to determining that a registered computing device has failed, delete the registration of the failed computing device and send a deletion event to the registered computing device; and an information sending unit 604 configured to, in response to a request sent by a registered computing device, send the recorded information of each registered computing device, so that the registered computing device can determine whether to acquire the distributed lock based on the received information, wherein the computing device that acquires the distributed lock becomes the master computing device of the blockchain node.
[0069] In the 1990s, improvements to a technology could be clearly distinguished as either hardware improvements (e.g., improvements to the circuit structure of diodes, transistors, switches, etc.) or software improvements (improvements to the methodology). However, with technological advancements, many methodological improvements today can be considered direct improvements to the hardware circuit structure. Designers almost always obtain the corresponding hardware circuit structure by programming the improved methodology into the hardware circuit. Therefore, it cannot be said that a methodological improvement cannot be implemented using hardware physical modules. For example, a Programmable Logic Device (PLD) (such as a Field Programmable Gate Array (FPGA)) is such an integrated circuit whose logic function is determined by the user programming the device. Designers can program and "integrate" a digital system onto a PLD themselves, without needing chip manufacturers to design and manufacture dedicated integrated circuit chips. Furthermore, nowadays, instead of manually manufacturing integrated circuit chips, this programming is mostly implemented using "logic compiler" software. Similar to the software compiler used in program development, the original code before compilation must be written in a specific programming language, called a Hardware Description Language (HDL). There are many HDLs, 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, and RHDL (Ruby Hardware Description Language). Currently, the most commonly used are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should understand that by simply performing some logic programming on the method flow using one of these hardware description languages and programming it into an integrated circuit, the hardware circuit implementing the logical method flow can be easily obtained.
[0070] The controller can be implemented in any suitable manner. For example, it can take the form of a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro)processor, logic gates, switches, application-specific integrated circuits (ASICs), programmable logic controllers, and embedded microcontrollers. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicon Labs C8051F320. A memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art will also recognize that, in addition to implementing the controller in purely computer-readable program code form, the same functionality can be achieved by logically programming the method steps to make the controller take the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers. Therefore, such a controller can be considered a hardware component, and the means included therein for implementing various functions can also be considered as structures within the hardware component. Alternatively, the means for implementing various functions can be considered as both software modules implementing the method and structures within the hardware component.
[0071] The systems, devices, modules, or units described in the above embodiments can be implemented by computer chips or physical entities, or by products with certain functions. A typical implementation device is a server system. Of course, this application does not exclude the possibility that, with the future development of computer technology, the computer implementing the functions of the above embodiments can be, for example, a personal computer, a laptop computer, an in-vehicle human-machine interaction device, a cellular phone, a camera phone, a smartphone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or any combination of these devices.
[0072] While one or more embodiments of this specification provide the operational steps of the methods described in the embodiments or flowcharts, more or fewer operational steps may be included based on conventional or non-inventive means. The order of steps listed in the embodiments is merely one possible order of execution among many steps and does not represent the only possible order. In actual device or end product execution, the methods shown in the embodiments or drawings may be executed sequentially or in parallel (e.g., in a parallel processor or multi-threaded processing environment, or even a distributed data processing environment). The terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, product, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, product, or apparatus. Without further limitations, the presence of other identical or equivalent elements in the process, method, product, or apparatus that includes the elements is not excluded. For example, the use of terms such as "first," "second," etc., is to denote names and does not indicate any particular order.
[0073] For ease of description, the above devices are described in terms of function, divided into various modules. Of course, when implementing one or more of these specifications, the functions of each module can be implemented in one or more software and / or hardware components, or a module that performs the same function can be implemented by a combination of multiple sub-modules or sub-units. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division; in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces, indirect coupling or communication connection between devices or units, and may be electrical, mechanical, or other forms.
[0074] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0075] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0076] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0077] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0078] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0079] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information by any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic disk storage, graphene storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0080] Those skilled in the art will understand that one or more embodiments of this specification can be provided as a method, system, or computer program product. Therefore, one or more embodiments of this specification may take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, one or more embodiments of this 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.
[0081] One or more embodiments of this specification can be described in the general context of computer-executable instructions, such as program modules, that are executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform a particular task or implement a particular abstract data type. One or more embodiments of this specification can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.
[0082] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, system embodiments are basically similar to method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments. In the description of this specification, the terms "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., refer to specific features, structures, materials, or characteristics described in connection with that embodiment or example, which are included in at least one embodiment or example of this specification. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described can be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification and the features of different embodiments or examples.
[0083] The above description is merely an embodiment of one or more embodiments of this specification and is not intended to limit the scope of these embodiments. Various modifications and variations can be made to these embodiments by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this specification should be included within the scope of the claims.
Claims
1. A method for performing master-slave switching of blockchain nodes, wherein the blockchain node includes a plurality of computing devices and a control device, the plurality of computing devices are respectively registered to the control device, and the control device is used to provide a distributed lock to one of the plurality of computing devices registered to the control device, wherein, The first computing device initially possesses the distributed lock, and the method includes: After the first computing device malfunctions, the control device deletes the registration of the first computing device and sends a deletion event corresponding to the first computing device to other computing devices. In response to the deletion event, the second computing device acquires the distributed lock based on the information of each computing device recorded in the control device, and becomes the master computing device of the blockchain node; The blockchain node also includes a database. After acquiring the distributed lock, the second computing device reads the first block number of the last block successfully written by the first computing device into the database. Based on the first block number and the second block number of the block corresponding to the latest successful consensus proposal of the blockchain, determine the missing block data in the database; Retrieve the missing block data from the database and store the missing block data in the database; The method further includes, before the first computing device fails, the second computing device synchronizing the block data of the first computing device to a memory cache; and The step of obtaining the missing block data in the database includes: In response to determining that the memory cache includes a first block of data that is missing from the database, the first block of data is retrieved from the memory cache; For second block data that is not stored in the memory cache and is missing in the database, the second block data is obtained from other blockchain nodes.
2. The method according to claim 1, wherein, The missing block data includes the missing block and the status data corresponding to the missing block.
3. The method according to claim 2, wherein, The method further includes, after filling in the missing data in the database, executing multiple transactions in the block with the second block number according to the consensus proposal, and updating the database based on the execution results of the multiple transactions.
4. The method according to claim 1, wherein, The control device is equipped with a distributed storage system, ETCD.
5. The method according to claim 4, wherein, The method further includes: the second computing device registering with the control device after startup; the control device determining a registration value corresponding to the second computing device in response to the registration of the second computing device; and the control device storing the registration value and identifier corresponding to the second computing device in a target list; and In response to the deletion event, the second computing device acquires the distributed lock based on the information of each computing device recorded in the control device, including: In response to the deletion event, the second computing device obtains the latest target list from the control device and determines whether to acquire the distributed lock based on the registration values of each computing device included in the latest target list.
6. The method according to claim 5, wherein, The method further includes: after receiving the heartbeat information sent by the computing device, if the control device determines that the time interval between the last heartbeat information sent is greater than the preset lease duration, it determines that the computing device has malfunctioned, and deletes the registration value and identifier corresponding to the malfunctioning computing device from the target list.
7. The method according to claim 1, wherein, The method further includes: if the control device does not receive heartbeat information from the first computing device for a preset interval, it determines that the first computing device has malfunctioned.
8. The method according to claim 5, wherein, The method further includes: after the first computing device restarts, it re-registers with the control device; after successful registration, it determines whether the distributed lock has been acquired based on the registration values of each computing device included in the updated target list; and if the distributed lock has not been acquired, it is used as a backup computing device for the blockchain node.
9. A method for performing master-slave switching of a blockchain node, wherein the blockchain node includes a plurality of computing devices and a control device, the blockchain node further includes a database, the plurality of computing devices are respectively registered to the control device, and the control device is used to provide a distributed lock to one of the plurality of computing devices registered to the control device, wherein... The first computing device initially possesses the distributed lock, and the method is applied to the second computing device, the method comprising: In response to a deletion event sent by the control device, a request is sent to the control device to obtain information about each computing device recorded in the control device; Based on the information of each computing device recorded in the control device, the device that acquires the distributed lock becomes the master computing device of the blockchain node. Read the first block number of the last block successfully written by the first computing device to the database; Based on the first block number and the second block number of the block corresponding to the latest successful consensus proposal of the blockchain, determine the missing block data in the database; Obtain the missing block data from the database and store the missing block data in the database; The method further includes, before the registered computing device fails, the master computing device synchronizing the block data of the first computing device to a memory cache; and The step of obtaining the missing block data in the database includes: In response to determining that the memory cache includes a first block of data that is missing from the database, the first block of data is retrieved from the memory cache; For second block data that is not stored in the memory cache and is missing in the database, the second block data is obtained from other blockchain nodes.
10. A method for performing master-slave switchover of a blockchain node, wherein the blockchain node includes a plurality of computing devices and control devices, and the blockchain node further includes a database, the method being applied to the control devices, the method comprising: Based on the registration of the aforementioned computing devices, information about each registered computing device is recorded; Based on the information from each computing device, determine from the plurality of computing devices that one computing device possesses a distributed lock; In response to determining that a registered computing device has malfunctioned, the registration of the malfunctioning computing device is deleted, and a deletion event is sent to the registered computing devices. In response to a request from a registered computing device, information about each registered computing device is transmitted, allowing the registered computing device to determine whether to acquire a distributed lock based on the received information. The computing device that acquires the distributed lock becomes the master computing device of the blockchain node. The master computing device is used to read the first block number of the last block successfully written to the database by the first computing device, and based on the first block number and the second block number of the block corresponding to the latest successful consensus proposal of the blockchain, determine the missing block data in the database, acquire the missing block data in the database, and store the missing block data in the database. Before a registered computing device malfunctions, the master computing device is also used to synchronize the block data of the first computing device to a memory cache. Acquiring the missing block data in the database includes: in response to determining that the memory cache contains the missing first block data from the database, acquiring the first block data from the memory cache; and for second block data that is not stored in the memory cache and is missing in the database, acquiring the second block data from other blockchain nodes.
11. An apparatus for performing master-slave switching of blockchain nodes, wherein the blockchain node includes a plurality of computing devices and a control device, the blockchain node further includes a database, the plurality of computing devices are respectively registered to the control device, and the control device is used to provide a distributed lock to one of the plurality of computing devices registered to the control device, wherein, The first computing device initially possesses the distributed lock, and the device is disposed on the second computing device, the device comprising: The acquisition unit is configured to send a request to the control device in response to a deletion event sent by the control device, in order to acquire information of each computing device recorded in the control device, and synchronize the block data of the first computing device to the memory cache before the first computing device fails. The determining unit is configured to determine, based on the information of each computing device recorded in the control device, the master computing device that acquires the distributed lock and becomes the blockchain node, and is further configured to read the first block number of the last block successfully written by the first computing device to the database; determine the missing block data in the database based on the first block number and the second block number of the block corresponding to the latest consensus proposal successfully reached by the blockchain; acquire the missing block data in the database; and store the missing block data in the database. The step of obtaining the missing block data in the database includes: In response to determining that the memory cache includes a first block of data that is missing from the database, the first block of data is retrieved from the memory cache; For second block data that is not stored in the memory cache and is missing in the database, the second block data is obtained from other blockchain nodes.
12. An apparatus for performing master-slave switching of blockchain nodes, wherein the blockchain node includes a plurality of computing devices and control devices, the blockchain node further includes a database, and the apparatus is disposed on the control devices, the apparatus comprising: The recording unit is configured to record information about each registered computing device based on the registration of the plurality of computing devices; The lock determination unit is configured to determine, based on information from each computing device, that one computing device possesses a distributed lock from the plurality of computing devices. The deletion unit is configured to, in response to determining that a registered computing device has failed, delete the registration of the failed computing device and send a deletion event to the registered computing device. The information sending unit is configured to send, in response to a request from a registered computing device, recorded information about each registered computing device, so that the registered computing device can determine whether to acquire a distributed lock based on the received information. The computing device that acquires the distributed lock becomes the master computing device of the blockchain node. The master computing device is used to read the first block number of the last block successfully written to the database by the first computing device, determine the missing block data in the database based on the first block number and the second block number of the block corresponding to the latest successful consensus proposal of the blockchain, acquire the missing block data in the database, and store the missing block data in the database. Before the first computing device fails, the master computing device is also used to synchronize the block data of the first computing device to a memory cache. Acquiring the missing block data in the database includes: in response to determining that the memory cache includes the missing first block data in the database, acquiring the first block data from the memory cache; for second block data that is not stored in the memory cache and is missing in the database, acquiring the second block data from other blockchain nodes.
13. A computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to perform the method of any one of claims 9-10.
14. A computing device comprising a memory and a processor, wherein the memory stores executable code, and the processor, when executing the executable code, implements the method of any one of claims 9-10.
Citation Information
Patent Citations
Method for switching nodes in distributed master-slave system
CN112860386A
Main and standby node switching method and device, equipment, medium and program product
CN114567540A