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

core: fix queued transaction eviction #21300

Merged
merged 2 commits into from
Jul 24, 2020

Conversation

rjl493456442
Copy link
Member

@rjl493456442 rjl493456442 commented Jul 7, 2020

This PR is the successor of #21119 by dropping the beats field in txpool.

@holiman @villanuevawill Please take a look if the PR is good to you guys.

If we want to merge this PR, please don't squash into a single commit, would be nice to keep the commit from vill

@rjl493456442 rjl493456442 force-pushed the txpool-fix-queued-evictions branch 2 times, most recently from 5c0946a to 534ba56 Compare July 8, 2020 08:31
@villanuevawill
Copy link
Contributor

villanuevawill commented Jul 8, 2020

@rjl493456442 I'd be curious to understand the progression here. This is mostly identical to the initial solution I included, however, this only updates the beat when the first transaction is queued (on promotion as well, which was in the initial PR). So if an account has no promotions for the lifetime, all new queued transactions will be ejected based on when the first queue item was included. Is this the intended behavior? If we have no recent promotions, this is essentially what will happen now:

  1. tx1 added to the queue
  2. tx2 added to the queue just before the config.lifetime duration has passed
  3. config.lifetime duration passes and both transactions are evicted
  4. tx3 added again to the queue right after eviction (stays for the config.lifetime duration)

This does fix the initial issue, but doesn't seem to be as consistent in its behavior.
re: conversations here:
#21119 (comment)
#21119 (comment)

The initial solution which this PR follows is in this commit: 6f8a7f6

@holiman
Copy link
Contributor

holiman commented Jul 8, 2020

Gary and I discussed it a bit, before this PR was made. So the original PR pivoted on this point

For the latter one, I think the best solution may record the timestamp of each transaction(but tbh not sure whether it's worthwhile to add this complexity).
Yes, this would be ideal.

And then per-tx timestamps were added. And suddenly there was both per-tx timestamp and per-account timestamp, which seemed kind of odd. And then Gary removed the per-account timestamp, to have only the per-tx ones.

However, the effect of that was that it added a lot of processing, since the tx handling has to flatten the lists and iterate all txs in the loop, instead of just checking one timestamp. So we agreed that maybe it would be better to focus on the original implementation by Peter, which used only one timestamp per account.

And yeah, we seem to have circled back to your original PR :) (more or less -- they're not identical, but they seem to be very similar).

@villanuevawill
Copy link
Contributor

However, the effect of that was that it added a lot of processing, since the tx handling has to flatten the lists and iterate all txs in the loop, instead of just checking one timestamp. So we agreed that maybe it would be better to focus on the original implementation by Peter, which used only one timestamp per account.

Makes sense - hopefully, I was helpful here. I'll likely put up some other PRs/bugfixes in the near term (looking at the backlog).

@rjl493456442
Copy link
Member Author

rjl493456442 commented Jul 9, 2020

@villanuevawill Hi, I would like to apologize first for the first suggestions I made. Recording the timestamp for each transaction is not a good idea. After reworking based on your code, I think I understand the original mechanism better so I choose to come back to the initial version(+ some fixes).

Makes sense - hopefully, I was helpful here.

We really appreciate your contribution, thanks for digging out the issue and open the initial fix PR!

@rjl493456442 rjl493456442 force-pushed the txpool-fix-queued-evictions branch from 2fca74d to f8aaa0e Compare July 14, 2020 02:52
Copy link
Contributor

@holiman holiman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

core/tx_pool.go Outdated
pool.removeTx(tx.Hash(), true)
}
queuedEvictionMeter.Mark(int64(size))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, please inline int64(len(list)). Seems weird to pre-calculate this field and store it. I was expecting something else to be done with it later.

core/tx_pool.go Outdated
@@ -618,6 +622,9 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err e
pool.journalTx(from, tx)
pool.queueTxEvent(tx)
log.Trace("Pooled new executable transaction", "hash", hash, "from", from, "to", tx.To())

// Successfully promotion, bump the heartbeat
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Successfully" -> "Successful"

core/tx_pool.go Outdated
pool.pendingNonces.set(addr, tx.Nonce()+1)

// Successfully promotion, bump the heartbeat
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Successfully" -> "Successful"

@karalabe karalabe added this to the 1.9.18 milestone Jul 24, 2020
villanuevawill and others added 2 commits July 24, 2020 11:11
Solves issue#20582. Non-executable transactions should not be evicted on each tick if there are no promote transactions or if a pending/reset empties the pending list. Tests and logging expanded to handle these cases in the future.

core/tx_pool: use a ts for each tx in the queue, but only update the heartbeat on promotion or pending replaced

queuedTs proper naming
core: address comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants