fix: create fixSerializedUint8Array helper method to deal with weird quirk of ssz serialize

This commit is contained in:
Derrick Hammer 2023-07-13 08:09:00 -04:00
parent 75ed669eb7
commit d8430b4a11
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 12 additions and 4 deletions

View File

@ -5,6 +5,7 @@ import { concatBytes } from "@noble/hashes/utils";
import { LightClientUpdate } from "#types.js"; import { LightClientUpdate } from "#types.js";
import * as capella from "@lodestar/types/capella"; import * as capella from "@lodestar/types/capella";
import NodeCache from "node-cache"; import NodeCache from "node-cache";
import { fixSerializedUint8Array } from "#util.js";
export interface StoreItem { export interface StoreItem {
update: Uint8Array; update: Uint8Array;
@ -22,10 +23,14 @@ export default class Store implements IStore {
addUpdate(period: number, update: LightClientUpdate) { addUpdate(period: number, update: LightClientUpdate) {
try { try {
this.store.set(period, { this.store.set(period, {
update: capella.ssz.LightClientUpdate.serialize(update), update: fixSerializedUint8Array(
nextCommittee: CommitteeSSZ.serialize(update.nextSyncCommittee.pubkeys), capella.ssz.LightClientUpdate.serialize(update),
nextCommitteeHash: digest( ),
concatBytes(...update.nextSyncCommittee.pubkeys), nextCommittee: fixSerializedUint8Array(
CommitteeSSZ.serialize(update.nextSyncCommittee.pubkeys),
),
nextCommitteeHash: fixSerializedUint8Array(
digest(concatBytes(...update.nextSyncCommittee.pubkeys)),
), ),
}); });
} catch (e) { } catch (e) {

View File

@ -131,3 +131,6 @@ function isValidLightClientHeader(
header.beacon.bodyRoot, header.beacon.bodyRoot,
); );
} }
export function fixSerializedUint8Array(arr: Uint8Array) {
return new Uint8Array(Object.values(arr));
}