Skip to content

Commit 48d708a

Browse files
authored
eth/filters: further optimize tx hash map in #32965 (#33108)
1 parent 12a389f commit 48d708a

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

eth/filters/filter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ type ReceiptWithTx struct {
563563
// In addition to returning receipts, it also returns the corresponding transactions.
564564
// This is because receipts only contain low-level data, while user-facing data
565565
// may require additional information from the Transaction.
566-
func filterReceipts(txHashes map[common.Hash]bool, ev core.ChainEvent) []*ReceiptWithTx {
566+
func filterReceipts(txHashes map[common.Hash]struct{}, ev core.ChainEvent) []*ReceiptWithTx {
567567
var ret []*ReceiptWithTx
568568

569569
receipts := ev.Receipts
@@ -585,7 +585,7 @@ func filterReceipts(txHashes map[common.Hash]bool, ev core.ChainEvent) []*Receip
585585
}
586586
} else {
587587
for i, receipt := range receipts {
588-
if txHashes[receipt.TxHash] {
588+
if _, ok := txHashes[receipt.TxHash]; ok {
589589
ret = append(ret, &ReceiptWithTx{
590590
Receipt: receipt,
591591
Transaction: txs[i],

eth/filters/filter_system.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,9 @@ type subscription struct {
185185
txs chan []*types.Transaction
186186
headers chan *types.Header
187187
receipts chan []*ReceiptWithTx
188-
txHashes map[common.Hash]bool // contains transaction hashes for transactionReceipts subscription filtering
189-
installed chan struct{} // closed when the filter is installed
190-
err chan error // closed when the filter is uninstalled
188+
txHashes map[common.Hash]struct{} // contains transaction hashes for transactionReceipts subscription filtering
189+
installed chan struct{} // closed when the filter is installed
190+
err chan error // closed when the filter is uninstalled
191191
}
192192

193193
// EventSystem creates subscriptions, processes events and broadcasts them to the
@@ -403,9 +403,9 @@ func (es *EventSystem) SubscribePendingTxs(txs chan []*types.Transaction) *Subsc
403403
// transactions when they are included in blocks. If txHashes is provided, only receipts
404404
// for those specific transaction hashes will be delivered.
405405
func (es *EventSystem) SubscribeTransactionReceipts(txHashes []common.Hash, receipts chan []*ReceiptWithTx) *Subscription {
406-
hashSet := make(map[common.Hash]bool)
406+
hashSet := make(map[common.Hash]struct{}, len(txHashes))
407407
for _, h := range txHashes {
408-
hashSet[h] = true
408+
hashSet[h] = struct{}{}
409409
}
410410
sub := &subscription{
411411
id: rpc.NewID(),

0 commit comments

Comments
 (0)