Skip to content

Commit

Permalink
SynchronizerImpl: use incoming message round on matching height
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Lebedev <lebdron@gmail.com>
  • Loading branch information
lebdron committed Oct 12, 2019
1 parent a125397 commit a97d630
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
8 changes: 5 additions & 3 deletions irohad/synchronizer/impl/synchronizer_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,15 @@ namespace iroha {
msg.public_keys);

commit_result.match(
[this](auto &value) {
[this, &msg](auto &value) {
auto &ledger_state = value.value;
assert(ledger_state);
auto new_height = ledger_state->top_block_info.height;
const auto new_height = ledger_state->top_block_info.height;
notifier_.get_subscriber().on_next(
SynchronizationEvent{SynchronizationOutcomeType::kCommit,
consensus::Round{new_height, 0},
new_height != msg.round.block_round
? consensus::Round{new_height, 0}
: msg.round,
std::move(ledger_state)});
},
[this](const auto &error) {
Expand Down
13 changes: 9 additions & 4 deletions test/module/irohad/synchronizer/synchronizer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ TEST_F(SynchronizerTest, ValidWhenSingleCommitSynchronized) {
TEST_F(SynchronizerTest, ValidWhenValidChain) {
DefaultValue<expected::Result<std::unique_ptr<MutableStorage>, std::string>>::
SetFactory(&createMockMutableStorage);
consensus::Round round{kHeight, 1};

EXPECT_CALL(*mutable_factory, createMutableStorage(_)).Times(1);

Expand All @@ -263,13 +264,14 @@ TEST_F(SynchronizerTest, ValidWhenValidChain) {

auto wrapper =
make_test_subscriber<CallExact>(synchronizer->on_commit_chain(), 1);
wrapper.subscribe([this](auto commit_event) {
wrapper.subscribe([this, round](auto commit_event) {
EXPECT_EQ(this->ledger_peers, commit_event.ledger_state->ledger_peers);
ASSERT_EQ(commit_event.sync_outcome, SynchronizationOutcomeType::kCommit);
ASSERT_EQ(commit_event.round, round);
});

gate_outcome.get_subscriber().on_next(consensus::VoteOther(
consensus::Round{kHeight, 1}, ledger_state, public_keys, hash));
gate_outcome.get_subscriber().on_next(
consensus::VoteOther(round, ledger_state, public_keys, hash));

ASSERT_TRUE(wrapper.validate());
}
Expand Down Expand Up @@ -589,9 +591,12 @@ TEST_F(SynchronizerTest, OneRoundDifference) {

auto wrapper =
make_test_subscriber<CallExact>(synchronizer->on_commit_chain(), 1);
wrapper.subscribe([this](auto commit_event) {
wrapper.subscribe([this,
expected_round = consensus::Round{commit_message->height(),
0}](auto commit_event) {
EXPECT_EQ(this->ledger_peers, commit_event.ledger_state->ledger_peers);
ASSERT_EQ(commit_event.sync_outcome, SynchronizationOutcomeType::kCommit);
ASSERT_EQ(commit_event.round, expected_round);
});

gate_outcome.get_subscriber().on_next(consensus::Future(
Expand Down

0 comments on commit a97d630

Please sign in to comment.