aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cmd/ethereum/main.go2
-rw-r--r--cmd/utils/cmd.go39
-rw-r--r--core/block_processor.go5
-rw-r--r--core/chain_makers.go6
-rw-r--r--core/types/block.go5
-rw-r--r--eth/backend.go7
-rw-r--r--eth/protocol.go2
-rw-r--r--javascript/javascript_runtime.go10
-rw-r--r--miner/miner.go9
-rw-r--r--miner/worker.go1
10 files changed, 28 insertions, 58 deletions
diff --git a/cmd/ethereum/main.go b/cmd/ethereum/main.go
index f72b11e14..dc25e4ae0 100644
--- a/cmd/ethereum/main.go
+++ b/cmd/ethereum/main.go
@@ -114,7 +114,7 @@ func main() {
}
if StartMining {
- utils.StartMining(ethereum)
+ ethereum.Miner().Start()
}
if len(ImportChain) > 0 {
diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go
index a36c10e3b..03ad883d7 100644
--- a/cmd/utils/cmd.go
+++ b/cmd/utils/cmd.go
@@ -32,7 +32,6 @@ import (
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/miner"
"github.com/ethereum/go-ethereum/rlp"
rpchttp "github.com/ethereum/go-ethereum/rpc/http"
rpcws "github.com/ethereum/go-ethereum/rpc/ws"
@@ -182,32 +181,6 @@ func StartWebSockets(eth *eth.Ethereum, wsPort int) {
}
}
-var gminer *miner.Miner
-
-func GetMiner() *miner.Miner {
- return gminer
-}
-
-func StartMining(ethereum *eth.Ethereum) bool {
- if !ethereum.Mining {
- ethereum.Mining = true
- addr := ethereum.KeyManager().Address()
-
- go func() {
- clilogger.Infoln("Start mining")
- if gminer == nil {
- gminer = miner.New(addr, ethereum, 4)
- }
- gminer.Start()
- }()
- RegisterInterrupt(func(os.Signal) {
- StopMining(ethereum)
- })
- return true
- }
- return false
-}
-
func FormatTransactionData(data string) []byte {
d := ethutil.StringToByteFunc(data, func(s string) (ret []byte) {
slice := regexp.MustCompile("\\n|\\s").Split(s, 1000000000)
@@ -221,18 +194,6 @@ func FormatTransactionData(data string) []byte {
return d
}
-func StopMining(ethereum *eth.Ethereum) bool {
- if ethereum.Mining && gminer != nil {
- gminer.Stop()
- clilogger.Infoln("Stopped mining")
- ethereum.Mining = false
-
- return true
- }
-
- return false
-}
-
// Replay block
func BlockDo(ethereum *eth.Ethereum, hash []byte) error {
block := ethereum.ChainManager().GetBlock(hash)
diff --git a/core/block_processor.go b/core/block_processor.go
index 17256fe9c..f4a3cb8e3 100644
--- a/core/block_processor.go
+++ b/core/block_processor.go
@@ -7,7 +7,6 @@ import (
"sync"
"time"
- "github.com/ethereum/ethash"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/event"
@@ -46,11 +45,11 @@ type BlockProcessor struct {
eventMux *event.TypeMux
}
-func NewBlockProcessor(db ethutil.Database, txpool *TxPool, chainManager *ChainManager, eventMux *event.TypeMux) *BlockProcessor {
+func NewBlockProcessor(db ethutil.Database, pow pow.PoW, txpool *TxPool, chainManager *ChainManager, eventMux *event.TypeMux) *BlockProcessor {
sm := &BlockProcessor{
db: db,
mem: make(map[string]*big.Int),
- Pow: ethash.New(chainManager),
+ Pow: pow,
bc: chainManager,
eventMux: eventMux,
txpool: txpool,
diff --git a/core/chain_makers.go b/core/chain_makers.go
index 2c36b892e..7afdfde0d 100644
--- a/core/chain_makers.go
+++ b/core/chain_makers.go
@@ -2,12 +2,13 @@ package core
import (
"fmt"
+ "math/big"
+
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/pow"
"github.com/ethereum/go-ethereum/state"
- "math/big"
)
// So we can generate blocks easily
@@ -119,8 +120,7 @@ func newChainManager(block *types.Block, eventMux *event.TypeMux, db ethutil.Dat
// block processor with fake pow
func newBlockProcessor(db ethutil.Database, txpool *TxPool, cman *ChainManager, eventMux *event.TypeMux) *BlockProcessor {
- bman := NewBlockProcessor(db, txpool, newChainManager(nil, eventMux, db), eventMux)
- bman.Pow = FakePow{}
+ bman := NewBlockProcessor(db, FakePow{}, txpool, newChainManager(nil, eventMux, db), eventMux)
return bman
}
diff --git a/core/types/block.go b/core/types/block.go
index a37038f73..673c72003 100644
--- a/core/types/block.go
+++ b/core/types/block.go
@@ -268,7 +268,10 @@ func (self *Header) String() string {
Time: %v
Extra: %v
Nonce: %x
-`, self.ParentHash, self.UncleHash, self.Coinbase, self.Root, self.TxHash, self.ReceiptHash, self.Bloom, self.Difficulty, self.Number, self.GasLimit, self.GasUsed, self.Time, self.Extra, self.Nonce)
+ MixDigest: %x
+ SeedHash: %x
+
+`, self.ParentHash, self.UncleHash, self.Coinbase, self.Root, self.TxHash, self.ReceiptHash, self.Bloom, self.Difficulty, self.Number, self.GasLimit, self.GasUsed, self.Time, self.Extra, self.Nonce, self.MixDigest, self.SeedHash)
}
type Blocks []*Block
diff --git a/eth/backend.go b/eth/backend.go
index 0de0fcf4a..50fb70720 100644
--- a/eth/backend.go
+++ b/eth/backend.go
@@ -7,6 +7,7 @@ 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"
@@ -179,11 +180,13 @@ func New(config *Config) (*Ethereum, error) {
}
eth.chainManager = core.NewChainManager(db, 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(db, 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
diff --git a/eth/protocol.go b/eth/protocol.go
index ee2316836..67ed8f9e5 100644
--- a/eth/protocol.go
+++ b/eth/protocol.go
@@ -14,7 +14,7 @@ import (
)
const (
- ProtocolVersion = 54
+ ProtocolVersion = 55
NetworkId = 0
ProtocolLength = uint64(8)
ProtocolMaxMsgSize = 10 * 1024 * 1024
diff --git a/javascript/javascript_runtime.go b/javascript/javascript_runtime.go
index beaca45b9..893ad5d33 100644
--- a/javascript/javascript_runtime.go
+++ b/javascript/javascript_runtime.go
@@ -7,7 +7,6 @@ import (
"path"
"path/filepath"
- "github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/eth"
@@ -157,13 +156,14 @@ func (self *JSRE) dump(call otto.FunctionCall) otto.Value {
}
func (self *JSRE) stopMining(call otto.FunctionCall) otto.Value {
- v, _ := self.Vm.ToValue(utils.StopMining(self.ethereum))
- return v
+ self.xeth.Miner().Stop()
+
+ return otto.TrueValue()
}
func (self *JSRE) startMining(call otto.FunctionCall) otto.Value {
- v, _ := self.Vm.ToValue(utils.StartMining(self.ethereum))
- return v
+ self.xeth.Miner().Start()
+ return otto.TrueValue()
}
func (self *JSRE) connect(call otto.FunctionCall) otto.Value {
diff --git a/miner/miner.go b/miner/miner.go
index 0cc2361c8..f207948a5 100644
--- a/miner/miner.go
+++ b/miner/miner.go
@@ -5,7 +5,7 @@ import (
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/pow/ezp"
+ "github.com/ethereum/go-ethereum/pow"
)
var minerlogger = logger.NewLogger("MINER")
@@ -18,16 +18,19 @@ type Miner struct {
Coinbase []byte
mining bool
+
+ pow pow.PoW
}
-func New(coinbase []byte, eth core.Backend, minerThreads int) *Miner {
+func New(coinbase []byte, eth core.Backend, pow pow.PoW, minerThreads int) *Miner {
miner := &Miner{
Coinbase: coinbase,
worker: newWorker(coinbase, eth),
+ pow: pow,
}
for i := 0; i < minerThreads; i++ {
- miner.worker.register(NewCpuMiner(i, ezp.New()))
+ miner.worker.register(NewCpuMiner(i, miner.pow))
}
return miner
diff --git a/miner/worker.go b/miner/worker.go
index 201367fdf..fe80b63ee 100644
--- a/miner/worker.go
+++ b/miner/worker.go
@@ -146,6 +146,7 @@ func (self *worker) wait() {
self.current.block.Header().Nonce = work.Nonce
self.current.block.Header().MixDigest = work.MixDigest
self.current.block.Header().SeedHash = work.SeedHash
+ fmt.Println(self.current.block)
if err := self.chain.InsertChain(types.Blocks{self.current.block}); err == nil {
self.mux.Post(core.NewMinedBlockEvent{self.current.block})