blockchain: Delete block headers from old block index bucket.

As part of the migration to the new block index bucket, also delete
the redundant data from the old bucket.
This commit is contained in:
Jim Posen 2017-09-05 19:22:16 -07:00 committed by Dave Collins
parent ad00e7ff82
commit a4d22d8384
2 changed files with 10 additions and 2 deletions

View file

@ -1192,7 +1192,7 @@ func (b *BlockChain) initChainState() error {
// number of nodes are already known, perform a single alloc
// for them versus a whole bunch of little ones to reduce
// pressure on the GC.
log.Infof("Loading block index. This might take a while...")
log.Infof("Loading block index...")
blockIndexBucket := dbTx.Metadata().Bucket(blockIndexBucketName)

View file

@ -72,8 +72,16 @@ func migrateBlockIndex(db database.DB) error {
"stored block %s", hash)
}
// Write header to v2 bucket
key := blockIndexKey(&hash, height)
return v2BlockIdxBucket.Put(key, headerBytes)
err := v2BlockIdxBucket.Put(key, headerBytes)
if err != nil {
return err
}
// Delete header from v1 bucket
truncatedRow := blockRow[0:blockHdrOffset:blockHdrOffset]
return v1BlockIdxBucket.Put(hashBytes, truncatedRow)
})
})
if err != nil {