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