Skip to content

Commit 8d804ea

Browse files
committed
fix: edge case for GENESIS_SLOT as post-altair block
1 parent 3a438b3 commit 8d804ea

File tree

5 files changed

+13
-31
lines changed

5 files changed

+13
-31
lines changed

packages/beacon-node/src/chain/chain.ts

+4-9
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
import {CheckpointWithHex, ExecutionStatus, IForkChoice, ProtoBlock} from "@lodestar/fork-choice";
3030
import {ProcessShutdownCallback} from "@lodestar/validator";
3131
import {Logger, isErrorAborted, pruneSetToMax, sleep, toHex} from "@lodestar/utils";
32-
import {ForkSeq, SLOTS_PER_EPOCH, MAX_BLOBS_PER_BLOCK} from "@lodestar/params";
32+
import {ForkSeq, SLOTS_PER_EPOCH, MAX_BLOBS_PER_BLOCK, GENESIS_SLOT} from "@lodestar/params";
3333

3434
import {toHexString} from "@lodestar/utils";
3535
import {GENESIS_EPOCH, ZERO_HASH} from "../constants/index.js";
@@ -43,7 +43,6 @@ import {isOptimisticBlock} from "../util/forkChoice.js";
4343
import {
4444
blindedOrFullBlockToFull,
4545
deserializeFullOrBlindedSignedBeaconBlock,
46-
getEth1BlockHashFromSerializedBlock,
4746
serializeFullOrBlindedSignedBeaconBlock,
4847
} from "../util/fullOrBlindedBlock.js";
4948
import {ExecutionPayloadBody} from "../execution/engine/types.js";
@@ -471,6 +470,7 @@ export class BeaconChain implements IBeaconChain {
471470
}
472471

473472
async blindedOrFullBlockToFull(block: allForks.FullOrBlindedSignedBeaconBlock): Promise<allForks.SignedBeaconBlock> {
473+
if (block.message.slot === GENESIS_SLOT) return block;
474474
const info = this.config.getForkInfo(block.message.slot);
475475
return blindedOrFullBlockToFull(
476476
this.config,
@@ -480,15 +480,10 @@ export class BeaconChain implements IBeaconChain {
480480
);
481481
}
482482

483-
async blindedOrFullBlockToFullBytes(forkSeq: ForkSeq, block: Uint8Array): Promise<Uint8Array> {
483+
async blindedOrFullBlockToFullBytes(block: Uint8Array): Promise<Uint8Array> {
484484
return serializeFullOrBlindedSignedBeaconBlock(
485485
this.config,
486-
blindedOrFullBlockToFull(
487-
this.config,
488-
forkSeq,
489-
deserializeFullOrBlindedSignedBeaconBlock(this.config, block),
490-
await this.getTransactionsAndWithdrawals(forkSeq, toHexString(getEth1BlockHashFromSerializedBlock(block)))
491-
)
486+
await this.blindedOrFullBlockToFull(deserializeFullOrBlindedSignedBeaconBlock(this.config, block))
492487
);
493488
}
494489

packages/beacon-node/src/chain/interface.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {BeaconConfig} from "@lodestar/config";
1010
import {Logger} from "@lodestar/utils";
1111

1212
import {IForkChoice, ProtoBlock} from "@lodestar/fork-choice";
13-
import {ForkSeq} from "@lodestar/params";
1413
import {IEth1ForBlockProduction} from "../eth1/index.js";
1514
import {IExecutionEngine, IExecutionBuilder} from "../execution/index.js";
1615
import {Metrics} from "../metrics/metrics.js";
@@ -140,7 +139,7 @@ export interface IBeaconChain {
140139
getBlobSidecars(beaconBlock: deneb.BeaconBlock): deneb.BlobSidecars;
141140

142141
blindedOrFullBlockToFull(block: allForks.FullOrBlindedSignedBeaconBlock): Promise<allForks.SignedBeaconBlock>;
143-
blindedOrFullBlockToFullBytes(forkSeq: ForkSeq, block: Uint8Array): Promise<Uint8Array>;
142+
blindedOrFullBlockToFullBytes(block: Uint8Array): Promise<Uint8Array>;
144143

145144
produceBlock(blockAttributes: BlockAttributes): Promise<{block: allForks.BeaconBlock; blockValue: Wei}>;
146145
produceBlindedBlock(blockAttributes: BlockAttributes): Promise<{block: allForks.BlindedBeaconBlock; blockValue: Wei}>;

packages/beacon-node/src/network/reqresp/handlers/beaconBlocksByRange.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ export async function* onBeaconBlocksByRange(
2323
if (startSlot <= finalizedSlot) {
2424
// Chain of blobs won't change
2525
for await (const {key, value} of finalized.binaryEntriesStream({gte: startSlot, lt: endSlot})) {
26-
const {name, seq} = chain.config.getForkInfo(finalized.decodeKey(key));
2726
yield {
28-
data: await chain.blindedOrFullBlockToFullBytes(seq, value),
29-
fork: name,
27+
data: await chain.blindedOrFullBlockToFullBytes(value),
28+
fork: chain.config.getForkName(finalized.decodeKey(key)),
3029
};
3130
}
3231
}
@@ -55,10 +54,9 @@ export async function* onBeaconBlocksByRange(
5554
throw new ResponseError(RespStatus.SERVER_ERROR, `No item for root ${block.blockRoot} slot ${block.slot}`);
5655
}
5756

58-
const {name, seq} = chain.config.getForkInfo(block.slot);
5957
yield {
60-
data: await chain.blindedOrFullBlockToFullBytes(seq, blockBytes),
61-
fork: name,
58+
data: await chain.blindedOrFullBlockToFullBytes(blockBytes),
59+
fork: chain.config.getForkName(block.slot),
6260
};
6361
}
6462

packages/beacon-node/src/network/reqresp/handlers/beaconBlocksByRoot.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,9 @@ export async function* onBeaconBlocksByRoot(
3838
slot = slotFromBytes;
3939
}
4040

41-
const {name, seq} = chain.config.getForkInfo(slot);
42-
4341
yield {
44-
data: await chain.blindedOrFullBlockToFullBytes(seq, blockBytes),
45-
fork: name,
42+
data: await chain.blindedOrFullBlockToFullBytes(blockBytes),
43+
fork: chain.config.getForkName(slot),
4644
};
4745
}
4846
}

packages/beacon-node/src/util/fullOrBlindedBlock.ts

+2-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {allForks, bellatrix, capella, deneb} from "@lodestar/types";
33
import {BYTES_PER_LOGS_BLOOM, ForkSeq, SYNC_COMMITTEE_SIZE} from "@lodestar/params";
44
import {executionPayloadToPayloadHeader} from "@lodestar/state-transition";
55
import {ExecutionPayloadBody} from "../execution/engine/types.js";
6-
import {ROOT_SIZE, getSlotFromSignedBeaconBlockSerialized} from "./sszBytes.js";
6+
import {getSlotFromSignedBeaconBlockSerialized} from "./sszBytes.js";
77

88
/**
99
* * class SignedBeaconBlock(Container):
@@ -49,15 +49,7 @@ const BEACON_BLOCK_FIXED_LENGTH = 8 + 8 + 32 + 32 + 4;
4949
* Deneb:
5050
* blobKzgCommitments [offset - 4 bytes]
5151
*/
52-
53-
const LOCATION_OF_ETH1_BLOCK_HASH = 96 + 32 + 8;
54-
export function getEth1BlockHashFromSerializedBlock(block: Uint8Array): Uint8Array {
55-
const firstByte = SIGNED_BEACON_BLOCK_FIXED_LENGTH + BEACON_BLOCK_FIXED_LENGTH + LOCATION_OF_ETH1_BLOCK_HASH;
56-
return block.slice(firstByte, firstByte + ROOT_SIZE);
57-
}
58-
59-
const LOCATION_OF_EXECUTION_PAYLOAD_OFFSET =
60-
LOCATION_OF_ETH1_BLOCK_HASH + 32 + 32 + 4 + 4 + 4 + 4 + 4 + SYNC_COMMITTEE_SIZE / 8 + 96;
52+
const LOCATION_OF_EXECUTION_PAYLOAD_OFFSET = 96 + 32 + 8 + 32 + 32 + 4 + 4 + 4 + 4 + 4 + SYNC_COMMITTEE_SIZE / 8 + 96;
6153

6254
/**
6355
* class ExecutionPayload(Container) or class ExecutionPayloadHeader(Container)

0 commit comments

Comments
 (0)