diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-04-13 23:34:34 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-04-13 23:34:34 +0800 |
commit | 5f9346bc7afd64706b3815aec6be2b2650929a6b (patch) | |
tree | ff02f1f4f36246e2431b43207f2400b49417e051 /eth | |
parent | ad4891a09a4f7c7fa3e77c5370c01f16a0a3070e (diff) | |
parent | 49a513bdebd7c4402b3a7f2f169a31c34f2ca9df (diff) | |
download | dexon-5f9346bc7afd64706b3815aec6be2b2650929a6b.tar dexon-5f9346bc7afd64706b3815aec6be2b2650929a6b.tar.gz dexon-5f9346bc7afd64706b3815aec6be2b2650929a6b.tar.bz2 dexon-5f9346bc7afd64706b3815aec6be2b2650929a6b.tar.lz dexon-5f9346bc7afd64706b3815aec6be2b2650929a6b.tar.xz dexon-5f9346bc7afd64706b3815aec6be2b2650929a6b.tar.zst dexon-5f9346bc7afd64706b3815aec6be2b2650929a6b.zip |
Merge pull request #700 from bas-vk/issue_650
Added blockchain DB versioning support, closes #650
Diffstat (limited to 'eth')
-rw-r--r-- | eth/backend.go | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/eth/backend.go b/eth/backend.go index c7a5b233f..f073ec6e6 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -42,6 +42,9 @@ type Config struct { ProtocolVersion int NetworkId int + BlockChainVersion int + SkipBcVersionCheck bool // e.g. blockchain export + DataDir string LogFile string LogLevel int @@ -149,7 +152,7 @@ type Ethereum struct { } func New(config *Config) (*Ethereum, error) { - // Boostrap database + // Bootstrap database logger.New(config.DataDir, config.LogFile, config.LogLevel) if len(config.LogJSON) > 0 { logger.NewJSONsystem(config.DataDir, config.LogJSON) @@ -179,6 +182,16 @@ func New(config *Config) (*Ethereum, error) { saveProtocolVersion(blockDb, config.ProtocolVersion) glog.V(logger.Info).Infof("Protocol Version: %v, Network Id: %v", config.ProtocolVersion, config.NetworkId) + if !config.SkipBcVersionCheck { + b, _ := blockDb.Get([]byte("BlockchainVersion")) + bcVersion := int(common.NewValue(b).Uint()) + if bcVersion != config.BlockChainVersion && bcVersion != 0 { + return nil, fmt.Errorf("Blockchain DB version mismatch (%d / %d). Run geth upgradedb.\n", bcVersion, config.BlockChainVersion) + } + saveBlockchainVersion(blockDb, config.BlockChainVersion) + } + glog.V(logger.Info).Infof("Blockchain DB Version: %d", config.BlockChainVersion) + eth := &Ethereum{ shutdownChan: make(chan bool), blockDb: blockDb, @@ -472,3 +485,12 @@ func saveProtocolVersion(db common.Database, protov int) { db.Put([]byte("ProtocolVersion"), common.NewValue(protov).Bytes()) } } + +func saveBlockchainVersion(db common.Database, bcVersion int) { + d, _ := db.Get([]byte("BlockchainVersion")) + blockchainVersion := common.NewValue(d).Uint() + + if blockchainVersion == 0 { + db.Put([]byte("BlockchainVersion"), common.NewValue(bcVersion).Bytes()) + } +} |