-
Notifications
You must be signed in to change notification settings - Fork 20k
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: make txpool operate on immutable state #15085
Conversation
568076c
to
5b6b535
Compare
core/tx_pool.go
Outdated
for rem.NumberU64() > add.NumberU64() { | ||
discarded = append(discarded, rem.Transactions()...) | ||
if rem = pool.chain.GetBlock(rem.ParentHash(), rem.NumberU64()-1); rem == nil { | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This return
and the ones below - these signify some kind of error, right, that we've been told about a new chain head which somehow lacks parent? Shouldn't that be reported rather than just silently ignored?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I'll add a warning to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see it anywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are all these returns error states? It seems like they should at least log at level ERROR, if not abort entirely.
5b6b535
to
f192220
Compare
There was a problem hiding this 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
for rem.NumberU64() > add.NumberU64() { | ||
discarded = append(discarded, rem.Transactions()...) | ||
if rem = pool.chain.GetBlock(rem.ParentHash(), rem.NumberU64()-1); rem == nil { | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see it anywhere?
core/tx_pool.go
Outdated
for rem.NumberU64() > add.NumberU64() { | ||
discarded = append(discarded, rem.Transactions()...) | ||
if rem = pool.chain.GetBlock(rem.ParentHash(), rem.NumberU64()-1); rem == nil { | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are all these returns error states? It seems like they should at least log at level ERROR, if not abort entirely.
core/tx_pool.go
Outdated
if list.Len() > 0 && list.txs.Get(nonce) == nil { | ||
for _, tx := range list.Cap(0) { | ||
hash := tx.Hash() | ||
log.Warn("Demoting invalidated transaction", "hash", hash) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think all 'should never happen' errors should be level ERROR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, will fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, ptal
f192220
to
40bbde1
Compare
40bbde1
to
da7d57e
Compare
Apparently the transaction pool (and handling in general) had 3 different update pathways:
Unfortunately, the above is a very very bad idea from multiple perspectives:
This PR tries to fix all these races via reducing the transaction pool's API surface to one single entry point: chain head events.
StateAt(head.Root)
). This ensures that even if the blockchain changes concurrently with the transaction pool, no changes leak into the pool without an isolated head event.