Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

Change managing way for round queue #2151

Merged
merged 8 commits into from
Mar 12, 2019
Merged

Change managing way for round queue #2151

merged 8 commits into from
Mar 12, 2019

Conversation

luckychess
Copy link
Contributor

Description of the Change

Pull request fixes a race with proposal retrieval

Benefits

No race ^^

Possible Drawbacks

Tests code could be better for erase case.

Signed-off-by: Konstantin Munichev <[email protected]>
Copy link
Contributor

@MBoldyrev MBoldyrev left a comment

Choose a reason for hiding this comment

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

As we now have the ordered proposals map, there seems to be no need for rounds erasure queue, if we as remove the map elements using the sorting by round. Could you remove that queue and rewrite tryErase using map order?

@neewy neewy added this to the rc5 milestone Mar 11, 2019
muratovv
muratovv previously approved these changes Mar 11, 2019
consensus::Round current_round = {i + 1, commit_round.reject_round};
auto proposal = os->onRequestProposal({i + 1, commit_round.reject_round});

if (current_round.block_round >= last_round.block_round) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems, if else ladder could be refactored with inline function and used twice for this and EraseReject tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, it's possible but these 2 code fragments are actually a bit different (using .block_round in the first one instead of .reject_round in the second) so I guess the resulting code will be too difficult to read.

Signed-off-by: Konstantin Munichev <[email protected]>
@luckychess luckychess requested review from MBoldyrev and muratovv and removed request for MBoldyrev March 11, 2019 12:19
@@ -334,14 +334,16 @@ TEST_F(OnDemandOsTest, PassMissingTransaction) {
auto proposal = os->onRequestProposal(target_round);

// since we only sent one transaction,
// if the proposal is present, there is no need to check for that specific tx
// if the proposal is present, there is no need to check for that specific
Copy link
Contributor

Choose a reason for hiding this comment

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

Changes in this file are not really required by clang-format and can be reverted.

proposal_map_.erase(round);
log_->info("tryErase: erased {}", round);
round_queue_.pop();
while (proposal_map_.size() > number_of_proposals_) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would rather use the previous logic, where this loop operated only on subset of proposal_map_ with map.round < packNextProposals.round.
I would suggest to first it = proposal_map_.find(round), and then operate on range(proposal_map_.begin(), it).

Copy link
Contributor

Choose a reason for hiding this comment

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

this makes sense. It could be also done by passing current round to tryErase and adding condition

Suggested change
while (proposal_map_.size() > number_of_proposals_) {
while (proposal_map_.size() > number_of_proposals_ and proposal_map_.begin()->first < current_round) {

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that the first condition should only consider the subset, e.g. size(range(proposal_map_.begin(), it)) > number_of_proposals_ instead of proposal_map_.size() > number_of_proposals_.

Signed-off-by: Konstantin Munichev <[email protected]>
@muratovv muratovv removed their request for review March 12, 2019 07:08
auto proposal_range_size = boost::size(
boost::make_iterator_range(proposal_map_.begin(), current_proposal));

while (proposal_range_size > number_of_proposals_
Copy link
Contributor

Choose a reason for hiding this comment

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

quite a strange condition, because proposal_range_size is unchanged in the loop. maybe

Suggested change
while (proposal_range_size > number_of_proposals_
while (proposal_range_size-- > number_of_proposals_

boost::make_iterator_range(proposal_map_.begin(), current_proposal));

while (proposal_range_size > number_of_proposals_
and proposal_map_.begin()->first < current_round) {
Copy link
Contributor

Choose a reason for hiding this comment

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

and if I get the code right, this can be converted into an assertion

@muratovv muratovv dismissed their stale review March 12, 2019 09:04

I am not a reviewer anymore:(

@luckychess luckychess merged commit dc5f931 into develop Mar 12, 2019
@luckychess luckychess deleted the fix/consensus_race branch March 12, 2019 18:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants