Skip to content

Commit

Permalink
optimise cal in should_recv_pbft_msg and should_send_pbft_msg; do…
Browse files Browse the repository at this point in the history
… not send stable checkpoints higher than my lscb
  • Loading branch information
oldcold authored and VincentOCL committed May 21, 2019
1 parent 902177a commit cf75956
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
2 changes: 2 additions & 0 deletions libraries/chain/include/eosio/chain/pbft_database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,8 @@ namespace eosio {

void prune(const pbft_state_ptr &h);

void prune_checkpoints(const pbft_checkpoint_state_ptr &h);

};

}
Expand Down
31 changes: 26 additions & 5 deletions libraries/chain/pbft_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,14 @@ namespace eosio {
prune(*pitr);
}
}

// auto &bni = checkpoint_index.get<by_num>();
// auto oldest = bni.begin();
// if (oldest != bni.end() && lscb_num - (*oldest)->block_num > 10000) {
// auto it = bni.lower_bound(lscb_num - 10000);
// if (it != bni.end() && (*it)->is_stable) {
// prune_checkpoints(*it);
// }
// }
}

void pbft_database::send_pbft_checkpoint() {
Expand Down Expand Up @@ -1404,12 +1411,11 @@ namespace eosio {
bool pbft_database::should_send_pbft_msg() {

//use last_stable_checkpoint producer schedule
auto lscb_num = ctrl.last_stable_checkpoint_block_num();

auto as = lscb_active_producers();
auto my_sp = ctrl.my_signature_providers();

for (auto i = lscb_num; i <= ctrl.head_block_num(); ++i) {
for (auto i: prepare_watermarks) {
for (auto const &bp: as.producers) {
for (auto const &my: my_sp) {
if (bp.block_signing_key == my.first) return true;
Expand All @@ -1422,11 +1428,10 @@ namespace eosio {
}

bool pbft_database::should_recv_pbft_msg(const public_key_type &pub_key) {
auto lscb_num = ctrl.last_stable_checkpoint_block_num();

auto as = lscb_active_producers();

for (auto i = lscb_num; i <= ctrl.head_block_num(); ++i) {
for (auto i: prepare_watermarks) {
for (auto const &bp: as.producers) {
if (bp.block_signing_key == pub_key) return true;
}
Expand Down Expand Up @@ -1542,6 +1547,22 @@ namespace eosio {
}
}

void pbft_database::prune_checkpoints(const pbft_checkpoint_state_ptr &h) {
auto num = h->block_num;

auto &by_bn = checkpoint_index.get<by_num>();
auto bni = by_bn.begin();
while (bni != by_bn.end() && (*bni)->block_num < num) {
prune_checkpoints(*bni);
bni = by_bn.begin();
}

auto itr = checkpoint_index.find(h->block_id);
if (itr != checkpoint_index.end()) {
checkpoint_index.erase(itr);
}
}

template<typename Signal, typename Arg>
void pbft_database::emit(const Signal &s, Arg &&a) {
try {
Expand Down
7 changes: 4 additions & 3 deletions plugins/net_plugin/net_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,6 @@ namespace eosio {

void connection::blk_send_branch() {
controller& cc = my_impl->chain_plug->chain();
pbft_controller &pcc = my_impl->chain_plug->pbft_ctrl();
uint32_t head_num = cc.fork_db_head_block_num();
notice_message note;
note.known_blocks.mode = normal;
Expand Down Expand Up @@ -2798,7 +2797,9 @@ namespace eosio {
controller &cc = my_impl->chain_plug->chain();
pbft_controller &pcc = my_impl->chain_plug->pbft_ctrl();

for (auto i = msg.end_block; i >= msg.start_block && i>0; --i) {
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 != pbft_stable_checkpoint{}) {
Expand Down Expand Up @@ -3104,7 +3105,7 @@ namespace eosio {
}

void net_plugin_impl::handle_message( connection_ptr c, const pbft_checkpoint &msg) {

fc_ilog( logger, "received checkpoint at ${n}, from ${v}", ("n", msg.block_num)("v", msg.public_key));
if (!is_pbft_msg_valid(msg)) return;

auto added = maybe_add_pbft_cache(msg.uuid);
Expand Down

0 comments on commit cf75956

Please sign in to comment.