From 385b71a318100198af249de2fda9a5ff0c20f966 Mon Sep 17 00:00:00 2001 From: Jakub Fornadel Date: Mon, 3 Jun 2024 12:58:25 -0700 Subject: [PATCH] fix pillar votes syncing --- .../src/pillar_chain/pillar_chain_manager.cpp | 10 +++++++++- .../get_pillar_votes_bundle_packet_handler.cpp | 13 +++++++++---- .../network/src/threadpool/priority_queue.cpp | 2 ++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/libraries/core_libs/consensus/src/pillar_chain/pillar_chain_manager.cpp b/libraries/core_libs/consensus/src/pillar_chain/pillar_chain_manager.cpp index 77fa53296e..7166241589 100644 --- a/libraries/core_libs/consensus/src/pillar_chain/pillar_chain_manager.cpp +++ b/libraries/core_libs/consensus/src/pillar_chain/pillar_chain_manager.cpp @@ -38,6 +38,9 @@ PillarChainManager::PillarChainManager(const FicusHardforkConfig& ficus_hf_confi if (auto&& latest_pillar_block_data = db_->getLatestPillarBlockData(); latest_pillar_block_data.has_value()) { last_finalized_pillar_block_ = std::move(latest_pillar_block_data->block_); + for (const auto& vote : latest_pillar_block_data->pillar_votes_) { + addVerifiedPillarVote(vote); + } } LOG_OBJECTS_CREATE("PILLAR_CHAIN"); @@ -294,7 +297,12 @@ bool PillarChainManager::isRelevantPillarVote(const std::shared_ptr return false; } - return !pillar_votes_.voteExists(vote); + if (pillar_votes_.voteExists(vote)) { + LOG(log_dg_) << "Received vote " << vote->getHash() << " already saved"; + return false; + } + + return true; } bool PillarChainManager::validatePillarVote(const std::shared_ptr vote) const { diff --git a/libraries/core_libs/network/src/tarcap/packets_handlers/latest/get_pillar_votes_bundle_packet_handler.cpp b/libraries/core_libs/network/src/tarcap/packets_handlers/latest/get_pillar_votes_bundle_packet_handler.cpp index d9b32c5310..14a359a413 100644 --- a/libraries/core_libs/network/src/tarcap/packets_handlers/latest/get_pillar_votes_bundle_packet_handler.cpp +++ b/libraries/core_libs/network/src/tarcap/packets_handlers/latest/get_pillar_votes_bundle_packet_handler.cpp @@ -20,6 +20,7 @@ void GetPillarVotesBundlePacketHandler::validatePacketRlpFormat(const threadpool void GetPillarVotesBundlePacketHandler::process(const threadpool::PacketData &packet_data, const std::shared_ptr &peer) { + LOG(log_dg_) << "GetPillarVotesBundlePacketHandler received from peer " << peer->getId(); const PbftPeriod period = packet_data.rlp_[0].toInt(); const blk_hash_t pillar_block_hash = packet_data.rlp_[1].toHash(); @@ -58,13 +59,17 @@ void GetPillarVotesBundlePacketHandler::process(const threadpool::PacketData &pa void GetPillarVotesBundlePacketHandler::requestPillarVotesBundle(PbftPeriod period, const blk_hash_t &pillar_block_hash, const std::shared_ptr &peer) { - dev::RLPStream s(2); + dev::RLPStream s(kGetPillarVotesBundlePacketSize); s << period; s << pillar_block_hash; - sealAndSend(peer->getId(), SubprotocolPacketType::GetPillarVotesBundlePacket, std::move(s)); - LOG(log_nf_) << "Requested pillar votes bundle for period " << period << " and pillar block " << pillar_block_hash - << " from peer " << peer->getId(); + if (sealAndSend(peer->getId(), SubprotocolPacketType::GetPillarVotesBundlePacket, std::move(s))) { + LOG(log_nf_) << "Requested pillar votes bundle for period " << period << " and pillar block " << pillar_block_hash + << " from peer " << peer->getId(); + } else { + LOG(log_er_) << "Unable to send pillar votes bundle request for period " << period << " and pillar block " + << pillar_block_hash << " to peer " << peer->getId(); + } } } // namespace taraxa::network::tarcap diff --git a/libraries/core_libs/network/src/threadpool/priority_queue.cpp b/libraries/core_libs/network/src/threadpool/priority_queue.cpp index 1021b19b74..8311626ddb 100644 --- a/libraries/core_libs/network/src/threadpool/priority_queue.cpp +++ b/libraries/core_libs/network/src/threadpool/priority_queue.cpp @@ -180,6 +180,8 @@ void PriorityQueue::updateDependenciesFinish(const PacketData& packet, std::mute switch (packet.type_) { case SubprotocolPacketType::GetDagSyncPacket: case SubprotocolPacketType::GetPbftSyncPacket: + case SubprotocolPacketType::GetPillarVotesBundlePacket: + case SubprotocolPacketType::PillarVotesBundlePacket: // TODO[2744]: remove case SubprotocolPacketType::PbftSyncPacket: { std::unique_lock lock(queue_mutex); blocked_packets_mask_.markPacketAsHardUnblocked(packet, packet.type_);