Skip to content

Commit

Permalink
view update version
Browse files Browse the repository at this point in the history
Signed-off-by: iceseer <[email protected]>
  • Loading branch information
iceseer committed Mar 14, 2024
1 parent 78531e3 commit fd3e6c6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
30 changes: 15 additions & 15 deletions core/network/impl/peer_manager_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,15 @@ namespace kagome::network {
return it->second;
}

std::optional<std::reference_wrapper<const PeerState>>
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)) {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions core/network/impl/peer_manager_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ namespace kagome::network {
/** @see PeerManager::getPeerState */
std::optional<std::reference_wrapper<PeerState>> getPeerState(
const PeerId &peer_id) override;
std::optional<std::reference_wrapper<const PeerState>> getPeerState(
const PeerId &peer_id) const override;

private:
/// Right way to check self peer as it takes into account dev mode
Expand Down
2 changes: 2 additions & 0 deletions core/network/peer_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ namespace kagome::network {
*/
virtual std::optional<std::reference_wrapper<PeerState>> getPeerState(
const PeerId &peer_id) = 0;
virtual std::optional<std::reference_wrapper<const PeerState>> getPeerState(
const PeerId &peer_id) const = 0;

/**
* @returns number of active peers
Expand Down
8 changes: 4 additions & 4 deletions core/parachain/validator/impl/parachain_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::ValidatorProtocolMessage>>(
network::WireMessage<network::vstaging::ValidatorProtocolMessage>>(
network::ViewUpdate{.view = view});
pm_->getStreamEngine()->broadcast(
router_->getValidationProtocolVStaging(),
Expand Down Expand Up @@ -568,7 +568,7 @@ namespace kagome::parachain {
BOOST_ASSERT(se);

auto message = std::make_shared<
network::WireMessage<network::ValidatorProtocolMessage>>(msg);
network::WireMessage<network::vstaging::ValidatorProtocolMessage>>(msg);
SL_TRACE(
logger_,
"Broadcasting view update to group.(relay_parent={}, group_size={})",
Expand All @@ -587,7 +587,7 @@ namespace kagome::parachain {

void ParachainProcessorImpl::broadcastView(const network::View &view) const {
auto msg = std::make_shared<
network::WireMessage<network::ValidatorProtocolMessage>>(
network::WireMessage<network::vstaging::ValidatorProtocolMessage>>(
network::ViewUpdate{.view = view});
pm_->getStreamEngine()->broadcast(router_->getCollationProtocolVStaging(),
msg);
Expand Down Expand Up @@ -2822,7 +2822,7 @@ namespace kagome::parachain {
peer_id,
protocol,
std::make_shared<
network::WireMessage<network::ValidatorProtocolMessage>>(
network::WireMessage<network::vstaging::ValidatorProtocolMessage>>(
network::ViewUpdate{.view = my_view->get().view}));
}

Expand Down

0 comments on commit fd3e6c6

Please sign in to comment.