diff --git a/libraries/core_libs/network/include/network/tarcap/taraxa_capability.hpp b/libraries/core_libs/network/include/network/tarcap/taraxa_capability.hpp index 33222e7384..1039e5ad9f 100644 --- a/libraries/core_libs/network/include/network/tarcap/taraxa_capability.hpp +++ b/libraries/core_libs/network/include/network/tarcap/taraxa_capability.hpp @@ -94,6 +94,8 @@ class TaraxaCapability final : public dev::p2p::CapabilityFace { template std::shared_ptr getSpecificHandler() const; + bool isQueueOverTheLimit() const; + private: bool filterSyncIrrelevantPackets(SubprotocolPacketType packet_type) const; void handlePacketQueueOverLimit(std::shared_ptr host, dev::p2p::NodeID node_id, size_t tp_queue_size); @@ -124,6 +126,7 @@ class TaraxaCapability final : public dev::p2p::CapabilityFace { std::chrono::system_clock::time_point last_ddos_disconnect_time_ = {}; std::chrono::system_clock::time_point queue_over_limit_start_time_ = {}; bool queue_over_limit_ = false; + std::atomic_bool queue_over_limit_extended_ = false; uint32_t last_disconnect_number_of_peers_ = 0; LOG_OBJECTS_DEFINE diff --git a/libraries/core_libs/network/src/network.cpp b/libraries/core_libs/network/src/network.cpp index 1e8ad6f63d..f9338a3f63 100644 --- a/libraries/core_libs/network/src/network.cpp +++ b/libraries/core_libs/network/src/network.cpp @@ -182,8 +182,10 @@ void Network::registerPeriodicEvents(const std::shared_ptr &pbft_mg // Send new transactions auto sendTxs = [this, trx_mgr = trx_mgr]() { for (auto &tarcap : tarcaps_) { - auto tx_packet_handler = tarcap.second->getSpecificHandler(); - tx_packet_handler->periodicSendTransactions(trx_mgr->getAllPoolTrxs()); + if (!tarcap.second->isQueueOverTheLimit()) { + auto tx_packet_handler = tarcap.second->getSpecificHandler(); + tx_packet_handler->periodicSendTransactions(trx_mgr->getAllPoolTrxs()); + } } }; periodic_events_tp_.post_loop({kConf.network.transaction_interval_ms}, sendTxs); @@ -291,8 +293,10 @@ void Network::addBootNodes(bool initial) { void Network::gossipDagBlock(const std::shared_ptr &block, bool proposed, const SharedTransactions &trxs) { for (const auto &tarcap : tarcaps_) { - tarcap.second->getSpecificHandler()->onNewBlockVerified(block, proposed, - trxs); + if (!tarcap.second->isQueueOverTheLimit()) { + tarcap.second->getSpecificHandler()->onNewBlockVerified(block, proposed, + trxs); + } } } diff --git a/libraries/core_libs/network/src/tarcap/taraxa_capability.cpp b/libraries/core_libs/network/src/tarcap/taraxa_capability.cpp index bee9e177f9..2406517290 100644 --- a/libraries/core_libs/network/src/tarcap/taraxa_capability.cpp +++ b/libraries/core_libs/network/src/tarcap/taraxa_capability.cpp @@ -124,6 +124,8 @@ std::string TaraxaCapability::packetTypeToString(unsigned _packetType) const { return convertPacketTypeToString(static_cast(_packetType)); } +bool TaraxaCapability::isQueueOverTheLimit() const { return queue_over_limit_extended_.load(); } + void TaraxaCapability::interpretCapabilityPacket(std::weak_ptr session, unsigned _id, dev::RLP const &_r) { const auto session_p = session.lock(); @@ -190,6 +192,7 @@ void TaraxaCapability::interpretCapabilityPacket(std::weak_ptr kConf.network.ddos_protection.queue_limit_time) { + queue_over_limit_extended_ = true; // Only disconnect if there is more than peer_disconnect_interval since last disconnect if ((std::chrono::system_clock::now() - last_ddos_disconnect_time_) > kConf.network.ddos_protection.peer_disconnect_interval) {