eth/filters: further optimize tx hash map in #32965 (#33108)

This commit is contained in:
Marcel 2025-11-13 14:48:26 +08:00 committed by GitHub
parent 12a389f065
commit 48d708a194
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 7 deletions

View file

@ -563,7 +563,7 @@ type ReceiptWithTx struct {
// In addition to returning receipts, it also returns the corresponding transactions. // In addition to returning receipts, it also returns the corresponding transactions.
// This is because receipts only contain low-level data, while user-facing data // This is because receipts only contain low-level data, while user-facing data
// may require additional information from the Transaction. // may require additional information from the Transaction.
func filterReceipts(txHashes map[common.Hash]bool, ev core.ChainEvent) []*ReceiptWithTx { func filterReceipts(txHashes map[common.Hash]struct{}, ev core.ChainEvent) []*ReceiptWithTx {
var ret []*ReceiptWithTx var ret []*ReceiptWithTx
receipts := ev.Receipts receipts := ev.Receipts
@ -585,7 +585,7 @@ func filterReceipts(txHashes map[common.Hash]bool, ev core.ChainEvent) []*Receip
} }
} else { } else {
for i, receipt := range receipts { for i, receipt := range receipts {
if txHashes[receipt.TxHash] { if _, ok := txHashes[receipt.TxHash]; ok {
ret = append(ret, &ReceiptWithTx{ ret = append(ret, &ReceiptWithTx{
Receipt: receipt, Receipt: receipt,
Transaction: txs[i], Transaction: txs[i],

View file

@ -185,9 +185,9 @@ type subscription struct {
txs chan []*types.Transaction txs chan []*types.Transaction
headers chan *types.Header headers chan *types.Header
receipts chan []*ReceiptWithTx receipts chan []*ReceiptWithTx
txHashes map[common.Hash]bool // contains transaction hashes for transactionReceipts subscription filtering txHashes map[common.Hash]struct{} // contains transaction hashes for transactionReceipts subscription filtering
installed chan struct{} // closed when the filter is installed installed chan struct{} // closed when the filter is installed
err chan error // closed when the filter is uninstalled err chan error // closed when the filter is uninstalled
} }
// EventSystem creates subscriptions, processes events and broadcasts them to the // EventSystem creates subscriptions, processes events and broadcasts them to the
@ -403,9 +403,9 @@ func (es *EventSystem) SubscribePendingTxs(txs chan []*types.Transaction) *Subsc
// transactions when they are included in blocks. If txHashes is provided, only receipts // transactions when they are included in blocks. If txHashes is provided, only receipts
// for those specific transaction hashes will be delivered. // for those specific transaction hashes will be delivered.
func (es *EventSystem) SubscribeTransactionReceipts(txHashes []common.Hash, receipts chan []*ReceiptWithTx) *Subscription { func (es *EventSystem) SubscribeTransactionReceipts(txHashes []common.Hash, receipts chan []*ReceiptWithTx) *Subscription {
hashSet := make(map[common.Hash]bool) hashSet := make(map[common.Hash]struct{}, len(txHashes))
for _, h := range txHashes { for _, h := range txHashes {
hashSet[h] = true hashSet[h] = struct{}{}
} }
sub := &subscription{ sub := &subscription{
id: rpc.NewID(), id: rpc.NewID(),