Time synchronization method of block chain system and related device
By implementing the time synchronization method in the blockchain system, the time difference between nodes is eliminated, and the problem of time difference in the blockchain system affecting reliability is solved, time unity is achieved, and system stability and reliability are improved.
Patent Information
- Application Number
- CN202311792996.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-22
- Publication Date
- 2025-06-24
AI Technical Summary
The time difference between nodes in the blockchain system affects the reliability of blockchain technology. How to reduce the time difference between nodes has become the key to ensuring the reliability of blockchain technology.
By introducing a time synchronization method in the blockchain system, the first node collects the time information of the consensus node, removes the time information that does not meet the preset conditions, calculates the mean value of the processed time information as the target time information, and sends the target time information to the consensus node to update the local time information.
It realizes the time unity of all nodes in the blockchain system, and improves the stability and reliability of the blockchain system.
Smart Images

Figure CN120196675A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of blockchain technology, and in particular, to a time synchronization method and related devices for a blockchain system. Background Art
[0002] A blockchain is a distributed and decentralized database structure. Each block in the blockchain stores certain information, and multiple blocks are connected into a chain in the order of their generation. This chain is stored in all nodes within the blockchain system. Modifying the data in the blockchain requires the consent of more than half of the nodes, so the blockchain has the characteristics of decentralization and difficulty in data tampering.
[0003] In a blockchain system, each node competes to obtain the opportunity to generate a block, that is, every node in the blockchain system can participate in the generation of the blockchain. A crucial link in the formation of multiple blocks into a chain is the timestamp in the block. Therefore, the time consistency of all nodes in the blockchain system becomes a crucial link in whether the blocks can be correctly connected into a chain. How to reduce the time difference between nodes in the blockchain system has become the key to ensuring the reliability of blockchain technology. Summary of the Invention
[0004] Embodiments of this application provide a time synchronization method and related devices for a blockchain system, which are used to reduce the time difference between nodes in the blockchain system and improve the reliability of blockchain technology.
[0005] The first aspect of this application provides a time synchronization method for a blockchain system, which is applied to a blockchain system. The blockchain system includes a first node and N second nodes. The first node and the N second nodes are consensus nodes. The first node is used to:
[0006] Send a first message to the N second nodes. The first message is used to obtain the time information of any one of the N second nodes, where N is a positive integer;
[0007] Obtain N second messages. The N second messages carry the time information of the N second nodes;
[0008] Remove the time information that does not meet the preset conditions from the time information of the N second nodes to obtain the processed time information;
[0009] Calculate the mean value of the processed time information to obtain the target time information;
[0010] Send the target time information to at least one consensus node, so that at least one consensus node updates the time information of at least one consensus node according to the target time information.
[0011] In the second aspect of the embodiments of the present application, a time synchronization method for a blockchain system is provided, which is applied to a blockchain system. The blockchain system includes a first node and N second nodes. The first node and the N second nodes are consensus nodes, where N is a positive integer. The second nodes are used for:
[0012] Obtain a first message sent by the first node, where the first message is used to obtain the time information of the N second nodes;
[0013] Send a second message to the first node, where the second message carries first time information, and the first time information is the time information of the second node;
[0014] Obtain target time information sent by the first node, where the target time information is the time information generated by the first node according to the time information of the N second nodes;
[0015] When the difference between the target time information and the first time information is greater than a target threshold, update the time information of the second node according to the target time information.
[0016] In the third aspect of the embodiments of the present application, a time synchronization device for a blockchain system is provided, which is applied to a blockchain system. The blockchain system includes a first node and N second nodes. The first node and the N second nodes are consensus nodes. The first node includes:
[0017] A sending unit, configured to send a first message to the N second nodes, where the first message is used to obtain the time information of any one of the N second nodes, and N is a positive integer;
[0018] An obtaining unit, configured to obtain N second messages, where the N second messages carry the time information of the N second nodes;
[0019] The obtaining unit is further configured to remove the time information that does not meet the preset conditions in the time information of the N second nodes to obtain processed time information;
[0020] A calculating unit, configured to calculate the mean value of the processed time information to obtain target time information;
[0021] The sending unit is further configured to send the target time information to at least one consensus node, so that at least one consensus node updates the time information of at least one consensus node according to the target time information.
[0022] In a possible implementation manner of the third aspect, the time information that does not meet the preset conditions includes, in the time information of the N second nodes, the time information whose difference from the average time information is greater than the preset threshold, or the maximum time information and the minimum time information in the time information of the N second nodes.
[0023] In a possible implementation of the third aspect, the obtaining unit is specifically configured to remove the time information that does not meet the preset conditions from the time information of the N second nodes and the time information of the first node, and obtain the processed time information.
[0024] In a possible implementation of the third aspect, the N second messages further carry the identity information of the N second nodes;
[0025] The calculation unit is specifically configured to:
[0026] Determine the weight of the processed time information according to the identity information corresponding to the processed time information, and the identity information corresponding to the processed time information is included in the identity information of the N second nodes;
[0027] Calculate the weighted average value of the processed time information according to the weight of the processed time information and the processed time information, and obtain the target time information.
[0028] In a possible implementation of the third aspect, the N second messages further carry the signatures of the N second nodes;
[0029] The verification unit is configured to verify whether the source of the time information of the N second nodes is reliable according to the signatures of the N second nodes and the identity information of the N second nodes;
[0030] The obtaining unit is specifically configured to, when the time information of the N second nodes is reliable, remove the time information that does not meet the preset conditions from the time information of the N second nodes, and obtain the processed time information.
[0031] In a possible implementation of the third aspect, the apparatus further includes a penalty unit, configured to implement a preset processing measure on the target node when the time information of the target node fails the time information detection, and the time information of the target node is any one of the time information of the N second nodes.
[0032] In a possible implementation of the third aspect, the calculation unit is specifically configured to:
[0033] Calculate the mean value of the processed time information;
[0034] When the difference between the mean value of the processed time information and the limit time information exceeds the preset range, calculate the median of the processed time information to obtain the target time information, and the limit time information is the maximum value or the minimum value in the processed time information.
[0035] In a possible implementation of the third aspect, the calculation unit is specifically configured to:
[0036] Calculate the mean value of the processed time information;
[0037] When the difference between the mean value of the processed time information and the limit time information exceeds a preset range, calculate the moving average of the processed time information to obtain the target time information, where the limit time information is the maximum or minimum value in the processed time information.
[0038] In a possible implementation manner of the third aspect, the device further includes a generating unit, configured to generate a target block according to the target time information, where the target block carries the time stamp of the first transaction and the time stamp of the second transaction. The time stamp of the first transaction is the same as the time stamp of the target block, and the time difference between the time stamp of the first transaction and the time stamp of the second transaction is a preset duration.
[0039] A time synchronization device for a blockchain system according to a fourth aspect of the embodiments of the present application is applied to a blockchain system. The blockchain system includes a first node and N second nodes. The first node and the N second nodes are consensus nodes, N is a positive integer, and the second node includes:
[0040] An obtaining unit, configured to obtain a first message sent by the first node, where the first message is used to obtain the time information of the second node;
[0041] A sending unit, configured to send a second message to the first node, where the second message carries first time information, and the first time information is the time information of the second node;
[0042] The obtaining unit is further configured to obtain target time information sent by the first node, where the target time information is time information generated by the first node according to the time information of the N second nodes, and N is an integer greater than 2;
[0043] An updating unit, configured to update the time information of the second node according to the target time information when the difference between the target time information and the first time information is greater than a target threshold.
[0044] A fifth aspect of the present application provides a computer device, including:
[0045] A memory, a transceiver, a processor, and a bus system;
[0046] Wherein, the memory is used to store a program;
[0047] The processor is configured to execute the program in the memory, including executing the methods of the above aspects;
[0048] The bus system is used to connect the memory and the processor to enable the memory and the processor to communicate.
[0049] A sixth aspect of the present application provides a computer-readable storage medium, where instructions are stored in the computer-readable storage medium. When the instructions run on a computer, the computer is caused to execute the methods of the above aspects.
[0050] A seventh aspect of the present application provides a computer program product or a computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the methods provided in the above aspects.
[0051] As can be seen from the above technical solutions, the embodiments of the present application have the following advantages:
[0052] The present application provides a time synchronization method and related devices for a blockchain system. By collecting the time information of consensus nodes in the blockchain system through a first node in the blockchain system, where the first node is a consensus node, removing the time information that does not meet the preset conditions to obtain the processed time information, calculating the average value of the processed time information as the target time information, and sending the target time information to at least one consensus node, so that at least one consensus node can update its local time information according to the target time information, realizing the time unification of all nodes in the blockchain system, thereby improving the stability and reliability of the blockchain system. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] Figure 1A It is a schematic diagram of an architecture of a blockchain system provided by an embodiment of the present application;
[0054] Figure 1B It is another schematic diagram of an architecture of a blockchain system provided by an embodiment of the present application;
[0055] Figure 2 It is a schematic diagram of an architecture of a time synchronization system of a blockchain system provided by an embodiment of the present application;
[0056] Figure 3 It is a schematic flowchart of a time synchronization method of a blockchain system provided by an embodiment of the present application;
[0057] Figure 4 It is another schematic flowchart of a time synchronization method of a blockchain system provided by an embodiment of the present application;
[0058] Figure 5 It is another schematic flowchart of a time synchronization method of a blockchain system provided by an embodiment of the present application;
[0059] Figure 6 It is a schematic diagram of a structure of a time synchronization device of a blockchain system provided by an embodiment of the present application;
[0060] Figure 7 It is another schematic diagram of a structure of a time synchronization device of a blockchain system provided by an embodiment of the present application;
[0061] Figure 8 Another structural schematic diagram of the time synchronization device for the blockchain system provided by the embodiment of the present application;
[0062] Figure 9 A structural schematic diagram of the server provided by the embodiment of the present application. Detailed implementation manners
[0063] The embodiment of the present application provides a time synchronization method and related device for a blockchain system, which reduces the difference between the time of nodes in the blockchain system and the time of other nodes, and improves the reliability of blockchain technology.
[0064] Terms such as "first", "second", "third", "fourth", etc. (if any) in the specification, claims and above-mentioned drawings of the present application are used to distinguish similar objects, and do not have to be used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged under appropriate circumstances, so that the embodiments of the present application described here can be implemented in an order other than those illustrated or described here. In addition, the terms "including" and "corresponding to" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device including a series of steps or units does not have to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products or devices.
[0065] To facilitate understanding of the technical solution provided by the present application, the blockchain technology is first briefly introduced:
[0066] The blockchain system involved in the present invention may be a distributed system formed by connecting a client and multiple nodes (any form of computing device accessing the network, such as a server, a user terminal) through network communication.
[0067] Taking the distributed system as an example of the blockchain system, see Figure 1A , Figure 1A It is an optional structural schematic diagram of the distributed system 100 applied to the blockchain system provided by the embodiment of the present invention, formed by multiple nodes (any form of computing device accessing the network, such as a server, a user terminal) and a client. A peer-to-peer network is formed between the nodes. The peer-to-peer network protocol is an application layer protocol running on top of the Transmission Control Protocol (TCP). In the distributed system, any machine such as a server or a terminal can join and become a node. A node includes a hardware layer, an intermediate layer, an operating system layer and an application layer.
[0068] See Figure 1AThe functions of each node in the shown blockchain system involve the following functions:
[0069] 1) Routing, a basic function of a node, used to support communication between nodes.
[0070] In addition to the routing function, a node can also have the following functions:
[0071] 2) Application, which is used to be deployed in the blockchain, implement specific services according to actual business requirements, record the data related to the implemented functions to form record data, carry a digital signature in the record data to indicate the source of the task data, and send the record data to other nodes in the blockchain system. When other nodes verify the source and integrity of the record data successfully, they add the record data to the temporary block.
[0072] For example, the services implemented by the application include:
[0073] 2.1) Wallet, which is used to provide the function of conducting electronic currency transactions, including initiating a transaction (i.e., sending the transaction record of the current transaction to other nodes in the blockchain system. After other nodes verify successfully, as a response to acknowledging the validity of the transaction, they deposit the record data of the transaction into the temporary block of the blockchain; of course, the wallet also supports querying the remaining electronic currency in the electronic currency address;
[0074] 2.2) Shared ledger, which is used to provide functions such as storing, querying, and modifying account data, sending the record data of the operations on the account data to other nodes in the blockchain system. After other nodes verify its validity, as a response to acknowledging the validity of the account data, they deposit the record data into the temporary block, and can also send a confirmation to the node that initiated the operation.
[0075] 2.3) Smart contract, a computerized protocol that can execute the terms of a certain contract, implemented through code deployed on the shared ledger and executed when certain conditions are met. According to actual business requirements, the code is used to complete automated transactions, such as querying the logistics status of the goods purchased by the buyer and transferring the buyer's electronic currency to the merchant's address after the buyer signs for the goods; of course, smart contracts are not limited to executing contracts for transactions, but can also execute contracts for processing received information.
[0076] 3) Blockchain, which includes a series of blocks (Block) that are sequentially connected in the order of generation. Once a new block is added to the blockchain, it will not be removed again. The block records the record data submitted by nodes in the blockchain system.
[0077] See Figure 1B , Figure 1BThis is an optional schematic diagram of the block structure provided by an embodiment of the present invention. Each block includes the hash value of the transaction records stored in this block (the hash value of this block), as well as the hash value of the previous block. Each block is connected through the hash value to form a blockchain. In addition, the block may also include information such as the timestamp when the block is generated. A blockchain, in essence, is a decentralized database, a series of data blocks associated using cryptographic methods. Each data block contains relevant information for verifying the validity of its information (anti-counterfeiting) and generating the next block.
[0078] To facilitate the understanding of the technical solutions provided by the embodiments of this application, some key terms used in the embodiments of this application are explained here first:
[0079] Blockchain: A distributed and decentralized database structure composed of immutable data blocks, which are connected in chronological order. Each data block contains a series of encrypted records or transactions.
[0080] Node: An independent participant in a blockchain network, undertaking functions such as data storage, verification, consensus, or others. Different types of nodes play different roles, such as validator nodes, full nodes, etc.
[0081] Consensus mechanism: An algorithm or protocol in a blockchain network used to ensure that each node reaches an agreement on the network state. There are various implementation methods of the consensus mechanism, such as proof-of-work (PoW), proof-of-stake (PoS), delegated proof-of-stake (DPoS), etc.
[0082] Proof-of-work (PoW) is an economic countermeasure against service and resource abuse or denial-of-service attacks. Generally, it requires users to perform some appropriately time-consuming complex operations, and the answers can be quickly verified by the service provider. The time, equipment, and energy consumed are used as the guarantee cost to ensure that the services and resources are used by real demands.
[0083] Proof-of-stake (PoS) requires the prover to provide the ownership of a certain amount of virtual resources. The operation mode of the proof-of-stake mechanism is that when creating a new block, the nodes in the blockchain system need to create a "virtual resource" transaction, and the transaction will send some virtual resources to the node itself according to a preset ratio. The proof-of-stake mechanism reduces the search difficulty of the node proportionally according to the ratio and time of the virtual resources owned by each node, thus accelerating the speed of finding random numbers. This consensus mechanism can shorten the time required to reach a consensus.
[0084] Delegated Proof of Stake (DPoS) uses the power of stakeholders to approve votes to resolve consensus issues in a fair manner. All network parameters, from fee estimation to block interval and transaction size, can be adjusted by the selected representatives. The deterministic selection of block producers allows transactions to be confirmed in an average of only 1 second. Most importantly, the consensus protocol aims to protect all participants from unnecessary logical checks.
[0085] Smart Contract: A program that automatically executes predefined rules and is deployed on a blockchain network. As part of a blockchain application, smart contracts can implement complex decentralized applications and business logic.
[0086] Timestamp: A numerical value representing the time when a specific event occurred, usually expressed in UNIX time (seconds since January 1, 1970) or Coordinated Universal Time (UTC) format. In a blockchain network, timestamps are used to mark the creation or modification time of elements such as transactions and data blocks.
[0087] Time Synchronization: In a distributed system, the process of ensuring that the system time of all nodes is consistent. Time synchronization can be achieved through the Network Time Protocol (NTP) or other corresponding protocols.
[0088] Replay Attack: A type of network attack where an attacker resends or delays previously sent legitimate data to deceive the system into thinking that the data is legitimate and new. In a blockchain environment, a replay attack may lead to double spending or false transactions.
[0089] A blockchain is a distributed and decentralized database structure. Each block in the blockchain stores certain information, and multiple blocks are connected into a chain in the order of their generation. This chain is stored in all nodes within the blockchain system. Modifying the data in the blockchain requires the consent of more than half of the nodes to be implemented. Therefore, the blockchain has the characteristics of decentralization and difficulty in data tampering.
[0090] In practical applications of blockchain technology, each node in the blockchain system can obtain the opportunity to generate a block through competition. That is, each node in the blockchain may use its local time to generate a timestamp and add this timestamp to the block. The blocks are connected into a chain based on this timestamp and other blocks. For example, each block in Ethereum contains a timestamp, and the timestamp in the block is the local time of the node that generated the block when generating the block.
[0091] Since the timestamps of blocks depend on the local time of the nodes that generate the blocks, and the generation of blocks is not limited to a particular node, the consistency of time between nodes has a great impact on the reliability of the blockchain system. Therefore, how to reduce the time difference between nodes in the blockchain system has become the key to ensuring the reliability of blockchain technology.
[0092] Based on the above problems, this application proposes that nodes in the blockchain system can collect the time information of any node other than the node itself, calculate the trimmed mean of any node other than the node itself as the target time information, and broadcast the target time information to any node other than the node itself, so that any node other than the node itself can update its local time information according to the target time information, achieving time synchronization among all nodes in the blockchain system, thereby improving the stability and reliability of the blockchain system.
[0093] For ease of understanding, please refer to Figure 2 , Figure 2 which is the application environment diagram of the time synchronization method for the blockchain system in the embodiments of this application. As Figure 2 shown, the time synchronization method for the blockchain system in the embodiments of this application is applied to the time synchronization system of the blockchain system. The time synchronization system of the blockchain system includes: a server and terminal devices; among them, the server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, Content Delivery Network (CDN), and big data and artificial intelligence platforms. The terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch, etc., but is not limited thereto. The terminal and the server can be directly or indirectly connected through wired or wireless communication methods, and this application does not make any restrictions in this regard.
[0094] The server first sends a first message to N second nodes. The first message is used to obtain the time information of the second nodes. The blockchain system includes a first node and N second nodes. The first node and the N second nodes are consensus nodes, and N is a positive integer;
[0095] Then, N second messages are obtained. The N second messages carry the time information of the N second nodes;
[0096] Then, the time information that does not meet the preset conditions in the time information of the N second nodes is removed to obtain the processed time information;
[0097] Then calculate the mean value of the processed time information to obtain the target time information;
[0098] Finally, send the target time to at least one consensus node so that at least one consensus node updates the time information of at least one consensus node according to the target time information.
[0099] Next, from the perspective of the server, the time synchronization method of the blockchain system in this application will be introduced. Please refer to Figure 3 , the time synchronization method of the blockchain system provided by the embodiments of this application includes: step S101 to step S110. Specifically:
[0100] S101. Synchronize the time information of the consensus nodes in the blockchain system;
[0101] In the startup phase of the blockchain system, first initialize the consensus nodes in the blockchain system and synchronize the time information of the consensus nodes in the blockchain system. Among them, the consensus nodes in the blockchain system include a first node and N second nodes, and N is a positive integer.
[0102] Specifically, the consensus nodes in the blockchain system synchronize the time information of the consensus nodes with a certain network time to achieve the synchronization of the time information of the consensus nodes in the blockchain system.
[0103] S102. The consensus nodes in the blockchain system elect the first node as the proposal node;
[0104] Before the target block is generated, the consensus nodes in the blockchain system use the consensus algorithm to select the first node as the proposal node when the blockchain system generates the target block.
[0105] Exemplarily, the blockchain system can use the PoS consensus mechanism or the DPoS consensus mechanism to elect the first node as the proposal node.
[0106] Specifically, multiple consensus nodes in the blockchain system can be used as the proposal node in turn. For example, the blockchain system includes consensus node 1, consensus node 2, consensus node 3, and consensus node 4. Among them, consensus node 1, consensus node 2, consensus node 3, and consensus node 4 are used as the proposal nodes of the blockchain system in turn.
[0107] It can be understood that the description of the consensus nodes in the blockchain system selecting the first node as the proposal node here is only an example. In actual applications, it should be set according to the specific application scenario and is not limited here.
[0108] S103. The first node sends a first message to the N second nodes;
[0109] After the first node is elected as the proposal node, the first node sends a first message to N second nodes, where the second nodes are any consensus nodes in the blockchain system except the first node, and the second nodes are verification nodes. The first message is used to obtain the time information of the second nodes, and the first message carries the identity information of the first node. N is a positive integer.
[0110] Optionally, the first message may further carry the current consensus round identifier, and the N second nodes may also learn about the progress of the proposal based on the current consensus round identifier carried in the first message.
[0111] S104. The N second nodes send N second messages to the first node;
[0112] After obtaining the first message sent by the first node, the N second nodes send N second messages to the first node, and the N second messages carry the time information of the N second nodes.
[0113] Optionally, the N second messages may further carry the signatures of the N second nodes and the identity information of the N second nodes.
[0114] It can be understood that the description of the content carried in the second message here is only an example. In actual applications, it should be set according to the specific application scenario, and there is no limitation here.
[0115] S105. The first node verifies whether the sources and contents of the N second messages are reliable;
[0116] The first node verifies the signatures carried in the N second messages to determine whether the sources and contents of the N second messages are reliable.
[0117] When the first node successfully verifies the signatures carried in the N second messages, the sources and contents of the N second messages are both reliable, and step S106 is executed;
[0118] When the first node fails to verify the signature carried in at least one of the N second messages, step S103 is executed.
[0119] In the embodiment of the present application, the second message is verified using the signatures carried in the N second messages. When the sources and message contents of the N second messages are both reliable, the target time information is calculated using the time information of the N second nodes carried in the N second messages. Subsequent operations are performed on the premise of ensuring the reliability of the message source, which improves the reliability of the solution.
[0120] S106. The first node removes the time information that does not meet the preset conditions from the time information of the N second nodes to obtain the processed time information;
[0121] When the sources of the N second messages are reliable, the first node removes the time information that does not meet the preset conditions from the time information of the N second nodes to obtain the processed time information.
[0122] Optionally, the time information that does not meet the preset conditions may be the time information among the time information of the N second nodes whose difference from the average time information is greater than the preset threshold, and the average time information is the mean value of the time information of the N second nodes.
[0123] Alternatively, the time information that does not meet the preset conditions may also be the maximum and minimum time information among the time information of the N second nodes, and there is no limitation here.
[0124] It can be understood that the description of the time information that does not meet the preset conditions here is only an example. In actual applications, different preset conditions can also be set in combination with specific application scenarios to implement the screening of the obtained time information, and there is no limitation here.
[0125] Optionally, the first node may also remove the time information that does not meet the preset conditions from the time information of the N second nodes and the time information of the first node to obtain the processed time information.
[0126] When the first node removes the time information that does not meet the preset conditions from the time information of the N second nodes and the time information of the first node to obtain the processed time information, the time information that does not meet the preset conditions may be:
[0127] Among the time information of the N second nodes and the time information of the first node, the time information whose difference from the average time information is greater than the preset threshold, and the average time information is the mean value of the time information of the N second nodes and the time information of the first node.
[0128] Alternatively, among the time information of the N second nodes and the time information of the first node, the maximum and minimum time information, and there is no limitation here.
[0129] S107. The first node calculates the target time information according to the processed time information;
[0130] Exemplarily, there are various methods for the first node to calculate the target time information according to the processed time information. The following introduces these methods respectively:
[0131] 1. Average value method;
[0132] Calculate the average value of the processed time information as the target time information.
[0133] 2. Weighted average method;
[0134] Calculate the weighted average of the processed time information as the target time information.
[0135] Specifically, first, determine the weight of the processed time information according to the identity information of the second node corresponding to the processed time information.
[0136] Then, calculate the weighted average of the processed time information based on the weight of the processed time information and the processed time information to obtain the target time information.
[0137] Optionally, the weight of the preset node is the weight calculated according to the trust level of the preset node and the rights and interests of the preset node. The preset node is any node corresponding to a time information in the processed time information, and the weight of the preset node is included in the processed weight corresponding to the processed time information.
[0138] In the embodiments of the present application, using the weighted average of the processed time information as the target time information fully considers that different second nodes have different reliabilities, gives greater weight to the time information of nodes with higher accuracy and trust level, and improves the accuracy of the target time information.
[0139] Furthermore, the weight of the preset node is the weight obtained by adjusting the weight to be adjusted of the preset node according to the node leadership of the preset node, the historical performance of the preset node, and the contribution degree of the preset node to the blockchain system.
[0140] In the embodiments of the present application, according to the real-time information of different nodes in the blockchain system, dynamically adjusting the weights corresponding to the time information of N second nodes can improve the accuracy of calculating the target time information of the blockchain system.
[0141] 3. Median method;
[0142] Calculate the median of the processed time information as the target time information.
[0143] Specifically, sort the processed time information in ascending order. Assume that the processed time information is M time information, and M is a positive integer;
[0144] When the number of processed time information is odd, select the ((M + 1) / 2)-th time information in the sorting as the target time information;
[0145] When the number of processed time information is even, calculate the average value of the (M / 2)-th time information and the ((M + 2) / 2)-th time information in the sorting as the target time information.
[0146] Further, when calculating the target time information by the median method, it can be used when it is found during the process of calculating the target time information by the average method that the difference between the mean value of the processed time information and the extreme time information exceeds the preset range. The extreme time information is the maximum or minimum value in the processed time information.
[0147] In the embodiments of the present application, when an abnormality is found during the process of calculating the target time information by the average method or the weighted average method, the median method is used to calculate the target time information to ensure the accuracy of the target time information of the blockchain system.
[0148] 4. Moving average method;
[0149] Calculate the moving average of the processed time information as the target time information.
[0150] Specifically, calculate the moving average of the processed time information as the target time information.
[0151] Further, when calculating the target time information by the moving average method, it can be used when it is found during the process of calculating the target time information by the average method that the difference between the mean value of the processed time information and the extreme time information exceeds the preset range. The extreme time information is the maximum or minimum value in the processed time information.
[0152] In the embodiments of the present application, when an abnormality is found during the process of calculating the target time information by the average method or the weighted average method, the moving average method is used to calculate the target time information to ensure the accuracy of the target time information of the blockchain system.
[0153] Optionally, the first node can also set the target time information as the time information of the blockchain system and generate an association relationship between the target time information and the consensus round information.
[0154] It can be understood that the description of the method for calculating the target time information here is only an example. In practical applications, it should be set according to the specific application scenario and actual requirements, and no limitation is made here.
[0155] Optionally, after the first node obtains N pieces of second information sent by N second nodes, it can also perform time information detection based on the time information in the N pieces of second information. When the time information of the target node exceeds the reasonable time range, it is considered that the time information of the target node fails the time information detection, and the first node executes a penalty on the target node. For example, reducing the weight of the target node, generating a bad credit record, or temporarily disabling the target node, etc. Among them, the target node is any one of the N second nodes, the time information of the target node is included in the time information of the N second nodes, and the weight of the target node is included in the weight of the N second nodes.
[0156] When the time information of the target node is within the reasonable time range, it is considered that the time information of the target node passes the time information detection and no additional operation needs to be performed.
[0157] In the embodiments of the present application, when the time information of the target node exceeds the reasonable time range, it is considered that the target node fails the time information detection, and a preset processing measure (penalty) is executed on the target node to reduce the influence degree of the target node on the blockchain system and improve the reliability of the solution.
[0158] Optionally, the target time information can also be associated with the current consensus round for subsequent reference when verifying the block or time generated in the current consensus round.
[0159] Furthermore, the interval time between two adjacent consensus rounds is usually 30s, which is not limited here.
[0160] S108. The first node sends the target time information to at least one consensus node;
[0161] After the first node calculates and obtains the target time information, it sends the target time information to at least one consensus node.
[0162] Specifically, the first node sending the target time information to at least one consensus node includes multiple situations, which will be introduced one by one below:
[0163] The first situation: After the first node calculates and obtains the target time information, it sends the target time information to at least one consensus node by broadcasting, so that after at least one consensus node obtains the target time information, it can update the time information according to the target time information.
[0164] The second situation: The first node periodically sends the target time information to the N second nodes;
[0165] Among them, the first node sending the target time information to the N second nodes can be an active sending or a sending triggered by a signal for obtaining sent by the N second nodes, which is not limited here.
[0166] For example, N second nodes use a certain time interval or a fixed block height interval as the period for the second nodes to regularly check and obtain the target time information. Among them, the time interval can be five minutes, ten minutes, etc., and the block height interval can be 50 blocks, 100 blocks, etc., which are not limited here.
[0167] Optionally, when the N second nodes periodically obtain the target time information, they can obtain the target time information, that is, the system time of the blockchain system, by querying the time query interface of the blockchain system contract.
[0168] The third case: The node administrators of the N second nodes obtain the target time information according to the actual situation.
[0169] It can be understood that the description of the situation where the N second nodes obtain the target time information here is only an example. In actual applications, it should be set according to the specific application scenario and usage requirements, which are not limited here.
[0170] S109. At least one consensus node updates the time information of at least one consensus node according to the target time information to obtain N updated time information;
[0171] After at least one consensus node obtains the target time information, it uses the target time information to update the time information of the consensus node to obtain the updated time information. At least one consensus node may include at least a second node among the N second nodes, and / or the first node.
[0172] Exemplarily, after at least one consensus node obtains the target time information, if the difference between the time information of at least one consensus node and the target time information is greater than the target threshold, the target time information is used to update the time information of the second node to obtain the updated time information. For example, the target threshold can be 1 second, 2 seconds, etc.
[0173] Among them, at least one consensus node includes at least one second node among the N second nodes, and / or the updated time information of the first node is included in the N updated time information.
[0174] Furthermore, the time of all components related to the timer, scheduler, and business logic data in at least one consensus node can also be set to the updated time information.
[0175] If the difference between the time information of at least one consensus node and the target time is less than or equal to the target threshold, no operation needs to be performed. Among them, at least one consensus node includes at least one second node among the N second nodes, and / or the updated time information is included in the N updated time information.
[0176] Optionally, the target threshold may be a value set by the node administrators of the N second nodes according to the actual situation.
[0177] It can be understood that the description of updating the time information of at least one consensus node by at least one consensus node here is only an example. In actual applications, it should be set according to the specific application scenario and usage requirements, and there is no limitation here.
[0178] It should be noted that there is no clear sequence between step S109 and step S110. In actual applications, it should be set according to the specific application scenario, and there is no limitation here.
[0179] S110. The first node generates a target block.
[0180] After the first node calculates the target time information, it can also generate a target block. The target block carries the timestamp of the target block, the timestamp of the first transaction, and the timestamp of the second transaction. Among them, the timestamp of the first transaction is the same as the timestamp of the target block, and the time difference between the timestamp of the first transaction and the timestamp of the second transaction is a preset duration.
[0181] Exemplarily, the target block may further include the timestamp of a third transaction, and the time difference between the timestamp of the third transaction and the timestamp of the second transaction is also the preset duration. The preset duration may be 1 millisecond.
[0182] For example, the timestamp of the target block is 00:00:01.003, the timestamp of the first transaction is 00:00:01.003, the timestamp of the second transaction is 00:00:01.004, the timestamp of the third transaction is 00:00:01.005, etc.
[0183] Optionally, the preset duration may be a duration preset by the administrator of the blockchain system, or a duration that can be dynamically modified, and there is no limitation here.
[0184] It can be understood that the description of the timestamps carried in the target block here is only an example. In actual applications, it should be set according to the specific usage scenario, and there is no limitation here.
[0185] It should be noted that there is no clear sequence between step S109 and step S110. In actual applications, it should be set according to the specific application scenario, and there is no limitation here.
[0186] In the embodiments of the present application, by defining the relationship between the timestamps in the target block, the execution time of each transaction in the target block is associated with the transaction execution order, which is convenient for the nodes in the blockchain system to understand the sequence of transactions in the target block and improves the usability of the solution.
[0187] In the embodiments of the present application, the consensus nodes in the blockchain system can collect the time information of the consensus nodes, remove the time information that does not meet the preset conditions, obtain the processed time information, calculate the average value of the processed time information as the target time information, and send the target time information to at least one consensus node, so that at least one consensus node can update the local time information according to the target time information, realizing the time unification of all nodes in the blockchain system, thereby improving the stability and reliability of the blockchain system.
[0188] The above introduced the inspection and processing of abnormal time for the first node. However, in actual applications, the abnormal time of the second node can also be discovered by the second node itself and report the time abnormality of this node to the first node. The following will introduce this situation in combination with Figure 4 introduce this situation:
[0189] S201. The second node determines whether the time information of the second node is within a reasonable time range;
[0190] The second node periodically determines whether the time information of the second node is within a reasonable time range.
[0191] Exemplarily, the second node uses a certain time interval or a fixed block height interval as the period for determining whether the time information of the second node is within a reasonable time range. Among them, the time interval can be five minutes, ten minutes, etc., and the block height interval can be 50 blocks, 100 blocks, etc. There is no limitation here.
[0192] Optionally, after the second node obtains the target time information calculated by the first node, it can also determine whether the time information of the second node is within a reasonable time range by judging whether the difference between the time information of the second node and the target time information is within a reasonable time difference range. There is no limitation here.
[0193] It can be understood that the description here for the second node to determine whether the time information of the second node is within a reasonable time range is only an example. In actual applications, it should be set in combination with specific application scenarios and usage requirements. There is no limitation here.
[0194] When the time information of the second node is within a reasonable time range, after the cycle duration, step S201 is executed again;
[0195] When the time information of the second node exceeds the reasonable time range, step S202 is executed.
[0196] S202. The second node sends time abnormality information to the first node;
[0197] When the second node determines that the time information of the second node exceeds the reasonable time range, it confirms that the appearance time of the second node is abnormal. Generate a time anomaly message and send the time anomaly message to the first node. The time anomaly message carries the signature of the second node and the identity information of the second node.
[0198] S203. The first node determines whether the source of the time anomaly message is reliable;
[0199] After obtaining the time anomaly message, the first node determines whether the source of the time anomaly message is reliable by using the signature of the second node and the identity information of the second node carried in the time anomaly message.
[0200] When the source of the time anomaly message is reliable, step S204 is executed;
[0201] When the source of the time anomaly message is unreliable, step S201 is executed.
[0202] S204. The first node performs a preset processing measure on the second node.
[0203] When the source of the time anomaly message is reliable, the first node performs a preset processing measure on the second node. For example, reduce the weight of the second node, generate a bad credit record related to the second node, or temporarily disable the second node, etc.
[0204] In the embodiment of the present application, the second node periodically detects the time information of the second node, and when the time information of the second node is not within the reasonable time range, sends a time anomaly message to the first node. The time anomaly message carries the signature and identity information of the second node, and the first node can perform a preset processing measure on the second node according to the time anomaly message. This enriches the specific implementation manner of the solution and improves the flexibility of the solution.
[0205] For ease of understanding, the following will be combined with Figure 5 Introduce a time synchronization method for a blockchain system applied to a blockchain system. After the proposal node enters a new height in consensus, it sets the consensus timeout duration and sends a time acquisition request to verification node 1 and verification node 2. After receiving the time acquisition request sent by the proposal node, verification node 1 verifies the reliability of the proposal node according to the signature and identity information carried in the time acquisition request. After the verification passes, it obtains the operating system time of verification node 1, signs the operating system time of verification node 1, and sends it to the proposal node.
[0206] After receiving the time acquisition request sent by the proposal node, verification node 2 verifies the reliability of the proposal node according to the signature and identity information carried in the time acquisition request. After the verification passes, it obtains the operating system time of verification node 2, signs the operating system time of verification node 2, and sends it to the proposal node.
[0207] After receiving the operating system time of the first verification node sent by the first verification node and the operating system time of the second verification node sent by the second verification node, the proposal node removes the abnormal time in the operating system time of the first verification node sent by the first verification node and the operating system time of the second verification node sent by the second verification node, and calculates the operating system time of the first verification node sent by the first verification node and the operating system time of the second verification node sent by the second verification node by using the weighted average method to obtain the target time information, and the proposal node records the target time information.
[0208] The time synchronization device of the blockchain system in the present application will be described in detail below. Please refer to Figure 6 。 Figure 6 FIG. 1 is a schematic diagram of an embodiment of a time synchronization device 10 of a blockchain system in an embodiment of the present application. The time synchronization device 10 of the blockchain system includes:
[0209] A sending unit 110, configured to send a first message to N second nodes, where the first message is used to obtain the time information of any one of the N second nodes, and N is a positive integer;
[0210] An obtaining unit 120, configured to obtain N second messages, where the N second messages carry the time information of the N second nodes;
[0211] The obtaining unit 120 is further configured to remove the time information that does not meet the preset conditions in the time information of the N second nodes to obtain the processed time information;
[0212] A calculating unit 130, configured to calculate the mean value of the processed time information to obtain the target time information;
[0213] The sending unit 110 is further configured to send the target time information to at least one consensus node, so that at least one consensus node updates the time information of at least one consensus node according to the target time information.
[0214] Optionally, the time information that does not meet the preset conditions includes the time information in the time information of the N second nodes that has a difference greater than the preset threshold from the average time information, or the time information with the largest value and the time information with the smallest value in the time information of the N second nodes.
[0215] Optionally, the obtaining unit 120 is specifically configured to remove the time information that does not meet the preset conditions in the time information of the N second nodes and the time information of the first node to obtain the processed time information.
[0216] Optionally, the N second messages further carry the identity information of the N second nodes;
[0217] The computing unit 130 is specifically configured to:
[0218] Determine the weight of the processed time information according to the identity information corresponding to the processed time information, and the identity information corresponding to the processed time information is included in the identity information of N second nodes;
[0219] Calculate the weighted average value of the processed time information based on the weight of the processed time information and the processed time information to obtain the target time information.
[0220] In the embodiment of the present application, the weighted average of the processed time information is used as the target time information, fully considering that different second nodes have different reliabilities, giving greater weight to the time information of nodes with higher accuracy and trust, and improving the accuracy of the target time information.
[0221] In the Figure 6 corresponding embodiment of the time synchronization device of the blockchain system provided by the embodiment of the present application, please refer to Figure 7 , the N second messages also carry the signatures of the N second nodes;
[0222] The verification unit 140 is configured to verify whether the source of the time information of the N second nodes is reliable according to the signatures of the N second nodes and the identity information of the N second nodes;
[0223] The acquisition unit 120 is specifically configured to, when the time information of the N second nodes is reliable, remove the latest time information and the earliest time information from the time information of the N second nodes to obtain the processed time information.
[0224] In the embodiment of the present application, the signatures and identity information carried by the N second messages are used to verify whether the sources of the N second messages are reliable. When the sources of the N second messages are all reliable, the time information of the N second nodes carried in the N second messages is used to calculate the target time information. Subsequent operations are carried out on the premise of ensuring the reliability of the message source, improving the reliability of the solution.
[0225] Optionally, the device further includes a penalty unit 150, configured to implement a preset processing measure on the target node when the time information of the target node fails the time information detection, and the time information of the target node is any one of the time information of the N second nodes.
[0226] In the embodiment of the present application, when the time information of the target node exceeds the reasonable time range, it is considered that the target node fails the time information detection, and a preset processing measure (penalty) is executed on the target node to reduce the influence degree of the target node on the blockchain system, improving the reliability of the solution.
[0227] Optionally, the computing unit 130 is specifically configured to:
[0228] Calculate the mean value of the processed time information;
[0229] When the difference between the mean value of the processed time information and the limit time information exceeds the preset range, calculate the median of the processed time information to obtain the target time information, where the limit time information is the maximum or minimum value in the processed time information.
[0230] In the embodiment of the present application, when an anomaly is found during the calculation of the target time information by the trimmed mean method or the weighted mean method, the median method is used to calculate the target time information to ensure the accuracy of the target time information of the blockchain system.
[0231] Optionally, the calculation unit 130 is specifically configured to:
[0232] Calculate the mean value of the processed time information;
[0233] When the difference between the mean value of the processed time information and the limit time information exceeds the preset range, calculate the moving average of the processed time information to obtain the target time information, where the limit time information is the maximum or minimum value in the processed time information.
[0234] In the embodiment of the present application, when an anomaly is found during the calculation of the target time information by the trimmed mean method or the weighted mean method, the moving average method is used to calculate the target time information to ensure the accuracy of the target time information of the blockchain system.
[0235] Optionally, the device further includes a generating unit 160, configured to generate a target block, where the target block carries the time stamp of the first transaction and the time stamp of the second transaction. The time stamp of the first transaction is the same as the time stamp of the target block, and the time difference between the time stamp of the first transaction and the time stamp of the second transaction is a preset duration.
[0236] In the embodiment of the present application, by defining the relationship between the time stamps in the target block, the execution time of each transaction in the target block is associated with the transaction execution order, which facilitates the nodes in the blockchain system to understand the sequence of transactions in the target block and improves the usability of the solution.
[0237] Please refer to Figure 8 , Figure 8 which is a schematic diagram of an embodiment of the time synchronization device 20 of the blockchain system in the embodiment of the present application. The time synchronization device 20 of the blockchain system includes:
[0238] An obtaining unit 210, configured to obtain a first message sent by a first node, where the first message is used to obtain the time information of a second node;
[0239] A sending unit 220, configured to send a second message to a first node, where the second message carries first time information, and the first time information is the time information of a second node;
[0240] An obtaining unit 210 is further configured to obtain target time information sent by the first node, where the target time information is time information generated by the first node according to the time information of N second nodes, and N is an integer greater than 2;
[0241] An updating unit 230 is configured to update the time information of the second node according to the target time information when the difference between the target time information and the first time information is greater than a target threshold.
[0242] Figure 9 FIG. is a schematic structural diagram of a server provided by an embodiment of the present application. The server 300 may vary greatly due to different configurations or performances, and may include one or more central processing units (CPUs) 322 (for example, one or more processors) and a memory 332, and one or more storage media 330 (for example, one or more mass storage devices) storing application programs 342 or data 344. Among them, the memory 332 and the storage media 330 may be transient storage or persistent storage. The program stored in the storage media 330 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations on the server. Further, the central processing unit 322 may be configured to communicate with the storage media 330 and execute a series of instruction operations in the storage media 330 on the server 300.
[0243] The server 300 may further include one or more power supplies 326, one or more wired or wireless network interfaces 350, one or more input / output interfaces 358, and / or one or more operating systems 341, such as Windows Server TM , Mac OS X TM , Unix TM , Linux TM , FreeBSD TM and so on.
[0244] In the above embodiments, the steps executed by the server may be based on the Figure 9 shown server structure.
[0245] Those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working processes of the systems, devices, and units described above may refer to the corresponding processes in the foregoing method embodiments, and will not be described herein again.
[0246] In several embodiments provided by the present application, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of units is only a logical function division. In actual implementation, there may be other division methods. 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 displayed or discussed couplings or direct couplings or communication connections to each other can be through some interfaces, and the indirect couplings or communication connections of devices or units can be in electrical, mechanical, or other forms.
[0247] The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they can be located in one place, or distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0248] In addition, in each embodiment of the present application, the functional units can be integrated in a processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit. The above-mentioned integrated units can be implemented in the form of hardware or in the form of software functional units.
[0249] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods in each embodiment of the present application. The foregoing storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical discs that can store program codes.
[0250] The above, the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements for some of the technical features; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of each embodiment of the present application.
Claims
1. A time synchronization method for a blockchain system, characterized in that, Applied to a blockchain system, the blockchain system includes a first node and N second nodes, the first node and the N second nodes are consensus nodes, and the first node is used to: Send a first message to the N second nodes, the first message is used to obtain the time information of any one of the N second nodes, and N is a positive integer; Obtain N second messages, and the N second messages carry the time information of the N second nodes; Remove the time information that does not meet the preset conditions from the time information of the N second nodes to obtain the processed time information; Calculate the mean value of the processed time information to obtain the target time information; Send the target time information to at least one consensus node of the blockchain system, so that the at least one consensus node updates the time information of the at least one consensus node according to the target time information.
2. The method according to claim 1, wherein The time information that does not meet the preset conditions includes the time information in the time information of the N second nodes that has a difference greater than the preset threshold from the average time information, or the time information with the largest value and the time information with the smallest value in the time information of the N second nodes, and the average time information is the mean value of the time information of the N second nodes.
3. The method according to claim 1, characterized in that, The removing the time information that does not meet the preset conditions from the time information of the N second nodes to obtain the processed time information includes: Removing the time information that does not meet the preset conditions from the time information of the N second nodes and the time information of the first node to obtain the processed time information.
4. The method according to any one of claims 1 to 3, characterized in that The N second messages also carry the identity information of the N second nodes; The calculating the mean value of the processed time information to obtain the target time information includes: Determine the weight of the processed time information according to the identity information corresponding to the processed time information, and the identity information corresponding to the processed time information is included in the identity information of the N second nodes; Calculate the weighted average value of the processed time information according to the weight of the processed time information and the processed time information to obtain the target time information.
5. The method according to claim 4, wherein The N second messages also carry the signatures of the N second nodes; The method further includes: Verify whether the source of the time information of the N second nodes is reliable according to the signatures of the N second nodes and the identity information of the N second nodes; The removing the time information that does not meet the preset conditions from the time information of the N second nodes to obtain the processed time information includes: When the time information of the N second nodes is reliable, remove the time information that does not meet the preset conditions from the time information of the N second nodes to obtain the processed time information.
6. The method according to claim 4 or 5, characterized in that, The method further includes: When the time information of the target node fails the time information detection, implement a preset processing measure on the target node, and the time information of the target node is any one of the time information of the N second nodes.
7. The method according to any one of claims 1 to 3, characterized in that The calculating the mean value of the processed time information to obtain the target time information includes: Calculate the mean value of the processed time information; When the difference between the mean of the processed time information and the limit time information exceeds a preset range, calculate the median of the processed time information to obtain the target time information, where the limit time information is the maximum or minimum value in the processed time information.
8. The method according to any one of claims 1 to 3, characterized in that, The calculating the mean of the processed time information to obtain the target time information includes: Calculating the mean of the processed time information; When the difference between the mean of the processed time information and the limit time information exceeds a preset range, calculate the moving average of the processed time information to obtain the target time information, where the limit time information is the maximum or minimum value in the processed time information.
9. The method according to any one of claims 1 to 3, characterized in that The method further includes: Generating a target block according to the target time information, where the target block carries the time stamp of the first transaction and the time stamp of the second transaction, the time stamp of the first transaction is the same as the time stamp of the target block, and the time difference between the time stamp of the first transaction and the time stamp of the second transaction is a preset duration.
10. A time synchronization method for a blockchain system, characterized in that, Applied to a blockchain system, the blockchain system includes a first node and N second nodes, the first node and the N second nodes are consensus nodes, N is a positive integer, and the second nodes are used for: Obtaining a first message sent by the first node, where the first message is used to obtain the time information of the N second nodes; Sending a second message to the first node, where the second message carries first time information, and the first time information is the time information of the second node; Obtaining the target time information sent by the first node, where the target time information is the time information generated by the first node according to the time information of the N second nodes; When the difference between the target time information and the first time information is greater than a target threshold, updating the time information of the second node according to the target time information.
11. A time synchronization device for a blockchain system, characterized in that, Applied to a blockchain system, the blockchain system includes a first node and N second nodes, the first node and the N second nodes are consensus nodes, and the first node includes: A sending unit, configured to send a first message to the N second nodes, where the first message is used to obtain the time information of any one of the N second nodes, and N is a positive integer; An obtaining unit, configured to obtain N second messages, where the N second messages carry the time information of the N second nodes; The obtaining unit is further configured to remove the time information that does not meet a preset condition from the time information of the N second nodes to obtain processed time information; A calculating unit, configured to calculate the mean of the processed time information to obtain target time information; The sending unit is further configured to send the target time information to at least one consensus node, so that the at least one consensus node updates the time information of the at least one consensus node according to the target time information.
12. A time synchronization device for a blockchain system, characterized in that, Applied to a blockchain system, the blockchain system includes a first node and N second nodes, the first node and the N second nodes are consensus nodes, N is a positive integer, and the second node includes: An acquisition unit, configured to acquire a first message sent by a first node, where the first message is used to acquire time information of a second node; A sending unit, configured to send a second message to the first node, where the second message carries first time information, and the first time information is the time information of the second node; The acquisition unit is further configured to acquire target time information sent by the first node, where the target time information is time information generated by the first node according to time information of N second nodes; An update unit, configured to update the time information of the second node according to the target time information when a difference between the target time information and the first time information is greater than a target threshold.
13. A computer device, characterized in that, It includes: A memory, a transceiver, a processor, and a bus system; Wherein, the memory is used to store programs; The processor is configured to execute the programs in the memory, including executing the time synchronization method of the blockchain system according to any one of claims 1 to 10; The bus system is configured to connect the memory and the processor, so that the memory and the processor can communicate with each other.
14. A computer-readable storage medium, including instructions, which when running on a computer, cause the computer to execute the time synchronization method of the blockchain system according to any one of claims 1 to 10.
15. A computer program product, comprising a computer program, characterized in that, The computer program is executed by a processor to perform the time synchronization method of the blockchain system according to any one of claims 1 to 10.