aboutsummaryrefslogtreecommitdiffstats
path: root/eth/backend.go
diff options
context:
space:
mode:
Diffstat (limited to 'eth/backend.go')
-rw-r--r--eth/backend.go57
1 files changed, 34 insertions, 23 deletions
diff --git a/eth/backend.go b/eth/backend.go
index efdd43bf5..584d60c7e 100644
--- a/eth/backend.go
+++ b/eth/backend.go
@@ -7,6 +7,8 @@ import (
"path"
"strings"
+ "github.com/ethereum/ethash"
+ "github.com/ethereum/go-ethereum/blockpool"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
@@ -17,8 +19,8 @@ import (
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p/discover"
"github.com/ethereum/go-ethereum/p2p/nat"
- "github.com/ethereum/go-ethereum/pow/ezp"
"github.com/ethereum/go-ethereum/rpc"
+ "github.com/ethereum/go-ethereum/vm"
"github.com/ethereum/go-ethereum/whisper"
)
@@ -42,6 +44,7 @@ type Config struct {
LogLevel int
KeyRing string
LogFormat string
+ VmDebug bool
MaxPeers int
Port string
@@ -106,18 +109,17 @@ func (cfg *Config) nodeKey() (*ecdsa.PrivateKey, error) {
type Ethereum struct {
// Channel for shutting down the ethereum
shutdownChan chan bool
- quit chan bool
// DB interface
- db ethutil.Database
- blacklist p2p.Blacklist
+ blockDb ethutil.Database
+ stateDb ethutil.Database
//*** SERVICES ***
// State manager for processing new blocks and managing the over all states
blockProcessor *core.BlockProcessor
txPool *core.TxPool
chainManager *core.ChainManager
- blockPool *BlockPool
+ blockPool *blockpool.BlockPool
whisper *whisper.Whisper
net *p2p.Server
@@ -131,19 +133,25 @@ type Ethereum struct {
logger logger.LogSystem
- Mining bool
+ Mining bool
+ DataDir string
}
func New(config *Config) (*Ethereum, error) {
// Boostrap database
ethlogger := logger.New(config.DataDir, config.LogFile, config.LogLevel, config.LogFormat)
- db, err := ethdb.NewLDBDatabase("blockchain")
+
+ blockDb, err := ethdb.NewLDBDatabase(path.Join(config.DataDir, "blockchain"))
+ if err != nil {
+ return nil, err
+ }
+ stateDb, err := ethdb.NewLDBDatabase(path.Join(config.DataDir, "state"))
if err != nil {
return nil, err
}
// Perform database sanity checks
- d, _ := db.Get([]byte("ProtocolVersion"))
+ d, _ := blockDb.Get([]byte("ProtocolVersion"))
protov := ethutil.NewValue(d).Uint()
if protov != ProtocolVersion && protov != 0 {
path := path.Join(config.DataDir, "blockchain")
@@ -154,7 +162,7 @@ func New(config *Config) (*Ethereum, error) {
var keyManager *crypto.KeyManager
switch config.KeyStore {
case "db":
- keyManager = crypto.NewDBKeyManager(db)
+ keyManager = crypto.NewDBKeyManager(blockDb)
case "file":
keyManager = crypto.NewFileKeyManager(config.DataDir)
default:
@@ -163,29 +171,31 @@ func New(config *Config) (*Ethereum, error) {
// Initialise the keyring
keyManager.Init(config.KeyRing, 0, false)
- saveProtocolVersion(db)
+ saveProtocolVersion(blockDb)
//ethutil.Config.Db = db
eth := &Ethereum{
shutdownChan: make(chan bool),
- quit: make(chan bool),
- db: db,
+ blockDb: blockDb,
+ stateDb: stateDb,
keyManager: keyManager,
- blacklist: p2p.NewBlacklist(),
eventMux: &event.TypeMux{},
logger: ethlogger,
+ DataDir: config.DataDir,
}
- eth.chainManager = core.NewChainManager(db, eth.EventMux())
+ eth.chainManager = core.NewChainManager(blockDb, stateDb, eth.EventMux())
+ pow := ethash.New(eth.chainManager)
+
eth.txPool = core.NewTxPool(eth.EventMux())
- eth.blockProcessor = core.NewBlockProcessor(db, eth.txPool, eth.chainManager, eth.EventMux())
+ eth.blockProcessor = core.NewBlockProcessor(stateDb, pow, eth.txPool, eth.chainManager, eth.EventMux())
eth.chainManager.SetProcessor(eth.blockProcessor)
eth.whisper = whisper.New()
- eth.miner = miner.New(keyManager.Address(), eth, config.MinerThreads)
+ eth.miner = miner.New(keyManager.Address(), eth, pow, config.MinerThreads)
hasBlock := eth.chainManager.HasBlock
insertChain := eth.chainManager.InsertChain
- eth.blockPool = NewBlockPool(hasBlock, insertChain, ezp.Verify)
+ eth.blockPool = blockpool.New(hasBlock, insertChain, pow.Verify)
netprv, err := config.nodeKey()
if err != nil {
@@ -202,7 +212,6 @@ func New(config *Config) (*Ethereum, error) {
Name: config.Name,
MaxPeers: config.MaxPeers,
Protocols: protocols,
- Blacklist: eth.blacklist,
NAT: config.NAT,
NoDial: !config.Dial,
BootstrapNodes: config.parseBootNodes(),
@@ -211,6 +220,8 @@ func New(config *Config) (*Ethereum, error) {
eth.net.ListenAddr = ":" + config.Port
}
+ vm.Debug = config.VmDebug
+
return eth, nil
}
@@ -220,10 +231,11 @@ func (s *Ethereum) Name() string { return s.net.Name }
func (s *Ethereum) ChainManager() *core.ChainManager { return s.chainManager }
func (s *Ethereum) BlockProcessor() *core.BlockProcessor { return s.blockProcessor }
func (s *Ethereum) TxPool() *core.TxPool { return s.txPool }
-func (s *Ethereum) BlockPool() *BlockPool { return s.blockPool }
+func (s *Ethereum) BlockPool() *blockpool.BlockPool { return s.blockPool }
func (s *Ethereum) Whisper() *whisper.Whisper { return s.whisper }
func (s *Ethereum) EventMux() *event.TypeMux { return s.eventMux }
-func (s *Ethereum) Db() ethutil.Database { return s.db }
+func (s *Ethereum) BlockDb() ethutil.Database { return s.blockDb }
+func (s *Ethereum) StateDb() ethutil.Database { return s.stateDb }
func (s *Ethereum) Miner() *miner.Miner { return s.miner }
func (s *Ethereum) IsListening() bool { return true } // Always listening
func (s *Ethereum) PeerCount() int { return s.net.PeerCount() }
@@ -274,9 +286,8 @@ func (self *Ethereum) SuggestPeer(nodeURL string) error {
func (s *Ethereum) Stop() {
// Close the database
- defer s.db.Close()
-
- close(s.quit)
+ defer s.blockDb.Close()
+ defer s.stateDb.Close()
s.txSub.Unsubscribe() // quits txBroadcastLoop
s.blockSub.Unsubscribe() // quits blockBroadcastLoop