diff --git a/packages/beacon-node/src/chain/chain.ts b/packages/beacon-node/src/chain/chain.ts index 792f5d61d168..3fd06d34f794 100644 --- a/packages/beacon-node/src/chain/chain.ts +++ b/packages/beacon-node/src/chain/chain.ts @@ -29,7 +29,7 @@ import { import {CheckpointWithHex, ExecutionStatus, IForkChoice, ProtoBlock} from "@lodestar/fork-choice"; import {ProcessShutdownCallback} from "@lodestar/validator"; import {Logger, isErrorAborted, pruneSetToMax, sleep, toHex} from "@lodestar/utils"; -import {ForkSeq, SLOTS_PER_EPOCH} from "@lodestar/params"; +import {ForkSeq, SLOTS_PER_EPOCH, GENESIS_SLOT} from "@lodestar/params"; import {toHexString} from "@lodestar/utils"; import {GENESIS_EPOCH, ZERO_HASH} from "../constants/index.js"; @@ -43,7 +43,6 @@ import {isOptimisticBlock} from "../util/forkChoice.js"; import { blindedOrFullBlockToFull, deserializeFullOrBlindedSignedBeaconBlock, - getEth1BlockHashFromSerializedBlock, serializeFullOrBlindedSignedBeaconBlock, } from "../util/fullOrBlindedBlock.js"; import {ExecutionPayloadBody} from "../execution/engine/types.js"; @@ -470,6 +469,7 @@ export class BeaconChain implements IBeaconChain { } async blindedOrFullBlockToFull(block: allForks.FullOrBlindedSignedBeaconBlock): Promise { + if (block.message.slot === GENESIS_SLOT) return block; const info = this.config.getForkInfo(block.message.slot); return blindedOrFullBlockToFull( this.config, @@ -479,15 +479,10 @@ export class BeaconChain implements IBeaconChain { ); } - async blindedOrFullBlockToFullBytes(forkSeq: ForkSeq, block: Uint8Array): Promise { + async blindedOrFullBlockToFullBytes(block: Uint8Array): Promise { return serializeFullOrBlindedSignedBeaconBlock( this.config, - blindedOrFullBlockToFull( - this.config, - forkSeq, - deserializeFullOrBlindedSignedBeaconBlock(this.config, block), - await this.getTransactionsAndWithdrawals(forkSeq, toHexString(getEth1BlockHashFromSerializedBlock(block))) - ) + await this.blindedOrFullBlockToFull(deserializeFullOrBlindedSignedBeaconBlock(this.config, block)) ); } diff --git a/packages/beacon-node/src/chain/interface.ts b/packages/beacon-node/src/chain/interface.ts index 59f3e1d4f7d5..417e8e69108d 100644 --- a/packages/beacon-node/src/chain/interface.ts +++ b/packages/beacon-node/src/chain/interface.ts @@ -10,7 +10,6 @@ import {BeaconConfig} from "@lodestar/config"; import {Logger} from "@lodestar/utils"; import {IForkChoice, ProtoBlock} from "@lodestar/fork-choice"; -import {ForkSeq} from "@lodestar/params"; import {IEth1ForBlockProduction} from "../eth1/index.js"; import {IExecutionEngine, IExecutionBuilder} from "../execution/index.js"; import {Metrics} from "../metrics/metrics.js"; @@ -145,7 +144,7 @@ export interface IBeaconChain { ): Promise<{block: allForks.BlindedBeaconBlock; executionPayloadValue: Wei}>; blindedOrFullBlockToFull(block: allForks.FullOrBlindedSignedBeaconBlock): Promise; - blindedOrFullBlockToFullBytes(forkSeq: ForkSeq, block: Uint8Array): Promise; + blindedOrFullBlockToFullBytes(block: Uint8Array): Promise; /** Process a block until complete */ processBlock(block: BlockInput, opts?: ImportBlockOpts): Promise; diff --git a/packages/beacon-node/src/network/reqresp/handlers/beaconBlocksByRange.ts b/packages/beacon-node/src/network/reqresp/handlers/beaconBlocksByRange.ts index c6ce01f47f58..56533596c2f2 100644 --- a/packages/beacon-node/src/network/reqresp/handlers/beaconBlocksByRange.ts +++ b/packages/beacon-node/src/network/reqresp/handlers/beaconBlocksByRange.ts @@ -23,10 +23,9 @@ export async function* onBeaconBlocksByRange( if (startSlot <= finalizedSlot) { // Chain of blobs won't change for await (const {key, value} of finalized.binaryEntriesStream({gte: startSlot, lt: endSlot})) { - const {name, seq} = chain.config.getForkInfo(finalized.decodeKey(key)); yield { - data: await chain.blindedOrFullBlockToFullBytes(seq, value), - fork: name, + data: await chain.blindedOrFullBlockToFullBytes(value), + fork: chain.config.getForkName(finalized.decodeKey(key)), }; } } @@ -55,10 +54,9 @@ export async function* onBeaconBlocksByRange( throw new ResponseError(RespStatus.SERVER_ERROR, `No item for root ${block.blockRoot} slot ${block.slot}`); } - const {name, seq} = chain.config.getForkInfo(block.slot); yield { - data: await chain.blindedOrFullBlockToFullBytes(seq, blockBytes), - fork: name, + data: await chain.blindedOrFullBlockToFullBytes(blockBytes), + fork: chain.config.getForkName(block.slot), }; } diff --git a/packages/beacon-node/src/network/reqresp/handlers/beaconBlocksByRoot.ts b/packages/beacon-node/src/network/reqresp/handlers/beaconBlocksByRoot.ts index bf3b928a5a3f..ba709633c173 100644 --- a/packages/beacon-node/src/network/reqresp/handlers/beaconBlocksByRoot.ts +++ b/packages/beacon-node/src/network/reqresp/handlers/beaconBlocksByRoot.ts @@ -38,11 +38,9 @@ export async function* onBeaconBlocksByRoot( slot = slotFromBytes; } - const {name, seq} = chain.config.getForkInfo(slot); - yield { - data: await chain.blindedOrFullBlockToFullBytes(seq, blockBytes), - fork: name, + data: await chain.blindedOrFullBlockToFullBytes(blockBytes), + fork: chain.config.getForkName(slot), }; } } diff --git a/packages/beacon-node/src/util/fullOrBlindedBlock.ts b/packages/beacon-node/src/util/fullOrBlindedBlock.ts index 7cf46c084013..a04c2ae04065 100644 --- a/packages/beacon-node/src/util/fullOrBlindedBlock.ts +++ b/packages/beacon-node/src/util/fullOrBlindedBlock.ts @@ -3,7 +3,7 @@ import {allForks, bellatrix, capella, deneb} from "@lodestar/types"; import {BYTES_PER_LOGS_BLOOM, ForkSeq, SYNC_COMMITTEE_SIZE} from "@lodestar/params"; import {executionPayloadToPayloadHeader} from "@lodestar/state-transition"; import {ExecutionPayloadBody} from "../execution/engine/types.js"; -import {ROOT_SIZE, getSlotFromSignedBeaconBlockSerialized} from "./sszBytes.js"; +import {getSlotFromSignedBeaconBlockSerialized} from "./sszBytes.js"; /** * * class SignedBeaconBlock(Container): @@ -49,15 +49,7 @@ const BEACON_BLOCK_FIXED_LENGTH = 8 + 8 + 32 + 32 + 4; * Deneb: * blobKzgCommitments [offset - 4 bytes] */ - -const LOCATION_OF_ETH1_BLOCK_HASH = 96 + 32 + 8; -export function getEth1BlockHashFromSerializedBlock(block: Uint8Array): Uint8Array { - const firstByte = SIGNED_BEACON_BLOCK_FIXED_LENGTH + BEACON_BLOCK_FIXED_LENGTH + LOCATION_OF_ETH1_BLOCK_HASH; - return block.slice(firstByte, firstByte + ROOT_SIZE); -} - -const LOCATION_OF_EXECUTION_PAYLOAD_OFFSET = - LOCATION_OF_ETH1_BLOCK_HASH + 32 + 32 + 4 + 4 + 4 + 4 + 4 + SYNC_COMMITTEE_SIZE / 8 + 96; +const LOCATION_OF_EXECUTION_PAYLOAD_OFFSET = 96 + 32 + 8 + 32 + 32 + 4 + 4 + 4 + 4 + 4 + SYNC_COMMITTEE_SIZE / 8 + 96; /** * class ExecutionPayload(Container) or class ExecutionPayloadHeader(Container)