Skip to content

Commit

Permalink
Merge pull request EOSIO#113 from eosiosg/feature/dpos-pbft-bos-upgrade
Browse files Browse the repository at this point in the history
hot fix: reserve prepare
  • Loading branch information
Thaipanda authored Jul 4, 2019
2 parents 8697a84 + ccd6dde commit ed3ef5b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
5 changes: 4 additions & 1 deletion libraries/chain/pbft_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ namespace eosio {
auto lib = ctrl.last_irreversible_block_id();
if (lib == block_id_type()) return true;
auto forks = ctrl.fork_db().fetch_branch_from(in, lib);
return !forks.first.empty() && forks.second.empty();

//`branch_type` will always contain at least the common ancestor.
//`in` block num should be higher than lib, yet fall on the same branch with lib.
return forks.first.size() > 1 && forks.second.size() == 1;
};


Expand Down
34 changes: 25 additions & 9 deletions plugins/net_plugin/net_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2362,7 +2362,8 @@ namespace eosio {
}
if( !conn->read_delay_timer ) return;
conn->read_delay_timer->expires_from_now( def_read_delay_for_full_write_queue );
conn->read_delay_timer->async_wait([this, weak_conn]( boost::system::error_code ) {
conn->read_delay_timer->async_wait([this, weak_conn]( boost::system::error_code ec ) {
if ( ec == boost::asio::error::operation_aborted ) return;
auto conn = weak_conn.lock();
if( !conn ) return;
start_read_message( conn );
Expand Down Expand Up @@ -2834,18 +2835,28 @@ namespace eosio {

if ( msg.end_block == 0 || msg.end_block < msg.start_block) return;

fc_dlog(logger, "received checkpoint request message ${m}", ("m", msg));
fc_dlog(logger, "received checkpoint request message ${m}, from ${p}", ("m", msg)("p", c->peer_name()));

if ( msg.end_block - msg.start_block > pbft_checkpoint_granularity * 100) {
fc_dlog(logger, "request range too large");
return;
}

vector<pbft_stable_checkpoint> scp_stack;
controller &cc = my_impl->chain_plug->chain();
pbft_controller &pcc = my_impl->chain_plug->pbft_ctrl();

auto end_block = std::min(msg.end_block, cc.last_stable_checkpoint_block_num());

for (auto i = end_block; i >= msg.start_block && i>0; --i) {
auto bid = cc.get_block_id_for_num(i);
auto scp = pcc.pbft_db.get_stable_checkpoint_by_id(bid);
if (!scp.empty()) {
scp_stack.push_back(scp);
try {
auto bid = cc.get_block_id_for_num(i);
auto scp = pcc.pbft_db.get_stable_checkpoint_by_id(bid);
if (!scp.empty()) {
scp_stack.push_back(scp);
}
} catch (...) {
break;
}
}

Expand Down Expand Up @@ -3080,6 +3091,8 @@ namespace eosio {
}

void net_plugin_impl::clean_expired_pbft_messages(){
pbft_message_cache_ticker ();

auto itr = pbft_message_cache.begin();
auto now = time_point::now();

Expand Down Expand Up @@ -3249,11 +3262,14 @@ namespace eosio {
void net_plugin_impl::pbft_message_cache_ticker() {
pbft_message_cache_timer->expires_from_now (pbft_message_cache_tick_interval);
pbft_message_cache_timer->async_wait ([this](boost::system::error_code ec) {
pbft_message_cache_ticker ();
if (ec) {

if ( !ec ) {
clean_expired_pbft_messages();
} else {
wlog ("pbft message cache ticker error: ${m}", ("m", ec.message()));
pbft_message_cache_ticker();
}
clean_expired_pbft_messages();

});
}

Expand Down

0 comments on commit ed3ef5b

Please sign in to comment.