From fd3e6c6633e61765f80bd68d76f2a54ff7f5959f Mon Sep 17 00:00:00 2001 From: iceseer Date: Thu, 14 Mar 2024 11:06:15 +0300 Subject: [PATCH] view update version Signed-off-by: iceseer --- core/network/impl/peer_manager_impl.cpp | 30 +++++++++---------- core/network/impl/peer_manager_impl.hpp | 2 ++ core/network/peer_manager.hpp | 2 ++ .../validator/impl/parachain_processor.cpp | 8 ++--- 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/core/network/impl/peer_manager_impl.cpp b/core/network/impl/peer_manager_impl.cpp index 60d8f0c66c..ed6a7f2c50 100644 --- a/core/network/impl/peer_manager_impl.cpp +++ b/core/network/impl/peer_manager_impl.cpp @@ -581,6 +581,15 @@ namespace kagome::network { return it->second; } + std::optional> + PeerManagerImpl::getPeerState(const PeerId &peer_id) const { + auto it = peer_states_.find(peer_id); + if (it == peer_states_.end()) { + return std::nullopt; + } + return it->second; + } + void PeerManagerImpl::processDiscoveredPeer(const PeerId &peer_id) { // Ignore himself if (isSelfPeer(peer_id)) { @@ -744,17 +753,6 @@ namespace kagome::network { validation_protocol->protocolName(), peer_id, stream_result.error().message()); - auto ps = self->getPeerState(peer_info.id); - if (ps) { - self->tryOpenValidationProtocol( - peer_info, ps->get(), network::CollationVersion::V1); - } else { - SL_TRACE( - self->log_, - "No peer state to open V1 validation protocol {} with {}", - validation_protocol->protocolName(), - peer_id); - } return; } @@ -839,11 +837,13 @@ namespace kagome::network { } void PeerManagerImpl::reserveStatusStreams(const PeerId &peer_id) const { - auto proto_val_vstaging = router_->getValidationProtocolVStaging(); - BOOST_ASSERT_MSG(proto_val_vstaging, - "Router did not provide validation protocol vstaging"); + if (auto ps = getPeerState(peer_id); ps && ps->get().roles.flags.authority) { + auto proto_val_vstaging = router_->getValidationProtocolVStaging(); + BOOST_ASSERT_MSG(proto_val_vstaging, + "Router did not provide validation protocol vstaging"); - stream_engine_->reserveStreams(peer_id, proto_val_vstaging); + stream_engine_->reserveStreams(peer_id, proto_val_vstaging); + } } void PeerManagerImpl::reserveStreams(const PeerId &peer_id) const { diff --git a/core/network/impl/peer_manager_impl.hpp b/core/network/impl/peer_manager_impl.hpp index ef7b0bdb6d..47e5bd2887 100644 --- a/core/network/impl/peer_manager_impl.hpp +++ b/core/network/impl/peer_manager_impl.hpp @@ -139,6 +139,8 @@ namespace kagome::network { /** @see PeerManager::getPeerState */ std::optional> getPeerState( const PeerId &peer_id) override; + std::optional> getPeerState( + const PeerId &peer_id) const override; private: /// Right way to check self peer as it takes into account dev mode diff --git a/core/network/peer_manager.hpp b/core/network/peer_manager.hpp index eb4559ef5c..89a5db0b87 100644 --- a/core/network/peer_manager.hpp +++ b/core/network/peer_manager.hpp @@ -193,6 +193,8 @@ namespace kagome::network { */ virtual std::optional> getPeerState( const PeerId &peer_id) = 0; + virtual std::optional> getPeerState( + const PeerId &peer_id) const = 0; /** * @returns number of active peers diff --git a/core/parachain/validator/impl/parachain_processor.cpp b/core/parachain/validator/impl/parachain_processor.cpp index 500c4981c2..6c19c98c9c 100644 --- a/core/parachain/validator/impl/parachain_processor.cpp +++ b/core/parachain/validator/impl/parachain_processor.cpp @@ -527,7 +527,7 @@ namespace kagome::parachain { void ParachainProcessorImpl::broadcastViewExcept( const libp2p::peer::PeerId &peer_id, const network::View &view) const { auto msg = std::make_shared< - network::WireMessage>( + network::WireMessage>( network::ViewUpdate{.view = view}); pm_->getStreamEngine()->broadcast( router_->getValidationProtocolVStaging(), @@ -568,7 +568,7 @@ namespace kagome::parachain { BOOST_ASSERT(se); auto message = std::make_shared< - network::WireMessage>(msg); + network::WireMessage>(msg); SL_TRACE( logger_, "Broadcasting view update to group.(relay_parent={}, group_size={})", @@ -587,7 +587,7 @@ namespace kagome::parachain { void ParachainProcessorImpl::broadcastView(const network::View &view) const { auto msg = std::make_shared< - network::WireMessage>( + network::WireMessage>( network::ViewUpdate{.view = view}); pm_->getStreamEngine()->broadcast(router_->getCollationProtocolVStaging(), msg); @@ -2822,7 +2822,7 @@ namespace kagome::parachain { peer_id, protocol, std::make_shared< - network::WireMessage>( + network::WireMessage>( network::ViewUpdate{.view = my_view->get().view})); }