Skip to content

Commit

Permalink
GH-3 Track num_messages per connection
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Apr 11, 2024
1 parent 7fc69ac commit c3a9c95
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions libraries/chain/include/eosio/chain/vote_processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,12 @@ class vote_processor_t {
void remove_before_lib() {
auto& idx = index.get<by_block_num>();
idx.erase(idx.lower_bound(lib.load()), idx.end()); // descending
// don't decrement num_messages as too many before lib should be considered an error
}

bool remove_all_for_block(auto& idx, auto& it, const block_id_type& id) {
while (it != idx.end() && (*it)->id() == id) {
--num_messages[(*it)->connection_id];
it = idx.erase(it);
}
return it == idx.end();
Expand Down Expand Up @@ -139,8 +141,10 @@ class vote_processor_t {
if (stopped)
break;
remove_before_lib();
if (index.empty())
if (index.empty()) {
num_messages.clear();
continue;
}
auto& idx = index.get<by_block_num>();
if (auto i = idx.begin(); i != idx.end() && not_in_forkdb_id == (*i)->id()) { // same block as last while loop
g.unlock();
Expand Down Expand Up @@ -196,7 +200,8 @@ class vote_processor_t {
boost::asio::post(thread_pool.get_executor(), [this, connection_id, msg] {
std::unique_lock g(mtx);
if (++num_messages[connection_id] > max_votes_per_connection) {
// consider the connection invalid, remove all votes
// consider the connection invalid, remove all votes of connection
// don't clear num_messages[connection_id] so we keep reporting max_exceeded until index is drained
remove_connection(connection_id);
g.unlock();

Expand Down

0 comments on commit c3a9c95

Please sign in to comment.