From 5088c070917ded53e26fcd30982f20f679e5d834 Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Mon, 13 Mar 2023 14:17:56 +0700 Subject: [PATCH 1/4] Process gossip block immediately --- .../src/network/processor/index.ts | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/packages/beacon-node/src/network/processor/index.ts b/packages/beacon-node/src/network/processor/index.ts index e1f37f8da531..25d009dbb7be 100644 --- a/packages/beacon-node/src/network/processor/index.ts +++ b/packages/beacon-node/src/network/processor/index.ts @@ -20,19 +20,24 @@ export type NetworkProcessorOpts = GossipHandlerOpts & { maxGossipTopicConcurrency?: number; }; -const executeGossipWorkOrderObj: Record = { +/** + * True if we want to process gossip object immediately, false if we check for bls and regen + * in order to process the gossip object. + */ +const executeGossipWorkOrderObj: Record = { + // gossip block verify signatures on main thread, hence we want to bypass the bls check [GossipType.beacon_block]: true, - [GossipType.beacon_block_and_blobs_sidecar]: true, - [GossipType.beacon_aggregate_and_proof]: true, - [GossipType.beacon_attestation]: true, - [GossipType.voluntary_exit]: true, - [GossipType.proposer_slashing]: true, - [GossipType.attester_slashing]: true, - [GossipType.sync_committee_contribution_and_proof]: true, - [GossipType.sync_committee]: true, - [GossipType.light_client_finality_update]: true, - [GossipType.light_client_optimistic_update]: true, - [GossipType.bls_to_execution_change]: true, + [GossipType.beacon_block_and_blobs_sidecar]: false, + [GossipType.beacon_aggregate_and_proof]: false, + [GossipType.beacon_attestation]: false, + [GossipType.voluntary_exit]: false, + [GossipType.proposer_slashing]: false, + [GossipType.attester_slashing]: false, + [GossipType.sync_committee_contribution_and_proof]: false, + [GossipType.sync_committee]: false, + [GossipType.light_client_finality_update]: false, + [GossipType.light_client_optimistic_update]: false, + [GossipType.bls_to_execution_change]: false, }; const executeGossipWorkOrder = Object.keys(executeGossipWorkOrderObj) as (keyof typeof executeGossipWorkOrderObj)[]; @@ -123,13 +128,14 @@ export class NetworkProcessor { let jobsSubmitted = 0; job_loop: while (jobsSubmitted < MAX_JOBS_SUBMITTED_PER_TICK) { - // Check canAcceptWork before calling queue.next() since it consumes the items - if (!this.chain.blsThreadPoolCanAcceptWork() || !this.chain.regenCanAcceptWork()) { - this.metrics?.networkProcessor.canNotAcceptWork.inc(); - break; - } - for (const topic of executeGossipWorkOrder) { + // Check canAcceptWork before calling queue.next() since it consumes the items + // beacon block is guaranteed to be processed immedately + const ensureAcceptWork = executeGossipWorkOrderObj[topic]; + if (!ensureAcceptWork && (!this.chain.blsThreadPoolCanAcceptWork() || !this.chain.regenCanAcceptWork())) { + this.metrics?.networkProcessor.canNotAcceptWork.inc(); + break job_loop; + } if ( this.opts.maxGossipTopicConcurrency !== undefined && this.gossipTopicConcurrency[topic] > this.opts.maxGossipTopicConcurrency From 07453fa0835cc96a445106413af2c9fc546ec222 Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Mon, 13 Mar 2023 14:23:10 +0700 Subject: [PATCH 2/4] Process beacon_block_and_blobs_sidecar gossip object immediately --- packages/beacon-node/src/network/processor/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/beacon-node/src/network/processor/index.ts b/packages/beacon-node/src/network/processor/index.ts index 25d009dbb7be..ded796cf7359 100644 --- a/packages/beacon-node/src/network/processor/index.ts +++ b/packages/beacon-node/src/network/processor/index.ts @@ -27,7 +27,7 @@ export type NetworkProcessorOpts = GossipHandlerOpts & { const executeGossipWorkOrderObj: Record = { // gossip block verify signatures on main thread, hence we want to bypass the bls check [GossipType.beacon_block]: true, - [GossipType.beacon_block_and_blobs_sidecar]: false, + [GossipType.beacon_block_and_blobs_sidecar]: true, [GossipType.beacon_aggregate_and_proof]: false, [GossipType.beacon_attestation]: false, [GossipType.voluntary_exit]: false, From 9ad4857d290e8d9ddf75d0099fb8d6f369f8ab67 Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Mon, 13 Mar 2023 16:50:16 +0700 Subject: [PATCH 3/4] New WorkOpts type --- .../src/network/processor/index.ts | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/packages/beacon-node/src/network/processor/index.ts b/packages/beacon-node/src/network/processor/index.ts index ded796cf7359..0ac62ffe49de 100644 --- a/packages/beacon-node/src/network/processor/index.ts +++ b/packages/beacon-node/src/network/processor/index.ts @@ -20,24 +20,28 @@ export type NetworkProcessorOpts = GossipHandlerOpts & { maxGossipTopicConcurrency?: number; }; +type WorkOpts = { + bypassQueue?: boolean; +}; + /** * True if we want to process gossip object immediately, false if we check for bls and regen * in order to process the gossip object. */ -const executeGossipWorkOrderObj: Record = { +const executeGossipWorkOrderObj: Record = { // gossip block verify signatures on main thread, hence we want to bypass the bls check - [GossipType.beacon_block]: true, - [GossipType.beacon_block_and_blobs_sidecar]: true, - [GossipType.beacon_aggregate_and_proof]: false, - [GossipType.beacon_attestation]: false, - [GossipType.voluntary_exit]: false, - [GossipType.proposer_slashing]: false, - [GossipType.attester_slashing]: false, - [GossipType.sync_committee_contribution_and_proof]: false, - [GossipType.sync_committee]: false, - [GossipType.light_client_finality_update]: false, - [GossipType.light_client_optimistic_update]: false, - [GossipType.bls_to_execution_change]: false, + [GossipType.beacon_block]: {bypassQueue: true}, + [GossipType.beacon_block_and_blobs_sidecar]: {bypassQueue: true}, + [GossipType.beacon_aggregate_and_proof]: {}, + [GossipType.beacon_attestation]: {}, + [GossipType.voluntary_exit]: {}, + [GossipType.proposer_slashing]: {}, + [GossipType.attester_slashing]: {}, + [GossipType.sync_committee_contribution_and_proof]: {}, + [GossipType.sync_committee]: {}, + [GossipType.light_client_finality_update]: {}, + [GossipType.light_client_optimistic_update]: {}, + [GossipType.bls_to_execution_change]: {}, }; const executeGossipWorkOrder = Object.keys(executeGossipWorkOrderObj) as (keyof typeof executeGossipWorkOrderObj)[]; @@ -131,8 +135,8 @@ export class NetworkProcessor { for (const topic of executeGossipWorkOrder) { // Check canAcceptWork before calling queue.next() since it consumes the items // beacon block is guaranteed to be processed immedately - const ensureAcceptWork = executeGossipWorkOrderObj[topic]; - if (!ensureAcceptWork && (!this.chain.blsThreadPoolCanAcceptWork() || !this.chain.regenCanAcceptWork())) { + const bypassQueue = executeGossipWorkOrderObj[topic]?.bypassQueue ?? false; + if (!bypassQueue && (!this.chain.blsThreadPoolCanAcceptWork() || !this.chain.regenCanAcceptWork())) { this.metrics?.networkProcessor.canNotAcceptWork.inc(); break job_loop; } From b1a27265bd47dfdb14ac441b67f77805feaed766 Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Tue, 14 Mar 2023 10:24:43 +0700 Subject: [PATCH 4/4] Check canAceptWork once per executeWork() --- packages/beacon-node/src/network/processor/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/beacon-node/src/network/processor/index.ts b/packages/beacon-node/src/network/processor/index.ts index 0ac62ffe49de..82ea47d636f5 100644 --- a/packages/beacon-node/src/network/processor/index.ts +++ b/packages/beacon-node/src/network/processor/index.ts @@ -132,11 +132,11 @@ export class NetworkProcessor { let jobsSubmitted = 0; job_loop: while (jobsSubmitted < MAX_JOBS_SUBMITTED_PER_TICK) { + // Check canAcceptWork before calling queue.next() since it consumes the items + const canAcceptWork = this.chain.blsThreadPoolCanAcceptWork() && this.chain.regenCanAcceptWork(); for (const topic of executeGossipWorkOrder) { - // Check canAcceptWork before calling queue.next() since it consumes the items // beacon block is guaranteed to be processed immedately - const bypassQueue = executeGossipWorkOrderObj[topic]?.bypassQueue ?? false; - if (!bypassQueue && (!this.chain.blsThreadPoolCanAcceptWork() || !this.chain.regenCanAcceptWork())) { + if (!canAcceptWork && !executeGossipWorkOrderObj[topic]?.bypassQueue) { this.metrics?.networkProcessor.canNotAcceptWork.inc(); break job_loop; }