Merge pull request #700 from bas-vk/issue_650

Added blockchain DB versioning support, closes #650
This commit is contained in:
Jeffrey Wilcke
2015-04-13 17:34:34 +02:00
6 changed files with 188 additions and 29 deletions

View File

@ -18,6 +18,12 @@ import (
"gopkg.in/fatih/set.v0"
)
const (
// must be bumped when consensus algorithm is changed, this forces the upgradedb
// command to be run (forces the blocks to be imported again using the new algorithm)
BlockChainVersion = 1
)
var statelogger = logger.NewLogger("BLOCK")
type BlockProcessor struct {

View File

@ -284,11 +284,14 @@ func (self *ChainManager) Export(w io.Writer) error {
defer self.mu.RUnlock()
glog.V(logger.Info).Infof("exporting %v blocks...\n", self.currentBlock.Header().Number)
for block := self.currentBlock; block != nil; block = self.GetBlock(block.Header().ParentHash) {
if err := block.EncodeRLP(w); err != nil {
last := self.currentBlock.NumberU64()
for nr := uint64(0); nr <= last; nr++ {
if err := self.GetBlockByNumber(nr).EncodeRLP(w); err != nil {
return err
}
}
return nil
}