@@ -269,7 +269,7 @@ func (self *BlockChain) FastSyncCommitHead(hash common.Hash) error {
269
269
if block == nil {
270
270
return fmt .Errorf ("non existent block [%x…]" , hash [:4 ])
271
271
}
272
- if _ , err := trie .NewSecure (block .Root (), self .chainDb ); err != nil {
272
+ if _ , err := trie .NewSecure (block .Root (), self .chainDb , 0 ); err != nil {
273
273
return err
274
274
}
275
275
// If all checks out, manually set the head block
@@ -824,19 +824,16 @@ func (self *BlockChain) InsertChain(chain types.Blocks) (int, error) {
824
824
// faster than direct delivery and requires much less mutex
825
825
// acquiring.
826
826
var (
827
- stats struct { queued , processed , ignored int }
827
+ stats = insertStats { startTime : time . Now () }
828
828
events = make ([]interface {}, 0 , len (chain ))
829
829
coalescedLogs vm.Logs
830
- tstart = time .Now ()
831
-
832
- nonceChecked = make ([]bool , len (chain ))
830
+ nonceChecked = make ([]bool , len (chain ))
833
831
)
834
832
835
833
// Start the parallel nonce verifier.
836
834
nonceAbort , nonceResults := verifyNoncesFromBlocks (self .pow , chain )
837
835
defer close (nonceAbort )
838
836
839
- txcount := 0
840
837
for i , block := range chain {
841
838
if atomic .LoadInt32 (& self .procInterrupt ) == 1 {
842
839
glog .V (logger .Debug ).Infoln ("Premature abort during block chain processing" )
@@ -931,7 +928,6 @@ func (self *BlockChain) InsertChain(chain types.Blocks) (int, error) {
931
928
return i , err
932
929
}
933
930
934
- txcount += len (block .Transactions ())
935
931
// write the block to the chain and get the status
936
932
status , err := self .WriteBlock (block )
937
933
if err != nil {
@@ -966,19 +962,54 @@ func (self *BlockChain) InsertChain(chain types.Blocks) (int, error) {
966
962
case SplitStatTy :
967
963
events = append (events , ChainSplitEvent {block , logs })
968
964
}
965
+
969
966
stats .processed ++
967
+ if glog .V (logger .Info ) {
968
+ stats .report (chain , i )
969
+ }
970
970
}
971
971
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
- }
977
972
go self .postChainEvents (events , coalescedLogs )
978
973
979
974
return 0 , nil
980
975
}
981
976
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
+
982
1013
// reorgs takes two blocks, an old chain and a new chain and will reconstruct the blocks and inserts them
983
1014
// to be part of the new canonical chain and accumulates potential missing transactions and post an
984
1015
// event about them
0 commit comments