feat: Update to capella fork

This commit is contained in:
Derrick Hammer 2023-06-18 03:42:56 -04:00
parent f5099a4546
commit 40d652fa22
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
4 changed files with 579 additions and 554 deletions

View File

@ -1,5 +1,4 @@
import {
Bytes32,
ClientConfig,
ExecutionInfo,
LightClientUpdate,
@ -22,17 +21,20 @@ import {
assertValidSignedHeader,
} from "@lodestar/light-client/validation";
import { SyncCommitteeFast } from "@lodestar/light-client";
import bls from "@chainsafe/bls/switchable";
import bls, { init } from "@chainsafe/bls/switchable";
import { PublicKey } from "@chainsafe/bls/types.js";
import { fromHexString, toHexString } from "@chainsafe/ssz";
import { AsyncOrSync } from "ts-essentials";
import * as altair from "@lodestar/types/altair";
import { fromHexString } from "@chainsafe/ssz";
import * as phase0 from "@lodestar/types/phase0";
import * as bellatrix from "@lodestar/types/bellatrix";
import { init } from "@chainsafe/bls/switchable";
import * as capella from "@lodestar/types/capella";
import NodeCache from "node-cache";
import { Mutex } from "async-mutex";
import { VerifyingProvider } from "./rpc/index.js";
import { ChainForkConfig } from "@lodestar/config";
import { allForks } from "@lodestar/types";
import {
BLOCK_BODY_EXECUTION_PAYLOAD_DEPTH as EXECUTION_PAYLOAD_DEPTH,
BLOCK_BODY_EXECUTION_PAYLOAD_INDEX as EXECUTION_PAYLOAD_INDEX,
} from "@lodestar/params";
export default class Client {
latestCommittee?: Uint8Array[];
@ -163,20 +165,21 @@ export default class Client {
}
optimisticUpdateFromJSON(update: any): OptimisticUpdate {
return altair.ssz.LightClientOptimisticUpdate.fromJson(update);
return capella.ssz.LightClientOptimisticUpdate.fromJson(update);
}
async optimisticUpdateVerify(
committee: Uint8Array[],
update: OptimisticUpdate
): Promise<VerifyWithReason> {
try {
const { attestedHeader: header, syncAggregate } = update;
const headerBlockRoot = phase0.ssz.BeaconBlockHeader.hashTreeRoot(
header.beacon
);
const committeeFast = this.deserializeSyncCommittee(committee);
try {
await assertValidSignedHeader(
assertValidSignedHeader(
this.config.chainConfig,
committeeFast,
syncAggregate,
@ -192,7 +195,33 @@ export default class Client {
if (participation < BEACON_SYNC_SUPER_MAJORITY) {
return { correct: false, reason: "insufficient signatures" };
}
if (!this.isValidLightClientHeader(this.config.chainConfig, header)) {
return { correct: false, reason: "invalid header" };
}
return { correct: true };
} catch (e) {
console.error(e);
return { correct: false, reason: (e as Error).message };
}
}
private isValidLightClientHeader(
config: ChainForkConfig,
header: allForks.LightClientHeader
): boolean {
return isValidMerkleBranch(
config
.getExecutionForkTypes(header.beacon.slot)
.ExecutionPayloadHeader.hashTreeRoot(
(header as capella.LightClientHeader).execution
),
(header as capella.LightClientHeader).executionBranch,
EXECUTION_PAYLOAD_DEPTH,
EXECUTION_PAYLOAD_INDEX,
header.beacon.bodyRoot
);
}
public async getNextValidExecutionInfo(

File diff suppressed because it is too large Load Diff

View File

@ -1,25 +1,22 @@
import {
ContainerType,
VectorCompositeType,
ByteVectorType,
BooleanType,
UintNumberType,
ListCompositeType,
} from '@chainsafe/ssz';
import * as altair from '@lodestar/types/altair';
import { BEACON_SYNC_COMMITTEE_SIZE } from './constants.js';
VectorCompositeType,
} from "@chainsafe/ssz";
import * as capella from "@lodestar/types/capella";
import { BEACON_SYNC_COMMITTEE_SIZE } from "./constants.js";
const MAX_BATCHSIZE = 10000;
export const LightClientUpdateSSZ = altair.ssz.LightClientUpdate;
export const LightClientUpdateSSZ = capella.ssz.LightClientUpdate;
export const LightClientUpdatesSSZ = new ListCompositeType(
LightClientUpdateSSZ as any,
MAX_BATCHSIZE,
MAX_BATCHSIZE
);
export const CommitteeSSZ = new VectorCompositeType(
new ByteVectorType(48),
BEACON_SYNC_COMMITTEE_SIZE,
BEACON_SYNC_COMMITTEE_SIZE
);
const HashSSZ = new ByteVectorType(32);

View File

@ -1,13 +1,12 @@
import { routes } from "@lodestar/api";
import { BeaconConfig } from "@lodestar/config";
import * as altair from "@lodestar/types/altair";
import * as capella from "@lodestar/types/capella";
export type PubKeyString = string;
export type Slot = number;
export type Bytes32 = string;
export type OptimisticUpdate = altair.LightClientOptimisticUpdate;
export type LightClientUpdate = altair.LightClientUpdate;
export type OptimisticUpdate = capella.LightClientOptimisticUpdate;
export type LightClientUpdate = capella.LightClientUpdate;
export type GenesisData = {
committee: PubKeyString[];