fixed pow stuff

This commit is contained in:
obscuren 2015-03-03 17:55:23 +01:00
parent 22b132e28f
commit 313fe3861b
10 changed files with 28 additions and 58 deletions

View File

@ -114,7 +114,7 @@ func main() {
}
if StartMining {
utils.StartMining(ethereum)
ethereum.Miner().Start()
}
if len(ImportChain) > 0 {

View File

@ -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)

View File

@ -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,

View File

@ -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
}

View File

@ -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

View File

@ -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

View File

@ -14,7 +14,7 @@ import (
)
const (
ProtocolVersion = 54
ProtocolVersion = 55
NetworkId = 0
ProtocolLength = uint64(8)
ProtocolMaxMsgSize = 10 * 1024 * 1024

View File

@ -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 {

View File

@ -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

View File

@ -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})