Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/app/application_metrics.def
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@ METRIC_GAUGE_LABELS(
METRIC_GAUGE(app_process_start_time,
"lean_process_start_time_seconds",
"UNIX timestamp of the moment the process started")

METRIC_GAUGE(connected_peer_count, "TODO_NAME_connected_peer_count", "TODO_HELP")
Copy link
Collaborator

@KatyaRyazantseva KatyaRyazantseva Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestion is to move these metrics to a separate network_metrics.def in the networking module. The number of the network metrics will grow further.

5 changes: 5 additions & 0 deletions src/loaders/impl/networking_loader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace lean::loaders {
public Loader,
public modules::NetworkingLoader {
log::Logger logger_;
qtils::SharedRef<metrics::Metrics> metrics_;
qtils::SharedRef<blockchain::BlockTree> block_tree_;
qtils::SharedRef<ForkChoiceStore> fork_choice_store_;
qtils::SharedRef<app::ChainSpec> chain_spec_;
Expand All @@ -58,12 +59,14 @@ namespace lean::loaders {
public:
NetworkingLoader(std::shared_ptr<log::LoggingSystem> logsys,
std::shared_ptr<Subscription> se_manager,
qtils::SharedRef<metrics::Metrics> metrics,
qtils::SharedRef<blockchain::BlockTree> block_tree,
qtils::SharedRef<ForkChoiceStore> fork_choice_store,
qtils::SharedRef<app::ChainSpec> chain_spec,
qtils::SharedRef<app::Configuration> app_config)
: Loader(std::move(logsys), std::move(se_manager)),
logger_(logsys_->getLogger("Networking", "networking_module")),
metrics_{std::move(metrics)},
block_tree_{std::move(block_tree)},
fork_choice_store_{std::move(fork_choice_store)},
chain_spec_{std::move(chain_spec)},
Expand All @@ -81,6 +84,7 @@ namespace lean::loaders {
->getFunctionFromLibrary<std::weak_ptr<lean::modules::Networking>,
modules::NetworkingLoader &,
std::shared_ptr<log::LoggingSystem>,
qtils::SharedRef<metrics::Metrics>,
qtils::SharedRef<blockchain::BlockTree>,
qtils::SharedRef<ForkChoiceStore>,
qtils::SharedRef<app::ChainSpec>,
Expand All @@ -93,6 +97,7 @@ namespace lean::loaders {

auto module_internal = (*module_accessor)(*this,
logsys_,
metrics_,
block_tree_,
fork_choice_store_,
chain_spec_,
Expand Down
14 changes: 10 additions & 4 deletions src/modules/networking/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@
#define MODULE_C_API extern "C" __attribute__((visibility("default")))
#define MODULE_API __attribute__((visibility("default")))

namespace lean::blockchain {
class BlockTree;
} // namespace lean::blockchain

namespace lean::app {
class ChainSpec;
class Configuration;
} // namespace lean::app

namespace lean::blockchain {
class BlockTree;
} // namespace lean::blockchain

namespace lean::metrics {
class Metrics;
} // namespace lean::metrics

MODULE_C_API const char *loader_id() {
return "NetworkingLoader";
}
Expand All @@ -34,6 +38,7 @@ static std::shared_ptr<lean::modules::Networking> module_instance;
MODULE_C_API std::weak_ptr<lean::modules::Networking> query_module_instance(
lean::modules::NetworkingLoader &loader,
std::shared_ptr<lean::log::LoggingSystem> logsys,
qtils::SharedRef<lean::metrics::Metrics> metrics,
qtils::SharedRef<lean::blockchain::BlockTree> block_tree,
qtils::SharedRef<lean::ForkChoiceStore> fork_choice_store,
qtils::SharedRef<lean::app::ChainSpec> chain_spec,
Expand All @@ -47,6 +52,7 @@ MODULE_C_API std::weak_ptr<lean::modules::Networking> query_module_instance(
module_instance =
lean::modules::NetworkingImpl::create_shared(loader,
std::move(logsys),
std::move(metrics),
block_tree,
fork_choice_store,
chain_spec,
Expand Down
13 changes: 12 additions & 1 deletion src/modules/networking/networking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#include "blockchain/block_tree.hpp"
#include "blockchain/impl/fc_block_tree.hpp"
#include "metrics/metrics.hpp"
#include "modules/networking/block_request_protocol.hpp"
#include "modules/networking/ssz_snappy.hpp"
#include "modules/networking/status_protocol.hpp"
Expand Down Expand Up @@ -72,12 +73,14 @@ namespace lean::modules {
NetworkingImpl::NetworkingImpl(
NetworkingLoader &loader,
qtils::SharedRef<log::LoggingSystem> logging_system,
qtils::SharedRef<metrics::Metrics> metrics,
qtils::SharedRef<blockchain::BlockTree> block_tree,
qtils::SharedRef<lean::ForkChoiceStore> fork_choice_store,
qtils::SharedRef<app::ChainSpec> chain_spec,
qtils::SharedRef<app::Configuration> config)
: loader_(loader),
logger_(logging_system->getLogger("Networking", "networking_module")),
metrics_{std::move(metrics)},
block_tree_{std::move(block_tree)},
fork_choice_store_{std::move(fork_choice_store)},
chain_spec_{std::move(chain_spec)},
Expand Down Expand Up @@ -124,6 +127,7 @@ namespace lean::modules {
io_context_ = injector->create<std::shared_ptr<boost::asio::io_context>>();

auto host = injector->create<std::shared_ptr<libp2p::host::BasicHost>>();
host_ = host;

bool has_enr_listen_address = false;
const auto &bootnodes = chain_spec_->getBootnodes();
Expand Down Expand Up @@ -253,6 +257,7 @@ namespace lean::modules {
if (not self) {
return;
}
self->updateMetricConnectedPeerCount();
auto peer_id = connection->remotePeer();
self->loader_.dispatch_peer_connected(
qtils::toSharedPtr(messages::PeerConnectedMessage{peer_id}));
Expand Down Expand Up @@ -295,6 +300,7 @@ namespace lean::modules {
if (not self) {
return;
}
self->updateMetricConnectedPeerCount();
self->loader_.dispatch_peer_disconnected(
qtils::toSharedPtr(messages::PeerDisconnectedMessage{peer_id}));
};
Expand Down Expand Up @@ -344,7 +350,8 @@ namespace lean::modules {
gossip_blocks_topic_ = gossipSubscribe<SignedBlockWithAttestation>(
"block",
[weak_self{weak_from_this()}](
SignedBlockWithAttestation &&signed_block_with_attestation, std::optional<libp2p::PeerId> received_from) {
SignedBlockWithAttestation &&signed_block_with_attestation,
std::optional<libp2p::PeerId> received_from) {
auto self = weak_self.lock();
if (not self) {
return;
Expand Down Expand Up @@ -547,4 +554,8 @@ namespace lean::modules {
}
return slot_hash.slot > block_tree_->lastFinalized().slot;
}

void NetworkingImpl::updateMetricConnectedPeerCount() {
metrics_->connected_peer_count()->set(host_->getConnectedPeerCount());
}
} // namespace lean::modules
21 changes: 17 additions & 4 deletions src/modules/networking/networking.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ namespace boost::asio {
class io_context;
} // namespace boost::asio

namespace libp2p::host {
class BasicHost;
} // namespace libp2p::host

namespace libp2p::protocol {
class Ping;
class Identify;
Expand All @@ -33,15 +37,19 @@ namespace lean {
class ForkChoiceStore;
} // namespace lean

namespace lean::blockchain {
class BlockTree;
} // namespace lean::blockchain

namespace lean::app {
class ChainSpec;
class Configuration;
} // namespace lean::app

namespace lean::blockchain {
class BlockTree;
} // namespace lean::blockchain

namespace lean::metrics {
class Metrics;
} // namespace lean::metrics

namespace lean::modules {
class StatusProtocol;
class BlockRequestProtocol;
Expand All @@ -61,6 +69,7 @@ namespace lean::modules {
class NetworkingImpl final : public Singleton<Networking>, public Networking {
NetworkingImpl(NetworkingLoader &loader,
qtils::SharedRef<log::LoggingSystem> logging_system,
qtils::SharedRef<metrics::Metrics> metrics,
qtils::SharedRef<blockchain::BlockTree> block_tree,
qtils::SharedRef<ForkChoiceStore> fork_choice_store,
qtils::SharedRef<app::ChainSpec> chain_spec,
Expand Down Expand Up @@ -91,8 +100,11 @@ namespace lean::modules {
SignedBlockWithAttestation &&block);
bool statusFinalizedIsGood(const BlockIndex &slot_hash);

void updateMetricConnectedPeerCount();

NetworkingLoader &loader_;
log::Logger logger_;
qtils::SharedRef<metrics::Metrics> metrics_;
qtils::SharedRef<blockchain::BlockTree> block_tree_;
qtils::SharedRef<ForkChoiceStore> fork_choice_store_;
qtils::SharedRef<app::ChainSpec> chain_spec_;
Expand All @@ -106,6 +118,7 @@ namespace lean::modules {
std::shared_ptr<BlockRequestProtocol> block_request_protocol_;
std::shared_ptr<libp2p::protocol::gossip::Gossip> gossip_;
std::shared_ptr<libp2p::protocol::Ping> ping_;
std::shared_ptr<libp2p::host::BasicHost> host_;
std::shared_ptr<libp2p::protocol::Identify> identify_;
std::shared_ptr<libp2p::protocol::gossip::Topic> gossip_blocks_topic_;
std::shared_ptr<libp2p::protocol::gossip::Topic> gossip_votes_topic_;
Expand Down
4 changes: 2 additions & 2 deletions vcpkg-overlay/leanp2p/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ vcpkg_check_linkage(ONLY_STATIC_LIBRARY)
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO qdrvm/leanp2p
REF refs/tags/v0.0.4
SHA512 9ab9ab55b08306198d2bdaf3b80086126b06b2ac04e6f795e22cb1ba7a44f4ae8d8505183622ba91abc1d0c4e65f3148939e5ccdbef7829b5b625a8bf87139fd
REF 3ae885f5b212c6d180b7a66226c812f228b9caf6
SHA512 dfe5e27020d1ee559c8261ee17ba4fd3bd554b17b0da9b6a419d2b898bb4c4677d2e892fd798607c8afcba02df7f018264a76c2a25f5f3b876b9b8dbed5f4c3a
)
vcpkg_cmake_configure(SOURCE_PATH "${SOURCE_PATH}")
vcpkg_cmake_install()
Expand Down
Loading