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

[Minor bug / minor fix] TxPool - fix inconsistent counters (estimators) #1842

Merged
merged 5 commits into from
Jun 1, 2020

Conversation

andreibancioiu
Copy link
Collaborator

@andreibancioiu andreibancioiu commented Jun 1, 2020

Original conversation in PR 1802.

Fixed some inconsistent counters for senders and transactions within the internal structures of the transactions pool. Inconsistencies could occur in case of high concurrency and / or concurrent removals (eviction plus removal due to commit / finalize). The bug was mostly benign, but if it were, say, thousands of such events, the counters would have become slightly off and therefore could have lead - in extreme cases - to OOM (since eviction would have been based on bad, low counters).

Extra - fixed some linting issues within package storage/immunitycache.

Details of the fix:

  • txListBySenderMap.addSender(): counter is consistent because the function is called under txListBySenderMap's global mutex
  • txListBySenderMap.removeSender(): fixed
  • txByHashMap.addTx(): counter is consistent because we use "SetIfAbsent"
  • txByHashMap.removeTx(): fixed

@andreibancioiu andreibancioiu self-assigned this Jun 1, 2020
@andreibancioiu andreibancioiu added the type:bug Something isn't working label Jun 1, 2020
@SebastianMarian SebastianMarian self-requested a review June 1, 2020 15:21
// we might end up decrementing the counters twice.
// Possible solution: use an "onItemRemoved" callback in the "backingMap"
// to decrement the counters.
tx := item.(*WrappedTransaction)
Copy link
Contributor

Choose a reason for hiding this comment

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

You can check for correct type assertion here, so if will be the case in some strange circumstances you will avoid passing nil to line 46 in estimateTxSize method and also to return nil, true in line 49

tx, ok := item.(*WrappedTransaction)
if !ok {
return nil, false
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed. Though, having something other than *WrappedTransaction in the backingMap would be a critical bug.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed. But for the sake of uncle Bob :)

@andreibancioiu andreibancioiu marked this pull request as ready for review June 1, 2020 15:39
Copy link
Contributor

@LucianMincu LucianMincu left a comment

Choose a reason for hiding this comment

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

System tests passed.

@LucianMincu LucianMincu merged commit 17f4c3f into release-candidate Jun 1, 2020
@LucianMincu LucianMincu deleted the EN-6526-pool branch June 1, 2020 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants