Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[R4R]fix:Shift panic for zero length of heads #870

Merged
merged 4 commits into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions core/state_prefetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ func (p *statePrefetcher) PrefetchMining(txs *types.TransactionsByPriceAndNonce,
go func(txset *types.TransactionsByPriceAndNonce) {
count := 0
for {
if count++; count%checkInterval == 0 {
txset.Forward(*txCurr)
}
tx := txset.Peek()
if tx == nil {
return
Expand All @@ -136,12 +139,6 @@ func (p *statePrefetcher) PrefetchMining(txs *types.TransactionsByPriceAndNonce,
return
default:
}
if count++; count%checkInterval == 0 {
if *txCurr == nil {
return
}
txset.Forward(*txCurr)
}
txCh <- tx
txset.Shift()
}
Expand Down
4 changes: 3 additions & 1 deletion core/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion core/types/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,14 +392,17 @@ 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
for ; i < j; i++ {
txset.Shift()
}
tx := txset.Peek()
if tx == nil {
continue
}
txsetCpy.Forward(tx)
txCpy := txsetCpy.Peek()
if txCpy == nil {
Expand Down