diff options
author | Taylor Gerring <taylor.gerring@gmail.com> | 2014-12-22 01:42:32 +0800 |
---|---|---|
committer | Taylor Gerring <taylor.gerring@gmail.com> | 2014-12-22 01:42:32 +0800 |
commit | 1360f027d9e365242466ca346b2b56f421729d91 (patch) | |
tree | a30ff7292e87583781b682b47d851d0f6e1925fc /miner/miner.go | |
parent | b3629c6f62bd3774eb8858819a8ee07dfb775b73 (diff) | |
parent | 795b14330ad4399ef292835eac452d258dcd7464 (diff) | |
download | dexon-1360f027d9e365242466ca346b2b56f421729d91.tar dexon-1360f027d9e365242466ca346b2b56f421729d91.tar.gz dexon-1360f027d9e365242466ca346b2b56f421729d91.tar.bz2 dexon-1360f027d9e365242466ca346b2b56f421729d91.tar.lz dexon-1360f027d9e365242466ca346b2b56f421729d91.tar.xz dexon-1360f027d9e365242466ca346b2b56f421729d91.tar.zst dexon-1360f027d9e365242466ca346b2b56f421729d91.zip |
Merge pull request #216 from ethereum/develop
Update tests branch from develop
Diffstat (limited to 'miner/miner.go')
-rw-r--r-- | miner/miner.go | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/miner/miner.go b/miner/miner.go index 589144c0c..f63096b63 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -29,6 +29,8 @@ import ( "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/ethutil" + "github.com/ethereum/go-ethereum/pow" + "github.com/ethereum/go-ethereum/pow/ezp" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" @@ -59,7 +61,7 @@ type Miner struct { localTxs map[int]*LocalTx localTxId int - pow core.PoW + pow pow.PoW quitCh chan struct{} powQuitCh chan struct{} @@ -74,7 +76,7 @@ func New(coinbase []byte, eth *eth.Ethereum) *Miner { return &Miner{ eth: eth, powQuitCh: make(chan struct{}), - pow: &core.EasyPow{}, + pow: ezp.New(), mining: false, localTxs: make(map[int]*LocalTx), MinAcceptedGasPrice: big.NewInt(10000000000000), @@ -82,7 +84,7 @@ func New(coinbase []byte, eth *eth.Ethereum) *Miner { } } -func (self *Miner) GetPow() core.PoW { +func (self *Miner) GetPow() pow.PoW { return self.pow } @@ -167,7 +169,6 @@ out: } func (self *Miner) reset() { - println("reset") close(self.powQuitCh) self.powQuitCh = make(chan struct{}) } @@ -192,7 +193,7 @@ func (self *Miner) mine() { // Accumulate all valid transactions and apply them to the new state // Error may be ignored. It's not important during mining - receipts, txs, _, erroneous, err := blockManager.ProcessTransactions(coinbase, block.State(), block, block, transactions) + receipts, txs, _, erroneous, err := blockManager.ApplyTransactions(coinbase, block.State(), block, transactions, true) if err != nil { minerlogger.Debugln(err) } @@ -228,23 +229,33 @@ func (self *Miner) mine() { func (self *Miner) finiliseTxs() types.Transactions { // Sort the transactions by nonce in case of odd network propagation - var txs types.Transactions + actualSize := len(self.localTxs) // See copy below + txs := make(types.Transactions, actualSize+self.eth.TxPool().Size()) - state := self.eth.BlockManager().TransState() + state := self.eth.ChainManager().TransState() // XXX This has to change. Coinbase is, for new, same as key. key := self.eth.KeyManager() - for _, ltx := range self.localTxs { + for i, ltx := range self.localTxs { tx := types.NewTransactionMessage(ltx.To, ethutil.Big(ltx.Value), ethutil.Big(ltx.Gas), ethutil.Big(ltx.GasPrice), ltx.Data) - tx.Nonce = state.GetNonce(self.Coinbase) - state.SetNonce(self.Coinbase, tx.Nonce+1) + tx.SetNonce(state.GetNonce(self.Coinbase)) + state.SetNonce(self.Coinbase, tx.Nonce()+1) tx.Sign(key.PrivateKey()) - txs = append(txs, tx) + txs[i] = tx } - txs = append(txs, self.eth.TxPool().CurrentTransactions()...) - sort.Sort(types.TxByNonce{txs}) + // Faster than append + for _, tx := range self.eth.TxPool().CurrentTransactions() { + if tx.GasPrice().Cmp(self.MinAcceptedGasPrice) >= 0 { + txs[actualSize] = tx + actualSize++ + } + } + + newTransactions := make(types.Transactions, actualSize) + copy(newTransactions, txs[:actualSize]) + sort.Sort(types.TxByNonce{newTransactions}) - return txs + return newTransactions } |