diff options
author | obscuren <geffobscura@gmail.com> | 2015-04-16 07:14:27 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-04-16 07:28:24 +0800 |
commit | 3a51c3b584b16b408c3fbf87c4f9719fcfb1c52a (patch) | |
tree | b2d4a5e7fcc1da2fd5b1aa3c139ddc7594c8646c /eth/backend.go | |
parent | 97d2954e227049a089652d91e6fb0ea1c8115cc6 (diff) | |
parent | c4678ffd77a18a9d03c888fdf242c9e5915b9f5f (diff) | |
download | dexon-3a51c3b584b16b408c3fbf87c4f9719fcfb1c52a.tar dexon-3a51c3b584b16b408c3fbf87c4f9719fcfb1c52a.tar.gz dexon-3a51c3b584b16b408c3fbf87c4f9719fcfb1c52a.tar.bz2 dexon-3a51c3b584b16b408c3fbf87c4f9719fcfb1c52a.tar.lz dexon-3a51c3b584b16b408c3fbf87c4f9719fcfb1c52a.tar.xz dexon-3a51c3b584b16b408c3fbf87c4f9719fcfb1c52a.tar.zst dexon-3a51c3b584b16b408c3fbf87c4f9719fcfb1c52a.zip |
Merge branch 'develop' into downloader-proto
Diffstat (limited to 'eth/backend.go')
-rw-r--r-- | eth/backend.go | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/eth/backend.go b/eth/backend.go index a71d5721e..3d5c4ba09 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -4,6 +4,7 @@ import ( "crypto/ecdsa" "fmt" "io/ioutil" + "math" "path" "strings" @@ -43,6 +44,9 @@ type Config struct { ProtocolVersion int NetworkId int + BlockChainVersion int + SkipBcVersionCheck bool // e.g. blockchain export + DataDir string LogFile string LogLevel int @@ -151,7 +155,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) @@ -181,6 +185,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, @@ -439,7 +453,7 @@ func (self *Ethereum) txBroadcastLoop() { // automatically stops if unsubscribe for obj := range self.txSub.Chan() { event := obj.(core.TxPreEvent) - self.net.Broadcast("eth", TxMsg, []*types.Transaction{event.Tx}) + self.net.BroadcastLimited("eth", TxMsg, math.Sqrt, []*types.Transaction{event.Tx}) self.syncAccounts(event.Tx) } } @@ -463,7 +477,7 @@ func (self *Ethereum) blockBroadcastLoop() { for obj := range self.blockSub.Chan() { switch ev := obj.(type) { case core.ChainHeadEvent: - self.net.Broadcast("eth", NewBlockMsg, []interface{}{ev.Block, ev.Block.Td}) + self.net.BroadcastLimited("eth", NewBlockMsg, math.Sqrt, []interface{}{ev.Block, ev.Block.Td}) } } } @@ -476,3 +490,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()) + } +} |