Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix the publish blinded block api parsing for optional header verison #6966

Merged
merged 2 commits into from
Jul 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/api/src/beacon/routes/beacon/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,16 @@ export function getDefinitions(config: ChainForkConfig): RouteDefinitions<Endpoi
};
},
parseReqJson: ({body, headers}) => {
const fork = toForkName(fromHeaders(headers, MetaHeader.Version));
let fork: ForkName;
// As per spec, version header is optional for JSON requests
const versionHeader = fromHeaders(headers, MetaHeader.Version, false);
if (versionHeader !== undefined) {
fork = toForkName(versionHeader);
} else {
// Determine fork from slot in JSON payload
fork = config.getForkName((body as SignedBlindedBeaconBlock).message.slot);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is why I mean it's a hack btw, we kinda just yolo it here and try to access body.message.slot but this will result in "Cannot access property x of undefined" if data is not formatted correctyl, while if you get version from header we can properly apply validation before we try to access any property of body.

}

return {
signedBlindedBlock: getExecutionForkTypes(fork).SignedBlindedBeaconBlock.fromJson(body),
};
Expand Down
Loading