Skip to content

Commit

Permalink
fix: metrics and should serve logic
Browse files Browse the repository at this point in the history
  • Loading branch information
renancloudwalk committed May 30, 2024
1 parent 7f0eb9d commit 10e5c90
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/eth/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ pub mod consensus_kube {
!self.is_leader()
}

//TODO for now the block number is the index, but it should be a separate index wiht the execution AND the block
pub async fn should_serve(&self) -> bool {
if Self::current_node().is_none() {
return false;
Expand All @@ -187,7 +188,7 @@ pub mod consensus_kube {
storage_block_number
);

last_arrived_block_number > (storage_block_number + 3)
(last_arrived_block_number - 2) <= storage_block_number
}

fn current_node() -> Option<String> {
Expand Down Expand Up @@ -299,7 +300,7 @@ pub mod consensus_kube {
#[tracing::instrument(skip_all)]
pub async fn append_block_commit_to_followers(block: Block, followers: Vec<Peer>) -> Result<(), anyhow::Error> {
let header: BlockHeader = (&block.header).into();
let transaction_hashes = vec!["hash1".to_string(), "hash2".to_string()]; // Replace with actual transaction hashes
let transaction_hashes = vec![]; // Replace with actual transaction hashes

let term = 0; // Populate with actual term
let prev_log_index = 0; // Populate with actual previous log index
Expand Down Expand Up @@ -370,6 +371,9 @@ pub mod consensus_kube {
"last arrived block number set",
);

#[cfg(feature = "metrics")]
metrics::set_append_entries_block_number_diff(last_last_arrived_block_number - header.number);

Ok(Response::new(AppendBlockCommitResponse {
status: StatusCode::AppendSuccess as i32,
message: "Block Commit appended successfully".into(),
Expand Down
5 changes: 4 additions & 1 deletion src/infra/metrics/metrics_definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ metrics! {
histogram_duration append_entries{} [],

"Time to run Consensus::append_entries_to_followers."
histogram_duration append_entries_to_followers{} []
histogram_duration append_entries_to_followers{} [],

"The diff between what is on the follower database and what it received from Append Entries."
gauge append_entries_block_number_diff{} []
}

metrics! {
Expand Down

0 comments on commit 10e5c90

Please sign in to comment.