From a4d22d8384806ca60e537108ed1672d330e1bda2 Mon Sep 17 00:00:00 2001 From: Jim Posen Date: Tue, 5 Sep 2017 19:22:16 -0700 Subject: [PATCH] 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. --- blockchain/chainio.go | 2 +- blockchain/upgrade.go | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/blockchain/chainio.go b/blockchain/chainio.go index 51216f56..85c910ab 100644 --- a/blockchain/chainio.go +++ b/blockchain/chainio.go @@ -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) diff --git a/blockchain/upgrade.go b/blockchain/upgrade.go index 60e8a897..f980d015 100644 --- a/blockchain/upgrade.go +++ b/blockchain/upgrade.go @@ -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 {