File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -650,6 +650,33 @@ func (bs *BlockService) ScanBlockPool() error {
650
650
}
651
651
}
652
652
}
653
+ // check if we have passed the last blocksmith expiry time
654
+ numberOfBlocksmiths := len (bs .BlocksmithStrategy .GetSortedBlocksmithsMap (previousBlock ))
655
+ lastBlocksmithExpiry := bs .BlocksmithStrategy .GetSmithTime (int64 (numberOfBlocksmiths - 1 ), previousBlock ) +
656
+ constant .SmithingBlockCreationTime + constant .SmithingNetworkTolerance
657
+ if len (blocks ) > 0 &&
658
+ time .Now ().Unix () > lastBlocksmithExpiry {
659
+ // choose block to persist since all blocksmith time has expired
660
+ var (
661
+ bestIndex int64
662
+ bestCumDiff = new (big.Int ).SetInt64 (0 )
663
+ )
664
+ for index , block := range blocks {
665
+ currBlockCumDiff , _ := new (big.Int ).SetString (block .GetCumulativeDifficulty (), 10 )
666
+ if currBlockCumDiff .Cmp (bestCumDiff ) > 0 {
667
+ bestCumDiff = currBlockCumDiff
668
+ bestIndex = index
669
+ }
670
+ }
671
+ bs .ChainWriteLock (constant .BlockchainStatusReceivingBlock )
672
+ err := bs .PushBlock (previousBlock , blocks [bestIndex ], true , true )
673
+ bs .ChainWriteUnlock (constant .BlockchainStatusReceivingBlock )
674
+ if err != nil {
675
+ return blocker .NewBlocker (
676
+ blocker .BlockErr , "ScanBlockPool:PushBlockFail" ,
677
+ )
678
+ }
679
+ }
653
680
return nil
654
681
}
655
682
You can’t perform that action at this time.
0 commit comments