diff --git a/core/state_prefetcher.go b/core/state_prefetcher.go index bf0a6b80c..a2c2df16a 100644 --- a/core/state_prefetcher.go +++ b/core/state_prefetcher.go @@ -127,23 +127,21 @@ func (p *statePrefetcher) PrefetchMining(txs *types.TransactionsByPriceAndNonce, go func(txset *types.TransactionsByPriceAndNonce) { count := 0 for { - tx := txset.Peek() - if tx == nil { - return - } select { case <-interruptCh: return default: - } - if count++; count%checkInterval == 0 { - if *txCurr == nil { + if count++; count%checkInterval == 0 { + txset.Forward(*txCurr) + } + tx := txset.Peek() + if tx == nil { return } - txset.Forward(*txCurr) + txCh <- tx + txset.Shift() + } - txCh <- tx - txset.Shift() } }(txs) } diff --git a/core/types/transaction.go b/core/types/transaction.go index e95cec25a..5c8d04c01 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -506,7 +506,9 @@ func (t *TransactionsByPriceAndNonce) CurrentSize() int { //Forward moves current transaction to be the one which is one index after tx func (t *TransactionsByPriceAndNonce) Forward(tx *Transaction) { if tx == nil { - t.heads = t.heads[0:0] + if len(t.heads) > 0 { + t.heads = t.heads[0:0] + } return } //check whether target tx exists in t.heads diff --git a/core/types/transaction_test.go b/core/types/transaction_test.go index c81b7b864..a5fbb5092 100644 --- a/core/types/transaction_test.go +++ b/core/types/transaction_test.go @@ -392,7 +392,7 @@ func TestTransactionForward(t *testing.T) { } tmp := txset.Copy() - for j := 0; j < 10; j++ { + for j := 0; j < 11; j++ { txset = tmp.Copy() txsetCpy = tmp.Copy() i := 0 @@ -400,6 +400,9 @@ func TestTransactionForward(t *testing.T) { txset.Shift() } tx := txset.Peek() + if tx == nil { + continue + } txsetCpy.Forward(tx) txCpy := txsetCpy.Peek() if txCpy == nil {