Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions eth/protocols/eth/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,14 +494,26 @@ func handleTransactions(backend Backend, msg Decoder, peer *Peer) error {
if err := msg.Decode(&txs); err != nil {
return err
}
// Deduplicate transactions within the message to avoid redundant processing
seen := make(map[common.Hash]struct{})
deduped := make([]*types.Transaction, 0, len(txs))

for i, tx := range txs {
// Validate and mark the remote transaction
if tx == nil {
return fmt.Errorf("Transactions: transaction %d is nil", i)
}
peer.markTransaction(tx.Hash())
hash := tx.Hash()
if _, exists := seen[hash]; exists {
continue
}
seen[hash] = struct{}{}
deduped = append(deduped, tx)
peer.markTransaction(hash)
}
return backend.Handle(peer, &txs)

dedupedPacket := TransactionsPacket(deduped)
return backend.Handle(peer, &dedupedPacket)
}

func handlePooledTransactions(backend Backend, msg Decoder, peer *Peer) error {
Expand All @@ -514,16 +526,27 @@ func handlePooledTransactions(backend Backend, msg Decoder, peer *Peer) error {
if err := msg.Decode(&txs); err != nil {
return err
}
// Deduplicate transactions within the message to avoid redundant processing
seen := make(map[common.Hash]struct{})
deduped := make([]*types.Transaction, 0, len(txs.PooledTransactionsResponse))

for i, tx := range txs.PooledTransactionsResponse {
// Validate and mark the remote transaction
if tx == nil {
return fmt.Errorf("PooledTransactions: transaction %d is nil", i)
}
peer.markTransaction(tx.Hash())
hash := tx.Hash()
if _, exists := seen[hash]; exists {
continue
}
seen[hash] = struct{}{}
deduped = append(deduped, tx)
peer.markTransaction(hash)
}
requestTracker.Fulfil(peer.id, peer.version, PooledTransactionsMsg, txs.RequestId)

return backend.Handle(peer, &txs.PooledTransactionsResponse)
dedupedPacket := PooledTransactionsResponse(deduped)
return backend.Handle(peer, &dedupedPacket)
}

func handleBlockRangeUpdate(backend Backend, msg Decoder, peer *Peer) error {
Expand Down