9
9
10
10
"github.com/vitelabs/go-vite/v2/common"
11
11
"github.com/vitelabs/go-vite/v2/common/types"
12
+ "github.com/vitelabs/go-vite/v2/common/upgrade"
12
13
ledger "github.com/vitelabs/go-vite/v2/interfaces/core"
13
14
"github.com/vitelabs/go-vite/v2/ledger/pool/batch"
14
15
"github.com/vitelabs/go-vite/v2/ledger/pool/tree"
@@ -78,6 +79,14 @@ func (sb *snapshotPoolBlock) Owner() *types.Address {
78
79
return nil
79
80
}
80
81
82
+ func (sb snapshotPoolBlock ) Ready () bool {
83
+ // If a block comes from the future with a maximum error of one second, then it is illegal.
84
+ if sb .block .Timestamp .After (time .Now ().Add (time .Second )) {
85
+ return false
86
+ }
87
+ return true
88
+ }
89
+
81
90
func newSnapshotPool (
82
91
name string ,
83
92
version * common.Version ,
@@ -218,7 +227,8 @@ func (sp *snapshotPool) loopCompactSnapshot() int {
218
227
sp .chainHeadMu .Lock ()
219
228
defer sp .chainHeadMu .Unlock ()
220
229
sum := 0
221
- sp .loopGenSnippetChains ()
230
+ // Starting from version 13, consider whether the block is ready when filtering.
231
+ sp .loopGenSnippetChains (upgrade .IsVersion13Upgrade (sp .rw .headSnapshot ().Height ))
222
232
sum += sp .loopAppendChains ()
223
233
now := time .Now ()
224
234
if now .After (sp .nextFetchTime ) {
@@ -343,49 +353,49 @@ func (sp *snapshotPool) loopFetchForSnapshot() {
343
353
return
344
354
}
345
355
346
- //func (self *snapshotPool) makeQueue(q Package, info *offsetInfo) (uint64, error) {
347
- // self.pool.RLock()
348
- // defer self.pool.RUnLock()
349
- // self.rMu.Lock()
350
- // defer self.rMu.Unlock()
356
+ // func (self *snapshotPool) makeQueue(q Package, info *offsetInfo) (uint64, error) {
357
+ // self.pool.RLock()
358
+ // defer self.pool.RUnLock()
359
+ // self.rMu.Lock()
360
+ // defer self.rMu.Unlock()
351
361
//
352
- // cp := self.chainpool
353
- // current := cp.current
362
+ // cp := self.chainpool
363
+ // current := cp.current
354
364
//
355
- // if info.offset == nil {
356
- // info.offset = &ledger.HashHeight{Hash: current.tailHash, Height: current.tailHeight}
357
- // } else {
358
- // block := current.getBlock(info.offset.Height+1, false)
359
- // if block == nil || block.PrevHash() != info.offset.Hash {
360
- // return uint64(0), errors.New("current chain modify.")
365
+ // if info.offset == nil {
366
+ // info.offset = &ledger.HashHeight{Hash: current.tailHash, Height: current.tailHeight}
367
+ // } else {
368
+ // block := current.getBlock(info.offset.Height+1, false)
369
+ // if block == nil || block.PrevHash() != info.offset.Hash {
370
+ // return uint64(0), errors.New("current chain modify.")
371
+ // }
361
372
// }
362
- // }
363
373
//
364
- // minH := info.offset.Height + 1
365
- // headH := current.headHeight
366
- // for i := minH; i <= headH; i++ {
367
- // block := self.getCurrentBlock(i)
368
- // if block == nil {
369
- // return uint64(i - minH), errors.New("current chain modify")
370
- // }
374
+ // minH := info.offset.Height + 1
375
+ // headH := current.headHeight
376
+ // for i := minH; i <= headH; i++ {
377
+ // block := self.getCurrentBlock(i)
378
+ // if block == nil {
379
+ // return uint64(i - minH), errors.New("current chain modify")
380
+ // }
371
381
//
372
- // if self.hashBlacklist.Exists(block.Hash()) {
373
- // return uint64(i - minH), errors.New("block in blacklist")
374
- // }
382
+ // if self.hashBlacklist.Exists(block.Hash()) {
383
+ // return uint64(i - minH), errors.New("block in blacklist")
384
+ // }
375
385
//
376
- // item := NewItem(block, nil)
386
+ // item := NewItem(block, nil)
377
387
//
378
- // err := q.AddItem(item)
379
- // if err != nil {
380
- // return uint64(i - minH), err
388
+ // err := q.AddItem(item)
389
+ // if err != nil {
390
+ // return uint64(i - minH), err
391
+ // }
392
+ // info.offset.Hash = item.Hash()
393
+ // info.offset.Height = item.Height()
381
394
// }
382
- // info.offset.Hash = item.Hash()
383
- // info.offset.Height = item.Height()
384
- // }
385
395
//
386
- // return uint64(headH - minH), errors.New("all in")
396
+ // return uint64(headH - minH), errors.New("all in")
387
397
//
388
- //}
398
+ // }
389
399
func (sp * snapshotPool ) getCurrentBlock (i uint64 ) * snapshotPoolBlock {
390
400
b := sp .CurrentChain ().GetKnot (i , false )
391
401
if b != nil {
@@ -394,16 +404,16 @@ func (sp *snapshotPool) getCurrentBlock(i uint64) *snapshotPoolBlock {
394
404
return nil
395
405
}
396
406
397
- //func (self *snapshotPool) getPendingForCurrent() ([]commonBlock, error) {
398
- // begin := self.chainpool.current.tailHeight + 1
399
- // blocks := self.chainpool.getCurrentBlocks(begin, begin+10)
400
- // err := self.checkChain(blocks)
401
- // if err != nil {
402
- // return nil, err
403
- // }
407
+ // func (self *snapshotPool) getPendingForCurrent() ([]commonBlock, error) {
408
+ // begin := self.chainpool.current.tailHeight + 1
409
+ // blocks := self.chainpool.getCurrentBlocks(begin, begin+10)
410
+ // err := self.checkChain(blocks)
411
+ // if err != nil {
412
+ // return nil, err
413
+ // }
404
414
//
405
- // return blocks, nil
406
- //}
415
+ // return blocks, nil
416
+ // }
407
417
func (sp * snapshotPool ) fetchAccounts (accounts map [types.Address ]* ledger.HashHeight , sHeight uint64 , sHash types.Hash ) {
408
418
for addr , hashH := range accounts {
409
419
ac := sp .pool .selfPendingAc (addr )
0 commit comments