X-Git-Url: http://git.osdn.net/view?p=bytom%2Fvapor.git;a=blobdiff_plain;f=netsync%2Fchainmgr%2Fblock_process.go;fp=netsync%2Fchainmgr%2Fblock_process.go;h=fac5cb51f328a7426a8cab5d637094cee23e2141;hp=2e6b41ea852fbbc266dc2d245b07cfd491d24807;hb=8643695a1ff4d574d231ef7ada1cde3bbc76404b;hpb=a1d6ba85cdcf3b2f1877a2bd252fa613ae6f7944 diff --git a/netsync/chainmgr/block_process.go b/netsync/chainmgr/block_process.go index 2e6b41ea..fac5cb51 100644 --- a/netsync/chainmgr/block_process.go +++ b/netsync/chainmgr/block_process.go @@ -13,7 +13,7 @@ import ( var errOrphanBlock = errors.New("fast sync inserting orphan block") type BlockProcessor interface { - process(chan struct{}, chan struct{}, *sync.WaitGroup) + process(chan struct{}, chan struct{}, uint64, *sync.WaitGroup) } type blockProcessor struct { @@ -43,7 +43,7 @@ func (bp *blockProcessor) insert(blockStorage *blockStorage) error { return err } -func (bp *blockProcessor) process(downloadNotifyCh chan struct{}, ProcessStop chan struct{}, wg *sync.WaitGroup) { +func (bp *blockProcessor) process(downloadNotifyCh chan struct{}, ProcessStop chan struct{}, syncHeight uint64, wg *sync.WaitGroup) { defer func() { close(ProcessStop) wg.Done() @@ -51,8 +51,7 @@ func (bp *blockProcessor) process(downloadNotifyCh chan struct{}, ProcessStop ch for { for { - nextHeight := bp.chain.BestBlockHeight() + 1 - block, err := bp.storage.readBlock(nextHeight) + block, err := bp.storage.readBlock(syncHeight) if err != nil { break } @@ -62,7 +61,8 @@ func (bp *blockProcessor) process(downloadNotifyCh chan struct{}, ProcessStop ch return } - bp.storage.deleteBlock(nextHeight) + bp.storage.deleteBlock(syncHeight) + syncHeight++ } if _, ok := <-downloadNotifyCh; !ok {