Skip to content

Commit

Permalink
insert verge between capella and deneb
Browse files Browse the repository at this point in the history
  • Loading branch information
g11tech committed Sep 1, 2023
1 parent 0051406 commit e8bcb58
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 23 deletions.
13 changes: 10 additions & 3 deletions packages/params/src/forkName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ export enum ForkSeq {
altair = 1,
bellatrix = 2,
capella = 3,
deneb = 4,
verge = 5,
// Verge is scheduled after capella for now
verge = 4,
deneb = 5,
}

export type ForkLightClient = Exclude<ForkName, ForkName.phase0>;
Expand All @@ -37,7 +38,13 @@ export function isForkWithdrawals(fork: ForkName): fork is ForkWithdrawals {
return isForkExecution(fork) && fork !== ForkName.bellatrix;
}

export type ForkBlobs = Exclude<ForkExecution, ForkName.bellatrix | ForkName.capella>;
// Verge is right now scheduled after capella
export type ForkVerge = Exclude<ForkWithdrawals, ForkName.capella>;
export function isForkVerge(fork: ForkName): fork is ForkBlobs {
return isForkWithdrawals(fork) && fork !== ForkName.capella;
}

export type ForkBlobs = Exclude<ForkWithdrawals, ForkName.capella>;
export function isForkBlobs(fork: ForkName): fork is ForkBlobs {
return isForkWithdrawals(fork) && fork !== ForkName.capella;
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ export function executionPayloadToPayloadHeader(

if (fork >= ForkSeq.verge) {
// https://github.com/ethereum/consensus-specs/blob/db74090c1e8dc1fb2c052bae268e22dc63061e32/specs/verge/beacon-chain.md#process_execution_payload
(bellatrixPayloadFields as verge.ExecutionPayloadHeader).executionWitness = (payload as verge.ExecutionPayload).executionWitness;
(bellatrixPayloadFields as verge.ExecutionPayloadHeader).executionWitnessRoot =
ssz.verge.ExecutionWitness.hashTreeRoot((payload as verge.ExecutionPayload).executionWitness);
}

return bellatrixPayloadFields;
Expand Down
4 changes: 1 addition & 3 deletions packages/state-transition/src/slot/upgradeStateToVerge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ export function upgradeStateToVerge(stateDeneb: CachedBeaconStateDeneb): CachedB
epoch: stateDeneb.epochCtx.epoch,
});

// Initialize ExecutionWitness empty List
stateVerge.latestExecutionPayloadHeader.executionWitness = ssz.verge.ExecutionWitness.defaultViewDU();
// latestExecutionPayloadHeader's executionWitnessRoot will have default zero root

stateVerge.commit();

return stateVerge;
}
4 changes: 3 additions & 1 deletion packages/types/src/allForks/sszTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ export const allForksBlobs = {
BlindedBlobSidecar: deneb.BlindedBlobSidecar,
},
verge: {
SignedBeaconBlockAndBlobsSidecar: deneb.SignedBeaconBlockAndBlobsSidecar,
SignedBeaconBlockAndBlobSidecars: deneb.SignedBeaconBlockAndBlobSidecars,
BlobSidecar: deneb.BlobSidecar,
BlindedBlobSidecar: deneb.BlindedBlobSidecar,
},
};
28 changes: 13 additions & 15 deletions packages/types/src/verge/sszTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
ByteVectorType,
VectorCompositeType,
ByteListType,
OptionalType,
OptionalType
} from "@chainsafe/ssz";
import {
HISTORICAL_ROOTS_LIMIT,
Expand All @@ -17,7 +17,7 @@ import {ssz as primitiveSsz} from "../primitive/index.js";
import {ssz as phase0Ssz} from "../phase0/index.js";
import {ssz as altairSsz} from "../altair/index.js";
import {ssz as bellatrixSsz} from "../bellatrix/index.js";
// import {ssz as capellaSsz} from "../capella/index.js";
import {ssz as capellaSsz} from "../capella/index.js";
// import {ssz as denebSsz} from "../deneb/index.js";

const {UintNum64, Root, BLSSignature} = primitiveSsz;
Expand All @@ -37,19 +37,16 @@ export const SuffixStateDiff = new ContainerType(
{
suffix: primitiveSsz.Byte,
// Null means not currently present
// TODO: Use new SSZ type Optional: https://github.com/ethereum/consensus-specs/commit/db74090c1e8dc1fb2c052bae268e22dc63061e32
currentValue: new OptionalType(primitiveSsz.Bytes32),
// newValue not present for the kaustenine network
// Null means value not updated
// newValue: new OptionalType(primitiveSsz.Bytes32),
newValue: new OptionalType(primitiveSsz.Bytes32),
},
{
typeName: "SuffixStateDiff",
casingMap: {
suffix: "suffix",
currentValue: "currentValue",
// newValue not present for the kaustenine network
// newValue: "newValue"
newValue: "newValue"
},
}
);
Expand Down Expand Up @@ -108,15 +105,15 @@ export const ExecutionWitness = new ContainerType(

export const ExecutionPayload = new ContainerType(
{
...bellatrixSsz.ExecutionPayload.fields,
...capellaSsz.ExecutionPayload.fields,
executionWitness: ExecutionWitness, // New in verge
},
{typeName: "ExecutionPayload", jsonCase: "eth2"}
);

export const ExecutionPayloadHeader = new ContainerType(
{
...bellatrixSsz.ExecutionPayloadHeader.fields,
...capellaSsz.ExecutionPayloadHeader.fields,
executionWitnessRoot: Root, // New in verge
},
{typeName: "ExecutionPayloadHeader", jsonCase: "eth2"}
Expand All @@ -127,15 +124,15 @@ export const BeaconBlockBody = new ContainerType(
{
...altairSsz.BeaconBlockBody.fields,
executionPayload: ExecutionPayload, // Modified in verge
// blsToExecutionChanges: capellaSsz.BeaconBlockBody.fields.blsToExecutionChanges,
blsToExecutionChanges: capellaSsz.BeaconBlockBody.fields.blsToExecutionChanges,
// blobKzgCommitments: denebSsz.BlobKzgCommitments,
},
{typeName: "BeaconBlockBody", jsonCase: "eth2", cachePermanentRootStruct: true}
);

export const BeaconBlock = new ContainerType(
{
...bellatrixSsz.BeaconBlock.fields,
...capellaSsz.BeaconBlock.fields,
body: BeaconBlockBody, // Modified in verge
},
{typeName: "BeaconBlock", jsonCase: "eth2", cachePermanentRootStruct: true}
Expand All @@ -151,8 +148,9 @@ export const SignedBeaconBlock = new ContainerType(

export const BlindedBeaconBlockBody = new ContainerType(
{
...BeaconBlockBody.fields,
...altairSsz.BeaconBlockBody.fields,
executionPayloadHeader: ExecutionPayloadHeader, // Modified in verge
blsToExecutionChanges: capellaSsz.BeaconBlockBody.fields.blsToExecutionChanges,
// blobKzgCommitments: denebSsz.BlobKzgCommitments,
},
{typeName: "BlindedBeaconBlockBody", jsonCase: "eth2", cachePermanentRootStruct: true}
Expand Down Expand Up @@ -214,10 +212,10 @@ export const BeaconState = new ContainerType(
// Execution
latestExecutionPayloadHeader: ExecutionPayloadHeader, // Modified in verge
// Withdrawals
// nextWithdrawalIndex: capellaSsz.BeaconState.fields.nextWithdrawalIndex,
// nextWithdrawalValidatorIndex: capellaSsz.BeaconState.fields.nextWithdrawalValidatorIndex,
nextWithdrawalIndex: capellaSsz.BeaconState.fields.nextWithdrawalIndex,
nextWithdrawalValidatorIndex: capellaSsz.BeaconState.fields.nextWithdrawalValidatorIndex,
// Deep history valid from Capella onwards
// historicalSummaries: capellaSsz.BeaconState.fields.historicalSummaries,
historicalSummaries: capellaSsz.BeaconState.fields.historicalSummaries,
},
{typeName: "BeaconState", jsonCase: "eth2"}
);

0 comments on commit e8bcb58

Please sign in to comment.