Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure light client update is in a single period #4029

Merged
merged 1 commit into from
May 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/lodestar/src/chain/lightClient/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ export class LightClientServer {
* ```
*
* 3. On new blocks use `block.body.sync_aggregate`, `block.parent_root` and `block.slot - 1`
*
* @param syncPeriod The sync period of the sync aggregate and signed block root
*/
private async onSyncAggregate(
syncPeriod: SyncPeriod,
Expand All @@ -445,6 +447,11 @@ export class LightClientServer {
}
}

const attestedPeriod = computeSyncPeriodAtSlot(attestedData.attestedHeader.slot);
if (syncPeriod !== attestedPeriod) {
throw new Error("attested data period different than signature period");
}

const headerUpdate: routes.lightclient.LightclientHeaderUpdate = {
attestedHeader: attestedData.attestedHeader,
syncAggregate,
Expand Down Expand Up @@ -506,7 +513,7 @@ export class LightClientServer {
// Only checkpoint candidates are stored, and not all headers are guaranteed to be available
const finalizedCheckpointRoot = attestedData.finalizedCheckpoint.root as Uint8Array;
const finalizedHeader = await this.getFinalizedHeader(finalizedCheckpointRoot);
if (finalizedHeader) {
if (finalizedHeader && computeSyncPeriodAtSlot(finalizedHeader.slot) == syncPeriod) {
// If finalizedHeader is available (should be most times) create a finalized update
newPartialUpdate = {...attestedData, finalizedHeader, syncAggregate};
} else {
Expand Down