Skip to content

Commit 4944fdd

Browse files
karalabekielbarry
authored andcommitted
internal/ethapi: reduce pendingTransactions to O(txs+accs) from O(txs*accs)
1 parent 78009b5 commit 4944fdd

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

internal/ethapi/api.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,22 +1301,27 @@ func (s *PublicTransactionPoolAPI) SignTransaction(ctx context.Context, args Sen
13011301
return &SignTransactionResult{data, tx}, nil
13021302
}
13031303

1304-
// PendingTransactions returns the transactions that are in the transaction pool and have a from address that is one of
1305-
// the accounts this node manages.
1304+
// PendingTransactions returns the transactions that are in the transaction pool
1305+
// and have a from address that is one of the accounts this node manages.
13061306
func (s *PublicTransactionPoolAPI) PendingTransactions() ([]*RPCTransaction, error) {
13071307
pending, err := s.b.GetPoolTransactions()
13081308
if err != nil {
13091309
return nil, err
13101310
}
1311-
1311+
accounts := make(map[common.Address]struct{})
1312+
for _, wallet := range s.b.AccountManager().Wallets() {
1313+
for _, account := range wallet.Accounts() {
1314+
accounts[account.Address] = struct{}{}
1315+
}
1316+
}
13121317
transactions := make([]*RPCTransaction, 0, len(pending))
13131318
for _, tx := range pending {
13141319
var signer types.Signer = types.HomesteadSigner{}
13151320
if tx.Protected() {
13161321
signer = types.NewEIP155Signer(tx.ChainId())
13171322
}
13181323
from, _ := types.Sender(signer, tx)
1319-
if _, err := s.b.AccountManager().Find(accounts.Account{Address: from}); err == nil {
1324+
if _, exists := accounts[from]; exists {
13201325
transactions = append(transactions, newRPCPendingTransaction(tx))
13211326
}
13221327
}

0 commit comments

Comments
 (0)