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

Fix potential mem-leak from hotstuff #1514

Merged
merged 3 commits into from Oct 22, 2021

Conversation

zhangchiqing
Copy link
Member

@zhangchiqing zhangchiqing commented Oct 22, 2021

This PR fixed a potential mem leak in hotstuff, where when a proposerVote was stored, the index for pruning was not updated, which leads to a potential memory leak.

@@ -835,6 +835,27 @@ func (as *AggregatorSuite) TestNonePruneAfterBlock() {
require.Equal(as.T(), 3, votingStatusLen)
}

// receive the block for view 2,3,4,5
// prune by view 5, should be all pruned
func (as *AggregatorSuite) TestPruneAll() {
Copy link
Member Author

Choose a reason for hiding this comment

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

This test case was able to reproduce the issue. Without the fix, this test will fail

@@ -153,6 +153,15 @@ func (va *VoteAggregator) StoreProposerVote(vote *model.Vote) bool {
return false
}
va.proposerVotes[vote.BlockID] = vote
// update viewToBlockIDSet
Copy link
Member Author

Choose a reason for hiding this comment

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

We can't use updateState here, even though that will that also update the viewToBlockIDSet which is used for pruning.

The reason is that the proposer Vote might be invalid, which we don't want to update the state with.

However, the viewToBlockIDSet is safe to update alone, since it's purely used for pruning.

Copy link
Member

Choose a reason for hiding this comment

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

proposer Vote might be invalid

Good observation. From the perspective of VoteAggregator, the proposer vote is still unchecked. A double voting attempt cannot be attributed without checking the vote first.

I was thinking that the EventHander always validates the proposer vote first:

_, err := v.ValidateVote(proposal.ProposerVote(), block)

Nevertheless, this happens outside of the VoteAggregator and we should probably not rely on external components for critical validity checks.

Copy link
Member

@AlexHentschel AlexHentschel left a comment

Choose a reason for hiding this comment

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

thanks for implementing the fix and adding a test

@@ -153,6 +153,15 @@ func (va *VoteAggregator) StoreProposerVote(vote *model.Vote) bool {
return false
}
va.proposerVotes[vote.BlockID] = vote
// update viewToBlockIDSet
Copy link
Member

Choose a reason for hiding this comment

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

proposer Vote might be invalid

Good observation. From the perspective of VoteAggregator, the proposer vote is still unchecked. A double voting attempt cannot be attributed without checking the vote first.

I was thinking that the EventHander always validates the proposer vote first:

_, err := v.ValidateVote(proposal.ProposerVote(), block)

Nevertheless, this happens outside of the VoteAggregator and we should probably not rely on external components for critical validity checks.

Copy link
Contributor

@synzhu synzhu left a comment

Choose a reason for hiding this comment

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

Thanks for catching this :)

@zhangchiqing zhangchiqing force-pushed the leo/fix-potential-mem-leak-from-hotstuff branch from 5df7142 to f6218fa Compare October 22, 2021 15:36
@codecov-commenter
Copy link

codecov-commenter commented Oct 22, 2021

Codecov Report

Merging #1514 (1b03335) into master (5413790) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1514      +/-   ##
==========================================
- Coverage   55.09%   55.09%   -0.01%     
==========================================
  Files         521      521              
  Lines       32514    32521       +7     
==========================================
+ Hits        17914    17917       +3     
- Misses      12192    12195       +3     
- Partials     2408     2409       +1     
Flag Coverage Δ
unittests 55.09% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...nsensus/hotstuff/voteaggregator/vote_aggregator.go 80.00% <100.00%> (+0.88%) ⬆️
module/component/component.go 38.83% <0.00%> (-1.95%) ⬇️
...sus/approvals/assignment_collector_statemachine.go 40.38% <0.00%> (-1.93%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5413790...1b03335. Read the comment docs.

@zhangchiqing zhangchiqing merged commit 72fd04c into master Oct 22, 2021
@zhangchiqing zhangchiqing deleted the leo/fix-potential-mem-leak-from-hotstuff branch October 22, 2021 18:08
zhangchiqing added a commit that referenced this pull request Oct 22, 2021
* fix potential mem-leak from hotstuff (#1514)

* Kan/clean up secondary result index (#1515)

* Remove from secondary index

* Add tests for caches

* add concurrency test

* Apply suggestions from code review

Co-authored-by: Simon Zhu <simon.zsiyan@gmail.com>

Co-authored-by: Leo Zhang (zhangchiqing) <zhangchiqing@gmail.com>
Co-authored-by: Simon Zhu <simon.zsiyan@gmail.com>

* disable cache metrics

Co-authored-by: Kan Zhang <kan@axiomzen.co>
Co-authored-by: Simon Zhu <simon.zsiyan@gmail.com>
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.

None yet

4 participants