Skip to content

Commit

Permalink
chore: cleanup logging
Browse files Browse the repository at this point in the history
  • Loading branch information
refcell committed Oct 24, 2024
1 parent e970f31 commit fd99d0b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 21 deletions.
2 changes: 1 addition & 1 deletion bin/hera/src/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct GossipCommand {
impl GossipCommand {
/// Run the discovery subcommand.
pub async fn run(self, args: &GlobalArgs) -> Result<()> {
let signer = ROLLUP_CONFIGS
let signer = ROLLUP_CONFIGS
.get(&args.l2_chain_id)
.ok_or(eyre::eyre!("No rollup config found for chain ID"))?
.genesis
Expand Down
2 changes: 1 addition & 1 deletion bin/hera/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use clap::{Parser, Subcommand};
use eyre::Result;

mod globals;
mod disc;
mod globals;
mod gossip;
mod node;

Expand Down
8 changes: 3 additions & 5 deletions crates/net/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,11 @@ impl NetworkDriver {
loop {
select! {
peer = peer_recv.recv() => {
tracing::info!("Received peer from discovery: {:?}", peer);
tracing::info!("Dialing peer: {:?}", peer);
self.gossip.dial_opt(peer).await;
tracing::info!("Connected peers: {:?}", self.gossip.connected_peers());
self.gossip.dial_opt(peer.clone()).await;
tracing::info!("Received peer: {:?} | Connected peers: {:?}", peer, self.gossip.connected_peers());
},
event = self.gossip.select_next_some() => {
tracing::info!("Received event: {:?}", event);
tracing::debug!("Received event: {:?}", event);
self.gossip.handle_event(event);
},
}
Expand Down
17 changes: 3 additions & 14 deletions crates/net/src/gossip/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ impl Handler for BlockHandler {
tracing::debug!("received block");

let decoded = if msg.topic == self.blocks_v1_topic.hash() {
tracing::info!("received v1 block");
tracing::debug!("received v1 block");
OpNetworkPayloadEnvelope::decode_v1(&msg.data)
} else if msg.topic == self.blocks_v2_topic.hash() {
tracing::info!("received v2 block");
tracing::debug!("received v2 block");
OpNetworkPayloadEnvelope::decode_v2(&msg.data)
} else if msg.topic == self.blocks_v3_topic.hash() {
tracing::info!("received v3 block");
tracing::debug!("received v3 block");
OpNetworkPayloadEnvelope::decode_v3(&msg.data)
} else {
return MessageAcceptance::Reject;
Expand Down Expand Up @@ -111,30 +111,19 @@ impl BlockHandler {
fn block_valid(&self, envelope: &OpNetworkPayloadEnvelope) -> bool {
let current_timestamp =
SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs();
println!("current_timestamp: {}", current_timestamp);
println!("envelope.payload.timestamp(): {}", envelope.payload.timestamp());

let is_future = envelope.payload.timestamp() > current_timestamp + 5;
println!("is_future: {}", is_future);
let is_past = envelope.payload.timestamp() < current_timestamp - 60;
println!("is_past: {}", is_past);
let time_valid = !(is_future || is_past);
println!("time_valid: {}", time_valid);

let msg = envelope.payload_hash.signature_message(self.chain_id);
println!("msg: {:?}", msg);
let block_signer = *self.unsafe_signer_recv.borrow();
println!("block_signer: {:?}", block_signer);
println!("signature: {:?}", envelope.signature);
let Ok(msg_signer) = envelope.signature.recover_address_from_prehash(&msg) else {
tracing::warn!("Failed to recover address from message");
return false;
};

println!("msg_signer: {:?}", msg_signer);
println!("block_signer: {:?}", block_signer);
let signer_valid = msg_signer == block_signer;
println!("signer_valid: {}", signer_valid);
time_valid && signer_valid
}
}

0 comments on commit fd99d0b

Please sign in to comment.