Skip to content

Commit 73bbd26

Browse files
committed
fix: missing functions
1 parent 2d0e747 commit 73bbd26

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

p2p/conns.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,11 @@ func (c *Conns) AddTxs(txs []*types.Transaction) []common.Hash {
332332
return hashes
333333
}
334334

335+
// GetTx retrieves a transaction from the shared cache and updates LRU ordering.
336+
func (c *Conns) GetTx(hash common.Hash) (*types.Transaction, bool) {
337+
return c.txs.Get(hash)
338+
}
339+
335340
// PeekTxs retrieves multiple transactions from the shared cache without updating LRU ordering.
336341
// Uses a single read lock for better concurrency when LRU ordering is not needed.
337342
func (c *Conns) PeekTxs(hashes []common.Hash) []*types.Transaction {

p2p/datastructures/lru.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,19 @@ func (c *LRU[K, V]) Remove(key K) (V, bool) {
257257
return zero, false
258258
}
259259

260+
// Keys returns all keys in the cache in LRU order (most recent first).
261+
func (c *LRU[K, V]) Keys() []K {
262+
c.mu.RLock()
263+
defer c.mu.RUnlock()
264+
265+
keys := make([]K, 0, c.list.Len())
266+
for elem := c.list.Front(); elem != nil; elem = elem.Next() {
267+
e := elem.Value.(*entry[K, V])
268+
keys = append(keys, e.key)
269+
}
270+
return keys
271+
}
272+
260273
// AddBatch adds multiple key-value pairs to the cache.
261274
// Uses a single write lock for all additions, reducing lock contention
262275
// compared to calling Add in a loop. Keys and values must have the same length.

0 commit comments

Comments
 (0)