Skip to content

Commit

Permalink
fix synchronization issues hyperledger-iroha#1247
Browse files Browse the repository at this point in the history
Signed-off-by: Moonraker <[email protected]>
  • Loading branch information
Solonets committed Apr 20, 2018
1 parent f78314f commit 58c9eec
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions irohad/consensus/yac/impl/yac_gate_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ namespace iroha {
})
// need only the first
.first()
.retry()
.subscribe(
// if load is successful from at least one node
[subscriber](auto block) {
Expand Down
5 changes: 5 additions & 0 deletions irohad/consensus/yac/impl/yac_gate_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ namespace iroha {
std::shared_ptr<network::BlockLoader> block_loader,
uint64_t delay);
void vote(const shared_model::interface::Block &) override;
/**
* method called when commit recived
* assumes to retrieve a block eventually
* @return observable with the Block commited
*/
rxcpp::observable<std::shared_ptr<shared_model::interface::Block>>
on_commit() override;

Expand Down
54 changes: 54 additions & 0 deletions test/module/irohad/consensus/yac/yac_gate_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,57 @@ TEST_F(YacGateTest, LoadBlockWhenDifferentCommit) {

ASSERT_TRUE(gate_wrapper.validate());
}

/**
* @given yac gate
* @when recives new commit different to the one it voted for
* @then polls nodes for the block with corresponding hash until it succeed,
* (reciving none on the first poll)
*/
TEST_F(YacGateTest, LoadBlockWhenDifferentCommitFailFirst) {
// Vote for block => receive different block => load committed block

// make blocks
EXPECT_CALL(*block_creator, on_block())
.WillOnce(Return(rxcpp::observable<>::just(expected_block)));

// make hash from block
EXPECT_CALL(*hash_provider, makeHash(_)).WillOnce(Return(expected_hash));

// generate order of peers
EXPECT_CALL(*peer_orderer, getOrdering(_))
.WillOnce(Return(ClusterOrdering::create({mk_peer("fake_node")})));

EXPECT_CALL(*hash_gate, vote(expected_hash, _)).Times(1);

// expected values
expected_hash = YacHash("actual_proposal", "actual_block");

message.hash = expected_hash;

commit_message = CommitMessage({message});
expected_commit = rxcpp::observable<>::just(commit_message);

// yac consensus
EXPECT_CALL(*hash_gate, on_commit()).WillOnce(Return(expected_commit));

// convert yac hash to model hash
EXPECT_CALL(*hash_provider, toModelHash(expected_hash))
.WillOnce(Return(expected_block->hash()));

// load block
auto sig = expected_block->signatures().begin();
auto &pubkey = (*sig)->publicKey();
EXPECT_CALL(*block_loader, retrieveBlock(pubkey, expected_block->hash()))
.WillOnce(Return(boost::none))
.WillOnce(Return(expected_block));

init();

// verify that yac gate emit expected block
auto gate_wrapper = make_test_subscriber<CallExact>(gate->on_commit(), 1);
gate_wrapper.subscribe(
[this](auto block) { ASSERT_EQ(*block, *expected_block); });

ASSERT_TRUE(gate_wrapper.validate());
}

0 comments on commit 58c9eec

Please sign in to comment.