Skip to content

Commit d8c3cb0

Browse files
committed
fix(p2p/libp2p/pubsub): duplicate block broadcasted from different senders for libp2p received blocks
Same issue affects transactions and snarks too, so needs to be fixed there as well.
1 parent 144afec commit d8c3cb0

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

node/src/transition_frontier/sync/transition_frontier_sync_effects.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,11 +322,6 @@ impl TransitionFrontierSyncAction {
322322
if !store.dispatch(TransitionFrontierSyncAction::BlocksNextApplyInit) {
323323
store.dispatch(TransitionFrontierSyncAction::BlocksSuccess);
324324
}
325-
326-
// TODO this should be handled by a callback
327-
store.dispatch(P2pNetworkPubsubAction::BroadcastValidatedMessage {
328-
message_id: p2p::BroadcastMessageId::BlockHash { hash: hash.clone() },
329-
});
330325
}
331326
TransitionFrontierSyncAction::BlocksSuccess => {}
332327
// Bootstrap/Catchup is practically complete at this point.

node/src/transition_frontier/transition_frontier_effects.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,18 @@ fn synced_effects<S: crate::Service>(
307307
best_tip: best_tip.block.clone(),
308308
});
309309
}
310-
// rebroadcast block if received from webrtc network, otherwise noop.
311-
store.dispatch(P2pNetworkPubsubAction::WebRtcRebroadcast {
312-
message: GossipNetMessageV2::NewState(best_tip.block().clone()),
313-
});
310+
// TODO this should be handled by a callback
311+
// If this get dispatched, we received block from libp2p.
312+
if !store.dispatch(P2pNetworkPubsubAction::BroadcastValidatedMessage {
313+
message_id: p2p::BroadcastMessageId::BlockHash {
314+
hash: best_tip.hash().clone(),
315+
},
316+
}) {
317+
// Otherwise block was received from WebRTC so inject it in libp2p.
318+
store.dispatch(P2pNetworkPubsubAction::WebRtcRebroadcast {
319+
message: GossipNetMessageV2::NewState(best_tip.block().clone()),
320+
});
321+
}
314322

315323
let best_tip_hash = best_tip.merkle_root_hash().clone();
316324
store.dispatch(ConsensusAction::Prune);

0 commit comments

Comments
 (0)