Просмотр исходного кода

consensus/proposal: addeed fmt::Display trait for simpler logging

aggstam 4 лет назад
Родитель
Сommit
9cac1225dc

+ 14 - 1
src/consensus/block.rs

@@ -1,4 +1,4 @@
-use std::io;
+use std::{fmt, io};
 
 
 use incrementalmerkletree::{bridgetree::BridgeTree, Tree};
 use incrementalmerkletree::{bridgetree::BridgeTree, Tree};
 use log::debug;
 use log::debug;
@@ -196,6 +196,19 @@ impl PartialEq for BlockProposal {
     }
     }
 }
 }
 
 
+impl fmt::Display for BlockProposal {
+    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+        formatter.write_fmt(format_args!(
+            "BlockProposal {{ leader: {}, hash: {}, epoch: {}, slot: {}, txs: {} }}",
+            self.address.to_string(),
+            self.block.header.headerhash(),
+            self.block.header.epoch,
+            self.block.header.slot,
+            self.block.txs.len()
+        ))
+    }
+}
+
 impl net::Message for BlockProposal {
 impl net::Message for BlockProposal {
     fn name() -> &'static str {
     fn name() -> &'static str {
         "proposal"
         "proposal"

+ 2 - 1
src/consensus/proto/protocol_proposal.rs

@@ -59,7 +59,8 @@ impl ProtocolProposal {
                 }
                 }
             };
             };
 
 
-            info!("ProtocolProposal::handle_receive_proposal() recv: {:?}", proposal);
+            info!("ProtocolProposal::handle_receive_proposal(): recv: {}", proposal);
+            debug!("ProtocolProposal::handle_receive_proposal(): Full proposal: {:?}", proposal);
 
 
             let proposal_copy = (*proposal).clone();
             let proposal_copy = (*proposal).clone();
 
 

+ 1 - 1
src/consensus/proto/protocol_sync.rs

@@ -109,7 +109,7 @@ impl ProtocolSync {
             };
             };
 
 
             info!(
             info!(
-                "ProtocolSync::handle_receive_block() Received block {}",
+                "ProtocolSync::handle_receive_block(): Received block: {}",
                 info.header.headerhash()
                 info.header.headerhash()
             );
             );
 
 

+ 2 - 1
src/consensus/task/proposal.rs

@@ -88,7 +88,8 @@ pub async fn proposal_task(consensus_p2p: P2pPtr, sync_p2p: P2pPtr, state: Valid
             }
             }
         };
         };
 
 
-        info!("consensus: Node is the slot leader: Proposed block: {:?}", proposal);
+        info!("consensus: Node is the slot leader: Proposed block: {}", proposal);
+        debug!("consensus: Full proposal: {:?}", proposal);
         let vote = state.write().await.receive_proposal(&proposal);
         let vote = state.write().await.receive_proposal(&proposal);
         let vote = match vote {
         let vote = match vote {
             Ok(v) => {
             Ok(v) => {