From df7fdbb2288375c62cbd962f984dc7e531bb0c71 Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Sat, 13 Apr 2024 12:50:22 +0100 Subject: [PATCH] Add getter to access MAX_SLOTS_CACHED from aggregator tracker --- .../beacon-node/src/network/processor/aggregatorTracker.ts | 5 +++++ .../test/unit/network/processor/aggregatorTracker.test.ts | 7 +++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/beacon-node/src/network/processor/aggregatorTracker.ts b/packages/beacon-node/src/network/processor/aggregatorTracker.ts index 912d8da4689b..b286a560c3e9 100644 --- a/packages/beacon-node/src/network/processor/aggregatorTracker.ts +++ b/packages/beacon-node/src/network/processor/aggregatorTracker.ts @@ -14,8 +14,13 @@ const MAX_SLOTS_CACHED = SLOTS_PER_EPOCH * 2; export class AggregatorTracker { private subnetAggregatorsBySlot = new MapDef>(() => new Set()); + get maxSlotsCached(): number { + return MAX_SLOTS_CACHED; + } + addAggregator(subnet: SubnetId, slot: Slot): void { this.subnetAggregatorsBySlot.getOrDefault(slot).add(subnet); + pruneSetToMax( this.subnetAggregatorsBySlot, MAX_SLOTS_CACHED, diff --git a/packages/beacon-node/test/unit/network/processor/aggregatorTracker.test.ts b/packages/beacon-node/test/unit/network/processor/aggregatorTracker.test.ts index 5cec237cb052..25fffa5651a3 100644 --- a/packages/beacon-node/test/unit/network/processor/aggregatorTracker.test.ts +++ b/packages/beacon-node/test/unit/network/processor/aggregatorTracker.test.ts @@ -1,5 +1,4 @@ import {describe, it, expect, beforeEach} from "vitest"; -import {SLOTS_PER_EPOCH} from "@lodestar/params"; import {AggregatorTracker} from "../../../../src/network/processor/aggregatorTracker.js"; describe("AggregatorTracker", () => { @@ -19,11 +18,11 @@ describe("AggregatorTracker", () => { }); it("should prune the oldest slots first when maximum cache size is reached", () => { - const maxSlots = SLOTS_PER_EPOCH * 2; + const {maxSlotsCached} = aggregatorTracker; const firstSlot = 0; - const lastSlot = firstSlot + maxSlots - 1; + const lastSlot = firstSlot + maxSlotsCached - 1; const subnet = 1; - const slots = Array.from({length: maxSlots}, (_, i) => firstSlot + i); + const slots = Array.from({length: maxSlotsCached}, (_, i) => firstSlot + i); // Slots should be inserted in random order for (let i = slots.length - 1; i > 0; i--) {