@@ -269,7 +269,7 @@ func (self *BlockChain) FastSyncCommitHead(hash common.Hash) error {
269269 if block == nil {
270270 return fmt .Errorf ("non existent block [%x…]" , hash [:4 ])
271271 }
272- if _ , err := trie .NewSecure (block .Root (), self .chainDb ); err != nil {
272+ if _ , err := trie .NewSecure (block .Root (), self .chainDb , 0 ); err != nil {
273273 return err
274274 }
275275 // If all checks out, manually set the head block
@@ -824,19 +824,16 @@ func (self *BlockChain) InsertChain(chain types.Blocks) (int, error) {
824824 // faster than direct delivery and requires much less mutex
825825 // acquiring.
826826 var (
827- stats struct { queued , processed , ignored int }
827+ stats = insertStats { startTime : time . Now () }
828828 events = make ([]interface {}, 0 , len (chain ))
829829 coalescedLogs vm.Logs
830- tstart = time .Now ()
831-
832- nonceChecked = make ([]bool , len (chain ))
830+ nonceChecked = make ([]bool , len (chain ))
833831 )
834832
835833 // Start the parallel nonce verifier.
836834 nonceAbort , nonceResults := verifyNoncesFromBlocks (self .pow , chain )
837835 defer close (nonceAbort )
838836
839- txcount := 0
840837 for i , block := range chain {
841838 if atomic .LoadInt32 (& self .procInterrupt ) == 1 {
842839 glog .V (logger .Debug ).Infoln ("Premature abort during block chain processing" )
@@ -931,7 +928,6 @@ func (self *BlockChain) InsertChain(chain types.Blocks) (int, error) {
931928 return i , err
932929 }
933930
934- txcount += len (block .Transactions ())
935931 // write the block to the chain and get the status
936932 status , err := self .WriteBlock (block )
937933 if err != nil {
@@ -966,19 +962,54 @@ func (self *BlockChain) InsertChain(chain types.Blocks) (int, error) {
966962 case SplitStatTy :
967963 events = append (events , ChainSplitEvent {block , logs })
968964 }
965+
969966 stats .processed ++
967+ if glog .V (logger .Info ) {
968+ stats .report (chain , i )
969+ }
970970 }
971971
972- if (stats .queued > 0 || stats .processed > 0 || stats .ignored > 0 ) && bool (glog .V (logger .Info )) {
973- tend := time .Since (tstart )
974- start , end := chain [0 ], chain [len (chain )- 1 ]
975- glog .Infof ("imported %d block(s) (%d queued %d ignored) including %d txs in %v. #%v [%x / %x]\n " , stats .processed , stats .queued , stats .ignored , txcount , tend , end .Number (), start .Hash ().Bytes ()[:4 ], end .Hash ().Bytes ()[:4 ])
976- }
977972 go self .postChainEvents (events , coalescedLogs )
978973
979974 return 0 , nil
980975}
981976
977+ // insertStats tracks and reports on block insertion.
978+ type insertStats struct {
979+ queued , processed , ignored int
980+ lastIndex int
981+ startTime time.Time
982+ }
983+
984+ const (
985+ statsReportLimit = 1024
986+ statsReportTimeLimit = 8 * time .Second
987+ )
988+
989+ // report prints statistics if some number of blocks have been processed
990+ // or more than a few seconds have passed since the last message.
991+ func (st * insertStats ) report (chain []* types.Block , index int ) {
992+ limit := statsReportLimit
993+ if index == len (chain )- 1 {
994+ limit = 0 // Always print a message for the last block.
995+ }
996+ now := time .Now ()
997+ duration := now .Sub (st .startTime )
998+ if duration > statsReportTimeLimit || st .queued > limit || st .processed > limit || st .ignored > limit {
999+ start , end := chain [st .lastIndex ], chain [index ]
1000+ txcount := countTransactions (chain [st .lastIndex : index + 1 ])
1001+ glog .Infof ("imported %d block(s) (%d queued %d ignored) including %d txs in %v. #%v [%x / %x]\n " , st .processed , st .queued , st .ignored , txcount , duration , end .Number (), start .Hash ().Bytes ()[:4 ], end .Hash ().Bytes ()[:4 ])
1002+ * st = insertStats {startTime : now , lastIndex : index }
1003+ }
1004+ }
1005+
1006+ func countTransactions (chain []* types.Block ) (c int ) {
1007+ for _ , b := range chain {
1008+ c += len (b .Transactions ())
1009+ }
1010+ return c
1011+ }
1012+
9821013// reorgs takes two blocks, an old chain and a new chain and will reconstruct the blocks and inserts them
9831014// to be part of the new canonical chain and accumulates potential missing transactions and post an
9841015// event about them
0 commit comments