From d3b108c20339dac8cf32935f999b526646d23ae7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Gr=C3=BCner?= <47506558+MegaRedHand@users.noreply.github.com> Date: Thu, 29 Jan 2026 17:21:04 -0300 Subject: [PATCH 01/16] log: add ShortRoot display helper for truncated hashes --- crates/common/types/src/lib.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/common/types/src/lib.rs b/crates/common/types/src/lib.rs index d344562..8192f00 100644 --- a/crates/common/types/src/lib.rs +++ b/crates/common/types/src/lib.rs @@ -4,3 +4,15 @@ pub mod genesis; pub mod primitives; pub mod signature; pub mod state; + +/// Display helper for truncated root hashes (8 hex chars) +pub struct ShortRoot<'a>(pub &'a [u8; 32]); + +impl std::fmt::Display for ShortRoot<'_> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + for byte in &self.0[..4] { + write!(f, "{:02x}", byte)?; + } + Ok(()) + } +} From 5fd34646dfe7b1da08a49658df35f8783d54eaa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Gr=C3=BCner?= <47506558+MegaRedHand@users.noreply.github.com> Date: Thu, 29 Jan 2026 17:21:42 -0300 Subject: [PATCH 02/16] log: add full context to block reception from gossip --- crates/net/p2p/src/gossipsub/handler.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/crates/net/p2p/src/gossipsub/handler.rs b/crates/net/p2p/src/gossipsub/handler.rs index f9caedf..1abd405 100644 --- a/crates/net/p2p/src/gossipsub/handler.rs +++ b/crates/net/p2p/src/gossipsub/handler.rs @@ -1,7 +1,8 @@ -use ethlambda_types::{attestation::SignedAttestation, block::SignedBlockWithAttestation}; +use ethlambda_types::{attestation::SignedAttestation, block::SignedBlockWithAttestation, ShortRoot}; use libp2p::gossipsub::Event; use ssz::{Decode, Encode}; use tracing::{error, info, trace}; +use tree_hash::TreeHash; use super::{ encoding::{compress_message, decompress_message}, @@ -32,7 +33,18 @@ pub async fn handle_gossipsub_message(server: &mut P2PServer, event: Event) { return; }; let slot = signed_block.message.block.slot; - info!(%slot, "Received new block from gossipsub, sending for processing"); + let block_root = signed_block.message.block.tree_hash_root(); + let proposer = signed_block.message.block.proposer_index; + let parent_root = signed_block.message.block.parent_root; + let attestation_count = signed_block.message.block.body.attestations.len(); + info!( + slot = %slot, + proposer = proposer, + block_root = %ShortRoot(&block_root.0), + parent_root = %ShortRoot(&parent_root.0), + attestation_count = attestation_count, + "Received block from gossip" + ); server.blockchain.notify_new_block(signed_block).await; } Some(ATTESTATION_TOPIC_KIND) => { From 45da2219da791f72613b4709c082fc7e3d42bf26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Gr=C3=BCner?= <47506558+MegaRedHand@users.noreply.github.com> Date: Thu, 29 Jan 2026 17:41:08 -0300 Subject: [PATCH 03/16] log: add block import success and context to failures --- crates/blockchain/src/lib.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/crates/blockchain/src/lib.rs b/crates/blockchain/src/lib.rs index 3fe6eb4..f12f3d5 100644 --- a/crates/blockchain/src/lib.rs +++ b/crates/blockchain/src/lib.rs @@ -10,6 +10,7 @@ use ethlambda_types::{ primitives::TreeHash, signature::ValidatorSecretKey, state::Checkpoint, + ShortRoot, }; use spawned_concurrency::tasks::{ CallResponse, CastResponse, GenServer, GenServerHandle, send_after, @@ -277,6 +278,7 @@ impl BlockChainServer { let slot = signed_block.message.block.slot; let block_root = signed_block.message.block.tree_hash_root(); let parent_root = signed_block.message.block.parent_root; + let proposer = signed_block.message.block.proposer_index; // Check if parent block exists before attempting to process if !self.store.contains_block(&parent_root) { @@ -296,13 +298,26 @@ impl BlockChainServer { // Parent exists, proceed with processing match self.process_block(signed_block) { Ok(_) => { - info!(%slot, "Block processed successfully"); + info!( + slot = %slot, + block_root = %ShortRoot(&block_root.0), + proposer = proposer, + parent_root = %ShortRoot(&parent_root.0), + "Block imported successfully" + ); // Check if any pending blocks can now be processed self.process_pending_children(block_root); } Err(err) => { - warn!(%slot, %err, "Failed to process block"); + warn!( + slot = %slot, + block_root = %ShortRoot(&block_root.0), + proposer = proposer, + parent_root = %ShortRoot(&parent_root.0), + error = %err, + "Failed to process block" + ); } } } From 8d4923ff947c71fee8837112750025baa8654094 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Gr=C3=BCner?= <47506558+MegaRedHand@users.noreply.github.com> Date: Thu, 29 Jan 2026 17:50:48 -0300 Subject: [PATCH 04/16] log: add finalization event logging --- crates/blockchain/state_transition/src/lib.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/crates/blockchain/state_transition/src/lib.rs b/crates/blockchain/state_transition/src/lib.rs index 2c9b4f2..96cb469 100644 --- a/crates/blockchain/state_transition/src/lib.rs +++ b/crates/blockchain/state_transition/src/lib.rs @@ -4,7 +4,9 @@ use ethlambda_types::{ block::{AggregatedAttestations, Block, BlockHeader}, primitives::{H256, TreeHash}, state::{Checkpoint, JustificationValidators, State}, + ShortRoot, }; +use tracing::info; mod justified_slots_ops; pub mod metrics; @@ -307,6 +309,14 @@ fn process_attestations( state.latest_finalized = source; metrics::inc_finalizations("success"); + info!( + finalized_slot = source.slot, + finalized_root = %ShortRoot(&source.root.0), + previous_finalized = old_finalized_slot, + justified_slot = state.latest_justified.slot, + "Checkpoint finalized" + ); + // Shift window to drop finalized slots from the front let delta = (state.latest_finalized.slot - old_finalized_slot) as usize; justified_slots_ops::shift_window(&mut state.justified_slots, delta); From 2f852ff55fe1da24a701a507c86047ce05a45448 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Gr=C3=BCner?= <47506558+MegaRedHand@users.noreply.github.com> Date: Thu, 29 Jan 2026 17:51:51 -0300 Subject: [PATCH 05/16] log: add fork choice head update and justification event logging --- crates/blockchain/src/store.rs | 15 +++++++++++++++ crates/blockchain/state_transition/src/lib.rs | 8 ++++++++ 2 files changed, 23 insertions(+) diff --git a/crates/blockchain/src/store.rs b/crates/blockchain/src/store.rs index 8b28e37..39dea63 100644 --- a/crates/blockchain/src/store.rs +++ b/crates/blockchain/src/store.rs @@ -14,6 +14,7 @@ use ethlambda_types::{ primitives::{H256, TreeHash}, signature::ValidatorSignature, state::{Checkpoint, State, Validator}, + ShortRoot, }; use tracing::{info, trace, warn}; @@ -43,6 +44,20 @@ fn update_head(store: &mut Store) { info!(%old_head, %new_head, "Fork choice reorg detected"); } store.update_checkpoints(ForkCheckpoints::head_only(new_head)); + + if old_head != new_head { + let old_slot = store.get_block(&old_head).map(|b| b.slot).unwrap_or(0); + let new_slot = store.get_block(&new_head).map(|b| b.slot).unwrap_or(0); + info!( + head_slot = new_slot, + head_root = %ShortRoot(&new_head.0), + previous_head_slot = old_slot, + previous_head_root = %ShortRoot(&old_head.0), + justified_slot = store.latest_justified().slot, + finalized_slot = store.latest_finalized().slot, + "Fork choice head updated" + ); + } } /// Update the safe target for attestation. diff --git a/crates/blockchain/state_transition/src/lib.rs b/crates/blockchain/state_transition/src/lib.rs index 96cb469..d3d4149 100644 --- a/crates/blockchain/state_transition/src/lib.rs +++ b/crates/blockchain/state_transition/src/lib.rs @@ -298,6 +298,14 @@ fn process_attestations( target.slot, ); + info!( + justified_slot = target.slot, + justified_root = %ShortRoot(&target.root.0), + vote_count = vote_count, + threshold = (2 * validator_count + 2) / 3, + "Checkpoint justified" + ); + justifications.remove(&target.root); // Consider whether finalization can advance. From b4f49fe11899fc5204f7678bc7eb9b5f7bb58445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Gr=C3=BCner?= <47506558+MegaRedHand@users.noreply.github.com> Date: Thu, 29 Jan 2026 17:52:34 -0300 Subject: [PATCH 06/16] log: add attestation processing with target/source --- crates/blockchain/src/store.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/blockchain/src/store.rs b/crates/blockchain/src/store.rs index 39dea63..3febcda 100644 --- a/crates/blockchain/src/store.rs +++ b/crates/blockchain/src/store.rs @@ -211,7 +211,7 @@ pub fn on_gossip_attestation( return Err(StoreError::SignatureVerificationFailed); } } - on_attestation(store, attestation, false)?; + on_attestation(store, attestation.clone(), false)?; if cfg!(not(feature = "skip-signature-verification")) { // Store signature for later lookup during block building @@ -221,6 +221,17 @@ pub fn on_gossip_attestation( store.insert_gossip_signature(signature_key, signature); } metrics::inc_attestations_valid("gossip"); + + info!( + slot = attestation.data.slot, + validator = validator_id, + target_slot = attestation.data.target.slot, + target_root = %ShortRoot(&attestation.data.target.root.0), + source_slot = attestation.data.source.slot, + source_root = %ShortRoot(&attestation.data.source.root.0), + "Attestation processed" + ); + Ok(()) } From 2b609bc8a1631cd525248fc3c1b14c6be55388e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Gr=C3=BCner?= <47506558+MegaRedHand@users.noreply.github.com> Date: Thu, 29 Jan 2026 17:54:31 -0300 Subject: [PATCH 07/16] log: enhance attestation reception with target/source --- crates/net/p2p/src/gossipsub/handler.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/net/p2p/src/gossipsub/handler.rs b/crates/net/p2p/src/gossipsub/handler.rs index 1abd405..1db1252 100644 --- a/crates/net/p2p/src/gossipsub/handler.rs +++ b/crates/net/p2p/src/gossipsub/handler.rs @@ -61,7 +61,16 @@ pub async fn handle_gossipsub_message(server: &mut P2PServer, event: Event) { }; let slot = signed_attestation.message.slot; let validator = signed_attestation.validator_id; - info!(%slot, %validator, "Received new attestation from gossipsub, sending for processing"); + info!( + slot = %slot, + validator = validator, + head_root = %ShortRoot(&signed_attestation.message.head.root.0), + target_slot = signed_attestation.message.target.slot, + target_root = %ShortRoot(&signed_attestation.message.target.root.0), + source_slot = signed_attestation.message.source.slot, + source_root = %ShortRoot(&signed_attestation.message.source.root.0), + "Received attestation from gossip" + ); server .blockchain .notify_new_attestation(signed_attestation) From 4a42feab572cc60ecf3e9bf66f60da6cbc93db40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Gr=C3=BCner?= <47506558+MegaRedHand@users.noreply.github.com> Date: Thu, 29 Jan 2026 17:54:55 -0300 Subject: [PATCH 08/16] log: add block and attestation publication details --- crates/net/p2p/src/gossipsub/handler.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/crates/net/p2p/src/gossipsub/handler.rs b/crates/net/p2p/src/gossipsub/handler.rs index 1db1252..c966ea5 100644 --- a/crates/net/p2p/src/gossipsub/handler.rs +++ b/crates/net/p2p/src/gossipsub/handler.rs @@ -98,7 +98,13 @@ pub async fn publish_attestation(server: &mut P2PServer, attestation: SignedAtte .behaviour_mut() .gossipsub .publish(server.attestation_topic.clone(), compressed) - .inspect(|_| trace!(%slot, %validator, "Published attestation to gossipsub")) + .inspect(|_| info!( + slot = %slot, + validator = validator, + target_slot = attestation.message.target.slot, + source_slot = attestation.message.source.slot, + "Published attestation to gossipsub" + )) .inspect_err(|err| { tracing::warn!(%slot, %validator, %err, "Failed to publish attestation to gossipsub") }); @@ -107,6 +113,9 @@ pub async fn publish_attestation(server: &mut P2PServer, attestation: SignedAtte pub async fn publish_block(server: &mut P2PServer, signed_block: SignedBlockWithAttestation) { let slot = signed_block.message.block.slot; let proposer = signed_block.message.block.proposer_index; + let block_root = signed_block.message.block.tree_hash_root(); + let parent_root = signed_block.message.block.parent_root; + let attestation_count = signed_block.message.block.body.attestations.len(); // Encode to SSZ let ssz_bytes = signed_block.as_ssz_bytes(); @@ -120,7 +129,14 @@ pub async fn publish_block(server: &mut P2PServer, signed_block: SignedBlockWith .behaviour_mut() .gossipsub .publish(server.block_topic.clone(), compressed) - .inspect(|_| info!(%slot, %proposer, "Published block to gossipsub")) + .inspect(|_| info!( + slot = %slot, + proposer = proposer, + block_root = %ShortRoot(&block_root.0), + parent_root = %ShortRoot(&parent_root.0), + attestation_count = attestation_count, + "Published block to gossipsub" + )) .inspect_err( |err| tracing::warn!(%slot, %proposer, %err, "Failed to publish block to gossipsub"), ); From e8da495e0800af4fb5018bcaa4b49b307da23397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Gr=C3=BCner?= <47506558+MegaRedHand@users.noreply.github.com> Date: Thu, 29 Jan 2026 17:57:27 -0300 Subject: [PATCH 09/16] log: add peer count to connection logs --- crates/net/p2p/src/lib.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/crates/net/p2p/src/lib.rs b/crates/net/p2p/src/lib.rs index 06f77ad..736524d 100644 --- a/crates/net/p2p/src/lib.rs +++ b/crates/net/p2p/src/lib.rs @@ -246,10 +246,18 @@ async fn handle_swarm_event(server: &mut P2PServer, event: SwarmEvent { let result = if error.to_string().to_lowercase().contains("timed out") { From 2dabc22dbe4f992e21dbe5ecffbfffafbffaaefb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Gr=C3=BCner?= <47506558+MegaRedHand@users.noreply.github.com> Date: Thu, 29 Jan 2026 18:02:41 -0300 Subject: [PATCH 10/16] fix: add tracing dependency and use div_ceil for clippy --- Cargo.lock | 1 + crates/blockchain/state_transition/Cargo.toml | 1 + crates/blockchain/state_transition/src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index dd70cad..88a3df4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2061,6 +2061,7 @@ dependencies = [ "serde", "serde_json", "thiserror 2.0.17", + "tracing", ] [[package]] diff --git a/crates/blockchain/state_transition/Cargo.toml b/crates/blockchain/state_transition/Cargo.toml index 01d06b0..d5335b8 100644 --- a/crates/blockchain/state_transition/Cargo.toml +++ b/crates/blockchain/state_transition/Cargo.toml @@ -14,6 +14,7 @@ ethlambda-types.workspace = true ethlambda-metrics.workspace = true thiserror.workspace = true +tracing.workspace = true [dev-dependencies] serde.workspace = true diff --git a/crates/blockchain/state_transition/src/lib.rs b/crates/blockchain/state_transition/src/lib.rs index d3d4149..6c5a270 100644 --- a/crates/blockchain/state_transition/src/lib.rs +++ b/crates/blockchain/state_transition/src/lib.rs @@ -302,7 +302,7 @@ fn process_attestations( justified_slot = target.slot, justified_root = %ShortRoot(&target.root.0), vote_count = vote_count, - threshold = (2 * validator_count + 2) / 3, + threshold = (2 * validator_count).div_ceil(3), "Checkpoint justified" ); From 19f606489bdb44138e996536ea6ffa016d3db5a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Gr=C3=BCner?= <47506558+MegaRedHand@users.noreply.github.com> Date: Thu, 29 Jan 2026 18:54:16 -0300 Subject: [PATCH 11/16] fix: standardize field order in block logs --- crates/blockchain/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/blockchain/src/lib.rs b/crates/blockchain/src/lib.rs index f12f3d5..6abe3ba 100644 --- a/crates/blockchain/src/lib.rs +++ b/crates/blockchain/src/lib.rs @@ -300,8 +300,8 @@ impl BlockChainServer { Ok(_) => { info!( slot = %slot, - block_root = %ShortRoot(&block_root.0), proposer = proposer, + block_root = %ShortRoot(&block_root.0), parent_root = %ShortRoot(&parent_root.0), "Block imported successfully" ); @@ -312,8 +312,8 @@ impl BlockChainServer { Err(err) => { warn!( slot = %slot, - block_root = %ShortRoot(&block_root.0), proposer = proposer, + block_root = %ShortRoot(&block_root.0), parent_root = %ShortRoot(&parent_root.0), error = %err, "Failed to process block" From e8b3f100d08a2a9b76ad4e625f8fdb00a8fb1b63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Gr=C3=BCner?= <47506558+MegaRedHand@users.noreply.github.com> Date: Thu, 29 Jan 2026 19:07:37 -0300 Subject: [PATCH 12/16] fix: add target_root and source_root to attestation publication log --- crates/net/p2p/src/gossipsub/handler.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/net/p2p/src/gossipsub/handler.rs b/crates/net/p2p/src/gossipsub/handler.rs index c966ea5..04fa73d 100644 --- a/crates/net/p2p/src/gossipsub/handler.rs +++ b/crates/net/p2p/src/gossipsub/handler.rs @@ -102,7 +102,9 @@ pub async fn publish_attestation(server: &mut P2PServer, attestation: SignedAtte slot = %slot, validator = validator, target_slot = attestation.message.target.slot, + target_root = %ShortRoot(&attestation.message.target.root.0), source_slot = attestation.message.source.slot, + source_root = %ShortRoot(&attestation.message.source.root.0), "Published attestation to gossipsub" )) .inspect_err(|err| { From 23695d6c1445d4654243d5eb71e8455d438220e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Gr=C3=BCner?= <47506558+MegaRedHand@users.noreply.github.com> Date: Thu, 29 Jan 2026 19:19:45 -0300 Subject: [PATCH 13/16] Apply suggestion from @greptile-apps[bot] Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --- crates/net/p2p/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/net/p2p/src/lib.rs b/crates/net/p2p/src/lib.rs index 736524d..847e17b 100644 --- a/crates/net/p2p/src/lib.rs +++ b/crates/net/p2p/src/lib.rs @@ -254,8 +254,8 @@ async fn handle_swarm_event(server: &mut P2PServer, event: SwarmEvent Date: Thu, 29 Jan 2026 19:26:31 -0300 Subject: [PATCH 14/16] refactor: simplify log field syntax using tracing shorthands --- crates/blockchain/src/lib.rs | 10 +++++----- crates/blockchain/src/store.rs | 15 +++++++++----- crates/blockchain/state_transition/src/lib.rs | 17 ++++++++++------ crates/net/p2p/src/gossipsub/handler.rs | 20 +++++++++---------- crates/net/p2p/src/lib.rs | 20 ++++++++++--------- 5 files changed, 47 insertions(+), 35 deletions(-) diff --git a/crates/blockchain/src/lib.rs b/crates/blockchain/src/lib.rs index 6abe3ba..0b15fcd 100644 --- a/crates/blockchain/src/lib.rs +++ b/crates/blockchain/src/lib.rs @@ -299,8 +299,8 @@ impl BlockChainServer { match self.process_block(signed_block) { Ok(_) => { info!( - slot = %slot, - proposer = proposer, + %slot, + proposer, block_root = %ShortRoot(&block_root.0), parent_root = %ShortRoot(&parent_root.0), "Block imported successfully" @@ -311,11 +311,11 @@ impl BlockChainServer { } Err(err) => { warn!( - slot = %slot, - proposer = proposer, + %slot, + proposer, block_root = %ShortRoot(&block_root.0), parent_root = %ShortRoot(&parent_root.0), - error = %err, + %err, "Failed to process block" ); } diff --git a/crates/blockchain/src/store.rs b/crates/blockchain/src/store.rs index 3febcda..65034f7 100644 --- a/crates/blockchain/src/store.rs +++ b/crates/blockchain/src/store.rs @@ -48,13 +48,15 @@ fn update_head(store: &mut Store) { if old_head != new_head { let old_slot = store.get_block(&old_head).map(|b| b.slot).unwrap_or(0); let new_slot = store.get_block(&new_head).map(|b| b.slot).unwrap_or(0); + let justified_slot = store.latest_justified().slot; + let finalized_slot = store.latest_finalized().slot; info!( head_slot = new_slot, head_root = %ShortRoot(&new_head.0), previous_head_slot = old_slot, previous_head_root = %ShortRoot(&old_head.0), - justified_slot = store.latest_justified().slot, - finalized_slot = store.latest_finalized().slot, + justified_slot, + finalized_slot, "Fork choice head updated" ); } @@ -222,12 +224,15 @@ pub fn on_gossip_attestation( } metrics::inc_attestations_valid("gossip"); + let slot = attestation.data.slot; + let target_slot = attestation.data.target.slot; + let source_slot = attestation.data.source.slot; info!( - slot = attestation.data.slot, + slot, validator = validator_id, - target_slot = attestation.data.target.slot, + target_slot, target_root = %ShortRoot(&attestation.data.target.root.0), - source_slot = attestation.data.source.slot, + source_slot, source_root = %ShortRoot(&attestation.data.source.root.0), "Attestation processed" ); diff --git a/crates/blockchain/state_transition/src/lib.rs b/crates/blockchain/state_transition/src/lib.rs index 6c5a270..cad74de 100644 --- a/crates/blockchain/state_transition/src/lib.rs +++ b/crates/blockchain/state_transition/src/lib.rs @@ -298,11 +298,13 @@ fn process_attestations( target.slot, ); + let justified_slot = target.slot; + let threshold = (2 * validator_count).div_ceil(3); info!( - justified_slot = target.slot, + justified_slot, justified_root = %ShortRoot(&target.root.0), - vote_count = vote_count, - threshold = (2 * validator_count).div_ceil(3), + vote_count, + threshold, "Checkpoint justified" ); @@ -317,11 +319,14 @@ fn process_attestations( state.latest_finalized = source; metrics::inc_finalizations("success"); + let finalized_slot = source.slot; + let previous_finalized = old_finalized_slot; + let justified_slot = state.latest_justified.slot; info!( - finalized_slot = source.slot, + finalized_slot, finalized_root = %ShortRoot(&source.root.0), - previous_finalized = old_finalized_slot, - justified_slot = state.latest_justified.slot, + previous_finalized, + justified_slot, "Checkpoint finalized" ); diff --git a/crates/net/p2p/src/gossipsub/handler.rs b/crates/net/p2p/src/gossipsub/handler.rs index 04fa73d..f1aefe1 100644 --- a/crates/net/p2p/src/gossipsub/handler.rs +++ b/crates/net/p2p/src/gossipsub/handler.rs @@ -38,11 +38,11 @@ pub async fn handle_gossipsub_message(server: &mut P2PServer, event: Event) { let parent_root = signed_block.message.block.parent_root; let attestation_count = signed_block.message.block.body.attestations.len(); info!( - slot = %slot, - proposer = proposer, + %slot, + proposer, block_root = %ShortRoot(&block_root.0), parent_root = %ShortRoot(&parent_root.0), - attestation_count = attestation_count, + attestation_count, "Received block from gossip" ); server.blockchain.notify_new_block(signed_block).await; @@ -62,8 +62,8 @@ pub async fn handle_gossipsub_message(server: &mut P2PServer, event: Event) { let slot = signed_attestation.message.slot; let validator = signed_attestation.validator_id; info!( - slot = %slot, - validator = validator, + %slot, + validator, head_root = %ShortRoot(&signed_attestation.message.head.root.0), target_slot = signed_attestation.message.target.slot, target_root = %ShortRoot(&signed_attestation.message.target.root.0), @@ -99,8 +99,8 @@ pub async fn publish_attestation(server: &mut P2PServer, attestation: SignedAtte .gossipsub .publish(server.attestation_topic.clone(), compressed) .inspect(|_| info!( - slot = %slot, - validator = validator, + %slot, + validator, target_slot = attestation.message.target.slot, target_root = %ShortRoot(&attestation.message.target.root.0), source_slot = attestation.message.source.slot, @@ -132,11 +132,11 @@ pub async fn publish_block(server: &mut P2PServer, signed_block: SignedBlockWith .gossipsub .publish(server.block_topic.clone(), compressed) .inspect(|_| info!( - slot = %slot, - proposer = proposer, + %slot, + proposer, block_root = %ShortRoot(&block_root.0), parent_root = %ShortRoot(&parent_root.0), - attestation_count = attestation_count, + attestation_count, "Published block to gossipsub" )) .inspect_err( diff --git a/crates/net/p2p/src/lib.rs b/crates/net/p2p/src/lib.rs index 847e17b..97097cc 100644 --- a/crates/net/p2p/src/lib.rs +++ b/crates/net/p2p/src/lib.rs @@ -250,12 +250,14 @@ async fn handle_swarm_event(server: &mut P2PServer, event: SwarmEvent Date: Thu, 29 Jan 2026 19:30:55 -0300 Subject: [PATCH 15/16] chore: fmt --- crates/blockchain/src/lib.rs | 2 +- crates/blockchain/src/store.rs | 2 +- crates/blockchain/state_transition/src/lib.rs | 2 +- crates/net/p2p/src/gossipsub/handler.rs | 22 +++++++++++-------- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/crates/blockchain/src/lib.rs b/crates/blockchain/src/lib.rs index 0b15fcd..a438a46 100644 --- a/crates/blockchain/src/lib.rs +++ b/crates/blockchain/src/lib.rs @@ -5,12 +5,12 @@ use ethlambda_state_transition::is_proposer; use ethlambda_storage::Store; use ethlambda_types::primitives::H256; use ethlambda_types::{ + ShortRoot, attestation::{Attestation, AttestationData, SignedAttestation}, block::{BlockSignatures, BlockWithAttestation, SignedBlockWithAttestation}, primitives::TreeHash, signature::ValidatorSecretKey, state::Checkpoint, - ShortRoot, }; use spawned_concurrency::tasks::{ CallResponse, CastResponse, GenServer, GenServerHandle, send_after, diff --git a/crates/blockchain/src/store.rs b/crates/blockchain/src/store.rs index 65034f7..e9e252c 100644 --- a/crates/blockchain/src/store.rs +++ b/crates/blockchain/src/store.rs @@ -6,6 +6,7 @@ use ethlambda_state_transition::{ }; use ethlambda_storage::{ForkCheckpoints, SignatureKey, Store}; use ethlambda_types::{ + ShortRoot, attestation::{AggregatedAttestation, Attestation, AttestationData, SignedAttestation}, block::{ AggregatedAttestations, AggregatedSignatureProof, AggregationBits, Block, BlockBody, @@ -14,7 +15,6 @@ use ethlambda_types::{ primitives::{H256, TreeHash}, signature::ValidatorSignature, state::{Checkpoint, State, Validator}, - ShortRoot, }; use tracing::{info, trace, warn}; diff --git a/crates/blockchain/state_transition/src/lib.rs b/crates/blockchain/state_transition/src/lib.rs index cad74de..815b737 100644 --- a/crates/blockchain/state_transition/src/lib.rs +++ b/crates/blockchain/state_transition/src/lib.rs @@ -1,10 +1,10 @@ use std::collections::HashMap; use ethlambda_types::{ + ShortRoot, block::{AggregatedAttestations, Block, BlockHeader}, primitives::{H256, TreeHash}, state::{Checkpoint, JustificationValidators, State}, - ShortRoot, }; use tracing::info; diff --git a/crates/net/p2p/src/gossipsub/handler.rs b/crates/net/p2p/src/gossipsub/handler.rs index f1aefe1..5dd9a9b 100644 --- a/crates/net/p2p/src/gossipsub/handler.rs +++ b/crates/net/p2p/src/gossipsub/handler.rs @@ -1,4 +1,6 @@ -use ethlambda_types::{attestation::SignedAttestation, block::SignedBlockWithAttestation, ShortRoot}; +use ethlambda_types::{ + ShortRoot, attestation::SignedAttestation, block::SignedBlockWithAttestation, +}; use libp2p::gossipsub::Event; use ssz::{Decode, Encode}; use tracing::{error, info, trace}; @@ -131,14 +133,16 @@ pub async fn publish_block(server: &mut P2PServer, signed_block: SignedBlockWith .behaviour_mut() .gossipsub .publish(server.block_topic.clone(), compressed) - .inspect(|_| info!( - %slot, - proposer, - block_root = %ShortRoot(&block_root.0), - parent_root = %ShortRoot(&parent_root.0), - attestation_count, - "Published block to gossipsub" - )) + .inspect(|_| { + info!( + %slot, + proposer, + block_root = %ShortRoot(&block_root.0), + parent_root = %ShortRoot(&parent_root.0), + attestation_count, + "Published block to gossipsub" + ) + }) .inspect_err( |err| tracing::warn!(%slot, %proposer, %err, "Failed to publish block to gossipsub"), ); From a6fee9d5fe0198688b1a5fb7bbf37a6e3dac97b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Gr=C3=BCner?= <47506558+MegaRedHand@users.noreply.github.com> Date: Thu, 29 Jan 2026 19:32:02 -0300 Subject: [PATCH 16/16] docs: add logging patterns to CLAUDE.md --- CLAUDE.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/CLAUDE.md b/CLAUDE.md index b3633e0..dbe0095 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -87,6 +87,51 @@ rm -rf leanSpec && make leanSpec/fixtures # Regenerate test fixtures (require let _timing = metrics::time_state_transition(); ``` +### Logging Patterns + +**Use tracing shorthand syntax for cleaner logs:** +```rust +// ✅ GOOD: Shorthand for simple variables +let slot = block.slot; +let proposer = block.proposer_index; +info!( + %slot, // Shorthand for slot = %slot (Display) + proposer, // Shorthand for proposer = proposer + block_root = %ShortRoot(&block_root.0), // Named expression + "Block imported" +); + +// ❌ BAD: Verbose +info!( + slot = %slot, + proposer = proposer, + ... +); +``` + +**Standardized field ordering (temporal → identity → identifiers → context → metadata):** +```rust +// Block logs +info!(%slot, proposer, block_root = ..., parent_root = ..., attestation_count, "..."); + +// Attestation logs +info!(%slot, validator, target_slot, target_root = ..., source_slot, source_root = ..., "..."); + +// Consensus events +info!(finalized_slot, finalized_root = ..., previous_finalized, justified_slot, "..."); + +// Peer events +info!(%peer_id, %direction, peer_count, our_finalized_slot, our_head_slot, "..."); +``` + +**Root hash truncation:** +```rust +use ethlambda_types::ShortRoot; + +// Always use ShortRoot for consistent 8-char display (4 bytes) +info!(block_root = %ShortRoot(&root.0), "..."); +``` + ### Relative Indexing (justified_slots) ```rust // Bounded storage: index relative to finalized_slot