-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7367bf3
commit a005a9b
Showing
14 changed files
with
260 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 24 additions & 17 deletions
41
libraries/core_libs/consensus/src/pillar_chain/bls_signature.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...network/include/network/tarcap/packets_handlers/latest/bls_sigs_bundle_packet_handler.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#pragma once | ||
|
||
#include "common/ext_bls_sig_packet_handler.hpp" | ||
|
||
namespace taraxa::network::tarcap { | ||
|
||
class BlsSigsBundlePacketHandler : public ExtBlsSigPacketHandler { | ||
public: | ||
BlsSigsBundlePacketHandler(const FullNodeConfig& conf, std::shared_ptr<PeersState> peers_state, | ||
std::shared_ptr<TimePeriodPacketsStats> packets_stats, | ||
std::shared_ptr<PillarChainManager> pillar_chain_manager, const addr_t& node_addr, | ||
const std::string& logs_prefix); | ||
|
||
// Packet type that is processed by this handler | ||
static constexpr SubprotocolPacketType kPacketType_ = SubprotocolPacketType::BlsSigsBundlePacket; | ||
|
||
private: | ||
virtual void validatePacketRlpFormat(const threadpool::PacketData& packet_data) const override; | ||
virtual void process(const threadpool::PacketData& packet_data, const std::shared_ptr<TaraxaPeer>& peer) override; | ||
|
||
protected: | ||
constexpr static size_t kMaxSignaturesInBundleRlp{250}; | ||
}; | ||
|
||
} // namespace taraxa::network::tarcap |
22 changes: 22 additions & 0 deletions
22
...work/include/network/tarcap/packets_handlers/latest/common/ext_bls_sig_packet_handler.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
|
||
#include "packet_handler.hpp" | ||
#include "pillar_chain/pillar_chain_manager.hpp" | ||
|
||
namespace taraxa::network::tarcap { | ||
|
||
class ExtBlsSigPacketHandler : public PacketHandler { | ||
public: | ||
ExtBlsSigPacketHandler(const FullNodeConfig& conf, std::shared_ptr<PeersState> peers_state, | ||
std::shared_ptr<TimePeriodPacketsStats> packets_stats, | ||
std::shared_ptr<PillarChainManager> pillar_chain_manager, const addr_t& node_addr, | ||
const std::string& logs_prefix); | ||
|
||
protected: | ||
void processBlsSignature(const std::shared_ptr<BlsSignature>& signature, const std::shared_ptr<TaraxaPeer>& peer); | ||
|
||
protected: | ||
std::shared_ptr<PillarChainManager> pillar_chain_manager_; | ||
}; | ||
|
||
} // namespace taraxa::network::tarcap |
31 changes: 31 additions & 0 deletions
31
...ork/include/network/tarcap/packets_handlers/latest/get_bls_sigs_bundle_packet_handler.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
#include "common/packet_handler.hpp" | ||
#include "pillar_chain/pillar_block.hpp" | ||
#include "pillar_chain/pillar_chain_manager.hpp" | ||
|
||
namespace taraxa::network::tarcap { | ||
|
||
class GetBlsSigsBundlePacketHandler : public PacketHandler { | ||
public: | ||
GetBlsSigsBundlePacketHandler(const FullNodeConfig& conf, std::shared_ptr<PeersState> peers_state, | ||
std::shared_ptr<TimePeriodPacketsStats> packets_stats, | ||
std::shared_ptr<PillarChainManager> pillar_chain_manager, const addr_t& node_addr, | ||
const std::string& logs_prefix); | ||
|
||
void requestBlsSigsBundle(PillarBlock::Hash pillar_block_hash, const std::shared_ptr<TaraxaPeer>& peer); | ||
|
||
// Packet type that is processed by this handler | ||
static constexpr SubprotocolPacketType kPacketType_ = SubprotocolPacketType::GetBlsSigsBundlePacket; | ||
|
||
private: | ||
virtual void validatePacketRlpFormat(const threadpool::PacketData& packet_data) const override; | ||
virtual void process(const threadpool::PacketData& packet_data, const std::shared_ptr<TaraxaPeer>& peer) override; | ||
|
||
protected: | ||
constexpr static size_t kGetBlsSigsPacketSize{1}; | ||
|
||
std::shared_ptr<PillarChainManager> pillar_chain_manager_; | ||
}; | ||
|
||
} // namespace taraxa::network::tarcap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...s/core_libs/network/src/tarcap/packets_handlers/latest/bls_sigs_bundle_packet_handler.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include "network/tarcap/packets_handlers/latest/bls_sigs_bundle_packet_handler.hpp" | ||
|
||
namespace taraxa::network::tarcap { | ||
|
||
BlsSigsBundlePacketHandler::BlsSigsBundlePacketHandler(const FullNodeConfig &conf, | ||
std::shared_ptr<PeersState> peers_state, | ||
std::shared_ptr<TimePeriodPacketsStats> packets_stats, | ||
std::shared_ptr<PillarChainManager> pillar_chain_manager, | ||
const addr_t &node_addr, const std::string &logs_prefix) | ||
: ExtBlsSigPacketHandler(conf, std::move(peers_state), std::move(packets_stats), std::move(pillar_chain_manager), | ||
node_addr, logs_prefix + "BLS_SIGS_BUNDLE_PH") {} | ||
|
||
void BlsSigsBundlePacketHandler::validatePacketRlpFormat( | ||
[[maybe_unused]] const threadpool::PacketData &packet_data) const { | ||
auto items = packet_data.rlp_.itemCount(); | ||
if (items == 0 || items > kMaxSignaturesInBundleRlp) { | ||
throw InvalidRlpItemsCountException(packet_data.type_str_, items, kMaxSignaturesInBundleRlp); | ||
} | ||
} | ||
|
||
void BlsSigsBundlePacketHandler::process(const threadpool::PacketData &packet_data, | ||
const std::shared_ptr<TaraxaPeer> &peer) { | ||
for (const auto signature_rlp : packet_data.rlp_) { | ||
const auto bls_signature = std::make_shared<BlsSignature>(signature_rlp); | ||
processBlsSignature(bls_signature, peer); | ||
} | ||
} | ||
|
||
} // namespace taraxa::network::tarcap |
32 changes: 32 additions & 0 deletions
32
...ore_libs/network/src/tarcap/packets_handlers/latest/common/ext_bls_sig_packet_handler.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include "network/tarcap/packets_handlers/latest/common/ext_bls_sig_packet_handler.hpp" | ||
|
||
#include "pillar_chain/pillar_chain_manager.hpp" | ||
|
||
namespace taraxa::network::tarcap { | ||
|
||
ExtBlsSigPacketHandler::ExtBlsSigPacketHandler(const FullNodeConfig &conf, std::shared_ptr<PeersState> peers_state, | ||
std::shared_ptr<TimePeriodPacketsStats> packets_stats, | ||
std::shared_ptr<PillarChainManager> pillar_chain_manager, | ||
const addr_t &node_addr, const std::string &logs_prefix) | ||
: PacketHandler(conf, std::move(peers_state), std::move(packets_stats), node_addr, logs_prefix + "BLS_SIG_PH"), | ||
pillar_chain_manager_{std::move(pillar_chain_manager)} {} | ||
|
||
void ExtBlsSigPacketHandler::processBlsSignature(const std::shared_ptr<BlsSignature> &signature, | ||
const std::shared_ptr<TaraxaPeer> &peer) { | ||
if (!pillar_chain_manager_->isRelevantBlsSig(signature)) { | ||
LOG(log_dg_) << "Drop irrelevant signature " << signature->getHash() << " from peer " << peer->getId(); | ||
} | ||
|
||
if (!signature->isValid()) { | ||
std::ostringstream err_msg; | ||
err_msg << "Invalid signature " << signature->getHash() << " from peer " << peer->getId(); | ||
throw MaliciousPeerException(err_msg.str()); | ||
} | ||
|
||
pillar_chain_manager_->addVerifiedBlsSig(signature); | ||
|
||
// Mark bls signature as known for peer | ||
peer->markBlsSigAsKnown(signature->getHash()); | ||
} | ||
|
||
} // namespace taraxa::network::tarcap |
Oops, something went wrong.