mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 05:06:43 +00:00
eth/protocols/eth: disconnect if duplicate in same message
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
parent
49a7c24743
commit
1e57bbdf55
1 changed files with 8 additions and 19 deletions
|
|
@ -494,11 +494,8 @@ func handleTransactions(backend Backend, msg Decoder, peer *Peer) error {
|
||||||
if err := msg.Decode(&txs); err != nil {
|
if err := msg.Decode(&txs); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Deduplicate transactions within the message to avoid redundant processing
|
// Duplicate transactions are not allowed
|
||||||
var (
|
seen := make(map[common.Hash]struct{})
|
||||||
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 {
|
||||||
|
|
@ -506,15 +503,12 @@ func handleTransactions(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)
|
return fmt.Errorf("Transactions: multiple copies of the same hash %v", hash)
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
seen[hash] = struct{}{}
|
seen[hash] = struct{}{}
|
||||||
|
|
||||||
filtered = append(filtered, tx)
|
|
||||||
peer.markTransaction(hash)
|
peer.markTransaction(hash)
|
||||||
}
|
}
|
||||||
return backend.Handle(peer, &filtered)
|
return backend.Handle(peer, &txs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func handlePooledTransactions(backend Backend, msg Decoder, peer *Peer) error {
|
func handlePooledTransactions(backend Backend, msg Decoder, peer *Peer) error {
|
||||||
|
|
@ -528,10 +522,7 @@ 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
|
||||||
var (
|
seen := make(map[common.Hash]struct{})
|
||||||
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 {
|
||||||
|
|
@ -539,16 +530,14 @@ 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)
|
return fmt.Errorf("PooledTransactions: multiple copies of the same hash %v", hash)
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
seen[hash] = struct{}{}
|
seen[hash] = struct{}{}
|
||||||
|
|
||||||
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)
|
|
||||||
|
return backend.Handle(peer, &txs.PooledTransactionsResponse)
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleBlockRangeUpdate(backend Backend, msg Decoder, peer *Peer) error {
|
func handleBlockRangeUpdate(backend Backend, msg Decoder, peer *Peer) error {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue