Skip to content

Commit

Permalink
chore: use flatMap()
Browse files Browse the repository at this point in the history
  • Loading branch information
twoeths committed Nov 28, 2023
1 parent 8b86487 commit dad4f29
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions packages/beacon-node/src/chain/shufflingCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export type ShufflingCacheOpts = {
* - skip computing shuffling when loading state bytes from disk
*/
export class ShufflingCache {
/** LRU cache implemented as an array, pruned every time we add an item */
/** LRU cache implemented as a map, pruned every time we add an item */
private readonly itemsByDecisionRootByEpoch: MapDef<Epoch, Map<RootHex, CacheItem>> = new MapDef(
() => new Map<RootHex, CacheItem>()
);
Expand Down Expand Up @@ -124,8 +124,7 @@ export class ShufflingCache {
*/
insertPromise(shufflingEpoch: Epoch, decisionRootHex: RootHex): void {
const promiseCount = Array.from(this.itemsByDecisionRootByEpoch.values())
.map((innerMap) => Array.from(innerMap.values()))
.flat()
.flatMap((innerMap) => Array.from(innerMap.values()))
.filter((item) => isPromiseCacheItem(item)).length;
if (promiseCount >= MAX_PROMISES) {
throw new Error(
Expand Down

0 comments on commit dad4f29

Please sign in to comment.