Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Commit

Permalink
Merge branch 'devel' into task/parchard/KEP-901
Browse files Browse the repository at this point in the history
  • Loading branch information
paularchard committed Dec 14, 2018
2 parents 464b031 + 299d8dc commit c56b447
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
14 changes: 8 additions & 6 deletions pbft/pbft.cpp
Expand Up @@ -1247,9 +1247,7 @@ pbft::is_valid_newview_message(const pbft_msg& theirs, const bzn_envelope& origi
viewchange_envelopes_from_senders[viewchange_env.sender()] = viewchange_env;
}

pbft_msg ours = this->build_newview(theirs.view(), viewchange_envelopes_from_senders);


pbft_msg ours = this->build_newview(theirs.view(), viewchange_envelopes_from_senders).first;
if (ours.pre_prepare_messages_size() != theirs.pre_prepare_messages_size() )
{
LOG(error) << "is_valid_newview_message - expected " << ours.pre_prepare_messages_size() << " preprepares in new view, found " << theirs.pre_prepare_messages_size();
Expand Down Expand Up @@ -1343,7 +1341,7 @@ pbft::make_newview(
return newview;
}

pbft_msg
std::pair<pbft_msg, uint64_t>
pbft::build_newview(uint64_t new_view, const std::map<uuid_t,bzn_envelope>& viewchange_envelopes_from_senders) const
{
// Computing O (set of new preprepares for new-view message)
Expand All @@ -1356,6 +1354,7 @@ pbft::build_newview(uint64_t new_view, const std::map<uuid_t,bzn_envelope>& view
viewchange.ParseFromString(sender_viewchange_envelope.second.pbft());
max_checkpoint_sequence = std::max(max_checkpoint_sequence, viewchange.sequence());
}
uint64_t next_seq = max_checkpoint_sequence + 1;

// - for each of the 2f+1 viewchange messages
for (const auto& sender_viewchange_envelope : viewchange_envelopes_from_senders)
Expand Down Expand Up @@ -1387,11 +1386,12 @@ pbft::build_newview(uint64_t new_view, const std::map<uuid_t,bzn_envelope>& view
continue;
}
pre_prepares[pre_prepare.sequence()] = this->wrap_message(pre_prepare);
next_seq = std::max(next_seq, pre_prepare.sequence() + 1);
}
}
this->fill_in_missing_pre_prepares(max_checkpoint_sequence, new_view, pre_prepares);

return this->make_newview(new_view, viewchange_envelopes_from_senders, pre_prepares);
return std::make_pair(this->make_newview(new_view, viewchange_envelopes_from_senders, pre_prepares), next_seq);
}

void
Expand Down Expand Up @@ -1457,7 +1457,9 @@ pbft::handle_viewchange(const pbft_msg &msg, const bzn_envelope &original_msg)
viewchange_envelopes_from_senders[sender] = viewchange_envelope;
}

this->broadcast(this->wrap_message(this->build_newview(viewchange->first, viewchange_envelopes_from_senders)));
auto res = this->build_newview(viewchange->first, viewchange_envelopes_from_senders);
this->next_issued_sequence_number = res.second;
this->broadcast(this->wrap_message(res.first));
}

void
Expand Down
2 changes: 1 addition & 1 deletion pbft/pbft.hpp
Expand Up @@ -194,7 +194,7 @@ namespace bzn
// VIEWCHANGE/NEWVIEW Helper methods
static pbft_msg make_viewchange(uint64_t new_view, uint64_t n, const std::unordered_map<bzn::uuid_t, std::string>& stable_checkpoint_proof, const std::unordered_set<std::shared_ptr<bzn::pbft_operation>>& prepared_operations);
pbft_msg make_newview(uint64_t new_view_index, const std::map<uuid_t,bzn_envelope>& viewchange_envelopes_from_senders, const std::map<uint64_t, bzn_envelope>& pre_prepare_messages) const;
pbft_msg build_newview(uint64_t new_view, const std::map<uuid_t,bzn_envelope>& viewchange_envelopes_from_senders) const;
std::pair<pbft_msg, uint64_t> build_newview(uint64_t new_view, const std::map<uuid_t,bzn_envelope>& viewchange_envelopes_from_senders) const;
std::unordered_set<std::shared_ptr<bzn::pbft_operation>> prepared_operations_since_last_checkpoint();
std::map<bzn::checkpoint_t , std::set<bzn::uuid_t>> validate_and_extract_checkpoint_hashes(const pbft_msg &viewchange_message) const;
void save_checkpoint(const pbft_msg& msg);
Expand Down
1 change: 1 addition & 0 deletions pbft/test/pbft_viewchange_test.cpp
Expand Up @@ -426,5 +426,6 @@ namespace bzn
this->pbft->handle_failure();

EXPECT_EQ(this->pbft->view, 2U);
EXPECT_EQ(pbft2->next_issued_sequence_number, 103U);
}
}

0 comments on commit c56b447

Please sign in to comment.