From 9d2166a964d83c09481dea6ef30889f260249295 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 5 Feb 2015 08:29:41 -0800 Subject: wip --- cmd/mist/assets/examples/coin.html | 20 +++--- cmd/mist/assets/html/home.html | 142 ++++++++++++++++++------------------- miner/miner.go | 42 +++++++++-- 3 files changed, 116 insertions(+), 88 deletions(-) diff --git a/cmd/mist/assets/examples/coin.html b/cmd/mist/assets/examples/coin.html index a84a828af..9d1a83171 100644 --- a/cmd/mist/assets/examples/coin.html +++ b/cmd/mist/assets/examples/coin.html @@ -93,18 +93,18 @@ function transact() { var to = document.querySelector("#address").value; if( to.length == 0 ) { - to = "0x4205b06c2cfa0e30359edcab94543266cb6fa1d3"; + to = "0x4205b06c2cfa0e30359edcab94543266cb6fa1d3"; } else { to = "0x"+to; } - - var value = parseInt( document.querySelector("#amount").value ); - - contract.transact({gas: "10000", gasprice: eth.gasPrice}).send( to, value ); - } - - reflesh(); - - + + var value = parseInt( document.querySelector("#amount").value ); + + contract.transact({gas: "10000", gasprice: eth.gasPrice}).send( to, value ); + } + + reflesh(); + + diff --git a/cmd/mist/assets/html/home.html b/cmd/mist/assets/html/home.html index 7116f5dde..3b27917fd 100644 --- a/cmd/mist/assets/html/home.html +++ b/cmd/mist/assets/html/home.html @@ -1,75 +1,75 @@ - -Ethereum - - - - - - -

Info

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Block number
Peer count
Accounts
Gas price
Mining
Listening
Coinbase
- - - - + + Ethereum + + + + + + +

Info

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Block number
Peer count
Accounts
Gas price
Mining
Listening
Coinbase
+ + + + diff --git a/miner/miner.go b/miner/miner.go index 52dd5687d..8044ef073 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), @@ -213,6 +234,13 @@ func (self *Miner) mine() { minerlogger.Infof("Mining on block. Includes %v transactions", len(transactions)) + x, y := getSeed(chainMan, block) + self.pow, err = ethash.New(append(x, y...), block) + if err != nil { + fmt.Println("err", err) + return + } + // Find a valid nonce nonce := self.pow.Search(block, self.powQuitCh) if nonce != nil { -- cgit v1.2.3