Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: no gossip if queue over limit #2894

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ class TaraxaCapability final : public dev::p2p::CapabilityFace {
template <typename PacketHandlerType>
std::shared_ptr<PacketHandlerType> getSpecificHandler() const;

bool isQueueOverTheLimit() const;

private:
bool filterSyncIrrelevantPackets(SubprotocolPacketType packet_type) const;
void handlePacketQueueOverLimit(std::shared_ptr<dev::p2p::Host> host, dev::p2p::NodeID node_id, size_t tp_queue_size);
Expand Down Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions libraries/core_libs/network/src/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,10 @@ void Network::registerPeriodicEvents(const std::shared_ptr<PbftManager> &pbft_mg
// Send new transactions
auto sendTxs = [this, trx_mgr = trx_mgr]() {
for (auto &tarcap : tarcaps_) {
auto tx_packet_handler = tarcap.second->getSpecificHandler<network::tarcap::TransactionPacketHandler>();
tx_packet_handler->periodicSendTransactions(trx_mgr->getAllPoolTrxs());
if (!tarcap.second->isQueueOverTheLimit()) {
auto tx_packet_handler = tarcap.second->getSpecificHandler<network::tarcap::TransactionPacketHandler>();
tx_packet_handler->periodicSendTransactions(trx_mgr->getAllPoolTrxs());
}
}
};
periodic_events_tp_.post_loop({kConf.network.transaction_interval_ms}, sendTxs);
Expand Down Expand Up @@ -291,8 +293,10 @@ void Network::addBootNodes(bool initial) {

void Network::gossipDagBlock(const std::shared_ptr<DagBlock> &block, bool proposed, const SharedTransactions &trxs) {
for (const auto &tarcap : tarcaps_) {
tarcap.second->getSpecificHandler<network::tarcap::DagBlockPacketHandler>()->onNewBlockVerified(block, proposed,
trxs);
if (!tarcap.second->isQueueOverTheLimit()) {
tarcap.second->getSpecificHandler<network::tarcap::DagBlockPacketHandler>()->onNewBlockVerified(block, proposed,
trxs);
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions libraries/core_libs/network/src/tarcap/taraxa_capability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ std::string TaraxaCapability::packetTypeToString(unsigned _packetType) const {
return convertPacketTypeToString(static_cast<SubprotocolPacketType>(_packetType));
}

bool TaraxaCapability::isQueueOverTheLimit() const { return queue_over_limit_extended_.load(); }

void TaraxaCapability::interpretCapabilityPacket(std::weak_ptr<dev::p2p::Session> session, unsigned _id,
dev::RLP const &_r) {
const auto session_p = session.lock();
Expand Down Expand Up @@ -190,6 +192,7 @@ void TaraxaCapability::interpretCapabilityPacket(std::weak_ptr<dev::p2p::Session
handlePacketQueueOverLimit(host, node_id, tp_queue_size);
} else {
queue_over_limit_ = false;
queue_over_limit_extended_ = false;
last_disconnect_number_of_peers_ = 0;
}

Expand All @@ -208,6 +211,7 @@ void TaraxaCapability::handlePacketQueueOverLimit(std::shared_ptr<dev::p2p::Host
// Check if Queue is over the limit for queue_limit_time
if ((std::chrono::system_clock::now() - queue_over_limit_start_time_) >
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) {
Expand Down
Loading