@lodestar/beacon-node
Version:
A Typescript implementation of the beacon chain
48 lines • 2.36 kB
JavaScript
import { JobItemQueue } from "../../util/queue/index.js";
import { processExecutionPayload } from "./importExecutionPayload.js";
// TODO GLOAS: Set to be equal to DEFAULT_MAX_PENDING_UNFINALIZED_PAYLOAD_ENVELOPE_WRITES for now
const QUEUE_MAX_LENGTH = 16;
var PayloadEnvelopeImportStatus;
(function (PayloadEnvelopeImportStatus) {
PayloadEnvelopeImportStatus["queued"] = "queued";
PayloadEnvelopeImportStatus["importing"] = "importing";
PayloadEnvelopeImportStatus["imported"] = "imported";
})(PayloadEnvelopeImportStatus || (PayloadEnvelopeImportStatus = {}));
/**
* PayloadEnvelopeProcessor processes payload envelope jobs in a queued fashion, one after the other.
*
* Jobs are enqueued only on envelope arrival (gossip or API). The envelope may reach us before
* the sampled data columns; importExecutionPayload awaits `verifyPayloadsDataAvailability`
* internally, so a queued job can pend for up to `PAYLOAD_DATA_AVAILABILITY_TIMEOUT` while
* waiting for columns. Duplicate triggers for the same payloadInput are deduped via `importStatus`.
*/
export class PayloadEnvelopeProcessor {
jobQueue;
importStatus = new WeakMap();
constructor(chain, metrics, signal) {
this.jobQueue = new JobItemQueue((payloadInput, opts) => {
this.importStatus.set(payloadInput, PayloadEnvelopeImportStatus.importing);
return processExecutionPayload.call(chain, payloadInput, signal, opts);
}, { maxLength: QUEUE_MAX_LENGTH, noYieldIfOneItem: true, signal }, metrics?.payloadEnvelopeProcessorQueue ?? undefined);
}
async processPayloadEnvelopeJob(payloadInput, opts = {}) {
if (this.importStatus.get(payloadInput) !== undefined) {
return;
}
await this.jobQueue.waitForSpace();
// Re-check after await, as another call may have queued this payload.
if (this.importStatus.get(payloadInput) !== undefined) {
return;
}
this.importStatus.set(payloadInput, PayloadEnvelopeImportStatus.queued);
try {
await this.jobQueue.push(payloadInput, opts);
this.importStatus.set(payloadInput, PayloadEnvelopeImportStatus.imported);
}
catch (e) {
this.importStatus.delete(payloadInput);
throw e;
}
}
}
//# sourceMappingURL=payloadEnvelopeProcessor.js.map