aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-12-05 06:54:07 +0800
committerobscuren <geffobscura@gmail.com>2014-12-05 06:54:07 +0800
commit8dbca75d85553f2d9451ee563a919850f05ea1dd (patch)
tree31fbd960506f216eb0c0dc394b1ce7b4014210d5
parent3db9c8007086e0735695a6477c21056737519db9 (diff)
downloaddexon-8dbca75d85553f2d9451ee563a919850f05ea1dd.tar.gz
dexon-8dbca75d85553f2d9451ee563a919850f05ea1dd.tar.zst
dexon-8dbca75d85553f2d9451ee563a919850f05ea1dd.zip
Skip mining on transactions that don't meet the min accepted gas price
-rw-r--r--core/block_manager.go28
-rw-r--r--core/transaction_pool.go8
-rw-r--r--miner/miner.go22
3 files changed, 32 insertions, 26 deletions
diff --git a/core/block_manager.go b/core/block_manager.go
index b648166ec..909f26a1b 100644
--- a/core/block_manager.go
+++ b/core/block_manager.go
@@ -231,7 +231,7 @@ func (sm *BlockManager) ProcessWithParent(block, parent *types.Block) (td *big.I
return
}
- _, err = sm.TransitionState(state, parent, block)
+ receipts, err := sm.TransitionState(state, parent, block)
if err != nil {
return
}
@@ -242,26 +242,22 @@ func (sm *BlockManager) ProcessWithParent(block, parent *types.Block) (td *big.I
return
}
- /*
- receiptSha := types.DeriveSha(receipts)
- if bytes.Compare(receiptSha, block.ReceiptSha) != 0 {
- err = fmt.Errorf("validating receipt root. received=%x got=%x", block.ReceiptSha, receiptSha)
- return
- }
- */
+ receiptSha := types.DeriveSha(receipts)
+ if bytes.Compare(receiptSha, block.ReceiptSha) != 0 {
+ err = fmt.Errorf("validating receipt root. received=%x got=%x", block.ReceiptSha, receiptSha)
+ return
+ }
if err = sm.AccumelateRewards(state, block, parent); err != nil {
return
}
- /*
- //block.receipts = receipts // although this isn't necessary it be in the future
- rbloom := types.CreateBloom(receipts)
- if bytes.Compare(rbloom, block.LogsBloom) != 0 {
- err = fmt.Errorf("unable to replicate block's bloom=%x", rbloom)
- return
- }
- */
+ //block.receipts = receipts // although this isn't necessary it be in the future
+ rbloom := types.CreateBloom(receipts)
+ if bytes.Compare(rbloom, block.LogsBloom) != 0 {
+ err = fmt.Errorf("unable to replicate block's bloom=%x", rbloom)
+ return
+ }
state.Update(ethutil.Big0)
diff --git a/core/transaction_pool.go b/core/transaction_pool.go
index c48d3d8a4..1d1f478e4 100644
--- a/core/transaction_pool.go
+++ b/core/transaction_pool.go
@@ -115,10 +115,6 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
return fmt.Errorf("tx.v != (28 || 27)")
}
- if tx.GasPrice.Cmp(MinGasPrice) < 0 {
- return fmt.Errorf("Gas price to low. Require %v > Got %v", MinGasPrice, tx.GasPrice)
- }
-
// Get the sender
sender := pool.Ethereum.BlockManager().CurrentState().GetAccount(tx.Sender())
@@ -169,6 +165,10 @@ func (self *TxPool) Add(tx *types.Transaction) error {
return nil
}
+func (self *TxPool) Size() int {
+ return self.pool.Len()
+}
+
func (pool *TxPool) CurrentTransactions() []*types.Transaction {
pool.mutex.Lock()
defer pool.mutex.Unlock()
diff --git a/miner/miner.go b/miner/miner.go
index f9b8a9c22..c350eb1a8 100644
--- a/miner/miner.go
+++ b/miner/miner.go
@@ -228,23 +228,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()
// 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.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
}