@@ -115,15 +115,13 @@ func newBlockfileMgr(id string, conf *Conf, indexConfig *blkstorage.IndexConfig,
115
115
panic (fmt .Sprintf ("Could not get block file info for current block file from db: %s" , err ))
116
116
}
117
117
if cpInfo == nil {
118
- logger .Info (`No info about blocks file found in the db.
119
- This could happen if this is the first time the ledger is constructed or the index is dropped.
120
- Scanning blocks dir for the latest info` )
118
+ logger .Info (`Getting block information from block storage` )
121
119
if cpInfo , err = constructCheckpointInfoFromBlockFiles (rootDir ); err != nil {
122
120
panic (fmt .Sprintf ("Could not build checkpoint info from block files: %s" , err ))
123
121
}
124
- logger .Infof ("Info constructed by scanning the blocks dir = %s" , spew .Sdump (cpInfo ))
122
+ logger .Debugf ("Info constructed by scanning the blocks dir = %s" , spew .Sdump (cpInfo ))
125
123
} else {
126
- logger .Info (`Synching the info about block files ` )
124
+ logger .Debug (`Synching block information from block storage (if needed) ` )
127
125
syncCPInfoFromFS (rootDir , cpInfo )
128
126
}
129
127
err = mgr .saveCurrentInfo (cpInfo , true )
@@ -153,18 +151,15 @@ func newBlockfileMgr(id string, conf *Conf, indexConfig *blkstorage.IndexConfig,
153
151
// or announcing the occurrence of an event.
154
152
mgr .cpInfoCond = sync .NewCond (& sync.Mutex {})
155
153
156
- // Verify that the index stored in db is accurate with what is actually stored in block file system
157
- // If not the same, sync the index and the file system
158
- mgr .syncIndex ()
159
-
160
154
// init BlockchainInfo for external API's
161
155
bcInfo := & common.BlockchainInfo {
162
156
Height : 0 ,
163
157
CurrentBlockHash : nil ,
164
158
PreviousBlockHash : nil }
165
159
166
- //If start up is a restart of an existing storage, update BlockchainInfo for external API's
167
160
if ! cpInfo .isChainEmpty {
161
+ //If start up is a restart of an existing storage, sync the index from block storage and update BlockchainInfo for external API's
162
+ mgr .syncIndex ()
168
163
lastBlockHeader , err := mgr .retrieveBlockHeaderByNumber (cpInfo .lastBlockNumber )
169
164
if err != nil {
170
165
panic (fmt .Sprintf ("Could not retrieve header of the last block form file: %s" , err ))
@@ -177,7 +172,6 @@ func newBlockfileMgr(id string, conf *Conf, indexConfig *blkstorage.IndexConfig,
177
172
PreviousBlockHash : previousBlockHash }
178
173
}
179
174
mgr .bcInfo .Store (bcInfo )
180
- //return the new manager (blockfileMgr)
181
175
return mgr
182
176
}
183
177
@@ -346,10 +340,10 @@ func (mgr *blockfileMgr) syncIndex() error {
346
340
//if the index stored in the db has value, update the index information with those values
347
341
if ! indexEmpty {
348
342
if lastBlockIndexed == mgr .cpInfo .lastBlockNumber {
349
- logger .Infof ("Both the block files and indices are in sync." )
343
+ logger .Debug ("Both the block files and indices are in sync." )
350
344
return nil
351
345
}
352
- logger .Infof ("Last block indexed [%d], Last block present in block files= [%d]" , lastBlockIndexed , mgr .cpInfo .lastBlockNumber )
346
+ logger .Debugf ("Last block indexed [%d], Last block present in block files [%d]" , lastBlockIndexed , mgr .cpInfo .lastBlockNumber )
353
347
var flp * fileLocPointer
354
348
if flp , err = mgr .index .getBlockLocByBlockNum (lastBlockIndexed ); err != nil {
355
349
return err
@@ -359,10 +353,10 @@ func (mgr *blockfileMgr) syncIndex() error {
359
353
skipFirstBlock = true
360
354
startingBlockNum = lastBlockIndexed + 1
361
355
} else {
362
- logger .Infof ("No block indexed, Last block present in block files=[%d]" , mgr .cpInfo .lastBlockNumber )
356
+ logger .Debugf ("No block indexed, Last block present in block files=[%d]" , mgr .cpInfo .lastBlockNumber )
363
357
}
364
358
365
- logger .Infof ("Start building index from block [%d]" , startingBlockNum )
359
+ logger .Infof ("Start building index from block [%d] to last block [%d] " , startingBlockNum , mgr . cpInfo . lastBlockNumber )
366
360
367
361
//open a blockstream to the file location that was stored in the index
368
362
var stream * blockStream
0 commit comments