Skip to content

Commit 8dbca75

Browse files
committed
Skip mining on transactions that don't meet the min accepted gas price
1 parent 3db9c80 commit 8dbca75

3 files changed

Lines changed: 32 additions & 26 deletions

File tree

‎core/block_manager.go‎

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ func (sm *BlockManager) ProcessWithParent(block, parent *types.Block) (td *big.I
231231
return
232232
}
233233

234-
_, err = sm.TransitionState(state, parent, block)
234+
receipts, err := sm.TransitionState(state, parent, block)
235235
if err != nil {
236236
return
237237
}
@@ -242,26 +242,22 @@ func (sm *BlockManager) ProcessWithParent(block, parent *types.Block) (td *big.I
242242
return
243243
}
244244

245-
/*
246-
receiptSha := types.DeriveSha(receipts)
247-
if bytes.Compare(receiptSha, block.ReceiptSha) != 0 {
248-
err = fmt.Errorf("validating receipt root. received=%x got=%x", block.ReceiptSha, receiptSha)
249-
return
250-
}
251-
*/
245+
receiptSha := types.DeriveSha(receipts)
246+
if bytes.Compare(receiptSha, block.ReceiptSha) != 0 {
247+
err = fmt.Errorf("validating receipt root. received=%x got=%x", block.ReceiptSha, receiptSha)
248+
return
249+
}
252250

253251
if err = sm.AccumelateRewards(state, block, parent); err != nil {
254252
return
255253
}
256254

257-
/*
258-
//block.receipts = receipts // although this isn't necessary it be in the future
259-
rbloom := types.CreateBloom(receipts)
260-
if bytes.Compare(rbloom, block.LogsBloom) != 0 {
261-
err = fmt.Errorf("unable to replicate block's bloom=%x", rbloom)
262-
return
263-
}
264-
*/
255+
//block.receipts = receipts // although this isn't necessary it be in the future
256+
rbloom := types.CreateBloom(receipts)
257+
if bytes.Compare(rbloom, block.LogsBloom) != 0 {
258+
err = fmt.Errorf("unable to replicate block's bloom=%x", rbloom)
259+
return
260+
}
265261

266262
state.Update(ethutil.Big0)
267263

‎core/transaction_pool.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,6 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
115115
return fmt.Errorf("tx.v != (28 || 27)")
116116
}
117117

118-
if tx.GasPrice.Cmp(MinGasPrice) < 0 {
119-
return fmt.Errorf("Gas price to low. Require %v > Got %v", MinGasPrice, tx.GasPrice)
120-
}
121-
122118
// Get the sender
123119
sender := pool.Ethereum.BlockManager().CurrentState().GetAccount(tx.Sender())
124120

@@ -169,6 +165,10 @@ func (self *TxPool) Add(tx *types.Transaction) error {
169165
return nil
170166
}
171167

168+
func (self *TxPool) Size() int {
169+
return self.pool.Len()
170+
}
171+
172172
func (pool *TxPool) CurrentTransactions() []*types.Transaction {
173173
pool.mutex.Lock()
174174
defer pool.mutex.Unlock()

‎miner/miner.go‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,23 +228,33 @@ func (self *Miner) mine() {
228228

229229
func (self *Miner) finiliseTxs() types.Transactions {
230230
// Sort the transactions by nonce in case of odd network propagation
231-
var txs types.Transactions
231+
actualSize := len(self.localTxs) // See copy below
232+
txs := make(types.Transactions, actualSize+self.eth.TxPool().Size())
232233

233234
state := self.eth.BlockManager().TransState()
234235
// XXX This has to change. Coinbase is, for new, same as key.
235236
key := self.eth.KeyManager()
236-
for _, ltx := range self.localTxs {
237+
for i, ltx := range self.localTxs {
237238
tx := types.NewTransactionMessage(ltx.To, ethutil.Big(ltx.Value), ethutil.Big(ltx.Gas), ethutil.Big(ltx.GasPrice), ltx.Data)
238239
tx.Nonce = state.GetNonce(self.Coinbase)
239240
state.SetNonce(self.Coinbase, tx.Nonce+1)
240241

241242
tx.Sign(key.PrivateKey())
242243

243-
txs = append(txs, tx)
244+
txs[i] = tx
244245
}
245246

246-
txs = append(txs, self.eth.TxPool().CurrentTransactions()...)
247-
sort.Sort(types.TxByNonce{txs})
247+
// Faster than append
248+
for _, tx := range self.eth.TxPool().CurrentTransactions() {
249+
if tx.GasPrice.Cmp(self.MinAcceptedGasPrice) >= 0 {
250+
txs[actualSize] = tx
251+
actualSize++
252+
}
253+
}
254+
255+
newTransactions := make(types.Transactions, actualSize)
256+
copy(newTransactions, txs[:actualSize])
257+
sort.Sort(types.TxByNonce{newTransactions})
248258

249-
return txs
259+
return newTransactions
250260
}

0 commit comments

Comments
 (0)