Skip to content

Commit

Permalink
Merge b643672 into 629a84d
Browse files Browse the repository at this point in the history
  • Loading branch information
g11tech authored Oct 25, 2023
2 parents 629a84d + b643672 commit dc77d5d
Show file tree
Hide file tree
Showing 54 changed files with 1,385 additions and 828 deletions.
1 change: 1 addition & 0 deletions .wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ nodemodule
overriden
params
plaintext
produceBlockV
prover
req
reqresp
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/beacon-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!

Expand Down
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,
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -186,7 +192,7 @@ export type Api = {
>;

publishBlockV2(
blockOrContents: allForks.SignedBeaconBlock | SignedBlockContents,
blockOrContents: allForks.SignedBeaconBlockOrContents,
opts: {broadcastValidation?: BroadcastValidation}
): Promise<
ApiClientResponse<
Expand All @@ -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;
Expand All @@ -213,7 +219,7 @@ export type Api = {
>;

publishBlindedBlockV2(
blindedBlockOrContents: allForks.SignedBlindedBeaconBlock | SignedBlindedBlockContents,
blindedBlockOrContents: allForks.SignedBlindedBeaconBlockOrContents,
opts: {broadcastValidation?: BroadcastValidation}
): Promise<
ApiClientResponse<
Expand Down Expand Up @@ -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),
};

Expand All @@ -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,
Expand Down
Loading

0 comments on commit dc77d5d

Please sign in to comment.