diff --git a/les/api_backend.go b/les/api_backend.go index f07d631c79..d2afe9818b 100644 --- a/les/api_backend.go +++ b/les/api_backend.go @@ -116,7 +116,7 @@ func (b *LesApiBackend) Stats() (pending int, queued int) { } func (b *LesApiBackend) TxPoolContent() (map[common.Address]map[uint64][]*types.Transaction, map[common.Address]map[uint64][]*types.Transaction) { - return make(map[common.Address]map[uint64][]*types.Transaction), make(map[common.Address]map[uint64][]*types.Transaction) + return b.eth.txPool.Content() } func (b *LesApiBackend) Downloader() *downloader.Downloader { diff --git a/light/txpool.go b/light/txpool.go index 15a2c540b4..5b2e8d58dd 100644 --- a/light/txpool.go +++ b/light/txpool.go @@ -469,8 +469,8 @@ func (tp *TxPool) GetTransaction(hash common.Hash) *types.Transaction { // GetTransactions returns all currently processable transactions. // The returned slice may be modified by the caller. func (self *TxPool) GetTransactions() (txs types.Transactions) { - self.mu.Lock() - defer self.mu.Unlock() + self.mu.RLock() + defer self.mu.RUnlock() txs = make(types.Transactions, len(self.pending)) i := 0 @@ -481,6 +481,29 @@ func (self *TxPool) GetTransactions() (txs types.Transactions) { return txs } +// Content retrieves the data content of the transaction pool, returning all the +// pending as well as queued transactions, grouped by account and nonce. +func (self *TxPool) Content() (map[common.Address]map[uint64][]*types.Transaction, map[common.Address]map[uint64][]*types.Transaction) { + self.mu.RLock() + defer self.mu.RUnlock() + + // Retrieve all the pending transactions and sort by account and by nonce + pending := make(map[common.Address]map[uint64][]*types.Transaction) + for _, tx := range self.pending { + account, _ := tx.From() + + owned, ok := pending[account] + if !ok { + owned = make(map[uint64][]*types.Transaction) + pending[account] = owned + } + owned[tx.Nonce()] = append(owned[tx.Nonce()], tx) + } + // There are no queued transactions in a light pool, just return an empty map + queued := make(map[common.Address]map[uint64][]*types.Transaction) + return pending, queued +} + // RemoveTransactions removes all given transactions from the pool. func (self *TxPool) RemoveTransactions(txs types.Transactions) { self.mu.Lock()