mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-11 10:36:37 +00:00
eth/protocols/eth: reject message containing duplicated txs and drop peer (#32728)
Drop peer if sending the same transaction multiple times in a single message. Fixes https://github.com/ethereum/go-ethereum/issues/32724 --------- Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com> Co-authored-by: Gary Rong <garyrong0905@gmail.com> Co-authored-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
parent
3cfc33477b
commit
40505a9bc0
1 changed files with 16 additions and 2 deletions
|
|
@ -494,12 +494,19 @@ 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
|
||||||
}
|
}
|
||||||
|
// Duplicate transactions are not allowed
|
||||||
|
seen := make(map[common.Hash]struct{})
|
||||||
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)
|
||||||
}
|
}
|
||||||
peer.markTransaction(tx.Hash())
|
hash := tx.Hash()
|
||||||
|
if _, exists := seen[hash]; exists {
|
||||||
|
return fmt.Errorf("Transactions: multiple copies of the same hash %v", hash)
|
||||||
|
}
|
||||||
|
seen[hash] = struct{}{}
|
||||||
|
peer.markTransaction(hash)
|
||||||
}
|
}
|
||||||
return backend.Handle(peer, &txs)
|
return backend.Handle(peer, &txs)
|
||||||
}
|
}
|
||||||
|
|
@ -514,12 +521,19 @@ func handlePooledTransactions(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
|
||||||
}
|
}
|
||||||
|
// Duplicate transactions are not allowed
|
||||||
|
seen := make(map[common.Hash]struct{})
|
||||||
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 {
|
||||||
return fmt.Errorf("PooledTransactions: transaction %d is nil", i)
|
return fmt.Errorf("PooledTransactions: transaction %d is nil", i)
|
||||||
}
|
}
|
||||||
peer.markTransaction(tx.Hash())
|
hash := tx.Hash()
|
||||||
|
if _, exists := seen[hash]; exists {
|
||||||
|
return fmt.Errorf("PooledTransactions: multiple copies of the same hash %v", hash)
|
||||||
|
}
|
||||||
|
seen[hash] = struct{}{}
|
||||||
|
peer.markTransaction(hash)
|
||||||
}
|
}
|
||||||
requestTracker.Fulfil(peer.id, peer.version, PooledTransactionsMsg, txs.RequestId)
|
requestTracker.Fulfil(peer.id, peer.version, PooledTransactionsMsg, txs.RequestId)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue