Skip to content

Enhance mithril-common logging #1940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 20, 2024
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
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions mithril-common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-common"
version = "0.4.53"
version = "0.4.54"
description = "Common types, interfaces, and utilities for Mithril nodes."
authors = { workspace = true }
edition = { workspace = true }
Expand Down Expand Up @@ -84,7 +84,6 @@ pallas-crypto = "0.30.1"
rand_core = { version = "0.6.4", features = ["getrandom"] }
reqwest = { version = "0.12.7", features = ["json"] }
slog-async = "2.8.0"
slog-scope = "4.4.0"
slog-term = "2.9.1"
tokio = { version = "1.40.0", features = ["macros", "rt-multi-thread", "time"] }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::cardano_block_scanner::BlockStreamer;
use crate::cardano_block_scanner::ChainScannedBlocks;
use crate::chain_reader::{ChainBlockNextAction, ChainBlockReader};
use crate::entities::{BlockNumber, ChainPoint};
use crate::logging::LoggerExtensions;
use crate::StdResult;

/// The action that indicates what to do next with the streamer
Expand All @@ -31,7 +32,7 @@ pub struct ChainReaderBlockStreamer {
#[async_trait]
impl BlockStreamer for ChainReaderBlockStreamer {
async fn poll_next(&mut self) -> StdResult<Option<ChainScannedBlocks>> {
debug!(self.logger, "ChainReaderBlockStreamer polls next");
debug!(self.logger, "polls next");

let chain_scanned_blocks: ChainScannedBlocks;
let mut roll_forwards = vec![];
Expand Down Expand Up @@ -111,7 +112,7 @@ impl ChainReaderBlockStreamer {
from,
until,
max_roll_forwards_per_poll,
logger,
logger: logger.new_with_component_name::<Self>(),
})
}

Expand All @@ -122,14 +123,14 @@ impl ChainReaderBlockStreamer {
if parsed_block.block_number > self.until {
trace!(
self.logger,
"ChainReaderBlockStreamer received a RollForward above threshold block number ({})",
"received a RollForward above threshold block number ({})",
parsed_block.block_number
);
Ok(None)
} else {
trace!(
self.logger,
"ChainReaderBlockStreamer received a RollForward below threshold block number ({})",
"received a RollForward below threshold block number ({})",
parsed_block.block_number
);
Ok(Some(BlockStreamerNextAction::ChainBlockNextAction(
Expand All @@ -142,7 +143,7 @@ impl ChainReaderBlockStreamer {
}) => {
trace!(
self.logger,
"ChainReaderBlockStreamer received a RollBackward({rollback_slot_number:?})"
"received a RollBackward({rollback_slot_number:?})"
);
let block_streamer_next_action = if rollback_slot_number == self.from.slot_number {
BlockStreamerNextAction::SkipToNextAction
Expand All @@ -156,7 +157,7 @@ impl ChainReaderBlockStreamer {
Ok(Some(block_streamer_next_action))
}
None => {
trace!(self.logger, "ChainReaderBlockStreamer received nothing");
trace!(self.logger, "received nothing");
Ok(None)
}
}
Expand Down
16 changes: 7 additions & 9 deletions mithril-common/src/cardano_transactions_preloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use slog::{debug, info, Logger};

use crate::chain_observer::ChainObserver;
use crate::entities::{BlockNumber, SignedEntityTypeDiscriminants};
use crate::logging::LoggerExtensions;
use crate::signable_builder::TransactionsImporter;
use crate::signed_entity_type_lock::SignedEntityTypeLock;
use crate::StdResult;
Expand Down Expand Up @@ -71,34 +72,31 @@ impl CardanoTransactionsPreloader {
importer,
security_parameter,
chain_observer,
logger,
logger: logger.new_with_component_name::<Self>(),
activation_state,
}
}

/// Preload the Cardano Transactions by running the importer up to the current chain block number.
pub async fn preload(&self) -> StdResult<()> {
if !self.is_activated().await? {
debug!(
self.logger,
"⟳ Preload Cardano Transactions - Not running, conditions not met"
);
debug!(self.logger, "Not running, conditions not met");
return Ok(());
}

info!(self.logger, "⟳ Preload Cardano Transactions - Started");
debug!(self.logger, "Locking signed entity type"; "entity_type" => "CardanoTransactions");
info!(self.logger, "Started");
debug!(self.logger, "Locking signed entity type"; "entity_type" => "CardanoTransactions");
self.signed_entity_type_lock
.lock(SignedEntityTypeDiscriminants::CardanoTransactions)
.await;

let preload_result = self.do_preload().await;

debug!(self.logger, "Releasing signed entity type"; "entity_type" => "CardanoTransactions");
debug!(self.logger, "Releasing signed entity type"; "entity_type" => "CardanoTransactions");
self.signed_entity_type_lock
.release(SignedEntityTypeDiscriminants::CardanoTransactions)
.await;
info!(self.logger, "⟳ Preload Cardano Transactions - Finished");
info!(self.logger, "Finished");

preload_result
}
Expand Down
22 changes: 11 additions & 11 deletions mithril-common/src/certificate_chain/certificate_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::crypto_helper::{
use crate::entities::{
Certificate, CertificateSignature, ProtocolMessage, ProtocolMessagePartKey, ProtocolParameters,
};
use crate::logging::LoggerExtensions;
use crate::StdResult;

#[cfg(test)]
Expand Down Expand Up @@ -122,7 +123,7 @@ impl MithrilCertificateVerifier {
pub fn new(logger: Logger, certificate_retriever: Arc<dyn CertificateRetriever>) -> Self {
debug!(logger, "New MithrilCertificateVerifier created");
Self {
logger,
logger: logger.new_with_component_name::<Self>(),
certificate_retriever,
}
}
Expand Down Expand Up @@ -302,14 +303,13 @@ impl CertificateVerifier for MithrilCertificateVerifier {
mod tests {
use async_trait::async_trait;
use mockall::mock;
use slog_scope;

use super::CertificateRetriever;
use super::*;

use crate::certificate_chain::CertificateRetrieverError;
use crate::crypto_helper::{tests_setup::*, ProtocolClerk};
use crate::test_utils::MithrilFixtureBuilder;
use crate::test_utils::{MithrilFixtureBuilder, TestLogger};

mock! {
pub CertificateRetrieverImpl { }
Expand Down Expand Up @@ -348,7 +348,7 @@ mod tests {
.into();

let verifier = MithrilCertificateVerifier::new(
slog_scope::logger(),
TestLogger::stdout(),
Arc::new(MockCertificateRetrieverImpl::new()),
);
let message_tampered = message_hash[1..].to_vec();
Expand Down Expand Up @@ -387,7 +387,7 @@ mod tests {
.returning(move |_| Ok(fake_certificate2.clone()))
.times(1);
let verifier = MithrilCertificateVerifier::new(
slog_scope::logger(),
TestLogger::stdout(),
Arc::new(mock_certificate_retriever),
);
let verify = verifier
Expand All @@ -410,7 +410,7 @@ mod tests {
.returning(move |_| Ok(fake_certificate2.clone()))
.times(1);
let verifier = MithrilCertificateVerifier::new(
slog_scope::logger(),
TestLogger::stdout(),
Arc::new(mock_certificate_retriever),
);
let verify = verifier
Expand All @@ -435,7 +435,7 @@ mod tests {
.returning(move |_| Ok(fake_certificate2.clone()))
.times(1);
let verifier = MithrilCertificateVerifier::new(
slog_scope::logger(),
TestLogger::stdout(),
Arc::new(mock_certificate_retriever),
);
let error = verifier
Expand Down Expand Up @@ -478,7 +478,7 @@ mod tests {
.returning(move |_| Ok(fake_certificate2.clone()))
.times(1);
let verifier = MithrilCertificateVerifier::new(
slog_scope::logger(),
TestLogger::stdout(),
Arc::new(mock_certificate_retriever),
);
let error = verifier
Expand All @@ -505,7 +505,7 @@ mod tests {
fake_certificate1.hash = "another-hash".to_string();
let mock_certificate_retriever = MockCertificateRetrieverImpl::new();
let verifier = MithrilCertificateVerifier::new(
slog_scope::logger(),
TestLogger::stdout(),
Arc::new(mock_certificate_retriever),
);
let error = verifier
Expand Down Expand Up @@ -537,7 +537,7 @@ mod tests {
.times(1);
}
let verifier = MithrilCertificateVerifier::new(
slog_scope::logger(),
TestLogger::stdout(),
Arc::new(mock_certificate_retriever),
);
let verify = verifier
Expand Down Expand Up @@ -570,7 +570,7 @@ mod tests {
.times(1);
}
let verifier = MithrilCertificateVerifier::new(
slog_scope::logger(),
TestLogger::stdout(),
Arc::new(mock_certificate_retriever),
);
let error = verifier
Expand Down
9 changes: 5 additions & 4 deletions mithril-common/src/chain_reader/pallas_chain_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use pallas_network::{
use pallas_traverse::MultiEraBlock;
use slog::{debug, Logger};

use crate::logging::LoggerExtensions;
use crate::{cardano_block_scanner::ScannedBlock, entities::ChainPoint, CardanoNetwork, StdResult};

use super::{ChainBlockNextAction, ChainBlockReader};
Expand All @@ -28,7 +29,7 @@ impl PallasChainReader {
socket: socket.to_owned(),
network,
client: None,
logger,
logger: logger.new_with_component_name::<Self>(),
}
}

Expand All @@ -45,7 +46,7 @@ impl PallasChainReader {
async fn get_client(&mut self) -> StdResult<&mut NodeClient> {
if self.client.is_none() {
self.client = Some(self.new_client().await?);
debug!(self.logger, "PallasChainReader connected to a new client");
debug!(self.logger, "connected to a new client");
}

self.client
Expand All @@ -60,12 +61,12 @@ impl PallasChainReader {
let chainsync = client.chainsync();

if chainsync.has_agency() {
debug!(logger, "PallasChainReader has agency, finding intersect point..."; "point" => ?point);
debug!(logger, "has agency, finding intersect point..."; "point" => ?point);
chainsync
.find_intersect(vec![point.to_owned().into()])
.await?;
} else {
debug!(logger, "PallasChainReader doesn't have agency, no need to find intersect point";);
debug!(logger, "doesn't have agency, no need to find intersect point";);
}

Ok(())
Expand Down
3 changes: 2 additions & 1 deletion mithril-common/src/digesters/cache/json_provider_builder.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{
digesters::cache::{ImmutableFileDigestCacheProvider, JsonImmutableFileDigestCacheProvider},
logging::LoggerExtensions,
StdResult,
};
use anyhow::Context;
Expand Down Expand Up @@ -43,7 +44,7 @@ impl<'a> JsonImmutableFileDigestCacheProviderBuilder<'a> {

/// Set the [Logger] to use.
pub fn with_logger(&mut self, logger: Logger) -> &mut Self {
self.logger = logger;
self.logger = logger.new_with_component_name::<Self>();
self
}

Expand Down
3 changes: 2 additions & 1 deletion mithril-common/src/digesters/cardano_immutable_digester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{
ImmutableFile,
},
entities::{CardanoDbBeacon, HexEncodedDigest, ImmutableFileName},
logging::LoggerExtensions,
};
use async_trait::async_trait;
use sha2::{Digest, Sha256};
Expand Down Expand Up @@ -32,7 +33,7 @@ impl CardanoImmutableDigester {
) -> Self {
Self {
cache_provider,
logger,
logger: logger.new_with_component_name::<Self>(),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions mithril-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub mod crypto_helper;
pub mod entities;
#[macro_use]
pub mod era;
pub mod logging;
pub mod messages;
pub mod protocol;
pub mod resource_pool;
Expand Down
Loading
Loading