|
|
@ -10,11 +10,11 @@ import ( |
|
|
|
"github.com/ethereum/ethash" |
|
|
|
"github.com/ethereum/ethash" |
|
|
|
"github.com/ethereum/go-ethereum/accounts" |
|
|
|
"github.com/ethereum/go-ethereum/accounts" |
|
|
|
"github.com/ethereum/go-ethereum/blockpool" |
|
|
|
"github.com/ethereum/go-ethereum/blockpool" |
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common" |
|
|
|
"github.com/ethereum/go-ethereum/core" |
|
|
|
"github.com/ethereum/go-ethereum/core" |
|
|
|
"github.com/ethereum/go-ethereum/core/types" |
|
|
|
"github.com/ethereum/go-ethereum/core/types" |
|
|
|
"github.com/ethereum/go-ethereum/crypto" |
|
|
|
"github.com/ethereum/go-ethereum/crypto" |
|
|
|
"github.com/ethereum/go-ethereum/ethdb" |
|
|
|
"github.com/ethereum/go-ethereum/ethdb" |
|
|
|
"github.com/ethereum/go-ethereum/common" |
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/event" |
|
|
|
"github.com/ethereum/go-ethereum/event" |
|
|
|
"github.com/ethereum/go-ethereum/logger" |
|
|
|
"github.com/ethereum/go-ethereum/logger" |
|
|
|
"github.com/ethereum/go-ethereum/miner" |
|
|
|
"github.com/ethereum/go-ethereum/miner" |
|
|
@ -39,6 +39,9 @@ var ( |
|
|
|
|
|
|
|
|
|
|
|
type Config struct { |
|
|
|
type Config struct { |
|
|
|
Name string |
|
|
|
Name string |
|
|
|
|
|
|
|
ProtocolVersion int |
|
|
|
|
|
|
|
NetworkId int |
|
|
|
|
|
|
|
|
|
|
|
DataDir string |
|
|
|
DataDir string |
|
|
|
LogFile string |
|
|
|
LogFile string |
|
|
|
LogLevel int |
|
|
|
LogLevel int |
|
|
@ -138,11 +141,13 @@ type Ethereum struct { |
|
|
|
Mining bool |
|
|
|
Mining bool |
|
|
|
DataDir string |
|
|
|
DataDir string |
|
|
|
version string |
|
|
|
version string |
|
|
|
|
|
|
|
ProtocolVersion int |
|
|
|
|
|
|
|
NetworkId int |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func New(config *Config) (*Ethereum, error) { |
|
|
|
func New(config *Config) (*Ethereum, error) { |
|
|
|
// Boostrap database
|
|
|
|
// Boostrap database
|
|
|
|
servlogger := logger.New(config.DataDir, config.LogFile, config.LogLevel, config.LogFormat) |
|
|
|
servlogsystem := logger.New(config.DataDir, config.LogFile, config.LogLevel, config.LogFormat) |
|
|
|
|
|
|
|
|
|
|
|
newdb := config.NewDB |
|
|
|
newdb := config.NewDB |
|
|
|
if newdb == nil { |
|
|
|
if newdb == nil { |
|
|
@ -159,13 +164,14 @@ func New(config *Config) (*Ethereum, error) { |
|
|
|
extraDb, err := ethdb.NewLDBDatabase(path.Join(config.DataDir, "extra")) |
|
|
|
extraDb, err := ethdb.NewLDBDatabase(path.Join(config.DataDir, "extra")) |
|
|
|
|
|
|
|
|
|
|
|
// Perform database sanity checks
|
|
|
|
// Perform database sanity checks
|
|
|
|
d, _ := blockDb.Get([]byte("ProtocolVersion")) |
|
|
|
d, _ := extraDb.Get([]byte("ProtocolVersion")) |
|
|
|
protov := common.NewValue(d).Uint() |
|
|
|
protov := int(common.NewValue(d).Uint()) |
|
|
|
if protov != ProtocolVersion && protov != 0 { |
|
|
|
if protov != config.ProtocolVersion && protov != 0 { |
|
|
|
path := path.Join(config.DataDir, "blockchain") |
|
|
|
path := path.Join(config.DataDir, "blockchain") |
|
|
|
return nil, fmt.Errorf("Database version mismatch. Protocol(%d / %d). `rm -rf %s`", protov, ProtocolVersion, path) |
|
|
|
return nil, fmt.Errorf("Database version mismatch. Protocol(%d / %d). `rm -rf %s`", protov, config.ProtocolVersion, path) |
|
|
|
} |
|
|
|
} |
|
|
|
saveProtocolVersion(extraDb) |
|
|
|
saveProtocolVersion(extraDb, config.ProtocolVersion) |
|
|
|
|
|
|
|
servlogger.Infof("Protocol Version: %v, Network Id: %v", config.ProtocolVersion, config.NetworkId) |
|
|
|
|
|
|
|
|
|
|
|
eth := &Ethereum{ |
|
|
|
eth := &Ethereum{ |
|
|
|
shutdownChan: make(chan bool), |
|
|
|
shutdownChan: make(chan bool), |
|
|
@ -173,7 +179,7 @@ func New(config *Config) (*Ethereum, error) { |
|
|
|
stateDb: stateDb, |
|
|
|
stateDb: stateDb, |
|
|
|
extraDb: extraDb, |
|
|
|
extraDb: extraDb, |
|
|
|
eventMux: &event.TypeMux{}, |
|
|
|
eventMux: &event.TypeMux{}, |
|
|
|
logger: servlogger, |
|
|
|
logger: servlogsystem, |
|
|
|
accountManager: config.AccountManager, |
|
|
|
accountManager: config.AccountManager, |
|
|
|
DataDir: config.DataDir, |
|
|
|
DataDir: config.DataDir, |
|
|
|
version: config.Name, // TODO should separate from Name
|
|
|
|
version: config.Name, // TODO should separate from Name
|
|
|
@ -195,7 +201,8 @@ func New(config *Config) (*Ethereum, error) { |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
|
ethProto := EthProtocol(eth.txPool, eth.chainManager, eth.blockPool) |
|
|
|
|
|
|
|
|
|
|
|
ethProto := EthProtocol(config.ProtocolVersion, config.NetworkId, eth.txPool, eth.chainManager, eth.blockPool) |
|
|
|
protocols := []p2p.Protocol{ethProto} |
|
|
|
protocols := []p2p.Protocol{ethProto} |
|
|
|
if config.Shh { |
|
|
|
if config.Shh { |
|
|
|
protocols = append(protocols, eth.whisper.Protocol()) |
|
|
|
protocols = append(protocols, eth.whisper.Protocol()) |
|
|
@ -309,7 +316,6 @@ func (s *Ethereum) StateDb() common.Database { return s.stateDb } |
|
|
|
func (s *Ethereum) ExtraDb() common.Database { return s.extraDb } |
|
|
|
func (s *Ethereum) ExtraDb() common.Database { return s.extraDb } |
|
|
|
func (s *Ethereum) IsListening() bool { return true } // Always listening
|
|
|
|
func (s *Ethereum) IsListening() bool { return true } // Always listening
|
|
|
|
func (s *Ethereum) PeerCount() int { return s.net.PeerCount() } |
|
|
|
func (s *Ethereum) PeerCount() int { return s.net.PeerCount() } |
|
|
|
func (s *Ethereum) PeerInfo() int { return s.net.PeerCount() } |
|
|
|
|
|
|
|
func (s *Ethereum) Peers() []*p2p.Peer { return s.net.Peers() } |
|
|
|
func (s *Ethereum) Peers() []*p2p.Peer { return s.net.Peers() } |
|
|
|
func (s *Ethereum) MaxPeers() int { return s.net.MaxPeers } |
|
|
|
func (s *Ethereum) MaxPeers() int { return s.net.MaxPeers } |
|
|
|
func (s *Ethereum) Version() string { return s.version } |
|
|
|
func (s *Ethereum) Version() string { return s.version } |
|
|
@ -413,11 +419,11 @@ func (self *Ethereum) blockBroadcastLoop() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func saveProtocolVersion(db common.Database) { |
|
|
|
func saveProtocolVersion(db common.Database, protov int) { |
|
|
|
d, _ := db.Get([]byte("ProtocolVersion")) |
|
|
|
d, _ := db.Get([]byte("ProtocolVersion")) |
|
|
|
protocolVersion := common.NewValue(d).Uint() |
|
|
|
protocolVersion := common.NewValue(d).Uint() |
|
|
|
|
|
|
|
|
|
|
|
if protocolVersion == 0 { |
|
|
|
if protocolVersion == 0 { |
|
|
|
db.Put([]byte("ProtocolVersion"), common.NewValue(ProtocolVersion).Bytes()) |
|
|
|
db.Put([]byte("ProtocolVersion"), common.NewValue(protov).Bytes()) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|