Skip to content

Commit

Permalink
refactor: rename data gas to blob gas for relevant deneb fields
Browse files Browse the repository at this point in the history
  • Loading branch information
g11tech committed Jul 28, 2023
1 parent 0c440c1 commit 4f19d94
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 34 deletions.
28 changes: 14 additions & 14 deletions packages/beacon-node/src/execution/engine/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ export type ExecutionPayloadRpc = {
blockHash: DATA; // 32 bytes
transactions: DATA[];
withdrawals?: WithdrawalRpc[]; // Capella hardfork
dataGasUsed?: QUANTITY; // DENEB
excessDataGas?: QUANTITY; // DENEB
blobGasUsed?: QUANTITY; // DENEB
excessBlobGas?: QUANTITY; // DENEB
parentBeaconBlockRoot?: QUANTITY; // DENEB
};

Expand Down Expand Up @@ -185,11 +185,11 @@ export function serializeExecutionPayload(fork: ForkName, data: allForks.Executi
payload.withdrawals = withdrawals.map(serializeWithdrawal);
}

// DENEB adds dataGasUsed & excessDataGas to the ExecutionPayload
// DENEB adds blobGasUsed & excessBlobGas to the ExecutionPayload
if (ForkSeq[fork] >= ForkSeq.deneb) {
const {dataGasUsed, excessDataGas} = data as deneb.ExecutionPayload;
payload.dataGasUsed = numToQuantity(dataGasUsed);
payload.excessDataGas = numToQuantity(excessDataGas);
const {blobGasUsed, excessBlobGas} = data as deneb.ExecutionPayload;
payload.blobGasUsed = numToQuantity(blobGasUsed);
payload.excessBlobGas = numToQuantity(excessBlobGas);
}

return payload;
Expand Down Expand Up @@ -249,23 +249,23 @@ export function parseExecutionPayload(
(executionPayload as capella.ExecutionPayload).withdrawals = withdrawals.map((w) => deserializeWithdrawal(w));
}

// DENEB adds excessDataGas to the ExecutionPayload
// DENEB adds excessBlobGas to the ExecutionPayload
if (ForkSeq[fork] >= ForkSeq.deneb) {
const {dataGasUsed, excessDataGas} = data;
const {blobGasUsed, excessBlobGas} = data;

if (dataGasUsed == null) {
if (blobGasUsed == null) {
throw Error(
`dataGasUsed missing for ${fork} >= deneb executionPayload number=${executionPayload.blockNumber} hash=${data.blockHash}`
`blobGasUsed missing for ${fork} >= deneb executionPayload number=${executionPayload.blockNumber} hash=${data.blockHash}`
);
}
if (excessDataGas == null) {
if (excessBlobGas == null) {
throw Error(
`excessDataGas missing for ${fork} >= deneb executionPayload number=${executionPayload.blockNumber} hash=${data.blockHash}`
`excessBlobGas missing for ${fork} >= deneb executionPayload number=${executionPayload.blockNumber} hash=${data.blockHash}`
);
}

(executionPayload as deneb.ExecutionPayload).dataGasUsed = quantityToBigint(dataGasUsed);
(executionPayload as deneb.ExecutionPayload).excessDataGas = quantityToBigint(excessDataGas);
(executionPayload as deneb.ExecutionPayload).blobGasUsed = quantityToBigint(blobGasUsed);
(executionPayload as deneb.ExecutionPayload).excessBlobGas = quantityToBigint(excessBlobGas);
}

return {executionPayload, blockValue, blobsBundle};
Expand Down
16 changes: 8 additions & 8 deletions packages/light-client/src/spec/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ export function upgradeLightClientHeader(

// eslint-disable-next-line no-fallthrough
case ForkName.deneb:
(upgradedHeader as deneb.LightClientHeader).execution.dataGasUsed =
ssz.deneb.LightClientHeader.fields.execution.fields.dataGasUsed.defaultValue();
(upgradedHeader as deneb.LightClientHeader).execution.excessDataGas =
ssz.deneb.LightClientHeader.fields.execution.fields.excessDataGas.defaultValue();
(upgradedHeader as deneb.LightClientHeader).execution.blobGasUsed =
ssz.deneb.LightClientHeader.fields.execution.fields.blobGasUsed.defaultValue();
(upgradedHeader as deneb.LightClientHeader).execution.excessBlobGas =
ssz.deneb.LightClientHeader.fields.execution.fields.excessBlobGas.defaultValue();

// Break if no further upgradation is required else fall through
if (ForkSeq[targetFork] <= ForkSeq.deneb) break;
Expand Down Expand Up @@ -129,10 +129,10 @@ export function isValidLightClientHeader(config: ChainForkConfig, header: allFor

if (epoch < config.DENEB_FORK_EPOCH) {
if (
((header as deneb.LightClientHeader).execution.dataGasUsed &&
(header as deneb.LightClientHeader).execution.dataGasUsed !== BigInt(0)) ||
((header as deneb.LightClientHeader).execution.excessDataGas &&
(header as deneb.LightClientHeader).execution.excessDataGas !== BigInt(0))
((header as deneb.LightClientHeader).execution.blobGasUsed &&
(header as deneb.LightClientHeader).execution.blobGasUsed !== BigInt(0)) ||
((header as deneb.LightClientHeader).execution.excessBlobGas &&
(header as deneb.LightClientHeader).execution.excessBlobGas !== BigInt(0))
) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe("isValidLightClientHeader", function () {

const capellaUpgradedDenebHeader = {
beacon: capellaLCHeader.beacon,
execution: {...capellaLCHeader.execution, dataGasUsed: 0, excessDataGas: 0},
execution: {...capellaLCHeader.execution, blobGasUsed: 0, excessBlobGas: 0},
executionBranch: capellaLCHeader.executionBranch,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ export function executionPayloadToPayloadHeader(

if (fork >= ForkSeq.deneb) {
// https://github.com/ethereum/consensus-specs/blob/dev/specs/eip4844/beacon-chain.md#process_execution_payload
(bellatrixPayloadFields as deneb.ExecutionPayloadHeader).dataGasUsed = (
(bellatrixPayloadFields as deneb.ExecutionPayloadHeader).blobGasUsed = (
payload as deneb.ExecutionPayloadHeader | deneb.ExecutionPayload
).dataGasUsed;
(bellatrixPayloadFields as deneb.ExecutionPayloadHeader).excessDataGas = (
).blobGasUsed;
(bellatrixPayloadFields as deneb.ExecutionPayloadHeader).excessBlobGas = (
payload as deneb.ExecutionPayloadHeader | deneb.ExecutionPayload
).excessDataGas;
).excessBlobGas;
}

return bellatrixPayloadFields;
Expand Down
6 changes: 3 additions & 3 deletions packages/state-transition/src/slot/upgradeStateToDeneb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ export function upgradeStateToDeneb(stateCapella: CachedBeaconStateCapella): Cac
epoch: stateCapella.epochCtx.epoch,
});

// Since excessDataGas and dataGasUsed are appened in the end to latestExecutionPayloadHeader so they should
// Since excessBlobGas and blobGasUsed are appened in the end to latestExecutionPayloadHeader so they should
// be set to defaults and need no assigning, but right now any access to latestExecutionPayloadHeader fails
// with LeafNode has no left node. Weirdly its beacuse of addition of the second field as with one field
// it seems to work.
//
// TODO DENEB: Debug and remove the following cloning
stateDeneb.latestExecutionPayloadHeader = ssz.deneb.BeaconState.fields.latestExecutionPayloadHeader.toViewDU({
...stateCapella.latestExecutionPayloadHeader.toValue(),
excessDataGas: BigInt(0),
dataGasUsed: BigInt(0),
excessBlobGas: BigInt(0),
blobGasUsed: BigInt(0),
});

stateDeneb.commit();
Expand Down
8 changes: 4 additions & 4 deletions packages/types/src/deneb/sszTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,17 @@ export const BeaconBlockAndBlobsSidecarByRootRequest = new ListCompositeType(Roo
export const ExecutionPayload = new ContainerType(
{
...capellaSsz.ExecutionPayload.fields,
dataGasUsed: UintBn64, // New in DENEB
excessDataGas: UintBn64, // New in DENEB
blobGasUsed: UintBn64, // New in DENEB
excessBlobGas: UintBn64, // New in DENEB
},
{typeName: "ExecutionPayload", jsonCase: "eth2"}
);

export const ExecutionPayloadHeader = new ContainerType(
{
...capellaSsz.ExecutionPayloadHeader.fields,
dataGasUsed: UintBn64, // New in DENEB
excessDataGas: UintBn64, // New in DENEB
blobGasUsed: UintBn64, // New in DENEB
excessBlobGas: UintBn64, // New in DENEB
},
{typeName: "ExecutionPayloadHeader", jsonCase: "eth2"}
);
Expand Down

0 comments on commit 4f19d94

Please sign in to comment.