diff --git a/libraries/core_libs/network/include/network/tarcap/packets_handlers/latest/common/ext_syncing_packet_handler.hpp b/libraries/core_libs/network/include/network/tarcap/packets_handlers/latest/common/ext_syncing_packet_handler.hpp index d230ecc6be..16b9058076 100644 --- a/libraries/core_libs/network/include/network/tarcap/packets_handlers/latest/common/ext_syncing_packet_handler.hpp +++ b/libraries/core_libs/network/include/network/tarcap/packets_handlers/latest/common/ext_syncing_packet_handler.hpp @@ -50,7 +50,8 @@ class ExtSyncingPacketHandler : public PacketHandler { PbftPeriod period); void requestPendingDagBlocks(std::shared_ptr peer = nullptr); - std::shared_ptr getMaxChainPeer(); + std::shared_ptr getMaxChainPeer(std::function &)> filter_func = + [](const std::shared_ptr &) { return true; }); protected: std::shared_ptr pbft_syncing_state_{nullptr}; diff --git a/libraries/core_libs/network/src/tarcap/packets_handlers/latest/common/ext_syncing_packet_handler.cpp b/libraries/core_libs/network/src/tarcap/packets_handlers/latest/common/ext_syncing_packet_handler.cpp index 3554417c6d..4dbe10aa1c 100644 --- a/libraries/core_libs/network/src/tarcap/packets_handlers/latest/common/ext_syncing_packet_handler.cpp +++ b/libraries/core_libs/network/src/tarcap/packets_handlers/latest/common/ext_syncing_packet_handler.cpp @@ -76,13 +76,19 @@ bool ExtSyncingPacketHandler::syncPeerPbft(PbftPeriod request_period) { std::move(dev::RLPStream(1) << request_period)); } -std::shared_ptr ExtSyncingPacketHandler::getMaxChainPeer() { +std::shared_ptr ExtSyncingPacketHandler::getMaxChainPeer( + std::function &)> filter_func) { std::shared_ptr max_pbft_chain_peer; PbftPeriod max_pbft_chain_size = 0; uint64_t max_node_dag_level = 0; // Find peer with max pbft chain and dag level for (auto const &peer : peers_state_->getAllPeers()) { + // Apply the filter function + if (!filter_func(peer.second)) { + continue; + } + if (peer.second->pbft_chain_size_ > max_pbft_chain_size) { if (peer.second->peer_light_node && pbft_mgr_->pbftSyncingPeriod() + peer.second->peer_light_node_history < peer.second->pbft_chain_size_) { @@ -105,7 +111,16 @@ std::shared_ptr ExtSyncingPacketHandler::getMaxChainPeer() { void ExtSyncingPacketHandler::requestPendingDagBlocks(std::shared_ptr peer) { if (!peer) { - peer = getMaxChainPeer(); + peer = getMaxChainPeer([](const std::shared_ptr &peer) { + if (peer->peer_dag_synced_ || !peer->dagSyncingAllowed()) { + return false; + } + return true; + }); + if (!peer) { + LOG(log_nf_) << "requestPendingDagBlocks not possible since no peers are matching conditions"; + return; + } } if (!peer) {