diff options
author | Péter Szilágyi <peterke@gmail.com> | 2018-06-12 19:07:21 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-12 19:07:21 +0800 |
commit | 85cd64df0e3331e46f41ec86a647f1b8ff306eda (patch) | |
tree | c8cd3db47a3144063b02f98c6d064bb4de901cf4 | |
parent | 9608ccf106584c73e91258518eb9d09ad39cc8ae (diff) | |
parent | 90829a04bfe7a1c73e6fe01699b5bbae31e3c3b2 (diff) | |
download | dexon-85cd64df0e3331e46f41ec86a647f1b8ff306eda.tar.gz dexon-85cd64df0e3331e46f41ec86a647f1b8ff306eda.tar.zst dexon-85cd64df0e3331e46f41ec86a647f1b8ff306eda.zip |
Merge pull request #16958 from karalabe/pending-account-fast
internal/ethapi: reduce pendingTransactions to O(txs+accs) from O(txs*accs)
-rw-r--r-- | internal/ethapi/api.go | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index f95388d65..f5753da22 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1301,14 +1301,19 @@ func (s *PublicTransactionPoolAPI) SignTransaction(ctx context.Context, args Sen return &SignTransactionResult{data, tx}, nil } -// PendingTransactions returns the transactions that are in the transaction pool and have a from address that is one of -// the accounts this node manages. +// PendingTransactions returns the transactions that are in the transaction pool +// and have a from address that is one of the accounts this node manages. func (s *PublicTransactionPoolAPI) PendingTransactions() ([]*RPCTransaction, error) { pending, err := s.b.GetPoolTransactions() if err != nil { return nil, err } - + accounts := make(map[common.Address]struct{}) + for _, wallet := range s.b.AccountManager().Wallets() { + for _, account := range wallet.Accounts() { + accounts[account.Address] = struct{}{} + } + } transactions := make([]*RPCTransaction, 0, len(pending)) for _, tx := range pending { var signer types.Signer = types.HomesteadSigner{} @@ -1316,7 +1321,7 @@ func (s *PublicTransactionPoolAPI) PendingTransactions() ([]*RPCTransaction, err signer = types.NewEIP155Signer(tx.ChainId()) } from, _ := types.Sender(signer, tx) - if _, err := s.b.AccountManager().Find(accounts.Account{Address: from}); err == nil { + if _, exists := accounts[from]; exists { transactions = append(transactions, newRPCPendingTransaction(tx)) } } |