@lodestar/beacon-node
Version:
A Typescript implementation of the beacon chain
115 lines • 4.7 kB
JavaScript
import { ForkSeq } from "@lodestar/params";
import { computeEpochAtSlot } from "@lodestar/state-transition";
export var BlockInputType;
(function (BlockInputType) {
// preData is preDeneb
BlockInputType["preData"] = "preData";
// data is out of available window, can be used to sync forward and keep adding to forkchoice
BlockInputType["outOfRangeData"] = "outOfRangeData";
BlockInputType["availableData"] = "availableData";
BlockInputType["dataPromise"] = "dataPromise";
})(BlockInputType || (BlockInputType = {}));
/** Enum to represent where blocks come from */
export var BlockSource;
(function (BlockSource) {
BlockSource["gossip"] = "gossip";
BlockSource["api"] = "api";
BlockSource["byRange"] = "req_resp_by_range";
BlockSource["byRoot"] = "req_resp_by_root";
})(BlockSource || (BlockSource = {}));
/** Enum to represent where blobs come from */
export var BlobsSource;
(function (BlobsSource) {
BlobsSource["gossip"] = "gossip";
BlobsSource["api"] = "api";
BlobsSource["byRange"] = "req_resp_by_range";
BlobsSource["byRoot"] = "req_resp_by_root";
})(BlobsSource || (BlobsSource = {}));
export var GossipedInputType;
(function (GossipedInputType) {
GossipedInputType["block"] = "block";
GossipedInputType["blob"] = "blob";
})(GossipedInputType || (GossipedInputType = {}));
export function blockRequiresBlobs(config, blockSlot, clockSlot) {
return (config.getForkSeq(blockSlot) >= ForkSeq.deneb &&
// Only request blobs if they are recent enough
computeEpochAtSlot(blockSlot) >= computeEpochAtSlot(clockSlot) - config.MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS);
}
export const getBlockInput = {
preData(config, block, source) {
if (config.getForkSeq(block.message.slot) >= ForkSeq.deneb) {
throw Error(`Post Deneb block slot ${block.message.slot}`);
}
return {
type: BlockInputType.preData,
block,
source,
};
},
// This isn't used right now but we might enable importing blobs into forkchoice from a point
// where data is not guaranteed to be available to hopefully reach a point where we have
// available data. Hence the validator duties can't be performed on outOfRangeData
//
// This can help with some of the requests of syncing without data for some use cases for e.g.
// building states or where importing data isn't important if valid child exists like ILs
outOfRangeData(config, block, source) {
if (config.getForkSeq(block.message.slot) < ForkSeq.deneb) {
throw Error(`Pre Deneb block slot ${block.message.slot}`);
}
return {
type: BlockInputType.outOfRangeData,
block,
source,
};
},
availableData(config, block, source, blockData) {
if (config.getForkSeq(block.message.slot) < ForkSeq.deneb) {
throw Error(`Pre Deneb block slot ${block.message.slot}`);
}
return {
type: BlockInputType.availableData,
block,
source,
blockData,
};
},
dataPromise(config, block, source, cachedData) {
if (config.getForkSeq(block.message.slot) < ForkSeq.deneb) {
throw Error(`Pre Deneb block slot ${block.message.slot}`);
}
return {
type: BlockInputType.dataPromise,
block,
source,
cachedData,
};
},
};
export function getBlockInputBlobs(blobsCache) {
const blobs = [];
for (let index = 0; index < blobsCache.size; index++) {
const blobSidecar = blobsCache.get(index);
if (blobSidecar === undefined) {
throw Error(`Missing blobSidecar at index=${index}`);
}
blobs.push(blobSidecar);
}
return { blobs };
}
export var AttestationImportOpt;
(function (AttestationImportOpt) {
AttestationImportOpt[AttestationImportOpt["Skip"] = 0] = "Skip";
AttestationImportOpt[AttestationImportOpt["Force"] = 1] = "Force";
})(AttestationImportOpt || (AttestationImportOpt = {}));
export var BlobSidecarValidation;
(function (BlobSidecarValidation) {
/** When recieved in gossip the blobs are individually verified before import */
BlobSidecarValidation[BlobSidecarValidation["Individual"] = 0] = "Individual";
/**
* Blobs when recieved in req/resp can be fully verified before import
* but currently used in spec tests where blobs come without proofs and assumed
* to be valid
*/
BlobSidecarValidation[BlobSidecarValidation["Full"] = 1] = "Full";
})(BlobSidecarValidation || (BlobSidecarValidation = {}));
//# sourceMappingURL=types.js.map