Skip to content

Commit

Permalink
Skip blobs validation if from gossip
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion committed Nov 29, 2022
1 parent b30aa71 commit 74287e3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
2 changes: 2 additions & 0 deletions packages/beacon-node/src/chain/blocks/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ export type ImportBlockOpts = {
* Metadata: `true` if all the signatures including the proposer signature have been verified
*/
validSignatures?: boolean;
/** Set to true if already run `validateBlobsSidecar()` sucessfully on the blobs */
validBlobsSidecar?: boolean;
/** Seen timestamp seconds */
seenTimestampSec?: number;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function verifyBlocksStateTransitionOnly(
// TODO EIP-4844: Is the best place here to call validateBlobsSidecar()?
// TODO EIP-4844: Gossip may already call validateBlobsSidecar, add some flag to de-dup from here
// TODO EIP-4844: For sync if this function is expensive, consider adding sleep(0) if metrics show it
const dataAvailableStatus = maybeValidateBlobs(config, blocks[i]);
const dataAvailableStatus = maybeValidateBlobs(config, blocks[i], opts);

// STFN - per_slot_processing() + per_block_processing()
// NOTE: `regen.getPreState()` should have dialed forward the state already caching checkpoint states
Expand Down Expand Up @@ -96,10 +96,18 @@ export async function verifyBlocksStateTransitionOnly(
return {postStates, proposerBalanceDeltas};
}

function maybeValidateBlobs(config: IChainForkConfig, blockImport: BlockImport): DataAvailableStatus {
function maybeValidateBlobs(
config: IChainForkConfig,
blockImport: BlockImport,
opts: ImportBlockOpts
): DataAvailableStatus {
// TODO EIP4844: Make switch verify it's exhaustive
switch (blockImport.type) {
case BlockImportType.postEIP4844: {
if (opts.validBlobsSidecar) {
return DataAvailableStatus.available;
}

const {block, blobs} = blockImport;
const blockSlot = block.message.slot;
const {blobKzgCommitments} = (block as eip4844.SignedBeaconBlock).message.body;
Expand Down
21 changes: 13 additions & 8 deletions packages/beacon-node/src/network/gossip/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,20 @@ export function getGossipHandlers(modules: ValidatorFnsModules, options: GossipH

metrics?.registerBeaconBlock(OpSource.gossip, seenTimestampSec, signedBlock.message);

// `validProposerSignature = true`, in gossip validation the proposer signature is checked
// At gossip time, it's critical to keep a good number of mesh peers.
// To do that, the Gossip Job Wait Time should be consistently <3s to avoid the behavior penalties in gossip
// Gossip Job Wait Time depends on the BLS Job Wait Time
// so `blsVerifyOnMainThread = true`: we want to verify signatures immediately without affecting the bls thread pool.
// otherwise we can't utilize bls thread pool capacity and Gossip Job Wait Time can't be kept low consistently.
// See https://github.com/ChainSafe/lodestar/issues/3792
chain
.processBlock(blockImport, {validProposerSignature: true, blsVerifyOnMainThread: true})
.processBlock(blockImport, {
// proposer signature already checked in validateBeaconBlock()
validProposerSignature: true,
// blobsSidecar already checked in validateGossipBlobsSidecar()
validBlobsSidecar: true,
// It's critical to keep a good number of mesh peers.
// To do that, the Gossip Job Wait Time should be consistently <3s to avoid the behavior penalties in gossip
// Gossip Job Wait Time depends on the BLS Job Wait Time
// so `blsVerifyOnMainThread = true`: we want to verify signatures immediately without affecting the bls thread pool.
// otherwise we can't utilize bls thread pool capacity and Gossip Job Wait Time can't be kept low consistently.
// See https://github.com/ChainSafe/lodestar/issues/3792
blsVerifyOnMainThread: true,
})
.then(() => {
// Returns the delay between the start of `block.slot` and `current time`
const delaySec = chain.clock.secFromSlot(slot);
Expand Down

0 comments on commit 74287e3

Please sign in to comment.