Integrate new ethash API and change geth makedag cmd
This commit is contained in:
parent
50659f4b48
commit
b1cc9cdc74
@ -27,8 +27,10 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
@ -601,12 +603,32 @@ func dump(ctx *cli.Context) {
|
||||
}
|
||||
|
||||
func makedag(ctx *cli.Context) {
|
||||
chain, _, _ := utils.GetChain(ctx)
|
||||
pow := ethash.New(chain)
|
||||
fmt.Println("making cache")
|
||||
pow.UpdateCache(0, true)
|
||||
fmt.Println("making DAG")
|
||||
pow.UpdateDAG()
|
||||
args := ctx.Args()
|
||||
wrongArgs := func() {
|
||||
utils.Fatalf(`Usage: geth makedag <block number> <outputdir>`)
|
||||
}
|
||||
switch {
|
||||
case len(args) == 2:
|
||||
blockNum, err := strconv.ParseUint(args[0], 0, 64)
|
||||
dir := args[1]
|
||||
if err != nil {
|
||||
wrongArgs()
|
||||
} else {
|
||||
dir = filepath.Clean(dir)
|
||||
// seems to require a trailing slash
|
||||
if !strings.HasSuffix(dir, "/") {
|
||||
dir = dir + "/"
|
||||
}
|
||||
_, err = ioutil.ReadDir(dir)
|
||||
if err != nil {
|
||||
utils.Fatalf("Can't find dir")
|
||||
}
|
||||
fmt.Println("making DAG, this could take awhile...")
|
||||
ethash.MakeDAG(blockNum, dir)
|
||||
}
|
||||
default:
|
||||
wrongArgs()
|
||||
}
|
||||
}
|
||||
|
||||
func version(c *cli.Context) {
|
||||
|
@ -316,7 +316,7 @@ func GetChain(ctx *cli.Context) (*core.ChainManager, common.Database, common.Dat
|
||||
|
||||
eventMux := new(event.TypeMux)
|
||||
chainManager := core.NewChainManager(blockDb, stateDb, eventMux)
|
||||
pow := ethash.New(chainManager)
|
||||
pow := ethash.New()
|
||||
txPool := core.NewTxPool(eventMux, chainManager.State, chainManager.GasLimit)
|
||||
blockProcessor := core.NewBlockProcessor(stateDb, extraDb, pow, txPool, chainManager, eventMux)
|
||||
chainManager.SetProcessor(blockProcessor)
|
||||
|
@ -14,8 +14,8 @@ import (
|
||||
// So we can generate blocks easily
|
||||
type FakePow struct{}
|
||||
|
||||
func (f FakePow) Search(block pow.Block, stop <-chan struct{}) (uint64, []byte, []byte) {
|
||||
return 0, nil, nil
|
||||
func (f FakePow) Search(block pow.Block, stop <-chan struct{}) (uint64, []byte) {
|
||||
return 0, nil
|
||||
}
|
||||
func (f FakePow) Verify(block pow.Block) bool { return true }
|
||||
func (f FakePow) GetHashrate() int64 { return 0 }
|
||||
|
@ -220,7 +220,7 @@ func New(config *Config) (*Ethereum, error) {
|
||||
|
||||
eth.chainManager = core.NewChainManager(blockDb, stateDb, eth.EventMux())
|
||||
eth.downloader = downloader.New(eth.chainManager.HasBlock, eth.chainManager.GetBlock)
|
||||
eth.pow = ethash.New(eth.chainManager)
|
||||
eth.pow = ethash.New()
|
||||
eth.txPool = core.NewTxPool(eth.EventMux(), eth.chainManager.State, eth.chainManager.GasLimit)
|
||||
eth.blockProcessor = core.NewBlockProcessor(stateDb, extraDb, eth.pow, eth.txPool, eth.chainManager, eth.EventMux())
|
||||
eth.chainManager.SetProcessor(eth.blockProcessor)
|
||||
@ -318,7 +318,6 @@ func (s *Ethereum) PeersInfo() (peersinfo []*PeerInfo) {
|
||||
|
||||
func (s *Ethereum) ResetWithGenesisBlock(gb *types.Block) {
|
||||
s.chainManager.ResetWithGenesisBlock(gb)
|
||||
s.pow.UpdateCache(0, true)
|
||||
}
|
||||
|
||||
func (s *Ethereum) StartMining() error {
|
||||
|
@ -85,7 +85,7 @@ func (self *CpuMiner) mine(block *types.Block) {
|
||||
self.chMu.Unlock()
|
||||
|
||||
// Mine
|
||||
nonce, mixDigest, _ := self.pow.Search(block, self.quitCurrentOp)
|
||||
nonce, mixDigest := self.pow.Search(block, self.quitCurrentOp)
|
||||
if nonce != 0 {
|
||||
block.SetNonce(nonce)
|
||||
block.Header().MixDigest = common.BytesToHash(mixDigest)
|
||||
|
@ -3,7 +3,6 @@ package miner
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/ethash"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/core/state"
|
||||
@ -41,13 +40,7 @@ func (self *Miner) Mining() bool {
|
||||
func (self *Miner) Start(coinbase common.Address) {
|
||||
self.mining = true
|
||||
self.worker.coinbase = coinbase
|
||||
|
||||
if self.threads > 0 {
|
||||
self.pow.(*ethash.Ethash).UpdateDAG()
|
||||
}
|
||||
|
||||
self.worker.start()
|
||||
|
||||
self.worker.commitNewWork()
|
||||
}
|
||||
|
||||
|
@ -6,8 +6,8 @@ import (
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/crypto/sha3"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/crypto/sha3"
|
||||
"github.com/ethereum/go-ethereum/logger"
|
||||
)
|
||||
|
||||
@ -44,7 +44,7 @@ func (dag *Dagger) Find(obj *big.Int, resChan chan int64) {
|
||||
resChan <- 0
|
||||
}
|
||||
|
||||
func (dag *Dagger) Search(hash, diff *big.Int) ([]byte, []byte, []byte) {
|
||||
func (dag *Dagger) Search(hash, diff *big.Int) (uint64, []byte) {
|
||||
// TODO fix multi threading. Somehow it results in the wrong nonce
|
||||
amountOfRoutines := 1
|
||||
|
||||
@ -69,7 +69,7 @@ func (dag *Dagger) Search(hash, diff *big.Int) ([]byte, []byte, []byte) {
|
||||
}
|
||||
}
|
||||
|
||||
return big.NewInt(res).Bytes(), nil, nil
|
||||
return uint64(res), nil
|
||||
}
|
||||
|
||||
func (dag *Dagger) Verify(hash, diff, nonce *big.Int) bool {
|
||||
|
@ -32,7 +32,7 @@ func (pow *EasyPow) Turbo(on bool) {
|
||||
pow.turbo = on
|
||||
}
|
||||
|
||||
func (pow *EasyPow) Search(block pow.Block, stop <-chan struct{}) (uint64, []byte, []byte) {
|
||||
func (pow *EasyPow) Search(block pow.Block, stop <-chan struct{}) (uint64, []byte) {
|
||||
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
hash := block.HashNoNonce()
|
||||
diff := block.Difficulty()
|
||||
@ -57,7 +57,7 @@ empty:
|
||||
for {
|
||||
select {
|
||||
case <-stop:
|
||||
return 0, nil, nil
|
||||
return 0, nil
|
||||
default:
|
||||
i++
|
||||
|
||||
@ -67,7 +67,7 @@ empty:
|
||||
|
||||
sha := uint64(r.Int63())
|
||||
if verify(hash, diff, sha) {
|
||||
return sha, nil, nil
|
||||
return sha, nil
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,7 +76,7 @@ empty:
|
||||
}
|
||||
}
|
||||
|
||||
return 0, nil, nil
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func (pow *EasyPow) Verify(block pow.Block) bool {
|
||||
|
@ -1,7 +1,7 @@
|
||||
package pow
|
||||
|
||||
type PoW interface {
|
||||
Search(block Block, stop <-chan struct{}) (uint64, []byte, []byte)
|
||||
Search(block Block, stop <-chan struct{}) (uint64, []byte)
|
||||
Verify(block Block) bool
|
||||
GetHashrate() int64
|
||||
Turbo(bool)
|
||||
|
Loading…
Reference in New Issue
Block a user