Skip to content

Commit

Permalink
Merge pull request #105 from eosiosg/feature/dpos-pbft-bos-upgrade
Browse files Browse the repository at this point in the history
fix pbft testcases
  • Loading branch information
Thaipanda authored Jun 16, 2019
2 parents 8679935 + f8d517b commit 16c2e27
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
6 changes: 4 additions & 2 deletions libraries/chain/pbft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,10 @@ namespace eosio {
}
}
pbft_db.mark_as_prepared(new_view.prepared_cert.block_info.block_id);
transit_to_prepared_state(s);
return;
if (pbft_db.should_prepared()) {
transit_to_prepared_state(s);
return;
}
}

transit_to_committed_state(s, true);
Expand Down
4 changes: 2 additions & 2 deletions libraries/chain/pbft_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -973,8 +973,8 @@ namespace eosio {

bool pbft_database::should_stop_view_change(const pbft_view_change &vc) {
auto lscb_num = ctrl.last_stable_checkpoint_block_num();
return lscb_num > vc.prepared_cert.block_info.block_num()
&& lscb_num > vc.stable_checkpoint.block_info.block_num();
auto vc_lscb = vc.stable_checkpoint.block_info.block_num();
return vc_lscb > 0 && lscb_num > vc_lscb;
}

vector<vector<block_info_type>> pbft_database::fetch_fork_from(vector<block_info_type> &block_infos) {
Expand Down
12 changes: 9 additions & 3 deletions unittests/pbft_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ BOOST_AUTO_TEST_CASE(view_change_validation) {
tester.produce_blocks(1);

BOOST_CHECK_EQUAL(ctrl.is_pbft_enabled(), true);
BOOST_CHECK_EQUAL(ctrl.head_block_num(), 101);
BOOST_CHECK_EQUAL(ctrl.head_block_num(), 102);


for(int i = 0; i< pbft_ctrl.view_change_timeout; i++){
Expand All @@ -217,8 +217,14 @@ BOOST_AUTO_TEST_CASE(view_change_validation) {
auto vcc = pbft_ctrl.pbft_db.generate_view_changed_certificate(new_view);
auto nv_msg = pbft_ctrl.pbft_db.send_pbft_new_view(vcc, new_view);

nv_msg.common.sender = tester::get_public_key( N(bob), "active");
BOOST_CHECK_EQUAL(pbft_ctrl.pbft_db.is_valid_new_view(nv_msg), false);
nv_msg.common.sender = tester::get_public_key( N(carol), "active");
auto nv_flag = false;
try {
nv_flag = pbft_ctrl.pbft_db.is_valid_new_view(nv_msg);
} catch (fc::exception) {
nv_flag = false;
}
BOOST_CHECK_EQUAL(nv_flag, false);
}

BOOST_AUTO_TEST_CASE(switch_fork_when_accept_new_view_with_prepare_certificate_on_short_fork) {
Expand Down

0 comments on commit 16c2e27

Please sign in to comment.