Skip to content

Commit

Permalink
feat: process gossip blocks with serializedData
Browse files Browse the repository at this point in the history
  • Loading branch information
twoeths committed May 3, 2023
1 parent dd95d8d commit b05b060
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
18 changes: 15 additions & 3 deletions packages/beacon-node/src/chain/interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
import {allForks, UintNum64, Root, phase0, Slot, RootHex, Epoch, ValidatorIndex, deneb, Wei} from "@lodestar/types";
import {
allForks,
UintNum64,
Root,
phase0,
Slot,
RootHex,
Epoch,
ValidatorIndex,
deneb,
Wei,
WithOptionalBytes,
} from "@lodestar/types";
import {CachedBeaconStateAllForks, Index2PubkeyCache, PubkeyIndexMap} from "@lodestar/state-transition";
import {BeaconConfig} from "@lodestar/config";
import {CompositeTypeAny, TreeView, Type} from "@chainsafe/ssz";
Expand Down Expand Up @@ -122,9 +134,9 @@ export interface IBeaconChain {
produceBlindedBlock(blockAttributes: BlockAttributes): Promise<{block: allForks.BlindedBeaconBlock; blockValue: Wei}>;

/** Process a block until complete */
processBlock(block: BlockInput, opts?: ImportBlockOpts): Promise<void>;
processBlock(block: WithOptionalBytes<BlockInput>, opts?: ImportBlockOpts): Promise<void>;
/** Process a chain of blocks until complete */
processChainSegment(blocks: BlockInput[], opts?: ImportBlockOpts): Promise<void>;
processChainSegment(blocks: WithOptionalBytes<BlockInput>[], opts?: ImportBlockOpts): Promise<void>;

getStatus(): phase0.Status;

Expand Down
12 changes: 8 additions & 4 deletions packages/beacon-node/src/network/processor/gossipHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {peerIdFromString} from "@libp2p/peer-id";
import {toHexString} from "@chainsafe/ssz";
import {BeaconConfig} from "@lodestar/config";
import {Logger, prettyBytes} from "@lodestar/utils";
import {Root, Slot, ssz} from "@lodestar/types";
import {Root, Slot, ssz, WithBytes} from "@lodestar/types";
import {ForkName, ForkSeq} from "@lodestar/params";
import {Metrics} from "../../metrics/index.js";
import {OpSource} from "../../metrics/validatorMonitor.js";
Expand Down Expand Up @@ -124,7 +124,11 @@ export function getGossipHandlers(modules: ValidatorFnsModules, options: GossipH
}
}

function handleValidBeaconBlock(blockInput: BlockInput, peerIdStr: string, seenTimestampSec: number): void {
function handleValidBeaconBlock(
blockInput: WithBytes<BlockInput>,
peerIdStr: string,
seenTimestampSec: number
): void {
const signedBlock = blockInput.block;

// Handler - MUST NOT `await`, to allow validation result to be propagated
Expand Down Expand Up @@ -178,7 +182,7 @@ export function getGossipHandlers(modules: ValidatorFnsModules, options: GossipH

const blockInput = getBlockInput.preDeneb(config, signedBlock);
await validateBeaconBlock(blockInput, topic.fork, peerIdStr, seenTimestampSec);
handleValidBeaconBlock(blockInput, peerIdStr, seenTimestampSec);
handleValidBeaconBlock({...blockInput, serializedData}, peerIdStr, seenTimestampSec);
},

[GossipType.beacon_block_and_blobs_sidecar]: async ({serializedData}, topic, peerIdStr, seenTimestampSec) => {
Expand All @@ -193,7 +197,7 @@ export function getGossipHandlers(modules: ValidatorFnsModules, options: GossipH
const blockInput = getBlockInput.postDeneb(config, beaconBlock, blobsSidecar);
await validateBeaconBlock(blockInput, topic.fork, peerIdStr, seenTimestampSec);
validateGossipBlobsSidecar(beaconBlock, blobsSidecar);
handleValidBeaconBlock(blockInput, peerIdStr, seenTimestampSec);
handleValidBeaconBlock({...blockInput, serializedData}, peerIdStr, seenTimestampSec);
},

[GossipType.beacon_aggregate_and_proof]: async ({serializedData}, topic, _peer, seenTimestampSec) => {
Expand Down

0 comments on commit b05b060

Please sign in to comment.