From 51503c404c275f94e762891fc2914ae794235c11 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Thu, 18 Apr 2024 14:56:43 -0500 Subject: [PATCH] GH-3 Use unordered_map --- .../chain/include/eosio/chain/vote_processor.hpp | 13 +++++++------ plugins/net_plugin/net_plugin.cpp | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/libraries/chain/include/eosio/chain/vote_processor.hpp b/libraries/chain/include/eosio/chain/vote_processor.hpp index 655e65bccf..32141a2a2a 100644 --- a/libraries/chain/include/eosio/chain/vote_processor.hpp +++ b/libraries/chain/include/eosio/chain/vote_processor.hpp @@ -10,6 +10,8 @@ #include #include +#include + namespace eosio::chain { /** @@ -17,7 +19,7 @@ namespace eosio::chain { */ class vote_processor_t { // Even 3000 vote structs are less than 1MB per connection. - // 2500 is should never be reached unless a specific connection is sending garbage. + // 2500 should never be reached unless a specific connection is sending garbage. static constexpr size_t max_votes_per_connection = 2500; // If we have not processed a vote in this amount of time, give up on it. static constexpr fc::microseconds too_old = fc::seconds(5); @@ -51,8 +53,8 @@ class vote_processor_t { std::mutex mtx; vote_index_type index; block_state_ptr last_bsp; - // connection, count of messages - std::map num_messages; + // connection, count of messages + std::unordered_map num_messages; std::atomic lib{0}; std::atomic largest_known_block_num{0}; @@ -99,7 +101,7 @@ class vote_processor_t { index.insert(vote{.connection_id = connection_id, .received = now, .msg = msg}); } - // called with locked mtx + // called with locked mtx, returns with a locked mutex void process_any_queued_for_later(std::unique_lock& g) { if (index.empty()) return; @@ -107,11 +109,10 @@ class vote_processor_t { remove_before_lib(); auto& idx = index.get(); std::vector unprocessed; - unprocessed.reserve(std::min(21u, idx.size())); // maybe increase if we increase # of finalizers from 21 for (auto i = idx.begin(); i != idx.end();) { if (stopped) return; - vote v = *i; + vote v = std::move(*i); idx.erase(i); auto bsp = get_block(v.msg->block_id, g); // g is unlocked diff --git a/plugins/net_plugin/net_plugin.cpp b/plugins/net_plugin/net_plugin.cpp index cb67c5c56a..815b2815e9 100644 --- a/plugins/net_plugin/net_plugin.cpp +++ b/plugins/net_plugin/net_plugin.cpp @@ -535,7 +535,7 @@ namespace eosio { void on_accepted_block_header( const signed_block_ptr& block, const block_id_type& id ); void on_accepted_block(); - void on_voted_block ( uint32_t connection_id, vote_status stauts, const vote_message_ptr& vote ); + void on_voted_block( uint32_t connection_id, vote_status stauts, const vote_message_ptr& vote ); void transaction_ack(const std::pair&); void on_irreversible_block( const block_id_type& id, uint32_t block_num );