Skip to content

Commit

Permalink
make broadcast validation optional
Browse files Browse the repository at this point in the history
  • Loading branch information
g11tech committed Jul 25, 2023
1 parent 89ff53b commit 45260c9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
8 changes: 4 additions & 4 deletions packages/api/src/beacon/routes/beacon/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export type Api = {

publishBlockV2(
blockOrContents: allForks.SignedBeaconBlock | SignedBlockContents,
opts: {broadcastValidation: BroadcastValidation}
opts: {broadcastValidation?: BroadcastValidation}
): Promise<
ApiClientResponse<
{
Expand All @@ -204,7 +204,7 @@ export type Api = {

publishBlindedBlockV2(
blindedBlockOrContents: allForks.SignedBlindedBeaconBlock | SignedBlindedBlockContents,
opts: {broadcastValidation: BroadcastValidation}
opts: {broadcastValidation?: BroadcastValidation}
): Promise<
ApiClientResponse<
{
Expand Down Expand Up @@ -256,9 +256,9 @@ export type ReqTypes = {
getBlockHeaders: {query: {slot?: number; parent_root?: string}};
getBlockRoot: BlockIdOnlyReq;
publishBlock: {body: unknown};
publishBlockV2: {body: unknown; query: {broadcast_validation: string}};
publishBlockV2: {body: unknown; query: {broadcast_validation?: string}};
publishBlindedBlock: {body: unknown};
publishBlindedBlockV2: {body: unknown; query: {broadcast_validation: string}};
publishBlindedBlockV2: {body: unknown; query: {broadcast_validation?: string}};
getBlobSidecars: BlockIdOnlyReq;
};

Expand Down
9 changes: 4 additions & 5 deletions packages/beacon-node/src/api/impl/beacon/blocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {ApiModules} from "../../types.js";
import {resolveBlockId, toBeaconHeaderResponse} from "./utils.js";

type PublishBlockOpts = ImportBlockOpts & {broadcastValidation?: routes.beacon.BroadcastValidation};
const defaultPublishOpts = {broadcastValidation: routes.beacon.BroadcastValidation.none};

/**
* Validator clock may be advanced from beacon's clock. If the validator requests a resource in a
Expand All @@ -42,7 +41,7 @@ export function getBeaconBlockApi({
}: Pick<ApiModules, "chain" | "config" | "metrics" | "network" | "db">): ServerApi<routes.beacon.block.Api> {
const publishBlock: ServerApi<routes.beacon.block.Api>["publishBlock"] = async (
signedBlockOrContents,
opts: PublishBlockOpts = defaultPublishOpts
opts: PublishBlockOpts = {}
) => {
const seenTimestampSec = Date.now() / 1000;
let blockForImport: BlockInput, signedBlock: allForks.SignedBeaconBlock, signedBlobs: deneb.SignedBlobSidecars;
Expand Down Expand Up @@ -70,7 +69,7 @@ export function getBeaconBlockApi({

// check what validations have been requested before broadcasting and publishing the block
// TODO: add validation time to metrics
const broadcastValidation = opts.broadcastValidation ?? defaultPublishOpts.broadcastValidation;
const broadcastValidation = opts.broadcastValidation ?? routes.beacon.BroadcastValidation.none;
switch (broadcastValidation) {
case routes.beacon.BroadcastValidation.none:
break;
Expand Down Expand Up @@ -137,7 +136,7 @@ export function getBeaconBlockApi({

const publishBlindedBlock: ServerApi<routes.beacon.block.Api>["publishBlindedBlock"] = async (
signedBlindedBlockOrContents,
opts: PublishBlockOpts = defaultPublishOpts
opts: PublishBlockOpts = {}
) => {
const executionBuilder = chain.executionBuilder;
if (!executionBuilder) throw Error("exeutionBuilder required to publish SignedBlindedBeaconBlock");
Expand Down Expand Up @@ -311,7 +310,7 @@ export function getBeaconBlockApi({
await publishBlindedBlock(signedBlindedBlockOrContents, opts);
},

async publishBlockV2(signedBlockOrContents, opts: PublishBlockOpts = defaultPublishOpts) {
async publishBlockV2(signedBlockOrContents, opts) {
await publishBlock(signedBlockOrContents, opts);
},

Expand Down
4 changes: 2 additions & 2 deletions packages/validator/src/services/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type ProduceBlockOpts = {
*/
export class BlockProposingService {
private readonly dutiesService: BlockDutiesService;
private readonly broadcastValidation: routes.beacon.BroadcastValidation;
private readonly broadcastValidation?: routes.beacon.BroadcastValidation;

constructor(
private readonly config: ChainForkConfig,
Expand All @@ -80,7 +80,7 @@ export class BlockProposingService {
this.notifyBlockProductionFn
);

this.broadcastValidation = broadcastValidation ?? routes.beacon.BroadcastValidation.none;
this.broadcastValidation = broadcastValidation;
}

removeDutiesForKey(pubkey: PubkeyHex): void {
Expand Down

0 comments on commit 45260c9

Please sign in to comment.