mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 05:06:43 +00:00
eth/protocols/eth: polish
This commit is contained in:
parent
2ecee9a735
commit
dae4a86dc9
1 changed files with 17 additions and 15 deletions
|
|
@ -495,25 +495,26 @@ func handleTransactions(backend Backend, msg Decoder, peer *Peer) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Deduplicate transactions within the message to avoid redundant processing
|
// Deduplicate transactions within the message to avoid redundant processing
|
||||||
seen := make(map[common.Hash]struct{})
|
var (
|
||||||
deduped := make([]*types.Transaction, 0, len(txs))
|
seen = make(map[common.Hash]struct{})
|
||||||
|
filtered = make(TransactionsPacket, 0, len(txs))
|
||||||
|
)
|
||||||
for i, tx := range txs {
|
for i, tx := range txs {
|
||||||
// Validate and mark the remote transaction
|
// Validate and mark the remote transaction
|
||||||
if tx == nil {
|
if tx == nil {
|
||||||
return fmt.Errorf("Transactions: transaction %d is nil", i)
|
return fmt.Errorf("transactions: transaction %d is nil", i)
|
||||||
}
|
}
|
||||||
hash := tx.Hash()
|
hash := tx.Hash()
|
||||||
if _, exists := seen[hash]; exists {
|
if _, exists := seen[hash]; exists {
|
||||||
|
log.Trace("Duplicated transaction", "hash", hash, "peer", peer.id)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
seen[hash] = struct{}{}
|
seen[hash] = struct{}{}
|
||||||
deduped = append(deduped, tx)
|
|
||||||
|
filtered = append(filtered, tx)
|
||||||
peer.markTransaction(hash)
|
peer.markTransaction(hash)
|
||||||
}
|
}
|
||||||
|
return backend.Handle(peer, &filtered)
|
||||||
dedupedPacket := TransactionsPacket(deduped)
|
|
||||||
return backend.Handle(peer, &dedupedPacket)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func handlePooledTransactions(backend Backend, msg Decoder, peer *Peer) error {
|
func handlePooledTransactions(backend Backend, msg Decoder, peer *Peer) error {
|
||||||
|
|
@ -527,9 +528,10 @@ func handlePooledTransactions(backend Backend, msg Decoder, peer *Peer) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Deduplicate transactions within the message to avoid redundant processing
|
// Deduplicate transactions within the message to avoid redundant processing
|
||||||
seen := make(map[common.Hash]struct{})
|
var (
|
||||||
deduped := make([]*types.Transaction, 0, len(txs.PooledTransactionsResponse))
|
seen = make(map[common.Hash]struct{})
|
||||||
|
filtered = make(PooledTransactionsResponse, 0, len(txs.PooledTransactionsResponse))
|
||||||
|
)
|
||||||
for i, tx := range txs.PooledTransactionsResponse {
|
for i, tx := range txs.PooledTransactionsResponse {
|
||||||
// Validate and mark the remote transaction
|
// Validate and mark the remote transaction
|
||||||
if tx == nil {
|
if tx == nil {
|
||||||
|
|
@ -537,16 +539,16 @@ func handlePooledTransactions(backend Backend, msg Decoder, peer *Peer) error {
|
||||||
}
|
}
|
||||||
hash := tx.Hash()
|
hash := tx.Hash()
|
||||||
if _, exists := seen[hash]; exists {
|
if _, exists := seen[hash]; exists {
|
||||||
|
log.Trace("Duplicated transaction", "hash", hash, "peer", peer.id)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
seen[hash] = struct{}{}
|
seen[hash] = struct{}{}
|
||||||
deduped = append(deduped, tx)
|
|
||||||
|
filtered = append(filtered, tx)
|
||||||
peer.markTransaction(hash)
|
peer.markTransaction(hash)
|
||||||
}
|
}
|
||||||
requestTracker.Fulfil(peer.id, peer.version, PooledTransactionsMsg, txs.RequestId)
|
requestTracker.Fulfil(peer.id, peer.version, PooledTransactionsMsg, txs.RequestId)
|
||||||
|
return backend.Handle(peer, &filtered)
|
||||||
dedupedPacket := PooledTransactionsResponse(deduped)
|
|
||||||
return backend.Handle(peer, &dedupedPacket)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleBlockRangeUpdate(backend Backend, msg Decoder, peer *Peer) error {
|
func handleBlockRangeUpdate(backend Backend, msg Decoder, peer *Peer) error {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue