diff options
author | obscuren <geffobscura@gmail.com> | 2015-04-13 23:35:46 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-04-13 23:35:46 +0800 |
commit | 333e539ce2143e9f416cef45053c1c21ce0312d4 (patch) | |
tree | da21c5ca613615f78e7475f67e743c6d9464d1cb /eth | |
parent | a8a2b2a488f7433abc09c51b751556875c9107a9 (diff) | |
parent | 1fa844aaf51beae9129b52a52f51b6602c52ccdb (diff) | |
download | dexon-333e539ce2143e9f416cef45053c1c21ce0312d4.tar dexon-333e539ce2143e9f416cef45053c1c21ce0312d4.tar.gz dexon-333e539ce2143e9f416cef45053c1c21ce0312d4.tar.bz2 dexon-333e539ce2143e9f416cef45053c1c21ce0312d4.tar.lz dexon-333e539ce2143e9f416cef45053c1c21ce0312d4.tar.xz dexon-333e539ce2143e9f416cef45053c1c21ce0312d4.tar.zst dexon-333e539ce2143e9f416cef45053c1c21ce0312d4.zip |
Merge branch 'develop' of github.com-obscure:ethereum/go-ethereum into develop
Diffstat (limited to 'eth')
-rw-r--r-- | eth/backend.go | 24 | ||||
-rw-r--r-- | eth/protocol.go | 12 |
2 files changed, 28 insertions, 8 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()) + } +} diff --git a/eth/protocol.go b/eth/protocol.go index 878038f74..1a19307db 100644 --- a/eth/protocol.go +++ b/eth/protocol.go @@ -299,7 +299,7 @@ func (self *ethProtocol) handle() error { // to simplify backend interface adding a new block // uses AddPeer followed by AddBlock only if peer is the best peer // (or selected as new best peer) - if best, _ := self.blockPool.AddPeer(request.TD, hash, self.id, self.requestBlockHashes, self.requestBlocks, self.protoErrorDisconnect); best { + if _, suspended := self.blockPool.AddPeer(request.TD, hash, self.id, self.requestBlockHashes, self.requestBlocks, self.protoErrorDisconnect); !suspended { self.blockPool.AddBlock(request.Block, self.id) } @@ -384,11 +384,9 @@ func (self *ethProtocol) sendStatus() error { } func (self *ethProtocol) protoErrorDisconnect(err *errs.Error) { - //err.Log(self.peer.Logger) err.Log(glog.V(logger.Info)) - /* - if err.Fatal() { - self.peer.Disconnect(p2p.DiscSubprotocolError) - } - */ + if err.Fatal() { + self.peer.Disconnect(p2p.DiscSubprotocolError) + } + } |