Skip to content

Commit

Permalink
Fix allForks SSZ types
Browse files Browse the repository at this point in the history
  • Loading branch information
dgcoffman committed Nov 7, 2022
1 parent e6c13e6 commit 87ecaaf
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 23 deletions.
2 changes: 0 additions & 2 deletions packages/beacon-node/src/api/impl/beacon/blocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,6 @@ export function getBeaconBlockApi({

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

console.log("Publishing block to P2P (gossip) network", signedBlock);

await Promise.all([
// Send the block, regardless of whether or not it is valid. The API
// specification is very clear that this is the desired behaviour.
Expand Down
1 change: 0 additions & 1 deletion packages/beacon-node/src/chain/prepareNextSlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export class PrepareNextSlotScheduler {
prepareSlot <= GENESIS_SLOT ||
(this.config.getForkSeq(prepareSlot) < ForkSeq.bellatrix && !isEpochTransition)
) {
console.log('prepareForNextSlot returning early')
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,8 @@ export async function produceBlockBody<T extends BlockType>(
((blockBody as eip4844.BeaconBlockBody)
.executionPayload as eip4844.ExecutionPayload).excessDataGas = BigInt(0);
}
}

// TODO EIP-4844: Actually all forks after EIP-4844
if (forkName === ForkName.eip4844) {
console.log("Dispatching request to Engine API to get blobs");
const blobsBundle = await this.executionEngine.getBlobsBundle(payloadId);
console.log("Got blobs bundle", blobsBundle);

// TODO EIP-4844: Optional (do it in a follow-up): sanity-check that the KZG commitments match blob contents as described by the spec
(blockBody as eip4844.BeaconBlockBody).blobKzgCommitments = blobsBundle.kzgs ?? [];
Expand Down
1 change: 0 additions & 1 deletion packages/beacon-node/src/network/gossip/gossipsub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ export class Eth2Gossipsub extends GossipSub {

async publishBeaconBlock(signedBlock: allForks.SignedBeaconBlock): Promise<void> {
const fork = this.config.getForkName(signedBlock.message.slot);
console.log(`Publishing beacon block for fork: ${fork}`);

// TODO: For EIP-4844, switch this to GossipType.beacon_block_and_blobs_sidecar
await this.publishObject<GossipType.beacon_block>({type: GossipType.beacon_block, fork}, signedBlock);
Expand Down
4 changes: 4 additions & 0 deletions packages/beacon-node/src/network/gossip/topic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ export function getGossipSSZType(topic: GossipTopic) {
return ssz.altair.LightClientOptimisticUpdate;
case GossipType.light_client_finality_update:
return ssz.altair.LightClientFinalityUpdate;
case GossipType.beacon_block_and_blobs_sidecar:
return ssz.eip4844.SignedBeaconBlockAndBlobsSidecar;
default:
throw new Error(`No ssz gossip type for ${(topic as GossipTopic).type}`);
}
}

Expand Down
28 changes: 14 additions & 14 deletions packages/types/src/allForks/sszTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {ssz as phase0} from "../phase0/index.js";
import {ssz as altair} from "../altair/index.js";
import {ssz as bellatrix} from "../bellatrix/index.js";
import {ssz as capella} from "../capella/index.js";
import {ssz as eip4844} from "../eip4844/index.js";

/**
* Index the ssz types that differ by fork
Expand Down Expand Up @@ -37,10 +38,10 @@ export const allForks = {
Metadata: altair.Metadata,
},
eip4844: {
BeaconBlockBody: capella.BeaconBlockBody,
BeaconBlock: capella.BeaconBlock,
SignedBeaconBlock: capella.SignedBeaconBlock,
BeaconState: capella.BeaconState,
BeaconBlockBody: eip4844.BeaconBlockBody,
BeaconBlock: eip4844.BeaconBlock,
SignedBeaconBlock: eip4844.SignedBeaconBlock,
BeaconState: eip4844.BeaconState,
Metadata: altair.Metadata,
},
};
Expand Down Expand Up @@ -68,13 +69,12 @@ export const allForksExecution = {
ExecutionPayloadHeader: capella.ExecutionPayloadHeader,
},
eip4844: {
BeaconBlockBody: capella.BeaconBlockBody,
BeaconBlock: capella.BeaconBlock,
SignedBeaconBlock: capella.SignedBeaconBlock,
BeaconState: capella.BeaconState,
// Not used in phase0 but added for type consitency
ExecutionPayload: capella.ExecutionPayload,
ExecutionPayloadHeader: capella.ExecutionPayloadHeader,
BeaconBlockBody: eip4844.BeaconBlockBody,
BeaconBlock: eip4844.BeaconBlock,
SignedBeaconBlock: eip4844.SignedBeaconBlock,
BeaconState: eip4844.BeaconState,
ExecutionPayload: eip4844.ExecutionPayload,
ExecutionPayloadHeader: eip4844.ExecutionPayloadHeader,
},
};

Expand All @@ -94,8 +94,8 @@ export const allForksBlinded = {
SignedBeaconBlock: capella.SignedBlindedBeaconBlock,
},
eip4844: {
BeaconBlockBody: capella.BlindedBeaconBlockBody,
BeaconBlock: capella.BlindedBeaconBlock,
SignedBeaconBlock: capella.SignedBlindedBeaconBlock,
BeaconBlockBody: eip4844.BlindedBeaconBlockBody,
BeaconBlock: eip4844.BlindedBeaconBlock,
SignedBeaconBlock: eip4844.SignedBlindedBeaconBlock,
},
};
1 change: 1 addition & 0 deletions packages/types/src/eip4844/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as ssz from "./sszTypes.js";

export type KZGCommitment = ValueOf<typeof ssz.KZGCommitment>;
export type Blob = ValueOf<typeof ssz.Blob>;
export type BlobKzgCommitments = ValueOf<typeof ssz.BlobKzgCommitments>;

export type ExecutionPayload = ValueOf<typeof ssz.ExecutionPayload>;
export type ExecutionPayloadHeader = ValueOf<typeof ssz.ExecutionPayloadHeader>;
Expand Down
1 change: 1 addition & 0 deletions packages/validator/src/services/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export class BlockProposingService {
}

private publishBlockWrapper = async (signedBlock: allForks.FullOrBlindedSignedBeaconBlock): Promise<void> => {
console.log("Validator is calling beacon node API to publish signed block", signedBlock.message);
return isBlindedBeaconBlock(signedBlock.message)
? this.api.beacon.publishBlindedBlock(signedBlock as bellatrix.SignedBlindedBeaconBlock)
: this.api.beacon.publishBlock(signedBlock as allForks.SignedBeaconBlock);
Expand Down

0 comments on commit 87ecaaf

Please sign in to comment.