-
Notifications
You must be signed in to change notification settings - Fork 20.2k
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: avoid modification of accountSet cache in tx_pool #21159
Conversation
This change looks OK, but I would like to know if the re-use of the cache causes a bug. If there is a bug in txpool which is fixed by this change, we should add a test for that. |
As I see, re-use of this cache may not cause a bug here because accountSet.cache is only used as a return value in function
|
core/tx_pool.go
Outdated
@@ -1032,8 +1032,8 @@ func (pool *TxPool) runReorg(done chan struct{}, reset *txpoolResetRequest, dirt | |||
delete(events, addr) | |||
} | |||
} | |||
// Reset needs promote for all addresses | |||
promoteAddrs = promoteAddrs[:0] | |||
// make a capable slice to avoid modify accountSet cache. |
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.
The old comment was referring to the logical flow. Please add that back. The new comments seems to be just a text-explanation of the line below, which doesn't make much sense. Please revert that.
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
28f5189
to
62dde91
Compare
This looks a bit odd to me: https://github.com/ethereum/go-ethereum/pull/21159/files#diff-8fecce9bb4c486ebc22226cf681416e2R1020-R1022 Basically, if var promoteAddrs []common.Address
if dirtyAccounts != nil && reset != nil {
promoteAddrs = dirtyAccounts.flatten()
}
pool.mu.Lock()
if reset != nil { Not sure if I'm missing some subtle side-effect |
Yes! I agree that if |
62dde91
to
aaeac55
Compare
when runReorg, we may copy the dirtyAccounts' accountSet cache to promoteAddrs in which accounts will be promoted, however, if we have reset request at the same time, we may reuse promoteAddrs and modify the cache content which is against the original intention of accountSet cache. So, we need to make a new slice here to avoid modify accountSet cache.
aaeac55
to
0b748ef
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
@@ -1023,7 +1023,8 @@ func (pool *TxPool) runReorg(done chan struct{}, reset *txpoolResetRequest, dirt | |||
defer close(done) | |||
|
|||
var promoteAddrs []common.Address | |||
if dirtyAccounts != nil { | |||
if dirtyAccounts != nil && reset != nil { |
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.
should be reset == nil
, right?
* core: avoid modification of accountSet cache in tx_pool when runReorg, we may copy the dirtyAccounts' accountSet cache to promoteAddrs in which accounts will be promoted, however, if we have reset request at the same time, we may reuse promoteAddrs and modify the cache content which is against the original intention of accountSet cache. So, we need to make a new slice here to avoid modify accountSet cache. * core: fix flatten condition + comment Co-authored-by: Felix Lange <fjl@twurst.com>
* core: avoid modification of accountSet cache in tx_pool when runReorg, we may copy the dirtyAccounts' accountSet cache to promoteAddrs in which accounts will be promoted, however, if we have reset request at the same time, we may reuse promoteAddrs and modify the cache content which is against the original intention of accountSet cache. So, we need to make a new slice here to avoid modify accountSet cache. * core: fix flatten condition + comment Co-authored-by: Felix Lange <fjl@twurst.com>
when runReorg, we may copy the dirtyAccounts' accountSet cache to promoteAddrs
in which accounts will be promoted, however, if we have reset request at the
same time, we may reuse promoteAddrs and modify the cache content which is
against the original intention of accountSet cache. So, we need to make a new
slice here to avoid modify accountSet cache.