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

feat: implement produce block v3 and move builder/execution race to beacon #5880

Merged
merged 1 commit into from
Oct 26, 2023
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
1 change: 1 addition & 0 deletions .wordlist.txt
Original file line number Diff line number Diff line change
@@ -109,6 +109,7 @@ nodemodule
overriden
params
plaintext
produceBlockV
prover
req
reqresp
2 changes: 1 addition & 1 deletion docs/usage/beacon-management.md
Original file line number Diff line number Diff line change
@@ -101,7 +101,7 @@ A young testnet should take a few hours to sync. If you see multiple or consiste

### Checkpoint Sync

If you are starting your node from a blank db, like starting from genesis, or from the last saved state in db and the network is now far ahead, your node will be susceptible to "long range attacks." Ethereum's solution to this is via something called weak subjectivity. [Read Vitalik's illuminating post explaining weak subjectivity.](https://blog.ethereum.org/2014/11/25/proof-stake-learned-love-weak-subjectivity/).
If you are starting your node from a blank db, like starting from genesis, or from the last saved state in db and the network is now far ahead, your node will be susceptible to "long range attacks." Ethereum's solution to this is via something called weak subjectivity. [Read Vitalik's illuminating post explaining weak subjectivity.](https://blog.ethereum.org/2014/11/25/proof-stake-learned-love-weak-subjectivity/).

If you have a synced beacon node available (e.g., your friend's node or an infrastructure provider) and a trusted checkpoint you can rely on, you can start off your beacon node in under a minute! And at the same time kicking the "long range attack" in its butt!

57 changes: 31 additions & 26 deletions packages/api/src/beacon/routes/beacon/block.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import {ContainerType} from "@chainsafe/ssz";
import {ForkName} from "@lodestar/params";
import {ChainForkConfig} from "@lodestar/config";
import {phase0, allForks, Slot, Root, ssz, RootHex, deneb} from "@lodestar/types";
import {
phase0,
allForks,
Slot,
Root,
ssz,
RootHex,
deneb,
isSignedBlockContents,
isSignedBlindedBlockContents,
} from "@lodestar/types";

import {
RoutesData,
@@ -21,12 +31,8 @@ import {HttpStatusCode} from "../../../utils/client/httpStatusCode.js";
import {parseAcceptHeader, writeAcceptHeader} from "../../../utils/acceptHeader.js";
import {ApiClientResponse, ResponseFormat} from "../../../interfaces.js";
import {
SignedBlockContents,
SignedBlindedBlockContents,
isSignedBlockContents,
isSignedBlindedBlockContents,
AllForksSignedBlockContentsReqSerializer,
AllForksSignedBlindedBlockContentsReqSerializer,
allForksSignedBlockContentsReqSerializer,
allForksSignedBlindedBlockContentsReqSerializer,
} from "../../../utils/routes.js";

// See /packages/api/src/routes/index.ts for reasoning and instructions to add new routes
@@ -175,7 +181,7 @@ export type Api = {
* @param requestBody The `SignedBeaconBlock` object composed of `BeaconBlock` object (produced by beacon node) and validator signature.
* @returns any The block was validated successfully and has been broadcast. It has also been integrated into the beacon node's database.
*/
publishBlock(blockOrContents: allForks.SignedBeaconBlock | SignedBlockContents): Promise<
publishBlock(blockOrContents: allForks.SignedBeaconBlockOrContents): Promise<
ApiClientResponse<
{
[HttpStatusCode.OK]: void;
@@ -186,7 +192,7 @@ export type Api = {
>;

publishBlockV2(
blockOrContents: allForks.SignedBeaconBlock | SignedBlockContents,
blockOrContents: allForks.SignedBeaconBlockOrContents,
opts: {broadcastValidation?: BroadcastValidation}
): Promise<
ApiClientResponse<
@@ -202,7 +208,7 @@ export type Api = {
* Publish a signed blinded block by submitting it to the mev relay and patching in the block
* transactions beacon node gets in response.
*/
publishBlindedBlock(blindedBlockOrContents: allForks.SignedBlindedBeaconBlock | SignedBlindedBlockContents): Promise<
publishBlindedBlock(blindedBlockOrContents: allForks.SignedBlindedBeaconBlockOrContents): Promise<
ApiClientResponse<
{
[HttpStatusCode.OK]: void;
@@ -213,7 +219,7 @@ export type Api = {
>;

publishBlindedBlockV2(
blindedBlockOrContents: allForks.SignedBlindedBeaconBlock | SignedBlindedBlockContents,
blindedBlockOrContents: allForks.SignedBlindedBeaconBlockOrContents,
opts: {broadcastValidation?: BroadcastValidation}
): Promise<
ApiClientResponse<
@@ -293,15 +299,15 @@ export function getReqSerializers(config: ChainForkConfig): ReqSerializers<Api,
const getSignedBeaconBlockType = (data: allForks.SignedBeaconBlock): allForks.AllForksSSZTypes["SignedBeaconBlock"] =>
config.getForkTypes(data.message.slot).SignedBeaconBlock;

const AllForksSignedBlockOrContents: TypeJson<allForks.SignedBeaconBlock | SignedBlockContents> = {
const AllForksSignedBlockOrContents: TypeJson<allForks.SignedBeaconBlockOrContents> = {
toJson: (data) =>
isSignedBlockContents(data)
? AllForksSignedBlockContentsReqSerializer(getSignedBeaconBlockType).toJson(data)
? allForksSignedBlockContentsReqSerializer(getSignedBeaconBlockType).toJson(data)
: getSignedBeaconBlockType(data).toJson(data),

fromJson: (data) =>
(data as {signed_block: unknown}).signed_block !== undefined
? AllForksSignedBlockContentsReqSerializer(getSignedBeaconBlockType).fromJson(data)
? allForksSignedBlockContentsReqSerializer(getSignedBeaconBlockType).fromJson(data)
: getSignedBeaconBlockType(data as allForks.SignedBeaconBlock).fromJson(data),
};

@@ -310,18 +316,17 @@ export function getReqSerializers(config: ChainForkConfig): ReqSerializers<Api,
): allForks.AllForksBlindedSSZTypes["SignedBeaconBlock"] =>
config.getBlindedForkTypes(data.message.slot).SignedBeaconBlock;

const AllForksSignedBlindedBlockOrContents: TypeJson<allForks.SignedBlindedBeaconBlock | SignedBlindedBlockContents> =
{
toJson: (data) =>
isSignedBlindedBlockContents(data)
? AllForksSignedBlindedBlockContentsReqSerializer(getSignedBlindedBeaconBlockType).toJson(data)
: getSignedBlindedBeaconBlockType(data).toJson(data),

fromJson: (data) =>
(data as {signed_blinded_block: unknown}).signed_blinded_block !== undefined
? AllForksSignedBlindedBlockContentsReqSerializer(getSignedBlindedBeaconBlockType).fromJson(data)
: getSignedBlindedBeaconBlockType(data as allForks.SignedBlindedBeaconBlock).fromJson(data),
};
const AllForksSignedBlindedBlockOrContents: TypeJson<allForks.SignedBlindedBeaconBlockOrContents> = {
toJson: (data) =>
isSignedBlindedBlockContents(data)
? allForksSignedBlindedBlockContentsReqSerializer(getSignedBlindedBeaconBlockType).toJson(data)
: getSignedBlindedBeaconBlockType(data).toJson(data),

fromJson: (data) =>
(data as {signed_blinded_block: unknown}).signed_blinded_block !== undefined
? allForksSignedBlindedBlockContentsReqSerializer(getSignedBlindedBeaconBlockType).fromJson(data)
: getSignedBlindedBeaconBlockType(data as allForks.SignedBlindedBeaconBlock).fromJson(data),
};

return {
getBlock: getBlockReq,
Loading