Skip to content

Commit

Permalink
Lint and add todos
Browse files Browse the repository at this point in the history
  • Loading branch information
ensi321 committed Jan 24, 2025
1 parent 54901a4 commit 48200e2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
1 change: 1 addition & 0 deletions packages/beacon-node/src/api/impl/validator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,7 @@ export function getValidatorApi(
notWhileSyncing();

// TODO FOCIL: Add error handling
// TODO FOCIL: Figure out if we need to add IL to opPool here

await validateApiInclusionList(chain, signedInclusionList);

Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/src/network/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ export class Network implements INetwork {
{type: GossipType.inclusion_list, fork},
inclusionList,
{ignoreDuplicatePublishError: true} // TODO FOCIL: Double check if we want to ignore duplicate error
)
);
}

private async publishGossip<K extends GossipType>(
Expand Down
19 changes: 9 additions & 10 deletions packages/validator/src/services/inclusionList.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import {ApiClient} from "@lodestar/api";
import {InclusionListDutyList} from "@lodestar/api/lib/beacon/routes/validator.js";
import {ChainForkConfig} from "@lodestar/config";
import {Slot, focil } from "@lodestar/types";
import {Slot, focil} from "@lodestar/types";
import {sleep} from "@lodestar/utils";
import {Metrics} from "../metrics.js";
import {IClock, LoggerVc} from "../util/index.js";
import {ChainHeaderTracker} from "./chainHeaderTracker.js";
import {ValidatorEventEmitter} from "./emitter.js";
import {InclusionListDutiesService} from "./inclusionListDuties.js";
import {SyncingStatusTracker} from "./syncingStatusTracker.js";
import {ValidatorStore} from "./validatorStore.js";
import { InclusionListDutiesService } from "./inclusionListDuties.js";
import { InclusionListDutyList } from "@lodestar/api/lib/beacon/routes/validator.js";

/**
* Service that sets up and handles validator inclusion list duties.
Expand All @@ -24,15 +24,15 @@ export class InclusionListService {
private readonly validatorStore: ValidatorStore,
private readonly emitter: ValidatorEventEmitter,
chainHeadTracker: ChainHeaderTracker,
syncingStatusTracker: SyncingStatusTracker,
syncingStatusTracker: SyncingStatusTracker
) {
this.dutiesService = new InclusionListDutiesService(
logger,
api,
clock,
validatorStore,
chainHeadTracker,
syncingStatusTracker,
syncingStatusTracker
);

// At most every slot, check existing duties from InclusionListDutiesService and run tasks
Expand All @@ -56,11 +56,10 @@ export class InclusionListService {
const inclusionListNoValidatorIndex = await this.produceInclusionList(slot);

await this.signAndPublishInclusionList(inclusionListNoValidatorIndex, duties);

};

// Note: The inclusion list returned here is a "blueprint" ie. every field
// is filled except validator index = 0. Need to replace validator index to
// is filled except validator index = 0. Need to replace validator index to
// form a valid InclusionList
private async produceInclusionList(slot: Slot): Promise<focil.InclusionList> {
// Produce one IL per slot
Expand All @@ -74,7 +73,7 @@ export class InclusionListService {

private async signAndPublishInclusionList(
inclusionListNoValidatorIndex: focil.InclusionList,
duties: InclusionListDutyList,
duties: InclusionListDutyList
) {
const signedInclusionLists: focil.SignedInclusionList[] = [];

Expand All @@ -87,7 +86,7 @@ export class InclusionListService {
this.logger.error("Error signing inclusiont list");
}
})
)
);

// Publish ILs right away
for (const signedInclusionList of signedInclusionLists) {
Expand All @@ -99,4 +98,4 @@ export class InclusionListService {
}
}
}
}
}
10 changes: 8 additions & 2 deletions packages/validator/src/services/inclusionListDuties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {SyncingStatusTracker} from "./syncingStatusTracker.js";
import {ValidatorStore} from "./validatorStore.js";

/** Only retain `HISTORICAL_DUTIES_EPOCHS` duties prior to the current epoch. */
// TODO FOCIL: Do we need 2 epochs like attestations?
const HISTORICAL_DUTIES_EPOCHS = 2;

type InclusionListDuty = routes.validator.InclusionListDuty;
Expand All @@ -35,7 +36,7 @@ export class InclusionListDutiesService {
private clock: IClock,
private readonly validatorStore: ValidatorStore,
chainHeadTracker: ChainHeaderTracker,
syncingStatusTracker: SyncingStatusTracker,
syncingStatusTracker: SyncingStatusTracker
) {
// Running this task every epoch is safe since a re-org of two epochs is very unlikely
// TODO: If the re-org event is reliable consider re-running then
Expand Down Expand Up @@ -270,7 +271,12 @@ export class InclusionListDutiesService {
priorDependentRoot: currentEpochDependentRoot,
newDependentRoot: previousDutyDependentRoot,
});
await this.handleInclusionListDutiesReorg(currentEpoch, slot, currentEpochDependentRoot, previousDutyDependentRoot);
await this.handleInclusionListDutiesReorg(
currentEpoch,
slot,
currentEpochDependentRoot,
previousDutyDependentRoot
);
}
};

Expand Down
10 changes: 6 additions & 4 deletions packages/validator/src/services/validatorStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -704,15 +704,15 @@ export class ValidatorStore {
validatorIndex: duty.validatorIndex,
inclusionListCommitteeRoot,
transactions,
}
};

const domain = this.config.getDomain(signingSlot, DOMAIN_INCLUSION_LIST_COMMITTEE);
const signingRoot = computeSigningRoot(ssz.focil.InclusionList, inclusionList, domain);

const signableMessage: SignableMessage = {
type: SignableMessageType.INCLUSION_LIST,
data: inclusionList,
}
};

return {
message: inclusionList,
Expand Down Expand Up @@ -850,13 +850,15 @@ export class ValidatorStore {
}

/** Prevent signing bad data sent by the Beacon node */
private validateInclusionListDuty(duty: routes.validator.InclusionListDuty, inclusionList: focil.InclusionList): void {
private validateInclusionListDuty(
duty: routes.validator.InclusionListDuty,
inclusionList: focil.InclusionList
): void {
if (duty.slot !== inclusionList.slot) {
throw Error(`Inconsistent duties during signing: duty.slot ${duty.slot} != il.slot ${inclusionList.slot}`);
}

// TODO FOCIL: Maybe check if validator index in inclusionListCommitteeRoot?

}

private assertDoppelgangerSafe(pubKey: PubkeyHex | BLSPubkey): void {
Expand Down

0 comments on commit 48200e2

Please sign in to comment.