Summary of the invention
The present invention provides a kind of method of inspection, device, equipment and storage medium that local block is synchronous, to detect local number
It according to the block data in library, is compensated to block is lost, to keep the integrality of local block data.
In a first aspect, the embodiment of the present invention provides a kind of method of inspection that the local block based on block chain is synchronous, comprising:
Obtain the current block chain block height and detection starting point height of block chain;
It successively traverses in the local block stored in local data base from the detection starting point height to the current block
Block between chain block height;
If detecting the presence of loss block, the loss block is obtained from the block chain, and be stored in local block phase
At the block height answered.
Further, the current block chain block height for obtaining block chain and detection starting point height are specific to wrap
It includes:
The current block chain block height of the block chain is periodically acquired with the first prefixed time interval;
The above cycle detection terminal height is as the detection starting point height;Wherein with first area in the period 1
Block is as the detection starting point height.
Further, it is described successively traverse in local data base in the local block that stores from the detection starting point height to
Block between the current block chain block height, specifically includes:
Block corresponding with the detection starting point height in the local block is detected;
By the detection starting point height, count is incremented if detection block is not lost;
Circulation executes until detection starting point height reaches the current block chain block height.
Further, it is described successively traverse in local data base in the local block that stores from the detection starting point height to
Block between the current block chain block height, comprising:
In successively ergodic process, parses and correspond to block in the either block and block chain of local block and compared
It is right, it is judged as loss block if comparison result is inconsistent.
Further, the method also includes:
The synchronization notice that the block chain is sent in newly-increased block is received, newly-increased block is synchronized to the local data
In library;Or
The current block chain block height and local block of the block chain are periodically acquired with the second prefixed time interval
Highly, if local block height is less than current block chain block height, it is high that the block chain is obtained into current block chain block
Block between degree and local block height is synchronized in the local data base.
Further, in block synchronizing process further include:
It is that each local block establishes unique index in the local data base, to identify in its area in local block
Block height.
Second aspect, the embodiment of the present invention provide a kind of verifying attachment that the local block based on block chain is synchronous, comprising:
Module is obtained, for obtaining the current block chain block height and detection starting point height of block chain;
Processing module, for successively traverse in the local block stored in local data base from the detection starting point height to
Block between the current block chain block height;
Synchronization module, if obtaining the loss block from the block chain, and store for detecting the presence of loss block
At the corresponding block height of local block.
Further, the acquisition module is used for:
The current block chain block height of the block chain is periodically acquired with the first prefixed time interval;
The above cycle detection terminal height is as the detection starting point height;Wherein with first area in the period 1
Block is as the detection starting point height.
Further, the processing module is specifically used for:
Block corresponding with the detection starting point height in the local block is detected;
By the detection starting point height, count is incremented if detection block is not lost;
Circulation executes until detection starting point height reaches the current block chain block height.
Further, the processing module is used for:
In successively ergodic process, parses and correspond to block in the either block and block chain of local block and compared
It is right, it is judged as loss block if comparison result is inconsistent.
Further, the synchronization module is also used to:
The synchronization notice that the block chain is sent in newly-increased block is received, newly-increased block is synchronized to the local data
In library;Or
The current block chain block height and local block of the block chain are periodically acquired with the second prefixed time interval
Highly, if local block height is less than current block chain block height, it is high that the block chain is obtained into current block chain block
Block between degree and local block height is synchronized in the local data base.
Further, the synchronization module is also used to,
In block synchronizing process, it is that each local block establishes unique index in the local data base, is existed with mark
Its block height in local block.
The third aspect, the embodiment of the present invention provide a kind of inspection equipment that the local block based on block chain is synchronous, comprising:
Memory;
Processor;And
Computer program;
Wherein, the computer program stores in the memory, and is configured as being executed by the processor with reality
Now method as described in relation to the first aspect.
Fourth aspect, the embodiment of the present invention provide a kind of computer readable storage medium, are stored thereon with computer program;
The computer program realizes method according to any one of claims 1 to 5 when being executed by processor.
Local the block provided in an embodiment of the present invention synchronous method of inspection, device, equipment and storage medium, pass through acquisition
The current block chain block height and detection starting point height of block chain;It successively traverses in local block from detection starting point height
Block between current block chain block height;If detecting the presence of loss block, the loss block is obtained from block chain,
And it is stored at the corresponding block height of local block.The embodiment of the present invention loses area by traversing local block to detect
Block, and compensated to block is lost, so that local block data is consistent with data on block chain, guarantee local block counts
According to integrality.
Specific embodiment
Following will be combined with the drawings in the embodiments of the present invention, and technical solution in the embodiment of the present invention carries out clear, complete
Site preparation description, it is clear that described embodiments are only a part of the embodiments of the present invention, instead of all the embodiments.It is based on
Embodiment in the present invention, it is obtained by those of ordinary skill in the art without making creative efforts every other
Embodiment shall fall within the protection scope of the present invention.
Fig. 1 is the synchronous method of inspection flow chart of the local block provided in an embodiment of the present invention based on block chain.This reality
It applies example and provides a kind of method of inspection that the local block based on block chain is synchronous, specific step is as follows for this method:
S101, the current block chain block height for obtaining block chain and detection starting point height.
In the present embodiment, block height is the serial number for the block being connected on block chain, can be used as the unique of block
Identifier indicates position of the block in block chain, and block height is since 0.And the block chain that the present embodiment obtains is current
The block height of current most newly generated block in block chain block height namely block chain.In addition, also being needed in the present embodiment
Detection starting point height is obtained, namely local block is detected since detecting starting point height, until detecting described current
Until block chain block height namely current block chain block height is detection terminal height.Wherein detection starting point height can be with
It is set, for example, if desired block all on block chain is synchronized by local data base, is then detected as needed
Point height is the corresponding block height of first block;If local data base only synchronize block chain on newest several blocks or
Newest several blocks are only needed to detect that with the presence or absence of losing, then the range setting detection starting point height detected as needed;It is right
In periodic Detection task, the detection starting point height in this period can be the detection terminal height in a upper period, can will be every
The detection starting point height and detection terminal height in one period are stored in local data base, when the starting of this period from local data base
The detection terminal height in a period in middle reading;In addition, in periodic Detection task, it can also every detection in ergodic process
One block updates one-time detection starting point height, arrives current block chain block height until updating, at this time newest detection starting point
Height is detection terminal height, can be used as the detection starting point height in next period.It furthermore it should be noted that can not also be to work as
Preceding block sequence block height is as detection terminal, but separately setting detection terminal height, namely only detects among local block
Certain blocks are with the presence or absence of loss.It needs constantly to carry out since block is synchronous under normal conditions, the present embodiment is preferably
Using current block chain block height as detection terminal.
S102, successively traverse in local data base in the local block that stores from the detection starting point height to it is described currently
Block between block chain block height.
In the present embodiment, for local block, each block is successively traversed since detecting starting point height up to current
Until block chain block height, wherein ergodic process can be local no in the presence of area corresponding with block height for only detection
Whether block namely block are lost, and can also more specifically detect in a certain block whether have loss of data.
If S103, detecting the presence of loss block, the loss block is obtained from the block chain, and be stored in this area
At the corresponding block height of block.
In the present embodiment, when detecting the presence of the case where losing block, then re-synchronization loss block, namely from area
Block chain reacquires the corresponding block of loss block, and is stored at the corresponding block height of local block.It needs to illustrate
The case where being, block is lost shown in the present embodiment, including entire block are lost, and may include losing number in some block
According to the case where.
The synchronous method of inspection of local block provided in this embodiment based on block chain, by obtaining the current of block chain
Block chain block height and detection starting point height;It successively traverses in local block from detection starting point height to current block chain
Block between block height;If detecting the presence of loss block, the loss block is obtained from block chain, and be stored in local
At the corresponding block height of block.The present embodiment detects loss block by traversing local block, and to lose block into
Row compensation guarantees the integrality of local block data so that local block data is consistent with data on block chain.
On the basis of the above embodiments, the current block chain block height and detection of block chain are obtained described in S101
Starting point height, specifically can include:
The current block chain block height of the block chain is periodically acquired with the first prefixed time interval;
The above cycle detection terminal height is as the detection starting point height;Wherein with first area in the period 1
Block is as the detection starting point height.
It, can be by setting the first prefixed time interval, to realize step shown in above-mentioned S101-S103 in the present embodiment
Periodic cycle executes.Specifically, the current block chain block height of block chain is obtained when the first detection cycle starts, and
Using first block as detection starting point height, to successively traverse in local block from first block to current block sequence
Block between block height is lost block if it exists and is then compensated to loss block;When the second detection cycle starts, obtain
The current block chain block height of block chain at this time, due to having had detected a part of local block in the period 1,
Second round only needs the detection terminal height of then period 1 to continue to test, and also will detect terminal height the period 1
Spend detection starting point height as second round, such as a upper cycle detection to third block, then this period is with third block
Starting point height is detected, the 4th block, the 5th block and subsequent block are successively traversed.Periodic cycle through this embodiment,
The newest local block for being synchronized to local data base is constantly detected to realize, guarantees timely to compensate loss block,
Guarantee the integrality of local block data.
In the present embodiment, ergodic process is specifically as follows:
Block corresponding with the detection starting point height in the local block is detected;
By the detection starting point height, count is incremented if detection block is not lost;If detecting certainly, block is lost,
By the detection starting point height, count is incremented after the re-synchronization loss block;
Circulation executes until detection starting point height reaches the current block chain block height.
In the present embodiment, when detection starting point height reaches the current block chain block height in this period, that is, reach this
The detection terminal in period can be used as the detection starting point height of next detection cycle.
Further, it is successively traversed described in S102 in the local block stored in local data base from the detection starting point
Height arrives the block between the current block chain block height, comprising:
In successively ergodic process, parses and correspond to block in the either block and block chain of local block and compared
It is right, it is judged as loss block if comparison result is inconsistent.
In the present embodiment, in order to guarantee that local block internal data also can be with the inside number that corresponds to block on block chain
According to consistent, therefore local block can be parsed in ergodic process, while parsing and corresponding to block on block chain, compare parsing
As a result, judging that the block internal data goes out active, therefore be also judged as loss block, the area Bing Duigai if result is inconsistent
Block carries out re-synchronization.In the present embodiment, ergodic process specifically can first detect whether a certain block height is sky, if it is empty then
Directly it is judged as that block is lost, carries out re-synchronization;If not empty, then further progress block analysis and comparison, and if block
The parsing result of block on chain is inconsistent, then judges to lose data inside the block, carry out re-synchronization;If not empty, and
Parsing result is consistent, then updates the detection that detection starting point height carries out block height.In the present embodiment, parsing can be solved only
The important information in block, such as Transaction Information are analysed, to improve resolution speed, and then shortens duration used in ergodic process, mentions
High detection efficiency.
Further, the detection process in the present embodiment and the synchronizing process of block do not clash, and can parallel may be used
Serially.Wherein the synchronizing process of block may include the following two kinds scheme:
Scheme one: receiving the synchronization notice that the block chain is sent in newly-increased block, newly-increased block is synchronized to described
In local data base.
In scheme one, using the passively method of synchronization, namely when block chain increases block newly, sent out to local device
Synchronization notice is sent, wherein may include that information, the local devices such as the block height of newly-increased block are logical according to synchronizing in synchronization notice
Know and obtain newly-increased block from block chain, and store into local data base, to realize the synchronization of local block.
Scheme two: the current block chain block height and sheet of the block chain are periodically acquired with the second prefixed time interval
The block chain is obtained current block chain if local block height is less than current block chain block height by ground block height
Block between block height and local block height is synchronized in the local data base.
In scheme two, the synchronizing process of block is realized by timed task, namely at predetermined intervals periodically
The current block chain block height and local block height of block chain are obtained, and judges the current block chain block height of block chain
Size between local block height illustrates if local block height is less than current block chain block height upper one
Secondary completion synchronizes rear block chain and increases block newly, then local device obtains newly-increased block namely block chain obtains current block sequence
Block between block height and local block height, and store into local data base, to realize the synchronization of local block.It needs
It is noted that the second prefixed time interval can it is identical as the first prefixed time interval can also be different, can be according to actual needs
It is set.
Fig. 2 is the synchronous method of inspection flow chart of the local block provided in an embodiment of the present invention based on block chain, Fig. 3 a
For the schematic diagram for examining preceding local data base and block chain, Fig. 3 b is local data base and block chain after executing process shown in Fig. 2
Schematic diagram.As shown in Fig. 2, the method for inspection synchronous another embodiment of the present invention provides a kind of local block of block chain, inspection
Survey process and the synchronizing process of block serially execute, and first carry out the synchronization of block, then carry out detection process.This method specifically flows
Journey is as follows:
S201, first setting check starting point height (checkpoint is denoted as cp), and initial value is -1;
S202, starting timed task;
S203, setting i=cp+1, namely detected block 0 since Fig. 3 a;
S204, current block chain block height H is obtained;
S205, local block height h is obtained;
S206, judge whether h is less than H, if so then execute S207, if otherwise executing S208;
Block between S207, synchronous h to H;
S208, judge to detect whether i is greater than H, if then terminating, illustrate block before i after testing, if it is not, then
Execute S209;
S209, local block i is checked;
S2010, judge whether local block i is empty, if so, illustrating that block i loses, S2011 is executed, if it is not, then saying
Area pellucida block i does not lose, executes S2013;
S2011, synchronous block i;
S2012, judge whether block i synchronizes success, if so then execute S2013, if otherwise re-executing S2011;
S2013, update cp are i;
S2014, update i are i+1, and return to 8.
It should be noted that cp does not need to reset after the completion of this timed task, in order to the starting of next timed task
When, continue from cp current value.
The synchronous method of inspection of local block provided in an embodiment of the present invention based on block chain, is the one of above-described embodiment
The achievable scheme of kind, concrete function and effect are same as the previously described embodiments, and details are not described herein again.
The synchronous method of inspection of local block provided in this embodiment based on block chain, carries out after synchronizing local block
The inspection of block by traversing local block to detect loss block, and is compensated to block is lost, so that local block
Data are consistent with data on block chain, guarantee the integrality of local block data.
Fig. 4 is the structure chart of the synchronous verifying attachment of the local block provided in an embodiment of the present invention based on block chain.This
It is same that the synchronous verifying attachment of the local block based on block chain that embodiment provides can execute the local block based on block chain
The process flow that the method for inspection embodiment of step provides, as shown in figure 4, the inspection that the local block based on block chain is synchronous
Device 30 includes obtaining module 31, processing module 32 and synchronization module 33.
Wherein, module 31 is obtained, for obtaining current block chain block height and detection starting point height;
Processing module 32, for successively traversing in the local block stored in local data base from the detection starting point height
Block between the current block chain block height;
Synchronization module 33, if obtaining the loss block from the block chain, and deposit for detecting the presence of loss block
Storage is at the corresponding block height of local block.
Further, the acquisition module 31 is used for:
The current block chain block height of the block chain is periodically acquired with the first prefixed time interval;
The above cycle detection terminal height is as the detection starting point height;Wherein with first area in the period 1
Block is as the detection starting point height.
Further, the processing module 32 is specifically used for:
Block corresponding with the detection starting point height in the local block is detected;
By the detection starting point height, count is incremented if detection block is not lost;
Circulation executes until detection starting point height reaches the current block chain block height.
Further, the processing module 32 is used for:
In successively ergodic process, parses and correspond to block in the either block and block chain of local block and compared
It is right, it is judged as loss block if comparison result is inconsistent.
Further, the synchronization module 33 is also used to:
The synchronization notice that the block chain is sent in newly-increased block is received, newly-increased block is synchronized to the local data
In library;Or
The current block chain block height and local block of the block chain are periodically acquired with the second prefixed time interval
Highly, if local block height is less than current block chain block height, it is high that the block chain is obtained into current block chain block
Block between degree and local block height is synchronized in the local data base.
Further, the synchronization module 33 is also used to,
In block synchronizing process, it is that each local block establishes unique index in the local data base, is existed with mark
Its block height in local block.
The synchronous verifying attachment of local block provided in an embodiment of the present invention based on block chain can be specifically used for executing
Embodiment of the method provided by above-mentioned Fig. 1 and Fig. 2, details are not described herein again for concrete function.
The synchronous verifying attachment of local block provided in an embodiment of the present invention based on block chain, by obtaining current block
Chain block height and detection starting point height;It successively traverses in the local block stored in local data base from detection high starting point
Spend the block between current block chain block height;If detecting the presence of loss block, the loss area is obtained from block chain
Block, and be stored at the corresponding block height of local block.The present embodiment by traversing local block to detect loss block,
And compensated to block is lost, so that local block data is consistent with data on block chain, guarantee local block data
Integrality.
Fig. 5 be another embodiment of the present invention provides the synchronous inspection equipment of local block based on block chain structure
Figure.As shown in figure 5, the inspection equipment 40 that the local block that the present embodiment provides a kind of based on block chain is synchronous, the equipment 40
It include: processor 41;Memory 42;And computer program.
Wherein, the computer program is stored in the memory 42, and is configured as being executed by the processor 41
To realize the process flow of the offer of the embodiment of the method as provided by Fig. 1 or Fig. 2, details are not described herein again for concrete function.
More specifically, the equipment 40 further includes receiver 43 and transmitter 44, receiver 43 and transmitter 44, processor
41 are connected with memory 42 by bus.
In addition, the present embodiment also provides a kind of computer readable storage medium, it is stored thereon with computer program, the meter
Calculation machine program is executed by processor the method for inspection to realize the local block synchronization described in above-described embodiment based on block chain.
In several embodiments provided by the present invention, it should be understood that disclosed device and method can pass through it
Its mode is realized.For example, the apparatus embodiments described above are merely exemplary, for example, the division of the unit, only
Only a kind of logical function partition, there may be another division manner in actual implementation, such as multiple units or components can be tied
Another system is closed or is desirably integrated into, or some features can be ignored or not executed.Another point, it is shown or discussed
Mutual coupling, direct-coupling or communication connection can be through some interfaces, the INDIRECT COUPLING or logical of device or unit
Letter connection can be electrical property, mechanical or other forms.
The unit as illustrated by the separation member may or may not be physically separated, aobvious as unit
The component shown may or may not be physical unit, it can and it is in one place, or may be distributed over multiple
In network unit.It can select some or all of unit therein according to the actual needs to realize the mesh of this embodiment scheme
's.
It, can also be in addition, the functional units in various embodiments of the present invention may be integrated into one processing unit
It is that each unit physically exists alone, can also be integrated in one unit with two or more units.Above-mentioned integrated list
Member both can take the form of hardware realization, can also realize in the form of hardware adds SFU software functional unit.
The above-mentioned integrated unit being realized in the form of SFU software functional unit can store and computer-readable deposit at one
In storage media.Above-mentioned SFU software functional unit is stored in a storage medium, including some instructions are used so that a computer
It is each that equipment (can be personal computer, server or the network equipment etc.) or processor (processor) execute the present invention
The part steps of embodiment the method.And storage medium above-mentioned includes: USB flash disk, mobile hard disk, read-only memory (Read-
Only Memory, ROM), random access memory (Random Access Memory, RAM), magnetic or disk etc. it is various
It can store the medium of program code.
Those skilled in the art can be understood that, for convenience and simplicity of description, only with above-mentioned each functional module
Division progress for example, in practical application, can according to need and above-mentioned function distribution is complete by different functional modules
At the internal structure of device being divided into different functional modules, to complete all or part of the functions described above.On
The specific work process for stating the device of description, can refer to corresponding processes in the foregoing method embodiment, and details are not described herein.
Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention., rather than its limitations;To the greatest extent
Pipe present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that: its according to
So be possible to modify the technical solutions described in the foregoing embodiments, or to some or all of the technical features into
Row equivalent replacement;And these are modified or replaceed, various embodiments of the present invention technology that it does not separate the essence of the corresponding technical solution
The range of scheme.