Skip to content
Merged
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: 1 addition & 1 deletion example/0-single/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Before starting the node, update the GENESIS_TIME in the genesis config file to

```bash
future_time=$(( $(date +%s) + 20 ))
sed -i "s/GENESIS_TIME: .*/GENESIS_TIME: $future_time/" example/0-single/genesis/config.yaml
sed -i '' "s/GENESIS_TIME: .*/GENESIS_TIME: $future_time/" example/0-single/genesis/config.yaml
```

Example CLI command:
Expand Down
10 changes: 5 additions & 5 deletions example/1-network/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Before starting nodes, set `GENESIS_TIME` in `example/1-network/genesis/config.y

```bash
future_time=$(( $(date +%s) + 20 ))
sed -i "s/GENESIS_TIME: .*/GENESIS_TIME: $future_time/" example/1-network/genesis/config.yaml
sed -i '' "s/GENESIS_TIME: .*/GENESIS_TIME: $future_time/" example/1-network/genesis/config.yaml
```

## Start the 4 validators
Expand All @@ -33,7 +33,7 @@ Node 0:
--genesis example/1-network/genesis/config.yaml \
--validator-registry-path example/1-network/genesis/validators.yaml \
--node-id node_0 \
--node-key cb920fbda3b96e18f03e22825f4a5a61343ec43c7be1c8c4a717fffee2f4c4ce \
--node-key 0000000000000000010000000000000002000000000000000300000000000000 \
--listen-addr /ip4/0.0.0.0/udp/9000/quic-v1 \
--prometheus-port 9100
```
Expand All @@ -47,7 +47,7 @@ Node 1:
--genesis example/1-network/genesis/config.yaml \
--validator-registry-path example/1-network/genesis/validators.yaml \
--node-id node_1 \
--node-key a87e7d23bb1de4613b67002b700bce41e031f4ab1529a3436bd73c893ea039b3 \
--node-key 0100000000000000020000000000000003000000000000000400000000000000 \
--listen-addr /ip4/0.0.0.0/udp/9001/quic-v1 \
--prometheus-port 9101
```
Expand All @@ -61,7 +61,7 @@ Node 2:
--genesis example/1-network/genesis/config.yaml \
--validator-registry-path example/1-network/genesis/validators.yaml \
--node-id node_2 \
--node-key f2f53f6acf312c5e92c2a611bbca7a1932b4db0b9e0c43bec413badca9b76760 \
--node-key 0200000000000000030000000000000004000000000000000500000000000000 \
--listen-addr /ip4/0.0.0.0/udp/9002/quic-v1 \
--prometheus-port 9102
```
Expand All @@ -75,7 +75,7 @@ Node 3:
--genesis example/1-network/genesis/config.yaml \
--validator-registry-path example/1-network/genesis/validators.yaml \
--node-id node_3 \
--node-key fa5ddbec80f964d17d28221c2c5bac0f4a3f9cfcf4b86674e605f459e195a1c4 \
--node-key 0300000000000000040000000000000005000000000000000600000000000000 \
--listen-addr /ip4/0.0.0.0/udp/9003/quic-v1 \
--prometheus-port 9103
```
Expand Down
9 changes: 4 additions & 5 deletions example/1-network/genesis/nodes.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
- enr:-IW4QIh9cSo0CPOcsTq5T6SAYr0HrGFMYekZjrgC7ZTgdsMhBKjIQgzCfgqsxulCO4O1TXyjRLZ3BYc4GgqVRvl3d1sBgmlkgnY0gmlwhAoAAAqEcXVpY4IjKIlzZWNwMjU2azGhAmVoFLEuozqtJ7uxbf6RlL8ow-UlDKSYLzxKcbpZ13Zg
- enr:-IW4QG_-KOB94fI18bEqxW8B_lKgG3cGVdvKIIKdZJBLftoaZE5y3Vg4PFQQIPmIRpeD1QawVKrd_6HDd1D2K7WLsLQBgmlkgnY0gmlwhAoAAAuEcXVpY4IjKYlzZWNwMjU2azGhA8PFJzjZs3Nmzn34yVzbnN5Mo5RhzwiWDxLnmoW1U7AV
- enr:-IW4QDEHjhkVEcEX5GS4qAjAHbiqCevwjwFd6ce1SYxLEIgYXDmozUjm8ao4Nl1YoFVhNBs1cn8zW2kwb6yaJpgVDLkBgmlkgnY0gmlwhAoAAAyEcXVpY4IjKolzZWNwMjU2azGhAsQeX5os8a2pG4v2cGuMMXZYY2B-yzYLcZM3yEHa3_kW
- enr:-IW4QEgn7uYKIhbom8qWeFGWBTOh_WZGKjLCfoJay5PHND9yAG359yxsK84DBxfOWm86U5zvVF_UbCO5n1Uz6P2tG28BgmlkgnY0gmlwhAoAAA2EcXVpY4IjK4lzZWNwMjU2azGhAhXhXn0CrP2llJ7PNcWcimcUJ31GeGVMfk0MF2lnH4Ri

- enr:-IW4QF83vMklTZR8wrXxsNiA14P7xNmk79zsy1OsqblVCiG5ZEzT2TMVbtkARM5q0QfHbYU2jaVfk5xCNXEv01LkZ1QBgmlkgnY0gmlwhH8AAAGEcXVpY4InEIlzZWNwMjU2azGhAyUAddLEC14kKi9ziAKt47wyvzX_jvJqFbbD-HkxKQak
- enr:-IW4QBj8XATzGHrMHeYuQG1PLXkH7CujKi0knmbeo8AAGNBqVXM24zrEElpLqYOaPdMiZzjeZ-KKOrZfBy24rvh9QaIBgmlkgnY0gmlwhH8AAAGEcXVpY4InEYlzZWNwMjU2azGhA3x5MQ79P8UyJ8JrEcHbbJp-CbX4AgyV6cZHlYb6uJrl
- enr:-IW4QPpY9L4EHFiGk3FXbGIe_pKSaORsxN-Kij2avIpg4V_jdHCnHYhEc_jyi6CLpwRnbHJvIxduC7AUU3d10P1ZoKoBgmlkgnY0gmlwhH8AAAGEcXVpY4InEolzZWNwMjU2azGhA9GSOWDRYKpxNbaRn_Nctl2E3GBReM6XsPumdACuwJvR
- enr:-IW4QANPPIHjaXKMePVjOIUvqtOUg89t6pWuey9hBcQhywX_dg8QekjUpigHkUvvBO8O7j3-4iRradZCf5puJ4hVDuMBgmlkgnY0gmlwhH8AAAGEcXVpY4InE4lzZWNwMjU2azGhAhbcwnDGuwqTSa-lfSuqVS2F6m3SLNP24pLUPHv6QT8E
48 changes: 27 additions & 21 deletions src/app/application_metrics.def
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,44 @@
*/

/**
* @file application_metrics.def
* @brief Application-level metrics definitions
*
* Format:
* METRIC_GAUGE(field_name,
* "prometheus_metric_name",
* "help_text")
*
* METRIC_GAUGE(field_name,
* "prometheus_metric_name",
* "help_text",
* "label1",
* "label2",
* ...)
* METRIC_GAUGE_LABELS(field_name,
* "prometheus_metric_name",
* "help_text",
* {"label1", "label2", ...})
*
* METRIC_COUNTER(field_name,
* "prometheus_metric_name",
* "help_text")
*
* METRIC_COUNTER_LABELS(field_name,
* "prometheus_metric_name",
* "help_text",
* {"label1", "label2", ...})
*
* Parameters:
* - field_name: Required - C++ member variable name
* - prometheus_metric_name: Required - Prometheus metric name
* - help_text: Required - Metric description
* - labels: Optional - Any number of label names (must be string literals)
* METRIC_HISTOGRAM(field_name,
* "prometheus_metric_name",
* "help_text",
* {bucket1, bucket2, ...})
*
* Notes:
* - All labels MUST be strings (enforced by static_assert at compile time)
* - If you pass a non-string type, you'll get a compile error
* - Usage: metrics_->metric_name({{"label1", value1}, {"label2", value2}})->set(...)
* METRIC_HISTOGRAM_LABELS(field_name,
* "prometheus_metric_name",
* "help_text",
* {bucket1, bucket2, ...},
* {"label1", "label2", ...})
*/

METRIC_GAUGE_LABELS(app_build_info,
"lean_build_info",
"A metric with a constant '1' value labeled by name, version",
"name",
"version")
METRIC_GAUGE_LABELS(
app_build_info,
"lean_build_info",
"A metric with a constant '1' value labeled by name, version",
("name", "version"))

METRIC_GAUGE(app_process_start_time,
"lean_process_start_time_seconds",
Expand Down
15 changes: 12 additions & 3 deletions src/blockchain/fork_choice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ namespace lean {
"Validating attestation for target {}, source {}",
signed_vote.data.target,
signed_vote.data.source);
auto timer = metrics_->fc_attestation_validation_time_seconds()->timer();
auto &vote = signed_vote.data;

// Validate vote targets exist in store
Expand Down Expand Up @@ -223,7 +224,12 @@ namespace lean {
outcome::result<void> ForkChoiceStore::processAttestation(
const SignedVote &signed_vote, bool is_from_block) {
// Validate attestation structure and constraints
BOOST_OUTCOME_TRY(validateAttestation(signed_vote));
if (auto res = validateAttestation(signed_vote); res.has_value()) {
metrics_->fc_attestations_valid_total()->inc();
} else {
metrics_->fc_attestations_invalid_total()->inc();
return res;
}

auto &validator_id = signed_vote.validator_id;
auto &vote = signed_vote.data;
Expand Down Expand Up @@ -261,6 +267,7 @@ namespace lean {
}

outcome::result<void> ForkChoiceStore::onBlock(Block block) {
auto timer = metrics_->fc_block_processing_time_seconds()->timer();
block.setHash();
auto block_hash = block.hash();
// If the block is already known, ignore it
Expand Down Expand Up @@ -464,7 +471,8 @@ namespace lean {
qtils::SharedRef<log::LoggingSystem> logging_system,
qtils::SharedRef<metrics::Metrics> metrics,
qtils::SharedRef<ValidatorRegistry> validator_registry)
: validator_registry_(validator_registry),
: stf_(metrics),
validator_registry_(validator_registry),
logger_(
logging_system->getLogger("ForkChoiceStore", "fork_choice_store")),
metrics_(std::move(metrics)) {
Expand Down Expand Up @@ -507,7 +515,8 @@ namespace lean {
Votes latest_new_votes,
ValidatorIndex validator_index,
qtils::SharedRef<ValidatorRegistry> validator_registry)
: time_(now_sec / SECONDS_PER_INTERVAL),
: stf_(metrics),
time_(now_sec / SECONDS_PER_INTERVAL),
logger_(
logging_system->getLogger("ForkChoiceStore", "fork_choice_store")),
config_(config),
Expand Down
56 changes: 41 additions & 15 deletions src/blockchain/fork_choice_metrics.def
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,55 @@
*/

/**
* @file fork_choice_metrics.def
* @brief ForkChoiceStore metrics definitions
*
* Format:
* METRIC_GAUGE(field_name,
* "prometheus_metric_name",
* "help_text")
*
* METRIC_GAUGE(field_name,
* "prometheus_metric_name",
* "help_text",
* "label1",
* "label2",
* ...)
* METRIC_GAUGE_LABELS(field_name,
* "prometheus_metric_name",
* "help_text",
* {"label1", "label2", ...})
*
* METRIC_COUNTER(field_name,
* "prometheus_metric_name",
* "help_text")
*
* Parameters:
* - field_name: Required - C++ member variable name
* - prometheus_metric_name: Required - Prometheus metric name
* - help_text: Required - Metric description
* - labels: Optional - Any number of label names
* METRIC_COUNTER_LABELS(field_name,
* "prometheus_metric_name",
* "help_text",
* {"label1", "label2", ...})
*
* METRIC_HISTOGRAM(field_name,
* "prometheus_metric_name",
* "help_text",
* {bucket1, bucket2, ...})
*
* METRIC_HISTOGRAM_LABELS(field_name,
* "prometheus_metric_name",
* "help_text",
* {bucket1, bucket2, ...},
* {"label1", "label2", ...})
*/

METRIC_GAUGE(fc_head_slot,
"lean_head_slot",
"Latest slot of the beacon chain")
METRIC_GAUGE(fc_head_slot, "lean_head_slot", "Latest slot of the beacon chain")

// Attestation validation
METRIC_COUNTER(fc_attestations_valid_total,
"lean_attestations_valid_total",
"Total number of valid attestations")
METRIC_COUNTER(fc_attestations_invalid_total,
"lean_attestations_invalid_total",
"Total number of invalid attestations")
METRIC_HISTOGRAM(fc_attestation_validation_time_seconds,
"lean_attestation_validation_time_seconds",
"Time taken to validate attestation",
(0.005, 0.01, 0.025, 0.05, 0.1, 1))

// Block processing
METRIC_HISTOGRAM(fc_block_processing_time_seconds,
"lean_fork_choice_block_processing_time_seconds",
"Time taken to process block in fork choice",
(0.005, 0.01, 0.025, 0.05, 0.1, 1))
43 changes: 43 additions & 0 deletions src/blockchain/impl/validator_metrics.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright Quadrivium LLC
* All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @brief Validator metrics definitions
*
* Format:
* METRIC_GAUGE(field_name,
* "prometheus_metric_name",
* "help_text")
*
* METRIC_GAUGE_LABELS(field_name,
* "prometheus_metric_name",
* "help_text",
* {"label1", "label2", ...})
*
* METRIC_COUNTER(field_name,
* "prometheus_metric_name",
* "help_text")
*
* METRIC_COUNTER_LABELS(field_name,
* "prometheus_metric_name",
* "help_text",
* {"label1", "label2", ...})
*
* METRIC_HISTOGRAM(field_name,
* "prometheus_metric_name",
* "help_text",
* {bucket1, bucket2, ...})
*
* METRIC_HISTOGRAM_LABELS(field_name,
* "prometheus_metric_name",
* "help_text",
* {bucket1, bucket2, ...},
* {"label1", "label2", ...})
*/

METRIC_GAUGE(val_validators_count,
"lean_validators_count",
"Number of connected validators")
9 changes: 9 additions & 0 deletions src/blockchain/impl/validator_registry_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <yaml-cpp/yaml.h>

#include "app/configuration.hpp"
#include "metrics/metrics.hpp"

namespace lean {
enum class ValidatorRegistryError {
Expand Down Expand Up @@ -42,16 +43,20 @@ namespace lean {

ValidatorRegistryImpl::ValidatorRegistryImpl(
qtils::SharedRef<log::LoggingSystem> logging_system,
qtils::SharedRef<metrics::Metrics> metrics,
const app::Configuration &config)
: ValidatorRegistryImpl{std::move(logging_system),
std::move(metrics),
YAML::LoadFile(config.validatorRegistryPath()),
config.nodeId()} {}

ValidatorRegistryImpl::ValidatorRegistryImpl(
qtils::SharedRef<log::LoggingSystem> logging_system,
qtils::SharedRef<metrics::Metrics> metrics,
std::string yaml,
std::string current_node_id)
: ValidatorRegistryImpl{std::move(logging_system),
std::move(metrics),
YAML::Load(yaml),
std::move(current_node_id)} {}

Expand Down Expand Up @@ -83,10 +88,12 @@ namespace lean {

ValidatorRegistryImpl::ValidatorRegistryImpl(
qtils::SharedRef<log::LoggingSystem> logging_system,
qtils::SharedRef<metrics::Metrics> metrics,
YAML::Node root,
std::string current_node_id)
: logger_{logging_system->getLogger("ValidatorRegistry",
"validator_registry")},
metrics_{std::move(metrics)},
current_node_id_{std::move(current_node_id)} {
if (not root.IsDefined() or root.IsNull()) {
SL_WARN(logger_, "Validator registry YAML is empty");
Expand Down Expand Up @@ -161,5 +168,7 @@ namespace lean {
"Validator indices for node '{}' not found in registry YAML",
current_node_id_);
}

metrics_->val_validators_count()->set(current_validator_indices_.size());
}
} // namespace lean
10 changes: 10 additions & 0 deletions src/blockchain/impl/validator_registry_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <boost/di.hpp>
#include <log/logger.hpp>
#include <qtils/shared_ref.hpp>

#include "blockchain/validator_registry.hpp"

Expand All @@ -21,6 +22,10 @@ namespace lean::app {
class Configuration;
} // namespace lean::app

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

namespace lean {
/**
* ValidatorRegistry provides access to mapping between validator indices and
Expand All @@ -36,10 +41,13 @@ namespace lean {
class ValidatorRegistryImpl : public ValidatorRegistry {
public:
ValidatorRegistryImpl(qtils::SharedRef<log::LoggingSystem> logging_system,
qtils::SharedRef<metrics::Metrics> metrics,
const app::Configuration &config);
BOOST_DI_INJECT_TRAITS(qtils::SharedRef<lean::log::LoggingSystem>,
qtils::SharedRef<lean::metrics::Metrics>,
const lean::app::Configuration &);
ValidatorRegistryImpl(qtils::SharedRef<log::LoggingSystem> logging_system,
qtils::SharedRef<metrics::Metrics> metrics,
std::string yaml,
std::string current_node_id);

Expand All @@ -55,10 +63,12 @@ namespace lean {

private:
ValidatorRegistryImpl(qtils::SharedRef<log::LoggingSystem> logging_system,
qtils::SharedRef<metrics::Metrics> metrics,
YAML::Node root,
std::string current_node_id);

log::Logger logger_;
qtils::SharedRef<metrics::Metrics> metrics_;
std::string current_node_id_;
std::unordered_map<ValidatorIndex, std::string> index_to_node_;
std::unordered_map<std::string, std::vector<ValidatorIndex>>
Expand Down
Loading
Loading