Nothing Special   »   [go: up one dir, main page]

CN116388921B - Link point time synchronization method, device and storage medium based on precompiled contracts - Google Patents

Link point time synchronization method, device and storage medium based on precompiled contracts Download PDF

Info

Publication number
CN116388921B
CN116388921B CN202310647296.5A CN202310647296A CN116388921B CN 116388921 B CN116388921 B CN 116388921B CN 202310647296 A CN202310647296 A CN 202310647296A CN 116388921 B CN116388921 B CN 116388921B
Authority
CN
China
Prior art keywords
time
node
nodes
time node
module
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202310647296.5A
Other languages
Chinese (zh)
Other versions
CN116388921A (en
Inventor
李晓风
许金林
赵赫
张晓婷
盛念祖
周桐
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Anhui Zhongke Lattice Technology Co ltd
Original Assignee
Anhui Zhongke Lattice Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Anhui Zhongke Lattice Technology Co ltd filed Critical Anhui Zhongke Lattice Technology Co ltd
Priority to CN202310647296.5A priority Critical patent/CN116388921B/en
Publication of CN116388921A publication Critical patent/CN116388921A/en
Application granted granted Critical
Publication of CN116388921B publication Critical patent/CN116388921B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04JMULTIPLEX COMMUNICATION
    • H04J3/00Time-division multiplex systems
    • H04J3/02Details
    • H04J3/06Synchronising arrangements
    • H04J3/0635Clock or time synchronisation in a network
    • H04J3/0638Clock or time synchronisation among nodes; Internode synchronisation
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04JMULTIPLEX COMMUNICATION
    • H04J3/00Time-division multiplex systems
    • H04J3/02Details
    • H04J3/06Synchronising arrangements
    • H04J3/0635Clock or time synchronisation in a network
    • H04J3/0638Clock or time synchronisation among nodes; Internode synchronisation
    • H04J3/0641Change of the master or reference, e.g. take-over or failure of the master
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L41/00Arrangements for maintenance, administration or management of data switching networks, e.g. of packet switching networks
    • H04L41/30Decision processes by autonomous network management units using voting and bidding
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computer And Data Communications (AREA)

Abstract

The application relates to a link point time synchronization method, equipment and a storage medium based on a precompiled contract, which comprises a link point time setting module, a time node management contract module and a time synchronization processing module; maintaining the time of the chain node through a chain link point time module, and providing a current time inquiry interface on the chain; a time node management contract module is used for pre-compiling a time node management contract on a chain, and the contract provides a path for selecting/switching time nodes for the nodes; and the problem of switching the time node in the next time view when the time node goes wrong offline is solved through the time synchronization processing module. The application can realize the time synchronization of the block chain link points without changing the time of the local server; meanwhile, the time node switching is triggered by the voting of the multiple consensus nodes, and the time node selection is flexible; the whole compatibility is strong, and the realization complexity is low.

Description

Link point time synchronization method, device and storage medium based on precompiled contracts
Technical Field
The application relates to the technical field of block chain link point clock synchronization, in particular to a chain link point time synchronization method based on precompiled contracts.
Background
Block link point time is a key factor for normal operation of block link points and is related to block out consensus and the like. The node time inconsistency among the block chains can cause verification to be difficult to pass, block consensus and the like to be stagnated. In the public chain, the nodes are in a public network and can be communicated with a time server (such as a window time server), and each node can synchronize the time of the time server, so that clock synchronization among the nodes of the block chain is achieved. For the federation chain, the nodes are mostly located in a local area network or an internal network and cannot communicate with a public network, so that time synchronization of each node through a time server is difficult. Therefore, the problem of link point clock synchronization of the alliance chain blocks needs to be solved. In the existing schemes, the clock synchronization is mostly dependent on the local clock synchronization of the servers where the nodes are located, for example, one node server is used as a time server, and the other node servers synchronize the time of the server at regular time. This method is not flexible enough and requires additional effort to calibrate the time. In addition, in the patent 'block chain node time synchronization method based on network consensus combined with VRF algorithm', node shards are firstly proposed in each shard through VRF algorithm, then a consensus time result is obtained by utilizing intra-shard network consensus as a system time corresponding to the shard, and finally network consensus is carried out again on the system time corresponding to each shard, so as to obtain the final system time of the whole P2P network. This approach is based on two network syncs that are suitable for public chains but too complex for federation chains.
Disclosure of Invention
The link point time synchronization method based on the precompiled contracts provided by the application can solve the problem of time consistency among alliance link nodes in an internal network.
In order to achieve the above purpose, the present application adopts the following technical scheme:
a link point time synchronization method based on precompiled contracts comprises a link point time module, a time node management contract module and a time synchronization processing module;
maintaining the time of the chain node through a chain link point time module, and providing a current time inquiry interface on the chain;
a time node management contract module is used for pre-compiling a time node management contract on a chain, and the contract provides a path for selecting/switching time nodes for the nodes;
and the problem of switching the time node in the next time view when the time node goes wrong offline is solved through the time synchronization processing module.
Further, the link point time module comprises a time delay value setting and maintaining sub-module and a node time inquiry sub-module;
for the time delay value setting and maintaining submodule, the chain node does not only use the server time of the node, but also encapsulates a layer of time structure to represent the link point time; the method comprises the steps of carrying out a first treatment on the surface of the The method comprises the steps of including server time and time delay values, namely chainTime { no, delay }, wherein no represents the server time of the node, and delay represents the time delay with the time node; when time delay exists between the link node and the time node, the delay needs to be updated, so that the link point time is ensured to be basically synchronous; meanwhile, the delay value is not only cached in the memory, but also needs to be stored in the hard disk, so as to prevent the delay value from being 0 when the node is restarted;
the node time inquiry sub-module is used for providing a current node time inquiry interface for the link point by the link point time module, accumulating the server time now of the node and the latest synchronized time delay, and providing the accumulated time as the current node time of the node for other modules of the node.
Further, the time node management contract module comprises a current time node set maintenance, a time node pointer set maintenance, a time node voting method and a time node determining algorithm;
the current time node set is maintained, and a current available time node set, namely a common node set of a alliance chain, is maintained in a time node management contract; the common node set of the alliance chain ensures that only common nodes can participate in the time synchronization of the chain link points as time nodes, and the activity of the time nodes is ensured by the activity of the common nodes;
the time node pointer set is maintained, three pointers are also maintained in the time node management contract, and the current time node pointer currentPointer, the switching time node pointer set switchpointer and the switching time node proposal time pointer;
the current time node pointer currentPointer represents the currently determined and working time node and points to the nodes in the available time node set;
the switching time node pointer set switchPointMap maintains the next time node set which is currently being voted; the set is composed of map structures; the node pointer is a key of the map, points to nodes in the available time node set, and the number of node votes is a value of the map;
the switching time node proposal time pointer marks the time pointer of the first proposal of the next time node, points to the first calling time node voting method and writes the time stamp of the transaction of the first item of the switching time node pointer set switch point map and the voted node;
the time node voting method is called by each node, and votes are carried out on the nodes in the available time node set to determine the next time node;
finally, judging whether a time node in the switching time node pointer set switchPointMap is determined to be the next time node according to a time node determining algorithm; if the existing node is determined to be the next time node, the switching time node time event is thrown.
Further, the time node determining algorithm includes three parameters: switching time node proposal time pointer, available time node number availableNodeNumber in the set of available time nodes and transaction timestamp of the current calling the contract method; setting an expiration time threshold quality;
if the difference of the current contract transaction timestamp minus the proposal time pointer timepoint with the switching time node is smaller than the expiration time threshold quality, counting the votes of all nodes in the switching time node pointer set switch point map, and if the votes of the nodes are more than half of the total node number in the available time node set, selecting the nodes as new time nodes;
if the difference value is greater than or equal to the expiration time threshold value quality, checking votes of all nodes in the switching time node pointer set switchPointMap, wherein the selected nodes with high number of votes are selected as time nodes, and if the same number of votes exists, the nodes which are proposed first are selected as the time nodes;
after the time node determining algorithm is slowest at the expiration time threshold quality, the latest round of time nodes can be determined; the latest round of time nodes are determined, and the current time node pointer currentPointer maintained in the contract is updated.
Further, the time synchronization processing module is divided into a time node processing sub-module and a non-time node processing sub-module;
the time node processing sub-module is used for checking whether the node is a determined next time node in the time event of the switching time node when the node receives the time event of the switching time node, if so, sending a synchronous time message syncNodeMessage { txid, timestamp }, wherein txid represents transaction id of the switching time node when the proposal of the switching time node passes and triggers the time event of the switching time node, timestamp represents synchronous time of a new time node, and the synchronous time is obtained by querying the time node module;
the non-time node processing submodule is used for checking whether the node is a determined next time node in the switching time node time event when the node receives the switching time node time event for the node in the same block chain network all the time, and waiting for receiving a synchronous time message syncNodeMessage of the new time node if the node is not the determined next time node in the switching time node time event; when receiving a synchronous time message syncNodeMessage, verifying whether txid is truly uplink; after verification is passed, comparing the time with the local server time to update the delay value in the node time module, and completing time synchronization.
Further, the non-time node processing sub-module is further included, and for the nodes newly added into the network, synchronization of the chain data is performed, but synchronization time message syncNodeMessage cannot be received; then, an active polling mode is adopted, after synchronization is completed, a current time node pointer and an available time node set recorded in a time node management contract are inquired, a current time node is obtained, and then a request time message { from } is constructed and sent to the time node, wherein from represents the request time synchronization node; if the time node receives the request TimeMessage message, the time node sends a synchronous time message SyncNodeMessage { txid, timestamp } to the request time synchronization node; after the request time synchronization node verifies that the message syncNodeMessage passes, the delay value in the node time module is updated, and the time synchronization is completed.
In yet another aspect, the application also discloses a computer readable storage medium storing a computer program which, when executed by a processor, causes the processor to perform the steps of the method as described above.
In yet another aspect, the application also discloses a computer device comprising a memory and a processor, the memory storing a computer program which, when executed by the processor, causes the processor to perform the steps of the method as above.
According to the technical scheme, the link point time synchronization method based on the precompiled contracts comprises a link point time module, a time node management contract module and a time synchronization processing module. Further, the node time module is divided into a time delay value setting and maintaining sub-module and a node time inquiring sub-module; the time node management contract module is divided into a current time node set maintenance, a time node pointer set maintenance, a time node voting method and a time node determining algorithm; the time synchronization processing module is divided into a time node processing sub-module and a non-time node processing sub-module.
Specifically, the application has the following advantages:
(1) The time of the local server is not changed, and the block chain link point time synchronization is realized;
(2) The time node switching is triggered by the voting of the multiple consensus nodes, and the time node selection is flexible;
(3) The clock synchronization and time node switching mechanism is realized based on the precompiled contracts, the compatibility is strong, and the realization complexity is low.
Drawings
FIG. 1 is a flow chart of the present application;
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present application more apparent, the technical solutions of the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application, and it is apparent that the described embodiments are some embodiments of the present application, but not all embodiments of the present application.
As shown in fig. 1, in the link point time synchronization method based on the precompiled contracts according to the embodiment, the main modules of the scheme include a link point time module, a time node management contract module and a time synchronization processing module. Further, the node time module is divided into a time delay value setting and maintaining sub-module and a node time inquiring sub-module; the time node management contract module is divided into a current time node set maintenance, a time node pointer set maintenance, a time node voting method and a time node determining algorithm; the time synchronization processing module is divided into a time node processing sub-module and a non-time node processing sub-module.
The following are respectively specified:
and a node time module: the module maintains a time module of link points and provides a current time inquiry interface to the chain.
The time delay value setting and maintaining submodule is used for enabling the chain node to not only use the server time of the node, but also encapsulate a layer of time structure to represent the link point time. The server time and time delay values, i.e., chainTime { no, delay }, where no represents the server time at which the node is located and delay represents the time delay from the time node. When there is time delay with the time node, the delay needs to be updated, and the link point time is ensured to be basically synchronous. Meanwhile, the delay value is not only cached in the memory, but also needs to be stored in the hard disk, so that the delay value is 0 when the node is restarted, and the time delay between the actual node and the time node is large, so that the node consensus abnormality is caused.
The node time inquiry sub-module provides a current node time inquiry interface for the link point, accumulates the server time now of the node and the latest synchronized time delay, and provides the accumulated time as the current node time of the node for other modules (a block packing module, a consensus verification module and the like) of the node.
A time node management contract module: the module is a time node management contract pre-compiled on the chain that primarily provides a way for nodes to select/switch time nodes.
The available time node set is maintained, and the current available time node set (availableNodeset), namely the common node set of the alliance chain, is maintained in the time node management contract. The common node set of the alliance chain ensures that only common nodes can participate in the time synchronization of the link points as time nodes, and the activity of the time nodes is ensured by the activity of the common nodes.
The time node pointer set is maintained, and three pointers, namely a current time node pointer (currentPointer), a switch time node pointer set (switchpointer) and a switch time node proposal time pointer (timepoint), are also maintained in the time node management contract. The current time node pointer represents a currently determined and operating time node, pointing to a node in the set of available time nodes. The set of switch time node pointers maintains the set of next time nodes currently being voted. The set is composed of map structures. The node pointer is a key of the map, points to nodes in the available time node set, and the number of node votes is the value of the map. Examples: if the available time node set availablenodeset= [ "node01", "node02", "node03", "node04", "node05" ], the current time node pointer currentpointer= "node01", the switch time node pointer set switchpointer= { "node02" [ "node02", "node04", "node05" ], "node03" [ "node03" ] ], which indicates that there are 3 consensus nodes ("node 02", "node04", "node 05") supporting node02 as the next round of time nodes, and 1 consensus node ("node 03") supporting node03 as the next round of time nodes, regarding the selection of the next round of time nodes. The switch time node proposal time pointer marks the time pointer of the next time node proposal for the first time, points to the first time node voting method and writes the time stamp of the transaction of the first item of the switch PointInterMap and the voted node. The example transaction tx invokes the time node voting method and selects to cast node02. When the node02 is written into the switchPointMap, if the switchPointMap is empty, a switching time node proposal time pointer timePoint= { tx. Timestamp, tx. Capacitor } is set. tx represents the transaction of the call contract method, tx.timestamp represents the timestamp of the transaction, and tx.caller represents the caller of the transaction.
The time node voting method is called by each node, and the nodes in the available time node set are voted to determine the next time node. In this method, the input parameter is a selected node, for example: "node02". When the method is executed, firstly, a caller of the contract method needs to be checked to check whether the contract caller is a consensus node, so that only nodes in the consensus node set are guaranteed to have authority to vote. It is then checked whether the contract caller repeatedly votes. If the repeated votes do not exist, increasing the number of votes of the corresponding item in the switchPointInterMap according to the selected node, namely adding voters. For example, the switchPointMap= { "node02": [ "node02", "node04" ], "node03": [ "node03" ] }, is modified to switchPointMap= { "node02": [ "node02", "node04", "node05" ], "node03": [ "node03" ] }. And finally, judging whether the time node in the switching time node pointer set switchPointMap is determined to be the next time node according to a time node determination algorithm. If the existing node is determined to be the next time node, a switch time node time event, such as switchNodeEvent { "node02" }, is thrown.
A time node determination algorithm in which three parameters are required: the switching time node proposes a time pointer timepoint, the number of nodes availableNodeNumber in the set of available time nodes, and a transaction timestamp currently calling the contract method. An expiration time threshold quality is set. If the difference of the current contract transaction timestamp minus the proposal time pointer timepoint with the switching time node is smaller than the expiration time threshold quality, counting the votes of all nodes in the switching time node pointer set switchpointer, and if the votes of the nodes are more than half of the total nodes in the available time node set, selecting the nodes as new time nodes. If the difference value is greater than or equal to the expiration time threshold quality, checking the votes of all the nodes in the switching time node pointer set switchPointMap, wherein the selected nodes with high number of votes are selected as time nodes, and if the number of votes is the same, the nodes which are proposed first are selected as the time nodes. The determination algorithm can determine the latest round of time nodes at the slowest after the expiration time threshold quality. The latest round of time nodes are determined, and a current time node pointer (currentPointer) maintained in the contract is updated.
And the time synchronization processing module is used for: the module mainly solves the problem of switching the time node in the next time view when the time node goes offline and other faults.
And the time node processing sub-module is used for checking whether the node is a determined next time node in the time event of the switching time node when the node receives the time event of the switching time node. If yes, sending a synchronization time message syncNodeMessage { txid, timestamp }, wherein txidetxid represents a transaction id of a switching time node proposal passing and triggering a switching time node time event, and timestamp represents the synchronization time of a new round of time nodes and is obtained by querying a time node module.
And the non-time node processing submodule is used for checking whether the node is a determined next time node in the time event of the switching time node when the node receives the time event of the switching time node. If not, waiting for receiving the synchronous time message syncNodeMessage of the new round time node. When the synchronous time message syncNodeMessage is received, it is verified whether txid is truly uplink. After verification is passed, comparing the time with the local server time to update the delay value in the node time module, and completing time synchronization. The above is a method of processing for nodes that are always in the blockchain network. For the nodes newly added into the network, the synchronization of the chain data is performed, but the synchronization time message syncNodeMessage cannot be received. Thus, an active polling-time approach is adopted. And after the synchronization is completed, inquiring a current time node pointer and an available time node set recorded in the time node management contract to acquire the current time node. Then constructs a request time message requestTimeMessage { from } and sends it to the time node. Where from represents the requesting time synchronization node. If the time node receives the requestTimeMessage message, it sends a synchronization time message syncNodeMessage { txid, timestamp }, to the requesting time synchronization node. After the request time synchronization node verifies that the message syncNodeMessage passes, the delay value in the node time module is updated, and the time synchronization is completed.
When the embodiment of the application is operated, the specific steps are as follows:
1. the user/contract invoker constructs a contract transaction to invoke a time node voting method in the time node management contract.
2. The node performs the transaction, i.e., performs a temporal node voting method.
3. Firstly, verifying whether a transaction caller is legal or not, namely judging whether the contract caller is in an available time node set or not;
4. then verifying whether the votes of the contract invoker are legal or not, namely judging whether repeated votes exist in the contract invoker or not;
5. if the verification is passed, updating the contract state switchPointmap and timepoint, adding votes, and carrying out the next operation. If the verification is not passed, the process is ended.
6. And judging whether the time difference between the transaction time stamp and the time difference in the switching time node proposal time pointer timepoint is greater than or equal to the expiration time threshold quality.
7. If yes, the time node is determined, and the current time node pointer (currentPointer) in the contract is updated. Otherwise, counting whether the vote can meet the condition of the node of the time of the resolution. If yes, updating a current time node pointer (currentPointer) in the contract, and continuing the next operation; if not, the process is ended.
8. And throwing out the switching time node event. The contract execution ends.
9. The node subscribes to a switching time node event, and first judges whether the time node recorded in the event is a local node.
10. If the node is a local node, the node sends a synchronous time message. Ending the flow. If not, waiting to receive the synchronization time message.
11. If the synchronous time message is received, the delay value in the node time module is updated, and the synchronization is completed. And if the synchronous time message is not received, sending a request time message to the time node. After receiving the replied synchronous time message, updating the delay value in the node time module to finish the synchronization. Ending the flow.
In summary, the link point time synchronization method based on the precompiled contract according to the embodiment of the present application may not change the local server time, so as to realize block link point time synchronization; meanwhile, the time node switching is triggered by the voting of the multiple consensus nodes, and the time node selection is flexible; the application realizes the clock synchronization and time node switching mechanism based on the precompiled contracts, has strong compatibility and low realization complexity.
In yet another aspect, the application also discloses a computer readable storage medium storing a computer program which, when executed by a processor, causes the processor to perform the steps of the method as described above.
In yet another aspect, the application also discloses a computer device comprising a memory and a processor, the memory storing a computer program which, when executed by the processor, causes the processor to perform the steps of the method as above.
In yet another embodiment of the present application, there is also provided a computer program product containing instructions that, when run on a computer, cause the computer to perform the link point time synchronization method of any of the above embodiments based on a precompiled contract.
It may be understood that the system provided by the embodiment of the present application corresponds to the method provided by the embodiment of the present application, and explanation, examples and beneficial effects of the related content may refer to corresponding parts in the above method.
The embodiment of the application also provides an electronic device, which comprises a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory are communicated with each other through the communication bus,
a memory for storing a computer program;
and the processor is used for realizing the chain link point time synchronization method based on the precompiled contracts when executing the programs stored in the memory.
The communication bus mentioned by the above electronic device may be a peripheral component interconnect standard (english: peripheral Component Interconnect, abbreviated: PCI) bus or an extended industry standard architecture (english: extended Industry Standard Architecture, abbreviated: EISA) bus, or the like. The communication bus may be classified as an address bus, a data bus, a control bus, or the like.
The communication interface is used for communication between the electronic device and other devices.
The Memory may include random access Memory (Random Access Memory, abbreviated as RAM) or nonvolatile Memory (NVM), such as at least one disk Memory. Optionally, the memory may also be at least one memory device located remotely from the aforementioned processor.
The processor may be a general-purpose processor, including a central processing unit (Central Processing Unit, CPU for short), a network processor (Network Processor, NP for short), etc.; it may also be a digital signal processor (English: digital Signal Processing; DSP; for short), an application specific integrated circuit (English: application Specific Integrated Circuit; ASIC; for short), a Field programmable gate array (English: field-Programmable Gate Array; FPGA; for short), or other programmable logic device, discrete gate or transistor logic device, discrete hardware components.
In the above embodiments, it may be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed on a computer, produces a flow or function in accordance with embodiments of the present application, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a computer network, or other programmable apparatus. The computer instructions may be stored in or transmitted from one computer-readable storage medium to another, for example, by wired (e.g., coaxial cable, optical fiber, digital Subscriber Line (DSL)), or wireless (e.g., infrared, wireless, microwave, etc.). The computer readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. that contains an integration of one or more available media. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid State Disk (SSD)), etc.
It is noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
In this specification, each embodiment is described in a related manner, and identical and similar parts of each embodiment are all referred to each other, and each embodiment mainly describes differences from other embodiments. In particular, for system embodiments, since they are substantially similar to method embodiments, the description is relatively simple, as relevant to see a section of the description of method embodiments.
The above embodiments are only for illustrating the technical solution of the present application, and are not limiting; although the application has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims (8)

1. The link point time synchronization method based on the precompiled contracts is characterized by comprising a link point time setting module, a time node management contract module and a time synchronization processing module;
maintaining the time of the chain node through a chain link point time module, and providing a current time inquiry interface on the chain;
a time node management contract module is used for pre-compiling a time node management contract on a chain, and the contract provides a path for selecting/switching time nodes for the nodes;
the problem of switching the time node in the next time view when the off-line fault occurs to the time node is solved through the time synchronization processing module;
the link point time module comprises a time delay value setting and maintaining sub-module and a node time query sub-module;
for the time delay value setting and maintaining submodule, the chain node does not only use the server time of the node, but also encapsulates a layer of time structure to represent the link point time; the method comprises the steps of including server time and time delay values, namely chainTime { no, delay }, wherein no represents the server time of the node, and delay represents the time delay with the time node; when time delay exists between the link node and the time node, the delay needs to be updated, so that the link point time is ensured to be basically synchronous; meanwhile, the delay value is not only cached in the memory, but also needs to be stored in the hard disk, so as to prevent the delay value from being 0 when the node is restarted;
the node time inquiry sub-module is used for providing a current node time inquiry interface for the link point by the link point time module, accumulating the server time now of the node and the latest synchronized time delay, and providing the accumulated time as the current node time of the node for other modules of the node.
2. The pre-compiling contract-based link point time synchronization method of claim 1, wherein: the time node management contract module comprises a current time node set maintenance, a time node pointer set maintenance, a time node voting method and a time node determining algorithm;
the current time node set is maintained, and a current available time node set, namely a common node set of a alliance chain, is maintained in a time node management contract; the common node set of the alliance chain ensures that only common nodes can participate in the time synchronization of the chain link points as time nodes, and the activity of the time nodes is ensured by the activity of the common nodes;
the time node pointer set is maintained, three pointers are also maintained in the time node management contract, and the current time node pointer currentPointer, the switching time node pointer set switchpointer and the switching time node proposal time pointer;
the current time node pointer currentPointer represents the currently determined and working time node and points to the nodes in the available time node set;
the switching time node pointer set switchPointMap maintains the next time node set which is currently being voted; the set is composed of map structures; the node pointer is a key of the map, points to nodes in the available time node set, and the number of node votes is a value of the map;
the switching time node proposal time pointer marks the time pointer of the first proposal of the next time node, points to the first calling time node voting method and writes the time stamp of the transaction of the first item of the switching time node pointer set switch point map and the voted node;
the time node voting method is called by each node, and votes are carried out on the nodes in the available time node set to determine the next time node;
finally, judging whether a time node in the switching time node pointer set switchPointMap is determined to be the next time node according to a time node determining algorithm; if the existing node is determined to be the next time node, the switching time node time event is thrown.
3. The pre-compiling contract-based link point time synchronization method of claim 2, wherein: the time node determining algorithm comprises three parameters: switching time node proposal time pointer, available time node number availableNodeNumber in the set of available time nodes and transaction timestamp of the current calling the contract method; setting an expiration time threshold quality;
if the difference of the current contract transaction timestamp minus the proposal time pointer timepoint with the switching time node is smaller than the expiration time threshold quality, counting the votes of all nodes in the switching time node pointer set switch point map, and if the votes of the nodes are more than half of the total node number in the available time node set, selecting the nodes as new time nodes;
if the difference value is greater than or equal to the expiration time threshold value quality, checking votes of all nodes in the switching time node pointer set switchPointMap, wherein the selected nodes with high number of votes are selected as time nodes, and if the same number of votes exists, the nodes which are proposed first are selected as the time nodes;
after the time node determining algorithm is slowest at the expiration time threshold quality, the latest round of time nodes can be determined; the latest round of time nodes are determined, and the current time node pointer currentPointer maintained in the contract is updated.
4. A pre-compiling contract-based link point time synchronization method according to claim 3, wherein: the time synchronization processing module is divided into a time node processing sub-module and a non-time node processing sub-module;
the time node processing sub-module is used for checking whether the node is a determined next time node in the time event of the switching time node when the node receives the time event of the switching time node, if so, sending a synchronous time message syncNodeMessage { txid, timestamp }, wherein txid represents transaction id of the switching time node when the proposal of the switching time node passes and triggers the time event of the switching time node, timestamp represents synchronous time of a new time node, and the synchronous time is obtained by querying the time node module;
the non-time node processing submodule is used for checking whether the node is a determined next time node in the switching time node time event when the node receives the switching time node time event for the node in the same block chain network all the time, and waiting for receiving a synchronous time message syncNodeMessage of the new time node if the node is not the determined next time node in the switching time node time event; when receiving a synchronous time message syncNodeMessage, verifying whether txid is truly uplink; after verification is passed, comparing the time with the local server time to update the delay value in the node time module, and completing time synchronization.
5. The pre-compiling contract-based link point time synchronization method of claim 4, wherein: the non-time node processing sub-module is used for synchronizing the link data of the nodes newly added into the network, but cannot receive the synchronous time message; then, an active polling mode is adopted, after synchronization is completed, a current time node pointer and an available time node set recorded in a time node management contract are inquired, a current time node is obtained, and then a request time message { from } is constructed and sent to the time node, wherein from represents the request time synchronization node; if the time node receives the request TimeMessage message, the time node sends a synchronous time message SyncNodeMessage { txid, timestamp } to the request time synchronization node; after the request time synchronization node verifies that the message syncNodeMessage passes, the delay value in the node time module is updated, and the time synchronization is completed.
6. A link point time synchronization method based on precompiled contracts is characterized in that: comprises the steps of,
s1, a user contract caller constructs a contract transaction to call a time node voting method in a time node management contract;
s2, executing the transaction by the node, namely executing a time node voting method;
s3, firstly verifying whether the transaction caller is legal or not, namely judging whether the contract caller is in the available time node set or not;
s4, verifying whether the voting of the contract caller is legal or not, namely judging whether repeated voting exists in the contract caller or not;
s5, if the verification is passed, updating a contract state, namely a switching time node pointer set switchpointer and a switching time node proposal time pointer timepoint, adding votes, carrying out the next operation, and if the verification is not passed, ending the flow;
s6, judging whether the time difference value between the transaction time stamp and the time pointer timepoint of the switching time node proposal is greater than or equal to the expiration time threshold quality;
s7, if yes, determining a time node, and updating a current time node pointer currentPointer in the contract; otherwise, counting whether the vote can meet the condition of the node of the time of the resolution; if yes, updating the current time node pointer currentPointer in the contract, and continuing the next operation; if not, ending the flow;
s8, throwing out a switching time node event, and ending contract execution;
s9, subscribing the node to a switching time node event, and firstly judging whether the time node recorded in the event is a local node or not;
s10, if the node is a local node, the node sends a synchronous time message, and the process is ended; if the node is not the local node, waiting for receiving the synchronous time message;
s11, if the synchronous time message is received, updating a delay value in a node time module to complete synchronization, and if the synchronous time message is not received, sending a request time message to a time node; after receiving the replied synchronous time message, updating the delay value in the node time module, completing the synchronization and ending the flow.
7. A computer device comprising a memory and a processor, the memory storing a computer program that, when executed by the processor, causes the processor to perform the steps of the method of any of claims 1 to 6.
8. A computer readable storage medium storing a computer program which, when executed by a processor, causes the processor to perform the steps of the method of any one of claims 1 to 6.
CN202310647296.5A 2023-06-02 2023-06-02 Link point time synchronization method, device and storage medium based on precompiled contracts Active CN116388921B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310647296.5A CN116388921B (en) 2023-06-02 2023-06-02 Link point time synchronization method, device and storage medium based on precompiled contracts

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310647296.5A CN116388921B (en) 2023-06-02 2023-06-02 Link point time synchronization method, device and storage medium based on precompiled contracts

Publications (2)

Publication Number Publication Date
CN116388921A CN116388921A (en) 2023-07-04
CN116388921B true CN116388921B (en) 2023-10-10

Family

ID=86971449

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310647296.5A Active CN116388921B (en) 2023-06-02 2023-06-02 Link point time synchronization method, device and storage medium based on precompiled contracts

Country Status (1)

Country Link
CN (1) CN116388921B (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2020160933A1 (en) * 2019-02-07 2020-08-13 International Business Machines Corporation Facilitating precision time protocol use in a coordinated timing network
CN111818185A (en) * 2020-08-31 2020-10-23 支付宝(杭州)信息技术有限公司 Method and device for starting intelligent contract, electronic equipment and storage medium
US11468089B1 (en) * 2021-02-19 2022-10-11 Sprint Communications Company L.P. Synchronization of distributed ledger processes
CN115860950A (en) * 2022-12-27 2023-03-28 浙江吉利控股集团有限公司 Contract transaction execution method and device, electronic equipment and readable storage medium
CN116017673A (en) * 2022-12-30 2023-04-25 中国联合网络通信集团有限公司 Time synchronization method and device among block chain multiple nodes

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9106353B2 (en) * 2011-12-13 2015-08-11 Jds Uniphase Corporation Time synchronization for network testing equipment
US11627003B2 (en) * 2018-03-05 2023-04-11 SmartAxiom, Inc. Systems and methods for a blockchain multi-chain smart contract time envelope
CN111814202B (en) * 2020-08-31 2020-12-11 支付宝(杭州)信息技术有限公司 Method for executing intelligent contract, block chain node and storage medium
CN111770201B (en) * 2020-08-31 2020-12-04 支付宝(杭州)信息技术有限公司 Data verification method, device and equipment

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2020160933A1 (en) * 2019-02-07 2020-08-13 International Business Machines Corporation Facilitating precision time protocol use in a coordinated timing network
CN111818185A (en) * 2020-08-31 2020-10-23 支付宝(杭州)信息技术有限公司 Method and device for starting intelligent contract, electronic equipment and storage medium
US11468089B1 (en) * 2021-02-19 2022-10-11 Sprint Communications Company L.P. Synchronization of distributed ledger processes
CN115860950A (en) * 2022-12-27 2023-03-28 浙江吉利控股集团有限公司 Contract transaction execution method and device, electronic equipment and readable storage medium
CN116017673A (en) * 2022-12-30 2023-04-25 中国联合网络通信集团有限公司 Time synchronization method and device among block chain multiple nodes

Also Published As

Publication number Publication date
CN116388921A (en) 2023-07-04

Similar Documents

Publication Publication Date Title
US10764369B2 (en) Data storage method and server applicable to distributed server cluster
WO2021233049A1 (en) Blockchain–based data processing method, apparatus, device, and readable storage medium
CN109788027B (en) Data synchronization method, device, server and computer storage medium
JP7401656B2 (en) METHODS, APPARATUS AND SYSTEM AND STORAGE MEDIA FOR SELECTING CLOCK SOURCES
CN106331046A (en) Cluster main node voting method and device
WO2014116527A1 (en) Method and system for using a recursive event listener on a node in hierarchical data structure
CN109167819B (en) Data synchronization system, method, device and storage medium
CN103488526A (en) System and method for locking business resource in distributed system
CN106612339A (en) Domain name updating method, system and main DNS (Domain Name System) server
CN104967536A (en) Method and device for realizing data consistency of multiple machine rooms
CN111461885A (en) Consensus network management method, device, computer and readable storage medium
CN111212135A (en) Message subscription method, device, system, electronic equipment and storage medium
GB2505229B (en) Upgrading nodes
CN112671908A (en) Network management method and device, electronic equipment and readable storage medium
CN114125812B (en) Data synchronization method, device, server and storage medium
CN116388921B (en) Link point time synchronization method, device and storage medium based on precompiled contracts
CN113271238B (en) Link detection method of EPA system, EPA device and computer medium
US20230360046A1 (en) Blockchain-based block processing method and apparatus, device, storage medium, and program product
US11194616B2 (en) Method, apparatus and system for simultaneously transmitting or receiving multiple managed objects
CN111182014A (en) Data synchronization method and device
CN115510161A (en) Data synchronization method, device, equipment and storage medium
WO2024221823A1 (en) Method and apparatus for data sending, device and storage medium
JP6043687B2 (en) Server / client system
CN111163088B (en) Message processing method, system and device and electronic equipment
CN115221245B (en) Intelligent data acquisition synchronization method, system and equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant