Skip to content

Commit

Permalink
Add getter to access MAX_SLOTS_CACHED from aggregator tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
nflaig committed Apr 13, 2024
1 parent a0a9c6d commit df7fdbb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ const MAX_SLOTS_CACHED = SLOTS_PER_EPOCH * 2;
export class AggregatorTracker {
private subnetAggregatorsBySlot = new MapDef<Slot, Set<SubnetId>>(() => 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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand All @@ -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--) {
Expand Down

0 comments on commit df7fdbb

Please sign in to comment.