@lodestar/beacon-node
Version:
A Typescript implementation of the beacon chain
78 lines • 3.86 kB
JavaScript
import { ForkSeq } from "@lodestar/params";
import { getBeaconBlockRootFromDataColumnSidecarSerialized, getBlockRootFromBeaconAttestationSerialized, getBlockRootFromPayloadAttestationMessageSerialized, getBlockRootFromSignedAggregateAndProofSerialized, getSlotFromBeaconAttestationSerialized, getSlotFromBlobSidecarSerialized, getSlotFromDataColumnSidecarSerialized, getSlotFromExecutionPayloadEnvelopeSerialized, getSlotFromPayloadAttestationMessageSerialized, getSlotFromSignedAggregateAndProofSerialized, getSlotFromSignedBeaconBlockSerialized, getSlotFromSignedExecutionPayloadBidSerialized, } from "../../util/sszBytes.js";
import { GossipType } from "../gossip/index.js";
/**
* Extract the slot and block root of a gossip message form serialized data.
* Only do it for messages that have a slot and block root, and we want to await the block if the block root is not known.
*/
export function createExtractBlockSlotRootFns() {
return {
[GossipType.beacon_attestation]: (data, fork) => {
const slot = getSlotFromBeaconAttestationSerialized(fork, data);
const root = getBlockRootFromBeaconAttestationSerialized(fork, data);
if (slot === null || root === null) {
return null;
}
return { slot, root };
},
[GossipType.beacon_aggregate_and_proof]: (data) => {
const slot = getSlotFromSignedAggregateAndProofSerialized(data);
const root = getBlockRootFromSignedAggregateAndProofSerialized(data);
if (slot === null || root === null) {
return null;
}
return { slot, root };
},
[GossipType.beacon_block]: (data) => {
const slot = getSlotFromSignedBeaconBlockSerialized(data);
if (slot === null) {
return null;
}
return { slot };
},
[GossipType.blob_sidecar]: (data) => {
const slot = getSlotFromBlobSidecarSerialized(data);
if (slot === null) {
return null;
}
return { slot };
},
[GossipType.data_column_sidecar]: (data, fork) => {
const slot = getSlotFromDataColumnSidecarSerialized(data, fork);
if (slot === null) {
return null;
}
if (ForkSeq[fork] < ForkSeq.gloas) {
return { slot };
}
const root = getBeaconBlockRootFromDataColumnSidecarSerialized(data);
// null root means the message is invalid here and will be ignored in gossip handler later
// returning the slot here helps check the earliest permissable slot in the network processor
return root !== null ? { slot, root } : { slot };
},
[GossipType.execution_payload]: (data) => {
const slot = getSlotFromExecutionPayloadEnvelopeSerialized(data);
// Do not extract the root here; the network processor will extract it in the 2nd round to trigger block search without awaiting.
if (slot === null) {
return null;
}
return { slot };
},
[GossipType.payload_attestation_message]: (data) => {
const slot = getSlotFromPayloadAttestationMessageSerialized(data);
const root = getBlockRootFromPayloadAttestationMessageSerialized(data);
if (slot === null || root === null) {
return null;
}
return { slot, root };
},
[GossipType.execution_payload_bid]: (data) => {
const slot = getSlotFromSignedExecutionPayloadBidSerialized(data);
if (slot === null) {
return null;
}
return { slot };
},
};
}
//# sourceMappingURL=extractSlotRootFns.js.map