diff options
-rw-r--r-- | cmd/mist/assets/examples/coin.html | 1 | ||||
-rw-r--r-- | core/block_processor.go | 5 | ||||
-rw-r--r-- | miner/miner.go | 42 | ||||
-rw-r--r-- | pow/block.go | 1 |
4 files changed, 39 insertions, 10 deletions
diff --git a/cmd/mist/assets/examples/coin.html b/cmd/mist/assets/examples/coin.html index 71b359834..30fbc6dad 100644 --- a/cmd/mist/assets/examples/coin.html +++ b/cmd/mist/assets/examples/coin.html @@ -116,7 +116,6 @@ refresh(); </script> - </html> <!-- diff --git a/core/block_processor.go b/core/block_processor.go index 6db3c25f5..d6755e7f7 100644 --- a/core/block_processor.go +++ b/core/block_processor.go @@ -7,6 +7,7 @@ import ( "sync" "time" + "github.com/ethereum/c-ethash/go-ethash" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethutil" @@ -14,7 +15,7 @@ import ( "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/pow" - "github.com/ethereum/go-ethereum/pow/ezp" + _ "github.com/ethereum/go-ethereum/pow/ezp" "github.com/ethereum/go-ethereum/state" "gopkg.in/fatih/set.v0" ) @@ -66,7 +67,7 @@ func NewBlockProcessor(db ethutil.Database, txpool *TxPool, chainManager *ChainM sm := &BlockProcessor{ db: db, mem: make(map[string]*big.Int), - Pow: ezp.New(), + Pow: ðash.Ethash{}, bc: chainManager, eventMux: eventMux, txpool: txpool, diff --git a/miner/miner.go b/miner/miner.go index 63c8e22a7..1f4fc2170 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -24,21 +24,43 @@ package miner import ( + "fmt" "math/big" "sort" - "github.com/ethereum/go-ethereum/eth" - "github.com/ethereum/go-ethereum/ethutil" - "github.com/ethereum/go-ethereum/pow" - "github.com/ethereum/go-ethereum/pow/ezp" - "github.com/ethereum/go-ethereum/state" - + "github.com/ethereum/c-ethash/go-ethash" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/eth" + "github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/logger" + "github.com/ethereum/go-ethereum/pow" + "github.com/ethereum/go-ethereum/state" ) +var dx = []byte{0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42} +var dy = []byte{0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43} + +const epochLen = uint64(1000) + +func getSeed(chainMan *core.ChainManager, block *types.Block) (x []byte, y []byte) { + if block.Number().Uint64() == 0 { + return dx, dy + } else if block.Number().Uint64()%epochLen == 0 { + x, y = getSeed(chainMan, chainMan.GetBlock(block.ParentHash())) + if (block.Number().Uint64()/epochLen)%2 > 0 { + y = crypto.Sha3(append(y, block.ParentHash()...)) + } else { + x = crypto.Sha3(append(x, block.ParentHash()...)) + } + return x, y + } else { + return getSeed(chainMan, chainMan.GetBlock(block.ParentHash())) + } +} + type LocalTx struct { To []byte `json:"to"` Data []byte `json:"data"` @@ -77,7 +99,6 @@ func New(coinbase []byte, eth *eth.Ethereum) *Miner { return &Miner{ eth: eth, powQuitCh: make(chan struct{}), - pow: ezp.New(), mining: false, localTxs: make(map[int]*LocalTx), MinAcceptedGasPrice: big.NewInt(10000000000000), @@ -211,6 +232,13 @@ func (self *Miner) mine() { minerlogger.Infof("Mining on block. Includes %v transactions", len(transactions)) + x, _ := getSeed(chainMan, block) + self.pow, err = ethash.New(x, block) + if err != nil { + fmt.Println("miner gave back err", err) + return + } + // Find a valid nonce nonce := self.pow.Search(block, self.powQuitCh) if nonce != nil { diff --git a/pow/block.go b/pow/block.go index 62df2b5ff..31e194d8d 100644 --- a/pow/block.go +++ b/pow/block.go @@ -6,4 +6,5 @@ type Block interface { Difficulty() *big.Int HashNoNonce() []byte N() []byte + Number() *big.Int } |