fn broadcast_single_peer<V>(peer: PeerNetworkId, smp: &mut SharedMempool<V>)
where
    V: TransactionValidation,
{
    let peer_manager = &smp.peer_manager;
    let timeline_id = if peer_manager.is_picked_peer(peer) {
        let state = peer_manager.get_peer_state(peer);
        if state.is_alive {
            state.timeline_id
        } else {
            return;
        }
    } else {
        return;
    };

    let (transactions, new_timeline_id) = smp
        .mempool
        .lock()
        .expect("[shared mempool] failed to acquire mempool lock")
        .read_timeline(timeline_id, smp.config.shared_mempool_batch_size);

    if transactions.is_empty() {
        return;
    }

    let mut network_sender = smp
        .network_senders
        .get_mut(&peer.network_id())
        .expect("[shared mempool] missing network sender");

    let request_id = create_request_id(timeline_id, new_timeline_id);
    let txns_ct = transactions.len();
    if let Err(e) = send_mempool_sync_msg(
        MempoolSyncMsg::BroadcastTransactionsRequest {
            request_id,
            transactions,
        },
        peer.peer_id(),
        &mut network_sender,
    ) {
        error!(
            "[shared mempool] error broadcasting transactions to peer {:?}: {}",
            peer, e
        );
    } else {
        counters::SHARED_MEMPOOL_TRANSACTION_BROADCAST.inc_by(txns_ct as i64);
        peer_manager.update_peer_broadcast(peer, new_timeline_id);
        notify_subscribers(SharedMempoolNotification::Broadcast, &smp.subscribers);
    }
}
/// broadcasts txns to `peer` if alive
broadcasts txns to `peer` if alive
broadcasts txns to ` peer ` if alive
fn broadcast_single_peer<V>(peer: PeerNetworkId, smp: &mut SharedMempool<V>)
where
    V: TransactionValidation,
{
    let peer_manager = &smp.peer_manager;
    let timeline_id = if peer_manager.is_picked_peer(peer) {
        let state = peer_manager.get_peer_state(peer);
        if state.is_alive {
            state.timeline_id
        } else {
            return;
        }
    } else {
        return;
    };
    let (transactions, new_timeline_id) = smp
        .mempool
        .lock()
        .expect("[shared mempool] failed to acquire mempool lock")
        .read_timeline(timeline_id, smp.config.shared_mempool_batch_size);
    if transactions.is_empty() {
        return;
    }
    let mut network_sender = smp
        .network_senders
        .get_mut(&peer.network_id())
        .expect("[shared mempool] missing network sender");
    let request_id = create_request_id(timeline_id, new_timeline_id);
    let txns_ct = transactions.len();
    if let Err(e) = send_mempool_sync_msg(
        MempoolSyncMsg::BroadcastTransactionsRequest {
            request_id,
            transactions,
        },
        peer.peer_id(),
        &mut network_sender,
    ) {
        error!(
            "[shared mempool] error broadcasting transactions to peer {:?}: {}",
            peer, e
        );
    } else {
        counters::SHARED_MEMPOOL_TRANSACTION_BROADCAST.inc_by(txns_ct as i64);
        peer_manager.update_peer_broadcast(peer, new_timeline_id);
        notify_subscribers(SharedMempoolNotification::Broadcast, &smp.subscribers);
    }
}
fn broadcast_single_peer < V > ( peer : PeerNetworkId , smp : & mut SharedMempool < V > ) where V : TransactionValidation , { let peer_manager = & smp . peer_manager ; let timeline_id = if peer_manager . is_picked_peer ( peer ) { let state = peer_manager . get_peer_state ( peer ) ; if state . is_alive { state . timeline_id } else { return ; } } else { return ; } ; let ( transactions , new_timeline_id ) = smp . mempool . lock ( ) . expect ( " " ) . read_timeline ( timeline_id , smp . config . shared_mempool_batch_size ) ; if transactions . is_empty ( ) { return ; } let mut network_sender = smp . network_senders . get_mut ( & peer . network_id ( ) ) . expect ( " " ) ; let request_id = create_request_id ( timeline_id , new_timeline_id ) ; let txns_ct = transactions . len ( ) ; if let Err ( e ) = send_mempool_sync_msg ( MempoolSyncMsg :: BroadcastTransactionsRequest { request_id , transactions , } , peer . peer_id ( ) , & mut network_sender , ) { error ! ( " " peer e ) ; } else { counters :: SHARED_MEMPOOL_TRANSACTION_BROADCAST . inc_by ( txns_ct as i64 ) ; peer_manager . update_peer_broadcast ( peer , new_timeline_id ) ; notify_subscribers ( SharedMempoolNotification :: Broadcast , & smp . subscribers ) ; } }
broadcasts txns to `peer` if alive
broadcasts txns to ` peer ` if alive
peer
PeerNetworkId
smp
&mut SharedMempool<V>
peer
PeerNetworkId
smp
&mut SharedMempool<V>