Skip to content

Commit

Permalink
perf: reuse the serialized tx when re-broadcasting
Browse files Browse the repository at this point in the history
Signed-off-by: ljedrz <[email protected]>
  • Loading branch information
ljedrz committed Aug 26, 2022
1 parent 248d909 commit 5e11fd2
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions snarkos/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,20 @@ pub(crate) async fn handle_peer<N: Network>(
},
Message::TransactionBroadcast(transaction_bytes) => {
// Perform deferred deserialization.
let transaction = transaction_bytes.deserialize().await?;
let transaction = transaction_bytes.clone().deserialize().await?;

let transaction_id = transaction.id();

// Check that the transaction doesn't already exist in the ledger or mempool.
if let Ok(true) = ledger.ledger().read().contains_transaction_id(&transaction_id) {
// Attempt to insert the transaction into the mempool.
match ledger.add_to_memory_pool(transaction.clone()) {
match ledger.add_to_memory_pool(transaction) {
Ok(_) => {
// Broadcast transaction to all peers except the sender.
let peers = ledger.peers().read().clone();
tokio::spawn(async move {
for (_, sender) in peers.iter().filter(|(ip, _)| *ip != &peer.ip) {
let _ = sender.send(Message::<N>::TransactionBroadcast(Data::Object(transaction.clone()))).await;
let _ = sender.send(Message::<N>::TransactionBroadcast(transaction_bytes.clone())).await;
}
});

Expand Down

0 comments on commit 5e11fd2

Please sign in to comment.