Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit 836c39a

Browse files
committed
chore: adding more logs
Signed-off-by: Simon Paitrault <[email protected]>
1 parent b1a3714 commit 836c39a

File tree

5 files changed

+44
-19
lines changed

5 files changed

+44
-19
lines changed

crates/topos-p2p/src/behaviour/gossip.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,15 @@ impl Behaviour {
3434
) -> Result<MessageId, P2PError> {
3535
match topic {
3636
TOPOS_GOSSIP | TOPOS_ECHO | TOPOS_READY => {
37-
let msg_id = self.gossipsub.publish(IdentTopic::new(topic), message)?;
37+
let topic = IdentTopic::new(topic);
38+
let topic_hash = topic.hash();
39+
let msg_id = self.gossipsub.publish(topic, message)?;
3840
trace!("Published on topos_gossip: {:?}", msg_id);
3941

42+
for p in self.gossipsub.mesh_peers(&topic_hash) {
43+
debug!("Sent gossipsub message({}) to {} peer", msg_id, p);
44+
}
45+
4046
Ok(msg_id)
4147
}
4248
_ => Err(P2PError::InvalidGossipTopic(topic)),
@@ -175,32 +181,35 @@ impl NetworkBehaviour for Behaviour {
175181
} => match topic.as_str() {
176182
TOPOS_GOSSIP => {
177183
return Poll::Ready(ToSwarm::GenerateEvent(ComposedEvent::Gossipsub(
178-
crate::event::GossipEvent::Message {
184+
Box::new(crate::event::GossipEvent::Message {
185+
propagated_by: propagation_source,
179186
topic: TOPOS_GOSSIP,
180187
message: data,
181188
source,
182189
id: message_id,
183-
},
190+
}),
184191
)))
185192
}
186193
TOPOS_ECHO => {
187194
return Poll::Ready(ToSwarm::GenerateEvent(ComposedEvent::Gossipsub(
188-
crate::event::GossipEvent::Message {
195+
Box::new(crate::event::GossipEvent::Message {
196+
propagated_by: propagation_source,
189197
topic: TOPOS_ECHO,
190198
message: data,
191199
source,
192200
id: message_id,
193-
},
201+
}),
194202
)))
195203
}
196204
TOPOS_READY => {
197205
return Poll::Ready(ToSwarm::GenerateEvent(ComposedEvent::Gossipsub(
198-
crate::event::GossipEvent::Message {
206+
Box::new(crate::event::GossipEvent::Message {
207+
propagated_by: propagation_source,
199208
topic: TOPOS_READY,
200209
message: data,
201210
source,
202211
id: message_id,
203-
},
212+
}),
204213
)))
205214
}
206215
_ => {}

crates/topos-p2p/src/event.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::behaviour::{grpc, HealthStatus};
77
pub enum GossipEvent {
88
/// A message has been received from a peer on one of the subscribed topics
99
Message {
10+
propagated_by: PeerId,
1011
source: Option<PeerId>,
1112
topic: &'static str,
1213
message: Vec<u8>,
@@ -18,7 +19,7 @@ pub enum GossipEvent {
1819
pub enum ComposedEvent {
1920
Kademlia(Box<kad::Event>),
2021
PeerInfo(Box<identify::Event>),
21-
Gossipsub(GossipEvent),
22+
Gossipsub(Box<GossipEvent>),
2223
Grpc(grpc::Event),
2324
Void,
2425
}
@@ -49,9 +50,11 @@ impl From<void::Void> for ComposedEvent {
4950

5051
/// Represents the events that the p2p layer can emit
5152
#[derive(Debug)]
53+
#[allow(clippy::large_enum_variant)]
5254
pub enum Event {
5355
/// An event emitted when a gossip message is received
5456
Gossip {
57+
propagated_by: PeerId,
5558
from: PeerId,
5659
data: Vec<u8>,
5760
id: String,

crates/topos-p2p/src/runtime/handle_event/gossipsub.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,46 @@ use crate::{constants, event::GossipEvent, Event, Runtime, TOPOS_ECHO, TOPOS_GOS
99
use super::{EventHandler, EventResult};
1010

1111
#[async_trait::async_trait]
12-
impl EventHandler<GossipEvent> for Runtime {
13-
async fn handle(&mut self, event: GossipEvent) -> EventResult {
12+
impl EventHandler<Box<GossipEvent>> for Runtime {
13+
async fn handle(&mut self, event: Box<GossipEvent>) -> EventResult {
1414
if let GossipEvent::Message {
15+
propagated_by,
1516
source: Some(source),
1617
message,
1718
topic,
1819
id,
19-
} = event
20+
} = *event
2021
{
2122
if self.event_sender.capacity() < *constants::CAPACITY_EVENT_STREAM_BUFFER {
2223
P2P_EVENT_STREAM_CAPACITY_TOTAL.inc();
2324
}
2425

25-
debug!("Received message from {:?} on topic {:?}", source, topic);
26+
debug!(
27+
"Received message({id}) from source {:?} on topic {:?} propagated by {propagated_by}",
28+
source, topic
29+
);
2630

2731
match topic {
2832
TOPOS_GOSSIP => P2P_MESSAGE_RECEIVED_ON_GOSSIP_TOTAL.inc(),
2933
TOPOS_ECHO => P2P_MESSAGE_RECEIVED_ON_ECHO_TOTAL.inc(),
3034
TOPOS_READY => P2P_MESSAGE_RECEIVED_ON_READY_TOTAL.inc(),
3135
_ => {
32-
error!("Received message on unknown topic {:?}", topic);
36+
error!("Received message({id}) on unknown topic {:?}", topic);
3337
return Ok(());
3438
}
3539
}
3640

3741
if let Err(e) = self
3842
.event_sender
3943
.send(Event::Gossip {
44+
propagated_by,
4045
from: source,
4146
data: message,
4247
id: id.to_string(),
4348
})
4449
.await
4550
{
46-
error!("Failed to send gossip event to runtime: {:?}", e);
51+
error!("Failed to send gossip event({id}) to runtime: {:?}", e);
4752
}
4853
}
4954

crates/topos-tce/src/app_context/network.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ impl AppContext {
2222
&evt
2323
);
2424

25-
if let NetEvent::Gossip { data, from, id } = evt {
25+
if let NetEvent::Gossip {
26+
data,
27+
propagated_by: received_from,
28+
from,
29+
id,
30+
} = evt
31+
{
2632
if let Ok(DoubleEchoRequest {
2733
request: Some(double_echo_request),
2834
}) = DoubleEchoRequest::decode(&data[..])
@@ -39,10 +45,8 @@ impl AppContext {
3945
}
4046
info!(
4147
message_id = id,
42-
"Received certificate {} from GossipSub message({}) from {}",
48+
"Received certificate {} from GossipSub message({id}) from {from} | propagated by {received_from}",
4349
cert.id,
44-
id,
45-
from
4650
);
4751

4852
match self.validator_store.insert_pending_certificate(&cert).await {
@@ -199,7 +203,7 @@ impl AppContext {
199203
if let (Ok(certificate_id), Ok(validator_id)) =
200204
(certificate_id, validator_id)
201205
{
202-
trace!(
206+
debug!(
203207
message_id = id,
204208
"Received Ready message({id}), certificate_id: \
205209
{certificate_id}, validator_id: {validator_id} from: {from}",

crates/topos-tce/src/tests/network.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ async fn handle_gossip(
3737
};
3838
context
3939
.on_net_event(topos_p2p::Event::Gossip {
40+
propagated_by: PeerId::random(),
4041
from: PeerId::random(),
4142
data: msg.encode_to_vec(),
4243
id: "0".to_string(),
@@ -67,6 +68,7 @@ async fn handle_echo(
6768
};
6869
context
6970
.on_net_event(topos_p2p::Event::Gossip {
71+
propagated_by: PeerId::random(),
7072
from: PeerId::random(),
7173
data: msg.encode_to_vec(),
7274
id: "0".to_string(),
@@ -97,6 +99,7 @@ async fn handle_ready(
9799
};
98100
context
99101
.on_net_event(topos_p2p::Event::Gossip {
102+
propagated_by: PeerId::random(),
100103
from: PeerId::random(),
101104
data: msg.encode_to_vec(),
102105
id: "0".to_string(),
@@ -131,6 +134,7 @@ async fn handle_already_delivered(
131134

132135
context
133136
.on_net_event(topos_p2p::Event::Gossip {
137+
propagated_by: PeerId::random(),
134138
from: PeerId::random(),
135139
data: msg.encode_to_vec(),
136140
id: "0".to_string(),

0 commit comments

Comments
 (0)