Skip to content

Commit

Permalink
Consistently use SubnetID for sync committee
Browse files Browse the repository at this point in the history
  • Loading branch information
nflaig committed Jan 8, 2025
1 parent 49cd798 commit e7c77e9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Signature, aggregateSignatures} from "@chainsafe/blst";
import {BitArray} from "@chainsafe/ssz";
import {SYNC_COMMITTEE_SIZE, SYNC_COMMITTEE_SUBNET_COUNT} from "@lodestar/params";
import {Root, Slot, SubcommitteeIndex, altair} from "@lodestar/types";
import {Root, Slot, SubcommitteeIndex, SubnetID, altair} from "@lodestar/types";
import {MapDef, toRootHex} from "@lodestar/utils";
import {IClock} from "../../util/clock.js";
import {InsertOutcome, OpPoolError, OpPoolErrorCode} from "./types.js";
Expand All @@ -26,7 +26,6 @@ type ContributionFast = Omit<altair.SyncCommitteeContribution, "aggregationBits"

/** Hex string of `contribution.beaconBlockRoot` */
type BlockRootHex = string;
type Subnet = SubcommitteeIndex;

/**
* Preaggregate SyncCommitteeMessage into SyncCommitteeContribution
Expand All @@ -40,8 +39,8 @@ export class SyncCommitteeMessagePool {
* */
private readonly contributionsByRootBySubnetBySlot = new MapDef<
Slot,
MapDef<Subnet, Map<BlockRootHex, ContributionFast>>
>(() => new MapDef<Subnet, Map<BlockRootHex, ContributionFast>>(() => new Map<BlockRootHex, ContributionFast>()));
MapDef<SubnetID, Map<BlockRootHex, ContributionFast>>
>(() => new MapDef<SubnetID, Map<BlockRootHex, ContributionFast>>(() => new Map<BlockRootHex, ContributionFast>()));
private lowestPermissibleSlot = 0;

constructor(
Expand All @@ -62,7 +61,7 @@ export class SyncCommitteeMessagePool {
}

// TODO: indexInSubcommittee: number should be indicesInSyncCommittee
add(subnet: Subnet, signature: altair.SyncCommitteeMessage, indexInSubcommittee: number): InsertOutcome {
add(subnet: SubnetID, signature: altair.SyncCommitteeMessage, indexInSubcommittee: number): InsertOutcome {
const {slot, beaconBlockRoot} = signature;
const rootHex = toRootHex(beaconBlockRoot);
const lowestPermissibleSlot = this.lowestPermissibleSlot;
Expand Down Expand Up @@ -146,7 +145,7 @@ function aggregateSignatureInto(
* Format `signature` into an efficient `contribution` to add more signatures in with aggregateSignatureInto()
*/
function signatureToAggregate(
subnet: Subnet,
subnet: SubnetID,
signature: altair.SyncCommitteeMessage,
indexInSubcommittee: number
): ContributionFast {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Signature, aggregateSignatures} from "@chainsafe/blst";
import {BitArray} from "@chainsafe/ssz";
import {SYNC_COMMITTEE_SIZE, SYNC_COMMITTEE_SUBNET_SIZE} from "@lodestar/params";
import {G2_POINT_AT_INFINITY} from "@lodestar/state-transition";
import {Root, Slot, altair, ssz} from "@lodestar/types";
import {Root, Slot, SubnetID, altair, ssz} from "@lodestar/types";
import {MapDef, toRootHex} from "@lodestar/utils";
import {InsertOutcome, OpPoolError, OpPoolErrorCode} from "./types.js";
import {pruneBySlot, signatureFromBytesNoCheck} from "./utils.js";
Expand Down Expand Up @@ -33,7 +33,6 @@ export type SyncContributionFast = {

/** Hex string of `contribution.beaconBlockRoot` */
type BlockRootHex = string;
type Subnet = number;

/**
* Cache SyncCommitteeContribution and seen ContributionAndProof.
Expand All @@ -43,8 +42,8 @@ type Subnet = number;
export class SyncContributionAndProofPool {
private readonly bestContributionBySubnetRootBySlot = new MapDef<
Slot,
MapDef<BlockRootHex, Map<Subnet, SyncContributionFast>>
>(() => new MapDef<BlockRootHex, Map<Subnet, SyncContributionFast>>(() => new Map<number, SyncContributionFast>()));
MapDef<BlockRootHex, Map<SubnetID, SyncContributionFast>>
>(() => new MapDef<BlockRootHex, Map<SubnetID, SyncContributionFast>>(() => new Map<number, SyncContributionFast>()));

private lowestPermissibleSlot = 0;

Expand Down
3 changes: 1 addition & 2 deletions packages/beacon-node/src/network/subnets/attnetsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ export enum SubnetSource {
longLived = "long_lived",
}

type Subnet = number;
// map of subnet to time to form stable mesh as seconds, null if not yet formed
type AggregatorDutyInfo = Map<Subnet, number | null>;
type AggregatorDutyInfo = Map<SubnetID, number | null>;

/**
* This value means node is not able to form stable mesh.
Expand Down

0 comments on commit e7c77e9

Please sign in to comment.